diff options
Diffstat (limited to 'svl/source')
115 files changed, 0 insertions, 53389 deletions
diff --git a/svl/source/config/asiancfg.cxx b/svl/source/config/asiancfg.cxx deleted file mode 100644 index a83f493d81..0000000000 --- a/svl/source/config/asiancfg.cxx +++ /dev/null @@ -1,268 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/asiancfg.hxx> -#include <svl/svarray.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/lang/Locale.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <tools/debug.hxx> - -//----------------------------------------------------------------------------- -using namespace utl; -using namespace com::sun::star; -using namespace com::sun::star::uno; -using namespace com::sun::star::beans; -using namespace com::sun::star::lang; - -using ::rtl::OUString; - -#define C2U(cChar) OUString(RTL_CONSTASCII_USTRINGPARAM(cChar)) - -//----------------------------------------------------------------------------- -struct SvxForbiddenStruct_Impl -{ - Locale aLocale; - OUString sStartChars; - OUString sEndChars; -}; -//----------------------------------------------------------------------------- -typedef SvxForbiddenStruct_Impl* SvxForbiddenStruct_ImplPtr; -SV_DECL_PTRARR_DEL(SvxForbiddenStructArr, SvxForbiddenStruct_ImplPtr, 2, 2) -SV_IMPL_PTRARR(SvxForbiddenStructArr, SvxForbiddenStruct_ImplPtr); -//----------------------------------------------------------------------------- -struct SvxAsianConfig_Impl -{ - sal_Bool bKerningWesternTextOnly; - sal_Int16 nCharDistanceCompression; - - SvxForbiddenStructArr aForbiddenArr; - - SvxAsianConfig_Impl() : - bKerningWesternTextOnly(sal_True), - nCharDistanceCompression(0) {} -}; - -Sequence<OUString> lcl_GetPropertyNames() -{ - Sequence<OUString> aNames(2); - OUString* pNames = aNames.getArray(); - pNames[0] = C2U("IsKerningWesternTextOnly"); - pNames[1] = C2U("CompressCharacterDistance"); - return aNames;; -} -// --------------------------------------------------------------------------- -SvxAsianConfig::SvxAsianConfig(sal_Bool bEnableNotify) : - utl::ConfigItem(C2U("Office.Common/AsianLayout")), - pImpl(new SvxAsianConfig_Impl) -{ - if(bEnableNotify) - EnableNotification(lcl_GetPropertyNames()); - Load(); -} - -SvxAsianConfig::~SvxAsianConfig() -{ - delete pImpl; -} - -void SvxAsianConfig::Load() -{ - Sequence<Any> aValues = GetProperties(lcl_GetPropertyNames()); - const Any* pValues = aValues.getConstArray(); - if(pValues[0].hasValue()) - pImpl->bKerningWesternTextOnly = *(sal_Bool*) pValues[0].getValue(); - pValues[1] >>= pImpl->nCharDistanceCompression; - - pImpl->aForbiddenArr.DeleteAndDestroy(0, pImpl->aForbiddenArr.Count()); - OUString sPropPrefix(C2U("StartEndCharacters")); - Sequence<OUString> aNodes = GetNodeNames(sPropPrefix); - - Sequence<OUString> aPropNames(aNodes.getLength() * 2); - OUString* pNames = aPropNames.getArray(); - sal_Int32 nName = 0; - sPropPrefix += C2U("/"); - sal_Int32 nNode; - const OUString* pNodes = aNodes.getConstArray(); - for(nNode = 0; nNode < aNodes.getLength(); nNode++) - { - OUString sStart(sPropPrefix); - sStart += pNodes[nNode]; - sStart += C2U("/"); - pNames[nName] = sStart; pNames[nName++] += C2U("StartCharacters"); - pNames[nName] = sStart; pNames[nName++] += C2U("EndCharacters"); - } - Sequence<Any> aNodeValues = GetProperties(aPropNames); - const Any* pNodeValues = aNodeValues.getConstArray(); - nName = 0; - for(nNode = 0; nNode < aNodes.getLength(); nNode++) - { - SvxForbiddenStruct_ImplPtr pInsert = new SvxForbiddenStruct_Impl; - pInsert->aLocale.Language = pNodes[nNode].copy(0, 2); - DBG_ASSERT(pInsert->aLocale.Language.getLength(), "illegal language"); - pInsert->aLocale.Country = pNodes[nNode].copy(3, 2); - - pNodeValues[nName++] >>= pInsert->sStartChars; - pNodeValues[nName++] >>= pInsert->sEndChars; - pImpl->aForbiddenArr.Insert(pInsert, pImpl->aForbiddenArr.Count()); - } -} - -void SvxAsianConfig::Notify( const Sequence<OUString>& ) -{ - Load(); -} - -void SvxAsianConfig::Commit() -{ - Sequence<Any> aValues(2); - Any* pValues = aValues.getArray(); - pValues[0].setValue(&pImpl->bKerningWesternTextOnly, ::getBooleanCppuType()); - pValues[1] <<= pImpl->nCharDistanceCompression; - PutProperties(lcl_GetPropertyNames(), aValues); - - - OUString sNode(C2U("StartEndCharacters")); - if(!pImpl->aForbiddenArr.Count()) - ClearNodeSet(sNode); - else - { - Sequence<PropertyValue> aSetValues(2 * pImpl->aForbiddenArr.Count()); - PropertyValue* pSetValues = aSetValues.getArray(); - sal_Int32 nSetValue = 0; - const OUString sStartChars(C2U("StartCharacters")); - const OUString sEndChars(C2U("EndCharacters")); - for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++) - { - OUString sPrefix(sNode); - sPrefix += C2U("/"); - sPrefix += pImpl->aForbiddenArr[i]->aLocale.Language; - DBG_ASSERT(pImpl->aForbiddenArr[i]->aLocale.Language.getLength(), "illegal language"); - sPrefix += C2U("-"); - sPrefix += pImpl->aForbiddenArr[i]->aLocale.Country; - sPrefix += C2U("/"); - pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sStartChars; - pSetValues[nSetValue++].Value <<= pImpl->aForbiddenArr[i]->sStartChars; - pSetValues[nSetValue].Name = sPrefix; pSetValues[nSetValue].Name += sEndChars; - pSetValues[nSetValue++].Value <<= pImpl->aForbiddenArr[i]->sEndChars; - } - ReplaceSetProperties(sNode, aSetValues); - } -} - -sal_Bool SvxAsianConfig::IsKerningWesternTextOnly() const -{ - return pImpl->bKerningWesternTextOnly; -} - -void SvxAsianConfig::SetKerningWesternTextOnly(sal_Bool bSet) -{ - pImpl->bKerningWesternTextOnly = bSet; - SetModified(); -} - -sal_Int16 SvxAsianConfig::GetCharDistanceCompression() const -{ - return pImpl->nCharDistanceCompression; -} - -void SvxAsianConfig::SetCharDistanceCompression(sal_Int16 nSet) -{ - DBG_ASSERT(nSet >= 0 && nSet < 3, "compression value illegal"); - SetModified(); - pImpl->nCharDistanceCompression = nSet; -} - -uno::Sequence<lang::Locale> SvxAsianConfig::GetStartEndCharLocales() -{ - Sequence<Locale> aRet(pImpl->aForbiddenArr.Count()); - Locale* pRet = aRet.getArray(); - for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++) - { - pRet[i] = pImpl->aForbiddenArr[i]->aLocale; - } - return aRet; -} - -sal_Bool SvxAsianConfig::GetStartEndChars( const Locale& rLocale, - OUString& rStartChars, - OUString& rEndChars ) -{ - for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++) - { - if(rLocale.Language == pImpl->aForbiddenArr[i]->aLocale.Language && - rLocale.Country == pImpl->aForbiddenArr[i]->aLocale.Country) - { - rStartChars = pImpl->aForbiddenArr[i]->sStartChars; - rEndChars = pImpl->aForbiddenArr[i]->sEndChars; - return sal_True; - } - } - return sal_False; -} - -void SvxAsianConfig::SetStartEndChars( const Locale& rLocale, - const OUString* pStartChars, - const OUString* pEndChars ) -{ - sal_Bool bFound = sal_False; - for(sal_uInt16 i = 0; i < pImpl->aForbiddenArr.Count(); i++) - { - if(rLocale.Language == pImpl->aForbiddenArr[i]->aLocale.Language && - rLocale.Country == pImpl->aForbiddenArr[i]->aLocale.Country) - { - if(pStartChars && pEndChars) - { - pImpl->aForbiddenArr[i]->sStartChars = *pStartChars; - pImpl->aForbiddenArr[i]->sEndChars = *pEndChars; - } - else - pImpl->aForbiddenArr.DeleteAndDestroy(i, 1); - bFound = sal_True; - } - } - if(!bFound && pStartChars && pEndChars) - { - SvxForbiddenStruct_ImplPtr pInsert = new SvxForbiddenStruct_Impl; - pInsert->aLocale = rLocale; - pInsert->sStartChars = *pStartChars; - pInsert->sEndChars = *pEndChars; - pImpl->aForbiddenArr.Insert(pInsert, pImpl->aForbiddenArr.Count()); - } -#ifdef DBG_UTIL - else if(!bFound) - OSL_FAIL("attempt to clear unavailable data"); -#endif - SetModified(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/cjkoptions.cxx b/svl/source/config/cjkoptions.cxx deleted file mode 100644 index 65a3096c6d..0000000000 --- a/svl/source/config/cjkoptions.cxx +++ /dev/null @@ -1,484 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/cjkoptions.hxx> - -#include <svl/languageoptions.hxx> -#include <i18npool/lang.h> -#include <unotools/configitem.hxx> -#include <tools/debug.hxx> -#include <com/sun/star/uno/Any.h> -#include <com/sun/star/uno/Sequence.hxx> -#include <osl/mutex.hxx> -#include <rtl/instance.hxx> - -#include <itemholder2.hxx> - -using namespace ::com::sun::star::uno; -using namespace ::rtl; - -#define C2U(cChar) OUString(RTL_CONSTASCII_USTRINGPARAM(cChar)) -#define CFG_READONLY_DEFAULT sal_False - -class SvtCJKOptions_Impl : public utl::ConfigItem -{ - sal_Bool bIsLoaded; - sal_Bool bCJKFont; - sal_Bool bVerticalText; - sal_Bool bAsianTypography; - sal_Bool bJapaneseFind; - sal_Bool bRuby; - sal_Bool bChangeCaseMap; - sal_Bool bDoubleLines; - sal_Bool bEmphasisMarks; - sal_Bool bVerticalCallOut; - - sal_Bool bROCJKFont; - sal_Bool bROVerticalText; - sal_Bool bROAsianTypography; - sal_Bool bROJapaneseFind; - sal_Bool bRORuby; - sal_Bool bROChangeCaseMap; - sal_Bool bRODoubleLines; - sal_Bool bROEmphasisMarks; - sal_Bool bROVerticalCallOut; - -public: - SvtCJKOptions_Impl(); - ~SvtCJKOptions_Impl(); - - virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& rPropertyNames ); - virtual void Commit(); - void Load(); - - sal_Bool IsLoaded() { return bIsLoaded; } - - sal_Bool IsCJKFontEnabled() const { return bCJKFont; } - sal_Bool IsVerticalTextEnabled() const { return bVerticalText; } - sal_Bool IsAsianTypographyEnabled() const { return bAsianTypography; } - sal_Bool IsJapaneseFindEnabled() const { return bJapaneseFind; } - sal_Bool IsRubyEnabled() const { return bRuby; } - sal_Bool IsChangeCaseMapEnabled() const { return bChangeCaseMap; } - sal_Bool IsDoubleLinesEnabled() const { return bDoubleLines; } - sal_Bool IsEmphasisMarksEnabled() const { return bEmphasisMarks; } - sal_Bool IsVerticalCallOutEnabled() const { return bVerticalCallOut; } - - sal_Bool IsAnyEnabled() const { - return bCJKFont||bVerticalText||bAsianTypography||bJapaneseFind|| - bRuby||bChangeCaseMap||bDoubleLines||bEmphasisMarks||bVerticalCallOut; } - void SetAll(sal_Bool bSet); - sal_Bool IsReadOnly(SvtCJKOptions::EOption eOption) const; -}; - -namespace -{ - struct PropertyNames - : public rtl::Static< Sequence<OUString>, PropertyNames > {}; -} - -SvtCJKOptions_Impl::SvtCJKOptions_Impl() : - utl::ConfigItem(C2U("Office.Common/I18N/CJK")), - bIsLoaded(sal_False), - bCJKFont(sal_True), - bVerticalText(sal_True), - bAsianTypography(sal_True), - bJapaneseFind(sal_True), - bRuby(sal_True), - bChangeCaseMap(sal_True), - bDoubleLines(sal_True), - bEmphasisMarks(sal_True), - bVerticalCallOut(sal_True), - bROCJKFont(CFG_READONLY_DEFAULT), - bROVerticalText(CFG_READONLY_DEFAULT), - bROAsianTypography(CFG_READONLY_DEFAULT), - bROJapaneseFind(CFG_READONLY_DEFAULT), - bRORuby(CFG_READONLY_DEFAULT), - bROChangeCaseMap(CFG_READONLY_DEFAULT), - bRODoubleLines(CFG_READONLY_DEFAULT), - bROEmphasisMarks(CFG_READONLY_DEFAULT), - bROVerticalCallOut(CFG_READONLY_DEFAULT) -{ -} - -SvtCJKOptions_Impl::~SvtCJKOptions_Impl() -{ -} - -void SvtCJKOptions_Impl::SetAll(sal_Bool bSet) -{ - if ( - !bROCJKFont && - !bROVerticalText && - !bROAsianTypography && - !bROJapaneseFind && - !bRORuby && - !bROChangeCaseMap && - !bRODoubleLines && - !bROEmphasisMarks && - !bROVerticalCallOut - ) - { - bCJKFont=bSet; - bVerticalText=bSet; - bAsianTypography=bSet; - bJapaneseFind=bSet; - bRuby=bSet; - bChangeCaseMap=bSet; - bDoubleLines=bSet; - bEmphasisMarks=bSet; - bVerticalCallOut=bSet; - - SetModified(); - Commit(); - NotifyListeners(0); - } -} - -void SvtCJKOptions_Impl::Load() -{ - Sequence<OUString> &rPropertyNames = PropertyNames::get(); - if(!rPropertyNames.getLength()) - { - rPropertyNames.realloc(9); - OUString* pNames = rPropertyNames.getArray(); - - pNames[0] = C2U("CJKFont"); - pNames[1] = C2U("VerticalText"); - pNames[2] = C2U("AsianTypography"); - pNames[3] = C2U("JapaneseFind"); - pNames[4] = C2U("Ruby"); - pNames[5] = C2U("ChangeCaseMap"); - pNames[6] = C2U("DoubleLines"); - pNames[7] = C2U("EmphasisMarks"); - pNames[8] = C2U("VerticalCallOut"); - - EnableNotification( rPropertyNames ); - } - Sequence< Any > aValues = GetProperties(rPropertyNames); - Sequence< sal_Bool > aROStates = GetReadOnlyStates(rPropertyNames); - const Any* pValues = aValues.getConstArray(); - const sal_Bool* pROStates = aROStates.getConstArray(); - DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" ); - DBG_ASSERT( aROStates.getLength() == rPropertyNames.getLength(), "GetReadOnlyStates failed" ); - if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() ) - { - for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ ) - { - if( pValues[nProp].hasValue() ) - { - sal_Bool bValue = *(sal_Bool*)pValues[nProp].getValue(); - switch ( nProp ) - { - case 0: { bCJKFont = bValue; bROCJKFont = pROStates[nProp]; } break; - case 1: { bVerticalText = bValue; bROVerticalText = pROStates[nProp]; } break; - case 2: { bAsianTypography = bValue; bROAsianTypography = pROStates[nProp]; } break; - case 3: { bJapaneseFind = bValue; bROJapaneseFind = pROStates[nProp]; } break; - case 4: { bRuby = bValue; bRORuby = pROStates[nProp]; } break; - case 5: { bChangeCaseMap = bValue; bROChangeCaseMap = pROStates[nProp]; } break; - case 6: { bDoubleLines = bValue; bRODoubleLines = pROStates[nProp]; } break; - case 7: { bEmphasisMarks = bValue; bROEmphasisMarks = pROStates[nProp]; } break; - case 8: { bVerticalCallOut = bValue; bROVerticalCallOut = pROStates[nProp]; } break; - } - } - } - } - - SvtSystemLanguageOptions aSystemLocaleSettings; - LanguageType eSystemLanguage = aSystemLocaleSettings.GetWin16SystemLanguage(); - sal_uInt16 nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage ); - - sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM); - if ( !bCJKFont && (( nScriptType & SCRIPTTYPE_ASIAN )|| - ((eSystemLanguage != LANGUAGE_SYSTEM) && ( nWinScript & SCRIPTTYPE_ASIAN )))) - { - SetAll(sal_True); - } - bIsLoaded = sal_True; -} - -void SvtCJKOptions_Impl::Notify( const Sequence< OUString >& ) -{ - Load(); - NotifyListeners(0); -} - -void SvtCJKOptions_Impl::Commit() -{ - Sequence<OUString> &rPropertyNames = PropertyNames::get(); - OUString* pOrgNames = rPropertyNames.getArray(); - sal_Int32 nOrgCount = rPropertyNames.getLength(); - - Sequence< OUString > aNames(nOrgCount); - Sequence< Any > aValues(nOrgCount); - - OUString* pNames = aNames.getArray(); - Any* pValues = aValues.getArray(); - sal_Int32 nRealCount = 0; - - const Type& rType = ::getBooleanCppuType(); - for(int nProp = 0; nProp < nOrgCount; nProp++) - { - switch(nProp) - { - case 0: - { - if (!bROCJKFont) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bCJKFont, rType); - ++nRealCount; - } - } - break; - - case 1: - { - if (!bROVerticalText) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bVerticalText, rType); - ++nRealCount; - } - } - break; - - case 2: - { - if (!bROAsianTypography) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bAsianTypography, rType); - ++nRealCount; - } - } - break; - - case 3: - { - if (!bROJapaneseFind) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bJapaneseFind, rType); - ++nRealCount; - } - } - break; - - case 4: - { - if (!bRORuby) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bRuby, rType); - ++nRealCount; - } - } - break; - - case 5: - { - if (!bROChangeCaseMap) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bChangeCaseMap, rType); - ++nRealCount; - } - } - break; - - case 6: - { - if (!bRODoubleLines) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bDoubleLines, rType); - ++nRealCount; - } - } - break; - - case 7: - { - if (!bROEmphasisMarks) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bEmphasisMarks, rType); - ++nRealCount; - } - } - break; - - case 8: - { - if (!bROVerticalCallOut) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue(&bVerticalCallOut, rType); - ++nRealCount; - } - } - break; - } - } - aNames.realloc(nRealCount); - aValues.realloc(nRealCount); - PutProperties(aNames, aValues); -} - -sal_Bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption) const -{ - sal_Bool bReadOnly = CFG_READONLY_DEFAULT; - switch(eOption) - { - case SvtCJKOptions::E_CJKFONT : bReadOnly = bROCJKFont; break; - case SvtCJKOptions::E_VERTICALTEXT : bReadOnly = bROVerticalText; break; - case SvtCJKOptions::E_ASIANTYPOGRAPHY : bReadOnly = bROAsianTypography; break; - case SvtCJKOptions::E_JAPANESEFIND : bReadOnly = bROJapaneseFind; break; - case SvtCJKOptions::E_RUBY : bReadOnly = bRORuby; break; - case SvtCJKOptions::E_CHANGECASEMAP : bReadOnly = bROChangeCaseMap; break; - case SvtCJKOptions::E_DOUBLELINES : bReadOnly = bRODoubleLines; break; - case SvtCJKOptions::E_EMPHASISMARKS : bReadOnly = bROEmphasisMarks; break; - case SvtCJKOptions::E_VERTICALCALLOUT : bReadOnly = bROVerticalCallOut; break; - case SvtCJKOptions::E_ALL : if (bROCJKFont || bROVerticalText || bROAsianTypography || bROJapaneseFind || bRORuby || bROChangeCaseMap || bRODoubleLines || bROEmphasisMarks || bROVerticalCallOut) - bReadOnly = sal_True; - break; - } - return bReadOnly; -} - -// global ---------------------------------------------------------------- - -static SvtCJKOptions_Impl* pCJKOptions = NULL; -static sal_Int32 nCJKRefCount = 0; -namespace { struct theCJKOptionsMutex : public rtl::Static< ::osl::Mutex , theCJKOptionsMutex >{}; } - - -// class SvtCJKOptions -------------------------------------------------- - -SvtCJKOptions::SvtCJKOptions(sal_Bool bDontLoad) -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() ); - if ( !pCJKOptions ) - { - pCJKOptions = new SvtCJKOptions_Impl; - ItemHolder2::holdConfigItem(E_CJKOPTIONS); - } - if( !bDontLoad && !pCJKOptions->IsLoaded()) - pCJKOptions->Load(); - - ++nCJKRefCount; - pImp = pCJKOptions; -} - -// ----------------------------------------------------------------------- - -SvtCJKOptions::~SvtCJKOptions() -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() ); - if ( !--nCJKRefCount ) - DELETEZ( pCJKOptions ); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsCJKFontEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsCJKFontEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsVerticalTextEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsVerticalTextEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsAsianTypographyEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsAsianTypographyEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsJapaneseFindEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsJapaneseFindEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsRubyEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsRubyEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsChangeCaseMapEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsChangeCaseMapEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsDoubleLinesEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsDoubleLinesEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsEmphasisMarksEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsEmphasisMarksEnabled(); -} -// ----------------------------------------------------------------------- -sal_Bool SvtCJKOptions::IsVerticalCallOutEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsVerticalCallOutEnabled(); -} - -void SvtCJKOptions::SetAll(sal_Bool bSet) -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - pCJKOptions->SetAll(bSet); -} - -sal_Bool SvtCJKOptions::IsAnyEnabled() const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsAnyEnabled(); -} - -sal_Bool SvtCJKOptions::IsReadOnly(EOption eOption) const -{ - DBG_ASSERT(pCJKOptions->IsLoaded(), "CJK options not loaded"); - return pCJKOptions->IsReadOnly(eOption); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/ctloptions.cxx b/svl/source/config/ctloptions.cxx deleted file mode 100644 index 2a771f50d4..0000000000 --- a/svl/source/config/ctloptions.cxx +++ /dev/null @@ -1,494 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/ctloptions.hxx> - -#include <svl/languageoptions.hxx> -#include <i18npool/mslangid.hxx> -#include <unotools/configitem.hxx> -#include <tools/debug.hxx> -#include <com/sun/star/uno/Any.h> -#include <com/sun/star/uno/Sequence.hxx> -#include <osl/mutex.hxx> -#include <osl/mutex.hxx> -#include <svl/smplhint.hxx> -#include <rtl/instance.hxx> -#include <unotools/syslocale.hxx> -#include <itemholder2.hxx> - -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; - -#define ASCII_STR(s) rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(s) ) -#define CFG_READONLY_DEFAULT sal_False - -// SvtCJKOptions_Impl ---------------------------------------------------------- - -class SvtCTLOptions_Impl : public utl::ConfigItem -{ -private: - sal_Bool m_bIsLoaded; - sal_Bool m_bCTLFontEnabled; - sal_Bool m_bCTLSequenceChecking; - sal_Bool m_bCTLRestricted; - sal_Bool m_bCTLTypeAndReplace; - SvtCTLOptions::CursorMovement m_eCTLCursorMovement; - SvtCTLOptions::TextNumerals m_eCTLTextNumerals; - - sal_Bool m_bROCTLFontEnabled; - sal_Bool m_bROCTLSequenceChecking; - sal_Bool m_bROCTLRestricted; - sal_Bool m_bROCTLTypeAndReplace; - sal_Bool m_bROCTLCursorMovement; - sal_Bool m_bROCTLTextNumerals; - -public: - SvtCTLOptions_Impl(); - ~SvtCTLOptions_Impl(); - - virtual void Notify( const Sequence< rtl::OUString >& _aPropertyNames ); - virtual void Commit(); - void Load(); - - sal_Bool IsLoaded() { return m_bIsLoaded; } - void SetCTLFontEnabled( sal_Bool _bEnabled ); - sal_Bool IsCTLFontEnabled() const { return m_bCTLFontEnabled; } - - void SetCTLSequenceChecking( sal_Bool _bEnabled ); - sal_Bool IsCTLSequenceChecking() const { return m_bCTLSequenceChecking;} - - void SetCTLSequenceCheckingRestricted( sal_Bool _bEnable ); - sal_Bool IsCTLSequenceCheckingRestricted( void ) const { return m_bCTLRestricted; } - - void SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable ); - sal_Bool IsCTLSequenceCheckingTypeAndReplace() const { return m_bCTLTypeAndReplace; } - - void SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement ); - SvtCTLOptions::CursorMovement - GetCTLCursorMovement() const { return m_eCTLCursorMovement; } - - void SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals ); - SvtCTLOptions::TextNumerals - GetCTLTextNumerals() const { return m_eCTLTextNumerals; } - - sal_Bool IsReadOnly(SvtCTLOptions::EOption eOption) const; -}; -//------------------------------------------------------------------------------ -namespace -{ - struct PropertyNames - : public rtl::Static< Sequence< rtl::OUString >, PropertyNames > {}; -} -//------------------------------------------------------------------------------ -sal_Bool SvtCTLOptions_Impl::IsReadOnly(SvtCTLOptions::EOption eOption) const -{ - sal_Bool bReadOnly = CFG_READONLY_DEFAULT; - switch(eOption) - { - case SvtCTLOptions::E_CTLFONT : bReadOnly = m_bROCTLFontEnabled ; break; - case SvtCTLOptions::E_CTLSEQUENCECHECKING : bReadOnly = m_bROCTLSequenceChecking ; break; - case SvtCTLOptions::E_CTLCURSORMOVEMENT : bReadOnly = m_bROCTLCursorMovement ; break; - case SvtCTLOptions::E_CTLTEXTNUMERALS : bReadOnly = m_bROCTLTextNumerals ; break; - case SvtCTLOptions::E_CTLSEQUENCECHECKINGRESTRICTED: bReadOnly = m_bROCTLRestricted ; break; - case SvtCTLOptions::E_CTLSEQUENCECHECKINGTYPEANDREPLACE: bReadOnly = m_bROCTLTypeAndReplace; break; - default: OSL_FAIL( "SvtCTLOptions_Impl::IsReadOnly() - invalid option" ); - } - return bReadOnly; -} -//------------------------------------------------------------------------------ -SvtCTLOptions_Impl::SvtCTLOptions_Impl() : - - utl::ConfigItem( ASCII_STR("Office.Common/I18N/CTL") ), - - m_bIsLoaded ( sal_False ), - m_bCTLFontEnabled ( sal_False ), - m_bCTLSequenceChecking ( sal_False ), - m_bCTLRestricted ( sal_False ), - m_eCTLCursorMovement ( SvtCTLOptions::MOVEMENT_LOGICAL ), - m_eCTLTextNumerals ( SvtCTLOptions::NUMERALS_ARABIC ), - - m_bROCTLFontEnabled ( CFG_READONLY_DEFAULT ), - m_bROCTLSequenceChecking( CFG_READONLY_DEFAULT ), - m_bROCTLRestricted ( CFG_READONLY_DEFAULT ), - m_bROCTLCursorMovement ( CFG_READONLY_DEFAULT ), - m_bROCTLTextNumerals ( CFG_READONLY_DEFAULT ) -{ -} -//------------------------------------------------------------------------------ -SvtCTLOptions_Impl::~SvtCTLOptions_Impl() -{ - if ( IsModified() == sal_True ) - Commit(); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions_Impl::Notify( const Sequence< rtl::OUString >& ) -{ - Load(); - NotifyListeners(SFX_HINT_CTL_SETTINGS_CHANGED); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions_Impl::Commit() -{ - Sequence< rtl::OUString > &rPropertyNames = PropertyNames::get(); - rtl::OUString* pOrgNames = rPropertyNames.getArray(); - sal_Int32 nOrgCount = rPropertyNames.getLength(); - - Sequence< rtl::OUString > aNames( nOrgCount ); - Sequence< Any > aValues( nOrgCount ); - - rtl::OUString* pNames = aNames.getArray(); - Any* pValues = aValues.getArray(); - sal_Int32 nRealCount = 0; - - const uno::Type& rType = ::getBooleanCppuType(); - - for ( int nProp = 0; nProp < nOrgCount; nProp++ ) - { - switch ( nProp ) - { - case 0: - { - if (!m_bROCTLFontEnabled) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue( &m_bCTLFontEnabled, rType ); - ++nRealCount; - } - } - break; - - case 1: - { - if (!m_bROCTLSequenceChecking) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue( &m_bCTLSequenceChecking, rType ); - ++nRealCount; - } - } - break; - - case 2: - { - if (!m_bROCTLCursorMovement) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount] <<= (sal_Int32)m_eCTLCursorMovement; - ++nRealCount; - } - } - break; - - case 3: - { - if (!m_bROCTLTextNumerals) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount] <<= (sal_Int32)m_eCTLTextNumerals; - ++nRealCount; - } - } - break; - - case 4: - { - if (!m_bROCTLRestricted) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue( &m_bCTLRestricted, rType ); - ++nRealCount; - } - } - break; - case 5: - { - if(!m_bROCTLTypeAndReplace) - { - pNames[nRealCount] = pOrgNames[nProp]; - pValues[nRealCount].setValue( &m_bCTLTypeAndReplace, rType ); - ++nRealCount; - } - } - break; - } - } - aNames.realloc(nRealCount); - aValues.realloc(nRealCount); - PutProperties( aNames, aValues ); - //broadcast changes - NotifyListeners(SFX_HINT_CTL_SETTINGS_CHANGED); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions_Impl::Load() -{ - Sequence< rtl::OUString >& rPropertyNames = PropertyNames::get(); - if ( !rPropertyNames.getLength() ) - { - rPropertyNames.realloc(6); - rtl::OUString* pNames = rPropertyNames.getArray(); - pNames[0] = ASCII_STR("CTLFont"); - pNames[1] = ASCII_STR("CTLSequenceChecking"); - pNames[2] = ASCII_STR("CTLCursorMovement"); - pNames[3] = ASCII_STR("CTLTextNumerals"); - pNames[4] = ASCII_STR("CTLSequenceCheckingRestricted"); - pNames[5] = ASCII_STR("CTLSequenceCheckingTypeAndReplace"); - EnableNotification( rPropertyNames ); - } - Sequence< Any > aValues = GetProperties( rPropertyNames ); - Sequence< sal_Bool > aROStates = GetReadOnlyStates( rPropertyNames ); - const Any* pValues = aValues.getConstArray(); - const sal_Bool* pROStates = aROStates.getConstArray(); - DBG_ASSERT( aValues.getLength() == rPropertyNames.getLength(), "GetProperties failed" ); - DBG_ASSERT( aROStates.getLength() == rPropertyNames.getLength(), "GetReadOnlyStates failed" ); - if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() ) - { - sal_Bool bValue = sal_False; - sal_Int32 nValue = 0; - - for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ ) - { - if ( pValues[nProp].hasValue() ) - { - if ( pValues[nProp] >>= bValue ) - { - switch ( nProp ) - { - case 0: { m_bCTLFontEnabled = bValue; m_bROCTLFontEnabled = pROStates[nProp]; } break; - case 1: { m_bCTLSequenceChecking = bValue; m_bROCTLSequenceChecking = pROStates[nProp]; } break; - case 4: { m_bCTLRestricted = bValue; m_bROCTLRestricted = pROStates[nProp]; } break; - case 5: { m_bCTLTypeAndReplace = bValue; m_bROCTLTypeAndReplace = pROStates[nProp]; } break; - } - } - else if ( pValues[nProp] >>= nValue ) - { - switch ( nProp ) - { - case 2: { m_eCTLCursorMovement = (SvtCTLOptions::CursorMovement)nValue; m_bROCTLCursorMovement = pROStates[nProp]; } break; - case 3: { m_eCTLTextNumerals = (SvtCTLOptions::TextNumerals)nValue; m_bROCTLTextNumerals = pROStates[nProp]; } break; - } - } - } - } - } - sal_uInt16 nType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM); - SvtSystemLanguageOptions aSystemLocaleSettings; - LanguageType eSystemLanguage = aSystemLocaleSettings.GetWin16SystemLanguage(); - sal_uInt16 nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage ); - if( !m_bCTLFontEnabled && (( nType & SCRIPTTYPE_COMPLEX ) || - ((eSystemLanguage != LANGUAGE_SYSTEM) && ( nWinScript & SCRIPTTYPE_COMPLEX ))) ) - { - m_bCTLFontEnabled = sal_True; - sal_uInt16 nLanguage = SvtSysLocale().GetLanguage(); - //enable sequence checking for the appropriate languages - m_bCTLSequenceChecking = m_bCTLRestricted = m_bCTLTypeAndReplace = - (MsLangId::needsSequenceChecking( nLanguage) || - MsLangId::needsSequenceChecking( eSystemLanguage)); - Commit(); - } - m_bIsLoaded = sal_True; -} -//------------------------------------------------------------------------------ -void SvtCTLOptions_Impl::SetCTLFontEnabled( sal_Bool _bEnabled ) -{ - if(!m_bROCTLFontEnabled && m_bCTLFontEnabled != _bEnabled) - { - m_bCTLFontEnabled = _bEnabled; - SetModified(); - NotifyListeners(0); - } -} -//------------------------------------------------------------------------------ -void SvtCTLOptions_Impl::SetCTLSequenceChecking( sal_Bool _bEnabled ) -{ - if(!m_bROCTLSequenceChecking && m_bCTLSequenceChecking != _bEnabled) - { - SetModified(); - m_bCTLSequenceChecking = _bEnabled; - NotifyListeners(0); - } -} -//------------------------------------------------------------------------------ -void SvtCTLOptions_Impl::SetCTLSequenceCheckingRestricted( sal_Bool _bEnabled ) -{ - if(!m_bROCTLRestricted && m_bCTLRestricted != _bEnabled) - { - SetModified(); - m_bCTLRestricted = _bEnabled; - NotifyListeners(0); - } -} -//------------------------------------------------------------------------------ -void SvtCTLOptions_Impl::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnabled ) -{ - if(!m_bROCTLTypeAndReplace && m_bCTLTypeAndReplace != _bEnabled) - { - SetModified(); - m_bCTLTypeAndReplace = _bEnabled; - NotifyListeners(0); - } -} -//------------------------------------------------------------------------------ -void SvtCTLOptions_Impl::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement ) -{ - if (!m_bROCTLCursorMovement && m_eCTLCursorMovement != _eMovement ) - { - SetModified(); - m_eCTLCursorMovement = _eMovement; - NotifyListeners(0); - } -} -//------------------------------------------------------------------------------ -void SvtCTLOptions_Impl::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals ) -{ - if (!m_bROCTLTextNumerals && m_eCTLTextNumerals != _eNumerals ) - { - SetModified(); - m_eCTLTextNumerals = _eNumerals; - NotifyListeners(0); - } -} -// global ---------------------------------------------------------------- - -static SvtCTLOptions_Impl* pCTLOptions = NULL; -static sal_Int32 nCTLRefCount = 0; -namespace { struct CTLMutex : public rtl::Static< osl::Mutex, CTLMutex > {}; } - -// class SvtCTLOptions -------------------------------------------------- - -SvtCTLOptions::SvtCTLOptions( sal_Bool bDontLoad ) -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( CTLMutex::get() ); - if ( !pCTLOptions ) - { - pCTLOptions = new SvtCTLOptions_Impl; - ItemHolder2::holdConfigItem(E_CTLOPTIONS); - } - if( !bDontLoad && !pCTLOptions->IsLoaded() ) - pCTLOptions->Load(); - - ++nCTLRefCount; - m_pImp = pCTLOptions; - m_pImp->AddListener(this); -} - -// ----------------------------------------------------------------------- - -SvtCTLOptions::~SvtCTLOptions() -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( CTLMutex::get() ); - - m_pImp->RemoveListener(this); - if ( !--nCTLRefCount ) - DELETEZ( pCTLOptions ); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions::SetCTLFontEnabled( sal_Bool _bEnabled ) -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - pCTLOptions->SetCTLFontEnabled( _bEnabled ); -} -// ----------------------------------------------------------------------------- -sal_Bool SvtCTLOptions::IsCTLFontEnabled() const -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - return pCTLOptions->IsCTLFontEnabled(); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions::SetCTLSequenceChecking( sal_Bool _bEnabled ) -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - pCTLOptions->SetCTLSequenceChecking(_bEnabled); -} -// ----------------------------------------------------------------------------- -sal_Bool SvtCTLOptions::IsCTLSequenceChecking() const -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - return pCTLOptions->IsCTLSequenceChecking(); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable ) -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - pCTLOptions->SetCTLSequenceCheckingRestricted(_bEnable); -} -// ----------------------------------------------------------------------------- -sal_Bool SvtCTLOptions::IsCTLSequenceCheckingRestricted( void ) const -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - return pCTLOptions->IsCTLSequenceCheckingRestricted(); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable ) -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - pCTLOptions->SetCTLSequenceCheckingTypeAndReplace(_bEnable); -} -// ----------------------------------------------------------------------------- -sal_Bool SvtCTLOptions::IsCTLSequenceCheckingTypeAndReplace() const -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - return pCTLOptions->IsCTLSequenceCheckingTypeAndReplace(); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement ) -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - pCTLOptions->SetCTLCursorMovement( _eMovement ); -} -// ----------------------------------------------------------------------------- -SvtCTLOptions::CursorMovement SvtCTLOptions::GetCTLCursorMovement() const -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - return pCTLOptions->GetCTLCursorMovement(); -} -// ----------------------------------------------------------------------------- -void SvtCTLOptions::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals ) -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - pCTLOptions->SetCTLTextNumerals( _eNumerals ); -} -// ----------------------------------------------------------------------------- -SvtCTLOptions::TextNumerals SvtCTLOptions::GetCTLTextNumerals() const -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - return pCTLOptions->GetCTLTextNumerals(); -} -// ----------------------------------------------------------------------------- -sal_Bool SvtCTLOptions::IsReadOnly(EOption eOption) const -{ - DBG_ASSERT( pCTLOptions->IsLoaded(), "CTL options not loaded" ); - return pCTLOptions->IsReadOnly(eOption); -} -// ----------------------------------------------------------------------------- - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/itemholder2.cxx b/svl/source/config/itemholder2.cxx deleted file mode 100644 index f508388da7..0000000000 --- a/svl/source/config/itemholder2.cxx +++ /dev/null @@ -1,182 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include "itemholder2.hxx" - -//----------------------------------------------- -// includes -#include <comphelper/processfactory.hxx> -#include <com/sun/star/lang/XComponent.hpp> - -#include <svl/cjkoptions.hxx> -#include <svl/ctloptions.hxx> -#include <svl/languageoptions.hxx> -#include <unotools/options.hxx> - -#include <tools/debug.hxx> - -//----------------------------------------------- -// namespaces - -namespace css = ::com::sun::star; - -//----------------------------------------------- -// declarations - -//----------------------------------------------- -ItemHolder2::ItemHolder2() - : ItemHolderMutexBase() -{ - try - { - css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = ::comphelper::getProcessServiceFactory(); - css::uno::Reference< css::lang::XComponent > xCfg( - xSMGR->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationProvider"))), - css::uno::UNO_QUERY); - if (xCfg.is()) - xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); - } -// #i37892 got errorhandling from ConfigManager::GetConfigurationProvider() - catch(css::uno::RuntimeException& rREx) - { - throw rREx; - } -#ifdef DBG_UTIL - catch(css::uno::Exception& rEx) - { - static sal_Bool bMessage = sal_True; - if(bMessage) - { - bMessage = sal_False; - ::rtl::OString sMsg("CreateInstance with arguments exception: "); - sMsg += ::rtl::OString(rEx.Message.getStr(), - rEx.Message.getLength(), - RTL_TEXTENCODING_ASCII_US); - OSL_FAIL(sMsg.getStr()); - } - } -#else - catch(css::uno::Exception&){} -#endif -} - -//----------------------------------------------- -ItemHolder2::~ItemHolder2() -{ - impl_releaseAllItems(); -} - -//----------------------------------------------- -void ItemHolder2::holdConfigItem(EItem eItem) -{ - static ItemHolder2* pHolder = new ItemHolder2(); - pHolder->impl_addItem(eItem); -} - -//----------------------------------------------- -void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&) - throw(css::uno::RuntimeException) -{ - impl_releaseAllItems(); -} - -//----------------------------------------------- -void ItemHolder2::impl_addItem(EItem eItem) -{ - ::osl::ResettableMutexGuard aLock(m_aLock); - - TItems::const_iterator pIt; - for ( pIt = m_lItems.begin(); - pIt != m_lItems.end() ; - ++pIt ) - { - const TItemInfo& rInfo = *pIt; - if (rInfo.eItem == eItem) - return; - } - - TItemInfo aNewItem; - aNewItem.eItem = eItem; - impl_newItem(aNewItem); - if (aNewItem.pItem) - m_lItems.push_back(aNewItem); -} - -//----------------------------------------------- -void ItemHolder2::impl_releaseAllItems() -{ - ::osl::ResettableMutexGuard aLock(m_aLock); - - TItems::iterator pIt; - for ( pIt = m_lItems.begin(); - pIt != m_lItems.end() ; - ++pIt ) - { - TItemInfo& rInfo = *pIt; - impl_deleteItem(rInfo); - } - m_lItems.clear(); -} - -//----------------------------------------------- -void ItemHolder2::impl_newItem(TItemInfo& rItem) -{ - switch(rItem.eItem) - { - case E_CJKOPTIONS : - rItem.pItem = new SvtCJKOptions(); - break; - - case E_CTLOPTIONS : - rItem.pItem = new SvtCTLOptions(); - break; - - case E_LANGUAGEOPTIONS : -// capsulate CTL and CJL options ! rItem.pItem = new SvtLanguageOptions(); - break; - - default: - OSL_ASSERT(false); - break; - } -} - -//----------------------------------------------- -void ItemHolder2::impl_deleteItem(TItemInfo& rItem) -{ - if (rItem.pItem) - { - delete rItem.pItem; - rItem.pItem = 0; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/itemholder2.hxx b/svl/source/config/itemholder2.hxx deleted file mode 100644 index 25a41788ba..0000000000 --- a/svl/source/config/itemholder2.hxx +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 INCLUDED_SVTOOLS_ITEMHOLDER2_HXX_ -#define INCLUDED_SVTOOLS_ITEMHOLDER2_HXX_ - -//----------------------------------------------- -// includes - -#include <unotools/itemholderbase.hxx> -#include <cppuhelper/implbase1.hxx> -#include <com/sun/star/lang/XEventListener.hpp> - -//----------------------------------------------- -// namespaces - -#ifdef css -#error "Cant use css as namespace alias." -#else -#define css ::com::sun::star -#endif - -//----------------------------------------------- -// definitions - -class ItemHolder2 : private ItemHolderMutexBase - , public ::cppu::WeakImplHelper1< css::lang::XEventListener > -{ - //........................................... - // member - private: - - TItems m_lItems; - - //........................................... - // c++ interface - public: - - ItemHolder2(); - virtual ~ItemHolder2(); - static void holdConfigItem(EItem eItem); - - //........................................... - // uno interface - public: - - virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) - throw(css::uno::RuntimeException); - - //........................................... - // helper - private: - - void impl_addItem(EItem eItem); - void impl_releaseAllItems(); - void impl_newItem(TItemInfo& rItem); - void impl_deleteItem(TItemInfo& rItem); -}; - -//----------------------------------------------- -// namespaces - -#undef css - -#endif // INCLUDED_SVTOOLS_ITEMHOLDER2_HXX_ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/languageoptions.cxx b/svl/source/config/languageoptions.cxx deleted file mode 100644 index bc52aef7a3..0000000000 --- a/svl/source/config/languageoptions.cxx +++ /dev/null @@ -1,259 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/languageoptions.hxx> -#include <svl/cjkoptions.hxx> -#include <svl/ctloptions.hxx> -#include <i18npool/mslangid.hxx> -#include <osl/mutex.hxx> -#include <osl/mutex.hxx> -#include <rtl/instance.hxx> -#include <com/sun/star/i18n/ScriptType.hpp> -#include <unotools/syslocale.hxx> - -using namespace ::com::sun::star; -// global ---------------------------------------------------------------------- - -namespace { struct ALMutex : public rtl::Static< ::osl::Mutex, ALMutex > {}; } - -// class SvtLanguageOptions ---------------------------------------------------- - -SvtLanguageOptions::SvtLanguageOptions( sal_Bool _bDontLoad ) -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( ALMutex::get() ); - - m_pCJKOptions = new SvtCJKOptions( _bDontLoad ); - m_pCTLOptions = new SvtCTLOptions( _bDontLoad ); - m_pCTLOptions->AddListener(this); - m_pCJKOptions->AddListener(this); -} -//------------------------------------------------------------------------------ -SvtLanguageOptions::~SvtLanguageOptions() -{ - // Global access, must be guarded (multithreading) - ::osl::MutexGuard aGuard( ALMutex::get() ); - - m_pCTLOptions->RemoveListener(this); - m_pCJKOptions->RemoveListener(this); - - delete m_pCJKOptions; - delete m_pCTLOptions; -} -//------------------------------------------------------------------------------ -// CJK options ----------------------------------------------------------------- -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsCJKFontEnabled() const -{ - return m_pCJKOptions->IsCJKFontEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsVerticalTextEnabled() const -{ - return m_pCJKOptions->IsVerticalTextEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsAsianTypographyEnabled() const -{ - return m_pCJKOptions->IsAsianTypographyEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsJapaneseFindEnabled() const -{ - return m_pCJKOptions->IsJapaneseFindEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsRubyEnabled() const -{ - return m_pCJKOptions->IsRubyEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsChangeCaseMapEnabled() const -{ - return m_pCJKOptions->IsChangeCaseMapEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsDoubleLinesEnabled() const -{ - return m_pCJKOptions->IsDoubleLinesEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsEmphasisMarksEnabled() const -{ - return m_pCJKOptions->IsEmphasisMarksEnabled(); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsVerticalCallOutEnabled() const -{ - return m_pCJKOptions->IsVerticalCallOutEnabled(); -} -//------------------------------------------------------------------------------ -void SvtLanguageOptions::SetAll( sal_Bool _bSet ) -{ - m_pCJKOptions->SetAll( _bSet ); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsAnyEnabled() const -{ - return m_pCJKOptions->IsAnyEnabled(); -} -//------------------------------------------------------------------------------ -// CTL options ----------------------------------------------------------------- -//------------------------------------------------------------------------------ -void SvtLanguageOptions::SetCTLFontEnabled( sal_Bool _bEnabled ) -{ - m_pCTLOptions->SetCTLFontEnabled( _bEnabled ); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsCTLFontEnabled() const -{ - return m_pCTLOptions->IsCTLFontEnabled(); -} -//------------------------------------------------------------------------------ -void SvtLanguageOptions::SetCTLSequenceChecking( sal_Bool _bEnabled ) -{ - m_pCTLOptions->SetCTLSequenceChecking( _bEnabled ); -} -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsCTLSequenceChecking() const -{ - return m_pCTLOptions->IsCTLSequenceChecking(); -} - -void SvtLanguageOptions::SetCTLSequenceCheckingRestricted( sal_Bool _bEnable ) -{ - m_pCTLOptions->SetCTLSequenceCheckingRestricted( _bEnable ); -} - -sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingRestricted( void ) const -{ - return m_pCTLOptions->IsCTLSequenceCheckingRestricted(); -} - -void SvtLanguageOptions::SetCTLSequenceCheckingTypeAndReplace( sal_Bool _bEnable ) -{ - m_pCTLOptions->SetCTLSequenceCheckingTypeAndReplace( _bEnable ); -} - -sal_Bool SvtLanguageOptions::IsCTLSequenceCheckingTypeAndReplace() const -{ - return m_pCTLOptions->IsCTLSequenceCheckingTypeAndReplace(); -} - -//------------------------------------------------------------------------------ -sal_Bool SvtLanguageOptions::IsReadOnly(SvtLanguageOptions::EOption eOption) const -{ - sal_Bool bReadOnly = sal_False; - switch(eOption) - { - // cjk options - case SvtLanguageOptions::E_CJKFONT : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CJKFONT ); break; - case SvtLanguageOptions::E_VERTICALTEXT : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALTEXT ); break; - case SvtLanguageOptions::E_ASIANTYPOGRAPHY : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ASIANTYPOGRAPHY); break; - case SvtLanguageOptions::E_JAPANESEFIND : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_JAPANESEFIND ); break; - case SvtLanguageOptions::E_RUBY : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_RUBY ); break; - case SvtLanguageOptions::E_CHANGECASEMAP : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_CHANGECASEMAP ); break; - case SvtLanguageOptions::E_DOUBLELINES : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_DOUBLELINES ); break; - case SvtLanguageOptions::E_EMPHASISMARKS : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_EMPHASISMARKS ); break; - case SvtLanguageOptions::E_VERTICALCALLOUT : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_VERTICALCALLOUT); break; - case SvtLanguageOptions::E_ALLCJK : bReadOnly = m_pCJKOptions->IsReadOnly(SvtCJKOptions::E_ALL ); break; - // ctl options - case SvtLanguageOptions::E_CTLFONT : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLFONT ); break; - case SvtLanguageOptions::E_CTLSEQUENCECHECKING : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLSEQUENCECHECKING); break; - case SvtLanguageOptions::E_CTLCURSORMOVEMENT : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLCURSORMOVEMENT ); break; - case SvtLanguageOptions::E_CTLTEXTNUMERALS : bReadOnly = m_pCTLOptions->IsReadOnly(SvtCTLOptions::E_CTLTEXTNUMERALS ); break; - } - return bReadOnly; -} - -// returns for a language the scripttype -sal_uInt16 SvtLanguageOptions::GetScriptTypeOfLanguage( sal_uInt16 nLang ) -{ - if( LANGUAGE_DONTKNOW == nLang ) - nLang = LANGUAGE_ENGLISH_US; - else if( LANGUAGE_SYSTEM == nLang ) - nLang = SvtSysLocale().GetLanguage(); - - sal_Int16 nScriptType = MsLangId::getScriptType( nLang ); - sal_uInt16 nScript; - switch (nScriptType) - { - case ::com::sun::star::i18n::ScriptType::ASIAN: - nScript = SCRIPTTYPE_ASIAN; - break; - case ::com::sun::star::i18n::ScriptType::COMPLEX: - nScript = SCRIPTTYPE_COMPLEX; - break; - default: - nScript = SCRIPTTYPE_LATIN; - } - return nScript; -} -// ----------------------------------------------------------------------------- - -SvtSystemLanguageOptions::SvtSystemLanguageOptions() : - utl::ConfigItem( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("System/L10N") )) -{ - uno::Sequence< rtl::OUString > aPropertyNames(1); - rtl::OUString* pNames = aPropertyNames.getArray(); - pNames[0] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SystemLocale")); - uno::Sequence< uno::Any > aValues = GetProperties( aPropertyNames ); - - if ( aValues.getLength() ) - { - aValues[0]>>= m_sWin16SystemLocale; - } -} - -SvtSystemLanguageOptions::~SvtSystemLanguageOptions() -{ -} - -void SvtSystemLanguageOptions::Commit() -{ - //does nothing -} - -void SvtSystemLanguageOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& ) -{ - // no listeners supported yet -} - - -LanguageType SvtSystemLanguageOptions::GetWin16SystemLanguage() -{ - if( m_sWin16SystemLocale.getLength() == 0 ) - return LANGUAGE_NONE; - return MsLangId::convertIsoStringToLanguage( m_sWin16SystemLocale ); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/filepicker/pickerhistory.cxx b/svl/source/filepicker/pickerhistory.cxx deleted file mode 100644 index a84ec0d4bd..0000000000 --- a/svl/source/filepicker/pickerhistory.cxx +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/pickerhistory.hxx> -#include <svl/pickerhistoryaccess.hxx> -#include <cppuhelper/weakref.hxx> -#include <vector> - -//......................................................................... -namespace svt -{ -//......................................................................... - using namespace ::com::sun::star::uno; - - namespace - { - typedef ::com::sun::star::uno::WeakReference< XInterface > InterfaceAdapter; - typedef ::std::vector< InterfaceAdapter > InterfaceArray; - - // ---------------------------------------------------------------- - InterfaceArray& getFolderPickerHistory() - { - static InterfaceArray s_aHistory; - return s_aHistory; - } - - // ---------------------------------------------------------------- - InterfaceArray& getFilePickerHistory() - { - static InterfaceArray s_aHistory; - return s_aHistory; - } - - // ---------------------------------------------------------------- - void implPushBackPicker( InterfaceArray& _rHistory, const Reference< XInterface >& _rxPicker ) - { - if ( !_rxPicker.is() ) - return; - - //============================================================= - // first, check which of the objects we hold in s_aHistory can be removed - { - InterfaceArray aCleanedHistory; - for ( InterfaceArray::const_iterator aLoop = _rHistory.begin(); - aLoop != _rHistory.end(); - ++aLoop - ) - { - Reference< XInterface > xCurrent( aLoop->get() ); - if ( xCurrent.is() ) - { - if ( aCleanedHistory.empty() ) - // make some room, assume that all interfaces (from here on) are valie - aCleanedHistory.reserve( _rHistory.size() - ( aLoop - _rHistory.begin() ) ); - aCleanedHistory.push_back( InterfaceAdapter( xCurrent ) ); - } - } - _rHistory.swap( aCleanedHistory ); - } - - //============================================================= - // then push_back the picker - _rHistory.push_back( InterfaceAdapter( _rxPicker ) ); - } - - //----------------------------------------------------------------- - Reference< XInterface > implGetTopMostPicker( const InterfaceArray& _rHistory ) - { - Reference< XInterface > xTopMostAlive; - - //============================================================= - // search the first picker which is still alive ... - for ( InterfaceArray::const_reverse_iterator aLoop = _rHistory.rbegin(); - ( aLoop != _rHistory.rend() ) && !xTopMostAlive.is(); - ++aLoop - ) - { - xTopMostAlive = aLoop->get(); - } - - return xTopMostAlive; - } - } - - //--------------------------------------------------------------------- - Reference< XInterface > GetTopMostFolderPicker( ) - { - return implGetTopMostPicker( getFolderPickerHistory() ); - } - - //--------------------------------------------------------------------- - Reference< XInterface > GetTopMostFilePicker( ) - { - return implGetTopMostPicker( getFilePickerHistory() ); - } - - //--------------------------------------------------------------------- - void addFolderPicker( const Reference< XInterface >& _rxPicker ) - { - implPushBackPicker( getFolderPickerHistory(), _rxPicker ); - } - - //--------------------------------------------------------------------- - void addFilePicker( const Reference< XInterface >& _rxPicker ) - { - implPushBackPicker( getFilePickerHistory(), _rxPicker ); - } - -//......................................................................... -} // namespace svt -//......................................................................... - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/filerec/filerec.cxx b/svl/source/filerec/filerec.cxx deleted file mode 100644 index 1e154f9e06..0000000000 --- a/svl/source/filerec/filerec.cxx +++ /dev/null @@ -1,751 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/filerec.hxx> -#include <osl/endian.h> - -//======================================================================== - -SV_IMPL_VARARR( SfxUINT32s, sal_uInt32 ); - -//======================================================================== - -/* Die folgenden Makros extrahieren Teilbereiche aus einem sal_uInt32 Wert. - Diese sal_uInt32-Werte werden anstelle der einzelnen Werte gestreamt, - um Calls zu sparen. -*/ - -#define SFX_REC_PRE(n) ( ((n) & 0x000000FF) ) -#define SFX_REC_OFS(n) ( ((n) & 0xFFFFFF00) >> 8 ) -#define SFX_REC_TYP(n) ( ((n) & 0x000000FF) ) -#define SFX_REC_VER(n) ( ((n) & 0x0000FF00) >> 8 ) -#define SFX_REC_TAG(n) ( ((n) & 0xFFFF0000) >> 16 ) - -#define SFX_REC_CONTENT_VER(n) ( ((n) & 0x000000FF) ) -#define SFX_REC_CONTENT_OFS(n) ( ((n) & 0xFFFFFF00) >> 8 ) - -//------------------------------------------------------------------------- - -/* Die folgenden Makros setzen Teilbereiche zu einem sal_uInt32 Wert zusammen. - Diese sal_uInt32-Werte werden anstelle der einzelnen Werte gestreamt, - um Calls zu sparen. -*/ - -#define SFX_REC_MINI_HEADER(nPreTag,nStartPos,nEndPos) \ - ( sal_uInt32(nPreTag) | \ - sal_uInt32(nEndPos-nStartPos-SFX_REC_HEADERSIZE_MINI) << 8 ) - -#define SFX_REC_HEADER(nRecType,nContentTag,nContentVer) \ - ( sal_uInt32(nRecType) | \ - ( sal_uInt32(nContentVer) << 8 ) | \ - ( sal_uInt32(nContentTag) << 16 ) ) - -#define SFX_REC_CONTENT_HEADER(nContentVer,n1StStartPos,nCurStartPos) \ - ( sal_uInt32(nContentVer) | \ - sal_uInt32( nCurStartPos - n1StStartPos ) << 8 ) - -//========================================================================= - -sal_uInt32 SfxMiniRecordWriter::Close -( - bool bSeekToEndOfRec /* true (default) - Der Stream wird an das Ende des Records - positioniert. - - false - Der Stream wird an den Anfang des - Contents (also hinter den Header) - positioniert. - */ -) - -/* [Beschreibung] - - Diese Methode schlie\st den Record. Dabei wird haupts"achlich der - Header geschrieben. - - Wurde der Header bereits geschrieben, hat der Aufruf keine Wirkung. - - - [R"uckgabewert] - - sal_uInt32 != 0 - Position im Stream, die direkt hinter dem Record liegt. - 'bSeekToEndOfRecord==sal_True' - => R"uckgabewert == aktuelle Stream-Position nach Aufruf - - == 0 - Der Header war bereits geschrieben worden. -*/ - -{ - // wurde der Header noch nicht geschrieben? - if ( !_bHeaderOk ) - { - // Header an den Anfang des Records schreiben - sal_uInt32 nEndPos = _pStream->Tell(); - _pStream->Seek( _nStartPos ); - *_pStream << SFX_REC_MINI_HEADER( _nPreTag, _nStartPos, nEndPos ); - - // je nachdem ans Ende des Records seeken oder hinter Header bleiben - if ( bSeekToEndOfRec ) - _pStream->Seek( nEndPos ); - - // Header wurde JETZT geschrieben - _bHeaderOk = true; - return nEndPos; - } - - // Record war bereits geschlossen - return 0; -} - -bool SfxMiniRecordReader::SetHeader_Impl( sal_uInt32 nHeader ) - -/* [Beschreibung] - - Interne Methode zum nachtr"aglichen Verarbeiten eines extern gelesenen - Headers. Falls der Header eine End-Of-Records-Kennung darstellt, - wird am Stream ein Errorcode gesetzt und sal_False zur"uckgeliefert. Im - Fehlerfall wird der Stream jedoch nicht auf den Record-Anfang zur"uck- - gesetzt. -*/ - -{ - bool bRet = true; - - // Record-Ende und Pre-Tag aus dem Header ermitteln - _nEofRec = _pStream->Tell() + SFX_REC_OFS(nHeader); - _nPreTag = sal::static_int_cast< sal_uInt8 >(SFX_REC_PRE(nHeader)); - - // wenn End-Of-Record-Kennung, dann Fehler - if ( _nPreTag == SFX_REC_PRETAG_EOR ) - { - _pStream->SetError( ERRCODE_IO_WRONGFORMAT ); - bRet = true; - } - return bRet; -} - -SfxMiniRecordReader::SfxMiniRecordReader -( - SvStream* pStream, /* <SvStream>, an dessen aktueller - Position sich ein <SfxMiniRecord> - befindet. - */ - sal_uInt8 nTag // Pre-Tag des gew"unschten Records -) - -/* [Beschreibung] - - Dieser Ctor interpretiert 'pStream' ab der aktuellen Position als - eine l"uckenlose Folge von, von dieser Klassen-Gruppe interpretierbaren, - Records. Der in dieser Folge erste als <SfxMiniRecord> interpretierbare - (also ggf. auch ein extended-Record) mit dem PreTag 'nTag' wird ge"offnet - und durch diese Instanz repr"asentiert. - - Wird das Ende des Streams oder die Kennung SFX_REC_PRETAG_EOR - erreicht, bevor ein Record mit dem ge"unschten Pre-Tag gefunden wird, - ist die erzeugte Instanz ung"ultig ('IsValid() == sal_False'). Ein ent- - sprechender Error-Code (ERRCODE_IO_EOF bzw. ERRCODE_IO_WRONGFORMAT) - ist dann am Stream gesetzt, dessen Position ist dann au\serdem unver- - "andert. - - Bei 'nTag==SFX_FILEREC_PRETAG_EOR' wird nicht versucht, einen Record - zu lesen, es wird sofort 'IsValid()' auf sal_False gesetzt und kein Error-Code - am Stream gesetzt. Dies ist dauzu gedacht, ohne 'new' und 'delete' - abw"rtskompatibel SfxMiniRecords einbauen zu k"onnen. Siehe dazu - <SfxItemSet::Load()>. - - - [Anwendungsvorschlag] - - Wird dieser Ctor in einer bereits ausgelieferten Programmversion - verwendet, k"onnen in das File-Format jeweils davor kompatibel neue - Records mit einer anderen Kennung eingef"ugt werden. Diese werden - schlie\slich automatisch "uberlesen. Erkauft wird diese M"oglichkeit - allerdings mit etwas schlechterem Laufzeitverhalten im Vergleich mit - direktem 'drauf-los-lesen', der sich jedoch auf einen Vergleich zweier - Bytes reduziert, falls der gesuchte Record der erste in der Folge ist. -*/ - -: _pStream( pStream ), - _bSkipped( nTag == SFX_REC_PRETAG_EOR ) -{ - // ggf. ignorieren (s.o.) - if ( _bSkipped ) - { - _nPreTag = nTag; - return; - } - - // StartPos merken, um im Fehlerfall zur"uck-seeken zu k"onnen - sal_uInt32 nStartPos = pStream->Tell(); - - // passenden Record suchen - while(sal_True) - { - // Header lesen - DBG( DbgOutf( "SfxFileRec: searching record at %ul", pStream->Tell() ) ); - sal_uInt32 nHeader; - *pStream >> nHeader; - - // Headerdaten von Basisklasse extrahieren lassen - SetHeader_Impl( nHeader ); - - // ggf. Fehler behandeln - if ( pStream->IsEof() ) - _nPreTag = SFX_REC_PRETAG_EOR; - else if ( _nPreTag == SFX_REC_PRETAG_EOR ) - pStream->SetError( ERRCODE_IO_WRONGFORMAT ); - else - { - // wenn gefunden, dann Schleife abbrechen - if ( _nPreTag == nTag ) - break; - - // sonst skippen und weitersuchen - pStream->Seek( _nEofRec ); - continue; - } - - // Fehler => zur"uck-seeken - pStream->Seek( nStartPos ); - break; - } -} - -//========================================================================= - -SfxSingleRecordWriter::SfxSingleRecordWriter -( - sal_uInt8 nRecordType, // f"ur Subklassen - SvStream* pStream, // Stream, in dem der Record angelegt wird - sal_uInt16 nContentTag, // Inhalts-Art-Kennung - sal_uInt8 nContentVer // Inhalts-Versions-Kennung -) - -/* [Beschreibung] - - Interner Ctor f"ur Subklassen. -*/ - -: SfxMiniRecordWriter( pStream, SFX_REC_PRETAG_EXT ) -{ - // Erweiterten Header hiner den des SfxMiniRec schreiben - *pStream << SFX_REC_HEADER(nRecordType, nContentTag, nContentVer); -} - -//------------------------------------------------------------------------- - -SfxSingleRecordWriter::SfxSingleRecordWriter -( - SvStream* pStream, // Stream, in dem der Record angelegt wird - sal_uInt16 nContentTag, // Inhalts-Art-Kennung - sal_uInt8 nContentVer // Inhalts-Versions-Kennung -) - -/* [Beschreibung] - - Legt in 'pStream' einen 'SfxSingleRecord' an, dessen Content-Gr"o\se - nicht bekannt ist, sondern nach dam Streamen des Contents errechnet - werden soll. -*/ - -: SfxMiniRecordWriter( pStream, SFX_REC_PRETAG_EXT ) -{ - // Erweiterten Header hiner den des SfxMiniRec schreiben - *pStream << SFX_REC_HEADER( SFX_REC_TYPE_SINGLE, nContentTag, nContentVer); -} - -//========================================================================= - -inline bool SfxSingleRecordReader::ReadHeader_Impl( sal_uInt16 nTypes ) - -/* [Beschreibung] - - Interne Methode zum Einlesen eines SfxMultiRecord-Headers, nachdem - die Basisklasse bereits initialisiert und deren Header gelesen ist. - Ggf. ist ein Error-Code am Stream gesetzt, im Fehlerfall wird jedoch - nicht zur"uckge-seekt. -*/ - -{ - bool bRet; - - // Basisklassen-Header einlesen - sal_uInt32 nHeader=0; - *_pStream >> nHeader; - if ( !SetHeader_Impl( nHeader ) ) - bRet = false; - else - { - // eigenen Header einlesen - *_pStream >> nHeader; - _nRecordVer = sal::static_int_cast< sal_uInt8 >(SFX_REC_VER(nHeader)); - _nRecordTag = sal::static_int_cast< sal_uInt16 >(SFX_REC_TAG(nHeader)); - - // falscher Record-Typ? - _nRecordType = sal::static_int_cast< sal_uInt8 >(SFX_REC_TYP(nHeader)); - bRet = 0 != ( nTypes & _nRecordType); - } - return bRet; -} - -//------------------------------------------------------------------------- - -SfxSingleRecordReader::SfxSingleRecordReader( SvStream *pStream, sal_uInt16 nTag ) -{ - // StartPos merken, um im Fehlerfall zur"uck-seeken zu k"onnen - sal_uInt32 nStartPos = pStream->Tell(); - - // richtigen Record suchen, ggf. Error-Code setzen und zur"uck-seeken - Construct_Impl( pStream ); - if ( !FindHeader_Impl( SFX_REC_TYPE_SINGLE, nTag ) ) - { - // Error-Code setzen und zur"uck-seeken - pStream->Seek( nStartPos ); - pStream->SetError( ERRCODE_IO_WRONGFORMAT ); - } -} - -//------------------------------------------------------------------------- - -bool SfxSingleRecordReader::FindHeader_Impl -( - sal_uInt16 nTypes, // arithm. Veroderung erlaubter Record-Typen - sal_uInt16 nTag // zu findende Record-Art-Kennung -) - -/* [Beschreibung] - - Interne Methode zum lesen des Headers des ersten Record, der einem - der Typen in 'nTypes' entspricht und mit der Art-Kennung 'nTag' - gekennzeichnet ist. - - Kann ein solcher Record nicht gefunden werden, wird am Stream ein - Errorcode gesetzt, zur"uck-geseekt und sal_False zur"uckgeliefert. -*/ - -{ - // StartPos merken, um im Fehlerfall zur"uck-seeken zu k"onnen - sal_uInt32 nStartPos = _pStream->Tell(); - - // richtigen Record suchen - while ( !_pStream->IsEof() ) - { - // Header lesen - sal_uInt32 nHeader; - DBG( DbgOutf( "SfxFileRec: searching record at %ul", _pStream->Tell() ) ); - *_pStream >> nHeader; - if ( !SetHeader_Impl( nHeader ) ) - // EOR => Such-Schleife abbreichen - break; - - // Extended Record gefunden? - if ( _nPreTag == SFX_REC_PRETAG_EXT ) - { - // Extended Header lesen - *_pStream >> nHeader; - _nRecordTag = sal::static_int_cast< sal_uInt16 >(SFX_REC_TAG(nHeader)); - - // richtigen Record gefunden? - if ( _nRecordTag == nTag ) - { - // gefundener Record-Typ passend? - _nRecordType = sal::static_int_cast< sal_uInt8 >( - SFX_REC_TYP(nHeader)); - if ( nTypes & _nRecordType ) - // ==> gefunden - return sal_True; - - // error => Such-Schleife abbrechen - break; - } - } - - // sonst skippen - if ( !_pStream->IsEof() ) - _pStream->Seek( _nEofRec ); - } - - // Fehler setzen und zur"uck-seeken - _pStream->SetError( ERRCODE_IO_WRONGFORMAT ); - _pStream->Seek( nStartPos ); - return sal_False; -} - -//========================================================================= - -SfxMultiFixRecordWriter::SfxMultiFixRecordWriter -( - sal_uInt8 nRecordType, // Subklassen Record-Kennung - SvStream* pStream, // Stream, in dem der Record angelegt wird - sal_uInt16 nContentTag, // Content-Art-Kennung - sal_uInt8 nContentVer, // Content-Versions-Kennung - sal_uInt32 // Gr"o\se jedes einzelnen Contents in Bytes -) - -/* [Beschreibung] - - Interne Methode f"ur Subklassen. -*/ - -: SfxSingleRecordWriter( nRecordType, pStream, nContentTag, nContentVer ), - _nContentCount( 0 ) -{ - // Platz f"ur eigenen Header - pStream->SeekRel( + SFX_REC_HEADERSIZE_MULTI ); -} - -//------------------------------------------------------------------------ - -sal_uInt32 SfxMultiFixRecordWriter::Close( bool bSeekToEndOfRec ) - -// siehe <SfxMiniRecordWriter> - -{ - // Header noch nicht geschrieben? - if ( !_bHeaderOk ) - { - // Position hinter Record merken, um sie restaurieren zu k"onnen - sal_uInt32 nEndPos = SfxSingleRecordWriter::Close( sal_False ); - - // gegen"uber SfxSingleRecord erweiterten Header schreiben - *_pStream << _nContentCount; - *_pStream << _nContentSize; - - // je nachdem ans Ende des Records seeken oder hinter Header bleiben - if ( bSeekToEndOfRec ) - _pStream->Seek(nEndPos); - return nEndPos; - } - - // Record war bereits geschlossen - return 0; -} - -//========================================================================= - -SfxMultiVarRecordWriter::SfxMultiVarRecordWriter -( - sal_uInt8 nRecordType, // Record-Kennung der Subklasse - SvStream* pStream, // Stream, in dem der Record angelegt wird - sal_uInt16 nRecordTag, // Gesamt-Art-Kennung - sal_uInt8 nRecordVer // Gesamt-Versions-Kennung -) - -/* [Beschreibung] - - Interner Ctor f"ur Subklassen. -*/ - -: SfxMultiFixRecordWriter( nRecordType, pStream, nRecordTag, nRecordVer, 0 ), - _nContentVer( 0 ) -{ -} - -//------------------------------------------------------------------------- - -SfxMultiVarRecordWriter::SfxMultiVarRecordWriter -( - SvStream* pStream, // Stream, in dem der Record angelegt wird - sal_uInt16 nRecordTag, // Gesamt-Art-Kennung - sal_uInt8 nRecordVer // Gesamt-Versions-Kennung -) - -/* [Beschreibung] - - Legt in 'pStream' einen 'SfxMultiVarRecord' an, dessen Content-Gr"o\sen - weder bekannt sind noch identisch sein m"ussen, sondern jeweils nach dem - Streamen jedes einzelnen Contents errechnet werden sollen. - - - [Anmerkung] - - Diese Methode ist nicht inline, da f"ur die Initialisierung eines - <SvULongs>-Members zu viel Code generiert werden w"urde. -*/ - -: SfxMultiFixRecordWriter( SFX_REC_TYPE_VARSIZE, - pStream, nRecordTag, nRecordVer, 0 ), - _nContentVer( 0 ) -{ -} - -//------------------------------------------------------------------------- - -SfxMultiVarRecordWriter::~SfxMultiVarRecordWriter() - -/* [Beschreibung] - - Der Dtor der Klasse <SfxMultiVarRecordWriter> schlie\st den Record - automatisch, falls <SfxMultiVarRecordWriter::Close()> nicht bereits - explizit gerufen wurde. -*/ - -{ - // wurde der Header noch nicht geschrieben oder mu\s er gepr"uft werden - if ( !_bHeaderOk ) - Close(); -} - -//------------------------------------------------------------------------- - -void SfxMultiVarRecordWriter::FlushContent_Impl() - -/* [Beschreibung] - - Interne Methode zum Abschlie\sen eines einzelnen Contents. -*/ - -{ - // Versions-Kennung und Positions-Offset des aktuellen Contents merken; - // das Positions-Offset ist relativ zur Startposition des ersten Contents - _aContentOfs.Insert( - SFX_REC_CONTENT_HEADER(_nContentVer,_nStartPos,_nContentStartPos), - _nContentCount-1 ); -} - -//------------------------------------------------------------------------- - -void SfxMultiVarRecordWriter::NewContent() - -// siehe <SfxMultiFixRecordWriter> - -{ - // schon ein Content geschrieben? - if ( _nContentCount ) - FlushContent_Impl(); - - // neuen Content beginnen - _nContentStartPos = _pStream->Tell(); - ++_nContentCount; -} - -//------------------------------------------------------------------------- - -sal_uInt32 SfxMultiVarRecordWriter::Close( bool bSeekToEndOfRec ) - -// siehe <SfxMiniRecordWriter> - -{ - // Header noch nicht geschrieben? - if ( !_bHeaderOk ) - { - // ggf. letzten Content abschlie\sen - if ( _nContentCount ) - FlushContent_Impl(); - - // Content-Offset-Tabelle schreiben - sal_uInt32 nContentOfsPos = _pStream->Tell(); - //! darf man das so einr"ucken? - #if defined(OSL_LITENDIAN) - _pStream->Write( _aContentOfs.GetData(), - sizeof(sal_uInt32)*_nContentCount ); - #else - for ( sal_uInt16 n = 0; n < _nContentCount; ++n ) - *_pStream << sal_uInt32(_aContentOfs[n]); - #endif - - // SfxMultiFixRecordWriter::Close() "uberspringen! - sal_uInt32 nEndPos = SfxSingleRecordWriter::Close( sal_False ); - - // eigenen Header schreiben - *_pStream << _nContentCount; - if ( SFX_REC_TYPE_VARSIZE_RELOC == _nPreTag || - SFX_REC_TYPE_MIXTAGS_RELOC == _nPreTag ) - *_pStream << static_cast<sal_uInt32>(nContentOfsPos - ( _pStream->Tell() + sizeof(sal_uInt32) )); - else - *_pStream << nContentOfsPos; - - // ans Ende des Records seeken bzw. am Ende des Headers bleiben - if ( bSeekToEndOfRec ) - _pStream->Seek(nEndPos); - return nEndPos; - } - - // Record war bereits vorher geschlossen - return 0; -} - -//========================================================================= - -void SfxMultiMixRecordWriter::NewContent -( - sal_uInt16 nContentTag, // Kennung f"ur die Art des Contents - sal_uInt8 nContentVer // Kennung f"ur die Version des Contents -) - -/* [Beschreibung] - - Mit dieser Methode wird in den Record ein neuer Content eingef"ugt - und dessen Content-Tag sowie dessen Content-Version angegeben. Jeder, - auch der 1. Record mu\s durch Aufruf dieser Methode eingeleitet werden. -*/ - -{ - // ggf. vorherigen Record abschlie\sen - if ( _nContentCount ) - FlushContent_Impl(); - - // Tag vor den Content schreiben, Version und Startposition merken - _nContentStartPos = _pStream->Tell(); - ++_nContentCount; - *_pStream << nContentTag; - _nContentVer = nContentVer; -} - -//========================================================================= - -bool SfxMultiRecordReader::ReadHeader_Impl() - -/* [Beschreibung] - - Interne Methode zum Einlesen eines SfxMultiRecord-Headers, nachdem - die Basisklasse bereits initialisiert und deren Header gelesen ist. - Ggf. ist ein Error-Code am Stream gesetzt, im Fehlerfall wird jedoch - nicht zur"uckge-seekt. -*/ - -{ - // eigenen Header lesen - *_pStream >> _nContentCount; - *_pStream >> _nContentSize; // Fix: jedes einzelnen, Var|Mix: Tabellen-Pos. - - // mu\s noch eine Tabelle mit Content-Offsets geladen werden? - if ( _nRecordType != SFX_REC_TYPE_FIXSIZE ) - { - // Tabelle aus dem Stream einlesen - sal_uInt32 nContentPos = _pStream->Tell(); - if ( _nRecordType == SFX_REC_TYPE_VARSIZE_RELOC || - _nRecordType == SFX_REC_TYPE_MIXTAGS_RELOC ) - _pStream->SeekRel( + _nContentSize ); - else - _pStream->Seek( _nContentSize ); - _pContentOfs = new sal_uInt32[_nContentCount]; - memset(_pContentOfs, 0, _nContentCount*sizeof(sal_uInt32)); - //! darf man jetzt so einr"ucken - #if defined(OSL_LITENDIAN) - _pStream->Read( _pContentOfs, sizeof(sal_uInt32)*_nContentCount ); - #else - for ( sal_uInt16 n = 0; n < _nContentCount; ++n ) - *_pStream >> _pContentOfs[n]; - #endif - _pStream->Seek( nContentPos ); - } - - // Header konnte gelesen werden, wenn am Stream kein Error gesetzt ist - return !_pStream->GetError(); -} - -//------------------------------------------------------------------------- - -SfxMultiRecordReader::SfxMultiRecordReader( SvStream *pStream, sal_uInt16 nTag ) -: _nContentNo(0) -{ - // Position im Stream merken, um im Fehlerfall zur"uck-seeken zu k"onnen - _nStartPos = pStream->Tell(); - - // passenden Record suchen und Basisklasse initialisieren - SfxSingleRecordReader::Construct_Impl( pStream ); - if ( SfxSingleRecordReader::FindHeader_Impl( SFX_REC_TYPE_FIXSIZE | - SFX_REC_TYPE_VARSIZE | SFX_REC_TYPE_VARSIZE_RELOC | - SFX_REC_TYPE_MIXTAGS | SFX_REC_TYPE_MIXTAGS_RELOC, - nTag ) ) - { - // eigenen Header dazu-lesen - if ( !ReadHeader_Impl() ) - // nicht lesbar => als ung"ultig markieren und zur"uck-seeken - SetInvalid_Impl( _nStartPos); - } -} - -//------------------------------------------------------------------------- - -SfxMultiRecordReader::~SfxMultiRecordReader() -{ - delete[] _pContentOfs; -} - -//------------------------------------------------------------------------- - -bool SfxMultiRecordReader::GetContent() - -/* [Beschreibung] - - Positioniert den Stream an den Anfang des n"chsten bzw. beim 1. Aufruf - auf den Anfang des ersten Contents im Record und liest ggf. dessen - Header ein. - - Liegt laut Record-Header kein Content mehr vor, wird sal_False zur"uck- - gegeben. Trotz einem sal_True-Returnwert kann am Stream ein Fehlercode - gesetzt sein, z.B. falls er unvorhergesehenerweise (kaputtes File) - zuende ist. -*/ - -{ - // noch ein Content vorhanden? - if ( _nContentNo < _nContentCount ) - { - // den Stream an den Anfang des Contents positionieren - sal_uInt32 nOffset = _nRecordType == SFX_REC_TYPE_FIXSIZE - ? _nContentNo * _nContentSize - : SFX_REC_CONTENT_OFS(_pContentOfs[_nContentNo]); - sal_uInt32 nNewPos = _nStartPos + nOffset; - DBG_ASSERT( nNewPos >= _pStream->Tell(), "SfxMultiRecordReader::GetContent() - New position before current, to much data red!" ); - - // #99366#: correct stream pos in every case; - // the if clause was added by MT a long time ago, - // maybe to 'repair' other corrupt documents; but this - // gives errors when writing with 5.1 and reading with current - // versions, so we decided to remove the if clause (KA-05/17/2002) - // if ( nNewPos > _pStream->Tell() ) - _pStream->Seek( nNewPos ); - - // ggf. Content-Header lesen - if ( _nRecordType == SFX_REC_TYPE_MIXTAGS || - _nRecordType == SFX_REC_TYPE_MIXTAGS_RELOC ) - { - _nContentVer = sal::static_int_cast< sal_uInt8 >( - SFX_REC_CONTENT_VER(_pContentOfs[_nContentNo])); - *_pStream >> _nContentTag; - } - - // ContentNo weiterz"ahlen - ++_nContentNo; - return sal_True; - } - - return sal_False; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/fsfactory.cxx b/svl/source/fsstor/fsfactory.cxx deleted file mode 100644 index 69ac09ee70..0000000000 --- a/svl/source/fsstor/fsfactory.cxx +++ /dev/null @@ -1,264 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include "fsfactory.hxx" -#include "cppuhelper/factory.hxx" -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/io/XSeekable.hpp> - - -#include <ucbhelper/fileidentifierconverter.hxx> -#include <ucbhelper/contentbroker.hxx> -#include <ucbhelper/content.hxx> - -#include <unotools/tempfile.hxx> -#include <unotools/ucbhelper.hxx> - -#include "fsstorage.hxx" - - -using namespace ::com::sun::star; - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::impl_staticGetSupportedServiceNames() -{ - uno::Sequence< ::rtl::OUString > aRet(2); - aRet[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.embed.FileSystemStorageFactory")); - aRet[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.FileSystemStorageFactory")); - return aRet; -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL FSStorageFactory::impl_staticGetImplementationName() -{ - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.embed.FileSystemStorageFactory")); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::impl_staticCreateSelfInstance( - const uno::Reference< lang::XMultiServiceFactory >& xServiceManager ) -{ - return uno::Reference< uno::XInterface >( *new FSStorageFactory( xServiceManager ) ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstance() - throw ( uno::Exception, - uno::RuntimeException ) -{ - ::rtl::OUString aTempURL; - - aTempURL = ::utl::TempFile( NULL, sal_True ).GetURL(); - - if ( !aTempURL.getLength() ) - throw uno::RuntimeException(); // TODO: can not create tempfile - - ::ucbhelper::Content aResultContent( - aTempURL, uno::Reference< ucb::XCommandEnvironment >() ); - - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( - new FSStorage( aResultContent, - embed::ElementModes::READWRITE, - uno::Sequence< beans::PropertyValue >(), - m_xFactory ) ), - uno::UNO_QUERY ); -} - -//------------------------------------------------------------------------- -uno::Reference< uno::XInterface > SAL_CALL FSStorageFactory::createInstanceWithArguments( - const uno::Sequence< uno::Any >& aArguments ) - throw ( uno::Exception, - uno::RuntimeException ) -{ - // The request for storage can be done with up to three arguments - - // The first argument specifies a source for the storage - // it must be URL. - // The second value is a mode the storage should be open in. - // And the third value is a media descriptor. - - sal_Int32 nArgNum = aArguments.getLength(); - OSL_ENSURE( nArgNum < 4, "Wrong parameter number" ); - - if ( !nArgNum ) - return createInstance(); - - // first try to retrieve storage open mode if any - // by default the storage will be open in readonly mode - sal_Int32 nStorageMode = embed::ElementModes::READ; - if ( nArgNum >= 2 ) - { - if( !( aArguments[1] >>= nStorageMode ) ) - { - OSL_FAIL( "Wrong second argument!\n" ); - throw uno::Exception(); // TODO: Illegal argument - } - // it's allways possible to read written storage in this implementation - nStorageMode |= embed::ElementModes::READ; - } - - // retrieve storage source URL - ::rtl::OUString aURL; - - if ( aArguments[0] >>= aURL ) - { - if ( !aURL.getLength() ) - { - OSL_FAIL( "Empty URL is provided!\n" ); - throw uno::Exception(); // TODO: illegal argument - } - } - else - { - OSL_FAIL( "Wrong first argument!\n" ); - throw uno::Exception(); // TODO: Illegal argument - } - - // retrieve mediadescriptor and set storage properties - uno::Sequence< beans::PropertyValue > aDescr; - uno::Sequence< beans::PropertyValue > aPropsToSet; - - if ( nArgNum >= 3 ) - { - if( aArguments[2] >>= aDescr ) - { - aPropsToSet.realloc(1); - aPropsToSet[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL")); - aPropsToSet[0].Value <<= aURL; - - for ( sal_Int32 nInd = 0, nNumArgs = 1; nInd < aDescr.getLength(); nInd++ ) - { - if ( aDescr[nInd].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" ) ) ) - { - aPropsToSet.realloc( ++nNumArgs ); - aPropsToSet[nNumArgs-1].Name = aDescr[nInd].Name; - aPropsToSet[nNumArgs-1].Value = aDescr[nInd].Value; - break; - } - else - OSL_FAIL( "Unacceptable property, will be ignored!\n" ); - } - } - else - { - OSL_FAIL( "Wrong third argument!\n" ); - throw uno::Exception(); // TODO: Illegal argument - } - } - - // allow to use other ucp's - // if ( !isLocalNotFile_Impl( aURL ) ) - if ( aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.pkg", 16 ) - || aURL.equalsIgnoreAsciiCaseAsciiL( "vnd.sun.star.zip", 16 ) - || ::utl::UCBContentHelper::IsDocument( aURL ) ) - { - OSL_FAIL( "File system storages can be based only on file URLs!\n" ); // ??? - throw uno::Exception(); // TODO: illegal argument - } - - if ( ( nStorageMode & embed::ElementModes::WRITE ) && !( nStorageMode & embed::ElementModes::NOCREATE ) ) - FSStorage::MakeFolderNoUI( aURL, sal_False ); - else if ( !::utl::UCBContentHelper::IsFolder( aURL ) ) - throw io::IOException(); // there is no such folder - - ::ucbhelper::Content aResultContent( - aURL, uno::Reference< ucb::XCommandEnvironment >() ); - - // create storage based on source - return uno::Reference< uno::XInterface >( - static_cast< OWeakObject* >( new FSStorage( aResultContent, - nStorageMode, - aPropsToSet, - m_xFactory ) ), - uno::UNO_QUERY ); -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL FSStorageFactory::getImplementationName() - throw ( uno::RuntimeException ) -{ - return impl_staticGetImplementationName(); -} - -//------------------------------------------------------------------------- -sal_Bool SAL_CALL FSStorageFactory::supportsService( const ::rtl::OUString& ServiceName ) - throw ( uno::RuntimeException ) -{ - uno::Sequence< ::rtl::OUString > aSeq = impl_staticGetSupportedServiceNames(); - - for ( sal_Int32 nInd = 0; nInd < aSeq.getLength(); nInd++ ) - if ( ServiceName.compareTo( aSeq[nInd] ) == 0 ) - return sal_True; - - return sal_False; -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL FSStorageFactory::getSupportedServiceNames() - throw ( uno::RuntimeException ) -{ - return impl_staticGetSupportedServiceNames(); -} - -//------------------------------------------------------------------------- - -extern "C" -{ -SAL_DLLPUBLIC_EXPORT void * SAL_CALL fsstorage_component_getFactory ( - const sal_Char * pImplementationName, void * pServiceManager, void * /* pRegistryKey */) -{ - void * pResult = 0; - if (pServiceManager) - { - uno::Reference< lang::XSingleServiceFactory > xFactory; - if (FSStorageFactory::impl_staticGetImplementationName().compareToAscii (pImplementationName) == 0) - { - xFactory = cppu::createOneInstanceFactory ( - reinterpret_cast< lang::XMultiServiceFactory* >(pServiceManager), - FSStorageFactory::impl_staticGetImplementationName(), - FSStorageFactory::impl_staticCreateSelfInstance, - FSStorageFactory::impl_staticGetSupportedServiceNames() ); - } - if (xFactory.is()) - { - xFactory->acquire(); - pResult = xFactory.get(); - } - } - return pResult; -} - -} // extern "C" - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/fsstorage.component b/svl/source/fsstor/fsstorage.component deleted file mode 100644 index f9f08487b8..0000000000 --- a/svl/source/fsstor/fsstorage.component +++ /dev/null @@ -1,35 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!--********************************************************************** -* -* 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. -* -**********************************************************************--> - -<component loader="com.sun.star.loader.SharedLibrary" prefix="fsstorage" - xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.embed.FileSystemStorageFactory"> - <service name="com.sun.star.comp.embed.FileSystemStorageFactory"/> - <service name="com.sun.star.embed.FileSystemStorageFactory"/> - </implementation> -</component> diff --git a/svl/source/fsstor/fsstorage.cxx b/svl/source/fsstor/fsstorage.cxx deleted file mode 100644 index 4fff58e946..0000000000 --- a/svl/source/fsstor/fsstorage.cxx +++ /dev/null @@ -1,1612 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/embed/ElementModes.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> -#include <com/sun/star/ucb/XProgressHandler.hpp> -#include <com/sun/star/ucb/XContentAccess.hpp> -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> - -#include <com/sun/star/ucb/InteractiveIOException.hpp> -#include <com/sun/star/ucb/IOErrorCode.hpp> -#include <com/sun/star/container/XHierarchicalNameAccess.hpp> -#include <com/sun/star/container/XEnumerationAccess.hpp> -#include <com/sun/star/container/XNamed.hpp> -#include <com/sun/star/util/XChangesBatch.hpp> -#include <com/sun/star/util/XCloneable.hpp> -#include <com/sun/star/lang/XUnoTunnel.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/lang/DisposedException.hpp> -#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> -#include <com/sun/star/io/IOException.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/sdbc/XResultSet.hpp> -#include <com/sun/star/sdbc/XRow.hpp> - - -#include <comphelper/processfactory.hxx> -#include <comphelper/storagehelper.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/exc_hlp.hxx> - -#include <tools/urlobj.hxx> -#include <unotools/ucbhelper.hxx> -#include <unotools/ucbstreamhelper.hxx> -#include <unotools/streamwrap.hxx> -#include <ucbhelper/fileidentifierconverter.hxx> -#include <ucbhelper/contentbroker.hxx> -#include <ucbhelper/content.hxx> - -#include "fsstorage.hxx" -#include "oinputstreamcontainer.hxx" -#include "ostreamcontainer.hxx" - -using namespace ::com::sun::star; - -//========================================================= - -// TODO: move to a standard helper -sal_Bool isLocalFile_Impl( ::rtl::OUString aURL ) -{ - ::rtl::OUString aSystemPath; - ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); - if ( !pBroker ) - throw uno::RuntimeException(); - - uno::Reference< ucb::XContentProviderManager > xManager = - pBroker->getContentProviderManagerInterface(); - try - { - aSystemPath = ::ucbhelper::getSystemPathFromFileURL( xManager, aURL ); - } - catch ( uno::Exception& ) - { - } - - return ( aSystemPath.getLength() != 0 ); -} - - -//========================================================= - -struct FSStorage_Impl -{ - ::rtl::OUString m_aURL; - - ::ucbhelper::Content* m_pContent; - sal_Int32 m_nMode; - - ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners - ::cppu::OTypeCollection* m_pTypeCollection; - - uno::Reference< lang::XMultiServiceFactory > m_xFactory; - - - FSStorage_Impl( const ::rtl::OUString& aURL, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory ) - : m_aURL( aURL ) - , m_pContent( NULL ) - , m_nMode( nMode ) - , m_pListenersContainer( NULL ) - , m_pTypeCollection( NULL ) - , m_xFactory( xFactory ) - { - OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" ); - } - - FSStorage_Impl( const ::ucbhelper::Content& aContent, sal_Int32 nMode, uno::Reference< lang::XMultiServiceFactory > xFactory ) - : m_aURL( aContent.getURL() ) - , m_pContent( new ::ucbhelper::Content( aContent ) ) - , m_nMode( nMode ) - , m_pListenersContainer( NULL ) - , m_pTypeCollection( NULL ) - , m_xFactory( xFactory ) - { - OSL_ENSURE( m_aURL.getLength(), "The URL must not be empty" ); - } - - ~FSStorage_Impl(); -}; - -//========================================================= - -FSStorage_Impl::~FSStorage_Impl() -{ - if ( m_pListenersContainer ) - delete m_pListenersContainer; - if ( m_pTypeCollection ) - delete m_pTypeCollection; - if ( m_pContent ) - delete m_pContent; -} - -//===================================================== -// FSStorage implementation -//===================================================== - -//----------------------------------------------- -FSStorage::FSStorage( const ::ucbhelper::Content& aContent, - sal_Int32 nMode, - uno::Sequence< beans::PropertyValue >, - uno::Reference< lang::XMultiServiceFactory > xFactory ) -: m_pImpl( new FSStorage_Impl( aContent, nMode, xFactory ) ) -{ - // TODO: use properties - if ( !xFactory.is() ) - throw uno::RuntimeException(); - - GetContent(); -} - -//----------------------------------------------- -FSStorage::~FSStorage() -{ - { - ::osl::MutexGuard aGuard( m_aMutex ); - m_refCount++; // to call dispose - try { - dispose(); - } - catch( uno::RuntimeException& ) - {} - } -} - -//----------------------------------------------- -sal_Bool FSStorage::MakeFolderNoUI( const String& rFolder, sal_Bool ) -{ - INetURLObject aURL( rFolder ); - ::rtl::OUString aTitle = aURL.getName( INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ); - aURL.removeSegment(); - ::ucbhelper::Content aParent; - ::ucbhelper::Content aResultContent; - - if ( ::ucbhelper::Content::create( aURL.GetMainURL( INetURLObject::NO_DECODE ), - uno::Reference< ucb::XCommandEnvironment >(), - aParent ) ) - return ::utl::UCBContentHelper::MakeFolder( aParent, aTitle, aResultContent, sal_False ); - - return sal_False; -} - -//----------------------------------------------- -::ucbhelper::Content* FSStorage::GetContent() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( !m_pImpl->m_pContent ) - { - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - - try - { - m_pImpl->m_pContent = new ::ucbhelper::Content( m_pImpl->m_aURL, xDummyEnv ); - } - catch( uno::Exception& ) - { - } - } - - return m_pImpl->m_pContent; -} - -//----------------------------------------------- -void FSStorage::CopyStreamToSubStream( const ::rtl::OUString& aSourceURL, - const uno::Reference< embed::XStorage >& xDest, - const ::rtl::OUString& aNewEntryName ) -{ - if ( !xDest.is() ) - throw uno::RuntimeException(); - - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv ); - uno::Reference< io::XInputStream > xSourceInput = aSourceContent.openStream(); - - if ( !xSourceInput.is() ) - throw io::IOException(); // TODO: error handling - - uno::Reference< io::XStream > xSubStream = xDest->openStreamElement( - aNewEntryName, - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ); - if ( !xSubStream.is() ) - throw uno::RuntimeException(); - - uno::Reference< io::XOutputStream > xDestOutput = xSubStream->getOutputStream(); - if ( !xDestOutput.is() ) - throw uno::RuntimeException(); - - ::comphelper::OStorageHelper::CopyInputToOutput( xSourceInput, xDestOutput ); - xDestOutput->closeOutput(); -} - -//----------------------------------------------- -void FSStorage::CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, const uno::Reference< embed::XStorage >& xDest ) -{ - if ( !pContent ) - throw uno::RuntimeException(); - - // get list of contents of the Content - // create cursor for access to children - uno::Sequence< ::rtl::OUString > aProps( 2 ); - ::rtl::OUString* pProps = aProps.getArray(); - pProps[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TargetURL")); - pProps[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsFolder")); - ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS; - - try - { - uno::Reference< sdbc::XResultSet > xResultSet = pContent->createCursor( aProps, eInclude ); - uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); - uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); - if ( xResultSet.is() ) - { - // go through the list: insert files as streams, insert folders as substorages using recursion - while ( xResultSet->next() ) - { - ::rtl::OUString aSourceURL( xRow->getString( 1 ) ); - sal_Bool bIsFolder( xRow->getBoolean(2) ); - - // TODO/LATER: not sure whether the entry name must be encoded - ::rtl::OUString aNewEntryName( INetURLObject( aSourceURL ).getName( INetURLObject::LAST_SEGMENT, - true, - INetURLObject::NO_DECODE ) ); - if ( bIsFolder ) - { - uno::Reference< embed::XStorage > xSubStorage = xDest->openStorageElement( aNewEntryName, - embed::ElementModes::READWRITE ); - if ( !xSubStorage.is() ) - throw uno::RuntimeException(); - - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aSourceContent( aSourceURL, xDummyEnv ); - CopyContentToStorage_Impl( &aSourceContent, xSubStorage ); - } - else - { - CopyStreamToSubStream( aSourceURL, xDest, aNewEntryName ); - } - } - } - - uno::Reference< embed::XTransactedObject > xTransact( xDest, uno::UNO_QUERY ); - if ( xTransact.is() ) - xTransact->commit(); - } - catch( ucb::InteractiveIOException& r ) - { - if ( r.Code == ucb::IOErrorCode_NOT_EXISTING ) - OSL_FAIL( "The folder does not exist!\n" ); - else - throw; - } -} - -//____________________________________________________________________________________________________ -// XInterface -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Any SAL_CALL FSStorage::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<lang::XTypeProvider*> ( this ) - , static_cast<embed::XStorage*> ( this ) - , static_cast<embed::XHierarchicalStorageAccess*> ( this ) - , static_cast<container::XNameAccess*> ( this ) - , static_cast<container::XElementAccess*> ( this ) - , static_cast<lang::XComponent*> ( this ) - , static_cast<beans::XPropertySet*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::acquire() throw() -{ - OWeakObject::acquire(); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::release() throw() -{ - OWeakObject::release(); -} - -//____________________________________________________________________________________________________ -// XTypeProvider -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Sequence< uno::Type > SAL_CALL FSStorage::getTypes() - throw( uno::RuntimeException ) -{ - if ( m_pImpl->m_pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pImpl->m_pTypeCollection == NULL ) - { - m_pImpl->m_pTypeCollection = new ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XStorage >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XHierarchicalStorageAccess >* )NULL ) - , ::getCppuType( ( const uno::Reference< beans::XPropertySet >* )NULL ) ); - } - } - - return m_pImpl->m_pTypeCollection->getTypes() ; -} - -//----------------------------------------------- -uno::Sequence< sal_Int8 > SAL_CALL FSStorage::getImplementationId() - throw( uno::RuntimeException ) -{ - static ::cppu::OImplementationId* pID = NULL ; - - if ( pID == NULL ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; - - if ( pID == NULL ) - { - static ::cppu::OImplementationId aID( sal_False ) ; - pID = &aID ; - } - } - - return pID->getImplementationId() ; - -} - -//____________________________________________________________________________________________________ -// XStorage -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL FSStorage::copyToStorage( const uno::Reference< embed::XStorage >& xDest ) - throw ( embed::InvalidStorageException, - io::IOException, - lang::IllegalArgumentException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !xDest.is() || xDest == uno::Reference< uno::XInterface >( static_cast< OWeakObject*> ( this ), uno::UNO_QUERY ) ) - throw lang::IllegalArgumentException(); // TODO: - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - try - { - CopyContentToStorage_Impl( GetContent(), xDest ); - } - catch( embed::InvalidStorageException& ) - { - throw; - } - catch( lang::IllegalArgumentException& ) - { - throw; - } - catch( embed::StorageWrappedTargetException& ) - { - throw; - } - catch( io::IOException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL FSStorage::openStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked - INetURLObject aFileURL( m_pImpl->m_aURL ); - aFileURL.Append( aStreamName ); - - if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); - - if ( ( nOpenMode & embed::ElementModes::NOCREATE ) - && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); // TODO: - - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any - uno::Reference< io::XStream > xResult; - try - { - if ( nOpenMode & embed::ElementModes::WRITE ) - { - if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - { - uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( - m_pImpl->m_xFactory->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), - uno::UNO_QUERY_THROW ); - xResult = xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ); - } - else - { - // TODO: test whether it really works for http and fwp - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), - STREAM_STD_WRITE ); - if ( pStream ) - { - if ( !pStream->GetError() ) - xResult = uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) ); - else - delete pStream; - } - } - - if ( !xResult.is() ) - throw io::IOException(); - - if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) ) - { - uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW ); - xTrunc->truncate(); - } - } - else - { - if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) - || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); // TODO: access denied - - ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); - uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); - xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) ); - } - } - catch( embed::InvalidStorageException& ) - { - throw; - } - catch( lang::IllegalArgumentException& ) - { - throw; - } - catch( packages::WrongPasswordException& ) - { - throw; - } - catch( embed::StorageWrappedTargetException& ) - { - throw; - } - catch( io::IOException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL FSStorage::openEncryptedStreamElement( - const ::rtl::OUString&, sal_Int32, const ::rtl::OUString& ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - throw packages::NoEncryptionException(); -} - -//----------------------------------------------- -uno::Reference< embed::XStorage > SAL_CALL FSStorage::openStorageElement( - const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - if ( ( nStorageMode & embed::ElementModes::WRITE ) - && !( m_pImpl->m_nMode & embed::ElementModes::WRITE ) ) - throw io::IOException(); // TODO: error handling - - // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked - INetURLObject aFolderURL( m_pImpl->m_aURL ); - aFolderURL.Append( aStorName ); - - sal_Bool bFolderExists = ::utl::UCBContentHelper::IsFolder( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); - if ( !bFolderExists && ::utl::UCBContentHelper::IsDocument( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); // TODO: - - if ( ( nStorageMode & embed::ElementModes::NOCREATE ) && !bFolderExists ) - throw io::IOException(); // TODO: - - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any - uno::Reference< embed::XStorage > xResult; - try - { - if ( nStorageMode & embed::ElementModes::WRITE ) - { - if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) && bFolderExists ) - { - ::utl::UCBContentHelper::Kill( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ) ); - bFolderExists = - MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :( - } - else if ( !bFolderExists ) - { - bFolderExists = - MakeFolderNoUI( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), sal_True ); // TODO: not atomar :( - } - } - else if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) ) - throw io::IOException(); // TODO: access denied - - if ( !bFolderExists ) - throw io::IOException(); // there is no such folder - - ::ucbhelper::Content aResultContent( aFolderURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); - xResult = uno::Reference< embed::XStorage >( - static_cast< OWeakObject* >( new FSStorage( aResultContent, - nStorageMode, - uno::Sequence< beans::PropertyValue >(), - m_pImpl->m_xFactory ) ), - uno::UNO_QUERY ); - } - catch( embed::InvalidStorageException& ) - { - throw; - } - catch( lang::IllegalArgumentException& ) - { - throw; - } - catch( embed::StorageWrappedTargetException& ) - { - throw; - } - catch( io::IOException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL FSStorage::cloneStreamElement( const ::rtl::OUString& aStreamName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked - INetURLObject aFileURL( m_pImpl->m_aURL ); - aFileURL.Append( aStreamName ); - - uno::Reference < io::XStream > xTempResult; - try - { - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); - uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); - - xTempResult = uno::Reference < io::XStream >( - m_pImpl->m_xFactory->createInstance ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile")) ), - uno::UNO_QUERY_THROW ); - uno::Reference < io::XOutputStream > xTempOut = xTempResult->getOutputStream(); - uno::Reference < io::XInputStream > xTempIn = xTempResult->getInputStream(); - - if ( !xTempOut.is() || !xTempIn.is() ) - throw io::IOException(); - - ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOut ); - xTempOut->closeOutput(); - } - catch( embed::InvalidStorageException& ) - { - throw; - } - catch( lang::IllegalArgumentException& ) - { - throw; - } - catch( packages::WrongPasswordException& ) - { - throw; - } - catch( io::IOException& ) - { - throw; - } - catch( embed::StorageWrappedTargetException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return xTempResult; -} - -//----------------------------------------------- -uno::Reference< io::XStream > SAL_CALL FSStorage::cloneEncryptedStreamElement( - const ::rtl::OUString&, - const ::rtl::OUString& ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - throw packages::NoEncryptionException(); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::copyLastCommitTo( - const uno::Reference< embed::XStorage >& xTargetStorage ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - copyToStorage( xTargetStorage ); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::copyStorageElementLastCommitTo( - const ::rtl::OUString& aStorName, - const uno::Reference< embed::XStorage >& xTargetStorage ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - uno::Reference< embed::XStorage > xSourceStor( openStorageElement( aStorName, embed::ElementModes::READ ), - uno::UNO_QUERY_THROW ); - xSourceStor->copyToStorage( xTargetStorage ); -} - -//----------------------------------------------- -sal_Bool SAL_CALL FSStorage::isStreamElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw embed::InvalidStorageException(); // TODO: error handling - - INetURLObject aURL( m_pImpl->m_aURL ); - aURL.Append( aElementName ); - - return !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); -} - -//----------------------------------------------- -sal_Bool SAL_CALL FSStorage::isStorageElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw embed::InvalidStorageException(); // TODO: error handling - - INetURLObject aURL( m_pImpl->m_aURL ); - aURL.Append( aElementName ); - - return ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::removeElement( const ::rtl::OUString& aElementName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - INetURLObject aURL( m_pImpl->m_aURL ); - aURL.Append( aElementName ); - - if ( !::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) - && !::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw container::NoSuchElementException(); // TODO: - - ::utl::UCBContentHelper::Kill( aURL.GetMainURL( INetURLObject::NO_DECODE ) ); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::renameElement( const ::rtl::OUString& aElementName, const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - INetURLObject aOldURL( m_pImpl->m_aURL ); - aOldURL.Append( aElementName ); - - INetURLObject aNewURL( m_pImpl->m_aURL ); - aNewURL.Append( aNewName ); - - if ( !::utl::UCBContentHelper::IsFolder( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) - && !::utl::UCBContentHelper::IsDocument( aOldURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw container::NoSuchElementException(); // TODO: - - if ( ::utl::UCBContentHelper::IsFolder( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) - || ::utl::UCBContentHelper::IsDocument( aNewURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw container::ElementExistException(); // TODO: - - try - { - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aSourceContent( aOldURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); - - if ( !GetContent()->transferContent( aSourceContent, - ::ucbhelper::InsertOperation_MOVE, - aNewName, - ucb::NameClash::ERROR ) ) - throw io::IOException(); // TODO: error handling - } - catch( embed::InvalidStorageException& ) - { - throw; - } - catch( lang::IllegalArgumentException& ) - { - throw; - } - catch( container::NoSuchElementException& ) - { - throw; - } - catch( container::ElementExistException& ) - { - throw; - } - catch( io::IOException& ) - { - throw; - } - catch( embed::StorageWrappedTargetException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL FSStorage::copyElementTo( const ::rtl::OUString& aElementName, - const uno::Reference< embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !xDest.is() ) - throw uno::RuntimeException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - INetURLObject aOwnURL( m_pImpl->m_aURL ); - aOwnURL.Append( aElementName ); - - if ( xDest->hasByName( aNewName ) ) - throw container::ElementExistException(); // TODO: - - try - { - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - if ( ::utl::UCBContentHelper::IsFolder( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - { - ::ucbhelper::Content aSourceContent( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); - uno::Reference< embed::XStorage > xDestSubStor( - xDest->openStorageElement( aNewName, embed::ElementModes::READWRITE ), - uno::UNO_QUERY_THROW ); - - CopyContentToStorage_Impl( &aSourceContent, xDestSubStor ); - } - else if ( ::utl::UCBContentHelper::IsDocument( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - { - CopyStreamToSubStream( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ), xDest, aNewName ); - } - else - throw container::NoSuchElementException(); // TODO: - } - catch( embed::InvalidStorageException& ) - { - throw; - } - catch( lang::IllegalArgumentException& ) - { - throw; - } - catch( container::NoSuchElementException& ) - { - throw; - } - catch( container::ElementExistException& ) - { - throw; - } - catch( embed::StorageWrappedTargetException& ) - { - throw; - } - catch( io::IOException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), - uno::Reference< io::XInputStream >(), - aCaught ); - } -} - -//----------------------------------------------- -void SAL_CALL FSStorage::moveElementTo( const ::rtl::OUString& aElementName, - const uno::Reference< embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - container::ElementExistException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - copyElementTo( aElementName, xDest, aNewName ); - - INetURLObject aOwnURL( m_pImpl->m_aURL ); - aOwnURL.Append( aElementName ); - if ( !::utl::UCBContentHelper::Kill( aOwnURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); // TODO: error handling -} - -//____________________________________________________________________________________________________ -// XNameAccess -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Any SAL_CALL FSStorage::getByName( const ::rtl::OUString& aName ) - throw ( container::NoSuchElementException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - if ( !aName.getLength() ) - throw lang::IllegalArgumentException(); - - INetURLObject aURL( m_pImpl->m_aURL ); - aURL.Append( aName ); - - uno::Any aResult; - try - { - if ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - { - aResult <<= openStorageElement( aName, embed::ElementModes::READ ); - } - else if ( ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - { - aResult <<= openStreamElement( aName, embed::ElementModes::READ ); - } - else - throw container::NoSuchElementException(); // TODO: - } - catch( container::NoSuchElementException& ) - { - throw; - } - catch( lang::WrappedTargetException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open element!\n")), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - return aResult; -} - - -//----------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL FSStorage::getElementNames() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - uno::Sequence< ::rtl::OUString > aProps( 1 ); - ::rtl::OUString* pProps = aProps.getArray(); - pProps[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title")); - ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS; - - uno::Sequence< ::rtl::OUString > aResult; - sal_Int32 nSize = 0; - - try - { - uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude ); - uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY ); - uno::Reference< sdbc::XRow > xRow( xResultSet, uno::UNO_QUERY ); - if ( xResultSet.is() ) - { - // go through the list - while ( xResultSet->next() ) - { - ::rtl::OUString aName( xRow->getString( 1 ) ); - aResult.realloc( ++nSize ); - aResult[nSize-1] = aName; - } - } - } - catch( ucb::InteractiveIOException& r ) - { - if ( r.Code == ucb::IOErrorCode_NOT_EXISTING ) - OSL_FAIL( "The folder does not exist!\n" ); - else - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open storage!\n")), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - } - catch( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open storage!\n")), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - return aResult; -} - - -//----------------------------------------------- -sal_Bool SAL_CALL FSStorage::hasByName( const ::rtl::OUString& aName ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - try - { - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - if ( !aName.getLength() ) - throw lang::IllegalArgumentException(); - } - catch( uno::RuntimeException& ) - { - throw; - } - catch ( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw lang::WrappedTargetRuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can not open storage!\n")), - uno::Reference< uno::XInterface >( static_cast< OWeakObject* >( this ), - uno::UNO_QUERY ), - aCaught ); - } - - INetURLObject aURL( m_pImpl->m_aURL ); - aURL.Append( aName ); - - return ( ::utl::UCBContentHelper::IsFolder( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) - || ::utl::UCBContentHelper::IsDocument( aURL.GetMainURL( INetURLObject::NO_DECODE ) ) ); -} - -//----------------------------------------------- -uno::Type SAL_CALL FSStorage::getElementType() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - // it is a multitype container - return uno::Type(); -} - -//----------------------------------------------- -sal_Bool SAL_CALL FSStorage::hasElements() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - uno::Sequence< ::rtl::OUString > aProps( 1 ); - aProps[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TargetURL")); - ::ucbhelper::ResultSetInclude eInclude = ::ucbhelper::INCLUDE_FOLDERS_AND_DOCUMENTS; - - try - { - uno::Reference< sdbc::XResultSet > xResultSet = GetContent()->createCursor( aProps, eInclude ); - return ( xResultSet.is() && xResultSet->next() ); - } - catch( uno::Exception& ) - { - throw uno::RuntimeException(); - } -} - - -//____________________________________________________________________________________________________ -// XDisposable -//____________________________________________________________________________________________________ - -//----------------------------------------------- -void SAL_CALL FSStorage::dispose() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( m_pImpl->m_pListenersContainer ) - { - lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) ); - m_pImpl->m_pListenersContainer->disposeAndClear( aSource ); - } - - delete m_pImpl; - m_pImpl = NULL; -} - -//----------------------------------------------- -void SAL_CALL FSStorage::addEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !m_pImpl->m_pListenersContainer ) - m_pImpl->m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex ); - - m_pImpl->m_pListenersContainer->addInterface( xListener ); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::removeEventListener( - const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( m_pImpl->m_pListenersContainer ) - m_pImpl->m_pListenersContainer->removeInterface( xListener ); -} - -//____________________________________________________________________________________________________ -// XPropertySet -//____________________________________________________________________________________________________ - -//----------------------------------------------- -uno::Reference< beans::XPropertySetInfo > SAL_CALL FSStorage::getPropertySetInfo() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - //TODO: - return uno::Reference< beans::XPropertySetInfo >(); -} - - -//----------------------------------------------- -void SAL_CALL FSStorage::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& ) - throw ( beans::UnknownPropertyException, - beans::PropertyVetoException, - lang::IllegalArgumentException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("URL")) || aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("OpenMode")) ) - throw beans::PropertyVetoException(); // TODO - else - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -uno::Any SAL_CALL FSStorage::getPropertyValue( const ::rtl::OUString& aPropertyName ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("URL")) ) - return uno::makeAny( m_pImpl->m_aURL ); - else if ( aPropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("OpenMode")) ) - return uno::makeAny( m_pImpl->m_nMode ); - - throw beans::UnknownPropertyException(); // TODO -} - - -//----------------------------------------------- -void SAL_CALL FSStorage::addPropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL FSStorage::removePropertyChangeListener( - const ::rtl::OUString& /*aPropertyName*/, - const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL FSStorage::addVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - //TODO: -} - - -//----------------------------------------------- -void SAL_CALL FSStorage::removeVetoableChangeListener( - const ::rtl::OUString& /*PropertyName*/, - const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) - throw ( beans::UnknownPropertyException, - lang::WrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - //TODO: -} - -//____________________________________________________________________________________________________ -// XHierarchicalStorageAccess -//____________________________________________________________________________________________________ -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( sStreamPath.toChar() == '/' ) - throw lang::IllegalArgumentException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - INetURLObject aBaseURL( m_pImpl->m_aURL ); - if ( !aBaseURL.setFinalSlash() ) - throw uno::RuntimeException(); - - INetURLObject aFileURL = INetURLObject::GetAbsURL( - aBaseURL.GetMainURL( INetURLObject::NO_DECODE ), - sStreamPath ); - - if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); - - if ( ( nOpenMode & embed::ElementModes::NOCREATE ) - && !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); // TODO: - - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; // TODO: provide InteractionHandler if any - uno::Reference< io::XStream > xResult; - try - { - if ( nOpenMode & embed::ElementModes::WRITE ) - { - if ( isLocalFile_Impl( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - { - uno::Reference< ucb::XSimpleFileAccess > xSimpleFileAccess( - m_pImpl->m_xFactory->createInstance( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.SimpleFileAccess" ) ) ), - uno::UNO_QUERY_THROW ); - uno::Reference< io::XStream > xStream = - xSimpleFileAccess->openFileReadWrite( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ); - - xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) ); - } - else - { - // TODO: test whether it really works for http and fwp - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), - STREAM_STD_WRITE ); - if ( pStream ) - { - if ( !pStream->GetError() ) - { - uno::Reference< io::XStream > xStream = - uno::Reference < io::XStream >( new ::utl::OStreamWrapper( *pStream ) ); - xResult = static_cast< io::XStream* >( new OFSStreamContainer( xStream ) ); - } - else - delete pStream; - } - } - - if ( !xResult.is() ) - throw io::IOException(); - - if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) ) - { - uno::Reference< io::XTruncate > xTrunc( xResult->getOutputStream(), uno::UNO_QUERY_THROW ); - xTrunc->truncate(); - } - } - else - { - if ( ( nOpenMode & embed::ElementModes::TRUNCATE ) - || !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); // TODO: access denied - - ::ucbhelper::Content aResultContent( aFileURL.GetMainURL( INetURLObject::NO_DECODE ), xDummyEnv ); - uno::Reference< io::XInputStream > xInStream = aResultContent.openStream(); - xResult = static_cast< io::XStream* >( new OFSInputStreamContainer( xInStream ) ); - } - } - catch( embed::InvalidStorageException& ) - { - throw; - } - catch( lang::IllegalArgumentException& ) - { - throw; - } - catch( packages::WrongPasswordException& ) - { - throw; - } - catch( embed::StorageWrappedTargetException& ) - { - throw; - } - catch( io::IOException& ) - { - throw; - } - catch( uno::RuntimeException& ) - { - throw; - } - catch( uno::Exception& ) - { - uno::Any aCaught( ::cppu::getCaughtException() ); - throw embed::StorageWrappedTargetException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't copy raw stream")), - uno::Reference< io::XInputStream >(), - aCaught ); - } - - return uno::Reference< embed::XExtendedStorageStream >( xResult, uno::UNO_QUERY_THROW ); -} - -//----------------------------------------------- -uno::Reference< embed::XExtendedStorageStream > SAL_CALL FSStorage::openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& /*sStreamName*/, ::sal_Int32 /*nOpenMode*/, const ::rtl::OUString& /*sPassword*/ ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - packages::NoEncryptionException, - packages::WrongPasswordException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - throw packages::NoEncryptionException(); -} - -//----------------------------------------------- -void SAL_CALL FSStorage::removeStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath ) - throw ( embed::InvalidStorageException, - lang::IllegalArgumentException, - container::NoSuchElementException, - io::IOException, - embed::StorageWrappedTargetException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !m_pImpl ) - throw lang::DisposedException(); - - if ( !GetContent() ) - throw io::IOException(); // TODO: error handling - - // TODO/LATER: may need possibility to create folder if it was removed, since the folder can not be locked - INetURLObject aBaseURL( m_pImpl->m_aURL ); - if ( !aBaseURL.setFinalSlash() ) - throw uno::RuntimeException(); - - INetURLObject aFileURL = INetURLObject::GetAbsURL( - aBaseURL.GetMainURL( INetURLObject::NO_DECODE ), - sStreamPath ); - - if ( !::utl::UCBContentHelper::IsDocument( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - { - if ( ::utl::UCBContentHelper::IsFolder( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw lang::IllegalArgumentException(); - else - throw container::NoSuchElementException(); // TODO: - } - - if ( !::utl::UCBContentHelper::Kill( aFileURL.GetMainURL( INetURLObject::NO_DECODE ) ) ) - throw io::IOException(); // TODO: error handling -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/fsstorage.hxx b/svl/source/fsstor/fsstorage.hxx deleted file mode 100644 index c2c616f039..0000000000 --- a/svl/source/fsstor/fsstorage.hxx +++ /dev/null @@ -1,339 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 __XSTORAGE_HXX_ -#define __XSTORAGE_HXX_ - -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/embed/XStorage.hpp> -#include <com/sun/star/embed/XHierarchicalStorageAccess.hpp> -#include <com/sun/star/beans/XPropertySet.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/io/XStream.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/packages/NoEncryptionException.hpp> -#include <cppuhelper/weak.hxx> -#include <cppuhelper/interfacecontainer.h> - -#include <ucbhelper/content.hxx> - -struct FSStorage_Impl; -class FSStorage : public ::com::sun::star::lang::XTypeProvider - , public ::com::sun::star::embed::XStorage - , public ::com::sun::star::embed::XHierarchicalStorageAccess - , public ::com::sun::star::beans::XPropertySet - , public ::cppu::OWeakObject -{ - ::osl::Mutex m_aMutex; - FSStorage_Impl* m_pImpl; - -protected: - -public: - - FSStorage( const ::ucbhelper::Content& aContent, - sal_Int32 nMode, - ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > xProperties, - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory ); - - virtual ~FSStorage(); - - ::ucbhelper::Content* GetContent(); - - void CopyStreamToSubStream( const ::rtl::OUString& aSourceURL, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - const ::rtl::OUString& aNewEntryName ); - - void CopyContentToStorage_Impl( ::ucbhelper::Content* pContent, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest ); - - static sal_Bool MakeFolderNoUI( const String& rFolder, sal_Bool bNewOnly ); - - //____________________________________________________________________________________________________ - // XInterface - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL acquire() throw(); - - virtual void SAL_CALL release() throw(); - - //____________________________________________________________________________________________________ - // XTypeProvider - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() - throw( ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() - throw( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XStorage - //____________________________________________________________________________________________________ - - virtual void SAL_CALL copyToStorage( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL openEncryptedStreamElement( - const ::rtl::OUString& aStreamName, sal_Int32 nOpenMode, const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL openStorageElement( - const ::rtl::OUString& aStorName, sal_Int32 nStorageMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneStreamElement( - const ::rtl::OUString& aStreamName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > SAL_CALL cloneEncryptedStreamElement( - const ::rtl::OUString& aStreamName, const ::rtl::OUString& aPass ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyLastCommitTo( - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyStorageElementLastCommitTo( - const ::rtl::OUString& aStorName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xTargetStorage ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL isStreamElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL isStorageElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeElement( const ::rtl::OUString& aElementName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL renameElement( const ::rtl::OUString& rEleName, const ::rtl::OUString& rNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL copyElementTo( const ::rtl::OUString& aElementName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - const ::rtl::OUString& aNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL moveElementTo( const ::rtl::OUString& aElementName, - const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xDest, - const ::rtl::OUString& rNewName ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::container::ElementExistException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XNameAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) - throw ( ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Type SAL_CALL getElementType() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual sal_Bool SAL_CALL hasElements() - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XComponent - //____________________________________________________________________________________________________ - - virtual void SAL_CALL dispose() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeEventListener( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) - throw ( ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XPropertySet - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() - throw ( ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addPropertyChangeListener( - const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removePropertyChangeListener( - const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL addVetoableChangeListener( - const ::rtl::OUString& PropertyName, - const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw ( ::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - //____________________________________________________________________________________________________ - // XHierarchicalStorageAccess - //____________________________________________________________________________________________________ - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openStreamElementByHierarchicalName( const ::rtl::OUString& sStreamPath, ::sal_Int32 nOpenMode ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XExtendedStorageStream > SAL_CALL openEncryptedStreamElementByHierarchicalName( const ::rtl::OUString& sStreamName, ::sal_Int32 nOpenMode, const ::rtl::OUString& sPassword ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::packages::NoEncryptionException, - ::com::sun::star::packages::WrongPasswordException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); - - virtual void SAL_CALL removeStreamElementByHierarchicalName( const ::rtl::OUString& sElementPath ) - throw ( ::com::sun::star::embed::InvalidStorageException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::container::NoSuchElementException, - ::com::sun::star::io::IOException, - ::com::sun::star::embed::StorageWrappedTargetException, - ::com::sun::star::uno::RuntimeException ); -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/oinputstreamcontainer.cxx b/svl/source/fsstor/oinputstreamcontainer.cxx deleted file mode 100644 index 7ed51d7866..0000000000 --- a/svl/source/fsstor/oinputstreamcontainer.cxx +++ /dev/null @@ -1,349 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include "oinputstreamcontainer.hxx" -#include <cppuhelper/typeprovider.hxx> - -using namespace ::com::sun::star; - -//----------------------------------------------- -OFSInputStreamContainer::OFSInputStreamContainer( const uno::Reference< io::XInputStream >& xStream ) -: m_xInputStream( xStream ) -, m_xSeekable( xStream, uno::UNO_QUERY ) -, m_bSeekable( sal_False ) -, m_bDisposed( sal_False ) -, m_pListenersContainer( NULL ) -{ - m_bSeekable = m_xSeekable.is(); -} - -//----------------------------------------------- -OFSInputStreamContainer::~OFSInputStreamContainer() -{ - if ( m_pListenersContainer ) - { - delete m_pListenersContainer; - m_pListenersContainer = NULL; - } -} - -//----------------------------------------------- -uno::Sequence< uno::Type > SAL_CALL OFSInputStreamContainer::getTypes() - throw ( uno::RuntimeException ) -{ - static ::cppu::OTypeCollection* pTypeCollection = NULL ; - - if ( pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_aMutex ) ; - - if ( pTypeCollection == NULL ) - { - if ( m_bSeekable ) - { - static ::cppu::OTypeCollection aTypeCollection( - ::getCppuType(( const uno::Reference< io::XStream >* )NULL ), - ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ), - ::getCppuType(( const uno::Reference< io::XSeekable >* )NULL ) ); - - pTypeCollection = &aTypeCollection ; - } - else - { - static ::cppu::OTypeCollection aTypeCollection( - ::getCppuType(( const uno::Reference< io::XStream >* )NULL ), - ::getCppuType(( const uno::Reference< io::XInputStream >* )NULL ) ); - - pTypeCollection = &aTypeCollection ; - } - } - } - - return pTypeCollection->getTypes() ; - -} - -//----------------------------------------------- -uno::Any SAL_CALL OFSInputStreamContainer::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - // Attention: - // Don't use mutex or guard in this method!!! Is a method of XInterface. - - uno::Any aReturn; - if ( m_bSeekable ) - aReturn = uno::Any( ::cppu::queryInterface( rType, - static_cast< io::XStream* >( this ), - static_cast< io::XInputStream* >( this ), - static_cast< io::XSeekable* >( this ) ) ); - else - aReturn = uno::Any( ::cppu::queryInterface( rType, - static_cast< io::XStream* >( this ), - static_cast< io::XInputStream* >( this ) ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - return ::cppu::OWeakObject::queryInterface( rType ) ; -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::acquire() - throw() -{ - ::cppu::OWeakObject::acquire(); -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::release() - throw() -{ - ::cppu::OWeakObject::release(); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OFSInputStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xInputStream.is() ) - throw uno::RuntimeException(); - - return m_xInputStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OFSInputStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xInputStream.is() ) - throw uno::RuntimeException(); - - return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead ); -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::skipBytes( sal_Int32 nBytesToSkip ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xInputStream.is() ) - throw uno::RuntimeException(); - - m_xInputStream->skipBytes( nBytesToSkip ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OFSInputStreamContainer::available( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xInputStream.is() ) - throw uno::RuntimeException(); - - return m_xInputStream->available(); -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::closeInput( ) - throw ( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xInputStream.is() ) - throw uno::RuntimeException(); - - dispose(); -} - -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OFSInputStreamContainer::getInputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xInputStream.is() ) - return uno::Reference< io::XInputStream >(); - - return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ), uno::UNO_QUERY ); -} - -//----------------------------------------------- -uno::Reference< io::XOutputStream > SAL_CALL OFSInputStreamContainer::getOutputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - return uno::Reference< io::XOutputStream >(); -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - m_xSeekable->seek( location ); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OFSInputStreamContainer::getPosition() - throw ( io::IOException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getPosition(); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OFSInputStreamContainer::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getLength(); -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::dispose( ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xInputStream.is() ) - throw uno::RuntimeException(); - - m_xInputStream->closeInput(); - - if ( m_pListenersContainer ) - { - lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); - m_pListenersContainer->disposeAndClear( aSource ); - } - - m_bDisposed = sal_True; -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_pListenersContainer ) - m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex ); - - m_pListenersContainer->addInterface( xListener ); -} - -//----------------------------------------------- -void SAL_CALL OFSInputStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( m_pListenersContainer ) - m_pListenersContainer->removeInterface( xListener ); -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/oinputstreamcontainer.hxx b/svl/source/fsstor/oinputstreamcontainer.hxx deleted file mode 100644 index 411890efe4..0000000000 --- a/svl/source/fsstor/oinputstreamcontainer.hxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _OINPUTSTREAMCONTAINER_HXX_ -#define _OINPUTSTREAMCONTAINER_HXX_ - -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> - - -#include <cppuhelper/implbase2.hxx> -#include <cppuhelper/interfacecontainer.h> - -#include <osl/mutex.hxx> - -class OFSInputStreamContainer : public cppu::WeakImplHelper2 < ::com::sun::star::io::XInputStream - ,::com::sun::star::embed::XExtendedStorageStream > - , public ::com::sun::star::io::XSeekable -{ -protected: - ::osl::Mutex m_aMutex; - - ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream > m_xInputStream; - ::com::sun::star::uno::Reference < ::com::sun::star::io::XSeekable > m_xSeekable; - - sal_Bool m_bSeekable; - - sal_Bool m_bDisposed; - - ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners - -public: - OFSInputStreamContainer( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XInputStream >& xStream ); - - virtual ~OFSInputStreamContainer(); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL acquire() throw(); - virtual void SAL_CALL release() throw(); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - - //XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - //XComponent - virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/ostreamcontainer.cxx b/svl/source/fsstor/ostreamcontainer.cxx deleted file mode 100644 index f7a30ae765..0000000000 --- a/svl/source/fsstor/ostreamcontainer.cxx +++ /dev/null @@ -1,569 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include "ostreamcontainer.hxx" - - -using namespace ::com::sun::star; - -//----------------------------------------------- -OFSStreamContainer::OFSStreamContainer( const uno::Reference < io::XStream >& xStream ) -: m_bDisposed( sal_False ) -, m_bInputClosed( sal_False ) -, m_bOutputClosed( sal_False ) -, m_pListenersContainer( NULL ) -, m_pTypeCollection( NULL ) -{ - try - { - m_xStream = xStream; - if ( !m_xStream.is() ) - throw uno::RuntimeException(); - - m_xSeekable = uno::Reference< io::XSeekable >( xStream, uno::UNO_QUERY ); - m_xInputStream = xStream->getInputStream(); - m_xOutputStream = xStream->getOutputStream(); - m_xTruncate = uno::Reference< io::XTruncate >( m_xOutputStream, uno::UNO_QUERY ); - m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >( m_xOutputStream, uno::UNO_QUERY ); - } - catch( uno::Exception& ) - { - m_xStream = uno::Reference< io::XStream >(); - m_xSeekable = uno::Reference< io::XSeekable >(); - m_xInputStream = uno::Reference< io::XInputStream >(); - m_xOutputStream = uno::Reference< io::XOutputStream >(); - m_xTruncate = uno::Reference< io::XTruncate >(); - m_xAsyncOutputMonitor = uno::Reference< io::XAsyncOutputMonitor >(); - } -} - -//----------------------------------------------- -OFSStreamContainer::~OFSStreamContainer() -{ - if ( m_pListenersContainer ) - { - delete m_pListenersContainer; - m_pListenersContainer = NULL; - } -} - -// XInterface -//----------------------------------------------- -uno::Any SAL_CALL OFSStreamContainer::queryInterface( const uno::Type& rType ) - throw( uno::RuntimeException ) -{ - uno::Any aReturn; - - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<lang::XTypeProvider*> ( this ) - , static_cast<io::XStream*> ( this ) - , static_cast<embed::XExtendedStorageStream*> ( this ) - , static_cast<lang::XComponent*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - - if ( m_xSeekable.is() ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<io::XSeekable*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - - if ( m_xInputStream.is() ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<io::XInputStream*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - if ( m_xOutputStream.is() ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<io::XOutputStream*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - if ( m_xTruncate.is() ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<io::XTruncate*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - if ( m_xAsyncOutputMonitor.is() ) - { - aReturn <<= ::cppu::queryInterface - ( rType - , static_cast<io::XAsyncOutputMonitor*> ( this ) ); - - if ( aReturn.hasValue() == sal_True ) - return aReturn ; - } - - return OWeakObject::queryInterface( rType ); -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::acquire() - throw() -{ - OWeakObject::acquire(); -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::release() - throw() -{ - OWeakObject::release(); -} - -// XTypeProvider -//----------------------------------------------- -uno::Sequence< uno::Type > SAL_CALL OFSStreamContainer::getTypes() - throw( uno::RuntimeException ) -{ - if ( m_pTypeCollection == NULL ) - { - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_pTypeCollection == NULL ) - { - ::cppu::OTypeCollection aTypeCollection - ( ::getCppuType( ( const uno::Reference< lang::XTypeProvider >* )NULL ) - , ::getCppuType( ( const uno::Reference< embed::XExtendedStorageStream >* )NULL ) ); - - if ( m_xSeekable.is() ) - aTypeCollection = ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< io::XSeekable >* )NULL ), - aTypeCollection.getTypes() ); - if ( m_xInputStream.is() ) - aTypeCollection = ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< io::XInputStream >* )NULL ), - aTypeCollection.getTypes() ); - - if ( m_xOutputStream.is() ) - aTypeCollection = ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< io::XOutputStream >* )NULL ), - aTypeCollection.getTypes() ); - if ( m_xTruncate.is() ) - aTypeCollection = ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< io::XTruncate >* )NULL ), - aTypeCollection.getTypes() ); - if ( m_xAsyncOutputMonitor.is() ) - aTypeCollection = ::cppu::OTypeCollection - ( ::getCppuType( ( const uno::Reference< io::XAsyncOutputMonitor >* )NULL ), - aTypeCollection.getTypes() ); - - m_pTypeCollection = new ::cppu::OTypeCollection( aTypeCollection ); - } - } - return m_pTypeCollection->getTypes() ; -} - -//----------------------------------------------- -uno::Sequence< sal_Int8 > SAL_CALL OFSStreamContainer::getImplementationId() - throw( uno::RuntimeException ) -{ - static ::cppu::OImplementationId* pID = NULL ; - - if ( pID == NULL ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; - - if ( pID == NULL ) - { - static ::cppu::OImplementationId aID( sal_False ) ; - pID = &aID ; - } - } - - return pID->getImplementationId() ; -} - -// XStream -//----------------------------------------------- -uno::Reference< io::XInputStream > SAL_CALL OFSStreamContainer::getInputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() ) - throw uno::RuntimeException(); - - if ( m_xInputStream.is() ) - return uno::Reference< io::XInputStream >( static_cast< io::XInputStream* >( this ) ); - - return uno::Reference< io::XInputStream >(); -} - -//----------------------------------------------- -uno::Reference< io::XOutputStream > SAL_CALL OFSStreamContainer::getOutputStream() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() ) - throw uno::RuntimeException(); - - if ( m_xOutputStream.is() ) - return uno::Reference< io::XOutputStream >( static_cast< io::XOutputStream* >( this ) ); - - return uno::Reference< io::XOutputStream >(); -} - -// XComponent -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::dispose() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() ) - throw uno::RuntimeException(); - - if ( m_xInputStream.is() && !m_bInputClosed ) - { - m_xInputStream->closeInput(); - m_bInputClosed = sal_True; - } - - if ( m_xOutputStream.is() && !m_bOutputClosed ) - { - m_xOutputStream->closeOutput(); - m_bOutputClosed = sal_True; - } - - if ( m_pListenersContainer ) - { - lang::EventObject aSource( static_cast< ::cppu::OWeakObject*>( this ) ); - m_pListenersContainer->disposeAndClear( aSource ); - } - - m_bDisposed = sal_True; -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_pListenersContainer ) - m_pListenersContainer = new ::cppu::OInterfaceContainerHelper( m_aMutex ); - - m_pListenersContainer->addInterface( xListener ); -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( m_pListenersContainer ) - m_pListenersContainer->removeInterface( xListener ); -} - - -// XSeekable -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::seek( sal_Int64 location ) - throw ( lang::IllegalArgumentException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xSeekable.is() ) - throw uno::RuntimeException(); - - m_xSeekable->seek( location ); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OFSStreamContainer::getPosition() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getPosition(); -} - -//----------------------------------------------- -sal_Int64 SAL_CALL OFSStreamContainer::getLength() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xSeekable.is() ) - throw uno::RuntimeException(); - - return m_xSeekable->getLength(); -} - - -// XInputStream -//----------------------------------------------- -sal_Int32 SAL_CALL OFSStreamContainer::readBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xInputStream.is() ) - throw uno::RuntimeException(); - - return m_xInputStream->readBytes( aData, nBytesToRead ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OFSStreamContainer::readSomeBytes( uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) - throw( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xInputStream.is() ) - throw uno::RuntimeException(); - - return m_xInputStream->readSomeBytes( aData, nMaxBytesToRead ); -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::skipBytes( sal_Int32 nBytesToSkip ) - throw( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xInputStream.is() ) - throw uno::RuntimeException(); - - m_xInputStream->skipBytes( nBytesToSkip ); -} - -//----------------------------------------------- -sal_Int32 SAL_CALL OFSStreamContainer::available() - throw( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xInputStream.is() ) - throw uno::RuntimeException(); - - return m_xInputStream->available(); -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::closeInput() - throw( io::NotConnectedException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xInputStream.is() ) - throw uno::RuntimeException(); - - if ( m_xInputStream.is() ) - { - m_xInputStream->closeInput(); - m_bInputClosed = sal_True; - } - - if ( m_bOutputClosed ) - dispose(); -} - -// XOutputStream -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::writeBytes( const uno::Sequence< sal_Int8 >& aData ) - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xOutputStream.is() ) - throw uno::RuntimeException(); - - return m_xOutputStream->writeBytes( aData ); -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::flush() - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xOutputStream.is() ) - throw uno::RuntimeException(); - - return m_xOutputStream->flush(); -} - -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::closeOutput() - throw ( io::NotConnectedException, - io::BufferSizeExceededException, - io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xOutputStream.is() ) - throw uno::RuntimeException(); - - if ( m_xOutputStream.is() ) - { - m_xOutputStream->closeOutput(); - m_bOutputClosed = sal_True; - } - - if ( m_bInputClosed ) - dispose(); -} - - -// XTruncate -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::truncate() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xTruncate.is() ) - throw uno::RuntimeException(); - - m_xTruncate->truncate(); -} - - -// XAsyncOutputMonitor -//----------------------------------------------- -void SAL_CALL OFSStreamContainer::waitForCompletion() - throw ( io::IOException, - uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( m_bDisposed ) - throw lang::DisposedException(); - - if ( !m_xStream.is() || !m_xAsyncOutputMonitor.is() ) - throw uno::RuntimeException(); - - m_xAsyncOutputMonitor->waitForCompletion(); -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/fsstor/ostreamcontainer.hxx b/svl/source/fsstor/ostreamcontainer.hxx deleted file mode 100644 index ad9bd4569a..0000000000 --- a/svl/source/fsstor/ostreamcontainer.hxx +++ /dev/null @@ -1,127 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _OSTREAMCONTAINER_HXX_ -#define _OSTREAMCONTAINER_HXX_ - -#include <com/sun/star/uno/XInterface.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/embed/XExtendedStorageStream.hpp> -#include <com/sun/star/io/XSeekable.hpp> -#include <com/sun/star/io/XTruncate.hpp> -#include <com/sun/star/io/XInputStream.hpp> -#include <com/sun/star/io/XOutputStream.hpp> -#include <com/sun/star/io/XStream.hpp> -#include "com/sun/star/io/XAsyncOutputMonitor.hpp" -#include <cppuhelper/weak.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/interfacecontainer.h> -#include <osl/mutex.hxx> - -class OFSStreamContainer : public cppu::OWeakObject, - public ::com::sun::star::lang::XTypeProvider, - public ::com::sun::star::embed::XExtendedStorageStream, - public ::com::sun::star::io::XSeekable, - public ::com::sun::star::io::XInputStream, - public ::com::sun::star::io::XOutputStream, - public ::com::sun::star::io::XTruncate, - public ::com::sun::star::io::XAsyncOutputMonitor -{ - ::osl::Mutex m_aMutex; - - ::com::sun::star::uno::Reference< ::com::sun::star::io::XStream > m_xStream; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XSeekable > m_xSeekable; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > m_xInputStream; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > m_xOutputStream; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XTruncate > m_xTruncate; - ::com::sun::star::uno::Reference< ::com::sun::star::io::XAsyncOutputMonitor > m_xAsyncOutputMonitor; - - sal_Bool m_bDisposed; - sal_Bool m_bInputClosed; - sal_Bool m_bOutputClosed; - - ::cppu::OInterfaceContainerHelper* m_pListenersContainer; // list of listeners - ::cppu::OTypeCollection* m_pTypeCollection; - -public: - OFSStreamContainer( const ::com::sun::star::uno::Reference < ::com::sun::star::io::XStream >& xStream ); - virtual ~OFSStreamContainer(); - - // XInterface - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& rType ) - throw( ::com::sun::star::uno::RuntimeException ); - virtual void SAL_CALL acquire() throw(); - virtual void SAL_CALL release() throw(); - - // XTypeProvider - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes() - throw( ::com::sun::star::uno::RuntimeException ); - virtual ::com::sun::star::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() - throw( ::com::sun::star::uno::RuntimeException ); - - // XStream - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream > SAL_CALL getInputStream( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > SAL_CALL getOutputStream( ) throw (::com::sun::star::uno::RuntimeException); - - // XComponent - virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException); - - // XSeekable - virtual void SAL_CALL seek( sal_Int64 location ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getPosition() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int64 SAL_CALL getLength() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - // XInputStream - virtual sal_Int32 SAL_CALL readBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL readSomeBytes( ::com::sun::star::uno::Sequence< sal_Int8 >& aData, sal_Int32 nMaxBytesToRead ) throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL skipBytes( sal_Int32 nBytesToSkip ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL available( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeInput( ) - throw(::com::sun::star::io::NotConnectedException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - // XOutputStream - virtual void SAL_CALL writeBytes( const ::com::sun::star::uno::Sequence< sal_Int8 >& aData ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL flush( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL closeOutput( ) throw (::com::sun::star::io::NotConnectedException, ::com::sun::star::io::BufferSizeExceededException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - // XTruncate - virtual void SAL_CALL truncate() throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - // XAsyncOutputMonitor - virtual void SAL_CALL waitForCompletion( ) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/inc/fsfactory.hxx b/svl/source/inc/fsfactory.hxx deleted file mode 100644 index 58842ed58a..0000000000 --- a/svl/source/inc/fsfactory.hxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 __FSFACTORY_HXX_ -#define __FSACTORY_HXX_ - -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <cppuhelper/implbase2.hxx> - - -class FSStorage; - -class FSStorageFactory : public ::cppu::WeakImplHelper2< ::com::sun::star::lang::XSingleServiceFactory, - ::com::sun::star::lang::XServiceInfo > -{ - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xFactory; - -public: - FSStorageFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xFactory ) - : m_xFactory( xFactory ) - { - OSL_ENSURE( xFactory.is(), "No service manager is provided!\n" ); - } - - static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL - impl_staticGetSupportedServiceNames(); - - static ::rtl::OUString SAL_CALL impl_staticGetImplementationName(); - - static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL - impl_staticCreateSelfInstance( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ); - - - // XSingleServiceFactory - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstance() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName() throw (::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (::com::sun::star::uno::RuntimeException); - -}; - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/inc/passwordcontainer.hxx b/svl/source/inc/passwordcontainer.hxx deleted file mode 100644 index b8f134cb48..0000000000 --- a/svl/source/inc/passwordcontainer.hxx +++ /dev/null @@ -1,428 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 INCLUDED_COMPHELPER_PASSWORDCONTAINER_HXX -#define INCLUDED_COMPHELPER_PASSWORDCONTAINER_HXX - -#include <list> -#include <vector> -#include <map> -#include <com/sun/star/task/XPasswordContainer.hpp> -#include <com/sun/star/task/XUrlContainer.hpp> -#include <com/sun/star/task/PasswordRequestMode.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XEventListener.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/task/XMasterPasswordHandling2.hpp> -#include <cppuhelper/implbase5.hxx> -#include <cppuhelper/typeprovider.hxx> -#include <cppuhelper/queryinterface.hxx> -#include <cppuhelper/factory.hxx> - -#include <tools/stream.hxx> -#include <unotools/configitem.hxx> -#include <ucbhelper/interactionrequest.hxx> - -#include <rtl/ref.hxx> -#include <osl/mutex.hxx> - -#include "syscreds.hxx" - -#define MEMORY_RECORD 0 -#define PERSISTENT_RECORD 1 - -//---------------------------------------------------------------------------------- - -class NamePassRecord -{ - ::rtl::OUString m_aName; - - // there are two lists of passwords, memory passwords and persistent passwords - sal_Bool m_bHasMemPass; - ::std::vector< ::rtl::OUString > m_aMemPass; - - // persistent passwords are encrypted in one string - sal_Bool m_bHasPersPass; - ::rtl::OUString m_aPersPass; - - void InitArrays( sal_Bool bHasMemoryList, const ::std::vector< ::rtl::OUString >& aMemoryList, - sal_Bool bHasPersistentList, const ::rtl::OUString& aPersistentList ) - { - m_bHasMemPass = bHasMemoryList; - if ( bHasMemoryList ) - m_aMemPass = aMemoryList; - - m_bHasPersPass = bHasPersistentList; - if ( bHasPersistentList ) - m_aPersPass = aPersistentList; - } - -public: - - NamePassRecord( const ::rtl::OUString& aName ) - : m_aName( aName ) - , m_bHasMemPass( sal_False ) - , m_bHasPersPass( sal_False ) - { - } - - NamePassRecord( const ::rtl::OUString& aName, const ::std::vector< ::rtl::OUString >& aMemoryList ) - : m_aName( aName ) - , m_bHasMemPass( sal_True ) - , m_aMemPass( aMemoryList ) - , m_bHasPersPass( sal_False ) - { - } - - NamePassRecord( const ::rtl::OUString& aName, const ::rtl::OUString& aPersistentList ) - : m_aName( aName ) - , m_bHasMemPass( sal_False ) - , m_bHasPersPass( sal_True ) - , m_aPersPass( aPersistentList ) - { - } - - NamePassRecord( const ::rtl::OUString& aName, - sal_Bool bHasMemoryList, const ::std::vector< ::rtl::OUString >& aMemoryList, - sal_Bool bHasPersistentList, const ::rtl::OUString aPersistentList ) - : m_aName( aName ) - , m_bHasMemPass( bHasMemoryList ) - , m_bHasPersPass( bHasPersistentList ) - { - InitArrays( bHasMemoryList, aMemoryList, bHasPersistentList, aPersistentList ); - } - - NamePassRecord( const NamePassRecord& aRecord ) - : m_aName( aRecord.m_aName ) - , m_bHasMemPass( sal_False ) - , m_bHasPersPass( sal_False ) - { - InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass, aRecord.m_bHasPersPass, aRecord.m_aPersPass ); - } - - NamePassRecord& operator=( const NamePassRecord& aRecord ) - { - m_aName = aRecord.m_aName; - - m_aMemPass.clear(); - m_aPersPass = ::rtl::OUString(); - InitArrays( aRecord.m_bHasMemPass, aRecord.m_aMemPass, aRecord.m_bHasPersPass, aRecord.m_aPersPass ); - - return *this; - } - - ::rtl::OUString GetUserName() const - { - return m_aName; - } - - sal_Bool HasPasswords( sal_Int8 nStatus ) const - { - if ( nStatus == MEMORY_RECORD ) - return m_bHasMemPass; - if ( nStatus == PERSISTENT_RECORD ) - return m_bHasPersPass; - - return sal_False; - } - - ::std::vector< ::rtl::OUString > GetMemPasswords() const - { - if ( m_bHasMemPass ) - return m_aMemPass; - - return ::std::vector< ::rtl::OUString >(); - } - - ::rtl::OUString GetPersPasswords() const - { - if ( m_bHasPersPass ) - return m_aPersPass; - - return ::rtl::OUString(); - } - - void SetMemPasswords( const ::std::vector< ::rtl::OUString >& aMemList ) - { - m_aMemPass = aMemList; - m_bHasMemPass = sal_True; - } - - void SetPersPasswords( const ::rtl::OUString& aPersList ) - { - m_aPersPass = aPersList; - m_bHasPersPass = sal_True; - } - - void RemovePasswords( sal_Int8 nStatus ) - { - if ( nStatus == MEMORY_RECORD ) - { - m_bHasMemPass = sal_False; - m_aMemPass.clear(); - } - else if ( nStatus == PERSISTENT_RECORD ) - { - m_bHasPersPass = sal_False; - m_aPersPass = ::rtl::OUString(); - } - } - -}; - -//---------------------------------------------------------------------------------- - -typedef ::std::pair< const ::rtl::OUString, ::std::list< NamePassRecord > > PairUrlRecord; -typedef ::std::map< ::rtl::OUString, ::std::list< NamePassRecord > > PassMap; - -//---------------------------------------------------------------------------------- - -class PasswordContainer; - -class StorageItem : public ::utl::ConfigItem { - PasswordContainer* mainCont; - sal_Bool hasEncoded; - ::rtl::OUString mEncoded; -public: - StorageItem( PasswordContainer* point, const ::rtl::OUString& path ) : - ConfigItem( path, CONFIG_MODE_IMMEDIATE_UPDATE ), - mainCont( point ), - hasEncoded( sal_False ) - { - ::com::sun::star::uno::Sequence< ::rtl::OUString > aNode( 1 ); - *aNode.getArray() = path; - *aNode.getArray() += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/Store")); - EnableNotification( aNode ); - } - - PassMap getInfo(); - void update( const ::rtl::OUString& url, const NamePassRecord& rec ); - void remove( const ::rtl::OUString& url, const ::rtl::OUString& rec ); - void clear(); - - sal_Bool getEncodedMP( ::rtl::OUString& aResult ); - void setEncodedMP( const ::rtl::OUString& aResult, sal_Bool bAcceptEnmpty = sal_False ); - void setUseStorage( sal_Bool bUse ); - sal_Bool useStorage(); - - virtual void Notify( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPropertyNames ); - virtual void Commit(); -}; - -//---------------------------------------------------------------------------------- - -enum PasswordState { - no_password, - entered, - cancelled -}; - -class PasswordContainer : public ::cppu::WeakImplHelper5< - ::com::sun::star::task::XPasswordContainer, - ::com::sun::star::task::XMasterPasswordHandling2, - ::com::sun::star::task::XUrlContainer, - ::com::sun::star::lang::XServiceInfo, - ::com::sun::star::lang::XEventListener > -{ -private: - PassMap m_aContainer; - StorageItem* m_pStorageFile; - ::osl::Mutex mMutex; - ::rtl::OUString m_aMasterPasswd; // master password is set when the string is not empty - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > mComponent; - SysCredentialsConfig mUrlContainer; - - ::com::sun::star::uno::Sequence< ::com::sun::star::task::UserRecord > CopyToUserRecordSequence( - const ::std::list< NamePassRecord >& original, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); - - ::com::sun::star::task::UserRecord CopyToUserRecord( - const NamePassRecord& aRecord, - sal_Bool& io_bTryToDecode, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler ); - - ::com::sun::star::uno::Sequence< ::com::sun::star::task::UserRecord > FindUsr( - const ::std::list< NamePassRecord >& userlist, - const ::rtl::OUString& name, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); -bool createUrlRecord( - const PassMap::iterator & rIter, - bool bName, - const ::rtl::OUString & aName, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler, - ::com::sun::star::task::UrlRecord & rRec ) - throw( ::com::sun::star::uno::RuntimeException ); - -::com::sun::star::task::UrlRecord find( - const ::rtl::OUString& aURL, - const ::rtl::OUString& aName, - bool bName, // only needed to support empty user names - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& aHandler ) throw(::com::sun::star::uno::RuntimeException); - - ::rtl::OUString GetDefaultMasterPassword(); - - ::rtl::OUString RequestPasswordFromUser( - ::com::sun::star::task::PasswordRequestMode aRMode, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ); - - ::rtl::OUString GetMasterPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); - - void UpdateVector( const ::rtl::OUString& url, ::std::list< NamePassRecord >& toUpdate, NamePassRecord& rec, sal_Bool writeFile ) - throw(::com::sun::star::uno::RuntimeException); - - void PrivateAdd( const ::rtl::OUString& aUrl, - const ::rtl::OUString& aUserName, - const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPasswords, - char aMode, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); - - ::std::vector< ::rtl::OUString > DecodePasswords( const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPassword ) - throw(::com::sun::star::uno::RuntimeException); - - ::rtl::OUString EncodePasswords( ::std::vector< ::rtl::OUString > lines, const ::rtl::OUString& aMasterPassword ) - throw(::com::sun::star::uno::RuntimeException); - -public: - PasswordContainer( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ); - ~PasswordContainer(); - - virtual void SAL_CALL add( const ::rtl::OUString& aUrl, - const ::rtl::OUString& aUserName, - const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPasswords, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL addPersistent( const ::rtl::OUString& aUrl, - const ::rtl::OUString& aUserName, - const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aPasswords, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::task::UrlRecord SAL_CALL - find( const ::rtl::OUString& aUrl, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::task::UrlRecord SAL_CALL - findForName( const ::rtl::OUString& aUrl, - const ::rtl::OUString& aUserName, - const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) - throw(::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL remove( const ::rtl::OUString& aUrl, - const ::rtl::OUString& aUserName ) - throw(::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL removePersistent( const ::rtl::OUString& aUrl, - const ::rtl::OUString& aUserName ) - throw(::com::sun::star::uno::RuntimeException); - - virtual void SAL_CALL removeAllPersistent() throw(::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::task::UrlRecord > SAL_CALL - getAllPersistent( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ) throw(::com::sun::star::uno::RuntimeException); - - - // provide factory - static ::rtl::OUString SAL_CALL impl_getStaticImplementationName( ) throw(::com::sun::star::uno::RuntimeException); - static ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL - impl_getStaticSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); - static ::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleServiceFactory > SAL_CALL - impl_createFactory( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ServiceManager ) throw(::com::sun::star::uno::RuntimeException); - static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL - impl_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceManager ) throw( ::com::sun::star::uno::RuntimeException ); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); - - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL - getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); - - // XEventListener - virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) - throw(::com::sun::star::uno::RuntimeException); - - // XMasterPasswordHandling - virtual ::sal_Bool SAL_CALL authorizateWithMasterPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) - throw (::com::sun::star::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL changeMasterPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeMasterPassword() throw (::com::sun::star::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL hasMasterPassword( ) throw (::com::sun::star::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL allowPersistentStoring( ::sal_Bool bAllow ) throw (::com::sun::star::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL isPersistentStoringAllowed( ) throw (::com::sun::star::uno::RuntimeException); - - // XMasterPasswordHandling2 - virtual ::sal_Bool SAL_CALL useDefaultMasterPassword( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler ) throw (::com::sun::star::uno::RuntimeException); - virtual ::sal_Bool SAL_CALL isDefaultMasterPasswordUsed( ) throw (::com::sun::star::uno::RuntimeException); - - // XUrlContainer - virtual void SAL_CALL addUrl( const ::rtl::OUString& Url, ::sal_Bool MakePersistent ) throw (::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL findUrl( const ::rtl::OUString& Url ) throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeUrl( const ::rtl::OUString& Url ) throw (::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getUrls( ::sal_Bool OnlyPersistent ) throw (::com::sun::star::uno::RuntimeException); - - void Notify(); -}; - -//---------------------------------------------------------------------------------- - -class MasterPasswordRequest_Impl : public ucbhelper::InteractionRequest -{ - ::rtl::Reference< ucbhelper::InteractionSupplyAuthentication > m_xAuthSupplier; - -public: - MasterPasswordRequest_Impl( ::com::sun::star::task::PasswordRequestMode Mode ); - - const ::rtl::Reference< ucbhelper::InteractionSupplyAuthentication > & - getAuthenticationSupplier() const { return m_xAuthSupplier; } - -}; - -//---------------------------------------------------------------------------------- - -class RW_SvMemoryStream : public SvMemoryStream { -public: - RW_SvMemoryStream( void* Buf, sal_uLong Size, StreamMode eMode ): - SvMemoryStream( Buf, Size, eMode){} - - RW_SvMemoryStream( sal_uLong InitSize=512, sal_uLong Resize=64 ): - SvMemoryStream( InitSize, Resize ){} - - sal_uLong getActualSize(){ return nEndOfData; } -}; - - - -#endif // #ifndef INCLUDED_COMPHELPER_PASSWORDCONTAINER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/inc/poolio.hxx b/svl/source/inc/poolio.hxx deleted file mode 100644 index 87bb47b105..0000000000 --- a/svl/source/inc/poolio.hxx +++ /dev/null @@ -1,216 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 <svl/brdcst.hxx> -#include <boost/shared_ptr.hpp> -#include <deque> - -#ifndef DELETEZ -#define DELETEZ(pPtr) { delete pPtr; pPtr = 0; } -#endif - - -struct SfxPoolVersion_Impl -{ - sal_uInt16 _nVer; - sal_uInt16 _nStart, _nEnd; - sal_uInt16* _pMap; - - SfxPoolVersion_Impl( sal_uInt16 nVer, sal_uInt16 nStart, sal_uInt16 nEnd, - sal_uInt16 *pMap ) - : _nVer( nVer ), - _nStart( nStart ), - _nEnd( nEnd ), - _pMap( pMap ) - {} - SfxPoolVersion_Impl( const SfxPoolVersion_Impl &rOrig ) - : _nVer( rOrig._nVer ), - _nStart( rOrig._nStart ), - _nEnd( rOrig._nEnd ), - _pMap( rOrig._pMap ) - {} -}; - -typedef std::deque<SfxPoolItem*> SfxPoolItemArrayBase_Impl; - -typedef boost::shared_ptr< SfxPoolVersion_Impl > SfxPoolVersion_ImplPtr; -typedef std::deque< SfxPoolVersion_ImplPtr > SfxPoolVersionArr_Impl; - -struct SfxPoolItemArray_Impl: public SfxPoolItemArrayBase_Impl -{ - size_t nFirstFree; - - SfxPoolItemArray_Impl () - : nFirstFree( 0 ) - {} -}; - -class SfxStyleSheetIterator; - -struct SfxItemPool_Impl -{ - SfxBroadcaster aBC; - SfxPoolItemArray_Impl** ppPoolItems; - SfxPoolVersionArr_Impl aVersions; - sal_uInt16 nVersion; - sal_uInt16 nLoadingVersion; - sal_uInt16 nInitRefCount; // 1, beim Laden ggf. 2 - sal_uInt16 nVerStart, nVerEnd; // WhichRange in Versions - sal_uInt16 nStoringStart, nStoringEnd; // zu speichernder Range - sal_uInt8 nMajorVer, nMinorVer; // Pool selbst - SfxMapUnit eDefMetric; - bool bInSetItem; - bool bStreaming; // in Load() bzw. Store() - - SfxItemPool_Impl( sal_uInt16 nStart, sal_uInt16 nEnd ) - : ppPoolItems (new SfxPoolItemArray_Impl*[ nEnd - nStart + 1]) - , nLoadingVersion(0) - , nInitRefCount(0) - , nVerStart(0) - , nVerEnd(0) - , nStoringStart(0) - , nStoringEnd(0) - , nMajorVer(0) - , nMinorVer(0) - , bInSetItem(false) - , bStreaming(false) - { - memset( ppPoolItems, 0, sizeof( SfxPoolItemArray_Impl* ) * ( nEnd - nStart + 1) ); - } - - ~SfxItemPool_Impl() - { - delete[] ppPoolItems; - } - - void DeleteItems() - { - delete[] ppPoolItems; - ppPoolItems = 0; - } -}; - -// ----------------------------------------------------------------------- - -// IBM-C-Set mag keine doppelten Defines -#ifdef DBG -# undef DBG -#endif - -#if defined(DBG_UTIL) && defined(MSC) -#define SFX_TRACE(s,p) \ - { \ - ByteString aPtr(RTL_CONSTASCII_STRINGPARAM("0x0000:0x0000")); \ - _snprintf(const_cast< sal_Char *>(aPtr.GetBuffer()), aPtr.Len(), \ - "%lp", p ); \ - aPtr.Insert(s, 0); \ - DbgTrace( aPtr.GetBuffer() ); \ - } -#define DBG(x) x -#else -#define SFX_TRACE(s,p) -#define DBG(x) -#endif - -#define CHECK_FILEFORMAT( rStream, nTag ) \ - { sal_uInt16 nFileTag; \ - rStream >> nFileTag; \ - if ( nTag != nFileTag ) \ - { \ - OSL_FAIL( #nTag ); /*! s.u. */ \ - /*! error-code setzen und auswerten! */ \ - (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ - pImp->bStreaming = sal_False; \ - return rStream; \ - } \ - } - -#define CHECK_FILEFORMAT_RELEASE( rStream, nTag, pPointer ) \ - { sal_uInt16 nFileTag; \ - rStream >> nFileTag; \ - if ( nTag != nFileTag ) \ - { \ - OSL_FAIL( #nTag ); /*! s.u. */ \ - /*! error-code setzen und auswerten! */ \ - (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ - pImp->bStreaming = sal_False; \ - delete pPointer; \ - return rStream; \ - } \ - } - -#define CHECK_FILEFORMAT2( rStream, nTag1, nTag2 ) \ - { sal_uInt16 nFileTag; \ - rStream >> nFileTag; \ - if ( nTag1 != nFileTag && nTag2 != nFileTag ) \ - { \ - OSL_FAIL( #nTag1 ); /*! s.u. */ \ - /*! error-code setzen und auswerten! */ \ - (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \ - pImp->bStreaming = sal_False; \ - return rStream; \ - } \ - } - -#define SFX_ITEMPOOL_VER_MAJOR sal_uInt8(2) -#define SFX_ITEMPOOL_VER_MINOR sal_uInt8(0) - -#define SFX_ITEMPOOL_TAG_STARTPOOL_4 sal_uInt16(0x1111) -#define SFX_ITEMPOOL_TAG_STARTPOOL_5 sal_uInt16(0xBBBB) -#define SFX_ITEMPOOL_TAG_ITEMPOOL sal_uInt16(0xAAAA) -#define SFX_ITEMPOOL_TAG_ITEMS sal_uInt16(0x2222) -#define SFX_ITEMPOOL_TAG_ITEM sal_uInt16(0x7777) -#define SFX_ITEMPOOL_TAG_SIZES sal_uInt16(0x3333) -#define SFX_ITEMPOOL_TAG_DEFAULTS sal_uInt16(0x4444) -#define SFX_ITEMPOOL_TAG_VERSIONMAP sal_uInt16(0x5555) -#define SFX_ITEMPOOL_TAG_HEADER sal_uInt16(0x6666) -#define SFX_ITEMPOOL_TAG_ENDPOOL sal_uInt16(0xEEEE) -#define SFX_ITEMPOOL_TAG_TRICK4OLD sal_uInt16(0xFFFF) - -#define SFX_ITEMPOOL_REC sal_uInt8(0x01) -#define SFX_ITEMPOOL_REC_HEADER sal_uInt8(0x10) -#define SFX_ITEMPOOL_REC_VERSIONMAP sal_uInt16(0x0020) -#define SFX_ITEMPOOL_REC_WHICHIDS sal_uInt16(0x0030) -#define SFX_ITEMPOOL_REC_ITEMS sal_uInt16(0x0040) -#define SFX_ITEMPOOL_REC_DEFAULTS sal_uInt16(0x0050) - -#define SFX_ITEMSET_REC sal_uInt8(0x02) - -#define SFX_STYLES_REC sal_uInt8(0x03) -#define SFX_STYLES_REC_HEADER sal_uInt16(0x0010) -#define SFX_STYLES_REC_STYLES sal_uInt16(0x0020) - -//======================================================================== - -inline sal_uInt16 SfxItemPool::GetIndex_Impl(sal_uInt16 nWhich) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - DBG_ASSERT(nWhich >= nStart && nWhich <= nEnd, "Which-Id nicht im Pool-Bereich"); - return nWhich - nStart; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/aeitem.cxx b/svl/source/items/aeitem.cxx deleted file mode 100644 index 7a804ce509..0000000000 --- a/svl/source/items/aeitem.cxx +++ /dev/null @@ -1,314 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/string.hxx> - -#define _SVSTDARR_USHORTS -#include <svl/svstdarr.hxx> -#include <svl/svarray.hxx> -#include <svl/aeitem.hxx> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxAllEnumItem) - -TYPEINIT1_AUTOFACTORY(SfxAllEnumItem, SfxEnumItem) - -// ----------------------------------------------------------------------- - -struct SfxAllEnumValue_Impl -{ - sal_uInt16 nValue; - XubString aText; -}; - -SV_DECL_PTRARR_DEL(SfxAllEnumValueArr, SfxAllEnumValue_Impl*, 0, 8) -SV_IMPL_PTRARR(SfxAllEnumValueArr, SfxAllEnumValue_Impl*) - -// ----------------------------------------------------------------------- - -SfxAllEnumItem::SfxAllEnumItem() : - SfxEnumItem(), - pValues( 0 ), - pDisabledValues( 0 ) -{ -} - -SfxAllEnumItem::SfxAllEnumItem( sal_uInt16 which, sal_uInt16 nVal, const XubString &rText ): - SfxEnumItem(which, nVal), - pValues( 0 ), - pDisabledValues( 0 ) -{ - DBG_CTOR(SfxAllEnumItem, 0); - InsertValue( nVal, rText ); -} - -// ----------------------------------------------------------------------- - -SfxAllEnumItem::SfxAllEnumItem(sal_uInt16 which, sal_uInt16 nVal): - SfxEnumItem(which, nVal), - pValues( 0 ), - pDisabledValues( 0 ) -{ - DBG_CTOR(SfxAllEnumItem, 0); - InsertValue( nVal ); -} - -// ----------------------------------------------------------------------- - -SfxAllEnumItem::SfxAllEnumItem( sal_uInt16 which, SvStream &rStream ): - SfxEnumItem(which, rStream), - pValues( 0 ), - pDisabledValues( 0 ) -{ - DBG_CTOR(SfxAllEnumItem, 0); - InsertValue( GetValue() ); -} - -// ----------------------------------------------------------------------- - - -SfxAllEnumItem::SfxAllEnumItem(sal_uInt16 which): - SfxEnumItem(which, 0), - pValues( 0 ), - pDisabledValues( 0 ) -{ - DBG_CTOR(SfxAllEnumItem, 0); -} - - -// ----------------------------------------------------------------------- - -SfxAllEnumItem::SfxAllEnumItem(const SfxAllEnumItem &rCopy): - SfxEnumItem(rCopy), - pValues(0), - pDisabledValues( 0 ) -{ - DBG_CTOR(SfxAllEnumItem, 0); - if ( !rCopy.pValues ) - return; - - pValues = new SfxAllEnumValueArr; - - for ( sal_uInt16 nPos = 0; nPos < rCopy.pValues->Count(); ++nPos ) - { - SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl; - pVal->nValue = rCopy.pValues->GetObject(nPos)->nValue; - pVal->aText = rCopy.pValues->GetObject(nPos)->aText; - const SfxAllEnumValue_Impl *pTemp = pVal; - pValues->Insert( pTemp, nPos ); - } - - if( rCopy.pDisabledValues ) - { - pDisabledValues = new SvUShorts; - for ( sal_uInt16 nPos = 0; nPos < rCopy.pDisabledValues->Count(); ++nPos ) - { - pDisabledValues->Insert( rCopy.pDisabledValues->GetObject(nPos), - nPos ); - } - } -} - -// ----------------------------------------------------------------------- - -SfxAllEnumItem::~SfxAllEnumItem() -{ - DBG_DTOR(SfxAllEnumItem, 0); - delete pValues; - delete pDisabledValues; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxAllEnumItem::GetValueCount() const -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - return pValues ? pValues->Count() : 0; -} - -// ----------------------------------------------------------------------- - -XubString SfxAllEnumItem::GetValueTextByPos( sal_uInt16 nPos ) const -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" ); - return pValues->GetObject(nPos)->aText; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxAllEnumItem::GetValueByPos( sal_uInt16 nPos ) const -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - DBG_ASSERT( pValues && nPos < pValues->Count(), "enum overflow" ); - return pValues->GetObject(nPos)->nValue; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxAllEnumItem::Clone( SfxItemPool * ) const -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - return new SfxAllEnumItem(*this); -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxAllEnumItem::Create( SvStream & rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - return new SfxAllEnumItem( Which(), rStream ); -} - - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxAllEnumItem::_GetPosByValue( sal_uInt16 nVal ) const - -/* [Beschreibung] - - Im Ggs. zu <SfxEnumItemInterface::GetPosByValue(sal_uInt16)const> liefert - diese interne Methode bei nicht vorhandenen Values die Position, - an der der Wert liegen w"urde. -*/ - -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - - if ( !pValues ) - return 0; - - //!O: binaere Suche oder SortArray verwenden - sal_uInt16 nPos; - for ( nPos = 0; nPos < pValues->Count(); ++nPos ) - if ( pValues->GetObject(nPos)->nValue >= nVal ) - return nPos; - return nPos; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxAllEnumItem::GetPosByValue( sal_uInt16 nValue ) const - -/* [Beschreibung] - - Liefert im Gegensatz zu <SfxEnumItemInterface::GetPosByValue(sal_uInt16)const> - immer nValue zur"uck, solange nicht mindestens ein Wert mit einer der - Methoden <SfxAllEnumItem::InsertValue()> eingef"ugt wurde. -*/ - -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - - if ( !pValues || !pValues->Count() ) - return nValue; - - return SfxEnumItem::GetPosByValue( nValue ); -} - -// ----------------------------------------------------------------------- - -void SfxAllEnumItem::InsertValue( sal_uInt16 nValue, const XubString &rValue ) -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl; - pVal->nValue = nValue; - pVal->aText = rValue; - const SfxAllEnumValue_Impl *pTemp = pVal; - if ( !pValues ) - pValues = new SfxAllEnumValueArr; - else if ( GetPosByValue( nValue ) != USHRT_MAX ) - // remove when exists - RemoveValue( nValue ); - // then insert - pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?! -} - -// ----------------------------------------------------------------------- - -void SfxAllEnumItem::InsertValue( sal_uInt16 nValue ) -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - SfxAllEnumValue_Impl *pVal = new SfxAllEnumValue_Impl; - pVal->nValue = nValue; - pVal->aText = XubString::CreateFromInt32( nValue ); - const SfxAllEnumValue_Impl *pTemp = pVal; - if ( !pValues ) - pValues = new SfxAllEnumValueArr; - - pValues->Insert( pTemp, _GetPosByValue(nValue) ); //! doppelte?! -} - -void SfxAllEnumItem::DisableValue( sal_uInt16 nValue ) -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - if ( !pDisabledValues ) - pDisabledValues = new SvUShorts; - - pDisabledValues->Insert( nValue, pDisabledValues->Count() ); -} - -sal_Bool SfxAllEnumItem::IsEnabled( sal_uInt16 nValue ) const -{ - if ( pDisabledValues ) - { - for ( sal_uInt16 i=0; i<pDisabledValues->Count(); i++ ) - if ( (*pDisabledValues)[i] == nValue ) - return sal_False; - } - - return sal_True; -} - -// ----------------------------------------------------------------------- - -void SfxAllEnumItem::RemoveValue( sal_uInt16 nValue ) -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - sal_uInt16 nPos = GetPosByValue(nValue); - DBG_ASSERT( nPos != USHRT_MAX, "removing value not in enum" ); - pValues->Remove( nPos ); -} - -// ----------------------------------------------------------------------- - - -void SfxAllEnumItem::RemoveAllValues() -{ - DBG_CHKTHIS(SfxAllEnumItem, 0); - if ( pValues ) - pValues->DeleteAndDestroy( 0, pValues->Count() ); -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/cenumitm.cxx b/svl/source/items/cenumitm.cxx deleted file mode 100644 index da39ee9e48..0000000000 --- a/svl/source/items/cenumitm.cxx +++ /dev/null @@ -1,294 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <com/sun/star/uno/Any.hxx> -#include <tools/stream.hxx> -#include <svl/cenumitm.hxx> -#include <whassert.hxx> - -#include <comphelper/extract.hxx> - -//============================================================================ -// -// class SfxEnumItemInterface -// -//============================================================================ - -DBG_NAME(SfxEnumItemInterface) - -//============================================================================ -TYPEINIT1(SfxEnumItemInterface, SfxPoolItem) - -//============================================================================ -// virtual -int SfxEnumItemInterface::operator ==(const SfxPoolItem & rItem) const -{ - SFX_ASSERT(SfxPoolItem::operator ==(rItem), Which(), "unequal type"); - return GetEnumValue() - == static_cast< const SfxEnumItemInterface * >(&rItem)-> - GetEnumValue(); -} - -//============================================================================ -// virtual -SfxItemPresentation -SfxEnumItemInterface::GetPresentation(SfxItemPresentation, SfxMapUnit, - SfxMapUnit, XubString & rText, - const IntlWrapper *) const -{ - rText = XubString::CreateFromInt32(GetEnumValue()); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//============================================================================ -// virtual -bool SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) - const -{ - rVal <<= sal_Int32(GetEnumValue()); - return true; -} - -//============================================================================ -// virtual -bool SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any& rVal, - sal_uInt8) -{ - sal_Int32 nTheValue = 0; - - if ( ::cppu::enum2int( nTheValue, rVal ) ) - { - SetEnumValue(sal_uInt16(nTheValue)); - return true; - } - OSL_FAIL("SfxEnumItemInterface::PutValue(): Wrong type"); - return false; -} - -//============================================================================ -XubString SfxEnumItemInterface::GetValueTextByPos(sal_uInt16) const -{ - DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual"); - return XubString(); -} - -//============================================================================ -// virtual -sal_uInt16 SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos) const -{ - return nPos; -} - -//============================================================================ -// virtual -sal_uInt16 SfxEnumItemInterface::GetPosByValue(sal_uInt16 nValue) const -{ - sal_uInt16 nCount = GetValueCount(); - for (sal_uInt16 i = 0; i < nCount; ++i) - if (GetValueByPos(i) == nValue) - return i; - return USHRT_MAX; -} - -sal_Bool SfxEnumItemInterface::IsEnabled(sal_uInt16) const -{ - return sal_True; -} - -//============================================================================ -// virtual -int SfxEnumItemInterface::HasBoolValue() const -{ - return false; -} - -//============================================================================ -// virtual -sal_Bool SfxEnumItemInterface::GetBoolValue() const -{ - return false; -} - -//============================================================================ -// virtual -void SfxEnumItemInterface::SetBoolValue(sal_Bool) -{} - -//============================================================================ -// -// class CntEnumItem -// -//============================================================================ - -DBG_NAME(CntEnumItem) - -//============================================================================ -CntEnumItem::CntEnumItem(sal_uInt16 which, SvStream & rStream): - SfxEnumItemInterface(which) -{ - m_nValue = 0; - rStream >> m_nValue; -} - -//============================================================================ -TYPEINIT1(CntEnumItem, SfxEnumItemInterface) - -//============================================================================ -// virtual -SvStream & CntEnumItem::Store(SvStream & rStream, sal_uInt16) const -{ - rStream << m_nValue; - return rStream; -} - -//============================================================================ -// virtual -sal_uInt16 CntEnumItem::GetEnumValue() const -{ - return GetValue(); -} - -//============================================================================ -// virtual -void CntEnumItem::SetEnumValue(sal_uInt16 nTheValue) -{ - SetValue(nTheValue); -} - -//============================================================================ -// -// class CntBoolItem -// -//============================================================================ - -DBG_NAME(CntBoolItem) - -//============================================================================ -TYPEINIT1_AUTOFACTORY(CntBoolItem, SfxPoolItem) - -//============================================================================ -CntBoolItem::CntBoolItem(sal_uInt16 which, SvStream & rStream): - SfxPoolItem(which) -{ - m_bValue = false; - rStream >> m_bValue; -} - -//============================================================================ -// virtual -int CntBoolItem::operator ==(const SfxPoolItem & rItem) const -{ - DBG_ASSERT(rItem.ISA(CntBoolItem), - "CntBoolItem::operator ==(): Bad type"); - return m_bValue == static_cast< CntBoolItem const * >(&rItem)->m_bValue; -} - -//============================================================================ -// virtual -int CntBoolItem::Compare(const SfxPoolItem & rWith) const -{ - DBG_ASSERT(rWith.ISA(CntBoolItem), "CntBoolItem::Compare(): Bad type"); - return m_bValue == static_cast< CntBoolItem const * >(&rWith)->m_bValue ? - 0 : m_bValue ? -1 : 1; -} - -//============================================================================ -// virtual -SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation, - SfxMapUnit, SfxMapUnit, - UniString & rText, - const IntlWrapper *) const -{ - rText = GetValueTextByVal(m_bValue); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//============================================================================ -// virtual -bool CntBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - rVal <<= sal_Bool(m_bValue); - return true; -} - -//============================================================================ -// virtual -bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) -{ - sal_Bool bTheValue = sal_Bool(); - if (rVal >>= bTheValue) - { - m_bValue = bTheValue; - return true; - } - OSL_FAIL("CntBoolItem::PutValue(): Wrong type"); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * CntBoolItem::Create(SvStream & rStream, sal_uInt16) const -{ - return new CntBoolItem(Which(), rStream); -} - -//============================================================================ -// virtual -SvStream & CntBoolItem::Store(SvStream & rStream, sal_uInt16) const -{ - rStream << m_bValue; - return rStream; -} - -//============================================================================ -// virtual -SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const -{ - return new CntBoolItem(*this); -} - -//============================================================================ -// virtual -sal_uInt16 CntBoolItem::GetValueCount() const -{ - return 2; -} - -//============================================================================ -// virtual -UniString CntBoolItem::GetValueTextByVal(sal_Bool bTheValue) const -{ - return - bTheValue ? - UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("TRUE")) : - UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("FALSE")); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/cintitem.cxx b/svl/source/items/cintitem.cxx deleted file mode 100644 index a9d11a61ec..0000000000 --- a/svl/source/items/cintitem.cxx +++ /dev/null @@ -1,556 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <com/sun/star/uno/Any.hxx> -#include <tools/stream.hxx> -#include <svl/cintitem.hxx> - -//============================================================================ -// -// class CntByteItem -// -//============================================================================ - -DBG_NAME(CntByteItem) - -//============================================================================ -TYPEINIT1_AUTOFACTORY(CntByteItem, SfxPoolItem); - -//============================================================================ -// virtual -int CntByteItem::operator ==(const SfxPoolItem & rItem) const -{ - DBG_CHKTHIS(CntByteItem, 0); - DBG_ASSERT(rItem.ISA(CntByteItem), - "CntByteItem::operator ==(): Bad type"); - return m_nValue == SAL_STATIC_CAST(const CntByteItem *, &rItem)->m_nValue; -} - -//============================================================================ -// virtual -int CntByteItem::Compare(const SfxPoolItem & rWith) const -{ - DBG_CHKTHIS(CntByteItem, 0); - DBG_ASSERT(rWith.ISA(CntByteItem), "CntByteItem::Compare(): Bad type"); - return SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue < m_nValue ? - -1 : - SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue - == m_nValue ? - 0 : 1; -} - -//============================================================================ -// virtual -SfxItemPresentation CntByteItem::GetPresentation(SfxItemPresentation, - SfxMapUnit, SfxMapUnit, - XubString & rText, - const IntlWrapper *) const -{ - DBG_CHKTHIS(CntByteItem, 0); - rText = XubString::CreateFromInt32(m_nValue); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//============================================================================ -// virtual -bool CntByteItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - sal_Int8 nValue = m_nValue; - rVal <<= nValue; - return true; -} - -//============================================================================ -// virtual -bool CntByteItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) -{ - sal_Int8 nValue = sal_Int8(); - if (rVal >>= nValue) - { - m_nValue = nValue; - return true; - } - - OSL_FAIL( "CntByteItem::PutValue - Wrong type!" ); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * CntByteItem::Create(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntByteItem, 0); - short nTheValue = 0; - rStream >> nTheValue; - return new CntByteItem(Which(), sal_uInt8(nTheValue)); -} - -//============================================================================ -// virtual -SvStream & CntByteItem::Store(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntByteItem, 0); - rStream << short(m_nValue); - return rStream; -} - -//============================================================================ -// virtual -SfxPoolItem * CntByteItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(CntByteItem, 0); - return new CntByteItem(*this); -} - -//============================================================================ -// virtual -sal_uInt8 CntByteItem::GetMin() const -{ - DBG_CHKTHIS(CntByteItem, 0); - return 0; -} - -//============================================================================ -// virtual -sal_uInt8 CntByteItem::GetMax() const -{ - DBG_CHKTHIS(CntByteItem, 0); - return 255; -} - -//============================================================================ -// virtual -SfxFieldUnit CntByteItem::GetUnit() const -{ - DBG_CHKTHIS(CntByteItem, 0); - return SFX_FUNIT_NONE; -} - -//============================================================================ -// -// class CntUInt16Item -// -//============================================================================ - -DBG_NAME(CntUInt16Item); - -//============================================================================ -TYPEINIT1_AUTOFACTORY(CntUInt16Item, SfxPoolItem); - -//============================================================================ -CntUInt16Item::CntUInt16Item(sal_uInt16 which, SvStream & rStream) : - SfxPoolItem(which) -{ - DBG_CTOR(CntUInt16Item, 0); - sal_uInt16 nTheValue = 0; - rStream >> nTheValue; - m_nValue = nTheValue; -} - -//============================================================================ -// virtual -int CntUInt16Item::operator ==(const SfxPoolItem & rItem) const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - DBG_ASSERT(rItem.ISA(CntUInt16Item), - "CntUInt16Item::operator ==(): Bad type"); - return m_nValue == SAL_STATIC_CAST(const CntUInt16Item *, &rItem)-> - m_nValue; -} - -//============================================================================ -// virtual -int CntUInt16Item::Compare(const SfxPoolItem & rWith) const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - DBG_ASSERT(rWith.ISA(CntUInt16Item), - "CntUInt16Item::Compare(): Bad type"); - return SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue - < m_nValue ? - -1 : - SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue - == m_nValue ? - 0 : 1; -} - -//============================================================================ -// virtual -SfxItemPresentation CntUInt16Item::GetPresentation(SfxItemPresentation, - SfxMapUnit, SfxMapUnit, - XubString & rText, - const IntlWrapper *) - const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - rText = XubString::CreateFromInt32(m_nValue); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//============================================================================ -// virtual -bool CntUInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - sal_Int32 nValue = m_nValue; - rVal <<= nValue; - return true; -} - -//============================================================================ -// virtual -bool CntUInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) -{ - sal_Int32 nValue = 0; - if (rVal >>= nValue) - { - DBG_ASSERT( nValue <= USHRT_MAX, "Overflow in UInt16 value!"); - m_nValue = (sal_uInt16)nValue; - return true; - } - - OSL_FAIL( "CntUInt16Item::PutValue - Wrong type!" ); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * CntUInt16Item::Create(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - return new CntUInt16Item(Which(), rStream); -} - -//============================================================================ -// virtual -SvStream & CntUInt16Item::Store(SvStream &rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - rStream << sal_uInt16(m_nValue); - return rStream; -} - -//============================================================================ -// virtual -SfxPoolItem * CntUInt16Item::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - return new CntUInt16Item(*this); -} - -//============================================================================ -// virtual -sal_uInt16 CntUInt16Item::GetMin() const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - return 0; -} - -//============================================================================ -// virtual -sal_uInt16 CntUInt16Item::GetMax() const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - return 65535; -} - -//============================================================================ -// virtual -SfxFieldUnit CntUInt16Item::GetUnit() const -{ - DBG_CHKTHIS(CntUInt16Item, 0); - return SFX_FUNIT_NONE; -} - -//============================================================================ -// -// class CntInt32Item -// -//============================================================================ - -DBG_NAME(CntInt32Item); - -//============================================================================ -TYPEINIT1_AUTOFACTORY(CntInt32Item, SfxPoolItem); - -//============================================================================ -CntInt32Item::CntInt32Item(sal_uInt16 which, SvStream & rStream) : - SfxPoolItem(which) -{ - DBG_CTOR(CntInt32Item, 0); - long nTheValue = 0; - rStream >> nTheValue; - m_nValue = nTheValue; -} - -//============================================================================ -// virtual -int CntInt32Item::operator ==(const SfxPoolItem & rItem) const -{ - DBG_CHKTHIS(CntInt32Item, 0); - DBG_ASSERT(rItem.ISA(CntInt32Item), - "CntInt32Item::operator ==(): Bad type"); - return m_nValue == SAL_STATIC_CAST(const CntInt32Item *, &rItem)-> - m_nValue; -} - -//============================================================================ -// virtual -int CntInt32Item::Compare(const SfxPoolItem & rWith) const -{ - DBG_CHKTHIS(CntInt32Item, 0); - DBG_ASSERT(rWith.ISA(CntInt32Item), "CntInt32Item::Compare(): Bad type"); - return SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue - < m_nValue ? - -1 : - SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue - == m_nValue ? - 0 : 1; -} - -//============================================================================ -// virtual -SfxItemPresentation CntInt32Item::GetPresentation(SfxItemPresentation, - SfxMapUnit, SfxMapUnit, - XubString & rText, - const IntlWrapper *) const -{ - DBG_CHKTHIS(CntInt32Item, 0); - rText = XubString::CreateFromInt32(m_nValue); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//============================================================================ -// virtual -bool CntInt32Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - sal_Int32 nValue = m_nValue; - rVal <<= nValue; - return true; -} - -//============================================================================ -// virtual -bool CntInt32Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) -{ - sal_Int32 nValue = 0; - if (rVal >>= nValue) - { - m_nValue = nValue; - return true; - } - - OSL_FAIL( "CntInt32Item::PutValue - Wrong type!" ); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * CntInt32Item::Create(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntInt32Item, 0); - return new CntInt32Item(Which(), rStream); -} - -//============================================================================ -// virtual -SvStream & CntInt32Item::Store(SvStream &rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntInt32Item, 0); - rStream << long(m_nValue); - return rStream; -} - -//============================================================================ -// virtual -SfxPoolItem * CntInt32Item::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(CntInt32Item, 0); - return new CntInt32Item(*this); -} - -//============================================================================ -// virtual -sal_Int32 CntInt32Item::GetMin() const -{ - DBG_CHKTHIS(CntInt32Item, 0); - return sal_Int32(0x80000000); -} - -//============================================================================ -// virtual -sal_Int32 CntInt32Item::GetMax() const -{ - DBG_CHKTHIS(CntInt32Item, 0); - return 0x7FFFFFFF; -} - -//============================================================================ -// virtual -SfxFieldUnit CntInt32Item::GetUnit() const -{ - DBG_CHKTHIS(CntInt32Item, 0); - return SFX_FUNIT_NONE; -} - -//============================================================================ -// -// class CntUInt32Item -// -//============================================================================ - -DBG_NAME(CntUInt32Item); - -//============================================================================ -TYPEINIT1_AUTOFACTORY(CntUInt32Item, SfxPoolItem); - -//============================================================================ -CntUInt32Item::CntUInt32Item(sal_uInt16 which, SvStream & rStream) : - SfxPoolItem(which) -{ - DBG_CTOR(CntUInt32Item, 0); - sal_uInt32 nTheValue = 0; - rStream >> nTheValue; - m_nValue = nTheValue; -} - -//============================================================================ -// virtual -int CntUInt32Item::operator ==(const SfxPoolItem & rItem) const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - DBG_ASSERT(rItem.ISA(CntUInt32Item), - "CntUInt32Item::operator ==(): Bad type"); - return m_nValue == SAL_STATIC_CAST(const CntUInt32Item *, &rItem)-> - m_nValue; -} - -//============================================================================ -// virtual -int CntUInt32Item::Compare(const SfxPoolItem & rWith) const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - DBG_ASSERT(rWith.ISA(CntUInt32Item), - "CntUInt32Item::operator ==(): Bad type"); - return SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue - < m_nValue ? - -1 : - SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue - == m_nValue ? - 0 : 1; -} - -//============================================================================ -// virtual -SfxItemPresentation CntUInt32Item::GetPresentation(SfxItemPresentation, - SfxMapUnit, SfxMapUnit, - XubString & rText, - const IntlWrapper *) - const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - rText = XubString::CreateFromInt64(m_nValue); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//============================================================================ -// virtual -bool CntUInt32Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - sal_Int32 nValue = m_nValue; - DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!"); - rVal <<= nValue; - return true; -} - -//============================================================================ -// virtual -bool CntUInt32Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) -{ - sal_Int32 nValue = 0; - if (rVal >>= nValue) - { - DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!"); - m_nValue = nValue; - return true; - } - - OSL_FAIL( "CntUInt32Item::PutValue - Wrong type!" ); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * CntUInt32Item::Create(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - return new CntUInt32Item(Which(), rStream); -} - -//============================================================================ -// virtual -SvStream & CntUInt32Item::Store(SvStream &rStream, sal_uInt16) const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - rStream << static_cast<sal_uInt32>(m_nValue); - return rStream; -} - -//============================================================================ -// virtual -SfxPoolItem * CntUInt32Item::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - return new CntUInt32Item(*this); -} - -//============================================================================ -// virtual -sal_uInt32 CntUInt32Item::GetMin() const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - return 0; -} - -//============================================================================ -// virtual -sal_uInt32 CntUInt32Item::GetMax() const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - return 0xFFFFFFFF; -} - -//============================================================================ -// virtual -SfxFieldUnit CntUInt32Item::GetUnit() const -{ - DBG_CHKTHIS(CntUInt32Item, 0); - return SFX_FUNIT_NONE; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/cntwall.cxx b/svl/source/items/cntwall.cxx deleted file mode 100644 index 77261f97da..0000000000 --- a/svl/source/items/cntwall.cxx +++ /dev/null @@ -1,169 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/debug.hxx> -#include <tools/string.hxx> -#include <tools/stream.hxx> -#include <tools/vcompat.hxx> - -#include <svl/cntwall.hxx> - -#define CNTWALLPAPERITEM_STREAM_MAGIC ( (sal_uInt32)0xfefefefe ) -#define CNTWALLPAPERITEM_STREAM_SEEKREL (-( (long)( sizeof( sal_uInt32 ) ) ) ) - -TYPEINIT1( CntWallpaperItem, SfxPoolItem ); - -// ----------------------------------------------------------------------- -CntWallpaperItem::CntWallpaperItem( sal_uInt16 which ) - : SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 ) -{ -} - -// ----------------------------------------------------------------------- -CntWallpaperItem::CntWallpaperItem( sal_uInt16 which, SvStream& rStream, sal_uInt16 nVersion ) - : SfxPoolItem( which ), _nColor( COL_TRANSPARENT ), _nStyle( 0 ) -{ - sal_uInt32 nMagic = 0; - rStream >> nMagic; - if ( nMagic == CNTWALLPAPERITEM_STREAM_MAGIC ) - { - // Okay, data were stored by CntWallpaperItem. - - readUnicodeString(rStream, _aURL, nVersion >= 1); - // !!! Color stream operators do not work - they discard any - // transparency info !!! - _nColor.Read( rStream, sal_True ); - rStream >> _nStyle; - } - else - { - rStream.SeekRel( CNTWALLPAPERITEM_STREAM_SEEKREL ); - - // Data were stored by SfxWallpaperItem ( SO < 6.0 ). The only - // thing we can do here is to get the URL and to position the stream. - - { - // "Read" Wallpaper member - The version compat object positions - // the stream after the wallpaper data in its dtor. We must use - // this trick here as no VCL must be used here ( No Wallpaper - // object allowed ). - VersionCompat aCompat( rStream, STREAM_READ ); - } - - // Read SfxWallpaperItem's string member _aURL. - readUnicodeString(rStream, _aURL, false); - - // "Read" SfxWallpaperItem's string member _aFilter. - ByteString aDummy; - rStream.ReadByteString(aDummy); - } -} - -// ----------------------------------------------------------------------- -CntWallpaperItem::CntWallpaperItem( const CntWallpaperItem& rItem ) : - SfxPoolItem( rItem ), - _aURL( rItem._aURL ), - _nColor( rItem._nColor ), - _nStyle( rItem._nStyle ) -{ -} - -// ----------------------------------------------------------------------- -CntWallpaperItem::~CntWallpaperItem() -{ -} - -// ----------------------------------------------------------------------- -int CntWallpaperItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - - const CntWallpaperItem& rWallItem = (const CntWallpaperItem&)rItem; - - if( ( rWallItem._nStyle == _nStyle ) && - ( rWallItem._nColor == _nColor ) && - ( rWallItem._aURL == _aURL ) ) - return sal_True; - else - return sal_False; -} - -//============================================================================ -// virtual -sal_uInt16 CntWallpaperItem::GetVersion(sal_uInt16) const -{ - return 1; // because it uses SfxPoolItem::read/writeUnicodeString() -} - -// ----------------------------------------------------------------------- -SfxPoolItem* CntWallpaperItem::Create( SvStream& rStream, sal_uInt16 nVersion) const -{ - return new CntWallpaperItem( Which(), rStream, nVersion ); -} - -// ----------------------------------------------------------------------- -SvStream& CntWallpaperItem::Store( SvStream& rStream, sal_uInt16 ) const -{ - rStream << CNTWALLPAPERITEM_STREAM_MAGIC; - writeUnicodeString(rStream, _aURL); - // !!! Color stream operators do not work - they discard any - // transparency info !!! - // ??? Why the hell Color::Write(...) isn't const ??? - SAL_CONST_CAST( CntWallpaperItem*, this )->_nColor.Write( rStream, sal_True ); - rStream << _nStyle; - - return rStream; -} - -// ----------------------------------------------------------------------- -SfxPoolItem* CntWallpaperItem::Clone( SfxItemPool* ) const -{ - return new CntWallpaperItem( *this ); -} - -//---------------------------------------------------------------------------- -// virtual -bool CntWallpaperItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8) const -{ - OSL_FAIL("Not implemented!"); - return false; -} - -//---------------------------------------------------------------------------- -// virtual -bool CntWallpaperItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8) -{ - OSL_FAIL("Not implemented!"); - return false; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/cstitem.src b/svl/source/items/cstitem.src deleted file mode 100644 index 206fe1a188..0000000000 --- a/svl/source/items/cstitem.src +++ /dev/null @@ -1,32 +0,0 @@ -/************************************************************************* - * - * 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 <svl/svl.hrc> -String STR_COLUM_DT_AUTO -{ - Text [ en-US ] = "automatic" ; -}; diff --git a/svl/source/items/ctypeitm.cxx b/svl/source/items/ctypeitm.cxx deleted file mode 100644 index 3eeb39c005..0000000000 --- a/svl/source/items/ctypeitm.cxx +++ /dev/null @@ -1,254 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <com/sun/star/uno/Any.hxx> - -#include <unotools/intlwrapper.hxx> -#include <tools/stream.hxx> -#include <svl/ctypeitm.hxx> - -//============================================================================ -// The following defines are copied from chaos/source/items/cstritem.cxx: -#define CNTSTRINGITEM_STREAM_MAGIC ( (sal_uInt32)0xfefefefe ) -#define CNTSTRINGITEM_STREAM_SEEKREL (-( (long)( sizeof( sal_uInt32 ) ) ) ) - -//============================================================================ -// -// class CntContentTypeItem Implementation. -// -//============================================================================ - -TYPEINIT1_AUTOFACTORY( CntContentTypeItem, CntUnencodedStringItem ); - -#define CONTENT_TYPE_NOT_INIT ( (INetContentType)-1 ) - -//---------------------------------------------------------------------------- -CntContentTypeItem::CntContentTypeItem() -: CntUnencodedStringItem(), - _eType( CONTENT_TYPE_NOT_INIT ) -{ -} - -//---------------------------------------------------------------------------- -CntContentTypeItem::CntContentTypeItem( sal_uInt16 which, const XubString& rType ) -: CntUnencodedStringItem( which, rType ), - _eType( CONTENT_TYPE_NOT_INIT ) -{ -} - -//---------------------------------------------------------------------------- -CntContentTypeItem::CntContentTypeItem( sal_uInt16 which, - const INetContentType eType ) -: CntUnencodedStringItem( which, INetContentTypes::GetContentType( eType ) ), - _eType( eType ) -{ -} - -//---------------------------------------------------------------------------- -CntContentTypeItem::CntContentTypeItem( const CntContentTypeItem& rOrig ) -: CntUnencodedStringItem( rOrig ), - _eType( rOrig._eType ), - _aPresentation( rOrig._aPresentation ) -{ -} - -//============================================================================ -// virtual -sal_uInt16 CntContentTypeItem::GetVersion(sal_uInt16) const -{ - return 1; // because it uses SfxPoolItem::read/writeUnicodeString() -} - -//---------------------------------------------------------------------------- -// virtual -SfxPoolItem* CntContentTypeItem::Create( SvStream& rStream, - sal_uInt16 nItemVersion ) const -{ - // CntContentTypeItem used to be derived from CntStringItem, so take that - // into account: - UniString aValue; - readUnicodeString(rStream, aValue, nItemVersion >= 1); - sal_uInt32 nMagic = 0; - rStream >> nMagic; - if (nMagic == CNTSTRINGITEM_STREAM_MAGIC) - { - sal_Bool bEncrypted = sal_False; - rStream >> bEncrypted; - DBG_ASSERT(!bEncrypted, - "CntContentTypeItem::Create() reads encrypted data"); - } - else - rStream.SeekRel(CNTSTRINGITEM_STREAM_SEEKREL); - - return new CntContentTypeItem(Which(), aValue); -} - -//---------------------------------------------------------------------------- -// virtual -SvStream & CntContentTypeItem::Store(SvStream & rStream, sal_uInt16) const -{ - // CntContentTypeItem used to be derived from CntStringItem, so take that - // into account: - writeUnicodeString(rStream, GetValue()); - rStream << CNTSTRINGITEM_STREAM_MAGIC << sal_Bool(sal_False); - return rStream; -} - -//---------------------------------------------------------------------------- -// virtual -int CntContentTypeItem::operator==( const SfxPoolItem& rOrig ) const -{ - const CntContentTypeItem& rOther = (const CntContentTypeItem&)rOrig; - - if ( ( _eType != CONTENT_TYPE_NOT_INIT ) && - ( rOther._eType != CONTENT_TYPE_NOT_INIT ) ) - return _eType == rOther._eType; - else - return CntUnencodedStringItem::operator==( rOther ); -} - -//---------------------------------------------------------------------------- -// virtual -SfxPoolItem* CntContentTypeItem::Clone( SfxItemPool* /* pPool */ ) const -{ - return new CntContentTypeItem( *this ); -} - -//---------------------------------------------------------------------------- -void CntContentTypeItem::SetValue( const XubString& rNewVal ) -{ - // De-initialize enum type and presentation. - _eType = CONTENT_TYPE_NOT_INIT; - _aPresentation.Erase(); - - CntUnencodedStringItem::SetValue( rNewVal ); -} - -//---------------------------------------------------------------------------- -void CntContentTypeItem::SetPresentation( const XubString& rNewVal ) -{ - _aPresentation = rNewVal; -} - -//---------------------------------------------------------------------------- -int CntContentTypeItem::Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const -{ - String aOwnText, aWithText; - GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS, - SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aOwnText, &rIntlWrapper ); - rWith.GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS, - SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aWithText, &rIntlWrapper ); - return rIntlWrapper.getCollator()->compareString( aOwnText, aWithText ); -} - -//---------------------------------------------------------------------------- -SfxItemPresentation CntContentTypeItem::GetPresentation( - SfxItemPresentation ePres, - SfxMapUnit eCoreMetric, - SfxMapUnit ePresMetric, - XubString & rText, - const IntlWrapper * pIntlWrapper) const -{ - if (_aPresentation.Len() == 0) - { - DBG_ASSERT(pIntlWrapper, - "CntContentTypeItem::GetPresentation(): No IntlWrapper"); - if (pIntlWrapper) - SAL_CONST_CAST(CntContentTypeItem *, this)->_aPresentation - = INetContentTypes::GetPresentation(GetEnumValue(), - pIntlWrapper-> - getLocale()); - } - if (_aPresentation.Len() > 0) - { - rText = _aPresentation; - return SFX_ITEM_PRESENTATION_COMPLETE; - } - else - return CntUnencodedStringItem::GetPresentation(ePres, eCoreMetric, - ePresMetric, rText, - pIntlWrapper); -} - -//---------------------------------------------------------------------------- -INetContentType CntContentTypeItem::GetEnumValue() const -{ - if ( _eType == CONTENT_TYPE_NOT_INIT ) - { - // Not yet initialized... Get enum value for string content type. - - CntContentTypeItem* pVarThis = SAL_CONST_CAST( CntContentTypeItem*, this ); - - pVarThis->_eType = INetContentTypes::GetContentType( GetValue() ); - } - - return _eType; -} - -//---------------------------------------------------------------------------- -void CntContentTypeItem::SetValue( const INetContentType eType ) -{ - SetValue( INetContentTypes::GetContentType( eType ) ); - - // Note: SetValue( const String& ....) resets _eType. Set new enum value - // after(!) calling it. - _eType = eType; -} - -//---------------------------------------------------------------------------- -// virtual -bool CntContentTypeItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - rVal <<= rtl::OUString(GetValue()); - return true; -} - -//---------------------------------------------------------------------------- -// virtual -bool CntContentTypeItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8) -{ - rtl::OUString aValue; - if ( rVal >>= aValue ) - { - // SetValue with an empty string resets the item; so call that - // function when PutValue is called with an empty string - if (aValue.getLength() == 0) - SetValue(aValue); - else - SetValue( - INetContentTypes::RegisterContentType(aValue, UniString())); - return true; - } - - OSL_FAIL( "CntContentTypeItem::PutValue - Wrong type!" ); - return false; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/custritm.cxx b/svl/source/items/custritm.cxx deleted file mode 100644 index b6fed31978..0000000000 --- a/svl/source/items/custritm.cxx +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <com/sun/star/uno/Any.hxx> - -#include <unotools/intlwrapper.hxx> -#include <tools/stream.hxx> -#include <svl/custritm.hxx> - -//============================================================================ -// -// class CntUnencodedStringItem -// -//============================================================================ - -DBG_NAME(CntUnencodedStringItem) - -//============================================================================ -TYPEINIT1_AUTOFACTORY(CntUnencodedStringItem, SfxPoolItem) - -//============================================================================ -// virtual -int CntUnencodedStringItem::operator ==(const SfxPoolItem & rItem) const -{ - DBG_CHKTHIS(CntUnencodedStringItem, 0); - DBG_ASSERT(rItem.ISA(CntUnencodedStringItem), - "CntUnencodedStringItem::operator ==(): Bad type"); - return m_aValue - == SAL_STATIC_CAST(const CntUnencodedStringItem *, &rItem)-> - m_aValue; -} - -//============================================================================ -// virtual -int CntUnencodedStringItem::Compare(SfxPoolItem const & rWith) const -{ - OSL_FAIL("CntUnencodedStringItem::Compare(): No international"); - DBG_CHKTHIS(CntUnencodedStringItem, 0); - DBG_ASSERT(rWith.ISA(CntUnencodedStringItem), - "CntUnencodedStringItem::Compare(): Bad type"); - switch (m_aValue.CompareTo(static_cast< CntUnencodedStringItem const * >( - &rWith)-> - m_aValue)) - { - case COMPARE_LESS: - return -1; - - case COMPARE_EQUAL: - return 0; - - default: // COMPARE_GREATER - return 1; - } -} - -//============================================================================ -// virtual -int CntUnencodedStringItem::Compare(SfxPoolItem const & rWith, - IntlWrapper const & rIntlWrapper) - const -{ - DBG_CHKTHIS(CntUnencodedStringItem, 0); - DBG_ASSERT(rWith.ISA(CntUnencodedStringItem), - "CntUnencodedStringItem::Compare(): Bad type"); - return rIntlWrapper.getCollator()->compareString( m_aValue, - static_cast< CntUnencodedStringItem const * >(&rWith)->m_aValue ); -} - -//============================================================================ -// virtual -SfxItemPresentation -CntUnencodedStringItem::GetPresentation(SfxItemPresentation, SfxMapUnit, - SfxMapUnit, XubString & rText, - const IntlWrapper *) const -{ - DBG_CHKTHIS(CntUnencodedStringItem, 0); - rText = m_aValue; - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//============================================================================ -// virtual -bool CntUnencodedStringItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) - const -{ - rVal <<= rtl::OUString(m_aValue); - return true; -} - -//============================================================================ -// virtual -bool CntUnencodedStringItem::PutValue(const com::sun::star::uno::Any& rVal, - sal_uInt8) -{ - rtl::OUString aTheValue; - if (rVal >>= aTheValue) - { - m_aValue = UniString(aTheValue); - return true; - } - OSL_FAIL("CntUnencodedStringItem::PutValue(): Wrong type"); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * CntUnencodedStringItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(CntUnencodedStringItem, 0); - return new CntUnencodedStringItem(*this); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/dateitem.cxx b/svl/source/items/dateitem.cxx deleted file mode 100644 index bb392a1b97..0000000000 --- a/svl/source/items/dateitem.cxx +++ /dev/null @@ -1,280 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -// include --------------------------------------------------------------- - -#define _DATETIMEITEM_CXX -#include <svl/dateitem.hxx> -#include <svl/svldata.hxx> -#include <svl/svl.hrc> - -#include <unotools/intlwrapper.hxx> -#include <comphelper/processfactory.hxx> - -#include <tools/stream.hxx> -#include <tools/debug.hxx> -#include <tools/datetime.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/util/DateTime.hpp> -#include <com/sun/star/lang/Locale.hpp> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxDateTimeItem) - - -// ----------------------------------------------------------------------- - -TYPEINIT1(SfxDateTimeItem, SfxPoolItem); - -// ----------------------------------------------------------------------- - -SfxDateTimeItem::SfxDateTimeItem( sal_uInt16 which ) : - SfxPoolItem( which ) -{ - DBG_CTOR(SfxDateTimeItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxDateTimeItem::SfxDateTimeItem( sal_uInt16 which, const DateTime& rDT ) : - SfxPoolItem( which ), - aDateTime( rDT ) - -{ - DBG_CTOR(SfxDateTimeItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxDateTimeItem::SfxDateTimeItem( const SfxDateTimeItem& rItem ) : - SfxPoolItem( rItem ), - aDateTime( rItem.aDateTime ) -{ - DBG_CTOR(SfxDateTimeItem, 0); -} - -// ----------------------------------------------------------------------- - -int SfxDateTimeItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_CHKTHIS(SfxDateTimeItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - return ( ( (SfxDateTimeItem&)rItem ).aDateTime == aDateTime ); -} - -// ----------------------------------------------------------------------- - -int SfxDateTimeItem::Compare( const SfxPoolItem& rItem ) const -{ - DBG_CHKTHIS(SfxDateTimeItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - - // da X.Compare( Y ) am String einem Compare( Y, X ) entspricht, - // vergleichen wir hier Y mit X - if ( ( (const SfxDateTimeItem&)rItem ).aDateTime < aDateTime ) - return -1; - else if ( ( (const SfxDateTimeItem&)rItem ).aDateTime == aDateTime ) - return 0; - else - return 1; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxDateTimeItem::Create( SvStream& rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxDateTimeItem, 0); - sal_uInt32 nDate = 0; - sal_Int32 nTime = 0; - rStream >> nDate; - rStream >> nTime; - DateTime aDT(nDate, nTime); - return new SfxDateTimeItem( Which(), aDT ); -} - -// ----------------------------------------------------------------------- - -SvStream& SfxDateTimeItem::Store( SvStream& rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxDateTimeItem, 0); - rStream << aDateTime.GetDate(); - rStream << aDateTime.GetTime(); - return rStream; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxDateTimeItem::Clone( SfxItemPool* ) const -{ - DBG_CHKTHIS(SfxDateTimeItem, 0); - return new SfxDateTimeItem( *this ); -} - -// ----------------------------------------------------------------------- - -SfxItemPresentation SfxDateTimeItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * pIntlWrapper -) const -{ - DBG_CHKTHIS(SfxDateTimeItem, 0); - if (aDateTime.IsValid()) - if (pIntlWrapper) - { - rText = pIntlWrapper->getLocaleData()->getDate(aDateTime); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += pIntlWrapper->getLocaleData()->getTime(aDateTime); - } - else - { - DBG_WARNING("SfxDateTimeItem::GetPresentation():" - " Using default en_US IntlWrapper"); - const IntlWrapper aIntlWrapper( - ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US ); - rText = aIntlWrapper.getLocaleData()->getDate(aDateTime); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += aIntlWrapper.getLocaleData()->getTime(aDateTime); - } - else - rText.Erase(); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxDateTimeItem::PutValue( const com::sun::star::uno::Any& rVal, - sal_uInt8 nMemberId ) -{ - nMemberId &= ~CONVERT_TWIPS; - com::sun::star::util::DateTime aValue; - if ( rVal >>= aValue ) - { - aDateTime = DateTime( Date( aValue.Day, - aValue.Month, - aValue.Year ), - Time( aValue.Hours, - aValue.Minutes, - aValue.Seconds, - aValue.HundredthSeconds ) ); - return true; - } - - OSL_FAIL( "SfxDateTimeItem::PutValue - Wrong type!" ); - return false; -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxDateTimeItem::QueryValue( com::sun::star::uno::Any& rVal, - sal_uInt8 nMemberId ) const -{ - nMemberId &= ~CONVERT_TWIPS; - com::sun::star::util::DateTime aValue( aDateTime.Get100Sec(), - aDateTime.GetSec(), - aDateTime.GetMin(), - aDateTime.GetHour(), - aDateTime.GetDay(), - aDateTime.GetMonth(), - aDateTime.GetYear() ); - rVal <<= aValue; - return true; -} - -// ----------------------------------------------------------------------- -// ----------------------------------------------------------------------- -// ----------------------------------------------------------------------- - -TYPEINIT1(SfxColumnDateTimeItem, SfxDateTimeItem); - - -SfxColumnDateTimeItem::SfxColumnDateTimeItem( sal_uInt16 which ) : - SfxDateTimeItem( which ) -{} - -SfxColumnDateTimeItem::SfxColumnDateTimeItem( sal_uInt16 which, const DateTime& rDT ) : - SfxDateTimeItem( which, rDT ) -{} - -SfxColumnDateTimeItem::SfxColumnDateTimeItem( const SfxDateTimeItem& rCpy ) : - SfxDateTimeItem( rCpy ) -{} - -SfxPoolItem* SfxColumnDateTimeItem::Clone( SfxItemPool* ) const -{ - return new SfxColumnDateTimeItem( *this ); -} - -SfxItemPresentation SfxColumnDateTimeItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * pIntlWrapper -) const -{ - DBG_ASSERT(pIntlWrapper, - "SfxColumnDateTimeItem::GetPresentation():" - " Using default en_US IntlWrapper"); - - ::com::sun::star::lang::Locale aLocale; - if (GetDateTime() == DateTime(Date(1, 2, 3), Time(3, 2, 1))) - { - rText = String(SvtSimpleResId(STR_COLUM_DT_AUTO, - pIntlWrapper ? - pIntlWrapper->getLocale() : - aLocale)); - } - else if (pIntlWrapper) - { - rText = pIntlWrapper->getLocaleData()->getDate(GetDateTime()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += pIntlWrapper->getLocaleData()->getTime(GetDateTime()); - } - else - { - const IntlWrapper aIntlWrapper( - ::comphelper::getProcessServiceFactory(), LANGUAGE_ENGLISH_US ); - rText = aIntlWrapper.getLocaleData()->getDate(GetDateTime()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += aIntlWrapper.getLocaleData()->getTime(GetDateTime()); - } - return SFX_ITEM_PRESENTATION_NAMELESS; -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/eitem.cxx b/svl/source/items/eitem.cxx deleted file mode 100644 index 19d4040c19..0000000000 --- a/svl/source/items/eitem.cxx +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/eitem.hxx> -//============================================================================ -// -// class SfxEnumItem -// -//============================================================================ - -TYPEINIT1(SfxEnumItem, CntEnumItem); - -//============================================================================ -// -// class SfxBoolItem -// -//============================================================================ - -TYPEINIT1_AUTOFACTORY(SfxBoolItem, CntBoolItem); - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/flagitem.cxx b/svl/source/items/flagitem.cxx deleted file mode 100644 index 218dab3716..0000000000 --- a/svl/source/items/flagitem.cxx +++ /dev/null @@ -1,156 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/flagitem.hxx> -#include <svl/poolitem.hxx> -#include <tools/stream.hxx> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxFlagItem) - -sal_uInt16 nSfxFlagVal[16] = -{ - 0x0001, 0x0002, 0x0004, 0x0008, - 0x0010, 0x0020, 0x0040, 0x0080, - 0x0100, 0x0200, 0x0400, 0x0800, - 0x1000, 0x2000, 0x4000, 0x8000 -}; - - -// ----------------------------------------------------------------------- - -TYPEINIT1(SfxFlagItem, SfxPoolItem); - -// ----------------------------------------------------------------------- - -SfxFlagItem::SfxFlagItem( sal_uInt16 nW, sal_uInt16 nV ) : - SfxPoolItem( nW ), - nVal(nV) -{ - DBG_CTOR(SfxFlagItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxFlagItem::SfxFlagItem( const SfxFlagItem& rItem ) : - SfxPoolItem( rItem ), - nVal( rItem.nVal ) -{ - DBG_CTOR(SfxFlagItem, 0); -} - -// ----------------------------------------------------------------------- - -SvStream& SfxFlagItem::Store(SvStream &rStream, sal_uInt16) const -{ - DBG_CHKTHIS(SfxFlagItem, 0); - rStream << nVal; - return rStream; -} - -// ----------------------------------------------------------------------- - -SfxItemPresentation SfxFlagItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * -) const -{ - DBG_CHKTHIS(SfxFlagItem, 0); - rText.Erase(); - for ( sal_uInt8 nFlag = 0; nFlag < GetFlagCount(); ++nFlag ) - rText += XubString::CreateFromInt32( GetFlag(nFlag) ); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -// ----------------------------------------------------------------------- - -XubString SfxFlagItem::GetFlagText( sal_uInt8 ) const -{ - DBG_CHKTHIS(SfxFlagItem, 0); - DBG_WARNING( "calling GetValueText(sal_uInt16) on SfxFlagItem -- overload!" ); - return XubString(); -} - -// ----------------------------------------------------------------------- - -sal_uInt8 SfxFlagItem::GetFlagCount() const -{ - DBG_CHKTHIS(SfxFlagItem, 0); - DBG_WARNING( "calling GetValueText(sal_uInt16) on SfxFlagItem -- overload!" ); - return 0; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxFlagItem::Create(SvStream &, sal_uInt16) const -{ - DBG_CHKTHIS(SfxFlagItem, 0); - DBG_WARNING( "calling Create() on SfxFlagItem -- overload!" ); - return 0; -} - -// ----------------------------------------------------------------------- - -int SfxFlagItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_CHKTHIS(SfxFlagItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - return (((SfxFlagItem&)rItem).nVal == nVal); -} - -// ----------------------------------------------------------------------- - -void SfxFlagItem::SetFlag( sal_uInt8 nFlag, int bVal ) -{ - if ( bVal ) - nVal |= nSfxFlagVal[nFlag]; - else - nVal &= ~nSfxFlagVal[nFlag]; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxFlagItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(SfxFlagItem, 0); - return new SfxFlagItem( *this ); -} - - - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/globalnameitem.cxx b/svl/source/items/globalnameitem.cxx deleted file mode 100644 index 40b9aba36e..0000000000 --- a/svl/source/items/globalnameitem.cxx +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/uno/Sequence.hxx> -#include <com/sun/star/script/XTypeConverter.hpp> - -#include <com/sun/star/lang/XMultiServiceFactory.hpp> - -#include <comphelper/processfactory.hxx> - -#include <svl/globalnameitem.hxx> - -// STATIC DATA ----------------------------------------------------------- - - -// ----------------------------------------------------------------------- - -TYPEINIT1_AUTOFACTORY(SfxGlobalNameItem, SfxPoolItem); - -// ----------------------------------------------------------------------- - -SfxGlobalNameItem::SfxGlobalNameItem() -{ -} - -// ----------------------------------------------------------------------- - -SfxGlobalNameItem::SfxGlobalNameItem( sal_uInt16 nW, const SvGlobalName& rName ) -: SfxPoolItem( nW ), - m_aName( rName ) -{ -} - -// ----------------------------------------------------------------------- - -SfxGlobalNameItem::~SfxGlobalNameItem() -{ -} - -// ----------------------------------------------------------------------- - -int SfxGlobalNameItem::operator==( const SfxPoolItem& rItem ) const -{ - return ((SfxGlobalNameItem&)rItem).m_aName == m_aName; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxGlobalNameItem::Clone(SfxItemPool *) const -{ - return new SfxGlobalNameItem( *this ); -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxGlobalNameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) -{ - com::sun::star::uno::Reference < com::sun::star::script::XTypeConverter > xConverter - ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter"))), - com::sun::star::uno::UNO_QUERY ); - com::sun::star::uno::Sequence< sal_Int8 > aSeq; - com::sun::star::uno::Any aNew; - - try { aNew = xConverter->convertTo( rVal, ::getCppuType((const com::sun::star::uno::Sequence < sal_Int8 >*)0) ); } - catch (com::sun::star::uno::Exception&) {} - aNew >>= aSeq; - if ( aSeq.getLength() == 16 ) - { - m_aName.MakeFromMemory( (void*) aSeq.getConstArray() ); - return true; - } - - OSL_FAIL( "SfxGlobalNameItem::PutValue - Wrong type!" ); - return true; -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxGlobalNameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const -{ - com::sun::star::uno::Sequence< sal_Int8 > aSeq( 16 ); - void* pData = ( void* ) &m_aName.GetCLSID(); - memcpy( aSeq.getArray(), pData, 16 ); - rVal <<= aSeq; - return true; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/ilstitem.cxx b/svl/source/items/ilstitem.cxx deleted file mode 100644 index a699f6c3ad..0000000000 --- a/svl/source/items/ilstitem.cxx +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <com/sun/star/script/XTypeConverter.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> - -#include <comphelper/processfactory.hxx> - -#include <svl/ilstitem.hxx> - -TYPEINIT1_AUTOFACTORY(SfxIntegerListItem, SfxPoolItem); - -SfxIntegerListItem::SfxIntegerListItem() -{ -} - -SfxIntegerListItem::SfxIntegerListItem( sal_uInt16 which, const ::std::vector < sal_Int32 >& rList ) - : SfxPoolItem( which ) -{ - m_aList.realloc( rList.size() ); - for ( sal_uInt16 n=0; n<rList.size(); ++n ) - m_aList[n] = rList[n]; -} - -SfxIntegerListItem::SfxIntegerListItem( sal_uInt16 which, const ::com::sun::star::uno::Sequence < sal_Int32 >& rList ) - : SfxPoolItem( which ) -{ - m_aList.realloc( rList.getLength() ); - for ( sal_Int32 n=0; n<rList.getLength(); ++n ) - m_aList[n] = rList[n]; -} - -SfxIntegerListItem::SfxIntegerListItem( const SfxIntegerListItem& rItem ) - : SfxPoolItem( rItem ) -{ - m_aList = rItem.m_aList; -} - -SfxIntegerListItem::~SfxIntegerListItem() -{ -} - -int SfxIntegerListItem::operator==( const SfxPoolItem& rPoolItem ) const -{ - if ( !rPoolItem.ISA( SfxIntegerListItem ) ) - return sal_False; - - const SfxIntegerListItem rItem = (const SfxIntegerListItem&) rPoolItem; - return rItem.m_aList == m_aList; -} - -SfxPoolItem* SfxIntegerListItem::Clone( SfxItemPool * ) const -{ - return new SfxIntegerListItem( *this ); -} - -bool SfxIntegerListItem::PutValue ( const com::sun::star::uno::Any& rVal, sal_uInt8 ) -{ - ::com::sun::star::uno::Reference < ::com::sun::star::script::XTypeConverter > xConverter - ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter"))), - ::com::sun::star::uno::UNO_QUERY ); - ::com::sun::star::uno::Any aNew; - try { aNew = xConverter->convertTo( rVal, ::getCppuType((const ::com::sun::star::uno::Sequence < sal_Int32 >*)0) ); } - catch (::com::sun::star::uno::Exception&) - { - return true; - } - - return ( aNew >>= m_aList ); -} - -bool SfxIntegerListItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const -{ - rVal <<= m_aList; - return true; -} - -void SfxIntegerListItem::GetList( ::std::vector< sal_Int32 >& rList ) const -{ - rList.reserve( m_aList.getLength() ); - for ( sal_Int32 n=0; n<m_aList.getLength(); ++n ) - rList.push_back( m_aList[n] ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/imageitm.cxx b/svl/source/items/imageitm.cxx deleted file mode 100644 index 45eda4163d..0000000000 --- a/svl/source/items/imageitm.cxx +++ /dev/null @@ -1,147 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/imageitm.hxx> -#include <com/sun/star/uno/Sequence.hxx> - -TYPEINIT1( SfxImageItem, SfxInt16Item ); - -struct SfxImageItem_Impl -{ - String aURL; - long nAngle; - sal_Bool bMirrored; - int operator == ( const SfxImageItem_Impl& rOther ) const - { return nAngle == rOther.nAngle && bMirrored == rOther.bMirrored; } -}; - -//--------------------------------------------------------- - -SfxImageItem::SfxImageItem( sal_uInt16 which, sal_uInt16 nImage ) - : SfxInt16Item( which, nImage ) -{ - pImp = new SfxImageItem_Impl; - pImp->nAngle = 0; - pImp->bMirrored = sal_False; -} - -SfxImageItem::SfxImageItem( sal_uInt16 which, const String& rURL ) - : SfxInt16Item( which, 0 ) -{ - pImp = new SfxImageItem_Impl; - pImp->nAngle = 0; - pImp->bMirrored = sal_False; - pImp->aURL = rURL; -} - -SfxImageItem::SfxImageItem( const SfxImageItem& rItem ) - : SfxInt16Item( rItem ) -{ - pImp = new SfxImageItem_Impl( *(rItem.pImp) ); -} - -//--------------------------------------------------------- -SfxImageItem::~SfxImageItem() -{ - delete pImp; -} - -//--------------------------------------------------------- - -SfxPoolItem* SfxImageItem::Clone( SfxItemPool* ) const -{ - return new SfxImageItem( *this ); -} - -//--------------------------------------------------------- - -int SfxImageItem::operator==( const SfxPoolItem& rItem ) const -{ - return( ((SfxImageItem&) rItem).GetValue() == GetValue() && (*pImp == *(((SfxImageItem&)rItem).pImp) ) ); -} - -bool SfxImageItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const -{ - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq( 4 ); - aSeq[0] = ::com::sun::star::uno::makeAny( GetValue() ); - aSeq[1] = ::com::sun::star::uno::makeAny( pImp->nAngle ); - aSeq[2] = ::com::sun::star::uno::makeAny( pImp->bMirrored ); - aSeq[3] = ::com::sun::star::uno::makeAny( rtl::OUString( pImp->aURL )); - - rVal = ::com::sun::star::uno::makeAny( aSeq ); - return true; -} - -bool SfxImageItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) -{ - ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq; - if (( rVal >>= aSeq ) && ( aSeq.getLength() == 4 )) - { - sal_Int16 nVal = sal_Int16(); - rtl::OUString aURL; - if ( aSeq[0] >>= nVal ) - SetValue( nVal ); - aSeq[1] >>= pImp->nAngle; - aSeq[2] >>= pImp->bMirrored; - if ( aSeq[3] >>= aURL ) - pImp->aURL = aURL; - return true; - } - - return false; -} - -void SfxImageItem::SetRotation( long nValue ) -{ - pImp->nAngle = nValue; -} - -long SfxImageItem::GetRotation() const -{ - return pImp->nAngle; -} - -void SfxImageItem::SetMirrored( sal_Bool bSet ) -{ - pImp->bMirrored = bSet; -} - -sal_Bool SfxImageItem::IsMirrored() const -{ - return pImp->bMirrored; -} - -String SfxImageItem::GetURL() const -{ - return pImp->aURL; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/intitem.cxx b/svl/source/items/intitem.cxx deleted file mode 100644 index 2ac1956bbb..0000000000 --- a/svl/source/items/intitem.cxx +++ /dev/null @@ -1,260 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/intitem.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <tools/bigint.hxx> -#include <tools/stream.hxx> -#include <svl/metitem.hxx> - -//============================================================================ -// -// class SfxByteItem -// -//============================================================================ - -TYPEINIT1_AUTOFACTORY(SfxByteItem, CntByteItem); - -//============================================================================ -// virtual -SfxPoolItem * SfxByteItem::Create(SvStream & rStream, sal_uInt16) const -{ - short nValue = 0; - rStream >> nValue; - return new SfxByteItem(Which(), sal_uInt8(nValue)); -} - -//============================================================================ -// -// class SfxInt16Item -// -//============================================================================ - -DBG_NAME(SfxInt16Item); - -//============================================================================ -TYPEINIT1_AUTOFACTORY(SfxInt16Item, SfxPoolItem); - -//============================================================================ -SfxInt16Item::SfxInt16Item(sal_uInt16 which, SvStream & rStream): - SfxPoolItem(which) -{ - DBG_CTOR(SfxInt16Item, 0); - short nTheValue = 0; - rStream >> nTheValue; - m_nValue = nTheValue; -} - -//============================================================================ -// virtual -int SfxInt16Item::operator ==(const SfxPoolItem & rItem) const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type"); - return m_nValue == SAL_STATIC_CAST(const SfxInt16Item *, &rItem)-> - m_nValue; -} - -//============================================================================ -// virtual -int SfxInt16Item::Compare(const SfxPoolItem & rWith) const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - DBG_ASSERT(SfxPoolItem::operator ==(rWith), "unequal type"); - return SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue - < m_nValue ? - -1 : - SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue - == m_nValue ? - 0 : 1; -} - -//============================================================================ -// virtual -SfxItemPresentation SfxInt16Item::GetPresentation(SfxItemPresentation, - SfxMapUnit, SfxMapUnit, - XubString & rText, - const IntlWrapper *) const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - rText = UniString::CreateFromInt32(m_nValue); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - - -//============================================================================ -// virtual -bool SfxInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - sal_Int16 nValue = m_nValue; - rVal <<= nValue; - return true; -} - -//============================================================================ -// virtual -bool SfxInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 ) -{ - sal_Int16 nValue = sal_Int16(); - if (rVal >>= nValue) - { - m_nValue = nValue; - return true; - } - - OSL_FAIL( "SfxInt16Item::PutValue - Wrong type!" ); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - return new SfxInt16Item(Which(), rStream); -} - -//============================================================================ -// virtual -SvStream & SfxInt16Item::Store(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - rStream << short(m_nValue); - return rStream; -} - -//============================================================================ -SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - return new SfxInt16Item(*this); -} - -//============================================================================ -sal_Int16 SfxInt16Item::GetMin() const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - return -32768; -} - -//============================================================================ -sal_Int16 SfxInt16Item::GetMax() const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - return 32767; -} - -//============================================================================ -SfxFieldUnit SfxInt16Item::GetUnit() const -{ - DBG_CHKTHIS(SfxInt16Item, 0); - return SFX_FUNIT_NONE; -} - -//============================================================================ -// -// class SfxUInt16Item -// -//============================================================================ - -TYPEINIT1_AUTOFACTORY(SfxUInt16Item, CntUInt16Item); - - -//============================================================================ -// -// class SfxInt32Item -// -//============================================================================ - -TYPEINIT1_AUTOFACTORY(SfxInt32Item, CntInt32Item); - - -//============================================================================ -// -// class SfxUInt32Item -// -//============================================================================ - -TYPEINIT1_AUTOFACTORY(SfxUInt32Item, CntUInt32Item); - - -//============================================================================ -// -// class SfxMetricItem -// -//============================================================================ - -DBG_NAME(SfxMetricItem); - -//============================================================================ -TYPEINIT1_AUTOFACTORY(SfxMetricItem, SfxInt32Item); - -//============================================================================ -SfxMetricItem::SfxMetricItem(sal_uInt16 which, sal_uInt32 nValue): - SfxInt32Item(which, nValue) -{ - DBG_CTOR(SfxMetricItem, 0); -} - -//============================================================================ -SfxMetricItem::SfxMetricItem(sal_uInt16 which, SvStream & rStream): - SfxInt32Item(which, rStream) -{ - DBG_CTOR(SfxMetricItem, 0); -} - -//============================================================================ -SfxMetricItem::SfxMetricItem(const SfxMetricItem & rItem): - SfxInt32Item(rItem) -{ - DBG_CTOR(SfxMetricItem, 0); -} - -//============================================================================ -// virtual -bool SfxMetricItem::ScaleMetrics(long nMult, long nDiv) -{ - BigInt aTheValue(GetValue()); - aTheValue *= nMult; - aTheValue += nDiv / 2; - aTheValue /= nDiv; - SetValue(aTheValue); - return true; -} - -//============================================================================ -// virtual -bool SfxMetricItem::HasMetrics() const -{ - return true; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/itemiter.cxx b/svl/source/items/itemiter.cxx deleted file mode 100644 index ea102b418f..0000000000 --- a/svl/source/items/itemiter.cxx +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/itemiter.hxx> -#include <svl/itempool.hxx> -#include <svl/itemset.hxx> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxItemIter); - - -// -------------------------------------------------------------------------- - - -SfxItemIter::SfxItemIter( const SfxItemSet& rItemSet ) - : _rSet( rItemSet ) -{ - DBG_CTOR(SfxItemIter, 0); - DBG_ASSERTWARNING( _rSet.Count(), "es gibt gar keine Attribute" ); - - if ( !_rSet._nCount ) - { - _nStt = 1; - _nEnd = 0; - } - else - { - SfxItemArray ppFnd = _rSet._aItems; - - // suche das 1. gesetzte Item - for ( _nStt = 0; !*(ppFnd + _nStt ); ++_nStt ) - ; // empty loop - if ( 1 < _rSet.Count() ) - for( _nEnd = _rSet.TotalCount(); !*( ppFnd + --_nEnd); ) - ; // empty loop - else - _nEnd = _nStt; - } - - _nAkt = _nStt; -} - -// -------------------------------------------------------------------------- - - -SfxItemIter::~SfxItemIter() -{ - DBG_DTOR(SfxItemIter, 0); -} - -// -------------------------------------------------------------------------- - - -const SfxPoolItem* SfxItemIter::NextItem() -{ - DBG_CHKTHIS(SfxItemIter, 0); - SfxItemArray ppFnd = _rSet._aItems; - - if( _nAkt < _nEnd ) - { - do { - _nAkt++; - } while( _nAkt < _nEnd && !*(ppFnd + _nAkt ) ); - return *(ppFnd+_nAkt); - } - return 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/itempool.cxx b/svl/source/items/itempool.cxx deleted file mode 100644 index ec94d5ef22..0000000000 --- a/svl/source/items/itempool.cxx +++ /dev/null @@ -1,1117 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <string.h> -#include <stdio.h> - -#include <svl/itempool.hxx> -#include "whassert.hxx" -#include <svl/brdcst.hxx> -#include <svl/smplhint.hxx> -#include "poolio.hxx" - -//======================================================================== - - -void SfxItemPool::AddSfxItemPoolUser(SfxItemPoolUser& rNewUser) -{ - maSfxItemPoolUsers.push_back(&rNewUser); -} - -void SfxItemPool::RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser) -{ - const SfxItemPoolUserVector::iterator aFindResult = ::std::find(maSfxItemPoolUsers.begin(), maSfxItemPoolUsers.end(), &rOldUser); - if(aFindResult != maSfxItemPoolUsers.end()) - { - maSfxItemPoolUsers.erase(aFindResult); - } -} - -const SfxPoolItem* SfxItemPool::GetPoolDefaultItem( sal_uInt16 nWhich ) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - const SfxPoolItem* pRet; - if( IsInRange( nWhich ) ) - pRet = *(ppPoolDefaults + GetIndex_Impl( nWhich )); - else if( pSecondary ) - pRet = pSecondary->GetPoolDefaultItem( nWhich ); - else - { - SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get pool default" ); - pRet = 0; - } - return pRet; -} - -// ----------------------------------------------------------------------- - -inline bool SfxItemPool::IsItemFlag_Impl( sal_uInt16 nPos, sal_uInt16 nFlag ) const -{ - sal_uInt16 nItemFlag = pItemInfos[nPos]._nFlags; - return nFlag == (nItemFlag & nFlag); -} - -// ----------------------------------------------------------------------- - -bool SfxItemPool::IsItemFlag( sal_uInt16 nWhich, sal_uInt16 nFlag ) const -{ - for ( const SfxItemPool *pPool = this; pPool; pPool = pPool->pSecondary ) - { - if ( pPool->IsInRange(nWhich) ) - return pPool->IsItemFlag_Impl( pPool->GetIndex_Impl(nWhich), nFlag); - } - DBG_ASSERT( !IsWhich(nWhich), "unknown which-id" ); - return sal_False; -} - -// ----------------------------------------------------------------------- - -SfxBroadcaster& SfxItemPool::BC() -{ - return pImp->aBC; -} - -// ----------------------------------------------------------------------- - - -SfxItemPool::SfxItemPool -( - UniString const & rName, /* Name des Pools zur Idetifikation - im File-Format */ - sal_uInt16 nStartWhich, /* erste Which-Id des Pools */ - sal_uInt16 nEndWhich, /* letzte Which-Id des Pools */ -#ifdef TF_POOLABLE - const SfxItemInfo* pInfos, /* SID-Map und Item-Flags */ -#endif - SfxPoolItem** pDefaults, /* Pointer auf statische Defaults, - wird direkt vom Pool referenziert, - jedoch kein Eigent"umer"ubergang */ -#ifndef TF_POOLABLE - sal_uInt16* pSlotIdArray, /* Zuordnung von Slot-Ids zu Which-Ids */ -#endif - bool bLoadRefCounts /* Ref-Counts mitladen oder auf 1 setzen */ -) - -/* [Beschreibung] - - Der im Normalfall verwendete Konstruktor der Klasse SfxItemPool. Es - wird eine SfxItemPool-Instanz initialisiert, die Items im b"undigen - Which-Bereich von 'nStartWhich' bis 'nEndWhich' verwalten kann. - - F"ur jede dieser Which-Ids mu\s ein statischer Default im Array 'pDefaults' - vorhanden sein, die dort beginnend mit einem <SfxPoolItem> mit der - Which-Id 'nStartWhich' nach Which-Ids sortiert aufeinanderfolgend - eingetragen sein m"ussen. - - 'pItemInfos' ist ein identisch angeordnetes Array von USHORTs, die - Slot-Ids darstellen und Flags. Die Slot-Ids k"onnen 0 sein, wenn die - betreffenden Items ausschlie\slich in der Core verwendet werden. - "Uber die Flags kann z.B. bestimmt werden, ob Value-Sharing - (SFX_ITEM_POOLABLE) stattfinden soll. - - [Anmerkung] - - Wenn der Pool <SfxSetItem>s enthalten soll, k"onnen im Konstruktor noch - keine static-Defaults angegeben werden. Dies mu\s dann nachtr"aglich - mit <SfxItemPool::SetDefaults(SfxItemPool**)> geschehen. - - - [Querverweise] - - <SfxItemPool::SetDefaults(SfxItemPool**)> - <SfxItemPool::ReleaseDefaults(SfxPoolItem**,sal_uInt16,sal_Bool)> - <SfxItemPool::ReldaseDefaults(sal_Bool)> -*/ - -: aName(rName), - nStart(nStartWhich), - nEnd(nEndWhich), -#ifdef TF_POOLABLE - pItemInfos(pInfos), -#else - pSlotIds(pSlotIdArray), -#endif - pImp( new SfxItemPool_Impl( nStart, nEnd ) ), - ppStaticDefaults(0), - ppPoolDefaults(new SfxPoolItem* [ nEndWhich - nStartWhich + 1]), - pSecondary(0), - pMaster(this), - _pPoolRanges( 0 ), - bPersistentRefCounts(bLoadRefCounts), - maSfxItemPoolUsers() -{ - DBG_CTOR(SfxItemPool, 0); - DBG_ASSERT(nStart, "Start-Which-Id must be greater 0" ); - - pImp->eDefMetric = SFX_MAPUNIT_TWIP; - pImp->nVersion = 0; - pImp->bStreaming = sal_False; - pImp->nLoadingVersion = 0; - pImp->nInitRefCount = 1; - pImp->nVerStart = nStart; - pImp->nVerEnd = nEnd; - pImp->bInSetItem = false; - pImp->nStoringStart = nStartWhich; - pImp->nStoringEnd = nEndWhich; - - memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1)); - - if ( pDefaults ) - SetDefaults(pDefaults); -} - -// ----------------------------------------------------------------------- - - -SfxItemPool::SfxItemPool -( - const SfxItemPool& rPool, // von dieser Instanz kopieren - sal_Bool bCloneStaticDefaults /* sal_True - statische Defaults kopieren - - sal_False - statische Defaults - "ubernehehmen */ -) - -/* [Beschreibung] - - Copy-Konstruktor der Klasse SfxItemPool. - - - [Querverweise] - - <SfxItemPool::Clone()const> -*/ - -: aName(rPool.aName), - nStart(rPool.nStart), - nEnd(rPool.nEnd), -#ifdef TF_POOLABLE - pItemInfos(rPool.pItemInfos), -#else - pSlotIds(rPool.pSlotIds), -#endif - pImp( new SfxItemPool_Impl( nStart, nEnd ) ), - ppStaticDefaults(0), - ppPoolDefaults(new SfxPoolItem* [ nEnd - nStart + 1]), - pSecondary(0), - pMaster(this), - _pPoolRanges( 0 ), - bPersistentRefCounts(rPool.bPersistentRefCounts ), - maSfxItemPoolUsers() -{ - DBG_CTOR(SfxItemPool, 0); - pImp->eDefMetric = rPool.pImp->eDefMetric; - pImp->nVersion = rPool.pImp->nVersion; - pImp->bStreaming = sal_False; - pImp->nLoadingVersion = 0; - pImp->nInitRefCount = 1; - pImp->nVerStart = rPool.pImp->nVerStart; - pImp->nVerEnd = rPool.pImp->nVerEnd; - pImp->bInSetItem = false; - pImp->nStoringStart = nStart; - pImp->nStoringEnd = nEnd; - - memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1)); - - // Static Defaults "ubernehmen - if ( bCloneStaticDefaults ) - { - SfxPoolItem **ppDefaults = new SfxPoolItem*[nEnd-nStart+1]; - for ( sal_uInt16 n = 0; n <= nEnd - nStart; ++n ) - { - (*( ppDefaults + n )) = (*( rPool.ppStaticDefaults + n ))->Clone(this); - (*( ppDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); - } - - SetDefaults( ppDefaults ); - } - else - SetDefaults( rPool.ppStaticDefaults ); - - // Pool Defaults kopieren - for ( sal_uInt16 n = 0; n <= nEnd - nStart; ++n ) - if ( (*( rPool.ppPoolDefaults + n )) ) - { - (*( ppPoolDefaults + n )) = (*( rPool.ppPoolDefaults + n ))->Clone(this); - (*( ppPoolDefaults + n ))->SetKind( SFX_ITEMS_POOLDEFAULT ); - } - - // Copy Version-Map - for ( size_t nVer = 0; nVer < rPool.pImp->aVersions.size(); ++nVer ) - { - const SfxPoolVersion_ImplPtr pOld = rPool.pImp->aVersions[nVer]; - SfxPoolVersion_ImplPtr pNew = SfxPoolVersion_ImplPtr( new SfxPoolVersion_Impl( *pOld ) ); - pImp->aVersions.push_back( pNew ); - } - - // Verkettung wiederherstellen - if ( rPool.pSecondary ) - SetSecondaryPool( rPool.pSecondary->Clone() ); -} - -// ----------------------------------------------------------------------- - -void SfxItemPool::SetDefaults( SfxPoolItem **pDefaults ) -{ - DBG_CHKTHIS(SfxItemPool, 0); - DBG_ASSERT( pDefaults, "erst wollen, dann nichts geben..." ); - DBG_ASSERT( !ppStaticDefaults, "habe schon defaults" ); - - ppStaticDefaults = pDefaults; - //! if ( (*ppStaticDefaults)->GetKind() != SFX_ITEMS_STATICDEFAULT ) - //! geht wohl nicht im Zshg mit SetItems, die hinten stehen - { - DBG_ASSERT( (*ppStaticDefaults)->GetRefCount() == 0 || - IsDefaultItem( (*ppStaticDefaults) ), - "das sind keine statics" ); - for ( sal_uInt16 n = 0; n <= nEnd - nStart; ++n ) - { - SFX_ASSERT( (*( ppStaticDefaults + n ))->Which() == n + nStart, - n + nStart, "static defaults not sorted" ); - (*( ppStaticDefaults + n ))->SetKind( SFX_ITEMS_STATICDEFAULT ); - DBG_ASSERT( !(pImp->ppPoolItems[n]), "defaults with setitems with items?!" ); - } - } -} - -// ----------------------------------------------------------------------- - -void SfxItemPool::ReleaseDefaults -( - sal_Bool bDelete /* sal_True - l"oscht sowohl das Array als auch die einzelnen - statischen Defaults - - sal_False - l"oscht weder das Array noch die einzelnen - statischen Defaults */ -) - -/* [Beschreibung] - - Gibt die statischen Defaults der betreffenden SfxItemPool-Instanz frei - und l"oscht ggf. die statischen Defaults. - - Nach Aufruf dieser Methode darf die SfxItemPool-Instanz nicht mehr - verwendet werden, einzig ist der Aufruf des Destruktors zu"lassig. -*/ - -{ - DBG_ASSERT( ppStaticDefaults, "keine Arme keine Kekse" ); - ReleaseDefaults( ppStaticDefaults, nEnd - nStart + 1, bDelete ); - - // KSO (22.10.98): ppStaticDefaults zeigt auf geloeschten Speicher, - // wenn bDelete == sal_True. - if ( bDelete ) - ppStaticDefaults = 0; -} - -// ----------------------------------------------------------------------- - -void SfxItemPool::ReleaseDefaults -( - SfxPoolItem** pDefaults, /* freizugebende statische Defaults */ - - sal_uInt16 nCount, /* Anzahl der statischen Defaults */ - - sal_Bool bDelete /* sal_True - l"oscht sowohl das Array als auch die - einzelnen statischen Defaults - - sal_False - l"oscht weder das Array noch die - einzelnen statischen Defaults */ -) - -/* [Beschreibung] - - Gibt die angegebenen statischen Defaults frei und l"oscht ggf. - die statischen Defaults. - - Diese Methode darf erst nach Zerst"orung aller SfxItemPool-Instanzen, - welche die angegebenen statischen Defaults 'pDefault' verwenden, - aufgerufen werden. -*/ - -{ - DBG_ASSERT( pDefaults, "erst wollen, dann nichts geben..." ); - - for ( sal_uInt16 n = 0; n < nCount; ++n ) - { - SFX_ASSERT( IsStaticDefaultItem( *(pDefaults+n) ), - n, "das ist kein static-default" ); - (*( pDefaults + n ))->SetRefCount( 0 ); - if ( bDelete ) - { delete *( pDefaults + n ); *(pDefaults + n) = 0; } - } - - if ( bDelete ) - { delete[] pDefaults; pDefaults = 0; } -} - -// ----------------------------------------------------------------------- - -SfxItemPool::~SfxItemPool() -{ - DBG_DTOR(SfxItemPool, 0); - DBG_ASSERT( pMaster == this, "destroying active Secondary-Pool" ); - - if ( pImp->ppPoolItems && ppPoolDefaults ) - Delete(); - delete[] _pPoolRanges; - delete pImp; -} - -void SfxItemPool::Free(SfxItemPool* pPool) -{ - if(pPool) - { - // tell all the registered SfxItemPoolUsers that the pool is in destruction - SfxItemPoolUserVector aListCopy(pPool->maSfxItemPoolUsers.begin(), pPool->maSfxItemPoolUsers.end()); - for(SfxItemPoolUserVector::iterator aIterator = aListCopy.begin(); aIterator != aListCopy.end(); ++aIterator) - { - SfxItemPoolUser* pSfxItemPoolUser = *aIterator; - DBG_ASSERT(pSfxItemPoolUser, "corrupt SfxItemPoolUser list (!)"); - pSfxItemPoolUser->ObjectInDestruction(*pPool); - } - - // Clear the vector. This means that user do not need to call RemoveSfxItemPoolUser() - // when they get called from ObjectInDestruction(). - pPool->maSfxItemPoolUsers.clear(); - - // delete pool - delete pPool; - } -} - -// ----------------------------------------------------------------------- - - -void SfxItemPool::SetSecondaryPool( SfxItemPool *pPool ) -{ - // ggf. an abgeh"angten Pools den Master zur"ucksetzen - if ( pSecondary ) - { -#ifdef DBG_UTIL - HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) - if ( ppStaticDefaults ) - { - // Delete() ist noch nicht gelaufen? - if ( pImp->ppPoolItems && pSecondary->pImp->ppPoolItems ) - { - // hat der master SetItems? - sal_Bool bHasSetItems = sal_False; - for ( sal_uInt16 i = 0; !bHasSetItems && i < nEnd-nStart; ++i ) - bHasSetItems = ppStaticDefaults[i]->ISA(SfxSetItem); - - // abgehaengte Pools muessen leer sein - sal_Bool bOK = bHasSetItems; - for ( sal_uInt16 n = 0; - bOK && n <= pSecondary->nEnd - pSecondary->nStart; - ++n ) - { - SfxPoolItemArray_Impl** ppItemArr = - pSecondary->pImp->ppPoolItems + n; - if ( *ppItemArr ) - { - SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); - for( size_t i = (*ppItemArr)->size(); i; ++ppHtArr, --i ) - if ( !(*ppHtArr) ) - { - OSL_FAIL( "old secondary pool must be empty" ); - bOK = sal_False; - break; - } - } - } - } - } -#endif - - pSecondary->pMaster = pSecondary; - for ( SfxItemPool *p = pSecondary->pSecondary; p; p = p->pSecondary ) - p->pMaster = pSecondary; - } - - // ggf. den Master der neuen Secondary-Pools setzen - DBG_ASSERT( !pPool || pPool->pMaster == pPool, "Secondary tanzt auf zwei Hochzeiten " ); - SfxItemPool *pNewMaster = pMaster ? pMaster : this; - for ( SfxItemPool *p = pPool; p; p = p->pSecondary ) - p->pMaster = pNewMaster; - - // neuen Secondary-Pool merken - pSecondary = pPool; -} - -// ----------------------------------------------------------------------- - -SfxMapUnit SfxItemPool::GetMetric( sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - - return pImp->eDefMetric; -} - -// ----------------------------------------------------------------------- - -void SfxItemPool::SetDefaultMetric( SfxMapUnit eNewMetric ) -{ - DBG_CHKTHIS(SfxItemPool, 0); - - pImp->eDefMetric = eNewMetric; -} - -// ----------------------------------------------------------------------- - -SfxItemPresentation SfxItemPool::GetPresentation -( - const SfxPoolItem& rItem, /* IN: <SfxPoolItem>, dessen textuelle - Wert-Darstellung geliefert werden - soll */ - SfxItemPresentation ePresent, /* IN: gew"unschte Art der Darstellung; - siehe <SfxItemPresentation> */ - SfxMapUnit eMetric, /* IN: gew"unschte Ma\seinheit der Darstellung */ - XubString& rText, /* OUT: textuelle Darstellung von 'rItem' */ - const IntlWrapper * pIntlWrapper -) const - -/* [Beschreibung] - - "Uber diese virtuelle Methode k"onnen textuelle Darstellungen der - von der jeweilige SfxItemPool-Subklasse verwalteten SfxPoolItems - angefordert werden. - - In Ableitungen sollte diese Methode "uberladen werden und auf - SfxPoolItems reagiert werden, die bei <SfxPoolItem::GetPresentation()const> - keine vollst"andige Information liefern k"onnen. - - Die Basisklasse liefert die unver"anderte Presentation von 'rItem'. -*/ - -{ - DBG_CHKTHIS(SfxItemPool, 0); - return rItem.GetPresentation( - ePresent, GetMetric(rItem.Which()), eMetric, rText, pIntlWrapper ); -} - - -// ----------------------------------------------------------------------- - -SfxItemPool* SfxItemPool::Clone() const -{ - DBG_CHKTHIS(SfxItemPool, 0); - - SfxItemPool *pPool = new SfxItemPool( *this ); - return pPool; -} - -// ---------------------------------------------------------------------- - -void SfxItemPool::Delete() -{ - DBG_CHKTHIS(SfxItemPool, 0); - - // schon deleted? - if ( !pImp->ppPoolItems || !ppPoolDefaults ) - return; - - // z.B. laufenden Requests bescheidsagen - pImp->aBC.Broadcast( SfxSimpleHint( SFX_HINT_DYING ) ); - - //MA 16. Apr. 97: Zweimal durchlaufen, in der ersten Runde fuer die SetItems. - //Der Klarheit halber wird das jetzt in zwei besser lesbare Schleifen aufgeteilt. - - SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; - SfxPoolItem** ppDefaultItem = ppPoolDefaults; - SfxPoolItem** ppStaticDefaultItem = ppStaticDefaults; - sal_uInt16 nArrCnt; - - //Erst die SetItems abraeumen - HACK( "fuer Image, dort gibt es derzeit keine Statics - Bug" ) - if ( ppStaticDefaults ) - { - for ( nArrCnt = GetSize_Impl(); - nArrCnt; - --nArrCnt, ++ppItemArr, ++ppDefaultItem, ++ppStaticDefaultItem ) - { - // KSO (22.10.98): *ppStaticDefaultItem kann im dtor einer - // von SfxItemPool abgeleiteten Klasse bereits geloescht worden - // sein! -> CHAOS Itempool - if ( *ppStaticDefaultItem && (*ppStaticDefaultItem)->ISA(SfxSetItem) ) - { - if ( *ppItemArr ) - { - SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); - for ( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) - if (*ppHtArr) - { -#ifdef DBG_UTIL - ReleaseRef( **ppHtArr, (*ppHtArr)->GetRefCount() ); -#endif - delete *ppHtArr; - } - DELETEZ( *ppItemArr ); - } - if ( *ppDefaultItem ) - { -#ifdef DBG_UTIL - SetRefCount( **ppDefaultItem, 0 ); -#endif - DELETEZ( *ppDefaultItem ); - } - } - } - } - - ppItemArr = pImp->ppPoolItems; - ppDefaultItem = ppPoolDefaults; - - //Jetzt die 'einfachen' Items - for ( nArrCnt = GetSize_Impl(); - nArrCnt; - --nArrCnt, ++ppItemArr, ++ppDefaultItem ) - { - if ( *ppItemArr ) - { - SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); - for ( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) - if (*ppHtArr) - { -#ifdef DBG_UTIL - ReleaseRef( **ppHtArr, (*ppHtArr)->GetRefCount() ); -#endif - delete *ppHtArr; - } - delete *ppItemArr; - } - if ( *ppDefaultItem ) - { -#ifdef DBG_UTIL - SetRefCount( **ppDefaultItem, 0 ); -#endif - delete *ppDefaultItem; - } - } - - pImp->DeleteItems(); - delete[] ppPoolDefaults; ppPoolDefaults = 0; -} - -// ---------------------------------------------------------------------- - -void SfxItemPool::SetPoolDefaultItem(const SfxPoolItem &rItem) -{ - DBG_CHKTHIS(SfxItemPool, 0); - if ( IsInRange(rItem.Which()) ) - { - SfxPoolItem **ppOldDefault = - ppPoolDefaults + GetIndex_Impl(rItem.Which()); - SfxPoolItem *pNewDefault = rItem.Clone(this); - pNewDefault->SetKind(SFX_ITEMS_POOLDEFAULT); - if ( *ppOldDefault ) - { - (*ppOldDefault)->SetRefCount(0); - DELETEZ( *ppOldDefault ); - } - *ppOldDefault = pNewDefault; - } - else if ( pSecondary ) - pSecondary->SetPoolDefaultItem(rItem); - else - { - SFX_ASSERT( 0, rItem.Which(), "unknown Which-Id - cannot set pool default" ); - } -} - -/* - * Resets the default of the given <Which-Id> back to the static default. - * If a pool default exists it is removed. - */ -void SfxItemPool::ResetPoolDefaultItem( sal_uInt16 nWhichId ) -{ - DBG_CHKTHIS(SfxItemPool, 0); - if ( IsInRange(nWhichId) ) - { - SfxPoolItem **ppOldDefault = - ppPoolDefaults + GetIndex_Impl( nWhichId ); - if ( *ppOldDefault ) - { - (*ppOldDefault)->SetRefCount(0); - DELETEZ( *ppOldDefault ); - } - } - else if ( pSecondary ) - pSecondary->ResetPoolDefaultItem(nWhichId); - else - { - SFX_ASSERT( 0, nWhichId, "unknown Which-Id - cannot set pool default" ); - } -} - -// ----------------------------------------------------------------------- - -const SfxPoolItem& SfxItemPool::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich ) -{ - DBG_ASSERT( !rItem.ISA(SfxSetItem) || - 0 != &((const SfxSetItem&)rItem).GetItemSet(), - "SetItem without ItemSet" ); - - DBG_CHKTHIS(SfxItemPool, 0); - if ( 0 == nWhich ) - nWhich = rItem.Which(); - - // richtigen Secondary-Pool finden - sal_Bool bSID = nWhich > SFX_WHICH_MAX; - if ( !bSID && !IsInRange(nWhich) ) - { - if ( pSecondary ) - return pSecondary->Put( rItem, nWhich ); - OSL_FAIL( "unknown Which-Id - cannot put item" ); - } - - // SID oder nicht poolable (neue Definition)? - sal_uInt16 nIndex = bSID ? USHRT_MAX : GetIndex_Impl(nWhich); - if ( USHRT_MAX == nIndex || - IsItemFlag_Impl( nIndex, SFX_ITEM_NOT_POOLABLE ) ) - { - SFX_ASSERT( USHRT_MAX != nIndex || rItem.Which() != nWhich || - !IsDefaultItem(&rItem) || rItem.GetKind() == SFX_ITEMS_DELETEONIDLE, - nWhich, "ein nicht Pool-Item ist Default?!" ); - SfxPoolItem *pPoolItem = rItem.Clone(pMaster); - pPoolItem->SetWhich(nWhich); - AddRef( *pPoolItem ); - return *pPoolItem; - } - - SFX_ASSERT( rItem.IsA(GetDefaultItem(nWhich).Type()), nWhich, - "SFxItemPool: wrong item type in Put" ); - - SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems + nIndex; - if( !*ppItemArr ) - *ppItemArr = new SfxPoolItemArray_Impl; - - SfxPoolItemArrayBase_Impl::iterator ppFree; - sal_Bool ppFreeIsSet = sal_False; - SfxPoolItemArrayBase_Impl::iterator ppHtArray = (*ppItemArr)->begin(); - if ( IsItemFlag_Impl( nIndex, SFX_ITEM_POOLABLE ) ) - { - // wenn es ueberhaupt gepoolt ist, koennte es schon drin sein - if ( IsPooledItem(&rItem) ) - { - // 1. Schleife: teste ob der Pointer vorhanden ist. - for( size_t n = (*ppItemArr)->size(); n; ++ppHtArray, --n ) - if( &rItem == (*ppHtArray) ) - { - AddRef( **ppHtArray ); - return **ppHtArray; - } - } - - // 2. Schleife: dann muessen eben die Attribute verglichen werden - size_t n; - for ( n = (*ppItemArr)->size(), ppHtArray = (*ppItemArr)->begin(); - n; ++ppHtArray, --n ) - { - if ( *ppHtArray ) - { - if( **ppHtArray == rItem ) - { - AddRef( **ppHtArray ); - return **ppHtArray; - } - } - else - if ( ppFreeIsSet == sal_False ) - { - ppFree = ppHtArray; - ppFreeIsSet = sal_True; - } - } - } - else - { - // freien Platz suchen - SfxPoolItemArrayBase_Impl::iterator ppHtArr; - size_t n, nCount = (*ppItemArr)->size(); - for ( n = (*ppItemArr)->nFirstFree, - ppHtArr = (*ppItemArr)->begin() + n; - n < nCount; - ++ppHtArr, ++n ) - if ( !*ppHtArr ) - { - ppFree = ppHtArr; - ppFreeIsSet = sal_True; - break; - } - - // naechstmoeglichen freien Platz merken - (*ppItemArr)->nFirstFree = n; - } - - // nicht vorhanden, also im PtrArray eintragen - SfxPoolItem* pNewItem = rItem.Clone(pMaster); - pNewItem->SetWhich(nWhich); -#ifdef DBG_UTIL - SFX_ASSERT( rItem.Type() == pNewItem->Type(), nWhich, "unequal types in Put(): no Clone()?" ) -#ifdef TF_POOLABLE - if ( !rItem.ISA(SfxSetItem) ) - { - SFX_ASSERT( !IsItemFlag(nWhich, SFX_ITEM_POOLABLE) || - rItem == *pNewItem, - nWhich, "unequal items in Put(): no operator==?" ); - SFX_ASSERT( !IsItemFlag(*pNewItem, SFX_ITEM_POOLABLE) || - *pNewItem == rItem, - nWhich, "unequal items in Put(): no operator==?" ); - } -#endif -#endif - AddRef( *pNewItem, pImp->nInitRefCount ); - SfxPoolItem* pTemp = pNewItem; - if ( ppFreeIsSet == sal_False ) - (*ppItemArr)->push_back( pTemp ); - else - { - DBG_ASSERT( *ppFree == 0, "using surrogate in use" ); - *ppFree = pNewItem; - } - return *pNewItem; -} - -// ----------------------------------------------------------------------- - -void SfxItemPool::Remove( const SfxPoolItem& rItem ) -{ - DBG_CHKTHIS(SfxItemPool, 0); - - DBG_ASSERT( !rItem.ISA(SfxSetItem) || - 0 != &((const SfxSetItem&)rItem).GetItemSet(), - "SetItem without ItemSet" ); - - SFX_ASSERT( !IsPoolDefaultItem(&rItem), rItem.Which(), - "wo kommt denn hier ein Pool-Default her" ); - - // richtigen Secondary-Pool finden - const sal_uInt16 nWhich = rItem.Which(); - sal_Bool bSID = nWhich > SFX_WHICH_MAX; - if ( !bSID && !IsInRange(nWhich) ) - { - if ( pSecondary ) - { - pSecondary->Remove( rItem ); - return; - } - OSL_FAIL( "unknown Which-Id - cannot remove item" ); - } - - // SID oder nicht poolable (neue Definition)? - sal_uInt16 nIndex = bSID ? USHRT_MAX : GetIndex_Impl(nWhich); - if ( bSID || IsItemFlag_Impl( nIndex, SFX_ITEM_NOT_POOLABLE ) ) - { - SFX_ASSERT( USHRT_MAX != nIndex || - !IsDefaultItem(&rItem), rItem.Which(), - "ein nicht Pool-Item ist Default?!" ); - if ( 0 == ReleaseRef(rItem) ) - { - SfxPoolItem *pItem = &(SfxPoolItem &)rItem; - delete pItem; - } - return; - } - - SFX_ASSERT( rItem.GetRefCount(), rItem.Which(), "RefCount == 0, Remove unmoeglich" ); - - // statische Defaults sind eben einfach da - if ( rItem.GetKind() == SFX_ITEMS_STATICDEFAULT && - &rItem == *( ppStaticDefaults + GetIndex_Impl(nWhich) ) ) - return; - - // Item im eigenen Pool suchen - SfxPoolItemArray_Impl** ppItemArr = (pImp->ppPoolItems + nIndex); - SFX_ASSERT( *ppItemArr, rItem.Which(), "removing Item not in Pool" ); - SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); - for( size_t n = (*ppItemArr)->size(); n; ++ppHtArr, --n ) - if( *ppHtArr == &rItem ) - { - if ( (*ppHtArr)->GetRefCount() ) //! - ReleaseRef( **ppHtArr ); - else - { - SFX_ASSERT( 0, rItem.Which(), "removing Item without ref" ); - SFX_TRACE( "to be removed, but not no refs: ", *ppHtArr ); - } - - // ggf. kleinstmoegliche freie Position merken - size_t nPos = (*ppItemArr)->size() - n; - if ( (*ppItemArr)->nFirstFree > nPos ) - (*ppItemArr)->nFirstFree = nPos; - - //! MI: Hack, solange wir das Problem mit dem Outliner haben - //! siehe anderes MI-REF - if ( 0 == (*ppHtArr)->GetRefCount() && nWhich < 4000 ) - DELETEZ(*ppHtArr); - return; - } - - // nicht vorhanden - SFX_ASSERT( 0, rItem.Which(), "removing Item not in Pool" ); - SFX_TRACE( "to be removed, but not in pool: ", &rItem ); -} - -// ----------------------------------------------------------------------- - -const SfxPoolItem& SfxItemPool::GetDefaultItem( sal_uInt16 nWhich ) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - - if ( !IsInRange(nWhich) ) - { - if ( pSecondary ) - return pSecondary->GetDefaultItem( nWhich ); - SFX_ASSERT( 0, nWhich, "unknown which - dont ask me for defaults" ); - } - - DBG_ASSERT( ppStaticDefaults, "no defaults known - dont ask me for defaults" ); - sal_uInt16 nPos = GetIndex_Impl(nWhich); - SfxPoolItem *pDefault = *(ppPoolDefaults + nPos); - if ( pDefault ) - return *pDefault; - return **(ppStaticDefaults + nPos); -} - -// ----------------------------------------------------------------------- - - -void SfxItemPool::FreezeIdRanges() - -/* [Beschreibung] - - This method should be called at the master pool, when all secondary - pools are appended to it. - - It calculates the ranges of 'which-ids' for fast construction of - item-sets, which contains all 'which-ids'. -*/ - -{ - FillItemIdRanges_Impl( _pPoolRanges ); -} - - -// ----------------------------------------------------------------------- - -void SfxItemPool::FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - DBG_ASSERT( !_pPoolRanges, "GetFrozenRanges() would be faster!" ); - - const SfxItemPool *pPool; - sal_uInt16 nLevel = 0; - for( pPool = this; pPool; pPool = pPool->pSecondary ) - ++nLevel; - - pWhichRanges = new sal_uInt16[ 2*nLevel + 1 ]; - - nLevel = 0; - for( pPool = this; pPool; pPool = pPool->pSecondary ) - { - *(pWhichRanges+(nLevel++)) = pPool->nStart; - *(pWhichRanges+(nLevel++)) = pPool->nEnd; - *(pWhichRanges+nLevel) = 0; - } -} - -// ----------------------------------------------------------------------- - -const SfxPoolItem *SfxItemPool::GetItem2(sal_uInt16 nWhich, sal_uInt32 nOfst) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - - if ( !IsInRange(nWhich) ) - { - if ( pSecondary ) - return pSecondary->GetItem2( nWhich, nOfst ); - SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot resolve surrogate" ); - return 0; - } - - // dflt-Attribut? - if ( nOfst == SFX_ITEMS_DEFAULT ) - return *(ppStaticDefaults + GetIndex_Impl(nWhich)); - - SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(nWhich)); - if( pItemArr && nOfst < pItemArr->size() ) - return (*pItemArr)[nOfst]; - - return 0; -} - -// ----------------------------------------------------------------------- - -sal_uInt32 SfxItemPool::GetItemCount2(sal_uInt16 nWhich) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - - if ( !IsInRange(nWhich) ) - { - if ( pSecondary ) - return pSecondary->GetItemCount2( nWhich ); - SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot resolve surrogate" ); - return 0; - } - - SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(nWhich)); - if ( pItemArr ) - return pItemArr->size(); - return 0; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemPool::GetWhich( sal_uInt16 nSlotId, sal_Bool bDeep ) const -{ - if ( !IsSlot(nSlotId) ) - return nSlotId; - -#ifdef TF_POOLABLE - sal_uInt16 nCount = nEnd - nStart + 1; - for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) - if ( pItemInfos[nOfs]._nSID == nSlotId ) - return nOfs + nStart; -#else - if ( pSlotIds ) - { - sal_uInt16 nCount = nEnd - nStart + 1; - for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) - if ( pSlotIds[nOfs] == nSlotId ) - return nOfs + nStart; - } -#endif - if ( pSecondary && bDeep ) - return pSecondary->GetWhich(nSlotId); - return nSlotId; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemPool::GetSlotId( sal_uInt16 nWhich, sal_Bool bDeep ) const -{ - if ( !IsWhich(nWhich) ) - return nWhich; - - if ( !IsInRange( nWhich ) ) - { - if ( pSecondary && bDeep ) - return pSecondary->GetSlotId(nWhich); - SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get slot-id" ); - return 0; - } -#ifdef TF_POOLABLE - - sal_uInt16 nSID = pItemInfos[nWhich - nStart]._nSID; - return nSID ? nSID : nWhich; -#else - else if ( pSlotIds ) - return pSlotIds[nWhich - nStart]; - return nWhich; -#endif -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemPool::GetTrueWhich( sal_uInt16 nSlotId, sal_Bool bDeep ) const -{ - if ( !IsSlot(nSlotId) ) - return 0; - -#ifdef TF_POOLABLE - sal_uInt16 nCount = nEnd - nStart + 1; - for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) - if ( pItemInfos[nOfs]._nSID == nSlotId ) - return nOfs + nStart; -#else - if ( pSlotIds ) - { - sal_uInt16 nCount = nEnd - nStart + 1; - for ( sal_uInt16 nOfs = 0; nOfs < nCount; ++nOfs ) - if ( pSlotIds[nOfs] == nSlotId ) - return nOfs + nStart; - } -#endif - if ( pSecondary && bDeep ) - return pSecondary->GetTrueWhich(nSlotId); - return 0; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemPool::GetTrueSlotId( sal_uInt16 nWhich, sal_Bool bDeep ) const -{ - if ( !IsWhich(nWhich) ) - return 0; - - if ( !IsInRange( nWhich ) ) - { - if ( pSecondary && bDeep ) - return pSecondary->GetTrueSlotId(nWhich); - SFX_ASSERT( 0, nWhich, "unknown Which-Id - cannot get slot-id" ); - return 0; - } -#ifdef TF_POOLABLE - return pItemInfos[nWhich - nStart]._nSID; -#else - else if ( pSlotIds ) - return pSlotIds[nWhich - nStart]; - else - return 0; -#endif -} -// ----------------------------------------------------------------------- -void SfxItemPool::SetFileFormatVersion( sal_uInt16 nFileFormatVersion ) - -/* [Description] - - You must call this function to set the file format version after - concatenating your secondary-pools but before you store any - pool, itemset or item. Only set the version at the master pool, - never at any secondary pool. -*/ - -{ - DBG_ASSERT( this == pMaster, - "SfxItemPool::SetFileFormatVersion() but not a master pool" ); - for ( SfxItemPool *pPool = this; pPool; pPool = pPool->pSecondary ) - pPool->_nFileFormatVersion = nFileFormatVersion; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/itemprop.cxx b/svl/source/items/itemprop.cxx deleted file mode 100644 index caabf2e624..0000000000 --- a/svl/source/items/itemprop.cxx +++ /dev/null @@ -1,435 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/itemprop.hxx> -#include <svl/itempool.hxx> -#include <svl/itemset.hxx> -#include <com/sun/star/beans/PropertyAttribute.hpp> -#include <boost/unordered_map.hpp> -/************************************************************************* - UNO III Implementation -*************************************************************************/ -using namespace com::sun::star; -using namespace com::sun::star::beans; -using namespace com::sun::star::lang; -using namespace com::sun::star::uno; - -struct equalOUString -{ - bool operator()(const ::rtl::OUString& r1, const ::rtl::OUString& r2) const - { - return r1.equals( r2 ); - } -}; - -typedef ::boost::unordered_map< ::rtl::OUString, - SfxItemPropertySimpleEntry, - ::rtl::OUStringHash, - equalOUString > SfxItemPropertyHashMap_t; - -class SfxItemPropertyMap_Impl : public SfxItemPropertyHashMap_t -{ -public: - mutable uno::Sequence< beans::Property > m_aPropSeq; - - SfxItemPropertyMap_Impl(){} - SfxItemPropertyMap_Impl( const SfxItemPropertyMap_Impl* pSource ); -}; -SfxItemPropertyMap_Impl::SfxItemPropertyMap_Impl( const SfxItemPropertyMap_Impl* pSource ) -{ - this->SfxItemPropertyHashMap_t::operator=( *pSource ); - m_aPropSeq = pSource->m_aPropSeq; -} - -SfxItemPropertyMap::SfxItemPropertyMap( const SfxItemPropertyMapEntry* pEntries ) : - m_pImpl( new SfxItemPropertyMap_Impl ) -{ - while( pEntries->pName ) - { - ::rtl::OUString sEntry(pEntries->pName, pEntries->nNameLen, RTL_TEXTENCODING_ASCII_US ); - (*m_pImpl) [ sEntry ] = pEntries; - ++pEntries; - } -} - -SfxItemPropertyMap::SfxItemPropertyMap( const SfxItemPropertyMap* pSource ) : - m_pImpl( new SfxItemPropertyMap_Impl( pSource->m_pImpl ) ) -{ -} - -SfxItemPropertyMap::~SfxItemPropertyMap() -{ - delete m_pImpl; -} - -const SfxItemPropertySimpleEntry* SfxItemPropertyMap::getByName( const ::rtl::OUString &rName ) const -{ - SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName); - if( aIter == m_pImpl->end() ) - return 0; - return &aIter->second; -} - -uno::Sequence<beans::Property> SfxItemPropertyMap::getProperties() const -{ - if( !m_pImpl->m_aPropSeq.getLength() ) - { - m_pImpl->m_aPropSeq.realloc( m_pImpl->size() ); - beans::Property* pPropArray = m_pImpl->m_aPropSeq.getArray(); - sal_uInt32 n = 0; - SfxItemPropertyHashMap_t::const_iterator aIt = m_pImpl->begin(); - while( aIt != m_pImpl->end() ) - //for ( const SfxItemPropertyMap *pMap = _pMap; pMap->pName; ++pMap ) - { - const SfxItemPropertySimpleEntry* pEntry = &(*aIt).second; - pPropArray[n].Name = (*aIt).first; - pPropArray[n].Handle = pEntry->nWID; - if(pEntry->pType) - pPropArray[n].Type = *pEntry->pType; - pPropArray[n].Attributes = - sal::static_int_cast< sal_Int16 >(pEntry->nFlags); - n++; - ++aIt; - } - } - - return m_pImpl->m_aPropSeq; -} - -beans::Property SfxItemPropertyMap::getPropertyByName( const ::rtl::OUString rName ) const - throw( beans::UnknownPropertyException ) -{ - SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName); - if( aIter == m_pImpl->end() ) - throw UnknownPropertyException(); - const SfxItemPropertySimpleEntry* pEntry = &aIter->second; - beans::Property aProp; - aProp.Name = rName; - aProp.Handle = pEntry->nWID; - if(pEntry->pType) - aProp.Type = *pEntry->pType; - aProp.Attributes = sal::static_int_cast< sal_Int16 >(pEntry->nFlags); - return aProp; -} - -sal_Bool SfxItemPropertyMap::hasPropertyByName( const ::rtl::OUString& rName ) const -{ - SfxItemPropertyHashMap_t::const_iterator aIter = m_pImpl->find(rName); - return aIter != m_pImpl->end(); -} - -void SfxItemPropertyMap::mergeProperties( const uno::Sequence< beans::Property >& rPropSeq ) -{ - const beans::Property* pPropArray = rPropSeq.getConstArray(); - sal_uInt32 nElements = rPropSeq.getLength(); - for( sal_uInt32 nElement = 0; nElement < nElements; ++nElement ) - { - SfxItemPropertySimpleEntry aTemp( - sal::static_int_cast< sal_Int16 >( pPropArray[nElement].Handle ), //nWID - &pPropArray[nElement].Type, //pType - pPropArray[nElement].Attributes, //nFlags - 0 ); //nMemberId - (*m_pImpl)[pPropArray[nElement].Name] = aTemp; - } -} - -PropertyEntryVector_t SfxItemPropertyMap::getPropertyEntries() const -{ - PropertyEntryVector_t aRet; - aRet.reserve(m_pImpl->size()); - - SfxItemPropertyHashMap_t::const_iterator aIt = m_pImpl->begin(); - while( aIt != m_pImpl->end() ) - { - const SfxItemPropertySimpleEntry* pEntry = &(*aIt).second; - aRet.push_back( SfxItemPropertyNamedEntry( (*aIt).first, * pEntry ) ); - ++aIt; - } - return aRet; -} - -sal_uInt32 SfxItemPropertyMap::getSize() const -{ - return m_pImpl->size(); -} - -SfxItemPropertySet::~SfxItemPropertySet() -{ -} - -sal_Bool SfxItemPropertySet::FillItem(SfxItemSet&, sal_uInt16, sal_Bool) const -{ - return sal_False; -} - -void SfxItemPropertySet::getPropertyValue( const SfxItemPropertySimpleEntry& rEntry, - const SfxItemSet& rSet, Any& rAny ) const - throw(RuntimeException) -{ - // get the SfxPoolItem - const SfxPoolItem* pItem = 0; - SfxItemState eState = rSet.GetItemState( rEntry.nWID, sal_True, &pItem ); - if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID ) - pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID); - // return item values as uno::Any - if(eState >= SFX_ITEM_DEFAULT && pItem) - { - pItem->QueryValue( rAny, rEntry.nMemberId ); - } - else - { - SfxItemSet aSet(*rSet.GetPool(), rEntry.nWID, rEntry.nWID); - if(FillItem(aSet, rEntry.nWID, sal_True)) - { - const SfxPoolItem& rItem = aSet.Get(rEntry.nWID); - rItem.QueryValue( rAny, rEntry.nMemberId ); - } - else if(0 == (rEntry.nFlags & PropertyAttribute::MAYBEVOID)) - throw RuntimeException(); - } - - - // convert general SfxEnumItem values to specific values - if( rEntry.pType && TypeClass_ENUM == rEntry.pType->getTypeClass() && - rAny.getValueTypeClass() == TypeClass_LONG ) - { - sal_Int32 nTmp = *(sal_Int32*)rAny.getValue(); - rAny.setValue( &nTmp, *rEntry.pType ); - } -} - -void SfxItemPropertySet::getPropertyValue( const rtl::OUString &rName, - const SfxItemSet& rSet, Any& rAny ) const - throw(RuntimeException, UnknownPropertyException) -{ - // detect which-id - const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName ); - if ( !pEntry ) - throw UnknownPropertyException(); - getPropertyValue( *pEntry,rSet, rAny ); -} - -Any SfxItemPropertySet::getPropertyValue( const rtl::OUString &rName, - const SfxItemSet& rSet ) const - throw(RuntimeException, UnknownPropertyException) -{ - Any aVal; - getPropertyValue( rName,rSet, aVal ); - return aVal; -} - -void SfxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry& rEntry, - const Any& aVal, - SfxItemSet& rSet ) const - throw(RuntimeException, - IllegalArgumentException) -{ - // get the SfxPoolItem - const SfxPoolItem* pItem = 0; - SfxPoolItem *pNewItem = 0; - SfxItemState eState = rSet.GetItemState( rEntry.nWID, sal_True, &pItem ); - if(SFX_ITEM_SET != eState && SFX_WHICH_MAX > rEntry.nWID ) - pItem = &rSet.GetPool()->GetDefaultItem(rEntry.nWID); - //maybe there's another way to find an Item - if(eState < SFX_ITEM_DEFAULT) - { - SfxItemSet aSet(*rSet.GetPool(), rEntry.nWID, rEntry.nWID); - if(FillItem(aSet, rEntry.nWID, sal_False)) - { - const SfxPoolItem &rItem = aSet.Get(rEntry.nWID); - pNewItem = rItem.Clone(); - } - } - if(!pNewItem && pItem) - { - pNewItem = pItem->Clone(); - } - if(pNewItem) - { - if( !pNewItem->PutValue( aVal, rEntry.nMemberId ) ) - { - DELETEZ(pNewItem); - throw IllegalArgumentException(); - } - // apply new item - rSet.Put( *pNewItem, rEntry.nWID ); - delete pNewItem; - } -} - -void SfxItemPropertySet::setPropertyValue( const rtl::OUString &rName, - const Any& aVal, - SfxItemSet& rSet ) const - throw(RuntimeException, - IllegalArgumentException, - UnknownPropertyException) -{ - const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName ); - if ( !pEntry ) - { - throw UnknownPropertyException(); - } - setPropertyValue(*pEntry, aVal, rSet); -} - -PropertyState SfxItemPropertySet::getPropertyState(const SfxItemPropertySimpleEntry& rEntry, const SfxItemSet& rSet) const - throw() -{ - PropertyState eRet = PropertyState_DIRECT_VALUE; - sal_uInt16 nWhich = rEntry.nWID; - - // item state holen - SfxItemState eState = rSet.GetItemState( nWhich, sal_False ); - // item-Wert als UnoAny zurueckgeben - if(eState == SFX_ITEM_DEFAULT) - eRet = PropertyState_DEFAULT_VALUE; - else if(eState < SFX_ITEM_DEFAULT) - eRet = PropertyState_AMBIGUOUS_VALUE; - return eRet; -} -PropertyState SfxItemPropertySet::getPropertyState( - const rtl::OUString& rName, const SfxItemSet& rSet) const - throw(UnknownPropertyException) -{ - PropertyState eRet = PropertyState_DIRECT_VALUE; - - // which-id ermitteln - const SfxItemPropertySimpleEntry* pEntry = m_aMap.getByName( rName ); - if( !pEntry || !pEntry->nWID ) - { - throw UnknownPropertyException(); - } - sal_uInt16 nWhich = pEntry->nWID; - - // item holen - const SfxPoolItem* pItem = 0; - SfxItemState eState = rSet.GetItemState( nWhich, sal_False, &pItem ); - if(!pItem && nWhich != rSet.GetPool()->GetSlotId(nWhich)) - pItem = &rSet.GetPool()->GetDefaultItem(nWhich); - // item-Wert als UnoAny zurueckgeben - if(eState == SFX_ITEM_DEFAULT) - eRet = PropertyState_DEFAULT_VALUE; - else if(eState < SFX_ITEM_DEFAULT) - eRet = PropertyState_AMBIGUOUS_VALUE; - return eRet; -} - -Reference<XPropertySetInfo> - SfxItemPropertySet::getPropertySetInfo() const -{ - if( !m_xInfo.is() ) - m_xInfo = new SfxItemPropertySetInfo( &m_aMap ); - return m_xInfo; -} - -struct SfxItemPropertySetInfo_Impl -{ - SfxItemPropertyMap* m_pOwnMap; -}; - -SfxItemPropertySetInfo::SfxItemPropertySetInfo(const SfxItemPropertyMap *pMap ) : - m_pImpl( new SfxItemPropertySetInfo_Impl ) -{ - m_pImpl->m_pOwnMap = new SfxItemPropertyMap( pMap ); -} - -SfxItemPropertySetInfo::SfxItemPropertySetInfo(const SfxItemPropertyMapEntry *pEntries ) : - m_pImpl( new SfxItemPropertySetInfo_Impl ) -{ - m_pImpl->m_pOwnMap = new SfxItemPropertyMap( pEntries ); -} - -Sequence< Property > SAL_CALL - SfxItemPropertySetInfo::getProperties( ) - throw(RuntimeException) -{ - return m_pImpl->m_pOwnMap->getProperties(); -} - -const SfxItemPropertyMap* SfxItemPropertySetInfo::getMap() const -{ - return m_pImpl->m_pOwnMap; -} - - -SfxItemPropertySetInfo::~SfxItemPropertySetInfo() -{ - delete m_pImpl->m_pOwnMap; - delete m_pImpl; -} - -Property SAL_CALL - SfxItemPropertySetInfo::getPropertyByName( const ::rtl::OUString& rName ) - throw(UnknownPropertyException, RuntimeException) -{ - return m_pImpl->m_pOwnMap->getPropertyByName( rName ); -} - -sal_Bool SAL_CALL - SfxItemPropertySetInfo::hasPropertyByName( const ::rtl::OUString& rName ) - throw(RuntimeException) -{ - return m_pImpl->m_pOwnMap->hasPropertyByName( rName ); -} - -SfxExtItemPropertySetInfo::SfxExtItemPropertySetInfo( - const SfxItemPropertyMapEntry *pMap, - const Sequence<Property>& rPropSeq ) : - aExtMap( pMap ) -{ - aExtMap.mergeProperties( rPropSeq ); -} - -SfxExtItemPropertySetInfo::~SfxExtItemPropertySetInfo() -{ -} - -Sequence< Property > SAL_CALL - SfxExtItemPropertySetInfo::getProperties( ) throw(RuntimeException) -{ - return aExtMap.getProperties(); -} - -Property SAL_CALL -SfxExtItemPropertySetInfo::getPropertyByName( const rtl::OUString& rPropertyName ) - throw(UnknownPropertyException, RuntimeException) -{ - return aExtMap.getPropertyByName( rPropertyName ); -} - -sal_Bool SAL_CALL -SfxExtItemPropertySetInfo::hasPropertyByName( const rtl::OUString& rPropertyName ) - throw(RuntimeException) -{ - return aExtMap.hasPropertyByName( rPropertyName ); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx deleted file mode 100644 index 0ca722382e..0000000000 --- a/svl/source/items/itemset.cxx +++ /dev/null @@ -1,2059 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <string.h> - -#include <cstdarg> -#define _SVSTDARR_USHORTS -#define _SVSTDARR_ULONGS - -#include <svl/svstdarr.hxx> -#include <svl/itemset.hxx> -#include <svl/itempool.hxx> -#include <svl/itemiter.hxx> -#include <svl/whiter.hxx> -#include <svl/nranges.hxx> -#include "whassert.hxx" - -#include <tools/stream.hxx> -#include <tools/solar.h> - -// STATIC DATA ----------------------------------------------------------- - -static const sal_uInt16 nInitCount = 10; // einzelne USHORTs => 5 Paare ohne '0' -#if OSL_DEBUG_LEVEL > 1 -static sal_uLong nRangesCopyCount = 0; // wie oft wurden Ranges kopiert -#endif - -DBG_NAME(SfxItemSet) - -//======================================================================== - -#define NUMTYPE sal_uInt16 -#define SvNums SvUShorts -#define SfxNumRanges SfxUShortRanges -#include "nranges.cxx" -#undef NUMTYPE -#undef SvNums -#undef SfxNumRanges - -#define NUMTYPE sal_uLong -#define SvNums SvULongs -#define SfxNumRanges SfxULongRanges -#include "nranges.cxx" -#undef NUMTYPE -#undef SvNums -#undef SfxNumRanges - -//======================================================================== - -#ifdef DBG_UTIL - - -const sal_Char *DbgCheckItemSet( const void* pVoid ) -{ - const SfxItemSet *pSet = (const SfxItemSet*) pVoid; - SfxWhichIter aIter( *pSet ); - sal_uInt16 nCount = 0, n = 0; - for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh; nWh = aIter.NextWhich(), ++n ) - { - const SfxPoolItem *pItem = pSet->_aItems[n]; - if ( pItem ) - { - ++nCount; - DBG_ASSERT( IsInvalidItem(pItem) || - pItem->Which() == 0 || pItem->Which() == nWh, - "SfxItemSet: invalid which-id" ); - DBG_ASSERT( IsInvalidItem(pItem) || !pItem->Which() || - !SfxItemPool::IsWhich(pItem->Which()) || - pSet->GetPool()->IsItemFlag(nWh, SFX_ITEM_NOT_POOLABLE) || - SFX_ITEMS_NULL != pSet->GetPool()->GetSurrogate(pItem), - "SfxItemSet: item in set which is not in pool" ); - } - - } - DBG_ASSERT( pSet->_nCount == nCount, "wrong SfxItemSet::nCount detected" ); - - return 0; -} - -#endif -// ----------------------------------------------------------------------- - -SfxItemSet::SfxItemSet -( - SfxItemPool& rPool, /* der Pool, in dem die SfxPoolItems, - welche in dieses SfxItemSet gelangen, - aufgenommen werden sollen */ - sal_Bool -#ifdef DBG_UTIL -#ifdef SFX_ITEMSET_NO_DEFAULT_CTOR - - bTotalRanges /* komplette Pool-Ranges uebernehmen, - muss auf sal_True gesetzt werden */ -#endif -#endif -) -/* [Beschreibung] - - Konstruktor fuer ein SfxItemSet mit genau den Which-Bereichen, welche - dem angegebenen <SfxItemPool> bekannt sind. - - - [Anmerkung] - - F"ur Sfx-Programmierer ein derart konstruiertes SfxItemSet kann - keinerlei Items mit Slot-Ids als Which-Werte aufnehmen! -*/ - -: _pPool( &rPool ), - _pParent( 0 ), - _nCount( 0 ) -{ - DBG_CTOR(SfxItemSet, DbgCheckItemSet); - DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); - DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); -// DBG_ASSERT( bTotalRanges || abs( &bTotalRanges - this ) < 1000, -// "please use suitable ranges" ); -#ifdef DBG_UTIL -#ifdef SFX_ITEMSET_NO_DEFAULT_CTOR - if ( !bTotalRanges ) - *(int*)0 = 0; // GPF -#endif -#endif - - _pWhichRanges = (sal_uInt16*) _pPool->GetFrozenIdRanges(); - DBG_ASSERT( _pWhichRanges, "don't create ItemSets with full range before FreezeIdRanges()" ); - if ( !_pWhichRanges ) - _pPool->FillItemIdRanges_Impl( _pWhichRanges ); - - const sal_uInt16 nSize = TotalCount(); - _aItems = new const SfxPoolItem* [ nSize ]; - memset( (void*) _aItems, 0, nSize * sizeof( SfxPoolItem* ) ); -} - -// ----------------------------------------------------------------------- - -SfxItemSet::SfxItemSet( SfxItemPool& rPool, sal_uInt16 nWhich1, sal_uInt16 nWhich2 ): - _pPool( &rPool ), - _pParent( 0 ), - _nCount( 0 ) -{ - DBG_CTOR(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT( nWhich1 <= nWhich2, "Ungueltiger Bereich" ); - DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); - DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); - - InitRanges_Impl(nWhich1, nWhich2); -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::InitRanges_Impl(sal_uInt16 nWh1, sal_uInt16 nWh2) -{ - DBG_CHKTHIS(SfxItemSet, 0); - _pWhichRanges = new sal_uInt16[ 3 ]; - *(_pWhichRanges+0) = nWh1; - *(_pWhichRanges+1) = nWh2; - *(_pWhichRanges+2) = 0; - const sal_uInt16 nRg = nWh2 - nWh1 + 1; - _aItems = new const SfxPoolItem* [ nRg ]; - memset( (void*) _aItems, 0, nRg * sizeof( SfxPoolItem* ) ); -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::InitRanges_Impl(va_list pArgs, sal_uInt16 nWh1, sal_uInt16 nWh2, sal_uInt16 nNull) -{ - DBG_CHKTHIS(SfxItemSet, 0); - - sal_uInt16 nSize = InitializeRanges_Impl( _pWhichRanges, pArgs, nWh1, nWh2, nNull ); - _aItems = new const SfxPoolItem* [ nSize ]; - memset( (void*) _aItems, 0, sizeof( SfxPoolItem* ) * nSize ); -} - -// ----------------------------------------------------------------------- - -SfxItemSet::SfxItemSet( SfxItemPool& rPool, - USHORT_ARG nWh1, USHORT_ARG nWh2, USHORT_ARG nNull, ... ): - _pPool( &rPool ), - _pParent( 0 ), - _pWhichRanges( 0 ), - _nCount( 0 ) -{ - DBG_CTOR(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT( nWh1 <= nWh2, "Ungueltiger Bereich" ); - DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); - DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); - - if(!nNull) - InitRanges_Impl( - sal::static_int_cast< sal_uInt16 >(nWh1), - sal::static_int_cast< sal_uInt16 >(nWh2)); - else { - va_list pArgs; - va_start( pArgs, nNull ); - InitRanges_Impl( - pArgs, sal::static_int_cast< sal_uInt16 >(nWh1), - sal::static_int_cast< sal_uInt16 >(nWh2), - sal::static_int_cast< sal_uInt16 >(nNull)); - va_end(pArgs); - } -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::InitRanges_Impl(const sal_uInt16 *pWhichPairTable) -{ - DBG_CHKTHIS(SfxItemSet, 0); - #if OSL_DEBUG_LEVEL > 1 - OSL_TRACE("SfxItemSet: Ranges-CopyCount==%ul", ++nRangesCopyCount); - #endif - - sal_uInt16 nCnt = 0; - const sal_uInt16* pPtr = pWhichPairTable; - while( *pPtr ) - { - nCnt += ( *(pPtr+1) - *pPtr ) + 1; - pPtr += 2; - } - - _aItems = new const SfxPoolItem* [ nCnt ]; - memset( (void*) _aItems, 0, sizeof( SfxPoolItem* ) * nCnt ); - - std::ptrdiff_t cnt = pPtr - pWhichPairTable +1; - _pWhichRanges = new sal_uInt16[ cnt ]; - memcpy( _pWhichRanges, pWhichPairTable, sizeof( sal_uInt16 ) * cnt ); -} - - -// ----------------------------------------------------------------------- - -SfxItemSet::SfxItemSet( SfxItemPool& rPool, const sal_uInt16* pWhichPairTable ): - _pPool( &rPool ), - _pParent( 0 ), - _pWhichRanges(0), - _nCount( 0 ) -{ - DBG_CTOR(SfxItemSet, 0); - DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); - DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); - - // pWhichPairTable == 0 ist f"ur das SfxAllEnumItemSet - if ( pWhichPairTable ) - InitRanges_Impl(pWhichPairTable); -} - -// ----------------------------------------------------------------------- - -SfxItemSet::SfxItemSet( const SfxItemSet& rASet ): - _pPool( rASet._pPool ), - _pParent( rASet._pParent ), - _nCount( rASet._nCount ) -{ - DBG_CTOR(SfxItemSet, DbgCheckItemSet); - DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); - DBG( _pChildCountCtor; *_pChildCount(this) = 0 ); - DBG( ++*_pChildCount(_pParent) ); - - // errechne die Anzahl von Attributen - sal_uInt16 nCnt = 0; - sal_uInt16* pPtr = rASet._pWhichRanges; - while( *pPtr ) - { - nCnt += ( *(pPtr+1) - *pPtr ) + 1; - pPtr += 2; - } - - _aItems = new const SfxPoolItem* [ nCnt ]; - - // Attribute kopieren - SfxItemArray ppDst = _aItems, ppSrc = rASet._aItems; - for( sal_uInt16 n = nCnt; n; --n, ++ppDst, ++ppSrc ) - if ( 0 == *ppSrc || // aktueller Default? - IsInvalidItem(*ppSrc) || // Dont Care? - IsStaticDefaultItem(*ppSrc) ) // nicht zu poolende Defaults - // einfach Pointer kopieren - *ppDst = *ppSrc; - else if ( _pPool->IsItemFlag( **ppSrc, SFX_ITEM_POOLABLE ) ) - { - // einfach Pointer kopieren und Ref-Count erh"ohen - *ppDst = *ppSrc; - ( (SfxPoolItem*) (*ppDst) )->AddRef(); - } - else if ( !(*ppSrc)->Which() ) - *ppDst = (*ppSrc)->Clone(); - else - // !IsPoolable() => via Pool zuweisen - *ppDst = &_pPool->Put( **ppSrc ); - - // dann noch die Which Ranges kopieren - #if OSL_DEBUG_LEVEL > 1 - OSL_TRACE("SfxItemSet: Ranges-CopyCount==%ul", ++nRangesCopyCount); - #endif - std::ptrdiff_t cnt = pPtr - rASet._pWhichRanges+1; - _pWhichRanges = new sal_uInt16[ cnt ]; - memcpy( _pWhichRanges, rASet._pWhichRanges, sizeof( sal_uInt16 ) * cnt); -} - -// ----------------------------------------------------------------------- - -SfxItemSet::~SfxItemSet() -{ - DBG_DTOR(SfxItemSet, DbgCheckItemSet); -#ifdef DBG_UTIL - DBG( DBG_ASSERT( 0 == *_pChildCount(this), "SfxItemSet: deleting parent-itemset" ) ) -#endif - - sal_uInt16 nCount = TotalCount(); - if( Count() ) - { - SfxItemArray ppFnd = _aItems; - for( sal_uInt16 nCnt = nCount; nCnt; --nCnt, ++ppFnd ) - if( *ppFnd && !IsInvalidItem(*ppFnd) ) - { - if( !(*ppFnd)->Which() ) - delete (SfxPoolItem*) *ppFnd; - else { - // noch mehrer Referenzen vorhanden, also nur den - // ReferenzCounter manipulieren - if ( 1 < (*ppFnd)->GetRefCount() && !IsDefaultItem(*ppFnd) ) - (*ppFnd)->ReleaseRef(); - else - if ( !IsDefaultItem(*ppFnd) ) - // aus dem Pool loeschen - _pPool->Remove( **ppFnd ); - } - } - } - - // FIXME: could be delete[] (SfxPoolItem **)_aItems; - delete[] _aItems; - if ( _pWhichRanges != _pPool->GetFrozenIdRanges() ) - delete[] _pWhichRanges; - _pWhichRanges = 0; // for invariant-testing - - DBG( --*_pChildCount(_pParent) ); - DBG( delete _pChildCount(this); _pChildCountDtor ); -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemSet::ClearItem( sal_uInt16 nWhich ) - -// einzelnes Item oder alle Items (nWhich==0) l"oschen - -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - if( !Count() ) - return 0; - - sal_uInt16 nDel = 0; - SfxItemArray ppFnd = _aItems; - - if( nWhich ) - { - const sal_uInt16* pPtr = _pWhichRanges; - while( *pPtr ) - { - // in diesem Bereich? - if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // "uberhaupt gesetzt? - ppFnd += nWhich - *pPtr; - if( *ppFnd ) - { - // wegen der Assertions ins Sub-Calls mu\s das hier sein - --_nCount; - const SfxPoolItem *pItemToClear = *ppFnd; - *ppFnd = 0; - - if ( !IsInvalidItem(pItemToClear) ) - { - if ( nWhich <= SFX_WHICH_MAX ) - { - const SfxPoolItem& rNew = _pParent - ? _pParent->Get( nWhich, sal_True ) - : _pPool->GetDefaultItem( nWhich ); - - Changed( *pItemToClear, rNew ); - } - if ( pItemToClear->Which() ) - _pPool->Remove( *pItemToClear ); - } - ++nDel; - } - - // gefunden => raus - break; - } - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } - } - else - { - nDel = _nCount; - - sal_uInt16* pPtr = _pWhichRanges; - while( *pPtr ) - { - for( nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) - if( *ppFnd ) - { - // wegen der Assertions ins Sub-Calls mu\s das hier sein - --_nCount; - const SfxPoolItem *pItemToClear = *ppFnd; - *ppFnd = 0; - - if ( !IsInvalidItem(pItemToClear) ) - { - if ( nWhich <= SFX_WHICH_MAX ) - { - const SfxPoolItem& rNew = _pParent - ? _pParent->Get( nWhich, sal_True ) - : _pPool->GetDefaultItem( nWhich ); - - Changed( *pItemToClear, rNew ); - } - - // #i32448# - // Take care of disabled items, too. - if(!pItemToClear->nWhich) - { - // item is disabled, delete it - delete pItemToClear; - } - else - { - // remove item from pool - _pPool->Remove( *pItemToClear ); - } - } - } - pPtr += 2; - } - } - return nDel; -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::ClearInvalidItems( sal_Bool bHardDefault ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - sal_uInt16* pPtr = _pWhichRanges; - SfxItemArray ppFnd = _aItems; - if ( bHardDefault ) - while( *pPtr ) - { - for ( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) - if ( IsInvalidItem(*ppFnd) ) - *ppFnd = &_pPool->Put( _pPool->GetDefaultItem(nWhich) ); - pPtr += 2; - } - else - while( *pPtr ) - { - for( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) - if( IsInvalidItem(*ppFnd) ) - { - *ppFnd = 0; - --_nCount; - } - pPtr += 2; - } -} - -//------------------------------------------------------------------------ - - -void SfxItemSet::InvalidateAllItems() -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT( !_nCount, "Es sind noch Items gesetzt" ); - - memset( (void*)_aItems, -1, ( _nCount = TotalCount() ) * sizeof( SfxPoolItem*) ); -} - -// ----------------------------------------------------------------------- - -SfxItemState SfxItemSet::GetItemState( sal_uInt16 nWhich, - sal_Bool bSrchInParent, - const SfxPoolItem **ppItem ) const -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - // suche den Bereich in dem das Which steht: - const SfxItemSet* pAktSet = this; - SfxItemState eRet = SFX_ITEM_UNKNOWN; - do - { - SfxItemArray ppFnd = pAktSet->_aItems; - const sal_uInt16* pPtr = pAktSet->_pWhichRanges; - if (pPtr) - { - while ( *pPtr ) - { - if ( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // in diesem Bereich - ppFnd += nWhich - *pPtr; - if ( !*ppFnd ) - { - eRet = SFX_ITEM_DEFAULT; - if( !bSrchInParent ) - return eRet; // nicht vorhanden - break; // JP: in den Parents weitersuchen !!! - } - - if ( (SfxPoolItem*) -1 == *ppFnd ) - // Unterschiedlich vorhanden - return SFX_ITEM_DONTCARE; - - if ( (*ppFnd)->Type() == TYPE(SfxVoidItem) ) - return SFX_ITEM_DISABLED; - - if (ppItem) - { - #ifdef DBG_UTIL - const SfxPoolItem *pItem = *ppFnd; - DBG_ASSERT( !pItem->ISA(SfxSetItem) || - 0 != &((const SfxSetItem*)pItem)->GetItemSet(), - "SetItem without ItemSet" ); - #endif - *ppItem = *ppFnd; - } - return SFX_ITEM_SET; - } - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } - } - } while( bSrchInParent && 0 != ( pAktSet = pAktSet->_pParent )); - return eRet; -} - -// ----------------------------------------------------------------------- - -const SfxPoolItem* SfxItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT( !rItem.ISA(SfxSetItem) || - 0 != &((const SfxSetItem&)rItem).GetItemSet(), - "SetItem without ItemSet" ); - if ( !nWhich ) - return 0; //! nur wegen Outliner-Bug - SfxItemArray ppFnd = _aItems; - const sal_uInt16* pPtr = _pWhichRanges; - while( *pPtr ) - { - if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // in diesem Bereich - ppFnd += nWhich - *pPtr; - if( *ppFnd ) // schon einer vorhanden - { - // selbes Item bereits vorhanden? - if ( *ppFnd == &rItem ) - return 0; - - // wird dontcare oder disabled mit was echtem ueberschrieben? - if ( rItem.Which() && ( IsInvalidItem(*ppFnd) || !(*ppFnd)->Which() ) ) - { - *ppFnd = &_pPool->Put( rItem, nWhich ); - return *ppFnd; - } - - // wird disabled? - if( !rItem.Which() ) - { - *ppFnd = rItem.Clone(_pPool); - return 0; - } - else - { - // selber Wert bereits vorhanden? - if ( rItem == **ppFnd ) - return 0; - - // den neuen eintragen, den alten austragen - const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich ); - const SfxPoolItem* pOld = *ppFnd; - *ppFnd = &rNew; - if(nWhich <= SFX_WHICH_MAX) - Changed( *pOld, rNew ); - _pPool->Remove( *pOld ); - } - } - else - { - ++_nCount; - if( !rItem.Which() ) - *ppFnd = rItem.Clone(_pPool); - else { - const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich ); - *ppFnd = &rNew; - if (nWhich <= SFX_WHICH_MAX ) - { - const SfxPoolItem& rOld = _pParent - ? _pParent->Get( nWhich, sal_True ) - : _pPool->GetDefaultItem( nWhich ); - Changed( rOld, rNew ); - } - } - } - SFX_ASSERT( !_pPool->IsItemFlag(nWhich, SFX_ITEM_POOLABLE) || - rItem.ISA(SfxSetItem) || **ppFnd == rItem, - nWhich, "putted Item unequal" ); - return *ppFnd; - } - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } - return 0; -} - -// ----------------------------------------------------------------------- - -int SfxItemSet::Put( const SfxItemSet& rSet, sal_Bool bInvalidAsDefault ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - sal_Bool bRet = sal_False; - if( rSet.Count() ) - { - SfxItemArray ppFnd = rSet._aItems; - const sal_uInt16* pPtr = rSet._pWhichRanges; - while ( *pPtr ) - { - for ( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) - if( *ppFnd ) - { - if ( IsInvalidItem( *ppFnd ) ) - { - if ( bInvalidAsDefault ) - bRet |= 0 != ClearItem( nWhich ); - // gab GPF bei non.WIDs: - // bRet |= 0 != Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich ); - else - InvalidateItem( nWhich ); - } - else - bRet |= 0 != Put( **ppFnd, nWhich ); - } - pPtr += 2; - } - } - return bRet; -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::PutExtended -( - const SfxItemSet& rSet, // Quelle der zu puttenden Items - SfxItemState eDontCareAs, // was mit DontCare-Items passiert - SfxItemState eDefaultAs // was mit Default-Items passiert -) - -/* [Beschreibung] - - Diese Methode "ubernimmt die Items aus 'rSet' in '*this'. Die - Which-Bereiche in '*this', die in 'rSet' nicht vorkommen bleiben unver- - "andert. Der Which-Bereich von '*this' bleibt auch unver"andert. - - In 'rSet' gesetzte Items werden auch in '*this*' gesetzt. Default- - (0 Pointer) und Invalid- (-1 Pointer) Items werden je nach Parameter - ('eDontCareAs' und 'eDefaultAs' behandelt: - - SFX_ITEM_SET: hart auf Default des Pools gesetzt - SFX_ITEM_DEFAULT: gel"oscht (0 Pointer) - SFX_ITEM_DONTCARE: invalidiert (-1 Pointer) - - Alle anderen Werte f"ur 'eDontCareAs' und 'eDefaultAs' sind ung"ultig. -*/ - -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - - // don't "optimize" with "if( rSet.Count()" because of dont-care + defaults - SfxItemArray ppFnd = rSet._aItems; - const sal_uInt16* pPtr = rSet._pWhichRanges; - while ( *pPtr ) - { - for ( sal_uInt16 nWhich = *pPtr; nWhich <= *(pPtr+1); ++nWhich, ++ppFnd ) - if( *ppFnd ) - { - if ( IsInvalidItem( *ppFnd ) ) - { - // Item ist DontCare: - switch ( eDontCareAs ) - { - case SFX_ITEM_SET: - Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich ); - break; - - case SFX_ITEM_DEFAULT: - ClearItem( nWhich ); - break; - - case SFX_ITEM_DONTCARE: - InvalidateItem( nWhich ); - break; - - default: - OSL_FAIL( "invalid Argument for eDontCareAs" ); - } - } - else - // Item ist gesetzt: - Put( **ppFnd, nWhich ); - } - else - { - // Item ist Default: - switch ( eDefaultAs ) - { - case SFX_ITEM_SET: - Put( rSet.GetPool()->GetDefaultItem(nWhich), nWhich ); - break; - - case SFX_ITEM_DEFAULT: - ClearItem( nWhich ); - break; - - case SFX_ITEM_DONTCARE: - InvalidateItem( nWhich ); - break; - - default: - OSL_FAIL( "invalid Argument for eDefaultAs" ); - } - } - pPtr += 2; - } -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::MergeRange( sal_uInt16 nFrom, sal_uInt16 nTo ) -/** <H3>Description</H3> - - Expands the ranges of settable items by 'nFrom' to 'nTo'. Keeps state of - items which are new ranges too. -*/ - -{ - // special case: exactly one sal_uInt16 which is already included? - if ( nFrom == nTo && SFX_ITEM_AVAILABLE <= GetItemState(nFrom, sal_False) ) - return; - - // merge new range - SfxUShortRanges aRanges( _pWhichRanges ); - aRanges += SfxUShortRanges( nFrom, nTo ); - SetRanges( aRanges ); -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::SetRanges( const sal_uInt16 *pNewRanges ) - -/** <H3>Description</H3> - - Modifies the ranges of settable items. Keeps state of items which - are new ranges too. -*/ - -{ - // identische Ranges? - if ( _pWhichRanges == pNewRanges ) - return; - const sal_uInt16* pOld = _pWhichRanges; - const sal_uInt16* pNew = pNewRanges; - while ( *pOld == *pNew ) - { - if ( !*pOld && !*pNew ) - return; - ++pOld, ++pNew; - } - - // create new item-array (by iterating through all new ranges) - sal_uLong nSize = Capacity_Impl(pNewRanges); - SfxItemArray aNewItems = new const SfxPoolItem* [ nSize ]; - sal_uInt16 n = 0, nNewCount = 0; - if ( _nCount == 0 ) - memset( aNewItems, 0, nSize * sizeof( SfxPoolItem* ) ); - else - { - for ( const sal_uInt16 *pRange = pNewRanges; *pRange; pRange += 2 ) - { - // iterate through all ids in the range - for ( sal_uInt16 nWID = *pRange; nWID <= pRange[1]; ++nWID, ++n ) - { - // direct move of pointer (not via pool) - SfxItemState eState = GetItemState( nWID, sal_False, aNewItems+n ); - if ( SFX_ITEM_SET == eState ) - { - // increment new item count and possibly increment ref count - ++nNewCount; - aNewItems[n]->AddRef(); - } - else if ( SFX_ITEM_DISABLED == eState ) - { - // put "disabled" item - ++nNewCount; - aNewItems[n] = new SfxVoidItem(0); - } - else if ( SFX_ITEM_DONTCARE == eState ) - { - ++nNewCount; - aNewItems[n] = (SfxPoolItem*)-1; - } - else - { - // default - aNewItems[n] = 0; - } - } - } - // free old items - sal_uInt16 nOldTotalCount = TotalCount(); - for ( sal_uInt16 nItem = 0; nItem < nOldTotalCount; ++nItem ) - { - const SfxPoolItem *pItem = _aItems[nItem]; - if ( pItem && !IsInvalidItem(pItem) && pItem->Which() ) - _pPool->Remove(*pItem); - } - } - - // replace old items-array and ranges - delete[] _aItems; - _aItems = aNewItems; - _nCount = nNewCount; - - if( pNewRanges == GetPool()->GetFrozenIdRanges() ) - { - delete[] _pWhichRanges; - _pWhichRanges = ( sal_uInt16* ) pNewRanges; - } - else - { - sal_uInt16 nCount = Count_Impl(pNewRanges) + 1; - if ( _pWhichRanges != _pPool->GetFrozenIdRanges() ) - delete[] _pWhichRanges; - _pWhichRanges = new sal_uInt16[ nCount ]; - memcpy( _pWhichRanges, pNewRanges, sizeof( sal_uInt16 ) * nCount ); - } -} - -// ----------------------------------------------------------------------- - -int SfxItemSet::Set -( - const SfxItemSet& rSet, /* das SfxItemSet, dessen SfxPoolItems - "ubernommen werden sollen */ - - sal_Bool bDeep /* sal_True (default) - auch die SfxPoolItems aus den ggf. an - rSet vorhandenen Parents werden direkt - in das SfxItemSet "ubernommen - - sal_False - die SfxPoolItems aus den Parents von - rSet werden nicht ber"ucksichtigt */ -) - -/* [Beschreibung] - - Das SfxItemSet nimmt genau die SfxPoolItems an, die auch in - rSet gesetzt sind und im eigenen <Which-Bereich> liegen. Alle - anderen werden entfernt. Der SfxItemPool wird dabei beibehalten, - so da"s die "ubernommenen SfxPoolItems dabei ggf. vom SfxItemPool - von rSet in den SfxItemPool von *this "ubernommen werden. - - SfxPoolItems, f"ur die in rSet IsInvalidItem() == sal_True gilt, - werden als Invalid-Item "ubernommen. - - - [R"uckgabewert] - - int sal_True - es wurden SfxPoolItems "ubernommen - - sal_False - es wurden keine SfxPoolItems "ubernommen, - da z.B. die Which-Bereiche der SfxItemSets - keine Schnittmenge haben oder in der - Schnittmenge keine SfxPoolItems in rSet - gesetzt sind - -*/ - -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - int bRet = sal_False; - if ( _nCount ) - ClearItem(); - if ( bDeep ) - { - SfxWhichIter aIter(*this); - sal_uInt16 nWhich = aIter.FirstWhich(); - while ( nWhich ) - { - const SfxPoolItem* pItem; - if( SFX_ITEM_SET == rSet.GetItemState( nWhich, sal_True, &pItem ) ) - bRet |= 0 != Put( *pItem, pItem->Which() ); - nWhich = aIter.NextWhich(); - } - } - else - bRet = Put(rSet, sal_False); - - return bRet; -} - -//------------------------------------------------------------------------ - -const SfxPoolItem* SfxItemSet::GetItem -( - sal_uInt16 nId, // Slot-Id oder Which-Id des Items - sal_Bool bSrchInParent, // sal_True: auch in Parent-ItemSets suchen - TypeId aItemType // != 0 => RTTI Pruefung mit Assertion -) const - -/* [Beschreibung] - - Mit dieser Methode wird der Zugriff auf einzelne Items im - SfxItemSet wesentlich vereinfacht. Insbesondere wird die Typpr"ufung - (per Assertion) durchgef"uhrt, wodurch die Applikations-Sourcen - wesentlich "ubersichtlicher werden. In der PRODUCT-Version wird - eine 0 zur"uckgegeben, wenn das gefundene Item nicht von der - angegebenen Klasse ist. Ist kein Item mit der Id 'nWhich' in dem ItemSet, - so wird 0 zurueckgegeben. -*/ - -{ - // ggf. in Which-Id umrechnen - sal_uInt16 nWhich = GetPool()->GetWhich(nId); - - // ist das Item gesetzt oder bei bDeep==sal_True verf"ugbar? - const SfxPoolItem *pItem = 0; - SfxItemState eState = GetItemState( nWhich, bSrchInParent, &pItem ); - if ( bSrchInParent && SFX_ITEM_AVAILABLE == eState && - nWhich <= SFX_WHICH_MAX ) - pItem = &_pPool->GetDefaultItem(nWhich); - if ( pItem ) - { - // stimmt der Typ "uberein? - if ( !aItemType || pItem->IsA(aItemType) ) - return pItem; - - // sonst Fehler melden - OSL_FAIL( "invalid argument type" ); - } - - // kein Item gefunden oder falschen Typ gefunden - return 0; -} - - -//------------------------------------------------------------------------ - - -const SfxPoolItem& SfxItemSet::Get( sal_uInt16 nWhich, sal_Bool bSrchInParent) const -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - // suche den Bereich in dem das Which steht: - const SfxItemSet* pAktSet = this; - do - { - if( pAktSet->Count() ) - { - SfxItemArray ppFnd = pAktSet->_aItems; - const sal_uInt16* pPtr = pAktSet->_pWhichRanges; - while( *pPtr ) - { - if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // in diesem Bereich - ppFnd += nWhich - *pPtr; - if( *ppFnd ) - { - if( (SfxPoolItem*)-1 == *ppFnd ) { - //?MI: folgender code ist Doppelt (unten) - SFX_ASSERT(_pPool, nWhich, "kein Pool, aber Status uneindeutig"); - //!((SfxAllItemSet *)this)->aDefault.SetWhich(nWhich); - //!return aDefault; - return _pPool->GetDefaultItem( nWhich ); - } -#ifdef DBG_UTIL - const SfxPoolItem *pItem = *ppFnd; - DBG_ASSERT( !pItem->ISA(SfxSetItem) || - 0 != &((const SfxSetItem*)pItem)->GetItemSet(), - "SetItem without ItemSet" ); - if ( pItem->ISA(SfxVoidItem) || !pItem->Which() ) - DBG_WARNING( "SFX_WARNING: Getting disabled Item" ); -#endif - return **ppFnd; - } - break; // dann beim Parent suchen - } - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } - } -// bis zum Ende vom Such-Bereich: was nun ? zum Parent, oder Default ?? -// if( !*pPtr ) // bis zum Ende vom Such-Bereich ? -// break; - } while( bSrchInParent && 0 != ( pAktSet = pAktSet->_pParent )); - - // dann das Default vom Pool holen und returnen - SFX_ASSERT(_pPool, nWhich, "kein Pool, aber Status uneindeutig"); - const SfxPoolItem *pItem = &_pPool->GetDefaultItem( nWhich ); - DBG_ASSERT( !pItem->ISA(SfxSetItem) || - 0 != &((const SfxSetItem*)pItem)->GetItemSet(), - "SetItem without ItemSet" ); - return *pItem; -} - - // Notification-Callback -// ----------------------------------------------------------------------- - -void SfxItemSet::Changed( const SfxPoolItem&, const SfxPoolItem& ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemSet::TotalCount() const -{ - DBG_CHKTHIS(SfxItemSet, 0); // wird im Ctor benutzt bevor vollst. init. - sal_uInt16 nRet = 0; - sal_uInt16* pPtr = _pWhichRanges; - while( *pPtr ) - { - nRet += ( *(pPtr+1) - *pPtr ) + 1; - pPtr += 2; - } - return nRet; -} -// ----------------------------------------------------------------------- - -// behalte nur die Items, die auch in rSet enthalten sein (Wert egal) - -void SfxItemSet::Intersect( const SfxItemSet& rSet ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT(_pPool, "nicht implementiert ohne Pool"); - if( !Count() ) // gar keine gesetzt ? - return; - - // loesche alle Items, die im rSet nicht mehr vorhanden sind - if( !rSet.Count() ) - { - ClearItem(); // alles loeschen - return; - } - - // teste mal, ob sich die Which-Bereiche unterscheiden. - sal_Bool bEqual = sal_True; - sal_uInt16* pWh1 = _pWhichRanges; - sal_uInt16* pWh2 = rSet._pWhichRanges; - sal_uInt16 nSize = 0; - - for( sal_uInt16 n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n ) - { - if( *pWh1 != *pWh2 ) - { - bEqual = sal_False; - break; - } - if( n & 1 ) - nSize += ( *(pWh1) - *(pWh1-1) ) + 1; - } - bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen - - // sind die Bereiche identisch, ist es einfacher zu handhaben ! - if( bEqual ) - { - SfxItemArray ppFnd1 = _aItems; - SfxItemArray ppFnd2 = rSet._aItems; - - for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 ) - if( *ppFnd1 && !*ppFnd2 ) - { - // aus dem Pool loeschen - if( !IsInvalidItem( *ppFnd1 ) ) - { - sal_uInt16 nWhich = (*ppFnd1)->Which(); - if(nWhich <= SFX_WHICH_MAX) - { - const SfxPoolItem& rNew = _pParent - ? _pParent->Get( nWhich, sal_True ) - : _pPool->GetDefaultItem( nWhich ); - - Changed( **ppFnd1, rNew ); - } - _pPool->Remove( **ppFnd1 ); - } - *ppFnd1 = 0; - --_nCount; - } - } - else - { - SfxItemIter aIter( *this ); - const SfxPoolItem* pItem = aIter.GetCurItem(); - while( sal_True ) - { - sal_uInt16 nWhich = IsInvalidItem( pItem ) - ? GetWhichByPos( aIter.GetCurPos() ) - : pItem->Which(); - if( 0 == rSet.GetItemState( nWhich, sal_False ) ) - ClearItem( nWhich ); // loeschen - if( aIter.IsAtEnd() ) - break; - pItem = aIter.NextItem(); - } - } -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::Differentiate( const SfxItemSet& rSet ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - if( !Count() || !rSet.Count() ) // gar keine gesetzt ? - return; - - // teste mal, ob sich die Which-Bereiche unterscheiden. - sal_Bool bEqual = sal_True; - sal_uInt16* pWh1 = _pWhichRanges; - sal_uInt16* pWh2 = rSet._pWhichRanges; - sal_uInt16 nSize = 0; - - for( sal_uInt16 n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n ) - { - if( *pWh1 != *pWh2 ) - { - bEqual = sal_False; - break; - } - if( n & 1 ) - nSize += ( *(pWh1) - *(pWh1-1) ) + 1; - } - bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen - - // sind die Bereiche identisch, ist es einfacher zu handhaben ! - if( bEqual ) - { - SfxItemArray ppFnd1 = _aItems; - SfxItemArray ppFnd2 = rSet._aItems; - - for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 ) - if( *ppFnd1 && *ppFnd2 ) - { - // aus dem Pool loeschen - if( !IsInvalidItem( *ppFnd1 ) ) - { - sal_uInt16 nWhich = (*ppFnd1)->Which(); - if(nWhich <= SFX_WHICH_MAX) - { - const SfxPoolItem& rNew = _pParent - ? _pParent->Get( nWhich, sal_True ) - : _pPool->GetDefaultItem( nWhich ); - - Changed( **ppFnd1, rNew ); - } - _pPool->Remove( **ppFnd1 ); - } - *ppFnd1 = 0; - --_nCount; - } - } - else - { - SfxItemIter aIter( *this ); - const SfxPoolItem* pItem = aIter.GetCurItem(); - while( sal_True ) - { - sal_uInt16 nWhich = IsInvalidItem( pItem ) - ? GetWhichByPos( aIter.GetCurPos() ) - : pItem->Which(); - if( SFX_ITEM_SET == rSet.GetItemState( nWhich, sal_False ) ) - ClearItem( nWhich ); // loeschen - if( aIter.IsAtEnd() ) - break; - pItem = aIter.NextItem(); - } - - } -} - -// ----------------------------------------------------------------------- -/* Entscheidungstabelle fuer MergeValue[s] - -Grundsaetze: - 1. Ist der Which-Wert im 1.Set "unknown", dann folgt niemals eine Aktion. - 2. Ist der Which-Wert im 2.Set "unknown", dann gilt er als "default". - 3. Es gelten fuer Vergleiche die Werte der "default"-Items. - -1.-Item 2.-Item Values bIgnoreDefs Remove Assign Add - -set set == sal_False - - - -default set == sal_False - - - -dontcare set == sal_False - - - -unknown set == sal_False - - - -set default == sal_False - - - -default default == sal_False - - - -dontcare default == sal_False - - - -unknown default == sal_False - - - -set dontcare == sal_False 1.-Item -1 - -default dontcare == sal_False - -1 - -dontcare dontcare == sal_False - - - -unknown dontcare == sal_False - - - -set unknown == sal_False 1.-Item -1 - -default unknown == sal_False - - - -dontcare unknown == sal_False - - - -unknown unknown == sal_False - - - - -set set != sal_False 1.-Item -1 - -default set != sal_False - -1 - -dontcare set != sal_False - - - -unknown set != sal_False - - - -set default != sal_False 1.-Item -1 - -default default != sal_False - - - -dontcare default != sal_False - - - -unknown default != sal_False - - - -set dontcare != sal_False 1.-Item -1 - -default dontcare != sal_False - -1 - -dontcare dontcare != sal_False - - - -unknown dontcare != sal_False - - - -set unknown != sal_False 1.-Item -1 - -default unknown != sal_False - - - -dontcare unknown != sal_False - - - -unknown unknown != sal_False - - - - -set set == sal_True - - - -default set == sal_True - 2.-Item 2.-Item -dontcare set == sal_True - - - -unknown set == sal_True - - - -set default == sal_True - - - -default default == sal_True - - - -dontcare default == sal_True - - - -unknown default == sal_True - - - -set dontcare == sal_True - - - -default dontcare == sal_True - -1 - -dontcare dontcare == sal_True - - - -unknown dontcare == sal_True - - - -set unknown == sal_True - - - -default unknown == sal_True - - - -dontcare unknown == sal_True - - - -unknown unknown == sal_True - - - - -set set != sal_True 1.-Item -1 - -default set != sal_True - 2.-Item 2.-Item -dontcare set != sal_True - - - -unknown set != sal_True - - - -set default != sal_True - - - -default default != sal_True - - - -dontcare default != sal_True - - - -unknown default != sal_True - - - -set dontcare != sal_True 1.-Item -1 - -default dontcare != sal_True - -1 - -dontcare dontcare != sal_True - - - -unknown dontcare != sal_True - - - -set unknown != sal_True - - - -default unknown != sal_True - - - -dontcare unknown != sal_True - - - -unknown unknown != sal_True - - - -*/ - - -static void MergeItem_Impl( SfxItemPool *_pPool, sal_uInt16 &rCount, - const SfxPoolItem **ppFnd1, const SfxPoolItem *pFnd2, - sal_Bool bIgnoreDefaults ) -{ - DBG_ASSERT( ppFnd1 != 0, "Merging to 0-Item" ); - - // 1. Item ist default? - if ( !*ppFnd1 ) - { - if ( IsInvalidItem(pFnd2) ) - // Entscheidungstabelle: default, dontcare, egal, egal - *ppFnd1 = (SfxPoolItem*) -1; - - else if ( pFnd2 && !bIgnoreDefaults && - _pPool->GetDefaultItem(pFnd2->Which()) != *pFnd2 ) - // Entscheidungstabelle: default, set, !=, sal_False - *ppFnd1 = (SfxPoolItem*) -1; - - else if ( pFnd2 && bIgnoreDefaults ) - // Entscheidungstabelle: default, set, egal, sal_True - *ppFnd1 = &_pPool->Put( *pFnd2 ); - - if ( *ppFnd1 ) - ++rCount; - } - - // 1. Item ist gesetzt? - else if ( !IsInvalidItem(*ppFnd1) ) - { - if ( !pFnd2 ) - { - // 2. Item ist default - if ( !bIgnoreDefaults && - **ppFnd1 != _pPool->GetDefaultItem((*ppFnd1)->Which()) ) - { - // Entscheidungstabelle: set, default, !=, sal_False - _pPool->Remove( **ppFnd1 ); - *ppFnd1 = (SfxPoolItem*) -1; - } - } - else if ( IsInvalidItem(pFnd2) ) - { - // 2. Item ist dontcare - if ( !bIgnoreDefaults || - **ppFnd1 != _pPool->GetDefaultItem( (*ppFnd1)->Which()) ) - { - // Entscheidungstabelle: set, dontcare, egal, sal_False - // oder: set, dontcare, !=, sal_True - _pPool->Remove( **ppFnd1 ); - *ppFnd1 = (SfxPoolItem*) -1; - } - } - else - { - // 2. Item ist gesetzt - if ( **ppFnd1 != *pFnd2 ) - { - // Entscheidungstabelle: set, set, !=, egal - _pPool->Remove( **ppFnd1 ); - *ppFnd1 = (SfxPoolItem*) -1; - } - } - } -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::MergeValues( const SfxItemSet& rSet, sal_Bool bIgnoreDefaults ) -{ - // Achtung!!! Bei Aenderungen/Bugfixes immer obenstehende Tabelle pflegen! - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT( GetPool() == rSet.GetPool(), "MergeValues mit verschiedenen Pools" ); - - // teste mal, ob sich die Which-Bereiche unterscheiden. - sal_Bool bEqual = sal_True; - sal_uInt16* pWh1 = _pWhichRanges; - sal_uInt16* pWh2 = rSet._pWhichRanges; - sal_uInt16 nSize = 0; - - for( sal_uInt16 n = 0; *pWh1 && *pWh2; ++pWh1, ++pWh2, ++n ) - { - if( *pWh1 != *pWh2 ) - { - bEqual = sal_False; - break; - } - if( n & 1 ) - nSize += ( *(pWh1) - *(pWh1-1) ) + 1; - } - bEqual = *pWh1 == *pWh2; // auch die 0 abpruefen - - // sind die Bereiche identisch, ist es effizieter zu handhaben ! - if( bEqual ) - { - SfxItemArray ppFnd1 = _aItems; - SfxItemArray ppFnd2 = rSet._aItems; - - for( ; nSize; --nSize, ++ppFnd1, ++ppFnd2 ) - MergeItem_Impl( _pPool, _nCount, ppFnd1, *ppFnd2, bIgnoreDefaults ); - } - else - { - SfxWhichIter aIter( rSet ); - register sal_uInt16 nWhich; - while( 0 != ( nWhich = aIter.NextWhich() ) ) - { - const SfxPoolItem* pItem = 0; - rSet.GetItemState( nWhich, sal_True, &pItem ); - if( !pItem ) - { - // nicht gesetzt, also default - if ( !bIgnoreDefaults ) - MergeValue( rSet.GetPool()->GetDefaultItem( nWhich ), bIgnoreDefaults ); - } - else if( IsInvalidItem( pItem ) ) - // dont care - InvalidateItem( nWhich ); - else - MergeValue( *pItem, bIgnoreDefaults ); - } - } -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::MergeValue( const SfxPoolItem& rAttr, sal_Bool bIgnoreDefaults ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - SfxItemArray ppFnd = _aItems; - const sal_uInt16* pPtr = _pWhichRanges; - const sal_uInt16 nWhich = rAttr.Which(); - while( *pPtr ) - { - // in diesem Bereich? - if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - ppFnd += nWhich - *pPtr; - MergeItem_Impl( _pPool, _nCount, ppFnd, &rAttr, bIgnoreDefaults ); - break; - } - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } -} - -// ----------------------------------------------------------------------- - -void SfxItemSet::InvalidateItem( sal_uInt16 nWhich ) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - SfxItemArray ppFnd = _aItems; - const sal_uInt16* pPtr = _pWhichRanges; - while( *pPtr ) - { - if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // in diesem Bereich - ppFnd += nWhich - *pPtr; - - if( *ppFnd ) // bei mir gesetzt - { - if( (SfxPoolItem*)-1 != *ppFnd ) // noch nicht dontcare ! - { - _pPool->Remove( **ppFnd ); - *ppFnd = (SfxPoolItem*)-1; - } - } - else - { - *ppFnd = (SfxPoolItem*)-1; - ++_nCount; - } - break; - } - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemSet::GetWhichByPos( sal_uInt16 nPos ) const -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - sal_uInt16 n = 0; - sal_uInt16* pPtr = _pWhichRanges; - while( *pPtr ) - { - n = ( *(pPtr+1) - *pPtr ) + 1; - if( nPos < n ) - return *(pPtr)+nPos; - nPos = nPos - n; - pPtr += 2; - } - DBG_ASSERT( sal_False, "Hier sind wir falsch" ); - return 0; -} - -// ----------------------------------------------------------------------- - -SvStream &SfxItemSet::Store -( - SvStream& rStream, // Zielstream f"ur normale Items - bool bDirect // TRUE: Items direkt speicher, FALSE: Surrogate -) const - -/* [Beschreibung] - - Speichert die <SfxItemSet>-Instanz in den angegebenen Stream. Dabei - werden die Surrorage der gesetzten <SfxPoolItem>s bzw. ('bDirect==sal_True') - die gesetzten Items selbst wie folgt im Stream abgelegt: - - sal_uInt16 (Count) Anzahl der gesetzten Items - Count* _pPool->StoreItem() siehe <SfxItemPool::StoreItem()const> - - - [Querverweise] - - <SfxItemSet::Load(SvStream&,sal_Bool,const SfxItemPool*)> -*/ - -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT( _pPool, "Kein Pool" ); - DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "kein Master-Pool" ); - - // Position des Counts merken, um ggf. zu korrigieren - sal_uLong nCountPos = rStream.Tell(); - rStream << _nCount; - - // wenn nichts zu speichern ist, auch keinen ItemIter aufsetzen! - if ( _nCount ) - { - // mitz"ahlen wieviel Items tats"achlich gespeichert werden - sal_uInt16 nWrittenCount = 0; // Anzahl in 'rStream' gestreamter Items - - // "uber alle gesetzten Items iterieren - SfxItemIter aIter(*this); - for ( const SfxPoolItem *pItem = aIter.FirstItem(); - pItem; - pItem = aIter.NextItem() ) - { - // Item (ggf. als Surrogat) via Pool speichern lassen - DBG_ASSERT( !IsInvalidItem(pItem), "can't store invalid items" ); - if ( !IsInvalidItem(pItem) && - _pPool->StoreItem( rStream, *pItem, bDirect ) ) - // Item wurde in 'rStream' gestreamt - ++nWrittenCount; - }; - - // weniger geschrieben als enthalten (z.B. altes Format) - if ( nWrittenCount != _nCount ) - { - // tats"achlichen Count im Stream ablegen - sal_uLong nPos = rStream.Tell(); - rStream.Seek( nCountPos ); - rStream << nWrittenCount; - rStream.Seek( nPos ); - } - } - - return rStream; -} - -// ----------------------------------------------------------------------- - -SvStream &SfxItemSet::Load -( - SvStream& rStream, // Stream, aus dem geladen werden soll - - bool bDirect, /* TRUE - Items werden direkt aus dem Stream - gelesen, nicht "uber Surrogate - - sal_False (default) - Items werden "uber Surrogate gelesen */ - - const SfxItemPool* pRefPool /* Pool, der die Surrogate aufl"osen kann - (z.B. zum Einf"ugen von Dokumenten) */ -) - -/* [Beschreibung] - - Diese Methode l"adt ein <SfxItemSet> aus einem Stream. Falls der - <SfxItemPool> ohne Ref-Counts geladen wurde, werden die geladenen - Item-Referenzen in den Items hochgez"ahlt, ansonsten wird vorausgesetzt, - da\s sie schon beim Laden des SfxItemPools ber"ucksichtigt waren. - - [Querverweise] - - <SfxItemSet::Store(Stream&,sal_Bool)const> -*/ - -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - DBG_ASSERT( _pPool, "Kein Pool"); - DBG_ASSERTWARNING( _pPool == _pPool->GetMasterPool(), "Kein Master-Pool"); - - // kein Ref-Pool => Surrogate mit Pool des ItemSets aufl"osen - if ( !pRefPool ) - pRefPool = _pPool; - - // Anzahl der zu ladenden Items laden und dann ebensoviele Items - sal_uInt16 nCount = 0; - rStream >> nCount; - for ( sal_uInt16 i = 0; i < nCount; ++i ) - { - // Surrogat/Item laden und (Surrogat) aufl"osen lassen - const SfxPoolItem *pItem = - _pPool->LoadItem( rStream, bDirect, pRefPool ); - - // konnte ein Item geladen oder via Surrogat aufgel"ost werden? - if ( pItem ) - { - // Position f"ur Item-Pointer im Set suchen - sal_uInt16 nWhich = pItem->Which(); - SfxItemArray ppFnd = _aItems; - const sal_uInt16* pPtr = _pWhichRanges; - while ( *pPtr ) - { - // in diesem Bereich? - if ( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // Item-Pointer im Set merken - ppFnd += nWhich - *pPtr; - SFX_ASSERT( !*ppFnd, nWhich, "Item doppelt eingetragen"); - *ppFnd = pItem; - ++_nCount; - break; - } - - // im Range-Array und Item-Array zum n"achsten Which-Range - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } - } - } - - return rStream; -} - -// ----------------------------------------------------------------------- - -int SfxItemSet::operator==(const SfxItemSet &rCmp) const -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - DBG_CHKOBJ(&rCmp, SfxItemSet, DbgCheckItemSet); - - // besonders schnell zu ermittelnde Werte muessen gleich sein - if ( _pParent != rCmp._pParent || - _pPool != rCmp._pPool || - Count() != rCmp.Count() ) - return sal_False; - - // Ranges durchzaehlen lassen dauert laenger, muss aber auch gleich sein - sal_uInt16 nCount1 = TotalCount(); - sal_uInt16 nCount2 = rCmp.TotalCount(); - if ( nCount1 != nCount2 ) - return sal_False; - - // sind die Ranges selbst ungleich? - for ( sal_uInt16 nRange = 0; _pWhichRanges[nRange]; nRange += 2 ) - if ( _pWhichRanges[nRange] != rCmp._pWhichRanges[nRange] || - _pWhichRanges[nRange+1] != rCmp._pWhichRanges[nRange+1] ) - { - // dann m"ussen wir die langsame Methode verwenden - SfxWhichIter aIter( *this ); - for ( sal_uInt16 nWh = aIter.FirstWhich(); - nWh; - nWh = aIter.NextWhich() ) - { - // wenn die Pointer von poolable Items ungleich sind, - // muessen die Items gleich sein - const SfxPoolItem *pItem1 = 0, *pItem2 = 0; - if ( GetItemState( nWh, sal_False, &pItem1 ) != - rCmp.GetItemState( nWh, sal_False, &pItem2 ) || - ( pItem1 != pItem2 && - ( !pItem1 || IsInvalidItem(pItem1) || - ( _pPool->IsItemFlag(*pItem1, SFX_ITEM_POOLABLE) && - *pItem1 != *pItem2 ) ) ) ) - return sal_False; - } - - return sal_True; - } - - // Pointer alle gleich? - if ( 0 == memcmp( _aItems, rCmp._aItems, nCount1 * sizeof(_aItems[0]) ) ) - return sal_True; - - // dann werden wir wohl alle einzeln vergleichen muessen - const SfxPoolItem **ppItem1 = (const SfxPoolItem**) _aItems; - const SfxPoolItem **ppItem2 = (const SfxPoolItem**) rCmp._aItems; - for ( sal_uInt16 nPos = 0; nPos < nCount1; ++nPos ) - { - // wenn die Pointer von poolable Items ungleich sind, - // muessen die Items gleich sein - if ( *ppItem1 != *ppItem2 && - ( ( !*ppItem1 || !*ppItem2 ) || - ( IsInvalidItem(*ppItem1) || IsInvalidItem(*ppItem2) ) || - ( _pPool->IsItemFlag(**ppItem1, SFX_ITEM_POOLABLE) ) || - **ppItem1 != **ppItem2 ) ) - return sal_False; - - ++ppItem1; - ++ppItem2; - } - - return sal_True; -} - -// ----------------------------------------------------------------------- - -SfxItemSet *SfxItemSet::Clone(sal_Bool bItems, SfxItemPool *pToPool ) const -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - if ( pToPool && pToPool != _pPool ) - { - SfxItemSet *pNewSet = new SfxItemSet( *pToPool, _pWhichRanges ); - if ( bItems ) - { - SfxWhichIter aIter(*pNewSet); - sal_uInt16 nWhich = aIter.FirstWhich(); - while ( nWhich ) - { - const SfxPoolItem* pItem; - if ( SFX_ITEM_SET == GetItemState( nWhich, sal_False, &pItem ) ) - pNewSet->Put( *pItem, pItem->Which() ); - nWhich = aIter.NextWhich(); - } - } - return pNewSet; - } - else - return bItems - ? new SfxItemSet(*this) - : new SfxItemSet(*_pPool, _pWhichRanges); -} - -// ----------------------------------------------------------------------- - -int SfxItemSet::PutDirect(const SfxPoolItem &rItem) -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - SfxItemArray ppFnd = _aItems; - const sal_uInt16* pPtr = _pWhichRanges; - const sal_uInt16 nWhich = rItem.Which(); -#ifdef DBG_UTIL - IsPoolDefaultItem(&rItem) || _pPool->GetSurrogate(&rItem); - // nur Assertion in den callees provozieren -#endif - while( *pPtr ) - { - if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // in diesem Bereich - ppFnd += nWhich - *pPtr; - const SfxPoolItem* pOld = *ppFnd; - if( pOld ) // schon einer vorhanden - { - if( rItem == **ppFnd ) - return sal_False; // schon vorhanden ! - _pPool->Remove( *pOld ); - } - else - ++_nCount; - - // den neuen eintragen - if( IsPoolDefaultItem(&rItem) ) - *ppFnd = &_pPool->Put( rItem ); - else - { - *ppFnd = &rItem; - if( !IsStaticDefaultItem( &rItem ) ) - rItem.AddRef(); - } - - return sal_True; - } - ppFnd += *(pPtr+1) - *pPtr + 1; - pPtr += 2; - } - return sal_False; -} - -// ----------------------------------------------------------------------- - -SfxAllItemSet::SfxAllItemSet( SfxItemPool &rPool ) -: SfxItemSet(rPool, (const sal_uInt16*) 0), - aDefault(0), - nFree(nInitCount) -{ - // initial keine Items - _aItems = 0; - - // nInitCount Paare an USHORTs fuer Ranges allozieren - _pWhichRanges = new sal_uInt16[ nInitCount + 1 ]; - memset( _pWhichRanges, 0, ( nInitCount + 1 ) * sizeof(sal_uInt16) ); -} - - -// ----------------------------------------------------------------------- - - -SfxAllItemSet::SfxAllItemSet(const SfxItemSet &rCopy) -: SfxItemSet(rCopy), - aDefault(0), - nFree(0) -{ -} - -// ----------------------------------------------------------------------- - - - -SfxAllItemSet::SfxAllItemSet(const SfxAllItemSet &rCopy) -: SfxItemSet(rCopy), - aDefault(0), - nFree(0) -/* [Anmerkung] - - Der mu\s sein, da sonst vom Compiler einer generiert wird, er nimmt - nicht den Ctor mit der 'const SfxItemSet&'! -*/ -{ -} - -// ----------------------------------------------------------------------- - -static sal_uInt16 *AddRanges_Impl( - sal_uInt16 *pUS, std::ptrdiff_t nOldSize, sal_uInt16 nIncr) - -/* Diese interne Funktion erzeugt ein neues Which-Range-Array, welches von - dem 'nOldSize'-USHORTs langen 'pUS' kopiert wird und hinten an Platz - f"ur 'nIncr' neue USHORTs hat. Das terminierende sal_uInt16 mit der '0' - wird weder in 'nOldSize' noch in 'nIncr' mitgez"ahlt, sondern implizit - hinzugerechnet. - - Das neue Which-Range-Array wird als Returnwert zur"uckgegeben, das alte - 'pUS' freigegeben. -*/ - -{ - // neues Which-Range-Array anlegen - sal_uInt16 *pNew = new sal_uInt16[ nOldSize + nIncr + 1 ]; - - // die alten Ranges "ubernehmen - memcpy( pNew, pUS, nOldSize * sizeof(sal_uInt16) ); - - // die neuen auf 0 initialisieren - memset( pNew + nOldSize, 0, ( nIncr + 1 ) * sizeof(sal_uInt16) ); - - // das alte Array freigeben - delete[] pUS; - - return pNew; -} - -// ----------------------------------------------------------------------- - -static SfxItemArray AddItem_Impl(SfxItemArray pItems, sal_uInt16 nOldSize, sal_uInt16 nPos) - -/* Diese interne Funktion erzeugt ein neues ItemArray, welches von 'pItems' - kopiert wird, an der Position 'nPos' jedoch Platz f"ur einen neuen - ItemPointer hat. - - Das neue ItemArray wird als Returnwert zur"uckgegeben, das alte 'pItems' - wird freigegeben. -*/ - -{ - // neues ItemArray anlegen - SfxItemArray pNew = new const SfxPoolItem*[nOldSize+1]; - - // war schon vorher eins da? - if ( pItems ) - { - // alte Items vor nPos kopieren - if ( nPos ) - memcpy( (void*) pNew, pItems, nPos * sizeof(SfxPoolItem *) ); - - // alte Items hinter nPos kopieren - if ( nPos < nOldSize ) - memcpy( (void*) (pNew + nPos + 1), pItems + nPos, - (nOldSize-nPos) * sizeof(SfxPoolItem *) ); - } - - // neues Item initialisieren - *(pNew + nPos) = 0; - - // altes ItemArray freigeben - delete[] pItems; - - return pNew; -} - -// ----------------------------------------------------------------------- - -const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhich ) - -// Putten mit automatischer Erweiterung der Whichs-Ids um die ID -// des Items. - -{ - sal_uInt16 nPos = 0; // Position f"ur 'rItem' in '_aItems' - const sal_uInt16 nItemCount = TotalCount(); - - // erstmal sehen, ob es schon einen passenden Bereich gibt - sal_uInt16 *pPtr = _pWhichRanges; - while ( *pPtr ) - { - // Which-Id liegt in diesem Bereich? - if( *pPtr <= nWhich && nWhich <= *(pPtr+1) ) - { - // Einfuegen - nPos += nWhich - *pPtr; - break; - } - - // Position des Items in _aItems mitf"uhren - nPos += *(pPtr+1) - *pPtr + 1; - - // zum n"achsten Bereich - pPtr += 2; - } - - // Which-Id noch nicht vorhanden? - if ( !*pPtr ) - { - // suchen, ob man sie irgendwo dranpacken kann - pPtr = _pWhichRanges; - nPos = 0; - while ( *pPtr ) - { - // Which-Id liegt exakt vor diesem Bereich? - if ( (nWhich+1) == *pPtr ) - { - // Bereich waechst nach unten - (*pPtr)--; - - // vor erstem Item dieses Bereichs Platz schaffen - _aItems = AddItem_Impl(_aItems, nItemCount, nPos); - break; - } - - // Which-Id liegt exakt hinter diesem Bereich? - else if ( (nWhich-1) == *(pPtr+1) ) - { - // Bereich waechst nach oben - (*(pPtr+1))++; - - // hinter letztem Item dieses Bereichs Platz schaffen - nPos += nWhich - *pPtr; - _aItems = AddItem_Impl(_aItems, nItemCount, nPos); - break; - } - - // Position des Items in _aItems mitf"uhren - nPos += *(pPtr+1) - *pPtr + 1; - - // zum n"achsten Bereich - pPtr += 2; - } - } - - // keinen erweiterbaren Bereich gefunden? - if ( !*pPtr ) - { - // kein Platz mehr in _pWhichRanges => erweitern - std::ptrdiff_t nSize = pPtr - _pWhichRanges; - if( !nFree ) - { - _pWhichRanges = AddRanges_Impl(_pWhichRanges, nSize, nInitCount); - nFree += nInitCount; - } - - // neuen Which-Range anh"angen - pPtr = _pWhichRanges + nSize; - *pPtr++ = nWhich; - *pPtr = nWhich; - nFree -= 2; - - // Itemarray vergroessern - nPos = nItemCount; - _aItems = AddItem_Impl(_aItems, nItemCount, nPos); - } - - // neues Item in Pool aufnehmen - const SfxPoolItem& rNew = _pPool->Put( rItem, nWhich ); - - // altes Item merken - sal_Bool bIncrementCount = sal_False; - const SfxPoolItem* pOld = *( _aItems + nPos ); - if ( reinterpret_cast< SfxPoolItem* >( -1 ) == pOld ) // state "dontcare" - pOld = NULL; - if ( !pOld ) - { - bIncrementCount = sal_True; - pOld = _pParent ? - &_pParent->Get( nWhich, sal_True ) - : nWhich <= SFX_WHICH_MAX ? &_pPool->GetDefaultItem( nWhich ) : 0; - } - - // neue Item in ItemSet aufnehmen - *(_aItems + nPos) = &rNew; - - // Changed Notification versenden - if ( pOld ) - { - Changed( *pOld, rNew ); - if ( !IsDefaultItem(pOld) ) - _pPool->Remove( *pOld ); - } - - if ( bIncrementCount ) - ++_nCount; - - return &rNew; -} - -// ----------------------------------------------------------------------- - - -/* Diese Methode wird forwarded, damit sie nicht durch die anderen - Put-Methoden dieser SubClass gehided wird. -*/ - -int SfxAllItemSet::Put( const SfxItemSet& rSet, sal_Bool bInvalidAsDefault ) -{ - //? pruefen, ob Which-Ranges erweitert werden - return SfxItemSet::Put( rSet, bInvalidAsDefault ); -} - -// ----------------------------------------------------------------------- -// Item disablen, wenn durch ein VoidItem mit dem Which-Wert 0 ausgedrueckt - -void SfxItemSet::DisableItem(sal_uInt16 nWhich) -{ - DBG_CHKTHIS(SfxItemSet, 0); - Put( SfxVoidItem(0), nWhich ); -} - -// ----------------------------------------------------------------------- - -SfxItemSet *SfxAllItemSet::Clone(sal_Bool bItems, SfxItemPool *pToPool ) const -{ - DBG_CHKTHIS(SfxItemSet, DbgCheckItemSet); - if ( pToPool && pToPool != _pPool ) - { - SfxAllItemSet *pNewSet = new SfxAllItemSet( *pToPool ); - if ( bItems ) - pNewSet->Set( *this ); - return pNewSet; - } - else - return bItems ? new SfxAllItemSet(*this) : new SfxAllItemSet(*_pPool); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/lckbitem.cxx b/svl/source/items/lckbitem.cxx deleted file mode 100644 index f22c6c4a09..0000000000 --- a/svl/source/items/lckbitem.cxx +++ /dev/null @@ -1,193 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#define _LCKBITEM_CXX -#include <svl/lckbitem.hxx> -#include <svl/poolitem.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/uno/Sequence.hxx> -#include <tools/cachestr.hxx> - -// STATIC DATA ----------------------------------------------------------- - - -// ----------------------------------------------------------------------- - -TYPEINIT1_AUTOFACTORY(SfxLockBytesItem, SfxPoolItem); - -// ----------------------------------------------------------------------- - -SfxLockBytesItem::SfxLockBytesItem() -{ -} - -// ----------------------------------------------------------------------- - -SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvLockBytes *pLockBytes ) -: SfxPoolItem( nW ), - _xVal( pLockBytes ) -{ -} - -// ----------------------------------------------------------------------- - -SfxLockBytesItem::SfxLockBytesItem( sal_uInt16 nW, SvStream &rStream ) -: SfxPoolItem( nW ) -{ - rStream.Seek( 0L ); - _xVal = new SvLockBytes( new SvCacheStream(), sal_True ); - - SvStream aLockBytesStream( _xVal ); - rStream >> aLockBytesStream; -} - -// ----------------------------------------------------------------------- - -SfxLockBytesItem::SfxLockBytesItem( const SfxLockBytesItem& rItem ) -: SfxPoolItem( rItem ), - _xVal( rItem._xVal ) -{ -} - -// ----------------------------------------------------------------------- - -SfxLockBytesItem::~SfxLockBytesItem() -{ -} - -// ----------------------------------------------------------------------- - -int SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const -{ - return ((SfxLockBytesItem&)rItem)._xVal == _xVal; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxLockBytesItem::Clone(SfxItemPool *) const -{ - return new SfxLockBytesItem( *this ); -} - -// ----------------------------------------------------------------------- - -#define MAX_BUF 32000 - -SfxPoolItem* SfxLockBytesItem::Create( SvStream &rStream, sal_uInt16 ) const -{ - sal_uInt32 nSize = 0; - sal_uLong nActRead = 0; - sal_Char cTmpBuf[MAX_BUF]; - SvMemoryStream aNewStream; - rStream >> nSize; - - do { - sal_uLong nToRead; - if( (nSize - nActRead) > MAX_BUF ) - nToRead = MAX_BUF; - else - nToRead = nSize - nActRead; - nActRead += rStream.Read( cTmpBuf, nToRead ); - aNewStream.Write( cTmpBuf, nToRead ); - } while( nSize > nActRead ); - - return new SfxLockBytesItem( Which(), aNewStream ); -} - -// ----------------------------------------------------------------------- - -SvStream& SfxLockBytesItem::Store(SvStream &rStream, sal_uInt16 ) const -{ - SvStream aLockBytesStream( _xVal ); - sal_uInt32 nSize = aLockBytesStream.Seek( STREAM_SEEK_TO_END ); - aLockBytesStream.Seek( 0L ); - - rStream << nSize; - rStream << aLockBytesStream; - - return rStream; -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxLockBytesItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) -{ - com::sun::star::uno::Sequence< sal_Int8 > aSeq; - if ( rVal >>= aSeq ) - { - if ( aSeq.getLength() ) - { - SvCacheStream* pStream = new SvCacheStream; - pStream->Write( (void*)aSeq.getConstArray(), aSeq.getLength() ); - pStream->Seek(0); - - _xVal = new SvLockBytes( pStream, sal_True ); - } - else - _xVal = NULL; - - return true; - } - - OSL_FAIL( "SfxLockBytesItem::PutValue - Wrong type!" ); - return true; -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxLockBytesItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const -{ - if ( _xVal.Is() ) - { - sal_uInt32 nLen; - SvLockBytesStat aStat; - - if ( _xVal->Stat( &aStat, SVSTATFLAG_DEFAULT ) == ERRCODE_NONE ) - nLen = aStat.nSize; - else - return false; - - sal_uLong nRead = 0; - com::sun::star::uno::Sequence< sal_Int8 > aSeq( nLen ); - - _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead ); - rVal <<= aSeq; - } - else - { - com::sun::star::uno::Sequence< sal_Int8 > aSeq( 0 ); - rVal <<= aSeq; - } - - return true; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/macitem.cxx b/svl/source/items/macitem.cxx deleted file mode 100644 index 60ca3a6bfd..0000000000 --- a/svl/source/items/macitem.cxx +++ /dev/null @@ -1,294 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/stream.hxx> - -#include <svl/macitem.hxx> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SvxMacroItem); - -// ----------------------------------------------------------------------- - -TYPEINIT1_FACTORY(SvxMacroItem, SfxPoolItem, new SvxMacroItem(0)); - -// ----------------------------------------------------------------------- - - -SjJSbxObjectBase::~SjJSbxObjectBase() -{ -} - -SjJSbxObjectBase* SjJSbxObjectBase::Clone( void ) -{ - return NULL; -} - -SvxMacro::SvxMacro( const String &rMacName, const String &rLanguage) - : aMacName( rMacName ), aLibName( rLanguage), - pFunctionObject(NULL), eType( EXTENDED_STYPE) -{ - if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_STARBASIC)) - eType=STARBASIC; - else if (rLanguage.EqualsAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT)) - eType=JAVASCRIPT; -} - - -SvxMacro::~SvxMacro() -{ - delete pFunctionObject; -} - -String SvxMacro::GetLanguage()const -{ - if(eType==STARBASIC) - { - return UniString::CreateFromAscii( - RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_STARBASIC)); - } - else if(eType==JAVASCRIPT) - { - return UniString::CreateFromAscii( - RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_JAVASCRIPT)); - } - else if(eType==EXTENDED_STYPE) - { - return UniString::CreateFromAscii( - RTL_CONSTASCII_STRINGPARAM(SVX_MACRO_LANGUAGE_SF)); - - } - return aLibName; -} - - - -SvxMacro& SvxMacro::operator=( const SvxMacro& rBase ) -{ - if( this != &rBase ) - { - aMacName = rBase.aMacName; - aLibName = rBase.aLibName; - delete pFunctionObject; - pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL; - eType = rBase.eType; - } - return *this; -} - - -SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl ) -{ - DelDtor(); - SvxMacro* pTmp = ((SvxMacroTableDtor&)rTbl).First(); - while( pTmp ) - { - SvxMacro *pNew = new SvxMacro( *pTmp ); - Insert( rTbl.GetCurKey(), pNew ); - pTmp = ((SvxMacroTableDtor&)rTbl).Next(); - } - return *this; -} - - -SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, sal_uInt16 nVersion ) -{ - if( SVX_MACROTBL_VERSION40 <= nVersion ) - rStrm >> nVersion; - short nMacro; - rStrm >> nMacro; - - for( short i = 0; i < nMacro; ++i ) - { - sal_uInt16 nCurKey, eType = STARBASIC; - String aLibName, aMacName; - rStrm >> nCurKey; - SfxPoolItem::readByteString(rStrm, aLibName); - SfxPoolItem::readByteString(rStrm, aMacName); - - if( SVX_MACROTBL_VERSION40 <= nVersion ) - rStrm >> eType; - - SvxMacro* pNew = new SvxMacro( aMacName, aLibName, (ScriptType)eType ); - - SvxMacro *pOld = Get( nCurKey ); - if( pOld ) - { - delete pOld; - Replace( nCurKey, pNew ); - } - else - Insert( nCurKey, pNew ); - } - return rStrm; -} - - -SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const -{ - sal_uInt16 nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion() - ? SVX_MACROTBL_VERSION31 - : SVX_MACROTBL_AKTVERSION; - - if( SVX_MACROTBL_VERSION40 <= nVersion ) - rStream << nVersion; - - rStream << (sal_uInt16)Count(); - - SvxMacro* pMac = ((SvxMacroTableDtor*)this)->First(); - while( pMac && rStream.GetError() == SVSTREAM_OK ) - { - rStream << (short)GetCurKey(); - SfxPoolItem::writeByteString(rStream, pMac->GetLibName()); - SfxPoolItem::writeByteString(rStream, pMac->GetMacName()); - - if( SVX_MACROTBL_VERSION40 <= nVersion ) - rStream << (sal_uInt16)pMac->GetScriptType(); - pMac = ((SvxMacroTableDtor*)this)->Next(); - } - return rStream; -} - -// ----------------------------------------------------------------------- - -void SvxMacroTableDtor::DelDtor() -{ - SvxMacro* pTmp = First(); - while( pTmp ) - { - delete pTmp; - pTmp = Next(); - } - Clear(); -} - -// ----------------------------------------------------------------------- - -int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const -{ - DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" ); - - const SvxMacroTableDtor& rOwn = aMacroTable; - const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable; - - // Anzahl unterschiedlich => auf jeden Fall ungleich - if ( rOwn.Count() != rOther.Count() ) - return sal_False; - - // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig - for ( sal_uInt16 nNo = 0; nNo < rOwn.Count(); ++nNo ) - { - const SvxMacro *pOwnMac = rOwn.GetObject(nNo); - const SvxMacro *pOtherMac = rOther.GetObject(nNo); - if ( rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac) || - pOwnMac->GetLibName() != pOtherMac->GetLibName() || - pOwnMac->GetMacName() != pOtherMac->GetMacName() ) - return sal_False; - } - - return sal_True; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const -{ - return new SvxMacroItem( *this ); -} - -//------------------------------------------------------------------------ - -SfxItemPresentation SvxMacroItem::GetPresentation -( - SfxItemPresentation /*ePres*/, - SfxMapUnit /*eCoreUnit*/, - SfxMapUnit /*ePresUnit*/, - XubString& rText, - const IntlWrapper * -) const -{ -/*!!! - SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable(); - SvxMacro* pMac = rTbl.First(); - - while ( pMac ) - { - rText += pMac->GetLibName(); - rText += cpDelim; - rText += pMac->GetMacName(); - pMac = rTbl.Next(); - if ( pMac ) - rText += cpDelim; - } -*/ - rText.Erase(); - return SFX_ITEM_PRESENTATION_NONE; -} - -// ----------------------------------------------------------------------- - -SvStream& SvxMacroItem::Store( SvStream& rStrm , sal_uInt16 ) const -{ - return aMacroTable.Write( rStrm ); -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const -{ - SvxMacroItem* pAttr = new SvxMacroItem( Which() ); - pAttr->aMacroTable.Read( rStrm, nVersion ); - return pAttr; -} - -// ----------------------------------------------------------------------- - -void SvxMacroItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro ) -{ - SvxMacro *pMacro; - if ( 0 != (pMacro=aMacroTable.Get(nEvent)) ) - { - delete pMacro; - aMacroTable.Replace(nEvent, new SvxMacro( rMacro ) ); - } - else - aMacroTable.Insert(nEvent, new SvxMacro( rMacro ) ); -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SvxMacroItem::GetVersion( sal_uInt16 nFileFormatVersion ) const -{ - return SOFFICE_FILEFORMAT_31 == nFileFormatVersion - ? 0 : aMacroTable.GetVersion(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/nranges.cxx b/svl/source/items/nranges.cxx deleted file mode 100644 index b1206f5df2..0000000000 --- a/svl/source/items/nranges.cxx +++ /dev/null @@ -1,795 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -// compiled via include from itemset.cxx only! - -//======================================================================== - -#ifdef DBG_UTIL - -#define DBG_CHECK_RANGES(NUMTYPE, pArr) \ - for ( const NUMTYPE *pRange = pArr; *pRange; pRange += 2 ) \ - { \ - DBG_ASSERT( pRange[0] <= pRange[1], "ranges must be sorted" ); \ - DBG_ASSERT( !pRange[2] || ( pRange[2] - pRange[1] ) > 1, \ - "ranges must be sorted and discrete" ); \ - } - -#else - -#define DBG_CHECK_RANGES(NUMTYPE,pArr) - -#endif - -//============================================================================ -inline void Swap_Impl(const NUMTYPE *& rp1, const NUMTYPE *& rp2) -{ - const NUMTYPE * pTemp = rp1; - rp1 = rp2; - rp2 = pTemp; -} - -//======================================================================== - -NUMTYPE InitializeRanges_Impl( NUMTYPE *&rpRanges, va_list pArgs, - NUMTYPE nWh1, NUMTYPE nWh2, NUMTYPE nNull ) - -/** <H3>Description</H3> - - Creates an sal_uInt16-ranges-array in 'rpRanges' using 'nWh1' and 'nWh2' as - first range, 'nNull' as terminator or start of 2nd range and 'pArgs' as - remaider. - - It returns the number of NUMTYPEs which are contained in the described - set of NUMTYPEs. -*/ - -{ - NUMTYPE nSize = 0, nIns = 0; - sal_uInt16 nCnt = 0; - SvNums aNumArr( 11, 8 ); - aNumArr.Insert( nWh1, nCnt++ ); - aNumArr.Insert( nWh2, nCnt++ ); - DBG_ASSERT( nWh1 <= nWh2, "Ungueltiger Bereich" ); - nSize += nWh2 - nWh1 + 1; - aNumArr.Insert( nNull, nCnt++ ); - while ( 0 != - ( nIns = - sal::static_int_cast< NUMTYPE >( - va_arg( pArgs, NUMTYPE_ARG ) ) ) ) - { - aNumArr.Insert( nIns, nCnt++ ); - if ( 0 == (nCnt & 1) ) // 4,6,8, usw. - { - DBG_ASSERT( aNumArr[ nCnt-2 ] <= nIns, "Ungueltiger Bereich" ); - nSize += nIns - aNumArr[ nCnt-2 ] + 1; - } - } - - DBG_ASSERT( 0 == (nCnt & 1), "ungerade Anzahl von Which-Paaren!" ); - - // so, jetzt sind alle Bereiche vorhanden und - rpRanges = new NUMTYPE[ nCnt+1 ]; - memcpy( rpRanges, aNumArr.GetData(), sizeof(NUMTYPE) * nCnt ); - *(rpRanges+nCnt) = 0; - - return nSize; -} - -//------------------------------------------------------------------------ - -NUMTYPE Count_Impl( const NUMTYPE *pRanges ) - -/** <H3>Description</H3> - - Determines the number of NUMTYPEs in an 0-terminated array of pairs of - NUMTYPEs. The terminating 0 is not included in the count. -*/ - -{ - NUMTYPE nCount = 0; - while ( *pRanges ) - { - nCount += 2; - pRanges += 2; - } - return nCount; -} - -//------------------------------------------------------------------------ - -NUMTYPE Capacity_Impl( const NUMTYPE *pRanges ) - -/** <H3>Description</H3> - - Determines the total number of NUMTYPEs described in an 0-terminated - array of pairs of NUMTYPEs, each representing an range of NUMTYPEs. -*/ - -{ - NUMTYPE nCount = 0; - - if ( pRanges ) - { - while ( *pRanges ) - { - nCount += pRanges[1] - pRanges[0] + 1; - pRanges += 2; - } - } - return nCount; -} - -//------------------------------------------------------------------------ - -SfxNumRanges::SfxNumRanges( const SfxNumRanges &rOrig ) - -/** <H3>Description</H3> - - Copy-Ctor. -*/ - -{ - if ( rOrig._pRanges ) - { - NUMTYPE nCount = Count_Impl( rOrig._pRanges ) + 1; - _pRanges = new NUMTYPE[nCount]; - memcpy( _pRanges, rOrig._pRanges, sizeof(NUMTYPE) * nCount ); - } - else - _pRanges = 0; -} - -//------------------------------------------------------------------------ - -SfxNumRanges::SfxNumRanges( NUMTYPE nWhich1, NUMTYPE nWhich2 ) - -/** <H3>Description</H3> - - Constructs an SfxNumRanges-instance from one range of NUMTYPEs. - - precondition: - nWhich1 <= nWhich2 -*/ - -: _pRanges( new NUMTYPE[3] ) -{ - _pRanges[0] = nWhich1; - _pRanges[1] = nWhich2; - _pRanges[2] = 0; -} - -//------------------------------------------------------------------------ - -SfxNumRanges::SfxNumRanges( NUMTYPE_ARG nWh0, NUMTYPE_ARG nWh1, NUMTYPE_ARG nNull, ... ) - -/** <H3>Description</H3> - - Constructs an SfxNumRanges-instance from more than one sorted ranges of - NUMTYPEs terminated with one 0. - - precondition: for each n >= 0 && n < nArgs - nWh(2n) <= nWh(2n+1) && ( nWh(2n+2)-nWh(2n+1) ) > 1 -*/ - -{ - va_list pArgs; - va_start( pArgs, nNull ); - InitializeRanges_Impl( - _pRanges, pArgs, sal::static_int_cast< NUMTYPE >(nWh0), - sal::static_int_cast< NUMTYPE >(nWh1), - sal::static_int_cast< NUMTYPE >(nNull)); - va_end(pArgs); - DBG_CHECK_RANGES(NUMTYPE, _pRanges); -} - -//------------------------------------------------------------------------ - -SfxNumRanges::SfxNumRanges( const NUMTYPE* pArr ) - -/** <H3>Description</H3> - - Constcurts an SfxNumRanges-instance from an sorted ranges of NUMTYPEs, - terminates with on 0. - - precondition: for each n >= 0 && n < (sizeof(pArr)-1) - pArr[2n] <= pArr[2n+1] && ( pArr[2n+2]-pArr[2n+1] ) > 1 -*/ - -{ - DBG_CHECK_RANGES(NUMTYPE, pArr); - NUMTYPE nCount = Count_Impl(pArr) + 1; - _pRanges = new NUMTYPE[ nCount ]; - memcpy( _pRanges, pArr, sizeof(NUMTYPE) * nCount ); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxNumRanges::operator==( const SfxNumRanges &rOther ) const -{ - // Object pointers equal? - if ( this == &rOther ) - return sal_True; - - // Ranges pointers equal? - if ( _pRanges == rOther._pRanges ) - return sal_True; - - // Counts equal? - NUMTYPE nCount = Count(); - if ( nCount != rOther.Count() ) - return sal_False; - - // Check arrays. - NUMTYPE n = 0; - while( _pRanges[ n ] != 0 ) - { - // Elements at current position equal? - if ( _pRanges[ n ] != rOther._pRanges[ n ] ) - return sal_False; - - ++n; - } - - return sal_True; -} - -//------------------------------------------------------------------------ - -SfxNumRanges& SfxNumRanges::operator = -( - const SfxNumRanges &rRanges -) - -/** <H3>Description</H3> - - Assigns ranges from 'rRanges' to '*this'. -*/ - -{ - // special case: assign itself - if ( &rRanges == this ) - return *this; - - delete[] _pRanges; - - // special case: 'rRanges' is empty - if ( rRanges.IsEmpty() ) - _pRanges = 0; - else - { - // copy ranges - NUMTYPE nCount = Count_Impl( rRanges._pRanges ) + 1; - _pRanges = new NUMTYPE[ nCount ]; - memcpy( _pRanges, rRanges._pRanges, sizeof(NUMTYPE) * nCount ); - } - return *this; -} - -//------------------------------------------------------------------------ - -SfxNumRanges& SfxNumRanges::operator += -( - const SfxNumRanges &rRanges -) - -/** <H3>Description</H3> - - Merges *this with 'rRanges'. - - for each NUMTYPE n: - this->Contains( n ) || rRanges.Contains( n ) => this'->Contains( n ) - !this->Contains( n ) && !rRanges.Contains( n ) => !this'->Contains( n ) -*/ - -{ - // special cases: one is empty - if ( rRanges.IsEmpty() ) - return *this; - if ( IsEmpty() ) - return *this = rRanges; - - // First, run thru _pRanges and rRanges._pRanges and determine the size of - // the new, merged ranges: - NUMTYPE nCount = 0; - const NUMTYPE * pRA = _pRanges; - const NUMTYPE * pRB = rRanges._pRanges; - - for (;;) - { - // The first pair of pRA has a lower lower bound than the first pair - // of pRB: - if (pRA[0] > pRB[0]) - Swap_Impl(pRA, pRB); - - // We are done with the merging if at least pRA is exhausted: - if (!pRA[0]) - break; - - for (;;) - { - // Skip those pairs in pRB that completely lie in the first pair - // of pRA: - while (pRB[1] <= pRA[1]) - { - pRB += 2; - - // Watch out for exhaustion of pRB: - if (!pRB[0]) - { - Swap_Impl(pRA, pRB); - goto count_rest; - } - } - - // If the next pair of pRA does not at least touch the current new - // pair, we are done with the current new pair: - if (pRB[0] > pRA[1] + 1) - break; - - // The next pair of pRB extends the current new pair; first, - // extend the current new pair (we are done if pRB is then - // exhausted); second, switch the roles of pRA and pRB in order to - // merge in those following pairs of the original pRA that will - // lie in the (now larger) current new pair or will even extend it - // further: - pRA += 2; - if (!pRA[0]) - goto count_rest; - Swap_Impl(pRA, pRB); - } - - // Done with the current new pair: - pRA += 2; - nCount += 2; - } - - // Only pRB has more pairs available, pRA is already exhausted: -count_rest: - for (; pRB[0]; pRB += 2) - nCount += 2; - - // Now, create new ranges of the correct size and, on a second run thru - // _pRanges and rRanges._pRanges, copy the merged pairs into the new - // ranges: - NUMTYPE * pNew = new NUMTYPE[nCount + 1]; - pRA = _pRanges; - pRB = rRanges._pRanges; - NUMTYPE * pRN = pNew; - - for (;;) - { - // The first pair of pRA has a lower lower bound than the first pair - // of pRB: - if (pRA[0] > pRB[0]) - Swap_Impl(pRA, pRB); - - // We are done with the merging if at least pRA is exhausted: - if (!pRA[0]) - break; - - // Lower bound of current new pair is already known: - *pRN++ = pRA[0]; - - for (;;) - { - // Skip those pairs in pRB that completely lie in the first pair - // of pRA: - while (pRB[1] <= pRA[1]) - { - pRB += 2; - - // Watch out for exhaustion of pRB: - if (!pRB[0]) - { - Swap_Impl(pRA, pRB); - ++pRB; - goto copy_rest; - } - } - - // If the next pair of pRA does not at least touch the current new - // pair, we are done with the current new pair: - if (pRB[0] > pRA[1] + 1) - break; - - // The next pair of pRB extends the current new pair; first, - // extend the current new pair (we are done if pRB is then - // exhausted); second, switch the roles of pRA and pRB in order to - // merge in those following pairs of the original pRA that will - // lie in the (now larger) current new pair or will even extend it - // further: - pRA += 2; - if (!pRA[0]) - { - ++pRB; - goto copy_rest; - } - Swap_Impl(pRA, pRB); - } - - // Done with the current new pair, now upper bound is also known: - *pRN++ = pRA[1]; - pRA += 2; - } - - // Only pRB has more pairs available (which are copied to the new ranges - // unchanged), pRA is already exhausted: -copy_rest: - for (; *pRB;) - *pRN++ = *pRB++; - *pRN = 0; - - delete[] _pRanges; - _pRanges = pNew; - - return *this; -} - -//------------------------------------------------------------------------ - -SfxNumRanges& SfxNumRanges::operator -= -( - const SfxNumRanges &rRanges -) - -/** <H3>Description</H3> - - Removes 'rRanges' from '*this'. - - for each NUMTYPE n: - this->Contains( n ) && rRanges.Contains( n ) => !this'->Contains( n ) - this->Contains( n ) && !rRanges.Contains( n ) => this'->Contains( n ) - !this->Contains( n ) => !this'->Contains( n ) -*/ - -{ - // special cases: one is empty - if ( rRanges.IsEmpty() || IsEmpty() ) - return *this; - - // differentiate 'rRanges' in a temporary copy of '*this' - // (size is computed for maximal possibly split-count plus terminating 0) - NUMTYPE nThisSize = Count_Impl(_pRanges); - NUMTYPE nTargetSize = 1 + ( nThisSize + Count_Impl(rRanges._pRanges) ); - NUMTYPE *pTarget = new NUMTYPE[ nTargetSize ]; - memset( pTarget, 0, sizeof(NUMTYPE)*nTargetSize ); - memcpy( pTarget, _pRanges, sizeof(NUMTYPE)*nThisSize ); - - NUMTYPE nPos1 = 0, nPos2 = 0, nTargetPos = 0; - while( _pRanges[ nPos1 ] ) - { - NUMTYPE l1 = _pRanges[ nPos1 ]; // lower bound of interval 1 - NUMTYPE u1 = _pRanges[ nPos1+1 ]; // upper bound of interval 1 - NUMTYPE l2 = rRanges._pRanges[ nPos2 ]; // lower bound of interval 2 - NUMTYPE u2 = rRanges._pRanges[ nPos2+1 ]; // upper bound of interval 2 - - // boundary cases - // * subtrahend is empty -> copy the minuend - if( !l2 ) - { - pTarget[ nTargetPos ] = l1; - pTarget[ nTargetPos+1 ] = u1; - nTargetPos += 2; - nPos1 += 2; - continue; - } - // * next subtrahend interval is completely higher -> copy the minuend - if( u1 < l2 ) - { - pTarget[ nTargetPos ] = l1; - pTarget[ nTargetPos+1 ] = u1; - nTargetPos += 2; - nPos1 += 2; - continue; - } - - // * next subtrahend interval is completely lower -> try next - if( u2 < l1 ) - { - nPos2 += 2; - continue; - } - - // intersecting cases - // * subtrahend cuts out from the beginning of the minuend - if( l2 <= l1 && u2 <= u1 ) - { - // reduce minuend interval, try again (minuend might be affected by other subtrahend intervals) - _pRanges[ nPos1 ] = u2 + 1; - nPos2 += 2; // this cannot hurt any longer - continue; - } - - // * subtrahend cuts out from the end of the minuend - if( l1 <= l2 && u1 <= u2 ) - { - // copy remaining part of minuend (cannot be affected by other intervals) - if( l1 < l2 ) // anything left at all? - { - pTarget[ nTargetPos ] = l1; - pTarget[ nTargetPos+1 ] = l2 - 1; - nTargetPos += 2; - // do not increment nPos2, might affect next minuend interval, too - } - nPos1 += 2; // nothing left at all - continue; - } - - // * subtrahend completely deletes minuend (larger or same at both ends) - if( l1 >= l2 && u1 <= u2 ) - { - nPos1 += 2; // minuend deleted - // do not increment nPos2, might affect next minuend interval, too - continue; - } - - // * subtrahend divides minuend into two pieces - if( l1 <= l2 && u1 >= u2 ) // >= and <= since they may be something left only at one side - { - // left side - if( l1 < l2 ) // anything left at all - { - pTarget[ nTargetPos ] = l1; - pTarget[ nTargetPos+1 ] = l2 - 1; - nTargetPos += 2; - } - - // right side - if( u1 > u2 ) // anything left at all - { - // reduce minuend interval, try again (minuend might be affected by other subtrahend itnervals ) - _pRanges[ nPos1 ] = u2 + 1; - } - - // subtrahend is completely used - nPos2 += 2; - continue; - } - - // we should never be here - OSL_FAIL( "SfxNumRanges::operator-=: internal error" ); - } // while - - pTarget[ nTargetPos ] = 0; - - // assign the differentiated ranges - delete[] _pRanges; - - NUMTYPE nUShorts = Count_Impl(pTarget) + 1; - if ( 1 != nUShorts ) - { - _pRanges = new NUMTYPE[ nUShorts ]; - memcpy( _pRanges, pTarget, nUShorts * sizeof(NUMTYPE) ); - } - else - _pRanges = 0; - - delete [] pTarget; - return *this; -} - -//------------------------------------------------------------------------ - -SfxNumRanges& SfxNumRanges::operator /= -( - const SfxNumRanges &rRanges -) - -/** <H3>Description</H3> - - Determines intersection of '*this' with 'rRanges'. - - for each NUMTYPE n: - this->Contains( n ) && rRanges.Contains( n ) => this'->Contains( n ) - !this->Contains( n ) => !this'->Contains( n ) - !rRanges.Contains( n ) => !this'->Contains( n ) -*/ - -{ - // boundary cases - // * first set is empty -> nothing to be done - // * second set is empty -> delete first set - if( rRanges.IsEmpty() ) - { - delete[] _pRanges; - - _pRanges = new NUMTYPE[1]; - _pRanges[0] = 0; - - return *this; - } - - // intersect 'rRanges' in a temporary copy of '*this' - // (size is computed for maximal possibly split-count plus terminating 0) - NUMTYPE nThisSize = Count_Impl(_pRanges); - NUMTYPE nTargetSize = 1 + ( nThisSize + Count_Impl(rRanges._pRanges) ); - NUMTYPE *pTarget = new NUMTYPE[ nTargetSize ]; - memset( pTarget, 0, sizeof(NUMTYPE)*nTargetSize ); - memcpy( pTarget, _pRanges, sizeof(NUMTYPE)*nThisSize ); - - NUMTYPE nPos1 = 0, nPos2 = 0, nTargetPos = 0; - while( _pRanges[ nPos1 ] != 0 && rRanges._pRanges[ nPos2 ] != 0 ) - { - NUMTYPE l1 = _pRanges[ nPos1 ]; // lower bound of interval 1 - NUMTYPE u1 = _pRanges[ nPos1+1 ]; // upper bound of interval 1 - NUMTYPE l2 = rRanges._pRanges[ nPos2 ]; // lower bound of interval 2 - NUMTYPE u2 = rRanges._pRanges[ nPos2+1 ]; // upper bound of interval 2 - - if( u1 < l2 ) - { - // current interval in s1 is completely before ci in s2 - nPos1 += 2; - continue; - } - if( u2 < l1 ) - { - // ci in s2 is completely before ci in s1 - nPos2 += 2; - continue; - } - - // assert: there exists an intersection between ci1 and ci2 - - if( l1 <= l2 ) - { - // c1 "is more to the left" than c2 - - if( u1 <= u2 ) - { - pTarget[ nTargetPos ] = l2; - pTarget[ nTargetPos+1 ] = u1; - nTargetPos += 2; - nPos1 += 2; - continue; - } - else - { - pTarget[ nTargetPos ] = l2; - pTarget[ nTargetPos+1 ] = u2; - nTargetPos += 2; - nPos2 += 2; - } - } - else - { - // c2 "is more to the left" than c1" - - if( u1 > u2 ) - { - pTarget[ nTargetPos ] = l1; - pTarget[ nTargetPos+1 ] = u2; - nTargetPos += 2; - nPos2 += 2; - } - else - { - pTarget[ nTargetPos ] = l1; - pTarget[ nTargetPos+1 ] = u1; - nTargetPos += 2; - nPos1 += 2; - } - } - }; // while - pTarget[ nTargetPos ] = 0; - - // assign the intersected ranges - delete[] _pRanges; - - NUMTYPE nUShorts = Count_Impl(pTarget) + 1; - if ( 1 != nUShorts ) - { - _pRanges = new NUMTYPE[ nUShorts ]; - memcpy( _pRanges, pTarget, nUShorts * sizeof(NUMTYPE) ); - } - else - _pRanges = 0; - - delete [] pTarget; - return *this; -} - -//------------------------------------------------------------------------ - -sal_Bool SfxNumRanges::Intersects( const SfxNumRanges &rRanges ) const - -/** <H3>Description</H3> - - Determines if at least one range in 'rRanges' intersects with one - range in '*this'. - - sal_True, if there is at least one with: - this->Contains( n ) && rRanges.Contains( n ) -*/ - -{ - // special cases: one is empty - if ( rRanges.IsEmpty() || IsEmpty() ) - return sal_False; - - // find at least one intersecting range - const NUMTYPE *pRange1 = _pRanges; - const NUMTYPE *pRange2 = rRanges._pRanges; - - do - { - // 1st range is smaller than 2nd range? - if ( pRange1[1] < pRange2[0] ) - // => keep 1st range - pRange1 += 2; - - // 2nd range is smaller than 1st range? - else if ( pRange2[1] < pRange1[0] ) - // => skip 2nd range - pRange2 += 2; - - // the ranges are overlappung - else - return sal_True; - } - while ( *pRange2 ); - - // no intersection found - return sal_False; -} - -//------------------------------------------------------------------------ - -NUMTYPE SfxNumRanges::Count() const - -/** <H3>Description</H3> - - Determines the number of USHORTs in the set described by the ranges - of USHORTs in '*this'. -*/ - -{ - return Capacity_Impl( _pRanges ); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxNumRanges::Contains( NUMTYPE n ) const - -/** <H3>Description</H3> - - Determines if '*this' contains 'n'. -*/ - -{ - for ( NUMTYPE *pRange = _pRanges; *pRange && *pRange <= n; pRange += 2 ) - if ( pRange[0] <= n && n <= pRange[1] ) - return sal_True; - return sal_False; - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/poolcach.cxx b/svl/source/items/poolcach.cxx deleted file mode 100644 index af2e0de9c1..0000000000 --- a/svl/source/items/poolcach.cxx +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <limits.h> - -#include <svl/itempool.hxx> -#include <svl/itemset.hxx> -#include <svl/poolcach.hxx> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxItemPoolCache) - -//------------------------------------------------------------------------ - -SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool, - const SfxPoolItem *pPutItem ): - pPool(pItemPool), - pCache(new SfxItemModifyArr_Impl), - pSetToPut( 0 ), - pItemToPut( &pItemPool->Put(*pPutItem) ) -{ - DBG_CTOR(SfxItemPoolCache, 0); - DBG_ASSERT(pItemPool, "kein Pool angegeben"); -} - -//------------------------------------------------------------------------ - -SfxItemPoolCache::SfxItemPoolCache( SfxItemPool *pItemPool, - const SfxItemSet *pPutSet ): - pPool(pItemPool), - pCache(new SfxItemModifyArr_Impl), - pSetToPut( pPutSet ), - pItemToPut( 0 ) -{ - DBG_CTOR(SfxItemPoolCache, 0); - DBG_ASSERT(pItemPool, "kein Pool angegeben"); -} - -//------------------------------------------------------------------------ - -SfxItemPoolCache::~SfxItemPoolCache() -{ - DBG_DTOR(SfxItemPoolCache, 0); - for ( size_t nPos = 0; nPos < pCache->size(); ++nPos ) { - pPool->Remove( *(*pCache)[nPos].pPoolItem ); - pPool->Remove( *(*pCache)[nPos].pOrigItem ); - } - delete pCache; pCache = 0; - - if ( pItemToPut ) - pPool->Remove( *pItemToPut ); -} - -//------------------------------------------------------------------------ - -const SfxSetItem& SfxItemPoolCache::ApplyTo( const SfxSetItem &rOrigItem, sal_Bool bNew ) -{ - DBG_CHKTHIS(SfxItemPoolCache, 0); - DBG_ASSERT( pPool == rOrigItem.GetItemSet().GetPool(), "invalid Pool" ); - DBG_ASSERT( IsDefaultItem( &rOrigItem ) || IsPooledItem( &rOrigItem ), - "original not in pool" ); - - // Find whether this Transformations ever occurred - for ( size_t nPos = 0; nPos < pCache->size(); ++nPos ) - { - SfxItemModifyImpl &rMapEntry = (*pCache)[nPos]; - if ( rMapEntry.pOrigItem == &rOrigItem ) - { - // aendert sich ueberhaupt etwas? - if ( rMapEntry.pPoolItem != &rOrigItem ) - { - rMapEntry.pPoolItem->AddRef(2); // einen davon fuer den Cache - if ( bNew ) - pPool->Put( rOrigItem ); //! AddRef?? - } - return *rMapEntry.pPoolItem; - } - } - - // die neue Attributierung in einem neuen Set eintragen - SfxSetItem *pNewItem = (SfxSetItem *)rOrigItem.Clone(); - if ( pItemToPut ) - { - pNewItem->GetItemSet().PutDirect( *pItemToPut ); - DBG_ASSERT( &pNewItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut, - "wrong item in temporary set" ); - } - else - pNewItem->GetItemSet().Put( *pSetToPut ); - const SfxSetItem* pNewPoolItem = (const SfxSetItem*) &pPool->Put( *pNewItem ); - DBG_ASSERT( pNewPoolItem != pNewItem, "Pool: rein == raus?" ); - delete pNewItem; - - // Refernzzaehler anpassen, je einen davon fuer den Cache - pNewPoolItem->AddRef( pNewPoolItem != &rOrigItem ? 2 : 1 ); - if ( bNew ) - pPool->Put( rOrigItem ); //! AddRef?? - - // die Transformation im Cache eintragen - SfxItemModifyImpl aModify; - aModify.pOrigItem = &rOrigItem; - aModify.pPoolItem = (SfxSetItem*) pNewPoolItem; - pCache->push_back( aModify ); - - DBG_ASSERT( !pItemToPut || - &pNewPoolItem->GetItemSet().Get( pItemToPut->Which() ) == pItemToPut, - "wrong item in resulting set" ); - - return *pNewPoolItem; -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/poolio.cxx b/svl/source/items/poolio.cxx deleted file mode 100644 index 833ba3ca32..0000000000 --- a/svl/source/items/poolio.cxx +++ /dev/null @@ -1,1628 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <string.h> -#include <stdio.h> - -#include <tools/solar.h> -#include <svl/itempool.hxx> -#include "whassert.hxx" -#include <svl/brdcst.hxx> -#include <svl/filerec.hxx> -#include <svl/svldata.hxx> -#include "poolio.hxx" - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxItemPool); - -//======================================================================== - -const SfxItemPool* SfxItemPool::GetStoringPool() - -/* [Beschreibung] - - Diese Methode liefert den <SfxItemPool>, der gerade gespeichert wird. - Sie sollte nur in Notf"allen verwendet werden, um z.B. File-Format- - Kompatibilit"at zu gew"ahrleisten o."o. - z.B. in der "uberladung eines - <SfxPoolItem::Store()> zus"atzliche Daten aus dem dazuge"horigen - Pool zu besorgen. -*/ - -{ - return ImpSvlData::GetSvlData().pStoringPool; -} - -//------------------------------------------------------------------------- - -SvStream &SfxItemPool::Store(SvStream &rStream) const - -/* [Beschreibung] - - Der SfxItemPool wird inklusive aller seiner Sekund"arpools mit - Pool-Defaults und gepoolten Items in dem angegebenen Stream gespeichert. - Die statischen Defaults werden nicht gespeichert. - - - [Fileformat] - - ;zun"achst ein Kompatiblit"ats-Header-Block - Start: 0x1111 SFX_ITEMPOOL_TAG_STARTPOOLS(_4/_5) - sal_uInt8 MAJOR_VER ;SfxItemPool-Version - sal_uInt8 MINOR_VER ;" - 0xFFFF SFX_ITEMPOOL_TAG_TRICK4OLD ;ex. GetVersion() - sal_uInt16 0x0000 ;Pseudo-StyleSheetPool - sal_uInt16 0x0000 ;Pseudo-StyleSheetPool - - ;den ganzen Pool in einen Record - record SfxMiniRecod(SFX_ITEMPOOL_REC) - - ;je ein Header vorweg - Header: record SfxMiniRecord(SFX_ITEMPOOL_REC_HEADER) - sal_uInt16 GetVersion() ;Which-Ranges etc. - String GetName() ;Pool-Name - - ;die Versions-Map, um WhichIds neuer File-Versionen mappen zu k"onnen - Versions: record SfxMultiRecord(SFX_ITEMPOOL_REC_VERSIONS, 0) - sal_uInt16 OldVersion - sal_uInt16 OldStartWhich - sal_uInt16 OldEndWhich - sal_uInt16[] NewWhich (OldEndWhich-OldStartWhich+1) - - ;jetzt die gepoolten Items (zuerst nicht-SfxSetItems) - Items: record SfxMultiRecord(SFX_ITEMPOOL_REC_WHICHIDS, 0) - content SlotId, 0 - sal_uInt16 WhichId - sal_uInt16 pItem->GetVersion() - sal_uInt16 Array-Size - record SfxMultiRecord(SFX_, 0) - content Surrogate - sal_uInt16 RefCount - unknown pItem->Store() - - ;jetzt die gesetzten Pool-Defaults - Defaults: record SfxMultiRecord(SFX_ITEMPOOL_REC_DEFAULTS, 0) - content SlotId, 0 - sal_uInt16 WhichId - sal_uInt16 pPoolDef->GetVersion() - unknown pPoolDef->Store(); - - ;dahinter folgt ggf. der Secondary ohne Kompatiblit"ats-Header-Block -*/ - -{ - DBG_CHKTHIS(SfxItemPool, 0); - - // Store-Master finden - SfxItemPool *pStoreMaster = pMaster != this ? pMaster : 0; - while ( pStoreMaster && !pStoreMaster->pImp->bStreaming ) - pStoreMaster = pStoreMaster->pSecondary; - - // Alter-Header (Version des Pools an sich und Inhalts-Version 0xffff) - pImp->bStreaming = sal_True; - if ( !pStoreMaster ) - { - rStream << ( rStream.GetVersion() >= SOFFICE_FILEFORMAT_50 - ? SFX_ITEMPOOL_TAG_STARTPOOL_5 - : SFX_ITEMPOOL_TAG_STARTPOOL_4 ); - rStream << SFX_ITEMPOOL_VER_MAJOR << SFX_ITEMPOOL_VER_MINOR; - rStream << SFX_ITEMPOOL_TAG_TRICK4OLD; - - // SfxStyleSheet-Bug umgehen - rStream << sal_uInt16(0); // Version - rStream << sal_uInt16(0); // Count (2. Schleife f"allt sonst auf die Fresse) - } - - // jeder Pool ist als ganzes ein Record - SfxMiniRecordWriter aPoolRec( &rStream, SFX_ITEMPOOL_REC ); - ImpSvlData::GetSvlData().pStoringPool = this; - - // Einzel-Header (Version des Inhalts und Name) - { - SfxMiniRecordWriter aPoolHeaderRec( &rStream, SFX_ITEMPOOL_REC_HEADER); - rStream << pImp->nVersion; - SfxPoolItem::writeByteString(rStream, aName); - } - - // Version-Maps - { - SfxMultiVarRecordWriter aVerRec( &rStream, SFX_ITEMPOOL_REC_VERSIONMAP, 0 ); - for ( size_t nVerNo = 0; nVerNo < pImp->aVersions.size(); ++nVerNo ) - { - aVerRec.NewContent(); - SfxPoolVersion_ImplPtr pVer = pImp->aVersions[nVerNo]; - rStream << pVer->_nVer << pVer->_nStart << pVer->_nEnd; - sal_uInt16 nCount = pVer->_nEnd - pVer->_nStart + 1; - sal_uInt16 nNewWhich = 0; - for ( sal_uInt16 n = 0; n < nCount; ++n ) - { - nNewWhich = pVer->_pMap[n]; - rStream << nNewWhich; - } - - // Workaround gegen Bug in SetVersionMap der 312 - if ( SOFFICE_FILEFORMAT_31 == _nFileFormatVersion ) - rStream << sal_uInt16(nNewWhich+1); - } - } - - // gepoolte Items - { - SfxMultiMixRecordWriter aWhichIdsRec( &rStream, SFX_ITEMPOOL_REC_WHICHIDS, 0 ); - - // erst Atomaren-Items und dann die Sets schreiben (wichtig beim Laden) - for (int ft = 0 ; ft < 2 && !rStream.GetError(); ft++) - { - pImp->bInSetItem = ft != 0; - - SfxPoolItemArray_Impl **pArr = pImp->ppPoolItems; - SfxPoolItem **ppDefItem = ppStaticDefaults; - const sal_uInt16 nSize = GetSize_Impl(); - for ( size_t i = 0; i < nSize && !rStream.GetError(); ++i, ++pArr, ++ppDefItem ) - { - // Version des Items feststellen - sal_uInt16 nItemVersion = (*ppDefItem)->GetVersion( _nFileFormatVersion ); - if ( USHRT_MAX == nItemVersion ) - // => kam in zu exportierender Version gar nicht vor - continue; - - // !poolable wird gar nicht im Pool gespeichert - // und itemsets/plain-items je nach Runde -#ifdef TF_POOLABLE - if ( *pArr && IsItemFlag(**ppDefItem, SFX_ITEM_POOLABLE) && -#else - if ( *pArr && (*ppDefItem)->IsPoolable() && -#endif - pImp->bInSetItem == (*ppDefItem)->ISA(SfxSetItem) ) - { - // eigene Kennung, globale Which-Id und Item-Version - sal_uInt16 nSlotId = GetSlotId( (*ppDefItem)->Which(), sal_False ); - aWhichIdsRec.NewContent(nSlotId, 0); - rStream << (*ppDefItem)->Which(); - rStream << nItemVersion; - const sal_uInt32 nCount = ::std::min<size_t>( (*pArr)->size(), SAL_MAX_UINT32 ); - DBG_ASSERT(nCount, "ItemArr is empty"); - rStream << nCount; - - // Items an sich schreiben - SfxMultiMixRecordWriter aItemsRec( &rStream, SFX_ITEMPOOL_REC_ITEMS, 0 ); - for ( size_t j = 0; j < nCount; ++j ) - { - // Item selbst besorgen - const SfxPoolItem *pItem = (*pArr)->operator[](j); - if ( pItem && pItem->GetRefCount() ) //! siehe anderes MI-REF - { - aItemsRec.NewContent((sal_uInt16)j, 'X' ); - - if ( pItem->GetRefCount() == SFX_ITEMS_SPECIAL ) - rStream << (sal_uInt16) pItem->GetKind(); - else - { - rStream << (sal_uInt16) pItem->GetRefCount(); - if( pItem->GetRefCount() > SFX_ITEMS_OLD_MAXREF ) - rStream.SetError( ERRCODE_IO_NOTSTORABLEINBINARYFORMAT ); - } - - if ( !rStream.GetError() ) - pItem->Store(rStream, nItemVersion); - else - break; -#ifdef DBG_UTIL_MI - if ( !pItem->ISA(SfxSetItem) ) - { - sal_uLong nMark = rStream.Tell(); - rStream.Seek( nItemStartPos + sizeof(sal_uInt16) ); - SfxPoolItem *pClone = pItem->Create(rStream, nItemVersion ); - sal_uInt16 nWh = pItem->Which(); - SFX_ASSERT( rStream.Tell() == nMark, nWh,"asymmetric store/create" ); - SFX_ASSERT( *pClone == *pItem, nWh, "unequal after store/create" ); - delete pClone; - } -#endif - } - } - } - } - } - - pImp->bInSetItem = false; - } - - // die gesetzten Defaults speichern (Pool-Defaults) - if ( !rStream.GetError() ) - { - SfxMultiMixRecordWriter aDefsRec( &rStream, SFX_ITEMPOOL_REC_DEFAULTS, 0 ); - sal_uInt16 nCount = GetSize_Impl(); - for ( sal_uInt16 n = 0; n < nCount; ++n ) - { - const SfxPoolItem* pDefaultItem = ppPoolDefaults[n]; - if ( pDefaultItem ) - { - // Version ermitteln - sal_uInt16 nItemVersion = pDefaultItem->GetVersion( _nFileFormatVersion ); - if ( USHRT_MAX == nItemVersion ) - // => gab es in der Version noch nicht - continue; - - // eigene Kennung, globale Kennung, Version - sal_uInt16 nSlotId = GetSlotId( pDefaultItem->Which(), sal_False ); - aDefsRec.NewContent( nSlotId, 0 ); - rStream << pDefaultItem->Which(); - rStream << nItemVersion; - - // Item an sich - pDefaultItem->Store( rStream, nItemVersion ); - } - } - } - - // weitere Pools rausschreiben - ImpSvlData::GetSvlData().pStoringPool = 0; - aPoolRec.Close(); - if ( !rStream.GetError() && pSecondary ) - pSecondary->Store( rStream ); - - pImp->bStreaming = sal_False; - return rStream; -} - -// ----------------------------------------------------------------------- - -void SfxItemPool::LoadCompleted() - -/* [Beschreibung] - - Wurde der SfxItemPool mit 'bRefCounts' == sal_False geladen, mu\s das - Laden der Dokumentinhalte mit einem Aufruf dieser Methode beendet - werden. Ansonsten hat der Aufruf dieser Methode keine Funktion. - - - [Anmerkung] - - Beim Laden ohne Ref-Counts werden diese tats"achlich auf 1 gesetzt, - damit nicht w"ahrend des Ladevorgangs SfxPoolItems gel"oscht werden, - die danach, aber auch noch beim Ladevorgang, ben"otigt werden. Diese - Methode setzt den Ref-Count wieder zur"uck und entfernt dabei - gleichzeitig alle nicht mehr ben"otigten Items. - - - [Querverweise] - - <SfxItemPool::Load()> -*/ - -{ - // wurden keine Ref-Counts mitgeladen? - if ( pImp->nInitRefCount > 1 ) - { - - // "uber alle Which-Werte iterieren - SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; - for( sal_uInt16 nArrCnt = GetSize_Impl(); nArrCnt; --nArrCnt, ++ppItemArr ) - { - // ist "uberhaupt ein Item mit dem Which-Wert da? - if ( *ppItemArr ) - { - // "uber alle Items mit dieser Which-Id iterieren - SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); - for( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) - if (*ppHtArr) - { - #ifdef DBG_UTIL - const SfxPoolItem &rItem = **ppHtArr; - DBG_ASSERT( !rItem.ISA(SfxSetItem) || - 0 != &((const SfxSetItem&)rItem).GetItemSet(), - "SetItem without ItemSet" ); - #endif - - if ( !ReleaseRef( **ppHtArr, 1 ) ) - DELETEZ( *ppHtArr ); - } - } - } - - // from now on normal initial ref count - pImp->nInitRefCount = 1; - } - - // notify secondary pool - if ( pSecondary ) - pSecondary->LoadCompleted(); -} - -//============================================================================ -// This had to be moved to a method of its own to keep Solaris GCC happy: -void SfxItemPool::readTheItems ( - SvStream & rStream, sal_uInt32 nItemCount, sal_uInt16 nVersion, - SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** ppArr) -{ - SfxMultiRecordReader aItemsRec( &rStream, SFX_ITEMPOOL_REC_ITEMS ); - - SfxPoolItemArray_Impl *pNewArr = new SfxPoolItemArray_Impl(); - SfxPoolItem *pItem = 0; - - sal_uLong n, nLastSurrogate = sal_uLong(-1); - while (aItemsRec.GetContent()) - { - // n"achstes Surrogat holen - sal_uInt16 nSurrogate = aItemsRec.GetContentTag(); - DBG_ASSERT( aItemsRec.GetContentVersion() == 'X', - "not an item content" ); - - // fehlende auff"ullen - for ( pItem = 0, n = nLastSurrogate+1; n < nSurrogate; ++n ) - pNewArr->push_back( (SfxPoolItem*) pItem ); - nLastSurrogate = nSurrogate; - - // Ref-Count und Item laden - sal_uInt16 nRef(0); - rStream >> nRef; - - pItem = pDefItem->Create(rStream, nVersion); - pNewArr->push_back( (SfxPoolItem*) pItem ); - - if ( !bPersistentRefCounts ) - // bis <SfxItemPool::LoadCompleted()> festhalten - AddRef(*pItem, 1); - else - { - if ( nRef > SFX_ITEMS_OLD_MAXREF ) - pItem->SetKind( nRef ); - else - AddRef(*pItem, nRef); - } - } - - // fehlende auff"ullen - for ( pItem = 0, n = nLastSurrogate+1; n < nItemCount; ++n ) - pNewArr->push_back( (SfxPoolItem*) pItem ); - - SfxPoolItemArray_Impl *pOldArr = *ppArr; - *ppArr = pNewArr; - - // die Items merken, die schon im Pool sind - bool bEmpty = true; - if ( 0 != pOldArr ) - for ( n = 0; bEmpty && n < pOldArr->size(); ++n ) - bEmpty = pOldArr->operator[](n) == 0; - DBG_ASSERTWARNING( bEmpty, "loading non-empty pool" ); - if ( !bEmpty ) - { - // f"ur alle alten suchen, ob ein gleiches neues existiert - for ( size_t nOld = 0; nOld < pOldArr->size(); ++nOld ) - { - SfxPoolItem *pOldItem = (*pOldArr)[nOld]; - if ( pOldItem ) - { - sal_uInt32 nFree = SAL_MAX_UINT32; - bool bFound = false; - for ( size_t nNew = (*ppArr)->size(); nNew--; ) - { - // geladenes Item - SfxPoolItem *&rpNewItem = - (SfxPoolItem*&)(*ppArr)->operator[](nNew); - - // surrogat unbenutzt? - if ( !rpNewItem ) - nFree = nNew; - - // gefunden? - else if ( *rpNewItem == *pOldItem ) - { - // wiederverwenden - AddRef( *pOldItem, rpNewItem->GetRefCount() ); - SetRefCount( *rpNewItem, 0 ); - delete rpNewItem; - rpNewItem = pOldItem; - bFound = true; - break; - } - } - - // vorhervorhandene, nicht geladene uebernehmen - if ( !bFound ) - { - if ( nFree != SAL_MAX_UINT32 ) - (SfxPoolItem*&)(*ppArr)->operator[](nFree) = pOldItem; - else - (*ppArr)->push_back( (SfxPoolItem*) pOldItem ); - } - } - } - } - delete pOldArr; -} - -// ----------------------------------------------------------------------- - -SvStream &SfxItemPool::Load(SvStream &rStream) -{ - DBG_CHKTHIS(SfxItemPool, 0); - DBG_ASSERT(ppStaticDefaults, "kein DefaultArray"); - - // protect items by increasing ref count - if ( !bPersistentRefCounts ) - { - - // "uber alle Which-Werte iterieren - SfxPoolItemArray_Impl** ppItemArr = pImp->ppPoolItems; - for( size_t nArrCnt = GetSize_Impl(); nArrCnt; --nArrCnt, ++ppItemArr ) - { - // ist "uberhaupt ein Item mit dem Which-Wert da? - if ( *ppItemArr ) - { - // "uber alle Items mit dieser Which-Id iterieren - SfxPoolItemArrayBase_Impl::iterator ppHtArr = (*ppItemArr)->begin(); - for( size_t n = (*ppItemArr)->size(); n; --n, ++ppHtArr ) - if (*ppHtArr) - { - #ifdef DBG_UTIL - const SfxPoolItem &rItem = **ppHtArr; - DBG_ASSERT( !rItem.ISA(SfxSetItem) || - 0 != &((const SfxSetItem&)rItem).GetItemSet(), - "SetItem without ItemSet" ); - DBG_WARNING( "loading non-empty ItemPool" ); - #endif - - AddRef( **ppHtArr, 1 ); - } - } - } - - // during loading (until LoadCompleted()) protect all items - pImp->nInitRefCount = 2; - } - - // Load-Master finden - SfxItemPool *pLoadMaster = pMaster != this ? pMaster : 0; - while ( pLoadMaster && !pLoadMaster->pImp->bStreaming ) - pLoadMaster = pLoadMaster->pSecondary; - - // Gesamt Header einlesen - pImp->bStreaming = sal_True; - if ( !pLoadMaster ) - { - // Format-Version laden - CHECK_FILEFORMAT2( rStream, - SFX_ITEMPOOL_TAG_STARTPOOL_5, SFX_ITEMPOOL_TAG_STARTPOOL_4 ); - rStream >> pImp->nMajorVer >> pImp->nMinorVer; - - // Format-Version in Master-Pool "ubertragen - pMaster->pImp->nMajorVer = pImp->nMajorVer; - pMaster->pImp->nMinorVer = pImp->nMinorVer; - - // altes Format? - if ( pImp->nMajorVer < 2 ) - // pImp->bStreaming wird von Load1_Impl() zur"uckgesetzt - return Load1_Impl( rStream ); - - // zu neues Format? - if ( pImp->nMajorVer > SFX_ITEMPOOL_VER_MAJOR ) - { - rStream.SetError(SVSTREAM_FILEFORMAT_ERROR); - pImp->bStreaming = sal_False; - return rStream; - } - - // Version 1.2-Trick-Daten "uberspringen - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_TRICK4OLD ); - rStream.SeekRel( 4 ); // Hack-Daten wegen SfxStyleSheetPool-Bug skippen - } - - // neues Record-orientiertes Format - SfxMiniRecordReader aPoolRec( &rStream, SFX_ITEMPOOL_REC ); - if ( rStream.GetError() ) - { - pImp->bStreaming = sal_False; - return rStream; - } - - // Einzel-Header - int bOwnPool = sal_True; - UniString aExternName; - { - // Header-Record suchen - SfxMiniRecordReader aPoolHeaderRec( &rStream, SFX_ITEMPOOL_REC_HEADER ); - if ( rStream.GetError() ) - { - pImp->bStreaming = sal_False; - return rStream; - } - - // Header-lesen - rStream >> pImp->nLoadingVersion; - SfxPoolItem::readByteString(rStream, aExternName); - bOwnPool = aExternName == aName; - - //! solange wir keine fremden Pools laden k"onnen - if ( !bOwnPool ) - { - rStream.SetError(SVSTREAM_FILEFORMAT_ERROR); - aPoolRec.Skip(); - pImp->bStreaming = sal_False; - return rStream; - } - } - - // Version-Maps - { - SfxMultiRecordReader aVerRec( &rStream, SFX_ITEMPOOL_REC_VERSIONMAP ); - if ( rStream.GetError() ) - { - pImp->bStreaming = sal_False; - return rStream; - } - - // Versions-Maps einlesen - sal_uInt16 nOwnVersion = pImp->nVersion; - for ( sal_uInt16 nVerNo = 0; aVerRec.GetContent(); ++nVerNo ) - { - // Header f"ur einzelne Version einlesen - sal_uInt16 nVersion(0), nHStart(0), nHEnd(0); - rStream >> nVersion >> nHStart >> nHEnd; - sal_uInt16 nCount = nHEnd - nHStart + 1; - - // Is new version is known? - if ( nVerNo >= pImp->aVersions.size() ) - { - // Add new Version - sal_uInt16 *pMap = new sal_uInt16[nCount]; - memset(pMap, 0, nCount * sizeof(sal_uInt16)); - for ( sal_uInt16 n = 0; n < nCount; ++n ) - rStream >> pMap[n]; - SetVersionMap( nVersion, nHStart, nHEnd, pMap ); - } - } - pImp->nVersion = nOwnVersion; - } - - // Items laden - bool bSecondaryLoaded = false; - long nSecondaryEnd = 0; - { - SfxMultiRecordReader aWhichIdsRec( &rStream, SFX_ITEMPOOL_REC_WHICHIDS); - while ( aWhichIdsRec.GetContent() ) - { - // SlotId, Which-Id und Item-Version besorgen - sal_uInt32 nCount(0); - sal_uInt16 nVersion(0), nWhich(0); - //!sal_uInt16 nSlotId = aWhichIdsRec.GetContentTag(); - rStream >> nWhich; - if ( pImp->nLoadingVersion != pImp->nVersion ) - // Which-Id aus File-Version in Pool-Version verschieben - nWhich = GetNewWhich( nWhich ); - - // unbekanntes Item aus neuerer Version - if ( !IsInRange(nWhich) ) - continue; - - rStream >> nVersion; - rStream >> nCount; - //!SFX_ASSERTWARNING( !nSlotId || !HasMap() || - //! ( nSlotId == GetSlotId( nWhich, sal_False ) ) || - //! !GetSlotId( nWhich, sal_False ), - //! nWhich, "Slot/Which mismatch" ); - - sal_uInt16 nIndex = GetIndex_Impl(nWhich); - SfxPoolItemArray_Impl **ppArr = pImp->ppPoolItems + nIndex; - - // SfxSetItems k"onnten Items aus Sekund"arpools beinhalten - SfxPoolItem *pDefItem = *(ppStaticDefaults + nIndex); - pImp->bInSetItem = pDefItem->ISA(SfxSetItem); - if ( !bSecondaryLoaded && pSecondary && pImp->bInSetItem ) - { - // an das Ende des eigenen Pools seeken - sal_uLong nLastPos = rStream.Tell(); - aPoolRec.Skip(); - - // Sekund"arpool einlesen - pSecondary->Load( rStream ); - bSecondaryLoaded = true; - nSecondaryEnd = rStream.Tell(); - - // zur"uck zu unseren eigenen Items - rStream.Seek(nLastPos); - } - - // Items an sich lesen - readTheItems(rStream, nCount, nVersion, pDefItem, ppArr); - - pImp->bInSetItem = sal_False; - } - } - - // Pool-Defaults lesen - { - SfxMultiRecordReader aDefsRec( &rStream, SFX_ITEMPOOL_REC_DEFAULTS ); - - while ( aDefsRec.GetContent() ) - { - // SlotId, Which-Id und Item-Version besorgen - sal_uInt16 nVersion(0), nWhich(0); - //!sal_uInt16 nSlotId = aDefsRec.GetContentTag(); - rStream >> nWhich; - if ( pImp->nLoadingVersion != pImp->nVersion ) - // Which-Id aus File-Version in Pool-Version verschieben - nWhich = GetNewWhich( nWhich ); - - // unbekanntes Item aus neuerer Version - if ( !IsInRange(nWhich) ) - continue; - - rStream >> nVersion; - //!SFX_ASSERTWARNING( !HasMap() || ( nSlotId == GetSlotId( nWhich, sal_False ) ), - //! nWhich, "Slot/Which mismatch" ); - - // Pool-Default-Item selbst laden - SfxPoolItem *pItem = - ( *( ppStaticDefaults + GetIndex_Impl(nWhich) ) ) - ->Create( rStream, nVersion ); - pItem->SetKind( SFX_ITEMS_POOLDEFAULT ); - *( ppPoolDefaults + GetIndex_Impl(nWhich) ) = pItem; - } - } - - // ggf. Secondary-Pool laden - aPoolRec.Skip(); - if ( pSecondary ) - { - if ( !bSecondaryLoaded ) - pSecondary->Load( rStream ); - else - rStream.Seek( nSecondaryEnd ); - } - - // wenn nicht own-Pool, dann kein Name - if ( aExternName != aName ) - aName.Erase(); - - pImp->bStreaming = sal_False; - return rStream; -}; - -// ----------------------------------------------------------------------- - -SvStream &SfxItemPool::Load1_Impl(SvStream &rStream) -{ - // beim Master ist der Header schon von <Load()> geladen worden - if ( !pImp->bStreaming ) - { - // Header des Secondary lesen - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_STARTPOOL_4 ); - rStream >> pImp->nMajorVer >> pImp->nMinorVer; - } - sal_uInt32 nAttribSize(0); - int bOwnPool = sal_True; - UniString aExternName; - if ( pImp->nMajorVer > 1 || pImp->nMinorVer >= 2 ) - rStream >> pImp->nLoadingVersion; - SfxPoolItem::readByteString(rStream, aExternName); - bOwnPool = aExternName == aName; - pImp->bStreaming = sal_True; - - //! solange wir keine fremden laden k"onnen - if ( !bOwnPool ) - { - rStream.SetError(SVSTREAM_FILEFORMAT_ERROR); - pImp->bStreaming = sal_False; - return rStream; - } - - // Versionen bis 1.3 k"onnen noch keine Which-Verschiebungen lesen - if ( pImp->nMajorVer == 1 && pImp->nMinorVer <= 2 && - pImp->nVersion < pImp->nLoadingVersion ) - { - rStream.SetError(ERRCODE_IO_WRONGVERSION); - pImp->bStreaming = sal_False; - return rStream; - } - - // Size-Table liegt hinter den eigentlichen Attributen - rStream >> nAttribSize; - - // Size-Table einlesen - sal_uLong nStartPos = rStream.Tell(); - rStream.SeekRel( nAttribSize ); - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_SIZES ); - sal_uInt32 nSizeTableLen(0); - rStream >> nSizeTableLen; - sal_Char *pBuf = new sal_Char[nSizeTableLen]; - rStream.Read( pBuf, nSizeTableLen ); - sal_uLong nEndOfSizes = rStream.Tell(); - SvMemoryStream aSizeTable( pBuf, nSizeTableLen, STREAM_READ ); - - // ab Version 1.3 steht in der Size-Table eine Versions-Map - if ( pImp->nMajorVer > 1 || pImp->nMinorVer >= 3 ) - { - // Version-Map finden (letztes sal_uLong der Size-Table gibt Pos an) - rStream.Seek( nEndOfSizes - sizeof(sal_uInt32) ); - sal_uInt32 nVersionMapPos(0); - rStream >> nVersionMapPos; - rStream.Seek( nVersionMapPos ); - - // Versions-Maps einlesen - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_VERSIONMAP ); - sal_uInt16 nVerCount(0); - rStream >> nVerCount; - for ( sal_uInt16 nVerNo = 0; nVerNo < nVerCount; ++nVerNo ) - { - // Header f"ur einzelne Version einlesen - sal_uInt16 nVersion(0), nHStart(0), nHEnd(0); - rStream >> nVersion >> nHStart >> nHEnd; - sal_uInt16 nCount = nHEnd - nHStart + 1; - sal_uInt16 nBytes = (nCount)*sizeof(sal_uInt16); - - // Is new version is known? - if ( nVerNo >= pImp->aVersions.size() ) - { - // Add new Version - sal_uInt16 *pMap = new sal_uInt16[nCount]; - memset(pMap, 0, nCount * sizeof(sal_uInt16)); - for ( sal_uInt16 n = 0; n < nCount; ++n ) - rStream >> pMap[n]; - SetVersionMap( nVersion, nHStart, nHEnd, pMap ); - } - else - // Version schon bekannt => "uberspringen - rStream.SeekRel( nBytes ); - } - } - - // Items laden - rStream.Seek( nStartPos ); - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ITEMS ); - bool bSecondaryLoaded = false; - long nSecondaryEnd = 0; - sal_uInt16 nWhich(0), nSlot(0); - while ( rStream >> nWhich, nWhich ) - { - // ggf. Which-Id aus alter Version verschieben? - if ( pImp->nLoadingVersion != pImp->nVersion ) - nWhich = GetNewWhich( nWhich ); - - rStream >> nSlot; - sal_uInt16 nMappedWhich = GetWhich(nSlot, sal_False); - int bKnownItem = bOwnPool || IsWhich(nMappedWhich); - - sal_uInt16 nRef(0), nCount(0), nVersion(0); - sal_uInt32 nAttrSize(0); - rStream >> nVersion >> nCount; - - SfxPoolItemArray_Impl **ppArr = 0; - SfxPoolItemArray_Impl *pNewArr = 0; - SfxPoolItem *pDefItem = 0; - if ( bKnownItem ) - { - if ( !bOwnPool ) - nWhich = nMappedWhich; - - //!SFX_ASSERTWARNING( !nSlot || !HasMap() || - //! ( nSlot == GetSlotId( nWhich, sal_False ) ) || - //! !GetSlotId( nWhich, sal_False ), - //! nWhich, "Slot/Which mismatch" ); - - sal_uInt16 nIndex = GetIndex_Impl(nWhich); - ppArr = pImp->ppPoolItems + nIndex; - pNewArr = new SfxPoolItemArray_Impl(); - pDefItem = *(ppStaticDefaults + nIndex); - } - - // Position vor ersten Item merken - sal_uLong nLastPos = rStream.Tell(); - - // SfxSetItems k"onnten Items aus Sekund"arpools beinhalten - if ( !bSecondaryLoaded && pSecondary && pDefItem->ISA(SfxSetItem) ) - { - // an das Ende des eigenen Pools seeken - rStream.Seek(nEndOfSizes); - CHECK_FILEFORMAT_RELEASE( rStream, SFX_ITEMPOOL_TAG_ENDPOOL, pNewArr ); - CHECK_FILEFORMAT_RELEASE( rStream, SFX_ITEMPOOL_TAG_ENDPOOL, pNewArr ); - - // Sekund"arpool einlesen - pSecondary->Load1_Impl( rStream ); - bSecondaryLoaded = true; - nSecondaryEnd = rStream.Tell(); - - // zur"uck zu unseren eigenen Items - rStream.Seek(nLastPos); - } - - // Items an sich lesen - for ( sal_uInt16 j = 0; j < nCount; ++j ) - { - sal_uLong nPos = nLastPos; - rStream >> nRef; - - if ( bKnownItem ) - { - SfxPoolItem *pItem = 0; - if ( nRef ) - { - pItem = pDefItem->Create(rStream, nVersion); - - if ( !bPersistentRefCounts ) - // bis <SfxItemPool::LoadCompleted()> festhalten - AddRef(*pItem, 1); - else - { - if ( nRef > SFX_ITEMS_OLD_MAXREF ) - pItem->SetKind( nRef ); - else - AddRef(*pItem, nRef); - } - } - //pNewArr->insert( pItem, j ); - pNewArr->push_back( (SfxPoolItem*) pItem ); - - // restliche gespeicherte Laenge skippen (neueres Format) - nLastPos = rStream.Tell(); - } - - aSizeTable >> nAttrSize; - SFX_ASSERT( !bKnownItem || ( nPos + nAttrSize) >= nLastPos, - nPos, - "too many bytes read - version mismatch?" ); - - if ( !bKnownItem || ( nLastPos < (nPos + nAttrSize) ) ) - { - nLastPos = nPos + nAttrSize; - rStream.Seek( nLastPos ); - } - } - - if ( bKnownItem ) - { - SfxPoolItemArray_Impl *pOldArr = *ppArr; - *ppArr = pNewArr; - - // die Items merken, die schon im Pool sind - int bEmpty = sal_True; - if ( 0 != pOldArr ) - for ( size_t n = 0; bEmpty && n < pOldArr->size(); ++n ) - bEmpty = pOldArr->operator[](n) == 0; - DBG_ASSERTWARNING( bEmpty, "loading non-empty pool" ); - if ( !bEmpty ) - { - // f"ur alle alten suchen, ob ein gleiches neues existiert - for ( size_t nOld = 0; nOld < pOldArr->size(); ++nOld ) - { - SfxPoolItem *pOldItem = (*pOldArr)[nOld]; - if ( pOldItem ) - { - bool bFound = false; - for ( size_t nNew = 0; - nNew < (*ppArr)->size(); ++nNew ) - { - SfxPoolItem *&rpNewItem = - (SfxPoolItem*&)(*ppArr)->operator[](nNew); - - if ( rpNewItem && *rpNewItem == *pOldItem ) - { - AddRef( *pOldItem, rpNewItem->GetRefCount() ); - SetRefCount( *rpNewItem, 0 ); - delete rpNewItem; - rpNewItem = pOldItem; - bFound = true; - SFX_TRACE( "reusing item", pOldItem ); - break; - } - } - if ( !bFound ) - { - SFX_TRACE( "item not found: ", pOldItem ); - } - } - } - } - delete pOldArr; /* @@@ */ - } - } - - // Pool-Defaults lesen - if ( pImp->nMajorVer > 1 || pImp->nMinorVer > 0 ) - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_DEFAULTS ); - - sal_uLong nLastPos = rStream.Tell(); - while ( rStream >> nWhich, nWhich ) - { - // ggf. Which-Id aus alter Version verschieben? - if ( pImp->nLoadingVersion != pImp->nVersion ) - nWhich = GetNewWhich( nWhich ); - - rStream >> nSlot; - sal_uInt16 nMappedWhich = GetWhich(nSlot, sal_False); - int bKnownItem = bOwnPool || IsWhich(nMappedWhich); - - sal_uLong nPos = nLastPos; - sal_uInt32 nSize(0); - sal_uInt16 nVersion(0); - rStream >> nVersion; - - if ( bKnownItem ) - { - if ( !bOwnPool ) - nWhich = nMappedWhich; - SfxPoolItem *pItem = - ( *( ppStaticDefaults + GetIndex_Impl(nWhich) ) ) - ->Create( rStream, nVersion ); - pItem->SetKind( SFX_ITEMS_POOLDEFAULT ); - *( ppPoolDefaults + GetIndex_Impl(nWhich) ) = pItem; - } - - nLastPos = rStream.Tell(); - aSizeTable >> nSize; - SFX_ASSERT( ( nPos + nSize) >= nLastPos, nPos, - "too many bytes read - version mismatch?" ); - if ( nLastPos < (nPos + nSize) ) - rStream.Seek( nPos + nSize ); - } - - delete[] pBuf; - rStream.Seek(nEndOfSizes); - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL ); - CHECK_FILEFORMAT( rStream, SFX_ITEMPOOL_TAG_ENDPOOL ); - - if ( pSecondary ) - { - if ( !bSecondaryLoaded ) - pSecondary->Load1_Impl( rStream ); - else - rStream.Seek( nSecondaryEnd ); - } - - if ( aExternName != aName ) - aName.Erase(); - - pImp->bStreaming = sal_False; - return rStream; -} - -// ----------------------------------------------------------------------- - -const SfxPoolItem* SfxItemPool::LoadSurrogate -( - SvStream& rStream, // vor einem Surrogat positionierter Stream - sal_uInt16& rWhich, // Which-Id des zu ladenden <SfxPoolItem>s - sal_uInt16 nSlotId, // Slot-Id des zu ladenden <SfxPoolItem>s - const SfxItemPool* pRefPool // <SfxItemPool> in dem das Surrogat gilt -) - -/* [Beschreibung] - - L"adt Surrogat aus 'rStream' und liefert das dadurch in 'rRefPool' - repr"asentierte SfxPoolItem zu"ruck. Ist das im Stream befindliche - Surrogat == SFX_ITEMS_DIRECT (!SFX_ITEM_POOLABLE) wird 0 zur"uckgegeben, - das Item ist direkt aus dem Stream zu laden. Bei 0xfffffff0 (SFX_ITEMS_NULL) - wird auch 0 zurueckgegeben und rWhich auf 0 gesetzt, das Item ist nicht - verfuegbar. - - Ansonsten wird ber"ucksichtigt, ob der betroffene Pool ohne Ref-Counts - geladen wird, ob aus einem neuen Pool nachgeladen wird (&rRefPool != this) - oder ob aus einem g"anzlich anders aufgebauten Pool geladen wird. - - Wird aus einem anders aufgebauten Pool geladen und die 'nSlotId' kann - nicht in eine Which-Id dieses Pools gemappt werden, wird ebenfalls 0 - zur"uckgeliefert. - - Preconditions: - Pool mu\s geladen sein - - LoadCompleted darf noch nicht gerufen worden sein - - 'rStream' steht genau an der Position, an der ein - Surrogat f"ur ein Item mit der SlotId 'nSlotId' und - der WhichId 'rWhichId' mit StoreSurrogate gepeichert - wurde - - Postconditions: - 'rStream' ist so positioniert, wie auch StoreSurrogate - sein speichern beendet hatte - - konnte ein Item geladen werden, befindet es sich - in diesem SfxItemPool - - 'rWhichId' enth"alt die ggf. gemappte Which-Id - Laufzeit: Tiefe des Ziel Sekund"arpools * 10 + 10 - - [Querverweise] - - <SfxItemPool::StoreSurrogate(SvStream&,const SfxPoolItem &)const> -*/ - -{ - // Read the first surrogate - sal_uInt32 nSurrogat(0); - rStream >> nSurrogat; - - // Is item stored directly? - if ( SFX_ITEMS_DIRECT == nSurrogat ) - return 0; - - // Item does not exist? - if ( SFX_ITEMS_NULL == nSurrogat ) - { - rWhich = 0; - return 0; - } - - // Bei einem identisch aufgebauten Pool (im Stream) kann das Surrogat - // auf jeden Fall aufgel"ost werden. - if ( !pRefPool ) - pRefPool = this; - bool bResolvable = pRefPool->GetName().Len() > 0; - if ( !bResolvable ) - { - // Bei einem anders aufgebauten Pool im Stream, mu\s die SlotId - // aus dem Stream in eine Which-Id gemappt werden k"onnen. - sal_uInt16 nMappedWhich = nSlotId ? GetWhich(nSlotId, sal_True) : 0; - if ( IsWhich(nMappedWhich) ) - { - // gemappte SlotId kann "ubernommen werden - rWhich = nMappedWhich; - bResolvable = sal_True; - } - } - - // kann Surrogat aufgel"ost werden? - const SfxPoolItem *pItem = 0; - if ( bResolvable ) - { - for ( SfxItemPool *pTarget = this; pTarget; pTarget = pTarget->pSecondary ) - { - // richtigen (Folge-) Pool gefunden? - if ( pTarget->IsInRange(rWhich) ) - { - // dflt-Attribut? - if ( SFX_ITEMS_DEFAULT == nSurrogat ) - return *(pTarget->ppStaticDefaults + - pTarget->GetIndex_Impl(rWhich)); - - SfxPoolItemArray_Impl* pItemArr = *(pTarget->pImp->ppPoolItems + - pTarget->GetIndex_Impl(rWhich)); - pItem = pItemArr && nSurrogat < pItemArr->size() - ? (*pItemArr)[nSurrogat] - : 0; - if ( !pItem ) - { - OSL_FAIL( "can't resolve surrogate" ); - rWhich = 0; // nur zur Sicherheit fuer richtige Stream-Pos - return 0; - } - - // Nachladen aus Ref-Pool? - if ( pRefPool != pMaster ) - return &pTarget->Put( *pItem ); - - // Referenzen sind NICHT schon mit Pool geladen worden? - if ( !pTarget->HasPersistentRefCounts() ) - AddRef( *pItem, 1 ); - else - return pItem; - - return pItem; - } - } - - SFX_ASSERT( sal_False, rWhich, "can't resolve Which-Id in LoadSurrogate" ); - } - - return 0; -} - -//------------------------------------------------------------------------- - - -bool SfxItemPool::StoreSurrogate -( - SvStream& rStream, - const SfxPoolItem* pItem -) const - -/* [Beschreibung] - - Speichert ein Surrogat f"ur '*pItem' in 'rStream'. - - - [R"uckgabewert] - - bool TRUE - es wurde ein echtes Surrogat gespeichert, auch - SFX_ITEMS_NULL bei 'pItem==0', - SFX_ITEMS_STATICDEFAULT und SFX_ITEMS_POOLDEFAULT - gelten als 'echte' Surrogate - - sal_False - es wurde ein Dummy-Surrogat (SFX_ITEMS_DIRECT) - gespeichert, das eigentliche Item mu\s direkt - hinterher selbst gespeichert werden -*/ - -{ - if ( pItem ) - { - bool bRealSurrogate = IsItemFlag(*pItem, SFX_ITEM_POOLABLE); - rStream << ( bRealSurrogate - ? GetSurrogate( pItem ) - : SFX_ITEMS_DIRECT ); - return bRealSurrogate; - } - - rStream << SFX_ITEMS_NULL; - return sal_True; -} - -// ----------------------------------------------------------------------- - -sal_uInt32 SfxItemPool::GetSurrogate(const SfxPoolItem *pItem) const -{ - DBG_CHKTHIS(SfxItemPool, 0); - DBG_ASSERT( pItem, "no 0-Pointer Surrogate" ); - DBG_ASSERT( !IsInvalidItem(pItem), "no Invalid-Item Surrogate" ); - DBG_ASSERT( !IsPoolDefaultItem(pItem), "no Pool-Default-Item Surrogate" ); - - if ( !IsInRange(pItem->Which()) ) - { - if ( pSecondary ) - return pSecondary->GetSurrogate( pItem ); - SFX_ASSERT( 0, pItem->Which(), "unknown Which-Id - dont ask me for surrogates" ); - } - - // Pointer auf static- oder pool-dflt-Attribut? - if( IsStaticDefaultItem(pItem) || IsPoolDefaultItem(pItem) ) - return SFX_ITEMS_DEFAULT; - - SfxPoolItemArray_Impl* pItemArr = *(pImp->ppPoolItems + GetIndex_Impl(pItem->Which())); - DBG_ASSERT(pItemArr, "ItemArr is not available"); - - for ( size_t i = 0; i < pItemArr->size(); ++i ) - { - const SfxPoolItem *p = (*pItemArr)[i]; - if ( p == pItem ) - return i; - } - SFX_ASSERT( 0, pItem->Which(), "Item not in the pool"); - return SFX_ITEMS_NULL; -} - -// ----------------------------------------------------------------------- - -bool SfxItemPool::IsInStoringRange( sal_uInt16 nWhich ) const -{ - return nWhich >= pImp->nStoringStart && - nWhich <= pImp->nStoringEnd; -} - -//------------------------------------------------------------------------ - -void SfxItemPool::SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo ) - -/* [Beschreibung] - - Mit dieser Methode kann der Which-Bereich eingeengt werden, der - von ItemSets dieses Pool (und dem Pool selbst) gespeichert wird. - Die Methode muss dazu vor <SfxItemPool::Store()> gerufen werden - und die Werte muessen auch noch gesetzt sein, wenn das eigentliche - Dokument (also die ItemSets gespeicher werden). - - Ein Zuruecksetzen ist dann nicht noetig, wenn dieser Range vor - JEDEM Speichern richtig gesetzt wird, da er nur beim Speichern - beruecksichtigt wird. - - Dieses muss fuer das 3.1-Format gemacht werden, da dort eine - Bug in der Pool-Lade-Methode vorliegt. -*/ - -{ - pImp->nStoringStart = nFrom; - pImp->nStoringEnd = nTo; -} - -// ----------------------------------------------------------------------- - -void SfxItemPool::SetVersionMap -( - sal_uInt16 nVer, /* neue Versionsnummer */ - sal_uInt16 nOldStart, /* alte erste Which-Id */ - sal_uInt16 nOldEnd, /* alte letzte Which-Id */ - sal_uInt16* pOldWhichIdTab /* Array mit genau dem Aufbau der Which-Ids - der vorhergehenden Version, in denen - die jeweils neue Which-Id steht. */ -) - -/* [Beschreibung] - - Mit dieser Methode k"onnen neue, inkompatible Which-Id-Folgen oder - Verteilungen realisiert werden. Pools, die noch mit alten Versionen - gespeichert wurden, werden dann "uber die angegebene Tabelle solange - gemappt, bis die aktuelle Version erreicht ist. Neuere Pools k"onnen - unter Verlust neuer Attribute geladen werden, da die Map mit dem Pool - gespeichert wird. - - Precondition: Pool darf noch nicht geladen sein - Postcondition: Which-Ids aus fr"uheren Versionen k"onnen bei Laden auf - Version 'nVer' gemappt werden - Laufzeit: 1.5 * new + 10 - - [Anmerkung] - - F"ur neue Which-Ranges (nStart,nEnd) m"ssen im Vergleich zur Vorg"anger- - Version (nOldStart,nOldEnd) immer gelten, da\s (nOldStart,nOldEnd) - vollst"andig in (nStart,nEnd) enthalten ist. Es ist also zul"assig, den - Which-Range in beide Richtungen zu erweitern, auch durch Einf"ugung - von Which-Ids, nicht aber ihn zu beschneiden. - - Diese Methode sollte nur im oder direkt nach Aufruf des Konstruktors - gerufen werden. - - Das Array mu\s statisch sein, da es nicht kopiert wird und au\serdem - im Copy-Ctor des SfxItemPool wiederverwendet wird. - - - [Beispiel] - - Urspr"unglich (Version 0) hatte der Pool folgende Which-Ids: - - 1:A, 2:B, 3:C, 4:D - - Nun soll eine neue Version (Version 1) zwei zus"atzliche Ids X und Y - zwischen B und C erhalten, also wie folgt aussehen: - - 1:A, 2:B, 3:X, 4:Y, 5:C, 6:D - - Dabei haben sich also die Ids 3 und 4 ge"andert. F"ur die neue Version - m"u\ste am Pool folgendes gesetzt werden: - - static sal_uInt16 nVersion1Map = { 1, 2, 5, 6 }; - pPool->SetVersionMap( 1, 1, 4, &nVersion1Map ); - - - [Querverweise] - - <SfxItemPool::IsLoadingVersionCurrent()const> - <SfxItemPool::GetNewWhich(sal_uInt16)> - <SfxItemPool::GetVersion()const> -*/ - -{ - // create new map entry to insert - const SfxPoolVersion_ImplPtr pVerMap = SfxPoolVersion_ImplPtr( new SfxPoolVersion_Impl( - nVer, nOldStart, nOldEnd, pOldWhichIdTab ) ); - pImp->aVersions.push_back( pVerMap ); - - DBG_ASSERT( nVer > pImp->nVersion, "Versions not sorted" ); - pImp->nVersion = nVer; - - // Versions-Range anpassen - for ( sal_uInt16 n = 0; n < nOldEnd-nOldStart+1; ++n ) - { - sal_uInt16 nWhich = pOldWhichIdTab[n]; - if ( nWhich < pImp->nVerStart ) - { - if ( !nWhich ) - nWhich = 0; - pImp->nVerStart = nWhich; - } - else if ( nWhich > pImp->nVerEnd ) - pImp->nVerEnd = nWhich; - } -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxItemPool::GetNewWhich -( - sal_uInt16 nFileWhich // die aus dem Stream geladene Which-Id -) const - -/* [Beschreibung] - - Diese Methoden rechnet Which-Ids aus einem File-Format in die der - aktuellen Pool-Version um. Ist das File-Format "alter, werden die vom - Pool-Entwickler mit SetVersion() gesetzten Tabellen verwendet, - ist das File-Format neuer, dann die aus dem File geladenen Tabellen. - Im letzteren Fall kann ggf. nicht jede Which-Id gemappt werden, - so da\s 0 zur"uckgeliefert wird. - - Die Berechnung ist nur f"ur Which-Ids definiert, die in der betreffenden - File-Version unterst"utzt wurden. Dies ist per Assertion abgesichert. - - Precondition: Pool mu\s geladen sein - Postcondition: unver"andert - Laufzeit: linear(Anzahl der Sekund"arpools) + - linear(Differenz zwischen alter und neuer Version) - - - [Querverweise] - - <SfxItemPool::IsLoadingVersionCurrent()const> - <SfxItemPool::SetVersionMap(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16*)> - <SfxItemPool::GetVersion()const> -*/ - -{ - // (Sekund"ar-) Pool bestimmen - if ( !IsInVersionsRange(nFileWhich) ) - { - if ( pSecondary ) - return pSecondary->GetNewWhich( nFileWhich ); - SFX_ASSERT( 0, nFileWhich, "unknown which in GetNewWhich()" ); - } - - // Version neuer/gleich/"alter? - short nDiff = (short)pImp->nLoadingVersion - (short)pImp->nVersion; - - // Which-Id einer neueren Version? - if ( nDiff > 0 ) - { - // von der Top-Version bis runter zur File-Version stufenweise mappen - for ( size_t nMap = pImp->aVersions.size(); nMap > 0; --nMap ) - { - SfxPoolVersion_ImplPtr pVerInfo = pImp->aVersions[nMap-1]; - if ( pVerInfo->_nVer > pImp->nVersion ) - { sal_uInt16 nOfs; - sal_uInt16 nCount = pVerInfo->_nEnd - pVerInfo->_nStart + 1; - for ( nOfs = 0; - nOfs <= nCount && - pVerInfo->_pMap[nOfs] != nFileWhich; - ++nOfs ) - continue; - - if ( pVerInfo->_pMap[nOfs] == nFileWhich ) - nFileWhich = pVerInfo->_nStart + nOfs; - else - return 0; - } - else - break; - } - } - - // Which-Id einer neueren Version? - else if ( nDiff < 0 ) - { - // von der File-Version bis zur aktuellen Version stufenweise mappen - for ( size_t nMap = 0; nMap < pImp->aVersions.size(); ++nMap ) - { - SfxPoolVersion_ImplPtr pVerInfo = pImp->aVersions[nMap]; - if ( pVerInfo->_nVer > pImp->nLoadingVersion ) - { - DBG_ASSERT( nFileWhich >= pVerInfo->_nStart && - nFileWhich <= pVerInfo->_nEnd, - "which-id unknown in version" ); - nFileWhich = pVerInfo->_pMap[nFileWhich - pVerInfo->_nStart]; - } - } - } - - // originale (nDiff==0) bzw. gemappte (nDiff!=0) Id zur"uckliefern - return nFileWhich; -} - -// ----------------------------------------------------------------------- - - -bool SfxItemPool::IsInVersionsRange( sal_uInt16 nWhich ) const -{ - return nWhich >= pImp->nVerStart && nWhich <= pImp->nVerEnd; -} - -// ----------------------------------------------------------------------- - -bool SfxItemPool::IsCurrentVersionLoading() const - -/* [Beschreibung] - - Mit dieser Methode kann festgestellt werden, ob die geladene Pool-Version - dem aktuellen Pool-Aufbau entspricht. - - Precondition: Pool mu\s geladen sein - Postcondition: unver"andert - Laufzeit: linear(Anzahl der Sekund"arpools) - - - [Querverweise] - - <SfxItemPool::SetVersionMap(sal_uInt16,sal_uInt16,sal_uInt16,sal_uInt16*)> - <SfxItemPool::GetNewWhich(sal_uInt16)const> - <SfxItemPool::GetVersion()const> -*/ - -{ - return ( pImp->nVersion == pImp->nLoadingVersion ) && - ( !pSecondary || pSecondary->IsCurrentVersionLoading() ); -} - -// ----------------------------------------------------------------------- - -bool SfxItemPool::IsVer2_Impl() const -{ - return pMaster->pImp->nMajorVer >= 2; -} - -//------------------------------------------------------------------------- - - -bool SfxItemPool::StoreItem( SvStream &rStream, const SfxPoolItem &rItem, - bool bDirect ) const - -/* [Beschreibung] - - Speichert das <SfxPoolItem> 'rItem' in den <SvStream> 'rStream' - entweder als Surrogat ('bDirect == sal_False') oder direkt mit 'rItem.Store()'. - Nicht poolable Items werden immer direkt gespeichert. Items ohne Which-Id, - also SID-Items, werden nicht gespeichert, ebenso wenn Items, die in der - File-Format-Version noch nicht vorhanden waren (return sal_False). - - Das Item wird im Stream wie folgt abgelegt: - - sal_uInt16 rItem.Which() - sal_uInt16 GetSlotId( rItem.Which() ) bzw. 0 falls nicht verf"urbar - sal_uInt16 GetSurrogate( &rItem ) bzw. SFX_ITEM_DIRECT bei '!SFX_ITEM_POOLBLE' - - optional (falls 'bDirect == sal_True' oder '!rItem.IsPoolable()': - - sal_uInt16 rItem.GetVersion() - sal_uLong Size - Size rItem.Store() - - - [Querverweise] - - <SfxItemPool::LoadItem(SvStream&,bool)const> -*/ - -{ - DBG_ASSERT( !IsInvalidItem(&rItem), "cannot store invalid items" ); - - if ( IsSlot( rItem.Which() ) ) - return sal_False; - const SfxItemPool *pPool = this; - while ( !pPool->IsInStoringRange(rItem.Which()) ) - if ( 0 == ( pPool = pPool->pSecondary ) ) - return sal_False; - - DBG_ASSERT( !pImp->bInSetItem || !rItem.ISA(SfxSetItem), - "SetItem contains ItemSet with SetItem" ); - - sal_uInt16 nSlotId = pPool->GetSlotId( rItem.Which(), sal_True ); - sal_uInt16 nItemVersion = rItem.GetVersion(_nFileFormatVersion); - if ( USHRT_MAX == nItemVersion ) - return sal_False; - - rStream << rItem.Which() << nSlotId; - if ( bDirect || !pPool->StoreSurrogate( rStream, &rItem ) ) - { - rStream << nItemVersion; - rStream << (sal_uInt32) 0L; // Platz fuer Laenge in Bytes - sal_uLong nIStart = rStream.Tell(); - rItem.Store(rStream, nItemVersion); - sal_uLong nIEnd = rStream.Tell(); - rStream.Seek( nIStart-4 ); - rStream << (sal_Int32) ( nIEnd-nIStart ); - rStream.Seek( nIEnd ); - } - - return sal_True; -} - -//------------------------------------------------------------------------- - - -const SfxPoolItem* SfxItemPool::LoadItem( SvStream &rStream, bool bDirect, - const SfxItemPool *pRefPool ) - -// pRefPool==-1 => nicht putten! - -{ - sal_uInt16 nWhich(0), nSlot(0); // nSurrogate; - rStream >> nWhich >> nSlot; - - sal_Bool bDontPut = (SfxItemPool*)-1 == pRefPool; - if ( bDontPut || !pRefPool ) - pRefPool = this; - - // richtigen Sekund"ar-Pool finden - while ( !pRefPool->IsInVersionsRange(nWhich) ) - { - if ( pRefPool->pSecondary ) - pRefPool = pRefPool->pSecondary; - else - { - // WID in der Version nicht vorhanden => ueberspringen - sal_uInt32 nSurro(0); - sal_uInt16 nVersion(0), nLen(0); - rStream >> nSurro; - if ( SFX_ITEMS_DIRECT == nSurro ) - { - rStream >> nVersion >> nLen; - rStream.SeekRel( nLen ); - } - return 0; - } - } - - // wird eine andere Version geladen? - bool bCurVersion = pRefPool->IsCurrentVersionLoading(); - if ( !bCurVersion ) - // Which-Id auf neue Version mappen - nWhich = pRefPool->GetNewWhich( nWhich ); - - DBG_ASSERT( !nWhich || !pImp->bInSetItem || - !pRefPool->ppStaticDefaults[pRefPool->GetIndex_Impl(nWhich)]->ISA(SfxSetItem), - "loading SetItem in ItemSet of SetItem" ); - - // soll "uber Surrogat geladen werden? - const SfxPoolItem *pItem = 0; - if ( !bDirect ) - { - // Which-Id in dieser Version bekannt? - if ( nWhich ) - // Surrogat laden, reagieren falls keins vorhanden - pItem = LoadSurrogate( rStream, nWhich, nSlot, pRefPool ); - else - // sonst "uberspringen - rStream.SeekRel( sizeof(sal_uInt16) ); - } - - // wird direkt, also nicht "uber Surrogat geladen? - if ( bDirect || ( nWhich && !pItem ) ) - { - // bDirekt bzw. nicht IsPoolable() => Item direkt laden - sal_uInt16 nVersion(0); - sal_uInt32 nLen(0); - rStream >> nVersion >> nLen; - sal_uLong nIStart = rStream.Tell(); - - // Which-Id in dieser Version bekannt? - if ( nWhich ) - { - // Item direkt laden - SfxPoolItem *pNewItem = - pRefPool->GetDefaultItem(nWhich).Create(rStream, nVersion); - if ( bDontPut ) - pItem = pNewItem; - else - if ( pNewItem ) - { - pItem = &Put(*pNewItem); - delete pNewItem; - } - else - pItem = 0; - sal_uLong nIEnd = rStream.Tell(); - DBG_ASSERT( nIEnd <= (nIStart+nLen), "read past end of item" ); - if ( (nIStart+nLen) != nIEnd ) - rStream.Seek( nIStart+nLen ); - } - else - // Item "uberspringen - rStream.Seek( nIStart+nLen ); - } - - return pItem; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx deleted file mode 100644 index d8abf88e66..0000000000 --- a/svl/source/items/poolitem.cxx +++ /dev/null @@ -1,444 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/poolitem.hxx> -#include <tools/stream.hxx> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxPoolItem) -DBG_NAME(SfxVoidItem) -// @@@ DBG_NAME(SfxInvalidItem); -DBG_NAME(SfxItemHandle) - -sal_uInt8 nSfxFlag8Val[8] = -{ - 1, 2, 4, 8, 16, 32, 64, 128 -}; - -sal_uInt16 nSfxFlag16Val[16] = -{ - 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, - 1024, 2048, 4096, 8192, 16384, 32768 -}; - -sal_uLong nSfxFlag32Val[32] = -{ - 0x1L, 0x2L, 0x4L, 0x8L, - 0x10L, 0x20L, 0x40L, 0x80L, - 0x100L, 0x200L, 0x400L, 0x800L, - 0x1000L, 0x2000L, 0x40000L, 0x8000L, - 0x10000L, 0x20000L, 0x40000L, 0x80000L, - 0x100000L, 0x200000L, 0x400000L, 0x800000L, - 0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L, - 0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L -}; - -// RTTI ------------------------------------------------------------------ - -TYPEINIT0(SfxPoolItem); -TYPEINIT1(SfxVoidItem, SfxPoolItem); -// @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem); -TYPEINIT1(SfxSetItem, SfxPoolItem); -// @@@ TYPEINIT1(SfxItemChangedHint, SfxHint); - -// ------------------------------------------------------------------------ -#if OSL_DEBUG_LEVEL > 1 -static sal_uLong nItemCount = 0; - -const char* pw1 = "Wow! 10.000 items!"; -const char* pw2 = "Wow! 100.000 items!"; -const char* pw3 = "Wow! 1.000.000 items!"; -const char* pw4 = "Wow! 50.000.000 items!"; -const char* pw5 = "Wow! 10.000.000 items!"; -#endif - -IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem) - -// SfxPoolItem ----------------------------------------------------------- -SfxPoolItem::SfxPoolItem( sal_uInt16 nW ) - : nRefCount( 0 ), - nWhich( nW ) - , nKind( 0 ) -{ - DBG_CTOR(SfxPoolItem, 0); - DBG_ASSERT(nW <= SHRT_MAX, "Which Bereich ueberschritten"); -#if OSL_DEBUG_LEVEL > 1 - ++nItemCount; - if ( pw1 && nItemCount>=10000 ) - { - DBG_WARNING( pw1 ); - pw1 = NULL; - } - if ( pw2 && nItemCount>=100000 ) - { - DBG_WARNING( pw2 ); - pw2 = NULL; - } - if ( pw3 && nItemCount>=1000000 ) - { - DBG_WARNING( pw3 ); - pw3 = NULL; - } - if ( pw4 && nItemCount>=5000000 ) - { - DBG_WARNING( pw4 ); - pw4 = NULL; - } - if ( pw5 && nItemCount>=10000000 ) - { - DBG_WARNING( pw5 ); - pw5 = NULL; - } -#endif -} - -// ----------------------------------------------------------------------- -SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy ) - : nRefCount( 0 ), // wird ja ein neues Object! - nWhich( rCpy.Which() ) // Funktion rufen wg. ChkThis() - , nKind( 0 ) -{ - DBG_CTOR(SfxPoolItem, 0); -#if OSL_DEBUG_LEVEL > 1 - ++nItemCount; - if ( pw1 && nItemCount>=10000 ) - { - DBG_WARNING( pw1 ); - pw1 = NULL; - } - if ( pw2 && nItemCount>=100000 ) - { - DBG_WARNING( pw2 ); - pw2 = NULL; - } - if ( pw3 && nItemCount>=1000000 ) - { - DBG_WARNING( pw3 ); - pw3 = NULL; - } - if ( pw4 && nItemCount>=5000000 ) - { - DBG_WARNING( pw4 ); - pw4 = NULL; - } - if ( pw5 && nItemCount>=10000000 ) - { - DBG_WARNING( pw5 ); - pw5 = NULL; - } -#endif -} - -// ------------------------------------------------------------------------ -SfxPoolItem::~SfxPoolItem() -{ - DBG_DTOR(SfxPoolItem, 0); - DBG_ASSERT(nRefCount == 0 || nRefCount > SFX_ITEMS_MAXREF, "destroying item in use" ); -#if OSL_DEBUG_LEVEL > 1 - --nItemCount; -#endif -} - -// ------------------------------------------------------------------------ -int SfxPoolItem::Compare( const SfxPoolItem& ) const -{ - return 0; -} - -// ------------------------------------------------------------------------ -int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const -{ - return Compare( rWith ); -} - -// ------------------------------------------------------------------------ -int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const -{ - DBG_CHKTHIS(SfxPoolItem, 0); - return rCmp.Type() == Type(); -} - -// ----------------------------------------------------------------------- -#ifndef TF_POOLABLE - -int SfxPoolItem::IsPoolable() const -{ - DBG_CHKTHIS(SfxPoolItem, 0); - return sal_True; -} -#endif - -// ----------------------------------------------------------------------- -SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const -{ - DBG_CHKTHIS(SfxPoolItem, 0); - return Clone(0); -} - -// ----------------------------------------------------------------------- -sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxPoolItem, 0); - return 0; -} - -// ----------------------------------------------------------------------- -SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxPoolItem, 0); - return rStream; -} - -//============================================================================ -// static -bool SfxPoolItem::readByteString(SvStream & rStream, UniString & rString) -{ - rStream.ReadByteString(rString); - return rStream.GetError() == ERRCODE_NONE; -} - -//============================================================================ -// static -void SfxPoolItem::writeByteString(SvStream & rStream, - UniString const & rString) -{ - rStream.WriteByteString(rString); -} - -//============================================================================ -// static -bool SfxPoolItem::readUnicodeString(SvStream & rStream, UniString & rString, - bool bUnicode) -{ - rStream.ReadByteString(rString, - bUnicode ? RTL_TEXTENCODING_UCS2 : - rStream.GetStreamCharSet()); - return rStream.GetError() == ERRCODE_NONE; -} - -//============================================================================ -// static -void SfxPoolItem::writeUnicodeString(SvStream & rStream, - UniString const & rString) -{ - rStream.WriteByteString(rString, RTL_TEXTENCODING_UCS2); -} - -// ------------------------------------------------------------------------ -SfxItemPresentation SfxPoolItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, // IN: wie formatiert werden soll - SfxMapUnit /*eCoreMetric*/, // IN: Ma\seinheit des SfxPoolItems - SfxMapUnit /*ePresentationMetric*/, // IN: Wunsch-Ma\einheit der Darstellung - XubString& /*rText*/, // OUT: textuelle Darstellung - const IntlWrapper * -) const - -/* [Beschreibung] - - "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen - eine textuelle Datstellung des Wertes erhalten werden. Sie sollte - von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden. - - Da die Ma\seinheit des Wertes im SfxItemPool nur "uber - <SfxItemPool::GetMetric(sal_uInt16)const> erfragbar ist, und nicht etwa - in der SfxPoolItem-Instanz oder -Subklasse verf"ugbar ist, wird die - eigene Ma\seinheit als 'eCoreMetric' "ubergeben. - - Die darzustellende Ma\seinheit wird als 'ePresentationMetric' - "ubergeben. - - - [R"uckgabewert] - - SfxItemPresentation SFX_ITEM_PRESENTATION_NONE - es konnte keine Text-Darstellung erzeugt werden - - SFX_ITEM_PRESENTATION_NAMELESS - es konnte eine Text-Darstellung (ggf. mit - Ma\seinheit) erzeugt werden, die jedoch keine - semantische Bedeutung enth"alt - - SFX_ITEM_PRESENTATION_COMPLETE - es konnte eine komplette Text-Darstellung mit - semantischer Bedeutung (und ggf. Ma\seinheit) - erzeugt werden - - - [Beispiele] - - pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... ) - "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS - - pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... ) - "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS - (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt, - kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird. - - pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... ) - "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..." -*/ - -{ - return SFX_ITEM_PRESENTATION_NONE; -} - -// SfxVoidItem ------------------------------------------------------------ -SfxVoidItem::SfxVoidItem( sal_uInt16 which ): - SfxPoolItem(which) -{ - DBG_CTOR(SfxVoidItem, 0); -} - -// SfxVoidItem ------------------------------------------------------------ -SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy): - SfxPoolItem(rCopy) -{ - DBG_CTOR(SfxVoidItem, 0); -} - -// ------------------------------------------------------------------------ -int SfxVoidItem::operator==( const SfxPoolItem& -#ifdef DBG_UTIL -rCmp -#endif -) const -{ - DBG_CHKTHIS(SfxVoidItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" ); - return sal_True; -} - -// ------------------------------------------------------------------------ -SfxItemPresentation SfxVoidItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * -) const -{ - DBG_CHKTHIS(SfxVoidItem, 0); - rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Void")); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -// ------------------------------------------------------------------------ -SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(SfxVoidItem, 0); - return new SfxVoidItem(*this); -} - -// SfxInvalidItem --------------------------------------------------------- - -// SfxItemHandle ---------------------------------------------------------- -SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem): - pRef(new sal_uInt16(1)), - pItem(rItem.Clone(0)) -{ - DBG_CTOR(SfxItemHandle, 0); -} - -// ------------------------------------------------------------------------ -SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy): - pRef(rCopy.pRef), - pItem(rCopy.pItem) -{ - DBG_CTOR(SfxItemHandle, 0); - ++(*pRef); -} - -// ------------------------------------------------------------------------ -const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy) -{ - DBG_CHKTHIS(SfxItemHandle, 0); - if(&rCopy == this || pItem == rCopy.pItem) - return *this; - --(*pRef); - if(!(*pRef)) - { - delete pItem; - pItem = 0; - } - pRef = rCopy.pRef; - ++(*pRef); - pItem = rCopy.pItem; - return *this; -} - -// ------------------------------------------------------------------------ -SfxItemHandle::~SfxItemHandle() -{ - DBG_DTOR(SfxItemHandle, 0); - --(*pRef); - if(!(*pRef)) { - delete pRef; pRef = 0; - delete pItem; pItem = 0; - } -} - -// ------------------------------------------------------------------------ -bool SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ ) -{ - return false; -} - -// ------------------------------------------------------------------------ -bool SfxPoolItem::HasMetrics() const -{ - return false; -} - -// ----------------------------------------------------------------------- - -bool SfxPoolItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8 ) const -{ - OSL_FAIL("There is no implementation for QueryValue for this item!"); - return false; -} - -// ----------------------------------------------------------------------- - -bool SfxPoolItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8 ) -{ - OSL_FAIL("There is no implementation for PutValue for this item!"); - return false; -} - -SfxVoidItem::~SfxVoidItem() -{ - DBG_DTOR(SfxVoidItem, 0); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/ptitem.cxx b/svl/source/items/ptitem.cxx deleted file mode 100644 index 14db870de3..0000000000 --- a/svl/source/items/ptitem.cxx +++ /dev/null @@ -1,198 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/ptitem.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/awt/Point.hpp> -#include <tools/stream.hxx> - -#include <svl/poolitem.hxx> -#include <svl/memberid.hrc> - -using namespace ::com::sun::star; -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxPointItem) - -#define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L)) -#define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L)) - -// ----------------------------------------------------------------------- - -TYPEINIT1_AUTOFACTORY(SfxPointItem, SfxPoolItem); - -// ----------------------------------------------------------------------- - -SfxPointItem::SfxPointItem() -{ - DBG_CTOR(SfxPointItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxPointItem::SfxPointItem( sal_uInt16 nW, const Point& rVal ) : - SfxPoolItem( nW ), - aVal( rVal ) -{ - DBG_CTOR(SfxPointItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxPointItem::SfxPointItem( const SfxPointItem& rItem ) : - SfxPoolItem( rItem ), - aVal( rItem.aVal ) -{ - DBG_CTOR(SfxPointItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxItemPresentation SfxPointItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * -) const -{ - DBG_CHKTHIS(SfxPointItem, 0); - rText = UniString::CreateFromInt32(aVal.X()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += UniString::CreateFromInt32(aVal.Y()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -// ----------------------------------------------------------------------- - -int SfxPointItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_CHKTHIS(SfxPointItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - return ((SfxPointItem&)rItem).aVal == aVal; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxPointItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(SfxPointItem, 0); - return new SfxPointItem( *this ); -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxPointItem::Create(SvStream &rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxPointItem, 0); - Point aStr; - rStream >> aStr; - return new SfxPointItem(Which(), aStr); -} - -// ----------------------------------------------------------------------- - -SvStream& SfxPointItem::Store(SvStream &rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxPointItem, 0); - rStream << aVal; - return rStream; -} - -// ----------------------------------------------------------------------- - -bool SfxPointItem::QueryValue( uno::Any& rVal, - sal_uInt8 nMemberId ) const -{ - sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); - awt::Point aTmp(aVal.X(), aVal.Y()); - if( bConvert ) - { - aTmp.X = TWIP_TO_MM100(aTmp.X); - aTmp.Y = TWIP_TO_MM100(aTmp.Y); - } - nMemberId &= ~CONVERT_TWIPS; - switch ( nMemberId ) - { - case 0: rVal <<= aTmp; break; - case MID_X: rVal <<= aTmp.X; break; - case MID_Y: rVal <<= aTmp.Y; break; - default: OSL_FAIL("Wrong MemberId!"); return true; - } - - return true; -} - -// ----------------------------------------------------------------------- - -bool SfxPointItem::PutValue( const uno::Any& rVal, - sal_uInt8 nMemberId ) -{ - sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); - nMemberId &= ~CONVERT_TWIPS; - bool bRet = false; - awt::Point aValue; - sal_Int32 nVal = 0; - if ( !nMemberId ) - { - bRet = ( rVal >>= aValue ); - if( bConvert ) - { - aValue.X = MM100_TO_TWIP(aValue.X); - aValue.Y = MM100_TO_TWIP(aValue.Y); - } - } - else - { - bRet = ( rVal >>= nVal ); - if( bConvert ) - nVal = MM100_TO_TWIP( nVal ); - } - - if ( bRet ) - { - switch ( nMemberId ) - { - case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break; - case MID_X: aVal.setX( nVal ); break; - case MID_Y: aVal.setY( nVal ); break; - default: OSL_FAIL("Wrong MemberId!"); return false; - } - } - - return bRet; -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/rectitem.cxx b/svl/source/items/rectitem.cxx deleted file mode 100644 index ed53439bfc..0000000000 --- a/svl/source/items/rectitem.cxx +++ /dev/null @@ -1,203 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/rectitem.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/awt/Rectangle.hpp> -#include <tools/stream.hxx> - -#include <svl/poolitem.hxx> -#include <svl/memberid.hrc> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxRectangleItem) - - -// ----------------------------------------------------------------------- - -TYPEINIT1_AUTOFACTORY(SfxRectangleItem, SfxPoolItem); - -// ----------------------------------------------------------------------- - -SfxRectangleItem::SfxRectangleItem() -{ - DBG_CTOR(SfxRectangleItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, const Rectangle& rVal ) : - SfxPoolItem( nW ), - aVal( rVal ) -{ - DBG_CTOR(SfxRectangleItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, SvStream &rStream ) : - SfxPoolItem( nW ) -{ - DBG_CTOR(SfxRectangleItem, 0); - rStream >> aVal; -} - -// ----------------------------------------------------------------------- - -SfxRectangleItem::SfxRectangleItem( const SfxRectangleItem& rItem ) : - SfxPoolItem( rItem ), - aVal( rItem.aVal ) -{ - DBG_CTOR(SfxRectangleItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxItemPresentation SfxRectangleItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * -) const -{ - DBG_CHKTHIS(SfxRectangleItem, 0); - rText = UniString::CreateFromInt32(aVal.Top()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += UniString::CreateFromInt32(aVal.Left()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += UniString::CreateFromInt32(aVal.Bottom()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += UniString::CreateFromInt32(aVal.Right()); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -// ----------------------------------------------------------------------- - -int SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_CHKTHIS(SfxRectangleItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - return ((SfxRectangleItem&)rItem).aVal == aVal; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxRectangleItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(SfxRectangleItem, 0); - return new SfxRectangleItem( *this ); -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxRectangleItem::Create(SvStream &rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxRectangleItem, 0); - Rectangle aStr; - rStream >> aStr; - return new SfxRectangleItem(Which(), aStr); -} - -// ----------------------------------------------------------------------- - -SvStream& SfxRectangleItem::Store(SvStream &rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxRectangleItem, 0); - rStream << aVal; - return rStream; -} - - -// ----------------------------------------------------------------------- -bool SfxRectangleItem::QueryValue( com::sun::star::uno::Any& rVal, - sal_uInt8 nMemberId) const -{ - nMemberId &= ~CONVERT_TWIPS; - switch ( nMemberId ) - { - case 0: - { - rVal <<= com::sun::star::awt::Rectangle( aVal.getX(), - aVal.getY(), - aVal.getWidth(), - aVal.getHeight() ); - break; - } - case MID_RECT_LEFT: rVal <<= aVal.getX(); break; - case MID_RECT_RIGHT: rVal <<= aVal.getY(); break; - case MID_WIDTH: rVal <<= aVal.getWidth(); break; - case MID_HEIGHT: rVal <<= aVal.getHeight(); break; - default: OSL_FAIL("Wrong MemberID!"); return false; - } - - return true; -} - -// ----------------------------------------------------------------------- -bool SfxRectangleItem::PutValue( const com::sun::star::uno::Any& rVal, - sal_uInt8 nMemberId ) -{ - bool bRet = false; - nMemberId &= ~CONVERT_TWIPS; - com::sun::star::awt::Rectangle aValue; - sal_Int32 nVal = 0; - if ( !nMemberId ) - bRet = (rVal >>= aValue); - else - bRet = (rVal >>= nVal); - - if ( bRet ) - { - switch ( nMemberId ) - { - case 0: - aVal.setX( aValue.X ); - aVal.setY( aValue.Y ); - aVal.setWidth( aValue.Width ); - aVal.setHeight( aValue.Height ); - break; - case MID_RECT_LEFT: aVal.setX( nVal ); break; - case MID_RECT_RIGHT: aVal.setY( nVal ); break; - case MID_WIDTH: aVal.setWidth( nVal ); break; - case MID_HEIGHT: aVal.setHeight( nVal ); break; - default: OSL_FAIL("Wrong MemberID!"); return false; - } - } - - return bRet; -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/rngitem.cxx b/svl/source/items/rngitem.cxx deleted file mode 100644 index 7df191d84f..0000000000 --- a/svl/source/items/rngitem.cxx +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/stream.hxx> - -#ifndef NUMTYPE - -#define NUMTYPE sal_uInt16 -#define SfxXRangeItem SfxRangeItem -#define SfxXRangesItem SfxUShortRangesItem -#include <svl/rngitem.hxx> -#include "rngitem_inc.cxx" - -#define NUMTYPE sal_uInt32 -#define SfxXRangeItem SfxULongRangeItem -#define SfxXRangesItem SfxULongRangesItem -#include <svl/rngitem.hxx> -#include "rngitem_inc.cxx" - -#else - -// We leave this condition just in case NUMTYPE has been defined externally to this -// file and we are supposed to define the SfxXRangeItem based on that. - -#include "rngitem_inc.cxx" - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/rngitem_inc.cxx b/svl/source/items/rngitem_inc.cxx deleted file mode 100644 index 6c21129963..0000000000 --- a/svl/source/items/rngitem_inc.cxx +++ /dev/null @@ -1,243 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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. - * - ************************************************************************/ - -// This snippet of code is included by rngitem.cxx but not compiled directly. -// Ugly hack, probably due to lack of templates in the 20th century. - -static inline NUMTYPE Count_Impl(const NUMTYPE * pRanges) -{ - NUMTYPE nCount = 0; - for (; *pRanges; pRanges += 2) nCount += 2; - return nCount; -} - -// ----------------------------------------------------------------------- - -TYPEINIT1_AUTOFACTORY(SfxXRangeItem, SfxPoolItem); -TYPEINIT1_AUTOFACTORY(SfxXRangesItem, SfxPoolItem); - -NUMTYPE Count_Impl( const NUMTYPE *pRanges ); - -// ----------------------------------------------------------------------- - -SfxXRangeItem::SfxXRangeItem() -{ - nFrom = 0; - nTo = 0; -} - -// ----------------------------------------------------------------------- - -SfxXRangeItem::SfxXRangeItem( sal_uInt16 which, NUMTYPE from, NUMTYPE to ): - SfxPoolItem( which ), - nFrom( from ), - nTo( to ) -{ -} - - -// ----------------------------------------------------------------------- - -SfxXRangeItem::SfxXRangeItem( sal_uInt16 nW, SvStream &rStream ) : - SfxPoolItem( nW ) -{ - rStream >> nFrom; - rStream >> nTo; -} - -// ----------------------------------------------------------------------- - -SfxXRangeItem::SfxXRangeItem( const SfxXRangeItem& rItem ) : - SfxPoolItem( rItem ) -{ - nFrom = rItem.nFrom; - nTo = rItem.nTo; -} - -// ----------------------------------------------------------------------- - -SfxItemPresentation SfxXRangeItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * -) const -{ - rText = UniString::CreateFromInt64(nFrom); - rText += ':'; - rText += UniString::CreateFromInt64(nTo); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -// ----------------------------------------------------------------------- - -int SfxXRangeItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - SfxXRangeItem* pT = (SfxXRangeItem*)&rItem; - if( nFrom==pT->nFrom && nTo==pT->nTo ) - return 1; - return 0; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxXRangeItem::Clone(SfxItemPool *) const -{ - return new SfxXRangeItem( Which(), nFrom, nTo ); -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxXRangeItem::Create(SvStream &rStream, sal_uInt16) const -{ - NUMTYPE nVon, nBis; - rStream >> nVon; - rStream >> nBis; - return new SfxXRangeItem( Which(), nVon, nBis ); -} - -// ----------------------------------------------------------------------- - -SvStream& SfxXRangeItem::Store(SvStream &rStream, sal_uInt16) const -{ - rStream << nFrom; - rStream << nTo; - return rStream; -} - -//========================================================================= - -SfxXRangesItem::SfxXRangesItem() -: _pRanges(0) -{ -} - -//------------------------------------------------------------------------- - -SfxXRangesItem::SfxXRangesItem( sal_uInt16 nWID, const NUMTYPE *pRanges ) -: SfxPoolItem( nWID ) -{ - NUMTYPE nCount = Count_Impl(pRanges) + 1; - _pRanges = new NUMTYPE[nCount]; - memcpy( _pRanges, pRanges, sizeof(NUMTYPE) * nCount ); -} - -//------------------------------------------------------------------------- - -SfxXRangesItem::SfxXRangesItem( sal_uInt16 nWID, SvStream &rStream ) -: SfxPoolItem( nWID ) -{ - NUMTYPE nCount; - rStream >> nCount; - _pRanges = new NUMTYPE[nCount + 1]; - for ( NUMTYPE n = 0; n < nCount; ++n ) - rStream >> _pRanges[n]; - _pRanges[nCount] = 0; -} - -//------------------------------------------------------------------------- - -SfxXRangesItem::SfxXRangesItem( const SfxXRangesItem& rItem ) -: SfxPoolItem( rItem ) -{ - NUMTYPE nCount = Count_Impl(rItem._pRanges) + 1; - _pRanges = new NUMTYPE[nCount]; - memcpy( _pRanges, rItem._pRanges, sizeof(NUMTYPE) * nCount ); -} - -//------------------------------------------------------------------------- - -SfxXRangesItem::~SfxXRangesItem() -{ - delete _pRanges; -} - -//------------------------------------------------------------------------- - -int SfxXRangesItem::operator==( const SfxPoolItem &rItem ) const -{ - const SfxXRangesItem &rOther = (const SfxXRangesItem&) rItem; - if ( !_pRanges && !rOther._pRanges ) - return sal_True; - if ( _pRanges || rOther._pRanges ) - return sal_False; - - NUMTYPE n; - for ( n = 0; _pRanges[n] && rOther._pRanges[n]; ++n ) - if ( *_pRanges != rOther._pRanges[n] ) - return 0; - - return !_pRanges[n] && !rOther._pRanges[n]; -} - -//------------------------------------------------------------------------- - -SfxItemPresentation SfxXRangesItem::GetPresentation( SfxItemPresentation /*ePres*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresMetric*/, - XubString &/*rText*/, - const IntlWrapper * ) const -{ - HACK(n. i.) - return SFX_ITEM_PRESENTATION_NONE; -} - -//------------------------------------------------------------------------- - -SfxPoolItem* SfxXRangesItem::Clone( SfxItemPool * ) const -{ - return new SfxXRangesItem( *this ); -} - -//------------------------------------------------------------------------- - -SfxPoolItem* SfxXRangesItem::Create( SvStream &rStream, sal_uInt16 ) const -{ - return new SfxXRangesItem( Which(), rStream ); -} - -//------------------------------------------------------------------------- - -SvStream& SfxXRangesItem::Store( SvStream &rStream, sal_uInt16 ) const -{ - NUMTYPE nCount = Count_Impl( _pRanges ); - rStream >> nCount; - for ( NUMTYPE n = 0; _pRanges[n]; ++n ) - rStream >> _pRanges[n]; - return rStream; -} - - -#undef NUMTYPE -#undef SfxXRangeItem -#undef SfxXRangesItem - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/sfontitm.cxx b/svl/source/items/sfontitm.cxx deleted file mode 100644 index 60d59398fc..0000000000 --- a/svl/source/items/sfontitm.cxx +++ /dev/null @@ -1,141 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/stream.hxx> -#include <tools/vcompat.hxx> -#include <svl/sfontitm.hxx> - -//============================================================================ -// -// class SfxFontItem -// -//============================================================================ - -TYPEINIT1(SfxFontItem, SfxPoolItem); - -//============================================================================ -// virtual -int SfxFontItem::operator ==(const SfxPoolItem & rItem) const -{ - const SfxFontItem * pFontItem = PTR_CAST(SfxFontItem, &rItem); - return pFontItem && m_bHasFont == pFontItem->m_bHasFont - && m_bHasColor == pFontItem->m_bHasColor - && m_bHasFillColor == pFontItem->m_bHasFillColor - && (!m_bHasColor || m_aColor == pFontItem->m_aColor) - && (!m_bHasFillColor || m_aFillColor == pFontItem->m_aFillColor) - && (!m_bHasFont || (m_bKerning == pFontItem->m_bKerning - && m_bShadow == pFontItem->m_bShadow - && m_bOutline == pFontItem->m_bOutline - && m_bWordLine == pFontItem->m_bWordLine - && m_nOrientation == pFontItem->m_nOrientation - && m_nStrikeout == pFontItem->m_nStrikeout - && m_nUnderline == pFontItem->m_nUnderline - && m_nItalic == pFontItem->m_nItalic - && m_nWidthType == pFontItem->m_nWidthType - && m_nWeight == pFontItem->m_nWeight - && m_nPitch == pFontItem->m_nPitch - && m_nFamily == pFontItem->m_nFamily - && m_nLanguage == pFontItem->m_nLanguage - && m_nCharSet == pFontItem->m_nCharSet - && m_aFillColor == pFontItem->m_aFillColor - && m_aColor == pFontItem->m_aColor - && m_aSize == pFontItem->m_aSize - && m_aStyleName == pFontItem->m_aStyleName - && m_aName == pFontItem->m_aName)); -} - -//============================================================================ -// virtual -SfxPoolItem * SfxFontItem::Create(SvStream & rStream, sal_uInt16) const -{ - VersionCompat aItemCompat(rStream, STREAM_READ); - SfxFontItem * pItem = new SfxFontItem(Which()); - { - VersionCompat aFontCompat(rStream, STREAM_READ); - readByteString(rStream, pItem->m_aName); - readByteString(rStream, pItem->m_aStyleName); - rStream >> pItem->m_aSize; - sal_Int16 nCharSet = 0; - rStream >> nCharSet; - pItem->m_nCharSet = rtl_TextEncoding(nCharSet); - rStream >> pItem->m_nFamily >> pItem->m_nPitch >> pItem->m_nWeight - >> pItem->m_nUnderline >> pItem->m_nStrikeout - >> pItem->m_nItalic; - sal_Int16 nLanguage = 0; - rStream >> nLanguage; - pItem->m_nLanguage = LanguageType(nLanguage); - rStream >> pItem->m_nWidthType >> pItem->m_nOrientation; - sal_Int8 nWordLine = 0; - rStream >> nWordLine; - pItem->m_bWordLine = nWordLine != 0; - sal_Int8 nOutline = 0; - rStream >> nOutline; - pItem->m_bOutline = nOutline != 0; - sal_Int8 nShadow = 0; - rStream >> nShadow; - pItem->m_bShadow = nShadow != 0; - sal_Int8 nKerning = 0; - rStream >> nKerning; - pItem->m_bKerning = nKerning != 0; - } - pItem->m_aColor.Read(rStream, sal_True); - pItem->m_aFillColor.Read(rStream, sal_True); - sal_Int16 nFlags = 0; - rStream >> nFlags; - pItem->m_bHasFont = (nFlags & 4) != 0; - pItem->m_bHasColor = (nFlags & 1) != 0; - pItem->m_bHasFillColor = (nFlags & 2) != 0; - return pItem; -} - -//============================================================================ -// virtual -SvStream & SfxFontItem::Store(SvStream & rStream, sal_uInt16) const -{ - VersionCompat aItemCompat(rStream, STREAM_WRITE, 1); - { - VersionCompat aFontCompat(rStream, STREAM_WRITE, 1); - writeByteString(rStream, m_aName); - writeByteString(rStream, m_aStyleName); - rStream << m_aSize << sal_Int16(m_nCharSet) - << m_nFamily << m_nPitch << m_nWeight << m_nUnderline - << m_nStrikeout << m_nItalic << sal_Int16(m_nLanguage) - << m_nWidthType << m_nOrientation << sal_Int8(m_bWordLine) - << sal_Int8(m_bOutline) << sal_Int8(m_bShadow) - << sal_Int8(m_bKerning); - } - SAL_CONST_CAST(Color &, m_aColor).Write(rStream, sal_True); - SAL_CONST_CAST(Color &, m_aFillColor).Write(rStream, sal_True); - rStream << sal_Int16(m_bHasFont << 2 | m_bHasColor - | m_bHasFillColor << 1); - return rStream; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/sitem.cxx b/svl/source/items/sitem.cxx deleted file mode 100644 index 9dda753ae5..0000000000 --- a/svl/source/items/sitem.cxx +++ /dev/null @@ -1,111 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/string.hxx> -#include <tools/stream.hxx> - -#include <svl/poolitem.hxx> -#include <svl/itemset.hxx> - - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxSetItem) - -// -------------------------------------------------------------------------- - -SfxSetItem::SfxSetItem( sal_uInt16 which, const SfxItemSet &rSet) : - SfxPoolItem(which), - pSet(rSet.Clone(sal_True)) -{ - DBG_CTOR(SfxSetItem, 0); -} - -// -------------------------------------------------------------------------- - -SfxSetItem::SfxSetItem( sal_uInt16 which, SfxItemSet *pS) : - SfxPoolItem(which), - pSet(pS) -{ - DBG_CTOR(SfxSetItem, 0); - DBG_ASSERT(pS, "SfxSetItem without set constructed" ); -} - -// -------------------------------------------------------------------------- - -SfxSetItem::SfxSetItem( const SfxSetItem& rCopy, SfxItemPool *pPool ) : - SfxPoolItem(rCopy.Which()), - pSet(rCopy.pSet->Clone(sal_True, pPool)) -{ - DBG_CTOR(SfxSetItem, 0); -} - -// -------------------------------------------------------------------------- - -SfxSetItem::~SfxSetItem() -{ - DBG_DTOR(SfxSetItem, 0); - delete pSet; pSet = 0; -} - -// -------------------------------------------------------------------------- - -int SfxSetItem::operator==( const SfxPoolItem& rCmp) const -{ - DBG_CHKTHIS(SfxSetItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" ); - return *pSet == *(((const SfxSetItem &)rCmp).pSet); -} - -// -------------------------------------------------------------------------- - -SfxItemPresentation SfxSetItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& /*rText*/, - const IntlWrapper * -) const -{ - DBG_CHKTHIS(SfxSetItem, 0); - return SFX_ITEM_PRESENTATION_NONE; -} - -// -------------------------------------------------------------------------- - -SvStream& SfxSetItem::Store(SvStream& rStream, sal_uInt16) const -{ - GetItemSet().Store(rStream); - return rStream; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/slstitm.cxx b/svl/source/items/slstitm.cxx deleted file mode 100644 index 5f61238925..0000000000 --- a/svl/source/items/slstitm.cxx +++ /dev/null @@ -1,403 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/slstitm.hxx> -#include <svl/poolitem.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/uno/Sequence.hxx> -#include <tools/stream.hxx> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxStringListItem) - -// ----------------------------------------------------------------------- - -TYPEINIT1_AUTOFACTORY(SfxStringListItem, SfxPoolItem); - -class SfxImpStringList -{ -public: - sal_uInt16 nRefCount; - std::vector<String> aList; - - SfxImpStringList() { nRefCount = 1; } - ~SfxImpStringList(); - void Sort( sal_Bool bAscending); -}; - -//------------------------------------------------------------------------ - -SfxImpStringList::~SfxImpStringList() -{ - DBG_ASSERT(nRefCount!=0xffff,"ImpList already deleted"); - nRefCount = 0xffff; -} - -//------------------------------------------------------------------------ - -void SfxImpStringList::Sort( sal_Bool bAscending) -{ - sal_uLong nCount = aList.size(); - if( nCount > 1 ) - { - nCount -= 2; - // Bubble Dir Einen - sal_Bool bSwapped = sal_True; - while( bSwapped ) - { - bSwapped = sal_False; - for( sal_uLong nCur = 0; nCur <= nCount; nCur++ ) - { - String aStr1 = aList[nCur]; - String aStr2 = aList[nCur+1]; - // COMPARE_GREATER => pStr2 ist groesser als pStr1 - StringCompare eCompare = aStr1.CompareIgnoreCaseToAscii( aStr2 ); //@@@ - sal_Bool bSwap = sal_False; - if( bAscending ) - { - if( eCompare == COMPARE_LESS ) - bSwap = sal_True; - } - else if( eCompare == COMPARE_GREATER ) - bSwap = sal_True; - - if( bSwap ) - { - bSwapped = sal_True; - aList[nCur+1] = aStr1; - aList[nCur] = aStr2; - } - } - } - } -} - -// class SfxStringListItem ----------------------------------------------- - -SfxStringListItem::SfxStringListItem() : - pImp(NULL) -{ -} - -//------------------------------------------------------------------------ - -SfxStringListItem::SfxStringListItem( sal_uInt16 which, const std::vector<String>* pList ) : - SfxPoolItem( which ), - pImp(NULL) -{ - // PB: das Putten einer leeren Liste funktionierte nicht, - // deshalb habe ich hier die Abfrage nach dem Count auskommentiert - if( pList /*!!! && pList->Count() */ ) - { - pImp = new SfxImpStringList; - - if (pImp) - pImp->aList = *pList; - } -} - -//------------------------------------------------------------------------ - -SfxStringListItem::SfxStringListItem( sal_uInt16 which, SvStream& rStream ) : - SfxPoolItem( which ), - pImp(NULL) -{ - long nEntryCount; - rStream >> nEntryCount; - - if( nEntryCount ) - pImp = new SfxImpStringList; - - if (pImp) - { - long i; - String aStr; - for( i=0; i < nEntryCount; i++ ) - { - readByteString(rStream, aStr); - pImp->aList.push_back(aStr); - } - } -} - -//------------------------------------------------------------------------ - -SfxStringListItem::SfxStringListItem( const SfxStringListItem& rItem ) : - SfxPoolItem( rItem ), - pImp(rItem.pImp) -{ - if( pImp ) - { - DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); - pImp->nRefCount++; - } -} - -//------------------------------------------------------------------------ - -SfxStringListItem::~SfxStringListItem() -{ - if( pImp ) - { - DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); - if( pImp->nRefCount > 1 ) - pImp->nRefCount--; - else - delete pImp; - } -} - -//------------------------------------------------------------------------ - -std::vector<String>& SfxStringListItem::GetList() -{ - if( !pImp ) - pImp = new SfxImpStringList; - DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); - return pImp->aList; -} - -const std::vector<String>& SfxStringListItem::GetList () const -{ - return SAL_CONST_CAST(SfxStringListItem *, this)->GetList(); -} - -//------------------------------------------------------------------------ - -int SfxStringListItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - - SfxStringListItem* pItem = (SfxStringListItem*)&rItem; - - return pImp == pItem->pImp; -} - -//------------------------------------------------------------------------ - -SfxItemPresentation SfxStringListItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * -) const -{ - rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("(List)")); - return SFX_ITEM_PRESENTATION_NONE; -} - -//------------------------------------------------------------------------ - -SfxPoolItem* SfxStringListItem::Clone( SfxItemPool *) const -{ - return new SfxStringListItem( *this ); - /* - if( pImp ) - return new SfxStringListItem( Which(), &(pImp->aList) ); - else - return new SfxStringListItem( Which(), NULL ); - */ - -} - -//------------------------------------------------------------------------ - -SfxPoolItem* SfxStringListItem::Create( SvStream & rStream, sal_uInt16 ) const -{ - return new SfxStringListItem( Which(), rStream ); -} - -//------------------------------------------------------------------------ - -SvStream& SfxStringListItem::Store( SvStream & rStream, sal_uInt16 ) const -{ - if( !pImp ) - { - rStream << 0L; - return rStream; - } - - DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); - - sal_uInt32 nCount = pImp->aList.size(); - rStream << nCount; - - for( sal_uInt32 i=0; i < nCount; i++ ) - writeByteString(rStream, pImp->aList[i]); - - return rStream; -} - -//------------------------------------------------------------------------ - -void SfxStringListItem::SetString( const XubString& rStr ) -{ - DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0"); - - if ( pImp && (pImp->nRefCount == 1) ) - delete pImp; - else - if( pImp ) - pImp->nRefCount--; - pImp = new SfxImpStringList; - - xub_StrLen nStart = 0; - xub_StrLen nDelimPos; - XubString aStr(rStr); - aStr.ConvertLineEnd(LINEEND_CR); - do - { - nDelimPos = aStr.Search( _CR, nStart ); - xub_StrLen nLen; - if ( nDelimPos == STRING_NOTFOUND ) - nLen = 0xffff; - else - nLen = nDelimPos - nStart; - - // String gehoert der Liste - pImp->aList.push_back(aStr.Copy(nStart, nLen)); - - nStart += nLen + 1 ; // delimiter ueberspringen - } while( nDelimPos != STRING_NOTFOUND ); - - // Kein Leerstring am Ende - if (!pImp->aList.empty() && !(pImp->aList.rbegin())->Len()) - pImp->aList.pop_back(); -} - -//------------------------------------------------------------------------ - -XubString SfxStringListItem::GetString() -{ - XubString aStr; - if ( pImp ) - { - DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid"); - - std::vector<String>::iterator iter; - for (iter = pImp->aList.begin();;) - { - aStr += *iter; - ++iter; - - if (iter != pImp->aList.end()) - aStr += '\r'; - else - break; - } - } - aStr.ConvertLineEnd(); - return aStr; -} - -//------------------------------------------------------------------------ - -#ifndef TF_POOLABLE - -int SfxStringListItem::IsPoolable() const -{ - return sal_False; -} - -#endif - -//------------------------------------------------------------------------ - -void SfxStringListItem::Sort( sal_Bool bAscending) -{ - DBG_ASSERT(GetRefCount()==0,"Sort:RefCount!=0"); - if( pImp ) - pImp->Sort( bAscending); -} - -//---------------------------------------------------------------------------- -void SfxStringListItem::SetStringList( const com::sun::star::uno::Sequence< rtl::OUString >& rList ) -{ - DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0"); - - if ( pImp && (pImp->nRefCount == 1) ) - delete pImp; - else - if( pImp ) - pImp->nRefCount--; - pImp = new SfxImpStringList; - - if (pImp) - { - // String gehoert der Liste - for ( sal_Int32 n = 0; n < rList.getLength(); n++ ) - pImp->aList.push_back(XubString(rList[n])); - } -} - -//---------------------------------------------------------------------------- -void SfxStringListItem::GetStringList( com::sun::star::uno::Sequence< rtl::OUString >& rList ) const -{ - long nCount = pImp->aList.size(); - - rList.realloc( nCount ); - for( long i=0; i < nCount; i++ ) - rList[i] = pImp->aList[i]; -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxStringListItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 ) -{ - com::sun::star::uno::Sequence< rtl::OUString > aValue; - if ( rVal >>= aValue ) - { - SetStringList( aValue ); - return true; - } - - OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" ); - return false; -} - -//---------------------------------------------------------------------------- -// virtual -bool SfxStringListItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const -{ - // GetString() is not const!!! - SfxStringListItem* pThis = const_cast< SfxStringListItem * >( this ); - - com::sun::star::uno::Sequence< rtl::OUString > aStringList; - pThis->GetStringList( aStringList ); - rVal = ::com::sun::star::uno::makeAny( aStringList ); - return true; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/srchitem.cxx b/svl/source/items/srchitem.cxx deleted file mode 100644 index 52c387eb4e..0000000000 --- a/svl/source/items/srchitem.cxx +++ /dev/null @@ -1,671 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -// include --------------------------------------------------------------- - -#include <svl/srchitem.hxx> -#include <sal/macros.h> - -#include <unotools/searchopt.hxx> -#include <com/sun/star/util/XReplaceable.hpp> -#include <com/sun/star/util/XSearchable.hpp> -#include <com/sun/star/util/XSearchDescriptor.hpp> -#include <com/sun/star/util/XPropertyReplace.hpp> -#include <com/sun/star/util/XReplaceDescriptor.hpp> -#include <com/sun/star/lang/Locale.hpp> -#include <svl/memberid.hrc> -#include <i18npool/mslangid.hxx> - -using namespace utl; -using namespace com::sun::star::beans; -using namespace com::sun::star::i18n; -using namespace com::sun::star::lang; -using namespace com::sun::star::uno; -using namespace com::sun::star::util; - -#define CFG_ROOT_NODE "Office.Common/SearchOptions" - -#define SRCH_PARAMS 12 -#define SRCH_PARA_OPTIONS "Options" -#define SRCH_PARA_FAMILY "Family" -#define SRCH_PARA_COMMAND "Command" -#define SRCH_PARA_CELLTYPE "CellType" -#define SRCH_PARA_APPFLAG "AppFlag" -#define SRCH_PARA_ROWDIR "RowDirection" -#define SRCH_PARA_ALLTABLES "AllTables" -#define SRCH_PARA_SEARCHFILTERED "SearchFiltered" -#define SRCH_PARA_BACKWARD "Backward" -#define SRCH_PARA_PATTERN "Pattern" -#define SRCH_PARA_CONTENT "Content" -#define SRCH_PARA_ASIANOPT "AsianOptions" - -// STATIC DATA ----------------------------------------------------------- - -TYPEINIT1_FACTORY(SvxSearchItem, SfxPoolItem, new SvxSearchItem(0)); - -// ----------------------------------------------------------------------- - -static Sequence< ::rtl::OUString > lcl_GetNotifyNames() -{ - // names of transliteration relevant properties - static const char* aTranslitNames[] = - { - "IsMatchCase", // 0 - "Japanese/IsMatchFullHalfWidthForms", // 1 - "Japanese/IsMatchHiraganaKatakana", // 2 - "Japanese/IsMatchContractions", // 3 - "Japanese/IsMatchMinusDashCho-on", // 4 - "Japanese/IsMatchRepeatCharMarks", // 5 - "Japanese/IsMatchVariantFormKanji", // 6 - "Japanese/IsMatchOldKanaForms", // 7 - "Japanese/IsMatch_DiZi_DuZu", // 8 - "Japanese/IsMatch_BaVa_HaFa", // 9 - "Japanese/IsMatch_TsiThiChi_DhiZi", // 10 - "Japanese/IsMatch_HyuIyu_ByuVyu", // 11 - "Japanese/IsMatch_SeShe_ZeJe", // 12 - "Japanese/IsMatch_IaIya", // 13 - "Japanese/IsMatch_KiKu", // 14 - "Japanese/IsIgnorePunctuation", // 15 - "Japanese/IsIgnoreWhitespace", // 16 - "Japanese/IsIgnoreProlongedSoundMark", // 17 - "Japanese/IsIgnoreMiddleDot" // 18 - }; - - const int nCount = SAL_N_ELEMENTS( aTranslitNames ); - Sequence< ::rtl::OUString > aNames( nCount ); - ::rtl::OUString* pNames = aNames.getArray(); - for (sal_Int32 i = 0; i < nCount; ++i) - pNames[i] = ::rtl::OUString::createFromAscii( aTranslitNames[i] ); - - return aNames; -} - -// ----------------------------------------------------------------------- -SvxSearchItem::SvxSearchItem( const sal_uInt16 nId ) : - - SfxPoolItem( nId ), - ConfigItem( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( CFG_ROOT_NODE )) ), - - aSearchOpt ( SearchAlgorithms_ABSOLUTE, - SearchFlags::LEV_RELAXED, - ::rtl::OUString(), - ::rtl::OUString(), - Locale(), - 2, 2, 2, - TransliterationModules_IGNORE_CASE ), - eFamily ( SFX_STYLE_FAMILY_PARA ), - nCommand ( 0 ), - nCellType ( SVX_SEARCHIN_FORMULA ), - nAppFlag ( SVX_SEARCHAPP_WRITER ), - bRowDirection ( sal_True ), - bAllTables ( sal_False ), - bSearchFiltered ( sal_False ), - bNotes ( sal_False), - bBackward ( sal_False ), - bPattern ( sal_False ), - bContent ( sal_False ), - bAsianOptions ( sal_False ) -{ - EnableNotification( lcl_GetNotifyNames() ); - - SvtSearchOptions aOpt; - - bBackward = aOpt.IsBackwards(); - bAsianOptions = aOpt.IsUseAsianOptions(); - bNotes = aOpt.IsNotes(); - - if (aOpt.IsUseRegularExpression()) - aSearchOpt.algorithmType = SearchAlgorithms_REGEXP; - if (aOpt.IsSimilaritySearch()) - aSearchOpt.algorithmType = SearchAlgorithms_APPROXIMATE; - if (aOpt.IsWholeWordsOnly()) - aSearchOpt.searchFlag |= SearchFlags::NORM_WORD_ONLY; - - sal_Int32 &rFlags = aSearchOpt.transliterateFlags; - - if (!aOpt.IsMatchCase()) - rFlags |= TransliterationModules_IGNORE_CASE; - if ( aOpt.IsMatchFullHalfWidthForms()) - rFlags |= TransliterationModules_IGNORE_WIDTH; - if ( bAsianOptions ) - { - if ( aOpt.IsMatchHiraganaKatakana()) - rFlags |= TransliterationModules_IGNORE_KANA; - if ( aOpt.IsMatchContractions()) - rFlags |= TransliterationModules_ignoreSize_ja_JP; - if ( aOpt.IsMatchMinusDashChoon()) - rFlags |= TransliterationModules_ignoreMinusSign_ja_JP; - if ( aOpt.IsMatchRepeatCharMarks()) - rFlags |= TransliterationModules_ignoreIterationMark_ja_JP; - if ( aOpt.IsMatchVariantFormKanji()) - rFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP; - if ( aOpt.IsMatchOldKanaForms()) - rFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP; - if ( aOpt.IsMatchDiziDuzu()) - rFlags |= TransliterationModules_ignoreZiZu_ja_JP; - if ( aOpt.IsMatchBavaHafa()) - rFlags |= TransliterationModules_ignoreBaFa_ja_JP; - if ( aOpt.IsMatchTsithichiDhizi()) - rFlags |= TransliterationModules_ignoreTiJi_ja_JP; - if ( aOpt.IsMatchHyuiyuByuvyu()) - rFlags |= TransliterationModules_ignoreHyuByu_ja_JP; - if ( aOpt.IsMatchSesheZeje()) - rFlags |= TransliterationModules_ignoreSeZe_ja_JP; - if ( aOpt.IsMatchIaiya()) - rFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP; - if ( aOpt.IsMatchKiku()) - rFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP; - if ( aOpt.IsIgnorePunctuation()) - rFlags |= TransliterationModules_ignoreSeparator_ja_JP; - if ( aOpt.IsIgnoreWhitespace()) - rFlags |= TransliterationModules_ignoreSpace_ja_JP; - if ( aOpt.IsIgnoreProlongedSoundMark()) - rFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP; - if ( aOpt.IsIgnoreMiddleDot()) - rFlags |= TransliterationModules_ignoreMiddleDot_ja_JP; - } - -} - -// ----------------------------------------------------------------------- - -SvxSearchItem::SvxSearchItem( const SvxSearchItem& rItem ) : - - SfxPoolItem ( rItem ), - ConfigItem( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( CFG_ROOT_NODE )) ), - - aSearchOpt ( rItem.aSearchOpt ), - eFamily ( rItem.eFamily ), - nCommand ( rItem.nCommand ), - nCellType ( rItem.nCellType ), - nAppFlag ( rItem.nAppFlag ), - bRowDirection ( rItem.bRowDirection ), - bAllTables ( rItem.bAllTables ), - bSearchFiltered ( rItem.bSearchFiltered ), - bNotes ( rItem.bNotes), - bBackward ( rItem.bBackward ), - bPattern ( rItem.bPattern ), - bContent ( rItem.bContent ), - bAsianOptions ( rItem.bAsianOptions ) -{ - EnableNotification( lcl_GetNotifyNames() ); -} - -// ----------------------------------------------------------------------- - -SvxSearchItem::~SvxSearchItem() -{ -} - -// ----------------------------------------------------------------------- -SfxPoolItem* SvxSearchItem::Clone( SfxItemPool *) const -{ - return new SvxSearchItem(*this); -} - -// ----------------------------------------------------------------------- - -//! used below -static sal_Bool operator == ( const SearchOptions& rItem1, const SearchOptions& rItem2 ) -{ - return rItem1.algorithmType == rItem2.algorithmType && - rItem1.searchFlag == rItem2.searchFlag && - rItem1.searchString == rItem2.searchString && - rItem1.replaceString == rItem2.replaceString && - //rItem1.Locale == rItem2.Locale && - rItem1.changedChars == rItem2.changedChars && - rItem1.deletedChars == rItem2.deletedChars && - rItem1.insertedChars == rItem2.insertedChars && - rItem1.transliterateFlags == rItem2.transliterateFlags; -} - - -int SvxSearchItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal which or type" ); - const SvxSearchItem &rSItem = (SvxSearchItem &) rItem; - return ( nCommand == rSItem.nCommand ) && - ( bBackward == rSItem.bBackward ) && - ( bPattern == rSItem.bPattern ) && - ( bContent == rSItem.bContent ) && - ( eFamily == rSItem.eFamily ) && - ( bRowDirection == rSItem.bRowDirection ) && - ( bAllTables == rSItem.bAllTables ) && - ( bSearchFiltered == rSItem.bSearchFiltered ) && - ( nCellType == rSItem.nCellType ) && - ( nAppFlag == rSItem.nAppFlag ) && - ( bAsianOptions == rSItem.bAsianOptions ) && - ( aSearchOpt == rSItem.aSearchOpt ) && - ( bNotes == rSItem.bNotes ); -} - - -//------------------------------------------------------------------------ - -SfxItemPresentation SvxSearchItem::GetPresentation -( - SfxItemPresentation , - SfxMapUnit , - SfxMapUnit , - XubString& , - const IntlWrapper * -) const -{ - return SFX_ITEM_PRESENTATION_NONE; -} - -void SvxSearchItem::GetFromDescriptor( const ::com::sun::star::uno::Reference< ::com::sun::star::util::XSearchDescriptor >& rDescr ) -{ - SetSearchString( rDescr->getSearchString() ); - ::com::sun::star::uno::Any aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchWords") ) ); - sal_Bool bTemp = false; - aAny >>= bTemp ; - SetWordOnly( bTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchCaseSensitive") ) ); - aAny >>= bTemp ; - SetExact( bTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchBackwards") ) ); - aAny >>= bTemp ; - SetBackward( bTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchInSelection") ) ); - aAny >>= bTemp ; - SetSelection( bTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchRegularExpression") ) ); - aAny >>= bTemp ; - SetRegExp( bTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarity") ) ); - aAny >>= bTemp ; - SetLevenshtein( bTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityRelax") ) ); - aAny >>= bTemp ; - SetLEVRelaxed( bTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityExchange") ) ); - sal_Int16 nTemp = 0; - aAny >>= nTemp ; - SetLEVOther( nTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityRemove") ) ); - aAny >>= nTemp ; - SetLEVShorter( nTemp ); - aAny = rDescr->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityAdd") ) ); - aAny >>= nTemp ; - SetLEVLonger( nTemp ); -} - -void SvxSearchItem::SetToDescriptor( ::com::sun::star::uno::Reference< ::com::sun::star::util::XSearchDescriptor > & rDescr ) -{ - rDescr->setSearchString( GetSearchString() ); - ::com::sun::star::uno::Any aAny; - aAny <<= GetWordOnly() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchWords") ), aAny ); - aAny <<= GetExact() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchCaseSensitive") ), aAny ); - aAny <<= GetBackward() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchBackwards") ), aAny ); - aAny <<= GetSelection() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchInSelection") ), aAny ); - aAny <<= GetRegExp() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchRegularExpression") ), aAny ); - aAny <<= IsLevenshtein() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarity") ), aAny ); - aAny <<= IsLEVRelaxed() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityRelax") ), aAny ); - aAny <<= GetLEVOther() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityExchange") ), aAny ); - aAny <<= GetLEVShorter() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityRemove") ), aAny ); - aAny <<= GetLEVLonger() ; - rDescr->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("SearchSimilarityAdd") ), aAny ); -} - - -void SvxSearchItem::Notify( const Sequence< ::rtl::OUString > & ) -{ - // applies transliteration changes in the configuration database - // to the current SvxSearchItem - SetTransliterationFlags( SvtSearchOptions().GetTransliterationFlags() ); -} - -void SvxSearchItem::Commit() -{ -} - -void SvxSearchItem::SetMatchFullHalfWidthForms( sal_Bool bVal ) -{ - if (bVal) - aSearchOpt.transliterateFlags |= TransliterationModules_IGNORE_WIDTH; - else - aSearchOpt.transliterateFlags &= ~TransliterationModules_IGNORE_WIDTH; -} - - -void SvxSearchItem::SetWordOnly( sal_Bool bVal ) -{ - if (bVal) - aSearchOpt.searchFlag |= SearchFlags::NORM_WORD_ONLY; - else - aSearchOpt.searchFlag &= ~SearchFlags::NORM_WORD_ONLY; -} - - -void SvxSearchItem::SetExact( sal_Bool bVal ) -{ - if (!bVal) - aSearchOpt.transliterateFlags |= TransliterationModules_IGNORE_CASE; - else - aSearchOpt.transliterateFlags &= ~TransliterationModules_IGNORE_CASE; -} - - -void SvxSearchItem::SetSelection( sal_Bool bVal ) -{ - if (bVal) - { - aSearchOpt.searchFlag |= (SearchFlags::REG_NOT_BEGINOFLINE | - SearchFlags::REG_NOT_ENDOFLINE); - } - else - { - aSearchOpt.searchFlag &= ~(SearchFlags::REG_NOT_BEGINOFLINE | - SearchFlags::REG_NOT_ENDOFLINE); - } -} - - -void SvxSearchItem::SetRegExp( sal_Bool bVal ) -{ - if ( bVal ) - aSearchOpt.algorithmType = SearchAlgorithms_REGEXP; - else if ( SearchAlgorithms_REGEXP == aSearchOpt.algorithmType ) - aSearchOpt.algorithmType = SearchAlgorithms_ABSOLUTE; -} - - -void SvxSearchItem::SetLEVRelaxed( sal_Bool bVal ) -{ - if (bVal) - aSearchOpt.searchFlag |= SearchFlags::LEV_RELAXED; - else - aSearchOpt.searchFlag &= ~SearchFlags::LEV_RELAXED; -} - - -void SvxSearchItem::SetLevenshtein( sal_Bool bVal ) -{ - if ( bVal ) - aSearchOpt.algorithmType = SearchAlgorithms_APPROXIMATE; - else if ( SearchAlgorithms_APPROXIMATE == aSearchOpt.algorithmType ) - aSearchOpt.algorithmType = SearchAlgorithms_ABSOLUTE; -} - - -void SvxSearchItem::SetTransliterationFlags( sal_Int32 nFlags ) -{ - aSearchOpt.transliterateFlags = nFlags; -} - -bool SvxSearchItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) const -{ - nMemberId &= ~CONVERT_TWIPS; - switch ( nMemberId ) - { - case 0 : - { - Sequence< PropertyValue > aSeq( SRCH_PARAMS ); - aSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_OPTIONS ) ); - aSeq[0].Value <<= aSearchOpt; - aSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_FAMILY )); - aSeq[1].Value <<= sal_Int16( eFamily ); - aSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_COMMAND )); - aSeq[2].Value <<= nCommand; - aSeq[3].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_CELLTYPE )); - aSeq[3].Value <<= nCellType; - aSeq[4].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_APPFLAG )); - aSeq[4].Value <<= nAppFlag; - aSeq[5].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_ROWDIR )); - aSeq[5].Value <<= bRowDirection; - aSeq[6].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_ALLTABLES )); - aSeq[6].Value <<= bAllTables; - aSeq[6].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_SEARCHFILTERED )); - aSeq[6].Value <<= bSearchFiltered; - aSeq[7].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_BACKWARD )); - aSeq[7].Value <<= bBackward; - aSeq[8].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_PATTERN )); - aSeq[8].Value <<= bPattern; - aSeq[9].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_CONTENT )); - aSeq[9].Value <<= bContent; - aSeq[10].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( SRCH_PARA_ASIANOPT )); - aSeq[10].Value <<= bAsianOptions; - rVal <<= aSeq; - } - break; - case MID_SEARCH_COMMAND: - rVal <<= (sal_Int16) nCommand; break; - case MID_SEARCH_STYLEFAMILY: - rVal <<= (sal_Int16) eFamily; break; - case MID_SEARCH_CELLTYPE: - rVal <<= (sal_Int32) nCellType; break; - case MID_SEARCH_ROWDIRECTION: - rVal <<= (sal_Bool) bRowDirection; break; - case MID_SEARCH_ALLTABLES: - rVal <<= (sal_Bool) bAllTables; break; - case MID_SEARCH_SEARCHFILTERED: - rVal <<= (sal_Bool) bSearchFiltered; break; - case MID_SEARCH_BACKWARD: - rVal <<= (sal_Bool) bBackward; break; - case MID_SEARCH_PATTERN: - rVal <<= (sal_Bool) bPattern; break; - case MID_SEARCH_CONTENT: - rVal <<= (sal_Bool) bContent; break; - case MID_SEARCH_ASIANOPTIONS: - rVal <<= (sal_Bool) bAsianOptions; break; - case MID_SEARCH_ALGORITHMTYPE: - rVal <<= (sal_Int16) aSearchOpt.algorithmType; break; - case MID_SEARCH_FLAGS: - rVal <<= aSearchOpt.searchFlag; break; - case MID_SEARCH_SEARCHSTRING: - rVal <<= aSearchOpt.searchString; break; - case MID_SEARCH_REPLACESTRING: - rVal <<= aSearchOpt.replaceString; break; - case MID_SEARCH_CHANGEDCHARS: - rVal <<= aSearchOpt.changedChars; break; - case MID_SEARCH_DELETEDCHARS: - rVal <<= aSearchOpt.deletedChars; break; - case MID_SEARCH_INSERTEDCHARS: - rVal <<= aSearchOpt.insertedChars; break; - case MID_SEARCH_TRANSLITERATEFLAGS: - rVal <<= aSearchOpt.transliterateFlags; break; - case MID_SEARCH_LOCALE: - { - sal_Int16 nLocale; - if (aSearchOpt.Locale.Language.getLength() || aSearchOpt.Locale.Country.getLength() ) - nLocale = MsLangId::convertLocaleToLanguage( aSearchOpt.Locale ); - else - nLocale = LANGUAGE_NONE; - rVal <<= nLocale; - break; - } - - default: - DBG_ERRORFILE( "SvxSearchItem::QueryValue(): Unknown MemberId" ); - return false; - } - - return true; -} - -// ----------------------------------------------------------------------- - -bool SvxSearchItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 nMemberId ) -{ - nMemberId &= ~CONVERT_TWIPS; - bool bRet = false; - sal_Int32 nInt = 0; - switch ( nMemberId ) - { - case 0 : - { - Sequence< PropertyValue > aSeq; - if ( ( rVal >>= aSeq ) && ( aSeq.getLength() == SRCH_PARAMS ) ) - { - sal_Int16 nConvertedCount( 0 ); - for ( sal_Int32 i = 0; i < aSeq.getLength(); ++i ) - { - if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_OPTIONS ) ) ) - { - if ( ( aSeq[i].Value >>= aSearchOpt ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_FAMILY ) ) ) - { - sal_uInt16 nTemp( 0 ); - if ( ( aSeq[i].Value >>= nTemp ) == sal_True ) - { - eFamily = SfxStyleFamily( nTemp ); - ++nConvertedCount; - } - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_COMMAND ) ) ) - { - if ( ( aSeq[i].Value >>= nCommand ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_CELLTYPE ) ) ) - { - if ( ( aSeq[i].Value >>= nCellType ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_APPFLAG ) ) ) - { - if ( ( aSeq[i].Value >>= nAppFlag ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_ROWDIR ) ) ) - { - if ( ( aSeq[i].Value >>= bRowDirection ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_ALLTABLES ) ) ) - { - if ( ( aSeq[i].Value >>= bAllTables ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_SEARCHFILTERED ) ) ) - { - if ( ( aSeq[i].Value >>= bSearchFiltered ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_BACKWARD ) ) ) - { - if ( ( aSeq[i].Value >>= bBackward ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_PATTERN ) ) ) - { - if ( ( aSeq[i].Value >>= bPattern ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_CONTENT ) ) ) - { - if ( ( aSeq[i].Value >>= bContent ) == sal_True ) - ++nConvertedCount; - } - else if ( aSeq[i].Name.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SRCH_PARA_ASIANOPT ) ) ) - { - if ( ( aSeq[i].Value >>= bAsianOptions ) == sal_True ) - ++nConvertedCount; - } - } - - bRet = ( nConvertedCount == SRCH_PARAMS ); - } - break; - } - case MID_SEARCH_COMMAND: - bRet = (rVal >>= nInt); nCommand = (sal_uInt16) nInt; break; - case MID_SEARCH_STYLEFAMILY: - bRet = (rVal >>= nInt); eFamily = (SfxStyleFamily) (sal_Int16) nInt; break; - case MID_SEARCH_CELLTYPE: - bRet = (rVal >>= nInt); nCellType = (sal_uInt16) nInt; break; - case MID_SEARCH_ROWDIRECTION: - bRet = (rVal >>= bRowDirection); break; - case MID_SEARCH_ALLTABLES: - bRet = (rVal >>= bAllTables); break; - case MID_SEARCH_SEARCHFILTERED: - bRet = (rVal >>= bSearchFiltered); break; - case MID_SEARCH_BACKWARD: - bRet = (rVal >>= bBackward); break; - case MID_SEARCH_PATTERN: - bRet = (rVal >>= bPattern); break; - case MID_SEARCH_CONTENT: - bRet = (rVal >>= bContent); break; - case MID_SEARCH_ASIANOPTIONS: - bRet = (rVal >>= bAsianOptions); break; - case MID_SEARCH_ALGORITHMTYPE: - bRet = (rVal >>= nInt); aSearchOpt.algorithmType = (SearchAlgorithms)(sal_Int16)nInt; break; - case MID_SEARCH_FLAGS: - bRet = (rVal >>= aSearchOpt.searchFlag); break; - case MID_SEARCH_SEARCHSTRING: - bRet = (rVal >>= aSearchOpt.searchString); break; - case MID_SEARCH_REPLACESTRING: - bRet = (rVal >>= aSearchOpt.replaceString); break; - case MID_SEARCH_CHANGEDCHARS: - bRet = (rVal >>= aSearchOpt.changedChars); break; - case MID_SEARCH_DELETEDCHARS: - bRet = (rVal >>= aSearchOpt.deletedChars); break; - case MID_SEARCH_INSERTEDCHARS: - bRet = (rVal >>= aSearchOpt.insertedChars); break; - case MID_SEARCH_TRANSLITERATEFLAGS: - bRet = (rVal >>= aSearchOpt.transliterateFlags); break; - case MID_SEARCH_LOCALE: - { - bRet = (rVal >>= nInt); - if ( bRet ) - { - if ( nInt == LANGUAGE_NONE ) - { - aSearchOpt.Locale = ::com::sun::star::lang::Locale(); - } - else - { - MsLangId::convertLanguageToLocale( (sal_Int16) nInt, aSearchOpt.Locale ); - } - } - break; - } - default: - OSL_FAIL( "Unknown MemberId" ); - } - - return bRet; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/stritem.cxx b/svl/source/items/stritem.cxx deleted file mode 100644 index f461951b0a..0000000000 --- a/svl/source/items/stritem.cxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/stritem.hxx> - -//============================================================================ -// -// class SfxStringItem -// -//============================================================================ - -TYPEINIT1_AUTOFACTORY(SfxStringItem, CntUnencodedStringItem) - -//============================================================================ -// virtual -SfxStringItem::SfxStringItem(sal_uInt16 which, SvStream & rStream): - CntUnencodedStringItem(which) -{ - UniString aValue; - readByteString(rStream, aValue); - SetValue(aValue); -} - - -//============================================================================ -// virtual -SfxPoolItem * SfxStringItem::Create(SvStream & rStream, sal_uInt16) const -{ - return new SfxStringItem(Which(), rStream); -} - -//============================================================================ -// virtual -SvStream & SfxStringItem::Store(SvStream & rStream, sal_uInt16) const -{ - writeByteString(rStream, GetValue()); - return rStream; -} - -//============================================================================ -// virtual -SfxPoolItem * SfxStringItem::Clone(SfxItemPool *) const -{ - return new SfxStringItem(*this); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx deleted file mode 100644 index c6e78a7ef4..0000000000 --- a/svl/source/items/style.cxx +++ /dev/null @@ -1,1394 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <com/sun/star/lang/XComponent.hpp> - -#define _SVSTDARR_STRINGS -#define _SVSTDARR_STRINGSSORTDTOR -#define _SVSTDARR_BYTESTRINGS -#define _SVSTDARR_BYTESTRINGSSORTDTOR - -#include <tools/tenccvt.hxx> -#include <comphelper/processfactory.hxx> -#include <unotools/intlwrapper.hxx> -#include <svl/smplhint.hxx> -#include <svl/poolitem.hxx> -#include <svl/itemset.hxx> -#include <svl/itempool.hxx> -#include <poolio.hxx> -#include <svl/filerec.hxx> -#include <svl/itemiter.hxx> -#include <svl/style.hxx> -#include <svl/svstdarr.hxx> -#include <unotools/syslocale.hxx> -#include <algorithm> -#include <comphelper/servicehelper.hxx> - -#define STYLESTREAM "SfxStyleSheets" -#define STYLESTREAM_VERSION sal_uInt16(50) - -#ifdef DBG_UTIL -class DbgStyleSheetReferences -{ -public: - DbgStyleSheetReferences() : mnStyles(0), mnPools(0) {} - ~DbgStyleSheetReferences() - { - OSL_TRACE("DbgStyleSheetReferences\nSfxStyleSheetBase left %ld\nSfxStyleSheetBasePool left %ld\n", mnStyles, mnPools ); - } - - sal_uInt32 mnStyles; - sal_uInt32 mnPools; -} -aDbgStyleSheetReferences; - -#endif - -TYPEINIT0(SfxStyleSheetBase) - -TYPEINIT3(SfxStyleSheet, SfxStyleSheetBase, SfxListener, SfxBroadcaster) - - -//========================================================================= - -TYPEINIT1(SfxStyleSheetHint, SfxHint); -TYPEINIT1(SfxStyleSheetHintExtended, SfxStyleSheetHint); -TYPEINIT1(SfxStyleSheetPoolHint, SfxHint); - -SfxStyleSheetHintExtended::SfxStyleSheetHintExtended -( - sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.) - const String& rOldName -) -: SfxStyleSheetHint( nAction ), - aName( rOldName ) -{} -SfxStyleSheetHintExtended::SfxStyleSheetHintExtended -( - sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.) - const String& rOldName, - SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer -) -: SfxStyleSheetHint( nAction, rStyleSheet ), - aName( rOldName ) -{} - -//------------------------------------------------------------------------- - -SfxStyleSheetHint::SfxStyleSheetHint -( - sal_uInt16 nAction, // SFX_STYLESHEET_... (s.o.) - SfxStyleSheetBase& rStyleSheet // geh"ort weiterhin dem Aufrufer -) -: pStyleSh( &rStyleSheet ), - nHint( nAction ) -{} - -SfxStyleSheetHint::SfxStyleSheetHint -( - sal_uInt16 nAction // SFX_STYLESHEET_... (s.o.) -) -: pStyleSh( NULL ), - nHint( nAction ) -{} - -//========================================================================= - -class SfxStyleSheetBasePool_Impl -{ - public: - SfxStyles aStyles; - SfxStyleSheetIterator *pIter; - SfxStyleSheetBasePool_Impl() : pIter(0){} - ~SfxStyleSheetBasePool_Impl(){delete pIter;} -}; - - -//////////////////////////// SfxStyleSheetBase /////////////////////////////// - -// Konstruktoren - -SfxStyleSheetBase::SfxStyleSheetBase( const XubString& rName, SfxStyleSheetBasePool& r, SfxStyleFamily eFam, sal_uInt16 mask ) - : rPool( r ) - , nFamily( eFam ) - , aName( rName ) - , aParent() - , aFollow( rName ) - , pSet( NULL ) - , nMask(mask) - , nHelpId( 0 ) - , bMySet( sal_False ) -{ -#ifdef DBG_UTIL - aDbgStyleSheetReferences.mnStyles++; -#endif -} - -SfxStyleSheetBase::SfxStyleSheetBase( const SfxStyleSheetBase& r ) - : comphelper::OWeakTypeObject() - , rPool( r.rPool ) - , nFamily( r.nFamily ) - , aName( r.aName ) - , aParent( r.aParent ) - , aFollow( r.aFollow ) - , aHelpFile( r.aHelpFile ) - , nMask( r.nMask ) - , nHelpId( r.nHelpId ) - , bMySet( r.bMySet ) -{ -#ifdef DBG_UTIL - aDbgStyleSheetReferences.mnStyles++; -#endif - if( r.pSet ) - pSet = bMySet ? new SfxItemSet( *r.pSet ) : r.pSet; - else - pSet = NULL; -} - -static SfxStyleSheetBasePool& implGetStaticPool() -{ - static SfxStyleSheetBasePool* pSheetPool = 0; - static SfxItemPool* pBasePool = 0; - if( !pSheetPool ) - { - UniString aName; - pBasePool = new SfxItemPool( aName, 0, 0, 0 ); - pSheetPool = new SfxStyleSheetBasePool(*pBasePool); - } - return *pSheetPool; -} - -SfxStyleSheetBase::SfxStyleSheetBase() -: comphelper::OWeakTypeObject() -, rPool( implGetStaticPool() ) -{ -} - -SfxStyleSheetBase::~SfxStyleSheetBase() -{ -#ifdef DBG_UTIL - --aDbgStyleSheetReferences.mnStyles; -#endif - - if( bMySet ) - { - delete pSet; - pSet = 0; - } -} - -sal_uInt16 SfxStyleSheetBase::GetVersion() const -{ - return 0x0000; -} - -// Namen aendern - -const XubString& SfxStyleSheetBase::GetName() const -{ - return aName; -} - -sal_Bool SfxStyleSheetBase::SetName( const XubString& rName ) -{ - if(rName.Len() == 0) - return sal_False; - if( aName != rName ) - { - String aOldName = aName; - SfxStyleSheetBase *pOther = rPool.Find( rName, nFamily ) ; - if ( pOther && pOther != this ) - return sal_False; - - SfxStyleFamily eTmpFam=rPool.GetSearchFamily(); - sal_uInt16 nTmpMask=rPool.GetSearchMask(); - - rPool.SetSearchMask(nFamily); - - if ( aName.Len() ) - rPool.ChangeParent( aName, rName, sal_False ); - if ( aFollow.Equals( aName ) ) - aFollow = rName; - aName = rName; - rPool.SetSearchMask(eTmpFam, nTmpMask); - rPool.Broadcast( SfxStyleSheetHintExtended( - SFX_STYLESHEET_MODIFIED, aOldName, *this ) ); - } - return sal_True; -} - -rtl::OUString SfxStyleSheetBase::GetDisplayName() const -{ - if( maDisplayName.getLength() == 0 ) - { - return aName; - } - else - { - return maDisplayName; - } -} - -void SfxStyleSheetBase::SetDisplayName( const rtl::OUString& rDisplayName ) -{ - maDisplayName = rDisplayName; -} - -// Parent aendern - -const XubString& SfxStyleSheetBase::GetParent() const -{ - return aParent; -} - -sal_Bool SfxStyleSheetBase::SetParent( const XubString& rName ) -{ - if ( rName == aName ) - return sal_False; - - if( aParent != rName ) - { - SfxStyleSheetBase* pIter = rPool.Find(rName, nFamily); - if( rName.Len() && !pIter ) - { - OSL_FAIL( "StyleSheet-Parent nicht gefunden" ); - return sal_False; - } - // rekursive Verknuepfungen verhindern - if( aName.Len() ) - while(pIter) - { - if(pIter->GetName() == aName && aName != rName) - return sal_False; - pIter = rPool.Find(pIter->GetParent(), nFamily); - } - aParent = rName; - } - rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); - return sal_True; -} - -// Follow aendern - -const XubString& SfxStyleSheetBase::GetFollow() const -{ - return aFollow; -} - -sal_Bool SfxStyleSheetBase::SetFollow( const XubString& rName ) -{ - if( aFollow != rName ) - { - if( !rPool.Find( rName, nFamily ) ) - { - OSL_FAIL( "StyleSheet-Follow nicht gefunden" ); - return sal_False; - } - aFollow = rName; - } - rPool.Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_MODIFIED, *this ) ); - return sal_True; -} - -// Itemset setzen. Die Dflt-Implementation legt ein neues Set an. - -SfxItemSet& SfxStyleSheetBase::GetItemSet() -{ - if( !pSet ) - { - pSet = new SfxItemSet( rPool.GetPool() ); - bMySet = sal_True; - } - return *pSet; -} - -// Hilfe-Datei und -ID setzen und abfragen - -sal_uLong SfxStyleSheetBase::GetHelpId( String& rFile ) -{ - rFile = aHelpFile; - return nHelpId; -} - -void SfxStyleSheetBase::SetHelpId( const String& rFile, sal_uLong nId ) -{ - aHelpFile = rFile; - nHelpId = nId; -} - -// Folgevorlage m"oglich? Default: Ja - -sal_Bool SfxStyleSheetBase::HasFollowSupport() const -{ - return sal_True; -} - -// Basisvorlage m"oglich? Default: Ja - -sal_Bool SfxStyleSheetBase::HasParentSupport() const -{ - return sal_True; -} - -// Basisvorlage uf NULL setzen m"oglich? Default: Nein - -sal_Bool SfxStyleSheetBase::HasClearParentSupport() const -{ - return sal_False; -} - -// Defaultmaessig sind alle StyleSheets Used - -sal_Bool SfxStyleSheetBase::IsUsed() const -{ - return sal_True; -} - -// eingestellte Attribute ausgeben - - -XubString SfxStyleSheetBase::GetDescription() -{ - return GetDescription( SFX_MAPUNIT_CM ); -} - -// eingestellte Attribute ausgeben - -XubString SfxStyleSheetBase::GetDescription( SfxMapUnit eMetric ) -{ - SfxItemIter aIter( GetItemSet() ); - XubString aDesc; - const SfxPoolItem* pItem = aIter.FirstItem(); - - IntlWrapper aIntlWrapper(comphelper::getProcessServiceFactory(), - SvtSysLocale().GetLanguage()); - while ( pItem ) - { - XubString aItemPresentation; - - if ( !IsInvalidItem( pItem ) && - rPool.GetPool().GetPresentation( - *pItem, SFX_ITEM_PRESENTATION_COMPLETE, - eMetric, aItemPresentation, &aIntlWrapper ) ) - { - if ( aDesc.Len() && aItemPresentation.Len() ) - aDesc.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" + ")); - if ( aItemPresentation.Len() ) - aDesc += aItemPresentation; - } - pItem = aIter.NextItem(); - } - return aDesc; -} - -/////////////////////////// SfxStyleSheetIterator /////////////////////////////// - -SfxStyleFamily SfxStyleSheetIterator::GetSearchFamily() const -{ - return nSearchFamily; -} - -inline sal_Bool SfxStyleSheetIterator::IsTrivialSearch() -{ - return nMask == 0xFFFF && GetSearchFamily() == SFX_STYLE_FAMILY_ALL; -} - -sal_Bool SfxStyleSheetIterator::DoesStyleMatch(SfxStyleSheetBase *pStyle) -{ - return ((GetSearchFamily() == SFX_STYLE_FAMILY_ALL) || - ( pStyle->GetFamily() == GetSearchFamily() )) - && (( pStyle->GetMask() & ( GetSearchMask() & ~SFXSTYLEBIT_USED )) || - ( bSearchUsed ? pStyle->IsUsed() : sal_False ) || - GetSearchMask() == SFXSTYLEBIT_ALL ); -} - - -SfxStyleSheetIterator::SfxStyleSheetIterator(SfxStyleSheetBasePool *pBase, - SfxStyleFamily eFam, sal_uInt16 n) -{ - pBasePool=pBase; - nSearchFamily=eFam; - bSearchUsed=sal_False; - if((n != SFXSTYLEBIT_ALL ) && ((n & SFXSTYLEBIT_USED) == SFXSTYLEBIT_USED)) - { - bSearchUsed = sal_True; - n &= ~SFXSTYLEBIT_USED; - } - nMask=n; -} - -SfxStyleSheetIterator::~SfxStyleSheetIterator() -{ -} - - -sal_uInt16 SfxStyleSheetIterator::Count() -{ - sal_uInt16 n = 0; - if( IsTrivialSearch()) - n = (sal_uInt16) pBasePool->aStyles.size(); - else - for(sal_uInt16 i=0; i<pBasePool->aStyles.size(); i++) - { - SfxStyleSheetBase* pStyle = pBasePool->aStyles[i].get(); - if(DoesStyleMatch(pStyle)) - n++; - } - return n; -} - -SfxStyleSheetBase* SfxStyleSheetIterator::operator[](sal_uInt16 nIdx) -{ - if( IsTrivialSearch()) - return pBasePool->aStyles[nIdx].get(); - - sal_uInt16 z = 0; - for(sal_uInt16 n=0; n<pBasePool->aStyles.size(); n++) - { - SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); - if( DoesStyleMatch(pStyle)) - { - if(z == nIdx) - { - nAktPosition=n; - return pAktStyle=pStyle; - } - ++z; - } - } - OSL_FAIL("falscher Index"); - return 0; -} - -SfxStyleSheetBase* SfxStyleSheetIterator::First() -{ - sal_Int32 nIdx = -1; - - if ( IsTrivialSearch() && pBasePool->aStyles.size() ) - nIdx = 0; - else - for( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ ) - { - SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); - - if ( DoesStyleMatch( pStyle ) ) - { - nIdx = n; - break; - } - } - - if ( nIdx != -1 ) - { - nAktPosition = (sal_uInt16)nIdx; - return pAktStyle = pBasePool->aStyles[nIdx].get(); - } - return 0; -} - - -SfxStyleSheetBase* SfxStyleSheetIterator::Next() -{ - sal_Int32 nIdx = -1; - - if ( IsTrivialSearch() && - (sal_uInt16)pBasePool->aStyles.size() > nAktPosition + 1 ) - nIdx = nAktPosition + 1; - else - for( sal_uInt16 n = nAktPosition + 1; n < pBasePool->aStyles.size(); n++ ) - { - SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); - - if ( DoesStyleMatch( pStyle ) ) - { - nIdx = n; - break; - } - } - - if ( nIdx != -1 ) - { - nAktPosition = (sal_uInt16)nIdx; - return pAktStyle = pBasePool->aStyles[nIdx].get(); - } - return 0; -} - - -SfxStyleSheetBase* SfxStyleSheetIterator::Find(const XubString& rStr) -{ - for ( sal_uInt16 n = 0; n < pBasePool->aStyles.size(); n++ ) - { - SfxStyleSheetBase* pStyle = pBasePool->aStyles[n].get(); - - // #98454# performance: in case of bSearchUsed==sal_True it may be - // significant to first compare the name and only if it matches to call - // the style sheet IsUsed() method in DoesStyleMatch(). - if ( pStyle->GetName().Equals( rStr ) && DoesStyleMatch( pStyle ) ) - { - nAktPosition = n; - return pAktStyle = pStyle; - } - } - return 0; -} - - -sal_uInt16 SfxStyleSheetIterator::GetSearchMask() const -{ - sal_uInt16 mask = nMask; - - if ( bSearchUsed ) - mask |= SFXSTYLEBIT_USED; - return mask; -} - -/////////////////////////// SfxStyleSheetBasePool /////////////////////////////// - -void SfxStyleSheetBasePool::Replace( - SfxStyleSheetBase& rSource, SfxStyleSheetBase& rTarget ) -{ - rTarget.SetFollow( rSource.GetFollow() ); - rTarget.SetParent( rSource.GetParent() ); - SfxItemSet& rSourceSet = rSource.GetItemSet(); - SfxItemSet& rTargetSet = rTarget.GetItemSet(); - rTargetSet.Intersect( rSourceSet ); - rTargetSet.Put( rSourceSet ); -} - -SfxStyleSheetIterator& SfxStyleSheetBasePool::GetIterator_Impl() -{ - SfxStyleSheetIterator*& rpIter = pImp->pIter; - if( !rpIter || (rpIter->GetSearchMask() != nMask) || (rpIter->GetSearchFamily() != nSearchFamily) ) - { - delete rpIter; - rpIter = CreateIterator( nSearchFamily, nMask ); - } - return *rpIter; -} - - -SfxStyleSheetBasePool::SfxStyleSheetBasePool( SfxItemPool& r ) - : aAppName(r.GetName()) - , rPool(r) - , nSearchFamily(SFX_STYLE_FAMILY_PARA) - , nMask(0xFFFF) -{ -#ifdef DBG_UTIL - aDbgStyleSheetReferences.mnPools++; -#endif - - pImp = new SfxStyleSheetBasePool_Impl; -} - -SfxStyleSheetBasePool::SfxStyleSheetBasePool( const SfxStyleSheetBasePool& r ) - : SfxBroadcaster( r ) - , comphelper::OWeakTypeObject() - , aAppName(r.aAppName) - , rPool(r.rPool) - , nSearchFamily(r.nSearchFamily) - , nMask( r.nMask ) -{ -#ifdef DBG_UTIL - aDbgStyleSheetReferences.mnPools++; -#endif - - pImp = new SfxStyleSheetBasePool_Impl; - *this += r; -} - -SfxStyleSheetBasePool::~SfxStyleSheetBasePool() -{ -#ifdef DBG_UTIL - aDbgStyleSheetReferences.mnPools--; -#endif - - Broadcast( SfxSimpleHint(SFX_HINT_DYING) ); - Clear(); - delete pImp; -} - -sal_Bool SfxStyleSheetBasePool::SetParent(SfxStyleFamily eFam, const XubString& rStyle, const XubString& rParent) -{ - SfxStyleSheetIterator aIter(this,eFam,SFXSTYLEBIT_ALL); - SfxStyleSheetBase *pStyle = - aIter.Find(rStyle); - OSL_ENSURE(pStyle, "Vorlage nicht gefunden. Writer mit Solar <2541??"); - if(pStyle) - return pStyle->SetParent(rParent); - else - return sal_False; -} - - -void SfxStyleSheetBasePool::SetSearchMask(SfxStyleFamily eFam, sal_uInt16 n) -{ - nSearchFamily = eFam; nMask = n; -} - -sal_uInt16 SfxStyleSheetBasePool::GetSearchMask() const -{ - return nMask; -} - - -// Der Name des Streams - -String SfxStyleSheetBasePool::GetStreamName() -{ - return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(STYLESTREAM)); -} - -/////////////////////////////////// Factory //////////////////////////////// - - - -SfxStyleSheetIterator* SfxStyleSheetBasePool::CreateIterator -( - SfxStyleFamily eFam, - sal_uInt16 mask -) -{ - return new SfxStyleSheetIterator(this,eFam,mask); -} - - -SfxStyleSheetBase* SfxStyleSheetBasePool::Create -( - const XubString& rName, - SfxStyleFamily eFam, - sal_uInt16 mask -) -{ - return new SfxStyleSheetBase( rName, *this, eFam, mask ); -} - -SfxStyleSheetBase* SfxStyleSheetBasePool::Create( const SfxStyleSheetBase& r ) -{ - return new SfxStyleSheetBase( r ); -} - -SfxStyleSheetBase& SfxStyleSheetBasePool::Make( const XubString& rName, SfxStyleFamily eFam, sal_uInt16 mask, sal_uInt16 nPos) -{ - OSL_ENSURE( eFam != SFX_STYLE_FAMILY_ALL, "svl::SfxStyleSheetBasePool::Make(), FamilyAll is not a allowed Familie" ); - - SfxStyleSheetIterator aIter(this, eFam, mask); - rtl::Reference< SfxStyleSheetBase > xStyle( aIter.Find( rName ) ); - OSL_ENSURE( !xStyle.is(), "svl::SfxStyleSheetBasePool::Make(), StyleSheet already exists" ); - SfxStyleSheetIterator& rIter = GetIterator_Impl(); - - if( !xStyle.is() ) - { - xStyle = Create( rName, eFam, mask ); - if(0xffff == nPos || nPos == aStyles.size() || nPos == rIter.Count()) - { - aStyles.push_back( xStyle ); - } - else - { - rIter[nPos]; - aStyles.insert( aStyles.begin() + rIter.GetPos(), xStyle ); - } - Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *xStyle.get() ) ); - } - return *xStyle.get(); -} - -/////////////////////////////// Kopieren /////////////////////////////////// - -// Hilfsroutine: Falls eine Vorlage dieses Namens existiert, wird -// sie neu erzeugt. Alle Vorlagen, die diese Vorlage zum Parent haben, -// werden umgehaengt. - -SfxStyleSheetBase& SfxStyleSheetBasePool::Add( SfxStyleSheetBase& rSheet ) -{ - SfxStyleSheetIterator aIter(this, rSheet.GetFamily(), nMask); - SfxStyleSheetBase* pOld = aIter.Find( rSheet.GetName() ); - Remove( pOld ); - rtl::Reference< SfxStyleSheetBase > xNew( Create( rSheet ) ); - aStyles.push_back( xNew ); - Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CHANGED, *xNew.get() ) ); - return *xNew.get(); -} - -SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator=( const SfxStyleSheetBasePool& r ) -{ - if( &r != this ) - { - Clear(); - *this += r; - } - return *this; -} - -SfxStyleSheetBasePool& SfxStyleSheetBasePool::operator+=( const SfxStyleSheetBasePool& r ) -{ - if( &r != this ) - { - SfxStyles::const_iterator aIter( r.aStyles.begin() ); - while( aIter != r.aStyles.end() ) - { - Add(*(*aIter++).get()); - } - } - return *this; -} - -//////////////////////////////// Suchen //////////////////////////////////// - -sal_uInt16 SfxStyleSheetBasePool::Count() -{ - return GetIterator_Impl().Count(); -} - -SfxStyleSheetBase *SfxStyleSheetBasePool::operator[](sal_uInt16 nIdx) -{ - return GetIterator_Impl()[nIdx]; -} - -SfxStyleSheetBase* SfxStyleSheetBasePool::Find(const XubString& rName, - SfxStyleFamily eFam, - sal_uInt16 mask) -{ - SfxStyleSheetIterator aIter(this,eFam,mask); - return aIter.Find(rName); -} - -const SfxStyles& SfxStyleSheetBasePool::GetStyles() -{ - return aStyles; -} - -SfxStyleSheetBase* SfxStyleSheetBasePool::First() -{ - return GetIterator_Impl().First(); -} - -SfxStyleSheetBase* SfxStyleSheetBasePool::Next() -{ - return GetIterator_Impl().Next(); -} - -//////////////////////////////// Loeschen ///////////////////////////////// - -void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p ) -{ - if( p ) - { - SfxStyles::iterator aIter( std::find( aStyles.begin(), aStyles.end(), rtl::Reference< SfxStyleSheetBase >( p ) ) ); - if( aIter != aStyles.end() ) - { - // Alle Styles umsetzen, deren Parent dieser hier ist - ChangeParent( p->GetName(), p->GetParent() ); - - com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY ); - if( xComp.is() ) try - { - xComp->dispose(); - } - catch( com::sun::star::uno::Exception& ) - { - } - - aStyles.erase(aIter); - Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *p ) ); - } - } -} - -void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase* p ) -{ -#if OSL_DEBUG_LEVEL > 0 - OSL_ENSURE( p, "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?" ); - - SfxStyleSheetIterator aIter(this, p->GetFamily(), p->GetMask()); - SfxStyleSheetBase* pOld = aIter.Find( p->GetName() ); - OSL_ENSURE( !pOld, "svl::SfxStyleSheetBasePool::Insert(), StyleSheet already inserted" ); - if( p->GetParent().Len() ) - { - pOld = aIter.Find( p->GetParent() ); - OSL_ENSURE( pOld, "svl::SfxStyleSheetBasePool::Insert(), Parent not found!" ); - } -#endif - aStyles.push_back( rtl::Reference< SfxStyleSheetBase >( p ) ); - Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_CREATED, *p ) ); -} - -void SfxStyleSheetBasePool::Clear() -{ - SfxStyles aClearStyles; - aClearStyles.swap( aStyles ); - - SfxStyles::iterator aIter( aClearStyles.begin() ); - while( aIter != aClearStyles.end() ) - { - com::sun::star::uno::Reference< com::sun::star::lang::XComponent > xComp( static_cast< ::cppu::OWeakObject* >((*aIter).get()), com::sun::star::uno::UNO_QUERY ); - if( xComp.is() ) try - { - xComp->dispose(); - } - catch( com::sun::star::uno::Exception& ) - { - } - - Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_ERASED, *(*aIter++).get() ) ); - } -} - -/////////////////////////// Parents umsetzen //////////////////////////////// - -void SfxStyleSheetBasePool::ChangeParent(const XubString& rOld, - const XubString& rNew, - sal_Bool bVirtual) -{ - const sal_uInt16 nTmpMask = GetSearchMask(); - SetSearchMask(GetSearchFamily(), 0xffff); - for( SfxStyleSheetBase* p = First(); p; p = Next() ) - { - if( p->GetParent().Equals( rOld ) ) - { - if(bVirtual) - p->SetParent( rNew ); - else - p->aParent = rNew; - } - } - SetSearchMask(GetSearchFamily(), nTmpMask); -} - -/////////////////////////// Laden/Speichern ///////////////////////////////// - -void SfxStyleSheetBase::Load( SvStream&, sal_uInt16 ) -{ -} - -void SfxStyleSheetBase::Store( SvStream& ) -{ -} - - -sal_Bool SfxStyleSheetBasePool::Load( SvStream& rStream ) -{ - // alte Version? - if ( !rPool.IsVer2_Impl() ) - return Load1_Impl( rStream ); - - // gesamten StyleSheetPool in neuer Version aus einem MiniRecord lesen - SfxMiniRecordReader aPoolRec( &rStream, SFX_STYLES_REC ); - - // Header-Record lesen - short nCharSet = 0; - if ( !rStream.GetError() ) - { - SfxSingleRecordReader aHeaderRec( &rStream, SFX_STYLES_REC_HEADER ); - if ( !aHeaderRec.IsValid() ) - return sal_False; - - aAppName = rPool.GetName(); - rStream >> nCharSet; - } - - // Styles-Record lesen - if ( !rStream.GetError() ) - { - SfxMultiRecordReader aStylesRec( &rStream, SFX_STYLES_REC_STYLES ); - if ( !aStylesRec.IsValid() ) - return sal_False; - - rtl_TextEncoding eEnc = GetSOLoadTextEncoding( - (rtl_TextEncoding)nCharSet, - sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) ); - rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); - rStream.SetStreamCharSet( eEnc ); - - sal_uInt16 nStyles; - for ( nStyles = 0; aStylesRec.GetContent(); nStyles++ ) - { - // kann nicht mehr weiterlesen? - if ( rStream.GetError() ) - break; - - // Globale Teile - XubString aName, aParent, aFollow; - String aHelpFile; - sal_uInt16 nFamily, nStyleMask,nCount; - sal_uInt32 nHelpId; - rStream.ReadByteString(aName, eEnc ); - rStream.ReadByteString(aParent, eEnc ); - rStream.ReadByteString(aFollow, eEnc ); - rStream >> nFamily >> nStyleMask; - SfxPoolItem::readByteString(rStream, aHelpFile); - rStream >> nHelpId; - - SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask); - rSheet.SetHelpId( aHelpFile, nHelpId ); - // Hier erst einmal Parent und Follow zwischenspeichern - rSheet.aParent = aParent; - rSheet.aFollow = aFollow; - sal_uInt32 nPos = rStream.Tell(); - rStream >> nCount; - if(nCount) - { - rStream.Seek( nPos ); - // Das Laden des ItemSets bedient sich der Methode GetItemSet(), - // damit eigene ItemSets untergeschoben werden koennen - SfxItemSet& rSet = rSheet.GetItemSet(); - rSet.ClearItem(); - //! SfxItemSet aTmpSet( *pTmpPool ); - /*!aTmpSet*/ rSet.Load( rStream ); - //! rSet.Put( aTmpSet ); - } - // Lokale Teile - sal_uInt32 nSize; - sal_uInt16 nVer; - rStream >> nVer >> nSize; - nPos = rStream.Tell() + nSize; - rSheet.Load( rStream, nVer ); - rStream.Seek( nPos ); - } - - // #72939# only loop through the styles that were really inserted - sal_uLong n = aStyles.size(); - - //! delete pTmpPool; - // Jetzt Parent und Follow setzen. Alle Sheets sind geladen. - // Mit Setxxx() noch einmal den String eintragen, da diese - // virtuellen Methoden evtl. ueberlagert sind. - for ( sal_uLong i = 0; i < n; i++ ) - { - SfxStyleSheetBase* p = aStyles[ i ].get(); - XubString aText = p->aParent; - p->aParent.Erase(); - p->SetParent( aText ); - aText = p->aFollow; - p->aFollow.Erase(); - p->SetFollow( aText ); - } - - rStream.SetStreamCharSet( eOldEnc ); - } - - // alles klar? - return sal_Bool( rStream.GetError() == SVSTREAM_OK ); -} - -sal_Bool SfxStyleSheetBasePool::Load1_Impl( SvStream& rStream ) -{ - aAppName = rPool.GetName(); - sal_uInt16 nVersion; - short nCharSet; - rStream >> nVersion; - - if(nVersion!=STYLESTREAM_VERSION) - nCharSet=nVersion; - else - rStream >> nCharSet; - - rtl_TextEncoding eEnc = GetSOLoadTextEncoding( - (rtl_TextEncoding)nCharSet, - sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) ); - rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); - rStream.SetStreamCharSet( eEnc ); - - sal_uInt16 nStyles; - rStream >> nStyles; - sal_uInt16 i; - for ( i = 0; i < nStyles; i++ ) - { - // kann nicht mehr weiterlesen? - if ( rStream.GetError() ) - { - nStyles = i; - break; - } - - // Globale Teile - XubString aName, aParent, aFollow; - String aHelpFile; - sal_uInt16 nFamily, nStyleMask,nCount; - sal_uInt32 nHelpId; - rStream.ReadByteString(aName, eEnc ); - rStream.ReadByteString(aParent, eEnc ); - rStream.ReadByteString(aFollow, eEnc ); - rStream >> nFamily >> nStyleMask; - SfxPoolItem::readByteString(rStream, aHelpFile); - if(nVersion!=STYLESTREAM_VERSION) - { - sal_uInt16 nTmpHelpId; - rStream >> nTmpHelpId; - nHelpId=nTmpHelpId; - } - else - rStream >> nHelpId; - - SfxStyleSheetBase& rSheet = Make( aName, (SfxStyleFamily)nFamily , nStyleMask); - rSheet.SetHelpId( aHelpFile, nHelpId ); - // Hier erst einmal Parent und Follow zwischenspeichern - rSheet.aParent = aParent; - rSheet.aFollow = aFollow; - sal_uInt32 nPos = rStream.Tell(); - rStream >> nCount; - if(nCount) { - rStream.Seek( nPos ); - // Das Laden des ItemSets bedient sich der Methode GetItemSet(), - // damit eigene ItemSets untergeschoben werden koennen - SfxItemSet& rSet = rSheet.GetItemSet(); - rSet.ClearItem(); -//! SfxItemSet aTmpSet( *pTmpPool ); - /*!aTmpSet*/ rSet.Load( rStream ); - //! rSet.Put( aTmpSet ); - } - // Lokale Teile - sal_uInt32 nSize; - sal_uInt16 nVer; - rStream >> nVer >> nSize; - nPos = rStream.Tell() + nSize; - rSheet.Load( rStream, nVer ); - rStream.Seek( nPos ); - } - - //! delete pTmpPool; - // Jetzt Parent und Follow setzen. Alle Sheets sind geladen. - // Mit Setxxx() noch einmal den String eintragen, da diese - // virtuellen Methoden evtl. ueberlagert sind. - for ( i = 0; i < nStyles; i++ ) - { - SfxStyleSheetBase* p = aStyles[ i ].get(); - XubString aText = p->aParent; - p->aParent.Erase(); - p->SetParent( aText ); - aText = p->aFollow; - p->aFollow.Erase(); - p->SetFollow( aText ); - } - - rStream.SetStreamCharSet( eOldEnc ); - - return sal_Bool( rStream.GetError() == SVSTREAM_OK ); -} - -sal_Bool SfxStyleSheetBasePool::Store( SvStream& rStream, sal_Bool bUsed ) -{ - // den ganzen StyleSheet-Pool in einen Mini-Record - SfxMiniRecordWriter aPoolRec( &rStream, SFX_STYLES_REC ); - - // Erst einmal die Dummies rauszaehlen; die werden nicht gespeichert - sal_uInt16 nCount = 0; - for( SfxStyleSheetBase* p = First(); p; p = Next() ) - { - if(!bUsed || p->IsUsed()) - nCount++; - } - - // einen Header-Record vorweg - rtl_TextEncoding eEnc - = ::GetSOStoreTextEncoding( - rStream.GetStreamCharSet(), - sal::static_int_cast< sal_uInt16 >(rStream.GetVersion()) ); - rtl_TextEncoding eOldEnc = rStream.GetStreamCharSet(); - rStream.SetStreamCharSet( eEnc ); - - { - SfxSingleRecordWriter aHeaderRec( &rStream, - SFX_STYLES_REC_HEADER, - STYLESTREAM_VERSION ); - rStream << (short) eEnc; - } - - // die StyleSheets in einen MultiVarRecord - { - // Bug 79478: - // make a check loop, to be shure, that the converted names are also - // unique like the originals! In other cases we get a loop. - SvStringsSortDtor aSortOrigNames( 0, 128 ); - SvStrings aOrigNames( 0, 128 ); - SvByteStringsSortDtor aSortConvNames( 0, 128 ); - SvByteStrings aConvNames( 0, 128 ); - - { - - for( SfxStyleSheetBase* p = First(); p; p = Next() ) - { - if(!bUsed || p->IsUsed()) - { - sal_uInt16 nFamily = (sal_uInt16)p->GetFamily(); - String* pName = new String( p->GetName() ); - ByteString* pConvName = new ByteString( *pName, eEnc ); - - pName->Insert( (sal_Unicode)nFamily, 0 ); - pConvName->Insert( " ", 0 ); - pConvName->SetChar( - 0, - sal::static_int_cast< char >(0xff & (nFamily >> 8)) ); - pConvName->SetChar( - 1, sal::static_int_cast< char >(0xff & nFamily) ); - - sal_uInt16 nInsPos, nAdd = aSortConvNames.Count(); - while( !aSortConvNames.Insert( pConvName, nInsPos ) ) - (pConvName->Append( '_' )).Append(ByteString( - rtl::OString::valueOf(static_cast<sal_Int32>(nAdd++)))); - aOrigNames.Insert( pName, nInsPos ); - } - } - - // now we have the list of the names, sorted by convertede names - // But now we need the sorted list of orignames. - { - sal_uInt16 nInsPos, nEnd = aOrigNames.Count(); - const ByteStringPtr* ppB = aSortConvNames.GetData(); - for( sal_uInt16 n = 0; n < nEnd; ++n, ++ppB ) - { - String* p = aOrigNames.GetObject( n ); - aSortOrigNames.Insert( p, nInsPos ); - aConvNames.Insert( *ppB, nInsPos ); - } - - } - } - - - ByteString sEmpty; - sal_uInt16 nFndPos; - String sNm; - SfxMultiVarRecordWriter aStylesRec( &rStream, SFX_STYLES_REC_STYLES, 0 ); - for( SfxStyleSheetBase* p = First(); p; p = Next() ) - { - if(!bUsed || p->IsUsed()) - { - aStylesRec.NewContent(); - - // Globale Teile speichern - String aHelpFile; - sal_uInt32 nHelpId = p->GetHelpId( aHelpFile ); - sal_uInt16 nFamily = sal::static_int_cast< sal_uInt16 >(p->GetFamily()); - String sFamily( (sal_Unicode)nFamily ); - - (sNm = sFamily) += p->GetName(); - if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) - rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); - else - rStream.WriteByteString( sEmpty ); - - (sNm = sFamily) += p->GetParent(); - if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) - rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); - else - rStream.WriteByteString( sEmpty ); - - (sNm = sFamily) += p->GetFollow(); - if( aSortOrigNames.Seek_Entry( &sNm, &nFndPos )) - rStream.WriteByteString( aConvNames.GetObject( nFndPos )->Copy( 2 )); - else - rStream.WriteByteString( sEmpty ); - - rStream << nFamily << p->GetMask(); - SfxPoolItem::writeByteString(rStream, aHelpFile); - rStream << nHelpId; - if(p->pSet) - p->pSet->Store( rStream ); - else - rStream << (sal_uInt16)0; - - // Lokale Teile speichern - // Vor dem lokalen Teil wird die Laenge der lokalen Daten - // als sal_uInt32 sowie die Versionsnummer gespeichert. - rStream << (sal_uInt16) p->GetVersion(); - sal_uLong nPos1 = rStream.Tell(); - rStream << (sal_uInt32) 0; - p->Store( rStream ); - sal_uLong nPos2 = rStream.Tell(); - rStream.Seek( nPos1 ); - rStream << (sal_uInt32) ( nPos2 - nPos1 - sizeof( sal_uInt32 ) ); - rStream.Seek( nPos2 ); - if( rStream.GetError() != SVSTREAM_OK ) - break; - } - } - } - - rStream.SetStreamCharSet( eOldEnc ); - - return sal_Bool( rStream.GetError() == SVSTREAM_OK ); -} - -SfxItemPool& SfxStyleSheetBasePool::GetPool() -{ - return rPool; -} - -const SfxItemPool& SfxStyleSheetBasePool::GetPool() const -{ - return rPool; -} - -/////////////////////// SfxStyleSheet ///////////////////////////////// - -SfxStyleSheet::SfxStyleSheet(const XubString &rName, - const SfxStyleSheetBasePool& r_Pool, - SfxStyleFamily eFam, - sal_uInt16 mask ): - SfxStyleSheetBase(rName, const_cast< SfxStyleSheetBasePool& >( r_Pool ), eFam, mask) -{} - -SfxStyleSheet::SfxStyleSheet(const SfxStyleSheet& rStyle) : - SfxStyleSheetBase(rStyle), - SfxListener( rStyle ), - SfxBroadcaster( rStyle ) -{} - -SfxStyleSheet::SfxStyleSheet() -{ -} - -SfxStyleSheet::~SfxStyleSheet() -{ - Broadcast( SfxStyleSheetHint( SFX_STYLESHEET_INDESTRUCTION, *this ) ); -} - - -sal_Bool SfxStyleSheet::SetParent( const XubString& rName ) -{ - if(aParent == rName) - return sal_True; - const XubString aOldParent(aParent); - if(SfxStyleSheetBase::SetParent(rName)) { - // aus der Benachrichtigungskette des alten - // Parents gfs. austragen - if(aOldParent.Len()) { - SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aOldParent, nFamily, 0xffff); - if(pParent) - EndListening(*pParent); - } - // in die Benachrichtigungskette des neuen - // Parents eintragen - if(aParent.Len()) { - SfxStyleSheet *pParent = (SfxStyleSheet *)rPool.Find(aParent, nFamily, 0xffff); - if(pParent) - StartListening(*pParent); - } - return sal_True; - } - return sal_False; -} - -// alle Zuhoerer benachtichtigen - -void SfxStyleSheet::Notify(SfxBroadcaster& rBC, const SfxHint& rHint ) -{ - Forward(rBC, rHint); -} - -//////////////////////// SfxStyleSheetPool /////////////////////////////// - -SfxStyleSheetPool::SfxStyleSheetPool( SfxItemPool const& rSet) -: SfxStyleSheetBasePool( const_cast< SfxItemPool& >( rSet ) ) -{ -} - -/////////////////////////////////// Factory //////////////////////////////// - -SfxStyleSheetBase* SfxStyleSheetPool::Create( const XubString& rName, - SfxStyleFamily eFam, sal_uInt16 mask ) -{ - return new SfxStyleSheet( rName, *this, eFam, mask ); -} - -SfxStyleSheetBase* SfxStyleSheetPool::Create( const SfxStyleSheet& r ) -{ - return new SfxStyleSheet( r ); -} -/* -sal_Bool SfxStyleSheetPool::CopyTo(SfxStyleSheetPool &, const String &) -{ - return sal_False; -} -*/ - -// -------------------------------------------------------------------- -// class SfxUnoStyleSheet -// -------------------------------------------------------------------- - -SfxUnoStyleSheet::SfxUnoStyleSheet( const UniString& _rName, const SfxStyleSheetBasePool& _rPool, SfxStyleFamily _eFamily, sal_uInt16 _nMaske ) -: ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rName, _rPool, _eFamily, _nMaske ) -{ -} - -// -------------------------------------------------------------------- -SfxUnoStyleSheet::SfxUnoStyleSheet( const SfxStyleSheet& _rSheet ) -: ::cppu::ImplInheritanceHelper2< SfxStyleSheet, ::com::sun::star::style::XStyle, ::com::sun::star::lang::XUnoTunnel >( _rSheet ) -{ -} - -// -------------------------------------------------------------------- - -SfxUnoStyleSheet* SfxUnoStyleSheet::getUnoStyleSheet( const ::com::sun::star::uno::Reference< ::com::sun::star::style::XStyle >& xStyle ) -{ - SfxUnoStyleSheet* pRet = dynamic_cast< SfxUnoStyleSheet* >( xStyle.get() ); - if( !pRet ) - { - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( xStyle, ::com::sun::star::uno::UNO_QUERY ); - if( xUT.is() ) - pRet = reinterpret_cast<SfxUnoStyleSheet*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SfxUnoStyleSheet::getIdentifier()))); - } - return pRet; -} - -// -------------------------------------------------------------------- -// XUnoTunnel -// -------------------------------------------------------------------- - -::sal_Int64 SAL_CALL SfxUnoStyleSheet::getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& rId ) throw (::com::sun::star::uno::RuntimeException) -{ - if( rId.getLength() == 16 && 0 == rtl_compareMemory( getIdentifier().getConstArray(), rId.getConstArray(), 16 ) ) - { - return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this)); - } - else - { - return 0; - } -} - -// -------------------------------------------------------------------- - -namespace -{ - class theSfxUnoStyleSheetIdentifier : public rtl::Static< UnoTunnelIdInit, theSfxUnoStyleSheetIdentifier > {}; -} - -const ::com::sun::star::uno::Sequence< ::sal_Int8 >& SfxUnoStyleSheet::getIdentifier() -{ - return theSfxUnoStyleSheetIdentifier::get().getSeq(); -} - -// -------------------------------------------------------------------- - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/stylepool.cxx b/svl/source/items/stylepool.cxx deleted file mode 100644 index d55424adb2..0000000000 --- a/svl/source/items/stylepool.cxx +++ /dev/null @@ -1,501 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#ifdef _MSC_VER -#pragma hdrstop -#endif - -#include <vector> -#include <map> - -#include <svl/stylepool.hxx> -#include <svl/itemiter.hxx> -#include <svl/itempool.hxx> - - -using namespace boost; - -namespace { - // A "Node" represents a subset of inserted SfxItemSets - // The root node represents the empty set - // The other nodes contain a SfxPoolItem and represents an item set which contains their - // pool item and the pool items of their parents. - class Node - { - std::vector<Node*> mChildren; // child nodes, create by findChildNode(..) - // container of shared pointers of inserted item sets; for non-poolable - // items more than one item set is needed - std::vector< StylePool::SfxItemSet_Pointer_t > maItemSet; - const SfxPoolItem *mpItem; // my pool item - Node *mpUpper; // if I'm a child node that's my parent node - // #i86923# - const bool mbIsItemIgnorable; - public: - // #i86923# - Node() // root node Ctor - : mChildren(), - maItemSet(), - mpItem( 0 ), - mpUpper( 0 ), - mbIsItemIgnorable( false ) - {} - Node( const SfxPoolItem& rItem, Node* pParent, const bool bIgnorable ) // child node Ctor - : mChildren(), - maItemSet(), - mpItem( rItem.Clone() ), - mpUpper( pParent ), - mbIsItemIgnorable( bIgnorable ) - {} - ~Node(); - // #i86923# - bool hasItemSet( const bool bCheckUsage ) const; - // #i87808# - const StylePool::SfxItemSet_Pointer_t getItemSet() const - { - return maItemSet.back(); - } - const StylePool::SfxItemSet_Pointer_t getUsedOrLastAddedItemSet() const; - void setItemSet( const SfxItemSet& rSet ){ maItemSet.push_back( StylePool::SfxItemSet_Pointer_t( rSet.Clone() ) ); } - // #i86923# - Node* findChildNode( const SfxPoolItem& rItem, - const bool bIsItemIgnorable = false ); - Node* nextItemSet( Node* pLast, - const bool bSkipUnusedItemSet, - const bool bSkipIgnorable ); - const SfxPoolItem& getPoolItem() const { return *mpItem; } - // #i86923# - bool hasIgnorableChildren( const bool bCheckUsage ) const; - const StylePool::SfxItemSet_Pointer_t getItemSetOfIgnorableChild( - const bool bSkipUnusedItemSets ) const; - }; - - // #i87808# - const StylePool::SfxItemSet_Pointer_t Node::getUsedOrLastAddedItemSet() const - { - std::vector< StylePool::SfxItemSet_Pointer_t >::const_reverse_iterator aIter; - - for ( aIter = maItemSet.rbegin(); aIter != maItemSet.rend(); ++aIter ) - { - if ( (*aIter).use_count() > 1 ) - { - return *aIter; - } - } - - return maItemSet.back(); - } - - // #i86923# - bool Node::hasItemSet( const bool bCheckUsage ) const - { - bool bHasItemSet = false; - - if ( maItemSet.size() > 0 ) - { - if ( bCheckUsage ) - { - std::vector< StylePool::SfxItemSet_Pointer_t >::const_reverse_iterator aIter; - - for ( aIter = maItemSet.rbegin(); aIter != maItemSet.rend(); ++aIter ) - { - if ( (*aIter).use_count() > 1 ) - { - bHasItemSet = true; - break; - } - } - } - else - { - bHasItemSet = true; - } - } - return bHasItemSet; - } - - // #i86923# - Node* Node::findChildNode( const SfxPoolItem& rItem, - const bool bIsItemIgnorable ) - { - Node* pNextNode = this; - std::vector<Node*>::iterator aIter = mChildren.begin(); - while( aIter != mChildren.end() ) - { - if( rItem.Which() == (*aIter)->getPoolItem().Which() && - rItem == (*aIter)->getPoolItem() ) - return *aIter; - ++aIter; - } - // #i86923# - pNextNode = new Node( rItem, pNextNode, bIsItemIgnorable ); - mChildren.push_back( pNextNode ); - return pNextNode; - } - - /* Find the next node which has a SfxItemSet. - The input parameter pLast has a sophisticated meaning: - downstairs only: - pLast == 0 => scan your children and their children - but neither your parents neither your siblings - downstairs and upstairs: - pLast == this => scan your children, their children, - the children of your parent behind you, and so on - partial downstairs and upstairs - pLast != 0 && pLast != this => scan your children behind the given children, - the children of your parent behind you and so on. - - OD 2008-03-11 #i86923# - introduce parameters <bSkipUnusedItemSets> and <bSkipIgnorable> - and its handling. - */ - Node* Node::nextItemSet( Node* pLast, - const bool bSkipUnusedItemSets, - const bool bSkipIgnorable ) - { - // Searching downstairs - std::vector<Node*>::iterator aIter = mChildren.begin(); - // For pLast == 0 and pLast == this all children are of interest - // for another pLast the search starts behind pLast... - if( pLast && pLast != this ) - { - aIter = std::find( mChildren.begin(), mChildren.end(), pLast ); - if( aIter != mChildren.end() ) - ++aIter; - } - Node *pNext = 0; - while( aIter != mChildren.end() ) - { - // #i86923# - if ( bSkipIgnorable && (*aIter)->mbIsItemIgnorable ) - { - ++aIter; - continue; - } - pNext = *aIter; - // #i86923# - if ( pNext->hasItemSet( bSkipUnusedItemSets ) ) - { - return pNext; - } - if ( bSkipIgnorable && - pNext->hasIgnorableChildren( bSkipUnusedItemSets ) ) - { - return pNext; - } - pNext = pNext->nextItemSet( 0, bSkipUnusedItemSets, bSkipIgnorable ); // 0 => downstairs only - if( pNext ) - return pNext; - ++aIter; - } - // Searching upstairs - if( pLast && mpUpper ) - { - // #i86923# - pNext = mpUpper->nextItemSet( this, bSkipUnusedItemSets, bSkipIgnorable ); - } - return pNext; - } - - // #i86923# - bool Node::hasIgnorableChildren( const bool bCheckUsage ) const - { - bool bHasIgnorableChildren( false ); - - std::vector<Node*>::const_iterator aIter = mChildren.begin(); - while( aIter != mChildren.end() && !bHasIgnorableChildren ) - { - Node* pChild = *aIter; - if ( pChild->mbIsItemIgnorable ) - { - bHasIgnorableChildren = - !bCheckUsage || - ( pChild->hasItemSet( bCheckUsage /* == true */ ) || - pChild->hasIgnorableChildren( bCheckUsage /* == true */ ) ); - } - ++aIter; - } - - return bHasIgnorableChildren; - } - - const StylePool::SfxItemSet_Pointer_t Node::getItemSetOfIgnorableChild( - const bool bSkipUnusedItemSets ) const - { - DBG_ASSERT( hasIgnorableChildren( bSkipUnusedItemSets ), - "<Node::getItemSetOfIgnorableChild> - node has no ignorable children" ); - - std::vector<Node*>::const_iterator aIter = mChildren.begin(); - while( aIter != mChildren.end() ) - { - Node* pChild = *aIter; - if ( pChild->mbIsItemIgnorable ) - { - if ( pChild->hasItemSet( bSkipUnusedItemSets ) ) - { - return pChild->getUsedOrLastAddedItemSet(); - } - else - { - pChild = pChild->nextItemSet( 0, bSkipUnusedItemSets, false ); - if ( pChild ) - { - return pChild->getUsedOrLastAddedItemSet(); - } - } - } - ++aIter; - } - - StylePool::SfxItemSet_Pointer_t pReturn; - return pReturn; - } - - Node::~Node() - { - std::vector<Node*>::iterator aIter = mChildren.begin(); - while( aIter != mChildren.end() ) - { - delete *aIter; - ++aIter; - } - delete mpItem; - } - - class Iterator : public IStylePoolIteratorAccess - { - std::map< const SfxItemSet*, Node >& mrRoot; - std::map< const SfxItemSet*, Node >::iterator mpCurrNode; - Node* mpNode; - const bool mbSkipUnusedItemSets; - const bool mbSkipIgnorable; - public: - // #i86923# - Iterator( std::map< const SfxItemSet*, Node >& rR, - const bool bSkipUnusedItemSets, - const bool bSkipIgnorable ) - : mrRoot( rR ), - mpCurrNode( rR.begin() ), - mpNode(0), - mbSkipUnusedItemSets( bSkipUnusedItemSets ), - mbSkipIgnorable( bSkipIgnorable ) - {} - virtual StylePool::SfxItemSet_Pointer_t getNext(); - virtual ::rtl::OUString getName(); - }; - - StylePool::SfxItemSet_Pointer_t Iterator::getNext() - { - StylePool::SfxItemSet_Pointer_t pReturn; - while( mpNode || mpCurrNode != mrRoot.end() ) - { - if( !mpNode ) - { - mpNode = &mpCurrNode->second; - ++mpCurrNode; - // #i86923# - if ( mpNode->hasItemSet( mbSkipUnusedItemSets ) ) - { - // #i87808# - return mpNode->getUsedOrLastAddedItemSet(); - } - } - // #i86923# - mpNode = mpNode->nextItemSet( mpNode, mbSkipUnusedItemSets, mbSkipIgnorable ); - if ( mpNode && mpNode->hasItemSet( mbSkipUnusedItemSets ) ) - { - // #i87808# - return mpNode->getUsedOrLastAddedItemSet(); - } - if ( mbSkipIgnorable && - mpNode && mpNode->hasIgnorableChildren( mbSkipUnusedItemSets ) ) - { - return mpNode->getItemSetOfIgnorableChild( mbSkipUnusedItemSets ); - } - } - return pReturn; - } - - ::rtl::OUString Iterator::getName() - { - ::rtl::OUString aString; - if( mpNode && mpNode->hasItemSet( false ) ) - { - aString = StylePool::nameOf( mpNode->getUsedOrLastAddedItemSet() ); - } - return aString; - } - -} - -/* This static method creates a unique name from a shared pointer to a SfxItemSet - The name is the memory address of the SfxItemSet itself. */ - -::rtl::OUString StylePool::nameOf( SfxItemSet_Pointer_t pSet ) -{ - return ::rtl::OUString::valueOf( reinterpret_cast<sal_IntPtr>( pSet.get() ), 16 ); -} - -// class StylePoolImpl organized a tree-structure where every node represents a SfxItemSet. -// The insertItemSet method adds a SfxItemSet into the tree if necessary and returns a shared_ptr -// to a copy of the SfxItemSet. -// The aRoot-Node represents an empty SfxItemSet. - -class StylePoolImpl -{ -private: - std::map< const SfxItemSet*, Node > maRoot; - sal_Int32 mnCount; - // #i86923# - SfxItemSet* mpIgnorableItems; -public: - // #i86923# - explicit StylePoolImpl( SfxItemSet* pIgnorableItems = 0 ) - : maRoot(), - mnCount(0), - mpIgnorableItems( pIgnorableItems != 0 - ? pIgnorableItems->Clone( sal_False ) - : 0 ) - { - DBG_ASSERT( !pIgnorableItems || !pIgnorableItems->Count(), - "<StylePoolImpl::StylePoolImpl(..)> - misusage: item set for ignorable item should be empty. Please correct usage." ); - DBG_ASSERT( !mpIgnorableItems || !mpIgnorableItems->Count(), - "<StylePoolImpl::StylePoolImpl(..)> - <SfxItemSet::Clone( sal_False )> does not work as excepted - <mpIgnorableItems> is not empty. Please inform OD." ); - } - - ~StylePoolImpl() - { - delete mpIgnorableItems; - } - - StylePool::SfxItemSet_Pointer_t insertItemSet( const SfxItemSet& rSet ); - - // #i86923# - IStylePoolIteratorAccess* createIterator( bool bSkipUnusedItemSets = false, - bool bSkipIgnorableItems = false ); - sal_Int32 getCount() const { return mnCount; } -}; - -StylePool::SfxItemSet_Pointer_t StylePoolImpl::insertItemSet( const SfxItemSet& rSet ) -{ - bool bNonPoolable = false; - Node* pCurNode = &maRoot[ rSet.GetParent() ]; - SfxItemIter aIter( rSet ); - const SfxPoolItem* pItem = aIter.GetCurItem(); - // Every SfxPoolItem in the SfxItemSet causes a step deeper into the tree, - // a complete empty SfxItemSet would stay at the root node. - // #i86923# insert ignorable items to the tree leaves. - std::auto_ptr<SfxItemSet> pFoundIgnorableItems; - if ( mpIgnorableItems ) - { - pFoundIgnorableItems.reset( new SfxItemSet( *mpIgnorableItems ) ); - } - while( pItem ) - { - if( !rSet.GetPool()->IsItemFlag(pItem->Which(), SFX_ITEM_POOLABLE ) ) - bNonPoolable = true; - if ( !pFoundIgnorableItems.get() || - ( pFoundIgnorableItems.get() && - pFoundIgnorableItems->Put( *pItem ) == 0 ) ) - { - pCurNode = pCurNode->findChildNode( *pItem ); - } - pItem = aIter.NextItem(); - } - if ( pFoundIgnorableItems.get() && - pFoundIgnorableItems->Count() > 0 ) - { - SfxItemIter aIgnorableItemsIter( *pFoundIgnorableItems ); - pItem = aIgnorableItemsIter.GetCurItem(); - while( pItem ) - { - if( !rSet.GetPool()->IsItemFlag(pItem->Which(), SFX_ITEM_POOLABLE ) ) - bNonPoolable = true; - pCurNode = pCurNode->findChildNode( *pItem, true ); - pItem = aIgnorableItemsIter.NextItem(); - } - } - // Every leaf node represents an inserted item set, but "non-leaf" nodes represents subsets - // of inserted itemsets. - // These nodes could have but does not need to have a shared_ptr to a item set. - if( !pCurNode->hasItemSet( false ) ) - { - pCurNode->setItemSet( rSet ); - bNonPoolable = false; // to avoid a double insertion - ++mnCount; - } - // If rSet contains at least one non poolable item, a new itemset has to be inserted - if( bNonPoolable ) - pCurNode->setItemSet( rSet ); -#ifdef DEBUG - { - sal_Int32 nCheck = -1; - IStylePoolIteratorAccess* pIter = createIterator(); - StylePool::SfxItemSet_Pointer_t pTemp; - do - { - ++nCheck; - pTemp = pIter->getNext(); - } while( pTemp.get() ); - DBG_ASSERT( mnCount == nCheck, "Wrong counting"); - delete pIter; - } -#endif - return pCurNode->getItemSet(); -} - -// #i86923# -IStylePoolIteratorAccess* StylePoolImpl::createIterator( bool bSkipUnusedItemSets, - bool bSkipIgnorableItems ) -{ - return new Iterator( maRoot, bSkipUnusedItemSets, bSkipIgnorableItems ); -} -// Ctor, Dtor and redirected methods of class StylePool, nearly inline ;-) - -// #i86923# -StylePool::StylePool( SfxItemSet* pIgnorableItems ) - : pImpl( new StylePoolImpl( pIgnorableItems ) ) -{} - -StylePool::SfxItemSet_Pointer_t StylePool::insertItemSet( const SfxItemSet& rSet ) -{ return pImpl->insertItemSet( rSet ); } - -// #i86923# -IStylePoolIteratorAccess* StylePool::createIterator( const bool bSkipUnusedItemSets, - const bool bSkipIgnorableItems ) -{ - return pImpl->createIterator( bSkipUnusedItemSets, bSkipIgnorableItems ); -} - -sal_Int32 StylePool::getCount() const -{ return pImpl->getCount(); } - -StylePool::~StylePool() { delete pImpl; } - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/szitem.cxx b/svl/source/items/szitem.cxx deleted file mode 100644 index f7620da68f..0000000000 --- a/svl/source/items/szitem.cxx +++ /dev/null @@ -1,213 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/szitem.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <com/sun/star/awt/Size.hpp> -#include <tools/stream.hxx> -#include <tools/gen.hxx> - -#include <svl/poolitem.hxx> -#include <svl/memberid.hrc> - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxSizeItem) - -// ----------------------------------------------------------------------- - -TYPEINIT1_AUTOFACTORY(SfxSizeItem, SfxPoolItem); - -// ----------------------------------------------------------------------- - -SfxSizeItem::SfxSizeItem() -{ - DBG_CTOR(SfxSizeItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxSizeItem::SfxSizeItem( sal_uInt16 nW, const Size& rVal ) : - SfxPoolItem( nW ), - aVal( rVal ) -{ - DBG_CTOR(SfxSizeItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxSizeItem::SfxSizeItem( sal_uInt16 nW, SvStream &rStream ) : - SfxPoolItem( nW ) -{ - DBG_CTOR(SfxSizeItem, 0); - rStream >> aVal; -} - -// ----------------------------------------------------------------------- - -SfxSizeItem::SfxSizeItem( const SfxSizeItem& rItem ) : - SfxPoolItem( rItem ), - aVal( rItem.aVal ) -{ - DBG_CTOR(SfxSizeItem, 0); -} - -// ----------------------------------------------------------------------- - -SfxItemPresentation SfxSizeItem::GetPresentation -( - SfxItemPresentation /*ePresentation*/, - SfxMapUnit /*eCoreMetric*/, - SfxMapUnit /*ePresentationMetric*/, - XubString& rText, - const IntlWrapper * -) const -{ - DBG_CHKTHIS(SfxSizeItem, 0); - rText = UniString::CreateFromInt32(aVal.Width()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - rText += UniString::CreateFromInt32(aVal.Height()); - rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM(", ")); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - -// ----------------------------------------------------------------------- - -int SfxSizeItem::operator==( const SfxPoolItem& rItem ) const -{ - DBG_CHKTHIS(SfxSizeItem, 0); - DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" ); - return ((SfxSizeItem&)rItem).aVal == aVal; -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxSizeItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(SfxSizeItem, 0); - return new SfxSizeItem( *this ); -} - -// ----------------------------------------------------------------------- - -SfxPoolItem* SfxSizeItem::Create(SvStream &rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxSizeItem, 0); - Size aStr; - rStream >> aStr; - return new SfxSizeItem(Which(), aStr); -} - -// ----------------------------------------------------------------------- - -SvStream& SfxSizeItem::Store(SvStream &rStream, sal_uInt16 ) const -{ - DBG_CHKTHIS(SfxSizeItem, 0); - rStream << aVal; - return rStream; -} - -// ----------------------------------------------------------------------- -bool SfxSizeItem::QueryValue( com::sun::star::uno::Any& rVal, - sal_uInt8 nMemberId ) const -{ - sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); - nMemberId &= ~CONVERT_TWIPS; - - Size aTmp(aVal); - if( bConvert ) - { - aTmp.Height() = ( aTmp.Height() * 127 + 36) / 72; - aTmp.Width() = ( aTmp.Width() * 127 + 36) / 72; - } - - switch ( nMemberId ) - { - case 0: - { - rVal <<= com::sun::star::awt::Size( aTmp.getWidth(), aTmp.getHeight() ); - break; - } - case MID_WIDTH: - rVal <<= aTmp.getWidth(); break; - case MID_HEIGHT: - rVal <<= aTmp.getHeight(); break; - default: OSL_FAIL("Wrong MemberId!"); return false; - } - - return true; -} - -// ----------------------------------------------------------------------- -bool SfxSizeItem::PutValue( const com::sun::star::uno::Any& rVal, - sal_uInt8 nMemberId ) -{ - sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); - nMemberId &= ~CONVERT_TWIPS; - - bool bRet = false; - com::sun::star::awt::Size aValue; - sal_Int32 nVal = 0; - if ( !nMemberId ) - bRet = ( rVal >>= aValue ); - else - { - bRet = ( rVal >>= nVal ); - if ( nMemberId == MID_WIDTH ) - { - aValue.Width = nVal; - aValue.Height = aVal.Height(); - } - else - { - aValue.Height = nVal; - aValue.Width = aVal.Width(); - } - } - - if ( bRet ) - { - Size aTmp( aValue.Width, aValue.Height ); - if( bConvert ) - { - aTmp.Height() = ( aTmp.Height() * 72 + 63) / 127; - aTmp.Width() = ( aTmp.Width() * 72 + 63) / 127; - } - - aVal = aTmp; - } - - return bRet; -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/visitem.cxx b/svl/source/items/visitem.cxx deleted file mode 100644 index ac988a6d3b..0000000000 --- a/svl/source/items/visitem.cxx +++ /dev/null @@ -1,148 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/visitem.hxx> -#include <com/sun/star/uno/Any.hxx> -#include <tools/stream.hxx> - -//============================================================================ -// -// class SfxVisibilityItem -// -//============================================================================ - -DBG_NAME(SfxVisibilityItem) - -//============================================================================ -TYPEINIT1_AUTOFACTORY(SfxVisibilityItem, SfxPoolItem); - -//============================================================================ -SfxVisibilityItem::SfxVisibilityItem(sal_uInt16 which, SvStream & rStream): - SfxPoolItem(which) -{ - DBG_CTOR(SfxVisibilityItem, 0); - sal_Bool bValue = 0; - rStream >> bValue; - m_nValue.bVisible = bValue; -} - -//============================================================================ -// virtual -int SfxVisibilityItem::operator ==(const SfxPoolItem & rItem) const -{ - DBG_CHKTHIS(SfxVisibilityItem, 0); - DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type"); - return m_nValue.bVisible == SAL_STATIC_CAST(const SfxVisibilityItem *, &rItem)-> - m_nValue.bVisible; -} - -//============================================================================ -// virtual -int SfxVisibilityItem::Compare(const SfxPoolItem & rWith) const -{ - DBG_ASSERT(rWith.ISA(SfxVisibilityItem), "SfxVisibilityItem::Compare(): Bad type"); - return m_nValue.bVisible == static_cast< SfxVisibilityItem const * >(&rWith)->m_nValue.bVisible ? - 0 : m_nValue.bVisible ? -1 : 1; -} - -//============================================================================ -// virtual -SfxItemPresentation SfxVisibilityItem::GetPresentation(SfxItemPresentation, - SfxMapUnit, SfxMapUnit, - XubString & rText, - const IntlWrapper *) const -{ - rText = GetValueTextByVal(m_nValue.bVisible); - return SFX_ITEM_PRESENTATION_NAMELESS; -} - - -//============================================================================ -// virtual -bool SfxVisibilityItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const -{ - rVal <<= m_nValue; - return true; -} - -//============================================================================ -// virtual -bool SfxVisibilityItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8) -{ - if (rVal >>= m_nValue) - return true; - - OSL_FAIL( "SfxInt16Item::PutValue - Wrong type!" ); - return false; -} - -//============================================================================ -// virtual -SfxPoolItem * SfxVisibilityItem::Create(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(SfxVisibilityItem, 0); - return new SfxVisibilityItem(Which(), rStream); -} - -//============================================================================ -// virtual -SvStream & SfxVisibilityItem::Store(SvStream & rStream, sal_uInt16) const -{ - DBG_CHKTHIS(SfxVisibilityItem, 0); - rStream << m_nValue.bVisible; - return rStream; -} - -//============================================================================ -// virtual -SfxPoolItem * SfxVisibilityItem::Clone(SfxItemPool *) const -{ - DBG_CHKTHIS(SfxVisibilityItem, 0); - return new SfxVisibilityItem(*this); -} - -//============================================================================ -// virtual -sal_uInt16 SfxVisibilityItem::GetValueCount() const -{ - return 2; -} - -//============================================================================ -// virtual -UniString SfxVisibilityItem::GetValueTextByVal(sal_Bool bTheValue) const -{ - return - bTheValue ? - UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("TRUE")) : - UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("FALSE")); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/whassert.hxx b/svl/source/items/whassert.hxx deleted file mode 100644 index e0f6efc124..0000000000 --- a/svl/source/items/whassert.hxx +++ /dev/null @@ -1,57 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_WHASSERT_HXX -#define _SFX_WHASSERT_HXX - -#include <tools/debug.hxx> -#include <rtl/strbuf.hxx> - -//------------------------------------------------------------------------ - -#ifdef DBG_UTIL -#define SFX_ASSERT( bCondition, nId, sMessage ) \ -{ \ - if ( DbgIsAssert() ) \ - { \ - if ( !(bCondition) ) \ - { \ - rtl::OStringBuffer aMsg(sMessage); \ - aMsg.append(RTL_CONSTASCII_STRINGPARAM("\nwith Id/Pos: ")); \ - aMsg.append(static_cast<sal_Int32>(nId)); \ - DbgError(aMsg.getStr(), __FILE__, __LINE__); \ - } \ - } \ -} -#else -#define SFX_ASSERT( bCondition, nId, sMessage ) -#endif - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/items/whiter.cxx b/svl/source/items/whiter.cxx deleted file mode 100644 index cb4099ee38..0000000000 --- a/svl/source/items/whiter.cxx +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/whiter.hxx> -#include <svl/itemset.hxx> - -DBG_NAME(SfxWhichIter) - -// ----------------------------------------------------------------------- - -SfxWhichIter::SfxWhichIter( const SfxItemSet& rSet, sal_uInt16 nFromWh, sal_uInt16 nToWh ): - pRanges(rSet.GetRanges()), - pStart(rSet.GetRanges()), - nOfst(0), nFrom(nFromWh), nTo(nToWh) -{ - DBG_CTOR(SfxWhichIter, 0); - if ( nFrom > 0 ) - FirstWhich(); -} - -// ----------------------------------------------------------------------- - -SfxWhichIter::~SfxWhichIter() -{ - DBG_DTOR(SfxWhichIter, 0); -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxWhichIter::NextWhich() -{ - DBG_CHKTHIS(SfxWhichIter, 0); - while ( 0 != *pRanges ) - { - const sal_uInt16 nLastWhich = *pRanges + nOfst; - ++nOfst; - if (*(pRanges+1) == nLastWhich) - { - pRanges += 2; - nOfst = 0; - } - sal_uInt16 nWhich = *pRanges + nOfst; - if ( 0 == nWhich || ( nWhich >= nFrom && nWhich <= nTo ) ) - return nWhich; - } - return 0; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxWhichIter::PrevWhich() -{ - DBG_CHKTHIS(SfxWhichIter, 0); - while ( pRanges != pStart || 0 != nOfst ) - { - if(nOfst) - --nOfst; - else { - pRanges -= 2; - nOfst = *(pRanges+1) - (*pRanges); - } - sal_uInt16 nWhich = *pRanges + nOfst; - if ( nWhich >= nFrom && nWhich <= nTo ) - return nWhich; - } - return 0; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxWhichIter::FirstWhich() -{ - DBG_CHKTHIS(SfxWhichIter, 0); - pRanges = pStart; - nOfst = 0; - if ( *pRanges >= nFrom && *pRanges <= nTo ) - return *pRanges; - return NextWhich(); -} - -// ----------------------------------------------------------------------- - -sal_uInt16 SfxWhichIter::LastWhich() -{ - DBG_CHKTHIS(SfxWhichIter, 0); - while(*pRanges) - ++pRanges; - nOfst = 0; - sal_uInt16 nWhich = *(pRanges-1); - if ( nWhich >= nFrom && nWhich <= nTo ) - return nWhich; - return PrevWhich(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/memtools/svarray.cxx b/svl/source/memtools/svarray.cxx deleted file mode 100644 index 9995498970..0000000000 --- a/svl/source/memtools/svarray.cxx +++ /dev/null @@ -1,170 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#define _SVARRAY_CXX - -#define _SVSTDARR_ULONGS -#define _SVSTDARR_sal_uInt16S -#define _SVSTDARR_STRINGS -#define _SVSTDARR_STRINGSDTOR -#define _SVSTDARR_STRINGSSORT -#define _SVSTDARR_STRINGSSORTDTOR -#define _SVSTDARR_STRINGSISORT -#define _SVSTDARR_STRINGSISORTDTOR -#define _SVSTDARR_sal_uInt16SSORT - -#define _SVSTDARR_BYTESTRINGS -#define _SVSTDARR_BYTESTRINGSDTOR -#define _SVSTDARR_BYTESTRINGSSORT -#define _SVSTDARR_BYTESTRINGSSORTDTOR -#define _SVSTDARR_BYTESTRINGSISORT -#define _SVSTDARR_BYTESTRINGSISORTDTOR - -#define _SVSTDARR_XUB_STRLEN - -#include <svl/svstdarr.hxx> -#include <tools/string.hxx> -#include <tools/debug.hxx> - -SV_IMPL_VARARR(SvPtrarr,VoidPtr) - -sal_uInt16 SvPtrarr::GetPos( const VoidPtr& aElement ) const -{ sal_uInt16 n; - for( n=0; n < nA && *(GetData()+n) != aElement; ) n++; - return ( n >= nA ? USHRT_MAX : n ); -} - -SV_IMPL_VARARR( SvULongs, sal_uLong ) -SV_IMPL_VARARR( SvUShorts, sal_uInt16 ) - -SV_IMPL_PTRARR( SvStrings, StringPtr ) -SV_IMPL_PTRARR( SvStringsDtor, StringPtr ) -SV_IMPL_OP_PTRARR_SORT( SvStringsSort, StringPtr ) -SV_IMPL_OP_PTRARR_SORT( SvStringsSortDtor, StringPtr ) - -SV_IMPL_PTRARR( SvByteStrings, ByteStringPtr ) -SV_IMPL_OP_PTRARR_SORT( SvByteStringsSortDtor, ByteStringPtr ) - -// ---------------- strings ------------------------------------- - -// Array mit anderer Seek-Methode! -_SV_IMPL_SORTAR_ALG( SvStringsISort, StringPtr ) -void SvStringsISort::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) -{ - if( nL ) - { - DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" ); - for( sal_uInt16 n=nP; n < nP + nL; n++ ) - delete *((StringPtr*)pData+n); - SvPtrarr::Remove( nP, nL ); - } -} -sal_Bool SvStringsISort::Seek_Entry( const StringPtr aE, sal_uInt16* pP ) const -{ - register sal_uInt16 nO = SvStringsISort_SAR::Count(), - nM, - nU = 0; - if( nO > 0 ) - { - nO--; - while( nU <= nO ) - { - nM = nU + ( nO - nU ) / 2; - StringCompare eCmp = (*((StringPtr*)pData + nM))-> - CompareIgnoreCaseToAscii( *(aE) ); - if( COMPARE_EQUAL == eCmp ) - { - if( pP ) *pP = nM; - return sal_True; - } - else if( COMPARE_LESS == eCmp ) - nU = nM + 1; - else if( nM == 0 ) - { - if( pP ) *pP = nU; - return sal_False; - } - else - nO = nM - 1; - } - } - if( pP ) *pP = nU; - return sal_False; -} - -// ---------------- strings ------------------------------------- - -// Array mit anderer Seek-Methode! -_SV_IMPL_SORTAR_ALG( SvStringsISortDtor, StringPtr ) -void SvStringsISortDtor::DeleteAndDestroy( sal_uInt16 nP, sal_uInt16 nL ) -{ - if( nL ) - { - DBG_ASSERT( nP < nA && nP + nL <= nA, "ERR_VAR_DEL" ); - for( sal_uInt16 n=nP; n < nP + nL; n++ ) - delete *((StringPtr*)pData+n); - SvPtrarr::Remove( nP, nL ); - } -} -sal_Bool SvStringsISortDtor::Seek_Entry( const StringPtr aE, sal_uInt16* pP ) const -{ - register sal_uInt16 nO = SvStringsISortDtor_SAR::Count(), - nM, - nU = 0; - if( nO > 0 ) - { - nO--; - while( nU <= nO ) - { - nM = nU + ( nO - nU ) / 2; - StringCompare eCmp = (*((StringPtr*)pData + nM))-> - CompareIgnoreCaseToAscii( *(aE) ); - if( COMPARE_EQUAL == eCmp ) - { - if( pP ) *pP = nM; - return sal_True; - } - else if( COMPARE_LESS == eCmp ) - nU = nM + 1; - else if( nM == 0 ) - { - if( pP ) *pP = nU; - return sal_False; - } - else - nO = nM - 1; - } - } - if( pP ) *pP = nU; - return sal_False; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/PasswordHelper.cxx b/svl/source/misc/PasswordHelper.cxx deleted file mode 100644 index ae05d539b1..0000000000 --- a/svl/source/misc/PasswordHelper.cxx +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/PasswordHelper.hxx> -#include <rtl/digest.h> -#include <tools/string.hxx> - -using namespace com::sun::star; - -void SvPasswordHelper::GetHashPassword(uno::Sequence<sal_Int8>& rPassHash, const sal_Char* pPass, sal_uInt32 nLen) -{ - rPassHash.realloc(RTL_DIGEST_LENGTH_SHA1); - - rtlDigestError aError = rtl_digest_SHA1 (pPass, nLen, reinterpret_cast<sal_uInt8*>(rPassHash.getArray()), rPassHash.getLength()); - if (aError != rtl_Digest_E_None) - { - rPassHash.realloc(0); - } -} - -void SvPasswordHelper::GetHashPasswordLittleEndian(uno::Sequence<sal_Int8>& rPassHash, const String& sPass) -{ - xub_StrLen nSize(sPass.Len()); - sal_Char* pCharBuffer = new sal_Char[nSize * sizeof(sal_Unicode)]; - - for (xub_StrLen i = 0; i < nSize; ++i) - { - sal_Unicode ch(sPass.GetChar(i)); - pCharBuffer[2 * i] = static_cast< sal_Char >(ch & 0xFF); - pCharBuffer[2 * i + 1] = static_cast< sal_Char >(ch >> 8); - } - - GetHashPassword(rPassHash, pCharBuffer, nSize * sizeof(sal_Unicode)); - - delete[] pCharBuffer; -} - -void SvPasswordHelper::GetHashPasswordBigEndian(uno::Sequence<sal_Int8>& rPassHash, const String& sPass) -{ - xub_StrLen nSize(sPass.Len()); - sal_Char* pCharBuffer = new sal_Char[nSize * sizeof(sal_Unicode)]; - - for (xub_StrLen i = 0; i < nSize; ++i) - { - sal_Unicode ch(sPass.GetChar(i)); - pCharBuffer[2 * i] = static_cast< sal_Char >(ch >> 8); - pCharBuffer[2 * i + 1] = static_cast< sal_Char >(ch & 0xFF); - } - - GetHashPassword(rPassHash, pCharBuffer, nSize * sizeof(sal_Unicode)); - - delete[] pCharBuffer; -} - -void SvPasswordHelper::GetHashPassword(uno::Sequence<sal_Int8>& rPassHash, const String& sPass) -{ - GetHashPasswordLittleEndian(rPassHash, sPass); -} - -bool SvPasswordHelper::CompareHashPassword(const uno::Sequence<sal_Int8>& rOldPassHash, const String& sNewPass) -{ - bool bResult = false; - - uno::Sequence<sal_Int8> aNewPass(RTL_DIGEST_LENGTH_SHA1); - GetHashPasswordLittleEndian(aNewPass, sNewPass); - if (aNewPass == rOldPassHash) - bResult = true; - else - { - GetHashPasswordBigEndian(aNewPass, sNewPass); - bResult = (aNewPass == rOldPassHash); - } - - return bResult; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/adrparse.cxx b/svl/source/misc/adrparse.cxx deleted file mode 100644 index b6aa9d9e6f..0000000000 --- a/svl/source/misc/adrparse.cxx +++ /dev/null @@ -1,783 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/inetmime.hxx> -#include <svl/adrparse.hxx> - -namespace unnamed_svl_adrparse {} -using namespace unnamed_svl_adrparse; - // unnamed namespaces don't work well yet - -//============================================================================ -namespace unnamed_svl_adrparse { - -enum ElementType { ELEMENT_START, ELEMENT_DELIM, ELEMENT_ITEM, ELEMENT_END }; - -//============================================================================ -struct ParsedAddrSpec -{ - sal_Unicode const * m_pBegin; - sal_Unicode const * m_pEnd; - ElementType m_eLastElem; - bool m_bAtFound; - bool m_bReparse; - - ParsedAddrSpec() { reset(); } - - bool isPoorlyValid() const { return m_eLastElem >= ELEMENT_ITEM; } - - bool isValid() const { return isPoorlyValid() && m_bAtFound; } - - inline void reset(); - - inline void finish(); -}; - -inline void ParsedAddrSpec::reset() -{ - m_pBegin = 0; - m_pEnd = 0; - m_eLastElem = ELEMENT_START; - m_bAtFound = false; - m_bReparse = false; -} - -inline void ParsedAddrSpec::finish() -{ - if (isPoorlyValid()) - m_eLastElem = ELEMENT_END; - else - reset(); -} - -} - -//============================================================================ -class SvAddressParser_Impl -{ - enum State { BEFORE_COLON, BEFORE_LESS, AFTER_LESS, AFTER_GREATER }; - - enum TokenType { TOKEN_QUOTED = 0x80000000, TOKEN_DOMAIN, TOKEN_COMMENT, - TOKEN_ATOM }; - - sal_Unicode const * m_pInputPos; - sal_Unicode const * m_pInputEnd; - sal_uInt32 m_nCurToken; - sal_Unicode const * m_pCurTokenBegin; - sal_Unicode const * m_pCurTokenEnd; - sal_Unicode const * m_pCurTokenContentBegin; - sal_Unicode const * m_pCurTokenContentEnd; - bool m_bCurTokenReparse; - ParsedAddrSpec m_aOuterAddrSpec; - ParsedAddrSpec m_aInnerAddrSpec; - ParsedAddrSpec * m_pAddrSpec; - sal_Unicode const * m_pRealNameBegin; - sal_Unicode const * m_pRealNameEnd; - sal_Unicode const * m_pRealNameContentBegin; - sal_Unicode const * m_pRealNameContentEnd; - bool m_bRealNameReparse; - bool m_bRealNameFinished; - sal_Unicode const * m_pFirstCommentBegin; - sal_Unicode const * m_pFirstCommentEnd; - bool m_bFirstCommentReparse; - State m_eState; - TokenType m_eType; - - inline void resetRealNameAndFirstComment(); - - inline void reset(); - - inline void addTokenToAddrSpec(ElementType eTokenElem); - - inline void addTokenToRealName(); - - bool readToken(); - - static UniString reparse(sal_Unicode const * pBegin, - sal_Unicode const * pEnd, bool bAddrSpec); - - static UniString reparseComment(sal_Unicode const * pBegin, - sal_Unicode const * pEnd); - -public: - SvAddressParser_Impl(SvAddressParser * pParser, UniString const & rInput); -}; - -inline void SvAddressParser_Impl::resetRealNameAndFirstComment() -{ - m_pRealNameBegin = 0; - m_pRealNameEnd = 0; - m_pRealNameContentBegin = 0; - m_pRealNameContentEnd = 0; - m_bRealNameReparse = false; - m_bRealNameFinished = false; - m_pFirstCommentBegin = 0; - m_pFirstCommentEnd = 0; - m_bFirstCommentReparse = false; -} - -inline void SvAddressParser_Impl::reset() -{ - m_aOuterAddrSpec.reset(); - m_aInnerAddrSpec.reset(); - m_pAddrSpec = &m_aOuterAddrSpec; - resetRealNameAndFirstComment(); - m_eState = BEFORE_COLON; - m_eType = TOKEN_ATOM; -} - -inline void SvAddressParser_Impl::addTokenToAddrSpec(ElementType eTokenElem) -{ - if (!m_pAddrSpec->m_pBegin) - m_pAddrSpec->m_pBegin = m_pCurTokenBegin; - else if (m_pAddrSpec->m_pEnd < m_pCurTokenBegin) - m_pAddrSpec->m_bReparse = true; - m_pAddrSpec->m_pEnd = m_pCurTokenEnd; - m_pAddrSpec->m_eLastElem = eTokenElem; -} - -inline void SvAddressParser_Impl::addTokenToRealName() -{ - if (!m_bRealNameFinished && m_eState != AFTER_LESS) - { - if (!m_pRealNameBegin) - m_pRealNameBegin = m_pRealNameContentBegin = m_pCurTokenBegin; - else if (m_pRealNameEnd < m_pCurTokenBegin - 1 - || (m_pRealNameEnd == m_pCurTokenBegin - 1 - && *m_pRealNameEnd != ' ')) - m_bRealNameReparse = true; - m_pRealNameEnd = m_pRealNameContentEnd = m_pCurTokenEnd; - } -} - -//============================================================================ -// -// SvAddressParser_Impl -// -//============================================================================ - -bool SvAddressParser_Impl::readToken() -{ - m_nCurToken = m_eType; - m_bCurTokenReparse = false; - switch (m_eType) - { - case TOKEN_QUOTED: - { - m_pCurTokenBegin = m_pInputPos - 1; - m_pCurTokenContentBegin = m_pInputPos; - bool bEscaped = false; - for (;;) - { - if (m_pInputPos >= m_pInputEnd) - return false; - sal_Unicode cChar = *m_pInputPos++; - if (bEscaped) - { - m_bCurTokenReparse = true; - bEscaped = false; - } - else if (cChar == '"') - { - m_pCurTokenEnd = m_pInputPos; - m_pCurTokenContentEnd = m_pInputPos - 1; - return true; - } - else if (cChar == '\\') - bEscaped = true; - } - } - - case TOKEN_DOMAIN: - { - m_pCurTokenBegin = m_pInputPos - 1; - m_pCurTokenContentBegin = m_pInputPos; - bool bEscaped = false; - for (;;) - { - if (m_pInputPos >= m_pInputEnd) - return false; - sal_Unicode cChar = *m_pInputPos++; - if (bEscaped) - bEscaped = false; - else if (cChar == ']') - { - m_pCurTokenEnd = m_pInputPos; - return true; - } - else if (cChar == '\\') - bEscaped = true; - } - } - - case TOKEN_COMMENT: - { - m_pCurTokenBegin = m_pInputPos - 1; - m_pCurTokenContentBegin = 0; - m_pCurTokenContentEnd = 0; - bool bEscaped = false; - xub_StrLen nLevel = 0; - for (;;) - { - if (m_pInputPos >= m_pInputEnd) - return false; - sal_Unicode cChar = *m_pInputPos++; - if (bEscaped) - { - m_bCurTokenReparse = true; - m_pCurTokenContentEnd = m_pInputPos; - bEscaped = false; - } - else if (cChar == '(') - { - if (!m_pCurTokenContentBegin) - m_pCurTokenContentBegin = m_pInputPos - 1; - m_pCurTokenContentEnd = m_pInputPos; - ++nLevel; - } - else if (cChar == ')') - if (nLevel) - { - m_pCurTokenContentEnd = m_pInputPos; - --nLevel; - } - else - return true; - else if (cChar == '\\') - { - if (!m_pCurTokenContentBegin) - m_pCurTokenContentBegin = m_pInputPos - 1; - bEscaped = true; - } - else if (cChar > ' ' && cChar != 0x7F) // DEL - { - if (!m_pCurTokenContentBegin) - m_pCurTokenContentBegin = m_pInputPos - 1; - m_pCurTokenContentEnd = m_pInputPos; - } - } - } - - default: - { - sal_Unicode cChar; - for (;;) - { - if (m_pInputPos >= m_pInputEnd) - return false; - cChar = *m_pInputPos++; - if (cChar > ' ' && cChar != 0x7F) // DEL - break; - } - m_pCurTokenBegin = m_pInputPos - 1; - if (cChar == '"' || cChar == '(' || cChar == ')' || cChar == ',' - || cChar == '.' || cChar == ':' || cChar == ';' - || cChar == '<' || cChar == '>' || cChar == '@' - || cChar == '[' || cChar == '\\' || cChar == ']') - { - m_nCurToken = cChar; - m_pCurTokenEnd = m_pInputPos; - return true; - } - else - for (;;) - { - if (m_pInputPos >= m_pInputEnd) - { - m_pCurTokenEnd = m_pInputPos; - return true; - } - cChar = *m_pInputPos++; - if (cChar <= ' ' || cChar == '"' || cChar == '(' - || cChar == ')' || cChar == ',' || cChar == '.' - || cChar == ':' || cChar == ';' || cChar == '<' - || cChar == '>' || cChar == '@' || cChar == '[' - || cChar == '\\' || cChar == ']' - || cChar == 0x7F) // DEL - { - m_pCurTokenEnd = --m_pInputPos; - return true; - } - } - } - } -} - -//============================================================================ -// static -UniString SvAddressParser_Impl::reparse(sal_Unicode const * pBegin, - sal_Unicode const * pEnd, - bool bAddrSpec) -{ - UniString aResult; - TokenType eMode = TOKEN_ATOM; - bool bEscaped = false; - bool bEndsWithSpace = false; - xub_StrLen nLevel = 0; - while (pBegin < pEnd) - { - sal_Unicode cChar = *pBegin++; - switch (eMode) - { - case TOKEN_QUOTED: - if (bEscaped) - { - aResult += cChar; - bEscaped = false; - } - else if (cChar == '"') - { - if (bAddrSpec) - aResult += cChar; - eMode = TOKEN_ATOM; - } - else if (cChar == '\\') - { - if (bAddrSpec) - aResult += cChar; - bEscaped = true; - } - else - aResult += cChar; - break; - - case TOKEN_DOMAIN: - if (bEscaped) - { - aResult += cChar; - bEscaped = false; - } - else if (cChar == ']') - { - aResult += cChar; - eMode = TOKEN_ATOM; - } - else if (cChar == '\\') - { - if (bAddrSpec) - aResult += cChar; - bEscaped = true; - } - else - aResult += cChar; - break; - - case TOKEN_COMMENT: - if (bEscaped) - bEscaped = false; - else if (cChar == '(') - ++nLevel; - else if (cChar == ')') - if (nLevel) - --nLevel; - else - eMode = TOKEN_ATOM; - else if (cChar == '\\') - bEscaped = true; - break; - - case TOKEN_ATOM: - if (cChar <= ' ' || cChar == 0x7F) // DEL - { - if (!bAddrSpec && !bEndsWithSpace) - { - aResult += ' '; - bEndsWithSpace = true; - } - } - else if (cChar == '(') - { - if (!bAddrSpec && !bEndsWithSpace) - { - aResult += ' '; - bEndsWithSpace = true; - } - eMode = TOKEN_COMMENT; - } - else - { - bEndsWithSpace = false; - if (cChar == '"') - { - if (bAddrSpec) - aResult += cChar; - eMode = TOKEN_QUOTED; - } - else if (cChar == '[') - { - aResult += cChar; - eMode = TOKEN_QUOTED; - } - else - aResult += cChar; - } - break; - } - } - return aResult; -} - -//============================================================================ -// static -UniString SvAddressParser_Impl::reparseComment(sal_Unicode const * pBegin, - sal_Unicode const * pEnd) -{ - UniString aResult; - while (pBegin < pEnd) - { - sal_Unicode cChar = *pBegin++; - if (cChar == '\\') - cChar = *pBegin++; - aResult += cChar; - } - return aResult; -} - -//============================================================================ -SvAddressParser_Impl::SvAddressParser_Impl(SvAddressParser * pParser, - UniString const & rInput) -{ - m_pInputPos = rInput.GetBuffer(); - m_pInputEnd = m_pInputPos + rInput.Len(); - - reset(); - bool bDone = false; - for (;;) - { - if (!readToken()) - { - m_bRealNameFinished = true; - if (m_eState == AFTER_LESS) - m_nCurToken = '>'; - else - { - m_nCurToken = ','; - bDone = true; - } - } - switch (m_nCurToken) - { - case TOKEN_QUOTED: - if (m_pAddrSpec->m_eLastElem != ELEMENT_END) - { - if (m_pAddrSpec->m_bAtFound - || m_pAddrSpec->m_eLastElem <= ELEMENT_DELIM) - m_pAddrSpec->reset(); - addTokenToAddrSpec(ELEMENT_ITEM); - } - if (!m_bRealNameFinished && m_eState != AFTER_LESS) - { - if (m_bCurTokenReparse) - { - if (!m_pRealNameBegin) - m_pRealNameBegin = m_pCurTokenBegin; - m_pRealNameEnd = m_pCurTokenEnd; - m_bRealNameReparse = true; - } - else if (m_bRealNameReparse) - m_pRealNameEnd = m_pCurTokenEnd; - else if (!m_pRealNameBegin) - { - m_pRealNameBegin = m_pCurTokenBegin; - m_pRealNameContentBegin = m_pCurTokenContentBegin; - m_pRealNameEnd = m_pRealNameContentEnd - = m_pCurTokenContentEnd; - } - else - { - m_pRealNameEnd = m_pCurTokenEnd; - m_bRealNameReparse = true; - } - } - m_eType = TOKEN_ATOM; - break; - - case TOKEN_DOMAIN: - if (m_pAddrSpec->m_eLastElem != ELEMENT_END) - { - if (m_pAddrSpec->m_bAtFound - && m_pAddrSpec->m_eLastElem == ELEMENT_DELIM) - addTokenToAddrSpec(ELEMENT_ITEM); - else - m_pAddrSpec->reset(); - } - addTokenToRealName(); - m_eType = TOKEN_ATOM; - break; - - case TOKEN_COMMENT: - if (!m_bRealNameFinished && m_eState != AFTER_LESS - && !m_pFirstCommentBegin && m_pCurTokenContentBegin) - { - m_pFirstCommentBegin = m_pCurTokenContentBegin; - m_pFirstCommentEnd = m_pCurTokenContentEnd; - m_bFirstCommentReparse = m_bCurTokenReparse; - } - m_eType = TOKEN_ATOM; - break; - - case TOKEN_ATOM: - if (m_pAddrSpec->m_eLastElem != ELEMENT_END) - { - if (m_pAddrSpec->m_eLastElem != ELEMENT_DELIM) - m_pAddrSpec->reset(); - addTokenToAddrSpec(ELEMENT_ITEM); - } - addTokenToRealName(); - break; - - case '(': - m_eType = TOKEN_COMMENT; - break; - - case ')': - case '\\': - case ']': - m_pAddrSpec->finish(); - addTokenToRealName(); - break; - - case '<': - switch (m_eState) - { - case BEFORE_COLON: - case BEFORE_LESS: - m_aOuterAddrSpec.finish(); - if (m_pRealNameBegin) - m_bRealNameFinished = true; - m_pAddrSpec = &m_aInnerAddrSpec; - m_eState = AFTER_LESS; - break; - - case AFTER_LESS: - m_aInnerAddrSpec.finish(); - break; - - case AFTER_GREATER: - m_aOuterAddrSpec.finish(); - addTokenToRealName(); - break; - } - break; - - case '>': - if (m_eState == AFTER_LESS) - { - m_aInnerAddrSpec.finish(); - if (m_aInnerAddrSpec.isValid()) - m_aOuterAddrSpec.m_eLastElem = ELEMENT_END; - m_pAddrSpec = &m_aOuterAddrSpec; - m_eState = AFTER_GREATER; - } - else - { - m_aOuterAddrSpec.finish(); - addTokenToRealName(); - } - break; - - case '@': - if (m_pAddrSpec->m_eLastElem != ELEMENT_END) - { - if (!m_pAddrSpec->m_bAtFound - && m_pAddrSpec->m_eLastElem == ELEMENT_ITEM) - { - addTokenToAddrSpec(ELEMENT_DELIM); - m_pAddrSpec->m_bAtFound = true; - } - else - m_pAddrSpec->reset(); - } - addTokenToRealName(); - break; - - case ',': - case ';': - if (m_eState == AFTER_LESS) - if (m_nCurToken == ',') - { - if (m_aInnerAddrSpec.m_eLastElem - != ELEMENT_END) - m_aInnerAddrSpec.reset(); - } - else - m_aInnerAddrSpec.finish(); - else - { - m_pAddrSpec = m_aInnerAddrSpec.isValid() - || (!m_aOuterAddrSpec.isValid() - && m_aInnerAddrSpec.isPoorlyValid()) ? - &m_aInnerAddrSpec : - m_aOuterAddrSpec.isPoorlyValid() ? - &m_aOuterAddrSpec : 0; - if (m_pAddrSpec) - { - UniString aTheAddrSpec; - if (m_pAddrSpec->m_bReparse) - aTheAddrSpec = reparse(m_pAddrSpec->m_pBegin, - m_pAddrSpec->m_pEnd, true); - else - { - xub_StrLen nLen = - sal::static_int_cast< xub_StrLen >( - m_pAddrSpec->m_pEnd - - m_pAddrSpec->m_pBegin); - if (nLen == rInput.Len()) - aTheAddrSpec = rInput; - else - aTheAddrSpec - = rInput.Copy( - sal::static_int_cast< xub_StrLen >( - m_pAddrSpec->m_pBegin - - rInput.GetBuffer()), - nLen); - } - UniString aTheRealName; - if (!m_pRealNameBegin - || (m_pAddrSpec == &m_aOuterAddrSpec - && m_pRealNameBegin - == m_aOuterAddrSpec.m_pBegin - && m_pRealNameEnd == m_aOuterAddrSpec.m_pEnd - && m_pFirstCommentBegin)) - if (!m_pFirstCommentBegin) - aTheRealName = aTheAddrSpec; - else if (m_bFirstCommentReparse) - aTheRealName - = reparseComment(m_pFirstCommentBegin, - m_pFirstCommentEnd); - else - aTheRealName - = rInput.Copy( - sal::static_int_cast< xub_StrLen >( - m_pFirstCommentBegin - - rInput.GetBuffer()), - sal::static_int_cast< xub_StrLen >( - m_pFirstCommentEnd - - m_pFirstCommentBegin)); - else if (m_bRealNameReparse) - aTheRealName = reparse(m_pRealNameBegin, - m_pRealNameEnd, false); - else - { - xub_StrLen nLen = - sal::static_int_cast< xub_StrLen >( - m_pRealNameContentEnd - - m_pRealNameContentBegin); - if (nLen == rInput.Len()) - aTheRealName = rInput; - else - aTheRealName - = rInput.Copy( - sal::static_int_cast< xub_StrLen >( - m_pRealNameContentBegin - - rInput.GetBuffer()), - nLen); - } - if (pParser->m_bHasFirst) - pParser->m_aRest.push_back(new SvAddressEntry_Impl( - aTheAddrSpec, - aTheRealName) - ); - else - { - pParser->m_bHasFirst = true; - pParser->m_aFirst.m_aAddrSpec = aTheAddrSpec; - pParser->m_aFirst.m_aRealName = aTheRealName; - } - } - if (bDone) - return; - reset(); - } - break; - - case ':': - switch (m_eState) - { - case BEFORE_COLON: - m_aOuterAddrSpec.reset(); - resetRealNameAndFirstComment(); - m_eState = BEFORE_LESS; - break; - - case BEFORE_LESS: - case AFTER_GREATER: - m_aOuterAddrSpec.finish(); - addTokenToRealName(); - break; - - case AFTER_LESS: - m_aInnerAddrSpec.reset(); - break; - } - break; - - case '"': - m_eType = TOKEN_QUOTED; - break; - - case '.': - if (m_pAddrSpec->m_eLastElem != ELEMENT_END) - { - if (m_pAddrSpec->m_eLastElem != ELEMENT_DELIM) - addTokenToAddrSpec(ELEMENT_DELIM); - else - m_pAddrSpec->reset(); - } - addTokenToRealName(); - break; - - case '[': - m_eType = TOKEN_DOMAIN; - break; - } - } -} - -//============================================================================ -// -// SvAddressParser -// -//============================================================================ - -SvAddressParser::SvAddressParser(UniString const & rInput): m_bHasFirst(false) -{ - SvAddressParser_Impl aDoParse(this, rInput); -} - -//============================================================================ -SvAddressParser::~SvAddressParser() -{ - for ( size_t i = m_aRest.size(); i > 0; ) - delete m_aRest[ --i ]; - m_aRest.clear(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/documentlockfile.cxx b/svl/source/misc/documentlockfile.cxx deleted file mode 100644 index d1c289a9c7..0000000000 --- a/svl/source/misc/documentlockfile.cxx +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <stdio.h> - -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/ucb/XCommandEnvironment.hpp> -#include <com/sun/star/ucb/InsertCommandArgument.hpp> -#include <com/sun/star/ucb/NameClashException.hpp> -#include <com/sun/star/io/WrongFormatException.hpp> - -#include <osl/time.h> -#include <osl/security.hxx> -#include <osl/socket.hxx> - -#include <rtl/string.hxx> -#include <rtl/ustring.hxx> -#include <rtl/strbuf.hxx> -#include <rtl/ustrbuf.hxx> - -#include <comphelper/processfactory.hxx> - -#include <tools/urlobj.hxx> -#include <unotools/bootstrap.hxx> - -#include <ucbhelper/content.hxx> - -#include <unotools/useroptions.hxx> - -#include <svl/documentlockfile.hxx> - -using namespace ::com::sun::star; - -namespace svt { - -sal_Bool DocumentLockFile::m_bAllowInteraction = sal_True; - -// ---------------------------------------------------------------------- -DocumentLockFile::DocumentLockFile( const ::rtl::OUString& aOrigURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory ) -: LockFileCommon( aOrigURL, xFactory, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".~lock." ) ) ) -{ -} - -// ---------------------------------------------------------------------- -DocumentLockFile::~DocumentLockFile() -{ -} - -// ---------------------------------------------------------------------- -void DocumentLockFile::WriteEntryToStream( uno::Sequence< ::rtl::OUString > aEntry, uno::Reference< io::XOutputStream > xOutput ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - ::rtl::OUStringBuffer aBuffer; - - for ( sal_Int32 nEntryInd = 0; nEntryInd < aEntry.getLength(); nEntryInd++ ) - { - aBuffer.append( EscapeCharacters( aEntry[nEntryInd] ) ); - if ( nEntryInd < aEntry.getLength() - 1 ) - aBuffer.append( (sal_Unicode)',' ); - else - aBuffer.append( (sal_Unicode)';' ); - } - - ::rtl::OString aStringData( ::rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) ); - uno::Sequence< sal_Int8 > aData( (sal_Int8*)aStringData.getStr(), aStringData.getLength() ); - xOutput->writeBytes( aData ); -} - -// ---------------------------------------------------------------------- -sal_Bool DocumentLockFile::CreateOwnLockFile() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - try - { - uno::Reference< io::XStream > xTempFile( - m_xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile")) ), - uno::UNO_QUERY_THROW ); - uno::Reference< io::XSeekable > xSeekable( xTempFile, uno::UNO_QUERY_THROW ); - - uno::Reference< io::XInputStream > xInput = xTempFile->getInputStream(); - uno::Reference< io::XOutputStream > xOutput = xTempFile->getOutputStream(); - - if ( !xInput.is() || !xOutput.is() ) - throw uno::RuntimeException(); - - uno::Sequence< ::rtl::OUString > aNewEntry = GenerateOwnEntry(); - WriteEntryToStream( aNewEntry, xOutput ); - xOutput->closeOutput(); - - xSeekable->seek( 0 ); - - uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aTargetContent( m_aURL, xEnv ); - - ucb::InsertCommandArgument aInsertArg; - aInsertArg.Data = xInput; - aInsertArg.ReplaceExisting = sal_False; - uno::Any aCmdArg; - aCmdArg <<= aInsertArg; - aTargetContent.executeCommand( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "insert" ) ), aCmdArg ); - - // try to let the file be hidden if possible - try { - aTargetContent.setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ), uno::makeAny( sal_True ) ); - } catch( uno::Exception& ) {} - } - catch( ucb::NameClashException& ) - { - return sal_False; - } - - return sal_True; -} - -// ---------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > DocumentLockFile::GetLockData() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - uno::Reference< io::XInputStream > xInput = OpenStream(); - if ( !xInput.is() ) - throw uno::RuntimeException(); - - const sal_Int32 nBufLen = 32000; - uno::Sequence< sal_Int8 > aBuffer( nBufLen ); - - sal_Int32 nRead = 0; - - nRead = xInput->readBytes( aBuffer, nBufLen ); - xInput->closeInput(); - - if ( nRead == nBufLen ) - throw io::WrongFormatException(); - - sal_Int32 nCurPos = 0; - return ParseEntry( aBuffer, nCurPos ); -} - -// ---------------------------------------------------------------------- -uno::Reference< io::XInputStream > DocumentLockFile::OpenStream() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aSourceContent( m_aURL, xEnv ); - - // the file can be opened readonly, no locking will be done - return aSourceContent.openStream(); -} - -// ---------------------------------------------------------------------- -sal_Bool DocumentLockFile::OverwriteOwnLockFile() -{ - // allows to overwrite the lock file with the current data - try - { - uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aTargetContent( m_aURL, xEnv ); - - uno::Sequence< ::rtl::OUString > aNewEntry = GenerateOwnEntry(); - - uno::Reference< io::XStream > xStream = aTargetContent.openWriteableStreamNoLock(); - uno::Reference< io::XOutputStream > xOutput = xStream->getOutputStream(); - uno::Reference< io::XTruncate > xTruncate( xOutput, uno::UNO_QUERY_THROW ); - - xTruncate->truncate(); - WriteEntryToStream( aNewEntry, xOutput ); - xOutput->closeOutput(); - } - catch( uno::Exception& ) - { - return sal_False; - } - - return sal_True; -} - -// ---------------------------------------------------------------------- -void DocumentLockFile::RemoveFile() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - // TODO/LATER: the removing is not atomar, is it possible in general to make it atomar? - uno::Sequence< ::rtl::OUString > aNewEntry = GenerateOwnEntry(); - uno::Sequence< ::rtl::OUString > aFileData = GetLockData(); - - if ( aFileData.getLength() < LOCKFILE_ENTRYSIZE ) - throw io::WrongFormatException(); - - if ( !aFileData[LOCKFILE_SYSUSERNAME_ID].equals( aNewEntry[LOCKFILE_SYSUSERNAME_ID] ) - || !aFileData[LOCKFILE_LOCALHOST_ID].equals( aNewEntry[LOCKFILE_LOCALHOST_ID] ) - || !aFileData[LOCKFILE_USERURL_ID].equals( aNewEntry[LOCKFILE_USERURL_ID] ) ) - throw io::IOException(); // not the owner, access denied - - uno::Reference < ::com::sun::star::ucb::XCommandEnvironment > xEnv; - ::ucbhelper::Content aCnt(m_aURL, xEnv); - aCnt.executeCommand(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("delete")), - uno::makeAny(sal_Bool(sal_True))); -} - -} // namespace svt - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/filenotation.cxx b/svl/source/misc/filenotation.cxx deleted file mode 100644 index 552ddf5c4c..0000000000 --- a/svl/source/misc/filenotation.cxx +++ /dev/null @@ -1,147 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/filenotation.hxx> -#include <osl/file.h> -#include <osl/diagnose.h> -#include <tools/urlobj.hxx> - -//......................................................................... -namespace svt -{ -//......................................................................... - - //===================================================================== - //= OFileNotation - //===================================================================== - //--------------------------------------------------------------------- - OFileNotation::OFileNotation( const ::rtl::OUString& _rUrlOrPath ) - { - construct( _rUrlOrPath ); - } - - //--------------------------------------------------------------------- - OFileNotation::OFileNotation( const ::rtl::OUString& _rUrlOrPath, NOTATION _eInputNotation ) - { - if ( _eInputNotation == N_URL ) - { - INetURLObject aParser( _rUrlOrPath ); - if ( aParser.GetProtocol() == INET_PROT_FILE ) - implInitWithURLNotation( _rUrlOrPath ); - else - m_sSystem = m_sFileURL = _rUrlOrPath; - } - else - implInitWithSystemNotation( _rUrlOrPath ); - } - - //--------------------------------------------------------------------- - bool OFileNotation::implInitWithSystemNotation( const ::rtl::OUString& _rSystemPath ) - { - bool bSuccess = false; - - m_sSystem = _rSystemPath; - if ( ( osl_File_E_None != osl_getFileURLFromSystemPath( m_sSystem.pData, &m_sFileURL.pData ) ) - && ( 0 == m_sFileURL.getLength() ) - ) - { - if ( _rSystemPath.getLength() ) - { - INetURLObject aSmartParser; - aSmartParser.SetSmartProtocol( INET_PROT_FILE ); - if ( aSmartParser.SetSmartURL( _rSystemPath ) ) - { - m_sFileURL = aSmartParser.GetMainURL( INetURLObject::NO_DECODE ); - osl_getSystemPathFromFileURL( m_sFileURL.pData, &m_sSystem.pData ); - bSuccess = true; - } - } - } - else - bSuccess = true; - return bSuccess; - } - - //--------------------------------------------------------------------- - bool OFileNotation::implInitWithURLNotation( const ::rtl::OUString& _rURL ) - { - m_sFileURL = _rURL; - osl_getSystemPathFromFileURL( _rURL.pData, &m_sSystem.pData ); - return true; - } - - //--------------------------------------------------------------------- - void OFileNotation::construct( const ::rtl::OUString& _rUrlOrPath ) - { - bool bSuccess = false; - // URL notation? - INetURLObject aParser( _rUrlOrPath ); - switch ( aParser.GetProtocol() ) - { - case INET_PROT_FILE: - // file URL - bSuccess = implInitWithURLNotation( _rUrlOrPath ); - break; - - case INET_PROT_NOT_VALID: - // assume system notation - bSuccess = implInitWithSystemNotation( _rUrlOrPath ); - break; - - default: - // it's a known scheme, but no file-URL -> assume that bothe the URL representation and the - // system representation are the URL itself - m_sSystem = m_sFileURL = _rUrlOrPath; - bSuccess = true; - break; - } - - OSL_ENSURE( bSuccess, "OFileNotation::OFileNotation: could not detect the format!" ); - (void)bSuccess; - } - - //--------------------------------------------------------------------- - ::rtl::OUString OFileNotation::get(NOTATION _eOutputNotation) - { - switch (_eOutputNotation) - { - case N_SYSTEM: return m_sSystem; - case N_URL: return m_sFileURL; - } - - OSL_FAIL("OFileNotation::get: inavlid enum value!"); - return ::rtl::OUString(); - } - -//......................................................................... -} // namespace svt -//......................................................................... - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/folderrestriction.cxx b/svl/source/misc/folderrestriction.cxx deleted file mode 100644 index 88f3b6d766..0000000000 --- a/svl/source/misc/folderrestriction.cxx +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/folderrestriction.hxx> -#include "osl/process.h" -#include "tools/urlobj.hxx" -#include "unotools/localfilehelper.hxx" - -//----------------------------------------------------------------------------- - -static void convertStringListToUrls ( - const String& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash ) -{ - const sal_Unicode s_cSeparator = -#if defined(WNT) - ';' -#else - ':' -#endif - ; - xub_StrLen nTokens = _rColonSeparatedList.GetTokenCount( s_cSeparator ); - _rTokens.resize( 0 ); _rTokens.reserve( nTokens ); - for ( xub_StrLen i=0; i<nTokens; ++i ) - { - // the current token in the list - String sCurrentToken = _rColonSeparatedList.GetToken( i, s_cSeparator ); - if ( !sCurrentToken.Len() ) - continue; - - INetURLObject aCurrentURL; - - String sURL; - if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) ) - aCurrentURL = INetURLObject( sURL ); - else - { - // smart URL parsing, assuming FILE protocol - aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE ); - } - - if ( _bFinalSlash ) - aCurrentURL.setFinalSlash( ); - else - aCurrentURL.removeFinalSlash( ); - _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) ); - } -} - -/** retrieves the value of an environment variable - @return <TRUE/> if and only if the retrieved string value is not empty -*/ -static bool getEnvironmentValue( const sal_Char* _pAsciiEnvName, ::rtl::OUString& _rValue ) -{ - _rValue = ::rtl::OUString(); - ::rtl::OUString sEnvName = ::rtl::OUString::createFromAscii( _pAsciiEnvName ); - osl_getEnvironment( sEnvName.pData, &_rValue.pData ); - return _rValue.getLength() != 0; -} - -//----------------------------------------------------------------------------- - -namespace svt -{ - - void getUnrestrictedFolders( ::std::vector< String >& _rFolders ) - { - _rFolders.resize( 0 ); - ::rtl::OUString sRestrictedPathList; - if ( getEnvironmentValue( "RestrictedPath", sRestrictedPathList ) ) - { - // append a final slash. This ensures that when we later on check - // for unrestricted paths, we don't allow paths like "/home/user35" just because - // "/home/user3" is allowed - with the final slash, we make it "/home/user3/". - convertStringListToUrls( sRestrictedPathList, _rFolders, true ); - } - } - -} // namespace svt - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/fstathelper.cxx b/svl/source/misc/fstathelper.cxx deleted file mode 100644 index fcc77cf863..0000000000 --- a/svl/source/misc/fstathelper.cxx +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/date.hxx> -#include <tools/time.hxx> -#include <tools/string.hxx> -#include <ucbhelper/content.hxx> -#include <com/sun/star/util/DateTime.hpp> -#include <svl/fstathelper.hxx> - -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::ucb; -using namespace ::rtl; - -sal_Bool FStatHelper::GetModifiedDateTimeOfFile( const UniString& rURL, - Date* pDate, Time* pTime ) -{ - sal_Bool bRet = sal_False; - try - { - ::ucbhelper::Content aTestContent( rURL, - uno::Reference< XCommandEnvironment > ()); - uno::Any aAny = aTestContent.getPropertyValue( - OUString(RTL_CONSTASCII_USTRINGPARAM("DateModified")) ); - if( aAny.hasValue() ) - { - bRet = sal_True; - const util::DateTime* pDT = (util::DateTime*)aAny.getValue(); - if( pDate ) - *pDate = Date( pDT->Day, pDT->Month, pDT->Year ); - if( pTime ) - *pTime = Time( pDT->Hours, pDT->Minutes, - pDT->Seconds, pDT->HundredthSeconds ); - } - } - catch(...) - { - } - - return bRet; -} - -sal_Bool FStatHelper::IsDocument( const UniString& rURL ) -{ - sal_Bool bExist = sal_False; - try - { - ::ucbhelper::Content aTestContent( rURL, - uno::Reference< XCommandEnvironment > ()); - bExist = aTestContent.isDocument(); - } - catch(...) - { - } - return bExist; -} - -sal_Bool FStatHelper::IsFolder( const UniString& rURL ) -{ - sal_Bool bExist = sal_False; - try - { - ::ucbhelper::Content aTestContent( rURL, - uno::Reference< XCommandEnvironment > ()); - bExist = aTestContent.isFolder(); - } - catch(...) - { - } - return bExist; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/inethist.cxx b/svl/source/misc/inethist.cxx deleted file mode 100644 index 37d75baf94..0000000000 --- a/svl/source/misc/inethist.cxx +++ /dev/null @@ -1,505 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/inethist.hxx> - -#ifndef INCLUDED_ALGORITHM -#include <algorithm> -#define INCLUDED_ALGORITHM -#endif -#include "rtl/instance.hxx" -#include "rtl/crc.h" -#include "rtl/memory.h" -#include <tools/solar.h> -#include <tools/debug.hxx> -#include <tools/string.hxx> -#include <tools/urlobj.hxx> - -/*======================================================================== - * - * INetURLHistory internals. - * - *======================================================================*/ -#define INETHIST_DEF_FTP_PORT 21 -#define INETHIST_DEF_HTTP_PORT 80 -#define INETHIST_DEF_HTTPS_PORT 443 - -#define INETHIST_SIZE_LIMIT 1024 -#define INETHIST_MAGIC_HEAD 0x484D4849UL - -/* - * INetURLHistoryHint implementation. - */ -IMPL_PTRHINT (INetURLHistoryHint, const INetURLObject); - -/*======================================================================== - * - * INetURLHistory_Impl interface. - * - *======================================================================*/ -class INetURLHistory_Impl -{ - /** head_entry. - */ - struct head_entry - { - /** Representation. - */ - sal_uInt32 m_nMagic; - sal_uInt16 m_nNext; - sal_uInt16 m_nMBZ; - - /** Initialization. - */ - void initialize (void) - { - m_nMagic = INETHIST_MAGIC_HEAD; - m_nNext = 0; - m_nMBZ = 0; - } - }; - - /** hash_entry. - */ - struct hash_entry - { - /** Representation. - */ - sal_uInt32 m_nHash; - sal_uInt16 m_nLru; - sal_uInt16 m_nMBZ; - - /** Initialization. - */ - void initialize (sal_uInt16 nLru, sal_uInt32 nHash = 0) - { - m_nHash = nHash; - m_nLru = nLru; - m_nMBZ = 0; - } - - /** Comparison. - */ - sal_Bool operator== (const hash_entry &rOther) const - { - return (m_nHash == rOther.m_nHash); - } - sal_Bool operator< (const hash_entry &rOther) const - { - return (m_nHash < rOther.m_nHash); - } - - sal_Bool operator== (sal_uInt32 nHash) const - { - return (m_nHash == nHash); - } - sal_Bool operator< (sal_uInt32 nHash) const - { - return (m_nHash < nHash); - } - }; - - /** lru_entry. - */ - struct lru_entry - { - /** Representation. - */ - sal_uInt32 m_nHash; - sal_uInt16 m_nNext; - sal_uInt16 m_nPrev; - - /** Initialization. - */ - void initialize (sal_uInt16 nThis, sal_uInt32 nHash = 0) - { - m_nHash = nHash; - m_nNext = nThis; - m_nPrev = nThis; - } - }; - - /** Representation. - */ - head_entry m_aHead; - hash_entry m_pHash[INETHIST_SIZE_LIMIT]; - lru_entry m_pList[INETHIST_SIZE_LIMIT]; - - /** Initialization. - */ - void initialize (void); - - /** capacity. - */ - sal_uInt16 capacity (void) const - { - return (sal_uInt16)(INETHIST_SIZE_LIMIT); - } - - /** crc32. - */ - sal_uInt32 crc32 (UniString const & rData) const - { - return rtl_crc32 (0, rData.GetBuffer(), rData.Len() * sizeof(sal_Unicode)); - } - - /** find. - */ - sal_uInt16 find (sal_uInt32 nHash) const; - - /** move. - */ - void move (sal_uInt16 nSI, sal_uInt16 nDI); - - /** backlink. - */ - void backlink (sal_uInt16 nThis, sal_uInt16 nTail) - { - register lru_entry &rThis = m_pList[nThis]; - register lru_entry &rTail = m_pList[nTail]; - - rTail.m_nNext = nThis; - rTail.m_nPrev = rThis.m_nPrev; - rThis.m_nPrev = nTail; - m_pList[rTail.m_nPrev].m_nNext = nTail; - } - - /** unlink. - */ - void unlink (sal_uInt16 nThis) - { - register lru_entry &rThis = m_pList[nThis]; - - m_pList[rThis.m_nPrev].m_nNext = rThis.m_nNext; - m_pList[rThis.m_nNext].m_nPrev = rThis.m_nPrev; - rThis.m_nNext = nThis; - rThis.m_nPrev = nThis; - } - - /** Not implemented. - */ - INetURLHistory_Impl (const INetURLHistory_Impl&); - INetURLHistory_Impl& operator= (const INetURLHistory_Impl&); - -public: - INetURLHistory_Impl (void); - ~INetURLHistory_Impl (void); - - /** putUrl/queryUrl. - */ - void putUrl (const String &rUrl); - sal_Bool queryUrl (const String &rUrl); -}; - -/*======================================================================== - * - * INetURLHistory_Impl implementation. - * - *======================================================================*/ -/* - * INetURLHistory_Impl. - */ -INetURLHistory_Impl::INetURLHistory_Impl (void) -{ - initialize(); -} - -/* - * ~INetURLHistory_Impl. - */ -INetURLHistory_Impl::~INetURLHistory_Impl (void) -{ -} - -/* - * initialize. - */ -void INetURLHistory_Impl::initialize (void) -{ - m_aHead.initialize(); - - sal_uInt16 i, n = capacity(); - for (i = 0; i < n; i++) - m_pHash[i].initialize(i); - for (i = 0; i < n; i++) - m_pList[i].initialize(i); - for (i = 1; i < n; i++) - backlink (m_aHead.m_nNext, i); -} - -/* - * find. - */ -sal_uInt16 INetURLHistory_Impl::find (sal_uInt32 nHash) const -{ - sal_uInt16 l = 0; - sal_uInt16 r = capacity() - 1; - sal_uInt16 c = capacity(); - - while ((l < r) && (r < c)) - { - sal_uInt16 m = (l + r) / 2; - if (m_pHash[m] == nHash) - return m; - - if (m_pHash[m] < nHash) - l = m + 1; - else - r = m - 1; - } - return l; -} - -/* - * move. - */ -void INetURLHistory_Impl::move (sal_uInt16 nSI, sal_uInt16 nDI) -{ - hash_entry e = m_pHash[nSI]; - if (nSI < nDI) - { - // shift left. - rtl_moveMemory ( - &m_pHash[nSI ], - &m_pHash[nSI + 1], - (nDI - nSI) * sizeof(hash_entry)); - } - if (nSI > nDI) - { - // shift right. - rtl_moveMemory ( - &m_pHash[nDI + 1], - &m_pHash[nDI ], - (nSI - nDI) * sizeof(hash_entry)); - } - m_pHash[nDI] = e; -} - -/* - * putUrl. - */ -void INetURLHistory_Impl::putUrl (const String &rUrl) -{ - sal_uInt32 h = crc32 (rUrl); - sal_uInt16 k = find (h); - if ((k < capacity()) && (m_pHash[k] == h)) - { - // Cache hit. - sal_uInt16 nMRU = m_pHash[k].m_nLru; - if (nMRU != m_aHead.m_nNext) - { - // Update LRU chain. - unlink (nMRU); - backlink (m_aHead.m_nNext, nMRU); - - // Rotate LRU chain. - m_aHead.m_nNext = m_pList[m_aHead.m_nNext].m_nPrev; - } - } - else - { - // Cache miss. Obtain least recently used. - sal_uInt16 nLRU = m_pList[m_aHead.m_nNext].m_nPrev; - - sal_uInt16 nSI = find (m_pList[nLRU].m_nHash); - if (!(nLRU == m_pHash[nSI].m_nLru)) - { - // Update LRU chain. - nLRU = m_pHash[nSI].m_nLru; - unlink (nLRU); - backlink (m_aHead.m_nNext, nLRU); - } - - // Rotate LRU chain. - m_aHead.m_nNext = m_pList[m_aHead.m_nNext].m_nPrev; - - // Check source and destination. - sal_uInt16 nDI = std::min (k, sal_uInt16(capacity() - 1)); - if (nSI < nDI) - { - if (!(m_pHash[nDI] < h)) - nDI -= 1; - } - if (nDI < nSI) - { - if (m_pHash[nDI] < h) - nDI += 1; - } - - // Assign data. - m_pList[m_aHead.m_nNext].m_nHash = m_pHash[nSI].m_nHash = h; - move (nSI, nDI); - } -} - -/* - * queryUrl. - */ -sal_Bool INetURLHistory_Impl::queryUrl (const String &rUrl) -{ - sal_uInt32 h = crc32 (rUrl); - sal_uInt16 k = find (h); - if ((k < capacity()) && (m_pHash[k] == h)) - { - // Cache hit. - return sal_True; - } - else - { - // Cache miss. - return sal_False; - } -} - -/*======================================================================== - * - * INetURLHistory::StaticInstance implementation. - * - *======================================================================*/ -INetURLHistory * INetURLHistory::StaticInstance::operator ()() -{ - static INetURLHistory g_aInstance; - return &g_aInstance; -} - -/*======================================================================== - * - * INetURLHistory implementation. - * - *======================================================================*/ -/* - * INetURLHistory. - */ -INetURLHistory::INetURLHistory() : m_pImpl (new INetURLHistory_Impl()) -{ -} - -/* - * ~INetURLHistory. - */ -INetURLHistory::~INetURLHistory() -{ - DELETEZ (m_pImpl); -} - -/* - * GetOrCreate. - */ -INetURLHistory* INetURLHistory::GetOrCreate() -{ - return rtl_Instance< - INetURLHistory, StaticInstance, - osl::MutexGuard, osl::GetGlobalMutex >::create ( - StaticInstance(), osl::GetGlobalMutex()); -} - -/* - * NormalizeUrl_Impl. - */ -void INetURLHistory::NormalizeUrl_Impl (INetURLObject &rUrl) -{ - switch (rUrl.GetProtocol()) - { - case INET_PROT_FILE: - if (!rUrl.IsCaseSensitive()) - { - String aPath (rUrl.GetURLPath(INetURLObject::NO_DECODE)); - aPath.ToLowerAscii(); - rUrl.SetURLPath (aPath, INetURLObject::NOT_CANONIC); - } - break; - - case INET_PROT_FTP: - if (!rUrl.HasPort()) - rUrl.SetPort (INETHIST_DEF_FTP_PORT); - break; - - case INET_PROT_HTTP: - if (!rUrl.HasPort()) - rUrl.SetPort (INETHIST_DEF_HTTP_PORT); - if (!rUrl.HasURLPath()) - rUrl.SetURLPath ("/"); - break; - - case INET_PROT_HTTPS: - if (!rUrl.HasPort()) - rUrl.SetPort (INETHIST_DEF_HTTPS_PORT); - if (!rUrl.HasURLPath()) - rUrl.SetURLPath ("/"); - break; - - default: - break; - } -} - -/* - * PutUrl_Impl. - */ -void INetURLHistory::PutUrl_Impl (const INetURLObject &rUrl) -{ - DBG_ASSERT (m_pImpl, "PutUrl_Impl(): no Implementation"); - if (m_pImpl) - { - INetURLObject aHistUrl (rUrl); - NormalizeUrl_Impl (aHistUrl); - - m_pImpl->putUrl (aHistUrl.GetMainURL(INetURLObject::NO_DECODE)); - Broadcast (INetURLHistoryHint (&rUrl)); - - if (aHistUrl.HasMark()) - { - aHistUrl.SetURL (aHistUrl.GetURLNoMark(INetURLObject::NO_DECODE), - INetURLObject::NOT_CANONIC); - - m_pImpl->putUrl (aHistUrl.GetMainURL(INetURLObject::NO_DECODE)); - Broadcast (INetURLHistoryHint (&aHistUrl)); - } - } -} - -/* - * QueryUrl_Impl. - */ -sal_Bool INetURLHistory::QueryUrl_Impl (const INetURLObject &rUrl) -{ - DBG_ASSERT (m_pImpl, "QueryUrl_Impl(): no Implementation"); - if (m_pImpl) - { - INetURLObject aHistUrl (rUrl); - NormalizeUrl_Impl (aHistUrl); - - return m_pImpl->queryUrl (aHistUrl.GetMainURL(INetURLObject::NO_DECODE)); - } - return sal_False; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/inettype.cxx b/svl/source/misc/inettype.cxx deleted file mode 100644 index c183f8c26b..0000000000 --- a/svl/source/misc/inettype.cxx +++ /dev/null @@ -1,1131 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/table.hxx> -#include <tools/wldcrd.hxx> -#include <svl/inettype.hxx> -#include <svl/svldata.hxx> -#include <svl/svl.hrc> - -#ifndef _SVSTDARR_STRINGSSORT_DECL -#define _SVSTDARR_STRINGSSORT -#include <svl/svstdarr.hxx> -#undef _SVSTDARR_STRINGSSORT -#endif - -namespace unnamed_svl_inettype {} -using namespace unnamed_svl_inettype; - // unnamed namespaces don't work well yet - -//============================================================================ -namespace unnamed_svl_inettype { - -//============================================================================ -struct MediaTypeEntry -{ - sal_Char const * m_pTypeName; - INetContentType m_eTypeID; - sal_Char const * m_pExtension; -}; - -//============================================================================ -struct TypeIDMapEntry -{ - UniString m_aTypeName; - UniString m_aPresentation; - UniString m_aSystemFileType; -}; - -//============================================================================ -struct TypeNameMapEntry: public UniString -{ - UniString m_aExtension; - INetContentType m_eTypeID; - - TypeNameMapEntry(const UniString & rType): - UniString(rType), m_eTypeID(CONTENT_TYPE_UNKNOWN) {} -}; - -//============================================================================ -struct ExtensionMapEntry: public UniString -{ - INetContentType m_eTypeID; - - ExtensionMapEntry(const UniString & rExt): - UniString(rExt), m_eTypeID(CONTENT_TYPE_UNKNOWN) {} -}; - -//============================================================================ -class Registration -{ - static Registration * m_pRegistration; - - Table m_aTypeIDMap; // map TypeID to TypeName, Presentation - SvStringsSort m_aTypeNameMap; // map TypeName to TypeID, Extension - SvStringsSort m_aExtensionMap; // map Extension to TypeID - sal_uInt32 m_nNextDynamicID; - -public: - Registration(): m_nNextDynamicID(CONTENT_TYPE_LAST + 1) {} - - ~Registration(); - - static inline void deinitialize(); - - static inline TypeIDMapEntry * getEntry(INetContentType eTypeID); - - static TypeNameMapEntry * getExtensionEntry(UniString const & rTypeName); - - static INetContentType RegisterContentType(UniString const & rTypeName, - UniString const & - rPresentation, - UniString const * pExtension, - UniString const * - pSystemFileType); - - static INetContentType GetContentType(UniString const & rTypeName); - - static UniString GetContentType(INetContentType eTypeID); - - static UniString GetPresentation(INetContentType eTypeID); - - static INetContentType GetContentType4Extension(UniString const & - rExtension); - -}; - -// static -inline void Registration::deinitialize() -{ - delete m_pRegistration; - m_pRegistration = 0; -} - -// static -inline TypeIDMapEntry * Registration::getEntry(INetContentType eTypeID) -{ - return - m_pRegistration ? - static_cast< TypeIDMapEntry * >(m_pRegistration-> - m_aTypeIDMap.Get(eTypeID)) : - 0; -} - -//============================================================================ -MediaTypeEntry const * seekEntry(UniString const & rTypeName, - MediaTypeEntry const * pMap, sal_Size nSize); - -//============================================================================ -/** A mapping from type names to type ids and extensions. Sorted by type - name. - */ -MediaTypeEntry const aStaticTypeNameMap[CONTENT_TYPE_LAST + 1] - = { { " ", CONTENT_TYPE_UNKNOWN, "" }, - { CONTENT_TYPE_STR_X_CNT_DOCUMENT, CONTENT_TYPE_X_CNT_DOCUMENT, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FSYSBOX, CONTENT_TYPE_X_CNT_FSYSBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_CDROM_VOLUME, - CONTENT_TYPE_X_CNT_CDROM_VOLUME, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_DISK_35, CONTENT_TYPE_X_CNT_DISK_35, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_DISK_525, CONTENT_TYPE_X_CNT_DISK_525, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FSYSFILE, CONTENT_TYPE_X_CNT_FSYSFILE, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FIXED_VOLUME, - CONTENT_TYPE_X_CNT_FIXED_VOLUME, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FSYSFOLDER, CONTENT_TYPE_X_CNT_FSYSFOLDER, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_RAM_VOLUME, CONTENT_TYPE_X_CNT_RAM_VOLUME, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_REMOTE_VOLUME, - CONTENT_TYPE_X_CNT_REMOTE_VOLUME, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_REMOVEABLE_VOLUME, - CONTENT_TYPE_X_CNT_REMOVEABLE_VOLUME, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FSYSSPECIALFILE, - CONTENT_TYPE_X_CNT_FSYSSPECIALFILE, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FSYSSPECIALFOLDER, - CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_TAPEDRIVE, CONTENT_TYPE_X_CNT_TAPEDRIVE, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FSYSURLFILE, CONTENT_TYPE_X_CNT_FSYSURLFILE, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FTPBOX, CONTENT_TYPE_X_CNT_FTPBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FTPFILE, CONTENT_TYPE_X_CNT_FTPFILE, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FTPFOLDER, CONTENT_TYPE_X_CNT_FTPFOLDER, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_FTPLINK, CONTENT_TYPE_X_CNT_FTPLINK, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_HTTPBOX, CONTENT_TYPE_X_CNT_HTTPBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_HTTPFILE, CONTENT_TYPE_X_CNT_HTTPFILE, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_IMAPBOX, CONTENT_TYPE_X_CNT_IMAPBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_IMAPFOLDER, CONTENT_TYPE_X_CNT_IMAPFOLDER, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_MESSAGE, CONTENT_TYPE_X_CNT_MESSAGE, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_NEWSBOX, CONTENT_TYPE_X_CNT_NEWSBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_NEWSGROUP, CONTENT_TYPE_X_CNT_NEWSGROUP, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_OUTBOX, CONTENT_TYPE_X_CNT_OUTBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_POP3BOX, CONTENT_TYPE_X_CNT_POP3BOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_PUBLISHBOX, CONTENT_TYPE_X_CNT_PUBLISHBOX, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_SEARCHBOX, CONTENT_TYPE_X_CNT_SEARCHBOX, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_SEPARATOR, CONTENT_TYPE_X_CNT_SEPARATOR, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_BOOKMARK, CONTENT_TYPE_X_CNT_BOOKMARK, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_SUBSCRIBEBOX, - CONTENT_TYPE_X_CNT_SUBSCRIBEBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_CDF, CONTENT_TYPE_X_CNT_CDF, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_CDFITEM, CONTENT_TYPE_X_CNT_CDFITEM, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_CDFSUB, CONTENT_TYPE_X_CNT_CDFSUB, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_STARCHANNEL, CONTENT_TYPE_X_CNT_STARCHANNEL, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_TRASHBOX, CONTENT_TYPE_X_CNT_TRASHBOX, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_TRASH, CONTENT_TYPE_X_CNT_TRASH, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_VIMBBOARD, CONTENT_TYPE_X_CNT_VIMBBOARD, - "tmp" }, - { CONTENT_TYPE_STR_X_CNT_VIMBBOARDBOX, - CONTENT_TYPE_X_CNT_VIMBBOARDBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_VIMBOX, CONTENT_TYPE_X_CNT_VIMBOX, "tmp" }, - { CONTENT_TYPE_STR_X_CNT_VIMINBOX, CONTENT_TYPE_X_CNT_VIMINBOX, - "tmp" }, - { CONTENT_TYPE_STR_APP_OCTSTREAM, CONTENT_TYPE_APP_OCTSTREAM, "tmp" }, - { CONTENT_TYPE_STR_APP_PDF, CONTENT_TYPE_APP_PDF, "pdf" }, - { CONTENT_TYPE_STR_APP_RTF, CONTENT_TYPE_APP_RTF, "rtf" }, - { CONTENT_TYPE_STR_APP_VND_CALC, CONTENT_TYPE_APP_VND_CALC, "sdc" }, - { CONTENT_TYPE_STR_APP_VND_CHART, CONTENT_TYPE_APP_VND_CHART, "sds" }, - { CONTENT_TYPE_STR_APP_VND_DRAW, CONTENT_TYPE_APP_VND_DRAW, "sda" }, - { CONTENT_TYPE_STR_APP_VND_IMAGE, CONTENT_TYPE_APP_VND_IMAGE, "sim" }, - { CONTENT_TYPE_STR_APP_VND_IMPRESS, CONTENT_TYPE_APP_VND_IMPRESS, - "sdd" }, - { CONTENT_TYPE_STR_APP_VND_IMPRESSPACKED, - CONTENT_TYPE_APP_VND_IMPRESSPACKED, "sdp" }, - { CONTENT_TYPE_STR_APP_VND_MAIL, CONTENT_TYPE_APP_VND_MAIL, "sdm" }, - { CONTENT_TYPE_STR_APP_VND_MATH, CONTENT_TYPE_APP_VND_MATH, "smf" }, - { CONTENT_TYPE_STR_APP_VND_NEWS, CONTENT_TYPE_APP_VND_NEWS, "sdm" }, - { CONTENT_TYPE_STR_APP_VND_OUTTRAY, CONTENT_TYPE_APP_VND_OUTTRAY, - "sdm" }, - { CONTENT_TYPE_STR_APP_VND_TEMPLATE, CONTENT_TYPE_APP_VND_TEMPLATE, - "vor" }, - { CONTENT_TYPE_STR_APP_VND_WRITER, CONTENT_TYPE_APP_VND_WRITER, - "sdw" }, - { CONTENT_TYPE_STR_APP_VND_WRITER_GLOBAL, - CONTENT_TYPE_APP_VND_WRITER_GLOBAL, "sgl" }, - { CONTENT_TYPE_STR_APP_VND_WRITER_WEB, - CONTENT_TYPE_APP_VND_WRITER_WEB, "htm" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_CALC, CONTENT_TYPE_APP_VND_SUN_XML_CALC, "sxc" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_CHART, CONTENT_TYPE_APP_VND_SUN_XML_CHART, "sxs" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_DRAW, CONTENT_TYPE_APP_VND_SUN_XML_DRAW, "sxd" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_IMPRESS, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS, "sxi" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_IMPRESSPACKED, CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED, "sxp" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_MATH, CONTENT_TYPE_APP_VND_SUN_XML_MATH, "sxm" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_WRITER, CONTENT_TYPE_APP_VND_SUN_XML_WRITER, "sxw" }, - { CONTENT_TYPE_STR_APP_VND_SUN_XML_WRITER_GLOBAL, CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL, "sxg" }, - { CONTENT_TYPE_STR_APP_FRAMESET, CONTENT_TYPE_APP_FRAMESET, "sfs" }, - { CONTENT_TYPE_STR_APP_GALLERY, CONTENT_TYPE_APP_GALLERY, "gal" }, - { CONTENT_TYPE_STR_APP_GALLERY_THEME, CONTENT_TYPE_APP_GALLERY_THEME, - "thm" }, - { CONTENT_TYPE_STR_APP_JAR, CONTENT_TYPE_APP_JAR, "jar" }, - { CONTENT_TYPE_STR_APP_MACRO, CONTENT_TYPE_APP_MACRO, "tmp" }, - { CONTENT_TYPE_STR_APP_MSEXCEL, CONTENT_TYPE_APP_MSEXCEL, "xls" }, - { CONTENT_TYPE_STR_APP_MSEXCEL_TEMPL, CONTENT_TYPE_APP_MSEXCEL_TEMPL, - "xlt" }, - { CONTENT_TYPE_STR_APP_MSPPOINT, CONTENT_TYPE_APP_MSPPOINT, "ppt" }, - { CONTENT_TYPE_STR_APP_MSPPOINT_TEMPL, - CONTENT_TYPE_APP_MSPPOINT_TEMPL, "pot" }, - { CONTENT_TYPE_STR_APP_MSWORD, CONTENT_TYPE_APP_MSWORD, "doc" }, - { CONTENT_TYPE_STR_APP_MSWORD_TEMPL, CONTENT_TYPE_APP_MSWORD_TEMPL, - "dot" }, - { CONTENT_TYPE_STR_APP_SCHEDULE_CMB, CONTENT_TYPE_APP_SCHEDULE, - "tmp" }, - { CONTENT_TYPE_STR_APP_SCHEDULE_EVT, CONTENT_TYPE_APP_SCHEDULE_EVT, - "tmp" }, - { CONTENT_TYPE_STR_APP_SCHEDULE_FEVT, - CONTENT_TYPE_APP_SCHEDULE_FORM_EVT, "tmp" }, - { CONTENT_TYPE_STR_APP_SCHEDULE_FTASK, - CONTENT_TYPE_APP_SCHEDULE_FORM_TASK, "tmp" }, - { CONTENT_TYPE_STR_APP_SCHEDULE_TASK, CONTENT_TYPE_APP_SCHEDULE_TASK, - "tmp" }, - { CONTENT_TYPE_STR_APP_STARCALC, CONTENT_TYPE_APP_STARCALC, "sdc" }, - { CONTENT_TYPE_STR_APP_STARCHART, CONTENT_TYPE_APP_STARCHART, "sds" }, - { CONTENT_TYPE_STR_APP_STARDRAW, CONTENT_TYPE_APP_STARDRAW, "sda" }, - { CONTENT_TYPE_STR_APP_STARHELP, CONTENT_TYPE_APP_STARHELP, "svh" }, - { CONTENT_TYPE_STR_APP_STARIMAGE, CONTENT_TYPE_APP_STARIMAGE, "sim" }, - { CONTENT_TYPE_STR_APP_STARIMPRESS, CONTENT_TYPE_APP_STARIMPRESS, - "sdd" }, - { CONTENT_TYPE_STR_APP_STARMAIL_SDM, CONTENT_TYPE_APP_STARMAIL_SDM, - "sdm" }, - { CONTENT_TYPE_STR_APP_STARMAIL_SMD, CONTENT_TYPE_APP_STARMAIL_SMD, - "smd" }, - { CONTENT_TYPE_STR_APP_STARMATH, CONTENT_TYPE_APP_STARMATH, "smf" }, - { CONTENT_TYPE_STR_APP_STARWRITER, CONTENT_TYPE_APP_STARWRITER, - "sdw" }, - { CONTENT_TYPE_STR_APP_STARWRITER_GLOB, - CONTENT_TYPE_APP_STARWRITER_GLOB, "sgl" }, - { CONTENT_TYPE_STR_APP_CDE_CALENDAR_APP, - CONTENT_TYPE_APP_CDE_CALENDAR_APP, "appt" }, - { CONTENT_TYPE_STR_APP_ZIP, CONTENT_TYPE_APP_ZIP, "zip" }, - { CONTENT_TYPE_STR_AUDIO_AIFF, CONTENT_TYPE_AUDIO_AIFF, "aif" }, - { CONTENT_TYPE_STR_AUDIO_BASIC, CONTENT_TYPE_AUDIO_BASIC, "au" }, - { CONTENT_TYPE_STR_AUDIO_MIDI, CONTENT_TYPE_AUDIO_MIDI, "mid" }, - { CONTENT_TYPE_STR_AUDIO_VORBIS, CONTENT_TYPE_AUDIO_VORBIS, "ogg" }, - { CONTENT_TYPE_STR_AUDIO_WAV, CONTENT_TYPE_AUDIO_WAV, "wav" }, - { CONTENT_TYPE_STR_AUDIO_WEBM, CONTENT_TYPE_AUDIO_WEBM, "webm" }, - { CONTENT_TYPE_STR_IMAGE_GENERIC, CONTENT_TYPE_IMAGE_GENERIC, "tmp" }, - { CONTENT_TYPE_STR_IMAGE_GIF, CONTENT_TYPE_IMAGE_GIF, "gif" }, - { CONTENT_TYPE_STR_IMAGE_JPEG, CONTENT_TYPE_IMAGE_JPEG, "jpg" }, - { CONTENT_TYPE_STR_IMAGE_PCX, CONTENT_TYPE_IMAGE_PCX, "pcx" }, - { CONTENT_TYPE_STR_IMAGE_PNG, CONTENT_TYPE_IMAGE_PNG, "png" }, - { CONTENT_TYPE_STR_IMAGE_TIFF, CONTENT_TYPE_IMAGE_TIFF, "tif" }, - { CONTENT_TYPE_STR_IMAGE_BMP, CONTENT_TYPE_IMAGE_BMP, "bmp" }, - { CONTENT_TYPE_STR_INET_MSG_RFC822, CONTENT_TYPE_INET_MESSAGE_RFC822, - "tmp" }, - { CONTENT_TYPE_STR_INET_MULTI_ALTERNATIVE, - CONTENT_TYPE_INET_MULTIPART_ALTERNATIVE, "tmp" }, - { CONTENT_TYPE_STR_INET_MULTI_DIGEST, - CONTENT_TYPE_INET_MULTIPART_DIGEST, "tmp" }, - { CONTENT_TYPE_STR_INET_MULTI_MIXED, - CONTENT_TYPE_INET_MULTIPART_MIXED, "tmp" }, - { CONTENT_TYPE_STR_INET_MULTI_PARALLEL, - CONTENT_TYPE_INET_MULTIPART_PARALLEL, "tmp" }, - { CONTENT_TYPE_STR_INET_MULTI_RELATED, - CONTENT_TYPE_INET_MULTIPART_RELATED, "tmp" }, - { CONTENT_TYPE_STR_TEXT_ICALENDAR, CONTENT_TYPE_TEXT_ICALENDAR, - "ics" }, - { CONTENT_TYPE_STR_TEXT_HTML, CONTENT_TYPE_TEXT_HTML, "htm" }, - { CONTENT_TYPE_STR_TEXT_PLAIN, CONTENT_TYPE_TEXT_PLAIN, "txt" }, - { CONTENT_TYPE_STR_TEXT_XMLICALENDAR, CONTENT_TYPE_TEXT_XMLICALENDAR, - "xcs" }, - { CONTENT_TYPE_STR_TEXT_URL, CONTENT_TYPE_TEXT_URL, "url" }, - { CONTENT_TYPE_STR_TEXT_VCALENDAR, CONTENT_TYPE_TEXT_VCALENDAR, - "vcs" }, - { CONTENT_TYPE_STR_TEXT_VCARD, CONTENT_TYPE_TEXT_VCARD, "vcf" }, - { CONTENT_TYPE_STR_VIDEO_MSVIDEO, CONTENT_TYPE_VIDEO_MSVIDEO, "avi" }, - { CONTENT_TYPE_STR_VIDEO_THEORA, CONTENT_TYPE_VIDEO_THEORA, "ogg" }, - { CONTENT_TYPE_STR_VIDEO_VDO, CONTENT_TYPE_VIDEO_VDO, "vdo" }, - { CONTENT_TYPE_STR_VIDEO_WEBM, CONTENT_TYPE_VIDEO_WEBM, "webm" }, - { CONTENT_TYPE_STR_X_STARMAIL, CONTENT_TYPE_X_STARMAIL, "smd" }, - { CONTENT_TYPE_STR_X_VRML, CONTENT_TYPE_X_VRML, "wrl" } -}; - -//============================================================================ -/** A mapping from type IDs to presentation resource IDs. Sorted by type ID. - */ -sal_uInt16 const aStaticResourceIDMap[CONTENT_TYPE_LAST + 1] - = { STR_SVT_MIMETYPE_APP_OCTSTREAM, // CONTENT_TYPE_UNKNOWN - STR_SVT_MIMETYPE_APP_OCTSTREAM, // CONTENT_TYPE_APP_OCTSTREAM - STR_SVT_MIMETYPE_APP_PDF, // CONTENT_TYPE_APP_PDF - STR_SVT_MIMETYPE_APP_RTF, // CONTENT_TYPE_APP_RTF - STR_SVT_MIMETYPE_APP_MSWORD, // CONTENT_TYPE_APP_MSWORD - STR_SVT_MIMETYPE_APP_MSWORD, // CONTENT_TYPE_APP_MSWORD_TEMPL //@todo new presentation string? - STR_SVT_MIMETYPE_APP_STARCALC, // CONTENT_TYPE_APP_STARCALC - STR_SVT_MIMETYPE_APP_STARCHART, // CONTENT_TYPE_APP_STARCHART - STR_SVT_MIMETYPE_APP_STARDRAW, // CONTENT_TYPE_APP_STARDRAW - STR_SVT_MIMETYPE_APP_STARHELP, // CONTENT_TYPE_APP_STARHELP - STR_SVT_MIMETYPE_APP_STARIMAGE, // CONTENT_TYPE_APP_STARIMAGE - STR_SVT_MIMETYPE_APP_STARIMPRESS, // CONTENT_TYPE_APP_STARIMPRESS - STR_SVT_MIMETYPE_APP_STARMATH, // CONTENT_TYPE_APP_STARMATH - STR_SVT_MIMETYPE_APP_STARWRITER, // CONTENT_TYPE_APP_STARWRITER - STR_SVT_MIMETYPE_APP_ZIP, // CONTENT_TYPE_APP_ZIP - STR_SVT_MIMETYPE_AUDIO_AIFF, // CONTENT_TYPE_AUDIO_AIFF - STR_SVT_MIMETYPE_AUDIO_BASIC, // CONTENT_TYPE_AUDIO_BASIC - STR_SVT_MIMETYPE_AUDIO_MIDI, // CONTENT_TYPE_AUDIO_MIDI - STR_SVT_MIMETYPE_AUDIO_VORBIS, // CONTENT_TYPE_AUDIO_VORBIS - STR_SVT_MIMETYPE_AUDIO_WAV, // CONTENT_TYPE_AUDIO_WAV - STR_SVT_MIMETYPE_AUDIO_WEBM, // CONTENT_TYPE_AUDIO_WEBM - STR_SVT_MIMETYPE_IMAGE_GIF, // CONTENT_TYPE_IMAGE_GIF - STR_SVT_MIMETYPE_IMAGE_JPEG, // CONTENT_TYPE_IMAGE_JPEG - STR_SVT_MIMETYPE_IMAGE_PCX, // CONTENT_TYPE_IMAGE_PCX - STR_SVT_MIMETYPE_IMAGE_PNG, // CONTENT_TYPE_IMAGE_PNG - STR_SVT_MIMETYPE_IMAGE_TIFF, // CONTENT_TYPE_IMAGE_TIFF - STR_SVT_MIMETYPE_IMAGE_BMP, // CONTENT_TYPE_IMAGE_BMP - STR_SVT_MIMETYPE_TEXT_HTML, // CONTENT_TYPE_TEXT_HTML - STR_SVT_MIMETYPE_TEXT_PLAIN, // CONTENT_TYPE_TEXT_PLAIN - STR_SVT_MIMETYPE_TEXT_URL, // CONTENT_TYPE_TEXT_URL - STR_SVT_MIMETYPE_TEXT_VCARD, // CONTENT_TYPE_TEXT_VCARD - STR_SVT_MIMETYPE_VIDEO_MSVIDEO, // CONTENT_TYPE_VIDEO_MSVIDEO - STR_SVT_MIMETYPE_VIDEO_THEORA, // CONTENT_TYPE_VIDEO_THEORA - STR_SVT_MIMETYPE_VIDEO_VDO, // CONTENT_TYPE_VIDEO_VDO - STR_SVT_MIMETYPE_VIDEO_WEBM, // CONTENT_TYPE_VIDEO_WEBM - STR_SVT_MIMETYPE_CNT_MSG, // CONTENT_TYPE_X_CNT_MESSAGE - STR_SVT_MIMETYPE_CNT_DOCUMENT, // CONTENT_TYPE_X_CNT_DOCUMENT - STR_SVT_MIMETYPE_CNT_POP3BOX, // CONTENT_TYPE_X_CNT_POP3BOX - STR_SVT_MIMETYPE_CNT_IMAPBOX, // CONTENT_TYPE_X_CNT_IMAPBOX - STR_SVT_MIMETYPE_CNT_IMAPFLD, // CONTENT_TYPE_X_CNT_IMAPFOLDER - STR_SVT_MIMETYPE_CNT_VIMBOX, // CONTENT_TYPE_X_CNT_VIMBOX - STR_SVT_MIMETYPE_CNT_VIMINBOX, // CONTENT_TYPE_X_CNT_VIMINBOX - STR_SVT_MIMETYPE_CNT_BBBOX, // CONTENT_TYPE_X_CNT_VIMBBOARDBOX - STR_SVT_MIMETYPE_CNT_VIM_BB, // CONTENT_TYPE_X_CNT_VIMBBOARD - STR_SVT_MIMETYPE_CNT_NEWSBOX, // CONTENT_TYPE_X_CNT_NEWSBOX - STR_SVT_MIMETYPE_CNT_NEWSGRP, // CONTENT_TYPE_X_CNT_NEWSGROUP - STR_SVT_MIMETYPE_CNT_OUTBOX, // CONTENT_TYPE_X_CNT_OUTBOX - STR_SVT_MIMETYPE_CNT_FTPBOX, // CONTENT_TYPE_X_CNT_FTPBOX - STR_SVT_MIMETYPE_CNT_FTPFLD, // CONTENT_TYPE_X_CNT_FTPFOLDER - STR_SVT_MIMETYPE_CNT_FTPFILE, // CONTENT_TYPE_X_CNT_FTPFILE - STR_SVT_MIMETYPE_CNT_FTPLINK, // CONTENT_TYPE_X_CNT_FTPLINK - STR_SVT_MIMETYPE_CNT_HTTPBOX, // CONTENT_TYPE_X_CNT_HTTPBOX - STR_SVT_MIMETYPE_CNT_FSYSBOX, // CONTENT_TYPE_X_CNT_FSYSBOX - STR_SVT_MIMETYPE_CNT_FSYSFLD, // CONTENT_TYPE_X_CNT_FSYSFOLDER - STR_SVT_MIMETYPE_CNT_FSYSFILE, // CONTENT_TYPE_X_CNT_FSYSFILE - STR_SVT_MIMETYPE_CNT_FSYSURLFILE, // CONTENT_TYPE_X_CNT_FSYSURLFILE - STR_SVT_MIMETYPE_CNT_PUBLBOX, // CONTENT_TYPE_X_CNT_PUBLISHBOX - STR_SVT_MIMETYPE_CNT_SRCHBOX, // CONTENT_TYPE_X_CNT_SEARCHBOX - STR_SVT_MIMETYPE_CNT_SUBSCRBOX, // CONTENT_TYPE_X_CNT_SUBSCRIBEBOX - STR_SVT_MIMETYPE_CNT_BOOKMARK, // CONTENT_TYPE_X_CNT_BOOKMARK - STR_SVT_MIMETYPE_CNT_CDF, // CONTENT_TYPE_X_CNT_CDF - STR_SVT_MIMETYPE_CNT_CDFSUB, // CONTENT_TYPE_X_CNT_CDFSUB - STR_SVT_MIMETYPE_CNT_CDFITEM, // CONTENT_TYPE_X_CNT_CDFITEM - STR_SVT_MIMETYPE_CNT_TRASHBOX, // CONTENT_TYPE_X_CNT_TRASHBOX - STR_SVT_MIMETYPE_CNT_TRASH, // CONTENT_TYPE_X_CNT_TRASH - STR_SVT_MIMETYPE_X_STARMAIL, // CONTENT_TYPE_X_STARMAIL - STR_SVT_MIMETYPE_X_VRML, // CONTENT_TYPE_X_VRML - STR_SVT_MIMETYPE_CNT_REMOV_VOL, - // CONTENT_TYPE_X_CNT_REMOVEABLE_VOLUME - STR_SVT_MIMETYPE_CNT_FIX_VOL, // CONTENT_TYPE_X_CNT_FIXED_VOLUME - STR_SVT_MIMETYPE_CNT_REM_VOL, // CONTENT_TYPE_X_CNT_REMOTE_VOLUME - STR_SVT_MIMETYPE_CNT_RAM_VOL, // CONTENT_TYPE_X_CNT_RAM_VOLUME - STR_SVT_MIMETYPE_CNT_CDROM, // CONTENT_TYPE_X_CNT_CDROM_VOLUME - STR_SVT_MIMETYPE_CNT_DISK_35, // CONTENT_TYPE_X_CNT_DISK_35 - STR_SVT_MIMETYPE_CNT_DISK_525, // CONTENT_TYPE_X_CNT_DISK_525 - STR_SVT_MIMETYPE_CNT_TAPEDRIVE, // CONTENT_TYPE_X_CNT_TAPEDRIVE - STR_SVT_MIMETYPE_APP_GAL, // CONTENT_TYPE_APP_GALLERY - STR_SVT_MIMETYPE_APP_GAL_THEME, // CONTENT_TYPE_APP_GALLERY_THEME - STR_SVT_MIMETYPE_CNT_STARCHANNEL, // CONTENT_TYPE_X_CNT_STARCHANNEL - STR_SVT_MIMETYPE_CNT_SEPARATOR, // CONTENT_TYPE_X_CNT_SEPARATOR - STR_SVT_MIMETYPE_APP_STARW_GLOB, // CONTENT_TYPE_APP_STARWRITER_GLOB - STR_SVT_MIMETYPE_APP_SDM, // CONTENT_TYPE_APP_STARMAIL_SDM - STR_SVT_MIMETYPE_APP_SMD, // CONTENT_TYPE_APP_STARMAIL_SMD - STR_SVT_MIMETYPE_APP_STARCALC, // CONTENT_TYPE_APP_VND_CALC - STR_SVT_MIMETYPE_APP_STARCHART, // CONTENT_TYPE_APP_VND_CHART - STR_SVT_MIMETYPE_APP_STARDRAW, // CONTENT_TYPE_APP_VND_DRAW - STR_SVT_MIMETYPE_APP_STARIMAGE, // CONTENT_TYPE_APP_VND_IMAGE - STR_SVT_MIMETYPE_APP_STARIMPRESS, // CONTENT_TYPE_APP_VND_IMPRESS - STR_SVT_MIMETYPE_X_STARMAIL, // CONTENT_TYPE_APP_VND_MAIL - STR_SVT_MIMETYPE_APP_STARMATH, // CONTENT_TYPE_APP_VND_MATH - STR_SVT_MIMETYPE_APP_STARWRITER, // CONTENT_TYPE_APP_VND_WRITER - STR_SVT_MIMETYPE_APP_STARW_GLOB, // CONTENT_TYPE_APP_VND_WRITER_GLOBAL - STR_SVT_MIMETYPE_APP_STARW_WEB, // CONTENT_TYPE_APP_VND_WRITER_WEB - STR_SVT_MIMETYPE_SCHEDULE, // CONTENT_TYPE_APP_SCHEDULE - STR_SVT_MIMETYPE_SCHEDULE_EVT, // CONTENT_TYPE_APP_SCHEDULE_EVT - STR_SVT_MIMETYPE_SCHEDULE_TASK, // CONTENT_TYPE_APP_SCHEDULE_TASK - STR_SVT_MIMETYPE_SCHEDULE_FEVT, // CONTENT_TYPE_APP_SCHEDULE_FORM_EVT - STR_SVT_MIMETYPE_SCHEDULE_FTASK, - // CONTENT_TYPE_APP_SCHEDULE_FORM_TASK - STR_SVT_MIMETYPE_FRAMESET, // CONTENT_TYPE_APP_FRAMESET - STR_SVT_MIMETYPE_MACRO, // CONTENT_TYPE_APP_MACRO - STR_SVT_MIMETYPE_CNT_SFSYSFOLDER, - // CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER - STR_SVT_MIMETYPE_CNT_SFSYSFILE, // CONTENT_TYPE_X_CNT_FSYSSPECIALFILE - STR_SVT_MIMETYPE_APP_TEMPLATE, // CONTENT_TYPE_APP_VND_TEMPLATE - STR_SVT_MIMETYPE_IMAGE_GENERIC, // CONTENT_TYPE_IMAGE_GENERIC - STR_SVT_MIMETYPE_X_STARMAIL, // CONTENT_TYPE_APP_VND_NEWS - STR_SVT_MIMETYPE_X_STARMAIL, // CONTENT_TYPE_APP_VND_OUTTRAY - STR_SVT_MIMETYPE_TEXT_HTML, // CONTENT_TYPE_X_CNT_HTTPFILE - STR_SVT_MIMETYPE_APP_MSEXCEL, // CONTENT_TYPE_APP_MSEXCEL - STR_SVT_MIMETYPE_APP_MSEXCEL_TEMPL, // CONTENT_TYPE_APP_MSEXCEL_TEMPL - STR_SVT_MIMETYPE_APP_MSPPOINT, // CONTENT_TYPE_APP_MSPPOINT - STR_SVT_MIMETYPE_APP_MSPPOINT, // CONTENT_TYPE_APP_MSPPOINT_TEMPL //@todo new presentation string? - STR_SVT_MIMETYPE_TEXT_VCALENDAR, // CONTENT_TYPE_TEXT_VCALENDAR - STR_SVT_MIMETYPE_TEXT_ICALENDAR, // CONTENT_TYPE_TEXT_ICALENDAR - STR_SVT_MIMETYPE_TEXT_XMLICALENDAR, // CONTENT_TYPE_TEXT_XMLICALENDAR - STR_SVT_MIMETYPE_TEXT_CDE_CALENDAR_APP, - // CONTENT_TYPE_APP_CDE_CALENDAR_APP - STR_SVT_MIMETYPE_INET_MSG_RFC822, // CONTENT_TYPE_INET_MESSAGE_RFC822 - STR_SVT_MIMETYPE_INET_MULTI_ALTERNATIVE, - // CONTENT_TYPE_INET_MULTIPART_ALTERNATIVE - STR_SVT_MIMETYPE_INET_MULTI_DIGEST, - // CONTENT_TYPE_INET_MULTIPART_DIGEST - STR_SVT_MIMETYPE_INET_MULTI_PARALLEL, - // CONTENT_TYPE_INET_MULTIPART_PARALLEL - STR_SVT_MIMETYPE_INET_MULTI_RELATED, - // CONTENT_TYPE_INET_MULTIPART_RELATED - STR_SVT_MIMETYPE_INET_MULTI_MIXED, - // CONTENT_TYPE_INET_MULTIPART_MIXED - STR_SVT_MIMETYPE_APP_IMPRESSPACKED, - // CONTENT_TYPE_APP_VND_IMPRESSPACKED - STR_SVT_MIMETYPE_APP_JAR, // CONTENT_TYPE_APP_JAR - STR_SVT_MIMETYPE_APP_SXWRITER, // CONTENT_TYPE_APP_VND_SUN_XML_WRITER - STR_SVT_MIMETYPE_APP_SXCALC, // CONTENT_TYPE_APP_VND_SUN_XML_CALC - STR_SVT_MIMETYPE_APP_SXIMPRESS, // CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS - STR_SVT_MIMETYPE_APP_SXDRAW, // CONTENT_TYPE_APP_VND_SUN_XML_DRAW - STR_SVT_MIMETYPE_APP_SXCHART, // CONTENT_TYPE_APP_VND_SUN_XML_CHART - STR_SVT_MIMETYPE_APP_SXMATH, // CONTENT_TYPE_APP_VND_SUN_XML_MATH - STR_SVT_MIMETYPE_APP_SXGLOBAL, // CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL - STR_SVT_MIMETYPE_APP_SXIPACKED, // CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED - }; - -//============================================================================ -/** A mapping from extensions to type IDs. Sorted by extension. - */ -MediaTypeEntry const aStaticExtensionMap[] - = { { "aif", CONTENT_TYPE_AUDIO_AIFF, "" }, - { "aiff", CONTENT_TYPE_AUDIO_AIFF, "" }, - { "appt", CONTENT_TYPE_APP_CDE_CALENDAR_APP, "" }, - { "au", CONTENT_TYPE_AUDIO_BASIC, "" }, - { "avi", CONTENT_TYPE_VIDEO_MSVIDEO, "" }, - { "bmp", CONTENT_TYPE_IMAGE_BMP, "" }, - { "cgm", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "doc", CONTENT_TYPE_APP_MSWORD, "" }, - { "dot", CONTENT_TYPE_APP_MSWORD_TEMPL, "" }, - { "dxf", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "eps", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "gal", CONTENT_TYPE_APP_GALLERY, "" }, - { "gif", CONTENT_TYPE_IMAGE_GIF, "" }, - { "htm", CONTENT_TYPE_TEXT_HTML, "" }, - { "html", CONTENT_TYPE_TEXT_HTML, "" }, - { "ics", CONTENT_TYPE_TEXT_ICALENDAR, "" }, - { "jar", CONTENT_TYPE_APP_JAR, "" }, - { "jpeg", CONTENT_TYPE_IMAGE_JPEG, "" }, - { "jpg", CONTENT_TYPE_IMAGE_JPEG, "" }, - { "met", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "mid", CONTENT_TYPE_AUDIO_MIDI, "" }, - { "midi", CONTENT_TYPE_AUDIO_MIDI, "" }, - { "ogg", CONTENT_TYPE_AUDIO_VORBIS, "" }, - { "pbm", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "pcd", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "pct", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "pcx", CONTENT_TYPE_IMAGE_PCX, "" }, - { "pdf", CONTENT_TYPE_APP_PDF, "" }, - { "pgm", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "png", CONTENT_TYPE_IMAGE_PNG, "" }, - { "pot", CONTENT_TYPE_APP_MSPPOINT_TEMPL, "" }, - { "ppm", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "ppt", CONTENT_TYPE_APP_MSPPOINT, "" }, - { "psd", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "ras", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "rtf", CONTENT_TYPE_APP_RTF, "" }, - { "sda", CONTENT_TYPE_APP_VND_DRAW, "" }, - { "sdc", CONTENT_TYPE_APP_VND_CALC, "" }, - { "sdd", CONTENT_TYPE_APP_VND_IMPRESS, "" }, - { "sdm", CONTENT_TYPE_APP_VND_MAIL, "" }, - { "sdp", CONTENT_TYPE_APP_VND_IMPRESSPACKED, "" }, - { "sds", CONTENT_TYPE_APP_VND_CHART, "" }, - { "sdw", CONTENT_TYPE_APP_VND_WRITER, "" }, - { "sd~", CONTENT_TYPE_X_STARMAIL, "" }, - { "sfs", CONTENT_TYPE_APP_FRAMESET , "" }, - { "sgl", CONTENT_TYPE_APP_VND_WRITER_GLOBAL , "" }, - { "sim", CONTENT_TYPE_APP_VND_IMAGE, "" }, - { "smd", CONTENT_TYPE_APP_STARMAIL_SMD, "" }, //CONTENT_TYPE_X_STARMAIL - { "smf", CONTENT_TYPE_APP_VND_MATH, "" }, - { "svh", CONTENT_TYPE_APP_STARHELP, "" }, - { "svm", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "sxc", CONTENT_TYPE_APP_VND_SUN_XML_CALC, "" }, - { "sxd", CONTENT_TYPE_APP_VND_SUN_XML_DRAW, "" }, - { "sxg", CONTENT_TYPE_APP_VND_SUN_XML_WRITER_GLOBAL, "" }, - { "sxi", CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS, "" }, - { "sxm", CONTENT_TYPE_APP_VND_SUN_XML_MATH, "" }, - { "sxp", CONTENT_TYPE_APP_VND_SUN_XML_IMPRESSPACKED, "" }, - { "sxs", CONTENT_TYPE_APP_VND_SUN_XML_CHART, "" }, - { "sxw", CONTENT_TYPE_APP_VND_SUN_XML_WRITER, "" }, - { "tga", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "thm", CONTENT_TYPE_APP_GALLERY_THEME, "" }, - { "tif", CONTENT_TYPE_IMAGE_TIFF, "" }, - { "tiff", CONTENT_TYPE_IMAGE_TIFF, "" }, - { "txt", CONTENT_TYPE_TEXT_PLAIN, "" }, - { "url", CONTENT_TYPE_TEXT_URL, "" }, - { "vcf", CONTENT_TYPE_TEXT_VCARD, "" }, - { "vcs", CONTENT_TYPE_TEXT_VCALENDAR, "" }, - { "vdo", CONTENT_TYPE_VIDEO_VDO, "" }, - { "vor", CONTENT_TYPE_APP_VND_TEMPLATE, "" }, - { "wav", CONTENT_TYPE_AUDIO_WAV, "" }, - { "webm", CONTENT_TYPE_VIDEO_WEBM, "" }, - { "wmf", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "wrl", CONTENT_TYPE_X_VRML, "" }, - { "xbm", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "xcs", CONTENT_TYPE_TEXT_XMLICALENDAR, "" }, - { "xls", CONTENT_TYPE_APP_MSEXCEL, "" }, - { "xlt", CONTENT_TYPE_APP_MSEXCEL_TEMPL, "" }, - { "xlw", CONTENT_TYPE_APP_MSEXCEL, "" }, - { "xpm", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "zip", CONTENT_TYPE_APP_ZIP, "" } }; - -//============================================================================ -/** A mapping from presentations to type IDs. Sorted by presentations. - */ -MediaTypeEntry const aStaticPresentationMap[] - = { { "Binary Data", CONTENT_TYPE_APP_OCTSTREAM, "" }, - { "Bitmap", CONTENT_TYPE_IMAGE_BMP, "" }, - { "DOS Command File", CONTENT_TYPE_APP_OCTSTREAM, "" }, - { "Digital Video", CONTENT_TYPE_VIDEO_MSVIDEO, "" }, - { "Executable", CONTENT_TYPE_APP_OCTSTREAM, "" }, - { "Grafik", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "HTM", CONTENT_TYPE_TEXT_HTML, "" }, - { "HTML", CONTENT_TYPE_TEXT_HTML, "" }, - { "Hypertext", CONTENT_TYPE_TEXT_HTML, "" }, - { "Icon", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "Image File", CONTENT_TYPE_IMAGE_GENERIC, "" }, - { "MIDI", CONTENT_TYPE_AUDIO_MIDI, "" }, - { "Master Document", CONTENT_TYPE_APP_VND_WRITER_GLOBAL, "" }, - { "Plain Text", CONTENT_TYPE_TEXT_PLAIN, "" }, - { "StarCalc", CONTENT_TYPE_APP_VND_CALC, "" }, - { "StarCalc 3.0", CONTENT_TYPE_APP_VND_CALC, "" }, - { "StarCalc 4.0", CONTENT_TYPE_APP_VND_CALC, "" }, - { "StarCalc 5.0", CONTENT_TYPE_APP_VND_CALC, "" }, - { "StarCalc Datei", CONTENT_TYPE_APP_VND_CALC, "" }, - { "StarCalc Document", CONTENT_TYPE_APP_VND_CALC, "" }, - { "StarCalc File", CONTENT_TYPE_APP_VND_CALC, "" }, - { "StarChart 3.0", CONTENT_TYPE_APP_VND_CHART, "" }, - { "StarChart 4.0", CONTENT_TYPE_APP_VND_CHART, "" }, - { "StarChart 5.0", CONTENT_TYPE_APP_VND_CHART, "" }, - { "StarChart Document", CONTENT_TYPE_APP_VND_CHART, "" }, - { "StarDraw 3.0", CONTENT_TYPE_APP_VND_DRAW, "" }, - { "StarDraw 5.0", CONTENT_TYPE_APP_VND_DRAW, "" }, - { "StarDraw", CONTENT_TYPE_APP_VND_DRAW, "" }, - { "StarDraw Document", CONTENT_TYPE_APP_VND_DRAW, "" }, - { "StarImpress 4.0", CONTENT_TYPE_APP_VND_IMPRESS, "" }, - { "StarImpress 5.0 (packed)", CONTENT_TYPE_APP_VND_IMPRESSPACKED, "" }, - { "StarImpress 5.0", CONTENT_TYPE_APP_VND_IMPRESS, "" }, - { "StarImpress Document", CONTENT_TYPE_APP_VND_IMPRESS, "" }, - { "StarMath 3.0", CONTENT_TYPE_APP_VND_MATH, "" }, - { "StarMath 4.0", CONTENT_TYPE_APP_VND_MATH, "" }, - { "StarMath 5.0", CONTENT_TYPE_APP_VND_MATH, "" }, - { "StarMath Document", CONTENT_TYPE_APP_VND_MATH, "" }, - { "StarMessage5", CONTENT_TYPE_APP_VND_MAIL, "" }, - { "StarOffice XML (Calc)", CONTENT_TYPE_APP_VND_SUN_XML_CALC, "" }, - { "StarOffice XML (Impress)", CONTENT_TYPE_APP_VND_SUN_XML_IMPRESS, "" }, - { "StarOffice XML (Draw)", CONTENT_TYPE_APP_VND_SUN_XML_DRAW, "" }, - { "StarOffice XML (Chart)", CONTENT_TYPE_APP_VND_SUN_XML_CHART, "" }, - { "StarOffice XML (Writer)", CONTENT_TYPE_APP_VND_SUN_XML_WRITER, "" }, - { "StarWriter", CONTENT_TYPE_APP_VND_WRITER, "" }, - { "StarWriter 3.0", CONTENT_TYPE_APP_VND_WRITER, "" }, - { "StarWriter 4.0", CONTENT_TYPE_APP_VND_WRITER, "" }, - { "StarWriter 5.0", CONTENT_TYPE_APP_VND_WRITER, "" }, - { "StarWriter Document", CONTENT_TYPE_APP_VND_WRITER, "" }, - { "StarWriter/Global 5.0", CONTENT_TYPE_APP_VND_WRITER_GLOBAL, "" }, - { "StarWriter/Global Document", CONTENT_TYPE_APP_VND_WRITER_GLOBAL, "" }, - { "StarWriter/Web 5.0", CONTENT_TYPE_APP_VND_WRITER_WEB, "" }, - { "StarWriterGlobal Document", CONTENT_TYPE_APP_VND_WRITER_GLOBAL, "" }, - { "StarWriterHtml Document", CONTENT_TYPE_APP_VND_WRITER_WEB, "" }, - { "UniformResourceLocator", CONTENT_TYPE_TEXT_URL, "" }, - { "text/html", CONTENT_TYPE_TEXT_HTML, "" } }; - -} - -//============================================================================ -// -// Registration -// -//============================================================================ - -// static -Registration * Registration::m_pRegistration = 0; - -//============================================================================ -Registration::~Registration() -{ - {for (sal_uLong i = 0; i < m_aTypeIDMap.Count(); ++i) - delete static_cast< TypeIDMapEntry * >(m_aTypeIDMap.GetObject(i)); - } - m_aTypeIDMap.Clear(); - {for (sal_uInt16 i = 0; i < m_aTypeNameMap.Count(); ++i) - delete static_cast< TypeNameMapEntry * >(m_aTypeNameMap.GetObject(i)); - } - m_aTypeNameMap.Remove(sal_uInt16(0), m_aTypeNameMap.Count()); - {for (sal_uInt16 i = 0; i < m_aExtensionMap.Count(); ++i) - delete - static_cast< ExtensionMapEntry * >(m_aExtensionMap.GetObject(i)); - } - m_aExtensionMap.Remove(sal_uInt16(0), m_aExtensionMap.Count()); -} - -//============================================================================ -// static -TypeNameMapEntry * Registration::getExtensionEntry(UniString const & - rTypeName) -{ - if (m_pRegistration) - { - UniString aTheTypeName = rTypeName; - aTheTypeName.ToLowerAscii(); - sal_uInt16 nPos; - if (m_pRegistration->m_aTypeNameMap.Seek_Entry(&aTheTypeName, &nPos)) - return static_cast< TypeNameMapEntry * >(m_pRegistration-> - m_aTypeNameMap. - GetObject(nPos)); - } - return 0; -} - -//============================================================================ -// static -INetContentType Registration::RegisterContentType(UniString const & rTypeName, - UniString const & - rPresentation, - UniString const * - pExtension, - UniString const * - pSystemFileType) -{ - if (!m_pRegistration) - m_pRegistration = new Registration; - - DBG_ASSERT(GetContentType(rTypeName) == CONTENT_TYPE_UNKNOWN, - "Registration::RegisterContentType(): Already registered"); - - INetContentType eTypeID - = INetContentType(m_pRegistration->m_nNextDynamicID++); - UniString aTheTypeName = rTypeName; - aTheTypeName.ToLowerAscii(); - - TypeIDMapEntry * pTypeIDMapEntry = new TypeIDMapEntry; - pTypeIDMapEntry->m_aTypeName = aTheTypeName; - pTypeIDMapEntry->m_aPresentation = rPresentation; - if (pSystemFileType) - pTypeIDMapEntry->m_aSystemFileType = *pSystemFileType; - m_pRegistration->m_aTypeIDMap.Insert(eTypeID, pTypeIDMapEntry); - - TypeNameMapEntry * pTypeNameMapEntry = new TypeNameMapEntry(aTheTypeName); - if (pExtension) - pTypeNameMapEntry->m_aExtension = *pExtension; - pTypeNameMapEntry->m_eTypeID = eTypeID; - m_pRegistration->m_aTypeNameMap.Insert(pTypeNameMapEntry); - - if (pExtension) - { - ExtensionMapEntry * pExtensionMapEntry - = new ExtensionMapEntry(*pExtension); - pExtensionMapEntry->m_eTypeID = eTypeID; - m_pRegistration->m_aExtensionMap.Insert(pExtensionMapEntry); - } - - return eTypeID; -} - -//============================================================================ -// static -INetContentType Registration::GetContentType(UniString const & rTypeName) -{ - if (!m_pRegistration) - m_pRegistration = new Registration; - - UniString aTheTypeName = rTypeName; - aTheTypeName.ToLowerAscii(); - sal_uInt16 nPos; - return m_pRegistration->m_aTypeNameMap.Seek_Entry(&aTheTypeName, &nPos) ? - static_cast< TypeNameMapEntry * >(m_pRegistration-> - m_aTypeNameMap. - GetObject(nPos))-> - m_eTypeID : - CONTENT_TYPE_UNKNOWN; -} - -//============================================================================ -// static -UniString Registration::GetContentType(INetContentType eTypeID) -{ - if (!m_pRegistration) - m_pRegistration = new Registration; - - TypeIDMapEntry * pEntry - = static_cast< TypeIDMapEntry * >(m_pRegistration-> - m_aTypeIDMap.Get(eTypeID)); - return pEntry ? pEntry->m_aTypeName : UniString(); -} - -//============================================================================ -// static -UniString Registration::GetPresentation(INetContentType eTypeID) -{ - if (!m_pRegistration) - m_pRegistration = new Registration; - - TypeIDMapEntry * pEntry - = static_cast< TypeIDMapEntry * >(m_pRegistration-> - m_aTypeIDMap.Get(eTypeID)); - return pEntry ? pEntry->m_aPresentation : UniString(); -} - -//============================================================================ -// static -INetContentType Registration::GetContentType4Extension(UniString const & - rExtension) -{ - if (!m_pRegistration) - m_pRegistration = new Registration; - - sal_uInt16 nPos; - return m_pRegistration-> - m_aExtensionMap. - Seek_Entry(const_cast< UniString * >(&rExtension), - &nPos) ? - static_cast< ExtensionMapEntry * >(m_pRegistration-> - m_aExtensionMap. - GetObject(nPos))-> - m_eTypeID : - CONTENT_TYPE_UNKNOWN; -} - -//============================================================================ -// -// seekEntry -// -//============================================================================ - -namespace unnamed_svl_inettype { - -MediaTypeEntry const * seekEntry(UniString const & rTypeName, - MediaTypeEntry const * pMap, sal_Size nSize) -{ -#if defined DBG_UTIL - for (sal_Size i = 0; i < nSize - 1; ++i) - DBG_ASSERT( - rtl_str_compare( - pMap[i].m_pTypeName, pMap[i + 1].m_pTypeName) < 0, - "seekEntry(): Bad map"); -#endif - - sal_Size nLow = 0; - sal_Size nHigh = nSize; - while (nLow != nHigh) - { - sal_Size nMiddle = (nLow + nHigh) / 2; - MediaTypeEntry const * pEntry = pMap + nMiddle; - switch (rTypeName.CompareIgnoreCaseToAscii(pEntry->m_pTypeName)) - { - case COMPARE_LESS: - nHigh = nMiddle; - break; - - case COMPARE_EQUAL: - return pEntry; - - case COMPARE_GREATER: - nLow = nMiddle + 1; - break; - } - } - return 0; -} - -} - -//static -INetContentType INetContentTypes::RegisterContentType(UniString const & - rTypeName, - UniString const & - rPresentation, - UniString const * - pExtension, - UniString const * - pSystemFileType) -{ - INetContentType eTypeID = GetContentType(rTypeName); - if (eTypeID == CONTENT_TYPE_UNKNOWN) - eTypeID = Registration::RegisterContentType(rTypeName, rPresentation, - pExtension, - pSystemFileType); - else if (eTypeID > CONTENT_TYPE_LAST) - { - TypeIDMapEntry * pTypeEntry = Registration::getEntry(eTypeID); - if (pTypeEntry) - { - if (rPresentation.Len() != 0) - pTypeEntry->m_aPresentation = rPresentation; - if (pSystemFileType) - pTypeEntry->m_aSystemFileType = *pSystemFileType; - } - if (pExtension) - { - TypeNameMapEntry * pEntry - = Registration::getExtensionEntry(rTypeName); - if (pEntry) - pEntry->m_aExtension = *pExtension; - } - } - return eTypeID; -} - -//============================================================================ -// static -INetContentType INetContentTypes::GetContentType(UniString const & rTypeName) -{ - UniString aType; - UniString aSubType; - if (parse(rTypeName, aType, aSubType)) - { - aType += '/'; - aType += aSubType; - MediaTypeEntry const * pEntry = seekEntry(aType, aStaticTypeNameMap, - CONTENT_TYPE_LAST + 1); - return pEntry ? pEntry->m_eTypeID : - Registration::GetContentType(aType); - } - else - return - rTypeName.EqualsIgnoreCaseAscii(CONTENT_TYPE_STR_X_STARMAIL) ? - CONTENT_TYPE_X_STARMAIL : CONTENT_TYPE_UNKNOWN; - // the content type "x-starmail" has no sub type -} - -//============================================================================ -//static -UniString INetContentTypes::GetContentType(INetContentType eTypeID) -{ - static sal_Char const * aMap[CONTENT_TYPE_LAST + 1]; - static bool bInitialized = false; - if (!bInitialized) - { - for (sal_Size i = 0; i <= CONTENT_TYPE_LAST; ++i) - aMap[aStaticTypeNameMap[i].m_eTypeID] - = aStaticTypeNameMap[i].m_pTypeName; - aMap[CONTENT_TYPE_UNKNOWN] = CONTENT_TYPE_STR_APP_OCTSTREAM; - aMap[CONTENT_TYPE_TEXT_PLAIN] = CONTENT_TYPE_STR_TEXT_PLAIN - "; charset=iso-8859-1"; - bInitialized = true; - } - - UniString aTypeName = eTypeID <= CONTENT_TYPE_LAST ? - UniString::CreateFromAscii(aMap[eTypeID]) : - Registration::GetContentType(eTypeID); - if (aTypeName.Len() == 0) - { - OSL_FAIL("INetContentTypes::GetContentType(): Bad ID"); - return - UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( - CONTENT_TYPE_STR_APP_OCTSTREAM)); - } - return aTypeName; -} - -//============================================================================ -//static -UniString INetContentTypes::GetPresentation(INetContentType eTypeID, - const ::com::sun::star::lang::Locale& aLocale) -{ - sal_uInt16 nResID = sal_uInt16(); - if (eTypeID <= CONTENT_TYPE_LAST) - nResID = aStaticResourceIDMap[eTypeID]; - else - { - UniString aPresentation = Registration::GetPresentation(eTypeID); - if (aPresentation.Len() == 0) - nResID = STR_SVT_MIMETYPE_APP_OCTSTREAM; - else - return aPresentation; - } - return SvtSimpleResId(nResID, aLocale); -} - -//============================================================================ -//static -INetContentType INetContentTypes::GetContentType4Extension(UniString const & - rExtension) -{ - MediaTypeEntry const * pEntry = seekEntry(rExtension, aStaticExtensionMap, - sizeof aStaticExtensionMap - / sizeof (MediaTypeEntry)); - if (pEntry) - return pEntry->m_eTypeID; - INetContentType eTypeID - = Registration::GetContentType4Extension(rExtension); - return eTypeID == CONTENT_TYPE_UNKNOWN ? CONTENT_TYPE_APP_OCTSTREAM : - eTypeID; -} - -//============================================================================ -//static -INetContentType INetContentTypes::GetContentTypeFromURL(UniString const & - rURL) -{ - INetContentType eTypeID = CONTENT_TYPE_UNKNOWN; - UniString aToken = rURL.GetToken(0, ':'); - if (aToken.Len() != 0) - { - if (aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_FILE)) - if (rURL.GetChar(rURL.Len() - 1) == '/') // folder - if (rURL.Len() > RTL_CONSTASCII_LENGTH("file:///")) - if (WildCard(UniString(RTL_CONSTASCII_USTRINGPARAM( - "*/{*}/"))). - Matches(rURL)) // special folder - eTypeID = CONTENT_TYPE_X_CNT_FSYSSPECIALFOLDER; - else - // drive? -> "file:///?|/" - if (rURL.Len() == 11 - && rURL.GetChar(rURL.Len() - 2) == '|') - { - // Drives need further processing, because of - // dynamic type according to underlying volume, - // which cannot be determined here. - } - else // normal folder - eTypeID = CONTENT_TYPE_X_CNT_FSYSFOLDER; - else // file system root - eTypeID = CONTENT_TYPE_X_CNT_FSYSBOX; - else // file - { - //@@@ - } - else if (aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_HTTP) - || aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_HTTPS)) - eTypeID = CONTENT_TYPE_TEXT_HTML; - else if (aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_PRIVATE)) - { - UniString aSecondPart = rURL.GetToken(1, ':'); - aToken = aSecondPart.GetToken(0, '/'); - if (aToken.EqualsAscii(INETTYPE_URL_SUB_FACTORY)) - { - aToken = aSecondPart.GetToken(1, '/'); - if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SWRITER)) - { - aToken = aSecondPart.GetToken(2, '/'); - eTypeID = aToken.EqualsAscii(INETTYPE_URL_SSSUB_WEB) ? - CONTENT_TYPE_APP_VND_WRITER_WEB : - aToken.EqualsAscii(INETTYPE_URL_SSSUB_GLOB) ? - CONTENT_TYPE_APP_VND_WRITER_GLOBAL : - CONTENT_TYPE_APP_VND_WRITER; - } - else if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SCALC)) - eTypeID = CONTENT_TYPE_APP_VND_CALC; - else if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SDRAW)) - eTypeID = CONTENT_TYPE_APP_VND_DRAW; - else if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SIMPRESS)) - eTypeID = CONTENT_TYPE_APP_VND_IMPRESS; - else if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SCHART)) - eTypeID = CONTENT_TYPE_APP_VND_CHART; - else if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SIMAGE)) - eTypeID = CONTENT_TYPE_APP_VND_IMAGE; - else if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SMATH)) - eTypeID = CONTENT_TYPE_APP_VND_MATH; - else if (aToken.EqualsAscii(INETTYPE_URL_SSUB_FRAMESET)) - eTypeID = CONTENT_TYPE_APP_FRAMESET; - } - else if (aToken.EqualsAscii(INETTYPE_URL_SUB_HELPID)) - eTypeID = CONTENT_TYPE_APP_STARHELP; - } - else if (aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_COMPONENT)) - { - aToken = rURL.GetToken(1, ':'); // aToken now equals ss / * - aToken = aToken.GetToken(0, '/'); - if (aToken.EqualsAscii(INETTYPE_URL_SSUB_SS)) - eTypeID = rURL.SearchAscii(INETTYPE_URL_SCHED_CMB) - == STRING_NOTFOUND - && rURL.SearchAscii(INETTYPE_URL_SCHED_FORM) - == STRING_NOTFOUND ? - CONTENT_TYPE_APP_SCHEDULE : - rURL.SearchAscii(INETTYPE_URL_SCHED_TASK) - == STRING_NOTFOUND ? - CONTENT_TYPE_APP_SCHEDULE_EVT : - CONTENT_TYPE_APP_SCHEDULE_TASK; - } - else if (aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_MAILTO)) - eTypeID = CONTENT_TYPE_APP_VND_OUTTRAY; - else if (aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_MACRO)) - eTypeID = CONTENT_TYPE_APP_MACRO; - else if (aToken.EqualsIgnoreCaseAscii(INETTYPE_URL_PROT_DATA)) - { - UniString aSecondPart = rURL.GetToken(1, ':'); - aToken = aSecondPart.GetToken(0, ','); - eTypeID = GetContentType(aToken); - } - } - if (eTypeID == CONTENT_TYPE_UNKNOWN) - { - UniString aExtension; - if (GetExtensionFromURL(rURL, aExtension)) - eTypeID = GetContentType4Extension(aExtension); - } - return eTypeID; -} - -//============================================================================ -//static -bool INetContentTypes::GetExtensionFromURL(UniString const & rURL, - UniString & rExtension) -{ - xub_StrLen nSlashPos = 0; - xub_StrLen i = 0; - while (i != STRING_NOTFOUND) - { - nSlashPos = i; - i = rURL.Search('/', i + 1); - } - if (nSlashPos != 0) - { - xub_StrLen nLastDotPos = i = rURL.Search('.', nSlashPos); - while (i != STRING_NOTFOUND) - { - nLastDotPos = i; - i = rURL.Search('.', i + 1); - } - if (nLastDotPos != STRING_NOTFOUND) - rExtension = rURL.Copy(nLastDotPos + 1); - return true; - } - return false; -} - -//============================================================================ -// static -bool INetContentTypes::parse(UniString const & rMediaType, - UniString & rType, UniString & rSubType, - INetContentTypeParameterList * pParameters) -{ - sal_Unicode const * p = rMediaType.GetBuffer(); - sal_Unicode const * pEnd = p + rMediaType.Len(); - - p = INetMIME::skipLinearWhiteSpaceComment(p, pEnd); - sal_Unicode const * pToken = p; - bool bDowncase = false; - while (p != pEnd && INetMIME::isTokenChar(*p)) - { - bDowncase = bDowncase || INetMIME::isUpperCase(*p); - ++p; - } - if (p == pToken) - return false; - rType = UniString(pToken, sal::static_int_cast< xub_StrLen >(p - pToken)); - if (bDowncase) - rType.ToLowerAscii(); - - p = INetMIME::skipLinearWhiteSpaceComment(p, pEnd); - if (p == pEnd || *p++ != '/') - return false; - - p = INetMIME::skipLinearWhiteSpaceComment(p, pEnd); - pToken = p; - bDowncase = false; - while (p != pEnd && INetMIME::isTokenChar(*p)) - { - bDowncase = bDowncase || INetMIME::isUpperCase(*p); - ++p; - } - if (p == pToken) - return false; - rSubType = UniString( - pToken, sal::static_int_cast< xub_StrLen >(p - pToken)); - if (bDowncase) - rSubType.ToLowerAscii(); - - return INetMIME::scanParameters(p, pEnd, pParameters) == pEnd; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/lngmisc.cxx b/svl/source/misc/lngmisc.cxx deleted file mode 100644 index 32b08b6e1b..0000000000 --- a/svl/source/misc/lngmisc.cxx +++ /dev/null @@ -1,172 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/lngmisc.hxx> -#include <tools/solar.h> -#include <tools/string.hxx> -#include <tools/debug.hxx> -#include <rtl/ustrbuf.hxx> -#include <rtl/ustring.hxx> - -using ::rtl::OUString; -using ::rtl::OUStringBuffer; - -namespace linguistic -{ - -/////////////////////////////////////////////////////////////////////////// - -sal_Int32 GetNumControlChars( const OUString &rTxt ) -{ - sal_Int32 nCnt = 0; - sal_Int32 nLen = rTxt.getLength(); - for (sal_Int32 i = 0; i < nLen; ++i) - { - if (IsControlChar( rTxt[i] )) - ++nCnt; - } - return nCnt; -} - - -sal_Bool RemoveHyphens( OUString &rTxt ) -{ - sal_Bool bModified = sal_False; - if (HasHyphens( rTxt )) - { - String aTmp( rTxt ); - aTmp.EraseAllChars( SVT_SOFT_HYPHEN ); - aTmp.EraseAllChars( SVT_HARD_HYPHEN ); - rTxt = aTmp; - bModified = sal_True; - } - return bModified; -} - - -sal_Bool RemoveControlChars( OUString &rTxt ) -{ - sal_Bool bModified = sal_False; - sal_Int32 nCtrlChars = GetNumControlChars( rTxt ); - if (nCtrlChars) - { - sal_Int32 nLen = rTxt.getLength(); - sal_Int32 nSize = nLen - nCtrlChars; - OUStringBuffer aBuf( nSize ); - aBuf.setLength( nSize ); - sal_Int32 nCnt = 0; - for (sal_Int32 i = 0; i < nLen; ++i) - { - sal_Unicode cChar = rTxt[i]; - if (!IsControlChar( cChar )) - { - DBG_ASSERT( nCnt < nSize, "index out of range" ); - aBuf.setCharAt( nCnt++, cChar ); - } - } - DBG_ASSERT( nCnt == nSize, "wrong size" ); - rTxt = aBuf.makeStringAndClear(); - bModified = sal_True; - } - return bModified; -} - - -// non breaking field character -#define CH_TXTATR_INWORD ((sal_Char) 0x02) - -sal_Bool ReplaceControlChars( rtl::OUString &rTxt, sal_Char /*aRplcChar*/ ) -{ - // the resulting string looks like this: - // 1. non breaking field characters get removed - // 2. remaining control characters will be replaced by ' ' - - sal_Bool bModified = sal_False; - sal_Int32 nCtrlChars = GetNumControlChars( rTxt ); - if (nCtrlChars) - { - sal_Int32 nLen = rTxt.getLength(); - OUStringBuffer aBuf( nLen ); - sal_Int32 nCnt = 0; - for (sal_Int32 i = 0; i < nLen; ++i) - { - sal_Unicode cChar = rTxt[i]; - if (CH_TXTATR_INWORD != cChar) - { - if (IsControlChar( cChar )) - cChar = ' '; - DBG_ASSERT( nCnt < nLen, "index out of range" ); - aBuf.setCharAt( nCnt++, cChar ); - } - } - aBuf.setLength( nCnt ); - rTxt = aBuf.makeStringAndClear(); - bModified = sal_True; - } - return bModified; -} - - -String GetThesaurusReplaceText( const String &rText ) -{ - // The strings for synonyms returned by the thesaurus sometimes have some - // explanation text put in between '(' and ')' or a trailing '*'. - // These parts should not be put in the ReplaceEdit Text that may get - // inserted into the document. Thus we strip them from the text. - - String aText( rText ); - - xub_StrLen nPos = aText.Search( sal_Unicode('(') ); - while (STRING_NOTFOUND != nPos) - { - xub_StrLen nEnd = aText.Search( sal_Unicode(')'), nPos ); - if (STRING_NOTFOUND != nEnd) - aText.Erase( nPos, nEnd-nPos+1 ); - else - break; - nPos = aText.Search( sal_Unicode('(') ); - } - - nPos = aText.Search( sal_Unicode('*') ); - if (STRING_NOTFOUND != nPos) - aText.Erase( nPos ); - - // remove any possible remaining ' ' that may confuse the thesaurus - // when it gets called with the text - aText.EraseLeadingAndTrailingChars( sal_Unicode(' ') ); - - return aText; -} - -/////////////////////////////////////////////////////////////////////////// - -} // namespace linguistic - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/lockfilecommon.cxx b/svl/source/misc/lockfilecommon.cxx deleted file mode 100644 index 5bba1242ba..0000000000 --- a/svl/source/misc/lockfilecommon.cxx +++ /dev/null @@ -1,259 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <stdio.h> - -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/ucb/XCommandEnvironment.hpp> -#include <com/sun/star/ucb/InsertCommandArgument.hpp> -#include <com/sun/star/ucb/NameClashException.hpp> -#include <com/sun/star/io/WrongFormatException.hpp> - -#include <osl/time.h> -#include <osl/security.hxx> -#include <osl/socket.hxx> -#include <osl/file.hxx> - -#include <rtl/string.hxx> -#include <rtl/ustring.hxx> -#include <rtl/strbuf.hxx> -#include <rtl/ustrbuf.hxx> - -#include <comphelper/processfactory.hxx> - -#include <tools/urlobj.hxx> -#include <unotools/bootstrap.hxx> - -#include <ucbhelper/content.hxx> - -#include <unotools/useroptions.hxx> - -#include <salhelper/linkhelper.hxx> - -#include <svl/lockfilecommon.hxx> - -using namespace ::com::sun::star; - -namespace svt { - -// ---------------------------------------------------------------------- -LockFileCommon::LockFileCommon( const ::rtl::OUString& aOrigURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory, const ::rtl::OUString& aPrefix ) -: m_xFactory( xFactory ) -{ - if ( !m_xFactory.is() ) - m_xFactory = ::comphelper::getProcessServiceFactory(); - - INetURLObject aDocURL = ResolveLinks( INetURLObject( aOrigURL ) ); - - ::rtl::OUString aShareURLString = aDocURL.GetPartBeforeLastName(); - aShareURLString += aPrefix; - aShareURLString += aDocURL.GetName(); - aShareURLString += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "%23" ) ); // '#' - m_aURL = INetURLObject( aShareURLString ).GetMainURL( INetURLObject::NO_DECODE ); -} - -// ---------------------------------------------------------------------- -LockFileCommon::~LockFileCommon() -{ -} - -// ---------------------------------------------------------------------- -INetURLObject LockFileCommon::ResolveLinks( const INetURLObject& aDocURL ) -{ - if ( aDocURL.HasError() ) - throw lang::IllegalArgumentException(); - - ::rtl::OUString aURLToCheck = aDocURL.GetMainURL(INetURLObject::NO_DECODE); - - // there is currently no UCB functionality to resolve the symbolic links; - // since the lock files are used only for local file systems the osl - // functionality is used directly - salhelper::LinkResolver aResolver(osl_FileStatus_Mask_FileName); - osl::FileBase::RC eStatus = aResolver.fetchFileStatus(aURLToCheck); - if (eStatus == osl::FileBase::E_None) - aURLToCheck = aResolver.m_aStatus.getFileURL(); - else if (eStatus == osl::FileBase::E_MULTIHOP) - { - // do not allow too deep links - throw io::IOException(); - } - - return INetURLObject( aURLToCheck ); -} - -// ---------------------------------------------------------------------- -uno::Sequence< uno::Sequence< ::rtl::OUString > > LockFileCommon::ParseList( const uno::Sequence< sal_Int8 >& aBuffer ) -{ - sal_Int32 nCurPos = 0; - sal_Int32 nCurEntry = 0; - uno::Sequence< uno::Sequence< ::rtl::OUString > > aResult( 10 ); - - while ( nCurPos < aBuffer.getLength() ) - { - if ( nCurEntry >= aResult.getLength() ) - aResult.realloc( nCurEntry + 10 ); - aResult[nCurEntry] = ParseEntry( aBuffer, nCurPos ); - nCurEntry++; - } - - aResult.realloc( nCurEntry ); - return aResult; -} - -// ---------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > LockFileCommon::ParseEntry( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos ) -{ - uno::Sequence< ::rtl::OUString > aResult( LOCKFILE_ENTRYSIZE ); - - for ( int nInd = 0; nInd < LOCKFILE_ENTRYSIZE; nInd++ ) - { - aResult[nInd] = ParseName( aBuffer, io_nCurPos ); - if ( io_nCurPos >= aBuffer.getLength() - || ( nInd < LOCKFILE_ENTRYSIZE - 1 && aBuffer[io_nCurPos++] != ',' ) - || ( nInd == LOCKFILE_ENTRYSIZE - 1 && aBuffer[io_nCurPos++] != ';' ) ) - throw io::WrongFormatException(); - } - - return aResult; -} - -// ---------------------------------------------------------------------- -::rtl::OUString LockFileCommon::ParseName( const uno::Sequence< sal_Int8 >& aBuffer, sal_Int32& io_nCurPos ) -{ - ::rtl::OStringBuffer aResult; - sal_Bool bHaveName = sal_False; - sal_Bool bEscape = sal_False; - - while( !bHaveName ) - { - if ( io_nCurPos >= aBuffer.getLength() ) - throw io::WrongFormatException(); - - if ( bEscape ) - { - if ( aBuffer[io_nCurPos] == ',' || aBuffer[io_nCurPos] == ';' || aBuffer[io_nCurPos] == '\\' ) - aResult.append( (sal_Char)aBuffer[io_nCurPos] ); - else - throw io::WrongFormatException(); - - bEscape = sal_False; - io_nCurPos++; - } - else if ( aBuffer[io_nCurPos] == ',' || aBuffer[io_nCurPos] == ';' ) - bHaveName = sal_True; - else - { - if ( aBuffer[io_nCurPos] == '\\' ) - bEscape = sal_True; - else - aResult.append( (sal_Char)aBuffer[io_nCurPos] ); - - io_nCurPos++; - } - } - - return ::rtl::OStringToOUString( aResult.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ); -} - -// ---------------------------------------------------------------------- -::rtl::OUString LockFileCommon::EscapeCharacters( const ::rtl::OUString& aSource ) -{ - ::rtl::OUStringBuffer aBuffer; - const sal_Unicode* pStr = aSource.getStr(); - for ( sal_Int32 nInd = 0; nInd < aSource.getLength() && pStr[nInd] != 0; nInd++ ) - { - if ( pStr[nInd] == '\\' || pStr[nInd] == ';' || pStr[nInd] == ',' ) - aBuffer.append( (sal_Unicode)'\\' ); - aBuffer.append( pStr[nInd] ); - } - - return aBuffer.makeStringAndClear(); -} - -// ---------------------------------------------------------------------- -::rtl::OUString LockFileCommon::GetOOOUserName() -{ - SvtUserOptions aUserOpt; - ::rtl::OUString aName = aUserOpt.GetFirstName(); - if ( aName.getLength() ) - aName += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ); - aName += aUserOpt.GetLastName(); - - return aName; -} - -// ---------------------------------------------------------------------- -::rtl::OUString LockFileCommon::GetCurrentLocalTime() -{ - ::rtl::OUString aTime; - - TimeValue aSysTime; - if ( osl_getSystemTime( &aSysTime ) ) - { - TimeValue aLocTime; - if ( osl_getLocalTimeFromSystemTime( &aSysTime, &aLocTime ) ) - { - oslDateTime aDateTime; - if ( osl_getDateTimeFromTimeValue( &aLocTime, &aDateTime ) ) - { - char pDateTime[20]; - sprintf( pDateTime, "%02d.%02d.%4d %02d:%02d", aDateTime.Day, aDateTime.Month, aDateTime.Year, aDateTime.Hours, aDateTime.Minutes ); - aTime = ::rtl::OUString::createFromAscii( pDateTime ); - } - } - } - - return aTime; -} - -// ---------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > LockFileCommon::GenerateOwnEntry() -{ - uno::Sequence< ::rtl::OUString > aResult( LOCKFILE_ENTRYSIZE ); - - aResult[LOCKFILE_OOOUSERNAME_ID] = GetOOOUserName(); - - ::osl::Security aSecurity; - aSecurity.getUserName( aResult[LOCKFILE_SYSUSERNAME_ID] ); - - aResult[LOCKFILE_LOCALHOST_ID] = ::osl::SocketAddr::getLocalHostname(); - - aResult[LOCKFILE_EDITTIME_ID] = GetCurrentLocalTime(); - - ::utl::Bootstrap::locateUserInstallation( aResult[LOCKFILE_USERURL_ID] ); - - - return aResult; -} - -} // namespace svt - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/mediatyp.src b/svl/source/misc/mediatyp.src deleted file mode 100644 index 1d191c9d93..0000000000 --- a/svl/source/misc/mediatyp.src +++ /dev/null @@ -1,601 +0,0 @@ -/************************************************************************* - * - * 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. - * - ************************************************************************/ -//============================================================================ -// -// Internet Media Type Presentations -// -//============================================================================ - -#ifndef _SVTOOLS_HRC -#include <svl/svl.hrc> -#endif - -String STR_SVT_MIMETYPE_APP_OCTSTREAM -{ - Text [ en-US ] = "Binary file" ; -}; - -String STR_SVT_MIMETYPE_APP_PDF -{ - Text [ en-US ] = "PDF file" ; -}; - -String STR_SVT_MIMETYPE_APP_RTF -{ - Text [ en-US ] = "RTF File" ; -}; - -String STR_SVT_MIMETYPE_APP_MSWORD -{ - Text [ en-US ] = "MS-Word document" ; -}; - -String STR_SVT_MIMETYPE_APP_STARCALC -{ - Text [ en-US ] = "%PRODUCTNAME Spreadsheet" ; -}; - -String STR_SVT_MIMETYPE_APP_STARCHART -{ - Text [ en-US ] = "%PRODUCTNAME Chart" ; -}; - -String STR_SVT_MIMETYPE_APP_STARDRAW -{ - Text [ en-US ] = "%PRODUCTNAME Drawing" ; -}; - -String STR_SVT_MIMETYPE_APP_STARIMAGE -{ - Text [ en-US ] = "%PRODUCTNAME Image" ; -}; - -String STR_SVT_MIMETYPE_APP_STARMATH -{ - Text [ en-US ] = "%PRODUCTNAME Formula" ; -}; - -String STR_SVT_MIMETYPE_APP_STARWRITER -{ - Text [ en-US ] = "%PRODUCTNAME Text" ; -}; - -String STR_SVT_MIMETYPE_APP_ZIP -{ - Text [ en-US ] = "ZIP file" ; -}; - -String STR_SVT_MIMETYPE_APP_JAR -{ - Text [ en-US ] = "JAR file" ; -}; - -String STR_SVT_MIMETYPE_AUDIO_AIFF -{ - Text [ en-US ] = "Audio file" ; -}; - -String STR_SVT_MIMETYPE_AUDIO_BASIC -{ - Text [ en-US ] = "Audio file" ; -}; - -String STR_SVT_MIMETYPE_AUDIO_MIDI -{ - Text [ en-US ] = "Audio file" ; -}; - -String STR_SVT_MIMETYPE_AUDIO_VORBIS -{ - Text [ en-US ] = "Audio file" ; -}; - -String STR_SVT_MIMETYPE_AUDIO_WAV -{ - Text [ en-US ] = "Audio file" ; -}; - -String STR_SVT_MIMETYPE_AUDIO_WEBM -{ - Text [ en-US ] = "Audio file" ; -}; - -String STR_SVT_MIMETYPE_IMAGE_GIF -{ - Text [ en-US ] = "Graphics" ; -}; - -String STR_SVT_MIMETYPE_IMAGE_JPEG -{ - Text [ en-US ] = "Graphics" ; -}; - -String STR_SVT_MIMETYPE_IMAGE_PCX -{ - Text [ en-US ] = "Graphics" ; -}; - -String STR_SVT_MIMETYPE_IMAGE_BMP -{ - Text [ en-US ] = "Bitmap" ; -}; - -String STR_SVT_MIMETYPE_TEXT_HTML -{ - Text [ en-US ] = "HTML document" ; -}; - -String STR_SVT_MIMETYPE_TEXT_PLAIN -{ - Text [ en-US ] = "Text file" ; -}; - -String STR_SVT_MIMETYPE_TEXT_URL -{ - Text [ en-US ] = "Bookmark" ; -}; - -String STR_SVT_MIMETYPE_TEXT_VCARD -{ - Text [ en-US ] = "vCard file" ; -}; - -String STR_SVT_MIMETYPE_VIDEO_MSVIDEO -{ - Text [ en-US ] = "Video file" ; -}; - -String STR_SVT_MIMETYPE_VIDEO_THEORA -{ - Text [ en-US ] = "Video file" ; -}; - -String STR_SVT_MIMETYPE_VIDEO_VDO -{ - Text [ en-US ] = "Video file" ; -}; - -String STR_SVT_MIMETYPE_VIDEO_WEBM -{ - Text [ en-US ] = "Video file" ; -}; - -String STR_SVT_MIMETYPE_X_STARMAIL -{ - Text [ en-US ] = "Message" ; -}; - -String STR_SVT_MIMETYPE_X_VRML -{ - Text [ en-US ] = "VRML file" ; -}; - -String STR_SVT_MIMETYPE_APP_STARIMPRESS -{ - Text [ en-US ] = "%PRODUCTNAME Presentation" ; -}; - -String STR_SVT_MIMETYPE_APP_IMPRESSPACKED -{ - Text [ en-US ] = "%PRODUCTNAME Presentation (packed)"; -}; - -String STR_SVT_MIMETYPE_APP_STARHELP -{ - Text [ en-US ] = "%PRODUCTNAME Help" ; -}; - - -String STR_SVT_MIMETYPE_CNT_MSG -{ - Text [ en-US ] = "Message" ; -}; - -String STR_SVT_MIMETYPE_CNT_DOCUMENT -{ - Text [ en-US ] = "Document" ; -}; - -String STR_SVT_MIMETYPE_CNT_POP3BOX -{ - Text [ en-US ] = "POP3 Account" ; -}; - -String STR_SVT_MIMETYPE_CNT_IMAPBOX -{ - Text [ en-US ] = "IMAP Account" ; -}; - -String STR_SVT_MIMETYPE_CNT_IMAPFLD -{ - Text [ en-US ] = "Folder" ; -}; - -String STR_SVT_MIMETYPE_CNT_VIMBOX -{ - Text [ en-US ] = "VIM Account" ; -}; - -String STR_SVT_MIMETYPE_CNT_VIMINBOX -{ - Text [ en-US ] = "Inbox" ; -}; - -String STR_SVT_MIMETYPE_CNT_BBBOX -{ - Text [ en-US ] = "Newsgroups" ; -}; - -String STR_SVT_MIMETYPE_CNT_VIM_BB -{ - Text [ en-US ] = "Newsgroup" ; -}; - -String STR_SVT_MIMETYPE_CNT_NEWSBOX -{ - Text [ en-US ] = "News" ; -}; - -String STR_SVT_MIMETYPE_CNT_NEWSGRP -{ - Text [ en-US ] = "Group" ; -}; - -String STR_SVT_MIMETYPE_CNT_OUTBOX -{ - Text [ en-US ] = "Outbox" ; -}; - -String STR_SVT_MIMETYPE_CNT_FTPBOX -{ - Text [ en-US ] = "FTP Account" ; -}; - -String STR_SVT_MIMETYPE_CNT_FTPFLD -{ - Text [ en-US ] = "FTP Folder" ; -}; - -String STR_SVT_MIMETYPE_CNT_FTPFILE -{ - Text [ en-US ] = "FTP File" ; -}; - -String STR_SVT_MIMETYPE_CNT_FTPLINK -{ - Text [ en-US ] = "FTP Link" ; -}; - -String STR_SVT_MIMETYPE_CNT_HTTPBOX -{ - Text [ en-US ] = "HTTP" ; -}; - -String STR_SVT_MIMETYPE_CNT_FSYSBOX -{ - Text [ en-US ] = "Workplace" ; -}; - -String STR_SVT_MIMETYPE_CNT_FSYSFLD -{ - Text [ en-US ] = "Folder" ; -}; - -String STR_SVT_MIMETYPE_CNT_FSYSFILE -{ - Text [ en-US ] = "File" ; -}; - -String STR_SVT_MIMETYPE_CNT_FSYSURLFILE -{ - Text [ en-US ] = "Link" ; -}; - -String STR_SVT_MIMETYPE_CNT_PUBLBOX -{ - Text [ en-US ] = "Project" ; -}; - -String STR_SVT_MIMETYPE_CNT_SRCHBOX -{ - Text [ en-US ] = "Find" ; -}; - -String STR_SVT_MIMETYPE_CNT_SUBSCRBOX -{ - Text [ en-US ] = "Subscriptions" ; -}; - -String STR_SVT_MIMETYPE_CNT_BOOKMARK -{ - Text [ en-US ] = "Bookmark subscription" ; -}; - -String STR_SVT_MIMETYPE_CNT_CDF -{ - Text [ en-US ] = "Channel subscription" ; -}; - -String STR_SVT_MIMETYPE_CNT_CDFSUB -{ - Text [ en-US ] = "Channel subscription" ; -}; - -String STR_SVT_MIMETYPE_CNT_CDFITEM -{ - Text [ en-US ] = "Channel subscription" ; -}; - -String STR_SVT_MIMETYPE_CNT_STARCHANNEL -{ - Text [ en-US ] = "StarChannel" ; -}; - -String STR_SVT_MIMETYPE_CNT_TRASHBOX -{ - Text [ en-US ] = "Recycle Bin" ; -}; - -String STR_SVT_MIMETYPE_CNT_TRASH -{ - Text [ en-US ] = "Deleted Object" ; -}; - -String STR_SVT_MIMETYPE_CNT_REMOV_VOL -{ - Text [ en-US ] = "Local drive" ; -}; - -String STR_SVT_MIMETYPE_CNT_FIX_VOL -{ - Text [ en-US ] = "Local drive" ; -}; - -String STR_SVT_MIMETYPE_CNT_REM_VOL -{ - Text [ en-US ] = "Network connection" ; -}; - -String STR_SVT_MIMETYPE_CNT_RAM_VOL -{ - Text [ en-US ] = "RAM Disk" ; -}; - -String STR_SVT_MIMETYPE_CNT_CDROM -{ - Text [ en-US ] = "CD-ROM drive" ; -}; - -String STR_SVT_MIMETYPE_CNT_DISK_35 -{ - Text [ en-US ] = "3.5'' Disk" ; -}; - -String STR_SVT_MIMETYPE_CNT_DISK_525 -{ - Text [ en-US ] = "5.25'' Disk" ; -}; - -String STR_SVT_MIMETYPE_CNT_TAPEDRIVE -{ - Text [ en-US ] = "Tape drive" ; -}; - -String STR_SVT_MIMETYPE_APP_GAL -{ - Text [ en-US ] = "Gallery"; -}; - -String STR_SVT_MIMETYPE_APP_GAL_THEME -{ - Text [ en-US ] = "Gallery theme" ; -}; - -String STR_SVT_MIMETYPE_CNT_SEPARATOR -{ - Text = "CntMenuView-Separator" ; -}; - -String STR_SVT_MIMETYPE_APP_STARW_GLOB -{ - Text [ en-US ] = "%PRODUCTNAME Master Document" ; -}; - -String STR_SVT_MIMETYPE_APP_SDM -{ - Text [ en-US ] = "Message" ; -}; - -String STR_SVT_MIMETYPE_APP_SMD -{ - Text [ en-US ] = "Message" ; -}; - -String STR_SVT_MIMETYPE_APP_STARW_WEB -{ - Text [ en-US ] = "%PRODUCTNAME Writer/Web" ; -}; - -String STR_SVT_MIMETYPE_SCHEDULE -{ - Text [ en-US ] = "Tasks & Events" ; -}; - -String STR_SVT_MIMETYPE_SCHEDULE_EVT -{ - Text [ en-US ] = "%PRODUCTNAME Events View" ; -}; - -String STR_SVT_MIMETYPE_SCHEDULE_TASK -{ - Text [ en-US ] = "%PRODUCTNAME Task View" ; -}; - -String STR_SVT_MIMETYPE_SCHEDULE_FEVT -{ - Text [ en-US ] = "%PRODUCTNAME Event" ; -}; - -String STR_SVT_MIMETYPE_SCHEDULE_FTASK -{ - Text [ en-US ] = "%PRODUCTNAME Task" ; -}; - -String STR_SVT_MIMETYPE_FRAMESET -{ - Text [ en-US ] = "Frameset Document" ; -}; - -String STR_SVT_MIMETYPE_MACRO -{ - Text [ en-US ] = "Macro file" ; -}; - -String STR_SVT_MIMETYPE_CNT_SFSYSFOLDER -{ - Text [ en-US ] = "System folder" ; -}; - -String STR_SVT_MIMETYPE_CNT_SFSYSFILE -{ - Text [ en-US ] = "System object" ; -}; - -String STR_SVT_MIMETYPE_APP_TEMPLATE -{ - Text [ en-US ] = "%PRODUCTNAME Template"; -}; - -String STR_SVT_MIMETYPE_IMAGE_GENERIC -{ - Text [ en-US ] = "Graphics"; -}; - -String STR_SVT_MIMETYPE_APP_MSEXCEL -{ - Text [ en-US ] = "MS Excel document" ; -}; - -String STR_SVT_MIMETYPE_APP_MSEXCEL_TEMPL -{ - Text [ en-US ] = "MS Excel Template" ; -}; - -String STR_SVT_MIMETYPE_APP_MSPPOINT -{ - Text [ en-US ] = "MS PowerPoint document" ; -}; - -String STR_SVT_MIMETYPE_TEXT_VCALENDAR -{ - Text [ en-US ] = "vCalendar-file" ; -}; - -String STR_SVT_MIMETYPE_TEXT_ICALENDAR -{ - Text [ en-US ] = "iCalendar-File"; -}; - -String STR_SVT_MIMETYPE_TEXT_XMLICALENDAR -{ - Text [ en-US ] = "XML-iCalendar-File"; -}; - -String STR_SVT_MIMETYPE_TEXT_CDE_CALENDAR_APP -{ - Text [ en-US ] = "CDE-Calendar-File"; -}; - -String STR_SVT_MIMETYPE_INET_MSG_RFC822 -{ - Text [ en-US ] = "message/rfc822" ; -}; - -String STR_SVT_MIMETYPE_INET_MULTI_ALTERNATIVE -{ - Text [ en-US ] = "multipart/alternative" ; -}; - -String STR_SVT_MIMETYPE_INET_MULTI_DIGEST -{ - Text [ en-US ] = "multipart/digest" ; -}; - -String STR_SVT_MIMETYPE_INET_MULTI_PARALLEL -{ - Text [ en-US ] = "multipart/parallel" ; -}; - -String STR_SVT_MIMETYPE_INET_MULTI_RELATED -{ - Text [ en-US ] = "multipart/related" ; -}; - -String STR_SVT_MIMETYPE_INET_MULTI_MIXED -{ - Text [ en-US ] = "multipart/mixed" ; -}; - -String STR_SVT_MIMETYPE_APP_SXCALC -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Spreadsheet" ; -}; - -String STR_SVT_MIMETYPE_APP_SXCHART -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Chart" ; -}; - -String STR_SVT_MIMETYPE_APP_SXDRAW -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Drawing" ; -}; - -String STR_SVT_MIMETYPE_APP_SXMATH -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Formula" ; -}; - -String STR_SVT_MIMETYPE_APP_SXWRITER -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Text Document" ; -}; - -String STR_SVT_MIMETYPE_APP_SXIMPRESS -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Presentation" ; -}; - -String STR_SVT_MIMETYPE_APP_SXGLOBAL -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Master Document" ; -}; - -String STR_SVT_MIMETYPE_APP_SXIPACKED -{ - Text [ en-US ] = "%PRODUCTNAME %PRODUCTXMLFILEFORMATVERSION Presentation (packed)" ; -}; diff --git a/svl/source/misc/ownlist.cxx b/svl/source/misc/ownlist.cxx deleted file mode 100644 index 0c7acdf632..0000000000 --- a/svl/source/misc/ownlist.cxx +++ /dev/null @@ -1,199 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <ctype.h> -#include <stdio.h> -#include <com/sun/star/beans/PropertyValues.hpp> - -#include <svl/ownlist.hxx> - -using namespace com::sun::star; - -//========================================================================= -//============== SvCommandList ============================================ -//========================================================================= - -static String parseString(const String & rCmd, sal_uInt16 * pIndex) -{ - String result; - - if(rCmd.GetChar( *pIndex ) == '\"') { - (*pIndex) ++; - - sal_uInt16 begin = *pIndex; - - while(*pIndex < rCmd.Len() && rCmd.GetChar((*pIndex) ++) != '\"') ; - - result = String(rCmd.Copy(begin, *pIndex - begin - 1)); - } - - return result; -} - -static String parseWord(const String & rCmd, sal_uInt16 * pIndex) -{ - sal_uInt16 begin = *pIndex; - - while(*pIndex < rCmd.Len() && !isspace(rCmd.GetChar(*pIndex)) && rCmd.GetChar(*pIndex) != '=') - (*pIndex) ++; - - return String(rCmd.Copy(begin, *pIndex - begin)); -} - -static void eatSpace(const String & rCmd, sal_uInt16 * pIndex) -{ - while(*pIndex < rCmd.Len() && isspace(rCmd.GetChar(*pIndex))) - (*pIndex) ++; -} - - -//========================================================================= -sal_Bool SvCommandList::AppendCommands -( - const String & rCmd, /* Dieser Text wird in Kommandos umgesetzt */ - sal_uInt16 * pEaten /* Anzahl der Zeichen, die gelesen wurden */ -) -/* [Beschreibung] - - Es wird eine Text geparsed und die einzelnen Kommandos werden an - die Liste angeh"angt. - - [R"uckgabewert] - - sal_Bool sal_True, der Text wurde korrekt geparsed. - sal_False, der Text wurde nicht korrekt geparsed. -*/ -{ - sal_uInt16 index = 0; - while(index < rCmd.Len()) - { - - eatSpace(rCmd, &index); - String name = (rCmd.GetChar(index) == '\"') ? parseString(rCmd, &index) : parseWord(rCmd, &index); - - eatSpace(rCmd, &index); - String value; - if(index < rCmd.Len() && rCmd.GetChar(index) == '=') - { - index ++; - - eatSpace(rCmd, &index); - value = (rCmd.GetChar(index) == '\"') ? parseString(rCmd, &index) : parseWord(rCmd, &index); - } - - aCommandList.push_back( SvCommand(name, value)); - } - - *pEaten = index; - - return sal_True; -} - -//========================================================================= -String SvCommandList::GetCommands() const -/* [Beschreibung] - - Die Kommandos in der Liste werden als Text hintereinander, durch ein - Leerzeichen getrennt geschrieben. Der Text muss nicht genauso - aussehen wie der in <SvCommandList::AppendCommands()> "ubergebene. - - [R"uckgabewert] - - String Die Kommandos werden zur"uckgegeben. -*/ -{ - String aRet; - for( sal_uLong i = 0; i < aCommandList.size(); i++ ) - { - if( i != 0 ) - aRet += ' '; - SvCommand aCmd = aCommandList[ i ]; - aRet += aCmd.GetCommand(); - if( aCmd.GetArgument().Len() ) - { - aRet.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "=\"" ) ); - aRet += aCmd.GetArgument(); - aRet.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "\"" ) ); - } - } - return aRet; -} - -//========================================================================= -SvCommand & SvCommandList::Append -( - const String & rCommand, /* das Kommando */ - const String & rArg /* dasArgument des Kommandos */ -) -/* [Beschreibung] - - Es wird eine Objekt vom Typ SvCommand erzeugt und an die Liste - angeh"angt. - - [R"uckgabewert] - - SvCommand & Das erteugte Objekt wird zur"uckgegeben. -*/ -{ - aCommandList.push_back( SvCommand( rCommand, rArg ) ); - return aCommandList.back(); -} - -sal_Bool SvCommandList::FillFromSequence( const com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence ) -{ - const sal_Int32 nCount = aCommandSequence.getLength(); - String aCommand, aArg; - ::rtl::OUString aApiArg; - for( sal_Int32 nIndex=0; nIndex<nCount; nIndex++ ) - { - aCommand = aCommandSequence[nIndex].Name; - if( !( aCommandSequence[nIndex].Value >>= aApiArg ) ) - return sal_False; - aArg = aApiArg; - Append( aCommand, aArg ); - } - - return sal_True; -} - -void SvCommandList::FillSequence( com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue >& aCommandSequence ) -{ - const sal_Int32 nCount = aCommandList.size(); - aCommandSequence.realloc( nCount ); - for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) - { - aCommandSequence[nIndex].Name = aCommandList[ nIndex ].GetCommand(); - aCommandSequence[nIndex].Handle = -1; - aCommandSequence[nIndex].Value = uno::makeAny( ::rtl::OUString( aCommandList[ nIndex ].GetArgument() ) ); - aCommandSequence[nIndex].State = beans::PropertyState_DIRECT_VALUE; - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/restrictedpaths.cxx b/svl/source/misc/restrictedpaths.cxx deleted file mode 100644 index 91042677f3..0000000000 --- a/svl/source/misc/restrictedpaths.cxx +++ /dev/null @@ -1,217 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/restrictedpaths.hxx> - -#include <algorithm> -#include <osl/process.h> -#include <tools/urlobj.hxx> -#include <unotools/localfilehelper.hxx> -#include <unotools/syslocale.hxx> - -namespace svt -{ - namespace - { - // ---------------------------------------------------------------- - /** retrieves the value of an environment variable - @return <TRUE/> if and only if the retrieved string value is not empty - */ - bool lcl_getEnvironmentValue( const sal_Char* _pAsciiEnvName, ::rtl::OUString& _rValue ) - { - _rValue = ::rtl::OUString(); - ::rtl::OUString sEnvName = ::rtl::OUString::createFromAscii( _pAsciiEnvName ); - osl_getEnvironment( sEnvName.pData, &_rValue.pData ); - return _rValue.getLength() != 0; - } - - //----------------------------------------------------------------- - void lcl_convertStringListToUrls( const String& _rColonSeparatedList, ::std::vector< String >& _rTokens, bool _bFinalSlash ) - { - const sal_Unicode s_cSeparator = - #if defined(WNT) - ';' - #else - ':' - #endif - ; - xub_StrLen nTokens = _rColonSeparatedList.GetTokenCount( s_cSeparator ); - _rTokens.resize( 0 ); _rTokens.reserve( nTokens ); - for ( xub_StrLen i=0; i<nTokens; ++i ) - { - // the current token in the list - String sCurrentToken = _rColonSeparatedList.GetToken( i, s_cSeparator ); - if ( !sCurrentToken.Len() ) - continue; - - INetURLObject aCurrentURL; - - String sURL; - if ( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( sCurrentToken, sURL ) ) - aCurrentURL = INetURLObject( sURL ); - else - { - // smart URL parsing, assuming FILE protocol - aCurrentURL = INetURLObject( sCurrentToken, INET_PROT_FILE ); - } - - if ( _bFinalSlash ) - aCurrentURL.setFinalSlash( ); - else - aCurrentURL.removeFinalSlash( ); - _rTokens.push_back( aCurrentURL.GetMainURL( INetURLObject::NO_DECODE ) ); - } - } - - } - - //===================================================================== - //= CheckURLAllowed - //===================================================================== - struct CheckURLAllowed - { - protected: - #ifdef WNT - SvtSysLocale m_aSysLocale; - #endif - String m_sCheckURL; // the URL to check - bool m_bAllowParent; - public: - inline CheckURLAllowed( const String& _rCheckURL, bool bAllowParent = true ) - :m_sCheckURL( _rCheckURL ), m_bAllowParent( bAllowParent ) - { - #ifdef WNT - // on windows, assume that the relevant file systems are case insensitive, - // thus normalize the URL - m_sCheckURL = m_aSysLocale.GetCharClass().toLower( m_sCheckURL, 0, m_sCheckURL.Len() ); - #endif - } - - bool operator()( const String& _rApprovedURL ) - { - #ifdef WNT - // on windows, assume that the relevant file systems are case insensitive, - // thus normalize the URL - String sApprovedURL( m_aSysLocale.GetCharClass().toLower( _rApprovedURL, 0, _rApprovedURL.Len() ) ); - #else - String sApprovedURL( _rApprovedURL ); - #endif - - xub_StrLen nLenApproved = sApprovedURL.Len(); - xub_StrLen nLenChecked = m_sCheckURL.Len(); - - if ( nLenApproved > nLenChecked ) - { - if ( m_bAllowParent ) - { - if ( sApprovedURL.Search( m_sCheckURL ) == 0 ) - { - if ( ( m_sCheckURL.GetChar( nLenChecked - 1 ) == '/' ) - || ( sApprovedURL.GetChar( nLenChecked ) == '/' ) ) - return true; - } - } - else - { - // just a difference in final slash? - if ( ( nLenApproved == ( nLenChecked + 1 ) ) && - ( sApprovedURL.GetChar( nLenApproved - 1 ) == '/' ) ) - return true; - } - return false; - } - else if ( nLenApproved < nLenChecked ) - { - if ( m_sCheckURL.Search( sApprovedURL ) == 0 ) - { - if ( ( sApprovedURL.GetChar( nLenApproved - 1 ) == '/' ) - || ( m_sCheckURL.GetChar( nLenApproved ) == '/' ) ) - return true; - } - return false; - } - else - { - // strings have equal length - return ( sApprovedURL == m_sCheckURL ); - } - } - }; - - //===================================================================== - //= RestrictedPaths - //===================================================================== - //--------------------------------------------------------------------- - RestrictedPaths::RestrictedPaths() - :m_bFilterIsEnabled( true ) - { - ::rtl::OUString sRestrictedPathList; - if ( lcl_getEnvironmentValue( "RestrictedPath", sRestrictedPathList ) ) - // append a final slash. This ensures that when we later on check - // for unrestricted paths, we don't allow paths like "/home/user35" just because - // "/home/user3" is allowed - with the final slash, we make it "/home/user3/". - lcl_convertStringListToUrls( sRestrictedPathList, m_aUnrestrictedURLs, true ); - } - - RestrictedPaths::~RestrictedPaths() {} - - // -------------------------------------------------------------------- - bool RestrictedPaths::isUrlAllowed( const String& _rURL ) const - { - if ( m_aUnrestrictedURLs.empty() || !m_bFilterIsEnabled ) - return true; - - ::std::vector< String >::const_iterator aApprovedURL = ::std::find_if( - m_aUnrestrictedURLs.begin(), - m_aUnrestrictedURLs.end(), - CheckURLAllowed( _rURL, true ) - ); - - return ( aApprovedURL != m_aUnrestrictedURLs.end() ); - } - - // -------------------------------------------------------------------- - bool RestrictedPaths::isUrlAllowed( const String& _rURL, bool allowParents ) const - { - if ( m_aUnrestrictedURLs.empty() || !m_bFilterIsEnabled ) - return true; - - ::std::vector< String >::const_iterator aApprovedURL = ::std::find_if( - m_aUnrestrictedURLs.begin(), - m_aUnrestrictedURLs.end(), - CheckURLAllowed( _rURL, allowParents ) - ); - - return ( aApprovedURL != m_aUnrestrictedURLs.end() ); - } - -} // namespace svt - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/sharecontrolfile.cxx b/svl/source/misc/sharecontrolfile.cxx deleted file mode 100644 index 1f48354a58..0000000000 --- a/svl/source/misc/sharecontrolfile.cxx +++ /dev/null @@ -1,375 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <stdio.h> - -#include <com/sun/star/ucb/XSimpleFileAccess.hpp> -#include <com/sun/star/ucb/XCommandEnvironment.hpp> -#include <com/sun/star/ucb/XContent.hpp> -#include <com/sun/star/ucb/InsertCommandArgument.hpp> -#include <com/sun/star/ucb/InteractiveIOException.hpp> -#include <com/sun/star/io/WrongFormatException.hpp> - -#include <osl/time.h> -#include <osl/security.hxx> -#include <osl/socket.hxx> - -#include <rtl/string.hxx> -#include <rtl/ustring.hxx> -#include <rtl/strbuf.hxx> -#include <rtl/ustrbuf.hxx> - -#include <comphelper/processfactory.hxx> -#include <ucbhelper/content.hxx> - -#include <tools/urlobj.hxx> -#include <tools/stream.hxx> -#include <unotools/bootstrap.hxx> -#include <unotools/streamwrap.hxx> - -#include <unotools/useroptions.hxx> - -#include <svl/sharecontrolfile.hxx> - -using namespace ::com::sun::star; - -namespace svt { - -// ---------------------------------------------------------------------- -ShareControlFile::ShareControlFile( const ::rtl::OUString& aOrigURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory ) -: LockFileCommon( aOrigURL, xFactory, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".~sharing." ) ) ) -{ - OpenStream(); - - if ( !IsValid() ) - throw io::NotConnectedException(); -} - -// ---------------------------------------------------------------------- -ShareControlFile::~ShareControlFile() -{ - try - { - Close(); - } - catch( uno::Exception& ) - {} -} - -// ---------------------------------------------------------------------- -void ShareControlFile::OpenStream() -{ - // if it is called outside of constructor the mutex must be locked already - - if ( !m_xStream.is() && m_aURL.getLength() ) - { - uno::Reference< ucb::XCommandEnvironment > xDummyEnv; - ::ucbhelper::Content aContent = ::ucbhelper::Content( m_aURL, xDummyEnv ); - - uno::Reference< ucb::XContentIdentifier > xContId( aContent.get().is() ? aContent.get()->getIdentifier() : 0 ); - if ( !xContId.is() || !xContId->getContentProviderScheme().equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "file" ) ) ) ) - throw io::IOException(); // the implementation supports only local files for now - - uno::Reference< io::XStream > xStream; - - // Currently the locking of the original document is intended to be used. - // That means that the shared file should be accessed only when the original document is locked and only by user who has locked the document. - // TODO/LATER: should the own file locking be used? - - try - { - xStream = aContent.openWriteableStreamNoLock(); - } - catch ( ucb::InteractiveIOException const & e ) - { - if ( e.Code == ucb::IOErrorCode_NOT_EXISTING ) - { - // Create file... - SvMemoryStream aStream(0,0); - uno::Reference< io::XInputStream > xInput( new ::utl::OInputStreamWrapper( aStream ) ); - ucb::InsertCommandArgument aInsertArg; - aInsertArg.Data = xInput; - aInsertArg.ReplaceExisting = sal_False; - aContent.executeCommand( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("insert")), uno::makeAny( aInsertArg ) ); - - // try to let the file be hidden if possible - try { - aContent.setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "IsHidden" ) ), uno::makeAny( sal_True ) ); - } catch( uno::Exception& ) {} - - // Try to open one more time - xStream = aContent.openWriteableStreamNoLock(); - } - else - throw; - } - - m_xSeekable.set( xStream, uno::UNO_QUERY_THROW ); - m_xInputStream.set( xStream->getInputStream(), uno::UNO_QUERY_THROW ); - m_xOutputStream.set( xStream->getOutputStream(), uno::UNO_QUERY_THROW ); - m_xTruncate.set( m_xOutputStream, uno::UNO_QUERY_THROW ); - m_xStream = xStream; - } -} - -// ---------------------------------------------------------------------- -void ShareControlFile::Close() -{ - // if it is called outside of destructor the mutex must be locked - - if ( m_xStream.is() ) - { - try - { - if ( m_xInputStream.is() ) - m_xInputStream->closeInput(); - if ( m_xOutputStream.is() ) - m_xOutputStream->closeOutput(); - } - catch( uno::Exception& ) - {} - - m_xStream = uno::Reference< io::XStream >(); - m_xInputStream = uno::Reference< io::XInputStream >(); - m_xOutputStream = uno::Reference< io::XOutputStream >(); - m_xSeekable = uno::Reference< io::XSeekable >(); - m_xTruncate = uno::Reference< io::XTruncate >(); - m_aUsersData.realloc( 0 ); - } -} - -// ---------------------------------------------------------------------- -uno::Sequence< uno::Sequence< ::rtl::OUString > > ShareControlFile::GetUsersData() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !IsValid() ) - throw io::NotConnectedException(); - - if ( !m_aUsersData.getLength() ) - { - sal_Int64 nLength = m_xSeekable->getLength(); - if ( nLength > SAL_MAX_INT32 ) - throw uno::RuntimeException(); - - uno::Sequence< sal_Int8 > aBuffer( (sal_Int32)nLength ); - m_xSeekable->seek( 0 ); - - sal_Int32 nRead = m_xInputStream->readBytes( aBuffer, (sal_Int32)nLength ); - nLength -= nRead; - while ( nLength > 0 ) - { - uno::Sequence< sal_Int8 > aTmpBuf( (sal_Int32)nLength ); - nRead = m_xInputStream->readBytes( aTmpBuf, (sal_Int32)nLength ); - if ( nRead > nLength ) - throw uno::RuntimeException(); - - for ( sal_Int32 nInd = 0; nInd < nRead; nInd++ ) - aBuffer[aBuffer.getLength() - (sal_Int32)nLength + nInd] = aTmpBuf[nInd]; - nLength -= nRead; - } - - m_aUsersData = ParseList( aBuffer ); - } - - return m_aUsersData; -} - -// ---------------------------------------------------------------------- -void ShareControlFile::SetUsersDataAndStore( const uno::Sequence< uno::Sequence< ::rtl::OUString > >& aUsersData ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !IsValid() ) - throw io::NotConnectedException(); - - if ( !m_xTruncate.is() || !m_xOutputStream.is() || !m_xSeekable.is() ) - throw uno::RuntimeException(); - - m_xTruncate->truncate(); - m_xSeekable->seek( 0 ); - - ::rtl::OUStringBuffer aBuffer; - for ( sal_Int32 nInd = 0; nInd < aUsersData.getLength(); nInd++ ) - { - if ( aUsersData[nInd].getLength() != SHARED_ENTRYSIZE ) - throw lang::IllegalArgumentException(); - - for ( sal_Int32 nEntryInd = 0; nEntryInd < SHARED_ENTRYSIZE; nEntryInd++ ) - { - aBuffer.append( EscapeCharacters( aUsersData[nInd][nEntryInd] ) ); - if ( nEntryInd < SHARED_ENTRYSIZE - 1 ) - aBuffer.append( (sal_Unicode)',' ); - else - aBuffer.append( (sal_Unicode)';' ); - } - } - - ::rtl::OString aStringData( ::rtl::OUStringToOString( aBuffer.makeStringAndClear(), RTL_TEXTENCODING_UTF8 ) ); - uno::Sequence< sal_Int8 > aData( (sal_Int8*)aStringData.getStr(), aStringData.getLength() ); - m_xOutputStream->writeBytes( aData ); - m_aUsersData = aUsersData; -} - -// ---------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > ShareControlFile::InsertOwnEntry() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !IsValid() ) - throw io::NotConnectedException(); - - GetUsersData(); - uno::Sequence< ::uno::Sequence< ::rtl::OUString > > aNewData( m_aUsersData.getLength() + 1 ); - uno::Sequence< ::rtl::OUString > aNewEntry = GenerateOwnEntry(); - - sal_Bool bExists = sal_False; - sal_Int32 nNewInd = 0; - for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); nInd++ ) - { - if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE ) - { - if ( m_aUsersData[nInd][SHARED_LOCALHOST_ID] == aNewEntry[SHARED_LOCALHOST_ID] - && m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] == aNewEntry[SHARED_SYSUSERNAME_ID] - && m_aUsersData[nInd][SHARED_USERURL_ID] == aNewEntry[SHARED_USERURL_ID] ) - { - if ( !bExists ) - { - aNewData[nNewInd] = aNewEntry; - bExists = sal_True; - } - } - else - { - aNewData[nNewInd] = m_aUsersData[nInd]; - } - - nNewInd++; - } - } - - if ( !bExists ) - aNewData[nNewInd++] = aNewEntry; - - aNewData.realloc( nNewInd ); - SetUsersDataAndStore( aNewData ); - - return aNewEntry; -} - -// ---------------------------------------------------------------------- -bool ShareControlFile::HasOwnEntry() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !IsValid() ) - { - throw io::NotConnectedException(); - } - - GetUsersData(); - uno::Sequence< ::rtl::OUString > aEntry = GenerateOwnEntry(); - - for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); ++nInd ) - { - if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE && - m_aUsersData[nInd][SHARED_LOCALHOST_ID] == aEntry[SHARED_LOCALHOST_ID] && - m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] == aEntry[SHARED_SYSUSERNAME_ID] && - m_aUsersData[nInd][SHARED_USERURL_ID] == aEntry[SHARED_USERURL_ID] ) - { - return true; - } - } - - return false; -} - -// ---------------------------------------------------------------------- -void ShareControlFile::RemoveEntry( const uno::Sequence< ::rtl::OUString >& aArgEntry ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !IsValid() ) - throw io::NotConnectedException(); - - GetUsersData(); - - uno::Sequence< ::rtl::OUString > aEntry = aArgEntry; - if ( aEntry.getLength() != SHARED_ENTRYSIZE ) - aEntry = GenerateOwnEntry(); - - uno::Sequence< ::uno::Sequence< ::rtl::OUString > > aNewData( m_aUsersData.getLength() + 1 ); - - sal_Int32 nNewInd = 0; - for ( sal_Int32 nInd = 0; nInd < m_aUsersData.getLength(); nInd++ ) - { - if ( m_aUsersData[nInd].getLength() == SHARED_ENTRYSIZE ) - { - if ( m_aUsersData[nInd][SHARED_LOCALHOST_ID] != aEntry[SHARED_LOCALHOST_ID] - || m_aUsersData[nInd][SHARED_SYSUSERNAME_ID] != aEntry[SHARED_SYSUSERNAME_ID] - || m_aUsersData[nInd][SHARED_USERURL_ID] != aEntry[SHARED_USERURL_ID] ) - { - aNewData[nNewInd] = m_aUsersData[nInd]; - nNewInd++; - } - } - } - - aNewData.realloc( nNewInd ); - SetUsersDataAndStore( aNewData ); - - if ( !nNewInd ) - { - // try to remove the file if it is empty - RemoveFile(); - } -} - -// ---------------------------------------------------------------------- -void ShareControlFile::RemoveFile() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( !IsValid() ) - throw io::NotConnectedException(); - - Close(); - - uno::Reference< lang::XMultiServiceFactory > xFactory = ::comphelper::getProcessServiceFactory(); - uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xSimpleFileAccess( - xFactory->createInstance( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.SimpleFileAccess")) ), - uno::UNO_QUERY_THROW ); - xSimpleFileAccess->kill( m_aURL ); -} - -} // namespace svt - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/strmadpt.cxx b/svl/source/misc/strmadpt.cxx deleted file mode 100644 index 4b90d120a1..0000000000 --- a/svl/source/misc/strmadpt.cxx +++ /dev/null @@ -1,1066 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <functional> // needed under Solaris when including <algorithm>... - -#include <algorithm> -#include <limits> -#include <set> -#include <rtl/alloc.h> -#include <rtl/memory.h> -#include <svl/instrm.hxx> -#include <svl/outstrm.hxx> -#include <svl/strmadpt.hxx> - -using namespace com::sun::star; - -//============================================================================ -class SvDataPipe_Impl -{ -public: - enum SeekResult { SEEK_BEFORE_MARKED, SEEK_OK, SEEK_PAST_END }; - -private: - struct Page - { - Page * m_pPrev; - Page * m_pNext; - sal_Int8 * m_pStart; - sal_Int8 * m_pRead; - sal_Int8 * m_pEnd; - sal_uInt32 m_nOffset; - sal_Int8 m_aBuffer[1]; - }; - - std::multiset< sal_uInt32 > m_aMarks; - Page * m_pFirstPage; - Page * m_pReadPage; - Page * m_pWritePage; - sal_Int8 * m_pReadBuffer; - sal_uInt32 m_nReadBufferSize; - sal_uInt32 m_nReadBufferFilled; - sal_uInt32 m_nPageSize; - sal_uInt32 m_nMinPages; - sal_uInt32 m_nMaxPages; - sal_uInt32 m_nPages; - bool m_bEOF; - - bool remove(Page * pPage); - -public: - inline SvDataPipe_Impl(sal_uInt32 nThePageSize = 1000, - sal_uInt32 nTheMinPages = 100, - sal_uInt32 nTheMaxPages - = std::numeric_limits< sal_uInt32 >::max()); - - ~SvDataPipe_Impl(); - - inline void setReadBuffer(sal_Int8 * pBuffer, sal_uInt32 nSize); - - sal_uInt32 read(); - - void clearReadBuffer() { m_pReadBuffer = 0; } - - sal_uInt32 write(sal_Int8 const * pBuffer, sal_uInt32 nSize); - - void setEOF() { m_bEOF = true; } - - inline bool isEOF() const; - - bool addMark(sal_uInt32 nPosition); - bool removeMark(sal_uInt32 nPosition); - - inline sal_uInt32 getReadPosition() const; - - SeekResult setReadPosition(sal_uInt32 nPosition); -}; - -SvDataPipe_Impl::SvDataPipe_Impl(sal_uInt32 nThePageSize, - sal_uInt32 nTheMinPages, - sal_uInt32 nTheMaxPages): - m_pFirstPage(0), - m_pReadPage(0), - m_pWritePage(0), - m_pReadBuffer(0), - m_nPageSize(std::min< sal_uInt32 >( - std::max< sal_uInt32 >(nThePageSize, sal_uInt32(1)), - sal_uInt32(std::numeric_limits< sal_uInt32 >::max() - - sizeof (Page) + 1))), - m_nMinPages(std::max< sal_uInt32 >(nTheMinPages, sal_uInt32(1))), - m_nMaxPages(std::max< sal_uInt32 >(nTheMaxPages, sal_uInt32(1))), - m_nPages(0), - m_bEOF(false) -{} - -inline void SvDataPipe_Impl::setReadBuffer(sal_Int8 * pBuffer, - sal_uInt32 nSize) -{ - m_pReadBuffer = pBuffer; - m_nReadBufferSize = nSize; - m_nReadBufferFilled = 0; -} - -inline bool SvDataPipe_Impl::isEOF() const -{ - return m_bEOF && m_pReadPage == m_pWritePage - && (!m_pReadPage || m_pReadPage->m_pRead == m_pReadPage->m_pEnd); -} - -inline sal_uInt32 SvDataPipe_Impl::getReadPosition() const -{ - return m_pReadPage == 0 ? 0 : - m_pReadPage->m_nOffset - + (m_pReadPage->m_pRead - - m_pReadPage->m_aBuffer); -} - -//============================================================================ -// -// SvOutputStreamOpenLockBytes -// -//============================================================================ - -TYPEINIT1(SvOutputStreamOpenLockBytes, SvOpenLockBytes) - -//============================================================================ -// virtual -ErrCode SvOutputStreamOpenLockBytes::ReadAt(sal_uLong, void *, sal_uLong, sal_uLong *) - const -{ - return ERRCODE_IO_CANTREAD; -} - -//============================================================================ -// virtual -ErrCode SvOutputStreamOpenLockBytes::WriteAt(sal_uLong nPos, void const * pBuffer, - sal_uLong nCount, sal_uLong * pWritten) -{ - if (nPos != m_nPosition) - return ERRCODE_IO_CANTWRITE; - return FillAppend(pBuffer, nCount, pWritten); -} - -//============================================================================ -// virtual -ErrCode SvOutputStreamOpenLockBytes::Flush() const -{ - if (!m_xOutputStream.is()) - return ERRCODE_IO_CANTWRITE; - try - { - m_xOutputStream->flush(); - } - catch (const io::IOException&) - { - return ERRCODE_IO_CANTWRITE; - } - return ERRCODE_NONE; -} - -//============================================================================ -// virtual -ErrCode SvOutputStreamOpenLockBytes::SetSize(sal_uLong) -{ - return ERRCODE_IO_NOTSUPPORTED; -} - -//============================================================================ -// virtual -ErrCode SvOutputStreamOpenLockBytes::Stat(SvLockBytesStat * pStat, - SvLockBytesStatFlag) const -{ - if (pStat) - pStat->nSize = m_nPosition; - return ERRCODE_NONE; -} - -//============================================================================ -// virtual -ErrCode SvOutputStreamOpenLockBytes::FillAppend(void const * pBuffer, - sal_uLong nCount, - sal_uLong * pWritten) -{ - if (!m_xOutputStream.is()) - return ERRCODE_IO_CANTWRITE; - if (nCount > 0 - && nCount > std::numeric_limits< sal_uLong >::max() - m_nPosition) - { - nCount = std::numeric_limits< sal_uLong >::max() - m_nPosition; - if (nCount == 0) - return ERRCODE_IO_CANTWRITE; - } - try - { - m_xOutputStream-> - writeBytes(uno::Sequence< sal_Int8 >( - static_cast< sal_Int8 const * >(pBuffer), nCount)); - } - catch (const io::IOException&) - { - return ERRCODE_IO_CANTWRITE; - } - m_nPosition += nCount; - if (pWritten) - *pWritten = nCount; - return ERRCODE_NONE; -} - -//============================================================================ -// virtual -sal_uLong SvOutputStreamOpenLockBytes::Tell() const -{ - return m_nPosition; -} - -//============================================================================ -// virtual -sal_uLong SvOutputStreamOpenLockBytes::Seek(sal_uLong) -{ - return m_nPosition; -} - -//============================================================================ -// virtual -void SvOutputStreamOpenLockBytes::Terminate() -{ - if (m_xOutputStream.is()) - { - try - { - m_xOutputStream->closeOutput(); - } - catch (const io::IOException&) - { - } - } -} - -//============================================================================ -// -// SvLockBytesInputStream -// -//============================================================================ - -// virtual -uno::Any SAL_CALL SvLockBytesInputStream::queryInterface(uno::Type const & - rType) - throw (uno::RuntimeException) -{ - uno::Any - aReturn(cppu::queryInterface(rType, - static_cast< io::XInputStream * >(this), - static_cast< io::XSeekable * >(this))); - return aReturn.hasValue() ? aReturn : OWeakObject::queryInterface(rType); -} - -//============================================================================ -// virtual -void SAL_CALL SvLockBytesInputStream::acquire() throw () -{ - OWeakObject::acquire(); -} - -//============================================================================ -// virtual -void SAL_CALL SvLockBytesInputStream::release() throw () -{ - OWeakObject::release(); -} - -//============================================================================ -// virtual -sal_Int32 SAL_CALL -SvLockBytesInputStream::readBytes(uno::Sequence< sal_Int8 > & rData, - sal_Int32 nBytesToRead) - throw (io::IOException, uno::RuntimeException) -{ - OSL_ASSERT(m_nPosition >= 0); - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - if ( - nBytesToRead < 0 || - ( - static_cast<sal_uInt64>(m_nPosition) > SAL_MAX_SIZE && - nBytesToRead > 0 - ) - ) - { - throw io::IOException(); - } - rData.realloc(nBytesToRead); - sal_Int32 nSize = 0; - while (nSize < nBytesToRead) - { - sal_Size nCount; - ErrCode nError = m_xLockBytes->ReadAt(static_cast<sal_Size>( - m_nPosition), - rData.getArray() + nSize, - nBytesToRead - nSize, &nCount); - if (nError != ERRCODE_NONE && nError != ERRCODE_IO_PENDING) - throw io::IOException(); - m_nPosition += nCount; - nSize += nCount; - if (nError == ERRCODE_NONE && nCount == 0) - break; - } - rData.realloc(nSize); - return nSize; -} - -//============================================================================ -// virtual -sal_Int32 SAL_CALL -SvLockBytesInputStream::readSomeBytes(uno::Sequence< sal_Int8 > & rData, - sal_Int32 nMaxBytesToRead) - throw (io::IOException, uno::RuntimeException) -{ - OSL_ASSERT(m_nPosition >= 0); - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - if (static_cast<sal_uInt64>(m_nPosition) > SAL_MAX_SIZE - && nMaxBytesToRead > 0) - throw io::IOException(); - rData.realloc(nMaxBytesToRead); - sal_Size nCount = 0; - if (nMaxBytesToRead > 0) - { - ErrCode nError; - do - { - nError = m_xLockBytes->ReadAt(static_cast<sal_Size>(m_nPosition), - rData.getArray(), - nMaxBytesToRead < 0 ? - 0 : nMaxBytesToRead, - &nCount); - if (nError != ERRCODE_NONE && nError != ERRCODE_IO_PENDING) - throw io::IOException(); - m_nPosition += nCount; - } - while (nCount == 0 && nError == ERRCODE_IO_PENDING); - } - rData.realloc(sal_Int32(nCount)); - return sal_Int32(nCount); -} - -//============================================================================ -// virtual -void SAL_CALL SvLockBytesInputStream::skipBytes(sal_Int32 nBytesToSkip) - throw (io::IOException, uno::RuntimeException) -{ - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - if (nBytesToSkip < 0) - throw io::IOException(); - if (nBytesToSkip > SAL_MAX_INT64 - m_nPosition) - throw io::BufferSizeExceededException(); - m_nPosition += nBytesToSkip; -} - -//============================================================================ -// virtual -sal_Int32 SAL_CALL SvLockBytesInputStream::available() - throw (io::IOException, uno::RuntimeException) -{ - OSL_ASSERT(m_nPosition >= 0); - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - SvLockBytesStat aStat; - if (m_xLockBytes->Stat(&aStat, SVSTATFLAG_DEFAULT) != ERRCODE_NONE) - throw io::IOException(); - return aStat.nSize <= static_cast<sal_uInt64>(m_nPosition) ? - 0 : - static_cast<sal_Size>(aStat.nSize - m_nPosition) <= - static_cast<sal_uInt32>(SAL_MAX_INT32) ? - static_cast<sal_Int32>(aStat.nSize - m_nPosition) : - SAL_MAX_INT32; -} - -//============================================================================ -// virtual -void SAL_CALL SvLockBytesInputStream::closeInput() - throw (io::IOException, uno::RuntimeException) -{ - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - m_xLockBytes = 0; -} - -//============================================================================ -// virtual -void SAL_CALL SvLockBytesInputStream::seek(sal_Int64 nLocation) - throw (lang::IllegalArgumentException, io::IOException, - uno::RuntimeException) -{ - if (nLocation < 0) - throw lang::IllegalArgumentException(); - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - m_nPosition = nLocation; -} - -//============================================================================ -// virtual -sal_Int64 SAL_CALL SvLockBytesInputStream::getPosition() - throw (io::IOException, uno::RuntimeException) -{ - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - return m_nPosition; -} - -//============================================================================ -// virtual -sal_Int64 SAL_CALL SvLockBytesInputStream::getLength() - throw (io::IOException, uno::RuntimeException) -{ - if (!m_xLockBytes.Is()) - throw io::NotConnectedException(); - SvLockBytesStat aStat; - if (m_xLockBytes->Stat(&aStat, SVSTATFLAG_DEFAULT) != ERRCODE_NONE) - throw io::IOException(); -#if SAL_TYPES_SIZEOFPOINTER > 4 // avoid warnings if sal_Size < sal_Int64 - if (aStat.nSize > static_cast<sal_uInt64>(SAL_MAX_INT64)) - throw io::IOException(); -#endif - return aStat.nSize; -} - -//============================================================================ -// -// SvInputStream -// -//============================================================================ - -bool SvInputStream::open() -{ - if (GetError() != ERRCODE_NONE) - return false; - if (!(m_xSeekable.is() || m_pPipe)) - { - if (!m_xStream.is()) - { - SetError(ERRCODE_IO_INVALIDDEVICE); - return false; - } - m_xSeekable - = uno::Reference< io::XSeekable >(m_xStream, uno::UNO_QUERY); - if (!m_xSeekable.is()) - m_pPipe = new SvDataPipe_Impl; - } - return true; -} - -//============================================================================ -// virtual -sal_uLong SvInputStream::GetData(void * pData, sal_uLong nSize) -{ - if (!open()) - { - SetError(ERRCODE_IO_CANTREAD); - return 0; - } - sal_uInt32 nRead = 0; - if (m_xSeekable.is()) - { - if (m_nSeekedFrom != STREAM_SEEK_TO_END) - { - try - { - m_xSeekable->seek(m_nSeekedFrom); - } - catch (const io::IOException&) - { - SetError(ERRCODE_IO_CANTREAD); - return 0; - } - m_nSeekedFrom = STREAM_SEEK_TO_END; - } - for (;;) - { - sal_Int32 nRemain - = sal_Int32( - std::min(sal_uLong(nSize - nRead), - sal_uLong(std::numeric_limits< sal_Int32 >::max()))); - if (nRemain == 0) - break; - uno::Sequence< sal_Int8 > aBuffer; - sal_Int32 nCount; - try - { - nCount = m_xStream->readBytes(aBuffer, nRemain); - } - catch (const io::IOException&) - { - SetError(ERRCODE_IO_CANTREAD); - return nRead; - } - rtl_copyMemory(static_cast< sal_Int8 * >(pData) + nRead, - aBuffer.getConstArray(), sal_uInt32(nCount)); - nRead += nCount; - if (nCount < nRemain) - break; - } - } - else - { - if (m_nSeekedFrom != STREAM_SEEK_TO_END) - { - SetError(ERRCODE_IO_CANTREAD); - return 0; - } - m_pPipe->setReadBuffer(static_cast< sal_Int8 * >(pData), nSize); - nRead = m_pPipe->read(); - if (nRead < nSize && !m_pPipe->isEOF()) - for (;;) - { - sal_Int32 nRemain - = sal_Int32( - std::min( - sal_uLong(nSize - nRead), - sal_uLong(std::numeric_limits< sal_Int32 >::max()))); - if (nRemain == 0) - break; - uno::Sequence< sal_Int8 > aBuffer; - sal_Int32 nCount; - try - { - nCount = m_xStream->readBytes(aBuffer, nRemain); - } - catch (const io::IOException&) - { - SetError(ERRCODE_IO_CANTREAD); - break; - } - m_pPipe->write(aBuffer.getConstArray(), sal_uInt32(nCount)); - nRead += m_pPipe->read(); - if (nCount < nRemain) - { - m_xStream->closeInput(); - m_pPipe->setEOF(); - break; - } - } - m_pPipe->clearReadBuffer(); - } - return nRead; -} - -//============================================================================ -// virtual -sal_uLong SvInputStream::PutData(void const *, sal_uLong) -{ - SetError(ERRCODE_IO_NOTSUPPORTED); - return 0; -} - -//============================================================================ -// virtual -void SvInputStream::FlushData() -{} - -//============================================================================ -// virtual -sal_uLong SvInputStream::SeekPos(sal_uLong nPos) -{ - if (open()) - { - if (nPos == STREAM_SEEK_TO_END) - { - if (m_nSeekedFrom == STREAM_SEEK_TO_END) - { - if (m_xSeekable.is()) - try - { - sal_Int64 nLength = m_xSeekable->getLength(); - OSL_ASSERT(nLength >= 0); - if (static_cast<sal_uInt64>(nLength) - < STREAM_SEEK_TO_END) - { - m_nSeekedFrom = Tell(); - return sal_uLong(nLength); - } - } - catch (const io::IOException&) - { - } - else - return Tell(); //@@@ - } - else - return Tell(); - } - else if (nPos == m_nSeekedFrom) - { - m_nSeekedFrom = STREAM_SEEK_TO_END; - return nPos; - } - else if (m_xSeekable.is()) - { - try - { - m_xSeekable->seek(nPos); - m_nSeekedFrom = STREAM_SEEK_TO_END; - return nPos; - } - catch (const io::IOException&) - { - } - } - else if (m_pPipe->setReadPosition(nPos) == SvDataPipe_Impl::SEEK_OK) - { - m_nSeekedFrom = STREAM_SEEK_TO_END; - return nPos; - } - } - SetError(ERRCODE_IO_CANTSEEK); - return Tell(); -} - -//============================================================================ -// virtual -void SvInputStream::SetSize(sal_uLong) -{ - SetError(ERRCODE_IO_NOTSUPPORTED); -} - -//============================================================================ -SvInputStream::SvInputStream( - com::sun::star::uno::Reference< com::sun::star::io::XInputStream > - const & - rTheStream): - m_xStream(rTheStream), - m_pPipe(0), - m_nSeekedFrom(STREAM_SEEK_TO_END) -{ - SetBufferSize(0); -} - -//============================================================================ -// virtual -SvInputStream::~SvInputStream() -{ - if (m_xStream.is()) - { - try - { - m_xStream->closeInput(); - } - catch (const io::IOException&) - { - } - } - delete m_pPipe; -} - -//============================================================================ -// virtual -sal_uInt16 SvInputStream::IsA() const -{ - return 0; -} - -//============================================================================ -// virtual -void SvInputStream::AddMark(sal_uLong nPos) -{ - if (open() && m_pPipe) - m_pPipe->addMark(nPos); -} - -//============================================================================ -// virtual -void SvInputStream::RemoveMark(sal_uLong nPos) -{ - if (open() && m_pPipe) - m_pPipe->removeMark(nPos); -} - -//============================================================================ -// -// SvOutputStream -// -//============================================================================ - -// virtual -sal_uLong SvOutputStream::GetData(void *, sal_uLong) -{ - SetError(ERRCODE_IO_NOTSUPPORTED); - return 0; -} - -//============================================================================ -// virtual -sal_uLong SvOutputStream::PutData(void const * pData, sal_uLong nSize) -{ - if (!m_xStream.is()) - { - SetError(ERRCODE_IO_CANTWRITE); - return 0; - } - sal_uLong nWritten = 0; - for (;;) - { - sal_Int32 nRemain - = sal_Int32( - std::min(sal_uLong(nSize - nWritten), - sal_uLong(std::numeric_limits< sal_Int32 >::max()))); - if (nRemain == 0) - break; - try - { - m_xStream->writeBytes(uno::Sequence< sal_Int8 >( - static_cast<const sal_Int8 * >(pData) - + nWritten, - nRemain)); - } - catch (const io::IOException&) - { - SetError(ERRCODE_IO_CANTWRITE); - break; - } - nWritten += nRemain; - } - return nWritten; -} - -//============================================================================ -// virtual -sal_uLong SvOutputStream::SeekPos(sal_uLong) -{ - SetError(ERRCODE_IO_NOTSUPPORTED); - return 0; -} - -//============================================================================ -// virtual -void SvOutputStream::FlushData() -{ - if (!m_xStream.is()) - { - SetError(ERRCODE_IO_INVALIDDEVICE); - return; - } - try - { - m_xStream->flush(); - } - catch (const io::IOException&) - { - } -} - -//============================================================================ -// virtual -void SvOutputStream::SetSize(sal_uLong) -{ - SetError(ERRCODE_IO_NOTSUPPORTED); -} - -//============================================================================ -SvOutputStream::SvOutputStream(uno::Reference< io::XOutputStream > const & - rTheStream): - m_xStream(rTheStream) -{ - SetBufferSize(0); -} - -//============================================================================ -// virtual -SvOutputStream::~SvOutputStream() -{ - if (m_xStream.is()) - { - try - { - m_xStream->closeOutput(); - } - catch (const io::IOException&) - { - } - } -} - -//============================================================================ -// virtual -sal_uInt16 SvOutputStream::IsA() const -{ - return 0; -} - -//============================================================================ -// -// SvDataPipe_Impl -// -//============================================================================ - -bool SvDataPipe_Impl::remove(Page * pPage) -{ - if ( - pPage != m_pFirstPage || - m_pReadPage == m_pFirstPage || - ( - !m_aMarks.empty() && - *m_aMarks.begin() < m_pFirstPage->m_nOffset + m_nPageSize - ) - ) - { - return false; - } - - m_pFirstPage = m_pFirstPage->m_pNext; - - if (m_nPages <= m_nMinPages) - return true; - - pPage->m_pPrev->m_pNext = pPage->m_pNext; - pPage->m_pNext->m_pPrev = pPage->m_pPrev; - rtl_freeMemory(pPage); - --m_nPages; - - return true; -} - -//============================================================================ -SvDataPipe_Impl::~SvDataPipe_Impl() -{ - if (m_pFirstPage != 0) - for (Page * pPage = m_pFirstPage;;) - { - Page * pNext = pPage->m_pNext; - rtl_freeMemory(pPage); - if (pNext == m_pFirstPage) - break; - pPage = pNext; - } -} - -//============================================================================ -sal_uInt32 SvDataPipe_Impl::read() -{ - if (m_pReadBuffer == 0 || m_nReadBufferSize == 0 || m_pReadPage == 0) - return 0; - - sal_uInt32 nSize = m_nReadBufferSize; - sal_uInt32 nRemain = m_nReadBufferSize - m_nReadBufferFilled; - - m_pReadBuffer += m_nReadBufferFilled; - m_nReadBufferSize -= m_nReadBufferFilled; - m_nReadBufferFilled = 0; - - while (nRemain > 0) - { - sal_uInt32 nBlock = std::min(sal_uInt32(m_pReadPage->m_pEnd - - m_pReadPage->m_pRead), - nRemain); - rtl_copyMemory(m_pReadBuffer, m_pReadPage->m_pRead, nBlock); - m_pReadPage->m_pRead += nBlock; - m_pReadBuffer += nBlock; - m_nReadBufferSize -= nBlock; - m_nReadBufferFilled = 0; - nRemain -= nBlock; - - if (m_pReadPage == m_pWritePage) - break; - - if (m_pReadPage->m_pRead == m_pReadPage->m_pEnd) - { - Page * pRemove = m_pReadPage; - m_pReadPage = pRemove->m_pNext; - remove(pRemove); - } - } - - return nSize - nRemain; -} - -//============================================================================ -sal_uInt32 SvDataPipe_Impl::write(sal_Int8 const * pBuffer, sal_uInt32 nSize) -{ - if (nSize == 0) - return 0; - - if (m_pWritePage == 0) - { - m_pFirstPage - = static_cast< Page * >(rtl_allocateMemory(sizeof (Page) - + m_nPageSize - - 1)); - m_pFirstPage->m_pPrev = m_pFirstPage; - m_pFirstPage->m_pNext = m_pFirstPage; - m_pFirstPage->m_pStart = m_pFirstPage->m_aBuffer; - m_pFirstPage->m_pRead = m_pFirstPage->m_aBuffer; - m_pFirstPage->m_pEnd = m_pFirstPage->m_aBuffer; - m_pFirstPage->m_nOffset = 0; - m_pReadPage = m_pFirstPage; - m_pWritePage = m_pFirstPage; - ++m_nPages; - } - - sal_uInt32 nRemain = nSize; - - if (m_pReadBuffer != 0 && m_pReadPage == m_pWritePage - && m_pReadPage->m_pRead == m_pWritePage->m_pEnd) - { - sal_uInt32 nBlock = std::min(nRemain, - sal_uInt32(m_nReadBufferSize - - m_nReadBufferFilled)); - sal_uInt32 nPosition = m_pWritePage->m_nOffset - + (m_pWritePage->m_pEnd - - m_pWritePage->m_aBuffer); - if (!m_aMarks.empty()) - nBlock = *m_aMarks.begin() > nPosition ? - std::min(nBlock, sal_uInt32(*m_aMarks.begin() - - nPosition)) : - 0; - - if (nBlock > 0) - { - rtl_copyMemory(m_pReadBuffer + m_nReadBufferFilled, pBuffer, - nBlock); - m_nReadBufferFilled += nBlock; - nRemain -= nBlock; - - nPosition += nBlock; - m_pWritePage->m_nOffset = (nPosition / m_nPageSize) * m_nPageSize; - m_pWritePage->m_pStart = m_pWritePage->m_aBuffer - + nPosition % m_nPageSize; - m_pWritePage->m_pRead = m_pWritePage->m_pStart; - m_pWritePage->m_pEnd = m_pWritePage->m_pStart; - } - } - - if (nRemain > 0) - for (;;) - { - sal_uInt32 nBlock - = std::min(sal_uInt32(m_pWritePage->m_aBuffer + m_nPageSize - - m_pWritePage->m_pEnd), - nRemain); - rtl_copyMemory(m_pWritePage->m_pEnd, pBuffer, nBlock); - m_pWritePage->m_pEnd += nBlock; - pBuffer += nBlock; - nRemain -= nBlock; - - if (nRemain == 0) - break; - - if (m_pWritePage->m_pNext == m_pFirstPage) - { - if (m_nPages == m_nMaxPages) - break; - - Page * pNew - = static_cast< Page * >(rtl_allocateMemory( - sizeof (Page) + m_nPageSize - - 1)); - pNew->m_pPrev = m_pWritePage; - pNew->m_pNext = m_pWritePage->m_pNext; - - m_pWritePage->m_pNext->m_pPrev = pNew; - m_pWritePage->m_pNext = pNew; - ++m_nPages; - } - - m_pWritePage->m_pNext->m_nOffset = m_pWritePage->m_nOffset - + m_nPageSize; - m_pWritePage = m_pWritePage->m_pNext; - m_pWritePage->m_pStart = m_pWritePage->m_aBuffer; - m_pWritePage->m_pRead = m_pWritePage->m_aBuffer; - m_pWritePage->m_pEnd = m_pWritePage->m_aBuffer; - } - - return nSize - nRemain; -} - -//============================================================================ -bool SvDataPipe_Impl::addMark(sal_uInt32 nPosition) -{ - if (m_pFirstPage != 0 && m_pFirstPage->m_nOffset > nPosition) - return false; - m_aMarks.insert(nPosition); - return true; -} - -//============================================================================ -bool SvDataPipe_Impl::removeMark(sal_uInt32 nPosition) -{ - std::multiset< sal_uInt32 >::iterator t = m_aMarks.find(nPosition); - if (t == m_aMarks.end()) - return false; - m_aMarks.erase(t); - while (remove(m_pFirstPage)) ; - return true; -} - -//============================================================================ -SvDataPipe_Impl::SeekResult SvDataPipe_Impl::setReadPosition(sal_uInt32 - nPosition) -{ - if (m_pFirstPage == 0) - return nPosition == 0 ? SEEK_OK : SEEK_PAST_END; - - if (nPosition - <= m_pReadPage->m_nOffset - + (m_pReadPage->m_pRead - m_pReadPage->m_aBuffer)) - { - if (nPosition - < m_pFirstPage->m_nOffset - + (m_pFirstPage->m_pStart - m_pFirstPage->m_aBuffer)) - return SEEK_BEFORE_MARKED; - - while (nPosition < m_pReadPage->m_nOffset) - { - m_pReadPage->m_pRead = m_pReadPage->m_pStart; - m_pReadPage = m_pReadPage->m_pPrev; - } - } - else - { - if (nPosition - > m_pWritePage->m_nOffset - + (m_pWritePage->m_pEnd - m_pWritePage->m_aBuffer)) - return SEEK_PAST_END; - - while (m_pReadPage != m_pWritePage - && nPosition >= m_pReadPage->m_nOffset + m_nPageSize) - { - Page * pRemove = m_pReadPage; - m_pReadPage = pRemove->m_pNext; - remove(pRemove); - } - } - - m_pReadPage->m_pRead = m_pReadPage->m_aBuffer - + (nPosition - m_pReadPage->m_nOffset); - return SEEK_OK; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/svldata.cxx b/svl/source/misc/svldata.cxx deleted file mode 100644 index 8ee7b9c7f8..0000000000 --- a/svl/source/misc/svldata.cxx +++ /dev/null @@ -1,92 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <map> -#include <tools/resmgr.hxx> -#include <tools/shl.hxx> -#include <svl/svldata.hxx> - -namespace unnamed_svl_svldata {} -using namespace unnamed_svl_svldata; - // unnamed namespaces don't work well yet - -//============================================================================ -namespace unnamed_svl_svldata { - -typedef std::map< rtl::OUString, SimpleResMgr * > SimpleResMgrMap; - -} - -//============================================================================ -// -// ImpSvlData -// -//============================================================================ - -static ImpSvlData* pSvlData = 0; - -ImpSvlData::~ImpSvlData() -{ - for (SimpleResMgrMap::iterator t - = static_cast< SimpleResMgrMap * >(m_pThreadsafeRMs)->begin(); - t != static_cast< SimpleResMgrMap * >(m_pThreadsafeRMs)->end(); ++t) - delete t->second; - delete static_cast< SimpleResMgrMap * >(m_pThreadsafeRMs); -} - -//============================================================================ -SimpleResMgr* ImpSvlData::GetSimpleRM(const ::com::sun::star::lang::Locale& rLocale) -{ - if (!m_pThreadsafeRMs) - m_pThreadsafeRMs = new SimpleResMgrMap; - rtl::OUString aISOcode = rLocale.Language; - aISOcode += rtl::OStringToOUString("-", RTL_TEXTENCODING_UTF8); - aISOcode += rLocale.Country; - - SimpleResMgr *& rResMgr - = (*static_cast< SimpleResMgrMap * >(m_pThreadsafeRMs))[aISOcode]; - if (!rResMgr) - { - rResMgr = new SimpleResMgr(CREATEVERSIONRESMGR_NAME(svl), rLocale ); - } - return rResMgr; -} - -//============================================================================ -// static -ImpSvlData & ImpSvlData::GetSvlData() -{ - if (!pSvlData) - pSvlData= new ImpSvlData; - return *pSvlData; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/misc/urihelper.cxx b/svl/source/misc/urihelper.cxx deleted file mode 100644 index feed4a87a9..0000000000 --- a/svl/source/misc/urihelper.cxx +++ /dev/null @@ -1,868 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/urihelper.hxx> -#include <com/sun/star/beans/XPropertySet.hpp> -#include "com/sun/star/lang/WrappedTargetRuntimeException.hpp" -#include "com/sun/star/lang/XMultiComponentFactory.hpp" -#include "com/sun/star/ucb/Command.hpp" -#include <com/sun/star/ucb/FileSystemNotation.hpp> -#include "com/sun/star/ucb/IllegalIdentifierException.hpp" -#include "com/sun/star/ucb/UnsupportedCommandException.hpp" -#include "com/sun/star/ucb/XCommandEnvironment.hpp" -#include "com/sun/star/ucb/XCommandProcessor.hpp" -#include "com/sun/star/ucb/XContent.hpp" -#include "com/sun/star/ucb/XContentIdentifierFactory.hpp" -#include "com/sun/star/ucb/XContentProvider.hpp" -#include <com/sun/star/ucb/XContentProviderManager.hpp> -#include "com/sun/star/uno/Any.hxx" -#include "com/sun/star/uno/Exception.hpp" -#include "com/sun/star/uno/Reference.hxx" -#include "com/sun/star/uno/RuntimeException.hpp" -#include "com/sun/star/uno/Sequence.hxx" -#include "com/sun/star/uno/XComponentContext.hpp" -#include "com/sun/star/uno/XInterface.hpp" -#include "com/sun/star/uri/UriReferenceFactory.hpp" -#include "com/sun/star/uri/XUriReference.hpp" -#include "com/sun/star/uri/XUriReferenceFactory.hpp" -#include "cppuhelper/exc_hlp.hxx" -#include "comphelper/processfactory.hxx" -#include "osl/diagnose.h" -#include "rtl/ustrbuf.hxx" -#include "rtl/ustring.h" -#include "rtl/ustring.hxx" -#include "sal/types.h" -#include <tools/debug.hxx> -#include <tools/inetmime.hxx> -#include <ucbhelper/contentbroker.hxx> -#include <unotools/charclass.hxx> -#include "rtl/instance.hxx" - -namespace css = com::sun::star; -using namespace com::sun::star; - -//============================================================================ -// -// SmartRel2Abs -// -//============================================================================ - -namespace { - -inline UniString toUniString(ByteString const & rString) -{ - return UniString(rString, RTL_TEXTENCODING_ISO_8859_1); -} - -inline UniString toUniString(UniString const & rString) -{ - return rString; -} - -template< typename Str > -inline UniString SmartRel2Abs_Impl(INetURLObject const & rTheBaseURIRef, - Str const & rTheRelURIRef, - Link const & rMaybeFileHdl, - bool bCheckFileExists, - bool bIgnoreFragment, - INetURLObject::EncodeMechanism - eEncodeMechanism, - INetURLObject::DecodeMechanism - eDecodeMechanism, - rtl_TextEncoding eCharset, - bool bRelativeNonURIs, - INetURLObject::FSysStyle eStyle) -{ - // Backwards compatibility: - if (rTheRelURIRef.Len() != 0 && rTheRelURIRef.GetChar(0) == '#') - return toUniString(rTheRelURIRef); - - INetURLObject aAbsURIRef; - if (rTheBaseURIRef.HasError()) - aAbsURIRef. - SetSmartURL(rTheRelURIRef, eEncodeMechanism, eCharset, eStyle); - else - { - bool bWasAbsolute; - aAbsURIRef = rTheBaseURIRef.smartRel2Abs(rTheRelURIRef, - bWasAbsolute, - bIgnoreFragment, - eEncodeMechanism, - eCharset, - bRelativeNonURIs, - eStyle); - if (bCheckFileExists - && !bWasAbsolute - && (aAbsURIRef.GetProtocol() == INET_PROT_FILE)) - { - INetURLObject aNonFileURIRef; - aNonFileURIRef.SetSmartURL(rTheRelURIRef, - eEncodeMechanism, - eCharset, - eStyle); - if (!aNonFileURIRef.HasError() - && aNonFileURIRef.GetProtocol() != INET_PROT_FILE) - { - bool bMaybeFile = false; - if (rMaybeFileHdl.IsSet()) - { - UniString aFilePath(toUniString(rTheRelURIRef)); - bMaybeFile = rMaybeFileHdl.Call(&aFilePath) != 0; - } - if (!bMaybeFile) - aAbsURIRef = aNonFileURIRef; - } - } - } - return aAbsURIRef.GetMainURL(eDecodeMechanism, eCharset); -} - -} - -UniString -URIHelper::SmartRel2Abs(INetURLObject const & rTheBaseURIRef, - UniString const & rTheRelURIRef, - Link const & rMaybeFileHdl, - bool bCheckFileExists, - bool bIgnoreFragment, - INetURLObject::EncodeMechanism eEncodeMechanism, - INetURLObject::DecodeMechanism eDecodeMechanism, - rtl_TextEncoding eCharset, - bool bRelativeNonURIs, - INetURLObject::FSysStyle eStyle) -{ - return SmartRel2Abs_Impl(rTheBaseURIRef, rTheRelURIRef, rMaybeFileHdl, - bCheckFileExists, bIgnoreFragment, - eEncodeMechanism, eDecodeMechanism, eCharset, - bRelativeNonURIs, eStyle); -} - -//============================================================================ -// -// SetMaybeFileHdl -// -//============================================================================ - -namespace { struct MaybeFileHdl : public rtl::Static< Link, MaybeFileHdl > {}; } - -void URIHelper::SetMaybeFileHdl(Link const & rTheMaybeFileHdl) -{ - MaybeFileHdl::get() = rTheMaybeFileHdl; -} - -//============================================================================ -// -// GetMaybeFileHdl -// -//============================================================================ - -Link URIHelper::GetMaybeFileHdl() -{ - return MaybeFileHdl::get(); -} - -namespace { - -bool isAbsoluteHierarchicalUriReference( - css::uno::Reference< css::uri::XUriReference > const & uriReference) -{ - return uriReference.is() && uriReference->isAbsolute() - && uriReference->isHierarchical() && !uriReference->hasRelativePath(); -} - -// To improve performance, assume that if for any prefix URL of a given -// hierarchical URL either a UCB content cannot be created, or the UCB content -// does not support the getCasePreservingURL command, then this will hold for -// any other prefix URL of the given URL, too: -enum Result { Success, GeneralFailure, SpecificFailure }; - -Result normalizePrefix( - css::uno::Reference< css::ucb::XContentProvider > const & broker, - rtl::OUString const & uri, rtl::OUString * normalized) -{ - OSL_ASSERT(broker.is() && normalized != 0); - css::uno::Reference< css::ucb::XContent > content; - try { - content = broker->queryContent( - css::uno::Reference< css::ucb::XContentIdentifierFactory >( - broker, css::uno::UNO_QUERY_THROW)->createContentIdentifier( - uri)); - } catch (css::ucb::IllegalIdentifierException &) {} - if (!content.is()) { - return GeneralFailure; - } - try { - #if OSL_DEBUG_LEVEL > 0 - bool ok = - #endif - (css::uno::Reference< css::ucb::XCommandProcessor >( - content, css::uno::UNO_QUERY_THROW)->execute( - css::ucb::Command( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "getCasePreservingURL")), - -1, css::uno::Any()), - 0, - css::uno::Reference< css::ucb::XCommandEnvironment >()) - >>= *normalized); - OSL_ASSERT(ok); - } catch (css::uno::RuntimeException &) { - throw; - } catch (css::ucb::UnsupportedCommandException &) { - return GeneralFailure; - } catch (css::uno::Exception &) { - return SpecificFailure; - } - return Success; -} - -rtl::OUString normalize( - css::uno::Reference< css::ucb::XContentProvider > const & broker, - css::uno::Reference< css::uri::XUriReferenceFactory > const & uriFactory, - rtl::OUString const & uriReference) -{ - // normalizePrefix can potentially fail (a typically example being a file - // URL that denotes a non-existing resource); in such a case, try to - // normalize as long a prefix of the given URL as possible (i.e., normalize - // all the existing directories within the path): - rtl::OUString normalized; - sal_Int32 n = uriReference.indexOf('#'); - normalized = n == -1 ? uriReference : uriReference.copy(0, n); - switch (normalizePrefix(broker, normalized, &normalized)) { - case Success: - return n == -1 ? normalized : normalized + uriReference.copy(n); - case GeneralFailure: - return uriReference; - case SpecificFailure: - default: - break; - } - css::uno::Reference< css::uri::XUriReference > ref( - uriFactory->parse(uriReference)); - if (!isAbsoluteHierarchicalUriReference(ref)) { - return uriReference; - } - sal_Int32 count = ref->getPathSegmentCount(); - if (count < 2) { - return uriReference; - } - rtl::OUStringBuffer head(ref->getScheme()); - head.append(static_cast< sal_Unicode >(':')); - if (ref->hasAuthority()) { - head.appendAscii(RTL_CONSTASCII_STRINGPARAM("//")); - head.append(ref->getAuthority()); - } - for (sal_Int32 i = count - 1; i > 0; --i) { - rtl::OUStringBuffer buf(head); - for (sal_Int32 j = 0; j < i; ++j) { - buf.append(static_cast< sal_Unicode >('/')); - buf.append(ref->getPathSegment(j)); - } - normalized = buf.makeStringAndClear(); - if (normalizePrefix(broker, normalized, &normalized) != SpecificFailure) - { - buf.append(normalized); - css::uno::Reference< css::uri::XUriReference > preRef( - uriFactory->parse(normalized)); - if (!isAbsoluteHierarchicalUriReference(preRef)) { - // This could only happen if something is inconsistent: - break; - } - sal_Int32 preCount = preRef->getPathSegmentCount(); - // normalizePrefix may have added or removed a final slash: - if (preCount != i) { - if (preCount == i - 1) { - buf.append(static_cast< sal_Unicode >('/')); - } else if (preCount - 1 == i && buf.getLength() > 0 - && buf.charAt(buf.getLength() - 1) == '/') - { - buf.setLength(buf.getLength() - 1); - } else { - // This could only happen if something is inconsistent: - break; - } - } - for (sal_Int32 j = i; j < count; ++j) { - buf.append(static_cast< sal_Unicode >('/')); - buf.append(ref->getPathSegment(j)); - } - if (ref->hasQuery()) { - buf.append(static_cast< sal_Unicode >('?')); - buf.append(ref->getQuery()); - } - if (ref->hasFragment()) { - buf.append(static_cast< sal_Unicode >('#')); - buf.append(ref->getFragment()); - } - return buf.makeStringAndClear(); - } - } - return uriReference; -} - -} - -css::uno::Reference< css::uri::XUriReference > -URIHelper::normalizedMakeRelative( - css::uno::Reference< css::uno::XComponentContext > const & context, - rtl::OUString const & baseUriReference, rtl::OUString const & uriReference) -{ - OSL_ASSERT(context.is()); - css::uno::Reference< css::lang::XMultiComponentFactory > componentFactory( - context->getServiceManager()); - if (!componentFactory.is()) { - throw css::uno::RuntimeException( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "component context has no service manager")), - css::uno::Reference< css::uno::XInterface >()); - } - css::uno::Sequence< css::uno::Any > args(2); - args[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); - args[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); - css::uno::Reference< css::ucb::XContentProvider > broker; - try { - broker = css::uno::Reference< css::ucb::XContentProvider >( - componentFactory->createInstanceWithArgumentsAndContext( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.ucb.UniversalContentBroker")), - args, context), - css::uno::UNO_QUERY_THROW); - } catch (css::uno::RuntimeException &) { - throw; - } catch (css::uno::Exception &) { - css::uno::Any exception(cppu::getCaughtException()); - throw css::lang::WrappedTargetRuntimeException( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "creating com.sun.star.ucb.UniversalContentBroker failed")), - css::uno::Reference< css::uno::XInterface >(), - exception); - } - css::uno::Reference< css::uri::XUriReferenceFactory > uriFactory( - css::uri::UriReferenceFactory::create(context)); - return uriFactory->makeRelative( - uriFactory->parse(normalize(broker, uriFactory, baseUriReference)), - uriFactory->parse(normalize(broker, uriFactory, uriReference)), true, - true, false); -} - -rtl::OUString URIHelper::simpleNormalizedMakeRelative( - rtl::OUString const & baseUriReference, rtl::OUString const & uriReference) -{ - com::sun::star::uno::Reference< com::sun::star::uri::XUriReference > rel( - URIHelper::normalizedMakeRelative( - com::sun::star::uno::Reference< - com::sun::star::uno::XComponentContext >( - (com::sun::star::uno::Reference< - com::sun::star::beans::XPropertySet >( - comphelper::getProcessServiceFactory(), - com::sun::star::uno::UNO_QUERY_THROW)-> - getPropertyValue( - rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM("DefaultContext")))), - com::sun::star::uno::UNO_QUERY_THROW), - baseUriReference, uriReference)); - return rel.is() ? rel->getUriReference() : uriReference; -} - -//============================================================================ -// -// FindFirstURLInText -// -//============================================================================ - -namespace { - -inline xub_StrLen nextChar(UniString const & rStr, xub_StrLen nPos) -{ - return INetMIME::isHighSurrogate(rStr.GetChar(nPos)) - && rStr.Len() - nPos >= 2 - && INetMIME::isLowSurrogate(rStr.GetChar(nPos + 1)) ? - nPos + 2 : nPos + 1; -} - -bool isBoundary1(CharClass const & rCharClass, UniString const & rStr, - xub_StrLen nPos, xub_StrLen nEnd) -{ - if (nPos == nEnd) - return true; - if (rCharClass.isLetterNumeric(rStr, nPos)) - return false; - switch (rStr.GetChar(nPos)) - { - case '$': - case '%': - case '&': - case '-': - case '/': - case '@': - case '\\': - return false; - default: - return true; - } -} - -bool isBoundary2(CharClass const & rCharClass, UniString const & rStr, - xub_StrLen nPos, xub_StrLen nEnd) -{ - if (nPos == nEnd) - return true; - if (rCharClass.isLetterNumeric(rStr, nPos)) - return false; - switch (rStr.GetChar(nPos)) - { - case '!': - case '#': - case '$': - case '%': - case '&': - case '\'': - case '*': - case '+': - case '-': - case '/': - case '=': - case '?': - case '@': - case '^': - case '_': - case '`': - case '{': - case '|': - case '}': - case '~': - return false; - default: - return true; - } -} - -bool checkWChar(CharClass const & rCharClass, UniString const & rStr, - xub_StrLen * pPos, xub_StrLen * pEnd, bool bBackslash = false, - bool bPipe = false) -{ - sal_Unicode c = rStr.GetChar(*pPos); - if (INetMIME::isUSASCII(c)) - { - static sal_uInt8 const aMap[128] - = { 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 0, 0, 4, 4, 4, 1, // !"#$%&' - 1, 1, 1, 1, 1, 4, 1, 4, // ()*+,-./ - 4, 4, 4, 4, 4, 4, 4, 4, // 01234567 - 4, 4, 1, 1, 0, 1, 0, 1, // 89:;<=>? - 4, 4, 4, 4, 4, 4, 4, 4, // @ABCDEFG - 4, 4, 4, 4, 4, 4, 4, 4, // HIJKLMNO - 4, 4, 4, 4, 4, 4, 4, 4, // PQRSTUVW - 4, 4, 4, 1, 2, 1, 0, 1, // XYZ[\]^_ - 0, 4, 4, 4, 4, 4, 4, 4, // `abcdefg - 4, 4, 4, 4, 4, 4, 4, 4, // hijklmno - 4, 4, 4, 4, 4, 4, 4, 4, // pqrstuvw - 4, 4, 4, 0, 3, 0, 1, 0 }; // xyz{|}~ - switch (aMap[c]) - { - default: // not uric - return false; - - case 1: // uric - ++(*pPos); - return true; - - case 2: // "\" - if (bBackslash) - { - *pEnd = ++(*pPos); - return true; - } - else - return false; - - case 3: // "|" - if (bPipe) - { - *pEnd = ++(*pPos); - return true; - } - else - return false; - - case 4: // alpha, digit, "$", "%", "&", "-", "/", "@" (see - // isBoundary1) - *pEnd = ++(*pPos); - return true; - } - } - else if (rCharClass.isLetterNumeric(rStr, *pPos)) - { - *pEnd = *pPos = nextChar(rStr, *pPos); - return true; - } - else - return false; -} - -sal_uInt32 scanDomain(UniString const & rStr, xub_StrLen * pPos, - xub_StrLen nEnd) -{ - sal_Unicode const * pBuffer = rStr.GetBuffer(); - sal_Unicode const * p = pBuffer + *pPos; - sal_uInt32 nLabels = INetURLObject::scanDomain(p, pBuffer + nEnd, false); - *pPos = sal::static_int_cast< xub_StrLen >(p - pBuffer); - return nLabels; -} - -} - -UniString -URIHelper::FindFirstURLInText(UniString const & rText, - xub_StrLen & rBegin, - xub_StrLen & rEnd, - CharClass const & rCharClass, - INetURLObject::EncodeMechanism eMechanism, - rtl_TextEncoding eCharset, - INetURLObject::FSysStyle eStyle) -{ - if (!(rBegin <= rEnd && rEnd <= rText.Len())) - return UniString(); - - // Search for the first substring of [rBegin..rEnd[ that matches any of the - // following productions (for which the appropriate style bit is set in - // eStyle, if applicable). - // - // 1st Production (known scheme): - // \B1 <one of the known schemes, except file> ":" 1*wchar ["#" 1*wchar] - // \B1 - // - // 2nd Production (file): - // \B1 "FILE:" 1*(wchar / "\" / "|") ["#" 1*wchar] \B1 - // - // 3rd Production (ftp): - // \B1 "FTP" 2*("." label) ["/" *wchar] ["#" 1*wchar] \B1 - // - // 4th Production (http): - // \B1 "WWW" 2*("." label) ["/" *wchar] ["#" 1*wchar] \B1 - // - // 5th Production (mailto): - // \B2 local-part "@" domain \B1 - // - // 6th Production (UNC file): - // \B1 "\\" domain "\" *(wchar / "\") \B1 - // - // 7th Production (DOS file): - // \B1 ALPHA ":\" *(wchar / "\") \B1 - // - // 8th Production (Unix-like DOS file): - // \B1 ALPHA ":/" *(wchar / "\") \B1 - // - // The productions use the following auxiliary rules. - // - // local-part = atom *("." atom) - // atom = 1*(alphanum / "!" / "#" / "$" / "%" / "&" / "'" / "*" / "+" - // / "-" / "/" / "=" / "?" / "^" / "_" / "`" / "{" / "|" / "}" - // / "~") - // domain = label *("." label) - // label = alphanum [*(alphanum / "-") alphanum] - // alphanum = ALPHA / DIGIT - // wchar = <any uric character (ignoring the escaped rule), or "%", or - // a letter or digit (according to rCharClass)> - // - // "\B1" (boundary 1) stands for the beginning or end of the block of text, - // or a character that is neither (a) a letter or digit (according to - // rCharClass), nor (b) any of "$", "%", "&", "-", "/", "@", or "\". - // (FIXME: What was the rationale for this set of punctuation characters?) - // - // "\B2" (boundary 2) stands for the beginning or end of the block of text, - // or a character that is neither (a) a letter or digit (according to - // rCharClass), nor (b) any of "!", "#", "$", "%", "&", "'", "*", "+", "-", - // "/", "=", "?", "@", "^", "_", "`", "{", "|", "}", or "~" (i.e., an RFC - // 822 <atom> character, or "@" from \B1's set above). - // - // Productions 1--4, and 6--8 try to find a maximum-length match, but they - // stop at the first <wchar> character that is a "\B1" character which is - // only followed by "\B1" characters (taking "\" and "|" characters into - // account appropriately). Production 5 simply tries to find a maximum- - // length match. - // - // Productions 1--4 use the given eMechanism and eCharset. Productions 5--9 - // use ENCODE_ALL. - // - // Productions 6--9 are only applicable if the FSYS_DOS bit is set in - // eStyle. - - bool bBoundary1 = true; - bool bBoundary2 = true; - for (xub_StrLen nPos = rBegin; nPos != rEnd; nPos = nextChar(rText, nPos)) - { - sal_Unicode c = rText.GetChar(nPos); - if (bBoundary1) - { - if (INetMIME::isAlpha(c)) - { - xub_StrLen i = nPos; - INetProtocol eScheme - = INetURLObject::CompareProtocolScheme(UniString(rText, i, - rEnd)); - if (eScheme == INET_PROT_FILE) // 2nd - { - while (rText.GetChar(i++) != ':') ; - xub_StrLen nPrefixEnd = i; - xub_StrLen nUriEnd = i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd, true, - true)) ; - if (i != nPrefixEnd && rText.GetChar(i) == '#') - { - ++i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd)) ; - } - if (nUriEnd != nPrefixEnd - && isBoundary1(rCharClass, rText, nUriEnd, rEnd)) - { - INetURLObject aUri(UniString(rText, nPos, - nUriEnd - nPos), - INET_PROT_FILE, eMechanism, eCharset, - eStyle); - if (!aUri.HasError()) - { - rBegin = nPos; - rEnd = nUriEnd; - return - aUri.GetMainURL(INetURLObject::DECODE_TO_IURI); - } - } - } - else if (eScheme != INET_PROT_NOT_VALID) // 1st - { - while (rText.GetChar(i++) != ':') ; - xub_StrLen nPrefixEnd = i; - xub_StrLen nUriEnd = i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd)) ; - if (i != nPrefixEnd && rText.GetChar(i) == '#') - { - ++i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd)) ; - } - if (nUriEnd != nPrefixEnd - && (isBoundary1(rCharClass, rText, nUriEnd, rEnd) - || rText.GetChar(nUriEnd) == '\\')) - { - INetURLObject aUri(UniString(rText, nPos, - nUriEnd - nPos), - INET_PROT_HTTP, eMechanism, - eCharset); - if (!aUri.HasError()) - { - rBegin = nPos; - rEnd = nUriEnd; - return - aUri.GetMainURL(INetURLObject::DECODE_TO_IURI); - } - } - } - - // 3rd, 4th: - i = nPos; - sal_uInt32 nLabels = scanDomain(rText, &i, rEnd); - if (nLabels >= 3 - && rText.GetChar(nPos + 3) == '.' - && (((rText.GetChar(nPos) == 'w' - || rText.GetChar(nPos) == 'W') - && (rText.GetChar(nPos + 1) == 'w' - || rText.GetChar(nPos + 1) == 'W') - && (rText.GetChar(nPos + 2) == 'w' - || rText.GetChar(nPos + 2) == 'W')) - || ((rText.GetChar(nPos) == 'f' - || rText.GetChar(nPos) == 'F') - && (rText.GetChar(nPos + 1) == 't' - || rText.GetChar(nPos + 1) == 'T') - && (rText.GetChar(nPos + 2) == 'p' - || rText.GetChar(nPos + 2) == 'P')))) - // (note that rText.GetChar(nPos + 3) is guaranteed to be - // valid) - { - xub_StrLen nUriEnd = i; - if (i != rEnd && rText.GetChar(i) == '/') - { - nUriEnd = ++i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd)) ; - } - if (i != rEnd && rText.GetChar(i) == '#') - { - ++i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd)) ; - } - if (isBoundary1(rCharClass, rText, nUriEnd, rEnd) - || rText.GetChar(nUriEnd) == '\\') - { - INetURLObject aUri(UniString(rText, nPos, - nUriEnd - nPos), - INET_PROT_HTTP, eMechanism, - eCharset); - if (!aUri.HasError()) - { - rBegin = nPos; - rEnd = nUriEnd; - return - aUri.GetMainURL(INetURLObject::DECODE_TO_IURI); - } - } - } - - if ((eStyle & INetURLObject::FSYS_DOS) != 0 && rEnd - nPos >= 3 - && rText.GetChar(nPos + 1) == ':' - && (rText.GetChar(nPos + 2) == '/' - || rText.GetChar(nPos + 2) == '\\')) // 7th, 8th - { - i = nPos + 3; - xub_StrLen nUriEnd = i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd)) ; - if (isBoundary1(rCharClass, rText, nUriEnd, rEnd)) - { - INetURLObject aUri(UniString(rText, nPos, - nUriEnd - nPos), - INET_PROT_FILE, - INetURLObject::ENCODE_ALL, - RTL_TEXTENCODING_UTF8, - INetURLObject::FSYS_DOS); - if (!aUri.HasError()) - { - rBegin = nPos; - rEnd = nUriEnd; - return - aUri.GetMainURL(INetURLObject::DECODE_TO_IURI); - } - } - } - } - else if ((eStyle & INetURLObject::FSYS_DOS) != 0 && rEnd - nPos >= 2 - && rText.GetChar(nPos) == '\\' - && rText.GetChar(nPos + 1) == '\\') // 6th - { - xub_StrLen i = nPos + 2; - sal_uInt32 nLabels = scanDomain(rText, &i, rEnd); - if (nLabels >= 1 && i != rEnd && rText.GetChar(i) == '\\') - { - xub_StrLen nUriEnd = ++i; - while (i != rEnd - && checkWChar(rCharClass, rText, &i, &nUriEnd, - true)) ; - if (isBoundary1(rCharClass, rText, nUriEnd, rEnd)) - { - INetURLObject aUri(UniString(rText, nPos, - nUriEnd - nPos), - INET_PROT_FILE, - INetURLObject::ENCODE_ALL, - RTL_TEXTENCODING_UTF8, - INetURLObject::FSYS_DOS); - if (!aUri.HasError()) - { - rBegin = nPos; - rEnd = nUriEnd; - return - aUri.GetMainURL(INetURLObject::DECODE_TO_IURI); - } - } - } - } - } - if (bBoundary2 && INetMIME::isAtomChar(c)) // 5th - { - bool bDot = false; - for (xub_StrLen i = nPos + 1; i != rEnd; ++i) - { - sal_Unicode c2 = rText.GetChar(i); - if (INetMIME::isAtomChar(c2)) - bDot = false; - else if (bDot) - break; - else if (c2 == '.') - bDot = true; - else - { - if (c2 == '@') - { - ++i; - sal_uInt32 nLabels = scanDomain(rText, &i, rEnd); - if (nLabels >= 1 - && isBoundary1(rCharClass, rText, i, rEnd)) - { - INetURLObject aUri(UniString(rText, nPos, i - nPos), - INET_PROT_MAILTO, - INetURLObject::ENCODE_ALL); - if (!aUri.HasError()) - { - rBegin = nPos; - rEnd = i; - return aUri.GetMainURL( - INetURLObject::DECODE_TO_IURI); - } - } - } - break; - } - } - } - bBoundary1 = isBoundary1(rCharClass, rText, nPos, rEnd); - bBoundary2 = isBoundary2(rCharClass, rText, nPos, rEnd); - } - rBegin = rEnd; - return UniString(); -} - -//============================================================================ -// -// removePassword -// -//============================================================================ - -UniString -URIHelper::removePassword(UniString const & rURI, - INetURLObject::EncodeMechanism eEncodeMechanism, - INetURLObject::DecodeMechanism eDecodeMechanism, - rtl_TextEncoding eCharset) -{ - INetURLObject aObj(rURI, eEncodeMechanism, eCharset); - return aObj.HasError() ? - rURI : - String(aObj.GetURLNoPass(eDecodeMechanism, eCharset)); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/brdcst.cxx b/svl/source/notify/brdcst.cxx deleted file mode 100644 index 7665284b69..0000000000 --- a/svl/source/notify/brdcst.cxx +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/debug.hxx> -#include <osl/diagnose.h> - -#include <svl/hint.hxx> -#include <svl/smplhint.hxx> -#include <svl/lstner.hxx> - -SV_DECL_PTRARR( SfxListenerArr_Impl, SfxListener*, 0, 2 ) - -#define _SFX_BRDCST_CXX -#include <svl/brdcst.hxx> - -//==================================================================== -DBG_NAME(SfxBroadcaster) -TYPEINIT0(SfxBroadcaster); - -//==================================================================== - -//==================================================================== -// broadcast immediately - - -void SfxBroadcaster::Broadcast( const SfxHint &rHint ) -{ - DBG_CHKTHIS(SfxBroadcaster, 0); - - // is anybody to notify? - if ( aListeners.Count() /*! || aGlobListeners.Count() */ ) - { - // notify all registered listeners exactly once - for ( sal_uInt16 n = 0; n < aListeners.Count(); ++n ) - { - SfxListener* pListener = aListeners[n]; - if ( pListener ) - pListener->Notify( *this, rHint ); - } - } -} - -// unregister all listeners - -SfxBroadcaster::~SfxBroadcaster() -{ - DBG_DTOR(SfxBroadcaster, 0); - - Broadcast( SfxSimpleHint(SFX_HINT_DYING) ); - - // remove all still registered listeners - for ( sal_uInt16 nPos = 0; nPos < aListeners.Count(); ++nPos ) - { - SfxListener *pListener = aListeners[nPos]; - if ( pListener ) - pListener->RemoveBroadcaster_Impl(*this); - } -} - -//-------------------------------------------------------------------- - -// simple ctor of class SfxBroadcaster - -SfxBroadcaster::SfxBroadcaster() -{ - DBG_CTOR(SfxBroadcaster, 0); -} - -//-------------------------------------------------------------------- - -// copy ctor of class SfxBroadcaster - - -SfxBroadcaster::SfxBroadcaster( const SfxBroadcaster &rBC ) -{ - DBG_CTOR(SfxBroadcaster, 0); - - for ( sal_uInt16 n = 0; n < rBC.aListeners.Count(); ++n ) - { - SfxListener *pListener = rBC.aListeners[n]; - if ( pListener ) - pListener->StartListening( *this ); - } -} - -//-------------------------------------------------------------------- - -// add a new SfxListener to the list - -sal_Bool SfxBroadcaster::AddListener( SfxListener& rListener ) -{ - DBG_CHKTHIS(SfxBroadcaster, 0); - const SfxListener *pListener = &rListener; - const SfxListener *pNull = 0; - sal_uInt16 nFreePos = aListeners.GetPos( pNull ); - if ( nFreePos < aListeners.Count() ) - aListeners.GetData()[nFreePos] = pListener; - else if ( aListeners.Count() < (USHRT_MAX-1) ) - aListeners.Insert( pListener, aListeners.Count() ); - else - { - OSL_FAIL( "array overflow" ); - return sal_False; - } - - DBG_ASSERT( USHRT_MAX != aListeners.GetPos(pListener), - "AddListener failed" ); - return sal_True; -} - -//-------------------------------------------------------------------- - -// called, if no more listeners exists - -void SfxBroadcaster::ListenersGone() -{ - DBG_CHKTHIS(SfxBroadcaster,0); -} - -//-------------------------------------------------------------------- - -// forward a notification to all registered listeners - -void SfxBroadcaster::Forward(SfxBroadcaster& rBC, const SfxHint& rHint) -{ - const sal_uInt16 nCount = aListeners.Count(); - for ( sal_uInt16 i = 0; i < nCount; ++i ) - { - SfxListener *pListener = aListeners[i]; - if ( pListener ) - pListener->Notify( rBC, rHint ); - } -} - -//-------------------------------------------------------------------- - -// remove one SfxListener from the list - -void SfxBroadcaster::RemoveListener( SfxListener& rListener ) -{ - {DBG_CHKTHIS(SfxBroadcaster, 0);} - const SfxListener *pListener = &rListener; - sal_uInt16 nPos = aListeners.GetPos(pListener); - DBG_ASSERT( nPos != USHRT_MAX, "RemoveListener: Listener unknown" ); - aListeners.GetData()[nPos] = 0; - if ( !HasListeners() ) - ListenersGone(); -} - -//-------------------------------------------------------------------- - -sal_Bool SfxBroadcaster::HasListeners() const -{ - for ( sal_uInt16 n = 0; n < aListeners.Count(); ++n ) - if ( aListeners.GetObject(n) != 0 ) - return sal_True; - return sal_False; -} - -//-------------------------------------------------------------------- - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/broadcast.cxx b/svl/source/notify/broadcast.cxx deleted file mode 100644 index 129abf99cd..0000000000 --- a/svl/source/notify/broadcast.cxx +++ /dev/null @@ -1,148 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/debug.hxx> - -#include <svl/listener.hxx> -#include <svl/listeneriter.hxx> -#include <svl/broadcast.hxx> -#include <svl/smplhint.hxx> - - -//==================================================================== -TYPEINIT0(SvtBroadcaster); - -//==================================================================== - -// simple ctor of class SvtBroadcaster - -SvtBroadcaster::SvtBroadcaster() - : pRoot( 0 ) -{ -} - -//-------------------------------------------------------------------- - -// copy ctor of class SvtBroadcaster - -SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC ) - : pRoot( 0 ) -{ - SvtListenerIter aIter( (SvtBroadcaster&)rBC ); - SvtListener* pLast = aIter.GoStart(); - if( pLast ) - do { - pLast->StartListening( *this ); - } while( 0 != ( pLast = aIter.GoNext() )); -} - -//-------------------------------------------------------------------- - -// unregister all listeners - -SvtBroadcaster::~SvtBroadcaster() -{ - Broadcast( SfxSimpleHint(SFX_HINT_DYING) ); - - SvtListenerIter aIter( *this ); - SvtListener* pLast = aIter.GoStart(); - if( pLast ) - do { - pLast->EndListening( *this ); - if( !HasListeners() ) // all gone ?? - break; - } while( 0 != ( pLast = aIter.GoNext() )); -} - -//-------------------------------------------------------------------- - -// broadcast immedeately - -void SvtBroadcaster::Broadcast( const SfxHint &rHint ) -{ - // is anybody to notify? - if( HasListeners() /* && !IsModifyLocked()*/ ) - { -// LockModify(); -// bInModify = sal_True; - - SvtListenerIter aIter( *this ); - SvtListener* pLast = aIter.GoStart(); - if( pLast ) - do { - pLast->Notify( *this, rHint ); - if( !HasListeners() ) // all gone ?? - break; - } while( 0 != ( pLast = aIter.GoNext() )); - -// bInModify = sal_False; -// UnlockModify(); - } -} - -//-------------------------------------------------------------------- - - -// called, if no more listeners exists - -void SvtBroadcaster::ListenersGone() -{ -} - -//-------------------------------------------------------------------- - -// forward a notification to all registered listeners - -void SvtBroadcaster::Forward( SvtBroadcaster& rBC, const SfxHint& rHint ) -{ - // is anybody to notify? - if( rBC.HasListeners() /* && !IsModifyLocked()*/ ) - { -// LockModify(); -// bInModify = sal_True; - - SvtListenerIter aIter( rBC ); - SvtListener* pLast = aIter.GoStart(); - if( pLast ) - do { - pLast->Notify( rBC, rHint ); - if( !rBC.HasListeners() ) // all gone ?? - break; - } while( 0 != ( pLast = aIter.GoNext() )); - -// bInModify = sal_False; -// UnlockModify(); - } -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/hint.cxx b/svl/source/notify/hint.cxx deleted file mode 100644 index 0becff59cf..0000000000 --- a/svl/source/notify/hint.cxx +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/hint.hxx> - -//==================================================================== - -TYPEINIT0(SfxHint); - -//==================================================================== -// virtual dtor for the typical base-class Hint - -SfxHint::~SfxHint() -{ -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/isethint.cxx b/svl/source/notify/isethint.cxx deleted file mode 100644 index 43ae33a4a1..0000000000 --- a/svl/source/notify/isethint.cxx +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/isethint.hxx> -#include <svl/itemset.hxx> - -//==================================================================== - -TYPEINIT1(SfxItemSetHint, SfxHint); - -//==================================================================== - -SfxItemSetHint::SfxItemSetHint( SfxItemSet *pItemSet ) - -/* [Beschreibung] - - Dieser Ctor "ubernimmt das als Parameter "ubergeben <SfxItemSet>, - das im Dtor gel"oscht wird. -*/ - -: _pItemSet( pItemSet ) -{ -} - -//-------------------------------------------------------------------- - -SfxItemSetHint::SfxItemSetHint( const SfxItemSet &rItemSet ) - -/* [Beschreibung] - - Dieser Ctor kopiert das als Parameter "ubergeben <SfxItemSet>. -*/ - -: _pItemSet( rItemSet.Clone() ) -{ -} - -//-------------------------------------------------------------------- - -SfxItemSetHint::~SfxItemSetHint() -{ - delete _pItemSet; -} - -//-------------------------------------------------------------------- - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listener.cxx b/svl/source/notify/listener.cxx deleted file mode 100644 index 798d2d84be..0000000000 --- a/svl/source/notify/listener.cxx +++ /dev/null @@ -1,163 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/debug.hxx> -#include <svl/broadcast.hxx> -#include <svl/listener.hxx> -#include "listenerbase.hxx" -#include <svl/listeneriter.hxx> - - -//==================================================================== -TYPEINIT0(SvtListener); - -//==================================================================== -// simple ctor of class SvtListener - -SvtListener::SvtListener() - : pBrdCastLst( 0 ) -{ -} -//-------------------------------------------------------------------- - -// copy ctor of class SvtListener - -SvtListener::SvtListener( const SvtListener &rListener ) - : pBrdCastLst( 0 ) -{ - SvtListenerBase* pLst = rListener.pBrdCastLst; - while( pLst ) - { - new SvtListenerBase( *this, *pLst->GetBroadcaster() ); - pLst = pLst->GetNext(); - } -} -//-------------------------------------------------------------------- - -// unregisteres the SvtListener from its SvtBroadcasters - -SvtListener::~SvtListener() -{ - EndListeningAll(); -} - -//-------------------------------------------------------------------- - -// registeres at a specific SvtBroadcaster - -sal_Bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster ) -{ - const SvtListenerBase* pLst = pBrdCastLst; - while( pLst ) - { - if( &rBroadcaster == pLst->GetBroadcaster() ) - { - // double, than return - return sal_False; - } - pLst = pLst->GetNext(); - } - new SvtListenerBase( *this, rBroadcaster ); - return sal_True; -} - -//-------------------------------------------------------------------- - -// unregisteres at a specific SvtBroadcaster - -sal_Bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster ) -{ - SvtListenerBase *pLst = pBrdCastLst, *pPrev = pLst; - while( pLst ) - { - if( &rBroadcaster == pLst->GetBroadcaster() ) - { - if( pBrdCastLst == pLst ) - pBrdCastLst = pLst->GetNext(); - else - pPrev->SetNext( pLst->GetNext() ); - - delete pLst; - return sal_True; - } - pPrev = pLst; - pLst = pLst->GetNext(); - } - return sal_False; -} - -//-------------------------------------------------------------------- - -// unregisteres all Broadcasters - -void SvtListener::EndListeningAll() -{ - SvtListenerBase *pLst = pBrdCastLst; - while( pLst ) - { - SvtListenerBase *pDel = pLst; - pLst = pLst->GetNext(); - - delete pDel; - } - pBrdCastLst = 0; -} - -//-------------------------------------------------------------------- - -sal_Bool SvtListener::IsListening( SvtBroadcaster& rBroadcaster ) const -{ - const SvtListenerBase *pLst = pBrdCastLst; - while( pLst ) - { - if( &rBroadcaster == pLst->GetBroadcaster() ) - break; - pLst = pLst->GetNext(); - } - return 0 != pLst; -} - -//-------------------------------------------------------------------- - -// base implementation of notification handler - -void SvtListener::Notify( SvtBroadcaster& -#ifdef DBG_UTIL -rBC -#endif -, const SfxHint& ) -{ - DBG_ASSERT( IsListening( rBC ), - "notification from unregistered broadcaster" ); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listenerbase.cxx b/svl/source/notify/listenerbase.cxx deleted file mode 100644 index 472dfc2833..0000000000 --- a/svl/source/notify/listenerbase.cxx +++ /dev/null @@ -1,78 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/debug.hxx> -#include "listenerbase.hxx" -#include <svl/listeneriter.hxx> -#include <svl/listener.hxx> -#include <svl/broadcast.hxx> - - -SvtListenerBase::SvtListenerBase( SvtListener& rLst, - SvtBroadcaster& rBroadcaster ) - : pLeft( 0 ), pRight( 0 ), - pBroadcaster( &rBroadcaster ), pListener( &rLst ) -{ - pNext = rLst.pBrdCastLst; - rLst.pBrdCastLst = this; - - if( pBroadcaster->pRoot ) - { - // set ever behind the root - pRight = pBroadcaster->pRoot->pRight; - pBroadcaster->pRoot->pRight = this; - this->pLeft = pBroadcaster->pRoot; - if( pRight ) - pRight->pLeft = this; - } - else - pBroadcaster->pRoot = this; -} - -SvtListenerBase::~SvtListenerBase() -{ - SvtListenerBase *pR = pRight, *pL = pLeft; - if( pBroadcaster->pRoot ) - pBroadcaster->pRoot = pL ? pL : pR; - - if( pL ) - pL->pRight = pR; - if( pR ) - pR->pLeft = pL; - - SvtListenerIter::RemoveListener( *this, pR ); - - if( !pBroadcaster->pRoot ) - pBroadcaster->ListenersGone(); -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listenerbase.hxx b/svl/source/notify/listenerbase.hxx deleted file mode 100644 index b0792e7b91..0000000000 --- a/svl/source/notify/listenerbase.hxx +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _SVT_LISTENERBASE_HXX -#define _SVT_LISTENERBASE_HXX - -class SvtBroadcaster; -class SvtListener; - -class SvtListenerBase -{ - SvtListenerBase *pNext; - SvtListenerBase *pLeft, *pRight; - SvtBroadcaster *pBroadcaster; - SvtListener *pListener; - -public: - - SvtListenerBase( SvtListener& rLst, SvtBroadcaster& rBroadcaster ); - ~SvtListenerBase(); - - SvtListenerBase* GetNext() const { return pNext; } - void SetNext( SvtListenerBase* p ) { pNext = p; } - - SvtBroadcaster* GetBroadcaster() const { return pBroadcaster; } - SvtListener* GetListener() const { return pListener; } - - SvtListenerBase* GetLeft() const { return pLeft; } - SvtListenerBase* GetRight() const { return pRight; } -}; - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listeneriter.cxx b/svl/source/notify/listeneriter.cxx deleted file mode 100644 index 6233999a53..0000000000 --- a/svl/source/notify/listeneriter.cxx +++ /dev/null @@ -1,192 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/debug.hxx> - -#include "listenerbase.hxx" -#include <svl/listeneriter.hxx> -#include <svl/broadcast.hxx> -#include <svl/listener.hxx> - -SvtListenerIter* SvtListenerIter::pListenerIters = 0; - -SvtListenerIter::SvtListenerIter( SvtBroadcaster& rBrdcst ) - : rRoot( rBrdcst ) -{ - // hinten einketten! - pNxtIter = 0; - if( pListenerIters ) - { - SvtListenerIter* pTmp = pListenerIters; - while( pTmp->pNxtIter ) - pTmp = pTmp->pNxtIter; - pTmp->pNxtIter = this; - } - else - pListenerIters = this; - - pAkt = rRoot.pRoot; - pDelNext = pAkt; -} - - - -SvtListenerIter::~SvtListenerIter() -{ - if( pListenerIters ) - { - if( pListenerIters == this ) - pListenerIters = pNxtIter; - else - { - SvtListenerIter* pTmp = pListenerIters; - while( pTmp->pNxtIter != this ) - if( 0 == ( pTmp = pTmp->pNxtIter ) ) - return ; - pTmp->pNxtIter = pNxtIter; - } - } -} - -void SvtListenerIter::RemoveListener( SvtListenerBase& rDel, - SvtListenerBase* pNext ) -{ - // Update the ListenerIter - SvtListenerIter* pTmp = pListenerIters; - while( pTmp ) - { - if( pTmp->pAkt == &rDel || pTmp->pDelNext == &rDel ) - pTmp->pDelNext = pNext; - pTmp = pTmp->pNxtIter; - } -} - -SvtListener* SvtListenerIter::GoNext() -{ - if( pDelNext == pAkt ) - { - pAkt = pAkt->GetRight(); - pDelNext = pAkt; - } - else - pAkt = pDelNext; - return pAkt ? pAkt->GetListener() : 0; -} - - -SvtListener* SvtListenerIter::GoPrev() -{ - if( pDelNext == pAkt ) - pAkt = pAkt->GetLeft(); - else - pAkt = pDelNext->GetLeft(); - pDelNext = pAkt; - return pAkt ? pAkt->GetListener() : 0; -} - - -SvtListener* SvtListenerIter::GoStart() // zum Anfang des Baums -{ - pAkt = rRoot.pRoot; - if( pAkt ) - while( pAkt->GetLeft() ) - pAkt = pAkt->GetLeft(); - pDelNext = pAkt; - return pAkt ? pAkt->GetListener() : 0; -} - - -SvtListener* SvtListenerIter::GoEnd() // zum End des Baums -{ - pAkt = pDelNext; - if( !pAkt ) - pAkt = rRoot.pRoot; - if( pAkt ) - while( pAkt->GetRight() ) - pAkt = pAkt->GetRight(); - pDelNext = pAkt; - return pAkt ? pAkt->GetListener() : 0; -} - - - -SvtListener* SvtListenerIter::First( TypeId nType ) -{ - aSrchId = nType; - GoStart(); - if( pAkt ) - do { - if( pAkt->GetListener()->IsA( aSrchId ) ) - break; - - if( pDelNext == pAkt ) - { - pAkt = pAkt->GetRight(); - pDelNext = pAkt; - } - else - pAkt = pDelNext; - - } while( pAkt ); - return pAkt ? pAkt->GetListener() : 0; -} - - -SvtListener* SvtListenerIter::Next() -{ - do { - // erstmal zum naechsten - if( pDelNext == pAkt ) - { - pAkt = pAkt->GetRight(); - pDelNext = pAkt; - } - else - pAkt = pDelNext; - - if( pAkt && pAkt->GetListener()->IsA( aSrchId ) ) - break; - } while( pAkt ); - return pAkt ? pAkt->GetListener() : 0; -} - - -SvtListener* SvtListenerIter::GoRoot() // wieder ab Root anfangen -{ - pDelNext = pAkt = rRoot.pRoot; - return pAkt ? pAkt->GetListener() : 0; -} - -SvtListener* SvtListenerIter::GetCurr() const // returns the current -{ - return pDelNext ? pDelNext->GetListener() : 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/lstner.cxx b/svl/source/notify/lstner.cxx deleted file mode 100644 index 66032028ef..0000000000 --- a/svl/source/notify/lstner.cxx +++ /dev/null @@ -1,191 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/debug.hxx> - -#include <svl/hint.hxx> -#include <svl/brdcst.hxx> - -SV_DECL_PTRARR( SfxBroadcasterArr_Impl, SfxBroadcaster*, 0, 2 ) - -#define _SFX_LSTNER_CXX -#include <svl/lstner.hxx> - -//==================================================================== -DBG_NAME(SfxListener) -TYPEINIT0(SfxListener); - -//==================================================================== -// simple ctor of class SfxListener - -SfxListener::SfxListener() -{ - DBG_CTOR(SfxListener, 0); -} -//-------------------------------------------------------------------- - -// copy ctor of class SfxListener - -SfxListener::SfxListener( const SfxListener &rListener ) -{ - DBG_CTOR(SfxListener, 0); - - for ( sal_uInt16 n = 0; n < rListener.aBCs.Count(); ++n ) - StartListening( *rListener.aBCs[n] ); -} -//-------------------------------------------------------------------- - -// unregisteres the SfxListener from its SfxBroadcasters - -SfxListener::~SfxListener() -{ - DBG_DTOR(SfxListener, 0); - - // unregister at all remainding broadcasters - for ( sal_uInt16 nPos = 0; nPos < aBCs.Count(); ++nPos ) - { - SfxBroadcaster *pBC = aBCs[nPos]; - pBC->RemoveListener(*this); - } -} - -//-------------------------------------------------------------------- - -// unregisteres at a specific SfxBroadcaster - -void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBC ) -{ - DBG_CHKTHIS(SfxListener, 0); - - const SfxBroadcaster *pBC = &rBC; - aBCs.Remove( aBCs.GetPos(pBC), 1 ); -} - -//-------------------------------------------------------------------- - -// registeres at a specific SfxBroadcaster - -sal_Bool SfxListener::StartListening( SfxBroadcaster& rBroadcaster, sal_Bool bPreventDups ) -{ - DBG_CHKTHIS(SfxListener, 0); - - if ( !bPreventDups || !IsListening( rBroadcaster ) ) - { - if ( rBroadcaster.AddListener(*this) ) - { - const SfxBroadcaster *pBC = &rBroadcaster; - aBCs.Insert( pBC, aBCs.Count() ); - - DBG_ASSERT( IsListening(rBroadcaster), "StartListening failed" ); - return sal_True; - } - - } - return sal_False; -} - -//-------------------------------------------------------------------- - -// unregisteres at a specific SfxBroadcaster - -sal_Bool SfxListener::EndListening( SfxBroadcaster& rBroadcaster, sal_Bool bAllDups ) -{ - DBG_CHKTHIS(SfxListener, 0); - - if ( !IsListening( rBroadcaster ) ) - return sal_False; - - do - { - rBroadcaster.RemoveListener(*this); - const SfxBroadcaster *pBC = &rBroadcaster; - aBCs.Remove( aBCs.GetPos(pBC), 1 ); - } - while ( bAllDups && IsListening( rBroadcaster ) ); - return sal_True; -} - -//-------------------------------------------------------------------- - -// unregisteres at a specific SfxBroadcaster by index - -void SfxListener::EndListening( sal_uInt16 nNo ) -{ - DBG_CHKTHIS(SfxListener, 0); - - SfxBroadcaster *pBC = aBCs.GetObject(nNo); - pBC->RemoveListener(*this); - aBCs.Remove( nNo, 1 ); -} - -//-------------------------------------------------------------------- - -// unregisteres all Broadcasters - -void SfxListener::EndListeningAll() -{ - DBG_CHKTHIS(SfxListener, 0); - - // MI: bei Optimierung beachten: Seiteneffekte von RemoveListener beachten! - while ( aBCs.Count() ) - { - SfxBroadcaster *pBC = aBCs.GetObject(0); - pBC->RemoveListener(*this); - aBCs.Remove( 0, 1 ); - } -} - -//-------------------------------------------------------------------- - -sal_Bool SfxListener::IsListening( SfxBroadcaster& rBroadcaster ) const -{ - const SfxBroadcaster *pBC = &rBroadcaster; - return USHRT_MAX != aBCs.GetPos( pBC ); -} - -//-------------------------------------------------------------------- - -// base implementation of notification handler - -#ifdef DBG_UTIL -void SfxListener::Notify( SfxBroadcaster& rBC, const SfxHint& ) -#else -void SfxListener::Notify( SfxBroadcaster&, const SfxHint& ) -#endif -{ - #ifdef DBG_UTIL - const SfxBroadcaster *pBC = &rBC; - DBG_ASSERT( USHRT_MAX != aBCs.GetPos(pBC), - "notification from unregistered broadcaster" ); - #endif -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/smplhint.cxx b/svl/source/notify/smplhint.cxx deleted file mode 100644 index 35cf56dfaa..0000000000 --- a/svl/source/notify/smplhint.cxx +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <svl/smplhint.hxx> - -//==================================================================== - -TYPEINIT1(SfxSimpleHint, SfxHint); - -//==================================================================== -// creates a SimpleHint with the type nId - -SfxSimpleHint::SfxSimpleHint( sal_uLong nIdP ) -{ - nId = nIdP; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/numfmuno.cxx b/svl/source/numbers/numfmuno.cxx deleted file mode 100644 index cb0c296e06..0000000000 --- a/svl/source/numbers/numfmuno.cxx +++ /dev/null @@ -1,1140 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/color.hxx> -#include <tools/debug.hxx> -#include <i18npool/mslangid.hxx> -#include <osl/mutex.hxx> -#include <rtl/ustring.hxx> - -#include <com/sun/star/util/Date.hpp> -#include <com/sun/star/beans/PropertyAttribute.hpp> - -#include "numfmuno.hxx" -#include <svl/numuno.hxx> -#include <svl/zforlist.hxx> -#include <svl/zformat.hxx> -#include <svl/itemprop.hxx> - -using namespace com::sun::star; - -//------------------------------------------------------------------------ - -#define SERVICENAME_NUMBERFORMATTER "com.sun.star.util.NumberFormatter" -#define SERVICENAME_NUMBERSETTINGS "com.sun.star.util.NumberFormatSettings" -#define SERVICENAME_NUMBERFORMATS "com.sun.star.util.NumberFormats" -#define SERVICENAME_NUMBERFORMAT "com.sun.star.util.NumberFormatProperties" - -//------------------------------------------------------------------------ - -#define PROPERTYNAME_FMTSTR "FormatString" -#define PROPERTYNAME_LOCALE "Locale" -#define PROPERTYNAME_TYPE "Type" -#define PROPERTYNAME_COMMENT "Comment" -#define PROPERTYNAME_CURREXT "CurrencyExtension" -#define PROPERTYNAME_CURRSYM "CurrencySymbol" -#define PROPERTYNAME_CURRABB "CurrencyAbbreviation" -#define PROPERTYNAME_DECIMALS "Decimals" -#define PROPERTYNAME_LEADING "LeadingZeros" -#define PROPERTYNAME_NEGRED "NegativeRed" -#define PROPERTYNAME_STDFORM "StandardFormat" -#define PROPERTYNAME_THOUS "ThousandsSeparator" -#define PROPERTYNAME_USERDEF "UserDefined" - -#define PROPERTYNAME_NOZERO "NoZero" -#define PROPERTYNAME_NULLDATE "NullDate" -#define PROPERTYNAME_STDDEC "StandardDecimals" -#define PROPERTYNAME_TWODIGIT "TwoDigitDateStart" - -//------------------------------------------------------------------------ - -// alles ohne Which-ID, Map nur fuer PropertySetInfo - -const SfxItemPropertyMapEntry* lcl_GetNumberFormatPropertyMap() -{ - static SfxItemPropertyMapEntry aNumberFormatPropertyMap_Impl[] = - { - {MAP_CHAR_LEN(PROPERTYNAME_FMTSTR), 0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_LOCALE), 0, &getCppuType((lang::Locale*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_TYPE), 0, &getCppuType((sal_Int16*)0), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_COMMENT), 0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_CURREXT), 0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_CURRSYM), 0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_DECIMALS), 0, &getCppuType((sal_Int16*)0), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_LEADING), 0, &getCppuType((sal_Int16*)0), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_NEGRED), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_STDFORM), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_THOUS), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_USERDEF), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_CURRABB), 0, &getCppuType((rtl::OUString*)0),beans::PropertyAttribute::BOUND | beans::PropertyAttribute::READONLY, 0}, - {0,0,0,0,0,0} - }; - return aNumberFormatPropertyMap_Impl; -} - -const SfxItemPropertyMapEntry* lcl_GetNumberSettingsPropertyMap() -{ - static SfxItemPropertyMapEntry aNumberSettingsPropertyMap_Impl[] = - { - {MAP_CHAR_LEN(PROPERTYNAME_NOZERO), 0, &getBooleanCppuType(), beans::PropertyAttribute::BOUND, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_NULLDATE), 0, &getCppuType((util::Date*)0), beans::PropertyAttribute::BOUND, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_STDDEC), 0, &getCppuType((sal_Int16*)0), beans::PropertyAttribute::BOUND, 0}, - {MAP_CHAR_LEN(PROPERTYNAME_TWODIGIT), 0, &getCppuType((sal_Int16*)0), beans::PropertyAttribute::BOUND, 0}, - {0,0,0,0,0,0} - }; - return aNumberSettingsPropertyMap_Impl; -} - -//---------------------------------------------------------------------------------------- - -LanguageType lcl_GetLanguage( const lang::Locale& rLocale ) -{ - // empty language -> LANGUAGE_SYSTEM - if ( rLocale.Language.getLength() == 0 ) - return LANGUAGE_SYSTEM; - - LanguageType eRet = MsLangId::convertLocaleToLanguage( rLocale ); - if ( eRet == LANGUAGE_NONE ) - eRet = LANGUAGE_SYSTEM; //! or throw an exception? - - return eRet; -} - -//---------------------------------------------------------------------------------------- - -SvNumberFormatterServiceObj::SvNumberFormatterServiceObj() - :m_aMutex() -{ -} - -SvNumberFormatterServiceObj::~SvNumberFormatterServiceObj() -{ -} - -com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SvNumberFormatterServiceObj_CreateInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& ) -{ - return ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface >( ( ::cppu::OWeakObject* ) new SvNumberFormatterServiceObj ); -} - -// XNumberFormatter - -void SAL_CALL SvNumberFormatterServiceObj::attachNumberFormatsSupplier( - const uno::Reference<util::XNumberFormatsSupplier>& _xSupplier ) - throw(uno::RuntimeException) -{ - ::rtl::Reference< SvNumberFormatsSupplierObj > xAutoReleaseOld; - - // SYNCHRONIZED -> - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - - SvNumberFormatsSupplierObj* pNew = SvNumberFormatsSupplierObj::getImplementation( _xSupplier ); - if (!pNew) - throw uno::RuntimeException(); // wrong object - - xAutoReleaseOld = xSupplier; - - xSupplier = pNew; - m_aMutex = xSupplier->getSharedMutex(); - } - // <- SYNCHRONIZED -} - -uno::Reference<util::XNumberFormatsSupplier> SAL_CALL - SvNumberFormatterServiceObj::getNumberFormatsSupplier() - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - return xSupplier.get(); -} - -sal_Int32 SAL_CALL SvNumberFormatterServiceObj::detectNumberFormat( - sal_Int32 nKey, const rtl::OUString& aString ) - throw(util::NotNumericException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - String aTemp = aString; - sal_uInt32 nUKey = nKey; - double fValue = 0.0; - if ( pFormatter->IsNumberFormat(aTemp, nUKey, fValue) ) - nRet = nUKey; - else - throw util::NotNumericException(); - } - else - throw uno::RuntimeException(); - - return nRet; -} - -double SAL_CALL SvNumberFormatterServiceObj::convertStringToNumber( - sal_Int32 nKey, const rtl::OUString& aString ) - throw(util::NotNumericException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - double fRet = 0.0; - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - String aTemp = aString; - sal_uInt32 nUKey = nKey; - double fValue = 0.0; - if ( pFormatter->IsNumberFormat(aTemp, nUKey, fValue) ) - fRet = fValue; - else - throw util::NotNumericException(); - } - else - throw uno::RuntimeException(); - - return fRet; -} - -rtl::OUString SAL_CALL SvNumberFormatterServiceObj::convertNumberToString( - sal_Int32 nKey, double fValue ) throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - String aRet; - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - Color* pColor = NULL; - pFormatter->GetOutputString(fValue, nKey, aRet, &pColor); - } - else - throw uno::RuntimeException(); - - return aRet; -} - -util::Color SAL_CALL SvNumberFormatterServiceObj::queryColorForNumber( sal_Int32 nKey, - double fValue, util::Color aDefaultColor ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - util::Color nRet = aDefaultColor; // color = sal_Int32 - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - String aStr; - Color* pColor = NULL; - pFormatter->GetOutputString(fValue, nKey, aStr, &pColor); - if (pColor) - nRet = pColor->GetColor(); - // sonst Default behalten - } - else - throw uno::RuntimeException(); - - return nRet; -} - -rtl::OUString SAL_CALL SvNumberFormatterServiceObj::formatString( sal_Int32 nKey, - const rtl::OUString& aString ) throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - String aRet; - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - String aTemp = aString; - Color* pColor = NULL; - pFormatter->GetOutputString(aTemp, nKey, aRet, &pColor); - } - else - throw uno::RuntimeException(); - - return aRet; -} - -util::Color SAL_CALL SvNumberFormatterServiceObj::queryColorForString( sal_Int32 nKey, - const rtl::OUString& aString,util::Color aDefaultColor ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - util::Color nRet = aDefaultColor; // color = sal_Int32 - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - String aTemp = aString; - String aStr; - Color* pColor = NULL; - pFormatter->GetOutputString(aTemp, nKey, aStr, &pColor); - if (pColor) - nRet = pColor->GetColor(); - // sonst Default behalten - } - else - throw uno::RuntimeException(); - - return nRet; -} - -rtl::OUString SAL_CALL SvNumberFormatterServiceObj::getInputString( sal_Int32 nKey, double fValue ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - String aRet; - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - pFormatter->GetInputLineString(fValue, nKey, aRet); - else - throw uno::RuntimeException(); - - return aRet; -} - -// XNumberFormatPreviewer - -rtl::OUString SAL_CALL SvNumberFormatterServiceObj::convertNumberToPreviewString( - const rtl::OUString& aFormat, double fValue, - const lang::Locale& nLocale, sal_Bool bAllowEnglish ) - throw(util::MalformedNumberFormatException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - String aRet; - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - String aOutString; - String aFormString = aFormat; - LanguageType eLang = lcl_GetLanguage( nLocale ); - Color* pColor = NULL; - - sal_Bool bOk; - if ( bAllowEnglish ) - bOk = pFormatter->GetPreviewStringGuess( - aFormString, fValue, aOutString, &pColor, eLang ); - else - bOk = pFormatter->GetPreviewString( - aFormString, fValue, aOutString, &pColor, eLang ); - - if (bOk) - aRet = aOutString; - else - throw util::MalformedNumberFormatException(); - } - else - throw uno::RuntimeException(); - - return aRet; -} - -util::Color SAL_CALL SvNumberFormatterServiceObj::queryPreviewColorForNumber( - const rtl::OUString& aFormat, double fValue, - const lang::Locale& nLocale, sal_Bool bAllowEnglish, - util::Color aDefaultColor ) - throw(util::MalformedNumberFormatException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - util::Color nRet = aDefaultColor; // color = sal_Int32 - SvNumberFormatter* pFormatter = xSupplier.is() ? xSupplier->GetNumberFormatter() : NULL; - if (pFormatter) - { - String aOutString; - String aFormString = aFormat; - LanguageType eLang = lcl_GetLanguage( nLocale ); - Color* pColor = NULL; - - sal_Bool bOk; - if ( bAllowEnglish ) - bOk = pFormatter->GetPreviewStringGuess( - aFormString, fValue, aOutString, &pColor, eLang ); - else - bOk = pFormatter->GetPreviewString( - aFormString, fValue, aOutString, &pColor, eLang ); - - if (bOk) - { - if (pColor) - nRet = pColor->GetColor(); - // sonst Default behalten - } - else - throw util::MalformedNumberFormatException(); - } - else - throw uno::RuntimeException(); - - return nRet; -} - -// XServiceInfo - -rtl::OUString SAL_CALL SvNumberFormatterServiceObj::getImplementationName() - throw(uno::RuntimeException) -{ - return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject")); -} - -sal_Bool SAL_CALL SvNumberFormatterServiceObj::supportsService( const rtl::OUString& ServiceName ) - throw(uno::RuntimeException) -{ - return ( ServiceName.compareToAscii(SERVICENAME_NUMBERFORMATTER) == 0 ); -} - -uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatterServiceObj::getSupportedServiceNames() - throw(uno::RuntimeException) -{ - uno::Sequence<rtl::OUString> aRet(1); - rtl::OUString* pArray = aRet.getArray(); - pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME_NUMBERFORMATTER)); - return aRet; -} - -//------------------------------------------------------------------------ - -SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj& _rParent, ::comphelper::SharedMutex& _rMutex ) - :rSupplier( _rParent ) - ,m_aMutex( _rMutex ) -{ - rSupplier.acquire(); -} - -SvNumberFormatsObj::~SvNumberFormatsObj() -{ - rSupplier.release(); -} - -// XNumberFormats - -uno::Reference<beans::XPropertySet> SAL_CALL SvNumberFormatsObj::getByKey( sal_Int32 nKey ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : NULL; - if (pFormat) - return new SvNumberFormatObj( rSupplier, nKey, m_aMutex ); - else - throw uno::RuntimeException(); -} - -uno::Sequence<sal_Int32> SAL_CALL SvNumberFormatsObj::queryKeys( sal_Int16 nType, - const lang::Locale& nLocale, sal_Bool bCreate ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if ( pFormatter ) - { - sal_uInt32 nIndex = 0; - LanguageType eLang = lcl_GetLanguage( nLocale ); - SvNumberFormatTable& rTable = bCreate ? - pFormatter->ChangeCL( nType, nIndex, eLang ) : - pFormatter->GetEntryTable( nType, nIndex, eLang ); - sal_uInt32 nCount = rTable.Count(); - uno::Sequence<sal_Int32> aSeq(nCount); - sal_Int32* pAry = aSeq.getArray(); - for (sal_uInt32 i=0; i<nCount; i++) - pAry[i] = rTable.GetObjectKey( i ); - - return aSeq; - } - else - throw uno::RuntimeException(); -} - -sal_Int32 SAL_CALL SvNumberFormatsObj::queryKey( const rtl::OUString& aFormat, - const lang::Locale& nLocale, sal_Bool bScan ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - String aFormStr = aFormat; - LanguageType eLang = lcl_GetLanguage( nLocale ); - if (bScan) - { - //! irgendwas muss hier noch passieren... - } - nRet = pFormatter->GetEntryKey( aFormat, eLang ); - } - else - throw uno::RuntimeException(); - - return nRet; -} - -sal_Int32 SAL_CALL SvNumberFormatsObj::addNew( const rtl::OUString& aFormat, - const lang::Locale& nLocale ) - throw(util::MalformedNumberFormatException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - String aFormStr = aFormat; - LanguageType eLang = lcl_GetLanguage( nLocale ); - sal_uInt32 nKey = 0; - xub_StrLen nCheckPos = 0; - short nType = 0; - sal_Bool bOk = pFormatter->PutEntry( aFormStr, nCheckPos, nType, nKey, eLang ); - if (bOk) - nRet = nKey; - else if (nCheckPos) - { - throw util::MalformedNumberFormatException(); // ungueltiges Format - } - else - throw uno::RuntimeException(); // anderer Fehler (z.B. schon vorhanden) - } - else - throw uno::RuntimeException(); - - return nRet; -} - -sal_Int32 SAL_CALL SvNumberFormatsObj::addNewConverted( const rtl::OUString& aFormat, - const lang::Locale& nLocale, const lang::Locale& nNewLocale ) - throw(util::MalformedNumberFormatException, uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - String aFormStr = aFormat; - LanguageType eLang = lcl_GetLanguage( nLocale ); - LanguageType eNewLang = lcl_GetLanguage( nNewLocale ); - sal_uInt32 nKey = 0; - xub_StrLen nCheckPos = 0; - short nType = 0; - sal_Bool bOk = pFormatter->PutandConvertEntry( aFormStr, nCheckPos, nType, nKey, eLang, eNewLang ); - if (bOk || nKey > 0) - nRet = nKey; - else if (nCheckPos) - { - throw util::MalformedNumberFormatException(); // ungueltiges Format - } - else - throw uno::RuntimeException(); // anderer Fehler (z.B. schon vorhanden) - } - else - throw uno::RuntimeException(); - - return nRet; -} - -void SAL_CALL SvNumberFormatsObj::removeByKey( sal_Int32 nKey ) throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - - if (pFormatter) - { - pFormatter->DeleteEntry(nKey); - rSupplier.NumberFormatDeleted(nKey); // Benachrichtigung fuers Dokument - } -} - -rtl::OUString SAL_CALL SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey, - const lang::Locale& nLocale, sal_Bool bThousands, - sal_Bool bRed, sal_Int16 nDecimals, sal_Int16 nLeading ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - String aRet; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - LanguageType eLang = lcl_GetLanguage( nLocale ); - pFormatter->GenerateFormat( aRet, nBaseKey, eLang, bThousands, bRed, nDecimals, nLeading ); - } - else - throw uno::RuntimeException(); - - return aRet; -} - -// XNumberFormatTypes - -sal_Int32 SAL_CALL SvNumberFormatsObj::getStandardIndex( const lang::Locale& nLocale ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - LanguageType eLang = lcl_GetLanguage( nLocale ); - nRet = pFormatter->GetStandardIndex(eLang); - } - else - throw uno::RuntimeException(); - - return nRet; -} - -sal_Int32 SAL_CALL SvNumberFormatsObj::getStandardFormat( sal_Int16 nType, const lang::Locale& nLocale ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - LanguageType eLang = lcl_GetLanguage( nLocale ); - // mask out "defined" bit, so type from an existing number format - // can directly be used for getStandardFormat - nType &= ~NUMBERFORMAT_DEFINED; - nRet = pFormatter->GetStandardFormat(nType, eLang); - } - else - throw uno::RuntimeException(); - - return nRet; -} - -sal_Int32 SAL_CALL SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex, const lang::Locale& nLocale ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - LanguageType eLang = lcl_GetLanguage( nLocale ); - nRet = pFormatter->GetFormatIndex( (NfIndexTableOffset)nIndex, eLang ); - } - else - throw uno::RuntimeException(); - - return nRet; -} - -sal_Bool SAL_CALL SvNumberFormatsObj::isTypeCompatible( sal_Int16 nOldType, sal_Int16 nNewType ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Bool bRet = sal_False; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - bRet = pFormatter->IsCompatible( nOldType, nNewType ); - else - throw uno::RuntimeException(); - - return bRet; -} - -sal_Int32 SAL_CALL SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey, const lang::Locale& nLocale ) - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - sal_Int32 nRet = 0; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - LanguageType eLang = lcl_GetLanguage( nLocale ); - nRet = pFormatter->GetFormatForLanguageIfBuiltIn(nKey, eLang); - } - else - throw uno::RuntimeException(); - - return nRet; -} - -// XServiceInfo - -rtl::OUString SAL_CALL SvNumberFormatsObj::getImplementationName() - throw(uno::RuntimeException) -{ - return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SvNumberFormatsObj")); -} - -sal_Bool SAL_CALL SvNumberFormatsObj::supportsService( const rtl::OUString& ServiceName ) - throw(uno::RuntimeException) -{ - return ( ServiceName.compareToAscii(SERVICENAME_NUMBERFORMATS) == 0 ); -} - -uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatsObj::getSupportedServiceNames() - throw(uno::RuntimeException) -{ - uno::Sequence<rtl::OUString> aRet(1); - rtl::OUString* pArray = aRet.getArray(); - pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME_NUMBERFORMATS)); - return aRet; -} - -//------------------------------------------------------------------------ - -SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj& rParent, sal_uLong nK, const ::comphelper::SharedMutex& _rMutex ) - :rSupplier( rParent ) - ,nKey( nK ) - ,m_aMutex( _rMutex ) -{ - rSupplier.acquire(); -} - -SvNumberFormatObj::~SvNumberFormatObj() -{ - rSupplier.release(); -} - -// XPropertySet - -uno::Reference<beans::XPropertySetInfo> SAL_CALL SvNumberFormatObj::getPropertySetInfo() - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - static uno::Reference<beans::XPropertySetInfo> aRef = - new SfxItemPropertySetInfo( lcl_GetNumberFormatPropertyMap() ); - return aRef; -} - -void SAL_CALL SvNumberFormatObj::setPropertyValue( const rtl::OUString&, - const uno::Any& ) - throw(beans::UnknownPropertyException, beans::PropertyVetoException, - lang::IllegalArgumentException, lang::WrappedTargetException, - uno::RuntimeException) -{ - throw beans::UnknownPropertyException(); // everything is read-only -} - -uno::Any SAL_CALL SvNumberFormatObj::getPropertyValue( const rtl::OUString& aPropertyName ) - throw(beans::UnknownPropertyException, lang::WrappedTargetException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - uno::Any aRet; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : NULL; - if (pFormat) - { - sal_Bool bThousand, bRed; - sal_uInt16 nDecimals, nLeading; - - String aString = aPropertyName; - if (aString.EqualsAscii( PROPERTYNAME_FMTSTR )) - { - aRet <<= rtl::OUString( pFormat->GetFormatstring() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_LOCALE )) - { - lang::Locale aLocale( MsLangId::convertLanguageToLocale( - pFormat->GetLanguage())); - aRet <<= aLocale; - } - else if (aString.EqualsAscii( PROPERTYNAME_TYPE )) - { - aRet <<= (sal_Int16)( pFormat->GetType() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_COMMENT )) - { - aRet <<= rtl::OUString( pFormat->GetComment() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_STDFORM )) - { - //! SvNumberformat Member bStandard rausreichen? - sal_Bool bStandard = ( ( nKey % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 ); - aRet.setValue( &bStandard, getBooleanCppuType() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_USERDEF )) - { - sal_Bool bUserDef = ( ( pFormat->GetType() & NUMBERFORMAT_DEFINED ) != 0 ); - aRet.setValue( &bUserDef, getBooleanCppuType() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_DECIMALS )) - { - pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading ); - aRet <<= (sal_Int16)( nDecimals ); - } - else if (aString.EqualsAscii( PROPERTYNAME_LEADING )) - { - pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading ); - aRet <<= (sal_Int16)( nLeading ); - } - else if (aString.EqualsAscii( PROPERTYNAME_NEGRED )) - { - pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading ); - aRet.setValue( &bRed, getBooleanCppuType() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_THOUS )) - { - pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading ); - aRet.setValue( &bThousand, getBooleanCppuType() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_CURRSYM )) - { - String aSymbol, aExt; - pFormat->GetNewCurrencySymbol( aSymbol, aExt ); - aRet <<= rtl::OUString( aSymbol ); - } - else if (aString.EqualsAscii( PROPERTYNAME_CURREXT )) - { - String aSymbol, aExt; - pFormat->GetNewCurrencySymbol( aSymbol, aExt ); - aRet <<= rtl::OUString( aExt ); - } - else if (aString.EqualsAscii( PROPERTYNAME_CURRABB )) - { - String aSymbol, aExt; - sal_Bool bBank = sal_False; - pFormat->GetNewCurrencySymbol( aSymbol, aExt ); - const NfCurrencyEntry* pCurr = pFormatter->GetCurrencyEntry( bBank, - aSymbol, aExt, pFormat->GetLanguage() ); - if ( pCurr ) - aRet <<= rtl::OUString( pCurr->GetBankSymbol() ); - else - aRet <<= rtl::OUString(); - } - else - throw beans::UnknownPropertyException(); - } - else - throw uno::RuntimeException(); - - return aRet; -} - -void SAL_CALL SvNumberFormatObj::addPropertyChangeListener( const rtl::OUString&, - const uno::Reference<beans::XPropertyChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -void SAL_CALL SvNumberFormatObj::removePropertyChangeListener( const rtl::OUString&, - const uno::Reference<beans::XPropertyChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -void SAL_CALL SvNumberFormatObj::addVetoableChangeListener( const rtl::OUString&, - const uno::Reference<beans::XVetoableChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -void SAL_CALL SvNumberFormatObj::removeVetoableChangeListener( const rtl::OUString&, - const uno::Reference<beans::XVetoableChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -// XPropertyAccess - -uno::Sequence<beans::PropertyValue> SAL_CALL SvNumberFormatObj::getPropertyValues() - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : NULL; - if (pFormat) - { - String aSymbol, aExt, aAbb; - sal_Bool bBank = sal_False; - pFormat->GetNewCurrencySymbol( aSymbol, aExt ); - const NfCurrencyEntry* pCurr = pFormatter->GetCurrencyEntry( bBank, - aSymbol, aExt, pFormat->GetLanguage() ); - if ( pCurr ) - aAbb = pCurr->GetBankSymbol(); - - String aFmtStr = pFormat->GetFormatstring(); - String aComment = pFormat->GetComment(); - sal_Bool bStandard = ( ( nKey % SV_COUNTRY_LANGUAGE_OFFSET ) == 0 ); - //! SvNumberformat Member bStandard rausreichen? - sal_Bool bUserDef = ( ( pFormat->GetType() & NUMBERFORMAT_DEFINED ) != 0 ); - sal_Bool bThousand, bRed; - sal_uInt16 nDecimals, nLeading; - pFormat->GetFormatSpecialInfo( bThousand, bRed, nDecimals, nLeading ); - lang::Locale aLocale( MsLangId::convertLanguageToLocale( - pFormat->GetLanguage())); - - uno::Sequence<beans::PropertyValue> aSeq(13); - beans::PropertyValue* pArray = aSeq.getArray(); - - pArray[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_FMTSTR )); - pArray[0].Value <<= rtl::OUString( aFmtStr ); - pArray[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_LOCALE )); - pArray[1].Value <<= aLocale; - pArray[2].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_TYPE )); - pArray[2].Value <<= (sal_Int16)( pFormat->GetType() ); - pArray[3].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_COMMENT )); - pArray[3].Value <<= rtl::OUString( aComment ); - pArray[4].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_STDFORM )); - pArray[4].Value.setValue( &bStandard, getBooleanCppuType() ); - pArray[5].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_USERDEF )); - pArray[5].Value.setValue( &bUserDef, getBooleanCppuType() ); - pArray[6].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_DECIMALS )); - pArray[6].Value <<= (sal_Int16)( nDecimals ); - pArray[7].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_LEADING )); - pArray[7].Value <<= (sal_Int16)( nLeading ); - pArray[8].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_NEGRED )); - pArray[8].Value.setValue( &bRed, getBooleanCppuType() ); - pArray[9].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_THOUS )); - pArray[9].Value.setValue( &bThousand, getBooleanCppuType() ); - pArray[10].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_CURRSYM )); - pArray[10].Value <<= rtl::OUString( aSymbol ); - pArray[11].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_CURREXT )); - pArray[11].Value <<= rtl::OUString( aExt ); - pArray[12].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( PROPERTYNAME_CURRABB )); - pArray[12].Value <<= rtl::OUString( aAbb ); - - return aSeq; - } - else - throw uno::RuntimeException(); -} - -void SAL_CALL SvNumberFormatObj::setPropertyValues( const uno::Sequence<beans::PropertyValue>& ) - throw(beans::UnknownPropertyException, beans::PropertyVetoException, - lang::IllegalArgumentException, lang::WrappedTargetException, - uno::RuntimeException) -{ - throw beans::UnknownPropertyException(); // everything is read-only -} - -// XServiceInfo - -rtl::OUString SAL_CALL SvNumberFormatObj::getImplementationName() - throw(uno::RuntimeException) -{ - return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SvNumberFormatObj")); -} - -sal_Bool SAL_CALL SvNumberFormatObj::supportsService( const rtl::OUString& ServiceName ) - throw(uno::RuntimeException) -{ - return ( ServiceName.compareToAscii(SERVICENAME_NUMBERFORMAT) == 0 ); -} - -uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatObj::getSupportedServiceNames() - throw(uno::RuntimeException) -{ - uno::Sequence<rtl::OUString> aRet(1); - rtl::OUString* pArray = aRet.getArray(); - pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME_NUMBERFORMAT)); - return aRet; -} - -//------------------------------------------------------------------------ - -SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj& rParent, const ::comphelper::SharedMutex& _rMutex ) - :rSupplier( rParent ) - ,m_aMutex( _rMutex ) -{ - rSupplier.acquire(); -} - -SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj() -{ - rSupplier.release(); -} - -// XPropertySet - -uno::Reference<beans::XPropertySetInfo> SAL_CALL SvNumberFormatSettingsObj::getPropertySetInfo() - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - static uno::Reference<beans::XPropertySetInfo> aRef = - new SfxItemPropertySetInfo( lcl_GetNumberSettingsPropertyMap() ); - return aRef; -} - -void SAL_CALL SvNumberFormatSettingsObj::setPropertyValue( const rtl::OUString& aPropertyName, - const uno::Any& aValue ) - throw(beans::UnknownPropertyException, beans::PropertyVetoException, - lang::IllegalArgumentException, lang::WrappedTargetException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - String aString = aPropertyName; - if (aString.EqualsAscii( PROPERTYNAME_NOZERO )) - { - // operator >>= shouldn't be used for bool (?) - if ( aValue.getValueTypeClass() == uno::TypeClass_BOOLEAN ) - pFormatter->SetNoZero( *(sal_Bool*)aValue.getValue() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_NULLDATE )) - { - util::Date aDate; - if ( aValue >>= aDate ) - pFormatter->ChangeNullDate( aDate.Day, aDate.Month, aDate.Year ); - } - else if (aString.EqualsAscii( PROPERTYNAME_STDDEC )) - { - sal_Int16 nInt16 = sal_Int16(); - if ( aValue >>= nInt16 ) - pFormatter->ChangeStandardPrec( nInt16 ); - } - else if (aString.EqualsAscii( PROPERTYNAME_TWODIGIT )) - { - sal_Int16 nInt16 = sal_Int16(); - if ( aValue >>= nInt16 ) - pFormatter->SetYear2000( nInt16 ); - } - else - throw beans::UnknownPropertyException(); - - rSupplier.SettingsChanged(); - } - else - throw uno::RuntimeException(); -} - -uno::Any SAL_CALL SvNumberFormatSettingsObj::getPropertyValue( const rtl::OUString& aPropertyName ) - throw(beans::UnknownPropertyException, lang::WrappedTargetException, - uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - uno::Any aRet; - SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter(); - if (pFormatter) - { - String aString = aPropertyName; - if (aString.EqualsAscii( PROPERTYNAME_NOZERO )) - { - sal_Bool bNoZero = pFormatter->GetNoZero(); - aRet.setValue( &bNoZero, getBooleanCppuType() ); - } - else if (aString.EqualsAscii( PROPERTYNAME_NULLDATE )) - { - Date* pDate = pFormatter->GetNullDate(); - if (pDate) - { - util::Date aUnoDate( pDate->GetDay(), pDate->GetMonth(), pDate->GetYear() ); - aRet <<= aUnoDate; - } - } - else if (aString.EqualsAscii( PROPERTYNAME_STDDEC )) - aRet <<= (sal_Int16)( pFormatter->GetStandardPrec() ); - else if (aString.EqualsAscii( PROPERTYNAME_TWODIGIT )) - aRet <<= (sal_Int16)( pFormatter->GetYear2000() ); - else - throw beans::UnknownPropertyException(); - } - else - throw uno::RuntimeException(); - - return aRet; -} - -void SAL_CALL SvNumberFormatSettingsObj::addPropertyChangeListener( const rtl::OUString&, - const uno::Reference<beans::XPropertyChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -void SAL_CALL SvNumberFormatSettingsObj::removePropertyChangeListener( const rtl::OUString&, - const uno::Reference<beans::XPropertyChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -void SAL_CALL SvNumberFormatSettingsObj::addVetoableChangeListener( const rtl::OUString&, - const uno::Reference<beans::XVetoableChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -void SAL_CALL SvNumberFormatSettingsObj::removeVetoableChangeListener( const rtl::OUString&, - const uno::Reference<beans::XVetoableChangeListener>&) - throw(beans::UnknownPropertyException, - lang::WrappedTargetException, uno::RuntimeException) -{ - OSL_FAIL("not implemented"); -} - -// XServiceInfo - -rtl::OUString SAL_CALL SvNumberFormatSettingsObj::getImplementationName() - throw(uno::RuntimeException) -{ - return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SvNumberFormatSettingsObj")); -} - -sal_Bool SAL_CALL SvNumberFormatSettingsObj::supportsService( const rtl::OUString& ServiceName ) - throw(uno::RuntimeException) -{ - return ( ServiceName.compareToAscii(SERVICENAME_NUMBERSETTINGS) == 0 ); -} - -uno::Sequence<rtl::OUString> SAL_CALL SvNumberFormatSettingsObj::getSupportedServiceNames() - throw(uno::RuntimeException) -{ - uno::Sequence<rtl::OUString> aRet(1); - rtl::OUString* pArray = aRet.getArray(); - pArray[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME_NUMBERSETTINGS)); - return aRet; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/numfmuno.hxx b/svl/source/numbers/numfmuno.hxx deleted file mode 100644 index 9909226cfe..0000000000 --- a/svl/source/numbers/numfmuno.hxx +++ /dev/null @@ -1,323 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _NUMFMUNO_HXX -#define _NUMFMUNO_HXX - -#include <com/sun/star/util/XNumberFormatter.hpp> -#include <com/sun/star/util/XNumberFormatPreviewer.hpp> -#include <com/sun/star/util/XNumberFormats.hpp> -#include <com/sun/star/util/XNumberFormatTypes.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/beans/XPropertyAccess.hpp> -#include <cppuhelper/implbase2.hxx> -#include <cppuhelper/implbase3.hxx> -#include <comphelper/sharedmutex.hxx> -#include <rtl/ref.hxx> - -class SvNumberformat; -class SvNumberFormatter; -class SvNumberFormatsSupplierObj; - - -// SvNumberFormatterServiceObj wird global als Service angemeldet - -class SvNumberFormatterServiceObj : public cppu::WeakImplHelper3< - com::sun::star::util::XNumberFormatter, - com::sun::star::util::XNumberFormatPreviewer, - com::sun::star::lang::XServiceInfo> -{ -private: - ::rtl::Reference< SvNumberFormatsSupplierObj > xSupplier; - mutable ::comphelper::SharedMutex m_aMutex; - -public: - SvNumberFormatterServiceObj(); - virtual ~SvNumberFormatterServiceObj(); - - // XNumberFormatter - virtual void SAL_CALL attachNumberFormatsSupplier( - const ::com::sun::star::uno::Reference< - ::com::sun::star::util::XNumberFormatsSupplier >& xSupplier ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > - SAL_CALL getNumberFormatsSupplier() - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL detectNumberFormat( sal_Int32 nKey, const ::rtl::OUString& aString ) - throw(::com::sun::star::util::NotNumericException, - ::com::sun::star::uno::RuntimeException); - virtual double SAL_CALL convertStringToNumber( sal_Int32 nKey, const ::rtl::OUString& aString ) - throw(::com::sun::star::util::NotNumericException, - ::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL convertNumberToString( sal_Int32 nKey, double fValue ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::util::Color SAL_CALL queryColorForNumber( sal_Int32 nKey, - double fValue, ::com::sun::star::util::Color aDefaultColor ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL formatString( sal_Int32 nKey, const ::rtl::OUString& aString ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::util::Color SAL_CALL queryColorForString( sal_Int32 nKey, - const ::rtl::OUString& aString, - ::com::sun::star::util::Color aDefaultColor ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL getInputString( sal_Int32 nKey, double fValue ) - throw(::com::sun::star::uno::RuntimeException); - - // XNumberFormatPreviewer - virtual ::rtl::OUString SAL_CALL convertNumberToPreviewString( - const ::rtl::OUString& aFormat, double fValue, - const ::com::sun::star::lang::Locale& nLocale, sal_Bool bAllowEnglish ) - throw(::com::sun::star::util::MalformedNumberFormatException, - ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::util::Color SAL_CALL queryPreviewColorForNumber( - const ::rtl::OUString& aFormat, double fValue, - const ::com::sun::star::lang::Locale& nLocale, sal_Bool bAllowEnglish, - ::com::sun::star::util::Color aDefaultColor ) - throw(::com::sun::star::util::MalformedNumberFormatException, - ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() - throw(::com::sun::star::uno::RuntimeException); -}; - - -class SvNumberFormatsObj : public cppu::WeakImplHelper3< - com::sun::star::util::XNumberFormats, - com::sun::star::util::XNumberFormatTypes, - com::sun::star::lang::XServiceInfo> -{ -private: - SvNumberFormatsSupplierObj& rSupplier; - mutable ::comphelper::SharedMutex m_aMutex; - -public: - SvNumberFormatsObj(SvNumberFormatsSupplierObj& pParent, ::comphelper::SharedMutex& _rMutex); - virtual ~SvNumberFormatsObj(); - - - // XNumberFormats - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL - getByKey( sal_Int32 nKey ) throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL queryKeys( sal_Int16 nType, - const ::com::sun::star::lang::Locale& nLocale, sal_Bool bCreate ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL queryKey( const ::rtl::OUString& aFormat, - const ::com::sun::star::lang::Locale& nLocale, sal_Bool bScan ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL addNew( const ::rtl::OUString& aFormat, - const ::com::sun::star::lang::Locale& nLocale ) - throw(::com::sun::star::util::MalformedNumberFormatException, - ::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL addNewConverted( const ::rtl::OUString& aFormat, - const ::com::sun::star::lang::Locale& nLocale, - const ::com::sun::star::lang::Locale& nNewLocale ) - throw(::com::sun::star::util::MalformedNumberFormatException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeByKey( sal_Int32 nKey ) throw(::com::sun::star::uno::RuntimeException); - virtual ::rtl::OUString SAL_CALL generateFormat( sal_Int32 nBaseKey, - const ::com::sun::star::lang::Locale& nLocale, sal_Bool bThousands, - sal_Bool bRed, sal_Int16 nDecimals, sal_Int16 nLeading ) - throw(::com::sun::star::uno::RuntimeException); - - // XNumberFormatTypes - virtual sal_Int32 SAL_CALL getStandardIndex( const ::com::sun::star::lang::Locale& nLocale ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL getStandardFormat( sal_Int16 nType, - const ::com::sun::star::lang::Locale& nLocale ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL getFormatIndex( sal_Int16 nIndex, - const ::com::sun::star::lang::Locale& nLocale ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL isTypeCompatible( sal_Int16 nOldType, sal_Int16 nNewType ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Int32 SAL_CALL getFormatForLocale( sal_Int32 nKey, - const ::com::sun::star::lang::Locale& nLocale ) - throw(::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() - throw(::com::sun::star::uno::RuntimeException); - -private: - SvNumberFormatsObj(); // never implemented -}; - - -class SvNumberFormatObj : public cppu::WeakImplHelper3< - com::sun::star::beans::XPropertySet, - com::sun::star::beans::XPropertyAccess, - com::sun::star::lang::XServiceInfo> -{ -private: - SvNumberFormatsSupplierObj& rSupplier; - sal_uLong nKey; - mutable ::comphelper::SharedMutex m_aMutex; - -public: - SvNumberFormatObj( SvNumberFormatsSupplierObj& rParent, sal_uLong nK, const ::comphelper::SharedMutex& _rMutex ); - virtual ~SvNumberFormatObj(); - - // XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > - SAL_CALL getPropertySetInfo( ) - throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Any& aValue ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( - const ::rtl::OUString& PropertyName ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertyChangeListener >& xListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertyChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - // XPropertyAccess - virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL - getPropertyValues() throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setPropertyValues( const ::com::sun::star::uno::Sequence< - ::com::sun::star::beans::PropertyValue >& aProps ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() - throw(::com::sun::star::uno::RuntimeException); -}; - - -class SvNumberFormatSettingsObj : public cppu::WeakImplHelper2< - com::sun::star::beans::XPropertySet, - com::sun::star::lang::XServiceInfo> -{ -private: - SvNumberFormatsSupplierObj& rSupplier; - mutable ::comphelper::SharedMutex m_aMutex; - -public: - SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj& rParent, const ::comphelper::SharedMutex& _rMutex); - virtual ~SvNumberFormatSettingsObj(); - - - // XPropertySet - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > - SAL_CALL getPropertySetInfo( ) - throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Any& aValue ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::beans::PropertyVetoException, - ::com::sun::star::lang::IllegalArgumentException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( - const ::rtl::OUString& PropertyName ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertyChangeListener >& xListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& aPropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertyChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& PropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& PropertyName, - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XVetoableChangeListener >& aListener ) - throw(::com::sun::star::beans::UnknownPropertyException, - ::com::sun::star::lang::WrappedTargetException, - ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) - throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) - throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() - throw(::com::sun::star::uno::RuntimeException); -}; - - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/numhead.cxx b/svl/source/numbers/numhead.cxx deleted file mode 100644 index c1b3b7d7d2..0000000000 --- a/svl/source/numbers/numhead.cxx +++ /dev/null @@ -1,249 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <tools/debug.hxx> - -#include "numhead.hxx" - -// ID's fuer Dateien: -#define SV_NUMID_SIZES 0x4200 - -// STATIC DATA ----------------------------------------------------------- - -//SEG_EOFGLOBALS() - -// ======================================================================= -/* wird fuer SvNumberformatter nicht gebraucht -//#pragma SEG_FUNCDEF(numhead_01) - -SvNumReadHeader::SvNumReadHeader(SvStream& rNewStream) : - rStream( rNewStream ) -{ - sal_uLong nDataSize; - rStream >> nDataSize; - nDataEnd = rStream.Tell() + nDataSize; -} - -//#pragma SEG_FUNCDEF(numhead_02) - -SvNumReadHeader::~SvNumReadHeader() -{ - sal_uLong nReadEnd = rStream.Tell(); - DBG_ASSERT( nReadEnd <= nDataEnd, "zuviele Bytes gelesen" ); - if ( nReadEnd != nDataEnd ) - rStream.Seek(nDataEnd); // Rest ueberspringen -} - -//#pragma SEG_FUNCDEF(numhead_03) - -sal_uLong SvNumReadHeader::BytesLeft() const -{ - sal_uLong nReadEnd = rStream.Tell(); - if (nReadEnd <= nDataEnd) - return nDataEnd-nReadEnd; - - OSL_FAIL("Fehler bei SvNumReadHeader::BytesLeft"); - return 0; -} - -// ----------------------------------------------------------------------- - -//#pragma SEG_FUNCDEF(numhead_04) - -SvNumWriteHeader::SvNumWriteHeader(SvStream& rNewStream, sal_uLong nDefault) : - rStream( rNewStream ) -{ - nDataSize = nDefault; - rStream << nDataSize; - nDataPos = rStream.Tell(); -} - -//#pragma SEG_FUNCDEF(numhead_05) - -SvNumWriteHeader::~SvNumWriteHeader() -{ - sal_uLong nPos = rStream.Tell(); - - if ( nPos - nDataPos != nDataSize ) // Default getroffen? - { - nDataSize = nPos - nDataPos; - rStream.Seek(nDataPos - sizeof(sal_uInt32)); - rStream << nDataSize; // Groesse am Anfang eintragen - rStream.Seek(nPos); - } -} -*/ - -// ======================================================================= - -//#pragma SEG_FUNCDEF(numhead_06) - -//! mit Skip() synchron -ImpSvNumMultipleReadHeader::ImpSvNumMultipleReadHeader(SvStream& rNewStream) : - rStream( rNewStream ) -{ - sal_uInt32 nDataSize; - rStream >> nDataSize; - sal_uLong nDataPos = rStream.Tell(); - nEntryEnd = nDataPos; - - rStream.SeekRel(nDataSize); - sal_uInt16 nID; - rStream >> nID; - if (nID != SV_NUMID_SIZES) - { - OSL_FAIL("SV_NUMID_SIZES nicht gefunden"); - } - sal_uInt32 nSizeTableLen; - rStream >> nSizeTableLen; - pBuf = new char[nSizeTableLen]; - rStream.Read( pBuf, nSizeTableLen ); - pMemStream = new SvMemoryStream( pBuf, nSizeTableLen, STREAM_READ ); - - nEndPos = rStream.Tell(); - rStream.Seek( nDataPos ); -} - -//#pragma SEG_FUNCDEF(numhead_07) - -ImpSvNumMultipleReadHeader::~ImpSvNumMultipleReadHeader() -{ - DBG_ASSERT( pMemStream->Tell() == pMemStream->GetEndOfData(), - "Sizes nicht vollstaendig gelesen" ); - delete pMemStream; - delete [] pBuf; - - rStream.Seek(nEndPos); -} - -//! mit ctor synchron -// static -void ImpSvNumMultipleReadHeader::Skip( SvStream& rStream ) -{ - sal_uInt32 nDataSize; - rStream >> nDataSize; - rStream.SeekRel( nDataSize ); - sal_uInt16 nID; - rStream >> nID; - if ( nID != SV_NUMID_SIZES ) - { - OSL_FAIL("SV_NUMID_SIZES nicht gefunden"); - } - sal_uInt32 nSizeTableLen; - rStream >> nSizeTableLen; - rStream.SeekRel( nSizeTableLen ); -} - -//#pragma SEG_FUNCDEF(numhead_08) - -void ImpSvNumMultipleReadHeader::EndEntry() -{ - sal_uLong nPos = rStream.Tell(); - DBG_ASSERT( nPos <= nEntryEnd, "zuviel gelesen" ); - if ( nPos != nEntryEnd ) - rStream.Seek( nEntryEnd ); // Rest ueberspringen -} - -//#pragma SEG_FUNCDEF(numhead_0d) - -void ImpSvNumMultipleReadHeader::StartEntry() -{ - sal_uLong nPos = rStream.Tell(); - sal_uInt32 nEntrySize; - (*pMemStream) >> nEntrySize; - - nEntryEnd = nPos + nEntrySize; -} - -//#pragma SEG_FUNCDEF(numhead_09) - -sal_uLong ImpSvNumMultipleReadHeader::BytesLeft() const -{ - sal_uLong nReadEnd = rStream.Tell(); - if (nReadEnd <= nEntryEnd) - return nEntryEnd-nReadEnd; - - OSL_FAIL("Fehler bei ImpSvNumMultipleReadHeader::BytesLeft"); - return 0; -} - -// ----------------------------------------------------------------------- - -//#pragma SEG_FUNCDEF(numhead_0a) - -ImpSvNumMultipleWriteHeader::ImpSvNumMultipleWriteHeader(SvStream& rNewStream, - sal_uLong nDefault) : - rStream( rNewStream ), - aMemStream( 4096, 4096 ) -{ - nDataSize = nDefault; - rStream << nDataSize; - - nDataPos = rStream.Tell(); - nEntryStart = nDataPos; -} - -//#pragma SEG_FUNCDEF(numhead_0b) - -ImpSvNumMultipleWriteHeader::~ImpSvNumMultipleWriteHeader() -{ - sal_uLong nDataEnd = rStream.Tell(); - - rStream << (sal_uInt16) SV_NUMID_SIZES; - rStream << static_cast<sal_uInt32>(aMemStream.Tell()); - rStream.Write( aMemStream.GetData(), aMemStream.Tell() ); - - if ( nDataEnd - nDataPos != nDataSize ) // Default getroffen? - { - nDataSize = nDataEnd - nDataPos; - sal_uLong nPos = rStream.Tell(); - rStream.Seek(nDataPos-sizeof(sal_uInt32)); - rStream << nDataSize; // Groesse am Anfang eintragen - rStream.Seek(nPos); - } -} - -//#pragma SEG_FUNCDEF(numhead_0c) - -void ImpSvNumMultipleWriteHeader::EndEntry() -{ - sal_uLong nPos = rStream.Tell(); - aMemStream << static_cast<sal_uInt32>(nPos - nEntryStart); -} - -//#pragma SEG_FUNCDEF(numhead_0e) - -void ImpSvNumMultipleWriteHeader::StartEntry() -{ - sal_uLong nPos = rStream.Tell(); - nEntryStart = nPos; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/numhead.hxx b/svl/source/numbers/numhead.hxx deleted file mode 100644 index 4443ebe3a6..0000000000 --- a/svl/source/numbers/numhead.hxx +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 NF_NUMHEAD_HXX -#define NF_NUMHEAD_HXX - -#include <tools/stream.hxx> - -// ----------------------------------------------------------------------- - - // "Automatischer" Record-Header mit Groessenangabe - -/* wird fuer SvNumberFormatter nicht gebraucht -class SvNumReadHeader -{ -private: - SvStream& rStream; - sal_uLong nDataEnd; - -public: - SvNumReadHeader(SvStream& rNewStream); - ~SvNumReadHeader(); - - sal_uLong BytesLeft() const; -}; - -class SvNumWriteHeader -{ -private: - SvStream& rStream; - sal_uLong nDataPos; - sal_uLong nDataSize; - -public: - SvNumWriteHeader(SvStream& rNewStream, sal_uLong nDefault = 0); - ~SvNumWriteHeader(); -}; - -*/ - - // Header mit Groessenangaben fuer mehrere Objekte - -class ImpSvNumMultipleReadHeader -{ -private: - SvStream& rStream; - char* pBuf; - SvMemoryStream* pMemStream; - sal_uLong nEndPos; - sal_uLong nEntryEnd; - -public: - ImpSvNumMultipleReadHeader(SvStream& rNewStream); - ~ImpSvNumMultipleReadHeader(); - - void StartEntry(); - void EndEntry(); - sal_uLong BytesLeft() const; - - static void Skip( SvStream& ); // komplett ueberspringen -}; - -class ImpSvNumMultipleWriteHeader -{ -private: - SvStream& rStream; - SvMemoryStream aMemStream; - sal_uLong nDataPos; - sal_uInt32 nDataSize; - sal_uLong nEntryStart; - -public: - ImpSvNumMultipleWriteHeader(SvStream& rNewStream, sal_uLong nDefault = 0); - ~ImpSvNumMultipleWriteHeader(); - - void StartEntry(); - void EndEntry(); -}; - -#endif - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/numuno.cxx b/svl/source/numbers/numuno.cxx deleted file mode 100644 index 097cdc4611..0000000000 --- a/svl/source/numbers/numuno.cxx +++ /dev/null @@ -1,159 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#define _ZFORLIST_DECLARE_TABLE - -#include <tools/color.hxx> -#include <tools/debug.hxx> -#include <comphelper/servicehelper.hxx> - -#include <svl/numuno.hxx> -#include "numfmuno.hxx" -#include <svl/zforlist.hxx> - -using namespace com::sun::star; - -//------------------------------------------------------------------------ - -class SvNumFmtSuppl_Impl -{ -public: - SvNumberFormatter* pFormatter; - mutable ::comphelper::SharedMutex aMutex; - - SvNumFmtSuppl_Impl(SvNumberFormatter* p) : - pFormatter(p) {} -}; - -//------------------------------------------------------------------------ - -// Default-ctor fuer getReflection -SvNumberFormatsSupplierObj::SvNumberFormatsSupplierObj() -{ - pImpl = new SvNumFmtSuppl_Impl(NULL); -} - -SvNumberFormatsSupplierObj::SvNumberFormatsSupplierObj(SvNumberFormatter* pForm) -{ - pImpl = new SvNumFmtSuppl_Impl(pForm); -} - -SvNumberFormatsSupplierObj::~SvNumberFormatsSupplierObj() -{ - delete pImpl; -} - -::comphelper::SharedMutex& SvNumberFormatsSupplierObj::getSharedMutex() const -{ - return pImpl->aMutex; -} - -SvNumberFormatter* SvNumberFormatsSupplierObj::GetNumberFormatter() const -{ - return pImpl->pFormatter; -} - -void SvNumberFormatsSupplierObj::SetNumberFormatter(SvNumberFormatter* pNew) -{ - // der alte Numberformatter ist ungueltig geworden, nicht mehr darauf zugreifen! - pImpl->pFormatter = pNew; -} - -void SvNumberFormatsSupplierObj::NumberFormatDeleted(sal_uInt32) -{ - // Basis-Implementierung tut nix... -} - -void SvNumberFormatsSupplierObj::SettingsChanged() -{ - // Basis-Implementierung tut nix... -} - -// XNumberFormatsSupplier - -uno::Reference<beans::XPropertySet> SAL_CALL SvNumberFormatsSupplierObj::getNumberFormatSettings() - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( pImpl->aMutex ); - - return new SvNumberFormatSettingsObj( *this, pImpl->aMutex ); -} - -uno::Reference<util::XNumberFormats> SAL_CALL SvNumberFormatsSupplierObj::getNumberFormats() - throw(uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( pImpl->aMutex ); - - return new SvNumberFormatsObj( *this, pImpl->aMutex ); -} - -// XUnoTunnel - -sal_Int64 SAL_CALL SvNumberFormatsSupplierObj::getSomething( - const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) -{ - if ( rId.getLength() == 16 && - 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), - rId.getConstArray(), 16 ) ) - { - return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this)); - } - return 0; -} - -namespace -{ - class theSvNumberFormatsSupplierObjUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvNumberFormatsSupplierObjUnoTunnelId > {}; -} - -// static -const uno::Sequence<sal_Int8>& SvNumberFormatsSupplierObj::getUnoTunnelId() -{ - return theSvNumberFormatsSupplierObjUnoTunnelId::get().getSeq(); -} - -// static -SvNumberFormatsSupplierObj* SvNumberFormatsSupplierObj::getImplementation( - const uno::Reference<util::XNumberFormatsSupplier> xObj ) -{ - SvNumberFormatsSupplierObj* pRet = NULL; - uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); - if (xUT.is()) - pRet = reinterpret_cast<SvNumberFormatsSupplierObj*>(sal::static_int_cast<sal_IntPtr>(xUT->getSomething( getUnoTunnelId() ))); - return pRet; -} - - -//------------------------------------------------------------------------ - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/supservs.cxx b/svl/source/numbers/supservs.cxx deleted file mode 100644 index a8ef48114c..0000000000 --- a/svl/source/numbers/supservs.cxx +++ /dev/null @@ -1,230 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include "supservs.hxx" -#include <com/sun/star/lang/Locale.hpp> -#include <comphelper/sharedmutex.hxx> -#include <i18npool/mslangid.hxx> -#include <tools/debug.hxx> -#include <osl/mutex.hxx> -#include <tools/stream.hxx> -#include <svl/strmadpt.hxx> -#include <svl/instrm.hxx> - -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::io; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::util; -using namespace ::utl; - -#define PERSISTENT_SERVICE_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatsSupplier")); - -//------------------------------------------------------------------------- -Reference< XInterface > SAL_CALL SvNumberFormatsSupplierServiceObject_CreateInstance(const Reference< XMultiServiceFactory >& _rxFactory) -{ - return static_cast< ::cppu::OWeakObject* >(new SvNumberFormatsSupplierServiceObject(_rxFactory)); -} - -//------------------------------------------------------------------------- -SvNumberFormatsSupplierServiceObject::SvNumberFormatsSupplierServiceObject(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB) - :m_pOwnFormatter(NULL) - ,m_xORB(_rxORB) -{ -} - -//------------------------------------------------------------------------- -SvNumberFormatsSupplierServiceObject::~SvNumberFormatsSupplierServiceObject() -{ - if (m_pOwnFormatter) - { - delete m_pOwnFormatter; - m_pOwnFormatter = NULL; - } -} - -//------------------------------------------------------------------------- -Any SAL_CALL SvNumberFormatsSupplierServiceObject::queryAggregation( const Type& _rType ) throw (RuntimeException) -{ - Any aReturn = ::cppu::queryInterface(_rType, - static_cast< XInitialization* >(this), - static_cast< XPersistObject* >(this), - static_cast< XServiceInfo* >(this) - ); - - if (!aReturn.hasValue()) - aReturn = SvNumberFormatsSupplierObj::queryAggregation(_rType); - - return aReturn; -} - -//------------------------------------------------------------------------- -void SAL_CALL SvNumberFormatsSupplierServiceObject::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException) -{ - ::osl::MutexGuard aGuard( getSharedMutex() ); - - DBG_ASSERT(m_pOwnFormatter == NULL, - "SvNumberFormatsSupplierServiceObject::initialize : already initialized !"); - // maybe you already called a method which needed the formatter - // you should use XMultiServiceFactory::createInstanceWithArguments to avoid that - if (m_pOwnFormatter) - { // !!! this is only a emergency handling, normally this should not occur !!! - delete m_pOwnFormatter; - m_pOwnFormatter = NULL; - SetNumberFormatter(m_pOwnFormatter); - } - - Type aExpectedArgType = ::getCppuType(static_cast<Locale*>(NULL)); - LanguageType eNewFormatterLanguage = LANGUAGE_ENGLISH_US; - // the default - - const Any* pArgs = _rArguments.getConstArray(); - for (sal_Int32 i=0; i<_rArguments.getLength(); ++i, ++pArgs) - { - if (pArgs->getValueType().equals(aExpectedArgType)) - { - Locale aLocale; - *pArgs >>= aLocale; - eNewFormatterLanguage = MsLangId::convertLocaleToLanguage( aLocale); - } -#ifdef DBG_UTIL - else - { - OSL_FAIL("SvNumberFormatsSupplierServiceObject::initialize : unknown argument !"); - } -#endif - } - - m_pOwnFormatter = new SvNumberFormatter(m_xORB, eNewFormatterLanguage); - m_pOwnFormatter->SetEvalDateFormat( NF_EVALDATEFORMAT_FORMAT_INTL ); - SetNumberFormatter(m_pOwnFormatter); -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getImplementationName( ) throw(RuntimeException) -{ - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject")); -} - -//------------------------------------------------------------------------- -sal_Bool SAL_CALL SvNumberFormatsSupplierServiceObject::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException) -{ - Sequence< ::rtl::OUString > aServices = getSupportedServiceNames(); - const ::rtl::OUString* pServices = aServices.getConstArray(); - for (sal_Int32 i=0; i<aServices.getLength(); ++i, ++pServices) - if (pServices->equals(_rServiceName)) - return sal_True; - - return sal_False; -} - -//------------------------------------------------------------------------- -Sequence< ::rtl::OUString > SAL_CALL SvNumberFormatsSupplierServiceObject::getSupportedServiceNames( ) throw(RuntimeException) -{ - Sequence< ::rtl::OUString > aSupported(1); - aSupported.getArray()[0] = PERSISTENT_SERVICE_NAME; - return aSupported; -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL SvNumberFormatsSupplierServiceObject::getServiceName( ) throw(RuntimeException) -{ - return PERSISTENT_SERVICE_NAME; -} - -//------------------------------------------------------------------------- -void SAL_CALL SvNumberFormatsSupplierServiceObject::write( const Reference< XObjectOutputStream >& _rxOutStream ) throw(IOException, RuntimeException) -{ - ::osl::MutexGuard aGuard( getSharedMutex() ); - implEnsureFormatter(); - - Reference< XOutputStream > xStream(_rxOutStream.get()); - SvLockBytesRef aLockBytes = new SvOutputStreamOpenLockBytes(xStream); - SvStream aSvOutputSteam(aLockBytes); - - m_pOwnFormatter->Save(aSvOutputSteam); -} - -//------------------------------------------------------------------------- -void SAL_CALL SvNumberFormatsSupplierServiceObject::read( const Reference< XObjectInputStream >& _rxInStream ) throw(IOException, RuntimeException) -{ - ::osl::MutexGuard aGuard( getSharedMutex() ); - implEnsureFormatter(); - - Reference< XInputStream > xStream(_rxInStream.get()); - SvInputStream aSvInputSteam(xStream); - - m_pOwnFormatter->Load(aSvInputSteam); -} - -//------------------------------------------------------------------------- -Reference< XPropertySet > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormatSettings() throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( getSharedMutex() ); - implEnsureFormatter(); - return SvNumberFormatsSupplierObj::getNumberFormatSettings(); -} - -//------------------------------------------------------------------------- -Reference< XNumberFormats > SAL_CALL SvNumberFormatsSupplierServiceObject::getNumberFormats() throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( getSharedMutex() ); - implEnsureFormatter(); - return SvNumberFormatsSupplierObj::getNumberFormats(); -} - -//------------------------------------------------------------------------- -sal_Int64 SAL_CALL SvNumberFormatsSupplierServiceObject::getSomething( const Sequence< sal_Int8 >& aIdentifier ) throw (RuntimeException) -{ - sal_Int64 nReturn = SvNumberFormatsSupplierObj::getSomething( aIdentifier ); - if ( nReturn ) - // if somebody accesses internals then we should have the formatter - implEnsureFormatter(); - return nReturn; -} - -//------------------------------------------------------------------------- -void SvNumberFormatsSupplierServiceObject::implEnsureFormatter() -{ - if (!m_pOwnFormatter) - { - // get the office's UI locale - SvtSysLocale aSysLocale; - Locale aOfficeLocale = aSysLocale.GetLocaleData().getLocale(); - - // initi with this locale - Sequence< Any > aFakedInitProps( 1 ); - aFakedInitProps[0] <<= aOfficeLocale; - - initialize( aFakedInitProps ); - } -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/supservs.hxx b/svl/source/numbers/supservs.hxx deleted file mode 100644 index bdc983f139..0000000000 --- a/svl/source/numbers/supservs.hxx +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _SVTOOLS_NUMBERS_SUPPLIERSERVICE_HXX_ -#define _SVTOOLS_NUMBERS_SUPPLIERSERVICE_HXX_ - -#include <svl/numuno.hxx> -#include <svl/zforlist.hxx> -#include <com/sun/star/lang/XInitialization.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/io/XPersistObject.hpp> - -//========================================================================= -//= SvNumberFormatsSupplierServiceObject - a number formats supplier which -//= - can be instantiated as an service -//= - supports the ::com::sun::star::io::XPersistObject interface -//= - works with it's own SvNumberFormatter instance -//= - can be initialized (::com::sun::star::lang::XInitialization) -//= with a specific language (i.e. ::com::sun::star::lang::Locale) -//========================================================================= -class SvNumberFormatsSupplierServiceObject - :protected SvNumberFormatsSupplierObj - ,public ::com::sun::star::lang::XInitialization - ,public ::com::sun::star::io::XPersistObject - ,public ::com::sun::star::lang::XServiceInfo -{ // don't want the Set-/GetNumberFormatter to be accessable from outside - - friend ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > - SAL_CALL SvNumberFormatsSupplierServiceObject_CreateInstance( - const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&); - -protected: - SvNumberFormatter* m_pOwnFormatter; - ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > - m_xORB; - -public: - SvNumberFormatsSupplierServiceObject(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB); - ~SvNumberFormatsSupplierServiceObject(); - - // XInterface - virtual void SAL_CALL acquire() throw() { SvNumberFormatsSupplierObj::acquire(); } - virtual void SAL_CALL release() throw() { SvNumberFormatsSupplierObj::release(); } - virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw(::com::sun::star::uno::RuntimeException) - { return SvNumberFormatsSupplierObj::queryInterface(_rType); } - - // XAggregation - virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(::com::sun::star::uno::RuntimeException); - - // XInitialization - virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); - - // XServiceInfo - virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw(::com::sun::star::uno::RuntimeException); - virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException); - - // XPersistObject - virtual ::rtl::OUString SAL_CALL getServiceName( ) throw(::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException); - - // XNumberFormatsSupplier - virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL - getNumberFormatSettings() throw(::com::sun::star::uno::RuntimeException); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormats > SAL_CALL - getNumberFormats() throw(::com::sun::star::uno::RuntimeException); - - // XUnoTunnler - virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& aIdentifier ) throw (::com::sun::star::uno::RuntimeException); - -protected: - void implEnsureFormatter(); -}; - - -#endif // _SVTOOLS_NUMBERS_SUPPLIERSERVICE_HXX_ - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforfind.cxx b/svl/source/numbers/zforfind.cxx deleted file mode 100644 index 976372d6e7..0000000000 --- a/svl/source/numbers/zforfind.cxx +++ /dev/null @@ -1,2810 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <ctype.h> -#include <stdlib.h> -#include <float.h> -#include <errno.h> -#include <tools/date.hxx> -#include <tools/debug.hxx> -#include <rtl/math.hxx> -#include <unotools/charclass.hxx> -#include <unotools/calendarwrapper.hxx> -#include <unotools/localedatawrapper.hxx> -#include <com/sun/star/i18n/CalendarFieldIndex.hpp> -#include <unotools/digitgroupingiterator.hxx> - -#include <svl/zforlist.hxx> // NUMBERFORMAT_XXX -#include "zforscan.hxx" -#include <svl/zformat.hxx> - -#define _ZFORFIND_CXX -#include "zforfind.hxx" -#undef _ZFORFIND_CXX - - -#ifndef DBG_UTIL -#define NF_TEST_CALENDAR 0 -#else -#define NF_TEST_CALENDAR 0 -#endif -#if NF_TEST_CALENDAR -#include <comphelper/processfactory.hxx> -#include <com/sun/star/i18n/XExtendedCalendar.hpp> -#endif - - -const sal_uInt8 ImpSvNumberInputScan::nMatchedEndString = 0x01; -const sal_uInt8 ImpSvNumberInputScan::nMatchedMidString = 0x02; -const sal_uInt8 ImpSvNumberInputScan::nMatchedStartString = 0x04; -const sal_uInt8 ImpSvNumberInputScan::nMatchedVirgin = 0x08; -const sal_uInt8 ImpSvNumberInputScan::nMatchedUsedAsReturn = 0x10; - -/* It is not clear how we want timezones to be handled. Convert them to local - * time isn't wanted, as it isn't done in any other place and timezone - * information isn't stored anywhere. Ignoring them and pretending local time - * may be wrong too and might not be what the user expects. Keep the input as - * string so that no information is lost. - * Anyway, defining NF_RECOGNIZE_ISO8601_TIMEZONES to 1 would be the way how it - * would work, together with the nTimezonePos handling in GetTimeRef(). */ -#define NF_RECOGNIZE_ISO8601_TIMEZONES 0 - -//--------------------------------------------------------------------------- -// Konstruktor - -ImpSvNumberInputScan::ImpSvNumberInputScan( SvNumberFormatter* pFormatterP ) - : - pUpperMonthText( NULL ), - pUpperAbbrevMonthText( NULL ), - pUpperDayText( NULL ), - pUpperAbbrevDayText( NULL ), - eScannedType( NUMBERFORMAT_UNDEFINED ), - eSetType( NUMBERFORMAT_UNDEFINED ) -{ - pFormatter = pFormatterP; - pNullDate = new Date(30,12,1899); - nYear2000 = SvNumberFormatter::GetYear2000Default(); - Reset(); - ChangeIntl(); -} - - -//--------------------------------------------------------------------------- -// Destruktor - -ImpSvNumberInputScan::~ImpSvNumberInputScan() -{ - Reset(); - delete pNullDate; - delete [] pUpperMonthText; - delete [] pUpperAbbrevMonthText; - delete [] pUpperDayText; - delete [] pUpperAbbrevDayText; -} - - -//--------------------------------------------------------------------------- -// Reset - -void ImpSvNumberInputScan::Reset() -{ - nMonth = 0; - nMonthPos = 0; - nTimePos = 0; - nSign = 0; - nESign = 0; - nDecPos = 0; - nNegCheck = 0; - nAnzStrings = 0; - nAnzNums = 0; - nThousand = 0; - eScannedType = NUMBERFORMAT_UNDEFINED; - nAmPm = 0; - nPosThousandString = 0; - nLogical = 0; - nStringScanNumFor = 0; - nStringScanSign = 0; - nMatchedAllStrings = nMatchedVirgin; - nMayBeIso8601 = 0; - nTimezonePos = 0; -} - - -//--------------------------------------------------------------------------- -// -// static -inline sal_Bool ImpSvNumberInputScan::MyIsdigit( sal_Unicode c ) -{ - return c < 128 && isdigit( (unsigned char) c ); -} - - -//--------------------------------------------------------------------------- -// -void ImpSvNumberInputScan::TransformInput( String& rStr ) -{ - xub_StrLen nPos, nLen; - for ( nPos = 0, nLen = rStr.Len(); nPos < nLen; ++nPos ) - { - if ( 256 <= rStr.GetChar( nPos ) && - pFormatter->GetCharClass()->isDigit( rStr, nPos ) ) - break; - } - if ( nPos < nLen ) - rStr = pFormatter->GetNatNum()->getNativeNumberString( rStr, - pFormatter->GetLocale(), 0 ); -} - - -//--------------------------------------------------------------------------- -// StringToDouble -// -// Only simple unsigned floating point values without any error detection, -// decimal separator has to be '.' - -double ImpSvNumberInputScan::StringToDouble( const String& rStr, sal_Bool bForceFraction ) -{ - double fNum = 0.0; - double fFrac = 0.0; - int nExp = 0; - xub_StrLen nPos = 0; - xub_StrLen nLen = rStr.Len(); - sal_Bool bPreSep = !bForceFraction; - - while (nPos < nLen) - { - if (rStr.GetChar(nPos) == '.') - bPreSep = sal_False; - else if (bPreSep) - fNum = fNum * 10.0 + (double) (rStr.GetChar(nPos) - '0'); - else - { - fFrac = fFrac * 10.0 + (double) (rStr.GetChar(nPos) - '0'); - --nExp; - } - nPos++; - } - if ( fFrac ) - return fNum + ::rtl::math::pow10Exp( fFrac, nExp ); - return fNum; -} - - -//--------------------------------------------------------------------------- -// NextNumberStringSymbol -// -// Zerlegt die Eingabe in Zahlen und Strings fuer die weitere -// Verarbeitung (Turing-Maschine). -//--------------------------------------------------------------------------- -// Ausgangs Zustand = GetChar -//---------------+-------------------+-----------------------+--------------- -// Alter Zustand | gelesenes Zeichen | Aktion | Neuer Zustand -//---------------+-------------------+-----------------------+--------------- -// GetChar | Ziffer | Symbol=Zeichen | GetValue -// | Sonst | Symbol=Zeichen | GetString -//---------------|-------------------+-----------------------+--------------- -// GetValue | Ziffer | Symbol=Symbol+Zeichen | GetValue -// | Sonst | Dec(CharPos) | Stop -//---------------+-------------------+-----------------------+--------------- -// GetString | Ziffer | Dec(CharPos) | Stop -// | Sonst | Symbol=Symbol+Zeichen | GetString -//---------------+-------------------+-----------------------+--------------- - -enum ScanState // States der Turing-Maschine -{ - SsStop = 0, - SsStart = 1, - SsGetValue = 2, - SsGetString = 3 -}; - -sal_Bool ImpSvNumberInputScan::NextNumberStringSymbol( - const sal_Unicode*& pStr, - String& rSymbol ) -{ - sal_Bool isNumber = sal_False; - sal_Unicode cToken; - ScanState eState = SsStart; - register const sal_Unicode* pHere = pStr; - register xub_StrLen nChars = 0; - - while ( ((cToken = *pHere) != 0) && eState != SsStop) - { - pHere++; - switch (eState) - { - case SsStart: - if ( MyIsdigit( cToken ) ) - { - eState = SsGetValue; - isNumber = sal_True; - } - else - eState = SsGetString; - nChars++; - break; - case SsGetValue: - if ( MyIsdigit( cToken ) ) - nChars++; - else - { - eState = SsStop; - pHere--; - } - break; - case SsGetString: - if ( !MyIsdigit( cToken ) ) - nChars++; - else - { - eState = SsStop; - pHere--; - } - break; - default: - break; - } // switch - } // while - - if ( nChars ) - rSymbol.Assign( pStr, nChars ); - else - rSymbol.Erase(); - - pStr = pHere; - - return isNumber; -} - - -//--------------------------------------------------------------------------- -// SkipThousands - -// FIXME: should be grouping; it is only used though in case nAnzStrings is -// near SV_MAX_ANZ_INPUT_STRINGS, in NumberStringDivision(). - -sal_Bool ImpSvNumberInputScan::SkipThousands( - const sal_Unicode*& pStr, - String& rSymbol ) -{ - sal_Bool res = sal_False; - sal_Unicode cToken; - const String& rThSep = pFormatter->GetNumThousandSep(); - register const sal_Unicode* pHere = pStr; - ScanState eState = SsStart; - xub_StrLen nCounter = 0; // counts 3 digits - - while ( ((cToken = *pHere) != 0) && eState != SsStop) - { - pHere++; - switch (eState) - { - case SsStart: - if ( StringPtrContains( rThSep, pHere-1, 0 ) ) - { - nCounter = 0; - eState = SsGetValue; - pHere += rThSep.Len()-1; - } - else - { - eState = SsStop; - pHere--; - } - break; - case SsGetValue: - if ( MyIsdigit( cToken ) ) - { - rSymbol += cToken; - nCounter++; - if (nCounter == 3) - { - eState = SsStart; - res = sal_True; // .000 combination found - } - } - else - { - eState = SsStop; - pHere--; - } - break; - default: - break; - } // switch - } // while - - if (eState == SsGetValue) // break witth less than 3 digits - { - if ( nCounter ) - rSymbol.Erase( rSymbol.Len() - nCounter, nCounter ); - pHere -= nCounter + rThSep.Len(); // put back ThSep also - } - pStr = pHere; - - return res; -} - - -//--------------------------------------------------------------------------- -// NumberStringDivision - -void ImpSvNumberInputScan::NumberStringDivision( const String& rString ) -{ - const sal_Unicode* pStr = rString.GetBuffer(); - const sal_Unicode* const pEnd = pStr + rString.Len(); - while ( pStr < pEnd && nAnzStrings < SV_MAX_ANZ_INPUT_STRINGS ) - { - if ( NextNumberStringSymbol( pStr, sStrArray[nAnzStrings] ) ) - { // Zahl - IsNum[nAnzStrings] = sal_True; - nNums[nAnzNums] = nAnzStrings; - nAnzNums++; - if (nAnzStrings >= SV_MAX_ANZ_INPUT_STRINGS - 7 && - nPosThousandString == 0) // nur einmal - if ( SkipThousands( pStr, sStrArray[nAnzStrings] ) ) - nPosThousandString = nAnzStrings; - } - else - { - IsNum[nAnzStrings] = sal_False; - } - nAnzStrings++; - } -} - - -//--------------------------------------------------------------------------- -// Whether rString contains rWhat at nPos - -sal_Bool ImpSvNumberInputScan::StringContainsImpl( const String& rWhat, - const String& rString, xub_StrLen nPos ) -{ - if ( nPos + rWhat.Len() <= rString.Len() ) - return StringPtrContainsImpl( rWhat, rString.GetBuffer(), nPos ); - return sal_False; -} - - -//--------------------------------------------------------------------------- -// Whether pString contains rWhat at nPos - -sal_Bool ImpSvNumberInputScan::StringPtrContainsImpl( const String& rWhat, - const sal_Unicode* pString, xub_StrLen nPos ) -{ - if ( rWhat.Len() == 0 ) - return sal_False; - register const sal_Unicode* pWhat = rWhat.GetBuffer(); - register const sal_Unicode* const pEnd = pWhat + rWhat.Len(); - register const sal_Unicode* pStr = pString + nPos; - while ( pWhat < pEnd ) - { - if ( *pWhat != *pStr ) - return sal_False; - pWhat++; - pStr++; - } - return sal_True; -} - - -//--------------------------------------------------------------------------- -// SkipChar -// -// ueberspringt genau das angegebene Zeichen - -inline sal_Bool ImpSvNumberInputScan::SkipChar( sal_Unicode c, const String& rString, - xub_StrLen& nPos ) -{ - if ((nPos < rString.Len()) && (rString.GetChar(nPos) == c)) - { - nPos++; - return sal_True; - } - return sal_False; -} - - -//--------------------------------------------------------------------------- -// SkipBlanks -// -// Ueberspringt Leerzeichen - -inline void ImpSvNumberInputScan::SkipBlanks( const String& rString, - xub_StrLen& nPos ) -{ - if ( nPos < rString.Len() ) - { - register const sal_Unicode* p = rString.GetBuffer() + nPos; - while ( *p == ' ' ) - { - nPos++; - p++; - } - } -} - - -//--------------------------------------------------------------------------- -// SkipString -// -// jump over rWhat in rString at nPos - -inline sal_Bool ImpSvNumberInputScan::SkipString( const String& rWhat, - const String& rString, xub_StrLen& nPos ) -{ - if ( StringContains( rWhat, rString, nPos ) ) - { - nPos = nPos + rWhat.Len(); - return sal_True; - } - return sal_False; -} - - -//--------------------------------------------------------------------------- -// GetThousandSep -// -// recognizes exactly ,111 in {3} and {3,2} or ,11 in {3,2} grouping - -inline sal_Bool ImpSvNumberInputScan::GetThousandSep( - const String& rString, - xub_StrLen& nPos, - sal_uInt16 nStringPos ) -{ - const String& rSep = pFormatter->GetNumThousandSep(); - // Is it an ordinary space instead of a non-breaking space? - bool bSpaceBreak = rSep.GetChar(0) == 0xa0 && rString.GetChar(0) == 0x20 && - rSep.Len() == 1 && rString.Len() == 1; - if (!( (rString == rSep || bSpaceBreak) // nothing else - && nStringPos < nAnzStrings - 1 // safety first! - && IsNum[nStringPos+1] )) // number follows - return sal_False; // no? => out - - utl::DigitGroupingIterator aGrouping( - pFormatter->GetLocaleData()->getDigitGrouping()); - // Match ,### in {3} or ,## in {3,2} - /* FIXME: this could be refined to match ,## in {3,2} only if ,##,## or - * ,##,### and to match ,### in {3,2} only if it's the last. However, - * currently there is no track kept where group separators occur. In {3,2} - * #,###,### and #,##,## would be valid input, which maybe isn't even bad - * for #,###,###. Other combinations such as #,###,## maybe not. */ - xub_StrLen nLen = sStrArray[nStringPos+1].Len(); - if (nLen == aGrouping.get() // with 3 (or so) digits - || nLen == aGrouping.advance().get() // or with 2 (or 3 or so) digits - || nPosThousandString == nStringPos+1 // or concatenated - ) - { - nPos = nPos + rSep.Len(); - return sal_True; - } - return sal_False; -} - - -//--------------------------------------------------------------------------- -// GetLogical -// -// Conversion of text to logial value -// "sal_True" => 1: -// "sal_False"=> -1: -// else => 0: - -short ImpSvNumberInputScan::GetLogical( const String& rString ) -{ - short res; - - const ImpSvNumberformatScan* pFS = pFormatter->GetFormatScanner(); - if ( rString == pFS->GetTrueString() ) - res = 1; - else if ( rString == pFS->GetFalseString() ) - res = -1; - else - res = 0; - - return res; -} - - -//--------------------------------------------------------------------------- -// GetMonth -// -// Converts a string containing a month name (JAN, January) at nPos into the -// month number (negative if abbreviated), returns 0 if nothing found - -short ImpSvNumberInputScan::GetMonth( const String& rString, xub_StrLen& nPos ) -{ - // #102136# The correct English form of month September abbreviated is - // SEPT, but almost every data contains SEP instead. - static const String aSeptCorrect( RTL_CONSTASCII_USTRINGPARAM( "SEPT" ) ); - static const String aSepShortened( RTL_CONSTASCII_USTRINGPARAM( "SEP" ) ); - - short res = 0; // no month found - - if (rString.Len() > nPos) // only if needed - { - if ( !bTextInitialized ) - InitText(); - sal_Int16 nMonths = pFormatter->GetCalendar()->getNumberOfMonthsInYear(); - for ( sal_Int16 i = 0; i < nMonths; i++ ) - { - if ( StringContains( pUpperMonthText[i], rString, nPos ) ) - { // full names first - nPos = nPos + pUpperMonthText[i].Len(); - res = i+1; - break; // for - } - else if ( StringContains( pUpperAbbrevMonthText[i], rString, nPos ) ) - { // abbreviated - nPos = nPos + pUpperAbbrevMonthText[i].Len(); - res = sal::static_int_cast< short >(-(i+1)); // negative - break; // for - } - else if ( i == 8 && pUpperAbbrevMonthText[i] == aSeptCorrect && - StringContains( aSepShortened, rString, nPos ) ) - { // #102136# SEPT/SEP - nPos = nPos + aSepShortened.Len(); - res = sal::static_int_cast< short >(-(i+1)); // negative - break; // for - } - } - } - - return res; -} - - -//--------------------------------------------------------------------------- -// GetDayOfWeek -// -// Converts a string containing a DayOfWeek name (Mon, Monday) at nPos into the -// DayOfWeek number + 1 (negative if abbreviated), returns 0 if nothing found - -int ImpSvNumberInputScan::GetDayOfWeek( const String& rString, xub_StrLen& nPos ) -{ - int res = 0; // no day found - - if (rString.Len() > nPos) // only if needed - { - if ( !bTextInitialized ) - InitText(); - sal_Int16 nDays = pFormatter->GetCalendar()->getNumberOfDaysInWeek(); - for ( sal_Int16 i = 0; i < nDays; i++ ) - { - if ( StringContains( pUpperDayText[i], rString, nPos ) ) - { // full names first - nPos = nPos + pUpperDayText[i].Len(); - res = i + 1; - break; // for - } - if ( StringContains( pUpperAbbrevDayText[i], rString, nPos ) ) - { // abbreviated - nPos = nPos + pUpperAbbrevDayText[i].Len(); - res = -(i + 1); // negative - break; // for - } - } - } - - return res; -} - - -//--------------------------------------------------------------------------- -// GetCurrency -// -// Lesen eines Waehrungssysmbols -// '$' => sal_True -// sonst => sal_False - -sal_Bool ImpSvNumberInputScan::GetCurrency( const String& rString, xub_StrLen& nPos, - const SvNumberformat* pFormat ) -{ - if ( rString.Len() > nPos ) - { - if ( !aUpperCurrSymbol.Len() ) - { // if no format specified the currency of the initialized formatter - LanguageType eLang = (pFormat ? pFormat->GetLanguage() : - pFormatter->GetLanguage()); - aUpperCurrSymbol = pFormatter->GetCharClass()->upper( - SvNumberFormatter::GetCurrencyEntry( eLang ).GetSymbol() ); - } - if ( StringContains( aUpperCurrSymbol, rString, nPos ) ) - { - nPos = nPos + aUpperCurrSymbol.Len(); - return sal_True; - } - if ( pFormat ) - { - String aSymbol, aExtension; - if ( pFormat->GetNewCurrencySymbol( aSymbol, aExtension ) ) - { - if ( aSymbol.Len() <= rString.Len() - nPos ) - { - pFormatter->GetCharClass()->toUpper( aSymbol ); - if ( StringContains( aSymbol, rString, nPos ) ) - { - nPos = nPos + aSymbol.Len(); - return sal_True; - } - } - } - } - } - - return sal_False; -} - - -//--------------------------------------------------------------------------- -// GetTimeAmPm -// -// Lesen des Zeitsymbols (AM od. PM) f. kurze Zeitangabe -// -// Rueckgabe: -// "AM" od. "PM" => sal_True -// sonst => sal_False -// -// nAmPos: -// "AM" => 1 -// "PM" => -1 -// sonst => 0 - -sal_Bool ImpSvNumberInputScan::GetTimeAmPm( const String& rString, xub_StrLen& nPos ) -{ - - if ( rString.Len() > nPos ) - { - const CharClass* pChr = pFormatter->GetCharClass(); - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - if ( StringContains( pChr->upper( pLoc->getTimeAM() ), rString, nPos ) ) - { - nAmPm = 1; - nPos = nPos + pLoc->getTimeAM().Len(); - return sal_True; - } - else if ( StringContains( pChr->upper( pLoc->getTimePM() ), rString, nPos ) ) - { - nAmPm = -1; - nPos = nPos + pLoc->getTimePM().Len(); - return sal_True; - } - } - - return sal_False; -} - - -//--------------------------------------------------------------------------- -// GetDecSep -// -// Lesen eines Dezimaltrenners (',') -// ',' => sal_True -// sonst => sal_False - -inline sal_Bool ImpSvNumberInputScan::GetDecSep( const String& rString, xub_StrLen& nPos ) -{ - if ( rString.Len() > nPos ) - { - const String& rSep = pFormatter->GetNumDecimalSep(); - if ( rString.Equals( rSep, nPos, rSep.Len() ) ) - { - nPos = nPos + rSep.Len(); - return sal_True; - } - } - return sal_False; -} - - -//--------------------------------------------------------------------------- -// read a hundredth seconds separator - -inline sal_Bool ImpSvNumberInputScan::GetTime100SecSep( const String& rString, xub_StrLen& nPos ) -{ - if ( rString.Len() > nPos ) - { - const String& rSep = pFormatter->GetLocaleData()->getTime100SecSep(); - if ( rString.Equals( rSep, nPos, rSep.Len() ) ) - { - nPos = nPos + rSep.Len(); - return sal_True; - } - } - return sal_False; -} - - -//--------------------------------------------------------------------------- -// GetSign -// -// Lesen eines Vorzeichens, auch Klammer !?! -// '+' => 1 -// '-' => -1 -// '(' => -1, nNegCheck = 1 -// sonst => 0 - -int ImpSvNumberInputScan::GetSign( const String& rString, xub_StrLen& nPos ) -{ - if (rString.Len() > nPos) - switch (rString.GetChar(nPos)) - { - case '+': - nPos++; - return 1; - case '(': // '(' aehnlich wie '-' ?!? - nNegCheck = 1; - //! fallthru - case '-': - nPos++; - return -1; - default: - break; - } - - return 0; -} - - -//--------------------------------------------------------------------------- -// GetESign -// -// Lesen eines Vorzeichens, gedacht fuer Exponent ?!? -// '+' => 1 -// '-' => -1 -// sonst => 0 - -short ImpSvNumberInputScan::GetESign( const String& rString, xub_StrLen& nPos ) -{ - if (rString.Len() > nPos) - switch (rString.GetChar(nPos)) - { - case '+': - nPos++; - return 1; - case '-': - nPos++; - return -1; - default: - break; - } - - return 0; -} - - -//--------------------------------------------------------------------------- -// GetNextNumber -// -// i counts string portions, j counts numbers thereof. -// It should had been called SkipNumber instead. - -inline sal_Bool ImpSvNumberInputScan::GetNextNumber( sal_uInt16& i, sal_uInt16& j ) -{ - if ( i < nAnzStrings && IsNum[i] ) - { - j++; - i++; - return sal_True; - } - return sal_False; -} - - -//--------------------------------------------------------------------------- -// GetTimeRef - -void ImpSvNumberInputScan::GetTimeRef( - double& fOutNumber, - sal_uInt16 nIndex, // j-value of the first numeric time part of input, default 0 - sal_uInt16 nAnz ) // count of numeric time parts -{ - sal_uInt16 nHour; - sal_uInt16 nMinute = 0; - sal_uInt16 nSecond = 0; - double fSecond100 = 0.0; - sal_uInt16 nStartIndex = nIndex; - - if (nTimezonePos) - { - // find first timezone number index and adjust count - for (sal_uInt16 j=0; j<nAnzNums; ++j) - { - if (nNums[j] == nTimezonePos) - { - // nAnz is not total count, but count of time relevant strings. - if (nStartIndex < j && j - nStartIndex < nAnz) - nAnz = j - nStartIndex; - break; // for - } - } - } - - if (nDecPos == 2 && (nAnz == 3 || nAnz == 2)) // 20:45.5 or 45.5 - nHour = 0; - else if (nIndex - nStartIndex < nAnz) - nHour = (sal_uInt16) sStrArray[nNums[nIndex++]].ToInt32(); - else - { - nHour = 0; - DBG_ERRORFILE( "ImpSvNumberInputScan::GetTimeRef: bad number index"); - } - if (nDecPos == 2 && nAnz == 2) // 45.5 - nMinute = 0; - else if (nIndex - nStartIndex < nAnz) - nMinute = (sal_uInt16) sStrArray[nNums[nIndex++]].ToInt32(); - if (nIndex - nStartIndex < nAnz) - nSecond = (sal_uInt16) sStrArray[nNums[nIndex++]].ToInt32(); - if (nIndex - nStartIndex < nAnz) - fSecond100 = StringToDouble( sStrArray[nNums[nIndex]], sal_True ); - if (nAmPm == -1 && nHour != 12) // PM - nHour += 12; - else if (nAmPm == 1 && nHour == 12) // 12 AM - nHour = 0; - - fOutNumber = ((double)nHour*3600 + - (double)nMinute*60 + - (double)nSecond + - fSecond100)/86400.0; -} - - -//--------------------------------------------------------------------------- -// ImplGetDay - -sal_uInt16 ImpSvNumberInputScan::ImplGetDay( sal_uInt16 nIndex ) -{ - sal_uInt16 nRes = 0; - - if (sStrArray[nNums[nIndex]].Len() <= 2) - { - sal_uInt16 nNum = (sal_uInt16) sStrArray[nNums[nIndex]].ToInt32(); - if (nNum <= 31) - nRes = nNum; - } - - return nRes; -} - - -//--------------------------------------------------------------------------- -// ImplGetMonth - -sal_uInt16 ImpSvNumberInputScan::ImplGetMonth( sal_uInt16 nIndex ) -{ - // preset invalid month number - sal_uInt16 nRes = pFormatter->GetCalendar()->getNumberOfMonthsInYear(); - - if (sStrArray[nNums[nIndex]].Len() <= 2) - { - sal_uInt16 nNum = (sal_uInt16) sStrArray[nNums[nIndex]].ToInt32(); - if ( 0 < nNum && nNum <= nRes ) - nRes = nNum - 1; // zero based for CalendarFieldIndex::MONTH - } - - return nRes; -} - - -//--------------------------------------------------------------------------- -// ImplGetYear -// -// 30 -> 1930, 29 -> 2029, oder 56 -> 1756, 55 -> 1855, ... - -sal_uInt16 ImpSvNumberInputScan::ImplGetYear( sal_uInt16 nIndex ) -{ - sal_uInt16 nYear = 0; - - if (sStrArray[nNums[nIndex]].Len() <= 4) - { - nYear = (sal_uInt16) sStrArray[nNums[nIndex]].ToInt32(); - nYear = SvNumberFormatter::ExpandTwoDigitYear( nYear, nYear2000 ); - } - - return nYear; -} - -//--------------------------------------------------------------------------- - -bool ImpSvNumberInputScan::MayBeIso8601() -{ - if (nMayBeIso8601 == 0) - { - if (nAnzNums >= 3 && nNums[0] < nAnzStrings && - sStrArray[nNums[0]].ToInt32() > 31) - nMayBeIso8601 = 1; - else - nMayBeIso8601 = 2; - } - return nMayBeIso8601 == 1; -} - -//--------------------------------------------------------------------------- -// GetDateRef - -sal_Bool ImpSvNumberInputScan::GetDateRef( double& fDays, sal_uInt16& nCounter, - const SvNumberformat* pFormat ) -{ - using namespace ::com::sun::star::i18n; - NfEvalDateFormat eEDF; - int nFormatOrder; - if ( pFormat && ((pFormat->GetType() & NUMBERFORMAT_DATE) == NUMBERFORMAT_DATE) ) - { - eEDF = pFormatter->GetEvalDateFormat(); - switch ( eEDF ) - { - case NF_EVALDATEFORMAT_INTL : - case NF_EVALDATEFORMAT_FORMAT : - nFormatOrder = 1; // only one loop - break; - default: - nFormatOrder = 2; - if ( nMatchedAllStrings ) - eEDF = NF_EVALDATEFORMAT_FORMAT_INTL; - // we have a complete match, use it - } - } - else - { - eEDF = NF_EVALDATEFORMAT_INTL; - nFormatOrder = 1; - } - sal_Bool res = sal_True; - - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - CalendarWrapper* pCal = pFormatter->GetCalendar(); - for ( int nTryOrder = 1; nTryOrder <= nFormatOrder; nTryOrder++ ) - { - pCal->setGregorianDateTime( Date() ); // today - String aOrgCalendar; // empty => not changed yet - DateFormat DateFmt; - sal_Bool bFormatTurn; - switch ( eEDF ) - { - case NF_EVALDATEFORMAT_INTL : - bFormatTurn = sal_False; - DateFmt = pLoc->getDateFormat(); - break; - case NF_EVALDATEFORMAT_FORMAT : - bFormatTurn = sal_True; - DateFmt = pFormat->GetDateOrder(); - break; - case NF_EVALDATEFORMAT_INTL_FORMAT : - if ( nTryOrder == 1 ) - { - bFormatTurn = sal_False; - DateFmt = pLoc->getDateFormat(); - } - else - { - bFormatTurn = sal_True; - DateFmt = pFormat->GetDateOrder(); - } - break; - case NF_EVALDATEFORMAT_FORMAT_INTL : - if ( nTryOrder == 2 ) - { - bFormatTurn = sal_False; - DateFmt = pLoc->getDateFormat(); - } - else - { - bFormatTurn = sal_True; - DateFmt = pFormat->GetDateOrder(); - } - break; - default: - OSL_FAIL( "ImpSvNumberInputScan::GetDateRef: unknown NfEvalDateFormat" ); - DateFmt = YMD; - bFormatTurn = sal_False; - } - if ( bFormatTurn ) - { -#if 0 -/* TODO: -We are currently not able to fully support a switch to another calendar during -input for the following reasons: -1. We do have a problem if both (locale's default and format's) calendars - define the same YMD order and use the same date separator, there is no way - to distinguish between them if the input results in valid calendar input for - both calendars. How to solve? Would NfEvalDateFormat be sufficient? Should - it always be set to NF_EVALDATEFORMAT_FORMAT_INTL and thus the format's - calendar be preferred? This could be confusing if a Calc cell was formatted - different to the locale's default and has no content yet, then the user has - no clue about the format or calendar being set. -2. In Calc cell edit mode a date is always displayed and edited using the - default edit format of the default calendar (normally being Gregorian). If - input was ambiguous due to issue #1 we'd need a mechanism to tell that a - date was edited and not newly entered. Not feasible. Otherwise we'd need a - mechanism to use a specific edit format with a specific calendar according - to the format set. -3. For some calendars like Japanese Gengou we'd need era input, which isn't - implemented at all. Though this is a rare and special case, forcing a - calendar dependent edit format as suggested in item #2 might require era - input, if it shouldn't result in a fallback to Gregorian calendar. -4. Last and least: the GetMonth() method currently only matches month names of - the default calendar. Alternating month names of the actual format's - calendar would have to be implemented. No problem. - -*/ - if ( pFormat->IsOtherCalendar( nStringScanNumFor ) ) - pFormat->SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - else - pFormat->SwitchToSpecifiedCalendar( aOrgCalendar, fOrgDateTime, - nStringScanNumFor ); -#endif - } - - res = sal_True; - nCounter = 0; - // For incomplete dates, always assume first day of month if not specified. - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, 1 ); - - switch (nAnzNums) // count of numbers in string - { - case 0: // none - if (nMonthPos) // only month (Jan) - pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 ); - else - res = sal_False; - break; - - case 1: // only one number - nCounter = 1; - switch (nMonthPos) // where is the month - { - case 0: // not found => only day entered - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - break; - case 1: // month at the beginning (Jan 01) - pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 ); - switch (DateFmt) - { - case MDY: - case YMD: { - sal_uInt16 nDay = ImplGetDay(0); - sal_uInt16 nYear = ImplGetYear(0); - if (nDay == 0 || nDay > 32) { - pCal->setValue( CalendarFieldIndex::YEAR, nYear); - } - else - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - break; - } - case DMY: - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - break; - default: - res = sal_False; - break; - } - break; - case 3: // month at the end (10 Jan) - pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 ); - switch (DateFmt) - { - case DMY: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - break; - case YMD: - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - break; - default: - res = sal_False; - break; - } - break; - default: - res = sal_False; - break; - } // switch (nMonthPos) - break; - - case 2: // 2 numbers - nCounter = 2; - switch (nMonthPos) // where is the month - { - case 0: // not found - { - bool bHadExact; - sal_uInt32 nExactDateOrder = (bFormatTurn ? pFormat->GetExactDateOrder() : 0); - if ( 0xff < nExactDateOrder && nExactDateOrder <= 0xffff ) - { // formatted as date and exactly 2 parts - bHadExact = true; - switch ( (nExactDateOrder >> 8) & 0xff ) - { - case 'Y': - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - break; - case 'M': - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) ); - break; - case 'D': - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - break; - default: - bHadExact = false; - } - switch ( nExactDateOrder & 0xff ) - { - case 'Y': - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(1) ); - break; - case 'M': - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(1) ); - break; - case 'D': - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(1) ); - break; - default: - bHadExact = false; - } - } - else - bHadExact = false; - if ( !bHadExact || !pCal->isValid() ) - { - if ( !bHadExact && nExactDateOrder ) - pCal->setGregorianDateTime( Date() ); // reset today - switch (DateFmt) - { - case MDY: - // M D - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(1) ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) ); - if ( !pCal->isValid() ) // 2nd try - { // M Y - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, 1 ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(1) ); - } - break; - case DMY: - // D M - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(1) ); - if ( !pCal->isValid() ) // 2nd try - { // M Y - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, 1 ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(1) ); - } - break; - case YMD: - // M D - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(1) ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) ); - if ( !pCal->isValid() ) // 2nd try - { // Y M - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, 1 ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(1) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - } - break; - default: - res = sal_False; - break; - } - } - } - break; - case 1: // month at the beginning (Jan 01 01) - { - // The input is valid as MDY in almost any - // constellation, there is no date order (M)YD except if - // set in a format applied. - pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 ); - sal_uInt32 nExactDateOrder = (bFormatTurn ? pFormat->GetExactDateOrder() : 0); - if ((((nExactDateOrder >> 8) & 0xff) == 'Y') && ((nExactDateOrder & 0xff) == 'D')) - { - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(1) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - } - else - { - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(1) ); - } - } - break; - case 2: // month in the middle (10 Jan 94) - pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 ); - switch (DateFmt) - { - case MDY: // yes, "10-Jan-94" is valid - case DMY: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(1) ); - break; - case YMD: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(1) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - break; - default: - res = sal_False; - break; - } - break; - default: // else, e.g. month at the end (94 10 Jan) - res = sal_False; - break; - } // switch (nMonthPos) - break; - - default: // more than two numbers (31.12.94 8:23) (31.12. 8:23) - switch (nMonthPos) // where is the month - { - case 0: // not found - { - nCounter = 3; - if ( nTimePos > 1 ) - { // find first time number index (should only be 3 or 2 anyway) - for ( sal_uInt16 j = 0; j < nAnzNums; j++ ) - { - if ( nNums[j] == nTimePos - 2 ) - { - nCounter = j; - break; // for - } - } - } - // ISO 8601 yyyy-mm-dd forced recognition - DateFormat eDF = (MayBeIso8601() ? YMD : DateFmt); - switch (eDF) - { - case MDY: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(1) ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(0) ); - if ( nCounter > 2 ) - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(2) ); - break; - case DMY: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(1) ); - if ( nCounter > 2 ) - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(2) ); - break; - case YMD: - if ( nCounter > 2 ) - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(2) ); - pCal->setValue( CalendarFieldIndex::MONTH, ImplGetMonth(1) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - break; - default: - res = sal_False; - break; - } - } - break; - case 1: // month at the beginning (Jan 01 01 8:23) - nCounter = 2; - switch (DateFmt) - { - case MDY: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(1) ); - break; - default: - res = sal_False; - break; - } - break; - case 2: // month in the middle (10 Jan 94 8:23) - nCounter = 2; - pCal->setValue( CalendarFieldIndex::MONTH, Abs(nMonth)-1 ); - switch (DateFmt) - { - case DMY: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(0) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(1) ); - break; - case YMD: - pCal->setValue( CalendarFieldIndex::DAY_OF_MONTH, ImplGetDay(1) ); - pCal->setValue( CalendarFieldIndex::YEAR, ImplGetYear(0) ); - break; - default: - res = sal_False; - break; - } - break; - default: // else, e.g. month at the end (94 10 Jan 8:23) - nCounter = 2; - res = sal_False; - break; - } // switch (nMonthPos) - break; - } // switch (nAnzNums) - - if ( res && pCal->isValid() ) - { - double fDiff = DateTime(*pNullDate) - pCal->getEpochStart(); - fDays = ::rtl::math::approxFloor( pCal->getLocalDateTime() ); - fDays -= fDiff; - nTryOrder = nFormatOrder; // break for - } - else - res = sal_False; - - if ( aOrgCalendar.Len() ) - pCal->loadCalendar( aOrgCalendar, pLoc->getLocale() ); // restore calendar - -#if NF_TEST_CALENDAR -{ - using namespace ::com::sun::star; - struct entry { const char* lan; const char* cou; const char* cal; }; - const entry cals[] = { - { "en", "US", "gregorian" }, - { "ar", "TN", "hijri" }, - { "he", "IL", "jewish" }, - { "ja", "JP", "gengou" }, - { "ko", "KR", "hanja_yoil" }, - { "th", "TH", "buddhist" }, - { "zh", "TW", "ROC" }, - {0,0,0} - }; - lang::Locale aLocale; - sal_Bool bValid; - sal_Int16 nDay, nMyMonth, nYear, nHour, nMinute, nSecond; - sal_Int16 nDaySet, nMonthSet, nYearSet, nHourSet, nMinuteSet, nSecondSet; - sal_Int16 nZO, nDST1, nDST2, nDST, nZOmillis, nDST1millis, nDST2millis, nDSTmillis; - sal_Int32 nZoneInMillis, nDST1InMillis, nDST2InMillis; - uno::Reference< lang::XMultiServiceFactory > xSMgr = - ::comphelper::getProcessServiceFactory(); - uno::Reference< ::com::sun::star::i18n::XExtendedCalendar > xCal( - xSMgr->createInstance( ::rtl::OUString( - RTL_CONSTASCII_USTRINGPARAM( - "com.sun.star.i18n.LocaleCalendar" ) ) ), - uno::UNO_QUERY ); - for ( const entry* p = cals; p->lan; ++p ) - { - aLocale.Language = ::rtl::OUString::createFromAscii( p->lan ); - aLocale.Country = ::rtl::OUString::createFromAscii( p->cou ); - xCal->loadCalendar( ::rtl::OUString::createFromAscii( p->cal ), - aLocale ); - double nDateTime = 0.0; // 1-Jan-1970 00:00:00 - nZO = xCal->getValue( i18n::CalendarFieldIndex::ZONE_OFFSET ); - nZOmillis = xCal->getValue( i18n::CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS ); - nZoneInMillis = static_cast<sal_Int32>(nZO) * 60000 + - (nZO < 0 ? -1 : 1) * static_cast<sal_uInt16>(nZOmillis); - nDST1 = xCal->getValue( i18n::CalendarFieldIndex::DST_OFFSET ); - nDST1millis = xCal->getValue( i18n::CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS ); - nDST1InMillis = static_cast<sal_Int32>(nDST1) * 60000 + - (nDST1 < 0 ? -1 : 1) * static_cast<sal_uInt16>(nDST1millis); - nDateTime -= (double)(nZoneInMillis + nDST1InMillis) / 1000.0 / 60.0 / 60.0 / 24.0; - xCal->setDateTime( nDateTime ); - nDST2 = xCal->getValue( i18n::CalendarFieldIndex::DST_OFFSET ); - nDST2millis = xCal->getValue( i18n::CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS ); - nDST2InMillis = static_cast<sal_Int32>(nDST2) * 60000 + - (nDST2 < 0 ? -1 : 1) * static_cast<sal_uInt16>(nDST2millis); - if ( nDST1InMillis != nDST2InMillis ) - { - nDateTime = 0.0 - (double)(nZoneInMillis + nDST2InMillis) / 1000.0 / 60.0 / 60.0 / 24.0; - xCal->setDateTime( nDateTime ); - } - nDaySet = xCal->getValue( i18n::CalendarFieldIndex::DAY_OF_MONTH ); - nMonthSet = xCal->getValue( i18n::CalendarFieldIndex::MONTH ); - nYearSet = xCal->getValue( i18n::CalendarFieldIndex::YEAR ); - nHourSet = xCal->getValue( i18n::CalendarFieldIndex::HOUR ); - nMinuteSet = xCal->getValue( i18n::CalendarFieldIndex::MINUTE ); - nSecondSet = xCal->getValue( i18n::CalendarFieldIndex::SECOND ); - nZO = xCal->getValue( i18n::CalendarFieldIndex::ZONE_OFFSET ); - nZOmillis = xCal->getValue( i18n::CalendarFieldIndex::ZONE_OFFSET_SECOND_MILLIS ); - nDST = xCal->getValue( i18n::CalendarFieldIndex::DST_OFFSET ); - nDSTmillis = xCal->getValue( i18n::CalendarFieldIndex::DST_OFFSET_SECOND_MILLIS ); - xCal->setValue( i18n::CalendarFieldIndex::DAY_OF_MONTH, nDaySet ); - xCal->setValue( i18n::CalendarFieldIndex::MONTH, nMonthSet ); - xCal->setValue( i18n::CalendarFieldIndex::YEAR, nYearSet ); - xCal->setValue( i18n::CalendarFieldIndex::HOUR, nHourSet ); - xCal->setValue( i18n::CalendarFieldIndex::MINUTE, nMinuteSet ); - xCal->setValue( i18n::CalendarFieldIndex::SECOND, nSecondSet ); - bValid = xCal->isValid(); - nDay = xCal->getValue( i18n::CalendarFieldIndex::DAY_OF_MONTH ); - nMyMonth= xCal->getValue( i18n::CalendarFieldIndex::MONTH ); - nYear = xCal->getValue( i18n::CalendarFieldIndex::YEAR ); - nHour = xCal->getValue( i18n::CalendarFieldIndex::HOUR ); - nMinute = xCal->getValue( i18n::CalendarFieldIndex::MINUTE ); - nSecond = xCal->getValue( i18n::CalendarFieldIndex::SECOND ); - bValid = bValid && nDay == nDaySet && nMyMonth == nMonthSet && nYear == - nYearSet && nHour == nHourSet && nMinute == nMinuteSet && nSecond - == nSecondSet; - } -} -#endif // NF_TEST_CALENDAR - - } - - return res; -} - - -//--------------------------------------------------------------------------- -// ScanStartString -// -// ersten String analysieren -// Alles weg => sal_True -// sonst => sal_False - -sal_Bool ImpSvNumberInputScan::ScanStartString( const String& rString, - const SvNumberformat* pFormat ) -{ - xub_StrLen nPos = 0; - - // First of all, eat leading blanks - SkipBlanks(rString, nPos); - - // Yes, nMatchedAllStrings should know about the sign position - nSign = GetSign(rString, nPos); - if ( nSign ) // sign? - SkipBlanks(rString, nPos); - - // #102371# match against format string only if start string is not a sign character - if ( nMatchedAllStrings && !(nSign && rString.Len() == 1) ) - { // Match against format in any case, so later on for a "x1-2-3" input - // we may distinguish between a xy-m-d (or similar) date and a x0-0-0 - // format. No sign detection here! - if ( ScanStringNumFor( rString, nPos, pFormat, 0, sal_True ) ) - nMatchedAllStrings |= nMatchedStartString; - else - nMatchedAllStrings = 0; - } - - if ( GetDecSep(rString, nPos) ) // decimal separator in start string - { - nDecPos = 1; - SkipBlanks(rString, nPos); - } - else if ( GetCurrency(rString, nPos, pFormat) ) // currency (DM 1)? - { - eScannedType = NUMBERFORMAT_CURRENCY; // !!! it IS currency !!! - SkipBlanks(rString, nPos); - if (nSign == 0) // no sign yet - { - nSign = GetSign(rString, nPos); - if ( nSign ) // DM -1 - SkipBlanks(rString, nPos); - } - } - else - { - nMonth = GetMonth(rString, nPos); - if ( nMonth ) // month (Jan 1)? - { - eScannedType = NUMBERFORMAT_DATE; // !!! it IS a date !!! - nMonthPos = 1; // month at the beginning - if ( nMonth < 0 ) - SkipChar( '.', rString, nPos ); // abbreviated - SkipBlanks(rString, nPos); - } - else - { - int nDayOfWeek = GetDayOfWeek( rString, nPos ); - if ( nDayOfWeek ) - { // day of week is just parsed away - eScannedType = NUMBERFORMAT_DATE; // !!! it IS a date !!! - if ( nPos < rString.Len() ) - { - if ( nDayOfWeek < 0 ) - { // abbreviated - if ( rString.GetChar( nPos ) == '.' ) - ++nPos; - } - else - { // full long name - SkipBlanks(rString, nPos); - SkipString( pFormatter->GetLocaleData()->getLongDateDayOfWeekSep(), rString, nPos ); - } - SkipBlanks(rString, nPos); - nMonth = GetMonth(rString, nPos); - if ( nMonth ) // month (Jan 1)? - { - nMonthPos = 1; // month a the beginning - if ( nMonth < 0 ) - SkipChar( '.', rString, nPos ); // abbreviated - SkipBlanks(rString, nPos); - } - } - } - } - } - - // skip any trailing '-' or '/' chars - if (nPos < rString.Len()) - { - while (SkipChar ('-', rString, nPos) || SkipChar ('/', rString, nPos)) { - // do nothing - } - } - if (nPos < rString.Len()) // not everything consumed - { - // Does input StartString equal StartString of format? - // This time with sign detection! - if ( !ScanStringNumFor( rString, nPos, pFormat, 0 ) ) - return MatchedReturn(); - } - - return sal_True; -} - - -//--------------------------------------------------------------------------- -// ScanMidString -// -// String in der Mitte analysieren -// Alles weg => sal_True -// sonst => sal_False - -sal_Bool ImpSvNumberInputScan::ScanMidString( const String& rString, - sal_uInt16 nStringPos, const SvNumberformat* pFormat ) -{ - xub_StrLen nPos = 0; - short eOldScannedType = eScannedType; - - if ( nMatchedAllStrings ) - { // Match against format in any case, so later on for a "1-2-3-4" input - // we may distinguish between a y-m-d (or similar) date and a 0-0-0-0 - // format. - if ( ScanStringNumFor( rString, 0, pFormat, nStringPos ) ) - nMatchedAllStrings |= nMatchedMidString; - else - nMatchedAllStrings = 0; - } - - SkipBlanks(rString, nPos); - if (GetDecSep(rString, nPos)) // decimal separator? - { - if (nDecPos == 1 || nDecPos == 3) // .12.4 or 1.E2.1 - return MatchedReturn(); - else if (nDecPos == 2) // . dup: 12.4. - { - if (bDecSepInDateSeps) // . also date separator - { - if ( eScannedType != NUMBERFORMAT_UNDEFINED && - eScannedType != NUMBERFORMAT_DATE && - eScannedType != NUMBERFORMAT_DATETIME) // already another type - return MatchedReturn(); - if (eScannedType == NUMBERFORMAT_UNDEFINED) - eScannedType = NUMBERFORMAT_DATE; // !!! it IS a date - SkipBlanks(rString, nPos); - } - else - return MatchedReturn(); - } - else - { - nDecPos = 2; // . in mid string - SkipBlanks(rString, nPos); - } - } - else if ( ((eScannedType & NUMBERFORMAT_TIME) == NUMBERFORMAT_TIME) - && GetTime100SecSep( rString, nPos ) ) - { // hundredth seconds separator - if ( nDecPos ) - return MatchedReturn(); - nDecPos = 2; // . in mid string - SkipBlanks(rString, nPos); - } - - if (SkipChar('/', rString, nPos)) // fraction? - { - if ( eScannedType != NUMBERFORMAT_UNDEFINED // already another type - && eScannedType != NUMBERFORMAT_DATE) // except date - return MatchedReturn(); // => jan/31/1994 - else if ( eScannedType != NUMBERFORMAT_DATE // analyzed date until now - && ( eSetType == NUMBERFORMAT_FRACTION // and preset was fraction - || (nAnzNums == 3 // or 3 numbers - && nStringPos > 2) ) ) // and what ??? - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_FRACTION; // !!! it IS a fraction - } - else - nPos--; // put '/' back - } - - if (GetThousandSep(rString, nPos, nStringPos)) // 1,000 - { - if ( eScannedType != NUMBERFORMAT_UNDEFINED // already another type - && eScannedType != NUMBERFORMAT_CURRENCY) // except currency - return MatchedReturn(); - nThousand++; - } - - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - const String& rDate = pFormatter->GetDateSep(); - const String& rTime = pLoc->getTimeSep(); - sal_Unicode cTime = rTime.GetChar(0); - SkipBlanks(rString, nPos); - if ( SkipString(rDate, rString, nPos) // 10., 10-, 10/ - || ((cTime != '.') && SkipChar('.', rString, nPos)) // TRICKY: - || ((cTime != '/') && SkipChar('/', rString, nPos)) // short boolean - || ((cTime != '-') && SkipChar('-', rString, nPos)) ) // evaluation! - { - if ( eScannedType != NUMBERFORMAT_UNDEFINED // already another type - && eScannedType != NUMBERFORMAT_DATE) // except date - return MatchedReturn(); - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_DATE; // !!! it IS a date - short nTmpMonth = GetMonth(rString, nPos); // 10. Jan 94 - if (nMonth && nTmpMonth) // month dup - return MatchedReturn(); - if (nTmpMonth) - { - nMonth = nTmpMonth; - nMonthPos = 2; // month in the middle - if ( nMonth < 0 && SkipChar( '.', rString, nPos ) ) - ; // short month may be abbreviated Jan. - else if ( SkipChar( '-', rString, nPos ) ) - ; // #79632# recognize 17-Jan-2001 to be a date - // #99065# short and long month name - else - SkipString( pLoc->getLongDateMonthSep(), rString, nPos ); - SkipBlanks(rString, nPos); - } - } - - short nTempMonth = GetMonth(rString, nPos); // month in the middle (10 Jan 94) - if (nTempMonth) - { - if (nMonth != 0) // month dup - return MatchedReturn(); - if ( eScannedType != NUMBERFORMAT_UNDEFINED // already another type - && eScannedType != NUMBERFORMAT_DATE) // except date - return MatchedReturn(); - eScannedType = NUMBERFORMAT_DATE; // !!! it IS a date - nMonth = nTempMonth; - nMonthPos = 2; // month in the middle - if ( nMonth < 0 ) - SkipChar( '.', rString, nPos ); // abbreviated - SkipString( pLoc->getLongDateMonthSep(), rString, nPos ); - SkipBlanks(rString, nPos); - } - - if ( SkipChar('E', rString, nPos) // 10E, 10e, 10,Ee - || SkipChar('e', rString, nPos) ) - { - if (eScannedType != NUMBERFORMAT_UNDEFINED) // already another type - return MatchedReturn(); - else - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_SCIENTIFIC; // !!! it IS scientific - if ( nThousand+2 == nAnzNums // special case 1.E2 - && nDecPos == 2 ) - nDecPos = 3; // 1,100.E2 1,100,100.E3 - } - nESign = GetESign(rString, nPos); // signed exponent? - SkipBlanks(rString, nPos); - } - - if ( SkipString(rTime, rString, nPos) ) // time separator? - { - if (nDecPos) // already . => maybe error - { - if (bDecSepInDateSeps) // . also date sep - { - if ( eScannedType != NUMBERFORMAT_DATE && // already another type than date - eScannedType != NUMBERFORMAT_DATETIME) // or date time - return MatchedReturn(); - if (eScannedType == NUMBERFORMAT_DATE) - nDecPos = 0; // reset for time transition - } - else - return MatchedReturn(); - } - if ( ( eScannedType == NUMBERFORMAT_DATE // already date type - || eScannedType == NUMBERFORMAT_DATETIME) // or date time - && nAnzNums > 3) // and more than 3 numbers? (31.Dez.94 8:23) - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_DATETIME; // !!! it IS date with time - } - else if ( eScannedType != NUMBERFORMAT_UNDEFINED // already another type - && eScannedType != NUMBERFORMAT_TIME) // except time - return MatchedReturn(); - else - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_TIME; // !!! it IS a time - } - if ( !nTimePos ) - nTimePos = nStringPos + 1; - } - - if (nPos < rString.Len()) - { - switch (eScannedType) - { - case NUMBERFORMAT_DATE: - if (nMonthPos == 1 && pLoc->getLongDateFormat() == MDY) - { - // #68232# recognize long date separators like ", " in "September 5, 1999" - if (SkipString( pLoc->getLongDateDaySep(), rString, nPos )) - SkipBlanks( rString, nPos ); - } - else if (nStringPos == 5 && nPos == 0 && rString.Len() == 1 && - rString.GetChar(0) == 'T' && MayBeIso8601()) - { - // ISO 8601 combined date and time, yyyy-mm-ddThh:mm - ++nPos; - } - break; -#if NF_RECOGNIZE_ISO8601_TIMEZONES - case NUMBERFORMAT_DATETIME: - if (nPos == 0 && rString.Len() == 1 && nStringPos >= 9 && - MayBeIso8601()) - { - // ISO 8601 timezone offset - switch (rString.GetChar(0)) - { - case '+': - case '-': - if (nStringPos == nAnzStrings-2 || - nStringPos == nAnzStrings-4) - { - ++nPos; // yyyy-mm-ddThh:mm[:ss]+xx[[:]yy] - // nTimezonePos needed for GetTimeRef() - if (!nTimezonePos) - nTimezonePos = nStringPos + 1; - } - break; - case ':': - if (nTimezonePos && nStringPos >= 11 && - nStringPos == nAnzStrings-2) - ++nPos; // yyyy-mm-ddThh:mm[:ss]+xx:yy - break; - } - } - break; -#endif - } - } - - if (nPos < rString.Len()) // not everything consumed? - { - if ( nMatchedAllStrings & ~nMatchedVirgin ) - eScannedType = eOldScannedType; - else - return sal_False; - } - - return sal_True; -} - - -//--------------------------------------------------------------------------- -// ScanEndString -// -// Schlussteil analysieren -// Alles weg => sal_True -// sonst => sal_False - -sal_Bool ImpSvNumberInputScan::ScanEndString( const String& rString, - const SvNumberformat* pFormat ) -{ - xub_StrLen nPos = 0; - - if ( nMatchedAllStrings ) - { // Match against format in any case, so later on for a "1-2-3-4" input - // we may distinguish between a y-m-d (or similar) date and a 0-0-0-0 - // format. - if ( ScanStringNumFor( rString, 0, pFormat, 0xFFFF ) ) - nMatchedAllStrings |= nMatchedEndString; - else - nMatchedAllStrings = 0; - } - - SkipBlanks(rString, nPos); - if (GetDecSep(rString, nPos)) // decimal separator? - { - if (nDecPos == 1 || nDecPos == 3) // .12.4 or 12.E4. - return MatchedReturn(); - else if (nDecPos == 2) // . dup: 12.4. - { - if (bDecSepInDateSeps) // . also date sep - { - if ( eScannedType != NUMBERFORMAT_UNDEFINED && - eScannedType != NUMBERFORMAT_DATE && - eScannedType != NUMBERFORMAT_DATETIME) // already another type - return MatchedReturn(); - if (eScannedType == NUMBERFORMAT_UNDEFINED) - eScannedType = NUMBERFORMAT_DATE; // !!! it IS a date - SkipBlanks(rString, nPos); - } - else - return MatchedReturn(); - } - else - { - nDecPos = 3; // . in end string - SkipBlanks(rString, nPos); - } - } - - if ( nSign == 0 // conflict - not signed - && eScannedType != NUMBERFORMAT_DATE) // and not date -//!? catch time too? - { // not signed yet - nSign = GetSign(rString, nPos); // 1- DM - if (nNegCheck) // '(' as sign - return MatchedReturn(); - } - - SkipBlanks(rString, nPos); - if (nNegCheck && SkipChar(')', rString, nPos)) // skip ')' if appropriate - { - nNegCheck = 0; - SkipBlanks(rString, nPos); - } - - if ( GetCurrency(rString, nPos, pFormat) ) // currency symbol? - { - if (eScannedType != NUMBERFORMAT_UNDEFINED) // currency dup - return MatchedReturn(); - else - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_CURRENCY; - } // behind currency a '-' is allowed - if (nSign == 0) // not signed yet - { - nSign = GetSign(rString, nPos); // DM - - SkipBlanks(rString, nPos); - if (nNegCheck) // 3 DM ( - return MatchedReturn(); - } - if ( nNegCheck && eScannedType == NUMBERFORMAT_CURRENCY - && SkipChar(')', rString, nPos) ) - { - nNegCheck = 0; // ')' skipped - SkipBlanks(rString, nPos); // only if currency - } - } - - if ( SkipChar('%', rString, nPos) ) // 1 % - { - if (eScannedType != NUMBERFORMAT_UNDEFINED) // already another type - return MatchedReturn(); - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_PERCENT; - } - - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - const String& rDate = pFormatter->GetDateSep(); - const String& rTime = pLoc->getTimeSep(); - if ( SkipString(rTime, rString, nPos) ) // 10: - { - if (nDecPos) // already , => error - return MatchedReturn(); - if (eScannedType == NUMBERFORMAT_DATE && nAnzNums > 2) // 31.Dez.94 8: - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_DATETIME; - } - else if (eScannedType != NUMBERFORMAT_UNDEFINED && - eScannedType != NUMBERFORMAT_TIME) // already another type - return MatchedReturn(); - else - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_TIME; - } - if ( !nTimePos ) - nTimePos = nAnzStrings; - } - - sal_Unicode cTime = rTime.GetChar(0); - if ( SkipString(rDate, rString, nPos) // 10., 10-, 10/ - || ((cTime != '.') && SkipChar('.', rString, nPos)) // TRICKY: - || ((cTime != '/') && SkipChar('/', rString, nPos)) // short boolean - || ((cTime != '-') && SkipChar('-', rString, nPos)) ) // evaluation! - { - if (eScannedType != NUMBERFORMAT_UNDEFINED && - eScannedType != NUMBERFORMAT_DATE) // already another type - return MatchedReturn(); - else - { - SkipBlanks(rString, nPos); - eScannedType = NUMBERFORMAT_DATE; - } - short nTmpMonth = GetMonth(rString, nPos); // 10. Jan - if (nMonth && nTmpMonth) // month dup - return MatchedReturn(); - if (nTmpMonth) - { - nMonth = nTmpMonth; - nMonthPos = 3; // month at end - if ( nMonth < 0 ) - SkipChar( '.', rString, nPos ); // abbreviated - SkipBlanks(rString, nPos); - } - } - - short nTempMonth = GetMonth(rString, nPos); // 10 Jan - if (nTempMonth) - { - if (nMonth) // month dup - return MatchedReturn(); - if (eScannedType != NUMBERFORMAT_UNDEFINED && - eScannedType != NUMBERFORMAT_DATE) // already another type - return MatchedReturn(); - eScannedType = NUMBERFORMAT_DATE; - nMonth = nTempMonth; - nMonthPos = 3; // month at end - if ( nMonth < 0 ) - SkipChar( '.', rString, nPos ); // abbreviated - SkipBlanks(rString, nPos); - } - - xub_StrLen nOrigPos = nPos; - if (GetTimeAmPm(rString, nPos)) - { - if (eScannedType != NUMBERFORMAT_UNDEFINED && - eScannedType != NUMBERFORMAT_TIME && - eScannedType != NUMBERFORMAT_DATETIME) // already another type - return MatchedReturn(); - else - { - // If not already scanned as time, 6.78am does not result in 6 - // seconds and 78 hundredths in the morning. Keep as suffix. - if (eScannedType != NUMBERFORMAT_TIME && nDecPos == 2 && nAnzNums == 2) - nPos = nOrigPos; // rewind am/pm - else - { - SkipBlanks(rString, nPos); - if ( eScannedType != NUMBERFORMAT_DATETIME ) - eScannedType = NUMBERFORMAT_TIME; - } - } - } - - if ( nNegCheck && SkipChar(')', rString, nPos) ) - { - if (eScannedType == NUMBERFORMAT_CURRENCY) // only if currency - { - nNegCheck = 0; // skip ')' - SkipBlanks(rString, nPos); - } - else - return MatchedReturn(); - } - - if ( nPos < rString.Len() && - (eScannedType == NUMBERFORMAT_DATE - || eScannedType == NUMBERFORMAT_DATETIME) ) - { // day of week is just parsed away - xub_StrLen nOldPos = nPos; - const String& rSep = pFormatter->GetLocaleData()->getLongDateDayOfWeekSep(); - if ( StringContains( rSep, rString, nPos ) ) - { - nPos = nPos + rSep.Len(); - SkipBlanks(rString, nPos); - } - int nDayOfWeek = GetDayOfWeek( rString, nPos ); - if ( nDayOfWeek ) - { - if ( nPos < rString.Len() ) - { - if ( nDayOfWeek < 0 ) - { // short - if ( rString.GetChar( nPos ) == '.' ) - ++nPos; - } - SkipBlanks(rString, nPos); - } - } - else - nPos = nOldPos; - } - -#if NF_RECOGNIZE_ISO8601_TIMEZONES - if (nPos == 0 && eScannedType == NUMBERFORMAT_DATETIME && - rString.Len() == 1 && rString.GetChar(0) == 'Z' && MayBeIso8601()) - { - // ISO 8601 timezone UTC yyyy-mm-ddThh:mmZ - ++nPos; - } -#endif - - if (nPos < rString.Len()) // everything consumed? - { - // does input EndString equal EndString in Format? - if ( !ScanStringNumFor( rString, nPos, pFormat, 0xFFFF ) ) - return sal_False; - } - - return sal_True; -} - - -sal_Bool ImpSvNumberInputScan::ScanStringNumFor( - const String& rString, // String to scan - xub_StrLen nPos, // Position until which was consumed - const SvNumberformat* pFormat, // The format to match - sal_uInt16 nString, // Substring of format, 0xFFFF => last - sal_Bool bDontDetectNegation // Suppress sign detection - ) -{ - if ( !pFormat ) - return sal_False; - const ::utl::TransliterationWrapper* pTransliteration = pFormatter->GetTransliteration(); - const String* pStr; - String aString( rString ); - sal_Bool bFound = sal_False; - sal_Bool bFirst = sal_True; - sal_Bool bContinue = sal_True; - sal_uInt16 nSub; - do - { - // Don't try "lower" subformats ff the very first match was the second - // or third subformat. - nSub = nStringScanNumFor; - do - { // Step through subformats, first positive, then negative, then - // other, but not the last (text) subformat. - pStr = pFormat->GetNumForString( nSub, nString, sal_True ); - if ( pStr && pTransliteration->isEqual( aString, *pStr ) ) - { - bFound = sal_True; - bContinue = sal_False; - } - else if ( nSub < 2 ) - ++nSub; - else - bContinue = sal_False; - } while ( bContinue ); - if ( !bFound && bFirst && nPos ) - { // try remaining substring - bFirst = sal_False; - aString.Erase( 0, nPos ); - bContinue = sal_True; - } - } while ( bContinue ); - - if ( !bFound ) - { - if ( !bDontDetectNegation && (nString == 0) && !bFirst && (nSign < 0) - && pFormat->IsNegativeRealNegative() ) - { // simply negated twice? --1 - aString.EraseAllChars( ' ' ); - if ( (aString.Len() == 1) && (aString.GetChar(0) == '-') ) - { - bFound = sal_True; - nStringScanSign = -1; - nSub = 0; //! not 1 - } - } - if ( !bFound ) - return sal_False; - } - else if ( !bDontDetectNegation && (nSub == 1) && - pFormat->IsNegativeRealNegative() ) - { // negative - if ( nStringScanSign < 0 ) - { - if ( (nSign < 0) && (nStringScanNumFor != 1) ) - nStringScanSign = 1; // triple negated --1 yyy - } - else if ( nStringScanSign == 0 ) - { - if ( nSign < 0 ) - { // nSign and nStringScanSign will be combined later, - // flip sign if doubly negated - if ( (nString == 0) && !bFirst - && SvNumberformat::HasStringNegativeSign( aString ) ) - nStringScanSign = -1; // direct double negation - else if ( pFormat->IsNegativeWithoutSign() ) - nStringScanSign = -1; // indirect double negation - } - else - nStringScanSign = -1; - } - else // > 0 - nStringScanSign = -1; - } - nStringScanNumFor = nSub; - return sal_True; -} - - -//--------------------------------------------------------------------------- -// IsNumberFormatMain -// -// Recognizes types of number, exponential, fraction, percent, currency, date, time. -// Else text => return sal_False - -sal_Bool ImpSvNumberInputScan::IsNumberFormatMain( - const String& rString, // string to be analyzed - double& , // OUT: result as number, if possible - const SvNumberformat* pFormat ) // maybe number format set to match against -{ - Reset(); - NumberStringDivision( rString ); // breakdown into strings and numbers - if (nAnzStrings >= SV_MAX_ANZ_INPUT_STRINGS) // too many elements - return sal_False; // Njet, Nope, ... - - if (nAnzNums == 0) // no number in input - { - if ( nAnzStrings > 0 ) - { - // Here we may change the original, we don't need it anymore. - // This saves copies and ToUpper() in GetLogical() and is faster. - String& rStrArray = sStrArray[0]; - rStrArray.EraseTrailingChars( ' ' ); - rStrArray.EraseLeadingChars( ' ' ); - nLogical = GetLogical( rStrArray ); - if ( nLogical ) - { - eScannedType = NUMBERFORMAT_LOGICAL; // !!! it's a BOOLEAN - nMatchedAllStrings &= ~nMatchedVirgin; - return sal_True; - } - else - return sal_False; // simple text - } - else - return sal_False; // simple text - } - - sal_uInt16 i = 0; // mark any symbol - sal_uInt16 j = 0; // mark only numbers - - switch ( nAnzNums ) - { - case 1 : // Exactly 1 number in input - { // nAnzStrings >= 1 - if (GetNextNumber(i,j)) // i=1,0 - { // Number at start - if (eSetType == NUMBERFORMAT_FRACTION) // Fraction 1 = 1/1 - { - if (i >= nAnzStrings || // no end string nor decimal separator - sStrArray[i] == pFormatter->GetNumDecimalSep()) - { - eScannedType = NUMBERFORMAT_FRACTION; - nMatchedAllStrings &= ~nMatchedVirgin; - return sal_True; - } - } - } - else - { // Analyze start string - if (!ScanStartString( sStrArray[i], pFormat )) // i=0 - return sal_False; // already an error - i++; // next symbol, i=1 - } - GetNextNumber(i,j); // i=1,2 - if (eSetType == NUMBERFORMAT_FRACTION) // Fraction -1 = -1/1 - { - if (nSign && !nNegCheck && // Sign +, - - eScannedType == NUMBERFORMAT_UNDEFINED && // not date or currency - nDecPos == 0 && // no previous decimal separator - (i >= nAnzStrings || // no end string nor decimal separator - sStrArray[i] == pFormatter->GetNumDecimalSep()) - ) - { - eScannedType = NUMBERFORMAT_FRACTION; - nMatchedAllStrings &= ~nMatchedVirgin; - return sal_True; - } - } - if (i < nAnzStrings && !ScanEndString( sStrArray[i], pFormat )) - return sal_False; - } - break; - case 2 : // Exactly 2 numbers in input - { // nAnzStrings >= 3 - if (!GetNextNumber(i,j)) // i=1,0 - { // Analyze start string - if (!ScanStartString( sStrArray[i], pFormat )) - return sal_False; // already an error - i++; // i=1 - } - GetNextNumber(i,j); // i=1,2 - if ( !ScanMidString( sStrArray[i], i, pFormat ) ) - return sal_False; - i++; // next symbol, i=2,3 - GetNextNumber(i,j); // i=3,4 - if (i < nAnzStrings && !ScanEndString( sStrArray[i], pFormat )) - return sal_False; - if (eSetType == NUMBERFORMAT_FRACTION) // -1,200. as fraction - { - if (!nNegCheck && // no sign '(' - eScannedType == NUMBERFORMAT_UNDEFINED && - (nDecPos == 0 || nDecPos == 3) // no decimal separator or at end - ) - { - eScannedType = NUMBERFORMAT_FRACTION; - nMatchedAllStrings &= ~nMatchedVirgin; - return sal_True; - } - } - } - break; - case 3 : // Exactly 3 numbers in input - { // nAnzStrings >= 5 - if (!GetNextNumber(i,j)) // i=1,0 - { // Analyze start string - if (!ScanStartString( sStrArray[i], pFormat )) - return sal_False; // already an error - i++; // i=1 - if (nDecPos == 1) // decimal separator at start => error - return sal_False; - } - GetNextNumber(i,j); // i=1,2 - if ( !ScanMidString( sStrArray[i], i, pFormat ) ) - return sal_False; - i++; // i=2,3 - if (eScannedType == NUMBERFORMAT_SCIENTIFIC) // E only at end - return sal_False; - GetNextNumber(i,j); // i=3,4 - if ( !ScanMidString( sStrArray[i], i, pFormat ) ) - return sal_False; - i++; // i=4,5 - GetNextNumber(i,j); // i=5,6 - if (i < nAnzStrings && !ScanEndString( sStrArray[i], pFormat )) - return sal_False; - if (eSetType == NUMBERFORMAT_FRACTION) // -1,200,100. as fraction - { - if (!nNegCheck && // no sign '(' - eScannedType == NUMBERFORMAT_UNDEFINED && - (nDecPos == 0 || nDecPos == 3) // no decimal separator or at end - ) - { - eScannedType = NUMBERFORMAT_FRACTION; - nMatchedAllStrings &= ~nMatchedVirgin; - return sal_True; - } - } - if ( eScannedType == NUMBERFORMAT_FRACTION && nDecPos ) - return sal_False; // #36857# not a real fraction - } - break; - default: // More than 3 numbers in input - { // nAnzStrings >= 7 - if (!GetNextNumber(i,j)) // i=1,0 - { // Analyze startstring - if (!ScanStartString( sStrArray[i], pFormat )) - return sal_False; // already an error - i++; // i=1 - if (nDecPos == 1) // decimal separator at start => error - return sal_False; - } - GetNextNumber(i,j); // i=1,2 - if ( !ScanMidString( sStrArray[i], i, pFormat ) ) - return sal_False; - i++; // i=2,3 - sal_uInt16 nThOld = 10; // just not 0 or 1 - while (nThOld != nThousand && j < nAnzNums-1) - // Execute at least one time - // but leave one number. - { // Loop over group separators - nThOld = nThousand; - if (eScannedType == NUMBERFORMAT_SCIENTIFIC) // E only at end - return sal_False; - GetNextNumber(i,j); - if ( i < nAnzStrings && !ScanMidString( sStrArray[i], i, pFormat ) ) - return sal_False; - i++; - } - if (eScannedType == NUMBERFORMAT_DATE || // long date or - eScannedType == NUMBERFORMAT_TIME || // long time or - eScannedType == NUMBERFORMAT_UNDEFINED) // long number - { - for (sal_uInt16 k = j; k < nAnzNums-1; k++) - { - if (eScannedType == NUMBERFORMAT_SCIENTIFIC) // E only at endd - return sal_False; - GetNextNumber(i,j); - if ( i < nAnzStrings && !ScanMidString( sStrArray[i], i, pFormat ) ) - return sal_False; - i++; - } - } - GetNextNumber(i,j); - if (i < nAnzStrings && !ScanEndString( sStrArray[i], pFormat )) - return sal_False; - if (eSetType == NUMBERFORMAT_FRACTION) // -1,200,100. as fraction - { - if (!nNegCheck && // no sign '(' - eScannedType == NUMBERFORMAT_UNDEFINED && - (nDecPos == 0 || nDecPos == 3) // no decimal separator or at end - ) - { - eScannedType = NUMBERFORMAT_FRACTION; - nMatchedAllStrings &= ~nMatchedVirgin; - return sal_True; - } - } - if ( eScannedType == NUMBERFORMAT_FRACTION && nDecPos ) - return sal_False; // #36857# not a real fraction - } - } - - if (eScannedType == NUMBERFORMAT_UNDEFINED) - { - nMatchedAllStrings &= ~nMatchedVirgin; - // did match including nMatchedUsedAsReturn - sal_Bool bDidMatch = (nMatchedAllStrings != 0); - if ( nMatchedAllStrings ) - { - sal_Bool bMatch = (pFormat ? pFormat->IsNumForStringElementCountEqual( - nStringScanNumFor, nAnzStrings, nAnzNums ) : sal_False); - if ( !bMatch ) - nMatchedAllStrings = 0; - } - if ( nMatchedAllStrings ) - eScannedType = eSetType; - else if ( bDidMatch ) - return sal_False; - else - eScannedType = NUMBERFORMAT_NUMBER; - // everything else should have been recognized by now - } - else if ( eScannedType == NUMBERFORMAT_DATE ) - { // the very relaxed date input checks may interfere with a preset format - nMatchedAllStrings &= ~nMatchedVirgin; - sal_Bool bWasReturn = ((nMatchedAllStrings & nMatchedUsedAsReturn) != 0); - if ( nMatchedAllStrings ) - { - sal_Bool bMatch = (pFormat ? pFormat->IsNumForStringElementCountEqual( - nStringScanNumFor, nAnzStrings, nAnzNums ) : sal_False); - if ( !bMatch ) - nMatchedAllStrings = 0; - } - if ( nMatchedAllStrings ) - eScannedType = eSetType; - else if ( bWasReturn ) - return sal_False; - } - else - nMatchedAllStrings = 0; // reset flag to no substrings matched - - return sal_True; -} - - -//--------------------------------------------------------------------------- -// return sal_True or sal_False depending on the nMatched... state and remember usage -sal_Bool ImpSvNumberInputScan::MatchedReturn() -{ - if ( nMatchedAllStrings & ~nMatchedVirgin ) - { - nMatchedAllStrings |= nMatchedUsedAsReturn; - return sal_True; - } - return sal_False; -} - - -//--------------------------------------------------------------------------- -// Initialize uppercase months and weekdays - -void ImpSvNumberInputScan::InitText() -{ - sal_Int32 j, nElems; - const CharClass* pChrCls = pFormatter->GetCharClass(); - const CalendarWrapper* pCal = pFormatter->GetCalendar(); - delete [] pUpperMonthText; - delete [] pUpperAbbrevMonthText; - ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::CalendarItem > xElems - = pCal->getMonths(); - nElems = xElems.getLength(); - pUpperMonthText = new String[nElems]; - pUpperAbbrevMonthText = new String[nElems]; - for ( j=0; j<nElems; j++ ) - { - pUpperMonthText[j] = pChrCls->upper( xElems[j].FullName ); - pUpperAbbrevMonthText[j] = pChrCls->upper( xElems[j].AbbrevName ); - } - delete [] pUpperDayText; - delete [] pUpperAbbrevDayText; - xElems = pCal->getDays(); - nElems = xElems.getLength(); - pUpperDayText = new String[nElems]; - pUpperAbbrevDayText = new String[nElems]; - for ( j=0; j<nElems; j++ ) - { - pUpperDayText[j] = pChrCls->upper( xElems[j].FullName ); - pUpperAbbrevDayText[j] = pChrCls->upper( xElems[j].AbbrevName ); - } - bTextInitialized = sal_True; -} - - -//=========================================================================== -// P U B L I C - -//--------------------------------------------------------------------------- -// ChangeIntl -// -// MUST be called if International/Locale is changed - -void ImpSvNumberInputScan::ChangeIntl() -{ - sal_Unicode cDecSep = pFormatter->GetNumDecimalSep().GetChar(0); - bDecSepInDateSeps = ( cDecSep == '-' || - cDecSep == '/' || - cDecSep == '.' || - cDecSep == pFormatter->GetDateSep().GetChar(0) ); - bTextInitialized = sal_False; - aUpperCurrSymbol.Erase(); -} - - -//--------------------------------------------------------------------------- -// ChangeNullDate - -void ImpSvNumberInputScan::ChangeNullDate( - const sal_uInt16 Day, - const sal_uInt16 Month, - const sal_uInt16 Year ) -{ - if ( pNullDate ) - *pNullDate = Date(Day, Month, Year); - else - pNullDate = new Date(Day, Month, Year); -} - - -//--------------------------------------------------------------------------- -// IsNumberFormat -// -// => does rString represent a number (also date, time et al) - -sal_Bool ImpSvNumberInputScan::IsNumberFormat( - const String& rString, // string to be analyzed - short& F_Type, // IN: old type, OUT: new type - double& fOutNumber, // OUT: number if convertable - const SvNumberformat* pFormat ) // maybe a number format to match against -{ - String sResString; - String aString; - sal_Bool res; // return value - eSetType = F_Type; // old type set - - if ( !rString.Len() ) - res = sal_False; - else if (rString.Len() > 308) // arbitrary - res = sal_False; - else - { - // NoMoreUpperNeeded, all comparisons on UpperCase - aString = pFormatter->GetCharClass()->upper( rString ); - // convert native number to ASCII if necessary - TransformInput( aString ); - res = IsNumberFormatMain( aString, fOutNumber, pFormat ); - } - - if (res) - { - if ( nNegCheck // ')' not found for '(' - || (nSign && (eScannedType == NUMBERFORMAT_DATE - || eScannedType == NUMBERFORMAT_DATETIME)) - ) // signed date/datetime - res = sal_False; - else - { // check count of partial number strings - switch (eScannedType) - { - case NUMBERFORMAT_PERCENT: - case NUMBERFORMAT_CURRENCY: - case NUMBERFORMAT_NUMBER: - if (nDecPos == 1) // .05 - { - // matched MidStrings function like group separators - if ( nMatchedAllStrings ) - nThousand = nAnzNums - 1; - else if ( nAnzNums != 1 ) - res = sal_False; - } - else if (nDecPos == 2) // 1.05 - { - // matched MidStrings function like group separators - if ( nMatchedAllStrings ) - nThousand = nAnzNums - 1; - else if ( nAnzNums != nThousand+2 ) - res = sal_False; - } - else // 1,100 or 1,100. - { - // matched MidStrings function like group separators - if ( nMatchedAllStrings ) - nThousand = nAnzNums - 1; - else if ( nAnzNums != nThousand+1 ) - res = sal_False; - } - break; - - case NUMBERFORMAT_SCIENTIFIC: // 1.0e-2 - if (nDecPos == 1) // .05 - { - if (nAnzNums != 2) - res = sal_False; - } - else if (nDecPos == 2) // 1.05 - { - if (nAnzNums != nThousand+3) - res = sal_False; - } - else // 1,100 or 1,100. - { - if (nAnzNums != nThousand+2) - res = sal_False; - } - break; - - case NUMBERFORMAT_DATE: - if (nMonth) - { // month name and numbers - if (nAnzNums > 2) - res = sal_False; - } - else - { - if (nAnzNums > 3) - res = sal_False; - } - break; - - case NUMBERFORMAT_TIME: - if (nDecPos) - { // hundredth seconds included - if (nAnzNums > 4) - res = sal_False; - } - else - { - if (nAnzNums > 3) - res = sal_False; - } - break; - - case NUMBERFORMAT_DATETIME: - if (nMonth) - { // month name and numbers - if (nDecPos) - { // hundredth seconds included - if (nAnzNums > 6) - res = sal_False; - } - else - { - if (nAnzNums > 5) - res = sal_False; - } - } - else - { - if (nDecPos) - { // hundredth seconds included - if (nAnzNums > 7) - res = sal_False; - } - else - { - if (nAnzNums > 6) - res = sal_False; - } - } - break; - - default: - break; - } // switch - } // else - } // if (res) - - if (res) - { // we finally have a number - switch (eScannedType) - { - case NUMBERFORMAT_LOGICAL: - if (nLogical == 1) - fOutNumber = 1.0; // True - else if (nLogical == -1) - fOutNumber = 0.0; // False - else - res = sal_False; // Oops - break; - - case NUMBERFORMAT_PERCENT: - case NUMBERFORMAT_CURRENCY: - case NUMBERFORMAT_NUMBER: - case NUMBERFORMAT_SCIENTIFIC: - case NUMBERFORMAT_DEFINED: // if no category detected handle as number - { - if ( nDecPos == 1 ) // . at start - sResString.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "0." ) ); - else - sResString.Erase(); - sal_uInt16 k; - for ( k = 0; k <= nThousand; k++) - sResString += sStrArray[nNums[k]]; // integer part - if ( nDecPos == 2 && k < nAnzNums ) // . somewhere - { - sResString += '.'; - sal_uInt16 nStop = (eScannedType == NUMBERFORMAT_SCIENTIFIC ? - nAnzNums-1 : nAnzNums); - for ( ; k < nStop; k++) - sResString += sStrArray[nNums[k]]; // fractional part - } - - if (eScannedType != NUMBERFORMAT_SCIENTIFIC) - fOutNumber = StringToDouble(sResString); - else - { // append exponent - sResString += 'E'; - if ( nESign == -1 ) - sResString += '-'; - sResString += sStrArray[nNums[nAnzNums-1]]; - rtl_math_ConversionStatus eStatus; - fOutNumber = ::rtl::math::stringToDouble( - sResString, '.', ',', &eStatus, NULL ); - if ( eStatus == rtl_math_ConversionStatus_OutOfRange ) - { - F_Type = NUMBERFORMAT_TEXT; // overflow/underflow -> Text - if (nESign == -1) - fOutNumber = 0.0; - else - fOutNumber = DBL_MAX; -/*!*/ return sal_True; - } - } - - if ( nStringScanSign ) - { - if ( nSign ) - nSign *= nStringScanSign; - else - nSign = nStringScanSign; - } - if ( nSign < 0 ) - fOutNumber = -fOutNumber; - - if (eScannedType == NUMBERFORMAT_PERCENT) - fOutNumber/= 100.0; - } - break; - - case NUMBERFORMAT_FRACTION: - if (nAnzNums == 1) - fOutNumber = StringToDouble(sStrArray[nNums[0]]); - else if (nAnzNums == 2) - { - if (nThousand == 1) - { - sResString = sStrArray[nNums[0]]; - sResString += sStrArray[nNums[1]]; // integer part - fOutNumber = StringToDouble(sResString); - } - else - { - double fZaehler = StringToDouble(sStrArray[nNums[0]]); - double fNenner = StringToDouble(sStrArray[nNums[1]]); - if (fNenner != 0.0) - fOutNumber = fZaehler/fNenner; - else - res = sal_False; - } - } - else // nAnzNums > 2 - { - sal_uInt16 k = 1; - sResString = sStrArray[nNums[0]]; - if (nThousand > 0) - for (k = 1; k <= nThousand; k++) - sResString += sStrArray[nNums[k]]; - fOutNumber = StringToDouble(sResString); - - if (k == nAnzNums-2) - { - double fZaehler = StringToDouble(sStrArray[nNums[k]]); - double fNenner = StringToDouble(sStrArray[nNums[k+1]]); - if (fNenner != 0.0) - fOutNumber += fZaehler/fNenner; - else - res = sal_False; - } - } - - if ( nStringScanSign ) - { - if ( nSign ) - nSign *= nStringScanSign; - else - nSign = nStringScanSign; - } - if ( nSign < 0 ) - fOutNumber = -fOutNumber; - break; - - case NUMBERFORMAT_TIME: - GetTimeRef(fOutNumber, 0, nAnzNums); - if ( nSign < 0 ) - fOutNumber = -fOutNumber; - break; - - case NUMBERFORMAT_DATE: - { - sal_uInt16 nCounter = 0; // dummy here - res = GetDateRef( fOutNumber, nCounter, pFormat ); - } - break; - - case NUMBERFORMAT_DATETIME: - { - sal_uInt16 nCounter = 0; // needed here - res = GetDateRef( fOutNumber, nCounter, pFormat ); - if ( res ) - { - double fTime; - GetTimeRef( fTime, nCounter, nAnzNums - nCounter ); - fOutNumber += fTime; - } - } - break; - - default: - DBG_ERRORFILE( "Some number recognized but what's it?" ); - fOutNumber = 0.0; - break; - } - } - - if (res) // overflow/underflow -> Text - { - if (fOutNumber < -DBL_MAX) // -1.7E308 - { - F_Type = NUMBERFORMAT_TEXT; - fOutNumber = -DBL_MAX; - return sal_True; - } - else if (fOutNumber > DBL_MAX) // 1.7E308 - { - F_Type = NUMBERFORMAT_TEXT; - fOutNumber = DBL_MAX; - return sal_True; - } - } - - if (res == sal_False) - { - eScannedType = NUMBERFORMAT_TEXT; - fOutNumber = 0.0; - } - - F_Type = eScannedType; - return res; -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforfind.hxx b/svl/source/numbers/zforfind.hxx deleted file mode 100644 index 8357ab674d..0000000000 --- a/svl/source/numbers/zforfind.hxx +++ /dev/null @@ -1,291 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _ZFORFIND_HXX -#define _ZFORFIND_HXX - -#include <tools/string.hxx> - -class Date; -class SvNumberformat; -class SvNumberFormatter; - -#define SV_MAX_ANZ_INPUT_STRINGS 20 // max count of substrings in input scanner - -class ImpSvNumberInputScan -{ -public: - ImpSvNumberInputScan( SvNumberFormatter* pFormatter ); - ~ImpSvNumberInputScan(); - -/*!*/ void ChangeIntl(); // MUST be called if language changes - - /// set reference date for offset calculation - void ChangeNullDate( - const sal_uInt16 nDay, - const sal_uInt16 nMonth, - const sal_uInt16 nYear ); - - /// convert input string to number - sal_Bool IsNumberFormat( - const String& rString, /// input string - short& F_Type, /// format type (in + out) - double& fOutNumber, /// value determined (out) - const SvNumberformat* pFormat = NULL /// optional a number format to which compare against - ); - - /// after IsNumberFormat: get decimal position - short GetDecPos() const { return nDecPos; } - /// after IsNumberFormat: get count of numeric substrings in input string - sal_uInt16 GetAnzNums() const { return nAnzNums; } - - /// set threshold of two-digit year input - void SetYear2000( sal_uInt16 nVal ) { nYear2000 = nVal; } - /// get threshold of two-digit year input - sal_uInt16 GetYear2000() const { return nYear2000; } - -private: - SvNumberFormatter* pFormatter; - String* pUpperMonthText; // Array of month names, uppercase - String* pUpperAbbrevMonthText; // Array of month names, abbreviated, uppercase - String* pUpperDayText; // Array of day of week names, uppercase - String* pUpperAbbrevDayText; // Array of day of week names, abbreviated, uppercase - String aUpperCurrSymbol; // Currency symbol, uppercase - sal_Bool bTextInitialized; // Whether days and months are initialized - Date* pNullDate; // 30Dec1899 - // Variables for provisional results: - String sStrArray[SV_MAX_ANZ_INPUT_STRINGS]; // Array of scanned substrings - sal_Bool IsNum[SV_MAX_ANZ_INPUT_STRINGS]; // Whether a substring is numeric - sal_uInt16 nNums[SV_MAX_ANZ_INPUT_STRINGS]; // Sequence of offsets to numeric strings - sal_uInt16 nAnzStrings; // Total count of scanned substrings - sal_uInt16 nAnzNums; // Count of numeric substrings - sal_Bool bDecSepInDateSeps; // True <=> DecSep in {.,-,/,DateSep} - sal_uInt8 nMatchedAllStrings; // Scan...String() matched all substrings, - // bit mask of nMatched... constants - - static const sal_uInt8 nMatchedEndString; // 0x01 - static const sal_uInt8 nMatchedMidString; // 0x02 - static const sal_uInt8 nMatchedStartString; // 0x04 - static const sal_uInt8 nMatchedVirgin; // 0x08 - static const sal_uInt8 nMatchedUsedAsReturn; // 0x10 - - int nSign; // Sign of number - short nMonth; // Month (1..x) if date - // negative => short format - short nMonthPos; // 1 = front, 2 = middle - // 3 = end - sal_uInt16 nTimePos; // Index of first time separator (+1) - short nDecPos; // Index of substring containing "," (+1) - short nNegCheck; // '( )' for negative - short nESign; // Sign of exponent - short nAmPm; // +1 AM, -1 PM, 0 if none - short nLogical; // -1 => False, 1 => True - sal_uInt16 nThousand; // Count of group (AKA thousand) separators - sal_uInt16 nPosThousandString; // Position of concatenaded 000,000,000 string - short eScannedType; // Scanned type - short eSetType; // Preset Type - - sal_uInt16 nStringScanNumFor; // Fixed strings recognized in - // pFormat->NumFor[nNumForStringScan] - short nStringScanSign; // Sign resulting of FixString - sal_uInt16 nYear2000; // Two-digit threshold - // Year as 20xx - // default 18 - // number <= nYear2000 => 20xx - // number > nYear2000 => 19xx - sal_uInt16 nTimezonePos; // Index of timezone separator (+1) - sal_uInt8 nMayBeIso8601; // 0:=dontknowyet, 1:=yes, 2:=no - -#ifdef _ZFORFIND_CXX // methods private to implementation - void Reset(); // Reset all variables before start of analysis - - void InitText(); // Init of months and days of week - - // Convert string to double. - // Only simple unsigned floating point values without any error detection, - // decimal separator has to be '.' - // If bForceFraction==sal_True the string is taken to be the fractional part - // of 0.1234 without the leading 0. (thus being just "1234"). - double StringToDouble( - const String& rStr, - sal_Bool bForceFraction = sal_False ); - - sal_Bool NextNumberStringSymbol( // Next number/string symbol - const sal_Unicode*& pStr, - String& rSymbol ); - - sal_Bool SkipThousands( // Concatenate ,000,23 blocks - const sal_Unicode*& pStr, // in input to 000123 - String& rSymbol ); - - void NumberStringDivision( // Divide numbers/strings into - const String& rString ); // arrays and variables above. - // Leading blanks and blanks - // after numbers are thrown away - - - // optimized substring versions - - static inline sal_Bool StringContains( // Whether rString contains rWhat at nPos - const String& rWhat, - const String& rString, - xub_StrLen nPos ) - { // mostly used with one character - if ( rWhat.GetChar(0) != rString.GetChar(nPos) ) - return sal_False; - return StringContainsImpl( rWhat, rString, nPos ); - } - static inline sal_Bool StringPtrContains( // Whether pString contains rWhat at nPos - const String& rWhat, - const sal_Unicode* pString, - xub_StrLen nPos ) // nPos MUST be a valid offset from pString - { // mostly used with one character - if ( rWhat.GetChar(0) != *(pString+nPos) ) - return sal_False; - return StringPtrContainsImpl( rWhat, pString, nPos ); - } - static sal_Bool StringContainsImpl( //! DO NOT use directly - const String& rWhat, - const String& rString, - xub_StrLen nPos ); - static sal_Bool StringPtrContainsImpl( //! DO NOT use directly - const String& rWhat, - const sal_Unicode* pString, - xub_StrLen nPos ); - - - static inline sal_Bool SkipChar( // Skip a special character - sal_Unicode c, - const String& rString, - xub_StrLen& nPos ); - static inline void SkipBlanks( // Skip blank - const String& rString, - xub_StrLen& nPos ); - static inline sal_Bool SkipString( // Jump over rWhat in rString at nPos - const String& rWhat, - const String& rString, - xub_StrLen& nPos ); - - inline sal_Bool GetThousandSep( // Recognizes exactly ,111 as group separator - const String& rString, - xub_StrLen& nPos, - sal_uInt16 nStringPos ); - short GetLogical( // Get boolean value - const String& rString ); - short GetMonth( // Get month and advance string position - const String& rString, - xub_StrLen& nPos ); - int GetDayOfWeek( // Get day of week and advance string position - const String& rString, - xub_StrLen& nPos ); - sal_Bool GetCurrency( // Get currency symbol and advance string position - const String& rString, - xub_StrLen& nPos, - const SvNumberformat* pFormat = NULL ); // optional number format to match against - sal_Bool GetTimeAmPm( // Get symbol AM or PM and advance string position - const String& rString, - xub_StrLen& nPos ); - inline sal_Bool GetDecSep( // Get decimal separator and advance string position - const String& rString, - xub_StrLen& nPos ); - inline sal_Bool GetTime100SecSep( // Get hundredth seconds separator and advance string position - const String& rString, - xub_StrLen& nPos ); - int GetSign( // Get sign and advance string position - const String& rString, // Including special case '(' - xub_StrLen& nPos ); - short GetESign( // Get sign of exponent and advance string position - const String& rString, - xub_StrLen& nPos ); - - inline sal_Bool GetNextNumber( // Get next number as array offset - sal_uInt16& i, - sal_uInt16& j ); - - void GetTimeRef( // Converts time -> double (only decimals) - double& fOutNumber, // result as double - sal_uInt16 nIndex, // Index of hour in input - sal_uInt16 nAnz ); // Count of time substrings in input - sal_uInt16 ImplGetDay ( sal_uInt16 nIndex ); // Day input, 0 if no match - sal_uInt16 ImplGetMonth( sal_uInt16 nIndex ); // Month input, zero based return, NumberOfMonths if no match - sal_uInt16 ImplGetYear ( sal_uInt16 nIndex ); // Year input, 0 if no match - sal_Bool GetDateRef( // Conversion of date to number - double& fDays, // OUT: days diff to null date - sal_uInt16& nCounter, // Count of date substrings - const SvNumberformat* pFormat = NULL ); // optional number format to match against - - sal_Bool ScanStartString( // Analyze start of string - const String& rString, - const SvNumberformat* pFormat = NULL ); - sal_Bool ScanMidString( // Analyze middle substring - const String& rString, - sal_uInt16 nStringPos, - const SvNumberformat* pFormat = NULL ); - sal_Bool ScanEndString( // Analyze end of string - const String& rString, - const SvNumberformat* pFormat = NULL ); - - // Whether input may be a ISO 8601 date format, yyyy-mm-dd... - // checks if at least 3 numbers and first number>31 - bool MayBeIso8601(); - - // Compare rString to substring of array indexed by nString - // nString == 0xFFFF => last substring - sal_Bool ScanStringNumFor( - const String& rString, - xub_StrLen nPos, - const SvNumberformat* pFormat, - sal_uInt16 nString, - sal_Bool bDontDetectNegation = sal_False ); - - // if nMatchedAllStrings set nMatchedUsedAsReturn and return sal_True, - // else do nothing and return sal_False - sal_Bool MatchedReturn(); - - //! Be sure that the string to be analyzed is already converted to upper - //! case and if it contained native humber digits that they are already - //! converted to ASCII. - sal_Bool IsNumberFormatMain( // Main anlyzing function - const String& rString, - double& fOutNumber, // return value if string is numeric - const SvNumberformat* pFormat = NULL // optional number format to match against - ); - - static inline sal_Bool MyIsdigit( sal_Unicode c ); - - // native number transliteration if necessary - void TransformInput( String& rString ); - -#endif // _ZFORFIND_CXX -}; - - - -#endif // _ZFORFIND_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforlist.cxx b/svl/source/numbers/zforlist.cxx deleted file mode 100644 index 1772a58668..0000000000 --- a/svl/source/numbers/zforlist.cxx +++ /dev/null @@ -1,4426 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <tools/debug.hxx> -#include <unotools/charclass.hxx> -#include <i18npool/mslangid.hxx> -#include <unotools/localedatawrapper.hxx> -#include <unotools/numberformatcodewrapper.hxx> -#include <unotools/calendarwrapper.hxx> -#include <com/sun/star/i18n/KNumberFormatUsage.hpp> -#include <com/sun/star/i18n/KNumberFormatType.hpp> -#include <comphelper/processfactory.hxx> -#include <unotools/misccfg.hxx> - -#define _SVSTDARR_USHORTS -#include <svl/svstdarr.hxx> - -#define _ZFORLIST_CXX -#include <osl/mutex.hxx> -#include <svl/zforlist.hxx> -#undef _ZFORLIST_CXX - -#include "zforscan.hxx" -#include "zforfind.hxx" -#include <svl/zformat.hxx> -#include "numhead.hxx" - -#include <unotools/syslocaleoptions.hxx> -#include <unotools/digitgroupingiterator.hxx> -#include <rtl/logfile.hxx> -#include <rtl/instance.hxx> -#include <rtl/strbuf.hxx> - -#include <math.h> -#include <limits> - -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::i18n; -using namespace ::com::sun::star::lang; - -using ::rtl::OUString; - - -// Constants for type offsets per Country/Language (CL) -#define ZF_STANDARD 0 -#define ZF_STANDARD_PERCENT 10 -#define ZF_STANDARD_CURRENCY 20 -#define ZF_STANDARD_DATE 30 -#define ZF_STANDARD_TIME 40 -#define ZF_STANDARD_DATETIME 50 -#define ZF_STANDARD_SCIENTIFIC 60 -#define ZF_STANDARD_FRACTION 70 -#define ZF_STANDARD_NEWEXTENDED 75 -#define ZF_STANDARD_NEWEXTENDEDMAX SV_MAX_ANZ_STANDARD_FORMATE-2 // 98 -#define ZF_STANDARD_LOGICAL SV_MAX_ANZ_STANDARD_FORMATE-1 // 99 -#define ZF_STANDARD_TEXT SV_MAX_ANZ_STANDARD_FORMATE // 100 - -/* Locale that is set if an unknown locale (from another system) is loaded of - * legacy documents. Can not be SYSTEM because else, for example, a German "DM" - * (old currency) is recognized as a date (#53155#). */ -#define UNKNOWN_SUBSTITUTE LANGUAGE_ENGLISH_US - -static sal_Bool bIndexTableInitialized = sal_False; -static sal_uInt32 theIndexTable[NF_INDEX_TABLE_ENTRIES]; - - -// ==================================================================== - -/** - instead of every number formatter being a listener we have a registry which - also handles one instance of the SysLocale options - */ - -typedef ::std::vector< SvNumberFormatter* > SvNumberFormatterList_impl; - -class SvNumberFormatterRegistry_Impl : public utl::ConfigurationListener -{ - SvNumberFormatterList_impl aFormatters; - SvtSysLocaleOptions aSysLocaleOptions; - LanguageType eSysLanguage; - -public: - SvNumberFormatterRegistry_Impl(); - virtual ~SvNumberFormatterRegistry_Impl(); - - void Insert( SvNumberFormatter* pThis ) - { aFormatters.push_back( pThis ); } - - SvNumberFormatter* Remove( SvNumberFormatter* pThis ); - - size_t Count() - { return aFormatters.size(); } - - virtual void ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 ); -}; - -SvNumberFormatterRegistry_Impl::SvNumberFormatterRegistry_Impl() -{ - eSysLanguage = MsLangId::getRealLanguage( LANGUAGE_SYSTEM ); - aSysLocaleOptions.AddListener( this ); -} - - -SvNumberFormatterRegistry_Impl::~SvNumberFormatterRegistry_Impl() -{ - aSysLocaleOptions.RemoveListener( this ); -} - - -SvNumberFormatter* SvNumberFormatterRegistry_Impl::Remove( SvNumberFormatter* pThis ) -{ - for( - SvNumberFormatterList_impl::iterator it = aFormatters.begin(); - it < aFormatters.end(); - ++it - ) { - if ( *it == pThis ) { - aFormatters.erase( it ); - break; - } - } - return pThis; -} - -void SvNumberFormatterRegistry_Impl::ConfigurationChanged( - utl::ConfigurationBroadcaster*, - sal_uInt32 nHint -) { - if ( nHint & SYSLOCALEOPTIONS_HINT_LOCALE ) - { - ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() ); - for( size_t i = 0, n = aFormatters.size(); i < n; ++i ) - aFormatters[ i ]->ReplaceSystemCL( eSysLanguage ); - eSysLanguage = MsLangId::getRealLanguage( LANGUAGE_SYSTEM ); - } - if ( nHint & SYSLOCALEOPTIONS_HINT_CURRENCY ) - { - ::osl::MutexGuard aGuard( SvNumberFormatter::GetMutex() ); - for( size_t i = 0, n = aFormatters.size(); i < n; ++i ) - aFormatters[ i ]->ResetDefaultSystemCurrency(); - } -} - - -// ==================================================================== - -SvNumberFormatterRegistry_Impl* SvNumberFormatter::pFormatterRegistry = NULL; -sal_Bool SvNumberFormatter::bCurrencyTableInitialized = sal_False; -namespace -{ - struct theCurrencyTable : - public rtl::Static< NfCurrencyTable, theCurrencyTable > {}; - - struct theLegacyOnlyCurrencyTable : - public rtl::Static< NfCurrencyTable, theLegacyOnlyCurrencyTable > {}; -} -sal_uInt16 SvNumberFormatter::nSystemCurrencyPosition = 0; -SV_IMPL_PTRARR( NfCurrencyTable, NfCurrencyEntry* ); -SV_IMPL_PTRARR( NfWSStringsDtor, String* ); - -// ob das BankSymbol immer am Ende ist (1 $;-1 $) oder sprachabhaengig -#define NF_BANKSYMBOL_FIX_POSITION 1 - - -/***********************Funktionen SvNumberFormatter**************************/ - -const sal_uInt16 SvNumberFormatter::UNLIMITED_PRECISION = ::std::numeric_limits<sal_uInt16>::max(); -const sal_uInt16 SvNumberFormatter::INPUTSTRING_PRECISION = ::std::numeric_limits<sal_uInt16>::max()-1; -NfInstalledLocales SvNumberFormatter::theInstalledLocales; - -SvNumberFormatter::SvNumberFormatter( - const Reference< XMultiServiceFactory >& xSMgr, - LanguageType eLang ) - : - xServiceManager( xSMgr ) -{ - ImpConstruct( eLang ); -} - - -SvNumberFormatter::SvNumberFormatter( LanguageType eLang ) -{ - ImpConstruct( eLang ); -} - - -SvNumberFormatter::~SvNumberFormatter() -{ - { - ::osl::MutexGuard aGuard( GetMutex() ); - pFormatterRegistry->Remove( this ); - if ( !pFormatterRegistry->Count() ) - { - delete pFormatterRegistry; - pFormatterRegistry = NULL; - } - } - - SvNumberformat* pEntry = aFTable.First(); - while (pEntry) - { - delete pEntry; - pEntry = aFTable.Next(); - } - delete pFormatTable; - delete pCharClass; - delete pStringScanner; - delete pFormatScanner; - ClearMergeTable(); - delete pMergeTable; -} - - -void SvNumberFormatter::ImpConstruct( LanguageType eLang ) -{ - RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog, "svl", "er93726", "SvNumberFormatter::ImpConstruct" ); - - if ( eLang == LANGUAGE_DONTKNOW ) - eLang = UNKNOWN_SUBSTITUTE; - IniLnge = eLang; - ActLnge = eLang; - eEvalDateFormat = NF_EVALDATEFORMAT_INTL; - nDefaultSystemCurrencyFormat = NUMBERFORMAT_ENTRY_NOT_FOUND; - - aLocale = MsLangId::convertLanguageToLocale( eLang ); - pCharClass = new CharClass( xServiceManager, aLocale ); - xLocaleData.init( xServiceManager, aLocale, eLang ); - xCalendar.init( xServiceManager, aLocale ); - xTransliteration.init( xServiceManager, eLang, - ::com::sun::star::i18n::TransliterationModules_IGNORE_CASE ); - xNatNum.init( xServiceManager ); - - // cached locale data items - const LocaleDataWrapper* pLoc = GetLocaleData(); - aDecimalSep = pLoc->getNumDecimalSep(); - aThousandSep = pLoc->getNumThousandSep(); - aDateSep = pLoc->getDateSep(); - - pStringScanner = new ImpSvNumberInputScan( this ); - pFormatScanner = new ImpSvNumberformatScan( this ); - pFormatTable = NULL; - MaxCLOffset = 0; - ImpGenerateFormats( 0, sal_False ); // 0 .. 999 for initialized language formats - pMergeTable = NULL; - bNoZero = sal_False; - - ::osl::MutexGuard aGuard( GetMutex() ); - GetFormatterRegistry().Insert( this ); -} - - -void SvNumberFormatter::ChangeIntl(LanguageType eLnge) -{ - if (ActLnge != eLnge) - { - ActLnge = eLnge; - - aLocale = MsLangId::convertLanguageToLocale( eLnge ); - pCharClass->setLocale( aLocale ); - xLocaleData.changeLocale( aLocale, eLnge ); - xCalendar.changeLocale( aLocale ); - xTransliteration.changeLocale( eLnge ); - - // cached locale data items, initialize BEFORE calling ChangeIntl below - const LocaleDataWrapper* pLoc = GetLocaleData(); - aDecimalSep = pLoc->getNumDecimalSep(); - aThousandSep = pLoc->getNumThousandSep(); - aDateSep = pLoc->getDateSep(); - - pFormatScanner->ChangeIntl(); - pStringScanner->ChangeIntl(); - } -} - - -// static -::osl::Mutex& SvNumberFormatter::GetMutex() -{ - static ::osl::Mutex* pMutex = NULL; - if( !pMutex ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if( !pMutex ) - { - // #i77768# Due to a static reference in the toolkit lib - // we need a mutex that lives longer than the svl library. - // Otherwise the dtor would use a destructed mutex!! - pMutex = new ::osl::Mutex; - } - } - return *pMutex; -} - - -// static -SvNumberFormatterRegistry_Impl& SvNumberFormatter::GetFormatterRegistry() -{ - ::osl::MutexGuard aGuard( GetMutex() ); - if ( !pFormatterRegistry ) - pFormatterRegistry = new SvNumberFormatterRegistry_Impl; - return *pFormatterRegistry; -} - - -Color* SvNumberFormatter::GetUserDefColor(sal_uInt16 nIndex) -{ - if( aColorLink.IsSet() ) - return (Color*) ( aColorLink.Call( (void*) &nIndex )); - else - return NULL; -} - -void SvNumberFormatter::ChangeNullDate(sal_uInt16 nDay, - sal_uInt16 nMonth, - sal_uInt16 nYear) -{ - pFormatScanner->ChangeNullDate(nDay, nMonth, nYear); - pStringScanner->ChangeNullDate(nDay, nMonth, nYear); -} - -Date* SvNumberFormatter::GetNullDate() -{ - return pFormatScanner->GetNullDate(); -} - -void SvNumberFormatter::ChangeStandardPrec(short nPrec) -{ - pFormatScanner->ChangeStandardPrec(nPrec); -} - -sal_uInt16 SvNumberFormatter::GetStandardPrec() -{ - return pFormatScanner->GetStandardPrec(); -} - -void SvNumberFormatter::ImpChangeSysCL( LanguageType eLnge, sal_Bool bLoadingSO5 ) -{ - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = UNKNOWN_SUBSTITUTE; - if (eLnge != IniLnge) - { - IniLnge = eLnge; - ChangeIntl(eLnge); - SvNumberformat* pEntry = aFTable.First(); - while (pEntry) // delete old formats - { - pEntry = (SvNumberformat*) aFTable.Remove(aFTable.GetCurKey()); - delete pEntry; - pEntry = (SvNumberformat*) aFTable.First(); - } - ImpGenerateFormats( 0, bLoadingSO5 ); // new standard formats - } - else if ( bLoadingSO5 ) - { // delete additional standard formats - sal_uInt32 nKey; - aFTable.Seek( SV_MAX_ANZ_STANDARD_FORMATE + 1 ); - while ( (nKey = aFTable.GetCurKey()) > SV_MAX_ANZ_STANDARD_FORMATE && - nKey < SV_COUNTRY_LANGUAGE_OFFSET ) - { - SvNumberformat* pEntry = (SvNumberformat*) aFTable.Remove( nKey ); - delete pEntry; - } - } -} - - -void SvNumberFormatter::ReplaceSystemCL( LanguageType eOldLanguage ) -{ - sal_uInt32 nCLOffset = ImpGetCLOffset( LANGUAGE_SYSTEM ); - if ( nCLOffset > MaxCLOffset ) - return ; // no SYSTEM entries to replace - - const sal_uInt32 nMaxBuiltin = nCLOffset + SV_MAX_ANZ_STANDARD_FORMATE; - const sal_uInt32 nNextCL = nCLOffset + SV_COUNTRY_LANGUAGE_OFFSET; - sal_uInt32 nKey; - - // remove old builtin formats - aFTable.Seek( nCLOffset ); - while ( (nKey = aFTable.GetCurKey()) >= nCLOffset && nKey <= nMaxBuiltin && aFTable.Count() ) - { - SvNumberformat* pEntry = (SvNumberformat*) aFTable.Remove( nKey ); - delete pEntry; - } - - // move additional and user defined to temporary table - Table aOldTable; - while ( (nKey = aFTable.GetCurKey()) >= nCLOffset && nKey < nNextCL && aFTable.Count() ) - { - SvNumberformat* pEntry = (SvNumberformat*) aFTable.Remove( nKey ); - aOldTable.Insert( nKey, pEntry ); - } - - // generate new old builtin formats - // reset ActLnge otherwise ChangeIntl() wouldn't switch if already LANGUAGE_SYSTEM - ActLnge = LANGUAGE_DONTKNOW; - ChangeIntl( LANGUAGE_SYSTEM ); - ImpGenerateFormats( nCLOffset, sal_True ); - - // convert additional and user defined from old system to new system - SvNumberformat* pStdFormat = (SvNumberformat*) aFTable.Get( nCLOffset + ZF_STANDARD ); - sal_uInt32 nLastKey = nMaxBuiltin; - pFormatScanner->SetConvertMode( eOldLanguage, LANGUAGE_SYSTEM, sal_True ); - aOldTable.First(); - while ( aOldTable.Count() ) - { - nKey = aOldTable.GetCurKey(); - if ( nLastKey < nKey ) - nLastKey = nKey; - SvNumberformat* pOldEntry = (SvNumberformat*) aOldTable.Remove( nKey ); - String aString( pOldEntry->GetFormatstring() ); - xub_StrLen nCheckPos = STRING_NOTFOUND; - - // Same as PutEntry() but assures key position even if format code is - // a duplicate. Also won't mix up any LastInsertKey. - ChangeIntl( eOldLanguage ); - LanguageType eLge = eOldLanguage; // ConvertMode changes this - bool bCheck = false; - SvNumberformat* pNewEntry = new SvNumberformat( aString, pFormatScanner, - pStringScanner, nCheckPos, eLge ); - if ( nCheckPos != 0 ) - delete pNewEntry; - else - { - short eCheckType = pNewEntry->GetType(); - if ( eCheckType != NUMBERFORMAT_UNDEFINED ) - pNewEntry->SetType( eCheckType | NUMBERFORMAT_DEFINED ); - else - pNewEntry->SetType( NUMBERFORMAT_DEFINED ); - - if ( !aFTable.Insert( nKey, pNewEntry ) ) - delete pNewEntry; - else - bCheck = true; - } - DBG_ASSERT( bCheck, "SvNumberFormatter::ReplaceSystemCL: couldn't convert" ); - (void)bCheck; - - delete pOldEntry; - } - pFormatScanner->SetConvertMode(sal_False); - pStdFormat->SetLastInsertKey( sal_uInt16(nLastKey - nCLOffset) ); - - // append new system additional formats - NumberFormatCodeWrapper aNumberFormatCode( xServiceManager, GetLocale() ); - ImpGenerateAdditionalFormats( nCLOffset, aNumberFormatCode, sal_True ); -} - - -sal_Bool SvNumberFormatter::IsTextFormat(sal_uInt32 F_Index) const -{ - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(F_Index); - if (!pFormat) - return sal_False; - else - return pFormat->IsTextFormat(); -} - -sal_Bool SvNumberFormatter::HasTextFormat(sal_uInt32 F_Index) const -{ - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(F_Index); - if (!pFormat) - return sal_False; - else - return pFormat->HasTextFormat(); -} - -sal_Bool SvNumberFormatter::PutEntry(String& rString, - xub_StrLen& nCheckPos, - short& nType, - sal_uInt32& nKey, // Formatnummer - LanguageType eLnge) -{ - nKey = 0; - if (rString.Len() == 0) // keinen Leerstring - { - nCheckPos = 1; // -> Fehler - return sal_False; - } - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - - ChangeIntl(eLnge); // ggfs. austauschen - LanguageType eLge = eLnge; // Umgehung const fuer ConvertMode - sal_Bool bCheck = sal_False; - SvNumberformat* p_Entry = new SvNumberformat(rString, - pFormatScanner, - pStringScanner, - nCheckPos, - eLge); - if (nCheckPos == 0) // Format ok - { // Typvergleich: - short eCheckType = p_Entry->GetType(); - if ( eCheckType != NUMBERFORMAT_UNDEFINED) - { - p_Entry->SetType(eCheckType | NUMBERFORMAT_DEFINED); - nType = eCheckType; - } - else - { - p_Entry->SetType(NUMBERFORMAT_DEFINED); - nType = NUMBERFORMAT_DEFINED; - } - sal_uInt32 CLOffset = ImpGenerateCL(eLge); // ggfs. neu Standard- - // formate anlegen - nKey = ImpIsEntry(p_Entry->GetFormatstring(),CLOffset, eLge); - if (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // schon vorhanden - delete p_Entry; - else - { - SvNumberformat* pStdFormat = - (SvNumberformat*) aFTable.Get(CLOffset + ZF_STANDARD); - sal_uInt32 nPos = CLOffset + pStdFormat->GetLastInsertKey(); - if (nPos - CLOffset >= SV_COUNTRY_LANGUAGE_OFFSET) - { - OSL_FAIL("SvNumberFormatter:: Zu viele Formate pro CL"); - delete p_Entry; - } - else if (!aFTable.Insert(nPos+1,p_Entry)) - delete p_Entry; - else - { - bCheck = sal_True; - nKey = nPos+1; - pStdFormat->SetLastInsertKey((sal_uInt16) (nKey-CLOffset)); - } - } - } - else - delete p_Entry; - return bCheck; -} - -bool SvNumberFormatter::PutEntry( - OUString& rString, xub_StrLen& nCheckPos, short& nType, sal_uInt32& nKey, - LanguageType eLnge) -{ - // Wrapper to allow rtl::OUString to be used. - String aStr(rString); - bool bRet = PutEntry(aStr, nCheckPos, nType, nKey, eLnge); - rString = aStr; - return bRet; -} - -bool SvNumberFormatter::PutandConvertEntry(String& rString, - xub_StrLen& nCheckPos, - short& nType, - sal_uInt32& nKey, - LanguageType eLnge, - LanguageType eNewLnge) -{ - bool bRes; - if (eNewLnge == LANGUAGE_DONTKNOW) - eNewLnge = IniLnge; - - pFormatScanner->SetConvertMode(eLnge, eNewLnge); - bRes = PutEntry(rString, nCheckPos, nType, nKey, eLnge); - pFormatScanner->SetConvertMode(false); - return bRes; -} - - -bool SvNumberFormatter::PutandConvertEntrySystem(String& rString, - xub_StrLen& nCheckPos, - short& nType, - sal_uInt32& nKey, - LanguageType eLnge, - LanguageType eNewLnge) -{ - sal_Bool bRes; - if (eNewLnge == LANGUAGE_DONTKNOW) - eNewLnge = IniLnge; - - pFormatScanner->SetConvertMode(eLnge, eNewLnge, sal_True); - bRes = PutEntry(rString, nCheckPos, nType, nKey, eLnge); - pFormatScanner->SetConvertMode(sal_False); - return bRes; -} - - -sal_uInt32 SvNumberFormatter::GetIndexPuttingAndConverting( String & rString, - LanguageType eLnge, LanguageType eSysLnge, short & rType, - sal_Bool & rNewInserted, xub_StrLen & rCheckPos ) -{ - sal_uInt32 nKey = NUMBERFORMAT_ENTRY_NOT_FOUND; - rNewInserted = sal_False; - rCheckPos = 0; - - // #62389# empty format string (of Writer) => General standard format - if (!rString.Len()) - ; // nothing - else if (eLnge == LANGUAGE_SYSTEM && eSysLnge != SvtSysLocale().GetLanguage()) - { - sal_uInt32 nOrig = GetEntryKey( rString, eSysLnge ); - if (nOrig == NUMBERFORMAT_ENTRY_NOT_FOUND) - nKey = nOrig; // none avaliable, maybe user-defined - else - nKey = GetFormatForLanguageIfBuiltIn( nOrig, SvtSysLocale().GetLanguage() ); - - if (nKey == nOrig) - { - // Not a builtin format, convert. - // The format code string may get modified and adapted to the real - // language and wouldn't match eSysLnge anymore, do that on a copy. - String aTmp( rString); - rNewInserted = PutandConvertEntrySystem( aTmp, rCheckPos, rType, - nKey, eLnge, SvtSysLocale().GetLanguage()); - if (rCheckPos > 0) - { - DBG_ERRORFILE("SvNumberFormatter::GetIndexPuttingAndConverting: bad format code string for current locale"); - nKey = NUMBERFORMAT_ENTRY_NOT_FOUND; - } - } - } - else - { - nKey = GetEntryKey( rString, eLnge); - if (nKey == NUMBERFORMAT_ENTRY_NOT_FOUND) - { - rNewInserted = PutEntry( rString, rCheckPos, rType, nKey, eLnge); - if (rCheckPos > 0) - { - DBG_ERRORFILE("SvNumberFormatter::GetIndexPuttingAndConverting: bad format code string for specified locale"); - nKey = NUMBERFORMAT_ENTRY_NOT_FOUND; - } - } - } - if (nKey == NUMBERFORMAT_ENTRY_NOT_FOUND) - nKey = GetStandardIndex( eLnge); - rType = GetType( nKey); - // Convert any (!) old "automatic" currency format to new fixed currency - // default format. - if ((rType & NUMBERFORMAT_CURRENCY) != 0) - { - const SvNumberformat* pFormat = GetEntry( nKey); - if (!pFormat->HasNewCurrency()) - { - if (rNewInserted) - { - DeleteEntry( nKey); // don't leave trails of rubbish - rNewInserted = sal_False; - } - nKey = GetStandardFormat( NUMBERFORMAT_CURRENCY, eLnge); - } - } - return nKey; -} - - -void SvNumberFormatter::DeleteEntry(sal_uInt32 nKey) -{ - SvNumberformat* pEntry = aFTable.Remove(nKey); - delete pEntry; -} - -void SvNumberFormatter::PrepareSave() -{ - SvNumberformat* pFormat = aFTable.First(); - while (pFormat) - { - pFormat->SetUsed(sal_False); - pFormat = aFTable.Next(); - } -} - -void SvNumberFormatter::SetFormatUsed(sal_uInt32 nFIndex) -{ - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(nFIndex); - if (pFormat) - pFormat->SetUsed(sal_True); -} - -sal_Bool SvNumberFormatter::Load( SvStream& rStream ) -{ - LanguageType eSysLang = SvtSysLocale().GetLanguage(); - SvNumberFormatter* pConverter = NULL; - - ImpSvNumMultipleReadHeader aHdr( rStream ); - sal_uInt16 nVersion; - rStream >> nVersion; - SvNumberformat* pEntry; - sal_uInt32 nPos; - LanguageType eSaveSysLang, eLoadSysLang; - sal_uInt16 nSysOnStore, eLge, eDummy; // Dummy fuer kompatibles Format - rStream >> nSysOnStore >> eLge; // Systemeinstellung aus - // Dokument - eSaveSysLang = (nVersion < SV_NUMBERFORMATTER_VERSION_SYSTORE ? - LANGUAGE_SYSTEM : (LanguageType) nSysOnStore); - LanguageType eLnge = (LanguageType) eLge; - ImpChangeSysCL( eLnge, sal_True ); - - rStream >> nPos; - while (nPos != NUMBERFORMAT_ENTRY_NOT_FOUND) - { - rStream >> eDummy >> eLge; - eLnge = (LanguageType) eLge; - ImpGenerateCL( eLnge, sal_True ); // ggfs. neue Standardformate anlegen - - sal_uInt32 nOffset = nPos % SV_COUNTRY_LANGUAGE_OFFSET; // relativIndex - sal_Bool bUserDefined = (nOffset > SV_MAX_ANZ_STANDARD_FORMATE); - //! HACK! ER 29.07.97 15:15 - // SaveLang wurde bei SYSTEM nicht gespeichert sondern war auch SYSTEM, - // erst ab 364i Unterscheidung moeglich - sal_Bool bConversionHack; - if ( eLnge == LANGUAGE_SYSTEM ) - { - if ( nVersion < SV_NUMBERFORMATTER_VERSION_SYSTORE ) - { - bConversionHack = bUserDefined; - eLoadSysLang = eSaveSysLang; - } - else - { - bConversionHack = sal_False; - eLoadSysLang = eSysLang; - } - } - else - { - bConversionHack = sal_False; - eLoadSysLang = eSaveSysLang; - } - - pEntry = new SvNumberformat(*pFormatScanner, eLnge); - if ( bConversionHack ) - { // SYSTEM - // nVersion < SV_NUMBERFORMATTER_VERSION_SYSTORE - // nVersion < SV_NUMBERFORMATTER_VERSION_KEYWORDS - if ( !pConverter ) - pConverter = new SvNumberFormatter( xServiceManager, eSysLang ); - NfHackConversion eHackConversion = pEntry->Load( - rStream, aHdr, pConverter, *pStringScanner ); - switch ( eHackConversion ) - { - case NF_CONVERT_GERMAN_ENGLISH : - pEntry->ConvertLanguage( *pConverter, - LANGUAGE_ENGLISH_US, eSysLang, sal_True ); - break; - case NF_CONVERT_ENGLISH_GERMAN : - switch ( eSysLang ) - { - case LANGUAGE_GERMAN: - case LANGUAGE_GERMAN_SWISS: - case LANGUAGE_GERMAN_AUSTRIAN: - case LANGUAGE_GERMAN_LUXEMBOURG: - case LANGUAGE_GERMAN_LIECHTENSTEIN: - // alles beim alten - break; - default: - pEntry->ConvertLanguage( *pConverter, - LANGUAGE_GERMAN, eSysLang, sal_True ); - } - break; - case NF_CONVERT_NONE : - break; // -Wall not handled. - } - - } - else - { - pEntry->Load( rStream, aHdr, NULL, *pStringScanner ); - if ( !bUserDefined ) - bUserDefined = (pEntry->GetNewStandardDefined() > SV_NUMBERFORMATTER_VERSION); - if ( bUserDefined ) - { - if ( eSaveSysLang != eLoadSysLang ) - { // SYSTEM verschieden - if ( !pConverter ) - pConverter = new SvNumberFormatter( xServiceManager, eSysLang ); - if ( nVersion < SV_NUMBERFORMATTER_VERSION_KEYWORDS ) - { - switch ( eSaveSysLang ) - { - case LANGUAGE_GERMAN: - case LANGUAGE_GERMAN_SWISS: - case LANGUAGE_GERMAN_AUSTRIAN: - case LANGUAGE_GERMAN_LUXEMBOURG: - case LANGUAGE_GERMAN_LIECHTENSTEIN: - // alles beim alten - pEntry->ConvertLanguage( *pConverter, - eSaveSysLang, eLoadSysLang, sal_True ); - break; - default: - // alte english nach neuem anderen - pEntry->ConvertLanguage( *pConverter, - LANGUAGE_ENGLISH_US, eLoadSysLang, sal_True ); - } - } - else - pEntry->ConvertLanguage( *pConverter, - eSaveSysLang, eLoadSysLang, sal_True ); - } - else - { // nicht SYSTEM oder gleiches SYSTEM - if ( nVersion < SV_NUMBERFORMATTER_VERSION_KEYWORDS ) - { - LanguageType eLoadLang; - sal_Bool bSystem; - if ( eLnge == LANGUAGE_SYSTEM ) - { - eLoadLang = eSysLang; - bSystem = sal_True; - } - else - { - eLoadLang = eLnge; - bSystem = sal_False; - } - switch ( eLoadLang ) - { - case LANGUAGE_GERMAN: - case LANGUAGE_GERMAN_SWISS: - case LANGUAGE_GERMAN_AUSTRIAN: - case LANGUAGE_GERMAN_LUXEMBOURG: - case LANGUAGE_GERMAN_LIECHTENSTEIN: - // alles beim alten - break; - default: - // alte english nach neuem anderen - if ( !pConverter ) - pConverter = new SvNumberFormatter( xServiceManager, eSysLang ); - pEntry->ConvertLanguage( *pConverter, - LANGUAGE_ENGLISH_US, eLoadLang, bSystem ); - } - } - } - } - } - if ( nOffset == 0 ) // StandardFormat - { - SvNumberformat* pEnt = aFTable.Get(nPos); - if (pEnt) - pEnt->SetLastInsertKey(pEntry->GetLastInsertKey()); - } - if (!aFTable.Insert(nPos, pEntry)) - delete pEntry; - rStream >> nPos; - } - - // ab SV_NUMBERFORMATTER_VERSION_YEAR2000 - if ( nVersion >= SV_NUMBERFORMATTER_VERSION_YEAR2000 ) - { - aHdr.StartEntry(); - if ( aHdr.BytesLeft() >= sizeof(sal_uInt16) ) - { - sal_uInt16 nY2k; - rStream >> nY2k; - if ( nVersion < SV_NUMBERFORMATTER_VERSION_TWODIGITYEAR && nY2k < 100 ) - nY2k += 1901; // war vor src513e: 29, jetzt: 1930 - SetYear2000( nY2k ); - } - aHdr.EndEntry(); - } - - if ( pConverter ) - delete pConverter; - - // generate additional i18n standard formats for all used locales - LanguageType eOldLanguage = ActLnge; - NumberFormatCodeWrapper aNumberFormatCode( xServiceManager, GetLocale() ); - SvUShorts aList; - GetUsedLanguages( aList ); - sal_uInt16 nCount = aList.Count(); - for ( sal_uInt16 j=0; j<nCount; j++ ) - { - LanguageType eLang = aList[j]; - ChangeIntl( eLang ); - sal_uInt32 CLOffset = ImpGetCLOffset( eLang ); - ImpGenerateAdditionalFormats( CLOffset, aNumberFormatCode, sal_True ); - } - ChangeIntl( eOldLanguage ); - - if (rStream.GetError()) - return sal_False; - else - return sal_True; -} - -sal_Bool SvNumberFormatter::Save( SvStream& rStream ) const -{ - ImpSvNumMultipleWriteHeader aHdr( rStream ); - // ab 364i wird gespeichert was SYSTEM wirklich war, vorher hart LANGUAGE_SYSTEM - rStream << (sal_uInt16) SV_NUMBERFORMATTER_VERSION; - rStream << (sal_uInt16) SvtSysLocale().GetLanguage() << (sal_uInt16) IniLnge; - SvNumberFormatTable* pTable = (SvNumberFormatTable*) &aFTable; - SvNumberformat* pEntry = (SvNumberformat*) pTable->First(); - while (pEntry) - { - // Gespeichert werden alle markierten, benutzerdefinierten Formate und - // jeweils das Standardformat zu allen angewaehlten CL-Kombinationen - // sowie NewStandardDefined - if ( pEntry->GetUsed() || (pEntry->GetType() & NUMBERFORMAT_DEFINED) || - pEntry->GetNewStandardDefined() || - (pTable->GetCurKey() % SV_COUNTRY_LANGUAGE_OFFSET == 0) ) - { - rStream << static_cast<sal_uInt32>(pTable->GetCurKey()) - << (sal_uInt16) LANGUAGE_SYSTEM - << (sal_uInt16) pEntry->GetLanguage(); - pEntry->Save(rStream, aHdr); - } - pEntry = (SvNumberformat*) pTable->Next(); - } - rStream << NUMBERFORMAT_ENTRY_NOT_FOUND; // EndeKennung - - // ab SV_NUMBERFORMATTER_VERSION_YEAR2000 - aHdr.StartEntry(); - rStream << (sal_uInt16) GetYear2000(); - aHdr.EndEntry(); - - if (rStream.GetError()) - return sal_False; - else - return sal_True; -} - -void SvNumberFormatter::GetUsedLanguages( SvUShorts& rList ) -{ - rList.Remove( 0, rList.Count() ); - - sal_uInt32 nOffset = 0; - while (nOffset <= MaxCLOffset) - { - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(nOffset); - if (pFormat) - rList.Insert( pFormat->GetLanguage(), rList.Count() ); - nOffset += SV_COUNTRY_LANGUAGE_OFFSET; - } -} - - -void SvNumberFormatter::FillKeywordTable( NfKeywordTable& rKeywords, - LanguageType eLang ) -{ - ChangeIntl( eLang ); - const NfKeywordTable & rTable = pFormatScanner->GetKeywords(); - for ( sal_uInt16 i = 0; i < NF_KEYWORD_ENTRIES_COUNT; ++i ) - { - rKeywords[i] = rTable[i]; - } -} - - -String SvNumberFormatter::GetKeyword( LanguageType eLnge, sal_uInt16 nIndex ) -{ - ChangeIntl(eLnge); - const NfKeywordTable & rTable = pFormatScanner->GetKeywords(); - if ( nIndex < NF_KEYWORD_ENTRIES_COUNT ) - return rTable[nIndex]; - - OSL_FAIL("GetKeyword: invalid index"); - return String(); -} - - -String SvNumberFormatter::GetStandardName( LanguageType eLnge ) -{ - ChangeIntl( eLnge ); - return pFormatScanner->GetStandardName(); -} - - -sal_uInt32 SvNumberFormatter::ImpGetCLOffset(LanguageType eLnge) const -{ - SvNumberformat* pFormat; - sal_uInt32 nOffset = 0; - while (nOffset <= MaxCLOffset) - { - pFormat = (SvNumberformat*) aFTable.Get(nOffset); - if (pFormat && pFormat->GetLanguage() == eLnge) - return nOffset; - nOffset += SV_COUNTRY_LANGUAGE_OFFSET; - } - return nOffset; -} - -sal_uInt32 SvNumberFormatter::ImpIsEntry(const String& rString, - sal_uInt32 nCLOffset, - LanguageType eLnge) -{ -#ifndef NF_COMMENT_IN_FORMATSTRING -#error NF_COMMENT_IN_FORMATSTRING not defined (zformat.hxx) -#endif -#if NF_COMMENT_IN_FORMATSTRING - String aStr( rString ); - SvNumberformat::EraseComment( aStr ); -#endif - sal_uInt32 res = NUMBERFORMAT_ENTRY_NOT_FOUND; - SvNumberformat* pEntry; - pEntry = (SvNumberformat*) aFTable.Seek(nCLOffset); - while ( res == NUMBERFORMAT_ENTRY_NOT_FOUND && - pEntry && pEntry->GetLanguage() == eLnge ) - { -#if NF_COMMENT_IN_FORMATSTRING - if ( pEntry->GetComment().Len() ) - { - String aFormat( pEntry->GetFormatstring() ); - SvNumberformat::EraseComment( aFormat ); - if ( aStr == aFormat ) - res = aFTable.GetCurKey(); - else - pEntry = (SvNumberformat*) aFTable.Next(); - } - else - { - if ( aStr == pEntry->GetFormatstring() ) - res = aFTable.GetCurKey(); - else - pEntry = (SvNumberformat*) aFTable.Next(); - } -#else - if ( rString == pEntry->GetFormatstring() ) - res = aFTable.GetCurKey(); - else - pEntry = (SvNumberformat*) aFTable.Next(); -#endif - } - return res; -} - - -SvNumberFormatTable& SvNumberFormatter::GetFirstEntryTable( - short& eType, - sal_uInt32& FIndex, - LanguageType& rLnge) -{ - short eTypetmp = eType; - if (eType == NUMBERFORMAT_ALL) // Leere Zelle oder don't care - rLnge = IniLnge; - else - { - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(FIndex); - if (!pFormat) - { -// OSL_FAIL("SvNumberFormatter:: Unbekanntes altes Zahlformat (1)"); - rLnge = IniLnge; - eType = NUMBERFORMAT_ALL; - eTypetmp = eType; - } - else - { - rLnge = pFormat->GetLanguage(); - eType = pFormat->GetType()&~NUMBERFORMAT_DEFINED; - if (eType == 0) - { - eType = NUMBERFORMAT_DEFINED; - eTypetmp = eType; - } - else if (eType == NUMBERFORMAT_DATETIME) - { - eTypetmp = eType; - eType = NUMBERFORMAT_DATE; - } - else - eTypetmp = eType; - } - } - ChangeIntl(rLnge); - return GetEntryTable(eTypetmp, FIndex, rLnge); -} - -sal_uInt32 SvNumberFormatter::ImpGenerateCL( LanguageType eLnge, sal_Bool bLoadingSO5 ) -{ - ChangeIntl(eLnge); - sal_uInt32 CLOffset = ImpGetCLOffset(ActLnge); - if (CLOffset > MaxCLOffset) - { // new CL combination - if (LocaleDataWrapper::areChecksEnabled()) - { - Locale aLoadedLocale = xLocaleData->getLoadedLocale(); - if ( aLoadedLocale.Language != aLocale.Language || - aLoadedLocale.Country != aLocale.Country ) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumerFormatter::ImpGenerateCL: locales don't match:")); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg )); - } - // test XML locale data FormatElement entries - { - uno::Sequence< i18n::FormatElement > xSeq = - xLocaleData->getAllFormats(); - // A test for completeness of formatindex="0" ... - // formatindex="47" is not needed here since it is done in - // ImpGenerateFormats(). - - // Test for dupes of formatindex="..." - for ( sal_Int32 j = 0; j < xSeq.getLength(); j++ ) - { - sal_Int16 nIdx = xSeq[j].formatIndex; - String aDupes; - for ( sal_Int32 i = 0; i < xSeq.getLength(); i++ ) - { - if ( i != j && xSeq[i].formatIndex == nIdx ) - { - aDupes += String::CreateFromInt32( i ); - aDupes += '('; - aDupes += String( xSeq[i].formatKey ); - aDupes += ')'; - aDupes += ' '; - } - } - if ( aDupes.Len() ) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "XML locale data FormatElement formatindex dupe: ")); - aMsg += String::CreateFromInt32( nIdx ); - aMsg.AppendAscii( RTL_CONSTASCII_STRINGPARAM( - "\nFormatElements: ")); - aMsg += String::CreateFromInt32( j ); - aMsg += '('; - aMsg += String( xSeq[j].formatKey ); - aMsg += ')'; - aMsg += ' '; - aMsg += aDupes; - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg )); - } - } - } - } - - MaxCLOffset += SV_COUNTRY_LANGUAGE_OFFSET; - ImpGenerateFormats( MaxCLOffset, bLoadingSO5 ); - CLOffset = MaxCLOffset; - } - return CLOffset; -} - -SvNumberFormatTable& SvNumberFormatter::ChangeCL(short eType, - sal_uInt32& FIndex, - LanguageType eLnge) -{ - ImpGenerateCL(eLnge); - return GetEntryTable(eType, FIndex, ActLnge); -} - -SvNumberFormatTable& SvNumberFormatter::GetEntryTable( - short eType, - sal_uInt32& FIndex, - LanguageType eLnge) -{ - if ( pFormatTable ) - pFormatTable->Clear(); - else - pFormatTable = new SvNumberFormatTable; - ChangeIntl(eLnge); - sal_uInt32 CLOffset = ImpGetCLOffset(ActLnge); - - // Might generate and insert a default format for the given type - // (e.g. currency) => has to be done before collecting formats. - sal_uInt32 nDefaultIndex = GetStandardFormat( eType, ActLnge ); - - SvNumberformat* pEntry; - pEntry = (SvNumberformat*) aFTable.Seek(CLOffset); - - if (eType == NUMBERFORMAT_ALL) - { - while (pEntry && pEntry->GetLanguage() == ActLnge) - { // copy all entries to output table - pFormatTable->Insert( aFTable.GetCurKey(), pEntry ); - pEntry = (SvNumberformat*) aFTable.Next(); - } - } - else - { - while (pEntry && pEntry->GetLanguage() == ActLnge) - { // copy entries of queried type to output table - if ((pEntry->GetType()) & eType) - pFormatTable->Insert(aFTable.GetCurKey(),pEntry); - pEntry = (SvNumberformat*) aFTable.Next(); - } - } - if ( pFormatTable->Count() > 0 ) - { // select default if queried format doesn't exist or queried type or - // language differ from existing format - pEntry = aFTable.Get(FIndex); - if ( !pEntry || !(pEntry->GetType() & eType) || pEntry->GetLanguage() != ActLnge ) - FIndex = nDefaultIndex; - } - return *pFormatTable; -} - -sal_Bool SvNumberFormatter::IsNumberFormat(const String& sString, - sal_uInt32& F_Index, - double& fOutNumber) -{ - short FType; - const SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(F_Index); - if (!pFormat) - { -// OSL_FAIL("SvNumberFormatter:: Unbekanntes altes Zahlformat (2)"); - ChangeIntl(IniLnge); - FType = NUMBERFORMAT_NUMBER; - } - else - { - FType = pFormat->GetType() &~NUMBERFORMAT_DEFINED; - if (FType == 0) - FType = NUMBERFORMAT_DEFINED; - ChangeIntl(pFormat->GetLanguage()); - } - sal_Bool res; - short RType = FType; - // Ergebnistyp - // ohne def-Kennung - if (RType == NUMBERFORMAT_TEXT) // Zahlzelle ->Stringz. - res = sal_False; - else - res = pStringScanner->IsNumberFormat(sString, RType, fOutNumber, pFormat); - - if (res && !IsCompatible(FType, RType)) // unpassender Typ - { - switch ( RType ) - { - case NUMBERFORMAT_TIME : - { - if ( pStringScanner->GetDecPos() ) - { // 100stel Sekunden - if ( pStringScanner->GetAnzNums() > 3 || fOutNumber < 0.0 ) - F_Index = GetFormatIndex( NF_TIME_HH_MMSS00, ActLnge ); - else - F_Index = GetFormatIndex( NF_TIME_MMSS00, ActLnge ); - } - else if ( fOutNumber >= 1.0 || fOutNumber < 0.0 ) - F_Index = GetFormatIndex( NF_TIME_HH_MMSS, ActLnge ); - else - F_Index = GetStandardFormat( RType, ActLnge ); - } - break; - default: - F_Index = GetStandardFormat( RType, ActLnge ); - } - } - return res; -} - -sal_Bool SvNumberFormatter::IsCompatible(short eOldType, - short eNewType) -{ - if (eOldType == eNewType) - return sal_True; - else if (eOldType == NUMBERFORMAT_DEFINED) - return sal_True; - else - { - switch (eNewType) - { - case NUMBERFORMAT_NUMBER: - { - switch (eOldType) - { - case NUMBERFORMAT_PERCENT: - case NUMBERFORMAT_CURRENCY: - case NUMBERFORMAT_SCIENTIFIC: - case NUMBERFORMAT_FRACTION: -// case NUMBERFORMAT_LOGICAL: - case NUMBERFORMAT_DEFINED: - return sal_True; - default: - return sal_False; - } - } - break; - case NUMBERFORMAT_DATE: - { - switch (eOldType) - { - case NUMBERFORMAT_DATETIME: - return sal_True; - default: - return sal_False; - } - } - break; - case NUMBERFORMAT_TIME: - { - switch (eOldType) - { - case NUMBERFORMAT_DATETIME: - return sal_True; - default: - return sal_False; - } - } - break; - case NUMBERFORMAT_DATETIME: - { - switch (eOldType) - { - case NUMBERFORMAT_TIME: - case NUMBERFORMAT_DATE: - return sal_True; - default: - return sal_False; - } - } - break; - default: - return sal_False; - } - return sal_False; - } -} - - -sal_uInt32 SvNumberFormatter::ImpGetDefaultFormat( short nType ) -{ - sal_uInt32 CLOffset = ImpGetCLOffset( ActLnge ); - sal_uInt32 nSearch; - switch( nType ) - { - case NUMBERFORMAT_DATE : - nSearch = CLOffset + ZF_STANDARD_DATE; - break; - case NUMBERFORMAT_TIME : - nSearch = CLOffset + ZF_STANDARD_TIME; - break; - case NUMBERFORMAT_DATETIME : - nSearch = CLOffset + ZF_STANDARD_DATETIME; - break; - case NUMBERFORMAT_PERCENT : - nSearch = CLOffset + ZF_STANDARD_PERCENT; - break; - case NUMBERFORMAT_SCIENTIFIC: - nSearch = CLOffset + ZF_STANDARD_SCIENTIFIC; - break; - default: - nSearch = CLOffset + ZF_STANDARD; - } - sal_uInt32 nDefaultFormat = (sal_uInt32)(sal_uLong) aDefaultFormatKeys.Get( nSearch ); - if ( !nDefaultFormat ) - nDefaultFormat = NUMBERFORMAT_ENTRY_NOT_FOUND; - if ( nDefaultFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) - { // look for a defined standard - sal_uInt32 nStopKey = CLOffset + SV_COUNTRY_LANGUAGE_OFFSET; - sal_uInt32 nKey; - aFTable.Seek( CLOffset ); - while ( (nKey = aFTable.GetCurKey()) >= CLOffset && nKey < nStopKey ) - { - const SvNumberformat* pEntry = - (const SvNumberformat*) aFTable.GetCurObject(); - if ( pEntry->IsStandard() && ((pEntry->GetType() & - ~NUMBERFORMAT_DEFINED) == nType) ) - { - nDefaultFormat = nKey; - break; // while - } - aFTable.Next(); - } - - if ( nDefaultFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) - { // none found, use old fixed standards - switch( nType ) - { - case NUMBERFORMAT_DATE : - nDefaultFormat = CLOffset + ZF_STANDARD_DATE; - break; - case NUMBERFORMAT_TIME : - nDefaultFormat = CLOffset + ZF_STANDARD_TIME+1; - break; - case NUMBERFORMAT_DATETIME : - nDefaultFormat = CLOffset + ZF_STANDARD_DATETIME; - break; - case NUMBERFORMAT_PERCENT : - nDefaultFormat = CLOffset + ZF_STANDARD_PERCENT+1; - break; - case NUMBERFORMAT_SCIENTIFIC: - nDefaultFormat = CLOffset + ZF_STANDARD_SCIENTIFIC; - break; - default: - nDefaultFormat = CLOffset + ZF_STANDARD; - } - } - sal_uIntPtr nFormat = nDefaultFormat; - aDefaultFormatKeys.Insert( nSearch, (void*) nFormat ); - } - return nDefaultFormat; -} - - -sal_uInt32 SvNumberFormatter::GetStandardFormat( short eType, LanguageType eLnge ) -{ - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); - switch(eType) - { - case NUMBERFORMAT_CURRENCY : - { - if ( eLnge == LANGUAGE_SYSTEM ) - return ImpGetDefaultSystemCurrencyFormat(); - else - return ImpGetDefaultCurrencyFormat(); - } - case NUMBERFORMAT_DATE : - case NUMBERFORMAT_TIME : - case NUMBERFORMAT_DATETIME : - case NUMBERFORMAT_PERCENT : - case NUMBERFORMAT_SCIENTIFIC: - return ImpGetDefaultFormat( eType ); - - case NUMBERFORMAT_FRACTION : return CLOffset + ZF_STANDARD_FRACTION; - case NUMBERFORMAT_LOGICAL : return CLOffset + ZF_STANDARD_LOGICAL; - case NUMBERFORMAT_TEXT : return CLOffset + ZF_STANDARD_TEXT; - case NUMBERFORMAT_ALL : - case NUMBERFORMAT_DEFINED : - case NUMBERFORMAT_NUMBER : - case NUMBERFORMAT_UNDEFINED : - default : return CLOffset + ZF_STANDARD; - } -} - -sal_Bool SvNumberFormatter::IsSpecialStandardFormat( sal_uInt32 nFIndex, - LanguageType eLnge ) -{ - return - nFIndex == GetFormatIndex( NF_TIME_MMSS00, eLnge ) || - nFIndex == GetFormatIndex( NF_TIME_HH_MMSS00, eLnge ) || - nFIndex == GetFormatIndex( NF_TIME_HH_MMSS, eLnge ) - ; -} - -sal_uInt32 SvNumberFormatter::GetStandardFormat( sal_uInt32 nFIndex, short eType, - LanguageType eLnge ) -{ - if ( IsSpecialStandardFormat( nFIndex, eLnge ) ) - return nFIndex; - else - return GetStandardFormat( eType, eLnge ); -} - -sal_uInt32 SvNumberFormatter::GetStandardFormat( double fNumber, sal_uInt32 nFIndex, - short eType, LanguageType eLnge ) -{ - if ( IsSpecialStandardFormat( nFIndex, eLnge ) ) - return nFIndex; - - switch( eType ) - { - case NUMBERFORMAT_TIME : - { - sal_Bool bSign; - if ( fNumber < 0.0 ) - { - bSign = sal_True; - fNumber = -fNumber; - } - else - bSign = sal_False; - double fSeconds = fNumber * 86400; - if ( floor( fSeconds + 0.5 ) * 100 != floor( fSeconds * 100 + 0.5 ) ) - { // mit 100stel Sekunden - if ( bSign || fSeconds >= 3600 ) - return GetFormatIndex( NF_TIME_HH_MMSS00, eLnge ); - else - return GetFormatIndex( NF_TIME_MMSS00, eLnge ); - } - else - { - if ( bSign || fNumber >= 1.0 ) - return GetFormatIndex( NF_TIME_HH_MMSS, eLnge ); - else - return GetStandardFormat( eType, eLnge ); - } - } - default: - return GetStandardFormat( eType, eLnge ); - } -} - -void SvNumberFormatter::GetInputLineString(const double& fOutNumber, - sal_uInt32 nFIndex, - String& sOutString) -{ - SvNumberformat* pFormat; - Color* pColor; - pFormat = (SvNumberformat*) aFTable.Get(nFIndex); - if (!pFormat) - pFormat = aFTable.Get(ZF_STANDARD); - LanguageType eLang = pFormat->GetLanguage(); - ChangeIntl( eLang ); - short eType = pFormat->GetType() & ~NUMBERFORMAT_DEFINED; - if (eType == 0) - eType = NUMBERFORMAT_DEFINED; - sal_uInt16 nOldPrec = pFormatScanner->GetStandardPrec(); - bool bPrecChanged = false; - if (eType == NUMBERFORMAT_NUMBER || eType == NUMBERFORMAT_PERCENT - || eType == NUMBERFORMAT_CURRENCY - || eType == NUMBERFORMAT_SCIENTIFIC - || eType == NUMBERFORMAT_FRACTION) - { - if (eType != NUMBERFORMAT_PERCENT) // spaeter Sonderbehandlung % - eType = NUMBERFORMAT_NUMBER; - ChangeStandardPrec(INPUTSTRING_PRECISION); - bPrecChanged = true; - } - sal_uInt32 nKey = nFIndex; - switch ( eType ) - { // #61619# always edit using 4-digit year - case NUMBERFORMAT_DATE : - if (::rtl::math::approxFloor( fOutNumber) != fOutNumber) - nKey = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eLang ); - // fdo#34977 preserve time when editing even if only date was - // displayed. - else - nKey = GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang ); - break; - case NUMBERFORMAT_TIME : - if (fOutNumber < 0.0 || fOutNumber >= 1.0) - { - /* XXX NOTE: this is a purely arbitrary value within the limits - * of a signed 16-bit. 32k hours are 3.7 years ... or - * 1903-09-26 if date. */ - if (fabs( fOutNumber) * 24 < 0x7fff) - nKey = GetFormatIndex( NF_TIME_HH_MMSS, eLang ); - // Preserve duration, use [HH]:MM:SS instead of time. - else - nKey = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eLang ); - // Assume that a large value is a datetime with only time - // displayed. - } - else - nKey = GetStandardFormat( fOutNumber, nFIndex, eType, eLang ); - break; - case NUMBERFORMAT_DATETIME : - nKey = GetFormatIndex( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, eLang ); - break; - default: - nKey = GetStandardFormat( fOutNumber, nFIndex, eType, eLang ); - } - if ( nKey != nFIndex ) - pFormat = (SvNumberformat*) aFTable.Get( nKey ); - if (pFormat) - { - if ( eType == NUMBERFORMAT_TIME && pFormat->GetFormatPrecision() ) - { - ChangeStandardPrec(INPUTSTRING_PRECISION); - bPrecChanged = true; - } - pFormat->GetOutputString(fOutNumber, sOutString, &pColor); - } - if (bPrecChanged) - ChangeStandardPrec(nOldPrec); -} - -void SvNumberFormatter::GetOutputString(const double& fOutNumber, - sal_uInt32 nFIndex, - String& sOutString, - Color** ppColor) -{ - if (bNoZero && fOutNumber == 0.0) - { - sOutString.Erase(); - return; - } - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(nFIndex); - if (!pFormat) - pFormat = aFTable.Get(ZF_STANDARD); - ChangeIntl(pFormat->GetLanguage()); - pFormat->GetOutputString(fOutNumber, sOutString, ppColor); -} - -void SvNumberFormatter::GetOutputString(String& sString, - sal_uInt32 nFIndex, - String& sOutString, - Color** ppColor) -{ - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(nFIndex); - if (!pFormat) - pFormat = aFTable.Get(ZF_STANDARD_TEXT); - if (!pFormat->IsTextFormat() && !pFormat->HasTextFormat()) - { - *ppColor = NULL; - sOutString = sString; - } - else - { - ChangeIntl(pFormat->GetLanguage()); - pFormat->GetOutputString(sString, sOutString, ppColor); - } -} - -sal_Bool SvNumberFormatter::GetPreviewString(const String& sFormatString, - double fPreviewNumber, - String& sOutString, - Color** ppColor, - LanguageType eLnge) -{ - if (sFormatString.Len() == 0) // keinen Leerstring - return sal_False; - - xub_StrLen nCheckPos = STRING_NOTFOUND; - sal_uInt32 nKey; - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - ChangeIntl(eLnge); // ggfs. austauschen - eLnge = ActLnge; - String sTmpString = sFormatString; - SvNumberformat* p_Entry = new SvNumberformat(sTmpString, - pFormatScanner, - pStringScanner, - nCheckPos, - eLnge); - if (nCheckPos == 0) // String ok - { - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // ggfs. neu Standard- - // formate anlegen - nKey = ImpIsEntry(p_Entry->GetFormatstring(),CLOffset, eLnge); - if (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // schon vorhanden - GetOutputString(fPreviewNumber,nKey,sOutString,ppColor); - else - p_Entry->GetOutputString(fPreviewNumber,sOutString, ppColor); - delete p_Entry; - return sal_True; - } - else - { - delete p_Entry; - return sal_False; - } -} - -sal_Bool SvNumberFormatter::GetPreviewStringGuess( const String& sFormatString, - double fPreviewNumber, - String& sOutString, - Color** ppColor, - LanguageType eLnge ) -{ - if (sFormatString.Len() == 0) // keinen Leerstring - return sal_False; - - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - - ChangeIntl( eLnge ); - eLnge = ActLnge; - sal_Bool bEnglish = (eLnge == LANGUAGE_ENGLISH_US); - - String aFormatStringUpper( pCharClass->upper( sFormatString ) ); - sal_uInt32 nCLOffset = ImpGenerateCL( eLnge ); - sal_uInt32 nKey = ImpIsEntry( aFormatStringUpper, nCLOffset, eLnge ); - if ( nKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) - { // Zielformat vorhanden - GetOutputString( fPreviewNumber, nKey, sOutString, ppColor ); - return sal_True; - } - - SvNumberformat *pEntry = NULL; - xub_StrLen nCheckPos = STRING_NOTFOUND; - String sTmpString; - - if ( bEnglish ) - { - sTmpString = sFormatString; - pEntry = new SvNumberformat( sTmpString, pFormatScanner, - pStringScanner, nCheckPos, eLnge ); - } - else - { - nCLOffset = ImpGenerateCL( LANGUAGE_ENGLISH_US ); - nKey = ImpIsEntry( aFormatStringUpper, nCLOffset, LANGUAGE_ENGLISH_US ); - sal_Bool bEnglishFormat = (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND); - - // try english --> other bzw. english nach other konvertieren - LanguageType eFormatLang = LANGUAGE_ENGLISH_US; - pFormatScanner->SetConvertMode( LANGUAGE_ENGLISH_US, eLnge ); - sTmpString = sFormatString; - pEntry = new SvNumberformat( sTmpString, pFormatScanner, - pStringScanner, nCheckPos, eFormatLang ); - pFormatScanner->SetConvertMode( sal_False ); - ChangeIntl( eLnge ); - - if ( !bEnglishFormat ) - { - if ( nCheckPos > 0 || xTransliteration->isEqual( sFormatString, - pEntry->GetFormatstring() ) ) - { // other Format - delete pEntry; - sTmpString = sFormatString; - pEntry = new SvNumberformat( sTmpString, pFormatScanner, - pStringScanner, nCheckPos, eLnge ); - } - else - { // verify english - xub_StrLen nCheckPos2 = STRING_NOTFOUND; - // try other --> english - eFormatLang = eLnge; - pFormatScanner->SetConvertMode( eLnge, LANGUAGE_ENGLISH_US ); - sTmpString = sFormatString; - SvNumberformat* pEntry2 = new SvNumberformat( sTmpString, pFormatScanner, - pStringScanner, nCheckPos2, eFormatLang ); - pFormatScanner->SetConvertMode( sal_False ); - ChangeIntl( eLnge ); - if ( nCheckPos2 == 0 && !xTransliteration->isEqual( sFormatString, - pEntry2->GetFormatstring() ) ) - { // other Format - delete pEntry; - sTmpString = sFormatString; - pEntry = new SvNumberformat( sTmpString, pFormatScanner, - pStringScanner, nCheckPos, eLnge ); - } - delete pEntry2; - } - } - } - - if (nCheckPos == 0) // String ok - { - ImpGenerateCL( eLnge ); // ggfs. neu Standardformate anlegen - pEntry->GetOutputString( fPreviewNumber, sOutString, ppColor ); - delete pEntry; - return sal_True; - } - delete pEntry; - return sal_False; -} - -sal_Bool SvNumberFormatter::GetPreviewString( const String& sFormatString, - const String& sPreviewString, - String& sOutString, - Color** ppColor, - LanguageType eLnge ) -{ - if (sFormatString.Len() == 0) // no empty string - return sal_False; - - xub_StrLen nCheckPos = STRING_NOTFOUND; - sal_uInt32 nKey; - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - ChangeIntl(eLnge); // switch if needed - eLnge = ActLnge; - String sTmpString = sFormatString; - SvNumberformat* p_Entry = new SvNumberformat( sTmpString, - pFormatScanner, - pStringScanner, - nCheckPos, - eLnge); - if (nCheckPos == 0) // String ok - { - String aNonConstPreview( sPreviewString); - // May have to create standard formats for this locale. - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); - nKey = ImpIsEntry( p_Entry->GetFormatstring(), CLOffset, eLnge); - if (nKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // already present - GetOutputString( aNonConstPreview, nKey, sOutString, ppColor); - else - { - // If the format is valid but not a text format and does not - // include a text subformat, an empty string would result. Same as - // in SvNumberFormatter::GetOutputString() - if (p_Entry->IsTextFormat() || p_Entry->HasTextFormat()) - p_Entry->GetOutputString( aNonConstPreview, sOutString, ppColor); - else - { - *ppColor = NULL; - sOutString = sPreviewString; - } - } - delete p_Entry; - return sal_True; - } - else - { - delete p_Entry; - return sal_False; - } -} - -sal_uInt32 SvNumberFormatter::TestNewString(const String& sFormatString, - LanguageType eLnge) -{ - if (sFormatString.Len() == 0) // keinen Leerstring - return NUMBERFORMAT_ENTRY_NOT_FOUND; - - xub_StrLen nCheckPos = STRING_NOTFOUND; - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - ChangeIntl(eLnge); // ggfs. austauschen - eLnge = ActLnge; - sal_uInt32 nRes; - String sTmpString = sFormatString; - SvNumberformat* pEntry = new SvNumberformat(sTmpString, - pFormatScanner, - pStringScanner, - nCheckPos, - eLnge); - if (nCheckPos == 0) // String ok - { - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // ggfs. neu Standard- - // formate anlegen - nRes = ImpIsEntry(pEntry->GetFormatstring(),CLOffset, eLnge); - // schon vorhanden ? - } - else - nRes = NUMBERFORMAT_ENTRY_NOT_FOUND; - delete pEntry; - return nRes; -} - -SvNumberformat* SvNumberFormatter::ImpInsertFormat( - const ::com::sun::star::i18n::NumberFormatCode& rCode, - sal_uInt32 nPos, sal_Bool bAfterLoadingSO5, sal_Int16 nOrgIndex ) -{ - String aCodeStr( rCode.Code ); - if ( rCode.Index < NF_INDEX_TABLE_ENTRIES && - rCode.Usage == ::com::sun::star::i18n::KNumberFormatUsage::CURRENCY && - rCode.Index != NF_CURRENCY_1000DEC2_CCC ) - { // strip surrounding [$...] on automatic currency - if ( aCodeStr.SearchAscii( "[$" ) != STRING_NOTFOUND ) - aCodeStr = SvNumberformat::StripNewCurrencyDelimiters( aCodeStr, sal_False ); - else - { - if (LocaleDataWrapper::areChecksEnabled() && - rCode.Index != NF_CURRENCY_1000DEC2_CCC ) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumberFormatter::ImpInsertFormat: no [$...] on currency format code, index ")); - aMsg += String::CreateFromInt32( rCode.Index ); - aMsg.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ":\n")); - aMsg += String( rCode.Code ); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - } - } - xub_StrLen nCheckPos = 0; - SvNumberformat* pFormat = new SvNumberformat(aCodeStr, - pFormatScanner, - pStringScanner, - nCheckPos, - ActLnge); - if ( !pFormat || nCheckPos > 0 ) - { - if (LocaleDataWrapper::areChecksEnabled()) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumberFormatter::ImpInsertFormat: bad format code, index ")); - aMsg += String::CreateFromInt32( rCode.Index ); - aMsg += '\n'; - aMsg += String( rCode.Code ); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - delete pFormat; - return NULL; - } - if ( rCode.Index >= NF_INDEX_TABLE_ENTRIES ) - { - sal_uInt32 nCLOffset = nPos - (nPos % SV_COUNTRY_LANGUAGE_OFFSET); - sal_uInt32 nKey = ImpIsEntry( aCodeStr, nCLOffset, ActLnge ); - if ( nKey != NUMBERFORMAT_ENTRY_NOT_FOUND ) - { - if (LocaleDataWrapper::areChecksEnabled()) - { - switch ( nOrgIndex ) - { - // These may be dupes of integer versions for locales where - // currencies have no decimals like Italian Lira. - case NF_CURRENCY_1000DEC2 : // NF_CURRENCY_1000INT - case NF_CURRENCY_1000DEC2_RED : // NF_CURRENCY_1000INT_RED - case NF_CURRENCY_1000DEC2_DASHED : // NF_CURRENCY_1000INT_RED - break; - default: - if ( !bAfterLoadingSO5 ) - { // If bAfterLoadingSO5 there will definitely be some dupes, - // don't cry. But we need this test for verification of locale - // data if not loading old SO5 documents. - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumberFormatter::ImpInsertFormat: dup format code, index ")); - aMsg += String::CreateFromInt32( rCode.Index ); - aMsg += '\n'; - aMsg += String( rCode.Code ); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - } - } - delete pFormat; - return NULL; - } - else if ( nPos - nCLOffset >= SV_COUNTRY_LANGUAGE_OFFSET ) - { - if (LocaleDataWrapper::areChecksEnabled()) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumberFormatter::ImpInsertFormat: too many format codes, index ")); - aMsg += String::CreateFromInt32( rCode.Index ); - aMsg += '\n'; - aMsg += String( rCode.Code ); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - delete pFormat; - return NULL; - } - } - if ( !aFTable.Insert( nPos, pFormat ) ) - { - if (LocaleDataWrapper::areChecksEnabled()) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "ImpInsertFormat: can't insert number format key pos: ")); - aMsg += String::CreateFromInt32( nPos ); - aMsg.AppendAscii( RTL_CONSTASCII_STRINGPARAM( ", code index ")); - aMsg += String::CreateFromInt32( rCode.Index ); - aMsg += '\n'; - aMsg += String( rCode.Code ); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - delete pFormat; - return NULL; - } - if ( rCode.Default ) - pFormat->SetStandard(); - if ( rCode.DefaultName.getLength() ) - pFormat->SetComment( rCode.DefaultName ); - return pFormat; -} - -SvNumberformat* SvNumberFormatter::ImpInsertNewStandardFormat( - const ::com::sun::star::i18n::NumberFormatCode& rCode, - sal_uInt32 nPos, sal_uInt16 nVersion, sal_Bool bAfterLoadingSO5, - sal_Int16 nOrgIndex ) -{ - SvNumberformat* pNewFormat = ImpInsertFormat( rCode, nPos, - bAfterLoadingSO5, nOrgIndex ); - if (pNewFormat) - pNewFormat->SetNewStandardDefined( nVersion ); - // so that it gets saved, displayed properly, and converted by old versions - return pNewFormat; -} - -void SvNumberFormatter::GetFormatSpecialInfo(sal_uInt32 nFormat, - sal_Bool& bThousand, - sal_Bool& IsRed, - sal_uInt16& nPrecision, - sal_uInt16& nAnzLeading) - -{ - const SvNumberformat* pFormat = aFTable.Get(nFormat); - if (pFormat) - pFormat->GetFormatSpecialInfo(bThousand, IsRed, - nPrecision, nAnzLeading); - else - { - bThousand = sal_False; - IsRed = sal_False; - nPrecision = pFormatScanner->GetStandardPrec(); - nAnzLeading = 0; - } -} - -sal_uInt16 SvNumberFormatter::GetFormatPrecision( sal_uInt32 nFormat ) const -{ - const SvNumberformat* pFormat = aFTable.Get( nFormat ); - if ( pFormat ) - return pFormat->GetFormatPrecision(); - else - return pFormatScanner->GetStandardPrec(); -} - - -String SvNumberFormatter::GetFormatDecimalSep( sal_uInt32 nFormat ) const -{ - const SvNumberformat* pFormat = aFTable.Get( nFormat ); - if ( !pFormat || pFormat->GetLanguage() == ActLnge ) - return GetNumDecimalSep(); - - String aRet; - LanguageType eSaveLang = xLocaleData.getCurrentLanguage(); - if ( pFormat->GetLanguage() == eSaveLang ) - aRet = xLocaleData->getNumDecimalSep(); - else - { - ::com::sun::star::lang::Locale aSaveLocale( xLocaleData->getLocale() ); - ::com::sun::star::lang::Locale aTmpLocale(MsLangId::convertLanguageToLocale(pFormat->GetLanguage())); - ((SvNumberFormatter*)this)->xLocaleData.changeLocale(aTmpLocale, pFormat->GetLanguage() ); - aRet = xLocaleData->getNumDecimalSep(); - ((SvNumberFormatter*)this)->xLocaleData.changeLocale( aSaveLocale, eSaveLang ); - } - return aRet; -} - - -sal_uInt32 SvNumberFormatter::GetFormatSpecialInfo( const String& rFormatString, - sal_Bool& bThousand, sal_Bool& IsRed, sal_uInt16& nPrecision, - sal_uInt16& nAnzLeading, LanguageType eLnge ) - -{ - xub_StrLen nCheckPos = 0; - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - ChangeIntl(eLnge); // ggfs. austauschen - eLnge = ActLnge; - String aTmpStr( rFormatString ); - SvNumberformat* pFormat = new SvNumberformat( aTmpStr, - pFormatScanner, pStringScanner, nCheckPos, eLnge ); - if ( nCheckPos == 0 ) - pFormat->GetFormatSpecialInfo( bThousand, IsRed, nPrecision, nAnzLeading ); - else - { - bThousand = sal_False; - IsRed = sal_False; - nPrecision = pFormatScanner->GetStandardPrec(); - nAnzLeading = 0; - } - delete pFormat; - return nCheckPos; -} - - -inline sal_uInt32 SetIndexTable( NfIndexTableOffset nTabOff, sal_uInt32 nIndOff ) -{ - if ( !bIndexTableInitialized ) - { - DBG_ASSERT( theIndexTable[nTabOff] == NUMBERFORMAT_ENTRY_NOT_FOUND, - "SetIndexTable: theIndexTable[nTabOff] already occupied" ); - theIndexTable[nTabOff] = nIndOff; - } - return nIndOff; -} - - -sal_Int32 SvNumberFormatter::ImpGetFormatCodeIndex( - ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::NumberFormatCode >& rSeq, - const NfIndexTableOffset nTabOff ) -{ - const sal_Int32 nLen = rSeq.getLength(); - for ( sal_Int32 j=0; j<nLen; j++ ) - { - if ( rSeq[j].Index == nTabOff ) - return j; - } - if (LocaleDataWrapper::areChecksEnabled() && (nTabOff < NF_CURRENCY_START - || NF_CURRENCY_END < nTabOff || nTabOff == NF_CURRENCY_1000INT - || nTabOff == NF_CURRENCY_1000INT_RED - || nTabOff == NF_CURRENCY_1000DEC2_CCC)) - { // currency entries with decimals might not exist, e.g. Italian Lira - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumberFormatter::ImpGetFormatCodeIndex: not found: ")); - aMsg += String::CreateFromInt32( nTabOff ); - LocaleDataWrapper::outputCheckMessage( xLocaleData->appendLocaleInfo( - aMsg)); - } - if ( nLen ) - { - sal_Int32 j; - // look for a preset default - for ( j=0; j<nLen; j++ ) - { - if ( rSeq[j].Default ) - return j; - } - // currencies are special, not all format codes must exist, but all - // builtin number format key index positions must have a format assigned - if ( NF_CURRENCY_START <= nTabOff && nTabOff <= NF_CURRENCY_END ) - { - // look for a format with decimals - for ( j=0; j<nLen; j++ ) - { - if ( rSeq[j].Index == NF_CURRENCY_1000DEC2 ) - return j; - } - // last resort: look for a format without decimals - for ( j=0; j<nLen; j++ ) - { - if ( rSeq[j].Index == NF_CURRENCY_1000INT ) - return j; - } - } - } - else - { // we need at least _some_ format - rSeq.realloc(1); - rSeq[0] = ::com::sun::star::i18n::NumberFormatCode(); - String aTmp( '0' ); - aTmp += GetNumDecimalSep(); - aTmp.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "############" ) ); - rSeq[0].Code = aTmp; - } - return 0; -} - - -sal_Int32 SvNumberFormatter::ImpAdjustFormatCodeDefault( - ::com::sun::star::i18n::NumberFormatCode * pFormatArr, - sal_Int32 nCnt, sal_Bool bCheckCorrectness ) -{ - using namespace ::com::sun::star; - - if ( !nCnt ) - return -1; - if (bCheckCorrectness && LocaleDataWrapper::areChecksEnabled()) - { - // check the locale data for correctness - rtl::OStringBuffer aMsg; - sal_Int32 nElem, nShort, nMedium, nLong, nShortDef, nMediumDef, nLongDef; - nShort = nMedium = nLong = nShortDef = nMediumDef = nLongDef = -1; - for ( nElem = 0; nElem < nCnt; nElem++ ) - { - switch ( pFormatArr[nElem].Type ) - { - case i18n::KNumberFormatType::SHORT : - nShort = nElem; - break; - case i18n::KNumberFormatType::MEDIUM : - nMedium = nElem; - break; - case i18n::KNumberFormatType::LONG : - nLong = nElem; - break; - default: - aMsg.append(RTL_CONSTASCII_STRINGPARAM("unknown type")); - } - if ( pFormatArr[nElem].Default ) - { - switch ( pFormatArr[nElem].Type ) - { - case i18n::KNumberFormatType::SHORT : - if ( nShortDef != -1 ) - aMsg.append(RTL_CONSTASCII_STRINGPARAM("dupe short type default")); - nShortDef = nElem; - break; - case i18n::KNumberFormatType::MEDIUM : - if ( nMediumDef != -1 ) - aMsg.append(RTL_CONSTASCII_STRINGPARAM("dupe medium type default")); - nMediumDef = nElem; - break; - case i18n::KNumberFormatType::LONG : - if ( nLongDef != -1 ) - aMsg.append(RTL_CONSTASCII_STRINGPARAM("dupe long type default")); - nLongDef = nElem; - break; - } - } - if (aMsg.getLength()) - { - aMsg.insert(0, RTL_CONSTASCII_STRINGPARAM("SvNumberFormatter::ImpAdjustFormatCodeDefault: ")); - aMsg.append(RTL_CONSTASCII_STRINGPARAM("\nXML locale data FormatElement formatindex: ")); - aMsg.append(static_cast<sal_Int32>(pFormatArr[nElem].Index)); - rtl::OUString aUMsg(rtl::OStringToOUString(aMsg.makeStringAndClear(), - RTL_TEXTENCODING_ASCII_US)); - LocaleDataWrapper::outputCheckMessage(xLocaleData->appendLocaleInfo(aUMsg)); - } - } - if ( nShort != -1 && nShortDef == -1 ) - aMsg.append(RTL_CONSTASCII_STRINGPARAM("no short type default ")); - if ( nMedium != -1 && nMediumDef == -1 ) - aMsg.append(RTL_CONSTASCII_STRINGPARAM("no medium type default ")); - if ( nLong != -1 && nLongDef == -1 ) - aMsg.append(RTL_CONSTASCII_STRINGPARAM("no long type default ")); - if (aMsg.getLength()) - { - aMsg.insert(0, RTL_CONSTASCII_STRINGPARAM("SvNumberFormatter::ImpAdjustFormatCodeDefault: ")); - aMsg.append(RTL_CONSTASCII_STRINGPARAM("\nXML locale data FormatElement group of: ")); - rtl::OUString aUMsg(rtl::OStringToOUString(aMsg.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US)); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo(aUMsg + pFormatArr[0].NameID)); - } - } - // find the default (medium preferred, then long) and reset all other defaults - sal_Int32 nElem, nDef, nMedium; - nDef = nMedium = -1; - for ( nElem = 0; nElem < nCnt; nElem++ ) - { - if ( pFormatArr[nElem].Default ) - { - switch ( pFormatArr[nElem].Type ) - { - case i18n::KNumberFormatType::MEDIUM : - nDef = nMedium = nElem; - break; - case i18n::KNumberFormatType::LONG : - if ( nMedium == -1 ) - nDef = nElem; - // fallthru - default: - if ( nDef == -1 ) - nDef = nElem; - pFormatArr[nElem].Default = sal_False; - } - } - } - if ( nDef == -1 ) - nDef = 0; - pFormatArr[nDef].Default = sal_True; - return nDef; -} - - -void SvNumberFormatter::ImpGenerateFormats( sal_uInt32 CLOffset, sal_Bool bLoadingSO5 ) -{ - using namespace ::com::sun::star; - - if ( !bIndexTableInitialized ) - { - for ( sal_uInt16 j=0; j<NF_INDEX_TABLE_ENTRIES; j++ ) - { - theIndexTable[j] = NUMBERFORMAT_ENTRY_NOT_FOUND; - } - } - sal_Bool bOldConvertMode = pFormatScanner->GetConvertMode(); - if (bOldConvertMode) - pFormatScanner->SetConvertMode(sal_False); // switch off for this function - - NumberFormatCodeWrapper aNumberFormatCode( xServiceManager, GetLocale() ); - - xub_StrLen nCheckPos = 0; - SvNumberformat* pNewFormat = NULL; - String aFormatCode; - sal_Int32 nIdx; - sal_Bool bDefault; - - // Counter for additional builtin formats not fitting into the first 10 - // of a category (TLOT:=The Legacy Of Templin), altogether about 20 formats. - // Has to be incremented on each ImpInsertNewStandardformat, new formats - // must be appended, not inserted! - sal_uInt16 nNewExtended = ZF_STANDARD_NEWEXTENDED; - - // Number - uno::Sequence< i18n::NumberFormatCode > aFormatSeq - = aNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::FIXED_NUMBER ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); - - // General - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_STANDARD ); - SvNumberformat* pStdFormat = ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_NUMBER_STANDARD, ZF_STANDARD )); - if (pStdFormat) - { - // This is _the_ standard format. - if (LocaleDataWrapper::areChecksEnabled() && - pStdFormat->GetType() != NUMBERFORMAT_NUMBER) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumberFormatter::ImpGenerateFormats: General format not NUMBER")); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - pStdFormat->SetType( NUMBERFORMAT_NUMBER ); - pStdFormat->SetStandard(); - pStdFormat->SetLastInsertKey( SV_MAX_ANZ_STANDARD_FORMATE ); - } - else - { - if (LocaleDataWrapper::areChecksEnabled()) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "SvNumberFormatter::ImpGenerateFormats: General format not insertable, nothing will work")); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - } - - // Boolean - aFormatCode = pFormatScanner->GetBooleanString(); - pNewFormat = new SvNumberformat( aFormatCode, - pFormatScanner, pStringScanner, nCheckPos, ActLnge ); - pNewFormat->SetType(NUMBERFORMAT_LOGICAL); - pNewFormat->SetStandard(); - if ( !aFTable.Insert( - CLOffset + SetIndexTable( NF_BOOLEAN, ZF_STANDARD_LOGICAL ), - pNewFormat)) - delete pNewFormat; - - // Text - aFormatCode = '@'; - pNewFormat = new SvNumberformat( aFormatCode, - pFormatScanner, pStringScanner, nCheckPos, ActLnge ); - pNewFormat->SetType(NUMBERFORMAT_TEXT); - pNewFormat->SetStandard(); - if ( !aFTable.Insert( - CLOffset + SetIndexTable( NF_TEXT, ZF_STANDARD_TEXT ), - pNewFormat)) - delete pNewFormat; - - - - // 0 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_INT ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_NUMBER_INT, ZF_STANDARD+1 )); - - // 0.00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_DEC2 ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_NUMBER_DEC2, ZF_STANDARD+2 )); - - // #,##0 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_1000INT ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_NUMBER_1000INT, ZF_STANDARD+3 )); - - // #,##0.00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_1000DEC2 ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_NUMBER_1000DEC2, ZF_STANDARD+4 )); - - // #.##0,00 System country/language dependent since number formatter version 6 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_NUMBER_SYSTEM ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_NUMBER_SYSTEM, ZF_STANDARD+5 ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - - // Percent number - aFormatSeq = aNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::PERCENT_NUMBER ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); - - // 0% - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_PERCENT_INT ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_PERCENT_INT, ZF_STANDARD_PERCENT )); - - // 0.00% - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_PERCENT_DEC2 ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_PERCENT_DEC2, ZF_STANDARD_PERCENT+1 )); - - - - // Currency. NO default standard option! Default is determined of locale - // data default currency and format is generated if needed. - aFormatSeq = aNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::CURRENCY ); - if (LocaleDataWrapper::areChecksEnabled()) - { - // though no default desired here, test for correctness of locale data - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); - } - - // #,##0 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000INT ); - bDefault = aFormatSeq[nIdx].Default; - aFormatSeq[nIdx].Default = sal_False; - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_CURRENCY_1000INT, ZF_STANDARD_CURRENCY )); - aFormatSeq[nIdx].Default = bDefault; - - // #,##0.00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2 ); - bDefault = aFormatSeq[nIdx].Default; - aFormatSeq[nIdx].Default = sal_False; - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_CURRENCY_1000DEC2, ZF_STANDARD_CURRENCY+1 )); - aFormatSeq[nIdx].Default = bDefault; - - // #,##0 negative red - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000INT_RED ); - bDefault = aFormatSeq[nIdx].Default; - aFormatSeq[nIdx].Default = sal_False; - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_CURRENCY_1000INT_RED, ZF_STANDARD_CURRENCY+2 )); - aFormatSeq[nIdx].Default = bDefault; - - // #,##0.00 negative red - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2_RED ); - bDefault = aFormatSeq[nIdx].Default; - aFormatSeq[nIdx].Default = sal_False; - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_CURRENCY_1000DEC2_RED, ZF_STANDARD_CURRENCY+3 )); - aFormatSeq[nIdx].Default = bDefault; - - // #,##0.00 USD since number formatter version 3 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2_CCC ); - bDefault = aFormatSeq[nIdx].Default; - aFormatSeq[nIdx].Default = sal_False; - pNewFormat = ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_CURRENCY_1000DEC2_CCC, ZF_STANDARD_CURRENCY+4 )); - if ( pNewFormat ) - pNewFormat->SetUsed(sal_True); // must be saved for older versions - aFormatSeq[nIdx].Default = bDefault; - - // #.##0,-- since number formatter version 6 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_CURRENCY_1000DEC2_DASHED ); - bDefault = aFormatSeq[nIdx].Default; - aFormatSeq[nIdx].Default = sal_False; - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_CURRENCY_1000DEC2_DASHED, ZF_STANDARD_CURRENCY+5 ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - aFormatSeq[nIdx].Default = bDefault; - - - - // Date - aFormatSeq = aNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::DATE ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); - - // DD.MM.YY System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYSTEM_SHORT ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYSTEM_SHORT, ZF_STANDARD_DATE )); - - // NN DD.MMM YY - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DEF_NNDDMMMYY ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_DEF_NNDDMMMYY, ZF_STANDARD_DATE+1 )); - - // DD.MM.YY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_MMYY ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_MMYY, ZF_STANDARD_DATE+2 )); - - // DD MMM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DDMMM ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_DDMMM, ZF_STANDARD_DATE+3 )); - - // MMMM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_MMMM ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_MMMM, ZF_STANDARD_DATE+4 )); - - // QQ YY - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_QQJJ ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_QQJJ, ZF_STANDARD_DATE+5 )); - - // DD.MM.YYYY since number formatter version 2, was DD.MM.[YY]YY - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DDMMYYYY ); - pNewFormat = ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_DDMMYYYY, ZF_STANDARD_DATE+6 )); - if ( pNewFormat ) - pNewFormat->SetUsed(sal_True); // must be saved for older versions - - // DD.MM.YY def/System, since number formatter version 6 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DDMMYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_DDMMYY, ZF_STANDARD_DATE+7 ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // NNN, D. MMMM YYYY System - // Long day of week: "NNNN" instead of "NNN," because of compatibility - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYSTEM_LONG ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYSTEM_LONG, ZF_STANDARD_DATE+8 ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // Hard coded but system (regional settings) delimiters dependent long date formats - // since numberformatter version 6 - - // D. MMM YY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DMMMYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_DMMMYY, ZF_STANDARD_DATE+9 ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - //! Unfortunally TLOT intended only 10 builtin formats per category, more - //! would overwrite the next category (ZF_STANDARD_TIME) :-(( - //! Therefore they are inserted with nNewExtended++ (which is also limited) - - // D. MMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DMMMYYYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_DMMMYYYY, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // D. MMMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_DMMMMYYYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_DMMMMYYYY, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // NN, D. MMM YY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_NNDMMMYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_NNDMMMYY, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // NN, D. MMMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_NNDMMMMYYYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_NNDMMMMYYYY, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // NNN, D. MMMM YYYY def/System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_SYS_NNNNDMMMMYYYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_SYS_NNNNDMMMMYYYY, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // Hard coded DIN (Deutsche Industrie Norm) and EN (European Norm) date formats - - // D. MMM. YYYY DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_DMMMYYYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_DIN_DMMMYYYY, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // D. MMMM YYYY DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_DMMMMYYYY ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_DIN_DMMMMYYYY, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // MM-DD DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_MMDD ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_DIN_MMDD, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // YY-MM-DD DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_YYMMDD ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_DIN_YYMMDD, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - // YYYY-MM-DD DIN/EN - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATE_DIN_YYYYMMDD ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATE_DIN_YYYYMMDD, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NEWSTANDARD ); - - - - // Time - aFormatSeq = aNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::TIME ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); - - // HH:MM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMM ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_TIME_HHMM, ZF_STANDARD_TIME )); - - // HH:MM:SS - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMMSS ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_TIME_HHMMSS, ZF_STANDARD_TIME+1 )); - - // HH:MM AM/PM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMMAMPM ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_TIME_HHMMAMPM, ZF_STANDARD_TIME+2 )); - - // HH:MM:SS AM/PM - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HHMMSSAMPM ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_TIME_HHMMSSAMPM, ZF_STANDARD_TIME+3 )); - - // [HH]:MM:SS - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HH_MMSS ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_TIME_HH_MMSS, ZF_STANDARD_TIME+4 )); - - // MM:SS,00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_MMSS00 ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_TIME_MMSS00, ZF_STANDARD_TIME+5 )); - - // [HH]:MM:SS,00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_TIME_HH_MMSS00 ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_TIME_HH_MMSS00, ZF_STANDARD_TIME+6 ), - SV_NUMBERFORMATTER_VERSION_NF_TIME_HH_MMSS00 ); - - - - // DateTime - aFormatSeq = aNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::DATE_TIME ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); - - // DD.MM.YY HH:MM System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATETIME_SYSTEM_SHORT_HHMM ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATETIME_SYSTEM_SHORT_HHMM, ZF_STANDARD_DATETIME )); - - // DD.MM.YYYY HH:MM:SS System - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_DATETIME_SYS_DDMMYYYY_HHMMSS ); - ImpInsertNewStandardFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_DATETIME_SYS_DDMMYYYY_HHMMSS, ZF_STANDARD_DATETIME+1 ), - SV_NUMBERFORMATTER_VERSION_NF_DATETIME_SYS_DDMMYYYY_HHMMSS ); - - - - // Scientific number - aFormatSeq = aNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::SCIENTIFIC_NUMBER ); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), aFormatSeq.getLength() ); - - // 0.00E+000 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_SCIENTIFIC_000E000 ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_SCIENTIFIC_000E000, ZF_STANDARD_SCIENTIFIC )); - - // 0.00E+00 - nIdx = ImpGetFormatCodeIndex( aFormatSeq, NF_SCIENTIFIC_000E00 ); - ImpInsertFormat( aFormatSeq[nIdx], - CLOffset + SetIndexTable( NF_SCIENTIFIC_000E00, ZF_STANDARD_SCIENTIFIC+1 )); - - - - // Fraction number (no default option) - i18n::NumberFormatCode aSingleFormatCode; - - // # ?/? - aSingleFormatCode.Code = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "# ?/?" ) ); - ImpInsertFormat( aSingleFormatCode, - CLOffset + SetIndexTable( NF_FRACTION_1, ZF_STANDARD_FRACTION )); - - // # ??/?? - //! "??/" would be interpreted by the compiler as a trigraph for '\' - aSingleFormatCode.Code = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "# ?\?/?\?" ) ); - ImpInsertFormat( aSingleFormatCode, - CLOffset + SetIndexTable( NF_FRACTION_2, ZF_STANDARD_FRACTION+1 )); - - // Week of year must be appended here because of nNewExtended - const NfKeywordTable & rKeyword = pFormatScanner->GetKeywords(); - aSingleFormatCode.Code = rKeyword[NF_KEY_WW]; - ImpInsertNewStandardFormat( aSingleFormatCode, - CLOffset + SetIndexTable( NF_DATE_WW, nNewExtended++ ), - SV_NUMBERFORMATTER_VERSION_NF_DATE_WW ); - - - - bIndexTableInitialized = sal_True; - DBG_ASSERT( nNewExtended <= ZF_STANDARD_NEWEXTENDEDMAX, - "ImpGenerateFormats: overflow of nNewExtended standard formats" ); - - // Now all additional format codes provided by I18N, but only if not - // loading from old SO5 file format, then they are appended last. - if ( !bLoadingSO5 ) - ImpGenerateAdditionalFormats( CLOffset, aNumberFormatCode, sal_False ); - - sal_uInt32 nPos = CLOffset + pStdFormat->GetLastInsertKey(); - - aSingleFormatCode.Code = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "# ?/4" ) ); - ImpInsertNewStandardFormat( aSingleFormatCode, nPos+1, SV_NUMBERFORMATTER_VERSION_ADDITIONAL_I18N_FORMATS ); - nPos++; - - aSingleFormatCode.Code = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "# ?\?/100" ) ); - ImpInsertNewStandardFormat( aSingleFormatCode, nPos+1, SV_NUMBERFORMATTER_VERSION_ADDITIONAL_I18N_FORMATS ); - nPos++; - - pStdFormat->SetLastInsertKey( (sal_uInt16)(nPos - CLOffset) ); - - if (bOldConvertMode) - pFormatScanner->SetConvertMode(sal_True); -} - - -void SvNumberFormatter::ImpGenerateAdditionalFormats( sal_uInt32 CLOffset, - NumberFormatCodeWrapper& rNumberFormatCode, sal_Bool bAfterLoadingSO5 ) -{ - using namespace ::com::sun::star; - - SvNumberformat* pStdFormat = - (SvNumberformat*) aFTable.Get( CLOffset + ZF_STANDARD ); - if ( !pStdFormat ) - { - DBG_ERRORFILE( "ImpGenerateAdditionalFormats: no GENERAL format" ); - return ; - } - sal_uInt32 nPos = CLOffset + pStdFormat->GetLastInsertKey(); - rNumberFormatCode.setLocale( GetLocale() ); - sal_Int32 j; - - // All currencies, this time with [$...] which was stripped in - // ImpGenerateFormats for old "automatic" currency formats. - uno::Sequence< i18n::NumberFormatCode > aFormatSeq = - rNumberFormatCode.getAllFormatCode( i18n::KNumberFormatUsage::CURRENCY ); - i18n::NumberFormatCode * pFormatArr = aFormatSeq.getArray(); - sal_Int32 nCodes = aFormatSeq.getLength(); - ImpAdjustFormatCodeDefault( aFormatSeq.getArray(), nCodes ); - for ( j = 0; j < nCodes; j++ ) - { - if ( nPos - CLOffset >= SV_COUNTRY_LANGUAGE_OFFSET ) - { - DBG_ERRORFILE( "ImpGenerateAdditionalFormats: too many formats" ); - break; // for - } - if ( pFormatArr[j].Index < NF_INDEX_TABLE_ENTRIES && - pFormatArr[j].Index != NF_CURRENCY_1000DEC2_CCC ) - { // Insert only if not already inserted, but internal index must be - // above so ImpInsertFormat can distinguish it. - sal_Int16 nOrgIndex = pFormatArr[j].Index; - pFormatArr[j].Index = sal::static_int_cast< sal_Int16 >( - pFormatArr[j].Index + nCodes + NF_INDEX_TABLE_ENTRIES); - //! no default on currency - sal_Bool bDefault = aFormatSeq[j].Default; - aFormatSeq[j].Default = sal_False; - if ( ImpInsertNewStandardFormat( pFormatArr[j], nPos+1, - SV_NUMBERFORMATTER_VERSION_ADDITIONAL_I18N_FORMATS, - bAfterLoadingSO5, nOrgIndex ) ) - nPos++; - pFormatArr[j].Index = nOrgIndex; - aFormatSeq[j].Default = bDefault; - } - } - - // all additional format codes provided by I18N that are not old standard index - aFormatSeq = rNumberFormatCode.getAllFormatCodes(); - nCodes = aFormatSeq.getLength(); - if ( nCodes ) - { - pFormatArr = aFormatSeq.getArray(); - // don't check ALL - sal_Int32 nDef = ImpAdjustFormatCodeDefault( pFormatArr, nCodes, sal_False); - // don't have any defaults here - pFormatArr[nDef].Default = sal_False; - for ( j = 0; j < nCodes; j++ ) - { - if ( nPos - CLOffset >= SV_COUNTRY_LANGUAGE_OFFSET ) - { - DBG_ERRORFILE( "ImpGenerateAdditionalFormats: too many formats" ); - break; // for - } - if ( pFormatArr[j].Index >= NF_INDEX_TABLE_ENTRIES ) - if ( ImpInsertNewStandardFormat( pFormatArr[j], nPos+1, - SV_NUMBERFORMATTER_VERSION_ADDITIONAL_I18N_FORMATS, - bAfterLoadingSO5 ) ) - nPos++; - } - } - - pStdFormat->SetLastInsertKey( (sal_uInt16)(nPos - CLOffset) ); -} - - -void SvNumberFormatter::ImpGetPosCurrFormat( String& sPosStr, const String& rCurrSymbol ) -{ - NfCurrencyEntry::CompletePositiveFormatString( sPosStr, - rCurrSymbol, xLocaleData->getCurrPositiveFormat() ); -} - -void SvNumberFormatter::ImpGetNegCurrFormat( String& sNegStr, const String& rCurrSymbol ) -{ - NfCurrencyEntry::CompleteNegativeFormatString( sNegStr, - rCurrSymbol, xLocaleData->getCurrNegativeFormat() ); -} - -void SvNumberFormatter::GenerateFormat(String& sString, - sal_uInt32 nIndex, - LanguageType eLnge, - sal_Bool bThousand, - sal_Bool IsRed, - sal_uInt16 nPrecision, - sal_uInt16 nAnzLeading) -{ - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - short eType = GetType(nIndex); - sal_uInt16 i; - ImpGenerateCL(eLnge); // ggfs. neu Standard- - // formate anlegen - sString.Erase(); - - utl::DigitGroupingIterator aGrouping( xLocaleData->getDigitGrouping()); - const xub_StrLen nDigitsInFirstGroup = static_cast<xub_StrLen>(aGrouping.get()); - const String& rThSep = GetNumThousandSep(); - - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(nIndex); - - if (nAnzLeading == 0) - { - if (!bThousand) - sString += '#'; - else - { - sString += '#'; - sString += rThSep; - sString.Expand( sString.Len() + nDigitsInFirstGroup, '#' ); - } - } - else - { - for (i = 0; i < nAnzLeading; i++) - { - if (bThousand && i > 0 && i == aGrouping.getPos()) - { - sString.Insert( rThSep, 0 ); - aGrouping.advance(); - } - sString.Insert('0',0); - } - if (bThousand && nAnzLeading < nDigitsInFirstGroup + 1) - { - for (i = nAnzLeading; i < nDigitsInFirstGroup + 1; i++) - { - if (bThousand && i % nDigitsInFirstGroup == 0) - sString.Insert( rThSep, 0 ); - sString.Insert('#',0); - } - } - } - if (nPrecision > 0) - { - sString += GetNumDecimalSep(); - sString.Expand( sString.Len() + nPrecision, '0' ); - } - if (eType == NUMBERFORMAT_PERCENT) - sString += '%'; - else if (eType == NUMBERFORMAT_CURRENCY) - { - String sNegStr = sString; - String aCurr; - const NfCurrencyEntry* pEntry; - sal_Bool bBank; - if ( GetNewCurrencySymbolString( nIndex, aCurr, &pEntry, &bBank ) ) - { - if ( pEntry ) - { - sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( - xLocaleData->getCurrPositiveFormat(), - pEntry->GetPositiveFormat(), bBank ); - sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( - xLocaleData->getCurrNegativeFormat(), - pEntry->GetNegativeFormat(), bBank ); - pEntry->CompletePositiveFormatString( sString, bBank, - nPosiForm ); - pEntry->CompleteNegativeFormatString( sNegStr, bBank, - nNegaForm ); - } - else - { // assume currency abbreviation (AKA banking symbol), not symbol - sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( - xLocaleData->getCurrPositiveFormat(), - xLocaleData->getCurrPositiveFormat(), sal_True ); - sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( - xLocaleData->getCurrNegativeFormat(), - xLocaleData->getCurrNegativeFormat(), sal_True ); - NfCurrencyEntry::CompletePositiveFormatString( sString, aCurr, - nPosiForm ); - NfCurrencyEntry::CompleteNegativeFormatString( sNegStr, aCurr, - nNegaForm ); - } - } - else - { // "automatic" old style - String aSymbol, aAbbrev; - GetCompatibilityCurrency( aSymbol, aAbbrev ); - ImpGetPosCurrFormat( sString, aSymbol ); - ImpGetNegCurrFormat( sNegStr, aSymbol ); - } - if (IsRed) - { - sString += ';'; - sString += '['; - sString += pFormatScanner->GetRedString(); - sString += ']'; - } - else - sString += ';'; - sString += sNegStr; - } - if (eType != NUMBERFORMAT_CURRENCY) - { - bool insertBrackets = false; - if ( eType != NUMBERFORMAT_UNDEFINED) - insertBrackets = pFormat->IsNegativeInBracket(); - if (IsRed || insertBrackets) - { - String sTmpStr = sString; - - if ( pFormat->HasPositiveBracketPlaceholder() ) - { - sTmpStr += '_'; - sTmpStr += ')'; - } - sTmpStr += ';'; - - if (IsRed) - { - sTmpStr += '['; - sTmpStr += pFormatScanner->GetRedString(); - sTmpStr += ']'; - } - - if (insertBrackets) - { - sTmpStr += '('; - sTmpStr += sString; - sTmpStr += ')'; - } - else - { - sTmpStr += '-'; - sTmpStr +=sString; - } - sString = sTmpStr; - } - } -} - -sal_Bool SvNumberFormatter::IsUserDefined(const String& sStr, - LanguageType eLnge) -{ - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // ggfs. neu Standard- - // formate anlegen - eLnge = ActLnge; - sal_uInt32 nKey = ImpIsEntry(sStr, CLOffset, eLnge); - if (nKey == NUMBERFORMAT_ENTRY_NOT_FOUND) - return sal_True; - SvNumberformat* pEntry = aFTable.Get(nKey); - if ( pEntry && ((pEntry->GetType() & NUMBERFORMAT_DEFINED) != 0) ) - return sal_True; - return sal_False; -} - -sal_uInt32 SvNumberFormatter::GetEntryKey(const String& sStr, - LanguageType eLnge) -{ - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - sal_uInt32 CLOffset = ImpGenerateCL(eLnge); // ggfs. neu Standard- - // formate anlegen - return ImpIsEntry(sStr, CLOffset, eLnge); -} - -sal_uInt32 SvNumberFormatter::GetStandardIndex(LanguageType eLnge) -{ - if (eLnge == LANGUAGE_DONTKNOW) - eLnge = IniLnge; - return GetStandardFormat(NUMBERFORMAT_NUMBER, eLnge); -} - -short SvNumberFormatter::GetType(sal_uInt32 nFIndex) -{ - short eType; - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get(nFIndex); - if (!pFormat) - eType = NUMBERFORMAT_UNDEFINED; - else - { - eType = pFormat->GetType() &~NUMBERFORMAT_DEFINED; - if (eType == 0) - eType = NUMBERFORMAT_DEFINED; - } - return eType; -} - -void SvNumberFormatter::ClearMergeTable() -{ - if ( pMergeTable ) - { - sal_uInt32* pIndex = (sal_uInt32*) pMergeTable->First(); - while (pIndex) - { - delete pIndex; - pIndex = pMergeTable->Next(); - } - pMergeTable->Clear(); - } -} - -SvNumberFormatterIndexTable* SvNumberFormatter::MergeFormatter(SvNumberFormatter& rTable) -{ - if ( pMergeTable ) - ClearMergeTable(); - else - pMergeTable = new SvNumberFormatterIndexTable; - sal_uInt32 nCLOffset = 0; - sal_uInt32 nOldKey, nOffset, nNewKey; - sal_uInt32* pNewIndex; - SvNumberformat* pNewEntry; - SvNumberformat* pFormat = rTable.aFTable.First(); - while (pFormat) - { - nOldKey = rTable.aFTable.GetCurKey(); - nOffset = nOldKey % SV_COUNTRY_LANGUAGE_OFFSET; // relativIndex - if (nOffset == 0) // 1. Format von CL - nCLOffset = ImpGenerateCL(pFormat->GetLanguage()); - - if (nOffset <= SV_MAX_ANZ_STANDARD_FORMATE) // Std.form. - { - nNewKey = nCLOffset + nOffset; - if (!aFTable.Get(nNewKey)) // noch nicht da - { -// pNewEntry = new SvNumberformat(*pFormat); // Copy reicht nicht !!! - pNewEntry = new SvNumberformat( *pFormat, *pFormatScanner ); - if (!aFTable.Insert(nNewKey, pNewEntry)) - delete pNewEntry; - } - if (nNewKey != nOldKey) // neuer Index - { - pNewIndex = new sal_uInt32(nNewKey); - if (!pMergeTable->Insert(nOldKey,pNewIndex)) - delete pNewIndex; - } - } - else // benutzerdef. - { -// pNewEntry = new SvNumberformat(*pFormat); // Copy reicht nicht !!! - pNewEntry = new SvNumberformat( *pFormat, *pFormatScanner ); - nNewKey = ImpIsEntry(pNewEntry->GetFormatstring(), - nCLOffset, - pFormat->GetLanguage()); - if (nNewKey != NUMBERFORMAT_ENTRY_NOT_FOUND) // schon vorhanden - delete pNewEntry; - else - { - SvNumberformat* pStdFormat = - (SvNumberformat*) aFTable.Get(nCLOffset + ZF_STANDARD); - sal_uInt32 nPos = nCLOffset + pStdFormat->GetLastInsertKey(); - nNewKey = nPos+1; - if (nPos - nCLOffset >= SV_COUNTRY_LANGUAGE_OFFSET) - { - OSL_FAIL( - "SvNumberFormatter:: Zu viele Formate pro CL"); - delete pNewEntry; - } - else if (!aFTable.Insert(nNewKey, pNewEntry)) - delete pNewEntry; - else - pStdFormat->SetLastInsertKey((sal_uInt16) (nNewKey - nCLOffset)); - } - if (nNewKey != nOldKey) // neuer Index - { - pNewIndex = new sal_uInt32(nNewKey); - if (!pMergeTable->Insert(nOldKey,pNewIndex)) - delete pNewIndex; - } - } - pFormat = rTable.aFTable.Next(); - } - return pMergeTable; -} - - -SvNumberFormatterMergeMap SvNumberFormatter::ConvertMergeTableToMap() -{ - if (!HasMergeFmtTbl()) - return SvNumberFormatterMergeMap(); - - SvNumberFormatterMergeMap aMap; - for (sal_uInt32* pIndex = pMergeTable->First(); pIndex; pIndex = pMergeTable->Next()) - { - sal_uInt32 nOldKey = pMergeTable->GetCurKey(); - aMap.insert( SvNumberFormatterMergeMap::value_type( nOldKey, *pIndex)); - } - ClearMergeTable(); - return aMap; -} - - -sal_uInt32 SvNumberFormatter::GetFormatForLanguageIfBuiltIn( sal_uInt32 nFormat, - LanguageType eLnge ) -{ - if ( eLnge == LANGUAGE_DONTKNOW ) - eLnge = IniLnge; - if ( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && eLnge == IniLnge ) - return nFormat; // es bleibt wie es ist - sal_uInt32 nOffset = nFormat % SV_COUNTRY_LANGUAGE_OFFSET; // relativIndex - if ( nOffset > SV_MAX_ANZ_STANDARD_FORMATE ) - return nFormat; // kein eingebautes Format - sal_uInt32 nCLOffset = ImpGenerateCL(eLnge); // ggbf. generieren - return nCLOffset + nOffset; -} - - -sal_uInt32 SvNumberFormatter::GetFormatIndex( NfIndexTableOffset nTabOff, - LanguageType eLnge ) -{ - if ( nTabOff >= NF_INDEX_TABLE_ENTRIES - || theIndexTable[nTabOff] == NUMBERFORMAT_ENTRY_NOT_FOUND ) - return NUMBERFORMAT_ENTRY_NOT_FOUND; - if ( eLnge == LANGUAGE_DONTKNOW ) - eLnge = IniLnge; - sal_uInt32 nCLOffset = ImpGenerateCL(eLnge); // ggbf. generieren - return nCLOffset + theIndexTable[nTabOff]; -} - - -NfIndexTableOffset SvNumberFormatter::GetIndexTableOffset( sal_uInt32 nFormat ) const -{ - sal_uInt32 nOffset = nFormat % SV_COUNTRY_LANGUAGE_OFFSET; // relativIndex - if ( nOffset > SV_MAX_ANZ_STANDARD_FORMATE ) - return NF_INDEX_TABLE_ENTRIES; // kein eingebautes Format - for ( sal_uInt16 j = 0; j < NF_INDEX_TABLE_ENTRIES; j++ ) - { - if ( theIndexTable[j] == nOffset ) - return (NfIndexTableOffset) j; - } - return NF_INDEX_TABLE_ENTRIES; // bad luck -} - - -void SvNumberFormatter::SetYear2000( sal_uInt16 nVal ) -{ - pStringScanner->SetYear2000( nVal ); -} - - -sal_uInt16 SvNumberFormatter::GetYear2000() const -{ - return pStringScanner->GetYear2000(); -} - - -sal_uInt16 SvNumberFormatter::ExpandTwoDigitYear( sal_uInt16 nYear ) const -{ - if ( nYear < 100 ) - return SvNumberFormatter::ExpandTwoDigitYear( nYear, - pStringScanner->GetYear2000() ); - return nYear; -} - - -// static -sal_uInt16 SvNumberFormatter::GetYear2000Default() -{ - return (sal_uInt16) ::utl::MiscCfg().GetYear2000(); -} - - -// static -const NfCurrencyTable& SvNumberFormatter::GetTheCurrencyTable() -{ - ::osl::MutexGuard aGuard( GetMutex() ); - while ( !bCurrencyTableInitialized ) - ImpInitCurrencyTable(); - return theCurrencyTable::get(); -} - - -// static -const NfCurrencyEntry* SvNumberFormatter::MatchSystemCurrency() -{ - // MUST call GetTheCurrencyTable() before accessing nSystemCurrencyPosition - const NfCurrencyTable& rTable = GetTheCurrencyTable(); - return nSystemCurrencyPosition ? rTable[nSystemCurrencyPosition] : NULL; -} - - -// static -const NfCurrencyEntry& SvNumberFormatter::GetCurrencyEntry( LanguageType eLang ) -{ - if ( eLang == LANGUAGE_SYSTEM ) - { - const NfCurrencyEntry* pCurr = MatchSystemCurrency(); - return pCurr ? *pCurr : *(GetTheCurrencyTable()[0]); - } - else - { - eLang = MsLangId::getRealLanguage( eLang ); - const NfCurrencyTable& rTable = GetTheCurrencyTable(); - sal_uInt16 nCount = rTable.Count(); - const NfCurrencyEntryPtr* ppData = rTable.GetData(); - for ( sal_uInt16 j = 0; j < nCount; j++, ppData++ ) - { - if ( (*ppData)->GetLanguage() == eLang ) - return **ppData; - } - return *(rTable[0]); - } -} - - -// static -const NfCurrencyEntry* SvNumberFormatter::GetCurrencyEntry( - const String& rAbbrev, LanguageType eLang ) -{ - eLang = MsLangId::getRealLanguage( eLang ); - const NfCurrencyTable& rTable = GetTheCurrencyTable(); - sal_uInt16 nCount = rTable.Count(); - const NfCurrencyEntryPtr* ppData = rTable.GetData(); - for ( sal_uInt16 j = 0; j < nCount; j++, ppData++ ) - { - if ( (*ppData)->GetLanguage() == eLang && - (*ppData)->GetBankSymbol() == rAbbrev ) - return *ppData; - } - return NULL; -} - - -// static -const NfCurrencyEntry* SvNumberFormatter::GetLegacyOnlyCurrencyEntry( - const String& rSymbol, const String& rAbbrev ) -{ - if (!bCurrencyTableInitialized) - GetTheCurrencyTable(); // just for initialization - const NfCurrencyTable& rTable = theLegacyOnlyCurrencyTable::get(); - sal_uInt16 nCount = rTable.Count(); - const NfCurrencyEntryPtr* ppData = rTable.GetData(); - for ( sal_uInt16 j = 0; j < nCount; j++, ppData++ ) - { - if ( (*ppData)->GetSymbol() == rSymbol && - (*ppData)->GetBankSymbol() == rAbbrev ) - return *ppData; - } - return NULL; -} - - -// static -IMPL_STATIC_LINK_NOINSTANCE( SvNumberFormatter, CurrencyChangeLink, void*, EMPTYARG ) -{ - ::osl::MutexGuard aGuard( GetMutex() ); - String aAbbrev; - LanguageType eLang = LANGUAGE_SYSTEM; - SvtSysLocaleOptions().GetCurrencyAbbrevAndLanguage( aAbbrev, eLang ); - SetDefaultSystemCurrency( aAbbrev, eLang ); - return 0; -} - - -// static -void SvNumberFormatter::SetDefaultSystemCurrency( const String& rAbbrev, LanguageType eLang ) -{ - ::osl::MutexGuard aGuard( GetMutex() ); - if ( eLang == LANGUAGE_SYSTEM ) - eLang = SvtSysLocale().GetLanguage(); - const NfCurrencyTable& rTable = GetTheCurrencyTable(); - sal_uInt16 nCount = rTable.Count(); - const NfCurrencyEntryPtr* ppData = rTable.GetData(); - if ( rAbbrev.Len() ) - { - for ( sal_uInt16 j = 0; j < nCount; j++, ppData++ ) - { - if ( (*ppData)->GetLanguage() == eLang && (*ppData)->GetBankSymbol() == rAbbrev ) - { - nSystemCurrencyPosition = j; - return ; - } - } - } - else - { - for ( sal_uInt16 j = 0; j < nCount; j++, ppData++ ) - { - if ( (*ppData)->GetLanguage() == eLang ) - { - nSystemCurrencyPosition = j; - return ; - } - } - } - nSystemCurrencyPosition = 0; // not found => simple SYSTEM -} - - -void SvNumberFormatter::ResetDefaultSystemCurrency() -{ - nDefaultSystemCurrencyFormat = NUMBERFORMAT_ENTRY_NOT_FOUND; -} - - -sal_uInt32 SvNumberFormatter::ImpGetDefaultSystemCurrencyFormat() -{ - if ( nDefaultSystemCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) - { - xub_StrLen nCheck; - short nType; - NfWSStringsDtor aCurrList; - sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList, - GetCurrencyEntry( LANGUAGE_SYSTEM ), sal_False ); - DBG_ASSERT( aCurrList.Count(), "where is the NewCurrency System standard format?!?" ); - // if already loaded or user defined nDefaultSystemCurrencyFormat - // will be set to the right value - PutEntry( *aCurrList.GetObject( nDefault ), nCheck, nType, - nDefaultSystemCurrencyFormat, LANGUAGE_SYSTEM ); - DBG_ASSERT( nCheck == 0, "NewCurrency CheckError" ); - DBG_ASSERT( nDefaultSystemCurrencyFormat != NUMBERFORMAT_ENTRY_NOT_FOUND, - "nDefaultSystemCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND" ); - } - return nDefaultSystemCurrencyFormat; -} - - -sal_uInt32 SvNumberFormatter::ImpGetDefaultCurrencyFormat() -{ - sal_uInt32 CLOffset = ImpGetCLOffset( ActLnge ); - sal_uInt32 nDefaultCurrencyFormat = - (sal_uInt32)(sal_uLong) aDefaultFormatKeys.Get( CLOffset + ZF_STANDARD_CURRENCY ); - if ( !nDefaultCurrencyFormat ) - nDefaultCurrencyFormat = NUMBERFORMAT_ENTRY_NOT_FOUND; - if ( nDefaultCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) - { - // look for a defined standard - sal_uInt32 nStopKey = CLOffset + SV_COUNTRY_LANGUAGE_OFFSET; - sal_uInt32 nKey; - aFTable.Seek( CLOffset ); - while ( (nKey = aFTable.GetCurKey()) >= CLOffset && nKey < nStopKey ) - { - const SvNumberformat* pEntry = - (const SvNumberformat*) aFTable.GetCurObject(); - if ( pEntry->IsStandard() && (pEntry->GetType() & NUMBERFORMAT_CURRENCY) ) - { - nDefaultCurrencyFormat = nKey; - break; // while - } - aFTable.Next(); - } - - if ( nDefaultCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) - { // none found, create one - xub_StrLen nCheck; - short nType; - NfWSStringsDtor aCurrList; - sal_uInt16 nDefault = GetCurrencyFormatStrings( aCurrList, - GetCurrencyEntry( ActLnge ), sal_False ); - DBG_ASSERT( aCurrList.Count(), "where is the NewCurrency standard format?" ); - if ( aCurrList.Count() ) - { - // if already loaded or user defined nDefaultSystemCurrencyFormat - // will be set to the right value - PutEntry( *aCurrList.GetObject( nDefault ), nCheck, nType, - nDefaultCurrencyFormat, ActLnge ); - DBG_ASSERT( nCheck == 0, "NewCurrency CheckError" ); - DBG_ASSERT( nDefaultCurrencyFormat != NUMBERFORMAT_ENTRY_NOT_FOUND, - "nDefaultCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND" ); - } - // old automatic currency format as a last resort - if ( nDefaultCurrencyFormat == NUMBERFORMAT_ENTRY_NOT_FOUND ) - nDefaultCurrencyFormat = CLOffset + ZF_STANDARD_CURRENCY+3; - else - { // mark as standard so that it is found next time - SvNumberformat* pEntry = aFTable.Get( nDefaultCurrencyFormat ); - if ( pEntry ) - pEntry->SetStandard(); - } - } - sal_uIntPtr nFormat = nDefaultCurrencyFormat; - aDefaultFormatKeys.Insert( CLOffset + ZF_STANDARD_CURRENCY, - (void*) nFormat ); - } - return nDefaultCurrencyFormat; -} - - -// static -// try to make it inline if possible since this a loop body -// sal_True: continue; sal_False: break loop, if pFoundEntry==NULL dupe found -#ifndef DBG_UTIL -inline -#endif - sal_Bool SvNumberFormatter::ImpLookupCurrencyEntryLoopBody( - const NfCurrencyEntry*& pFoundEntry, sal_Bool& bFoundBank, - const NfCurrencyEntry* pData, sal_uInt16 nPos, const String& rSymbol ) -{ - sal_Bool bFound; - if ( pData->GetSymbol() == rSymbol ) - { - bFound = sal_True; - bFoundBank = sal_False; - } - else if ( pData->GetBankSymbol() == rSymbol ) - { - bFound = sal_True; - bFoundBank = sal_True; - } - else - bFound = sal_False; - if ( bFound ) - { - if ( pFoundEntry && pFoundEntry != pData ) - { - pFoundEntry = NULL; - return sal_False; // break loop, not unique - } - if ( nPos == 0 ) - { // first entry is SYSTEM - pFoundEntry = MatchSystemCurrency(); - if ( pFoundEntry ) - return sal_False; // break loop - // even if there are more matching entries - // this one is propably the one we are looking for - else - pFoundEntry = pData; - } - else - pFoundEntry = pData; - } - return sal_True; -} - - -sal_Bool SvNumberFormatter::GetNewCurrencySymbolString( sal_uInt32 nFormat, - String& rStr, const NfCurrencyEntry** ppEntry /* = NULL */, - sal_Bool* pBank /* = NULL */ ) const -{ - rStr.Erase(); - if ( ppEntry ) - *ppEntry = NULL; - if ( pBank ) - *pBank = sal_False; - SvNumberformat* pFormat = (SvNumberformat*) aFTable.Get( nFormat ); - if ( pFormat ) - { - String aSymbol, aExtension; - if ( pFormat->GetNewCurrencySymbol( aSymbol, aExtension ) ) - { - if ( ppEntry ) - { - sal_Bool bFoundBank = sal_False; - // we definiteley need an entry matching the format code string - const NfCurrencyEntry* pFoundEntry = GetCurrencyEntry( - bFoundBank, aSymbol, aExtension, pFormat->GetLanguage(), - sal_True ); - if ( pFoundEntry ) - { - *ppEntry = pFoundEntry; - if ( pBank ) - *pBank = bFoundBank; - pFoundEntry->BuildSymbolString( rStr, bFoundBank ); - } - } - if ( !rStr.Len() ) - { // analog zu BuildSymbolString - rStr = '['; - rStr += '$'; - if ( aSymbol.Search( '-' ) != STRING_NOTFOUND || - aSymbol.Search( ']' ) != STRING_NOTFOUND ) - { - rStr += '"'; - rStr += aSymbol; - rStr += '"'; - } - else - rStr += aSymbol; - if ( aExtension.Len() ) - rStr += aExtension; - rStr += ']'; - } - return sal_True; - } - } - return sal_False; -} - - -// static -const NfCurrencyEntry* SvNumberFormatter::GetCurrencyEntry( sal_Bool & bFoundBank, - const String& rSymbol, const String& rExtension, - LanguageType eFormatLanguage, sal_Bool bOnlyStringLanguage ) -{ - xub_StrLen nExtLen = rExtension.Len(); - LanguageType eExtLang; - if ( nExtLen ) - { - sal_Int32 nExtLang = ::rtl::OUString( rExtension ).toInt32( 16 ); - if ( !nExtLang ) - eExtLang = LANGUAGE_DONTKNOW; - else - eExtLang = (LanguageType) ((nExtLang < 0) ? - -nExtLang : nExtLang); - } - else - eExtLang = LANGUAGE_DONTKNOW; - const NfCurrencyEntry* pFoundEntry = NULL; - const NfCurrencyTable& rTable = GetTheCurrencyTable(); - sal_uInt16 nCount = rTable.Count(); - sal_Bool bCont = sal_True; - - // first try with given extension language/country - if ( nExtLen ) - { - const NfCurrencyEntryPtr* ppData = rTable.GetData(); - for ( sal_uInt16 j = 0; j < nCount && bCont; j++, ppData++ ) - { - LanguageType eLang = (*ppData)->GetLanguage(); - if ( eLang == eExtLang || - ((eExtLang == LANGUAGE_DONTKNOW) && - (eLang == LANGUAGE_SYSTEM)) - ) - { - bCont = ImpLookupCurrencyEntryLoopBody( pFoundEntry, bFoundBank, - *ppData, j, rSymbol ); - } - } - } - - // ok? - if ( pFoundEntry || !bCont || (bOnlyStringLanguage && nExtLen) ) - return pFoundEntry; - - if ( !bOnlyStringLanguage ) - { - // now try the language/country of the number format - const NfCurrencyEntryPtr* ppData = rTable.GetData(); - for ( sal_uInt16 j = 0; j < nCount && bCont; j++, ppData++ ) - { - LanguageType eLang = (*ppData)->GetLanguage(); - if ( eLang == eFormatLanguage || - ((eFormatLanguage == LANGUAGE_DONTKNOW) && - (eLang == LANGUAGE_SYSTEM)) - ) - { - bCont = ImpLookupCurrencyEntryLoopBody( pFoundEntry, bFoundBank, - *ppData, j, rSymbol ); - } - } - - // ok? - if ( pFoundEntry || !bCont ) - return pFoundEntry; - } - - // then try without language/country if no extension specified - if ( !nExtLen ) - { - const NfCurrencyEntryPtr* ppData = rTable.GetData(); - for ( sal_uInt16 j = 0; j < nCount && bCont; j++, ppData++ ) - { - bCont = ImpLookupCurrencyEntryLoopBody( pFoundEntry, bFoundBank, - *ppData, j, rSymbol ); - } - } - - return pFoundEntry; -} - - -void SvNumberFormatter::GetCompatibilityCurrency( String& rSymbol, String& rAbbrev ) const -{ - ::com::sun::star::uno::Sequence< ::com::sun::star::i18n::Currency2 > - xCurrencies( xLocaleData->getAllCurrencies() ); - - const ::com::sun::star::i18n::Currency2 *pCurrencies = xCurrencies.getConstArray(); - sal_Int32 nCurrencies = xCurrencies.getLength(); - - sal_Int32 j; - for ( j=0; j < nCurrencies; ++j ) - { - if ( pCurrencies[j].UsedInCompatibleFormatCodes ) - { - rSymbol = pCurrencies[j].Symbol; - rAbbrev = pCurrencies[j].BankSymbol; - break; - } - } - if ( j >= nCurrencies ) - { - if (LocaleDataWrapper::areChecksEnabled()) - { - String aMsg( RTL_CONSTASCII_USTRINGPARAM( - "GetCompatibilityCurrency: none?")); - LocaleDataWrapper::outputCheckMessage( - xLocaleData->appendLocaleInfo( aMsg)); - } - rSymbol = xLocaleData->getCurrSymbol(); - rAbbrev = xLocaleData->getCurrBankSymbol(); - } -} - - -void lcl_CheckCurrencySymbolPosition( const NfCurrencyEntry& rCurr ) -{ - switch ( rCurr.GetPositiveFormat() ) - { - case 0: // $1 - case 1: // 1$ - case 2: // $ 1 - case 3: // 1 $ - break; - default: - LocaleDataWrapper::outputCheckMessage( - "lcl_CheckCurrencySymbolPosition: unknown PositiveFormat"); - break; - } - switch ( rCurr.GetNegativeFormat() ) - { - case 0: // ($1) - case 1: // -$1 - case 2: // $-1 - case 3: // $1- - case 4: // (1$) - case 5: // -1$ - case 6: // 1-$ - case 7: // 1$- - case 8: // -1 $ - case 9: // -$ 1 - case 10: // 1 $- - case 11: // $ -1 - case 12 : // $ 1- - case 13 : // 1- $ - case 14 : // ($ 1) - case 15 : // (1 $) - break; - default: - LocaleDataWrapper::outputCheckMessage( - "lcl_CheckCurrencySymbolPosition: unknown NegativeFormat"); - break; - } -} - - -// static -void SvNumberFormatter::ImpInitCurrencyTable() -{ - // racing condition possible: - // ::osl::MutexGuard aGuard( GetMutex() ); - // while ( !bCurrencyTableInitialized ) - // ImpInitCurrencyTable(); - static sal_Bool bInitializing = sal_False; - if ( bCurrencyTableInitialized || bInitializing ) - return ; - bInitializing = sal_True; - - RTL_LOGFILE_CONTEXT_AUTHOR( aTimeLog, "svl", "er93726", "SvNumberFormatter::ImpInitCurrencyTable" ); - - LanguageType eSysLang = SvtSysLocale().GetLanguage(); - LocaleDataWrapper* pLocaleData = new LocaleDataWrapper( - ::comphelper::getProcessServiceFactory(), - MsLangId::convertLanguageToLocale( eSysLang ) ); - // get user configured currency - String aConfiguredCurrencyAbbrev; - LanguageType eConfiguredCurrencyLanguage = LANGUAGE_SYSTEM; - SvtSysLocaleOptions().GetCurrencyAbbrevAndLanguage( - aConfiguredCurrencyAbbrev, eConfiguredCurrencyLanguage ); - sal_uInt16 nSecondarySystemCurrencyPosition = 0; - sal_uInt16 nMatchingSystemCurrencyPosition = 0; - NfCurrencyEntryPtr pEntry; - - // first entry is SYSTEM - pEntry = new NfCurrencyEntry( *pLocaleData, LANGUAGE_SYSTEM ); - theCurrencyTable::get().Insert( pEntry, 0 ); - sal_uInt16 nCurrencyPos = 1; - - ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > xLoc = - LocaleDataWrapper::getInstalledLocaleNames(); - sal_Int32 nLocaleCount = xLoc.getLength(); - RTL_LOGFILE_CONTEXT_TRACE1( aTimeLog, "number of locales: %ld", nLocaleCount ); - Locale const * const pLocales = xLoc.getConstArray(); - NfCurrencyTable &rCurrencyTable = theCurrencyTable::get(); - NfCurrencyTable &rLegacyOnlyCurrencyTable = theLegacyOnlyCurrencyTable::get(); - sal_uInt16 nLegacyOnlyCurrencyPos = 0; - for ( sal_Int32 nLocale = 0; nLocale < nLocaleCount; nLocale++ ) - { - LanguageType eLang = MsLangId::convertLocaleToLanguage( - pLocales[nLocale]); - theInstalledLocales.insert( eLang); - pLocaleData->setLocale( pLocales[nLocale] ); - Sequence< Currency2 > aCurrSeq = pLocaleData->getAllCurrencies(); - sal_Int32 nCurrencyCount = aCurrSeq.getLength(); - Currency2 const * const pCurrencies = aCurrSeq.getConstArray(); - - // one default currency for each locale, insert first so it is found first - sal_Int32 nDefault; - for ( nDefault = 0; nDefault < nCurrencyCount; nDefault++ ) - { - if ( pCurrencies[nDefault].Default ) - break; - } - if ( nDefault < nCurrencyCount ) - pEntry = new NfCurrencyEntry( pCurrencies[nDefault], *pLocaleData, eLang ); - else - pEntry = new NfCurrencyEntry( *pLocaleData, eLang ); // first or ShellsAndPebbles - - if (LocaleDataWrapper::areChecksEnabled()) - lcl_CheckCurrencySymbolPosition( *pEntry ); - - rCurrencyTable.Insert( pEntry, nCurrencyPos++ ); - if ( !nSystemCurrencyPosition && (aConfiguredCurrencyAbbrev.Len() ? - pEntry->GetBankSymbol() == aConfiguredCurrencyAbbrev && - pEntry->GetLanguage() == eConfiguredCurrencyLanguage : sal_False) ) - nSystemCurrencyPosition = nCurrencyPos-1; - if ( !nMatchingSystemCurrencyPosition && - pEntry->GetLanguage() == eSysLang ) - nMatchingSystemCurrencyPosition = nCurrencyPos-1; - - // all remaining currencies for each locale - if ( nCurrencyCount > 1 ) - { - sal_Int32 nCurrency; - for ( nCurrency = 0; nCurrency < nCurrencyCount; nCurrency++ ) - { - if (pCurrencies[nCurrency].LegacyOnly) - { - pEntry = new NfCurrencyEntry( pCurrencies[nCurrency], *pLocaleData, eLang ); - rLegacyOnlyCurrencyTable.Insert( pEntry, nLegacyOnlyCurrencyPos++ ); - } - else if ( nCurrency != nDefault ) - { - pEntry = new NfCurrencyEntry( pCurrencies[nCurrency], *pLocaleData, eLang ); - // no dupes - sal_Bool bInsert = sal_True; - NfCurrencyEntry const * const * pData = rCurrencyTable.GetData(); - sal_uInt16 n = rCurrencyTable.Count(); - pData++; // skip first SYSTEM entry - for ( sal_uInt16 j=1; j<n; j++ ) - { - if ( *(*pData++) == *pEntry ) - { - bInsert = sal_False; - break; // for - } - } - if ( !bInsert ) - delete pEntry; - else - { - rCurrencyTable.Insert( pEntry, nCurrencyPos++ ); - if ( !nSecondarySystemCurrencyPosition && - (aConfiguredCurrencyAbbrev.Len() ? - pEntry->GetBankSymbol() == aConfiguredCurrencyAbbrev : - pEntry->GetLanguage() == eConfiguredCurrencyLanguage) ) - nSecondarySystemCurrencyPosition = nCurrencyPos-1; - if ( !nMatchingSystemCurrencyPosition && - pEntry->GetLanguage() == eSysLang ) - nMatchingSystemCurrencyPosition = nCurrencyPos-1; - } - } - } - } - } - if ( !nSystemCurrencyPosition ) - nSystemCurrencyPosition = nSecondarySystemCurrencyPosition; - if ((aConfiguredCurrencyAbbrev.Len() && !nSystemCurrencyPosition) && - LocaleDataWrapper::areChecksEnabled()) - LocaleDataWrapper::outputCheckMessage( - "SvNumberFormatter::ImpInitCurrencyTable: configured currency not in I18N locale data."); - // match SYSTEM if no configured currency found - if ( !nSystemCurrencyPosition ) - nSystemCurrencyPosition = nMatchingSystemCurrencyPosition; - if ((!aConfiguredCurrencyAbbrev.Len() && !nSystemCurrencyPosition) && - LocaleDataWrapper::areChecksEnabled()) - LocaleDataWrapper::outputCheckMessage( - "SvNumberFormatter::ImpInitCurrencyTable: system currency not in I18N locale data."); - delete pLocaleData; - SvtSysLocaleOptions::SetCurrencyChangeLink( - STATIC_LINK( NULL, SvNumberFormatter, CurrencyChangeLink ) ); - bInitializing = sal_False; - bCurrencyTableInitialized = sal_True; -} - - -sal_uInt16 SvNumberFormatter::GetCurrencyFormatStrings( NfWSStringsDtor& rStrArr, - const NfCurrencyEntry& rCurr, sal_Bool bBank ) const -{ - sal_uInt16 nDefault = 0; - if ( bBank ) - { // nur Bankensymbole - String aPositiveBank, aNegativeBank; - rCurr.BuildPositiveFormatString( aPositiveBank, sal_True, *xLocaleData, 1 ); - rCurr.BuildNegativeFormatString( aNegativeBank, sal_True, *xLocaleData, 1 ); - - WSStringPtr pFormat1 = new String( aPositiveBank ); - *pFormat1 += ';'; - WSStringPtr pFormat2 = new String( *pFormat1 ); - - String aRed( '[' ); - aRed += pFormatScanner->GetRedString(); - aRed += ']'; - - *pFormat2 += aRed; - - *pFormat1 += aNegativeBank; - *pFormat2 += aNegativeBank; - - rStrArr.Insert( pFormat1, rStrArr.Count() ); - rStrArr.Insert( pFormat2, rStrArr.Count() ); - nDefault = rStrArr.Count() - 1; - } - else - { // gemischte Formate wie in SvNumberFormatter::ImpGenerateFormats - // aber keine doppelten, wenn keine Nachkommastellen in Waehrung - String aPositive, aNegative, aPositiveNoDec, aNegativeNoDec, - aPositiveDashed, aNegativeDashed; - WSStringPtr pFormat1, pFormat2, pFormat3, pFormat4, pFormat5; - - String aRed( '[' ); - aRed += pFormatScanner->GetRedString(); - aRed += ']'; - - rCurr.BuildPositiveFormatString( aPositive, sal_False, *xLocaleData, 1 ); - rCurr.BuildNegativeFormatString( aNegative, sal_False, *xLocaleData, 1 ); - if ( rCurr.GetDigits() ) - { - rCurr.BuildPositiveFormatString( aPositiveNoDec, sal_False, *xLocaleData, 0 ); - rCurr.BuildNegativeFormatString( aNegativeNoDec, sal_False, *xLocaleData, 0 ); - rCurr.BuildPositiveFormatString( aPositiveDashed, sal_False, *xLocaleData, 2 ); - rCurr.BuildNegativeFormatString( aNegativeDashed, sal_False, *xLocaleData, 2 ); - - pFormat1 = new String( aPositiveNoDec ); - *pFormat1 += ';'; - pFormat3 = new String( *pFormat1 ); - pFormat5 = new String( aPositiveDashed ); - *pFormat5 += ';'; - - *pFormat1 += aNegativeNoDec; - - *pFormat3 += aRed; - *pFormat5 += aRed; - - *pFormat3 += aNegativeNoDec; - *pFormat5 += aNegativeDashed; - } - else - { - pFormat1 = NULL; - pFormat3 = NULL; - pFormat5 = NULL; - } - - pFormat2 = new String( aPositive ); - *pFormat2 += ';'; - pFormat4 = new String( *pFormat2 ); - - *pFormat2 += aNegative; - - *pFormat4 += aRed; - *pFormat4 += aNegative; - - if ( pFormat1 ) - rStrArr.Insert( pFormat1, rStrArr.Count() ); - rStrArr.Insert( pFormat2, rStrArr.Count() ); - if ( pFormat3 ) - rStrArr.Insert( pFormat3, rStrArr.Count() ); - rStrArr.Insert( pFormat4, rStrArr.Count() ); - nDefault = rStrArr.Count() - 1; - if ( pFormat5 ) - rStrArr.Insert( pFormat5, rStrArr.Count() ); - } - return nDefault; -} - - -//--- NfCurrencyEntry ---------------------------------------------------- - -NfCurrencyEntry::NfCurrencyEntry() - : eLanguage( LANGUAGE_DONTKNOW ), - nPositiveFormat(3), - nNegativeFormat(8), - nDigits(2), - cZeroChar('0') -{ -} - - -NfCurrencyEntry::NfCurrencyEntry( const LocaleDataWrapper& rLocaleData, LanguageType eLang ) -{ - aSymbol = rLocaleData.getCurrSymbol(); - aBankSymbol = rLocaleData.getCurrBankSymbol(); - eLanguage = eLang; - nPositiveFormat = rLocaleData.getCurrPositiveFormat(); - nNegativeFormat = rLocaleData.getCurrNegativeFormat(); - nDigits = rLocaleData.getCurrDigits(); - cZeroChar = rLocaleData.getCurrZeroChar(); -} - - -NfCurrencyEntry::NfCurrencyEntry( const ::com::sun::star::i18n::Currency & rCurr, - const LocaleDataWrapper& rLocaleData, LanguageType eLang ) -{ - aSymbol = rCurr.Symbol; - aBankSymbol = rCurr.BankSymbol; - eLanguage = eLang; - nPositiveFormat = rLocaleData.getCurrPositiveFormat(); - nNegativeFormat = rLocaleData.getCurrNegativeFormat(); - nDigits = rCurr.DecimalPlaces; - cZeroChar = rLocaleData.getCurrZeroChar(); -} - - -sal_Bool NfCurrencyEntry::operator==( const NfCurrencyEntry& r ) const -{ - return aSymbol == r.aSymbol - && aBankSymbol == r.aBankSymbol - && eLanguage == r.eLanguage - ; -} - - -void NfCurrencyEntry::SetEuro() -{ - aSymbol = NfCurrencyEntry::GetEuroSymbol(); - aBankSymbol.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "EUR" ) ); - eLanguage = LANGUAGE_DONTKNOW; - nPositiveFormat = 3; - nNegativeFormat = 8; - nDigits = 2; - cZeroChar = '0'; -} - - -sal_Bool NfCurrencyEntry::IsEuro() const -{ - if ( aBankSymbol.EqualsAscii( "EUR" ) ) - return sal_True; - String aEuro( NfCurrencyEntry::GetEuroSymbol() ); - return aSymbol == aEuro; -} - - -void NfCurrencyEntry::ApplyVariableInformation( const NfCurrencyEntry& r ) -{ - nPositiveFormat = r.nPositiveFormat; - nNegativeFormat = r.nNegativeFormat; - cZeroChar = r.cZeroChar; -} - - -void NfCurrencyEntry::BuildSymbolString( String& rStr, sal_Bool bBank, - sal_Bool bWithoutExtension ) const -{ - rStr = '['; - rStr += '$'; - if ( bBank ) - rStr += aBankSymbol; - else - { - if ( aSymbol.Search( '-' ) != STRING_NOTFOUND || aSymbol.Search( ']' ) != STRING_NOTFOUND ) - { - rStr += '"'; - rStr += aSymbol; - rStr += '"'; - } - else - rStr += aSymbol; - if ( !bWithoutExtension && eLanguage != LANGUAGE_DONTKNOW && eLanguage != LANGUAGE_SYSTEM ) - { - rStr += '-'; - rStr += String::CreateFromInt32( sal_Int32( eLanguage ), 16 ).ToUpperAscii(); - } - } - rStr += ']'; -} - - -void NfCurrencyEntry::Impl_BuildFormatStringNumChars( String& rStr, - const LocaleDataWrapper& rLoc, sal_uInt16 nDecimalFormat ) const -{ - rStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "###0" ) ); - rStr.Insert( rLoc.getNumThousandSep(), 1 ); - if ( nDecimalFormat && nDigits ) - { - rStr += rLoc.getNumDecimalSep(); - rStr.Expand( rStr.Len() + nDigits, (nDecimalFormat == 2 ? '-' : cZeroChar) ); - } -} - - -void NfCurrencyEntry::BuildPositiveFormatString( String& rStr, sal_Bool bBank, - const LocaleDataWrapper& rLoc, sal_uInt16 nDecimalFormat ) const -{ - Impl_BuildFormatStringNumChars( rStr, rLoc, nDecimalFormat ); - sal_uInt16 nPosiForm = NfCurrencyEntry::GetEffectivePositiveFormat( - rLoc.getCurrPositiveFormat(), nPositiveFormat, bBank ); - CompletePositiveFormatString( rStr, bBank, nPosiForm ); -} - - -void NfCurrencyEntry::BuildNegativeFormatString( String& rStr, sal_Bool bBank, - const LocaleDataWrapper& rLoc, sal_uInt16 nDecimalFormat ) const -{ - Impl_BuildFormatStringNumChars( rStr, rLoc, nDecimalFormat ); - sal_uInt16 nNegaForm = NfCurrencyEntry::GetEffectiveNegativeFormat( - rLoc.getCurrNegativeFormat(), nNegativeFormat, bBank ); - CompleteNegativeFormatString( rStr, bBank, nNegaForm ); -} - - -void NfCurrencyEntry::CompletePositiveFormatString( String& rStr, sal_Bool bBank, - sal_uInt16 nPosiForm ) const -{ - String aSymStr; - BuildSymbolString( aSymStr, bBank ); - NfCurrencyEntry::CompletePositiveFormatString( rStr, aSymStr, nPosiForm ); -} - - -void NfCurrencyEntry::CompleteNegativeFormatString( String& rStr, sal_Bool bBank, - sal_uInt16 nNegaForm ) const -{ - String aSymStr; - BuildSymbolString( aSymStr, bBank ); - NfCurrencyEntry::CompleteNegativeFormatString( rStr, aSymStr, nNegaForm ); -} - - -// static -void NfCurrencyEntry::CompletePositiveFormatString( String& rStr, - const String& rSymStr, sal_uInt16 nPositiveFormat ) -{ - switch( nPositiveFormat ) - { - case 0: // $1 - rStr.Insert( rSymStr , 0 ); - break; - case 1: // 1$ - rStr += rSymStr; - break; - case 2: // $ 1 - { - rStr.Insert( ' ', 0 ); - rStr.Insert( rSymStr, 0 ); - } - break; - case 3: // 1 $ - { - rStr += ' '; - rStr += rSymStr; - } - break; - default: - OSL_FAIL("NfCurrencyEntry::CompletePositiveFormatString: unknown option"); - break; - } -} - - -// static -void NfCurrencyEntry::CompleteNegativeFormatString( String& rStr, - const String& rSymStr, sal_uInt16 nNegativeFormat ) -{ - switch( nNegativeFormat ) - { - case 0: // ($1) - { - rStr.Insert( rSymStr, 0); - rStr.Insert('(',0); - rStr += ')'; - } - break; - case 1: // -$1 - { - rStr.Insert( rSymStr, 0); - rStr.Insert('-',0); - } - break; - case 2: // $-1 - { - rStr.Insert('-',0); - rStr.Insert( rSymStr, 0); - } - break; - case 3: // $1- - { - rStr.Insert( rSymStr, 0); - rStr += '-'; - } - break; - case 4: // (1$) - { - rStr.Insert('(',0); - rStr += rSymStr; - rStr += ')'; - } - break; - case 5: // -1$ - { - rStr += rSymStr; - rStr.Insert('-',0); - } - break; - case 6: // 1-$ - { - rStr += '-'; - rStr += rSymStr; - } - break; - case 7: // 1$- - { - rStr += rSymStr; - rStr += '-'; - } - break; - case 8: // -1 $ - { - rStr += ' '; - rStr += rSymStr; - rStr.Insert('-',0); - } - break; - case 9: // -$ 1 - { - rStr.Insert(' ',0); - rStr.Insert( rSymStr, 0); - rStr.Insert('-',0); - } - break; - case 10: // 1 $- - { - rStr += ' '; - rStr += rSymStr; - rStr += '-'; - } - break; - case 11: // $ -1 - { - String aTmp( rSymStr ); - aTmp += ' '; - aTmp += '-'; - rStr.Insert( aTmp, 0 ); - } - break; - case 12 : // $ 1- - { - rStr.Insert(' ', 0); - rStr.Insert( rSymStr, 0); - rStr += '-'; - } - break; - case 13 : // 1- $ - { - rStr += '-'; - rStr += ' '; - rStr += rSymStr; - } - break; - case 14 : // ($ 1) - { - rStr.Insert(' ',0); - rStr.Insert( rSymStr, 0); - rStr.Insert('(',0); - rStr += ')'; - } - break; - case 15 : // (1 $) - { - rStr.Insert('(',0); - rStr += ' '; - rStr += rSymStr; - rStr += ')'; - } - break; - default: - OSL_FAIL("NfCurrencyEntry::CompleteNegativeFormatString: unknown option"); - break; - } -} - - -// static -sal_uInt16 NfCurrencyEntry::GetEffectivePositiveFormat( sal_uInt16 -#if ! NF_BANKSYMBOL_FIX_POSITION - nIntlFormat -#endif - , sal_uInt16 nCurrFormat, sal_Bool bBank ) -{ - if ( bBank ) - { -#if NF_BANKSYMBOL_FIX_POSITION - return 3; -#else - switch ( nIntlFormat ) - { - case 0: // $1 - nIntlFormat = 2; // $ 1 - break; - case 1: // 1$ - nIntlFormat = 3; // 1 $ - break; - case 2: // $ 1 - break; - case 3: // 1 $ - break; - default: - OSL_FAIL("NfCurrencyEntry::GetEffectivePositiveFormat: unknown option"); - break; - } - return nIntlFormat; -#endif - } - else - return nCurrFormat; -} - - -// nur aufrufen, wenn nCurrFormat wirklich mit Klammern ist -sal_uInt16 lcl_MergeNegativeParenthesisFormat( sal_uInt16 nIntlFormat, sal_uInt16 nCurrFormat ) -{ - short nSign = 0; // -1:=Klammer 0:=links, 1:=mitte, 2:=rechts - switch ( nIntlFormat ) - { - case 0: // ($1) - case 4: // (1$) - case 14 : // ($ 1) - case 15 : // (1 $) - return nCurrFormat; - case 1: // -$1 - case 5: // -1$ - case 8: // -1 $ - case 9: // -$ 1 - nSign = 0; - break; - case 2: // $-1 - case 6: // 1-$ - case 11 : // $ -1 - case 13 : // 1- $ - nSign = 1; - break; - case 3: // $1- - case 7: // 1$- - case 10: // 1 $- - case 12 : // $ 1- - nSign = 2; - break; - default: - OSL_FAIL("lcl_MergeNegativeParenthesisFormat: unknown option"); - break; - } - - switch ( nCurrFormat ) - { - case 0: // ($1) - switch ( nSign ) - { - case 0: - return 1; // -$1 - case 1: - return 2; // $-1 - case 2: - return 3; // $1- - } - break; - case 4: // (1$) - switch ( nSign ) - { - case 0: - return 5; // -1$ - case 1: - return 6; // 1-$ - case 2: - return 7; // 1$- - } - break; - case 14 : // ($ 1) - switch ( nSign ) - { - case 0: - return 9; // -$ 1 - case 1: - return 11; // $ -1 - case 2: - return 12; // $ 1- - } - break; - case 15 : // (1 $) - switch ( nSign ) - { - case 0: - return 8; // -1 $ - case 1: - return 13; // 1- $ - case 2: - return 10; // 1 $- - } - break; - } - return nCurrFormat; -} - - -// static -sal_uInt16 NfCurrencyEntry::GetEffectiveNegativeFormat( sal_uInt16 nIntlFormat, - sal_uInt16 nCurrFormat, sal_Bool bBank ) -{ - if ( bBank ) - { -#if NF_BANKSYMBOL_FIX_POSITION - return 8; -#else - switch ( nIntlFormat ) - { - case 0: // ($1) -// nIntlFormat = 14; // ($ 1) - nIntlFormat = 9; // -$ 1 - break; - case 1: // -$1 - nIntlFormat = 9; // -$ 1 - break; - case 2: // $-1 - nIntlFormat = 11; // $ -1 - break; - case 3: // $1- - nIntlFormat = 12; // $ 1- - break; - case 4: // (1$) -// nIntlFormat = 15; // (1 $) - nIntlFormat = 8; // -1 $ - break; - case 5: // -1$ - nIntlFormat = 8; // -1 $ - break; - case 6: // 1-$ - nIntlFormat = 13; // 1- $ - break; - case 7: // 1$- - nIntlFormat = 10; // 1 $- - break; - case 8: // -1 $ - break; - case 9: // -$ 1 - break; - case 10: // 1 $- - break; - case 11: // $ -1 - break; - case 12 : // $ 1- - break; - case 13 : // 1- $ - break; - case 14 : // ($ 1) -// nIntlFormat = 14; // ($ 1) - nIntlFormat = 9; // -$ 1 - break; - case 15 : // (1 $) -// nIntlFormat = 15; // (1 $) - nIntlFormat = 8; // -1 $ - break; - default: - OSL_FAIL("NfCurrencyEntry::GetEffectiveNegativeFormat: unknown option"); - break; - } -#endif - } - else if ( nIntlFormat != nCurrFormat ) - { - switch ( nCurrFormat ) - { - case 0: // ($1) - nIntlFormat = lcl_MergeNegativeParenthesisFormat( - nIntlFormat, nCurrFormat ); - break; - case 1: // -$1 - nIntlFormat = nCurrFormat; - break; - case 2: // $-1 - nIntlFormat = nCurrFormat; - break; - case 3: // $1- - nIntlFormat = nCurrFormat; - break; - case 4: // (1$) - nIntlFormat = lcl_MergeNegativeParenthesisFormat( - nIntlFormat, nCurrFormat ); - break; - case 5: // -1$ - nIntlFormat = nCurrFormat; - break; - case 6: // 1-$ - nIntlFormat = nCurrFormat; - break; - case 7: // 1$- - nIntlFormat = nCurrFormat; - break; - case 8: // -1 $ - nIntlFormat = nCurrFormat; - break; - case 9: // -$ 1 - nIntlFormat = nCurrFormat; - break; - case 10: // 1 $- - nIntlFormat = nCurrFormat; - break; - case 11: // $ -1 - nIntlFormat = nCurrFormat; - break; - case 12 : // $ 1- - nIntlFormat = nCurrFormat; - break; - case 13 : // 1- $ - nIntlFormat = nCurrFormat; - break; - case 14 : // ($ 1) - nIntlFormat = lcl_MergeNegativeParenthesisFormat( - nIntlFormat, nCurrFormat ); - break; - case 15 : // (1 $) - nIntlFormat = lcl_MergeNegativeParenthesisFormat( - nIntlFormat, nCurrFormat ); - break; - default: - OSL_FAIL("NfCurrencyEntry::GetEffectiveNegativeFormat: unknown option"); - break; - } - } - return nIntlFormat; -} - - -// we only support default encodings here -// static -sal_Char NfCurrencyEntry::GetEuroSymbol( rtl_TextEncoding eTextEncoding ) -{ - switch ( eTextEncoding ) - { - case RTL_TEXTENCODING_MS_1252 : // WNT Ansi - case RTL_TEXTENCODING_ISO_8859_1 : // UNX for use with TrueType fonts - return '\x80'; - case RTL_TEXTENCODING_ISO_8859_15 : // UNX real - return '\xA4'; - case RTL_TEXTENCODING_IBM_850 : // OS2 - return '\xD5'; - case RTL_TEXTENCODING_APPLE_ROMAN : // MAC - return '\xDB'; - default: // default system -#if WNT - return '\x80'; -#elif UNX -// return '\xA4'; // #56121# 0xA4 waere korrekt fuer iso-8859-15 - return '\x80'; // aber Windoze-Code fuer die konvertierten TrueType-Fonts -#else -#error EuroSymbol is what? - return '\x80'; -#endif - } - return '\x80'; -} - - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zformat.cxx b/svl/source/numbers/zformat.cxx deleted file mode 100644 index 69b3e1762f..0000000000 --- a/svl/source/numbers/zformat.cxx +++ /dev/null @@ -1,4787 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <stdio.h> -#include <ctype.h> -#include <float.h> -#include <errno.h> -#include <stdlib.h> -#include <tools/debug.hxx> -#include <osl/diagnose.h> -#include <i18npool/mslangid.hxx> -#include <rtl/math.hxx> -#include <rtl/instance.hxx> -#include <unotools/charclass.hxx> -#include <unotools/calendarwrapper.hxx> -#include <unotools/nativenumberwrapper.hxx> -#include <com/sun/star/i18n/CalendarFieldIndex.hpp> -#include <com/sun/star/i18n/CalendarDisplayIndex.hpp> -#include <com/sun/star/i18n/CalendarDisplayCode.hpp> -#include <com/sun/star/i18n/AmPmValue.hpp> - -#define _ZFORMAT_CXX -#include <svl/zformat.hxx> -#include <zforscan.hxx> - -#include "zforfind.hxx" -#include <svl/zforlist.hxx> -#include "numhead.hxx" -#include <unotools/digitgroupingiterator.hxx> -#include <svl/nfsymbol.hxx> - -#include <cmath> - -using namespace svt; -using ::rtl::OUString; -using ::rtl::OUStringBuffer; - -namespace { -struct Gregorian - : public rtl::StaticWithInit<const ::rtl::OUString, Gregorian> { - const ::rtl::OUString operator () () { - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("gregorian")); - } -}; - -const sal_uInt16 UPPER_PRECISION = 300; // entirely arbitrary... -const double EXP_LOWER_BOUND = 1.0E-4; // prefer scientific notation below this value. - -} - -const double _D_MAX_U_LONG_ = (double) 0xffffffff; // 4294967295.0 -const double _D_MAX_LONG_ = (double) 0x7fffffff; // 2147483647.0 -const sal_uInt16 _MAX_FRACTION_PREC = 3; -const double D_EPS = 1.0E-2; - -const double _D_MAX_D_BY_100 = 1.7E306; -const double _D_MIN_M_BY_1000 = 2.3E-305; - -static sal_uInt8 cCharWidths[ 128-32 ] = { - 1,1,1,2,2,3,2,1,1,1,1,2,1,1,1,1, - 2,2,2,2,2,2,2,2,2,2,1,1,2,2,2,2, - 3,2,2,2,2,2,2,3,2,1,2,2,2,3,3,3, - 2,3,2,2,2,2,2,3,2,2,2,1,1,1,2,2, - 1,2,2,2,2,2,1,2,2,1,1,2,1,3,2,2, - 2,2,1,2,1,2,2,2,2,2,2,1,1,1,2,1 -}; - -// static -xub_StrLen SvNumberformat::InsertBlanks( String& r, xub_StrLen nPos, sal_Unicode c ) -{ - if( c >= 32 ) - { - sal_uInt16 n = 2; // Default fuer Zeichen > 128 (HACK!) - if( c <= 127 ) - n = cCharWidths[ c - 32 ]; - while( n-- ) - r.Insert( ' ', nPos++ ); - } - return nPos; -} - -static long GetPrecExp( double fAbsVal ) -{ - DBG_ASSERT( fAbsVal > 0.0, "GetPrecExp: fAbsVal <= 0.0" ); - if ( fAbsVal < 1e-7 || fAbsVal > 1e7 ) - { // die Schere, ob's schneller ist oder nicht, liegt zwischen 1e6 und 1e7 - return (long) floor( log10( fAbsVal ) ) + 1; - } - else - { - long nPrecExp = 1; - while( fAbsVal < 1 ) - { - fAbsVal *= 10; - nPrecExp--; - } - while( fAbsVal >= 10 ) - { - fAbsVal /= 10; - nPrecExp++; - } - return nPrecExp; - } -} - -const sal_uInt16 nNewCurrencyVersionId = 0x434E; // "NC" -const sal_Unicode cNewCurrencyMagic = 0x01; // Magic for format code in comment -const sal_uInt16 nNewStandardFlagVersionId = 0x4653; // "SF" - -/***********************Funktion SvNumberformatInfo******************************/ - -void ImpSvNumberformatInfo::Copy( const ImpSvNumberformatInfo& rNumFor, sal_uInt16 nAnz ) -{ - for (sal_uInt16 i = 0; i < nAnz; i++) - { - sStrArray[i] = rNumFor.sStrArray[i]; - nTypeArray[i] = rNumFor.nTypeArray[i]; - } - eScannedType = rNumFor.eScannedType; - bThousand = rNumFor.bThousand; - nThousand = rNumFor.nThousand; - nCntPre = rNumFor.nCntPre; - nCntPost = rNumFor.nCntPost; - nCntExp = rNumFor.nCntExp; -} - -void ImpSvNumberformatInfo::Save(SvStream& rStream, sal_uInt16 nAnz) const -{ - for (sal_uInt16 i = 0; i < nAnz; i++) - { - rStream.WriteByteString( sStrArray[i], rStream.GetStreamCharSet() ); - short nType = nTypeArray[i]; - switch ( nType ) - { // der Krampf fuer Versionen vor SV_NUMBERFORMATTER_VERSION_NEW_CURR - case NF_SYMBOLTYPE_CURRENCY : - rStream << short( NF_SYMBOLTYPE_STRING ); - break; - case NF_SYMBOLTYPE_CURRDEL : - case NF_SYMBOLTYPE_CURREXT : - rStream << short(0); // werden ignoriert (hoffentlich..) - break; - default: - if ( nType > NF_KEY_LASTKEYWORD_SO5 ) - rStream << short( NF_SYMBOLTYPE_STRING ); // all new keywords are string - else - rStream << nType; - } - - } - rStream << eScannedType << bThousand << nThousand - << nCntPre << nCntPost << nCntExp; -} - -void ImpSvNumberformatInfo::Load(SvStream& rStream, sal_uInt16 nAnz) -{ - for (sal_uInt16 i = 0; i < nAnz; i++) - { - SvNumberformat::LoadString( rStream, sStrArray[i] ); - rStream >> nTypeArray[i]; - } - rStream >> eScannedType >> bThousand >> nThousand - >> nCntPre >> nCntPost >> nCntExp; -} - -//============================================================================ - -// static -sal_uInt8 SvNumberNatNum::MapDBNumToNatNum( sal_uInt8 nDBNum, LanguageType eLang, sal_Bool bDate ) -{ - sal_uInt8 nNatNum = 0; - eLang = MsLangId::getRealLanguage( eLang ); // resolve SYSTEM etc. - eLang &= 0x03FF; // 10 bit primary language - if ( bDate ) - { - if ( nDBNum == 4 && eLang == LANGUAGE_KOREAN ) - nNatNum = 9; - else if ( nDBNum <= 3 ) - nNatNum = nDBNum; // known to be good for: zh,ja,ko / 1,2,3 - } - else - { - switch ( nDBNum ) - { - case 1: - switch ( eLang ) - { - case (LANGUAGE_CHINESE & 0x03FF) : nNatNum = 4; break; - case (LANGUAGE_JAPANESE & 0x03FF) : nNatNum = 1; break; - case (LANGUAGE_KOREAN & 0x03FF) : nNatNum = 1; break; - } - break; - case 2: - switch ( eLang ) - { - case (LANGUAGE_CHINESE & 0x03FF) : nNatNum = 5; break; - case (LANGUAGE_JAPANESE & 0x03FF) : nNatNum = 4; break; - case (LANGUAGE_KOREAN & 0x03FF) : nNatNum = 2; break; - } - break; - case 3: - switch ( eLang ) - { - case (LANGUAGE_CHINESE & 0x03FF) : nNatNum = 6; break; - case (LANGUAGE_JAPANESE & 0x03FF) : nNatNum = 5; break; - case (LANGUAGE_KOREAN & 0x03FF) : nNatNum = 3; break; - } - break; - case 4: - switch ( eLang ) - { - case (LANGUAGE_JAPANESE & 0x03FF) : nNatNum = 7; break; - case (LANGUAGE_KOREAN & 0x03FF) : nNatNum = 9; break; - } - break; - } - } - return nNatNum; -} - -// static -sal_uInt8 SvNumberNatNum::MapNatNumToDBNum( sal_uInt8 nNatNum, LanguageType eLang, sal_Bool bDate ) -{ - sal_uInt8 nDBNum = 0; - eLang = MsLangId::getRealLanguage( eLang ); // resolve SYSTEM etc. - eLang &= 0x03FF; // 10 bit primary language - if ( bDate ) - { - if ( nNatNum == 9 && eLang == LANGUAGE_KOREAN ) - nDBNum = 4; - else if ( nNatNum <= 3 ) - nDBNum = nNatNum; // known to be good for: zh,ja,ko / 1,2,3 - } - else - { - switch ( nNatNum ) - { - case 1: - switch ( eLang ) - { - case (LANGUAGE_JAPANESE & 0x03FF) : nDBNum = 1; break; - case (LANGUAGE_KOREAN & 0x03FF) : nDBNum = 1; break; - } - break; - case 2: - switch ( eLang ) - { - case (LANGUAGE_KOREAN & 0x03FF) : nDBNum = 2; break; - } - break; - case 3: - switch ( eLang ) - { - case (LANGUAGE_KOREAN & 0x03FF) : nDBNum = 3; break; - } - break; - case 4: - switch ( eLang ) - { - case (LANGUAGE_CHINESE & 0x03FF) : nDBNum = 1; break; - case (LANGUAGE_JAPANESE & 0x03FF) : nDBNum = 2; break; - } - break; - case 5: - switch ( eLang ) - { - case (LANGUAGE_CHINESE & 0x03FF) : nDBNum = 2; break; - case (LANGUAGE_JAPANESE & 0x03FF) : nDBNum = 3; break; - } - break; - case 6: - switch ( eLang ) - { - case (LANGUAGE_CHINESE & 0x03FF) : nDBNum = 3; break; - } - break; - case 7: - switch ( eLang ) - { - case (LANGUAGE_JAPANESE & 0x03FF) : nDBNum = 4; break; - } - break; - case 8: - break; - case 9: - switch ( eLang ) - { - case (LANGUAGE_KOREAN & 0x03FF) : nDBNum = 4; break; - } - break; - case 10: - break; - case 11: - break; - } - } - return nDBNum; -} - -/***********************Funktionen SvNumFor******************************/ - -ImpSvNumFor::ImpSvNumFor() -{ - nAnzStrings = 0; - aI.nTypeArray = NULL; - aI.sStrArray = NULL; - aI.eScannedType = NUMBERFORMAT_UNDEFINED; - aI.bThousand = sal_False; - aI.nThousand = 0; - aI.nCntPre = 0; - aI.nCntPost = 0; - aI.nCntExp = 0; - pColor = NULL; -} - -ImpSvNumFor::~ImpSvNumFor() -{ - for (sal_uInt16 i = 0; i < nAnzStrings; i++) - aI.sStrArray[i].Erase(); - delete [] aI.sStrArray; - delete [] aI.nTypeArray; -} - -void ImpSvNumFor::Enlarge(sal_uInt16 nAnz) -{ - if ( nAnzStrings != nAnz ) - { - if ( aI.nTypeArray ) - delete [] aI.nTypeArray; - if ( aI.sStrArray ) - delete [] aI.sStrArray; - nAnzStrings = nAnz; - if ( nAnz ) - { - aI.nTypeArray = new short[nAnz]; - aI.sStrArray = new String[nAnz]; - } - else - { - aI.nTypeArray = NULL; - aI.sStrArray = NULL; - } - } -} - -void ImpSvNumFor::Copy( const ImpSvNumFor& rNumFor, ImpSvNumberformatScan* pSc ) -{ - Enlarge( rNumFor.nAnzStrings ); - aI.Copy( rNumFor.aI, nAnzStrings ); - sColorName = rNumFor.sColorName; - if ( pSc ) - pColor = pSc->GetColor( sColorName ); // #121103# don't copy pointer between documents - else - pColor = rNumFor.pColor; - aNatNum = rNumFor.aNatNum; -} - -void ImpSvNumFor::Save(SvStream& rStream) const -{ - rStream << nAnzStrings; - aI.Save(rStream, nAnzStrings); - rStream.WriteByteString( sColorName, rStream.GetStreamCharSet() ); -} - -void ImpSvNumFor::Load(SvStream& rStream, ImpSvNumberformatScan& rSc, - String& rLoadedColorName ) -{ - sal_uInt16 nAnz; - rStream >> nAnz; //! noch nicht direkt nAnzStrings wg. Enlarge - Enlarge( nAnz ); - aI.Load( rStream, nAnz ); - rStream.ReadByteString( sColorName, rStream.GetStreamCharSet() ); - rLoadedColorName = sColorName; - pColor = rSc.GetColor(sColorName); -} - -sal_Bool ImpSvNumFor::HasNewCurrency() const -{ - for ( sal_uInt16 j=0; j<nAnzStrings; j++ ) - { - if ( aI.nTypeArray[j] == NF_SYMBOLTYPE_CURRENCY ) - return sal_True; - } - return sal_False; -} - -sal_Bool ImpSvNumFor::GetNewCurrencySymbol( String& rSymbol, - String& rExtension ) const -{ - for ( sal_uInt16 j=0; j<nAnzStrings; j++ ) - { - if ( aI.nTypeArray[j] == NF_SYMBOLTYPE_CURRENCY ) - { - rSymbol = aI.sStrArray[j]; - if ( j < nAnzStrings-1 && aI.nTypeArray[j+1] == NF_SYMBOLTYPE_CURREXT ) - rExtension = aI.sStrArray[j+1]; - else - rExtension.Erase(); - return sal_True; - } - } - //! kein Erase an rSymbol, rExtension - return sal_False; -} - -void ImpSvNumFor::SaveNewCurrencyMap( SvStream& rStream ) const -{ - sal_uInt16 j; - sal_uInt16 nCnt = 0; - for ( j=0; j<nAnzStrings; j++ ) - { - switch ( aI.nTypeArray[j] ) - { - case NF_SYMBOLTYPE_CURRENCY : - case NF_SYMBOLTYPE_CURRDEL : - case NF_SYMBOLTYPE_CURREXT : - nCnt++; - break; - } - } - rStream << nCnt; - for ( j=0; j<nAnzStrings; j++ ) - { - switch ( aI.nTypeArray[j] ) - { - case NF_SYMBOLTYPE_CURRENCY : - case NF_SYMBOLTYPE_CURRDEL : - case NF_SYMBOLTYPE_CURREXT : - rStream << j << aI.nTypeArray[j]; - break; - } - } -} - -void ImpSvNumFor::LoadNewCurrencyMap( SvStream& rStream ) -{ - sal_uInt16 nCnt; - rStream >> nCnt; - for ( sal_uInt16 j=0; j<nCnt; j++ ) - { - sal_uInt16 nPos; - short nType; - rStream >> nPos >> nType; - if ( nPos < nAnzStrings ) - aI.nTypeArray[nPos] = nType; - } -} - -/***********************Funktionen SvNumberformat************************/ - -enum BracketFormatSymbolType -{ - BRACKET_SYMBOLTYPE_FORMAT = -1, // subformat string - BRACKET_SYMBOLTYPE_COLOR = -2, // color - BRACKET_SYMBOLTYPE_ERROR = -3, // error - BRACKET_SYMBOLTYPE_DBNUM1 = -4, // DoubleByteNumber, represent numbers - BRACKET_SYMBOLTYPE_DBNUM2 = -5, // using CJK characters, Excel compatible. - BRACKET_SYMBOLTYPE_DBNUM3 = -6, - BRACKET_SYMBOLTYPE_DBNUM4 = -7, - BRACKET_SYMBOLTYPE_DBNUM5 = -8, - BRACKET_SYMBOLTYPE_DBNUM6 = -9, - BRACKET_SYMBOLTYPE_DBNUM7 = -10, - BRACKET_SYMBOLTYPE_DBNUM8 = -11, - BRACKET_SYMBOLTYPE_DBNUM9 = -12, - BRACKET_SYMBOLTYPE_LOCALE = -13, - BRACKET_SYMBOLTYPE_NATNUM0 = -14, // Our NativeNumber support, ASCII - BRACKET_SYMBOLTYPE_NATNUM1 = -15, // Our NativeNumber support, represent - BRACKET_SYMBOLTYPE_NATNUM2 = -16, // numbers using CJK, CTL, ... - BRACKET_SYMBOLTYPE_NATNUM3 = -17, - BRACKET_SYMBOLTYPE_NATNUM4 = -18, - BRACKET_SYMBOLTYPE_NATNUM5 = -19, - BRACKET_SYMBOLTYPE_NATNUM6 = -20, - BRACKET_SYMBOLTYPE_NATNUM7 = -21, - BRACKET_SYMBOLTYPE_NATNUM8 = -22, - BRACKET_SYMBOLTYPE_NATNUM9 = -23, - BRACKET_SYMBOLTYPE_NATNUM10 = -24, - BRACKET_SYMBOLTYPE_NATNUM11 = -25, - BRACKET_SYMBOLTYPE_NATNUM12 = -26, - BRACKET_SYMBOLTYPE_NATNUM13 = -27, - BRACKET_SYMBOLTYPE_NATNUM14 = -28, - BRACKET_SYMBOLTYPE_NATNUM15 = -29, - BRACKET_SYMBOLTYPE_NATNUM16 = -30, - BRACKET_SYMBOLTYPE_NATNUM17 = -31, - BRACKET_SYMBOLTYPE_NATNUM18 = -32, - BRACKET_SYMBOLTYPE_NATNUM19 = -33 -}; - -SvNumberformat::SvNumberformat( ImpSvNumberformatScan& rSc, LanguageType eLge ) - : - rScan(rSc), - nNewStandardDefined(0), - bStarFlag( sal_False ) -{ - maLocale.meLanguage = eLge; -} - -void SvNumberformat::ImpCopyNumberformat( const SvNumberformat& rFormat ) -{ - sFormatstring = rFormat.sFormatstring; - eType = rFormat.eType; - maLocale = rFormat.maLocale; - fLimit1 = rFormat.fLimit1; - fLimit2 = rFormat.fLimit2; - eOp1 = rFormat.eOp1; - eOp2 = rFormat.eOp2; - bStandard = rFormat.bStandard; - bIsUsed = rFormat.bIsUsed; - sComment = rFormat.sComment; - nNewStandardDefined = rFormat.nNewStandardDefined; - - // #121103# when copying between documents, get color pointers from own scanner - ImpSvNumberformatScan* pColorSc = ( &rScan != &rFormat.rScan ) ? &rScan : NULL; - - for (sal_uInt16 i = 0; i < 4; i++) - NumFor[i].Copy(rFormat.NumFor[i], pColorSc); -} - -SvNumberformat::SvNumberformat( SvNumberformat& rFormat ) - : rScan(rFormat.rScan), bStarFlag( rFormat.bStarFlag ) -{ - ImpCopyNumberformat( rFormat ); -} - -SvNumberformat::SvNumberformat( SvNumberformat& rFormat, ImpSvNumberformatScan& rSc ) - : rScan(rSc), bStarFlag( rFormat.bStarFlag ) -{ - ImpCopyNumberformat( rFormat ); -} - -sal_Bool lcl_SvNumberformat_IsBracketedPrefix( short nSymbolType ) -{ - if ( nSymbolType > 0 ) - return sal_True; // conditions - switch ( nSymbolType ) - { - case BRACKET_SYMBOLTYPE_COLOR : - case BRACKET_SYMBOLTYPE_DBNUM1 : - case BRACKET_SYMBOLTYPE_DBNUM2 : - case BRACKET_SYMBOLTYPE_DBNUM3 : - case BRACKET_SYMBOLTYPE_DBNUM4 : - case BRACKET_SYMBOLTYPE_DBNUM5 : - case BRACKET_SYMBOLTYPE_DBNUM6 : - case BRACKET_SYMBOLTYPE_DBNUM7 : - case BRACKET_SYMBOLTYPE_DBNUM8 : - case BRACKET_SYMBOLTYPE_DBNUM9 : - case BRACKET_SYMBOLTYPE_LOCALE : - case BRACKET_SYMBOLTYPE_NATNUM0 : - case BRACKET_SYMBOLTYPE_NATNUM1 : - case BRACKET_SYMBOLTYPE_NATNUM2 : - case BRACKET_SYMBOLTYPE_NATNUM3 : - case BRACKET_SYMBOLTYPE_NATNUM4 : - case BRACKET_SYMBOLTYPE_NATNUM5 : - case BRACKET_SYMBOLTYPE_NATNUM6 : - case BRACKET_SYMBOLTYPE_NATNUM7 : - case BRACKET_SYMBOLTYPE_NATNUM8 : - case BRACKET_SYMBOLTYPE_NATNUM9 : - case BRACKET_SYMBOLTYPE_NATNUM10 : - case BRACKET_SYMBOLTYPE_NATNUM11 : - case BRACKET_SYMBOLTYPE_NATNUM12 : - case BRACKET_SYMBOLTYPE_NATNUM13 : - case BRACKET_SYMBOLTYPE_NATNUM14 : - case BRACKET_SYMBOLTYPE_NATNUM15 : - case BRACKET_SYMBOLTYPE_NATNUM16 : - case BRACKET_SYMBOLTYPE_NATNUM17 : - case BRACKET_SYMBOLTYPE_NATNUM18 : - case BRACKET_SYMBOLTYPE_NATNUM19 : - return sal_True; - } - return sal_False; -} - - -String SvNumberformat::ImpObtainCalendarAndNumerals( String & rString, - xub_StrLen & nPos, LanguageType & nLang, const LocaleType & aTmpLocale ) -{ - String sCalendar; - /* TODO: this could be enhanced to allow other possible locale dependent - * calendars and numerals. BUT only if our locale data allows it! For LCID - * numerals and calendars see - * http://office.microsoft.com/en-us/excel/HA010346351033.aspx */ - if (MsLangId::getRealLanguage( aTmpLocale.meLanguage) == LANGUAGE_THAI) - { - // Numeral shape code "D" = Thai digits. - if (aTmpLocale.mnNumeralShape == 0xD) - rString.InsertAscii( "[NatNum1]", nPos); - - // Calendar type code "07" = Thai Buddhist calendar, insert this after - // all prefixes have been consumed as it is actually a format modifier - // and not a prefix. - if (aTmpLocale.mnCalendarType == 0x07) - { - // Currently calendars are tied to the locale of the entire number - // format, e.g. [~buddhist] in en_US doesn't work. - // => Having different locales in sub formats does not work! - /* TODO: calendars could be tied to a sub format's NatNum info - * instead, or even better be available for any locale. Needs a - * different implementation of GetCal() and locale data calendars. - * */ - // If this is not Thai yet, make it so. - if (MsLangId::getRealLanguage( maLocale.meLanguage) != LANGUAGE_THAI) - { - maLocale = aTmpLocale; - nLang = maLocale.meLanguage = LANGUAGE_THAI; - } - sCalendar.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "[~buddhist]")); - } - } - return sCalendar; -} - - -SvNumberformat::SvNumberformat(String& rString, - ImpSvNumberformatScan* pSc, - ImpSvNumberInputScan* pISc, - xub_StrLen& nCheckPos, - LanguageType& eLan, - sal_Bool bStan) - : - rScan(*pSc), - nNewStandardDefined(0), - bStarFlag( sal_False ) -{ - // If the group (AKA thousand) separator is a Non-Breaking Space (French) - // replace all occurrences by a simple space. - // The tokens will be changed to the LocaleData separator again later on. - const sal_Unicode cNBSp = 0xA0; - const String& rThSep = GetFormatter().GetNumThousandSep(); - if ( rThSep.GetChar(0) == cNBSp && rThSep.Len() == 1 ) - { - xub_StrLen nIndex = 0; - do - nIndex = rString.SearchAndReplace( cNBSp, ' ', nIndex ); - while ( nIndex != STRING_NOTFOUND ); - } - - if (rScan.GetConvertMode()) - { - maLocale.meLanguage = rScan.GetNewLnge(); - eLan = maLocale.meLanguage; // Wechsel auch zurueckgeben - } - else - maLocale.meLanguage = eLan; - bStandard = bStan; - bIsUsed = sal_False; - fLimit1 = 0.0; - fLimit2 = 0.0; - eOp1 = NUMBERFORMAT_OP_NO; - eOp2 = NUMBERFORMAT_OP_NO; - eType = NUMBERFORMAT_DEFINED; - - sal_Bool bCancel = sal_False; - sal_Bool bCondition = sal_False; - short eSymbolType; - xub_StrLen nPos = 0; - xub_StrLen nPosOld; - nCheckPos = 0; - String aComment; - - // Split into 4 sub formats - sal_uInt16 nIndex; - for ( nIndex = 0; nIndex < 4 && !bCancel; nIndex++ ) - { - // Original language/country may have to be reestablished - if (rScan.GetConvertMode()) - (rScan.GetNumberformatter())->ChangeIntl(rScan.GetTmpLnge()); - - String sInsertCalendar; // a calendar resulting from parsing LCID - String sStr; - nPosOld = nPos; // Start position of substring - // first get bracketed prefixes; e.g. conditions, color - do - { - eSymbolType = ImpNextSymbol(rString, nPos, sStr); - if (eSymbolType > 0) // condition - { - if ( nIndex == 0 && !bCondition ) - { - bCondition = sal_True; - eOp1 = (SvNumberformatLimitOps) eSymbolType; - } - else if ( nIndex == 1 && bCondition ) - eOp2 = (SvNumberformatLimitOps) eSymbolType; - else // error - { - bCancel = sal_True; // break for - nCheckPos = nPosOld; - } - if (!bCancel) - { - double fNumber; - xub_StrLen nAnzChars = ImpGetNumber(rString, nPos, sStr); - if (nAnzChars > 0) - { - short F_Type = NUMBERFORMAT_UNDEFINED; - if (!pISc->IsNumberFormat(sStr,F_Type,fNumber) || - ( F_Type != NUMBERFORMAT_NUMBER && - F_Type != NUMBERFORMAT_SCIENTIFIC) ) - { - fNumber = 0.0; - nPos = nPos - nAnzChars; - rString.Erase(nPos, nAnzChars); - rString.Insert('0',nPos); - nPos++; - } - } - else - { - fNumber = 0.0; - rString.Insert('0',nPos++); - } - if (nIndex == 0) - fLimit1 = fNumber; - else - fLimit2 = fNumber; - if ( rString.GetChar(nPos) == ']' ) - nPos++; - else - { - bCancel = sal_True; // break for - nCheckPos = nPos; - } - } - nPosOld = nPos; // position before string - } - else if ( lcl_SvNumberformat_IsBracketedPrefix( eSymbolType ) ) - { - String sSymbol( sStr); - switch ( eSymbolType ) - { - case BRACKET_SYMBOLTYPE_COLOR : - { - if ( NumFor[nIndex].GetColor() != NULL ) - { // error, more than one color - bCancel = sal_True; // break for - nCheckPos = nPosOld; - } - else - { - Color* pColor = pSc->GetColor( sStr); - NumFor[nIndex].SetColor( pColor, sStr); - if (pColor == NULL) - { // error - bCancel = sal_True; // break for - nCheckPos = nPosOld; - } - } - } - break; - case BRACKET_SYMBOLTYPE_NATNUM0 : - case BRACKET_SYMBOLTYPE_NATNUM1 : - case BRACKET_SYMBOLTYPE_NATNUM2 : - case BRACKET_SYMBOLTYPE_NATNUM3 : - case BRACKET_SYMBOLTYPE_NATNUM4 : - case BRACKET_SYMBOLTYPE_NATNUM5 : - case BRACKET_SYMBOLTYPE_NATNUM6 : - case BRACKET_SYMBOLTYPE_NATNUM7 : - case BRACKET_SYMBOLTYPE_NATNUM8 : - case BRACKET_SYMBOLTYPE_NATNUM9 : - case BRACKET_SYMBOLTYPE_NATNUM10 : - case BRACKET_SYMBOLTYPE_NATNUM11 : - case BRACKET_SYMBOLTYPE_NATNUM12 : - case BRACKET_SYMBOLTYPE_NATNUM13 : - case BRACKET_SYMBOLTYPE_NATNUM14 : - case BRACKET_SYMBOLTYPE_NATNUM15 : - case BRACKET_SYMBOLTYPE_NATNUM16 : - case BRACKET_SYMBOLTYPE_NATNUM17 : - case BRACKET_SYMBOLTYPE_NATNUM18 : - case BRACKET_SYMBOLTYPE_NATNUM19 : - { - if ( NumFor[nIndex].GetNatNum().IsSet() ) - { - bCancel = sal_True; // break for - nCheckPos = nPosOld; - } - else - { - sStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "NatNum" ) ); - //! eSymbolType is negative - sal_uInt8 nNum = sal::static_int_cast< sal_uInt8 >(0 - (eSymbolType - BRACKET_SYMBOLTYPE_NATNUM0)); - sStr += String::CreateFromInt32( nNum ); - NumFor[nIndex].SetNatNumNum( nNum, sal_False ); - } - } - break; - case BRACKET_SYMBOLTYPE_DBNUM1 : - case BRACKET_SYMBOLTYPE_DBNUM2 : - case BRACKET_SYMBOLTYPE_DBNUM3 : - case BRACKET_SYMBOLTYPE_DBNUM4 : - case BRACKET_SYMBOLTYPE_DBNUM5 : - case BRACKET_SYMBOLTYPE_DBNUM6 : - case BRACKET_SYMBOLTYPE_DBNUM7 : - case BRACKET_SYMBOLTYPE_DBNUM8 : - case BRACKET_SYMBOLTYPE_DBNUM9 : - { - if ( NumFor[nIndex].GetNatNum().IsSet() ) - { - bCancel = sal_True; // break for - nCheckPos = nPosOld; - } - else - { - sStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DBNum" ) ); - //! eSymbolType is negative - sal_uInt8 nNum = sal::static_int_cast< sal_uInt8 >(1 - (eSymbolType - BRACKET_SYMBOLTYPE_DBNUM1)); - sStr += static_cast< sal_Unicode >('0' + nNum); - NumFor[nIndex].SetNatNumNum( nNum, sal_True ); - } - } - break; - case BRACKET_SYMBOLTYPE_LOCALE : - { - if ( NumFor[nIndex].GetNatNum().GetLang() != LANGUAGE_DONTKNOW || - rString.GetChar(nPos-1) != ']' ) - // Check also for ']' to avoid pulling in - // locale data for the preview string for not - // yet completed LCIDs in the dialog. - { - bCancel = sal_True; // break for - nCheckPos = nPosOld; - } - else - { - xub_StrLen nTmp = 2; - LocaleType aTmpLocale( ImpGetLocaleType( sStr, nTmp)); - if (aTmpLocale.meLanguage == LANGUAGE_DONTKNOW) - { - bCancel = sal_True; // break for - nCheckPos = nPosOld; - } - else - { - // Only the first sub format's locale will be - // used as the format's overall locale. - // Sorts this also under the corresponding - // locale for the dialog. - // If we don't support the locale this would - // result in an unknown (empty) language - // listbox entry and the user would never see - // this format. - if (nIndex == 0 && (aTmpLocale.meLanguage == 0 || - SvNumberFormatter::IsLocaleInstalled( aTmpLocale.meLanguage))) - { - maLocale = aTmpLocale; - eLan = aTmpLocale.meLanguage; // return to caller - /* TODO: fiddle with scanner to make this - * known? A change in the locale may affect - * separators and keywords. On the other - * hand they may have been entered as used - * in the originating locale, there's no - * way to predict other than analyzing the - * format code, we assume here the current - * context is used, which is most likely - * the case. - * */ - } - sStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM("$-") ); - sStr += String( aTmpLocale.generateCode()); - NumFor[nIndex].SetNatNumLang( MsLangId::getRealLanguage( aTmpLocale.meLanguage)); - - // "$-NNCCLLLL" Numerals and Calendar - if (sSymbol.Len() > 6) - sInsertCalendar = ImpObtainCalendarAndNumerals( rString, nPos, eLan, aTmpLocale); - /* NOTE: there can be only one calendar - * inserted so the last one wins, though - * our own calendar modifiers support - * multiple calendars within one sub format - * code if at different positions. */ - } - } - } - break; - } - if ( !bCancel ) - { - if (sStr == sSymbol) - nPosOld = nPos; - else - { - rString.Erase(nPosOld,nPos-nPosOld); - if (sStr.Len()) - { - rString.Insert(sStr,nPosOld); - nPos = nPosOld + sStr.Len(); - rString.Insert(']', nPos); - rString.Insert('[', nPosOld); - nPos += 2; - nPosOld = nPos; // position before string - } - else - { - nPos = nPosOld; // prefix removed for whatever reason - } - } - } - } - } while ( !bCancel && lcl_SvNumberformat_IsBracketedPrefix( eSymbolType ) ); - - // The remaining format code string - if ( !bCancel ) - { - if (eSymbolType == BRACKET_SYMBOLTYPE_FORMAT) - { - if (nIndex == 1 && eOp1 == NUMBERFORMAT_OP_NO) - eOp1 = NUMBERFORMAT_OP_GT; // undefined condition, default: > 0 - else if (nIndex == 2 && eOp2 == NUMBERFORMAT_OP_NO) - eOp2 = NUMBERFORMAT_OP_LT; // undefined condition, default: < 0 - if (sStr.Len() == 0) - { // empty sub format - } - else - { - if (sInsertCalendar.Len()) - sStr.Insert( sInsertCalendar, 0); - - xub_StrLen nStrPos = pSc->ScanFormat( sStr, aComment ); - sal_uInt16 nAnz = pSc->GetAnzResStrings(); - if (nAnz == 0) // error - nStrPos = 1; - if (nStrPos == 0) // ok - { - // e.g. Thai T speciality - if (pSc->GetNatNumModifier() && !NumFor[nIndex].GetNatNum().IsSet()) - { - String aNat( RTL_CONSTASCII_USTRINGPARAM( "[NatNum")); - aNat += String::CreateFromInt32( pSc->GetNatNumModifier()); - aNat += ']'; - sStr.Insert( aNat, 0); - NumFor[nIndex].SetNatNumNum( pSc->GetNatNumModifier(), sal_False ); - } - // #i53826# #i42727# For the Thai T speciality we need - // to freeze the locale and immunize it against - // conversions during exports, just in case we want to - // save to Xcl. This disables the feature of being able - // to convert a NatNum to another locale. You can't - // have both. - // FIXME: implement a specialized export conversion - // that works on tokens (have to tokenize all first) - // and doesn't use the format string and - // PutandConvertEntry() to LANGUAGE_ENGLISH_US in - // sc/source/filter/excel/xestyle.cxx - // XclExpNumFmtBuffer::WriteFormatRecord(). - LanguageType eLanguage; - if (NumFor[nIndex].GetNatNum().GetNatNum() == 1 && - ((eLanguage = - MsLangId::getRealLanguage( eLan)) - == LANGUAGE_THAI) && - NumFor[nIndex].GetNatNum().GetLang() == - LANGUAGE_DONTKNOW) - { - String aLID( RTL_CONSTASCII_USTRINGPARAM( "[$-")); - aLID += String::CreateFromInt32( sal_Int32( - eLanguage), 16 ).ToUpperAscii(); - aLID += ']'; - sStr.Insert( aLID, 0); - NumFor[nIndex].SetNatNumLang( eLanguage); - } - rString.Erase(nPosOld,nPos-nPosOld); - rString.Insert(sStr,nPosOld); - nPos = nPosOld + sStr.Len(); - if (nPos < rString.Len()) - { - rString.Insert(';',nPos); - nPos++; - } - NumFor[nIndex].Enlarge(nAnz); - pSc->CopyInfo(&(NumFor[nIndex].Info()), nAnz); - // type check - if (nIndex == 0) - eType = (short) NumFor[nIndex].Info().eScannedType; - else if (nIndex == 3) - { // #77026# Everything recognized IS text - NumFor[nIndex].Info().eScannedType = NUMBERFORMAT_TEXT; - } - else if ( (short) NumFor[nIndex].Info().eScannedType != - eType) - eType = NUMBERFORMAT_DEFINED; - } - else - { - nCheckPos = nPosOld + nStrPos; // error in string - bCancel = sal_True; // break for - } - } - } - else if (eSymbolType == BRACKET_SYMBOLTYPE_ERROR) // error - { - nCheckPos = nPosOld; - bCancel = sal_True; - } - else if ( lcl_SvNumberformat_IsBracketedPrefix( eSymbolType ) ) - { - nCheckPos = nPosOld+1; // error, prefix in string - bCancel = sal_True; // break for - } - } - if ( bCancel && !nCheckPos ) - nCheckPos = 1; // nCheckPos is used as an error condition - if ( !bCancel ) - { - if ( NumFor[nIndex].GetNatNum().IsSet() && - NumFor[nIndex].GetNatNum().GetLang() == LANGUAGE_DONTKNOW ) - NumFor[nIndex].SetNatNumLang( eLan ); - } - if (rString.Len() == nPos) - { - if ( nIndex == 2 && eSymbolType == BRACKET_SYMBOLTYPE_FORMAT && - rString.GetChar(nPos-1) == ';' ) - { // #83510# A 4th subformat explicitly specified to be empty - // hides any text. Need the type here for HasTextFormat() - NumFor[3].Info().eScannedType = NUMBERFORMAT_TEXT; - } - bCancel = sal_True; - } - if ( NumFor[nIndex].GetNatNum().IsSet() ) - NumFor[nIndex].SetNatNumDate( - (NumFor[nIndex].Info().eScannedType & NUMBERFORMAT_DATE) != 0 ); - } - - if ( bCondition && !nCheckPos ) - { - if ( nIndex == 1 && NumFor[0].GetCount() == 0 && - rString.GetChar(rString.Len()-1) != ';' ) - { // No format code => GENERAL but not if specified empty - String aAdd( pSc->GetStandardName() ); - String aTmp; - if ( !pSc->ScanFormat( aAdd, aTmp ) ) - { - sal_uInt16 nAnz = pSc->GetAnzResStrings(); - if ( nAnz ) - { - NumFor[0].Enlarge(nAnz); - pSc->CopyInfo( &(NumFor[0].Info()), nAnz ); - rString += aAdd; - } - } - } - else if ( nIndex == 1 && NumFor[nIndex].GetCount() == 0 && - rString.GetChar(rString.Len()-1) != ';' && - (NumFor[0].GetCount() > 1 || (NumFor[0].GetCount() == 1 && - NumFor[0].Info().nTypeArray[0] != NF_KEY_GENERAL)) ) - { // No trailing second subformat => GENERAL but not if specified empty - // and not if first subformat is GENERAL - String aAdd( pSc->GetStandardName() ); - String aTmp; - if ( !pSc->ScanFormat( aAdd, aTmp ) ) - { - sal_uInt16 nAnz = pSc->GetAnzResStrings(); - if ( nAnz ) - { - NumFor[nIndex].Enlarge(nAnz); - pSc->CopyInfo( &(NumFor[nIndex].Info()), nAnz ); - rString += ';'; - rString += aAdd; - } - } - } - else if ( nIndex == 2 && NumFor[nIndex].GetCount() == 0 && - rString.GetChar(rString.Len()-1) != ';' && - eOp2 != NUMBERFORMAT_OP_NO ) - { // No trailing third subformat => GENERAL but not if specified empty - String aAdd( pSc->GetStandardName() ); - String aTmp; - if ( !pSc->ScanFormat( aAdd, aTmp ) ) - { - sal_uInt16 nAnz = pSc->GetAnzResStrings(); - if ( nAnz ) - { - NumFor[nIndex].Enlarge(nAnz); - pSc->CopyInfo( &(NumFor[nIndex].Info()), nAnz ); - rString += ';'; - rString += aAdd; - } - } - } - } - sFormatstring = rString; - if ( aComment.Len() ) - { - SetComment( aComment ); // setzt sComment und sFormatstring - rString = sFormatstring; // geaenderten sFormatstring uebernehmen - } - if (NumFor[2].GetCount() == 0 && // kein 3. Teilstring - eOp1 == NUMBERFORMAT_OP_GT && eOp2 == NUMBERFORMAT_OP_NO && - fLimit1 == 0.0 && fLimit2 == 0.0) - eOp1 = NUMBERFORMAT_OP_GE; // 0 zum ersten Format dazu - -} - -SvNumberformat::~SvNumberformat() -{ -} - -//--------------------------------------------------------------------------- -// Next_Symbol -//--------------------------------------------------------------------------- -// Zerlegt die Eingabe in Symbole fuer die weitere -// Verarbeitung (Turing-Maschine). -//--------------------------------------------------------------------------- -// Ausgangs Zustand = SsStart -//---------------+-------------------+-----------------------+--------------- -// Alter Zustand | gelesenes Zeichen | Aktion | Neuer Zustand -//---------------+-------------------+-----------------------+--------------- -// SsStart | ; | Pos-- | SsGetString -// | [ | Symbol += Zeichen | SsGetBracketed -// | ] | Fehler | SsStop -// | BLANK | | -// | Sonst | Symbol += Zeichen | SsGetString -//---------------+-------------------+-----------------------+--------------- -// SsGetString | ; | | SsStop -// | Sonst | Symbol+=Zeichen | -//---------------+-------------------+-----------------------+--------------- -// SsGetBracketed| <, > = | del [ | -// | | Symbol += Zeichen | SsGetCon -// | BLANK | | -// | h, H, m, M, s, S | Symbol += Zeichen | SsGetTime -// | sonst | del [ | -// | | Symbol += Zeichen | SsGetPrefix -//---------------+-------------------+-----------------------+--------------- -// SsGetTime | ] | Symbol += Zeichen | SsGetString -// | h, H, m, M, s, S | Symbol += Zeichen, * | SsGetString -// | sonst | del [; Symbol+=Zeichen| SsGetPrefix -//---------------+-------------------+-----------------------+--------------- -// SsGetPrefix | ] | | SsStop -// | sonst | Symbol += Zeichen | -//---------------+-------------------+-----------------------+--------------- -// SsGetCon | >, = | Symbol+=Zeichen | -// | ] | | SsStop -// | sonst | Fehler | SsStop -//---------------+-------------------+-----------------------+--------------- -// * : Sonderbedingung - -enum ScanState -{ - SsStop, - SsStart, - SsGetCon, // condition - SsGetString, // format string - SsGetPrefix, // color or NatNumN - SsGetTime, // [HH] for time - SsGetBracketed // any [...] not decided yet -}; - -// read a string until ']' and delete spaces in input -// static -xub_StrLen SvNumberformat::ImpGetNumber(String& rString, - xub_StrLen& nPos, - String& sSymbol) -{ - xub_StrLen nStartPos = nPos; - sal_Unicode cToken; - xub_StrLen nLen = rString.Len(); - sSymbol.Erase(); - while ( nPos < nLen && ((cToken = rString.GetChar(nPos)) != ']') ) - { - if (cToken == ' ') - { // delete spaces - rString.Erase(nPos,1); - nLen--; - } - else - { - nPos++; - sSymbol += cToken; - } - } - return nPos - nStartPos; -} - -namespace { - -sal_Unicode toUniChar(sal_uInt8 n) -{ - sal_Char c; - if (n < 10) - c = '0' + n; - else - c = 'A' + n - 10; - return sal_Unicode(c); -} - -} - -OUString SvNumberformat::LocaleType::generateCode() const -{ - OUStringBuffer aBuf; -#if 0 - // TODO: We may re-enable this later. Don't remove it! --Kohei - if (mnNumeralShape) - { - sal_uInt8 nVal = mnNumeralShape; - for (sal_uInt8 i = 0; i < 2; ++i) - { - sal_uInt8 n = (nVal & 0xF0) >> 4; - if (n || aBuf.getLength()) - aBuf.append(toUniChar(n)); - nVal = nVal << 4; - } - } - - if (mnNumeralShape || mnCalendarType) - { - sal_uInt8 nVal = mnCalendarType; - for (sal_uInt8 i = 0; i < 2; ++i) - { - sal_uInt8 n = (nVal & 0xF0) >> 4; - if (n || aBuf.getLength()) - aBuf.append(toUniChar(n)); - nVal = nVal << 4; - } - } -#endif - - sal_uInt16 n16 = static_cast<sal_uInt16>(meLanguage); - for (sal_uInt8 i = 0; i < 4; ++i) - { - sal_uInt8 n = static_cast<sal_uInt8>((n16 & 0xF000) >> 12); - // Omit leading zeros for consistency. - if (n || aBuf.getLength() || i == 3) - aBuf.append(toUniChar(n)); - n16 = n16 << 4; - } - - return aBuf.makeStringAndClear(); -} - -SvNumberformat::LocaleType::LocaleType() : - mnNumeralShape(0), - mnCalendarType(0), - meLanguage(LANGUAGE_DONTKNOW) -{ -} - -SvNumberformat::LocaleType::LocaleType(sal_uInt32 nRawNum) : - mnNumeralShape(0), - mnCalendarType(0), - meLanguage(LANGUAGE_DONTKNOW) -{ - meLanguage = static_cast<LanguageType>(nRawNum & 0x0000FFFF); - nRawNum = (nRawNum >> 16); - mnCalendarType = static_cast<sal_uInt8>(nRawNum & 0xFF); - nRawNum = (nRawNum >> 8); - mnNumeralShape = static_cast<sal_uInt8>(nRawNum & 0xFF); -} - -// static -SvNumberformat::LocaleType SvNumberformat::ImpGetLocaleType( - const String& rString, xub_StrLen& nPos ) -{ - sal_uInt32 nNum = 0; - sal_Unicode cToken = 0; - xub_StrLen nStart = nPos; - xub_StrLen nLen = rString.Len(); - while ( nPos < nLen && (nPos - nStart < 8) && ((cToken = rString.GetChar(nPos)) != ']') ) - { - if ( '0' <= cToken && cToken <= '9' ) - { - nNum *= 16; - nNum += cToken - '0'; - } - else if ( 'a' <= cToken && cToken <= 'f' ) - { - nNum *= 16; - nNum += cToken - 'a' + 10; - } - else if ( 'A' <= cToken && cToken <= 'F' ) - { - nNum *= 16; - nNum += cToken - 'A' + 10; - } - else - return LANGUAGE_DONTKNOW; - ++nPos; - } - - return (cToken == ']' || nPos == nLen) ? LocaleType(nNum) : LocaleType(); -} - -short SvNumberformat::ImpNextSymbol(String& rString, - xub_StrLen& nPos, - String& sSymbol) -{ - short eSymbolType = BRACKET_SYMBOLTYPE_FORMAT; - sal_Unicode cToken; - sal_Unicode cLetter = ' '; // Zwischenergebnis - xub_StrLen nLen = rString.Len(); - ScanState eState = SsStart; - sSymbol.Erase(); - const NfKeywordTable & rKeywords = rScan.GetKeywords(); - while (nPos < nLen && eState != SsStop) - { - cToken = rString.GetChar(nPos); - nPos++; - switch (eState) - { - case SsStart: - { - if (cToken == '[') - { - eState = SsGetBracketed; - sSymbol += cToken; - } - else if (cToken == ';') - { - eState = SsGetString; - nPos--; - eSymbolType = BRACKET_SYMBOLTYPE_FORMAT; - } - else if (cToken == ']') - { - eState = SsStop; - eSymbolType = BRACKET_SYMBOLTYPE_ERROR; - } - else if (cToken == ' ') // Skip Blanks - { - rString.Erase(nPos-1,1); - nPos--; - nLen--; - } - else - { - sSymbol += cToken; - eState = SsGetString; - eSymbolType = BRACKET_SYMBOLTYPE_FORMAT; - } - } - break; - case SsGetBracketed: - { - switch (cToken) - { - case '<': - case '>': - case '=': - { - sSymbol.EraseAllChars('['); - sSymbol += cToken; - cLetter = cToken; - eState = SsGetCon; - switch (cToken) - { - case '<': eSymbolType = NUMBERFORMAT_OP_LT; break; - case '>': eSymbolType = NUMBERFORMAT_OP_GT; break; - case '=': eSymbolType = NUMBERFORMAT_OP_EQ; break; - default: break; - } - } - break; - case ' ': - { - rString.Erase(nPos-1,1); - nPos--; - nLen--; - } - break; - case '$' : - { - if ( rString.GetChar(nPos) == '-' ) - { // [$-xxx] locale - sSymbol.EraseAllChars('['); - eSymbolType = BRACKET_SYMBOLTYPE_LOCALE; - eState = SsGetPrefix; - } - else - { // currency as of SV_NUMBERFORMATTER_VERSION_NEW_CURR - eSymbolType = BRACKET_SYMBOLTYPE_FORMAT; - eState = SsGetString; - } - sSymbol += cToken; - } - break; - case '~' : - { // calendarID as of SV_NUMBERFORMATTER_VERSION_CALENDAR - eSymbolType = BRACKET_SYMBOLTYPE_FORMAT; - sSymbol += cToken; - eState = SsGetString; - } - break; - default: - { - const String aNatNum(RTL_CONSTASCII_USTRINGPARAM("NATNUM")); - const String aDBNum(RTL_CONSTASCII_USTRINGPARAM("DBNUM")); - String aUpperNatNum( rChrCls().toUpper( rString, nPos-1, aNatNum.Len() ) ); - String aUpperDBNum( rChrCls().toUpper( rString, nPos-1, aDBNum.Len() ) ); - sal_Unicode cUpper = aUpperNatNum.GetChar(0); - sal_Int32 nNatNumNum = rString.Copy( nPos-1+aNatNum.Len() ).ToInt32(); - sal_Unicode cDBNum = rString.GetChar( nPos-1+aDBNum.Len() ); - if ( aUpperNatNum == aNatNum && 0 <= nNatNumNum && nNatNumNum <= 19 ) - { - sSymbol.EraseAllChars('['); - sSymbol += rString.Copy( --nPos, aNatNum.Len()+1 ); - nPos += aNatNum.Len()+1; - //! SymbolType is negative - eSymbolType = (short) (BRACKET_SYMBOLTYPE_NATNUM0 - nNatNumNum); - eState = SsGetPrefix; - } - else if ( aUpperDBNum == aDBNum && '1' <= cDBNum && cDBNum <= '9' ) - { - sSymbol.EraseAllChars('['); - sSymbol += rString.Copy( --nPos, aDBNum.Len()+1 ); - nPos += aDBNum.Len()+1; - //! SymbolType is negative - eSymbolType = sal::static_int_cast< short >( - BRACKET_SYMBOLTYPE_DBNUM1 - (cDBNum - '1')); - eState = SsGetPrefix; - } - else if (cUpper == rKeywords[NF_KEY_H].GetChar(0) || // H - cUpper == rKeywords[NF_KEY_MI].GetChar(0) || // M - cUpper == rKeywords[NF_KEY_S].GetChar(0) ) // S - { - sSymbol += cToken; - eState = SsGetTime; - cLetter = cToken; - } - else - { - sSymbol.EraseAllChars('['); - sSymbol += cToken; - eSymbolType = BRACKET_SYMBOLTYPE_COLOR; - eState = SsGetPrefix; - } - } - break; - } - } - break; - case SsGetString: - { - if (cToken == ';') - eState = SsStop; - else - sSymbol += cToken; - } - break; - case SsGetTime: - { - if (cToken == ']') - { - sSymbol += cToken; - eState = SsGetString; - eSymbolType = BRACKET_SYMBOLTYPE_FORMAT; - } - else - { - sal_Unicode cUpper = rChrCls().toUpper( rString, nPos-1, 1 ).GetChar(0); - if (cUpper == rKeywords[NF_KEY_H].GetChar(0) || // H - cUpper == rKeywords[NF_KEY_MI].GetChar(0) || // M - cUpper == rKeywords[NF_KEY_S].GetChar(0) ) // S - { - if (cLetter == cToken) - { - sSymbol += cToken; - cLetter = ' '; - } - else - { - sSymbol.EraseAllChars('['); - sSymbol += cToken; - eState = SsGetPrefix; - } - } - else - { - sSymbol.EraseAllChars('['); - sSymbol += cToken; - eSymbolType = BRACKET_SYMBOLTYPE_COLOR; - eState = SsGetPrefix; - } - } - } - break; - case SsGetCon: - { - switch (cToken) - { - case '<': - { - eState = SsStop; - eSymbolType = BRACKET_SYMBOLTYPE_ERROR; - } - break; - case '>': - { - if (cLetter == '<') - { - sSymbol += cToken; - cLetter = ' '; - eState = SsStop; - eSymbolType = NUMBERFORMAT_OP_NE; - } - else - { - eState = SsStop; - eSymbolType = BRACKET_SYMBOLTYPE_ERROR; - } - } - break; - case '=': - { - if (cLetter == '<') - { - sSymbol += cToken; - cLetter = ' '; - eSymbolType = NUMBERFORMAT_OP_LE; - } - else if (cLetter == '>') - { - sSymbol += cToken; - cLetter = ' '; - eSymbolType = NUMBERFORMAT_OP_GE; - } - else - { - eState = SsStop; - eSymbolType = BRACKET_SYMBOLTYPE_ERROR; - } - } - break; - case ' ': - { - rString.Erase(nPos-1,1); - nPos--; - nLen--; - } - break; - default: - { - eState = SsStop; - nPos--; - } - break; - } - } - break; - case SsGetPrefix: - { - if (cToken == ']') - eState = SsStop; - else - sSymbol += cToken; - } - break; - default: - break; - } // of switch - } // of while - - return eSymbolType; -} - -NfHackConversion SvNumberformat::Load( SvStream& rStream, - ImpSvNumMultipleReadHeader& rHdr, SvNumberFormatter* pHackConverter, - ImpSvNumberInputScan& rISc ) -{ - rHdr.StartEntry(); - sal_uInt16 nOp1, nOp2; - SvNumberformat::LoadString( rStream, sFormatstring ); - rStream >> eType >> fLimit1 >> fLimit2 - >> nOp1 >> nOp2 >> bStandard >> bIsUsed; - NfHackConversion eHackConversion = NF_CONVERT_NONE; - sal_Bool bOldConvert = sal_False; - LanguageType eOldTmpLang = 0; - LanguageType eOldNewLang = 0; - if ( pHackConverter ) - { // werden nur hierbei gebraucht - bOldConvert = rScan.GetConvertMode(); - eOldTmpLang = rScan.GetTmpLnge(); - eOldNewLang = rScan.GetNewLnge(); - } - String aLoadedColorName; - for (sal_uInt16 i = 0; i < 4; i++) - { - NumFor[i].Load( rStream, rScan, aLoadedColorName ); - if ( pHackConverter && eHackConversion == NF_CONVERT_NONE ) - { - //! HACK! ER 29.07.97 13:52 - // leider wurde nicht gespeichert, was SYSTEM on Save wirklich war :-/ - // aber immerhin wird manchmal fuer einen Entry FARBE oder COLOR gespeichert.. - // System-German FARBE nach System-xxx COLOR umsetzen und vice versa, - //! geht davon aus, dass onSave nur GERMAN und ENGLISH KeyWords in - //! ImpSvNumberformatScan existierten - if ( aLoadedColorName.Len() && !NumFor[i].GetColor() - && aLoadedColorName != rScan.GetColorString() ) - { - if ( rScan.GetColorString().EqualsAscii( "FARBE" ) ) - { // English -> German - eHackConversion = NF_CONVERT_ENGLISH_GERMAN; - rScan.GetNumberformatter()->ChangeIntl( LANGUAGE_ENGLISH_US ); - rScan.SetConvertMode( LANGUAGE_ENGLISH_US, LANGUAGE_GERMAN ); - } - else - { // German -> English - eHackConversion = NF_CONVERT_GERMAN_ENGLISH; - rScan.GetNumberformatter()->ChangeIntl( LANGUAGE_GERMAN ); - rScan.SetConvertMode( LANGUAGE_GERMAN, LANGUAGE_ENGLISH_US ); - } - String aColorName = NumFor[i].GetColorName(); - const Color* pColor = rScan.GetColor( aColorName ); - if ( !pColor && aLoadedColorName == aColorName ) - eHackConversion = NF_CONVERT_NONE; - rScan.GetNumberformatter()->ChangeIntl( LANGUAGE_SYSTEM ); - rScan.SetConvertMode( eOldTmpLang, eOldNewLang ); - rScan.SetConvertMode( bOldConvert ); - } - } - } - eOp1 = (SvNumberformatLimitOps) nOp1; - eOp2 = (SvNumberformatLimitOps) nOp2; - String aComment; // wird nach dem NewCurrency-Geraffel richtig gesetzt - if ( rHdr.BytesLeft() ) - { // ab SV_NUMBERFORMATTER_VERSION_NEWSTANDARD - SvNumberformat::LoadString( rStream, aComment ); - rStream >> nNewStandardDefined; - } - - xub_StrLen nNewCurrencyEnd = STRING_NOTFOUND; - sal_Bool bNewCurrencyComment = ( aComment.GetChar(0) == cNewCurrencyMagic && - (nNewCurrencyEnd = aComment.Search( cNewCurrencyMagic, 1 )) != STRING_NOTFOUND ); - sal_Bool bNewCurrencyLoaded = sal_False; - sal_Bool bNewCurrency = sal_False; - - sal_Bool bGoOn = sal_True; - while ( rHdr.BytesLeft() && bGoOn ) - { // as of SV_NUMBERFORMATTER_VERSION_NEW_CURR - sal_uInt16 nId; - rStream >> nId; - switch ( nId ) - { - case nNewCurrencyVersionId : - { - bNewCurrencyLoaded = sal_True; - rStream >> bNewCurrency; - if ( bNewCurrency ) - { - for ( sal_uInt16 j=0; j<4; j++ ) - { - NumFor[j].LoadNewCurrencyMap( rStream ); - } - } - } - break; - case nNewStandardFlagVersionId : - rStream >> bStandard; // the real standard flag - break; - default: - DBG_ERRORFILE( "SvNumberformat::Load: unknown header bytes left nId" ); - bGoOn = sal_False; // stop reading unknown stream left over of newer versions - // Would be nice to have multiple read/write headers instead - // but old versions wouldn't know it, TLOT. - } - } - rHdr.EndEntry(); - - if ( bNewCurrencyLoaded ) - { - if ( bNewCurrency && bNewCurrencyComment ) - { // original Formatstring und Kommentar wiederherstellen - sFormatstring = aComment.Copy( 1, nNewCurrencyEnd-1 ); - aComment.Erase( 0, nNewCurrencyEnd+1 ); - } - } - else if ( bNewCurrencyComment ) - { // neu, aber mit Version vor SV_NUMBERFORMATTER_VERSION_NEW_CURR gespeichert - // original Formatstring und Kommentar wiederherstellen - sFormatstring = aComment.Copy( 1, nNewCurrencyEnd-1 ); - aComment.Erase( 0, nNewCurrencyEnd+1 ); - // Zustaende merken - short nDefined = ( eType & NUMBERFORMAT_DEFINED ); - sal_uInt16 nNewStandard = nNewStandardDefined; - // neu parsen etc. - String aStr( sFormatstring ); - xub_StrLen nCheckPos = 0; - SvNumberformat* pFormat = new SvNumberformat( aStr, &rScan, &rISc, - nCheckPos, maLocale.meLanguage, bStandard ); - DBG_ASSERT( !nCheckPos, "SvNumberformat::Load: NewCurrencyRescan nCheckPos" ); - ImpCopyNumberformat( *pFormat ); - delete pFormat; - // Zustaende wiederherstellen - eType |= nDefined; - if ( nNewStandard ) - SetNewStandardDefined( nNewStandard ); - } - SetComment( aComment ); - - if ( eHackConversion != NF_CONVERT_NONE ) - { //! und weiter mit dem HACK! - switch ( eHackConversion ) - { - case NF_CONVERT_ENGLISH_GERMAN : - ConvertLanguage( *pHackConverter, - LANGUAGE_ENGLISH_US, LANGUAGE_GERMAN, sal_True ); - break; - case NF_CONVERT_GERMAN_ENGLISH : - ConvertLanguage( *pHackConverter, - LANGUAGE_GERMAN, LANGUAGE_ENGLISH_US, sal_True ); - break; - default: - DBG_ERRORFILE( "SvNumberformat::Load: eHackConversion unknown" ); - } - } - return eHackConversion; -} - -void SvNumberformat::ConvertLanguage( SvNumberFormatter& rConverter, - LanguageType eConvertFrom, LanguageType eConvertTo, sal_Bool bSystem ) -{ - xub_StrLen nCheckPos; - sal_uInt32 nKey; - short nType = eType; - String aFormatString( sFormatstring ); - if ( bSystem ) - rConverter.PutandConvertEntrySystem( aFormatString, nCheckPos, nType, - nKey, eConvertFrom, eConvertTo ); - else - rConverter.PutandConvertEntry( aFormatString, nCheckPos, nType, - nKey, eConvertFrom, eConvertTo ); - const SvNumberformat* pFormat = rConverter.GetEntry( nKey ); - DBG_ASSERT( pFormat, "SvNumberformat::ConvertLanguage: Conversion ohne Format" ); - if ( pFormat ) - { - ImpCopyNumberformat( *pFormat ); - // aus Formatter/Scanner uebernommene Werte zuruecksetzen - if ( bSystem ) - maLocale.meLanguage = LANGUAGE_SYSTEM; - // pColor zeigt noch auf Tabelle in temporaerem Formatter/Scanner - for ( sal_uInt16 i = 0; i < 4; i++ ) - { - String aColorName = NumFor[i].GetColorName(); - Color* pColor = rScan.GetColor( aColorName ); - NumFor[i].SetColor( pColor, aColorName ); - } - } -} - -// static -void SvNumberformat::LoadString( SvStream& rStream, String& rStr ) -{ - CharSet eStream = rStream.GetStreamCharSet(); - ByteString aStr; - rStream.ReadByteString( aStr ); - sal_Char cStream = NfCurrencyEntry::GetEuroSymbol( eStream ); - if ( aStr.Search( cStream ) == STRING_NOTFOUND ) - { // simple conversion to unicode - rStr = UniString( aStr, eStream ); - } - else - { - sal_Unicode cTarget = NfCurrencyEntry::GetEuroSymbol(); - register const sal_Char* p = aStr.GetBuffer(); - register const sal_Char* const pEnd = p + aStr.Len(); - register sal_Unicode* pUni = rStr.AllocBuffer( aStr.Len() ); - while ( p < pEnd ) - { - if ( *p == cStream ) - *pUni = cTarget; - else - *pUni = ByteString::ConvertToUnicode( *p, eStream ); - p++; - pUni++; - } - *pUni = 0; - } -} - -void SvNumberformat::Save( SvStream& rStream, ImpSvNumMultipleWriteHeader& rHdr ) const -{ - String aFormatstring( sFormatstring ); - String aComment( sComment ); -#if NF_COMMENT_IN_FORMATSTRING - // der Kommentar im Formatstring wird nicht gespeichert, um in alten Versionen - // nicht ins schleudern zu kommen und spaeter getrennte Verarbeitung - // (z.B. im Dialog) zu ermoeglichen - SetComment( "", aFormatstring, aComment ); -#endif - - sal_Bool bNewCurrency = HasNewCurrency(); - if ( bNewCurrency ) - { // SV_NUMBERFORMATTER_VERSION_NEW_CURR im Kommentar speichern - aComment.Insert( cNewCurrencyMagic, 0 ); - aComment.Insert( cNewCurrencyMagic, 0 ); - aComment.Insert( aFormatstring, 1 ); - Build50Formatstring( aFormatstring ); // alten Formatstring generieren - } - - // old SO5 versions do behave strange (no output) if standard flag is set - // on formats not prepared for it (not having the following exact types) - sal_Bool bOldStandard = bStandard; - if ( bOldStandard ) - { - switch ( eType ) - { - case NUMBERFORMAT_NUMBER : - case NUMBERFORMAT_DATE : - case NUMBERFORMAT_TIME : - case NUMBERFORMAT_DATETIME : - case NUMBERFORMAT_PERCENT : - case NUMBERFORMAT_SCIENTIFIC : - // ok to save - break; - default: - bOldStandard = sal_False; - } - } - - rHdr.StartEntry(); - rStream.WriteByteString( aFormatstring, rStream.GetStreamCharSet() ); - rStream << eType << fLimit1 << fLimit2 << (sal_uInt16) eOp1 << (sal_uInt16) eOp2 - << bOldStandard << bIsUsed; - for (sal_uInt16 i = 0; i < 4; i++) - NumFor[i].Save(rStream); - // ab SV_NUMBERFORMATTER_VERSION_NEWSTANDARD - rStream.WriteByteString( aComment, rStream.GetStreamCharSet() ); - rStream << nNewStandardDefined; - // ab SV_NUMBERFORMATTER_VERSION_NEW_CURR - rStream << nNewCurrencyVersionId; - rStream << bNewCurrency; - if ( bNewCurrency ) - { - for ( sal_uInt16 j=0; j<4; j++ ) - { - NumFor[j].SaveNewCurrencyMap( rStream ); - } - } - - // the real standard flag to load with versions >638 if different - if ( bStandard != bOldStandard ) - { - rStream << nNewStandardFlagVersionId; - rStream << bStandard; - } - - rHdr.EndEntry(); -} - -sal_Bool SvNumberformat::HasNewCurrency() const -{ - for ( sal_uInt16 j=0; j<4; j++ ) - { - if ( NumFor[j].HasNewCurrency() ) - return sal_True; - } - return sal_False; -} - -sal_Bool SvNumberformat::GetNewCurrencySymbol( String& rSymbol, - String& rExtension ) const -{ - for ( sal_uInt16 j=0; j<4; j++ ) - { - if ( NumFor[j].GetNewCurrencySymbol( rSymbol, rExtension ) ) - return sal_True; - } - rSymbol.Erase(); - rExtension.Erase(); - return sal_False; -} - -// static -String SvNumberformat::StripNewCurrencyDelimiters( const String& rStr, - sal_Bool bQuoteSymbol ) -{ - String aTmp; - xub_StrLen nStartPos, nPos, nLen; - nLen = rStr.Len(); - nStartPos = 0; - while ( (nPos = rStr.SearchAscii( "[$", nStartPos )) != STRING_NOTFOUND ) - { - xub_StrLen nEnd; - if ( (nEnd = GetQuoteEnd( rStr, nPos )) < nLen ) - { - aTmp += rStr.Copy( nStartPos, ++nEnd - nStartPos ); - nStartPos = nEnd; - } - else - { - aTmp += rStr.Copy( nStartPos, nPos - nStartPos ); - nStartPos = nPos + 2; - xub_StrLen nDash; - nEnd = nStartPos - 1; - do - { - nDash = rStr.Search( '-', ++nEnd ); - } while ( (nEnd = GetQuoteEnd( rStr, nDash )) < nLen ); - xub_StrLen nClose; - nEnd = nStartPos - 1; - do - { - nClose = rStr.Search( ']', ++nEnd ); - } while ( (nEnd = GetQuoteEnd( rStr, nClose )) < nLen ); - nPos = ( nDash < nClose ? nDash : nClose ); - if ( !bQuoteSymbol || rStr.GetChar( nStartPos ) == '"' ) - aTmp += rStr.Copy( nStartPos, nPos - nStartPos ); - else - { - aTmp += '"'; - aTmp += rStr.Copy( nStartPos, nPos - nStartPos ); - aTmp += '"'; - } - nStartPos = nClose + 1; - } - } - if ( nLen > nStartPos ) - aTmp += rStr.Copy( nStartPos, nLen - nStartPos ); - return aTmp; -} - -void SvNumberformat::Build50Formatstring( String& rStr ) const -{ - rStr = StripNewCurrencyDelimiters( sFormatstring, sal_True ); -} - -void SvNumberformat::ImpGetOutputStandard(double& fNumber, String& OutString) -{ - sal_uInt16 nStandardPrec = rScan.GetStandardPrec(); - - if ( fabs(fNumber) > 1.0E15 ) // #58531# war E16 - { - nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals - OutString = ::rtl::math::doubleToUString( fNumber, - rtl_math_StringFormat_E, nStandardPrec /*2*/, - GetFormatter().GetNumDecimalSep().GetChar(0)); - } - else - ImpGetOutputStdToPrecision(fNumber, OutString, nStandardPrec); -} - -void SvNumberformat::ImpGetOutputStdToPrecision(double& rNumber, String& rOutString, sal_uInt16 nPrecision) const -{ - // Make sure the precision doesn't go over the maximum allowable precision. - nPrecision = ::std::min(UPPER_PRECISION, nPrecision); - -#if 0 -{ - // debugger test case for ANSI standard correctness - ::rtl::OUString aTest; - // expect 0.00123 OK - aTest = ::rtl::math::doubleToUString( 0.001234567, - rtl_math_StringFormat_G, 3, '.', sal_True ); - // expect 123 OK - aTest = ::rtl::math::doubleToUString( 123.4567, - rtl_math_StringFormat_G, 3, '.', sal_True ); - // expect 123.5 OK - aTest = ::rtl::math::doubleToUString( 123.4567, - rtl_math_StringFormat_G, 4, '.', sal_True ); - // expect 1e+03 (as 999.6 rounded to 3 significant digits results in - // 1000 with an exponent equal to significant digits) - // Currently (24-Jan-2003) we do fail in this case and output 1000 - // instead, negligible. - aTest = ::rtl::math::doubleToUString( 999.6, - rtl_math_StringFormat_G, 3, '.', sal_True ); - // expect what? result is 1.2e+004 - aTest = ::rtl::math::doubleToUString( 12345.6789, - rtl_math_StringFormat_G, -3, '.', sal_True ); -} -#endif - - // We decided to strip trailing zeros unconditionally, since binary - // double-precision rounding error makes it impossible to determine e.g. - // whether 844.10000000000002273737 is what the user has typed, or the - // user has typed 844.1 but IEEE 754 represents it that way internally. - - rOutString = ::rtl::math::doubleToUString( rNumber, - rtl_math_StringFormat_F, nPrecision /*2*/, - GetFormatter().GetNumDecimalSep().GetChar(0), true ); - if (rOutString.GetChar(0) == '-' && - rOutString.GetTokenCount('0') == rOutString.Len()) - rOutString.EraseLeadingChars('-'); // nicht -0 - - ImpTransliterate( rOutString, NumFor[0].GetNatNum() ); -} - -void SvNumberformat::ImpGetOutputInputLine(double fNumber, String& OutString) -{ - sal_Bool bModified = sal_False; - if ( (eType & NUMBERFORMAT_PERCENT) && (fabs(fNumber) < _D_MAX_D_BY_100)) - { - if (fNumber == 0.0) - { - OutString.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "0%" ) ); - return; - } - fNumber *= 100; - bModified = sal_True; - } - - if (fNumber == 0.0) - { - OutString = '0'; - return; - } - - OutString = ::rtl::math::doubleToUString( fNumber, - rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, - GetFormatter().GetNumDecimalSep().GetChar(0), sal_True ); - - if ( eType & NUMBERFORMAT_PERCENT && bModified) - OutString += '%'; - return; -} - -short SvNumberformat::ImpCheckCondition(double& fNumber, - double& fLimit, - SvNumberformatLimitOps eOp) -{ - switch(eOp) - { - case NUMBERFORMAT_OP_NO: return -1; - case NUMBERFORMAT_OP_EQ: return (short) (fNumber == fLimit); - case NUMBERFORMAT_OP_NE: return (short) (fNumber != fLimit); - case NUMBERFORMAT_OP_LT: return (short) (fNumber < fLimit); - case NUMBERFORMAT_OP_LE: return (short) (fNumber <= fLimit); - case NUMBERFORMAT_OP_GT: return (short) (fNumber > fLimit); - case NUMBERFORMAT_OP_GE: return (short) (fNumber >= fLimit); - default: return -1; - } -} - -sal_Bool SvNumberformat::GetOutputString(String& sString, - String& OutString, - Color** ppColor) -{ - OutString.Erase(); - sal_uInt16 nIx; - if (eType & NUMBERFORMAT_TEXT) - nIx = 0; - else if (NumFor[3].GetCount() > 0) - nIx = 3; - else - { - *ppColor = NULL; // no change of color - return sal_False; - } - *ppColor = NumFor[nIx].GetColor(); - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - if (rInfo.eScannedType == NUMBERFORMAT_TEXT) - { - sal_Bool bRes = sal_False; - const sal_uInt16 nAnz = NumFor[nIx].GetCount(); - for (sal_uInt16 i = 0; i < nAnz; i++) - { - switch (rInfo.nTypeArray[i]) - { - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - OutString += (sal_Unicode) 0x1B; - OutString += rInfo.sStrArray[i].GetChar(1); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - InsertBlanks( OutString, OutString.Len(), - rInfo.sStrArray[i].GetChar(1) ); - break; - case NF_KEY_GENERAL : // #77026# "General" is the same as "@" - case NF_SYMBOLTYPE_DEL : - OutString += sString; - break; - default: - OutString += rInfo.sStrArray[i]; - } - } - return bRes; - } - return sal_False; -} - -sal_uLong SvNumberformat::ImpGGT(sal_uLong x, sal_uLong y) -{ - if (y == 0) - return x; - else - { - sal_uLong z = x%y; - while (z) - { - x = y; - y = z; - z = x%y; - } - return y; - } -} - -sal_uLong SvNumberformat::ImpGGTRound(sal_uLong x, sal_uLong y) -{ - if (y == 0) - return x; - else - { - sal_uLong z = x%y; - while ((double)z/(double)y > D_EPS) - { - x = y; - y = z; - z = x%y; - } - return y; - } -} - -namespace { - -void lcl_GetOutputStringScientific( - double fNumber, sal_uInt16 nCharCount, const SvNumberFormatter& rFormatter, String& rOutString) -{ - bool bSign = ::rtl::math::isSignBitSet(fNumber); - - // 1.000E+015 (one digit and the decimal point, and the five chars for the exponential part, totalling 7). - sal_uInt16 nPrec = nCharCount > 7 ? nCharCount - 7 : 0; - if (nPrec && bSign) - // Make room for the negative sign. - --nPrec; - - nPrec = ::std::min(nPrec, static_cast<sal_uInt16>(14)); // limit to 14 decimals. - - rOutString = ::rtl::math::doubleToUString( - fNumber, rtl_math_StringFormat_E, nPrec, rFormatter.GetNumDecimalSep().GetChar(0)); -} - -sal_Int32 lcl_GetForcedDenominator(ImpSvNumberformatInfo &rInfo, sal_uInt16 nAnz) -{ - sal_uInt16 i; - rtl::OUString aDiv; - for( i = 0; i < nAnz; i++ ) - { - if( rInfo.nTypeArray[i] == NF_SYMBOLTYPE_FRAC_FDIV ) - aDiv += rInfo.sStrArray[i]; - } - return aDiv.toInt32(); -} - -// TODO: More optimizations? -void lcl_ForcedDenominator(sal_uLong &nFrac, sal_uLong &nDiv, sal_uLong nForcedDiv) -{ - double fFrac = (double)nFrac / (double)nDiv; - double fMultiplier = (double)nForcedDiv / (double)nDiv; - nFrac = (sal_uLong)( (double)nFrac * fMultiplier ); - - double fFracNew = (double)nFrac / (double)nForcedDiv; - double fFracNew1 = (double)(nFrac + 1) / (double)nForcedDiv; - double fDiff = fFrac - fFracNew; - if( fDiff > ( fFracNew1 - fFrac ) ) - nFrac++; - nDiv = nForcedDiv; -} - -} - -bool SvNumberformat::GetOutputString(double fNumber, sal_uInt16 nCharCount, String& rOutString) const -{ - using namespace std; - - if (eType != NUMBERFORMAT_NUMBER) - return false; - - double fTestNum = fNumber; - bool bSign = ::rtl::math::isSignBitSet(fTestNum); - if (bSign) - fTestNum = -fTestNum; - - if (fTestNum < EXP_LOWER_BOUND) - { - lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString); - return true; - } - - double fExp = log10(fTestNum); - // Values < 1.0 always have one digit before the decimal point. - sal_uInt16 nDigitPre = fExp >= 0.0 ? static_cast<sal_uInt16>(ceil(fExp)) : 1; - - if (nDigitPre > 15) - { - lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString); - return true; - } - - sal_uInt16 nPrec = nCharCount >= nDigitPre ? nCharCount - nDigitPre : 0; - if (nPrec && bSign) - // Subtract the negative sign. - --nPrec; - if (nPrec) - // Subtract the decimal point. - --nPrec; - - ImpGetOutputStdToPrecision(fNumber, rOutString, nPrec); - if (rOutString.Len() > nCharCount) - // String still wider than desired. Switch to scientific notation. - lcl_GetOutputStringScientific(fNumber, nCharCount, GetFormatter(), rOutString); - - return true; -} - -sal_Bool SvNumberformat::GetOutputString(double fNumber, - String& OutString, - Color** ppColor) -{ - sal_Bool bRes = sal_False; - OutString.Erase(); // alles loeschen - *ppColor = NULL; // keine Farbaenderung - if (eType & NUMBERFORMAT_LOGICAL) - { - if (fNumber) - OutString = rScan.GetTrueString(); - else - OutString = rScan.GetFalseString(); - return sal_False; - } - if (eType & NUMBERFORMAT_TEXT) - { - ImpGetOutputStandard(fNumber, OutString); - return sal_False; - } - sal_Bool bHadStandard = sal_False; - if (bStandard) // einzelne Standardformate - { - if (rScan.GetStandardPrec() == SvNumberFormatter::INPUTSTRING_PRECISION) // alle Zahlformate InputLine - { - ImpGetOutputInputLine(fNumber, OutString); - return false; - } - switch (eType) - { - case NUMBERFORMAT_NUMBER: // Standardzahlformat - { - if (rScan.GetStandardPrec() == SvNumberFormatter::UNLIMITED_PRECISION) - { - bool bSign = ::rtl::math::isSignBitSet(fNumber); - if (bSign) - fNumber = -fNumber; - ImpGetOutputStdToPrecision(fNumber, OutString, 10); // Use 10 decimals for general 'unlimited' format. - if (fNumber < EXP_LOWER_BOUND) - { - xub_StrLen nLen = OutString.Len(); - if (!nLen) - return false; - - // #i112250# With the 10-decimal limit, small numbers are formatted as "0". - // Switch to scientific in that case, too: - if (nLen > 11 || (OutString.EqualsAscii("0") && fNumber != 0.0)) - { - sal_uInt16 nStandardPrec = rScan.GetStandardPrec(); - nStandardPrec = ::std::min(nStandardPrec, static_cast<sal_uInt16>(14)); // limits to 14 decimals - OutString = ::rtl::math::doubleToUString( fNumber, - rtl_math_StringFormat_E, nStandardPrec /*2*/, - GetFormatter().GetNumDecimalSep().GetChar(0), true); - } - } - if (bSign) - OutString.Insert('-', 0); - return false; - } - ImpGetOutputStandard(fNumber, OutString); - bHadStandard = sal_True; - } - break; - case NUMBERFORMAT_DATE: - bRes |= ImpGetDateOutput(fNumber, 0, OutString); - bHadStandard = sal_True; - break; - case NUMBERFORMAT_TIME: - bRes |= ImpGetTimeOutput(fNumber, 0, OutString); - bHadStandard = sal_True; - break; - case NUMBERFORMAT_DATETIME: - bRes |= ImpGetDateTimeOutput(fNumber, 0, OutString); - bHadStandard = sal_True; - break; - } - } - if ( !bHadStandard ) - { - sal_uInt16 nIx; // Index des Teilformats - short nCheck = ImpCheckCondition(fNumber, fLimit1, eOp1); - if (nCheck == -1 || nCheck == 1) // nur 1 String oder True - nIx = 0; - else - { - nCheck = ImpCheckCondition(fNumber, fLimit2, eOp2); - if (nCheck == -1 || nCheck == 1) - nIx = 1; - else - nIx = 2; - } - if (nIx == 1 && fNumber < 0.0 && // negatives Format - IsNegativeRealNegative() ) // ohne Vorzeichen - fNumber = -fNumber; // Vorzeichen eliminieren - *ppColor = NumFor[nIx].GetColor(); - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - const sal_uInt16 nAnz = NumFor[nIx].GetCount(); - if (nAnz == 0 && rInfo.eScannedType == NUMBERFORMAT_UNDEFINED) - return sal_False; // leer => nichts - else if (nAnz == 0) // sonst Standard-Format - { - ImpGetOutputStandard(fNumber, OutString); - return sal_False; - } - switch (rInfo.eScannedType) - { - case NUMBERFORMAT_TEXT: - case NUMBERFORMAT_DEFINED: - { - for (sal_uInt16 i = 0; i < nAnz; i++) - { - switch (rInfo.nTypeArray[i]) - { - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - OutString += (sal_Unicode) 0x1B; - OutString += rInfo.sStrArray[i].GetChar(1); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - InsertBlanks( OutString, OutString.Len(), - rInfo.sStrArray[i].GetChar(1) ); - break; - case NF_SYMBOLTYPE_STRING: - case NF_SYMBOLTYPE_CURRENCY: - OutString += rInfo.sStrArray[i]; - break; - case NF_SYMBOLTYPE_THSEP: - if (rInfo.nThousand == 0) - OutString += rInfo.sStrArray[i]; - break; - default: - break; - } - } - } - break; - case NUMBERFORMAT_DATE: - bRes |= ImpGetDateOutput(fNumber, nIx, OutString); - break; - case NUMBERFORMAT_TIME: - bRes |= ImpGetTimeOutput(fNumber, nIx, OutString); - break; - case NUMBERFORMAT_DATETIME: - bRes |= ImpGetDateTimeOutput(fNumber, nIx, OutString); - break; - case NUMBERFORMAT_NUMBER: - case NUMBERFORMAT_PERCENT: - case NUMBERFORMAT_CURRENCY: - bRes |= ImpGetNumberOutput(fNumber, nIx, OutString); - break; - case NUMBERFORMAT_FRACTION: - { - String sStr, sFrac, sDiv; // Strings, Wert fuer - sal_uLong nFrac, nDiv; // Vorkommaanteil - // Zaehler und Nenner - sal_Bool bSign = sal_False; - if (fNumber < 0) - { - if (nIx == 0) // nicht in hinteren - bSign = sal_True; // Formaten - fNumber = -fNumber; - } - double fNum = floor(fNumber); // Vorkommateil - fNumber -= fNum; // Nachkommateil - if (fNum > _D_MAX_U_LONG_ || rInfo.nCntExp > 9) - // zu gross - { - OutString = rScan.GetErrorString(); - return sal_False; - } - if (rInfo.nCntExp == 0) - { - OSL_FAIL("SvNumberformat:: Bruch, nCntExp == 0"); - return sal_False; - } - sal_uLong nBasis = ((sal_uLong)floor( // 9, 99, 999 ,... - pow(10.0,rInfo.nCntExp))) - 1; - sal_uLong x0, y0, x1, y1; - - if (rInfo.nCntExp <= _MAX_FRACTION_PREC) - { - sal_Bool bUpperHalf; - if (fNumber > 0.5) - { - bUpperHalf = sal_True; - fNumber -= (fNumber - 0.5) * 2.0; - } - else - bUpperHalf = sal_False; - // Einstieg in Farey-Serie - // finden: - x0 = (sal_uLong) floor(fNumber*nBasis); // z.B. 2/9 <= x < 3/9 - if (x0 == 0) // => x0 = 2 - { - y0 = 1; - x1 = 1; - y1 = nBasis; - } - else if (x0 == (nBasis-1)/2) // (b-1)/2, 1/2 - { // geht (nBasis ungerade) - y0 = nBasis; - x1 = 1; - y1 = 2; - } - else if (x0 == 1) - { - y0 = nBasis; // 1/n; 1/(n-1) - x1 = 1; - y1 = nBasis - 1; - } - else - { - y0 = nBasis; // z.B. 2/9 2/8 - x1 = x0; - y1 = nBasis - 1; - double fUg = (double) x0 / (double) y0; - double fOg = (double) x1 / (double) y1; - sal_uLong nGgt = ImpGGT(y0, x0); // x0/y0 kuerzen - x0 /= nGgt; - y0 /= nGgt; // Einschachteln: - sal_uLong x2 = 0; - sal_uLong y2 = 0; - sal_Bool bStop = sal_False; - while (!bStop) - { -#ifdef GCC - // #i21648# GCC over-optimizes something resulting - // in wrong fTest values throughout the loops. - volatile -#endif - double fTest = (double)x1/(double)y1; - while (!bStop) - { - while (fTest > fOg) - { - x1--; - fTest = (double)x1/(double)y1; - } - while (fTest < fUg && y1 > 1) - { - y1--; - fTest = (double)x1/(double)y1; - } - if (fTest <= fOg) - { - fOg = fTest; - bStop = sal_True; - } - else if (y1 == 1) - bStop = sal_True; - } // of while - nGgt = ImpGGT(y1, x1); // x1/y1 kuerzen - x2 = x1 / nGgt; - y2 = y1 / nGgt; - if (x2*y0 - x0*y2 == 1 || y1 <= 1) // Test, ob x2/y2 - bStop = sal_True; // naechste Farey-Zahl - else - { - y1--; - bStop = sal_False; - } - } // of while - x1 = x2; - y1 = y2; - } // of else - double fup, flow; - flow = (double)x0/(double)y0; - fup = (double)x1/(double)y1; - while (fNumber > fup) - { - sal_uLong x2 = ((y0+nBasis)/y1)*x1 - x0; // naechste Farey-Zahl - sal_uLong y2 = ((y0+nBasis)/y1)*y1 - y0; - x0 = x1; - y0 = y1; - x1 = x2; - y1 = y2; - flow = fup; - fup = (double)x1/(double)y1; - } - if (fNumber - flow < fup - fNumber) - { - nFrac = x0; - nDiv = y0; - } - else - { - nFrac = x1; - nDiv = y1; - } - if (bUpperHalf) // Original restaur. - { - if (nFrac == 0 && nDiv == 1) // 1/1 - fNum += 1.0; - else - nFrac = nDiv - nFrac; - } - } - else // grosse Nenner - { // 0,1234->123/1000 - sal_uLong nGgt; - nDiv = 10000000; - nFrac = ((sal_uLong)floor(0.5 + fNumber * 10000000.0)); - nGgt = ImpGGT(nDiv, nFrac); - if (nGgt > 1) - { - nDiv /= nGgt; - nFrac /= nGgt; - } - if (nDiv > nBasis) - { - nGgt = ImpGGTRound(nDiv, nFrac); - if (nGgt > 1) - { - nDiv /= nGgt; - nFrac /= nGgt; - } - } - if (nDiv > nBasis) - { - nDiv = nBasis; - nFrac = ((sal_uLong)floor(0.5 + fNumber * - pow(10.0,rInfo.nCntExp))); - nGgt = ImpGGTRound(nDiv, nFrac); - if (nGgt > 1) - { - nDiv /= nGgt; - nFrac /= nGgt; - } - } - } - - if( sal_Int32 nForcedDiv = lcl_GetForcedDenominator(NumFor[nIx].Info(), nAnz) ) - { - lcl_ForcedDenominator(nFrac, nDiv, nForcedDiv); - if( nFrac >= nDiv ) - { - nFrac = nDiv = 0; - fNum = fNum + 1.0; - } - } - - if (rInfo.nCntPre == 0) // unechter Bruch - { - double fNum1 = fNum * (double)nDiv + (double)nFrac; - if (fNum1 > _D_MAX_U_LONG_) - { - OutString = rScan.GetErrorString(); - return sal_False; - } - nFrac = (sal_uLong) floor(fNum1); - sStr.Erase(); - } - else if (fNum == 0.0 && nFrac != 0) - sStr.Erase(); - else - { - char aBuf[100]; - sprintf( aBuf, "%.f", fNum ); // simple rounded integer (#100211# - checked) - sStr.AssignAscii( aBuf ); - ImpTransliterate( sStr, NumFor[nIx].GetNatNum() ); - } - if (rInfo.nCntPre > 0 && nFrac == 0) - { - sFrac.Erase(); - sDiv.Erase(); - } - else - { - sFrac = ImpIntToString( nIx, nFrac ); - sDiv = ImpIntToString( nIx, nDiv ); - } - - sal_uInt16 j = nAnz-1; // letztes Symbol->rueckw. - xub_StrLen k; // Nenner: - bRes |= ImpNumberFill(sDiv, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRAC); - sal_Bool bCont = sal_True; - if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_FRAC) - { - if (rInfo.nCntPre > 0 && nFrac == 0) - sDiv.Insert(' ',0); - else - sDiv.Insert( rInfo.sStrArray[j].GetChar(0), 0 ); - if ( j ) - j--; - else - bCont = sal_False; - } - // weiter Zaehler: - if ( !bCont ) - sFrac.Erase(); - else - { - bRes |= ImpNumberFill(sFrac, fNumber, k, j, nIx, NF_SYMBOLTYPE_FRACBLANK); - if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_FRACBLANK) - { - sFrac.Insert(rInfo.sStrArray[j],0); - if ( j ) - j--; - else - bCont = sal_False; - } - } - // weiter Hauptzahl - if ( !bCont ) - sStr.Erase(); - else - { - k = sStr.Len(); // hinter letzter Ziffer - bRes |= ImpNumberFillWithThousands(sStr, fNumber, k, j, nIx, - rInfo.nCntPre); - } - if (bSign && !(nFrac == 0 && fNum == 0.0)) - OutString.Insert('-',0); // nicht -0 - OutString += sStr; - OutString += sFrac; - OutString += sDiv; - } - break; - case NUMBERFORMAT_SCIENTIFIC: - { - sal_Bool bSign = sal_False; - if (fNumber < 0) - { - if (nIx == 0) // nicht in hinteren - bSign = sal_True; // Formaten - fNumber = -fNumber; - } - String sStr( ::rtl::math::doubleToUString( fNumber, - rtl_math_StringFormat_E, - rInfo.nCntPre + rInfo.nCntPost - 1, '.' )); - - String ExpStr; - short nExpSign = 1; - xub_StrLen nExPos = sStr.Search('E'); - if ( nExPos != STRING_NOTFOUND ) - { - // split into mantisse and exponent and get rid of "E+" or "E-" - xub_StrLen nExpStart = nExPos + 1; - switch ( sStr.GetChar( nExpStart ) ) - { - case '-' : - nExpSign = -1; - // fallthru - case '+' : - ++nExpStart; - break; - } - ExpStr = sStr.Copy( nExpStart ); // part following the "E+" - sStr.Erase( nExPos ); - sStr.EraseAllChars('.'); // cut any decimal delimiter - if ( rInfo.nCntPre != 1 ) // rescale Exp - { - sal_Int32 nExp = ExpStr.ToInt32() * nExpSign; - nExp -= sal_Int32(rInfo.nCntPre)-1; - if ( nExp < 0 ) - { - nExpSign = -1; - nExp = -nExp; - } - else - nExpSign = 1; - ExpStr = String::CreateFromInt32( nExp ); - } - } - sal_uInt16 j = nAnz-1; // last symbol - xub_StrLen k; // position in ExpStr - bRes |= ImpNumberFill(ExpStr, fNumber, k, j, nIx, NF_SYMBOLTYPE_EXP); - - xub_StrLen nZeros = 0; // erase leading zeros - while (nZeros < k && ExpStr.GetChar(nZeros) == '0') - ++nZeros; - if (nZeros) - ExpStr.Erase( 0, nZeros); - - sal_Bool bCont = sal_True; - if (rInfo.nTypeArray[j] == NF_SYMBOLTYPE_EXP) - { - const String& rStr = rInfo.sStrArray[j]; - if (nExpSign == -1) - ExpStr.Insert('-',0); - else if (rStr.Len() > 1 && rStr.GetChar(1) == '+') - ExpStr.Insert('+',0); - ExpStr.Insert(rStr.GetChar(0),0); - if ( j ) - j--; - else - bCont = sal_False; - } - // weiter Hauptzahl: - if ( !bCont ) - sStr.Erase(); - else - { - k = sStr.Len(); // hinter letzter Ziffer - bRes |= ImpNumberFillWithThousands(sStr,fNumber, k,j,nIx, - rInfo.nCntPre + - rInfo.nCntPost); - } - if (bSign) - sStr.Insert('-',0); - OutString = sStr; - OutString += ExpStr; - } - break; - } - } - return bRes; -} - -sal_Bool SvNumberformat::ImpGetTimeOutput(double fNumber, - sal_uInt16 nIx, - String& OutString) -{ - using namespace ::com::sun::star::i18n; - sal_Bool bCalendarSet = sal_False; - double fNumberOrig = fNumber; - sal_Bool bRes = sal_False; - sal_Bool bSign = sal_False; - if (fNumber < 0.0) - { - fNumber = -fNumber; - if (nIx == 0) - bSign = sal_True; - } - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - if (rInfo.bThousand) // []-Format - { - if (fNumber > 1.0E10) // zu gross - { - OutString = rScan.GetErrorString(); - return sal_False; - } - } - else - fNumber -= floor(fNumber); // sonst Datum abtrennen - sal_Bool bInputLine; - xub_StrLen nCntPost; - if ( rScan.GetStandardPrec() == 300 && - 0 < rInfo.nCntPost && rInfo.nCntPost < 7 ) - { // round at 7 decimals (+5 of 86400 == 12 significant digits) - bInputLine = sal_True; - nCntPost = 7; - } - else - { - bInputLine = sal_False; - nCntPost = xub_StrLen(rInfo.nCntPost); - } - if (bSign && !rInfo.bThousand) // kein []-Format - fNumber = 1.0 - fNumber; // "Kehrwert" - double fTime = fNumber * 86400.0; - fTime = ::rtl::math::round( fTime, int(nCntPost) ); - if (bSign && fTime == 0.0) - bSign = sal_False; // nicht -00:00:00 - - if( floor( fTime ) > _D_MAX_U_LONG_ ) - { - OutString = rScan.GetErrorString(); - return sal_False; - } - sal_uLong nSeconds = (sal_uLong)floor( fTime ); - - String sSecStr( ::rtl::math::doubleToUString( fTime-nSeconds, - rtl_math_StringFormat_F, int(nCntPost), '.')); - sSecStr.EraseLeadingChars('0'); - sSecStr.EraseLeadingChars('.'); - if ( bInputLine ) - { - sSecStr.EraseTrailingChars('0'); - if ( sSecStr.Len() < xub_StrLen(rInfo.nCntPost) ) - sSecStr.Expand( xub_StrLen(rInfo.nCntPost), '0' ); - ImpTransliterate( sSecStr, NumFor[nIx].GetNatNum() ); - nCntPost = sSecStr.Len(); - } - else - ImpTransliterate( sSecStr, NumFor[nIx].GetNatNum() ); - - xub_StrLen nSecPos = 0; // Zum Ziffernweisen - // abarbeiten - sal_uLong nHour, nMin, nSec; - if (!rInfo.bThousand) // kein [] Format - { - nHour = (nSeconds/3600) % 24; - nMin = (nSeconds%3600) / 60; - nSec = nSeconds%60; - } - else if (rInfo.nThousand == 3) // [ss] - { - nHour = 0; - nMin = 0; - nSec = nSeconds; - } - else if (rInfo.nThousand == 2) // [mm]:ss - { - nHour = 0; - nMin = nSeconds / 60; - nSec = nSeconds % 60; - } - else if (rInfo.nThousand == 1) // [hh]:mm:ss - { - nHour = nSeconds / 3600; - nMin = (nSeconds%3600) / 60; - nSec = nSeconds%60; - } - else { - // TODO What should these be set to? - nHour = 0; - nMin = 0; - nSec = 0; - } - - sal_Unicode cAmPm = ' '; // a oder p - if (rInfo.nCntExp) // AM/PM - { - if (nHour == 0) - { - nHour = 12; - cAmPm = 'a'; - } - else if (nHour < 12) - cAmPm = 'a'; - else - { - cAmPm = 'p'; - if (nHour > 12) - nHour -= 12; - } - } - const sal_uInt16 nAnz = NumFor[nIx].GetCount(); - for (sal_uInt16 i = 0; i < nAnz; i++) - { - switch (rInfo.nTypeArray[i]) - { - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - OutString += (sal_Unicode) 0x1B; - OutString += rInfo.sStrArray[i].GetChar(1); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - InsertBlanks( OutString, OutString.Len(), - rInfo.sStrArray[i].GetChar(1) ); - break; - case NF_SYMBOLTYPE_STRING: - case NF_SYMBOLTYPE_CURRENCY: - case NF_SYMBOLTYPE_DATESEP: - case NF_SYMBOLTYPE_TIMESEP: - case NF_SYMBOLTYPE_TIME100SECSEP: - OutString += rInfo.sStrArray[i]; - break; - case NF_SYMBOLTYPE_DIGIT: - { - xub_StrLen nLen = ( bInputLine && i > 0 && - (rInfo.nTypeArray[i-1] == NF_SYMBOLTYPE_STRING || - rInfo.nTypeArray[i-1] == NF_SYMBOLTYPE_TIME100SECSEP) ? - nCntPost : rInfo.sStrArray[i].Len() ); - for (xub_StrLen j = 0; j < nLen && nSecPos < nCntPost; j++) - { - OutString += sSecStr.GetChar(nSecPos); - nSecPos++; - } - } - break; - case NF_KEY_AMPM: // AM/PM - { - if ( !bCalendarSet ) - { - double fDiff = DateTime(*(rScan.GetNullDate())) - GetCal().getEpochStart(); - fDiff += fNumberOrig; - GetCal().setLocalDateTime( fDiff ); - bCalendarSet = sal_True; - } - if (cAmPm == 'a') - OutString += GetCal().getDisplayName( - CalendarDisplayIndex::AM_PM, AmPmValue::AM, 0 ); - else - OutString += GetCal().getDisplayName( - CalendarDisplayIndex::AM_PM, AmPmValue::PM, 0 ); - } - break; - case NF_KEY_AP: // A/P - { - if (cAmPm == 'a') - OutString += 'a'; - else - OutString += 'p'; - } - break; - case NF_KEY_MI: // M - OutString += ImpIntToString( nIx, nMin ); - break; - case NF_KEY_MMI: // MM - OutString += ImpIntToString( nIx, nMin, 2 ); - break; - case NF_KEY_H: // H - OutString += ImpIntToString( nIx, nHour ); - break; - case NF_KEY_HH: // HH - OutString += ImpIntToString( nIx, nHour, 2 ); - break; - case NF_KEY_S: // S - OutString += ImpIntToString( nIx, nSec ); - break; - case NF_KEY_SS: // SS - OutString += ImpIntToString( nIx, nSec, 2 ); - break; - default: - break; - } - } - if (bSign && rInfo.bThousand) - OutString.Insert('-',0); - return bRes; -} - -sal_Bool SvNumberformat::ImpIsOtherCalendar( const ImpSvNumFor& rNumFor ) const -{ - if ( GetCal().getUniqueID() != Gregorian::get() ) - return sal_False; - const ImpSvNumberformatInfo& rInfo = rNumFor.Info(); - const sal_uInt16 nAnz = rNumFor.GetCount(); - sal_uInt16 i; - for ( i = 0; i < nAnz; i++ ) - { - switch ( rInfo.nTypeArray[i] ) - { - case NF_SYMBOLTYPE_CALENDAR : - return sal_False; - case NF_KEY_EC : - case NF_KEY_EEC : - case NF_KEY_R : - case NF_KEY_RR : - case NF_KEY_AAA : - case NF_KEY_AAAA : - return sal_True; - } - } - return sal_False; -} - -void SvNumberformat::SwitchToOtherCalendar( String& rOrgCalendar, - double& fOrgDateTime ) const -{ - CalendarWrapper& rCal = GetCal(); - const rtl::OUString &rGregorian = Gregorian::get(); - if ( rCal.getUniqueID() == rGregorian ) - { - using namespace ::com::sun::star::i18n; - ::com::sun::star::uno::Sequence< ::rtl::OUString > xCals - = rCal.getAllCalendars( rLoc().getLocale() ); - sal_Int32 nCnt = xCals.getLength(); - if ( nCnt > 1 ) - { - for ( sal_Int32 j=0; j < nCnt; j++ ) - { - if ( xCals[j] != rGregorian ) - { - if ( !rOrgCalendar.Len() ) - { - rOrgCalendar = rCal.getUniqueID(); - fOrgDateTime = rCal.getDateTime(); - } - rCal.loadCalendar( xCals[j], rLoc().getLocale() ); - rCal.setDateTime( fOrgDateTime ); - break; // for - } - } - } - } -} - -void SvNumberformat::SwitchToGregorianCalendar( const String& rOrgCalendar, - double fOrgDateTime ) const -{ - CalendarWrapper& rCal = GetCal(); - const rtl::OUString &rGregorian = Gregorian::get(); - if ( rOrgCalendar.Len() && rCal.getUniqueID() != rGregorian ) - { - rCal.loadCalendar( rGregorian, rLoc().getLocale() ); - rCal.setDateTime( fOrgDateTime ); - } -} - -sal_Bool SvNumberformat::ImpFallBackToGregorianCalendar( String& rOrgCalendar, double& fOrgDateTime ) -{ - using namespace ::com::sun::star::i18n; - CalendarWrapper& rCal = GetCal(); - const rtl::OUString &rGregorian = Gregorian::get(); - if ( rCal.getUniqueID() != rGregorian ) - { - sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::ERA ); - if ( nVal == 0 && rCal.getLoadedCalendar().Eras[0].ID.equalsAsciiL( - RTL_CONSTASCII_STRINGPARAM( "Dummy" ) ) ) - { - if ( !rOrgCalendar.Len() ) - { - rOrgCalendar = rCal.getUniqueID(); - fOrgDateTime = rCal.getDateTime(); - } - else if ( rOrgCalendar == String(rGregorian) ) - rOrgCalendar.Erase(); - rCal.loadCalendar( rGregorian, rLoc().getLocale() ); - rCal.setDateTime( fOrgDateTime ); - return sal_True; - } - } - return sal_False; -} - -sal_Bool SvNumberformat::ImpSwitchToSpecifiedCalendar( String& rOrgCalendar, - double& fOrgDateTime, const ImpSvNumFor& rNumFor ) const -{ - const ImpSvNumberformatInfo& rInfo = rNumFor.Info(); - const sal_uInt16 nAnz = rNumFor.GetCount(); - for ( sal_uInt16 i = 0; i < nAnz; i++ ) - { - if ( rInfo.nTypeArray[i] == NF_SYMBOLTYPE_CALENDAR ) - { - CalendarWrapper& rCal = GetCal(); - if ( !rOrgCalendar.Len() ) - { - rOrgCalendar = rCal.getUniqueID(); - fOrgDateTime = rCal.getDateTime(); - } - rCal.loadCalendar( rInfo.sStrArray[i], rLoc().getLocale() ); - rCal.setDateTime( fOrgDateTime ); - return sal_True; - } - } - return sal_False; -} - -// static -void SvNumberformat::ImpAppendEraG( String& OutString, - const CalendarWrapper& rCal, sal_Int16 nNatNum ) -{ - using namespace ::com::sun::star::i18n; - if ( rCal.getUniqueID().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "gengou" ) ) ) - { - sal_Unicode cEra; - sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::ERA ); - switch ( nVal ) - { - case 1 : cEra = 'M'; break; - case 2 : cEra = 'T'; break; - case 3 : cEra = 'S'; break; - case 4 : cEra = 'H'; break; - default: - cEra = '?'; - } - OutString += cEra; - } - else - OutString += rCal.getDisplayString( CalendarDisplayCode::SHORT_ERA, nNatNum ); -} - -sal_Bool SvNumberformat::ImpGetDateOutput(double fNumber, - sal_uInt16 nIx, - String& OutString) -{ - using namespace ::com::sun::star::i18n; - sal_Bool bRes = sal_False; - CalendarWrapper& rCal = GetCal(); - double fDiff = DateTime(*(rScan.GetNullDate())) - rCal.getEpochStart(); - fNumber += fDiff; - rCal.setLocalDateTime( fNumber ); - String aOrgCalendar; // empty => not changed yet - double fOrgDateTime; - sal_Bool bOtherCalendar = ImpIsOtherCalendar( NumFor[nIx] ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - if ( ImpFallBackToGregorianCalendar( aOrgCalendar, fOrgDateTime ) ) - bOtherCalendar = sal_False; - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - const sal_uInt16 nAnz = NumFor[nIx].GetCount(); - sal_Int16 nNatNum = NumFor[nIx].GetNatNum().GetNatNum(); - for (sal_uInt16 i = 0; i < nAnz; i++) - { - switch (rInfo.nTypeArray[i]) - { - case NF_SYMBOLTYPE_CALENDAR : - if ( !aOrgCalendar.Len() ) - { - aOrgCalendar = rCal.getUniqueID(); - fOrgDateTime = rCal.getDateTime(); - } - rCal.loadCalendar( rInfo.sStrArray[i], rLoc().getLocale() ); - rCal.setDateTime( fOrgDateTime ); - ImpFallBackToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - break; - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - OutString += (sal_Unicode) 0x1B; - OutString += rInfo.sStrArray[i].GetChar(1); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - InsertBlanks( OutString, OutString.Len(), - rInfo.sStrArray[i].GetChar(1) ); - break; - case NF_SYMBOLTYPE_STRING: - case NF_SYMBOLTYPE_CURRENCY: - case NF_SYMBOLTYPE_DATESEP: - case NF_SYMBOLTYPE_TIMESEP: - case NF_SYMBOLTYPE_TIME100SECSEP: - OutString += rInfo.sStrArray[i]; - break; - case NF_KEY_M: // M - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_MONTH, nNatNum ); - break; - case NF_KEY_MM: // MM - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_MONTH, nNatNum ); - break; - case NF_KEY_MMM: // MMM - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_MONTH_NAME, nNatNum ); - break; - case NF_KEY_MMMM: // MMMM - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_MONTH_NAME, nNatNum ); - break; - case NF_KEY_MMMMM: // MMMMM - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_MONTH_NAME, nNatNum ).GetChar(0); - break; - case NF_KEY_Q: // Q - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_QUARTER, nNatNum ); - break; - case NF_KEY_QQ: // QQ - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_QUARTER, nNatNum ); - break; - case NF_KEY_D: // D - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_DAY, nNatNum ); - break; - case NF_KEY_DD: // DD - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY, nNatNum ); - break; - case NF_KEY_DDD: // DDD - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_DDDD: // DDDD - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_YY: // YY - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_YEAR, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_YYYY: // YYYY - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_YEAR, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_EC: // E - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_YEAR, nNatNum ); - break; - case NF_KEY_EEC: // EE - case NF_KEY_R: // R - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_YEAR, nNatNum ); - break; - case NF_KEY_NN: // NN - case NF_KEY_AAA: // AAA - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); - break; - case NF_KEY_NNN: // NNN - case NF_KEY_AAAA: // AAAA - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); - break; - case NF_KEY_NNNN: // NNNN - { - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); - OutString += rLoc().getLongDateDayOfWeekSep(); - } - break; - case NF_KEY_WW : // WW - { - sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::WEEK_OF_YEAR ); - OutString += ImpIntToString( nIx, nVal ); - } - break; - case NF_KEY_G: // G - ImpAppendEraG( OutString, rCal, nNatNum ); - break; - case NF_KEY_GG: // GG - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_ERA, nNatNum ); - break; - case NF_KEY_GGG: // GGG - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_ERA, nNatNum ); - break; - case NF_KEY_RR: // RR => GGGEE - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_YEAR_AND_ERA, nNatNum ); - break; - } - } - if ( aOrgCalendar.Len() ) - rCal.loadCalendar( aOrgCalendar, rLoc().getLocale() ); // restore calendar - return bRes; -} - -sal_Bool SvNumberformat::ImpGetDateTimeOutput(double fNumber, - sal_uInt16 nIx, - String& OutString) -{ - using namespace ::com::sun::star::i18n; - sal_Bool bRes = sal_False; - - CalendarWrapper& rCal = GetCal(); - double fDiff = DateTime(*(rScan.GetNullDate())) - rCal.getEpochStart(); - fNumber += fDiff; - - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - sal_Bool bInputLine; - xub_StrLen nCntPost; - if ( rScan.GetStandardPrec() == 300 && - 0 < rInfo.nCntPost && rInfo.nCntPost < 7 ) - { // round at 7 decimals (+5 of 86400 == 12 significant digits) - bInputLine = sal_True; - nCntPost = 7; - } - else - { - bInputLine = sal_False; - nCntPost = xub_StrLen(rInfo.nCntPost); - } - double fTime = (fNumber - floor( fNumber )) * 86400.0; - fTime = ::rtl::math::round( fTime, int(nCntPost) ); - if (fTime >= 86400.0) - { - // result of fNumber==x.999999999... rounded up, use correct date/time - fTime -= 86400.0; - fNumber = floor( fNumber + 0.5) + fTime; - } - rCal.setLocalDateTime( fNumber ); - - String aOrgCalendar; // empty => not changed yet - double fOrgDateTime; - sal_Bool bOtherCalendar = ImpIsOtherCalendar( NumFor[nIx] ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - if ( ImpFallBackToGregorianCalendar( aOrgCalendar, fOrgDateTime ) ) - bOtherCalendar = sal_False; - sal_Int16 nNatNum = NumFor[nIx].GetNatNum().GetNatNum(); - - sal_uLong nSeconds = (sal_uLong)floor( fTime ); - String sSecStr( ::rtl::math::doubleToUString( fTime-nSeconds, - rtl_math_StringFormat_F, int(nCntPost), '.')); - sSecStr.EraseLeadingChars('0'); - sSecStr.EraseLeadingChars('.'); - if ( bInputLine ) - { - sSecStr.EraseTrailingChars('0'); - if ( sSecStr.Len() < xub_StrLen(rInfo.nCntPost) ) - sSecStr.Expand( xub_StrLen(rInfo.nCntPost), '0' ); - ImpTransliterate( sSecStr, NumFor[nIx].GetNatNum() ); - nCntPost = sSecStr.Len(); - } - else - ImpTransliterate( sSecStr, NumFor[nIx].GetNatNum() ); - - xub_StrLen nSecPos = 0; // Zum Ziffernweisen - // abarbeiten - sal_uLong nHour, nMin, nSec; - if (!rInfo.bThousand) // [] Format - { - nHour = (nSeconds/3600) % 24; - nMin = (nSeconds%3600) / 60; - nSec = nSeconds%60; - } - else if (rInfo.nThousand == 3) // [ss] - { - nHour = 0; - nMin = 0; - nSec = nSeconds; - } - else if (rInfo.nThousand == 2) // [mm]:ss - { - nHour = 0; - nMin = nSeconds / 60; - nSec = nSeconds % 60; - } - else if (rInfo.nThousand == 1) // [hh]:mm:ss - { - nHour = nSeconds / 3600; - nMin = (nSeconds%3600) / 60; - nSec = nSeconds%60; - } - else { - nHour = 0; // TODO What should these values be? - nMin = 0; - nSec = 0; - } - sal_Unicode cAmPm = ' '; // a oder p - if (rInfo.nCntExp) // AM/PM - { - if (nHour == 0) - { - nHour = 12; - cAmPm = 'a'; - } - else if (nHour < 12) - cAmPm = 'a'; - else - { - cAmPm = 'p'; - if (nHour > 12) - nHour -= 12; - } - } - const sal_uInt16 nAnz = NumFor[nIx].GetCount(); - for (sal_uInt16 i = 0; i < nAnz; i++) - { - switch (rInfo.nTypeArray[i]) - { - case NF_SYMBOLTYPE_CALENDAR : - if ( !aOrgCalendar.Len() ) - { - aOrgCalendar = rCal.getUniqueID(); - fOrgDateTime = rCal.getDateTime(); - } - rCal.loadCalendar( rInfo.sStrArray[i], rLoc().getLocale() ); - rCal.setDateTime( fOrgDateTime ); - ImpFallBackToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - break; - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - OutString += (sal_Unicode) 0x1B; - OutString += rInfo.sStrArray[i].GetChar(1); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - InsertBlanks( OutString, OutString.Len(), - rInfo.sStrArray[i].GetChar(1) ); - break; - case NF_SYMBOLTYPE_STRING: - case NF_SYMBOLTYPE_CURRENCY: - case NF_SYMBOLTYPE_DATESEP: - case NF_SYMBOLTYPE_TIMESEP: - case NF_SYMBOLTYPE_TIME100SECSEP: - OutString += rInfo.sStrArray[i]; - break; - case NF_SYMBOLTYPE_DIGIT: - { - xub_StrLen nLen = ( bInputLine && i > 0 && - (rInfo.nTypeArray[i-1] == NF_SYMBOLTYPE_STRING || - rInfo.nTypeArray[i-1] == NF_SYMBOLTYPE_TIME100SECSEP) ? - nCntPost : rInfo.sStrArray[i].Len() ); - for (xub_StrLen j = 0; j < nLen && nSecPos < nCntPost; j++) - { - OutString += sSecStr.GetChar(nSecPos); - nSecPos++; - } - } - break; - case NF_KEY_AMPM: // AM/PM - { - if (cAmPm == 'a') - OutString += rCal.getDisplayName( CalendarDisplayIndex::AM_PM, - AmPmValue::AM, 0 ); - else - OutString += rCal.getDisplayName( CalendarDisplayIndex::AM_PM, - AmPmValue::PM, 0 ); - } - break; - case NF_KEY_AP: // A/P - { - if (cAmPm == 'a') - OutString += 'a'; - else - OutString += 'p'; - } - break; - case NF_KEY_MI: // M - OutString += ImpIntToString( nIx, nMin ); - break; - case NF_KEY_MMI: // MM - OutString += ImpIntToString( nIx, nMin, 2 ); - break; - case NF_KEY_H: // H - OutString += ImpIntToString( nIx, nHour ); - break; - case NF_KEY_HH: // HH - OutString += ImpIntToString( nIx, nHour, 2 ); - break; - case NF_KEY_S: // S - OutString += ImpIntToString( nIx, nSec ); - break; - case NF_KEY_SS: // SS - OutString += ImpIntToString( nIx, nSec, 2 ); - break; - case NF_KEY_M: // M - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_MONTH, nNatNum ); - break; - case NF_KEY_MM: // MM - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_MONTH, nNatNum ); - break; - case NF_KEY_MMM: // MMM - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_MONTH_NAME, nNatNum ); - break; - case NF_KEY_MMMM: // MMMM - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_MONTH_NAME, nNatNum ); - break; - case NF_KEY_MMMMM: // MMMMM - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_MONTH_NAME, nNatNum ).GetChar(0); - break; - case NF_KEY_Q: // Q - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_QUARTER, nNatNum ); - break; - case NF_KEY_QQ: // QQ - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_QUARTER, nNatNum ); - break; - case NF_KEY_D: // D - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_DAY, nNatNum ); - break; - case NF_KEY_DD: // DD - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY, nNatNum ); - break; - case NF_KEY_DDD: // DDD - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_DDDD: // DDDD - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_YY: // YY - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_YEAR, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_YYYY: // YYYY - { - if ( bOtherCalendar ) - SwitchToGregorianCalendar( aOrgCalendar, fOrgDateTime ); - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_YEAR, nNatNum ); - if ( bOtherCalendar ) - SwitchToOtherCalendar( aOrgCalendar, fOrgDateTime ); - } - break; - case NF_KEY_EC: // E - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_YEAR, nNatNum ); - break; - case NF_KEY_EEC: // EE - case NF_KEY_R: // R - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_YEAR, nNatNum ); - break; - case NF_KEY_NN: // NN - case NF_KEY_AAA: // AAA - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_DAY_NAME, nNatNum ); - break; - case NF_KEY_NNN: // NNN - case NF_KEY_AAAA: // AAAA - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); - break; - case NF_KEY_NNNN: // NNNN - { - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_DAY_NAME, nNatNum ); - OutString += rLoc().getLongDateDayOfWeekSep(); - } - break; - case NF_KEY_WW : // WW - { - sal_Int16 nVal = rCal.getValue( CalendarFieldIndex::WEEK_OF_YEAR ); - OutString += ImpIntToString( nIx, nVal ); - } - break; - case NF_KEY_G: // G - ImpAppendEraG( OutString, rCal, nNatNum ); - break; - case NF_KEY_GG: // GG - OutString += rCal.getDisplayString( - CalendarDisplayCode::SHORT_ERA, nNatNum ); - break; - case NF_KEY_GGG: // GGG - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_ERA, nNatNum ); - break; - case NF_KEY_RR: // RR => GGGEE - OutString += rCal.getDisplayString( - CalendarDisplayCode::LONG_YEAR_AND_ERA, nNatNum ); - break; - } - } - if ( aOrgCalendar.Len() ) - rCal.loadCalendar( aOrgCalendar, rLoc().getLocale() ); // restore calendar - return bRes; -} - -sal_Bool SvNumberformat::ImpGetNumberOutput(double fNumber, - sal_uInt16 nIx, - String& OutString) -{ - sal_Bool bRes = sal_False; - sal_Bool bSign; - if (fNumber < 0.0) - { - if (nIx == 0) // nicht in hinteren - bSign = sal_True; // Formaten - else - bSign = sal_False; - fNumber = -fNumber; - } - else - { - bSign = sal_False; - if ( ::rtl::math::isSignBitSet( fNumber ) ) - fNumber = -fNumber; // yes, -0.0 is possible, eliminate '-' - } - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - if (rInfo.eScannedType == NUMBERFORMAT_PERCENT) - { - if (fNumber < _D_MAX_D_BY_100) - fNumber *= 100.0; - else - { - OutString = rScan.GetErrorString(); - return sal_False; - } - } - sal_uInt16 i, j; - xub_StrLen k; - String sStr; - sal_Bool bInteger = sal_False; - if ( rInfo.nThousand != FLAG_STANDARD_IN_FORMAT ) - { // special formatting only if no GENERAL keyword in format code - const sal_uInt16 nThousand = rInfo.nThousand; - long nPrecExp; - for (i = 0; i < nThousand; i++) - { - if (fNumber > _D_MIN_M_BY_1000) - fNumber /= 1000.0; - else - fNumber = 0.0; - } - if (fNumber > 0.0) - nPrecExp = GetPrecExp( fNumber ); - else - nPrecExp = 0; - if (rInfo.nCntPost) // NachkommaStellen - { - if (rInfo.nCntPost + nPrecExp > 15 && nPrecExp < 15) - { - sStr = ::rtl::math::doubleToUString( fNumber, - rtl_math_StringFormat_F, 15-nPrecExp, '.'); - for (long l = 15-nPrecExp; l < (long) rInfo.nCntPost; l++) - sStr += '0'; - } - else - sStr = ::rtl::math::doubleToUString( fNumber, - rtl_math_StringFormat_F, rInfo.nCntPost, '.' ); - sStr.EraseLeadingChars('0'); // fuehrende Nullen weg - } - else if (fNumber == 0.0) // Null - { - // nothing to be done here, keep empty string sStr, - // ImpNumberFillWithThousands does the rest - } - else // Integer - { - sStr = ::rtl::math::doubleToUString( fNumber, - rtl_math_StringFormat_F, 0, '.'); - sStr.EraseLeadingChars('0'); // fuehrende Nullen weg - } - xub_StrLen nPoint = sStr.Search( '.' ); - if ( nPoint != STRING_NOTFOUND ) - { - register const sal_Unicode* p = sStr.GetBuffer() + nPoint; - while ( *++p == '0' ) - ; - if ( !*p ) - bInteger = sal_True; - sStr.Erase( nPoint, 1 ); // . herausnehmen - } - if (bSign && - (sStr.Len() == 0 || sStr.GetTokenCount('0') == sStr.Len()+1)) // nur 00000 - bSign = sal_False; // nicht -0.00 - } // End of != FLAG_STANDARD_IN_FORMAT - - // von hinten nach vorn - // editieren: - k = sStr.Len(); // hinter letzter Ziffer - j = NumFor[nIx].GetCount()-1; // letztes Symbol - // Nachkommastellen: - if (rInfo.nCntPost > 0) - { - sal_Bool bTrailing = sal_True; // ob Endnullen? - sal_Bool bFilled = sal_False; // ob aufgefuellt wurde ? - short nType; - while (j > 0 && // rueckwaerts - (nType = rInfo.nTypeArray[j]) != NF_SYMBOLTYPE_DECSEP) - { - switch ( nType ) - { - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - sStr.Insert( (sal_Unicode) 0x1B, k /*++*/ ); - sStr.Insert(rInfo.sStrArray[j].GetChar(1),k); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - /*k = */ InsertBlanks( sStr,k,rInfo.sStrArray[j].GetChar(1) ); - break; - case NF_SYMBOLTYPE_STRING: - case NF_SYMBOLTYPE_CURRENCY: - case NF_SYMBOLTYPE_PERCENT: - sStr.Insert(rInfo.sStrArray[j],k); - break; - case NF_SYMBOLTYPE_THSEP: - if (rInfo.nThousand == 0) - sStr.Insert(rInfo.sStrArray[j],k); - break; - case NF_SYMBOLTYPE_DIGIT: - { - const String& rStr = rInfo.sStrArray[j]; - const sal_Unicode* p1 = rStr.GetBuffer(); - register const sal_Unicode* p = p1 + rStr.Len(); - while ( p1 < p-- ) - { - const sal_Unicode c = *p; - k--; - if ( sStr.GetChar(k) != '0' ) - bTrailing = sal_False; - if (bTrailing) - { - if ( c == '0' ) - bFilled = sal_True; - else if ( c == '-' ) - { - if ( bInteger ) - sStr.SetChar( k, '-' ); - bFilled = sal_True; - } - else if ( c == '?' ) - { - sStr.SetChar( k, ' ' ); - bFilled = sal_True; - } - else if ( !bFilled ) // # - sStr.Erase(k,1); - } - } // of for - } // of case digi - break; - case NF_KEY_CCC: // CCC-Waehrung - sStr.Insert(rScan.GetCurAbbrev(), k); - break; - case NF_KEY_GENERAL: // Standard im String - { - String sNum; - ImpGetOutputStandard(fNumber, sNum); - sNum.EraseLeadingChars('-'); - sStr.Insert(sNum, k); - } - break; - default: - break; - } // of switch - j--; - } // of while - } // of Nachkomma - - bRes |= ImpNumberFillWithThousands(sStr, fNumber, k, j, nIx, // ggfs Auffuellen mit . - rInfo.nCntPre); - if ( rInfo.nCntPost > 0 ) - { - const String& rDecSep = GetFormatter().GetNumDecimalSep(); - xub_StrLen nLen = rDecSep.Len(); - if ( sStr.Len() > nLen && sStr.Equals( rDecSep, sStr.Len() - nLen, nLen ) ) - sStr.Erase( sStr.Len() - nLen ); // no decimals => strip DecSep - } - if (bSign) - sStr.Insert('-',0); - ImpTransliterate( sStr, NumFor[nIx].GetNatNum() ); - OutString = sStr; - return bRes; -} - -sal_Bool SvNumberformat::ImpNumberFillWithThousands( - String& sStr, // number string - double& rNumber, // number - xub_StrLen k, // position within string - sal_uInt16 j, // symbol index within format code - sal_uInt16 nIx, // subformat index - sal_uInt16 nDigCnt) // count of integer digits in format -{ - sal_Bool bRes = sal_False; - xub_StrLen nLeadingStringChars = 0; // inserted StringChars before number - xub_StrLen nDigitCount = 0; // count of integer digits from the right - sal_Bool bStop = sal_False; - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - // no normal thousands separators if number divided by thousands - sal_Bool bDoThousands = (rInfo.nThousand == 0); - utl::DigitGroupingIterator aGrouping( - GetFormatter().GetLocaleData()->getDigitGrouping()); - while (!bStop) // backwards - { - if (j == 0) - bStop = sal_True; - switch (rInfo.nTypeArray[j]) - { - case NF_SYMBOLTYPE_DECSEP: - aGrouping.reset(); - // fall thru - case NF_SYMBOLTYPE_STRING: - case NF_SYMBOLTYPE_CURRENCY: - case NF_SYMBOLTYPE_PERCENT: - sStr.Insert(rInfo.sStrArray[j],k); - if ( k == 0 ) - nLeadingStringChars = - nLeadingStringChars + rInfo.sStrArray[j].Len(); - break; - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - sStr.Insert( (sal_Unicode) 0x1B, k/*++*/ ); - sStr.Insert(rInfo.sStrArray[j].GetChar(1),k); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - /*k = */ InsertBlanks( sStr,k,rInfo.sStrArray[j].GetChar(1) ); - break; - case NF_SYMBOLTYPE_THSEP: - { - // #i7284# #102685# Insert separator also if number is divided - // by thousands and the separator is specified somewhere in - // between and not only at the end. - // #i12596# But do not insert if it's a parenthesized negative - // format like (#,) - // In fact, do not insert if divided and regex [0#,],[^0#] and - // no other digit symbol follows (which was already detected - // during scan of format code, otherwise there would be no - // division), else do insert. Same in ImpNumberFill() below. - if ( !bDoThousands && j < NumFor[nIx].GetCount()-1 ) - bDoThousands = ((j == 0) || - (rInfo.nTypeArray[j-1] != NF_SYMBOLTYPE_DIGIT && - rInfo.nTypeArray[j-1] != NF_SYMBOLTYPE_THSEP) || - (rInfo.nTypeArray[j+1] == NF_SYMBOLTYPE_DIGIT)); - if ( bDoThousands ) - { - if (k > 0) - sStr.Insert(rInfo.sStrArray[j],k); - else if (nDigitCount < nDigCnt) - { - // Leading '#' displays nothing (e.g. no leading - // separator for numbers <1000 with #,##0 format). - // Leading '?' displays blank. - // Everything else, including nothing, displays the - // separator. - sal_Unicode cLeader = 0; - if (j > 0 && rInfo.nTypeArray[j-1] == NF_SYMBOLTYPE_DIGIT) - { - const String& rStr = rInfo.sStrArray[j-1]; - xub_StrLen nLen = rStr.Len(); - if (nLen) - cLeader = rStr.GetChar(nLen-1); - } - switch (cLeader) - { - case '#': - ; // nothing - break; - case '?': - // erAck: 2008-04-03T16:24+0200 - // Actually this currently isn't executed - // because the format scanner in the context of - // "?," doesn't generate a group separator but - // a literal ',' character instead that is - // inserted unconditionally. Should be changed - // on some occasion. - sStr.Insert(' ',k); - break; - default: - sStr.Insert(rInfo.sStrArray[j],k); - } - } - aGrouping.advance(); - } - } - break; - case NF_SYMBOLTYPE_DIGIT: - { - const String& rStr = rInfo.sStrArray[j]; - const sal_Unicode* p1 = rStr.GetBuffer(); - register const sal_Unicode* p = p1 + rStr.Len(); - while ( p1 < p-- ) - { - nDigitCount++; - if (k > 0) - k--; - else - { - switch (*p) - { - case '0': - sStr.Insert('0',0); - break; - case '?': - sStr.Insert(' ',0); - break; - } - } - if (nDigitCount == nDigCnt && k > 0) - { // more digits than specified - ImpDigitFill(sStr, 0, k, nIx, nDigitCount, aGrouping); - } - } - } - break; - case NF_KEY_CCC: // CCC currency - sStr.Insert(rScan.GetCurAbbrev(), k); - break; - case NF_KEY_GENERAL: // "General" in string - { - String sNum; - ImpGetOutputStandard(rNumber, sNum); - sNum.EraseLeadingChars('-'); - sStr.Insert(sNum, k); - } - break; - - default: - break; - } // switch - j--; // next format code string - } // while - k = k + nLeadingStringChars; // MSC converts += to int and then warns, so ... - if (k > nLeadingStringChars) - ImpDigitFill(sStr, nLeadingStringChars, k, nIx, nDigitCount, aGrouping); - return bRes; -} - -void SvNumberformat::ImpDigitFill( - String& sStr, // number string - xub_StrLen nStart, // start of digits - xub_StrLen& k, // position within string - sal_uInt16 nIx, // subformat index - xub_StrLen & nDigitCount, // count of integer digits from the right so far - utl::DigitGroupingIterator & rGrouping ) // current grouping -{ - if (NumFor[nIx].Info().bThousand) // only if grouping - { // fill in separators - const String& rThousandSep = GetFormatter().GetNumThousandSep(); - while (k > nStart) - { - if (nDigitCount == rGrouping.getPos()) - { - sStr.Insert( rThousandSep, k ); - rGrouping.advance(); - } - nDigitCount++; - k--; - } - } - else // simply skip - k = nStart; -} - -sal_Bool SvNumberformat::ImpNumberFill( String& sStr, // number string - double& rNumber, // number for "General" format - xub_StrLen& k, // position within string - sal_uInt16& j, // symbol index within format code - sal_uInt16 nIx, // subformat index - short eSymbolType ) // type of stop condition -{ - sal_Bool bRes = sal_False; - k = sStr.Len(); // behind last digit - const ImpSvNumberformatInfo& rInfo = NumFor[nIx].Info(); - // no normal thousands separators if number divided by thousands - sal_Bool bDoThousands = (rInfo.nThousand == 0); - short nType; - while (j > 0 && (nType = rInfo.nTypeArray[j]) != eSymbolType ) - { // rueckwaerts: - switch ( nType ) - { - case NF_SYMBOLTYPE_STAR: - if( bStarFlag ) - { - sStr.Insert( sal_Unicode(0x1B), k++ ); - sStr.Insert(rInfo.sStrArray[j].GetChar(1),k); - bRes = sal_True; - } - break; - case NF_SYMBOLTYPE_BLANK: - k = InsertBlanks( sStr,k,rInfo.sStrArray[j].GetChar(1) ); - break; - case NF_SYMBOLTYPE_THSEP: - { - // Same as in ImpNumberFillWithThousands() above, do not insert - // if divided and regex [0#,],[^0#] and no other digit symbol - // follows (which was already detected during scan of format - // code, otherwise there would be no division), else do insert. - if ( !bDoThousands && j < NumFor[nIx].GetCount()-1 ) - bDoThousands = ((j == 0) || - (rInfo.nTypeArray[j-1] != NF_SYMBOLTYPE_DIGIT && - rInfo.nTypeArray[j-1] != NF_SYMBOLTYPE_THSEP) || - (rInfo.nTypeArray[j+1] == NF_SYMBOLTYPE_DIGIT)); - if ( bDoThousands && k > 0 ) - { - sStr.Insert(rInfo.sStrArray[j],k); - } - } - break; - case NF_SYMBOLTYPE_DIGIT: - { - const String& rStr = rInfo.sStrArray[j]; - const sal_Unicode* p1 = rStr.GetBuffer(); - register const sal_Unicode* p = p1 + rStr.Len(); - while ( p1 < p-- ) - { - if (k > 0) - k--; - else - { - switch (*p) - { - case '0': - sStr.Insert('0',0); - break; - case '?': - sStr.Insert(' ',0); - break; - } - } - } - } - break; - case NF_KEY_CCC: // CCC-Waehrung - sStr.Insert(rScan.GetCurAbbrev(), k); - break; - case NF_KEY_GENERAL: // Standard im String - { - String sNum; - ImpGetOutputStandard(rNumber, sNum); - sNum.EraseLeadingChars('-'); // Vorzeichen weg!! - sStr.Insert(sNum, k); - } - break; - case NF_SYMBOLTYPE_FRAC_FDIV: // Do Nothing - break; - - default: - sStr.Insert(rInfo.sStrArray[j],k); - break; - } // of switch - j--; // naechster String - } // of while - return bRes; -} - -void SvNumberformat::GetFormatSpecialInfo(sal_Bool& bThousand, - sal_Bool& IsRed, - sal_uInt16& nPrecision, - sal_uInt16& nAnzLeading) const -{ - // as before: take info from nNumFor=0 for whole format (for dialog etc.) - - short nDummyType; - GetNumForInfo( 0, nDummyType, bThousand, nPrecision, nAnzLeading ); - - // "negative in red" is only useful for the whole format - - const Color* pColor = NumFor[1].GetColor(); - if (fLimit1 == 0.0 && fLimit2 == 0.0 && pColor - && (*pColor == rScan.GetRedColor())) - IsRed = sal_True; - else - IsRed = sal_False; -} - -void SvNumberformat::GetNumForInfo( sal_uInt16 nNumFor, short& rScannedType, - sal_Bool& bThousand, sal_uInt16& nPrecision, sal_uInt16& nAnzLeading ) const -{ - // take info from a specified sub-format (for XML export) - - if ( nNumFor > 3 ) - return; // invalid - - const ImpSvNumberformatInfo& rInfo = NumFor[nNumFor].Info(); - rScannedType = rInfo.eScannedType; - bThousand = rInfo.bThousand; - nPrecision = rInfo.nCntPost; - if (bStandard && rInfo.eScannedType == NUMBERFORMAT_NUMBER) - // StandardFormat - nAnzLeading = 1; - else - { - nAnzLeading = 0; - sal_Bool bStop = sal_False; - sal_uInt16 i = 0; - const sal_uInt16 nAnz = NumFor[nNumFor].GetCount(); - while (!bStop && i < nAnz) - { - short nType = rInfo.nTypeArray[i]; - if ( nType == NF_SYMBOLTYPE_DIGIT) - { - register const sal_Unicode* p = rInfo.sStrArray[i].GetBuffer(); - while ( *p == '#' ) - p++; - while ( *p++ == '0' ) - nAnzLeading++; - } - else if (nType == NF_SYMBOLTYPE_DECSEP || nType == NF_SYMBOLTYPE_EXP) - bStop = sal_True; - i++; - } - } -} - -const String* SvNumberformat::GetNumForString( sal_uInt16 nNumFor, sal_uInt16 nPos, - sal_Bool bString /* = sal_False */ ) const -{ - if ( nNumFor > 3 ) - return NULL; - sal_uInt16 nAnz = NumFor[nNumFor].GetCount(); - if ( !nAnz ) - return NULL; - if ( nPos == 0xFFFF ) - { - nPos = nAnz - 1; - if ( bString ) - { // rueckwaerts - short* pType = NumFor[nNumFor].Info().nTypeArray + nPos; - while ( nPos > 0 && (*pType != NF_SYMBOLTYPE_STRING) && - (*pType != NF_SYMBOLTYPE_CURRENCY) ) - { - pType--; - nPos--; - } - if ( (*pType != NF_SYMBOLTYPE_STRING) && (*pType != NF_SYMBOLTYPE_CURRENCY) ) - return NULL; - } - } - else if ( nPos > nAnz - 1 ) - return NULL; - else if ( bString ) - { // vorwaerts - short* pType = NumFor[nNumFor].Info().nTypeArray + nPos; - while ( nPos < nAnz && (*pType != NF_SYMBOLTYPE_STRING) && - (*pType != NF_SYMBOLTYPE_CURRENCY) ) - { - pType++; - nPos++; - } - if ( nPos >= nAnz || ((*pType != NF_SYMBOLTYPE_STRING) && - (*pType != NF_SYMBOLTYPE_CURRENCY)) ) - return NULL; - } - return &NumFor[nNumFor].Info().sStrArray[nPos]; -} - -short SvNumberformat::GetNumForType( sal_uInt16 nNumFor, sal_uInt16 nPos, - sal_Bool bString /* = sal_False */ ) const -{ - if ( nNumFor > 3 ) - return 0; - sal_uInt16 nAnz = NumFor[nNumFor].GetCount(); - if ( !nAnz ) - return 0; - if ( nPos == 0xFFFF ) - { - nPos = nAnz - 1; - if ( bString ) - { // rueckwaerts - short* pType = NumFor[nNumFor].Info().nTypeArray + nPos; - while ( nPos > 0 && (*pType != NF_SYMBOLTYPE_STRING) && - (*pType != NF_SYMBOLTYPE_CURRENCY) ) - { - pType--; - nPos--; - } - if ( (*pType != NF_SYMBOLTYPE_STRING) && (*pType != NF_SYMBOLTYPE_CURRENCY) ) - return 0; - } - } - else if ( nPos > nAnz - 1 ) - return 0; - else if ( bString ) - { // vorwaerts - short* pType = NumFor[nNumFor].Info().nTypeArray + nPos; - while ( nPos < nAnz && (*pType != NF_SYMBOLTYPE_STRING) && - (*pType != NF_SYMBOLTYPE_CURRENCY) ) - { - pType++; - nPos++; - } - if ( (*pType != NF_SYMBOLTYPE_STRING) && (*pType != NF_SYMBOLTYPE_CURRENCY) ) - return 0; - } - return NumFor[nNumFor].Info().nTypeArray[nPos]; -} - -sal_Bool SvNumberformat::IsNegativeWithoutSign() const -{ - if ( IsNegativeRealNegative() ) - { - const String* pStr = GetNumForString( 1, 0, sal_True ); - if ( pStr ) - return !HasStringNegativeSign( *pStr ); - } - return sal_False; -} - -sal_Bool SvNumberformat::IsNegativeInBracket() const -{ - sal_uInt16 nAnz = NumFor[1].GetCount(); - if (!nAnz) - return sal_False; - - String *tmpStr = NumFor[1].Info().sStrArray; - return (tmpStr[0] == '(' && tmpStr[nAnz-1] == ')' ); -} - -sal_Bool SvNumberformat::HasPositiveBracketPlaceholder() const -{ - sal_uInt16 nAnz = NumFor[0].GetCount(); - String *tmpStr = NumFor[0].Info().sStrArray; - return (tmpStr[nAnz-1].EqualsAscii( "_)" )); -} - -DateFormat SvNumberformat::GetDateOrder() const -{ - if ( (eType & NUMBERFORMAT_DATE) == NUMBERFORMAT_DATE ) - { - short const * const pType = NumFor[0].Info().nTypeArray; - sal_uInt16 nAnz = NumFor[0].GetCount(); - for ( sal_uInt16 j=0; j<nAnz; j++ ) - { - switch ( pType[j] ) - { - case NF_KEY_D : - case NF_KEY_DD : - return DMY; - case NF_KEY_M : - case NF_KEY_MM : - case NF_KEY_MMM : - case NF_KEY_MMMM : - case NF_KEY_MMMMM : - return MDY; - case NF_KEY_YY : - case NF_KEY_YYYY : - case NF_KEY_EC : - case NF_KEY_EEC : - case NF_KEY_R : - case NF_KEY_RR : - return YMD; - } - } - } - else - { - OSL_FAIL( "SvNumberformat::GetDateOrder: no date" ); - } - return rLoc().getDateFormat(); -} - -sal_uInt32 SvNumberformat::GetExactDateOrder() const -{ - sal_uInt32 nRet = 0; - if ( (eType & NUMBERFORMAT_DATE) != NUMBERFORMAT_DATE ) - { - OSL_FAIL( "SvNumberformat::GetExactDateOrder: no date" ); - return nRet; - } - short const * const pType = NumFor[0].Info().nTypeArray; - sal_uInt16 nAnz = NumFor[0].GetCount(); - int nShift = 0; - for ( sal_uInt16 j=0; j<nAnz && nShift < 3; j++ ) - { - switch ( pType[j] ) - { - case NF_KEY_D : - case NF_KEY_DD : - nRet = (nRet << 8) | 'D'; - ++nShift; - break; - case NF_KEY_M : - case NF_KEY_MM : - case NF_KEY_MMM : - case NF_KEY_MMMM : - case NF_KEY_MMMMM : - nRet = (nRet << 8) | 'M'; - ++nShift; - break; - case NF_KEY_YY : - case NF_KEY_YYYY : - case NF_KEY_EC : - case NF_KEY_EEC : - case NF_KEY_R : - case NF_KEY_RR : - nRet = (nRet << 8) | 'Y'; - ++nShift; - break; - } - } - return nRet; -} - -void SvNumberformat::GetConditions( SvNumberformatLimitOps& rOper1, double& rVal1, - SvNumberformatLimitOps& rOper2, double& rVal2 ) const -{ - rOper1 = eOp1; - rOper2 = eOp2; - rVal1 = fLimit1; - rVal2 = fLimit2; -} - -Color* SvNumberformat::GetColor( sal_uInt16 nNumFor ) const -{ - if ( nNumFor > 3 ) - return NULL; - - return NumFor[nNumFor].GetColor(); -} - -void lcl_SvNumberformat_AddLimitStringImpl( String& rStr, - SvNumberformatLimitOps eOp, double fLimit, const String& rDecSep ) -{ - if ( eOp != NUMBERFORMAT_OP_NO ) - { - switch ( eOp ) - { - case NUMBERFORMAT_OP_EQ : - rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "[=" ) ); - break; - case NUMBERFORMAT_OP_NE : - rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "[<>" ) ); - break; - case NUMBERFORMAT_OP_LT : - rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "[<" ) ); - break; - case NUMBERFORMAT_OP_LE : - rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "[<=" ) ); - break; - case NUMBERFORMAT_OP_GT : - rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "[>" ) ); - break; - case NUMBERFORMAT_OP_GE : - rStr.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "[>=" ) ); - break; - default: - OSL_FAIL( "unsupported number format" ); - break; - } - rStr += String( ::rtl::math::doubleToUString( fLimit, - rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, - rDecSep.GetChar(0), sal_True)); - rStr += ']'; - } -} - -String SvNumberformat::GetMappedFormatstring( - const NfKeywordTable& rKeywords, const LocaleDataWrapper& rLocWrp, - sal_Bool bDontQuote ) const -{ - String aStr; - sal_Bool bDefault[4]; - // 1 subformat matches all if no condition specified, - bDefault[0] = ( NumFor[1].GetCount() == 0 && eOp1 == NUMBERFORMAT_OP_NO ); - // with 2 subformats [>=0];[<0] is implied if no condition specified - bDefault[1] = ( !bDefault[0] && NumFor[2].GetCount() == 0 && - eOp1 == NUMBERFORMAT_OP_GE && fLimit1 == 0.0 && - eOp2 == NUMBERFORMAT_OP_NO && fLimit2 == 0.0 ); - // with 3 or more subformats [>0];[<0];[=0] is implied if no condition specified, - // note that subformats may be empty (;;;) and NumFor[2].GetnAnz()>0 is not checked. - bDefault[2] = ( !bDefault[0] && !bDefault[1] && - eOp1 == NUMBERFORMAT_OP_GT && fLimit1 == 0.0 && - eOp2 == NUMBERFORMAT_OP_LT && fLimit2 == 0.0 ); - sal_Bool bDefaults = bDefault[0] || bDefault[1] || bDefault[2]; - // from now on bDefault[] values are used to append empty subformats at the end - bDefault[3] = sal_False; - if ( !bDefaults ) - { // conditions specified - if ( eOp1 != NUMBERFORMAT_OP_NO && eOp2 == NUMBERFORMAT_OP_NO ) - bDefault[0] = bDefault[1] = sal_True; // [];x - else if ( eOp1 != NUMBERFORMAT_OP_NO && eOp2 != NUMBERFORMAT_OP_NO && - NumFor[2].GetCount() == 0 ) - bDefault[0] = bDefault[1] = bDefault[2] = bDefault[3] = sal_True; // [];[];; - // nothing to do if conditions specified for every subformat - } - else if ( bDefault[0] ) - bDefault[0] = sal_False; // a single unconditional subformat is never delimited - else - { - if ( bDefault[2] && NumFor[2].GetCount() == 0 && NumFor[1].GetCount() > 0 ) - bDefault[3] = sal_True; // special cases x;x;; and ;x;; - for ( int i=0; i<3 && !bDefault[i]; ++i ) - bDefault[i] = sal_True; - } - int nSem = 0; // needed ';' delimiters - int nSub = 0; // subformats delimited so far - for ( int n=0; n<4; n++ ) - { - if ( n > 0 ) - nSem++; - - String aPrefix; - bool LCIDInserted = false; - - if ( !bDefaults ) - { - switch ( n ) - { - case 0 : - lcl_SvNumberformat_AddLimitStringImpl( aPrefix, eOp1, - fLimit1, rLocWrp.getNumDecimalSep() ); - break; - case 1 : - lcl_SvNumberformat_AddLimitStringImpl( aPrefix, eOp2, - fLimit2, rLocWrp.getNumDecimalSep() ); - break; - } - } - - const String& rColorName = NumFor[n].GetColorName(); - if ( rColorName.Len() ) - { - const NfKeywordTable & rKey = rScan.GetKeywords(); - for ( int j=NF_KEY_FIRSTCOLOR; j<=NF_KEY_LASTCOLOR; j++ ) - { - if ( rKey[j] == rColorName ) - { - aPrefix += '['; - aPrefix += rKeywords[j]; - aPrefix += ']'; - break; // for - } - } - } - - const SvNumberNatNum& rNum = NumFor[n].GetNatNum(); - - sal_uInt16 nAnz = NumFor[n].GetCount(); - if ( nSem && (nAnz || aPrefix.Len()) ) - { - for ( ; nSem; --nSem ) - aStr += ';'; - for ( ; nSub <= n; ++nSub ) - bDefault[nSub] = sal_False; - } - - if ( aPrefix.Len() ) - aStr += aPrefix; - - if ( nAnz ) - { - const short* pType = NumFor[n].Info().nTypeArray; - const String* pStr = NumFor[n].Info().sStrArray; - for ( sal_uInt16 j=0; j<nAnz; j++ ) - { - if ( 0 <= pType[j] && pType[j] < NF_KEYWORD_ENTRIES_COUNT ) - { - aStr += rKeywords[pType[j]]; - if( NF_KEY_NNNN == pType[j] ) - aStr += rLocWrp.getLongDateDayOfWeekSep(); - } - else - { - switch ( pType[j] ) - { - case NF_SYMBOLTYPE_DECSEP : - aStr += rLocWrp.getNumDecimalSep(); - break; - case NF_SYMBOLTYPE_THSEP : - aStr += rLocWrp.getNumThousandSep(); - break; - case NF_SYMBOLTYPE_DATESEP : - aStr += rLocWrp.getDateSep(); - break; - case NF_SYMBOLTYPE_TIMESEP : - aStr += rLocWrp.getTimeSep(); - break; - case NF_SYMBOLTYPE_TIME100SECSEP : - aStr += rLocWrp.getTime100SecSep(); - break; - case NF_SYMBOLTYPE_STRING : - if( bDontQuote ) - aStr += pStr[j]; - else if ( pStr[j].Len() == 1 ) - { - aStr += '\\'; - aStr += pStr[j]; - } - else - { - aStr += '"'; - aStr += pStr[j]; - aStr += '"'; - } - break; - case NF_SYMBOLTYPE_CALDEL : - if ( pStr[j+1].EqualsAscii("buddhist") ) - { - aStr.InsertAscii( "[$-", 0 ); - if ( rNum.IsSet() && rNum.GetNatNum() == 1 && - MsLangId::getRealLanguage( rNum.GetLang() ) == - LANGUAGE_THAI ) - { - aStr.InsertAscii( "D07041E]", 3 ); // date in Thai digit, Buddhist era - } - else - { - aStr.InsertAscii( "107041E]", 3 ); // date in Arabic digit, Buddhist era - } - j = j+2; - } - LCIDInserted = true; - break; - default: - aStr += pStr[j]; - } - - } - } - } - // The Thai T NatNum modifier during Xcl export. - if (rNum.IsSet() && rNum.GetNatNum() == 1 && - rKeywords[NF_KEY_THAI_T].EqualsAscii( "T") && - MsLangId::getRealLanguage( rNum.GetLang()) == - LANGUAGE_THAI && !LCIDInserted ) - { - - aStr.InsertAscii( "[$-D00041E]", 0 ); // number in Thai digit - } - } - for ( ; nSub<4 && bDefault[nSub]; ++nSub ) - { // append empty subformats - aStr += ';'; - } - return aStr; -} - -String SvNumberformat::ImpGetNatNumString( const SvNumberNatNum& rNum, - sal_Int32 nVal, sal_uInt16 nMinDigits ) const -{ - String aStr; - if ( nMinDigits ) - { - if ( nMinDigits == 2 ) - { // speed up the most common case - if ( 0 <= nVal && nVal < 10 ) - { - sal_Unicode* p = aStr.AllocBuffer( 2 ); - *p++ = '0'; - *p = sal_Unicode( '0' + nVal ); - } - else - aStr = String::CreateFromInt32( nVal ); - } - else - { - String aValStr( String::CreateFromInt32( nVal ) ); - if ( aValStr.Len() >= nMinDigits ) - aStr = aValStr; - else - { - aStr.Fill( nMinDigits - aValStr.Len(), '0' ); - aStr += aValStr; - } - } - } - else - aStr = String::CreateFromInt32( nVal ); - ImpTransliterate( aStr, rNum ); - return aStr; -} - -void SvNumberformat::ImpTransliterateImpl( String& rStr, - const SvNumberNatNum& rNum ) const -{ - com::sun::star::lang::Locale aLocale( - MsLangId::convertLanguageToLocale( rNum.GetLang() ) ); - rStr = GetFormatter().GetNatNum()->getNativeNumberString( rStr, - aLocale, rNum.GetNatNum() ); -} - -void SvNumberformat::GetNatNumXml( - com::sun::star::i18n::NativeNumberXmlAttributes& rAttr, - sal_uInt16 nNumFor ) const -{ - if ( nNumFor <= 3 ) - { - const SvNumberNatNum& rNum = NumFor[nNumFor].GetNatNum(); - if ( rNum.IsSet() ) - { - com::sun::star::lang::Locale aLocale( - MsLangId::convertLanguageToLocale( rNum.GetLang() ) ); - rAttr = GetFormatter().GetNatNum()->convertToXmlAttributes( - aLocale, rNum.GetNatNum() ); - } - else - rAttr = com::sun::star::i18n::NativeNumberXmlAttributes(); - } - else - rAttr = com::sun::star::i18n::NativeNumberXmlAttributes(); -} - -// static -sal_Bool SvNumberformat::HasStringNegativeSign( const String& rStr ) -{ - // fuer Sign muss '-' am Anfang oder am Ende des TeilStrings sein (Blanks ignored) - xub_StrLen nLen = rStr.Len(); - if ( !nLen ) - return sal_False; - const sal_Unicode* const pBeg = rStr.GetBuffer(); - const sal_Unicode* const pEnd = pBeg + nLen; - register const sal_Unicode* p = pBeg; - do - { // Anfang - if ( *p == '-' ) - return sal_True; - } while ( *p == ' ' && ++p < pEnd ); - p = pEnd - 1; - do - { // Ende - if ( *p == '-' ) - return sal_True; - } while ( *p == ' ' && pBeg < --p ); - return sal_False; -} - -// static -void SvNumberformat::SetComment( const String& rStr, String& rFormat, - String& rComment ) -{ - if ( rComment.Len() ) - { // alten Kommentar aus Formatstring loeschen - //! nicht per EraseComment, der Kommentar muss matchen - String aTmp( '{' ); - aTmp += ' '; - aTmp += rComment; - aTmp += ' '; - aTmp += '}'; - xub_StrLen nCom = 0; - do - { - nCom = rFormat.Search( aTmp, nCom ); - } while ( (nCom != STRING_NOTFOUND) && (nCom + aTmp.Len() != rFormat.Len()) ); - if ( nCom != STRING_NOTFOUND ) - rFormat.Erase( nCom ); - } - if ( rStr.Len() ) - { // neuen Kommentar setzen - rFormat += '{'; - rFormat += ' '; - rFormat += rStr; - rFormat += ' '; - rFormat += '}'; - rComment = rStr; - } -} - -// static -void SvNumberformat::EraseCommentBraces( String& rStr ) -{ - xub_StrLen nLen = rStr.Len(); - if ( nLen && rStr.GetChar(0) == '{' ) - { - rStr.Erase( 0, 1 ); - --nLen; - } - if ( nLen && rStr.GetChar(0) == ' ' ) - { - rStr.Erase( 0, 1 ); - --nLen; - } - if ( nLen && rStr.GetChar( nLen-1 ) == '}' ) - rStr.Erase( --nLen, 1 ); - if ( nLen && rStr.GetChar( nLen-1 ) == ' ' ) - rStr.Erase( --nLen, 1 ); -} - -// static -void SvNumberformat::EraseComment( String& rStr ) -{ - register const sal_Unicode* p = rStr.GetBuffer(); - sal_Bool bInString = sal_False; - sal_Bool bEscaped = sal_False; - sal_Bool bFound = sal_False; - xub_StrLen nPos = 0; - while ( !bFound && *p ) - { - switch ( *p ) - { - case '\\' : - bEscaped = !bEscaped; - break; - case '\"' : - if ( !bEscaped ) - bInString = !bInString; - break; - case '{' : - if ( !bEscaped && !bInString ) - { - bFound = sal_True; - nPos = sal::static_int_cast< xub_StrLen >( - p - rStr.GetBuffer()); - } - break; - } - if ( bEscaped && *p != '\\' ) - bEscaped = sal_False; - ++p; - } - if ( bFound ) - rStr.Erase( nPos ); -} - -// static -sal_Bool SvNumberformat::IsInQuote( const String& rStr, xub_StrLen nPos, - sal_Unicode cQuote, sal_Unicode cEscIn, sal_Unicode cEscOut ) -{ - xub_StrLen nLen = rStr.Len(); - if ( nPos >= nLen ) - return sal_False; - register const sal_Unicode* p0 = rStr.GetBuffer(); - register const sal_Unicode* p = p0; - register const sal_Unicode* p1 = p0 + nPos; - sal_Bool bQuoted = sal_False; - while ( p <= p1 ) - { - if ( *p == cQuote ) - { - if ( p == p0 ) - bQuoted = sal_True; - else if ( bQuoted ) - { - if ( *(p-1) != cEscIn ) - bQuoted = sal_False; - } - else - { - if ( *(p-1) != cEscOut ) - bQuoted = sal_True; - } - } - p++; - } - return bQuoted; -} - -// static -xub_StrLen SvNumberformat::GetQuoteEnd( const String& rStr, xub_StrLen nPos, - sal_Unicode cQuote, sal_Unicode cEscIn, sal_Unicode cEscOut ) -{ - xub_StrLen nLen = rStr.Len(); - if ( nPos >= nLen ) - return STRING_NOTFOUND; - if ( !IsInQuote( rStr, nPos, cQuote, cEscIn, cEscOut ) ) - { - if ( rStr.GetChar( nPos ) == cQuote ) - return nPos; // schliessendes cQuote - return STRING_NOTFOUND; - } - register const sal_Unicode* p0 = rStr.GetBuffer(); - register const sal_Unicode* p = p0 + nPos; - register const sal_Unicode* p1 = p0 + nLen; - while ( p < p1 ) - { - if ( *p == cQuote && p > p0 && *(p-1) != cEscIn ) - return sal::static_int_cast< xub_StrLen >(p - p0); - p++; - } - return nLen; // String Ende -} - -sal_uInt16 SvNumberformat::ImpGetNumForStringElementCount( sal_uInt16 nNumFor ) const -{ - sal_uInt16 nCnt = 0; - sal_uInt16 nAnz = NumFor[nNumFor].GetCount(); - short const * const pType = NumFor[nNumFor].Info().nTypeArray; - for ( sal_uInt16 j=0; j<nAnz; ++j ) - { - switch ( pType[j] ) - { - case NF_SYMBOLTYPE_STRING: - case NF_SYMBOLTYPE_CURRENCY: - case NF_SYMBOLTYPE_DATESEP: - case NF_SYMBOLTYPE_TIMESEP: - case NF_SYMBOLTYPE_TIME100SECSEP: - case NF_SYMBOLTYPE_PERCENT: - ++nCnt; - break; - } - } - return nCnt; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx deleted file mode 100644 index 6e5fb8a104..0000000000 --- a/svl/source/numbers/zforscan.cxx +++ /dev/null @@ -1,2813 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <stdlib.h> -#include <tools/debug.hxx> -#include <i18npool/mslangid.hxx> -#include <unotools/charclass.hxx> -#include <unotools/localedatawrapper.hxx> -#include <unotools/numberformatcodewrapper.hxx> -#include <rtl/instance.hxx> - -#include <svl/zforlist.hxx> -#include <svl/zformat.hxx> -#include <unotools/digitgroupingiterator.hxx> - -#define _ZFORSCAN_CXX -#include "zforscan.hxx" -#undef _ZFORSCAN_CXX -#include <svl/nfsymbol.hxx> -using namespace svt; - -const sal_Unicode cNonBreakingSpace = 0xA0; - -namespace -{ - struct ImplEnglishColors - { - const String* operator()() - { - static const String aEnglishColors[NF_MAX_DEFAULT_COLORS] = - { - String( RTL_CONSTASCII_USTRINGPARAM( "BLACK" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "BLUE" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "GREEN" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "CYAN" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "RED" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "MAGENTA" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "BROWN" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "GREY" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "YELLOW" ) ), - String( RTL_CONSTASCII_USTRINGPARAM( "WHITE" ) ) - }; - return &aEnglishColors[0]; - } - }; - - struct theEnglishColors - : public rtl::StaticAggregate< const String, ImplEnglishColors> {}; - -} - -ImpSvNumberformatScan::ImpSvNumberformatScan( SvNumberFormatter* pFormatterP ) -{ - pFormatter = pFormatterP; - bConvertMode = sal_False; - //! All keywords MUST be UPPERCASE! - sKeyword[NF_KEY_E].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "E" ) ); // Exponent - sKeyword[NF_KEY_AMPM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AM/PM" ) ); // AM/PM - sKeyword[NF_KEY_AP].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "A/P" ) ); // AM/PM short - sKeyword[NF_KEY_MI].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "M" ) ); // Minute - sKeyword[NF_KEY_MMI].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MM" ) ); // Minute 02 - sKeyword[NF_KEY_S].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "S" ) ); // Second - sKeyword[NF_KEY_SS].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "SS" ) ); // Second 02 - sKeyword[NF_KEY_Q].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "Q" ) ); // Quarter short 'Q' - sKeyword[NF_KEY_QQ].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "QQ" ) ); // Quarter long - sKeyword[NF_KEY_NN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "NN" ) ); // Day of week short - sKeyword[NF_KEY_NNN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "NNN" ) ); // Day of week long - sKeyword[NF_KEY_NNNN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "NNNN" ) ); // Day of week long incl. separator - sKeyword[NF_KEY_WW].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "WW" ) ); // Week of year - sKeyword[NF_KEY_CCC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "CCC" ) ); // Currency abbreviation - bKeywordsNeedInit = sal_True; // locale dependent keywords - bCompatCurNeedInit = sal_True; // locale dependent compatibility currency strings - - StandardColor[0] = Color(COL_BLACK); - StandardColor[1] = Color(COL_LIGHTBLUE); - StandardColor[2] = Color(COL_LIGHTGREEN); - StandardColor[3] = Color(COL_LIGHTCYAN); - StandardColor[4] = Color(COL_LIGHTRED); - StandardColor[5] = Color(COL_LIGHTMAGENTA); - StandardColor[6] = Color(COL_BROWN); - StandardColor[7] = Color(COL_GRAY); - StandardColor[8] = Color(COL_YELLOW); - StandardColor[9] = Color(COL_WHITE); - - pNullDate = new Date(30,12,1899); - nStandardPrec = 2; - - sErrStr.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "###" ) ); - Reset(); -} - -ImpSvNumberformatScan::~ImpSvNumberformatScan() -{ - delete pNullDate; - Reset(); -} - -void ImpSvNumberformatScan::ChangeIntl() -{ - bKeywordsNeedInit = sal_True; - bCompatCurNeedInit = sal_True; - // may be initialized by InitSpecialKeyword() - sKeyword[NF_KEY_TRUE].Erase(); - sKeyword[NF_KEY_FALSE].Erase(); -} - -void ImpSvNumberformatScan::InitSpecialKeyword( NfKeywordIndex eIdx ) const -{ - switch ( eIdx ) - { - case NF_KEY_TRUE : - ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_TRUE] = - pFormatter->GetCharClass()->upper( - pFormatter->GetLocaleData()->getTrueWord() ); - if ( !sKeyword[NF_KEY_TRUE].Len() ) - { - DBG_ERRORFILE( "InitSpecialKeyword: TRUE_WORD?" ); - ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_TRUE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TRUE" ) ); - } - break; - case NF_KEY_FALSE : - ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_FALSE] = - pFormatter->GetCharClass()->upper( - pFormatter->GetLocaleData()->getFalseWord() ); - if ( !sKeyword[NF_KEY_FALSE].Len() ) - { - DBG_ERRORFILE( "InitSpecialKeyword: FALSE_WORD?" ); - ((ImpSvNumberformatScan*)this)->sKeyword[NF_KEY_FALSE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "FALSE" ) ); - } - break; - default: - DBG_ERRORFILE( "InitSpecialKeyword: unknown request" ); - } -} - -void ImpSvNumberformatScan::InitCompatCur() const -{ - ImpSvNumberformatScan* pThis = (ImpSvNumberformatScan*)this; - // currency symbol for old style ("automatic") compatibility format codes - pFormatter->GetCompatibilityCurrency( pThis->sCurSymbol, pThis->sCurAbbrev ); - // currency symbol upper case - pThis->sCurString = pFormatter->GetCharClass()->upper( sCurSymbol ); - bCompatCurNeedInit = sal_False; -} - -void ImpSvNumberformatScan::InitKeywords() const -{ - if ( !bKeywordsNeedInit ) - return ; - ((ImpSvNumberformatScan*)this)->SetDependentKeywords(); - bKeywordsNeedInit = sal_False; -} - -/** Extract the name of General, Standard, Whatever, ignoring leading modifiers - such as [NatNum1]. */ -static String lcl_extractStandardGeneralName( const ::rtl::OUString & rCode ) -{ - String aStr; - const sal_Unicode* p = rCode.getStr(); - const sal_Unicode* const pStop = p + rCode.getLength(); - const sal_Unicode* pBeg = p; // name begins here - bool bMod = false; - bool bDone = false; - while (p < pStop && !bDone) - { - switch (*p) - { - case '[': - bMod = true; - break; - case ']': - if (bMod) - { - bMod = false; - pBeg = p+1; - } - // else: would be a locale data error, easily to be spotted in - // UI dialog - break; - case ';': - if (!bMod) - { - bDone = true; - --p; // put back, increment by one follows - } - break; - } - ++p; - if (bMod) - pBeg = p; - } - if (pBeg < p) - aStr = rCode.copy( pBeg - rCode.getStr(), p - pBeg); - return aStr; -} - -void ImpSvNumberformatScan::SetDependentKeywords() -{ - using namespace ::com::sun::star; - using namespace ::com::sun::star::uno; - - const CharClass* pCharClass = pFormatter->GetCharClass(); - const LocaleDataWrapper* pLocaleData = pFormatter->GetLocaleData(); - // #80023# be sure to generate keywords for the loaded Locale, not for the - // requested Locale, otherwise number format codes might not match - lang::Locale aLoadedLocale = pLocaleData->getLoadedLocale(); - LanguageType eLang = MsLangId::convertLocaleToLanguage( aLoadedLocale ); - NumberFormatCodeWrapper aNumberFormatCode( pFormatter->GetServiceManager(), aLoadedLocale ); - - i18n::NumberFormatCode aFormat = aNumberFormatCode.getFormatCode( NF_NUMBER_STANDARD ); - sNameStandardFormat = lcl_extractStandardGeneralName( aFormat.Code); - sKeyword[NF_KEY_GENERAL] = pCharClass->upper( sNameStandardFormat ); - - // preset new calendar keywords - sKeyword[NF_KEY_AAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAA" ) ); - sKeyword[NF_KEY_AAAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAAA" ) ); - sKeyword[NF_KEY_EC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "E" ) ); - sKeyword[NF_KEY_EEC].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "EE" ) ); - sKeyword[NF_KEY_G].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "G" ) ); - sKeyword[NF_KEY_GG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GG" ) ); - sKeyword[NF_KEY_GGG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGG" ) ); - sKeyword[NF_KEY_R].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "R" ) ); - sKeyword[NF_KEY_RR].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "RR" ) ); - - // Thai T NatNum special. Other locale's small letter 't' results in upper - // case comparison not matching but length does in conversion mode. Ugly. - if (eLang == LANGUAGE_THAI) - sKeyword[NF_KEY_THAI_T].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "T")); - else - sKeyword[NF_KEY_THAI_T].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "t")); - - switch ( eLang ) - { - case LANGUAGE_GERMAN: - case LANGUAGE_GERMAN_SWISS: - case LANGUAGE_GERMAN_AUSTRIAN: - case LANGUAGE_GERMAN_LUXEMBOURG: - case LANGUAGE_GERMAN_LIECHTENSTEIN: - { - //! all capital letters - sKeyword[NF_KEY_M].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "M" ) ); // month 1 - sKeyword[NF_KEY_MM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MM" ) ); // month 01 - sKeyword[NF_KEY_MMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMM" ) ); // month Jan - sKeyword[NF_KEY_MMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMM" ) ); // month Januar - sKeyword[NF_KEY_MMMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMMM" ) );// month J - sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "H" ) ); // hour 2 - sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "HH" ) ); // hour 02 - sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "T" ) ); - sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TT" ) ); - sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TTT" ) ); - sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TTTT" ) ); - sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJ" ) ); - sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJJ" ) ); - sKeyword[NF_KEY_BOOLEAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "LOGISCH" ) ); - sKeyword[NF_KEY_COLOR].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "FARBE" ) ); - sKeyword[NF_KEY_BLACK].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "SCHWARZ" ) ); - sKeyword[NF_KEY_BLUE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLAU" ) ); - sKeyword[NF_KEY_GREEN] = UniString( "GR" "\xDC" "N", RTL_TEXTENCODING_ISO_8859_1 ); - sKeyword[NF_KEY_CYAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "CYAN" ) ); - sKeyword[NF_KEY_RED].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "ROT" ) ); - sKeyword[NF_KEY_MAGENTA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MAGENTA" ) ); - sKeyword[NF_KEY_BROWN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BRAUN" ) ); - sKeyword[NF_KEY_GREY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GRAU" ) ); - sKeyword[NF_KEY_YELLOW].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GELB" ) ); - sKeyword[NF_KEY_WHITE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "WEISS" ) ); - } - break; - default: - { - // day - switch ( eLang ) - { - case LANGUAGE_ITALIAN : - case LANGUAGE_ITALIAN_SWISS : - sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "G" ) ); - sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GG" ) ); - sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGG" ) ); - sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GGGG" ) ); - // must exchange the era code, same as Xcl - sKeyword[NF_KEY_G].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "X" ) ); - sKeyword[NF_KEY_GG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "XX" ) ); - sKeyword[NF_KEY_GGG].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "XXX" ) ); - break; - case LANGUAGE_FRENCH : - case LANGUAGE_FRENCH_BELGIAN : - case LANGUAGE_FRENCH_CANADIAN : - case LANGUAGE_FRENCH_SWISS : - case LANGUAGE_FRENCH_LUXEMBOURG : - case LANGUAGE_FRENCH_MONACO : - sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "J" ) ); - sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJ" ) ); - sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJ" ) ); - sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJJ" ) ); - break; - case LANGUAGE_FINNISH : - sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "P" ) ); - sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "PP" ) ); - sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "PPP" ) ); - sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "PPPP" ) ); - break; - default: - sKeyword[NF_KEY_D].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "D" ) ); - sKeyword[NF_KEY_DD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DD" ) ); - sKeyword[NF_KEY_DDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDD" ) ); - sKeyword[NF_KEY_DDDD].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDDD" ) ); - } - // month - switch ( eLang ) - { - case LANGUAGE_FINNISH : - sKeyword[NF_KEY_M].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "K" ) ); - sKeyword[NF_KEY_MM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KK" ) ); - sKeyword[NF_KEY_MMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KKK" ) ); - sKeyword[NF_KEY_MMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KKKK" ) ); - sKeyword[NF_KEY_MMMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "KKKKK" ) ); - break; - default: - sKeyword[NF_KEY_M].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "M" ) ); - sKeyword[NF_KEY_MM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MM" ) ); - sKeyword[NF_KEY_MMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMM" ) ); - sKeyword[NF_KEY_MMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMM" ) ); - sKeyword[NF_KEY_MMMMM].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MMMMM" ) ); - } - // year - switch ( eLang ) - { - case LANGUAGE_ITALIAN : - case LANGUAGE_ITALIAN_SWISS : - case LANGUAGE_FRENCH : - case LANGUAGE_FRENCH_BELGIAN : - case LANGUAGE_FRENCH_CANADIAN : - case LANGUAGE_FRENCH_SWISS : - case LANGUAGE_FRENCH_LUXEMBOURG : - case LANGUAGE_FRENCH_MONACO : - case LANGUAGE_PORTUGUESE : - case LANGUAGE_PORTUGUESE_BRAZILIAN : - case LANGUAGE_SPANISH_MODERN : - case LANGUAGE_SPANISH_DATED : - case LANGUAGE_SPANISH_MEXICAN : - case LANGUAGE_SPANISH_GUATEMALA : - case LANGUAGE_SPANISH_COSTARICA : - case LANGUAGE_SPANISH_PANAMA : - case LANGUAGE_SPANISH_DOMINICAN_REPUBLIC : - case LANGUAGE_SPANISH_VENEZUELA : - case LANGUAGE_SPANISH_COLOMBIA : - case LANGUAGE_SPANISH_PERU : - case LANGUAGE_SPANISH_ARGENTINA : - case LANGUAGE_SPANISH_ECUADOR : - case LANGUAGE_SPANISH_CHILE : - case LANGUAGE_SPANISH_URUGUAY : - case LANGUAGE_SPANISH_PARAGUAY : - case LANGUAGE_SPANISH_BOLIVIA : - case LANGUAGE_SPANISH_EL_SALVADOR : - case LANGUAGE_SPANISH_HONDURAS : - case LANGUAGE_SPANISH_NICARAGUA : - case LANGUAGE_SPANISH_PUERTO_RICO : - sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AA" ) ); - sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "AAAA" ) ); - // must exchange the day of week name code, same as Xcl - sKeyword[NF_KEY_AAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "OOO" ) ); - sKeyword[NF_KEY_AAAA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "OOOO" ) ); - break; - case LANGUAGE_DUTCH : - case LANGUAGE_DUTCH_BELGIAN : - sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJ" ) ); - sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "JJJJ" ) ); - break; - case LANGUAGE_FINNISH : - sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "VV" ) ); - sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "VVVV" ) ); - break; - default: - sKeyword[NF_KEY_YY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YY" ) ); - sKeyword[NF_KEY_YYYY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YYYY" ) ); - } - // hour - switch ( eLang ) - { - case LANGUAGE_DUTCH : - case LANGUAGE_DUTCH_BELGIAN : - sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "U" ) ); - sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "UU" ) ); - break; - case LANGUAGE_FINNISH : - case LANGUAGE_SWEDISH : - case LANGUAGE_SWEDISH_FINLAND : - case LANGUAGE_DANISH : - case LANGUAGE_NORWEGIAN : - case LANGUAGE_NORWEGIAN_BOKMAL : - case LANGUAGE_NORWEGIAN_NYNORSK : - sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "T" ) ); - sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "TT" ) ); - break; - default: - sKeyword[NF_KEY_H].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "H" ) ); - sKeyword[NF_KEY_HH].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "HH" ) ); - } - // boolean - sKeyword[NF_KEY_BOOLEAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BOOLEAN" ) ); - // colours - sKeyword[NF_KEY_COLOR].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "COLOR" ) ); - sKeyword[NF_KEY_BLACK].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLACK" ) ); - sKeyword[NF_KEY_BLUE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BLUE" ) ); - sKeyword[NF_KEY_GREEN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GREEN" ) ); - sKeyword[NF_KEY_CYAN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "CYAN" ) ); - sKeyword[NF_KEY_RED].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "RED" ) ); - sKeyword[NF_KEY_MAGENTA].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "MAGENTA" ) ); - sKeyword[NF_KEY_BROWN].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "BROWN" ) ); - sKeyword[NF_KEY_GREY].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "GREY" ) ); - sKeyword[NF_KEY_YELLOW].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "YELLOW" ) ); - sKeyword[NF_KEY_WHITE].AssignAscii( RTL_CONSTASCII_STRINGPARAM( "WHITE" ) ); - } - break; - } - - // boolean keyords - InitSpecialKeyword( NF_KEY_TRUE ); - InitSpecialKeyword( NF_KEY_FALSE ); - - // compatibility currency strings - InitCompatCur(); -} - -void ImpSvNumberformatScan::ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear) -{ - if ( pNullDate ) - *pNullDate = Date(nDay, nMonth, nYear); - else - pNullDate = new Date(nDay, nMonth, nYear); -} - -void ImpSvNumberformatScan::ChangeStandardPrec(sal_uInt16 nPrec) -{ - nStandardPrec = nPrec; -} - -Color* ImpSvNumberformatScan::GetColor(String& sStr) -{ - String sString = pFormatter->GetCharClass()->upper(sStr); - const NfKeywordTable & rKeyword = GetKeywords(); - size_t i = 0; - while (i < NF_MAX_DEFAULT_COLORS && - sString != rKeyword[NF_KEY_FIRSTCOLOR+i] ) - i++; - if ( i >= NF_MAX_DEFAULT_COLORS ) - { - const String* pEnglishColors = theEnglishColors::get(); - size_t j = 0; - while ( j < NF_MAX_DEFAULT_COLORS && - sString != pEnglishColors[j] ) - ++j; - if ( j < NF_MAX_DEFAULT_COLORS ) - i = j; - } - - Color* pResult = NULL; - if (i >= NF_MAX_DEFAULT_COLORS) - { - const String& rColorWord = rKeyword[NF_KEY_COLOR]; - xub_StrLen nPos = sString.Match(rColorWord); - if (nPos > 0) - { - sStr.Erase(0, nPos); - sStr.EraseLeadingChars(); - sStr.EraseTrailingChars(); - if (bConvertMode) - { - pFormatter->ChangeIntl(eNewLnge); - sStr.Insert( GetKeywords()[NF_KEY_COLOR], 0 ); // Color -> FARBE - pFormatter->ChangeIntl(eTmpLnge); - } - else - sStr.Insert(rColorWord,0); - sString.Erase(0, nPos); - sString.EraseLeadingChars(); - sString.EraseTrailingChars(); - - if ( CharClass::isAsciiNumeric( sString ) ) - { - long nIndex = sString.ToInt32(); - if (nIndex > 0 && nIndex <= 64) - pResult = pFormatter->GetUserDefColor((sal_uInt16)nIndex-1); - } - } - } - else - { - sStr.Erase(); - if (bConvertMode) - { - pFormatter->ChangeIntl(eNewLnge); - sStr = GetKeywords()[NF_KEY_FIRSTCOLOR+i]; // red -> rot - pFormatter->ChangeIntl(eTmpLnge); - } - else - sStr = rKeyword[NF_KEY_FIRSTCOLOR+i]; - - pResult = &(StandardColor[i]); - } - return pResult; -} - -short ImpSvNumberformatScan::GetKeyWord( const String& sSymbol, xub_StrLen nPos ) -{ - String sString = pFormatter->GetCharClass()->toUpper( sSymbol, nPos, sSymbol.Len() - nPos ); - const NfKeywordTable & rKeyword = GetKeywords(); - // #77026# for the Xcl perverts: the GENERAL keyword is recognized anywhere - if ( sString.Search( rKeyword[NF_KEY_GENERAL] ) == 0 ) - return NF_KEY_GENERAL; - //! MUST be a reverse search to find longer strings first - short i = NF_KEYWORD_ENTRIES_COUNT-1; - sal_Bool bFound = sal_False; - for ( ; i > NF_KEY_LASTKEYWORD_SO5; --i ) - { - bFound = sString.Search(rKeyword[i]) == 0; - if ( bFound ) - { - break; - } - } - // new keywords take precedence over old keywords - if ( !bFound ) - { // skip the gap of colors et al between new and old keywords and search on - i = NF_KEY_LASTKEYWORD; - while ( i > 0 && sString.Search(rKeyword[i]) != 0 ) - i--; - if ( i > NF_KEY_LASTOLDKEYWORD && sString != rKeyword[i] ) - { // found something, but maybe it's something else? - // e.g. new NNN is found in NNNN, for NNNN we must search on - short j = i - 1; - while ( j > 0 && sString.Search(rKeyword[j]) != 0 ) - j--; - if ( j && rKeyword[j].Len() > rKeyword[i].Len() ) - return j; - } - } - // The Thai T NatNum modifier during Xcl import. - if (i == 0 && bConvertMode && sString.GetChar(0) == 'T' && eTmpLnge == - LANGUAGE_ENGLISH_US && MsLangId::getRealLanguage( eNewLnge) == - LANGUAGE_THAI) - i = NF_KEY_THAI_T; - return i; // 0 => not found -} - -//--------------------------------------------------------------------------- -// Next_Symbol -//--------------------------------------------------------------------------- -// Zerlegt die Eingabe in Symbole fuer die weitere -// Verarbeitung (Turing-Maschine). -//--------------------------------------------------------------------------- -// Ausgangs Zustand = SsStart -//---------------+-------------------+-----------------------+--------------- -// Alter Zustand | gelesenes Zeichen | Aktion | Neuer Zustand -//---------------+-------------------+-----------------------+--------------- -// SsStart | Buchstabe | Symbol=Zeichen | SsGetWord -// | " | Typ = String | SsGetString -// | \ | Typ = String | SsGetChar -// | * | Typ = Star | SsGetStar -// | _ | Typ = Blank | SsGetBlank -// | @ # 0 ? / . , % [ | Symbol = Zeichen; | -// | ] ' Blank | Typ = Steuerzeichen | SsStop -// | $ - + ( ) : | Typ = String; | -// | | | Typ = Comment | SsStop -// | Sonst | Symbol = Zeichen | SsStop -//---------------|-------------------+-----------------------+--------------- -// SsGetChar | Sonst | Symbol=Zeichen | SsStop -//---------------+-------------------+-----------------------+--------------- -// GetString | " | | SsStop -// | Sonst | Symbol+=Zeichen | GetString -//---------------+-------------------+-----------------------+--------------- -// SsGetWord | Buchstabe | Symbol += Zeichen | -// | + - (E+ E-)| Symbol += Zeichen | SsStop -// | / (AM/PM)| Symbol += Zeichen | -// | Sonst | Pos--, if Key Typ=Word| SsStop -//---------------+-------------------+-----------------------+--------------- -// SsGetStar | Sonst | Symbol+=Zeichen | SsStop -// | | markiere Sonderfall * | -//---------------+-------------------+-----------------------+--------------- -// SsGetBlank | Sonst | Symbol+=Zeichen | SsStop -// | | markiere Sonderfall _ | -//---------------+-------------------+-----------------------+--------------- -// Wurde im State SsGetWord ein Schluesselwort erkannt (auch als -// Anfangsteilwort des Symbols) -// so werden die restlichen Buchstaben zurueckgeschrieben !! - -enum ScanState -{ - SsStop = 0, - SsStart = 1, - SsGetChar = 2, - SsGetString = 3, - SsGetWord = 4, - SsGetStar = 5, - SsGetBlank = 6 -}; - -short ImpSvNumberformatScan::Next_Symbol( const String& rStr, - xub_StrLen& nPos, String& sSymbol ) -{ - if ( bKeywordsNeedInit ) - InitKeywords(); - const CharClass* pChrCls = pFormatter->GetCharClass(); - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - const xub_StrLen nStart = nPos; - short eType = 0; - ScanState eState = SsStart; - sSymbol.Erase(); - while ( nPos < rStr.Len() && eState != SsStop ) - { - sal_Unicode cToken = rStr.GetChar( nPos++ ); - switch (eState) - { - case SsStart: - { - // Fetch any currency longer than one character and don't get - // confused later on by "E/" or other combinations of letters - // and meaningful symbols. Necessary for old automatic currency. - // #96158# But don't do it if we're starting a "[...]" section, - // for example a "[$...]" new currency symbol to not parse away - // "$U" (symbol) of "[$UYU]" (abbreviation). - if ( nCurrPos != STRING_NOTFOUND && sCurString.Len() > 1 && - nPos-1 + sCurString.Len() <= rStr.Len() && - !(nPos > 1 && rStr.GetChar( nPos-2 ) == '[') ) - { - String aTest( rStr.Copy( nPos-1, sCurString.Len() ) ); - pChrCls->toUpper( aTest ); - if ( aTest == sCurString ) - { - sSymbol = rStr.Copy( --nPos, sCurString.Len() ); - nPos = nPos + sSymbol.Len(); - eState = SsStop; - eType = NF_SYMBOLTYPE_STRING; - return eType; - } - } - switch (cToken) - { - case '#': - case '0': - case '?': - case '%': - case '@': - case '[': - case ']': - case ',': - case '.': - case '/': - case '\'': - case ' ': - case ':': - case '-': - { - eType = NF_SYMBOLTYPE_DEL; - sSymbol += cToken; - eState = SsStop; - } - break; - case '*': - { - eType = NF_SYMBOLTYPE_STAR; - sSymbol += cToken; - eState = SsGetStar; - } - break; - case '_': - { - eType = NF_SYMBOLTYPE_BLANK; - sSymbol += cToken; - eState = SsGetBlank; - } - break; -#if NF_COMMENT_IN_FORMATSTRING - case '{': - eType = NF_SYMBOLTYPE_COMMENT; - eState = SsStop; - sSymbol.Append( rStr.GetBuffer() + (nPos-1), rStr.Len() - (nPos-1) ); - nPos = rStr.Len(); - break; -#endif - case '"': - eType = NF_SYMBOLTYPE_STRING; - eState = SsGetString; - sSymbol += cToken; - break; - case '\\': - eType = NF_SYMBOLTYPE_STRING; - eState = SsGetChar; - sSymbol += cToken; - break; - case '$': - case '+': - case '(': - case ')': - eType = NF_SYMBOLTYPE_STRING; - eState = SsStop; - sSymbol += cToken; - break; - default : - { - if (StringEqualsChar( pFormatter->GetNumDecimalSep(), cToken) || - StringEqualsChar( pFormatter->GetNumThousandSep(), cToken) || - StringEqualsChar( pFormatter->GetDateSep(), cToken) || - StringEqualsChar( pLoc->getTimeSep(), cToken) || - StringEqualsChar( pLoc->getTime100SecSep(), cToken)) - { - // Another separator than pre-known ASCII - eType = NF_SYMBOLTYPE_DEL; - sSymbol += cToken; - eState = SsStop; - } - else if ( pChrCls->isLetter( rStr, nPos-1 ) ) - { - short nTmpType = GetKeyWord( rStr, nPos-1 ); - if ( nTmpType ) - { - sal_Bool bCurrency = sal_False; - // "Automatic" currency may start with keyword, - // like "R" (Rand) and 'R' (era) - if ( nCurrPos != STRING_NOTFOUND && - nPos-1 + sCurString.Len() <= rStr.Len() && - sCurString.Search( sKeyword[nTmpType] ) == 0 ) - { - String aTest( rStr.Copy( nPos-1, sCurString.Len() ) ); - pChrCls->toUpper( aTest ); - if ( aTest == sCurString ) - bCurrency = sal_True; - } - if ( bCurrency ) - { - eState = SsGetWord; - sSymbol += cToken; - } - else - { - eType = nTmpType; - xub_StrLen nLen = sKeyword[eType].Len(); - sSymbol = rStr.Copy( nPos-1, nLen ); - if ( eType == NF_KEY_E || IsAmbiguousE( eType ) ) - { - sal_Unicode cNext = rStr.GetChar(nPos); - switch ( cNext ) - { - case '+' : - case '-' : // E+ E- combine to one symbol - sSymbol += cNext; - eType = NF_KEY_E; - nPos++; - break; - case '0' : - case '#' : // scientific E without sign - eType = NF_KEY_E; - break; - } - } - nPos--; - nPos = nPos + nLen; - eState = SsStop; - } - } - else - { - eState = SsGetWord; - sSymbol += cToken; - } - } - else - { - eType = NF_SYMBOLTYPE_STRING; - eState = SsStop; - sSymbol += cToken; - } - } - break; - } - } - break; - case SsGetChar: - { - sSymbol += cToken; - eState = SsStop; - } - break; - case SsGetString: - { - if (cToken == '"') - eState = SsStop; - sSymbol += cToken; - } - break; - case SsGetWord: - { - if ( pChrCls->isLetter( rStr, nPos-1 ) ) - { - short nTmpType = GetKeyWord( rStr, nPos-1 ); - if ( nTmpType ) - { // beginning of keyword, stop scan and put back - eType = NF_SYMBOLTYPE_STRING; - eState = SsStop; - nPos--; - } - else - sSymbol += cToken; - } - else - { - sal_Bool bDontStop = sal_False; - switch (cToken) - { - case '/': // AM/PM, A/P - { - sal_Unicode cNext = rStr.GetChar(nPos); - if ( cNext == 'P' || cNext == 'p' ) - { - xub_StrLen nLen = sSymbol.Len(); - if ( 1 <= nLen - && (sSymbol.GetChar(0) == 'A' || sSymbol.GetChar(0) == 'a') - && (nLen == 1 || (nLen == 2 - && (sSymbol.GetChar(1) == 'M' || sSymbol.GetChar(1) == 'm') - && (rStr.GetChar(nPos+1) == 'M' || rStr.GetChar(nPos+1) == 'm'))) ) - { - sSymbol += cToken; - bDontStop = sal_True; - } - } - } - break; - } - // anything not recognized will stop the scan - if ( eState != SsStop && !bDontStop ) - { - eState = SsStop; - nPos--; - eType = NF_SYMBOLTYPE_STRING; - } - } - } - break; - case SsGetStar: - { - eState = SsStop; - sSymbol += cToken; - nRepPos = (nPos - nStart) - 1; // everytime > 0!! - } - break; - case SsGetBlank: - { - eState = SsStop; - sSymbol += cToken; - } - break; - default: - break; - } // of switch - } // of while - if (eState == SsGetWord) - eType = NF_SYMBOLTYPE_STRING; - return eType; -} - -xub_StrLen ImpSvNumberformatScan::Symbol_Division(const String& rString) -{ - nCurrPos = STRING_NOTFOUND; - // Ist Waehrung im Spiel? - String sString = pFormatter->GetCharClass()->upper(rString); - xub_StrLen nCPos = 0; - while (nCPos != STRING_NOTFOUND) - { - nCPos = sString.Search(GetCurString(),nCPos); - if (nCPos != STRING_NOTFOUND) - { - // in Quotes? - xub_StrLen nQ = SvNumberformat::GetQuoteEnd( sString, nCPos ); - if ( nQ == STRING_NOTFOUND ) - { - sal_Unicode c; - if ( nCPos == 0 || - ((c = sString.GetChar(xub_StrLen(nCPos-1))) != '"' - && c != '\\') ) // dm kann durch "dm - { // \d geschuetzt werden - nCurrPos = nCPos; - nCPos = STRING_NOTFOUND; // Abbruch - } - else - nCPos++; // weitersuchen - } - else - nCPos = nQ + 1; // weitersuchen - } - } - nAnzStrings = 0; - sal_Bool bStar = sal_False; // wird bei '*'Detektion gesetzt - Reset(); - - xub_StrLen nPos = 0; - const xub_StrLen nLen = rString.Len(); - while (nPos < nLen && nAnzStrings < NF_MAX_FORMAT_SYMBOLS) - { - nTypeArray[nAnzStrings] = Next_Symbol(rString, nPos, sStrArray[nAnzStrings]); - if (nTypeArray[nAnzStrings] == NF_SYMBOLTYPE_STAR) - { // Ueberwachung des '*' - if (bStar) - return nPos; // Fehler: doppelter '*' - else - bStar = sal_True; - } - nAnzStrings++; - } - - return 0; // 0 => ok -} - -void ImpSvNumberformatScan::SkipStrings(sal_uInt16& i, xub_StrLen& nPos) -{ - while (i < nAnzStrings && ( nTypeArray[i] == NF_SYMBOLTYPE_STRING - || nTypeArray[i] == NF_SYMBOLTYPE_BLANK - || nTypeArray[i] == NF_SYMBOLTYPE_STAR) ) - { - nPos = nPos + sStrArray[i].Len(); - i++; - } -} - -sal_uInt16 ImpSvNumberformatScan::PreviousKeyword(sal_uInt16 i) -{ - short res = 0; - if (i > 0 && i < nAnzStrings) - { - i--; - while (i > 0 && nTypeArray[i] <= 0) - i--; - if (nTypeArray[i] > 0) - res = nTypeArray[i]; - } - return res; -} - -sal_uInt16 ImpSvNumberformatScan::NextKeyword(sal_uInt16 i) -{ - short res = 0; - if (i < nAnzStrings-1) - { - i++; - while (i < nAnzStrings-1 && nTypeArray[i] <= 0) - i++; - if (nTypeArray[i] > 0) - res = nTypeArray[i]; - } - return res; -} - -short ImpSvNumberformatScan::PreviousType( sal_uInt16 i ) -{ - if ( i > 0 && i < nAnzStrings ) - { - do - { - i--; - } while ( i > 0 && nTypeArray[i] == NF_SYMBOLTYPE_EMPTY ); - return nTypeArray[i]; - } - return 0; -} - -sal_Unicode ImpSvNumberformatScan::PreviousChar(sal_uInt16 i) -{ - sal_Unicode res = ' '; - if (i > 0 && i < nAnzStrings) - { - i--; - while (i > 0 && ( nTypeArray[i] == NF_SYMBOLTYPE_EMPTY - || nTypeArray[i] == NF_SYMBOLTYPE_STRING - || nTypeArray[i] == NF_SYMBOLTYPE_STAR - || nTypeArray[i] == NF_SYMBOLTYPE_BLANK ) ) - i--; - if (sStrArray[i].Len() > 0) - res = sStrArray[i].GetChar(xub_StrLen(sStrArray[i].Len()-1)); - } - return res; -} - -sal_Unicode ImpSvNumberformatScan::NextChar(sal_uInt16 i) -{ - sal_Unicode res = ' '; - if (i < nAnzStrings-1) - { - i++; - while (i < nAnzStrings-1 && - ( nTypeArray[i] == NF_SYMBOLTYPE_EMPTY - || nTypeArray[i] == NF_SYMBOLTYPE_STRING - || nTypeArray[i] == NF_SYMBOLTYPE_STAR - || nTypeArray[i] == NF_SYMBOLTYPE_BLANK)) - i++; - if (sStrArray[i].Len() > 0) - res = sStrArray[i].GetChar(0); - } - return res; -} - -sal_Bool ImpSvNumberformatScan::IsLastBlankBeforeFrac(sal_uInt16 i) -{ - sal_Bool res = sal_True; - if (i < nAnzStrings-1) - { - sal_Bool bStop = sal_False; - i++; - while (i < nAnzStrings-1 && !bStop) - { - i++; - if ( nTypeArray[i] == NF_SYMBOLTYPE_DEL && - sStrArray[i].GetChar(0) == '/') - bStop = sal_True; - else if ( nTypeArray[i] == NF_SYMBOLTYPE_DEL && - sStrArray[i].GetChar(0) == ' ') - res = sal_False; - } - if (!bStop) // kein '/' - res = sal_False; - } - else - res = sal_False; // kein '/' mehr - - return res; -} - -void ImpSvNumberformatScan::Reset() -{ - nAnzStrings = 0; - nAnzResStrings = 0; -#if 0 -// ER 20.06.97 14:05 nicht noetig, wenn nAnzStrings beachtet wird - for (size_t i = 0; i < NF_MAX_FORMAT_SYMBOLS; i++) - { - sStrArray[i].Erase(); - nTypeArray[i] = 0; - } -#endif - eScannedType = NUMBERFORMAT_UNDEFINED; - nRepPos = 0; - bExp = sal_False; - bThousand = sal_False; - nThousand = 0; - bDecSep = sal_False; - nDecPos = -1; - nExpPos = (sal_uInt16) -1; - nBlankPos = (sal_uInt16) -1; - nCntPre = 0; - nCntPost = 0; - nCntExp = 0; - bFrac = sal_False; - bBlank = sal_False; - nNatNumModifier = 0; -} - -sal_Bool ImpSvNumberformatScan::Is100SecZero( sal_uInt16 i, sal_Bool bHadDecSep ) -{ - sal_uInt16 nIndexPre = PreviousKeyword( i ); - return (nIndexPre == NF_KEY_S || nIndexPre == NF_KEY_SS) - && (bHadDecSep // S, SS ',' - || (i>0 && nTypeArray[i-1] == NF_SYMBOLTYPE_STRING)); - // SS"any"00 take "any" as a valid decimal separator -} - -xub_StrLen ImpSvNumberformatScan::ScanType(const String&) -{ - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - - xub_StrLen nPos = 0; - sal_uInt16 i = 0; - short eNewType; - sal_Bool bMatchBracket = sal_False; - bool bHaveGeneral = false; // if General/Standard encountered - - SkipStrings(i, nPos); - while (i < nAnzStrings) - { - if (nTypeArray[i] > 0) - { // keyword - switch (nTypeArray[i]) - { - case NF_KEY_E: // E - eNewType = NUMBERFORMAT_SCIENTIFIC; - break; - case NF_KEY_AMPM: // AM,A,PM,P - case NF_KEY_AP: - case NF_KEY_H: // H - case NF_KEY_HH: // HH - case NF_KEY_S: // S - case NF_KEY_SS: // SS - eNewType = NUMBERFORMAT_TIME; - break; - case NF_KEY_M: // M - case NF_KEY_MM: // MM - { // minute or month - sal_uInt16 nIndexPre = PreviousKeyword(i); - sal_uInt16 nIndexNex = NextKeyword(i); - sal_Unicode cChar = PreviousChar(i); - if (nIndexPre == NF_KEY_H || // H - nIndexPre == NF_KEY_HH || // HH - nIndexNex == NF_KEY_S || // S - nIndexNex == NF_KEY_SS || // SS - cChar == '[' ) // [M - { - eNewType = NUMBERFORMAT_TIME; - nTypeArray[i] -= 2; // 6 -> 4, 7 -> 5 - } - else - eNewType = NUMBERFORMAT_DATE; - } - break; - case NF_KEY_MMM: // MMM - case NF_KEY_MMMM: // MMMM - case NF_KEY_MMMMM: // MMMMM - case NF_KEY_Q: // Q - case NF_KEY_QQ: // QQ - case NF_KEY_D: // D - case NF_KEY_DD: // DD - case NF_KEY_DDD: // DDD - case NF_KEY_DDDD: // DDDD - case NF_KEY_YY: // YY - case NF_KEY_YYYY: // YYYY - case NF_KEY_NN: // NN - case NF_KEY_NNN: // NNN - case NF_KEY_NNNN: // NNNN - case NF_KEY_WW : // WW - case NF_KEY_AAA : // AAA - case NF_KEY_AAAA : // AAAA - case NF_KEY_EC : // E - case NF_KEY_EEC : // EE - case NF_KEY_G : // G - case NF_KEY_GG : // GG - case NF_KEY_GGG : // GGG - case NF_KEY_R : // R - case NF_KEY_RR : // RR - eNewType = NUMBERFORMAT_DATE; - break; - case NF_KEY_CCC: // CCC - eNewType = NUMBERFORMAT_CURRENCY; - break; - case NF_KEY_GENERAL: // Standard - eNewType = NUMBERFORMAT_NUMBER; - bHaveGeneral = true; - break; - default: - eNewType = NUMBERFORMAT_UNDEFINED; - break; - } - } - else - { // control character - switch ( sStrArray[i].GetChar(0) ) - { - case '#': - case '?': - eNewType = NUMBERFORMAT_NUMBER; - break; - case '0': - { - if ( (eScannedType & NUMBERFORMAT_TIME) == NUMBERFORMAT_TIME ) - { - if ( Is100SecZero( i, bDecSep ) ) - { - bDecSep = sal_True; // subsequent 0's - eNewType = NUMBERFORMAT_TIME; - } - else - return nPos; // Error - } - else - eNewType = NUMBERFORMAT_NUMBER; - } - break; - case '%': - eNewType = NUMBERFORMAT_PERCENT; - break; - case '/': - eNewType = NUMBERFORMAT_FRACTION; - break; - case '[': - { - if ( i < nAnzStrings-1 && - nTypeArray[i+1] == NF_SYMBOLTYPE_STRING && - sStrArray[i+1].GetChar(0) == '$' ) - { // as of SV_NUMBERFORMATTER_VERSION_NEW_CURR - eNewType = NUMBERFORMAT_CURRENCY; - bMatchBracket = sal_True; - } - else if ( i < nAnzStrings-1 && - nTypeArray[i+1] == NF_SYMBOLTYPE_STRING && - sStrArray[i+1].GetChar(0) == '~' ) - { // as of SV_NUMBERFORMATTER_VERSION_CALENDAR - eNewType = NUMBERFORMAT_DATE; - bMatchBracket = sal_True; - } - else - { - sal_uInt16 nIndexNex = NextKeyword(i); - if (nIndexNex == NF_KEY_H || // H - nIndexNex == NF_KEY_HH || // HH - nIndexNex == NF_KEY_M || // M - nIndexNex == NF_KEY_MM || // MM - nIndexNex == NF_KEY_S || // S - nIndexNex == NF_KEY_SS ) // SS - eNewType = NUMBERFORMAT_TIME; - else - return nPos; // Error - } - } - break; - case '@': - eNewType = NUMBERFORMAT_TEXT; - break; - default: - if ( sStrArray[i] == pLoc->getTime100SecSep() ) - bDecSep = sal_True; // for SS,0 - eNewType = NUMBERFORMAT_UNDEFINED; - break; - } - } - if (eScannedType == NUMBERFORMAT_UNDEFINED) - eScannedType = eNewType; - else if (eScannedType == NUMBERFORMAT_TEXT || eNewType == NUMBERFORMAT_TEXT) - eScannedType = NUMBERFORMAT_TEXT; // Text bleibt immer Text - else if (eNewType == NUMBERFORMAT_UNDEFINED) - { // bleibt wie bisher - } - else if (eScannedType != eNewType) - { - switch (eScannedType) - { - case NUMBERFORMAT_DATE: - { - switch (eNewType) - { - case NUMBERFORMAT_TIME: - eScannedType = NUMBERFORMAT_DATETIME; - break; - case NUMBERFORMAT_FRACTION: // DD/MM - break; - default: - { - if (nCurrPos != STRING_NOTFOUND) - eScannedType = NUMBERFORMAT_UNDEFINED; - else if ( sStrArray[i] != pFormatter->GetDateSep() ) - return nPos; - } - } - } - break; - case NUMBERFORMAT_TIME: - { - switch (eNewType) - { - case NUMBERFORMAT_DATE: - eScannedType = NUMBERFORMAT_DATETIME; - break; - case NUMBERFORMAT_FRACTION: // MM/SS - break; - default: - { - if (nCurrPos != STRING_NOTFOUND) - eScannedType = NUMBERFORMAT_UNDEFINED; - else if ( sStrArray[i] != pLoc->getTimeSep() ) - return nPos; - } - } - } - break; - case NUMBERFORMAT_DATETIME: - { - switch (eNewType) - { - case NUMBERFORMAT_TIME: - case NUMBERFORMAT_DATE: - break; - case NUMBERFORMAT_FRACTION: // DD/MM - break; - default: - { - if (nCurrPos != STRING_NOTFOUND) - eScannedType = NUMBERFORMAT_UNDEFINED; - else if ( sStrArray[i] != pFormatter->GetDateSep() - && sStrArray[i] != pLoc->getTimeSep() ) - return nPos; - } - } - } - break; - case NUMBERFORMAT_PERCENT: - { - switch (eNewType) - { - case NUMBERFORMAT_NUMBER: // nur Zahl nach Prozent - break; - default: - return nPos; - } - } - break; - case NUMBERFORMAT_SCIENTIFIC: - { - switch (eNewType) - { - case NUMBERFORMAT_NUMBER: // nur Zahl nach E - break; - default: - return nPos; - } - } - break; - case NUMBERFORMAT_NUMBER: - { - switch (eNewType) - { - case NUMBERFORMAT_SCIENTIFIC: - case NUMBERFORMAT_PERCENT: - case NUMBERFORMAT_FRACTION: - case NUMBERFORMAT_CURRENCY: - eScannedType = eNewType; - break; - default: - if (nCurrPos != STRING_NOTFOUND) - eScannedType = NUMBERFORMAT_UNDEFINED; - else - return nPos; - } - } - break; - case NUMBERFORMAT_FRACTION: - { - switch (eNewType) - { - case NUMBERFORMAT_NUMBER: // nur Zahl nach Bruch - break; - default: - return nPos; - } - } - break; - default: - break; - } - } - nPos = nPos + sStrArray[i].Len(); // Korrekturposition - i++; - if ( bMatchBracket ) - { // no type detection inside of matching brackets if [$...], [~...] - while ( bMatchBracket && i < nAnzStrings ) - { - if ( nTypeArray[i] == NF_SYMBOLTYPE_DEL - && sStrArray[i].GetChar(0) == ']' ) - bMatchBracket = sal_False; - else - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - if ( bMatchBracket ) - return nPos; // missing closing bracket at end of code - } - SkipStrings(i, nPos); - } - - if ((eScannedType == NUMBERFORMAT_NUMBER || eScannedType == NUMBERFORMAT_UNDEFINED) - && nCurrPos != STRING_NOTFOUND && !bHaveGeneral) - eScannedType = NUMBERFORMAT_CURRENCY; // old "automatic" currency - if (eScannedType == NUMBERFORMAT_UNDEFINED) - eScannedType = NUMBERFORMAT_DEFINED; - return 0; // Alles ok -} - -bool ImpSvNumberformatScan::InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const String& rStr ) -{ - if (nAnzStrings >= NF_MAX_FORMAT_SYMBOLS || nPos > nAnzStrings) - return false; - if (nPos > 0 && nTypeArray[nPos-1] == NF_SYMBOLTYPE_EMPTY) - --nPos; // reuse position - else - { - if ((size_t) (nAnzStrings + 1) >= NF_MAX_FORMAT_SYMBOLS) - return false; - ++nAnzStrings; - for (size_t i = nAnzStrings; i > nPos; --i) - { - nTypeArray[i] = nTypeArray[i-1]; - sStrArray[i] = sStrArray[i-1]; - } - } - ++nAnzResStrings; - nTypeArray[nPos] = static_cast<short>(eType); - sStrArray[nPos] = rStr; - return true; -} - -int ImpSvNumberformatScan::FinalScanGetCalendar( xub_StrLen& nPos, sal_uInt16& i, - sal_uInt16& rAnzResStrings ) -{ - if ( sStrArray[i].GetChar(0) == '[' && - i < nAnzStrings-1 && - nTypeArray[i+1] == NF_SYMBOLTYPE_STRING && - sStrArray[i+1].GetChar(0) == '~' ) - { // [~calendarID] - // as of SV_NUMBERFORMATTER_VERSION_CALENDAR - nPos = nPos + sStrArray[i].Len(); // [ - nTypeArray[i] = NF_SYMBOLTYPE_CALDEL; - nPos = nPos + sStrArray[++i].Len(); // ~ - sStrArray[i-1] += sStrArray[i]; // [~ - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - rAnzResStrings--; - if ( ++i >= nAnzStrings ) - return -1; // error - nPos = nPos + sStrArray[i].Len(); // calendarID - String& rStr = sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_CALENDAR; // convert - i++; - while ( i < nAnzStrings && - sStrArray[i].GetChar(0) != ']' ) - { - nPos = nPos + sStrArray[i].Len(); - rStr += sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - rAnzResStrings--; - i++; - } - if ( rStr.Len() && i < nAnzStrings && - sStrArray[i].GetChar(0) == ']' ) - { - nTypeArray[i] = NF_SYMBOLTYPE_CALDEL; - nPos = nPos + sStrArray[i].Len(); - i++; - } - else - return -1; // error - return 1; - } - return 0; -} - -xub_StrLen ImpSvNumberformatScan::FinalScan( String& rString, String& rComment ) -{ - const LocaleDataWrapper* pLoc = pFormatter->GetLocaleData(); - - // save values for convert mode - String sOldDecSep = pFormatter->GetNumDecimalSep(); - String sOldThousandSep = pFormatter->GetNumThousandSep(); - String sOldDateSep = pFormatter->GetDateSep(); - String sOldTimeSep = pLoc->getTimeSep(); - String sOldTime100SecSep= pLoc->getTime100SecSep(); - String sOldCurSymbol = GetCurSymbol(); - String sOldCurString = GetCurString(); - sal_Unicode cOldKeyH = sKeyword[NF_KEY_H].GetChar(0); - sal_Unicode cOldKeyMI = sKeyword[NF_KEY_MI].GetChar(0); - sal_Unicode cOldKeyS = sKeyword[NF_KEY_S].GetChar(0); - - // If the group separator is a Non-Breaking Space (French) continue with a - // normal space instead so queries on space work correctly. - // The format string is adjusted to allow both. - // For output of the format code string the LocaleData characters are used. - if ( sOldThousandSep.GetChar(0) == cNonBreakingSpace && sOldThousandSep.Len() == 1 ) - sOldThousandSep = ' '; - - // change locale data et al - if (bConvertMode) - { - pFormatter->ChangeIntl(eNewLnge); - //! pointer may have changed - pLoc = pFormatter->GetLocaleData(); - //! init new keywords - InitKeywords(); - } - const CharClass* pChrCls = pFormatter->GetCharClass(); - - xub_StrLen nPos = 0; // error correction position - sal_uInt16 i = 0; // symbol loop counter - sal_uInt16 nCounter = 0; // counts digits - nAnzResStrings = nAnzStrings; // counts remaining symbols - bDecSep = sal_False; // reset in case already used in TypeCheck - bool bThaiT = false; // Thai T NatNum modifier present - - switch (eScannedType) - { - case NUMBERFORMAT_TEXT: - case NUMBERFORMAT_DEFINED: - { - while (i < nAnzStrings) - { - switch (nTypeArray[i]) - { - case NF_SYMBOLTYPE_BLANK: - case NF_SYMBOLTYPE_STAR: - break; - case NF_SYMBOLTYPE_COMMENT: - { - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - SvNumberformat::EraseCommentBraces( rStr ); - rComment += rStr; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - break; - case NF_KEY_GENERAL : // #77026# "General" is the same as "@" - break; - default: - { - if ( nTypeArray[i] != NF_SYMBOLTYPE_DEL || - sStrArray[i].GetChar(0) != '@' ) - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - } - break; - } - nPos = nPos + sStrArray[i].Len(); - i++; - } // of while - } - break; - case NUMBERFORMAT_NUMBER: - case NUMBERFORMAT_PERCENT: - case NUMBERFORMAT_CURRENCY: - case NUMBERFORMAT_SCIENTIFIC: - case NUMBERFORMAT_FRACTION: - { - while (i < nAnzStrings) - { - // TODO: rechecking eScannedType is unnecessary. - // This switch-case is for eScannedType == NUMBERFORMAT_FRACTION anyway - if (eScannedType == NUMBERFORMAT_FRACTION && // special case - nTypeArray[i] == NF_SYMBOLTYPE_DEL && // # ### #/# - StringEqualsChar( sOldThousandSep, ' ' ) && // e.g. France or Sweden - StringEqualsChar( sStrArray[i], ' ' ) && - !bFrac && - IsLastBlankBeforeFrac(i) ) - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; // del->string - } // kein Taus.p. - - if (nTypeArray[i] == NF_SYMBOLTYPE_BLANK || - nTypeArray[i] == NF_SYMBOLTYPE_STAR || - nTypeArray[i] == NF_KEY_CCC || // CCC - nTypeArray[i] == NF_KEY_GENERAL ) // Standard - { - if (nTypeArray[i] == NF_KEY_GENERAL) - { - nThousand = FLAG_STANDARD_IN_FORMAT; - if ( bConvertMode ) - sStrArray[i] = sNameStandardFormat; - } - nPos = nPos + sStrArray[i].Len(); - i++; - } - else if (nTypeArray[i] == NF_SYMBOLTYPE_STRING || // Strings oder - nTypeArray[i] > 0) // Keywords - { - if (eScannedType == NUMBERFORMAT_SCIENTIFIC && - nTypeArray[i] == NF_KEY_E) // E+ - { - if (bExp) // doppelt - return nPos; - bExp = sal_True; - nExpPos = i; - if (bDecSep) - nCntPost = nCounter; - else - nCntPre = nCounter; - nCounter = 0; - nTypeArray[i] = NF_SYMBOLTYPE_EXP; - } - else if (eScannedType == NUMBERFORMAT_FRACTION && - sStrArray[i].GetChar(0) == ' ') - { - if (!bBlank && !bFrac) // nicht doppelt oder hinter / - { - if (bDecSep && nCounter > 0) // Nachkommastellen - return nPos; // Fehler - bBlank = sal_True; - nBlankPos = i; - nCntPre = nCounter; - nCounter = 0; - } - nTypeArray[i] = NF_SYMBOLTYPE_FRACBLANK; - } - else if (nTypeArray[i] == NF_KEY_THAI_T) - { - bThaiT = true; - sStrArray[i] = sKeyword[nTypeArray[i]]; - } - else if (sStrArray[i].GetChar(0) >= '0' && - sStrArray[i].GetChar(0) <= '9') - { - rtl::OUString sDiv; - sal_uInt16 j = i; - while(j < nAnzStrings) - sDiv += sStrArray[j++]; - if (rtl::OUString::valueOf(sDiv.toInt32()) == sDiv) - { - /* Found a Divisor */ - while (i < j) - nTypeArray[i++] = NF_SYMBOLTYPE_FRAC_FDIV; - i = j - 1; // Stop the loop - if (nCntPost) - nCounter = nCntPost; - else if (nCntPre) - nCounter = nCntPre; - if (!nCntPre) - nCntPre++; - } - } - else - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - else if (nTypeArray[i] == NF_SYMBOLTYPE_DEL) - { - sal_Unicode cHere = sStrArray[i].GetChar(0); - // Handle not pre-known separators in switch. - sal_Unicode cSimplified; - if (StringEqualsChar( pFormatter->GetNumThousandSep(), cHere)) - cSimplified = ','; - else if (StringEqualsChar( pFormatter->GetNumDecimalSep(), cHere)) - cSimplified = '.'; - else - cSimplified = cHere; - switch ( cSimplified ) - { - case '#': - case '0': - case '?': - { - if (nThousand > 0) // #... # - return nPos; // Fehler - else if (bFrac && cHere == '0') - return nPos; // 0 im Nenner - nTypeArray[i] = NF_SYMBOLTYPE_DIGIT; - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - i++; - nCounter++; - while (i < nAnzStrings && - (sStrArray[i].GetChar(0) == '#' || - sStrArray[i].GetChar(0) == '0' || - sStrArray[i].GetChar(0) == '?') - ) - { - nTypeArray[i] = NF_SYMBOLTYPE_DIGIT; - nPos = nPos + sStrArray[i].Len(); - nCounter++; - i++; - } - } - break; - case '-': - { - if ( bDecSep && nDecPos+1 == i && - nTypeArray[nDecPos] == NF_SYMBOLTYPE_DECSEP ) - { // "0.--" - nTypeArray[i] = NF_SYMBOLTYPE_DIGIT; - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - i++; - nCounter++; - while (i < nAnzStrings && - (sStrArray[i].GetChar(0) == '-') ) - { - // If more than two dashes are present in - // currency formats the last dash will be - // interpreted literally as a minus sign. - // Has to be this ugly. Period. - if ( eScannedType == NUMBERFORMAT_CURRENCY - && rStr.Len() >= 2 && - (i == nAnzStrings-1 || - sStrArray[i+1].GetChar(0) != '-') ) - break; - rStr += sStrArray[i]; - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - nCounter++; - i++; - } - } - else - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - } - break; - case '.': - case ',': - case '\'': - case ' ': - { - sal_Unicode cSep = cHere; // remember - if ( StringEqualsChar( sOldThousandSep, cSep ) ) - { - // previous char with skip empty - sal_Unicode cPre = PreviousChar(i); - sal_Unicode cNext; - if (bExp || bBlank || bFrac) - { // after E, / or ' ' - if ( !StringEqualsChar( sOldThousandSep, ' ' ) ) - { - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; // eat it - } - else - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - } - else if (i > 0 && i < nAnzStrings-1 && - (cPre == '#' || cPre == '0') && - ((cNext = NextChar(i)) == '#' || cNext == '0') - ) // #,# - { - nPos = nPos + sStrArray[i].Len(); - if (!bThousand) // only once - bThousand = sal_True; - // Eat it, will be reinserted at proper - // grouping positions further down. - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - else if (i > 0 && (cPre == '#' || cPre == '0') - && PreviousType(i) == NF_SYMBOLTYPE_DIGIT - && nThousand < FLAG_STANDARD_IN_FORMAT ) - { // #,,,, - if ( StringEqualsChar( sOldThousandSep, ' ' ) ) - { // strange, those French.. - sal_Bool bFirst = sal_True; - String& rStr = sStrArray[i]; - // set a hard Non-Breaking Space or ConvertMode - const String& rSepF = pFormatter->GetNumThousandSep(); - while ( i < nAnzStrings - && sStrArray[i] == sOldThousandSep - && StringEqualsChar( sOldThousandSep, NextChar(i) ) ) - { // last was a space or another space - // is following => separator - nPos = nPos + sStrArray[i].Len(); - if ( bFirst ) - { - bFirst = sal_False; - rStr = rSepF; - nTypeArray[i] = NF_SYMBOLTYPE_THSEP; - } - else - { - rStr += rSepF; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - nThousand++; - i++; - } - if ( i < nAnzStrings-1 - && sStrArray[i] == sOldThousandSep ) - { // something following last space - // => space if currency contained, - // else separator - nPos = nPos + sStrArray[i].Len(); - if ( (nPos <= nCurrPos && - nCurrPos < nPos + sStrArray[i+1].Len()) - || nTypeArray[i+1] == NF_KEY_CCC - || (i < nAnzStrings-2 && - sStrArray[i+1].GetChar(0) == '[' && - sStrArray[i+2].GetChar(0) == '$') ) - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - } - else - { - if ( bFirst ) - { - bFirst = sal_False; - rStr = rSepF; - nTypeArray[i] = NF_SYMBOLTYPE_THSEP; - } - else - { - rStr += rSepF; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - nThousand++; - } - i++; - } - } - else - { - do - { - nThousand++; - nTypeArray[i] = NF_SYMBOLTYPE_THSEP; - nPos = nPos + sStrArray[i].Len(); - sStrArray[i] = pFormatter->GetNumThousandSep(); - i++; - } while (i < nAnzStrings && - sStrArray[i] == sOldThousandSep); - } - } - else // any grsep - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - i++; - while ( i < nAnzStrings && - sStrArray[i] == sOldThousandSep ) - { - rStr += sStrArray[i]; - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - } - } - else if ( StringEqualsChar( sOldDecSep, cSep ) ) - { - if (bBlank || bFrac) // . behind / or ' ' - return nPos; // error - else if (bExp) // behind E - { - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; // eat it - } - else if (bDecSep) // any . - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - i++; - while ( i < nAnzStrings && - sStrArray[i] == sOldDecSep ) - { - rStr += sStrArray[i]; - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - } - else - { - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_DECSEP; - sStrArray[i] = pFormatter->GetNumDecimalSep(); - bDecSep = sal_True; - nDecPos = i; - nCntPre = nCounter; - nCounter = 0; - - i++; - } - } // of else = DecSep - else // . without meaning - { - if (cSep == ' ' && - eScannedType == NUMBERFORMAT_FRACTION && - StringEqualsChar( sStrArray[i], ' ' ) ) - { - if (!bBlank && !bFrac) // no dups - { // or behind / - if (bDecSep && nCounter > 0)// dec. - return nPos; // error - bBlank = sal_True; - nBlankPos = i; - nCntPre = nCounter; - nCounter = 0; - } - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - } - else - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - i++; - while (i < nAnzStrings && - StringEqualsChar( sStrArray[i], cSep ) ) - { - rStr += sStrArray[i]; - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - } - } - } - break; - case '/': - { - if (eScannedType == NUMBERFORMAT_FRACTION) - { - if ( i == 0 || - (nTypeArray[i-1] != NF_SYMBOLTYPE_DIGIT && - nTypeArray[i-1] != NF_SYMBOLTYPE_EMPTY) ) - return nPos ? nPos : 1; // /? not allowed - else if (!bFrac || (bDecSep && nCounter > 0)) - { - bFrac = sal_True; - nCntPost = nCounter; - nCounter = 0; - nTypeArray[i] = NF_SYMBOLTYPE_FRAC; - nPos = nPos + sStrArray[i].Len(); - i++; - } - else // / doppelt od. , imZaehl - return nPos; // Fehler - } - else - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - } - break; - case '[' : - { - if ( eScannedType == NUMBERFORMAT_CURRENCY && - i < nAnzStrings-1 && - nTypeArray[i+1] == NF_SYMBOLTYPE_STRING && - sStrArray[i+1].GetChar(0) == '$' ) - { // [$DM-xxx] - // ab SV_NUMBERFORMATTER_VERSION_NEW_CURR - nPos = nPos + sStrArray[i].Len(); // [ - nTypeArray[i] = NF_SYMBOLTYPE_CURRDEL; - nPos = nPos + sStrArray[++i].Len(); // $ - sStrArray[i-1] += sStrArray[i]; // [$ - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - if ( ++i >= nAnzStrings ) - return nPos; // Fehler - nPos = nPos + sStrArray[i].Len(); // DM - String& rStr = sStrArray[i]; - String* pStr = &sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_CURRENCY; // wandeln - sal_Bool bHadDash = sal_False; - i++; - while ( i < nAnzStrings && - sStrArray[i].GetChar(0) != ']' ) - { - nPos = nPos + sStrArray[i].Len(); - if ( bHadDash ) - { - *pStr += sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - else - { - if ( sStrArray[i].GetChar(0) == '-' ) - { - bHadDash = sal_True; - pStr = &sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_CURREXT; - } - else - { - *pStr += sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - } - i++; - } - if ( rStr.Len() && i < nAnzStrings && - sStrArray[i].GetChar(0) == ']' ) - { - nTypeArray[i] = NF_SYMBOLTYPE_CURRDEL; - nPos = nPos + sStrArray[i].Len(); - i++; - } - else - return nPos; // Fehler - } - else - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - } - break; - default: // andere Dels - { - if (eScannedType == NUMBERFORMAT_PERCENT && - cHere == '%') - nTypeArray[i] = NF_SYMBOLTYPE_PERCENT; - else - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - } // of switch (Del) - } // of else Del - else if ( nTypeArray[i] == NF_SYMBOLTYPE_COMMENT ) - { - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - SvNumberformat::EraseCommentBraces( rStr ); - rComment += rStr; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - else - { - DBG_ERRORFILE( "unknown NF_SYMBOLTYPE_..." ); - nPos = nPos + sStrArray[i].Len(); - i++; - } - } // of while - if (eScannedType == NUMBERFORMAT_FRACTION) - { - if (bFrac) - nCntExp = nCounter; - else if (bBlank) - nCntPost = nCounter; - else - nCntPre = nCounter; - } - else - { - if (bExp) - nCntExp = nCounter; - else if (bDecSep) - nCntPost = nCounter; - else - nCntPre = nCounter; - } - if (bThousand) // Expansion of grouping separators - { - sal_uInt16 nMaxPos; - if (bFrac) - { - if (bBlank) - nMaxPos = nBlankPos; - else - nMaxPos = 0; // no grouping - } - else if (bDecSep) // decimal separator present - nMaxPos = nDecPos; - else if (bExp) // 'E' exponent present - nMaxPos = nExpPos; - else // up to end - nMaxPos = i; - // Insert separators at proper positions. - xub_StrLen nCount = 0; - utl::DigitGroupingIterator aGrouping( pLoc->getDigitGrouping()); - size_t nFirstDigitSymbol = nMaxPos; - size_t nFirstGroupingSymbol = nMaxPos; - i = nMaxPos; - while (i-- > 0) - { - if (nTypeArray[i] == NF_SYMBOLTYPE_DIGIT) - { - nFirstDigitSymbol = i; - nCount = nCount + sStrArray[i].Len(); // MSC converts += to int and then warns, so ... - // Insert separator only if not leftmost symbol. - if (i > 0 && nCount >= aGrouping.getPos()) - { - DBG_ASSERT( sStrArray[i].Len() == 1, - "ImpSvNumberformatScan::FinalScan: combined digits in group separator insertion"); - if (!InsertSymbol( i, NF_SYMBOLTYPE_THSEP, - pFormatter->GetNumThousandSep())) - // nPos isn't correct here, but signals error - return nPos; - // i may have been decremented by 1 - nFirstDigitSymbol = i + 1; - nFirstGroupingSymbol = i; - aGrouping.advance(); - } - } - } - // Generated something like "string",000; remove separator again. - if (nFirstGroupingSymbol < nFirstDigitSymbol) - { - nTypeArray[nFirstGroupingSymbol] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - } - // Combine digits into groups to save memory (Info will be copied - // later, taking only non-empty symbols). - for (i = 0; i < nAnzStrings; ++i) - { - if (nTypeArray[i] == NF_SYMBOLTYPE_DIGIT) - { - String& rStr = sStrArray[i]; - while (++i < nAnzStrings && - nTypeArray[i] == NF_SYMBOLTYPE_DIGIT) - { - rStr += sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - } - } - } - break; // of NUMBERFORMAT_NUMBER - case NUMBERFORMAT_DATE: - { - while (i < nAnzStrings) - { - switch (nTypeArray[i]) - { - case NF_SYMBOLTYPE_BLANK: - case NF_SYMBOLTYPE_STAR: - case NF_SYMBOLTYPE_STRING: - nPos = nPos + sStrArray[i].Len(); - i++; - break; - case NF_SYMBOLTYPE_COMMENT: - { - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - SvNumberformat::EraseCommentBraces( rStr ); - rComment += rStr; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - break; - case NF_SYMBOLTYPE_DEL: - { - int nCalRet; - if (sStrArray[i] == sOldDateSep) - { - nTypeArray[i] = NF_SYMBOLTYPE_DATESEP; - nPos = nPos + sStrArray[i].Len(); - if (bConvertMode) - sStrArray[i] = pFormatter->GetDateSep(); - i++; - } - else if ( (nCalRet = FinalScanGetCalendar( nPos, i, nAnzResStrings )) != 0 ) - { - if ( nCalRet < 0 ) - return nPos; // error - } - else - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - } - break; - case NF_KEY_THAI_T : - bThaiT = true; - // fall thru - case NF_KEY_M: // M - case NF_KEY_MM: // MM - case NF_KEY_MMM: // MMM - case NF_KEY_MMMM: // MMMM - case NF_KEY_MMMMM: // MMMMM - case NF_KEY_Q: // Q - case NF_KEY_QQ: // QQ - case NF_KEY_D: // D - case NF_KEY_DD: // DD - case NF_KEY_DDD: // DDD - case NF_KEY_DDDD: // DDDD - case NF_KEY_YY: // YY - case NF_KEY_YYYY: // YYYY - case NF_KEY_NN: // NN - case NF_KEY_NNN: // NNN - case NF_KEY_NNNN: // NNNN - case NF_KEY_WW : // WW - case NF_KEY_AAA : // AAA - case NF_KEY_AAAA : // AAAA - case NF_KEY_EC : // E - case NF_KEY_EEC : // EE - case NF_KEY_G : // G - case NF_KEY_GG : // GG - case NF_KEY_GGG : // GGG - case NF_KEY_R : // R - case NF_KEY_RR : // RR - sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT - nPos = nPos + sStrArray[i].Len(); - i++; - break; - default: // andere Keywords - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - break; - } - } // of while - } - break; // of NUMBERFORMAT_DATE - case NUMBERFORMAT_TIME: - { - while (i < nAnzStrings) - { - switch (nTypeArray[i]) - { - case NF_SYMBOLTYPE_BLANK: - case NF_SYMBOLTYPE_STAR: - { - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - case NF_SYMBOLTYPE_DEL: - { - switch( sStrArray[i].GetChar(0) ) - { - case '0': - { - if ( Is100SecZero( i, bDecSep ) ) - { - bDecSep = sal_True; - nTypeArray[i] = NF_SYMBOLTYPE_DIGIT; - String& rStr = sStrArray[i]; - i++; - nPos = nPos + sStrArray[i].Len(); - nCounter++; - while (i < nAnzStrings && - sStrArray[i].GetChar(0) == '0') - { - rStr += sStrArray[i]; - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - nCounter++; - i++; - } - } - else - return nPos; - } - break; - case '#': - case '?': - return nPos; - case '[': - { - if (bThousand) // doppelt - return nPos; - bThousand = sal_True; // bei Time frei - sal_Unicode cChar = pChrCls->upper( NextChar(i) ).GetChar(0); - if ( cChar == cOldKeyH ) - nThousand = 1; // H - else if ( cChar == cOldKeyMI ) - nThousand = 2; // M - else if ( cChar == cOldKeyS ) - nThousand = 3; // S - else - return nPos; - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - case ']': - { - if (!bThousand) // kein [ vorher - return nPos; - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - default: - { - nPos = nPos + sStrArray[i].Len(); - if ( sStrArray[i] == sOldTimeSep ) - { - nTypeArray[i] = NF_SYMBOLTYPE_TIMESEP; - if ( bConvertMode ) - sStrArray[i] = pLoc->getTimeSep(); - } - else if ( sStrArray[i] == sOldTime100SecSep ) - { - bDecSep = sal_True; - nTypeArray[i] = NF_SYMBOLTYPE_TIME100SECSEP; - if ( bConvertMode ) - sStrArray[i] = pLoc->getTime100SecSep(); - } - else - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - i++; - } - break; - } - } - break; - case NF_SYMBOLTYPE_STRING: - { - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - case NF_SYMBOLTYPE_COMMENT: - { - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - SvNumberformat::EraseCommentBraces( rStr ); - rComment += rStr; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - break; - case NF_KEY_AMPM: // AM/PM - case NF_KEY_AP: // A/P - { - bExp = sal_True; // missbraucht fuer A/P - sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - case NF_KEY_THAI_T : - bThaiT = true; - // fall thru - case NF_KEY_MI: // M - case NF_KEY_MMI: // MM - case NF_KEY_H: // H - case NF_KEY_HH: // HH - case NF_KEY_S: // S - case NF_KEY_SS: // SS - { - sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - default: // andere Keywords - { - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - } - } // of while - nCntPost = nCounter; // Zaehler der Nullen - if (bExp) - nCntExp = 1; // merkt AM/PM - } - break; // of NUMBERFORMAT_TIME - case NUMBERFORMAT_DATETIME: - { - sal_Bool bTimePart = sal_False; - while (i < nAnzStrings) - { - switch (nTypeArray[i]) - { - case NF_SYMBOLTYPE_BLANK: - case NF_SYMBOLTYPE_STAR: - case NF_SYMBOLTYPE_STRING: - nPos = nPos + sStrArray[i].Len(); - i++; - break; - case NF_SYMBOLTYPE_COMMENT: - { - String& rStr = sStrArray[i]; - nPos = nPos + rStr.Len(); - SvNumberformat::EraseCommentBraces( rStr ); - rComment += rStr; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - i++; - } - break; - case NF_SYMBOLTYPE_DEL: - { - int nCalRet; - if ( (nCalRet = FinalScanGetCalendar( nPos, i, nAnzResStrings )) != 0 ) - { - if ( nCalRet < 0 ) - return nPos; // error - } - else - { - switch( sStrArray[i].GetChar(0) ) - { - case '0': - { - if ( bTimePart && Is100SecZero( i, bDecSep ) ) - { - bDecSep = sal_True; - nTypeArray[i] = NF_SYMBOLTYPE_DIGIT; - String& rStr = sStrArray[i]; - i++; - nPos = nPos + sStrArray[i].Len(); - nCounter++; - while (i < nAnzStrings && - sStrArray[i].GetChar(0) == '0') - { - rStr += sStrArray[i]; - nPos = nPos + sStrArray[i].Len(); - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - nCounter++; - i++; - } - } - else - return nPos; - } - break; - case '#': - case '?': - return nPos; - default: - { - nPos = nPos + sStrArray[i].Len(); - if (bTimePart) - { - if ( sStrArray[i] == sOldTimeSep ) - { - nTypeArray[i] = NF_SYMBOLTYPE_TIMESEP; - if ( bConvertMode ) - sStrArray[i] = pLoc->getTimeSep(); - } - else if ( sStrArray[i] == sOldTime100SecSep ) - { - bDecSep = sal_True; - nTypeArray[i] = NF_SYMBOLTYPE_TIME100SECSEP; - if ( bConvertMode ) - sStrArray[i] = pLoc->getTime100SecSep(); - } - else - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - } - else - { - if ( sStrArray[i] == sOldDateSep ) - { - nTypeArray[i] = NF_SYMBOLTYPE_DATESEP; - if (bConvertMode) - sStrArray[i] = pFormatter->GetDateSep(); - } - else - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - } - i++; - } - } - } - } - break; - case NF_KEY_AMPM: // AM/PM - case NF_KEY_AP: // A/P - { - bTimePart = sal_True; - bExp = sal_True; // missbraucht fuer A/P - sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT - nPos = nPos + sStrArray[i].Len(); - i++; - } - break; - case NF_KEY_MI: // M - case NF_KEY_MMI: // MM - case NF_KEY_H: // H - case NF_KEY_HH: // HH - case NF_KEY_S: // S - case NF_KEY_SS: // SS - bTimePart = sal_True; - sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT - nPos = nPos + sStrArray[i].Len(); - i++; - break; - case NF_KEY_M: // M - case NF_KEY_MM: // MM - case NF_KEY_MMM: // MMM - case NF_KEY_MMMM: // MMMM - case NF_KEY_MMMMM: // MMMMM - case NF_KEY_Q: // Q - case NF_KEY_QQ: // QQ - case NF_KEY_D: // D - case NF_KEY_DD: // DD - case NF_KEY_DDD: // DDD - case NF_KEY_DDDD: // DDDD - case NF_KEY_YY: // YY - case NF_KEY_YYYY: // YYYY - case NF_KEY_NN: // NN - case NF_KEY_NNN: // NNN - case NF_KEY_NNNN: // NNNN - case NF_KEY_WW : // WW - case NF_KEY_AAA : // AAA - case NF_KEY_AAAA : // AAAA - case NF_KEY_EC : // E - case NF_KEY_EEC : // EE - case NF_KEY_G : // G - case NF_KEY_GG : // GG - case NF_KEY_GGG : // GGG - case NF_KEY_R : // R - case NF_KEY_RR : // RR - bTimePart = sal_False; - sStrArray[i] = sKeyword[nTypeArray[i]]; // tTtT -> TTTT - nPos = nPos + sStrArray[i].Len(); - i++; - break; - case NF_KEY_THAI_T : - bThaiT = true; - sStrArray[i] = sKeyword[nTypeArray[i]]; - nPos = nPos + sStrArray[i].Len(); - i++; - break; - default: // andere Keywords - nTypeArray[i] = NF_SYMBOLTYPE_STRING; - nPos = nPos + sStrArray[i].Len(); - i++; - break; - } - } // of while - nCntPost = nCounter; // decimals (100th seconds) - if (bExp) - nCntExp = 1; // merkt AM/PM - } - break; // of NUMBERFORMAT_DATETIME - default: - break; - } - if (eScannedType == NUMBERFORMAT_SCIENTIFIC && - (nCntPre + nCntPost == 0 || nCntExp == 0)) - return nPos; - else if (eScannedType == NUMBERFORMAT_FRACTION && (nCntExp > 8 || nCntExp == 0)) - return nPos; - - if (bThaiT && !GetNatNumModifier()) - SetNatNumModifier(1); - - if ( bConvertMode ) - { // strings containing keywords of the target locale must be quoted, so - // the user sees the difference and is able to edit the format string - for ( i=0; i < nAnzStrings; i++ ) - { - if ( nTypeArray[i] == NF_SYMBOLTYPE_STRING && - sStrArray[i].GetChar(0) != '\"' ) - { - if ( bConvertSystemToSystem && eScannedType == NUMBERFORMAT_CURRENCY ) - { // don't stringize automatic currency, will be converted - if ( sStrArray[i] == sOldCurSymbol ) - continue; // for - // DM might be splitted into D and M - if ( sStrArray[i].Len() < sOldCurSymbol.Len() && - pChrCls->toUpper( sStrArray[i], 0, 1 ).GetChar(0) == - sOldCurString.GetChar(0) ) - { - String aTmp( sStrArray[i] ); - sal_uInt16 j = i + 1; - while ( aTmp.Len() < sOldCurSymbol.Len() && - j < nAnzStrings && - nTypeArray[j] == NF_SYMBOLTYPE_STRING ) - { - aTmp += sStrArray[j++]; - } - if ( pChrCls->upper( aTmp ) == sOldCurString ) - { - sStrArray[i++] = aTmp; - for ( ; i<j; i++ ) - { - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - i = j - 1; - continue; // for - } - } - } - String& rStr = sStrArray[i]; - xub_StrLen nLen = rStr.Len(); - for ( xub_StrLen j=0; j<nLen; j++ ) - { - if ( (j == 0 || rStr.GetChar(j-1) != '\\') && GetKeyWord( rStr, j ) ) - { - rStr.Insert( '\"', 0 ); - rStr += '\"'; - break; // for - } - } - } - } - } - // concatenate strings, remove quotes for output, and rebuild the format string - rString.Erase(); - i = 0; - while (i < nAnzStrings) - { - switch ( nTypeArray[i] ) - { - case NF_SYMBOLTYPE_STRING : - { - xub_StrLen nStringPos = rString.Len(); - xub_StrLen nArrPos = 0; - sal_uInt16 iPos = i; - do - { - if (sStrArray[i].Len() == 2 && - sStrArray[i].GetChar(0) == '\\') - { - // Unescape some simple forms of symbols even in the UI - // visible string to prevent duplicates that differ - // only in notation, originating from import. - // e.g. YYYY-MM-DD and YYYY\-MM\-DD are identical, - // but 0\ 000 0 and 0 000 0 in a French locale are not. - sal_Unicode c = sStrArray[i].GetChar(1); - switch (c) - { - case '+': - case '-': - rString += c; - break; - case ' ': - case '.': - case '/': - if (((eScannedType & NUMBERFORMAT_DATE) == 0) - && (StringEqualsChar( - pFormatter->GetNumThousandSep(), - c) || StringEqualsChar( - pFormatter->GetNumDecimalSep(), - c) || (c == ' ' && - StringEqualsChar( - pFormatter->GetNumThousandSep(), - cNonBreakingSpace)))) - rString += sStrArray[i]; - else if ((eScannedType & NUMBERFORMAT_DATE) && - StringEqualsChar( - pFormatter->GetDateSep(), c)) - rString += sStrArray[i]; - else if ((eScannedType & NUMBERFORMAT_TIME) && - (StringEqualsChar( pLoc->getTimeSep(), - c) || - StringEqualsChar( - pLoc->getTime100SecSep(), c))) - rString += sStrArray[i]; - else if (eScannedType & NUMBERFORMAT_FRACTION) - rString += sStrArray[i]; - else - rString += c; - break; - default: - rString += sStrArray[i]; - } - } - else - rString += sStrArray[i]; - if ( RemoveQuotes( sStrArray[i] ) > 0 ) - { // update currency up to quoted string - if ( eScannedType == NUMBERFORMAT_CURRENCY ) - { // dM -> DM or DM -> $ in old automatic - // currency formats, oh my ..., why did we ever - // introduce them? - String aTmp( pChrCls->toUpper( - sStrArray[iPos], nArrPos, - sStrArray[iPos].Len()-nArrPos ) ); - xub_StrLen nCPos = aTmp.Search( sOldCurString ); - if ( nCPos != STRING_NOTFOUND ) - { - const String& rCur = - bConvertMode && bConvertSystemToSystem ? - GetCurSymbol() : sOldCurSymbol; - sStrArray[iPos].Replace( nArrPos+nCPos, - sOldCurString.Len(), rCur ); - rString.Replace( nStringPos+nCPos, - sOldCurString.Len(), rCur ); - } - nStringPos = rString.Len(); - if ( iPos == i ) - nArrPos = sStrArray[iPos].Len(); - else - nArrPos = sStrArray[iPos].Len() + sStrArray[i].Len(); - } - } - if ( iPos != i ) - { - sStrArray[iPos] += sStrArray[i]; - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - i++; - } while ( i < nAnzStrings && nTypeArray[i] == NF_SYMBOLTYPE_STRING ); - if ( i < nAnzStrings ) - i--; // enter switch on next symbol again - if ( eScannedType == NUMBERFORMAT_CURRENCY && nStringPos < rString.Len() ) - { // same as above, since last RemoveQuotes - String aTmp( pChrCls->toUpper( - sStrArray[iPos], nArrPos, - sStrArray[iPos].Len()-nArrPos ) ); - xub_StrLen nCPos = aTmp.Search( sOldCurString ); - if ( nCPos != STRING_NOTFOUND ) - { - const String& rCur = - bConvertMode && bConvertSystemToSystem ? - GetCurSymbol() : sOldCurSymbol; - sStrArray[iPos].Replace( nArrPos+nCPos, - sOldCurString.Len(), rCur ); - rString.Replace( nStringPos+nCPos, - sOldCurString.Len(), rCur ); - } - } - } - break; - case NF_SYMBOLTYPE_CURRENCY : - { - rString += sStrArray[i]; - RemoveQuotes( sStrArray[i] ); - } - break; - case NF_KEY_THAI_T: - if (bThaiT && GetNatNumModifier() == 1) - { // Remove T from format code, will be replaced with a [NatNum1] prefix. - nTypeArray[i] = NF_SYMBOLTYPE_EMPTY; - nAnzResStrings--; - } - else - rString += sStrArray[i]; - break; - case NF_SYMBOLTYPE_EMPTY : - // nothing - break; - default: - rString += sStrArray[i]; - } - i++; - } - return 0; -} - -xub_StrLen ImpSvNumberformatScan::RemoveQuotes( String& rStr ) -{ - if ( rStr.Len() > 1 ) - { - sal_Unicode c = rStr.GetChar(0); - xub_StrLen n; - if ( c == '"' && rStr.GetChar( (n = xub_StrLen(rStr.Len()-1)) ) == '"' ) - { - rStr.Erase(n,1); - rStr.Erase(0,1); - return 2; - } - else if ( c == '\\' ) - { - rStr.Erase(0,1); - return 1; - } - } - return 0; -} - -xub_StrLen ImpSvNumberformatScan::ScanFormat( String& rString, String& rComment ) -{ - xub_StrLen res = Symbol_Division(rString); //lexikalische Analyse - if (!res) - res = ScanType(rString); // Erkennung des Formattyps - if (!res) - res = FinalScan( rString, rComment ); // Typabhaengige Endanalyse - return res; // res = Kontrollposition - // res = 0 => Format ok -} - -void ImpSvNumberformatScan::CopyInfo(ImpSvNumberformatInfo* pInfo, sal_uInt16 nAnz) -{ - size_t i,j; - j = 0; - i = 0; - while (i < nAnz && j < NF_MAX_FORMAT_SYMBOLS) - { - if (nTypeArray[j] != NF_SYMBOLTYPE_EMPTY) - { - pInfo->sStrArray[i] = sStrArray[j]; - pInfo->nTypeArray[i] = nTypeArray[j]; - i++; - } - j++; - } - pInfo->eScannedType = eScannedType; - pInfo->bThousand = bThousand; - pInfo->nThousand = nThousand; - pInfo->nCntPre = nCntPre; - pInfo->nCntPost = nCntPost; - pInfo->nCntExp = nCntExp; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/numbers/zforscan.hxx b/svl/source/numbers/zforscan.hxx deleted file mode 100644 index ffa5849370..0000000000 --- a/svl/source/numbers/zforscan.hxx +++ /dev/null @@ -1,278 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _ZFORSCAN_HXX -#define _ZFORSCAN_HXX - -#include <tools/string.hxx> -#include <tools/date.hxx> -#include <i18npool/lang.h> -#include <tools/color.hxx> -#include <svl/nfkeytab.hxx> -#include <svl/nfsymbol.hxx> - -class SvNumberFormatter; -struct ImpSvNumberformatInfo; - - -const size_t NF_MAX_FORMAT_SYMBOLS = 100; -const size_t NF_MAX_DEFAULT_COLORS = 10; - -// Hack: nThousand==1000 => "Default" occurs in format string -const sal_uInt16 FLAG_STANDARD_IN_FORMAT = 1000; - -class ImpSvNumberformatScan -{ -public: - - ImpSvNumberformatScan( SvNumberFormatter* pFormatter ); - ~ImpSvNumberformatScan(); - void ChangeIntl(); // tauscht Keywords aus - - void ChangeNullDate(sal_uInt16 nDay, sal_uInt16 nMonth, sal_uInt16 nYear); - // tauscht Referenzdatum aus - void ChangeStandardPrec(sal_uInt16 nPrec); // tauscht Standardprecision aus - - xub_StrLen ScanFormat( String& rString, String& rComment ); // Aufruf der Scan-Analyse - - void CopyInfo(ImpSvNumberformatInfo* pInfo, - sal_uInt16 nAnz); // Kopiert die FormatInfo - sal_uInt16 GetAnzResStrings() const { return nAnzResStrings; } - - const CharClass& GetChrCls() const { return *pFormatter->GetCharClass(); } - const LocaleDataWrapper& GetLoc() const { return *pFormatter->GetLocaleData(); } - CalendarWrapper& GetCal() const { return *pFormatter->GetCalendar(); } - - const NfKeywordTable & GetKeywords() const - { - if ( bKeywordsNeedInit ) - InitKeywords(); - return sKeyword; - } - // Keywords used in output like sal_True and sal_False - const String& GetSpecialKeyword( NfKeywordIndex eIdx ) const - { - if ( !sKeyword[eIdx].Len() ) - InitSpecialKeyword( eIdx ); - return sKeyword[eIdx]; - } - const String& GetTrueString() const { return GetSpecialKeyword( NF_KEY_TRUE ); } - const String& GetFalseString() const { return GetSpecialKeyword( NF_KEY_FALSE ); } - const String& GetColorString() const { return GetKeywords()[NF_KEY_COLOR]; } - const String& GetRedString() const { return GetKeywords()[NF_KEY_RED]; } - const String& GetBooleanString() const { return GetKeywords()[NF_KEY_BOOLEAN]; } - const String& GetErrorString() const { return sErrStr; } - - Date* GetNullDate() const { return pNullDate; } - const String& GetStandardName() const - { - if ( bKeywordsNeedInit ) - InitKeywords(); - return sNameStandardFormat; - } - sal_uInt16 GetStandardPrec() const { return nStandardPrec; } - const Color& GetRedColor() const { return StandardColor[4]; } - Color* GetColor(String& sStr); // Setzt Hauptfarben oder - // definierte Farben - - // the compatibility currency symbol for old automatic currency formats - const String& GetCurSymbol() const - { - if ( bCompatCurNeedInit ) - InitCompatCur(); - return sCurSymbol; - } - - // the compatibility currency abbreviation for CCC format code - const String& GetCurAbbrev() const - { - if ( bCompatCurNeedInit ) - InitCompatCur(); - return sCurAbbrev; - } - - // the compatibility currency symbol upper case for old automatic currency formats - const String& GetCurString() const - { - if ( bCompatCurNeedInit ) - InitCompatCur(); - return sCurString; - } - - void SetConvertMode(LanguageType eTmpLge, LanguageType eNewLge, - sal_Bool bSystemToSystem = sal_False ) - { - bConvertMode = sal_True; - eNewLnge = eNewLge; - eTmpLnge = eTmpLge; - bConvertSystemToSystem = bSystemToSystem; - } - void SetConvertMode(sal_Bool bMode) { bConvertMode = bMode; } - // Veraendert nur die Bool-Variable - // (zum temporaeren Unterbrechen des - // Convert-Modus) - sal_Bool GetConvertMode() const { return bConvertMode; } - LanguageType GetNewLnge() const { return eNewLnge; } - // Lesezugriff auf ConvertMode - // und Konvertierungsland/Spr. - LanguageType GetTmpLnge() const { return eTmpLnge; } - // Lesezugriff auf - // und Ausgangsland/Spr. - - /// get Thai T speciality - sal_uInt8 GetNatNumModifier() const { return nNatNumModifier; } - /// set Thai T speciality - void SetNatNumModifier( sal_uInt8 n ) { nNatNumModifier = n; } - - SvNumberFormatter* GetNumberformatter() { return pFormatter; } - // Zugriff auf Formatierer - // (fuer zformat.cxx) - - -private: // ---- privater Teil - NfKeywordTable sKeyword; // Schluesselworte der Syntax - Color StandardColor[NF_MAX_DEFAULT_COLORS]; - // Array der Standardfarben - Date* pNullDate; // 30Dec1899 - String sNameStandardFormat; // "Standard" - sal_uInt16 nStandardPrec; // default Precision for Standardformat - SvNumberFormatter* pFormatter; // Pointer auf die Formatliste - - String sStrArray[NF_MAX_FORMAT_SYMBOLS]; // Array der Symbole - short nTypeArray[NF_MAX_FORMAT_SYMBOLS]; // Array der Infos - // externe Infos: - sal_uInt16 nAnzResStrings; // Anzahl der Ergebnissymbole -#if !(defined SOLARIS && defined X86) - short eScannedType; // Typ gemaess Scan -#else - int eScannedType; // wg. Optimierung -#endif - sal_Bool bThousand; // Mit Tausenderpunkt - sal_uInt16 nThousand; // Zaehlt ....-Folgen - sal_uInt16 nCntPre; // Zaehlt Vorkommastellen - sal_uInt16 nCntPost; // Zaehlt Nachkommastellen - sal_uInt16 nCntExp; // Zaehlt Exp.Stellen, AM/PM - // interne Infos: - sal_uInt16 nAnzStrings; // Anzahl der Symbole - sal_uInt16 nRepPos; // Position eines '*' - sal_uInt16 nExpPos; // interne Position des E - sal_uInt16 nBlankPos; // interne Position des Blank - short nDecPos; // interne Pos. des , - sal_Bool bExp; // wird bei Lesen des E gesetzt - sal_Bool bFrac; // wird bei Lesen des / gesetzt - sal_Bool bBlank; // wird bei ' '(Fraction) ges. - sal_Bool bDecSep; // Wird beim ersten , gesetzt - mutable sal_Bool bKeywordsNeedInit; // Locale dependent keywords need to be initialized - mutable sal_Bool bCompatCurNeedInit; // Locale dependent compatibility currency need to be initialized - String sCurSymbol; // Currency symbol for compatibility format codes - String sCurString; // Currency symbol in upper case - String sCurAbbrev; // Currency abbreviation - String sErrStr; // String fuer Fehlerausgaben - - sal_Bool bConvertMode; // Wird im Convert-Mode gesetzt - // Land/Sprache, in die der - LanguageType eNewLnge; // gescannte String konvertiert - // wird (fuer Excel Filter) - // Land/Sprache, aus der der - LanguageType eTmpLnge; // gescannte String konvertiert - // wird (fuer Excel Filter) - sal_Bool bConvertSystemToSystem; // Whether the conversion is - // from one system locale to - // another system locale (in - // this case the automatic - // currency symbol is converted - // too). - - xub_StrLen nCurrPos; // Position des Waehrungssymbols - - sal_uInt8 nNatNumModifier; // Thai T speciality - - void InitKeywords() const; - void InitSpecialKeyword( NfKeywordIndex eIdx ) const; - void InitCompatCur() const; - -#ifdef _ZFORSCAN_CXX // ----- private Methoden ----- - void SetDependentKeywords(); - // Setzt die Sprachabh. Keyw. - void SkipStrings(sal_uInt16& i,xub_StrLen& nPos);// Ueberspringt StringSymbole - sal_uInt16 PreviousKeyword(sal_uInt16 i); // Gibt Index des vorangeh. - // Schluesselworts oder 0 - sal_uInt16 NextKeyword(sal_uInt16 i); // Gibt Index des naechsten - // Schluesselworts oder 0 - sal_Unicode PreviousChar(sal_uInt16 i); // Gibt letzten Buchstaben - // vor der Position, - // skipt EMPTY, STRING, STAR, BLANK - sal_Unicode NextChar(sal_uInt16 i); // Gibt ersten Buchst. danach - short PreviousType( sal_uInt16 i ); // Gibt Typ vor Position, - // skipt EMPTY - sal_Bool IsLastBlankBeforeFrac(sal_uInt16 i); // True <=> es kommt kein ' ' - // mehr bis zum '/' - void Reset(); // Reset aller Variablen - // vor Analysestart - short GetKeyWord( const String& sSymbol, // determine keyword at nPos - xub_StrLen nPos ); // return 0 <=> not found - - inline sal_Bool IsAmbiguousE( short nKey ) // whether nKey is ambiguous E of NF_KEY_E/NF_KEY_EC - { - return (nKey == NF_KEY_EC || nKey == NF_KEY_E) && - (GetKeywords()[NF_KEY_EC] == GetKeywords()[NF_KEY_E]); - } - - // if 0 at strArray[i] is of S,00 or SS,00 or SS"any"00 in ScanType() or FinalScan() - sal_Bool Is100SecZero( sal_uInt16 i, sal_Bool bHadDecSep ); - - short Next_Symbol(const String& rStr, - xub_StrLen& nPos, - String& sSymbol); // Naechstes Symbol - xub_StrLen Symbol_Division(const String& rString);// lexikalische Voranalyse - xub_StrLen ScanType(const String& rString); // Analyse des Formattyps - xub_StrLen FinalScan( String& rString, String& rComment ); // Endanalyse mit Vorgabe - // des Typs - // -1:= error, return nPos in FinalScan; 0:= no calendar, 1:= calendar found - int FinalScanGetCalendar( xub_StrLen& nPos, sal_uInt16& i, sal_uInt16& nAnzResStrings ); - - /** Insert symbol into nTypeArray and sStrArray, e.g. grouping separator. - If at nPos-1 a symbol type NF_SYMBOLTYPE_EMPTY is present, that is - reused instead of shifting all one up and nPos is decremented! */ - bool InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType eType, const String& rStr ); - - static inline sal_Bool StringEqualsChar( const String& rStr, sal_Unicode ch ) - { return rStr.GetChar(0) == ch && rStr.Len() == 1; } - // Yes, for efficiency get the character first and then compare length - // because in most places where this is used the string is one char. - - // remove "..." and \... quotes from rStr, return how many chars removed - static xub_StrLen RemoveQuotes( String& rStr ); - -#endif //_ZFORSCAN_CXX -}; - - - -#endif // _ZFORSCAN_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/passwordcontainer/passwordcontainer.component b/svl/source/passwordcontainer/passwordcontainer.component deleted file mode 100644 index 3fc55af186..0000000000 --- a/svl/source/passwordcontainer/passwordcontainer.component +++ /dev/null @@ -1,34 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!--********************************************************************** -* -* 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. -* -**********************************************************************--> - -<component loader="com.sun.star.loader.SharedLibrary" prefix="passwordcontainer" - xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="stardiv.svl.PasswordContainer"> - <service name="com.sun.star.task.PasswordContainer"/> - </implementation> -</component> diff --git a/svl/source/passwordcontainer/passwordcontainer.cxx b/svl/source/passwordcontainer/passwordcontainer.cxx deleted file mode 100644 index e612616d3a..0000000000 --- a/svl/source/passwordcontainer/passwordcontainer.cxx +++ /dev/null @@ -1,1564 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include "passwordcontainer.hxx" - -#include <unotools/pathoptions.hxx> -#include "cppuhelper/factory.hxx" -#include <com/sun/star/registry/XSimpleRegistry.hpp> -#include <com/sun/star/beans/PropertyValue.hpp> -#include <com/sun/star/task/MasterPasswordRequest.hpp> -#include <com/sun/star/task/NoMasterException.hpp> - -#include <rtl/cipher.h> -#include <rtl/digest.h> -#include <rtl/byteseq.hxx> - -#ifndef _TOOLS_INETSTRM_HXX -// @@@ #include <inetstrm.hxx> -#endif - -using namespace std; -using namespace osl; -using namespace utl; -using namespace com::sun::star; -using namespace com::sun::star::uno; -using namespace com::sun::star::registry; -using namespace com::sun::star::lang; -using namespace com::sun::star::task; -using namespace com::sun::star::ucb; - -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- - -static ::rtl::OUString createIndex( vector< ::rtl::OUString > lines ) -{ - ::rtl::OString aResult; - const sal_Char* pLine; - - for( unsigned int i = 0; i < lines.size(); i++ ) - { - if( i ) - aResult += ::rtl::OString( "__" ); - ::rtl::OString line = ::rtl::OUStringToOString( lines[i], RTL_TEXTENCODING_UTF8 ); - pLine = line.getStr(); - - while( *pLine ) - { - if( ( *pLine >= 'A' && *pLine <= 'Z' ) - || ( *pLine >= 'a' && *pLine <= 'z' ) - || ( *pLine >= '0' && *pLine <= '9' ) ) - { - aResult += ::rtl::OString::valueOf( *pLine ); - } - else - { - aResult += ::rtl::OString("_"); - aResult += ::rtl::OString::valueOf( (sal_Int32) *pLine, 16 ); - } - - pLine++; - } - } - - return ::rtl::OUString::createFromAscii( aResult.getStr() ); -} - -//------------------------------------------------------------------------- - -static vector< ::rtl::OUString > getInfoFromInd( ::rtl::OUString aInd ) -{ - vector< ::rtl::OUString > aResult; - sal_Bool aStart = sal_True; - - ::rtl::OString line = ::rtl::OUStringToOString( aInd, RTL_TEXTENCODING_ASCII_US ); - const sal_Char* pLine = line.getStr(); - do - { - ::rtl::OUString newItem; - if( !aStart ) - pLine += 2; - else - aStart = sal_False; - - while( *pLine && !( pLine[0] == '_' && pLine[1] == '_' )) - if( *pLine != '_' ) - { - newItem += ::rtl::OUString::valueOf( (sal_Unicode) *pLine ); - pLine++; - } - else - { - ::rtl::OUString aNum; - for( int i = 1; i < 3; i++ ) - { - if( !pLine[i] - || ( ( pLine[i] < '0' || pLine[i] > '9' ) - && ( pLine[i] < 'a' || pLine[i] > 'f' ) - && ( pLine[i] < 'A' || pLine[i] > 'F' ) ) ) - { - OSL_FAIL( "Wrong index syntax!\n" ); - return aResult; - } - - aNum += ::rtl::OUString::valueOf( (sal_Unicode) pLine[i] ); - } - - newItem += ::rtl::OUString::valueOf( (sal_Unicode) aNum.toInt32( 16 ) ); - pLine += 3; - } - - aResult.push_back( newItem ); - } while( pLine[0] == '_' && pLine[1] == '_' ); - - if( *pLine ) - OSL_FAIL( "Wrong index syntax!\n" ); - - return aResult; -} - -//------------------------------------------------------------------------- - -static sal_Bool shorterUrl( ::rtl::OUString& aURL ) -{ - sal_Int32 aInd = aURL.lastIndexOf( sal_Unicode( '/' ) ); - if( aInd > 0 && aURL.indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("://")) ) != aInd-2 ) - { - aURL = aURL.copy( 0, aInd ); - return sal_True; - } - - return sal_False; -} - -//------------------------------------------------------------------------- - -static ::rtl::OUString getAsciiLine( const ::rtl::ByteSequence& buf ) -{ - ::rtl::OUString aResult; - - ::rtl::ByteSequence outbuf( buf.getLength()*2+1 ); - - for( int ind = 0; ind < buf.getLength(); ind++ ) - { - outbuf[ind*2] = ( ((sal_uInt8)buf[ind]) >> 4 ) + 'a'; - outbuf[ind*2+1] = ( ((sal_uInt8)buf[ind]) & 0x0f ) + 'a'; - } - outbuf[buf.getLength()*2] = '\0'; - - aResult = ::rtl::OUString::createFromAscii( (sal_Char*)outbuf.getArray() ); - - return aResult; -} - -//------------------------------------------------------------------------- - -static ::rtl::ByteSequence getBufFromAsciiLine( ::rtl::OUString line ) -{ - OSL_ENSURE( line.getLength() % 2 == 0, "Wrong syntax!\n" ); - ::rtl::OString tmpLine = ::rtl::OUStringToOString( line, RTL_TEXTENCODING_ASCII_US ); - ::rtl::ByteSequence aResult(line.getLength()/2); - - for( int ind = 0; ind < tmpLine.getLength()/2; ind++ ) - { - aResult[ind] = ( (sal_uInt8)( tmpLine.getStr()[ind*2] - 'a' ) << 4 ) | (sal_uInt8)( tmpLine.getStr()[ind*2+1] - 'a' ); - } - - return aResult; -} - -//------------------------------------------------------------------------- - -static Sequence< ::rtl::OUString > copyVectorToSequence( const vector< ::rtl::OUString >& original ) -{ - Sequence< ::rtl::OUString > newOne ( original.size() ); - for( unsigned int i = 0; i < original.size() ; i++ ) - newOne[i] = original[i]; - - return newOne; -} - -static vector< ::rtl::OUString > copySequenceToVector( const Sequence< ::rtl::OUString >& original ) -{ - vector< ::rtl::OUString > newOne ( original.getLength() ); - for( int i = 0; i < original.getLength() ; i++ ) - newOne[i] = original[i]; - - return newOne; -} - -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- - -PassMap StorageItem::getInfo() -{ - PassMap aResult; - - Sequence< ::rtl::OUString > aNodeNames = ConfigItem::GetNodeNames( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Store")) ); - sal_Int32 aNodeCount = aNodeNames.getLength(); - Sequence< ::rtl::OUString > aPropNames( aNodeCount ); - sal_Int32 aNodeInd; - - for( aNodeInd = 0; aNodeInd < aNodeCount; ++aNodeInd ) - { - aPropNames[aNodeInd] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Store/Passwordstorage['")); - aPropNames[aNodeInd] += aNodeNames[aNodeInd]; - aPropNames[aNodeInd] += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("']/Password")); - } - - Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aPropNames ); - - if( aPropertyValues.getLength() != aNodeNames.getLength() ) - { - OSL_ENSURE( aPropertyValues.getLength() == aNodeNames.getLength(), "Problems during reading\n" ); - return aResult; - } - - for( aNodeInd = 0; aNodeInd < aNodeCount; ++aNodeInd ) - { - vector< ::rtl::OUString > aUrlUsr = getInfoFromInd( aNodeNames[aNodeInd] ); - - if( aUrlUsr.size() == 2 ) - { - ::rtl::OUString aUrl = aUrlUsr[0]; - ::rtl::OUString aName = aUrlUsr[1]; - - ::rtl::OUString aEPasswd; - aPropertyValues[aNodeInd] >>= aEPasswd; - - PassMap::iterator aIter = aResult.find( aUrl ); - if( aIter != aResult.end() ) - aIter->second.push_back( NamePassRecord( aName, aEPasswd ) ); - else - { - NamePassRecord aNewRecord( aName, aEPasswd ); - list< NamePassRecord > listToAdd( 1, aNewRecord ); - - aResult.insert( PairUrlRecord( aUrl, listToAdd ) ); - } - } - else - OSL_FAIL( "Wrong index sintax!\n" ); - } - - return aResult; -} - -//------------------------------------------------------------------------- - -void StorageItem::setUseStorage( sal_Bool bUse ) -{ - Sequence< ::rtl::OUString > sendNames(1); - Sequence< uno::Any > sendVals(1); - - sendNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseStorage")); - - sendVals[0] <<= bUse; - - ConfigItem::SetModified(); - ConfigItem::PutProperties( sendNames, sendVals ); -} - -//------------------------------------------------------------------------- - -sal_Bool StorageItem::useStorage() -{ - Sequence< ::rtl::OUString > aNodeNames( 1 ); - aNodeNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UseStorage")); - - Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aNodeNames ); - - if( aPropertyValues.getLength() != aNodeNames.getLength() ) - { - OSL_ENSURE( aPropertyValues.getLength() == aNodeNames.getLength(), "Problems during reading\n" ); - return sal_False; - } - - sal_Bool aResult = false; - aPropertyValues[0] >>= aResult; - - return aResult; -} - -//------------------------------------------------------------------------- - -sal_Bool StorageItem::getEncodedMP( ::rtl::OUString& aResult ) -{ - if( hasEncoded ) - { - aResult = mEncoded; - return sal_True; - } - - Sequence< ::rtl::OUString > aNodeNames( 2 ); - aNodeNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasMaster")); - aNodeNames[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Master")); - - Sequence< Any > aPropertyValues = ConfigItem::GetProperties( aNodeNames ); - - if( aPropertyValues.getLength() != aNodeNames.getLength() ) - { - OSL_ENSURE( aPropertyValues.getLength() == aNodeNames.getLength(), "Problems during reading\n" ); - return sal_False; - } - - aPropertyValues[0] >>= hasEncoded; - aPropertyValues[1] >>= mEncoded; - - aResult = mEncoded; - - return hasEncoded; -} - -//------------------------------------------------------------------------- - -void StorageItem::setEncodedMP( const ::rtl::OUString& aEncoded, sal_Bool bAcceptEmpty ) -{ - Sequence< ::rtl::OUString > sendNames(2); - Sequence< uno::Any > sendVals(2); - - sendNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HasMaster")); - sendNames[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Master")); - - sal_Bool bHasMaster = ( aEncoded.getLength() > 0 || bAcceptEmpty ); - sendVals[0] <<= bHasMaster; - sendVals[1] <<= aEncoded; - - ConfigItem::SetModified(); - ConfigItem::PutProperties( sendNames, sendVals ); - - hasEncoded = bHasMaster; - mEncoded = aEncoded; -} - -//------------------------------------------------------------------------- - -void StorageItem::remove( const ::rtl::OUString& aURL, const ::rtl::OUString& aName ) -{ - vector < ::rtl::OUString > forIndex; - forIndex.push_back( aURL ); - forIndex.push_back( aName ); - - Sequence< ::rtl::OUString > sendSeq(1); - - sendSeq[0] = createIndex( forIndex ); - // sendSeq[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Store/Passwordstorage['")); - // sendSeq[0] += createIndex( forIndex ); - // sendSeq[0] += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("']")); - - ConfigItem::ClearNodeElements( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Store")), sendSeq ); -} - -//------------------------------------------------------------------------- - -void StorageItem::clear() -{ - Sequence< ::rtl::OUString > sendSeq(1); - - ConfigItem::ClearNodeSet( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Store")) ); -} - -//------------------------------------------------------------------------- - -void StorageItem::update( const ::rtl::OUString& aURL, const NamePassRecord& aRecord ) -{ - if ( !aRecord.HasPasswords( PERSISTENT_RECORD ) ) - { - OSL_FAIL( "Unexpected storing of a record!" ); - return; - } - - vector < ::rtl::OUString > forIndex; - forIndex.push_back( aURL ); - forIndex.push_back( aRecord.GetUserName() ); - - Sequence< beans::PropertyValue > sendSeq(1); - - sendSeq[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Store/Passwordstorage['")); - sendSeq[0].Name += createIndex( forIndex ); - sendSeq[0].Name += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("']/Password")); - - sendSeq[0].Value <<= aRecord.GetPersPasswords(); - - ConfigItem::SetModified(); - ConfigItem::SetSetProperties( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Store")), sendSeq ); -} - -//------------------------------------------------------------------------- - -void StorageItem::Notify( const Sequence< ::rtl::OUString >& ) -{ - // this feature still should not be used - if( mainCont ) - mainCont->Notify(); -} - -//------------------------------------------------------------------------- - -void StorageItem::Commit() -{ - // Do nothing, we stored everything we want already -} - -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- - -PasswordContainer::PasswordContainer( const Reference<XMultiServiceFactory>& xServiceFactory ): - m_pStorageFile( NULL ) -{ - // m_pStorageFile->Notify() can be called - ::osl::MutexGuard aGuard( mMutex ); - - mComponent = Reference< XComponent >( xServiceFactory, UNO_QUERY ); - mComponent->addEventListener( this ); - - m_pStorageFile = new StorageItem( this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Passwords")) ); - if( m_pStorageFile ) - if( m_pStorageFile->useStorage() ) - m_aContainer = m_pStorageFile->getInfo(); -} - -//------------------------------------------------------------------------- - -PasswordContainer::~PasswordContainer() -{ - ::osl::MutexGuard aGuard( mMutex ); - - if( m_pStorageFile ) - { - delete m_pStorageFile; - m_pStorageFile = NULL; - } - - if( mComponent.is() ) - { - mComponent->removeEventListener(this); - mComponent = Reference< XComponent >(); - } -} - -//------------------------------------------------------------------------- - -void SAL_CALL PasswordContainer::disposing( const EventObject& ) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - if( m_pStorageFile ) - { - delete m_pStorageFile; - m_pStorageFile = NULL; - } - - if( mComponent.is() ) - { - //mComponent->removeEventListener(this); - mComponent = Reference< XComponent >(); - } -} - -//------------------------------------------------------------------------- - -vector< ::rtl::OUString > PasswordContainer::DecodePasswords( const ::rtl::OUString& aLine, const ::rtl::OUString& aMasterPasswd ) throw(RuntimeException) -{ - if( aMasterPasswd.getLength() ) - { - rtlCipher aDecoder = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream ); - OSL_ENSURE( aDecoder, "Can't create decoder\n" ); - - if( aDecoder ) - { - OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!\n" ); - - unsigned char code[RTL_DIGEST_LENGTH_MD5]; - for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ ) - code[ ind ] = (char)(aMasterPasswd.copy( ind*2, 2 ).toInt32(16)); - - rtlCipherError result = rtl_cipher_init ( - aDecoder, rtl_Cipher_DirectionDecode, - code, RTL_DIGEST_LENGTH_MD5, NULL, 0 ); - - if( result == rtl_Cipher_E_None ) - { - ::rtl::ByteSequence aSeq = getBufFromAsciiLine( aLine ); - - ::rtl::ByteSequence resSeq( aSeq.getLength() ); - - result = rtl_cipher_decode ( aDecoder, (sal_uInt8*)aSeq.getArray(), aSeq.getLength(), - (sal_uInt8*)resSeq.getArray(), resSeq.getLength() ); - - ::rtl::OUString aPasswd( ( sal_Char* )resSeq.getArray(), resSeq.getLength(), RTL_TEXTENCODING_UTF8 ); - - rtl_cipher_destroy (aDecoder); - - return getInfoFromInd( aPasswd ); - } - - rtl_cipher_destroy (aDecoder); - } - } - else - { - OSL_FAIL( "No master password provided!\n" ); - // throw special exception - } - - // problems with decoding - OSL_FAIL( "Problem with decoding\n" ); - throw RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't decode!")), Reference< XInterface >() ); -} - - -//------------------------------------------------------------------------- - -::rtl::OUString PasswordContainer::EncodePasswords( vector< ::rtl::OUString > lines, const ::rtl::OUString& aMasterPasswd ) throw(RuntimeException) -{ - if( aMasterPasswd.getLength() ) - { - ::rtl::OString aSeq = ::rtl::OUStringToOString( createIndex( lines ), RTL_TEXTENCODING_UTF8 ); - - rtlCipher aEncoder = rtl_cipher_create (rtl_Cipher_AlgorithmBF, rtl_Cipher_ModeStream ); - OSL_ENSURE( aEncoder, "Can't create encoder\n" ); - - if( aEncoder ) - { - OSL_ENSURE( aMasterPasswd.getLength() == RTL_DIGEST_LENGTH_MD5 * 2, "Wrong master password format!\n" ); - - unsigned char code[RTL_DIGEST_LENGTH_MD5]; - for( int ind = 0; ind < RTL_DIGEST_LENGTH_MD5; ind++ ) - code[ ind ] = (char)(aMasterPasswd.copy( ind*2, 2 ).toInt32(16)); - - rtlCipherError result = rtl_cipher_init ( - aEncoder, rtl_Cipher_DirectionEncode, - code, RTL_DIGEST_LENGTH_MD5, NULL, 0 ); - - if( result == rtl_Cipher_E_None ) - { - ::rtl::ByteSequence resSeq(aSeq.getLength()+1); - - result = rtl_cipher_encode ( aEncoder, (sal_uInt8*)aSeq.getStr(), aSeq.getLength()+1, - (sal_uInt8*)resSeq.getArray(), resSeq.getLength() ); - -/* - //test - rtlCipherError result = rtl_cipher_init ( - aEncoder, rtl_Cipher_DirectionDecode, - code, RTL_DIGEST_LENGTH_MD5, NULL, 0 ); - - - if( result == rtl_Cipher_E_None ) - { - ::rtl::OUString testOU = getAsciiLine( resSeq ); - ::rtl::ByteSequence aSeq1 = getBufFromAsciiLine( testOU ); - - ::rtl::ByteSequence resSeq1( aSeq1.getLength() ); - - if( resSeq.getLength() == aSeq1.getLength() ) - { - for( int ind = 0; ind < aSeq1.getLength(); ind++ ) - if( resSeq[ind] != aSeq1[ind] ) - testOU = ::rtl::OUString(); - } - - result = rtl_cipher_decode ( aEncoder, (sal_uInt8*)aSeq1.getArray(), aSeq1.getLength(), - (sal_uInt8*)resSeq1.getArray(), resSeq1.getLength() ); - - ::rtl::OUString aPasswd( ( sal_Char* )resSeq1.getArray(), resSeq1.getLength(), RTL_TEXTENCODING_UTF8 ); - } -*/ - - rtl_cipher_destroy (aEncoder); - - if( result == rtl_Cipher_E_None ) - return getAsciiLine( resSeq ); - - } - - rtl_cipher_destroy (aEncoder); - } - } - else - { - OSL_FAIL( "No master password provided!\n" ); - // throw special exception - } - - // problems with encoding - OSL_FAIL( "Problem with encoding\n" ); - throw RuntimeException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Can't encode!")), Reference< XInterface >() ); -} - -//------------------------------------------------------------------------- - -void PasswordContainer::UpdateVector( const ::rtl::OUString& aURL, list< NamePassRecord >& toUpdate, NamePassRecord& aRecord, sal_Bool writeFile ) throw(RuntimeException) -{ - for( list< NamePassRecord >::iterator aNPIter = toUpdate.begin(); aNPIter != toUpdate.end(); ++aNPIter ) - if( aNPIter->GetUserName().equals( aRecord.GetUserName() ) ) - { - if( aRecord.HasPasswords( MEMORY_RECORD ) ) - aNPIter->SetMemPasswords( aRecord.GetMemPasswords() ); - - if( aRecord.HasPasswords( PERSISTENT_RECORD ) ) - { - aNPIter->SetPersPasswords( aRecord.GetPersPasswords() ); - - if( writeFile ) - { - // the password must be already encoded - m_pStorageFile->update( aURL, aRecord ); // change existing ( aURL, aName ) record in the configfile - } - } - - return; - } - - - if( aRecord.HasPasswords( PERSISTENT_RECORD ) && writeFile ) - { - // the password must be already encoded - m_pStorageFile->update( aURL, aRecord ); // add new aName to the existing url - } - - toUpdate.insert( toUpdate.begin(), aRecord ); -} - -//------------------------------------------------------------------------- - -UserRecord PasswordContainer::CopyToUserRecord( const NamePassRecord& aRecord, sal_Bool& io_bTryToDecode, const Reference< XInteractionHandler >& aHandler ) -{ - ::std::vector< ::rtl::OUString > aPasswords; - if( aRecord.HasPasswords( MEMORY_RECORD ) ) - aPasswords = aRecord.GetMemPasswords(); - - if( io_bTryToDecode && aRecord.HasPasswords( PERSISTENT_RECORD ) ) - { - try - { - ::std::vector< ::rtl::OUString > aDecodedPasswords = DecodePasswords( aRecord.GetPersPasswords(), GetMasterPassword( aHandler ) ); - aPasswords.insert( aPasswords.end(), aDecodedPasswords.begin(), aDecodedPasswords.end() ); - } - catch( NoMasterException& ) - { - // if master password could not be detected the entry will be just ignored - io_bTryToDecode = sal_False; - } - } - - return UserRecord( aRecord.GetUserName(), copyVectorToSequence( aPasswords ) ); -} - -//------------------------------------------------------------------------- - -Sequence< UserRecord > PasswordContainer::CopyToUserRecordSequence( const list< NamePassRecord >& original, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - Sequence< UserRecord > aResult( original.size() ); - sal_uInt32 nInd = 0; - sal_Bool bTryToDecode = sal_True; - - for( list< NamePassRecord >::const_iterator aNPIter = original.begin(); - aNPIter != original.end(); - ++aNPIter, ++nInd ) - { - aResult[nInd] = CopyToUserRecord( *aNPIter, bTryToDecode, aHandler ); - } - - return aResult; -} - -//------------------------------------------------------------------------- - -void SAL_CALL PasswordContainer::add( const ::rtl::OUString& Url, const ::rtl::OUString& UserName, const Sequence< ::rtl::OUString >& Passwords, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - PrivateAdd( Url, UserName, Passwords, MEMORY_RECORD, aHandler ); -} - -//------------------------------------------------------------------------- - -void SAL_CALL PasswordContainer::addPersistent( const ::rtl::OUString& Url, const ::rtl::OUString& UserName, const Sequence< ::rtl::OUString >& Passwords, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - PrivateAdd( Url, UserName, Passwords, PERSISTENT_RECORD, aHandler ); -} - -//------------------------------------------------------------------------- - -void PasswordContainer::PrivateAdd( const ::rtl::OUString& Url, const ::rtl::OUString& UserName, const Sequence< ::rtl::OUString >& Passwords, char Mode, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - NamePassRecord aRecord( UserName ); - ::std::vector< ::rtl::OUString > aStorePass = copySequenceToVector( Passwords ); - - if( Mode == PERSISTENT_RECORD ) - aRecord.SetPersPasswords( EncodePasswords( aStorePass, GetMasterPassword( aHandler ) ) ); - else if( Mode == MEMORY_RECORD ) - aRecord.SetMemPasswords( aStorePass ); - else - { - OSL_FAIL( "Unexpected persistence status!" ); - return; - } - - if( !m_aContainer.empty() ) - { - PassMap::iterator aIter = m_aContainer.find( Url ); - - if( aIter != m_aContainer.end() ) - { - UpdateVector( aIter->first, aIter->second, aRecord, sal_True ); - return; - } - } - - list< NamePassRecord > listToAdd( 1, aRecord ); - m_aContainer.insert( PairUrlRecord( Url, listToAdd ) ); - - if( Mode == PERSISTENT_RECORD && m_pStorageFile && m_pStorageFile->useStorage() ) - m_pStorageFile->update( Url, aRecord ); - -} - -//------------------------------------------------------------------------- - - -UrlRecord SAL_CALL PasswordContainer::find( const ::rtl::OUString& aURL, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - return find( aURL, rtl::OUString(), false, aHandler ); -} - -//------------------------------------------------------------------------- - -UrlRecord SAL_CALL PasswordContainer::findForName( const ::rtl::OUString& aURL, const ::rtl::OUString& aName, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - return find( aURL, aName, true, aHandler ); -} - -//------------------------------------------------------------------------- - -Sequence< UserRecord > PasswordContainer::FindUsr( const list< NamePassRecord >& userlist, const ::rtl::OUString& aName, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - sal_uInt32 nInd = 0; - for( list< NamePassRecord >::const_iterator aNPIter = userlist.begin(); - aNPIter != userlist.end(); - ++aNPIter, ++nInd ) - { - if( aNPIter->GetUserName().equals( aName ) ) - { - Sequence< UserRecord > aResult(1); - sal_Bool bTryToDecode = sal_True; - aResult[0] = CopyToUserRecord( *aNPIter, bTryToDecode, aHandler ); - - return aResult; - } - } - - return Sequence< UserRecord >(); -} - -//------------------------------------------------------------------------- - -bool PasswordContainer::createUrlRecord( - const PassMap::iterator & rIter, - bool bName, - const ::rtl::OUString & aName, - const Reference< XInteractionHandler >& aHandler, - UrlRecord & rRec ) - throw( RuntimeException ) -{ - if ( bName ) - { - Sequence< UserRecord > aUsrRec - = FindUsr( rIter->second, aName, aHandler ); - if( aUsrRec.getLength() ) - { - rRec = UrlRecord( rIter->first, aUsrRec ); - return true; - } - } - else - { - rRec = UrlRecord( - rIter->first, - CopyToUserRecordSequence( rIter->second, aHandler ) ); - return true; - } - return false; -} - -//------------------------------------------------------------------------- - -UrlRecord PasswordContainer::find( - const ::rtl::OUString& aURL, - const ::rtl::OUString& aName, - bool bName, // only needed to support empty user names - const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - if( !m_aContainer.empty() && aURL.getLength() ) - { - ::rtl::OUString aUrl( aURL ); - - // each iteration remove last '/...' section from the aUrl - // while it's possible, up to the most left '://' - do - { - // first look for <url>/somename and then look for <url>/somename/... - PassMap::iterator aIter = m_aContainer.find( aUrl ); - if( aIter != m_aContainer.end() ) - { - UrlRecord aRec; - if ( createUrlRecord( aIter, bName, aName, aHandler, aRec ) ) - return aRec; - } - else - { - ::rtl::OUString tmpUrl( aUrl ); - if ( tmpUrl.getStr()[tmpUrl.getLength() - 1] != (sal_Unicode)'/' ) - tmpUrl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); - - aIter = m_aContainer.lower_bound( tmpUrl ); - if( aIter != m_aContainer.end() && aIter->first.match( tmpUrl ) ) - { - UrlRecord aRec; - if ( createUrlRecord( aIter, bName, aName, aHandler, aRec ) ) - return aRec; - } - } - } - while( shorterUrl( aUrl ) && aUrl.getLength() ); - } - - return UrlRecord(); -} - -//------------------------------------------------------------------------- -::rtl::OUString PasswordContainer::GetDefaultMasterPassword() -{ - ::rtl::OUString aResult; - for ( sal_Int32 nInd = 0; nInd < RTL_DIGEST_LENGTH_MD5; nInd++ ) - aResult += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "aa" ) ); - - return aResult; -} - -//------------------------------------------------------------------------- -::rtl::OUString PasswordContainer::RequestPasswordFromUser( PasswordRequestMode aRMode, const uno::Reference< task::XInteractionHandler >& xHandler ) -{ - // empty string means that the call was cancelled or just failed - ::rtl::OUString aResult; - - if ( xHandler.is() ) - { - ::rtl::Reference< MasterPasswordRequest_Impl > xRequest = new MasterPasswordRequest_Impl( aRMode ); - - xHandler->handle( xRequest.get() ); - - ::rtl::Reference< ucbhelper::InteractionContinuation > xSelection = xRequest->getSelection(); - - if ( xSelection.is() ) - { - Reference< XInteractionAbort > xAbort( xSelection.get(), UNO_QUERY ); - if ( !xAbort.is() ) - { - const ::rtl::Reference< ucbhelper::InteractionSupplyAuthentication > & xSupp - = xRequest->getAuthenticationSupplier(); - - aResult = xSupp->getPassword(); - } - } - } - - return aResult; -} - -//------------------------------------------------------------------------- - -::rtl::OUString PasswordContainer::GetMasterPassword( const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException) -{ - PasswordRequestMode aRMode = PasswordRequestMode_PASSWORD_ENTER; - if( !m_pStorageFile || !m_pStorageFile->useStorage() ) - throw NoMasterException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Password storing is not active!")), Reference< XInterface >(), aRMode ); - - if( !m_aMasterPasswd.getLength() && aHandler.is() ) - { - ::rtl::OUString aEncodedMP; - sal_Bool bAskAgain = sal_False; - sal_Bool bDefaultPassword = sal_False; - - if( !m_pStorageFile->getEncodedMP( aEncodedMP ) ) - aRMode = PasswordRequestMode_PASSWORD_CREATE; - else if ( !aEncodedMP.getLength() ) - { - m_aMasterPasswd = GetDefaultMasterPassword(); - bDefaultPassword = sal_True; - } - - if ( !bDefaultPassword ) - { - do { - bAskAgain = sal_False; - - ::rtl::OUString aPass = RequestPasswordFromUser( aRMode, aHandler ); - if ( aPass.getLength() ) - { - if( aRMode == PasswordRequestMode_PASSWORD_CREATE ) - { - m_aMasterPasswd = aPass; - vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd ); - - m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) ); - } - else - { - vector< ::rtl::OUString > aRM( DecodePasswords( aEncodedMP, aPass ) ); - if( !aRM.size() || !aPass.equals( aRM[0] ) ) - { - bAskAgain = sal_True; - aRMode = PasswordRequestMode_PASSWORD_REENTER; - } - else - m_aMasterPasswd = aPass; - } - } - - } while( bAskAgain ); - } - } - - if ( !m_aMasterPasswd.getLength() ) - throw NoMasterException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("No master password!")), Reference< XInterface >(), aRMode ); - - return m_aMasterPasswd; -} - -//------------------------------------------------------------------------- - -void SAL_CALL PasswordContainer::remove( const ::rtl::OUString& aURL, const ::rtl::OUString& aName ) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - ::rtl::OUString aUrl( aURL ); - if( !m_aContainer.empty() ) - { - PassMap::iterator aIter = m_aContainer.find( aUrl ); - - if( aIter == m_aContainer.end() ) - { - sal_Int32 aInd = aUrl.lastIndexOf( sal_Unicode( '/' ) ); - if( aInd > 0 && aUrl.getLength()-1 == aInd ) - aUrl = aUrl.copy( 0, aUrl.getLength() - 1 ); - else - aUrl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); - - aIter = m_aContainer.find( aUrl ); - } - - if( aIter != m_aContainer.end() ) - { - for( list< NamePassRecord >::iterator aNPIter = aIter->second.begin(); aNPIter != aIter->second.end(); ++aNPIter ) - if( aNPIter->GetUserName().equals( aName ) ) - { - if( aNPIter->HasPasswords( PERSISTENT_RECORD ) && m_pStorageFile ) - m_pStorageFile->remove( aURL, aName ); // remove record ( aURL, aName ) - - // the iterator will not be used any more so it can be removed directly - aIter->second.erase( aNPIter ); - - if( aIter->second.begin() == aIter->second.end() ) - m_aContainer.erase( aIter ); - - return; - } - } - } -} - -//------------------------------------------------------------------------- - -void SAL_CALL PasswordContainer::removePersistent( const ::rtl::OUString& aURL, const ::rtl::OUString& aName ) throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - ::rtl::OUString aUrl( aURL ); - if( !m_aContainer.empty() ) - { - PassMap::iterator aIter = m_aContainer.find( aUrl ); - - if( aIter == m_aContainer.end() ) - { - sal_Int32 aInd = aUrl.lastIndexOf( sal_Unicode( '/' ) ); - if( aInd > 0 && aUrl.getLength()-1 == aInd ) - aUrl = aUrl.copy( 0, aUrl.getLength() - 1 ); - else - aUrl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); - - aIter = m_aContainer.find( aUrl ); - } - - if( aIter != m_aContainer.end() ) - { - for( list< NamePassRecord >::iterator aNPIter = aIter->second.begin(); aNPIter != aIter->second.end(); ++aNPIter ) - if( aNPIter->GetUserName().equals( aName ) ) - { - if( aNPIter->HasPasswords( PERSISTENT_RECORD ) ) - { - // TODO/LATER: should the password be converted to MemoryPassword? - aNPIter->RemovePasswords( PERSISTENT_RECORD ); - - if ( m_pStorageFile ) - m_pStorageFile->remove( aURL, aName ); // remove record ( aURL, aName ) - } - - if( !aNPIter->HasPasswords( MEMORY_RECORD ) ) - aIter->second.erase( aNPIter ); - - if( aIter->second.begin() == aIter->second.end() ) - m_aContainer.erase( aIter ); - - return; - } - } - } -} -//------------------------------------------------------------------------- - -void SAL_CALL PasswordContainer::removeAllPersistent() throw(RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - if( m_pStorageFile ) - m_pStorageFile->clear(); - - for( PassMap::iterator aIter = m_aContainer.begin(); aIter != m_aContainer.end(); ) - { - for( list< NamePassRecord >::iterator aNPIter = aIter->second.begin(); aNPIter != aIter->second.end(); ) - { - if( aNPIter->HasPasswords( PERSISTENT_RECORD ) ) - { - // TODO/LATER: should the password be converted to MemoryPassword? - aNPIter->RemovePasswords( PERSISTENT_RECORD ); - - if ( m_pStorageFile ) - m_pStorageFile->remove( aIter->first, aNPIter->GetUserName() ); // remove record ( aURL, aName ) - } - - if( !aNPIter->HasPasswords( MEMORY_RECORD ) ) - { - list< NamePassRecord >::iterator aIterToDelete( aNPIter ); - ++aNPIter; - aIter->second.erase( aIterToDelete ); - } - else - ++aNPIter; - } - - if( aIter->second.begin() == aIter->second.end() ) - { - PassMap::iterator aIterToDelete( aIter ); - ++aIter; - m_aContainer.erase( aIterToDelete ); - } - else - ++aIter; - } -} -//------------------------------------------------------------------------- - -Sequence< UrlRecord > SAL_CALL PasswordContainer::getAllPersistent( const Reference< XInteractionHandler >& xHandler ) throw(RuntimeException) -{ - Sequence< UrlRecord > aResult; - - ::osl::MutexGuard aGuard( mMutex ); - for( PassMap::iterator aIter = m_aContainer.begin(); aIter != m_aContainer.end(); ++aIter ) - { - Sequence< UserRecord > aUsers; - for( list< NamePassRecord >::iterator aNPIter = aIter->second.begin(); aNPIter != aIter->second.end(); ++aNPIter ) - if( aNPIter->HasPasswords( PERSISTENT_RECORD ) ) - { - sal_Int32 oldLen = aUsers.getLength(); - aUsers.realloc( oldLen + 1 ); - aUsers[ oldLen ] = UserRecord( aNPIter->GetUserName(), copyVectorToSequence( DecodePasswords( aNPIter->GetPersPasswords(), GetMasterPassword( xHandler ) ) ) ); - } - - if( aUsers.getLength() ) - { - sal_Int32 oldLen = aResult.getLength(); - aResult.realloc( oldLen + 1 ); - aResult[ oldLen ] = UrlRecord( aIter->first, aUsers ); - } - } - - return aResult; -} - -//------------------------------------------------------------------------- -sal_Bool SAL_CALL PasswordContainer::authorizateWithMasterPassword( const uno::Reference< task::XInteractionHandler >& xHandler ) - throw (uno::RuntimeException) -{ - sal_Bool bResult = sal_False; - ::rtl::OUString aEncodedMP; - uno::Reference< task::XInteractionHandler > xTmpHandler = xHandler; - ::osl::MutexGuard aGuard( mMutex ); - - // the method should fail if there is no master password - if( m_pStorageFile && m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) ) - { - if ( !aEncodedMP.getLength() ) - { - // this is a default master password - // no UI is necessary - bResult = sal_True; - } - else - { - if ( !xTmpHandler.is() ) - { - uno::Reference< lang::XMultiServiceFactory > xFactory( mComponent, uno::UNO_QUERY_THROW ); - xTmpHandler.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), uno::UNO_QUERY_THROW ); - } - - if ( m_aMasterPasswd.getLength() ) - { - // there is a password, it should be just rechecked - PasswordRequestMode aRMode = PasswordRequestMode_PASSWORD_ENTER; - ::rtl::OUString aPass; - - do { - aPass = RequestPasswordFromUser( aRMode, xTmpHandler ); - bResult = ( aPass.getLength() && aPass.equals( m_aMasterPasswd ) ); - aRMode = PasswordRequestMode_PASSWORD_REENTER; // further questions with error notification - } while( !bResult && aPass.getLength() ); - } - else - { - try - { - // ask for the password, if user provide no correct password an exception will be thrown - bResult = ( GetMasterPassword( xTmpHandler ).getLength() > 0 ); - } - catch( uno::Exception& ) - {} - } - } - } - - return bResult; -} - -//------------------------------------------------------------------------- -sal_Bool SAL_CALL PasswordContainer::changeMasterPassword( const uno::Reference< task::XInteractionHandler >& xHandler ) - throw (uno::RuntimeException) -{ - sal_Bool bResult = sal_False; - uno::Reference< task::XInteractionHandler > xTmpHandler = xHandler; - ::osl::MutexGuard aGuard( mMutex ); - - if ( m_pStorageFile && m_pStorageFile->useStorage() ) - { - if ( !xTmpHandler.is() ) - { - uno::Reference< lang::XMultiServiceFactory > xFactory( mComponent, uno::UNO_QUERY_THROW ); - xTmpHandler.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), uno::UNO_QUERY_THROW ); - } - - sal_Bool bCanChangePassword = sal_True; - // if there is already a stored master password it should be entered by the user before the change happen - ::rtl::OUString aEncodedMP; - if( m_aMasterPasswd.getLength() || m_pStorageFile->getEncodedMP( aEncodedMP ) ) - bCanChangePassword = authorizateWithMasterPassword( xTmpHandler ); - - if ( bCanChangePassword ) - { - // ask for the new password, but do not set it - PasswordRequestMode aRMode = PasswordRequestMode_PASSWORD_CREATE; - ::rtl::OUString aPass = RequestPasswordFromUser( aRMode, xTmpHandler ); - - if ( aPass.getLength() ) - { - // get all the persistent entries if it is possible - Sequence< UrlRecord > aPersistent = getAllPersistent( uno::Reference< task::XInteractionHandler >() ); - - // remove the master password and the entries persistence - removeMasterPassword(); - - // store the new master password - m_aMasterPasswd = aPass; - vector< ::rtl::OUString > aMaster( 1, m_aMasterPasswd ); - m_pStorageFile->setEncodedMP( EncodePasswords( aMaster, m_aMasterPasswd ) ); - - // store all the entries with the new password - for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ ) - for ( int nNameInd = 0; nNameInd< aPersistent[nURLInd].UserList.getLength(); nNameInd++ ) - addPersistent( aPersistent[nURLInd].Url, - aPersistent[nURLInd].UserList[nNameInd].UserName, - aPersistent[nURLInd].UserList[nNameInd].Passwords, - uno::Reference< task::XInteractionHandler >() ); - - bResult = sal_True; - } - } - } - - return bResult; -} - -//------------------------------------------------------------------------- -void SAL_CALL PasswordContainer::removeMasterPassword() - throw (uno::RuntimeException) -{ - // remove all the stored passwords and the master password - removeAllPersistent(); - - ::osl::MutexGuard aGuard( mMutex ); - if ( m_pStorageFile ) - { - m_aMasterPasswd = ::rtl::OUString(); - m_pStorageFile->setEncodedMP( ::rtl::OUString() ); // let the master password be removed from configuration - } -} - -//------------------------------------------------------------------------- -::sal_Bool SAL_CALL PasswordContainer::hasMasterPassword( ) - throw (::com::sun::star::uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - if ( !m_pStorageFile ) - throw uno::RuntimeException(); - - ::rtl::OUString aEncodedMP; - return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) ); -} - -//------------------------------------------------------------------------- -::sal_Bool SAL_CALL PasswordContainer::allowPersistentStoring( ::sal_Bool bAllow ) - throw (::com::sun::star::uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - if ( !m_pStorageFile ) - throw uno::RuntimeException(); - - if ( !bAllow ) - removeMasterPassword(); - - if ( m_pStorageFile->useStorage() == bAllow ) - return bAllow; - - m_pStorageFile->setUseStorage( bAllow ); - return !bAllow; -} - -//------------------------------------------------------------------------- -::sal_Bool SAL_CALL PasswordContainer::isPersistentStoringAllowed() - throw (::com::sun::star::uno::RuntimeException) -{ - ::osl::MutexGuard aGuard( mMutex ); - - if ( !m_pStorageFile ) - throw uno::RuntimeException(); - - return m_pStorageFile->useStorage(); -} - -//------------------------------------------------------------------------- -::sal_Bool SAL_CALL PasswordContainer::useDefaultMasterPassword( const uno::Reference< task::XInteractionHandler >& xHandler ) - throw ( uno::RuntimeException ) -{ - sal_Bool bResult = sal_False; - uno::Reference< task::XInteractionHandler > xTmpHandler = xHandler; - ::osl::MutexGuard aGuard( mMutex ); - - if ( m_pStorageFile && m_pStorageFile->useStorage() ) - { - if ( !xTmpHandler.is() ) - { - uno::Reference< lang::XMultiServiceFactory > xFactory( mComponent, uno::UNO_QUERY_THROW ); - xTmpHandler.set( xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ), uno::UNO_QUERY_THROW ); - } - - sal_Bool bCanChangePassword = sal_True; - // if there is already a stored nondefault master password it should be entered by the user before the change happen - ::rtl::OUString aEncodedMP; - if( m_pStorageFile->getEncodedMP( aEncodedMP ) && aEncodedMP.getLength() ) - bCanChangePassword = authorizateWithMasterPassword( xTmpHandler ); - - if ( bCanChangePassword ) - { - // generate the default password - ::rtl::OUString aPass = GetDefaultMasterPassword(); - if ( aPass.getLength() ) - { - // get all the persistent entries if it is possible - Sequence< UrlRecord > aPersistent = getAllPersistent( uno::Reference< task::XInteractionHandler >() ); - - // remove the master password and the entries persistence - removeMasterPassword(); - - // store the empty string to flag the default master password - m_aMasterPasswd = aPass; - m_pStorageFile->setEncodedMP( ::rtl::OUString(), sal_True ); - - // store all the entries with the new password - for ( int nURLInd = 0; nURLInd < aPersistent.getLength(); nURLInd++ ) - for ( int nNameInd = 0; nNameInd< aPersistent[nURLInd].UserList.getLength(); nNameInd++ ) - addPersistent( aPersistent[nURLInd].Url, - aPersistent[nURLInd].UserList[nNameInd].UserName, - aPersistent[nURLInd].UserList[nNameInd].Passwords, - uno::Reference< task::XInteractionHandler >() ); - - bResult = sal_True; - } - } - } - - return bResult; - -} - -//------------------------------------------------------------------------- -::sal_Bool SAL_CALL PasswordContainer::isDefaultMasterPasswordUsed() - throw ( uno::RuntimeException ) -{ - ::osl::MutexGuard aGuard( mMutex ); - - if ( !m_pStorageFile ) - throw uno::RuntimeException(); - - ::rtl::OUString aEncodedMP; - return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) && !aEncodedMP.getLength() ); -} - - -//------------------------------------------------------------------------- -void SAL_CALL PasswordContainer::addUrl( const ::rtl::OUString& Url, ::sal_Bool MakePersistent ) - throw (uno::RuntimeException) -{ - mUrlContainer.add( Url, MakePersistent ); -} - -//------------------------------------------------------------------------- -::rtl::OUString SAL_CALL PasswordContainer::findUrl( const ::rtl::OUString& Url ) - throw (uno::RuntimeException) -{ - return mUrlContainer.find( Url ); -} - -//------------------------------------------------------------------------- -void SAL_CALL PasswordContainer::removeUrl( const ::rtl::OUString& Url ) - throw (uno::RuntimeException) -{ - mUrlContainer.remove( Url ); -} - -//------------------------------------------------------------------------- -uno::Sequence< ::rtl::OUString > SAL_CALL PasswordContainer::getUrls( ::sal_Bool OnlyPersistent ) - throw (uno::RuntimeException) -{ - return mUrlContainer.list( OnlyPersistent ); -} - -//------------------------------------------------------------------------- - -void PasswordContainer::Notify() -{ - ::osl::MutexGuard aGuard( mMutex ); - - PassMap::iterator aIter; - - // remove the cached persistent values in the memory - for( aIter = m_aContainer.begin(); aIter != m_aContainer.end(); ++aIter ) - { - for( list< NamePassRecord >::iterator aNPIter = aIter->second.begin(); aNPIter != aIter->second.end(); ) - { - if( aNPIter->HasPasswords( PERSISTENT_RECORD ) ) - { - aNPIter->RemovePasswords( PERSISTENT_RECORD ); - - if ( m_pStorageFile ) - m_pStorageFile->remove( aIter->first, aNPIter->GetUserName() ); // remove record ( aURL, aName ) - } - - if( !aNPIter->HasPasswords( MEMORY_RECORD ) ) - { - list< NamePassRecord >::iterator aIterToDelete( aNPIter ); - ++aNPIter; - aIter->second.erase( aIterToDelete ); - } - else - ++aNPIter; - } - } - - PassMap addon; - if( m_pStorageFile ) - addon = m_pStorageFile->getInfo(); - - for( aIter = addon.begin(); aIter != addon.end(); ++aIter ) - { - PassMap::iterator aSearchIter = m_aContainer.find( aIter->first ); - if( aSearchIter != m_aContainer.end() ) - for( list< NamePassRecord >::iterator aNPIter = aIter->second.begin(); aNPIter != aIter->second.end(); ++aNPIter ) - UpdateVector( aSearchIter->first, aSearchIter->second, *aNPIter, sal_False ); - else - m_aContainer.insert( PairUrlRecord( aIter->first, aIter->second ) ); - } -} - -//------------------------------------------------------------------------- - -::rtl::OUString SAL_CALL PasswordContainer::getImplementationName( ) throw(uno::RuntimeException) -{ - return impl_getStaticImplementationName(); -} - -//------------------------------------------------------------------------- - -sal_Bool SAL_CALL PasswordContainer::supportsService( const ::rtl::OUString& ServiceName ) throw(uno::RuntimeException) -{ - if ( ServiceName.compareToAscii("com.sun.star.task.PasswordContainer") == 0 ) - return sal_True; - else - return sal_False; -} - -//------------------------------------------------------------------------- - -Sequence< ::rtl::OUString > SAL_CALL PasswordContainer::getSupportedServiceNames( ) throw(uno::RuntimeException) -{ - return impl_getStaticSupportedServiceNames(); -} - -//------------------------------------------------------------------------- - -Sequence< ::rtl::OUString > SAL_CALL PasswordContainer::impl_getStaticSupportedServiceNames( ) throw(uno::RuntimeException) -{ - Sequence< ::rtl::OUString > aRet(1); - *aRet.getArray() = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.task.PasswordContainer")); - return aRet; -} - -//------------------------------------------------------------------------- - -::rtl::OUString SAL_CALL PasswordContainer::impl_getStaticImplementationName() throw(uno::RuntimeException) -{ - return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("stardiv.svl.PasswordContainer")); -} - -//------------------------------------------------------------------------- - -Reference< XInterface > SAL_CALL PasswordContainer::impl_createInstance( const Reference< XMultiServiceFactory >& xServiceManager ) throw( RuntimeException ) -{ - return Reference< XInterface >( *new PasswordContainer( xServiceManager ) ); -} - -//------------------------------------------------------------------------- - -Reference< XSingleServiceFactory > SAL_CALL PasswordContainer::impl_createFactory( const Reference< XMultiServiceFactory >& ServiceManager ) throw(RuntimeException) -{ - Reference< XSingleServiceFactory > xReturn( ::cppu::createOneInstanceFactory( ServiceManager, - PasswordContainer::impl_getStaticImplementationName(), - PasswordContainer::impl_createInstance, - PasswordContainer::impl_getStaticSupportedServiceNames())); - return xReturn ; - -} - -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- - -MasterPasswordRequest_Impl::MasterPasswordRequest_Impl( PasswordRequestMode Mode ) -{ - MasterPasswordRequest aRequest; - - aRequest.Classification = InteractionClassification_ERROR; - aRequest.Mode = Mode; - - setRequest( makeAny( aRequest ) ); - - // Fill continuations... - Sequence< RememberAuthentication > aRememberModes( 1 ); - aRememberModes[ 0 ] = RememberAuthentication_NO; - - m_xAuthSupplier - = new ::ucbhelper::InteractionSupplyAuthentication( - this, - sal_False, // bCanSetRealm - sal_False, // bCanSetUserName - sal_True, // bCanSetPassword - sal_False, // bCanSetAccount - aRememberModes, // rRememberPasswordModes - RememberAuthentication_NO, // eDefaultRememberPasswordMode - aRememberModes, // rRememberAccountModes - RememberAuthentication_NO, // eDefaultRememberAccountMode - sal_False, // bCanUseSystemCredentials - sal_False // bDefaultUseSystemCredentials - ); - - Sequence< - Reference< XInteractionContinuation > > aContinuations( 3 ); - aContinuations[ 0 ] = new ::ucbhelper::InteractionAbort( this ); - aContinuations[ 1 ] = new ::ucbhelper::InteractionRetry( this ); - aContinuations[ 2 ] = m_xAuthSupplier.get(); - - setContinuations( aContinuations ); -} - -//------------------------------------------------------------------------- -//------------------------------------------------------------------------- - -extern "C" -{ -SAL_DLLPUBLIC_EXPORT void * SAL_CALL passwordcontainer_component_getFactory ( - const sal_Char * pImplementationName, void * pServiceManager, void * /* pRegistryKey */) -{ - void * pResult = 0; - if (pServiceManager) - { - Reference< XSingleServiceFactory > xFactory; - if (PasswordContainer::impl_getStaticImplementationName().compareToAscii (pImplementationName) == 0) - { - xFactory = PasswordContainer::impl_createFactory ( - reinterpret_cast< XMultiServiceFactory* >(pServiceManager)); - } - if (xFactory.is()) - { - xFactory->acquire(); - pResult = xFactory.get(); - } - } - return pResult; -} - -} // extern "C" - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/passwordcontainer/syscreds.cxx b/svl/source/passwordcontainer/syscreds.cxx deleted file mode 100644 index 934a367839..0000000000 --- a/svl/source/passwordcontainer/syscreds.cxx +++ /dev/null @@ -1,303 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 "syscreds.hxx" -#include "com/sun/star/beans/PropertyValue.hpp" - -using namespace com::sun::star; - -SysCredentialsConfigItem::SysCredentialsConfigItem( - SysCredentialsConfig * pOwner ) -: utl::ConfigItem( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Common/Passwords")), - CONFIG_MODE_IMMEDIATE_UPDATE ), - m_bInited( false ), - m_pOwner( pOwner ) -{ - uno::Sequence< ::rtl::OUString > aNode( 1 ); - aNode[ 0 ] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "Office.Common/Passwords/AuthenticateUsingSystemCredentials" )); - EnableNotification( aNode ); -} - -//virtual -void SysCredentialsConfigItem::Notify( - const uno::Sequence< rtl::OUString > & /*seqPropertyNames*/ ) -{ - { - ::osl::MutexGuard aGuard( m_aMutex ); - m_bInited = false; - // rebuild m_seqURLs - getSystemCredentialsURLs(); - } - m_pOwner->persistentConfigChanged(); -} - -void SysCredentialsConfigItem::Commit() -{ - // does nothing -} - -uno::Sequence< rtl::OUString > -SysCredentialsConfigItem::getSystemCredentialsURLs() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - if ( !m_bInited ) - { - // read config item - uno::Sequence< ::rtl::OUString > aPropNames( 1 ); - aPropNames[ 0 ] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "AuthenticateUsingSystemCredentials" )); - uno::Sequence< uno::Any > aAnyValues( - utl::ConfigItem::GetProperties( aPropNames ) ); - - OSL_ENSURE( - aAnyValues.getLength() == 1, - "SysCredentialsConfigItem::getSystemCredentialsURLs: " - "Error reading config item!" ); - - uno::Sequence< rtl::OUString > aValues; - if ( ( aAnyValues[ 0 ] >>= aValues ) || - ( !aAnyValues[ 0 ].hasValue() ) ) - { - m_seqURLs = aValues; - m_bInited = true; - } - } - return m_seqURLs; -} - -void SysCredentialsConfigItem::setSystemCredentialsURLs( - const uno::Sequence< rtl::OUString > & seqURLList ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - // write config item. - uno::Sequence< rtl::OUString > aPropNames( 1 ); - uno::Sequence< uno::Any > aPropValues( 1 ); - aPropNames[ 0 ] - = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( - "AuthenticateUsingSystemCredentials" )); - aPropValues[ 0 ] <<= seqURLList; - - utl::ConfigItem::SetModified(); - utl::ConfigItem::PutProperties( aPropNames, aPropValues ); - - m_seqURLs = seqURLList; - m_bInited = true; -} - -//============================================================================ - -namespace -{ - // TODO: This code is actually copied from svl/source/passwordcontainer.cxx - bool removeLastSegment( ::rtl::OUString & aURL ) - { - sal_Int32 aInd = aURL.lastIndexOf( sal_Unicode( '/' ) ); - - if( aInd > 0 ) - { - sal_Int32 aPrevInd = aURL.lastIndexOf( sal_Unicode( '/' ), aInd ); - if ( aURL.indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("://")) ) - != aPrevInd - 2 || - aInd != aURL.getLength() - 1 ) - { - aURL = aURL.copy( 0, aInd ); - return true; - } - } - - return false; - } - - bool findURL( StringSet const & rContainer, rtl::OUString const & aURL, rtl::OUString & aResult ) - { - // TODO: This code is actually copied from svl/source/passwordcontainer.cxx - if( !rContainer.empty() && aURL.getLength() ) - { - ::rtl::OUString aUrl( aURL ); - - // each iteration remove last '/...' section from the aUrl - // while it's possible, up to the most left '://' - do - { - // first look for <url>/somename and then look for <url>/somename/... - StringSet::const_iterator aIter = rContainer.find( aUrl ); - if( aIter != rContainer.end() ) - { - aResult = *aIter; - return true; - } - else - { - ::rtl::OUString tmpUrl( aUrl ); - if ( tmpUrl.getStr()[tmpUrl.getLength() - 1] != (sal_Unicode)'/' ) - tmpUrl += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); - - aIter = rContainer.lower_bound( tmpUrl ); - if( aIter != rContainer.end() && aIter->match( tmpUrl ) ) - { - aResult = *aIter; - return true; - } - } - } - while( removeLastSegment( aUrl ) && aUrl.getLength() ); - } - aResult = rtl::OUString(); - return false; - } - -} // namespace - -SysCredentialsConfig::SysCredentialsConfig() -: m_aConfigItem( this ), - m_bCfgInited( false ) -{ -} - -void SysCredentialsConfig::initCfg() -{ - osl::MutexGuard aGuard( m_aMutex ); - if ( !m_bCfgInited ) - { - uno::Sequence< rtl::OUString > aURLs( - m_aConfigItem.getSystemCredentialsURLs() ); - for ( sal_Int32 n = 0; n < aURLs.getLength(); ++n ) - m_aCfgContainer.insert( aURLs[ n ] ); - - m_bCfgInited = true; - } -} - -void SysCredentialsConfig::writeCfg() -{ - osl::MutexGuard aGuard( m_aMutex ); - - OSL_ENSURE( m_bCfgInited, "SysCredentialsConfig::writeCfg : not initialized!" ); - - uno::Sequence< rtl::OUString > aURLs( m_aCfgContainer.size() ); - StringSet::const_iterator it = m_aCfgContainer.begin(); - const StringSet::const_iterator end = m_aCfgContainer.end(); - sal_Int32 n = 0; - - while ( it != end ) - { - aURLs[ n ] = *it; - ++it; - ++n; - } - - m_aConfigItem.setSystemCredentialsURLs( aURLs ); -} - -rtl::OUString SysCredentialsConfig::find( rtl::OUString const & aURL ) -{ - osl::MutexGuard aGuard( m_aMutex ); - rtl::OUString aResult; - if ( findURL( m_aMemContainer, aURL, aResult ) ) - return aResult; - - initCfg(); - if ( findURL( m_aCfgContainer, aURL, aResult ) ) - return aResult; - - return rtl::OUString(); -} - -void SysCredentialsConfig::add( rtl::OUString const & rURL, bool bPersistent ) -{ - ::osl::MutexGuard aGuard( m_aMutex ); - - if ( bPersistent ) - { - m_aMemContainer.erase( rURL ); - - initCfg(); - m_aCfgContainer.insert( rURL ); - writeCfg(); - } - else - { - initCfg(); - if ( m_aCfgContainer.erase( rURL ) > 0 ) - writeCfg(); - - m_aMemContainer.insert( rURL ); - } -} - -void SysCredentialsConfig::remove( rtl::OUString const & rURL ) -{ - m_aMemContainer.erase( rURL ); - - initCfg(); - if ( m_aCfgContainer.erase( rURL ) > 0 ) - writeCfg(); -} - -uno::Sequence< rtl::OUString > SysCredentialsConfig::list( bool bOnlyPersistent ) -{ - initCfg(); - sal_Int32 nCount = m_aCfgContainer.size() - + ( bOnlyPersistent ? 0 : m_aMemContainer.size() ); - uno::Sequence< rtl::OUString > aResult( nCount ); - - StringSet::const_iterator it = m_aCfgContainer.begin(); - StringSet::const_iterator end = m_aCfgContainer.end(); - sal_Int32 n = 0; - - while ( it != end ) - { - aResult[ n ] = *it; - ++it; - ++n; - } - - if ( !bOnlyPersistent ) - { - it = m_aMemContainer.begin(); - end = m_aMemContainer.end(); - - while ( it != end ) - { - aResult[ n ] = *it; - ++it; - ++n; - } - } - return aResult; -} - -void SysCredentialsConfig::persistentConfigChanged() -{ - ::osl::MutexGuard aGuard( m_aMutex ); - m_bCfgInited = false; // re-init on demand. -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/passwordcontainer/syscreds.hxx b/svl/source/passwordcontainer/syscreds.hxx deleted file mode 100644 index a81b6d3e27..0000000000 --- a/svl/source/passwordcontainer/syscreds.hxx +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 INCLUDED_SVTOOLS_SYSCREDS_HXX -#define INCLUDED_SVTOOLS_SYSCREDS_HXX - -#include <set> -#include <memory> -#include "osl/mutex.hxx" -#include "rtl/ustring.hxx" -#include "com/sun/star/uno/Sequence.hxx" -#include "unotools/configitem.hxx" - -class SysCredentialsConfig; - -class SysCredentialsConfigItem : public utl::ConfigItem -{ - public: - SysCredentialsConfigItem( SysCredentialsConfig * pOwner ); - //virtual ~SysCredentialsConfigItem(); - - virtual void Notify( - const com::sun::star::uno::Sequence< rtl::OUString > & - seqPropertyNames ); - virtual void Commit(); - - com::sun::star::uno::Sequence< rtl::OUString > - getSystemCredentialsURLs(); - - void setSystemCredentialsURLs( - const com::sun::star::uno::Sequence< rtl::OUString > & - seqURLList ); - - //bool isSystemCredentialsURL( const rtl::OUString & rURL ) const; - -private: - ::osl::Mutex m_aMutex; - bool m_bInited; - com::sun::star::uno::Sequence< rtl::OUString > m_seqURLs; - SysCredentialsConfig * m_pOwner; -}; - -typedef std::set< rtl::OUString > StringSet; - -class SysCredentialsConfig -{ - public: - SysCredentialsConfig(); - - rtl::OUString find( rtl::OUString const & rURL ); - void add( rtl::OUString const & rURL, bool bPersistent ); - void remove( rtl::OUString const & rURL ); - com::sun::star::uno::Sequence< rtl::OUString > list( bool bOnlyPersistent ); - - void persistentConfigChanged(); - - private: - void initCfg(); - void writeCfg(); - - ::osl::Mutex m_aMutex; - StringSet m_aMemContainer; - StringSet m_aCfgContainer; - SysCredentialsConfigItem m_aConfigItem; - bool m_bCfgInited; -}; - -#endif // INCLUDED_SVTOOLS_SYSCREDS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddecli.cxx b/svl/source/svdde/ddecli.cxx deleted file mode 100644 index 7203e129d0..0000000000 --- a/svl/source/svdde/ddecli.cxx +++ /dev/null @@ -1,473 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#define UNICODE -#include <string.h> // memset -#include <algorithm> -#include "ddeimp.hxx" -#include <svl/svdde.hxx> - -#include <osl/thread.h> -#include <tools/debug.hxx> -#include <tools/solarmutex.hxx> -#include <osl/mutex.hxx> - -DdeInstData* ImpInitInstData() -{ - DdeInstData* pData = new DdeInstData; - memset( pData,0,sizeof(DdeInstData) ); - DdeInstData** ppInst = (DdeInstData**)GetAppData( SHL_SVDDE ); - *ppInst = pData; - return pData; -} - -void ImpDeinitInstData() -{ - DdeInstData** ppInst = (DdeInstData**)GetAppData( SHL_SVDDE ); - delete (*ppInst); - *ppInst = 0; -} - - -struct DdeImp -{ - HCONV hConv; - long nStatus; -}; - -// --- DdeInternat::CliCallback() ---------------------------------- - -HDDEDATA CALLBACK DdeInternal::CliCallback( - WORD nCode, WORD nCbType, HCONV hConv, HSZ, HSZ hText2, - HDDEDATA hData, DWORD nInfo1, DWORD ) -{ - HDDEDATA nRet = DDE_FNOTPROCESSED; - const std::vector<DdeConnection*> &rAll = DdeConnection::GetConnections(); - DdeConnection* self = 0; - - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - - for ( size_t i = 0; i < rAll.size(); ++i) - { - self = rAll[i]; - - if ( self->pImp->hConv == hConv ) - break; - } - - if( self ) - { - sal_Bool bFound = sal_False; - std::vector<DdeTransaction*>::iterator iter; - for( iter = self->aTransactions.begin(); iter != self->aTransactions.end(); ++iter ) - { - switch( nCode ) - { - case XTYP_XACT_COMPLETE: - if( (DWORD)(*iter)->nId == nInfo1 ) - { - nCode = (*iter)->nType & (XCLASS_MASK | XTYP_MASK); - (*iter)->bBusy = sal_False; - (*iter)->Done( 0 != hData ); - bFound = sal_True; - } - break; - - case XTYP_DISCONNECT: - self->pImp->hConv = DdeReconnect( hConv ); - self->pImp->nStatus = self->pImp->hConv - ? DMLERR_NO_ERROR - : DdeGetLastError( pInst->hDdeInstCli ); - iter = self->aTransactions.end(); - nRet = 0; - bFound = sal_True; - break; - - case XTYP_ADVDATA: - bFound = sal_Bool( *(*iter)->pName == hText2 ); - break; - } - if( bFound ) - break; - } - - if( iter != self->aTransactions.end() ) - { - switch( nCode ) - { - case XTYP_ADVDATA: - if( !hData ) - { - static_cast<DdeLink*>(*iter)->Notify(); - nRet = (HDDEDATA)DDE_FACK; - break; - } - // kein break; - - case XTYP_REQUEST: - if( !hData && XTYP_REQUEST == nCode ) - { - - } - - DdeData d; - d.pImp->hData = hData; - d.pImp->nFmt = DdeData::GetInternalFormat( nCbType ); - d.Lock(); - (*iter)->Data( &d ); - nRet = (HDDEDATA)DDE_FACK; - break; - } - } - } - return nRet; -} - -// --- DdeConnection::DdeConnection() ------------------------------ - -DdeConnection::DdeConnection( const String& rService, const String& rTopic ) -{ - pImp = new DdeImp; - pImp->nStatus = DMLERR_NO_ERROR; - pImp->hConv = NULL; - - DdeInstData* pInst = ImpGetInstData(); - if( !pInst ) - pInst = ImpInitInstData(); - pInst->nRefCount++; - pInst->nInstanceCli++; - if ( !pInst->hDdeInstCli ) - { - pImp->nStatus = DdeInitialize( &pInst->hDdeInstCli, - (PFNCALLBACK)DdeInternal::CliCallback, - APPCLASS_STANDARD | APPCMD_CLIENTONLY | - CBF_FAIL_ALLSVRXACTIONS | - CBF_SKIP_REGISTRATIONS | - CBF_SKIP_UNREGISTRATIONS, 0L ); - } - - pService = new DdeString( pInst->hDdeInstCli, rService ); - pTopic = new DdeString( pInst->hDdeInstCli, rTopic ); - - if ( pImp->nStatus == DMLERR_NO_ERROR ) - { - pImp->hConv = DdeConnect( pInst->hDdeInstCli,*pService,*pTopic, NULL); - if( !pImp->hConv ) - pImp->nStatus = DdeGetLastError( pInst->hDdeInstCli ); - } - - pInst->aConnections.push_back( this ); -} - -// --- DdeConnection::~DdeConnection() ----------------------------- - -DdeConnection::~DdeConnection() -{ - if ( pImp->hConv ) - DdeDisconnect( pImp->hConv ); - - delete pService; - delete pTopic; - - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - - std::vector<DdeConnection*>::iterator it(std::find(pInst->aConnections.begin(), - pInst->aConnections.end(), - this)); - if (it != pInst->aConnections.end()) - pInst->aConnections.erase(it); - - pInst->nInstanceCli--; - pInst->nRefCount--; - if ( !pInst->nInstanceCli && pInst->hDdeInstCli ) - { - if( DdeUninitialize( pInst->hDdeInstCli ) ) - { - pInst->hDdeInstCli = NULL; - if( pInst->nRefCount == 0 ) - ImpDeinitInstData(); - } - } - delete pImp; -} - -// --- DdeConnection::IsConnected() -------------------------------- - -sal_Bool DdeConnection::IsConnected() -{ - CONVINFO c; - c.cb = sizeof( c ); - if ( DdeQueryConvInfo( pImp->hConv, QID_SYNC, &c ) ) - return sal_True; - else - { - DdeInstData* pInst = ImpGetInstData(); - pImp->hConv = DdeReconnect( pImp->hConv ); - pImp->nStatus = pImp->hConv ? DMLERR_NO_ERROR : DdeGetLastError( pInst->hDdeInstCli ); - return sal_Bool( pImp->nStatus == DMLERR_NO_ERROR ); - } -} - -// --- DdeConnection::GetServiceName() ----------------------------- - -const String& DdeConnection::GetServiceName() -{ - return (const String&)*pService; -} - -// --- DdeConnection::GetTopicName() ------------------------------- - -const String& DdeConnection::GetTopicName() -{ - return (const String&)*pTopic; -} - -// --- DdeConnection::GetConvId() ---------------------------------- - -long DdeConnection::GetConvId() -{ - return (long)pImp->hConv; -} - -const std::vector<DdeConnection*>& DdeConnection::GetConnections() -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - return pInst->aConnections; -} - -// --- DdeTransaction::DdeTransaction() ---------------------------- - -DdeTransaction::DdeTransaction( DdeConnection& d, const String& rItemName, - long n ) : - rDde( d ) -{ - DdeInstData* pInst = ImpGetInstData(); - pName = new DdeString( pInst->hDdeInstCli, rItemName ); - nTime = n; - nId = 0; - nType = 0; - bBusy = sal_False; - - rDde.aTransactions.push_back( this ); -} - -// --- DdeTransaction::~DdeTransaction() --------------------------- - -DdeTransaction::~DdeTransaction() -{ - if ( nId && rDde.pImp->hConv ) - { - DdeInstData* pInst = ImpGetInstData(); - DdeAbandonTransaction( pInst->hDdeInstCli, rDde.pImp->hConv, nId ); - } - - delete pName; - rDde.aTransactions.erase(std::remove(rDde.aTransactions.begin(), - rDde.aTransactions.end(),this)); -} - -// --- DdeTransaction::Execute() ----------------------------------- - -void DdeTransaction::Execute() -{ - HSZ hItem = *pName; - void* pData = (void*)(const void *)aDdeData; - DWORD nData = (DWORD)(long)aDdeData; - sal_uLong nIntFmt = aDdeData.pImp->nFmt; - UINT nExtFmt = DdeData::GetExternalFormat( nIntFmt ); - DdeInstData* pInst = ImpGetInstData(); - - if ( nType == XTYP_EXECUTE ) - hItem = NULL; - if ( nType != XTYP_EXECUTE && nType != XTYP_POKE ) - { - pData = NULL; - nData = 0L; - } - if ( nTime ) - { - HDDEDATA hData = DdeClientTransaction( (unsigned char*)pData, - nData, rDde.pImp->hConv, - hItem, nExtFmt, (UINT)nType, - (DWORD)nTime, (DWORD FAR*)NULL ); - - rDde.pImp->nStatus = DdeGetLastError( pInst->hDdeInstCli ); - if( hData && nType == XTYP_REQUEST ) - { - { - DdeData d; - d.pImp->hData = hData; - d.pImp->nFmt = nIntFmt; - d.Lock(); - Data( &d ); - } - DdeFreeDataHandle( hData ); - } - } - else - { - if ( nId && rDde.pImp->hConv ) - DdeAbandonTransaction( pInst->hDdeInstCli, rDde.pImp->hConv, nId); - nId = 0; - bBusy = sal_True; - HDDEDATA hRet = DdeClientTransaction( (unsigned char*)pData, nData, - rDde.pImp->hConv, hItem, nExtFmt, - (UINT)nType, TIMEOUT_ASYNC, - (DWORD FAR *) ((long*) &nId) ); - rDde.pImp->nStatus = hRet ? DMLERR_NO_ERROR - : DdeGetLastError( pInst->hDdeInstCli ); - } -} - -// --- DdeTransaction::GetName() ----------------------------------- - -const String& DdeTransaction::GetName() const -{ - return *pName; -} - -// --- DdeTransaction::Data() -------------------------------------- - - -void DdeTransaction::Data( const DdeData* p ) -{ - if ( ::tools::SolarMutex::Acquire() ) - { - aData.Call( (void*)p ); - ::tools::SolarMutex::Release(); - } -} - -// --- DdeTransaction::Done() -------------------------------------- - -void DdeTransaction::Done( sal_Bool bDataValid ) -{ - aDone.Call( (void*)bDataValid ); -} - -// --- DdeLink::DdeLink() ------------------------------------------ - -DdeLink::DdeLink( DdeConnection& d, const String& aItemName, long n ) : - DdeTransaction (d, aItemName, n) -{ -} - -// --- DdeLink::~DdeLink() ----------------------------------------- - -DdeLink::~DdeLink() -{ - nType = (sal_uInt16)XTYP_ADVSTOP; - nTime = 0; -} - -// --- DdeLink::Notify() ----------------------------------------- - -void DdeLink::Notify() -{ - aNotify.Call( NULL ); -} - -// --- DdeRequest::DdeRequest() ------------------------------------ - -DdeRequest::DdeRequest( DdeConnection& d, const String& i, long n ) : - DdeTransaction( d, i, n ) -{ - nType = XTYP_REQUEST; -} - -// --- DdeWarmLink::DdeWarmLink() ---------------------------------- - -DdeWarmLink::DdeWarmLink( DdeConnection& d, const String& i, long n ) : - DdeLink( d, i, n ) -{ - nType = XTYP_ADVSTART | XTYPF_NODATA; -} - -// --- DdeHotLink::DdeHotLink() ------------------------------------ - -DdeHotLink::DdeHotLink( DdeConnection& d, const String& i, long n ) : - DdeLink( d, i, n ) -{ - nType = XTYP_ADVSTART; -} - -// --- DdePoke::DdePoke() ------------------------------------------ - -DdePoke::DdePoke( DdeConnection& d, const String& i, const char* p, - long l, sal_uLong f, long n ) : - DdeTransaction( d, i, n ) -{ - aDdeData = DdeData( p, l, f ); - nType = XTYP_POKE; -} - -// --- DdePoke::DdePoke() ------------------------------------------ - -DdePoke::DdePoke( DdeConnection& d, const String& i, const String& rData, - long n ) : - DdeTransaction( d, i, n ) -{ -// ByteString aByteStr( rData, osl_getThreadTextEncoding() ); - aDdeData = DdeData( (void*) rData.GetBuffer(), sizeof(sal_Unicode) * (rData.Len()), CF_TEXT ); - nType = XTYP_POKE; -} - -// --- DdePoke::DdePoke() ------------------------------------------ - -DdePoke::DdePoke( DdeConnection& d, const String& i, const DdeData& rData, - long n ) : - DdeTransaction( d, i, n ) -{ - aDdeData = rData; - nType = XTYP_POKE; -} - -// --- DdeExecute::DdeExecute() ------------------------------------ - -DdeExecute::DdeExecute( DdeConnection& d, const String& rData, long n ) : - DdeTransaction( d, String(), n ) -{ -// ByteString aByteStr( rData, osl_getThreadTextEncoding() ); - aDdeData = DdeData( (void*)rData.GetBuffer(), sizeof(sal_Unicode) * (rData.Len() + 1), CF_TEXT ); - nType = XTYP_EXECUTE; -} - -// --- DdeConnection::GetError() ----------------------------------- - -long DdeConnection::GetError() -{ - return pImp->nStatus; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddedata.cxx b/svl/source/svdde/ddedata.cxx deleted file mode 100644 index 3e1d6a4e5b..0000000000 --- a/svl/source/svdde/ddedata.cxx +++ /dev/null @@ -1,205 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -// ACHTUNG: es wird angenommen, dass StarView-Clipboard-Foamatnummern -// und Windows-Formatnummern identisch sind! Ist dies einmal nicht der -// Fall, muessen die Routinen hier angepasst werden. Die Implementation -// verwendet die hier defineirten Konversionen. - -#define UNICODE - -#include <string.h> -#include "ddeimp.hxx" -#include <svl/svdde.hxx> - -#include <osl/thread.h> - -// --- DdeData::DdeData() ------------------------------------------ - -DdeData::DdeData() -{ - pImp = new DdeDataImp; - pImp->hData = NULL; - pImp->nData = 0; - pImp->pData = NULL; - pImp->nFmt = CF_TEXT; -} - -// --- DdeData::DdeData() ------------------------------------------ - -DdeData::DdeData( const void* p, long n, sal_uLong f ) -{ - pImp = new DdeDataImp; - pImp->hData = NULL; - pImp->pData = (LPBYTE)p; - pImp->nData = n; - pImp->nFmt = f; -} - -// --- DdeData::DdeData() ------------------------------------------ - -DdeData::DdeData( const String& s ) -{ - pImp = new DdeDataImp; - pImp->hData = NULL; - pImp->pData = (LPBYTE)s.GetBuffer(); - pImp->nData = s.Len()+1; - pImp->nFmt = CF_TEXT; -} - -// --- DdeData::DdeData() ------------------------------------------ - -DdeData::DdeData( const DdeData& rData ) -{ - pImp = new DdeDataImp; - pImp->hData = rData.pImp->hData; - pImp->nData = rData.pImp->nData; - pImp->pData = rData.pImp->pData; - pImp->nFmt = rData.pImp->nFmt; - Lock(); -} - -// --- DdeData::~DdeData() ----------------------------------------- - -DdeData::~DdeData() -{ - if ( pImp && pImp->hData ) - DdeUnaccessData( pImp->hData ); - delete pImp; -} - -// --- DdeData::Lock() --------------------------------------------- - -void DdeData::Lock() -{ - if ( pImp->hData ) - pImp->pData = DdeAccessData( pImp->hData, (LPDWORD) &pImp->nData ); -} - -// --- DdeData::GetFormat() ---------------------------------------- - -sal_uLong DdeData::GetFormat() const -{ - return pImp->nFmt; -} - -void DdeData::SetFormat( sal_uLong nFmt ) -{ - pImp->nFmt = nFmt; -} - -// --- DdeData::operator const char*() ----------------------------- - -DdeData::operator const void*() const -{ - return pImp->pData; -} - -// --- DdeData::operator long() ------------------------------------ - -DdeData::operator long() const -{ - return pImp->nData; -} - -// --- DdeData::operator =() --------------------------------------- - -DdeData& DdeData::operator = ( const DdeData& rData ) -{ - if ( &rData != this ) - { - DdeData tmp( rData ); - delete pImp; - pImp = tmp.pImp; - tmp.pImp = NULL; - } - - return *this; -} - -sal_uLong DdeData::GetExternalFormat( sal_uLong nFmt ) -{ - switch( nFmt ) - { - case FORMAT_STRING: - nFmt = CF_TEXT; - break; - case FORMAT_BITMAP: - nFmt = CF_BITMAP; - break; - case FORMAT_GDIMETAFILE: - nFmt = CF_METAFILEPICT; - break; - - default: - { -#if defined(WNT) - String aName( SotExchange::GetFormatName( nFmt ) ); - if( aName.Len() ) - nFmt = RegisterClipboardFormat( reinterpret_cast<LPCWSTR>(aName.GetBuffer()) ); -#endif - } - } - return nFmt; -} - -sal_uLong DdeData::GetInternalFormat( sal_uLong nFmt ) -{ - switch( nFmt ) - { - case CF_TEXT: - nFmt = FORMAT_STRING; - break; - - case CF_BITMAP: - nFmt = FORMAT_BITMAP; - break; - - case CF_METAFILEPICT: - nFmt = FORMAT_GDIMETAFILE; - break; - - default: -#if defined(WNT) - if( nFmt >= CF_MAX ) - { - TCHAR szName[ 256 ]; - - if( GetClipboardFormatName( nFmt, szName, sizeof(szName) ) ) - nFmt = SotExchange::RegisterFormatName( String(reinterpret_cast<const sal_Unicode*>(szName)) ); - } -#endif - break; - } - return nFmt; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddeimp.hxx b/svl/source/svdde/ddeimp.hxx deleted file mode 100644 index b29c953832..0000000000 --- a/svl/source/svdde/ddeimp.hxx +++ /dev/null @@ -1,153 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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 _DDEIMP_HXX -#define _DDEIMP_HXX - -#include <windows.h> -#include <ddeml.h> -#include "ddewrap.hxx" - -#include <tools/string.hxx> -#include <tools/shl.hxx> -#include <vector> - -class DdeService; -class DdeTopic; -class DdeItem; - -// ---------------- -// - Conversation - -// ---------------- - -struct Conversation -{ - HCONV hConv; - DdeTopic* pTopic; -}; - -typedef ::std::vector< Conversation* > ConvList; - -// --------------- -// - DdeInternal - -// --------------- - -class DdeInternal -{ -public: -#ifdef WNT - static HDDEDATA CALLBACK CliCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); - static HDDEDATA CALLBACK SvrCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); - static HDDEDATA CALLBACK InfCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); -#else -#if defined( ICC ) - static HDDEDATA CALLBACK CliCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); - static HDDEDATA CALLBACK SvrCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); - static HDDEDATA CALLBACK InfCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); -#else - static HDDEDATA CALLBACK _export CliCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); - static HDDEDATA CALLBACK _export SvrCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); - static HDDEDATA CALLBACK _export InfCallback - ( WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ); -#endif -#endif - static DdeService* FindService( HSZ ); - static DdeTopic* FindTopic( DdeService&, HSZ ); - static DdeItem* FindItem( DdeTopic&, HSZ ); -}; - -// ------------- -// - DdeString - -// ------------- - -class DdeString : public String -{ -protected: - HSZ hString; - DWORD hInst; - -public: - DdeString( DWORD, const sal_Unicode* ); - DdeString( DWORD, const String& ); - ~DdeString(); - - int operator==( HSZ ); - operator HSZ(); -}; - -// -------------- -// - DdeDataImp - -// -------------- - -struct DdeDataImp -{ - HDDEDATA hData; - LPBYTE pData; - long nData; - sal_uLong nFmt; -}; - -class DdeConnection; -class DdeServices; - -struct DdeInstData -{ - sal_uInt16 nRefCount; - std::vector<DdeConnection*> aConnections; - // Server - long hCurConvSvr; - DWORD hDdeInstSvr; - short nInstanceSvr; - DdeServices* pServicesSvr; - // Client - DWORD hDdeInstCli; - short nInstanceCli; -}; - -#ifndef SHL_SVDDE -#define SHL_SVDDE SHL_SHL2 -#endif - -inline DdeInstData* ImpGetInstData() -{ - return (DdeInstData*)(*GetAppData( SHL_SVDDE )); -} -DdeInstData* ImpInitInstData(); -void ImpDeinitInstData(); - -#endif // _DDEIMP_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddeinf.cxx b/svl/source/svdde/ddeinf.cxx deleted file mode 100644 index 3c4f7a4fca..0000000000 --- a/svl/source/svdde/ddeinf.cxx +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#define UNICODE - -#include <string.h> -#include "ddeimp.hxx" -#include <svl/svdde.hxx> - -// --- DdeInternal::InfCallback() ---------------------------------- - -#ifdef WNT -HDDEDATA CALLBACK DdeInternal::InfCallback( - WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) -#else -#if defined( ICC ) -HDDEDATA CALLBACK DdeInternal::InfCallback( - WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) -#else -HDDEDATA CALLBACK _export DdeInternal::InfCallback( - WORD, WORD, HCONV, HSZ, HSZ, HDDEDATA, DWORD, DWORD ) -#endif -#endif -{ - return (HDDEDATA)DDE_FNOTPROCESSED; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddestrg.cxx b/svl/source/svdde/ddestrg.cxx deleted file mode 100644 index 5e126e3d27..0000000000 --- a/svl/source/svdde/ddestrg.cxx +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#define UNICODE - -#include "ddeimp.hxx" -#include <svl/svdde.hxx> - -// --- DdeString::DdeString() -------------------------------------- - -DdeString::DdeString( DWORD hDdeInst, const sal_Unicode* p ) : - String( p ) -{ - hString = DdeCreateStringHandle( hDdeInst, (LPTSTR)p, CP_WINUNICODE ); - hInst = hDdeInst; -} - -// --- DdeString::DdeString() -------------------------------------- - -DdeString::DdeString( DWORD hDdeInst, const String& r) : - String( r ) -{ - hString = DdeCreateStringHandle( hDdeInst, (LPTSTR)r.GetBuffer(), CP_WINUNICODE ); - hInst = hDdeInst; -} - -// --- DdeString::~DdeString() ------------------------------------- - -DdeString::~DdeString() -{ - if ( hString ) - DdeFreeStringHandle( hInst, hString ); -} - -// --- DdeString::operator==() ------------------------------------- - -int DdeString::operator==( HSZ h ) -{ - return( !DdeCmpStringHandles( hString, h ) ); -} - -// --- DdeString::operator HSZ() ----------------------------------- - -DdeString::operator HSZ() -{ - return hString; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddesvr.cxx b/svl/source/svdde/ddesvr.cxx deleted file mode 100644 index 12b217ccca..0000000000 --- a/svl/source/svdde/ddesvr.cxx +++ /dev/null @@ -1,1090 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#define UNICODE -#include "ddeimp.hxx" -#include <algorithm> -#include <svl/svdde.hxx> -#include <svl/svarray.hxx> -#include <tools/debug.hxx> -#include <osl/thread.h> - -enum DdeItemType -{ - DDEITEM, - DDEGETPUTITEM -}; - -struct DdeItemImpData -{ - sal_uLong nHCnv; - sal_uInt16 nCnt; - - DdeItemImpData( sal_uLong nH ) : nHCnv( nH ), nCnt( 1 ) {} -}; - -SV_DECL_VARARR( DdeItemImp, DdeItemImpData, 1, 1 ) -SV_IMPL_VARARR( DdeItemImp, DdeItemImpData ) - -// --- DdeInternat::SvrCallback() ---------------------------------- - -#ifdef WNT -HDDEDATA CALLBACK DdeInternal::SvrCallback( - WORD nCode, WORD nCbType, HCONV hConv, HSZ hText1, HSZ hText2, - HDDEDATA hData, DWORD, DWORD ) -#else -#if defined( ICC ) -HDDEDATA CALLBACK DdeInternal::SvrCallback( - WORD nCode, WORD nCbType, HCONV hConv, HSZ hText1, HSZ hText2, - HDDEDATA hData, DWORD, DWORD ) -#else -HDDEDATA CALLBACK _export DdeInternal::SvrCallback( - WORD nCode, WORD nCbType, HCONV hConv, HSZ hText1, HSZ hText2, - HDDEDATA hData, DWORD, DWORD ) -#endif -#endif -{ - DdeServices& rAll = DdeService::GetServices(); - DdeService* pService; - DdeTopic* pTopic; - DdeItem* pItem; - DdeData* pData; - Conversation* pC; - - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - - switch( nCode ) - { - case XTYP_WILDCONNECT: - { - int nTopics = 0; - - TCHAR chTopicBuf[250]; - if( hText1 ) - DdeQueryString( pInst->hDdeInstSvr, hText1, chTopicBuf, - sizeof(chTopicBuf)/sizeof(TCHAR), CP_WINUNICODE ); - - for( pService = rAll.First();pService;pService = rAll.Next() ) - { - if ( !hText2 || ( *pService->pName == hText2 ) ) - { - String sTopics( pService->Topics() ); - if( sTopics.Len() ) - { - if( hText1 ) - { - sal_uInt16 n = 0; - while( STRING_NOTFOUND != n ) - { - String s( sTopics.GetToken( 0, '\t', n )); - if( s == reinterpret_cast<const sal_Unicode*>(chTopicBuf) ) - ++nTopics; - } - } - else - nTopics += sTopics.GetTokenCount( '\t' ); - } - } - } - - if( !nTopics ) - return (HDDEDATA)NULL; - - HSZPAIR* pPairs = new HSZPAIR [nTopics + 1]; - if ( !pPairs ) - return (HDDEDATA)NULL; - - HSZPAIR* q = pPairs; - for( pService = rAll.First(); pService; pService = rAll.Next() ) - { - if ( !hText2 || (*pService->pName == hText2 ) ) - { - String sTopics( pService->Topics() ); - sal_uInt16 n = 0; - while( STRING_NOTFOUND != n ) - { - String s( sTopics.GetToken( 0, '\t', n )); - s.EraseAllChars( '\n' ).EraseAllChars( '\r' ); - if( !hText1 || s == reinterpret_cast<const sal_Unicode*>(chTopicBuf) ) - { - DdeString aDStr( pInst->hDdeInstSvr, s ); - pTopic = FindTopic( *pService, (HSZ)aDStr ); - if( pTopic ) - { - q->hszSvc = *pService->pName; - q->hszTopic = *pTopic->pName; - q++; - } - } - } - } - } - - q->hszSvc = NULL; - q->hszTopic = NULL; - HDDEDATA h = DdeCreateDataHandle( - pInst->hDdeInstSvr, (LPBYTE) pPairs, - sizeof(HSZPAIR) * (nTopics+1), - 0, NULL, nCbType, 0); - delete [] pPairs; - return h; - } - - case XTYP_CONNECT: - pService = FindService( hText2 ); - if ( pService) - pTopic = FindTopic( *pService, hText1 ); - else - pTopic = NULL; - if ( pTopic ) - return (HDDEDATA)DDE_FACK; - else - return (HDDEDATA) NULL; - - case XTYP_CONNECT_CONFIRM: - pService = FindService( hText2 ); - if ( pService ) - { - pTopic = FindTopic( *pService, hText1 ); - if ( pTopic ) - { - pTopic->Connect( (long) hConv ); - pC = new Conversation; - pC->hConv = hConv; - pC->pTopic = pTopic; - pService->pConv->push_back( pC ); - } - } - return (HDDEDATA)NULL; - } - - for ( pService = rAll.First(); pService; pService = rAll.Next() ) - { - for ( size_t i = 0, n = pService->pConv->size(); i < n; ++i ) - { - pC = (*pService->pConv)[ i ]; - if ( pC->hConv == hConv ) - goto found; - } - } - - return (HDDEDATA) DDE_FNOTPROCESSED; - -found: - if ( nCode == XTYP_DISCONNECT) - { - pC->pTopic->_Disconnect( (long) hConv ); - for ( ConvList::iterator it = pService->pConv->begin(); - it < pService->pConv->end(); - ++it - ) { - if ( *it == pC ) - { - delete *it; - pService->pConv->erase( it ); - break; - } - } - return (HDDEDATA)NULL; - } - - sal_Bool bExec = sal_Bool(nCode == XTYP_EXECUTE); - pTopic = pC->pTopic; - if ( pTopic && !bExec ) - pItem = FindItem( *pTopic, hText2 ); - else - pItem = NULL; - - if ( !bExec && !pService->HasCbFormat( nCbType ) ) - pItem = NULL; - if ( !pItem && !bExec ) - return (HDDEDATA)DDE_FNOTPROCESSED; - if ( pItem ) - pTopic->aItem = pItem->GetName(); - else - pTopic->aItem.Erase(); - - sal_Bool bRes = sal_False; - pInst->hCurConvSvr = (long)hConv; - switch( nCode ) - { - case XTYP_REQUEST: - case XTYP_ADVREQ: - { - String aRes; // darf erst am Ende freigegeben werden!! - if ( pTopic->IsSystemTopic() ) - { - if ( pTopic->aItem == reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_TOPICS) ) - aRes = pService->Topics(); - else if ( pTopic->aItem == reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_SYSITEMS) ) - aRes = pService->SysItems(); - else if ( pTopic->aItem == reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_STATUS) ) - aRes = pService->Status(); - else if ( pTopic->aItem == reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_FORMATS) ) - aRes = pService->Formats(); - else if ( pTopic->aItem == reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_HELP) ) - aRes = pService->GetHelp(); - else - aRes = pService->SysTopicGet( pTopic->aItem ); - - if ( aRes.Len() ) - pData = new DdeData( aRes ); - else - pData = NULL; - } - else if( DDEGETPUTITEM == pItem->nType ) - pData = ((DdeGetPutItem*)pItem)->Get( - DdeData::GetInternalFormat( nCbType ) ); - else - pData = pTopic->Get( DdeData::GetInternalFormat( nCbType )); - - if ( pData ) - return DdeCreateDataHandle( pInst->hDdeInstSvr, - (LPBYTE)pData->pImp->pData, - pData->pImp->nData, - 0, hText2, - DdeData::GetExternalFormat( - pData->pImp->nFmt ), - 0 ); - } - break; - - case XTYP_POKE: - if ( !pTopic->IsSystemTopic() ) - { - DdeData d; - d.pImp->hData = hData; - d.pImp->nFmt = DdeData::GetInternalFormat( nCbType ); - d.Lock(); - if( DDEGETPUTITEM == pItem->nType ) - bRes = ((DdeGetPutItem*)pItem)->Put( &d ); - else - bRes = pTopic->Put( &d ); - } - pInst->hCurConvSvr = NULL; - if ( bRes ) - return (HDDEDATA)DDE_FACK; - else - return (HDDEDATA) DDE_FNOTPROCESSED; - - case XTYP_ADVSTART: - { - // wird das Item zum erstenmal ein HotLink ? - if( !pItem->pImpData && pTopic->StartAdviseLoop() ) - { - // dann wurde das Item ausgewechselt - std::vector<DdeItem*>::iterator it(std::find(pTopic->aItems.begin(), - pTopic->aItems.end(), - pItem)); - if (it != pTopic->aItems.end()) - pTopic->aItems.erase(it); - - std::vector<DdeItem*>::iterator iter; - for( iter = pTopic->aItems.begin(); - iter != pTopic->aItems.end(); - ++iter ) - { - if( *(*iter)->pName == hText2 ) - { - // es wurde tatsaechlich ausgewechselt - delete pItem; - pItem = 0; - break; - } - } - - if( pItem ) - // es wurde doch nicht ausgewechselt, also wieder rein - pTopic->aItems.push_back(pItem); - else - pItem = iter != pTopic->aItems.end() ? *iter : NULL; - } - - if (pItem) - { - pItem->IncMonitor( (long)hConv ); - pInst->hCurConvSvr = NULL; - } - } - return (HDDEDATA)sal_True; - - case XTYP_ADVSTOP: - pItem->DecMonitor( (long)hConv ); - if( !pItem->pImpData ) - pTopic->StopAdviseLoop(); - pInst->hCurConvSvr = NULL; - return (HDDEDATA)sal_True; - - case XTYP_EXECUTE: - { - DdeData aExec; - aExec.pImp->hData = hData; - aExec.pImp->nFmt = DdeData::GetInternalFormat( nCbType ); - aExec.Lock(); - String aName; - - aName = (const sal_Unicode *)aExec.pImp->pData; - - if( pTopic->IsSystemTopic() ) - bRes = pService->SysTopicExecute( &aName ); - else - bRes = pTopic->Execute( &aName ); - } - pInst->hCurConvSvr = NULL; - if ( bRes ) - return (HDDEDATA)DDE_FACK; - else - return (HDDEDATA)DDE_FNOTPROCESSED; - } - - return (HDDEDATA)NULL; -} - -// --- DdeInternat::FindService() ---------------------------------- - -DdeService* DdeInternal::FindService( HSZ hService ) -{ - DdeService* s; - DdeServices& rSvc = DdeService::GetServices(); - for ( s = rSvc.First(); s; s = rSvc.Next() ) - { - if ( *s->pName == hService ) - return s; - } - - return NULL; -} - -// --- DdeInternat::FindTopic() ------------------------------------ - -DdeTopic* DdeInternal::FindTopic( DdeService& rService, HSZ hTopic ) -{ - std::vector<DdeTopic*>::iterator iter; - std::vector<DdeTopic*> &rTopics = rService.aTopics; - int bWeiter = sal_False; - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - - do { // middle check loop - for ( iter = rTopics.begin(); iter != rTopics.end(); ++iter ) - { - if ( *(*iter)->pName == hTopic ) - return *iter; - } - - bWeiter = !bWeiter; - if( !bWeiter ) - break; - - // dann befragen wir doch mal unsere Ableitung: - TCHAR chBuf[250]; - DdeQueryString(pInst->hDdeInstSvr,hTopic,chBuf,sizeof(chBuf)/sizeof(TCHAR),CP_WINUNICODE ); - bWeiter = rService.MakeTopic( reinterpret_cast<const sal_Unicode*>(chBuf) ); - // dann muessen wir noch mal suchen - } while( bWeiter ); - - return 0; -} - -// --- DdeInternal::FindItem() ------------------------------------- - -DdeItem* DdeInternal::FindItem( DdeTopic& rTopic, HSZ hItem ) -{ - std::vector<DdeItem*>::iterator iter; - std::vector<DdeItem*> &rItems = rTopic.aItems; - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - int bWeiter = sal_False; - - do { // middle check loop - - for ( iter = rItems.begin(); iter != rItems.end(); ++iter ) - if ( *(*iter)->pName == hItem ) - return *iter; - - bWeiter = !bWeiter; - if( !bWeiter ) - break; - - // dann befragen wir doch mal unsere Ableitung: - TCHAR chBuf[250]; - DdeQueryString(pInst->hDdeInstSvr,hItem,chBuf,sizeof(chBuf)/sizeof(TCHAR),CP_WINUNICODE ); - bWeiter = rTopic.MakeItem( reinterpret_cast<const sal_Unicode*>(chBuf) ); - // dann muessen wir noch mal suchen - } while( bWeiter ); - - return 0; -} - -// --- DdeService::DdeService() ------------------------------------ - -DdeService::DdeService( const String& rService ) -{ - DdeInstData* pInst = ImpGetInstData(); - if( !pInst ) - pInst = ImpInitInstData(); - pInst->nRefCount++; - pInst->nInstanceSvr++; - - if ( !pInst->hDdeInstSvr ) - { - nStatus = sal::static_int_cast< short >( - DdeInitialize( &pInst->hDdeInstSvr, - (PFNCALLBACK)DdeInternal::SvrCallback, - APPCLASS_STANDARD | - CBF_SKIP_REGISTRATIONS | - CBF_SKIP_UNREGISTRATIONS, 0L ) ); - pInst->pServicesSvr = new DdeServices; - } - else - nStatus = DMLERR_NO_ERROR; - - pConv = new ConvList; - - if ( pInst->pServicesSvr ) - pInst->pServicesSvr->Insert( this ); - - pName = new DdeString( pInst->hDdeInstSvr, rService ); - if ( nStatus == DMLERR_NO_ERROR ) - if ( !DdeNameService( pInst->hDdeInstSvr, *pName, NULL, - DNS_REGISTER | DNS_FILTEROFF ) ) - nStatus = DMLERR_SYS_ERROR; - - AddFormat( FORMAT_STRING ); - pSysTopic = new DdeTopic( reinterpret_cast<const sal_Unicode*>(SZDDESYS_TOPIC) ); - pSysTopic->AddItem( DdeItem( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_TOPICS) ) ); - pSysTopic->AddItem( DdeItem( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_SYSITEMS) ) ); - pSysTopic->AddItem( DdeItem( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_STATUS) ) ); - pSysTopic->AddItem( DdeItem( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_FORMATS) ) ); - pSysTopic->AddItem( DdeItem( reinterpret_cast<const sal_Unicode*>(SZDDESYS_ITEM_HELP) ) ); - AddTopic( *pSysTopic ); -} - -// --- DdeService::~DdeService() ----------------------------------- - -DdeService::~DdeService() -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - if ( pInst->pServicesSvr ) - pInst->pServicesSvr->Remove( this ); - - // MT: Im Auftrage des Herrn (AM) auskommentiert... - // Grund: - // Bei Client/Server werden die Server nicht beendet, wenn mehr - // als einer gestartet. - // Weil keine System-Messagequeue ?! - - delete pSysTopic; - delete pName; - - pInst->nInstanceSvr--; - pInst->nRefCount--; - if ( !pInst->nInstanceSvr && pInst->hDdeInstSvr ) - { - if( DdeUninitialize( pInst->hDdeInstSvr ) ) - { - pInst->hDdeInstSvr = NULL; - delete pInst->pServicesSvr; - pInst->pServicesSvr = NULL; - if( pInst->nRefCount == 0) - ImpDeinitInstData(); - } - } - delete pConv; -} - -// --- DdeService::GetName() --------------------------------------- - -const String& DdeService::GetName() const -{ - return *pName; -} - -// --- DdeService::GetServices() ----------------------------------- - -DdeServices& DdeService::GetServices() -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - return *(pInst->pServicesSvr); -} - -// --- DdeService::AddTopic() -------------------------------------- - -void DdeService::AddTopic( const DdeTopic& rTopic ) -{ - RemoveTopic( rTopic ); - aTopics.push_back((DdeTopic *) &rTopic); -} - -// --- DdeService::RemoveTopic() ----------------------------------- - -void DdeService::RemoveTopic( const DdeTopic& rTopic ) -{ - std::vector<DdeTopic*>::iterator iter; - for ( iter = aTopics.begin(); iter != aTopics.end(); ++iter ) - { - if ( !DdeCmpStringHandles (*(*iter)->pName, *rTopic.pName ) ) - { - aTopics.erase(iter); - // JP 27.07.95: und alle Conversions loeschen !!! - // (sonst wird auf geloeschten Topics gearbeitet!!) - for( size_t n = pConv->size(); n; ) - { - Conversation* pC = (*pConv)[ --n ]; - if( pC->pTopic == &rTopic ) - { - ConvList::iterator it = pConv->begin(); - ::std::advance( it, n ); - delete *it; - pConv->erase( it ); - } - } - break; - } - } -} - -// --- DdeService::HasCbFormat() ----------------------------------- - -sal_Bool DdeService::HasCbFormat( sal_uInt16 nFmt ) -{ - for ( size_t i = 0, n = aFormats.size(); i < n; ++i ) - if ( aFormats[ i ] == nFmt ) - return true; - return false; -} - -// --- DdeService::HasFormat() ------------------------------------- - -sal_Bool DdeService::HasFormat( sal_uLong nFmt ) -{ - return HasCbFormat( (sal_uInt16)DdeData::GetExternalFormat( nFmt )); -} - -// --- DdeService::AddFormat() ------------------------------------- - -void DdeService::AddFormat( sal_uLong nFmt ) -{ - nFmt = DdeData::GetExternalFormat( nFmt ); - for ( size_t i = 0, n = aFormats.size(); i < n; ++i ) - if ( aFormats[ i ] == nFmt ) - return; - aFormats.push_back( nFmt ); -} - -// --- DdeService::RemoveFormat() ---------------------------------- - -void DdeService::RemoveFormat( sal_uLong nFmt ) -{ - nFmt = DdeData::GetExternalFormat( nFmt ); - for ( DdeFormats::iterator it = aFormats.begin(); it < aFormats.end(); ++it ) { - if ( *it == nFmt ) { - aFormats.erase( it ); - break; - } - } -} - -// --- DdeTopic::DdeTopic() ---------------------------------------- - -DdeTopic::DdeTopic( const String& rName ) -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - pName = new DdeString( pInst->hDdeInstSvr, rName ); -} - -// --- DdeTopic::~DdeTopic() --------------------------------------- - -DdeTopic::~DdeTopic() -{ - std::vector<DdeItem*>::iterator iter; - for (iter = aItems.begin(); iter != aItems.end(); ++iter) - { - (*iter)->pMyTopic = 0; - delete *iter; - } - - delete pName; -} - -// --- DdeTopic::GetName() ----------------------------------------- - -const String& DdeTopic::GetName() const -{ - return *pName; -} - -// --- DdeTopic::IsSystemTopic() ----------------------------------- - -sal_Bool DdeTopic::IsSystemTopic() -{ - return sal_Bool (GetName() == reinterpret_cast<const sal_Unicode*>(SZDDESYS_TOPIC)); -} - -// --- DdeTopic::AddItem() ----------------------------------------- - -DdeItem* DdeTopic::AddItem( const DdeItem& r ) -{ - DdeItem* s; - if( DDEGETPUTITEM == r.nType ) - s = new DdeGetPutItem( r ); - else - s = new DdeItem( r ); - if ( s ) - { - aItems.push_back( s ); - s->pMyTopic = this; - } - return s; -} - -// --- DdeTopic::InsertItem() ----------------------------------------- - -void DdeTopic::InsertItem( DdeItem* pNew ) -{ - if( pNew ) - { - aItems.push_back( pNew ); - pNew->pMyTopic = this; - } -} - -// --- DdeTopic::RemoveItem() -------------------------------------- - -void DdeTopic::RemoveItem( const DdeItem& r ) -{ - std::vector<DdeItem*>::iterator iter; - for (iter = aItems.begin(); iter != aItems.end(); ++iter) - { - if ( !DdeCmpStringHandles (*(*iter)->pName, *r.pName ) ) - break; - } - - if ( iter != aItems.end() ) - { - (*iter)->pMyTopic = 0; - delete *iter; - aItems.erase(iter); - } -} - -// --- DdeTopic::NotifyClient() ------------------------------------ - -void DdeTopic::NotifyClient( const String& rItem ) -{ - std::vector<DdeItem*>::iterator iter; - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - for ( iter = aItems.begin(); iter != aItems.end(); ++iter) - { - if ( (*iter)->GetName() == rItem && (*iter)->pImpData) - { - DdePostAdvise( pInst->hDdeInstSvr, *pName, *(*iter)->pName ); - break; - } - } -} - -// --- DdeTopic::Connect() ----------------------------------------- - -void DdeTopic::Connect( long nId ) -{ - aConnectLink.Call( (void*)nId ); -} - -// --- DdeTopic::Disconnect() -------------------------------------- - -void DdeTopic::Disconnect( long nId ) -{ - aDisconnectLink.Call( (void*)nId ); -} - -// --- DdeTopic::_Disconnect() -------------------------------------- - -void DdeTopic::_Disconnect( long nId ) -{ - std::vector<DdeItem*>::iterator iter; - for (iter = aItems.begin(); iter != aItems.end(); ++iter) - (*iter)->DecMonitor( nId ); - - Disconnect( nId ); -} - -// --- DdeTopic::Get() --------------------------------------------- - -DdeData* DdeTopic::Get( sal_uLong nFmt ) -{ - if ( aGetLink.IsSet() ) - return (DdeData*)aGetLink.Call( (void*)nFmt ); - else - return NULL; -} - -// --- DdeTopic::Put() --------------------------------------------- - -sal_Bool DdeTopic::Put( const DdeData* r ) -{ - if ( aPutLink.IsSet() ) - return (sal_Bool)aPutLink.Call( (void*) r ); - else - return sal_False; -} - -// --- DdeTopic::Execute() ----------------------------------------- - -sal_Bool DdeTopic::Execute( const String* r ) -{ - if ( aExecLink.IsSet() ) - return (sal_Bool)aExecLink.Call( (void*)r ); - else - return sal_False; -} - -// --- DdeTopic::GetConvId() --------------------------------------- - -long DdeTopic::GetConvId() -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - return pInst->hCurConvSvr; -} - -// --- DdeTopic::StartAdviseLoop() --------------------------------- - -sal_Bool DdeTopic::StartAdviseLoop() -{ - return sal_False; -} - -// --- DdeTopic::StopAdviseLoop() ---------------------------------- - -sal_Bool DdeTopic::StopAdviseLoop() -{ - return sal_False; -} - -// --- DdeItem::DdeItem() ------------------------------------------ - -DdeItem::DdeItem( const sal_Unicode* p ) -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - pName = new DdeString( pInst->hDdeInstSvr, p ); - nType = DDEITEM; - pMyTopic = 0; - pImpData = 0; -} - -// --- DdeItem::DdeItem() ------------------------------------------ - -DdeItem::DdeItem( const String& r) -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - pName = new DdeString( pInst->hDdeInstSvr, r ); - nType = DDEITEM; - pMyTopic = 0; - pImpData = 0; -} - -// --- DdeItem::DdeItem() ------------------------------------------ - -DdeItem::DdeItem( const DdeItem& r) -{ - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - pName = new DdeString( pInst->hDdeInstSvr, *r.pName ); - nType = DDEITEM; - pMyTopic = 0; - pImpData = 0; -} - -// --- DdeItem::~DdeItem() ----------------------------------------- - -DdeItem::~DdeItem() -{ - if( pMyTopic ) - pMyTopic->aItems.erase(std::remove(pMyTopic->aItems.begin(), - pMyTopic->aItems.end(),this)); - delete pName; - delete pImpData; -} - -// --- DdeItem::GetName() ------------------------------------------ - -const String& DdeItem::GetName() const -{ - return *pName; -} - -// --- DdeItem::NotifyClient() ------------------------------------------ - -void DdeItem::NotifyClient() -{ - if( pMyTopic && pImpData ) - { - DdeInstData* pInst = ImpGetInstData(); - DBG_ASSERT(pInst,"SVDDE:No instance data"); - DdePostAdvise( pInst->hDdeInstSvr, *pMyTopic->pName, *pName ); - } -} - -// --- DdeItem::IncMonitor() ------------------------------------------ - -void DdeItem::IncMonitor( sal_uLong nHCnv ) -{ - if( !pImpData ) - { - pImpData = new DdeItemImp; - if( DDEGETPUTITEM == nType ) - ((DdeGetPutItem*)this)->AdviseLoop( sal_True ); - } - else - { - for( sal_uInt16 n = pImpData->Count(); n; ) - if( (*pImpData)[ --n ].nHCnv == nHCnv ) - { - ++(*pImpData)[ n ].nHCnv; - return ; - } - } - - pImpData->Insert( DdeItemImpData( nHCnv ), pImpData->Count() ); -} - -// --- DdeItem::DecMonitor() ------------------------------------------ - -void DdeItem::DecMonitor( sal_uLong nHCnv ) -{ - if( pImpData ) - { - DdeItemImpData* pData = (DdeItemImpData*)pImpData->GetData(); - for( sal_uInt16 n = pImpData->Count(); n; --n, ++pData ) - if( pData->nHCnv == nHCnv ) - { - if( !pData->nCnt || !--pData->nCnt ) - { - if( 1 < pImpData->Count() ) - pImpData->Remove( pImpData->Count() - n ); - else - { - delete pImpData, pImpData = 0; - if( DDEGETPUTITEM == nType ) - ((DdeGetPutItem*)this)->AdviseLoop( sal_False ); - } - } - return ; - } - } -} - -// --- DdeItem::GetLinks() ------------------------------------------ - -short DdeItem::GetLinks() -{ - short nCnt = 0; - if( pImpData ) - for( sal_uInt16 n = pImpData->Count(); n; ) - nCnt = nCnt + (*pImpData)[ --n ].nCnt; - return nCnt; -} - -// --- DdeGetPutItem::DdeGetPutItem() ------------------------------ - -DdeGetPutItem::DdeGetPutItem( const sal_Unicode* p ) - : DdeItem( p ) -{ - nType = DDEGETPUTITEM; -} - -// --- DdeGetPutItem::DdeGetPutItem() ------------------------------ - -DdeGetPutItem::DdeGetPutItem( const String& rStr ) - : DdeItem( rStr ) -{ - nType = DDEGETPUTITEM; -} - -// --- DdeGetPutItem::DdeGetPutItem() ------------------------------ - -DdeGetPutItem::DdeGetPutItem( const DdeItem& rItem ) - : DdeItem( rItem ) -{ - nType = DDEGETPUTITEM; -} - - -// --- DdeGetPutData::Get() ---------------------------------------- - -DdeData* DdeGetPutItem::Get( sal_uLong ) -{ - return 0; -} - -// --- DdeGetPutData::Put() ---------------------------------------- - -sal_Bool DdeGetPutItem::Put( const DdeData* ) -{ - return sal_False; -} - -// --- DdeGetPutData::AdviseLoop() --------------------------------- - -void DdeGetPutItem::AdviseLoop( sal_Bool ) -{ -} - - -// --- DdeService::SysItems() -------------------------------------- - -String DdeService::SysItems() -{ - String s; - std::vector<DdeTopic*>::iterator iter; - std::vector<DdeItem*>::iterator iterItem; - for ( iter = aTopics.begin(); iter != aTopics.end(); ++iter ) - { - if ( (*iter)->GetName() == reinterpret_cast<const sal_Unicode*>(SZDDESYS_TOPIC) ) - { - short n = 0; - for ( iterItem = (*iter)->aItems.begin(); iterItem != (*iter)->aItems.end(); ++iterItem, n++ ) - { - if ( n ) - s += '\t'; - s += (*iterItem)->GetName(); - } - s += String::CreateFromAscii("\r\n"); - } - } - - return s; -} - -// --- DdeService::Topics() ---------------------------------------- - -String DdeService::Topics() -{ - String s; - std::vector<DdeTopic*>::iterator iter; - short n = 0; - - for ( iter = aTopics.begin(); iter != aTopics.end(); ++iter, n++ ) - { - if ( n ) - s += '\t'; - s += (*iter)->GetName(); - } - s += String::CreateFromAscii("\r\n"); - - return s; -} - -// --- DdeService::Formats() --------------------------------------- - -String DdeService::Formats() -{ - String s; - long f; - TCHAR buf[128]; - LPCTSTR p; - short n = 0; - - for ( size_t i = 0; i < aFormats.size(); ++i, n++ ) - { - f = aFormats[ i ]; - if ( n ) - s += '\t'; - p = buf; - - switch( (sal_uInt16)f ) - { - case CF_TEXT: - p = reinterpret_cast<LPCTSTR>(String::CreateFromAscii("TEXT").GetBuffer()); - break; - case CF_BITMAP: - p = reinterpret_cast<LPCTSTR>(String::CreateFromAscii("BITMAP").GetBuffer()); - break; - default: - GetClipboardFormatName( (UINT)f, buf, sizeof(buf) / sizeof(TCHAR) ); - } - s += String( reinterpret_cast<const sal_Unicode*>(p) ); - } - s += String::CreateFromAscii("\r\n"); - - return s; -} - -// --- DdeService::Status() ---------------------------------------- - -String DdeService::Status() -{ - return IsBusy() ? String::CreateFromAscii("Busy\r\n") : String::CreateFromAscii("Ready\r\n"); -} - -// --- DdeService::IsBusy() ---------------------------------------- - -sal_Bool DdeService::IsBusy() -{ - return sal_False; -} - -// --- DdeService::GetHelp() ---------------------------------------- - -String DdeService::GetHelp() -{ - return String(); -} - -sal_Bool DdeTopic::MakeItem( const String& ) -{ - return sal_False; -} - -sal_Bool DdeService::MakeTopic( const String& ) -{ - return sal_False; -} - -String DdeService::SysTopicGet( const String& ) -{ - return String(); -} - -sal_Bool DdeService::SysTopicExecute( const String* ) -{ - return sal_False; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddewrap.cxx b/svl/source/svdde/ddewrap.cxx deleted file mode 100644 index f59897b15e..0000000000 --- a/svl/source/svdde/ddewrap.cxx +++ /dev/null @@ -1,102 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#define _SVTOOLS_SVDDE_DDEWRAP_CXX_ - -#if defined _MSC_VER -#pragma warning(push, 1) -#endif -#include <windows.h> -#if defined _MSC_VER -#pragma warning(pop) -#endif -#include "ddewrap.hxx" - -//------------------------------------------------------------------------ - -HSZ WINAPI DdeCreateStringHandleW_9x( DWORD idInst, LPCWSTR pszString, int ) -{ - HSZ hszResult; - LPSTR pszANSIString; - int nSize; - - nSize = pszString ? WideCharToMultiByte( CP_ACP, 0, pszString, -1, NULL, 0, NULL, NULL ) : 0; - pszANSIString = nSize ? (LPSTR)HeapAlloc( GetProcessHeap(), 0, nSize * sizeof(CHAR) ) : NULL; - - if ( pszANSIString ) - WideCharToMultiByte( CP_ACP, 0, pszString, -1, pszANSIString, nSize, NULL, NULL ); - - hszResult = DdeCreateStringHandleA( idInst, pszANSIString, CP_WINANSI ); - - if ( pszANSIString ) - HeapFree( GetProcessHeap(), 0, pszANSIString ); - - return hszResult; -} - -//------------------------------------------------------------------------ - -DWORD WINAPI DdeQueryStringW_9x( DWORD idInst, HSZ hsz, LPWSTR pszString, DWORD cchMax, int ) -{ - DWORD dwResult; - LPSTR pszANSIString; - - pszANSIString = cchMax ? (LPSTR)HeapAlloc( GetProcessHeap(), 0, cchMax * sizeof(CHAR) ) : NULL; - - dwResult = DdeQueryStringA( idInst, hsz, pszANSIString, cchMax, CP_WINANSI ); - - if ( dwResult && pszANSIString ) - MultiByteToWideChar( CP_ACP, 0, pszANSIString, -1, pszString, cchMax ); - - if ( pszANSIString ) - HeapFree( GetProcessHeap(), 0, pszANSIString ); - - return dwResult; -} - -//------------------------------------------------------------------------ - -UINT WINAPI DdeInitializeW_9x( LPDWORD pidInst, PFNCALLBACK pfnCallback, DWORD afCmd, DWORD ulRes ) -{ - return DdeInitializeA( pidInst, pfnCallback, afCmd, ulRes ); -} - -//------------------------------------------------------------------------ - -#define DEFINE_WAPI_FUNC(func) \ -func##_PROC lpfn##func = (LONG)GetVersion() >= 0 ? func : func##_9x; - - -DEFINE_WAPI_FUNC( DdeCreateStringHandleW ); -DEFINE_WAPI_FUNC( DdeQueryStringW ); -DEFINE_WAPI_FUNC( DdeInitializeW ); - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svdde/ddewrap.hxx b/svl/source/svdde/ddewrap.hxx deleted file mode 100644 index 36a480f693..0000000000 --- a/svl/source/svdde/ddewrap.hxx +++ /dev/null @@ -1,27 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -#ifndef _SVTOOLS_SVDDE_DDEWRAP_HXX_ -#define _SVTOOLS_SVDDE_DDEWRAP_HXX_ - -#define DECLARE_WAPI_FUNC(func) \ - extern func##_PROC lpfn##func; - -typedef HSZ (WINAPI *DdeCreateStringHandleW_PROC)( DWORD idInst, LPCWSTR pszString, int iCodePage ); -typedef DWORD (WINAPI *DdeQueryStringW_PROC)( DWORD idInst, HSZ hsz, LPWSTR pszString, DWORD cchMax, int iCodePage ); -typedef UINT (WINAPI *DdeInitializeW_PROC)( LPDWORD pidInst, PFNCALLBACK pfnCallback, DWORD afCmd, DWORD ulRes ); - - -DECLARE_WAPI_FUNC( DdeCreateStringHandleW ); -DECLARE_WAPI_FUNC( DdeQueryStringW ); -DECLARE_WAPI_FUNC( DdeInitializeW ); - - -#ifndef _SVTOOLS_SVDDE_DDEWRAP_CXX_ -#define DdeCreateStringHandleW lpfnDdeCreateStringHandleW -#define DdeQueryStringW lpfnDdeQueryStringW -#define DdeInitializeW lpfnDdeInitializeW -#endif - - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/svsql/converter.cxx b/svl/source/svsql/converter.cxx deleted file mode 100644 index bd58d4469b..0000000000 --- a/svl/source/svsql/converter.cxx +++ /dev/null @@ -1,44 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include <svl/converter.hxx> - -sal_Int32 SvDbaseConverter::ConvertPrecisionToDbase(sal_Int32 _nLen, sal_Int32 _nScale) -{ - return _nScale ? _nLen +2 : _nLen +1; -} -//------------------------------------------------------------------------ -sal_Int32 SvDbaseConverter::ConvertPrecisionToOdbc(sal_Int32 _nLen, sal_Int32 _nScale) -{ - return _nScale ? _nLen -2 : _nLen -1; -} - - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx deleted file mode 100644 index 03c970a06d..0000000000 --- a/svl/source/undo/undo.cxx +++ /dev/null @@ -1,1502 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <com/sun/star/uno/Exception.hpp> - -#include <comphelper/flagguard.hxx> -#include <tools/debug.hxx> -#include <tools/diagnose_ex.h> - -#include <svl/undo.hxx> - -#include <vector> -#include <list> -#include <limits> - -using ::com::sun::star::uno::Exception; - -// STATIC DATA ----------------------------------------------------------- - -DBG_NAME(SfxUndoAction) - -//======================================================================== - -TYPEINIT0(SfxUndoAction); -TYPEINIT0(SfxListUndoAction); -TYPEINIT0(SfxLinkUndoAction); -TYPEINIT0(SfxRepeatTarget); - -//------------------------------------------------------------------------ - -SfxRepeatTarget::~SfxRepeatTarget() -{ -} - -//------------------------------------------------------------------------ - -SfxUndoContext::~SfxUndoContext() -{ -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoAction::IsLinked() -{ - return bLinked; -} - -//------------------------------------------------------------------------ - -void SfxUndoAction::SetLinked( sal_Bool bIsLinked ) -{ - bLinked = bIsLinked; -} - -//------------------------------------------------------------------------ - -SfxUndoAction::~SfxUndoAction() -{ - DBG_DTOR(SfxUndoAction, 0); - DBG_ASSERT( !IsLinked(), "Gelinkte Action geloescht" ); -} - - -SfxUndoAction::SfxUndoAction() -{ - DBG_CTOR(SfxUndoAction, 0); - SetLinked( sal_False ); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoAction::Merge( SfxUndoAction * ) -{ - DBG_CHKTHIS(SfxUndoAction, 0); - return sal_False; -} - -//------------------------------------------------------------------------ - -XubString SfxUndoAction::GetComment() const -{ - DBG_CHKTHIS(SfxUndoAction, 0); - return XubString(); -} - -//------------------------------------------------------------------------ - - -sal_uInt16 SfxUndoAction::GetId() const -{ - DBG_CHKTHIS(SfxUndoAction, 0); - return 0; -} - -//------------------------------------------------------------------------ - -XubString SfxUndoAction::GetRepeatComment(SfxRepeatTarget&) const -{ - DBG_CHKTHIS(SfxUndoAction, 0); - return GetComment(); -} - -//------------------------------------------------------------------------ - -void SfxUndoAction::Undo() -{ - // die sind nur konzeptuell pure virtual - OSL_FAIL( "pure virtual function called: SfxUndoAction::Undo()" ); -} - -//------------------------------------------------------------------------ - -void SfxUndoAction::UndoWithContext( SfxUndoContext& i_context ) -{ - (void)i_context; - Undo(); -} - -//------------------------------------------------------------------------ - -void SfxUndoAction::Redo() -{ - // die sind nur konzeptuell pure virtual - OSL_FAIL( "pure virtual function called: SfxUndoAction::Redo()" ); -} - -//------------------------------------------------------------------------ - -void SfxUndoAction::RedoWithContext( SfxUndoContext& i_context ) -{ - (void)i_context; - Redo(); -} - -//------------------------------------------------------------------------ - -void SfxUndoAction::Repeat(SfxRepeatTarget&) -{ - // die sind nur konzeptuell pure virtual - OSL_FAIL( "pure virtual function called: SfxUndoAction::Repeat()" ); -} - -//------------------------------------------------------------------------ - - -sal_Bool SfxUndoAction::CanRepeat(SfxRepeatTarget&) const -{ - return sal_True; -} - -//======================================================================== - -typedef ::std::vector< SfxUndoListener* > UndoListeners; - -struct SVL_DLLPRIVATE SfxUndoManager_Data -{ - ::osl::Mutex aMutex; - SfxUndoArray* pUndoArray; - SfxUndoArray* pActUndoArray; - SfxUndoArray* pFatherUndoArray; - - sal_Int32 mnLockCount; - sal_Int32 mnMarks; - sal_Int32 mnEmptyMark; - bool mbDoing; - bool mbClearUntilTopLevel; - - UndoListeners aListeners; - - SfxUndoManager_Data( size_t i_nMaxUndoActionCount ) - :pUndoArray( new SfxUndoArray( i_nMaxUndoActionCount ) ) - ,pActUndoArray( NULL ) - ,pFatherUndoArray( NULL ) - ,mnLockCount( 0 ) - ,mnMarks( 0 ) - ,mnEmptyMark(MARK_INVALID) - ,mbDoing( false ) - ,mbClearUntilTopLevel( false ) - { - pActUndoArray = pUndoArray; - } - - ~SfxUndoManager_Data() - { - delete pUndoArray; - } -}; - -//======================================================================== - -namespace svl { namespace undo { namespace impl -{ - //-------------------------------------------------------------------- - class SVL_DLLPRIVATE LockGuard - { - public: - LockGuard( SfxUndoManager& i_manager ) - :m_manager( i_manager ) - { - m_manager.ImplEnableUndo_Lock( false ); - } - - ~LockGuard() - { - m_manager.ImplEnableUndo_Lock( true ); - } - - private: - SfxUndoManager& m_manager; - }; - - //-------------------------------------------------------------------- - typedef void ( SfxUndoListener::*UndoListenerVoidMethod )(); - typedef void ( SfxUndoListener::*UndoListenerStringMethod )( const String& ); - - //-------------------------------------------------------------------- - struct SVL_DLLPRIVATE NotifyUndoListener : public ::std::unary_function< SfxUndoListener*, void > - { - NotifyUndoListener() - :m_notificationMethod( NULL ) - ,m_altNotificationMethod( NULL ) - ,m_sActionComment() - { - } - - NotifyUndoListener( UndoListenerVoidMethod i_notificationMethod ) - :m_notificationMethod( i_notificationMethod ) - ,m_altNotificationMethod( NULL ) - ,m_sActionComment() - { - } - - NotifyUndoListener( UndoListenerStringMethod i_notificationMethod, const String& i_actionComment ) - :m_notificationMethod( NULL ) - ,m_altNotificationMethod( i_notificationMethod ) - ,m_sActionComment( i_actionComment ) - { - } - - bool is() const - { - return ( m_notificationMethod != NULL ) || ( m_altNotificationMethod != NULL ); - } - - void operator()( SfxUndoListener* i_listener ) const - { - OSL_PRECOND( is(), "NotifyUndoListener: this will crash!" ); - if ( m_altNotificationMethod != NULL ) - { - ( i_listener->*m_altNotificationMethod )( m_sActionComment ); - } - else - { - ( i_listener->*m_notificationMethod )(); - } - } - - private: - UndoListenerVoidMethod m_notificationMethod; - UndoListenerStringMethod m_altNotificationMethod; - String m_sActionComment; - }; - - //-------------------------------------------------------------------- - class SVL_DLLPRIVATE UndoManagerGuard - { - public: - UndoManagerGuard( SfxUndoManager_Data& i_managerData ) - :m_rManagerData( i_managerData ) - ,m_aGuard( i_managerData.aMutex ) - ,m_notifiers() - { - } - - ~UndoManagerGuard(); - - void clear() - { - m_aGuard.clear(); - } - - void reset() - { - m_aGuard.reset(); - } - - void cancelNotifications() - { - m_notifiers.clear(); - } - - /** marks the given Undo action for deletion - - The Undo action will be put into a list, whose members will be deleted from within the destructor of the - UndoManagerGuard. This deletion will happen without the UndoManager's mutex locked. - */ - void markForDeletion( SfxUndoAction* i_action ) - { - // remember - if ( i_action ) - m_aUndoActionsCleanup.push_back( i_action ); - } - - /** schedules the given SfxUndoListener method to be called for all registered listeners. - - The notification will happen after the Undo manager's mutex has been released, and after all pending - deletions of Undo actions are done. - */ - void scheduleNotification( UndoListenerVoidMethod i_notificationMethod ) - { - m_notifiers.push_back( NotifyUndoListener( i_notificationMethod ) ); - } - - void scheduleNotification( UndoListenerStringMethod i_notificationMethod, const String& i_actionComment ) - { - m_notifiers.push_back( NotifyUndoListener( i_notificationMethod, i_actionComment ) ); - } - - private: - SfxUndoManager_Data& m_rManagerData; - ::osl::ResettableMutexGuard m_aGuard; - ::std::list< SfxUndoAction* > m_aUndoActionsCleanup; - ::std::list< NotifyUndoListener > m_notifiers; - }; - - UndoManagerGuard::~UndoManagerGuard() - { - // copy members - UndoListeners aListenersCopy( m_rManagerData.aListeners ); - - // release mutex - m_aGuard.clear(); - - // delete all actions - while ( !m_aUndoActionsCleanup.empty() ) - { - SfxUndoAction* pAction = m_aUndoActionsCleanup.front(); - m_aUndoActionsCleanup.pop_front(); - try - { - delete pAction; - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - } - - // handle scheduled notification - for ( ::std::list< NotifyUndoListener >::const_iterator notifier = m_notifiers.begin(); - notifier != m_notifiers.end(); - ++notifier - ) - { - if ( notifier->is() ) - ::std::for_each( aListenersCopy.begin(), aListenersCopy.end(), *notifier ); - } - } -} } } - -using namespace ::svl::undo::impl; - -//======================================================================== - -SfxUndoManager::SfxUndoManager( size_t nMaxUndoActionCount ) - :m_pData( new SfxUndoManager_Data( nMaxUndoActionCount ) ) -{ -} - -//------------------------------------------------------------------------ - -SfxUndoManager::~SfxUndoManager() -{ - UndoListeners aListenersCopy; - { - UndoManagerGuard aGuard( *m_pData ); - aListenersCopy = m_pData->aListeners; - } - - ::std::for_each( aListenersCopy.begin(), aListenersCopy.end(), - NotifyUndoListener( &SfxUndoListener::undoManagerDying ) ); -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::EnableUndo( bool i_enable ) -{ - UndoManagerGuard aGuard( *m_pData ); - ImplEnableUndo_Lock( i_enable ); - -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::ImplEnableUndo_Lock( bool const i_enable ) -{ - if ( !i_enable ) - ++m_pData->mnLockCount; - else - { - OSL_PRECOND( m_pData->mnLockCount > 0, "SfxUndoManager::ImplEnableUndo_NoNotify: not disabled, so why enabling?" ); - if ( m_pData->mnLockCount > 0 ) - --m_pData->mnLockCount; - } -} - -//------------------------------------------------------------------------ - -bool SfxUndoManager::IsUndoEnabled() const -{ - UndoManagerGuard aGuard( *m_pData ); - return ImplIsUndoEnabled_Lock(); -} - -//------------------------------------------------------------------------ - -bool SfxUndoManager::ImplIsUndoEnabled_Lock() const -{ - return m_pData->mnLockCount == 0; -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::SetMaxUndoActionCount( size_t nMaxUndoActionCount ) -{ - UndoManagerGuard aGuard( *m_pData ); - - // Remove entries from the pActUndoArray when we have to reduce - // the number of entries due to a lower nMaxUndoActionCount. - // Both redo and undo action entries will be removed until we reached the - // new nMaxUndoActionCount. - - long nNumToDelete = m_pData->pActUndoArray->aUndoActions.size() - nMaxUndoActionCount; - while ( nNumToDelete > 0 ) - { - size_t nPos = m_pData->pActUndoArray->aUndoActions.size(); - if ( nPos > m_pData->pActUndoArray->nCurUndoAction ) - { - SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[nPos-1].pAction; - if ( !pAction->IsLinked() ) - { - aGuard.markForDeletion( pAction ); - m_pData->pActUndoArray->aUndoActions.Remove( nPos-1 ); - --nNumToDelete; - } - } - - if ( nNumToDelete > 0 && m_pData->pActUndoArray->nCurUndoAction > 0 ) - { - SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[0].pAction; - if ( !pAction->IsLinked() ) - { - aGuard.markForDeletion( pAction ); - m_pData->pActUndoArray->aUndoActions.Remove(0); - --m_pData->pActUndoArray->nCurUndoAction; - --nNumToDelete; - } - } - - if ( nPos == m_pData->pActUndoArray->aUndoActions.size() ) - break; // Cannot delete more entries - } - - m_pData->pActUndoArray->nMaxUndoActions = nMaxUndoActionCount; -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::GetMaxUndoActionCount() const -{ - UndoManagerGuard aGuard( *m_pData ); - return m_pData->pActUndoArray->nMaxUndoActions; -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::ImplClearCurrentLevel_NoNotify( UndoManagerGuard& i_guard ) -{ - // clear array - while ( !m_pData->pActUndoArray->aUndoActions.empty() ) - { - size_t deletePos = m_pData->pActUndoArray->aUndoActions.size() - 1; - SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ deletePos ].pAction; - i_guard.markForDeletion( pAction ); - m_pData->pActUndoArray->aUndoActions.Remove( deletePos ); - } - - m_pData->pActUndoArray->nCurUndoAction = 0; - - m_pData->mnMarks = 0; - m_pData->mnEmptyMark = MARK_INVALID; -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::Clear() -{ - UndoManagerGuard aGuard( *m_pData ); - - OSL_ENSURE( !ImplIsInListAction_Lock(), "SfxUndoManager::Clear: suspicious call - do you really wish to clear the current level?" ); - ImplClearCurrentLevel_NoNotify( aGuard ); - - // notify listeners - aGuard.scheduleNotification( &SfxUndoListener::cleared ); -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::ClearAllLevels() -{ - UndoManagerGuard aGuard( *m_pData ); - ImplClearCurrentLevel_NoNotify( aGuard ); - - if ( ImplIsInListAction_Lock() ) - { - m_pData->mbClearUntilTopLevel = true; - } - else - { - aGuard.scheduleNotification( &SfxUndoListener::cleared ); - } -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::ImplClearRedo_NoLock( bool const i_currentLevel ) -{ - UndoManagerGuard aGuard( *m_pData ); - ImplClearRedo( aGuard, i_currentLevel ); -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::ClearRedo() -{ - OSL_ENSURE( !IsInListAction(), "SfxUndoManager::ClearRedo: suspicious call - do you really wish to clear the current level?" ); - ImplClearRedo_NoLock( CurrentLevel ); -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::Reset() -{ - UndoManagerGuard aGuard( *m_pData ); - - // clear all locks - while ( !ImplIsUndoEnabled_Lock() ) - ImplEnableUndo_Lock( true ); - - // cancel all list actions - while ( IsInListAction() ) - ImplLeaveListAction( false, aGuard ); - - // clear both stacks - ImplClearCurrentLevel_NoNotify( aGuard ); - - // cancel the notifications scheduled by ImplLeaveListAction, - // as we want to do an own, dedicated notification - aGuard.cancelNotifications(); - - // schedule notification - aGuard.scheduleNotification( &SfxUndoListener::resetAll ); -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::ImplClearUndo( UndoManagerGuard& i_guard ) -{ - while ( m_pData->pActUndoArray->nCurUndoAction > 0 ) - { - SfxUndoAction* pUndoAction = m_pData->pActUndoArray->aUndoActions[0].pAction; - m_pData->pActUndoArray->aUndoActions.Remove( 0 ); - i_guard.markForDeletion( pUndoAction ); - --m_pData->pActUndoArray->nCurUndoAction; - } - // TODO: notifications? We don't have clearedUndo, only cleared and clearedRedo at the SfxUndoListener -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::ImplClearRedo( UndoManagerGuard& i_guard, bool const i_currentLevel ) -{ - SfxUndoArray* pUndoArray = ( i_currentLevel == IUndoManager::CurrentLevel ) ? m_pData->pActUndoArray : m_pData->pUndoArray; - - // clearance - while ( pUndoArray->aUndoActions.size() > pUndoArray->nCurUndoAction ) - { - size_t deletePos = pUndoArray->aUndoActions.size() - 1; - SfxUndoAction* pAction = pUndoArray->aUndoActions[ deletePos ].pAction; - pUndoArray->aUndoActions.Remove( deletePos ); - i_guard.markForDeletion( pAction ); - } - - // notification - only if the top level's stack was cleared - if ( i_currentLevel == IUndoManager::TopLevel ) - i_guard.scheduleNotification( &SfxUndoListener::clearedRedo ); -} - -//------------------------------------------------------------------------ - -bool SfxUndoManager::ImplAddUndoAction_NoNotify( SfxUndoAction *pAction, bool bTryMerge, bool bClearRedo, UndoManagerGuard& i_guard ) -{ - if ( !ImplIsUndoEnabled_Lock() || ( m_pData->pActUndoArray->nMaxUndoActions == 0 ) ) - { - i_guard.markForDeletion( pAction ); - return false; - } - - // merge, if required - SfxUndoAction* pMergeWithAction = m_pData->pActUndoArray->nCurUndoAction ? - m_pData->pActUndoArray->aUndoActions[m_pData->pActUndoArray->nCurUndoAction-1].pAction : NULL; - if ( bTryMerge && ( !pMergeWithAction || !pMergeWithAction->Merge( pAction ) ) ) - { - i_guard.markForDeletion( pAction ); - return false; - } - - // clear redo stack, if requested - if ( bClearRedo && ( ImplGetRedoActionCount_Lock( CurrentLevel ) > 0 ) ) - ImplClearRedo( i_guard, IUndoManager::CurrentLevel ); - - // respect max number - if( m_pData->pActUndoArray == m_pData->pUndoArray ) - { - while( m_pData->pActUndoArray->aUndoActions.size() >= - m_pData->pActUndoArray->nMaxUndoActions && - !m_pData->pActUndoArray->aUndoActions[0].pAction->IsLinked() ) - { - i_guard.markForDeletion( m_pData->pActUndoArray->aUndoActions[0].pAction ); - m_pData->pActUndoArray->aUndoActions.Remove(0); - --m_pData->pActUndoArray->nCurUndoAction; - } - } - - // append new action - m_pData->pActUndoArray->aUndoActions.Insert( pAction, m_pData->pActUndoArray->nCurUndoAction++ ); - return true; -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::AddUndoAction( SfxUndoAction *pAction, sal_Bool bTryMerge ) -{ - UndoManagerGuard aGuard( *m_pData ); - - // add - if ( ImplAddUndoAction_NoNotify( pAction, bTryMerge, true, aGuard ) ) - { - // notify listeners - aGuard.scheduleNotification( &SfxUndoListener::undoActionAdded, pAction->GetComment() ); - } -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::GetUndoActionCount( bool const i_currentLevel ) const -{ - UndoManagerGuard aGuard( *m_pData ); - const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray; - return pUndoArray->nCurUndoAction; -} - -//------------------------------------------------------------------------ - -XubString SfxUndoManager::GetUndoActionComment( size_t nNo, bool const i_currentLevel ) const -{ - UndoManagerGuard aGuard( *m_pData ); - - String sComment; - const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray; - DBG_ASSERT( nNo < pUndoArray->nCurUndoAction, "svl::SfxUndoManager::GetUndoActionComment: illegal index!" ); - if( nNo < pUndoArray->nCurUndoAction ) - { - sComment = pUndoArray->aUndoActions[ pUndoArray->nCurUndoAction - 1 - nNo ].pAction->GetComment(); - } - return sComment; -} - -//------------------------------------------------------------------------ - -sal_uInt16 SfxUndoManager::GetUndoActionId() const -{ - UndoManagerGuard aGuard( *m_pData ); - - DBG_ASSERT( m_pData->pActUndoArray->nCurUndoAction > 0, "svl::SfxUndoManager::GetUndoActionId(), illegal id!" ); - if ( m_pData->pActUndoArray->nCurUndoAction == 0 ) - return 0; - return m_pData->pActUndoArray->aUndoActions[m_pData->pActUndoArray->nCurUndoAction-1].pAction->GetId(); -} - -//------------------------------------------------------------------------ - -SfxUndoAction* SfxUndoManager::GetUndoAction( size_t nNo ) const -{ - UndoManagerGuard aGuard( *m_pData ); - - DBG_ASSERT( nNo < m_pData->pActUndoArray->nCurUndoAction, "svl::SfxUndoManager::GetUndoAction(), illegal id!" ); - if( nNo >= m_pData->pActUndoArray->nCurUndoAction ) - return NULL; - return m_pData->pActUndoArray->aUndoActions[m_pData->pActUndoArray->nCurUndoAction-1-nNo].pAction; -} - -//------------------------------------------------------------------------ - -/** clears the redo stack and removes the top undo action */ -void SfxUndoManager::RemoveLastUndoAction() -{ - UndoManagerGuard aGuard( *m_pData ); - - ENSURE_OR_RETURN_VOID( m_pData->pActUndoArray->nCurUndoAction, "svl::SfxUndoManager::RemoveLastUndoAction(), no action to remove?!" ); - - m_pData->pActUndoArray->nCurUndoAction--; - - // delete redo-actions and top action - for ( size_t nPos = m_pData->pActUndoArray->aUndoActions.size(); nPos > m_pData->pActUndoArray->nCurUndoAction; --nPos ) - { - aGuard.markForDeletion( m_pData->pActUndoArray->aUndoActions[nPos-1].pAction ); - } - - m_pData->pActUndoArray->aUndoActions.Remove( - m_pData->pActUndoArray->nCurUndoAction, - m_pData->pActUndoArray->aUndoActions.size() - m_pData->pActUndoArray->nCurUndoAction ); -} - -//------------------------------------------------------------------------ - -bool SfxUndoManager::IsDoing() const -{ - UndoManagerGuard aGuard( *m_pData ); - return m_pData->mbDoing; -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::Undo() -{ - return ImplUndo( NULL ); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::UndoWithContext( SfxUndoContext& i_context ) -{ - return ImplUndo( &i_context ); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::ImplUndo( SfxUndoContext* i_contextOrNull ) -{ - UndoManagerGuard aGuard( *m_pData ); - OSL_ENSURE( !IsDoing(), "SfxUndoManager::Undo: *nested* Undo/Redo actions? How this?" ); - - ::comphelper::FlagGuard aDoingGuard( m_pData->mbDoing ); - LockGuard aLockGuard( *this ); - - if ( ImplIsInListAction_Lock() ) - { - OSL_ENSURE( false, "SfxUndoManager::Undo: not possible when within a list action!" ); - return sal_False; - } - - if ( m_pData->pActUndoArray->nCurUndoAction == 0 ) - { - OSL_ENSURE( false, "SfxUndoManager::Undo: undo stack is empty!" ); - return sal_False; - } - - SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ --m_pData->pActUndoArray->nCurUndoAction ].pAction; - const String sActionComment = pAction->GetComment(); - try - { - // clear the guard/mutex before calling into the SfxUndoAction - this can be an extension-implemented UNO component - // nowadays ... - aGuard.clear(); - if ( i_contextOrNull != NULL ) - pAction->UndoWithContext( *i_contextOrNull ); - else - pAction->Undo(); - aGuard.reset(); - } - catch( ... ) - { - aGuard.reset(); - - // in theory, somebody might have tampered with all of *m_pData while the mutex was unlocked. So, see if - // we still find pAction in our current Undo array - size_t nCurAction = 0; - while ( nCurAction < m_pData->pActUndoArray->aUndoActions.size() ) - { - if ( m_pData->pActUndoArray->aUndoActions[ nCurAction++ ].pAction == pAction ) - { - // the Undo action is still there ... - // assume the error is a permanent failure, and clear the Undo stack - ImplClearUndo( aGuard ); - throw; - } - } - OSL_ENSURE( false, "SfxUndoManager::Undo: can't clear the Undo stack after the failure - some other party was faster ..." ); - throw; - } - - aGuard.scheduleNotification( &SfxUndoListener::actionUndone, sActionComment ); - - return sal_True; -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::GetRedoActionCount( bool const i_currentLevel ) const -{ - UndoManagerGuard aGuard( *m_pData ); - return ImplGetRedoActionCount_Lock( i_currentLevel ); -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::ImplGetRedoActionCount_Lock( bool const i_currentLevel ) const -{ - const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray; - return pUndoArray->aUndoActions.size() - pUndoArray->nCurUndoAction; -} - -//------------------------------------------------------------------------ - -XubString SfxUndoManager::GetRedoActionComment( size_t nNo, bool const i_currentLevel ) const -{ - UndoManagerGuard aGuard( *m_pData ); - const SfxUndoArray* pUndoArray = i_currentLevel ? m_pData->pActUndoArray : m_pData->pUndoArray; - return pUndoArray->aUndoActions[ pUndoArray->nCurUndoAction + nNo ].pAction->GetComment(); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::Redo() -{ - return ImplRedo( NULL ); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::RedoWithContext( SfxUndoContext& i_context ) -{ - return ImplRedo( &i_context ); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::ImplRedo( SfxUndoContext* i_contextOrNull ) -{ - UndoManagerGuard aGuard( *m_pData ); - OSL_ENSURE( !IsDoing(), "SfxUndoManager::Redo: *nested* Undo/Redo actions? How this?" ); - - ::comphelper::FlagGuard aDoingGuard( m_pData->mbDoing ); - LockGuard aLockGuard( *this ); - - if ( ImplIsInListAction_Lock() ) - { - OSL_ENSURE( false, "SfxUndoManager::Redo: not possible when within a list action!" ); - return sal_False; - } - - if ( m_pData->pActUndoArray->nCurUndoAction >= m_pData->pActUndoArray->aUndoActions.size() ) - { - OSL_ENSURE( false, "SfxUndoManager::Redo: redo stack is empty!" ); - return sal_False; - } - - SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction++ ].pAction; - const String sActionComment = pAction->GetComment(); - try - { - // clear the guard/mutex before calling into the SfxUndoAction - this can be a extension-implemented UNO component - // nowadays ... - aGuard.clear(); - if ( i_contextOrNull != NULL ) - pAction->RedoWithContext( *i_contextOrNull ); - else - pAction->Redo(); - aGuard.reset(); - } - catch( ... ) - { - aGuard.reset(); - - // in theory, somebody might have tampered with all of *m_pData while the mutex was unlocked. So, see if - // we still find pAction in our current Undo array - size_t nCurAction = 0; - while ( nCurAction < m_pData->pActUndoArray->aUndoActions.size() ) - { - if ( m_pData->pActUndoArray->aUndoActions[ nCurAction ].pAction == pAction ) - { - // the Undo action is still there ... - // assume the error is a permanent failure, and clear the Undo stack - ImplClearRedo( aGuard, IUndoManager::CurrentLevel ); - throw; - } - ++nCurAction; - } - OSL_ENSURE( false, "SfxUndoManager::Redo: can't clear the Undo stack after the failure - some other party was faster ..." ); - throw; - } - - aGuard.scheduleNotification( &SfxUndoListener::actionRedone, sActionComment ); - - return sal_True; -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::GetRepeatActionCount() const -{ - UndoManagerGuard aGuard( *m_pData ); - return m_pData->pActUndoArray->aUndoActions.size(); -} - -//------------------------------------------------------------------------ - -XubString SfxUndoManager::GetRepeatActionComment( SfxRepeatTarget &rTarget) const -{ - UndoManagerGuard aGuard( *m_pData ); - return m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->aUndoActions.size() - 1 ].pAction - ->GetRepeatComment(rTarget); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::Repeat( SfxRepeatTarget &rTarget ) -{ - UndoManagerGuard aGuard( *m_pData ); - if ( !m_pData->pActUndoArray->aUndoActions.empty() ) - { - SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->aUndoActions.size() - 1 ].pAction; - aGuard.clear(); - if ( pAction->CanRepeat( rTarget ) ) - pAction->Repeat( rTarget ); - return sal_True; - } - - return sal_False; -} - -//------------------------------------------------------------------------ - -sal_Bool SfxUndoManager::CanRepeat( SfxRepeatTarget &rTarget ) const -{ - UndoManagerGuard aGuard( *m_pData ); - if ( !m_pData->pActUndoArray->aUndoActions.empty() ) - { - size_t nActionNo = m_pData->pActUndoArray->aUndoActions.size() - 1; - return m_pData->pActUndoArray->aUndoActions[nActionNo].pAction->CanRepeat(rTarget); - } - return sal_False; -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::AddUndoListener( SfxUndoListener& i_listener ) -{ - UndoManagerGuard aGuard( *m_pData ); - m_pData->aListeners.push_back( &i_listener ); -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::RemoveUndoListener( SfxUndoListener& i_listener ) -{ - UndoManagerGuard aGuard( *m_pData ); - for ( UndoListeners::iterator lookup = m_pData->aListeners.begin(); - lookup != m_pData->aListeners.end(); - ++lookup - ) - { - if ( (*lookup) == &i_listener ) - { - m_pData->aListeners.erase( lookup ); - break; - } - } -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::EnterListAction( - const XubString& rComment, const XubString &rRepeatComment, sal_uInt16 nId ) - -/* [Beschreibung] - - Fuegt eine ListUndoAction ein und setzt dessen UndoArray als aktuelles. -*/ - -{ - UndoManagerGuard aGuard( *m_pData ); - - if( !ImplIsUndoEnabled_Lock() ) - return; - - if ( !m_pData->pUndoArray->nMaxUndoActions ) - return; - - m_pData->pFatherUndoArray = m_pData->pActUndoArray; - SfxListUndoAction* pAction = new SfxListUndoAction( rComment, rRepeatComment, nId, m_pData->pActUndoArray ); - OSL_VERIFY( ImplAddUndoAction_NoNotify( pAction, false, false, aGuard ) ); - // expected to succeed: all conditions under which it could fail should have been checked already - m_pData->pActUndoArray = pAction; - - // notification - aGuard.scheduleNotification( &SfxUndoListener::listActionEntered, rComment ); -} - -//------------------------------------------------------------------------ - -bool SfxUndoManager::IsInListAction() const -{ - UndoManagerGuard aGuard( *m_pData ); - return ImplIsInListAction_Lock(); -} - -//------------------------------------------------------------------------ - -bool SfxUndoManager::ImplIsInListAction_Lock() const -{ - return ( m_pData->pActUndoArray != m_pData->pUndoArray ); -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::GetListActionDepth() const -{ - UndoManagerGuard aGuard( *m_pData ); - size_t nDepth(0); - - SfxUndoArray* pLookup( m_pData->pActUndoArray ); - while ( pLookup != m_pData->pUndoArray ) - { - pLookup = pLookup->pFatherUndoArray; - ++nDepth; - } - - return nDepth; -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::LeaveListAction() -{ - UndoManagerGuard aGuard( *m_pData ); - size_t nCount = ImplLeaveListAction( false, aGuard ); - - if ( m_pData->mbClearUntilTopLevel ) - { - ImplClearCurrentLevel_NoNotify( aGuard ); - if ( !ImplIsInListAction_Lock() ) - { - m_pData->mbClearUntilTopLevel = false; - aGuard.scheduleNotification( &SfxUndoListener::cleared ); - } - nCount = 0; - } - - return nCount; -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::LeaveAndMergeListAction() -{ - UndoManagerGuard aGuard( *m_pData ); - return ImplLeaveListAction( true, aGuard ); -} - -//------------------------------------------------------------------------ - -size_t SfxUndoManager::ImplLeaveListAction( const bool i_merge, UndoManagerGuard& i_guard ) -{ - if ( !ImplIsUndoEnabled_Lock() ) - return 0; - - if ( !m_pData->pUndoArray->nMaxUndoActions ) - return 0; - - if( !ImplIsInListAction_Lock() ) - { - OSL_TRACE( "svl::SfxUndoManager::ImplLeaveListAction, called without calling EnterListAction()!" ); - return 0; - } - - DBG_ASSERT( m_pData->pActUndoArray->pFatherUndoArray, "SfxUndoManager::ImplLeaveListAction, no father undo array!?" ); - - // the array/level which we're about to leave - SfxUndoArray* pArrayToLeave = m_pData->pActUndoArray; - // one step up - m_pData->pActUndoArray = m_pData->pActUndoArray->pFatherUndoArray; - - // If no undo actions were added to the list, delete the list action - const size_t nListActionElements = pArrayToLeave->nCurUndoAction; - if ( nListActionElements == 0 ) - { - SfxUndoAction* pCurrentAction= m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction-1 ].pAction; - m_pData->pActUndoArray->aUndoActions.Remove( --m_pData->pActUndoArray->nCurUndoAction ); - i_guard.markForDeletion( pCurrentAction ); - - i_guard.scheduleNotification( &SfxUndoListener::listActionCancelled ); - return 0; - } - - // now that it is finally clear the list action is non-trivial, and does participate in the Undo stack, clear - // the redo stack - ImplClearRedo( i_guard, IUndoManager::CurrentLevel ); - - SfxUndoAction* pCurrentAction= m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction-1 ].pAction; - SfxListUndoAction* pListAction = dynamic_cast< SfxListUndoAction * >( pCurrentAction ); - ENSURE_OR_RETURN( pListAction, "SfxUndoManager::ImplLeaveListAction: list action expected at this position!", nListActionElements ); - - if ( i_merge ) - { - // merge the list action with its predecessor on the same level - OSL_ENSURE( m_pData->pActUndoArray->nCurUndoAction > 1, - "SfxUndoManager::ImplLeaveListAction: cannot merge the list action if there's no other action on the same level - check this beforehand!" ); - if ( m_pData->pActUndoArray->nCurUndoAction > 1 ) - { - SfxUndoAction* pPreviousAction = m_pData->pActUndoArray->aUndoActions[ m_pData->pActUndoArray->nCurUndoAction - 2 ].pAction; - m_pData->pActUndoArray->aUndoActions.Remove( m_pData->pActUndoArray->nCurUndoAction - 2 ); - --m_pData->pActUndoArray->nCurUndoAction; - pListAction->aUndoActions.Insert( pPreviousAction, 0 ); - ++pListAction->nCurUndoAction; - - pListAction->SetComment( pPreviousAction->GetComment() ); - } - } - - // if the undo array has no comment, try to get it from its children - if ( pListAction->GetComment().Len() == 0 ) - { - for( size_t n = 0; n < pListAction->aUndoActions.size(); n++ ) - { - if( pListAction->aUndoActions[n].pAction->GetComment().Len() ) - { - pListAction->SetComment( pListAction->aUndoActions[n].pAction->GetComment() ); - break; - } - } - } - - // notify listeners - i_guard.scheduleNotification( &SfxUndoListener::listActionLeft, pListAction->GetComment() ); - - // outta here - return nListActionElements; -} - -//------------------------------------------------------------------------ -UndoStackMark SfxUndoManager::MarkTopUndoAction() -{ - UndoManagerGuard aGuard( *m_pData ); - - OSL_ENSURE( !IsInListAction(), - "SfxUndoManager::MarkTopUndoAction(): suspicious call!" ); - OSL_ENSURE((m_pData->mnMarks + 1) < (m_pData->mnEmptyMark - 1), - "SfxUndoManager::MarkTopUndoAction(): mark overflow!"); - - size_t const nActionPos = m_pData->pUndoArray->nCurUndoAction; - if (0 == nActionPos) - { - --m_pData->mnEmptyMark; - return m_pData->mnEmptyMark; - } - - m_pData->pUndoArray->aUndoActions[ nActionPos-1 ].aMarks.push_back( - ++m_pData->mnMarks ); - return m_pData->mnMarks; -} - -//------------------------------------------------------------------------ -void SfxUndoManager::RemoveMark( UndoStackMark const i_mark ) -{ - UndoManagerGuard aGuard( *m_pData ); - - if ((m_pData->mnEmptyMark < i_mark) || (MARK_INVALID == i_mark)) - { - return; // nothing to remove - } - else if (i_mark == m_pData->mnEmptyMark) - { - --m_pData->mnEmptyMark; // never returned from MarkTop => invalid - return; - } - - for ( size_t i=0; i<m_pData->pUndoArray->aUndoActions.size(); ++i ) - { - MarkedUndoAction& rAction = m_pData->pUndoArray->aUndoActions[i]; - for ( ::std::vector< UndoStackMark >::iterator markPos = rAction.aMarks.begin(); - markPos != rAction.aMarks.end(); - ++markPos - ) - { - if ( *markPos == i_mark ) - { - rAction.aMarks.erase( markPos ); - return; - } - } - } - OSL_ENSURE( false, "SfxUndoManager::RemoveMark: mark not found!" ); - // TODO: this might be too offensive. There are situations where we implicitly remove marks - // without our clients, in particular the client which created the mark, having a chance to know - // about this. -} - -//------------------------------------------------------------------------ -bool SfxUndoManager::HasTopUndoActionMark( UndoStackMark const i_mark ) -{ - UndoManagerGuard aGuard( *m_pData ); - - size_t nActionPos = m_pData->pUndoArray->nCurUndoAction; - if ( nActionPos == 0 ) - { - return (i_mark == m_pData->mnEmptyMark); - } - - const MarkedUndoAction& rAction = - m_pData->pUndoArray->aUndoActions[ nActionPos-1 ]; - for ( ::std::vector< UndoStackMark >::const_iterator markPos = rAction.aMarks.begin(); - markPos != rAction.aMarks.end(); - ++markPos - ) - { - if ( *markPos == i_mark ) - return true; - } - - return false; -} - -//------------------------------------------------------------------------ - -void SfxUndoManager::RemoveOldestUndoActions( size_t const i_count ) -{ - UndoManagerGuard aGuard( *m_pData ); - - size_t nActionsToRemove = i_count; - while ( nActionsToRemove ) - { - SfxUndoAction* pActionToRemove = m_pData->pUndoArray->aUndoActions[0].pAction; - - if ( IsInListAction() && ( m_pData->pUndoArray->nCurUndoAction == 1 ) ) - { - OSL_ENSURE( false, "SfxUndoManager::RemoveOldestUndoActions: cannot remove a not-yet-closed list action!" ); - return; - } - - aGuard.markForDeletion( pActionToRemove ); - m_pData->pUndoArray->aUndoActions.Remove( 0 ); - --m_pData->pUndoArray->nCurUndoAction; - --nActionsToRemove; - } -} - -//------------------------------------------------------------------------ - -sal_uInt16 SfxListUndoAction::GetId() const -{ - return nId; -} - -//------------------------------------------------------------------------ - -XubString SfxListUndoAction::GetComment() const -{ - return aComment; -} - -//------------------------------------------------------------------------ - -void SfxListUndoAction::SetComment( const UniString& rComment ) -{ - aComment = rComment; -} - -//------------------------------------------------------------------------ - -XubString SfxListUndoAction::GetRepeatComment(SfxRepeatTarget &) const -{ - return aRepeatComment; -} - - -//------------------------------------------------------------------------ - -SfxListUndoAction::SfxListUndoAction -( - const XubString &rComment, - const XubString rRepeatComment, - sal_uInt16 Id, - SfxUndoArray *pFather -) -: nId(Id), aComment(rComment), aRepeatComment(rRepeatComment) -{ - pFatherUndoArray = pFather; - nMaxUndoActions = USHRT_MAX; -} - -//------------------------------------------------------------------------ - -void SfxListUndoAction::Undo() -{ - for(size_t i=nCurUndoAction;i>0;) - aUndoActions[--i].pAction->Undo(); - nCurUndoAction=0; -} - -//------------------------------------------------------------------------ - -void SfxListUndoAction::UndoWithContext( SfxUndoContext& i_context ) -{ - for(size_t i=nCurUndoAction;i>0;) - aUndoActions[--i].pAction->UndoWithContext( i_context ); - nCurUndoAction=0; -} - -//------------------------------------------------------------------------ - -void SfxListUndoAction::Redo() -{ - for(size_t i=nCurUndoAction;i<aUndoActions.size();i++) - aUndoActions[i].pAction->Redo(); - nCurUndoAction = aUndoActions.size(); -} - -//------------------------------------------------------------------------ - -void SfxListUndoAction::RedoWithContext( SfxUndoContext& i_context ) -{ - for(size_t i=nCurUndoAction;i<aUndoActions.size();i++) - aUndoActions[i].pAction->RedoWithContext( i_context ); - nCurUndoAction = aUndoActions.size(); -} - -//------------------------------------------------------------------------ - -void SfxListUndoAction::Repeat(SfxRepeatTarget&rTarget) -{ - for(size_t i=0;i<nCurUndoAction;i++) - aUndoActions[i].pAction->Repeat(rTarget); -} - -//------------------------------------------------------------------------ - -sal_Bool SfxListUndoAction::CanRepeat(SfxRepeatTarget&r) const -{ - for(size_t i=0;i<nCurUndoAction;i++) - if(!aUndoActions[i].pAction->CanRepeat(r)) - return sal_False; - return sal_True; -} - -//------------------------------------------------------------------------ - -sal_Bool SfxListUndoAction::Merge( SfxUndoAction *pNextAction ) -{ - return !aUndoActions.empty() && aUndoActions[aUndoActions.size()-1].pAction->Merge( pNextAction ); -} - -//------------------------------------------------------------------------ - -SfxLinkUndoAction::SfxLinkUndoAction(::svl::IUndoManager *pManager) -/* [Beschreibung] - - Richtet eine LinkAction ein, die auf einen weiteren UndoManager zeigt. - Holt sich als zugehoerige Action des weiteren UndoManagers dessen - aktuelle Action. -*/ - -{ - pUndoManager = pManager; - SfxUndoManager* pUndoManagerImplementation = dynamic_cast< SfxUndoManager* >( pManager ); - ENSURE_OR_THROW( pUndoManagerImplementation != NULL, "unsupported undo manager implementation!" ); - // yes, this cast is dirty. But reaching into the the SfxUndoManager's implementation, - // directly accessing its internal stack, and tampering with an action on that stack - // is dirty, too. - if ( pManager->GetMaxUndoActionCount() ) - { - size_t nPos = pManager->GetUndoActionCount()-1; - pAction = pUndoManagerImplementation->m_pData->pActUndoArray->aUndoActions[nPos].pAction; - pAction->SetLinked(); - } - else - pAction = 0; -} - -//------------------------------------------------------------------------ - -void SfxLinkUndoAction::Undo() -{ - if ( pAction ) - pUndoManager->Undo(); -} - -//------------------------------------------------------------------------ - -void SfxLinkUndoAction::Redo() -{ - if ( pAction ) - pUndoManager->Redo(); -} - -//------------------------------------------------------------------------ - - -sal_Bool SfxLinkUndoAction::CanRepeat(SfxRepeatTarget& r) const -{ - return pAction && pAction->CanRepeat(r); -} - - -//------------------------------------------------------------------------ - - -void SfxLinkUndoAction::Repeat(SfxRepeatTarget&r) -{ - if ( pAction && pAction->CanRepeat( r ) ) - pAction->Repeat( r ); -} - - -//------------------------------------------------------------------------ - -XubString SfxLinkUndoAction::GetComment() const -{ - if ( pAction ) - return pAction->GetComment(); - else - return XubString(); -} - - -//------------------------------------------------------------------------ - -XubString SfxLinkUndoAction::GetRepeatComment(SfxRepeatTarget&r) const -{ - if ( pAction ) - return pAction->GetRepeatComment(r); - else - return XubString(); -} - -//------------------------------------------------------------------------ - -SfxLinkUndoAction::~SfxLinkUndoAction() -{ - if( pAction ) - pAction->SetLinked( sal_False ); -} - - -//------------------------------------------------------------------------ - -SfxUndoArray::~SfxUndoArray() -{ - while ( !aUndoActions.empty() ) - { - SfxUndoAction *pAction = aUndoActions[ aUndoActions.size() - 1 ].pAction; - aUndoActions.Remove( aUndoActions.size() - 1 ); - delete pAction; - } -} - - -sal_uInt16 SfxLinkUndoAction::GetId() const -{ - return pAction ? pAction->GetId() : 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/uno/pathservice.cxx b/svl/source/uno/pathservice.cxx deleted file mode 100644 index 458347e717..0000000000 --- a/svl/source/uno/pathservice.cxx +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" - -#include <unotools/pathoptions.hxx> -#include "sal/types.h" -#include "rtl/ustring.hxx" -#include <cppuhelper/implbase2.hxx> -#include <com/sun/star/frame/XConfigManager.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> - -namespace css = com::sun::star; -using rtl::OUString; - -// ----------------------------------------------------------------------- - -class PathService : public ::cppu::WeakImplHelper2< css::frame::XConfigManager, css::lang::XServiceInfo > -{ - SvtPathOptions m_aOptions; - -public: - PathService() - {} - - virtual OUString SAL_CALL getImplementationName() - throw(css::uno::RuntimeException) - { - return OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.svl.PathService")); - } - - virtual sal_Bool SAL_CALL supportsService ( - const OUString & rName) - throw(css::uno::RuntimeException) - { - return (rName.compareToAscii("com.sun.star.config.SpecialConfigManager") == 0); - } - - virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() - throw(css::uno::RuntimeException) - { - css::uno::Sequence< OUString > aRet(1); - aRet.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.config.SpecialConfigManager")); - return aRet; - } - - virtual OUString SAL_CALL substituteVariables ( - const OUString& sText) - throw(css::uno::RuntimeException) - { - return m_aOptions.SubstituteVariable( sText ); - } - - virtual void SAL_CALL addPropertyChangeListener ( - const OUString &, const css::uno::Reference< css::beans::XPropertyChangeListener > &) - throw(css::uno::RuntimeException) - {} - - virtual void SAL_CALL removePropertyChangeListener ( - const OUString &, const css::uno::Reference< css::beans::XPropertyChangeListener > &) - throw(css::uno::RuntimeException) - {} - - virtual void SAL_CALL flush() - throw(css::uno::RuntimeException) - {} -}; - -// ----------------------------------------------------------------------- - -css::uno::Reference< css::uno::XInterface > PathService_CreateInstance ( - const css::uno::Reference< css::lang::XMultiServiceFactory > &) -{ - return css::uno::Reference< css::uno::XInterface >( - static_cast< cppu::OWeakObject* >(new PathService())); -} - -// ----------------------------------------------------------------------- - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/uno/registerservices.cxx b/svl/source/uno/registerservices.cxx deleted file mode 100644 index 6dfbf1b4e4..0000000000 --- a/svl/source/uno/registerservices.cxx +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/************************************************************************* - * - * 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_svl.hxx" -#include "sal/types.h" -#include "rtl/ustring.hxx" -#include <cppuhelper/factory.hxx> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/registry/XRegistryKey.hpp> -#include <svl/svldllapi.h> - -namespace css = com::sun::star; -using css::uno::Reference; -using css::uno::Sequence; -using rtl::OUString; - -// ------------------------------------------------------------------------------------- - -#define DECLARE_CREATEINSTANCE( ImplName ) \ - Reference< css::uno::XInterface > SAL_CALL ImplName##_CreateInstance( const Reference< css::lang::XMultiServiceFactory >& ); - -DECLARE_CREATEINSTANCE( SvNumberFormatterServiceObj ) -DECLARE_CREATEINSTANCE( SvNumberFormatsSupplierServiceObject ) -DECLARE_CREATEINSTANCE( PathService ) - -// ------------------------------------------------------------------------------------- - -extern "C" -{ - -SVL_DLLPUBLIC void* SAL_CALL svl_component_getFactory ( - const sal_Char * pImplementationName, void * _pServiceManager, void * /* _pRegistryKey*/) -{ - void * pResult = 0; - if ( _pServiceManager ) - { - Reference< css::lang::XSingleServiceFactory > xFactory; - if (rtl_str_compare( - pImplementationName, - "com.sun.star.uno.util.numbers.SvNumberFormatsSupplierServiceObject") == 0) - { - Sequence< OUString > aServiceNames(1); - aServiceNames.getArray()[0] = - OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatsSupplier")); - - xFactory = ::cppu::createSingleFactory( - reinterpret_cast< css::lang::XMultiServiceFactory* >(_pServiceManager), - OUString::createFromAscii( pImplementationName ), - SvNumberFormatsSupplierServiceObject_CreateInstance, - aServiceNames); - } - else if (rtl_str_compare( - pImplementationName, - "com.sun.star.uno.util.numbers.SvNumberFormatterServiceObject") == 0) - { - Sequence< OUString > aServiceNames(1); - aServiceNames.getArray()[0] = - OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.NumberFormatter")); - - xFactory = ::cppu::createSingleFactory( - reinterpret_cast< css::lang::XMultiServiceFactory* >(_pServiceManager), - OUString::createFromAscii( pImplementationName ), - SvNumberFormatterServiceObj_CreateInstance, - aServiceNames); - } - else if (rtl_str_compare ( - pImplementationName, "com.sun.star.comp.svl.PathService") == 0) - { - Sequence< OUString > aServiceNames(1); - aServiceNames.getArray()[0] = - OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.config.SpecialConfigManager")); - xFactory = ::cppu::createSingleFactory ( - reinterpret_cast< css::lang::XMultiServiceFactory* >( _pServiceManager ), - OUString::createFromAscii( pImplementationName ), - PathService_CreateInstance, - aServiceNames); - } - if ( xFactory.is() ) - { - xFactory->acquire(); - pResult = xFactory.get(); - } - } - return pResult; -} - -} // "C" - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |