diff options
Diffstat (limited to 'bf_sc/source/ui/unoobj')
30 files changed, 29537 insertions, 0 deletions
diff --git a/bf_sc/source/ui/unoobj/makefile.mk b/bf_sc/source/ui/unoobj/makefile.mk new file mode 100644 index 000000000..96b97983c --- /dev/null +++ b/bf_sc/source/ui/unoobj/makefile.mk @@ -0,0 +1,70 @@ +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +PRJ=..$/..$/..$/.. +BFPRJ=..$/..$/.. + +PRJNAME=binfilter +TARGET=sc_unoobj + +NO_HIDS=TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(BFPRJ)$/util$/makefile.pmk +INC+= -I$(PRJ)$/inc$/bf_sc +# --- Files -------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/sc_docuno.obj \ + $(SLO)$/sc_servuno.obj \ + $(SLO)$/sc_defltuno.obj \ + $(SLO)$/sc_drdefuno.obj \ + $(SLO)$/sc_cellsuno.obj \ + $(SLO)$/sc_textuno.obj \ + $(SLO)$/sc_notesuno.obj \ + $(SLO)$/sc_cursuno.obj \ + $(SLO)$/sc_fielduno.obj \ + $(SLO)$/sc_miscuno.obj \ + $(SLO)$/sc_optuno.obj \ + $(SLO)$/sc_appluno.obj \ + $(SLO)$/sc_funcuno.obj \ + $(SLO)$/sc_nameuno.obj \ + $(SLO)$/sc_datauno.obj \ + $(SLO)$/sc_dapiuno.obj \ + $(SLO)$/sc_chartuno.obj \ + $(SLO)$/sc_shapeuno.obj \ + $(SLO)$/sc_pageuno.obj \ + $(SLO)$/sc_forbiuno.obj \ + $(SLO)$/sc_styleuno.obj \ + $(SLO)$/sc_afmtuno.obj \ + $(SLO)$/sc_fmtuno.obj \ + $(SLO)$/sc_linkuno.obj \ + $(SLO)$/sc_convuno.obj \ + $(SLO)$/sc_editsrc.obj \ + $(SLO)$/sc_confuno.obj \ + $(SLO)$/sc_filtuno.obj \ + $(SLO)$/sc_unodoc.obj + +# --- Tagets ------------------------------------------------------- + +.INCLUDE : target.mk + diff --git a/bf_sc/source/ui/unoobj/sc_afmtuno.cxx b/bf_sc/source/ui/unoobj/sc_afmtuno.cxx new file mode 100644 index 000000000..5811f7451 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_afmtuno.cxx @@ -0,0 +1,822 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include "unowids.hxx" + +#include <rtl/uuid.h> + +#include <com/sun/star/table/CellVertJustify.hpp> +#include <com/sun/star/table/CellHoriJustify.hpp> +#include <com/sun/star/table/CellOrientation.hpp> +#include <com/sun/star/awt/XFont.hpp> + +#include "afmtuno.hxx" +#include "miscuno.hxx" +#include "autoform.hxx" +#include <vcl/svapp.hxx> +#include "scdll.hxx" +#include "unonames.hxx" +#include "cellsuno.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +// ein AutoFormat hat immer 16 Eintraege +#define SC_AF_FIELD_COUNT 16 + +//------------------------------------------------------------------------ + +// AutoFormat-Map nur fuer PropertySetInfo, ohne Which-IDs + +const SfxItemPropertyMap* lcl_GetAutoFormatMap() +{ + static SfxItemPropertyMap aAutoFormatMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_INCBACK), 0, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_INCBORD), 0, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_INCFONT), 0, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_INCJUST), 0, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_INCNUM), 0, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_INCWIDTH), 0, &::getBooleanCppuType(), 0, 0 }, + {0,0,0,0,0,0} + }; + return aAutoFormatMap_Impl; +} + +//! Zahlformat (String/Language) ??? (in XNumberFormat nur ReadOnly) +//! table::TableBorder ??!? + +const SfxItemPropertyMap* lcl_GetAutoFieldMap() +{ + static SfxItemPropertyMap aAutoFieldMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT, &::getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &::getCppuType((const sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &::getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &::getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &::getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &::getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &::getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &::getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &::getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &::getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT, &::getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT, &::getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &::getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE, &::getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE, &::getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &::getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE, &::getCppuType((const sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &::getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT, &::getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT, &::getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &::getCppuType((const table::CellHoriJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &::getCppuType((const table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &::getCppuType((const table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &::getCppuType((const table::CellVertJustify*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aAutoFieldMap_Impl; +} + +//------------------------------------------------------------------------ + +#define SCAUTOFORMATSOBJ_SERVICE "com.sun.star.sheet.TableAutoFormats" + +SC_SIMPLE_SERVICE_INFO( ScAutoFormatFieldObj, "ScAutoFormatFieldObj", "com.sun.star.sheet.TableAutoFormatField" ) +SC_SIMPLE_SERVICE_INFO( ScAutoFormatObj, "ScAutoFormatObj", "com.sun.star.sheet.TableAutoFormat" ) +SC_SIMPLE_SERVICE_INFO( ScAutoFormatsObj, "ScAutoFormatsObj", SCAUTOFORMATSOBJ_SERVICE ) + +//------------------------------------------------------------------------ + +sal_Bool lcl_FindAutoFormatIndex( const ScAutoFormat& rFormats, const String& rName, sal_uInt16& rOutIndex ) +{ + String aEntryName; + sal_uInt16 nCount = rFormats.GetCount(); + for( sal_uInt16 nPos=0; nPos<nCount; nPos++ ) + { + ScAutoFormatData* pEntry = rFormats[nPos]; + pEntry->GetName( aEntryName ); + if ( aEntryName == rName ) + { + rOutIndex = nPos; + return sal_True; + } + } + return sal_False; // is nich +} + +//------------------------------------------------------------------------ + +ScAutoFormatsObj::ScAutoFormatsObj() +{ + //! Dieses Objekt darf es nur einmal geben, und es muss an den Auto-Format-Daten + //! bekannt sein, damit Aenderungen gebroadcasted werden koennen +} + +ScAutoFormatsObj::~ScAutoFormatsObj() +{ +} + +// stuff for exService_... + +uno::Reference<uno::XInterface> SAL_CALL ScAutoFormatsObj_CreateInstance( + const uno::Reference<lang::XMultiServiceFactory>& ) +{ + SolarMutexGuard aGuard; + SC_DLL()->Load(); // load module + static uno::Reference< uno::XInterface > xInst = (::cppu::OWeakObject*) new ScAutoFormatsObj; + return xInst; +} + +::rtl::OUString ScAutoFormatsObj::getImplementationName_Static() +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "stardiv.StarCalc.ScAutoFormatsObj" )); +} + +uno::Sequence< ::rtl::OUString> ScAutoFormatsObj::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCAUTOFORMATSOBJ_SERVICE )); + return aRet; +} + +// XTableAutoFormats + +ScAutoFormatObj* ScAutoFormatsObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) +{ + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats && nIndex < pFormats->GetCount()) + return new ScAutoFormatObj(nIndex); + + return NULL; // falscher Index +} + +ScAutoFormatObj* ScAutoFormatsObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats) + { + String aString = aName; + sal_uInt16 nIndex; + if (lcl_FindAutoFormatIndex( *pFormats, aString, nIndex )) + return GetObjectByIndex_Impl(nIndex); + } + return NULL; +} + +// container::XNameContainer + +void SAL_CALL ScAutoFormatsObj::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::ElementExistException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + sal_Bool bDone = sal_False; + // Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein... + uno::Reference< uno::XInterface > xInterface; + if ( aElement >>= xInterface ) + { + ScAutoFormatObj* pFormatObj = ScAutoFormatObj::getImplementation( xInterface ); + if ( pFormatObj && !pFormatObj->IsInserted() ) // noch nicht eingefuegt? + { + String aNameStr = aName; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + + sal_uInt16 nDummy; + if (pFormats && !lcl_FindAutoFormatIndex( *pFormats, aNameStr, nDummy )) + { + ScAutoFormatData* pNew = new ScAutoFormatData(); + pNew->SetName( aNameStr ); + + if (pFormats->Insert( pNew )) + { + //! Notify fuer andere Objekte + pFormats->Save(); // sofort speichern + + sal_uInt16 nNewIndex; + if (lcl_FindAutoFormatIndex( *pFormats, aNameStr, nNewIndex )) + { + pFormatObj->InitFormat( nNewIndex ); // kann jetzt benutzt werden + bDone = sal_True; + } + } + else + { + delete pNew; + OSL_FAIL("AutoFormat konnte nicht eingefuegt werden"); + throw uno::RuntimeException(); + } + } + else + { + throw container::ElementExistException(); + } + } + } + + if (!bDone) + { + // other errors are handled above + throw lang::IllegalArgumentException(); + } +} + +void SAL_CALL ScAutoFormatsObj::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! zusammenfassen? + removeByName( aName ); + insertByName( aName, aElement ); +} + +void SAL_CALL ScAutoFormatsObj::removeByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr = aName; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + + sal_uInt16 nIndex; + if (pFormats && lcl_FindAutoFormatIndex( *pFormats, aNameStr, nIndex )) + { + pFormats->AtFree( nIndex ); + + //! Notify fuer andere Objekte + pFormats->Save(); // sofort speichern + } + else + { + throw container::NoSuchElementException(); + } +} + +// container::XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration"))); +} + +// container::XIndexAccess + +sal_Int32 SAL_CALL ScAutoFormatsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats) + return pFormats->GetCount(); + + return 0; +} + +uno::Any SAL_CALL ScAutoFormatsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< container::XNamed > xFormat = GetObjectByIndex_Impl((sal_uInt16)nIndex); + uno::Any aAny; + if (xFormat.is()) + aAny <<= xFormat; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScAutoFormatsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ::getCppuType((const uno::Reference< container::XNamed >*)0); // muss zu getByIndex passen +} + +sal_Bool SAL_CALL ScAutoFormatsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// container::XNameAccess + +uno::Any SAL_CALL ScAutoFormatsObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< container::XNamed > xFormat = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xFormat.is()) + aAny <<= xFormat; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScAutoFormatsObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats) + { + String aName; + sal_uInt16 nCount = pFormats->GetCount(); + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (sal_uInt16 i=0; i<nCount; i++) + { + (*pFormats)[i]->GetName(aName); + pAry[i] = aName; + } + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(0); +} + +sal_Bool SAL_CALL ScAutoFormatsObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats) + { + String aString = aName; + sal_uInt16 nDummy; + return lcl_FindAutoFormatIndex( *pFormats, aString, nDummy ); + } + return sal_False; +} + +//------------------------------------------------------------------------ + +ScAutoFormatObj::ScAutoFormatObj(sal_uInt16 nIndex) : + aPropSet( lcl_GetAutoFormatMap() ), + nFormatIndex( nIndex ) +{ + //! Listening !!! +} + +ScAutoFormatObj::~ScAutoFormatObj() +{ + // Wenn ein AutoFormat-Objekt losgelassen wird, werden eventuelle Aenderungen + // gespeichert, damit sie z.B. im Writer sichtbar sind + + if (IsInserted()) + { + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if ( pFormats && pFormats->IsSaveLater() ) + pFormats->Save(); + + // Save() setzt SaveLater Flag zurueck + } +} + +void ScAutoFormatObj::InitFormat( sal_uInt16 nNewIndex ) +{ + DBG_ASSERT( nFormatIndex == SC_AFMTOBJ_INVALID, "ScAutoFormatObj::InitFormat mehrfach" ); + nFormatIndex = nNewIndex; + //! Listening !!! +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScAutoFormatObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScAutoFormatObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScAutoFormatObj* ScAutoFormatObj::getImplementation( + const uno::Reference<uno::XInterface> xObj ) +{ + ScAutoFormatObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScAutoFormatObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +void ScAutoFormatObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& /*rHint*/ ) +{ + // spaeter... +} + +// XTableAutoFormat + +ScAutoFormatFieldObj* ScAutoFormatObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) +{ + if ( IsInserted() && nIndex < SC_AF_FIELD_COUNT ) + return new ScAutoFormatFieldObj( nFormatIndex, nIndex ); + + return NULL; +} + +// container::XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScAutoFormatObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableAutoFormatEnumeration"))); +} + +// container::XIndexAccess + +sal_Int32 SAL_CALL ScAutoFormatObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (IsInserted()) + return SC_AF_FIELD_COUNT; // immer 16 Elemente + else + return 0; +} + +uno::Any SAL_CALL ScAutoFormatObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( nIndex < 0 || nIndex >= getCount() ) + throw lang::IndexOutOfBoundsException(); + + uno::Any aAny; + if (IsInserted()) + { + uno::Reference< beans::XPropertySet > xField = GetObjectByIndex_Impl((sal_uInt16)nIndex); + aAny <<= xField; + } + return aAny; +} + +uno::Type SAL_CALL ScAutoFormatObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ::getCppuType((const uno::Reference< beans::XPropertySet >*)0); // muss zu getByIndex passen +} + +sal_Bool SAL_CALL ScAutoFormatObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// container::XNamed + +::rtl::OUString SAL_CALL ScAutoFormatObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount()) + { + String aName; + (*pFormats)[nFormatIndex]->GetName(aName); + return aName; + } + return ::rtl::OUString(); +} + +void SAL_CALL ScAutoFormatObj::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNewString = aNewName; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + + sal_uInt16 nDummy; + if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount() && + !lcl_FindAutoFormatIndex( *pFormats, aNewString, nDummy )) + { + ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; + DBG_ASSERT(pData,"AutoFormat Daten nicht da"); + + ScAutoFormatData* pNew = new ScAutoFormatData(*pData); + pNew->SetName( aNewString ); + + pFormats->AtFree( nFormatIndex ); + if (pFormats->Insert( pNew )) + { + nFormatIndex = pFormats->IndexOf( pNew ); // ist evtl. anders einsortiert... + + //! Notify fuer andere Objekte + pFormats->SetSaveLater(sal_True); + } + else + { + delete pNew; + OSL_FAIL("AutoFormat konnte nicht eingefuegt werden"); + nFormatIndex = 0; //! alter Index ist ungueltig + } + } + else + { + // not inserted or name exists + throw uno::RuntimeException(); + } +} + +// beans::XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference< beans::XPropertySetInfo > aRef = new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScAutoFormatObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount()) + { + ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; + DBG_ASSERT(pData,"AutoFormat Daten nicht da"); + + String aPropString = aPropertyName; + sal_Bool bBool = sal_False; + if (aPropString.EqualsAscii( SC_UNONAME_INCBACK ) && (aValue >>= bBool)) + pData->SetIncludeBackground( bBool ); + else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD ) && (aValue >>= bBool)) + pData->SetIncludeFrame( bBool ); + else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT ) && (aValue >>= bBool)) + pData->SetIncludeFont( bBool ); + else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST ) && (aValue >>= bBool)) + pData->SetIncludeJustify( bBool ); + else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM ) && (aValue >>= bBool)) + pData->SetIncludeValueFormat( bBool ); + else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH ) && (aValue >>= bBool)) + pData->SetIncludeWidthHeight( bBool ); + + // else Fehler + + //! Notify fuer andere Objekte + pFormats->SetSaveLater(sal_True); + } +} + +uno::Any SAL_CALL ScAutoFormatObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aAny; + + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + if (pFormats && IsInserted() && nFormatIndex < pFormats->GetCount()) + { + ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; + DBG_ASSERT(pData,"AutoFormat Daten nicht da"); + + sal_Bool bValue; + sal_Bool bError = sal_False; + + String aPropString = aPropertyName; + if (aPropString.EqualsAscii( SC_UNONAME_INCBACK )) + bValue = pData->GetIncludeBackground(); + else if (aPropString.EqualsAscii( SC_UNONAME_INCBORD )) + bValue = pData->GetIncludeFrame(); + else if (aPropString.EqualsAscii( SC_UNONAME_INCFONT )) + bValue = pData->GetIncludeFont(); + else if (aPropString.EqualsAscii( SC_UNONAME_INCJUST )) + bValue = pData->GetIncludeJustify(); + else if (aPropString.EqualsAscii( SC_UNONAME_INCNUM )) + bValue = pData->GetIncludeValueFormat(); + else if (aPropString.EqualsAscii( SC_UNONAME_INCWIDTH )) + bValue = pData->GetIncludeWidthHeight(); + else + bError = sal_True; // unbekannte Property + + if (!bError) + aAny <<= bValue; + } + + return aAny; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatObj ) + + +ScAutoFormatFieldObj::ScAutoFormatFieldObj(sal_uInt16 nFormat, sal_uInt16 nField) : + aPropSet( lcl_GetAutoFieldMap() ), + nFormatIndex( nFormat ), + nFieldIndex( nField ) +{ + //! Listening !!! +} + +ScAutoFormatFieldObj::~ScAutoFormatFieldObj() +{ +} + +void ScAutoFormatFieldObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& /*rHint*/ ) +{ + // spaeter... +} + +// beans::XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAutoFormatFieldObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference< beans::XPropertySetInfo > aRef = new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScAutoFormatFieldObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + String aPropString = aPropertyName; + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetAutoFieldMap(), aPropString ); + + if ( pMap && pMap->nWID && pFormats && nFormatIndex < pFormats->GetCount() ) + { + ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; + + if ( IsScItemWid( pMap->nWID ) ) + { + const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pMap->nWID ); + if (pItem) + { + SfxPoolItem* pNewItem = pItem->Clone(); + sal_Bool bDone = pNewItem->PutValue( aValue, pMap->nMemberId ); + if (bDone) + { + pData->PutItem( nFieldIndex, *pNewItem ); + + //! Notify fuer andere Objekte? + pFormats->SetSaveLater(sal_True); + } + delete pNewItem; + } + } + else + { + switch (pMap->nWID) + { + case SC_WID_UNO_TBLBORD: + { + table::TableBorder aBorder; + if ( aValue >>= aBorder ) // empty = nothing to do + { + SvxBoxItem aOuter(ATTR_BORDER); + SvxBoxInfoItem aInner(ATTR_BORDER_INNER); + ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder ); + pData->PutItem( nFieldIndex, aOuter ); + + //! Notify fuer andere Objekte? + pFormats->SetSaveLater(sal_True); + } + } + break; + } + } + } +} + +uno::Any SAL_CALL ScAutoFormatFieldObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aVal; + + ScAutoFormat* pFormats = ScGlobal::GetAutoFormat(); + String aPropString = aPropertyName; + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetAutoFieldMap(), aPropString ); + + if ( pMap && pMap->nWID && pFormats && nFormatIndex < pFormats->GetCount() ) + { + const ScAutoFormatData* pData = (*pFormats)[nFormatIndex]; + + if ( IsScItemWid( pMap->nWID ) ) + { + const SfxPoolItem* pItem = pData->GetItem( nFieldIndex, pMap->nWID ); + if (pItem) + pItem->QueryValue( aVal, pMap->nMemberId ); + } + else + { + switch (pMap->nWID) + { + case SC_WID_UNO_TBLBORD: + { + const SfxPoolItem* pItem = pData->GetItem(nFieldIndex, ATTR_BORDER); + if (pItem) + { + SvxBoxItem aOuter(*(static_cast<const SvxBoxItem*>(pItem))); + SvxBoxInfoItem aInner(ATTR_BORDER_INNER); + + table::TableBorder aBorder; + ScHelperFunctions::FillTableBorder( aBorder, aOuter, aInner ); + aVal <<= aBorder; + } + } + break; + } + } + } + + return aVal; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAutoFormatFieldObj ) + + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_appluno.cxx b/bf_sc/source/ui/unoobj/sc_appluno.cxx new file mode 100644 index 000000000..7c946e37e --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_appluno.cxx @@ -0,0 +1,886 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <cppuhelper/factory.hxx> +#include <osl/diagnose.h> +#include <bf_sfx2/app.hxx> + +#include "appluno.hxx" +#include "afmtuno.hxx" +#include "funcuno.hxx" +#include "filtuno.hxx" +#include "miscuno.hxx" +#include "scmod.hxx" +#include "appoptio.hxx" +#include "inputopt.hxx" +#include "printopt.hxx" +#include "userlist.hxx" +#include "bf_sc.hrc" // VAR_ARGS +#include <vcl/svapp.hxx> +#include "unonames.hxx" + +#include <com/sun/star/sheet/FunctionArgument.hpp> +namespace binfilter { + +using namespace ::com::sun::star; + + +// Calc document +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScDocument_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScDocument_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScDocument_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); + +// Calc XML import +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLImport_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLImport_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLImport_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLImport_Meta_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLImport_Meta_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLImport_Meta_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLImport_Styles_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLImport_Styles_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLImport_Styles_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLImport_Content_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLImport_Content_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLImport_Content_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLImport_Settings_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLImport_Settings_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLImport_Settings_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); + +// Calc XML export +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLExport_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLExport_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLExport_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLExport_Meta_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLExport_Meta_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLExport_Meta_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLExport_Styles_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLExport_Styles_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLExport_Styles_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLExport_Content_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLExport_Content_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLExport_Content_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); +extern uno::Sequence< ::rtl::OUString > SAL_CALL ScXMLExport_Settings_getSupportedServiceNames() throw(); +extern ::rtl::OUString SAL_CALL ScXMLExport_Settings_getImplementationName() throw(); +extern uno::Reference< uno::XInterface > SAL_CALL ScXMLExport_Settings_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & rSMgr ) throw( uno::Exception ); + + +// Anzahl der Funktionen, die als zuletzt benutzt gespeichert werden +//! Define mit funcpage.hxx und dwfunctr.hxx zusammenfassen !!! +#define LRU_MAX 10 + +// Spezial-Werte fuer Zoom +//! irgendwo zentral +#define SC_ZOOMVAL_OPTIMAL (-1) +#define SC_ZOOMVAL_WHOLEPAGE (-2) +#define SC_ZOOMVAL_PAGEWIDTH (-3) + +// Anzahl der PropertyValues in einer Function-Description +#define SC_FUNCDESC_PROPCOUNT 5 + + +// alles ohne Which-ID, Map nur fuer PropertySetInfo + +const SfxItemPropertyMap* lcl_GetSettingsPropertyMap() +{ + static SfxItemPropertyMap aSettingsPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_DOAUTOCP), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ENTERED), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_EXPREF), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_EXTFMT), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_LINKUPD), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_MARKHDR), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_METRIC), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_MOVEDIR), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_MOVESEL), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_PRALLSH), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_PREMPTY), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_RANGEFIN), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_SCALE), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_STBFUNC), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ULISTS), 0, &getCppuType((uno::Sequence< ::rtl::OUString>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_PRMETRICS),0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_USETABCOL),0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_REPLWARN), 0, &getBooleanCppuType(), 0,0}, + {0,0,0,0,0,0} + }; + return aSettingsPropertyMap_Impl; +} + + +#define SCFUNCTIONLISTOBJ_SERVICE "com.sun.star.sheet.FunctionDescriptions" +#define SCRECENTFUNCTIONSOBJ_SERVICE "com.sun.star.sheet.RecentFunctions" +#define SCSPREADSHEETSETTINGS_SERVICE "com.sun.star.sheet.GlobalSheetSettings" + +SC_SIMPLE_SERVICE_INFO( ScFunctionListObj, "ScFunctionListObj", SCFUNCTIONLISTOBJ_SERVICE ) +SC_SIMPLE_SERVICE_INFO( ScRecentFunctionsObj, "ScRecentFunctionsObj", SCRECENTFUNCTIONSOBJ_SERVICE ) +SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettings, "ScSpreadsheetSettings", SCSPREADSHEETSETTINGS_SERVICE ) + + +extern "C" { + +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) +{ + if (!pServiceManager) + return NULL; + + uno::Reference<lang::XSingleServiceFactory> xFactory; + ::rtl::OUString aImpl = ::rtl::OUString::createFromAscii(pImplName); + + if ( aImpl == ScSpreadsheetSettings::getImplementationName_Static() ) + xFactory = cppu::createOneInstanceFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScSpreadsheetSettings::getImplementationName_Static(), + ScSpreadsheetSettings_CreateInstance, + ScSpreadsheetSettings::getSupportedServiceNames_Static() ); + + if ( aImpl == ScRecentFunctionsObj::getImplementationName_Static() ) + xFactory = cppu::createOneInstanceFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScRecentFunctionsObj::getImplementationName_Static(), + ScRecentFunctionsObj_CreateInstance, + ScRecentFunctionsObj::getSupportedServiceNames_Static() ); + + if ( aImpl == ScFunctionListObj::getImplementationName_Static() ) + xFactory = cppu::createOneInstanceFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScFunctionListObj::getImplementationName_Static(), + ScFunctionListObj_CreateInstance, + ScFunctionListObj::getSupportedServiceNames_Static() ); + + if ( aImpl == ScAutoFormatsObj::getImplementationName_Static() ) + xFactory = cppu::createOneInstanceFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScAutoFormatsObj::getImplementationName_Static(), + ScAutoFormatsObj_CreateInstance, + ScAutoFormatsObj::getSupportedServiceNames_Static() ); + + if ( aImpl == ScFunctionAccess::getImplementationName_Static() ) + xFactory = cppu::createOneInstanceFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScFunctionAccess::getImplementationName_Static(), + ScFunctionAccess_CreateInstance, + ScFunctionAccess::getSupportedServiceNames_Static() ); + + if ( aImpl == ScFilterOptionsObj::getImplementationName_Static() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScFilterOptionsObj::getImplementationName_Static(), + ScFilterOptionsObj_CreateInstance, + ScFilterOptionsObj::getSupportedServiceNames_Static() ); + + if ( aImpl == ScXMLImport_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLImport_getImplementationName(), + ScXMLImport_createInstance, + ScXMLImport_getSupportedServiceNames() ); + + if ( aImpl == ScXMLImport_Meta_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLImport_Meta_getImplementationName(), + ScXMLImport_Meta_createInstance, + ScXMLImport_Meta_getSupportedServiceNames() ); + + if ( aImpl == ScXMLImport_Styles_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLImport_Styles_getImplementationName(), + ScXMLImport_Styles_createInstance, + ScXMLImport_Styles_getSupportedServiceNames() ); + + if ( aImpl == ScXMLImport_Content_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLImport_Content_getImplementationName(), + ScXMLImport_Content_createInstance, + ScXMLImport_Content_getSupportedServiceNames() ); + + if ( aImpl == ScXMLImport_Settings_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLImport_Settings_getImplementationName(), + ScXMLImport_Settings_createInstance, + ScXMLImport_Settings_getSupportedServiceNames() ); + + if ( aImpl == ScXMLExport_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLExport_getImplementationName(), + ScXMLExport_createInstance, + ScXMLExport_getSupportedServiceNames() ); + + if ( aImpl == ScXMLExport_Meta_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLExport_Meta_getImplementationName(), + ScXMLExport_Meta_createInstance, + ScXMLExport_Meta_getSupportedServiceNames() ); + + if ( aImpl == ScXMLExport_Styles_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLExport_Styles_getImplementationName(), + ScXMLExport_Styles_createInstance, + ScXMLExport_Styles_getSupportedServiceNames() ); + + if ( aImpl == ScXMLExport_Content_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLExport_Content_getImplementationName(), + ScXMLExport_Content_createInstance, + ScXMLExport_Content_getSupportedServiceNames() ); + + if ( aImpl == ScXMLExport_Settings_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScXMLExport_Settings_getImplementationName(), + ScXMLExport_Settings_createInstance, + ScXMLExport_Settings_getSupportedServiceNames() ); + + if ( aImpl == ScDocument_getImplementationName() ) + xFactory = cppu::createSingleFactory( + reinterpret_cast<lang::XMultiServiceFactory*>(pServiceManager), + ScDocument_getImplementationName(), + ScDocument_createInstance, + ScDocument_getSupportedServiceNames() ); + + + void* pRet = NULL; + if (xFactory.is()) + { + xFactory->acquire(); + pRet = xFactory.get(); + } + return pRet; +} + +} // extern C + + +ScSpreadsheetSettings::ScSpreadsheetSettings() : + aPropSet( lcl_GetSettingsPropertyMap() ) +{ +} + +ScSpreadsheetSettings::~ScSpreadsheetSettings() +{ +} + +uno::Reference<uno::XInterface> SAL_CALL ScSpreadsheetSettings_CreateInstance( + const uno::Reference<lang::XMultiServiceFactory>& /*rSMgr*/ ) +{ + SolarMutexGuard aGuard; + SC_DLL()->Load(); // load module + static uno::Reference<uno::XInterface> xInst = (cppu::OWeakObject*)new ScSpreadsheetSettings(); + return xInst; +} + +::rtl::OUString ScSpreadsheetSettings::getImplementationName_Static() +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "stardiv.StarCalc.ScSpreadsheetSettings" )); +} + +uno::Sequence< ::rtl::OUString> ScSpreadsheetSettings::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSPREADSHEETSETTINGS_SERVICE )); + return aRet; +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettings::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScSpreadsheetSettings::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + + ScModule* pScMod = SC_MOD(); + ScAppOptions aAppOpt = pScMod->GetAppOptions(); + ScInputOptions aInpOpt = pScMod->GetInputOptions(); + BOOL bSaveApp = FALSE; + BOOL bSaveInp = FALSE; + // print options aren't loaded until needed + + if (aString.EqualsAscii( SC_UNONAME_DOAUTOCP )) + { + aAppOpt.SetAutoComplete( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveApp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_ENTERED )) + { + aInpOpt.SetEnterEdit( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_EXPREF )) + { + aInpOpt.SetExpandRefs( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_EXTFMT )) + { + aInpOpt.SetExtendFormat( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_LINKUPD )) + { + aAppOpt.SetLinkMode( (ScLkUpdMode) ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); + bSaveApp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_MARKHDR )) + { + aInpOpt.SetMarkHeader( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_MOVESEL )) + { + aInpOpt.SetMoveSelection( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_RANGEFIN )) + { + aInpOpt.SetRangeFinder( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_USETABCOL )) + { + aInpOpt.SetUseTabCol( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_PRMETRICS )) + { + aInpOpt.SetTextWysiwyg( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_REPLWARN )) + { + aInpOpt.SetReplaceCellsWarn( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_METRIC )) + { + aAppOpt.SetAppMetric( (FieldUnit) ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); + bSaveApp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_MOVEDIR )) + { + aInpOpt.SetMoveDir( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); + bSaveInp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_SCALE )) + { + short nVal = ScUnoHelpFunctions::GetInt16FromAny( aValue ); + if ( nVal < 0 ) + { + SvxZoomType eType = SVX_ZOOM_PERCENT; + switch (nVal) + { + case SC_ZOOMVAL_OPTIMAL: eType = SVX_ZOOM_OPTIMAL; break; + case SC_ZOOMVAL_WHOLEPAGE: eType = SVX_ZOOM_WHOLEPAGE; break; + case SC_ZOOMVAL_PAGEWIDTH: eType = SVX_ZOOM_PAGEWIDTH; break; + } + aAppOpt.SetZoomType( eType ); + } + else if ( nVal >= MINZOOM && nVal <= MAXZOOM ) + { + aAppOpt.SetZoom( nVal ); + aAppOpt.SetZoomType( SVX_ZOOM_PERCENT ); + } + bSaveApp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_STBFUNC )) + { + aAppOpt.SetStatusFunc( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ); + bSaveApp = TRUE; + } + else if (aString.EqualsAscii( SC_UNONAME_ULISTS )) + { + ScUserList* pUserList = ScGlobal::GetUserList(); + uno::Sequence< ::rtl::OUString> aSeq; + if ( pUserList && ( aValue >>= aSeq ) ) + { + // es wird direkt die "lebende" Liste veraendert, + // mehr tut ScGlobal::SetUserList auch nicht + + pUserList->FreeAll(); // alle Eintraege raus + USHORT nCount = (USHORT)aSeq.getLength(); + const ::rtl::OUString* pAry = aSeq.getConstArray(); + for (USHORT i=0; i<nCount; i++) + { + String aEntry = pAry[i]; + ScUserListData* pData = new ScUserListData(aEntry); + if (!pUserList->Insert(pData)) // hinten anhaengen + delete pData; // sollte nicht vorkommen + } + bSaveApp = TRUE; // Liste wird mit den App-Optionen gespeichert + } + } + else if (aString.EqualsAscii( SC_UNONAME_PRALLSH )) + { + ScPrintOptions aPrintOpt = pScMod->GetPrintOptions(); + aPrintOpt.SetAllSheets( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + pScMod->SetPrintOptions( aPrintOpt ); + } + else if (aString.EqualsAscii( SC_UNONAME_PREMPTY )) + { + ScPrintOptions aPrintOpt = pScMod->GetPrintOptions(); + aPrintOpt.SetSkipEmpty( !ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); // reversed + pScMod->SetPrintOptions( aPrintOpt ); + SFX_APP()->Broadcast( SfxSimpleHint( SID_SCPRINTOPTIONS ) ); // update previews + } + + if ( bSaveApp ) + pScMod->SetAppOptions( aAppOpt ); + if ( bSaveInp ) + pScMod->SetInputOptions( aInpOpt ); +} + +uno::Any SAL_CALL ScSpreadsheetSettings::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + uno::Any aRet; + + ScModule* pScMod = SC_MOD(); + ScAppOptions aAppOpt = pScMod->GetAppOptions(); + ScInputOptions aInpOpt = pScMod->GetInputOptions(); + // print options aren't loaded until needed + + if (aString.EqualsAscii( SC_UNONAME_DOAUTOCP )) ScUnoHelpFunctions::SetBoolInAny( aRet, aAppOpt.GetAutoComplete() ); + else if (aString.EqualsAscii( SC_UNONAME_ENTERED )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetEnterEdit() ); + else if (aString.EqualsAscii( SC_UNONAME_EXPREF )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetExpandRefs() ); + else if (aString.EqualsAscii( SC_UNONAME_EXTFMT )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetExtendFormat() ); + else if (aString.EqualsAscii( SC_UNONAME_LINKUPD )) aRet <<= (sal_Int16) aAppOpt.GetLinkMode(); + else if (aString.EqualsAscii( SC_UNONAME_MARKHDR )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetMarkHeader() ); + else if (aString.EqualsAscii( SC_UNONAME_MOVESEL )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetMoveSelection() ); + else if (aString.EqualsAscii( SC_UNONAME_RANGEFIN )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetRangeFinder() ); + else if (aString.EqualsAscii( SC_UNONAME_USETABCOL )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetUseTabCol() ); + else if (aString.EqualsAscii( SC_UNONAME_PRMETRICS )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetTextWysiwyg() ); + else if (aString.EqualsAscii( SC_UNONAME_REPLWARN )) ScUnoHelpFunctions::SetBoolInAny( aRet, aInpOpt.GetReplaceCellsWarn() ); + else if (aString.EqualsAscii( SC_UNONAME_METRIC )) aRet <<= (sal_Int16) aAppOpt.GetAppMetric(); + else if (aString.EqualsAscii( SC_UNONAME_MOVEDIR )) aRet <<= (sal_Int16) aInpOpt.GetMoveDir(); + else if (aString.EqualsAscii( SC_UNONAME_STBFUNC )) aRet <<= (sal_Int16) aAppOpt.GetStatusFunc(); + else if (aString.EqualsAscii( SC_UNONAME_SCALE )) + { + INT16 nZoomVal = 0; + switch ( aAppOpt.GetZoomType() ) + { + case SVX_ZOOM_PERCENT: nZoomVal = aAppOpt.GetZoom(); break; + case SVX_ZOOM_OPTIMAL: nZoomVal = SC_ZOOMVAL_OPTIMAL; break; + case SVX_ZOOM_WHOLEPAGE: nZoomVal = SC_ZOOMVAL_WHOLEPAGE; break; + case SVX_ZOOM_PAGEWIDTH: nZoomVal = SC_ZOOMVAL_PAGEWIDTH; break; + default: break; + } + aRet <<= (sal_Int16) nZoomVal; + } + else if (aString.EqualsAscii( SC_UNONAME_ULISTS )) + { + ScUserList* pUserList = ScGlobal::GetUserList(); + if (pUserList) + { + USHORT nCount = pUserList->GetCount(); + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + String aEntry = (*pUserList)[i]->GetString(); + pAry[i] = aEntry; + } + aRet <<= aSeq; + } + } + else if (aString.EqualsAscii( SC_UNONAME_PRALLSH )) + ScUnoHelpFunctions::SetBoolInAny( aRet, pScMod->GetPrintOptions().GetAllSheets() ); + else if (aString.EqualsAscii( SC_UNONAME_PREMPTY )) + ScUnoHelpFunctions::SetBoolInAny( aRet, !pScMod->GetPrintOptions().GetSkipEmpty() ); // reversed + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettings ) + + +ScRecentFunctionsObj::ScRecentFunctionsObj() +{ +} + +ScRecentFunctionsObj::~ScRecentFunctionsObj() +{ +} + +// stuff for exService_... + +uno::Reference<uno::XInterface> SAL_CALL ScRecentFunctionsObj_CreateInstance( + const uno::Reference<lang::XMultiServiceFactory>& /*rSMgr*/ ) +{ + SolarMutexGuard aGuard; + SC_DLL()->Load(); // load module + static uno::Reference<uno::XInterface> xInst = (cppu::OWeakObject*)new ScRecentFunctionsObj(); + return xInst; +} + +::rtl::OUString ScRecentFunctionsObj::getImplementationName_Static() +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "stardiv.StarCalc.ScRecentFunctionsObj" )); +} + +uno::Sequence< ::rtl::OUString> ScRecentFunctionsObj::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCRECENTFUNCTIONSOBJ_SERVICE )); + return aRet; +} + +// XRecentFunctions + +uno::Sequence<sal_Int32> SAL_CALL ScRecentFunctionsObj::getRecentFunctionIds() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScAppOptions& rOpt = SC_MOD()->GetAppOptions(); + USHORT nCount = rOpt.GetLRUFuncListCount(); + const USHORT* pFuncs = rOpt.GetLRUFuncList(); + if (pFuncs) + { + uno::Sequence<sal_Int32> aSeq(nCount); + sal_Int32* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + pAry[i] = pFuncs[i]; + return aSeq; + } + return uno::Sequence<sal_Int32>(0); +} + +void SAL_CALL ScRecentFunctionsObj::setRecentFunctionIds( + const uno::Sequence<sal_Int32>& aRecentFunctionIds ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = (USHORT) Min( aRecentFunctionIds.getLength(), (INT32) LRU_MAX ); + const INT32* pAry = aRecentFunctionIds.getConstArray(); + + USHORT* pFuncs = nCount ? new USHORT[nCount] : NULL; + for (USHORT i=0; i<nCount; i++) + pFuncs[i] = (USHORT)pAry[i]; //! auf gueltige Werte testen? + + ScModule* pScMod = SC_MOD(); + ScAppOptions aNewOpts(pScMod->GetAppOptions()); + aNewOpts.SetLRUFuncList(pFuncs, nCount); + pScMod->SetAppOptions(aNewOpts); + + delete[] pFuncs; +} + +sal_Int32 SAL_CALL ScRecentFunctionsObj::getMaxRecentFunctions() throw(uno::RuntimeException) +{ + return LRU_MAX; +} + + +ScFunctionListObj::ScFunctionListObj() +{ +} + +ScFunctionListObj::~ScFunctionListObj() +{ +} + +// stuff for exService_... + +uno::Reference<uno::XInterface> SAL_CALL ScFunctionListObj_CreateInstance( + const uno::Reference<lang::XMultiServiceFactory>& /*rSMgr*/ ) +{ + SolarMutexGuard aGuard; + SC_DLL()->Load(); // load module + static uno::Reference<uno::XInterface> xInst = (cppu::OWeakObject*)new ScFunctionListObj(); + return xInst; +} + +::rtl::OUString ScFunctionListObj::getImplementationName_Static() +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "stardiv.StarCalc.ScFunctionListObj" )); +} + +uno::Sequence< ::rtl::OUString> ScFunctionListObj::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCFUNCTIONLISTOBJ_SERVICE )); + return aRet; +} + + +void lcl_FillSequence( uno::Sequence<beans::PropertyValue>& rSequence, const ScFuncDesc& rDesc ) +{ + DBG_ASSERT( rSequence.getLength() == SC_FUNCDESC_PROPCOUNT, "Falscher Count" ); + + beans::PropertyValue* pArray = rSequence.getArray(); + + pArray[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ID )); + pArray[0].Value <<= (sal_Int32) rDesc.nFIndex; + + pArray[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CATEGORY )); + pArray[1].Value <<= (sal_Int32) rDesc.nCategory; + + pArray[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_NAME )); + if (rDesc.pFuncName) + pArray[2].Value <<= ::rtl::OUString( *rDesc.pFuncName ); + + pArray[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_DESCRIPTION )); + if (rDesc.pFuncDesc) + pArray[3].Value <<= ::rtl::OUString( *rDesc.pFuncDesc ); + + pArray[4].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ARGUMENTS )); + if (rDesc.aDefArgNames && rDesc.aDefArgDescs && rDesc.aDefArgOpt ) + { + USHORT nCount = rDesc.nArgCount; + if (nCount >= VAR_ARGS) nCount = nCount-VAR_ARGS+1; + + uno::Sequence<sheet::FunctionArgument> aArgSeq(nCount); + sheet::FunctionArgument* pArgAry = aArgSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + String aArgName; + if (rDesc.aDefArgNames[i]) aArgName = *rDesc.aDefArgNames[i]; + String aArgDesc; + if (rDesc.aDefArgDescs[i]) aArgDesc = *rDesc.aDefArgDescs[i]; + sheet::FunctionArgument aArgument; + aArgument.Name = aArgName; + aArgument.Description = aArgDesc; + aArgument.IsOptional = rDesc.aDefArgOpt[i]; + pArgAry[i] = aArgument; + } + pArray[4].Value <<= aArgSeq; + } +} + +// XFunctionDescriptions + +uno::Sequence<beans::PropertyValue> SAL_CALL ScFunctionListObj::getById( sal_Int32 nId ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); + if ( pFuncList ) + { + USHORT nCount = (USHORT)pFuncList->GetCount(); + for (USHORT nIndex=0; nIndex<nCount; nIndex++) + { + const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); + if ( pDesc && pDesc->nFIndex == nId ) + { + uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT ); + lcl_FillSequence( aSeq, *pDesc ); + return aSeq; + } + } + + throw lang::IllegalArgumentException(); // not found + } + else + throw uno::RuntimeException(); // should not happen + + return uno::Sequence<beans::PropertyValue>(0); +} + +// XNameAccess + +uno::Any SAL_CALL ScFunctionListObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr = aName; + const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); + if ( pFuncList ) + { + USHORT nCount = (USHORT)pFuncList->GetCount(); + for (USHORT nIndex=0; nIndex<nCount; nIndex++) + { + const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); + //! Case-insensitiv ??? + if ( pDesc && pDesc->pFuncName && aNameStr == *pDesc->pFuncName ) + { + uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT ); + lcl_FillSequence( aSeq, *pDesc ); + uno::Any aAny; + aAny <<= aSeq; + return aAny; + } + } + + throw container::NoSuchElementException(); // not found + } + else + throw uno::RuntimeException(); // should not happen + + return uno::Any(); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScFunctionListObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = 0; + const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); + if ( pFuncList ) + nCount = (USHORT)pFuncList->GetCount(); + return nCount; +} + +uno::Any SAL_CALL ScFunctionListObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); + if ( pFuncList ) + { + if ( nIndex >= 0 && nIndex < (sal_Int32)pFuncList->GetCount() ) + { + const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); + if ( pDesc ) + { + uno::Sequence<beans::PropertyValue> aSeq( SC_FUNCDESC_PROPCOUNT ); + lcl_FillSequence( aSeq, *pDesc ); + uno::Any aAny; + aAny <<= aSeq; + return aAny; + } + } + + throw lang::IndexOutOfBoundsException(); // illegal index + } + else + throw uno::RuntimeException(); // should not happen + + return uno::Any(); +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScFunctionListObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.FunctionDescriptionEnumeration"))); +} + +// XElementAccess + +uno::Type SAL_CALL ScFunctionListObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Sequence<beans::PropertyValue>*)0); +} + +sal_Bool SAL_CALL ScFunctionListObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() > 0 ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScFunctionListObj::getElementNames() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); + if ( pFuncList ) + { + USHORT nCount = (USHORT)pFuncList->GetCount(); + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (USHORT nIndex=0; nIndex<nCount; nIndex++) + { + const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); + if ( pDesc && pDesc->pFuncName ) + pAry[nIndex] = *pDesc->pFuncName; + } + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(0); +} + +sal_Bool SAL_CALL ScFunctionListObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr = aName; + const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList(); + if ( pFuncList ) + { + USHORT nCount = (USHORT)pFuncList->GetCount(); + for (USHORT nIndex=0; nIndex<nCount; nIndex++) + { + const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); + //! Case-insensitiv ??? + if ( pDesc && pDesc->pFuncName && aNameStr == *pDesc->pFuncName ) + return TRUE; + } + } + return FALSE; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_cellsuno.cxx b/bf_sc/source/ui/unoobj/sc_cellsuno.cxx new file mode 100644 index 000000000..76a8bd814 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_cellsuno.cxx @@ -0,0 +1,8248 @@ +/* -*- 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. + * + ************************************************************************/ + + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include "scitems.hxx" +#include <bf_svx/eeitem.hxx> +#define ITEMID_FIELD EE_FEATURE_FIELD + + + +#include <bf_svtools/poolitem.hxx> + +#include <bf_svx/itemdata.hxx> + +#include <tools/date.hxx> + +#include <tools/time.hxx> + +#include <vcl/svapp.hxx> +#include <bf_svx/flditem.hxx> +#include <bf_svx/langitem.hxx> +#include <bf_svx/linkmgr.hxx> +#include <bf_svx/svdpage.hxx> +#include <bf_sch/memchrt.hxx> +#include <bf_svtools/zformat.hxx> +#include <rtl/uuid.h> +#include <rtl/strbuf.hxx> +#include <float.h> // DBL_MIN + +#include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/util/CellProtection.hpp> +#include <com/sun/star/table/CellHoriJustify.hpp> +#include <com/sun/star/table/CellOrientation.hpp> +#include <com/sun/star/table/CellVertJustify.hpp> +#include <com/sun/star/table/ShadowFormat.hpp> +#include <com/sun/star/sheet/CellFlags.hpp> +#include <com/sun/star/sheet/FormulaResult.hpp> + +#include "autoform.hxx" +#include "cursuno.hxx" +#include "textuno.hxx" +#include "editsrc.hxx" +#include "notesuno.hxx" +#include "fielduno.hxx" +#include "docuno.hxx" // ScTableColumnsObj etc +#include "datauno.hxx" +#include "dapiuno.hxx" +#include "chartuno.hxx" +#include "fmtuno.hxx" +#include "miscuno.hxx" +#include "convuno.hxx" +#include "docsh.hxx" +#include "patattr.hxx" +#include "docpool.hxx" +#include "docfunc.hxx" +#include "dbdocfun.hxx" +#include "hints.hxx" +#include "cell.hxx" +#include "undotab.hxx" +#include "stlsheet.hxx" +#include "dbcolect.hxx" +#include "attrib.hxx" +#include "chartarr.hxx" +#include "chartlis.hxx" +#include "drwlayer.hxx" +#include "printfun.hxx" +#include "prnsave.hxx" +#include "tablink.hxx" +#include "dociter.hxx" +#include "validat.hxx" +#include "bf_sc.hrc" +#include <vcl/svapp.hxx> +#include "cellform.hxx" +#include "globstr.hrc" +#include "unonames.hxx" +#include "styleuno.hxx" +#include "rangeseq.hxx" +#include "unowids.hxx" + +#include <list> + +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +//! ScLinkListener in anderes File verschieben !!! + +class ScLinkListener : public SfxListener +{ + Link aLink; +public: + ScLinkListener(const Link& rL) : aLink(rL) {} + virtual ~ScLinkListener(); + virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); +}; + + +class ScNamedEntry +{ + String aName; + ScRange aRange; + +public: + ScNamedEntry(const String& rN, const ScRange& rR) : + aName(rN), aRange(rR) {} + + const String& GetName() const { return aName; } + const ScRange& GetRange() const { return aRange; } +}; + + +//------------------------------------------------------------------------ + +// Die Namen in den Maps muessen (nach strcmp) sortiert sein! +//! statt Which-ID 0 special IDs verwenden, und nicht ueber Namen vergleichen !!!!!!!!! + +// Left/Right/Top/BottomBorder are mapped directly to the core items, +// not collected/applied to the borders of a range -> ATTR_BORDER can be used directly + +const SfxItemPropertyMap* lcl_GetCellsPropertyMap() +{ + static SfxItemPropertyMap aCellsPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &getCppuType((sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CELLPRO), ATTR_PROTECTION, &getCppuType((util::CellProtection*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLSTYL), SC_WID_UNO_CELLSTYL,&getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CEMPHAS), ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0), 0, MID_EMPHASIS }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CRELIEF), ATTR_FONT_RELIEF, &getCppuType((sal_Int16*)0), 0, MID_RELIEF }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CSTRIKE), ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0), 0, MID_CROSS_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0), 0, MID_UL_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS), ATTR_FONT_UNDERLINE,&getBooleanCppuType(), 0, MID_UL_HASCOLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CWORDMOD), ATTR_FONT_WORDLINE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR), SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHROWHDR), SC_WID_UNO_CHROWHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDFMT), SC_WID_UNO_CONDFMT, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDLOC), SC_WID_UNO_CONDLOC, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDXML), SC_WID_UNO_CONDXML, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_NUMFMT), ATTR_VALUE_FORMAT, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NUMRULES), SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &getCppuType((table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PADJUST), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PINDENT), ATTR_INDENT, &getCppuType((sal_Int16*)0), 0, 0 }, //! CONVERT_TWIPS + {MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHANG), ATTR_HANGPUNCTUATION,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PLASTADJ), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_SHADOW), ATTR_SHADOW, &getCppuType((table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIDAT), SC_WID_UNO_VALIDAT, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALILOC), SC_WID_UNO_VALILOC, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIXML), SC_WID_UNO_VALIXML, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aCellsPropertyMap_Impl; +} + +// CellRange enthaelt alle Eintraege von Cells, zusaetzlich eigene Eintraege +// mit Which-ID 0 (werden nur fuer getPropertySetInfo benoetigt). + +const SfxItemPropertyMap* lcl_GetRangePropertyMap() +{ + static SfxItemPropertyMap aRangePropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &getCppuType((sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CELLPRO), ATTR_PROTECTION, &getCppuType((util::CellProtection*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLSTYL), SC_WID_UNO_CELLSTYL,&getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CEMPHAS), ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0), 0, MID_EMPHASIS }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CRELIEF), ATTR_FONT_RELIEF, &getCppuType((sal_Int16*)0), 0, MID_RELIEF }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CSTRIKE), ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0), 0, MID_CROSS_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0), 0, MID_UL_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS), ATTR_FONT_UNDERLINE,&getBooleanCppuType(), 0, MID_UL_HASCOLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CWORDMOD), ATTR_FONT_WORDLINE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR), SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHROWHDR), SC_WID_UNO_CHROWHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDFMT), SC_WID_UNO_CONDFMT, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDLOC), SC_WID_UNO_CONDLOC, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDXML), SC_WID_UNO_CONDXML, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_NUMFMT), ATTR_VALUE_FORMAT, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NUMRULES), SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &getCppuType((table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PADJUST), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PINDENT), ATTR_INDENT, &getCppuType((sal_Int16*)0), 0, 0 }, //! CONVERT_TWIPS + {MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHANG), ATTR_HANGPUNCTUATION,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PLASTADJ), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_POS), SC_WID_UNO_POS, &getCppuType((awt::Point*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_SHADOW), ATTR_SHADOW, &getCppuType((table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_SIZE), SC_WID_UNO_SIZE, &getCppuType((awt::Size*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIDAT), SC_WID_UNO_VALIDAT, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALILOC), SC_WID_UNO_VALILOC, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIXML), SC_WID_UNO_VALIXML, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aRangePropertyMap_Impl; +} + +// Cell enthaelt alle Eintraege von CellRange, zusaetzlich eigene Eintraege +// mit Which-ID 0 (werden nur fuer getPropertySetInfo benoetigt). + +const SfxItemPropertyMap* lcl_GetCellPropertyMap() +{ + static SfxItemPropertyMap aCellPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &getCppuType((sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CELLPRO), ATTR_PROTECTION, &getCppuType((util::CellProtection*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLSTYL), SC_WID_UNO_CELLSTYL,&getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CEMPHAS), ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0), 0, MID_EMPHASIS }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CRELIEF), ATTR_FONT_RELIEF, &getCppuType((sal_Int16*)0), 0, MID_RELIEF }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CSTRIKE), ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0), 0, MID_CROSS_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0), 0, MID_UL_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS), ATTR_FONT_UNDERLINE,&getBooleanCppuType(), 0, MID_UL_HASCOLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CWORDMOD), ATTR_FONT_WORDLINE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR), SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHROWHDR), SC_WID_UNO_CHROWHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDFMT), SC_WID_UNO_CONDFMT, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDLOC), SC_WID_UNO_CONDLOC, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDXML), SC_WID_UNO_CONDXML, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_FORMLOC), SC_WID_UNO_FORMLOC, &getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_FORMRT), SC_WID_UNO_FORMRT, &getCppuType((table::CellContentType*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_NUMFMT), ATTR_VALUE_FORMAT, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NUMRULES), SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &getCppuType((table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PADJUST), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PINDENT), ATTR_INDENT, &getCppuType((sal_Int16*)0), 0, 0 }, //! CONVERT_TWIPS + {MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHANG), ATTR_HANGPUNCTUATION,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PLASTADJ), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_POS), SC_WID_UNO_POS, &getCppuType((awt::Point*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_SHADOW), ATTR_SHADOW, &getCppuType((table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_SIZE), SC_WID_UNO_SIZE, &getCppuType((awt::Size*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIDAT), SC_WID_UNO_VALIDAT, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALILOC), SC_WID_UNO_VALILOC, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIXML), SC_WID_UNO_VALIXML, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aCellPropertyMap_Impl; +} + +// Column und Row enthalten alle Eintraege von CellRange, zusaetzlich eigene Eintraege +// mit Which-ID 0 (werden nur fuer getPropertySetInfo benoetigt). + +const SfxItemPropertyMap* lcl_GetColumnPropertyMap() +{ + static SfxItemPropertyMap aColumnPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &getCppuType((sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CELLPRO), ATTR_PROTECTION, &getCppuType((util::CellProtection*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLSTYL), SC_WID_UNO_CELLSTYL,&getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CEMPHAS), ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0), 0, MID_EMPHASIS }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CRELIEF), ATTR_FONT_RELIEF, &getCppuType((sal_Int16*)0), 0, MID_RELIEF }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CSTRIKE), ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0), 0, MID_CROSS_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0), 0, MID_UL_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS), ATTR_FONT_UNDERLINE,&getBooleanCppuType(), 0, MID_UL_HASCOLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CWORDMOD), ATTR_FONT_WORDLINE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR), SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHROWHDR), SC_WID_UNO_CHROWHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDFMT), SC_WID_UNO_CONDFMT, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDLOC), SC_WID_UNO_CONDLOC, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDXML), SC_WID_UNO_CONDXML, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), SC_WID_UNO_MANPAGE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), SC_WID_UNO_NEWPAGE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), SC_WID_UNO_CELLVIS, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_NUMFMT), ATTR_VALUE_FORMAT, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NUMRULES), SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_OWIDTH), SC_WID_UNO_OWIDTH, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &getCppuType((table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PADJUST), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PINDENT), ATTR_INDENT, &getCppuType((sal_Int16*)0), 0, 0 }, //! CONVERT_TWIPS + {MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHANG), ATTR_HANGPUNCTUATION,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PLASTADJ), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_POS), SC_WID_UNO_POS, &getCppuType((awt::Point*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_SHADOW), ATTR_SHADOW, &getCppuType((table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_SIZE), SC_WID_UNO_SIZE, &getCppuType((awt::Size*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIDAT), SC_WID_UNO_VALIDAT, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALILOC), SC_WID_UNO_VALILOC, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIXML), SC_WID_UNO_VALIXML, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLWID), SC_WID_UNO_CELLWID, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aColumnPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetRowPropertyMap() +{ + static SfxItemPropertyMap aRowPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &getCppuType((sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CELLPRO), ATTR_PROTECTION, &getCppuType((util::CellProtection*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLSTYL), SC_WID_UNO_CELLSTYL,&getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CEMPHAS), ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0), 0, MID_EMPHASIS }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CRELIEF), ATTR_FONT_RELIEF, &getCppuType((sal_Int16*)0), 0, MID_RELIEF }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CSTRIKE), ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0), 0, MID_CROSS_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0), 0, MID_UL_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS), ATTR_FONT_UNDERLINE,&getBooleanCppuType(), 0, MID_UL_HASCOLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CWORDMOD), ATTR_FONT_WORDLINE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR), SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHROWHDR), SC_WID_UNO_CHROWHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDFMT), SC_WID_UNO_CONDFMT, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDLOC), SC_WID_UNO_CONDLOC, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDXML), SC_WID_UNO_CONDXML, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHGT), SC_WID_UNO_CELLHGT, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_CELLFILT), SC_WID_UNO_CELLFILT,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), SC_WID_UNO_MANPAGE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), SC_WID_UNO_NEWPAGE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), SC_WID_UNO_CELLVIS, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_NUMFMT), ATTR_VALUE_FORMAT, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NUMRULES), SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_OHEIGHT), SC_WID_UNO_OHEIGHT, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &getCppuType((table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PADJUST), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PINDENT), ATTR_INDENT, &getCppuType((sal_Int16*)0), 0, 0 }, //! CONVERT_TWIPS + {MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHANG), ATTR_HANGPUNCTUATION,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PLASTADJ), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_POS), SC_WID_UNO_POS, &getCppuType((awt::Point*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_SHADOW), ATTR_SHADOW, &getCppuType((table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_SIZE), SC_WID_UNO_SIZE, &getCppuType((awt::Size*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIDAT), SC_WID_UNO_VALIDAT, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALILOC), SC_WID_UNO_VALILOC, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIXML), SC_WID_UNO_VALIXML, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aRowPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetSheetPropertyMap() +{ + static SfxItemPropertyMap aSheetPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &getCppuType((sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CELLPRO), ATTR_PROTECTION, &getCppuType((util::CellProtection*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLSTYL), SC_WID_UNO_CELLSTYL,&getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT,&getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CEMPHAS), ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0), 0, MID_EMPHASIS }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT,&getCppuType((float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE,&getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE,&getCppuType((awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CRELIEF), ATTR_FONT_RELIEF, &getCppuType((sal_Int16*)0), 0, MID_RELIEF }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CSTRIKE), ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0), 0, MID_CROSS_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0), 0, MID_UL_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS), ATTR_FONT_UNDERLINE,&getBooleanCppuType(), 0, MID_UL_HASCOLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT,&getCppuType((float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CWORDMOD), ATTR_FONT_WORDLINE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHCOLHDR), SC_WID_UNO_CHCOLHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CHROWHDR), SC_WID_UNO_CHROWHDR,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDFMT), SC_WID_UNO_CONDFMT, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDLOC), SC_WID_UNO_CONDLOC, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CONDXML), SC_WID_UNO_CONDXML, &getCppuType((uno::Reference<sheet::XSheetConditionalEntries>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &getCppuType((table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), SC_WID_UNO_CELLVIS, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), SC_WID_UNO_LINKDISPBIT,&getCppuType((uno::Reference<awt::XBitmap>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), SC_WID_UNO_LINKDISPNAME,&getCppuType((::rtl::OUString*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NUMFMT), ATTR_VALUE_FORMAT, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NUMRULES), SC_WID_UNO_NUMRULES,&getCppuType((const uno::Reference<container::XIndexReplace>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &getCppuType((table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PAGESTL), SC_WID_UNO_PAGESTL, &getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PADJUST), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PINDENT), ATTR_INDENT, &getCppuType((sal_Int16*)0), 0, 0 }, //! CONVERT_TWIPS + {MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHANG), ATTR_HANGPUNCTUATION,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PLASTADJ), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &getCppuType((sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_POS), SC_WID_UNO_POS, &getCppuType((awt::Point*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_SHADOW), ATTR_SHADOW, &getCppuType((table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_SIZE), SC_WID_UNO_SIZE, &getCppuType((awt::Size*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &getCppuType((table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIDAT), SC_WID_UNO_VALIDAT, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALILOC), SC_WID_UNO_VALILOC, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_VALIXML), SC_WID_UNO_VALIXML, &getCppuType((uno::Reference<beans::XPropertySet>*)0), 0 | beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &getCppuType((table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aSheetPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetEditPropertyMap() +{ + static SfxItemPropertyMap aEditPropertyMap_Impl[] = + { + SVX_UNOEDIT_CHAR_PROPERTIES, + SVX_UNOEDIT_FONT_PROPERTIES, + SVX_UNOEDIT_PARA_PROPERTIES, + SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties + {MAP_CHAR_LEN(SC_UNONAME_TEXTUSER), EE_CHAR_XMLATTRIBS, &getCppuType((const uno::Reference< container::XNameContainer >*)0), 0, 0}, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), EE_PARA_XMLATTRIBS, &getCppuType((const uno::Reference< container::XNameContainer >*)0), 0, 0}, + {0,0,0,0,0,0} + }; + return aEditPropertyMap_Impl; +} + + +//------------------------------------------------------------------------ + +//! diese Funktionen in einen allgemeinen Header verschieben +inline long TwipsToHMM(long nTwips) { return (nTwips * 127 + 36) / 72; } +inline long HMMToTwips(long nHMM) { return (nHMM * 72 + 63) / 127; } + +//------------------------------------------------------------------------ + +#define SCCHARPROPERTIES_SERVICE "com.sun.star.style.CharacterProperties" +#define SCPARAPROPERTIES_SERVICE "com.sun.star.style.ParagraphProperties" +#define SCCELLPROPERTIES_SERVICE "com.sun.star.table.CellProperties" +#define SCCELLRANGE_SERVICE "com.sun.star.table.CellRange" +#define SCCELL_SERVICE "com.sun.star.table.Cell" +#define SCSHEETCELLRANGES_SERVICE "com.sun.star.sheet.SheetCellRanges" +#define SCSHEETCELLRANGE_SERVICE "com.sun.star.sheet.SheetCellRange" +#define SCSPREADSHEET_SERVICE "com.sun.star.sheet.Spreadsheet" +#define SCSHEETCELL_SERVICE "com.sun.star.sheet.SheetCell" + +SC_SIMPLE_SERVICE_INFO( ScCellFormatsEnumeration, "ScCellFormatsEnumeration", "com.sun.star.sheet.CellFormatRangesEnumeration" ) +SC_SIMPLE_SERVICE_INFO( ScCellFormatsObj, "ScCellFormatsObj", "com.sun.star.sheet.CellFormatRanges" ) +SC_SIMPLE_SERVICE_INFO( ScUniqueCellFormatsEnumeration, "ScUniqueCellFormatsEnumeration", "com.sun.star.sheet.UniqueCellFormatRangesEnumeration" ) +SC_SIMPLE_SERVICE_INFO( ScUniqueCellFormatsObj, "ScUniqueCellFormatsObj", "com.sun.star.sheet.UniqueCellFormatRanges" ) +SC_SIMPLE_SERVICE_INFO( ScCellRangesBase, "ScCellRangesBase", "stardiv.unknown" ) +SC_SIMPLE_SERVICE_INFO( ScCellsEnumeration, "ScCellsEnumeration", "com.sun.star.sheet.CellsEnumeration" ) +SC_SIMPLE_SERVICE_INFO( ScCellsObj, "ScCellsObj", "com.sun.star.sheet.Cells" ) +SC_SIMPLE_SERVICE_INFO( ScTableColumnObj, "ScTableColumnObj", "com.sun.star.table.TableColumn" ) +SC_SIMPLE_SERVICE_INFO( ScTableRowObj, "ScTableRowObj", "com.sun.star.table.TableRow" ) + +//------------------------------------------------------------------------ + +SV_IMPL_PTRARR( XPropertyChangeListenerArr_Impl, XPropertyChangeListenerPtr ); +SV_IMPL_PTRARR( ScNamedEntryArr_Impl, ScNamedEntryPtr ); + +//------------------------------------------------------------------------ + +#ifdef DBG_UTIL +#define TEST_PROPERTY_MAPS +#endif + +#ifdef TEST_PROPERTY_MAPS + +void lcl_TestMap( const SfxItemPropertyMap* pMap ) +{ + while ( pMap->pName ) + { + const SfxItemPropertyMap* pNext = pMap + 1; + if ( pNext->pName ) + { + int nDiff = strcmp( pMap->pName, pNext->pName ); + if ( nDiff >= 0 ) + { + rtl::OStringBuffer aErr("Reihenfolge: "); + aErr.append(pMap->pName).append('/').append(pNext->pName); + OSL_FAIL(aErr.getStr()); + } + } + pMap = pNext; + } +} + +struct ScPropertyTester +{ + ScPropertyTester(); +}; + +ScPropertyTester::ScPropertyTester() +{ + lcl_TestMap( lcl_GetCellsPropertyMap() ); + lcl_TestMap( lcl_GetRangePropertyMap() ); + lcl_TestMap( lcl_GetCellPropertyMap() ); + lcl_TestMap( lcl_GetColumnPropertyMap() ); + lcl_TestMap( lcl_GetRowPropertyMap() ); + lcl_TestMap( lcl_GetSheetPropertyMap() ); +} + +ScPropertyTester aPropertyTester; + +#endif + +//------------------------------------------------------------------------ + +//! ScLinkListener in anderes File verschieben !!! + +ScLinkListener::~ScLinkListener() +{ +} + +void ScLinkListener::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + aLink.Call( (SfxHint*)&rHint ); +} + + +void lcl_CopyProperties( beans::XPropertySet& rDest, beans::XPropertySet& rSource ) +{ + uno::Reference<beans::XPropertySetInfo> xInfo = rSource.getPropertySetInfo(); + if (xInfo.is()) + { + uno::Sequence<beans::Property> aSeq = xInfo->getProperties(); + const beans::Property* pAry = aSeq.getConstArray(); + ULONG nCount = aSeq.getLength(); + for (ULONG i=0; i<nCount; i++) + { + ::rtl::OUString aName = pAry[i].Name; + rDest.setPropertyValue( aName, rSource.getPropertyValue( aName ) ); + } + } +} + +USHORT lcl_FirstTab( const ScRangeList& rRanges ) +{ + DBG_ASSERT(rRanges.Count() >= 1, "was fuer Ranges ?!?!"); + const ScRange* pFirst = rRanges.GetObject(0); + if (pFirst) + return pFirst->aStart.Tab(); + + return 0; // soll nicht sein +} + +//------------------------------------------------------------------------ + +ScSubTotalFunc lcl_SummaryToSubTotal( sheet::GeneralFunction eSummary ) +{ + ScSubTotalFunc eSubTotal; + switch (eSummary) + { + case sheet::GeneralFunction_SUM: + eSubTotal = SUBTOTAL_FUNC_SUM; + break; + case sheet::GeneralFunction_COUNT: + eSubTotal = SUBTOTAL_FUNC_CNT2; + break; + case sheet::GeneralFunction_AVERAGE: + eSubTotal = SUBTOTAL_FUNC_AVE; + break; + case sheet::GeneralFunction_MAX: + eSubTotal = SUBTOTAL_FUNC_MAX; + break; + case sheet::GeneralFunction_MIN: + eSubTotal = SUBTOTAL_FUNC_MIN; + break; + case sheet::GeneralFunction_PRODUCT: + eSubTotal = SUBTOTAL_FUNC_PROD; + break; + case sheet::GeneralFunction_COUNTNUMS: + eSubTotal = SUBTOTAL_FUNC_CNT; + break; + case sheet::GeneralFunction_STDEV: + eSubTotal = SUBTOTAL_FUNC_STD; + break; + case sheet::GeneralFunction_STDEVP: + eSubTotal = SUBTOTAL_FUNC_STDP; + break; + case sheet::GeneralFunction_VAR: + eSubTotal = SUBTOTAL_FUNC_VAR; + break; + case sheet::GeneralFunction_VARP: + eSubTotal = SUBTOTAL_FUNC_VARP; + break; + + case sheet::GeneralFunction_NONE: + case sheet::GeneralFunction_AUTO: + default: + eSubTotal = SUBTOTAL_FUNC_NONE; + break; + } + return eSubTotal; +} + +//------------------------------------------------------------------------ + +const SvxBorderLine* ScHelperFunctions::GetBorderLine( SvxBorderLine& rLine, const table::BorderLine& rStruct ) +{ + // Calc braucht Twips, im Uno-Struct sind 1/100mm + + rLine.SetOutWidth( (USHORT)HMMToTwips( rStruct.OuterLineWidth ) ); + rLine.SetInWidth( (USHORT)HMMToTwips( rStruct.InnerLineWidth ) ); + rLine.SetDistance( (USHORT)HMMToTwips( rStruct.LineDistance ) ); + rLine.SetColor( ColorData( rStruct.Color ) ); + + if ( rLine.GetOutWidth() || rLine.GetInWidth() || rLine.GetDistance() ) + return &rLine; + else + return NULL; +} + +void ScHelperFunctions::FillBoxItems( SvxBoxItem& rOuter, SvxBoxInfoItem& rInner, const table::TableBorder& rBorder ) +{ + SvxBorderLine aLine; + rOuter.SetDistance( (USHORT)HMMToTwips( rBorder.Distance ) ); + rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.TopLine ), BOX_LINE_TOP ); + rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.BottomLine ), BOX_LINE_BOTTOM ); + rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.LeftLine ), BOX_LINE_LEFT ); + rOuter.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.RightLine ), BOX_LINE_RIGHT ); + rInner.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.HorizontalLine ), BOXINFO_LINE_HORI ); + rInner.SetLine( ScHelperFunctions::GetBorderLine( aLine, rBorder.VerticalLine ), BOXINFO_LINE_VERT ); + rInner.SetValid( VALID_TOP, rBorder.IsTopLineValid ); + rInner.SetValid( VALID_BOTTOM, rBorder.IsBottomLineValid ); + rInner.SetValid( VALID_LEFT, rBorder.IsLeftLineValid ); + rInner.SetValid( VALID_RIGHT, rBorder.IsRightLineValid ); + rInner.SetValid( VALID_HORI, rBorder.IsHorizontalLineValid ); + rInner.SetValid( VALID_VERT, rBorder.IsVerticalLineValid ); + rInner.SetValid( VALID_DISTANCE, rBorder.IsDistanceValid ); + rInner.SetTable( TRUE ); +} + +void ScHelperFunctions::FillBorderLine( table::BorderLine& rStruct, const SvxBorderLine* pLine ) +{ + if (pLine) + { + rStruct.Color = pLine->GetColor().GetColor(); + rStruct.InnerLineWidth = (sal_Int16)TwipsToHMM( pLine->GetInWidth() ); + rStruct.OuterLineWidth = (sal_Int16)TwipsToHMM( pLine->GetOutWidth() ); + rStruct.LineDistance = (sal_Int16)TwipsToHMM( pLine->GetDistance() ); + } + else + rStruct.Color = rStruct.InnerLineWidth = + rStruct.OuterLineWidth = rStruct.LineDistance = 0; +} + +void ScHelperFunctions::FillTableBorder( table::TableBorder& rBorder, + const SvxBoxItem& rOuter, const SvxBoxInfoItem& rInner ) +{ + ScHelperFunctions::FillBorderLine( rBorder.TopLine, rOuter.GetTop() ); + ScHelperFunctions::FillBorderLine( rBorder.BottomLine, rOuter.GetBottom() ); + ScHelperFunctions::FillBorderLine( rBorder.LeftLine, rOuter.GetLeft() ); + ScHelperFunctions::FillBorderLine( rBorder.RightLine, rOuter.GetRight() ); + ScHelperFunctions::FillBorderLine( rBorder.HorizontalLine, rInner.GetHori() ); + ScHelperFunctions::FillBorderLine( rBorder.VerticalLine, rInner.GetVert() ); + + rBorder.Distance = rOuter.GetDistance(); + rBorder.IsTopLineValid = rInner.IsValid(VALID_TOP); + rBorder.IsBottomLineValid = rInner.IsValid(VALID_BOTTOM); + rBorder.IsLeftLineValid = rInner.IsValid(VALID_LEFT); + rBorder.IsRightLineValid = rInner.IsValid(VALID_RIGHT); + rBorder.IsHorizontalLineValid = rInner.IsValid(VALID_HORI); + rBorder.IsVerticalLineValid = rInner.IsValid(VALID_VERT); + rBorder.IsDistanceValid = rInner.IsValid(VALID_DISTANCE); +} + +//------------------------------------------------------------------------ + +//! lcl_ApplyBorder nach docfunc verschieben! + +void ScHelperFunctions::ApplyBorder( ScDocShell* pDocShell, const ScRangeList& rRanges, + const SvxBoxItem&, const SvxBoxInfoItem& ) +{ + ULONG nCount = rRanges.Count(); + ULONG i; + for (i=0; i<nCount; i++) + { + ScRange aRange = *rRanges.GetObject(i); + USHORT nTab = aRange.aStart.Tab(); + + ScMarkData aMark; + aMark.SetMarkArea( aRange ); + aMark.SelectTable( nTab, TRUE ); + } + + for (i=0; i<nCount; i++) + pDocShell->PostPaint( *rRanges.GetObject(i), PAINT_GRID, SC_PF_LINES | SC_PF_TESTMERGE ); + + pDocShell->SetDocumentModified(); +} + +//! move lcl_PutDataArray to docfunc? +//! merge loop with ScFunctionAccess::callFunction + +BOOL lcl_PutDataArray( ScDocShell& rDocShell, const ScRange& rRange, + const uno::Sequence< uno::Sequence<uno::Any> >& aData ) +{ +// BOOL bApi = TRUE; + + ScDocument* pDoc = rDocShell.GetDocument(); + USHORT nTab = rRange.aStart.Tab(); + USHORT nStartCol = rRange.aStart.Col(); + USHORT nStartRow = rRange.aStart.Row(); + USHORT nEndCol = rRange.aEnd.Col(); + USHORT nEndRow = rRange.aEnd.Row(); + + if ( !pDoc->IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) ) + { + //! error message + return FALSE; + } + + long nCols = 0; + long nRows = aData.getLength(); + const uno::Sequence<uno::Any>* pArray = aData.getConstArray(); + if ( nRows ) + nCols = pArray[0].getLength(); + + if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 ) + { + //! error message? + return FALSE; + } + + pDoc->DeleteAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, IDF_CONTENTS ); + + BOOL bError = FALSE; + USHORT nDocRow = nStartRow; + for (long nRow=0; nRow<nRows; nRow++) + { + const uno::Sequence<uno::Any>& rColSeq = pArray[nRow]; + if ( rColSeq.getLength() == nCols ) + { + USHORT nDocCol = nStartCol; + const uno::Any* pColArr = rColSeq.getConstArray(); + for (long nCol=0; nCol<nCols; nCol++) + { + const uno::Any& rElement = pColArr[nCol]; + uno::TypeClass eElemClass = rElement.getValueTypeClass(); + if ( eElemClass == uno::TypeClass_VOID ) + { + // void = "no value" + pDoc->SetError( nDocCol, nDocRow, nTab, NOVALUE ); + } + else if ( eElemClass == uno::TypeClass_BYTE || + eElemClass == uno::TypeClass_SHORT || + eElemClass == uno::TypeClass_UNSIGNED_SHORT || + eElemClass == uno::TypeClass_LONG || + eElemClass == uno::TypeClass_UNSIGNED_LONG || + eElemClass == uno::TypeClass_FLOAT || + eElemClass == uno::TypeClass_DOUBLE ) + { + // #87871# accept integer types because Basic passes a floating point + // variable as byte, short or long if it's an integer number. + double fVal; + rElement >>= fVal; + pDoc->SetValue( nDocCol, nDocRow, nTab, fVal ); + } + else if ( eElemClass == uno::TypeClass_STRING ) + { + ::rtl::OUString aUStr; + rElement >>= aUStr; + if ( aUStr.getLength() ) + pDoc->PutCell( nDocCol, nDocRow, nTab, new ScStringCell( aUStr ) ); + } + else + bError = TRUE; // invalid type + + ++nDocCol; + } + } + else + bError = TRUE; // wrong size + + ++nDocRow; + } + + BOOL bHeight = rDocShell.AdjustRowHeight( nStartRow, nEndRow, nTab ); + + if (!bHeight) + rDocShell.PostPaint( rRange, PAINT_GRID ); // AdjustRowHeight may have painted already + + rDocShell.SetDocumentModified(); + + return !bError; +} + +BOOL lcl_PutFormulaArray( ScDocShell& rDocShell, const ScRange& rRange, + const uno::Sequence< uno::Sequence< ::rtl::OUString> >& aData ) +{ +// BOOL bApi = TRUE; + + ScDocument* pDoc = rDocShell.GetDocument(); + USHORT nTab = rRange.aStart.Tab(); + USHORT nStartCol = rRange.aStart.Col(); + USHORT nStartRow = rRange.aStart.Row(); + USHORT nEndCol = rRange.aEnd.Col(); + USHORT nEndRow = rRange.aEnd.Row(); + + if ( !pDoc->IsBlockEditable( nTab, nStartCol,nStartRow, nEndCol,nEndRow ) ) + { + //! error message + return FALSE; + } + + long nCols = 0; + long nRows = aData.getLength(); + const uno::Sequence< ::rtl::OUString>* pArray = aData.getConstArray(); + if ( nRows ) + nCols = pArray[0].getLength(); + + if ( nCols != nEndCol-nStartCol+1 || nRows != nEndRow-nStartRow+1 ) + { + //! error message? + return FALSE; + } + + pDoc->DeleteAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, IDF_CONTENTS ); + + ScDocFunc aFunc( rDocShell ); // for InterpretEnglishString + + BOOL bError = FALSE; + USHORT nDocRow = nStartRow; + for (long nRow=0; nRow<nRows; nRow++) + { + const uno::Sequence< ::rtl::OUString>& rColSeq = pArray[nRow]; + if ( rColSeq.getLength() == nCols ) + { + USHORT nDocCol = nStartCol; + const ::rtl::OUString* pColArr = rColSeq.getConstArray(); + for (long nCol=0; nCol<nCols; nCol++) + { + String aText = pColArr[nCol]; + ScAddress aPos( nDocCol, nDocRow, nTab ); + ScBaseCell* pNewCell = aFunc.InterpretEnglishString( aPos, aText ); + pDoc->PutCell( aPos, pNewCell ); + + ++nDocCol; + } + } + else + bError = TRUE; // wrong size + + ++nDocRow; + } + + BOOL bHeight = rDocShell.AdjustRowHeight( nStartRow, nEndRow, nTab ); + + if (!bHeight) + rDocShell.PostPaint( rRange, PAINT_GRID ); // AdjustRowHeight may have painted already + + rDocShell.SetDocumentModified(); + + return !bError; +} + +// used in ScCellRangeObj::getFormulaArray and ScCellObj::GetInputString_Impl +String lcl_GetInputString( ScDocShell* pDocSh, const ScAddress& rPosition, BOOL bEnglish ) +{ + String aVal; + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + ScBaseCell* pCell = pDoc->GetCell( rPosition ); + if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE ) + { + CellType eType = pCell->GetCellType(); + if ( eType == CELLTYPE_FORMULA ) + { + ScFormulaCell* pForm = (ScFormulaCell*)pCell; + if (bEnglish) + pForm->GetEnglishFormula( aVal ); + else + pForm->GetFormula( aVal ); + } + else + { + SvNumberFormatter* pFormatter = bEnglish ? ScGlobal::GetEnglishFormatter() : + pDoc->GetFormatTable(); + // Since the English formatter was constructed with + // LANGUAGE_ENGLISH_US the "General" format has index key 0, + // we don't have to query. + sal_uInt32 nNumFmt = bEnglish ? + 0 : + pDoc->GetNumberFormat( rPosition ); + + if ( eType == CELLTYPE_EDIT ) + { + // GetString an der EditCell macht Leerzeichen aus Umbruechen, + // hier werden die Umbrueche aber gebraucht + const EditTextObject* pData = ((ScEditCell*)pCell)->GetData(); + if (pData) + { + EditEngine& rEngine = pDoc->GetEditEngine(); + rEngine.SetText( *pData ); + aVal = rEngine.GetText( LINEEND_LF ); + } + } + else + ScCellFormat::GetInputString( pCell, nNumFmt, aVal, *pFormatter ); + + // ggf. ein ' davorhaengen wie in ScTabViewShell::UpdateInputHandler + if ( eType == CELLTYPE_STRING || eType == CELLTYPE_EDIT ) + { + double fDummy; + sal_Bool bIsNumberFormat(pFormatter->IsNumberFormat(aVal, nNumFmt, fDummy)); + if ( bIsNumberFormat ) + aVal.Insert('\'',0); + else if ( aVal.Len() && aVal.GetChar(0) == '\'' ) + { + // if the string starts with a "'", add another one because setFormula + // strips one (like text input, except for "text" number formats) + if ( bEnglish || ( pFormatter->GetType(nNumFmt) != NUMBERFORMAT_TEXT ) ) + aVal.Insert('\'',0); + } + } + } + } + } + return aVal; +} + + +ScCellRangesBase::ScCellRangesBase(ScDocShell* pDocSh, const ScRange& rR) : + aPropSet(lcl_GetCellsPropertyMap()), + pDocShell( pDocSh ), + pValueListener( NULL ), + pCurrentFlat( NULL ), + pCurrentDeep( NULL ), + pCurrentDataSet( NULL ), + pMarkData( NULL ), + bChartColAsHdr( FALSE ), + bChartRowAsHdr( FALSE ), + bCursorOnly( FALSE ), + bValueChangePosted( FALSE ), + aValueListeners( 0 ) +{ + ScRange aCellRange = rR; + aCellRange.Justify(); + aRanges.Append( aCellRange ); + + if (pDocShell) // Null, wenn per createInstance erzeugt... + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScCellRangesBase::ScCellRangesBase(ScDocShell* pDocSh, const ScRangeList& rR) : + aPropSet(lcl_GetCellsPropertyMap()), + pDocShell( pDocSh ), + pValueListener( NULL ), + pCurrentFlat( NULL ), + pCurrentDeep( NULL ), + pCurrentDataSet( NULL ), + pMarkData( NULL ), + aRanges( rR ), + bChartColAsHdr( FALSE ), + bChartRowAsHdr( FALSE ), + bCursorOnly( FALSE ), + bValueChangePosted( FALSE ), + aValueListeners( 0 ) +{ + if (pDocShell) // Null, wenn per createInstance erzeugt... + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScCellRangesBase::~ScCellRangesBase() +{ + // #107294# call RemoveUnoObject first, so no notification can happen + // during ForgetCurrentAttrs + + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + + ForgetCurrentAttrs(); + + delete pValueListener; + + //! XChartDataChangeEventListener abmelden ?? + //! (ChartCollection haelt dann auch dieses Objekt fest!) +} + +void ScCellRangesBase::ForgetCurrentAttrs() +{ + delete pCurrentFlat; + delete pCurrentDeep; + delete pCurrentDataSet; + delete pMarkData; + pCurrentFlat = NULL; + pCurrentDeep = NULL; + pCurrentDataSet = NULL; + pMarkData = NULL; +} + +const ScPatternAttr* ScCellRangesBase::GetCurrentAttrsFlat() +{ + // get and cache direct cell attributes for this object's range + + if ( !pCurrentFlat && pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pCurrentFlat = pDoc->CreateSelectionPattern( *GetMarkData(), FALSE ); + } + return pCurrentFlat; +} + +const ScPatternAttr* ScCellRangesBase::GetCurrentAttrsDeep() +{ + // get and cache cell attributes (incl. styles) for this object's range + + if ( !pCurrentDeep && pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pCurrentDeep = pDoc->CreateSelectionPattern( *GetMarkData(), TRUE ); + } + return pCurrentDeep; +} + +SfxItemSet* ScCellRangesBase::GetCurrentDataSet() +{ + if(!pCurrentDataSet) + { + const ScPatternAttr* pPattern = GetCurrentAttrsDeep(); + if ( pPattern ) + { + // Dontcare durch Default ersetzen, damit man immer eine Reflection hat + pCurrentDataSet = new SfxItemSet( pPattern->GetItemSet() ); + pCurrentDataSet->ClearInvalidItems(); + } + } + return pCurrentDataSet; +} + +const ScMarkData* ScCellRangesBase::GetMarkData() +{ + if (!pMarkData) + { + pMarkData = new ScMarkData(); + pMarkData->MarkFromRangeList( aRanges, FALSE ); + } + return pMarkData; +} + +void ScCellRangesBase::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; + + if ( aRanges.UpdateReference( rRef.GetMode(), pDocShell->GetDocument(), rRef.GetRange(), + rRef.GetDx(), rRef.GetDy(), rRef.GetDz() ) ) + { + if (rRef.GetMode() == URM_INSDEL && + aRanges.Count() == 1 && + ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this )) + { + // #101755#; the range size of a sheet does not change + ScRange* pR = aRanges.First(); + if (pR) + { + pR->aStart.SetCol(0); + pR->aStart.SetRow(0); + pR->aEnd.SetCol(MAXCOL); + pR->aEnd.SetRow(MAXROW); + } + } + RefChanged(); + } + } + else if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + { + ForgetCurrentAttrs(); + pDocShell = NULL; // invalid + } + else if ( nId == SFX_HINT_DATACHANGED ) + { + // document content changed -> forget cached attributes + ForgetCurrentAttrs(); + } + } +} + +void ScCellRangesBase::RefChanged() +{ + //! XChartDataChangeEventListener anpassen + + //! Test !!! + + if ( pValueListener && aValueListeners.Count() != 0 ) + { + pValueListener->EndListeningAll(); + + ScDocument* pDoc = pDocShell->GetDocument(); + ULONG nCount = aRanges.Count(); + for (ULONG i=0; i<nCount; i++) + pDoc->StartListeningArea( *aRanges.GetObject(i), pValueListener ); + } + //! Test !!! + + ForgetCurrentAttrs(); +} + +ScDocument* ScCellRangesBase::GetDocument() const +{ + if (pDocShell) + return pDocShell->GetDocument(); + else + return NULL; +} + +void ScCellRangesBase::InitInsertRange(ScDocShell* pDocSh, const ScRange& rR) +{ + if ( !pDocShell && pDocSh ) + { + pDocShell = pDocSh; + + ScRange aCellRange = rR; + aCellRange.Justify(); + aRanges.RemoveAll(); + aRanges.Append( aCellRange ); + + pDocShell->GetDocument()->AddUnoObject(*this); + + RefChanged(); // Range im Range-Objekt anpassen + } +} + +void ScCellRangesBase::AddRange(const ScRange& rRange, const sal_Bool bMergeRanges) +{ + if (bMergeRanges) + aRanges.Join(rRange); + else + aRanges.Append(rRange); + RefChanged(); +} + +void ScCellRangesBase::SetNewRange(const ScRange& rNew) +{ + ScRange aCellRange = rNew; + aCellRange.Justify(); + + aRanges.RemoveAll(); + aRanges.Append( aCellRange ); + RefChanged(); +} + +void ScCellRangesBase::SetNewRanges(const ScRangeList& rNew) +{ + aRanges = rNew; + RefChanged(); +} + +uno::Any SAL_CALL ScCellRangesBase::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( beans::XPropertySet ) + SC_QUERYINTERFACE( beans::XMultiPropertySet ) + SC_QUERYINTERFACE( beans::XPropertyState ) + SC_QUERYINTERFACE( sheet::XSheetOperation ) + SC_QUERYINTERFACE( chart::XChartDataArray ) + SC_QUERYINTERFACE( chart::XChartData ) + SC_QUERYINTERFACE( util::XIndent ) + SC_QUERYINTERFACE( sheet::XCellRangesQuery ) + SC_QUERYINTERFACE( sheet::XFormulaQuery ) + SC_QUERYINTERFACE( util::XReplaceable ) + SC_QUERYINTERFACE( util::XSearchable ) + SC_QUERYINTERFACE( lang::XServiceInfo ) + SC_QUERYINTERFACE( lang::XUnoTunnel ) + SC_QUERYINTERFACE( lang::XTypeProvider ) + + return OWeakObject::queryInterface( rType ); +} + +void SAL_CALL ScCellRangesBase::acquire() throw() +{ + OWeakObject::acquire(); +} + +void SAL_CALL ScCellRangesBase::release() throw() +{ + OWeakObject::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScCellRangesBase::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + aTypes.realloc(12); + uno::Type* pPtr = aTypes.getArray(); + pPtr[0] = getCppuType((const uno::Reference<beans::XPropertySet>*)0); + pPtr[1] = getCppuType((const uno::Reference<beans::XMultiPropertySet>*)0); + pPtr[2] = getCppuType((const uno::Reference<beans::XPropertyState>*)0); + pPtr[3] = getCppuType((const uno::Reference<sheet::XSheetOperation>*)0); + pPtr[4] = getCppuType((const uno::Reference<chart::XChartDataArray>*)0); + pPtr[5] = getCppuType((const uno::Reference<util::XIndent>*)0); + pPtr[6] = getCppuType((const uno::Reference<sheet::XCellRangesQuery>*)0); + pPtr[7] = getCppuType((const uno::Reference<sheet::XFormulaQuery>*)0); + pPtr[8] = getCppuType((const uno::Reference<util::XReplaceable>*)0); + pPtr[9] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0); + pPtr[10] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0); + pPtr[11]= getCppuType((const uno::Reference<lang::XTypeProvider>*)0); + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScCellRangesBase::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + + +void ScCellRangesBase::PaintRanges_Impl( USHORT nPart ) +{ + ULONG nCount = aRanges.Count(); + for (ULONG i=0; i<nCount; i++) + pDocShell->PostPaint( *aRanges.GetObject(i), nPart ); +} + +// XSheetOperation + +double SAL_CALL ScCellRangesBase::computeFunction( sheet::GeneralFunction nFunction ) + throw(uno::Exception, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScMarkData aMark(*GetMarkData()); + aMark.MarkToSimple(); + if (!aMark.IsMarked()) + aMark.SetMarkNegative(TRUE); // um Dummy Position angeben zu koennen + + ScAddress aDummy; // wenn nicht Marked, ignoriert wegen Negative + double fVal; + ScSubTotalFunc eFunc = lcl_SummaryToSubTotal( nFunction ); + ScDocument* pDoc = pDocShell->GetDocument(); + if ( !pDoc->GetSelectionFunction( eFunc, aDummy, aMark, fVal ) ) + { + throw uno::RuntimeException(); //! own exception? + } + + return fVal; +} + +void SAL_CALL ScCellRangesBase::clearContents( sal_Int32 nContentFlags ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( aRanges.Count() ) + { + // only for clearContents: EDITATTR is only used if no contents are deleted + USHORT nDelFlags = nContentFlags & IDF_ALL; + if ( ( nContentFlags & IDF_EDITATTR ) && ( nContentFlags & IDF_CONTENTS ) == 0 ) + nDelFlags |= IDF_EDITATTR; + + ScDocFunc aFunc(*pDocShell); + aFunc.DeleteContents( *GetMarkData(), nDelFlags, TRUE, TRUE ); + } + // sonst ist nichts zu tun +} + +// XPropertyState + +const SfxItemPropertyMap* ScCellRangesBase::GetItemPropertyMap() +{ + return lcl_GetCellsPropertyMap(); +} + +const SfxItemPropertyMap* lcl_GetPropertyWhich( const SfxItemPropertyMap* pMap, const ::rtl::OUString& rName, + USHORT& rItemWhich ) +{ + // Which-ID des betroffenen Items, auch wenn das Item die Property + // nicht alleine behandeln kann + + const SfxItemPropertyMap* pRetMap = SfxItemPropertyMap::GetByName( pMap, rName ); + if ( pRetMap ) + { + if ( IsScItemWid( pRetMap->nWID ) ) + rItemWhich = pRetMap->nWID; + else + switch ( pRetMap->nWID ) + { + case SC_WID_UNO_TBLBORD: + rItemWhich = ATTR_BORDER; + break; + case SC_WID_UNO_CONDFMT: + case SC_WID_UNO_CONDLOC: + case SC_WID_UNO_CONDXML: + rItemWhich = ATTR_CONDITIONAL; + break; + case SC_WID_UNO_VALIDAT: + case SC_WID_UNO_VALILOC: + case SC_WID_UNO_VALIXML: + rItemWhich = ATTR_VALIDDATA; + break; + } + } + + return pRetMap; +} + +beans::PropertyState ScCellRangesBase::GetOnePropertyState( USHORT nItemWhich, const SfxItemPropertyMap* pMap ) +{ + beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE; + if ( nItemWhich ) // item wid (from map or special case) + { + // For items that contain several properties (like background), + // "ambiguous" is returned too often here + + // for PropertyState, don't look at styles + const ScPatternAttr* pPattern = GetCurrentAttrsFlat(); + if ( pPattern ) + { + SfxItemState eState = pPattern->GetItemSet().GetItemState( nItemWhich, FALSE ); + + // if no rotate value is set, look at orientation + //! also for a fixed value of 0 (in case orientation is ambiguous)? + if ( nItemWhich == ATTR_ROTATE_VALUE && eState == SFX_ITEM_DEFAULT ) + eState = pPattern->GetItemSet().GetItemState( ATTR_ORIENTATION, FALSE ); + + if ( nItemWhich == ATTR_VALUE_FORMAT && eState == SFX_ITEM_DEFAULT ) + eState = pPattern->GetItemSet().GetItemState( ATTR_LANGUAGE_FORMAT, FALSE ); + + if ( eState == SFX_ITEM_SET ) + eRet = beans::PropertyState_DIRECT_VALUE; + else if ( eState == SFX_ITEM_DEFAULT ) + eRet = beans::PropertyState_DEFAULT_VALUE; + else if ( eState == SFX_ITEM_DONTCARE ) + eRet = beans::PropertyState_AMBIGUOUS_VALUE; + else + OSL_FAIL("unbekannter ItemState"); + } + } + else if ( pMap ) + { + if ( pMap->nWID == SC_WID_UNO_CHCOLHDR || pMap->nWID == SC_WID_UNO_CHROWHDR ) + eRet = beans::PropertyState_DIRECT_VALUE; + else if ( pMap->nWID == SC_WID_UNO_CELLSTYL ) + { + // a style is always set, there's no default state + const ScStyleSheet* pStyle = pDocShell->GetDocument()->GetSelectionStyle(*GetMarkData()); + if (pStyle) + eRet = beans::PropertyState_DIRECT_VALUE; + else + eRet = beans::PropertyState_AMBIGUOUS_VALUE; + } + else if ( pMap->nWID == SC_WID_UNO_NUMRULES ) + eRet = beans::PropertyState_DEFAULT_VALUE; // numbering rules are always default + } + return eRet; +} + +beans::PropertyState SAL_CALL ScCellRangesBase::getPropertyState( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( aRanges.Count() == 0 ) + throw uno::RuntimeException(); + + const SfxItemPropertyMap* pMap = GetItemPropertyMap(); // from derived class + USHORT nItemWhich = 0; + pMap = lcl_GetPropertyWhich( pMap, aPropertyName, nItemWhich ); + return GetOnePropertyState( nItemWhich, pMap ); +} + +uno::Sequence<beans::PropertyState> SAL_CALL ScCellRangesBase::getPropertyStates( + const uno::Sequence< ::rtl::OUString>& aPropertyNames ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap(); // from derived class + + aPropertyNames.getConstArray(); + uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength()); + beans::PropertyState* pStates = aRet.getArray(); + const SfxItemPropertyMap* pMap = pPropertyMap; + for(INT32 i = 0; i < aPropertyNames.getLength(); i++) + { + USHORT nItemWhich = 0; + pMap = lcl_GetPropertyWhich(pMap, aPropertyNames[i], nItemWhich); + pStates[i] = GetOnePropertyState(nItemWhich, pMap); + if (!pMap) + pMap = pPropertyMap; + else + pMap++; + } + return aRet; +} + +void SAL_CALL ScCellRangesBase::setPropertyToDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + const SfxItemPropertyMap* pMap = lcl_GetCellsPropertyMap(); + USHORT nItemWhich = 0; + pMap = lcl_GetPropertyWhich(pMap, aPropertyName, nItemWhich); + + if ( nItemWhich ) // item wid (from map or special case) + { + if ( aRanges.Count() ) // leer = nichts zu tun + { + pDocShell->GetDocument(); + ScDocFunc aFunc(*pDocShell); + + //! Bei Items, die mehrere Properties enthalten (z.B. Hintergrund) + //! wird hier zuviel zurueckgesetzt + + //! for ATTR_ROTATE_VALUE, also reset ATTR_ORIENTATION? + + USHORT aWIDs[3]; + aWIDs[0] = nItemWhich; + if ( nItemWhich == ATTR_VALUE_FORMAT ) + { + aWIDs[1] = ATTR_LANGUAGE_FORMAT; // #67847# language for number formats + aWIDs[2] = 0; + } + else + aWIDs[1] = 0; + aFunc.ClearItems( *GetMarkData(), aWIDs, TRUE ); + } + } + else if ( pMap ) + { + if ( pMap->nWID == SC_WID_UNO_CHCOLHDR ) + bChartColAsHdr = FALSE; + else if ( pMap->nWID == SC_WID_UNO_CHROWHDR ) + bChartRowAsHdr = FALSE; + else if ( pMap->nWID == SC_WID_UNO_CELLSTYL ) + { + ScDocFunc aFunc(*pDocShell); + aFunc.ApplyStyle( *GetMarkData(), ScGlobal::GetRscString(STR_STYLENAME_STANDARD), TRUE, TRUE ); + } + } + } +} + +uno::Any SAL_CALL ScCellRangesBase::getPropertyDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + //! mit getPropertyValue zusammenfassen + + SolarMutexGuard aGuard; + uno::Any aAny; + + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetCellsPropertyMap(), aPropertyName ); + if ( pMap ) + { + if ( IsScItemWid( pMap->nWID ) ) + { + const ScPatternAttr* pPattern = pDoc->GetDefPattern(); + if ( pPattern ) + { + const SfxItemSet& rSet = pPattern->GetItemSet(); + + switch ( pMap->nWID ) // fuer Item-Spezial-Behandlungen + { + case ATTR_VALUE_FORMAT: + // default has no language set + aAny <<= (sal_Int32)( ((const SfxUInt32Item&)rSet.Get(pMap->nWID)).GetValue() ); + break; + case ATTR_INDENT: + aAny <<= (sal_Int16)( TwipsToHMM(((const SfxUInt16Item&) + rSet.Get(pMap->nWID)).GetValue()) ); + break; + default: + aPropSet.getPropertyValue(aPropertyName, rSet, aAny); + } + } + } + else + switch ( pMap->nWID ) + { + case SC_WID_UNO_CHCOLHDR: + case SC_WID_UNO_CHROWHDR: + ScUnoHelpFunctions::SetBoolInAny( aAny, FALSE ); + break; + case SC_WID_UNO_CELLSTYL: + aAny <<= ::rtl::OUString( ScStyleNameConversion::DisplayToProgrammaticName( + ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA ) ); + break; + case SC_WID_UNO_TBLBORD: + { + const ScPatternAttr* pPattern = pDoc->GetDefPattern(); + if ( pPattern ) + { + table::TableBorder aBorder; + ScHelperFunctions::FillTableBorder( aBorder, + (const SvxBoxItem&)pPattern->GetItem(ATTR_BORDER), + (const SvxBoxInfoItem&)pPattern->GetItem(ATTR_BORDER_INNER) ); + aAny <<= aBorder; + } + } + break; + case SC_WID_UNO_CONDFMT: + case SC_WID_UNO_CONDLOC: + case SC_WID_UNO_CONDXML: + { + BOOL bEnglish = ( pMap->nWID != SC_WID_UNO_CONDLOC ); + BOOL bXML = ( pMap->nWID == SC_WID_UNO_CONDXML ); + + uno::Reference<sheet::XSheetConditionalEntries> xObj = + new ScTableConditionalFormat( pDoc, 0, bEnglish, bXML ); + aAny <<= xObj; + } + break; + case SC_WID_UNO_VALIDAT: + case SC_WID_UNO_VALILOC: + case SC_WID_UNO_VALIXML: + { + BOOL bEnglish = ( pMap->nWID != SC_WID_UNO_VALILOC ); + BOOL bXML = ( pMap->nWID == SC_WID_UNO_VALIXML ); + + uno::Reference<beans::XPropertySet> xObj = + new ScTableValidationObj( pDoc, 0, bEnglish, bXML ); + aAny <<= xObj; + } + break; + case SC_WID_UNO_NUMRULES: + { + uno::Reference<container::XIndexReplace> xObj = ScStyleObj::CreateEmptyNumberingRules(); + aAny <<= xObj; + } + break; + } + } + } + + return aAny; +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellRangesBase::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + + +void lcl_SetCellProperty( const SfxItemPropertyMap& rMap, const uno::Any& rValue, + ScPatternAttr& rPattern, ScDocument* pDoc, + USHORT& rFirstItemId, USHORT& rSecondItemId ) +{ + rFirstItemId = rMap.nWID; + rSecondItemId = 0; + + SfxItemSet& rSet = rPattern.GetItemSet(); + switch ( rMap.nWID ) + { + case ATTR_VALUE_FORMAT: + { + // #67847# language for number formats + SvNumberFormatter* pFormatter = pDoc->GetFormatTable(); + ULONG nOldFormat = ((const SfxUInt32Item&)rSet.Get( ATTR_VALUE_FORMAT )).GetValue(); + LanguageType eOldLang = ((const SvxLanguageItem&)rSet.Get( ATTR_LANGUAGE_FORMAT )).GetLanguage(); + nOldFormat = pFormatter->GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang ); + + sal_Int32 nIntVal = 0; + if ( rValue >>= nIntVal ) + { + ULONG nNewFormat = (ULONG)nIntVal; + rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) ); + + const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat ); + LanguageType eNewLang = + pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW; + if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW ) + { + rSet.Put( SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) ); + + // #40606# if only language is changed, + // don't touch number format attribute + ULONG nNewMod = nNewFormat % SV_COUNTRY_LANGUAGE_OFFSET; + if ( nNewMod == ( nOldFormat % SV_COUNTRY_LANGUAGE_OFFSET ) && + nNewMod <= SV_MAX_ANZ_STANDARD_FORMATE ) + { + rFirstItemId = 0; // don't use ATTR_VALUE_FORMAT value + } + + rSecondItemId = ATTR_LANGUAGE_FORMAT; + } + } + } + break; + case ATTR_INDENT: + { + sal_Int16 nIntVal = 0; + if ( rValue >>= nIntVal ) + rSet.Put( SfxUInt16Item( rMap.nWID, (USHORT)HMMToTwips(nIntVal) ) ); + } + break; + case ATTR_ROTATE_VALUE: + { + sal_Int32 nRotVal = 0; + if ( rValue >>= nRotVal ) + { + // stored value is always between 0 and 360 deg. + nRotVal %= 36000; + if ( nRotVal < 0 ) + nRotVal += 36000; + + // always set rotation value and orientation + + SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD; + BOOL bSetOrient = TRUE; + + SvxCellOrientation eOld = (SvxCellOrientation) + ((const SvxOrientationItem&)rSet.Get(ATTR_ORIENTATION)). + GetValue(); + + // #103272#; don't overwrite stacked orientation + if ( eOld == SVX_ORIENTATION_STACKED ) + bSetOrient = FALSE; + else if ( nRotVal == 9000 ) + eOrient = SVX_ORIENTATION_BOTTOMTOP; + else if ( nRotVal == 27000 ) + eOrient = SVX_ORIENTATION_TOPBOTTOM; + + rSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, nRotVal ) ); + if (bSetOrient) + { + rSet.Put( SvxOrientationItem( eOrient, ATTR_ORIENTATION ) ); + rSecondItemId = ATTR_ORIENTATION; + } + } + } + break; + default: + { + SfxItemPropertySet aPropSet( lcl_GetCellsPropertyMap() ); + aPropSet.setPropertyValue(rMap, rValue, rSet); + } + } +} + +void SAL_CALL ScCellRangesBase::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !pDocShell || aRanges.Count() == 0 ) + throw uno::RuntimeException(); + + const SfxItemPropertyMap* pMap = GetItemPropertyMap(); // from derived class + pMap = SfxItemPropertyMap::GetByName( pMap, aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + SetOnePropertyValue( pMap, aValue ); +} + +void ScCellRangesBase::SetOnePropertyValue( const SfxItemPropertyMap* pMap, const uno::Any& aValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + if ( pMap ) + { + if ( IsScItemWid( pMap->nWID ) ) + { + if ( aRanges.Count() ) // leer = nichts zu tun + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDocFunc aFunc(*pDocShell); + + // Fuer Teile von zusammengesetzten Items mit mehreren Properties (z.B. Hintergrund) + // muss vorher das alte Item aus dem Dokument geholt werden + //! Das kann hier aber nicht erkannt werden + //! -> eigenes Flag im PropertyMap-Eintrag, oder was ??? + //! Item direkt von einzelner Position im Bereich holen? + // ClearInvalidItems, damit auf jeden Fall ein Item vom richtigen Typ da ist + + ScPatternAttr aPattern( *GetCurrentAttrsDeep() ); + SfxItemSet& rSet = aPattern.GetItemSet(); + rSet.ClearInvalidItems(); + + USHORT nFirstItem, nSecondItem; + lcl_SetCellProperty( *pMap, aValue, aPattern, pDoc, nFirstItem, nSecondItem ); + + for (USHORT nWhich = ATTR_PATTERN_START; nWhich <= ATTR_PATTERN_END; nWhich++) + if ( nWhich != nFirstItem && nWhich != nSecondItem ) + rSet.ClearItem(nWhich); + + aFunc.ApplyAttributes( *GetMarkData(), aPattern, TRUE, TRUE ); + } + } + else // implemented here + switch ( pMap->nWID ) + { + case SC_WID_UNO_CHCOLHDR: + // chart header flags are set for this object, not stored with document + bChartColAsHdr = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + break; + case SC_WID_UNO_CHROWHDR: + bChartRowAsHdr = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + break; + case SC_WID_UNO_CELLSTYL: + { + ::rtl::OUString aStrVal; + aValue >>= aStrVal; + String aString = ScStyleNameConversion::ProgrammaticToDisplayName( + aStrVal, SFX_STYLE_FAMILY_PARA ); + ScDocFunc aFunc(*pDocShell); + aFunc.ApplyStyle( *GetMarkData(), aString, TRUE, TRUE ); + } + break; + case SC_WID_UNO_TBLBORD: + { + table::TableBorder aBorder; + if ( aRanges.Count() && ( aValue >>= aBorder ) ) // empty = nothing to do + { + SvxBoxItem aOuter(ATTR_BORDER); + SvxBoxInfoItem aInner(ATTR_BORDER_INNER); + ScHelperFunctions::FillBoxItems( aOuter, aInner, aBorder ); + + ScHelperFunctions::ApplyBorder( pDocShell, aRanges, aOuter, aInner ); //! docfunc + } + } + break; + case SC_WID_UNO_CONDFMT: + case SC_WID_UNO_CONDLOC: + case SC_WID_UNO_CONDXML: + { + BOOL bEnglish = ( pMap->nWID != SC_WID_UNO_CONDLOC ); + BOOL bXML = ( pMap->nWID == SC_WID_UNO_CONDXML ); + + uno::Reference<sheet::XSheetConditionalEntries> xInterface; + if ( aRanges.Count() && ( aValue >>= xInterface ) ) // leer = nichts zu tun + { + ScTableConditionalFormat* pFormat = + ScTableConditionalFormat::getImplementation( xInterface ); + if (pFormat) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + ScConditionalFormat aNew( 0, pDoc ); // Index wird beim Einfuegen gesetzt + pFormat->FillFormat( aNew, pDoc, bEnglish, bXML ); + ULONG nIndex = pDoc->AddCondFormat( aNew ); + + ScDocFunc aFunc(*pDocShell); + + ScPatternAttr aPattern( pDoc->GetPool() ); + aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_CONDITIONAL, nIndex ) ); + aFunc.ApplyAttributes( *GetMarkData(), aPattern, TRUE, TRUE ); + } + } + } + break; + case SC_WID_UNO_VALIDAT: + case SC_WID_UNO_VALILOC: + case SC_WID_UNO_VALIXML: + { + BOOL bEnglish = ( pMap->nWID != SC_WID_UNO_VALILOC ); + BOOL bXML = ( pMap->nWID == SC_WID_UNO_VALIXML ); + + uno::Reference<beans::XPropertySet> xInterface; + if ( aRanges.Count() && ( aValue >>= xInterface ) ) // leer = nichts zu tun + { + ScTableValidationObj* pValidObj = + ScTableValidationObj::getImplementation( xInterface ); + if (pValidObj) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + ScValidationData* pNewData = + pValidObj->CreateValidationData( pDoc, bEnglish, bXML ); + ULONG nIndex = pDoc->AddValidationEntry( *pNewData ); + delete pNewData; + + ScDocFunc aFunc(*pDocShell); + + ScPatternAttr aPattern( pDoc->GetPool() ); + aPattern.GetItemSet().Put( SfxUInt32Item( ATTR_VALIDDATA, nIndex ) ); + aFunc.ApplyAttributes( *GetMarkData(), aPattern, TRUE, TRUE ); + } + } + } + break; + // SC_WID_UNO_NUMRULES is ignored... + } + } +} + +uno::Any SAL_CALL ScCellRangesBase::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !pDocShell || aRanges.Count() == 0 ) + throw uno::RuntimeException(); + + const SfxItemPropertyMap* pMap = GetItemPropertyMap(); // from derived class + pMap = SfxItemPropertyMap::GetByName( pMap, aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + uno::Any aAny; + GetOnePropertyValue( pMap, aAny ); + return aAny; +} + +void ScCellRangesBase::GetOnePropertyValue( const SfxItemPropertyMap* pMap, + uno::Any& rAny ) + throw(uno::RuntimeException) +{ + if ( pMap ) + { + if ( IsScItemWid( pMap->nWID ) ) + { + SfxItemSet* pDataSet = GetCurrentDataSet(); + if ( pDataSet ) + { + switch ( pMap->nWID ) // fuer Item-Spezial-Behandlungen + { + case ATTR_VALUE_FORMAT: + { + ScDocument* pDoc = pDocShell->GetDocument(); + ULONG nOldFormat = ((const SfxUInt32Item&) + pDataSet->Get( ATTR_VALUE_FORMAT )).GetValue(); + LanguageType eOldLang = ((const SvxLanguageItem&) + pDataSet->Get( ATTR_LANGUAGE_FORMAT )).GetLanguage(); + nOldFormat = pDoc->GetFormatTable()-> + GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang ); + rAny <<= (sal_Int32)( nOldFormat ); + } + break; + case ATTR_INDENT: + rAny <<= (sal_Int16)( TwipsToHMM(((const SfxUInt16Item&) + pDataSet->Get(pMap->nWID)).GetValue()) ); + break; + case ATTR_ROTATE_VALUE: + { + // if value is 0 and orientation topbottom or bottomtop, + // adjust value + + sal_Int32 nRotVal = ((const SfxInt32Item&) + pDataSet->Get(ATTR_ROTATE_VALUE)).GetValue(); + if ( nRotVal == 0 ) + { + SvxCellOrientation eOrient = (SvxCellOrientation) + ((const SvxOrientationItem&)pDataSet->Get(ATTR_ORIENTATION)). + GetValue(); + if ( eOrient == SVX_ORIENTATION_BOTTOMTOP ) + nRotVal = 9000; + else if ( eOrient == SVX_ORIENTATION_TOPBOTTOM ) + nRotVal = 27000; + } + rAny <<= nRotVal; + } + break; + default: + aPropSet.getPropertyValue(*pMap, *pDataSet, rAny); + } + } + } + else // implemented here + switch ( pMap->nWID ) + { + case SC_WID_UNO_CHCOLHDR: + ScUnoHelpFunctions::SetBoolInAny( rAny, bChartColAsHdr ); + break; + case SC_WID_UNO_CHROWHDR: + ScUnoHelpFunctions::SetBoolInAny( rAny, bChartRowAsHdr ); + break; + case SC_WID_UNO_CELLSTYL: + { + String aStyleName; + const ScStyleSheet* pStyle = pDocShell->GetDocument()->GetSelectionStyle(*GetMarkData()); + if (pStyle) + aStyleName = pStyle->GetName(); + rAny <<= ::rtl::OUString( ScStyleNameConversion::DisplayToProgrammaticName( + aStyleName, SFX_STYLE_FAMILY_PARA ) ); + } + break; + case SC_WID_UNO_TBLBORD: + { + //! loop throgh all ranges + const ScRange* pFirst = aRanges.GetObject(0); + if (pFirst) + { + SvxBoxItem aOuter(ATTR_BORDER); + SvxBoxInfoItem aInner(ATTR_BORDER_INNER); + + ScDocument* pDoc = pDocShell->GetDocument(); + ScMarkData aMark; + aMark.SetMarkArea( *pFirst ); + aMark.SelectTable( pFirst->aStart.Tab(), TRUE ); + pDoc->GetSelectionFrame( aMark, aOuter, aInner ); + + table::TableBorder aBorder; + ScHelperFunctions::FillTableBorder( aBorder, aOuter, aInner ); + rAny <<= aBorder; + } + } + break; + case SC_WID_UNO_CONDFMT: + case SC_WID_UNO_CONDLOC: + case SC_WID_UNO_CONDXML: + { + BOOL bEnglish = ( pMap->nWID != SC_WID_UNO_CONDLOC ); + BOOL bXML = ( pMap->nWID == SC_WID_UNO_CONDXML ); + + const ScPatternAttr* pPattern = GetCurrentAttrsDeep(); + if ( pPattern ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ULONG nIndex = ((const SfxUInt32Item&) + pPattern->GetItem(ATTR_CONDITIONAL)).GetValue(); + uno::Reference<sheet::XSheetConditionalEntries> xObj = + new ScTableConditionalFormat( pDoc, nIndex, bEnglish, bXML ); + rAny <<= xObj; + } + } + break; + case SC_WID_UNO_VALIDAT: + case SC_WID_UNO_VALILOC: + case SC_WID_UNO_VALIXML: + { + BOOL bEnglish = ( pMap->nWID != SC_WID_UNO_VALILOC ); + BOOL bXML = ( pMap->nWID == SC_WID_UNO_VALIXML ); + + const ScPatternAttr* pPattern = GetCurrentAttrsDeep(); + if ( pPattern ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ULONG nIndex = ((const SfxUInt32Item&) + pPattern->GetItem(ATTR_VALIDDATA)).GetValue(); + uno::Reference<beans::XPropertySet> xObj = + new ScTableValidationObj( pDoc, nIndex, bEnglish, bXML ); + rAny <<= xObj; + } + } + break; + case SC_WID_UNO_NUMRULES: + { + // always return empty numbering rules object + uno::Reference<container::XIndexReplace> xObj = ScStyleObj::CreateEmptyNumberingRules(); + rAny <<= xObj; + } + break; + } + } +} + +void SAL_CALL ScCellRangesBase::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, + const uno::Reference<beans::XPropertyChangeListener>& aListener) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( aRanges.Count() == 0 ) + throw uno::RuntimeException(); + + //! Test !!!!! + if (String(aPropertyName).EqualsAscii( "Test" )) + { + uno::Reference<beans::XPropertyChangeListener> *pObj = + new uno::Reference<beans::XPropertyChangeListener>( aListener ); + aValueListeners.Insert( pObj, aValueListeners.Count() ); + + if ( aValueListeners.Count() == 1 ) + { + if (!pValueListener) + pValueListener = new ScLinkListener( LINK( this, ScCellRangesBase, ValueListenerHdl ) ); + + ScDocument* pDoc = pDocShell->GetDocument(); + ULONG nCount = aRanges.Count(); + for (ULONG i=0; i<nCount; i++) + pDoc->StartListeningArea( *aRanges.GetObject(i), pValueListener ); + + acquire(); // nicht verlieren (eine Ref fuer alle Listener) + } + + return; + } + //! Test !!!!! + + OSL_FAIL("not implemented"); +} + +void SAL_CALL ScCellRangesBase::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, + const uno::Reference<beans::XPropertyChangeListener>& aListener) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( aRanges.Count() == 0 ) + throw uno::RuntimeException(); + + //! Test !!!!! + if (String(aPropertyName).EqualsAscii( "Test" )) + { + acquire(); // falls fuer Listener die letzte Ref existiert - wird unten freigegeben + + USHORT nCount = aValueListeners.Count(); + for ( USHORT n=nCount; n--; ) + { + uno::Reference<beans::XPropertyChangeListener> *pObj = aValueListeners[n]; + if ( *pObj == aListener ) + { + aValueListeners.DeleteAndDestroy( n ); + + if ( aValueListeners.Count() == 0 ) + { + if (pValueListener) + pValueListener->EndListeningAll(); + + release(); // Listener-Ref freigeben + } + + break; + } + } + + release(); // damit kann dieses Objekt geloescht werden + return; + } + //! Test !!!!! + + OSL_FAIL("not implemented"); +} + +void SAL_CALL ScCellRangesBase::addVetoableChangeListener( const ::rtl::OUString&, + const uno::Reference<beans::XVetoableChangeListener>&) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +void SAL_CALL ScCellRangesBase::removeVetoableChangeListener( const ::rtl::OUString&, + const uno::Reference<beans::XVetoableChangeListener>&) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +// XMultiPropertySet + +void SAL_CALL ScCellRangesBase::setPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, + const uno::Sequence< uno::Any >& aValues ) + throw (beans::PropertyVetoException, + lang::IllegalArgumentException, + lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap(); // from derived class + + sal_Int32 nCount(aPropertyNames.getLength()); + sal_Int32 nValues(aValues.getLength()); + if (nCount != nValues) + throw lang::IllegalArgumentException(); + + if ( pDocShell && nCount ) + { + SfxItemPropertySet aLclPropSet( pPropertyMap ); + + ScDocument* pDoc = pDocShell->GetDocument(); + ScPatternAttr* pOldPattern = NULL; + ScPatternAttr* pNewPattern = NULL; + + const ::rtl::OUString* pNames = aPropertyNames.getConstArray(); + const uno::Any* pValues = aValues.getConstArray(); + const SfxItemPropertyMap* pMap = pPropertyMap; + for(sal_Int32 i = 0; i < nCount; i++) + { + pMap = SfxItemPropertyMap::GetByName( pPropertyMap, pNames[i] ); + if ( pMap ) + { + if ( IsScItemWid( pMap->nWID ) ) // can be handled by SfxItemPropertySet + { + if ( !pOldPattern ) + { + pOldPattern = new ScPatternAttr( *GetCurrentAttrsDeep() ); + pOldPattern->GetItemSet().ClearInvalidItems(); + pNewPattern = new ScPatternAttr( pDoc->GetPool() ); + } + + // collect items in pNewPattern, apply with one call after the loop + + USHORT nFirstItem, nSecondItem; + lcl_SetCellProperty( *pMap, pValues[i], *pOldPattern, pDoc, nFirstItem, nSecondItem ); + + // put only affected items into new set + if ( nFirstItem ) + pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nFirstItem ) ); + if ( nSecondItem ) + pNewPattern->GetItemSet().Put( pOldPattern->GetItemSet().Get( nSecondItem ) ); + } + else + { + // call virtual method to set a single property + SetOnePropertyValue( pMap, pValues[i] ); + } + + pMap++; + } + else + pMap = pPropertyMap; + } + + if ( pNewPattern && aRanges.Count() ) + { + ScDocFunc aFunc(*pDocShell); + aFunc.ApplyAttributes( *GetMarkData(), *pNewPattern, TRUE, TRUE ); + } + + delete pNewPattern; + delete pOldPattern; + } +} + +uno::Sequence<uno::Any> SAL_CALL ScCellRangesBase::getPropertyValues( + const uno::Sequence< ::rtl::OUString >& aPropertyNames ) + throw (uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + const SfxItemPropertyMap* pPropertyMap = GetItemPropertyMap(); // from derived class + + aPropertyNames.getConstArray(); + uno::Sequence<uno::Any> aRet(aPropertyNames.getLength()); + uno::Any* pProperties = aRet.getArray(); + const SfxItemPropertyMap* pMap = pPropertyMap; + for(INT32 i = 0; i < aPropertyNames.getLength(); i++) + { + pMap = SfxItemPropertyMap::GetByName( pMap, aPropertyNames[i] ); + GetOnePropertyValue( pMap, pProperties[i] ); + if (!pMap) + pMap = pPropertyMap; + else + pMap++; + } + return aRet; +} + +void SAL_CALL ScCellRangesBase::addPropertiesChangeListener( const uno::Sequence< ::rtl::OUString >& /*aPropertyNames*/, + const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) + throw (uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +void SAL_CALL ScCellRangesBase::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) + throw (uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +void SAL_CALL ScCellRangesBase::firePropertiesChangeEvent( const uno::Sequence< ::rtl::OUString >& /*aPropertyNames*/, + const uno::Reference< beans::XPropertiesChangeListener >& /*xListener*/ ) + throw (uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +//! Test !!! + +IMPL_LINK( ScCellRangesBase, ValueListenerHdl, SfxHint*, pHint ) +{ + if ( pDocShell && pHint && pHint->ISA( SfxSimpleHint ) && + ((const SfxSimpleHint*)pHint)->GetId() & (SC_HINT_DATACHANGED | SC_HINT_DYING) ) + { + // nicht doppelt notifien, wenn sich mehrere Formeln im Bereich aendern... + + if ( aValueListeners.Count() && !bValueChangePosted ) + { + // Die Listener koennen nur asynchron benachrichtigt werden, weil im + // Formel-Broadcast auf keinen Fall Reschedule gerufen werden darf + + beans::PropertyChangeEvent* pEvent = new beans::PropertyChangeEvent; + pEvent->Source = (cppu::OWeakObject*)this; + pEvent->PropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Test" )); + pEvent->Further = FALSE; + pEvent->PropertyHandle = -1; + pEvent->OldValue = uno::Any(); + pEvent->NewValue = uno::Any(); + + // Die Ref im Event-Objekt haelt dieses Objekt fest + // Das Event-Objekt wird im Link-Handler geloescht + + bValueChangePosted = TRUE; + Application::PostUserEvent( LINK( this, ScCellRangesBase, ValueChanged ), pEvent ); + } + } + return 0; +} + +// ValueChanged wird asynchron gerufen + +IMPL_LINK( ScCellRangesBase, ValueChanged, beans::PropertyChangeEvent*, pEvent ) +{ + if ( pEvent ) + { + if ( pDocShell ) + for ( USHORT n=0; n<aValueListeners.Count(); n++ ) + (*aValueListeners[n])->propertyChange( *pEvent ); + + bValueChangePosted = FALSE; + + delete pEvent; // damit kann auch dieses Objekt geloescht werden + } + return 0; +} + +//! Test !!!!! + +// XIndent + +void SAL_CALL ScCellRangesBase::decrementIndent() throw(::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell && aRanges.Count() ) // leer = nichts zu tun + { + ScDocFunc aFunc(*pDocShell); + //#97041#; put only MultiMarked ScMarkData in ChangeIndent + ScMarkData aMarkData(*GetMarkData()); + aMarkData.MarkToMulti(); + aFunc.ChangeIndent( aMarkData, FALSE, TRUE ); + } +} + +void SAL_CALL ScCellRangesBase::incrementIndent() throw(::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell && aRanges.Count() ) // leer = nichts zu tun + { + ScDocFunc aFunc(*pDocShell); + //#97041#; put only MultiMarked ScMarkData in ChangeIndent + ScMarkData aMarkData(*GetMarkData()); + aMarkData.MarkToMulti(); + aFunc.ChangeIndent( aMarkData, TRUE, TRUE ); + } +} + +// XChartData + +SchMemChart* ScCellRangesBase::CreateMemChart_Impl() const +{ + if ( pDocShell && aRanges.Count() ) + { + ScRangeListRef xChartRanges; + if ( aRanges.Count() == 1 ) + { + // ganze Tabelle sinnvoll begrenzen (auf belegten Datenbereich) + // (nur hier, Listener werden auf den ganzen Bereich angemeldet) + //! direkt testen, ob es ein ScTableSheetObj ist? + + ScRange* pRange = aRanges.GetObject(0); + if ( pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL && + pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW ) + { + USHORT nTab = pRange->aStart.Tab(); + + USHORT nStartX, nStartY; // Anfang holen + if (!pDocShell->GetDocument()->GetDataStart( nTab, nStartX, nStartY )) + nStartX = nStartY = 0; + + USHORT nEndX, nEndY; // Ende holen + if (!pDocShell->GetDocument()->GetTableArea( nTab, nEndX, nEndY )) + nEndX = nEndY = 0; + + xChartRanges = new ScRangeList; + xChartRanges->Append( ScRange( nStartX, nStartY, nTab, nEndX, nEndY, nTab ) ); + } + } + if (!xChartRanges.Is()) // sonst Ranges direkt uebernehmen + xChartRanges = new ScRangeList(aRanges); + ScChartArray aArr( pDocShell->GetDocument(), xChartRanges, String() ); + + // RowAsHdr = ColHeaders und umgekehrt + aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr ); + + return aArr.CreateMemChart(); + } + return NULL; +} + +uno::Sequence< uno::Sequence<double> > SAL_CALL ScCellRangesBase::getData() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SchMemChart* pMemChart = CreateMemChart_Impl(); + if ( pMemChart ) + { + short nColCount = pMemChart->GetColCount(); + short nRowCount = pMemChart->GetRowCount(); + + uno::Sequence< uno::Sequence<double> > aRowSeq( nRowCount ); + uno::Sequence<double>* pRowAry = aRowSeq.getArray(); + for (short nRow = 0; nRow < nRowCount; nRow++) + { + uno::Sequence<double> aColSeq( nColCount ); + double* pColAry = aColSeq.getArray(); + for (short nCol = 0; nCol < nColCount; nCol++) + pColAry[nCol] = pMemChart->GetData( nCol, nRow ); + + pRowAry[nRow] = aColSeq; + } + + delete pMemChart; + return aRowSeq; + } + + return uno::Sequence< uno::Sequence<double> >(0); +} + +ScRangeListRef ScCellRangesBase::GetLimitedChartRanges_Impl( long nDataColumns, long nDataRows ) const +{ + if ( aRanges.Count() == 1 ) + { + ScRange* pRange = aRanges.GetObject(0); + if ( pRange->aStart.Col() == 0 && pRange->aEnd.Col() == MAXCOL && + pRange->aStart.Row() == 0 && pRange->aEnd.Row() == MAXROW ) + { + // if aRanges is a complete sheet, limit to given size + + USHORT nTab = pRange->aStart.Tab(); + + long nEndColumn = nDataColumns - 1 + ( bChartColAsHdr ? 1 : 0 ); + if ( nEndColumn < 0 ) + nEndColumn = 0; + if ( nEndColumn > MAXCOL ) + nEndColumn = MAXCOL; + + long nEndRow = nDataRows - 1 + ( bChartRowAsHdr ? 1 : 0 ); + if ( nEndRow < 0 ) + nEndRow = 0; + if ( nEndRow > MAXROW ) + nEndRow = MAXROW; + + ScRangeListRef xChartRanges = new ScRangeList; + xChartRanges->Append( ScRange( 0, 0, nTab, (USHORT)nEndColumn, (USHORT)nEndRow, nTab ) ); + return xChartRanges; + } + } + + return new ScRangeList(aRanges); // as-is +} + +void SAL_CALL ScCellRangesBase::setData( const uno::Sequence< uno::Sequence<double> >& aData ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + long nRowCount = aData.getLength(); + long nColCount = nRowCount ? aData[0].getLength() : 0; + ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, nRowCount ); + if ( pDocShell && xChartRanges.Is() ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScChartArray aArr( pDoc, xChartRanges, String() ); + aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr ); // RowAsHdr = ColHeaders + const ScChartPositionMap* pPosMap = aArr.GetPositionMap(); + if (pPosMap) + { + if ( pPosMap->GetColCount() == nColCount && + pPosMap->GetRowCount() == nRowCount ) + { + for (long nRow=0; nRow<nRowCount; nRow++) + { + const uno::Sequence<double>& rRowSeq = aData[nRow]; + const double* pArray = rRowSeq.getConstArray(); + nColCount = rRowSeq.getLength(); + for (long nCol=0; nCol<nColCount; nCol++) + { + const ScAddress* pPos = pPosMap->GetPosition( (USHORT)nCol, (USHORT)nRow ); + if (pPos) + { + double fVal = pArray[nCol]; + if ( fVal == DBL_MIN ) + pDoc->PutCell( *pPos, NULL ); // empty cell + else + pDoc->SetValue( pPos->Col(), pPos->Row(), pPos->Tab(), pArray[nCol] ); + } + } + } + + //! undo + PaintRanges_Impl( PAINT_GRID ); + pDocShell->SetDocumentModified(); + ForceChartListener_Impl(); // call listeners for this object synchronously + bDone = TRUE; + } + } + } + + if (!bDone) + throw uno::RuntimeException(); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellRangesBase::getRowDescriptions() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SchMemChart* pMemChart = CreateMemChart_Impl(); + if ( pMemChart ) + { + short nRowCount = pMemChart->GetRowCount(); + uno::Sequence< ::rtl::OUString> aSeq( nRowCount ); + ::rtl::OUString* pAry = aSeq.getArray(); + for (short nRow = 0; nRow < nRowCount; nRow++) + pAry[nRow] = pMemChart->GetRowText(nRow); + + delete pMemChart; + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(0); +} + +void SAL_CALL ScCellRangesBase::setRowDescriptions( + const uno::Sequence< ::rtl::OUString>& aRowDescriptions ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if ( bChartColAsHdr ) + { + long nRowCount = aRowDescriptions.getLength(); + ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( 1, nRowCount ); + if ( pDocShell && xChartRanges.Is() ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScChartArray aArr( pDoc, xChartRanges, String() ); + aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr ); // RowAsHdr = ColHeaders + const ScChartPositionMap* pPosMap = aArr.GetPositionMap(); + if (pPosMap) + { + if ( pPosMap->GetRowCount() == nRowCount ) + { + const ::rtl::OUString* pArray = aRowDescriptions.getConstArray(); + for (long nRow=0; nRow<nRowCount; nRow++) + { + const ScAddress* pPos = pPosMap->GetRowHeaderPosition( (USHORT)nRow ); + if (pPos) + { + String aStr = pArray[nRow]; + if ( aStr.Len() ) + pDoc->PutCell( *pPos, new ScStringCell( aStr ) ); + else + pDoc->PutCell( *pPos, NULL ); // empty cell + } + } + + //! undo + PaintRanges_Impl( PAINT_GRID ); + pDocShell->SetDocumentModified(); + ForceChartListener_Impl(); // call listeners for this object synchronously + bDone = TRUE; + } + } + } + } + + if (!bDone) + throw uno::RuntimeException(); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellRangesBase::getColumnDescriptions() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SchMemChart* pMemChart = CreateMemChart_Impl(); + if ( pMemChart ) + { + short nColCount = pMemChart->GetColCount(); + uno::Sequence< ::rtl::OUString> aSeq( nColCount ); + ::rtl::OUString* pAry = aSeq.getArray(); + for (short nCol = 0; nCol < nColCount; nCol++) + pAry[nCol] = pMemChart->GetColText(nCol); + + delete pMemChart; + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(0); +} + +void SAL_CALL ScCellRangesBase::setColumnDescriptions( + const uno::Sequence< ::rtl::OUString>& aColumnDescriptions ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if ( bChartRowAsHdr ) + { + long nColCount = aColumnDescriptions.getLength(); + ScRangeListRef xChartRanges = GetLimitedChartRanges_Impl( nColCount, 1 ); + if ( pDocShell && xChartRanges.Is() ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScChartArray aArr( pDoc, xChartRanges, String() ); + aArr.SetHeaders( bChartRowAsHdr, bChartColAsHdr ); // RowAsHdr = ColHeaders + const ScChartPositionMap* pPosMap = aArr.GetPositionMap(); + if (pPosMap) + { + if ( pPosMap->GetColCount() == nColCount ) + { + const ::rtl::OUString* pArray = aColumnDescriptions.getConstArray(); + for (long nCol=0; nCol<nColCount; nCol++) + { + const ScAddress* pPos = pPosMap->GetColHeaderPosition( (USHORT)nCol ); + if (pPos) + { + String aStr = pArray[nCol]; + if ( aStr.Len() ) + pDoc->PutCell( *pPos, new ScStringCell( aStr ) ); + else + pDoc->PutCell( *pPos, NULL ); // empty cell + } + } + + //! undo + PaintRanges_Impl( PAINT_GRID ); + pDocShell->SetDocumentModified(); + ForceChartListener_Impl(); // call listeners for this object synchronously + bDone = TRUE; + } + } + } + } + + if (!bDone) + throw uno::RuntimeException(); +} + +void ScCellRangesBase::ForceChartListener_Impl() +{ + // call Update immediately so the caller to setData etc. can + // regognize the listener call + + if ( pDocShell ) + { + ScChartListenerCollection* pColl = pDocShell->GetDocument()->GetChartListenerCollection(); + if ( pColl ) + { + USHORT nCollCount = pColl->GetCount(); + for ( USHORT nIndex = 0; nIndex < nCollCount; nIndex++ ) + { + ScChartListener* pChartListener = (ScChartListener*)pColl->At(nIndex); + if ( pChartListener && + pChartListener->GetUnoSource() == static_cast<chart::XChartData*>(this) && + pChartListener->IsDirty() ) + pChartListener->Update(); + } + } + } +} + +String lcl_UniqueName( StrCollection& rColl, const String& rPrefix ) +{ + long nNumber = 1; + USHORT nCollCount = rColl.GetCount(); + while (TRUE) + { + String aName = rPrefix; + aName += String::CreateFromInt32( nNumber ); + BOOL bFound = FALSE; + for (USHORT i=0; i<nCollCount; i++) + if ( rColl[i]->GetString() == aName ) + { + bFound = TRUE; + break; + } + if (!bFound) + return aName; + ++nNumber; + } +} + +void SAL_CALL ScCellRangesBase::addChartDataChangeEventListener( const uno::Reference< + chart::XChartDataChangeEventListener >& aListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell && aRanges.Count() ) + { + //! auf doppelte testen? + + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangeListRef aRangesRef( new ScRangeList(aRanges) ); + ScChartListenerCollection* pColl = pDoc->GetChartListenerCollection(); + String aName = lcl_UniqueName( *pColl, + String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("__Uno")) ); + ScChartListener* pListener = new ScChartListener( aName, pDoc, aRangesRef ); + pListener->SetUno( aListener, this ); + pColl->Insert( pListener ); + pListener->StartListeningTo(); + } +} + +void SAL_CALL ScCellRangesBase::removeChartDataChangeEventListener( const uno::Reference< + chart::XChartDataChangeEventListener >& aListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell && aRanges.Count() ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScChartListenerCollection* pColl = pDoc->GetChartListenerCollection(); + pColl->FreeUno( aListener, this ); + } +} + +double SAL_CALL ScCellRangesBase::getNotANumber() throw(::com::sun::star::uno::RuntimeException) +{ + // im ScChartArray wird DBL_MIN verwendet, weil das Chart es so will + return DBL_MIN; +} + +sal_Bool SAL_CALL ScCellRangesBase::isNotANumber( double nNumber ) throw(uno::RuntimeException) +{ + // im ScChartArray wird DBL_MIN verwendet, weil das Chart es so will + return (nNumber == DBL_MIN); +} + +// XCellRangesQuery + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryVisibleCells() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + //! fuer alle Tabellen getrennt, wenn Markierungen pro Tabelle getrennt sind! + USHORT nTab = lcl_FirstTab(aRanges); + + ScMarkData aMarkData(*GetMarkData()); + + ScDocument* pDoc = pDocShell->GetDocument(); + for (USHORT nCol=0; nCol<=MAXCOL; nCol++) + if (pDoc->GetColFlags(nCol,nTab) & CR_HIDDEN) + aMarkData.SetMultiMarkArea( ScRange( nCol,0,nTab, nCol,MAXROW,nTab ), FALSE ); + + //! nur bis zur letzten selektierten Zeile testen? + for (USHORT nRow=0; nRow<=MAXROW; nRow++) + if (pDoc->GetRowFlags(nRow,nTab) & CR_HIDDEN) + { + USHORT nHiddenCount = pDoc->GetHiddenRowCount( nRow, nTab ); + DBG_ASSERT(nHiddenCount, "huch?"); + USHORT nLast = nRow + nHiddenCount - 1; + aMarkData.SetMultiMarkArea( ScRange( 0,nRow,nTab, MAXCOL,nLast,nTab ), FALSE ); + nRow = nLast; // +1 wird hinterher addiert + } + + ScRangeList aNewRanges; + aMarkData.FillRangeListWithMarks( &aNewRanges, FALSE ); + return new ScCellRangesObj( pDocShell, aNewRanges ); + } + + return NULL; +} + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryEmptyCells() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + ScMarkData aMarkData(*GetMarkData()); + + // belegte Zellen wegmarkieren + ULONG nCount = aRanges.Count(); + for (ULONG i=0; i<nCount; i++) + { + ScRange aRange = *aRanges.GetObject(i); + + ScCellIterator aIter( pDoc, aRange ); + ScBaseCell* pCell = aIter.GetFirst(); + while (pCell) + { + // Notizen zaehlen als nicht-leer + if ( pCell->GetCellType() != CELLTYPE_NOTE || pCell->GetNotePtr() ) + aMarkData.SetMultiMarkArea( + ScRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ), + FALSE ); + + pCell = aIter.GetNext(); + } + } + + ScRangeList aNewRanges; + // IsMultiMarked reicht hier nicht (wird beim deselektieren nicht zurueckgesetzt) + if (aMarkData.HasAnyMultiMarks()) + aMarkData.FillRangeListWithMarks( &aNewRanges, FALSE ); + + return new ScCellRangesObj( pDocShell, aNewRanges ); // aNewRanges kann leer sein + } + + return NULL; +} + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryContentCells( + sal_Int16 nContentFlags ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + ScMarkData aMarkData; + + // passende Zellen selektieren + ULONG nCount = aRanges.Count(); + for (ULONG i=0; i<nCount; i++) + { + ScRange aRange = *aRanges.GetObject(i); + + ScCellIterator aIter( pDoc, aRange ); + ScBaseCell* pCell = aIter.GetFirst(); + while (pCell) + { + BOOL bAdd = FALSE; + if ( pCell->GetNotePtr() && ( nContentFlags & sheet::CellFlags::ANNOTATION ) ) + bAdd = TRUE; + else + switch ( pCell->GetCellType() ) + { + case CELLTYPE_STRING: + case CELLTYPE_EDIT: + if ( nContentFlags & sheet::CellFlags::STRING ) + bAdd = TRUE; + break; + case CELLTYPE_FORMULA: + if ( nContentFlags & sheet::CellFlags::FORMULA ) + bAdd = TRUE; + break; + case CELLTYPE_VALUE: + if ( (nContentFlags & (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME)) + == (sheet::CellFlags::VALUE|sheet::CellFlags::DATETIME) ) + bAdd = TRUE; + else + { + // Date/Time Erkennung + + ULONG nIndex = (ULONG)((SfxUInt32Item*)pDoc->GetAttr( + aIter.GetCol(), aIter.GetRow(), aIter.GetTab(), + ATTR_VALUE_FORMAT ))->GetValue(); + short nTyp = pDoc->GetFormatTable()->GetType(nIndex); + if ((nTyp == NUMBERFORMAT_DATE) || (nTyp == NUMBERFORMAT_TIME) || + (nTyp == NUMBERFORMAT_DATETIME)) + { + if ( nContentFlags & sheet::CellFlags::DATETIME ) + bAdd = TRUE; + } + else + { + if ( nContentFlags & sheet::CellFlags::VALUE ) + bAdd = TRUE; + } + } + break; + default: + break; + } + + if (bAdd) + aMarkData.SetMultiMarkArea( + ScRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ), + TRUE ); + + pCell = aIter.GetNext(); + } + } + + ScRangeList aNewRanges; + if (aMarkData.IsMultiMarked()) + aMarkData.FillRangeListWithMarks( &aNewRanges, FALSE ); + + return new ScCellRangesObj( pDocShell, aNewRanges ); // aNewRanges kann leer sein + } + + return NULL; +} + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryFormulaCells( + sal_Int32 nResultFlags ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + ScMarkData aMarkData; + + // passende Zellen selektieren + ULONG nCount = aRanges.Count(); + for (ULONG i=0; i<nCount; i++) + { + ScRange aRange = *aRanges.GetObject(i); + + ScCellIterator aIter( pDoc, aRange ); + ScBaseCell* pCell = aIter.GetFirst(); + while (pCell) + { + if (pCell->GetCellType() == CELLTYPE_FORMULA) + { + ScFormulaCell* pFCell = (ScFormulaCell*)pCell; + BOOL bAdd = FALSE; + if (pFCell->GetErrCode()) + { + if ( nResultFlags & sheet::FormulaResult::ERROR ) + bAdd = TRUE; + } + else if (pFCell->IsValue()) + { + if ( nResultFlags & sheet::FormulaResult::VALUE ) + bAdd = TRUE; + } + else // String + { + if ( nResultFlags & sheet::FormulaResult::STRING ) + bAdd = TRUE; + } + + if (bAdd) + aMarkData.SetMultiMarkArea( + ScRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ), + TRUE ); + } + + pCell = aIter.GetNext(); + } + } + + ScRangeList aNewRanges; + if (aMarkData.IsMultiMarked()) + aMarkData.FillRangeListWithMarks( &aNewRanges, FALSE ); + + return new ScCellRangesObj( pDocShell, aNewRanges ); // aNewRanges kann leer sein + } + + return NULL; +} + +uno::Reference<sheet::XSheetCellRanges> ScCellRangesBase::QueryDifferences_Impl( + const table::CellAddress& aCompare, BOOL bColumnDiff) +{ + if (pDocShell) + { + ULONG nRangeCount = aRanges.Count(); + ULONG i; + ScDocument* pDoc = pDocShell->GetDocument(); + ScMarkData aMarkData; + + USHORT nCmpPos = bColumnDiff ? (USHORT)aCompare.Row : (USHORT)aCompare.Column; + + // zuerst alles selektieren, wo ueberhaupt etwas in der Vergleichsspalte steht + // (fuer gleiche Zellen wird die Selektion im zweiten Schritt aufgehoben) + + USHORT nTab = lcl_FirstTab(aRanges); //! fuer alle Tabellen, wenn Markierungen pro Tabelle! + ScRange aCmpRange, aCellRange; + if (bColumnDiff) + aCmpRange = ScRange( 0,nCmpPos,nTab, MAXCOL,nCmpPos,nTab ); + else + aCmpRange = ScRange( nCmpPos,0,nTab, nCmpPos,MAXROW,nTab ); + ScCellIterator aCmpIter( pDoc, aCmpRange ); + ScBaseCell* pCmpCell = aCmpIter.GetFirst(); + while (pCmpCell) + { + if (pCmpCell->GetCellType() != CELLTYPE_NOTE) + { + USHORT nCellPos = bColumnDiff ? aCmpIter.GetCol() : aCmpIter.GetRow(); + if (bColumnDiff) + aCellRange = ScRange( nCellPos,0,nTab, nCellPos,MAXROW,nTab ); + else + aCellRange = ScRange( 0,nCellPos,nTab, MAXCOL,nCellPos,nTab ); + + for (i=0; i<nRangeCount; i++) + { + ScRange aRange = *aRanges.GetObject(i); + if ( aRange.Intersects( aCellRange ) ) + { + if (bColumnDiff) + { + aRange.aStart.SetCol(nCellPos); + aRange.aEnd.SetCol(nCellPos); + } + else + { + aRange.aStart.SetRow(nCellPos); + aRange.aEnd.SetRow(nCellPos); + } + aMarkData.SetMultiMarkArea( aRange ); + } + } + } + pCmpCell = aCmpIter.GetNext(); + } + + // alle nichtleeren Zellen mit der Vergleichsspalte vergleichen und entsprechend + // selektieren oder aufheben + + ScAddress aCmpAddr; + for (i=0; i<nRangeCount; i++) + { + ScRange aRange = *aRanges.GetObject(i); + + ScCellIterator aIter( pDoc, aRange ); + ScBaseCell* pCell = aIter.GetFirst(); + while (pCell) + { + if (bColumnDiff) + aCmpAddr = ScAddress( aIter.GetCol(), nCmpPos, aIter.GetTab() ); + else + aCmpAddr = ScAddress( nCmpPos, aIter.GetRow(), aIter.GetTab() ); + const ScBaseCell* pLclCmpCell = pDoc->GetCell( aCmpAddr ); + + ScRange aLclCellRange( aIter.GetCol(), aIter.GetRow(), aIter.GetTab() ); + if ( !ScBaseCell::CellEqual( pCell, pLclCmpCell ) ) + aMarkData.SetMultiMarkArea( aLclCellRange ); + else + aMarkData.SetMultiMarkArea( aLclCellRange, FALSE ); // aufheben + + pCell = aIter.GetNext(); + } + } + + ScRangeList aNewRanges; + if (aMarkData.IsMultiMarked()) + aMarkData.FillRangeListWithMarks( &aNewRanges, FALSE ); + + return new ScCellRangesObj( pDocShell, aNewRanges ); // aNewRanges kann leer sein + } + return NULL; +} + +uno::Reference<sheet::XSheetCellRanges > SAL_CALL ScCellRangesBase::queryColumnDifferences( + const table::CellAddress& aCompare ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return QueryDifferences_Impl( aCompare, TRUE ); +} + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryRowDifferences( + const table::CellAddress& aCompare ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return QueryDifferences_Impl( aCompare, FALSE ); +} + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryIntersection( + const table::CellRangeAddress& aRange ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRange aMask( (USHORT)aRange.StartColumn, (USHORT)aRange.StartRow, aRange.Sheet, + (USHORT)aRange.EndColumn, (USHORT)aRange.EndRow, aRange.Sheet ); + + ScRangeList aNew; + ULONG nCount = aRanges.Count(); + for (ULONG i=0; i<nCount; i++) + { + ScRange aTemp = *aRanges.GetObject(i); + if ( aTemp.Intersects( aMask ) ) + aNew.Join( ScRange( Max( aTemp.aStart.Col(), aMask.aStart.Col() ), + Max( aTemp.aStart.Row(), aMask.aStart.Row() ), + Max( aTemp.aStart.Tab(), aMask.aStart.Tab() ), + Min( aTemp.aEnd.Col(), aMask.aEnd.Col() ), + Min( aTemp.aEnd.Row(), aMask.aEnd.Row() ), + Min( aTemp.aEnd.Tab(), aMask.aEnd.Tab() ) ) ); + } + + return new ScCellRangesObj( pDocShell, aNew ); // kann leer sein +} + +// XFormulaQuery + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryPrecedents( + sal_Bool bRecursive ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + ScRangeList aNewRanges = aRanges; + BOOL bFound; + do + { + bFound = FALSE; + + // #97205# aMarkData uses aNewRanges, not aRanges, so GetMarkData can't be used + ScMarkData aMarkData; + aMarkData.MarkFromRangeList( aNewRanges, FALSE ); + aMarkData.MarkToMulti(); // needed for IsAllMarked + + ULONG nCount = aNewRanges.Count(); + for (USHORT nR=0; nR<nCount; nR++) + { + ScRange aRange = *aNewRanges.GetObject(nR); + ScCellIterator aIter( pDoc, aRange ); + ScBaseCell* pCell = aIter.GetFirst(); + while (pCell) + { + if ( pCell->GetCellType() == CELLTYPE_FORMULA ) + { + ScFormulaCell* pFCell = (ScFormulaCell*) pCell; + + ScDetectiveRefIter aLclIter( pFCell ); + ScTripel aRefStart; + ScTripel aRefEnd; + while ( aLclIter.GetNextRef( aRefStart, aRefEnd ) ) + { + ScRange aRefRange( aRefStart, aRefEnd ); + if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aRefRange ) ) + bFound = TRUE; + aMarkData.SetMultiMarkArea( aRefRange, TRUE ); + } + } + pCell = aIter.GetNext(); + } + } + + aMarkData.FillRangeListWithMarks( &aNewRanges, TRUE ); + } + while ( bRecursive && bFound ); + + return new ScCellRangesObj( pDocShell, aNewRanges ); + } + + return NULL; +} + +uno::Reference<sheet::XSheetCellRanges> SAL_CALL ScCellRangesBase::queryDependents( + sal_Bool bRecursive ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + ScRangeList aNewRanges = aRanges; + BOOL bFound; + do + { + bFound = FALSE; + ULONG nRangesCount = aNewRanges.Count(); + + // #97205# aMarkData uses aNewRanges, not aRanges, so GetMarkData can't be used + ScMarkData aMarkData; + aMarkData.MarkFromRangeList( aNewRanges, FALSE ); + aMarkData.MarkToMulti(); // needed for IsAllMarked + + USHORT nTab = lcl_FirstTab(aNewRanges); //! alle Tabellen + + ScCellIterator aCellIter( pDoc, 0,0, nTab, MAXCOL,MAXROW, nTab ); + ScBaseCell* pCell = aCellIter.GetFirst(); + while (pCell) + { + if (pCell->GetCellType() == CELLTYPE_FORMULA) + { + BOOL bMark = FALSE; + ScDetectiveRefIter aIter( (ScFormulaCell*) pCell ); + ScTripel aRefStart; + ScTripel aRefEnd; + while ( aIter.GetNextRef( aRefStart, aRefEnd ) ) + { + ScRange aRefRange( aRefStart, aRefEnd ); + for (USHORT nR=0; nR<nRangesCount; nR++) + { + ScRange aRange = *aNewRanges.GetObject(nR); + if (aRange.Intersects(aRefRange)) + bMark = TRUE; // von Teil des Ranges abhaengig + } + } + if (bMark) + { + ScRange aCellRange( aCellIter.GetCol(), + aCellIter.GetRow(), + aCellIter.GetTab() ); + if ( bRecursive && !bFound && !aMarkData.IsAllMarked( aCellRange ) ) + bFound = TRUE; + aMarkData.SetMultiMarkArea( aCellRange, TRUE ); + } + } + pCell = aCellIter.GetNext(); + } + + aMarkData.FillRangeListWithMarks( &aNewRanges, TRUE ); + } + while ( bRecursive && bFound ); + + return new ScCellRangesObj( pDocShell, aNewRanges ); + } + + return NULL; +} + +// XSearchable + +uno::Reference<util::XSearchDescriptor> SAL_CALL ScCellRangesBase::createSearchDescriptor() + throw(uno::RuntimeException) +{ + return uno::Reference<util::XSearchDescriptor>() ; +} + +uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangesBase::findAll( + const uno::Reference<util::XSearchDescriptor>& /*xDesc*/ ) + throw(uno::RuntimeException) +{ + // Wenn nichts gefunden wird, soll Null zurueckgegeben werden (?) + uno::Reference<container::XIndexAccess> xRet; + return xRet; +} + +uno::Reference<uno::XInterface> ScCellRangesBase::Find_Impl( + const uno::Reference<util::XSearchDescriptor>& /*xDesc*/, + const ScAddress* /*pLastPos*/ ) +{ + uno::Reference<uno::XInterface> xRet; + return xRet; +} + +uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findFirst( + const uno::Reference<util::XSearchDescriptor>& xDesc ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return Find_Impl( xDesc, NULL ); +} + +uno::Reference<uno::XInterface> SAL_CALL ScCellRangesBase::findNext( + const uno::Reference<uno::XInterface>& /*xStartAt*/, + const uno::Reference<util::XSearchDescriptor >& /*xDesc*/ ) + throw(uno::RuntimeException) +{ + return NULL; +} + +// XReplaceable + +uno::Reference<util::XReplaceDescriptor> SAL_CALL ScCellRangesBase::createReplaceDescriptor() + throw(uno::RuntimeException) +{ + return uno::Reference<util::XReplaceDescriptor>() ; +} + +sal_Int32 SAL_CALL ScCellRangesBase::replaceAll( const uno::Reference<util::XSearchDescriptor>& /*xDesc*/ ) + throw(uno::RuntimeException) +{ + INT32 nReplaced = 0; + return nReplaced; +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScCellRangesBase::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScCellRangesBase::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScCellRangesBase* ScCellRangesBase::getImplementation( const uno::Reference<uno::XInterface> xObj ) +{ + ScCellRangesBase* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScCellRangesBase*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + + +ScCellRangesObj::ScCellRangesObj(ScDocShell* pDocSh, const ScRangeList& rR) : + ScCellRangesBase( pDocSh, rR ) +{ +} + +ScCellRangesObj::~ScCellRangesObj() +{ +} + +void ScCellRangesObj::RefChanged() +{ + ScCellRangesBase::RefChanged(); + + // nix weiter... +} + +uno::Any SAL_CALL ScCellRangesObj::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( sheet::XSheetCellRangeContainer ) + SC_QUERYINTERFACE( sheet::XSheetCellRanges ) + SC_QUERYINTERFACE( container::XIndexAccess ) + SC_QUERY_MULTIPLE( container::XElementAccess, container::XIndexAccess ) + SC_QUERYINTERFACE( container::XEnumerationAccess ) + SC_QUERYINTERFACE( container::XNameContainer ) + SC_QUERYINTERFACE( container::XNameReplace ) + SC_QUERYINTERFACE( container::XNameAccess ) + + return ScCellRangesBase::queryInterface( rType ); +} + +void SAL_CALL ScCellRangesObj::acquire() throw() +{ + ScCellRangesBase::acquire(); +} + +void SAL_CALL ScCellRangesObj::release() throw() +{ + ScCellRangesBase::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScCellRangesObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = ScCellRangesBase::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 3 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSheetCellRangeContainer>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<container::XNameContainer>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<container::XEnumerationAccess>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScCellRangesObj::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// XCellRanges + +ScCellRangeObj* ScCellRangesObj::GetObjectByIndex_Impl(USHORT nIndex) const +{ + ScDocShell* pDocSh = GetDocShell(); + const ScRangeList& rRanges = GetRangeList(); + if ( pDocSh && nIndex < rRanges.Count() ) + { + ScRange aRange = *rRanges.GetObject(nIndex); + if ( aRange.aStart == aRange.aEnd ) + return new ScCellObj( pDocSh, aRange.aStart ); + else + return new ScCellRangeObj( pDocSh, aRange ); + } + + return NULL; // keine DocShell oder falscher Index +} + +uno::Sequence<table::CellRangeAddress> SAL_CALL ScCellRangesObj::getRangeAddresses() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + const ScRangeList& rRanges = GetRangeList(); + ULONG nCount = rRanges.Count(); + if ( pDocSh && nCount ) + { + table::CellRangeAddress aRangeAddress; + uno::Sequence<table::CellRangeAddress> aSeq(nCount); + table::CellRangeAddress* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + ScUnoConversion::FillApiRange( aRangeAddress, *rRanges.GetObject(i) ); + pAry[i] = aRangeAddress; + } + return aSeq; + } + + return uno::Sequence<table::CellRangeAddress>(0); // leer ist moeglich +} + +uno::Reference<container::XEnumerationAccess> SAL_CALL ScCellRangesObj::getCells() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // getCells with empty range list is possible (no exception), + // the resulting enumeration just has no elements + // (same behaviour as a valid range with no cells) + // This is handled in ScCellsEnumeration ctor. + + const ScRangeList& rRanges = GetRangeList(); + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + return new ScCellsObj( pDocSh, rRanges ); + return NULL; +} + +::rtl::OUString SAL_CALL ScCellRangesObj::getRangeAddressesAsString() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString; + ScDocShell* pDocSh = GetDocShell(); + const ScRangeList& rRanges = GetRangeList(); + if (pDocSh) + rRanges.Format( aString, SCA_VALID | SCA_TAB_3D, pDocSh->GetDocument() ); + return aString; +} + +// XSheetCellRangeContainer + +void SAL_CALL ScCellRangesObj::addRangeAddress( const table::CellRangeAddress& rRange, + sal_Bool bMergeRanges ) + throw(::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRange aRange(static_cast<sal_uInt16>(rRange.StartColumn), + static_cast<sal_uInt16>(rRange.StartRow), + static_cast<sal_uInt16>(rRange.Sheet), + static_cast<sal_uInt16>(rRange.EndColumn), + static_cast<sal_uInt16>(rRange.EndRow), + static_cast<sal_uInt16>(rRange.Sheet)); + AddRange(aRange, bMergeRanges); +} + +void lcl_RemoveNamedEntry( ScNamedEntryArr_Impl& rNamedEntries, const ScRange& rRange ) +{ + USHORT nCount = rNamedEntries.Count(); + for ( USHORT n=nCount; n--; ) + if ( rNamedEntries[n]->GetRange() == rRange ) + rNamedEntries.DeleteAndDestroy( n ); +} + +void SAL_CALL ScCellRangesObj::removeRangeAddress( const table::CellRangeAddress& rRange ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + + ScRangeList aSheetRanges; + ScRangeList aNotSheetRanges; + for (sal_uInt32 i = 0; i < rRanges.Count(); ++i) + { + if (rRanges.GetObject(i)->aStart.Tab() == rRange.Sheet) + { + aSheetRanges.Append(*rRanges.GetObject(i)); + } + else + { + aNotSheetRanges.Append(*rRanges.GetObject(i)); + } + } + ScMarkData aMarkData; + aMarkData.MarkFromRangeList( aSheetRanges, FALSE ); + ScRange aRange(static_cast<sal_uInt16>(rRange.StartColumn), + static_cast<sal_uInt16>(rRange.StartRow), + static_cast<sal_uInt16>(rRange.Sheet), + static_cast<sal_uInt16>(rRange.EndColumn), + static_cast<sal_uInt16>(rRange.EndRow), + static_cast<sal_uInt16>(rRange.Sheet)); + if (aMarkData.GetTableSelect( aRange.aStart.Tab() )) + { + aMarkData.MarkToMulti(); + if (aMarkData.IsAllMarked( aRange ) ) + { + aMarkData.SetMultiMarkArea( aRange, FALSE ); + lcl_RemoveNamedEntry(aNamedEntries, aRange); + } + else + throw container::NoSuchElementException(); + } + SetNewRanges(aNotSheetRanges); + ScRangeList aNew; + aMarkData.FillRangeListWithMarks( &aNew, FALSE ); + for (sal_uInt32 j = 0; j < aNew.Count(); ++j) + { + AddRange(*aNew.GetObject(j), sal_False); + } +} + +void SAL_CALL ScCellRangesObj::addRangeAddresses( const uno::Sequence<table::CellRangeAddress >& rRanges, + sal_Bool bMergeRanges ) + throw(::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + sal_Int32 nCount(rRanges.getLength()); + if (nCount) + { + const table::CellRangeAddress* pRanges = rRanges.getConstArray(); + for (sal_Int32 i = 0; i < rRanges.getLength(); i++, pRanges++) + { + ScRange aRange(static_cast<sal_uInt16>(pRanges->StartColumn), + static_cast<sal_uInt16>(pRanges->StartRow), + static_cast<sal_uInt16>(pRanges->Sheet), + static_cast<sal_uInt16>(pRanges->EndColumn), + static_cast<sal_uInt16>(pRanges->EndRow), + static_cast<sal_uInt16>(pRanges->Sheet)); + AddRange(aRange, bMergeRanges); + } + } +} + +void SAL_CALL ScCellRangesObj::removeRangeAddresses( const uno::Sequence<table::CellRangeAddress >& rRangeSeq ) + throw(::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException) +{ + // with this implementation not needed +// SolarMutexGuard aGuard; + + + // use sometimes a better/faster implementation + sal_uInt32 nCount(rRangeSeq.getLength()); + if (nCount) + { + const table::CellRangeAddress* pRanges = rRangeSeq.getConstArray(); + for (sal_uInt32 i=0; i < nCount; ++i, ++pRanges) + { + removeRangeAddress(*pRanges); + } + } +} + +// XNameContainer + +void lcl_RemoveNamedEntry( ScNamedEntryArr_Impl& rNamedEntries, const String& rName ) +{ + USHORT nCount = rNamedEntries.Count(); + for ( USHORT n=nCount; n--; ) + if ( rNamedEntries[n]->GetName() == rName ) + rNamedEntries.DeleteAndDestroy( n ); +} + +void SAL_CALL ScCellRangesObj::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::ElementExistException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + BOOL bDone = FALSE; + + //! Type of aElement can be some specific interface instead of XInterface + + uno::Reference<uno::XInterface> xInterface; + if ( pDocSh && ( aElement >>= xInterface ) ) + { + ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( xInterface ); + if ( pRangesImp && pRangesImp->GetDocShell() == pDocSh ) + { + // if explicit name is given and already existing, throw exception + + String aNamStr = aName; + if ( aNamStr.Len() ) + { + USHORT nNamedCount = aNamedEntries.Count(); + for (USHORT n=0; n<nNamedCount; n++) + if ( aNamedEntries[n]->GetName() == aNamStr ) + throw container::ElementExistException(); + } + + ScRangeList aNew = GetRangeList(); + const ScRangeList& rAddRanges = pRangesImp->GetRangeList(); + ULONG nAddCount = rAddRanges.Count(); + for (ULONG i=0; i<nAddCount; i++) + aNew.Join( *rAddRanges.GetObject(i) ); + SetNewRanges(aNew); + bDone = TRUE; + + if ( aName.getLength() && nAddCount == 1 ) + { + // if a name is given, also insert into list of named entries + // (only possible for a single range) + // name is not in aNamedEntries (tested above) + + ScNamedEntry* pEntry = new ScNamedEntry( aNamStr, *rAddRanges.GetObject(0) ); + aNamedEntries.Insert( pEntry, aNamedEntries.Count() ); + } + } + } + + if (!bDone) + { + // invalid element - double names are handled above + throw lang::IllegalArgumentException(); + } +} + +BOOL lcl_FindRangeByName( const ScRangeList& rRanges, ScDocShell* pDocSh, + const String& rName, ULONG& rIndex ) +{ + if (pDocSh) + { + String aRangeStr; + ScDocument* pDoc = pDocSh->GetDocument(); + ULONG nCount = rRanges.Count(); + for (ULONG i=0; i<nCount; i++) + { + rRanges.GetObject(i)->Format( aRangeStr, SCA_VALID | SCA_TAB_3D, pDoc ); + if ( aRangeStr == rName ) + { + rIndex = i; + return TRUE; + } + } + } + return FALSE; // nicht gefunden +} + +BOOL lcl_FindRangeOrEntry( const ScNamedEntryArr_Impl& rNamedEntries, + const ScRangeList& rRanges, ScDocShell* pDocSh, + const String& rName, ScRange& rFound ) +{ + // exact range in list? + + ULONG nIndex = 0; + if ( lcl_FindRangeByName( rRanges, pDocSh, rName, nIndex ) ) + { + rFound = *rRanges.GetObject(nIndex); + return TRUE; + } + + // range contained in selection? (sheet must be specified) + + ScRange aCellRange; + USHORT nParse = aCellRange.ParseAny( rName, pDocSh->GetDocument() ); + if ( ( nParse & ( SCA_VALID | SCA_TAB_3D ) ) == ( SCA_VALID | SCA_TAB_3D ) ) + { + ScMarkData aMarkData; + aMarkData.MarkFromRangeList( rRanges, FALSE ); + aMarkData.MarkToMulti(); // needed for IsAllMarked + if ( aMarkData.IsAllMarked( aCellRange ) ) + { + rFound = aCellRange; + return TRUE; + } + } + + // named entry in this object? + + if ( rNamedEntries.Count() ) + { + for ( USHORT n=0; n<rNamedEntries.Count(); n++ ) + if ( rNamedEntries[n]->GetName() == rName ) + { + // test if named entry is contained in rRanges + + const ScRange& rComp = rNamedEntries[n]->GetRange(); + ScMarkData aMarkData; + aMarkData.MarkFromRangeList( rRanges, FALSE ); + aMarkData.MarkToMulti(); // needed for IsAllMarked + if ( aMarkData.IsAllMarked( rComp ) ) + { + rFound = rComp; + return TRUE; + } + } + } + + return FALSE; // not found +} + +void SAL_CALL ScCellRangesObj::removeByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + String aNameStr = aName; + ScDocShell* pDocSh = GetDocShell(); + const ScRangeList& rRanges = GetRangeList(); + ULONG nIndex = 0; + if ( lcl_FindRangeByName( rRanges, pDocSh, aNameStr, nIndex ) ) + { + // einzelnen Range weglassen + ScRangeList aNew; + ULONG nCount = rRanges.Count(); + for (ULONG i=0; i<nCount; i++) + if (i != nIndex) + aNew.Append( *rRanges.GetObject(i) ); + SetNewRanges(aNew); + bDone = TRUE; + } + else if (pDocSh) + { + // deselect any ranges (parsed or named entry) + ScRangeList aDiff; + BOOL bValid = ( aDiff.Parse( aNameStr, pDocSh->GetDocument() ) & SCA_VALID ) != 0; + if ( !bValid && aNamedEntries.Count() ) + { + USHORT nCount = aNamedEntries.Count(); + for (USHORT n=0; n<nCount && !bValid; n++) + if (aNamedEntries[n]->GetName() == aNameStr) + { + aDiff.RemoveAll(); + aDiff.Append( aNamedEntries[n]->GetRange() ); + bValid = TRUE; + } + } + if ( bValid ) + { + ScMarkData aMarkData; + aMarkData.MarkFromRangeList( rRanges, FALSE ); + + ULONG nDiffCount = aDiff.Count(); + for (ULONG i=0; i<nDiffCount; i++) + { + ScRange* pDiffRange = aDiff.GetObject(i); + if (aMarkData.GetTableSelect( pDiffRange->aStart.Tab() )) + aMarkData.SetMultiMarkArea( *pDiffRange, FALSE ); + } + + ScRangeList aNew; + aMarkData.FillRangeListWithMarks( &aNew, FALSE ); + SetNewRanges(aNew); + + bDone = TRUE; //! error if range was not selected before? + } + } + + if (aNamedEntries.Count()) + lcl_RemoveNamedEntry( aNamedEntries, aNameStr ); // remove named entry + + if (!bDone) + throw container::NoSuchElementException(); // not found +} + +// XNameReplace + +void SAL_CALL ScCellRangesObj::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! zusammenfassen? + removeByName( aName ); + insertByName( aName, aElement ); +} + +// XNameAccess + +uno::Any SAL_CALL ScCellRangesObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aRet; + + String aNameStr = aName; + ScDocShell* pDocSh = GetDocShell(); + const ScRangeList& rRanges = GetRangeList(); + ScRange aRange; + if ( lcl_FindRangeOrEntry( aNamedEntries, rRanges, pDocSh, aNameStr, aRange ) ) + { + uno::Reference<table::XCellRange> xRange; + if ( aRange.aStart == aRange.aEnd ) + xRange = new ScCellObj( pDocSh, aRange.aStart ); + else + xRange = new ScCellRangeObj( pDocSh, aRange ); + aRet <<= xRange; + } + else + throw container::NoSuchElementException(); + return aRet; +} + +BOOL lcl_FindEntryName( const ScNamedEntryArr_Impl& rNamedEntries, + const ScRange& rRange, String& rName ) +{ + USHORT nCount = rNamedEntries.Count(); + for (USHORT i=0; i<nCount; i++) + if (rNamedEntries[i]->GetRange() == rRange) + { + rName = rNamedEntries[i]->GetName(); + return TRUE; + } + return FALSE; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellRangesObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + ScDocShell* pDocSh = GetDocShell(); + const ScRangeList& rRanges = GetRangeList(); + if (pDocSh) + { + String aRangeStr; + ScDocument* pDoc = pDocSh->GetDocument(); + ULONG nCount = rRanges.Count(); + + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (ULONG i=0; i<nCount; i++) + { + // use given name if for exactly this range, otherwise just format + ScRange aRange = *rRanges.GetObject(i); + if ( !aNamedEntries.Count() || !lcl_FindEntryName( aNamedEntries, aRange, aRangeStr ) ) + aRange.Format( aRangeStr, SCA_VALID | SCA_TAB_3D, pDoc ); + pAry[i] = aRangeStr; + } + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(0); +} + +sal_Bool SAL_CALL ScCellRangesObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr = aName; + ScDocShell* pDocSh = GetDocShell(); + const ScRangeList& rRanges = GetRangeList(); + ScRange aRange; + return lcl_FindRangeOrEntry( aNamedEntries, rRanges, pDocSh, aNameStr, aRange ); +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScCellRangesObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SheetCellRangesEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScCellRangesObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + return rRanges.Count(); +} + +uno::Any SAL_CALL ScCellRangesObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<table::XCellRange> xRange = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xRange.is()) + aAny <<= xRange; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScCellRangesObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<table::XCellRange>*)0); +} + +sal_Bool SAL_CALL ScCellRangesObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + return rRanges.Count() != 0; +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScCellRangesObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScCellRangesObj" )); +} + +sal_Bool SAL_CALL ScCellRangesObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr(rServiceName); + return aServiceStr.EqualsAscii( SCSHEETCELLRANGES_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellRangesObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(4); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSHEETCELLRANGES_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLPROPERTIES_SERVICE )); + pArray[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCHARPROPERTIES_SERVICE )); + pArray[3] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCPARAPROPERTIES_SERVICE )); + return aRet; +} + +//------------------------------------------------------------------------ + +// static +uno::Reference<table::XCellRange> ScCellRangeObj::CreateRangeFromDoc( ScDocument* pDoc, const ScRange& rR ) +{ + SfxObjectShell* pObjSh = pDoc->GetDocumentShell(); + if ( pObjSh && pObjSh->ISA(ScDocShell) ) + return new ScCellRangeObj( (ScDocShell*) pObjSh, rR ); + return NULL; +} + +//------------------------------------------------------------------------ + +ScCellRangeObj::ScCellRangeObj(ScDocShell* pDocSh, const ScRange& rR) : + ScCellRangesBase( pDocSh, rR ), + aRangePropSet( lcl_GetRangePropertyMap() ), + aRange( rR ) +{ + aRange.Justify(); // Anfang / Ende richtig +} + +ScCellRangeObj::~ScCellRangeObj() +{ +} + +void ScCellRangeObj::RefChanged() +{ + ScCellRangesBase::RefChanged(); + + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT(rRanges.Count() == 1, "was fuer Ranges ?!?!"); + const ScRange* pFirst = rRanges.GetObject(0); + if (pFirst) + { + aRange = *pFirst; + aRange.Justify(); + } +} + +uno::Any SAL_CALL ScCellRangeObj::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( sheet::XCellRangeAddressable ) + SC_QUERYINTERFACE( table::XCellRange ) + SC_QUERYINTERFACE( sheet::XSheetCellRange ) + SC_QUERYINTERFACE( sheet::XArrayFormulaRange ) + SC_QUERYINTERFACE( sheet::XCellRangeData ) + SC_QUERYINTERFACE( sheet::XCellRangeFormula ) + SC_QUERYINTERFACE( sheet::XMultipleOperation ) + SC_QUERYINTERFACE( util::XMergeable ) + SC_QUERYINTERFACE( sheet::XCellSeries ) + SC_QUERYINTERFACE( table::XAutoFormattable ) + SC_QUERYINTERFACE( util::XSortable ) + SC_QUERYINTERFACE( sheet::XSheetFilterableEx ) + SC_QUERYINTERFACE( sheet::XSheetFilterable ) + SC_QUERYINTERFACE( sheet::XSubTotalCalculatable ) + SC_QUERYINTERFACE( table::XColumnRowRange ) + SC_QUERYINTERFACE( util::XImportable ) + SC_QUERYINTERFACE( sheet::XCellFormatRangesSupplier ) + SC_QUERYINTERFACE( sheet::XUniqueCellFormatRangesSupplier ) + + return ScCellRangesBase::queryInterface( rType ); +} + +void SAL_CALL ScCellRangeObj::acquire() throw() +{ + ScCellRangesBase::acquire(); +} + +void SAL_CALL ScCellRangeObj::release() throw() +{ + ScCellRangesBase::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScCellRangeObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = ScCellRangesBase::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 16 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XCellRangeAddressable>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<sheet::XSheetCellRange>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XArrayFormulaRange>*)0); + pPtr[nParentLen + 3] = getCppuType((const uno::Reference<sheet::XCellRangeData>*)0); + pPtr[nParentLen + 4] = getCppuType((const uno::Reference<sheet::XCellRangeFormula>*)0); + pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XMultipleOperation>*)0); + pPtr[nParentLen + 6] = getCppuType((const uno::Reference<util::XMergeable>*)0); + pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XCellSeries>*)0); + pPtr[nParentLen + 8] = getCppuType((const uno::Reference<table::XAutoFormattable>*)0); + pPtr[nParentLen + 9] = getCppuType((const uno::Reference<util::XSortable>*)0); + pPtr[nParentLen +10] = getCppuType((const uno::Reference<sheet::XSheetFilterableEx>*)0); + pPtr[nParentLen +11] = getCppuType((const uno::Reference<sheet::XSubTotalCalculatable>*)0); + pPtr[nParentLen +12] = getCppuType((const uno::Reference<table::XColumnRowRange>*)0); + pPtr[nParentLen +13] = getCppuType((const uno::Reference<util::XImportable>*)0); + pPtr[nParentLen +14] = getCppuType((const uno::Reference<sheet::XCellFormatRangesSupplier>*)0); + pPtr[nParentLen +15] = getCppuType((const uno::Reference<sheet::XUniqueCellFormatRangesSupplier>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScCellRangeObj::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// XCellRange + +// ColumnCount / RowCount sind weggefallen +//! werden im Writer fuer Tabellen noch gebraucht ??? + +uno::Reference<table::XCell> ScCellRangeObj::GetCellByPosition_Impl( + sal_Int32 nColumn, sal_Int32 nRow ) + throw(lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + throw uno::RuntimeException(); + + if ( nColumn >= 0 && nRow >= 0 ) + { + sal_Int32 nPosX = aRange.aStart.Col() + nColumn; + sal_Int32 nPosY = aRange.aStart.Row() + nRow; + + if ( nPosX <= aRange.aEnd.Col() && nPosY <= aRange.aEnd.Row() ) + { + ScAddress aNew( (USHORT)nPosX, (USHORT)nPosY, aRange.aStart.Tab() ); + return new ScCellObj( pDocSh, aNew ); + } + } + + throw lang::IndexOutOfBoundsException(); + return NULL; +} + +uno::Reference<table::XCell> SAL_CALL ScCellRangeObj::getCellByPosition( + sal_Int32 nColumn, sal_Int32 nRow ) + throw(lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + return GetCellByPosition_Impl(nColumn, nRow); +} + +uno::Reference<table::XCellRange> SAL_CALL ScCellRangeObj::getCellRangeByPosition( + sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) + throw(lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + throw uno::RuntimeException(); + + if ( nLeft >= 0 && nTop >= 0 && nRight >= 0 && nBottom >= 0 ) + { + sal_Int32 nStartX = aRange.aStart.Col() + nLeft; + sal_Int32 nStartY = aRange.aStart.Row() + nTop; + sal_Int32 nEndX = aRange.aStart.Col() + nRight; + sal_Int32 nEndY = aRange.aStart.Row() + nBottom; + + if ( nStartX <= nEndX && nEndX <= aRange.aEnd.Col() && + nStartY <= nEndY && nEndY <= aRange.aEnd.Row() ) + { + ScRange aNew( (USHORT)nStartX, (USHORT)nStartY, aRange.aStart.Tab(), + (USHORT)nEndX, (USHORT)nEndY, aRange.aEnd.Tab() ); + return new ScCellRangeObj( pDocSh, aNew ); + } + } + + throw lang::IndexOutOfBoundsException(); + return NULL; +} + +uno::Reference<table::XCellRange> SAL_CALL ScCellRangeObj::getCellRangeByName( + const ::rtl::OUString& aName ) throw(uno::RuntimeException) +{ + // name refers to the whole document (with the range's table as default), + // valid only if the range is within this range + + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = aRange.aStart.Tab(); + + ScRange aCellRange; + BOOL bFound = FALSE; + String aString = aName; + USHORT nParse = aCellRange.ParseAny( aString, pDoc ); + if ( nParse & SCA_VALID ) + { + if ( !(nParse & SCA_TAB_3D) ) // keine Tabelle angegeben -> auf dieser Tabelle + { + aCellRange.aStart.SetTab(nTab); + aCellRange.aEnd.SetTab(nTab); + } + bFound = TRUE; + } + else + { + ScRangeUtil aRangeUtil; + if ( aRangeUtil.MakeRangeFromName( aString, pDoc, nTab, aCellRange, RUTL_NAMES ) || + aRangeUtil.MakeRangeFromName( aString, pDoc, nTab, aCellRange, RUTL_DBASE ) ) + bFound = TRUE; + } + + if (bFound) // valid only if within this object's range + { + if (!aRange.In(aCellRange)) + bFound = FALSE; + } + + if (bFound) + { + if ( aCellRange.aStart == aCellRange.aEnd ) + return new ScCellObj( pDocSh, aCellRange.aStart ); + else + return new ScCellRangeObj( pDocSh, aCellRange ); + } + } + + throw uno::RuntimeException(); + return NULL; +} + +// XColumnRowRange + +uno::Reference<table::XTableColumns> SAL_CALL ScCellRangeObj::getColumns() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + return new ScTableColumnsObj( pDocSh, aRange.aStart.Tab(), + aRange.aStart.Col(), aRange.aEnd.Col() ); + + OSL_FAIL("Dokument ungueltig"); + return NULL; +} + +uno::Reference<table::XTableRows> SAL_CALL ScCellRangeObj::getRows() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + return new ScTableRowsObj( pDocSh, aRange.aStart.Tab(), + aRange.aStart.Row(), aRange.aEnd.Row() ); + + OSL_FAIL("Dokument ungueltig"); + return NULL; +} + +// XAddressableCellRange + +table::CellRangeAddress SAL_CALL ScCellRangeObj::getRangeAddress() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aRet; + ScUnoConversion::FillApiRange( aRet, aRange ); + return aRet; +} + +// XSheetCellRange + +uno::Reference<sheet::XSpreadsheet> SAL_CALL ScCellRangeObj::getSpreadsheet() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + return new ScTableSheetObj( pDocSh, aRange.aStart.Tab() ); + + OSL_FAIL("Dokument ungueltig"); + return NULL; +} + +// XArrayFormulaRange + +::rtl::OUString SAL_CALL ScCellRangeObj::getArrayFormula() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // Matrix-Formel, wenn eindeutig Teil einer Matrix, + // also wenn Anfang und Ende des Blocks zur selben Matrix gehoeren. + // Sonst Leerstring. + + String aFormula; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + ScDocument* pDoc = pDocSh->GetDocument(); + const ScBaseCell* pCell1 = pDoc->GetCell( aRange.aStart ); + const ScBaseCell* pCell2 = pDoc->GetCell( aRange.aEnd ); + if ( pCell1 && pCell2 && pCell1->GetCellType() == CELLTYPE_FORMULA && + pCell2->GetCellType() == CELLTYPE_FORMULA ) + { + const ScFormulaCell* pFCell1 = (const ScFormulaCell*)pCell1; + const ScFormulaCell* pFCell2 = (const ScFormulaCell*)pCell2; + ScAddress aStart1; + ScAddress aStart2; + if ( pFCell1->GetMatrixOrigin( aStart1 ) && pFCell2->GetMatrixOrigin( aStart2 ) ) + { + if ( aStart1 == aStart2 ) // beides dieselbe Matrix + pFCell1->GetFormula( aFormula ); // egal, von welcher Zelle + } + } + } + return aFormula; +} + +void SAL_CALL ScCellRangeObj::setArrayFormula( const ::rtl::OUString& aFormula ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + String aString = aFormula; + ScDocFunc aFunc(*pDocSh); + if ( aString.Len() ) + { + if ( ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ) ) + { + // #74681# don't set array formula for sheet object + throw uno::RuntimeException(); + } + + aFunc.EnterMatrix( aRange, NULL, aString, TRUE, TRUE ); + } + else + { + // empty string -> erase array formula + ScMarkData aMark; + aMark.SetMarkArea( aRange ); + aMark.SelectTable( aRange.aStart.Tab(), TRUE ); + aFunc.DeleteContents( aMark, IDF_CONTENTS, TRUE, TRUE ); + } + } +} + +// XCellRangeData + +uno::Sequence< uno::Sequence<uno::Any> > SAL_CALL ScCellRangeObj::getDataArray() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ) ) + { + // don't create a data array for the sheet + throw uno::RuntimeException(); + } + + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + uno::Any aAny; + // bAllowNV = TRUE: errors as void + if ( ScRangeToSequence::FillMixedArray( aAny, pDocSh->GetDocument(), aRange, TRUE ) ) + { + uno::Sequence< uno::Sequence<uno::Any> > aSeq; + if ( aAny >>= aSeq ) + return aSeq; // success + } + } + + throw uno::RuntimeException(); // no other exceptions specified + return uno::Sequence< uno::Sequence<uno::Any> >(0); +} + +void SAL_CALL ScCellRangeObj::setDataArray( + const uno::Sequence< uno::Sequence<uno::Any> >& aArray ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + BOOL bDone = FALSE; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + //! move lcl_PutDataArray to docfunc? + bDone = lcl_PutDataArray( *pDocSh, aRange, aArray ); + } + + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +// XCellRangeFormula + +uno::Sequence< uno::Sequence< ::rtl::OUString> > SAL_CALL ScCellRangeObj::getFormulaArray() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( ScTableSheetObj::getImplementation( (cppu::OWeakObject*)this ) ) + { + // don't create a data array for the sheet + throw uno::RuntimeException(); + } + + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + USHORT nStartCol = aRange.aStart.Col(); + USHORT nStartRow = aRange.aStart.Row(); + USHORT nEndCol = aRange.aEnd.Col(); + USHORT nEndRow = aRange.aEnd.Row(); + USHORT nColCount = nEndCol + 1 - nStartCol; + USHORT nRowCount = nEndRow + 1 - nStartRow; + USHORT nTab = aRange.aStart.Tab(); + + uno::Sequence< uno::Sequence< ::rtl::OUString> > aRowSeq( nRowCount ); + uno::Sequence< ::rtl::OUString>* pRowAry = aRowSeq.getArray(); + for (USHORT nRowIndex = 0; nRowIndex < nRowCount; nRowIndex++) + { + uno::Sequence< ::rtl::OUString> aColSeq( nColCount ); + ::rtl::OUString* pColAry = aColSeq.getArray(); + for (USHORT nColIndex = 0; nColIndex < nColCount; nColIndex++) + pColAry[nColIndex] = lcl_GetInputString( pDocSh, + ScAddress( nStartCol+nColIndex, nStartRow+nRowIndex, nTab ), TRUE ); + + pRowAry[nRowIndex] = aColSeq; + } + + return aRowSeq; + } + + throw uno::RuntimeException(); // no other exceptions specified + return uno::Sequence< uno::Sequence< ::rtl::OUString> >(0); +} + +void SAL_CALL ScCellRangeObj::setFormulaArray( + const uno::Sequence< uno::Sequence< ::rtl::OUString> >& aArray ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + BOOL bDone = FALSE; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + bDone = lcl_PutFormulaArray( *pDocSh, aRange, aArray ); + } + + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +// XMultipleOperation + +void SAL_CALL ScCellRangeObj::setTableOperation( const table::CellRangeAddress& aFormulaRange, + sheet::TableOperationMode nMode, + const table::CellAddress& aColumnCell, + const table::CellAddress& aRowCell ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + ScTabOpParam aParam; + aParam.aRefFormulaCell = ScRefTripel( (USHORT)aFormulaRange.StartColumn, + (USHORT)aFormulaRange.StartRow, aFormulaRange.Sheet, + FALSE, FALSE, FALSE ); + aParam.aRefFormulaEnd = ScRefTripel( (USHORT)aFormulaRange.EndColumn, + (USHORT)aFormulaRange.EndRow, aFormulaRange.Sheet, + FALSE, FALSE, FALSE ); + aParam.aRefRowCell = ScRefTripel( (USHORT)aRowCell.Column, + (USHORT)aRowCell.Row, aRowCell.Sheet, + FALSE, FALSE, FALSE ); + aParam.aRefColCell = ScRefTripel( (USHORT)aColumnCell.Column, + (USHORT)aColumnCell.Row, aColumnCell.Sheet, + FALSE, FALSE, FALSE ); + switch (nMode) + { + case sheet::TableOperationMode_COLUMN: + aParam.nMode = 0; + break; + case sheet::TableOperationMode_ROW: + aParam.nMode = 1; + break; + case sheet::TableOperationMode_BOTH: + aParam.nMode = 2; + break; + default: + break; + } + } +} + +// XMergeable + +void SAL_CALL ScCellRangeObj::merge( sal_Bool bMerge ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocFunc aFunc(*pDocSh); + if ( bMerge ) + aFunc.MergeCells( aRange, FALSE, TRUE, TRUE ); + } +} + +sal_Bool SAL_CALL ScCellRangeObj::getIsMerged() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + return pDocSh && pDocSh->GetDocument()->HasAttrib( aRange, HASATTR_MERGED ); +} + +// XCellSeries + +void SAL_CALL ScCellRangeObj::fillSeries( sheet::FillDirection nFillDirection, + sheet::FillMode nFillMode, sheet::FillDateMode nFillDateMode, + double /*fStep*/, double /*fEndValue*/ ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + switch (nFillDirection) + { + case sheet::FillDirection_TO_BOTTOM: + break; + case sheet::FillDirection_TO_RIGHT: + break; + case sheet::FillDirection_TO_TOP: + break; + case sheet::FillDirection_TO_LEFT: + break; + default: + break; + } + + switch ( nFillMode ) + { + case sheet::FillMode_SIMPLE: + break; + case sheet::FillMode_LINEAR: + break; + case sheet::FillMode_GROWTH: + break; + case sheet::FillMode_DATE: + break; + case sheet::FillMode_AUTO: + break; + default: + break; + } + + switch ( nFillDateMode ) + { + case sheet::FillDateMode_FILL_DATE_DAY: + break; + case sheet::FillDateMode_FILL_DATE_WEEKDAY: + break; + case sheet::FillDateMode_FILL_DATE_MONTH: + break; + case sheet::FillDateMode_FILL_DATE_YEAR: + break; + default: + break; + } + } +} + +void SAL_CALL ScCellRangeObj::fillAuto( sheet::FillDirection nFillDirection, + sal_Int32 nSourceCount ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh && nSourceCount ) + { + ScRange aSourceRange = aRange; + switch (nFillDirection) + { + case sheet::FillDirection_TO_BOTTOM: + aSourceRange.aEnd.SetRow( aSourceRange.aStart.Row() + nSourceCount - 1 ); + break; + case sheet::FillDirection_TO_RIGHT: + aSourceRange.aEnd.SetCol( aSourceRange.aStart.Col() + nSourceCount - 1 ); + break; + case sheet::FillDirection_TO_TOP: + aSourceRange.aStart.SetRow( aSourceRange.aEnd.Row() - nSourceCount + 1 ); + break; + case sheet::FillDirection_TO_LEFT: + aSourceRange.aStart.SetCol( aSourceRange.aEnd.Col() - nSourceCount + 1 ); + break; + default: + break; + } + } +} + +// XAutoFormattable + +void SAL_CALL ScCellRangeObj::autoFormat( const ::rtl::OUString& aName ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAutoFormat* pAutoFormat = ScGlobal::GetAutoFormat(); + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh && pAutoFormat ) + { + String aNameString = aName; + USHORT nCount = pAutoFormat->GetCount(); + USHORT nIndex; + String aCompare; + for (nIndex=0; nIndex<nCount; nIndex++) + { + (*pAutoFormat)[nIndex]->GetName(aCompare); + if ( aCompare == aNameString ) //! Case-insensitiv ??? + break; + } + if (nIndex<nCount) + { + ScDocFunc aFunc(*pDocSh); + aFunc.AutoFormat( aRange, NULL, nIndex, TRUE, TRUE ); + } + else + throw lang::IllegalArgumentException(); + } +} + +// XSortable + +uno::Sequence<beans::PropertyValue> SAL_CALL ScCellRangeObj::createSortDescriptor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSortParam aParam; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + // DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich + ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, TRUE ); + if (pData) + { + pData->GetSortParam(aParam); + + // im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = aParam.bByRow ? aDBRange.aStart.Col() : aDBRange.aStart.Row(); + for (USHORT i=0; i<MAXSORT; i++) + if ( aParam.bDoSort[i] && aParam.nField[i] >= nFieldStart ) + aParam.nField[i] -= nFieldStart; + } + } + + uno::Sequence<beans::PropertyValue> aSeq( ScSortDescriptor::GetPropertyCount() ); + ScSortDescriptor::FillProperties( aSeq, aParam ); + return aSeq; +} + +void SAL_CALL ScCellRangeObj::sort( const uno::Sequence<beans::PropertyValue>& aDescriptor ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + USHORT i; + ScSortParam aParam; + ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_MAKE, TRUE ); // ggf. Bereich anlegen + if (pData) + { + // alten Einstellungen holen, falls nicht alles neu gesetzt wird + pData->GetSortParam(aParam); + USHORT nOldStart = aParam.bByRow ? aRange.aStart.Col() : aRange.aStart.Row(); + for (i=0; i<MAXSORT; i++) + if ( aParam.bDoSort[i] && aParam.nField[i] >= nOldStart ) + aParam.nField[i] -= nOldStart; + } + + ScSortDescriptor::FillSortParam( aParam, aDescriptor ); + + // im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt + // ByRow kann bei FillSortParam umgesetzt worden sein + USHORT nFieldStart = aParam.bByRow ? aRange.aStart.Col() : aRange.aStart.Row(); + for (i=0; i<MAXSORT; i++) + aParam.nField[i] += nFieldStart; + + aParam.nCol1 = aRange.aStart.Col(); + aParam.nRow1 = aRange.aStart.Row(); + aParam.nCol2 = aRange.aEnd.Col(); + aParam.nRow2 = aRange.aEnd.Row(); + + pDocSh->GetDBData( aRange, SC_DB_MAKE, TRUE ); // ggf. Bereich anlegen + } +} + +// XFilterable + +uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScCellRangeObj::createFilterDescriptor( + sal_Bool bEmpty ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + ScFilterDescriptor* pNew = new ScFilterDescriptor(pDocSh); + if ( !bEmpty && pDocSh ) + { + // DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich + ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, TRUE ); + if (pData) + { + ScQueryParam aParam; + pData->GetQueryParam(aParam); + // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = aParam.bByRow ? aDBRange.aStart.Col() : aDBRange.aStart.Row(); + USHORT nCount = aParam.GetEntryCount(); + for (USHORT i=0; i<nCount; i++) + { + ScQueryEntry& rEntry = aParam.GetEntry(i); + if (rEntry.bDoQuery && rEntry.nField >= nFieldStart) + rEntry.nField -= nFieldStart; + } + pNew->SetParam(aParam); + } + } + return pNew; +} + +void SAL_CALL ScCellRangeObj::filter( const uno::Reference<sheet::XSheetFilterDescriptor>& xDescriptor ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // das koennte theoretisch ein fremdes Objekt sein, also nur das + // oeffentliche XSheetFilterDescriptor Interface benutzen, um + // die Daten in ein ScFilterDescriptor Objekt zu kopieren: + //! wenn es schon ein ScFilterDescriptor ist, direkt per getImplementation? + + ScDocShell* pDocSh = GetDocShell(); + ScFilterDescriptor aImpl(pDocSh); + aImpl.setFilterFields( xDescriptor->getFilterFields() ); + // Rest sind jetzt Properties... + + uno::Reference<beans::XPropertySet> xPropSet( xDescriptor, uno::UNO_QUERY ); + if (xPropSet.is()) + lcl_CopyProperties( aImpl, *(beans::XPropertySet*)xPropSet.get() ); + + // + // ausfuehren... + // + + if (pDocSh) + { + ScQueryParam aParam = aImpl.GetParam(); + // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt + USHORT nFieldStart = aParam.bByRow ? aRange.aStart.Col() : aRange.aStart.Row(); + USHORT nCount = aParam.GetEntryCount(); + for (USHORT i=0; i<nCount; i++) + { + ScQueryEntry& rEntry = aParam.GetEntry(i); + if (rEntry.bDoQuery) + { + rEntry.nField += nFieldStart; + // Im Dialog wird immer der String angezeigt -> muss zum Wert passen + if ( !rEntry.bQueryByString ) + pDocSh->GetDocument()->GetFormatTable()-> + GetInputLineString( rEntry.nVal, 0, *rEntry.pStr ); + } + } + + aParam.nCol1 = aRange.aStart.Col(); + aParam.nRow1 = aRange.aStart.Row(); + aParam.nCol2 = aRange.aEnd.Col(); + aParam.nRow2 = aRange.aEnd.Row(); + + pDocSh->GetDBData( aRange, SC_DB_MAKE, TRUE ); // ggf. Bereich anlegen + } +} + +//! get/setAutoFilter als Properties!!! + +// XAdvancedFilterSource + +uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScCellRangeObj::createFilterDescriptorByObject( + const uno::Reference<sheet::XSheetFilterable>& xObject ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // this ist hier nicht der Bereich, der gefiltert wird, sondern der + // Bereich mit der Abfrage... + + uno::Reference<sheet::XCellRangeAddressable> xAddr( xObject, uno::UNO_QUERY ); + + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh && xAddr.is() ) + { + //! Test, ob xObject im selben Dokument ist + + ScFilterDescriptor* pNew = new ScFilterDescriptor(pDocSh); //! stattdessen vom Objekt? + + ScQueryParam aParam = pNew->GetParam(); + aParam.bHasHeader = TRUE; + + table::CellRangeAddress aDataAddress = xAddr->getRangeAddress(); + aParam.nCol1 = (USHORT)aDataAddress.StartColumn; + aParam.nRow1 = (USHORT)aDataAddress.StartRow; + aParam.nCol2 = (USHORT)aDataAddress.EndColumn; + aParam.nRow2 = (USHORT)aDataAddress.EndRow; + aParam.nTab = aDataAddress.Sheet; + + delete pNew; + return NULL; // ungueltig -> null + } + + OSL_FAIL("kein Dokument oder kein Bereich"); + return NULL; +} + +// XSubTotalSource + +uno::Reference<sheet::XSubTotalDescriptor> SAL_CALL ScCellRangeObj::createSubTotalDescriptor( + sal_Bool bEmpty ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalDescriptor* pNew = new ScSubTotalDescriptor; + ScDocShell* pDocSh = GetDocShell(); + if ( !bEmpty && pDocSh ) + { + // DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich + ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, TRUE ); + if (pData) + { + ScSubTotalParam aParam; + pData->GetSubTotalParam(aParam); + // im SubTotalDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = aDBRange.aStart.Col(); + for (USHORT i=0; i<MAXSUBTOTAL; i++) + { + if ( aParam.bGroupActive[i] ) + { + if ( aParam.nField[i] >= nFieldStart ) + aParam.nField[i] -= nFieldStart; + for (USHORT j=0; j<aParam.nSubTotals[i]; j++) + if ( aParam.pSubTotals[i][j] >= nFieldStart ) + aParam.pSubTotals[i][j] -= nFieldStart; + } + } + pNew->SetParam(aParam); + } + } + return pNew; +} + +void SAL_CALL ScCellRangeObj::applySubTotals( + const uno::Reference<sheet::XSubTotalDescriptor>& xDescriptor, + sal_Bool bReplace ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if (!xDescriptor.is()) return; + + ScDocShell* pDocSh = GetDocShell(); + ScSubTotalDescriptorBase* pImp = + ScSubTotalDescriptorBase::getImplementation( xDescriptor ); + + if (pDocSh && pImp) + { + ScSubTotalParam aParam; + pImp->GetData(aParam); // virtuelle Methode der Basisklasse + + // im SubTotalDescriptor sind die Fields innerhalb des Bereichs gezaehlt + USHORT nFieldStart = aRange.aStart.Col(); + for (USHORT i=0; i<MAXSUBTOTAL; i++) + { + if ( aParam.bGroupActive[i] ) + { + aParam.nField[i] += nFieldStart; + for (USHORT j=0; j<aParam.nSubTotals[i]; j++) + aParam.pSubTotals[i][j] += nFieldStart; + } + } + + aParam.bReplace = bReplace; + aParam.nCol1 = aRange.aStart.Col(); + aParam.nRow1 = aRange.aStart.Row(); + aParam.nCol2 = aRange.aEnd.Col(); + aParam.nRow2 = aRange.aEnd.Row(); + + pDocSh->GetDBData( aRange, SC_DB_MAKE, TRUE ); // ggf. Bereich anlegen + } +} + +void SAL_CALL ScCellRangeObj::removeSubTotals() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + ScSubTotalParam aParam; + ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, TRUE ); + if (pData) + pData->GetSubTotalParam(aParam); // auch bei Remove die Feld-Eintraege behalten + + aParam.bRemoveOnly = TRUE; + aParam.nCol1 = aRange.aStart.Col(); + aParam.nRow1 = aRange.aStart.Row(); + aParam.nCol2 = aRange.aEnd.Col(); + aParam.nRow2 = aRange.aEnd.Row(); + + pDocSh->GetDBData( aRange, SC_DB_MAKE, TRUE ); // ggf. Bereich anlegen + } +} + +uno::Sequence<beans::PropertyValue> SAL_CALL ScCellRangeObj::createImportDescriptor( sal_Bool bEmpty ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScImportParam aParam; + ScDocShell* pDocSh = GetDocShell(); + if ( !bEmpty && pDocSh ) + { + // DB-Bereich anlegen erst beim Ausfuehren, per API immer genau den Bereich + ScDBData* pData = pDocSh->GetDBData( aRange, SC_DB_OLD, TRUE ); + if (pData) + pData->GetImportParam(aParam); + } + + uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() ); + ScImportDescriptor::FillProperties( aSeq, aParam ); + return aSeq; +} + +void SAL_CALL ScCellRangeObj::doImport( const uno::Sequence<beans::PropertyValue>& aDescriptor ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + ScImportParam aParam; + ScImportDescriptor::FillImportParam( aParam, aDescriptor ); + + USHORT nTab = aRange.aStart.Tab(); + aParam.nCol1 = aRange.aStart.Col(); + aParam.nRow1 = aRange.aStart.Row(); + aParam.nCol2 = aRange.aEnd.Col(); + aParam.nRow2 = aRange.aEnd.Row(); + + //! TODO: could we get passed a valid result set by any means? + uno::Reference< sdbc::XResultSet > xResultSet; + + pDocSh->GetDBData( aRange, SC_DB_MAKE, TRUE ); // ggf. Bereich anlegen + + ScDBDocFunc aFunc(*pDocSh); // Bereich muss angelegt sein + aFunc.DoImport( nTab, aParam, xResultSet, NULL, TRUE, FALSE ); //! Api-Flag als Parameter + } +} + +// XCellFormatRangesSupplier + +uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangeObj::getCellFormatRanges() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return new ScCellFormatsObj( pDocSh, aRange ); + return NULL; +} + +// XUniqueCellFormatRangesSupplier + +uno::Reference<container::XIndexAccess> SAL_CALL ScCellRangeObj::getUniqueCellFormatRanges() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return new ScUniqueCellFormatsObj( pDocSh, aRange ); + return NULL; +} + +// XPropertySet erweitert fuer Range-Properties + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellRangeObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aRangePropSet.getPropertyMap() ); + return aRef; +} + +void ScCellRangeObj::SetOnePropertyValue( const SfxItemPropertyMap* pMap, const uno::Any& aValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + // Range has only Position and Size in addition to ScCellRangesBase, both are ReadOnly + // -> nothing to do here + + ScCellRangesBase::SetOnePropertyValue( pMap, aValue ); +} + +void ScCellRangeObj::GetOnePropertyValue( const SfxItemPropertyMap* pMap, + uno::Any& rAny ) + throw(uno::RuntimeException) +{ + if ( pMap ) + { + if ( pMap->nWID == SC_WID_UNO_POS ) + { + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + // GetMMRect converts using HMM_PER_TWIPS, like the DrawingLayer + Rectangle aMMRect = pDocSh->GetDocument()->GetMMRect( + aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ); + awt::Point aPos( aMMRect.Left(), aMMRect.Top() ); + rAny <<= aPos; + } + } + else if ( pMap->nWID == SC_WID_UNO_SIZE ) + { + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + // GetMMRect converts using HMM_PER_TWIPS, like the DrawingLayer + Rectangle aMMRect = pDocSh->GetDocument()->GetMMRect( + aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aEnd.Row(), aRange.aStart.Tab() ); + Size aSize = aMMRect.GetSize(); + awt::Size aAwtSize( aSize.Width(), aSize.Height() ); + rAny <<= aAwtSize; + } + } + else + ScCellRangesBase::GetOnePropertyValue( pMap, rAny ); + + } +} + +const SfxItemPropertyMap* ScCellRangeObj::GetItemPropertyMap() +{ + return lcl_GetRangePropertyMap(); +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScCellRangeObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScCellRangeObj" )); +} + +sal_Bool SAL_CALL ScCellRangeObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCSHEETCELLRANGE_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLRANGE_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellRangeObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(5); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSHEETCELLRANGE_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLRANGE_SERVICE )); + pArray[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLPROPERTIES_SERVICE )); + pArray[3] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCHARPROPERTIES_SERVICE )); + pArray[4] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCPARAPROPERTIES_SERVICE )); + return aRet; +} + + +const SfxItemPropertyMap* ScCellObj::GetEditPropertyMap() // static +{ + return lcl_GetEditPropertyMap(); +} + +ScCellObj::ScCellObj(ScDocShell* pDocSh, const ScAddress& rP) : + ScCellRangeObj( pDocSh, ScRange(rP,rP) ), + pUnoText( NULL ), + aCellPropSet( lcl_GetCellPropertyMap() ), + aCellPos( rP ), + nActionLockCount( 0 ) +{ + // pUnoText is allocated on demand (GetUnoText) + // can't be aggregated because getString/setString is handled here +} + +SvxUnoText& ScCellObj::GetUnoText() +{ + if (!pUnoText) + { + pUnoText = new ScCellTextObj( GetDocShell(), aCellPos ); + pUnoText->acquire(); + if (nActionLockCount) + { + ScSharedCellEditSource* pEditSource = + static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource()); + if (pEditSource) + pEditSource->SetDoUpdateData(sal_False); + } + } + return *pUnoText; +} + +ScCellObj::~ScCellObj() +{ + if (pUnoText) + pUnoText->release(); +} + +void ScCellObj::RefChanged() +{ + ScCellRangeObj::RefChanged(); + + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT(rRanges.Count() == 1, "was fuer Ranges ?!?!"); + const ScRange* pFirst = rRanges.GetObject(0); + if (pFirst) + aCellPos = pFirst->aStart; +} + +uno::Any SAL_CALL ScCellObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( table::XCell ) + SC_QUERYINTERFACE( sheet::XCellAddressable ) + SC_QUERYINTERFACE( text::XText ) + SC_QUERYINTERFACE( text::XSimpleText ) + SC_QUERYINTERFACE( text::XTextRange ) + SC_QUERYINTERFACE( container::XEnumerationAccess ) + SC_QUERYINTERFACE( container::XElementAccess ) + SC_QUERYINTERFACE( sheet::XSheetAnnotationAnchor ) + SC_QUERYINTERFACE( text::XTextFieldsSupplier ) + SC_QUERYINTERFACE( document::XActionLockable ) + + return ScCellRangeObj::queryInterface( rType ); +} + +void SAL_CALL ScCellObj::acquire() throw() +{ + ScCellRangeObj::acquire(); +} + +void SAL_CALL ScCellObj::release() throw() +{ + ScCellRangeObj::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScCellObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = ScCellRangeObj::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 7 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<table::XCell>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<sheet::XCellAddressable>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<text::XText>*)0); + pPtr[nParentLen + 3] = getCppuType((const uno::Reference<container::XEnumerationAccess>*)0); + pPtr[nParentLen + 4] = getCppuType((const uno::Reference<sheet::XSheetAnnotationAnchor>*)0); + pPtr[nParentLen + 5] = getCppuType((const uno::Reference<text::XTextFieldsSupplier>*)0); + pPtr[nParentLen + 6] = getCppuType((const uno::Reference<document::XActionLockable>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScCellObj::getImplementationId() throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// Hilfsfunktionen + +String ScCellObj::GetInputString_Impl(BOOL bEnglish) const // fuer getFormula / FormulaLocal +{ + return lcl_GetInputString( GetDocShell(), aCellPos, bEnglish ); +} + +String ScCellObj::GetOutputString_Impl() const +{ + ScDocShell* pDocSh = GetDocShell(); + String aVal; + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + ScBaseCell* pCell = pDoc->GetCell( aCellPos ); + if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE ) + { + if ( pCell->GetCellType() == CELLTYPE_EDIT ) + { + // GetString an der EditCell macht Leerzeichen aus Umbruechen, + // hier werden die Umbrueche aber gebraucht + const EditTextObject* pData = ((ScEditCell*)pCell)->GetData(); + if (pData) + { + EditEngine& rEngine = pDoc->GetEditEngine(); + rEngine.SetText( *pData ); + aVal = rEngine.GetText( LINEEND_LF ); + } + // Edit-Zellen auch nicht per NumberFormatter formatieren + // (passend zur Ausgabe) + } + else + { + // wie in GetString am Dokument (column) + Color* pColor; + ULONG nNumFmt = pDoc->GetNumberFormat( aCellPos ); + ScCellFormat::GetString( pCell, nNumFmt, aVal, &pColor, *pDoc->GetFormatTable() ); + } + } + } + return aVal; +} + +void ScCellObj::SetString_Impl(const String& rString, BOOL bInterpret, BOOL bEnglish) +{ + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocFunc aFunc(*pDocSh); + aFunc.SetCellText( aCellPos, rString, bInterpret, bEnglish, TRUE ); + } +} + +double ScCellObj::GetValue_Impl() const +{ + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return pDocSh->GetDocument()->GetValue( aCellPos ); + + return 0.0; +} + +void ScCellObj::SetValue_Impl(double fValue) +{ + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocFunc aFunc(*pDocSh); + aFunc.PutCell( aCellPos, new ScValueCell(fValue), TRUE ); + } +} + +// only for XML import + +void ScCellObj::SetFormulaResultString( const ::rtl::OUString& rResult ) +{ + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScBaseCell* pCell = pDocSh->GetDocument()->GetCell( aCellPos ); + if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA ) + ((ScFormulaCell*)pCell)->SetString( rResult ); + } +} + +void ScCellObj::SetFormulaResultDouble( double fResult ) +{ + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScBaseCell* pCell = pDocSh->GetDocument()->GetCell( aCellPos ); + if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA ) + ((ScFormulaCell*)pCell)->SetDouble( fResult ); + } +} + +// XText + +uno::Reference<text::XTextCursor> SAL_CALL ScCellObj::createTextCursor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScCellTextCursor( *this ); +} + +uno::Reference<text::XTextCursor> SAL_CALL ScCellObj::createTextCursorByRange( + const uno::Reference<text::XTextRange>& aTextPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SvxUnoTextCursor* pCursor = new ScCellTextCursor( *this ); + uno::Reference<text::XTextCursor> xCursor = pCursor; + + SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition ); + if(pRange) + pCursor->SetSelection( pRange->GetSelection() ); + else + { + ScCellTextCursor* pOther = ScCellTextCursor::getImplementation( aTextPosition ); + if(pOther) + pCursor->SetSelection( pOther->GetSelection() ); + else + throw uno::RuntimeException(); + } + + return xCursor; +} + +::rtl::OUString SAL_CALL ScCellObj::getString() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetOutputString_Impl(); +} + +void SAL_CALL ScCellObj::setString( const ::rtl::OUString& aText ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aText; + SetString_Impl(aString, FALSE, FALSE); // immer Text + + // don't create pUnoText here if not there + if (pUnoText) + pUnoText->SetSelection(ESelection( 0,0, 0,aString.Len() )); +} + +void SAL_CALL ScCellObj::insertString( const uno::Reference<text::XTextRange>& xRange, + const ::rtl::OUString& aString, sal_Bool bAbsorb ) + throw(uno::RuntimeException) +{ + // special handling for ScCellTextCursor is no longer needed, + // SvxUnoText::insertString checks for SvxUnoTextRangeBase instead of SvxUnoTextRange + + SolarMutexGuard aGuard; + GetUnoText().insertString(xRange, aString, bAbsorb); +} + +void SAL_CALL ScCellObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange, + sal_Int16 nControlCharacter, sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + GetUnoText().insertControlCharacter(xRange, nControlCharacter, bAbsorb); +} + +void SAL_CALL ScCellObj::insertTextContent( const uno::Reference<text::XTextRange >& xRange, + const uno::Reference<text::XTextContent >& xContent, + sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh && xContent.is() ) + { + ScCellFieldObj* pCellField = ScCellFieldObj::getImplementation( xContent ); + SvxUnoTextRangeBase* pTextRange = ScCellTextCursor::getImplementation( xRange ); + + if ( pCellField && !pCellField->IsInserted() && pTextRange ) + { + SvxEditSource* pEditSource = pTextRange->GetEditSource(); + ESelection aSelection = pTextRange->GetSelection(); + + if (!bAbsorb) + { + // nicht ersetzen -> hinten anhaengen + aSelection.Adjust(); + aSelection.nStartPara = aSelection.nEndPara; + aSelection.nStartPos = aSelection.nEndPos; + } + + SvxFieldItem aItem = pCellField->CreateFieldItem(); + + SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder(); + pForwarder->QuickInsertField( aItem, aSelection ); + pEditSource->UpdateData(); + + // neue Selektion: ein Zeichen + aSelection.Adjust(); + aSelection.nEndPara = aSelection.nStartPara; + aSelection.nEndPos = aSelection.nStartPos + 1; + pCellField->InitDoc( pDocSh, aCellPos, aSelection ); + + // #91431# for bAbsorb=FALSE, the new selection must be behind the inserted content + // (the xml filter relies on this) + if (!bAbsorb) + aSelection.nStartPos = aSelection.nEndPos; + + pTextRange->SetSelection( aSelection ); + + return; + } + } + GetUnoText().insertTextContent(xRange, xContent, bAbsorb); +} + +void SAL_CALL ScCellObj::removeTextContent( const uno::Reference<text::XTextContent>& xContent ) + throw(container::NoSuchElementException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( xContent.is() ) + { + ScCellFieldObj* pCellField = ScCellFieldObj::getImplementation( xContent ); + if ( pCellField && pCellField->IsInserted() ) + { + //! Testen, ob das Feld in dieser Zelle ist + pCellField->DeleteField(); + return; + } + } + GetUnoText().removeTextContent(xContent); +} + +uno::Reference<text::XText> SAL_CALL ScCellObj::getText() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return this; +} + +uno::Reference<text::XTextRange> SAL_CALL ScCellObj::getStart() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().getStart(); +} + +uno::Reference<text::XTextRange> SAL_CALL ScCellObj::getEnd() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().getEnd(); +} + +uno::Reference<container::XEnumeration> SAL_CALL ScCellObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().createEnumeration(); +} + +uno::Type SAL_CALL ScCellObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().getElementType(); +} + +sal_Bool SAL_CALL ScCellObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().hasElements(); +} + +// XCell + +::rtl::OUString SAL_CALL ScCellObj::getFormula() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // TRUE = englisch + return GetInputString_Impl(TRUE); +} + +void SAL_CALL ScCellObj::setFormula( const ::rtl::OUString& aFormula ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aFormula; + SetString_Impl(aString, TRUE, TRUE); // englisch interpretieren +} + +double SAL_CALL ScCellObj::getValue() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetValue_Impl(); +} + +void SAL_CALL ScCellObj::setValue( double nValue ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SetValue_Impl(nValue); +} + +table::CellContentType SAL_CALL ScCellObj::getType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellContentType eRet = table::CellContentType_EMPTY; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + CellType eCalcType = pDocSh->GetDocument()->GetCellType( aCellPos ); + switch (eCalcType) + { + case CELLTYPE_VALUE: + eRet = table::CellContentType_VALUE; + break; + case CELLTYPE_STRING: + case CELLTYPE_EDIT: + eRet = table::CellContentType_TEXT; + break; + case CELLTYPE_FORMULA: + eRet = table::CellContentType_FORMULA; + break; + default: + eRet = table::CellContentType_EMPTY; + } + } + else + OSL_FAIL("keine DocShell"); //! Exception oder so? + + return eRet; +} + +table::CellContentType ScCellObj::GetResultType_Impl() +{ + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScBaseCell* pCell = pDocSh->GetDocument()->GetCell(aCellPos); + if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA ) + { + BOOL bValue = ((ScFormulaCell*)pCell)->IsValue(); + return bValue ? table::CellContentType_VALUE : table::CellContentType_TEXT; + } + } + return getType(); // wenn keine Formel +} + +sal_Int32 SAL_CALL ScCellObj::getError() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nError = 0; + ScDocShell* pDocSh = GetDocShell(); + if (pDocSh) + { + ScBaseCell* pCell = pDocSh->GetDocument()->GetCell( aCellPos ); + if ( pCell && pCell->GetCellType() == CELLTYPE_FORMULA ) + nError = ((ScFormulaCell*)pCell)->GetErrCode(); + // sonst bleibt's bei 0 + } + else + OSL_FAIL("keine DocShell"); //! Exception oder so? + + return nError; +} + +// XCellAddressable + +table::CellAddress SAL_CALL ScCellObj::getCellAddress() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellAddress aAdr; + aAdr.Sheet = aCellPos.Tab(); + aAdr.Column = aCellPos.Col(); + aAdr.Row = aCellPos.Row(); + return aAdr; +} + +// XSheetAnnotationAnchor + +uno::Reference<sheet::XSheetAnnotation> SAL_CALL ScCellObj::getAnnotation() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return new ScAnnotationObj( pDocSh, aCellPos ); + + OSL_FAIL("getAnnotation ohne DocShell"); + return NULL; +} + +// XFieldTypesSupplier + +uno::Reference<container::XEnumerationAccess> SAL_CALL ScCellObj::getTextFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return new ScCellFieldsObj( pDocSh, aCellPos ); + + return NULL; +} + +uno::Reference<container::XNameAccess> SAL_CALL ScCellObj::getTextFieldMasters() + throw(uno::RuntimeException) +{ + // sowas gibts nicht im Calc (?) + return NULL; +} + +// XPropertySet erweitert fuer Zell-Properties + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aCellPropSet.getPropertyMap() ); + return aRef; +} + +void ScCellObj::SetOnePropertyValue( const SfxItemPropertyMap* pMap, const uno::Any& aValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + if ( pMap ) + { + if ( pMap->nWID == SC_WID_UNO_FORMLOC ) + { + ::rtl::OUString aStrVal; + aValue >>= aStrVal; + String aString = aStrVal; + SetString_Impl(aString, TRUE, FALSE); // lokal interpretieren + } + else if ( pMap->nWID == SC_WID_UNO_FORMRT ) + { + // Read-Only + //! Exception oder so... + } + else + ScCellRangeObj::SetOnePropertyValue( pMap, aValue ); + } +} + +void ScCellObj::GetOnePropertyValue( const SfxItemPropertyMap* pMap, + uno::Any& rAny ) + throw(uno::RuntimeException) +{ + if ( pMap ) + { + if ( pMap->nWID == SC_WID_UNO_FORMLOC ) + { + // FALSE = lokal + String aFormStr = GetInputString_Impl(FALSE); + rAny <<= ::rtl::OUString( aFormStr ); + } + else if ( pMap->nWID == SC_WID_UNO_FORMRT ) + { + table::CellContentType eType = GetResultType_Impl(); + rAny <<= eType; + } + else + ScCellRangeObj::GetOnePropertyValue(pMap, rAny); + } +} + +const SfxItemPropertyMap* ScCellObj::GetItemPropertyMap() +{ + return lcl_GetCellPropertyMap(); +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScCellObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScCellObj" )); +} + +sal_Bool SAL_CALL ScCellObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + // CellRange/SheetCellRange are not in SheetCell service description, + // but ScCellObj is used instead of ScCellRangeObj in CellRanges collections, + // so it must support them + + String aServiceStr(rServiceName); + return aServiceStr.EqualsAscii( SCSHEETCELL_SERVICE ) || + aServiceStr.EqualsAscii( SCCELL_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCSHEETCELLRANGE_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLRANGE_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(7); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSHEETCELL_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELL_SERVICE )); + pArray[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLPROPERTIES_SERVICE )); + pArray[3] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCHARPROPERTIES_SERVICE )); + pArray[4] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCPARAPROPERTIES_SERVICE )); + pArray[5] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSHEETCELLRANGE_SERVICE )); + pArray[6] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLRANGE_SERVICE )); + return aRet; +} + +// XActionLockable + +sal_Bool SAL_CALL ScCellObj::isActionLocked() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return nActionLockCount != 0; +} + +void SAL_CALL ScCellObj::addActionLock() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!nActionLockCount) + { + if (pUnoText) + { + ScSharedCellEditSource* pEditSource = + static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource()); + if (pEditSource) + pEditSource->SetDoUpdateData(sal_False); + } + } + nActionLockCount++; +} + +void SAL_CALL ScCellObj::removeActionLock() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (nActionLockCount > 0) + { + nActionLockCount--; + if (!nActionLockCount) + { + if (pUnoText) + { + ScSharedCellEditSource* pEditSource = + static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource()); + if (pEditSource) + { + pEditSource->SetDoUpdateData(sal_True); + if (pEditSource->IsDirty()) + pEditSource->UpdateData(); + } + } + } + } +} + +void SAL_CALL ScCellObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pUnoText) + { + ScSharedCellEditSource* pEditSource = + static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource()); + if (pEditSource) + { + pEditSource->SetDoUpdateData(nLock == 0); + if ((nActionLockCount > 0) && (nLock == 0) && pEditSource->IsDirty()) + pEditSource->UpdateData(); + } + } + nActionLockCount = nLock; +} + +sal_Int16 SAL_CALL ScCellObj::resetActionLocks() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nRet(nActionLockCount); + if (pUnoText) + { + ScSharedCellEditSource* pEditSource = + static_cast<ScSharedCellEditSource*> (pUnoText->GetEditSource()); + if (pEditSource) + { + pEditSource->SetDoUpdateData(sal_True); + if (pEditSource->IsDirty()) + pEditSource->UpdateData(); + } + } + nActionLockCount = 0; + return nRet; +} + + +ScTableSheetObj::ScTableSheetObj( ScDocShell* pDocSh, USHORT nTab ) : + ScCellRangeObj( pDocSh, ScRange(0,0,nTab, MAXCOL,MAXROW,nTab) ), + aSheetPropSet(lcl_GetSheetPropertyMap()) +{ +} + +ScTableSheetObj::~ScTableSheetObj() +{ +} + +void ScTableSheetObj::InitInsertSheet(ScDocShell* pDocSh, USHORT nTab) +{ + InitInsertRange( pDocSh, ScRange(0,0,nTab, MAXCOL,MAXROW,nTab) ); +} + +uno::Any SAL_CALL ScTableSheetObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( sheet::XSpreadsheet ) + SC_QUERYINTERFACE( container::XNamed ) + SC_QUERYINTERFACE( sheet::XSheetPageBreak ) + SC_QUERYINTERFACE( sheet::XCellRangeMovement ) + SC_QUERYINTERFACE( table::XTableChartsSupplier ) + SC_QUERYINTERFACE( sheet::XDataPilotTablesSupplier ) + SC_QUERYINTERFACE( sheet::XScenariosSupplier ) + SC_QUERYINTERFACE( sheet::XSheetAnnotationsSupplier ) + SC_QUERYINTERFACE( drawing::XDrawPageSupplier ) + SC_QUERYINTERFACE( sheet::XPrintAreas ) + SC_QUERYINTERFACE( sheet::XSheetAuditing ) + SC_QUERYINTERFACE( sheet::XSheetOutline ) + SC_QUERYINTERFACE( util::XProtectable ) + SC_QUERYINTERFACE( sheet::XScenario ) + SC_QUERYINTERFACE( sheet::XSheetLinkable ) + + return ScCellRangeObj::queryInterface( rType ); +} + +void SAL_CALL ScTableSheetObj::acquire() throw() +{ + ScCellRangeObj::acquire(); +} + +void SAL_CALL ScTableSheetObj::release() throw() +{ + ScCellRangeObj::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScTableSheetObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = ScCellRangeObj::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 15 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheet>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<container::XNamed>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XSheetPageBreak>*)0); + pPtr[nParentLen + 3] = getCppuType((const uno::Reference<sheet::XCellRangeMovement>*)0); + pPtr[nParentLen + 4] = getCppuType((const uno::Reference<table::XTableChartsSupplier>*)0); + pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XDataPilotTablesSupplier>*)0); + pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XScenariosSupplier>*)0); + pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XSheetAnnotationsSupplier>*)0); + pPtr[nParentLen + 8] = getCppuType((const uno::Reference<drawing::XDrawPageSupplier>*)0); + pPtr[nParentLen + 9] = getCppuType((const uno::Reference<sheet::XPrintAreas>*)0); + pPtr[nParentLen +10] = getCppuType((const uno::Reference<sheet::XSheetAuditing>*)0); + pPtr[nParentLen +11] = getCppuType((const uno::Reference<sheet::XSheetOutline>*)0); + pPtr[nParentLen +12] = getCppuType((const uno::Reference<util::XProtectable>*)0); + pPtr[nParentLen +13] = getCppuType((const uno::Reference<sheet::XScenario>*)0); + pPtr[nParentLen +14] = getCppuType((const uno::Reference<sheet::XSheetLinkable>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScTableSheetObj::getImplementationId() throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// Hilfsfunktionen + +USHORT ScTableSheetObj::GetTab_Impl() const +{ + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT(rRanges.Count() == 1, "was fuer Ranges ?!?!"); + const ScRange* pFirst = rRanges.GetObject(0); + if (pFirst) + return pFirst->aStart.Tab(); + + return 0; // soll nicht sein +} + +// former XSheet + +uno::Reference<table::XTableCharts> SAL_CALL ScTableSheetObj::getCharts() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return new ScChartsObj( pDocSh, GetTab_Impl() ); + + OSL_FAIL("kein Dokument"); + return NULL; +} + +uno::Reference<sheet::XDataPilotTables> SAL_CALL ScTableSheetObj::getDataPilotTables() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return new ScDataPilotTablesObj( pDocSh, GetTab_Impl() ); + + OSL_FAIL("kein Dokument"); + return NULL; +} + +uno::Reference<sheet::XScenarios> SAL_CALL ScTableSheetObj::getScenarios() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + + if ( pDocSh ) + return new ScScenariosObj( pDocSh, GetTab_Impl() ); + + OSL_FAIL("kein Dokument"); + return NULL; +} + +uno::Reference<sheet::XSheetAnnotations> SAL_CALL ScTableSheetObj::getAnnotations() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + + if ( pDocSh ) + return new ScAnnotationsObj( pDocSh, GetTab_Impl() ); + + OSL_FAIL("kein Dokument"); + return NULL; +} + +uno::Reference<table::XCellRange> SAL_CALL ScTableSheetObj::getCellRangeByName( + const ::rtl::OUString& rRange ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScCellRangeObj::getCellRangeByName( rRange ); +} + +uno::Reference<sheet::XSheetCellCursor> SAL_CALL ScTableSheetObj::createCursor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + //! einzelne Zelle oder ganze Tabelle??????? + USHORT nTab = GetTab_Impl(); + return new ScCellCursorObj( pDocSh, ScRange( 0,0,nTab, MAXCOL,MAXROW,nTab ) ); + } + return NULL; +} + +uno::Reference<sheet::XSheetCellCursor> SAL_CALL ScTableSheetObj::createCursorByRange( + const uno::Reference<sheet::XSheetCellRange>& rRange ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh && rRange.is() ) + { + ScCellRangesBase* pRangesImp = ScCellRangesBase::getImplementation( rRange ); + if (pRangesImp) + { + const ScRangeList& rRanges = pRangesImp->GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + return new ScCellCursorObj( pDocSh, *rRanges.GetObject(0) ); + } + } + return NULL; +} + +// XSheetCellRange + +uno::Reference<sheet::XSpreadsheet> SAL_CALL ScTableSheetObj::getSpreadsheet() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return this; //!??? +} + +// XCellRange + +uno::Reference<table::XCell> SAL_CALL ScTableSheetObj::getCellByPosition( + sal_Int32 nColumn, sal_Int32 nRow ) + throw(lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScCellRangeObj::GetCellByPosition_Impl(nColumn, nRow); +} + +uno::Reference<table::XCellRange> SAL_CALL ScTableSheetObj::getCellRangeByPosition( + sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) + throw(lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScCellRangeObj::getCellRangeByPosition(nLeft,nTop,nRight,nBottom); +} + +uno::Sequence<sheet::TablePageBreakData> SAL_CALL ScTableSheetObj::getColumnPageBreaks() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + Size aSize = pDoc->GetPageSize( nTab ); + if (aSize.Width() && aSize.Height()) // effektive Groesse schon gesetzt? + pDoc->UpdatePageBreaks( nTab ); + else + { + // Umbrueche updaten wie in ScDocShell::PageStyleModified: + ScPrintFunc aPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ); + aPrintFunc.UpdatePages(); + } + + USHORT nCount = 0; + USHORT nCol; + for (nCol=0; nCol<=MAXCOL; nCol++) + if (pDoc->GetColFlags( nCol, nTab ) & ( CR_PAGEBREAK | CR_MANUALBREAK )) + ++nCount; + + sheet::TablePageBreakData aData; + uno::Sequence<sheet::TablePageBreakData> aSeq(nCount); + sheet::TablePageBreakData* pAry = aSeq.getArray(); + USHORT nPos = 0; + for (nCol=0; nCol<=MAXCOL; nCol++) + { + BYTE nFlags = pDoc->GetColFlags( nCol, nTab ); + if (nFlags & ( CR_PAGEBREAK | CR_MANUALBREAK )) + { + aData.Position = nCol; + aData.ManualBreak = ( nFlags & CR_MANUALBREAK ) != 0; + pAry[nPos] = aData; + ++nPos; + } + } + return aSeq; + } + return uno::Sequence<sheet::TablePageBreakData>(0); +} + +uno::Sequence<sheet::TablePageBreakData> SAL_CALL ScTableSheetObj::getRowPageBreaks() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + Size aSize = pDoc->GetPageSize( nTab ); + if (aSize.Width() && aSize.Height()) // effektive Groesse schon gesetzt? + pDoc->UpdatePageBreaks( nTab ); + else + { + // Umbrueche updaten wie in ScDocShell::PageStyleModified: + ScPrintFunc aPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ); + aPrintFunc.UpdatePages(); + } + + USHORT nCount = 0; + USHORT nRow; + for (nRow=0; nRow<=MAXROW; nRow++) + if (pDoc->GetRowFlags( nRow, nTab ) & ( CR_PAGEBREAK | CR_MANUALBREAK )) + ++nCount; + + sheet::TablePageBreakData aData; + uno::Sequence<sheet::TablePageBreakData> aSeq(nCount); + sheet::TablePageBreakData* pAry = aSeq.getArray(); + USHORT nPos = 0; + for (nRow=0; nRow<=MAXROW; nRow++) + { + BYTE nFlags = pDoc->GetRowFlags( nRow, nTab ); + if (nFlags & ( CR_PAGEBREAK | CR_MANUALBREAK )) + { + aData.Position = nRow; + aData.ManualBreak = ( nFlags & CR_MANUALBREAK ) != 0; + pAry[nPos] = aData; + ++nPos; + } + } + return aSeq; + } + return uno::Sequence<sheet::TablePageBreakData>(0); +} + +void SAL_CALL ScTableSheetObj::removeAllManualPageBreaks() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + //! docfunc Funktion, auch fuer ScViewFunc::RemoveManualBreaks + + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + pDoc->RemoveManualBreaks(nTab); + pDoc->UpdatePageBreaks(nTab); + + //? UpdatePageBreakData( TRUE ); + pDocSh->SetDocumentModified(); + pDocSh->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID ); + } +} + +// XNamed + +::rtl::OUString SAL_CALL ScTableSheetObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aName; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + pDocSh->GetDocument()->GetName( GetTab_Impl(), aName ); + return aName; +} + +void SAL_CALL ScTableSheetObj::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + String aString = aNewName; + ScDocFunc aFunc( *pDocSh ); + aFunc.RenameTable( GetTab_Impl(), aString, TRUE, TRUE ); + } +} + +// XDrawPageSupplier + +uno::Reference<drawing::XDrawPage> SAL_CALL ScTableSheetObj::getDrawPage() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDrawLayer* pDrawLayer = pDocSh->MakeDrawLayer(); + DBG_ASSERT(pDrawLayer,"kann Draw-Layer nicht anlegen"); + + USHORT nTab = GetTab_Impl(); + SdrPage* pPage = pDrawLayer->GetPage(nTab); + DBG_ASSERT(pPage,"Draw-Page nicht gefunden"); + if (pPage) + return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY); + + // Das DrawPage-Objekt meldet sich als Listener am SdrModel an + // und sollte von dort alle Aktionen mitbekommen + } + return NULL; +} + +// XCellMovement + +void SAL_CALL ScTableSheetObj::insertCells( const table::CellRangeAddress& rRange, + sheet::CellInsertMode nMode ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + BOOL bDo = TRUE; + switch (nMode) + { + case sheet::CellInsertMode_NONE: bDo = FALSE; break; + case sheet::CellInsertMode_DOWN: break; + case sheet::CellInsertMode_RIGHT: break; + case sheet::CellInsertMode_ROWS: break; + case sheet::CellInsertMode_COLUMNS: break; + default: + OSL_FAIL("insertCells: falscher Mode"); + bDo = FALSE; + } + + if (bDo) + { + DBG_ASSERT( rRange.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" ); + ScRange aScRange; + ScUnoConversion::FillScRange( aScRange, rRange ); + } + } +} + +void SAL_CALL ScTableSheetObj::removeRange( const table::CellRangeAddress& rRange, + sheet::CellDeleteMode nMode ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + BOOL bDo = TRUE; + switch (nMode) + { + case sheet::CellDeleteMode_NONE: bDo = FALSE; break; + case sheet::CellDeleteMode_UP: break; + case sheet::CellDeleteMode_LEFT: break; + case sheet::CellDeleteMode_ROWS: break; + case sheet::CellDeleteMode_COLUMNS: break; + default: + OSL_FAIL("deleteCells: falscher Mode"); + bDo = FALSE; + } + + if (bDo) + { + DBG_ASSERT( rRange.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" ); + ScRange aScRange; + ScUnoConversion::FillScRange( aScRange, rRange ); + } + } +} + +void SAL_CALL ScTableSheetObj::moveRange( const table::CellAddress& /*aDestination*/, + const table::CellRangeAddress& aSource ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + DBG_ASSERT( aSource.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" ); + ScRange aLclRange; + ScUnoConversion::FillScRange( aLclRange, aSource ); + } +} + +void SAL_CALL ScTableSheetObj::copyRange( const table::CellAddress& /*aDestination*/, + const table::CellRangeAddress& aSource ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + DBG_ASSERT( aSource.Sheet == GetTab_Impl(), "falsche Tabelle in CellRangeAddress" ); + ScRange aLclRange; + ScUnoConversion::FillScRange( aLclRange, aSource ); + } +} + +// XPrintAreas + +void ScTableSheetObj::PrintAreaUndo_Impl( ScPrintRangeSaver* pOldRanges ) +{ + // Umbrueche und Undo + + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + pDoc->CreatePrintRangeSaver(); + ScPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ).UpdatePages(); + pDocSh->SetDocumentModified(); + } + else + delete pOldRanges; +} + +uno::Sequence<table::CellRangeAddress> SAL_CALL ScTableSheetObj::getPrintAreas() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + USHORT nCount = pDoc->GetPrintRangeCount( nTab ); + + table::CellRangeAddress aRangeAddress; + uno::Sequence<table::CellRangeAddress> aSeq(nCount); + table::CellRangeAddress* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + const ScRange* pRange = pDoc->GetPrintRange( nTab, i ); + DBG_ASSERT(pRange,"wo ist der Druckbereich"); + if (pRange) + { + ScUnoConversion::FillApiRange( aRangeAddress, *pRange ); + pAry[i] = aRangeAddress; + } + } + return aSeq; + } + return uno::Sequence<table::CellRangeAddress>(); +} + +void SAL_CALL ScTableSheetObj::setPrintAreas( + const uno::Sequence<table::CellRangeAddress>& aPrintAreas ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver(); + + USHORT nCount = (USHORT) aPrintAreas.getLength(); + pDoc->SetPrintRangeCount( nTab, nCount ); + if (nCount) + { + ScRange aLclRange; + const table::CellRangeAddress* pAry = aPrintAreas.getConstArray(); + for (USHORT i=0; i<nCount; i++) + { + ScUnoConversion::FillScRange( aLclRange, pAry[i] ); + pDoc->SetPrintRange( nTab, i, aLclRange ); + } + } + + PrintAreaUndo_Impl( pOldRanges ); // Undo, Umbrueche, Modified etc. + } +} + +sal_Bool SAL_CALL ScTableSheetObj::getPrintTitleColumns() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + return ( pDoc->GetRepeatColRange(nTab) != NULL ); + } + return FALSE; +} + +void SAL_CALL ScTableSheetObj::setPrintTitleColumns( sal_Bool bPrintTitleColumns ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver(); + + if ( bPrintTitleColumns ) + { + if ( !pDoc->GetRepeatColRange( nTab ) ) // keinen bestehenden Bereich veraendern + { + ScRange aNew( 0, 0, nTab, 0, 0, nTab ); // Default + pDoc->SetRepeatColRange( nTab, &aNew ); // einschalten + } + } + else + pDoc->SetRepeatColRange( nTab, NULL ); // abschalten + + PrintAreaUndo_Impl( pOldRanges ); // Undo, Umbrueche, Modified etc. + + //! zuletzt gesetzten Bereich beim Abschalten merken und beim Einschalten wiederherstellen ??? + } +} + +table::CellRangeAddress SAL_CALL ScTableSheetObj::getTitleColumns() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aRet; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + const ScRange* pRange = pDoc->GetRepeatColRange(nTab); + if (pRange) + ScUnoConversion::FillApiRange( aRet, *pRange ); + } + return aRet; +} + +void SAL_CALL ScTableSheetObj::setTitleColumns( const table::CellRangeAddress& aTitleColumns ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver(); + + ScRange aNew; + ScUnoConversion::FillScRange( aNew, aTitleColumns ); + pDoc->SetRepeatColRange( nTab, &aNew ); // immer auch einschalten + + PrintAreaUndo_Impl( pOldRanges ); // Undo, Umbrueche, Modified etc. + } +} + +sal_Bool SAL_CALL ScTableSheetObj::getPrintTitleRows() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + return ( pDoc->GetRepeatRowRange(nTab) != NULL ); + } + return FALSE; +} + +void SAL_CALL ScTableSheetObj::setPrintTitleRows( sal_Bool bPrintTitleRows ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver(); + + if ( bPrintTitleRows ) + { + if ( !pDoc->GetRepeatRowRange( nTab ) ) // keinen bestehenden Bereich veraendern + { + ScRange aNew( 0, 0, nTab, 0, 0, nTab ); // Default + pDoc->SetRepeatRowRange( nTab, &aNew ); // einschalten + } + } + else + pDoc->SetRepeatRowRange( nTab, NULL ); // abschalten + + PrintAreaUndo_Impl( pOldRanges ); // Undo, Umbrueche, Modified etc. + + //! zuletzt gesetzten Bereich beim Abschalten merken und beim Einschalten wiederherstellen ??? + } +} + +table::CellRangeAddress SAL_CALL ScTableSheetObj::getTitleRows() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aRet; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + const ScRange* pRange = pDoc->GetRepeatRowRange(nTab); + if (pRange) + ScUnoConversion::FillApiRange( aRet, *pRange ); + } + return aRet; +} + +void SAL_CALL ScTableSheetObj::setTitleRows( const table::CellRangeAddress& aTitleRows ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + ScPrintRangeSaver* pOldRanges = pDoc->CreatePrintRangeSaver(); + + ScRange aNew; + ScUnoConversion::FillScRange( aNew, aTitleRows ); + pDoc->SetRepeatRowRange( nTab, &aNew ); // immer auch einschalten + + PrintAreaUndo_Impl( pOldRanges ); // Undo, Umbrueche, Modified etc. + } +} + +// XSheetLinkable + +sheet::SheetLinkMode SAL_CALL ScTableSheetObj::getLinkMode() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + sheet::SheetLinkMode eRet = sheet::SheetLinkMode_NONE; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + BYTE nMode = pDocSh->GetDocument()->GetLinkMode( GetTab_Impl() ); + if ( nMode == SC_LINK_NORMAL ) + eRet = sheet::SheetLinkMode_NORMAL; + else if ( nMode == SC_LINK_VALUE ) + eRet = sheet::SheetLinkMode_VALUE; + } + return eRet; +} + +void SAL_CALL ScTableSheetObj::setLinkMode( sheet::SheetLinkMode nLinkMode ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! Filter und Options aus altem Link suchen + + ::rtl::OUString aUrl = getLinkUrl(); + ::rtl::OUString aSheet = getLinkSheetName(); + + ::rtl::OUString aEmpty; + link( aUrl, aSheet, aEmpty, aEmpty, nLinkMode ); +} + +::rtl::OUString SAL_CALL ScTableSheetObj::getLinkUrl() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aFile; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + aFile = pDocSh->GetDocument()->GetLinkDoc( GetTab_Impl() ); + return aFile; +} + +void SAL_CALL ScTableSheetObj::setLinkUrl( const ::rtl::OUString& aLinkUrl ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! Filter und Options aus altem Link suchen + + sheet::SheetLinkMode eMode = getLinkMode(); + ::rtl::OUString aSheet = getLinkSheetName(); + + ::rtl::OUString aEmpty; + link( aLinkUrl, aSheet, aEmpty, aEmpty, eMode ); +} + +::rtl::OUString SAL_CALL ScTableSheetObj::getLinkSheetName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aSheet; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + aSheet = pDocSh->GetDocument()->GetLinkTab( GetTab_Impl() ); + return aSheet; +} + +void SAL_CALL ScTableSheetObj::setLinkSheetName( const ::rtl::OUString& aLinkSheetName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! Filter und Options aus altem Link suchen + + sheet::SheetLinkMode eMode = getLinkMode(); + ::rtl::OUString aUrl = getLinkUrl(); + + ::rtl::OUString aEmpty; + link( aUrl, aLinkSheetName, aEmpty, aEmpty, eMode ); +} + +void SAL_CALL ScTableSheetObj::link( const ::rtl::OUString& aUrl, const ::rtl::OUString& aSheetName, + const ::rtl::OUString& aFilterName, const ::rtl::OUString& aFilterOptions, + sheet::SheetLinkMode nMode ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + String aFileString = aUrl; + String aFilterString = aFilterName; + String aOptString = aFilterOptions; + String aSheetString = aSheetName; + + aFileString = ScGlobal::GetAbsDocName( aFileString, pDocSh ); + if ( !aFilterString.Len() ) + ScDocumentLoader::GetFilterName( aFileString, aFilterString, aOptString ); + + // remove application prefix from filter name here, so the filter options + // aren't reset when the filter name is changed in ScTableLink::DataChanged + ScDocumentLoader::RemoveAppPrefix( aFilterString ); + + BYTE nLinkMode = SC_LINK_NONE; + if ( nMode == sheet::SheetLinkMode_NORMAL ) + nLinkMode = SC_LINK_NORMAL; + else if ( nMode == sheet::SheetLinkMode_VALUE ) + nLinkMode = SC_LINK_VALUE; + + ULONG nRefresh = 0; + pDoc->SetLink( nTab, nLinkMode, aFileString, aFilterString, aOptString, aSheetString, nRefresh ); + + pDocSh->UpdateLinks(); // ggf. Link eintragen oder loeschen + + //! Undo fuer Link-Daten an der Table + + if ( nLinkMode != SC_LINK_NONE ) // Link updaten + { + // Update immer, auch wenn der Link schon da war + //! Update nur fuer die betroffene Tabelle??? + + SvxLinkManager* pLinkManager = pDoc->GetLinkManager(); + USHORT nCount = pLinkManager->GetLinks().Count(); + for ( USHORT i=0; i<nCount; i++ ) + { + ::binfilter::SvBaseLink* pBase = *pLinkManager->GetLinks()[i]; + if (pBase->ISA(ScTableLink)) + { + ScTableLink* pTabLink = (ScTableLink*)pBase; + if ( pTabLink->GetFileName() == aFileString ) + pTabLink->Update(); // inkl. Paint&Undo + + //! Der Dateiname sollte nur einmal vorkommen (?) + } + } + } + + //! Notify fuer ScSheetLinkObj Objekte!!! + } +} + +// XSheetAuditing + +sal_Bool SAL_CALL ScTableSheetObj::hideDependents( const table::CellAddress& aPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nTab = GetTab_Impl(); + DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" ); + ScAddress aPos( (USHORT)aPosition.Column, (USHORT)aPosition.Row, nTab ); + ScDocFunc aFunc(*pDocSh); + return aFunc.DetectiveDelSucc( aPos ); + } + return FALSE; +} + +sal_Bool SAL_CALL ScTableSheetObj::hidePrecedents( const table::CellAddress& aPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nTab = GetTab_Impl(); + DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" ); + ScAddress aPos( (USHORT)aPosition.Column, (USHORT)aPosition.Row, nTab ); + ScDocFunc aFunc(*pDocSh); + return aFunc.DetectiveDelPred( aPos ); + } + return FALSE; +} + +sal_Bool SAL_CALL ScTableSheetObj::showDependents( const table::CellAddress& aPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nTab = GetTab_Impl(); + DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" ); + (void)aPosition; + (void)nTab; + return false; + } + return FALSE; +} + +sal_Bool SAL_CALL ScTableSheetObj::showPrecedents( const table::CellAddress& aPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nTab = GetTab_Impl(); + DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" ); + ScAddress aPos( (USHORT)aPosition.Column, (USHORT)aPosition.Row, nTab ); + ScDocFunc aFunc(*pDocSh); + return aFunc.DetectiveAddPred( aPos ); + } + return FALSE; +} + +sal_Bool SAL_CALL ScTableSheetObj::showErrors( const table::CellAddress& aPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nTab = GetTab_Impl(); + DBG_ASSERT( aPosition.Sheet == nTab, "falsche Tabelle in CellAddress" ); + ScAddress aPos( (USHORT)aPosition.Column, (USHORT)aPosition.Row, nTab ); + ScDocFunc aFunc(*pDocSh); + return aFunc.DetectiveAddError( aPos ); + } + return FALSE; +} + +sal_Bool SAL_CALL ScTableSheetObj::showInvalid() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocFunc aFunc(*pDocSh); + return aFunc.DetectiveMarkInvalid( GetTab_Impl() ); + } + return FALSE; +} + +void SAL_CALL ScTableSheetObj::clearArrows() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocFunc aFunc(*pDocSh); + aFunc.DetectiveDelAll( GetTab_Impl() ); + } +} + +// XSheetOutline + +void SAL_CALL ScTableSheetObj::group( const table::CellRangeAddress&, + table::TableOrientation ) + throw(uno::RuntimeException) +{ + DBG_BF_ASSERT(0, "STRIP"); // VIRTUAL +} + +void SAL_CALL ScTableSheetObj::ungroup( const table::CellRangeAddress&, + table::TableOrientation ) + throw(uno::RuntimeException) +{ + DBG_BF_ASSERT(0, "STRIP"); // VIRTUAL +} + +void SAL_CALL ScTableSheetObj::autoOutline( const table::CellRangeAddress& ) + throw(uno::RuntimeException) +{ + DBG_BF_ASSERT(0, "STRIP"); // VIRTUAL +} + +void SAL_CALL ScTableSheetObj::clearOutline() throw(uno::RuntimeException) +{ + DBG_BF_ASSERT(0, "STRIP"); // VIRTUAL +} + +void SAL_CALL ScTableSheetObj::hideDetail( const table::CellRangeAddress& ) + throw(uno::RuntimeException) +{ + DBG_BF_ASSERT(0, "STRIP"); // VIRTUAL +} + +void SAL_CALL ScTableSheetObj::showDetail( const table::CellRangeAddress& ) + throw(uno::RuntimeException) +{ + DBG_BF_ASSERT(0, "STRIP"); // VIRTUAL +} + +void SAL_CALL ScTableSheetObj::showLevel( sal_Int16, table::TableOrientation ) + throw(uno::RuntimeException) +{ + DBG_BF_ASSERT(0, "STRIP"); // VIRTUAL +} + +// XProtectable + +void SAL_CALL ScTableSheetObj::protect( const ::rtl::OUString& aPassword ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + String aString = aPassword; + ScDocFunc aFunc(*pDocSh); + aFunc.Protect( GetTab_Impl(), aString, TRUE ); + } +} + +void SAL_CALL ScTableSheetObj::unprotect( const ::rtl::OUString& aPassword ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + String aString = aPassword; + ScDocFunc aFunc(*pDocSh); + aFunc.Unprotect( GetTab_Impl(), aString, TRUE ); + + //! Rueckgabewert auswerten, Exception oder so + } +} + +sal_Bool SAL_CALL ScTableSheetObj::isProtected() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return pDocSh->GetDocument()->IsTabProtected( GetTab_Impl() ); + + OSL_FAIL("keine DocShell"); //! Exception oder so? + return FALSE; +} + +// XScenario + +sal_Bool SAL_CALL ScTableSheetObj::getIsScenario() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + return pDocSh->GetDocument()->IsScenario( GetTab_Impl() ); + + return FALSE; +} + +::rtl::OUString SAL_CALL ScTableSheetObj::getScenarioComment() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + String aComment; + Color aColor; + USHORT nFlags; + pDocSh->GetDocument()->GetScenarioData( GetTab_Impl(), aComment, aColor, nFlags ); + return aComment; + } + return ::rtl::OUString(); +} + +void SAL_CALL ScTableSheetObj::setScenarioComment( const ::rtl::OUString& aScenarioComment ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + String aName; + String aComment; + Color aColor; + USHORT nFlags; + pDoc->GetName( nTab, aName ); + pDoc->GetScenarioData( nTab, aComment, aColor, nFlags ); + + aComment = String( aScenarioComment ); + } +} + +void SAL_CALL ScTableSheetObj::addRanges( const uno::Sequence<table::CellRangeAddress>& rRanges ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + ScMarkData aMarkData; + aMarkData.SelectTable( nTab, TRUE ); + + USHORT nRangeCount = (USHORT)rRanges.getLength(); + if (nRangeCount) + { + const table::CellRangeAddress* pAry = rRanges.getConstArray(); + for (USHORT i=0; i<nRangeCount; i++) + { + DBG_ASSERT( pAry[i].Sheet == nTab, "addRanges mit falscher Tab" ); + ScRange aLclRange( (USHORT)pAry[i].StartColumn, (USHORT)pAry[i].StartRow, nTab, + (USHORT)pAry[i].EndColumn, (USHORT)pAry[i].EndRow, nTab ); + + aMarkData.SetMultiMarkArea( aLclRange ); + } + } + + // Szenario-Ranges sind durch Attribut gekennzeichnet + ScPatternAttr aPattern( pDoc->GetPool() ); + aPattern.GetItemSet().Put( ScMergeFlagAttr( SC_MF_SCENARIO ) ); + aPattern.GetItemSet().Put( ScProtectionAttr( TRUE ) ); + ScDocFunc aFunc(*pDocSh); + aFunc.ApplyAttributes( aMarkData, aPattern, TRUE, TRUE ); + } +} + +void SAL_CALL ScTableSheetObj::apply() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + String aName; + pDoc->GetName( nTab, aName ); // Name dieses Szenarios + + USHORT nDestTab = nTab; + while ( nDestTab > 0 && pDoc->IsScenario(nDestTab) ) + --nDestTab; + + if ( !pDoc->IsScenario(nDestTab) ) + pDocSh->UseScenario( nDestTab, aName ); + + //! sonst Fehler oder so + } +} + +// XPropertySet erweitert fuer Sheet-Properties + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableSheetObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aSheetPropSet.getPropertyMap() ); + return aRef; +} + +void ScTableSheetObj::SetOnePropertyValue( const SfxItemPropertyMap* pMap, const uno::Any& aValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + if ( pMap ) + { + if ( IsScItemWid( pMap->nWID ) ) + { + // for Item WIDs, call ScCellRangesBase directly + ScCellRangesBase::SetOnePropertyValue(pMap, aValue); + return; + } + + // own properties + + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + return; //! Exception oder so? + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + ScDocFunc aFunc(*pDocSh); + + if ( pMap->nWID == SC_WID_UNO_PAGESTL ) + { + ::rtl::OUString aStrVal; + aValue >>= aStrVal; + String aNewStr = ScStyleNameConversion::ProgrammaticToDisplayName( + aStrVal, SFX_STYLE_FAMILY_PAGE ); + + //! Undo? (auch bei SID_STYLE_APPLY an der View) + + if ( pDoc->GetPageStyle( nTab ) != aNewStr ) + { + pDoc->SetPageStyle( nTab, aNewStr ); + ScPrintFunc( pDocSh, pDocSh->GetPrinter(), nTab ).UpdatePages(); + pDocSh->SetDocumentModified(); + + } + } + else if ( pMap->nWID == SC_WID_UNO_CELLVIS ) + { + BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + aFunc.SetTableVisible( nTab, bVis, TRUE ); + } + else + ScCellRangeObj::SetOnePropertyValue(pMap, aValue); // base class, no Item WID + } +} + +void ScTableSheetObj::GetOnePropertyValue( const SfxItemPropertyMap* pMap, + uno::Any& rAny ) + throw(uno::RuntimeException) +{ + if ( pMap ) + { + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + throw uno::RuntimeException(); + ScDocument* pDoc = pDocSh->GetDocument(); + USHORT nTab = GetTab_Impl(); + + if ( pMap->nWID == SC_WID_UNO_PAGESTL ) + { + String aStyle = ScStyleNameConversion::DisplayToProgrammaticName( + pDoc->GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE ); + rAny <<= ::rtl::OUString( aStyle ); + } + else if ( pMap->nWID == SC_WID_UNO_CELLVIS ) + { + BOOL bVis = pDoc->IsVisible( nTab ); + ScUnoHelpFunctions::SetBoolInAny( rAny, bVis ); + } + else if ( pMap->nWID == SC_WID_UNO_LINKDISPBIT ) + { + // no target bitmaps for individual entries (would be all equal) + // ScLinkTargetTypeObj::SetLinkTargetBitmap( aAny, SC_LINKTARGETTYPE_SHEET ); + } + else if ( pMap->nWID == SC_WID_UNO_LINKDISPNAME ) + { + // LinkDisplayName for hyperlink dialog + rAny <<= getName(); // sheet name + } + else + ScCellRangeObj::GetOnePropertyValue(pMap, rAny); + } +} + +const SfxItemPropertyMap* ScTableSheetObj::GetItemPropertyMap() +{ + return lcl_GetSheetPropertyMap(); +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScTableSheetObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScTableSheetObj" )); +} + +sal_Bool SAL_CALL ScTableSheetObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCSPREADSHEET_SERVICE ) || + aServiceStr.EqualsAscii( SCSHEETCELLRANGE_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLRANGE_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCCHARPROPERTIES_SERVICE ) || + aServiceStr.EqualsAscii( SCPARAPROPERTIES_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScTableSheetObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(6); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSPREADSHEET_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSHEETCELLRANGE_SERVICE )); + pArray[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLRANGE_SERVICE )); + pArray[3] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLPROPERTIES_SERVICE )); + pArray[4] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCHARPROPERTIES_SERVICE )); + pArray[5] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCPARAPROPERTIES_SERVICE )); + return aRet; +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScTableSheetObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + + return ScCellRangeObj::getSomething( rId ); +} + +// static +const uno::Sequence<sal_Int8>& ScTableSheetObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScTableSheetObj* ScTableSheetObj::getImplementation( const uno::Reference<uno::XInterface> xObj ) +{ + ScTableSheetObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScTableSheetObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + + +ScTableColumnObj::ScTableColumnObj( ScDocShell* pDocSh, USHORT nCol, USHORT nTab ) : + ScCellRangeObj( pDocSh, ScRange(nCol,0,nTab, nCol,MAXROW,nTab) ), + aColPropSet(lcl_GetColumnPropertyMap()) +{ +} + +ScTableColumnObj::~ScTableColumnObj() +{ +} + +uno::Any SAL_CALL ScTableColumnObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( container::XNamed ) + + return ScCellRangeObj::queryInterface( rType ); +} + +void SAL_CALL ScTableColumnObj::acquire() throw() +{ + ScCellRangeObj::acquire(); +} + +void SAL_CALL ScTableColumnObj::release() throw() +{ + ScCellRangeObj::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScTableColumnObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = ScCellRangeObj::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 1 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<container::XNamed>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScTableColumnObj::getImplementationId() throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// XNamed + +::rtl::OUString SAL_CALL ScTableColumnObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + const ScRange& rRange = GetRange(); + DBG_ASSERT(rRange.aStart.Col() == rRange.aEnd.Col(), "too many columns"); + USHORT nCol = rRange.aStart.Col(); + + return ColToAlpha( nCol ); // from global.hxx +} + +void SAL_CALL ScTableColumnObj::setName( const ::rtl::OUString& /*aNewName*/ ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + throw uno::RuntimeException(); // read-only +} + +// XPropertySet erweitert fuer Spalten-Properties + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aColPropSet.getPropertyMap() ); + return aRef; +} + +void ScTableColumnObj::SetOnePropertyValue( const SfxItemPropertyMap* pMap, const uno::Any& aValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + if ( pMap ) + { + if ( IsScItemWid( pMap->nWID ) ) + { + // for Item WIDs, call ScCellRangesBase directly + ScCellRangesBase::SetOnePropertyValue(pMap, aValue); + return; + } + + // own properties + + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + return; //! Exception oder so? + pDocSh->GetDocument(); + const ScRange& rRange = GetRange(); + DBG_ASSERT(rRange.aStart.Col() == rRange.aEnd.Col(), "zuviele Spalten"); + USHORT nCol = rRange.aStart.Col(); + USHORT nTab = rRange.aStart.Tab(); + ScDocFunc aFunc(*pDocSh); + + USHORT nColArr[2]; + nColArr[0] = nColArr[1] = nCol; + + if ( pMap->nWID == SC_WID_UNO_CELLWID ) + { + sal_Int32 nNewWidth = 0; + if ( aValue >>= nNewWidth ) + { + // property is 1/100mm, column width is twips + nNewWidth = HMMToTwips(nNewWidth); + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, SC_SIZE_ORIGINAL, + (USHORT)nNewWidth, TRUE, TRUE ); + } + } + else if ( pMap->nWID == SC_WID_UNO_CELLVIS ) + { + BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT; + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, eMode, 0, TRUE, TRUE ); + // SC_SIZE_DIRECT mit Groesse 0 blendet aus + } + else if ( pMap->nWID == SC_WID_UNO_OWIDTH ) + { + BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + if (bOpt) + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, + SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, TRUE, TRUE ); + // FALSE bei Spalten momentan ohne Auswirkung + } + else if ( pMap->nWID == SC_WID_UNO_NEWPAGE || pMap->nWID == SC_WID_UNO_MANPAGE ) + { + BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + if (!bSet) + aFunc.RemovePageBreak( TRUE, rRange.aStart, TRUE, TRUE ); + } + else + ScCellRangeObj::SetOnePropertyValue(pMap, aValue); // base class, no Item WID + } +} + +void ScTableColumnObj::GetOnePropertyValue( const SfxItemPropertyMap* pMap, + uno::Any& rAny ) + throw(uno::RuntimeException) +{ + if ( pMap ) + { + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + throw uno::RuntimeException(); + + ScDocument* pDoc = pDocSh->GetDocument(); + const ScRange& rRange = GetRange(); + DBG_ASSERT(rRange.aStart.Col() == rRange.aEnd.Col(), "zuviele Spalten"); + USHORT nCol = rRange.aStart.Col(); + USHORT nTab = rRange.aStart.Tab(); + + if ( pMap->nWID == SC_WID_UNO_CELLWID ) + { + // for hidden column, return original height + USHORT nWidth = pDoc->GetOriginalWidth( nCol, nTab ); + // property is 1/100mm, column width is twips + nWidth = (USHORT) TwipsToHMM(nWidth); + rAny <<= (sal_Int32)( nWidth ); + } + else if ( pMap->nWID == SC_WID_UNO_CELLVIS ) + { + BOOL bVis = !(pDoc->GetColFlags( nCol, nTab ) & CR_HIDDEN); + ScUnoHelpFunctions::SetBoolInAny( rAny, bVis ); + } + else if ( pMap->nWID == SC_WID_UNO_OWIDTH ) + { + //! momentan immer gesetzt ??!?! + BOOL bOpt = !(pDoc->GetColFlags( nCol, nTab ) & CR_MANUALSIZE); + ScUnoHelpFunctions::SetBoolInAny( rAny, bOpt ); + } + else if ( pMap->nWID == SC_WID_UNO_NEWPAGE ) + { + BOOL bBreak = ( 0 != (pDoc->GetColFlags( nCol, nTab ) & (CR_PAGEBREAK|CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( rAny, bBreak ); + } + else if ( pMap->nWID == SC_WID_UNO_MANPAGE ) + { + BOOL bBreak = ( 0 != (pDoc->GetColFlags( nCol, nTab ) & (CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( rAny, bBreak ); + } + else + ScCellRangeObj::GetOnePropertyValue(pMap, rAny); + } +} + +const SfxItemPropertyMap* ScTableColumnObj::GetItemPropertyMap() +{ + return lcl_GetColumnPropertyMap(); +} + + +ScTableRowObj::ScTableRowObj(ScDocShell* pDocSh, USHORT nRow, USHORT nTab) : + ScCellRangeObj( pDocSh, ScRange(0,nRow,nTab, MAXCOL,nRow,nTab) ), + aRowPropSet(lcl_GetRowPropertyMap()) +{ +} + +ScTableRowObj::~ScTableRowObj() +{ +} + +// XPropertySet erweitert fuer Zeilen-Properties + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aRowPropSet.getPropertyMap() ); + return aRef; +} + +void ScTableRowObj::SetOnePropertyValue( const SfxItemPropertyMap* pMap, const uno::Any& aValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + if ( pMap ) + { + if ( IsScItemWid( pMap->nWID ) ) + { + // for Item WIDs, call ScCellRangesBase directly + ScCellRangesBase::SetOnePropertyValue(pMap, aValue); + return; + } + + // own properties + + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + return; //! Exception oder so? + ScDocument* pDoc = pDocSh->GetDocument(); + const ScRange& rRange = GetRange(); + DBG_ASSERT(rRange.aStart.Row() == rRange.aEnd.Row(), "zuviele Zeilen"); + USHORT nRow = rRange.aStart.Row(); + USHORT nTab = rRange.aStart.Tab(); + ScDocFunc aFunc(*pDocSh); + + USHORT nRowArr[2]; + nRowArr[0] = nRowArr[1] = nRow; + + if ( pMap->nWID == SC_WID_UNO_CELLHGT ) + { + sal_Int32 nNewHeight = 0; + if ( aValue >>= nNewHeight ) + { + // property is 1/100mm, row height is twips + nNewHeight = HMMToTwips(nNewHeight); + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_ORIGINAL, + (USHORT)nNewHeight, TRUE, TRUE ); + } + } + else if ( pMap->nWID == SC_WID_UNO_CELLVIS ) + { + BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT; + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, eMode, 0, TRUE, TRUE ); + // SC_SIZE_DIRECT mit Groesse 0 blendet aus + } + else if ( pMap->nWID == SC_WID_UNO_CELLFILT ) + { + BOOL bFil = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + // SC_SIZE_DIRECT mit Groesse 0 blendet aus + BYTE nFlags = pDoc->GetRowFlags(nRow, nTab); + if (bFil) + nFlags |= CR_FILTERED; + else + nFlags &= ~CR_FILTERED; + pDoc->SetRowFlags(nRow, nTab, nFlags); + } + else if ( pMap->nWID == SC_WID_UNO_OHEIGHT ) + { + BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + if (bOpt) + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_OPTIMAL, 0, TRUE, TRUE ); + else + { + // set current height again manually + USHORT nHeight = pDoc->GetOriginalHeight( nRow, nTab ); + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_ORIGINAL, nHeight, TRUE, TRUE ); + } + } + else if ( pMap->nWID == SC_WID_UNO_NEWPAGE || pMap->nWID == SC_WID_UNO_MANPAGE ) + { + BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + if (!bSet) + aFunc.RemovePageBreak( FALSE, rRange.aStart, TRUE, TRUE ); + } + else + ScCellRangeObj::SetOnePropertyValue(pMap, aValue); // base class, no Item WID + } +} + +void ScTableRowObj::GetOnePropertyValue( const SfxItemPropertyMap* pMap, + uno::Any& rAny ) + throw(uno::RuntimeException) +{ + if ( pMap ) + { + ScDocShell* pDocSh = GetDocShell(); + if (!pDocSh) + throw uno::RuntimeException(); + ScDocument* pDoc = pDocSh->GetDocument(); + const ScRange& rRange = GetRange(); + DBG_ASSERT(rRange.aStart.Row() == rRange.aEnd.Row(), "zuviele Zeilen"); + USHORT nRow = rRange.aStart.Row(); + USHORT nTab = rRange.aStart.Tab(); + + if ( pMap->nWID == SC_WID_UNO_CELLHGT ) + { + // for hidden row, return original height + USHORT nHeight = pDoc->GetOriginalHeight( nRow, nTab ); + // property is 1/100mm, row height is twips + nHeight = (USHORT) TwipsToHMM(nHeight); + rAny <<= (sal_Int32)( nHeight ); + } + else if ( pMap->nWID == SC_WID_UNO_CELLVIS ) + { + BOOL bVis = !(pDoc->GetRowFlags( nRow, nTab ) & CR_HIDDEN); + ScUnoHelpFunctions::SetBoolInAny( rAny, bVis ); + } + else if ( pMap->nWID == SC_WID_UNO_CELLFILT ) + { + BOOL bVis = ((pDoc->GetRowFlags( nRow, nTab ) & CR_FILTERED) != 0); + ScUnoHelpFunctions::SetBoolInAny( rAny, bVis ); + } + else if ( pMap->nWID == SC_WID_UNO_OHEIGHT ) + { + BOOL bOpt = !(pDoc->GetRowFlags( nRow, nTab ) & CR_MANUALSIZE); + ScUnoHelpFunctions::SetBoolInAny( rAny, bOpt ); + } + else if ( pMap->nWID == SC_WID_UNO_NEWPAGE ) + { + BOOL bBreak = ( 0 != (pDoc->GetRowFlags( nRow, nTab ) & (CR_PAGEBREAK|CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( rAny, bBreak ); + } + else if ( pMap->nWID == SC_WID_UNO_MANPAGE ) + { + BOOL bBreak = ( 0 != (pDoc->GetRowFlags( nRow, nTab ) & (CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( rAny, bBreak ); + } + else + ScCellRangeObj::GetOnePropertyValue(pMap, rAny); + } +} + +const SfxItemPropertyMap* ScTableRowObj::GetItemPropertyMap() +{ + return lcl_GetRowPropertyMap(); +} + + +ScCellsObj::ScCellsObj(ScDocShell* pDocSh, const ScRangeList& rR) : + pDocShell( pDocSh ), + aRanges( rR ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScCellsObj::~ScCellsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScCellsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; + aRanges.UpdateReference( rRef.GetMode(), pDocShell->GetDocument(), rRef.GetRange(), + rRef.GetDx(), rRef.GetDy(), rRef.GetDz() ); + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScCellsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScCellsEnumeration( pDocShell, aRanges ); + return NULL; +} + +uno::Type SAL_CALL ScCellsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<table::XCell>*)0); +} + +sal_Bool SAL_CALL ScCellsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bHas = FALSE; + if ( pDocShell ) + { + //! schneller selber testen? + + uno::Reference<container::XEnumeration> xEnum = new ScCellsEnumeration( pDocShell, aRanges ); + bHas = xEnum->hasMoreElements(); + } + return bHas; +} + + +ScCellsEnumeration::ScCellsEnumeration(ScDocShell* pDocSh, const ScRangeList& rR) : + pDocShell( pDocSh ), + aRanges( rR ), + pMark( NULL ), + bAtEnd( FALSE ) +{ + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->AddUnoObject(*this); + + if ( aRanges.Count() == 0 ) + bAtEnd = TRUE; + else + { + USHORT nTab = 0; + const ScRange* pFirst = aRanges.GetObject(0); + if (pFirst) + nTab = pFirst->aStart.Tab(); + aPos = ScAddress(0,0,nTab); + CheckPos_Impl(); // aPos auf erste passende Zelle setzen + } +} + +void ScCellsEnumeration::CheckPos_Impl() +{ + if (pDocShell) + { + BOOL bFound = FALSE; + ScDocument* pDoc = pDocShell->GetDocument(); + ScBaseCell* pCell = pDoc->GetCell(aPos); + if ( pCell && pCell->GetCellType() != CELLTYPE_NOTE ) + { + if (!pMark) + { + pMark = new ScMarkData; + pMark->MarkFromRangeList( aRanges, FALSE ); + pMark->MarkToMulti(); // needed for GetNextMarkedCell + } + bFound = pMark->IsCellMarked( aPos.Col(), aPos.Row() ); + } + if (!bFound) + Advance_Impl(); + } +} + +ScCellsEnumeration::~ScCellsEnumeration() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + delete pMark; +} + +void ScCellsEnumeration::Advance_Impl() +{ + DBG_ASSERT(!bAtEnd,"zuviel Advance_Impl"); + if (!pMark) + { + pMark = new ScMarkData; + pMark->MarkFromRangeList( aRanges, FALSE ); + pMark->MarkToMulti(); // needed for GetNextMarkedCell + } + + USHORT nCol = aPos.Col(); + USHORT nRow = aPos.Row(); + USHORT nTab = aPos.Tab(); + BOOL bFound = pDocShell->GetDocument()->GetNextMarkedCell( nCol, nRow, nTab, *pMark ); + if (bFound) + aPos.Set( nCol, nRow, nTab ); + else + bAtEnd = TRUE; // kommt nix mehr +} + +void ScCellsEnumeration::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + if (pDocShell) + { + const ScUpdateRefHint& rRef = (const ScUpdateRefHint&)rHint; + aRanges.UpdateReference( rRef.GetMode(), pDocShell->GetDocument(), rRef.GetRange(), + rRef.GetDx(), rRef.GetDy(), rRef.GetDz() ); + + delete pMark; // aus verschobenen Bereichen neu erzeugen + pMark = NULL; + + if (!bAtEnd) // aPos anpassen + { + ScRangeList aNew; + aNew.Append(ScRange(aPos)); + aNew.UpdateReference( rRef.GetMode(), pDocShell->GetDocument(), rRef.GetRange(), + rRef.GetDx(), rRef.GetDy(), rRef.GetDz() ); + if (aNew.Count()==1) + { + aPos = aNew.GetObject(0)->aStart; + CheckPos_Impl(); + } + } + } + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XEnumeration + +sal_Bool SAL_CALL ScCellsEnumeration::hasMoreElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return !bAtEnd; +} + +uno::Any SAL_CALL ScCellsEnumeration::nextElement() throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell && !bAtEnd) + { + // Interface-Typ muss zu ScCellsObj::getElementType passen + + uno::Any aAny; + uno::Reference<table::XCell> xCell = new ScCellObj( pDocShell, aPos ); + aAny <<= xCell; + Advance_Impl(); + return aAny; + } + + throw container::NoSuchElementException(); // no more elements + return uno::Any(); +} + + +ScCellFormatsObj::ScCellFormatsObj(ScDocShell* pDocSh, const ScRange& rRange) : + pDocShell( pDocSh ), + aTotalRange( rRange ) +{ + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->AddUnoObject(*this); + + DBG_ASSERT( aTotalRange.aStart.Tab() == aTotalRange.aEnd.Tab(), "unterschiedliche Tabellen" ); +} + +ScCellFormatsObj::~ScCellFormatsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScCellFormatsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! aTotalRange... + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +ScCellRangeObj* ScCellFormatsObj::GetObjectByIndex_Impl(long nIndex) const +{ + //! direkt auf die AttrArrays zugreifen !!!! + + ScCellRangeObj* pRet = NULL; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + long nPos = 0; + ScAttrRectIterator aIter( pDoc, aTotalRange.aStart.Tab(), + aTotalRange.aStart.Col(), aTotalRange.aStart.Row(), + aTotalRange.aEnd.Col(), aTotalRange.aEnd.Row() ); + USHORT nCol1, nCol2, nRow1, nRow2; + while ( aIter.GetNext( nCol1, nCol2, nRow1, nRow2 ) ) + { + if ( nPos == nIndex ) + { + USHORT nTab = aTotalRange.aStart.Tab(); + ScRange aNext( nCol1, nRow1, nTab, nCol2, nRow2, nTab ); + + if ( aNext.aStart == aNext.aEnd ) + pRet = new ScCellObj( pDocShell, aNext.aStart ); + else + pRet = new ScCellRangeObj( pDocShell, aNext ); + } + ++nPos; + } + } + return pRet; +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScCellFormatsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! direkt auf die AttrArrays zugreifen !!!! + + long nCount = 0; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScAttrRectIterator aIter( pDoc, aTotalRange.aStart.Tab(), + aTotalRange.aStart.Col(), aTotalRange.aStart.Row(), + aTotalRange.aEnd.Col(), aTotalRange.aEnd.Row() ); + USHORT nCol1, nCol2, nRow1, nRow2; + while ( aIter.GetNext( nCol1, nCol2, nRow1, nRow2 ) ) + ++nCount; + } + return nCount; +} + +uno::Any SAL_CALL ScCellFormatsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<table::XCellRange> xRange = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xRange.is()) + aAny <<= xRange; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScCellFormatsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<table::XCellRange>*)0); +} + +sal_Bool SAL_CALL ScCellFormatsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); //! immer groesser 0 ?? +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScCellFormatsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScCellFormatsEnumeration( pDocShell, aTotalRange ); + return NULL; +} + + +ScCellFormatsEnumeration::ScCellFormatsEnumeration(ScDocShell* pDocSh, const ScRange& rRange) : + pDocShell( pDocSh ), + nTab( rRange.aStart.Tab() ), + pIter( NULL ), + bAtEnd( FALSE ), + bDirty( FALSE ) +{ + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->AddUnoObject(*this); + + DBG_ASSERT( rRange.aStart.Tab() == rRange.aEnd.Tab(), + "CellFormatsEnumeration: unterschiedliche Tabellen" ); + + pIter = new ScAttrRectIterator( pDoc, nTab, + rRange.aStart.Col(), rRange.aStart.Row(), + rRange.aEnd.Col(), rRange.aEnd.Row() ); + Advance_Impl(); +} + +ScCellFormatsEnumeration::~ScCellFormatsEnumeration() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + delete pIter; +} + +void ScCellFormatsEnumeration::Advance_Impl() +{ + DBG_ASSERT(!bAtEnd,"zuviel Advance_Impl"); + + if ( pIter ) + { + if ( bDirty ) + { + pIter->DataChanged(); // AttrArray-Index neu suchen + bDirty = FALSE; + } + + USHORT nCol1, nCol2, nRow1, nRow2; + if ( pIter->GetNext( nCol1, nCol2, nRow1, nRow2 ) ) + aNext = ScRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab ); + else + bAtEnd = TRUE; // kommt nix mehr + } + else + bAtEnd = TRUE; // Dok weggekommen oder so +} + +ScCellRangeObj* ScCellFormatsEnumeration::NextObject_Impl() +{ + ScCellRangeObj* pRet = NULL; + if (pDocShell && !bAtEnd) + { + if ( aNext.aStart == aNext.aEnd ) + pRet = new ScCellObj( pDocShell, aNext.aStart ); + else + pRet = new ScCellRangeObj( pDocShell, aNext ); + Advance_Impl(); + } + return pRet; +} + +void ScCellFormatsEnumeration::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! und nun ??? + } + else if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + delete pIter; + pIter = NULL; + } + else if ( nId == SFX_HINT_DATACHANGED ) + { + bDirty = TRUE; // AttrArray-Index evtl. ungueltig geworden + } + } +} + +// XEnumeration + +sal_Bool SAL_CALL ScCellFormatsEnumeration::hasMoreElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return !bAtEnd; +} + +uno::Any SAL_CALL ScCellFormatsEnumeration::nextElement() throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( bAtEnd || !pDocShell ) + throw container::NoSuchElementException(); // no more elements + + // Interface-Typ muss zu ScCellFormatsObj::getElementType passen + + uno::Any aAny; + uno::Reference<table::XCellRange> xRange = NextObject_Impl(); + aAny <<= xRange; + return aAny; +} + + +ScUniqueCellFormatsObj::ScUniqueCellFormatsObj(ScDocShell* pDocSh, const ScRange& rRange) : + pDocShell( pDocSh ), + aTotalRange( rRange ), + aRangeLists() +{ + pDocShell->GetDocument()->AddUnoObject(*this); + + DBG_ASSERT( aTotalRange.aStart.Tab() == aTotalRange.aEnd.Tab(), "unterschiedliche Tabellen" ); + + GetObjects_Impl(); +} + +ScUniqueCellFormatsObj::~ScUniqueCellFormatsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScUniqueCellFormatsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! aTotalRange... + } + else if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + pDocShell = NULL; // ungueltig geworden + } +} + +void ScUniqueCellFormatsObj::GetObjects_Impl() +{ + //! direkt auf die AttrArrays zugreifen !!!! + + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nTab = aTotalRange.aStart.Tab(); + ScAttrRectIterator aIter( pDoc, nTab, + aTotalRange.aStart.Col(), aTotalRange.aStart.Row(), + aTotalRange.aEnd.Col(), aTotalRange.aEnd.Row() ); + USHORT nCol1, nCol2, nRow1, nRow2; + std::list<ScRange> aList; + ScRange aFirst; + if (aIter.GetNext( nCol1, nCol2, nRow1, nRow2 ) ) + { + aFirst = ScRange( nCol1, nRow1, nTab, nCol2, nRow2, nTab ); + aRangeLists.push_back(ScRangeList()); + aRangeLists[0].Join(aFirst); + } + while ( aIter.GetNext( nCol1, nCol2, nRow1, nRow2 ) ) + { + ScRange aNext( nCol1, nRow1, nTab, nCol2, nRow2, nTab ); + if (pDoc->GetPattern(nCol1, nRow1, nTab) == pDoc->GetPattern(aFirst.aStart.Col(), aFirst.aStart.Row(), aFirst.aStart.Tab()) ) + aRangeLists[0].Join(aNext); + else + aList.push_back(aNext); + } + if (!aList.empty()) + { + std::list<ScRange>::iterator aItr = aList.begin(); + aRangeLists.push_back(ScRangeList()); + sal_Int32 nIndex(1); + aFirst = *aItr; + aRangeLists[nIndex].Join(aFirst); + aItr = aList.erase(aItr); + while (!aList.empty()) + { + if (pDoc->GetPattern(aItr->aStart.Col(), aItr->aStart.Row(), aItr->aStart.Tab()) == + pDoc->GetPattern(aFirst.aStart.Col(), aFirst.aStart.Row(), aFirst.aStart.Tab()) ) + { + aRangeLists[nIndex].Join(*aItr); + aItr = aList.erase(aItr); + } + else + ++aItr; + if (aItr == aList.end() && !aList.empty()) + { + aItr = aList.begin(); + aRangeLists.push_back(ScRangeList()); + nIndex++; + aFirst = *aItr; + aRangeLists[nIndex].Join(aFirst); + aItr = aList.erase(aItr); + } + } + } + } +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScUniqueCellFormatsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + return aRangeLists.size(); +} + +uno::Any SAL_CALL ScUniqueCellFormatsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Any aAny; + if(static_cast<sal_uInt32>(nIndex) < aRangeLists.size()) + { + uno::Reference<sheet::XSheetCellRangeContainer> xCellRanges = new ScCellRangesObj(pDocShell, aRangeLists[nIndex]); + aAny <<= xCellRanges; + } + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScUniqueCellFormatsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XSheetCellRangeContainer>*)0); +} + +sal_Bool SAL_CALL ScUniqueCellFormatsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( aRangeLists.size() != 0 ); +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScUniqueCellFormatsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScUniqueCellFormatsEnumeration( pDocShell, aRangeLists ); + return NULL; +} + + +ScUniqueCellFormatsEnumeration::ScUniqueCellFormatsEnumeration(ScDocShell* pDocSh, const ScMyRangeLists& rRangeLists) : + aRangeLists(rRangeLists), + pDocShell( pDocSh ), + nCurrentPosition(0) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScUniqueCellFormatsEnumeration::~ScUniqueCellFormatsEnumeration() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScUniqueCellFormatsEnumeration::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! und nun ??? + } + else if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + pDocShell = NULL; // ungueltig geworden + } +} + +// XEnumeration + +sal_Bool SAL_CALL ScUniqueCellFormatsEnumeration::hasMoreElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return static_cast<sal_uInt32>(nCurrentPosition + 1) < aRangeLists.size(); +} + +uno::Any SAL_CALL ScUniqueCellFormatsEnumeration::nextElement() throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !hasMoreElements() || !pDocShell ) + throw container::NoSuchElementException(); // no more elements + + // Interface-Typ muss zu ScCellFormatsObj::getElementType passen + + nCurrentPosition++; + uno::Reference<sheet::XSheetCellRangeContainer> xCellRanges = new ScCellRangesObj(pDocShell, aRangeLists[nCurrentPosition]); + uno::Any aAny; + aAny <<= xCellRanges; + return aAny; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_chartuno.cxx b/bf_sc/source/ui/unoobj/sc_chartuno.cxx new file mode 100644 index 000000000..a28b7222c --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_chartuno.cxx @@ -0,0 +1,596 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <bf_svx/svditer.hxx> +#include <bf_svx/svdoole2.hxx> +#include <bf_svx/svdpage.hxx> +#include <bf_svx/svdundo.hxx> +#include <bf_sch/schdll.hxx> +#include <bf_sch/memchrt.hxx> +#include <bf_sch/schdll0.hxx> +#include <bf_svtools/moduleoptions.hxx> + +#include "chartuno.hxx" +#include "miscuno.hxx" +#include "docsh.hxx" +#include "drwlayer.hxx" +#include "undodat.hxx" +#include "chartarr.hxx" +#include "chartlis.hxx" +#include <vcl/svapp.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + + +SC_SIMPLE_SERVICE_INFO( ScChartObj, "ScChartObj", "com.sun.star.table.TableChart" ) +SC_SIMPLE_SERVICE_INFO( ScChartsObj, "ScChartsObj", "com.sun.star.table.TableCharts" ) + + +SdrOle2Obj* lcl_FindChartObj( ScDocShell* pDocShell, USHORT nTab, const String& rName ) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + if (pDrawLayer) + { + SdrPage* pPage = pDrawLayer->GetPage(nTab); + DBG_ASSERT(pPage, "Page nicht gefunden"); + if (pPage) + { + SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); + SdrObject* pObject = aIter.Next(); + while (pObject) + { + if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) ) + { + SvInPlaceObjectRef aIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); + if (aIPObj.Is()) + { + SvInfoObject* pInfoObj = pDocShell->Find( aIPObj ); + if (pInfoObj) + { + if ( pInfoObj->GetObjName() == rName ) + return (SdrOle2Obj*)pObject; + } + } + } + pObject = aIter.Next(); + } + } + } + } + return NULL; +} + + +ScChartsObj::ScChartsObj(ScDocShell* pDocSh, USHORT nT) : + pDocShell( pDocSh ), + nTab( nT ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScChartsObj::~ScChartsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScChartsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! Referenz-Update + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +ScChartObj* ScChartsObj::GetObjectByIndex_Impl(long nIndex) const +{ + String aName; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + if (pDrawLayer) + { + SdrPage* pPage = pDrawLayer->GetPage(nTab); + DBG_ASSERT(pPage, "Page nicht gefunden"); + if (pPage) + { + long nPos = 0; + SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); + SdrObject* pObject = aIter.Next(); + while (pObject) + { + if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) ) + { + if ( nPos == nIndex ) + { + SvInPlaceObjectRef aIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); + if (aIPObj.Is()) + { + SvInfoObject* pInfoObj = pDocShell->Find( aIPObj ); + if (pInfoObj) + aName = pInfoObj->GetObjName(); + } + break; // nicht weitersuchen + } + ++nPos; + } + pObject = aIter.Next(); + } + } + } + } + + if (aName.Len()) + return new ScChartObj( pDocShell, nTab, aName ); + return NULL; +} + +ScChartObj* ScChartsObj::GetObjectByName_Impl(const ::rtl::OUString& aName) const +{ + String aNameString = aName; + if ( lcl_FindChartObj( pDocShell, nTab, aNameString ) ) + return new ScChartObj( pDocShell, nTab, aNameString ); + return NULL; +} + +// XTableCharts + +void SAL_CALL ScChartsObj::addNewByName( const ::rtl::OUString& aName, + const awt::Rectangle& aRect, + const uno::Sequence<table::CellRangeAddress>& aRanges, + sal_Bool bColumnHeaders, sal_Bool bRowHeaders ) + throw(::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pDocShell) + return; + + ScDocument* pDoc = pDocShell->GetDocument(); + ScDrawLayer* pModel = pDocShell->MakeDrawLayer(); + SdrPage* pPage = pModel->GetPage(nTab); + DBG_ASSERT(pPage,"addChart: keine Page"); + if (!pPage) + return; + + // chart can't be inserted if any ole object with that name exists on any table + // (empty string: generate valid name) + + String aNameString = aName; + USHORT nDummy; + if ( aNameString.Len() && pModel->GetNamedObject( aNameString, OBJ_OLE2, nDummy ) ) + { + // object exists - only RuntimeException is specified + throw uno::RuntimeException(); + } + + ScRangeList* pList = new ScRangeList; + USHORT nRangeCount = (USHORT)aRanges.getLength(); + if (nRangeCount) + { + const table::CellRangeAddress* pAry = aRanges.getConstArray(); + for (USHORT i=0; i<nRangeCount; i++) + { + ScRange aRange( (USHORT)pAry[i].StartColumn, (USHORT)pAry[i].StartRow, pAry[i].Sheet, + (USHORT)pAry[i].EndColumn, (USHORT)pAry[i].EndRow, pAry[i].Sheet ); + pList->Append( aRange ); + } + } + ScRangeListRef xNewRanges( pList ); + + SvStorageRef aStor = new SvStorage( String() ); + SvInPlaceObjectRef aIPObj; + if ( SvtModuleOptions().IsChart() ) + aIPObj = &((SvFactory*)SvInPlaceObject::ClassFactory())->CreateAndInit( + *SCH_MOD()->pSchChartDocShellFactory, + aStor ); + if ( aIPObj.Is() ) + { + SvEmbeddedInfoObject* pInfoObj = pDocShell->InsertObject( aIPObj, aNameString ); + if ( pInfoObj ) + { + String aObjName = pInfoObj->GetObjName(); // wirklich eingefuegter Name... + + // Rechteck anpassen + //! Fehler/Exception, wenn leer/ungueltig ??? + Point aRectPos( aRect.X, aRect.Y ); + if (aRectPos.X() < 0) aRectPos.X() = 0; + if (aRectPos.Y() < 0) aRectPos.Y() = 0; + Size aRectSize( aRect.Width, aRect.Height ); + if (aRectSize.Width() <= 0) aRectSize.Width() = 5000; // Default-Groesse + if (aRectSize.Height() <= 0) aRectSize.Height() = 5000; + Rectangle aInsRect( aRectPos, aRectSize ); + + Size aSize = aInsRect.GetSize(); + aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aIPObj->GetMapUnit() ) ); + aIPObj->SetVisAreaSize(aSize); + + Window* pWin = NULL; + + ScChartArray aParam( pDoc, xNewRanges, String() ); + aParam.SetHeaders( bColumnHeaders, bRowHeaders ); + SchMemChart* pMemChart = aParam.CreateMemChart(); + SchDLL::Update( aIPObj, pMemChart, pWin ); + delete pMemChart; + + ScChartListener* pChartListener = + new ScChartListener( aObjName, pDoc, xNewRanges ); + pDoc->GetChartListenerCollection()->Insert( pChartListener ); + pChartListener->StartListeningTo(); + + SdrOle2Obj* pObj = new SdrOle2Obj( aIPObj, aObjName, aInsRect ); + + pPage->InsertObject( pObj ); + pModel->AddUndo( new SdrUndoInsertObj( *pObj ) ); //! Undo-Kommentar? + + // Dies veranlaesst Chart zum sofortigen Update + + aIPObj->SendViewChanged(); + } + } +} + +void SAL_CALL ScChartsObj::removeByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aName; + SdrOle2Obj* pObj = lcl_FindChartObj( pDocShell, nTab, aNameString ); + if (pObj) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDrawLayer* pModel = pDoc->GetDrawLayer(); // ist nicht 0 + SdrPage* pPage = pModel->GetPage(nTab); // ist nicht 0 + + pModel->AddUndo( new SdrUndoRemoveObj( *pObj ) ); //! Undo-Kommentar? + pPage->RemoveObject( pObj->GetOrdNum() ); + + //! Notify etc.??? + } +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScChartsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableChartsEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScChartsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + INT32 nCount = 0; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + if (pDrawLayer) + { + SdrPage* pPage = pDrawLayer->GetPage(nTab); + DBG_ASSERT(pPage, "Page nicht gefunden"); + if (pPage) + { + SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); + SdrObject* pObject = aIter.Next(); + while (pObject) + { + if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) ) + ++nCount; + pObject = aIter.Next(); + } + } + } + } + return nCount; +} + +uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<table::XTableChart> xChart = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xChart.is()) + aAny <<= xChart; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScChartsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<table::XTableChart>*)0); +} + +sal_Bool SAL_CALL ScChartsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCount() != 0; +} + +uno::Any SAL_CALL ScChartsObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<table::XTableChart> xChart = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xChart.is()) + aAny <<= xChart; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScChartsObj::getElementNames() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + long nCount = getCount(); + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + + long nPos = 0; + ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer(); + if (pDrawLayer) + { + SdrPage* pPage = pDrawLayer->GetPage(nTab); + DBG_ASSERT(pPage, "Page nicht gefunden"); + if (pPage) + { + SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); + SdrObject* pObject = aIter.Next(); + while (pObject) + { + if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) ) + { + String aName; + SvInPlaceObjectRef aIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); + if (aIPObj.Is()) + { + SvInfoObject* pInfoObj = pDocShell->Find( aIPObj ); + if (pInfoObj) + aName = pInfoObj->GetObjName(); + } + DBG_ASSERT(nPos<nCount, "huch, verzaehlt?"); + pAry[nPos++] = aName; + } + pObject = aIter.Next(); + } + } + } + DBG_ASSERT(nPos==nCount, "nanu, verzaehlt?"); + + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(0); +} + +sal_Bool SAL_CALL ScChartsObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aName; + return ( lcl_FindChartObj( pDocShell, nTab, aNameString ) != NULL ); +} + + +ScChartObj::ScChartObj(ScDocShell* pDocSh, USHORT nT, const String& rN) : + pDocShell( pDocSh ), + nTab( nT ), + aChartName( rN ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScChartObj::~ScChartObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScChartObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! Referenz-Update + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, BOOL& rColHeaders, BOOL& rRowHeaders ) const +{ + rRanges = NULL; + rColHeaders = FALSE; + rRowHeaders = FALSE; +} + +void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, BOOL bColHeaders, BOOL bRowHeaders ) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + Window* pWin = NULL; + pDoc->UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, FALSE, pWin ); + } +} + +// XTableChart + +sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRangeListRef xRanges; + BOOL bColHeaders, bRowHeaders; + GetData_Impl( xRanges, bColHeaders, bRowHeaders ); + return bColHeaders; +} + +void SAL_CALL ScChartObj::setHasColumnHeaders( sal_Bool bHasColumnHeaders ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRangeListRef xRanges; + BOOL bOldColHeaders, bOldRowHeaders; + GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders ); + if ( bOldColHeaders != bHasColumnHeaders ) + Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders ); +} + +sal_Bool SAL_CALL ScChartObj::getHasRowHeaders() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRangeListRef xRanges; + BOOL bColHeaders, bRowHeaders; + GetData_Impl( xRanges, bColHeaders, bRowHeaders ); + return bRowHeaders; +} + +void SAL_CALL ScChartObj::setHasRowHeaders( sal_Bool bHasRowHeaders ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRangeListRef xRanges; + BOOL bOldColHeaders, bOldRowHeaders; + GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders ); + if ( bOldRowHeaders != bHasRowHeaders ) + Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders ); +} + +uno::Sequence<table::CellRangeAddress> SAL_CALL ScChartObj::getRanges() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRangeListRef xRanges; + BOOL bColHeaders, bRowHeaders; + GetData_Impl( xRanges, bColHeaders, bRowHeaders ); + if ( xRanges.Is() ) + { + ULONG nCount = xRanges->Count(); + + table::CellRangeAddress aRangeAddress; + uno::Sequence<table::CellRangeAddress> aSeq(nCount); + table::CellRangeAddress* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + ScRange aRange = *xRanges->GetObject(i); + + aRangeAddress.Sheet = aRange.aStart.Tab(); + aRangeAddress.StartColumn = aRange.aStart.Col(); + aRangeAddress.StartRow = aRange.aStart.Row(); + aRangeAddress.EndColumn = aRange.aEnd.Col(); + aRangeAddress.EndRow = aRange.aEnd.Row(); + + pAry[i] = aRangeAddress; + } + return aSeq; + } + + OSL_FAIL("ScChartObj::getRanges: keine Ranges"); + return uno::Sequence<table::CellRangeAddress>(); +} + +void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress>& aRanges ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRangeListRef xOldRanges; + BOOL bColHeaders, bRowHeaders; + GetData_Impl( xOldRanges, bColHeaders, bRowHeaders ); + + ScRangeList* pList = new ScRangeList; + USHORT nRangeCount = (USHORT)aRanges.getLength(); + if (nRangeCount) + { + const table::CellRangeAddress* pAry = aRanges.getConstArray(); + for (USHORT i=0; i<nRangeCount; i++) + { + ScRange aRange( (USHORT)pAry[i].StartColumn, (USHORT)pAry[i].StartRow, pAry[i].Sheet, + (USHORT)pAry[i].EndColumn, (USHORT)pAry[i].EndRow, pAry[i].Sheet ); + pList->Append( aRange ); + } + } + ScRangeListRef xNewRanges( pList ); + + if ( !xOldRanges.Is() || (*xOldRanges) != (*xNewRanges) ) + Update_Impl( xNewRanges, bColHeaders, bRowHeaders ); +} + +// XEmbeddedObjectSupplier + +uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SdrOle2Obj* pObject = lcl_FindChartObj( pDocShell, nTab, aChartName ); + if (pObject) + { + SvInPlaceObjectRef aIPObj = pObject->GetObjRef(); + if (aIPObj.Is()) + { + SfxInPlaceObjectRef aSfxObj( aIPObj ); + if (aSfxObj.Is()) + { + SfxObjectShell* pObjSh = aSfxObj->GetObjectShell(); + if (pObjSh) + return pObjSh->GetBaseModel().get(); + } + } + } + return NULL; +} + +// XNamed + +::rtl::OUString SAL_CALL ScChartObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aChartName; +} + +void SAL_CALL ScChartObj::setName( const ::rtl::OUString& /*aName*/ ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + throw uno::RuntimeException(); // name cannot be changed +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_confuno.cxx b/bf_sc/source/ui/unoobj/sc_confuno.cxx new file mode 100644 index 000000000..db95849e5 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_confuno.cxx @@ -0,0 +1,406 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include "confuno.hxx" +#include "unonames.hxx" +#include <vcl/svapp.hxx> +#include "docsh.hxx" +#include "miscuno.hxx" +#include "forbiuno.hxx" +#include "viewopti.hxx" +#include "docpool.hxx" +#include "bf_sc.hrc" + +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include <bf_sfx2/printer.hxx> +#include <bf_sfx2/docinf.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + +#define SCCOMPSCPREADSHEETSETTINGS_SERVICE "com.sun.star.comp.SpreadsheetSettings" +#define SCDOCUMENTSETTINGS_SERVICE "com.sun.star.document.Settings" +#define SCSAVEVERSION "SaveVersionOnClose" + + +const SfxItemPropertyMap* lcl_GetConfigPropertyMap() +{ + static SfxItemPropertyMap aConfigPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNO_SHOWZERO), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SHOWNOTES), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SHOWGRID), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_GRIDCOLOR), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SHOWPAGEBR), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_LINKUPD), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_COLROWHDR), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SHEETTABS), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_OUTLSYMB), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SNAPTORASTER), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_RASTERVIS), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_RASTERRESX), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_RASTERRESY), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_RASTERSUBX), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_RASTERSUBY), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_RASTERSYNC), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_AUTOCALC), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_PRINTERNAME), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_PRINTERSETUP), 0, &getCppuType((uno::Sequence<sal_Int8>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_APPLYDOCINF), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_FORBIDDEN), 0, &getCppuType((uno::Reference<i18n::XForbiddenCharacters>*)0), beans::PropertyAttribute::READONLY,0}, + {MAP_CHAR_LEN(SC_UNO_CHARCOMP), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ASIANKERN), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SCSAVEVERSION), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_UPDTEMPL), 0, &getBooleanCppuType(), 0,0}, + {0,0,0,0,0,0} + }; + return aConfigPropertyMap_Impl; +} + +//------------------------------------------------------------------------ + +ScDocumentConfiguration::ScDocumentConfiguration(ScDocShell* pDocSh) + : pDocShell(pDocSh) + , aPropSet ( lcl_GetConfigPropertyMap() ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDocumentConfiguration::~ScDocumentConfiguration() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDocumentConfiguration::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocumentConfiguration::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScDocumentConfiguration::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if(pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if (pDoc) + { + sal_Bool bUpdateHeights = sal_False; + + ScViewOptions aViewOpt(pDoc->GetViewOptions()); + if ( aPropertyName.compareToAscii( SC_UNO_SHOWZERO ) == 0 ) + aViewOpt.SetOption(VOPT_NULLVALS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_SHOWNOTES ) == 0 ) + aViewOpt.SetOption(VOPT_NOTES, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_SHOWGRID ) == 0 ) + aViewOpt.SetOption(VOPT_GRID, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_GRIDCOLOR ) == 0 ) + { + sal_Int64 nColor(0); + if (aValue >>= nColor) + { + String aColorName; + Color aColor(static_cast<sal_uInt32>(nColor)); + aViewOpt.SetGridColor(aColor, aColorName); + } + } + else if ( aPropertyName.compareToAscii( SC_UNO_SHOWPAGEBR ) == 0 ) + aViewOpt.SetOption(VOPT_PAGEBREAKS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNONAME_LINKUPD ) == 0 ) + pDoc->SetLinkMode( static_cast<ScLkUpdMode> ( ScUnoHelpFunctions::GetInt16FromAny( aValue ) ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_COLROWHDR ) == 0 ) + aViewOpt.SetOption(VOPT_HEADER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_SHEETTABS ) == 0 ) + aViewOpt.SetOption(VOPT_TABCONTROLS, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_OUTLSYMB ) == 0 ) + aViewOpt.SetOption(VOPT_OUTLINER, ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_AUTOCALC ) == 0 ) + pDoc->SetAutoCalc( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_PRINTERNAME ) == 0 ) + { + SfxPrinter* pPrinter = pDocShell->GetPrinter(); + if (pPrinter) + { + ::rtl::OUString sPrinterName; + if (aValue >>= sPrinterName) + { + String aString(sPrinterName); + SfxPrinter* pNewPrinter = new SfxPrinter( pPrinter->GetOptions().Clone(), aString ); + if (pNewPrinter->IsKnown()) + pDocShell->SetPrinter( pNewPrinter, SFX_PRINTER_PRINTER ); + else + delete pNewPrinter; + } + else + throw lang::IllegalArgumentException(); + } + else + throw uno::RuntimeException(); + } + else if ( aPropertyName.compareToAscii( SC_UNO_PRINTERSETUP ) == 0 ) + { + uno::Sequence<sal_Int8> aSequence; + if ( aValue >>= aSequence ) + { + sal_uInt32 nSize = aSequence.getLength(); + SvMemoryStream aStream (aSequence.getArray(), nSize, STREAM_READ ); + aStream.Seek ( STREAM_SEEK_TO_BEGIN ); + SfxItemSet* pSet = new SfxItemSet( *pDoc->GetPool(), + SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN, + SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC, + SID_SCPRINTOPTIONS, SID_SCPRINTOPTIONS, + NULL ); + pDocShell->SetPrinter( SfxPrinter::Create( aStream, pSet ) ); + } + } + else if ( aPropertyName.compareToAscii( SC_UNO_APPLYDOCINF ) == 0 ) + pDocShell->GetDocInfo().SetUseUserData( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_FORBIDDEN ) == 0 ) + { + // read-only - should not be set + } + else if ( aPropertyName.compareToAscii( SC_UNO_CHARCOMP ) == 0 ) + { + // Int16 contains CharacterCompressionType values + sal_Int16 nUno = ScUnoHelpFunctions::GetInt16FromAny( aValue ); + pDoc->SetAsianCompression( (BYTE) nUno ); + bUpdateHeights = sal_True; + } + else if ( aPropertyName.compareToAscii( SC_UNO_ASIANKERN ) == 0 ) + { + pDoc->SetAsianKerning( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + bUpdateHeights = sal_True; + } + else if ( aPropertyName.compareToAscii( SCSAVEVERSION ) == 0) + pDocShell->GetDocInfo().SetSaveVersionOnClose( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_UPDTEMPL ) == 0 ) + pDocShell->GetDocInfo().SetQueryLoadTemplate( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else + { + ScGridOptions aGridOpt(aViewOpt.GetGridOptions()); + if ( aPropertyName.compareToAscii( SC_UNO_SNAPTORASTER ) == 0 ) + aGridOpt.SetUseGridSnap( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERVIS ) == 0 ) + aGridOpt.SetGridVisible( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERRESX ) == 0 ) + aGridOpt.SetFldDrawX( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( aValue ) ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERRESY ) == 0 ) + aGridOpt.SetFldDrawY( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( aValue ) ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERSUBX ) == 0 ) + aGridOpt.SetFldDivisionX( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( aValue ) ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERSUBY ) == 0 ) + aGridOpt.SetFldDivisionY( static_cast <sal_uInt32> ( ScUnoHelpFunctions::GetInt32FromAny( aValue ) ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERSYNC ) == 0 ) + aGridOpt.SetSynchronize( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else + throw beans::UnknownPropertyException(); + aViewOpt.SetGridOptions(aGridOpt); + } + pDoc->SetViewOptions(aViewOpt); + + if ( bUpdateHeights && !pDoc->IsImportingXML() ) + { + // update automatic row heights and repaint + USHORT nTabCount = pDoc->GetTableCount(); + for (USHORT nTab=0; nTab<nTabCount; nTab++) + if ( !pDocShell->AdjustRowHeight( 0, MAXROW, nTab ) ) + pDocShell->PostPaint( 0,0,nTab, MAXCOL,MAXROW,nTab, PAINT_GRID ); + pDocShell->SetDocumentModified(); + } + } + else + throw uno::RuntimeException(); + } + else + throw uno::RuntimeException(); +} + +uno::Any SAL_CALL ScDocumentConfiguration::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aRet; + + if(pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if (pDoc) + { + const ScViewOptions& aViewOpt = pDoc->GetViewOptions(); + if ( aPropertyName.compareToAscii( SC_UNO_SHOWZERO ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aViewOpt.GetOption( VOPT_NULLVALS ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_SHOWNOTES ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aViewOpt.GetOption( VOPT_NOTES ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_SHOWGRID ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aViewOpt.GetOption( VOPT_GRID ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_GRIDCOLOR ) == 0 ) + { + String aColorName; + Color aColor = aViewOpt.GetGridColor(&aColorName); + aRet <<= static_cast<sal_Int64>(aColor.GetColor()); + } + else if ( aPropertyName.compareToAscii( SC_UNO_SHOWPAGEBR ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aViewOpt.GetOption( VOPT_PAGEBREAKS ) ); + else if ( aPropertyName.compareToAscii( SC_UNONAME_LINKUPD ) == 0 ) + aRet <<= static_cast<sal_Int16> ( pDoc->GetLinkMode() ); + else if ( aPropertyName.compareToAscii( SC_UNO_COLROWHDR ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aViewOpt.GetOption( VOPT_HEADER ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_SHEETTABS ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aViewOpt.GetOption( VOPT_TABCONTROLS ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_OUTLSYMB ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aViewOpt.GetOption( VOPT_OUTLINER ) ); + else if ( aPropertyName.compareToAscii( SC_UNO_AUTOCALC ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->GetAutoCalc() ); + else if ( aPropertyName.compareToAscii( SC_UNO_PRINTERNAME ) == 0 ) + { + SfxPrinter *pPrinter = pDoc->GetPrinter (); + if (pPrinter) + aRet <<= ::rtl::OUString ( pPrinter->GetName()); + else + throw uno::RuntimeException(); + } + else if ( aPropertyName.compareToAscii( SC_UNO_PRINTERSETUP ) == 0 ) + { + SfxPrinter *pPrinter = pDocShell->GetPrinter(); + if (pPrinter) + { + SvMemoryStream aStream; + pPrinter->Store( aStream ); + aStream.Seek ( STREAM_SEEK_TO_END ); + sal_uInt32 nSize = aStream.Tell(); + aStream.Seek ( STREAM_SEEK_TO_BEGIN ); + uno::Sequence < sal_Int8 > aSequence( nSize ); + aStream.Read ( aSequence.getArray(), nSize ); + aRet <<= aSequence; + } + } + else if ( aPropertyName.compareToAscii( SC_UNO_APPLYDOCINF ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, pDocShell->GetDocInfo().IsUseUserData() ); + else if ( aPropertyName.compareToAscii( SC_UNO_FORBIDDEN ) == 0 ) + { + uno::Reference<i18n::XForbiddenCharacters> xForbidden = new ScForbiddenCharsObj( pDocShell ); + aRet <<= xForbidden; + } + else if ( aPropertyName.compareToAscii( SC_UNO_CHARCOMP ) == 0 ) + aRet <<= static_cast<sal_Int16> ( pDoc->GetAsianCompression() ); + else if ( aPropertyName.compareToAscii( SC_UNO_ASIANKERN ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, pDoc->GetAsianKerning() ); + else if ( aPropertyName.compareToAscii( SCSAVEVERSION ) == 0) + ScUnoHelpFunctions::SetBoolInAny( aRet, pDocShell->GetDocInfo().IsSaveVersionOnClose() ); + else if ( aPropertyName.compareToAscii( SC_UNO_UPDTEMPL ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, pDocShell->GetDocInfo().IsQueryLoadTemplate()); + else + { + const ScGridOptions& aGridOpt = aViewOpt.GetGridOptions(); + if ( aPropertyName.compareToAscii( SC_UNO_SNAPTORASTER ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aGridOpt.GetUseGridSnap() ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERVIS ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aGridOpt.GetGridVisible() ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERRESX ) == 0 ) + aRet <<= static_cast<sal_Int32> ( aGridOpt.GetFldDrawX() ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERRESY ) == 0 ) + aRet <<= static_cast<sal_Int32> ( aGridOpt.GetFldDrawY() ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERSUBX ) == 0 ) + aRet <<= static_cast<sal_Int32> ( aGridOpt.GetFldDivisionX() ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERSUBY ) == 0 ) + aRet <<= static_cast<sal_Int32> ( aGridOpt.GetFldDivisionY() ); + else if ( aPropertyName.compareToAscii( SC_UNO_RASTERSYNC ) == 0 ) + ScUnoHelpFunctions::SetBoolInAny( aRet, aGridOpt.GetSynchronize() ); + else + throw beans::UnknownPropertyException(); + } + } + else + throw uno::RuntimeException(); + } + else + throw uno::RuntimeException(); + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDocumentConfiguration ) + +// XServiceInfo + +::rtl::OUString SAL_CALL ScDocumentConfiguration::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScDocumentConfiguration" )); +} + +sal_Bool SAL_CALL ScDocumentConfiguration::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCCOMPSCPREADSHEETSETTINGS_SERVICE ) || + aServiceStr.EqualsAscii( SCDOCUMENTSETTINGS_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScDocumentConfiguration::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(2); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCOMPSCPREADSHEETSETTINGS_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCDOCUMENTSETTINGS_SERVICE )); + return aRet; +} + +//------------------------------------------------------------------------- + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_convuno.cxx b/bf_sc/source/ui/unoobj/sc_convuno.cxx new file mode 100644 index 000000000..d94ab3969 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_convuno.cxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <i18npool/mslangid.hxx> + +#include "convuno.hxx" + +#include <com/sun/star/lang/Locale.hpp> + +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +// everything is static... + +LanguageType ScUnoConversion::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; +} + +void ScUnoConversion::FillLocale( lang::Locale& rLocale, LanguageType eLang ) +{ + MsLangId::convertLanguageToLocale( eLang, rLocale ); +} + + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_cursuno.cxx b/bf_sc/source/ui/unoobj/sc_cursuno.cxx new file mode 100644 index 000000000..24a286abb --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_cursuno.cxx @@ -0,0 +1,483 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <rtl/uuid.h> + +#include "cursuno.hxx" +#include "docsh.hxx" +#include "markdata.hxx" +#include <vcl/svapp.hxx> +#include "miscuno.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +#define SCSHEETCELLCURSOR_SERVICE "com.sun.star.sheet.SheetCellCursor" +#define SCCELLCURSOR_SERVICE "com.sun.star.table.CellCursor" + +//------------------------------------------------------------------------ + +ScCellCursorObj::ScCellCursorObj(ScDocShell* pDocSh, const ScRange& rR) : + ScCellRangeObj( pDocSh, rR ) +{ +} + +ScCellCursorObj::~ScCellCursorObj() +{ +} + +uno::Any SAL_CALL ScCellCursorObj::queryInterface( const uno::Type& rType ) throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( sheet::XSheetCellCursor ) + SC_QUERYINTERFACE( sheet::XUsedAreaCursor ) + SC_QUERYINTERFACE( table::XCellCursor ) + + return ScCellRangeObj::queryInterface( rType ); +} + +void SAL_CALL ScCellCursorObj::acquire() throw() +{ + ScCellRangeObj::acquire(); +} + +void SAL_CALL ScCellCursorObj::release() throw() +{ + ScCellRangeObj::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScCellCursorObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = ScCellRangeObj::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 3 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSheetCellCursor>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<sheet::XUsedAreaCursor>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<table::XCellCursor>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScCellCursorObj::getImplementationId() throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +// XSheetCellCursor + +void SAL_CALL ScCellCursorObj::collapseToCurrentRegion() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aLclRange = *rRanges.GetObject(0); + + aLclRange.Justify(); + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nStartCol = aLclRange.aStart.Col(); + USHORT nStartRow = aLclRange.aStart.Row(); + USHORT nEndCol = aLclRange.aEnd.Col(); + USHORT nEndRow = aLclRange.aEnd.Row(); + USHORT nTab = aLclRange.aStart.Tab(); + + ScRange aNew( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab ); + SetNewRange( aNew ); + } +} + +void SAL_CALL ScCellCursorObj::collapseToCurrentArray() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aLclRange = *rRanges.GetObject(0); + + aLclRange.Justify(); + ScAddress aCursor = aLclRange.aStart; // use the start address of the range + + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + ScRange aMatrix; + + // finding the matrix range is now in GetMatrixFormulaRange in the document + if ( pDoc->GetMatrixFormulaRange( aCursor, aMatrix ) ) + { + SetNewRange( aMatrix ); + } + } + // thats a Bug, that this assertion comes; the API Reference says, that + // if there is no Matrix, the Range is left unchanged; they says nothing + // about a exception + /*if (!bFound) + { + OSL_FAIL("keine Matrix"); + //! Exception, oder was? + }*/ +} + +void SAL_CALL ScCellCursorObj::collapseToMergedArea() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aNewRange = *rRanges.GetObject(0); + + ScDocument* pDoc = pDocSh->GetDocument(); + pDoc->ExtendOverlapped( aNewRange ); + pDoc->ExtendMerge( aNewRange ); // after ExtendOverlapped! + + SetNewRange( aNewRange ); + } +} + +void SAL_CALL ScCellCursorObj::expandToEntireColumns() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aNewRange = *rRanges.GetObject(0); + + aNewRange.aStart.SetRow( 0 ); + aNewRange.aEnd.SetRow( MAXROW ); + + SetNewRange( aNewRange ); +} + +void SAL_CALL ScCellCursorObj::expandToEntireRows() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aNewRange = *rRanges.GetObject(0); + + aNewRange.aStart.SetCol( 0 ); + aNewRange.aEnd.SetCol( MAXCOL ); + + SetNewRange( aNewRange ); +} + +void SAL_CALL ScCellCursorObj::collapseToSize( sal_Int32 nColumns, sal_Int32 nRows ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( nColumns <= 0 || nRows <= 0 ) + { + OSL_FAIL("leerer Range geht nicht"); + //! und dann? + } + else + { + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aNewRange = *rRanges.GetObject(0); + + aNewRange.Justify(); //! wirklich? + + long nEndX = aNewRange.aStart.Col() + nColumns - 1; + long nEndY = aNewRange.aStart.Row() + nRows - 1; + if ( nEndX < 0 ) nEndX = 0; + if ( nEndX > MAXCOL ) nEndX = MAXCOL; + if ( nEndY < 0 ) nEndY = 0; + if ( nEndY > MAXROW ) nEndY = MAXROW; + //! Fehler/Exception oder so, wenn zu gross/zu klein? + + aNewRange.aEnd.SetCol((USHORT)nEndX); + aNewRange.aEnd.SetRow((USHORT)nEndY); + + aNewRange.Justify(); //! wirklich? + + SetNewRange( aNewRange ); + } +} + +// XUsedAreaCursor + +void SAL_CALL ScCellCursorObj::gotoStartOfUsedArea( sal_Bool bExpand ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aNewRange = *rRanges.GetObject(0); + USHORT nTab = aNewRange.aStart.Tab(); + + USHORT nUsedX = 0; // Anfang holen + USHORT nUsedY = 0; + if (!pDocSh->GetDocument()->GetDataStart( nTab, nUsedX, nUsedY )) + nUsedX = nUsedY = 0; + + aNewRange.aStart.SetCol( nUsedX ); + aNewRange.aStart.SetRow( nUsedY ); + if (!bExpand) + aNewRange.aEnd = aNewRange.aStart; + SetNewRange( aNewRange ); + } +} + +void SAL_CALL ScCellCursorObj::gotoEndOfUsedArea( sal_Bool bExpand ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aNewRange = *rRanges.GetObject(0); + USHORT nTab = aNewRange.aStart.Tab(); + + USHORT nUsedX = 0; // Ende holen + USHORT nUsedY = 0; + if (!pDocSh->GetDocument()->GetTableArea( nTab, nUsedX, nUsedY )) + nUsedX = nUsedY = 0; + + aNewRange.aEnd.SetCol( nUsedX ); + aNewRange.aEnd.SetRow( nUsedY ); + if (!bExpand) + aNewRange.aStart = aNewRange.aEnd; + SetNewRange( aNewRange ); + } +} + +// XCellCursor + +void SAL_CALL ScCellCursorObj::gotoStart() throw(uno::RuntimeException) +{ + // this is similar to collapseToCurrentRegion + //! something like gotoEdge with 4 possible directions is needed + + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aLclRange = *rRanges.GetObject(0); + + aLclRange.Justify(); + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nStartCol = aLclRange.aStart.Col(); + USHORT nStartRow = aLclRange.aStart.Row(); + USHORT nTab = aLclRange.aStart.Tab(); + + ScRange aNew( nStartCol, nStartRow, nTab ); + SetNewRange( aNew ); + } +} + +void SAL_CALL ScCellCursorObj::gotoEnd() throw(uno::RuntimeException) +{ + // this is similar to collapseToCurrentRegion + //! something like gotoEdge with 4 possible directions is needed + + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aLclRange = *rRanges.GetObject(0); + + aLclRange.Justify(); + ScDocShell* pDocSh = GetDocShell(); + if ( pDocSh ) + { + USHORT nEndCol = aLclRange.aEnd.Col(); + USHORT nEndRow = aLclRange.aEnd.Row(); + USHORT nTab = aLclRange.aStart.Tab(); + + ScRange aNew( nEndCol, nEndRow, nTab ); + SetNewRange( aNew ); + } +} + +void SAL_CALL ScCellCursorObj::gotoNext() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aLclRange = *rRanges.GetObject(0); + + aLclRange.Justify(); + ScAddress aCursor = aLclRange.aStart; // bei Block immer den Start nehmen + + ScMarkData aMark; // not used with bMarked=FALSE + USHORT nNewX = aCursor.Col(); + USHORT nNewY = aCursor.Row(); + USHORT nTab = aCursor.Tab(); + //! sonst Exception oder so + + SetNewRange( ScRange( nNewX, nNewY, nTab ) ); +} + +void SAL_CALL ScCellCursorObj::gotoPrevious() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aLclRange = *rRanges.GetObject(0); + + aLclRange.Justify(); + ScAddress aCursor = aLclRange.aStart; // bei Block immer den Start nehmen + + ScMarkData aMark; // not used with bMarked=FALSE + USHORT nNewX = aCursor.Col(); + USHORT nNewY = aCursor.Row(); + USHORT nTab = aCursor.Tab(); + //! sonst Exception oder so + + SetNewRange( ScRange( nNewX, nNewY, nTab ) ); +} + +void SAL_CALL ScCellCursorObj::gotoOffset( sal_Int32 nColumnOffset, sal_Int32 nRowOffset ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + const ScRangeList& rRanges = GetRangeList(); + DBG_ASSERT( rRanges.Count() == 1, "Range? Ranges?" ); + ScRange aLclRange = *rRanges.GetObject(0); + aLclRange.Justify(); + + if ( aLclRange.aStart.Col() + nColumnOffset >= 0 && + aLclRange.aEnd.Col() + nColumnOffset <= MAXCOL && + aLclRange.aStart.Row() + nRowOffset >= 0 && + aLclRange.aEnd.Row() + nRowOffset <= MAXROW ) + { + ScRange aNew( (USHORT)(aLclRange.aStart.Col() + nColumnOffset), + (USHORT)(aLclRange.aStart.Row() + nRowOffset), + aLclRange.aStart.Tab(), + (USHORT)(aLclRange.aEnd.Col() + nColumnOffset), + (USHORT)(aLclRange.aEnd.Row() + nRowOffset), + aLclRange.aEnd.Tab() ); + SetNewRange( aNew ); + } +} + +// XSheetCellRange + +uno::Reference<sheet::XSpreadsheet> SAL_CALL ScCellCursorObj::getSpreadsheet() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScCellRangeObj::getSpreadsheet(); +} + +// XCellRange + +uno::Reference<table::XCell> SAL_CALL ScCellCursorObj::getCellByPosition( + sal_Int32 nColumn, sal_Int32 nRow ) + throw(lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScCellRangeObj::getCellByPosition(nColumn,nRow); +} + +uno::Reference<table::XCellRange> SAL_CALL ScCellCursorObj::getCellRangeByPosition( + sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom ) + throw(lang::IndexOutOfBoundsException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScCellRangeObj::getCellRangeByPosition(nLeft,nTop,nRight,nBottom); +} + +uno::Reference<table::XCellRange> SAL_CALL ScCellCursorObj::getCellRangeByName( + const ::rtl::OUString& rRange ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScCellRangeObj::getCellRangeByName(rRange); +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScCellCursorObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScCellCursorObj" )); +} + +sal_Bool SAL_CALL ScCellCursorObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCSHEETCELLCURSOR_SERVICE ) || + aServiceStr.EqualsAscii( SCCELLCURSOR_SERVICE ) || + ScCellRangeObj::supportsService(rServiceName); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellCursorObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + // get all service names from cell range + uno::Sequence< ::rtl::OUString> aParentSeq = ScCellRangeObj::getSupportedServiceNames(); + sal_Int32 nParentLen = aParentSeq.getLength(); + const ::rtl::OUString* pParentArr = aParentSeq.getConstArray(); + + // SheetCellCursor should be first (?) + uno::Sequence< ::rtl::OUString> aTotalSeq( nParentLen + 2 ); + ::rtl::OUString* pTotalArr = aTotalSeq.getArray(); + pTotalArr[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSHEETCELLCURSOR_SERVICE )); + pTotalArr[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLCURSOR_SERVICE )); + + // append cell range services + for (long i=0; i<nParentLen; i++) + pTotalArr[i+2] = pParentArr[i]; + + return aTotalSeq; +} + + + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_dapiuno.cxx b/bf_sc/source/ui/unoobj/sc_dapiuno.cxx new file mode 100644 index 000000000..541fe76b4 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_dapiuno.cxx @@ -0,0 +1,1825 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <rtl/uuid.h> + +#include "dapiuno.hxx" +#include "datauno.hxx" +#include "miscuno.hxx" +#include "docsh.hxx" +#include "pivot.hxx" +#include <vcl/svapp.hxx> +#include "dpobject.hxx" +#include "dpshttab.hxx" +#include "dpsave.hxx" +#include "dbdocfun.hxx" +#include "unonames.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + + +const SfxItemPropertyMap* lcl_GetDataPilotFieldMap() +{ + static SfxItemPropertyMap aDataPilotFieldMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_FUNCTION), 0, &getCppuType((sheet::GeneralFunction*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ORIENT), 0, &getCppuType((sheet::DataPilotFieldOrientation*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aDataPilotFieldMap_Impl; +} + + +SC_SIMPLE_SERVICE_INFO( ScDataPilotDescriptor, "ScDataPilotDescriptor", "stardiv::one::sheet::DataPilotDescriptor" ) +SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldObj, "ScDataPilotFieldObj", "com.sun.star.sheet.DataPilotField" ) +SC_SIMPLE_SERVICE_INFO( ScDataPilotFieldsObj, "ScDataPilotFieldsObj", "com.sun.star.sheet.DataPilotFields" ) +SC_SIMPLE_SERVICE_INFO( ScDataPilotTableObj, "ScDataPilotTableObj", "com.sun.star.sheet.DataPilotTable" ) +SC_SIMPLE_SERVICE_INFO( ScDataPilotTablesObj, "ScDataPilotTablesObj", "com.sun.star.sheet.DataPilotTables" ) + + +//! irgendwann ueberall die neuen enum-Werte benutzen +#define DATA_PILOT_HIDDEN sheet::DataPilotFieldOrientation_HIDDEN +#define DATA_PILOT_COLUMN sheet::DataPilotFieldOrientation_COLUMN +#define DATA_PILOT_ROW sheet::DataPilotFieldOrientation_ROW +#define DATA_PILOT_PAGE sheet::DataPilotFieldOrientation_PAGE +#define DATA_PILOT_DATA sheet::DataPilotFieldOrientation_DATA + + +USHORT lcl_BitCount( USHORT nBits ) +{ + if (!nBits) return 0; + + USHORT nCount = 0; + USHORT nMask = 1; + for (USHORT i=0; i<16; i++) + { + if ( nBits & nMask ) + ++nCount; + nMask <<= 1; + } + return nCount; +} + +USHORT lcl_DataCount( const ScPivotParam& rParam ) +{ + USHORT nRet = 0; + for ( USHORT i=0; i<rParam.nDataCount; i++ ) + nRet += lcl_BitCount( rParam.aDataArr[i].nFuncMask ); // nFuncCount stimmt nicht + return nRet; +} + +BOOL lcl_GetDataArrayPos( const ScPivotParam& rParam, USHORT nIndex, + USHORT& rArrayPos, USHORT& rFuncBit ) +{ + USHORT nPos = 0; + for ( USHORT i=0; i<rParam.nDataCount; i++ ) + { + USHORT nBits = rParam.aDataArr[i].nFuncMask; + USHORT nMask = 1; + for (USHORT nBP=0; nBP<16; nBP++) + { + if ( nBits & nMask ) + { + if ( nPos == nIndex ) + { + rArrayPos = i; // position in aDataArr + rFuncBit = nMask; + return TRUE; + } + ++nPos; + } + nMask <<= 1; + } + } + rArrayPos = 0; + rFuncBit = 0; + return FALSE; +} + +ScDPObject* lcl_GetDPObject( ScDocShell* pDocShell, USHORT nTab, const String& rName ) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDPCollection* pColl = pDoc->GetDPCollection(); + if ( pColl ) + { + USHORT nCount = pColl->GetCount(); + for (USHORT i=0; i<nCount; i++) + { + ScDPObject* pDPObj = (*pColl)[i]; + if ( pDPObj->IsSheetData() && + pDPObj->GetOutRange().aStart.Tab() == nTab && + pDPObj->GetName() == rName ) + return pDPObj; + } + } + } + return NULL; // nicht gefunden +} + +String lcl_ColumnTitle( ScDocument* pDoc, USHORT nCol, USHORT nRow, USHORT nTab ) +{ + // Spaltennamen, wie sie in der Pivottabelle angezeigt werden + String aStr; + pDoc->GetString(nCol, nRow, nTab, aStr); + if (aStr.Len() == 0) + aStr = ColToAlpha( nCol ); + return aStr; +} + +sheet::GeneralFunction ScDataPilotConversion::FirstFunc( USHORT nBits ) +{ + if ( nBits & PIVOT_FUNC_SUM ) return sheet::GeneralFunction_SUM; + if ( nBits & PIVOT_FUNC_COUNT ) return sheet::GeneralFunction_COUNT; + if ( nBits & PIVOT_FUNC_AVERAGE ) return sheet::GeneralFunction_AVERAGE; + if ( nBits & PIVOT_FUNC_MAX ) return sheet::GeneralFunction_MAX; + if ( nBits & PIVOT_FUNC_MIN ) return sheet::GeneralFunction_MIN; + if ( nBits & PIVOT_FUNC_PRODUCT ) return sheet::GeneralFunction_PRODUCT; + if ( nBits & PIVOT_FUNC_COUNT_NUM ) return sheet::GeneralFunction_COUNTNUMS; + if ( nBits & PIVOT_FUNC_STD_DEV ) return sheet::GeneralFunction_STDEV; + if ( nBits & PIVOT_FUNC_STD_DEVP ) return sheet::GeneralFunction_STDEVP; + if ( nBits & PIVOT_FUNC_STD_VAR ) return sheet::GeneralFunction_VAR; + if ( nBits & PIVOT_FUNC_STD_VARP ) return sheet::GeneralFunction_VARP; + if ( nBits & PIVOT_FUNC_AUTO ) return sheet::GeneralFunction_AUTO; + return sheet::GeneralFunction_NONE; +} + +USHORT ScDataPilotConversion::FunctionBit( sheet::GeneralFunction eFunc ) +{ + USHORT nRet = PIVOT_FUNC_NONE; // 0 + switch (eFunc) + { + case sheet::GeneralFunction_SUM: nRet = PIVOT_FUNC_SUM; break; + case sheet::GeneralFunction_COUNT: nRet = PIVOT_FUNC_COUNT; break; + case sheet::GeneralFunction_AVERAGE: nRet = PIVOT_FUNC_AVERAGE; break; + case sheet::GeneralFunction_MAX: nRet = PIVOT_FUNC_MAX; break; + case sheet::GeneralFunction_MIN: nRet = PIVOT_FUNC_MIN; break; + case sheet::GeneralFunction_PRODUCT: nRet = PIVOT_FUNC_PRODUCT; break; + case sheet::GeneralFunction_COUNTNUMS: nRet = PIVOT_FUNC_COUNT_NUM; break; + case sheet::GeneralFunction_STDEV: nRet = PIVOT_FUNC_STD_DEV; break; + case sheet::GeneralFunction_STDEVP: nRet = PIVOT_FUNC_STD_DEVP; break; + case sheet::GeneralFunction_VAR: nRet = PIVOT_FUNC_STD_VAR; break; + case sheet::GeneralFunction_VARP: nRet = PIVOT_FUNC_STD_VARP; break; + case sheet::GeneralFunction_AUTO: nRet = PIVOT_FUNC_AUTO; break; + default: break; + } + return nRet; +} + +String lcl_CreatePivotName( ScDocShell* pDocShell ) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDPCollection* pColl = pDoc->GetDPCollection(); + if ( pColl ) + return pColl->CreateNewName(); + } + return String(); // sollte nicht vorkommen +} + +void lcl_SetLayoutNamesToObject( ScDocument* pDoc, + const ScPivotParam& rParam, const ScArea& rSrcArea, + ScDPObject& rObject ) +{ + // set layout names from LabelData to SaveData + + //! reset old names? (renamed columns) + + ScDPSaveData* pOldData = rObject.GetSaveData(); + if ( pOldData && rSrcArea.nColEnd >= rSrcArea.nColStart ) + { + ScDPSaveData aNewData( *pOldData ); + + USHORT nRow = rSrcArea.nRowStart; + USHORT nTab = rSrcArea.nTab; + USHORT nCount = rSrcArea.nColEnd - rSrcArea.nColStart + 1; + for (USHORT nField = 0; nField < nCount; nField++) + { + USHORT nCol = rSrcArea.nColStart + nField; + String aSourceName = lcl_ColumnTitle( pDoc, nCol, nRow, nTab ); + + if ( nField < rParam.nLabels && rParam.ppLabelArr && + rParam.ppLabelArr[nField] && + rParam.ppLabelArr[nField]->pStrColName && + rParam.ppLabelArr[nField]->pStrColName->Len() ) + { + String aLayoutName = *rParam.ppLabelArr[nField]->pStrColName; + + // create SaveDimension if not there + ScDPSaveDimension* pDim = aNewData.GetDimensionByName( aSourceName ); + if (pDim) + pDim->SetLayoutName( &aLayoutName ); + } + else + { + // reset layout name if one was set + ScDPSaveDimension* pDim = aNewData.GetExistingDimensionByName( aSourceName ); + if (pDim) + pDim->ResetLayoutName(); + } + } + + rObject.SetSaveData( aNewData ); + } +} + +void lcl_SetLayoutNamesToParam( ScPivotParam& rParam, ScDocument* pDoc, + const ScArea& rSrcArea, const ScDPObject& rObject ) +{ + // set layout names from SaveData to LabelData + + ScDPSaveData* pSaveData = rObject.GetSaveData(); + if ( pSaveData && rSrcArea.nColEnd >= rSrcArea.nColStart ) + { + BOOL bAnyFound = FALSE; + USHORT nNewCount = rSrcArea.nColEnd - rSrcArea.nColStart + 1; + LabelData** ppNewData = new LabelData*[nNewCount]; + + USHORT nRow = rSrcArea.nRowStart; + USHORT nTab = rSrcArea.nTab; + for (USHORT nField = 0; nField < nNewCount; nField++) + { + USHORT nCol = rSrcArea.nColStart + nField; + String aSourceName = lcl_ColumnTitle( pDoc, nCol, nRow, nTab ); + + String aLayoutName; + ScDPSaveDimension* pDim = pSaveData->GetExistingDimensionByName( aSourceName ); + if ( pDim && pDim->HasLayoutName() ) + { + aLayoutName = pDim->GetLayoutName(); + if (aLayoutName.Len()) + bAnyFound = TRUE; + } + + ppNewData[nField] = new LabelData( aLayoutName, 0, FALSE ); + } + + if ( bAnyFound ) + rParam.SetLabelData( ppNewData, nNewCount ); + + // SetLabelData copies data - ppNewData must be deleted + for (USHORT i=0; i<nNewCount; i++) + delete ppNewData[i]; + delete[] ppNewData; + } +} + + +ScDataPilotTablesObj::ScDataPilotTablesObj(ScDocShell* pDocSh, USHORT nT) : + pDocShell( pDocSh ), + nTab( nT ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDataPilotTablesObj::~ScDataPilotTablesObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDataPilotTablesObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! Referenz-Update + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XDataPilotTables + +ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByIndex_Impl(USHORT nIndex) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDPCollection* pColl = pDoc->GetDPCollection(); + if ( pColl ) + { + // count tables on this sheet + // api only handles sheet data at this time + //! allow all data sources!!! + USHORT nFound = 0; + USHORT nCount = pColl->GetCount(); + for (USHORT i=0; i<nCount; i++) + { + ScDPObject* pDPObj = (*pColl)[i]; + if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + { + if ( nFound == nIndex ) + { + String aName = pDPObj->GetName(); + return new ScDataPilotTableObj( pDocShell, nTab, aName ); + } + ++nFound; + } + } + } + } + return NULL; +} + +ScDataPilotTableObj* ScDataPilotTablesObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + if (hasByName(aName)) + { + String aNamStr = aName; + return new ScDataPilotTableObj( pDocShell, nTab, aNamStr ); + } + return NULL; +} + +uno::Reference<sheet::XDataPilotDescriptor> SAL_CALL ScDataPilotTablesObj::createDataPilotDescriptor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScDataPilotDescriptor(pDocShell); + return NULL; +} + +void SAL_CALL ScDataPilotTablesObj::insertNewByName( const ::rtl::OUString& aNewName, + const table::CellAddress& aOutputAddress, + const uno::Reference<sheet::XDataPilotDescriptor>& xDescriptor ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!xDescriptor.is()) return; + + // inserting with already existing name? + if ( aNewName.getLength() && hasByName( aNewName ) ) + throw uno::RuntimeException(); // no other exceptions specified + + BOOL bDone = FALSE; + ScDataPilotDescriptorBase* pImp = ScDataPilotDescriptorBase::getImplementation( xDescriptor ); + if ( pDocShell && pImp ) + { + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pImp->GetParam( aParam, aQuery, aSrcArea ); + + aParam.nCol = (USHORT)aOutputAddress.Column; + aParam.nRow = (USHORT)aOutputAddress.Row; + aParam.nTab = aOutputAddress.Sheet; + + // in den Uno-Objekten sind alle Fields in den Descriptoren innerhalb des Bereichs gezaehlt + + short nFieldStart = aSrcArea.nColStart; + USHORT i; + for ( i=0; i<aParam.nColCount; i++ ) + if ( aParam.aColArr[i].nCol != PIVOT_DATA_FIELD ) + aParam.aColArr[i].nCol += nFieldStart; + for ( i=0; i<aParam.nRowCount; i++ ) + if ( aParam.aRowArr[i].nCol != PIVOT_DATA_FIELD ) + aParam.aRowArr[i].nCol += nFieldStart; + for ( i=0; i<aParam.nDataCount; i++ ) + if ( aParam.aDataArr[i].nCol != PIVOT_DATA_FIELD ) + aParam.aDataArr[i].nCol += nFieldStart; + + // Daten-Eintrag hinzufuegen, wenn noch nicht vorhanden + + BOOL bDataFound = FALSE; + for ( i=0; i<aParam.nColCount; i++ ) + if ( aParam.aColArr[i].nCol == PIVOT_DATA_FIELD ) + bDataFound = TRUE; + for ( i=0; i<aParam.nRowCount; i++ ) + if ( aParam.aRowArr[i].nCol == PIVOT_DATA_FIELD ) + bDataFound = TRUE; + if (!bDataFound) + { + if ( aParam.nRowCount < PIVOT_MAXFIELD ) + aParam.aRowArr[aParam.nRowCount++].nCol = PIVOT_DATA_FIELD; + else if ( aParam.nColCount < PIVOT_MAXFIELD ) + aParam.aColArr[aParam.nColCount++].nCol = PIVOT_DATA_FIELD; + else + throw uno::RuntimeException(); // no space for data field + } + + String aName = aNewName; + if (!aName.Len()) + aName = lcl_CreatePivotName( pDocShell ); + String aTag = xDescriptor->getTag(); + + ScDocument* pDoc = pDocShell->GetDocument(); + ScPivot* pNewPivot = new ScPivot( pDoc ); + pNewPivot->SetName( aName ); + pNewPivot->SetTag( aTag ); + pNewPivot->SetParam( aParam, aQuery, aSrcArea ); + + ScDPObject* pNewObj = new ScDPObject( pDoc ); + pNewObj->InitFromOldPivot( *pNewPivot, pDoc, TRUE ); + lcl_SetLayoutNamesToObject( pDoc, aParam, aSrcArea, *pNewObj ); + + ScDBDocFunc aFunc(*pDocShell); + bDone = aFunc.DataPilotUpdate( NULL, pNewObj, TRUE, TRUE ); + + delete pNewObj; // DataPilotUpdate copies settings from "new" object + delete pNewPivot; + } + + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScDataPilotTablesObj::removeByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr = aName; + ScDPObject* pDPObj = lcl_GetDPObject( pDocShell, nTab, aNameStr ); + if (pDPObj && pDocShell) + { + ScDBDocFunc aFunc(*pDocShell); + aFunc.DataPilotUpdate( pDPObj, NULL, TRUE, TRUE ); // remove - incl. undo etc. + } + else + throw uno::RuntimeException(); // no other exceptions specified +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScDataPilotTablesObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotTablesEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScDataPilotTablesObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDPCollection* pColl = pDoc->GetDPCollection(); + if ( pColl ) + { + // count tables on this sheet + // api only handles sheet data at this time + //! allow all data sources!!! + + USHORT nFound = 0; + USHORT nCount = pColl->GetCount(); + for (USHORT i=0; i<nCount; i++) + { + ScDPObject* pDPObj = (*pColl)[i]; + if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + ++nFound; + } + return nFound; + } + } + + return 0; +} + +uno::Any SAL_CALL ScDataPilotTablesObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XDataPilotTable> xTable = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xTable.is()) + aAny <<= xTable; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScDataPilotTablesObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XDataPilotTable>*)0); +} + +sal_Bool SAL_CALL ScDataPilotTablesObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// XNameAccess + +uno::Any SAL_CALL ScDataPilotTablesObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XDataPilotTable> xTable = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xTable.is()) + aAny <<= xTable; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScDataPilotTablesObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDPCollection* pColl = pDoc->GetDPCollection(); + if ( pColl ) + { + // count tables on this sheet + // api only handles sheet data at this time + //! allow all data sources!!! + + USHORT nFound = 0; + USHORT nCount = pColl->GetCount(); + USHORT i; + for (i=0; i<nCount; i++) + { + ScDPObject* pDPObj = (*pColl)[i]; + if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + ++nFound; + } + + USHORT nPos = 0; + uno::Sequence< ::rtl::OUString> aSeq(nFound); + ::rtl::OUString* pAry = aSeq.getArray(); + for (i=0; i<nCount; i++) + { + ScDPObject* pDPObj = (*pColl)[i]; + if ( pDPObj->IsSheetData() && pDPObj->GetOutRange().aStart.Tab() == nTab ) + pAry[nPos++] = pDPObj->GetName(); + } + + return aSeq; + } + } + return uno::Sequence< ::rtl::OUString>(0); +} + +sal_Bool SAL_CALL ScDataPilotTablesObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScDPCollection* pColl = pDoc->GetDPCollection(); + if ( pColl ) + { + String aNamStr = aName; + USHORT nCount = pColl->GetCount(); + for (USHORT i=0; i<nCount; i++) + { + // api only handles sheet data at this time + //! allow all data sources!!! + + ScDPObject* pDPObj = (*pColl)[i]; + if ( pDPObj->IsSheetData() && + pDPObj->GetOutRange().aStart.Tab() == nTab && + pDPObj->GetName() == aNamStr ) + return TRUE; + } + } + } + return FALSE; +} + + +ScDataPilotDescriptorBase::ScDataPilotDescriptorBase(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDataPilotDescriptorBase::~ScDataPilotDescriptorBase() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +uno::Any SAL_CALL ScDataPilotDescriptorBase::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( sheet::XDataPilotDescriptor ) + SC_QUERYINTERFACE( container::XNamed ) // base of XDataPilotDescriptor + SC_QUERYINTERFACE( lang::XUnoTunnel ) + SC_QUERYINTERFACE( lang::XTypeProvider ) + SC_QUERYINTERFACE( lang::XServiceInfo ) + + return OWeakObject::queryInterface( rType ); +} + +void SAL_CALL ScDataPilotDescriptorBase::acquire() throw() +{ + OWeakObject::acquire(); +} + +void SAL_CALL ScDataPilotDescriptorBase::release() throw() +{ + OWeakObject::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScDataPilotDescriptorBase::getTypes() + throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + aTypes.realloc(4); + uno::Type* pPtr = aTypes.getArray(); + pPtr[0] = getCppuType((const uno::Reference<sheet::XDataPilotDescriptor>*)0); + pPtr[1] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0); + pPtr[2] = getCppuType((const uno::Reference<lang::XTypeProvider>*)0); + pPtr[3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0); + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScDataPilotDescriptorBase::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +void ScDataPilotDescriptorBase::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! Referenz-Update? + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XDataPilotDescriptor + +table::CellRangeAddress SAL_CALL ScDataPilotDescriptorBase::getSourceRange() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + GetParam( aParam, aQuery, aSrcArea ); + + table::CellRangeAddress aRet; + aRet.Sheet = aSrcArea.nTab; + aRet.StartColumn = aSrcArea.nColStart; + aRet.StartRow = aSrcArea.nRowStart; + aRet.EndColumn = aSrcArea.nColEnd; + aRet.EndRow = aSrcArea.nRowEnd; + return aRet; +} + +void SAL_CALL ScDataPilotDescriptorBase::setSourceRange( + const table::CellRangeAddress& aSourceRange ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + GetParam( aParam, aQuery, aSrcArea ); + + aSrcArea.nTab = aSourceRange.Sheet; + aSrcArea.nColStart = (USHORT)aSourceRange.StartColumn; + aSrcArea.nRowStart = (USHORT)aSourceRange.StartRow; + aSrcArea.nColEnd = (USHORT)aSourceRange.EndColumn; + aSrcArea.nRowEnd = (USHORT)aSourceRange.EndRow; + + SetParam( aParam, aQuery, aSrcArea ); +} + +uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScDataPilotDescriptorBase::getFilterDescriptor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScDataPilotFilterDescriptor( pDocShell, this ); +} + +uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getDataPilotFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScDataPilotFieldsObj( this, SC_FIELDORIENT_ALL ); +} + +uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getColumnFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScDataPilotFieldsObj( this, DATA_PILOT_COLUMN ); +} + +uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getRowFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScDataPilotFieldsObj( this, DATA_PILOT_ROW ); +} + +uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getPageFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScDataPilotFieldsObj( this, DATA_PILOT_PAGE ); +} + +uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getDataFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScDataPilotFieldsObj( this, DATA_PILOT_DATA ); +} + +uno::Reference<container::XIndexAccess> SAL_CALL ScDataPilotDescriptorBase::getHiddenFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScDataPilotFieldsObj( this, DATA_PILOT_HIDDEN ); +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScDataPilotDescriptorBase::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScDataPilotDescriptorBase::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScDataPilotDescriptorBase* ScDataPilotDescriptorBase::getImplementation( + const uno::Reference<sheet::XDataPilotDescriptor> xObj ) +{ + ScDataPilotDescriptorBase* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScDataPilotDescriptorBase*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + + +ScDataPilotTableObj::ScDataPilotTableObj(ScDocShell* pDocSh, USHORT nT, const String& rN) : + ScDataPilotDescriptorBase( pDocSh ), + nTab( nT ), + aName( rN ) +{ +} + +ScDataPilotTableObj::~ScDataPilotTableObj() +{ +} + +uno::Any SAL_CALL ScDataPilotTableObj::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( sheet::XDataPilotTable ) + + return ScDataPilotDescriptorBase::queryInterface( rType ); +} + +void SAL_CALL ScDataPilotTableObj::acquire() throw() +{ + ScDataPilotDescriptorBase::acquire(); +} + +void SAL_CALL ScDataPilotTableObj::release() throw() +{ + ScDataPilotDescriptorBase::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScDataPilotTableObj::getTypes() + throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = ScDataPilotDescriptorBase::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 1 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XDataPilotTable>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScDataPilotTableObj::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +void ScDataPilotTableObj::GetParam( ScPivotParam& rParam, ScQueryParam& rQuery, ScArea& rSrcArea ) const +{ + ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName); + if (pDPObj) + { + const ScSheetSourceDesc* pSheetDesc = pDPObj->GetSheetDesc(); + if ( pSheetDesc ) + { + // FALSE -> fields are counted within the source range + pDPObj->FillOldParam( rParam, FALSE ); + + rSrcArea = ScArea( pSheetDesc->aSourceRange.aStart.Tab(), + pSheetDesc->aSourceRange.aStart.Col(), + pSheetDesc->aSourceRange.aStart.Row(), + pSheetDesc->aSourceRange.aEnd.Col(), + pSheetDesc->aSourceRange.aEnd.Row() ); + rQuery = pSheetDesc->aQueryParam; + + // in the Uno objects all fields in descriptors are counted within the source range + // fields in ScPivotParam are correct (bForFile=FALSE in FillOldParam), + // ScQueryParam still has to be adjusted: + + short nFieldStart = rSrcArea.nColStart; + USHORT nQueryCount = rQuery.GetEntryCount(); + for ( USHORT i=0; i<nQueryCount; i++ ) + { + ScQueryEntry& rEntry = rQuery.GetEntry(i); + if (rEntry.bDoQuery && rEntry.nField >= nFieldStart) + rEntry.nField -= nFieldStart; + } + + lcl_SetLayoutNamesToParam( rParam, GetDocShell()->GetDocument(), rSrcArea, *pDPObj ); + } + } +} + +void ScDataPilotTableObj::SetParam( const ScPivotParam& rParam, + const ScQueryParam& rQuery, const ScArea& rSrcArea ) +{ + ScDocShell* pLclDocShell = GetDocShell(); + ScDPObject* pDPObj = lcl_GetDPObject(pLclDocShell, nTab, aName); + if ( pDPObj && pLclDocShell ) + { + // in den Uno-Objekten sind alle Fields in den Descriptoren innerhalb des Bereichs gezaehlt + + ScPivotParam aNewParam( rParam ); + short nFieldStart = rSrcArea.nColStart; + USHORT i; + for ( i=0; i<aNewParam.nColCount; i++ ) + if ( aNewParam.aColArr[i].nCol != PIVOT_DATA_FIELD ) + aNewParam.aColArr[i].nCol += nFieldStart; + for ( i=0; i<aNewParam.nRowCount; i++ ) + if ( aNewParam.aRowArr[i].nCol != PIVOT_DATA_FIELD ) + aNewParam.aRowArr[i].nCol += nFieldStart; + for ( i=0; i<aNewParam.nDataCount; i++ ) + if ( aNewParam.aDataArr[i].nCol != PIVOT_DATA_FIELD ) + aNewParam.aDataArr[i].nCol += nFieldStart; + + ScQueryParam aNewQuery( rQuery ); + USHORT nQueryCount = aNewQuery.GetEntryCount(); + for ( i=0; i<nQueryCount; i++ ) + { + ScQueryEntry& rEntry = aNewQuery.GetEntry(i); + if (rEntry.bDoQuery) + rEntry.nField += nFieldStart; + } + + ScDocument* pDoc = pLclDocShell->GetDocument(); + ScPivot* pNew = new ScPivot( pDoc ); + pNew->SetName( pDPObj->GetName() ); + pNew->SetTag( pDPObj->GetTag() ); + pNew->SetParam( aNewParam, aNewQuery, rSrcArea ); + + ScDPObject* pNewObj = new ScDPObject( pDoc ); + pNewObj->InitFromOldPivot( *pNew, pDoc, TRUE ); + lcl_SetLayoutNamesToObject( pDoc, aNewParam, rSrcArea, *pNewObj ); + + ScDBDocFunc aFunc(*pLclDocShell); + aFunc.DataPilotUpdate( pDPObj, pNewObj, TRUE, TRUE ); + + delete pNewObj; // DataPilotUpdate copies settings from "new" object + delete pNew; + } +} + +// "rest of XDataPilotDescriptor" + +::rtl::OUString SAL_CALL ScDataPilotTableObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName); + if (pDPObj) + return pDPObj->GetName(); + return ::rtl::OUString(); +} + +void SAL_CALL ScDataPilotTableObj::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName); + if (pDPObj) + { + //! test for existing names !!! + + String aString = aNewName; + pDPObj->SetName( aString ); //! Undo - DBDocFunc ??? + aName = aString; + + // DataPilotUpdate would do too much (output table is not changed) + GetDocShell()->SetDocumentModified(); + } +} + +::rtl::OUString SAL_CALL ScDataPilotTableObj::getTag() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName); + if (pDPObj) + return pDPObj->GetTag(); + return ::rtl::OUString(); +} + +void SAL_CALL ScDataPilotTableObj::setTag( const ::rtl::OUString& aNewTag ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName); + if (pDPObj) + { + String aString = aNewTag; + pDPObj->SetTag( aString ); //! Undo - DBDocFunc ??? + + // DataPilotUpdate would do too much (output table is not changed) + GetDocShell()->SetDocumentModified(); + } +} + +// XDataPilotTable + +table::CellRangeAddress SAL_CALL ScDataPilotTableObj::getOutputRange() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aRet; + ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName); + if (pDPObj) + { + ScRange aRange = pDPObj->GetOutRange(); + aRet.Sheet = aRange.aStart.Tab(); + aRet.StartColumn = aRange.aStart.Col(); + aRet.StartRow = aRange.aStart.Row(); + aRet.EndColumn = aRange.aEnd.Col(); + aRet.EndRow = aRange.aEnd.Row(); + } + return aRet; +} + +void SAL_CALL ScDataPilotTableObj::refresh() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDPObject* pDPObj = lcl_GetDPObject(GetDocShell(), nTab, aName); + if (pDPObj) + { + ScDPObject* pNew = new ScDPObject(*pDPObj); + ScDBDocFunc aFunc(*GetDocShell()); + aFunc.DataPilotUpdate( pDPObj, pNew, TRUE, TRUE ); + delete pNew; // DataPilotUpdate copies settings from "new" object + } +} + +ScDataPilotDescriptor::ScDataPilotDescriptor(ScDocShell* pDocSh) : + ScDataPilotDescriptorBase( pDocSh ) +{ +} + +ScDataPilotDescriptor::~ScDataPilotDescriptor() +{ +} + +void ScDataPilotDescriptor::GetParam( ScPivotParam& rParam, ScQueryParam& rQuery, + ScArea& rSrcArea ) const +{ + // Fields sind und bleiben innerhalb des Bereichs + + rParam = aParam; + rQuery = aQuery; + rSrcArea = aSrcArea; +} + +void ScDataPilotDescriptor::SetParam( const ScPivotParam& rParam, + const ScQueryParam& rQuery, const ScArea& rSrcArea ) +{ + // Fields sind und bleiben innerhalb des Bereichs + + aParam = rParam; + aQuery = rQuery; + aSrcArea = rSrcArea; +} + +// "rest of XDataPilotDescriptor" + +::rtl::OUString SAL_CALL ScDataPilotDescriptor::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aNameStr; +} + +void SAL_CALL ScDataPilotDescriptor::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aNameStr = String( aNewName ); +} + +::rtl::OUString SAL_CALL ScDataPilotDescriptor::getTag() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aTagStr; +} + +void SAL_CALL ScDataPilotDescriptor::setTag( const ::rtl::OUString& aNewTag ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aTagStr = String( aNewTag ); +} + +ScDataPilotFieldsObj::ScDataPilotFieldsObj(ScDataPilotDescriptorBase* pPar, USHORT nTy) : + pParent( pPar ), + nType( nTy ) +{ + pParent->acquire(); +} + +ScDataPilotFieldsObj::~ScDataPilotFieldsObj() +{ + pParent->release(); +} + +USHORT lcl_GetFieldCount( const ScPivotParam& rParam, const ScArea& rSrcArea, USHORT nType ) +{ + USHORT nRet = 0; + + USHORT nDataCount = lcl_DataCount(rParam); + // Daten-Feld bei Spalten oder Zeile, wenn mehr als 1 Eintrag + + USHORT i; + switch (nType) + { + case SC_FIELDORIENT_ALL: + // Anzahl Spalten im Datenbereich + // plus eins fuer das Datenfeld (immer) + nRet = rSrcArea.nColEnd - rSrcArea.nColStart + 2; + break; + case DATA_PILOT_HIDDEN: + { + //! Datenfeld auch hier? + USHORT nColCount = rSrcArea.nColEnd - rSrcArea.nColStart + 1; + for (USHORT nSrcField=0; nSrcField<nColCount; nSrcField++) + { + BOOL bUsed = FALSE; + for (i=0; i<rParam.nColCount; i++) + if ( rParam.aColArr[i].nCol == nSrcField ) bUsed = TRUE; + for (i=0; i<rParam.nRowCount; i++) + if ( rParam.aRowArr[i].nCol == nSrcField ) bUsed = TRUE; + for (i=0; i<rParam.nDataCount; i++) + if ( rParam.aDataArr[i].nCol == nSrcField ) bUsed = TRUE; + if (!bUsed) + ++nRet; + } + } + break; + case DATA_PILOT_COLUMN: + for (i=0; i<rParam.nColCount; i++) + if ( rParam.aColArr[i].nCol != PIVOT_DATA_FIELD || nDataCount > 1 ) + ++nRet; + break; + case DATA_PILOT_ROW: + for (i=0; i<rParam.nRowCount; i++) + if ( rParam.aRowArr[i].nCol != PIVOT_DATA_FIELD || nDataCount > 1 ) + ++nRet; + break; + case DATA_PILOT_PAGE: + nRet = 0; // Page-Fields sind nicht implementiert + break; + case DATA_PILOT_DATA: + nRet = nDataCount; + break; + } + + return nRet; +} + +BOOL lcl_GetFieldDataByIndex( const ScPivotParam& rParam, const ScArea& rSrcArea, + USHORT nType, USHORT nIndex, USHORT& rField ) +{ + BOOL bOk = FALSE; + USHORT nPos = 0; + + USHORT nDataCount = lcl_DataCount(rParam); + // Daten-Feld bei Spalten oder Zeile, wenn mehr als 1 Eintrag + + USHORT i; + switch (nType) + { + case SC_FIELDORIENT_ALL: + { + USHORT nSourceCount = rSrcArea.nColEnd - rSrcArea.nColStart + 1; + if ( nIndex < nSourceCount ) + { + rField = nIndex; + bOk = TRUE; + } + else if ( nIndex == nSourceCount ) + { + rField = PIVOT_DATA_FIELD; + bOk = TRUE; + } + } + break; + case DATA_PILOT_HIDDEN: + { + //! Datenfeld auch hier? + USHORT nColCount = rSrcArea.nColEnd - rSrcArea.nColStart + 1; + for (USHORT nSrcField=0; nSrcField<nColCount; nSrcField++) + { + BOOL bUsed = FALSE; + for (i=0; i<rParam.nColCount; i++) + if ( rParam.aColArr[i].nCol == nSrcField ) bUsed = TRUE; + for (i=0; i<rParam.nRowCount; i++) + if ( rParam.aRowArr[i].nCol == nSrcField ) bUsed = TRUE; + for (i=0; i<rParam.nDataCount; i++) + if ( rParam.aDataArr[i].nCol == nSrcField ) bUsed = TRUE; + if (!bUsed) + { + if ( nPos == nIndex ) + { + rField = nSrcField; + bOk = TRUE; + } + ++nPos; + } + } + } + break; + case DATA_PILOT_COLUMN: + for (i=0; i<rParam.nColCount; i++) + if ( rParam.aColArr[i].nCol != PIVOT_DATA_FIELD || nDataCount > 1 ) + { + if ( nPos == nIndex ) + { + rField = rParam.aColArr[i].nCol; + bOk = TRUE; + } + ++nPos; + } + break; + case DATA_PILOT_ROW: + for (i=0; i<rParam.nRowCount; i++) + if ( rParam.aRowArr[i].nCol != PIVOT_DATA_FIELD || nDataCount > 1 ) + { + if ( nPos == nIndex ) + { + rField = rParam.aRowArr[i].nCol; + bOk = TRUE; + } + ++nPos; + } + break; + case DATA_PILOT_PAGE: + break; // Page-Fields sind nicht implementiert + case DATA_PILOT_DATA: + { + USHORT nArrayPos, nFuncBit; + if ( lcl_GetDataArrayPos( rParam, nIndex, nArrayPos, nFuncBit ) ) + { + rField = rParam.aDataArr[nArrayPos].nCol; + bOk = TRUE; + } + } + break; + } + return bOk; +} + +String lcl_FieldName( ScDocShell* pDocSh, const ScPivotParam& rParam, + const ScArea& rSrcArea, USHORT nField ) +{ + String aRet; + if ( nField == PIVOT_DATA_FIELD ) + aRet = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Data")); //! ??? + else + { + USHORT nCol = rSrcArea.nColStart + nField; + if ( pDocSh && nCol <= rSrcArea.nColEnd ) + { + USHORT nRow = rSrcArea.nRowStart; + aRet = lcl_ColumnTitle( pDocSh->GetDocument(), nCol, nRow, rSrcArea.nTab ); + + // layout names from SaveData are in PivotParam LabelData + + if ( nField < rParam.nLabels && rParam.ppLabelArr && + rParam.ppLabelArr[nField] && + rParam.ppLabelArr[nField]->pStrColName && + rParam.ppLabelArr[nField]->pStrColName->Len() ) + aRet = *rParam.ppLabelArr[nField]->pStrColName; + } + } + return aRet; +} + +void lcl_SetFieldName( ScPivotParam& rParam, USHORT nField, const String& rNewName ) +{ + USHORT nNewCount = Max( rParam.nLabels, (USHORT)( nField + 1 ) ); + USHORT i; + + LabelData** ppNewData = new LabelData*[nNewCount]; + for (i=0; i<nNewCount; i++) + { + if ( i == nField ) + ppNewData[i] = new LabelData( rNewName, 0, FALSE ); + else if ( i < rParam.nLabels && rParam.ppLabelArr && rParam.ppLabelArr[i] ) + ppNewData[i] = new LabelData( *rParam.ppLabelArr[i] ); + else + ppNewData[i] = new LabelData( EMPTY_STRING, 0, FALSE ); + } + + rParam.SetLabelData( ppNewData, nNewCount ); + + // SetLabelData copies data - ppNewData must be deleted + for (i=0; i<nNewCount; i++) + delete ppNewData[i]; + delete[] ppNewData; +} + +// XDataPilotFields + +ScDataPilotFieldObj* ScDataPilotFieldsObj::GetObjectByIndex_Impl(USHORT nIndex) const +{ + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + USHORT nField = 0; + BOOL bOk = lcl_GetFieldDataByIndex( aParam, aSrcArea, nType, nIndex, nField ); + + if (bOk) + return new ScDataPilotFieldObj( pParent, nField, nType, nIndex ); + + return NULL; +} + +ScDataPilotFieldObj* ScDataPilotFieldsObj::GetObjectByName_Impl(const ::rtl::OUString& aName) const +{ + String aNameStr = aName; + + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + ScDocShell* pDocSh = pParent->GetDocShell(); + USHORT nCount = lcl_GetFieldCount( aParam, aSrcArea, nType ); + USHORT nField = 0; + for (USHORT i=0; i<nCount; i++) + { + if (lcl_GetFieldDataByIndex( aParam, aSrcArea, nType, i, nField )) + { + if ( aNameStr == lcl_FieldName( pDocSh, aParam, aSrcArea, nField ) ) + return new ScDataPilotFieldObj( pParent, nField, nType, i ); + } + } + return NULL; +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScDataPilotFieldsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DataPilotFieldsEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScDataPilotFieldsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + return lcl_GetFieldCount( aParam, aSrcArea, nType ); +} + +uno::Any SAL_CALL ScDataPilotFieldsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<beans::XPropertySet> xField = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xField.is()) + aAny <<= xField; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScDataPilotFieldsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<beans::XPropertySet>*)0); +} + +sal_Bool SAL_CALL ScDataPilotFieldsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Any SAL_CALL ScDataPilotFieldsObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<beans::XPropertySet> xField = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xField.is()) + aAny <<= xField; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScDataPilotFieldsObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + ScDocShell* pDocSh = pParent->GetDocShell(); + USHORT nCount = lcl_GetFieldCount( aParam, aSrcArea, nType ); + USHORT nField = 0; + + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + lcl_GetFieldDataByIndex( aParam, aSrcArea, nType, i, nField ); + String aName = lcl_FieldName( pDocSh, aParam, aSrcArea, nField ); + pAry[i] = aName; + } + return aSeq; +} + +sal_Bool SAL_CALL ScDataPilotFieldsObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr = aName; + + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + ScDocShell* pDocSh = pParent->GetDocShell(); + USHORT nCount = lcl_GetFieldCount( aParam, aSrcArea, nType ); + USHORT nField = 0; + for (USHORT i=0; i<nCount; i++) + { + if (lcl_GetFieldDataByIndex( aParam, aSrcArea, nType, i, nField )) + { + if ( aNameStr == lcl_FieldName( pDocSh, aParam, aSrcArea, nField ) ) + return TRUE; + } + } + return FALSE; +} + +ScDataPilotFieldObj::ScDataPilotFieldObj( ScDataPilotDescriptorBase* pPar, + USHORT nF, USHORT nST, USHORT nSP ) : + aPropSet( lcl_GetDataPilotFieldMap() ), + pParent( pPar ), + nField( nF ), + nSourceType( nST ), + nSourcePos( nSP ), + nLastFunc( sheet::GeneralFunction_NONE ) +{ + pParent->acquire(); +} + +ScDataPilotFieldObj::~ScDataPilotFieldObj() +{ + pParent->release(); +} + +// XNamed + +::rtl::OUString SAL_CALL ScDataPilotFieldObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + String aRet = lcl_FieldName( pParent->GetDocShell(), aParam, aSrcArea, nField ); + + return aRet; +} + +void SAL_CALL ScDataPilotFieldObj::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + if ( nField == PIVOT_DATA_FIELD ) + { + //! ... ??? + } + else + lcl_SetFieldName( aParam, nField, aNewName ); + + pParent->SetParam( aParam, aQuery, aSrcArea ); +} + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDataPilotFieldObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScDataPilotFieldObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + if ( aNameString.EqualsAscii( SC_UNONAME_FUNCTION ) ) + { + //! test for correct enum type? + sheet::GeneralFunction eFunction = (sheet::GeneralFunction) + ScUnoHelpFunctions::GetEnumFromAny( aValue ); + setFunction( eFunction ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_ORIENT ) ) + { + //! test for correct enum type? + sheet::DataPilotFieldOrientation eOrient = (sheet::DataPilotFieldOrientation) + ScUnoHelpFunctions::GetEnumFromAny( aValue ); + setOrientation( eOrient ); + } +} + +uno::Any SAL_CALL ScDataPilotFieldObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + uno::Any aRet; + + if ( aNameString.EqualsAscii( SC_UNONAME_FUNCTION ) ) + { + sheet::GeneralFunction eFunction = getFunction(); + aRet <<= eFunction; + } + else if ( aNameString.EqualsAscii( SC_UNONAME_ORIENT ) ) + { + sheet::DataPilotFieldOrientation eOrient = getOrientation(); + aRet <<= eOrient; + } + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDataPilotFieldObj ) + +void lcl_FindUsage( const ScPivotParam& rParam, USHORT nField, USHORT& rType, USHORT& rPos ) +{ + USHORT i; + for (i=0; i<rParam.nColCount; i++) + if ( rParam.aColArr[i].nCol == nField ) + { + rType = DATA_PILOT_COLUMN; + rPos = i; + return; + } + for (i=0; i<rParam.nRowCount; i++) + if ( rParam.aRowArr[i].nCol == nField ) + { + rType = DATA_PILOT_ROW; + rPos = i; + return; + } + USHORT nBitCount = 0; + for (i=0; i<rParam.nDataCount; i++) + { + if ( rParam.aDataArr[i].nCol == nField ) + { + rType = DATA_PILOT_DATA; + rPos = nBitCount; // Uno-Index der ersten Funktion + return; + } + nBitCount += lcl_BitCount( rParam.aDataArr[i].nFuncMask ); + } + //! DATA_PILOT_HIDDEN zurueck - Position suchen +} + +sheet::DataPilotFieldOrientation ScDataPilotFieldObj::getOrientation(void) const +{ + SolarMutexGuard aGuard; + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + USHORT nType = nSourceType; + USHORT nPos = nSourcePos; + if ( nType == SC_FIELDORIENT_ALL ) + lcl_FindUsage( aParam, nField, nType, nPos ); + + if ( nType == SC_FIELDORIENT_ALL ) // bei FindUsage nicht gefunden + nType = DATA_PILOT_HIDDEN; // nicht verwendet + + return (sheet::DataPilotFieldOrientation)nType; +} + +void lcl_RemoveField( PivotField* pFields, USHORT& rCount, USHORT nField ) +{ + for (USHORT i=0; i<rCount; i++) + if (pFields[i].nCol == nField) + { + for (USHORT j=i; j+1<rCount; j++) + pFields[j] = pFields[j+1]; + --rCount; + return; // nicht weitersuchen + } +} + +void ScDataPilotFieldObj::setOrientation(sheet::DataPilotFieldOrientation eNew) +{ + SolarMutexGuard aGuard; + if ( eNew == nSourceType ) + return; // nix + + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + // aus altem Array entfernen + + switch (nSourceType) + { + case DATA_PILOT_COLUMN: + if ( nSourcePos < aParam.nColCount ) + { + for (USHORT i=nSourcePos; i+1<aParam.nColCount; i++) + aParam.aColArr[i] = aParam.aColArr[i+1]; + --aParam.nColCount; + } + break; + case DATA_PILOT_ROW: + if ( nSourcePos < aParam.nRowCount ) + { + for (USHORT i=nSourcePos; i+1<aParam.nRowCount; i++) + aParam.aRowArr[i] = aParam.aRowArr[i+1]; + --aParam.nRowCount; + } + break; + case DATA_PILOT_DATA: + { + USHORT nArrayPos, nFuncBit; + if ( lcl_GetDataArrayPos( aParam, nSourcePos, nArrayPos, nFuncBit ) ) + { + aParam.aDataArr[nArrayPos].nFuncMask &= ~nFuncBit; // Funktion weglassen + if (!aParam.aDataArr[nArrayPos].nFuncMask) // war's die letzte? + { + for (USHORT j=nArrayPos; j+1<aParam.nDataCount; j++) + aParam.aDataArr[j] = aParam.aDataArr[j+1]; + --aParam.nDataCount; + } + } + } + break; + + // SC_FIELDORIENT_ALL, DATA_PILOT_HIDDEN: nichts + } + + // if Function was set for this object, use that value; + // default otherwise (0 for SubTotals, SUM for data) + USHORT nNewBit = ScDataPilotConversion::FunctionBit( (sheet::GeneralFunction)nLastFunc ); + + // in neues Array eintragen + + switch (eNew) + { + case DATA_PILOT_COLUMN: + if ( aParam.nColCount < PIVOT_MAXFIELD ) + { + lcl_RemoveField( aParam.aColArr, aParam.nColCount, nField ); // nicht doppelt + lcl_RemoveField( aParam.aRowArr, aParam.nRowCount, nField ); + aParam.aColArr[aParam.nColCount].nCol = nField; + aParam.aColArr[aParam.nColCount].nFuncMask = nNewBit; + nSourceType = DATA_PILOT_COLUMN; + nSourcePos = aParam.nColCount; + ++aParam.nColCount; + } + break; + case DATA_PILOT_ROW: + if ( aParam.nRowCount < PIVOT_MAXFIELD ) + { + lcl_RemoveField( aParam.aColArr, aParam.nColCount, nField ); // nicht doppelt + lcl_RemoveField( aParam.aRowArr, aParam.nRowCount, nField ); + aParam.aRowArr[aParam.nRowCount].nCol = nField; + aParam.aRowArr[aParam.nRowCount].nFuncMask = nNewBit; + nSourceType = DATA_PILOT_ROW; + nSourcePos = aParam.nRowCount; + ++aParam.nRowCount; + } + break; + case DATA_PILOT_DATA: + if ( aParam.nDataCount < PIVOT_MAXFIELD ) + { + //! ggf. mit bestehendem Eintrag zusammenfassen (Funktionen verodern) ??? + aParam.aDataArr[aParam.nDataCount].nCol = nField; + if ( nNewBit == 0 ) + nNewBit = PIVOT_FUNC_SUM; + aParam.aDataArr[aParam.nDataCount].nFuncMask = nNewBit; + nSourceType = DATA_PILOT_DATA; + nSourcePos = aParam.nDataCount; + ++aParam.nDataCount; + } + break; + default: // PAGE or HIDDEN + nSourceType = eNew; + nSourcePos = 0; + break; + } + + pParent->SetParam( aParam, aQuery, aSrcArea ); +} + +sheet::GeneralFunction ScDataPilotFieldObj::getFunction(void) const +{ + SolarMutexGuard aGuard; + sheet::GeneralFunction eRet = sheet::GeneralFunction_NONE; + + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + USHORT nType = nSourceType; + USHORT nPos = nSourcePos; + if ( nType == SC_FIELDORIENT_ALL ) + lcl_FindUsage( aParam, nField, nType, nPos ); + + switch ( nType ) + { + case DATA_PILOT_COLUMN: + if ( nPos < aParam.nColCount ) + eRet = ScDataPilotConversion::FirstFunc( aParam.aColArr[nPos].nFuncMask ); + break; + case DATA_PILOT_ROW: + if ( nPos < aParam.nRowCount ) + eRet = ScDataPilotConversion::FirstFunc( aParam.aRowArr[nPos].nFuncMask ); + break; + case DATA_PILOT_DATA: // Bits zaehlen... + { + USHORT nArrayPos, nFuncBit; + if ( lcl_GetDataArrayPos( aParam, nPos, nArrayPos, nFuncBit ) ) + eRet = ScDataPilotConversion::FirstFunc( nFuncBit ); + } + break; + default: + // if Function has been set for this object, return that value + eRet = (sheet::GeneralFunction) nLastFunc; + } + return eRet; +} + +void ScDataPilotFieldObj::setFunction(sheet::GeneralFunction eNewFunc) +{ + SolarMutexGuard aGuard; + ScPivotParam aParam; + ScQueryParam aQuery; + ScArea aSrcArea; + pParent->GetParam( aParam, aQuery, aSrcArea ); + + USHORT nType = nSourceType; + USHORT nPos = nSourcePos; + if ( nType == SC_FIELDORIENT_ALL ) + lcl_FindUsage( aParam, nField, nType, nPos ); + + switch ( nType ) + { + case DATA_PILOT_COLUMN: + if ( nPos < aParam.nColCount ) + aParam.aColArr[nPos].nFuncMask = ScDataPilotConversion::FunctionBit(eNewFunc); + break; + case DATA_PILOT_ROW: + if ( nPos < aParam.nRowCount ) + aParam.aRowArr[nPos].nFuncMask = ScDataPilotConversion::FunctionBit(eNewFunc); + break; + case DATA_PILOT_DATA: // Bits zaehlen... + { + USHORT nArrayPos, nFuncBit; + if ( lcl_GetDataArrayPos( aParam, nPos, nArrayPos, nFuncBit ) ) + { + // alte Funktion weglassen, neue eintragen + aParam.aDataArr[nArrayPos].nFuncMask &= ~nFuncBit; + aParam.aDataArr[nArrayPos].nFuncMask |= ScDataPilotConversion::FunctionBit(eNewFunc); + } + } + break; + } + + pParent->SetParam( aParam, aQuery, aSrcArea ); + + nLastFunc = eNewFunc; // to allow setting Function before Orientation +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_datauno.cxx b/bf_sc/source/ui/unoobj/sc_datauno.cxx new file mode 100644 index 000000000..e50161f45 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_datauno.cxx @@ -0,0 +1,2043 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <bf_svtools/zforlist.hxx> +#include <rtl/uuid.h> + +#include <com/sun/star/awt/XBitmap.hpp> +#include <com/sun/star/util/SortField.hpp> +#include <com/sun/star/table/TableSortField.hpp> +#include <com/sun/star/sheet/DataImportMode.hpp> + +#include "datauno.hxx" +#include "dapiuno.hxx" +#include "cellsuno.hxx" +#include "miscuno.hxx" +#include "dbcolect.hxx" +#include "docsh.hxx" +#include "dbdocfun.hxx" +#include <vcl/svapp.hxx> +#include "unonames.hxx" +#include "globstr.hrc" +#include "convuno.hxx" +#include "attrib.hxx" +#include <comphelper/extract.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + + +// alles ohne Which-ID, Map nur fuer PropertySetInfo + +const SfxItemPropertyMap* lcl_GetSubTotalPropertyMap() +{ + // some old property names are for 5.2 compatibility + + static SfxItemPropertyMap aSubTotalPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_BINDFMT), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_CASE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ENABSORT), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ENUSLIST), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_FORMATS), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_INSBRK), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ISCASE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_MAXFLD), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY,0}, + {MAP_CHAR_LEN(SC_UNONAME_SORTASC), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ULIST), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_UINDEX), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_USINDEX), 0, &getCppuType((sal_Int32*)0), 0,0}, + {0,0,0,0,0,0} + }; + return aSubTotalPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetFilterPropertyMap() +{ + static SfxItemPropertyMap aFilterPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_CONTHDR), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_COPYOUT), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ISCASE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_MAXFLD), 0, &getCppuType((sal_Int32*)0), beans::PropertyAttribute::READONLY,0}, + {MAP_CHAR_LEN(SC_UNONAME_ORIENT), 0, &getCppuType((table::TableOrientation*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_OUTPOS), 0, &getCppuType((table::CellAddress*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_SAVEOUT), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_SKIPDUP), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_USEREGEX), 0, &getBooleanCppuType(), 0,0}, + {0,0,0,0,0,0} + }; + return aFilterPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetDBRangePropertyMap() +{ + static SfxItemPropertyMap aDBRangePropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_AUTOFLT), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_FLTCRT), 0, &getCppuType((table::CellRangeAddress*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ISUSER), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_KEEPFORM), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), 0, &getCppuType((uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0, &getCppuType((::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_MOVCELLS), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_STRIPDAT), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_USEFLTCRT),0, &getBooleanCppuType(), 0,0}, + {0,0,0,0,0,0} + }; + return aDBRangePropertyMap_Impl; +} + + + +#define SCDATABASERANGEOBJ_SERVICE "com.sun.star.sheet.DatabaseRange" + +SC_SIMPLE_SERVICE_INFO( ScConsolidationDescriptor, "ScConsolidationDescriptor", "com.sun.star.sheet.ConsolidationDescriptor" ) +SC_SIMPLE_SERVICE_INFO( ScDatabaseRangesObj, "ScDatabaseRangesObj", "com.sun.star.sheet.DatabaseRanges" ) +SC_SIMPLE_SERVICE_INFO( ScFilterDescriptorBase, "ScFilterDescriptorBase", "com.sun.star.sheet.SheetFilterDescriptor" ) +SC_SIMPLE_SERVICE_INFO( ScSubTotalDescriptorBase, "ScSubTotalDescriptorBase", "com.sun.star.sheet.SubTotalDescriptor" ) +SC_SIMPLE_SERVICE_INFO( ScSubTotalFieldObj, "ScSubTotalFieldObj", "com.sun.star.sheet.SubTotalField" ) + + + +// static +ScSubTotalFunc ScDataUnoConversion::GeneralToSubTotal( sheet::GeneralFunction eSummary ) +{ + ScSubTotalFunc eSubTotal; + switch (eSummary) + { + case sheet::GeneralFunction_NONE: eSubTotal = SUBTOTAL_FUNC_NONE; break; + case sheet::GeneralFunction_SUM: eSubTotal = SUBTOTAL_FUNC_SUM; break; + case sheet::GeneralFunction_COUNT: eSubTotal = SUBTOTAL_FUNC_CNT2; break; + case sheet::GeneralFunction_AVERAGE: eSubTotal = SUBTOTAL_FUNC_AVE; break; + case sheet::GeneralFunction_MAX: eSubTotal = SUBTOTAL_FUNC_MAX; break; + case sheet::GeneralFunction_MIN: eSubTotal = SUBTOTAL_FUNC_MIN; break; + case sheet::GeneralFunction_PRODUCT: eSubTotal = SUBTOTAL_FUNC_PROD; break; + case sheet::GeneralFunction_COUNTNUMS: eSubTotal = SUBTOTAL_FUNC_CNT; break; + case sheet::GeneralFunction_STDEV: eSubTotal = SUBTOTAL_FUNC_STD; break; + case sheet::GeneralFunction_STDEVP: eSubTotal = SUBTOTAL_FUNC_STDP; break; + case sheet::GeneralFunction_VAR: eSubTotal = SUBTOTAL_FUNC_VAR; break; + case sheet::GeneralFunction_VARP: eSubTotal = SUBTOTAL_FUNC_VARP; break; + case sheet::GeneralFunction_AUTO: + default: + OSL_FAIL("GeneralToSubTotal: falscher enum"); + eSubTotal = SUBTOTAL_FUNC_NONE; + } + return eSubTotal; +} + +// static +sheet::GeneralFunction ScDataUnoConversion::SubTotalToGeneral( ScSubTotalFunc eSubTotal ) +{ + sheet::GeneralFunction eGeneral; + switch (eSubTotal) + { + case SUBTOTAL_FUNC_NONE: eGeneral = sheet::GeneralFunction_NONE; break; + case SUBTOTAL_FUNC_AVE: eGeneral = sheet::GeneralFunction_AVERAGE; break; + case SUBTOTAL_FUNC_CNT: eGeneral = sheet::GeneralFunction_COUNTNUMS; break; + case SUBTOTAL_FUNC_CNT2: eGeneral = sheet::GeneralFunction_COUNT; break; + case SUBTOTAL_FUNC_MAX: eGeneral = sheet::GeneralFunction_MAX; break; + case SUBTOTAL_FUNC_MIN: eGeneral = sheet::GeneralFunction_MIN; break; + case SUBTOTAL_FUNC_PROD: eGeneral = sheet::GeneralFunction_PRODUCT; break; + case SUBTOTAL_FUNC_STD: eGeneral = sheet::GeneralFunction_STDEV; break; + case SUBTOTAL_FUNC_STDP: eGeneral = sheet::GeneralFunction_STDEVP; break; + case SUBTOTAL_FUNC_SUM: eGeneral = sheet::GeneralFunction_SUM; break; + case SUBTOTAL_FUNC_VAR: eGeneral = sheet::GeneralFunction_VAR; break; + case SUBTOTAL_FUNC_VARP: eGeneral = sheet::GeneralFunction_VARP; break; + default: + OSL_FAIL("SubTotalToGeneral: falscher enum"); + eGeneral = sheet::GeneralFunction_NONE; + break; + } + return eGeneral; +} + + +// ScImportDescriptor: alles static + +long ScImportDescriptor::GetPropertyCount() +{ + return 4; +} + +void ScImportDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScImportParam& rParam ) +{ + DBG_ASSERT( rSeq.getLength() == GetPropertyCount(), "falscher Count" ); + + beans::PropertyValue* pArray = rSeq.getArray(); + + sheet::DataImportMode eMode = sheet::DataImportMode_NONE; + if ( rParam.bImport ) + { + if ( rParam.bSql ) + eMode = sheet::DataImportMode_SQL; + else if ( rParam.nType == ScDbQuery ) + eMode = sheet::DataImportMode_QUERY; + else + eMode = sheet::DataImportMode_TABLE; // Type ist immer ScDbQuery oder ScDbTable + } + + pArray[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_DBNAME )); + pArray[0].Value <<= ::rtl::OUString( rParam.aDBName ); + + pArray[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SRCTYPE )); + pArray[1].Value <<= eMode; + + pArray[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SRCOBJ )); + pArray[2].Value <<= ::rtl::OUString( rParam.aStatement ); + + pArray[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_NATIVE )); + ScUnoHelpFunctions::SetBoolInAny( pArray[3].Value, rParam.bNative ); +} + +void ScImportDescriptor::FillImportParam( ScImportParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq ) +{ + ::rtl::OUString aStrVal; + const beans::PropertyValue* pPropArray = rSeq.getConstArray(); + long nPropCount = rSeq.getLength(); + for (long i = 0; i < nPropCount; i++) + { + const beans::PropertyValue& rProp = pPropArray[i]; + String aPropName = rProp.Name; + + if (aPropName.EqualsAscii( SC_UNONAME_NATIVE )) + rParam.bNative = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_DBNAME )) + { + if ( rProp.Value >>= aStrVal ) + rParam.aDBName = String( aStrVal ); + } + else if (aPropName.EqualsAscii( SC_UNONAME_SRCOBJ )) + { + if ( rProp.Value >>= aStrVal ) + rParam.aStatement = String( aStrVal ); + } + else if (aPropName.EqualsAscii( SC_UNONAME_SRCTYPE )) + { + //! test for correct enum type? + sheet::DataImportMode eMode = (sheet::DataImportMode) + ScUnoHelpFunctions::GetEnumFromAny( rProp.Value ); + switch (eMode) + { + case sheet::DataImportMode_NONE: + rParam.bImport = FALSE; + break; + case sheet::DataImportMode_SQL: + rParam.bImport = TRUE; + rParam.bSql = TRUE; + break; + case sheet::DataImportMode_TABLE: + rParam.bImport = TRUE; + rParam.bSql = FALSE; + rParam.nType = ScDbTable; + break; + case sheet::DataImportMode_QUERY: + rParam.bImport = TRUE; + rParam.bSql = FALSE; + rParam.nType = ScDbQuery; + break; + default: + OSL_FAIL("falscher Mode"); + rParam.bImport = FALSE; + } + } + } +} + +//------------------------------------------------------------------------ + +// ScSortDescriptor: alles static + +//! SortAscending muss aus der SheetSortDescriptor service-Beschreibung raus + +long ScSortDescriptor::GetPropertyCount() +{ + return 9; // TableSortDescriptor and SheetSortDescriptor +} + +void ScSortDescriptor::FillProperties( uno::Sequence<beans::PropertyValue>& rSeq, const ScSortParam& rParam ) +{ + DBG_ASSERT( rSeq.getLength() == GetPropertyCount(), "falscher Count" ); + + beans::PropertyValue* pArray = rSeq.getArray(); + + // Uno-Werte zusammensuchen + + table::CellAddress aOutPos; + aOutPos.Sheet = rParam.nDestTab; + aOutPos.Column = rParam.nDestCol; + aOutPos.Row = rParam.nDestRow; + + USHORT nSortCount = 0; + while ( nSortCount < MAXSORT && rParam.bDoSort[nSortCount] ) + ++nSortCount; + + uno::Sequence<table::TableSortField> aFields(nSortCount); + if (nSortCount) + { + table::TableSortField* pFieldArray = aFields.getArray(); + for (USHORT i=0; i<nSortCount; i++) + { + pFieldArray[i].Field = rParam.nField[i]; + pFieldArray[i].IsAscending = rParam.bAscending[i]; + pFieldArray[i].FieldType = table::TableSortFieldType_AUTOMATIC; // immer Automatic + pFieldArray[i].IsCaseSensitive = rParam.bCaseSens; + pFieldArray[i].CollatorLocale = rParam.aCollatorLocale; + pFieldArray[i].CollatorAlgorithm = ::rtl::OUString( rParam.aCollatorAlgorithm ); + } + } + + // Sequence fuellen + + pArray[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ISSORTCOLUMNS )); + pArray[0].Value = ::cppu::bool2any(!rParam.bByRow); + + pArray[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_CONTHDR )); + ScUnoHelpFunctions::SetBoolInAny( pArray[1].Value, rParam.bHasHeader ); + + pArray[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_MAXFLD )); + pArray[2].Value <<= (sal_Int32) MAXSORT; + + pArray[3].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_SORTFLD )); + pArray[3].Value <<= aFields; + + pArray[4].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_BINDFMT )); + ScUnoHelpFunctions::SetBoolInAny( pArray[4].Value, rParam.bIncludePattern ); + + pArray[5].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_COPYOUT )); + ScUnoHelpFunctions::SetBoolInAny( pArray[5].Value, !rParam.bInplace ); + + pArray[6].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OUTPOS )); + pArray[6].Value <<= aOutPos; + + pArray[7].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_ISULIST )); + ScUnoHelpFunctions::SetBoolInAny( pArray[7].Value, rParam.bUserDef ); + + pArray[8].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_UINDEX )); + pArray[8].Value <<= (sal_Int32) rParam.nUserIndex; +} + +void ScSortDescriptor::FillSortParam( ScSortParam& rParam, const uno::Sequence<beans::PropertyValue>& rSeq ) +{ + const beans::PropertyValue* pPropArray = rSeq.getConstArray(); + long nPropCount = rSeq.getLength(); + for (long i = 0; i < nPropCount; i++) + { + const beans::PropertyValue& rProp = pPropArray[i]; + String aPropName = rProp.Name; + + if (aPropName.EqualsAscii( SC_UNONAME_ORIENT )) + { + //! test for correct enum type? + table::TableOrientation eOrient = (table::TableOrientation) + ScUnoHelpFunctions::GetEnumFromAny( rProp.Value ); + rParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS ); + } + else if (aPropName.EqualsAscii( SC_UNONAME_ISSORTCOLUMNS )) + rParam.bByRow = !::cppu::any2bool(rProp.Value); + else if (aPropName.EqualsAscii( SC_UNONAME_CONTHDR )) + rParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_MAXFLD )) + { + sal_Int32 nVal; + if ( (rProp.Value >>= nVal) && nVal > MAXSORT ) + { + //! specify exceptions + //! throw lang::IllegalArgumentException(); + } + } + else if (aPropName.EqualsAscii( SC_UNONAME_SORTFLD )) + { + uno::Sequence<util::SortField> aSeq; + uno::Sequence<table::TableSortField> aNewSeq; + if ( rProp.Value >>= aSeq ) + { + INT32 nCount = aSeq.getLength(); + INT32 k; + if ( nCount > MAXSORT ) + { + OSL_FAIL("Zu viele Sortierfelder"); + nCount = MAXSORT; + } + const util::SortField* pFieldArray = aSeq.getConstArray(); + for (k=0; k<nCount; k++) + { + rParam.nField[k] = (USHORT)pFieldArray[k].Field; + rParam.bAscending[k] = pFieldArray[k].SortAscending; + + // FieldType wird ignoriert + rParam.bDoSort[k] = TRUE; + } + for (k=nCount; k<MAXSORT; k++) + rParam.bDoSort[k] = FALSE; + } + else if ( rProp.Value >>= aNewSeq ) + { + INT32 nCount = aNewSeq.getLength(); + INT32 k; + if ( nCount > MAXSORT ) + { + OSL_FAIL("Zu viele Sortierfelder"); + nCount = MAXSORT; + } + const table::TableSortField* pFieldArray = aNewSeq.getConstArray(); + for (k=0; k<nCount; k++) + { + rParam.nField[k] = (USHORT)pFieldArray[k].Field; + rParam.bAscending[k] = pFieldArray[k].IsAscending; + + // only one is possible, sometime we should make it possible to have different for every entry + rParam.bCaseSens = pFieldArray[k].IsCaseSensitive; + rParam.aCollatorLocale = pFieldArray[k].CollatorLocale; + rParam.aCollatorAlgorithm = pFieldArray[k].CollatorAlgorithm; + + // FieldType wird ignoriert + rParam.bDoSort[k] = TRUE; + } + for (k=nCount; k<MAXSORT; k++) + rParam.bDoSort[k] = FALSE; + } + } + else if (aPropName.EqualsAscii( SC_UNONAME_ISCASE )) + rParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_BINDFMT )) + rParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_COPYOUT )) + rParam.bInplace = !ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_OUTPOS )) + { + table::CellAddress aAddress; + if ( rProp.Value >>= aAddress ) + { + rParam.nDestTab = aAddress.Sheet; + rParam.nDestCol = (USHORT)aAddress.Column; + rParam.nDestRow = (USHORT)aAddress.Row; + } + } + else if (aPropName.EqualsAscii( SC_UNONAME_ISULIST )) + rParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_UINDEX )) + { + sal_Int32 nVal = 0; + if ( rProp.Value >>= nVal ) + rParam.nUserIndex = (USHORT)nVal; + } + else if (aPropName.EqualsAscii( SC_UNONAME_COLLLOC )) + rProp.Value >>= rParam.aCollatorLocale; + else if (aPropName.EqualsAscii( SC_UNONAME_COLLALG )) + { + ::rtl::OUString sStr; + if ( rProp.Value >>= sStr ) + rParam.aCollatorAlgorithm = sStr; + } + } +} + + +ScSubTotalFieldObj::ScSubTotalFieldObj( ScSubTotalDescriptorBase* pDesc, USHORT nP ) : + xRef( pDesc ), // Objekt festhalten + rParent( *pDesc ), + nPos( nP ) +{ + DBG_ASSERT(pDesc, "ScSubTotalFieldObj: Parent ist 0"); +} + +ScSubTotalFieldObj::~ScSubTotalFieldObj() +{ +} + +// XSubTotalField + +sal_Int32 SAL_CALL ScSubTotalFieldObj::getGroupColumn() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + rParent.GetData(aParam); + + return aParam.nField[nPos]; +} + +void SAL_CALL ScSubTotalFieldObj::setGroupColumn( sal_Int32 nGroupColumn ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + rParent.GetData(aParam); + + aParam.nField[nPos] = (USHORT)nGroupColumn; + + rParent.PutData(aParam); +} + +uno::Sequence<sheet::SubTotalColumn> SAL_CALL ScSubTotalFieldObj::getSubTotalColumns() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + rParent.GetData(aParam); + + USHORT nCount = aParam.nSubTotals[nPos]; + uno::Sequence<sheet::SubTotalColumn> aSeq(nCount); + sheet::SubTotalColumn* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + pAry[i].Column = aParam.pSubTotals[nPos][i]; + pAry[i].Function = ScDataUnoConversion::SubTotalToGeneral( + aParam.pFunctions[nPos][i] ); + } + return aSeq; +} + +void SAL_CALL ScSubTotalFieldObj::setSubTotalColumns( + const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + rParent.GetData(aParam); + + UINT32 nColCount = aSubTotalColumns.getLength(); + if ( nColCount <= USHRT_MAX ) + { + USHORT nCount = (USHORT)nColCount; + aParam.nSubTotals[nPos] = nCount; + if (nCount) + { + aParam.pSubTotals[nPos] = new USHORT[nCount]; + aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount]; + + const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray(); + for (USHORT i=0; i<nCount; i++) + { + aParam.pSubTotals[nPos][i] = (USHORT)pAry[i].Column; + aParam.pFunctions[nPos][i] = + ScDataUnoConversion::GeneralToSubTotal( pAry[i].Function ); + } + } + else + { + aParam.pSubTotals[nPos] = NULL; + aParam.pFunctions[nPos] = NULL; + } + } + //! sonst Exception oder so? (zuviele Spalten) + + rParent.PutData(aParam); +} + + +ScSubTotalDescriptorBase::ScSubTotalDescriptorBase() : + aPropSet( lcl_GetSubTotalPropertyMap() ) +{ +} + +ScSubTotalDescriptorBase::~ScSubTotalDescriptorBase() +{ +} + +// XSubTotalDesctiptor + +ScSubTotalFieldObj* ScSubTotalDescriptorBase::GetObjectByIndex_Impl(USHORT nIndex) +{ + if ( nIndex < getCount() ) + return new ScSubTotalFieldObj( this, nIndex ); + return NULL; +} + +void SAL_CALL ScSubTotalDescriptorBase::clear() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + GetData(aParam); + + for (USHORT i=0; i<MAXSUBTOTAL; i++) + aParam.bGroupActive[i] = FALSE; + + //! Notify oder so fuer die Field-Objekte??? + + PutData(aParam); +} + +void SAL_CALL ScSubTotalDescriptorBase::addNew( + const uno::Sequence<sheet::SubTotalColumn>& aSubTotalColumns, + sal_Int32 nGroupColumn ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + GetData(aParam); + + USHORT nPos = 0; + while ( nPos < MAXSUBTOTAL && aParam.bGroupActive[nPos] ) + ++nPos; + + UINT32 nColCount = aSubTotalColumns.getLength(); + + if ( nPos < MAXSUBTOTAL && nColCount <= USHRT_MAX ) + { + aParam.bGroupActive[nPos] = TRUE; + aParam.nField[nPos] = (USHORT)nGroupColumn; + + delete aParam.pSubTotals[nPos]; + delete aParam.pFunctions[nPos]; + + USHORT nCount = (USHORT)nColCount; + aParam.nSubTotals[nPos] = nCount; + if (nCount) + { + aParam.pSubTotals[nPos] = new USHORT[nCount]; + aParam.pFunctions[nPos] = new ScSubTotalFunc[nCount]; + + const sheet::SubTotalColumn* pAry = aSubTotalColumns.getConstArray(); + for (USHORT i=0; i<nCount; i++) + { + aParam.pSubTotals[nPos][i] = (USHORT)pAry[i].Column; + aParam.pFunctions[nPos][i] = + ScDataUnoConversion::GeneralToSubTotal( pAry[i].Function ); + } + } + else + { + aParam.pSubTotals[nPos] = NULL; + aParam.pFunctions[nPos] = NULL; + } + } + else // too many fields / columns + throw uno::RuntimeException(); // no other exceptions specified + + PutData(aParam); +} + +// Flags/Einstellungen als Properties + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScSubTotalDescriptorBase::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SubTotalFieldsEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScSubTotalDescriptorBase::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + GetData(aParam); + + USHORT nCount = 0; + while ( nCount < MAXSUBTOTAL && aParam.bGroupActive[nCount] ) + ++nCount; + return nCount; +} + +uno::Any SAL_CALL ScSubTotalDescriptorBase::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XSubTotalField> xField = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xField.is()) + aAny <<= xField; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScSubTotalDescriptorBase::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XSubTotalField>*)0); +} + +sal_Bool SAL_CALL ScSubTotalDescriptorBase::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSubTotalDescriptorBase::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScSubTotalDescriptorBase::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + GetData(aParam); + + String aString = aPropertyName; + + // some old property names are for 5.2 compatibility + + if (aString.EqualsAscii( SC_UNONAME_CASE ) || aString.EqualsAscii( SC_UNONAME_ISCASE )) + aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_FORMATS ) || aString.EqualsAscii( SC_UNONAME_BINDFMT )) + aParam.bIncludePattern = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_ENABSORT )) + aParam.bDoSort = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_SORTASC )) + aParam.bAscending = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_INSBRK )) + aParam.bPagebreak = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_ULIST ) || aString.EqualsAscii( SC_UNONAME_ENUSLIST )) + aParam.bUserDef = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_UINDEX ) || aString.EqualsAscii( SC_UNONAME_USINDEX )) + { + sal_Int32 nVal = 0; + if ( aValue >>= nVal ) + aParam.nUserIndex = (USHORT)nVal; + } + else if (aString.EqualsAscii( SC_UNONAME_MAXFLD )) + { + sal_Int32 nVal = 0; + if ( (aValue >>= nVal) && nVal > MAXSUBTOTAL ) + { + throw lang::IllegalArgumentException(); + } + } + + PutData(aParam); +} + +uno::Any SAL_CALL ScSubTotalDescriptorBase::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSubTotalParam aParam; + GetData(aParam); + + String aString = aPropertyName; + uno::Any aRet; + + // some old property names are for 5.2 compatibility + + if (aString.EqualsAscii( SC_UNONAME_CASE ) || aString.EqualsAscii( SC_UNONAME_ISCASE )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens ); + else if (aString.EqualsAscii( SC_UNONAME_FORMATS ) || aString.EqualsAscii( SC_UNONAME_BINDFMT )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bIncludePattern ); + else if (aString.EqualsAscii( SC_UNONAME_ENABSORT )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDoSort ); + else if (aString.EqualsAscii( SC_UNONAME_SORTASC )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bAscending ); + else if (aString.EqualsAscii( SC_UNONAME_INSBRK )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bPagebreak ); + else if (aString.EqualsAscii( SC_UNONAME_ULIST ) || aString.EqualsAscii( SC_UNONAME_ENUSLIST )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bUserDef ); + else if (aString.EqualsAscii( SC_UNONAME_UINDEX ) || aString.EqualsAscii( SC_UNONAME_USINDEX )) + aRet <<= (sal_Int32) aParam.nUserIndex; + else if (aString.EqualsAscii( SC_UNONAME_MAXFLD )) + aRet <<= (sal_Int32) MAXSUBTOTAL; + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSubTotalDescriptorBase ) + +// XUnoTunnel + +sal_Int64 SAL_CALL ScSubTotalDescriptorBase::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScSubTotalDescriptorBase::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScSubTotalDescriptorBase* ScSubTotalDescriptorBase::getImplementation( + const uno::Reference<sheet::XSubTotalDescriptor> xObj ) +{ + ScSubTotalDescriptorBase* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScSubTotalDescriptorBase*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + + +ScSubTotalDescriptor::ScSubTotalDescriptor() +{ +} + +ScSubTotalDescriptor::~ScSubTotalDescriptor() +{ +} + +void ScSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const +{ + rParam = aStoredParam; // Abfrage fuer Interface +} + +void ScSubTotalDescriptor::PutData( const ScSubTotalParam& rParam ) +{ + aStoredParam = rParam; // vom Interface gesetzt +} + +void ScSubTotalDescriptor::SetParam( const ScSubTotalParam& rNew ) +{ + aStoredParam = rNew; // von aussen gesetzt +} + + +ScRangeSubTotalDescriptor::ScRangeSubTotalDescriptor(ScDatabaseRangeObj* pPar) : + pParent(pPar) +{ + if (pParent) + pParent->acquire(); +} + +ScRangeSubTotalDescriptor::~ScRangeSubTotalDescriptor() +{ + if (pParent) + pParent->release(); +} + +void ScRangeSubTotalDescriptor::GetData( ScSubTotalParam& rParam ) const +{ + if (pParent) + pParent->GetSubTotalParam( rParam ); +} + +void ScRangeSubTotalDescriptor::PutData( const ScSubTotalParam& rParam ) +{ + if (pParent) + pParent->SetSubTotalParam( rParam ); +} + + +ScConsolidationDescriptor::ScConsolidationDescriptor() +{ +} + +ScConsolidationDescriptor::~ScConsolidationDescriptor() +{ +} + +void ScConsolidationDescriptor::SetParam( const ScConsolidateParam& rNew ) +{ + aParam = rNew; +} + +// XConsolidationDescriptor + +sheet::GeneralFunction SAL_CALL ScConsolidationDescriptor::getFunction() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScDataUnoConversion::SubTotalToGeneral(aParam.eFunction); +} + +void SAL_CALL ScConsolidationDescriptor::setFunction( sheet::GeneralFunction nFunction ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aParam.eFunction = ScDataUnoConversion::GeneralToSubTotal(nFunction); +} + +uno::Sequence<table::CellRangeAddress> SAL_CALL ScConsolidationDescriptor::getSources() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = aParam.nDataAreaCount; + if (!aParam.ppDataAreas) + nCount = 0; + table::CellRangeAddress aRange; + uno::Sequence<table::CellRangeAddress> aSeq(nCount); + table::CellRangeAddress* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + ScArea* pArea = aParam.ppDataAreas[i]; + if (pArea) + { + aRange.Sheet = pArea->nTab; + aRange.StartColumn = pArea->nColStart; + aRange.StartRow = pArea->nRowStart; + aRange.EndColumn = pArea->nColEnd; + aRange.EndRow = pArea->nRowEnd; + } + pAry[i] = aRange; + } + return aSeq; +} + +void SAL_CALL ScConsolidationDescriptor::setSources( + const uno::Sequence<table::CellRangeAddress>& aSources ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = (USHORT)aSources.getLength(); + if (nCount) + { + const table::CellRangeAddress* pAry = aSources.getConstArray(); + ScArea** pNew = new ScArea*[nCount]; + USHORT i; + for (i=0; i<nCount; i++) + pNew[i] = new ScArea( pAry[i].Sheet, + (USHORT)pAry[i].StartColumn, (USHORT)pAry[i].StartRow, + (USHORT)pAry[i].EndColumn, (USHORT)pAry[i].EndRow ); + + aParam.SetAreas( pNew, nCount ); // kopiert alles + + for (i=0; i<nCount; i++) + delete pNew[i]; + delete[] pNew; + } + else + aParam.ClearDataAreas(); +} + +table::CellAddress SAL_CALL ScConsolidationDescriptor::getStartOutputPosition() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellAddress aPos; + aPos.Column = aParam.nCol; + aPos.Row = aParam.nRow; + aPos.Sheet = aParam.nTab; + return aPos; +} + +void SAL_CALL ScConsolidationDescriptor::setStartOutputPosition( + const table::CellAddress& aStartOutputPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aParam.nCol = (USHORT)aStartOutputPosition.Column; + aParam.nRow = (USHORT)aStartOutputPosition.Row; + aParam.nTab = aStartOutputPosition.Sheet; +} + +sal_Bool SAL_CALL ScConsolidationDescriptor::getUseColumnHeaders() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aParam.bByCol; +} + +void SAL_CALL ScConsolidationDescriptor::setUseColumnHeaders( sal_Bool bUseColumnHeaders ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aParam.bByCol = bUseColumnHeaders; +} + +sal_Bool SAL_CALL ScConsolidationDescriptor::getUseRowHeaders() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aParam.bByRow; +} + +void SAL_CALL ScConsolidationDescriptor::setUseRowHeaders( sal_Bool bUseRowHeaders ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aParam.bByRow = bUseRowHeaders; +} + +sal_Bool SAL_CALL ScConsolidationDescriptor::getInsertLinks() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aParam.bReferenceData; +} + +void SAL_CALL ScConsolidationDescriptor::setInsertLinks( sal_Bool bInsertLinks ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aParam.bReferenceData = bInsertLinks; +} + + +ScFilterDescriptorBase::ScFilterDescriptorBase(ScDocShell* pDocShell) + : aPropSet( lcl_GetFilterPropertyMap() ) + , pDocSh(pDocShell) +{ + if (pDocSh) + pDocSh->GetDocument()->AddUnoObject(*this); +} + +ScFilterDescriptorBase::~ScFilterDescriptorBase() +{ + if (pDocSh) + pDocSh->GetDocument()->RemoveUnoObject(*this); +} + +void ScFilterDescriptorBase::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + { + pDocSh = NULL; // invalid + } + } +} + +// XSheetFilterDescriptor + +uno::Sequence<sheet::TableFilterField> SAL_CALL ScFilterDescriptorBase::getFilterFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScQueryParam aParam; + GetData(aParam); + + USHORT nEntries = aParam.GetEntryCount(); // allozierte Eintraege im Param + USHORT nCount = 0; // aktive + while ( nCount < nEntries && + aParam.GetEntry(nCount).bDoQuery ) + ++nCount; + + sheet::TableFilterField aField; + uno::Sequence<sheet::TableFilterField> aSeq(nCount); + sheet::TableFilterField* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + const ScQueryEntry& rEntry = aParam.GetEntry(i); + + ::rtl::OUString aStringValue; + if (rEntry.pStr) + aStringValue = *rEntry.pStr; + + aField.Connection = (rEntry.eConnect == SC_AND) ? sheet::FilterConnection_AND : + sheet::FilterConnection_OR; + aField.Field = rEntry.nField; + aField.IsNumeric = !rEntry.bQueryByString; + aField.StringValue = aStringValue; + aField.NumericValue = rEntry.nVal; + + switch (rEntry.eOp) // ScQueryOp + { + case SC_EQUAL: + { + aField.Operator = sheet::FilterOperator_EQUAL; + if (!rEntry.bQueryByString && *rEntry.pStr == EMPTY_STRING) + { + if (rEntry.nVal == SC_EMPTYFIELDS) + { + aField.Operator = sheet::FilterOperator_EMPTY; + aField.NumericValue = 0; + } + else if (rEntry.nVal == SC_NONEMPTYFIELDS) + { + aField.Operator = sheet::FilterOperator_NOT_EMPTY; + aField.NumericValue = 0; + } + } + } + break; + case SC_LESS: aField.Operator = sheet::FilterOperator_LESS; break; + case SC_GREATER: aField.Operator = sheet::FilterOperator_GREATER; break; + case SC_LESS_EQUAL: aField.Operator = sheet::FilterOperator_LESS_EQUAL; break; + case SC_GREATER_EQUAL: aField.Operator = sheet::FilterOperator_GREATER_EQUAL; break; + case SC_NOT_EQUAL: aField.Operator = sheet::FilterOperator_NOT_EQUAL; break; + case SC_TOPVAL: aField.Operator = sheet::FilterOperator_TOP_VALUES; break; + case SC_BOTVAL: aField.Operator = sheet::FilterOperator_BOTTOM_VALUES; break; + case SC_TOPPERC: aField.Operator = sheet::FilterOperator_TOP_PERCENT; break; + case SC_BOTPERC: aField.Operator = sheet::FilterOperator_BOTTOM_PERCENT; break; + default: + OSL_FAIL("Falscher Filter-enum"); + aField.Operator = sheet::FilterOperator_EMPTY; + } + pAry[i] = aField; + } + return aSeq; +} + +void SAL_CALL ScFilterDescriptorBase::setFilterFields( + const uno::Sequence<sheet::TableFilterField>& aFilterFields ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScQueryParam aParam; + GetData(aParam); + + USHORT nCount = (USHORT)aFilterFields.getLength(); + DBG_ASSERT( nCount <= MAXQUERY, "setFilterFields: zu viele" ); + + aParam.Resize( nCount ); + + const sheet::TableFilterField* pAry = aFilterFields.getConstArray(); + USHORT i; + for (i=0; i<nCount; i++) + { + ScQueryEntry& rEntry = aParam.GetEntry(i); + if (!rEntry.pStr) + rEntry.pStr = new String; // sollte nicht sein (soll immer initialisiert sein) + + rEntry.bDoQuery = TRUE; + rEntry.eConnect = (pAry[i].Connection == sheet::FilterConnection_AND) ? SC_AND : SC_OR; + rEntry.nField = (USHORT)pAry[i].Field; + rEntry.bQueryByString = !pAry[i].IsNumeric; + *rEntry.pStr = String( pAry[i].StringValue ); + rEntry.nVal = pAry[i].NumericValue; + + if (!rEntry.bQueryByString && pDocSh) + { + pDocSh->GetDocument()->GetFormatTable()->GetInputLineString(rEntry.nVal, 0, *rEntry.pStr); + } + + switch (pAry[i].Operator) // FilterOperator + { + case sheet::FilterOperator_EQUAL: rEntry.eOp = SC_EQUAL; break; + case sheet::FilterOperator_LESS: rEntry.eOp = SC_LESS; break; + case sheet::FilterOperator_GREATER: rEntry.eOp = SC_GREATER; break; + case sheet::FilterOperator_LESS_EQUAL: rEntry.eOp = SC_LESS_EQUAL; break; + case sheet::FilterOperator_GREATER_EQUAL: rEntry.eOp = SC_GREATER_EQUAL; break; + case sheet::FilterOperator_NOT_EQUAL: rEntry.eOp = SC_NOT_EQUAL; break; + case sheet::FilterOperator_TOP_VALUES: rEntry.eOp = SC_TOPVAL; break; + case sheet::FilterOperator_BOTTOM_VALUES: rEntry.eOp = SC_BOTVAL; break; + case sheet::FilterOperator_TOP_PERCENT: rEntry.eOp = SC_TOPPERC; break; + case sheet::FilterOperator_BOTTOM_PERCENT: rEntry.eOp = SC_BOTPERC; break; + case sheet::FilterOperator_EMPTY: + { + rEntry.eOp = SC_EQUAL; + rEntry.nVal = SC_EMPTYFIELDS; + rEntry.bQueryByString = FALSE; + *rEntry.pStr = EMPTY_STRING; + } + break; + case sheet::FilterOperator_NOT_EMPTY: + { + rEntry.eOp = SC_EQUAL; + rEntry.nVal = SC_NONEMPTYFIELDS; + rEntry.bQueryByString = FALSE; + *rEntry.pStr = EMPTY_STRING; + } + break; + default: + OSL_FAIL("Falscher Query-enum"); + rEntry.eOp = SC_EQUAL; + } + } + + USHORT nParamCount = aParam.GetEntryCount(); // Param wird nicht unter 8 resized + for (i=nCount; i<nParamCount; i++) + aParam.GetEntry(i).bDoQuery = FALSE; // ueberzaehlige Felder zuruecksetzen + + PutData(aParam); +} + +// Rest sind Properties + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScFilterDescriptorBase::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScFilterDescriptorBase::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScQueryParam aParam; + GetData(aParam); + + String aString = aPropertyName; + if (aString.EqualsAscii( SC_UNONAME_CONTHDR )) + aParam.bHasHeader = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_COPYOUT )) + aParam.bInplace = !(ScUnoHelpFunctions::GetBoolFromAny( aValue )); + else if (aString.EqualsAscii( SC_UNONAME_ISCASE )) + aParam.bCaseSens = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_MAXFLD )) + { + sal_Int32 nVal = 0; + if ( (aValue >>= nVal) && nVal > MAXQUERY ) + { + throw lang::IllegalArgumentException(); + } + } + else if (aString.EqualsAscii( SC_UNONAME_ORIENT )) + { + //! test for correct enum type? + table::TableOrientation eOrient = (table::TableOrientation) + ScUnoHelpFunctions::GetEnumFromAny( aValue ); + aParam.bByRow = ( eOrient != table::TableOrientation_COLUMNS ); + } + else if (aString.EqualsAscii( SC_UNONAME_OUTPOS )) + { + table::CellAddress aAddress; + if ( aValue >>= aAddress ) + { + aParam.nDestTab = aAddress.Sheet; + aParam.nDestCol = (USHORT)aAddress.Column; + aParam.nDestRow = (USHORT)aAddress.Row; + } + } + else if (aString.EqualsAscii( SC_UNONAME_SAVEOUT )) + aParam.bDestPers = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if (aString.EqualsAscii( SC_UNONAME_SKIPDUP )) + aParam.bDuplicate = !(ScUnoHelpFunctions::GetBoolFromAny( aValue )); + else if (aString.EqualsAscii( SC_UNONAME_USEREGEX )) + aParam.bRegExp = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + + PutData(aParam); +} + +uno::Any SAL_CALL ScFilterDescriptorBase::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScQueryParam aParam; + GetData(aParam); + + String aString = aPropertyName; + uno::Any aRet; + + if (aString.EqualsAscii( SC_UNONAME_CONTHDR )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bHasHeader ); + else if (aString.EqualsAscii( SC_UNONAME_COPYOUT )) + ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bInplace) ); + else if (aString.EqualsAscii( SC_UNONAME_ISCASE )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bCaseSens ); + else if (aString.EqualsAscii( SC_UNONAME_MAXFLD )) + aRet <<= (sal_Int32) MAXQUERY; + else if (aString.EqualsAscii( SC_UNONAME_ORIENT )) + { + table::TableOrientation eOrient = aParam.bByRow ? table::TableOrientation_ROWS : + table::TableOrientation_COLUMNS; + aRet <<= eOrient; + } + else if (aString.EqualsAscii( SC_UNONAME_OUTPOS )) + { + table::CellAddress aOutPos; + aOutPos.Sheet = aParam.nDestTab; + aOutPos.Column = aParam.nDestCol; + aOutPos.Row = aParam.nDestRow; + aRet <<= aOutPos; + } + else if (aString.EqualsAscii( SC_UNONAME_SAVEOUT )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bDestPers ); + else if (aString.EqualsAscii( SC_UNONAME_SKIPDUP )) + ScUnoHelpFunctions::SetBoolInAny( aRet, !(aParam.bDuplicate) ); + else if (aString.EqualsAscii( SC_UNONAME_USEREGEX )) + ScUnoHelpFunctions::SetBoolInAny( aRet, aParam.bRegExp ); + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScFilterDescriptorBase ) + + +ScFilterDescriptor::ScFilterDescriptor(ScDocShell* pInDocSh) + : + ScFilterDescriptorBase(pInDocSh) +{ +} + +ScFilterDescriptor::~ScFilterDescriptor() +{ +} + +void ScFilterDescriptor::GetData( ScQueryParam& rParam ) const +{ + rParam = aStoredParam; // Abfrage fuer Interface +} + +void ScFilterDescriptor::PutData( const ScQueryParam& rParam ) +{ + aStoredParam = rParam; // vom Interface gesetzt +} + +void ScFilterDescriptor::SetParam( const ScQueryParam& rNew ) +{ + aStoredParam = rNew; // von aussen gesetzt +} + + +ScRangeFilterDescriptor::ScRangeFilterDescriptor(ScDocShell* pInDocSh, ScDatabaseRangeObj* pPar) : + ScFilterDescriptorBase(pInDocSh), + pParent(pPar) +{ + if (pParent) + pParent->acquire(); +} + +ScRangeFilterDescriptor::~ScRangeFilterDescriptor() +{ + if (pParent) + pParent->release(); +} + +void ScRangeFilterDescriptor::GetData( ScQueryParam& rParam ) const +{ + if (pParent) + pParent->GetQueryParam( rParam ); +} + +void ScRangeFilterDescriptor::PutData( const ScQueryParam& rParam ) +{ + if (pParent) + pParent->SetQueryParam( rParam ); +} + + +ScDataPilotFilterDescriptor::ScDataPilotFilterDescriptor(ScDocShell* pInDocSh, ScDataPilotDescriptorBase* pPar) : + ScFilterDescriptorBase(pInDocSh), + pParent(pPar) +{ + if (pParent) + pParent->acquire(); +} + +ScDataPilotFilterDescriptor::~ScDataPilotFilterDescriptor() +{ + if (pParent) + pParent->release(); +} + +void ScDataPilotFilterDescriptor::GetData( ScQueryParam& rParam ) const +{ + if (pParent) + { + ScPivotParam aPivot; + ScArea aArea; + pParent->GetParam( aPivot, rParam, aArea ); + } +} + +void ScDataPilotFilterDescriptor::PutData( const ScQueryParam& rParam ) +{ + if (pParent) + { + ScPivotParam aPivot; + ScArea aArea; + ScQueryParam aOldQuery; + pParent->GetParam( aPivot, aOldQuery, aArea ); + pParent->SetParam( aPivot, rParam, aArea ); + } +} + + +ScDatabaseRangeObj::ScDatabaseRangeObj(ScDocShell* pDocSh, const String& rNm) : + pDocShell( pDocSh ), + aName( rNm ), + aPropSet( lcl_GetDBRangePropertyMap() ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDatabaseRangeObj::~ScDatabaseRangeObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDatabaseRangeObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Ref-Update interessiert nicht + + if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + pDocShell = NULL; // ungueltig geworden +} + +// Hilfsfuntionen + +ScDBData* ScDatabaseRangeObj::GetDBData_Impl() const +{ + ScDBData* pRet = NULL; + if (pDocShell) + { + ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection(); + if (pNames) + { + USHORT nPos = 0; + if (pNames->SearchName( aName, nPos )) + pRet = (*pNames)[nPos]; + } + } + return pRet; +} + +// XNamed + +::rtl::OUString SAL_CALL ScDatabaseRangeObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aName; +} + +void SAL_CALL ScDatabaseRangeObj::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDBDocFunc aFunc(*pDocShell); + String aNewStr = aNewName; + BOOL bOk = aFunc.RenameDBRange( aName, aNewStr ); + if (bOk) + aName = aNewStr; + } +} + +// XDatabaseRange + +table::CellRangeAddress SAL_CALL ScDatabaseRangeObj::getDataArea() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aAddress; + ScDBData* pData = GetDBData_Impl(); + if (pData) + { + ScRange aRange; + pData->GetArea(aRange); + aAddress.Sheet = aRange.aStart.Tab(); + aAddress.StartColumn = aRange.aStart.Col(); + aAddress.StartRow = aRange.aStart.Row(); + aAddress.EndColumn = aRange.aEnd.Col(); + aAddress.EndRow = aRange.aEnd.Row(); + } + return aAddress; +} + +void SAL_CALL ScDatabaseRangeObj::setDataArea( const table::CellRangeAddress& aDataArea ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDBData* pData = GetDBData_Impl(); + if ( pDocShell && pData ) + { + ScDBData aNewData( *pData ); + //! MoveTo ??? + aNewData.SetArea( aDataArea.Sheet, (USHORT)aDataArea.StartColumn, (USHORT)aDataArea.StartRow, + (USHORT)aDataArea.EndColumn, (USHORT)aDataArea.EndRow ); + ScDBDocFunc aFunc(*pDocShell); + aFunc.ModifyDBData(aNewData); + } +} + +uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getSortDescriptor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScSortParam aParam; + const ScDBData* pData = GetDBData_Impl(); + if (pData) + { + pData->GetSortParam(aParam); + + // im SortDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = aParam.bByRow ? aDBRange.aStart.Col() : aDBRange.aStart.Row(); + for (USHORT i=0; i<MAXSORT; i++) + if ( aParam.bDoSort[i] && aParam.nField[i] >= nFieldStart ) + aParam.nField[i] -= nFieldStart; + } + + uno::Sequence<beans::PropertyValue> aSeq( ScSortDescriptor::GetPropertyCount() ); + ScSortDescriptor::FillProperties( aSeq, aParam ); + return aSeq; +} + +void ScDatabaseRangeObj::GetQueryParam(ScQueryParam& rQueryParam) const +{ + const ScDBData* pData = GetDBData_Impl(); + if (pData) + { + pData->GetQueryParam(rQueryParam); + + // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = rQueryParam.bByRow ? aDBRange.aStart.Col() : aDBRange.aStart.Row(); + USHORT nCount = rQueryParam.GetEntryCount(); + for (USHORT i=0; i<nCount; i++) + { + ScQueryEntry& rEntry = rQueryParam.GetEntry(i); + if (rEntry.bDoQuery && rEntry.nField >= nFieldStart) + rEntry.nField -= nFieldStart; + } + } +} + +void ScDatabaseRangeObj::SetQueryParam(const ScQueryParam& rQueryParam) +{ + const ScDBData* pData = GetDBData_Impl(); + if (pData) + { + // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScQueryParam aParam = rQueryParam; + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = aParam.bByRow ? aDBRange.aStart.Col() : aDBRange.aStart.Row(); + + USHORT nCount = aParam.GetEntryCount(); + for (USHORT i=0; i<nCount; i++) + { + ScQueryEntry& rEntry = aParam.GetEntry(i); + if (rEntry.bDoQuery) + rEntry.nField += nFieldStart; + } + + ScDBData aNewData( *pData ); + aNewData.SetQueryParam(aParam); + aNewData.SetHeader(aParam.bHasHeader); // not in ScDBData::SetQueryParam + ScDBDocFunc aFunc(*pDocShell); + aFunc.ModifyDBData(aNewData); + } +} + +uno::Reference<sheet::XSheetFilterDescriptor> SAL_CALL ScDatabaseRangeObj::getFilterDescriptor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScRangeFilterDescriptor(pDocShell, this); +} + +void ScDatabaseRangeObj::GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const +{ + const ScDBData* pData = GetDBData_Impl(); + if (pData) + { + pData->GetSubTotalParam(rSubTotalParam); + + // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = aDBRange.aStart.Col(); + for (USHORT i=0; i<MAXSUBTOTAL; i++) + { + if ( rSubTotalParam.bGroupActive[i] ) + { + if ( rSubTotalParam.nField[i] >= nFieldStart ) + rSubTotalParam.nField[i] -= nFieldStart; + for (USHORT j=0; j<rSubTotalParam.nSubTotals[i]; j++) + if ( rSubTotalParam.pSubTotals[i][j] >= nFieldStart ) + rSubTotalParam.pSubTotals[i][j] -= nFieldStart; + } + } + } +} + +void ScDatabaseRangeObj::SetSubTotalParam(const ScSubTotalParam& rSubTotalParam) +{ + const ScDBData* pData = GetDBData_Impl(); + if (pData) + { + // im FilterDescriptor sind die Fields innerhalb des Bereichs gezaehlt + ScSubTotalParam aParam = rSubTotalParam; + ScRange aDBRange; + pData->GetArea(aDBRange); + USHORT nFieldStart = aDBRange.aStart.Col(); + for (USHORT i=0; i<MAXSUBTOTAL; i++) + { + if ( aParam.bGroupActive[i] ) + { + aParam.nField[i] += nFieldStart; + for (USHORT j=0; j<aParam.nSubTotals[i]; j++) + aParam.pSubTotals[i][j] += nFieldStart; + } + } + + ScDBData aNewData( *pData ); + aNewData.SetSubTotalParam(aParam); + ScDBDocFunc aFunc(*pDocShell); + aFunc.ModifyDBData(aNewData); + } +} + +uno::Reference<sheet::XSubTotalDescriptor> SAL_CALL ScDatabaseRangeObj::getSubTotalDescriptor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScRangeSubTotalDescriptor(this); +} + +uno::Sequence<beans::PropertyValue> SAL_CALL ScDatabaseRangeObj::getImportDescriptor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScImportParam aParam; + const ScDBData* pData = GetDBData_Impl(); + if (pData) + pData->GetImportParam(aParam); + + uno::Sequence<beans::PropertyValue> aSeq( ScImportDescriptor::GetPropertyCount() ); + ScImportDescriptor::FillProperties( aSeq, aParam ); + return aSeq; +} + +void SAL_CALL ScDatabaseRangeObj::refresh() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDBData* pData = GetDBData_Impl(); + if ( pDocShell && pData ) + { + ScDBDocFunc aFunc(*pDocShell); + + // Import zu wiederholen? + BOOL bContinue = TRUE; + ScImportParam aImportParam; + pData->GetImportParam( aImportParam ); + if (aImportParam.bImport && !pData->HasImportSelection()) + { + USHORT nTab, nDummy; + pData->GetArea( nTab, nDummy,nDummy,nDummy,nDummy ); + uno::Reference< sdbc::XResultSet > xResultSet; + bContinue = aFunc.DoImport( nTab, aImportParam, xResultSet, NULL, TRUE, FALSE ); //! Api-Flag als Parameter + } + + // interne Operationen (sort, query, subtotal) nur, wenn kein Fehler + if (bContinue) + aFunc.RepeatDB( pData->GetName(), TRUE ); + } +} + +// XCellRangeSource + +uno::Reference<table::XCellRange> SAL_CALL ScDatabaseRangeObj::getReferredCells() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRange aRange; + ScDBData* pData = GetDBData_Impl(); + if ( pData ) + { + //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ??? + + pData->GetArea(aRange); + if ( aRange.aStart == aRange.aEnd ) + return new ScCellObj( pDocShell, aRange.aStart ); + else + return new ScCellRangeObj( pDocShell, aRange ); + } + return NULL; +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDatabaseRangeObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScDatabaseRangeObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScDBData* pData = GetDBData_Impl(); + if ( pDocShell && pData ) + { + ScDBData aNewData( *pData ); + BOOL bDo = TRUE; + + String aString = aPropertyName; + if ( aString.EqualsAscii( SC_UNONAME_KEEPFORM ) ) + aNewData.SetKeepFmt( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNONAME_MOVCELLS ) ) + aNewData.SetDoSize( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNONAME_STRIPDAT ) ) + aNewData.SetStripData( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if (aString.EqualsAscii( SC_UNONAME_AUTOFLT )) + { + sal_Bool bAutoFilter(ScUnoHelpFunctions::GetBoolFromAny( aValue )); + aNewData.SetAutoFilter(bAutoFilter); + ScRange aRange; + aNewData.GetArea(aRange); + ScDocument* pDoc = pDocShell->GetDocument(); + if (bAutoFilter && pDoc) + pDoc->ApplyFlagsTab( aRange.aStart.Col(), aRange.aStart.Row(), + aRange.aEnd.Col(), aRange.aStart.Row(), + aRange.aStart.Tab(), SC_MF_AUTO ); + + ScRange aPaintRange(aRange.aStart, aRange.aEnd); + aPaintRange.aEnd.SetRow(aPaintRange.aStart.Row()); + pDocShell->PostPaint(aPaintRange, PAINT_GRID); + } + else if (aString.EqualsAscii( SC_UNONAME_USEFLTCRT )) + { + if (ScUnoHelpFunctions::GetBoolFromAny( aValue )) + { + ScRange aRange; + aNewData.GetAdvancedQuerySource(aRange); + aNewData.SetAdvancedQuerySource(&aRange); + } + else + aNewData.SetAdvancedQuerySource(NULL); + } + else if (aString.EqualsAscii( SC_UNONAME_FLTCRT )) + { + table::CellRangeAddress aRange; + if (aValue >>= aRange) + { + ScRange aCoreRange; + ScUnoConversion::FillScRange(aCoreRange, aRange); + + aNewData.SetAdvancedQuerySource(&aCoreRange); + } + } + else + bDo = FALSE; + + if (bDo) + { + ScDBDocFunc aFunc(*pDocShell); + aFunc.ModifyDBData(aNewData); + } + } +} + +uno::Any SAL_CALL ScDatabaseRangeObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aRet; + ScDBData* pData = GetDBData_Impl(); + if ( pData ) + { + String aString = aPropertyName; + if ( aString.EqualsAscii( SC_UNONAME_KEEPFORM ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsKeepFmt() ); + else if ( aString.EqualsAscii( SC_UNONAME_MOVCELLS ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsDoSize() ); + else if ( aString.EqualsAscii( SC_UNONAME_STRIPDAT ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, pData->IsStripData() ); + else if ( aString.EqualsAscii( SC_UNONAME_ISUSER ) ) + { + // all database ranges except "unnamed" are user defined + ScUnoHelpFunctions::SetBoolInAny( aRet, + ( pData->GetName() != ScGlobal::GetRscString(STR_DB_NONAME) ) ); + } + else if ( aString.EqualsAscii( SC_UNO_LINKDISPBIT ) ) + { + // no target bitmaps for individual entries (would be all equal) + // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_DBAREA ); + } + else if ( aString.EqualsAscii( SC_UNO_LINKDISPNAME ) ) + aRet <<= ::rtl::OUString( aName ); + else if (aString.EqualsAscii( SC_UNONAME_AUTOFLT )) + { + sal_Bool bAutoFilter(GetDBData_Impl()->HasAutoFilter()); + + ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoFilter ); + } + else if (aString.EqualsAscii( SC_UNONAME_USEFLTCRT )) + { + ScRange aRange; + sal_Bool bIsAdvancedSource(GetDBData_Impl()->GetAdvancedQuerySource(aRange)); + + ScUnoHelpFunctions::SetBoolInAny( aRet, bIsAdvancedSource ); + } + else if (aString.EqualsAscii( SC_UNONAME_FLTCRT )) + { + table::CellRangeAddress aRange; + ScRange aCoreRange; + if (GetDBData_Impl()->GetAdvancedQuerySource(aCoreRange)) + ScUnoConversion::FillApiRange(aRange, aCoreRange); + + aRet <<= aRange; + } + } + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDatabaseRangeObj ) + +// XServiceInfo + +::rtl::OUString SAL_CALL ScDatabaseRangeObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScDatabaseRangeObj" )); +} + +sal_Bool SAL_CALL ScDatabaseRangeObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCDATABASERANGEOBJ_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScDatabaseRangeObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCDATABASERANGEOBJ_SERVICE )); + return aRet; +} + + +ScDatabaseRangesObj::ScDatabaseRangesObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDatabaseRangesObj::~ScDatabaseRangesObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDatabaseRangesObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XDatabaseRanges + +ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByIndex_Impl(USHORT nIndex) +{ + if (pDocShell) + { + ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection(); + if (pNames && nIndex < pNames->GetCount()) + return new ScDatabaseRangeObj( pDocShell, (*pNames)[nIndex]->GetName() ); + } + return NULL; +} + +ScDatabaseRangeObj* ScDatabaseRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + if ( pDocShell && hasByName(aName) ) + { + String aString = aName; + return new ScDatabaseRangeObj( pDocShell, aString ); + } + return NULL; +} + + +void SAL_CALL ScDatabaseRangesObj::addNewByName( const ::rtl::OUString& aName, + const table::CellRangeAddress& aRange ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + ScDBDocFunc aFunc(*pDocShell); + + String aString = aName; + ScRange aNameRange( (USHORT)aRange.StartColumn, (USHORT)aRange.StartRow, aRange.Sheet, + (USHORT)aRange.EndColumn, (USHORT)aRange.EndRow, aRange.Sheet ); + bDone = aFunc.AddDBRange( aString, aNameRange ); + } + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScDatabaseRangesObj::removeByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + ScDBDocFunc aFunc(*pDocShell); + String aString = aName; + bDone = aFunc.DeleteDBRange( aString ); + } + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScDatabaseRangesObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DatabaseRangesEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScDatabaseRangesObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! "unbenannt" weglassen ? + + if (pDocShell) + { + ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection(); + if (pNames) + return pNames->GetCount(); + } + + return 0; +} + +uno::Any SAL_CALL ScDatabaseRangesObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XDatabaseRange> xRange = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xRange.is()) + aAny <<= xRange; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScDatabaseRangesObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XDatabaseRange>*)0); +} + +sal_Bool SAL_CALL ScDatabaseRangesObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// XNameAccess + +uno::Any SAL_CALL ScDatabaseRangesObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XDatabaseRange> xRange = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xRange.is()) + aAny <<= xRange; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScDatabaseRangesObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! "unbenannt" weglassen ? + + if (pDocShell) + { + ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection(); + if (pNames) + { + USHORT nCount = pNames->GetCount(); + String aName; + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + pAry[i] = (*pNames)[i]->GetName(); + + return aSeq; + } + } + return uno::Sequence< ::rtl::OUString>(0); +} + +sal_Bool SAL_CALL ScDatabaseRangesObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! "unbenannt" weglassen ? + + if (pDocShell) + { + ScDBCollection* pNames = pDocShell->GetDocument()->GetDBCollection(); + if (pNames) + { + String aString = aName; + USHORT nPos = 0; + if (pNames->SearchName( aString, nPos )) + return TRUE; + } + } + return FALSE; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_defltuno.cxx b/bf_sc/source/ui/unoobj/sc_defltuno.cxx new file mode 100644 index 000000000..1a570f298 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_defltuno.cxx @@ -0,0 +1,376 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <bf_svtools/itemprop.hxx> +#include <i18npool/mslangid.hxx> + + +#include "scitems.hxx" +#include "defltuno.hxx" +#include "miscuno.hxx" +#include "docsh.hxx" +#include "docpool.hxx" +#include <vcl/svapp.hxx> +#include "unonames.hxx" +#include "docoptio.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +const SfxItemPropertyMap* lcl_GetDocDefaultsMap() +{ + static SfxItemPropertyMap aDocDefaultsMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE, &getCppuType((lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), 0, &getCppuType((sal_Int16*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_TABSTOPDIS), 0, &getCppuType((sal_Int32*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aDocDefaultsMap_Impl; +} + +inline long TwipsToHMM(long nTwips) { return (nTwips * 127 + 36) / 72; } +inline long HMMToTwips(long nHMM) { return (nHMM * 72 + 63) / 127; } +inline long TwipsToEvenHMM(long nTwips) { return ( (nTwips * 127 + 72) / 144 ) * 2; } + +//------------------------------------------------------------------------ + +SC_SIMPLE_SERVICE_INFO( ScDocDefaultsObj, "ScDocDefaultsObj", "com.sun.star.sheet.Defaults" ) + +//------------------------------------------------------------------------ + +ScDocDefaultsObj::ScDocDefaultsObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDocDefaultsObj::~ScDocDefaultsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDocDefaultsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // document gone + } +} + +void ScDocDefaultsObj::ItemsChanged() +{ + if (pDocShell) + { + //! if not in XML import, adjust row heights + + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); + } +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScDocDefaultsObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( lcl_GetDocDefaultsMap() ); + return aRef; +} + +void SAL_CALL ScDocDefaultsObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !pDocShell ) + throw uno::RuntimeException(); + + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetDocDefaultsMap(), aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + if(!pMap->nWID) + { + if(aPropertyName.compareToAscii(SC_UNO_STANDARDDEC) == 0) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if (pDoc) + { + ScDocOptions aDocOpt(pDoc->GetDocOptions()); + sal_Int16 nValue = 0; + if (aValue >>= nValue) + { + aDocOpt.SetStdPrecision(static_cast<sal_uInt8> (nValue)); + pDoc->SetDocOptions(aDocOpt); + } + } + else + throw uno::RuntimeException(); + } + else if (aPropertyName.compareToAscii(SC_UNO_TABSTOPDIS) == 0) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if (pDoc) + { + ScDocOptions aDocOpt(pDoc->GetDocOptions()); + sal_Int32 nValue = 0; + if (aValue >>= nValue) + { + aDocOpt.SetTabDistance(static_cast<sal_uInt16>(HMMToTwips(nValue))); + pDoc->SetDocOptions(aDocOpt); + } + } + else + throw uno::RuntimeException(); + } + } + else if ( pMap->nWID == ATTR_FONT_LANGUAGE || + pMap->nWID == ATTR_CJK_FONT_LANGUAGE || + pMap->nWID == ATTR_CTL_FONT_LANGUAGE ) + { + // for getPropertyValue the PoolDefaults are sufficient, + // but setPropertyValue has to be handled differently + + lang::Locale aLocale; + if ( aValue >>= aLocale ) + { + LanguageType eNew; + if (aLocale.Language.getLength() || aLocale.Country.getLength()) + eNew = MsLangId::convertIsoNamesToLanguage( aLocale.Language, aLocale.Country ); + else + eNew = LANGUAGE_NONE; + + ScDocument* pDoc = pDocShell->GetDocument(); + LanguageType eLatin, eCjk, eCtl; + pDoc->GetLanguage( eLatin, eCjk, eCtl ); + + if ( pMap->nWID == ATTR_CJK_FONT_LANGUAGE ) + eCjk = eNew; + else if ( pMap->nWID == ATTR_CTL_FONT_LANGUAGE ) + eCtl = eNew; + else + eLatin = eNew; + + pDoc->SetLanguage( eLatin, eCjk, eCtl ); + } + } + else + { + ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool(); + SfxPoolItem* pNewItem = pPool->GetDefaultItem(pMap->nWID).Clone(); + + if( !pNewItem->PutValue( aValue, pMap->nMemberId ) ) + throw lang::IllegalArgumentException(); + + pPool->SetPoolDefaultItem( *pNewItem ); + delete pNewItem; // copied in SetPoolDefaultItem + + ItemsChanged(); + } +} + +uno::Any SAL_CALL ScDocDefaultsObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + // use pool default if set + + SolarMutexGuard aGuard; + + if ( !pDocShell ) + throw uno::RuntimeException(); + + uno::Any aRet; + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetDocDefaultsMap(), aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + if (!pMap->nWID) + { + if(aPropertyName.compareToAscii(SC_UNO_STANDARDDEC) == 0) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if (pDoc) + { + const ScDocOptions& aDocOpt = pDoc->GetDocOptions(); + aRet <<= static_cast<sal_Int16> (aDocOpt.GetStdPrecision()); + } + else + throw uno::RuntimeException(); + } + else if (aPropertyName.compareToAscii(SC_UNO_TABSTOPDIS) == 0) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if (pDoc) + { + const ScDocOptions& aDocOpt = pDoc->GetDocOptions(); + sal_Int32 nValue (TwipsToEvenHMM(aDocOpt.GetTabDistance())); + aRet <<= nValue; + } + else + throw uno::RuntimeException(); + } + } + else + { + ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool(); + const SfxPoolItem& rItem = pPool->GetDefaultItem( pMap->nWID ); + rItem.QueryValue( aRet, pMap->nMemberId ); + } + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScDocDefaultsObj ) + +// XPropertyState + +beans::PropertyState SAL_CALL ScDocDefaultsObj::getPropertyState( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !pDocShell ) + throw uno::RuntimeException(); + + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetDocDefaultsMap(), aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + beans::PropertyState eRet = beans::PropertyState_DEFAULT_VALUE; + + USHORT nWID = pMap->nWID; + if ( nWID == ATTR_FONT || nWID == ATTR_CJK_FONT || nWID == ATTR_CTL_FONT || !nWID ) + { + // static default for font is system-dependent, + // so font default is always treated as "direct value". + + eRet = beans::PropertyState_DIRECT_VALUE; + } + else + { + // check if pool default is set + + ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool(); + if ( pPool->GetPoolDefaultItem( nWID ) != NULL ) + eRet = beans::PropertyState_DIRECT_VALUE; + } + + return eRet; +} + +uno::Sequence<beans::PropertyState> SAL_CALL ScDocDefaultsObj::getPropertyStates( + const uno::Sequence< ::rtl::OUString>& aPropertyNames ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + // the simple way: call getPropertyState + + SolarMutexGuard aGuard; + const ::rtl::OUString* pNames = aPropertyNames.getConstArray(); + uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength()); + beans::PropertyState* pStates = aRet.getArray(); + for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++) + pStates[i] = getPropertyState(pNames[i]); + return aRet; +} + +void SAL_CALL ScDocDefaultsObj::setPropertyToDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !pDocShell ) + throw uno::RuntimeException(); + + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetDocDefaultsMap(), aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + if (pMap->nWID) + { + ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool(); + pPool->ResetPoolDefaultItem( pMap->nWID ); + + ItemsChanged(); + } +} + +uno::Any SAL_CALL ScDocDefaultsObj::getPropertyDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + // always use static default + + SolarMutexGuard aGuard; + + if ( !pDocShell ) + throw uno::RuntimeException(); + + const SfxItemPropertyMap* pMap = + SfxItemPropertyMap::GetByName( lcl_GetDocDefaultsMap(), aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + uno::Any aRet; + if (pMap->nWID) + { + ScDocumentPool* pPool = pDocShell->GetDocument()->GetPool(); + const SfxPoolItem* pItem = pPool->GetItem( pMap->nWID, SFX_ITEMS_STATICDEFAULT ); + if (pItem) + pItem->QueryValue( aRet, pMap->nMemberId ); + } + return aRet; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_docuno.cxx b/bf_sc/source/ui/unoobj/sc_docuno.cxx new file mode 100644 index 000000000..19b155b69 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_docuno.cxx @@ -0,0 +1,2496 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/container/XIndexContainer.hpp> + +#include <bf_svx/fmdpage.hxx> +#include <bf_svx/fmview.hxx> +#include <bf_svx/svdpage.hxx> + +#include <bf_svtools/numuno.hxx> +#include <vcl/waitobj.hxx> +#include <tools/multisel.hxx> +#include <toolkit/awt/vclxdevice.hxx> +#include <ctype.h> +#include <float.h> // DBL_MAX + +#include <com/sun/star/util/Date.hpp> + +#include "cellsuno.hxx" +#include "nameuno.hxx" +#include "datauno.hxx" +#include "miscuno.hxx" +#include "notesuno.hxx" +#include "styleuno.hxx" +#include "linkuno.hxx" +#include "servuno.hxx" +#include "convuno.hxx" +#include "optuno.hxx" +#include "forbiuno.hxx" +#include "docsh.hxx" +#include "hints.hxx" +#include "docfunc.hxx" +#include "dociter.hxx" +#include "cell.hxx" +#include "drwlayer.hxx" +#include <vcl/svapp.hxx> +#include "unonames.hxx" +#include "shapeuno.hxx" +#include "printfun.hxx" +#include "scmod.hxx" +#include "docsh.hxx" +#include "viewdata.hxx" + +#include "ViewSettingsSequenceDefines.hxx" +#include <legacysmgr/legacy_binfilters_smgr.hxx> +namespace binfilter { +using namespace ::com::sun::star; + +#define TABLEID_DOC 0xFFFF + +//------------------------------------------------------------------------ + +// alles ohne Which-ID, Map nur fuer PropertySetInfo + +//! umbenennen, sind nicht mehr nur Options +const SfxItemPropertyMap* lcl_GetDocOptPropertyMap() +{ + static SfxItemPropertyMap aDocOptPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNO_APPLYFMDES), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_AREALINKS), 0, &getCppuType((uno::Reference<sheet::XAreaLinks>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_AUTOCONTFOC), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_BASICLIBRARIES),0, &getCppuType((uno::Reference< script::XLibraryContainer >*)0), beans::PropertyAttribute::READONLY,0}, + {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), 0, &getCppuType((lang::Locale*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_COLLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_DDELINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_FORBIDDEN), 0, &getCppuType((uno::Reference<i18n::XForbiddenCharacters>*)0), beans::PropertyAttribute::READONLY,0}, + {MAP_CHAR_LEN(SC_UNO_HASDRAWPAGES), 0, &getBooleanCppuType(), beans::PropertyAttribute::READONLY,0}, + {MAP_CHAR_LEN(SC_UNO_IGNORECASE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ITERENABLED), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), 0, &getCppuType((double*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_NAMEDRANGES), 0, &getCppuType((uno::Reference<sheet::XNamedRanges>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_DATABASERNG), 0, &getCppuType((uno::Reference<sheet::XDatabaseRanges>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_NULLDATE), 0, &getCppuType((util::Date*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ROWLABELRNG), 0, &getCppuType((uno::Reference<sheet::XLabelRanges>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SHEETLINKS), 0, &getCppuType((uno::Reference<container::XNameAccess>*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), 0, &getBooleanCppuType(), 0,0}, + + {0,0,0,0,0,0} + }; + return aDocOptPropertyMap_Impl; +} + +//! StandardDecimals als Property und vom NumberFormatter ???????? + +const SfxItemPropertyMap* lcl_GetColumnsPropertyMap() +{ + static SfxItemPropertyMap aColumnsPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_OWIDTH), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLWID), 0, &getCppuType((sal_Int32*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aColumnsPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetRowsPropertyMap() +{ + static SfxItemPropertyMap aRowsPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_CELLHGT), 0, &getCppuType((sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLFILT), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_OHEIGHT), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_MANPAGE), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_NEWPAGE), 0, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVIS), 0, &getBooleanCppuType(), 0, 0 }, + {0,0,0,0,0,0} + }; + return aRowsPropertyMap_Impl; +} + +//! move these functions to a header file +inline long TwipsToHMM(long nTwips) { return (nTwips * 127 + 36) / 72; } +inline long HMMToTwips(long nHMM) { return (nHMM * 72 + 63) / 127; } + +//------------------------------------------------------------------------ + +#define SCMODELOBJ_SERVICE "com.sun.star.sheet.SpreadsheetDocument" +#define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings" +#define SCDOC_SERVICE "com.sun.star.document.OfficeDocument" + +SC_SIMPLE_SERVICE_INFO( ScAnnotationsObj, "ScAnnotationsObj", "com.sun.star.sheet.CellAnnotations" ) +SC_SIMPLE_SERVICE_INFO( ScDrawPagesObj, "ScDrawPagesObj", "com.sun.star.drawing.DrawPages" ) +SC_SIMPLE_SERVICE_INFO( ScScenariosObj, "ScScenariosObj", "com.sun.star.sheet.Scenarios" ) +SC_SIMPLE_SERVICE_INFO( ScSpreadsheetSettingsObj, "ScSpreadsheetSettingsObj", "com.sun.star.sheet.SpreadsheetDocumentSettings" ) +SC_SIMPLE_SERVICE_INFO( ScTableColumnsObj, "ScTableColumnsObj", "com.sun.star.table.TableColumns" ) +SC_SIMPLE_SERVICE_INFO( ScTableRowsObj, "ScTableRowsObj", "com.sun.star.table.TableRows" ) +SC_SIMPLE_SERVICE_INFO( ScTableSheetsObj, "ScTableSheetsObj", "com.sun.star.sheet.Spreadsheets" ) + +//------------------------------------------------------------------------ + +String lcl_ColumnToString( USHORT nCol ) //! irgendwo global ??? +{ + if ( nCol < 26 ) + return String( (sal_Unicode) ( 'A' + nCol ) ); + else if ( nCol <= MAXCOL ) + { + String aStr( (sal_Unicode) ( 'A' + ( nCol / 26 ) - 1 ) ); + aStr += (sal_Unicode) ( 'A' + ( nCol % 26 ) ); + return aStr; + } + return '*'; //! oder #REF oder so ?? +} + +BOOL lcl_StringToColumn( const String& rStr, USHORT& rCol ) //! irgendwo global ??? +{ + BOOL bOk = FALSE; + sal_Unicode c = rStr.GetChar(0); + if (CharClass::isAsciiAlpha(c)) + { + USHORT nResult = toupper((sal_Char)c) - 'A'; + c = rStr.GetChar(1); + if (CharClass::isAsciiAlpha(c)) + nResult = ((nResult + 1) * 26) + (toupper((sal_Char)c) - 'A'); + if (nResult <= MAXCOL) + { + rCol = nResult; + bOk = TRUE; + } + } + return bOk; +} + +//------------------------------------------------------------------------ + +// static +void ScModelObj::CreateAndSet(ScDocShell* pDocSh) +{ + if (pDocSh) + pDocSh->SetBaseModel( new ScModelObj(pDocSh) ); +} + +ScModelObj::ScModelObj( ScDocShell* pDocSh ) : + SfxBaseModel( pDocSh ), + aPropSet( lcl_GetDocOptPropertyMap() ), + pDocShell( pDocSh ), + pPrintFuncCache( NULL ) +{ + // pDocShell may be NULL if this is the base of a ScDocOptionsObj + if ( pDocShell ) + { + pDocShell->GetDocument()->AddUnoObject(*this); // SfxModel is derived from SfxListener + + // setDelegator veraendert den RefCount, darum eine Referenz selber halten + // (direkt am m_refCount, um sich beim release nicht selbst zu loeschen) + ::comphelper::increment( m_refCount ); + + // waehrend des queryInterface braucht man ein Ref auf das + // SvNumberFormatsSupplierObj, sonst wird es geloescht. + uno::Reference<util::XNumberFormatsSupplier> xFormatter = new SvNumberFormatsSupplierObj( + pDocShell->GetDocument()->GetFormatTable() ); + { + xNumberAgg = uno::Reference<uno::XAggregation>( xFormatter, uno::UNO_QUERY ); + // extra block to force deletion of the temporary before setDelegator + } + + // beim setDelegator darf die zusaetzliche Ref nicht mehr existieren + xFormatter = NULL; + + if (xNumberAgg.is()) + xNumberAgg->setDelegator( (cppu::OWeakObject*)this ); + + ::comphelper::decrement( m_refCount ); + } +} + +ScModelObj::~ScModelObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + + if (xNumberAgg.is()) + xNumberAgg->setDelegator(uno::Reference<uno::XInterface>()); +} + +ScDocument* ScModelObj::GetDocument() const +{ + if (pDocShell) + return pDocShell->GetDocument(); + return NULL; +} + +SvEmbeddedObject* ScModelObj::GetEmbeddedObject() const +{ + return pDocShell; +} + +BOOL ScModelObj::AdjustRowHeight( USHORT nStartRow, USHORT nEndRow, USHORT nTab ) +{ + if (pDocShell) + return pDocShell->AdjustRowHeight( nStartRow, nEndRow, nTab ); + return FALSE; +} + +void ScModelObj::BeforeXMLLoading() +{ + if (pDocShell) + pDocShell->BeforeXMLLoading(); +} + +void ScModelObj::AfterXMLLoading(sal_Bool bRet) +{ + if (pDocShell) + pDocShell->AfterXMLLoading(bRet); +} + +uno::Any SAL_CALL ScModelObj::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( sheet::XSpreadsheetDocument ) + SC_QUERYINTERFACE( document::XActionLockable ) + SC_QUERYINTERFACE( sheet::XCalculatable ) + SC_QUERYINTERFACE( util::XProtectable ) + SC_QUERYINTERFACE( drawing::XDrawPagesSupplier ) + SC_QUERYINTERFACE( sheet::XGoalSeek ) + SC_QUERYINTERFACE( sheet::XConsolidatable ) + SC_QUERYINTERFACE( sheet::XDocumentAuditing ) + SC_QUERYINTERFACE( style::XStyleFamiliesSupplier ) + SC_QUERYINTERFACE( view::XRenderable ) + SC_QUERYINTERFACE( document::XLinkTargetSupplier ) + SC_QUERYINTERFACE( beans::XPropertySet ) + SC_QUERYINTERFACE( lang::XMultiServiceFactory ) + SC_QUERYINTERFACE( lang::XUnoTunnel ) + SC_QUERYINTERFACE( lang::XServiceInfo ) + + uno::Any aRet = SfxBaseModel::queryInterface( rType ); + if ( !aRet.hasValue() && xNumberAgg.is() ) + aRet = xNumberAgg->queryAggregation( rType ); + + return aRet; +} + +void SAL_CALL ScModelObj::acquire() throw() +{ + SfxBaseModel::acquire(); +} + +void SAL_CALL ScModelObj::release() throw() +{ + SfxBaseModel::release(); +} + +uno::Sequence<uno::Type> SAL_CALL ScModelObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = SfxBaseModel::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + uno::Sequence<uno::Type> aAggTypes; + if ( xNumberAgg.is() ) + { + const uno::Type& rProvType = ::getCppuType((uno::Reference<lang::XTypeProvider>*) 0); + uno::Any aNumProv = xNumberAgg->queryAggregation(rProvType); + if(aNumProv.getValueType() == rProvType) + { + uno::Reference<lang::XTypeProvider> xNumProv = + *(uno::Reference<lang::XTypeProvider>*)aNumProv.getValue(); + aAggTypes = xNumProv->getTypes(); + } + } + long nAggLen = aAggTypes.getLength(); + const uno::Type* pAggPtr = aAggTypes.getConstArray(); + + const long nThisLen = 15; + aTypes.realloc( nParentLen + nAggLen + nThisLen ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<sheet::XSpreadsheetDocument>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<document::XActionLockable>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<sheet::XCalculatable>*)0); + pPtr[nParentLen + 3] = getCppuType((const uno::Reference<util::XProtectable>*)0); + pPtr[nParentLen + 4] = getCppuType((const uno::Reference<drawing::XDrawPagesSupplier>*)0); + pPtr[nParentLen + 5] = getCppuType((const uno::Reference<sheet::XGoalSeek>*)0); + pPtr[nParentLen + 6] = getCppuType((const uno::Reference<sheet::XConsolidatable>*)0); + pPtr[nParentLen + 7] = getCppuType((const uno::Reference<sheet::XDocumentAuditing>*)0); + pPtr[nParentLen + 8] = getCppuType((const uno::Reference<style::XStyleFamiliesSupplier>*)0); + pPtr[nParentLen + 9] = getCppuType((const uno::Reference<view::XRenderable>*)0); + pPtr[nParentLen +10] = getCppuType((const uno::Reference<document::XLinkTargetSupplier>*)0); + pPtr[nParentLen +11] = getCppuType((const uno::Reference<beans::XPropertySet>*)0); + pPtr[nParentLen +12] = getCppuType((const uno::Reference<lang::XMultiServiceFactory>*)0); + pPtr[nParentLen +13] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0); + pPtr[nParentLen +14] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0); + + long i; + for (i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + + for (i=0; i<nAggLen; i++) + pPtr[nParentLen+nThisLen+i] = pAggPtr[i]; // aggregated types last + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScModelObj::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +void ScModelObj::Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) +{ + // Not interested in reference update hints here + + if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + { + pDocShell = NULL; // has become invalid + if (xNumberAgg.is()) + { + SvNumberFormatsSupplierObj* pNumFmt = + SvNumberFormatsSupplierObj::getImplementation( + uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) ); + if ( pNumFmt ) + pNumFmt->SetNumberFormatter( NULL ); + } + } + } + else if ( rHint.ISA( ScPointerChangedHint ) ) + { + USHORT nFlags = ((const ScPointerChangedHint&)rHint).GetFlags(); + if (nFlags & SC_POINTERCHANGED_NUMFMT) + { + // NumberFormatter-Pointer am Uno-Objekt neu setzen + + if (xNumberAgg.is()) + { + SvNumberFormatsSupplierObj* pNumFmt = + SvNumberFormatsSupplierObj::getImplementation( + uno::Reference<util::XNumberFormatsSupplier>(xNumberAgg, uno::UNO_QUERY) ); + if ( pNumFmt && pDocShell ) + pNumFmt->SetNumberFormatter( pDocShell->GetDocument()->GetFormatTable() ); + } + } + } + else + SfxBaseModel::Notify( rBC, rHint ); // SfxBaseModel is derived from SfxListener +} + +// XSpreadsheetDocument + +uno::Reference<sheet::XSpreadsheets> SAL_CALL ScModelObj::getSheets() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScTableSheetsObj(pDocShell); + return NULL; +} + +// XStyleFamiliesSupplier + +uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getStyleFamilies() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScStyleFamiliesObj(pDocShell); + return NULL; +} + +// XRenderable + +sal_Int32 SAL_CALL ScModelObj::getRendererCount( const uno::Any& /*aSelection*/, + const uno::Sequence<beans::PropertyValue>& /*xOptions*/ ) + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + OSL_FAIL("Strip!"); + return 0; +} + +uno::Sequence<beans::PropertyValue> SAL_CALL ScModelObj::getRenderer( sal_Int32 /*nRenderer*/, + const uno::Any& /*aSelection*/, const uno::Sequence<beans::PropertyValue>& /*xOptions*/ ) + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + OSL_FAIL("Strip!"); + uno::Sequence<beans::PropertyValue> aSequence; + return aSequence; +} + +void SAL_CALL ScModelObj::render( sal_Int32 /*nRenderer*/, const uno::Any& /*aSelection*/, + const uno::Sequence<beans::PropertyValue>& /*rOptions*/ ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + OSL_FAIL("Strip!"); +} + +// XLinkTargetSupplier + +uno::Reference<container::XNameAccess> SAL_CALL ScModelObj::getLinks() throw(uno::RuntimeException) +{ + return NULL; +} + +// XActionLockable + +sal_Bool SAL_CALL ScModelObj::isActionLocked() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bLocked = FALSE; + if (pDocShell) + bLocked = ( pDocShell->GetLockCount() != 0 ); + return bLocked; +} + +void SAL_CALL ScModelObj::addActionLock() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + pDocShell->LockDocument(); +} + +void SAL_CALL ScModelObj::removeActionLock() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + pDocShell->UnlockDocument(); +} + +void SAL_CALL ScModelObj::setActionLocks( sal_Int16 nLock ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + pDocShell->SetLockCount(nLock); +} + +sal_Int16 SAL_CALL ScModelObj::resetActionLocks() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nRet = 0; + if (pDocShell) + { + nRet = pDocShell->GetLockCount(); + pDocShell->SetLockCount(0); + } + return nRet; +} + +void SAL_CALL ScModelObj::lockControllers() throw (::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SfxBaseModel::lockControllers(); + if (pDocShell) + pDocShell->LockPaint(); +} + +void SAL_CALL ScModelObj::unlockControllers() throw (::com::sun::star::uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (hasControllersLocked()) + { + SfxBaseModel::unlockControllers(); + if (pDocShell) + pDocShell->UnlockPaint(); + } +} + +// XCalculate + +void SAL_CALL ScModelObj::calculate() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pDocShell) + OSL_FAIL("keine DocShell"); //! Exception oder so? +} + +void SAL_CALL ScModelObj::calculateAll() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + pDocShell->DoHardRecalc(TRUE); + else + OSL_FAIL("keine DocShell"); //! Exception oder so? +} + +sal_Bool SAL_CALL ScModelObj::isAutomaticCalculationEnabled() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return pDocShell->GetDocument()->GetAutoCalc(); + + OSL_FAIL("keine DocShell"); //! Exception oder so? + return FALSE; +} + +void SAL_CALL ScModelObj::enableAutomaticCalculation( sal_Bool bEnabled ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if ( pDoc->GetAutoCalc() != bEnabled ) + { + pDoc->SetAutoCalc( bEnabled ); + pDocShell->SetDocumentModified(); + } + } + else + OSL_FAIL("keine DocShell"); //! Exception oder so? +} + +// XProtectable + +void SAL_CALL ScModelObj::protect( const ::rtl::OUString& aPassword ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + String aString = aPassword; + + ScDocFunc aFunc(*pDocShell); + aFunc.Protect( TABLEID_DOC, aString, TRUE ); + } +} + +void SAL_CALL ScModelObj::unprotect( const ::rtl::OUString& aPassword ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + String aString = aPassword; + + ScDocFunc aFunc(*pDocShell); + aFunc.Unprotect( TABLEID_DOC, aString, TRUE ); + + //! Rueckgabewert auswerten, Exception oder so + } +} + +sal_Bool SAL_CALL ScModelObj::isProtected() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return pDocShell->GetDocument()->IsDocProtected(); + + OSL_FAIL("keine DocShell"); //! Exception oder so? + return FALSE; +} + +// XDrawPagesSupplier + +uno::Reference<drawing::XDrawPages> SAL_CALL ScModelObj::getDrawPages() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScDrawPagesObj(pDocShell); + + OSL_FAIL("keine DocShell"); //! Exception oder so? + return NULL; +} + +// XGoalSeek + +sheet::GoalResult SAL_CALL ScModelObj::seekGoal( + const table::CellAddress& aFormulaPosition, + const table::CellAddress& aVariablePosition, + const ::rtl::OUString& aGoalValue ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + sheet::GoalResult aResult; + aResult.Divergence = DBL_MAX; // nichts gefunden + if (pDocShell) + { + WaitObject aWait( pDocShell->GetDialogParent() ); + String aGoalString = aGoalValue; + ScDocument* pDoc = pDocShell->GetDocument(); + double fValue = 0.0; + BOOL bFound = pDoc->Solver( + (USHORT)aFormulaPosition.Column, (USHORT)aFormulaPosition.Row, aFormulaPosition.Sheet, + (USHORT)aVariablePosition.Column, (USHORT)aVariablePosition.Row, aVariablePosition.Sheet, + aGoalString, fValue ); + aResult.Result = fValue; + if (bFound) + aResult.Divergence = 0.0; //! das ist gelogen + } + return aResult; +} + +// XConsolidatable + +uno::Reference<sheet::XConsolidationDescriptor> SAL_CALL ScModelObj::createConsolidationDescriptor( + sal_Bool bEmpty ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScConsolidationDescriptor* pNew = new ScConsolidationDescriptor; + if ( pDocShell && !bEmpty ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + const ScConsolidateParam* pParam = pDoc->GetConsolidateDlgData(); + if (pParam) + pNew->SetParam( *pParam ); + } + return pNew; +} + +void SAL_CALL ScModelObj::consolidate( + const uno::Reference<sheet::XConsolidationDescriptor>& xDescriptor ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // das koennte theoretisch ein fremdes Objekt sein, also nur das + // oeffentliche XConsolidationDescriptor Interface benutzen, um + // die Daten in ein ScConsolidationDescriptor Objekt zu kopieren: + //! wenn es schon ein ScConsolidationDescriptor ist, direkt per getImplementation? + + ScConsolidationDescriptor aImpl; + aImpl.setFunction( xDescriptor->getFunction() ); + aImpl.setSources( xDescriptor->getSources() ); + aImpl.setStartOutputPosition( xDescriptor->getStartOutputPosition() ); + aImpl.setUseColumnHeaders( xDescriptor->getUseColumnHeaders() ); + aImpl.setUseRowHeaders( xDescriptor->getUseRowHeaders() ); + aImpl.setInsertLinks( xDescriptor->getInsertLinks() ); + + if (pDocShell) + { + const ScConsolidateParam& rParam = aImpl.GetParam(); + pDocShell->DoConsolidate( rParam, TRUE ); + pDocShell->GetDocument()->SetConsolidateDlgData( &rParam ); + } +} + +// XDocumentAuditing + +void SAL_CALL ScModelObj::refreshArrows() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocFunc aFunc(*pDocShell); + aFunc.DetectiveRefresh(); + } +} + +// XViewDataSupplier +uno::Reference< container::XIndexAccess > SAL_CALL ScModelObj::getViewData( ) + throw (uno::RuntimeException) +{ + uno::Reference < container::XIndexAccess > xRet( SfxBaseModel::getViewData() ); + + if( !xRet.is() ) + { + SolarMutexGuard aGuard; + if (pDocShell && pDocShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED) + { + xRet = uno::Reference < container::XIndexAccess >::query(::legacy_binfilters::getLegacyProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues")))); + + uno::Reference < container::XIndexContainer > xCont( xRet, uno::UNO_QUERY ); + DBG_ASSERT( xCont.is(), "ScModelObj::getViewData() failed for OLE object" ); + if( xCont.is() ) + { + uno::Sequence< beans::PropertyValue > aSeq; + aSeq.realloc(1); + String sName; + pDocShell->GetDocument()->GetName( pDocShell->GetDocument()->GetVisibleTab(), sName ); + ::rtl::OUString sOUName(sName); + aSeq[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SC_ACTIVETABLE)); + aSeq[0].Value <<= sOUName; + xCont->insertByIndex( 0, uno::makeAny( aSeq ) ); + } + } + else if ( pDocShell ) + { + // #116578# Convert manually loaded state from sfx window data + // into view data sequence + + String aUserData = pDocShell->GetUserData(); + if ( aUserData.Len() ) + { + ScViewData aLocalViewData( pDocShell ); + aLocalViewData.ReadUserData( aUserData ); + uno::Sequence< beans::PropertyValue > aSeq; + aLocalViewData.WriteUserDataSequence( aSeq ); + + xRet = uno::Reference < container::XIndexAccess >::query(::legacy_binfilters::getLegacyProcessServiceFactory()->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.IndexedPropertyValues")))); + uno::Reference < container::XIndexContainer > xCont( xRet, uno::UNO_QUERY ); + if( xCont.is() ) + xCont->insertByIndex( 0, uno::makeAny( aSeq ) ); + } + } + } + + return xRet; +} + +// XPropertySet (Doc-Optionen) +//! auch an der Applikation anbieten? + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScModelObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScModelObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + const ScDocOptions& rOldOpt = pDoc->GetDocOptions(); + ScDocOptions aNewOpt = rOldOpt; + + BOOL bOpt = ScDocOptionsHelper::setPropertyValue( aNewOpt, aPropertyName, aValue ); + if (bOpt) + { + // done... + } + else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) ) + { + lang::Locale aLocale; + if ( aValue >>= aLocale ) + { + LanguageType eLatin, eCjk, eCtl; + pDoc->GetLanguage( eLatin, eCjk, eCtl ); + eLatin = ScUnoConversion::GetLanguage(aLocale); + pDoc->SetLanguage( eLatin, eCjk, eCtl ); + } + } + else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) ) + { + lang::Locale aLocale; + if ( aValue >>= aLocale ) + { + LanguageType eLatin, eCjk, eCtl; + pDoc->GetLanguage( eLatin, eCjk, eCtl ); + eCjk = ScUnoConversion::GetLanguage(aLocale); + pDoc->SetLanguage( eLatin, eCjk, eCtl ); + } + } + else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) ) + { + lang::Locale aLocale; + if ( aValue >>= aLocale ) + { + LanguageType eLatin, eCjk, eCtl; + pDoc->GetLanguage( eLatin, eCjk, eCtl ); + eCtl = ScUnoConversion::GetLanguage(aLocale); + pDoc->SetLanguage( eLatin, eCjk, eCtl ); + } + } + else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) ) + { + // model is created if not there + ScDrawLayer* pModel = pDocShell->MakeDrawLayer(); + pModel->SetOpenInDesignMode( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + + } + else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) ) + { + // model is created if not there + ScDrawLayer* pModel = pDocShell->MakeDrawLayer(); + pModel->SetAutoControlFocus( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + + } + + if ( aNewOpt != rOldOpt ) + { + pDoc->SetDocOptions( aNewOpt ); + pDocShell->DoHardRecalc( TRUE ); //! Recalc nur bei entsprechenden Optionen? + pDocShell->SetDocumentModified(); + } + } +} + +uno::Any SAL_CALL ScModelObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + uno::Any aRet; + + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + const ScDocOptions& rOpt = pDoc->GetDocOptions(); + aRet = ScDocOptionsHelper::getPropertyValue( rOpt, aPropertyName ); + if ( aRet.hasValue() ) + { + // done... + } + else if ( aString.EqualsAscii( SC_UNONAME_CLOCAL ) ) + { + LanguageType eLatin, eCjk, eCtl; + pDoc->GetLanguage( eLatin, eCjk, eCtl ); + + lang::Locale aLocale; + ScUnoConversion::FillLocale( aLocale, eLatin ); + aRet <<= aLocale; + } + else if ( aString.EqualsAscii( SC_UNO_CJK_CLOCAL ) ) + { + LanguageType eLatin, eCjk, eCtl; + pDoc->GetLanguage( eLatin, eCjk, eCtl ); + + lang::Locale aLocale; + ScUnoConversion::FillLocale( aLocale, eCjk ); + aRet <<= aLocale; + } + else if ( aString.EqualsAscii( SC_UNO_CTL_CLOCAL ) ) + { + LanguageType eLatin, eCjk, eCtl; + pDoc->GetLanguage( eLatin, eCjk, eCtl ); + + lang::Locale aLocale; + ScUnoConversion::FillLocale( aLocale, eCtl ); + aRet <<= aLocale; + } + else if ( aString.EqualsAscii( SC_UNO_NAMEDRANGES ) ) + { + uno::Reference<sheet::XNamedRanges> xRanges = new ScNamedRangesObj( pDocShell ); + aRet <<= xRanges; + } + else if ( aString.EqualsAscii( SC_UNO_DATABASERNG ) ) + { + uno::Reference<sheet::XDatabaseRanges> xRanges = new ScDatabaseRangesObj( pDocShell ); + aRet <<= xRanges; + } + else if ( aString.EqualsAscii( SC_UNO_COLLABELRNG ) ) + { + uno::Reference<sheet::XLabelRanges> xRanges = new ScLabelRangesObj( pDocShell, TRUE ); + aRet <<= xRanges; + } + else if ( aString.EqualsAscii( SC_UNO_ROWLABELRNG ) ) + { + uno::Reference<sheet::XLabelRanges> xRanges = new ScLabelRangesObj( pDocShell, FALSE ); + aRet <<= xRanges; + } + else if ( aString.EqualsAscii( SC_UNO_AREALINKS ) ) + { + uno::Reference<sheet::XAreaLinks> xLinks = new ScAreaLinksObj( pDocShell ); + aRet <<= xLinks; + } + else if ( aString.EqualsAscii( SC_UNO_DDELINKS ) ) + { + uno::Reference<container::XNameAccess> xLinks = new ScDDELinksObj( pDocShell ); + aRet <<= xLinks; + } + else if ( aString.EqualsAscii( SC_UNO_SHEETLINKS ) ) + { + uno::Reference<container::XNameAccess> xLinks = new ScSheetLinksObj( pDocShell ); + aRet <<= xLinks; + } + else if ( aString.EqualsAscii( SC_UNO_APPLYFMDES ) ) + { + // default for no model is TRUE + ScDrawLayer* pModel = pDoc->GetDrawLayer(); + sal_Bool bOpenInDesign = pModel ? pModel->GetOpenInDesignMode() : sal_True; + ScUnoHelpFunctions::SetBoolInAny( aRet, bOpenInDesign ); + } + else if ( aString.EqualsAscii( SC_UNO_AUTOCONTFOC ) ) + { + // default for no model is FALSE + ScDrawLayer* pModel = pDoc->GetDrawLayer(); + sal_Bool bAutoControlFocus = pModel ? pModel->GetAutoControlFocus() : sal_False; + ScUnoHelpFunctions::SetBoolInAny( aRet, bAutoControlFocus ); + } + else if ( aString.EqualsAscii( SC_UNO_FORBIDDEN ) ) + { + uno::Reference<i18n::XForbiddenCharacters> xForbidden = new ScForbiddenCharsObj( pDocShell ); + aRet <<= xForbidden; + } + else if ( aString.EqualsAscii( SC_UNO_HASDRAWPAGES ) ) + { + ScUnoHelpFunctions::SetBoolInAny( aRet, (pDocShell->GetDocument()->GetDrawLayer() != 0) ); + } + else if ( aString.EqualsAscii( SC_UNO_BASICLIBRARIES ) ) + { + aRet <<= pDocShell->GetBasicContainer(); + } + } + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScModelObj ) + +// XMultiServiceFactory + +uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstance( + const ::rtl::OUString& aServiceSpecifier ) + throw(uno::Exception, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<uno::XInterface> xRet; + String aNameStr = aServiceSpecifier; + USHORT nType = ScServiceProvider::GetProviderType(aNameStr); + if ( nType != SC_SERVICE_INVALID ) + { + // drawing layer tables must be kept as long as the model is alive + // return stored instance if already set + switch ( nType ) + { + case SC_SERVICE_GRADTAB: xRet = xDrawGradTab; break; + case SC_SERVICE_HATCHTAB: xRet = xDrawHatchTab; break; + case SC_SERVICE_BITMAPTAB: xRet = xDrawBitmapTab; break; + case SC_SERVICE_TRGRADTAB: xRet = xDrawTrGradTab; break; + case SC_SERVICE_MARKERTAB: xRet = xDrawMarkerTab; break; + case SC_SERVICE_DASHTAB: xRet = xDrawDashTab; break; + } + + if ( !xRet.is() ) + { + xRet = ScServiceProvider::MakeInstance( nType, pDocShell ); + + // store created instance + switch ( nType ) + { + case SC_SERVICE_GRADTAB: xDrawGradTab = xRet; break; + case SC_SERVICE_HATCHTAB: xDrawHatchTab = xRet; break; + case SC_SERVICE_BITMAPTAB: xDrawBitmapTab = xRet; break; + case SC_SERVICE_TRGRADTAB: xDrawTrGradTab = xRet; break; + case SC_SERVICE_MARKERTAB: xDrawMarkerTab = xRet; break; + case SC_SERVICE_DASHTAB: xDrawDashTab = xRet; break; + } + } + } + else + { + // alles was ich nicht kenn, werf ich der SvxFmMSFactory an den Hals, + // da wird dann 'ne Exception geworfen, wenn's nicht passt... + + { + xRet = SvxFmMSFactory::createInstance(aServiceSpecifier); + // extra block to force deletion of the temporary before ScShapeObj ctor (setDelegator) + } + + // #96117# if the drawing factory created a shape, a ScShapeObj has to be used + // to support own properties like ImageMap: + + uno::Reference<drawing::XShape> xShape( xRet, uno::UNO_QUERY ); + if ( xShape.is() ) + { + xRet.clear(); // for aggregation, xShape must be the object's only ref + new ScShapeObj( xShape ); // aggregates object and modifies xShape + xRet = xShape; + } + } + return xRet; +} + +uno::Reference<uno::XInterface> SAL_CALL ScModelObj::createInstanceWithArguments( + const ::rtl::OUString& ServiceSpecifier, + const uno::Sequence<uno::Any>& /*Arguments*/ ) + throw(uno::Exception, uno::RuntimeException) +{ + //! unterscheiden zwischen eigenen Services und denen vom Drawing-Layer? + + SolarMutexGuard aGuard; + uno::Reference<uno::XInterface> xInt = createInstance(ServiceSpecifier); + //die Any-Sequence dient zur Initialisierung von Objekten, die auf + //Parameter zwingend angewiesen sind - bis jetzt haben wir das nicht + return xInt; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScModelObj::getAvailableServiceNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! warum sind die Parameter bei concatServiceNames nicht const ??? + //! return concatServiceNames( ScServiceProvider::GetAllServiceNames(), + //! SvxFmMSFactory::getAvailableServiceNames() ); + + uno::Sequence< ::rtl::OUString> aMyServices = ScServiceProvider::GetAllServiceNames(); + uno::Sequence< ::rtl::OUString> aDrawServices = SvxFmMSFactory::getAvailableServiceNames(); + + return concatServiceNames( aMyServices, aDrawServices ); +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScModelObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScModelObj" )); +} + +sal_Bool SAL_CALL ScModelObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr = rServiceName; + return aServiceStr.EqualsAscii( SCMODELOBJ_SERVICE ) || + aServiceStr.EqualsAscii( SCDOCSETTINGS_SERVICE ) || + aServiceStr.EqualsAscii( SCDOC_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScModelObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(3); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCMODELOBJ_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCDOCSETTINGS_SERVICE )); + pArray[2] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCDOC_SERVICE )); + return aRet; +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScModelObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + + // aggregated number formats supplier has XUnoTunnel, too + // interface from aggregated object must be obtained via queryAggregation + + if ( xNumberAgg.is() ) + { + const uno::Type& rTunnelType = ::getCppuType((uno::Reference<lang::XUnoTunnel>*) 0); + uno::Any aNumTunnel = xNumberAgg->queryAggregation(rTunnelType); + if(aNumTunnel.getValueType() == rTunnelType) + { + uno::Reference<lang::XUnoTunnel> xTunnelAgg = + *(uno::Reference<lang::XUnoTunnel>*)aNumTunnel.getValue(); + return xTunnelAgg->getSomething( rId ); + } + } + + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScModelObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScModelObj* ScModelObj::getImplementation( const uno::Reference<uno::XInterface> xObj ) +{ + ScModelObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScModelObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + + +ScDrawPagesObj::ScDrawPagesObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDrawPagesObj::~ScDrawPagesObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDrawPagesObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +uno::Reference<drawing::XDrawPage> ScDrawPagesObj::GetObjectByIndex_Impl(INT32 nIndex) const +{ + if (pDocShell) + { + ScDrawLayer* pDrawLayer = pDocShell->MakeDrawLayer(); + DBG_ASSERT(pDrawLayer,"kann Draw-Layer nicht anlegen"); + if ( pDrawLayer && nIndex >= 0 && nIndex < pDocShell->GetDocument()->GetTableCount() ) + { + SdrPage* pPage = pDrawLayer->GetPage((USHORT)nIndex); + DBG_ASSERT(pPage,"Draw-Page nicht gefunden"); + if (pPage) + { + return uno::Reference<drawing::XDrawPage> (pPage->getUnoPage(), uno::UNO_QUERY); + } + } + } + return NULL; +} + +// XDrawPages + +uno::Reference<drawing::XDrawPage> SAL_CALL ScDrawPagesObj::insertNewByIndex( sal_Int32 nPos ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<drawing::XDrawPage> xRet; + if (pDocShell) + { + String aNewName; + pDocShell->GetDocument()->CreateValidTabName(aNewName); + ScDocFunc aFunc(*pDocShell); + if ( aFunc.InsertTable( (USHORT)nPos, aNewName, TRUE, TRUE ) ) + xRet = GetObjectByIndex_Impl( nPos ); + } + return xRet; +} + +void SAL_CALL ScDrawPagesObj::remove( const uno::Reference<drawing::XDrawPage>& xPage ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SvxDrawPage* pImp = SvxDrawPage::getImplementation( xPage ); + if ( pDocShell && pImp ) + { + SdrPage* pPage = pImp->GetSdrPage(); + if (pPage) + { + pPage->GetPageNum(); + } + } +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScDrawPagesObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return pDocShell->GetDocument()->GetTableCount(); + return 0; +} + +uno::Any SAL_CALL ScDrawPagesObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<drawing::XDrawPage> xPage = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xPage.is()) + aAny <<= xPage; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScDrawPagesObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<drawing::XDrawPage>*)0); +} + +sal_Bool SAL_CALL ScDrawPagesObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +ScTableSheetsObj::ScTableSheetsObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScTableSheetsObj::~ScTableSheetsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScTableSheetsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XSpreadsheets + +ScTableSheetObj* ScTableSheetsObj::GetObjectByIndex_Impl(USHORT nIndex) const +{ + if ( pDocShell && nIndex < pDocShell->GetDocument()->GetTableCount() ) + return new ScTableSheetObj( pDocShell, nIndex ); + + return NULL; +} + +ScTableSheetObj* ScTableSheetsObj::GetObjectByName_Impl(const ::rtl::OUString& aName) const +{ + if (pDocShell) + { + USHORT nIndex; + String aString = aName; + if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) ) + return new ScTableSheetObj( pDocShell, nIndex ); + } + return NULL; +} + +void SAL_CALL ScTableSheetsObj::insertNewByName( const ::rtl::OUString& aName, sal_Int16 nPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + String aNamStr = aName; + ScDocFunc aFunc(*pDocShell); + bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE ); + } + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScTableSheetsObj::moveByName( const ::rtl::OUString& aName, sal_Int16 ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + String aNamStr = aName; + USHORT nSource; + if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) ) + bDone = TRUE; + } + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScTableSheetsObj::copyByName( const ::rtl::OUString& aName, + const ::rtl::OUString& aCopy, sal_Int16 nDestination ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + String aNamStr = aName; + String aNewStr = aCopy; + USHORT nSource; + if ( pDocShell->GetDocument()->GetTable( aNamStr, nSource ) ) + { + ScDocFunc aFunc(*pDocShell); + bDone = aFunc.RenameTable( nDestination, aNewStr, TRUE, TRUE ); + } + } + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScTableSheetsObj::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::ElementExistException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + BOOL bIllArg = FALSE; + + //! Type of aElement can be some specific interface instead of XInterface + + uno::Reference<uno::XInterface> xInterface; + if ( pDocShell ) + { + if ( aElement >>= xInterface ) + { + ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface ); + if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt? + { + ScDocument* pDoc = pDocShell->GetDocument(); + String aNamStr = aName; + USHORT nDummy; + if ( pDoc->GetTable( aNamStr, nDummy ) ) + { + // name already exists + throw container::ElementExistException(); + } + else + { + USHORT nPosition = pDoc->GetTableCount(); + ScDocFunc aFunc(*pDocShell); + bDone = aFunc.InsertTable( nPosition, aNamStr, TRUE, TRUE ); + if (bDone) + pSheetObj->InitInsertSheet( pDocShell, nPosition ); + // Dokument und neuen Range am Objekt setzen + } + } + else + bIllArg = TRUE; + } + else + bIllArg = TRUE; + } + + if (!bDone) + { + if (bIllArg) + throw lang::IllegalArgumentException(); + else + throw uno::RuntimeException(); // ElementExistException is handled above + } +} + +void SAL_CALL ScTableSheetsObj::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + BOOL bIllArg = FALSE; + + //! Type of aElement can be some specific interface instead of XInterface + + uno::Reference<uno::XInterface> xInterface; + if ( pDocShell ) + { + if ( aElement >>= xInterface ) + { + ScTableSheetObj* pSheetObj = ScTableSheetObj::getImplementation( xInterface ); + if ( pSheetObj && !pSheetObj->GetDocShell() ) // noch nicht eingefuegt? + { + String aNamStr = aName; + USHORT nPosition; + if ( !pDocShell->GetDocument()->GetTable( aNamStr, nPosition ) ) + { + // not found + throw container::NoSuchElementException(); + } + } + else + bIllArg = TRUE; + } + else + bIllArg = TRUE; + } + + if (!bDone) + { + if (bIllArg) + throw lang::IllegalArgumentException(); + else + throw uno::RuntimeException(); // NoSuchElementException is handled above + } +} + +void SAL_CALL ScTableSheetsObj::removeByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + USHORT nIndex; + String aString = aName; + if ( !pDocShell->GetDocument()->GetTable( aString, nIndex ) ) + { + // not found + throw container::NoSuchElementException(); + } + } + + if (!bDone) + throw uno::RuntimeException(); // NoSuchElementException is handled above +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScTableSheetsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetsEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScTableSheetsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return pDocShell->GetDocument()->GetTableCount(); + return 0; +} + +uno::Any SAL_CALL ScTableSheetsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XSpreadsheet> xSheet = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xSheet.is()) + aAny <<= xSheet; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScTableSheetsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XSpreadsheet>*)0); +} + +sal_Bool SAL_CALL ScTableSheetsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// XNameAccess + +uno::Any SAL_CALL ScTableSheetsObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XSpreadsheet> xSheet = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xSheet.is()) + aAny <<= xSheet; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScTableSheetsObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nCount = pDoc->GetTableCount(); + String aName; + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + { + pDoc->GetName( i, aName ); + pAry[i] = aName; + } + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(); +} + +sal_Bool SAL_CALL ScTableSheetsObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + USHORT nIndex; + String aString = aName; + if ( pDocShell->GetDocument()->GetTable( aString, nIndex ) ) + return TRUE; + } + return FALSE; +} + + +ScTableColumnsObj::ScTableColumnsObj(ScDocShell* pDocSh, USHORT nT, USHORT nSC, USHORT nEC) : + pDocShell( pDocSh ), + nTab ( nT ), + nStartCol( nSC ), + nEndCol ( nEC ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScTableColumnsObj::~ScTableColumnsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScTableColumnsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + + //! Referenz-Update fuer Tab und Start/Ende + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XTableColumns + +ScTableColumnObj* ScTableColumnsObj::GetObjectByIndex_Impl(USHORT nIndex) const +{ + USHORT nCol = nIndex + nStartCol; + if ( pDocShell && nCol <= nEndCol ) + return new ScTableColumnObj( pDocShell, nCol, nTab ); + + return NULL; // falscher Index +} + +ScTableColumnObj* ScTableColumnsObj::GetObjectByName_Impl(const ::rtl::OUString& aName) const +{ + USHORT nCol = 0; + String aString = aName; + if ( lcl_StringToColumn( aString, nCol ) ) + if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol ) + return new ScTableColumnObj( pDocShell, nCol, nTab ); + + return NULL; +} + +void SAL_CALL ScTableColumnsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartCol+nPosition <= nEndCol && + nStartCol+nPosition+nCount-1 <= MAXCOL ) + bDone = false; + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScTableColumnsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + // Der zu loeschende Bereich muss innerhalb des Objekts liegen + if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartCol+nIndex+nCount-1 <= nEndCol ) + bDone = true; + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScTableColumnsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableColumnsEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScTableColumnsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return nEndCol - nStartCol + 1; +} + +uno::Any SAL_CALL ScTableColumnsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<table::XCellRange> xColumn = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xColumn.is()) + aAny <<= xColumn; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScTableColumnsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<table::XCellRange>*)0); +} + +sal_Bool SAL_CALL ScTableColumnsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Any SAL_CALL ScTableColumnsObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<table::XCellRange> xColumn = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xColumn.is()) + aAny <<= xColumn; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScTableColumnsObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = nEndCol - nStartCol + 1; + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + pAry[i] = lcl_ColumnToString( nStartCol + i ); + + return aSeq; +} + +sal_Bool SAL_CALL ScTableColumnsObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCol = 0; + String aString = aName; + if ( lcl_StringToColumn( aString, nCol ) ) + if ( pDocShell && nCol >= nStartCol && nCol <= nEndCol ) + return TRUE; + + return FALSE; // nicht gefunden +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableColumnsObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( lcl_GetColumnsPropertyMap() ); + return aRef; +} + +void SAL_CALL ScTableColumnsObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pDocShell) + throw uno::RuntimeException(); + + ScDocFunc aFunc(*pDocShell); + pDocShell->GetDocument(); + USHORT nColArr[2]; + nColArr[0] = nStartCol; + nColArr[1] = nEndCol; + String aNameString = aPropertyName; + + if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) ) + { + sal_Int32 nNewWidth = 0; + if ( aValue >>= nNewWidth ) + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, SC_SIZE_ORIGINAL, + (USHORT)HMMToTwips(nNewWidth), TRUE, TRUE ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) ) + { + BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT; + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, eMode, 0, TRUE, TRUE ); + // SC_SIZE_DIRECT with size 0: hide + } + else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) ) + { + BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + if (bOpt) + aFunc.SetWidthOrHeight( TRUE, 1, nColArr, nTab, + SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH, TRUE, TRUE ); + // FALSE for columns currently has no effect + } + else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) ) + { + //! single function to set/remove all breaks? + BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + for (USHORT nCol=nStartCol; nCol<=nEndCol; nCol++) + if (!bSet) + aFunc.RemovePageBreak( TRUE, ScAddress(nCol,0,nTab), TRUE, TRUE ); + } +} + +uno::Any SAL_CALL ScTableColumnsObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pDocShell) + throw uno::RuntimeException(); + + ScDocument* pDoc = pDocShell->GetDocument(); + String aNameString = aPropertyName; + uno::Any aAny; + + //! loop over all columns for current state? + + if ( aNameString.EqualsAscii( SC_UNONAME_CELLWID ) ) + { + // for hidden column, return original height + USHORT nWidth = pDoc->GetOriginalWidth( nStartCol, nTab ); + aAny <<= (sal_Int32)TwipsToHMM(nWidth); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) ) + { + BOOL bVis = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_HIDDEN); + ScUnoHelpFunctions::SetBoolInAny( aAny, bVis ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_OWIDTH ) ) + { + BOOL bOpt = !(pDoc->GetColFlags( nStartCol, nTab ) & CR_MANUALSIZE); + ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) ) + { + BOOL bBreak = ( 0 != (pDoc->GetColFlags( nStartCol, nTab ) & (CR_PAGEBREAK|CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) ) + { + BOOL bBreak = ( 0 != (pDoc->GetColFlags( nStartCol, nTab ) & (CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak ); + } + + return aAny; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableColumnsObj ) + +//------------------------------------------------------------------------ + +ScTableRowsObj::ScTableRowsObj(ScDocShell* pDocSh, USHORT nT, USHORT nSR, USHORT nER) : + pDocShell( pDocSh ), + nTab ( nT ), + nStartRow( nSR ), + nEndRow ( nER ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScTableRowsObj::~ScTableRowsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScTableRowsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + + //! Referenz-Update fuer Tab und Start/Ende + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XTableRows + +ScTableRowObj* ScTableRowsObj::GetObjectByIndex_Impl(USHORT nIndex) const +{ + USHORT nRow = nIndex + nStartRow; + if ( pDocShell && nRow <= nEndRow ) + return new ScTableRowObj( pDocShell, nRow, nTab ); + + return NULL; // falscher Index +} + +void SAL_CALL ScTableRowsObj::insertByIndex( sal_Int32 nPosition, sal_Int32 nCount ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if ( pDocShell && nCount > 0 && nPosition >= 0 && nStartRow+nPosition <= nEndRow && + nStartRow+nPosition+nCount-1 <= MAXROW ) + bDone = false; + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScTableRowsObj::removeByIndex( sal_Int32 nIndex, sal_Int32 nCount ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + // Der zu loeschende Bereich muss innerhalb des Objekts liegen + if ( pDocShell && nCount > 0 && nIndex >= 0 && nStartRow+nIndex+nCount-1 <= nEndRow ) + bDone = true; + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScTableRowsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableRowsEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScTableRowsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return nEndRow - nStartRow + 1; +} + +uno::Any SAL_CALL ScTableRowsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<table::XCellRange> xRow = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xRow.is()) + aAny <<= xRow; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScTableRowsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<table::XCellRange>*)0); +} + +sal_Bool SAL_CALL ScTableRowsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableRowsObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( lcl_GetRowsPropertyMap() ); + return aRef; +} + +void SAL_CALL ScTableRowsObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pDocShell) + throw uno::RuntimeException(); + + ScDocFunc aFunc(*pDocShell); + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nRowArr[2]; + nRowArr[0] = nStartRow; + nRowArr[1] = nEndRow; + String aNameString = aPropertyName; + + if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) ) + { + sal_Int32 nNewHeight = 0; + if ( aValue >>= nNewHeight ) + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_ORIGINAL, + (USHORT)HMMToTwips(nNewHeight), TRUE, TRUE ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) ) + { + BOOL bVis = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + ScSizeMode eMode = bVis ? SC_SIZE_SHOW : SC_SIZE_DIRECT; + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, eMode, 0, TRUE, TRUE ); + // SC_SIZE_DIRECT with size 0: hide + } + else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) ) + { + //! undo etc. + BOOL bFil = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + for (USHORT nRow=nStartRow; nRow<=nEndRow; nRow++) + { + BYTE nFlags = pDoc->GetRowFlags(nRow, nTab); + if (bFil) + nFlags |= CR_FILTERED; + else + nFlags &= ~CR_FILTERED; + pDoc->SetRowFlags(nRow, nTab, nFlags); + } + } + else if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) ) + { + BOOL bOpt = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + if (bOpt) + aFunc.SetWidthOrHeight( FALSE, 1, nRowArr, nTab, SC_SIZE_OPTIMAL, 0, TRUE, TRUE ); + else + { + //! manually set old heights again? + } + } + else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE) || aNameString.EqualsAscii( SC_UNONAME_MANPAGE) ) + { + //! single function to set/remove all breaks? + BOOL bSet = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + for (USHORT nRow=nStartRow; nRow<=nEndRow; nRow++) + if (!bSet) + aFunc.RemovePageBreak( FALSE, ScAddress(0,nRow,nTab), TRUE, TRUE ); + } +} + +uno::Any SAL_CALL ScTableRowsObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pDocShell) + throw uno::RuntimeException(); + + ScDocument* pDoc = pDocShell->GetDocument(); + String aNameString = aPropertyName; + uno::Any aAny; + + //! loop over all rows for current state? + + if ( aNameString.EqualsAscii( SC_UNONAME_CELLHGT ) ) + { + // for hidden row, return original height + USHORT nHeight = pDoc->GetOriginalHeight( nStartRow, nTab ); + aAny <<= (sal_Int32)TwipsToHMM(nHeight); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_CELLVIS ) ) + { + BOOL bVis = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_HIDDEN); + ScUnoHelpFunctions::SetBoolInAny( aAny, bVis ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_CELLFILT ) ) + { + BOOL bVis = ((pDoc->GetRowFlags( nStartRow, nTab ) & CR_FILTERED) != 0); + ScUnoHelpFunctions::SetBoolInAny( aAny, bVis ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_OHEIGHT ) ) + { + BOOL bOpt = !(pDoc->GetRowFlags( nStartRow, nTab ) & CR_MANUALSIZE); + ScUnoHelpFunctions::SetBoolInAny( aAny, bOpt ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_NEWPAGE ) ) + { + BOOL bBreak = ( 0 != (pDoc->GetRowFlags( nStartRow, nTab ) & (CR_PAGEBREAK|CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_MANPAGE ) ) + { + BOOL bBreak = ( 0 != (pDoc->GetRowFlags( nStartRow, nTab ) & (CR_MANUALBREAK)) ); + ScUnoHelpFunctions::SetBoolInAny( aAny, bBreak ); + } + + return aAny; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableRowsObj ) + +ScSpreadsheetSettingsObj::~ScSpreadsheetSettingsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScSpreadsheetSettingsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSpreadsheetSettingsObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + //! muss noch + return NULL; +} + +void SAL_CALL ScSpreadsheetSettingsObj::setPropertyValue( + const ::rtl::OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + //! muss noch +} + +uno::Any SAL_CALL ScSpreadsheetSettingsObj::getPropertyValue( const ::rtl::OUString& /*aPropertyName*/ ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + //! muss noch + return uno::Any(); +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSpreadsheetSettingsObj ) + +//------------------------------------------------------------------------ + +ScAnnotationsObj::ScAnnotationsObj(ScDocShell* pDocSh, USHORT nT) : + pDocShell( pDocSh ), + nTab( nT ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScAnnotationsObj::~ScAnnotationsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScAnnotationsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! nTab bei Referenz-Update anpassen!!! + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +BOOL ScAnnotationsObj::GetAddressByIndex_Impl( ULONG nIndex, ScAddress& rPos ) const +{ + if (pDocShell) + { + ULONG nFound = 0; + ScDocument* pDoc = pDocShell->GetDocument(); + ScCellIterator aCellIter( pDoc, 0,0, nTab, MAXCOL,MAXROW, nTab ); + ScBaseCell* pCell = aCellIter.GetFirst(); + while (pCell) + { + if (pCell->GetNotePtr()) + { + if (nFound == nIndex) + { + rPos = ScAddress( aCellIter.GetCol(), aCellIter.GetRow(), aCellIter.GetTab() ); + return TRUE; + } + ++nFound; + } + pCell = aCellIter.GetNext(); + } + } + return FALSE; // nicht gefunden +} + +// XSheetAnnotations + +ScAnnotationObj* ScAnnotationsObj::GetObjectByIndex_Impl(USHORT nIndex) const +{ + if (pDocShell) + { + ScAddress aPos; + if ( GetAddressByIndex_Impl( nIndex, aPos ) ) + return new ScAnnotationObj( pDocShell, aPos ); + } + return NULL; +} + +void SAL_CALL ScAnnotationsObj::insertNew( const table::CellAddress& aPosition, + const ::rtl::OUString& aText ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + DBG_ASSERT( aPosition.Sheet == nTab, "addAnnotation mit falschem Sheet" ); + ScAddress aPos( (USHORT)aPosition.Column, (USHORT)aPosition.Row, nTab ); + + String aString = aText; + + ScDocFunc aFunc(*pDocShell); + aFunc.SetNoteText( aPos, aString, TRUE ); + } +} + +void SAL_CALL ScAnnotationsObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScAddress aPos; + if ( GetAddressByIndex_Impl( nIndex, aPos ) ) + { + ScMarkData aMarkData; + aMarkData.SelectTable( aPos.Tab(), TRUE ); + aMarkData.SetMultiMarkArea( ScRange(aPos) ); + + ScDocFunc aFunc(*pDocShell); + aFunc.DeleteContents( aMarkData, IDF_NOTE, TRUE, TRUE ); + } + } +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScAnnotationsObj::createEnumeration() + throw(uno::RuntimeException) +{ + //! iterate directly (more efficiently)? + + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.CellAnnotationsEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScAnnotationsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ULONG nCount = 0; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScCellIterator aCellIter( pDoc, 0,0, nTab, MAXCOL,MAXROW, nTab ); + ScBaseCell* pCell = aCellIter.GetFirst(); + while (pCell) + { + if (pCell->GetNotePtr()) + ++nCount; + pCell = aCellIter.GetNext(); + } + } + return nCount; +} + +uno::Any SAL_CALL ScAnnotationsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XSheetAnnotation> xAnnotation = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xAnnotation.is()) + aAny <<= xAnnotation; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScAnnotationsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XSheetAnnotation>*)0); +} + +sal_Bool SAL_CALL ScAnnotationsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +ScScenariosObj::ScScenariosObj(ScDocShell* pDocSh, USHORT nT) : + pDocShell( pDocSh ), + nTab ( nT ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScScenariosObj::~ScScenariosObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScScenariosObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! Referenz-Update fuer Tab und Start/Ende + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XScenarios + +BOOL ScScenariosObj::GetScenarioIndex_Impl( const ::rtl::OUString& rName, USHORT& rIndex ) +{ + //! Case-insensitiv ???? + + if ( pDocShell ) + { + String aString = rName; + + String aTabName; + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nCount = (USHORT)getCount(); + for (USHORT i=0; i<nCount; i++) + if (pDoc->GetName( nTab+i+1, aTabName )) + if ( aTabName == aString ) + { + rIndex = i; + return TRUE; + } + } + + return FALSE; +} + +ScTableSheetObj* ScScenariosObj::GetObjectByIndex_Impl(USHORT nIndex) +{ + USHORT nCount = (USHORT)getCount(); + if ( pDocShell && nIndex < nCount ) + return new ScTableSheetObj( pDocShell, nTab+nIndex+1 ); + + return NULL; // kein Dokument oder falscher Index +} + +ScTableSheetObj* ScScenariosObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + USHORT nIndex; + if ( pDocShell && GetScenarioIndex_Impl( aName, nIndex ) ) + return new ScTableSheetObj( pDocShell, nTab+nIndex+1 ); + + return NULL; // nicht gefunden +} + +void SAL_CALL ScScenariosObj::addNewByName( const ::rtl::OUString& aName, + const uno::Sequence<table::CellRangeAddress>& aRanges, + const ::rtl::OUString& aComment ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + ScMarkData aMarkData; + aMarkData.SelectTable( nTab, TRUE ); + + USHORT nRangeCount = (USHORT)aRanges.getLength(); + if (nRangeCount) + { + const table::CellRangeAddress* pAry = aRanges.getConstArray(); + for (USHORT i=0; i<nRangeCount; i++) + { + DBG_ASSERT( pAry[i].Sheet == nTab, "addScenario mit falscher Tab" ); + ScRange aRange( (USHORT)pAry[i].StartColumn, (USHORT)pAry[i].StartRow, nTab, + (USHORT)pAry[i].EndColumn, (USHORT)pAry[i].EndRow, nTab ); + + aMarkData.SetMultiMarkArea( aRange ); + } + } + + String aNameStr = aName; + String aCommStr = aComment; + + Color aColor( COL_LIGHTGRAY ); // Default + } +} + +void SAL_CALL ScScenariosObj::removeByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nIndex; + if ( pDocShell ) + GetScenarioIndex_Impl( aName, nIndex ); +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScScenariosObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.ScenariosEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScScenariosObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = 0; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + if (!pDoc->IsScenario(nTab)) + { + USHORT nTabCount = pDoc->GetTableCount(); + USHORT nNext = nTab + 1; + while (nNext < nTabCount && pDoc->IsScenario(nNext)) + { + ++nCount; + ++nNext; + } + } + } + return nCount; +} + +uno::Any SAL_CALL ScScenariosObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XScenario> xScen = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xScen.is()) + aAny <<= xScen; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScScenariosObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XScenario>*)0); +} + +sal_Bool SAL_CALL ScScenariosObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Any SAL_CALL ScScenariosObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XScenario> xScen = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xScen.is()) + aAny <<= xScen; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScScenariosObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = (USHORT)getCount(); + uno::Sequence< ::rtl::OUString> aSeq(nCount); + + if ( pDocShell ) // sonst ist auch Count = 0 + { + String aTabName; + ScDocument* pDoc = pDocShell->GetDocument(); + ::rtl::OUString* pAry = aSeq.getArray(); + for (USHORT i=0; i<nCount; i++) + if (pDoc->GetName( nTab+i+1, aTabName )) + pAry[i] = aTabName; + } + + return aSeq; +} + +sal_Bool SAL_CALL ScScenariosObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nIndex; + return GetScenarioIndex_Impl( aName, nIndex ); +} + + + + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_drdefuno.cxx b/bf_sc/source/ui/unoobj/sc_drdefuno.cxx new file mode 100644 index 000000000..6b4682732 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_drdefuno.cxx @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include "drdefuno.hxx" +#include "docsh.hxx" +#include "drwlayer.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +ScDrawDefaultsObj::ScDrawDefaultsObj(ScDocShell* pDocSh) : + SvxUnoDrawPool( NULL ), + pDocShell( pDocSh ) +{ + // SvxUnoDrawPool is initialized without model, + // draw layer is created on demand in getModelPool + + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDrawDefaultsObj::~ScDrawDefaultsObj() throw () +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDrawDefaultsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // document gone + } +} + +SfxItemPool* ScDrawDefaultsObj::getModelPool( sal_Bool bReadOnly ) throw() +{ + SfxItemPool* pRet = NULL; + if ( pDocShell ) + { + ScDrawLayer* pModel = bReadOnly ? + pDocShell->GetDocument()->GetDrawLayer() : + pDocShell->MakeDrawLayer(); + if ( pModel ) + pRet = &pModel->GetItemPool(); + } + if ( !pRet ) + pRet = SvxUnoDrawPool::getModelPool( bReadOnly ); // uses default pool + + return pRet; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_editsrc.cxx b/bf_sc/source/ui/unoobj/sc_editsrc.cxx new file mode 100644 index 000000000..b34f1dc05 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_editsrc.cxx @@ -0,0 +1,343 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#define ITEMID_FIELD EE_FEATURE_FIELD +#include <bf_svx/unofored.hxx> + +#include "editsrc.hxx" +#include "editutil.hxx" +#include "docsh.hxx" +#include "docfunc.hxx" +#include "hints.hxx" +#include <vcl/svapp.hxx> +#include "AccessibleText.hxx" +namespace binfilter { + +//------------------------------------------------------------------------ + +TYPEINIT1( ScHeaderFooterChangedHint, SfxHint ); + +ScHeaderFooterChangedHint::ScHeaderFooterChangedHint(USHORT nP) : + nPart( nP ) +{ +} + +ScHeaderFooterChangedHint::~ScHeaderFooterChangedHint() +{ +} + +//------------------------------------------------------------------------ + +ScSharedHeaderFooterEditSource::ScSharedHeaderFooterEditSource( ScHeaderFooterTextData* pData ) : + pTextData( pData ) +{ + // pTextData is held by the ScHeaderFooterTextObj. + // Text range and cursor keep a reference to their parent text, so the text object is + // always alive and the TextData is valid as long as there are children. +} + +ScSharedHeaderFooterEditSource::~ScSharedHeaderFooterEditSource() +{ +} + +SvxEditSource* ScSharedHeaderFooterEditSource::Clone() const +{ + return new ScSharedHeaderFooterEditSource( pTextData ); +} + +SvxTextForwarder* ScSharedHeaderFooterEditSource::GetTextForwarder() +{ + return pTextData->GetTextForwarder(); +} + +void ScSharedHeaderFooterEditSource::UpdateData() +{ + pTextData->UpdateData(); +} + +ScEditEngineDefaulter* ScSharedHeaderFooterEditSource::GetEditEngine() +{ + return pTextData->GetEditEngine(); +} + +//------------------------------------------------------------------------ + +// each ScHeaderFooterEditSource object has its own ScHeaderFooterTextData + +ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj* pContent, + USHORT nP ) : + ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( *pContent, nP ) ) +{ +} + +ScHeaderFooterEditSource::ScHeaderFooterEditSource( ScHeaderFooterContentObj& rContent, + USHORT nP ) : + ScSharedHeaderFooterEditSource( new ScHeaderFooterTextData( rContent, nP ) ) +{ +} + +ScHeaderFooterEditSource::~ScHeaderFooterEditSource() +{ + delete GetTextData(); // not accessed in ScSharedHeaderFooterEditSource dtor +} + +SvxEditSource* ScHeaderFooterEditSource::Clone() const +{ + const ScHeaderFooterTextData* pData = GetTextData(); + return new ScHeaderFooterEditSource( pData->GetContentObj(), pData->GetPart() ); +} + +//------------------------------------------------------------------------ + +ScSharedCellEditSource::ScSharedCellEditSource( ScCellTextData* pData ) : + pCellTextData( pData ) +{ + // pCellTextData is part of the ScCellTextObj. + // Text range and cursor keep a reference to their parent text, so the text object is + // always alive and the CellTextData is valid as long as there are children. +} + +ScSharedCellEditSource::~ScSharedCellEditSource() +{ +} + +SvxEditSource* ScSharedCellEditSource::Clone() const +{ + return new ScSharedCellEditSource( pCellTextData ); +} + +SvxTextForwarder* ScSharedCellEditSource::GetTextForwarder() +{ + return pCellTextData->GetTextForwarder(); +} + +void ScSharedCellEditSource::UpdateData() +{ + pCellTextData->UpdateData(); +} + +void ScSharedCellEditSource::SetDoUpdateData(sal_Bool bValue) +{ + pCellTextData->SetDoUpdate(bValue); +} + +sal_Bool ScSharedCellEditSource::IsDirty() const +{ + return pCellTextData->IsDirty(); +} + +ScEditEngineDefaulter* ScSharedCellEditSource::GetEditEngine() +{ + return pCellTextData->GetEditEngine(); +} + +//------------------------------------------------------------------------ + +// each ScCellEditSource object has its own ScCellTextData + +ScCellEditSource::ScCellEditSource( ScDocShell* pDocSh, const ScAddress& rP ) : + ScSharedCellEditSource( new ScCellTextData( pDocSh, rP ) ) +{ +} + +ScCellEditSource::~ScCellEditSource() +{ + delete GetCellTextData(); // not accessed in ScSharedCellEditSource dtor +} + +SvxEditSource* ScCellEditSource::Clone() const +{ + const ScCellTextData* pData = GetCellTextData(); + return new ScCellEditSource( pData->GetDocShell(), pData->GetCellPos() ); +} + +//------------------------------------------------------------------------ + +ScAnnotationEditSource::ScAnnotationEditSource(ScDocShell* pDocSh, const ScAddress& rP) : + pDocShell( pDocSh ), + aCellPos( rP ), + pEditEngine( NULL ), + pForwarder( NULL ), + bDataValid( FALSE ) +{ + if (pDocShell) + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScAnnotationEditSource::~ScAnnotationEditSource() +{ + SolarMutexGuard aGuard; // needed for EditEngine dtor + + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + + delete pForwarder; + delete pEditEngine; +} + +SvxEditSource* ScAnnotationEditSource::Clone() const +{ + return new ScAnnotationEditSource( pDocShell, aCellPos ); +} + +SvxTextForwarder* ScAnnotationEditSource::GetTextForwarder() +{ + if (!pEditEngine) + { + // Notizen haben keine Felder + if ( pDocShell ) + pEditEngine = new ScEditEngineDefaulter( + pDocShell->GetDocument()->GetEnginePool(), FALSE ); + else + { + SfxItemPool* pEnginePool = EditEngine::CreatePool(); + pEnginePool->FreezeIdRanges(); + pEditEngine = new ScEditEngineDefaulter( pEnginePool, TRUE ); + } + pForwarder = new SvxEditEngineForwarder(*pEditEngine); + } + + if (bDataValid) + return pForwarder; + + if ( pDocShell ) + { + ScPostIt aNote; + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->GetNote( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), aNote ); + + pEditEngine->SetText( aNote.GetText() ); // incl. Umbrueche + } + + bDataValid = TRUE; + return pForwarder; +} + +void ScAnnotationEditSource::UpdateData() +{ + if ( pDocShell && pEditEngine ) + { + String aNewText = pEditEngine->GetText( LINEEND_LF ); // im SetNoteText passiert convertLineEnd + ScDocFunc aFunc(*pDocShell); + aFunc.SetNoteText( aCellPos, aNewText, TRUE ); + + // bDataValid wird bei SetDocumentModified zurueckgesetzt + } +} + +void ScAnnotationEditSource::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! Ref-Update + } + else if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + + DELETEZ( pForwarder ); + DELETEZ( pEditEngine ); // EditEngine uses document's pool + } + else if ( nId == SFX_HINT_DATACHANGED ) + bDataValid = FALSE; // Text muss neu geholt werden + } +} + + +ScSimpleEditSource::ScSimpleEditSource( SvxTextForwarder* pForw ) : + pForwarder( pForw ) +{ + // The same forwarder (and EditEngine) is shared by all children of the same Text object. + // Text range and cursor keep a reference to their parent text, so the text object is + // always alive and the forwarder is valid as long as there are children. +} + +ScSimpleEditSource::~ScSimpleEditSource() +{ +} + +SvxEditSource* ScSimpleEditSource::Clone() const +{ + return new ScSimpleEditSource( pForwarder ); +} + +SvxTextForwarder* ScSimpleEditSource::GetTextForwarder() +{ + return pForwarder; +} + +void ScSimpleEditSource::UpdateData() +{ + // nothing +} + + +SAL_WNODEPRECATED_DECLARATIONS_PUSH +ScAccessibilityEditSource::ScAccessibilityEditSource( ::std::auto_ptr < ScAccessibleTextData > pAccessibleCellTextData ) + : mpAccessibleTextData(pAccessibleCellTextData) +{ +} +SAL_WNODEPRECATED_DECLARATIONS_POP + +ScAccessibilityEditSource::~ScAccessibilityEditSource() +{ +} + +SAL_WNODEPRECATED_DECLARATIONS_PUSH +SvxEditSource* ScAccessibilityEditSource::Clone() const +{ + return new ScAccessibilityEditSource(::std::auto_ptr < ScAccessibleTextData > (mpAccessibleTextData->Clone())); +} +SAL_WNODEPRECATED_DECLARATIONS_POP + +SvxTextForwarder* ScAccessibilityEditSource::GetTextForwarder() +{ + return mpAccessibleTextData->GetTextForwarder(); +} + +SvxViewForwarder* ScAccessibilityEditSource::GetViewForwarder() +{ + return mpAccessibleTextData->GetViewForwarder(); +} + +SvxEditViewForwarder* ScAccessibilityEditSource::GetEditViewForwarder( sal_Bool bCreate ) +{ + return mpAccessibleTextData->GetEditViewForwarder(bCreate); +} + +void ScAccessibilityEditSource::UpdateData() +{ + mpAccessibleTextData->UpdateData(); +} + +SfxBroadcaster& ScAccessibilityEditSource::GetBroadcaster() const +{ + return mpAccessibleTextData->GetBroadcaster(); +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_fielduno.cxx b/bf_sc/source/ui/unoobj/sc_fielduno.cxx new file mode 100644 index 000000000..621b00d9c --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_fielduno.cxx @@ -0,0 +1,1520 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#define ITEMID_FIELD EE_FEATURE_FIELD + +#include <bf_svx/editobj.hxx> + + + +#include <bf_svx/itemdata.hxx> + +#include <tools/date.hxx> + +#include <tools/time.hxx> + +#include <bf_svx/flditem.hxx> +#include <rtl/uuid.h> + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <com/sun/star/text/FilenameDisplayFormat.hpp> + +#include "fielduno.hxx" +#include "textuno.hxx" +#include "miscuno.hxx" +#include "docsh.hxx" +#include "hints.hxx" +#include "editsrc.hxx" +#include "cellsuno.hxx" +#include "servuno.hxx" // fuer IDs +#include <vcl/svapp.hxx> +#include "unonames.hxx" +#include "editutil.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + + +// alles ohne Which-ID, Map nur fuer PropertySetInfo + +const SfxItemPropertyMap* lcl_GetURLPropertyMap() +{ + static SfxItemPropertyMap aURLPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_REPR), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_TARGET), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_URL), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {0,0,0,0,0,0} + }; + return aURLPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetHeaderFieldPropertyMap() +{ + static SfxItemPropertyMap aHeaderFieldPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY,0 }, + {0,0,0,0,0,0} + }; + return aHeaderFieldPropertyMap_Impl; +} + +const SfxItemPropertyMap* lcl_GetFileFieldPropertyMap() +{ + static SfxItemPropertyMap aFileFieldPropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ANCTYPE), 0, &getCppuType((text::TextContentAnchorType*)0), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_ANCTYPES), 0, &getCppuType((uno::Sequence<text::TextContentAnchorType>*)0), beans::PropertyAttribute::READONLY,0 }, + {MAP_CHAR_LEN(SC_UNONAME_FILEFORM), 0, &getCppuType((sal_Int16*)0), 0,0 }, + {MAP_CHAR_LEN(SC_UNONAME_TEXTWRAP), 0, &getCppuType((text::WrapTextMode*)0), beans::PropertyAttribute::READONLY,0 }, + {0,0,0,0,0,0} + }; + return aFileFieldPropertyMap_Impl; +} + + +#define SCTEXTFIELD_SERVICE "com.sun.star.text.TextField" +#define SCTEXTCONTENT_SERVICE "com.sun.star.text.TextContent" + +SC_SIMPLE_SERVICE_INFO( ScCellFieldsObj, "ScCellFieldsObj", "com.sun.star.text.TextFields" ) +SC_SIMPLE_SERVICE_INFO( ScHeaderFieldsObj, "ScHeaderFieldsObj", "com.sun.star.text.TextFields" ) + + +// ScUnoEditEngine nur um aus einer EditEngine die Felder herauszubekommen... + +enum ScUnoCollectMode +{ + SC_UNO_COLLECT_NONE, + SC_UNO_COLLECT_COUNT, + SC_UNO_COLLECT_FINDINDEX, + SC_UNO_COLLECT_FINDPOS +}; + +class ScUnoEditEngine : public ScEditEngineDefaulter +{ + ScUnoCollectMode eMode; + USHORT nFieldCount; + TypeId aFieldType; + SvxFieldData* pFound; // lokale Kopie + USHORT nFieldPar; + xub_StrLen nFieldPos; + USHORT nFieldIndex; + +public: + ScUnoEditEngine(ScEditEngineDefaulter* pSource); + ~ScUnoEditEngine(); + + //! nPos should be xub_StrLen + virtual String CalcFieldValue( const SvxFieldItem& rField, USHORT nPara, USHORT nPos, + Color*& rTxtColor, Color*& rFldColor ); + + USHORT CountFields(TypeId aType); + SvxFieldData* FindByIndex(USHORT nIndex, TypeId aType); + SvxFieldData* FindByPos(USHORT nPar, xub_StrLen nPos, TypeId aType); + + USHORT GetFieldPar() const { return nFieldPar; } + xub_StrLen GetFieldPos() const { return nFieldPos; } +}; + +ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource) : + ScEditEngineDefaulter( *pSource ), + eMode( SC_UNO_COLLECT_NONE ), + nFieldCount( 0 ), + aFieldType( NULL ), + pFound( NULL ) +{ + if (pSource) + { + EditTextObject* pData = pSource->CreateTextObject(); + SetText( *pData ); + delete pData; + } +} + +ScUnoEditEngine::~ScUnoEditEngine() +{ + delete pFound; +} + +String ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField, + USHORT nPara, USHORT nPos, Color*& rTxtColor, Color*& rFldColor ) +{ + String aRet = EditEngine::CalcFieldValue( rField, nPara, nPos, rTxtColor, rFldColor ); + if (eMode != SC_UNO_COLLECT_NONE) + { + const SvxFieldData* pFieldData = rField.GetField(); + if ( pFieldData ) + { + if ( !aFieldType || pFieldData->Type() == aFieldType ) + { + if ( eMode == SC_UNO_COLLECT_FINDINDEX && !pFound && nFieldCount == nFieldIndex ) + { + pFound = pFieldData->Clone(); + nFieldPar = nPara; + nFieldPos = nPos; + } + if ( eMode == SC_UNO_COLLECT_FINDPOS && !pFound && + nPara == nFieldPar && nPos == nFieldPos ) + { + pFound = pFieldData->Clone(); + nFieldIndex = nFieldCount; + } + ++nFieldCount; + } + } + } + return aRet; +} + +USHORT ScUnoEditEngine::CountFields(TypeId aType) +{ + eMode = SC_UNO_COLLECT_COUNT; + aFieldType = aType; + nFieldCount = 0; + UpdateFields(); + aFieldType = NULL; + eMode = SC_UNO_COLLECT_NONE; + + return nFieldCount; +} + +SvxFieldData* ScUnoEditEngine::FindByIndex(USHORT nIndex, TypeId aType) +{ + eMode = SC_UNO_COLLECT_FINDINDEX; + nFieldIndex = nIndex; + aFieldType = aType; + nFieldCount = 0; + UpdateFields(); + aFieldType = NULL; + eMode = SC_UNO_COLLECT_NONE; + + return pFound; +} + +SvxFieldData* ScUnoEditEngine::FindByPos(USHORT nPar, xub_StrLen nPos, TypeId aType) +{ + eMode = SC_UNO_COLLECT_FINDPOS; + nFieldPar = nPar; + nFieldPos = nPos; + aFieldType = aType; + nFieldCount = 0; + UpdateFields(); + aFieldType = NULL; + eMode = SC_UNO_COLLECT_NONE; + + return pFound; +} + + +ScCellFieldsObj::ScCellFieldsObj(ScDocShell* pDocSh, const ScAddress& rPos) : + pDocShell( pDocSh ), + aCellPos( rPos ), + mpRefreshListeners( NULL ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); + + pEditSource = new ScCellEditSource( pDocShell, aCellPos ); +} + +ScCellFieldsObj::~ScCellFieldsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + + delete pEditSource; + + // increment refcount to prevent double call off dtor + osl_incrementInterlockedCount( &m_refCount ); + + if (mpRefreshListeners) + { + lang::EventObject aEvent; + aEvent.Source = static_cast<cppu::OWeakObject*>(this); + if (mpRefreshListeners) + { + mpRefreshListeners->disposeAndClear(aEvent); + DELETEZ( mpRefreshListeners ); + } + } +} + +void ScCellFieldsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! Ref-Update + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } + + // EditSource hat sich selber als Listener angemeldet +} + +// XIndexAccess (via XTextFields) + +ScCellFieldObj* ScCellFieldsObj::GetObjectByIndex_Impl(INT32 Index) const +{ + //! Feld-Funktionen muessen an den Forwarder !!! + ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + + if ( aTempEngine.FindByIndex( (USHORT)Index, NULL ) ) // in der Zelle ist der Typ egal + { + USHORT nPar = aTempEngine.GetFieldPar(); + xub_StrLen nPos = aTempEngine.GetFieldPos(); + ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Feld ist 1 Zeichen + return new ScCellFieldObj( pDocShell, aCellPos, aSelection ); + } + return NULL; +} + +sal_Int32 SAL_CALL ScCellFieldsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! Feld-Funktionen muessen an den Forwarder !!! + ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + + return aTempEngine.CountFields(NULL); // Felder zaehlen, in Zelle ist der Typ egal +} + +uno::Any SAL_CALL ScCellFieldsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<text::XTextField> xField = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xField.is()) + aAny <<= xField; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScCellFieldsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<text::XTextField>*)0); +} + +sal_Bool SAL_CALL ScCellFieldsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Reference<container::XEnumeration> SAL_CALL ScCellFieldsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration"))); +} + +void SAL_CALL ScCellFieldsObj::addContainerListener( + const uno::Reference<container::XContainerListener>& /*xListener*/ ) + throw(uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +void SAL_CALL ScCellFieldsObj::removeContainerListener( + const uno::Reference<container::XContainerListener>& /*xListener*/ ) + throw(uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +// XRefreshable +void SAL_CALL ScCellFieldsObj::refresh( ) + throw (uno::RuntimeException) +{ + if (mpRefreshListeners) + { + // Call all listeners. + uno::Sequence< uno::Reference< uno::XInterface > > aListeners = mpRefreshListeners->getElements(); + sal_uInt32 nLength(aListeners.getLength()); + if (nLength) + { + const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray(); + if (pInterfaces) + { + lang::EventObject aEvent; + aEvent.Source = uno::Reference< util::XRefreshable >(const_cast<ScCellFieldsObj*>(this)); + sal_uInt32 i(0); + while (i < nLength) + { + try + { + while(i < nLength) + { + static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent); + ++pInterfaces; + ++i; + } + } + catch(uno::RuntimeException&) + { +// OSL_FAIL("a object is gone without to remove from Broadcaster"); + ++pInterfaces; + ++i; + } + } + } + } + } +} + +void SAL_CALL ScCellFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener ) + throw (uno::RuntimeException) +{ + if (xListener.is()) + { + SolarMutexGuard aGuard; + if (!mpRefreshListeners) + mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex); + mpRefreshListeners->addInterface(xListener); + } +} + +void SAL_CALL ScCellFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener ) + throw (uno::RuntimeException) +{ + if (xListener.is()) + { + SolarMutexGuard aGuard; + if (mpRefreshListeners) + mpRefreshListeners->removeInterface(xListener); + } +} + + +ScCellFieldObj::ScCellFieldObj(ScDocShell* pDocSh, const ScAddress& rPos, + const ESelection& rSel) : + OComponentHelper( getMutex() ), + aPropSet( lcl_GetURLPropertyMap() ), + pDocShell( pDocSh ), + aCellPos( rPos ), + aSelection( rSel ) +{ + // pDocShell ist Null, wenn per ServiceProvider erzeugt + + if (pDocShell) + { + pDocShell->GetDocument()->AddUnoObject(*this); + pEditSource = new ScCellEditSource( pDocShell, aCellPos ); + } + else + pEditSource = NULL; +} + +uno::Any SAL_CALL ScCellFieldObj::queryAggregation( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( text::XTextField ) + SC_QUERYINTERFACE( text::XTextContent ) // parent of XTextField + SC_QUERYINTERFACE( beans::XPropertySet ) + SC_QUERYINTERFACE( lang::XUnoTunnel ) + SC_QUERYINTERFACE( lang::XServiceInfo ) + + return OComponentHelper::queryAggregation( rType ); // XComponent +} + +uno::Sequence<uno::Type> SAL_CALL ScCellFieldObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = OComponentHelper::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 4 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0); + pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScCellFieldObj::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +uno::Any SAL_CALL ScCellFieldObj::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + return OComponentHelper::queryInterface( rType ); +} + +void SAL_CALL ScCellFieldObj::acquire() throw() +{ + OComponentHelper::acquire(); +} + +void SAL_CALL ScCellFieldObj::release() throw() +{ + OComponentHelper::release(); +} + +void ScCellFieldObj::InitDoc( ScDocShell* pDocSh, const ScAddress& rPos, + const ESelection& rSel ) +{ + if ( pDocSh && !pEditSource ) + { + aCellPos = rPos; + aSelection = rSel; + pDocShell = pDocSh; + + pDocShell->GetDocument()->AddUnoObject(*this); + pEditSource = new ScCellEditSource( pDocShell, aCellPos ); + } +} + +ScCellFieldObj::~ScCellFieldObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + + delete pEditSource; +} + +void ScCellFieldObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! Updates fuer aSelection (muessen erst noch erzeugt werden) !!!!!! + + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! Ref-Update + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } + + // EditSource hat sich selber als Listener angemeldet +} + +// per getImplementation gerufen: + +SvxFieldItem ScCellFieldObj::CreateFieldItem() +{ + DBG_ASSERT( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" ); + + SvxURLField aField; + aField.SetFormat(SVXURLFORMAT_APPDEFAULT); + aField.SetURL( aUrl ); + aField.SetRepresentation( aRepresentation ); + aField.SetTargetFrame( aTarget ); + return SvxFieldItem( aField ); +} + +void ScCellFieldObj::DeleteField() +{ + if (pEditSource) + { + SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder(); + pForwarder->QuickInsertText( String(), aSelection ); + pEditSource->UpdateData(); + + aSelection.nEndPara = aSelection.nStartPara; + aSelection.nEndPos = aSelection.nStartPos; + + //! Broadcast, um Selektion in anderen Objekten anzupassen + //! (auch bei anderen Aktionen) + } +} + +// XTextField + +::rtl::OUString SAL_CALL ScCellFieldObj::getPresentation( sal_Bool bShowCommand ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aRet; + + if (pEditSource) + { + //! Feld-Funktionen muessen an den Forwarder !!! + ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + + // Typ egal (in Zellen gibts nur URLs) + SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 ); + DBG_ASSERT(pField,"getPresentation: Feld nicht gefunden"); + if (pField) + { + SvxURLField* pURL = (SvxURLField*)pField; + if (bShowCommand) + aRet = pURL->GetURL(); + else + aRet = pURL->GetRepresentation(); + } + } + + return aRet; +} + +// XTextContent + +void SAL_CALL ScCellFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (xTextRange.is()) + { + uno::Reference<text::XText> xText = xTextRange->getText(); + if (xText.is()) + { + xText->insertTextContent( xTextRange, this, TRUE ); + } + } +} + +uno::Reference<text::XTextRange> SAL_CALL ScCellFieldObj::getAnchor() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + return new ScCellObj( pDocShell, aCellPos ); + return NULL; +} + +// XComponent + +void SAL_CALL ScCellFieldObj::dispose() throw(uno::RuntimeException) +{ + OComponentHelper::dispose(); +} + +void SAL_CALL ScCellFieldObj::addEventListener( + const uno::Reference<lang::XEventListener>& xListener ) + throw(uno::RuntimeException) +{ + OComponentHelper::addEventListener( xListener ); +} + +void SAL_CALL ScCellFieldObj::removeEventListener( + const uno::Reference<lang::XEventListener>& xListener ) + throw(uno::RuntimeException) +{ + OComponentHelper::removeEventListener( xListener ); +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScCellFieldObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScCellFieldObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + ::rtl::OUString aStrVal; + if (pEditSource) + { + //! Feld-Funktionen muessen an den Forwarder !!! + ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + + // Typ egal (in Zellen gibts nur URLs) + SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 ); + DBG_ASSERT(pField,"setPropertyValue: Feld nicht gefunden"); + if (pField) + { + SvxURLField* pURL = (SvxURLField*)pField; // ist eine Kopie in der ScUnoEditEngine + + BOOL bOk = TRUE; + if ( aNameString.EqualsAscii( SC_UNONAME_URL ) ) + { + if (aValue >>= aStrVal) + pURL->SetURL( aStrVal ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) ) + { + if (aValue >>= aStrVal) + pURL->SetRepresentation( aStrVal ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) ) + { + if (aValue >>= aStrVal) + pURL->SetTargetFrame( aStrVal ); + } + else + bOk = FALSE; + + if (bOk) + { + pEditEngine->QuickInsertField( SvxFieldItem(*pField), aSelection ); + pEditSource->UpdateData(); + } + } + } + else // noch nicht eingefuegt + { + if ( aNameString.EqualsAscii( SC_UNONAME_URL ) ) + { + if (aValue >>= aStrVal) + aUrl = String( aStrVal ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) ) + { + if (aValue >>= aStrVal) + aRepresentation = String( aStrVal ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) ) + { + if (aValue >>= aStrVal) + aTarget = String( aStrVal ); + } + } +} + +uno::Any SAL_CALL ScCellFieldObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aRet; + String aNameString = aPropertyName; + + // anchor type is always "as character", text wrap always "none" + + if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) ) + aRet <<= text::TextContentAnchorType_AS_CHARACTER; + else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) ) + { + uno::Sequence<text::TextContentAnchorType> aSeq(1); + aSeq[0] = text::TextContentAnchorType_AS_CHARACTER; + aRet <<= aSeq; + } + else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) ) + aRet <<= text::WrapTextMode_NONE; + else if (pEditSource) + { + //! Feld-Funktionen muessen an den Forwarder !!! + ScEditEngineDefaulter* pEditEngine = ((ScCellEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + + // Typ egal (in Zellen gibts nur URLs) + SvxFieldData* pField = aTempEngine.FindByPos( aSelection.nStartPara, aSelection.nStartPos, 0 ); + DBG_ASSERT(pField,"getPropertyValue: Feld nicht gefunden"); + if (pField) + { + SvxURLField* pURL = (SvxURLField*)pField; + + if ( aNameString.EqualsAscii( SC_UNONAME_URL ) ) + aRet <<= ::rtl::OUString( pURL->GetURL() ); + else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) ) + aRet <<= ::rtl::OUString( pURL->GetRepresentation() ); + else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) ) + aRet <<= ::rtl::OUString( pURL->GetTargetFrame() ); + } + } + else // noch nicht eingefuegt + { + if ( aNameString.EqualsAscii( SC_UNONAME_URL ) ) + aRet <<= ::rtl::OUString( aUrl ); + else if ( aNameString.EqualsAscii( SC_UNONAME_REPR ) ) + aRet <<= ::rtl::OUString( aRepresentation ); + else if ( aNameString.EqualsAscii( SC_UNONAME_TARGET ) ) + aRet <<= ::rtl::OUString( aTarget ); + } + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScCellFieldObj ) + +// XUnoTunnel + +sal_Int64 SAL_CALL ScCellFieldObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScCellFieldObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScCellFieldObj* ScCellFieldObj::getImplementation( + const uno::Reference<text::XTextContent> xObj ) +{ + ScCellFieldObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScCellFieldObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScCellFieldObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScCellFieldObj" )); +} + +sal_Bool SAL_CALL ScCellFieldObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) || + aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScCellFieldObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(2); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTFIELD_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTCONTENT_SERVICE )); + return aRet; +} + + +ScHeaderFieldsObj::ScHeaderFieldsObj(ScHeaderFooterContentObj* pContent, USHORT nP, USHORT nT) : + pContentObj( pContent ), + nPart( nP ), + nType( nT ), + mpRefreshListeners( NULL ) +{ + DBG_ASSERT( pContentObj, "ScHeaderFieldsObj ohne Objekt?" ); + + if (pContentObj) + { + pContentObj->acquire(); // darf nicht wegkommen + pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart ); + } + else + pEditSource = NULL; +} + +ScHeaderFieldsObj::~ScHeaderFieldsObj() +{ + delete pEditSource; + + if (pContentObj) + pContentObj->release(); + + // increment refcount to prevent double call off dtor + osl_incrementInterlockedCount( &m_refCount ); + + if (mpRefreshListeners) + { + lang::EventObject aEvent; + aEvent.Source = static_cast<cppu::OWeakObject*>(this); + if (mpRefreshListeners) + { + mpRefreshListeners->disposeAndClear(aEvent); + DELETEZ( mpRefreshListeners ); + } + } +} + +// XIndexAccess (via XTextFields) + +ScHeaderFieldObj* ScHeaderFieldsObj::GetObjectByIndex_Impl(INT32 Index) const +{ + //! Feld-Funktionen muessen an den Forwarder !!! + ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + + TypeId aTypeId = NULL; + switch (nType) + { + case SC_SERVICE_PAGEFIELD: aTypeId = TYPE(SvxPageField); break; + case SC_SERVICE_PAGESFIELD: aTypeId = TYPE(SvxPagesField); break; + case SC_SERVICE_DATEFIELD: aTypeId = TYPE(SvxDateField); break; + case SC_SERVICE_TIMEFIELD: aTypeId = TYPE(SvxTimeField); break; + case SC_SERVICE_TITLEFIELD: aTypeId = TYPE(SvxFileField); break; + case SC_SERVICE_FILEFIELD: aTypeId = TYPE(SvxExtFileField); break; + case SC_SERVICE_SHEETFIELD: aTypeId = TYPE(SvxTableField); break; + // bei SC_SERVICE_INVALID bleibt TypeId Null + } + SvxFieldData* pData = aTempEngine.FindByIndex( (USHORT)Index, aTypeId ); + if ( pData ) + { + USHORT nPar = aTempEngine.GetFieldPar(); + xub_StrLen nPos = aTempEngine.GetFieldPos(); + + USHORT nFieldType = nType; + if ( nFieldType == SC_SERVICE_INVALID ) + { + if ( pData->ISA( SvxPageField ) ) nFieldType = SC_SERVICE_PAGEFIELD; + else if ( pData->ISA( SvxPagesField ) ) nFieldType = SC_SERVICE_PAGESFIELD; + else if ( pData->ISA( SvxDateField ) ) nFieldType = SC_SERVICE_DATEFIELD; + else if ( pData->ISA( SvxTimeField ) ) nFieldType = SC_SERVICE_TIMEFIELD; + else if ( pData->ISA( SvxFileField ) ) nFieldType = SC_SERVICE_TITLEFIELD; + else if ( pData->ISA( SvxExtFileField ) ) nFieldType = SC_SERVICE_FILEFIELD; + else if ( pData->ISA( SvxTableField ) ) nFieldType = SC_SERVICE_SHEETFIELD; + } + + ESelection aSelection( nPar, nPos, nPar, nPos+1 ); // Field is 1 character + return new ScHeaderFieldObj( pContentObj, nPart, nFieldType, aSelection ); + } + return NULL; +} + +sal_Int32 SAL_CALL ScHeaderFieldsObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! Feld-Funktionen muessen an den Forwarder !!! + ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + + TypeId aTypeId = NULL; + switch (nType) + { + case SC_SERVICE_PAGEFIELD: aTypeId = TYPE(SvxPageField); break; + case SC_SERVICE_PAGESFIELD: aTypeId = TYPE(SvxPagesField); break; + case SC_SERVICE_DATEFIELD: aTypeId = TYPE(SvxDateField); break; + case SC_SERVICE_TIMEFIELD: aTypeId = TYPE(SvxTimeField); break; + case SC_SERVICE_TITLEFIELD: aTypeId = TYPE(SvxFileField); break; + case SC_SERVICE_FILEFIELD: aTypeId = TYPE(SvxExtFileField); break; + case SC_SERVICE_SHEETFIELD: aTypeId = TYPE(SvxTableField); break; + } + return aTempEngine.CountFields(aTypeId); // Felder zaehlen +} + +uno::Any SAL_CALL ScHeaderFieldsObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<text::XTextField> xField = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xField.is()) + aAny <<= xField; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScHeaderFieldsObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<text::XTextField>*)0); +} + +sal_Bool SAL_CALL ScHeaderFieldsObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFieldsObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextFieldEnumeration"))); +} + +void SAL_CALL ScHeaderFieldsObj::addContainerListener( + const uno::Reference<container::XContainerListener>& /*xListener*/ ) + throw(uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +void SAL_CALL ScHeaderFieldsObj::removeContainerListener( + const uno::Reference<container::XContainerListener>& /*xListener*/ ) + throw(uno::RuntimeException) +{ + OSL_FAIL("not implemented"); +} + +// XRefreshable +void SAL_CALL ScHeaderFieldsObj::refresh( ) + throw (uno::RuntimeException) +{ + if (mpRefreshListeners) + { + // Call all listeners. + uno::Sequence< uno::Reference< uno::XInterface > > aListeners = mpRefreshListeners->getElements(); + sal_uInt32 nLength(aListeners.getLength()); + if (nLength) + { + const uno::Reference< uno::XInterface >* pInterfaces = aListeners.getConstArray(); + if (pInterfaces) + { + lang::EventObject aEvent; + aEvent.Source = uno::Reference< util::XRefreshable >(const_cast<ScHeaderFieldsObj*>(this)); + sal_uInt32 i(0); + while (i < nLength) + { + try + { + while(i < nLength) + { + static_cast< util::XRefreshListener* >(pInterfaces->get())->refreshed(aEvent); + ++pInterfaces; + ++i; + } + } + catch(uno::RuntimeException&) + { + ++pInterfaces; + ++i; + } + } + } + } + } +} + +void SAL_CALL ScHeaderFieldsObj::addRefreshListener( const uno::Reference< util::XRefreshListener >& xListener ) + throw (uno::RuntimeException) +{ + if (xListener.is()) + { + SolarMutexGuard aGuard; + if (!mpRefreshListeners) + mpRefreshListeners = new cppu::OInterfaceContainerHelper(aMutex); + mpRefreshListeners->addInterface(xListener); + } +} + +void SAL_CALL ScHeaderFieldsObj::removeRefreshListener( const uno::Reference<util::XRefreshListener >& xListener ) + throw (uno::RuntimeException) +{ + if (xListener.is()) + { + SolarMutexGuard aGuard; + if (mpRefreshListeners) + mpRefreshListeners->removeInterface(xListener); + } +} + + +SvxFileFormat lcl_UnoToSvxFileFormat( sal_Int16 nUnoValue ) +{ + switch( nUnoValue ) + { + case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH; + case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH; + case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME; + default: + return SVXFILEFORMAT_NAME_EXT; + } +} + +sal_Int16 lcl_SvxToUnoFileFormat( SvxFileFormat nSvxValue ) +{ + switch( nSvxValue ) + { + case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT; + case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL; + case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH; + default: + return text::FilenameDisplayFormat::NAME; + } +} + + +ScHeaderFieldObj::ScHeaderFieldObj(ScHeaderFooterContentObj* pContent, USHORT nP, + USHORT nT, const ESelection& rSel) : + OComponentHelper( getMutex() ), + aPropSet( (nT == SC_SERVICE_FILEFIELD) ? lcl_GetFileFieldPropertyMap() : lcl_GetHeaderFieldPropertyMap() ), + pContentObj( pContent ), + nPart( nP ), + nType( nT ), + aSelection( rSel ), + nFileFormat( SVXFILEFORMAT_NAME_EXT ) +{ + // pContent ist Null, wenn per ServiceProvider erzeugt + + if (pContentObj) + { + pContentObj->acquire(); // darf nicht wegkommen + pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart ); + } + else + pEditSource = NULL; +} + +uno::Any SAL_CALL ScHeaderFieldObj::queryAggregation( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( text::XTextField ) + SC_QUERYINTERFACE( text::XTextContent ) // parent of XTextField + SC_QUERYINTERFACE( beans::XPropertySet ) + SC_QUERYINTERFACE( lang::XUnoTunnel ) + SC_QUERYINTERFACE( lang::XServiceInfo ) + + return OComponentHelper::queryAggregation( rType ); // XComponent +} + +uno::Sequence<uno::Type> SAL_CALL ScHeaderFieldObj::getTypes() throw(uno::RuntimeException) +{ + static uno::Sequence<uno::Type> aTypes; + if ( aTypes.getLength() == 0 ) + { + uno::Sequence<uno::Type> aParentTypes = OComponentHelper::getTypes(); + long nParentLen = aParentTypes.getLength(); + const uno::Type* pParentPtr = aParentTypes.getConstArray(); + + aTypes.realloc( nParentLen + 4 ); + uno::Type* pPtr = aTypes.getArray(); + pPtr[nParentLen + 0] = getCppuType((const uno::Reference<text::XTextField>*)0); + pPtr[nParentLen + 1] = getCppuType((const uno::Reference<beans::XPropertySet>*)0); + pPtr[nParentLen + 2] = getCppuType((const uno::Reference<lang::XUnoTunnel>*)0); + pPtr[nParentLen + 3] = getCppuType((const uno::Reference<lang::XServiceInfo>*)0); + + for (long i=0; i<nParentLen; i++) + pPtr[i] = pParentPtr[i]; // parent types first + } + return aTypes; +} + +uno::Sequence<sal_Int8> SAL_CALL ScHeaderFieldObj::getImplementationId() + throw(uno::RuntimeException) +{ + static uno::Sequence< sal_Int8 > aId; + if( aId.getLength() == 0 ) + { + aId.realloc( 16 ); + rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); + } + return aId; +} + +uno::Any SAL_CALL ScHeaderFieldObj::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + return OComponentHelper::queryInterface( rType ); +} + +void SAL_CALL ScHeaderFieldObj::acquire() throw() +{ + OComponentHelper::acquire(); +} + +void SAL_CALL ScHeaderFieldObj::release() throw() +{ + OComponentHelper::release(); +} + +void ScHeaderFieldObj::InitDoc( ScHeaderFooterContentObj* pContent, USHORT nP, + const ESelection& rSel ) +{ + if ( pContent && !pEditSource ) + { + DBG_ASSERT( !pContentObj, "ContentObj, aber kein EditSource?" ); + + aSelection = rSel; + nPart = nP; + pContentObj = pContent; + + pContentObj->acquire(); // darf nicht wegkommen + pEditSource = new ScHeaderFooterEditSource( pContentObj, nPart ); + } +} + +ScHeaderFieldObj::~ScHeaderFieldObj() +{ + delete pEditSource; + + if (pContentObj) + pContentObj->release(); +} + +// per getImplementation gerufen: + +SvxFieldItem ScHeaderFieldObj::CreateFieldItem() +{ + DBG_ASSERT( !pEditSource, "CreateFieldItem mit eingefuegtem Feld" ); + + switch (nType) + { + case SC_SERVICE_PAGEFIELD: + { + SvxPageField aField; + return SvxFieldItem( aField ); + } + case SC_SERVICE_PAGESFIELD: + { + SvxPagesField aField; + return SvxFieldItem( aField ); + } + case SC_SERVICE_DATEFIELD: + { + SvxDateField aField; + return SvxFieldItem( aField ); + } + case SC_SERVICE_TIMEFIELD: + { + SvxTimeField aField; + return SvxFieldItem( aField ); + } + case SC_SERVICE_TITLEFIELD: + { + SvxFileField aField; + return SvxFieldItem( aField ); + } + case SC_SERVICE_FILEFIELD: + { + SvxExtFileField aField; + aField.SetFormat( (SvxFileFormat) nFileFormat ); + return SvxFieldItem( aField ); + } + case SC_SERVICE_SHEETFIELD: + { + SvxTableField aField; + return SvxFieldItem( aField ); + } + } + + return SvxFieldItem( SvxFieldData() ); +} + +void ScHeaderFieldObj::DeleteField() +{ + if (pEditSource) + { + SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder(); + pForwarder->QuickInsertText( String(), aSelection ); + pEditSource->UpdateData(); + + aSelection.nEndPara = aSelection.nStartPara; + aSelection.nEndPos = aSelection.nStartPos; + + //! Broadcast, um Selektion in anderen Objekten anzupassen + //! (auch bei anderen Aktionen) + } +} + +// XTextField + +::rtl::OUString SAL_CALL ScHeaderFieldObj::getPresentation( sal_Bool /*bShowCommand*/ ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aRet; + + if (pEditSource) + { + // Feld von der EditEngine formatieren lassen, bShowCommand gibt's nicht + + SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder(); + aRet = pForwarder->GetText( aSelection ); + } + + return aRet; +} + +// XTextContent + +void SAL_CALL ScHeaderFieldObj::attach( const uno::Reference<text::XTextRange>& xTextRange ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (xTextRange.is()) + { + uno::Reference<text::XText> xText = xTextRange->getText(); + if (xText.is()) + { + xText->insertTextContent( xTextRange, this, TRUE ); + } + } +} + +uno::Reference<text::XTextRange> SAL_CALL ScHeaderFieldObj::getAnchor() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pContentObj) + { + uno::Reference<text::XText> xText; + if ( nPart == SC_HDFT_LEFT ) + xText = pContentObj->getLeftText(); + else if (nPart == SC_HDFT_CENTER) + xText = pContentObj->getCenterText(); + else + xText = pContentObj->getRightText(); + return uno::Reference<text::XTextRange>( xText, uno::UNO_QUERY ); + } + return NULL; +} + +// XComponent + +void SAL_CALL ScHeaderFieldObj::dispose() throw(uno::RuntimeException) +{ + OComponentHelper::dispose(); +} + +void SAL_CALL ScHeaderFieldObj::addEventListener( + const uno::Reference<lang::XEventListener>& xListener ) + throw(uno::RuntimeException) +{ + OComponentHelper::addEventListener( xListener ); +} + +void SAL_CALL ScHeaderFieldObj::removeEventListener( + const uno::Reference<lang::XEventListener>& xListener ) + throw(uno::RuntimeException) +{ + OComponentHelper::removeEventListener( xListener ); +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScHeaderFieldObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (nType == SC_SERVICE_FILEFIELD) + { + // file field has different properties + static uno::Reference<beans::XPropertySetInfo> aFileFieldInfo = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aFileFieldInfo; + } + else + { + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; + } +} + +void SAL_CALL ScHeaderFieldObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) ) + { + sal_Int16 nIntVal = 0; + if ( aValue >>= nIntVal ) + { + SvxFileFormat eFormat = lcl_UnoToSvxFileFormat( nIntVal ); + if (pEditSource) + { + ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + SvxFieldData* pField = aTempEngine.FindByPos( + aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) ); + DBG_ASSERT(pField,"setPropertyValue: Field not found"); + if (pField) + { + SvxExtFileField* pExtFile = (SvxExtFileField*)pField; // local to the ScUnoEditEngine + pExtFile->SetFormat( eFormat ); + pEditEngine->QuickInsertField( SvxFieldItem(*pField), aSelection ); + pEditSource->UpdateData(); + } + } + else + nFileFormat = eFormat; // not inserted yet - store value + } + } +} + +uno::Any SAL_CALL ScHeaderFieldObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! Properties? + uno::Any aRet; + String aNameString = aPropertyName; + + // anchor type is always "as character", text wrap always "none" + + if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPE ) ) + aRet <<= text::TextContentAnchorType_AS_CHARACTER; + else if ( aNameString.EqualsAscii( SC_UNONAME_ANCTYPES ) ) + { + uno::Sequence<text::TextContentAnchorType> aSeq(1); + aSeq[0] = text::TextContentAnchorType_AS_CHARACTER; + aRet <<= aSeq; + } + else if ( aNameString.EqualsAscii( SC_UNONAME_TEXTWRAP ) ) + aRet <<= text::WrapTextMode_NONE; + else if ( nType == SC_SERVICE_FILEFIELD && aNameString.EqualsAscii( SC_UNONAME_FILEFORM ) ) + { + SvxFileFormat eFormat = SVXFILEFORMAT_NAME_EXT; + if (pEditSource) + { + ScEditEngineDefaulter* pEditEngine = ((ScHeaderFooterEditSource*)pEditSource)->GetEditEngine(); + ScUnoEditEngine aTempEngine(pEditEngine); + SvxFieldData* pField = aTempEngine.FindByPos( + aSelection.nStartPara, aSelection.nStartPos, TYPE(SvxExtFileField) ); + DBG_ASSERT(pField,"setPropertyValue: Field not found"); + if (pField) + { + const SvxExtFileField* pExtFile = (const SvxExtFileField*)pField; + eFormat = pExtFile->GetFormat(); + } + } + else + eFormat = (SvxFileFormat) nFileFormat; // not inserted yet - use stored value + + sal_Int16 nIntVal = lcl_SvxToUnoFileFormat( eFormat ); + aRet <<= nIntVal; + } + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScHeaderFieldObj ) + +// XUnoTunnel + +sal_Int64 SAL_CALL ScHeaderFieldObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScHeaderFieldObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScHeaderFieldObj* ScHeaderFieldObj::getImplementation( + const uno::Reference<text::XTextContent> xObj ) +{ + ScHeaderFieldObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScHeaderFieldObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScHeaderFieldObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScHeaderFieldObj" )); +} + +sal_Bool SAL_CALL ScHeaderFieldObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCTEXTFIELD_SERVICE ) || + aServiceStr.EqualsAscii( SCTEXTCONTENT_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScHeaderFieldObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(2); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTFIELD_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCTEXTCONTENT_SERVICE )); + return aRet; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_filtuno.cxx b/bf_sc/source/ui/unoobj/sc_filtuno.cxx new file mode 100644 index 000000000..8e8ef48f0 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_filtuno.cxx @@ -0,0 +1,241 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> +#include <tools/urlobj.hxx> +#include <unotools/ucbstreamhelper.hxx> + +#include "filtuno.hxx" +#include "miscuno.hxx" +#include <vcl/svapp.hxx> +#include "imoptdlg.hxx" +#include "docsh.hxx" +#include "globstr.hrc" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +#define SCFILTEROPTIONSOBJ_SERVICE "com.sun.star.ui.dialogs.FilterOptionsDialog" +#define SCFILTEROPTIONSOBJ_IMPLNAME "com.sun.star.comp.Calc.FilterOptionsDialog" + +SC_SIMPLE_SERVICE_INFO( ScFilterOptionsObj, SCFILTEROPTIONSOBJ_IMPLNAME, SCFILTEROPTIONSOBJ_SERVICE ) + +#define SC_UNONAME_FILENAME "URL" +#define SC_UNONAME_FILTERNAME "FilterName" +#define SC_UNONAME_FILTEROPTIONS "FilterOptions" +#define SC_UNONAME_INPUTSTREAM "InputStream" + +//------------------------------------------------------------------------ + +ScFilterOptionsObj::ScFilterOptionsObj() : + bExport( sal_False ) +{ +} + +ScFilterOptionsObj::~ScFilterOptionsObj() +{ +} + +// stuff for exService_... + +uno::Reference<uno::XInterface> SAL_CALL ScFilterOptionsObj_CreateInstance( + const uno::Reference<lang::XMultiServiceFactory>& ) +{ + SolarMutexGuard aGuard; + SC_DLL()->Load(); // load module + + return (::cppu::OWeakObject*) new ScFilterOptionsObj; +} + +::rtl::OUString ScFilterOptionsObj::getImplementationName_Static() +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCFILTEROPTIONSOBJ_IMPLNAME )); +} + +uno::Sequence< ::rtl::OUString> ScFilterOptionsObj::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCFILTEROPTIONSOBJ_SERVICE )); + return aRet; +} + +// XPropertyAccess + +uno::Sequence<beans::PropertyValue> SAL_CALL ScFilterOptionsObj::getPropertyValues() throw(uno::RuntimeException) +{ + uno::Sequence<beans::PropertyValue> aRet(1); + beans::PropertyValue* pArray = aRet.getArray(); + + pArray[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_FILTEROPTIONS )); + pArray[0].Value <<= aFilterOptions; + + return aRet; +} + +void SAL_CALL ScFilterOptionsObj::setPropertyValues( const uno::Sequence<beans::PropertyValue>& aProps ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) +{ + const beans::PropertyValue* pPropArray = aProps.getConstArray(); + long nPropCount = aProps.getLength(); + for (long i = 0; i < nPropCount; i++) + { + const beans::PropertyValue& rProp = pPropArray[i]; + String aPropName = rProp.Name; + + if ( aPropName.EqualsAscii( SC_UNONAME_FILENAME ) ) + rProp.Value >>= aFileName; + else if ( aPropName.EqualsAscii( SC_UNONAME_FILTERNAME ) ) + rProp.Value >>= aFilterName; + else if ( aPropName.EqualsAscii( SC_UNONAME_FILTEROPTIONS ) ) + rProp.Value >>= aFilterOptions; + else if ( aPropName.EqualsAscii( SC_UNONAME_INPUTSTREAM ) ) + rProp.Value >>= xInputStream; + } +} + +// XExecutableDialog + +void SAL_CALL ScFilterOptionsObj::setTitle( const ::rtl::OUString& /*aTitle*/ ) throw(uno::RuntimeException) +{ + // not used +} + +sal_Int16 SAL_CALL ScFilterOptionsObj::execute() throw(uno::RuntimeException) +{ + sal_Int16 nRet = ui::dialogs::ExecutableDialogResults::CANCEL; + + String aFilterString( aFilterName ); + if ( !bExport && aFilterString == ScDocShell::GetAsciiFilterName() ) + { + // ascii import is special... + + INetURLObject aURL( aFileName ); + String aExt = aURL.getExtension(); + String aPrivDatName = aURL.getName(); + + SvStream* pInStream = NULL; + if ( xInputStream.is() ) + pInStream = ::utl::UcbStreamHelper::CreateStream( xInputStream ); + + delete pInStream; + } + else + { + sal_Unicode cStrDel = '"'; + sal_Unicode cAsciiDel = ';'; + rtl_TextEncoding eEncoding = RTL_TEXTENCODING_DONTKNOW; + + String aTitle; + + if ( aFilterString == ScDocShell::GetAsciiFilterName() ) + { + // ascii export (import is handled above) + + INetURLObject aURL( aFileName ); + String aExt = aURL.getExtension(); + if (aExt.EqualsIgnoreCaseAscii("CSV")) + cAsciiDel = ','; + else + cAsciiDel = '\t'; + + aTitle = ScGlobal::GetRscString( STR_EXPORT_ASCII ); + } + else if ( aFilterString == ScDocShell::GetLotusFilterName() ) + { + // lotus is only imported + DBG_ASSERT( !bExport, "Filter Options for Lotus Export is not implemented" ); + + aTitle = ScGlobal::GetRscString( STR_IMPORT_LOTUS ); + eEncoding = RTL_TEXTENCODING_IBM_437; + } + else if ( aFilterString == ScDocShell::GetDBaseFilterName() ) + { + if ( bExport ) + { + // dBase export + aTitle = ScGlobal::GetRscString( STR_EXPORT_DBF ); + } + else + { + // dBase import + aTitle = ScGlobal::GetRscString( STR_IMPORT_DBF ); + } + // common for dBase import/export + eEncoding = RTL_TEXTENCODING_IBM_850; + } + else if ( aFilterString == ScDocShell::GetDifFilterName() ) + { + if ( bExport ) + { + // DIF export + aTitle = ScGlobal::GetRscString( STR_EXPORT_DIF ); + } + else + { + // DIF import + aTitle = ScGlobal::GetRscString( STR_IMPORT_DIF ); + } + // common for DIF import/export + eEncoding = RTL_TEXTENCODING_MS_1252; + } + + ScImportOptions aOptions( cAsciiDel, cStrDel, eEncoding); + } + + xInputStream.clear(); // don't hold the stream longer than necessary + + return nRet; +} + +// XImporter + +void SAL_CALL ScFilterOptionsObj::setTargetDocument( const uno::Reference<lang::XComponent>& /*xDoc*/ ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + bExport = sal_False; +} + +// XExporter + +void SAL_CALL ScFilterOptionsObj::setSourceDocument( const uno::Reference<lang::XComponent>& /*xDoc*/ ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + bExport = sal_True; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_fmtuno.cxx b/bf_sc/source/ui/unoobj/sc_fmtuno.cxx new file mode 100644 index 000000000..6da1ef8ce --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_fmtuno.cxx @@ -0,0 +1,856 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <rtl/uuid.h> + +#include <com/sun/star/sheet/ValidationAlertStyle.hpp> +#include <com/sun/star/sheet/ValidationType.hpp> + +#include "fmtuno.hxx" +#include "miscuno.hxx" +#include "validat.hxx" +#include "document.hxx" +#include <vcl/svapp.hxx> +#include "unonames.hxx" +#include "styleuno.hxx" // ScStyleNameConversion +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +// Map nur fuer PropertySetInfo + +const SfxItemPropertyMap* lcl_GetValidatePropertyMap() +{ + static SfxItemPropertyMap aValidatePropertyMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ERRALSTY), 0, &getCppuType((sheet::ValidationAlertStyle*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ERRMESS), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_ERRTITLE), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_IGNOREBL), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_INPMESS), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_INPTITLE), 0, &getCppuType((::rtl::OUString*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_SHOWERR), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_SHOWINP), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNONAME_TYPE), 0, &getCppuType((sheet::ValidationType*)0), 0,0}, + {0,0,0,0,0,0} + }; + return aValidatePropertyMap_Impl; +} + +//------------------------------------------------------------------------ + +SC_SIMPLE_SERVICE_INFO( ScTableConditionalEntry, "ScTableConditionalEntry", "com.sun.star.sheet.TableConditionalEntry" ) +SC_SIMPLE_SERVICE_INFO( ScTableConditionalFormat, "ScTableConditionalFormat", "com.sun.star.sheet.TableConditionalFormat" ) +SC_SIMPLE_SERVICE_INFO( ScTableValidationObj, "ScTableValidationObj", "com.sun.star.sheet.TableValidation" ) + +//------------------------------------------------------------------------ + +sheet::ConditionOperator lcl_ConditionModeToOperator( ScConditionMode eMode ) +{ + sheet::ConditionOperator eOper = sheet::ConditionOperator_NONE; + switch (eMode) + { + case SC_COND_EQUAL: eOper = sheet::ConditionOperator_EQUAL; break; + case SC_COND_LESS: eOper = sheet::ConditionOperator_LESS; break; + case SC_COND_GREATER: eOper = sheet::ConditionOperator_GREATER; break; + case SC_COND_EQLESS: eOper = sheet::ConditionOperator_LESS_EQUAL; break; + case SC_COND_EQGREATER: eOper = sheet::ConditionOperator_GREATER_EQUAL; break; + case SC_COND_NOTEQUAL: eOper = sheet::ConditionOperator_NOT_EQUAL; break; + case SC_COND_BETWEEN: eOper = sheet::ConditionOperator_BETWEEN; break; + case SC_COND_NOTBETWEEN: eOper = sheet::ConditionOperator_NOT_BETWEEN; break; + case SC_COND_DIRECT: eOper = sheet::ConditionOperator_FORMULA; break; + default: break; + } + return eOper; +} + +ScConditionMode lcl_ConditionOperatorToMode( sheet::ConditionOperator eOper ) +{ + ScConditionMode eMode = SC_COND_NONE; + switch (eOper) + { + case sheet::ConditionOperator_EQUAL: eMode = SC_COND_EQUAL; break; + case sheet::ConditionOperator_LESS: eMode = SC_COND_LESS; break; + case sheet::ConditionOperator_GREATER: eMode = SC_COND_GREATER; break; + case sheet::ConditionOperator_LESS_EQUAL: eMode = SC_COND_EQLESS; break; + case sheet::ConditionOperator_GREATER_EQUAL: eMode = SC_COND_EQGREATER; break; + case sheet::ConditionOperator_NOT_EQUAL: eMode = SC_COND_NOTEQUAL; break; + case sheet::ConditionOperator_BETWEEN: eMode = SC_COND_BETWEEN; break; + case sheet::ConditionOperator_NOT_BETWEEN: eMode = SC_COND_NOTBETWEEN; break; + case sheet::ConditionOperator_FORMULA: eMode = SC_COND_DIRECT; break; + default: break; + } + return eMode; +} + +//------------------------------------------------------------------------ + +ScTableConditionalFormat::ScTableConditionalFormat(ScDocument* pDoc, ULONG nKey, + BOOL bEnglish, BOOL bCompileXML) +{ + // Eintrag aus dem Dokument lesen... + + if ( pDoc && nKey ) + { + ScConditionalFormatList* pList = pDoc->GetCondFormList(); + if (pList) + { + const ScConditionalFormat* pFormat = pList->GetFormat( nKey ); + if (pFormat) + { + USHORT nEntryCount = pFormat->Count(); + for (USHORT i=0; i<nEntryCount; i++) + { + const ScCondFormatEntry* pFormatEntry = pFormat->GetEntry(i); + ScConditionMode eMode = pFormatEntry->GetOperation(); + ScAddress aPos = pFormatEntry->GetSrcPos(); + String aExpr1 = pFormatEntry->GetExpression( aPos, 0, 0, bEnglish, bCompileXML ); + String aExpr2 = pFormatEntry->GetExpression( aPos, 1, 0, bEnglish, bCompileXML ); + String aStyle = pFormatEntry->GetStyle(); + + AddEntry_Impl( eMode, aExpr1, aExpr2, aPos, aStyle ); + } + } + } + } +} + +void ScTableConditionalFormat::FillFormat( ScConditionalFormat& rFormat, + ScDocument* pDoc, BOOL bEnglish, BOOL bCompileXML ) const +{ + // ScConditionalFormat = Core-Struktur, muss leer sein + + DBG_ASSERT( rFormat.IsEmpty(), "FillFormat: Format nicht leer" ); + USHORT nCount = (USHORT)aEntries.Count(); + for (USHORT i=0; i<nCount; i++) + { + ScTableConditionalEntry* pEntry = (ScTableConditionalEntry*)aEntries.GetObject(i); + if (pEntry) + { + USHORT nMode; + String aExpr1, aExpr2, aStyle; + ScAddress aPos; + pEntry->GetData( nMode, aExpr1, aExpr2, aPos, aStyle ); + ScCondFormatEntry aCoreEntry( (ScConditionMode)nMode, + aExpr1, aExpr2, pDoc, aPos, aStyle, bEnglish, bCompileXML ); + rFormat.AddEntry( aCoreEntry ); + } + } +} + +ScTableConditionalFormat::~ScTableConditionalFormat() +{ + ScTableConditionalEntry* pEntry; + aEntries.First(); + while ( (pEntry = (ScTableConditionalEntry*)aEntries.Remove()) ) + pEntry->release(); +} + +void ScTableConditionalFormat::AddEntry_Impl( USHORT nMode, + const String& rExpr1, const String& rExpr2, + const ScAddress& rPos, const String& rStyle ) +{ + ScTableConditionalEntry* pNew = new ScTableConditionalEntry( + this, nMode, rExpr1, rExpr2, rPos, rStyle ); + pNew->acquire(); + aEntries.Insert( pNew, LIST_APPEND ); +} + +void ScTableConditionalFormat::DataChanged() +{ + // wenn's mal das "lebende Objekt" ist, muss hier was passieren... +} + +// XSheetConditionalFormat + +ScTableConditionalEntry* ScTableConditionalFormat::GetObjectByIndex_Impl(USHORT nIndex) const +{ + return (ScTableConditionalEntry*)aEntries.GetObject(nIndex); +} + +void SAL_CALL ScTableConditionalFormat::addNew( + const uno::Sequence<beans::PropertyValue >& aConditionalEntry ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScConditionMode eMode = SC_COND_NONE; + String aExpr1; + String aExpr2; + ScAddress aPos; + String aStyle; + + const beans::PropertyValue* pPropArray = aConditionalEntry.getConstArray(); + long nPropCount = aConditionalEntry.getLength(); + for (long i = 0; i < nPropCount; i++) + { + const beans::PropertyValue& rProp = pPropArray[i]; + String aPropName = rProp.Name; + + if ( aPropName.EqualsAscii( SC_UNONAME_OPERATOR ) ) + { + sheet::ConditionOperator eOper = (sheet::ConditionOperator) + ScUnoHelpFunctions::GetEnumFromAny( rProp.Value ); + eMode = lcl_ConditionOperatorToMode( eOper ); + } + else if ( aPropName.EqualsAscii( SC_UNONAME_FORMULA1 ) ) + { + ::rtl::OUString aStrVal; + if ( rProp.Value >>= aStrVal ) + aExpr1 = String( aStrVal ); + } + else if ( aPropName.EqualsAscii( SC_UNONAME_FORMULA2 ) ) + { + ::rtl::OUString aStrVal; + if ( rProp.Value >>= aStrVal ) + aExpr2 = String( aStrVal ); + } + else if ( aPropName.EqualsAscii( SC_UNONAME_SOURCEPOS ) ) + { + table::CellAddress aAddress; + if ( rProp.Value >>= aAddress ) + aPos = ScAddress( (USHORT)aAddress.Column, (USHORT)aAddress.Row, aAddress.Sheet ); + } + else if ( aPropName.EqualsAscii( SC_UNONAME_STYLENAME ) ) + { + ::rtl::OUString aStrVal; + if ( rProp.Value >>= aStrVal ) + aStyle = ScStyleNameConversion::ProgrammaticToDisplayName( + aStrVal, SFX_STYLE_FAMILY_PARA ); + } + else + { + OSL_FAIL("falsche Property"); + //! Exception... + } + } + + AddEntry_Impl( eMode, aExpr1, aExpr2, aPos, aStyle ); + DataChanged(); +} + +void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScTableConditionalEntry* pEntry = (ScTableConditionalEntry*)aEntries.GetObject(nIndex); + if (pEntry) + { + aEntries.Remove(pEntry); + pEntry->release(); + DataChanged(); + } +} + +void SAL_CALL ScTableConditionalFormat::clear() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScTableConditionalEntry* pEntry; + aEntries.First(); + while ( (pEntry = (ScTableConditionalEntry*)aEntries.Remove()) ) + pEntry->release(); + + DataChanged(); +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScTableConditionalFormat::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.TableConditionalEntryEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScTableConditionalFormat::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aEntries.Count(); +} + +uno::Any SAL_CALL ScTableConditionalFormat::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XSheetConditionalEntry> xEntry = GetObjectByIndex_Impl((USHORT)nIndex); + uno::Any aAny; + if (xEntry.is()) + aAny <<= xEntry; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScTableConditionalFormat::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XSheetConditionalEntry>*)0); +} + +sal_Bool SAL_CALL ScTableConditionalFormat::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// conditional format entries have no real names +// -> generate name from index + +::rtl::OUString lcl_GetEntryNameFromIndex( sal_Int32 nIndex ) +{ + ::rtl::OUString aRet( RTL_CONSTASCII_USTRINGPARAM( "Entry" ) ); + aRet += ::rtl::OUString::valueOf( nIndex ); + return aRet; +} + +uno::Any SAL_CALL ScTableConditionalFormat::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<sheet::XSheetConditionalEntry> xEntry; + long nCount = aEntries.Count(); + for (long i=0; i<nCount; i++) + if ( aName == lcl_GetEntryNameFromIndex(i) ) + { + xEntry = GetObjectByIndex_Impl((USHORT)i); + break; + } + + uno::Any aAny; + if (xEntry.is()) + aAny <<= xEntry; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScTableConditionalFormat::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + long nCount = aEntries.Count(); + uno::Sequence< ::rtl::OUString> aNames(nCount); + ::rtl::OUString* pArray = aNames.getArray(); + for (long i=0; i<nCount; i++) + pArray[i] = lcl_GetEntryNameFromIndex(i); + + return aNames; +} + +sal_Bool SAL_CALL ScTableConditionalFormat::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + long nCount = aEntries.Count(); + for (long i=0; i<nCount; i++) + if ( aName == lcl_GetEntryNameFromIndex(i) ) + return TRUE; + + return FALSE; +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScTableConditionalFormat::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScTableConditionalFormat::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScTableConditionalFormat* ScTableConditionalFormat::getImplementation( + const uno::Reference<sheet::XSheetConditionalEntries> xObj ) +{ + ScTableConditionalFormat* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScTableConditionalFormat*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +//------------------------------------------------------------------------ + +ScTableConditionalEntry::ScTableConditionalEntry( ScTableConditionalFormat* pPar, + USHORT nM, const String& rEx1, const String& rEx2, + const ScAddress& rPos, const String& rSt ) : + pParent( pPar ), + nMode( nM ), + aExpr1( rEx1 ), + aExpr2( rEx2 ), + aSrcPos( rPos ), + aStyle( rSt ) +{ + if (pParent) + pParent->acquire(); +} + +ScTableConditionalEntry::~ScTableConditionalEntry() +{ + if (pParent) + pParent->release(); +} + +void ScTableConditionalEntry::GetData( USHORT& rM, String& rEx1, String& rEx2, + ScAddress& rPos, String& rSt ) const +{ + rM = nMode; + rEx1 = aExpr1; + rEx2 = aExpr2; + rPos = aSrcPos; + rSt = aStyle; +} + +// XSheetCondition + +sheet::ConditionOperator SAL_CALL ScTableConditionalEntry::getOperator() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return lcl_ConditionModeToOperator( (ScConditionMode)nMode ); +} + +void SAL_CALL ScTableConditionalEntry::setOperator( sheet::ConditionOperator nOperator ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + nMode = lcl_ConditionOperatorToMode( nOperator ); + if (pParent) + pParent->DataChanged(); +} + +::rtl::OUString SAL_CALL ScTableConditionalEntry::getFormula1() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aExpr1; +} + +void SAL_CALL ScTableConditionalEntry::setFormula1( const ::rtl::OUString& aFormula1 ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aExpr1 = String( aFormula1 ); + if (pParent) + pParent->DataChanged(); +} + +::rtl::OUString SAL_CALL ScTableConditionalEntry::getFormula2() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aExpr2; +} + +void SAL_CALL ScTableConditionalEntry::setFormula2( const ::rtl::OUString& aFormula2 ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aExpr2 = String( aFormula2 ); + if (pParent) + pParent->DataChanged(); +} + +table::CellAddress SAL_CALL ScTableConditionalEntry::getSourcePosition() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellAddress aRet; + aRet.Column = aSrcPos.Col(); + aRet.Row = aSrcPos.Row(); + aRet.Sheet = aSrcPos.Tab(); + return aRet; +} + +void SAL_CALL ScTableConditionalEntry::setSourcePosition( const table::CellAddress& aSourcePosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aSrcPos.Set( (USHORT)aSourcePosition.Column, (USHORT)aSourcePosition.Row, aSourcePosition.Sheet ); + if (pParent) + pParent->DataChanged(); +} + +// XSheetConditionalEntry + +::rtl::OUString SAL_CALL ScTableConditionalEntry::getStyleName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ScStyleNameConversion::DisplayToProgrammaticName( aStyle, SFX_STYLE_FAMILY_PARA ); +} + +void SAL_CALL ScTableConditionalEntry::setStyleName( const ::rtl::OUString& aStyleName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aStyle = ScStyleNameConversion::ProgrammaticToDisplayName( aStyleName, SFX_STYLE_FAMILY_PARA ); + if (pParent) + pParent->DataChanged(); +} + +ScTableValidationObj::ScTableValidationObj(ScDocument* pDoc, ULONG nKey, + BOOL bEnglish, BOOL bCompileXML) : + aPropSet( lcl_GetValidatePropertyMap() ) +{ + // Eintrag aus dem Dokument lesen... + + BOOL bFound = FALSE; + if ( pDoc && nKey ) + { + const ScValidationData* pData = pDoc->GetValidationEntry( nKey ); + if (pData) + { + nMode = pData->GetOperation(); + aSrcPos = pData->GetSrcPos(); + aExpr1 = pData->GetExpression( aSrcPos, 0, 0, bEnglish, bCompileXML ); + aExpr2 = pData->GetExpression( aSrcPos, 1, 0, bEnglish, bCompileXML ); + nValMode = pData->GetDataMode(); + bIgnoreBlank = pData->IsIgnoreBlank(); + bShowInput = pData->GetInput( aInputTitle, aInputMessage ); + ScValidErrorStyle eStyle; + bShowError = pData->GetErrMsg( aErrorTitle, aErrorMessage, eStyle ); + nErrorStyle = eStyle; + + bFound = TRUE; + } + } + if (!bFound) + ClearData_Impl(); // Defaults +} + +ScValidationData* ScTableValidationObj::CreateValidationData( ScDocument* pDoc, + BOOL bEnglish, BOOL bCompileXML ) const +{ + // ScValidationData = Core-Struktur + + ScValidationData* pRet = new ScValidationData( (ScValidationMode)nValMode, + (ScConditionMode)nMode, + aExpr1, aExpr2, pDoc, aSrcPos, + bEnglish, bCompileXML ); + pRet->SetIgnoreBlank(bIgnoreBlank); + + // set strings for error / input even if disabled (and disable afterwards) + pRet->SetInput( aInputTitle, aInputMessage ); + if (!bShowInput) + pRet->ResetInput(); + pRet->SetError( aErrorTitle, aErrorMessage, (ScValidErrorStyle)nErrorStyle ); + if (!bShowError) + pRet->ResetError(); + + return pRet; +} + +void ScTableValidationObj::ClearData_Impl() +{ + nMode = SC_COND_NONE; + nValMode = SC_VALID_ANY; + bIgnoreBlank = TRUE; + bShowInput = FALSE; + bShowError = FALSE; + nErrorStyle = SC_VALERR_STOP; + aSrcPos.Set(0,0,0); + aExpr1.Erase(); + aExpr2.Erase(); + aInputTitle.Erase(); + aInputMessage.Erase(); + aErrorTitle.Erase(); + aErrorMessage.Erase(); +} + +ScTableValidationObj::~ScTableValidationObj() +{ +} + +void ScTableValidationObj::DataChanged() +{ + // wenn's mal das "lebende Objekt" ist, muss hier was passieren... +} + +// XSheetCondition + +sheet::ConditionOperator SAL_CALL ScTableValidationObj::getOperator() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return lcl_ConditionModeToOperator( (ScConditionMode)nMode ); +} + +void SAL_CALL ScTableValidationObj::setOperator( sheet::ConditionOperator nOperator ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + nMode = lcl_ConditionOperatorToMode( nOperator ); + DataChanged(); +} + +::rtl::OUString SAL_CALL ScTableValidationObj::getFormula1() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aExpr1; +} + +void SAL_CALL ScTableValidationObj::setFormula1( const ::rtl::OUString& aFormula1 ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aExpr1 = String( aFormula1 ); + DataChanged(); +} + +::rtl::OUString SAL_CALL ScTableValidationObj::getFormula2() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aExpr2; +} + +void SAL_CALL ScTableValidationObj::setFormula2( const ::rtl::OUString& aFormula2 ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aExpr2 = String( aFormula2 ); + DataChanged(); +} + +table::CellAddress SAL_CALL ScTableValidationObj::getSourcePosition() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellAddress aRet; + aRet.Column = aSrcPos.Col(); + aRet.Row = aSrcPos.Row(); + aRet.Sheet = aSrcPos.Tab(); + return aRet; +} + +void SAL_CALL ScTableValidationObj::setSourcePosition( const table::CellAddress& aSourcePosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + aSrcPos.Set( (USHORT)aSourcePosition.Column, (USHORT)aSourcePosition.Row, aSourcePosition.Sheet ); + DataChanged(); +} + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScTableValidationObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScTableValidationObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + + if ( aString.EqualsAscii( SC_UNONAME_SHOWINP ) ) bShowInput = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if ( aString.EqualsAscii( SC_UNONAME_SHOWERR ) ) bShowError = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if ( aString.EqualsAscii( SC_UNONAME_IGNOREBL ) ) bIgnoreBlank = ScUnoHelpFunctions::GetBoolFromAny( aValue ); + else if ( aString.EqualsAscii( SC_UNONAME_INPTITLE ) ) + { + ::rtl::OUString aStrVal; + if ( aValue >>= aStrVal ) + aInputTitle = String( aStrVal ); + } + else if ( aString.EqualsAscii( SC_UNONAME_INPMESS ) ) + { + ::rtl::OUString aStrVal; + if ( aValue >>= aStrVal ) + aInputMessage = String( aStrVal ); + } + else if ( aString.EqualsAscii( SC_UNONAME_ERRTITLE ) ) + { + ::rtl::OUString aStrVal; + if ( aValue >>= aStrVal ) + aErrorTitle = String( aStrVal ); + } + else if ( aString.EqualsAscii( SC_UNONAME_ERRMESS ) ) + { + ::rtl::OUString aStrVal; + if ( aValue >>= aStrVal ) + aErrorMessage = String( aStrVal ); + } + else if ( aString.EqualsAscii( SC_UNONAME_TYPE ) ) + { + sheet::ValidationType eType = (sheet::ValidationType) + ScUnoHelpFunctions::GetEnumFromAny( aValue ); + switch (eType) + { + case sheet::ValidationType_ANY: nValMode = SC_VALID_ANY; break; + case sheet::ValidationType_WHOLE: nValMode = SC_VALID_WHOLE; break; + case sheet::ValidationType_DECIMAL: nValMode = SC_VALID_DECIMAL; break; + case sheet::ValidationType_DATE: nValMode = SC_VALID_DATE; break; + case sheet::ValidationType_TIME: nValMode = SC_VALID_TIME; break; + case sheet::ValidationType_TEXT_LEN: nValMode = SC_VALID_TEXTLEN; break; + case sheet::ValidationType_LIST: nValMode = SC_VALID_LIST; break; + case sheet::ValidationType_CUSTOM: nValMode = SC_VALID_CUSTOM; break; + default: break; + } + } + else if ( aString.EqualsAscii( SC_UNONAME_ERRALSTY ) ) + { + sheet::ValidationAlertStyle eStyle = (sheet::ValidationAlertStyle) + ScUnoHelpFunctions::GetEnumFromAny( aValue ); + switch (eStyle) + { + case sheet::ValidationAlertStyle_STOP: nErrorStyle = SC_VALERR_STOP; break; + case sheet::ValidationAlertStyle_WARNING: nErrorStyle = SC_VALERR_WARNING; break; + case sheet::ValidationAlertStyle_INFO: nErrorStyle = SC_VALERR_INFO; break; + case sheet::ValidationAlertStyle_MACRO: nErrorStyle = SC_VALERR_MACRO; break; + default: break; + } + } + + DataChanged(); +} + +uno::Any SAL_CALL ScTableValidationObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + uno::Any aRet; + + if ( aString.EqualsAscii( SC_UNONAME_SHOWINP ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowInput ); + else if ( aString.EqualsAscii( SC_UNONAME_SHOWERR ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bShowError ); + else if ( aString.EqualsAscii( SC_UNONAME_IGNOREBL ) ) ScUnoHelpFunctions::SetBoolInAny( aRet, bIgnoreBlank ); + else if ( aString.EqualsAscii( SC_UNONAME_INPTITLE ) ) aRet <<= ::rtl::OUString( aInputTitle ); + else if ( aString.EqualsAscii( SC_UNONAME_INPMESS ) ) aRet <<= ::rtl::OUString( aInputMessage ); + else if ( aString.EqualsAscii( SC_UNONAME_ERRTITLE ) ) aRet <<= ::rtl::OUString( aErrorTitle ); + else if ( aString.EqualsAscii( SC_UNONAME_ERRMESS ) ) aRet <<= ::rtl::OUString( aErrorMessage ); + else if ( aString.EqualsAscii( SC_UNONAME_TYPE ) ) + { + sheet::ValidationType eType = sheet::ValidationType_ANY; + switch (nValMode) + { + case SC_VALID_ANY: eType = sheet::ValidationType_ANY; break; + case SC_VALID_WHOLE: eType = sheet::ValidationType_WHOLE; break; + case SC_VALID_DECIMAL: eType = sheet::ValidationType_DECIMAL; break; + case SC_VALID_DATE: eType = sheet::ValidationType_DATE; break; + case SC_VALID_TIME: eType = sheet::ValidationType_TIME; break; + case SC_VALID_TEXTLEN: eType = sheet::ValidationType_TEXT_LEN; break; + case SC_VALID_LIST: eType = sheet::ValidationType_LIST; break; + case SC_VALID_CUSTOM: eType = sheet::ValidationType_CUSTOM; break; + } + aRet <<= eType; + } + else if ( aString.EqualsAscii( SC_UNONAME_ERRALSTY ) ) + { + sheet::ValidationAlertStyle eStyle = sheet::ValidationAlertStyle_STOP; + switch (nErrorStyle) + { + case SC_VALERR_STOP: eStyle = sheet::ValidationAlertStyle_STOP; break; + case SC_VALERR_WARNING: eStyle = sheet::ValidationAlertStyle_WARNING; break; + case SC_VALERR_INFO: eStyle = sheet::ValidationAlertStyle_INFO; break; + case SC_VALERR_MACRO: eStyle = sheet::ValidationAlertStyle_MACRO; break; + } + aRet <<= eStyle; + } + + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScTableValidationObj ) + +// XUnoTunnel + +sal_Int64 SAL_CALL ScTableValidationObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScTableValidationObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScTableValidationObj* ScTableValidationObj::getImplementation( + const uno::Reference<beans::XPropertySet> xObj ) +{ + ScTableValidationObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScTableValidationObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +//------------------------------------------------------------------------ + + + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_forbiuno.cxx b/bf_sc/source/ui/unoobj/sc_forbiuno.cxx new file mode 100644 index 000000000..f27039d7c --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_forbiuno.cxx @@ -0,0 +1,88 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <bf_svx/forbiddencharacterstable.hxx> + +#include "forbiuno.hxx" +#include "docsh.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +rtl::Reference<SvxForbiddenCharactersTable> lcl_GetForbidden( ScDocShell* pDocSh ) +{ + rtl::Reference<SvxForbiddenCharactersTable> xRet; + if ( pDocSh ) + { + ScDocument* pDoc = pDocSh->GetDocument(); + xRet = pDoc->GetForbiddenCharacters(); + if ( !xRet.is() ) + { + // create an empty SvxForbiddenCharactersTable for SvxUnoForbiddenCharsTable, + // so changes can be stored. + + xRet = new SvxForbiddenCharactersTable( pDoc->GetServiceManager() ); + pDoc->SetForbiddenCharacters( xRet ); + } + } + return xRet; +} + +ScForbiddenCharsObj::ScForbiddenCharsObj( ScDocShell* pDocSh ) : + SvxUnoForbiddenCharsTable( lcl_GetForbidden( pDocSh ) ), + pDocShell( pDocSh ) +{ + if (pDocShell) + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScForbiddenCharsObj::~ScForbiddenCharsObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScForbiddenCharsObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // document gone + } +} + +void ScForbiddenCharsObj::onChange() +{ + if (pDocShell) + { + pDocShell->GetDocument()->SetForbiddenCharacters( mxForbiddenChars ); + pDocShell->PostPaintGridAll(); + pDocShell->SetDocumentModified(); + } +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_funcuno.cxx b/bf_sc/source/ui/unoobj/sc_funcuno.cxx new file mode 100644 index 000000000..aab90f947 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_funcuno.cxx @@ -0,0 +1,713 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <bf_sfx2/app.hxx> + +#include "funcuno.hxx" +#include "miscuno.hxx" +#include "cellsuno.hxx" +#include <vcl/svapp.hxx> +#include "scdll.hxx" +#include "document.hxx" +#include "callform.hxx" +#include "addincol.hxx" +#include "rangeseq.hxx" +#include "cell.hxx" +#include "optuno.hxx" + +// for lcl_CopyData: +#include "markdata.hxx" +#include "patattr.hxx" +#include "docpool.hxx" +#include "attrib.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +// registered as implementation for service FunctionAccess, +// also supports service SpreadsheetDocumentSettings (to set null date etc.) + +#define SCFUNCTIONACCESS_SERVICE "com.sun.star.sheet.FunctionAccess" +#define SCDOCSETTINGS_SERVICE "com.sun.star.sheet.SpreadsheetDocumentSettings" + +//------------------------------------------------------------------------ + +// helper to use cached document if not in use, temporary document otherwise + +class ScTempDocSource +{ +private: + ScTempDocCache& rCache; + ScDocument* pTempDoc; + + static ScDocument* CreateDocument(); // create and initialize doc + +public: + ScTempDocSource( ScTempDocCache& rDocCache ); + ~ScTempDocSource(); + + ScDocument* GetDocument(); +}; + +//------------------------------------------------------------------------ + +// static +ScDocument* ScTempDocSource::CreateDocument() +{ + ScDocument* pDoc = new ScDocument; // SCDOCMODE_DOCUMENT + pDoc->MakeTable( 0 ); + return pDoc; +} + +ScTempDocSource::ScTempDocSource( ScTempDocCache& rDocCache ) : + rCache( rDocCache ), + pTempDoc( NULL ) +{ + if ( rCache.IsInUse() ) + pTempDoc = CreateDocument(); + else + { + rCache.SetInUse( TRUE ); + if ( !rCache.GetDocument() ) + rCache.SetDocument( CreateDocument() ); + } +} + +ScTempDocSource::~ScTempDocSource() +{ + if ( pTempDoc ) + delete pTempDoc; + else + rCache.SetInUse( FALSE ); +} + +ScDocument* ScTempDocSource::GetDocument() +{ + if ( pTempDoc ) + return pTempDoc; + else + return rCache.GetDocument(); +} + + +ScTempDocCache::ScTempDocCache() : + pDoc( NULL ), + bInUse( FALSE ) +{ +} + +ScTempDocCache::~ScTempDocCache() +{ + DBG_ASSERT( !bInUse, "ScTempDocCache dtor: bInUse" ); + delete pDoc; +} + +void ScTempDocCache::SetDocument( ScDocument* pNew ) +{ + DBG_ASSERT( !pDoc, "ScTempDocCache::SetDocument: already set" ); + pDoc = pNew; +} + +void ScTempDocCache::Clear() +{ + DBG_ASSERT( !bInUse, "ScTempDocCache::Clear: bInUse" ); + delete pDoc; + pDoc = NULL; +} + +// copy results from one document into another +//! merge this with ScAreaLink::Refresh +//! copy directly without a clipboard document? + +BOOL lcl_CopyData( ScDocument* pSrcDoc, const ScRange& rSrcRange, + ScDocument* pDestDoc, const ScAddress& rDestPos ) +{ + USHORT nSrcTab = rSrcRange.aStart.Tab(); + USHORT nDestTab = rDestPos.Tab(); + + ScRange aNewRange( rDestPos, ScAddress( + rSrcRange.aEnd.Col() - rSrcRange.aStart.Col() + rDestPos.Col(), + rSrcRange.aEnd.Row() - rSrcRange.aStart.Row() + rDestPos.Row(), + nDestTab ) ); + + ScDocument* pClipDoc = new ScDocument( SCDOCMODE_CLIP ); + ScMarkData aSourceMark; + aSourceMark.SelectOneTable( nSrcTab ); // for CopyToClip + aSourceMark.SetMarkArea( rSrcRange ); + pSrcDoc->CopyToClip( rSrcRange.aStart.Col(),rSrcRange.aStart.Row(), + rSrcRange.aEnd.Col(),rSrcRange.aEnd.Row(), + FALSE, pClipDoc, FALSE, &aSourceMark ); + + if ( pClipDoc->HasAttrib( 0,0,nSrcTab, MAXCOL,MAXROW,nSrcTab, + HASATTR_MERGED | HASATTR_OVERLAPPED ) ) + { + ScPatternAttr aPattern( pSrcDoc->GetPool() ); + aPattern.GetItemSet().Put( ScMergeAttr() ); // Defaults + aPattern.GetItemSet().Put( ScMergeFlagAttr() ); + pClipDoc->ApplyPatternAreaTab( 0,0, MAXCOL,MAXROW, nSrcTab, aPattern ); + } + + ScMarkData aDestMark; + aDestMark.SelectOneTable( nDestTab ); + aDestMark.SetMarkArea( aNewRange ); + pDestDoc->CopyFromClip( aNewRange, aDestMark, IDF_ALL & ~IDF_FORMULA, NULL, pClipDoc, FALSE ); + + delete pClipDoc; + return TRUE; +} + +ScFunctionAccess::ScFunctionAccess() + : pOptions( NULL ) + , bInvalid( FALSE ) +{ + StartListening( *SFX_APP() ); // for SFX_HINT_DEINITIALIZING +} + +ScFunctionAccess::~ScFunctionAccess() +{ + delete pOptions; +} + +void ScFunctionAccess::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA(SfxSimpleHint) && + ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_DEINITIALIZING ) + { + // document must not be used anymore + aDocCache.Clear(); + bInvalid = TRUE; + } +} + +// stuff for exService_... + +uno::Reference<uno::XInterface> SAL_CALL ScFunctionAccess_CreateInstance( + const uno::Reference<lang::XMultiServiceFactory>& ) +{ + SolarMutexGuard aGuard; + SC_DLL()->Load(); // load module + static uno::Reference< uno::XInterface > xInst = (::cppu::OWeakObject*) new ScFunctionAccess; + return xInst; +} + +::rtl::OUString ScFunctionAccess::getImplementationName_Static() +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "stardiv.StarCalc.ScFunctionAccess" )); +} + +uno::Sequence< ::rtl::OUString> ScFunctionAccess::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCFUNCTIONACCESS_SERVICE )); + return aRet; +} + +// XServiceInfo + +::rtl::OUString SAL_CALL ScFunctionAccess::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScFunctionAccess" )); +} + +sal_Bool SAL_CALL ScFunctionAccess::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr = rServiceName; + return aServiceStr.EqualsAscii( SCFUNCTIONACCESS_SERVICE ) || + aServiceStr.EqualsAscii( SCDOCSETTINGS_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScFunctionAccess::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(2); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCFUNCTIONACCESS_SERVICE )); + pArray[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCDOCSETTINGS_SERVICE )); + return aRet; +} + +// XPropertySet (document settings) + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScFunctionAccess::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( ScDocOptionsHelper::GetPropertyMap() ); + return aRef; +} + +void SAL_CALL ScFunctionAccess::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !pOptions ) + pOptions = new ScDocOptions(); + + // options aren't initialized from configuration - always get the same default behaviour + + BOOL bDone = ScDocOptionsHelper::setPropertyValue( *pOptions, aPropertyName, aValue ); + if (!bDone) + throw beans::UnknownPropertyException(); +} + +uno::Any SAL_CALL ScFunctionAccess::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( !pOptions ) + pOptions = new ScDocOptions(); + + // options aren't initialized from configuration - always get the same default behaviour + + return ScDocOptionsHelper::getPropertyValue( *pOptions, aPropertyName ); +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScFunctionAccess ) + +// XFunctionAccess + +BOOL lcl_AddFunctionToken( ScTokenArray& rArray, const ::rtl::OUString& rName ) +{ + // function names are always case-insensitive + String aUpper( ScGlobal::pCharClass->uppercase( rName ) ); + + // same options as in ScCompiler::IsOpCode: + // 1. built-in function name + + DBG_ASSERT( ScCompiler::pSymbolHashMapEnglish, "no symbol hash map" ); + if (!ScCompiler::pSymbolHashMapEnglish) + return FALSE; + + ScOpCodeHashMap::const_iterator iLook( ScCompiler::pSymbolHashMapEnglish->find( aUpper ) ); + if ( iLook != ScCompiler::pSymbolHashMapEnglish->end() ) + { + rArray.AddOpCode( iLook->second ); + return TRUE; + } + + // 2. old add in functions + + USHORT nIndex; + if ( ScGlobal::GetFuncCollection()->SearchFunc( aUpper, nIndex ) ) + { + rArray.AddExternal( aUpper.GetBuffer() ); + return TRUE; + } + + // 3. new (uno) add in functions + + String aIntName = ScGlobal::GetAddInCollection()->FindFunction( aUpper, FALSE ); + if (aIntName.Len()) + { + rArray.AddExternal( aIntName.GetBuffer() ); // international name + return TRUE; + } + + return FALSE; // no valid function name +} + +void lcl_AddRef( ScTokenArray& rArray, long nStartRow, long nColCount, long nRowCount ) +{ + ComplRefData aRef; + aRef.InitFlags(); + aRef.Ref1.nTab = 0; + aRef.Ref2.nTab = 0; + aRef.Ref1.nCol = 0; + aRef.Ref1.nRow = (USHORT) nStartRow; + aRef.Ref2.nCol = (USHORT) (nColCount - 1); + aRef.Ref2.nRow = (USHORT) (nStartRow + nRowCount - 1); + rArray.AddDoubleReference(aRef); +} + +uno::Any SAL_CALL ScFunctionAccess::callFunction( const ::rtl::OUString& aName, + const uno::Sequence<uno::Any>& aArguments ) + throw(container::NoSuchElementException, lang::IllegalArgumentException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if (bInvalid) + throw uno::RuntimeException(); + + // use cached document if not in use, temporary document otherwise + // (deleted in ScTempDocSource dtor) + ScTempDocSource aSource( aDocCache ); + ScDocument* pDoc = aSource.GetDocument(); + + if (!ScCompiler::pSymbolTableEnglish) + { + ScCompiler aComp( pDoc, ScAddress() ); + aComp.SetCompileEnglish( TRUE ); // setup english symbol table + } + + // + // find function + // + + ScTokenArray aTokenArr; + if ( !lcl_AddFunctionToken( aTokenArr, aName ) ) + { + // function not found + throw container::NoSuchElementException(); + } + + // + // set options (null date, etc.) + // + + if ( pOptions ) + pDoc->SetDocOptions( *pOptions ); + + // + // add arguments to token array + // + + BOOL bArgErr = FALSE; + BOOL bOverflow = FALSE; + long nDocRow = 0; + long nArgCount = aArguments.getLength(); + const uno::Any* pArgArr = aArguments.getConstArray(); + + aTokenArr.AddOpCode(ocOpen); + for (long nPos=0; nPos<nArgCount; nPos++) + { + if ( nPos > 0 ) + aTokenArr.AddOpCode(ocSep); + + const uno::Any& rArg = pArgArr[nPos]; + + uno::TypeClass eClass = rArg.getValueTypeClass(); + uno::Type aType = rArg.getValueType(); + if ( eClass == uno::TypeClass_BYTE || + eClass == uno::TypeClass_SHORT || + eClass == uno::TypeClass_UNSIGNED_SHORT || + eClass == uno::TypeClass_LONG || + eClass == uno::TypeClass_UNSIGNED_LONG || + eClass == uno::TypeClass_FLOAT || + eClass == uno::TypeClass_DOUBLE ) + { + // #87871# accept integer types because Basic passes a floating point + // variable as byte, short or long if it's an integer number. + double fVal(0.0); + rArg >>= fVal; + aTokenArr.AddDouble( fVal ); + } + else if ( eClass == uno::TypeClass_STRING ) + { + ::rtl::OUString aUStr; + rArg >>= aUStr; + String aStr( aUStr ); + aTokenArr.AddString( aStr.GetBuffer() ); + } + else if ( aType.equals( getCppuType( (uno::Sequence< uno::Sequence<sal_Int16> > *)0 ) ) ) + { + uno::Sequence< uno::Sequence<sal_Int16> > aRowSeq; + rArg >>= aRowSeq; + + long nStartRow = nDocRow; + long nMaxColCount = 0; + long nRowCount = aRowSeq.getLength(); + const uno::Sequence<sal_Int16>* pRowArr = aRowSeq.getConstArray(); + for (long nRow=0; nRow<nRowCount; nRow++) + { + long nColCount = pRowArr[nRow].getLength(); + if ( nColCount > nMaxColCount ) + nMaxColCount = nColCount; + const sal_Int16* pColArr = pRowArr[nRow].getConstArray(); + for (long nCol=0; nCol<nColCount; nCol++) + if ( nCol <= MAXCOL && nDocRow <= MAXROW ) + pDoc->SetValue( (USHORT) nCol, (USHORT) nDocRow, 0, pColArr[nCol] ); + else + bOverflow = TRUE; + ++nDocRow; + } + + if ( nRowCount && nMaxColCount && !bOverflow ) + lcl_AddRef( aTokenArr, nStartRow, nMaxColCount, nRowCount ); + } + else if ( aType.equals( getCppuType( (uno::Sequence< uno::Sequence<sal_Int32> > *)0 ) ) ) + { + uno::Sequence< uno::Sequence<sal_Int32> > aRowSeq; + rArg >>= aRowSeq; + + long nStartRow = nDocRow; + long nMaxColCount = 0; + long nRowCount = aRowSeq.getLength(); + const uno::Sequence<sal_Int32>* pRowArr = aRowSeq.getConstArray(); + for (long nRow=0; nRow<nRowCount; nRow++) + { + long nColCount = pRowArr[nRow].getLength(); + if ( nColCount > nMaxColCount ) + nMaxColCount = nColCount; + const sal_Int32* pColArr = pRowArr[nRow].getConstArray(); + for (long nCol=0; nCol<nColCount; nCol++) + if ( nCol <= MAXCOL && nDocRow <= MAXROW ) + pDoc->SetValue( (USHORT) nCol, (USHORT) nDocRow, 0, pColArr[nCol] ); + else + bOverflow = TRUE; + ++nDocRow; + } + + if ( nRowCount && nMaxColCount && !bOverflow ) + lcl_AddRef( aTokenArr, nStartRow, nMaxColCount, nRowCount ); + } + else if ( aType.equals( getCppuType( (uno::Sequence< uno::Sequence<double> > *)0 ) ) ) + { + uno::Sequence< uno::Sequence<double> > aRowSeq; + rArg >>= aRowSeq; + + long nStartRow = nDocRow; + long nMaxColCount = 0; + long nRowCount = aRowSeq.getLength(); + const uno::Sequence<double>* pRowArr = aRowSeq.getConstArray(); + for (long nRow=0; nRow<nRowCount; nRow++) + { + long nColCount = pRowArr[nRow].getLength(); + if ( nColCount > nMaxColCount ) + nMaxColCount = nColCount; + const double* pColArr = pRowArr[nRow].getConstArray(); + for (long nCol=0; nCol<nColCount; nCol++) + if ( nCol <= MAXCOL && nDocRow <= MAXROW ) + pDoc->SetValue( (USHORT) nCol, (USHORT) nDocRow, 0, pColArr[nCol] ); + else + bOverflow = TRUE; + ++nDocRow; + } + + if ( nRowCount && nMaxColCount && !bOverflow ) + lcl_AddRef( aTokenArr, nStartRow, nMaxColCount, nRowCount ); + } + else if ( aType.equals( getCppuType( (uno::Sequence< uno::Sequence< ::rtl::OUString> > *)0 ) ) ) + { + uno::Sequence< uno::Sequence< ::rtl::OUString> > aRowSeq; + rArg >>= aRowSeq; + + long nStartRow = nDocRow; + long nMaxColCount = 0; + long nRowCount = aRowSeq.getLength(); + const uno::Sequence< ::rtl::OUString>* pRowArr = aRowSeq.getConstArray(); + for (long nRow=0; nRow<nRowCount; nRow++) + { + long nColCount = pRowArr[nRow].getLength(); + if ( nColCount > nMaxColCount ) + nMaxColCount = nColCount; + const ::rtl::OUString* pColArr = pRowArr[nRow].getConstArray(); + for (long nCol=0; nCol<nColCount; nCol++) + if ( nCol <= MAXCOL && nDocRow <= MAXROW ) + { + if ( pColArr[nCol].getLength() ) + pDoc->PutCell( (USHORT) nCol, (USHORT) nDocRow, 0, + new ScStringCell( pColArr[nCol] ) ); + } + else + bOverflow = TRUE; + ++nDocRow; + } + + if ( nRowCount && nMaxColCount && !bOverflow ) + lcl_AddRef( aTokenArr, nStartRow, nMaxColCount, nRowCount ); + } + else if ( aType.equals( getCppuType( (uno::Sequence< uno::Sequence<uno::Any> > *)0 ) ) ) + { + uno::Sequence< uno::Sequence<uno::Any> > aRowSeq; + rArg >>= aRowSeq; + + long nStartRow = nDocRow; + long nMaxColCount = 0; + long nRowCount = aRowSeq.getLength(); + const uno::Sequence<uno::Any>* pRowArr = aRowSeq.getConstArray(); + for (long nRow=0; nRow<nRowCount; nRow++) + { + long nColCount = pRowArr[nRow].getLength(); + if ( nColCount > nMaxColCount ) + nMaxColCount = nColCount; + const uno::Any* pColArr = pRowArr[nRow].getConstArray(); + for (long nCol=0; nCol<nColCount; nCol++) + if ( nCol <= MAXCOL && nDocRow <= MAXROW ) + { + const uno::Any& rElement = pColArr[nCol]; + uno::TypeClass eElemClass = rElement.getValueTypeClass(); + if ( eElemClass == uno::TypeClass_VOID ) + { + // leave empty + } + else if ( eElemClass == uno::TypeClass_BYTE || + eElemClass == uno::TypeClass_SHORT || + eElemClass == uno::TypeClass_UNSIGNED_SHORT || + eElemClass == uno::TypeClass_LONG || + eElemClass == uno::TypeClass_UNSIGNED_LONG || + eElemClass == uno::TypeClass_FLOAT || + eElemClass == uno::TypeClass_DOUBLE ) + { + // #87871# accept integer types because Basic passes a floating point + // variable as byte, short or long if it's an integer number. + double fVal(0.0); + rElement >>= fVal; + pDoc->SetValue( (USHORT) nCol, (USHORT) nDocRow, 0, fVal ); + } + else if ( eElemClass == uno::TypeClass_STRING ) + { + ::rtl::OUString aUStr; + rElement >>= aUStr; + if ( aUStr.getLength() ) + pDoc->PutCell( (USHORT) nCol, (USHORT) nDocRow, 0, + new ScStringCell( aUStr ) ); + } + else + bArgErr = TRUE; // invalid type + } + else + bOverflow = TRUE; + ++nDocRow; + } + + if ( nRowCount && nMaxColCount && !bOverflow ) + lcl_AddRef( aTokenArr, nStartRow, nMaxColCount, nRowCount ); + } + else if ( aType.equals( getCppuType( (uno::Reference<table::XCellRange>*)0 ) ) ) + { + // currently, only our own cell ranges are supported + + uno::Reference<table::XCellRange> xRange; + rArg >>= xRange; + ScCellRangesBase* pImpl = ScCellRangesBase::getImplementation( xRange ); + if ( pImpl ) + { + ScDocument* pSrcDoc = pImpl->GetDocument(); + const ScRangeList& rRanges = pImpl->GetRangeList(); + if ( pSrcDoc && rRanges.Count() == 1 ) + { + ScRange aSrcRange = *rRanges.GetObject(0); + + long nStartRow = nDocRow; + long nColCount = aSrcRange.aEnd.Col() - aSrcRange.aStart.Col() + 1; + long nRowCount = aSrcRange.aEnd.Row() - aSrcRange.aStart.Row() + 1; + + if ( nStartRow + nRowCount > MAXROW ) + bOverflow = TRUE; + else + { + // copy data + if ( !lcl_CopyData( pSrcDoc, aSrcRange, pDoc, ScAddress( 0, (USHORT)nDocRow, 0 ) ) ) + bOverflow = TRUE; + } + + nDocRow += nRowCount; + if ( !bOverflow ) + lcl_AddRef( aTokenArr, nStartRow, nColCount, nRowCount ); + } + else + bArgErr = TRUE; + } + else + bArgErr = TRUE; + } + else + bArgErr = TRUE; // invalid type + } + aTokenArr.AddOpCode(ocClose); + aTokenArr.AddOpCode(ocStop); + + // + // execute formula + // + + uno::Any aRet; + if ( !bArgErr && !bOverflow && nDocRow <= MAXROW ) + { + ScAddress aFormulaPos( 0, (USHORT)nDocRow, 0 ); + ScFormulaCell* pFormula = new ScFormulaCell( pDoc, aFormulaPos, &aTokenArr, MM_FORMULA ); + pDoc->PutCell( aFormulaPos, pFormula ); //! necessary? + + // call GetMatrix before GetErrCode because GetMatrix always recalculates + // if there is no matrix result + + ScMatrix* pMat = NULL; + pFormula->GetMatrix(&pMat); + USHORT nErrCode = pFormula->GetErrCode(); + if ( nErrCode == 0 ) + { + if ( pMat ) + { + // array result + ScRangeToSequence::FillMixedArray( aRet, pMat ); + } + else if ( pFormula->IsValue() ) + { + // numeric value + aRet <<= (double) pFormula->GetValue(); + } + else + { + // string result + String aStrVal; + pFormula->GetString( aStrVal ); + aRet <<= ::rtl::OUString( aStrVal ); + } + } + else if ( nErrCode == NOVALUE ) + { + // #N/A: leave result empty, no exception + } + else + { + // any other error: IllegalArgumentException + bArgErr = TRUE; + } + + pDoc->DeleteAreaTab( 0, 0, MAXCOL, MAXROW, 0, IDF_ALL ); + } + + if (bOverflow) + throw uno::RuntimeException(); + + if (bArgErr) + throw lang::IllegalArgumentException(); + + return aRet; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_linkuno.cxx b/bf_sc/source/ui/unoobj/sc_linkuno.cxx new file mode 100644 index 000000000..69ffb2aac --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_linkuno.cxx @@ -0,0 +1,1323 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <bf_svx/linkmgr.hxx> + +#include "linkuno.hxx" +#include "miscuno.hxx" +#include "convuno.hxx" +#include "docsh.hxx" +#include "docfunc.hxx" +#include "collect.hxx" +#include "tablink.hxx" +#include "arealink.hxx" +#include <vcl/svapp.hxx> +#include "hints.hxx" +#include "unonames.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +// fuer Sheet- und Area-Links benutzt: +const SfxItemPropertyMap* lcl_GetSheetLinkMap() +{ + static SfxItemPropertyMap aSheetLinkMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_FILTER), 0, &getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_FILTOPT), 0, &getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LINKURL), 0, &getCppuType((::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_REFDELAY), 0, &getCppuType((sal_Int32*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aSheetLinkMap_Impl; +} + + +SV_IMPL_PTRARR( XRefreshListenerArr_Impl, XRefreshListenerPtr ); + +SC_SIMPLE_SERVICE_INFO( ScAreaLinkObj, "ScAreaLinkObj", "com.sun.star.sheet.CellAreaLink" ) +SC_SIMPLE_SERVICE_INFO( ScAreaLinksObj, "ScAreaLinksObj", "com.sun.star.sheet.CellAreaLinks" ) +SC_SIMPLE_SERVICE_INFO( ScDDELinkObj, "ScDDELinkObj", "com.sun.star.sheet.DDELink" ) +SC_SIMPLE_SERVICE_INFO( ScDDELinksObj, "ScDDELinksObj", "com.sun.star.sheet.DDELinks" ) +SC_SIMPLE_SERVICE_INFO( ScSheetLinkObj, "ScSheetLinkObj", "com.sun.star.sheet.SheetLink" ) +SC_SIMPLE_SERVICE_INFO( ScSheetLinksObj, "ScSheetLinksObj", "com.sun.star.sheet.SheetLinks" ) + + +ScSheetLinkObj::ScSheetLinkObj(ScDocShell* pDocSh, const String& rName) : + aPropSet( lcl_GetSheetLinkMap() ), + pDocShell( pDocSh ), + aFileName( rName ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScSheetLinkObj::~ScSheetLinkObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScSheetLinkObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! notify if links in document are changed + // UpdateRef is not needed here + + if ( rHint.ISA( SfxSimpleHint ) ) + { + if ( ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + pDocShell = NULL; // pointer is invalid + } + else if ( rHint.ISA( ScLinkRefreshedHint ) ) + { + const ScLinkRefreshedHint& rLH = (const ScLinkRefreshedHint&) rHint; + if ( rLH.GetLinkType() == SC_LINKREFTYPE_SHEET && rLH.GetUrl() == aFileName ) + Refreshed_Impl(); + } +} + +ScTableLink* ScSheetLinkObj::GetLink_Impl() const +{ + if (pDocShell) + { + SvxLinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager(); + USHORT nCount = pLinkManager->GetLinks().Count(); + for (USHORT i=0; i<nCount; i++) + { + ::binfilter::SvBaseLink* pBase = *pLinkManager->GetLinks()[i]; + if (pBase->ISA(ScTableLink)) + { + ScTableLink* pTabLink = (ScTableLink*)pBase; + if ( pTabLink->GetFileName() == aFileName ) + return pTabLink; + } + } + } + return NULL; // nicht gefunden +} + +// XNamed + +::rtl::OUString SAL_CALL ScSheetLinkObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getFileName(); // Name ist der Dateiname (URL) +} + +void SAL_CALL ScSheetLinkObj::setName( const ::rtl::OUString& aName ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + setFileName(aName); // Name ist der Dateiname (URL) +} + +// XRefreshable + +void SAL_CALL ScSheetLinkObj::refresh() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScTableLink* pLink = GetLink_Impl(); + if (pLink) + pLink->Refresh( pLink->GetFileName(), pLink->GetFilterName(), NULL, pLink->GetRefreshDelay() ); +} + +void SAL_CALL ScSheetLinkObj::addRefreshListener( + const uno::Reference<util::XRefreshListener >& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<util::XRefreshListener>* pObj = + new uno::Reference<util::XRefreshListener>( xListener ); + aRefreshListeners.Insert( pObj, aRefreshListeners.Count() ); + + // hold one additional ref to keep this object alive as long as there are listeners + if ( aRefreshListeners.Count() == 1 ) + acquire(); +} + +void SAL_CALL ScSheetLinkObj::removeRefreshListener( + const uno::Reference<util::XRefreshListener >& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = aRefreshListeners.Count(); + for ( USHORT n=nCount; n--; ) + { + uno::Reference<util::XRefreshListener>* pObj = aRefreshListeners[n]; + if ( *pObj == xListener ) + { + aRefreshListeners.DeleteAndDestroy( n ); + if ( aRefreshListeners.Count() == 0 ) + release(); // release ref for listeners + break; + } + } +} + +void ScSheetLinkObj::Refreshed_Impl() +{ + lang::EventObject aEvent; + aEvent.Source = (cppu::OWeakObject*)this; + for ( USHORT n=0; n<aRefreshListeners.Count(); n++ ) + (*aRefreshListeners[n])->refreshed( aEvent ); +} + +void ScSheetLinkObj::ModifyRefreshDelay_Impl( sal_Int32 nRefresh ) +{ + ScTableLink* pLink = GetLink_Impl(); + if( pLink ) + pLink->SetRefreshDelay( (ULONG) nRefresh ); +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScSheetLinkObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScSheetLinkObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + ::rtl::OUString aValStr; + if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) ) + { + if ( aValue >>= aValStr ) + setFileName( aValStr ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) ) + { + if ( aValue >>= aValStr ) + setFilter( aValStr ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) ) + { + if ( aValue >>= aValStr ) + setFilterOptions( aValStr ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) ) + { + sal_Int32 nRefresh = 0; + if ( aValue >>= nRefresh ) + setRefreshDelay( nRefresh ); + } +} + +uno::Any SAL_CALL ScSheetLinkObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + uno::Any aRet; + if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) ) + aRet <<= getFileName(); + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) ) + aRet <<= getFilter(); + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) ) + aRet <<= getFilterOptions(); + else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) ) + aRet <<= getRefreshDelay(); + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScSheetLinkObj ) + +// internal: + +::rtl::OUString ScSheetLinkObj::getFileName(void) const +{ + SolarMutexGuard aGuard; + return aFileName; +} + +void ScSheetLinkObj::setFileName(const ::rtl::OUString& rNewName) +{ + SolarMutexGuard aGuard; + ScTableLink* pLink = GetLink_Impl(); + if (pLink) + { + // pLink->Refresh mit neuem Dateinamen bringt SvxLinkManager durcheinander + // darum per Hand die Tabellen umsetzen und Link per UpdateLinks neu erzeugen + + String aNewStr = rNewName; + aNewStr = ScGlobal::GetAbsDocName( aNewStr, pDocShell ); + + // zuerst Tabellen umsetzen + + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nTabCount = pDoc->GetTableCount(); + for (USHORT nTab=0; nTab<nTabCount; nTab++) + if ( pDoc->IsLinked(nTab) && pDoc->GetLinkDoc(nTab) == aFileName ) // alte Datei + pDoc->SetLink( nTab, pDoc->GetLinkMode(nTab), aNewStr, + pDoc->GetLinkFlt(nTab), pDoc->GetLinkOpt(nTab), + pDoc->GetLinkTab(nTab), + pDoc->GetLinkRefreshDelay(nTab) ); // nur Datei aendern + + // Links updaten + //! Undo !!! + + pLink = NULL; // wird bei UpdateLinks ungueltig + pDocShell->UpdateLinks(); // alter Link raus, evtl. neuen Link anlegen + + // Daten kopieren + + aFileName = aNewStr; + pLink = GetLink_Impl(); // neuer Link mit neuem Namen + if (pLink) + pLink->Update(); // inkl. Paint & Undo fuer Daten + } +} + +::rtl::OUString ScSheetLinkObj::getFilter(void) const +{ + SolarMutexGuard aGuard; + ::rtl::OUString aRet; + ScTableLink* pLink = GetLink_Impl(); + if (pLink) + aRet = pLink->GetFilterName(); + return aRet; +} + +void ScSheetLinkObj::setFilter(const ::rtl::OUString& Filter) +{ + SolarMutexGuard aGuard; + ScTableLink* pLink = GetLink_Impl(); + if (pLink) + { + String aFilterStr = Filter; + pLink->Refresh( aFileName, aFilterStr, NULL, pLink->GetRefreshDelay() ); + } +} + +::rtl::OUString ScSheetLinkObj::getFilterOptions(void) const +{ + SolarMutexGuard aGuard; + ::rtl::OUString aRet; + ScTableLink* pLink = GetLink_Impl(); + if (pLink) + aRet = pLink->GetOptions(); + return aRet; +} + +void ScSheetLinkObj::setFilterOptions(const ::rtl::OUString& FilterOptions) +{ + SolarMutexGuard aGuard; + ScTableLink* pLink = GetLink_Impl(); + if (pLink) + { + String aOptStr = FilterOptions; + pLink->Refresh( aFileName, pLink->GetFilterName(), &aOptStr, pLink->GetRefreshDelay() ); + } +} + +sal_Int32 ScSheetLinkObj::getRefreshDelay(void) const +{ + SolarMutexGuard aGuard; + sal_Int32 nRet = 0; + ScTableLink* pLink = GetLink_Impl(); + if (pLink) + nRet = (sal_Int32) pLink->GetRefreshDelay(); + return nRet; +} + +void ScSheetLinkObj::setRefreshDelay(sal_Int32 nRefreshDelay) +{ + SolarMutexGuard aGuard; + ModifyRefreshDelay_Impl( nRefreshDelay ); +} + + +ScSheetLinksObj::ScSheetLinksObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScSheetLinksObj::~ScSheetLinksObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScSheetLinksObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XSheetLinks + +ScSheetLinkObj* ScSheetLinksObj::GetObjectByIndex_Impl(INT32 nIndex) +{ + if (pDocShell) + { + INT32 nCount = 0; + StrCollection aNames; // um doppelte wegzulassen + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nTabCount = pDoc->GetTableCount(); + for (USHORT nTab=0; nTab<nTabCount; nTab++) + if (pDoc->IsLinked(nTab)) + { + String aLinkDoc = pDoc->GetLinkDoc( nTab ); + StrData* pData = new StrData(aLinkDoc); + if (aNames.Insert(pData)) + { + if ( nCount == nIndex ) + return new ScSheetLinkObj( pDocShell, aLinkDoc ); + ++nCount; + } + else + delete pData; + } + } + return NULL; // kein Dokument oder Index zu gross +} + +ScSheetLinkObj* ScSheetLinksObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + // Name ist der Dateiname + + if (pDocShell) + { + String aNameStr = aName; + + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nTabCount = pDoc->GetTableCount(); + for (USHORT nTab=0; nTab<nTabCount; nTab++) + if (pDoc->IsLinked(nTab)) + { + //! case-insensitiv ??? + String aLinkDoc = pDoc->GetLinkDoc( nTab ); + if ( aLinkDoc == aNameStr ) + return new ScSheetLinkObj( pDocShell, aNameStr ); + } + } + + return NULL; +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScSheetLinksObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SheetLinksEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScSheetLinksObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + INT32 nCount = 0; + if (pDocShell) + { + StrCollection aNames; // um doppelte wegzulassen + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nTabCount = pDoc->GetTableCount(); + for (USHORT nTab=0; nTab<nTabCount; nTab++) + if (pDoc->IsLinked(nTab)) + { + String aLinkDoc = pDoc->GetLinkDoc( nTab ); + StrData* pData = new StrData(aLinkDoc); + if (aNames.Insert(pData)) + ++nCount; + else + delete pData; + } + } + return nCount; +} + +uno::Any SAL_CALL ScSheetLinksObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<beans::XPropertySet> xLink = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xLink.is()) + aAny <<= xLink; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScSheetLinksObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<beans::XPropertySet>*)0); +} + +sal_Bool SAL_CALL ScSheetLinksObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Any SAL_CALL ScSheetLinksObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<beans::XPropertySet> xLink = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xLink.is()) + aAny <<= xLink; + else + throw container::NoSuchElementException(); + return aAny; +} + +sal_Bool SAL_CALL ScSheetLinksObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // Name ist der Dateiname + + if (pDocShell) + { + String aNameStr = aName; + + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nTabCount = pDoc->GetTableCount(); + for (USHORT nTab=0; nTab<nTabCount; nTab++) + if (pDoc->IsLinked(nTab)) + { + //! case-insensitiv ??? + String aLinkDoc = pDoc->GetLinkDoc( nTab ); + if ( aLinkDoc == aNameStr ) + return TRUE; + } + } + return FALSE; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScSheetLinksObj::getElementNames() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // Name ist der Dateiname + + if (pDocShell) + { + StrCollection aNames; // um doppelte wegzulassen + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nTabCount = pDoc->GetTableCount(); + String aName; + + INT32 nLinkCount = getCount(); + uno::Sequence< ::rtl::OUString> aSeq(nLinkCount); + ::rtl::OUString* pAry = aSeq.getArray(); + USHORT nPos = 0; + for (USHORT nTab=0; nTab<nTabCount; nTab++) + { + if (pDoc->IsLinked(nTab)) + { + String aLinkDoc = pDoc->GetLinkDoc( nTab ); + StrData* pData = new StrData(aLinkDoc); + if (aNames.Insert(pData)) + pAry[nPos++] = aLinkDoc; + else + delete pData; + } + } + DBG_ASSERT( nPos==nLinkCount, "verzaehlt" ); + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(); +} + + +ScAreaLink* lcl_GetAreaLink( ScDocShell* pDocShell, USHORT nPos ) +{ + if (pDocShell) + { + SvxLinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager(); + USHORT nTotalCount = pLinkManager->GetLinks().Count(); + USHORT nAreaCount = 0; + for (USHORT i=0; i<nTotalCount; i++) + { + ::binfilter::SvBaseLink* pBase = *pLinkManager->GetLinks()[i]; + if (pBase->ISA(ScAreaLink)) + { + if ( nAreaCount == nPos ) + return (ScAreaLink*)pBase; + ++nAreaCount; + } + } + } + return NULL; // nicht gefunden +} + +ScAreaLinkObj::ScAreaLinkObj(ScDocShell* pDocSh, USHORT nP) : + aPropSet( lcl_GetSheetLinkMap() ), + pDocShell( pDocSh ), + nPos( nP ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScAreaLinkObj::~ScAreaLinkObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScAreaLinkObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! notify if links in document are changed + // UpdateRef is not needed here + + if ( rHint.ISA( SfxSimpleHint ) ) + { + if ( ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + pDocShell = NULL; // pointer is invalid + } + else if ( rHint.ISA( ScLinkRefreshedHint ) ) + { + const ScLinkRefreshedHint& rLH = (const ScLinkRefreshedHint&) rHint; + if ( rLH.GetLinkType() == SC_LINKREFTYPE_AREA ) + { + // get this link to compare dest position + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if ( pLink && pLink->GetDestArea().aStart == rLH.GetDestPos() ) + Refreshed_Impl(); + } + } +} + +// XFileLink + +void ScAreaLinkObj::Modify_Impl( const ::rtl::OUString* pNewFile, const ::rtl::OUString* pNewFilter, + const ::rtl::OUString* pNewOptions, const ::rtl::OUString* pNewSource, + const table::CellRangeAddress* pNewDest ) +{ + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + { + String aFile = pLink->GetFile(); + String aFilter = pLink->GetFilter(); + String aOptions = pLink->GetOptions(); + String aSource = pLink->GetSource(); + ScRange aDest = pLink->GetDestArea(); + ULONG nRefresh = pLink->GetRefreshDelay(); + + //! Undo fuer Loeschen + //! Undo zusammenfassen + + SvxLinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager(); + pLinkManager->Remove( pLink ); + pLink = NULL; // bei Remove geloescht + + BOOL bFitBlock = TRUE; // verschieben, wenn durch Update Groesse geaendert + if (pNewFile) + { + aFile = String( *pNewFile ); + aFile = ScGlobal::GetAbsDocName( aFile, pDocShell ); //! in InsertAreaLink? + } + if (pNewFilter) + aFilter = String( *pNewFilter ); + if (pNewOptions) + aOptions = String( *pNewOptions ); + if (pNewSource) + aSource = String( *pNewSource ); + if (pNewDest) + { + ScUnoConversion::FillScRange( aDest, *pNewDest ); + bFitBlock = FALSE; // neuer Bereich angegeben -> keine Inhalte verschieben + } + + ScDocFunc aFunc(*pDocShell); + aFunc.InsertAreaLink( aFile, aFilter, aOptions, aSource, aDest, nRefresh, bFitBlock ); + } +} + +void ScAreaLinkObj::ModifyRefreshDelay_Impl( sal_Int32 nRefresh ) +{ + ScAreaLink* pLink = lcl_GetAreaLink( pDocShell, nPos ); + if( pLink ) + pLink->SetRefreshDelay( (ULONG) nRefresh ); +} + +// XRefreshable + +void SAL_CALL ScAreaLinkObj::refresh() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + pLink->Refresh( pLink->GetFile(), pLink->GetFilter(), pLink->GetSource(), pLink->GetRefreshDelay() ); +} + +void SAL_CALL ScAreaLinkObj::addRefreshListener( + const uno::Reference<util::XRefreshListener >& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<util::XRefreshListener>* pObj = + new uno::Reference<util::XRefreshListener>( xListener ); + aRefreshListeners.Insert( pObj, aRefreshListeners.Count() ); + + // hold one additional ref to keep this object alive as long as there are listeners + if ( aRefreshListeners.Count() == 1 ) + acquire(); +} + +void SAL_CALL ScAreaLinkObj::removeRefreshListener( + const uno::Reference<util::XRefreshListener >& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = aRefreshListeners.Count(); + for ( USHORT n=nCount; n--; ) + { + uno::Reference<util::XRefreshListener>* pObj = aRefreshListeners[n]; + if ( *pObj == xListener ) + { + aRefreshListeners.DeleteAndDestroy( n ); + if ( aRefreshListeners.Count() == 0 ) + release(); // release ref for listeners + break; + } + } +} + +void ScAreaLinkObj::Refreshed_Impl() +{ + lang::EventObject aEvent; + aEvent.Source = (cppu::OWeakObject*)this; + for ( USHORT n=0; n<aRefreshListeners.Count(); n++ ) + (*aRefreshListeners[n])->refreshed( aEvent ); +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScAreaLinkObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference<beans::XPropertySetInfo> aRef = + new SfxItemPropertySetInfo( aPropSet.getPropertyMap() ); + return aRef; +} + +void SAL_CALL ScAreaLinkObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + ::rtl::OUString aValStr; + if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) ) + { + if ( aValue >>= aValStr ) + setFileName( aValStr ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) ) + { + if ( aValue >>= aValStr ) + setFilter( aValStr ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) ) + { + if ( aValue >>= aValStr ) + setFilterOptions( aValStr ); + } + else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) ) + { + sal_Int32 nRefresh = 0; + if ( aValue >>= nRefresh ) + setRefreshDelay( nRefresh ); + } +} + +uno::Any SAL_CALL ScAreaLinkObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + uno::Any aRet; + if ( aNameString.EqualsAscii( SC_UNONAME_LINKURL ) ) + aRet <<= getFileName(); + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTER ) ) + aRet <<= getFilter(); + else if ( aNameString.EqualsAscii( SC_UNONAME_FILTOPT ) ) + aRet <<= getFilterOptions(); + else if ( aNameString.EqualsAscii( SC_UNONAME_REFDELAY ) ) + aRet <<= getRefreshDelay(); + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScAreaLinkObj ) + +// internal: + +::rtl::OUString ScAreaLinkObj::getFileName(void) const +{ + SolarMutexGuard aGuard; + ::rtl::OUString aRet; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + aRet = pLink->GetFile(); + return aRet; +} + +void ScAreaLinkObj::setFileName(const ::rtl::OUString& rNewName) +{ + SolarMutexGuard aGuard; + Modify_Impl( &rNewName, NULL, NULL, NULL, NULL ); +} + +::rtl::OUString ScAreaLinkObj::getFilter(void) const +{ + SolarMutexGuard aGuard; + ::rtl::OUString aRet; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + aRet = pLink->GetFilter(); + return aRet; +} + +void ScAreaLinkObj::setFilter(const ::rtl::OUString& Filter) +{ + SolarMutexGuard aGuard; + Modify_Impl( NULL, &Filter, NULL, NULL, NULL ); +} + +::rtl::OUString ScAreaLinkObj::getFilterOptions(void) const +{ + SolarMutexGuard aGuard; + ::rtl::OUString aRet; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + aRet = pLink->GetOptions(); + return aRet; +} + +void ScAreaLinkObj::setFilterOptions(const ::rtl::OUString& FilterOptions) +{ + SolarMutexGuard aGuard; + Modify_Impl( NULL, NULL, &FilterOptions, NULL, NULL ); +} + +sal_Int32 ScAreaLinkObj::getRefreshDelay(void) const +{ + SolarMutexGuard aGuard; + sal_Int32 nRet = 0; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + nRet = (sal_Int32) pLink->GetRefreshDelay(); + return nRet; +} + +void ScAreaLinkObj::setRefreshDelay(sal_Int32 nRefreshDelay) +{ + SolarMutexGuard aGuard; + ModifyRefreshDelay_Impl( nRefreshDelay ); +} + +// XAreaLink + +::rtl::OUString SAL_CALL ScAreaLinkObj::getSourceArea() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ::rtl::OUString aRet; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + aRet = pLink->GetSource(); + return aRet; +} + +void SAL_CALL ScAreaLinkObj::setSourceArea( const ::rtl::OUString& aSourceArea ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + Modify_Impl( NULL, NULL, NULL, &aSourceArea, NULL ); +} + +table::CellRangeAddress SAL_CALL ScAreaLinkObj::getDestArea() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aRet; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, nPos); + if (pLink) + ScUnoConversion::FillApiRange( aRet, pLink->GetDestArea() ); + return aRet; +} + +void SAL_CALL ScAreaLinkObj::setDestArea( const table::CellRangeAddress& aDestArea ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + Modify_Impl( NULL, NULL, NULL, NULL, &aDestArea ); +} + +//------------------------------------------------------------------------ + +ScAreaLinksObj::ScAreaLinksObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScAreaLinksObj::~ScAreaLinksObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScAreaLinksObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XAreaLinks + +ScAreaLinkObj* ScAreaLinksObj::GetObjectByIndex_Impl(INT32 nIndex) +{ + if ( pDocShell && nIndex >= 0 && nIndex < getCount() ) + return new ScAreaLinkObj( pDocShell, (USHORT)nIndex ); + + return NULL; // nicht gefunden +} + +void SAL_CALL ScAreaLinksObj::insertAtPosition( const table::CellAddress& aDestPos, + const ::rtl::OUString& aFileName, + const ::rtl::OUString& aSourceArea, + const ::rtl::OUString& aFilter, + const ::rtl::OUString& aFilterOptions ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + String aFileStr = aFileName; + String aFilterStr = aFilter; + String aOptionStr = aFilterOptions; + String aSourceStr = aSourceArea; + ScAddress aDestAddr( (USHORT)aDestPos.Column, (USHORT)aDestPos.Row, aDestPos.Sheet ); + + aFileStr = ScGlobal::GetAbsDocName( aFileStr, pDocShell ); //! in InsertAreaLink ??? + + ScDocFunc aFunc(*pDocShell); + aFunc.InsertAreaLink( aFileStr, aFilterStr, aOptionStr, + aSourceStr, ScRange(aDestAddr), + 0, FALSE ); // keine Inhalte verschieben + } +} + +void SAL_CALL ScAreaLinksObj::removeByIndex( sal_Int32 nIndex ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAreaLink* pLink = lcl_GetAreaLink(pDocShell, (USHORT)nIndex); + if (pLink) + { + //! SetAddUndo oder so + + SvxLinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager(); + pLinkManager->Remove( pLink ); + } +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScAreaLinksObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.CellAreaLinksEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScAreaLinksObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + INT32 nAreaCount = 0; + if (pDocShell) + { + SvxLinkManager* pLinkManager = pDocShell->GetDocument()->GetLinkManager(); + USHORT nTotalCount = pLinkManager->GetLinks().Count(); + for (USHORT i=0; i<nTotalCount; i++) + { + ::binfilter::SvBaseLink* pBase = *pLinkManager->GetLinks()[i]; + if (pBase->ISA(ScAreaLink)) + ++nAreaCount; + } + } + return nAreaCount; +} + +uno::Any SAL_CALL ScAreaLinksObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XAreaLink> xLink = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xLink.is()) + aAny <<= xLink; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScAreaLinksObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XAreaLink>*)0); +} + +sal_Bool SAL_CALL ScAreaLinksObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +//------------------------------------------------------------------------ + +ScDDELinkObj::ScDDELinkObj(ScDocShell* pDocSh, const String& rA, + const String& rT, const String& rI) : + pDocShell( pDocSh ), + aAppl( rA ), + aTopic( rT ), + aItem( rI ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDDELinkObj::~ScDDELinkObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDDELinkObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! notify if links in document are changed + // UpdateRef is not needed here + + if ( rHint.ISA( SfxSimpleHint ) ) + { + if ( ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + pDocShell = NULL; // pointer is invalid + } + else if ( rHint.ISA( ScLinkRefreshedHint ) ) + { + const ScLinkRefreshedHint& rLH = (const ScLinkRefreshedHint&) rHint; + if ( rLH.GetLinkType() == SC_LINKREFTYPE_DDE && + rLH.GetDdeAppl() == aAppl && + rLH.GetDdeTopic() == aTopic && + rLH.GetDdeItem() == aItem ) //! mode is ignored + Refreshed_Impl(); + } +} + +// XNamed + +String lcl_BuildDDEName( const String& rAppl, const String& rTopic, const String& rItem ) +{ + // Appl|Topic!Item (wie Excel) + String aRet = rAppl; + aRet += '|'; + aRet += rTopic; + aRet += '!'; + aRet += rItem; + return aRet; +} + +::rtl::OUString SAL_CALL ScDDELinkObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return lcl_BuildDDEName( aAppl, aTopic, aItem ); +} + +void SAL_CALL ScDDELinkObj::setName( const ::rtl::OUString& /*aName*/ ) throw(uno::RuntimeException) +{ + // name can't be changed (formulas wouldn't find the link) + throw uno::RuntimeException(); +} + +// XDDELink + +::rtl::OUString SAL_CALL ScDDELinkObj::getApplication() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! Test, ob Link noch im Dokument enthalten? + + return aAppl; +} + +::rtl::OUString SAL_CALL ScDDELinkObj::getTopic() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! Test, ob Link noch im Dokument enthalten? + + return aTopic; +} + +::rtl::OUString SAL_CALL ScDDELinkObj::getItem() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! Test, ob Link noch im Dokument enthalten? + + return aItem; +} + +// XRefreshable + +void SAL_CALL ScDDELinkObj::refresh() throw(uno::RuntimeException) +{ +} + +void SAL_CALL ScDDELinkObj::addRefreshListener( + const uno::Reference<util::XRefreshListener >& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<util::XRefreshListener>* pObj = + new uno::Reference<util::XRefreshListener>( xListener ); + aRefreshListeners.Insert( pObj, aRefreshListeners.Count() ); + + // hold one additional ref to keep this object alive as long as there are listeners + if ( aRefreshListeners.Count() == 1 ) + acquire(); +} + +void SAL_CALL ScDDELinkObj::removeRefreshListener( + const uno::Reference<util::XRefreshListener >& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + USHORT nCount = aRefreshListeners.Count(); + for ( USHORT n=nCount; n--; ) + { + uno::Reference<util::XRefreshListener>* pObj = aRefreshListeners[n]; + if ( *pObj == xListener ) + { + aRefreshListeners.DeleteAndDestroy( n ); + if ( aRefreshListeners.Count() == 0 ) + release(); // release ref for listeners + break; + } + } +} + +void ScDDELinkObj::Refreshed_Impl() +{ + lang::EventObject aEvent; + aEvent.Source = (cppu::OWeakObject*)this; + for ( USHORT n=0; n<aRefreshListeners.Count(); n++ ) + (*aRefreshListeners[n])->refreshed( aEvent ); +} + + +ScDDELinksObj::ScDDELinksObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScDDELinksObj::~ScDDELinksObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScDDELinksObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XDDELinks + +ScDDELinkObj* ScDDELinksObj::GetObjectByIndex_Impl(INT32 nIndex) +{ + if (pDocShell) + { + String aAppl, aTopic, aItem; + if ( nIndex <= USHRT_MAX && + pDocShell->GetDocument()->GetDdeLinkData( (USHORT)nIndex, aAppl, aTopic, aItem ) ) + return new ScDDELinkObj( pDocShell, aAppl, aTopic, aItem ); + } + return NULL; +} + +ScDDELinkObj* ScDDELinksObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + if (pDocShell) + { + String aNamStr = aName; + String aAppl, aTopic, aItem; + + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nCount = pDoc->GetDdeLinkCount(); + for (USHORT i=0; i<nCount; i++) + { + pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem ); + if ( lcl_BuildDDEName(aAppl, aTopic, aItem) == aNamStr ) + return new ScDDELinkObj( pDocShell, aAppl, aTopic, aItem ); + } + } + return NULL; +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScDDELinksObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.DDELinksEnumeration"))); +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScDDELinksObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + INT32 nAreaCount = 0; + if (pDocShell) + nAreaCount = pDocShell->GetDocument()->GetDdeLinkCount(); + return nAreaCount; +} + +uno::Any SAL_CALL ScDDELinksObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XDDELink> xLink = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xLink.is()) + aAny <<= xLink; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScDDELinksObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<sheet::XDDELink>*)0); +} + +sal_Bool SAL_CALL ScDDELinksObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Any SAL_CALL ScDDELinksObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference<sheet::XDDELink> xLink = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xLink.is()) + aAny <<= xLink; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScDDELinksObj::getElementNames() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + String aAppl, aTopic, aItem; + + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nCount = pDoc->GetDdeLinkCount(); + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + + for (USHORT i=0; i<nCount; i++) + { + pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem ); + pAry[i] = lcl_BuildDDEName(aAppl, aTopic, aItem); + } + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(); +} + +sal_Bool SAL_CALL ScDDELinksObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + String aNamStr = aName; + String aAppl, aTopic, aItem; + + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nCount = pDoc->GetDdeLinkCount(); + for (USHORT i=0; i<nCount; i++) + { + pDoc->GetDdeLinkData( i, aAppl, aTopic, aItem ); + if ( lcl_BuildDDEName(aAppl, aTopic, aItem) == aNamStr ) + return TRUE; + } + } + return FALSE; +} + + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_miscuno.cxx b/bf_sc/source/ui/unoobj/sc_miscuno.cxx new file mode 100644 index 000000000..6458c3918 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_miscuno.cxx @@ -0,0 +1,367 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <bf_svtools/bf_solar.h> +#include <tools/debug.hxx> + +#include "miscuno.hxx" +#include <vcl/svapp.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + + +SC_SIMPLE_SERVICE_INFO( ScEmptyEnumeration, "ScEmptyEnumeration", "stardiv.unknown" ) +SC_SIMPLE_SERVICE_INFO( ScEmptyEnumerationAccess, "ScEmptyEnumerationAccess", "stardiv.unknown" ) +//SC_SIMPLE_SERVICE_INFO( ScIndexEnumeration, "ScIndexEnumeration", "stardiv.unknown" ) +SC_SIMPLE_SERVICE_INFO( ScPrintSettingsObj, "ScPrintSettingsObj", "stardiv.unknown" ) + +SC_SIMPLE_SERVICE_INFO( ScNameToIndexAccess, "ScNameToIndexAccess", "stardiv.unknown" ) + + +// static +uno::Reference<uno::XInterface> ScUnoHelpFunctions::AnyToInterface( const uno::Any& rAny ) +{ + if ( rAny.getValueTypeClass() == uno::TypeClass_INTERFACE ) + { + uno::Reference<uno::XInterface> xInterface; + rAny >>= xInterface; + return xInterface; + } + return uno::Reference<uno::XInterface>(); //! Exception? +} + +// static +sal_Bool ScUnoHelpFunctions::GetBoolProperty( const uno::Reference<beans::XPropertySet>& xProp, + const ::rtl::OUString& rName, sal_Bool bDefault ) +{ + sal_Bool bRet = bDefault; + if ( xProp.is() ) + { + try + { + uno::Any aAny = xProp->getPropertyValue( rName ); + //! type conversion??? + // operator >>= shouldn't be used for bool (?) + if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN ) + { + //! safe way to get bool value from any??? + bRet = *(sal_Bool*)aAny.getValue(); + } + } + catch(uno::Exception&) + { + // keep default + } + } + return bRet; +} + +// static +sal_Int32 ScUnoHelpFunctions::GetLongProperty( const uno::Reference<beans::XPropertySet>& xProp, + const ::rtl::OUString& rName, long nDefault ) +{ + sal_Int32 nRet = nDefault; + if ( xProp.is() ) + { + try + { + uno::Any aAny = xProp->getPropertyValue( rName ); + //! type conversion??? + aAny >>= nRet; + } + catch(uno::Exception&) + { + // keep default + } + } + return nRet; +} + +// static +sal_Int32 ScUnoHelpFunctions::GetEnumProperty( const uno::Reference<beans::XPropertySet>& xProp, + const ::rtl::OUString& rName, long nDefault ) +{ + sal_Int32 nRet = nDefault; + if ( xProp.is() ) + { + try + { + uno::Any aAny = xProp->getPropertyValue( rName ); + + if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM ) + { + //! get enum value from any??? + nRet = *(sal_Int32*)aAny.getValue(); + } + else + { + //! type conversion??? + aAny >>= nRet; + } + } + catch(uno::Exception&) + { + // keep default + } + } + return nRet; +} + +// static +sal_Bool ScUnoHelpFunctions::GetBoolFromAny( const uno::Any& aAny ) +{ + if ( aAny.getValueTypeClass() == uno::TypeClass_BOOLEAN ) + return *(sal_Bool*)aAny.getValue(); + return FALSE; +} + +// static +sal_Int16 ScUnoHelpFunctions::GetInt16FromAny( const uno::Any& aAny ) +{ + sal_Int16 nRet = 0; + if ( aAny >>= nRet ) + return nRet; + return 0; +} + +// static +sal_Int32 ScUnoHelpFunctions::GetInt32FromAny( const uno::Any& aAny ) +{ + sal_Int32 nRet = 0; + if ( aAny >>= nRet ) + return nRet; + return 0; +} + +// static +sal_Int32 ScUnoHelpFunctions::GetEnumFromAny( const uno::Any& aAny ) +{ + sal_Int32 nRet = 0; + if ( aAny.getValueTypeClass() == uno::TypeClass_ENUM ) + nRet = *(sal_Int32*)aAny.getValue(); + else + aAny >>= nRet; + return nRet; +} + +// static +void ScUnoHelpFunctions::SetBoolInAny( uno::Any& rAny, sal_Bool bValue ) +{ + rAny.setValue( &bValue, getBooleanCppuType() ); +} + + +ScIndexEnumeration::ScIndexEnumeration(const uno::Reference<container::XIndexAccess>& rInd, + const ::rtl::OUString& rServiceName) : + xIndex( rInd ), + sServiceName(rServiceName), + nPos( 0 ) +{ +} + +ScIndexEnumeration::~ScIndexEnumeration() +{ +} + +// XEnumeration + +sal_Bool SAL_CALL ScIndexEnumeration::hasMoreElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( nPos < xIndex->getCount() ); +} + +uno::Any SAL_CALL ScIndexEnumeration::nextElement() throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aReturn; + try + { + aReturn = xIndex->getByIndex(nPos++); + } + catch (lang::IndexOutOfBoundsException&) + { + throw container::NoSuchElementException(); + } + return aReturn; +} + +::rtl::OUString SAL_CALL ScIndexEnumeration::getImplementationName() + throw(::com::sun::star::uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScIndexEnumeration" )); +} + +sal_Bool SAL_CALL ScIndexEnumeration::supportsService( const ::rtl::OUString& ServiceName ) + throw(::com::sun::star::uno::RuntimeException) +{ + return sServiceName == ServiceName; +} + +::com::sun::star::uno::Sequence< ::rtl::OUString > + SAL_CALL ScIndexEnumeration::getSupportedServiceNames(void) + throw(::com::sun::star::uno::RuntimeException) +{ + ::com::sun::star::uno::Sequence< ::rtl::OUString > aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = sServiceName; + return aRet; +} + + +ScEmptyEnumerationAccess::~ScEmptyEnumerationAccess() +{ +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScEmptyEnumerationAccess::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScEmptyEnumeration; +} + +uno::Type SAL_CALL ScEmptyEnumerationAccess::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return getCppuType((uno::Reference<uno::XInterface>*)0); // or what? +} + +sal_Bool SAL_CALL ScEmptyEnumerationAccess::hasElements() throw(uno::RuntimeException) +{ + return FALSE; +} + + +ScEmptyEnumeration::ScEmptyEnumeration() +{ +} + +ScEmptyEnumeration::~ScEmptyEnumeration() +{ +} + +// XEnumeration + +sal_Bool SAL_CALL ScEmptyEnumeration::hasMoreElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return FALSE; +} + +uno::Any SAL_CALL ScEmptyEnumeration::nextElement() throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return uno::Any(); +} + +//------------------------------------------------------------------------ + +ScNameToIndexAccess::ScNameToIndexAccess( const ::com::sun::star::uno::Reference< + ::com::sun::star::container::XNameAccess>& rNameObj ) : + xNameAccess( rNameObj ) +{ + //! test for XIndexAccess interface at rNameObj, use that instead! + + if ( xNameAccess.is() ) + aNames = xNameAccess->getElementNames(); +} + +ScNameToIndexAccess::~ScNameToIndexAccess() +{ +} + +// XIndexAccess + +sal_Int32 SAL_CALL ScNameToIndexAccess::getCount( ) throw(::com::sun::star::uno::RuntimeException) +{ + return aNames.getLength(); +} + +::com::sun::star::uno::Any SAL_CALL ScNameToIndexAccess::getByIndex( sal_Int32 nIndex ) + throw(::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::lang::WrappedTargetException, + ::com::sun::star::uno::RuntimeException) +{ + if ( xNameAccess.is() && nIndex >= 0 && nIndex < aNames.getLength() ) + return xNameAccess->getByName( aNames.getConstArray()[nIndex] ); + + throw lang::IndexOutOfBoundsException(); +} + +// XElementAccess + +::com::sun::star::uno::Type SAL_CALL ScNameToIndexAccess::getElementType( ) + throw(::com::sun::star::uno::RuntimeException) +{ + if ( xNameAccess.is() ) + return xNameAccess->getElementType(); + else + return uno::Type(); +} + +sal_Bool SAL_CALL ScNameToIndexAccess::hasElements( ) throw(::com::sun::star::uno::RuntimeException) +{ + return getCount() > 0; +} + + +ScPrintSettingsObj::~ScPrintSettingsObj() +{ +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScPrintSettingsObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + return NULL; +} + +void SAL_CALL ScPrintSettingsObj::setPropertyValue( + const ::rtl::OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + //! later... +} + +uno::Any SAL_CALL ScPrintSettingsObj::getPropertyValue( const ::rtl::OUString& /*aPropertyName*/ ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + //! later... + return uno::Any(); +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScPrintSettingsObj ) + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_nameuno.cxx b/bf_sc/source/ui/unoobj/sc_nameuno.cxx new file mode 100644 index 000000000..c56400135 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_nameuno.cxx @@ -0,0 +1,926 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/sheet/NamedRangeFlag.hpp> +#include <com/sun/star/awt/XBitmap.hpp> + +using namespace ::com::sun::star; + + +#include "nameuno.hxx" +#include "miscuno.hxx" +#include "cellsuno.hxx" +#include "convuno.hxx" +#include "docsh.hxx" +#include "docfunc.hxx" +#include "rangenam.hxx" +#include "namecrea.hxx" // NAME_TOP etc. +#include <vcl/svapp.hxx> +#include "unonames.hxx" +namespace binfilter { + +//------------------------------------------------------------------------ + +const SfxItemPropertyMap* lcl_GetNamedRangeMap() +{ + static SfxItemPropertyMap aNamedRangeMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNO_LINKDISPBIT), 0, &getCppuType((uno::Reference<awt::XBitmap>*)0), beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNO_LINKDISPNAME), 0, &getCppuType((::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, + {0,0,0,0,0,0} + }; + return aNamedRangeMap_Impl; +} + + +#define SCNAMEDRANGEOBJ_SERVICE "com.sun.star.sheet.NamedRange" + +SC_SIMPLE_SERVICE_INFO( ScLabelRangeObj, "ScLabelRangeObj", "com.sun.star.sheet.LabelRange" ) +SC_SIMPLE_SERVICE_INFO( ScLabelRangesObj, "ScLabelRangesObj", "com.sun.star.sheet.LabelRanges" ) +SC_SIMPLE_SERVICE_INFO( ScNamedRangesObj, "ScNamedRangesObj", "com.sun.star.sheet.NamedRanges" ) + + +sal_Bool lcl_UserVisibleName( const ScRangeData* pData ) +{ + //! als Methode an ScRangeData + + return ( pData && !pData->HasType( RT_DATABASE ) && !pData->HasType( RT_SHARED ) ); +} + + +ScNamedRangeObj::ScNamedRangeObj(ScDocShell* pDocSh, const String& rNm) : + pDocShell( pDocSh ), + aName( rNm ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScNamedRangeObj::~ScNamedRangeObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScNamedRangeObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Ref-Update interessiert nicht + + if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + pDocShell = NULL; // ungueltig geworden +} + +// Hilfsfuntionen + +ScRangeData* ScNamedRangeObj::GetRangeData_Impl() +{ + ScRangeData* pRet = NULL; + if (pDocShell) + { + ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); + if (pNames) + { + sal_uInt16 nPos = 0; + if (pNames->SearchName( aName, nPos )) + { + pRet = (*pNames)[nPos]; + pRet->ValidateTabRefs(); // adjust relative tab refs to valid tables + } + } + } + return pRet; +} + +// sheet::XNamedRange + +void ScNamedRangeObj::Modify_Impl( const String* pNewName, const String* pNewContent, + const ScAddress* pNewPos, const sal_uInt16* pNewType ) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangeName* pNames = pDoc->GetRangeName(); + if (pNames) + { + ScRangeName aNewRanges( *pNames ); + sal_uInt16 nPos = 0; + if (aNewRanges.SearchName( aName, nPos )) + { + ScRangeData* pOld = (*pNames)[nPos]; + + String aInsName = pOld->GetName(); + if (pNewName) + aInsName = *pNewName; + String aContent; // Inhalt immer ueber Strings -> + pOld->GetEnglishSymbol(aContent); // keine Probleme mit geaenderter Position etc. + if (pNewContent) + aContent = *pNewContent; + ScAddress aPos = pOld->GetPos(); + if (pNewPos) + aPos = *pNewPos; + sal_uInt16 nType = pOld->GetType(); + if (pNewType) + nType = *pNewType; + + ScRangeData* pNew = new ScRangeData( pDoc, aInsName, aContent, + aPos, nType, sal_True ); + pNew->SetIndex( pOld->GetIndex() ); + + aNewRanges.AtFree( nPos ); + if ( aNewRanges.Insert(pNew) ) + { + ScDocFunc aFunc(*pDocShell); + aFunc.ModifyRangeNames( aNewRanges ); + + aName = aInsName; //! broadcast? + } + else + delete pNew; //! uno::Exception/Fehler oder so + } + } + } +} + + +::rtl::OUString SAL_CALL ScNamedRangeObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aName; +} + +void SAL_CALL ScNamedRangeObj::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! Formeln anpassen ????? + + String aNewStr = aNewName; + Modify_Impl( &aNewStr, NULL, NULL, NULL ); + + if ( aName != aNewStr ) // some error occurred... + throw uno::RuntimeException(); // no other exceptions specified +} + +::rtl::OUString SAL_CALL ScNamedRangeObj::getContent() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aContent; + ScRangeData* pData = GetRangeData_Impl(); + if (pData) + pData->GetEnglishSymbol(aContent); + return aContent; +} + +void SAL_CALL ScNamedRangeObj::setContent( const ::rtl::OUString& aContent ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aContStr = aContent; + Modify_Impl( NULL, &aContStr, NULL, NULL ); +} + +table::CellAddress SAL_CALL ScNamedRangeObj::getReferencePosition() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAddress aPos; + ScRangeData* pData = GetRangeData_Impl(); + if (pData) + aPos = pData->GetPos(); + table::CellAddress aAddress; + aAddress.Column = aPos.Col(); + aAddress.Row = aPos.Row(); + aAddress.Sheet = aPos.Tab(); + if (pDocShell) + { + USHORT nDocTabs = pDocShell->GetDocument()->GetTableCount(); + if ( aAddress.Sheet >= nDocTabs && nDocTabs > 0 ) + { + // Even after ValidateTabRefs, the position can be invalid if + // the content points to preceding tables. The resulting string + // is invalid in any case, so the position is just shifted. + aAddress.Sheet = nDocTabs - 1; + } + } + return aAddress; +} + +void SAL_CALL ScNamedRangeObj::setReferencePosition( const table::CellAddress& aReferencePosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAddress aPos( (USHORT)aReferencePosition.Column, (USHORT)aReferencePosition.Row, aReferencePosition.Sheet ); + Modify_Impl( NULL, NULL, &aPos, NULL ); +} + +sal_Int32 SAL_CALL ScNamedRangeObj::getType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + sal_Int32 nType=0; + ScRangeData* pData = GetRangeData_Impl(); + if (pData) + { + // interne RT_* Flags werden weggelassen + + if ( pData->HasType(RT_CRITERIA) ) nType |= sheet::NamedRangeFlag::FILTER_CRITERIA; + if ( pData->HasType(RT_PRINTAREA) ) nType |= sheet::NamedRangeFlag::PRINT_AREA; + if ( pData->HasType(RT_COLHEADER) ) nType |= sheet::NamedRangeFlag::COLUMN_HEADER; + if ( pData->HasType(RT_ROWHEADER) ) nType |= sheet::NamedRangeFlag::ROW_HEADER; + } + return nType; +} + +void SAL_CALL ScNamedRangeObj::setType( sal_Int32 nUnoType ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + sal_uInt16 nNewType = RT_NAME; + if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA ) nNewType |= RT_CRITERIA; + if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA ) nNewType |= RT_PRINTAREA; + if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER ) nNewType |= RT_COLHEADER; + if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER ) nNewType |= RT_ROWHEADER; + + Modify_Impl( NULL, NULL, NULL, &nNewType ); +} + +// XCellRangeSource + +uno::Reference<table::XCellRange> SAL_CALL ScNamedRangeObj::getReferredCells() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRange aRange; + ScRangeData* pData = GetRangeData_Impl(); + if ( pData && pData->IsReference( aRange ) ) + { + //! static Funktion um ScCellObj/ScCellRangeObj zu erzeugen am ScCellRangeObj ??? + + if ( aRange.aStart == aRange.aEnd ) + return new ScCellObj( pDocShell, aRange.aStart ); + else + return new ScCellRangeObj( pDocShell, aRange ); + } + return NULL; +} + +// beans::XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScNamedRangeObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + static uno::Reference< beans::XPropertySetInfo > aRef = new SfxItemPropertySetInfo( lcl_GetNamedRangeMap() ); + return aRef; +} + +void SAL_CALL ScNamedRangeObj::setPropertyValue( + const ::rtl::OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + // everything is read-only +} + +uno::Any SAL_CALL ScNamedRangeObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Any aRet; + String aString = aPropertyName; + if ( aString.EqualsAscii( SC_UNO_LINKDISPBIT ) ) + { + // no target bitmaps for individual entries (would be all equal) + // ScLinkTargetTypeObj::SetLinkTargetBitmap( aRet, SC_LINKTARGETTYPE_RANGENAME ); + } + else if ( aString.EqualsAscii( SC_UNO_LINKDISPNAME ) ) + aRet <<= ::rtl::OUString( aName ); + return aRet; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScNamedRangeObj ) + +// lang::XServiceInfo + +::rtl::OUString SAL_CALL ScNamedRangeObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScNamedRangeObj" )); +} + +sal_Bool SAL_CALL ScNamedRangeObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCNAMEDRANGEOBJ_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScNamedRangeObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCNAMEDRANGEOBJ_SERVICE )); + return aRet; +} + + +ScNamedRangesObj::ScNamedRangesObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScNamedRangesObj::~ScNamedRangesObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScNamedRangesObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// sheet::XNamedRanges + +ScNamedRangeObj* ScNamedRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) +{ + if (pDocShell) + { + ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); + if (pNames) + { + sal_uInt16 nCount = pNames->GetCount(); + sal_uInt16 nPos = 0; + for (sal_uInt16 i=0; i<nCount; i++) + { + ScRangeData* pData = (*pNames)[i]; + if (lcl_UserVisibleName(pData)) // interne weglassen + { + if ( nPos == nIndex ) + return new ScNamedRangeObj( pDocShell, pData->GetName() ); + ++nPos; + } + } + } + } + return NULL; +} + +ScNamedRangeObj* ScNamedRangesObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + if ( pDocShell && hasByName(aName) ) + { + String aString = aName; + return new ScNamedRangeObj( pDocShell, aString ); + } + return NULL; +} + +void SAL_CALL ScNamedRangesObj::addNewByName( const ::rtl::OUString& aName, + const ::rtl::OUString& aContent, const table::CellAddress& aPosition, + sal_Int32 nUnoType ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr = aName; + String aContStr = aContent; + ScAddress aPos( (USHORT)aPosition.Column, (USHORT)aPosition.Row, aPosition.Sheet ); + + sal_uInt16 nNewType = RT_NAME; + if ( nUnoType & sheet::NamedRangeFlag::FILTER_CRITERIA ) nNewType |= RT_CRITERIA; + if ( nUnoType & sheet::NamedRangeFlag::PRINT_AREA ) nNewType |= RT_PRINTAREA; + if ( nUnoType & sheet::NamedRangeFlag::COLUMN_HEADER ) nNewType |= RT_COLHEADER; + if ( nUnoType & sheet::NamedRangeFlag::ROW_HEADER ) nNewType |= RT_ROWHEADER; + + BOOL bDone = FALSE; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangeName* pNames = pDoc->GetRangeName(); + USHORT nIndex = 0; + if (pNames && !pNames->SearchName(aNameStr, nIndex)) + { + ScRangeName aNewRanges( *pNames ); + ScRangeData* pNew = new ScRangeData( pDoc, aNameStr, aContStr, + aPos, nNewType, sal_True ); + if ( aNewRanges.Insert(pNew) ) + { + ScDocFunc aFunc(*pDocShell); + aFunc.ModifyRangeNames( aNewRanges ); + bDone = TRUE; + } + else + delete pNew; + } + } + + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScNamedRangesObj::addNewFromTitles( const table::CellRangeAddress& aSource, + sheet::Border aBorder ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! das darf kein enum sein, weil mehrere Bits gesetzt sein koennen !!! + + sal_Bool bTop = ( aBorder == sheet::Border_TOP ); + sal_Bool bLeft = ( aBorder == sheet::Border_LEFT ); + sal_Bool bBottom = ( aBorder == sheet::Border_BOTTOM ); + sal_Bool bRight = ( aBorder == sheet::Border_RIGHT ); + + ScRange aRange; + ScUnoConversion::FillScRange( aRange, aSource ); + + sal_uInt16 nFlags = 0; + if (bTop) nFlags |= NAME_TOP; + if (bLeft) nFlags |= NAME_LEFT; + if (bBottom) nFlags |= NAME_BOTTOM; + if (bRight) nFlags |= NAME_RIGHT; + + if (nFlags) + { + ScDocFunc aFunc(*pDocShell); + aFunc.CreateNames( aRange, nFlags, sal_True ); + } +} + +void SAL_CALL ScNamedRangesObj::removeByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); + if (pNames) + { + String aString = aName; + sal_uInt16 nPos = 0; + if (pNames->SearchName( aString, nPos )) + if ( lcl_UserVisibleName((*pNames)[nPos]) ) + { + ScRangeName aNewRanges(*pNames); + aNewRanges.AtFree(nPos); + ScDocFunc aFunc(*pDocShell); + aFunc.ModifyRangeNames( aNewRanges ); + bDone = TRUE; + } + } + } + + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +void SAL_CALL ScNamedRangesObj::outputList( const table::CellAddress& aOutputPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScAddress aPos( (USHORT)aOutputPosition.Column, (USHORT)aOutputPosition.Row, aOutputPosition.Sheet ); + if (pDocShell) + { + ScDocFunc aFunc(*pDocShell); + aFunc.InsertNameList( aPos, sal_True ); + } +} + +// container::XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScNamedRangesObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.NamedRangesEnumeration"))); +} + +// container::XIndexAccess + +sal_Int32 SAL_CALL ScNamedRangesObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + long nRet = 0; + if (pDocShell) + { + ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); + if (pNames) + { + sal_uInt16 nCount = pNames->GetCount(); + for (sal_uInt16 i=0; i<nCount; i++) + if (lcl_UserVisibleName( (*pNames)[i] )) // interne weglassen + ++nRet; + } + } + return nRet; +} + +uno::Any SAL_CALL ScNamedRangesObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< sheet::XNamedRange > xRange = GetObjectByIndex_Impl((sal_uInt16)nIndex); + uno::Any aAny; + if ( xRange.is() ) + aAny <<= xRange; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScNamedRangesObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ::getCppuType((const uno::Reference< sheet::XNamedRange >*)0); // muss zu getByIndex passen +} + +sal_Bool SAL_CALL ScNamedRangesObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +uno::Any SAL_CALL ScNamedRangesObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< sheet::XNamedRange > xRange = GetObjectByName_Impl(aName); + uno::Any aAny; + if ( xRange.is() ) + aAny <<= xRange; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScNamedRangesObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); + if (pNames) + { + long nVisCount = getCount(); // Namen mit lcl_UserVisibleName + uno::Sequence< ::rtl::OUString> aSeq(nVisCount); + ::rtl::OUString* pAry = aSeq.getArray(); + + sal_uInt16 nCount = pNames->GetCount(); + sal_uInt16 nVisPos = 0; + for (sal_uInt16 i=0; i<nCount; i++) + { + ScRangeData* pData = (*pNames)[i]; + if ( lcl_UserVisibleName(pData) ) + pAry[nVisPos++] = pData->GetName(); + } + return aSeq; + } + } + return uno::Sequence< ::rtl::OUString>(0); +} + +sal_Bool SAL_CALL ScNamedRangesObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScRangeName* pNames = pDocShell->GetDocument()->GetRangeName(); + if (pNames) + { + String aString = aName; + sal_uInt16 nPos = 0; + if (pNames->SearchName( aString, nPos )) + if ( lcl_UserVisibleName((*pNames)[nPos]) ) + return sal_True; + } + } + return sal_False; +} + + +ScLabelRangeObj::ScLabelRangeObj(ScDocShell* pDocSh, sal_Bool bCol, const ScRange& rR) : + pDocShell( pDocSh ), + bColumn( bCol ), + aRange( rR ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScLabelRangeObj::~ScLabelRangeObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScLabelRangeObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + //! Ref-Update !!! + + if ( rHint.ISA( SfxSimpleHint ) && ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + pDocShell = NULL; // ungueltig geworden +} + +// Hilfsfuntionen + +ScRangePair* ScLabelRangeObj::GetData_Impl() +{ + ScRangePair* pRet = NULL; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); + if (pList) + pRet = pList->Find( aRange ); + } + return pRet; +} + +void ScLabelRangeObj::Modify_Impl( const ScRange* pLabel, const ScRange* pData ) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); + if (pOldList) + { + ScRangePairListRef xNewList = pOldList->Clone(); + ScRangePair* pEntry = xNewList->Find( aRange ); + if (pEntry) + { + xNewList->Remove( pEntry ); // nur aus der Liste entfernt, nicht geloescht + + if ( pLabel ) + pEntry->GetRange(0) = *pLabel; + if ( pData ) + pEntry->GetRange(1) = *pData; + + xNewList->Join( *pEntry ); + delete pEntry; + + if (bColumn) + pDoc->GetColNameRangesRef() = xNewList; + else + pDoc->GetRowNameRangesRef() = xNewList; + + pDoc->CompileColRowNameFormula(); + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); + pDocShell->SetDocumentModified(); + + //! Undo ?!?! (hier und aus Dialog) + + if ( pLabel ) + aRange = *pLabel; // Objekt anpassen, um Range wiederzufinden + } + } + } +} + +// sheet::XLabelRange + +table::CellRangeAddress SAL_CALL ScLabelRangeObj::getLabelArea() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aRet; + ScRangePair* pData = GetData_Impl(); + if (pData) + ScUnoConversion::FillApiRange( aRet, pData->GetRange(0) ); + return aRet; +} + +void SAL_CALL ScLabelRangeObj::setLabelArea( const table::CellRangeAddress& aLabelArea ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRange aLabelRange; + ScUnoConversion::FillScRange( aLabelRange, aLabelArea ); + Modify_Impl( &aLabelRange, NULL ); +} + +table::CellRangeAddress SAL_CALL ScLabelRangeObj::getDataArea() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellRangeAddress aRet; + ScRangePair* pData = GetData_Impl(); + if (pData) + ScUnoConversion::FillApiRange( aRet, pData->GetRange(1) ); + return aRet; +} + +void SAL_CALL ScLabelRangeObj::setDataArea( const table::CellRangeAddress& aDataArea ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScRange aDataRange; + ScUnoConversion::FillScRange( aDataRange, aDataArea ); + Modify_Impl( NULL, &aDataRange ); +} + + +ScLabelRangesObj::ScLabelRangesObj(ScDocShell* pDocSh, sal_Bool bCol) : + pDocShell( pDocSh ), + bColumn( bCol ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScLabelRangesObj::~ScLabelRangesObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScLabelRangesObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// sheet::XLabelRanges + +ScLabelRangeObj* ScLabelRangesObj::GetObjectByIndex_Impl(sal_uInt16 nIndex) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); + if ( pList && nIndex < pList->Count() ) + { + ScRangePair* pData = pList->GetObject(nIndex); + if (pData) + return new ScLabelRangeObj( pDocShell, bColumn, pData->GetRange(0) ); + } + } + return NULL; +} + +void SAL_CALL ScLabelRangesObj::addNew( const table::CellRangeAddress& aLabelArea, + const table::CellRangeAddress& aDataArea ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); + if (pOldList) + { + ScRangePairListRef xNewList = pOldList->Clone(); + + ScRange aLabelRange; + ScRange aDataRange; + ScUnoConversion::FillScRange( aLabelRange, aLabelArea ); + ScUnoConversion::FillScRange( aDataRange, aDataArea ); + xNewList->Join( ScRangePair( aLabelRange, aDataRange ) ); + + if (bColumn) + pDoc->GetColNameRangesRef() = xNewList; + else + pDoc->GetRowNameRangesRef() = xNewList; + + pDoc->CompileColRowNameFormula(); + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); + pDocShell->SetDocumentModified(); + + //! Undo ?!?! (hier und aus Dialog) + } + } +} + +void SAL_CALL ScLabelRangesObj::removeByIndex( sal_Int32 nIndex ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangePairList* pOldList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); + + if ( pOldList && nIndex < (sal_Int32)pOldList->Count() ) + { + ScRangePairListRef xNewList = pOldList->Clone(); + + ScRangePair* pEntry = xNewList->GetObject( nIndex ); + if (pEntry) + { + xNewList->Remove( pEntry ); + delete pEntry; + + if (bColumn) + pDoc->GetColNameRangesRef() = xNewList; + else + pDoc->GetRowNameRangesRef() = xNewList; + + pDoc->CompileColRowNameFormula(); + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID ); + pDocShell->SetDocumentModified(); + bDone = TRUE; + + //! Undo ?!?! (hier und aus Dialog) + } + } + } + if (!bDone) + throw uno::RuntimeException(); // no other exceptions specified +} + +// container::XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScLabelRangesObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScIndexEnumeration(this, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.LabelRangesEnumeration"))); +} + +// container::XIndexAccess + +sal_Int32 SAL_CALL ScLabelRangesObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScRangePairList* pList = bColumn ? pDoc->GetColNameRanges() : pDoc->GetRowNameRanges(); + if (pList) + return pList->Count(); + } + return 0; +} + +uno::Any SAL_CALL ScLabelRangesObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< sheet::XLabelRange > xRange = GetObjectByIndex_Impl((sal_uInt16)nIndex); + uno::Any aAny; + if ( xRange.is() ) + aAny <<= xRange; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScLabelRangesObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ::getCppuType((const uno::Reference< sheet::XLabelRange >*)0); // muss zu getByIndex passen + +} + +sal_Bool SAL_CALL ScLabelRangesObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_notesuno.cxx b/bf_sc/source/ui/unoobj/sc_notesuno.cxx new file mode 100644 index 000000000..cdbce49de --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_notesuno.cxx @@ -0,0 +1,298 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + + +#include "notesuno.hxx" +#include "textuno.hxx" +#include "cellsuno.hxx" // getParent +#include "docsh.hxx" +#include "docfunc.hxx" +#include "hints.hxx" +#include "editsrc.hxx" +#include "miscuno.hxx" + +// setVisible: +#include <bf_svx/svdundo.hxx> +#include "drwlayer.hxx" +#include "detfunc.hxx" +#include "undocell.hxx" +#include <vcl/svapp.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +// keine Properties fuer Text in Notizen +const SfxItemPropertyMap* lcl_GetAnnotationPropertyMap() +{ + static SfxItemPropertyMap aAnnotationPropertyMap_Impl[] = + { + {0,0,0,0,0,0} + }; + return aAnnotationPropertyMap_Impl; +} + + +SC_SIMPLE_SERVICE_INFO( ScAnnotationObj, "ScAnnotationObj", "com.sun.star.sheet.CellAnnotation" ) + + +ScAnnotationObj::ScAnnotationObj(ScDocShell* pDocSh, const ScAddress& rPos) : + pDocShell( pDocSh ), + aCellPos( rPos ), + pUnoText( NULL ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); + + // pUnoText is allocated on demand (GetUnoText) + // can't be aggregated because getString/setString is handled here +} + +SvxUnoText& ScAnnotationObj::GetUnoText() +{ + if (!pUnoText) + { + ScAnnotationEditSource aEditSource( pDocShell, aCellPos ); + pUnoText = new SvxUnoText( &aEditSource, lcl_GetAnnotationPropertyMap(), + uno::Reference<text::XText>() ); + pUnoText->acquire(); + } + return *pUnoText; +} + +ScAnnotationObj::~ScAnnotationObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); + + if (pUnoText) + pUnoText->release(); +} + +void ScAnnotationObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! Ref-Update + } + else if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + + +// XChild + +uno::Reference<uno::XInterface> SAL_CALL ScAnnotationObj::getParent() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // Parent der Notiz ist die zugehoerige Zelle + //! existierendes Objekt finden und zurueckgeben ??? + + if (pDocShell) + return (cppu::OWeakObject*)new ScCellObj( pDocShell, aCellPos ); + + return NULL; +} + +void SAL_CALL ScAnnotationObj::setParent( const uno::Reference<uno::XInterface>& /*Parent*/ ) + throw(lang::NoSupportException, uno::RuntimeException) +{ + // hamma nich + //! Exception oder so ??! +} + +// XSimpleText + +uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // Notizen brauchen keine Extrawurst + return GetUnoText().createTextCursor(); +} + +uno::Reference<text::XTextCursor> SAL_CALL ScAnnotationObj::createTextCursorByRange( + const uno::Reference<text::XTextRange>& aTextPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // Notizen brauchen keine Extrawurst + return GetUnoText().createTextCursorByRange(aTextPosition); +} + +::rtl::OUString SAL_CALL ScAnnotationObj::getString() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPostIt aNote; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->GetNote( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), aNote ); + } + return aNote.GetText(); +} + +void SAL_CALL ScAnnotationObj::setString( const ::rtl::OUString& aText ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + String aString = aText; + ScDocFunc aFunc(*pDocShell); + aFunc.SetNoteText( aCellPos, aString, TRUE ); + + // don't create pUnoText here if not there + if (pUnoText) + pUnoText->SetSelection(ESelection( 0,0, 0,aString.Len() )); + } +} + +void SAL_CALL ScAnnotationObj::insertString( const uno::Reference<text::XTextRange>& xRange, + const ::rtl::OUString& aString, sal_Bool bAbsorb ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + GetUnoText().insertString( xRange, aString, bAbsorb ); +} + +void SAL_CALL ScAnnotationObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange, + sal_Int16 nControlCharacter, sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + GetUnoText().insertControlCharacter( xRange, nControlCharacter, bAbsorb ); +} + +uno::Reference<text::XText> SAL_CALL ScAnnotationObj::getText() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().getText(); +} + +uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getStart() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().getStart(); +} + +uno::Reference<text::XTextRange> SAL_CALL ScAnnotationObj::getEnd() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return GetUnoText().getEnd(); +} + +// XSheetAnnotation + +table::CellAddress SAL_CALL ScAnnotationObj::getPosition() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + table::CellAddress aAdr; + aAdr.Sheet = aCellPos.Tab(); + aAdr.Column = aCellPos.Col(); + aAdr.Row = aCellPos.Row(); + return aAdr; +} + +::rtl::OUString SAL_CALL ScAnnotationObj::getAuthor() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPostIt aNote; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->GetNote( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), aNote ); + } + return aNote.GetAuthor(); +} + +::rtl::OUString SAL_CALL ScAnnotationObj::getDate() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPostIt aNote; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->GetNote( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), aNote ); + } + return aNote.GetDate(); +} + +sal_Bool SAL_CALL ScAnnotationObj::getIsVisible() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ScPostIt aNote; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->GetNote( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab(), aNote ); + } + return aNote.IsShown(); +} + +void SAL_CALL ScAnnotationObj::setIsVisible( sal_Bool bIsVisible ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bDone = FALSE; + if ( pDocShell ) + { + //! Funktion an docfunc oder so + + BOOL bSet = bIsVisible ? TRUE : FALSE; + ScDocument* pDoc = pDocShell->GetDocument(); + USHORT nCol = aCellPos.Col(); + USHORT nRow = aCellPos.Row(); + USHORT nTab = aCellPos.Tab(); + ScPostIt aNote; + if ( pDoc->GetNote( nCol, nRow, nTab, aNote ) ) + { + BOOL bHad = pDoc->HasNoteObject( nCol, nRow, nTab ); + if ( bHad != bSet ) + { + pDocShell->MakeDrawLayer(); + pDoc->GetDrawLayer(); + + ScDetectiveFunc aFunc( pDoc,nTab ); + if ( bSet ) + bDone = ( aFunc.ShowComment( nCol, nRow, FALSE ) != NULL ); + else + bDone = aFunc.HideComment( nCol, nRow ); + if (bDone) + { + aNote.SetShown( bSet ); + pDoc->SetNote( nCol, nRow, nTab, aNote ); + + pDocShell->SetDocumentModified(); + } + } + } + } +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_optuno.cxx b/bf_sc/source/ui/unoobj/sc_optuno.cxx new file mode 100644 index 000000000..99f160f93 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_optuno.cxx @@ -0,0 +1,201 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + + +#include <com/sun/star/util/Date.hpp> + +#include "optuno.hxx" +#include "miscuno.hxx" +#include "unonames.hxx" +#include <vcl/svapp.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +// static +const SfxItemPropertyMap* ScDocOptionsHelper::GetPropertyMap() +{ + static SfxItemPropertyMap aMap[] = + { + {MAP_CHAR_LEN(SC_UNO_CALCASSHOWN), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_DEFTABSTOP), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_IGNORECASE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ITERENABLED), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ITERCOUNT), 0, &getCppuType((sal_Int32*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_ITEREPSILON), 0, &getCppuType((double*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_LOOKUPLABELS), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_MATCHWHOLE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_NULLDATE), 0, &getCppuType((util::Date*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_SPELLONLINE), 0, &getBooleanCppuType(), 0,0}, + {MAP_CHAR_LEN(SC_UNO_STANDARDDEC), 0, &getCppuType((sal_Int16*)0), 0,0}, + {MAP_CHAR_LEN(SC_UNO_REGEXENABLED), 0, &getBooleanCppuType(), 0,0}, + {0,0,0,0,0,0} + }; + return aMap; +} + +// static +sal_Bool ScDocOptionsHelper::setPropertyValue( ScDocOptions& rOptions, + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) +{ + //! use map (with new identifiers) + + sal_Bool bKnown = sal_True; + String aString = aPropertyName; + + if ( aString.EqualsAscii( SC_UNO_CALCASSHOWN ) ) + rOptions.SetCalcAsShown( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNO_IGNORECASE ) ) + rOptions.SetIgnoreCase( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNO_ITERENABLED ) ) + rOptions.SetIter( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNO_REGEXENABLED ) ) + rOptions.SetFormulaRegexEnabled( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNO_LOOKUPLABELS ) ) + rOptions.SetLookUpColRowNames( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNO_MATCHWHOLE ) ) + rOptions.SetMatchWholeCell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNO_SPELLONLINE ) ) + rOptions.SetAutoSpell( ScUnoHelpFunctions::GetBoolFromAny( aValue ) ); + else if ( aString.EqualsAscii( SC_UNO_DEFTABSTOP ) ) + { + sal_Int16 nIntVal = 0; + if ( aValue >>= nIntVal ) + rOptions.SetTabDistance( nIntVal ); + } + else if ( aString.EqualsAscii( SC_UNO_ITERCOUNT ) ) + { + sal_Int32 nIntVal = 0; + if ( aValue >>= nIntVal ) + rOptions.SetIterCount( (USHORT)nIntVal ); + } + else if ( aString.EqualsAscii( SC_UNO_STANDARDDEC ) ) + { + sal_Int16 nIntVal = 0; + if ( aValue >>= nIntVal ) + rOptions.SetStdPrecision( nIntVal ); + } + else if ( aString.EqualsAscii( SC_UNO_ITEREPSILON ) ) + { + double fDoubleVal = 0.0; + if ( aValue >>= fDoubleVal ) + rOptions.SetIterEps( fDoubleVal ); + } + else if ( aString.EqualsAscii( SC_UNO_NULLDATE ) ) + { + util::Date aDate; + if ( aValue >>= aDate ) + rOptions.SetDate( aDate.Day, aDate.Month, aDate.Year ); + } + else + bKnown = sal_False; + + return bKnown; +} + +// static +uno::Any ScDocOptionsHelper::getPropertyValue( + const ScDocOptions& rOptions, const ::rtl::OUString& aPropertyName ) +{ + //! use map (with new identifiers) + + String aString = aPropertyName; + uno::Any aRet; + + if ( aString.EqualsAscii( SC_UNO_CALCASSHOWN ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsCalcAsShown() ); + else if ( aString.EqualsAscii( SC_UNO_IGNORECASE ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIgnoreCase() ); + else if ( aString.EqualsAscii( SC_UNO_ITERENABLED ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsIter() ); + else if ( aString.EqualsAscii( SC_UNO_REGEXENABLED ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsFormulaRegexEnabled() ); + else if ( aString.EqualsAscii( SC_UNO_LOOKUPLABELS ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsLookUpColRowNames() ); + else if ( aString.EqualsAscii( SC_UNO_MATCHWHOLE ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsMatchWholeCell() ); + else if ( aString.EqualsAscii( SC_UNO_SPELLONLINE ) ) + ScUnoHelpFunctions::SetBoolInAny( aRet, rOptions.IsAutoSpell() ); + else if ( aString.EqualsAscii( SC_UNO_DEFTABSTOP ) ) + aRet <<= (sal_Int16)( rOptions.GetTabDistance() ); + else if ( aString.EqualsAscii( SC_UNO_ITERCOUNT ) ) + aRet <<= (sal_Int32)( rOptions.GetIterCount() ); + else if ( aString.EqualsAscii( SC_UNO_STANDARDDEC ) ) + aRet <<= (sal_Int16)( rOptions.GetStdPrecision() ); + else if ( aString.EqualsAscii( SC_UNO_ITEREPSILON ) ) + aRet <<= (double)( rOptions.GetIterEps() ); + else if ( aString.EqualsAscii( SC_UNO_NULLDATE ) ) + { + USHORT nD, nM, nY; + rOptions.GetDate( nD, nM, nY ); + util::Date aDate( nD, nM, nY ); + aRet <<= aDate; + } + + return aRet; +} + +//------------------------------------------------------------------------ + +ScDocOptionsObj::ScDocOptionsObj( const ScDocOptions& rOpt ) : + ScModelObj( NULL ), + aOptions( rOpt ) +{ +} + +ScDocOptionsObj::~ScDocOptionsObj() +{ +} + +void SAL_CALL ScDocOptionsObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + BOOL bDone = ScDocOptionsHelper::setPropertyValue( aOptions, aPropertyName, aValue ); + + if (!bDone) + ScModelObj::setPropertyValue( aPropertyName, aValue ); +} + +uno::Any SAL_CALL ScDocOptionsObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Any aRet = ScDocOptionsHelper::getPropertyValue( aOptions, aPropertyName ); + if ( !aRet.hasValue() ) + aRet = ScModelObj::getPropertyValue( aPropertyName ); + + return aRet; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_pageuno.cxx b/bf_sc/source/ui/unoobj/sc_pageuno.cxx new file mode 100644 index 000000000..397db72f4 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_pageuno.cxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include "pageuno.hxx" +#include "shapeuno.hxx" + +#include <bf_tools/string.hxx> + +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +ScPageObj::ScPageObj( SdrPage* pInPage ) : + SvxFmDrawPage( pInPage ) +{ +} + +ScPageObj::~ScPageObj() throw() +{ +} + +uno::Reference<drawing::XShape > ScPageObj::_CreateShape( SdrObject *pObj ) const throw() +{ + uno::Reference<drawing::XShape> xShape = SvxFmDrawPage::_CreateShape( pObj ); + + new ScShapeObj( xShape ); // aggregates object and modifies xShape + + return xShape; +} + +::rtl::OUString SAL_CALL ScPageObj::getImplementationName() + throw(uno::RuntimeException) +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ScPageObj")); +} + +sal_Bool SAL_CALL ScPageObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + String aServiceStr = rServiceName; + return aServiceStr.EqualsAscii( "com.sun.star.sheet.SpreadsheetDrawPage" ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScPageObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + uno::Sequence< ::rtl::OUString> aRet(1); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDrawPage")); + return aRet; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_servuno.cxx b/bf_sc/source/ui/unoobj/sc_servuno.cxx new file mode 100644 index 000000000..f44ff629d --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_servuno.cxx @@ -0,0 +1,297 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <bf_svtools/unoimap.hxx> +#include <bf_svx/unofill.hxx> + +#include <bf_svx/unonrule.hxx> + +#include "servuno.hxx" +#include "cellsuno.hxx" +#include "fielduno.hxx" +#include "styleuno.hxx" +#include "afmtuno.hxx" +#include "defltuno.hxx" +#include "drdefuno.hxx" +#include "docsh.hxx" +#include "drwlayer.hxx" +#include "confuno.hxx" +#include "shapeuno.hxx" + +// #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver +#include <bf_svx/xmleohlp.hxx> + +#include <bf_svx/xmlgrhlp.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + + +//------------------------------------------------------------------------ + +static const sal_Char* aProvNames[SC_SERVICE_COUNT] = + { + "com.sun.star.sheet.Spreadsheet", // SC_SERVICE_SHEET + "com.sun.star.text.TextField.URL", // SC_SERVICE_URLFIELD + "com.sun.star.text.TextField.PageNumber", // SC_SERVICE_PAGEFIELD + "com.sun.star.text.TextField.PageCount", // SC_SERVICE_PAGESFIELD + "com.sun.star.text.TextField.Date", // SC_SERVICE_DATEFIELD + "com.sun.star.text.TextField.Time", // SC_SERVICE_TIMEFIELD + "com.sun.star.text.TextField.DocumentTitle",// SC_SERVICE_TITLEFIELD + "com.sun.star.text.TextField.FileName", // SC_SERVICE_FILEFIELD + "com.sun.star.text.TextField.SheetName", // SC_SERVICE_SHEETFIELD + "com.sun.star.style.CellStyle", // SC_SERVICE_CELLSTYLE + "com.sun.star.style.PageStyle", // SC_SERVICE_PAGESTYLE + "com.sun.star.sheet.TableAutoFormat", // SC_SERVICE_AUTOFORMAT + "com.sun.star.sheet.SheetCellRanges", // SC_SERVICE_CELLRANGES + "com.sun.star.drawing.GradientTable", // SC_SERVICE_GRADTAB + "com.sun.star.drawing.HatchTable", // SC_SERVICE_HATCHTAB + "com.sun.star.drawing.BitmapTable", // SC_SERVICE_BITMAPTAB + "com.sun.star.drawing.TransparencyGradientTable", // SC_SERVICE_TRGRADTAB + "com.sun.star.drawing.MarkerTable", // SC_SERVICE_MARKERTAB + "com.sun.star.drawing.DashTable", // SC_SERVICE_DASHTAB + "com.sun.star.text.NumberingRules", // SC_SERVICE_NUMRULES + "com.sun.star.sheet.Defaults", // SC_SERVICE_DOCDEFLTS + "com.sun.star.drawing.Defaults", // SC_SERVICE_DRAWDEFLTS + "com.sun.star.comp.SpreadsheetSettings", // SC_SERVICE_DOCSPRSETT + "com.sun.star.document.Settings", // SC_SERVICE_DOCCONF + "com.sun.star.image.ImageMapRectangleObject",// SC_SERVICE_IMAP_RECT + "com.sun.star.image.ImageMapCircleObject", // SC_SERVICE_IMAP_CIRC + "com.sun.star.image.ImageMapPolygonObject", // SC_SERVICE_IMAP_POLY + + // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver + "com.sun.star.document.ExportGraphicObjectResolver", // SC_SERVICE_EXPORT_GOR + "com.sun.star.document.ImportGraphicObjectResolver", // SC_SERVICE_IMPORT_GOR + "com.sun.star.document.ExportEmbeddedObjectResolver", // SC_SERVICE_EXPORT_EOR + "com.sun.star.document.ImportEmbeddedObjectResolver" // SC_SERVICE_IMPORT_EOR + }; + +// +// old service names that were in 567 still work in createInstance, +// in case some macro is still using them +// + +static const sal_Char* aOldNames[SC_SERVICE_COUNT] = + { + "", // SC_SERVICE_SHEET + "stardiv.one.text.TextField.URL", // SC_SERVICE_URLFIELD + "stardiv.one.text.TextField.PageNumber", // SC_SERVICE_PAGEFIELD + "stardiv.one.text.TextField.PageCount", // SC_SERVICE_PAGESFIELD + "stardiv.one.text.TextField.Date", // SC_SERVICE_DATEFIELD + "stardiv.one.text.TextField.Time", // SC_SERVICE_TIMEFIELD + "stardiv.one.text.TextField.DocumentTitle", // SC_SERVICE_TITLEFIELD + "stardiv.one.text.TextField.FileName", // SC_SERVICE_FILEFIELD + "stardiv.one.text.TextField.SheetName", // SC_SERVICE_SHEETFIELD + "stardiv.one.style.CellStyle", // SC_SERVICE_CELLSTYLE + "stardiv.one.style.PageStyle", // SC_SERVICE_PAGESTYLE + "", // SC_SERVICE_AUTOFORMAT + "", // SC_SERVICE_CELLRANGES + "", // SC_SERVICE_GRADTAB + "", // SC_SERVICE_HATCHTAB + "", // SC_SERVICE_BITMAPTAB + "", // SC_SERVICE_TRGRADTAB + "", // SC_SERVICE_MARKERTAB + "", // SC_SERVICE_DASHTAB + "", // SC_SERVICE_NUMRULES + "", // SC_SERVICE_DOCDEFLTS + "", // SC_SERVICE_DRAWDEFLTS + "", // SC_SERVICE_DOCSPRSETT + "", // SC_SERVICE_DOCCONF + "", // SC_SERVICE_IMAP_RECT + "", // SC_SERVICE_IMAP_CIRC + "", // SC_SERVICE_IMAP_POLY + + // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver + "", // SC_SERVICE_EXPORT_GOR + "", // SC_SERVICE_IMPORT_GOR + "", // SC_SERVICE_EXPORT_EOR + "" // SC_SERVICE_IMPORT_EOR + }; + + + + +//------------------------------------------------------------------------ + +// alles static + +sal_uInt16 ScServiceProvider::GetProviderType(const String& rServiceName) +{ + if (rServiceName.Len()) + { + USHORT i; + for (i=0; i<SC_SERVICE_COUNT; i++) + if (rServiceName.EqualsAscii( aProvNames[i] )) + return i; + + for (i=0; i<SC_SERVICE_COUNT; i++) + if (rServiceName.EqualsAscii( aOldNames[i] )) + { + OSL_FAIL("old service name used"); + return i; + } + } + return SC_SERVICE_INVALID; +} + +uno::Reference<uno::XInterface> ScServiceProvider::MakeInstance( + sal_uInt16 nType, ScDocShell* pDocShell ) +{ + uno::Reference<uno::XInterface> xRet; + switch (nType) + { + case SC_SERVICE_SHEET: + // noch nicht eingefuegt - DocShell=Null + xRet = (sheet::XSpreadsheet*)new ScTableSheetObj(NULL,0); + break; + case SC_SERVICE_URLFIELD: + xRet = (text::XTextField*)new ScCellFieldObj( NULL, ScAddress(), ESelection() ); + break; + case SC_SERVICE_PAGEFIELD: + case SC_SERVICE_PAGESFIELD: + case SC_SERVICE_DATEFIELD: + case SC_SERVICE_TIMEFIELD: + case SC_SERVICE_TITLEFIELD: + case SC_SERVICE_FILEFIELD: + case SC_SERVICE_SHEETFIELD: + xRet = (text::XTextField*)new ScHeaderFieldObj( NULL, 0, nType, ESelection() ); + break; + case SC_SERVICE_CELLSTYLE: + xRet = (style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PARA, String() ); + break; + case SC_SERVICE_PAGESTYLE: + xRet = (style::XStyle*)new ScStyleObj( NULL, SFX_STYLE_FAMILY_PAGE, String() ); + break; + case SC_SERVICE_AUTOFORMAT: + xRet = (container::XIndexAccess*)new ScAutoFormatObj( SC_AFMTOBJ_INVALID ); + break; + case SC_SERVICE_CELLRANGES: + // wird nicht eingefuegt, sondern gefuellt + // -> DocShell muss gesetzt sein, aber leere Ranges + if (pDocShell) + xRet = (sheet::XSheetCellRanges*)new ScCellRangesObj( pDocShell, ScRangeList() ); + break; + + case SC_SERVICE_DOCDEFLTS: + if (pDocShell) + xRet = (beans::XPropertySet*)new ScDocDefaultsObj( pDocShell ); + break; + case SC_SERVICE_DRAWDEFLTS: + if (pDocShell) + xRet = (beans::XPropertySet*)new ScDrawDefaultsObj( pDocShell ); + break; + + // Drawing layer tables are not in SvxUnoDrawMSFactory, + // because SvxUnoDrawMSFactory doesn't have a SdrModel pointer. + // Drawing layer is always allocated if not there (MakeDrawLayer). + + case SC_SERVICE_GRADTAB: + if (pDocShell) + xRet = SvxUnoGradientTable_createInstance( pDocShell->MakeDrawLayer() ); + break; + case SC_SERVICE_HATCHTAB: + if (pDocShell) + xRet = SvxUnoHatchTable_createInstance( pDocShell->MakeDrawLayer() ); + break; + case SC_SERVICE_BITMAPTAB: + if (pDocShell) + xRet = SvxUnoBitmapTable_createInstance( pDocShell->MakeDrawLayer() ); + break; + case SC_SERVICE_TRGRADTAB: + if (pDocShell) + xRet = SvxUnoTransGradientTable_createInstance( pDocShell->MakeDrawLayer() ); + break; + case SC_SERVICE_MARKERTAB: + if (pDocShell) + xRet = SvxUnoMarkerTable_createInstance( pDocShell->MakeDrawLayer() ); + break; + case SC_SERVICE_DASHTAB: + if (pDocShell) + xRet = SvxUnoDashTable_createInstance( pDocShell->MakeDrawLayer() ); + break; + case SC_SERVICE_NUMRULES: + if (pDocShell) + xRet = SvxCreateNumRule( pDocShell->MakeDrawLayer() ); + break; + case SC_SERVICE_DOCSPRSETT: + case SC_SERVICE_DOCCONF: + if (pDocShell) + xRet = (beans::XPropertySet*)new ScDocumentConfiguration(pDocShell); + break; + + case SC_SERVICE_IMAP_RECT: + xRet = SvUnoImageMapRectangleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ); + break; + case SC_SERVICE_IMAP_CIRC: + xRet = SvUnoImageMapCircleObject_createInstance( ScShapeObj::GetSupportedMacroItems() ); + break; + case SC_SERVICE_IMAP_POLY: + xRet = SvUnoImageMapPolygonObject_createInstance( ScShapeObj::GetSupportedMacroItems() ); + break; + + // #100263# Support creation of GraphicObjectResolver and EmbeddedObjectResolver + case SC_SERVICE_EXPORT_GOR: + xRet = (::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_WRITE ); + break; + + case SC_SERVICE_IMPORT_GOR: + xRet = (::cppu::OWeakObject * )new SvXMLGraphicHelper( GRAPHICHELPER_MODE_READ ); + break; + + case SC_SERVICE_EXPORT_EOR: + if (pDocShell) + xRet = (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_WRITE ); + break; + + case SC_SERVICE_IMPORT_EOR: + if (pDocShell) + xRet = (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ ); + break; + } + return xRet; +} + +uno::Sequence< ::rtl::OUString> ScServiceProvider::GetAllServiceNames() +{ + uno::Sequence< ::rtl::OUString> aRet(SC_SERVICE_COUNT); + ::rtl::OUString* pArray = aRet.getArray(); + for (sal_uInt16 i = 0; i < SC_SERVICE_COUNT; i++) + pArray[i] = ::rtl::OUString::createFromAscii( aProvNames[i] ); + return aRet; +} + + + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_shapeuno.cxx b/bf_sc/source/ui/unoobj/sc_shapeuno.cxx new file mode 100644 index 000000000..f98d71edb --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_shapeuno.cxx @@ -0,0 +1,791 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include <comphelper/uno3.hxx> +#include <bf_svtools/unoevent.hxx> +#include <bf_svtools/unoimap.hxx> +#include <bf_svx/unoshape.hxx> +#include <bf_svx/unofield.hxx> + + +#include "shapeuno.hxx" +#include "miscuno.hxx" +#include "cellsuno.hxx" +#include "textuno.hxx" +#include "fielduno.hxx" +#include "docsh.hxx" +#include "drwlayer.hxx" +#include "userdat.hxx" +#include "unonames.hxx" +#include <vcl/svapp.hxx> + +#include <comphelper/stl_types.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +DECLARE_STL_USTRINGACCESS_MAP( uno::Sequence< sal_Int8 > *, ScShapeImplementationIdMap ); + +static ScShapeImplementationIdMap aImplementationIdMap; + +const SfxItemPropertyMap* lcl_GetShapeMap() +{ + static SfxItemPropertyMap aShapeMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_IMAGEMAP), 0, &getCppuType((uno::Reference<container::XIndexContainer>*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aShapeMap_Impl; +} + +// static +const SvEventDescription* ScShapeObj::GetSupportedMacroItems() +{ + static const SvEventDescription aMacroDescriptionsImpl[] = + { + { 0, NULL } + }; + return aMacroDescriptionsImpl; +} + +//------------------------------------------------------------------------ + +ScShapeObj::ScShapeObj( uno::Reference<drawing::XShape>& xShape ) + : pImplementationId(NULL), + bIsTextShape(FALSE) +{ + ::comphelper::increment( m_refCount ); + + { + mxShapeAgg = uno::Reference<uno::XAggregation>( xShape, uno::UNO_QUERY ); + // extra block to force deletion of the temporary before setDelegator + } + + if (mxShapeAgg.is()) + { + xShape = NULL; // during setDelegator, mxShapeAgg must be the only ref + + mxShapeAgg->setDelegator( (cppu::OWeakObject*)this ); + + xShape = uno::Reference<drawing::XShape>( mxShapeAgg, uno::UNO_QUERY ); + + bIsTextShape = ( SvxUnoTextBase::getImplementation( mxShapeAgg ) != NULL ); + } + + ::comphelper::decrement( m_refCount ); +} + +ScShapeObj::~ScShapeObj() +{ +// if (mxShapeAgg.is()) +// mxShapeAgg->setDelegator(uno::Reference<uno::XInterface>()); +} + +// XInterface + +uno::Any SAL_CALL ScShapeObj::queryInterface( const uno::Type& rType ) + throw(uno::RuntimeException) +{ + SC_QUERYINTERFACE( beans::XPropertySet ) + SC_QUERYINTERFACE( beans::XPropertyState ) + SC_QUERYINTERFACE( text::XTextContent ) + SC_QUERYINTERFACE( lang::XComponent ) + if ( bIsTextShape ) + { + // #105585# for text shapes, XText (and parent interfaces) must + // be handled here, too (for ScCellFieldObj handling): + SC_QUERYINTERFACE( text::XText ) + SC_QUERYINTERFACE( text::XSimpleText ) + SC_QUERYINTERFACE( text::XTextRange ) + } + SC_QUERYINTERFACE( lang::XTypeProvider ) + + uno::Any aRet = OWeakObject::queryInterface( rType ); + if ( !aRet.hasValue() && mxShapeAgg.is() ) + aRet = mxShapeAgg->queryAggregation( rType ); + + return aRet; +} + +void SAL_CALL ScShapeObj::acquire() throw() +{ + OWeakObject::acquire(); +} + +void SAL_CALL ScShapeObj::release() throw() +{ + OWeakObject::release(); +} + +uno::Reference<beans::XPropertySet> lcl_GetPropertySet( const uno::Reference<uno::XAggregation>& xAgg ) +{ + uno::Reference<beans::XPropertySet> xRet; + if ( xAgg.is() ) + xAgg->queryAggregation( getCppuType((uno::Reference<beans::XPropertySet>*) 0) ) >>= xRet; + return xRet; +} + +uno::Reference<beans::XPropertyState> lcl_GetPropertyState( const uno::Reference<uno::XAggregation>& xAgg ) +{ + uno::Reference<beans::XPropertyState> xRet; + if ( xAgg.is() ) + xAgg->queryAggregation( getCppuType((uno::Reference<beans::XPropertyState>*) 0) ) >>= xRet; + return xRet; +} + +uno::Reference<lang::XComponent> lcl_GetComponent( const uno::Reference<uno::XAggregation>& xAgg ) +{ + uno::Reference<lang::XComponent> xRet; + if ( xAgg.is() ) + xAgg->queryAggregation( getCppuType((uno::Reference<lang::XComponent>*) 0) ) >>= xRet; + return xRet; +} + +uno::Reference<text::XText> lcl_GetText( const uno::Reference<uno::XAggregation>& xAgg ) +{ + uno::Reference<text::XText> xRet; + if ( xAgg.is() ) + xAgg->queryAggregation( getCppuType((uno::Reference<text::XText>*) 0) ) >>= xRet; + return xRet; +} + +uno::Reference<text::XSimpleText> lcl_GetSimpleText( const uno::Reference<uno::XAggregation>& xAgg ) +{ + uno::Reference<text::XSimpleText> xRet; + if ( xAgg.is() ) + xAgg->queryAggregation( getCppuType((uno::Reference<text::XSimpleText>*) 0) ) >>= xRet; + return xRet; +} + +uno::Reference<text::XTextRange> lcl_GetTextRange( const uno::Reference<uno::XAggregation>& xAgg ) +{ + uno::Reference<text::XTextRange> xRet; + if ( xAgg.is() ) + xAgg->queryAggregation( getCppuType((uno::Reference<text::XTextRange>*) 0) ) >>= xRet; + return xRet; +} + +// XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScShapeObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // mix own and aggregated properties: + uno::Reference<beans::XPropertySetInfo> xRet; + uno::Reference<beans::XPropertySet> xAggProp = lcl_GetPropertySet(mxShapeAgg); + if ( xAggProp.is() ) + { + uno::Reference<beans::XPropertySetInfo> xAggInfo = xAggProp->getPropertySetInfo(); + const uno::Sequence<beans::Property> aPropSeq = xAggInfo->getProperties(); + xRet = new SfxExtItemPropertySetInfo( lcl_GetShapeMap(), aPropSeq ); + } + return xRet; +} + +void SAL_CALL ScShapeObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + + if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) ) + { + SdrObject* pObj = GetSdrObject(); + if ( pObj ) + { + ImageMap aImageMap; + uno::Reference< uno::XInterface > xImageMapInt; + aValue >>= xImageMapInt; + + if( !xImageMapInt.is() || !SvUnoImageMap_fillImageMap( xImageMapInt, aImageMap ) ) + throw lang::IllegalArgumentException(); + + ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(pObj); + if( pIMapInfo ) + { + // replace existing image map + pIMapInfo->SetImageMap( aImageMap ); + } + else + { + // insert new user data with image map + pObj->InsertUserData(new ScIMapInfo(aImageMap) ); + } + } + } + else + { + uno::Reference<beans::XPropertySet> xAggProp = lcl_GetPropertySet(mxShapeAgg); + if ( xAggProp.is() ) + xAggProp->setPropertyValue( aPropertyName, aValue ); + } +} + +uno::Any SAL_CALL ScShapeObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + + uno::Any aAny; + if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) ) + { + uno::Reference< uno::XInterface > xImageMap; + SdrObject* pObj = GetSdrObject(); + if ( pObj ) + { + ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(GetSdrObject()); + if( pIMapInfo ) + { + const ImageMap& rIMap = pIMapInfo->GetImageMap(); + xImageMap = SvUnoImageMap_createInstance( rIMap, GetSupportedMacroItems() ); + } + else + xImageMap = SvUnoImageMap_createInstance( GetSupportedMacroItems() ); + } + aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap ); + } + else + { + uno::Reference<beans::XPropertySet> xAggProp = lcl_GetPropertySet(mxShapeAgg); + if ( xAggProp.is() ) + aAny = xAggProp->getPropertyValue( aPropertyName ); + } + + return aAny; +} + +void SAL_CALL ScShapeObj::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, + const uno::Reference<beans::XPropertyChangeListener>& aListener) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<beans::XPropertySet> xAggProp = lcl_GetPropertySet(mxShapeAgg); + if ( xAggProp.is() ) + xAggProp->addPropertyChangeListener( aPropertyName, aListener ); +} + +void SAL_CALL ScShapeObj::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, + const uno::Reference<beans::XPropertyChangeListener>& aListener) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<beans::XPropertySet> xAggProp = lcl_GetPropertySet(mxShapeAgg); + if ( xAggProp.is() ) + xAggProp->removePropertyChangeListener( aPropertyName, aListener ); +} + +void SAL_CALL ScShapeObj::addVetoableChangeListener( const ::rtl::OUString& aPropertyName, + const uno::Reference<beans::XVetoableChangeListener>& aListener) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<beans::XPropertySet> xAggProp = lcl_GetPropertySet(mxShapeAgg); + if ( xAggProp.is() ) + xAggProp->addVetoableChangeListener( aPropertyName, aListener ); +} + +void SAL_CALL ScShapeObj::removeVetoableChangeListener( const ::rtl::OUString& aPropertyName, + const uno::Reference<beans::XVetoableChangeListener>& aListener) + throw(beans::UnknownPropertyException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<beans::XPropertySet> xAggProp = lcl_GetPropertySet(mxShapeAgg); + if ( xAggProp.is() ) + xAggProp->removeVetoableChangeListener( aPropertyName, aListener ); +} + +// XPropertyState + +beans::PropertyState SAL_CALL ScShapeObj::getPropertyState( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + + beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE; + if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) ) + { + // ImageMap is always "direct" + } + else + { + uno::Reference<beans::XPropertyState> xAggState = lcl_GetPropertyState(mxShapeAgg); + if ( xAggState.is() ) + eRet = xAggState->getPropertyState( aPropertyName ); + } + + return eRet; +} + +uno::Sequence<beans::PropertyState> SAL_CALL ScShapeObj::getPropertyStates( + const uno::Sequence< ::rtl::OUString>& aPropertyNames ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // simple loop to get own and aggregated states + + const ::rtl::OUString* pNames = aPropertyNames.getConstArray(); + uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength()); + beans::PropertyState* pStates = aRet.getArray(); + for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++) + pStates[i] = getPropertyState(pNames[i]); + return aRet; +} + +void SAL_CALL ScShapeObj::setPropertyToDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + + if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) ) + { + SdrObject* pObj = GetSdrObject(); + if ( pObj ) + { + ScIMapInfo* pIMapInfo = ScDrawLayer::GetIMapInfo(pObj); + if( pIMapInfo ) + { + ImageMap aEmpty; + pIMapInfo->SetImageMap( aEmpty ); // replace with empty image map + } + else + { + // nothing to do (no need to insert user data for an empty map) + } + } + } + else + { + uno::Reference<beans::XPropertyState> xAggState = lcl_GetPropertyState(mxShapeAgg); + if ( xAggState.is() ) + xAggState->setPropertyToDefault( aPropertyName ); + } +} + +uno::Any SAL_CALL ScShapeObj::getPropertyDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameString = aPropertyName; + + uno::Any aAny; + if ( aNameString.EqualsAscii( SC_UNONAME_IMAGEMAP ) ) + { + // default: empty ImageMap + uno::Reference< uno::XInterface > xImageMap = SvUnoImageMap_createInstance( GetSupportedMacroItems() ); + aAny <<= uno::Reference< container::XIndexContainer >::query( xImageMap ); + } + else + { + uno::Reference<beans::XPropertyState> xAggState = lcl_GetPropertyState(mxShapeAgg); + if ( xAggState.is() ) + aAny = xAggState->getPropertyDefault( aPropertyName ); + } + + return aAny; +} + +// XTextContent + +void SAL_CALL ScShapeObj::attach( const uno::Reference<text::XTextRange>& /*xTextRange*/ ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + throw lang::IllegalArgumentException(); // anchor cannot be changed +} + +BOOL lcl_GetPageNum( SdrPage* pPage, SdrModel& rModel, USHORT& rNum ) +{ + USHORT nCount = rModel.GetPageCount(); + for (USHORT i=0; i<nCount; i++) + if ( rModel.GetPage(i) == pPage ) + { + rNum = i; + return TRUE; + } + + return FALSE; +} + +uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getAnchor() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XTextRange> xRet; + + SdrObject* pObj = GetSdrObject(); + if( pObj ) + { + ScDrawLayer* pModel = (ScDrawLayer*)pObj->GetModel(); + SdrPage* pPage = pObj->GetPage(); + if ( pModel ) + { + ScDocument* pDoc = pModel->GetDocument(); + if ( pDoc ) + { + SfxObjectShell* pObjSh = pDoc->GetDocumentShell(); + if ( pObjSh && pObjSh->ISA(ScDocShell) ) + { + ScDocShell* pDocSh = (ScDocShell*)pObjSh; + + USHORT nTab = 0; + if ( lcl_GetPageNum( pPage, *pModel, nTab ) ) + { + Point aPos = pObj->GetBoundRect().TopLeft(); + ScRange aRange = pDoc->GetRange( nTab, Rectangle( aPos, aPos ) ); + + // anchor is always the cell + + xRet = new ScCellObj( pDocSh, aRange.aStart ); + } + } + } + } + } + + return xRet; +} + +// XComponent + +void SAL_CALL ScShapeObj::dispose() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<lang::XComponent> xAggComp = lcl_GetComponent(mxShapeAgg); + if ( xAggComp.is() ) + xAggComp->dispose(); +} + +void SAL_CALL ScShapeObj::addEventListener( + const uno::Reference<lang::XEventListener>& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<lang::XComponent> xAggComp = lcl_GetComponent(mxShapeAgg); + if ( xAggComp.is() ) + xAggComp->addEventListener(xListener); +} + +void SAL_CALL ScShapeObj::removeEventListener( + const uno::Reference<lang::XEventListener>& xListener ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<lang::XComponent> xAggComp = lcl_GetComponent(mxShapeAgg); + if ( xAggComp.is() ) + xAggComp->removeEventListener(xListener); +} + +// XText +// (special handling for ScCellFieldObj) + +void lcl_CopyOneProperty( beans::XPropertySet& rDest, beans::XPropertySet& rSource, const sal_Char* pName ) +{ + ::rtl::OUString aNameStr = ::rtl::OUString::createFromAscii(pName); + try + { + uno::Any aValue = rSource.getPropertyValue( aNameStr ); + rDest.setPropertyValue( aNameStr, aValue ); + } + catch (uno::Exception&) + { + OSL_FAIL("Exception in text field"); + } +} + +void SAL_CALL ScShapeObj::insertTextContent( const uno::Reference<text::XTextRange>& xRange, + const uno::Reference<text::XTextContent>& xContent, + sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XTextContent> xEffContent; + + ScCellFieldObj* pCellField = ScCellFieldObj::getImplementation( xContent ); + if ( pCellField ) + { + // #105585# createInstance("TextField.URL") from the document creates a ScCellFieldObj. + // To insert it into drawing text, a SvxUnoTextField is needed instead. + // The ScCellFieldObj object is left in non-inserted state. + + SvxUnoTextField* pDrawField = new SvxUnoTextField( ID_URLFIELD ); + xEffContent = pDrawField; + lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_URL ); + lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_REPR ); + lcl_CopyOneProperty( *pDrawField, *pCellField, SC_UNONAME_TARGET ); + } + else + xEffContent = xContent; + + uno::Reference<text::XText> xAggText = lcl_GetText(mxShapeAgg); + if ( xAggText.is() ) + xAggText->insertTextContent( xRange, xEffContent, bAbsorb ); +} + +void SAL_CALL ScShapeObj::removeTextContent( const uno::Reference<text::XTextContent>& xContent ) + throw(container::NoSuchElementException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + // ScCellFieldObj can't be used here. + + uno::Reference<text::XText> xAggText = lcl_GetText(mxShapeAgg); + if ( xAggText.is() ) + xAggText->removeTextContent( xContent ); +} + +// XSimpleText (parent of XText) +// Use own SvxUnoTextCursor subclass - everything is just passed to aggregated object + +uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( mxShapeAgg.is() ) + { + // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText + + SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( mxShapeAgg ); + if (pText) + return new ScDrawTextCursor( this, *pText ); + } + + return uno::Reference<text::XTextCursor>(); +} + +uno::Reference<text::XTextCursor> SAL_CALL ScShapeObj::createTextCursorByRange( + const uno::Reference<text::XTextRange>& aTextPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + if ( mxShapeAgg.is() && aTextPosition.is() ) + { + // ScDrawTextCursor must be used to ensure the ScShapeObj is returned by getText + + SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( mxShapeAgg ); + SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition ); + if ( pText && pRange ) + { + SvxUnoTextCursor* pCursor = new ScDrawTextCursor( this, *pText ); + uno::Reference<text::XTextCursor> xCursor( pCursor ); + pCursor->SetSelection( pRange->GetSelection() ); + return xCursor; + } + } + + return uno::Reference<text::XTextCursor>(); +} + +void SAL_CALL ScShapeObj::insertString( const uno::Reference<text::XTextRange>& xRange, + const ::rtl::OUString& aString, sal_Bool bAbsorb ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XSimpleText> xAggSimpleText = lcl_GetSimpleText(mxShapeAgg); + if ( xAggSimpleText.is() ) + xAggSimpleText->insertString( xRange, aString, bAbsorb ); + else + throw uno::RuntimeException(); +} + +void SAL_CALL ScShapeObj::insertControlCharacter( const uno::Reference<text::XTextRange>& xRange, + sal_Int16 nControlCharacter, sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XSimpleText> xAggSimpleText = lcl_GetSimpleText(mxShapeAgg); + if ( xAggSimpleText.is() ) + xAggSimpleText->insertControlCharacter( xRange, nControlCharacter, bAbsorb ); + else + throw uno::RuntimeException(); +} + +// XTextRange +// (parent of XSimpleText) + +uno::Reference<text::XText> SAL_CALL ScShapeObj::getText() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return this; +} + +uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getStart() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XTextRange> xAggTextRange = lcl_GetTextRange(mxShapeAgg); + if ( xAggTextRange.is() ) + return xAggTextRange->getStart(); + else + throw uno::RuntimeException(); + + return uno::Reference<text::XTextRange>(); +} + +uno::Reference<text::XTextRange> SAL_CALL ScShapeObj::getEnd() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XTextRange> xAggTextRange = lcl_GetTextRange(mxShapeAgg); + if ( xAggTextRange.is() ) + return xAggTextRange->getEnd(); + else + throw uno::RuntimeException(); + + return uno::Reference<text::XTextRange>(); +} + +::rtl::OUString SAL_CALL ScShapeObj::getString() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XTextRange> xAggTextRange = lcl_GetTextRange(mxShapeAgg); + if ( xAggTextRange.is() ) + return xAggTextRange->getString(); + else + throw uno::RuntimeException(); + + return ::rtl::OUString(); +} + +void SAL_CALL ScShapeObj::setString( const ::rtl::OUString& aText ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + uno::Reference<text::XTextRange> xAggTextRange = lcl_GetTextRange(mxShapeAgg); + if ( xAggTextRange.is() ) + xAggTextRange->setString( aText ); + else + throw uno::RuntimeException(); +} + +// XTypeProvider + +uno::Sequence<uno::Type> SAL_CALL ScShapeObj::getTypes() throw(uno::RuntimeException) +{ + uno::Sequence< uno::Type > aTypeSequence; + + uno::Reference<lang::XTypeProvider> xBaseProvider; + if ( mxShapeAgg.is() ) + mxShapeAgg->queryAggregation( getCppuType((uno::Reference<lang::XTypeProvider>*) 0) ) >>= xBaseProvider; + + DBG_ASSERT( xBaseProvider.is(), "ScShapeObj: No XTypeProvider from aggregated shape!" ); + if( xBaseProvider.is() ) + { + aTypeSequence = xBaseProvider->getTypes(); + long nBaseLen = aTypeSequence.getLength(); + + aTypeSequence.realloc( nBaseLen + 1 ); + uno::Type* pPtr = aTypeSequence.getArray(); + pPtr[nBaseLen + 0] = getCppuType((const uno::Reference<text::XTextContent>*)0); + } + return aTypeSequence; +} + +uno::Sequence<sal_Int8> SAL_CALL ScShapeObj::getImplementationId() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // do we need to compute the implementation id for this instance? + if( !pImplementationId && mxShapeAgg.is()) + { + uno::Reference< drawing::XShape > xAggShape; + mxShapeAgg->queryAggregation( ::getCppuType((uno::Reference< drawing::XShape >*)0) ) >>= xAggShape; + + if( xAggShape.is() ) + { + const ::rtl::OUString aShapeType( xAggShape->getShapeType() ); + // did we already compute an implementation id for the agregated shape type? + ScShapeImplementationIdMap::iterator aIter( aImplementationIdMap.find(aShapeType ) ); + if( aIter == aImplementationIdMap.end() ) + { + // we need to create a new implementation id for this + // note: this memory is not free'd until application exists + // but since we have a fixed set of shapetypes and the + // memory will be reused this is ok. + pImplementationId = new uno::Sequence< sal_Int8 >( 16 ); + rtl_createUuid( (sal_uInt8 *) pImplementationId->getArray(), 0, sal_True ); + aImplementationIdMap[ aShapeType ] = pImplementationId; + } + else + { + // use the already computed implementation id + pImplementationId = (*aIter).second; + } + } + } + if( NULL == pImplementationId ) + { + OSL_FAIL( "Could not create an implementation id for a ScXShape!" ); + return uno::Sequence< sal_Int8 > (); + } + else + { + return *pImplementationId; + } +} + +SdrObject* ScShapeObj::GetSdrObject() const throw() +{ + if(mxShapeAgg.is()) + { + SvxShape* pShape = SvxShape::getImplementation( mxShapeAgg ); + if(pShape) + return pShape->GetSdrObject(); + } + + return NULL; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_styleuno.cxx b/bf_sc/source/ui/unoobj/sc_styleuno.cxx new file mode 100644 index 000000000..1f4256a24 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_styleuno.cxx @@ -0,0 +1,1906 @@ +/* -*- 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. + * + ************************************************************************/ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include "scitems.hxx" +#include <bf_svx/algitem.hxx> +#include <bf_svx/langitem.hxx> +#include <bf_svx/numitem.hxx> +#include <bf_svx/pageitem.hxx> +#include <bf_svx/pbinitem.hxx> +#include <bf_svx/unonrule.hxx> +#include <bf_sfx2/printer.hxx> +#include <vcl/virdev.hxx> +#include <bf_svtools/itempool.hxx> +#include <bf_svtools/zformat.hxx> +#include <rtl/uuid.h> + +#include <com/sun/star/table/CellVertJustify.hpp> +#include <com/sun/star/table/TableBorder.hpp> +#include <com/sun/star/table/ShadowFormat.hpp> +#include <com/sun/star/table/CellHoriJustify.hpp> +#include <com/sun/star/table/CellOrientation.hpp> +#include <com/sun/star/style/PageStyleLayout.hpp> +#include <com/sun/star/style/GraphicLocation.hpp> +#include <com/sun/star/sheet/XHeaderFooterContent.hpp> +#include <com/sun/star/util/CellProtection.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include "styleuno.hxx" +#include "docsh.hxx" +#include "attrib.hxx" +#include "stlpool.hxx" +#include <vcl/svapp.hxx> +#include "miscuno.hxx" +#include "tablink.hxx" +#include "unonames.hxx" +#include "unowids.hxx" +#include "globstr.hrc" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +const SfxItemPropertyMap* lcl_GetCellStyleMap() +{ + static SfxItemPropertyMap aCellStyleMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNONAME_ASIANVERT),ATTR_VERTICAL_ASIAN,&getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_BOTTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CELLBACK), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CELLPRO), ATTR_PROTECTION, &::getCppuType((const util::CellProtection*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCOLOR), ATTR_FONT_COLOR, &::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_COUTL), ATTR_FONT_CONTOUR, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CCROSS), ATTR_FONT_CROSSEDOUT,&::getBooleanCppuType(), 0, MID_CROSSED_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CEMPHAS), ATTR_FONT_EMPHASISMARK,&getCppuType((sal_Int16*)0), 0, MID_EMPHASIS }, + {MAP_CHAR_LEN(SC_UNONAME_CFONT), ATTR_FONT, &::getCppuType((const sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFCHARS), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFCHARS), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFCHARS), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_CHAR_SET }, + {MAP_CHAR_LEN(SC_UNONAME_CFFAMIL), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFFAMIL), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFFAMIL), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_FAMILY }, + {MAP_CHAR_LEN(SC_UNONAME_CFNAME), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFNAME), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFNAME), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_FAMILY_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CFPITCH), ATTR_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFPITCH), ATTR_CJK_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFPITCH), ATTR_CTL_FONT, &getCppuType((sal_Int16*)0), 0, MID_FONT_PITCH }, + {MAP_CHAR_LEN(SC_UNONAME_CFSTYLE), ATTR_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CJK_CFSTYLE), ATTR_CJK_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNO_CTL_CFSTYLE), ATTR_CTL_FONT, &getCppuType((::rtl::OUString*)0), 0, MID_FONT_STYLE_NAME }, + {MAP_CHAR_LEN(SC_UNONAME_CHEIGHT), ATTR_FONT_HEIGHT, &::getCppuType((const float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CJK_CHEIGHT), ATTR_CJK_FONT_HEIGHT,&::getCppuType((const float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_CTL_CHEIGHT), ATTR_CTL_FONT_HEIGHT,&::getCppuType((const float*)0), 0, MID_FONTHEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_CLOCAL), ATTR_FONT_LANGUAGE, &::getCppuType((const lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CLOCAL), ATTR_CJK_FONT_LANGUAGE,&::getCppuType((const lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CLOCAL), ATTR_CTL_FONT_LANGUAGE,&::getCppuType((const lang::Locale*)0), 0, MID_LANG_LOCALE }, + {MAP_CHAR_LEN(SC_UNONAME_CPOST), ATTR_FONT_POSTURE, &::getCppuType((const awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CJK_CPOST), ATTR_CJK_FONT_POSTURE,&::getCppuType((const awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNO_CTL_CPOST), ATTR_CTL_FONT_POSTURE,&::getCppuType((const awt::FontSlant*)0), 0, MID_POSTURE }, + {MAP_CHAR_LEN(SC_UNONAME_CRELIEF), ATTR_FONT_RELIEF, &getCppuType((sal_Int16*)0), 0, MID_RELIEF }, + {MAP_CHAR_LEN(SC_UNONAME_CSHADD), ATTR_FONT_SHADOWED, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CSTRIKE), ATTR_FONT_CROSSEDOUT,&getCppuType((sal_Int16*)0), 0, MID_CROSS_OUT }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDER), ATTR_FONT_UNDERLINE,&::getCppuType((const sal_Int16*)0), 0, MID_UNDERLINE }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLCOL), ATTR_FONT_UNDERLINE,&getCppuType((sal_Int32*)0), 0, MID_UL_COLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CUNDLHAS), ATTR_FONT_UNDERLINE,&getBooleanCppuType(), 0, MID_UL_HASCOLOR }, + {MAP_CHAR_LEN(SC_UNONAME_CWEIGHT), ATTR_FONT_WEIGHT, &::getCppuType((const float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CJK_CWEIGHT), ATTR_CJK_FONT_WEIGHT,&::getCppuType((const float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNO_CTL_CWEIGHT), ATTR_CTL_FONT_WEIGHT,&::getCppuType((const float*)0), 0, MID_WEIGHT }, + {MAP_CHAR_LEN(SC_UNONAME_CWORDMOD), ATTR_FONT_WORDLINE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_DISPNAME), SC_WID_UNO_DISPNAME,&::getCppuType((::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLHJUS), ATTR_HOR_JUSTIFY, &::getCppuType((const table::CellHoriJustify*)0), 0, MID_HORJUST_HORJUST }, + {MAP_CHAR_LEN(SC_UNONAME_CELLTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNONAME_WRAP), ATTR_LINEBREAK, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_LEFTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_NUMFMT), ATTR_VALUE_FORMAT, &::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLORI), ATTR_ORIENTATION, &::getCppuType((const table::CellOrientation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PADJUST), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PBMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PINDENT), ATTR_INDENT, &::getCppuType((const sal_Int16*)0), 0, 0 }, //! CONVERT_TWIPS + {MAP_CHAR_LEN(SC_UNONAME_PISCHDIST),ATTR_SCRIPTSPACE, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISFORBID),ATTR_FORBIDDEN_RULES,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHANG), ATTR_HANGPUNCTUATION,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PISHYPHEN),ATTR_HYPHENATE, &getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_PLASTADJ), ATTR_HOR_JUSTIFY, &::getCppuType((const sal_Int16*)0), 0, MID_HORJUST_ADJUST }, + {MAP_CHAR_LEN(SC_UNONAME_PLMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PRMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_PTMARGIN), ATTR_MARGIN, &::getCppuType((const sal_Int32*)0), 0, MID_MARGIN_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_RIGHTBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_ROTANG), ATTR_ROTATE_VALUE, &::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_ROTREF), ATTR_ROTATE_MODE, &::getCppuType((const table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_SHADOW), ATTR_SHADOW, &::getCppuType((const table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TBLBORD), SC_WID_UNO_TBLBORD, &::getCppuType((const table::TableBorder*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_TOPBORDER),ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_CELLVJUS), ATTR_VER_JUSTIFY, &::getCppuType((const table::CellVertJustify*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aCellStyleMap_Impl; +} + +// Map mit allen Seitenattributen, incl. Kopf-/Fusszeilenattribute + +const SfxItemPropertyMap* lcl_GetPageStyleMap() +{ + static SfxItemPropertyMap aPageStyleMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNO_PAGE_BACKCOLOR), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNO_PAGE_GRAPHICFILT), ATTR_BACKGROUND, &::getCppuType((const ::rtl::OUString*)0), 0, MID_GRAPHIC_FILTER }, + {MAP_CHAR_LEN(SC_UNO_PAGE_GRAPHICLOC), ATTR_BACKGROUND, &::getCppuType((const style::GraphicLocation*)0), 0, MID_GRAPHIC_POSITION }, + {MAP_CHAR_LEN(SC_UNO_PAGE_GRAPHICURL), ATTR_BACKGROUND, &::getCppuType((const ::rtl::OUString*)0), 0, MID_GRAPHIC_URL }, + {MAP_CHAR_LEN(SC_UNO_PAGE_BACKTRANS), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_BACKCOLOR), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNO_PAGE_BORDERDIST), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_BOTTBORDER), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_BOTTBRDDIST), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, BOTTOM_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_BOTTMARGIN), ATTR_ULSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_CENTERHOR), ATTR_PAGE_HORCENTER,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_CENTERVER), ATTR_PAGE_VERCENTER,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_DISPNAME), SC_WID_UNO_DISPNAME,&::getCppuType((::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FIRSTPAGE), ATTR_PAGE_FIRSTPAGENO,&::getCppuType((const sal_Int16*)0), 0, 0 }, +// + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBACKCOL), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRGRFFILT), SC_WID_UNO_FOOTERSET,&::getCppuType((const ::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRGRFLOC), SC_WID_UNO_FOOTERSET,&::getCppuType((const style::GraphicLocation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRGRFURL), SC_WID_UNO_FOOTERSET,&::getCppuType((const ::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBACKTRAN), SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRBACKCOL), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBODYDIST), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBRDDIST), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBOTTBOR), SC_WID_UNO_FOOTERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBOTTBDIS), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRDYNAMIC), SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRHEIGHT), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRDYNAMIC), SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRON), SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRSHARED), SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRLEFTBOR), SC_WID_UNO_FOOTERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRLEFTBDIS), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRLEFTMAR), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRON), SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRRIGHTBOR), SC_WID_UNO_FOOTERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRRIGHTBDIS),SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRRIGHTMAR), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRSHADOW), SC_WID_UNO_FOOTERSET,&::getCppuType((const table::ShadowFormat*)0), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRSHARED), SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRTOPBOR), SC_WID_UNO_FOOTERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRTOPBDIS), SC_WID_UNO_FOOTERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, +// + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBACKCOL), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRGRFFILT), SC_WID_UNO_HEADERSET,&::getCppuType((const ::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRGRFLOC), SC_WID_UNO_HEADERSET,&::getCppuType((const style::GraphicLocation*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRGRFURL), SC_WID_UNO_HEADERSET,&::getCppuType((const ::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBACKTRAN), SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRBACKCOL), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBODYDIST), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBRDDIST), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBOTTBOR), SC_WID_UNO_HEADERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBOTTBDIS), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRDYNAMIC), SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRHEIGHT), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRDYNAMIC), SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRON), SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRSHARED), SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRLEFTBOR), SC_WID_UNO_HEADERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRLEFTBDIS), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRLEFTMAR), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRON), SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRRIGHTBOR), SC_WID_UNO_HEADERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRRIGHTBDIS),SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRRIGHTMAR), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRSHADOW), SC_WID_UNO_HEADERSET,&::getCppuType((const table::ShadowFormat*)0), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRSHARED), SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRTOPBOR), SC_WID_UNO_HEADERSET,&::getCppuType((const table::BorderLine*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRTOPBDIS), SC_WID_UNO_HEADERSET,&::getCppuType((const sal_Int32*)0), 0, 0 }, +// + {MAP_CHAR_LEN(SC_UNO_PAGE_HEIGHT), ATTR_PAGE_SIZE, &::getCppuType((const sal_Int32*)0), 0, MID_SIZE_HEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_BACKTRANS), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(SC_UNO_PAGE_LANDSCAPE), ATTR_PAGE, &::getBooleanCppuType(), 0, MID_PAGE_ORIENTATION }, + {MAP_CHAR_LEN(SC_UNO_PAGE_LEFTBORDER), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_LEFTBRDDIST), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, LEFT_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_LEFTMARGIN), ATTR_LRSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_LEFTFTRCONT), ATTR_PAGE_FOOTERLEFT,&::getCppuType((const uno::Reference< sheet::XHeaderFooterContent >*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_LEFTHDRCONT), ATTR_PAGE_HEADERLEFT,&::getCppuType((const uno::Reference< sheet::XHeaderFooterContent >*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_NUMBERTYPE), ATTR_PAGE, &::getCppuType((const sal_Int16*)0), 0, MID_PAGE_NUMTYPE }, + {MAP_CHAR_LEN(SC_UNO_PAGE_SCALEVAL), ATTR_PAGE_SCALE, &::getCppuType((const sal_Int16*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_SYTLELAYOUT), ATTR_PAGE, &::getCppuType((const style::PageStyleLayout*)0), 0, MID_PAGE_LAYOUT }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTANNOT), ATTR_PAGE_NOTES, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTCHARTS), ATTR_PAGE_CHARTS, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTDOWN), ATTR_PAGE_TOPDOWN, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTDRAW), ATTR_PAGE_DRAWINGS, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTFORMUL), ATTR_PAGE_FORMULAS, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTGRID), ATTR_PAGE_GRID, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTHEADER), ATTR_PAGE_HEADERS, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTOBJS), ATTR_PAGE_OBJECTS, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PRINTZERO), ATTR_PAGE_NULLVALS, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_PAPERTRAY), ATTR_PAGE_PAPERBIN, &::getCppuType((const ::rtl::OUString*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_RIGHTBORDER), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_RIGHTBRDDIST),ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, RIGHT_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_RIGHTMARGIN), ATTR_LRSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_RIGHTFTRCON), ATTR_PAGE_FOOTERRIGHT,&::getCppuType((const uno::Reference< sheet::XHeaderFooterContent >*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_RIGHTHDRCON), ATTR_PAGE_HEADERRIGHT,&::getCppuType((const uno::Reference< sheet::XHeaderFooterContent >*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_SCALETOPAG), ATTR_PAGE_SCALETOPAGES,&::getCppuType((const sal_Int16*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_SHADOWFORM), ATTR_SHADOW, &::getCppuType((const table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_SIZE), ATTR_PAGE_SIZE, &::getCppuType((const awt::Size*)0), 0, MID_SIZE_SIZE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_TOPBORDER), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_TOPBRDDIST), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, TOP_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_TOPMARGIN), ATTR_ULSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRBACKTRAN),SC_WID_UNO_FOOTERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRBACKTRAN),SC_WID_UNO_HEADERSET,&::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNONAME_USERDEF), ATTR_USERDEF, &getCppuType((uno::Reference<container::XNameContainer>*)0), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_WIDTH), ATTR_PAGE_SIZE, &::getCppuType((const sal_Int32*)0), 0, MID_SIZE_WIDTH | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNONAME_WRITING), ATTR_WRITINGDIR, &getCppuType((sal_Int16*)0), 0, 0 }, + {0,0,0,0,0,0} + }; + return aPageStyleMap_Impl; +} + +// Map mit Inhalten des Header-Item-Sets + +const SfxItemPropertyMap* lcl_GetHeaderStyleMap() +{ + static SfxItemPropertyMap aHeaderStyleMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBACKCOL), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRGRFFILT), ATTR_BACKGROUND, &::getCppuType((const ::rtl::OUString*)0), 0, MID_GRAPHIC_FILTER }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRGRFLOC), ATTR_BACKGROUND, &::getCppuType((const style::GraphicLocation*)0), 0, MID_GRAPHIC_POSITION }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRGRFURL), ATTR_BACKGROUND, &::getCppuType((const ::rtl::OUString*)0), 0, MID_GRAPHIC_URL }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBACKTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRBACKCOL), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBODYDIST), ATTR_ULSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_LO_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBRDDIST), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBOTTBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRBOTTBDIS), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, BOTTOM_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRDYNAMIC), ATTR_PAGE_DYNAMIC, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRHEIGHT), ATTR_PAGE_SIZE, &::getCppuType((const sal_Int32*)0), 0, MID_SIZE_HEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRDYNAMIC), ATTR_PAGE_DYNAMIC, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRON), ATTR_PAGE_ON, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRSHARED), ATTR_PAGE_SHARED, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRLEFTBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRLEFTBDIS), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, LEFT_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRLEFTMAR), ATTR_LRSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRON), ATTR_PAGE_ON, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRRIGHTBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRRIGHTBDIS),ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, RIGHT_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRRIGHTMAR), ATTR_LRSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRSHADOW), ATTR_SHADOW, &::getCppuType((const table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRSHARED), ATTR_PAGE_SHARED, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRTOPBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_HDRTOPBDIS), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, TOP_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_HDRBACKTRAN),ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {0,0,0,0,0,0} + }; + return aHeaderStyleMap_Impl; +} + +// Map mit Inhalten des Footer-Item-Sets + +const SfxItemPropertyMap* lcl_GetFooterStyleMap() +{ + static SfxItemPropertyMap aFooterStyleMap_Impl[] = + { + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBACKCOL), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRGRFFILT), ATTR_BACKGROUND, &::getCppuType((const ::rtl::OUString*)0), 0, MID_GRAPHIC_FILTER }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRGRFLOC), ATTR_BACKGROUND, &::getCppuType((const style::GraphicLocation*)0), 0, MID_GRAPHIC_POSITION }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRGRFURL), ATTR_BACKGROUND, &::getCppuType((const ::rtl::OUString*)0), 0, MID_GRAPHIC_URL }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBACKTRAN), ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRBACKCOL), ATTR_BACKGROUND, &::getCppuType((const sal_Int32*)0), 0, MID_BACK_COLOR }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBODYDIST), ATTR_ULSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_UP_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBRDDIST), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBOTTBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, BOTTOM_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRBOTTBDIS), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, BOTTOM_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRDYNAMIC), ATTR_PAGE_DYNAMIC, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRHEIGHT), ATTR_PAGE_SIZE, &::getCppuType((const sal_Int32*)0), 0, MID_SIZE_HEIGHT | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRDYNAMIC), ATTR_PAGE_DYNAMIC, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRON), ATTR_PAGE_ON, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRSHARED), ATTR_PAGE_SHARED, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRLEFTBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, LEFT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRLEFTBDIS), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, LEFT_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRLEFTMAR), ATTR_LRSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_L_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRON), ATTR_PAGE_ON, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRRIGHTBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, RIGHT_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRRIGHTBDIS),ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, RIGHT_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRRIGHTMAR), ATTR_LRSPACE, &::getCppuType((const sal_Int32*)0), 0, MID_R_MARGIN | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRSHADOW), ATTR_SHADOW, &::getCppuType((const table::ShadowFormat*)0), 0, 0 | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRSHARED), ATTR_PAGE_SHARED, &::getBooleanCppuType(), 0, 0 }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRTOPBOR), ATTR_BORDER, &::getCppuType((const table::BorderLine*)0), 0, TOP_BORDER | CONVERT_TWIPS }, + {MAP_CHAR_LEN(SC_UNO_PAGE_FTRTOPBDIS), ATTR_BORDER, &::getCppuType((const sal_Int32*)0), 0, TOP_BORDER_DISTANCE | CONVERT_TWIPS }, + {MAP_CHAR_LEN(OLD_UNO_PAGE_FTRBACKTRAN),ATTR_BACKGROUND, &::getBooleanCppuType(), 0, MID_GRAPHIC_TRANSPARENT }, + {0,0,0,0,0,0} + }; + return aFooterStyleMap_Impl; +} + + + +// Index-Access auf die Style-Typen: 0 = Cell, 1 = Page + +#define SC_STYLE_FAMILY_COUNT 2 + +#define SC_FAMILYNAME_CELL "CellStyles" +#define SC_FAMILYNAME_PAGE "PageStyles" + +static UINT16 aStyleFamilyTypes[SC_STYLE_FAMILY_COUNT] = { SFX_STYLE_FAMILY_PARA, SFX_STYLE_FAMILY_PAGE }; + + +//! diese Funktionen in einen allgemeinen Header verschieben +inline long TwipsToHMM(long nTwips) { return (nTwips * 127 + 36) / 72; } +inline long HMMToTwips(long nHMM) { return (nHMM * 72 + 63) / 127; } + + +#define SCSTYLE_SERVICE "com.sun.star.style.Style" +#define SCCELLSTYLE_SERVICE "com.sun.star.style.CellStyle" +#define SCPAGESTYLE_SERVICE "com.sun.star.style.PageStyle" + +SC_SIMPLE_SERVICE_INFO( ScStyleFamiliesObj, "ScStyleFamiliesObj", "com.sun.star.style.StyleFamilies" ) +SC_SIMPLE_SERVICE_INFO( ScStyleFamilyObj, "ScStyleFamilyObj", "com.sun.star.style.StyleFamily" ) + + +#define SC_PAPERBIN_DEFAULTNAME "[From printer settings]" + + +// conversion programmatic <-> display (visible) name +// currently, the core always has the visible names +// the api is required to use programmatic names for default styles +// these programmatic names must never change! + +#define SC_STYLE_PROG_STANDARD "Default" +#define SC_STYLE_PROG_RESULT "Result" +#define SC_STYLE_PROG_RESULT1 "Result2" +#define SC_STYLE_PROG_HEADLINE "Heading" +#define SC_STYLE_PROG_HEADLINE1 "Heading1" +#define SC_STYLE_PROG_REPORT "Report" + +struct ScDisplayNameMap +{ + String aDispName; + String aProgName; +}; + +const ScDisplayNameMap* lcl_GetStyleNameMap( UINT16 nType ) +{ + if ( nType == SFX_STYLE_FAMILY_PARA ) + { + static BOOL bCellMapFilled = FALSE; + static ScDisplayNameMap aCellMap[6]; + if ( !bCellMapFilled ) + { + aCellMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD ); + aCellMap[0].aProgName = String::CreateFromAscii( SC_STYLE_PROG_STANDARD ); + + aCellMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT ); + aCellMap[1].aProgName = String::CreateFromAscii( SC_STYLE_PROG_RESULT ); + + aCellMap[2].aDispName = ScGlobal::GetRscString( STR_STYLENAME_RESULT1 ); + aCellMap[2].aProgName = String::CreateFromAscii( SC_STYLE_PROG_RESULT1 ); + + aCellMap[3].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE ); + aCellMap[3].aProgName = String::CreateFromAscii( SC_STYLE_PROG_HEADLINE ); + + aCellMap[4].aDispName = ScGlobal::GetRscString( STR_STYLENAME_HEADLINE1 ); + aCellMap[4].aProgName = String::CreateFromAscii( SC_STYLE_PROG_HEADLINE1 ); + + // last entry remains empty + + bCellMapFilled = TRUE; + } + return aCellMap; + } + else if ( nType == SFX_STYLE_FAMILY_PAGE ) + { + static BOOL bPageMapFilled = FALSE; + static ScDisplayNameMap aPageMap[3]; + if ( !bPageMapFilled ) + { + aPageMap[0].aDispName = ScGlobal::GetRscString( STR_STYLENAME_STANDARD ); + aPageMap[0].aProgName = String::CreateFromAscii( SC_STYLE_PROG_STANDARD ); + + aPageMap[1].aDispName = ScGlobal::GetRscString( STR_STYLENAME_REPORT ); + aPageMap[1].aProgName = String::CreateFromAscii( SC_STYLE_PROG_REPORT ); + + // last entry remains empty + + bPageMapFilled = TRUE; + } + return aPageMap; + } + OSL_FAIL("invalid family"); + return NULL; +} + +// programmatic name suffix for display names that match other programmatic names +// is " (user)" including a space + +#define SC_SUFFIX_USER " (user)" +#define SC_SUFFIX_USER_LEN 7 + +BOOL lcl_EndsWithUser( const String& rString ) +{ + const sal_Unicode *pChar = rString.GetBuffer(); + xub_StrLen nLen = rString.Len(); + return nLen >= SC_SUFFIX_USER_LEN && + pChar[nLen-7] == ' ' && + pChar[nLen-6] == '(' && + pChar[nLen-5] == 'u' && + pChar[nLen-4] == 's' && + pChar[nLen-3] == 'e' && + pChar[nLen-2] == 'r' && + pChar[nLen-1] == ')'; +} + +// static +String ScStyleNameConversion::DisplayToProgrammaticName( const String& rDispName, UINT16 nType ) +{ + BOOL bDisplayIsProgrammatic = FALSE; + + const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType ); + if (pNames) + { + do + { + if (pNames->aDispName == rDispName) + return pNames->aProgName; + else if (pNames->aProgName == rDispName) + bDisplayIsProgrammatic = TRUE; // display name matches any programmatic name + } + while( (++pNames)->aDispName.Len() ); + } + + if ( bDisplayIsProgrammatic || lcl_EndsWithUser( rDispName ) ) + { + // add the (user) suffix if the display name matches any style's programmatic name + // or if it already contains the suffix + + String aRet = rDispName; + aRet.AppendAscii( RTL_CONSTASCII_STRINGPARAM( SC_SUFFIX_USER ) ); + return aRet; + } + + return rDispName; +} + +// static +String ScStyleNameConversion::ProgrammaticToDisplayName( const String& rProgName, UINT16 nType ) +{ + if ( lcl_EndsWithUser( rProgName ) ) + { + // remove the (user) suffix, don't compare to map entries + return rProgName.Copy( 0, rProgName.Len() - SC_SUFFIX_USER_LEN ); + } + + const ScDisplayNameMap* pNames = lcl_GetStyleNameMap( nType ); + if (pNames) + { + do + { + if (pNames->aProgName == rProgName) + return pNames->aDispName; + } + while( (++pNames)->aDispName.Len() ); + } + return rProgName; +} + + +sal_Bool lcl_AnyTabProtected( ScDocument& rDoc ) +{ + USHORT nTabCount = rDoc.GetTableCount(); + for (USHORT i=0; i<nTabCount; i++) + if (rDoc.IsTabProtected(i)) + return sal_True; + return sal_False; +} + + +ScStyleFamiliesObj::ScStyleFamiliesObj(ScDocShell* pDocSh) : + pDocShell( pDocSh ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScStyleFamiliesObj::~ScStyleFamiliesObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScStyleFamiliesObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XStyleFamilies + +ScStyleFamilyObj*ScStyleFamiliesObj::GetObjectByType_Impl(UINT16 nType) const +{ + if ( pDocShell ) + { + if ( nType == SFX_STYLE_FAMILY_PARA ) + return new ScStyleFamilyObj( pDocShell, SFX_STYLE_FAMILY_PARA ); + else if ( nType == SFX_STYLE_FAMILY_PAGE ) + return new ScStyleFamilyObj( pDocShell, SFX_STYLE_FAMILY_PAGE ); + } + OSL_FAIL("getStyleFamilyByType: keine DocShell oder falscher Typ"); + return NULL; +} + +ScStyleFamilyObj* ScStyleFamiliesObj::GetObjectByIndex_Impl(UINT32 nIndex) const +{ + if ( nIndex < SC_STYLE_FAMILY_COUNT ) + return GetObjectByType_Impl(aStyleFamilyTypes[nIndex]); + + return NULL; // ungueltiger Index +} + +ScStyleFamilyObj* ScStyleFamiliesObj::GetObjectByName_Impl(const ::rtl::OUString& aName) const +{ + if ( pDocShell ) + { + String aNameStr( aName ); + if ( aNameStr.EqualsAscii( SC_FAMILYNAME_CELL ) ) + return new ScStyleFamilyObj( pDocShell, SFX_STYLE_FAMILY_PARA ); + else if ( aNameStr.EqualsAscii( SC_FAMILYNAME_PAGE ) ) + return new ScStyleFamilyObj( pDocShell, SFX_STYLE_FAMILY_PAGE ); + } + // no assertion - called directly from getByName + return NULL; +} + +// container::XIndexAccess + +sal_Int32 SAL_CALL ScStyleFamiliesObj::getCount() throw(uno::RuntimeException) +{ + return SC_STYLE_FAMILY_COUNT; +} + +uno::Any SAL_CALL ScStyleFamiliesObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< container::XNameContainer > xFamily = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xFamily.is()) + aAny <<= xFamily; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScStyleFamiliesObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ::getCppuType((const uno::Reference< container::XNameContainer >*)0); // muss zu getByIndex passen +} + +sal_Bool SAL_CALL ScStyleFamiliesObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// container::XNameAccess + +uno::Any SAL_CALL ScStyleFamiliesObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< container::XNameContainer > xFamily = GetObjectByName_Impl(aName); + uno::Any aAny; + if (xFamily.is()) + aAny <<= xFamily; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScStyleFamiliesObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Sequence< ::rtl::OUString> aNames(SC_STYLE_FAMILY_COUNT); + ::rtl::OUString* pNames = aNames.getArray(); + pNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_FAMILYNAME_CELL )); + pNames[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_FAMILYNAME_PAGE )); + return aNames; +} + +sal_Bool SAL_CALL ScStyleFamiliesObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aNameStr( aName ); + return ( aNameStr.EqualsAscii( SC_FAMILYNAME_CELL ) || aNameStr.EqualsAscii( SC_FAMILYNAME_PAGE ) ); +} + +// style::XStyleLoader + +void SAL_CALL ScStyleFamiliesObj::loadStylesFromURL( const ::rtl::OUString& aURL, + const uno::Sequence<beans::PropertyValue>& aOptions ) + throw(io::IOException, uno::RuntimeException) +{ + //! use aOptions (like Writer) + //! set flag to disable filter option dialogs when importing + + String aFilter; // empty - detect + String aFiltOpt; + ScDocumentLoader aLoader( aURL, aFilter, aFiltOpt ); + + ScDocShell* pSource = aLoader.GetDocShell(); + if ( pSource && pDocShell ) + { + // collect options + + BOOL bLoadReplace = TRUE; // defaults + BOOL bLoadCellStyles = TRUE; + BOOL bLoadPageStyles = TRUE; + + const beans::PropertyValue* pPropArray = aOptions.getConstArray(); + long nPropCount = aOptions.getLength(); + for (long i = 0; i < nPropCount; i++) + { + const beans::PropertyValue& rProp = pPropArray[i]; + String aPropName = rProp.Name; + + if (aPropName.EqualsAscii( SC_UNONAME_OVERWSTL )) + bLoadReplace = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_LOADCELL )) + bLoadCellStyles = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + else if (aPropName.EqualsAscii( SC_UNONAME_LOADPAGE )) + bLoadPageStyles = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value ); + } + + pDocShell->LoadStylesArgs( *pSource, bLoadReplace, bLoadCellStyles, bLoadPageStyles ); + pDocShell->SetDocumentModified(); // paint is inside LoadStyles + } +} + +uno::Sequence<beans::PropertyValue> SAL_CALL ScStyleFamiliesObj::getStyleLoaderOptions() + throw(uno::RuntimeException) +{ + // return defaults for options (?) + + uno::Sequence<beans::PropertyValue> aSequence(3); + beans::PropertyValue* pArray = aSequence.getArray(); + + pArray[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_OVERWSTL )); + ScUnoHelpFunctions::SetBoolInAny( pArray[0].Value, TRUE ); + + pArray[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_LOADCELL )); + ScUnoHelpFunctions::SetBoolInAny( pArray[1].Value, TRUE ); + + pArray[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_UNONAME_LOADPAGE )); + ScUnoHelpFunctions::SetBoolInAny( pArray[2].Value, TRUE ); + + return aSequence; +} + +//------------------------------------------------------------------------ + +ScStyleFamilyObj::ScStyleFamilyObj(ScDocShell* pDocSh, SfxStyleFamily eFam) : + pDocShell( pDocSh ), + eFamily( eFam ) +{ + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScStyleFamilyObj::~ScStyleFamilyObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +void ScStyleFamilyObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +// XStyleFamily + +ScStyleObj* ScStyleFamilyObj::GetObjectByIndex_Impl(UINT32 nIndex) +{ + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + + SfxStyleSheetIterator aIter( pStylePool, eFamily ); + if ( nIndex < aIter.Count() ) + { + SfxStyleSheetBase* pStyle = aIter[(USHORT)nIndex]; + if ( pStyle ) + { + String aName = pStyle->GetName(); + return new ScStyleObj( pDocShell, eFamily, aName ); + } + } + } + return NULL; +} + +ScStyleObj* ScStyleFamilyObj::GetObjectByName_Impl(const ::rtl::OUString& aName) +{ + if ( pDocShell ) + { + String aString = aName; + + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + if ( pStylePool->Find( aString, eFamily ) ) + return new ScStyleObj( pDocShell, eFamily, aString ); + } + return NULL; +} + +void SAL_CALL ScStyleFamilyObj::insertByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::ElementExistException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + sal_Bool bDone = sal_False; + // Reflection muss nicht uno::XInterface sein, kann auch irgendein Interface sein... + uno::Reference< uno::XInterface > xInterface; + if ( aElement >>= xInterface ) + { + ScStyleObj* pStyleObj = ScStyleObj::getImplementation( xInterface ); + if ( pStyleObj && pStyleObj->GetFamily() == eFamily && + !pStyleObj->IsInserted() ) // noch nicht eingefuegt? + { + String aNameStr = ScStyleNameConversion::ProgrammaticToDisplayName( aName, eFamily ); + + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + + //! DocFunc-Funktion?? + //! Undo ????????????? + + if ( !pStylePool->Find( aNameStr, eFamily ) ) // noch nicht vorhanden + { + /*SfxStyleSheetBase& rStyle =*/ pStylePool->Make( aNameStr, eFamily, SFXSTYLEBIT_USERDEF ); + + pStyleObj->InitDoc( pDocShell, aNameStr ); // Objekt kann benutzt werden + + pDocShell->SetDocumentModified(); // verwendet wird der neue Style noch nicht + bDone = sal_True; + } + else + throw container::ElementExistException(); + } + } + + if (!bDone) + { + // other errors are handled above + throw lang::IllegalArgumentException(); + } +} + +void SAL_CALL ScStyleFamilyObj::replaceByName( const ::rtl::OUString& aName, const uno::Any& aElement ) + throw(lang::IllegalArgumentException, container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + //! zusammenfassen? + removeByName( aName ); + insertByName( aName, aElement ); +} + +void SAL_CALL ScStyleFamilyObj::removeByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + BOOL bFound = FALSE; + if ( pDocShell ) + { + String aString = ScStyleNameConversion::ProgrammaticToDisplayName( aName, eFamily ); + + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + + //! DocFunc-Funktion?? + //! Undo ????????????? + + SfxStyleSheetBase* pStyle = pStylePool->Find( aString, eFamily ); + if (pStyle) + { + bFound = TRUE; + if ( eFamily == SFX_STYLE_FAMILY_PARA ) + { + // wie ScViewFunc::RemoveStyleSheetInUse + VirtualDevice aVDev; + Point aLogic = aVDev.LogicToPixel( Point(1000,1000), MAP_TWIP ); + double nPPTX = aLogic.X() / 1000.0; + double nPPTY = aLogic.Y() / 1000.0; + Fraction aZoom(1,1); + pDoc->StyleSheetChanged( pStyle, sal_False, &aVDev, nPPTX, nPPTY, aZoom, aZoom ); + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_LEFT ); + pDocShell->SetDocumentModified(); + + pStylePool->Erase( pStyle ); + + } + else + { + if ( pDoc->RemovePageStyleInUse( aString ) ) + pDocShell->PageStyleModified( ScGlobal::GetRscString(STR_STYLENAME_STANDARD), sal_True ); + + pStylePool->Erase( pStyle ); + + pDocShell->SetDocumentModified(); + } + } + } + + if (!bFound) + throw container::NoSuchElementException(); +} + +// container::XIndexAccess + +sal_Int32 SAL_CALL ScStyleFamilyObj::getCount() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + + SfxStyleSheetIterator aIter( pStylePool, eFamily ); + return aIter.Count(); + } + return 0; +} + +uno::Any SAL_CALL ScStyleFamilyObj::getByIndex( sal_Int32 nIndex ) + throw(lang::IndexOutOfBoundsException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< style::XStyle > xObj = GetObjectByIndex_Impl(nIndex); + uno::Any aAny; + if (xObj.is()) + aAny <<= xObj; + else + throw lang::IndexOutOfBoundsException(); + return aAny; +} + +uno::Type SAL_CALL ScStyleFamilyObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ::getCppuType((const uno::Reference< style::XStyle >*)0); // muss zu getByIndex passen +} + +sal_Bool SAL_CALL ScStyleFamilyObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return ( getCount() != 0 ); +} + +// container::XNameAccess + +uno::Any SAL_CALL ScStyleFamilyObj::getByName( const ::rtl::OUString& aName ) + throw(container::NoSuchElementException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + uno::Reference< style::XStyle > xObj = + GetObjectByName_Impl( ScStyleNameConversion::ProgrammaticToDisplayName( aName, eFamily ) ); + uno::Any aAny; + if (xObj.is()) + aAny <<= xObj; + else + throw container::NoSuchElementException(); + return aAny; +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScStyleFamilyObj::getElementNames() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + + SfxStyleSheetIterator aIter( pStylePool, eFamily ); + UINT16 nCount = aIter.Count(); + + String aName; + uno::Sequence< ::rtl::OUString> aSeq(nCount); + ::rtl::OUString* pAry = aSeq.getArray(); + SfxStyleSheetBase* pStyle = aIter.First(); + UINT16 nPos = 0; + while (pStyle) + { + DBG_ASSERT( nPos<nCount, "Anzahl durcheinandergekommen" ); + if (nPos<nCount) + pAry[nPos++] = ScStyleNameConversion::DisplayToProgrammaticName( + pStyle->GetName(), eFamily ); + pStyle = aIter.Next(); + } + return aSeq; + } + return uno::Sequence< ::rtl::OUString>(); +} + +sal_Bool SAL_CALL ScStyleFamilyObj::hasByName( const ::rtl::OUString& aName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( pDocShell ) + { + String aString = ScStyleNameConversion::ProgrammaticToDisplayName( aName, eFamily ); + + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + if ( pStylePool->Find( aString, eFamily ) ) + return sal_True; + } + return sal_False; +} + + +ScStyleObj::ScStyleObj(ScDocShell* pDocSh, SfxStyleFamily eFam, const String& rName) : + aPropSet( (eFam == SFX_STYLE_FAMILY_PARA) ? lcl_GetCellStyleMap() : lcl_GetPageStyleMap() ), + pDocShell( pDocSh ), + eFamily( eFam ), + aStyleName( rName ) +{ + // pDocShell ist Null, wenn per ServiceProvider erzeugt + + if (pDocShell) + pDocShell->GetDocument()->AddUnoObject(*this); +} + +void ScStyleObj::InitDoc( ScDocShell* pNewDocSh, const String& rNewName ) +{ + if ( pNewDocSh && !pDocShell ) + { + aStyleName = rNewName; + pDocShell = pNewDocSh; + pDocShell->GetDocument()->AddUnoObject(*this); + } +} + +ScStyleObj::~ScStyleObj() +{ + if (pDocShell) + pDocShell->GetDocument()->RemoveUnoObject(*this); +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScStyleObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScStyleObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScStyleObj* ScStyleObj::getImplementation( + const uno::Reference<uno::XInterface> xObj ) +{ + ScStyleObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScStyleObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +void ScStyleObj::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + // Referenz-Update interessiert hier nicht + + if ( rHint.ISA( SfxSimpleHint ) && + ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING ) + { + pDocShell = NULL; // ungueltig geworden + } +} + +SfxStyleSheetBase* ScStyleObj::GetStyle_Impl() +{ + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool(); + return pStylePool->Find( aStyleName, eFamily ); + } + return NULL; +} + +// style::XStyle + +sal_Bool SAL_CALL ScStyleObj::isUserDefined() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + return pStyle->IsUserDefined(); + return sal_False; +} + +sal_Bool SAL_CALL ScStyleObj::isInUse() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + return pStyle->IsUsed(); + return sal_False; +} + +::rtl::OUString SAL_CALL ScStyleObj::getParentStyle() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + return ScStyleNameConversion::DisplayToProgrammaticName( pStyle->GetParent(), eFamily ); + return ::rtl::OUString(); +} + +void SAL_CALL ScStyleObj::setParentStyle( const ::rtl::OUString& rParentStyle ) + throw(container::NoSuchElementException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + { + // #70909# cell styles cannot be modified if any sheet is protected + if ( eFamily == SFX_STYLE_FAMILY_PARA && lcl_AnyTabProtected( *pDocShell->GetDocument() ) ) + return; //! exception? + + //! DocFunc-Funktion?? + //! Undo ????????????? + + String aString = ScStyleNameConversion::ProgrammaticToDisplayName( rParentStyle, eFamily ); + sal_Bool bOk = pStyle->SetParent( aString ); + if (bOk) + { + // wie bei setPropertyValue + + ScDocument* pDoc = pDocShell->GetDocument(); + if ( eFamily == SFX_STYLE_FAMILY_PARA ) + { + // Zeilenhoehen anpassen... + + VirtualDevice aVDev; + Point aLogic = aVDev.LogicToPixel( Point(1000,1000), MAP_TWIP ); + double nPPTX = aLogic.X() / 1000.0; + double nPPTY = aLogic.Y() / 1000.0; + Fraction aZoom(1,1); + pDoc->StyleSheetChanged( pStyle, sal_False, &aVDev, nPPTX, nPPTY, aZoom, aZoom ); + + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_LEFT ); + pDocShell->SetDocumentModified(); + } + else + { + //! ModifyStyleSheet am Dokument (alte Werte merken) + + pDocShell->PageStyleModified( aStyleName, sal_True ); + } + } + } +} + +// container::XNamed + +::rtl::OUString SAL_CALL ScStyleObj::getName() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + return ScStyleNameConversion::DisplayToProgrammaticName( pStyle->GetName(), eFamily ); + return ::rtl::OUString(); +} + +void SAL_CALL ScStyleObj::setName( const ::rtl::OUString& aNewName ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + { + // #71225# cell styles cannot be renamed if any sheet is protected + if ( eFamily == SFX_STYLE_FAMILY_PARA && lcl_AnyTabProtected( *pDocShell->GetDocument() ) ) + return; //! exception? + + //! DocFunc-Funktion?? + //! Undo ????????????? + + String aString = aNewName; + sal_Bool bOk = pStyle->SetName( aString ); + if (bOk) + { + aStyleName = aString; //! notify other objects for this style? + } + } +} + +// static +uno::Reference<container::XIndexReplace> ScStyleObj::CreateEmptyNumberingRules() +{ + SvxNumRule aRule( 0, 0, TRUE ); // nothing supported + return SvxCreateNumRule( &aRule ); +} + +// beans::XPropertyState + +const SfxItemSet* ScStyleObj::GetStyleItemSet_Impl( const String& rPropName, + const SfxItemPropertyMap*& rpResultEntry ) +{ + //! OUString as argument? + + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + { + const SfxItemPropertyMap* pMap = NULL; + if ( eFamily == SFX_STYLE_FAMILY_PAGE ) + { + pMap = SfxItemPropertyMap::GetByName( lcl_GetHeaderStyleMap(), rPropName ); + if ( pMap ) // only item-wids in header/footer map + { + rpResultEntry = pMap; + return &((const SvxSetItem&)pStyle->GetItemSet().Get(ATTR_PAGE_HEADERSET)).GetItemSet(); + } + pMap = SfxItemPropertyMap::GetByName( lcl_GetFooterStyleMap(), rPropName ); + if ( pMap ) // only item-wids in header/footer map + { + rpResultEntry = pMap; + return &((const SvxSetItem&)pStyle->GetItemSet().Get(ATTR_PAGE_FOOTERSET)).GetItemSet(); + } + } + pMap = SfxItemPropertyMap::GetByName( aPropSet.getPropertyMap(), rPropName ); + if ( pMap && IsScItemWid( pMap->nWID ) ) + { + rpResultEntry = pMap; + return &pStyle->GetItemSet(); + } + } + + rpResultEntry = NULL; + return NULL; +} + +beans::PropertyState SAL_CALL ScStyleObj::getPropertyState( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + beans::PropertyState eRet = beans::PropertyState_DIRECT_VALUE; + String aString = aPropertyName; + + const SfxItemPropertyMap* pResultEntry = NULL; + const SfxItemSet* pItemSet = GetStyleItemSet_Impl( aString, pResultEntry ); + + if ( pItemSet && pResultEntry ) + { + USHORT nWhich = pResultEntry->nWID; + SfxItemState eState = pItemSet->GetItemState( nWhich, sal_False ); + + // if no rotate value is set, look at orientation + //! also for a fixed value of 0 (in case orientation is ambiguous)? + if ( nWhich == ATTR_ROTATE_VALUE && eState == SFX_ITEM_DEFAULT ) + eState = pItemSet->GetItemState( ATTR_ORIENTATION, sal_False ); + + if ( eState == SFX_ITEM_SET ) + eRet = beans::PropertyState_DIRECT_VALUE; + else if ( eState == SFX_ITEM_DEFAULT ) + eRet = beans::PropertyState_DEFAULT_VALUE; + else if ( eState == SFX_ITEM_DONTCARE ) + eRet = beans::PropertyState_AMBIGUOUS_VALUE; // kann eigentlich nicht sein... + else + OSL_FAIL("unbekannter ItemState"); + } + return eRet; +} + +uno::Sequence<beans::PropertyState> SAL_CALL ScStyleObj::getPropertyStates( + const uno::Sequence< ::rtl::OUString>& aPropertyNames ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + // duemmliche Default-Implementierung: alles einzeln per getPropertyState holen + //! sollte optimiert werden! + + SolarMutexGuard aGuard; + const ::rtl::OUString* pNames = aPropertyNames.getConstArray(); + uno::Sequence<beans::PropertyState> aRet(aPropertyNames.getLength()); + beans::PropertyState* pStates = aRet.getArray(); + for(sal_Int32 i = 0; i < aPropertyNames.getLength(); i++) + pStates[i] = getPropertyState(pNames[i]); + return aRet; +} + +void SAL_CALL ScStyleObj::setPropertyToDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + const SfxItemPropertyMap* pMap = aPropSet.getPropertyMap(); + pMap = SfxItemPropertyMap::GetByName( pMap, aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + SetOnePropertyValue( pMap, NULL ); +} + +uno::Any SAL_CALL ScStyleObj::getPropertyDefault( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + uno::Any aAny; + + const SfxItemPropertyMap* pResultEntry = NULL; + const SfxItemSet* pStyleSet = GetStyleItemSet_Impl( aString, pResultEntry ); + + if ( pStyleSet && pResultEntry ) + { + USHORT nWhich = pResultEntry->nWID; + + // Default ist Default vom ItemPool, nicht vom Standard-Style, + // damit es zu setPropertyToDefault passt + SfxItemSet aEmptySet( *pStyleSet->GetPool(), pStyleSet->GetRanges() ); + // #65253# Default-Items mit falscher Slot-ID funktionieren im SfxItemPropertySet3 nicht + //! Slot-IDs aendern... + if ( aEmptySet.GetPool()->GetSlotId(nWhich) == nWhich && + aEmptySet.GetItemState(nWhich, sal_False) == SFX_ITEM_DEFAULT ) + { + aEmptySet.Put( aEmptySet.Get( nWhich ) ); + } + const SfxItemSet* pItemSet = &aEmptySet; + + switch ( nWhich ) // fuer Item-Spezial-Behandlungen + { + case ATTR_VALUE_FORMAT: + // default has no language set + aAny <<= sal_Int32( ((const SfxUInt32Item&)pItemSet->Get(nWhich)).GetValue() ); + break; + case ATTR_INDENT: + aAny <<= sal_Int16( TwipsToHMM(((const SfxUInt16Item&) + pItemSet->Get(nWhich)).GetValue()) ); + break; + case ATTR_PAGE_SCALE: + case ATTR_PAGE_SCALETOPAGES: + case ATTR_PAGE_FIRSTPAGENO: + aAny <<= sal_Int16( ((const SfxUInt16Item&)pItemSet->Get(nWhich)).GetValue() ); + break; + case ATTR_PAGE_CHARTS: + case ATTR_PAGE_OBJECTS: + case ATTR_PAGE_DRAWINGS: + //! sal_Bool-MID fuer ScViewObjectModeItem definieren? + aAny <<= sal_Bool( ((const ScViewObjectModeItem&)pItemSet->Get(nWhich)). + GetValue() == VOBJ_MODE_SHOW ); + break; + default: + aAny = aPropSet.getPropertyValue( *pResultEntry, *pItemSet ); + } + } + return aAny; +} + +// XMultiPropertySet + +void SAL_CALL ScStyleObj::setPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, + const uno::Sequence< uno::Any >& aValues ) + throw (beans::PropertyVetoException, lang::IllegalArgumentException, + lang::WrappedTargetException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + sal_Int32 nCount = aPropertyNames.getLength(); + if ( aValues.getLength() != nCount ) + throw lang::IllegalArgumentException(); + + if ( nCount ) + { + const ::rtl::OUString* pNames = aPropertyNames.getConstArray(); + const uno::Any* pValues = aValues.getConstArray(); + + const SfxItemPropertyMap* pPropertyMap = aPropSet.getPropertyMap(); + const SfxItemPropertyMap* pMap = pPropertyMap; + for (sal_Int32 i = 0; i < nCount; i++) + { + String aNameString = pNames[i]; + pMap = SfxItemPropertyMap::GetByName( pMap, aNameString ); + SetOnePropertyValue( pMap, &pValues[i] ); + if (!pMap) + pMap = pPropertyMap; + else + pMap++; + } + } +} + +uno::Sequence<uno::Any> SAL_CALL ScStyleObj::getPropertyValues( + const uno::Sequence< ::rtl::OUString >& aPropertyNames ) + throw (uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! optimize + + sal_Int32 nCount = aPropertyNames.getLength(); + uno::Sequence<uno::Any> aSequence( nCount ); + if ( nCount ) + { + uno::Any* pValues = aSequence.getArray(); + for (sal_Int32 i=0; i<nCount; i++) + pValues[i] = getPropertyValue( aPropertyNames[i] ); + } + return aSequence; +} + +void SAL_CALL ScStyleObj::addPropertiesChangeListener( const uno::Sequence< ::rtl::OUString>& /*aPropertyNames*/, + const uno::Reference<beans::XPropertiesChangeListener>& /*xListener*/ ) + throw (uno::RuntimeException) +{ + // no bound properties +} + +void SAL_CALL ScStyleObj::removePropertiesChangeListener( + const uno::Reference<beans::XPropertiesChangeListener>& /*xListener*/ ) + throw (uno::RuntimeException) +{ + // no bound properties +} + +void SAL_CALL ScStyleObj::firePropertiesChangeEvent( const uno::Sequence< ::rtl::OUString>& /*aPropertyNames*/, + const uno::Reference<beans::XPropertiesChangeListener>& /*xListener*/ ) + throw (uno::RuntimeException) +{ + // no bound properties +} + +// XMultiPropertyStates +// getPropertyStates already defined for XPropertyState + +void SAL_CALL ScStyleObj::setAllPropertiesToDefault() throw (uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if ( pStyle ) + { + // #70909# cell styles cannot be modified if any sheet is protected + if ( eFamily == SFX_STYLE_FAMILY_PARA && lcl_AnyTabProtected( *pDocShell->GetDocument() ) ) + throw uno::RuntimeException(); + + SfxItemSet& rSet = pStyle->GetItemSet(); + rSet.ClearItem(); // set all items to default + + //! merge with SetOneProperty + + ScDocument* pDoc = pDocShell->GetDocument(); + if ( eFamily == SFX_STYLE_FAMILY_PARA ) + { + // row heights + + VirtualDevice aVDev; + Point aLogic = aVDev.LogicToPixel( Point(1000,1000), MAP_TWIP ); + double nPPTX = aLogic.X() / 1000.0; + double nPPTY = aLogic.Y() / 1000.0; + Fraction aZoom(1,1); + pDoc->StyleSheetChanged( pStyle, sal_False, &aVDev, nPPTX, nPPTY, aZoom, aZoom ); + + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_LEFT ); + pDocShell->SetDocumentModified(); + } + else + { + pDocShell->PageStyleModified( aStyleName, sal_True ); + } + } +} + +void SAL_CALL ScStyleObj::setPropertiesToDefault( const uno::Sequence< ::rtl::OUString>& aPropertyNames ) + throw (beans::UnknownPropertyException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + sal_Int32 nCount = aPropertyNames.getLength(); + if ( nCount ) + { + const ::rtl::OUString* pNames = aPropertyNames.getConstArray(); + + const SfxItemPropertyMap* pPropertyMap = aPropSet.getPropertyMap(); + const SfxItemPropertyMap* pMap = pPropertyMap; + for (sal_Int32 i = 0; i < nCount; i++) + { + String aNameString = pNames[i]; + pMap = SfxItemPropertyMap::GetByName( pMap, aNameString ); + SetOnePropertyValue( pMap, NULL ); + if (!pMap) + pMap = pPropertyMap; + else + pMap++; + } + } +} + +uno::Sequence<uno::Any> SAL_CALL ScStyleObj::getPropertyDefaults( + const uno::Sequence< ::rtl::OUString>& aPropertyNames ) + throw (beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! optimize + + sal_Int32 nCount = aPropertyNames.getLength(); + uno::Sequence<uno::Any> aSequence( nCount ); + if ( nCount ) + { + uno::Any* pValues = aSequence.getArray(); + for (sal_Int32 i=0; i<nCount; i++) + pValues[i] = getPropertyDefault( aPropertyNames[i] ); + } + return aSequence; +} + +// beans::XPropertySet + +uno::Reference<beans::XPropertySetInfo> SAL_CALL ScStyleObj::getPropertySetInfo() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return aPropSet.getPropertySetInfo(); +} + +void SAL_CALL ScStyleObj::setPropertyValue( + const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw(beans::UnknownPropertyException, beans::PropertyVetoException, + lang::IllegalArgumentException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + const SfxItemPropertyMap* pMap = aPropSet.getPropertyMap(); + pMap = SfxItemPropertyMap::GetByName( pMap, aPropertyName ); + if ( !pMap ) + throw beans::UnknownPropertyException(); + + SetOnePropertyValue( pMap, &aValue ); +} + +void ScStyleObj::SetOnePropertyValue( const SfxItemPropertyMap* pMap, const uno::Any* pValue ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if ( pStyle && pMap ) + { + // #70909# cell styles cannot be modified if any sheet is protected + if ( eFamily == SFX_STYLE_FAMILY_PARA && lcl_AnyTabProtected( *pDocShell->GetDocument() ) ) + throw uno::RuntimeException(); + + String aString = String::CreateFromAscii( pMap->pName ); + + SfxItemSet& rSet = pStyle->GetItemSet(); // direkt im lebenden Style aendern... + sal_Bool bDone = sal_False; + if ( eFamily == SFX_STYLE_FAMILY_PAGE ) + { + const SfxItemPropertyMap* pHeaderMap = + SfxItemPropertyMap::GetByName( lcl_GetHeaderStyleMap(), aString ); + if ( pHeaderMap ) // only item-wids in header/footer map + { + SvxSetItem aNewHeader( (const SvxSetItem&)rSet.Get(ATTR_PAGE_HEADERSET) ); + if (pValue) + aPropSet.setPropertyValue( *pHeaderMap, *pValue, aNewHeader.GetItemSet() ); + else + aNewHeader.GetItemSet().ClearItem( pHeaderMap->nWID ); + rSet.Put( aNewHeader ); + bDone = sal_True; + } + else + { + const SfxItemPropertyMap* pFooterMap = + SfxItemPropertyMap::GetByName( lcl_GetFooterStyleMap(), aString ); + if ( pFooterMap ) // only item-wids in header/footer map + { + SvxSetItem aNewFooter( (const SvxSetItem&)rSet.Get(ATTR_PAGE_FOOTERSET) ); + if (pValue) + aPropSet.setPropertyValue( *pFooterMap, *pValue, aNewFooter.GetItemSet() ); + else + aNewFooter.GetItemSet().ClearItem( pFooterMap->nWID ); + rSet.Put( aNewFooter ); + bDone = sal_True; + } + } + } + if (!bDone) + { + const SfxItemPropertyMap* pLclMap = + SfxItemPropertyMap::GetByName( aPropSet.getPropertyMap(), aString ); + if ( pLclMap && IsScItemWid( pLclMap->nWID ) ) + { + if (pValue) + { + switch ( pLclMap->nWID ) // fuer Item-Spezial-Behandlungen + { + case ATTR_VALUE_FORMAT: + { + // #67847# language for number formats + SvNumberFormatter* pFormatter = + pDocShell->GetDocument()->GetFormatTable(); + UINT32 nOldFormat = ((const SfxUInt32Item&) + rSet.Get( ATTR_VALUE_FORMAT )).GetValue(); + LanguageType eOldLang = ((const SvxLanguageItem&) + rSet.Get( ATTR_LANGUAGE_FORMAT )).GetLanguage(); + nOldFormat = pFormatter-> + GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang ); + + UINT32 nNewFormat(0); + *pValue >>= nNewFormat; + rSet.Put( SfxUInt32Item( ATTR_VALUE_FORMAT, nNewFormat ) ); + + const SvNumberformat* pNewEntry = pFormatter->GetEntry( nNewFormat ); + LanguageType eNewLang = + pNewEntry ? pNewEntry->GetLanguage() : LANGUAGE_DONTKNOW; + if ( eNewLang != eOldLang && eNewLang != LANGUAGE_DONTKNOW ) + rSet.Put( SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) ); + + //! keep default state of number format if only language changed? + } + break; + case ATTR_INDENT: + { + sal_Int16 nVal(0); + *pValue >>= nVal; + rSet.Put( SfxUInt16Item( pLclMap->nWID, (USHORT)HMMToTwips(nVal) ) ); + } + break; + case ATTR_ROTATE_VALUE: + { + sal_Int32 nRotVal = 0; + if ( *pValue >>= nRotVal ) + { + // stored value is always between 0 and 360 deg. + nRotVal %= 36000; + if ( nRotVal < 0 ) + nRotVal += 36000; + + // always set rotation value and orientation + + SvxCellOrientation eOrient = SVX_ORIENTATION_STANDARD; + BOOL bSetOrient = TRUE; + + if ( nRotVal == 9000 ) + eOrient = SVX_ORIENTATION_BOTTOMTOP; + else if ( nRotVal == 27000 ) + eOrient = SVX_ORIENTATION_TOPBOTTOM; + else if ( nRotVal == 0 ) + { + // don't overwrite stacked orientation by setting + // rotation to 0 + + SvxCellOrientation eOld = (SvxCellOrientation) + ((const SvxOrientationItem&)rSet.Get(ATTR_ORIENTATION)). + GetValue(); + if ( eOld == SVX_ORIENTATION_STACKED ) + bSetOrient = FALSE; + } + + rSet.Put( SfxInt32Item( ATTR_ROTATE_VALUE, nRotVal ) ); + if (bSetOrient) + rSet.Put( SvxOrientationItem( eOrient, ATTR_ORIENTATION ) ); + } + } + break; + case ATTR_PAGE_SCALE: + case ATTR_PAGE_SCALETOPAGES: + case ATTR_PAGE_FIRSTPAGENO: + { + sal_Int16 nVal(0); + *pValue >>= nVal; + rSet.Put( SfxUInt16Item( pLclMap->nWID, nVal ) ); + } + break; + case ATTR_PAGE_CHARTS: + case ATTR_PAGE_OBJECTS: + case ATTR_PAGE_DRAWINGS: + { + sal_Bool bBool(sal_False); + *pValue >>= bBool; + //! sal_Bool-MID fuer ScViewObjectModeItem definieren? + rSet.Put( ScViewObjectModeItem( pLclMap->nWID, + bBool ? VOBJ_MODE_SHOW : VOBJ_MODE_HIDE ) ); + } + break; + case ATTR_PAGE_PAPERBIN: + { + BYTE nTray = PAPERBIN_PRINTER_SETTINGS; + BOOL bFound = FALSE; + + ::rtl::OUString aName; + if ( *pValue >>= aName ) + { + if ( aName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( SC_PAPERBIN_DEFAULTNAME ) ) ) + bFound = TRUE; + else + { + Printer* pPrinter = pDocShell->GetPrinter(); + if (pPrinter) + { + rtl::OUString aNameStr = aName; + USHORT nCount = pPrinter->GetPaperBinCount(); + for (USHORT i=0; i<nCount; i++) + if ( aNameStr == pPrinter->GetPaperBinName(i) ) + { + nTray = (BYTE) i; + bFound = TRUE; + break; + } + } + } + } + if ( bFound ) + rSet.Put( SvxPaperBinItem( ATTR_PAGE_PAPERBIN, nTray ) ); + else + throw lang::IllegalArgumentException(); + } + break; + default: + // #65253# Default-Items mit falscher Slot-ID + // funktionieren im SfxItemPropertySet3 nicht + //! Slot-IDs aendern... + if ( rSet.GetPool()->GetSlotId(pLclMap->nWID) == pLclMap->nWID && + rSet.GetItemState(pLclMap->nWID, sal_False) == SFX_ITEM_DEFAULT ) + { + rSet.Put( rSet.Get(pLclMap->nWID) ); + } + aPropSet.setPropertyValue( *pLclMap, *pValue, rSet ); + } + } + else + { + rSet.ClearItem( pLclMap->nWID ); + // #67847# language for number formats + if ( pLclMap->nWID == ATTR_VALUE_FORMAT ) + rSet.ClearItem( ATTR_LANGUAGE_FORMAT ); + + //! for ATTR_ROTATE_VALUE, also reset ATTR_ORIENTATION? + } + } + } + + //! DocFunc-Funktion?? + //! Undo ????????????? + + ScDocument* pDoc = pDocShell->GetDocument(); + if ( eFamily == SFX_STYLE_FAMILY_PARA ) + { + // Zeilenhoehen anpassen... + + VirtualDevice aVDev; + Point aLogic = aVDev.LogicToPixel( Point(1000,1000), MAP_TWIP ); + double nPPTX = aLogic.X() / 1000.0; + double nPPTY = aLogic.Y() / 1000.0; + Fraction aZoom(1,1); + pDoc->StyleSheetChanged( pStyle, sal_False, &aVDev, nPPTX, nPPTY, aZoom, aZoom ); + + pDocShell->PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID|PAINT_LEFT ); + pDocShell->SetDocumentModified(); + } + else + { + //! ModifyStyleSheet am Dokument (alte Werte merken) + + pDocShell->PageStyleModified( aStyleName, sal_True ); + } + } +} + +uno::Any SAL_CALL ScStyleObj::getPropertyValue( const ::rtl::OUString& aPropertyName ) + throw(beans::UnknownPropertyException, lang::WrappedTargetException, + uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aPropertyName; + uno::Any aAny; + + const SfxItemPropertyMap* pResultEntry = NULL; + const SfxItemSet* pItemSet = GetStyleItemSet_Impl( aString, pResultEntry ); + + if ( pItemSet && pResultEntry ) + { + USHORT nWhich = pResultEntry->nWID; + + switch ( nWhich ) // fuer Item-Spezial-Behandlungen + { + case ATTR_VALUE_FORMAT: + if ( pDocShell ) + { + UINT32 nOldFormat = ((const SfxUInt32Item&) + pItemSet->Get( ATTR_VALUE_FORMAT )).GetValue(); + LanguageType eOldLang = ((const SvxLanguageItem&) + pItemSet->Get( ATTR_LANGUAGE_FORMAT )).GetLanguage(); + nOldFormat = pDocShell->GetDocument()->GetFormatTable()-> + GetFormatForLanguageIfBuiltIn( nOldFormat, eOldLang ); + aAny <<= nOldFormat; + } + break; + case ATTR_INDENT: + aAny <<= sal_Int16( TwipsToHMM(((const SfxUInt16Item&) + pItemSet->Get(nWhich)).GetValue()) ); + break; + case ATTR_ROTATE_VALUE: + { + // if value is 0 and orientation topbottom or bottomtop, + // adjust value + + sal_Int32 nRotVal = ((const SfxInt32Item&) + pItemSet->Get(ATTR_ROTATE_VALUE)).GetValue(); + if ( nRotVal == 0 ) + { + SvxCellOrientation eOrient = (SvxCellOrientation) + ((const SvxOrientationItem&)pItemSet->Get(ATTR_ORIENTATION)). + GetValue(); + if ( eOrient == SVX_ORIENTATION_BOTTOMTOP ) + nRotVal = 9000; + else if ( eOrient == SVX_ORIENTATION_TOPBOTTOM ) + nRotVal = 27000; + } + aAny <<= nRotVal; + } + break; + case ATTR_PAGE_SCALE: + case ATTR_PAGE_SCALETOPAGES: + case ATTR_PAGE_FIRSTPAGENO: + aAny <<= sal_Int16( ((const SfxUInt16Item&)pItemSet->Get(nWhich)).GetValue() ); + break; + case ATTR_PAGE_CHARTS: + case ATTR_PAGE_OBJECTS: + case ATTR_PAGE_DRAWINGS: + //! sal_Bool-MID fuer ScViewObjectModeItem definieren? + aAny <<= sal_Bool( ((const ScViewObjectModeItem&)pItemSet-> + Get(nWhich)).GetValue() == VOBJ_MODE_SHOW ); + break; + case ATTR_PAGE_PAPERBIN: + { + // property PrinterPaperTray is the name of the tray + + BYTE nValue = ((const SvxPaperBinItem&)pItemSet->Get(nWhich)).GetValue(); + ::rtl::OUString aName; + if ( nValue == PAPERBIN_PRINTER_SETTINGS ) + aName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SC_PAPERBIN_DEFAULTNAME )); + else + { + Printer* pPrinter = pDocShell->GetPrinter(); + if (pPrinter) + aName = pPrinter->GetPaperBinName( nValue ); + } + aAny <<= aName; + } + break; + default: + // #65253# Default-Items mit falscher Slot-ID + // funktionieren im SfxItemPropertySet3 nicht + //! Slot-IDs aendern... + if ( pItemSet->GetPool()->GetSlotId(nWhich) == nWhich && + pItemSet->GetItemState(nWhich, sal_False) == SFX_ITEM_DEFAULT ) + { + SfxItemSet aNoEmptySet( *pItemSet ); + aNoEmptySet.Put( aNoEmptySet.Get( nWhich ) ); + aAny = aPropSet.getPropertyValue( *pResultEntry, aNoEmptySet ); + } + else + aAny = aPropSet.getPropertyValue( *pResultEntry, *pItemSet ); + } + } + else if ( aString.EqualsAscii( SC_UNONAME_DISPNAME ) ) // read-only + { + // core always has the display name + SfxStyleSheetBase* pStyle = GetStyle_Impl(); + if (pStyle) + aAny <<= ::rtl::OUString( pStyle->GetName() ); + } + + return aAny; +} + +SC_IMPL_DUMMY_PROPERTY_LISTENER( ScStyleObj ) + +// lang::XServiceInfo + +::rtl::OUString SAL_CALL ScStyleObj::getImplementationName() throw(uno::RuntimeException) +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScStyleObj" )); +} + +sal_Bool SAL_CALL ScStyleObj::supportsService( const ::rtl::OUString& rServiceName ) + throw(uno::RuntimeException) +{ + BOOL bPage = ( eFamily == SFX_STYLE_FAMILY_PAGE ); + String aServiceStr( rServiceName ); + return aServiceStr.EqualsAscii( SCSTYLE_SERVICE ) || + aServiceStr.EqualsAscii( bPage ? SCPAGESTYLE_SERVICE + : SCCELLSTYLE_SERVICE ); +} + +uno::Sequence< ::rtl::OUString> SAL_CALL ScStyleObj::getSupportedServiceNames() + throw(uno::RuntimeException) +{ + BOOL bPage = ( eFamily == SFX_STYLE_FAMILY_PAGE ); + uno::Sequence< ::rtl::OUString> aRet(2); + ::rtl::OUString* pArray = aRet.getArray(); + pArray[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCSTYLE_SERVICE )); + pArray[1] = bPage ? ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCPAGESTYLE_SERVICE )) + : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( SCCELLSTYLE_SERVICE )); + return aRet; +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_textuno.cxx b/bf_sc/source/ui/unoobj/sc_textuno.cxx new file mode 100644 index 000000000..945fd7853 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_textuno.cxx @@ -0,0 +1,1135 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifdef _MSC_VER +#pragma hdrstop +#endif + +#include "scitems.hxx" +#define ITEMID_FIELD EE_FEATURE_FIELD + +#include <bf_svx/editobj.hxx> + + + +#include <bf_svx/itemdata.hxx> + +#include <tools/date.hxx> + +#include <tools/time.hxx> + +#include <bf_svx/flditem.hxx> +#include <bf_svx/unofored.hxx> +#include <rtl/uuid.h> +#include <vcl/virdev.hxx> + +#define _SVSTDARR_USHORTS +#include <bf_svtools/svstdarr.hxx> + + +#include "textuno.hxx" +#include "fielduno.hxx" +#include "servuno.hxx" +#include "editsrc.hxx" +#include "docsh.hxx" +#include "editutil.hxx" +#include <vcl/svapp.hxx> +#include "miscuno.hxx" +#include "cellsuno.hxx" +#include "hints.hxx" +#include "patattr.hxx" +#include "cell.hxx" +#include "docfunc.hxx" +#include "scmod.hxx" +namespace binfilter { + +using namespace ::com::sun::star; + +//------------------------------------------------------------------------ + +const SfxItemPropertyMap* lcl_GetHdFtPropertyMap() +{ + static SfxItemPropertyMap aHdFtPropertyMap_Impl[] = + { + SVX_UNOEDIT_CHAR_PROPERTIES, + SVX_UNOEDIT_FONT_PROPERTIES, + SVX_UNOEDIT_PARA_PROPERTIES, + SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties + {0,0,0,0,0,0} + }; + static BOOL bTwipsSet = FALSE; + + if (!bTwipsSet) + { + // modify PropertyMap to include CONVERT_TWIPS flag for font height + // (headers/footers are in twips) + + SfxItemPropertyMap* pEntry = aHdFtPropertyMap_Impl; + while (pEntry->pName) + { + if ( ( pEntry->nWID == EE_CHAR_FONTHEIGHT || + pEntry->nWID == EE_CHAR_FONTHEIGHT_CJK || + pEntry->nWID == EE_CHAR_FONTHEIGHT_CTL ) && + pEntry->nMemberId == MID_FONTHEIGHT ) + { + pEntry->nMemberId |= CONVERT_TWIPS; + } + + ++pEntry; + } + bTwipsSet = TRUE; + } + + return aHdFtPropertyMap_Impl; +} + +//------------------------------------------------------------------------ + +SC_SIMPLE_SERVICE_INFO( ScHeaderFooterContentObj, "ScHeaderFooterContentObj", "com.sun.star.sheet.HeaderFooterContent" ) +SC_SIMPLE_SERVICE_INFO( ScHeaderFooterTextObj, "ScHeaderFooterTextObj", "stardiv.one.Text.Text" ) + +//------------------------------------------------------------------------ + +ScHeaderFooterContentObj::ScHeaderFooterContentObj( const EditTextObject* pLeft, + const EditTextObject* pCenter, + const EditTextObject* pRight ) : + pLeftText ( NULL ), + pCenterText ( NULL ), + pRightText ( NULL ) +{ + if ( pLeft ) + pLeftText = pLeft->Clone(); + if ( pCenter ) + pCenterText = pCenter->Clone(); + if ( pRight ) + pRightText = pRight->Clone(); +} + +ScHeaderFooterContentObj::~ScHeaderFooterContentObj() +{ + delete pLeftText; + delete pCenterText; + delete pRightText; +} + +void ScHeaderFooterContentObj::AddListener( SfxListener& rListener ) +{ + rListener.StartListening( aBC ); +} + +void ScHeaderFooterContentObj::RemoveListener( SfxListener& rListener ) +{ + rListener.EndListening( aBC ); +} + +void ScHeaderFooterContentObj::UpdateText( USHORT nPart, EditEngine& rSource ) +{ + EditTextObject* pNew = rSource.CreateTextObject(); + switch (nPart) + { + case SC_HDFT_LEFT: + delete pLeftText; + pLeftText = pNew; + break; + case SC_HDFT_CENTER: + delete pCenterText; + pCenterText = pNew; + break; + default: // SC_HDFT_RIGHT + delete pRightText; + pRightText = pNew; + break; + } + + aBC.Broadcast( ScHeaderFooterChangedHint( nPart ) ); +} + +// XHeaderFooterContent + +uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getLeftText() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScHeaderFooterTextObj( *this, SC_HDFT_LEFT ); +} + +uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getCenterText() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScHeaderFooterTextObj( *this, SC_HDFT_CENTER ); +} + +uno::Reference<text::XText> SAL_CALL ScHeaderFooterContentObj::getRightText() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScHeaderFooterTextObj( *this, SC_HDFT_RIGHT ); +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScHeaderFooterContentObj::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return 0; +} + +// static +const uno::Sequence<sal_Int8>& ScHeaderFooterContentObj::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScHeaderFooterContentObj* ScHeaderFooterContentObj::getImplementation( + const uno::Reference<sheet::XHeaderFooterContent> xObj ) +{ + ScHeaderFooterContentObj* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScHeaderFooterContentObj*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + + +//------------------------------------------------------------------------ + +ScHeaderFooterTextData::ScHeaderFooterTextData( ScHeaderFooterContentObj& rContent, + USHORT nP ) : + rContentObj( rContent ), + nPart( nP ), + pEditEngine( NULL ), + pForwarder( NULL ), + bDataValid( FALSE ), + bInUpdate( FALSE ) +{ + rContentObj.acquire(); // must not go away + rContentObj.AddListener( *this ); +} + +ScHeaderFooterTextData::~ScHeaderFooterTextData() +{ + SolarMutexGuard aGuard; // needed for EditEngine dtor + + rContentObj.RemoveListener( *this ); + + delete pForwarder; + delete pEditEngine; + + rContentObj.release(); +} + +void ScHeaderFooterTextData::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScHeaderFooterChangedHint ) ) + { + if ( ((const ScHeaderFooterChangedHint&)rHint).GetPart() == nPart ) + { + if (!bInUpdate) // not for own updates + bDataValid = FALSE; // text has to be fetched again + } + } +} + +SvxTextForwarder* ScHeaderFooterTextData::GetTextForwarder() +{ + if (!pEditEngine) + { + SfxItemPool* pEnginePool = EditEngine::CreatePool(); + pEnginePool->FreezeIdRanges(); + ScHeaderEditEngine* pHdrEngine = new ScHeaderEditEngine( pEnginePool, TRUE ); + + pHdrEngine->EnableUndo( FALSE ); + pHdrEngine->SetRefMapMode( MAP_TWIP ); + + // default font must be set, independently of document + // -> use global pool from module + + SfxItemSet aDefaults( pHdrEngine->GetEmptyItemSet() ); + const ScPatternAttr& rPattern = (const ScPatternAttr&)SC_MOD()->GetPool().GetDefaultItem(ATTR_PATTERN); + rPattern.FillEditItemSet( &aDefaults ); + // FillEditItemSet adjusts font height to 1/100th mm, + // but for header/footer twips is needed, as in the PatternAttr: + aDefaults.Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT ); + aDefaults.Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK ); + aDefaults.Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL ); + pHdrEngine->SetDefaults( aDefaults ); + + ScHeaderFieldData aData; + ScHeaderFooterTextObj::FillDummyFieldData( aData ); + pHdrEngine->SetData( aData ); + + pEditEngine = pHdrEngine; + pForwarder = new SvxEditEngineForwarder(*pEditEngine); + } + + if (bDataValid) + return pForwarder; + + const EditTextObject* pData; + if (nPart == SC_HDFT_LEFT) + pData = rContentObj.GetLeftEditObject(); + else if (nPart == SC_HDFT_CENTER) + pData = rContentObj.GetCenterEditObject(); + else + pData = rContentObj.GetRightEditObject(); + + if (pData) + { + pEditEngine->SetText(*pData); + + // #i75599# If there's an invalid field ID in a binary file, the result is + // a SvxFieldItem with NULL as SvxFieldData. These have to be removed here. + + USHORT nParCount = pEditEngine->GetParagraphCount(); + for (USHORT nPar=0; nPar<nParCount; nPar++) + { + SvUShorts aPortions; + pEditEngine->GetPortions( nPar, aPortions ); + + for ( USHORT nPos = aPortions.Count(); nPos; ) + { + --nPos; + USHORT nEnd = aPortions.GetObject( nPos ); + USHORT nStart = nPos ? aPortions.GetObject( nPos - 1 ) : 0; + // fields are single characters + if ( nEnd == nStart+1 ) + { + ESelection aFieldSel( nPar, nStart, nPar, nEnd ); + SfxItemSet aSet = pEditEngine->GetAttribs( aFieldSel ); + const SfxPoolItem* pItem = NULL; + if ( aSet.GetItemState( EE_FEATURE_FIELD, FALSE, &pItem ) == SFX_ITEM_ON ) + { + const SvxFieldItem* pFieldItem = static_cast<const SvxFieldItem*>(pItem); + const SvxFieldData* pLclData = pFieldItem->GetField(); + if ( !pLclData ) + { + // remove the invalid field + pEditEngine->QuickDelete( aFieldSel ); + } + } + } + } + } + } + + bDataValid = TRUE; + return pForwarder; +} + +void ScHeaderFooterTextData::UpdateData() +{ + if ( pEditEngine ) + { + bInUpdate = TRUE; // don't reset bDataValid during UpdateText + + rContentObj.UpdateText( nPart, *pEditEngine ); + + bInUpdate = FALSE; + } +} + +//------------------------------------------------------------------------ + +ScHeaderFooterTextObj::ScHeaderFooterTextObj( ScHeaderFooterContentObj& rContent, + USHORT nP ) : + aTextData( rContent, nP ), + pUnoText( NULL ) +{ + // ScHeaderFooterTextData acquires rContent + // pUnoText is created on demand (getString/setString work without it) +} + +void ScHeaderFooterTextObj::CreateUnoText_Impl() +{ + if ( !pUnoText ) + { + // can't be aggregated because getString/setString is handled here + ScSharedHeaderFooterEditSource aEditSource( &aTextData ); + pUnoText = new SvxUnoText( &aEditSource, lcl_GetHdFtPropertyMap(), uno::Reference<text::XText>() ); + pUnoText->acquire(); + } +} + +ScHeaderFooterTextObj::~ScHeaderFooterTextObj() +{ + if (pUnoText) + pUnoText->release(); +} + +const SvxUnoText& ScHeaderFooterTextObj::GetUnoText() +{ + if (!pUnoText) + CreateUnoText_Impl(); + return *pUnoText; +} + +// XText + +uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursor() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return new ScHeaderFooterTextCursor( *this ); +} + +uno::Reference<text::XTextCursor> SAL_CALL ScHeaderFooterTextObj::createTextCursorByRange( + const uno::Reference<text::XTextRange>& aTextPosition ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + return pUnoText->createTextCursorByRange(aTextPosition); + //! wie ScCellObj::createTextCursorByRange, wenn SvxUnoTextRange_getReflection verfuegbar +} + +void ScHeaderFooterTextObj::FillDummyFieldData( ScHeaderFieldData& rData ) // static +{ + String aDummy = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( "???" )); + rData.aTitle = aDummy; + rData.aLongDocName = aDummy; + rData.aShortDocName = aDummy; + rData.aTabName = aDummy; + rData.nPageNo = 1; + rData.nTotalPages = 99; +} + +::rtl::OUString SAL_CALL ScHeaderFooterTextObj::getString() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + ::rtl::OUString aRet; + const EditTextObject* pData; + + USHORT nPart = aTextData.GetPart(); + ScHeaderFooterContentObj& rContentObj = aTextData.GetContentObj(); + + if (nPart == SC_HDFT_LEFT) + pData = rContentObj.GetLeftEditObject(); + else if (nPart == SC_HDFT_CENTER) + pData = rContentObj.GetCenterEditObject(); + else + pData = rContentObj.GetRightEditObject(); + if (pData) + { + // for pure text, no font info is needed in pool defaults + ScHeaderEditEngine aEditEngine( EditEngine::CreatePool(), TRUE ); + + ScHeaderFieldData aData; + FillDummyFieldData( aData ); + aEditEngine.SetData( aData ); + + aEditEngine.SetText(*pData); + aRet = ScEditUtil::GetSpaceDelimitedString( aEditEngine ); + } + return aRet; +} + +void SAL_CALL ScHeaderFooterTextObj::setString( const ::rtl::OUString& aText ) throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + String aString = aText; + + // for pure text, no font info is needed in pool defaults + ScHeaderEditEngine aEditEngine( EditEngine::CreatePool(), TRUE ); + aEditEngine.SetText( aString ); + + aTextData.GetContentObj().UpdateText( aTextData.GetPart(), aEditEngine ); +} + +void SAL_CALL ScHeaderFooterTextObj::insertString( const uno::Reference<text::XTextRange>& xRange, + const ::rtl::OUString& aString, sal_Bool bAbsorb ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + pUnoText->insertString( xRange, aString, bAbsorb ); +} + +void SAL_CALL ScHeaderFooterTextObj::insertControlCharacter( + const uno::Reference<text::XTextRange>& xRange, + sal_Int16 nControlCharacter, sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + pUnoText->insertControlCharacter( xRange, nControlCharacter, bAbsorb ); +} + +void SAL_CALL ScHeaderFooterTextObj::insertTextContent( + const uno::Reference<text::XTextRange >& xRange, + const uno::Reference<text::XTextContent >& xContent, + sal_Bool bAbsorb ) + throw(lang::IllegalArgumentException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( xContent.is() && xRange.is() ) + { + ScHeaderFieldObj* pHeaderField = ScHeaderFieldObj::getImplementation( xContent ); + + SvxUnoTextRangeBase* pTextRange = + ScHeaderFooterTextCursor::getImplementation( xRange ); + + if ( pHeaderField && !pHeaderField->IsInserted() && pTextRange ) + { + SvxEditSource* pEditSource = pTextRange->GetEditSource(); + ESelection aSelection = pTextRange->GetSelection(); + + if (!bAbsorb) + { + // don't replace -> append at end + aSelection.Adjust(); + aSelection.nStartPara = aSelection.nEndPara; + aSelection.nStartPos = aSelection.nEndPos; + } + + SvxFieldItem aItem = pHeaderField->CreateFieldItem(); + + SvxTextForwarder* pForwarder = pEditSource->GetTextForwarder(); + pForwarder->QuickInsertField( aItem, aSelection ); + pEditSource->UpdateData(); + + // neue Selektion: ein Zeichen + aSelection.Adjust(); + aSelection.nEndPara = aSelection.nStartPara; + aSelection.nEndPos = aSelection.nStartPos + 1; + pHeaderField->InitDoc( &aTextData.GetContentObj(), aTextData.GetPart(), aSelection ); + + // #91431# for bAbsorb=FALSE, the new selection must be behind the inserted content + // (the xml filter relies on this) + if (!bAbsorb) + aSelection.nStartPos = aSelection.nEndPos; + + pTextRange->SetSelection( aSelection ); + + return; + } + } + + if (!pUnoText) + CreateUnoText_Impl(); + pUnoText->insertTextContent( xRange, xContent, bAbsorb ); +} + +void SAL_CALL ScHeaderFooterTextObj::removeTextContent( + const uno::Reference<text::XTextContent>& xContent ) + throw(container::NoSuchElementException, uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if ( xContent.is() ) + { + ScHeaderFieldObj* pHeaderField = ScHeaderFieldObj::getImplementation( xContent ); + if ( pHeaderField && pHeaderField->IsInserted() ) + { + //! Testen, ob das Feld in dieser Zelle ist + pHeaderField->DeleteField(); + return; + } + } + if (!pUnoText) + CreateUnoText_Impl(); + pUnoText->removeTextContent( xContent ); +} + +uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextObj::getText() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + return pUnoText->getText(); +} + +uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getStart() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + return pUnoText->getStart(); +} + +uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextObj::getEnd() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + return pUnoText->getEnd(); +} + +// XTextFieldsSupplier + +uno::Reference<container::XEnumerationAccess> SAL_CALL ScHeaderFooterTextObj::getTextFields() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + // all fields + return new ScHeaderFieldsObj( &aTextData.GetContentObj(), aTextData.GetPart(), SC_SERVICE_INVALID ); +} + +uno::Reference<container::XNameAccess> SAL_CALL ScHeaderFooterTextObj::getTextFieldMasters() + throw(uno::RuntimeException) +{ + // sowas gibts nicht im Calc (?) + return NULL; +} + +// XTextRangeMover + +void SAL_CALL ScHeaderFooterTextObj::moveTextRange( + const uno::Reference<text::XTextRange>& xRange, + sal_Int16 nParagraphs ) + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + pUnoText->moveTextRange( xRange, nParagraphs ); +} + +// XEnumerationAccess + +uno::Reference<container::XEnumeration> SAL_CALL ScHeaderFooterTextObj::createEnumeration() + throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + return pUnoText->createEnumeration(); +} + +// XElementAccess + +uno::Type SAL_CALL ScHeaderFooterTextObj::getElementType() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + return pUnoText->getElementType(); +} + +sal_Bool SAL_CALL ScHeaderFooterTextObj::hasElements() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + if (!pUnoText) + CreateUnoText_Impl(); + return pUnoText->hasElements(); +} + +//------------------------------------------------------------------------ + +ScCellTextCursor::ScCellTextCursor(const ScCellTextCursor& rOther) : + SvxUnoTextCursor( rOther ), + rTextObj( rOther.rTextObj ) +{ + rTextObj.acquire(); +} + +ScCellTextCursor::ScCellTextCursor(ScCellObj& rText) : + SvxUnoTextCursor( rText.GetUnoText() ), + rTextObj( rText ) +{ + rTextObj.acquire(); +} + +ScCellTextCursor::~ScCellTextCursor() throw() +{ + rTextObj.release(); +} + +// SvxUnoTextCursor methods reimplemented here to return the right objects: + +uno::Reference<text::XText> SAL_CALL ScCellTextCursor::getText() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return &rTextObj; +} + +uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getStart() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! use other object for range than cursor? + + ScCellTextCursor* pNew = new ScCellTextCursor( *this ); + uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) ); + + ESelection aNewSel = GetSelection(); + aNewSel.nEndPara = aNewSel.nStartPara; + aNewSel.nEndPos = aNewSel.nStartPos; + pNew->SetSelection( aNewSel ); + + return xRange; +} + +uno::Reference<text::XTextRange> SAL_CALL ScCellTextCursor::getEnd() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! use other object for range than cursor? + + ScCellTextCursor* pNew = new ScCellTextCursor( *this ); + uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) ); + + ESelection aNewSel = GetSelection(); + aNewSel.nStartPara = aNewSel.nEndPara; + aNewSel.nStartPos = aNewSel.nEndPos; + pNew->SetSelection( aNewSel ); + + return xRange; +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScCellTextCursor::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return SvxUnoTextCursor::getSomething( rId ); +} + +// static +const uno::Sequence<sal_Int8>& ScCellTextCursor::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScCellTextCursor* ScCellTextCursor::getImplementation( const uno::Reference<uno::XInterface> xObj ) +{ + ScCellTextCursor* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScCellTextCursor*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +//------------------------------------------------------------------------ + +ScHeaderFooterTextCursor::ScHeaderFooterTextCursor(const ScHeaderFooterTextCursor& rOther) : + SvxUnoTextCursor( rOther ), + rTextObj( rOther.rTextObj ) +{ + rTextObj.acquire(); +} + +ScHeaderFooterTextCursor::ScHeaderFooterTextCursor(ScHeaderFooterTextObj& rText) : + SvxUnoTextCursor( rText.GetUnoText() ), + rTextObj( rText ) +{ + rTextObj.acquire(); +} + +ScHeaderFooterTextCursor::~ScHeaderFooterTextCursor() throw() +{ + rTextObj.release(); +} + +// SvxUnoTextCursor methods reimplemented here to return the right objects: + +uno::Reference<text::XText> SAL_CALL ScHeaderFooterTextCursor::getText() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return &rTextObj; +} + +uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getStart() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! use other object for range than cursor? + + ScHeaderFooterTextCursor* pNew = new ScHeaderFooterTextCursor( *this ); + uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) ); + + ESelection aNewSel = GetSelection(); + aNewSel.nEndPara = aNewSel.nStartPara; + aNewSel.nEndPos = aNewSel.nStartPos; + pNew->SetSelection( aNewSel ); + + return xRange; +} + +uno::Reference<text::XTextRange> SAL_CALL ScHeaderFooterTextCursor::getEnd() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! use other object for range than cursor? + + ScHeaderFooterTextCursor* pNew = new ScHeaderFooterTextCursor( *this ); + uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) ); + + ESelection aNewSel = GetSelection(); + aNewSel.nStartPara = aNewSel.nEndPara; + aNewSel.nStartPos = aNewSel.nEndPos; + pNew->SetSelection( aNewSel ); + + return xRange; +} + +// XUnoTunnel + +sal_Int64 SAL_CALL ScHeaderFooterTextCursor::getSomething( + const uno::Sequence<sal_Int8 >& rId ) throw(uno::RuntimeException) +{ + if ( rId.getLength() == 16 && + 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), + rId.getConstArray(), 16 ) ) + { + return (sal_Int64)this; + } + return SvxUnoTextCursor::getSomething( rId ); +} + +// static +const uno::Sequence<sal_Int8>& ScHeaderFooterTextCursor::getUnoTunnelId() +{ + static uno::Sequence<sal_Int8> * pSeq = 0; + if( !pSeq ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if( !pSeq ) + { + static uno::Sequence< sal_Int8 > aSeq( 16 ); + rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True ); + pSeq = &aSeq; + } + } + return *pSeq; +} + +// static +ScHeaderFooterTextCursor* ScHeaderFooterTextCursor::getImplementation( + const uno::Reference<uno::XInterface> xObj ) +{ + ScHeaderFooterTextCursor* pRet = NULL; + uno::Reference<lang::XUnoTunnel> xUT( xObj, uno::UNO_QUERY ); + if (xUT.is()) + pRet = (ScHeaderFooterTextCursor*) xUT->getSomething( getUnoTunnelId() ); + return pRet; +} + +//------------------------------------------------------------------------ + +ScDrawTextCursor::ScDrawTextCursor(const ScDrawTextCursor& rOther) : + SvxUnoTextCursor( rOther ), + xParentText( rOther.xParentText ) +{ +} + +ScDrawTextCursor::ScDrawTextCursor( const uno::Reference<text::XText>& xParent, + const SvxUnoTextBase& rText ) : + SvxUnoTextCursor( rText ), + xParentText( xParent ) + +{ +} + +ScDrawTextCursor::~ScDrawTextCursor() throw() +{ +} + +// SvxUnoTextCursor methods reimplemented here to return the right objects: + +uno::Reference<text::XText> SAL_CALL ScDrawTextCursor::getText() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + return xParentText; +} + +uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getStart() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! use other object for range than cursor? + + ScDrawTextCursor* pNew = new ScDrawTextCursor( *this ); + uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) ); + + ESelection aNewSel = GetSelection(); + aNewSel.nEndPara = aNewSel.nStartPara; + aNewSel.nEndPos = aNewSel.nStartPos; + pNew->SetSelection( aNewSel ); + + return xRange; +} + +uno::Reference<text::XTextRange> SAL_CALL ScDrawTextCursor::getEnd() throw(uno::RuntimeException) +{ + SolarMutexGuard aGuard; + + //! use other object for range than cursor? + + ScDrawTextCursor* pNew = new ScDrawTextCursor( *this ); + uno::Reference<text::XTextRange> xRange( static_cast<SvxUnoTextRangeBase*>(pNew) ); + + ESelection aNewSel = GetSelection(); + aNewSel.nStartPara = aNewSel.nEndPara; + aNewSel.nStartPos = aNewSel.nEndPos; + pNew->SetSelection( aNewSel ); + + return xRange; +} + +//------------------------------------------------------------------------ + +ScSimpleEditSourceHelper::ScSimpleEditSourceHelper() +{ + SfxItemPool* pEnginePool = EditEngine::CreatePool(); + pEnginePool->SetDefaultMetric( SFX_MAPUNIT_100TH_MM ); + pEnginePool->FreezeIdRanges(); + + pEditEngine = new ScFieldEditEngine( pEnginePool, NULL, TRUE ); // TRUE: become owner of pool + pForwarder = new SvxEditEngineForwarder( *pEditEngine ); + pOriginalSource = new ScSimpleEditSource( pForwarder ); +} + +ScSimpleEditSourceHelper::~ScSimpleEditSourceHelper() +{ + SolarMutexGuard aGuard; // needed for EditEngine dtor + + delete pOriginalSource; + delete pForwarder; + delete pEditEngine; +} + +ScEditEngineTextObj::ScEditEngineTextObj() : + SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertyMap(), uno::Reference<text::XText>() ) +{ +} + +ScEditEngineTextObj::~ScEditEngineTextObj() throw() +{ +} + +void ScEditEngineTextObj::SetText( const EditTextObject& rTextObject ) +{ + GetEditEngine()->SetText( rTextObject ); + + ESelection aSel; + ::binfilter::GetSelection( aSel, GetEditSource()->GetTextForwarder() ); + SetSelection( aSel ); +} + +EditTextObject* ScEditEngineTextObj::CreateTextObject() +{ + return GetEditEngine()->CreateTextObject(); +} + + +ScCellTextData::ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP) : + pDocShell( pDocSh ), + aCellPos( rP ), + pEditEngine( NULL ), + pForwarder( NULL ), + pOriginalSource( NULL ), + bDataValid( FALSE ), + bInUpdate( FALSE ), + bDirty( FALSE ), + bDoUpdate( TRUE ) +{ + if (pDocShell) + pDocShell->GetDocument()->AddUnoObject(*this); +} + +ScCellTextData::~ScCellTextData() +{ + SolarMutexGuard aGuard; // needed for EditEngine dtor + + if (pDocShell) + { + pDocShell->GetDocument()->RemoveUnoObject(*this); + pDocShell->GetDocument()->DisposeFieldEditEngine(pEditEngine); + } + else + delete pEditEngine; + + delete pForwarder; + + delete pOriginalSource; +} + +ScSharedCellEditSource* ScCellTextData::GetOriginalSource() +{ + if (!pOriginalSource) + pOriginalSource = new ScSharedCellEditSource( this ); + return pOriginalSource; +} + +void ScCellTextData::GetCellText(const ScAddress& rCellPos, String& rText) +{ + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pDoc->GetInputString( rCellPos.Col(), rCellPos.Row(), rCellPos.Tab(), rText ); + } +} + +SvxTextForwarder* ScCellTextData::GetTextForwarder() +{ + if (!pEditEngine) + { + if ( pDocShell ) + { + ScDocument* pDoc = pDocShell->GetDocument(); + pEditEngine = pDoc->CreateFieldEditEngine(); + } + else + { + SfxItemPool* pEnginePool = EditEngine::CreatePool(); + pEnginePool->FreezeIdRanges(); + pEditEngine = new ScFieldEditEngine( pEnginePool, NULL, TRUE ); + } + // currently, GetPortions doesn't work if UpdateMode is FALSE, + // this will be fixed (in EditEngine) by src600 + pEditEngine->EnableUndo( FALSE ); + if (pDocShell) + pEditEngine->SetRefDevice(pDocShell->GetVirtualDevice_100th_mm()); + else + pEditEngine->SetRefMapMode( MAP_100TH_MM ); + pForwarder = new SvxEditEngineForwarder(*pEditEngine); + } + + if (bDataValid) + return pForwarder; + + String aText; + + if (pDocShell) + { + ScDocument* pDoc = pDocShell->GetDocument(); + + SfxItemSet aDefaults( pEditEngine->GetEmptyItemSet() ); + const ScPatternAttr* pPattern = + pDoc->GetPattern( aCellPos.Col(), aCellPos.Row(), aCellPos.Tab() ); + pPattern->FillEditItemSet( &aDefaults ); + pPattern->FillEditParaItems( &aDefaults ); // including alignment etc. (for reading) + + const ScBaseCell* pCell = pDoc->GetCell( aCellPos ); + if ( pCell && pCell->GetCellType() == CELLTYPE_EDIT ) + pEditEngine->SetTextNewDefaults( *((const ScEditCell*)pCell)->GetData(), aDefaults ); + else + { + GetCellText( aCellPos, aText ); + if (aText.Len()) + pEditEngine->SetTextNewDefaults( aText, aDefaults ); + else + pEditEngine->SetDefaults(aDefaults); + } + } + + bDataValid = TRUE; + return pForwarder; +} + +void ScCellTextData::UpdateData() +{ + if ( bDoUpdate ) + { + DBG_ASSERT(pEditEngine != NULL, "no EditEngine for UpdateData()"); + if ( pDocShell && pEditEngine ) + { + // during the own UpdateData call, bDataValid must not be reset, + // or things like attributes after the text would be lost + // (are not stored in the cell) + + bInUpdate = TRUE; // prevents bDataValid from being reset + + ScDocFunc aFunc(*pDocShell); + aFunc.PutData( aCellPos, *pEditEngine, FALSE, TRUE ); // always as text + + bInUpdate = FALSE; + bDirty = FALSE; + } + } + else + bDirty = TRUE; +} + +void ScCellTextData::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) +{ + if ( rHint.ISA( ScUpdateRefHint ) ) + { + //! Ref-Update + } + else if ( rHint.ISA( SfxSimpleHint ) ) + { + ULONG nId = ((const SfxSimpleHint&)rHint).GetId(); + if ( nId == SFX_HINT_DYING ) + { + pDocShell = NULL; // invalid now + + DELETEZ( pForwarder ); + DELETEZ( pEditEngine ); // EditEngine uses document's pool + } + else if ( nId == SFX_HINT_DATACHANGED ) + { + if (!bInUpdate) // not for own UpdateData calls + bDataValid = FALSE; // text has to be read from the cell again + } + } +} + +ScCellTextObj::ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP) : + ScCellTextData( pDocSh, rP ), + SvxUnoText( GetOriginalSource(), ScCellObj::GetEditPropertyMap(), uno::Reference<text::XText>() ) +{ +} + +ScCellTextObj::~ScCellTextObj() throw() +{ +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bf_sc/source/ui/unoobj/sc_unodoc.cxx b/bf_sc/source/ui/unoobj/sc_unodoc.cxx new file mode 100644 index 000000000..48c9424a6 --- /dev/null +++ b/bf_sc/source/ui/unoobj/sc_unodoc.cxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "scmod.hxx" + +#include <osl/mutex.hxx> +#include <vcl/svapp.hxx> +namespace binfilter { + +using namespace ::com::sun::star; + +::rtl::OUString SAL_CALL ScDocument_getImplementationName() throw() +{ + return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.Calc.SpreadsheetDocument" ) ); +} + +uno::Sequence< ::rtl::OUString > SAL_CALL ScDocument_getSupportedServiceNames() throw() +{ + //useable for component registration only! + uno::Sequence< ::rtl::OUString > aSeq( 1 ); + aSeq[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocument" )); + return aSeq; +} + +uno::Reference< uno::XInterface > SAL_CALL ScDocument_createInstance( + const uno::Reference< lang::XMultiServiceFactory > & /*rSMgr*/ ) throw( uno::Exception ) +{ + SolarMutexGuard aGuard; + + // to create the service the SW_MOD should be already initialized + DBG_ASSERT( SC_MOD(), "No StarCalc module!" ); + + if ( SC_MOD() ) + { + ::rtl::OUString aFactoryURL( RTL_CONSTASCII_USTRINGPARAM ( "private:factory/scalc" ) ); + const SfxObjectFactory* pFactory = SfxObjectFactory::GetFactory( aFactoryURL ); + if ( pFactory ) + { + SfxObjectShell* pShell = pFactory->CreateObject(); + if( pShell ) + return uno::Reference< uno::XInterface >( pShell->GetModel() ); + } + } + + return uno::Reference< uno::XInterface >(); +} + + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |