diff options
Diffstat (limited to 'vbahelper')
110 files changed, 17245 insertions, 0 deletions
diff --git a/vbahelper/Library_msforms.mk b/vbahelper/Library_msforms.mk new file mode 100755 index 000000000000..58a90a7ccd42 --- /dev/null +++ b/vbahelper/Library_msforms.mk @@ -0,0 +1,95 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2011 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. +# +#************************************************************************* + +# MODULE is the name of the module the makefile is located in + +# declare a library +# LIB is the name of the library as it is found in Repository.mk +$(eval $(call gb_Library_Library,msforms)) + +# for platforms supporting PCH: declare the location of the pch file +# this is the name of the cxx file (without extension) +#$(eval $(call gb_Library_add_precompiled_header,msforms,$(SRCDIR)/vbahelper/PCH_FILE)) + +# in case UNO services are exported: declare location of component file +$(eval $(call gb_Library_set_componentfile,msforms,vbahelper/util/msforms)) + +# add any additional include paths for this library here +$(eval $(call gb_Library_set_include,msforms,\ + $$(INCLUDE) \ + -I$(OUTDIR)/inc/offuh \ +)) + +# add libraries to be linked to LIB; again these names need to be given as +# specified in Repository.mk +$(eval $(call gb_Library_add_linked_libs,msforms,\ + comphelper \ + cppu \ + cppuhelper \ + sal \ + sb \ + sfx \ + svl \ + svt \ + svx \ + stl \ + tk \ + tl \ + vbahelper \ + vcl \ + $(gb_STDLIBS) \ +)) + +# add all source files that shall be compiled with exceptions enabled +# the name is relative to $(SRCROOT) and must not contain an extension +$(eval $(call gb_Library_add_exception_objects,msforms,\ + vbahelper/source/msforms/service \ + vbahelper/source/msforms/vbabutton \ + vbahelper/source/msforms/vbacheckbox \ + vbahelper/source/msforms/vbacombobox \ + vbahelper/source/msforms/vbacontrol \ + vbahelper/source/msforms/vbacontrols \ + vbahelper/source/msforms/vbaframe \ + vbahelper/source/msforms/vbaimage \ + vbahelper/source/msforms/vbalabel \ + vbahelper/source/msforms/vbalistbox \ + vbahelper/source/msforms/vbalistcontrolhelper \ + vbahelper/source/msforms/vbamultipage \ + vbahelper/source/msforms/vbanewfont \ + vbahelper/source/msforms/vbapages \ + vbahelper/source/msforms/vbaprogressbar \ + vbahelper/source/msforms/vbaradiobutton \ + vbahelper/source/msforms/vbascrollbar \ + vbahelper/source/msforms/vbaspinbutton \ + vbahelper/source/msforms/vbasystemaxcontrol \ + vbahelper/source/msforms/vbatextbox \ + vbahelper/source/msforms/vbatogglebutton \ + vbahelper/source/msforms/vbauserform \ +)) + +# vim: set noet sw=4 ts=4: + diff --git a/vbahelper/Library_vbahelper.mk b/vbahelper/Library_vbahelper.mk new file mode 100755 index 000000000000..af6b4089ada8 --- /dev/null +++ b/vbahelper/Library_vbahelper.mk @@ -0,0 +1,102 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2011 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. +# +#************************************************************************* + +$(eval $(call gb_Library_Library,vbahelper)) + +$(eval $(call gb_Library_add_package_headers,vbahelper,vbahelper_inc)) + +# for platforms supporting PCH: declare the location of the pch file +# this is the name of the cxx file (without extension) +#$(eval $(call gb_Library_add_precompiled_header,vbahelper,$(SRCDIR)/vbahelper/PCH_FILE)) + +# in case UNO services are exported: declare location of component file +#$(eval $(call gb_Library_set_componentfile,vbahelper,vbahelper/COMPONENT_FILE)) + +# add any additional include paths for this library here +$(eval $(call gb_Library_set_include,vbahelper,\ + $$(INCLUDE) \ + -I$(OUTDIR)/inc/offuh \ +)) + +$(eval $(call gb_Library_set_defs,vbahelper,\ + $$(DEFS) \ + -DVBAHELPER_DLLIMPLEMENTATION \ +)) + +# add libraries to be linked to vbahelper; again these names need to be given as +# specified in Repository.mk +$(eval $(call gb_Library_add_linked_libs,vbahelper,\ + comphelper \ + cppu \ + cppuhelper \ + msfilter \ + sal \ + sb \ + sfx \ + stl \ + svl \ + svt \ + tk \ + tl \ + utl \ + vcl \ + $(gb_STDLIBS) \ +)) + +# add all source files that shall be compiled with exceptions enabled +# the name is relative to $(SRCROOT) and must not contain an extension +$(eval $(call gb_Library_add_exception_objects,vbahelper,\ + vbahelper/source/vbahelper/collectionbase \ + vbahelper/source/vbahelper/vbaapplicationbase \ + vbahelper/source/vbahelper/vbacolorformat \ + vbahelper/source/vbahelper/vbacommandbar \ + vbahelper/source/vbahelper/vbacommandbarcontrol \ + vbahelper/source/vbahelper/vbacommandbarcontrols \ + vbahelper/source/vbahelper/vbacommandbarhelper \ + vbahelper/source/vbahelper/vbacommandbars \ + vbahelper/source/vbahelper/vbadialogbase \ + vbahelper/source/vbahelper/vbadialogsbase \ + vbahelper/source/vbahelper/vbadocumentbase \ + vbahelper/source/vbahelper/vbadocumentsbase \ + vbahelper/source/vbahelper/vbaeventshelperbase \ + vbahelper/source/vbahelper/vbafillformat \ + vbahelper/source/vbahelper/vbafontbase \ + vbahelper/source/vbahelper/vbaglobalbase \ + vbahelper/source/vbahelper/vbahelper \ + vbahelper/source/vbahelper/vbalineformat \ + vbahelper/source/vbahelper/vbapagesetupbase \ + vbahelper/source/vbahelper/vbapictureformat \ + vbahelper/source/vbahelper/vbapropvalue \ + vbahelper/source/vbahelper/vbashape \ + vbahelper/source/vbahelper/vbashaperange \ + vbahelper/source/vbahelper/vbashapes \ + vbahelper/source/vbahelper/vbatextframe \ + vbahelper/source/vbahelper/vbawindowbase \ +)) + +# vim: set noet sw=4 ts=4: + diff --git a/vbahelper/Makefile b/vbahelper/Makefile new file mode 100755 index 000000000000..a79aff831024 --- /dev/null +++ b/vbahelper/Makefile @@ -0,0 +1,38 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +ifeq ($(strip $(SOLARENV)),) +$(error No environment set!) +endif + +gb_PARTIALBUILD := T +GBUILDDIR := $(SOLARENV)/gbuild +include $(GBUILDDIR)/gbuild.mk + +$(eval $(call gb_Module_make_global_targets,$(shell ls $(dir $(realpath $(firstword $(MAKEFILE_LIST))))/Module*.mk))) + +# vim: set noet sw=4 ts=4: diff --git a/vbahelper/Module_vbahelper.mk b/vbahelper/Module_vbahelper.mk new file mode 100755 index 000000000000..8fe6c15b6abf --- /dev/null +++ b/vbahelper/Module_vbahelper.mk @@ -0,0 +1,46 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2011 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. +# +#************************************************************************* + +$(eval $(call gb_Module_Module,vbahelper)) + +# the targets to be inserted are their file names without .mk extension +$(eval $(call gb_Module_add_targets,vbahelper,\ + Library_vbahelper \ + Library_msforms \ + Package_inc \ +)) + +# add any runtime tests (unit tests) here +# remove if no tests +#$(eval $(call gb_Module_add_check_targets,vbahelper,\ +#)) + +# add any subsequent checks (e.g. complex tests) here +#$(eval $(call gb_Module_add_subsequentcheck_targets,vbahelper,\ +#)) + +# vim: set noet sw=4 ts=4: diff --git a/vbahelper/Package_inc.mk b/vbahelper/Package_inc.mk new file mode 100755 index 000000000000..385fbf15a625 --- /dev/null +++ b/vbahelper/Package_inc.mk @@ -0,0 +1,53 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2011 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. +# +#************************************************************************* + +$(eval $(call gb_Package_Package,vbahelper_inc,$(SRCDIR)/vbahelper/inc)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/collectionbase.hxx,vbahelper/collectionbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/helperdecl.hxx,vbahelper/helperdecl.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaaccesshelper.hxx,vbahelper/vbaaccesshelper.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaapplicationbase.hxx,vbahelper/vbaapplicationbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbacollectionimpl.hxx,vbahelper/vbacollectionimpl.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbadialogbase.hxx,vbahelper/vbadialogbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbadialogsbase.hxx,vbahelper/vbadialogsbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbadllapi.h,vbahelper/vbadllapi.h)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbadocumentbase.hxx,vbahelper/vbadocumentbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbadocumentsbase.hxx,vbahelper/vbadocumentsbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaeventshelperbase.hxx,vbahelper/vbaeventshelperbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbafontbase.hxx,vbahelper/vbafontbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbaglobalbase.hxx,vbahelper/vbaglobalbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbahelper.hxx,vbahelper/vbahelper.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbahelperinterface.hxx,vbahelper/vbahelperinterface.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbapagesetupbase.hxx,vbahelper/vbapagesetupbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbapropvalue.hxx,vbahelper/vbapropvalue.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbashape.hxx,vbahelper/vbashape.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbashaperange.hxx,vbahelper/vbashaperange.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbashapes.hxx,vbahelper/vbashapes.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbatextframe.hxx,vbahelper/vbatextframe.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/vbawindowbase.hxx,vbahelper/vbawindowbase.hxx)) +$(eval $(call gb_Package_add_file,vbahelper_inc,inc/vbahelper/weakreference.hxx,vbahelper/weakreference.hxx)) + +# vim: set noet sw=4 ts=4: diff --git a/vbahelper/inc/vbahelper/collectionbase.hxx b/vbahelper/inc/vbahelper/collectionbase.hxx new file mode 100755 index 000000000000..ebb5bf8f2b9a --- /dev/null +++ b/vbahelper/inc/vbahelper/collectionbase.hxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBAHELPER_COLLECTIONBASE_HXX +#define VBAHELPER_COLLECTIONBASE_HXX + +#include <vector> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/container/XElementAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> +#include <ooo/vba/XCollectionBase.hpp> +#include <cppuhelper/implbase1.hxx> +#include <vbahelper/vbahelper.hxx> + +namespace vbahelper { + +// ============================================================================ + +typedef ::cppu::WeakImplHelper1< ov::XCollectionBase > CollectionBase_BASE; + +/** Base class of VBA objects implementing the VBA collection concept. + + This base class intentionally does not include the interface + XHelperInterface supported by all application VBA object. There may be + other VBA objects that do not support the special methods provided by + XHelperInterface. + */ +class VBAHELPER_DLLPUBLIC CollectionBase : public CollectionBase_BASE +{ +public: + /** Enumerates different container types a VBA collection can be based on. */ + enum ContainerType + { + /** Container elements are VBA items. + + The initial container contains the final VBA items provided by the + VBA collection. No conversion takes place on item access. + */ + CONTAINER_NATIVE_VBA, + + /** Container elements will be converted to VBA items on demand. + + The initial container contains intermediate objects (e.g. UNO + objects) which will be converted to VBA items everytime the item is + accessed (e.g. item access method, enumeration). Changes in the + initial container are reflected by the collection. + */ + CONTAINER_CONVERT_ON_DEMAND, + }; + + // ------------------------------------------------------------------------ + + CollectionBase( const css::uno::Type& rElementType ); + + // ------------------------------------------------------------------------ + + // attributes + virtual sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException); + // XDefaultMethod + virtual ::rtl::OUString SAL_CALL getDefaultMethodName() throw (css::uno::RuntimeException); + + // ------------------------------------------------------------------------ + + /** Associates this collection with the passed UNO container. + + @param rxElementAccess + The UNO container with the elements of this collection. Shall + support either XIndexAccess or XNameAccess, may support both. + + If the container does not support XIndexAccess, index access is + simulated based on the order returned by the function + XNameAccess::getElementNames(). + + If the container does not support XNameAccess, name access is + simulated by iterating the elements via index access and asking the + elements for their name via the interface XNamed. If the elements + do not support XNamed, the elements cannot be accessed by name. + + @param eContainerType + Specifies the type of the passed container. + */ + void initContainer( + const css::uno::Reference< css::container::XElementAccess >& rxElementAccess, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Initializes this collection with copies of all elements in the passed + temporary STL vector. + + @param rElements + The STL vector with the named elements of this collection. + @param eContainerType + Specifies the type of the passed vector. + */ + void initElements( + const ::std::vector< css::uno::Reference< css::container::XNamed > >& rElements, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Initializes this collection with copies of all elements in the passed + temporary STL vector. + + @param rElements + The STL vector with the named elements of this collection. + @param eContainerType + Specifies the type of the passed vector. + */ + void initElements( + const ::std::vector< css::beans::NamedValue >& rElements, + ContainerType eContainerType ) throw (css::uno::RuntimeException); + + /** Returns a VBA implementation object from the passed element. + + If the container type is CONTAINER_NATIVE_VBA, returns the passed + object unmodified. If the container type is CONTAINER_CONVERT_ON_DEMAND, + calls the virtual function implCreateCollectionItem() that implements + creation of the VBA implmentation object. + + @param rElement + The container element the VBA implementation object is based on. + + @param rIndex + The index or name that has been used to access the item. + */ + css::uno::Any createCollectionItem( + const css::uno::Any& rElement, + const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its one-based item index. + + @param nIndex + The one-based index of the collection item. + */ + css::uno::Any getItemByIndex( sal_Int32 nIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its name. + + @param rName + The name of the collection item. + */ + css::uno::Any getItemByName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + + /** Returns a collection item specified by its index or name. + + @param rIndex + The index or name of the collection item. May be empty, in that + case the entire collection is returned. + */ + css::uno::Any getAnyItemOrThis( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + + /** Returns a collection item of a specific type specified by its index or + name. + + @param rIndex + The index or name of the collection item. + */ + template< typename XType > + inline css::uno::Reference< XType > getAnyItem( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException) + { css::uno::Any aRet; if( rIndex.hasValue() ) aRet = getAnyItemOrThis( rIndex ); return css::uno::Reference< XType >( aRet, css::uno::UNO_QUERY_THROW ); } + +protected: + /** Derived classes implement creation of a VBA implementation object from + the passed intermediate container element. + + May be kept unimplemented if container type is CONTAINER_NATIVE_VBA. + + @param rElement + The container element the VBA implementation object is based on. + + @param rIndex + The index or name used to access the item. Can be used by + implementations as a hint how to find or convert the VBA object. + */ + virtual css::uno::Any implCreateCollectionItem( const css::uno::Any& rElement, const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + +private: + css::uno::Reference< css::container::XIndexAccess > mxIndexAccess; + css::uno::Reference< css::container::XNameAccess > mxNameAccess; + css::uno::Type maElementType; + bool mbConvertOnDemand; +}; + +// ============================================================================ + +} // namespace vbahelper + +#endif diff --git a/vbahelper/inc/vbahelper/helperdecl.hxx b/vbahelper/inc/vbahelper/helperdecl.hxx new file mode 100644 index 000000000000..0b51c6242226 --- /dev/null +++ b/vbahelper/inc/vbahelper/helperdecl.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef OOVBAAPI_SERV_DECL +#define OOVBAAPI_SERV_DECL +#include <comphelper/servicedecl.hxx> +#include <ooo/vba/XHelperInterface.hpp> + +namespace comphelper { +namespace service_decl { +template <typename ImplT_, typename WithArgsT = with_args<false> > +struct vba_service_class_ : public serviceimpl_base< detail::OwnServiceImpl<ImplT_>, WithArgsT > +{ + typedef serviceimpl_base< detail::OwnServiceImpl<ImplT_>, WithArgsT > baseT; + /** Default ctor. Implementation class without args, expecting + component context as single argument. + */ + vba_service_class_() : baseT() {} + template <typename PostProcessFuncT> + /** Ctor to pass a post processing function/functor. + + @tpl PostProcessDefaultT let your compiler deduce this + @param postProcessFunc function/functor that gets the yet unacquired + ImplT_ pointer returning a + uno::Reference<uno::XInterface> + */ + explicit vba_service_class_( PostProcessFuncT const& postProcessFunc ) : baseT( postProcessFunc ) {} +}; + +} // namespace service_decl +} // namespace comphelper +#endif diff --git a/vbahelper/inc/vbahelper/vbaaccesshelper.hxx b/vbahelper/inc/vbahelper/vbaaccesshelper.hxx new file mode 100644 index 000000000000..9fcfde744bbc --- /dev/null +++ b/vbahelper/inc/vbahelper/vbaaccesshelper.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: vbahelper.hxx,v $ + * $Revision: 1.5.32.1 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef OOVBAAPI_VBA_ACCESS_HELPER_HXX +#define OOVBAAPI_VBA_ACCESS_HELPER_HXX + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <basic/basmgr.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> +//#define VBAHELPER_DLLIMPLEMENTATION +#include <vbahelper/vbadllapi.h> +#include <memory> +namespace css = ::com::sun::star; +namespace ooo +{ + namespace vba + { + + VBAHELPER_DLLPRIVATE inline css::uno::Reference< css::lang::XMultiServiceFactory > getVBAServiceFactory( SfxObjectShell* pShell ) + { + css::uno::Any aUnoVar; + if ( !pShell || ! pShell->GetBasicManager()->GetGlobalUNOConstant( "VBAGlobals", aUnoVar ) ) + throw css::lang::IllegalArgumentException(); + css::uno::Reference< css::lang::XMultiServiceFactory > xVBAFactory( aUnoVar, css::uno::UNO_QUERY_THROW ); + return xVBAFactory; + } + + VBAHELPER_DLLPUBLIC inline css::uno::Reference< css::uno::XInterface > createVBAUnoAPIServiceWithArgs( SfxObjectShell* pShell, const sal_Char* _pAsciiName, const css::uno::Sequence< css::uno::Any >& aArgs ) throw (css::uno::RuntimeException) + { + OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" ); + ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) ); + css::uno::Reference< css::uno::XInterface > xIf = getVBAServiceFactory( pShell )->createInstanceWithArguments( sVarName, aArgs ); + return xIf; + } + + + VBAHELPER_DLLPRIVATE inline bool isAlienDoc( SfxObjectShell& rDocShell, const char* pMimeType ) + { + bool bRes( false ); + const SfxFilter *pFilt = rDocShell.GetMedium()->GetFilter(); + if ( pFilt && pFilt->IsAlienFormat() ) + bRes = ( pFilt->GetMimeType().CompareToAscii( pMimeType ) == 0 ); + return bRes; + } + VBAHELPER_DLLPUBLIC inline bool isAlienExcelDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-excel" ); } + VBAHELPER_DLLPUBLIC inline bool isAlienWordDoc( SfxObjectShell& rDocShell ) { return isAlienDoc( rDocShell, "application/vnd.ms-word" ); } + + } // openoffice +} // org + +#endif diff --git a/vbahelper/inc/vbahelper/vbaapplicationbase.hxx b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx new file mode 100644 index 000000000000..10cf0ba6ab70 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbaapplicationbase.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_APPLICATION_BASE_HXX +#define VBA_APPLICATION_BASE_HXX + +#include <ooo/vba/XHelperInterface.hpp> +#include <ooo/vba/XApplicationBase.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <sfx2/objsh.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::XApplicationBase > ApplicationBase_BASE; + +struct VbaApplicationBase_Impl; + +class VBAHELPER_DLLPUBLIC VbaApplicationBase : public ApplicationBase_BASE +{ + VbaApplicationBase_Impl* m_pImpl; + +protected: + VbaApplicationBase( const css::uno::Reference< css::uno::XComponentContext >& xContext ); + virtual ~VbaApplicationBase(); + + virtual css::uno::Reference< css::frame::XModel > getCurrentDocument() throw (css::uno::RuntimeException) = 0; +public: + // XHelperInterface ( parent is itself ) + virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { return this; } + + virtual sal_Bool SAL_CALL getScreenUpdating() throw (css::uno::RuntimeException); + virtual void SAL_CALL setScreenUpdating(sal_Bool bUpdate) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getDisplayStatusBar() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDisplayStatusBar(sal_Bool bDisplayStatusBar) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getInteractive() throw (css::uno::RuntimeException); + virtual void SAL_CALL setInteractive( ::sal_Bool bInteractive ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( ::sal_Bool bVisible ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL CommandBars( const css::uno::Any& aIndex ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getVersion() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getVBE() throw (css::uno::RuntimeException); + + virtual void SAL_CALL Run( const ::rtl::OUString& MacroName, const css::uno::Any& varg1, const css::uno::Any& varg2, const css::uno::Any& varg3, const css::uno::Any& varg4, const css::uno::Any& varg5, const css::uno::Any& varg6, const css::uno::Any& varg7, const css::uno::Any& varg8, const css::uno::Any& varg9, const css::uno::Any& varg10, const css::uno::Any& varg11, const css::uno::Any& varg12, const css::uno::Any& varg13, const css::uno::Any& varg14, const css::uno::Any& varg15, const css::uno::Any& varg16, const css::uno::Any& varg17, const css::uno::Any& varg18, const css::uno::Any& varg19, const css::uno::Any& varg20, const css::uno::Any& varg21, const css::uno::Any& varg22, const css::uno::Any& varg23, const css::uno::Any& varg24, const css::uno::Any& varg25, const css::uno::Any& varg26, const css::uno::Any& varg27, const css::uno::Any& varg28, const css::uno::Any& varg29, const css::uno::Any& varg30 ) throw (css::uno::RuntimeException); + virtual void SAL_CALL OnTime( const css::uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const css::uno::Any& aLatestTime, const css::uno::Any& aSchedule ) throw (css::uno::RuntimeException); + virtual float SAL_CALL CentimetersToPoints( float _Centimeters ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Undo() throw (css::uno::RuntimeException); + virtual void SAL_CALL Quit() throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif diff --git a/vbahelper/inc/vbahelper/vbacollectionimpl.hxx b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx new file mode 100644 index 000000000000..da0fd29267ae --- /dev/null +++ b/vbahelper/inc/vbahelper/vbacollectionimpl.hxx @@ -0,0 +1,347 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef OOVBAAPI_VBA_COLLECTION_IMPL_HXX +#define OOVBAAPI_VBA_COLLECTION_IMPL_HXX + +#include <ooo/vba/XCollection.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/script/XDefaultMethod.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNamed.hpp> + +#include <cppuhelper/implbase3.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase1.hxx> + +#include "vbahelper/vbahelper.hxx" +#include "vbahelper/vbahelperinterface.hxx" + +#include <vector> + +// ============================================================================ + +typedef ::cppu::WeakImplHelper1< css::container::XEnumeration > EnumerationHelper_BASE; + +// ============================================================================ + +/** A wrapper that holds a com.sun.star.container.XIndexAccess and provides a + com.sun.star.container.XEnumeration. + + Can be used to provide an enumeration from an index container that contains + completely constructed/initialized VBA implementation objects. CANNOT be + used to provide an enumeration from an index container with other objects + (e.g. UNO objects) where construction of the VBA objects is needed first. + */ +class VBAHELPER_DLLPUBLIC SimpleIndexAccessToEnumeration : public EnumerationHelper_BASE +{ +public: + explicit SimpleIndexAccessToEnumeration( + const css::uno::Reference< css::container::XIndexAccess >& rxIndexAccess ) throw (css::uno::RuntimeException) : + mxIndexAccess( rxIndexAccess ), mnIndex( 0 ) {} + + virtual sal_Bool SAL_CALL hasMoreElements() throw (css::uno::RuntimeException) + { + return mnIndex < mxIndexAccess->getCount(); + } + + virtual css::uno::Any SAL_CALL nextElement() throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException) + { + if( !hasMoreElements() ) + throw css::container::NoSuchElementException(); + return mxIndexAccess->getByIndex( mnIndex++ ); + } + +private: + css::uno::Reference< css::container::XIndexAccess > mxIndexAccess; + sal_Int32 mnIndex; +}; + +// ============================================================================ + +/** A wrapper that holds a com.sun.star.container.XEnumeration or a + com.sun.star.container.XIndexAccess and provides an enumeration of VBA objects. + + The method createCollectionObject() needs to be implemented by the derived + class. This class can be used to convert an enumeration or an index container + containing UNO objects to an enumeration providing the related VBA objects. + */ +class VBAHELPER_DLLPUBLIC SimpleEnumerationBase : public EnumerationHelper_BASE +{ +public: + explicit SimpleEnumerationBase( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::container::XEnumeration >& rxEnumeration ) throw (css::uno::RuntimeException) : + mxParent( rxParent ), mxContext( rxContext ), mxEnumeration( rxEnumeration ) {} + + explicit SimpleEnumerationBase( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::container::XIndexAccess >& rxIndexAccess ) throw (css::uno::RuntimeException) : + mxParent( rxParent ), mxContext( rxContext ), mxEnumeration( new SimpleIndexAccessToEnumeration( rxIndexAccess ) ) {} + + virtual sal_Bool SAL_CALL hasMoreElements() throw (css::uno::RuntimeException) + { + return mxEnumeration->hasMoreElements(); + } + + virtual css::uno::Any SAL_CALL nextElement() throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException) + { + return createCollectionObject( mxEnumeration->nextElement() ); + } + + /** Derived classes implement creation of a VBA implementation object from + the passed container element. */ + virtual css::uno::Any createCollectionObject( const css::uno::Any& rSource ) = 0; + +protected: + css::uno::Reference< ov::XHelperInterface > mxParent; + css::uno::Reference< css::uno::XComponentContext > mxContext; + css::uno::Reference< css::container::XEnumeration > mxEnumeration; +}; + +// ============================================================================ + +// deprecated, use SimpleEnumerationBase instead! +class VBAHELPER_DLLPUBLIC EnumerationHelperImpl : public EnumerationHelper_BASE +{ +protected: + css::uno::WeakReference< ov::XHelperInterface > m_xParent; + css::uno::Reference< css::uno::XComponentContext > m_xContext; + css::uno::Reference< css::container::XEnumeration > m_xEnumeration; +public: + + EnumerationHelperImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XEnumeration >& xEnumeration ) throw ( css::uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_xEnumeration( xEnumeration ) { } + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (css::uno::RuntimeException) { return m_xEnumeration->hasMoreElements(); } +}; + +// a wrapper class for a providing a XIndexAccess, XNameAccess, XEnumerationAccess impl based on providing a vector of interfaces +// only requirement is the object needs to implement XName + + + +typedef ::cppu::WeakImplHelper3< css::container::XNameAccess, css::container::XIndexAccess, css::container::XEnumerationAccess > XNamedCollectionHelper_BASE; + +template< typename Ifc1 > +class XNamedObjectCollectionHelper : public XNamedCollectionHelper_BASE +{ +public: +typedef std::vector< css::uno::Reference< Ifc1 > > XNamedVec; +private: + + class XNamedEnumerationHelper : public EnumerationHelper_BASE + { + XNamedVec mXNamedVec; + typename XNamedVec::iterator mIt; + public: + XNamedEnumerationHelper( const XNamedVec& sMap ) : mXNamedVec( sMap ), mIt( mXNamedVec.begin() ) {} + + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (css::uno::RuntimeException) + { + return ( mIt != mXNamedVec.end() ); + } + + virtual css::uno::Any SAL_CALL nextElement( ) throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException) + { + if ( hasMoreElements() ) + return css::uno::makeAny( *mIt++ ); + throw css::container::NoSuchElementException(); + } + }; + +protected: + XNamedVec mXNamedVec; + typename XNamedVec::iterator cachePos; +public: + XNamedObjectCollectionHelper( const XNamedVec& sMap ) : mXNamedVec( sMap ), cachePos(mXNamedVec.begin()) {} + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType( ) throw (css::uno::RuntimeException) { return Ifc1::static_type(0); } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (css::uno::RuntimeException) { return ( mXNamedVec.size() > 0 ); } + // XNameAcess + virtual css::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (css::container::NoSuchElementException, css::lang::WrappedTargetException, css::uno::RuntimeException) + { + if ( !hasByName(aName) ) + throw css::container::NoSuchElementException(); + return css::uno::makeAny( *cachePos ); + } + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (css::uno::RuntimeException) + { + css::uno::Sequence< rtl::OUString > sNames( mXNamedVec.size() ); + rtl::OUString* pString = sNames.getArray(); + typename XNamedVec::iterator it = mXNamedVec.begin(); + typename XNamedVec::iterator it_end = mXNamedVec.end(); + + for ( ; it != it_end; ++it, ++pString ) + { + css::uno::Reference< css::container::XNamed > xName( *it, css::uno::UNO_QUERY_THROW ); + *pString = xName->getName(); + } + return sNames; + } + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException) + { + cachePos = mXNamedVec.begin(); + typename XNamedVec::iterator it_end = mXNamedVec.end(); + for ( ; cachePos != it_end; ++cachePos ) + { + css::uno::Reference< css::container::XNamed > xName( *cachePos, css::uno::UNO_QUERY_THROW ); + if ( aName.equals( xName->getName() ) ) + break; + } + return ( cachePos != it_end ); + } + + // XElementAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (css::uno::RuntimeException) { return mXNamedVec.size(); } + virtual css::uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (css::lang::IndexOutOfBoundsException, css::lang::WrappedTargetException, css::uno::RuntimeException ) + { + if ( Index < 0 || Index >= getCount() ) + throw css::lang::IndexOutOfBoundsException(); + + return css::uno::makeAny( mXNamedVec[ Index ] ); + + } + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration( ) throw (css::uno::RuntimeException) + { + return new XNamedEnumerationHelper( mXNamedVec ); + } +}; + +// including a HelperInterface implementation +template< typename Ifc1 > +class ScVbaCollectionBase : public InheritedHelperInterfaceImpl< Ifc1 > +{ +typedef InheritedHelperInterfaceImpl< Ifc1 > BaseColBase; +protected: + css::uno::Reference< css::container::XIndexAccess > m_xIndexAccess; + css::uno::Reference< css::container::XNameAccess > m_xNameAccess; + + virtual css::uno::Any getItemByStringIndex( const rtl::OUString& sIndex ) throw (css::uno::RuntimeException) + { + if ( !m_xNameAccess.is() ) + throw css::uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScVbaCollectionBase string index access not supported by this object") ), css::uno::Reference< css::uno::XInterface >() ); + + return createCollectionObject( m_xNameAccess->getByName( sIndex ) ); + } + + virtual css::uno::Any getItemByIntIndex( const sal_Int32 nIndex ) throw (css::uno::RuntimeException) + { + if ( !m_xIndexAccess.is() ) + throw css::uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ScVbaCollectionBase numeric index access not supported by this object") ), css::uno::Reference< css::uno::XInterface >() ); + if ( nIndex <= 0 ) + { + throw css::lang::IndexOutOfBoundsException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "index is 0 or negative" ) ), + css::uno::Reference< css::uno::XInterface >() ); + } + // need to adjust for vba index ( for which first element is 1 ) + return createCollectionObject( m_xIndexAccess->getByIndex( nIndex - 1 ) ); + } + + virtual void UpdateCollectionIndex( const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) + { + css::uno::Reference< css::container::XNameAccess > xNameAccess( xIndexAccess, css::uno::UNO_QUERY_THROW ); + m_xIndexAccess = xIndexAccess; + m_xNameAccess = xNameAccess; + } + +public: + ScVbaCollectionBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) : BaseColBase( xParent, xContext ), m_xIndexAccess( xIndexAccess ){ m_xNameAccess.set(m_xIndexAccess, css::uno::UNO_QUERY); } + //XCollection + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException) + { + return m_xIndexAccess->getCount(); + } + + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& /*not processed in this base class*/ ) throw (css::uno::RuntimeException) + { + if ( Index1.getValueTypeClass() != css::uno::TypeClass_STRING ) + { + sal_Int32 nIndex = 0; + + if ( ( Index1 >>= nIndex ) != sal_True ) + { + rtl::OUString message; + message = rtl::OUString::createFromAscii( + "Couldn't convert index to Int32"); + throw css::lang::IndexOutOfBoundsException( message, + css::uno::Reference< css::uno::XInterface >() ); + } + return getItemByIntIndex( nIndex ); + } + rtl::OUString aStringSheet; + + Index1 >>= aStringSheet; + return getItemByStringIndex( aStringSheet ); + } + // XDefaultMethod + ::rtl::OUString SAL_CALL getDefaultMethodName( ) throw (css::uno::RuntimeException) + { + const static rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM("Item") ); + return sName; + } + // XEnumerationAccess + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException) = 0; + + // XElementAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException) = 0; + // XElementAccess + virtual ::sal_Bool SAL_CALL hasElements() throw (css::uno::RuntimeException) + { + return ( m_xIndexAccess->getCount() > 0 ); + } + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) = 0; + +}; + +typedef ::cppu::WeakImplHelper1<ov::XCollection> XCollection_InterfacesBASE; + +typedef ScVbaCollectionBase< XCollection_InterfacesBASE > CollImplBase1; +// compatible with the old collections ( pre XHelperInterface base class ) ( some internal objects still use this ) +class VBAHELPER_DLLPUBLIC ScVbaCollectionBaseImpl : public CollImplBase1 +{ +public: + ScVbaCollectionBaseImpl( const css::uno::Reference< ov::XHelperInterface > xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) throw( css::uno::RuntimeException ) : CollImplBase1( xParent, xContext, xIndexAccess){} + +}; + +template <typename Ifc> // where Ifc must implement XCollectionTest +class CollTestImplHelper : public ScVbaCollectionBase< ::cppu::WeakImplHelper1< Ifc > > +{ +typedef ScVbaCollectionBase< ::cppu::WeakImplHelper1< Ifc > > ImplBase1; + +public: + CollTestImplHelper( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess ) throw( css::uno::RuntimeException ) : ImplBase1( xParent, xContext, xIndexAccess ) {} +}; + + +#endif //SC_VBA_COLLECTION_IMPL_HXX diff --git a/vbahelper/inc/vbahelper/vbadialogbase.hxx b/vbahelper/inc/vbahelper/vbadialogbase.hxx new file mode 100644 index 000000000000..79c3fa551073 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbadialogbase.hxx @@ -0,0 +1,51 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_DIALOG_BASE_HXX +#define VBA_DIALOG_BASE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/XDialogBase.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/frame/XModel.hpp> + +typedef InheritedHelperInterfaceImpl1< ov::XDialogBase > VbaDialogBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDialogBase : public VbaDialogBase_BASE +{ +protected: + sal_Int32 mnIndex; + css::uno::Reference< css::frame::XModel > m_xModel; +public: + VbaDialogBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel, sal_Int32 nIndex ):VbaDialogBase_BASE( xParent, xContext ), mnIndex( nIndex ), m_xModel( xModel ) {} + virtual ~VbaDialogBase() {} + + // Methods + virtual void SAL_CALL Show() throw (css::uno::RuntimeException); + virtual rtl::OUString mapIndexToName( sal_Int32 nIndex ) = 0; +}; + +#endif /* VBA_DIALOG_BASE_HXX */ diff --git a/vbahelper/inc/vbahelper/vbadialogsbase.hxx b/vbahelper/inc/vbahelper/vbadialogsbase.hxx new file mode 100644 index 000000000000..408a156ac3bc --- /dev/null +++ b/vbahelper/inc/vbahelper/vbadialogsbase.hxx @@ -0,0 +1,51 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_DIALOGS_BASE_HXX +#define VBA_DIALOGS_BASE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/XHelperInterface.hpp> +#include <ooo/vba/XDialogsBase.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/frame/XModel.hpp> + +typedef InheritedHelperInterfaceImpl1< ov::XDialogsBase > VbaDialogsBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDialogsBase : public VbaDialogsBase_BASE +{ +protected: + css::uno::Reference< css::frame::XModel > m_xModel; +public: + VbaDialogsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel >& xModel ): VbaDialogsBase_BASE( xParent, xContext ), m_xModel( xModel ) {} + virtual ~VbaDialogsBase() {} + + // XCollection + virtual ::sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index ) throw (css::uno::RuntimeException); +}; + +#endif /* VBA_DIALOGS_BASE_HXX */ diff --git a/vbahelper/inc/vbahelper/vbadllapi.h b/vbahelper/inc/vbahelper/vbadllapi.h new file mode 100644 index 000000000000..1768802c5176 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbadllapi.h @@ -0,0 +1,41 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_VBADLLAPI_H +#define INCLUDED_VBADLLAPI_H + +#include "sal/types.h" + +#if defined(VBAHELPER_DLLIMPLEMENTATION) +#define VBAHELPER_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define VBAHELPER_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define VBAHELPER_DLLPRIVATE SAL_DLLPRIVATE + +#endif /* INCLUDED_SVLDLLAPI_H */ + diff --git a/vbahelper/inc/vbahelper/vbadocumentbase.hxx b/vbahelper/inc/vbahelper/vbadocumentbase.hxx new file mode 100644 index 000000000000..d1c7320fbfb1 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbadocumentbase.hxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_DOCUMENTBASE_HXX +#define VBA_DOCUMENTBASE_HXX + +#include <com/sun/star/frame/XModel.hpp> +#include <ooo/vba/XDocumentBase.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::XDocumentBase > VbaDocumentBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDocumentBase : public VbaDocumentBase_BASE +{ +protected: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::uno::XInterface > mxVBProject; +protected: + virtual css::uno::Reference< css::frame::XModel > getModel() { return mxModel; } + VbaDocumentBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext); +public: + VbaDocumentBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + css::uno::Reference< css::frame::XModel > xModel ); + VbaDocumentBase( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ); + virtual ~VbaDocumentBase() {} + + // Attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getPath() throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getFullName() throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getSaved() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSaved( sal_Bool bSave ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getVBProject() throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Close( const css::uno::Any &bSaveChanges, + const css::uno::Any &aFileName, + const css::uno::Any &bRouteWorkbook ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Protect( const css::uno::Any & aPassword ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Unprotect( const css::uno::Any &aPassword ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Save() throw (css::uno::RuntimeException); + virtual void SAL_CALL Activate() throw (css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif /* VBA_DOCUMENTBASE_HXX */ diff --git a/vbahelper/inc/vbahelper/vbadocumentsbase.hxx b/vbahelper/inc/vbahelper/vbadocumentsbase.hxx new file mode 100644 index 000000000000..8e4554b74b3d --- /dev/null +++ b/vbahelper/inc/vbahelper/vbadocumentsbase.hxx @@ -0,0 +1,66 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_WORKBOOKS_HXX +#define VBA_WORKBOOKS_HXX + + +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/XDocumentsBase.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> + +typedef CollTestImplHelper< ooo::vba::XDocumentsBase > VbaDocumentsBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaDocumentsBase : public VbaDocumentsBase_BASE +{ +public: + enum DOCUMENT_TYPE + { + WORD_DOCUMENT = 1, + EXCEL_DOCUMENT + }; + +private: + DOCUMENT_TYPE meDocType; + +public: + VbaDocumentsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, DOCUMENT_TYPE eDocType ) throw (css::uno::RuntimeException); + virtual ~VbaDocumentsBase() {} + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException) = 0; + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException) = 0; + + // VbaDocumentsBase_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) = 0; + +protected: + css::uno::Any createDocument() throw (css::uno::RuntimeException); + void closeDocuments() throw (css::uno::RuntimeException); + css::uno::Any openDocument( const ::rtl::OUString& Filename, const css::uno::Any& ReadOnly, const css::uno::Sequence< css::beans::PropertyValue >& rProps ) throw (css::uno::RuntimeException); +}; + +#endif /* SC_VBA_WORKBOOKS_HXX */ diff --git a/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx new file mode 100755 index 000000000000..dc554d6a043f --- /dev/null +++ b/vbahelper/inc/vbahelper/vbaeventshelperbase.hxx @@ -0,0 +1,190 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBAHELPER_VBAEVENTSHELPERBASE_HXX +#define VBAHELPER_VBAEVENTSHELPERBASE_HXX + +#include <deque> +#include <hash_map> +#include <map> +#include <com/sun/star/document/XEventListener.hpp> +#include <com/sun/star/script/vba/XVBAEventProcessor.hpp> +#include <com/sun/star/util/XChangesListener.hpp> +#include <cppuhelper/implbase3.hxx> +#include "vbahelper/vbahelper.hxx" + +namespace com { namespace sun { namespace star { + namespace script { namespace vba { class XVBAModuleInfo; } } + namespace uno { class XComponentContext; } +} } } + +// ============================================================================ + +typedef ::cppu::WeakImplHelper3< + css::script::vba::XVBAEventProcessor, + css::document::XEventListener, + css::util::XChangesListener > VbaEventsHelperBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaEventsHelperBase : public VbaEventsHelperBase_BASE +{ +public: + VbaEventsHelperBase( + const css::uno::Sequence< css::uno::Any >& rArgs, + const css::uno::Reference< css::uno::XComponentContext >& xContext ); + virtual ~VbaEventsHelperBase(); + + // script::vba::XVBAEventProcessor + virtual sal_Bool SAL_CALL hasVbaEventHandler( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); + virtual sal_Bool SAL_CALL processVbaEvent( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::util::VetoException, css::uno::RuntimeException); + + // document::XEventListener + virtual void SAL_CALL notifyEvent( const css::document::EventObject& rEvent ) throw (css::uno::RuntimeException); + + // util::XChangesListener + virtual void SAL_CALL changesOccurred( const css::util::ChangesEvent& rEvent ) throw (css::uno::RuntimeException); + + // lang::XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) throw (css::uno::RuntimeException); + + // little helpers --------------------------------------------------------- + + /** Helper to execute event handlers without throwing any exceptions. */ + void processVbaEventNoThrow( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ); + + /** Throws, if the passed sequence does not contain a value at the specified index. */ + static inline void checkArgument( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException) + { if( (nIndex < 0) || (nIndex >= rArgs.getLength()) ) throw css::lang::IllegalArgumentException(); } + + /** Throws, if the passed sequence does not contain a value of a specific at the specified index. */ + template< typename Type > + static inline void checkArgumentType( const css::uno::Sequence< css::uno::Any >& rArgs, sal_Int32 nIndex ) throw (css::lang::IllegalArgumentException) + { checkArgument( rArgs, nIndex ); if( !rArgs[ nIndex ].has< Type >() ) throw css::lang::IllegalArgumentException(); } + +protected: + // ------------------------------------------------------------------------ + + struct EventHandlerInfo + { + sal_Int32 mnEventId; + sal_Int32 mnModuleType; + ::rtl::OUString maMacroName; + sal_Int32 mnCancelIndex; + css::uno::Any maUserData; + }; + + /** Registers a supported event handler. + + @param nEventId Event identifier from com.sun.star.script.vba.VBAEventId. + @param nModuleType Type of the module containing the event handler. + @param pcMacroName Name of the associated VBA event handler macro. + @param nCancelIndex 0-based index of Cancel parameter, or -1. + @param rUserData User data for free usage in derived implementations. */ + void registerEventHandler( + sal_Int32 nEventId, + sal_Int32 nModuleType, + const sal_Char* pcMacroName, + sal_Int32 nCancelIndex = -1, + const css::uno::Any& rUserData = css::uno::Any() ); + + // ------------------------------------------------------------------------ + + struct EventQueueEntry + { + sal_Int32 mnEventId; + css::uno::Sequence< css::uno::Any > maArgs; + inline /*implicit*/ EventQueueEntry( sal_Int32 nEventId ) : mnEventId( nEventId ) {} + inline EventQueueEntry( sal_Int32 nEventId, const css::uno::Sequence< css::uno::Any >& rArgs ) : mnEventId( nEventId ), maArgs( rArgs ) {} + }; + typedef ::std::deque< EventQueueEntry > EventQueue; + + /** Derived classes do additional prpeparations and return whether the + event handler has to be called. */ + virtual bool implPrepareEvent( + EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::uno::RuntimeException) = 0; + + /** Derived classes have to return the argument list for the specified VBA event handler. */ + virtual css::uno::Sequence< css::uno::Any > implBuildArgumentList( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException) = 0; + + /** Derived classes may do additional postprocessing. Called even if the + event handler does not exist, or if an error occured during execution. */ + virtual void implPostProcessEvent( + EventQueue& rEventQueue, + const EventHandlerInfo& rInfo, + bool bCancel ) throw (css::uno::RuntimeException) = 0; + + /** Derived classes have to return the name of the Basic document module. */ + virtual ::rtl::OUString implGetDocumentModuleName( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) const throw (css::lang::IllegalArgumentException) = 0; + +private: + typedef ::std::map< sal_Int32, ::rtl::OUString > ModulePathMap; + + /** Starts listening at the document model. */ + void startListening(); + /** Stops listening at the document model. */ + void stopListening(); + + /** Returns the event handler info struct for the specified event, or throws. */ + const EventHandlerInfo& getEventHandlerInfo( sal_Int32 nEventId ) const throw (css::lang::IllegalArgumentException); + + /** Searches the event handler in the document and returns its full script path. */ + ::rtl::OUString getEventHandlerPath( + const EventHandlerInfo& rInfo, + const css::uno::Sequence< css::uno::Any >& rArgs ) throw (css::lang::IllegalArgumentException, css::uno::RuntimeException); + + /** On first call, accesses the Basic library containing the VBA source code. */ + void ensureVBALibrary() throw (css::uno::RuntimeException); + + /** Returns the type of the Basic module with the specified name. */ + sal_Int32 getModuleType( const ::rtl::OUString& rModuleName ) throw (css::uno::RuntimeException); + + /** Updates the map containing paths to event handlers for a Basic module. */ + ModulePathMap& updateModulePathMap( const ::rtl::OUString& rModuleName ) throw (css::uno::RuntimeException); + +protected: + css::uno::Reference< css::frame::XModel > mxModel; + SfxObjectShell* mpShell; + +private: + typedef ::std::map< sal_Int32, EventHandlerInfo > EventHandlerInfoMap; + typedef ::std::hash_map< ::rtl::OUString, ModulePathMap, ::rtl::OUStringHash > EventHandlerPathMap; + + EventHandlerInfoMap maEventInfos; + EventHandlerPathMap maEventPaths; + css::uno::Reference< css::script::vba::XVBAModuleInfo > mxModuleInfos; + ::rtl::OUString maLibraryName; + bool mbDisposed; +}; + +// ============================================================================ + +#endif diff --git a/vbahelper/inc/vbahelper/vbafontbase.hxx b/vbahelper/inc/vbahelper/vbafontbase.hxx new file mode 100644 index 000000000000..d1272c9dcf48 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbafontbase.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBAHELPER_FONTBASE_HXX +#define VBAHELPER_FONTBASE_HXX + +#include <cppuhelper/implbase1.hxx> + +#include <ooo/vba/XFontBase.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +// use local constants there is no need to expose these constants +// externally. Looking at the Format->Character dialog it seem that +// these may infact be even be calculated. Leave hardcoded for now +// #FIXEME #TBD investigate the code for dialog mentioned above + +// The font baseline is not specified. +const short NORMAL = 0; + +// specifies a superscripted. +const short SUPERSCRIPT = 33; + +// specifies a subscripted. +const short SUBSCRIPT = -33; + +// specifies a hight of superscripted font + const sal_Int8 SUPERSCRIPTHEIGHT = 58; + +// specifies a hight of subscripted font +const sal_Int8 SUBSCRIPTHEIGHT = 58; + +// specifies a hight of normal font +const short NORMALHEIGHT = 100; + +typedef InheritedHelperInterfaceImpl1< ov::XFontBase > VbaFontBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaFontBase : public VbaFontBase_BASE +{ +protected: + css::uno::Reference< css::beans::XPropertySet > mxFont; + css::uno::Reference< css::container::XIndexAccess > mxPalette; + bool mbFormControl; + +public: + VbaFontBase( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::container::XIndexAccess >& xPalette, + const css::uno::Reference< css::beans::XPropertySet >& xPropertySet, + bool bFormControl = false ) throw ( css::uno::RuntimeException ); + virtual ~VbaFontBase();// {} + + // Attributes + virtual css::uno::Any SAL_CALL getSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSize( const css::uno::Any& _size ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getColorIndex() throw (css::uno::RuntimeException); + virtual void SAL_CALL setColorIndex( const css::uno::Any& _colorindex ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getBold() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBold( const css::uno::Any& _bold ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getUnderline() throw (css::uno::RuntimeException) = 0; + virtual void SAL_CALL setUnderline( const css::uno::Any& _underline ) throw (css::uno::RuntimeException) = 0; + virtual css::uno::Any SAL_CALL getStrikethrough() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStrikethrough( const css::uno::Any& _strikethrough ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getShadow() throw (css::uno::RuntimeException); + virtual void SAL_CALL setShadow( const css::uno::Any& _shadow ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getItalic() throw (css::uno::RuntimeException); + virtual void SAL_CALL setItalic( const css::uno::Any& _italic ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getSubscript() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSubscript( const css::uno::Any& _subscript ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getSuperscript() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSuperscript( const css::uno::Any& _superscript ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const css::uno::Any& _name ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getColor() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setColor( const css::uno::Any& _color ) throw (css::uno::RuntimeException) ; +}; + +#endif + diff --git a/vbahelper/inc/vbahelper/vbaglobalbase.hxx b/vbahelper/inc/vbahelper/vbaglobalbase.hxx new file mode 100644 index 000000000000..61aaa1d65657 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbaglobalbase.hxx @@ -0,0 +1,50 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_GLOBAL_BASE_HXX +#define VBA_GLOBAL_BASE_HXX + +#include "vbahelperinterface.hxx" +#include <ooo/vba/XGlobalsBase.hpp> + +typedef InheritedHelperInterfaceImpl1< ov::XGlobalsBase > Globals_BASE; +class VBAHELPER_DLLPUBLIC VbaGlobalsBase : public Globals_BASE +{ +protected: + rtl::OUString msDocCtxName; + + bool hasServiceName( const rtl::OUString& serviceName ); + void init( const css::uno::Sequence< css::beans::PropertyValue >& aInitArgs ); + +public: + VbaGlobalsBase( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName ); + virtual ~VbaGlobalsBase(); + // XMultiServiceFactory + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (css::uno::Exception, css::uno::RuntimeException); + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier, const css::uno::Sequence< css::uno::Any >& Arguments ) throw (css::uno::Exception, css::uno::RuntimeException); + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getAvailableServiceNames( ) throw (css::uno::RuntimeException); +}; +#endif diff --git a/vbahelper/inc/vbahelper/vbahelper.hxx b/vbahelper/inc/vbahelper/vbahelper.hxx new file mode 100644 index 000000000000..bf20541eff1e --- /dev/null +++ b/vbahelper/inc/vbahelper/vbahelper.hxx @@ -0,0 +1,285 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef OOVBAAPI_VBA_HELPER_HXX +#define OOVBAAPI_VBA_HELPER_HXX + +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/beans/XIntrospectionAccess.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/script/BasicErrorException.hpp> +#include <com/sun/star/script/XTypeConverter.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/XUnitConversion.hpp> +#include <basic/basmgr.hxx> +#include <basic/sberrors.hxx> +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/frame/XModel.hpp> +#include <sfx2/dispatch.hxx> +#include <sfx2/objsh.hxx> +#include <sfx2/docfilt.hxx> +#include <sfx2/docfile.hxx> +#include <vcl/pointr.hxx> +#include <memory> +#include "vbaaccesshelper.hxx" + +namespace css = ::com::sun::star; +namespace ooo +{ + namespace vba + { + template < class T > + css::uno::Reference< T > getXSomethingFromArgs( css::uno::Sequence< css::uno::Any > const & args, sal_Int32 nPos, bool bCanBeNull = true ) throw (css::lang::IllegalArgumentException) + { + if ( args.getLength() < ( nPos + 1) ) + throw css::lang::IllegalArgumentException(); + css::uno::Reference< T > aSomething( args[ nPos ], css::uno::UNO_QUERY ); + if ( !bCanBeNull && !aSomething.is() ) + throw css::lang::IllegalArgumentException(); + return aSomething; + } + + class XHelperInterface; + + /** Returns the VBA document implementation object representing the passed UNO document model. */ + VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getVBADocument( const css::uno::Reference< css::frame::XModel >& xModel ); + VBAHELPER_DLLPUBLIC css::uno::Reference< XHelperInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ); + VBAHELPER_DLLPUBLIC SfxObjectShell* getSfxObjShell( const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException); + + css::uno::Reference< css::frame::XModel > getCurrentDoc( const rtl::OUString& sKey ) throw (css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getThisWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentExcelDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::frame::XModel > getCurrentWordDoc( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); + + VBAHELPER_DLLPUBLIC css::uno::Reference< css::beans::XIntrospectionAccess > getIntrospectionAccess( const css::uno::Any& aObject ) throw (css::uno::RuntimeException); + VBAHELPER_DLLPUBLIC css::uno::Reference< css::script::XTypeConverter > getTypeConverter( const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); + + VBAHELPER_DLLPUBLIC void dispatchRequests( const css::uno::Reference< css::frame::XModel>& xModel, const rtl::OUString& aUrl ); + VBAHELPER_DLLPUBLIC void dispatchRequests( const css::uno::Reference< css::frame::XModel>& xModel, const rtl::OUString& aUrl, const css::uno::Sequence< css::beans::PropertyValue >& sProps ); + VBAHELPER_DLLPUBLIC void dispatchExecute(SfxViewShell* pView, sal_uInt16 nSlot, SfxCallMode nCall = SFX_CALLMODE_SYNCHRON ); + VBAHELPER_DLLPUBLIC sal_Int32 OORGBToXLRGB( sal_Int32 ); + VBAHELPER_DLLPUBLIC sal_Int32 XLRGBToOORGB( sal_Int32 ); + VBAHELPER_DLLPUBLIC css::uno::Any OORGBToXLRGB( const css::uno::Any& ); + VBAHELPER_DLLPUBLIC css::uno::Any XLRGBToOORGB( const css::uno::Any& ); + // provide a NULL object that can be passed as variant so that + // the object when passed to IsNull will return true. aNULL + // contains an empty object reference + VBAHELPER_DLLPUBLIC const css::uno::Any& aNULL(); + VBAHELPER_DLLPUBLIC void PrintOutHelper( SfxViewShell* pViewShell, const css::uno::Any& From, const css::uno::Any& To, const css::uno::Any& Copies, const css::uno::Any& Preview, const css::uno::Any& ActivePrinter, const css::uno::Any& PrintToFile, const css::uno::Any& Collate, const css::uno::Any& PrToFileName, sal_Bool bSelection ); + VBAHELPER_DLLPUBLIC void PrintPreviewHelper( const css::uno::Any& EnableChanges, SfxViewShell* ); + + /** Extracts a 32-bit integer value from the passed Any, which may contain an integer or floating-point value. + Throws, if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC sal_Int32 extractIntFromAny( const css::uno::Any& rAny ) throw (css::uno::RuntimeException); + /** Extracts a 32-bit integer value from the passed Any, which may contain an integer or floating-point value. + Returns nDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC sal_Int32 extractIntFromAny( const css::uno::Any& rAny, sal_Int32 nDefault ) throw (css::uno::RuntimeException); + + /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value. + Throws, if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny ) throw (css::uno::RuntimeException); + /** Extracts a boolean value from the passed Any, which may contain a Boolean or an integer or floating-point value. + Returns bDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC bool extractBoolFromAny( const css::uno::Any& rAny, bool bDefault ) throw (css::uno::RuntimeException); + + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + Throws, if the Any is empty or contains an incompatible type. */ + VBAHELPER_DLLPUBLIC ::rtl::OUString extractStringFromAny( const css::uno::Any& rAny, bool bUppercaseBool = false ) throw (css::uno::RuntimeException); + /** Extracts a string from the passed Any, which may contain a Boolean, a value, or a string. + Returns rDefault, if rAny is empty. Throws, if the Any contains an incompatible type. */ + VBAHELPER_DLLPUBLIC ::rtl::OUString extractStringFromAny( const css::uno::Any& rAny, const ::rtl::OUString& rDefault, bool bUppercaseBool = false ) throw (css::uno::RuntimeException); + + VBAHELPER_DLLPUBLIC rtl::OUString getAnyAsString( const css::uno::Any& pvargItem ) throw ( css::uno::RuntimeException ); + VBAHELPER_DLLPUBLIC rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike = false); // needs to be in an uno service ( already this code is duplicated in basic ) + VBAHELPER_DLLPUBLIC double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical); + VBAHELPER_DLLPUBLIC sal_Int32 PointsToHmm( double fPoints ); + VBAHELPER_DLLPUBLIC double HmmToPoints( sal_Int32 nHmm ); + VBAHELPER_DLLPUBLIC sal_Int32 getPointerStyle( const css::uno::Reference< css::frame::XModel >& ); + VBAHELPER_DLLPUBLIC void setCursorHelper( const css::uno::Reference< css::frame::XModel >& xModel, const Pointer& rPointer, sal_Bool bOverWrite ); + VBAHELPER_DLLPUBLIC void setDefaultPropByIntrospection( const css::uno::Any& aObj, const css::uno::Any& aValue ) throw ( css::uno::RuntimeException ); + VBAHELPER_DLLPUBLIC css::uno::Any getPropertyValue( const css::uno::Sequence< css::beans::PropertyValue >& aProp, const rtl::OUString& aName ); + VBAHELPER_DLLPUBLIC sal_Bool setPropertyValue( css::uno::Sequence< css::beans::PropertyValue >& aProp, const rtl::OUString& aName, const css::uno::Any& aValue ); + +class VBAHELPER_DLLPUBLIC Millimeter +{ +//Factor to translate between points and hundredths of millimeters: +private: + double m_nMillimeter; + +public: + Millimeter(); + + Millimeter(double mm); + + void set(double mm); + void setInPoints(double points) ; + void setInHundredthsOfOneMillimeter(double hmm); + double get(); + double getInHundredthsOfOneMillimeter(); + double getInPoints(); + static sal_Int32 getInHundredthsOfOneMillimeter(double points); + static double getInPoints(int _hmm); +}; + +class VBAHELPER_DLLPUBLIC AbstractGeometryAttributes // probably should replace the ShapeHelper below +{ +public: + virtual ~AbstractGeometryAttributes() {} + virtual double getLeft() const = 0; + virtual void setLeft( double ) = 0; + virtual double getTop() const = 0; + virtual void setTop( double ) = 0; + virtual double getHeight() const = 0; + virtual void setHeight( double ) = 0; + virtual double getWidth() const = 0; + virtual void setWidth( double ) = 0; + + virtual double getInnerHeight() const { return 0.0; } + virtual void setInnerHeight( double ) {} + virtual double getInnerWidth() const { return 0.0; } + virtual void setInnerWidth( double ) {} + virtual double getOffsetX() const { return 0.0; } + virtual double getOffsetY() const { return 0.0; } +}; + +namespace msforms { + class XShape; +} + +class VBAHELPER_DLLPUBLIC ShapeHelper +{ +protected: + css::uno::Reference< css::drawing::XShape > xShape; +public: + ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ); + + double getHeight() const; + void setHeight(double _fheight) throw ( css::script::BasicErrorException ); + double getWidth() const; + void setWidth(double _fWidth) throw ( css::script::BasicErrorException ); + double getLeft() const; + void setLeft(double _fLeft); + double getTop() const; + void setTop(double _fTop); +}; + +class VBAHELPER_DLLPUBLIC ConcreteXShapeGeometryAttributes : public AbstractGeometryAttributes +{ + std::auto_ptr< ShapeHelper > m_pShapeHelper; +public: + ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape ); + virtual double getLeft() const; + virtual void setLeft( double nLeft ); + virtual double getTop() const; + virtual void setTop( double nTop ); + virtual double getHeight() const; + virtual void setHeight( double nHeight ); + virtual double getWidth() const; + virtual void setWidth( double nWidth); + virtual ~ConcreteXShapeGeometryAttributes(); +}; + +#define VBA_LEFT "PositionX" +#define VBA_TOP "PositionY" +#define VBA_HEIGHT "Height" +#define VBA_WIDTH "Width" +class VBAHELPER_DLLPUBLIC UserFormGeometryHelper : public AbstractGeometryAttributes +{ +public: + UserFormGeometryHelper( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::awt::XControl >& xControl, + double fOffsetX, double fOffsetY ); + virtual double getLeft() const; + virtual void setLeft( double fLeft ); + virtual double getTop() const; + virtual void setTop( double fTop ); + virtual double getWidth() const; + virtual void setWidth( double fWidth ); + virtual double getHeight() const; + virtual void setHeight( double fHeight ); + virtual double getInnerWidth() const; + virtual void setInnerWidth( double fWidth ); + virtual double getInnerHeight() const; + virtual void setInnerHeight( double fHeight ); + virtual double getOffsetX() const; + virtual double getOffsetY() const; + +private: + double implGetPos( bool bPosY ) const; + void implSetPos( double fPos, bool bPosY ); + double implGetSize( bool bHeight, bool bOuter ) const; + void implSetSize( double fSize, bool bHeight, bool bOuter ); + +private: + css::uno::Reference< css::awt::XWindow > mxWindow; + css::uno::Reference< css::beans::XPropertySet > mxModelProps; + css::uno::Reference< css::awt::XUnitConversion > mxUnitConv; + double mfOffsetX; + double mfOffsetY; + sal_Bool mbDialog; +}; + +class VBAHELPER_DLLPUBLIC ContainerUtilities +{ + +public: + static rtl::OUString getUniqueName( const css::uno::Sequence< ::rtl::OUString >& _slist, const rtl::OUString& _sElementName, const ::rtl::OUString& _sSuffixSeparator); + static rtl::OUString getUniqueName( const css::uno::Sequence< rtl::OUString >& _slist, const rtl::OUString _sElementName, const rtl::OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix ); + + static sal_Int32 FieldInList( const css::uno::Sequence< rtl::OUString >& SearchList, const rtl::OUString& SearchString ); +}; + +// really just a a place holder to ease the porting pain +class VBAHELPER_DLLPUBLIC DebugHelper +{ +public: + static void exception( const rtl::OUString& DetailedMessage, const css::uno::Exception& ex, int err, const rtl::OUString& /*additionalArgument*/ ) throw( css::script::BasicErrorException ); + + static void exception( int err, const rtl::OUString& additionalArgument ) throw( css::script::BasicErrorException ); + + static void exception( css::uno::Exception& ex ) throw( css::script::BasicErrorException ); +}; + } // vba +} // ooo + +namespace ov = ooo::vba; + +#ifdef DEBUG +# define SC_VBA_FIXME(a) OSL_TRACE( a ) +# define SC_VBA_STUB() SC_VBA_FIXME(( "%s - stubbed\n", __FUNCTION__ )) +#else +# define SC_VBA_FIXME(a) +# define SC_VBA_STUB() +#endif + +#endif diff --git a/vbahelper/inc/vbahelper/vbahelperinterface.hxx b/vbahelper/inc/vbahelper/vbahelperinterface.hxx new file mode 100644 index 000000000000..dcd04af3d55f --- /dev/null +++ b/vbahelper/inc/vbahelper/vbahelperinterface.hxx @@ -0,0 +1,193 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef OOVBAAPI_VBA_HELPERINTERFACE_HXX +#define OOVBAAPI_VBA_HELPERINTERFACE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase3.hxx> +#include <ooo/vba/XHelperInterface.hpp> +#include <vbahelper/vbahelper.hxx> +#include <com/sun/star/container/XNameAccess.hpp> + +// use this class when you have an a object like +// interface XAnInterface which contains XHelperInterface in its inheritance hierarchy +// interface XAnInterface +// { +// interface XHelperInterface; +// [attribute, string] name; +// } +// or +// interface XAnInterface : XHelperInterface; +// { +// [attribute, string] name; +// } +// +// then this class can provide a default implementation of XHelperInterface, +// you can use it like this +// typedef InheritedHelperInterfaceImpl< XAnInterface > > AnInterfaceImpl_BASE; +// class AnInterfaceImpl : public AnInterfaceImpl_BASE +// { +// public: +// AnInterface( const Reference< HelperInterface >& xParent ) : AnInterfaceImpl_BASE( xParent ) {} +// // implement XAnInterface methods only, no need to implement the XHelperInterface +// // methods +// virtual void setName( const OUString& ); +// virtual OUString getName(); +// } +// +const ::rtl::OUString sHelperServiceName( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.HelperServiceBase" ) ); + +template< typename Ifc1 > +class InheritedHelperInterfaceImpl : public Ifc1 +{ +protected: + css::uno::WeakReference< ov::XHelperInterface > mxParent; + css::uno::Reference< css::uno::XComponentContext > mxContext; +public: + InheritedHelperInterfaceImpl() {} + InheritedHelperInterfaceImpl( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxContext( xContext ) {} + InheritedHelperInterfaceImpl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : mxParent( xParent ), mxContext( xContext ) {} + virtual rtl::OUString& getServiceImplName() = 0; + virtual css::uno::Sequence<rtl::OUString> getServiceNames() = 0; + + // XHelperInterface Methods + virtual ::sal_Int32 SAL_CALL getCreator() throw (css::script::BasicErrorException, css::uno::RuntimeException) + { + return 0x53756E4F; + } + virtual css::uno::Reference< ov::XHelperInterface > SAL_CALL getParent( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { return mxParent; } + + virtual css::uno::Any SAL_CALL Application( ) throw (css::script::BasicErrorException, css::uno::RuntimeException) { + // The application could certainly be passed around in the context - seems + // to make sense + css::uno::Reference< css::container::XNameAccess > xNameAccess( mxContext, css::uno::UNO_QUERY_THROW ); + return xNameAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Application" ) ) ); + } + + // XServiceInfo Methods + virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (css::uno::RuntimeException) { return getServiceImplName(); } + virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (css::uno::RuntimeException) + { + css::uno::Sequence< rtl::OUString > sServices = getSupportedServiceNames(); + const rtl::OUString* pStart = sServices.getConstArray(); + const rtl::OUString* pEnd = pStart + sServices.getLength(); + for ( ; pStart != pEnd ; ++pStart ) + if ( (*pStart).equals( ServiceName ) ) + return sal_True; + return sal_False; + } + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (css::uno::RuntimeException) + { + css::uno::Sequence< rtl::OUString > aNames = getServiceNames(); + return aNames; + } + }; + +template< typename Ifc1 > +class InheritedHelperInterfaceImpl1 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > +{ + typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper1< Ifc1 > > Base; +public: + InheritedHelperInterfaceImpl1< Ifc1 >() {} + InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} + InheritedHelperInterfaceImpl1< Ifc1 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} +}; + +template< typename Ifc1, typename Ifc2 > +class InheritedHelperInterfaceImpl2 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > > +{ + typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper2< Ifc1, Ifc2 > > Base; +public: + InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >() {} + InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} + InheritedHelperInterfaceImpl2< Ifc1, Ifc2 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} +}; + +template< typename Ifc1, typename Ifc2, typename Ifc3 > +class InheritedHelperInterfaceImpl3 : public InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > > +{ + typedef InheritedHelperInterfaceImpl< ::cppu::WeakImplHelper3< Ifc1, Ifc2, Ifc3 > > Base; +public: + InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >() {} + InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xContext ) {} + InheritedHelperInterfaceImpl3< Ifc1, Ifc2, Ifc3 >( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext ) : Base( xParent, xContext ) {} +}; + +// ============================================================================ + +/** Helper macro to implement the method 'getServiceImplName()' of the + 'ooo.vba.XHelperInterface' interface. Will return the class name as service + implementation name. + */ +#define VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \ +::rtl::OUString& classname::getServiceImplName() \ +{ \ + static ::rtl::OUString saImplName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( #classname ) ); \ + return saImplName; \ +} + +// ---------------------------------------------------------------------------- + +/** Helper macro to implement the method 'getServiceNames()' for a single + service name. + */ +#define VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename ) \ +css::uno::Sequence< ::rtl::OUString > classname::getServiceNames() \ +{ \ + static css::uno::Sequence< ::rtl::OUString > saServiceNames; \ + if( saServiceNames.getLength() == 0 ) \ + { \ + saServiceNames.realloc( 1 ); \ + saServiceNames[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( servicename ) ); \ + } \ + return saServiceNames; \ +} + +// ---------------------------------------------------------------------------- + +/** Helper macro to declare the methods 'getServiceImplName()' and + 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface in a class + declaration. + */ +#define VBAHELPER_DECL_XHELPERINTERFACE \ + virtual ::rtl::OUString& getServiceImplName(); \ + virtual css::uno::Sequence< ::rtl::OUString > getServiceNames(); + +// ---------------------------------------------------------------------------- + +/** Helper macro to implement the methods 'getServiceImplName()' and + 'getServiceNames()' of the 'ooo.vba.XHelperInterface' interface. Will + return the class name as service implementation name. + */ +#define VBAHELPER_IMPL_XHELPERINTERFACE( classname, servicename ) \ +VBAHELPER_IMPL_GETSERVICEIMPLNAME( classname ) \ +VBAHELPER_IMPL_GETSERVICENAMES( classname, servicename ) + +// ============================================================================ + +#endif diff --git a/vbahelper/inc/vbahelper/vbapagesetupbase.hxx b/vbahelper/inc/vbahelper/vbapagesetupbase.hxx new file mode 100644 index 000000000000..09ad2f91d654 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbapagesetupbase.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_PAGESETUPBASE_HXX +#define VBA_PAGESETUPBASE_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/XPageSetupBase.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ooo::vba::XPageSetupBase > VbaPageSetupBase_BASE; + +class VBAHELPER_DLLPUBLIC VbaPageSetupBase : public VbaPageSetupBase_BASE +{ +protected: + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::beans::XPropertySet > mxPageProps; + sal_Int32 mnOrientLandscape; + sal_Int32 mnOrientPortrait; + + VbaPageSetupBase( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw (css::uno::RuntimeException); +public: + virtual ~VbaPageSetupBase(){} + + // Attribute + virtual double SAL_CALL getTopMargin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTopMargin( double margin ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getBottomMargin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBottomMargin( double margin ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getRightMargin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRightMargin( double margin ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getLeftMargin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeftMargin( double margin ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getHeaderMargin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeaderMargin( double margin ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getFooterMargin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setFooterMargin( double margin ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getOrientation() throw (css::uno::RuntimeException); + virtual void SAL_CALL setOrientation( sal_Int32 orientation ) throw (css::uno::RuntimeException); +}; +#endif diff --git a/vbahelper/inc/vbahelper/vbapropvalue.hxx b/vbahelper/inc/vbahelper/vbapropvalue.hxx new file mode 100644 index 000000000000..1efef8f8c05e --- /dev/null +++ b/vbahelper/inc/vbahelper/vbapropvalue.hxx @@ -0,0 +1,57 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PROPVALULE_HXX +#define SC_VBA_PROPVALULE_HXX +#include <ooo/vba/XPropValue.hpp> +#include <cppuhelper/implbase1.hxx> + +#include <vbahelper/vbahelper.hxx> + +typedef ::cppu::WeakImplHelper1< ov::XPropValue > PropValueImpl_BASE; + +class VBAHELPER_DLLPUBLIC PropListener +{ +public: + virtual void setValueEvent( const css::uno::Any& value ) = 0; + virtual css::uno::Any getValueEvent() = 0; +}; + + +class VBAHELPER_DLLPUBLIC ScVbaPropValue : public PropValueImpl_BASE +{ + PropListener* m_pListener; +public: + ScVbaPropValue( PropListener* pListener ); + + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + + rtl::OUString SAL_CALL getDefaultPropertyName() throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + +}; +#endif //SC_VBA_PROPVALULE_HXX diff --git a/vbahelper/inc/vbahelper/vbashape.hxx b/vbahelper/inc/vbahelper/vbashape.hxx new file mode 100644 index 000000000000..87c640db203a --- /dev/null +++ b/vbahelper/inc/vbahelper/vbashape.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_SHAPE_HXX +#define SC_VBA_SHAPE_HXX + +#include <ooo/vba/office/MsoShapeType.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/msforms/XShape.hpp> +#include <ooo/vba/msforms/XLineFormat.hpp> +#include <cppuhelper/implbase2.hxx> + +#include <vbahelper/vbahelperinterface.hxx> + +typedef ::cppu::WeakImplHelper2< ov::msforms::XShape, css::lang::XEventListener > ListeningShape; + +typedef InheritedHelperInterfaceImpl< ListeningShape > ScVbaShape_BASE; + +class VBAHELPER_DLLPUBLIC ScVbaShape : public ScVbaShape_BASE +{ +private: +protected: + std::auto_ptr< ov::ShapeHelper > m_pShapeHelper; + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::drawing::XShapes > m_xShapes; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; + sal_Int32 m_nType; + css::uno::Reference< css::frame::XModel > m_xModel; + css::uno::Any m_aRange; + virtual void addListeners(); + virtual void removeShapeListener() throw( css::uno::RuntimeException ); + virtual void removeShapesListener() throw( css::uno::RuntimeException ); + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +public: + ScVbaShape( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::drawing::XShapes >& xShapes, const css::uno::Reference< css::frame::XModel >& xModel, sal_Int32 nType ) throw ( css::lang::IllegalArgumentException ); + ScVbaShape( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape >& xShape, const css::uno::Reference< css::frame::XModel >& xModel ) throw ( css::lang::IllegalArgumentException ); + virtual ~ScVbaShape(); + css::uno::Any getRange() { return m_aRange; }; + void setRange( css::uno::Any aRange ) { m_aRange = aRange; }; + + static sal_Int32 getType( const css::uno::Reference< css::drawing::XShape > xShape ) throw (css::uno::RuntimeException); + + // Attributes + virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const rtl::OUString& _name ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( double _height ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( double _width ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeft( double _left ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getTop() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTop( double _top ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getZOrderPosition() throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException); + virtual double SAL_CALL getRotation() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRotation( double _rotation ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XLineFormat > SAL_CALL getLine() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XFillFormat > SAL_CALL getFill() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XPictureFormat > SAL_CALL getPictureFormat() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getLockAspectRatio() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLockAspectRatio( ::sal_Bool _lockaspectratio ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getLockAnchor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLockAnchor( ::sal_Bool _lockanchor ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getRelativeHorizontalPosition() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getRelativeVerticalPosition() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (css::uno::RuntimeException); + + // Methods + virtual css::uno::Any SAL_CALL SAL_CALL TextFrame( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL SAL_CALL WrapFormat( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Delete() throw (css::uno::RuntimeException); + virtual void SAL_CALL ZOrder( sal_Int32 ZOrderCmd ) throw (css::uno::RuntimeException); + virtual void SAL_CALL IncrementRotation( double Increment ) throw (css::uno::RuntimeException); + virtual void SAL_CALL IncrementLeft( double Increment ) throw (css::uno::RuntimeException); + virtual void SAL_CALL IncrementTop( double Increment ) throw (css::uno::RuntimeException); + virtual void SAL_CALL ScaleHeight( double Factor, sal_Bool RelativeToOriginalSize, sal_Int32 Scale ) throw (css::uno::RuntimeException); + virtual void SAL_CALL ScaleWidth( double Factor, sal_Bool RelativeToOriginalSize, sal_Int32 Scale ) throw (css::uno::RuntimeException); + // Replace?? + virtual void SAL_CALL Select( const css::uno::Any& Replace ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL ShapeRange( const css::uno::Any& index ) throw ( css::uno::RuntimeException ); + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rEventObject ) throw( css::uno::RuntimeException ); +}; +#endif//SC_VBA_SHAPE_HXX diff --git a/vbahelper/inc/vbahelper/vbashaperange.hxx b/vbahelper/inc/vbahelper/vbashaperange.hxx new file mode 100644 index 000000000000..a4cc35958ef2 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbashaperange.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_SHAPERANGE_HXX +#define SC_VBA_SHAPERANGE_HXX + +#include <com/sun/star/drawing/XShapes.hpp> +#include <ooo/vba/msforms/XShapeRange.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <vbahelper/vbacollectionimpl.hxx> +#include <ooo/vba/msforms/XLineFormat.hpp> +#include <ooo/vba/msforms/XFillFormat.hpp> + +typedef CollTestImplHelper< ov::msforms::XShapeRange > ScVbaShapeRange_BASE; + +class VBAHELPER_DLLPUBLIC ScVbaShapeRange : public ScVbaShapeRange_BASE +{ +private: + css::uno::Reference< css::drawing::XDrawPage > m_xDrawPage; + css::uno::Reference< css::drawing::XShapes > m_xShapes; + sal_Int32 m_nShapeGroupCount; +protected: + css::uno::Reference< css::frame::XModel > m_xModel; + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + css::uno::Reference< css::drawing::XShapes > getShapes() throw (css::uno::RuntimeException) ; +public: + ScVbaShapeRange( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xShapes, const css::uno::Reference< css::drawing::XDrawPage>& xDrawShape, const css::uno::Reference< css::frame::XModel >& xModel ); + + // Methods + virtual void SAL_CALL Select( ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ::ooo::vba::msforms::XShape > SAL_CALL Group() throw (css::uno::RuntimeException); + virtual void SAL_CALL IncrementRotation( double Increment ) throw (css::uno::RuntimeException); + virtual void SAL_CALL IncrementLeft( double Increment ) throw (css::uno::RuntimeException) ; + virtual void SAL_CALL IncrementTop( double Increment ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( double _height ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( double _width ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeft( double _left ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getTop() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTop( double _top ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XLineFormat > SAL_CALL getLine() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XFillFormat > SAL_CALL getFill() throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getLockAspectRatio() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLockAspectRatio( ::sal_Bool _lockaspectratio ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getLockAnchor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLockAnchor( ::sal_Bool _lockanchor ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getRelativeHorizontalPosition() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getRelativeVerticalPosition() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL SAL_CALL TextFrame( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL SAL_CALL WrapFormat( ) throw (css::uno::RuntimeException); + //XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); +}; + +#endif//SC_VBA_SHAPERANGE_HXX diff --git a/vbahelper/inc/vbahelper/vbashapes.hxx b/vbahelper/inc/vbahelper/vbashapes.hxx new file mode 100644 index 000000000000..18e123a9c7f6 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbashapes.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_SHAPES_HXX +#define SC_VBA_SHAPES_HXX + +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <ooo/vba/msforms/XShapes.hpp> + +#include <vbahelper/vbahelperinterface.hxx> + +#include <vbahelper/vbacollectionimpl.hxx> + +typedef CollTestImplHelper< ov::msforms::XShapes > ScVbaShapes_BASE; + +class VBAHELPER_DLLPUBLIC ScVbaShapes : public ScVbaShapes_BASE +{ +private: + css::uno::Reference< css::drawing::XShapes > m_xShapes; + css::uno::Reference< css::drawing::XDrawPage > m_xDrawPage; + sal_Int32 m_nNewShapeCount; + void initBaseCollection(); +protected: + css::uno::Reference< css::frame::XModel > m_xModel; + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + virtual css::uno::Reference< css::container::XIndexAccess > getShapesByArrayIndices( const css::uno::Any& Index ) throw (css::uno::RuntimeException); + css::uno::Reference< css::drawing::XShape > createShape( rtl::OUString service ) throw (css::uno::RuntimeException); + css::uno::Any AddRectangle( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, css::uno::Any aRange ) throw (css::uno::RuntimeException); + css::uno::Any AddEllipse( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, css::uno::Any aRange ) throw (css::uno::RuntimeException); + css::uno::Any AddTextboxInWriter( sal_Int32 _nOrientation, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (css::uno::RuntimeException); + rtl::OUString createName( rtl::OUString sName ); + css::uno::Any AddShape( const rtl::OUString& sService, const rtl::OUString& sName, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (css::uno::RuntimeException); + //TODO helperapi using a writer document + //css::awt::Point calculateTopLeftMargin( css::uno::Reference< ov::XHelperInterface > xDocument ); + +public: + ScVbaShapes( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess > xShapes, const css::uno::Reference< css::frame::XModel >& xModel ); + static void setDefaultShapeProperties( css::uno::Reference< css::drawing::XShape > xShape ) throw (css::uno::RuntimeException); + static void setShape_NameProperty( css::uno::Reference< css::drawing::XShape > xShape, rtl::OUString sName ); + //XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + virtual void SAL_CALL SelectAll() throw (css::uno::RuntimeException); + //helper::calc + virtual css::uno::Any SAL_CALL AddLine( sal_Int32 StartX, sal_Int32 StartY, sal_Int32 endX, sal_Int32 endY ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL AddShape( sal_Int32 _nType, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL AddTextbox( sal_Int32 _nOrientation, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XShapeRange > SAL_CALL Range( const css::uno::Any& shapes ) throw (css::uno::RuntimeException); + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index1, const css::uno::Any& Index2 ) throw (css::uno::RuntimeException); +}; + +#endif//SC_VBA_SHAPES_HXX diff --git a/vbahelper/inc/vbahelper/vbatextframe.hxx b/vbahelper/inc/vbahelper/vbatextframe.hxx new file mode 100644 index 000000000000..91bc4525b973 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbatextframe.hxx @@ -0,0 +1,67 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_TEXTFRAME_HXX +#define VBA_TEXTFRAME_HXX +#include <ooo/vba/msforms/XTextFrame.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::msforms::XTextFrame > VbaTextFrame_BASE; + +class VBAHELPER_DLLPUBLIC VbaTextFrame : public VbaTextFrame_BASE +{ +protected: + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + virtual void setAsMSObehavior(); + sal_Int32 getMargin( rtl::OUString sMarginType ); + void setMargin( rtl::OUString sMarginType, float fMargin ); +public: + VbaTextFrame( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext , css::uno::Reference< css::drawing::XShape > xShape); + virtual ~VbaTextFrame() {} + // Attributes + virtual sal_Bool SAL_CALL getAutoSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoSize( sal_Bool _autosize ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getMarginBottom() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMarginBottom( float _marginbottom ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getMarginTop() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMarginTop( float _margintop ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getMarginLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMarginLeft( float _marginleft ) throw (css::uno::RuntimeException); + virtual float SAL_CALL getMarginRight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMarginRight( float _marginright ) throw (css::uno::RuntimeException); + + // Methods + virtual css::uno::Any SAL_CALL Characters( ) throw (css::uno::RuntimeException); + +}; + +#endif//SC_VBA_TEXTFRAME_HXX diff --git a/vbahelper/inc/vbahelper/vbawindowbase.hxx b/vbahelper/inc/vbahelper/vbawindowbase.hxx new file mode 100644 index 000000000000..e9f1d40e4bd4 --- /dev/null +++ b/vbahelper/inc/vbahelper/vbawindowbase.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBA_WINDOWBASE_HXX +#define VBA_WINDOWBASE_HXX + +#include <ooo/vba/XWindowBase.hpp> +#include <com/sun/star/awt/XWindow2.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::XWindowBase > WindowBaseImpl_BASE; + +class VBAHELPER_DLLPUBLIC VbaWindowBase : public WindowBaseImpl_BASE +{ +public: + VbaWindowBase( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const css::uno::Reference< css::frame::XController >& xController ) + throw (css::uno::RuntimeException); + VbaWindowBase( + css::uno::Sequence< css::uno::Any > const& aArgs, + css::uno::Reference< css::uno::XComponentContext > const& xContext ) + throw (css::uno::RuntimeException); + + // XWindowBase + virtual sal_Int32 SAL_CALL getHeight() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setHeight( sal_Int32 _height ) throw (css::uno::RuntimeException) ; + virtual sal_Int32 SAL_CALL getLeft() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setLeft( sal_Int32 _left ) throw (css::uno::RuntimeException) ; + virtual sal_Int32 SAL_CALL getTop() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setTop( sal_Int32 _top ) throw (css::uno::RuntimeException) ; + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getWidth() throw (css::uno::RuntimeException) ; + virtual void SAL_CALL setWidth( sal_Int32 _width ) throw (css::uno::RuntimeException) ; + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +protected: + css::uno::Reference< css::frame::XController > getController() throw (css::uno::RuntimeException); + css::uno::Reference< css::awt::XWindow > getWindow() throw (css::uno::RuntimeException); + css::uno::Reference< css::awt::XWindow2 > getWindow2() throw (css::uno::RuntimeException); + + css::uno::Reference< css::frame::XModel > m_xModel; + +private: + void construct( const css::uno::Reference< css::frame::XController >& xController ) throw (css::uno::RuntimeException); + + css::uno::WeakReference< css::frame::XController > m_xController; + css::uno::WeakReference< css::awt::XWindow > m_xWindow; +}; + +#endif //VBA_WINDOWBASE_HXX diff --git a/vbahelper/inc/vbahelper/weakreference.hxx b/vbahelper/inc/vbahelper/weakreference.hxx new file mode 100755 index 000000000000..661f3bc5d73e --- /dev/null +++ b/vbahelper/inc/vbahelper/weakreference.hxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBAHELPER_WEAKREFERENCE_HXX +#define VBAHELPER_WEAKREFERENCE_HXX + +#include <cppuhelper/weakref.hxx> +#include <rtl/ref.hxx> + +namespace vbahelper { + +// ============================================================================ + +/** A weak reference holding any UNO implementation object. + + The held object must implement the ::com::sun::star::uno::XWeak interface. + + In difference to the ::com::sun::star::uno::WeakReference<> implementation + from cppuhelper/weakref.hxx, the class type of this weak reference is not + restricted to UNO interface types, but can be used for any C++ class type + implementing the XWeak interface somehow (e.g. ::cppu::WeakImplHelperN<>, + ::cppu::ImplInheritanceHelperN<>, etc.). + */ +template< typename ObjectType > +class WeakReference +{ +public: + /** Default constructor. Creates an empty weak reference. + */ + inline explicit WeakReference() SAL_THROW( () ) : mpObject( 0 ) {} + + /** Initializes this weak reference with the passed reference to an object. + */ + inline explicit WeakReference( const ::rtl::Reference< ObjectType >& rxObject ) SAL_THROW( () ) : + mxWeakRef( rxObject.get() ), mpObject( rxObject.get() ) {} + + /** Releases this weak reference and takes over the passed reference. + */ + inline WeakReference& SAL_CALL operator=( const ::rtl::Reference< ObjectType >& rxObject ) SAL_THROW( () ) + { + mxWeakRef = ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak >( rxObject.get() ); + mpObject = rxObject.get(); + return *this; + } + + /** Gets an RTL reference to the referenced object. + + @return Reference or null, if the weakly referenced object is gone. + */ + inline SAL_CALL operator ::rtl::Reference< ObjectType >() SAL_THROW( () ) + { + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XWeak > xRef = mxWeakRef; + ::rtl::Reference< ObjectType > xObject; + if( xRef.is() ) + xObject = mpObject; + else + mpObject = 0; + return xObject; + } + +private: + ::com::sun::star::uno::WeakReference< ::com::sun::star::uno::XWeak > mxWeakRef; + ObjectType* mpObject; +}; + +// ============================================================================ + +} // namespace vbahelper + +#endif diff --git a/vbahelper/prj/build.lst b/vbahelper/prj/build.lst new file mode 100644 index 000000000000..be2e516de360 --- /dev/null +++ b/vbahelper/prj/build.lst @@ -0,0 +1,3 @@ +vba vbahelper : oovbaapi offuh basic sfx2 svx filter cppuhelper vcl comphelper svtools tools sal unotools LIBXSLT:libxslt NULL +vba vbahelper usr1 - all vba_mkout NULL +vba vbahelper\prj nmake - all vba_prj NULL diff --git a/vbahelper/prj/d.lst b/vbahelper/prj/d.lst new file mode 100644 index 000000000000..e69de29bb2d1 --- /dev/null +++ b/vbahelper/prj/d.lst diff --git a/vbahelper/prj/makefile.mk b/vbahelper/prj/makefile.mk new file mode 100755 index 000000000000..e312a7ccab65 --- /dev/null +++ b/vbahelper/prj/makefile.mk @@ -0,0 +1,40 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ=.. +TARGET=prj + +.INCLUDE : settings.mk + +.IF "$(VERBOSE)"!="" +VERBOSEFLAG := +.ELSE +VERBOSEFLAG := -s +.ENDIF + +all: + cd $(PRJ) && $(GNUMAKE) $(VERBOSEFLAG) -r -j$(MAXPROCESS) $(gb_MAKETARGET) && $(GNUMAKE) $(VERBOSEFLAG) -r deliverlog diff --git a/vbahelper/source/msforms/service.cxx b/vbahelper/source/msforms/service.cxx new file mode 100644 index 000000000000..152517be3958 --- /dev/null +++ b/vbahelper/source/msforms/service.cxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "cppuhelper/implementationentry.hxx" +#include "com/sun/star/lang/XMultiServiceFactory.hpp" +#include "com/sun/star/registry/XRegistryKey.hpp" +#include "comphelper/servicedecl.hxx" + +// ============================================================================= +// component exports +// ============================================================================= +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +namespace sdecl = comphelper::service_decl; + +// reference service helper(s) +namespace controlprovider +{ +extern sdecl::ServiceDecl const serviceDecl; +} + +namespace userform +{ +extern sdecl::ServiceDecl const serviceDecl; +} + +extern "C" +{ + SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ ) + { + OSL_TRACE("In component_getImplementationEnv"); + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; + } + + SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const sal_Char * pImplName, lang::XMultiServiceFactory * pServiceManager, + registry::XRegistryKey * pRegistryKey ) + { + OSL_TRACE("In component_getFactory for %s", pImplName ); + void* pRet = component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, controlprovider::serviceDecl, userform::serviceDecl ); + OSL_TRACE("Ret is 0x%x", pRet); + return pRet; + } +} diff --git a/vbahelper/source/msforms/vbabutton.cxx b/vbahelper/source/msforms/vbabutton.cxx new file mode 100644 index 000000000000..775a05cbb5b5 --- /dev/null +++ b/vbahelper/source/msforms/vbabutton.cxx @@ -0,0 +1,122 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbabutton.hxx" +#include "vbanewfont.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); +ScVbaButton::ScVbaButton( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ButtonImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +// Attributes +rtl::OUString SAL_CALL +ScVbaButton::getCaption() throw (css::uno::RuntimeException) +{ + rtl::OUString Label; + m_xProps->getPropertyValue( LABEL ) >>= Label; + return Label; +} + +void SAL_CALL +ScVbaButton::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); +} + +sal_Bool SAL_CALL ScVbaButton::getAutoSize() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaButton::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaButton::getCancel() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaButton::setCancel( sal_Bool /*bCancel*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaButton::getDefault() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaButton::setDefault( sal_Bool /*bDefault*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaButton::getBackColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaButton::setBackColor( sal_Int32 /*nBackColor*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaButton::getForeColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaButton::setForeColor( sal_Int32 /*nForeColor*/ ) throw (uno::RuntimeException) +{ +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaButton::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaButton::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaButton") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaButton::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.Button" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbabutton.hxx b/vbahelper/source/msforms/vbabutton.hxx new file mode 100644 index 000000000000..93a55e1bf73a --- /dev/null +++ b/vbahelper/source/msforms/vbabutton.hxx @@ -0,0 +1,59 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_BUTTON_HXX +#define SC_VBA_BUTTON_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XCommandButton.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XCommandButton > ButtonImpl_BASE; + +class ScVbaButton : public ButtonImpl_BASE +{ +public: + ScVbaButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + // Attributes + virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getAutoSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoSize( sal_Bool bAutoSize ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getCancel() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCancel( sal_Bool bCancel ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getDefault() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDefault( sal_Bool bDefault ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBackColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBackColor( sal_Int32 nBackColor ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getForeColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setForeColor( sal_Int32 nForeColor ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif //SC_VBA_BUTTON_HXX diff --git a/vbahelper/source/msforms/vbacheckbox.cxx b/vbahelper/source/msforms/vbacheckbox.cxx new file mode 100644 index 000000000000..329586cf6b27 --- /dev/null +++ b/vbahelper/source/msforms/vbacheckbox.cxx @@ -0,0 +1,111 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbacheckbox.hxx" +#include "vbanewfont.hxx" +#include <vbahelper/helperdecl.hxx> + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); +const static rtl::OUString STATE( RTL_CONSTASCII_USTRINGPARAM("State") ); +ScVbaCheckbox::ScVbaCheckbox( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ) : CheckBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +// Attributes +rtl::OUString SAL_CALL +ScVbaCheckbox::getCaption() throw (css::uno::RuntimeException) +{ + rtl::OUString Label; + m_xProps->getPropertyValue( LABEL ) >>= Label; + return Label; +} + +void SAL_CALL +ScVbaCheckbox::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); +} + +uno::Any SAL_CALL +ScVbaCheckbox::getValue() throw (css::uno::RuntimeException) +{ + sal_Int16 nValue = -1; + m_xProps->getPropertyValue( STATE ) >>= nValue; + if( nValue != 0 ) + nValue = -1; +// return uno::makeAny( nValue ); +// I must be missing something MSO says value should be -1 if selected, 0 if not +// selected + return uno::makeAny( ( nValue == -1 ) ? sal_True : sal_False ); +} + +void SAL_CALL +ScVbaCheckbox::setValue( const uno::Any& _value ) throw (css::uno::RuntimeException) +{ + sal_Int16 nValue = 0; + sal_Bool bValue = false; + if( _value >>= nValue ) + { + if( nValue == -1) + nValue = 1; + } + else if ( _value >>= bValue ) + { + if ( bValue ) + nValue = 1; + } + m_xProps->setPropertyValue( STATE, uno::makeAny( nValue ) ); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaCheckbox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaCheckbox::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCheckbox") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaCheckbox::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.CheckBox" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/msforms/vbacheckbox.hxx b/vbahelper/source/msforms/vbacheckbox.hxx new file mode 100644 index 000000000000..59e4d7e75e49 --- /dev/null +++ b/vbahelper/source/msforms/vbacheckbox.hxx @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CHECKBOX_HXX +#define SC_VBA_CHECKBOX_HXX +#include <cppuhelper/implbase2.hxx> +#include <ooo/vba/msforms/XCheckBox.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XCheckBox, css::script::XDefaultProperty > CheckBoxImpl_BASE; + +class ScVbaCheckbox : public CheckBoxImpl_BASE +{ +public: + ScVbaCheckbox( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + // Attributes + virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif //SC_VBA_CHECKBOX_HXX diff --git a/vbahelper/source/msforms/vbacombobox.cxx b/vbahelper/source/msforms/vbacombobox.cxx new file mode 100644 index 000000000000..9a75fa5cbaa1 --- /dev/null +++ b/vbahelper/source/msforms/vbacombobox.cxx @@ -0,0 +1,260 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbacombobox.hxx" +#include "vbanewfont.hxx" +#include <ooo/vba/msforms/fmStyle.hpp> +#include <ooo/vba/msforms/fmDropButtonStyle.hpp> +#include <ooo/vba/msforms/fmDragBehavior.hpp> +#include <ooo/vba/msforms/fmEnterFieldBehavior.hpp> +#include <ooo/vba/msforms/fmListStyle.hpp> +#include <ooo/vba/msforms/fmTextAlign.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + + +//SelectedItems list of integer indexes +//StringItemList list of items + +const static rtl::OUString TEXT( RTL_CONSTASCII_USTRINGPARAM("Text") ); +const static rtl::OUString SELECTEDITEMS( RTL_CONSTASCII_USTRINGPARAM("SelectedItems") ); +const static rtl::OUString ITEMS( RTL_CONSTASCII_USTRINGPARAM("StringItemList") ); +const static rtl::OUString CONTROLSOURCEPROP( RTL_CONSTASCII_USTRINGPARAM("DataFieldProperty") ); + +ScVbaComboBox::ScVbaComboBox( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper, bool bDialogType ) : ComboBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), mbDialogType( bDialogType ) +{ + mpListHelper.reset( new ListControlHelper( m_xProps ) ); + try + { + // grab the default value property name + m_xProps->getPropertyValue( CONTROLSOURCEPROP ) >>= sSourceName; + } + catch( uno::Exception& ) + { + } + if( sSourceName.getLength() == 0 ) + sSourceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ); +} + +// Attributes + + +// Value, [read] e.g. getValue returns the value of ooo Text propery e.g. the value in +// the drop down +uno::Any SAL_CALL +ScVbaComboBox::getValue() throw (uno::RuntimeException) +{ + return m_xProps->getPropertyValue( sSourceName ); +} + +void SAL_CALL +ScVbaComboBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException) +{ + sal_Int16 nIndex = 0; + if( _value >>= nIndex ) + { + uno::Sequence< rtl::OUString > sItems; + m_xProps->getPropertyValue( ITEMS ) >>= sItems; + if( ( nIndex >= 0 ) && ( sItems.getLength() > nIndex ) ) + { + rtl::OUString sText = sItems[ nIndex ]; + m_xProps->setPropertyValue( TEXT, uno::makeAny( sText ) ); + } + } +} + +uno::Any SAL_CALL +ScVbaComboBox::getListIndex() throw (uno::RuntimeException) +{ + uno::Sequence< rtl::OUString > sItems; + m_xProps->getPropertyValue( ITEMS ) >>= sItems; + // should really return the item that has focus regardless of + // it been selected + if ( sItems.getLength() > 0 ) + { + rtl::OUString sText = getText(); + sal_Int32 nLen = sItems.getLength(); + for ( sal_Int32 index = 0; sText.getLength() && index < nLen; ++index ) + { + if ( sItems[ index ].equals( sText ) ) + { + OSL_TRACE("getListIndex returning %d", index ); + return uno::makeAny( index ); + } + + } + } + OSL_TRACE("getListIndex returning %d", -1 ); + return uno::makeAny( sal_Int32( -1 ) ); +} + +// Value, [write]e.g. setValue sets the value in the drop down, and if the value is one +// of the values in the list then the selection is also set +void SAL_CALL +ScVbaComboBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException) +{ + // booleans are converted to uppercase strings + m_xProps->setPropertyValue( sSourceName, uno::Any( extractStringFromAny( _value, ::rtl::OUString(), true ) ) ); +} + +// see Value + +::rtl::OUString SAL_CALL +ScVbaComboBox::getText() throw (uno::RuntimeException) +{ + rtl::OUString result; + getValue() >>= result; + return result; +} + +void SAL_CALL +ScVbaComboBox::setText( const ::rtl::OUString& _text ) throw (uno::RuntimeException) +{ + setValue( uno::makeAny( _text ) ); // seems the same +} + +// Methods +void SAL_CALL +ScVbaComboBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException) +{ + mpListHelper->AddItem( pvargItem, pvargIndex ); +} + +void SAL_CALL +ScVbaComboBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException) +{ + mpListHelper->removeItem( index ); +} + +void SAL_CALL +ScVbaComboBox::Clear( ) throw (uno::RuntimeException) +{ + mpListHelper->Clear(); +} + +void SAL_CALL +ScVbaComboBox::setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException) +{ + ScVbaControl::setRowSource( _rowsource ); + mpListHelper->setRowSource( _rowsource ); +} + +sal_Int32 SAL_CALL +ScVbaComboBox::getListCount() throw (uno::RuntimeException) +{ + return mpListHelper->getListCount(); +} + +uno::Any SAL_CALL +ScVbaComboBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException) +{ + return mpListHelper->List( pvargIndex, pvarColumn ); +} + +sal_Int32 SAL_CALL ScVbaComboBox::getStyle() throw (uno::RuntimeException) +{ + return msforms::fmStyle::fmStyleDropDownCombo; +} + +void SAL_CALL ScVbaComboBox::setStyle( sal_Int32 /*nStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getDropButtonStyle() throw (uno::RuntimeException) +{ + return msforms::fmDropButtonStyle::fmDropButtonStyleArrow; +} + +void SAL_CALL ScVbaComboBox::setDropButtonStyle( sal_Int32 /*nDropButtonStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getDragBehavior() throw (uno::RuntimeException) +{ + return msforms::fmDragBehavior::fmDragBehaviorDisabled; +} + +void SAL_CALL ScVbaComboBox::setDragBehavior( sal_Int32 /*nDragBehavior*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getEnterFieldBehavior() throw (uno::RuntimeException) +{ + return msforms::fmEnterFieldBehavior::fmEnterFieldBehaviorSelectAll; +} + +void SAL_CALL ScVbaComboBox::setEnterFieldBehavior( sal_Int32 /*nEnterFieldBehavior*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getListStyle() throw (uno::RuntimeException) +{ + return msforms::fmListStyle::fmListStylePlain; +} + +void SAL_CALL ScVbaComboBox::setListStyle( sal_Int32 /*nListStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getTextAlign() throw (uno::RuntimeException) +{ + return msforms::fmTextAlign::fmTextAlignLeft; +} + +void SAL_CALL ScVbaComboBox::setTextAlign( sal_Int32 /*nTextAlign*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaComboBox::getTextLength() throw (uno::RuntimeException) +{ + return getText().getLength(); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaComboBox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaComboBox::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaComboBox") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaComboBox::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ComboBox" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbacombobox.hxx b/vbahelper/source/msforms/vbacombobox.hxx new file mode 100644 index 000000000000..c73b617a743b --- /dev/null +++ b/vbahelper/source/msforms/vbacombobox.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_COMBOBOX_HXX +#define SC_VBA_COMBOBOX_HXX +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/script/XDefaultProperty.hpp> +#include <ooo/vba/msforms/XComboBox.hpp> +#include <comphelper/proparrhlp.hxx> +#include <comphelper/propertycontainer.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include "vbacontrol.hxx" +#include "vbalistcontrolhelper.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper2<ScVbaControl, ov::msforms::XComboBox, css::script::XDefaultProperty > ComboBoxImpl_BASE; +class ScVbaComboBox : public ComboBoxImpl_BASE +{ + std::auto_ptr< ListControlHelper > mpListHelper; + rtl::OUString sSourceName; + rtl::OUString msDftPropName; + bool mbDialogType; + +public: + ScVbaComboBox( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper, bool bDialogType = false ); + + // Attributes + virtual css::uno::Any SAL_CALL getListIndex() throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getListCount() throw (css::uno::RuntimeException); + virtual void SAL_CALL setListIndex( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); + virtual void SAL_CALL setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStyle( sal_Int32 nStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getDropButtonStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDropButtonStyle( sal_Int32 nDropButtonStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getDragBehavior() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDragBehavior( sal_Int32 nDragBehavior ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getEnterFieldBehavior() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnterFieldBehavior( sal_Int32 nEnterFieldBehavior ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getListStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setListStyle( sal_Int32 nListStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTextAlign() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTextAlign( sal_Int32 nTextAlign ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTextLength() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL AddItem( const css::uno::Any& pvargItem, const css::uno::Any& pvargIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL removeItem( const css::uno::Any& index ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Clear( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL List( const css::uno::Any& pvargIndex, const css::uno::Any& pvarColumn ) throw (css::uno::RuntimeException); + // XControl + virtual void SAL_CALL setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException); + + // XDefaultProperty + ::rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif // diff --git a/vbahelper/source/msforms/vbacontrol.cxx b/vbahelper/source/msforms/vbacontrol.cxx new file mode 100644 index 000000000000..780191885049 --- /dev/null +++ b/vbahelper/source/msforms/vbacontrol.cxx @@ -0,0 +1,550 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/form/FormComponentType.hpp> +#include <com/sun/star/awt/XControlModel.hpp> +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XWindow2.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/view/XControlAccess.hpp> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/form/binding/XBindableValue.hpp> +#include <com/sun/star/form/binding/XListEntrySink.hpp> +#include <com/sun/star/table/CellAddress.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> +#include <ooo/vba/XControlProvider.hpp> +#ifdef VBA_OOBUILD_HACK +#include <svtools/bindablecontrolhelper.hxx> +#endif +#include "vbacontrol.hxx" +#include "vbacombobox.hxx" +#include "vbabutton.hxx" +#include "vbalabel.hxx" +#include "vbatextbox.hxx" +#include "vbaradiobutton.hxx" +#include "vbalistbox.hxx" +#include "vbatogglebutton.hxx" +#include "vbacheckbox.hxx" +#include "vbaframe.hxx" +#include "vbascrollbar.hxx" +#include "vbaprogressbar.hxx" +#include "vbamultipage.hxx" +#include "vbaspinbutton.hxx" +#include "vbasystemaxcontrol.hxx" +#include "vbaimage.hxx" +#include <vbahelper/helperdecl.hxx> + + +using namespace com::sun::star; +using namespace ooo::vba; + +uno::Reference< css::awt::XWindowPeer > +ScVbaControl::getWindowPeer() throw (uno::RuntimeException) +{ + uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ); + + uno::Reference< awt::XControlModel > xControlModel; + uno::Reference< css::awt::XWindowPeer > xWinPeer; + if ( !xControlShape.is() ) + { + // would seem to be a Userform control + uno::Reference< awt::XControl > xControl( m_xControl, uno::UNO_QUERY_THROW ); + xWinPeer = xControl->getPeer(); + return xWinPeer; + } + // form control + xControlModel.set( xControlShape->getControl(), uno::UNO_QUERY_THROW ); + + uno::Reference< view::XControlAccess > xControlAccess( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + try + { + uno::Reference< awt::XControl > xControl( xControlAccess->getControl( xControlModel ), uno::UNO_QUERY ); + xWinPeer = xControl->getPeer(); + } + catch( uno::Exception ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "The Control does not exsit" ), + uno::Reference< uno::XInterface >() ); + } + return xWinPeer; +} + +//ScVbaControlListener +class ScVbaControlListener: public cppu::WeakImplHelper1< lang::XEventListener > +{ +private: + ScVbaControl *pControl; +public: + ScVbaControlListener( ScVbaControl *pTmpControl ); + virtual ~ScVbaControlListener(); + virtual void SAL_CALL disposing( const lang::EventObject& rEventObject ) throw( uno::RuntimeException ); +}; + +ScVbaControlListener::ScVbaControlListener( ScVbaControl *pTmpControl ): pControl( pTmpControl ) +{ +} + +ScVbaControlListener::~ScVbaControlListener() +{ +} + +void SAL_CALL +ScVbaControlListener::disposing( const lang::EventObject& ) throw( uno::RuntimeException ) +{ + if( pControl ) + { + pControl->removeResouce(); + pControl = NULL; + } +} + +//ScVbaControl + +ScVbaControl::ScVbaControl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< ::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ControlImpl_BASE( xParent, xContext ), m_xControl( xControl ), m_xModel( xModel ) +{ + //add listener + m_xEventListener.set( new ScVbaControlListener( this ) ); + setGeometryHelper( pGeomHelper ); + uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW ); + xComponent->addEventListener( m_xEventListener ); + + //init m_xProps + uno::Reference< drawing::XControlShape > xControlShape( m_xControl, uno::UNO_QUERY ) ; + uno::Reference< awt::XControl> xUserFormControl( m_xControl, uno::UNO_QUERY ) ; + if ( xControlShape.is() ) // form control + m_xProps.set( xControlShape->getControl(), uno::UNO_QUERY_THROW ); + else if ( xUserFormControl.is() ) // userform control + m_xProps.set( xUserFormControl->getModel(), uno::UNO_QUERY_THROW ); +} + +ScVbaControl::~ScVbaControl() +{ + if( m_xControl.is() ) +{ + uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW ); + xComponent->removeEventListener( m_xEventListener ); +} +} + +void +ScVbaControl::setGeometryHelper( AbstractGeometryAttributes* pHelper ) +{ + mpGeometryHelper.reset( pHelper ); +} + +void ScVbaControl::removeResouce() throw( uno::RuntimeException ) +{ + uno::Reference< lang::XComponent > xComponent( m_xControl, uno::UNO_QUERY_THROW ); + xComponent->removeEventListener( m_xEventListener ); + m_xControl= NULL; + m_xProps = NULL; +} + +//In design model has different behavior +sal_Bool SAL_CALL ScVbaControl::getEnabled() throw (uno::RuntimeException) +{ + uno::Any aValue = m_xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ) ); + sal_Bool bRet = false; + aValue >>= bRet; + return bRet; +} + +void SAL_CALL ScVbaControl::setEnabled( sal_Bool bVisible ) throw (uno::RuntimeException) +{ + uno::Any aValue( bVisible ); + m_xProps->setPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Enabled" ) ), aValue); + +} + +sal_Bool SAL_CALL ScVbaControl::getVisible() throw (uno::RuntimeException) +{ + sal_Bool bVisible( sal_True ); + m_xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) )) >>= bVisible; + return bVisible; +} + +void SAL_CALL ScVbaControl::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException) +{ + uno::Any aValue( bVisible ); + m_xProps->setPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "EnableVisible" ) ), aValue); +} +double SAL_CALL ScVbaControl::getHeight() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getHeight(); +} +void SAL_CALL ScVbaControl::setHeight( double _height ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setHeight( _height ); +} + +double SAL_CALL ScVbaControl::getWidth() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getWidth(); +} +void SAL_CALL ScVbaControl::setWidth( double _width ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setWidth( _width ); +} + +double SAL_CALL +ScVbaControl::getLeft() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getLeft(); +} + +void SAL_CALL +ScVbaControl::setLeft( double _left ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setLeft( _left ); +} + +double SAL_CALL +ScVbaControl::getTop() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getTop(); +} + +void SAL_CALL +ScVbaControl::setTop( double _top ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setTop( _top ); +} + +uno::Reference< uno::XInterface > SAL_CALL +ScVbaControl::getObject() throw (uno::RuntimeException) +{ + uno::Reference< msforms::XControl > xRet( this ); + return xRet; +} + +void SAL_CALL ScVbaControl::SetFocus() throw (uno::RuntimeException) +{ + uno::Reference< awt::XWindow > xWin( m_xControl, uno::UNO_QUERY_THROW ); + xWin->setFocus(); +} + +void SAL_CALL ScVbaControl::Move( double Left, double Top, const uno::Any& Width, const uno::Any& Height ) + throw ( uno::RuntimeException ) +{ + double nWidth = 0.0; + double nHeight = 0.0; + + setLeft( Left ); + setTop( Top ); + + if ( Width >>= nWidth ) + setWidth( nWidth ); + + if ( Height >>= nHeight ) + setHeight( nHeight ); +} + +rtl::OUString SAL_CALL +ScVbaControl::getControlSource() throw (uno::RuntimeException) +{ +// #FIXME I *hate* having these upstream differences +// but this is necessary until I manage to upstream other +// dependant parts +#ifdef VBA_OOBUILD_HACK + rtl::OUString sControlSource; + uno::Reference< form::binding::XBindableValue > xBindable( m_xProps, uno::UNO_QUERY ); + if ( xBindable.is() ) + { + try + { + uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellAddressConversion" ))), uno::UNO_QUERY ); + uno::Reference< beans::XPropertySet > xProps( xBindable->getValueBinding(), uno::UNO_QUERY_THROW ); + table::CellAddress aAddress; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BoundCell") ) ) >>= aAddress; + xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address") ), uno::makeAny( aAddress ) ); + xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sControlSource; + } + catch( uno::Exception& ) + { + } + } + return sControlSource; +#else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getControlSource not supported") ), uno::Reference< uno::XInterface >()); // not supported +#endif +} + +void SAL_CALL +ScVbaControl::setControlSource( const rtl::OUString& _controlsource ) throw (uno::RuntimeException) +{ +#ifdef VBA_OOBUILD_HACK + rtl::OUString sEmpty; + svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, _controlsource, sEmpty ); +#else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setControlSource not supported ") ).concat( _controlsource ), uno::Reference< uno::XInterface >()); // not supported +#endif +} + +rtl::OUString SAL_CALL +ScVbaControl::getRowSource() throw (uno::RuntimeException) +{ +#ifdef VBA_OOBUILD_HACK + rtl::OUString sRowSource; + uno::Reference< form::binding::XListEntrySink > xListSink( m_xProps, uno::UNO_QUERY ); + if ( xListSink.is() ) + { + try + { + uno::Reference< lang::XMultiServiceFactory > xFac( m_xModel, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xConvertor( xFac->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.table.CellRangeAddressConversion" ))), uno::UNO_QUERY ); + + uno::Reference< beans::XPropertySet > xProps( xListSink->getListEntrySource(), uno::UNO_QUERY_THROW ); + table::CellRangeAddress aAddress; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CellRange") ) ) >>= aAddress; + xConvertor->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Address")), uno::makeAny( aAddress ) ); + xConvertor->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("XL_A1_Representation") ) ) >>= sRowSource; + } + catch( uno::Exception& ) + { + } + } + return sRowSource; +#else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("getRowSource not supported") ), uno::Reference< uno::XInterface >()); // not supported +#endif +} + +void SAL_CALL +ScVbaControl::setRowSource( const rtl::OUString& _rowsource ) throw (uno::RuntimeException) +{ +#ifdef VBA_OOBUILD_HACK + rtl::OUString sEmpty; + svt::BindableControlHelper::ApplyListSourceAndBindableData( m_xModel, m_xProps, sEmpty, _rowsource ); +#else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("setRowSource not supported ") ).concat( _rowsource ), uno::Reference< uno::XInterface >()); // not supported +#endif +} + +rtl::OUString SAL_CALL +ScVbaControl::getName() throw (uno::RuntimeException) +{ + rtl::OUString sName; + m_xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sName; + return sName; + +} + +void SAL_CALL +ScVbaControl::setName( const rtl::OUString& _name ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ), uno::makeAny( _name ) ); + } + +rtl::OUString SAL_CALL +ScVbaControl::getControlTipText() throw (css::uno::RuntimeException) +{ + rtl::OUString sName; + m_xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ) ) >>= sName; + return sName; +} + +void SAL_CALL +ScVbaControl::setControlTipText( const rtl::OUString& rsToolTip ) throw (css::uno::RuntimeException) +{ + m_xProps->setPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) ), uno::makeAny( rsToolTip ) ); +} + +::rtl::OUString SAL_CALL ScVbaControl::getTag() + throw (css::uno::RuntimeException) +{ + return m_aControlTag; +} + +void SAL_CALL ScVbaControl::setTag( const ::rtl::OUString& aTag ) + throw (css::uno::RuntimeException) +{ + m_aControlTag = aTag; +} + +sal_Int32 SAL_CALL ScVbaControl::getTabIndex() throw (uno::RuntimeException) +{ + return 1; +} + +void SAL_CALL ScVbaControl::setTabIndex( sal_Int32 /*nTabIndex*/ ) throw (uno::RuntimeException) +{ +} + +//ScVbaControlFactory + +/*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createShapeControl( + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< drawing::XControlShape >& xControlShape, + const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( xControlShape->getControl(), uno::UNO_QUERY_THROW ); + sal_Int32 nClassId = -1; + const static rtl::OUString sClassId( RTL_CONSTASCII_USTRINGPARAM("ClassId") ); + xProps->getPropertyValue( sClassId ) >>= nClassId; + uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess + uno::Reference< drawing::XShape > xShape( xControlShape, uno::UNO_QUERY_THROW ); + ::std::auto_ptr< ConcreteXShapeGeometryAttributes > xGeoHelper( new ConcreteXShapeGeometryAttributes( xContext, xShape ) ); + + switch( nClassId ) + { + case form::FormComponentType::COMBOBOX: + return new ScVbaComboBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + case form::FormComponentType::COMMANDBUTTON: + return new ScVbaButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + case form::FormComponentType::FIXEDTEXT: + return new ScVbaLabel( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + case form::FormComponentType::TEXTFIELD: + return new ScVbaTextBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + case form::FormComponentType::RADIOBUTTON: + return new ScVbaRadioButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + case form::FormComponentType::LISTBOX: + return new ScVbaListBox( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + case form::FormComponentType::SPINBUTTON: + return new ScVbaSpinButton( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + case form::FormComponentType::IMAGECONTROL: + return new ScVbaImage( xVbaParent, xContext, xControlShape, xModel, xGeoHelper.release() ); + } + throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() ); +} + +/*static*/ uno::Reference< msforms::XControl > ScVbaControlFactory::createUserformControl( + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< awt::XControl >& xControl, + const uno::Reference< awt::XControl >& xDialog, + const uno::Reference< frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xProps( xControl->getModel(), uno::UNO_QUERY_THROW ); + uno::Reference< lang::XServiceInfo > xServiceInfo( xProps, uno::UNO_QUERY_THROW ); + uno::Reference< msforms::XControl > xVBAControl; + uno::Reference< XHelperInterface > xVbaParent; // #FIXME - should be worksheet I guess + ::std::auto_ptr< UserFormGeometryHelper > xGeoHelper( new UserFormGeometryHelper( xContext, xControl, fOffsetX, fOffsetY ) ); + + if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlCheckBoxModel") ) ) ) + xVBAControl.set( new ScVbaCheckbox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlRadioButtonModel") ) ) ) + xVBAControl.set( new ScVbaRadioButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlEditModel") ) ) ) + xVBAControl.set( new ScVbaTextBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlButtonModel") ) ) ) + { + sal_Bool bToggle = sal_False; + xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toggle") ) ) >>= bToggle; + if ( bToggle ) + xVBAControl.set( new ScVbaToggleButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else + xVBAControl.set( new ScVbaButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + } + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlComboBoxModel") ) ) ) + xVBAControl.set( new ScVbaComboBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), true ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlListBoxModel") ) ) ) + xVBAControl.set( new ScVbaListBox( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedTextModel") ) ) ) + xVBAControl.set( new ScVbaLabel( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlImageControlModel") ) ) ) + xVBAControl.set( new ScVbaImage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlProgressBarModel") ) ) ) + xVBAControl.set( new ScVbaProgressBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlGroupBoxModel") ) ) ) + xVBAControl.set( new ScVbaFrame( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlScrollBarModel") ) ) ) + xVBAControl.set( new ScVbaScrollBar( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoMultiPageModel") ) ) ) + xVBAControl.set( new ScVbaMultiPage( xVbaParent, xContext, xControl, xModel, xGeoHelper.release(), xDialog ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlSpinButtonModel") ) ) ) + xVBAControl.set( new ScVbaSpinButton( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + else if ( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.custom.awt.UnoControlSystemAXContainerModel") ) ) ) + xVBAControl.set( new VbaSystemAXControl( xVbaParent, xContext, xControl, xModel, xGeoHelper.release() ) ); + + if( xVBAControl.is() ) + return xVBAControl; + throw uno::RuntimeException( rtl::OUString::createFromAscii("Unsupported control." ), uno::Reference< uno::XInterface >() ); +} + +rtl::OUString& +ScVbaControl::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaControl") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaControl::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.Control" ) ); + } + return aServiceNames; +} + + + +typedef cppu::WeakImplHelper1< XControlProvider > ControlProvider_BASE; +class ControlProviderImpl : public ControlProvider_BASE +{ + uno::Reference< uno::XComponentContext > m_xCtx; +public: + ControlProviderImpl( const uno::Reference< uno::XComponentContext >& xCtx ) : m_xCtx( xCtx ) {} + virtual uno::Reference< msforms::XControl > SAL_CALL createControl( const uno::Reference< drawing::XControlShape >& xControl, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException); +}; + +uno::Reference< msforms::XControl > SAL_CALL +ControlProviderImpl::createControl( const uno::Reference< drawing::XControlShape >& xControlShape, const uno::Reference< frame::XModel >& xDocOwner ) throw (uno::RuntimeException) +{ + uno::Reference< msforms::XControl > xControlToReturn; + if ( xControlShape.is() ) + xControlToReturn = ScVbaControlFactory::createShapeControl( m_xCtx, xControlShape, xDocOwner ); + return xControlToReturn; + +} + +namespace controlprovider +{ +namespace sdecl = comphelper::service_decl; +sdecl::class_<ControlProviderImpl, sdecl::with_args<false> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ControlProviderImpl", + "ooo.vba.ControlProvider" ); +} + + diff --git a/vbahelper/source/msforms/vbacontrol.hxx b/vbahelper/source/msforms/vbacontrol.hxx new file mode 100644 index 000000000000..e421f919b6a4 --- /dev/null +++ b/vbahelper/source/msforms/vbacontrol.hxx @@ -0,0 +1,126 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CONTROL_HXX +#define SC_VBA_CONTROL_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/script/XDefaultProperty.hpp> +#include <com/sun/star/drawing/XControlShape.hpp> +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XWindowPeer.hpp> +#include <ooo/vba/msforms/XControl.hpp> + +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbahelperinterface.hxx> +#include <memory> + +//typedef ::cppu::WeakImplHelper1< ov::msforms::XControl > ControlImpl_BASE; +//template SAL_DLLPUBLIC_IMPORT InheritedHelperInterfaceImpl1< ov::msforms::XControl >; +typedef InheritedHelperInterfaceImpl1< ov::msforms::XControl > ControlImpl_BASE; + +class ScVbaControl : public ControlImpl_BASE +{ +private: + com::sun::star::uno::Reference< com::sun::star::lang::XEventListener > m_xEventListener; +protected: + // awt control has nothing similar to Tag property of Mso controls, + // whether it is necessary is another question + ::rtl::OUString m_aControlTag; + + std::auto_ptr< ov::AbstractGeometryAttributes > mpGeometryHelper; + css::uno::Reference< css::beans::XPropertySet > m_xProps; + css::uno::Reference< css::uno::XInterface > m_xControl; + css::uno::Reference< css::frame::XModel > m_xModel; + + virtual css::uno::Reference< css::awt::XWindowPeer > getWindowPeer() throw (css::uno::RuntimeException); +public: + ScVbaControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pHelper ); + virtual ~ScVbaControl(); + // This class will own the helper, so make sure it is allocated from + // the heap + void setGeometryHelper( ov::AbstractGeometryAttributes* pHelper ); + // XControl + virtual sal_Bool SAL_CALL getEnabled() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnabled( sal_Bool _enabled ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getHeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setHeight( double _height ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWidth( double _width ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getLeft() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLeft( double _left ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getTop() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTop( double _top ) throw (css::uno::RuntimeException); + virtual void SAL_CALL SetFocus( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Move( double Left, double Top, const ::com::sun::star::uno::Any& Width, const ::com::sun::star::uno::Any& Height ) throw (::com::sun::star::uno::RuntimeException); + + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getObject() throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getControlSource() throw (css::uno::RuntimeException); + virtual void SAL_CALL setControlSource( const rtl::OUString& _controlsource ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getRowSource() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const rtl::OUString& _name ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getControlTipText() throw (css::uno::RuntimeException); + virtual void SAL_CALL setControlTipText( const rtl::OUString& ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getTag() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTag( const ::rtl::OUString& aTag ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTabIndex() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTabIndex( sal_Int32 nTabIndex ) throw (css::uno::RuntimeException); + //remove resouce because ooo.vba.excel.XControl is a wrapper of com.sun.star.drawing.XControlShape + virtual void removeResouce() throw( css::uno::RuntimeException ); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + + +class ScVbaControlFactory +{ +public: + static css::uno::Reference< ov::msforms::XControl > createShapeControl( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::drawing::XControlShape >& xControlShape, + const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + + static css::uno::Reference< ov::msforms::XControl > createUserformControl( + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::awt::XControl >& xControl, + const css::uno::Reference< css::awt::XControl >& xDialog, + const css::uno::Reference< css::frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) throw (css::uno::RuntimeException); + +private: + ScVbaControlFactory(); + ~ScVbaControlFactory(); +}; + +#endif//SC_VBA_CONTROL_HXX diff --git a/vbahelper/source/msforms/vbacontrols.cxx b/vbahelper/source/msforms/vbacontrols.cxx new file mode 100644 index 000000000000..7411f7ad9463 --- /dev/null +++ b/vbahelper/source/msforms/vbacontrols.cxx @@ -0,0 +1,500 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/script/XInvocation.hpp> +#include <com/sun/star/lang/WrappedTargetException.hpp> + +#include "vbacontrols.hxx" +#include "vbacontrol.hxx" +#include <cppuhelper/implbase2.hxx> +#include <ooo/vba/XControlProvider.hpp> +#include <hash_map> + +using namespace com::sun::star; +using namespace ooo::vba; + + +typedef ::cppu::WeakImplHelper2< container::XNameAccess, container::XIndexAccess > ArrayWrapImpl; + +typedef std::hash_map< rtl::OUString, sal_Int32, ::rtl::OUStringHash, + ::std::equal_to< ::rtl::OUString > > ControlIndexMap; +typedef std::vector< uno::Reference< awt::XControl > > ControlVec; + +class ControlArrayWrapper : public ArrayWrapImpl +{ + uno::Reference< awt::XControlContainer > mxDialog; + uno::Sequence< ::rtl::OUString > msNames; + ControlVec mControls; + ControlIndexMap mIndices; + +private: + void SetArrayElementTo( const uno::Reference< awt::XControl >& xCtrl, sal_Int32 nIndex = -1 ) + { + // initialize the element with specified index to the control + if ( xCtrl.is() ) + { + if ( nIndex == -1 ) + nIndex = msNames.getLength(); + + if ( nIndex >= msNames.getLength() ) + msNames.realloc( nIndex ); + + msNames[ nIndex ] = getControlName( xCtrl ); + mControls.push_back( xCtrl ); + mIndices[ msNames[ nIndex ] ] = nIndex; + } + } + +public: + ControlArrayWrapper( const uno::Reference< awt::XControl >& xDialog ) + { + try + { + mxDialog.set( xDialog, uno::UNO_QUERY_THROW ); + uno::Sequence< uno::Reference< awt::XControl > > sXControls = mxDialog->getControls(); + + msNames.realloc( sXControls.getLength() ); + for ( sal_Int32 i = 0; i < sXControls.getLength(); ++i ) + SetArrayElementTo( sXControls[ i ], i ); + } + catch( uno::Exception& ) + { + // accept the case when the dialog already does not exist + // in this case the wrapper should work in dummy mode + } + } + + static rtl::OUString getControlName( const uno::Reference< awt::XControl >& xCtrl ) + { + if ( !xCtrl.is() ) + throw uno::RuntimeException(); + + uno::Reference< beans::XPropertySet > xProp( xCtrl->getModel(), uno::UNO_QUERY_THROW ); + rtl::OUString sName; + xProp->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Name" ) ) ) >>= sName; + return sName; + } + + + // XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return awt::XControl::static_type(0); + } + + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return ( mControls.size() > 0 ); + } + + // XNameAcess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasByName( aName ) ) + throw container::NoSuchElementException(); + return getByIndex( mIndices[ aName ] ); + } + + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) + { + return msNames; + } + + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException) + { + ControlIndexMap::iterator it = mIndices.find( aName ); + return it != mIndices.end(); + } + + // XElementAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (css::uno::RuntimeException) + { + return mControls.size(); + } + + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException ) + { + if ( Index < 0 || Index >= static_cast< sal_Int32 >( mControls.size() ) ) + throw lang::IndexOutOfBoundsException(); + return uno::makeAny( mControls[ Index ] ); + } +}; + + +class ControlsEnumWrapper : public EnumerationHelper_BASE +{ + uno::Reference<XHelperInterface > m_xParent; + uno::Reference<uno::XComponentContext > m_xContext; + uno::Reference<container::XIndexAccess > m_xIndexAccess; + uno::Reference<awt::XControl > m_xDlg; + uno::Reference< frame::XModel > m_xModel; + double mfOffsetX; + double mfOffsetY; + sal_Int32 nIndex; + +public: + + ControlsEnumWrapper( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< container::XIndexAccess >& xIndexAccess, + const uno::Reference< awt::XControl >& xDlg, + const uno::Reference< frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) : + m_xParent( xParent ), + m_xContext( xContext), + m_xIndexAccess( xIndexAccess ), + m_xDlg( xDlg ), + m_xModel( xModel ), + mfOffsetX( fOffsetX ), + mfOffsetY( fOffsetY ), + nIndex( 0 ) {} + + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( nIndex < m_xIndexAccess->getCount() ) + { + uno::Reference< awt::XControl > xControl; + m_xIndexAccess->getByIndex( nIndex++ ) >>= xControl; + + uno::Reference< msforms::XControl > xVBAControl; + if ( xControl.is() && m_xDlg.is() ) + xVBAControl = ScVbaControlFactory::createUserformControl( m_xContext, xControl, m_xDlg, m_xModel, mfOffsetX, mfOffsetY ); + return uno::makeAny( xVBAControl ); + } + throw container::NoSuchElementException(); + } + +}; + + +uno::Reference<container::XIndexAccess > +lcl_controlsWrapper( const uno::Reference< awt::XControl >& xDlg ) +{ + return new ControlArrayWrapper( xDlg ); +} + +ScVbaControls::ScVbaControls( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const css::uno::Reference< awt::XControl >& xDialog, + const uno::Reference< frame::XModel >& xModel, + double fOffsetX, double fOffsetY ) : + ControlsImpl_BASE( xParent, xContext, lcl_controlsWrapper( xDialog ) ), + mxDialog( xDialog ), + mxModel( xModel ), + mfOffsetX( fOffsetX ), + mfOffsetY( fOffsetY ) +{ +} + +uno::Reference< container::XEnumeration > +ScVbaControls::createEnumeration() throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumeration > xEnum( new ControlsEnumWrapper( mxParent, mxContext, m_xIndexAccess, mxDialog, mxModel, mfOffsetX, mfOffsetY ) ); + if ( !xEnum.is() ) + throw uno::RuntimeException(); + return xEnum; +} + +uno::Any +ScVbaControls::createCollectionObject( const css::uno::Any& aSource ) +{ + // Create control from awt::XControl + uno::Reference< awt::XControl > xControl( aSource, uno::UNO_QUERY_THROW ); + uno::Reference< msforms::XControl > xVBAControl = ScVbaControlFactory::createUserformControl( mxContext, xControl, mxDialog, mxModel, mfOffsetX, mfOffsetY ); + return uno::Any( xVBAControl ); +} + +void SAL_CALL +ScVbaControls::Move( double cx, double cy ) throw (uno::RuntimeException) +{ + uno::Reference< container::XEnumeration > xEnum( createEnumeration() ); + while ( xEnum->hasMoreElements() ) + { + uno::Reference< msforms::XControl > xControl( xEnum->nextElement(), uno::UNO_QUERY_THROW ); + xControl->setLeft( xControl->getLeft() + cx ); + xControl->setTop( xControl->getTop() + cy ); + } +} + +uno::Any SAL_CALL ScVbaControls::Add( const uno::Any& Object, const uno::Any& StringKey, const uno::Any& /*Before*/, const uno::Any& /*After*/ ) + throw (uno::RuntimeException) +{ + uno::Any aResult; + ::rtl::OUString aComServiceName; + + try + { + if ( !mxDialog.is() ) + throw uno::RuntimeException(); + + uno::Reference< awt::XControl > xNewControl; + uno::Reference< lang::XMultiServiceFactory > xModelFactory( mxDialog->getModel(), uno::UNO_QUERY_THROW ); + + uno::Reference< container::XNameContainer > xDialogContainer( xModelFactory, uno::UNO_QUERY_THROW ); + + Object >>= aComServiceName; + + // TODO: Support Before and After? + ::rtl::OUString aNewName; + StringKey >>= aNewName; + if ( !aNewName.getLength() ) + { + aNewName = aComServiceName; + if ( !aNewName.getLength() ) + aNewName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Control" ) ); + + sal_Int32 nInd = 0; + while( xDialogContainer->hasByName( aNewName ) && (nInd < SAL_MAX_INT32) ) + { + aNewName = aComServiceName; + aNewName += ::rtl::OUString::valueOf( nInd++ ); + } + } + + double fDefWidth = 72.0, fDefHeight = 18.0; + if ( aComServiceName.getLength() ) + { + // create a UNO control model based on the passed control type + uno::Reference< awt::XControlModel > xNewModel; + bool bFontSupport = false; + bool bNativeAX = false; + if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.CommandButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 24.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Label.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlFixedTextModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Image.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlImageControlModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 72.0; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.CheckBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlCheckBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 108.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.OptionButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlRadioButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 108.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.TextBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlEditModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ListBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlListBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ComboBox.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlComboBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xNewModel, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Dropdown" ) ), uno::Any( true ) ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ToggleButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xNewModel, uno::UNO_QUERY_THROW ); + xProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Toggle" ) ), uno::Any( true ) ); + fDefWidth = 72.0; fDefHeight = 18.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.Frame.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlGroupBoxModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 216.0; fDefHeight = 144.0; + bFontSupport = true; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.SpinButton.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlSpinButtonModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 12.75; fDefHeight = 25.5; + } + else if( aComServiceName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM( "Forms.ScrollBar.1" ) ) ) + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlScrollBarModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 12.75; fDefHeight = 63.8; + } + else + { + xNewModel.set( xModelFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.custom.awt.UnoControlSystemAXContainerModel" ) ) ), uno::UNO_QUERY_THROW ); + fDefWidth = 72.0; fDefHeight = 18.0; + bNativeAX = true; + } + + // need to set a few font properties to get rid of the default DONT_KNOW values + if( bFontSupport ) + { + uno::Reference< beans::XPropertySet > xModelProps( xNewModel, uno::UNO_QUERY_THROW ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ), uno::Any( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Tahoma" ) ) ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ), uno::Any( float( 8.0 ) ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ), uno::Any( awt::FontWeight::NORMAL ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ), uno::Any( awt::FontSlant_NONE ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ), uno::Any( awt::FontUnderline::NONE ) ); + xModelProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ), uno::Any( awt::FontStrikeout::NONE ) ); + } + + xDialogContainer->insertByName( aNewName, uno::makeAny( xNewModel ) ); + uno::Reference< awt::XControlContainer > xControlContainer( mxDialog, uno::UNO_QUERY_THROW ); + xNewControl = xControlContainer->getControl( aNewName ); + + if( bNativeAX ) try + { + uno::Reference< script::XInvocation > xControlInvoke( xNewControl, uno::UNO_QUERY_THROW ); + + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[0] <<= aComServiceName; + uno::Sequence< sal_Int16 > aOutIDDummy; + uno::Sequence< uno::Any > aOutDummy; + xControlInvoke->invoke( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SOAddAXControl" ) ), aArgs, aOutIDDummy, aOutDummy ); + } + catch( uno::Exception& ) + { + xDialogContainer->removeByName( aNewName ); + throw; + } + } + + if ( xNewControl.is() ) + { + UpdateCollectionIndex( lcl_controlsWrapper( mxDialog ) ); + aResult <<= xNewControl; + aResult = createCollectionObject( aResult ); + uno::Reference< msforms::XControl > xVBAControl( aResult, uno::UNO_QUERY_THROW ); + if( fDefWidth > 0.0 ) + xVBAControl->setWidth( fDefWidth ); + if( fDefHeight > 0.0 ) + xVBAControl->setHeight( fDefHeight ); + } + else + throw uno::RuntimeException(); + } + catch( uno::RuntimeException& ) + { + throw; + } + catch( uno::Exception& e ) + { + throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not create AXControl!" ) ), + uno::Reference< uno::XInterface >(), + uno::makeAny( e ) ); + } + + return aResult; +} + +void SAL_CALL ScVbaControls::Remove( const uno::Any& StringKeyOrIndex ) + throw (uno::RuntimeException) +{ + ::rtl::OUString aControlName; + sal_Int32 nIndex = -1; + + try + { + if ( !mxDialog.is() ) + throw uno::RuntimeException(); + + uno::Reference< lang::XMultiServiceFactory > xModelFactory( mxDialog->getModel(), uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameContainer > xDialogContainer( xModelFactory, uno::UNO_QUERY_THROW ); + + if ( !( ( StringKeyOrIndex >>= aControlName ) && aControlName.getLength() ) + && !( ( StringKeyOrIndex >>= nIndex ) && nIndex >= 0 && nIndex < m_xIndexAccess->getCount() ) ) + throw uno::RuntimeException(); + + uno::Reference< awt::XControl > xControl; + if ( aControlName.getLength() ) + { + uno::Reference< awt::XControlContainer > xControlContainer( mxDialog, uno::UNO_QUERY_THROW ); + xControl = xControlContainer->getControl( aControlName ); + } + else + { + m_xIndexAccess->getByIndex( nIndex ) >>= xControl; + } + + if ( !xControl.is() ) + throw uno::RuntimeException(); + + if ( !aControlName.getLength() ) + aControlName = ControlArrayWrapper::getControlName( xControl ); + + xDialogContainer->removeByName( aControlName ); + xControl->dispose(); + } + catch( uno::RuntimeException& ) + { + // the exceptions are not rethrown, impossibility to find or remove the control is currently not reported + // since in most cases it means just that the controls is already not there, the VBA seems to do it in the same way + + // throw; + } + catch( uno::Exception& e ) + { + // throw lang::WrappedTargetException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can not create AXControl!" ) ), + // uno::Reference< uno::XInterface >(), + // uno::makeAny( e ) ); + } +} + + +uno::Type +ScVbaControls::getElementType() throw (uno::RuntimeException) +{ + return ooo::vba::msforms::XControl::static_type(0); +} + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaControls, "ooo.vba.msforms.Controls" ) diff --git a/vbahelper/source/msforms/vbacontrols.hxx b/vbahelper/source/msforms/vbacontrols.hxx new file mode 100644 index 000000000000..4b4838a45a8e --- /dev/null +++ b/vbahelper/source/msforms/vbacontrols.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_CONTROLS_HXX +#define SC_VBA_CONTROLS_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XControls.hpp> +#include <com/sun/star/awt/XControl.hpp> + +#include <vbahelper/vbacollectionimpl.hxx> +#include <vbahelper/vbahelper.hxx> + +typedef CollTestImplHelper< ov::msforms::XControls > ControlsImpl_BASE; + +class ScVbaControls : public ControlsImpl_BASE +{ +public: + ScVbaControls( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::awt::XControl >& xDialog, + const css::uno::Reference< css::frame::XModel >& xModel, + double fOffsetX, double fOffsetY ); + // XControls + virtual void SAL_CALL Move( double cx, double cy ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Object, const css::uno::Any& StringKey, const css::uno::Any& Before, const css::uno::Any& After ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Remove( const css::uno::Any& StringKeyOrIndex ) throw (css::uno::RuntimeException); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + + // ScVbaCollectionBaseImpl + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +private: + css::uno::Reference< css::awt::XControl > mxDialog; + css::uno::Reference< css::frame::XModel > mxModel; + double mfOffsetX; + double mfOffsetY; +}; + +#endif //SC_VBA_OLEOBJECTS_HXX + diff --git a/vbahelper/source/msforms/vbaframe.cxx b/vbahelper/source/msforms/vbaframe.cxx new file mode 100644 index 000000000000..4a1fe6a58b49 --- /dev/null +++ b/vbahelper/source/msforms/vbaframe.cxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbaframe.hxx" +#include "vbanewfont.hxx" +#include "vbacontrols.hxx" +#include <ooo/vba/msforms/fmBorderStyle.hpp> +#include <ooo/vba/msforms/fmSpecialEffect.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); + +ScVbaFrame::ScVbaFrame( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< uno::XInterface >& xControl, + const uno::Reference< frame::XModel >& xModel, + ov::AbstractGeometryAttributes* pGeomHelper, + const css::uno::Reference< css::awt::XControl >& xDialog ) : + FrameImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), + mxDialog( xDialog ) +{ +} + +// XFrame attributes + +rtl::OUString SAL_CALL ScVbaFrame::getCaption() throw (css::uno::RuntimeException) +{ + rtl::OUString Label; + m_xProps->getPropertyValue( LABEL ) >>= Label; + return Label; +} + +void SAL_CALL ScVbaFrame::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); +} + +sal_Int32 SAL_CALL ScVbaFrame::getSpecialEffect() throw (uno::RuntimeException) +{ + return msforms::fmSpecialEffect::fmSpecialEffectEtched; +} + +void SAL_CALL ScVbaFrame::setSpecialEffect( sal_Int32 /*nSpecialEffect*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaFrame::getBorderStyle() throw (uno::RuntimeException) +{ + return msforms::fmBorderStyle::fmBorderStyleNone; +} + +void SAL_CALL ScVbaFrame::setBorderStyle( sal_Int32 /*nBorderStyle*/ ) throw (uno::RuntimeException) +{ +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaFrame::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +// XFrame methods + +uno::Any SAL_CALL ScVbaFrame::Controls( const uno::Any& rIndex ) throw (uno::RuntimeException) +{ + // horizontal anchor of frame children is inside border line (add one unit to compensate border line width) + double fOffsetX = mpGeometryHelper->getOffsetX() + getLeft() + 1.0; + // vertical anchor of frame children is inside border line (add half of text height and one unit to compensate border line width) + double fOffsetY = mpGeometryHelper->getOffsetY() + getTop() + (getFont()->getSize() / 2.0) + 1.0; + + uno::Reference< XCollection > xControls( new ScVbaControls( this, mxContext, mxDialog, m_xModel, fOffsetX, fOffsetY ) ); + if( rIndex.hasValue() ) + return uno::Any( xControls->Item( rIndex, uno::Any() ) ); + return uno::Any( xControls ); +} + +// XHelperInterface + +VBAHELPER_IMPL_XHELPERINTERFACE( ScVbaFrame, "ooo.vba.msforms.Frame" ) diff --git a/vbahelper/source/msforms/vbaframe.hxx b/vbahelper/source/msforms/vbaframe.hxx new file mode 100644 index 000000000000..d76f31230bba --- /dev/null +++ b/vbahelper/source/msforms/vbaframe.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_FRAME_HXX +#define SC_VBA_FRAME_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XFrame.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XFrame > FrameImpl_BASE; + +class ScVbaFrame : public FrameImpl_BASE +{ +public: + ScVbaFrame( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::uno::XInterface >& xControl, + const css::uno::Reference< css::frame::XModel >& xModel, + ov::AbstractGeometryAttributes* pGeomHelper, + const css::uno::Reference< css::awt::XControl >& xDialog ); + + // XFrame attributes + virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSpecialEffect() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSpecialEffect( sal_Int32 nSpecialEffect ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBorderStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBorderStyle( sal_Int32 nBorderStyle ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + // XFrame methods + css::uno::Any SAL_CALL Controls( const css::uno::Any& rIndex ) throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +private: + css::uno::Reference< css::awt::XControl > mxDialog; +}; +#endif //SC_VBA_LABEL_HXX diff --git a/vbahelper/source/msforms/vbaimage.cxx b/vbahelper/source/msforms/vbaimage.cxx new file mode 100644 index 000000000000..508f97824f51 --- /dev/null +++ b/vbahelper/source/msforms/vbaimage.cxx @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaimage.hxx" +#include <vector> + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); +ScVbaImage::ScVbaImage( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ImageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +rtl::OUString& +ScVbaImage::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaImage") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaImage::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.Image" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbaimage.hxx b/vbahelper/source/msforms/vbaimage.hxx new file mode 100644 index 000000000000..52012fc1fee3 --- /dev/null +++ b/vbahelper/source/msforms/vbaimage.hxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_IMAGE_HXX +#define SC_VBA_IMAGE_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XImage.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XImage > ImageImpl_BASE; + +class ScVbaImage : public ImageImpl_BASE +{ +public: + ScVbaImage( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif //SC_VBA_IMAGE_HXX diff --git a/vbahelper/source/msforms/vbalabel.cxx b/vbahelper/source/msforms/vbalabel.cxx new file mode 100644 index 000000000000..d5aa1176e3d3 --- /dev/null +++ b/vbahelper/source/msforms/vbalabel.cxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbalabel.hxx" +#include "vbanewfont.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); +ScVbaLabel::ScVbaLabel( const css::uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ) : LabelImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +// Attributes +rtl::OUString SAL_CALL +ScVbaLabel::getCaption() throw (css::uno::RuntimeException) +{ + rtl::OUString Label; + m_xProps->getPropertyValue( LABEL ) >>= Label; + return Label; +} + +void SAL_CALL +ScVbaLabel::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); +} +uno::Any SAL_CALL +ScVbaLabel::getValue() throw (css::uno::RuntimeException) +{ + return uno::makeAny( getCaption() ); +} + +void SAL_CALL +ScVbaLabel::setValue( const uno::Any& _value ) throw (::com::sun::star::uno::RuntimeException) +{ + rtl::OUString sCaption; + _value >>= sCaption; + setCaption( sCaption ); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaLabel::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaLabel::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaLabel") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaLabel::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.Label" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbalabel.hxx b/vbahelper/source/msforms/vbalabel.hxx new file mode 100644 index 000000000000..2dcee186d58b --- /dev/null +++ b/vbahelper/source/msforms/vbalabel.hxx @@ -0,0 +1,54 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_LABEL_HXX +#define SC_VBA_LABEL_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XLabel.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> +#include <cppuhelper/implbase2.hxx> + +typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XLabel, css::script::XDefaultProperty > LabelImpl_BASE; + +class ScVbaLabel : public LabelImpl_BASE +{ +public: + ScVbaLabel( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } +}; +#endif //SC_VBA_LABEL_HXX diff --git a/vbahelper/source/msforms/vbalistbox.cxx b/vbahelper/source/msforms/vbalistbox.cxx new file mode 100644 index 000000000000..8829c8ae7256 --- /dev/null +++ b/vbahelper/source/msforms/vbalistbox.cxx @@ -0,0 +1,292 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbalistbox.hxx" +#include "vbanewfont.hxx" +#include <comphelper/anytostring.hxx> +#include <com/sun/star/script/ArrayWrapper.hpp> +#include <com/sun/star/form/validation/XValidatableFormComponent.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + +const static rtl::OUString TEXT( RTL_CONSTASCII_USTRINGPARAM("Text") ); +const static rtl::OUString SELECTEDITEMS( RTL_CONSTASCII_USTRINGPARAM("SelectedItems") ); +const static rtl::OUString ITEMS( RTL_CONSTASCII_USTRINGPARAM("StringItemList") ); + + +ScVbaListBox::ScVbaListBox( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< css::uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ListBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ + mpListHelper.reset( new ListControlHelper( m_xProps ) ); +} + +// Attributes +void SAL_CALL +ScVbaListBox::setListIndex( const uno::Any& _value ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + _value >>= nIndex; + uno::Reference< XPropValue > xPropVal( Selected( nIndex ), uno::UNO_QUERY_THROW ); + xPropVal->setValue( uno::makeAny( sal_True ) ); +} + +uno::Any SAL_CALL +ScVbaListBox::getListIndex() throw (uno::RuntimeException) +{ + uno::Sequence< sal_Int16 > sSelection; + m_xProps->getPropertyValue( SELECTEDITEMS ) >>= sSelection; + if ( sSelection.getLength() == 0 ) + return uno::Any( sal_Int32( -1 ) ); + return uno::Any( sSelection[ 0 ] ); +} + +uno::Any SAL_CALL +ScVbaListBox::getValue() throw (uno::RuntimeException) +{ + uno::Sequence< sal_Int16 > sSelection; + uno::Sequence< rtl::OUString > sItems; + m_xProps->getPropertyValue( SELECTEDITEMS ) >>= sSelection; + m_xProps->getPropertyValue( ITEMS ) >>= sItems; + if( getMultiSelect() ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "Attribute use invalid." ), uno::Reference< uno::XInterface >() ); + uno::Any aRet; + if ( sSelection.getLength() ) + aRet = uno::makeAny( sItems[ sSelection[ 0 ] ] ); + return aRet; +} + +void SAL_CALL +ScVbaListBox::setValue( const uno::Any& _value ) throw (uno::RuntimeException) +{ + if( getMultiSelect() ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "Attribute use invalid." ), uno::Reference< uno::XInterface >() ); + } + rtl::OUString sValue = getAnyAsString( _value ); + uno::Sequence< rtl::OUString > sList; + m_xProps->getPropertyValue( ITEMS ) >>= sList; + uno::Sequence< sal_Int16 > nList; + sal_Int16 nLength = static_cast<sal_Int16>( sList.getLength() ); + sal_Int16 nValue = -1; + sal_Int16 i = 0; + for( i = 0; i < nLength; i++ ) + { + if( sList[i].equals( sValue ) ) + { + nValue = i; + break; + } + } + if( nValue == -1 ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "Attribute use invalid." ), uno::Reference< uno::XInterface >() ); + + uno::Sequence< sal_Int16 > nSelectedIndices(1); + nSelectedIndices[ 0 ] = nValue; + m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nSelectedIndices ) ); + m_xProps->setPropertyValue( TEXT, uno::makeAny( sValue ) ); +} + +::rtl::OUString SAL_CALL +ScVbaListBox::getText() throw (uno::RuntimeException) +{ + rtl::OUString result; + getValue() >>= result; + return result; +} + +void SAL_CALL +ScVbaListBox::setText( const ::rtl::OUString& _text ) throw (uno::RuntimeException) +{ + setValue( uno::makeAny( _text ) ); // seems the same +} + +sal_Bool SAL_CALL +ScVbaListBox::getMultiSelect() throw (css::uno::RuntimeException) +{ + sal_Bool bMultiSelect = sal_False; + m_xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiSelection" ) ) ) >>= bMultiSelect; + return bMultiSelect; +} + +void SAL_CALL +ScVbaListBox::setMultiSelect( sal_Bool _multiselect ) throw (css::uno::RuntimeException) +{ + m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiSelection" ) ), uno::makeAny( _multiselect ) ); +} + +css::uno::Any SAL_CALL +ScVbaListBox::Selected( sal_Int32 index ) throw (css::uno::RuntimeException) +{ + uno::Sequence< rtl::OUString > sList; + m_xProps->getPropertyValue( ITEMS ) >>= sList; + sal_Int16 nLength = static_cast< sal_Int16 >( sList.getLength() ); + // no choice but to do a horror cast as internally + // the indices are but sal_Int16 + sal_Int16 nIndex = static_cast< sal_Int16 >( index ); + if( nIndex < 0 || nIndex >= nLength ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "Error Number." ), uno::Reference< uno::XInterface >() ); + m_nIndex = nIndex; + return uno::makeAny( uno::Reference< XPropValue > ( new ScVbaPropValue( this ) ) ); +} + +// Methods +void SAL_CALL +ScVbaListBox::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException) +{ + mpListHelper->AddItem( pvargItem, pvargIndex ); + } + +void SAL_CALL +ScVbaListBox::removeItem( const uno::Any& index ) throw (uno::RuntimeException) +{ + mpListHelper->removeItem( index ); +} + +void SAL_CALL +ScVbaListBox::Clear( ) throw (uno::RuntimeException) +{ + mpListHelper->Clear(); +} + +// this is called when something like the following vba code is used +// to set the selected state of particular entries in the Listbox +// ListBox1.Selected( 3 ) = false +//PropListener +void +ScVbaListBox::setValueEvent( const uno::Any& value ) +{ + sal_Bool bValue = sal_False; + if( !(value >>= bValue) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "Invalid type\n. need boolean." ), uno::Reference< uno::XInterface >() ); + uno::Sequence< sal_Int16 > nList; + m_xProps->getPropertyValue( SELECTEDITEMS ) >>= nList; + sal_Int16 nLength = static_cast<sal_Int16>( nList.getLength() ); + sal_Int16 nIndex = m_nIndex; + for( sal_Int16 i = 0; i < nLength; i++ ) + { + if( nList[i] == nIndex ) + { + if( bValue ) + return; + else + { + for( ; i < nLength - 1; i++ ) + { + nList[i] = nList[i + 1]; + } + nList.realloc( nLength - 1 ); + //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) ); + m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nList ) ); + return; + } + } + } + if( bValue ) + { + if( getMultiSelect() ) + { + nList.realloc( nLength + 1 ); + nList[nLength] = nIndex; + } + else + { + nList.realloc( 1 ); + nList[0] = nIndex; + } + //m_xProps->setPropertyValue( sSourceName, uno::makeAny( nList ) ); + m_xProps->setPropertyValue( SELECTEDITEMS, uno::makeAny( nList ) ); + } +} + +// this is called when something like the following vba code is used +// to determine the selected state of particular entries in the Listbox +// msgbox ListBox1.Selected( 3 ) + +css::uno::Any +ScVbaListBox::getValueEvent() +{ + uno::Sequence< sal_Int16 > nList; + m_xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "SelectedItems" ) ) ) >>= nList; + sal_Int32 nLength = nList.getLength(); + sal_Int32 nIndex = m_nIndex; + + for( sal_Int32 i = 0; i < nLength; i++ ) + { + if( nList[i] == nIndex ) + return uno::makeAny( sal_True ); + } + + return uno::makeAny( sal_False ); +} + +void SAL_CALL +ScVbaListBox::setRowSource( const rtl::OUString& _rowsource ) throw (uno::RuntimeException) +{ + ScVbaControl::setRowSource( _rowsource ); + mpListHelper->setRowSource( _rowsource ); +} + +sal_Int32 SAL_CALL +ScVbaListBox::getListCount() throw (uno::RuntimeException) +{ + return mpListHelper->getListCount(); +} + +uno::Any SAL_CALL +ScVbaListBox::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException) +{ + return mpListHelper->List( pvargIndex, pvarColumn ); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaListBox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaListBox::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaListBox") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaListBox::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ScVbaListBox" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbalistbox.hxx b/vbahelper/source/msforms/vbalistbox.hxx new file mode 100644 index 000000000000..7dbda1837cb0 --- /dev/null +++ b/vbahelper/source/msforms/vbalistbox.hxx @@ -0,0 +1,88 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_LISTBOX_HXX +#define SC_VBA_LISTBOX_HXX +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/script/XDefaultProperty.hpp> +#include <ooo/vba/msforms/XListBox.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbapropvalue.hxx> +#include "vbalistcontrolhelper.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper2<ScVbaControl, ov::msforms::XListBox, css::script::XDefaultProperty > ListBoxImpl_BASE; +class ScVbaListBox : public ListBoxImpl_BASE + ,public PropListener +{ + std::auto_ptr< ListControlHelper > mpListHelper; + rtl::OUString sSourceName; + rtl::OUString msDftPropName; + + sal_Int16 m_nIndex; + +public: + ScVbaListBox( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + + // Attributes + virtual css::uno::Any SAL_CALL getListIndex() throw (css::uno::RuntimeException); + virtual void SAL_CALL setListIndex( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getListCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); + virtual void SAL_CALL setText( const ::rtl::OUString& _text ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getMultiSelect() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMultiSelect( sal_Bool _multiselect ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + + // Methods + virtual css::uno::Any SAL_CALL Selected( ::sal_Int32 index ) throw (css::uno::RuntimeException); + virtual void SAL_CALL AddItem( const css::uno::Any& pvargItem, const css::uno::Any& pvargIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL removeItem( const css::uno::Any& index ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Clear( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL List( const css::uno::Any& pvargIndex, const css::uno::Any& pvarColumn ) throw (css::uno::RuntimeException); + // XControl + virtual void SAL_CALL setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException); + + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + + //PropListener + virtual void setValueEvent( const css::uno::Any& value ); + virtual css::uno::Any getValueEvent(); + + +}; + +#endif // diff --git a/vbahelper/source/msforms/vbalistcontrolhelper.cxx b/vbahelper/source/msforms/vbalistcontrolhelper.cxx new file mode 100644 index 000000000000..76763b42039e --- /dev/null +++ b/vbahelper/source/msforms/vbalistcontrolhelper.cxx @@ -0,0 +1,146 @@ +#include <vbalistcontrolhelper.hxx> +#include <vector> + +using namespace com::sun::star; +using namespace ooo::vba; + +const static rtl::OUString ITEMS( RTL_CONSTASCII_USTRINGPARAM("StringItemList") ); + +void SAL_CALL +ListControlHelper::AddItem( const uno::Any& pvargItem, const uno::Any& pvargIndex ) throw (uno::RuntimeException) +{ + if ( pvargItem.hasValue() ) + { + uno::Sequence< rtl::OUString > sList; + m_xProps->getPropertyValue( ITEMS ) >>= sList; + + sal_Int32 nIndex = sList.getLength(); + + if ( pvargIndex.hasValue() ) + pvargIndex >>= nIndex; + + rtl::OUString sString = getAnyAsString( pvargItem ); + + // if no index specified or item is to be appended to end of + // list just realloc the array and set the last item + if ( nIndex == sList.getLength() ) + { + sal_Int32 nOldSize = sList.getLength(); + sList.realloc( nOldSize + 1 ); + sList[ nOldSize ] = sString; + } + else + { + // just copy those elements above the one to be inserted + std::vector< rtl::OUString > sVec; + // reserve just the amount we need to copy + sVec.reserve( sList.getLength() - nIndex ); + + // point at first element to copy + rtl::OUString* pString = sList.getArray() + nIndex; + const rtl::OUString* pEndString = sList.getArray() + sList.getLength(); + // insert the new element + sVec.push_back( sString ); + // copy elements + for ( ; pString != pEndString; ++pString ) + sVec.push_back( *pString ); + + sList.realloc( sList.getLength() + 1 ); + + // point at first element to be overwritten + pString = sList.getArray() + nIndex; + pEndString = sList.getArray() + sList.getLength(); + std::vector< rtl::OUString >::iterator it = sVec.begin(); + for ( ; pString != pEndString; ++pString, ++it) + *pString = *it; + // + } + + m_xProps->setPropertyValue( ITEMS, uno::makeAny( sList ) ); + + } +} + +void SAL_CALL +ListControlHelper::removeItem( const uno::Any& index ) throw (uno::RuntimeException) +{ + sal_Int32 nIndex = 0; + // for int index + if ( index >>= nIndex ) + { + uno::Sequence< rtl::OUString > sList; + m_xProps->getPropertyValue( ITEMS ) >>= sList; + if( nIndex < 0 || nIndex > ( sList.getLength() - 1 ) ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid index" ), uno::Reference< uno::XInterface > () ); + if( sList.hasElements() ) + { + if( sList.getLength() == 1 ) + { + Clear(); + return; + } + for( sal_Int32 i = nIndex; i < ( sList.getLength()-1 ); i++ ) + { + sList[i] = sList[i+1]; + } + sList.realloc( sList.getLength() - 1 ); + } + + m_xProps->setPropertyValue( ITEMS, uno::makeAny( sList ) ); + } +} + +void SAL_CALL +ListControlHelper::Clear( ) throw (uno::RuntimeException) +{ + // urk, setValue doesn't seem to work !! + //setValue( uno::makeAny( sal_Int16() ) ); + m_xProps->setPropertyValue( ITEMS, uno::makeAny( uno::Sequence< rtl::OUString >() ) ); +} + +void SAL_CALL +ListControlHelper::setRowSource( const rtl::OUString& _rowsource ) throw (uno::RuntimeException) +{ + if ( _rowsource.getLength() == 0 ) + Clear(); +} + +sal_Int32 SAL_CALL +ListControlHelper::getListCount() throw (uno::RuntimeException) +{ + uno::Sequence< rtl::OUString > sList; + m_xProps->getPropertyValue( ITEMS ) >>= sList; + return sList.getLength(); +} + +uno::Any SAL_CALL +ListControlHelper::List( const ::uno::Any& pvargIndex, const uno::Any& pvarColumn ) throw (uno::RuntimeException) +{ + uno::Sequence< rtl::OUString > sList; + m_xProps->getPropertyValue( ITEMS ) >>= sList; + sal_Int16 nLength = static_cast< sal_Int16 >( sList.getLength() ); + uno::Any aRet; + if ( pvargIndex.hasValue() ) + { + sal_Int16 nIndex = -1; + pvargIndex >>= nIndex; + if( nIndex < 0 || nIndex >= nLength ) + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "Bad row Index" ), uno::Reference< uno::XInterface >() ); + aRet <<= sList[ nIndex ]; + } + else if ( pvarColumn.hasValue() ) // pvarColumn on its own would be bad + throw uno::RuntimeException( rtl::OUString::createFromAscii( + "Bad column Index" ), uno::Reference< uno::XInterface >() ); + else // List() ( e.g. no args ) + { + uno::Sequence< uno::Sequence< rtl::OUString > > sReturnArray( nLength ); + for ( sal_Int32 i = 0; i < nLength; ++i ) + { + sReturnArray[ i ].realloc( 10 ); + sReturnArray[ i ][ 0 ] = sList[ i ]; + } + aRet = uno::makeAny( sReturnArray ); + } + return aRet; +} diff --git a/vbahelper/source/msforms/vbalistcontrolhelper.hxx b/vbahelper/source/msforms/vbalistcontrolhelper.hxx new file mode 100644 index 000000000000..d56729da17e6 --- /dev/null +++ b/vbahelper/source/msforms/vbalistcontrolhelper.hxx @@ -0,0 +1,20 @@ +#ifndef SC_VBA_LISTCONTROLHELPER +#define SC_VBA_LISTCONTROLHELPER + +#include <vbahelper/vbahelper.hxx> + +class ListControlHelper +{ + css::uno::Reference< css::beans::XPropertySet > m_xProps; + +public: + ListControlHelper( const css::uno::Reference< css::beans::XPropertySet >& rxControl ) : m_xProps( rxControl ){} + virtual ~ListControlHelper() {} + virtual void SAL_CALL AddItem( const css::uno::Any& pvargItem, const css::uno::Any& pvargIndex ) throw (css::uno::RuntimeException); + virtual void SAL_CALL removeItem( const css::uno::Any& index ) throw (css::uno::RuntimeException); + virtual void SAL_CALL setRowSource( const rtl::OUString& _rowsource ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getListCount() throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL List( const css::uno::Any& pvargIndex, const css::uno::Any& pvarColumn ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Clear( ) throw (css::uno::RuntimeException); +}; +#endif diff --git a/vbahelper/source/msforms/vbamultipage.cxx b/vbahelper/source/msforms/vbamultipage.cxx new file mode 100644 index 000000000000..78590f0fd85b --- /dev/null +++ b/vbahelper/source/msforms/vbamultipage.cxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbamultipage.hxx" +#include <ooo/vba/XCollection.hpp> +#include "vbapages.hxx" +#include <vector> + +using namespace com::sun::star; +using namespace ooo::vba; + +// uno servicename com.sun.star.awt.UnoControlProgressBarMode +const rtl::OUString SVALUE( RTL_CONSTASCII_USTRINGPARAM("ProgressValue") ); +const rtl::OUString SVALUEMAX( RTL_CONSTASCII_USTRINGPARAM("ProgressValueMax") ); +const rtl::OUString SSTEP( RTL_CONSTASCII_USTRINGPARAM("Step") ); + +typedef cppu::WeakImplHelper1< container::XIndexAccess > PagesImpl_Base; +class PagesImpl : public PagesImpl_Base +{ + sal_Int32 mnPages; +public: + PagesImpl( sal_Int32 nPages ) : mnPages( nPages ) {} + virtual ::sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException) { return mnPages; } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, ::uno::RuntimeException) + { + if ( Index < 0 || Index > mnPages ) + throw lang::IndexOutOfBoundsException(); + return uno::makeAny( uno::Reference< uno::XInterface >() ); + } + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException) + { + // no Pages object yet #FIXME + //return msforms::XPage::static_type(0); + return uno::XInterface::static_type(0); + } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return ( mnPages > 0 ); + } +}; +uno::Reference< container::XIndexAccess > +ScVbaMultiPage::getPages( sal_Int32 nPages ) +{ + return new PagesImpl( nPages ); +} + +ScVbaMultiPage::ScVbaMultiPage( + const uno::Reference< ov::XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< uno::XInterface >& xControl, + const uno::Reference< frame::XModel >& xModel, + AbstractGeometryAttributes* pGeomHelper, + const uno::Reference< awt::XControl >& xDialog ) : + MultiPageImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ + mxDialogProps.set( xDialog->getModel(), uno::UNO_QUERY_THROW ); + // set dialog step to value of multipage pseudo model + setValue(getValue()); +} + +// Attributes +sal_Int32 SAL_CALL +ScVbaMultiPage::getValue() throw (css::uno::RuntimeException) +{ + sal_Int32 nValue = 0; + m_xProps->getPropertyValue( SVALUE ) >>= nValue; + return nValue; +} + +void SAL_CALL +ScVbaMultiPage::setValue( const sal_Int32 _value ) throw (::com::sun::star::uno::RuntimeException) +{ + // track change in dialog ( dialog value is 1 based, 0 is a special value ) + m_xProps->setPropertyValue( SVALUE, uno::makeAny( _value ) ); + mxDialogProps->setPropertyValue( SSTEP, uno::makeAny( _value + 1) ); +} + + +rtl::OUString& +ScVbaMultiPage::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaMultiPage") ); + return sImplName; +} + +uno::Any SAL_CALL +ScVbaMultiPage::Pages( const uno::Any& index ) throw (uno::RuntimeException) +{ + sal_Int32 nValue = 0; + m_xProps->getPropertyValue( SVALUEMAX ) >>= nValue; + uno::Reference< XCollection > xColl( new ScVbaPages( this, mxContext, getPages( nValue ) ) ); + if ( !index.hasValue() ) + return uno::makeAny( xColl ); + return xColl->Item( uno::makeAny( index ), uno::Any() ); +} + +uno::Sequence< rtl::OUString > +ScVbaMultiPage::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.MultiPage" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbamultipage.hxx b/vbahelper/source/msforms/vbamultipage.hxx new file mode 100644 index 000000000000..328a71b61592 --- /dev/null +++ b/vbahelper/source/msforms/vbamultipage.hxx @@ -0,0 +1,64 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_MULTIPAGE_HXX +#define SC_VBA_MULTIPAGE_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XMultiPage.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> +//#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase1.hxx> + +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XMultiPage > MultiPageImpl_BASE; + +class ScVbaMultiPage : public MultiPageImpl_BASE +{ + css::uno::Reference< css::container::XIndexAccess > getPages( sal_Int32 nPages ); + css::uno::Reference< css::beans::XPropertySet > mxDialogProps; +public: + ScVbaMultiPage( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + const css::uno::Reference< css::uno::XInterface >& xControl, + const css::uno::Reference< css::frame::XModel >& xModel, + ov::AbstractGeometryAttributes* pGeomHelper, + const css::uno::Reference< css::awt::XControl >& xDialog ); + + // Attributes + virtual sal_Int32 SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( sal_Int32 _value ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Pages( const css::uno::Any& index ) throw (css::uno::RuntimeException); + + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } +}; +#endif //SC_VBA_LABEL_HXX diff --git a/vbahelper/source/msforms/vbanewfont.cxx b/vbahelper/source/msforms/vbanewfont.cxx new file mode 100755 index 000000000000..f487b4e6919c --- /dev/null +++ b/vbahelper/source/msforms/vbanewfont.cxx @@ -0,0 +1,160 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <vbanewfont.hxx> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +// ============================================================================ + +VbaNewFont::VbaNewFont( + const uno::Reference< XHelperInterface >& rxParent, + const uno::Reference< uno::XComponentContext >& rxContext, + const uno::Reference< beans::XPropertySet >& rxModelProps ) throw (uno::RuntimeException) : + VbaNewFont_BASE( rxParent, rxContext ), + mxProps( rxModelProps, uno::UNO_SET_THROW ) +{ +} + +// XNewFont attributes + +::rtl::OUString SAL_CALL VbaNewFont::getName() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ) ); + return aAny.get< ::rtl::OUString >(); +} + +void SAL_CALL VbaNewFont::setName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontName" ) ), + uno::Any( rName ) ); +} + +double SAL_CALL VbaNewFont::getSize() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ) ); + return aAny.get< float >(); +} + +void SAL_CALL VbaNewFont::setSize( double fSize ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontHeight" ) ), + uno::Any( static_cast< float >( fSize ) ) ); +} + +sal_Int16 SAL_CALL VbaNewFont::getCharset() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ) ); + return rtl_getBestWindowsCharsetFromTextEncoding( static_cast< rtl_TextEncoding >( aAny.get< sal_Int16 >() ) ); +} + +void SAL_CALL VbaNewFont::setCharset( sal_Int16 nCharset ) throw (uno::RuntimeException) +{ + rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW; + if( (0 <= nCharset) && (nCharset <= SAL_MAX_UINT8) ) + eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( nCharset ) ); + if( eFontEnc == RTL_TEXTENCODING_DONTKNOW ) + throw uno::RuntimeException(); + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontCharset" ) ), + uno::Any( static_cast< sal_Int16 >( eFontEnc ) ) ); +} + +sal_Int16 SAL_CALL VbaNewFont::getWeight() throw (uno::RuntimeException) +{ + return getBold() ? 700 : 400; +} + +void SAL_CALL VbaNewFont::setWeight( sal_Int16 nWeight ) throw (uno::RuntimeException) +{ + setBold( nWeight >= 700 ); +} + +sal_Bool SAL_CALL VbaNewFont::getBold() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ) ); + return aAny.get< float >() > awt::FontWeight::NORMAL; +} + +void SAL_CALL VbaNewFont::setBold( sal_Bool bBold ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontWeight" ) ), + uno::Any( bBold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL ) ); +} + +sal_Bool SAL_CALL VbaNewFont::getItalic() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ) ); + return aAny.get< awt::FontSlant >() != awt::FontSlant_NONE; +} + +void SAL_CALL VbaNewFont::setItalic( sal_Bool bItalic ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontSlant" ) ), + uno::Any( bItalic ? awt::FontSlant_ITALIC : awt::FontSlant_NONE ) ); +} + +sal_Bool SAL_CALL VbaNewFont::getUnderline() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ) ); + return aAny.get< sal_Int16 >() != awt::FontUnderline::NONE; +} + +void SAL_CALL VbaNewFont::setUnderline( sal_Bool bUnderline ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontUnderline" ) ), + uno::Any( bUnderline ? awt::FontUnderline::SINGLE : awt::FontUnderline::NONE ) ); +} + +sal_Bool SAL_CALL VbaNewFont::getStrikethrough() throw (uno::RuntimeException) +{ + uno::Any aAny = mxProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ) ); + return aAny.get< sal_Int16 >() != awt::FontStrikeout::NONE; +} + +void SAL_CALL VbaNewFont::setStrikethrough( sal_Bool bStrikethrough ) throw (uno::RuntimeException) +{ + mxProps->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontStrikeout" ) ), + uno::Any( bStrikethrough ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE ) ); +} + +// XHelperInterface + +VBAHELPER_IMPL_XHELPERINTERFACE( VbaNewFont, "ooo.vba.msforms.NewFont" ) + +// ============================================================================ diff --git a/vbahelper/source/msforms/vbanewfont.hxx b/vbahelper/source/msforms/vbanewfont.hxx new file mode 100755 index 000000000000..d59d5caa139c --- /dev/null +++ b/vbahelper/source/msforms/vbanewfont.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef VBAHELPER_MSFORMS_VBANEWFONT_HXX +#define VBAHELPER_MSFORMS_VBANEWFONT_HXX + +#include <ooo/vba/msforms/XNewFont.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +// ============================================================================ + +typedef InheritedHelperInterfaceImpl1< ov::msforms::XNewFont > VbaNewFont_BASE; + +class VbaNewFont : public VbaNewFont_BASE +{ +public: + VbaNewFont( + const css::uno::Reference< ov::XHelperInterface >& rxParent, + const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::beans::XPropertySet >& rxModelProps ) throw (css::uno::RuntimeException); + + // XNewFont attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& rName ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSize( double fSize ) throw (css::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getCharset() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCharset( sal_Int16 nCharset ) throw (css::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getWeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWeight( sal_Int16 nWeight ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getBold() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBold( sal_Bool bBold ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getItalic() throw (css::uno::RuntimeException); + virtual void SAL_CALL setItalic( sal_Bool bItalic ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getUnderline() throw (css::uno::RuntimeException); + virtual void SAL_CALL setUnderline( sal_Bool bUnderline ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getStrikethrough() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStrikethrough( sal_Bool bStrikethrough ) throw (css::uno::RuntimeException); + + // XHelperInterface + VBAHELPER_DECL_XHELPERINTERFACE + +private: + css::uno::Reference< css::beans::XPropertySet > mxProps; +}; + +// ============================================================================ + +#endif diff --git a/vbahelper/source/msforms/vbapages.cxx b/vbahelper/source/msforms/vbapages.cxx new file mode 100644 index 000000000000..dd52a66a65cf --- /dev/null +++ b/vbahelper/source/msforms/vbapages.cxx @@ -0,0 +1,72 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapages.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +ScVbaPages::ScVbaPages( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xPages ) throw( lang::IllegalArgumentException ) : ScVbaPages_BASE( xParent, xContext, xPages ) +{ +} + +uno::Type SAL_CALL +ScVbaPages::getElementType() throw (uno::RuntimeException) +{ + // return msforms::XPage::static_type(0); + return uno::XInterface::static_type(0); +} + +uno::Any +ScVbaPages::createCollectionObject( const css::uno::Any& aSource ) +{ + return aSource; +} + +rtl::OUString& +ScVbaPages::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPages") ); + return sImplName; +} + +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaPages::createEnumeration() throw (uno::RuntimeException) +{ + return uno::Reference< container::XEnumeration >(); +} + +uno::Sequence< rtl::OUString > +ScVbaPages::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.Pages" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbapages.hxx b/vbahelper/source/msforms/vbapages.hxx new file mode 100644 index 000000000000..4bc743b1ee96 --- /dev/null +++ b/vbahelper/source/msforms/vbapages.hxx @@ -0,0 +1,56 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PAGES_HXX +#define SC_VBA_PAGES_HXX + +#include <ooo/vba/office/MsoShapeType.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/msforms/XPages.hpp> +#include <cppuhelper/implbase2.hxx> +#include <cppuhelper/implbase1.hxx> + +#include <vbahelper/vbacollectionimpl.hxx> +typedef CollTestImplHelper< +ov::msforms::XPages > ScVbaPages_BASE; + +class ScVbaPages : public ScVbaPages_BASE +{ +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +public: + ScVbaPages( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xPages ) throw ( css::lang::IllegalArgumentException ); + virtual ~ScVbaPages() {} + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + // ScVbaPages_BASE + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + +}; +#endif//SC_VBA_SHAPE_HXX diff --git a/vbahelper/source/msforms/vbaprogressbar.cxx b/vbahelper/source/msforms/vbaprogressbar.cxx new file mode 100644 index 000000000000..716cdcc61583 --- /dev/null +++ b/vbahelper/source/msforms/vbaprogressbar.cxx @@ -0,0 +1,70 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaprogressbar.hxx" +#include <vector> + +using namespace com::sun::star; +using namespace ooo::vba; + +// uno servicename com.sun.star.awt.UnoControlProgressBarMode +const rtl::OUString SVALUE( RTL_CONSTASCII_USTRINGPARAM("ProgressValue") ); + +ScVbaProgressBar::ScVbaProgressBar( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ProgressBarImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +// Attributes +uno::Any SAL_CALL +ScVbaProgressBar::getValue() throw (css::uno::RuntimeException) +{ + return m_xProps->getPropertyValue( SVALUE ); +} + +void SAL_CALL +ScVbaProgressBar::setValue( const uno::Any& _value ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( SVALUE, _value ); +} + +rtl::OUString& +ScVbaProgressBar::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaProgressBar") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaProgressBar::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.Label" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbaprogressbar.hxx b/vbahelper/source/msforms/vbaprogressbar.hxx new file mode 100644 index 000000000000..13980f522ef4 --- /dev/null +++ b/vbahelper/source/msforms/vbaprogressbar.hxx @@ -0,0 +1,51 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PROGRESSBAR_HXX +#define SC_VBA_PROGRESSBAR_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XProgressBar.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> +#include <cppuhelper/implbase2.hxx> + +typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XProgressBar, css::script::XDefaultProperty > ProgressBarImpl_BASE; + +class ScVbaProgressBar : public ProgressBarImpl_BASE +{ +public: + ScVbaProgressBar( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } +}; +#endif //SC_VBA_LABEL_HXX diff --git a/vbahelper/source/msforms/vbaradiobutton.cxx b/vbahelper/source/msforms/vbaradiobutton.cxx new file mode 100644 index 000000000000..12ee1ad8ae41 --- /dev/null +++ b/vbahelper/source/msforms/vbaradiobutton.cxx @@ -0,0 +1,110 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbaradiobutton.hxx" +#include "vbanewfont.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); +const static rtl::OUString STATE( RTL_CONSTASCII_USTRINGPARAM("State") ); +ScVbaRadioButton::ScVbaRadioButton( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : RadioButtonImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +// Attributes +rtl::OUString SAL_CALL +ScVbaRadioButton::getCaption() throw (css::uno::RuntimeException) +{ + rtl::OUString Label; + m_xProps->getPropertyValue( LABEL ) >>= Label; + return Label; +} + +void SAL_CALL +ScVbaRadioButton::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); +} + +uno::Any SAL_CALL +ScVbaRadioButton::getValue() throw (css::uno::RuntimeException) +{ + sal_Int16 nValue = -1; + m_xProps->getPropertyValue( STATE ) >>= nValue; + if( nValue != 0 ) + nValue = -1; +// return uno::makeAny( nValue ); +// I must be missing something MSO says value should be -1 if selected, 0 if not +// selected + return uno::makeAny( ( nValue == -1 ) ? sal_True : sal_False ); + +} + +void SAL_CALL +ScVbaRadioButton::setValue( const uno::Any& _value ) throw (uno::RuntimeException) +{ + sal_Int16 nValue = 0; + sal_Bool bValue = sal_False; + if( _value >>= nValue ) + { + if( nValue == -1) + nValue = 1; + } + else if ( _value >>= bValue ) + { + if ( bValue ) + nValue = 1; + } + m_xProps->setPropertyValue( STATE, uno::makeAny( nValue ) ); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaRadioButton::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaRadioButton::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaRadioButton") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaRadioButton::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.RadioButton" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbaradiobutton.hxx b/vbahelper/source/msforms/vbaradiobutton.hxx new file mode 100644 index 000000000000..3da00eb0765e --- /dev/null +++ b/vbahelper/source/msforms/vbaradiobutton.hxx @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_RADIOBUTTON_HXX +#define SC_VBA_RADIOBUTTON_HXX +#include <ooo/vba/msforms/XRadioButton.hpp> +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> +#include <cppuhelper/implbase2.hxx> + +typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XRadioButton, css::script::XDefaultProperty > RadioButtonImpl_BASE; + +class ScVbaRadioButton : public RadioButtonImpl_BASE +{ +public: + ScVbaRadioButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + // Attributes + virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue(const com::sun::star::uno::Any&) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + +}; +#endif //SC_VBA_RADIOBUTTON_HXX diff --git a/vbahelper/source/msforms/vbascrollbar.cxx b/vbahelper/source/msforms/vbascrollbar.cxx new file mode 100644 index 000000000000..f208f5acdcf9 --- /dev/null +++ b/vbahelper/source/msforms/vbascrollbar.cxx @@ -0,0 +1,131 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbascrollbar.hxx" +#include <vector> + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LARGECHANGE( RTL_CONSTASCII_USTRINGPARAM("BlockIncrement") ); +const static rtl::OUString SMALLCHANGE( RTL_CONSTASCII_USTRINGPARAM("LineIncrement") ); +const static rtl::OUString ORIENTATION( RTL_CONSTASCII_USTRINGPARAM("Orientation") ); +const static rtl::OUString SCROLLVALUE( RTL_CONSTASCII_USTRINGPARAM("ScrollValue") ); +const static rtl::OUString SCROLLMAX( RTL_CONSTASCII_USTRINGPARAM("ScrollValueMax") ); +const static rtl::OUString SCROLLMIN( RTL_CONSTASCII_USTRINGPARAM("ScrollValueMin") ); + +ScVbaScrollBar::ScVbaScrollBar( const css::uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : ScrollBarImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +// Attributes +uno::Any SAL_CALL +ScVbaScrollBar::getValue() throw (css::uno::RuntimeException) +{ + return m_xProps->getPropertyValue( SCROLLVALUE ); +} + +void SAL_CALL +ScVbaScrollBar::setValue( const uno::Any& _value ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( SCROLLVALUE, _value ); +} + +::sal_Int32 SAL_CALL +ScVbaScrollBar::getMax() throw (uno::RuntimeException) +{ + sal_Int32 nMax = 0; + m_xProps->getPropertyValue( SCROLLMAX ) >>= nMax; + return nMax; +} + +void SAL_CALL +ScVbaScrollBar::setMax( sal_Int32 nVal ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue( SCROLLMAX, uno::makeAny( nVal ) ); +} + +::sal_Int32 SAL_CALL +ScVbaScrollBar::getMin() throw (uno::RuntimeException) +{ + sal_Int32 nVal = 0; + m_xProps->getPropertyValue( SCROLLMIN ) >>= nVal; + return nVal; +} + +void SAL_CALL +ScVbaScrollBar::setMin( sal_Int32 nVal ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue( SCROLLMIN, uno::makeAny( nVal ) ); +} + +void SAL_CALL +ScVbaScrollBar::setLargeChange( ::sal_Int32 _largechange ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue( LARGECHANGE, uno::makeAny( _largechange ) ); +} + +::sal_Int32 SAL_CALL +ScVbaScrollBar::getLargeChange() throw (uno::RuntimeException) +{ + sal_Int32 nVal = 0; + m_xProps->getPropertyValue( LARGECHANGE ) >>= nVal; + return nVal; +} + +::sal_Int32 SAL_CALL +ScVbaScrollBar::getSmallChange() throw (uno::RuntimeException) +{ + sal_Int32 nSmallChange = 0; + m_xProps->getPropertyValue( SMALLCHANGE ) >>= nSmallChange; + return nSmallChange; +} + +void SAL_CALL +ScVbaScrollBar::setSmallChange( ::sal_Int32 _smallchange ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue( SMALLCHANGE, uno::makeAny( _smallchange ) ); +} + +rtl::OUString& +ScVbaScrollBar::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaScrollBar") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaScrollBar::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.Frame" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbascrollbar.hxx b/vbahelper/source/msforms/vbascrollbar.hxx new file mode 100644 index 000000000000..8b4e122c0422 --- /dev/null +++ b/vbahelper/source/msforms/vbascrollbar.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_SCROLLBAR_HXX +#define SC_VBA_SCROLLBAR_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XScrollBar.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XScrollBar > ScrollBarImpl_BASE; + +class ScVbaScrollBar : public ScrollBarImpl_BASE +{ +public: + ScVbaScrollBar( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMax() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMax( ::sal_Int32 _max ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMin( ::sal_Int32 _min ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getLargeChange() throw (css::uno::RuntimeException); + virtual void SAL_CALL setLargeChange( ::sal_Int32 _largechange ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getSmallChange() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSmallChange( ::sal_Int32 _smallchange ) throw (css::uno::RuntimeException); + + + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif //SC_VBA_LABEL_HXX diff --git a/vbahelper/source/msforms/vbaspinbutton.cxx b/vbahelper/source/msforms/vbaspinbutton.cxx new file mode 100644 index 000000000000..d536e0c41340 --- /dev/null +++ b/vbahelper/source/msforms/vbaspinbutton.cxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbaspinbutton.hxx" +#include <vector> + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString ORIENTATION( RTL_CONSTASCII_USTRINGPARAM("Orientation") ); +const static rtl::OUString SPINVALUE( RTL_CONSTASCII_USTRINGPARAM("SpinValue") ); +const static rtl::OUString SPINMAX( RTL_CONSTASCII_USTRINGPARAM("SpinValueMax") ); +const static rtl::OUString SPINMIN( RTL_CONSTASCII_USTRINGPARAM("SpinValueMin") ); + +ScVbaSpinButton::ScVbaSpinButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) : SpinButtonImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ +} + +// Attributes +uno::Any SAL_CALL +ScVbaSpinButton::getValue() throw (css::uno::RuntimeException) +{ + return m_xProps->getPropertyValue( SPINVALUE ); +} + +void SAL_CALL +ScVbaSpinButton::setValue( const uno::Any& _value ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( SPINVALUE, _value ); +} + +::sal_Int32 SAL_CALL +ScVbaSpinButton::getMax() throw (uno::RuntimeException) +{ + sal_Int32 nMax = 0; + m_xProps->getPropertyValue( SPINMAX ) >>= nMax; + return nMax; +} + +void SAL_CALL +ScVbaSpinButton::setMax( sal_Int32 nVal ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue( SPINMAX, uno::makeAny( nVal ) ); +} + +::sal_Int32 SAL_CALL +ScVbaSpinButton::getMin() throw (uno::RuntimeException) +{ + sal_Int32 nVal = 0; + m_xProps->getPropertyValue( SPINMIN ) >>= nVal; + return nVal; +} + +void SAL_CALL +ScVbaSpinButton::setMin( sal_Int32 nVal ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue( SPINMIN, uno::makeAny( nVal ) ); +} + +rtl::OUString& +ScVbaSpinButton::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaSpinButton") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaSpinButton::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.Frame" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbaspinbutton.hxx b/vbahelper/source/msforms/vbaspinbutton.hxx new file mode 100644 index 000000000000..1c600a0aa156 --- /dev/null +++ b/vbahelper/source/msforms/vbaspinbutton.hxx @@ -0,0 +1,53 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_SPINBUTTON_HXX +#define SC_VBA_SPINBUTTON_HXX +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XSpinButton.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XSpinButton > SpinButtonImpl_BASE; + +class ScVbaSpinButton : public SpinButtonImpl_BASE +{ +public: + ScVbaSpinButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMax() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMax( ::sal_Int32 _max ) throw (css::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMin() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMin( ::sal_Int32 _min ) throw (css::uno::RuntimeException); + + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif //SC_VBA_SPINBUTTON_HXX diff --git a/vbahelper/source/msforms/vbasystemaxcontrol.cxx b/vbahelper/source/msforms/vbasystemaxcontrol.cxx new file mode 100755 index 000000000000..ed2fc70164ac --- /dev/null +++ b/vbahelper/source/msforms/vbasystemaxcontrol.cxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * ( a copy is included in the LICENSE file that accompanied this code ). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbasystemaxcontrol.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +//---------------------------------------------------------- +VbaSystemAXControl::VbaSystemAXControl( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper ) +: SystemAXControlImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +, m_xControlInvocation( xControl, uno::UNO_QUERY_THROW ) +{ +} + +//---------------------------------------------------------- +uno::Reference< beans::XIntrospectionAccess > SAL_CALL VbaSystemAXControl::getIntrospection() + throw ( uno::RuntimeException ) +{ + return m_xControlInvocation->getIntrospection(); +} + +//---------------------------------------------------------- +uno::Any SAL_CALL VbaSystemAXControl::invoke( const ::rtl::OUString& aFunctionName, const uno::Sequence< uno::Any >& aParams, uno::Sequence< ::sal_Int16 >& aOutParamIndex, uno::Sequence< uno::Any >& aOutParam ) + throw ( lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException ) +{ + return m_xControlInvocation->invoke( aFunctionName, aParams, aOutParamIndex, aOutParam ); +} + +//---------------------------------------------------------- +void SAL_CALL VbaSystemAXControl::setValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) + throw ( beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException ) +{ + m_xControlInvocation->setValue( aPropertyName, aValue ); +} + +//---------------------------------------------------------- +uno::Any SAL_CALL VbaSystemAXControl::getValue( const ::rtl::OUString& aPropertyName ) + throw ( beans::UnknownPropertyException, uno::RuntimeException ) +{ + return m_xControlInvocation->getValue( aPropertyName ); +} + +//---------------------------------------------------------- +::sal_Bool SAL_CALL VbaSystemAXControl::hasMethod( const ::rtl::OUString& aName ) + throw ( uno::RuntimeException ) +{ + return m_xControlInvocation->hasMethod( aName ); +} + +//---------------------------------------------------------- +::sal_Bool SAL_CALL VbaSystemAXControl::hasProperty( const ::rtl::OUString& aName ) + throw ( uno::RuntimeException ) +{ + return m_xControlInvocation->hasProperty( aName ); +} + +//---------------------------------------------------------- +rtl::OUString& +VbaSystemAXControl::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM( "VbaSystemAXControl" ) ); + return sImplName; +} + +//---------------------------------------------------------- +uno::Sequence< rtl::OUString > +VbaSystemAXControl::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.msforms.Frame" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/msforms/vbasystemaxcontrol.hxx b/vbahelper/source/msforms/vbasystemaxcontrol.hxx new file mode 100755 index 000000000000..bffe5b99c4f1 --- /dev/null +++ b/vbahelper/source/msforms/vbasystemaxcontrol.hxx @@ -0,0 +1,58 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * ( a copy is included in the LICENSE file that accompanied this code ). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_SYSTEMAXCONTROL_HXX +#define VBA_SYSTEMAXCONTROL_HXX + +#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/script/XInvocation.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper1< ScVbaControl, css::script::XInvocation > SystemAXControlImpl_BASE; + +class VbaSystemAXControl : public SystemAXControlImpl_BASE +{ + css::uno::Reference< css::script::XInvocation > m_xControlInvocation; + +public: + VbaSystemAXControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + + // XInvocation + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XIntrospectionAccess > SAL_CALL getIntrospection( ) throw ( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Any SAL_CALL invoke( const ::rtl::OUString& aFunctionName, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aParams, ::com::sun::star::uno::Sequence< ::sal_Int16 >& aOutParamIndex, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aOutParam ) throw ( ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::script::CannotConvertException, ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException ); + virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::script::CannotConvertException, ::com::sun::star::reflection::InvocationTargetException, ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ) throw ( ::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException ); + virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) throw ( ::com::sun::star::uno::RuntimeException ); + virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) throw ( ::com::sun::star::uno::RuntimeException ); + + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif diff --git a/vbahelper/source/msforms/vbatextbox.cxx b/vbahelper/source/msforms/vbatextbox.cxx new file mode 100644 index 000000000000..b6aedcdceaf6 --- /dev/null +++ b/vbahelper/source/msforms/vbatextbox.cxx @@ -0,0 +1,163 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbatextbox.hxx" +#include "vbanewfont.hxx" +#include <com/sun/star/text/XTextRange.hpp> +#include <ooo/vba/msforms/fmBorderStyle.hpp> +#include <ooo/vba/msforms/fmSpecialEffect.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaTextBox::ScVbaTextBox( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, AbstractGeometryAttributes* pGeomHelper, bool bDialog ) : TextBoxImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ), mbDialog( bDialog ) +{ +} + +// Attributes +uno::Any SAL_CALL +ScVbaTextBox::getValue() throw (css::uno::RuntimeException) +{ + return uno::makeAny( getText() ); +} + +void SAL_CALL +ScVbaTextBox::setValue( const uno::Any& _value ) throw (css::uno::RuntimeException) +{ + // booleans are converted to uppercase strings + rtl::OUString sVal = extractStringFromAny( _value, true ); + setText( sVal ); +} + +//getString() will cause some imfo lose. +rtl::OUString SAL_CALL +ScVbaTextBox::getText() throw (css::uno::RuntimeException) +{ + uno::Any aValue; + aValue = m_xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" ) ) ); + rtl::OUString sString; + aValue >>= sString; + return sString; +} + +void SAL_CALL +ScVbaTextBox::setText( const rtl::OUString& _text ) throw (css::uno::RuntimeException) +{ + if ( !mbDialog ) + { + uno::Reference< text::XTextRange > xTextRange( m_xProps, uno::UNO_QUERY_THROW ); + xTextRange->setString( _text ); +} + else + m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Text") ), uno::makeAny( _text ) ); +} + +sal_Int32 SAL_CALL +ScVbaTextBox::getMaxLength() throw (css::uno::RuntimeException) +{ + uno::Any aValue; + aValue = m_xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ) ); + sal_Int32 nMaxLength = 0; + aValue >>= nMaxLength; + return nMaxLength; +} + +void SAL_CALL +ScVbaTextBox::setMaxLength( sal_Int32 _maxlength ) throw (css::uno::RuntimeException) +{ + uno::Any aValue( _maxlength ); + m_xProps->setPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MaxTextLen" ) ), aValue); +} + +sal_Bool SAL_CALL +ScVbaTextBox::getMultiline() throw (css::uno::RuntimeException) +{ + uno::Any aValue; + aValue = m_xProps->getPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ) ); + sal_Bool bRet = false; + aValue >>= bRet; + return bRet; +} + +void SAL_CALL +ScVbaTextBox::setMultiline( sal_Bool _multiline ) throw (css::uno::RuntimeException) +{ + uno::Any aValue( _multiline ); + m_xProps->setPropertyValue + (rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MultiLine" ) ), aValue); +} + +sal_Int32 SAL_CALL ScVbaTextBox::getSpecialEffect() throw (uno::RuntimeException) +{ + return msforms::fmSpecialEffect::fmSpecialEffectSunken; +} + +void SAL_CALL ScVbaTextBox::setSpecialEffect( sal_Int32 /*nSpecialEffect*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaTextBox::getBorderStyle() throw (uno::RuntimeException) +{ + return msforms::fmBorderStyle::fmBorderStyleNone; +} + +void SAL_CALL ScVbaTextBox::setBorderStyle( sal_Int32 /*nBorderStyle*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaTextBox::getTextLength() throw (uno::RuntimeException) +{ + return getText().getLength(); +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaTextBox::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaTextBox::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaTextBox") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaTextBox::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.TextBox" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/msforms/vbatextbox.hxx b/vbahelper/source/msforms/vbatextbox.hxx new file mode 100644 index 000000000000..586bceb607a0 --- /dev/null +++ b/vbahelper/source/msforms/vbatextbox.hxx @@ -0,0 +1,62 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_TEXTBOX_HXX +#define SC_VBA_TEXTBOX_HXX +#include <cppuhelper/implbase2.hxx> +#include <ooo/vba/msforms/XTextBox.hpp> +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XTextBox, css::script::XDefaultProperty > TextBoxImpl_BASE; + +class ScVbaTextBox : public TextBoxImpl_BASE +{ + bool mbDialog; +public: + ScVbaTextBox( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper, bool bDialog = false ); + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getText() throw (css::uno::RuntimeException); + virtual void SAL_CALL setText( const rtl::OUString& _text ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getMaxLength() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMaxLength( sal_Int32 _maxlength ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getMultiline() throw (css::uno::RuntimeException); + virtual void SAL_CALL setMultiline( sal_Bool _multiline ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSpecialEffect() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSpecialEffect( sal_Int32 nSpecialEffect ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBorderStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBorderStyle( sal_Int32 nBorderStyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getTextLength() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif //SC_VBA_TEXTBOX_HXX diff --git a/vbahelper/source/msforms/vbatogglebutton.cxx b/vbahelper/source/msforms/vbatogglebutton.cxx new file mode 100644 index 000000000000..d1a3b40d6eb7 --- /dev/null +++ b/vbahelper/source/msforms/vbatogglebutton.cxx @@ -0,0 +1,151 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbatogglebutton.hxx" +#include "vbanewfont.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + + +const static rtl::OUString LABEL( RTL_CONSTASCII_USTRINGPARAM("Label") ); +const static rtl::OUString TOGGLE( RTL_CONSTASCII_USTRINGPARAM("Toggle") ); +const static rtl::OUString STATE( RTL_CONSTASCII_USTRINGPARAM("State") ); +ScVbaToggleButton::ScVbaToggleButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< uno::XInterface >& xControl, const uno::Reference< frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ) : ToggleButtonImpl_BASE( xParent, xContext, xControl, xModel, pGeomHelper ) +{ + OSL_TRACE("ScVbaToggleButton(ctor)"); + m_xProps->setPropertyValue( TOGGLE, uno::makeAny( sal_True ) ); +} + +ScVbaToggleButton::~ScVbaToggleButton() +{ + OSL_TRACE("~ScVbaToggleButton(dtor)"); +} + +// Attributes +rtl::OUString SAL_CALL +ScVbaToggleButton::getCaption() throw (css::uno::RuntimeException) +{ + rtl::OUString Label; + m_xProps->getPropertyValue( LABEL ) >>= Label; + return Label; +} + +void SAL_CALL +ScVbaToggleButton::setCaption( const rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException) +{ + m_xProps->setPropertyValue( LABEL, uno::makeAny( _caption ) ); +} + +uno::Any SAL_CALL +ScVbaToggleButton::getValue() throw (uno::RuntimeException) +{ + sal_Int16 nState = 0; + m_xProps->getPropertyValue( STATE ) >>= nState; + return uno::makeAny( nState ? sal_Int16( -1 ) : sal_Int16( 0 ) ); +} + +void SAL_CALL +ScVbaToggleButton::setValue( const uno::Any& _value ) throw (uno::RuntimeException) +{ + sal_Int16 nState = 0; + _value >>= nState; + OSL_TRACE( "nState - %d", nState ); + nState = ( nState == -1 ) ? 1 : 0; + OSL_TRACE( "nState - %d", nState ); + m_xProps->setPropertyValue( STATE, uno::makeAny( nState ) ); +} + +sal_Bool SAL_CALL ScVbaToggleButton::getAutoSize() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaToggleButton::setAutoSize( sal_Bool /*bAutoSize*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaToggleButton::getCancel() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaToggleButton::setCancel( sal_Bool /*bCancel*/ ) throw (uno::RuntimeException) +{ +} + +sal_Bool SAL_CALL ScVbaToggleButton::getDefault() throw (uno::RuntimeException) +{ + return sal_False; +} + +void SAL_CALL ScVbaToggleButton::setDefault( sal_Bool /*bDefault*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaToggleButton::getBackColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaToggleButton::setBackColor( sal_Int32 /*nBackColor*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL ScVbaToggleButton::getForeColor() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL ScVbaToggleButton::setForeColor( sal_Int32 /*nForeColor*/ ) throw (uno::RuntimeException) +{ +} + +uno::Reference< msforms::XNewFont > SAL_CALL ScVbaToggleButton::getFont() throw (uno::RuntimeException) +{ + return new VbaNewFont( this, mxContext, m_xProps ); +} + +rtl::OUString& +ScVbaToggleButton::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaToggleButton") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaToggleButton::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ToggleButton" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/msforms/vbatogglebutton.hxx b/vbahelper/source/msforms/vbatogglebutton.hxx new file mode 100644 index 000000000000..d2bf4c6b7f17 --- /dev/null +++ b/vbahelper/source/msforms/vbatogglebutton.hxx @@ -0,0 +1,65 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_TOGGLEBUTTON_HXX +#define SC_VBA_TOGGLEBUTTON_HXX +#include <cppuhelper/implbase2.hxx> +#include <ooo/vba/msforms/XToggleButton.hpp> + +#include "vbacontrol.hxx" +#include <vbahelper/vbahelper.hxx> + +typedef cppu::ImplInheritanceHelper2< ScVbaControl, ov::msforms::XToggleButton, css::script::XDefaultProperty > ToggleButtonImpl_BASE; + +class ScVbaToggleButton : public ToggleButtonImpl_BASE +{ + rtl::OUString msDftPropName; +public: + ScVbaToggleButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::uno::XInterface >& xControl, const css::uno::Reference< css::frame::XModel >& xModel, ov::AbstractGeometryAttributes* pGeomHelper ); + ~ScVbaToggleButton(); + // Attributes + virtual css::uno::Any SAL_CALL getValue() throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException); + virtual rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getAutoSize() throw (css::uno::RuntimeException); + virtual void SAL_CALL setAutoSize( sal_Bool bAutoSize ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getCancel() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCancel( sal_Bool bCancel ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getDefault() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDefault( sal_Bool bDefault ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBackColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBackColor( sal_Int32 nBackColor ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getForeColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setForeColor( sal_Int32 nForeColor ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XNewFont > SAL_CALL getFont() throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + // XDefaultProperty + rtl::OUString SAL_CALL getDefaultPropertyName( ) throw (css::uno::RuntimeException) { return ::rtl::OUString::createFromAscii("Value"); } +}; +#endif //SC_VBA_TOGGLEBUTTON_HXX diff --git a/vbahelper/source/msforms/vbauserform.cxx b/vbahelper/source/msforms/vbauserform.cxx new file mode 100644 index 000000000000..3eb799205389 --- /dev/null +++ b/vbahelper/source/msforms/vbauserform.cxx @@ -0,0 +1,272 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> +#include "vbauserform.hxx" +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/beans/PropertyConcept.hpp> +#include <com/sun/star/util/MeasureUnit.hpp> +#include <basic/sbx.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbmeth.hxx> +#include "vbacontrols.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +// some little notes +// XDialog implementation has the following interesting bits +// a Controls property ( which is an array of the container controls ) +// each item in the controls array is a XControl, where the model is +// basically a property bag +// additionally the XDialog instance has itself a model +// this model has a ControlModels ( array of models ) property +// the models in ControlModels can be accessed by name +// also the XDialog is a XControl ( to access the model above + +ScVbaUserForm::ScVbaUserForm( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) throw ( lang::IllegalArgumentException ) : ScVbaUserForm_BASE( getXSomethingFromArgs< XHelperInterface >( aArgs, 0 ), xContext, getXSomethingFromArgs< uno::XInterface >( aArgs, 1 ), getXSomethingFromArgs< frame::XModel >( aArgs, 2 ), static_cast< ooo::vba::AbstractGeometryAttributes* >(0) ), mbDispose( true ) +{ + m_xDialog.set( m_xControl, uno::UNO_QUERY_THROW ); + uno::Reference< awt::XControl > xControl( m_xDialog, uno::UNO_QUERY_THROW ); + m_xProps.set( xControl->getModel(), uno::UNO_QUERY_THROW ); + setGeometryHelper( new UserFormGeometryHelper( xContext, xControl, 0.0, 0.0 ) ); +} + +ScVbaUserForm::~ScVbaUserForm() +{ +} + +void SAL_CALL +ScVbaUserForm::Show( ) throw (uno::RuntimeException) +{ + OSL_TRACE("ScVbaUserForm::Show( )"); + short aRet = 0; + mbDispose = true; + + if ( m_xDialog.is() ) + { + // try to center dialog on model window + if( m_xModel.is() ) try + { + uno::Reference< frame::XController > xController( m_xModel->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); + uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW ); + awt::Rectangle aPosSize = xWindow->getPosSize(); // already in pixel + + uno::Reference< awt::XControl > xControl( m_xDialog, uno::UNO_QUERY_THROW ); + uno::Reference< awt::XWindow > xControlWindow( xControl->getPeer(), uno::UNO_QUERY_THROW ); + xControlWindow->setPosSize( (aPosSize.Width - getWidth()) / 2.0, (aPosSize.Height - getHeight()) / 2.0, 0, 0, awt::PosSize::POS ); + } + catch( uno::Exception& ) + { + } + + aRet = m_xDialog->execute(); + } + OSL_TRACE("ScVbaUserForm::Show() execute returned %d", aRet); + if ( mbDispose ) + { + try + { + uno::Reference< lang::XComponent > xComp( m_xDialog, uno::UNO_QUERY_THROW ); + m_xDialog = NULL; + xComp->dispose(); + mbDispose = false; + } + catch( uno::Exception& ) + { + } + } +} + +rtl::OUString SAL_CALL +ScVbaUserForm::getCaption() throw (uno::RuntimeException) +{ + rtl::OUString sCaption; + m_xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ) ) >>= sCaption; + return sCaption; +} +void +ScVbaUserForm::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException) +{ + m_xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Title") ), uno::makeAny( _caption ) ); +} + +double SAL_CALL ScVbaUserForm::getInnerWidth() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getInnerWidth(); +} + +void SAL_CALL ScVbaUserForm::setInnerWidth( double fInnerWidth ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setInnerWidth( fInnerWidth ); +} + +double SAL_CALL ScVbaUserForm::getInnerHeight() throw (uno::RuntimeException) +{ + return mpGeometryHelper->getInnerHeight(); +} + +void SAL_CALL ScVbaUserForm::setInnerHeight( double fInnerHeight ) throw (uno::RuntimeException) +{ + mpGeometryHelper->setInnerHeight( fInnerHeight ); +} + +void SAL_CALL +ScVbaUserForm::Hide( ) throw (uno::RuntimeException) +{ + mbDispose = false; // hide not dispose + if ( m_xDialog.is() ) + m_xDialog->endExecute(); +} + +void SAL_CALL +ScVbaUserForm::RePaint( ) throw (uno::RuntimeException) +{ + // do nothing +} + +void SAL_CALL +ScVbaUserForm::UnloadObject( ) throw (uno::RuntimeException) +{ + mbDispose = true; + if ( m_xDialog.is() ) + m_xDialog->endExecute(); +} + +rtl::OUString& +ScVbaUserForm::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaUserForm") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaUserForm::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.UserForm" ) ); + } + return aServiceNames; +} + +uno::Reference< beans::XIntrospectionAccess > SAL_CALL +ScVbaUserForm::getIntrospection( ) throw (uno::RuntimeException) +{ + return uno::Reference< beans::XIntrospectionAccess >(); +} + +uno::Any SAL_CALL +ScVbaUserForm::invoke( const ::rtl::OUString& /*aFunctionName*/, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException) +{ + throw uno::RuntimeException(); // unsupported operation +} + +void SAL_CALL +ScVbaUserForm::setValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException) +{ + uno::Any aObject = getValue( aPropertyName ); + + // in case the dialog is already closed the VBA implementation should not throw exceptions + if ( aObject.hasValue() ) + { + // The Object *must* support XDefaultProperty here because getValue will + // only return properties that are Objects ( e.g. controls ) + // e.g. Userform1.aControl = something + // 'aControl' has to support XDefaultProperty to make sense here + uno::Reference< script::XDefaultProperty > xDfltProp( aObject, uno::UNO_QUERY_THROW ); + rtl::OUString aDfltPropName = xDfltProp->getDefaultPropertyName(); + uno::Reference< beans::XIntrospectionAccess > xUnoAccess( getIntrospectionAccess( aObject ) ); + uno::Reference< beans::XPropertySet > xPropSet( xUnoAccess->queryAdapter( ::getCppuType( (const uno::Reference< beans::XPropertySet > *)0 ) ), uno::UNO_QUERY_THROW ); + xPropSet->setPropertyValue( aDfltPropName, aValue ); + } +} + +uno::Any SAL_CALL +ScVbaUserForm::getValue( const ::rtl::OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException) +{ + uno::Any aResult; + + // in case the dialog is already closed the VBA implementation should not throw exceptions + if ( m_xDialog.is() ) + { + uno::Reference< awt::XControl > xDialogControl( m_xDialog, uno::UNO_QUERY_THROW ); + uno::Reference< awt::XControlContainer > xContainer( m_xDialog, uno::UNO_QUERY_THROW ); + uno::Reference< awt::XControl > xControl = xContainer->getControl( aPropertyName ); + if ( xControl.is() ) + aResult <<= ScVbaControlFactory::createUserformControl( mxContext, xControl, xDialogControl, m_xModel, mpGeometryHelper->getOffsetX(), mpGeometryHelper->getOffsetY() ); + } + + return aResult; +} + +::sal_Bool SAL_CALL +ScVbaUserForm::hasMethod( const ::rtl::OUString& /*aName*/ ) throw (uno::RuntimeException) +{ + return sal_False; +} +uno::Any SAL_CALL +ScVbaUserForm::Controls( const uno::Any& index ) throw (uno::RuntimeException) +{ + // if the dialog already closed we should do nothing, but the VBA will call methods of the Controls objects + // thus we have to provide a dummy object in this case + uno::Reference< awt::XControl > xDialogControl( m_xDialog, uno::UNO_QUERY ); + uno::Reference< XCollection > xControls( new ScVbaControls( this, mxContext, xDialogControl, m_xModel, mpGeometryHelper->getOffsetX(), mpGeometryHelper->getOffsetY() ) ); + if ( index.hasValue() ) + return uno::makeAny( xControls->Item( index, uno::Any() ) ); + return uno::makeAny( xControls ); +} + +::sal_Bool SAL_CALL +ScVbaUserForm::hasProperty( const ::rtl::OUString& aName ) throw (uno::RuntimeException) +{ + uno::Reference< awt::XControl > xControl( m_xDialog, uno::UNO_QUERY ); + OSL_TRACE("ScVbaUserForm::hasProperty(%s) %d", rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr(), xControl.is() ); + if ( xControl.is() ) + { + uno::Reference< container::XNameAccess > xNameAccess( xControl->getModel(), uno::UNO_QUERY_THROW ); + sal_Bool bRes = xNameAccess->hasByName( aName ); + OSL_TRACE("ScVbaUserForm::hasProperty(%s) %d ---> %d", rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr(), xControl.is(), bRes ); + return bRes; + } + return sal_False; +} + +namespace userform +{ +namespace sdecl = comphelper::service_decl; +sdecl::vba_service_class_<ScVbaUserForm, sdecl::with_args<true> > serviceImpl; +extern sdecl::ServiceDecl const serviceDecl( + serviceImpl, + "ScVbaUserForm", + "ooo.vba.msforms.UserForm" ); +} + diff --git a/vbahelper/source/msforms/vbauserform.hxx b/vbahelper/source/msforms/vbauserform.hxx new file mode 100644 index 000000000000..1777a979b9f2 --- /dev/null +++ b/vbahelper/source/msforms/vbauserform.hxx @@ -0,0 +1,73 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_USERFORM_HXX +#define SC_VBA_USERFORM_HXX + +#include <cppuhelper/implbase1.hxx> +#include <ooo/vba/msforms/XUserForm.hpp> +#include <com/sun/star/awt/XDialog.hpp> +#include <com/sun/star/frame/XModel.hpp> + +#include <vbahelper/vbahelperinterface.hxx> +#include "vbacontrol.hxx" + +//typedef InheritedHelperInterfaceImpl1< ov::msforms::XUserForm > ScVbaUserForm_BASE; +typedef cppu::ImplInheritanceHelper1< ScVbaControl, ov::msforms::XUserForm > ScVbaUserForm_BASE; + +class ScVbaUserForm : public ScVbaUserForm_BASE +{ +private: + css::uno::Reference< css::awt::XDialog > m_xDialog; + bool mbDispose; +protected: +public: + ScVbaUserForm( css::uno::Sequence< css::uno::Any > const& aArgs, css::uno::Reference< css::uno::XComponentContext >const& xContext ) throw ( css::lang::IllegalArgumentException ); + virtual ~ScVbaUserForm(); + // XUserForm + virtual void SAL_CALL RePaint( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL Show( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL setValue( const ::rtl::OUString& aPropertyName, const css::uno::Any& aValue ) throw (css::beans::UnknownPropertyException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL getValue( const ::rtl::OUString& aPropertyName ) throw (css::beans::UnknownPropertyException, css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getCaption() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setCaption( const ::rtl::OUString& _caption ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getInnerWidth() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setInnerWidth( double fInnerWidth ) throw (::com::sun::star::uno::RuntimeException); + virtual double SAL_CALL getInnerHeight() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setInnerHeight( double fInnerHeight ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL Hide( ) throw (css::uno::RuntimeException); + virtual void SAL_CALL UnloadObject( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Controls( const css::uno::Any& index ) throw (css::uno::RuntimeException); + // XIntrospection + virtual css::uno::Reference< css::beans::XIntrospectionAccess > SAL_CALL getIntrospection( ) throw (css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL invoke( const ::rtl::OUString& aFunctionName, const css::uno::Sequence< css::uno::Any >& aParams, css::uno::Sequence< ::sal_Int16 >& aOutParamIndex, css::uno::Sequence< css::uno::Any >& aOutParam ) throw (css::lang::IllegalArgumentException, css::script::CannotConvertException, css::reflection::InvocationTargetException, css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasMethod( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasProperty( const ::rtl::OUString& aName ) throw (css::uno::RuntimeException); + //XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; +#endif diff --git a/vbahelper/source/vbahelper/collectionbase.cxx b/vbahelper/source/vbahelper/collectionbase.cxx new file mode 100755 index 000000000000..16fc673f54d5 --- /dev/null +++ b/vbahelper/source/vbahelper/collectionbase.cxx @@ -0,0 +1,332 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2011 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include <vbahelper/collectionbase.hxx> + +#include <map> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <cppuhelper/implbase2.hxx> + +namespace vbahelper { + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +// ============================================================================ + +namespace { + +// ---------------------------------------------------------------------------- + +class CollectionEnumeration : public ::cppu::WeakImplHelper1< container::XEnumeration > +{ +public: + explicit CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection ); + virtual sal_Bool SAL_CALL hasMoreElements() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); + +private: + ::rtl::Reference< CollectionBase > mxCollection; + sal_Int32 mnCurrIndex; +}; + +CollectionEnumeration::CollectionEnumeration( const ::rtl::Reference< CollectionBase >& rxCollection ) : + mxCollection( rxCollection ), + mnCurrIndex( 1 ) // collection expects one-based indexes +{ +} + +sal_Bool SAL_CALL CollectionEnumeration::hasMoreElements() throw (uno::RuntimeException) +{ + return mnCurrIndex <= mxCollection->getCount(); +} + +uno::Any SAL_CALL CollectionEnumeration::nextElement() throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( hasMoreElements() ) + return mxCollection->getItemByIndex( mnCurrIndex++ ); + throw container::NoSuchElementException(); +} + +// ---------------------------------------------------------------------------- + +struct IsLessIgnoreCase +{ + inline bool operator()( const ::rtl::OUString& rName1, const ::rtl::OUString& rName2 ) const + { return ::rtl_ustr_compareIgnoreAsciiCase_WithLength( rName1.getStr(), rName1.getLength(), rName2.getStr(), rName2.getLength() ) < 0; } +}; + +// ---------------------------------------------------------------------------- + +class SequenceToContainer : public ::cppu::WeakImplHelper2< container::XIndexAccess, container::XNameAccess > +{ +public: + explicit SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType ); + explicit SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType ); + // XIndexAccess + virtual sal_Int32 SAL_CALL getCount() throw (uno::RuntimeException); + virtual uno::Any SAL_CALL getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException); + // XNameAccess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException); + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames() throw (uno::RuntimeException); + virtual sal_Bool SAL_CALL hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException); + // XElementAccess + virtual uno::Type SAL_CALL getElementType() throw (uno::RuntimeException); + virtual sal_Bool SAL_CALL hasElements() throw (uno::RuntimeException); + +private: + typedef uno::Sequence< ::rtl::OUString > ElementNameSequence; + typedef ::std::vector< uno::Any > ElementVector; + typedef ::std::map< ::rtl::OUString, uno::Any, IsLessIgnoreCase > ElementMap; + + ElementNameSequence maElementNames; + ElementVector maElements; + ElementMap maElementMap; + uno::Type maElementType; +}; + +SequenceToContainer::SequenceToContainer( const ::std::vector< uno::Reference< container::XNamed > >& rElements, const uno::Type& rElementType ) : + maElementType( rElementType ) +{ + maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) ); + maElements.reserve( rElements.size() ); + ::rtl::OUString* pElementName = maElementNames.getArray(); + for( ::std::vector< uno::Reference< container::XNamed > >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName ) + { + uno::Reference< container::XNamed > xNamed = *aIt; + *pElementName = xNamed->getName(); + maElements.push_back( uno::Any( xNamed ) ); + // same name may occur multiple times, VBA returns first occurance + if( maElementMap.count( *pElementName ) == 0 ) + maElementMap[ *pElementName ] <<= xNamed; + } +} + +SequenceToContainer::SequenceToContainer( const ::std::vector< beans::NamedValue >& rElements, const uno::Type& rElementType ) : + maElementType( rElementType ) +{ + maElementNames.realloc( static_cast< sal_Int32 >( rElements.size() ) ); + maElements.reserve( rElements.size() ); + ::rtl::OUString* pElementName = maElementNames.getArray(); + for( ::std::vector< beans::NamedValue >::const_iterator aIt = rElements.begin(), aEnd = rElements.end(); aIt != aEnd; ++aIt, ++pElementName ) + { + *pElementName = aIt->Name; + maElements.push_back( aIt->Value ); + // same name may occur multiple times, VBA returns first occurance + if( maElementMap.count( *pElementName ) == 0 ) + maElementMap[ *pElementName ] = aIt->Value; + } +} + +sal_Int32 SAL_CALL SequenceToContainer::getCount() throw (uno::RuntimeException) +{ + return static_cast< sal_Int32 >( maElements.size() ); +} + +uno::Any SAL_CALL SequenceToContainer::getByIndex( sal_Int32 nIndex ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) +{ + if( (0 <= nIndex) && (nIndex < getCount()) ) + return maElements[ static_cast< size_t >( nIndex ) ]; + throw lang::IndexOutOfBoundsException(); +} + +uno::Any SAL_CALL SequenceToContainer::getByName( const ::rtl::OUString& rName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) +{ + ElementMap::iterator aIt = maElementMap.find( rName ); + if( aIt != maElementMap.end() ) + return aIt->second; + throw container::NoSuchElementException(); +} + +uno::Sequence< ::rtl::OUString > SAL_CALL SequenceToContainer::getElementNames() throw (uno::RuntimeException) +{ + return maElementNames; +} + +sal_Bool SAL_CALL SequenceToContainer::hasByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) +{ + return maElementMap.count( rName ) > 0; +} + +uno::Type SAL_CALL SequenceToContainer::getElementType() throw (uno::RuntimeException) +{ + return maElementType; +} + +sal_Bool SAL_CALL SequenceToContainer::hasElements() throw (uno::RuntimeException) +{ + return !maElements.empty(); +} + +} // namespace + +// ============================================================================ + +CollectionBase::CollectionBase( const uno::Type& rElementType ) : + maElementType( rElementType ), + mbConvertOnDemand( false ) +{ +} + +sal_Int32 SAL_CALL CollectionBase::getCount() throw (uno::RuntimeException) +{ + if( mxIndexAccess.is() ) + return mxIndexAccess->getCount(); + if( mxNameAccess.is() ) + return mxNameAccess->getElementNames().getLength(); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +uno::Reference< container::XEnumeration > SAL_CALL CollectionBase::createEnumeration() throw (uno::RuntimeException) +{ + return new CollectionEnumeration( this ); +} + +uno::Type SAL_CALL CollectionBase::getElementType() throw (uno::RuntimeException) +{ + return maElementType; +} + +sal_Bool SAL_CALL CollectionBase::hasElements() throw (uno::RuntimeException) +{ + if( mxIndexAccess.is() ) + return mxIndexAccess->hasElements(); + if( mxNameAccess.is() ) + return mxNameAccess->hasElements(); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +::rtl::OUString SAL_CALL CollectionBase::getDefaultMethodName() throw (uno::RuntimeException) +{ + static ::rtl::OUString saDefMethodName( RTL_CONSTASCII_USTRINGPARAM( "Item" ) ); + return saDefMethodName; +} + +// ---------------------------------------------------------------------------- + +void CollectionBase::initContainer( + const uno::Reference< container::XElementAccess >& rxElementAccess, + ContainerType eContainerType ) throw (uno::RuntimeException) +{ + mxIndexAccess.set( rxElementAccess, uno::UNO_QUERY ); + mxNameAccess.set( rxElementAccess, uno::UNO_QUERY ); + switch( eContainerType ) + { + case CONTAINER_NATIVE_VBA: + mbConvertOnDemand = false; + break; + case CONTAINER_CONVERT_ON_DEMAND: + mbConvertOnDemand = true; + break; + } +} + +void CollectionBase::initElements( const ::std::vector< uno::Reference< container::XNamed > >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException) +{ + // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity + initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType ); +} + +void CollectionBase::initElements( const ::std::vector< beans::NamedValue >& rElements, ContainerType eContainerType ) throw (uno::RuntimeException) +{ + // SequenceToContainer derives twice from XElementAccess, need to resolve ambiguity + initContainer( static_cast< container::XIndexAccess* >( new SequenceToContainer( rElements, maElementType ) ), eContainerType ); +} + +uno::Any CollectionBase::createCollectionItem( const uno::Any& rElement, const uno::Any& rIndex ) throw (css::uno::RuntimeException) +{ + uno::Any aItem = mbConvertOnDemand ? implCreateCollectionItem( rElement, rIndex ) : rElement; + if( aItem.hasValue() ) + return aItem; + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item." ) ), 0 ); +} + +uno::Any CollectionBase::getItemByIndex( sal_Int32 nIndex ) throw (uno::RuntimeException) +{ + if( mxIndexAccess.is() ) + { + if( (1 <= nIndex) && (nIndex <= mxIndexAccess->getCount()) ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( mxIndexAccess->getByIndex( nIndex - 1 ), uno::Any( nIndex ) ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 ); + } + if( mxNameAccess.is() ) + { + uno::Sequence< ::rtl::OUString > aElementNames = mxNameAccess->getElementNames(); + if( (1 <= nIndex) && (nIndex <= aElementNames.getLength()) ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( mxNameAccess->getByName( aElementNames[ nIndex - 1 ] ), uno::Any( aElementNames[ nIndex - 1 ] ) ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Index out of bounds." ) ), 0 ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +uno::Any CollectionBase::getItemByName( const ::rtl::OUString& rName ) throw (uno::RuntimeException) +{ + if( mxNameAccess.is() ) + { + if( rName.getLength() > 0 ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( mxNameAccess->getByName( rName ), uno::Any( rName ) ); + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 ); + } + if( mxIndexAccess.is() ) + { + for( sal_Int32 nIndex = 0, nSize = mxIndexAccess->getCount(); nIndex < nSize; ++nIndex ) + { + uno::Any aElement = mxIndexAccess->getByIndex( nIndex ); + uno::Reference< container::XNamed > xNamed( aElement, uno::UNO_QUERY ); + if( xNamed.is() && xNamed->getName().equalsIgnoreAsciiCase( rName ) ) + // createCollectionItem() will convert from container element to VBA item + return createCollectionItem( aElement, uno::Any( nIndex ) ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid item name." ) ), 0 ); + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No element container set." ) ), 0 ); +} + +uno::Any CollectionBase::getAnyItemOrThis( const uno::Any& rIndex ) throw (uno::RuntimeException) +{ + if( !rIndex.hasValue() ) + return uno::Any( uno::Reference< XCollectionBase >( this ) ); + if( rIndex.has< ::rtl::OUString >() ) + return getItemByName( rIndex.get< ::rtl::OUString >() ); + // extractIntFromAny() throws if no index can be extracted + return getItemByIndex( extractIntFromAny( rIndex ) ); +} + +// protected ------------------------------------------------------------------ + +uno::Any CollectionBase::implCreateCollectionItem( const uno::Any& /*rElement*/, const uno::Any& /*rIndex*/ ) throw (uno::RuntimeException) +{ + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Creation of VBA implementation object not implemented." ) ), 0 ); +} + +// ============================================================================ + +} // namespace vbahelper diff --git a/vbahelper/source/vbahelper/vbaapplicationbase.cxx b/vbahelper/source/vbahelper/vbaapplicationbase.cxx new file mode 100644 index 000000000000..5ae0a2c23890 --- /dev/null +++ b/vbahelper/source/vbahelper/vbaapplicationbase.cxx @@ -0,0 +1,445 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahelper/vbaapplicationbase.hxx" + +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/container/XEnumeration.hpp> +#include <com/sun/star/frame/XLayoutManager.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/document/XDocumentInfoSupplier.hpp> +#include <com/sun/star/document/XDocumentProperties.hpp> +#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> +#include <com/sun/star/awt/XWindow2.hpp> + +#include <hash_map> +#include <filter/msfilter/msvbahelper.hxx> +#include <tools/datetime.hxx> + +#include <basic/sbx.hxx> +#include <basic/sbstar.hxx> +#include <basic/sbuno.hxx> +#include <basic/sbmeth.hxx> +#include <basic/sbmod.hxx> +#include <basic/vbahelper.hxx> + +#include "vbacommandbars.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +#define OFFICEVERSION "11.0" + +// ====VbaTimerInfo================================== +typedef ::std::pair< ::rtl::OUString, ::std::pair< double, double > > VbaTimerInfo; + +// ====VbaTimer================================== +class VbaTimer +{ + Timer m_aTimer; + VbaTimerInfo m_aTimerInfo; + ::rtl::Reference< VbaApplicationBase > m_xBase; + + // the following declarations are here to prevent the usage of them + VbaTimer( const VbaTimer& ); + VbaTimer& operator=( const VbaTimer& ); + +public: + VbaTimer() + {} + + virtual ~VbaTimer() + { + m_aTimer.Stop(); + } + + static double GetNow() + { + Date aDateNow; + Time aTimeNow; + Date aRefDate( 1,1,1900 ); + long nDiffDays = (long)(aDateNow - aRefDate); + nDiffDays += 2; // Anpassung VisualBasic: 1.Jan.1900 == 2 + + long nDiffSeconds = aTimeNow.GetHour() * 3600 + aTimeNow.GetMin() * 60 + aTimeNow.GetSec(); + return (double)nDiffDays + ((double)nDiffSeconds)/(double)(24*3600); + } + + static sal_Int32 GetTimerMiliseconds( double nFrom, double nTo ) + { + double nResult = nTo - nFrom; + if ( nResult > 0 ) + nResult *= 24*3600*1000; + else + nResult = 50; + + return (sal_Int32) nResult; + } + + void Start( const ::rtl::Reference< VbaApplicationBase > xBase, const ::rtl::OUString& aFunction, double nFrom, double nTo ) + { + if ( !xBase.is() || !aFunction.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected arguments!" ) ), uno::Reference< uno::XInterface >() ); + + m_xBase = xBase; + m_aTimerInfo = VbaTimerInfo( aFunction, ::std::pair< double, double >( nFrom, nTo ) ); + m_aTimer.SetTimeoutHdl( LINK( this, VbaTimer, MacroCallHdl ) ); + m_aTimer.SetTimeout( GetTimerMiliseconds( GetNow(), nFrom ) ); + m_aTimer.Start(); + } + + DECL_LINK( MacroCallHdl, void* ); +}; + +IMPL_LINK( VbaTimer, MacroCallHdl, void*, EMPTYARG ) +{ + if ( m_aTimerInfo.second.second == 0 || GetNow() < m_aTimerInfo.second.second ) + { + uno::Any aDummyArg; + try + { + m_xBase->Run( m_aTimerInfo.first, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg, aDummyArg ); + } + catch( uno::Exception& ) + {} + } + + // mast be the last call in the method since it deletes the timer + try + { + m_xBase->OnTime( uno::makeAny( m_aTimerInfo.second.first ), m_aTimerInfo.first, uno::makeAny( m_aTimerInfo.second.second ), uno::makeAny( sal_False ) ); + } catch( uno::Exception& ) + {} + + return 0; +} + +// ====VbaTimerInfoHash================================== +struct VbaTimerInfoHash +{ + size_t operator()( const VbaTimerInfo& rTimerInfo ) const + { + return (size_t)rTimerInfo.first.hashCode() + + (size_t)rtl_str_hashCode_WithLength( (char*)&rTimerInfo.second.first, sizeof( double ) ) + + (size_t)rtl_str_hashCode_WithLength( (char*)&rTimerInfo.second.second, sizeof( double ) ); + } +}; + +// ====VbaTimerHashMap================================== +typedef ::std::hash_map< VbaTimerInfo, VbaTimer*, VbaTimerInfoHash, ::std::equal_to< VbaTimerInfo > > VbaTimerHashMap; + +// ====VbaApplicationBase_Impl================================== +struct VbaApplicationBase_Impl +{ + VbaTimerHashMap m_aTimerHash; + sal_Bool mbVisible; + + inline VbaApplicationBase_Impl() : mbVisible( sal_True ) {} + + virtual ~VbaApplicationBase_Impl() + { + // remove the remaining timers + for ( VbaTimerHashMap::iterator aIter = m_aTimerHash.begin(); + aIter != m_aTimerHash.end(); + aIter++ ) + { + delete aIter->second; + aIter->second = NULL; + } + } +}; + +// ====VbaApplicationBase================================== +VbaApplicationBase::VbaApplicationBase( const uno::Reference< uno::XComponentContext >& xContext ) + : ApplicationBase_BASE( uno::Reference< XHelperInterface >(), xContext ) + , m_pImpl( new VbaApplicationBase_Impl ) +{ +} + +VbaApplicationBase::~VbaApplicationBase() +{ + delete m_pImpl; +} + +sal_Bool SAL_CALL +VbaApplicationBase::getScreenUpdating() throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + return !xModel->hasControllersLocked(); +} + +void SAL_CALL +VbaApplicationBase::setScreenUpdating(sal_Bool bUpdate) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + // #163808# use helper from module "basic" to lock all documents of this application + ::basic::vba::lockControllersOfAllDocuments( xModel, !bUpdate ); +} + +sal_Bool SAL_CALL +VbaApplicationBase::getDisplayStatusBar() throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xFrame, uno::UNO_QUERY_THROW ); + + if( xProps.is() ){ + uno::Reference< frame::XLayoutManager > xLayoutManager( xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LayoutManager")) ), uno::UNO_QUERY_THROW ); + rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); + if( xLayoutManager.is() && xLayoutManager->isElementVisible( url ) ){ + return sal_True; + } + } + return sal_False; +} + +void SAL_CALL +VbaApplicationBase::setDisplayStatusBar(sal_Bool bDisplayStatusBar) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xFrame, uno::UNO_QUERY_THROW ); + + if( xProps.is() ){ + uno::Reference< frame::XLayoutManager > xLayoutManager( xProps->getPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LayoutManager")) ), uno::UNO_QUERY_THROW ); + rtl::OUString url(RTL_CONSTASCII_USTRINGPARAM( "private:resource/statusbar/statusbar" )); + if( xLayoutManager.is() ){ + if( bDisplayStatusBar && !xLayoutManager->isElementVisible( url ) ){ + if( !xLayoutManager->showElement( url ) ) + xLayoutManager->createElement( url ); + return; + } + else if( !bDisplayStatusBar && xLayoutManager->isElementVisible( url ) ){ + xLayoutManager->hideElement( url ); + return; + } + } + } + return; +} + +::sal_Bool SAL_CALL VbaApplicationBase::getInteractive() + throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XFrame > xFrame( xModel->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + uno::Reference< awt::XWindow2 > xWindow( xFrame->getContainerWindow(), uno::UNO_QUERY_THROW ); + + return xWindow->isEnabled(); +} + +void SAL_CALL VbaApplicationBase::setInteractive( ::sal_Bool bInteractive ) + throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + // #163808# use helper from module "basic" to enable/disable all container windows of all documents of this application + ::basic::vba::enableContainerWindowsOfAllDocuments( xModel, bInteractive ); +} + +sal_Bool SAL_CALL VbaApplicationBase::getVisible() throw (uno::RuntimeException) +{ + return m_pImpl->mbVisible; // dummy implementation +} + +void SAL_CALL VbaApplicationBase::setVisible( sal_Bool bVisible ) throw (uno::RuntimeException) +{ + m_pImpl->mbVisible = bVisible; // dummy implementation +} + +uno::Any SAL_CALL +VbaApplicationBase::CommandBars( const uno::Any& aIndex ) throw (uno::RuntimeException) +{ + uno::Reference< XCommandBars > xCommandBars( new ScVbaCommandBars( this, mxContext, uno::Reference< container::XIndexAccess >(), getCurrentDocument() ) ); + if( aIndex.hasValue() ) + return uno::makeAny( xCommandBars->Item( aIndex, uno::Any() ) ); + return uno::makeAny( xCommandBars ); +} + +::rtl::OUString SAL_CALL +VbaApplicationBase::getVersion() throw (uno::RuntimeException) +{ + return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(OFFICEVERSION)); +} + +void SAL_CALL VbaApplicationBase::Run( const ::rtl::OUString& MacroName, const uno::Any& varg1, const uno::Any& varg2, const uno::Any& varg3, const uno::Any& varg4, const uno::Any& varg5, const uno::Any& varg6, const uno::Any& varg7, const uno::Any& varg8, const uno::Any& varg9, const uno::Any& varg10, const uno::Any& varg11, const uno::Any& varg12, const uno::Any& varg13, const uno::Any& varg14, const uno::Any& varg15, const uno::Any& varg16, const uno::Any& varg17, const uno::Any& varg18, const uno::Any& varg19, const uno::Any& varg20, const uno::Any& varg21, const uno::Any& varg22, const uno::Any& varg23, const uno::Any& varg24, const uno::Any& varg25, const uno::Any& varg26, const uno::Any& varg27, const uno::Any& varg28, const uno::Any& varg29, const uno::Any& varg30 ) throw (uno::RuntimeException) +{ + ::rtl::OUString aMacroName = MacroName.trim(); + if (0 == aMacroName.indexOf('!')) + aMacroName = aMacroName.copy(1).trim(); + + uno::Reference< frame::XModel > xModel; + SbMethod* pMeth = StarBASIC::GetActiveMethod(); + if ( pMeth ) + { + SbModule* pMod = dynamic_cast< SbModule* >( pMeth->GetParent() ); + if ( pMod ) + xModel = StarBASIC::GetModelFromBasic( pMod ); + } + + if ( !xModel.is() ) + xModel = getCurrentDocument(); + + MacroResolvedInfo aMacroInfo = resolveVBAMacro( getSfxObjShell( xModel ), aMacroName ); + if( aMacroInfo.mbFound ) + { + // handle the arguments + const uno::Any* aArgsPtrArray[] = { &varg1, &varg2, &varg3, &varg4, &varg5, &varg6, &varg7, &varg8, &varg9, &varg10, &varg11, &varg12, &varg13, &varg14, &varg15, &varg16, &varg17, &varg18, &varg19, &varg20, &varg21, &varg22, &varg23, &varg24, &varg25, &varg26, &varg27, &varg28, &varg29, &varg30 }; + + int nArg = sizeof( aArgsPtrArray ) / sizeof( aArgsPtrArray[0] ); + uno::Sequence< uno::Any > aArgs( nArg ); + + const uno::Any** pArg = aArgsPtrArray; + const uno::Any** pArgEnd = ( aArgsPtrArray + nArg ); + + sal_Int32 nLastArgWithValue = 0; + sal_Int32 nArgProcessed = 0; + + for ( ; pArg != pArgEnd; ++pArg, ++nArgProcessed ) + { + aArgs[ nArgProcessed ] = **pArg; + if( (*pArg)->hasValue() ) + nLastArgWithValue = nArgProcessed; + } + + // resize array to position of last param with value + aArgs.realloc( nArgProcessed + 1 ); + + uno::Any aRet; + uno::Any aDummyCaller; + executeMacro( aMacroInfo.mpDocContext, aMacroInfo.msResolvedMacro, aArgs, aRet, aDummyCaller ); + } + else + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("The macro doesn't exist") ), uno::Reference< uno::XInterface >() ); + } +} + +void SAL_CALL VbaApplicationBase::OnTime( const uno::Any& aEarliestTime, const ::rtl::OUString& aFunction, const uno::Any& aLatestTime, const uno::Any& aSchedule ) + throw ( uno::RuntimeException ) +{ + if ( !aFunction.getLength() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Unexpected function name!" ) ), uno::Reference< uno::XInterface >() ); + + double nEarliestTime = 0; + double nLatestTime = 0; + if ( !( aEarliestTime >>= nEarliestTime ) + || ( aLatestTime.hasValue() && !( aLatestTime >>= nLatestTime ) ) ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Only double is supported as time for now!" ) ), uno::Reference< uno::XInterface >() ); + + sal_Bool bSetTimer = sal_True; + aSchedule >>= bSetTimer; + + VbaTimerInfo aTimerIndex( aFunction, ::std::pair< double, double >( nEarliestTime, nLatestTime ) ); + + VbaTimerHashMap::iterator aIter = m_pImpl->m_aTimerHash.find( aTimerIndex ); + if ( aIter != m_pImpl->m_aTimerHash.end() ) + { + delete aIter->second; + aIter->second = NULL; + m_pImpl->m_aTimerHash.erase( aIter ); + } + + if ( bSetTimer ) + { + VbaTimer* pTimer = new VbaTimer; + m_pImpl->m_aTimerHash[ aTimerIndex ] = pTimer; + pTimer->Start( this, aFunction, nEarliestTime, nLatestTime ); + } +} + +float SAL_CALL VbaApplicationBase::CentimetersToPoints( float _Centimeters ) throw (uno::RuntimeException) +{ + // i cm = 28.35 points + static const float rate = 28.35f; + return ( _Centimeters * rate ); +} + +uno::Any SAL_CALL VbaApplicationBase::getVBE() throw (uno::RuntimeException) +{ + try // return empty object on error + { + // "VBE" object does not have a parent, but pass document model to be able to determine application type + uno::Sequence< uno::Any > aArgs( 1 ); + aArgs[ 0 ] <<= getCurrentDocument(); + uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< uno::XInterface > xVBE = xServiceManager->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.vbide.VBE" ) ), aArgs, mxContext ); + return uno::Any( xVBE ); + } + catch( uno::Exception& ) + { + } + return uno::Any(); +} + +rtl::OUString& +VbaApplicationBase::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaApplicationBase") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> +VbaApplicationBase::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.VbaApplicationBase" ) ); + } + return aServiceNames; +} + +void SAL_CALL VbaApplicationBase::Undo() + throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + dispatchRequests( xModel, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:Undo" ) ) ); +} + +void VbaApplicationBase::Quit() throw (uno::RuntimeException) +{ + // need to stop basic + SbMethod* pMeth = StarBASIC::GetActiveMethod(); + if ( pMeth ) + { + SbModule* pMod = dynamic_cast< SbModule* >( pMeth->GetParent() ); + if ( pMod ) + { + StarBASIC* pBasic = dynamic_cast< StarBASIC* >( pMod->GetParent() ); + if ( pBasic ) + pBasic->QuitAndExitApplication(); + } + } +} + diff --git a/vbahelper/source/vbahelper/vbacolorformat.cxx b/vbahelper/source/vbahelper/vbacolorformat.cxx new file mode 100644 index 000000000000..c5924e4b7efd --- /dev/null +++ b/vbahelper/source/vbahelper/vbacolorformat.cxx @@ -0,0 +1,187 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/msforms/XLineFormat.hpp> +#include "vbacolorformat.hxx" + +using namespace ooo::vba; +using namespace com::sun::star; + +sal_Int32 +MsoColorIndizes::getColorIndex( sal_Int32 nIndex ) +{ + const static sal_Int32 COLORINDIZES[56] = + { HAPICOLOR_BLACK, HAPICOLOR_WITHE, HAPICOLOR_RED, HAPICOLOR_BRIGHTGREEN, HAPICOLOR_BLUE, HAPICOLOR_YELLOW, HAPICOLOR_PINK, + HAPICOLOR_TURQUOISE, HAPICOLOR_DARKRED, HAPICOLOR_GREEN, HAPICOLOR_DARKBLUE, HAPICOLOR_DARKYELLOW, HAPICOLOR_VIOLET, + HAPICOLOR_TEAL, HAPICOLOR_GRAY_25_PERCENT, HAPICOLOR_GRAY_50_PERCENT, HAPICOLOR_PERIWINCKLE, HAPICOLOR_PLUM, + HAPICOLOR_IVORY, HAPICOLOR_LIGHTTURQUOISE, HAPICOLOR_DARKPRUPLE, HAPICOLOR_CORAL, HAPICOLOR_OCEANBLUE, HAPICOLOR_ICEBLUE, + HAPICOLOR_GREEN, HAPICOLOR_PINK, HAPICOLOR_YELLOW, HAPICOLOR_TURQUOISE, HAPICOLOR_VIOLET, HAPICOLOR_DARKRED, HAPICOLOR_TEAL, + HAPICOLOR_BLUE, HAPICOLOR_SKYBLUE, HAPICOLOR_LIGHTTURQUOISE, HAPICOLOR_LIGHTGREEN, HAPICOLOR_LIGHTYELLOW, HAPICOLOR_PALEBLUE, + HAPICOLOR_ROSE, HAPICOLOR_LAVENDER, HAPICOLOR_TAN, HAPICOLOR_LIGHTBLUE, HAPICOLOR_AQUA, HAPICOLOR_LIME, HAPICOLOR_GOLD, + HAPICOLOR_LIGHTORANGE, HAPICOLOR_ORANGE, HAPICOLOR_BLUEGRAY, HAPICOLOR_GRAY_40_PERCENT, HAPICOLOR_DARKTEAL, + HAPICOLOR_SEAGREEN, HAPICOLOR_NONAME, HAPICOLOR_OLIVEGREEN, HAPICOLOR_BROWN, HAPICOLOR_PLUM, HAPICOLOR_INDIGO, + HAPICOLOR_GRAY_80_PERCENT + }; + return COLORINDIZES[nIndex]; +} +ScVbaColorFormat::ScVbaColorFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< XHelperInterface > xInternalParent, const uno::Reference< drawing::XShape > xShape, const sal_Int16 nColorFormatType ) : ScVbaColorFormat_BASE( xParent, xContext ), m_xInternalParent( xInternalParent ), m_xShape( xShape ), m_nColorFormatType( nColorFormatType ) +{ + m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW ); + m_nFillFormatBackColor = 0; + try + { + uno::Reference< ov::msforms::XFillFormat > xFillFormat( xInternalParent, uno::UNO_QUERY_THROW ); + m_pFillFormat = ( ScVbaFillFormat* )( xFillFormat.get() ); + }catch ( uno::RuntimeException e ) + { + m_pFillFormat = NULL; + } +} + +void +ScVbaColorFormat::setColorFormat( sal_Int16 _ntype ) +{ + m_nColorFormatType = _ntype; +} + +// Attribute +sal_Int32 SAL_CALL +ScVbaColorFormat::getRGB() throw (uno::RuntimeException) +{ + sal_Int32 nRGB = 0; + switch( m_nColorFormatType ) + { + case ColorFormatType::LINEFORMAT_FORECOLOR: + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("LineColor") ) >>= nRGB; + break; + case ColorFormatType::LINEFORMAT_BACKCOLOR: + //TODO BackColor not supported + // m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("Color"), uno::makeAny( nRGB ) ); + break; + case ColorFormatType::FILLFORMAT_FORECOLOR: + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("FillColor") ) >>= nRGB; + break; + case ColorFormatType::FILLFORMAT_BACKCOLOR: + nRGB = m_nFillFormatBackColor; + break; + default: + throw uno::RuntimeException( rtl::OUString::createFromAscii("Second parameter of ColorFormat is wrong."), uno::Reference< uno::XInterface >() ); + } + nRGB = OORGBToXLRGB( nRGB ); + return nRGB; +} + +void SAL_CALL +ScVbaColorFormat::setRGB( sal_Int32 _rgb ) throw (uno::RuntimeException) +{ + sal_Int32 nRGB = XLRGBToOORGB( _rgb ); + switch( m_nColorFormatType ) + { + case ColorFormatType::LINEFORMAT_FORECOLOR: + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineColor" ), uno::makeAny( nRGB ) ); + break; + case ColorFormatType::LINEFORMAT_BACKCOLOR: + // TODO BackColor not supported + break; + case ColorFormatType::FILLFORMAT_FORECOLOR: + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillColor" ), uno::makeAny( nRGB ) ); + if( m_pFillFormat ) + { + m_pFillFormat->setForeColorAndInternalStyle(nRGB); + } + break; + case ColorFormatType::FILLFORMAT_BACKCOLOR: + m_nFillFormatBackColor = nRGB; + if( m_pFillFormat ) + { + m_pFillFormat->setForeColorAndInternalStyle(nRGB); + } + break; + default: + throw uno::RuntimeException( rtl::OUString::createFromAscii("Second parameter of ColorFormat is wrong."), uno::Reference< uno::XInterface >() ); + } +} + +sal_Int32 SAL_CALL +ScVbaColorFormat::getSchemeColor() throw (uno::RuntimeException) +{ + sal_Int32 nColor = getRGB(); + // #TODO I guess the number of elements is determined by the correct scheme + // the implementation here seems to be a rehash of color index ( which seems to be a + // different thing ) - I would guess we need to know/import etc. the correct color scheme + // or at least find out a little more + sal_Int32 i = 0; + for( ; i < 56; i++ ) + { + if( nColor == MsoColorIndizes::getColorIndex(i) ) + break; + } + + if( i == 56 ) // this is most likely an error condition + --i; + return i; + // #TODO figure out what craziness is this, + // the 56 colors seems incorrect, as in default XL ( 2003 ) there are 80 colors +/* + if( i == 56 ) + { + i = -2; + } + + return ( i + 2 ); +*/ +} + +void SAL_CALL +ScVbaColorFormat::setSchemeColor( sal_Int32 _schemecolor ) throw (uno::RuntimeException) +{ + // the table is 0 based + sal_Int32 nColor = MsoColorIndizes::getColorIndex( _schemecolor ); + // nColor is already xl RGB + setRGB( nColor ); +} + + +rtl::OUString& +ScVbaColorFormat::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaColorFormat") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaColorFormat::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.ColorFormat" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/vbahelper/vbacolorformat.hxx b/vbahelper/source/vbahelper/vbacolorformat.hxx new file mode 100644 index 000000000000..01ca5a047e44 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacolorformat.hxx @@ -0,0 +1,125 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_XCOLORFORMAT_HXX +#define SC_VBA_XCOLORFORMAT_HXX + +#include <com/sun/star/drawing/XShape.hpp> +#include <ooo/vba/msforms/XColorFormat.hpp> +#include <ooo/vba/msforms/XFillFormat.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include "vbafillformat.hxx" + +typedef InheritedHelperInterfaceImpl1< ov::msforms::XColorFormat > ScVbaColorFormat_BASE; + +class ColorFormatType +{ +public: + const static sal_Int16 LINEFORMAT_FORECOLOR = 1; + const static sal_Int16 LINEFORMAT_BACKCOLOR = 2; + const static sal_Int16 FILLFORMAT_FORECOLOR = 3; + const static sal_Int16 FILLFORMAT_BACKCOLOR = 4; + const static sal_Int16 THREEDFORMAT_EXTRUSIONCOLOR = 5; +}; + +struct MsoColorIndizes +{ + const static sal_Int32 HAPICOLOR_BLACK = 0; + const static sal_Int32 HAPICOLOR_WITHE = 16777215; + const static sal_Int32 HAPICOLOR_RED = 16711680; + const static sal_Int32 HAPICOLOR_BRIGHTGREEN = 65280; + const static sal_Int32 HAPICOLOR_BLUE = 255; + const static sal_Int32 HAPICOLOR_YELLOW = 16776960; + const static sal_Int32 HAPICOLOR_PINK = 16711935; + const static sal_Int32 HAPICOLOR_TURQUOISE = 65535; + const static sal_Int32 HAPICOLOR_DARKRED = 8388608; + const static sal_Int32 HAPICOLOR_GREEN = 32768; + const static sal_Int32 HAPICOLOR_DARKBLUE = 128; + const static sal_Int32 HAPICOLOR_DARKYELLOW = 8421376; + const static sal_Int32 HAPICOLOR_VIOLET = 8388736; + const static sal_Int32 HAPICOLOR_TEAL = 32896; + const static sal_Int32 HAPICOLOR_GRAY_25_PERCENT = 12632256; + const static sal_Int32 HAPICOLOR_GRAY_50_PERCENT = 8421504; + const static sal_Int32 HAPICOLOR_PERIWINCKLE = 10066431; + const static sal_Int32 HAPICOLOR_PLUM = 10040166; + const static sal_Int32 HAPICOLOR_IVORY = 16777164; + const static sal_Int32 HAPICOLOR_LIGHTTURQUOISE = 13434879; + const static sal_Int32 HAPICOLOR_DARKPRUPLE = 6684774; + const static sal_Int32 HAPICOLOR_CORAL = 16744576; + const static sal_Int32 HAPICOLOR_OCEANBLUE = 26316; + const static sal_Int32 HAPICOLOR_ICEBLUE = 13421823; + const static sal_Int32 HAPICOLOR_SKYBLUE = 52479; + const static sal_Int32 HAPICOLOR_LIGHTGREEN = 13434828; + const static sal_Int32 HAPICOLOR_LIGHTYELLOW = 16777113; + const static sal_Int32 HAPICOLOR_PALEBLUE = 10079487; + const static sal_Int32 HAPICOLOR_ROSE = 16751052; + const static sal_Int32 HAPICOLOR_LAVENDER = 13408767; + const static sal_Int32 HAPICOLOR_TAN = 16764057; + const static sal_Int32 HAPICOLOR_LIGHTBLUE = 3368703; + const static sal_Int32 HAPICOLOR_AQUA = 3394764; + const static sal_Int32 HAPICOLOR_LIME = 10079232; + const static sal_Int32 HAPICOLOR_GOLD = 16763904; + const static sal_Int32 HAPICOLOR_LIGHTORANGE = 16750848; + const static sal_Int32 HAPICOLOR_ORANGE = 16737792; + const static sal_Int32 HAPICOLOR_BLUEGRAY = 6710937; + const static sal_Int32 HAPICOLOR_GRAY_40_PERCENT = 9868950; + const static sal_Int32 HAPICOLOR_DARKTEAL = 13158; + const static sal_Int32 HAPICOLOR_SEAGREEN = 3381606; + const static sal_Int32 HAPICOLOR_NONAME = 13056; + const static sal_Int32 HAPICOLOR_OLIVEGREEN = 3355392; + const static sal_Int32 HAPICOLOR_BROWN = 10040064; + const static sal_Int32 HAPICOLOR_INDIGO = 3355545; + const static sal_Int32 HAPICOLOR_GRAY_80_PERCENT = 3355443; + + static sal_Int32 getColorIndex( sal_Int32 nIndex ); + +}; + +class ScVbaColorFormat : public ScVbaColorFormat_BASE +{ +private: + css::uno::Reference< ov::XHelperInterface > m_xInternalParent; + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; + ScVbaFillFormat *m_pFillFormat; + sal_Int16 m_nColorFormatType; + sal_Int32 m_nFillFormatBackColor; +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + void setColorFormat( sal_Int16 nType ); +public: + ScVbaColorFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< ov::XHelperInterface > xInternalParent, const css::uno::Reference< css::drawing::XShape > xShape, const sal_Int16 nColorFormatType ); + + // Attributes + virtual sal_Int32 SAL_CALL getRGB() throw (css::uno::RuntimeException); + virtual void SAL_CALL setRGB( sal_Int32 _rgb ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getSchemeColor() throw (css::uno::RuntimeException); + virtual void SAL_CALL setSchemeColor( sal_Int32 _schemecolor ) throw (css::uno::RuntimeException); + +}; + +#endif//SC_VBA_XCOLORFORMAT_HXX diff --git a/vbahelper/source/vbahelper/vbacommandbar.cxx b/vbahelper/source/vbahelper/vbacommandbar.cxx new file mode 100644 index 000000000000..11cbacb79894 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbar.cxx @@ -0,0 +1,279 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacommandbar.hxx" +#include "vbacommandbarcontrols.hxx" +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/frame/XLayoutManager.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameContainer.hpp> +#include <ooo/vba/office/MsoBarType.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaCommandBar::ScVbaCommandBar( const uno::Reference< ov::XHelperInterface > xParent, const uno::Reference< uno::XComponentContext > xContext, VbaCommandBarHelperRef pHelper, const uno::Reference< container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Bool bIsMenu, sal_Bool bTemporary ) throw( uno::RuntimeException ) : CommandBar_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl ), m_bIsMenu( bIsMenu ), m_bTemporary( bTemporary ) +{ +} + +::rtl::OUString SAL_CALL +ScVbaCommandBar::getName() throw ( uno::RuntimeException ) +{ + // This will get a "NULL length string" when Name is not set. + uno::Reference< beans::XPropertySet > xPropertySet( m_xBarSettings, uno::UNO_QUERY_THROW ); + uno::Any aName = xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("UIName") ); + rtl::OUString sName; + aName >>= sName; + if( sName.getLength() < 1 ) + { + if( m_bIsMenu ) + { + if( m_sResourceUrl.equalsAscii( ITEM_MENUBAR_URL ) ) + { + if( pCBarHelper->getModuleId().equalsAscii("com.sun.star.sheet.SpreadsheetDocument") ) + sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Worksheet Menu Bar") ); + else if( pCBarHelper->getModuleId().equalsAscii("com.sun.star.text.TextDocument") ) + sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Menu Bar") ); + return sName; + } + } + // Toolbar name + uno::Reference< container::XNameAccess > xNameAccess = pCBarHelper->getPersistentWindowState(); + if( xNameAccess->hasByName( m_sResourceUrl ) ) + { + uno::Sequence< beans::PropertyValue > aToolBar; + xNameAccess->getByName( m_sResourceUrl ) >>= aToolBar; + getPropertyValue( aToolBar, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("UIName") ) ) >>= sName; + } + } + return sName; +} +void SAL_CALL +ScVbaCommandBar::setName( const ::rtl::OUString& _name ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xPropertySet( m_xBarSettings, uno::UNO_QUERY_THROW ); + xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("UIName"), uno::makeAny( _name ) ); + + pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); +} +::sal_Bool SAL_CALL +ScVbaCommandBar::getVisible() throw (uno::RuntimeException) +{ + // menu bar is allways visible in OOo + if( m_bIsMenu ) + return sal_True; + + sal_Bool bVisible = sal_False; + try + { + uno::Reference< container::XNameAccess > xNameAccess = pCBarHelper->getPersistentWindowState(); + if( xNameAccess->hasByName( m_sResourceUrl ) ) + { + uno::Sequence< beans::PropertyValue > aToolBar; + xNameAccess->getByName( m_sResourceUrl ) >>= aToolBar; + getPropertyValue( aToolBar, rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Visible") ) ) >>= bVisible; + } + } + catch ( uno::Exception e ) + { + } + return bVisible; +} +void SAL_CALL +ScVbaCommandBar::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException) +{ + try + { + uno::Reference< frame::XLayoutManager > xLayoutManager = pCBarHelper->getLayoutManager(); + if( _visible ) + { + xLayoutManager->createElement( m_sResourceUrl ); + xLayoutManager->showElement( m_sResourceUrl ); + } + else + { + xLayoutManager->hideElement( m_sResourceUrl ); + xLayoutManager->destroyElement( m_sResourceUrl ); + } + } + catch( uno::Exception e ) + { + OSL_TRACE( "SetVisible get an exception\n" ); + } +} + +::sal_Bool SAL_CALL +ScVbaCommandBar::getEnabled() throw (uno::RuntimeException) +{ + // emulated with Visible + return getVisible(); +} + +void SAL_CALL +ScVbaCommandBar::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) +{ + // emulated with Visible + setVisible( _enabled ); +} + +void SAL_CALL +ScVbaCommandBar::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + pCBarHelper->removeSettings( m_sResourceUrl ); + uno::Reference< container::XNameContainer > xNameContainer( pCBarHelper->getPersistentWindowState(), uno::UNO_QUERY_THROW ); + if( xNameContainer->hasByName( m_sResourceUrl ) ) + { + xNameContainer->removeByName( m_sResourceUrl ); + } +} +uno::Any SAL_CALL +ScVbaCommandBar::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, m_xBarSettings, pCBarHelper, m_xBarSettings, m_sResourceUrl ) ); + if( aIndex.hasValue() ) + { + return xCommandBarControls->Item( aIndex, uno::Any() ); + } + return uno::makeAny( xCommandBarControls ); +} + +sal_Int32 SAL_CALL +ScVbaCommandBar::Type() throw (script::BasicErrorException, uno::RuntimeException) +{ + // #FIXME support msoBarTypePopup + sal_Int32 nType = office::MsoBarType::msoBarTypePopup; + nType = m_bIsMenu? office::MsoBarType::msoBarTypeNormal : office::MsoBarType::msoBarTypeMenuBar; + return nType; +} + +uno::Any SAL_CALL +ScVbaCommandBar::FindControl( const uno::Any& /*aType*/, const uno::Any& /*aId*/, const uno::Any& /*aTag*/, const uno::Any& /*aVisible*/, const uno::Any& /*aRecursive*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // alwayse fail to find control + return uno::makeAny( uno::Reference< XCommandBarControl > () ); +} + +rtl::OUString& +ScVbaCommandBar::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBar") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaCommandBar::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBar" ) ); + } + return aServiceNames; +} + + +VbaDummyCommandBar::VbaDummyCommandBar( + const uno::Reference< ov::XHelperInterface > xParent, + const uno::Reference< uno::XComponentContext > xContext, + const ::rtl::OUString& rName, sal_Int32 nType ) throw( uno::RuntimeException ) : + CommandBar_BASE( xParent, xContext ), + maName( rName ), + mnType( nType ) +{ +} + +::rtl::OUString SAL_CALL VbaDummyCommandBar::getName() throw ( uno::RuntimeException ) +{ + return maName; +} + +void SAL_CALL VbaDummyCommandBar::setName( const ::rtl::OUString& _name ) throw (uno::RuntimeException) +{ + maName = _name; +} + +::sal_Bool SAL_CALL VbaDummyCommandBar::getVisible() throw (uno::RuntimeException) +{ + return sal_True; +} + +void SAL_CALL VbaDummyCommandBar::setVisible( ::sal_Bool /*_visible*/ ) throw (uno::RuntimeException) +{ +} + +::sal_Bool SAL_CALL VbaDummyCommandBar::getEnabled() throw (uno::RuntimeException) +{ + // emulated with Visible + return getVisible(); +} + +void SAL_CALL VbaDummyCommandBar::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) +{ + // emulated with Visible + setVisible( _enabled ); +} + +void SAL_CALL VbaDummyCommandBar::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // no-op +} + +uno::Any SAL_CALL VbaDummyCommandBar::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) +{ + uno::Reference< XCommandBarControls > xCommandBarControls( new VbaDummyCommandBarControls( this, mxContext ) ); + if( aIndex.hasValue() ) + return xCommandBarControls->Item( aIndex, uno::Any() ); + return uno::Any( xCommandBarControls ); +} + +sal_Int32 SAL_CALL VbaDummyCommandBar::Type() throw (script::BasicErrorException, uno::RuntimeException) +{ + return mnType; +} + +uno::Any SAL_CALL VbaDummyCommandBar::FindControl( const uno::Any& /*aType*/, const uno::Any& /*aId*/, const uno::Any& /*aTag*/, const uno::Any& /*aVisible*/, const uno::Any& /*aRecursive*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return uno::Any( uno::Reference< XCommandBarControl >() ); +} + +rtl::OUString& VbaDummyCommandBar::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaDummyCommandBar") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > VbaDummyCommandBar::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBar" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/vbahelper/vbacommandbar.hxx b/vbahelper/source/vbahelper/vbacommandbar.hxx new file mode 100644 index 000000000000..bcb5a11e9691 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbar.hxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_COMMANDBAR_HXX +#define SC_VBA_COMMANDBAR_HXX + +#include <ooo/vba/XCommandBar.hpp> +#include <com/sun/star/ui/XUIConfigurationManager.hpp> +#include <com/sun/star/ui/XUIConfigurationPersistence.hpp> +#include <com/sun/star/container/XIndexContainer.hpp> +#include <com/sun/star/beans/PropertyValues.hpp> + +#include <vbahelper/vbahelperinterface.hxx> +#include "vbacommandbarhelper.hxx" + +#include <map> + +typedef InheritedHelperInterfaceImpl1< ov::XCommandBar > CommandBar_BASE; + +class ScVbaCommandBar : public CommandBar_BASE +{ +private: + VbaCommandBarHelperRef pCBarHelper; + css::uno::Reference< css::container::XIndexAccess > m_xBarSettings; + rtl::OUString m_sResourceUrl; + sal_Bool m_bIsMenu; + sal_Bool m_bTemporary; + +public: + ScVbaCommandBar( const css::uno::Reference< ov::XHelperInterface > xParent, const css::uno::Reference< css::uno::XComponentContext > xContext, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Bool bIsMenu, sal_Bool bTemporary = sal_True ) throw( css::uno::RuntimeException ); + + sal_Bool IsMenu() { return m_bIsMenu; } + + // Attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& _name ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( ::sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getEnabled() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Controls( const css::uno::Any& aIndex ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL Type( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL FindControl( const css::uno::Any& aType, const css::uno::Any& aId, const css::uno::Any& aTag, const css::uno::Any& aVisible, const css::uno::Any& aRecursive ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +/** Dummy command bar implementation. Does nothing but provide its name. */ +class VbaDummyCommandBar : public CommandBar_BASE +{ +public: + VbaDummyCommandBar( + const css::uno::Reference< ov::XHelperInterface > xParent, + const css::uno::Reference< css::uno::XComponentContext > xContext, + const ::rtl::OUString& rName, + sal_Int32 nType ) throw( css::uno::RuntimeException ); + + // Attributes + virtual ::rtl::OUString SAL_CALL getName() throw (css::uno::RuntimeException); + virtual void SAL_CALL setName( const ::rtl::OUString& _name ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( ::sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getEnabled() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Controls( const css::uno::Any& aIndex ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL Type( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL FindControl( const css::uno::Any& aType, const css::uno::Any& aId, const css::uno::Any& aTag, const css::uno::Any& aVisible, const css::uno::Any& aRecursive ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +private: + ::rtl::OUString maName; + sal_Int32 mnType; +}; + +#endif//SC_VBA_COMMANDBAR_HXX diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx b/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx new file mode 100644 index 000000000000..d57bc00644a5 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbarcontrol.cxx @@ -0,0 +1,259 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacommandbarcontrol.hxx" +#include "vbacommandbarcontrols.hxx" +#include <vbahelper/vbahelper.hxx> +#include <filter/msfilter/msvbahelper.hxx> + +using namespace com::sun::star; +using namespace ooo::vba; + +ScVbaCommandBarControl::ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl ) throw (css::uno::RuntimeException) : CommandBarControl_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_sResourceUrl( sResourceUrl ), m_xCurrentSettings( xSettings ), m_xBarSettings( xBarSettings ), m_nPosition( 0 ), m_bTemporary( sal_True ) +{ +} + +ScVbaCommandBarControl::ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarControl_BASE( xParent, xContext ), pCBarHelper( pHelper ), m_sResourceUrl( sResourceUrl ), m_xCurrentSettings( xSettings ), m_xBarSettings( xBarSettings ), m_nPosition( nPosition ), m_bTemporary( bTemporary ) +{ + m_xCurrentSettings->getByIndex( nPosition ) >>= m_aPropertyValues; +} + +void ScVbaCommandBarControl::ApplyChange() throw ( uno::RuntimeException ) +{ + uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW ); + xIndexContainer->replaceByIndex( m_nPosition, uno::makeAny( m_aPropertyValues ) ); + pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); +} + +::rtl::OUString SAL_CALL +ScVbaCommandBarControl::getCaption() throw ( uno::RuntimeException ) +{ + // "Label" always empty + rtl::OUString sCaption; + getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("Label") ) >>= sCaption; + return sCaption; +} + +void SAL_CALL +ScVbaCommandBarControl::setCaption( const ::rtl::OUString& _caption ) throw (uno::RuntimeException) +{ + rtl::OUString sCaption = _caption.replace('&','~'); + setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("Label"), uno::makeAny( sCaption ) ); + ApplyChange(); +} + +::rtl::OUString SAL_CALL +ScVbaCommandBarControl::getOnAction() throw (uno::RuntimeException) +{ + rtl::OUString sCommandURL; + getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL") ) >>= sCommandURL; + return sCommandURL; +} + +void SAL_CALL +ScVbaCommandBarControl::setOnAction( const ::rtl::OUString& _onaction ) throw (uno::RuntimeException) +{ + // get the current model + uno::Reference< frame::XModel > xModel( pCBarHelper->getModel() ); + MacroResolvedInfo aResolvedMacro = ooo::vba::resolveVBAMacro( getSfxObjShell( xModel ), _onaction, true ); + if ( aResolvedMacro.mbFound ) + { + rtl::OUString aCommandURL = ooo::vba::makeMacroURL( aResolvedMacro.msResolvedMacro ); + OSL_TRACE(" ScVbaCommandBarControl::setOnAction: %s", rtl::OUStringToOString( aCommandURL, RTL_TEXTENCODING_UTF8 ).getStr() ); + setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii("CommandURL"), uno::makeAny( aCommandURL ) ); + ApplyChange(); + } +} + +::sal_Bool SAL_CALL +ScVbaCommandBarControl::getVisible() throw (uno::RuntimeException) +{ + sal_Bool bVisible = sal_True; + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); + if( aValue.hasValue() ) + aValue >>= bVisible; + return bVisible; +} +void SAL_CALL +ScVbaCommandBarControl::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException) +{ + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ) ); + if( aValue.hasValue() ) + { + setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ), uno::makeAny( _visible ) ); + ApplyChange(); + } +} + +::sal_Bool SAL_CALL +ScVbaCommandBarControl::getEnabled() throw (uno::RuntimeException) +{ + sal_Bool bEnabled = sal_True; + + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); + if( aValue.hasValue() ) + { + aValue >>= bEnabled; + } + else + { + // emulated with Visible + bEnabled = getVisible(); + } + return bEnabled; +} + +void SAL_CALL +ScVbaCommandBarControl::setEnabled( sal_Bool _enabled ) throw (uno::RuntimeException) +{ + uno::Any aValue = getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ) ); + if( aValue.hasValue() ) + { + setPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ), uno::makeAny( _enabled ) ); + ApplyChange(); + } + else + { + // emulated with Visible + setVisible( _enabled ); + } +} + +::sal_Bool SAL_CALL +ScVbaCommandBarControl::getBeginGroup() throw (css::uno::RuntimeException) +{ + // TODO: need to check if the item before this item is of type 'separator' + return sal_False; +} + +void SAL_CALL +ScVbaCommandBarControl::setBeginGroup( ::sal_Bool _begin ) throw (css::uno::RuntimeException) +{ + if( getBeginGroup() != _begin ) + { + // TODO: need to insert or remove an item of type 'separator' before this item + } +} + +void SAL_CALL +ScVbaCommandBarControl::Delete( ) throw (script::BasicErrorException, uno::RuntimeException) +{ + if( m_xCurrentSettings.is() ) + { + uno::Reference< container::XIndexContainer > xIndexContainer( m_xCurrentSettings, uno::UNO_QUERY_THROW ); + xIndexContainer->removeByIndex( m_nPosition ); + + pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); + } +} + +uno::Any SAL_CALL +ScVbaCommandBarControl::Controls( const uno::Any& aIndex ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // only Popup Menu has controls + uno::Reference< container::XIndexAccess > xSubMenu; + getPropertyValue( m_aPropertyValues, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu; + if( !xSubMenu.is() ) + throw uno::RuntimeException(); + + uno::Reference< XCommandBarControls > xCommandBarControls( new ScVbaCommandBarControls( this, mxContext, xSubMenu, pCBarHelper, m_xBarSettings, m_sResourceUrl ) ); + if( aIndex.hasValue() ) + { + return xCommandBarControls->Item( aIndex, uno::Any() ); + } + return uno::makeAny( xCommandBarControls ); +} + +rtl::OUString& +ScVbaCommandBarControl::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarControl") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> +ScVbaCommandBarControl::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarControl" ) ); + } + return aServiceNames; +} + +//////////// ScVbaCommandBarPopup ////////////////////////////// +ScVbaCommandBarPopup::ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarPopup_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) +{ + m_nPosition = nPosition; + m_bTemporary = bTemporary; + m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; +} + +rtl::OUString& +ScVbaCommandBarPopup::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarPopup") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaCommandBarPopup::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarPopup" ) ); + } + return aServiceNames; +} + +//////////// ScVbaCommandBarButton ////////////////////////////// +ScVbaCommandBarButton::ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException) : CommandBarButton_BASE( xParent, xContext, xSettings, pHelper, xBarSettings, sResourceUrl ) +{ + m_nPosition = nPosition; + m_bTemporary = bTemporary; + m_xCurrentSettings->getByIndex( m_nPosition ) >>= m_aPropertyValues; +} + +rtl::OUString& +ScVbaCommandBarButton::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarButton") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaCommandBarButton::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarButton" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrol.hxx b/vbahelper/source/vbahelper/vbacommandbarcontrol.hxx new file mode 100644 index 000000000000..5066ba75eea0 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbarcontrol.hxx @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_COMMANDBARCONTROL_HXX +#define SC_VBA_COMMANDBARCONTROL_HXX + +#include <ooo/vba/XCommandBarControl.hpp> +#include <ooo/vba/XCommandBarPopup.hpp> +#include <ooo/vba/XCommandBarButton.hpp> +#include <ooo/vba/office/MsoControlType.hpp> +#include <com/sun/star/awt/XMenu.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include "vbacommandbarhelper.hxx" +#include <cppuhelper/implbase1.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::XCommandBarControl > CommandBarControl_BASE; + +class ScVbaCommandBarControl : public CommandBarControl_BASE +{ +protected: + VbaCommandBarHelperRef pCBarHelper; + rtl::OUString m_sResourceUrl; + css::uno::Reference< css::container::XIndexAccess > m_xCurrentSettings; + css::uno::Reference< css::container::XIndexAccess > m_xBarSettings; + css::uno::Sequence< css::beans::PropertyValue > m_aPropertyValues; + + sal_Int32 m_nPosition; + sal_Bool m_bTemporary; + +private: + void ApplyChange() throw (css::uno::RuntimeException); + +public: + ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl ) throw (css::uno::RuntimeException); + ScVbaCommandBarControl( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException); + + // Attributes + virtual ::rtl::OUString SAL_CALL getCaption() throw (css::uno::RuntimeException); + virtual void SAL_CALL setCaption( const ::rtl::OUString& _caption ) throw (css::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getOnAction() throw (css::uno::RuntimeException); + virtual void SAL_CALL setOnAction( const ::rtl::OUString& _onaction ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( ::sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getEnabled() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEnabled( ::sal_Bool _enabled ) throw (css::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL getBeginGroup() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBeginGroup( ::sal_Bool _begin ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException) + { + return ov::office::MsoControlType::msoControlButton; + } + + // Methods + virtual void SAL_CALL Delete( ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Controls( const css::uno::Any& aIndex ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +typedef cppu::ImplInheritanceHelper1< ScVbaCommandBarControl, ov::XCommandBarPopup > CommandBarPopup_BASE; +class ScVbaCommandBarPopup : public CommandBarPopup_BASE +{ +public: + ScVbaCommandBarPopup( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException) + { + return ov::office::MsoControlType::msoControlPopup; + } + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +typedef cppu::ImplInheritanceHelper1< ScVbaCommandBarControl, ov::XCommandBarButton > CommandBarButton_BASE; +class ScVbaCommandBarButton : public CommandBarButton_BASE +{ +public: + ScVbaCommandBarButton( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xSettings, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl, sal_Int32 nPosition, sal_Bool bTemporary ) throw (css::uno::RuntimeException); + + virtual sal_Int32 SAL_CALL getType() throw (css::uno::RuntimeException) + { + return ov::office::MsoControlType::msoControlButton; + } + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif//SC_VBA_COMMANDBARCONTROL_HXX diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx new file mode 100644 index 000000000000..da218d007736 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbarcontrols.cxx @@ -0,0 +1,329 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacommandbarcontrols.hxx" +#include "vbacommandbarcontrol.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > CommandBarControlEnumeration_BASE; +class CommandBarControlEnumeration : public CommandBarControlEnumeration_BASE +{ + //uno::Reference< uno::XComponentContext > m_xContext; + CommandBarControls_BASE* m_pCommandBarControls; + sal_Int32 m_nCurrentPosition; +public: + CommandBarControlEnumeration( CommandBarControls_BASE* pCommandBarControls ) : m_pCommandBarControls( pCommandBarControls ), m_nCurrentPosition( 0 ) {} + virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException ) + { + if( m_nCurrentPosition < m_pCommandBarControls->getCount() ) + return sal_True; + return sal_False; + } + virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) + { + if( hasMoreElements() ) + { + return m_pCommandBarControls->createCollectionObject( uno::makeAny( m_nCurrentPosition++ ) ); + } + else + throw container::NoSuchElementException(); + } +}; + +ScVbaCommandBarControls::ScVbaCommandBarControls( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess>& xIndexAccess, VbaCommandBarHelperRef pHelper, const uno::Reference< container::XIndexAccess>& xBarSettings, const rtl::OUString& sResourceUrl ) throw (uno::RuntimeException) : CommandBarControls_BASE( xParent, xContext, xIndexAccess ), pCBarHelper( pHelper ), m_xBarSettings( xBarSettings ), m_sResourceUrl( sResourceUrl ) +{ + m_bIsMenu = sResourceUrl.equalsAscii( ITEM_MENUBAR_URL ) ? sal_True : sal_False; +} + +uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateMenuItemData( const rtl::OUString& sCommandURL, + const rtl::OUString& sHelpURL, + const rtl::OUString& sLabel, + sal_uInt16 nType, + const uno::Any& aSubMenu, + sal_Bool isVisible, + sal_Bool isEnabled ) +{ + uno::Sequence< beans::PropertyValue > aProps(7); + + aProps[0].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_COMMANDURL ); + aProps[0].Value <<= sCommandURL; + aProps[1].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_HELPURL ); + aProps[1].Value <<= sHelpURL; + aProps[2].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_LABEL ); + aProps[2].Value <<= sLabel; + aProps[3].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_TYPE ); + aProps[3].Value <<= nType; + aProps[4].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ); + aProps[4].Value = aSubMenu; + aProps[5].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ); + aProps[5].Value <<= isVisible; + aProps[6].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ENABLED ); + aProps[6].Value <<= isEnabled; + + return aProps; +} + +uno::Sequence< beans::PropertyValue > ScVbaCommandBarControls::CreateToolbarItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const uno::Any& aSubMenu, sal_Bool isVisible, sal_Int32 nStyle ) +{ + uno::Sequence< beans::PropertyValue > aProps(7); + + aProps[0].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_COMMANDURL ); + aProps[0].Value <<= sCommandURL; + aProps[1].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_HELPURL ); + aProps[1].Value <<= sHelpURL; + aProps[2].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_LABEL ); + aProps[2].Value <<= sLabel; + aProps[3].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_TYPE ); + aProps[3].Value <<= nType; + aProps[4].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ); + aProps[4].Value = aSubMenu; + aProps[5].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_ISVISIBLE ); + aProps[5].Value <<= isVisible; + aProps[6].Name = rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_STYLE ); + aProps[6].Value <<= nStyle; + + return aProps; +} + +// XEnumerationAccess +uno::Type SAL_CALL +ScVbaCommandBarControls::getElementType() throw ( uno::RuntimeException ) +{ + return XCommandBarControl::static_type( 0 ); +} + +uno::Reference< container::XEnumeration > +ScVbaCommandBarControls::createEnumeration() throw ( uno::RuntimeException ) +{ + return uno::Reference< container::XEnumeration >( new CommandBarControlEnumeration( this ) ); +} + +uno::Any +ScVbaCommandBarControls::createCollectionObject( const uno::Any& aSource ) +{ + sal_Int32 nPosition = -1; + aSource >>= nPosition; + uno::Sequence< beans::PropertyValue > aProps; + m_xIndexAccess->getByIndex( nPosition ) >>= aProps; + uno::Reference< container::XIndexAccess > xSubMenu; + getPropertyValue( aProps, rtl::OUString::createFromAscii( ITEM_DESCRIPTOR_CONTAINER ) ) >>= xSubMenu; + ScVbaCommandBarControl* pNewCommandBarControl = NULL; + if( xSubMenu.is() ) + pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True ); + else + pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, sal_True ); + + return uno::makeAny( uno::Reference< XCommandBarControl > ( pNewCommandBarControl ) ); +} + +// Methods +uno::Any SAL_CALL +ScVbaCommandBarControls::Item( const uno::Any& aIndex, const uno::Any& /*aIndex*/ ) throw (uno::RuntimeException) +{ + sal_Int32 nPosition = -1; + if( aIndex.getValueTypeClass() == uno::TypeClass_STRING ) + { + rtl::OUString sName; + aIndex >>= sName; + nPosition = VbaCommandBarHelper::findControlByName( m_xIndexAccess, sName, m_bIsMenu ); + } + else + { + aIndex >>= nPosition; + } + + if( nPosition < 0 || nPosition >= getCount() ) + { + throw uno::RuntimeException(); + } + + return createCollectionObject( uno::makeAny( nPosition ) ); +} + +uno::Reference< XCommandBarControl > SAL_CALL +ScVbaCommandBarControls::Add( const uno::Any& Type, const uno::Any& Id, const uno::Any& Parameter, const uno::Any& Before, const uno::Any& Temporary ) throw (script::BasicErrorException, uno::RuntimeException) +{ + // Parameter is not supported + // the following name needs to be individually created; + rtl::OUString sLabel( rtl::OUString::createFromAscii("Custom") ); + rtl::OUString sCommandUrl = rtl::OUString::createFromAscii( CUSTOM_MENU_STR ) + sLabel; + sal_Int32 nType = office::MsoControlType::msoControlButton; + sal_Int32 nPosition = 0; + sal_Bool bTemporary = sal_True; + + if( Type.hasValue() ) + { + Type >>= nType; + } + + if( nType != office::MsoControlType::msoControlButton && + nType != office::MsoControlType::msoControlPopup ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + + if( Id.hasValue() || Parameter.hasValue( ) ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + + if( Before.hasValue() ) + Before >>= nPosition; + else + nPosition = m_xIndexAccess->getCount(); + + if( Temporary.hasValue() ) + Temporary >>= bTemporary; + + uno::Any aSubMenu; + if( nType == office::MsoControlType::msoControlPopup ) + { + // it is a Popmenu + uno::Reference< lang::XSingleComponentFactory > xSCF( m_xBarSettings, uno::UNO_QUERY_THROW ); + aSubMenu <<= xSCF->createInstanceWithContext( mxContext ); + } + + // create control + uno::Sequence< beans::PropertyValue > aProps; + rtl::OUString sHelpUrl; + sal_uInt16 nItemType = 0; + if( IsMenu() ) + { + aProps = CreateMenuItemData( sCommandUrl, sHelpUrl, sLabel, nItemType, aSubMenu, true, true ); + } + else + { + sal_Bool isVisible = sal_True; + sal_Int32 nStyle = 0; + aProps = CreateToolbarItemData( sCommandUrl, sHelpUrl, sLabel, nItemType, aSubMenu, isVisible, nStyle ); + } + + + uno::Reference< container::XIndexContainer > xIndexContainer( m_xIndexAccess, uno::UNO_QUERY_THROW ); + xIndexContainer->insertByIndex( nPosition, uno::makeAny( aProps ) ); + + pCBarHelper->ApplyChange( m_sResourceUrl, m_xBarSettings ); + + ScVbaCommandBarControl* pNewCommandBarControl = NULL; + if( nType == office::MsoControlType::msoControlPopup ) + pNewCommandBarControl = new ScVbaCommandBarPopup( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary ); + else + pNewCommandBarControl = new ScVbaCommandBarButton( this, mxContext, m_xIndexAccess, pCBarHelper, m_xBarSettings, m_sResourceUrl, nPosition, bTemporary ); + + return uno::Reference< XCommandBarControl >( pNewCommandBarControl ); +} + +// XHelperInterface +rtl::OUString& +ScVbaCommandBarControls::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBarControls") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaCommandBarControls::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarControls" ) ); + } + return aServiceNames; +} + +// ============================================================================ + +class VbaDummyIndexAccess : public ::cppu::WeakImplHelper1< container::XIndexAccess > +{ +public: + inline VbaDummyIndexAccess() {} + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { return 0; } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { throw lang::IndexOutOfBoundsException(); } + // XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { return XCommandBarControl::static_type( 0 ); } + virtual ::sal_Bool SAL_CALL hasElements( ) throw (::com::sun::star::uno::RuntimeException) + { return false; } +}; + +// ---------------------------------------------------------------------------- + +VbaDummyCommandBarControls::VbaDummyCommandBarControls( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) : + CommandBarControls_BASE( xParent, xContext, new VbaDummyIndexAccess ) +{ +} + +// XEnumerationAccess +uno::Type SAL_CALL VbaDummyCommandBarControls::getElementType() throw ( uno::RuntimeException ) +{ + return XCommandBarControl::static_type( 0 ); +} + +uno::Reference< container::XEnumeration > VbaDummyCommandBarControls::createEnumeration() throw ( uno::RuntimeException ) +{ + return uno::Reference< container::XEnumeration >( new CommandBarControlEnumeration( this ) ); +} + +uno::Any VbaDummyCommandBarControls::createCollectionObject( const uno::Any& /*aSource*/ ) +{ + return uno::Any( uno::Reference< XCommandBarControl >() ); +} + +// Methods +uno::Any SAL_CALL VbaDummyCommandBarControls::Item( const uno::Any& /*aIndex*/, const uno::Any& /*aIndex*/ ) throw (uno::RuntimeException) +{ + return uno::Any( uno::Reference< XCommandBarControl >() ); +} + +uno::Reference< XCommandBarControl > SAL_CALL VbaDummyCommandBarControls::Add( + const uno::Any& /*Type*/, const uno::Any& /*Id*/, const uno::Any& /*Parameter*/, const uno::Any& /*Before*/, const uno::Any& /*Temporary*/ ) throw (script::BasicErrorException, uno::RuntimeException) +{ + return uno::Reference< XCommandBarControl >(); +} + +// XHelperInterface +rtl::OUString& VbaDummyCommandBarControls::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaDummyCommandBarControls") ); + return sImplName; +} + +uno::Sequence<rtl::OUString> VbaDummyCommandBarControls::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBarControls" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/vbahelper/vbacommandbarcontrols.hxx b/vbahelper/source/vbahelper/vbacommandbarcontrols.hxx new file mode 100644 index 000000000000..79a4a8c5a5fe --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbarcontrols.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_COMMANDBARCONTROLS_HXX +#define SC_VBA_COMMANDBARCONTROLS_HXX + +#include <ooo/vba/XCommandBarControls.hpp> +#include <com/sun/star/awt/XMenu.hpp> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> +#include "vbacommandbarhelper.hxx" + +typedef CollTestImplHelper< ov::XCommandBarControls > CommandBarControls_BASE; + +class ScVbaCommandBarControls : public CommandBarControls_BASE +{ +private: + VbaCommandBarHelperRef pCBarHelper; + css::uno::Reference< css::container::XIndexAccess > m_xBarSettings; + rtl::OUString m_sResourceUrl; + sal_Bool m_bIsMenu; + + css::uno::Sequence< css::beans::PropertyValue > CreateMenuItemData( const rtl::OUString& sCommandURL, + const rtl::OUString& sHelpURL, + const rtl::OUString& sLabel, + sal_uInt16 nType, + const css::uno::Any& aSubMenu, + sal_Bool isVisible, + sal_Bool isEnabled ); + css::uno::Sequence< css::beans::PropertyValue > CreateToolbarItemData( const rtl::OUString& sCommandURL, const rtl::OUString& sHelpURL, const rtl::OUString& sLabel, sal_uInt16 nType, const css::uno::Any& aSubMenu, sal_Bool isVisible, sal_Int32 nStyle ); + +public: + ScVbaCommandBarControls( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, VbaCommandBarHelperRef pHelper, const css::uno::Reference< css::container::XIndexAccess >& xBarSettings, const rtl::OUString& sResourceUrl ) throw( css::uno::RuntimeException ); + sal_Bool IsMenu(){ return m_bIsMenu; } + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // Methods + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index, const css::uno::Any& /*Index2*/ ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::XCommandBarControl > SAL_CALL Add( const css::uno::Any& Type, const css::uno::Any& Id, const css::uno::Any& Parameter, const css::uno::Any& Before, const css::uno::Any& Temporary ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +class VbaDummyCommandBarControls : public CommandBarControls_BASE +{ +public: + VbaDummyCommandBarControls( + const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext ) throw( css::uno::RuntimeException ); + + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + // Methods + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Index, const css::uno::Any& /*Index2*/ ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::XCommandBarControl > SAL_CALL Add( const css::uno::Any& Type, const css::uno::Any& Id, const css::uno::Any& Parameter, const css::uno::Any& Before, const css::uno::Any& Temporary ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif//SC_VBA_COMMANDBARCONTROLS_HXX diff --git a/vbahelper/source/vbahelper/vbacommandbarhelper.cxx b/vbahelper/source/vbahelper/vbacommandbarhelper.cxx new file mode 100644 index 000000000000..385b220d201c --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbarhelper.cxx @@ -0,0 +1,277 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbacommandbarhelper.hxx" +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/ui/XUIConfigurationStorage.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManager.hpp> +#include <com/sun/star/ui/XUIConfigurationPersistence.hpp> +#include <com/sun/star/ui/XUIElement.hpp> +#include <com/sun/star/ui/UIElementType.hpp> +#include <comphelper/processfactory.hxx> +#include <vbahelper/vbahelper.hxx> +#include <rtl/ustrbuf.hxx> +#include <time.h> +#include <map> + +using namespace com::sun::star; +using namespace ooo::vba; + +#define CREATEOUSTRING(asciistr) rtl::OUString::createFromAscii(asciistr) + +typedef std::map< rtl::OUString, rtl::OUString > MSO2OOCommandbarMap; + +class MSO2OOCommandbarHelper +{ +private: + static MSO2OOCommandbarHelper* pMSO2OOCommandbarHelper; + MSO2OOCommandbarMap maBuildinToolbarMap; + + MSO2OOCommandbarHelper() + { + // Buildin toolbars + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Standard"),CREATEOUSTRING("private:resource/toolbar/standardbar") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Formatting"),CREATEOUSTRING("private:resource/toolbar/formatobjectbar") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Drawing"),CREATEOUSTRING("private:resource/toolbar/drawbar") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Toolbar List"),CREATEOUSTRING("private:resource/toolbar/toolbar") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Forms"),CREATEOUSTRING("private:resource/toolbar/formcontrols") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Form Controls"),CREATEOUSTRING("private:resource/toolbar/formcontrols") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Full Screen"),CREATEOUSTRING("private:resource/toolbar/fullscreenbar") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Chart"),CREATEOUSTRING("private:resource/toolbar/flowchartshapes") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("Picture"),CREATEOUSTRING("private:resource/toolbar/graphicobjectbar") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("WordArt"),CREATEOUSTRING("private:resource/toolbar/fontworkobjectbar") ) ); + maBuildinToolbarMap.insert( std::make_pair( CREATEOUSTRING("3-D Settings"),CREATEOUSTRING("private:resource/toolbar/extrusionobjectbar") ) ); + } + +public: + virtual ~MSO2OOCommandbarHelper() {}; + static MSO2OOCommandbarHelper* getMSO2OOCommandbarHelper() + { + if( pMSO2OOCommandbarHelper == NULL ) + { + pMSO2OOCommandbarHelper = new MSO2OOCommandbarHelper(); + } + return pMSO2OOCommandbarHelper; + } + + rtl::OUString findBuildinToolbar( const rtl::OUString& sToolbarName ) + { + MSO2OOCommandbarMap::iterator it = maBuildinToolbarMap.begin(); + for(; it != maBuildinToolbarMap.end(); it++ ) + { + rtl::OUString sName = it->first; + if( sName.equalsIgnoreAsciiCase( sToolbarName ) ) + return it->second; + } + return rtl::OUString(); + } +}; + +MSO2OOCommandbarHelper* MSO2OOCommandbarHelper::pMSO2OOCommandbarHelper = NULL; + + +VbaCommandBarHelper::VbaCommandBarHelper( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException) : mxContext( xContext ), mxModel( xModel ) +{ + Init(); +} + +void VbaCommandBarHelper::Init( ) throw (css::uno::RuntimeException) +{ + uno::Reference< css::ui::XUIConfigurationManagerSupplier > xUICfgSupplier( mxModel, uno::UNO_QUERY_THROW ); + m_xDocCfgMgr = xUICfgSupplier->getUIConfigurationManager(); + + uno::Reference< lang::XServiceInfo > xServiceInfo( mxModel, uno::UNO_QUERY_THROW ); + if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument") ) ) ) + { + maModuleId = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument") ); + } + else if( xServiceInfo->supportsService( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) ) + { + maModuleId = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument") ); + } + + if( maModuleId.getLength() == 0 ) + { + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + } + + uno::Reference< lang::XMultiServiceFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + + css::uno::Reference< css::ui::XModuleUIConfigurationManagerSupplier > xUICfgMgrSupp( xServiceManager->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" ))), uno::UNO_QUERY_THROW ); + + m_xAppCfgMgr.set( xUICfgMgrSupp->getUIConfigurationManager( maModuleId ), uno::UNO_QUERY_THROW ); + + css::uno::Reference< css::container::XNameAccess > xNameAccess( xServiceManager->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.WindowStateConfiguration" ))), uno::UNO_QUERY_THROW ); + + m_xWindowState.set( xNameAccess->getByName( maModuleId ), uno::UNO_QUERY_THROW ); +} + +css::uno::Reference< css::container::XIndexAccess > VbaCommandBarHelper::getSettings( const rtl::OUString& sResourceUrl ) throw (css::uno::RuntimeException) +{ + if( m_xDocCfgMgr->hasSettings( sResourceUrl ) ) + return m_xDocCfgMgr->getSettings( sResourceUrl, sal_True ); + else if( m_xAppCfgMgr->hasSettings( sResourceUrl ) ) + return m_xAppCfgMgr->getSettings( sResourceUrl, sal_True ); + else + { + css::uno::Reference< css::container::XIndexAccess > xSettings( m_xAppCfgMgr->createSettings( ), uno::UNO_QUERY_THROW ); + return xSettings; + } +} + +void VbaCommandBarHelper::removeSettings( const rtl::OUString& sResourceUrl ) throw (css::uno::RuntimeException) +{ + if( m_xDocCfgMgr->hasSettings( sResourceUrl ) ) + m_xDocCfgMgr->removeSettings( sResourceUrl ); + else if( m_xAppCfgMgr->hasSettings( sResourceUrl ) ) + m_xAppCfgMgr->removeSettings( sResourceUrl ); + + // persistChanges(); +} + +void VbaCommandBarHelper::ApplyChange( const rtl::OUString& sResourceUrl, const css::uno::Reference< css::container::XIndexAccess >& xSettings, sal_Bool bTemporary ) throw (css::uno::RuntimeException) +{ + if( m_xDocCfgMgr->hasSettings( sResourceUrl ) ) + { + m_xDocCfgMgr->replaceSettings( sResourceUrl, xSettings ); + } + else + { + m_xDocCfgMgr->insertSettings( sResourceUrl, xSettings ); + } + if( !bTemporary ) + { + persistChanges(); + } +} + +sal_Bool VbaCommandBarHelper::persistChanges() throw (css::uno::RuntimeException) +{ + uno::Reference< css::ui::XUIConfigurationPersistence > xConfigPersistence( m_xDocCfgMgr, uno::UNO_QUERY_THROW ); + sal_Bool result = sal_False; + if( xConfigPersistence->isModified() ) + { + xConfigPersistence->store(); + result = sal_True; + } + return result; +} + +uno::Reference< frame::XLayoutManager > VbaCommandBarHelper::getLayoutManager() throw (uno::RuntimeException) +{ + uno::Reference< frame::XFrame > xFrame( getModel()->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xPropertySet( xFrame, uno::UNO_QUERY_THROW ); + uno::Reference< frame::XLayoutManager > xLayoutManager( xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("LayoutManager") ), uno::UNO_QUERY_THROW ); + return xLayoutManager; +} + +sal_Bool VbaCommandBarHelper::hasToolbar( const rtl::OUString& sResourceUrl, const rtl::OUString& sName ) throw (css::uno::RuntimeException) +{ + if( m_xDocCfgMgr->hasSettings( sResourceUrl ) ) + { + rtl::OUString sUIName; + uno::Reference< beans::XPropertySet > xPropertySet( m_xDocCfgMgr->getSettings( sResourceUrl, sal_False ), uno::UNO_QUERY_THROW ); + xPropertySet->getPropertyValue( rtl::OUString::createFromAscii(ITEM_DESCRIPTOR_UINAME) ) >>= sUIName; + if( sName.equalsIgnoreAsciiCase( sUIName ) ) + return sal_True; + } + return sal_False; +} + +// return the resource url if found +rtl::OUString VbaCommandBarHelper::findToolbarByName( const css::uno::Reference< css::container::XNameAccess >& xNameAccess, const rtl::OUString& sName ) throw (css::uno::RuntimeException) +{ + rtl::OUString sResourceUrl; + + // check if it is an buildin toolbar + sResourceUrl = MSO2OOCommandbarHelper::getMSO2OOCommandbarHelper()->findBuildinToolbar( sName ); + if( sResourceUrl.getLength() > 0 ) + return sResourceUrl; + + uno::Sequence< ::rtl::OUString > allNames = xNameAccess->getElementNames(); + for( sal_Int32 i = 0; i < allNames.getLength(); i++ ) + { + sResourceUrl = allNames[i]; + if(sResourceUrl.indexOf( rtl::OUString::createFromAscii( ITEM_TOOLBAR_URL ) ) == 0 ) + { + if( hasToolbar( sResourceUrl, sName ) ) + return sResourceUrl; + } + } + + // the customize toolbars creating during importing, shoud found there. + static rtl::OUString sToolbarPrefix( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/custom_" ) ); + sResourceUrl = sToolbarPrefix.concat( sName ); + if( hasToolbar( sResourceUrl, sName ) ) + return sResourceUrl; + + return rtl::OUString(); +} + +// if found, return the position of the control. if not found, return -1 +sal_Int32 VbaCommandBarHelper::findControlByName( const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, const rtl::OUString& sName, bool bMenu ) throw (css::uno::RuntimeException) +{ + sal_Int32 nCount = xIndexAccess->getCount(); + css::uno::Sequence< css::beans::PropertyValue > aProps; + for( sal_Int32 i = 0; i < nCount; i++ ) + { + rtl::OUString sLabel; + xIndexAccess->getByIndex( i ) >>= aProps; + getPropertyValue( aProps, rtl::OUString::createFromAscii(ITEM_DESCRIPTOR_LABEL) ) >>= sLabel; + // handle the hotkey marker '~' (remove in toolbars (?), replace by '&' in menus) + ::rtl::OUStringBuffer aBuffer; + sal_Int32 index = sLabel.indexOf( sal_Unicode('~') ); + if( index < 0 ) + { + aBuffer = sLabel; + } + else + { + aBuffer.append( sLabel.copy( 0, index ) ); + if( bMenu ) + aBuffer.append( sal_Unicode( '&' ) ); + aBuffer.append( sLabel.copy( index + 1 ) ); + } + rtl::OUString sNewLabel = aBuffer.makeStringAndClear(); + OSL_TRACE("VbaCommandBarHelper::findControlByName, control name: %s", rtl::OUStringToOString( sNewLabel, RTL_TEXTENCODING_UTF8 ).getStr() ); + if( sName.equalsIgnoreAsciiCase( sNewLabel ) ) + return i; + } + + // not found + return -1; +} + +rtl::OUString VbaCommandBarHelper::generateCustomURL() +{ + rtl::OUString url = rtl::OUString::createFromAscii( ITEM_TOOLBAR_URL ); + url += rtl::OUString::createFromAscii( CUSTOM_TOOLBAR_STR ); + + // use a random number to minimize possible clash with existing custom toolbars + srand( unsigned( time( NULL ) )); + url += rtl::OUString::valueOf( sal_Int64( rand() ), 16 ); + return url; +} diff --git a/vbahelper/source/vbahelper/vbacommandbarhelper.hxx b/vbahelper/source/vbahelper/vbacommandbarhelper.hxx new file mode 100644 index 000000000000..93c6e5f55457 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbarhelper.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef VBA_COMMANDBARHELPER_HXX +#define VBA_COMMANDBARHELPER_HXX + +#include <vbahelper/vbahelperinterface.hxx> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/ui/XUIConfigurationManager.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/container/XIndexAccess.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/frame/XLayoutManager.hpp> +#include <boost/shared_ptr.hpp> + + +static const char ITEM_DESCRIPTOR_COMMANDURL[] = "CommandURL"; +static const char ITEM_DESCRIPTOR_HELPURL[] = "HelpURL"; +static const char ITEM_DESCRIPTOR_CONTAINER[] = "ItemDescriptorContainer"; +static const char ITEM_DESCRIPTOR_LABEL[] = "Label"; +static const char ITEM_DESCRIPTOR_TYPE[] = "Type"; +static const char ITEM_DESCRIPTOR_STYLE[] = "Style"; +static const char ITEM_DESCRIPTOR_ISVISIBLE[] = "IsVisible"; +static const char ITEM_DESCRIPTOR_RESOURCEURL[] = "ResourceURL"; +static const char ITEM_DESCRIPTOR_UINAME[] = "UIName"; +static const char ITEM_DESCRIPTOR_ENABLED[] = "Enabled"; + +static const char ITEM_MENUBAR_URL[] = "private:resource/menubar/menubar"; +static const char ITEM_TOOLBAR_URL[] = "private:resource/toolbar/"; + +static const char CUSTOM_TOOLBAR_STR[] = "custom_toolbar_"; +static const char CUSTOM_MENU_STR[] = "vnd.openoffice.org:CustomMenu"; + +class VbaCommandBarHelper; +typedef ::boost::shared_ptr< VbaCommandBarHelper > VbaCommandBarHelperRef; + +class VbaCommandBarHelper +{ +private: + css::uno::Reference< css::uno::XComponentContext > mxContext; + css::uno::Reference< css::frame::XModel > mxModel; + css::uno::Reference< css::ui::XUIConfigurationManager > m_xDocCfgMgr; // current document + css::uno::Reference< css::ui::XUIConfigurationManager > m_xAppCfgMgr; + css::uno::Reference< css::container::XNameAccess > m_xWindowState; + rtl::OUString maModuleId; + + void Init() throw (css::uno::RuntimeException); + sal_Bool hasToolbar( const rtl::OUString& sResourceUrl, const rtl::OUString& sName ) throw (css::uno::RuntimeException); +public: + VbaCommandBarHelper( const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::frame::XModel >& xModel ) throw( css::uno::RuntimeException ); + + css::uno::Reference< css::frame::XModel > getModel() { return mxModel; } + + css::uno::Reference< css::ui::XUIConfigurationManager > getDocCfgManager() throw (css::uno::RuntimeException) + { + return m_xDocCfgMgr; + } + css::uno::Reference< css::ui::XUIConfigurationManager > getAppCfgManager() throw (css::uno::RuntimeException) + { + return m_xAppCfgMgr; + } + css::uno::Reference< css::container::XNameAccess > getPersistentWindowState() throw (css::uno::RuntimeException) + { + return m_xWindowState; + } + sal_Bool persistChanges() throw (css::uno::RuntimeException); + css::uno::Reference< css::container::XIndexAccess > getSettings( const rtl::OUString& sResourceUrl ) throw (css::uno::RuntimeException); + void removeSettings( const rtl::OUString& sResourceUrl ) throw (css::uno::RuntimeException); + void ApplyChange( const rtl::OUString& sResourceUrl, const css::uno::Reference< css::container::XIndexAccess >& xSettings, sal_Bool bTemporary = sal_True ) throw (css::uno::RuntimeException); + + css::uno::Reference< css::frame::XLayoutManager > getLayoutManager() throw (css::uno::RuntimeException); + + const rtl::OUString getModuleId(){ return maModuleId; } + rtl::OUString findToolbarByName( const css::uno::Reference< css::container::XNameAccess >& xNameAccess, const rtl::OUString& sName ) throw (css::uno::RuntimeException); + static sal_Int32 findControlByName( const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, const rtl::OUString& sName, bool bMenu = false ) throw (css::uno::RuntimeException); + static rtl::OUString generateCustomURL(); +}; + +#endif //VBA_COMMANDBARHELPER_HXX diff --git a/vbahelper/source/vbahelper/vbacommandbars.cxx b/vbahelper/source/vbahelper/vbacommandbars.cxx new file mode 100644 index 000000000000..9d6cd9e2eea7 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbars.cxx @@ -0,0 +1,256 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/ui/XUIConfigurationStorage.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManager.hpp> +#include <com/sun/star/ui/XUIConfigurationPersistence.hpp> +#include <ooo/vba/office/MsoBarType.hpp> + +#include "vbacommandbars.hxx" +#include "vbacommandbar.hxx" + +using namespace com::sun::star; +using namespace ooo::vba; + + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > CommandBarEnumeration_BASE; + +class CommandBarEnumeration : public CommandBarEnumeration_BASE +{ + uno::Reference< XHelperInterface > m_xParent; + uno::Reference< uno::XComponentContext > m_xContext; + VbaCommandBarHelperRef m_pCBarHelper; + uno::Sequence< rtl::OUString > m_sNames; + sal_Int32 m_nCurrentPosition; +public: + CommandBarEnumeration( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, VbaCommandBarHelperRef pHelper) throw ( uno::RuntimeException ) : m_xParent( xParent ), m_xContext( xContext ), m_pCBarHelper( pHelper ) , m_nCurrentPosition( 0 ) + { + uno::Reference< container::XNameAccess > xNameAccess = m_pCBarHelper->getPersistentWindowState(); + m_sNames = xNameAccess->getElementNames(); + } + virtual sal_Bool SAL_CALL hasMoreElements() throw ( uno::RuntimeException ) + { + if( m_nCurrentPosition < m_sNames.getLength() ) + return sal_True; + return sal_False; + } + virtual uno::Any SAL_CALL nextElement() throw ( container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException ) + { + // FIXME: should be add menubar + if( hasMoreElements() ) + { + rtl::OUString sResourceUrl( m_sNames[ m_nCurrentPosition++ ] ); + if( sResourceUrl.indexOf( rtl::OUString::createFromAscii("private:resource/toolbar/") ) != -1 ) + { + uno::Reference< container::XIndexAccess > xCBarSetting = m_pCBarHelper->getSettings( sResourceUrl ); + uno::Reference< XCommandBar > xCommandBar( new ScVbaCommandBar( m_xParent, m_xContext, m_pCBarHelper, xCBarSetting, sResourceUrl, sal_False, sal_False ) ); + } + else + return nextElement(); + } + else + throw container::NoSuchElementException(); + return uno::Any(); + } +}; + +ScVbaCommandBars::ScVbaCommandBars( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference< frame::XModel >& xModel ) throw ( uno::RuntimeException ) : CommandBars_BASE( xParent, xContext, xIndexAccess ) +{ + m_pCBarHelper.reset( new VbaCommandBarHelper( mxContext, xModel ) ); + m_xNameAccess = m_pCBarHelper->getPersistentWindowState(); +} + +ScVbaCommandBars::~ScVbaCommandBars() +{ +} + +// XEnumerationAccess +uno::Type SAL_CALL +ScVbaCommandBars::getElementType() throw ( uno::RuntimeException ) +{ + return XCommandBar::static_type( 0 ); +} + +uno::Reference< container::XEnumeration > +ScVbaCommandBars::createEnumeration() throw ( uno::RuntimeException ) +{ + return uno::Reference< container::XEnumeration >( new CommandBarEnumeration( this, mxContext, m_pCBarHelper ) ); +} + +uno::Any +ScVbaCommandBars::createCollectionObject( const uno::Any& aSource ) +{ + // aSource should be a name at this time, because of the class is API wrapper. + rtl::OUString sResourceUrl; + uno::Reference< container::XIndexAccess > xBarSettings; + rtl::OUString sBarName; + sal_Bool bMenu = sal_False; + uno::Any aRet; + + if( aSource >>= sBarName ) + { + // some built-in command bars + if( m_pCBarHelper->getModuleId().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.sheet.SpreadsheetDocument") ) ) + { + if( sBarName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM("Worksheet Menu Bar") ) ) + { + // spreadsheet menu bar + sResourceUrl = rtl::OUString::createFromAscii( ITEM_MENUBAR_URL ); + bMenu = sal_True; + } + else if( sBarName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM("Cell") ) ) + { + // EVIL HACK (tm): spreadsheet cell context menu as dummy object without functionality + aRet <<= uno::Reference< XCommandBar >( new VbaDummyCommandBar( this, mxContext, sBarName, office::MsoBarType::msoBarTypePopup ) ); + } + } + else if( m_pCBarHelper->getModuleId().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextDocument") ) ) + { + if( sBarName.equalsIgnoreAsciiCaseAsciiL( RTL_CONSTASCII_STRINGPARAM("Menu Bar") ) ) + { + // text processor menu bar + sResourceUrl = rtl::OUString::createFromAscii( ITEM_MENUBAR_URL ); + bMenu = sal_True; + } + } + + // nothing found - try to resolve from name + if( !aRet.hasValue() && (sResourceUrl.getLength() == 0) ) + { + sResourceUrl = m_pCBarHelper->findToolbarByName( m_xNameAccess, sBarName ); + bMenu = sal_False; + } + } + + if( sResourceUrl.getLength() ) + { + xBarSettings = m_pCBarHelper->getSettings( sResourceUrl ); + aRet <<= uno::Reference< XCommandBar >( new ScVbaCommandBar( this, mxContext, m_pCBarHelper, xBarSettings, sResourceUrl, bMenu, sal_False ) ); + } + + if( !aRet.hasValue() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toolbar do not exist") ), uno::Reference< uno::XInterface >() ); + + return aRet; +} + +// XCommandBars +uno::Reference< XCommandBar > SAL_CALL +ScVbaCommandBars::Add( const css::uno::Any& Name, const css::uno::Any& /*Position*/, const css::uno::Any& /*MenuBar*/, const css::uno::Any& Temporary ) throw (css::script::BasicErrorException, css::uno::RuntimeException) +{ + // FIXME: only support to add Toolbar + // Position - MsoBar MenuBar - sal_Bool + // Currently only the Name is supported. + rtl::OUString sName; + if( Name.hasValue() ) + Name >>= sName; + + rtl::OUString sResourceUrl; + if( sName.getLength() ) + { + sResourceUrl = m_pCBarHelper->findToolbarByName( m_xNameAccess, sName ); + if( sResourceUrl.getLength() ) + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Toolbar exists") ), uno::Reference< uno::XInterface >() ); + } + else + { + sName = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Custom1") ); + } + + sal_Bool bTemporary = sal_False; + if( Temporary.hasValue() ) + Temporary >>= bTemporary; + + sResourceUrl = VbaCommandBarHelper::generateCustomURL(); + uno::Reference< container::XIndexAccess > xBarSettings( m_pCBarHelper->getSettings( sResourceUrl ), uno::UNO_QUERY_THROW ); + uno::Reference< XCommandBar > xCBar( new ScVbaCommandBar( this, mxContext, m_pCBarHelper, xBarSettings, sResourceUrl, sal_False, bTemporary ) ); + xCBar->setName( sName ); + return xCBar; +} +sal_Int32 SAL_CALL +ScVbaCommandBars::getCount() throw(css::uno::RuntimeException) +{ + // Filter out all toolbars from the window collection + sal_Int32 nCount = 1; // there is a Menubar in OOo + uno::Sequence< ::rtl::OUString > allNames = m_xNameAccess->getElementNames(); + for( sal_Int32 i = 0; i < allNames.getLength(); i++ ) + { + if(allNames[i].indexOf( rtl::OUString::createFromAscii("private:resource/toolbar/") ) != -1 ) + { + nCount++; + } + } + return nCount; +} + +// ScVbaCollectionBaseImpl +uno::Any SAL_CALL +ScVbaCommandBars::Item( const uno::Any& aIndex, const uno::Any& /*aIndex2*/ ) throw( uno::RuntimeException ) +{ + if( aIndex.getValueTypeClass() == uno::TypeClass_STRING ) + { + return createCollectionObject( aIndex ); + } + + // hardcode if "aIndex = 1" that would return "main menu". + sal_Int16 nIndex = 0; + aIndex >>= nIndex; + if( nIndex == 1 ) + { + uno::Any aSource; + if( m_pCBarHelper->getModuleId().equalsAscii( "com.sun.star.sheet.SpreadsheetDocument" ) ) + aSource <<= rtl::OUString::createFromAscii( "Worksheet Menu Bar" ); + else if( m_pCBarHelper->getModuleId().equalsAscii("com.sun.star.text.TextDocument") ) + aSource <<= rtl::OUString::createFromAscii( "Menu Bar" ); + if( aSource.hasValue() ) + return createCollectionObject( aSource ); + } + return uno::Any(); +} + +// XHelperInterface +rtl::OUString& +ScVbaCommandBars::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaCommandBars") ); + return sImplName; +} +uno::Sequence<rtl::OUString> +ScVbaCommandBars::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.CommandBars" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/vbahelper/vbacommandbars.hxx b/vbahelper/source/vbahelper/vbacommandbars.hxx new file mode 100644 index 000000000000..92ed1438d269 --- /dev/null +++ b/vbahelper/source/vbahelper/vbacommandbars.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_COMMANDBARS_HXX +#define SC_VBA_COMMANDBARS_HXX + +#include <ooo/vba/XCommandBar.hpp> +#include <ooo/vba/XCommandBars.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <cppuhelper/implbase1.hxx> +#include <vbahelper/vbahelperinterface.hxx> +#include <vbahelper/vbacollectionimpl.hxx> +#include "vbacommandbarhelper.hxx" + +typedef CollTestImplHelper< ov::XCommandBars > CommandBars_BASE; + +class ScVbaCommandBars : public CommandBars_BASE +{ +private: + VbaCommandBarHelperRef m_pCBarHelper; + +public: + ScVbaCommandBars( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess >& xIndexAccess, const css::uno::Reference< css::frame::XModel >& xModel ) throw (css::uno::RuntimeException); + virtual ~ScVbaCommandBars(); + + // XCommandBars + virtual css::uno::Reference< ov::XCommandBar > SAL_CALL Add( const css::uno::Any& Name, const css::uno::Any& Position, const css::uno::Any& MenuBar, const css::uno::Any& Temporary ) throw (css::script::BasicErrorException, css::uno::RuntimeException); + // XEnumerationAccess + virtual css::uno::Type SAL_CALL getElementType() throw (css::uno::RuntimeException); + virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() throw (css::uno::RuntimeException); + virtual css::uno::Any createCollectionObject( const css::uno::Any& aSource ); + + virtual sal_Int32 SAL_CALL getCount() throw(css::uno::RuntimeException); + virtual css::uno::Any SAL_CALL Item( const css::uno::Any& aIndex, const css::uno::Any& /*aIndex2*/ ) throw( css::uno::RuntimeException); + // XHelperInterface + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +}; + +#endif//SC_VBA_COMMANDBARS_HXX diff --git a/vbahelper/source/vbahelper/vbadialogbase.cxx b/vbahelper/source/vbahelper/vbadialogbase.cxx new file mode 100644 index 000000000000..e093e32c7443 --- /dev/null +++ b/vbahelper/source/vbahelper/vbadialogbase.cxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/vbadialogbase.hxx> +#include <vbahelper/vbahelper.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +// fails silently +void +VbaDialogBase::Show() throw(uno::RuntimeException) +{ + rtl::OUString aURL; + if ( m_xModel.is() ) + { + aURL = mapIndexToName( mnIndex ); + if( aURL.getLength() == 0 ) + throw uno::RuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " Unable to open the specified dialog " ) ), + uno::Reference< XInterface > () ); + dispatchRequests( m_xModel, aURL ); + } +} + diff --git a/vbahelper/source/vbahelper/vbadialogsbase.cxx b/vbahelper/source/vbahelper/vbadialogsbase.cxx new file mode 100644 index 000000000000..2e02c35ac674 --- /dev/null +++ b/vbahelper/source/vbahelper/vbadialogsbase.cxx @@ -0,0 +1,44 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/vbadialogsbase.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +::sal_Int32 +VbaDialogsBase::getCount() throw (uno::RuntimeException) +{ + //#TODO #FIXEME + return 0; +} + +uno::Any +VbaDialogsBase::Item( const uno::Any& /* &aItem */) throw (uno::RuntimeException) +{ + return uno::Any(); +} + diff --git a/vbahelper/source/vbahelper/vbadocumentbase.cxx b/vbahelper/source/vbahelper/vbadocumentbase.cxx new file mode 100644 index 000000000000..291bc6ad2931 --- /dev/null +++ b/vbahelper/source/vbahelper/vbadocumentbase.cxx @@ -0,0 +1,304 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahelper/vbadocumentbase.hxx" +#include "vbahelper/helperdecl.hxx" + +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/util/XProtectable.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/document/XEmbeddedScripts.hpp> //Michael E. Bohn +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/XApplicationBase.hpp> + +#include <cppuhelper/exc_hlp.hxx> +#include <comphelper/unwrapargs.hxx> +#include <tools/urlobj.hxx> +#include <osl/file.hxx> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +VbaDocumentBase::VbaDocumentBase( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext) :VbaDocumentBase_BASE( xParent, xContext ), mxModel(NULL) +{ +} + +VbaDocumentBase::VbaDocumentBase( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > xModel ) : VbaDocumentBase_BASE( xParent, xContext ), mxModel( xModel ) +{ +} + +VbaDocumentBase::VbaDocumentBase( uno::Sequence< uno::Any> const & args, + uno::Reference< uno::XComponentContext> const & xContext ) : VbaDocumentBase_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0 ), xContext ), mxModel( getXSomethingFromArgs< frame::XModel >( args, 1 ) ) +{ +} + +::rtl::OUString +VbaDocumentBase::getName() throw (uno::RuntimeException) +{ + rtl::OUString sName = getModel()->getURL(); + if ( sName.getLength() ) + { + + INetURLObject aURL( getModel()->getURL() ); + ::osl::File::getSystemPathFromFileURL( aURL.GetLastName(), sName ); + } + else + { + const static rtl::OUString sTitle( RTL_CONSTASCII_USTRINGPARAM("Title" ) ); + // process "UntitledX - $(PRODUCTNAME)" + uno::Reference< frame::XFrame > xFrame( getModel()->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xProps( xFrame, uno::UNO_QUERY_THROW ); + xProps->getPropertyValue(sTitle ) >>= sName; + sal_Int32 pos = 0; + sName = sName.getToken(0,'-',pos); + sName = sName.trim(); + } + return sName; +} +::rtl::OUString +VbaDocumentBase::getPath() throw (uno::RuntimeException) +{ + INetURLObject aURL( getModel()->getURL() ); + rtl::OUString sURL = aURL.GetMainURL( INetURLObject::DECODE_TO_IURI ); + rtl::OUString sPath; + if( sURL.getLength() > 0 ) + { + sURL = sURL.copy( 0, sURL.getLength() - aURL.GetLastName().getLength() - 1 ); + ::osl::File::getSystemPathFromFileURL( sURL, sPath ); + } + return sPath; +} + +::rtl::OUString +VbaDocumentBase::getFullName() throw (uno::RuntimeException) +{ + rtl::OUString sPath = getName(); + //::osl::File::getSystemPathFromFileURL( getModel()->getURL(), sPath ); + return sPath; +} + +void +VbaDocumentBase::Close( const uno::Any &rSaveArg, const uno::Any &rFileArg, + const uno::Any &rRouteArg ) throw (uno::RuntimeException) +{ + sal_Bool bSaveChanges = sal_False; + rtl::OUString aFileName; + sal_Bool bRouteWorkbook = sal_True; + + rSaveArg >>= bSaveChanges; + sal_Bool bFileName = ( rFileArg >>= aFileName ); + rRouteArg >>= bRouteWorkbook; + uno::Reference< frame::XStorable > xStorable( getModel(), uno::UNO_QUERY_THROW ); + uno::Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY_THROW ); + + if( bSaveChanges ) + { + if( xStorable->isReadonly() ) + { + throw uno::RuntimeException(::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( "Unable to save to a read only file ") ), + uno::Reference< XInterface >() ); + } + if( bFileName ) + xStorable->storeAsURL( aFileName, uno::Sequence< beans::PropertyValue >(0) ); + else + xStorable->store(); + } + else + xModifiable->setModified( false ); + + // first try to close the document using UI dispatch functionality + sal_Bool bUIClose = sal_False; + try + { + uno::Reference< frame::XController > xController( getModel()->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< frame::XDispatchProvider > xDispatchProvider( xController->getFrame(), uno::UNO_QUERY_THROW ); + + uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + uno::Reference< util::XURLTransformer > xURLTransformer( + xServiceManager->createInstanceWithContext( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ) ), + mxContext ), + uno::UNO_QUERY_THROW ); + + util::URL aURL; + aURL.Complete = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CloseDoc" ) ); + xURLTransformer->parseStrict( aURL ); + + uno::Reference< css::frame::XDispatch > xDispatch( + xDispatchProvider->queryDispatch( aURL, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ), 0 ), + uno::UNO_SET_THROW ); + xDispatch->dispatch( aURL, uno::Sequence< beans::PropertyValue >() ); + bUIClose = sal_True; + } + catch( uno::Exception& ) + { + } + + if ( !bUIClose ) + { + // if it is not possible to use UI dispatch, try to close the model directly + uno::Reference< util::XCloseable > xCloseable( getModel(), uno::UNO_QUERY ); + if( xCloseable.is() ) + { + // use close(boolean DeliverOwnership) + + // The boolean parameter DeliverOwnership tells objects vetoing the close process that they may + // assume ownership if they object the closure by throwing a CloseVetoException + // Here we give up ownership. To be on the safe side, catch possible veto exception anyway. + xCloseable->close(sal_True); + } + else + { + // If close is not supported by this model - try to dispose it. + // But if the model disagree with a reset request for the modify state + // we shouldn't do so. Otherwhise some strange things can happen. + uno::Reference< lang::XComponent > xDisposable ( getModel(), uno::UNO_QUERY ); + if ( xDisposable.is() ) + xDisposable->dispose(); + } + } +} + +void +VbaDocumentBase::Protect( const uno::Any &aPassword ) throw (uno::RuntimeException) +{ + rtl::OUString rPassword; + uno::Reference< util::XProtectable > xProt( getModel(), uno::UNO_QUERY_THROW ); + SC_VBA_FIXME(("Workbook::Protect stub")); + if( aPassword >>= rPassword ) + xProt->protect( rPassword ); + else + xProt->protect( rtl::OUString() ); +} + +void +VbaDocumentBase::Unprotect( const uno::Any &aPassword ) throw (uno::RuntimeException) +{ + rtl::OUString rPassword; + uno::Reference< util::XProtectable > xProt( getModel(), uno::UNO_QUERY_THROW ); + if( !xProt->isProtected() ) + throw uno::RuntimeException(::rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( "File is already unprotected" ) ), + uno::Reference< XInterface >() ); + else + { + if( aPassword >>= rPassword ) + xProt->unprotect( rPassword ); + else + xProt->unprotect( rtl::OUString() ); + } +} + +void +VbaDocumentBase::setSaved( sal_Bool bSave ) throw (uno::RuntimeException) +{ + uno::Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY_THROW ); + try + { + xModifiable->setModified( !bSave ); + } + catch ( lang::DisposedException& ) + { + // impossibility to set the modified state on disposed document should not trigger an error + } + catch ( beans::PropertyVetoException& ) + { + uno::Any aCaught( ::cppu::getCaughtException() ); + throw lang::WrappedTargetRuntimeException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't change modified state of model!" ) ), + uno::Reference< uno::XInterface >(), + aCaught ); + } +} + +sal_Bool +VbaDocumentBase::getSaved() throw (uno::RuntimeException) +{ + uno::Reference< util::XModifiable > xModifiable( getModel(), uno::UNO_QUERY_THROW ); + return !xModifiable->isModified(); +} + +void +VbaDocumentBase::Save() throw (uno::RuntimeException) +{ + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(".uno:Save")); + uno::Reference< frame::XModel > xModel = getModel(); + dispatchRequests(xModel,url); +} + +void +VbaDocumentBase::Activate() throw (uno::RuntimeException) +{ + uno::Reference< frame::XFrame > xFrame( getModel()->getCurrentController()->getFrame(), uno::UNO_QUERY_THROW ); + xFrame->activate(); +} + +uno::Any SAL_CALL +VbaDocumentBase::getVBProject() throw (uno::RuntimeException) +{ + if( !mxVBProject.is() ) try + { + uno::Reference< XApplicationBase > xApp( Application(), uno::UNO_QUERY_THROW ); + uno::Reference< XInterface > xVBE( xApp->getVBE(), uno::UNO_QUERY_THROW ); + uno::Sequence< uno::Any > aArgs( 2 ); + aArgs[ 0 ] <<= xVBE; // the VBE + aArgs[ 1 ] <<= getModel(); // document model for script container access + uno::Reference< lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_SET_THROW ); + mxVBProject = xServiceManager->createInstanceWithArgumentsAndContext( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.vbide.VBProject" ) ), aArgs, mxContext ); + } + catch( uno::Exception& ) + { + } + return uno::Any( mxVBProject ); +} + +rtl::OUString& +VbaDocumentBase::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaDocumentBase") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +VbaDocumentBase::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.VbaDocumentBase" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/vbahelper/vbadocumentsbase.cxx b/vbahelper/source/vbahelper/vbadocumentsbase.cxx new file mode 100644 index 000000000000..b65a58542b92 --- /dev/null +++ b/vbahelper/source/vbahelper/vbadocumentsbase.cxx @@ -0,0 +1,352 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahelper/vbadocumentsbase.hxx" + +#include <comphelper/mediadescriptor.hxx> +#include <comphelper/processfactory.hxx> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase3.hxx> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/container/XEnumerationAccess.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/beans/PropertyVetoException.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/lang/IndexOutOfBoundsException.hpp> +#include <com/sun/star/document/XTypeDetection.hpp> +#include <com/sun/star/document/MacroExecMode.hpp> +#include <com/sun/star/uri/XUriReference.hpp> +#include <com/sun/star/uri/XUriReferenceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <sfx2/objsh.hxx> +#include <tools/urlobj.hxx> +#include <hash_map> +#include <osl/file.hxx> + +#include "vbahelper/vbahelper.hxx" +#include "vbahelper/vbaapplicationbase.hxx" + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +static const rtl::OUString sSpreadsheetDocument( rtl::OUString::createFromAscii( "com.sun.star.sheet.SpreadsheetDocument" ) ); +static const rtl::OUString sTextDocument( rtl::OUString::createFromAscii( "com.sun.star.text.TextDocument" ) ); + +typedef std::hash_map< rtl::OUString, +sal_Int32, ::rtl::OUStringHash, +::std::equal_to< ::rtl::OUString > > NameIndexHash; + +typedef std::vector < uno::Reference< frame::XModel > > Documents; + +typedef ::cppu::WeakImplHelper1< container::XEnumeration > DocumentsEnumImpl_BASE; + +// #FIXME clearly this is a candidate for some sort of helper base class as +// this is a copy of SelectedSheetsEnum ( vbawindow.cxx ) + +class DocumentsEnumImpl : public DocumentsEnumImpl_BASE +{ + uno::Reference< uno::XComponentContext > m_xContext; + Documents m_documents; + Documents::const_iterator m_it; + +public: + DocumentsEnumImpl( const uno::Reference< uno::XComponentContext >& xContext, const Documents& docs ) throw ( uno::RuntimeException ) : m_xContext( xContext ), m_documents( docs ) + { + m_it = m_documents.begin(); + } + DocumentsEnumImpl( const uno::Reference< uno::XComponentContext >& xContext ) throw ( uno::RuntimeException ) : m_xContext( xContext ) + { + uno::Reference< lang::XMultiComponentFactory > xSMgr( + m_xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + + uno::Reference< frame::XDesktop > xDesktop + (xSMgr->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), m_xContext), uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration > mxComponents = xDesktop->getComponents()->createEnumeration(); + while( mxComponents->hasMoreElements() ) + { + uno::Reference< frame::XModel > xNext( mxComponents->nextElement(), uno::UNO_QUERY ); + if ( xNext.is() ) + m_documents.push_back( xNext ); + } + m_it = m_documents.begin(); + } + // XEnumeration + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return m_it != m_documents.end(); + } + + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( !hasMoreElements() ) + { + throw container::NoSuchElementException(); + } + return makeAny( *(m_it++) ); + } +}; + +// #FIXME clearly this is also a candidate for some sort of helper base class as +// a very similar one is used in vbawindow ( SelectedSheetsEnumAccess ) +// Maybe a template base class that does all of the operations on the hashmap +// and vector only, and the sub-class does everything else +// => ctor, createEnumeration & factory method need be defined ( to be called +// by getByIndex, getByName ) +typedef ::cppu::WeakImplHelper3< container::XEnumerationAccess + , com::sun::star::container::XIndexAccess + , com::sun::star::container::XNameAccess + > DocumentsAccessImpl_BASE; + +class DocumentsAccessImpl : public DocumentsAccessImpl_BASE +{ + uno::Reference< uno::XComponentContext > m_xContext; + Documents m_documents; + NameIndexHash namesToIndices; + VbaDocumentsBase::DOCUMENT_TYPE meDocType; +public: + DocumentsAccessImpl( const uno::Reference< uno::XComponentContext >& xContext, VbaDocumentsBase::DOCUMENT_TYPE eDocType ) throw (uno::RuntimeException) :m_xContext( xContext ), meDocType( eDocType ) + { + uno::Reference< container::XEnumeration > xEnum = new DocumentsEnumImpl( m_xContext ); + sal_Int32 nIndex=0; + while( xEnum->hasMoreElements() ) + { + uno::Reference< lang::XServiceInfo > xServiceInfo( xEnum->nextElement(), uno::UNO_QUERY ); + if ( xServiceInfo.is() + && ( ( xServiceInfo->supportsService( sSpreadsheetDocument ) && meDocType == VbaDocumentsBase::EXCEL_DOCUMENT ) + || ( xServiceInfo->supportsService( sTextDocument ) && meDocType == VbaDocumentsBase::WORD_DOCUMENT ) ) ) + { + uno::Reference< frame::XModel > xModel( xServiceInfo, uno::UNO_QUERY_THROW ); // that the spreadsheetdocument is a xmodel is a given + m_documents.push_back( xModel ); + INetURLObject aURL( xModel->getURL() ); + namesToIndices[ aURL.GetLastName() ] = nIndex++; + } + } + + } + + //XEnumerationAccess + virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration( ) throw (uno::RuntimeException) + { + return new DocumentsEnumImpl( m_xContext, m_documents ); + } + // XIndexAccess + virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException) + { + return m_documents.size(); + } + virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw ( lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException) + { + if ( Index < 0 + || static_cast< Documents::size_type >(Index) >= m_documents.size() ) + throw lang::IndexOutOfBoundsException(); + return makeAny( m_documents[ Index ] ); // returns xspreadsheetdoc + } + + //XElementAccess + virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException) + { + return frame::XModel::static_type(0); + } + + virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException) + { + return (m_documents.size() > 0); + } + + //XNameAccess + virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + NameIndexHash::const_iterator it = namesToIndices.find( aName ); + if ( it == namesToIndices.end() ) + throw container::NoSuchElementException(); + return makeAny( m_documents[ it->second ] ); + + } + + virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames( ) throw (uno::RuntimeException) + { + uno::Sequence< ::rtl::OUString > names( namesToIndices.size() ); + ::rtl::OUString* pString = names.getArray(); + NameIndexHash::const_iterator it = namesToIndices.begin(); + NameIndexHash::const_iterator it_end = namesToIndices.end(); + for ( ; it != it_end; ++it, ++pString ) + *pString = it->first; + return names; + } + + virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException) + { + NameIndexHash::const_iterator it = namesToIndices.find( aName ); + return (it != namesToIndices.end()); + } + +}; + +VbaDocumentsBase::VbaDocumentsBase( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< css::uno::XComponentContext >& xContext, DOCUMENT_TYPE eDocType ) throw (uno::RuntimeException) : VbaDocumentsBase_BASE( xParent, xContext, uno::Reference< container::XIndexAccess >( new DocumentsAccessImpl( xContext, eDocType ) ) ), meDocType( eDocType ) +{ +} + +namespace { + +void lclSetupComponent( const uno::Reference< lang::XComponent >& rxComponent, sal_Bool bScreenUpdating, sal_Bool bInteractive ) +{ + if( !bScreenUpdating ) try + { + uno::Reference< frame::XModel >( rxComponent, uno::UNO_QUERY_THROW )->lockControllers(); + } + catch( uno::Exception& ) + { + } + + if( !bInteractive ) try + { + uno::Reference< frame::XModel > xModel( rxComponent, uno::UNO_QUERY_THROW ); + uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); + uno::Reference< awt::XWindow >( xFrame->getContainerWindow(), uno::UNO_SET_THROW )->setEnable( sal_False ); + } + catch( uno::Exception& ) + { + } +} + +} // namespace + +uno::Any VbaDocumentsBase::createDocument() throw (uno::RuntimeException) +{ + // #163808# determine state of Application.ScreenUpdating and Application.Interactive symbols (before new document is opened) + uno::Reference< XApplicationBase > xApplication( Application(), uno::UNO_QUERY ); + sal_Bool bScreenUpdating = !xApplication.is() || xApplication->getScreenUpdating(); + sal_Bool bInteractive = !xApplication.is() || xApplication->getInteractive(); + + uno::Reference< lang::XMultiComponentFactory > xSMgr( + mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + + uno::Reference< frame::XComponentLoader > xLoader( + xSMgr->createInstanceWithContext( + ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), + mxContext), uno::UNO_QUERY_THROW ); + rtl::OUString sURL; + if( meDocType == WORD_DOCUMENT ) + sURL = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("private:factory/swriter") ); + else if( meDocType == EXCEL_DOCUMENT ) + sURL = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("private:factory/scalc") ); + else + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); + + // prepare the media descriptor + ::comphelper::MediaDescriptor aMediaDesc; + aMediaDesc[ ::comphelper::MediaDescriptor::PROP_MACROEXECUTIONMODE() ] <<= document::MacroExecMode::USE_CONFIG; + aMediaDesc.setComponentDataEntry( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ApplyFormDesignMode" ) ), uno::Any( false ) ); + + // craete the new document + uno::Reference< lang::XComponent > xComponent = xLoader->loadComponentFromURL( + sURL , + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_blank") ), 0, + aMediaDesc.getAsConstPropertyValueList() ); + + // #163808# lock document controllers and container window if specified by application + lclSetupComponent( xComponent, bScreenUpdating, bInteractive ); + + return uno::makeAny( xComponent ); +} + +void VbaDocumentsBase::closeDocuments() throw (uno::RuntimeException) +{ +// #FIXME this *MUST* be wrong documents::close surely closes ALL documents +// in the collection, use of getCurrentDocument here is totally wrong +/* + uno::Reference< lang::XMultiComponentFactory > xSMgr( + mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XModel > xModel( getCurrentDocument(), uno::UNO_QUERY_THROW ); + rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:CloseDoc")); + dispatchRequests(xModel,url); +*/ +} + +// #TODO# #FIXME# can any of the unused params below be used? +uno::Any VbaDocumentsBase::openDocument( const rtl::OUString& rFileName, const uno::Any& ReadOnly, const uno::Sequence< beans::PropertyValue >& rProps ) throw (uno::RuntimeException) +{ + // #163808# determine state of Application.ScreenUpdating and Application.Interactive symbols (before new document is opened) + uno::Reference< XApplicationBase > xApplication( Application(), uno::UNO_QUERY ); + sal_Bool bScreenUpdating = !xApplication.is() || xApplication->getScreenUpdating(); + sal_Bool bInteractive = !xApplication.is() || xApplication->getInteractive(); + + // we need to detect if this is a URL, if not then assume its a file path + rtl::OUString aURL; + INetURLObject aObj; + aObj.SetURL( rFileName ); + bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID; + if ( bIsURL ) + aURL = rFileName; + else + osl::FileBase::getFileURLFromSystemPath( rFileName, aURL ); + uno::Reference< lang::XMultiComponentFactory > xSMgr( + mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + uno::Reference< frame::XDesktop > xDesktop + (xSMgr->createInstanceWithContext(::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop") , mxContext), + uno::UNO_QUERY_THROW ); + uno::Reference< frame::XComponentLoader > xLoader( + xSMgr->createInstanceWithContext( + ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop"), + mxContext), + uno::UNO_QUERY_THROW ); + + uno::Sequence< beans::PropertyValue > sProps( rProps ); + sProps.realloc( sProps.getLength() + 1 ); + sProps[ sProps.getLength() - 1 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("MacroExecutionMode") ); + sProps[ sProps.getLength() - 1 ].Value <<= document::MacroExecMode::ALWAYS_EXECUTE_NO_WARN; + + if ( ReadOnly.hasValue() ) + { + sal_Bool bIsReadOnly = sal_False; ReadOnly >>= bIsReadOnly; + if ( bIsReadOnly ) + { + sProps.realloc( sProps.getLength() + 1 ); + sProps[ sProps.getLength() - 1 ].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ReadOnly") ); + sProps[ sProps.getLength() - 1 ].Value <<= true; + } + } + + uno::Reference< lang::XComponent > xComponent = xLoader->loadComponentFromURL( aURL, + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("_default") ), + frame::FrameSearchFlag::CREATE, + sProps); + + // #163808# lock document controllers and container window if specified by application + lclSetupComponent( xComponent, bScreenUpdating, bInteractive ); + + return uno::makeAny( xComponent ); +} + diff --git a/vbahelper/source/vbahelper/vbaeventshelperbase.cxx b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx new file mode 100755 index 000000000000..5e2cf949c473 --- /dev/null +++ b/vbahelper/source/vbahelper/vbaeventshelperbase.cxx @@ -0,0 +1,350 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahelper/vbaeventshelperbase.hxx" +#include <com/sun/star/document/XEventBroadcaster.hpp> +#include <com/sun/star/script/ModuleType.hpp> +#include <com/sun/star/script/vba/XVBAModuleInfo.hpp> +#include <com/sun/star/util/XChangesNotifier.hpp> +#include <filter/msfilter/msvbahelper.hxx> +#include <unotools/eventcfg.hxx> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +using ::rtl::OUString; +using ::rtl::OUStringBuffer; + +// ============================================================================ + +VbaEventsHelperBase::VbaEventsHelperBase( const uno::Sequence< uno::Any >& rArgs, const uno::Reference< uno::XComponentContext >& /*xContext*/ ) : + mpShell( 0 ), + mbDisposed( true ) +{ + try + { + mxModel = getXSomethingFromArgs< frame::XModel >( rArgs, 0, false ); + mpShell = getSfxObjShell( mxModel ); + } + catch( uno::Exception& ) + { + } + mbDisposed = mpShell == 0; + startListening(); +} + +VbaEventsHelperBase::~VbaEventsHelperBase() +{ + OSL_ENSURE( mbDisposed, "VbaEventsHelperBase::~VbaEventsHelperBase - missing disposing notification" ); +} + +sal_Bool SAL_CALL VbaEventsHelperBase::hasVbaEventHandler( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) + throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + // getEventHandlerInfo() throws, if unknown event dentifier has been passed + const EventHandlerInfo& rInfo = getEventHandlerInfo( nEventId ); + // getEventHandlerPath() searches for the macro in the document + return getEventHandlerPath( rInfo, rArgs ).getLength() > 0; +} + +sal_Bool SAL_CALL VbaEventsHelperBase::processVbaEvent( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) + throw (lang::IllegalArgumentException, util::VetoException, uno::RuntimeException) +{ + /* Derived classes may add new event identifiers to be processed while + processing the original event. All unprocessed events are collected in + a queue. First element in the queue is the next event to be processed. */ + EventQueue aEventQueue; + aEventQueue.push_back( EventQueueEntry( nEventId, rArgs ) ); + + /* bCancel will contain the current Cancel value. It is possible that + multiple events will try to modify the Cancel value. Every event + handler receives the Cancel value of the previous event handler. */ + bool bCancel = false; + + /* bExecuted will change to true if at least one event handler has been + found and executed. */ + bool bExecuted = false; + + /* Loop as long as there are more events to be processed. Derived classes + may add new events to be processed in the virtual implPrepareEvent() + function. */ + while( !aEventQueue.empty() ) + { + /* Check that all class members are available, and that we are not + disposed (this may have happened at any time during execution of + the last event handler). */ + if( mbDisposed || !mxModel.is() || !mpShell ) + throw uno::RuntimeException(); + + // get info for next event + const EventHandlerInfo& rInfo = getEventHandlerInfo( aEventQueue.front().mnEventId ); + uno::Sequence< uno::Any > aEventArgs = aEventQueue.front().maArgs; + aEventQueue.pop_front(); + OSL_TRACE( "VbaEventsHelperBase::processVbaEvent( \"%s\" )", ::rtl::OUStringToOString( rInfo.maMacroName, RTL_TEXTENCODING_UTF8 ).getStr() ); + + /* Let derived classes prepare the event, they may add new events for + next iteration. If false is returned, the event handler must not be + called. */ + if( implPrepareEvent( aEventQueue, rInfo, aEventArgs ) ) + { + // search the event handler macro in the document + OUString aMacroPath = getEventHandlerPath( rInfo, aEventArgs ); + if( aMacroPath.getLength() > 0 ) + { + // build the argument list + uno::Sequence< uno::Any > aVbaArgs = implBuildArgumentList( rInfo, aEventArgs ); + // insert current cancel value + if( rInfo.mnCancelIndex >= 0 ) + { + if( rInfo.mnCancelIndex >= aVbaArgs.getLength() ) + throw lang::IllegalArgumentException(); + aVbaArgs[ rInfo.mnCancelIndex ] <<= bCancel; + } + // execute the event handler + uno::Any aRet, aCaller; + executeMacro( mpShell, aMacroPath, aVbaArgs, aRet, aCaller ); + // extract new cancel value (may be boolean or any integer type) + if( rInfo.mnCancelIndex >= 0 ) + { + checkArgument( aVbaArgs, rInfo.mnCancelIndex ); + bCancel = extractBoolFromAny( aVbaArgs[ rInfo.mnCancelIndex ] ); + } + // event handler has been found + bExecuted = true; + } + } + // post processing (also, if event handler does not exist, or disabled, or on error + implPostProcessEvent( aEventQueue, rInfo, bCancel ); + } + + // if event handlers want to cancel the event, do so regardless of any errors + if( bCancel ) + throw util::VetoException(); + + // return true, if at least one event handler has been found + return bExecuted; +} + +void SAL_CALL VbaEventsHelperBase::notifyEvent( const document::EventObject& rEvent ) throw (uno::RuntimeException) +{ + OSL_TRACE( "VbaEventsHelperBase::notifyEvent( \"%s\" )", ::rtl::OUStringToOString( rEvent.EventName, RTL_TEXTENCODING_UTF8 ).getStr() ); + if( rEvent.EventName == GlobalEventConfig::GetEventName( STR_EVENT_CLOSEDOC ) ) + stopListening(); +} + +void SAL_CALL VbaEventsHelperBase::changesOccurred( const util::ChangesEvent& rEvent ) throw (uno::RuntimeException) +{ + // make sure the VBA library exists + try + { + ensureVBALibrary(); + } + catch( uno::Exception& ) + { + return; + } + + // check that the sender of the event is the VBA library + uno::Reference< script::vba::XVBAModuleInfo > xSender( rEvent.Base, uno::UNO_QUERY ); + if( mxModuleInfos.get() != xSender.get() ) + return; + + // process all changed modules + for( sal_Int32 nIndex = 0, nLength = rEvent.Changes.getLength(); nIndex < nLength; ++nIndex ) + { + const util::ElementChange& rChange = rEvent.Changes[ nIndex ]; + OUString aModuleName; + if( (rChange.Accessor >>= aModuleName) && (aModuleName.getLength() > 0) ) try + { + // invalidate event handler path map depending on module type + if( getModuleType( aModuleName ) == script::ModuleType::NORMAL ) + // paths to global event handlers are stored with empty key (will be searched in all normal code modules) + maEventPaths.erase( OUString() ); + else + // paths to class/form/document event handlers are keyed by module name + maEventPaths.erase( aModuleName ); + } + catch( uno::Exception& ) + { + } + } +} + +void SAL_CALL VbaEventsHelperBase::disposing( const lang::EventObject& rEvent ) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xSender( rEvent.Source, uno::UNO_QUERY ); + if( xSender.is() ) + stopListening(); +} + +void VbaEventsHelperBase::processVbaEventNoThrow( sal_Int32 nEventId, const uno::Sequence< uno::Any >& rArgs ) +{ + try + { + processVbaEvent( nEventId, rArgs ); + } + catch( uno::Exception& ) + { + } +} + +// protected ------------------------------------------------------------------ + +void VbaEventsHelperBase::registerEventHandler( sal_Int32 nEventId, sal_Int32 nModuleType, + const sal_Char* pcMacroName, sal_Int32 nCancelIndex, const uno::Any& rUserData ) +{ + EventHandlerInfo& rInfo = maEventInfos[ nEventId ]; + rInfo.mnEventId = nEventId; + rInfo.mnModuleType = nModuleType; + rInfo.maMacroName = OUString::createFromAscii( pcMacroName ); + rInfo.mnCancelIndex = nCancelIndex; + rInfo.maUserData = rUserData; +} + +// private -------------------------------------------------------------------- + +void VbaEventsHelperBase::startListening() +{ + if( mbDisposed ) + return; + + uno::Reference< document::XEventBroadcaster > xEventBroadcaster( mxModel, uno::UNO_QUERY ); + if( xEventBroadcaster.is() ) + try { xEventBroadcaster->addEventListener( this ); } catch( uno::Exception& ) {} +} + +void VbaEventsHelperBase::stopListening() +{ + if( mbDisposed ) + return; + + uno::Reference< document::XEventBroadcaster > xEventBroadcaster( mxModel, uno::UNO_QUERY ); + if( xEventBroadcaster.is() ) + try { xEventBroadcaster->removeEventListener( this ); } catch( uno::Exception& ) {} + + mxModel.clear(); + mpShell = 0; + maEventInfos.clear(); + mbDisposed = true; +} + +const VbaEventsHelperBase::EventHandlerInfo& VbaEventsHelperBase::getEventHandlerInfo( + sal_Int32 nEventId ) const throw (lang::IllegalArgumentException) +{ + EventHandlerInfoMap::const_iterator aIt = maEventInfos.find( nEventId ); + if( aIt == maEventInfos.end() ) + throw lang::IllegalArgumentException(); + return aIt->second; +} + +OUString VbaEventsHelperBase::getEventHandlerPath( const EventHandlerInfo& rInfo, + const uno::Sequence< uno::Any >& rArgs ) throw (lang::IllegalArgumentException, uno::RuntimeException) +{ + OUString aModuleName; + switch( rInfo.mnModuleType ) + { + // global event handlers may exist in any standard code module + case script::ModuleType::NORMAL: + break; + + // document event: get name of the code module associated to the event sender + case script::ModuleType::DOCUMENT: + aModuleName = implGetDocumentModuleName( rInfo, rArgs ); + if( aModuleName.getLength() == 0 ) + throw lang::IllegalArgumentException(); + break; + + default: + throw uno::RuntimeException(); // unsupported module type + } + + /* Performance improvement: Check the list of existing event handlers + instead of searching in Basic source code every time. */ + EventHandlerPathMap::iterator aIt = maEventPaths.find( aModuleName ); + ModulePathMap& rPathMap = (aIt == maEventPaths.end()) ? updateModulePathMap( aModuleName ) : aIt->second; + return rPathMap[ rInfo.mnEventId ]; +} + +void VbaEventsHelperBase::ensureVBALibrary() throw (uno::RuntimeException) +{ + if( !mxModuleInfos.is() ) try + { + maLibraryName = getDefaultProjectName( mpShell ); + if( maLibraryName.getLength() == 0 ) + throw uno::RuntimeException(); + uno::Reference< beans::XPropertySet > xModelProps( mxModel, uno::UNO_QUERY_THROW ); + uno::Reference< container::XNameAccess > xBasicLibs( xModelProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicLibraries" ) ) ), uno::UNO_QUERY_THROW ); + mxModuleInfos.set( xBasicLibs->getByName( maLibraryName ), uno::UNO_QUERY_THROW ); + // listen to changes in the VBA source code + uno::Reference< util::XChangesNotifier > xChangesNotifier( mxModuleInfos, uno::UNO_QUERY_THROW ); + xChangesNotifier->addChangesListener( this ); + } + catch( uno::Exception& ) + { + // error accessing the Basic library, so this object is useless + stopListening(); + throw uno::RuntimeException(); + } +} + +sal_Int32 VbaEventsHelperBase::getModuleType( const OUString& rModuleName ) throw (uno::RuntimeException) +{ + // make sure the VBA library exists + ensureVBALibrary(); + + // no module specified: global event handler in standard code modules + if( rModuleName.getLength() == 0 ) + return script::ModuleType::NORMAL; + + // get module type from module info + try + { + return mxModuleInfos->getModuleInfo( rModuleName ).ModuleType; + } + catch( uno::Exception& ) + { + } + throw uno::RuntimeException(); +} + +VbaEventsHelperBase::ModulePathMap& VbaEventsHelperBase::updateModulePathMap( const ::rtl::OUString& rModuleName ) throw (uno::RuntimeException) +{ + // get type of the specified module (throws on error) + sal_Int32 nModuleType = getModuleType( rModuleName ); + // search for all event handlers + ModulePathMap& rPathMap = maEventPaths[ rModuleName ]; + for( EventHandlerInfoMap::iterator aIt = maEventInfos.begin(), aEnd = maEventInfos.end(); aIt != aEnd; ++aIt ) + { + const EventHandlerInfo& rInfo = aIt->second; + if( rInfo.mnModuleType == nModuleType ) + rPathMap[ rInfo.mnEventId ] = resolveVBAMacro( mpShell, maLibraryName, rModuleName, rInfo.maMacroName ); + } + return rPathMap; +} + +// ============================================================================ diff --git a/vbahelper/source/vbahelper/vbafillformat.cxx b/vbahelper/source/vbahelper/vbafillformat.cxx new file mode 100644 index 000000000000..dc474dd158bc --- /dev/null +++ b/vbahelper/source/vbahelper/vbafillformat.cxx @@ -0,0 +1,199 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/awt/Gradient.hpp> +#include <com/sun/star/awt/GradientStyle.hpp> +#include <ooo/vba/office/MsoGradientStyle.hpp> +#include "vbafillformat.hxx" +#include "vbacolorformat.hxx" + +using namespace ooo::vba; +using namespace com::sun::star; + +ScVbaFillFormat::ScVbaFillFormat( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape > xShape ) : ScVbaFillFormat_BASE( xParent, xContext ), m_xShape( xShape ) +{ + m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW ); + m_nFillStyle = drawing::FillStyle_SOLID; + m_nForeColor = 0; + m_nBackColor = 0; + m_nGradientAngle = 0; +} + +void +ScVbaFillFormat::setFillStyle( drawing::FillStyle nFillStyle ) throw (uno::RuntimeException) +{ + m_nFillStyle = nFillStyle; + if( m_nFillStyle == drawing::FillStyle_GRADIENT ) + { + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), uno::makeAny( drawing::FillStyle_GRADIENT ) ); + awt::Gradient aGradient; + // AXIAL + // RADIAL + // ELLIPTICAL + // SQUARE + // RECT + aGradient.Style = awt::GradientStyle_LINEAR; + aGradient.StartColor = ForeColor()->getRGB(); + aGradient.EndColor = BackColor()->getRGB(); + aGradient.Angle = m_nGradientAngle; + aGradient.Border = 0; + aGradient.XOffset = 0; + aGradient.YOffset = 0; + aGradient.StartIntensity = 100; + aGradient.EndIntensity = 100; + aGradient.StepCount = 1; + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillGradient"), uno::makeAny( aGradient ) ); + } + else if( m_nFillStyle == drawing::FillStyle_SOLID ) + { + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), uno::makeAny(drawing::FillStyle_SOLID) ); + } +} + +void +ScVbaFillFormat::setForeColorAndInternalStyle( sal_Int32 nForeColor ) throw (css::uno::RuntimeException) +{ + m_nForeColor = nForeColor; + setFillStyle( m_nFillStyle ); +} + +// Attributes +sal_Bool SAL_CALL +ScVbaFillFormat::getVisible() throw (uno::RuntimeException) +{ + drawing::FillStyle nFillStyle; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("FillStyle") ) >>= nFillStyle; + if( nFillStyle == drawing::FillStyle_NONE ) + return sal_False; + return sal_True; +} + +void SAL_CALL +ScVbaFillFormat::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) +{ + drawing::FillStyle aFillStyle; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("FillStyle") ) >>= aFillStyle; + if( !_visible ) + { + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("FillStyle"), uno::makeAny( drawing::FillStyle_NONE ) ); + } + else + { + if( aFillStyle == drawing::FillStyle_NONE ) + { + setFillStyle( m_nFillStyle ); + } + } +} + +double SAL_CALL +ScVbaFillFormat::getTransparency() throw (uno::RuntimeException) +{ + sal_Int16 nTransparence = 0; + double dTransparence = 0; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "FillTransparence" ) ) >>= nTransparence; + dTransparence = static_cast<double>( nTransparence ); + dTransparence /= 100; + return dTransparence; +} + +void SAL_CALL +ScVbaFillFormat::setTransparency( double _transparency ) throw (uno::RuntimeException) +{ + sal_Int16 nTransparence = static_cast< sal_Int16 >( _transparency * 100 ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillTransparence" ), uno::makeAny( nTransparence ) ); +} + + +// Methods +void SAL_CALL +ScVbaFillFormat::Solid() throw (uno::RuntimeException) +{ + setFillStyle( drawing::FillStyle_SOLID ); +} + +void SAL_CALL +ScVbaFillFormat::TwoColorGradient( sal_Int32 style, sal_Int32 /*variant*/ ) throw (uno::RuntimeException) +{ + if( style == office::MsoGradientStyle::msoGradientHorizontal ) + { + m_nGradientAngle = 0; + setFillStyle( drawing::FillStyle_GRADIENT ); + } + else if( style == office::MsoGradientStyle::msoGradientVertical ) + { + m_nGradientAngle = 900; + setFillStyle( drawing::FillStyle_GRADIENT ); + } + else if( style == office::MsoGradientStyle::msoGradientDiagonalDown ) + { + m_nGradientAngle = 450; + setFillStyle( drawing::FillStyle_GRADIENT ); + } + else if( style == office::MsoGradientStyle::msoGradientDiagonalUp ) + { + m_nGradientAngle = 900 + 450; + setFillStyle( drawing::FillStyle_GRADIENT ); + } +} + +uno::Reference< msforms::XColorFormat > SAL_CALL +ScVbaFillFormat::BackColor() throw (uno::RuntimeException) +{ + if( !m_xColorFormat.is() ) + m_xColorFormat.set( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ColorFormatType::FILLFORMAT_BACKCOLOR ) ); + return m_xColorFormat; +} + +uno::Reference< msforms::XColorFormat > SAL_CALL +ScVbaFillFormat::ForeColor() throw (uno::RuntimeException) +{ + if( !m_xColorFormat.is() ) + m_xColorFormat.set( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ColorFormatType::FILLFORMAT_FORECOLOR ) ); + return m_xColorFormat; +} + + +rtl::OUString& +ScVbaFillFormat::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaFillFormat") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaFillFormat::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.FillFormat" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/vbahelper/vbafillformat.hxx b/vbahelper/source/vbahelper/vbafillformat.hxx new file mode 100644 index 000000000000..31f4dccb5a38 --- /dev/null +++ b/vbahelper/source/vbahelper/vbafillformat.hxx @@ -0,0 +1,71 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_XFILLFORMAT_HXX +#define SC_VBA_XFILLFORMAT_HXX + +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <ooo/vba/msforms/XFillFormat.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::msforms::XFillFormat > ScVbaFillFormat_BASE; + +class ScVbaFillFormat : public ScVbaFillFormat_BASE +{ +private: + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; + css::uno::Reference< ov::msforms::XColorFormat > m_xColorFormat; + css::drawing::FillStyle m_nFillStyle; + sal_Int32 m_nForeColor; + sal_Int32 m_nBackColor; + sal_Int16 m_nGradientAngle; +private: + void setFillStyle( css::drawing::FillStyle nFillStyle ) throw (css::uno::RuntimeException); +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + +public: + ScVbaFillFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape > xShape ); + + void setForeColorAndInternalStyle( sal_Int32 nForeColor ) throw (css::uno::RuntimeException); + // Attributes + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getTransparency() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTransparency( double _transparency ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL Solid() throw (css::uno::RuntimeException); + virtual void SAL_CALL TwoColorGradient( sal_Int32 style, sal_Int32 variant ) throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL BackColor() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL ForeColor() throw (css::uno::RuntimeException); + +}; + +#endif//SC_VBA_XFILLFORMAT_HXX diff --git a/vbahelper/source/vbahelper/vbafontbase.cxx b/vbahelper/source/vbahelper/vbafontbase.cxx new file mode 100644 index 000000000000..065414343bd1 --- /dev/null +++ b/vbahelper/source/vbahelper/vbafontbase.cxx @@ -0,0 +1,339 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/beans/XProperty.hpp> +#include <com/sun/star/awt/FontWeight.hpp> +#include <com/sun/star/awt/FontUnderline.hpp> +#include <com/sun/star/awt/FontStrikeout.hpp> +#include <com/sun/star/awt/FontSlant.hpp> +#include <com/sun/star/text/XSimpleText.hpp> +#include <vbahelper/vbafontbase.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +// form controls use other property name as the remaining OOo API +#define VBAFONTBASE_PROPNAME( ascii_normal, ascii_control ) \ + mbFormControl ? rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ascii_control ) ) : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ascii_normal ) ) + +VbaFontBase::VbaFontBase( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const uno::Reference< css::container::XIndexAccess >& xPalette, + const uno::Reference< beans::XPropertySet >& xPropertySet, + bool bFormControl ) throw ( uno::RuntimeException ) : + VbaFontBase_BASE( xParent, xContext ), + mxFont( xPropertySet, uno::UNO_SET_THROW ), + mxPalette( xPalette, uno::UNO_SET_THROW ), + mbFormControl( bFormControl ) +{ +} + +VbaFontBase::~VbaFontBase() +{ +} + +void SAL_CALL +VbaFontBase::setSuperscript( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + // not supported in form controls + if( mbFormControl ) + return; + + sal_Bool bValue = sal_False; + aValue >>= bValue; + sal_Int16 nValue = NORMAL; + sal_Int8 nValue2 = NORMALHEIGHT; + + if( bValue ) + { + nValue = SUPERSCRIPT; + nValue2 = SUPERSCRIPTHEIGHT; + } + mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ), ( uno::Any )nValue ); + mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapementHeight" ) ), ( uno::Any )nValue2 ); +} + +uno::Any SAL_CALL +VbaFontBase::getSuperscript() throw ( uno::RuntimeException ) +{ + short nValue = NORMAL; + // not supported in form controls + if( !mbFormControl ) + mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ) ) >>= nValue; + return uno::makeAny( ( nValue == SUPERSCRIPT ) ); +} + +void SAL_CALL +VbaFontBase::setSubscript( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + // not supported in form controls + if( mbFormControl ) + return; + + sal_Bool bValue = sal_False; + aValue >>= bValue; + sal_Int16 nValue = NORMAL; + sal_Int8 nValue2 = NORMALHEIGHT; + + if( bValue ) + { + nValue= SUBSCRIPT; + nValue2 = SUBSCRIPTHEIGHT; + } + + mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapementHeight" ) ), ( uno::Any )nValue2 ); + mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ), ( uno::Any )nValue ); + +} + +uno::Any SAL_CALL +VbaFontBase::getSubscript() throw ( uno::RuntimeException ) +{ + short nValue = NORMAL; + // not supported in form controls + if( !mbFormControl ) + mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharEscapement" ) ) ) >>= nValue; + return uno::makeAny( ( nValue == SUBSCRIPT ) ); +} + +void SAL_CALL +VbaFontBase::setSize( const uno::Any& aValue ) throw( uno::RuntimeException ) +{ + // form controls need a sal_Int16 containing points, other APIs need a float + uno::Any aVal( aValue ); + if( mbFormControl ) + { + float fVal = 0.0; + aVal >>= fVal; + aVal <<= static_cast< sal_Int16 >( fVal ); + } + mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharHeight", "FontHeight" ), aVal ); +} + +uno::Any SAL_CALL +VbaFontBase::getSize() throw ( uno::RuntimeException ) +{ + return mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharHeight", "FontHeight" ) ); +} + +void SAL_CALL +VbaFontBase::setColorIndex( const uno::Any& _colorindex ) throw( uno::RuntimeException ) +{ + sal_Int32 nIndex = 0; + _colorindex >>= nIndex; + + --nIndex; // OOo indices are zero bases + + // setColor expects colors in XL RGB values + // #FIXME this is daft we convert OO RGB val to XL RGB val and + // then back again to OO RGB value + setColor( OORGBToXLRGB(mxPalette->getByIndex( nIndex )) ); +} + + +uno::Any SAL_CALL +VbaFontBase::getColorIndex() throw ( uno::RuntimeException ) +{ + sal_Int32 nColor = 0; + + XLRGBToOORGB( getColor() ) >>= nColor; + sal_Int32 nElems = mxPalette->getCount(); + sal_Int32 nIndex = -1; + for ( sal_Int32 count=0; count<nElems; ++count ) + { + sal_Int32 nPaletteColor = 0; + mxPalette->getByIndex( count ) >>= nPaletteColor; + if ( nPaletteColor == nColor ) + { + nIndex = count + 1; // 1 based + break; + } + } + return uno::makeAny( nIndex ); +} + +void SAL_CALL +VbaFontBase::setBold( const uno::Any& aValue ) throw( uno::RuntimeException ) +{ + sal_Bool bValue = sal_False; + aValue >>= bValue; + double fBoldValue = awt::FontWeight::NORMAL; + if( bValue ) + fBoldValue = awt::FontWeight::BOLD; + mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharWeight", "FontWeight" ), uno::Any( fBoldValue ) ); + +} + +uno::Any SAL_CALL +VbaFontBase::getBold() throw ( uno::RuntimeException ) +{ + double fValue = 0.0; + mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharWeight", "FontWeight" ) ) >>= fValue; + return uno::makeAny( fValue == awt::FontWeight::BOLD ); +} + +void SAL_CALL +VbaFontBase::setStrikethrough( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + sal_Bool bValue = sal_False; + aValue >>= bValue; + short nValue = awt::FontStrikeout::NONE; + if( bValue ) + nValue = awt::FontStrikeout::SINGLE; + mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharStrikeout", "FontStrikeout" ), uno::Any( nValue ) ); +} + +uno::Any SAL_CALL +VbaFontBase::getStrikethrough() throw ( uno::RuntimeException ) +{ + short nValue = 0; + mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharStrikeout", "FontStrikeout" ) ) >>= nValue; + return uno::Any( nValue == awt::FontStrikeout::SINGLE ); +} + +void SAL_CALL +VbaFontBase::setShadow( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + if( !mbFormControl ) + mxFont->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharShadowed" ) ), aValue ); +} + +uno::Any SAL_CALL +VbaFontBase::getShadow() throw (uno::RuntimeException) +{ + return mbFormControl ? uno::Any( false ) : mxFont->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharShadowed" ) ) ); +} + +void SAL_CALL +VbaFontBase::setItalic( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + sal_Bool bValue = sal_False; + aValue >>= bValue; + short nValue = awt::FontSlant_NONE; + if( bValue ) + nValue = awt::FontSlant_ITALIC; + mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharPosture", "FontSlant" ), uno::Any( nValue ) ); +} + +uno::Any SAL_CALL +VbaFontBase::getItalic() throw ( uno::RuntimeException ) +{ + awt::FontSlant aFS; + mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharPosture", "FontSlant" ) ) >>= aFS; + return uno::makeAny( aFS == awt::FontSlant_ITALIC ); +} + +void SAL_CALL +VbaFontBase::setName( const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + rtl::OUString sString; + aValue >>= sString; + mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharFontName", "FontName" ), aValue ); +} + +uno::Any SAL_CALL +VbaFontBase::getName() throw ( uno::RuntimeException ) +{ + return mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharFontName", "FontName" ) ); +} + +uno::Any +VbaFontBase::getColor() throw (uno::RuntimeException) +{ + uno::Any aAny; + aAny = OORGBToXLRGB( mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharColor", "TextColor" ) ) ); + return aAny; +} + +void +VbaFontBase::setColor( const uno::Any& _color ) throw (uno::RuntimeException) +{ + mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharColor", "TextColor" ), XLRGBToOORGB(_color) ); +} + +void SAL_CALL +VbaFontBase::setUnderline( const uno::Any& /*aValue*/ ) throw ( uno::RuntimeException ) +{ +/* + // default + sal_Int32 nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone; + aValue >>= nValue; + switch ( nValue ) + { +// NOTE:: #TODO #FIMXE +// xlUnderlineStyleDoubleAccounting & xlUnderlineStyleSingleAccounting +// don't seem to be supported in Openoffice. +// The import filter converts them to single or double underlines as appropriate +// So, here at the moment we are similarly silently converting +// xlUnderlineStyleSingleAccounting to xlUnderlineStyleSingle. + + case excel::XlUnderlineStyle::xlUnderlineStyleNone: + nValue = awt::FontUnderline::NONE; + break; + case excel::XlUnderlineStyle::xlUnderlineStyleSingle: + case excel::XlUnderlineStyle::xlUnderlineStyleSingleAccounting: + nValue = awt::FontUnderline::SINGLE; + break; + case excel::XlUnderlineStyle::xlUnderlineStyleDouble: + case excel::XlUnderlineStyle::xlUnderlineStyleDoubleAccounting: + nValue = awt::FontUnderline::DOUBLE; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown value for Underline")), uno::Reference< uno::XInterface >() ); + } + + mxFont->setPropertyValue( VBAFONTBASE_PROPNAME( "CharUnderline", "FontUnderline" ), uno::Any( nValue ) ); +*/ + +} + +uno::Any SAL_CALL +VbaFontBase::getUnderline() throw ( uno::RuntimeException ) +{ + sal_Int32 nValue = awt::FontUnderline::NONE; + mxFont->getPropertyValue( VBAFONTBASE_PROPNAME( "CharUnderline", "FontUnderline" ) ) >>= nValue; +/* + switch ( nValue ) + { + case awt::FontUnderline::DOUBLE: + nValue = excel::XlUnderlineStyle::xlUnderlineStyleDouble; + break; + case awt::FontUnderline::SINGLE: + nValue = excel::XlUnderlineStyle::xlUnderlineStyleSingle; + break; + case awt::FontUnderline::NONE: + nValue = excel::XlUnderlineStyle::xlUnderlineStyleNone; + break; + default: + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown value retrieved for Underline") ), uno::Reference< uno::XInterface >() ); + + } +*/ + return uno::makeAny( nValue ); +} + + diff --git a/vbahelper/source/vbahelper/vbaglobalbase.cxx b/vbahelper/source/vbahelper/vbaglobalbase.cxx new file mode 100644 index 000000000000..e0df37583df5 --- /dev/null +++ b/vbahelper/source/vbahelper/vbaglobalbase.cxx @@ -0,0 +1,156 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbahelper/vbaglobalbase.hxx" + +#include <cppuhelper/component_context.hxx> +#include <comphelper/processfactory.hxx> +#include <com/sun/star/container/XNameContainer.hpp> + +using namespace com::sun::star; +using namespace ooo::vba; + +rtl::OUString sApplication( RTL_CONSTASCII_USTRINGPARAM("Application") ); + +// special key to return the Application +rtl::OUString sAppService( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.Application") ); + +VbaGlobalsBase::VbaGlobalsBase( +const uno::Reference< ov::XHelperInterface >& xParent, +const uno::Reference< uno::XComponentContext >& xContext, const rtl::OUString& sDocCtxName ) +: Globals_BASE( xParent, xContext ), msDocCtxName( sDocCtxName ) +{ + // overwrite context with custom one ( that contains the application ) + // wrap the service manager as we don't want the disposing context to tear down the 'normal' ServiceManager ( or at least thats what the code appears like it wants to do ) + uno::Any aSrvMgr; + if ( xContext.is() && xContext->getServiceManager().is() ) + { + aSrvMgr = uno::makeAny( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.stoc.OServiceManagerWrapper") ), xContext ) ); + } + + ::cppu::ContextEntry_Init aHandlerContextInfo[] = + { + ::cppu::ContextEntry_Init( sApplication, uno::Any() ), + ::cppu::ContextEntry_Init( sDocCtxName, uno::Any() ), + ::cppu::ContextEntry_Init( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/singletons/com.sun.star.lang.theServiceManager" ) ), aSrvMgr ) + }; + // don't pass a delegate, this seems to introduce yet another cyclic dependency ( and + // some strange behavior + mxContext = ::cppu::createComponentContext( aHandlerContextInfo, sizeof( aHandlerContextInfo ) / sizeof( aHandlerContextInfo[0] ), NULL ); +} + +VbaGlobalsBase::~VbaGlobalsBase() +{ + try + { + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY ); + if ( xNameContainer.is() ) + { + // release document reference ( we don't wan't the component context trying to dispose that ) + xNameContainer->removeByName( msDocCtxName ); + // release application reference, as it is holding onto the context + xNameContainer->removeByName( sApplication ); + } + } + catch ( const uno::Exception& ) + { + } +} + +void +VbaGlobalsBase::init( const uno::Sequence< beans::PropertyValue >& aInitArgs ) +{ + sal_Int32 nLen = aInitArgs.getLength(); + for ( sal_Int32 nIndex = 0; nIndex < nLen; ++nIndex ) + { + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY_THROW ); + if ( aInitArgs[ nIndex ].Name.equals( sApplication ) ) + { + xNameContainer->replaceByName( sApplication, aInitArgs[ nIndex ].Value ); + uno::Reference< XHelperInterface > xParent( aInitArgs[ nIndex ].Value, uno::UNO_QUERY ); + mxParent = xParent; + } + else + xNameContainer->replaceByName( aInitArgs[ nIndex ].Name, aInitArgs[ nIndex ].Value ); + } +} + +uno::Reference< uno::XInterface > SAL_CALL +VbaGlobalsBase::createInstance( const ::rtl::OUString& aServiceSpecifier ) throw (uno::Exception, uno::RuntimeException) +{ + uno::Reference< uno::XInterface > xReturn; + if ( aServiceSpecifier.equals( sAppService ) ) + { + // try to extract the Application from the context + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY ); + xNameContainer->getByName( sApplication ) >>= xReturn; + } + else if ( hasServiceName( aServiceSpecifier ) ) + xReturn = mxContext->getServiceManager()->createInstanceWithContext( aServiceSpecifier, mxContext ); + return xReturn; +} + +uno::Reference< uno::XInterface > SAL_CALL +VbaGlobalsBase::createInstanceWithArguments( const ::rtl::OUString& aServiceSpecifier, const uno::Sequence< uno::Any >& Arguments ) throw (uno::Exception, uno::RuntimeException) +{ + + uno::Reference< uno::XInterface > xReturn; + if ( aServiceSpecifier.equals( sAppService ) ) + { + // try to extract the Application from the context + uno::Reference< container::XNameContainer > xNameContainer( mxContext, uno::UNO_QUERY ); + xNameContainer->getByName( sApplication ) >>= xReturn; + } + else if ( hasServiceName( aServiceSpecifier ) ) + xReturn = mxContext->getServiceManager()->createInstanceWithArgumentsAndContext( aServiceSpecifier, Arguments, mxContext ); + return xReturn; +} + +uno::Sequence< ::rtl::OUString > SAL_CALL +VbaGlobalsBase::getAvailableServiceNames( ) throw (uno::RuntimeException) +{ + static const rtl::OUString names[] = { + // common + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "ooo.vba.msforms.UserForm" ) ), + }; + static uno::Sequence< rtl::OUString > serviceNames( names, sizeof( names )/ sizeof( names[0] ) ); + return serviceNames; +} + +bool +VbaGlobalsBase::hasServiceName( const rtl::OUString& serviceName ) +{ + uno::Sequence< rtl::OUString > sServiceNames( getAvailableServiceNames() ); + sal_Int32 nLen = sServiceNames.getLength(); + for ( sal_Int32 index = 0; index < nLen; ++index ) + { + if ( sServiceNames[ index ].equals( serviceName ) ) + return true; + } + return false; +} + + diff --git a/vbahelper/source/vbahelper/vbahelper.cxx b/vbahelper/source/vbahelper/vbahelper.cxx new file mode 100644 index 000000000000..2a13124a741e --- /dev/null +++ b/vbahelper/source/vbahelper/vbahelper.cxx @@ -0,0 +1,1381 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <cppuhelper/bootstrap.hxx> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XDesktop.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/XModel2.hpp> +#include <com/sun/star/script/XDefaultProperty.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/beans/XIntrospection.hpp> +#include <com/sun/star/util/MeasureUnit.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XDialog.hpp> +#include <com/sun/star/awt/PosSize.hpp> + +#include <ooo/vba/msforms/XShape.hpp> + +#include <comphelper/processfactory.hxx> + +#include <sfx2/objsh.hxx> +#include <sfx2/viewfrm.hxx> +#include <sfx2/dispatch.hxx> +#include <sfx2/app.hxx> +#include <svl/stritem.hxx> +#include <svl/eitem.hxx> +#include <svl/intitem.hxx> +#include <svl/itemset.hxx> +#include <sfx2/docfac.hxx> +#include <sfx2/viewfac.hxx> + +#include <basic/sbx.hxx> +#include <basic/sbstar.hxx> +#include <basic/basmgr.hxx> +#include <basic/sbmod.hxx> +#include <basic/sbmeth.hxx> +#include <rtl/math.hxx> +#include <sfx2/viewsh.hxx> +#include <math.h> +#include <tools/urlobj.hxx> +#include <osl/file.hxx> +#include <toolkit/awt/vclxwindow.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <vcl/window.hxx> +#include <vcl/syswin.hxx> +#include <tools/diagnose_ex.h> + +#ifndef OOVBA_DLLIMPLEMENTATION +#define OOVBA_DLLIMPLEMENTATION +#endif + +#include <vbahelper/vbahelper.hxx> +#include <sfx2/app.hxx> +// #FIXME needs service +//#include "vbashape.hxx" +//#include "unonames.hxx" + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +void unoToSbxValue( SbxVariable* pVar, const uno::Any& aValue ); + +uno::Any sbxToUnoValue( SbxVariable* pVar ); + + +namespace ooo +{ +namespace vba +{ + +namespace { const double factor = 2540.0 / 72.0; } + +css::uno::Reference< css::uno::XInterface > createVBAUnoAPIService( SfxObjectShell* pShell, const sal_Char* _pAsciiName ) throw (css::uno::RuntimeException) +{ + OSL_PRECOND( pShell, "createVBAUnoAPIService: no shell!" ); + ::rtl::OUString sVarName( ::rtl::OUString::createFromAscii( _pAsciiName ) ); + return getVBAServiceFactory( pShell )->createInstance( sVarName ); +} + +// helper method to determine if the view ( calc ) is in print-preview mode +bool isInPrintPreview( SfxViewFrame* pView ) +{ + sal_uInt16 nViewNo = SID_VIEWSHELL1 - SID_VIEWSHELL0; + if ( pView->GetObjectShell()->GetFactory().GetViewFactoryCount() > +nViewNo && !pView->GetObjectShell()->IsInPlaceActive() ) + { + SfxViewFactory &rViewFactory = + pView->GetObjectShell()->GetFactory().GetViewFactory(nViewNo); + if ( pView->GetCurViewId() == rViewFactory.GetOrdinal() ) + return true; + } + return false; +} +#if 0 +namespace excel // all in this namespace probably can be moved to sc +{ + + +const ::rtl::OUString REPLACE_CELLS_WARNING( RTL_CONSTASCII_USTRINGPARAM( "ReplaceCellsWarning")); +class PasteCellsWarningReseter +{ +private: + bool bInitialWarningState; + static uno::Reference< beans::XPropertySet > getGlobalSheetSettings() throw ( uno::RuntimeException ) + { + static uno::Reference< beans::XPropertySet > xTmpProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + static uno::Reference<uno::XComponentContext > xContext( xTmpProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); + static uno::Reference<lang::XMultiComponentFactory > xServiceManager( + xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + static uno::Reference< beans::XPropertySet > xProps( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.GlobalSheetSettings" ) ) ,xContext ), uno::UNO_QUERY_THROW ); + return xProps; + } + + bool getReplaceCellsWarning() throw ( uno::RuntimeException ) + { + sal_Bool res = sal_False; + getGlobalSheetSettings()->getPropertyValue( REPLACE_CELLS_WARNING ) >>= res; + return ( res == sal_True ); + } + + void setReplaceCellsWarning( bool bState ) throw ( uno::RuntimeException ) + { + getGlobalSheetSettings()->setPropertyValue( REPLACE_CELLS_WARNING, uno::makeAny( bState ) ); + } +public: + PasteCellsWarningReseter() throw ( uno::RuntimeException ) + { + bInitialWarningState = getReplaceCellsWarning(); + if ( bInitialWarningState ) + setReplaceCellsWarning( false ); + } + ~PasteCellsWarningReseter() + { + if ( bInitialWarningState ) + { + // don't allow dtor to throw + try + { + setReplaceCellsWarning( true ); + } + catch ( uno::Exception& /*e*/ ){} + } + } +}; + +void +implnPaste() +{ + PasteCellsWarningReseter resetWarningBox; + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + { + pViewShell->PasteFromSystem(); + pViewShell->CellContentChanged(); + } +} + + +void +implnCopy() +{ + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + pViewShell->CopyToClip(NULL,false,false,true); +} + +void +implnCut() +{ + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + pViewShell->CutToClip( NULL, sal_True ); +} +void implnPasteSpecial(SfxViewShell* pViewShell, sal_uInt16 nFlags,sal_uInt16 nFunction,sal_Bool bSkipEmpty, sal_Bool bTranspose) +{ + PasteCellsWarningReseter resetWarningBox; + sal_Bool bAsLink(sal_False), bOtherDoc(sal_False); + InsCellCmd eMoveMode = INS_NONE; + + if ( !pTabViewShell ) + // none active, try next best + pTabViewShell = getCurrentBestViewShell(); + if ( pTabViewShell ) + { + ScViewData* pView = pTabViewShell->GetViewData(); + Window* pWin = ( pView != NULL ) ? pView->GetActiveWin() : NULL; + if ( pView && pWin ) + { + if ( bAsLink && bOtherDoc ) + pTabViewShell->PasteFromSystem(0);//SOT_FORMATSTR_ID_LINK + else + { + ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard( pWin ); + ScDocument* pDoc = NULL; + if ( pOwnClip ) + pDoc = pOwnClip->GetDocument(); + pTabViewShell->PasteFromClip( nFlags, pDoc, + nFunction, bSkipEmpty, bTranspose, bAsLink, + eMoveMode, IDF_NONE, sal_True ); + pTabViewShell->CellContentChanged(); + } + } + } + +} + +ScDocShell* +getDocShell( css::uno::Reference< css::frame::XModel>& xModel ) +{ + uno::Reference< uno::XInterface > xIf( xModel, uno::UNO_QUERY_THROW ); + ScModelObj* pModel = dynamic_cast< ScModelObj* >( xIf.get() ); + ScDocShell* pDocShell = NULL; + if ( pModel ) + pDocShell = (ScDocShell*)pModel->GetEmbeddedObject(); + return pDocShell; + +} + +ScTabViewShell* +getBestViewShell( css::uno::Reference< css::frame::XModel>& xModel ) +{ + ScDocShell* pDocShell = getDocShell( xModel ); + if ( pDocShell ) + return pDocShell->GetBestViewShell(); + return NULL; +} + +ScTabViewShell* +getCurrentBestViewShell() +{ + uno::Reference< frame::XModel > xModel = getCurrentDocument(); + return getBestViewShell( xModel ); +} + +SfxViewFrame* +getCurrentViewFrame() +{ + ScTabViewShell* pViewShell = getCurrentBestViewShell(); + if ( pViewShell ) + return pViewShell->GetViewFrame(); + return NULL; +} +}; + +#endif + +uno::Reference< beans::XIntrospectionAccess > +getIntrospectionAccess( const uno::Any& aObject ) throw (uno::RuntimeException) +{ + static uno::Reference< beans::XIntrospection > xIntrospection; + if( !xIntrospection.is() ) + { + uno::Reference< lang::XMultiServiceFactory > xFactory( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + xIntrospection.set( xFactory->createInstance( rtl::OUString::createFromAscii("com.sun.star.beans.Introspection") ), uno::UNO_QUERY_THROW ); + } + return xIntrospection->inspect( aObject ); +} + +uno::Reference< script::XTypeConverter > +getTypeConverter( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + static uno::Reference< script::XTypeConverter > xTypeConv( xContext->getServiceManager()->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.script.Converter") ), xContext ), uno::UNO_QUERY_THROW ); + return xTypeConv; +} +const uno::Any& +aNULL() +{ + static uno::Any aNULLL = uno::makeAny( uno::Reference< uno::XInterface >() ); + return aNULLL; +} + +void dispatchExecute(SfxViewShell* pViewShell, sal_uInt16 nSlot, SfxCallMode nCall) +{ + SfxViewFrame* pViewFrame = NULL; + if ( pViewShell ) + pViewFrame = pViewShell->GetViewFrame(); + if ( pViewFrame ) + { + SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); + if( pDispatcher ) + { + pDispatcher->Execute( nSlot , nCall ); + } + } +} + +void +dispatchRequests( const uno::Reference< frame::XModel>& xModel, const rtl::OUString& aUrl, const uno::Sequence< beans::PropertyValue >& sProps ) +{ + util::URL url; + url.Complete = aUrl; + rtl::OUString emptyString = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "" )); + uno::Reference<frame::XController> xController = xModel->getCurrentController(); + uno::Reference<frame::XFrame> xFrame = xController->getFrame(); + uno::Reference<frame::XDispatchProvider> xDispatchProvider (xFrame,uno::UNO_QUERY_THROW); + try + { + uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Reference<uno::XComponentContext > xContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW ); + if ( !xContext.is() ) + return; + + uno::Reference<lang::XMultiComponentFactory > xServiceManager = xContext->getServiceManager(); + if ( !xServiceManager.is() ) + return; + + uno::Reference<util::XURLTransformer> xParser( xServiceManager->createInstanceWithContext( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ) ), xContext), + uno::UNO_QUERY_THROW ); + if (!xParser.is()) + return; + xParser->parseStrict (url); + } + catch ( uno::Exception & /*e*/ ) + { + return; + } + + uno::Reference<frame::XDispatch> xDispatcher = xDispatchProvider->queryDispatch(url,emptyString,0); + + uno::Sequence<beans::PropertyValue> dispatchProps(1); + + sal_Int32 nProps = sProps.getLength(); + beans::PropertyValue* pDest = dispatchProps.getArray(); + if ( nProps ) + { + dispatchProps.realloc( nProps + 1 ); + // need to reaccquire pDest after realloc + pDest = dispatchProps.getArray(); + const beans::PropertyValue* pSrc = sProps.getConstArray(); + for ( sal_Int32 index=0; index<nProps; ++index, ++pSrc, ++pDest ) + *pDest = *pSrc; + } + + (*pDest).Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Silent" )); + (*pDest).Value <<= (sal_Bool)sal_True; + + if (xDispatcher.is()) + xDispatcher->dispatch( url, dispatchProps ); +} + +void +dispatchRequests( const uno::Reference< frame::XModel>& xModel, const rtl::OUString& aUrl ) +{ + uno::Sequence<beans::PropertyValue> dispatchProps; + dispatchRequests( xModel, aUrl, dispatchProps ); +} + +uno::Reference< frame::XModel > +getCurrentDoc( const rtl::OUString& sKey ) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel; + SbxObject* pBasic = dynamic_cast< SbxObject* > ( SFX_APP()->GetBasic() ); + SbxObject* basicChosen = pBasic ; + if ( basicChosen == NULL) + { + OSL_TRACE("getModelFromBasic() StarBASIC* is NULL" ); + return xModel; + } + SbxObject* p = pBasic; + SbxObject* pParent = p->GetParent(); + SbxObject* pParentParent = pParent ? pParent->GetParent() : NULL; + + if( pParentParent ) + { + basicChosen = pParentParent; + } + else if( pParent ) + { + basicChosen = pParent; + } + + + uno::Any aModel; + SbxVariable *pCompVar = basicChosen->Find( sKey, SbxCLASS_OBJECT ); + + if ( pCompVar ) + { + aModel = sbxToUnoValue( pCompVar ); + if ( sal_False == ( aModel >>= xModel ) || + !xModel.is() ) + { + throw uno::RuntimeException( + rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Can't extract model from basic ( its obviously not set yet ) therefore don't know the current documet context") ), uno::Reference< uno::XInterface >() ); + } + else + { + OSL_TRACE("Have model points to url %s", + ::rtl::OUStringToOString( xModel->getURL(), + RTL_TEXTENCODING_ASCII_US ).pData->buffer ); + } + } + else + { + OSL_TRACE("Failed to get %s", rtl::OUStringToOString( sKey, RTL_TEXTENCODING_UTF8 ).getStr() ); + throw uno::RuntimeException( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "Can't determine the currently selected document") ), + uno::Reference< uno::XInterface >() ); + } + return xModel; +} + + uno::Reference< frame::XModel > +getCurrentDocCtx( const rtl::OUString& ctxName, const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + uno::Reference< frame::XModel > xModel; + // try fallback to calling doc + css::uno::Reference< css::container::XNameAccess > xNameAccess( xContext, css::uno::UNO_QUERY_THROW ); + xModel.set( xNameAccess->getByName( ctxName ), uno::UNO_QUERY_THROW ); + return xModel; +} + +uno::Reference< frame::XModel > +getThisExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + return getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ExcelDocumentContext" ) ), xContext ); +} + +uno::Reference< frame::XModel > +getThisWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + return getCurrentDocCtx( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("WordDocumentContext" ) ), xContext ); +} + + uno::Reference< frame::XModel > +getCurrentExcelDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + static const rtl::OUString sThisExcelDoc( RTL_CONSTASCII_USTRINGPARAM("ThisExcelDoc" ) ); + uno::Reference< frame::XModel > xModel; + try + { + xModel = getCurrentDoc( sThisExcelDoc ); + } + catch( uno::Exception& e ) + { + xModel = getThisExcelDoc( xContext ); + } + return xModel; +} + + uno::Reference< frame::XModel > +getCurrentWordDoc( const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException) +{ + static const rtl::OUString sThisWordDoc( RTL_CONSTASCII_USTRINGPARAM("ThisWordDoc" ) ); + uno::Reference< frame::XModel > xModel; + try + { + xModel = getCurrentDoc( sThisWordDoc ); + } + catch( uno::Exception& e ) + { + xModel = getThisWordDoc( xContext ); + } + return xModel; +} + +sal_Int32 +OORGBToXLRGB( sal_Int32 nCol ) +{ + sal_Int32 nAutoBits = nCol; + nAutoBits &= 0xFF000000; + sal_Int32 nRed = nCol; + nRed &= 0x00FF0000; + nRed >>= 16; + sal_Int32 nGreen = nCol; + nGreen &= 0x0000FF00; + nGreen >>= 8; + sal_Int32 nBlue = nCol; + nBlue &= 0x000000FF; + sal_Int32 nRGB = ( nAutoBits | (nBlue << 16) | (nGreen << 8) | nRed ); + return nRGB; +} +sal_Int32 +XLRGBToOORGB( sal_Int32 nCol ) +{ + sal_Int32 nAutoBits = nCol; + nAutoBits &= 0xFF000000; + + sal_Int32 nBlue = nCol; + nBlue &= 0x00FF0000; + nBlue >>= 16; + sal_Int32 nGreen = nCol; + nGreen &= 0x0000FF00; + nGreen >>= 8; + sal_Int32 nRed = nCol; + nRed &= 0x000000FF; + sal_Int32 nRGB = ( nAutoBits | (nRed << 16) | (nGreen << 8) | nBlue ); + return nRGB; +} +uno::Any +OORGBToXLRGB( const uno::Any& aCol ) +{ + sal_Int32 nCol(0); + aCol >>= nCol; + nCol = OORGBToXLRGB( nCol ); + return uno::makeAny( nCol ); +} +uno::Any +XLRGBToOORGB( const uno::Any& aCol ) +{ + sal_Int32 nCol(0); + aCol >>= nCol; + nCol = XLRGBToOORGB( nCol ); + return uno::makeAny( nCol ); +} + +void PrintOutHelper( SfxViewShell* pViewShell, const uno::Any& From, const uno::Any& To, const uno::Any& Copies, const uno::Any& Preview, const uno::Any& /*ActivePrinter*/, const uno::Any& /*PrintToFile*/, const uno::Any& Collate, const uno::Any& PrToFileName, sal_Bool bUseSelection ) +{ + sal_Int32 nTo = 0; + sal_Int32 nFrom = 0; + sal_Int16 nCopies = 1; + sal_Bool bPreview = sal_False; + sal_Bool bCollate = sal_False; + sal_Bool bSelection = bUseSelection; + From >>= nFrom; + To >>= nTo; + Copies >>= nCopies; + Preview >>= bPreview; + if ( nCopies > 1 ) // Collate only useful when more that 1 copy + Collate >>= bCollate; + + rtl::OUString sRange( RTL_CONSTASCII_USTRINGPARAM( "-" ) ); + rtl::OUString sFileName; + + if (( nFrom || nTo ) ) + { + if ( nFrom ) + sRange = ( ::rtl::OUString::valueOf( nFrom ) + sRange ); + if ( nTo ) + sRange += ::rtl::OUString::valueOf( nTo ); + } + + if ( PrToFileName.getValue() ) + { + PrToFileName >>= sFileName; + } + SfxViewFrame* pViewFrame = NULL; + if ( pViewShell ) + pViewFrame = pViewShell->GetViewFrame(); + if ( pViewFrame ) + { + SfxAllItemSet aArgs( SFX_APP()->GetPool() ); + + SfxBoolItem sfxCollate( SID_PRINT_COLLATE, bCollate ); + aArgs.Put( sfxCollate, sfxCollate.Which() ); + SfxInt16Item sfxCopies( SID_PRINT_COPIES, nCopies ); + aArgs.Put( sfxCopies, sfxCopies.Which() ); + if ( sFileName.getLength() ) + { + SfxStringItem sfxFileName( SID_FILE_NAME, sFileName); + aArgs.Put( sfxFileName, sfxFileName.Which() ); + + } + if ( sRange.getLength() ) + { + SfxStringItem sfxRange( SID_PRINT_PAGES, sRange ); + aArgs.Put( sfxRange, sfxRange.Which() ); + } + SfxBoolItem sfxSelection( SID_SELECTION, bSelection ); + aArgs.Put( sfxSelection, sfxSelection.Which() ); + SfxBoolItem sfxAsync( SID_ASYNCHRON, sal_False ); + aArgs.Put( sfxAsync, sfxAsync.Which() ); + SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher(); + + if ( pDispatcher ) + { + if ( bPreview ) + { + if ( !pViewFrame->GetFrame().IsInPlace() ) + { + // #TODO is this necessary ( calc specific ) +// SC_MOD()->InputEnterHandler(); + pViewFrame->GetDispatcher()->Execute( SID_VIEWSHELL1, SFX_CALLMODE_SYNCHRON ); + while ( isInPrintPreview( pViewFrame ) ) + Application::Yield(); + } + } + else + pDispatcher->Execute( (sal_uInt16)SID_PRINTDOC, (SfxCallMode)SFX_CALLMODE_SYNCHRON, aArgs ); + } + + } + + // #FIXME #TODO + // 1 ActivePrinter ( how/can we switch a printer via API? ) + // 2 PrintToFile ( ms behaviour if this option is specified but no + // filename supplied 'PrToFileName' then the user will be prompted ) + // 3 Need to check behaviour of Selected sheets with range ( e.g. From & To + // values ) in oOO these options are mutually exclusive + // 4 There is a pop up to do with transparent objects in the print source + // should be able to disable that via configuration for the duration + // of this method +} + + void PrintPreviewHelper( const css::uno::Any& /*EnableChanges*/, SfxViewShell* pViewShell ) +{ + dispatchExecute( pViewShell, SID_VIEWSHELL1 ); +} + +sal_Int32 extractIntFromAny( const uno::Any& rAny ) throw (uno::RuntimeException) +{ + switch( rAny.getValueType().getTypeClass() ) + { + case uno::TypeClass_FLOAT: + return static_cast< sal_Int32 >( rAny.get< float >() ); + case uno::TypeClass_DOUBLE: + return static_cast< sal_Int32 >( rAny.get< double >() ); + case uno::TypeClass_BYTE: + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + return rAny.get< sal_Int32 >(); + default:; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to integer." ) ), 0 ); +} + +sal_Int32 extractIntFromAny( const uno::Any& rAny, sal_Int32 nDefault ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractIntFromAny( rAny ) : nDefault; +} + +bool extractBoolFromAny( const uno::Any& rAny ) throw (uno::RuntimeException) +{ + switch( rAny.getValueType().getTypeClass() ) + { + case uno::TypeClass_BOOLEAN: + return rAny.get< bool >(); + case uno::TypeClass_FLOAT: + return rAny.get< float >() != 0.0; + case uno::TypeClass_DOUBLE: + return rAny.get< double >() != 0.0; + case uno::TypeClass_BYTE: + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + return rAny.get< sal_Int32 >() != 0; + case uno::TypeClass_HYPER: + return rAny.get< sal_Int64 >() != 0; + default:; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to boolean." ) ), 0 ); +} + +bool extractBoolFromAny( const uno::Any& rAny, bool bDefault ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractBoolFromAny( rAny ) : bDefault; +} + +::rtl::OUString extractStringFromAny( const uno::Any& rAny, bool bUppercaseBool ) throw (uno::RuntimeException) +{ + switch( rAny.getValueType().getTypeClass() ) + { + case uno::TypeClass_STRING: + return rAny.get< ::rtl::OUString >(); + case uno::TypeClass_BOOLEAN: + return bUppercaseBool ? + (rAny.get< bool >() ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TRUE" ) ) : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FALSE" ) )) : + ::rtl::OUString::valueOf( (sal_Bool)rAny.get< bool >() ); + case uno::TypeClass_FLOAT: + return ::rtl::OUString::valueOf( rAny.get< float >() ); + case uno::TypeClass_DOUBLE: + return ::rtl::OUString::valueOf( rAny.get< double >() ); + case uno::TypeClass_BYTE: + case uno::TypeClass_SHORT: + case uno::TypeClass_LONG: + return ::rtl::OUString::valueOf( rAny.get< sal_Int32 >() ); + case uno::TypeClass_HYPER: + return ::rtl::OUString::valueOf( rAny.get< sal_Int64 >() ); + default:; + } + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid type, cannot convert to string." ) ), 0 ); +} + +::rtl::OUString extractStringFromAny( const uno::Any& rAny, const ::rtl::OUString& rDefault, bool bUppercaseBool ) throw (uno::RuntimeException) +{ + return rAny.hasValue() ? extractStringFromAny( rAny, bUppercaseBool ) : rDefault; +} + +rtl::OUString getAnyAsString( const uno::Any& pvargItem ) throw ( uno::RuntimeException ) +{ + return extractStringFromAny( pvargItem ); +} + + +rtl::OUString +ContainerUtilities::getUniqueName( const uno::Sequence< ::rtl::OUString >& _slist, const rtl::OUString& _sElementName, const ::rtl::OUString& _sSuffixSeparator) +{ + return getUniqueName(_slist, _sElementName, _sSuffixSeparator, sal_Int32(2)); +} + +rtl::OUString +ContainerUtilities::getUniqueName( const uno::Sequence< rtl::OUString >& _slist, const rtl::OUString _sElementName, const rtl::OUString& _sSuffixSeparator, sal_Int32 _nStartSuffix) +{ + sal_Int32 a = _nStartSuffix; + rtl::OUString scompname = _sElementName; + bool bElementexists = true; + sal_Int32 nLen = _slist.getLength(); + if ( nLen == 0 ) + return _sElementName; + + while (bElementexists == true) + { + for (sal_Int32 i = 0; i < nLen; i++) + { + if (FieldInList(_slist, scompname) == -1) + { + return scompname; + } + } + scompname = _sElementName + _sSuffixSeparator + rtl::OUString::valueOf( a++ ); + } + return rtl::OUString(); +} + +sal_Int32 +ContainerUtilities::FieldInList( const uno::Sequence< rtl::OUString >& SearchList, const rtl::OUString& SearchString ) +{ + sal_Int32 FieldLen = SearchList.getLength(); + sal_Int32 retvalue = -1; + for (sal_Int32 i = 0; i < FieldLen; i++) + { + // I wonder why comparing lexicographically is done + // when its a match is whats interesting? + //if (SearchList[i].compareTo(SearchString) == 0) + if ( SearchList[i].equals( SearchString ) ) + { + retvalue = i; + break; + } + } + return retvalue; + +} +bool NeedEsc(sal_Unicode cCode) +{ + String sEsc(RTL_CONSTASCII_USTRINGPARAM(".^$+\\|{}()")); + return (STRING_NOTFOUND != sEsc.Search(cCode)); +} + +rtl::OUString VBAToRegexp(const rtl::OUString &rIn, bool bForLike ) +{ + rtl::OUStringBuffer sResult; + const sal_Unicode *start = rIn.getStr(); + const sal_Unicode *end = start + rIn.getLength(); + + int seenright = 0; + if ( bForLike ) + sResult.append(static_cast<sal_Unicode>('^')); + + while (start < end) + { + switch (*start) + { + case '?': + sResult.append(static_cast<sal_Unicode>('.')); + start++; + break; + case '*': + sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(".*"))); + start++; + break; + case '#': + sResult.append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("[0-9]"))); + start++; + break; + case '~': + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*(++start)); + start++; + break; + // dump the ~ and escape the next characture + case ']': + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start++); + break; + case '[': + sResult.append(*start++); + seenright = 0; + while (start < end && !seenright) + { + switch (*start) + { + case '[': + case '?': + case '*': + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start); + break; + case ']': + sResult.append(*start); + seenright = 1; + break; + case '!': + sResult.append(static_cast<sal_Unicode>('^')); + break; + default: + if (NeedEsc(*start)) + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start); + break; + } + start++; + } + break; + default: + if (NeedEsc(*start)) + sResult.append(static_cast<sal_Unicode>('\\')); + sResult.append(*start++); + } + } + + if ( bForLike ) + sResult.append(static_cast<sal_Unicode>('$')); + + return sResult.makeStringAndClear( ); +} + +double getPixelTo100thMillimeterConversionFactor( const css::uno::Reference< css::awt::XDevice >& xDevice, sal_Bool bVertical) +{ + double fConvertFactor = 1.0; + if( bVertical ) + { + fConvertFactor = xDevice->getInfo().PixelPerMeterY/100000; + } + else + { + fConvertFactor = xDevice->getInfo().PixelPerMeterX/100000; + } + return fConvertFactor; +} + +double PointsToPixels( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPoints, sal_Bool bVertical) +{ + double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); + return PointsToHmm( fPoints ) * fConvertFactor; +} +double PixelsToPoints( const css::uno::Reference< css::awt::XDevice >& xDevice, double fPixels, sal_Bool bVertical) +{ + double fConvertFactor = getPixelTo100thMillimeterConversionFactor( xDevice, bVertical ); + return HmmToPoints( fPixels/fConvertFactor ); +} + +sal_Int32 PointsToHmm( double fPoints ) +{ + return static_cast<sal_Int32>( fPoints * factor + 0.5 ); +} + +double HmmToPoints( sal_Int32 nHmm ) +{ + return nHmm / factor; +} + +ConcreteXShapeGeometryAttributes::ConcreteXShapeGeometryAttributes( const css::uno::Reference< css::uno::XComponentContext >& /*xContext*/, const css::uno::Reference< css::drawing::XShape >& xShape ) +{ + m_pShapeHelper.reset( new ShapeHelper( xShape ) ); +} +ConcreteXShapeGeometryAttributes::~ConcreteXShapeGeometryAttributes() +{ +} + +sal_Int32 getPointerStyle( const uno::Reference< frame::XModel >& xModel ) +{ + + sal_Int32 nPointerStyle( POINTER_ARROW ); + try + { + const uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + const uno::Reference< frame::XFrame > xFrame ( xController->getFrame(), uno::UNO_SET_THROW ); + const uno::Reference< awt::XWindow > xWindow ( xFrame->getContainerWindow(), uno::UNO_SET_THROW ); + // why the heck isn't there an XWindowPeer::getPointer, but a setPointer only? + const Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); + if ( pWindow ) + nPointerStyle = pWindow->GetSystemWindow()->GetPointer().GetStyle(); + } + catch( const uno::Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return nPointerStyle; +} + +// #FIXME this method looks wrong, shouldn't it just affect calc *or* writer +// document/frame/window(s) but not both ( and depending on what api called +// this ) +void setCursorHelper( const uno::Reference< frame::XModel >& xModel, const Pointer& rPointer, sal_Bool bOverWrite ) +{ + ::std::vector< uno::Reference< frame::XController > > aControllers; + + uno::Reference< frame::XModel2 > xModel2( xModel, uno::UNO_QUERY ); + if ( xModel2.is() ) + { + const uno::Reference< container::XEnumeration > xEnumControllers( xModel2->getControllers(), uno::UNO_SET_THROW ); + while ( xEnumControllers->hasMoreElements() ) + { + const uno::Reference< frame::XController > xController( xEnumControllers->nextElement(), uno::UNO_QUERY_THROW ); + aControllers.push_back( xController ); + } + } + else + { + if ( xModel.is() ) + { + const uno::Reference< frame::XController > xController( xModel->getCurrentController(), uno::UNO_SET_THROW ); + aControllers.push_back( xController ); + } + } + + for ( ::std::vector< uno::Reference< frame::XController > >::const_iterator controller = aControllers.begin(); + controller != aControllers.end(); + ++controller + ) + { + const uno::Reference< frame::XFrame > xFrame ( (*controller)->getFrame(), uno::UNO_SET_THROW ); + const uno::Reference< awt::XWindow > xWindow ( xFrame->getContainerWindow(), uno::UNO_SET_THROW ); + + Window* pWindow = VCLUnoHelper::GetWindow( xWindow ); + OSL_ENSURE( pWindow, "ScVbaApplication::setCursor: no window!" ); + if ( !pWindow ) + continue; + + pWindow->GetSystemWindow()->SetPointer( rPointer ); + pWindow->GetSystemWindow()->EnableChildPointerOverwrite( bOverWrite ); + } +} + +void setDefaultPropByIntrospection( const uno::Any& aObj, const uno::Any& aValue ) throw ( uno::RuntimeException ) +{ + uno::Reference< beans::XIntrospectionAccess > xUnoAccess( getIntrospectionAccess( aObj ) ); + + // #MAYBE #FIXME sort of a bit of a hack, + uno::Reference< script::XDefaultProperty > xDflt( aObj, uno::UNO_QUERY_THROW ); + uno::Reference< beans::XPropertySet > xPropSet; + + if ( xUnoAccess.is() ) + xPropSet.set( xUnoAccess->queryAdapter( ::getCppuType( (const uno::Reference< beans::XPropertySet > *)0 ) ), uno::UNO_QUERY); + + if ( xPropSet.is() ) + xPropSet->setPropertyValue( xDflt->getDefaultPropertyName(), aValue ); + else + throw uno::RuntimeException(); +} + +uno::Any getPropertyValue( const uno::Sequence< beans::PropertyValue >& aProp, const rtl::OUString& aName ) +{ + uno::Any result; + for ( sal_Int32 i = 0; i < aProp.getLength(); i++ ) + { + if ( aProp[i].Name.equals(aName) ) + { + aProp[i].Value >>= result; + return result; + } + } + return result; +} + +sal_Bool setPropertyValue( uno::Sequence< beans::PropertyValue >& aProp, const rtl::OUString& aName, const uno::Any& aValue ) +{ + for ( sal_Int32 i = 0; i < aProp.getLength(); i++ ) + { + if ( aProp[i].Name.equals(aName) ) + { + aProp[i].Value = aValue; + return sal_True; + } + } + return sal_False; +} + +// ====UserFormGeomentryHelper==== +//--------------------------------------------- +UserFormGeometryHelper::UserFormGeometryHelper( + const uno::Reference< uno::XComponentContext >& /*xContext*/, + const uno::Reference< awt::XControl >& xControl, + double fOffsetX, double fOffsetY ) : + mfOffsetX( fOffsetX ), + mfOffsetY( fOffsetY ), + mbDialog( uno::Reference< awt::XDialog >( xControl, uno::UNO_QUERY ).is() ) +{ + if ( !xControl.is() ) + throw uno::RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No control is provided!" ) ), + uno::Reference< uno::XInterface >() ); + + mxWindow.set( xControl->getPeer(), uno::UNO_QUERY_THROW ); + mxModelProps.set( xControl->getModel(), uno::UNO_QUERY_THROW ); + mxUnitConv.set( mxWindow, uno::UNO_QUERY_THROW ); +} + +double UserFormGeometryHelper::getLeft() const +{ + return implGetPos( false ); +} + +void UserFormGeometryHelper::setLeft( double fLeft ) +{ + implSetPos( fLeft, false ); +} + +double UserFormGeometryHelper::getTop() const +{ + return implGetPos( true ); +} + +void UserFormGeometryHelper::setTop( double fTop ) +{ + implSetPos( fTop, true ); +} + +double UserFormGeometryHelper::getWidth() const +{ + return implGetSize( false, true ); +} + +void UserFormGeometryHelper::setWidth( double fWidth ) +{ + implSetSize( fWidth, false, true ); +} + +double UserFormGeometryHelper::getHeight() const +{ + return implGetSize( true, true ); +} + +void UserFormGeometryHelper::setHeight( double fHeight ) +{ + implSetSize( fHeight, true, true ); +} + +double UserFormGeometryHelper::getInnerWidth() const +{ + return implGetSize( false, false ); +} + +void UserFormGeometryHelper::setInnerWidth( double fWidth ) +{ + implSetSize( fWidth, false, false ); +} + +double UserFormGeometryHelper::getInnerHeight() const +{ + return implGetSize( true, false ); +} + +void UserFormGeometryHelper::setInnerHeight( double fHeight ) +{ + implSetSize( fHeight, true, false ); +} + +double UserFormGeometryHelper::getOffsetX() const +{ + return mfOffsetX; +} + +double UserFormGeometryHelper::getOffsetY() const +{ + return mfOffsetY; +} + +// ---------------------------------------------------------------------------- + +static const ::rtl::OUString saPosXName( RTL_CONSTASCII_USTRINGPARAM( "PositionX" ) ); +static const ::rtl::OUString saPosYName( RTL_CONSTASCII_USTRINGPARAM( "PositionY" ) ); +static const ::rtl::OUString saWidthName( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ); +static const ::rtl::OUString saHeightName( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ); + +double UserFormGeometryHelper::implGetPos( bool bPosY ) const +{ + sal_Int32 nPosAppFont = mxModelProps->getPropertyValue( bPosY ? saPosYName : saPosXName ).get< sal_Int32 >(); + // appfont to pixel + awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosAppFont, nPosAppFont ), util::MeasureUnit::APPFONT ); + // pixel to VBA points + awt::Point aPosPoint = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::POINT ); + return bPosY ? (aPosPoint.Y - mfOffsetY) : (aPosPoint.X - mfOffsetX); +} + +void UserFormGeometryHelper::implSetPos( double fPos, bool bPosY ) +{ + // convert passed VBA points to pixels + sal_Int32 nPosPixel = static_cast< sal_Int32 >( fPos + (bPosY ? mfOffsetY : mfOffsetX) ); + awt::Point aPosPixel = mxUnitConv->convertPointToPixel( awt::Point( nPosPixel, nPosPixel ), util::MeasureUnit::POINT ); + // pixel to appfont + awt::Point aPosAppFont = mxUnitConv->convertPointToLogic( aPosPixel, util::MeasureUnit::APPFONT ); + mxModelProps->setPropertyValue( bPosY ? saPosYName : saPosXName, uno::Any( bPosY ? aPosAppFont.Y : aPosAppFont.X ) ); +} + +double UserFormGeometryHelper::implGetSize( bool bHeight, bool bOuter ) const +{ + sal_Int32 nSizeAppFont = mxModelProps->getPropertyValue( bHeight ? saHeightName : saWidthName ).get< sal_Int32 >(); + // appfont to pixel + awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSizeAppFont, nSizeAppFont ), util::MeasureUnit::APPFONT ); + + /* The VBA symbols 'Width' and 'Height' return the outer size including + window decoration (in difference to the symbols 'InnerWidth' and + 'InnerHeight'), but the window API returns the inner size. */ + if( mbDialog && bOuter ) + { + if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) ) + { + Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL ); + aSizePixel = awt::Size( aOuterRect.getWidth(), aOuterRect.getHeight() ); + } + } + + // pixel to VBA points + awt::Size aSizePoint = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::POINT ); + return bHeight ? aSizePoint.Height : aSizePoint.Width; +} + +void UserFormGeometryHelper::implSetSize( double fSize, bool bHeight, bool bOuter ) +{ + // convert passed VBA points to pixels + sal_Int32 nSize = static_cast< sal_Int32 >( fSize ); + awt::Size aSizePixel = mxUnitConv->convertSizeToPixel( awt::Size( nSize, nSize ), util::MeasureUnit::POINT ); + + /* The VBA symbols 'Width' and 'Height' set the outer size (in difference + to the symbols 'InnerWidth' and 'InnerHeight'), but the dialog model + expects the inner size. We have to remove the window extents from the + pixel height to get the same result. */ + if ( mbDialog && bOuter ) + { + if( const Window* pWindow = VCLUnoHelper::GetWindow( mxWindow ) ) + { + Rectangle aOuterRect = pWindow->GetWindowExtentsRelative( NULL ); + if( !aOuterRect.IsEmpty() ) + { + awt::Rectangle aInnerRect = mxWindow->getPosSize(); + sal_Int32 nDecorWidth = aOuterRect.getWidth() - aInnerRect.Width; + sal_Int32 nDecorHeight = aOuterRect.getHeight() - aInnerRect.Height; + aSizePixel.Width = ::std::max< sal_Int32 >( aSizePixel.Width - nDecorWidth, 1 ); + aSizePixel.Height = ::std::max< sal_Int32 >( aSizePixel.Height - nDecorHeight, 1 ); + } + } + } + + awt::Size aSizeAppFont = mxUnitConv->convertSizeToLogic( aSizePixel, util::MeasureUnit::APPFONT ); + mxModelProps->setPropertyValue( bHeight ? saHeightName : saWidthName, uno::Any( bHeight ? aSizeAppFont.Height : aSizeAppFont.Width ) ); +} + +// ============================================================================ + + double ConcreteXShapeGeometryAttributes::getLeft() const + { + return m_pShapeHelper->getLeft(); + } + void ConcreteXShapeGeometryAttributes::setLeft( double nLeft ) + { + m_pShapeHelper->setLeft( nLeft ); + } + double ConcreteXShapeGeometryAttributes::getTop() const + { + return m_pShapeHelper->getTop(); + } + void ConcreteXShapeGeometryAttributes::setTop( double nTop ) + { + m_pShapeHelper->setTop( nTop ); + } + + double ConcreteXShapeGeometryAttributes::getHeight() const + { + return m_pShapeHelper->getHeight(); + } + void ConcreteXShapeGeometryAttributes::setHeight( double nHeight ) + { + m_pShapeHelper->setHeight( nHeight ); + } + double ConcreteXShapeGeometryAttributes::getWidth() const + { + return m_pShapeHelper->getWidth(); + } + void ConcreteXShapeGeometryAttributes::setWidth( double nWidth) + { + m_pShapeHelper->setWidth( nWidth ); + } + + + ShapeHelper::ShapeHelper( const css::uno::Reference< css::drawing::XShape >& _xShape) throw (css::script::BasicErrorException ) : xShape( _xShape ) + { + if( !xShape.is() ) + throw css::uno::RuntimeException( rtl::OUString::createFromAscii("No valid shape for helper"), css::uno::Reference< css::uno::XInterface >() ); + } + + double ShapeHelper::getHeight() const + { + return Millimeter::getInPoints(xShape->getSize().Height); + } + + + void ShapeHelper::setHeight(double _fheight) throw ( css::script::BasicErrorException ) + { + try + { + css::awt::Size aSize = xShape->getSize(); + aSize.Height = Millimeter::getInHundredthsOfOneMillimeter(_fheight); + xShape->setSize(aSize); + } + catch ( css::uno::Exception& /*e*/) + { + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + } + + + double ShapeHelper::getWidth() const + { + return Millimeter::getInPoints(xShape->getSize().Width); + } + + void ShapeHelper::setWidth(double _fWidth) throw ( css::script::BasicErrorException ) + { + try + { + css::awt::Size aSize = xShape->getSize(); + aSize.Width = Millimeter::getInHundredthsOfOneMillimeter(_fWidth); + xShape->setSize(aSize); + } + catch (css::uno::Exception& /*e*/) + { + throw css::script::BasicErrorException( rtl::OUString(), css::uno::Reference< css::uno::XInterface >(), SbERR_METHOD_FAILED, rtl::OUString() ); + } + } + + + double ShapeHelper::getLeft() const + { + return Millimeter::getInPoints(xShape->getPosition().X); + } + + + void ShapeHelper::setLeft(double _fLeft) + { + css::awt::Point aPoint = xShape->getPosition(); + aPoint.X = Millimeter::getInHundredthsOfOneMillimeter(_fLeft); + xShape->setPosition(aPoint); + } + + + double ShapeHelper::getTop() const + { + return Millimeter::getInPoints(xShape->getPosition().Y); + } + + + void ShapeHelper::setTop(double _fTop) + { + css::awt::Point aPoint = xShape->getPosition(); + aPoint.Y = Millimeter::getInHundredthsOfOneMillimeter(_fTop); + xShape->setPosition(aPoint); + } + + void DebugHelper::exception( const rtl::OUString& DetailedMessage, const css::uno::Exception& ex, int err, const rtl::OUString& /*additionalArgument*/ ) throw( css::script::BasicErrorException ) + { + // #TODO #FIXME ( do we want to support additionalArg here ) + throw css::script::BasicErrorException( DetailedMessage.concat( rtl::OUString::createFromAscii(" ") ).concat( ex.Message ), css::uno::Reference< css::uno::XInterface >(), err, rtl::OUString() ); + } + + void DebugHelper::exception( int err, const rtl::OUString& additionalArgument ) throw( css::script::BasicErrorException ) + { + exception( rtl::OUString(), css::uno::Exception(), err, additionalArgument ); + } + void DebugHelper::exception( css::uno::Exception& ex ) throw( css::script::BasicErrorException ) + { + exception( rtl::OUString(), ex, SbERR_INTERNAL_ERROR, rtl::OUString() ); + } + + Millimeter::Millimeter():m_nMillimeter(0) {} + + Millimeter::Millimeter(double mm):m_nMillimeter(mm) {} + + void Millimeter::set(double mm) { m_nMillimeter = mm; } + void Millimeter::setInPoints(double points) + { + m_nMillimeter = points * factor / 100.0; + } + + void Millimeter::setInHundredthsOfOneMillimeter(double hmm) + { + m_nMillimeter = hmm / 100; + } + + double Millimeter::get() + { + return m_nMillimeter; + } + double Millimeter::getInHundredthsOfOneMillimeter() + { + return m_nMillimeter * 100; + } + double Millimeter::getInPoints() + { + return m_nMillimeter / factor * 100.0; + } + + sal_Int32 Millimeter::getInHundredthsOfOneMillimeter(double points) + { + sal_Int32 mm = static_cast<sal_Int32>(points * factor); + return mm; + } + + double Millimeter::getInPoints(int _hmm) + { + double points = double( static_cast<double>(_hmm) / factor); + return points; + } + +uno::Reference< XHelperInterface > getVBADocument( const uno::Reference< frame::XModel >& xModel ) +{ + uno::Reference< XHelperInterface > xIf; + try + { + uno::Reference< beans::XPropertySet > xDocProps( xModel, uno::UNO_QUERY_THROW ); + ::rtl::OUString aCodeName; + xDocProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CodeName" ) ) ) >>= aCodeName; + xIf = getUnoDocModule( aCodeName, getSfxObjShell( xModel ) ); + } + catch( uno::Exception& ) + { + } + return xIf; +} + +uno::Reference< XHelperInterface > getUnoDocModule( const String& aModName, SfxObjectShell* pShell ) +{ + uno::Reference< XHelperInterface > xIf; + if ( pShell ) + { + rtl::OUString sProj( RTL_CONSTASCII_USTRINGPARAM("Standard") ); + BasicManager* pBasMgr = pShell->GetBasicManager(); + if ( pBasMgr && pBasMgr->GetName().Len() ) + sProj = pBasMgr->GetName(); + if( StarBASIC* pBasic = pShell->GetBasicManager()->GetLib( sProj ) ) + if( SbModule* pMod = pBasic->FindModule( aModName ) ) + xIf.set( pMod->GetUnoModule(), uno::UNO_QUERY ); + } + return xIf; +} + +SfxObjectShell* getSfxObjShell( const uno::Reference< frame::XModel >& xModel ) throw (uno::RuntimeException) +{ + SfxObjectShell* pFoundShell = NULL; + if ( xModel.is() ) + { + uno::Reference< lang::XUnoTunnel > xObjShellTunnel( xModel, uno::UNO_QUERY_THROW ); + pFoundShell = reinterpret_cast<SfxObjectShell*>( xObjShellTunnel->getSomething(SfxObjectShell::getUnoTunnelId())); + } + if ( !pFoundShell ) + throw uno::RuntimeException(); + return pFoundShell; +} + +} // openoffice +} //org diff --git a/vbahelper/source/vbahelper/vbalineformat.cxx b/vbahelper/source/vbahelper/vbalineformat.cxx new file mode 100644 index 000000000000..e0ea1f3e077b --- /dev/null +++ b/vbahelper/source/vbahelper/vbalineformat.cxx @@ -0,0 +1,455 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <ooo/vba/office/MsoArrowheadStyle.hpp> +#include <ooo/vba/office/MsoArrowheadLength.hpp> +#include <ooo/vba/office/MsoArrowheadWidth.hpp> +#include <ooo/vba/office/MsoLineDashStyle.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/drawing/LineDash.hpp> +#include "vbalineformat.hxx" +#include "vbacolorformat.hxx" + +using namespace ooo::vba; +using namespace com::sun::star; + +ScVbaLineFormat::ScVbaLineFormat( const uno::Reference< ov::XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape > xShape ) : ScVbaLineFormat_BASE( xParent, xContext ), m_xShape( xShape ) +{ + m_xPropertySet.set( xShape, uno::UNO_QUERY_THROW ); + m_nLineDashStyle = office::MsoLineDashStyle::msoLineSolid; + m_nLineWeight = 1; +} + +sal_Int32 +ScVbaLineFormat::calculateArrowheadSize() +{ + return 0; +} + +sal_Int32 +ScVbaLineFormat::convertLineStartEndNameToArrowheadStyle( rtl::OUString sLineName ) +{ + sal_Int32 nLineType = office::MsoArrowheadStyle::msoArrowheadNone; + if (sLineName.equals(rtl::OUString::createFromAscii("Small Arrow")) || + sLineName.equals(rtl::OUString::createFromAscii("Arrow")) || + sLineName.equals(rtl::OUString::createFromAscii("msArrowEnd")) || + sLineName.equals(rtl::OUString::createFromAscii("Double Arrow"))) + { + // msoArrowheadTriangle + nLineType = office::MsoArrowheadStyle::msoArrowheadTriangle; + } + else if (sLineName.equals(rtl::OUString::createFromAscii("Square 45")) || + sLineName.equals(rtl::OUString::createFromAscii("Square")) || + sLineName.equals(rtl::OUString::createFromAscii("msArrowDiamondEnd"))) + { + // msoArrowheadDiamond + nLineType = office::MsoArrowheadStyle::msoArrowheadDiamond; + } + else if (sLineName.equals(rtl::OUString::createFromAscii("Circle")) || + sLineName.equals(rtl::OUString::createFromAscii("msArrowOvalEnd")) || + sLineName.equals(rtl::OUString::createFromAscii("Dimension Lines")) ) + { + // msoArrowheadOval + nLineType = office::MsoArrowheadStyle::msoArrowheadOval; + } + else if (sLineName.equals(rtl::OUString::createFromAscii("Arrow concave")) || + sLineName.equals(rtl::OUString::createFromAscii("msArrowStealthEnd"))) + { + // msoArrowheadStealth + nLineType = office::MsoArrowheadStyle::msoArrowheadStealth; + } + else if (sLineName.equals(rtl::OUString::createFromAscii("Rounded short Arrow")) || + sLineName.equals(rtl::OUString::createFromAscii("Rounded large Arrow")) || + sLineName.equals(rtl::OUString::createFromAscii("Symmetric Arrow")) || + sLineName.equals(rtl::OUString::createFromAscii("msArrowOpenEnd")) || + sLineName.equals(rtl::OUString::createFromAscii("Line Arrow"))) + { + // msoArrowheadOpen + nLineType = office::MsoArrowheadStyle::msoArrowheadOpen; + } + else + { + // msoArrowheadNone + nLineType = office::MsoArrowheadStyle::msoArrowheadNone; + } + return nLineType; +} + +rtl::OUString +ScVbaLineFormat::convertArrowheadStyleToLineStartEndName( sal_Int32 nArrowheadStyle ) throw (uno::RuntimeException) +{ + switch( nArrowheadStyle ) + { + case office::MsoArrowheadStyle::msoArrowheadNone: + return rtl::OUString(rtl::OUString::createFromAscii( "" ) ); + case office::MsoArrowheadStyle::msoArrowheadStealth: + return rtl::OUString::createFromAscii( "Arrow concave" ); + case office::MsoArrowheadStyle::msoArrowheadOpen: + return rtl::OUString::createFromAscii("Line Arrow" ); + case office::MsoArrowheadStyle::msoArrowheadOval: + return rtl::OUString::createFromAscii("Circle" ); + case office::MsoArrowheadStyle::msoArrowheadDiamond: + return rtl::OUString::createFromAscii( "Square 45" ); + case office::MsoArrowheadStyle::msoArrowheadTriangle: + return rtl::OUString::createFromAscii( "Arrow" ); + default: + throw uno::RuntimeException( rtl::OUString::createFromAscii("Invalid Arrow Style!"), uno::Reference< uno::XInterface >() ); + } +} + +// Attributes +sal_Int32 SAL_CALL +ScVbaLineFormat::getBeginArrowheadStyle() throw (uno::RuntimeException) +{ + sal_Int32 nLineType = office::MsoArrowheadStyle::msoArrowheadNone; + rtl::OUString sLineName; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "LineStartName" ) ) >>= sLineName; + if( ( sLineName.getLength() > 7 ) && ( sLineName.indexOf( rtl::OUString::createFromAscii( "msArray" ) ) ) != -1 ) + { + sal_Int32 nIndex = sLineName.indexOf( rtl::OUString::createFromAscii(" ") ); + rtl::OUString sName = sLineName.copy( 0, nIndex ); + //sal_Int32 nSize = sLineName.copy( nIndex + 1 ).toInt32(); + nLineType = convertLineStartEndNameToArrowheadStyle( sName ); + } + else + { + nLineType = convertLineStartEndNameToArrowheadStyle( sLineName ); + } + return nLineType; +} + +void SAL_CALL +ScVbaLineFormat::setBeginArrowheadStyle( sal_Int32 _beginarrowheadstyle ) throw (uno::RuntimeException) +{ + rtl::OUString sArrayName = convertArrowheadStyleToLineStartEndName( _beginarrowheadstyle ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineStartName" ), uno::makeAny( sArrayName ) ); +} + +sal_Int32 SAL_CALL +ScVbaLineFormat::getBeginArrowheadLength() throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +void SAL_CALL +ScVbaLineFormat::setBeginArrowheadLength( sal_Int32 /*_beginarrowheadlength*/ ) throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +sal_Int32 SAL_CALL +ScVbaLineFormat::getBeginArrowheadWidth() throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +void SAL_CALL +ScVbaLineFormat::setBeginArrowheadWidth( sal_Int32 /*_beginarrowheadwidth*/ ) throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +sal_Int32 SAL_CALL +ScVbaLineFormat::getEndArrowheadStylel() throw (uno::RuntimeException) +{ + return 0; +} + +void SAL_CALL +ScVbaLineFormat::setEndArrowheadStylel( sal_Int32 /*_endarrowheadstylel*/ ) throw (uno::RuntimeException) +{ +} + +sal_Int32 SAL_CALL +ScVbaLineFormat::getEndArrowheadLength() throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +void SAL_CALL +ScVbaLineFormat::setEndArrowheadLength( sal_Int32 /*_endarrowheadlength*/ ) throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +sal_Int32 SAL_CALL +ScVbaLineFormat::getEndArrowheadWidth() throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +void SAL_CALL +ScVbaLineFormat::setEndArrowheadWidth( sal_Int32 /*_endarrowheadwidth*/ ) throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString::createFromAscii("Property 'EndArrowheadWidth' is not supported."), uno::Reference< uno::XInterface >() ); +} + +double SAL_CALL +ScVbaLineFormat::getWeight() throw (uno::RuntimeException) +{ + sal_Int32 nLineWidth=0; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "LineWidth") ) >>= nLineWidth; + double dLineWidth = Millimeter::getInPoints( nLineWidth ); + return dLineWidth; +} + +void SAL_CALL +ScVbaLineFormat::setWeight( double _weight ) throw (uno::RuntimeException) +{ + if( _weight < 0 ) + throw uno::RuntimeException( rtl::OUString::createFromAscii("Parameter: Must be positv."), uno::Reference< uno::XInterface >() ); + if( _weight == 0 ) + _weight = 0.5; + m_nLineWeight = _weight; + Millimeter aMillimeter; + aMillimeter.setInPoints( _weight ); + + sal_Int32 nLineWidth = static_cast<sal_Int32>( aMillimeter.getInHundredthsOfOneMillimeter() ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineWidth" ), uno::makeAny( nLineWidth ) ); + setDashStyle( m_nLineDashStyle ); +} + +sal_Bool SAL_CALL +ScVbaLineFormat::getVisible() throw (uno::RuntimeException) +{ + drawing::LineStyle aLineStyle; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ) ) >>= aLineStyle; + if( aLineStyle == drawing::LineStyle_NONE ) + { + return sal_False; + } + return sal_True; +} + +void SAL_CALL +ScVbaLineFormat::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) +{ + drawing::LineStyle aLineStyle; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ) ) >>= aLineStyle; + if( !_visible ) + { + aLineStyle = drawing::LineStyle_NONE; + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ), uno::makeAny( aLineStyle ) ); + } + else + { + if( aLineStyle == drawing::LineStyle_NONE ) + { + setDashStyle( m_nLineDashStyle ); + } + } +} + +double SAL_CALL +ScVbaLineFormat::getTransparency() throw (uno::RuntimeException) +{ + sal_Int16 nTransparency = 0; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "LineTransparence" ) ) >>= nTransparency; + double fTransparency = static_cast<double>( nTransparency ); + return fTransparency / 100; +} + +void SAL_CALL +ScVbaLineFormat::setTransparency( double _transparency ) throw (uno::RuntimeException) +{ + sal_Int16 nTransparency = static_cast<sal_Int16>( _transparency * 100 ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineTransparence" ), uno::makeAny( nTransparency ) ); +} + +sal_Int16 SAL_CALL +ScVbaLineFormat::getStyle() throw (uno::RuntimeException) +{ + //OpenOffice.org only supports one LineStyle (other than the DashStyles) + //Therefore we can only return the SingleLine + return 1; +} + +void SAL_CALL +ScVbaLineFormat::setStyle( sal_Int16 /*_style */) throw (uno::RuntimeException) +{ + //OpenOffice.org only supports one LineStyle (other than the DashStyles) + //Therefore we do not set the LineStyle, because it maybe is already set + //to Dashed or Single Line. Setting the 'Visible' or 'DashStyle' properties + //will be done with the according methods. +} + +sal_Int32 SAL_CALL +ScVbaLineFormat::getDashStyle() throw (uno::RuntimeException) +{ + drawing::LineStyle eLineStyle; + //LineStyle integer in Xray + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ) ) >>= eLineStyle; + if( eLineStyle == drawing::LineStyle_SOLID ) + m_nLineDashStyle = office::MsoLineDashStyle::msoLineSolid; + else + { + drawing::LineDash aLineDash; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "LineDash" ) ) >>= aLineDash; + if( aLineDash.Dots == 0 ) + { + //LineDash + //LineLongDash + m_nLineDashStyle = office::MsoLineDashStyle::msoLineDash; + if( aLineDash.Distance > 0 && ( aLineDash.DashLen / aLineDash.Distance > 1 ) ) + { + m_nLineDashStyle = office::MsoLineDashStyle::msoLineLongDash; + } + } + else if( aLineDash.Dots == 1 ) + { + // LineDashDot + // LineLongDashDot + // LineSquareDot + // LineRoundDot ! not supported + m_nLineDashStyle = office::MsoLineDashStyle::msoLineDashDot; + if( aLineDash.Dashes == 0 ) + { + m_nLineDashStyle = office::MsoLineDashStyle::msoLineSquareDot; + } + else + { + if( aLineDash.Distance > 0 && ( aLineDash.DashLen / aLineDash.Distance > 1 ) ) + { + m_nLineDashStyle = office::MsoLineDashStyle::msoLineLongDashDot; + } + } + } + else if( aLineDash.Dots == 2 ) + { + // LineDashDotDot + m_nLineDashStyle = office::MsoLineDashStyle::msoLineDashDotDot; + } + } + + return m_nLineDashStyle; +} + +void SAL_CALL +ScVbaLineFormat::setDashStyle( sal_Int32 _dashstyle ) throw (uno::RuntimeException) +{ + m_nLineDashStyle = _dashstyle; + if( _dashstyle == office::MsoLineDashStyle::msoLineSolid ) + { + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ), uno::makeAny( drawing::LineStyle_SOLID )); + } + else + { + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ), uno::makeAny( drawing::LineStyle_DASH ) ); + drawing::LineDash pLineDash; + Millimeter aMillimeter( m_nLineWeight ); + sal_Int32 nPixel = static_cast< sal_Int32 >( aMillimeter.getInHundredthsOfOneMillimeter() ); + switch( _dashstyle ) + { + case office::MsoLineDashStyle::msoLineDashDot: + pLineDash.Dots = 1; + pLineDash.DotLen = nPixel; + pLineDash.Dashes = 1; + pLineDash.DashLen = 5 * nPixel; + pLineDash.Distance = 4 * nPixel; + break; + case office::MsoLineDashStyle::msoLineLongDashDot: + pLineDash.Dots = 1; + pLineDash.DotLen = nPixel; + pLineDash.Dashes = 1; + pLineDash.DashLen = 10 * nPixel; + pLineDash.Distance = 4 * nPixel; + break; + case office::MsoLineDashStyle::msoLineDash: + pLineDash.Dots = 0; + pLineDash.DotLen = 0; + pLineDash.Dashes = 1; + pLineDash.DashLen = 6 * nPixel; + pLineDash.Distance = 4 * nPixel; + break; + case office::MsoLineDashStyle::msoLineDashDotDot: + pLineDash.Dots = 2; + pLineDash.DotLen = nPixel; + pLineDash.Dashes = 1; + pLineDash.DashLen = 10 * nPixel; + pLineDash.Distance = 3 * nPixel; + break; + case office::MsoLineDashStyle::msoLineLongDash: + pLineDash.Dots = 0; + pLineDash.DotLen = 0; + pLineDash.Dashes = 1; + pLineDash.DashLen = 10 * nPixel; + pLineDash.Distance = 4 * nPixel; + break; + case office::MsoLineDashStyle::msoLineSquareDot: + pLineDash.Dots = 1; + pLineDash.DotLen = nPixel; + pLineDash.Dashes = 0; + pLineDash.DashLen = 0; + pLineDash.Distance = nPixel; + break; + case office::MsoLineDashStyle::msoLineRoundDot: + pLineDash.Dots = 1; + pLineDash.DotLen = nPixel; + pLineDash.Dashes = 0; + pLineDash.DashLen = 0; + pLineDash.Distance = nPixel; + break; + default: + throw uno::RuntimeException( rtl::OUString::createFromAscii("this MsoLineDashStyle is not supported."), uno::Reference< uno::XInterface >() ); + } + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "LineDash" ), uno::makeAny( pLineDash ) ); + } +} + +// Methods +uno::Reference< msforms::XColorFormat > SAL_CALL +ScVbaLineFormat::BackColor() throw (uno::RuntimeException) +{ + return uno::Reference< msforms::XColorFormat >( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ::ColorFormatType::LINEFORMAT_BACKCOLOR ) ); +} + +uno::Reference< msforms::XColorFormat > SAL_CALL +ScVbaLineFormat::ForeColor() throw (uno::RuntimeException) +{ + return uno::Reference< msforms::XColorFormat >( new ScVbaColorFormat( getParent(), mxContext, this, m_xShape, ::ColorFormatType::LINEFORMAT_FORECOLOR ) ); +} + + +rtl::OUString& +ScVbaLineFormat::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaLineFormat") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaLineFormat::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.LineFormat" ) ); + } + return aServiceNames; +} + + diff --git a/vbahelper/source/vbahelper/vbalineformat.hxx b/vbahelper/source/vbahelper/vbalineformat.hxx new file mode 100644 index 000000000000..8c95fc996e0c --- /dev/null +++ b/vbahelper/source/vbahelper/vbalineformat.hxx @@ -0,0 +1,82 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_XLINEFORMAT_HXX +#define SC_VBA_XLINEFORMAT_HXX + +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/msforms/XLineFormat.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::msforms::XLineFormat > ScVbaLineFormat_BASE; + +class ScVbaLineFormat : public ScVbaLineFormat_BASE +{ +private: + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; + sal_Int32 m_nLineDashStyle; + double m_nLineWeight; +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); + sal_Int32 convertLineStartEndNameToArrowheadStyle( rtl::OUString sLineName ); + rtl::OUString convertArrowheadStyleToLineStartEndName( sal_Int32 nArrowheadStyle ) throw (css::uno::RuntimeException); + sal_Int32 calculateArrowheadSize(); +public: + ScVbaLineFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::drawing::XShape > xShape ); + + // Attributes + virtual sal_Int32 SAL_CALL getBeginArrowheadStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBeginArrowheadStyle( sal_Int32 _beginarrowheadstyle ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBeginArrowheadLength() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBeginArrowheadLength( sal_Int32 _beginarrowheadlength ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getBeginArrowheadWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBeginArrowheadWidth( sal_Int32 _beginarrowheadwidth ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getEndArrowheadStylel() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEndArrowheadStylel( sal_Int32 _endarrowheadstylel ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getEndArrowheadLength() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEndArrowheadLength( sal_Int32 _endarrowheadlength ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getEndArrowheadWidth() throw (css::uno::RuntimeException); + virtual void SAL_CALL setEndArrowheadWidth( sal_Int32 _endarrowheadwidth ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getWeight() throw (css::uno::RuntimeException); + virtual void SAL_CALL setWeight( double _weight ) throw (css::uno::RuntimeException); + virtual sal_Bool SAL_CALL getVisible() throw (css::uno::RuntimeException); + virtual void SAL_CALL setVisible( sal_Bool _visible ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getTransparency() throw (css::uno::RuntimeException); + virtual void SAL_CALL setTransparency( double _transparency ) throw (css::uno::RuntimeException); + virtual sal_Int16 SAL_CALL getStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setStyle( sal_Int16 _style ) throw (css::uno::RuntimeException); + virtual sal_Int32 SAL_CALL getDashStyle() throw (css::uno::RuntimeException); + virtual void SAL_CALL setDashStyle( sal_Int32 _dashstyle ) throw (css::uno::RuntimeException); + + // Methods + virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL BackColor() throw (css::uno::RuntimeException); + virtual css::uno::Reference< ov::msforms::XColorFormat > SAL_CALL ForeColor() throw (css::uno::RuntimeException); +}; + +#endif//SC_VBA_XLINEFORMAT_HXX diff --git a/vbahelper/source/vbahelper/vbapagesetupbase.cxx b/vbahelper/source/vbahelper/vbapagesetupbase.cxx new file mode 100644 index 000000000000..0d023e502b7c --- /dev/null +++ b/vbahelper/source/vbahelper/vbapagesetupbase.cxx @@ -0,0 +1,322 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/vbapagesetupbase.hxx> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +VbaPageSetupBase::VbaPageSetupBase(const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext ) throw (uno::RuntimeException): VbaPageSetupBase_BASE( xParent, xContext ) +{ +} + +double SAL_CALL VbaPageSetupBase::getTopMargin() throw (css::uno::RuntimeException) +{ + sal_Bool headerOn = sal_False; + sal_Int32 topMargin = 0; + sal_Int32 headerHeight = 0; + + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))); + aValue >>= headerOn; + + aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin"))); + aValue >>= topMargin; + + if( headerOn ) + { + aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight"))); + aValue >>= headerHeight; + topMargin = topMargin + headerHeight; + } + } + catch( uno::Exception& ) + { + } + + return Millimeter::getInPoints( topMargin ); +} + +void SAL_CALL VbaPageSetupBase::setTopMargin( double margin ) throw (css::uno::RuntimeException) +{ + sal_Int32 topMargin = Millimeter::getInHundredthsOfOneMillimeter( margin ); + sal_Bool headerOn = sal_False; + sal_Int32 headerHeight = 0; + + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))); + aValue >>= headerOn; + + if( headerOn ) + { + aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight"))); + aValue >>= headerHeight; + topMargin -= headerHeight; + } + + aValue <<= topMargin; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")), aValue ); + } + catch( uno::Exception& ) + { + } +} + +double SAL_CALL VbaPageSetupBase::getBottomMargin() throw (css::uno::RuntimeException) +{ + sal_Bool footerOn = sal_False; + sal_Int32 bottomMargin = 0; + sal_Int32 footerHeight = 0; + + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn"))); + aValue >>= footerOn; + + aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin"))); + aValue >>= bottomMargin; + + if( footerOn ) + { + aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight"))); + aValue >>= footerHeight; + bottomMargin += footerHeight; + } + } + catch( uno::Exception& ) + { + } + + return Millimeter::getInPoints( bottomMargin ); +} + +void SAL_CALL VbaPageSetupBase::setBottomMargin( double margin ) throw (css::uno::RuntimeException) +{ + sal_Int32 bottomMargin = Millimeter::getInHundredthsOfOneMillimeter( margin ); + sal_Bool footerOn = sal_False; + sal_Int32 footerHeight = 0; + + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn"))); + aValue >>= footerOn; + + if( footerOn ) + { + aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight"))); + aValue >>= footerHeight; + bottomMargin -= footerHeight; + } + + aValue <<= bottomMargin; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")), aValue ); + } + catch( uno::Exception& ) + { + } +} + +double SAL_CALL VbaPageSetupBase::getRightMargin() throw (css::uno::RuntimeException) +{ + sal_Int32 rightMargin = 0; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin"))); + aValue >>= rightMargin; + } + catch( uno::Exception& ) + { + } + + return Millimeter::getInPoints( rightMargin );; +} + +void SAL_CALL VbaPageSetupBase::setRightMargin( double margin ) throw (css::uno::RuntimeException) +{ + sal_Int32 rightMargin = Millimeter::getInHundredthsOfOneMillimeter( margin ); + try + { + uno::Any aValue; + aValue <<= rightMargin; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin")), aValue ); + } + catch( uno::Exception& ) + { + } + +} + +double SAL_CALL VbaPageSetupBase::getLeftMargin() throw (css::uno::RuntimeException) +{ + sal_Int32 leftMargin = 0; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin"))); + aValue >>= leftMargin; + } + catch( uno::Exception& ) + { + } + + return Millimeter::getInPoints( leftMargin );; +} + +void SAL_CALL VbaPageSetupBase::setLeftMargin( double margin ) throw (css::uno::RuntimeException) +{ + sal_Int32 leftMargin = Millimeter::getInHundredthsOfOneMillimeter( margin ); + try + { + uno::Any aValue; + aValue <<= leftMargin; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin")), aValue ); + } + catch( uno::Exception& ) + { + } +} + +double SAL_CALL VbaPageSetupBase::getHeaderMargin() throw (css::uno::RuntimeException) +{ + sal_Int32 headerMargin = 0; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin"))); + aValue >>= headerMargin; + } + catch( uno::Exception& ) + { + } + + return Millimeter::getInPoints( headerMargin );; +} + +void SAL_CALL VbaPageSetupBase::setHeaderMargin( double margin ) throw (css::uno::RuntimeException) +{ + sal_Int32 headerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin ); + try + { + uno::Any aValue; + aValue <<= headerMargin; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")), aValue ); + } + catch( uno::Exception& ) + { + } +} + +double SAL_CALL VbaPageSetupBase::getFooterMargin() throw (css::uno::RuntimeException) +{ + sal_Int32 footerMargin = 0; + try + { + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin"))); + aValue >>= footerMargin; + } + catch( uno::Exception& ) + { + } + + return Millimeter::getInPoints( footerMargin );; +} + +void SAL_CALL VbaPageSetupBase::setFooterMargin( double margin ) throw (css::uno::RuntimeException) +{ + sal_Int32 footerMargin = Millimeter::getInHundredthsOfOneMillimeter( margin ); + try + { + uno::Any aValue; + aValue <<= footerMargin; + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")), aValue ); + } + catch( uno::Exception& ) + { + } +} + +sal_Int32 SAL_CALL VbaPageSetupBase::getOrientation() throw (css::uno::RuntimeException) +{ + sal_Int32 orientation = mnOrientPortrait; + try + { + sal_Bool isLandscape = sal_False; + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsLandscape"))); + aValue >>= isLandscape; + + if( isLandscape ) + { + orientation = mnOrientLandscape; + } + } + catch( uno::Exception& ) + { + } + return orientation; +} + +void SAL_CALL VbaPageSetupBase::setOrientation( sal_Int32 orientation ) throw (css::uno::RuntimeException) +{ + if( ( orientation != mnOrientPortrait ) && + ( orientation != mnOrientLandscape ) ) + { + DebugHelper::exception(SbERR_BAD_PARAMETER, rtl::OUString() ); + } + + try + { + sal_Bool isLandscape = sal_False; + uno::Any aValue = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsLandscape"))); + aValue >>= isLandscape; + + sal_Bool switchOrientation = sal_False; + if(( isLandscape && orientation != mnOrientLandscape ) || + ( !isLandscape && orientation != mnOrientPortrait )) + { + switchOrientation = sal_True; + } + + if( switchOrientation ) + { + aValue <<= !isLandscape; + uno::Any aHeight = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height"))); + uno::Any aWidth = mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width"))); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("IsLandscape")), aValue ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Width")), aHeight ); + mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Height")), aWidth ); + } + + if( isLandscape ) + { + orientation = mnOrientLandscape; + } + } + catch( uno::Exception& ) + { + } +} + diff --git a/vbahelper/source/vbahelper/vbapictureformat.cxx b/vbahelper/source/vbahelper/vbapictureformat.cxx new file mode 100644 index 000000000000..7ebbb62d1125 --- /dev/null +++ b/vbahelper/source/vbahelper/vbapictureformat.cxx @@ -0,0 +1,144 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbapictureformat.hxx" + +using namespace ooo::vba; +using namespace com::sun::star; + +ScVbaPictureFormat::ScVbaPictureFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, + const css::uno::Reference< css::uno::XComponentContext >& xContext, + uno::Reference< drawing::XShape > xShape ) + throw( lang::IllegalArgumentException ) : ScVbaPictureFormat_BASE( xParent, xContext ), m_xShape( xShape ) +{ + m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW ); +} + +void +ScVbaPictureFormat::checkParameterRangeInDouble( double nRange, double nMin, double nMax ) throw (css::uno::RuntimeException) +{ + if( nRange < nMin ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii("Parameter out of range, value is too small.") , uno::Reference< uno::XInterface >() ); + } + if( nRange > nMax ) + { + throw uno::RuntimeException( rtl::OUString::createFromAscii("Parameter out of range, value is too high.") , uno::Reference< uno::XInterface >() ); + } +} + +// Attributes +double SAL_CALL +ScVbaPictureFormat::getBrightness() throw (uno::RuntimeException) +{ + sal_Int16 nLuminance = 0; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("AdjustLuminance") ) >>= nLuminance; + double fBrightness = static_cast< double >( nLuminance ); + fBrightness = ( fBrightness +100 ) / 200; + return fBrightness; +} + +void SAL_CALL +ScVbaPictureFormat::setBrightness( double _brightness ) throw (uno::RuntimeException) +{ + checkParameterRangeInDouble( _brightness, 0.0, 1.0 ); + double fLuminance = _brightness * 200 - 100; + sal_Int16 nLuminance = static_cast< sal_Int16 >( fLuminance ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("AdjustLuminance"), uno::makeAny( nLuminance ) ); +} + +double SAL_CALL +ScVbaPictureFormat::getContrast() throw (uno::RuntimeException) +{ + sal_Int16 nContrast = 0; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("AdjustContrast") ) >>= nContrast; + double fContrast = static_cast< double >( nContrast ); + fContrast = ( fContrast + 100 ) / 200; + return fContrast; +} + +void SAL_CALL +ScVbaPictureFormat::setContrast( double _contrast ) throw (uno::RuntimeException) +{ + checkParameterRangeInDouble( _contrast, 0.0, 1.0 ); + double fContrast = _contrast * 200 - 100; + sal_Int16 nContrast = static_cast< sal_Int16 >( fContrast ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii("AdjustContrast"), uno::makeAny( nContrast ) ); +} + + +// Methods +void SAL_CALL +ScVbaPictureFormat::IncrementBrightness( double increment ) throw (uno::RuntimeException) +{ + double fBrightness = getBrightness(); + fBrightness += increment; + if( fBrightness < 0 ) + { + fBrightness = 0.0; + } + if( fBrightness > 1 ) + { + fBrightness = 1; + } + setBrightness( fBrightness ); +} + +void SAL_CALL +ScVbaPictureFormat::IncrementContrast( double increment ) throw (uno::RuntimeException) +{ + double nContrast = getContrast(); + nContrast += increment; + if( increment < 0 ) + { + increment = 0.0; + } + if( increment > 1 ) + { + increment = 1.0; + } + setContrast( nContrast ); +} + + +rtl::OUString& +ScVbaPictureFormat::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaPictureFormat") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaPictureFormat::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.PictureFormat" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/vbahelper/vbapictureformat.hxx b/vbahelper/source/vbahelper/vbapictureformat.hxx new file mode 100644 index 000000000000..e7b6ed9c1a30 --- /dev/null +++ b/vbahelper/source/vbahelper/vbapictureformat.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef SC_VBA_PICTUREFORMAT_HXX +#define SC_VBA_PICTUREFORMAT_HXX + +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <ooo/vba/msforms/XPictureFormat.hpp> +#include <vbahelper/vbahelperinterface.hxx> + +typedef InheritedHelperInterfaceImpl1< ov::msforms::XPictureFormat > ScVbaPictureFormat_BASE; + +class ScVbaPictureFormat : public ScVbaPictureFormat_BASE +{ +private: + css::uno::Reference< css::drawing::XShape > m_xShape; + css::uno::Reference< css::beans::XPropertySet > m_xPropertySet; +protected: + virtual rtl::OUString& getServiceImplName(); + virtual css::uno::Sequence<rtl::OUString> getServiceNames(); +private: + void checkParameterRangeInDouble( double nRange, double nMin, double nMax ) throw (css::uno::RuntimeException); +public: + ScVbaPictureFormat( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, css::uno::Reference< css::drawing::XShape > xShape ) throw( css::lang::IllegalArgumentException ); + + // Attributes + virtual double SAL_CALL getBrightness() throw (css::uno::RuntimeException); + virtual void SAL_CALL setBrightness( double _brightness ) throw (css::uno::RuntimeException); + virtual double SAL_CALL getContrast() throw (css::uno::RuntimeException); + virtual void SAL_CALL setContrast( double _contrast ) throw (css::uno::RuntimeException); + + // Methods + virtual void SAL_CALL IncrementBrightness( double increment ) throw (css::uno::RuntimeException); + virtual void SAL_CALL IncrementContrast( double increment ) throw (css::uno::RuntimeException); +}; + +#endif//SC_VBA_PICTUREFORMAT_HXX diff --git a/vbahelper/source/vbahelper/vbapropvalue.cxx b/vbahelper/source/vbahelper/vbapropvalue.cxx new file mode 100644 index 000000000000..26437a359e8d --- /dev/null +++ b/vbahelper/source/vbahelper/vbapropvalue.cxx @@ -0,0 +1,45 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include "vbahelper/vbapropvalue.hxx" + +using namespace com::sun::star; + +ScVbaPropValue::ScVbaPropValue( PropListener* pListener ) : m_pListener( pListener ) +{ +} + +css::uno::Any SAL_CALL +ScVbaPropValue::getValue() throw (css::uno::RuntimeException) +{ + return m_pListener->getValueEvent(); +} + +void SAL_CALL +ScVbaPropValue::setValue( const css::uno::Any& _value ) throw (css::uno::RuntimeException) +{ + m_pListener->setValueEvent( _value ); +} diff --git a/vbahelper/source/vbahelper/vbashape.cxx b/vbahelper/source/vbahelper/vbashape.cxx new file mode 100644 index 000000000000..485ebee3ea8d --- /dev/null +++ b/vbahelper/source/vbahelper/vbashape.cxx @@ -0,0 +1,673 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include<ooo/vba/office/MsoZOrderCmd.hpp> +#include<ooo/vba/office/MsoScaleFrom.hpp> +#include<com/sun/star/container/XNamed.hpp> +#include<com/sun/star/drawing/ConnectorType.hpp> +#include <com/sun/star/lang/XEventListener.hpp> +#include<com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include<com/sun/star/drawing/XDrawPages.hpp> +#include<com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <ooo/vba/word/WdRelativeHorizontalPosition.hpp> +#include <ooo/vba/word/WdRelativeVerticalPosition.hpp> + +#include <comphelper/processfactory.hxx> +#include <vos/mutex.hxx> +#include <vcl/svapp.hxx> +#include <svx/unopage.hxx> +#include <svx/unoshape.hxx> + +#include <vbahelper/vbashape.hxx> +#include <vbahelper/vbatextframe.hxx> +#include "vbalineformat.hxx" +#include "vbafillformat.hxx" +#include "vbapictureformat.hxx" +#include <vbahelper/vbashaperange.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; +using namespace ::vos; + +ScVbaShape::ScVbaShape( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< drawing::XShapes >& xShapes, const uno::Reference< frame::XModel >& xModel, sal_Int32 nType ) throw( lang::IllegalArgumentException ) : ScVbaShape_BASE( xParent, xContext ), m_xShape( xShape ), m_xShapes( xShapes ), m_nType( nType ), m_xModel( xModel ) +{ + m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW ); + m_pShapeHelper.reset( new ShapeHelper( m_xShape ) ); + addListeners(); +} + +ScVbaShape::ScVbaShape( const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< drawing::XShape >& xShape, const uno::Reference< frame::XModel >& xModel ) throw( lang::IllegalArgumentException ) : ScVbaShape_BASE( uno::Reference< XHelperInterface >(), xContext ), m_xShape( xShape ), m_xModel( xModel ) +{ + // add listener + addListeners(); +} + +ScVbaShape::~ScVbaShape() +{ + // dtor must never ever throw + /*try + { + removeShapeListener(); + removeShapesListener(); + } + catch( uno::Exception& ) + { + }*/ +} + +void SAL_CALL +ScVbaShape::disposing( const lang::EventObject& rEventObject ) throw( uno::RuntimeException ) +{ + try + { + uno::Reference< drawing::XShapes > xShapes( rEventObject.Source, uno::UNO_QUERY ); + uno::Reference< drawing::XShape > xShape( rEventObject.Source, uno::UNO_QUERY ); + if ( xShapes.is() ) + removeShapesListener(); + if ( xShape.is() ) + removeShapeListener(); + } + catch( uno::Exception& ) + { + } +} + + +void ScVbaShape::addListeners() +{ + uno::Reference< lang::XComponent > xComponent( m_xShape, uno::UNO_QUERY ); + if ( xComponent.is() ) + xComponent->addEventListener( this ); + + xComponent.set( m_xShapes, uno::UNO_QUERY ); + if ( xComponent.is() ) + xComponent->addEventListener( this ); +} + +void +ScVbaShape::removeShapeListener() throw( uno::RuntimeException ) +{ + if( m_xShape.is() ) + { + uno::Reference< lang::XComponent > xComponent( m_xShape, uno::UNO_QUERY_THROW ); + xComponent->removeEventListener( this ); + } + m_xShape = NULL; + m_xPropertySet = NULL; +} + +void +ScVbaShape::removeShapesListener() throw( uno::RuntimeException ) +{ + if( m_xShapes.is() ) + { + uno::Reference< lang::XComponent > xComponent( m_xShapes, uno::UNO_QUERY_THROW ); + xComponent->removeEventListener( this ); + } + m_xShapes = NULL; +} + +sal_Int32 +ScVbaShape::getType( const css::uno::Reference< drawing::XShape > xShape ) throw (uno::RuntimeException) +{ + rtl::OUString sShapeType; + uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor( xShape, uno::UNO_QUERY_THROW ); + sShapeType = xShapeDescriptor->getShapeType(); + OSL_TRACE("ScVbaShape::getType: %s", rtl::OUStringToOString( sShapeType, RTL_TEXTENCODING_UTF8 ).getStr() ); + // office::MsoShapeType::msoDiagram to "com.sun.star.drawing.GroupShape" + if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.GroupShape" ) ) ) + return office::MsoShapeType::msoGroup; + else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.GraphicObjectShape" ) ) ) + return office::MsoShapeType::msoPicture; + else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.ControlShape" ) ) || + sShapeType.equals( rtl::OUString::createFromAscii( "FrameShape" ) ) ) + return office::MsoShapeType::msoOLEControlObject; + // OOo don't support office::MsoShapeType::msoComment as a Shape. + else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.OLE2Shape" ) ) ) + return office::MsoShapeType::msoChart; + // Art characters office::MsoShapeType::msoTextEffect, in OOo corresponding to "com.sun.star.drawing.CustomShape" + else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.ConnectorShape" ) ) ) + { + enum drawing::ConnectorType connectorType; + uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW ); + xPropertySet->getPropertyValue( rtl::OUString::createFromAscii("EdgeKind")) >>= connectorType; + if( connectorType == drawing::ConnectorType_CURVE ) + return office::MsoShapeType::msoFreeform; + else if( connectorType == drawing::ConnectorType_LINE ) + return office::MsoShapeType::msoLine; + else + return office::MsoShapeType::msoAutoShape; + } + else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.LineShape" ) ) ) + return office::MsoShapeType::msoLine; + else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.CustomShape" ) ) || + sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.RectangleShape") ) ) + return office::MsoShapeType::msoAutoShape; + else if( sShapeType.equals( rtl::OUString::createFromAscii( "com.sun.star.drawing.TextShape" ) ) ) + return office::MsoShapeType::msoTextBox; + else + throw uno::RuntimeException( rtl::OUString::createFromAscii( "the shape type do not be supported: " ) + sShapeType, uno::Reference< uno::XInterface >() ); +} + +// Attributes +rtl::OUString SAL_CALL +ScVbaShape::getName() throw (uno::RuntimeException) +{ + rtl::OUString sName; + uno::Reference< container::XNamed > xNamed( m_xShape, uno::UNO_QUERY_THROW ); + sName = xNamed->getName(); + return sName; +} + +void SAL_CALL +ScVbaShape::setName( const rtl::OUString& _name ) throw (uno::RuntimeException) +{ + uno::Reference< container::XNamed > xNamed( m_xShape, uno::UNO_QUERY_THROW ); + xNamed->setName( _name ); +} + +double SAL_CALL +ScVbaShape::getHeight() throw (uno::RuntimeException) +{ + return m_pShapeHelper->getHeight(); +} + +void SAL_CALL +ScVbaShape::setHeight( double _height ) throw (uno::RuntimeException) +{ + m_pShapeHelper->setHeight( _height ); +} + +double SAL_CALL +ScVbaShape::getWidth() throw (uno::RuntimeException) +{ + return m_pShapeHelper->getWidth(); +} + +void SAL_CALL +ScVbaShape::setWidth( double _width ) throw (uno::RuntimeException) +{ + m_pShapeHelper->setWidth( _width ); +} + +double SAL_CALL +ScVbaShape::getLeft() throw (uno::RuntimeException) +{ + return m_pShapeHelper->getLeft(); +} + +void SAL_CALL +ScVbaShape::setLeft( double _left ) throw (uno::RuntimeException) +{ + m_pShapeHelper->setLeft( _left ); +} + +double SAL_CALL +ScVbaShape::getTop() throw (uno::RuntimeException) +{ + return m_pShapeHelper->getTop(); +} + +void SAL_CALL +ScVbaShape::setTop( double _top ) throw (uno::RuntimeException) +{ + return m_pShapeHelper->setTop( _top ); +} + +sal_Bool SAL_CALL +ScVbaShape::getVisible() throw (uno::RuntimeException) +{ + //UNO Shapes are always visible + return sal_True; +} + +void SAL_CALL +ScVbaShape::setVisible( sal_Bool /*_visible*/ ) throw (uno::RuntimeException) +{ + //UNO Shapes are always visible +} + +sal_Int32 SAL_CALL +ScVbaShape::getZOrderPosition() throw (uno::RuntimeException) +{ + sal_Int32 nZOrderPosition = 0; + uno::Any aZOrderPosition = m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ) ); + aZOrderPosition >>= nZOrderPosition; + return nZOrderPosition + 1; +} + +sal_Int32 SAL_CALL +ScVbaShape::getType() throw (uno::RuntimeException) +{ + return m_nType; +} + +double SAL_CALL +ScVbaShape::getRotation() throw (uno::RuntimeException) +{ + double dRotation = 0; + sal_Int32 nRotation = 0; + m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "RotateAngle" ) ) >>= nRotation; + dRotation = static_cast< double >( nRotation /100 ); + return dRotation; +} + +void SAL_CALL +ScVbaShape::setRotation( double _rotation ) throw (uno::RuntimeException) +{ + sal_Int32 nRotation = static_cast < sal_Int32 > ( _rotation * 100 ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "RotateAngle" ), uno::makeAny( nRotation ) ); +} + +uno::Reference< msforms::XLineFormat > SAL_CALL +ScVbaShape::getLine() throw (uno::RuntimeException) +{ + // TODO should ongly return line + return uno::Reference< msforms::XLineFormat >( new ScVbaLineFormat( this, mxContext, m_xShape ) ); +} + +uno::Reference< msforms::XFillFormat > SAL_CALL +ScVbaShape::getFill() throw (uno::RuntimeException) +{ + return uno::Reference< msforms::XFillFormat >( new ScVbaFillFormat( this, mxContext, m_xShape ) ); +} + +uno::Reference< msforms::XPictureFormat > SAL_CALL +ScVbaShape::getPictureFormat() throw (uno::RuntimeException) +{ + return uno::Reference< msforms::XPictureFormat >( new ScVbaPictureFormat( this, mxContext, m_xShape ) ); +} + +// Methods +uno::Any SAL_CALL +ScVbaShape::TextFrame() throw (uno::RuntimeException) +{ + uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW ); + if( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument" ) ) ) ) + { + uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Sequence< uno::Any > aArgs(2); + aArgs[0] = uno::makeAny( getParent() ); + aArgs[1] <<= m_xShape; + uno::Reference< uno::XInterface > xTextFrame( xSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.excel.TextFrame") ) , aArgs ) , uno::UNO_QUERY_THROW ); + return uno::makeAny( xTextFrame ); + } + + return uno::makeAny( uno::Reference< msforms::XTextFrame >( new VbaTextFrame( this, mxContext, m_xShape ) ) ); +} + +void SAL_CALL +ScVbaShape::Delete() throw (uno::RuntimeException) +{ + OGuard aGuard( Application::GetSolarMutex() ); + m_xShapes->remove( m_xShape ); +} + +void SAL_CALL +ScVbaShape::ZOrder( sal_Int32 ZOrderCmd ) throw (uno::RuntimeException) +{ + sal_Int32 nOrderPositon; + uno::Any aOrderPostion = m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ) ); + aOrderPostion >>= nOrderPositon; + switch( ZOrderCmd ) + { + case office::MsoZOrderCmd::msoBringToFront: + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( SAL_MAX_INT32 ) ); + break; + case office::MsoZOrderCmd::msoSendToBack: + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( (sal_Int32)0 ) ); + break; + case office::MsoZOrderCmd::msoBringForward: + nOrderPositon += 1; + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( nOrderPositon ) ); + break; + case office::MsoZOrderCmd::msoSendBackward: + if( nOrderPositon > 0 ) + { + nOrderPositon -= 1; + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "ZOrder" ), uno::makeAny( nOrderPositon ) ); + } + break; + // below two commands use with Writer for text and image object. + case office::MsoZOrderCmd::msoBringInFrontOfText: + case office::MsoZOrderCmd::msoSendBehindText: + throw uno::RuntimeException( rtl::OUString::createFromAscii( "This ZOrderCmd is not implemented, it is use with writer." ), uno::Reference< uno::XInterface >() ); + default: + throw uno::RuntimeException( rtl::OUString::createFromAscii( "Invalid Parameter." ), uno::Reference< uno::XInterface >() ); + } +} + +void SAL_CALL +ScVbaShape::IncrementRotation( double Increment ) throw (uno::RuntimeException) +{ + double nCurrentRotation = getRotation(); + nCurrentRotation += Increment; + setRotation(nCurrentRotation); +} + +void SAL_CALL +ScVbaShape::IncrementLeft( double Increment ) throw (uno::RuntimeException) +{ + double nCurrentLeft = getLeft(); + nCurrentLeft += Increment; + setLeft(nCurrentLeft); +} + +void SAL_CALL +ScVbaShape::IncrementTop( double Increment ) throw (uno::RuntimeException) +{ + double nCurrentTop = getTop(); + nCurrentTop += Increment; + setTop(nCurrentTop); +} + +void SAL_CALL +ScVbaShape::ScaleHeight( double Factor, sal_Bool /*RelativeToOriginalSize*/, sal_Int32 Scale ) throw (uno::RuntimeException) +{ + double nHeight = getHeight(); + double nNewHeight = nHeight * Factor; + if( Scale == office::MsoScaleFrom::msoScaleFromTopLeft ) + { + setHeight(nNewHeight); + } + else if( Scale == office::MsoScaleFrom::msoScaleFromBottomRight ) + { + double nDeltaHeight = nNewHeight - nHeight; + double nNewTop = getTop() - nDeltaHeight; + setTop(nNewTop); + setHeight(nNewHeight); + } + else if( Scale == office::MsoScaleFrom::msoScaleFromMiddle ) + { + double nDeltaHeight = (nNewHeight - nHeight) / 2; + double nNewTop = getTop() - nDeltaHeight; + setTop(nNewTop); + setHeight(nNewHeight); + } + else + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "ScaleHeight.Scale wrong value is given." ) , uno::Reference< uno::XInterface >() ); + } +} + +void SAL_CALL +ScVbaShape::ScaleWidth( double Factor, sal_Bool /*RelativeToOriginalSize*/, sal_Int32 Scale ) throw (uno::RuntimeException) +{ + double nWidth = getWidth(); + double nNewWidth = nWidth * Factor; + if( Scale == office::MsoScaleFrom::msoScaleFromTopLeft ) + { + setWidth(nNewWidth); + } + else if( Scale == office::MsoScaleFrom::msoScaleFromBottomRight ) + { + double nDeltaWidth = nNewWidth - nWidth; + double nNewLeft = getLeft() - nDeltaWidth; + setLeft(nNewLeft); + setWidth(nNewWidth); + } + else if( Scale == office::MsoScaleFrom::msoScaleFromMiddle ) + { + double nDeltaWidth = (nNewWidth - nWidth) / 2; + double nNewLeft = getLeft() - nDeltaWidth; + setLeft(nNewLeft); + setWidth(nNewWidth); + } + else + { + throw uno::RuntimeException( rtl::OUString::createFromAscii( "ScaleHeight.Scale wrong value is given." ) , uno::Reference< uno::XInterface >() ); + } +} + +void SAL_CALL +ScVbaShape::Select( const uno::Any& /*Replace*/ ) throw ( uno::RuntimeException ) +{ + uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelectSupp->select( uno::makeAny( m_xShape ) ); +} + +// This method should not be part of Shape, what we reall need to do is... +// dynamically create the appropriate objects e.g. TextBox, Oval, Picture etc. +// ( e.g. the ones that really do have ShapeRange as an attribute ) +uno::Any SAL_CALL +ScVbaShape::ShapeRange( const uno::Any& index ) throw ( uno::RuntimeException ) +{ + // perhaps we should store a reference to the Shapes Collection + // in this class + // but anyway this method should not even be in this class + // #TODO not sure what the parent of the Shapes collection should be + + XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec aVec; + aVec.push_back( m_xShape ); + uno::Reference< container::XIndexAccess > xIndexAccess( new XNamedObjectCollectionHelper< drawing::XShape >( aVec ) ); + uno::Reference< container::XChild > xChild( m_xShape, uno::UNO_QUERY_THROW ); + // #FIXME for want of a better parent, setting this + uno::Reference< msforms::XShapeRange > xShapeRange( new ScVbaShapeRange( mxParent, mxContext, xIndexAccess, uno::Reference< drawing::XDrawPage >( xChild->getParent(), uno::UNO_QUERY_THROW ), m_xModel ) ); + if ( index.hasValue() ) + return xShapeRange->Item( index, uno::Any() ); + return uno::makeAny( xShapeRange ); +} + +sal_Bool SAL_CALL +ScVbaShape::getLockAspectRatio() throw (uno::RuntimeException) +{ + // FIXME: + return sal_False; +} + +void SAL_CALL +ScVbaShape::setLockAspectRatio( sal_Bool /*_lockaspectratio*/ ) throw (uno::RuntimeException) +{ + // FIXME: +} + +sal_Bool SAL_CALL +ScVbaShape::getLockAnchor() throw (uno::RuntimeException) +{ + // FIXME: + return sal_True; +} + +void SAL_CALL +ScVbaShape::setLockAnchor( sal_Bool /*_lockanchor*/ ) throw (uno::RuntimeException) +{ + // FIXME: +} + +sal_Int32 SAL_CALL +ScVbaShape::getRelativeHorizontalPosition() throw (uno::RuntimeException) +{ + sal_Int32 nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin; + text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH; + m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ) ) >>= eType; + + switch( eType ) + { + case text::TextContentAnchorType_AT_PARAGRAPH: + { + nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn; + break; + } + case text::TextContentAnchorType_AT_PAGE: + { + nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage; + break; + } + case text::TextContentAnchorType_AT_CHARACTER: + { + nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter; + break; + } + case text::TextContentAnchorType_AT_FRAME: + case text::TextContentAnchorType_AS_CHARACTER: + { + nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin; + break; + } + default: + { + nRelativeHorizontalPosition = word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin; + } + } + return nRelativeHorizontalPosition; +} + +void SAL_CALL +ScVbaShape::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (uno::RuntimeException) +{ + text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH; + switch( _relativehorizontalposition ) + { + case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionCharacter: + { + eType = text::TextContentAnchorType_AT_CHARACTER; + break; + } + case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionColumn: + case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionMargin: + { + eType = text::TextContentAnchorType_AT_PARAGRAPH; + break; + } + case word::WdRelativeHorizontalPosition::wdRelativeHorizontalPositionPage: + { + eType = text::TextContentAnchorType_AT_PAGE; + break; + } + default: + { + DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); + } + } + m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ), uno::makeAny( eType ) ); +} + +sal_Int32 SAL_CALL +ScVbaShape::getRelativeVerticalPosition() throw (uno::RuntimeException) +{ + sal_Int32 nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin; + text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH; + m_xPropertySet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ) ) >>= eType; + + switch( eType ) + { + case text::TextContentAnchorType_AT_PARAGRAPH: + { + nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph; + break; + } + case text::TextContentAnchorType_AT_PAGE: + { + nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage; + break; + } + case text::TextContentAnchorType_AT_CHARACTER: + { + nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine; + break; + } + case text::TextContentAnchorType_AT_FRAME: + case text::TextContentAnchorType_AS_CHARACTER: + { + nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin; + break; + } + default: + { + nRelativeVerticalPosition = word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin; + } + } + return nRelativeVerticalPosition; +} + +void SAL_CALL +ScVbaShape::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (uno::RuntimeException) +{ + text::TextContentAnchorType eType = text::TextContentAnchorType_AT_PARAGRAPH; + switch( _relativeverticalposition ) + { + case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionLine: + { + eType = text::TextContentAnchorType_AT_CHARACTER; + break; + } + case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionParagraph: + case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionMargin: + { + eType = text::TextContentAnchorType_AT_PARAGRAPH; + break; + } + case word::WdRelativeVerticalPosition::wdRelativeVerticalPositionPage: + { + eType = text::TextContentAnchorType_AT_PAGE; + break; + } + default: + { + DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString()); + } + } + m_xPropertySet->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("AnchorType") ), uno::makeAny( eType ) ); +} + +uno::Any SAL_CALL +ScVbaShape::WrapFormat() throw (uno::RuntimeException) +{ + uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW ); + if( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) ) + { + uno::Reference< lang::XMultiServiceFactory > xSF( comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW ); + uno::Sequence< uno::Any > aArgs(2); + aArgs[0] = uno::makeAny( getParent() ); + aArgs[1] <<= m_xShape; + uno::Reference< uno::XInterface > xWrapFormat( xSF->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.WrapFormat") ) , aArgs ) , uno::UNO_QUERY_THROW ); + return uno::makeAny( xWrapFormat ); + } + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); +} + + +rtl::OUString& +ScVbaShape::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaShape") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaShape::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.Shape" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/vbahelper/vbashaperange.cxx b/vbahelper/source/vbahelper/vbashaperange.cxx new file mode 100644 index 000000000000..3020cfa47eca --- /dev/null +++ b/vbahelper/source/vbahelper/vbashaperange.cxx @@ -0,0 +1,379 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/drawing/XShapeGrouper.hpp> +#include <com/sun/star/drawing/XDrawPage.hpp> +#include<com/sun/star/view/XSelectionSupplier.hpp> + +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbashaperange.hxx> +#include <vbahelper/vbashape.hxx> +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class VbShapeRangeEnumHelper : public EnumerationHelper_BASE +{ + uno::Reference< XCollection > m_xParent; + uno::Reference<container::XIndexAccess > m_xIndexAccess; + sal_Int32 nIndex; +public: + VbShapeRangeEnumHelper( const uno::Reference< XCollection >& xParent, const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xParent( xParent ), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + ScVbaShapeRange* pCollectionImpl = dynamic_cast< ScVbaShapeRange* >(m_xParent.get()); + if ( pCollectionImpl && hasMoreElements() ) + return pCollectionImpl->createCollectionObject( m_xIndexAccess->getByIndex( nIndex++ ) ); + throw container::NoSuchElementException(); + } + +}; + +ScVbaShapeRange::ScVbaShapeRange( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XIndexAccess >& xShapes, const uno::Reference< drawing::XDrawPage >& xDrawPage, const uno::Reference< frame::XModel >& xModel ) : ScVbaShapeRange_BASE( xParent, xContext, xShapes ), m_xDrawPage( xDrawPage ), m_nShapeGroupCount(0), m_xModel( xModel ) +{ +} + +// Methods +void SAL_CALL +ScVbaShapeRange::Select( ) throw (uno::RuntimeException) +{ + uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + xSelectSupp->select( uno::makeAny( getShapes() ) ); +} + +uno::Reference< msforms::XShape > SAL_CALL +ScVbaShapeRange::Group() throw (uno::RuntimeException) +{ + uno::Reference< drawing::XShapeGrouper > xShapeGrouper( m_xDrawPage, uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XShapeGroup > xShapeGroup( xShapeGrouper->group( getShapes() ), uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XShape > xShape( xShapeGroup, uno::UNO_QUERY_THROW ); + return uno::Reference< msforms::XShape >( new ScVbaShape( getParent(), mxContext, xShape, getShapes(), m_xModel, office::MsoShapeType::msoGroup ) ); +} + +uno::Reference< drawing::XShapes > +ScVbaShapeRange::getShapes() throw (uno::RuntimeException) +{ + if ( !m_xShapes.is() ) + { + uno::Reference< lang::XMultiServiceFactory > xMSF( mxContext->getServiceManager(), uno::UNO_QUERY_THROW ); + m_xShapes.set( xMSF->createInstance( rtl::OUString::createFromAscii( "com.sun.star.drawing.ShapeCollection" ) ), uno::UNO_QUERY_THROW ); + sal_Int32 nLen = m_xIndexAccess->getCount(); + for ( sal_Int32 index = 0; index < nLen; ++index ) + m_xShapes->add( uno::Reference< drawing::XShape >( m_xIndexAccess->getByIndex( index ), uno::UNO_QUERY_THROW ) ); + + } + return m_xShapes; +} + + +void SAL_CALL +ScVbaShapeRange::IncrementRotation( double Increment ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->IncrementRotation( Increment ); + } +} + +void SAL_CALL +ScVbaShapeRange::IncrementLeft( double Increment ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->IncrementLeft( Increment ); + } +} + +void SAL_CALL +ScVbaShapeRange::IncrementTop( double Increment ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->IncrementTop( Increment ); + } +} + +double SAL_CALL ScVbaShapeRange::getHeight() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getHeight( ); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setHeight( double _height ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setHeight( _height ); + } +} + +double SAL_CALL ScVbaShapeRange::getWidth() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getWidth( ); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setWidth( double _width ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setWidth( _width ); + } +} + +double SAL_CALL ScVbaShapeRange::getLeft() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getLeft(); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setLeft( double _left ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setLeft( _left ); + } +} + +double SAL_CALL ScVbaShapeRange::getTop() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getTop(); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setTop( double _top ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setTop( _top ); + } +} + +uno::Reference< ov::msforms::XLineFormat > SAL_CALL ScVbaShapeRange::getLine() throw (css::uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getLine(); + } + throw uno::RuntimeException(); +} + +uno::Reference< ov::msforms::XFillFormat > SAL_CALL ScVbaShapeRange::getFill() throw (css::uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getFill(); + } + throw uno::RuntimeException(); +} + +::sal_Bool SAL_CALL ScVbaShapeRange::getLockAspectRatio() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getLockAspectRatio(); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setLockAspectRatio( ::sal_Bool _lockaspectratio ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setLockAspectRatio( _lockaspectratio ); + } +} + +::sal_Bool SAL_CALL ScVbaShapeRange::getLockAnchor() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getLockAnchor(); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setLockAnchor( ::sal_Bool _lockanchor ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setLockAnchor( _lockanchor ); + } +} + +::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeHorizontalPosition() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getRelativeHorizontalPosition(); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setRelativeHorizontalPosition( ::sal_Int32 _relativehorizontalposition ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setRelativeHorizontalPosition( _relativehorizontalposition ); + } +} + +::sal_Int32 SAL_CALL ScVbaShapeRange::getRelativeVerticalPosition() throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->getRelativeVerticalPosition(); + } + throw uno::RuntimeException(); +} + +void SAL_CALL ScVbaShapeRange::setRelativeVerticalPosition( ::sal_Int32 _relativeverticalposition ) throw (uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + xShape->setRelativeVerticalPosition( _relativeverticalposition ); + } +} + +uno::Any SAL_CALL ScVbaShapeRange::TextFrame( ) throw (css::uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->TextFrame(); + } + throw uno::RuntimeException(); +} + +uno::Any SAL_CALL ScVbaShapeRange::WrapFormat( ) throw (css::uno::RuntimeException) +{ + sal_Int32 nLen = getCount(); + for ( sal_Int32 index = 1; index <= nLen; ++index ) + { + uno::Reference< msforms::XShape > xShape( Item( uno::makeAny( index ), uno::Any() ), uno::UNO_QUERY_THROW ); + return xShape->WrapFormat(); + } + throw uno::RuntimeException(); +} + +uno::Type SAL_CALL +ScVbaShapeRange::getElementType() throw (uno::RuntimeException) +{ + return msforms::XShape::static_type(0); +} + +uno::Reference< container::XEnumeration > SAL_CALL +ScVbaShapeRange::createEnumeration() throw (uno::RuntimeException) +{ + return new VbShapeRangeEnumHelper( this, m_xIndexAccess ); +} + +uno::Any +ScVbaShapeRange:: createCollectionObject( const css::uno::Any& aSource ) +{ + uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW ); + // #TODO #FIXME Shape parent should always be the sheet the shapes belong + // to + uno::Reference< msforms::XShape > xVbShape( new ScVbaShape( uno::Reference< XHelperInterface >(), mxContext, xShape, getShapes(), m_xModel, ScVbaShape::getType( xShape ) ) ); + return uno::makeAny( xVbShape ); +} + +rtl::OUString& +ScVbaShapeRange::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaShapeRange") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaShapeRange::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.ShapeRange" ) ); + } + return aServiceNames; +} diff --git a/vbahelper/source/vbahelper/vbashapes.cxx b/vbahelper/source/vbahelper/vbashapes.cxx new file mode 100644 index 000000000000..37952ee3d3a3 --- /dev/null +++ b/vbahelper/source/vbahelper/vbashapes.cxx @@ -0,0 +1,488 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <com/sun/star/container/XNamed.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/text/WrapTextMode.hpp> +#include <ooo/vba/msforms/XShapeRange.hpp> +#include <ooo/vba/office/MsoAutoShapeType.hpp> +#include <ooo/vba/office/MsoTextOrientation.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/text/XText.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/text/XTextContent.hpp> +#include <com/sun/star/text/TextContentAnchorType.hpp> +#include <com/sun/star/text/HoriOrientation.hpp> +#include <com/sun/star/text/VertOrientation.hpp> +#include <com/sun/star/text/RelOrientation.hpp> +#include <com/sun/star/text/SizeType.hpp> +#include <com/sun/star/text/WritingMode.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> + +#include <vbahelper/vbahelper.hxx> +#include <vbahelper/vbashape.hxx> +#include <vbahelper/vbashapes.hxx> +#include <vbahelper/vbashaperange.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +class VbShapeEnumHelper : public EnumerationHelper_BASE +{ + uno::Reference<msforms::XShapes > m_xParent; + uno::Reference<container::XIndexAccess > m_xIndexAccess; + sal_Int32 nIndex; +public: + VbShapeEnumHelper( const uno::Reference< msforms::XShapes >& xParent, const uno::Reference< container::XIndexAccess >& xIndexAccess ) : m_xParent( xParent ), m_xIndexAccess( xIndexAccess ), nIndex( 0 ) {} + virtual ::sal_Bool SAL_CALL hasMoreElements( ) throw (uno::RuntimeException) + { + return ( nIndex < m_xIndexAccess->getCount() ); + } + virtual uno::Any SAL_CALL nextElement( ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException) + { + ScVbaShapes* pShapes = dynamic_cast< ScVbaShapes* >(m_xParent.get()); + if ( pShapes && hasMoreElements() ) + return pShapes->createCollectionObject( m_xIndexAccess->getByIndex( nIndex++ ) ); + throw container::NoSuchElementException(); + } + +}; + +void ScVbaShapes::initBaseCollection() +{ + if ( m_xNameAccess.is() ) // already has NameAccess + return; + // no NameAccess then use ShapeCollectionHelper + XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec mShapes; + sal_Int32 nLen = m_xIndexAccess->getCount(); + mShapes.reserve( nLen ); + for ( sal_Int32 index=0; index<nLen; ++index ) + mShapes.push_back( uno::Reference< drawing::XShape >( m_xIndexAccess->getByIndex( index ) , uno::UNO_QUERY ) ); + uno::Reference< container::XIndexAccess > xShapes( new XNamedObjectCollectionHelper< drawing::XShape >( mShapes ) ); + m_xIndexAccess.set( xShapes, uno::UNO_QUERY ); + m_xNameAccess.set( xShapes, uno::UNO_QUERY ); +} + +ScVbaShapes::ScVbaShapes( const css::uno::Reference< ov::XHelperInterface >& xParent, const css::uno::Reference< css::uno::XComponentContext >& xContext, const css::uno::Reference< css::container::XIndexAccess > xShapes, const uno::Reference< frame::XModel>& xModel ): ScVbaShapes_BASE( xParent, xContext, xShapes ), m_nNewShapeCount(0), m_xModel( xModel ) +{ + m_xShapes.set( xShapes, uno::UNO_QUERY_THROW ); + m_xDrawPage.set( xShapes, uno::UNO_QUERY_THROW ); + initBaseCollection(); +} + +uno::Reference< container::XEnumeration > +ScVbaShapes::createEnumeration() throw (uno::RuntimeException) +{ + return new VbShapeEnumHelper( this, m_xIndexAccess ); +} + +uno::Any +ScVbaShapes::createCollectionObject( const css::uno::Any& aSource ) throw (uno::RuntimeException) +{ + if( aSource.hasValue() ) + { + uno::Reference< drawing::XShape > xShape( aSource, uno::UNO_QUERY_THROW ); + return uno::makeAny( uno::Reference< msforms::XShape >( new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ) ) ); + } + return uno::Any(); +} + +uno::Type +ScVbaShapes::getElementType() throw (uno::RuntimeException) +{ + return ooo::vba::msforms::XShape::static_type(0); +} +rtl::OUString& +ScVbaShapes::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("ScVbaShapes") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +ScVbaShapes::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msform.Shapes" ) ); + } + return aServiceNames; +} + +css::uno::Reference< css::container::XIndexAccess > +ScVbaShapes::getShapesByArrayIndices( const uno::Any& Index ) throw (uno::RuntimeException) +{ + if ( Index.getValueTypeClass() != uno::TypeClass_SEQUENCE ) + throw uno::RuntimeException(); + + uno::Reference< script::XTypeConverter > xConverter = getTypeConverter(mxContext); + uno::Any aConverted; + aConverted = xConverter->convertTo( Index, getCppuType((uno::Sequence< uno::Any >*)0) ); + + uno::Sequence< uno::Any > sIndices; + aConverted >>= sIndices; + XNamedObjectCollectionHelper< drawing::XShape >::XNamedVec mShapes; + sal_Int32 nElems = sIndices.getLength(); + for( sal_Int32 index = 0; index < nElems; ++index ) + { + uno::Reference< drawing::XShape > xShape; + if ( sIndices[ index ].getValueTypeClass() == uno::TypeClass_STRING ) + { + rtl::OUString sName; + sIndices[ index ] >>= sName; + xShape.set( m_xNameAccess->getByName( sName ), uno::UNO_QUERY ); + } + else + { + sal_Int32 nIndex = 0; + sIndices[ index ] >>= nIndex; + // adjust for 1 based mso indexing + xShape.set( m_xIndexAccess->getByIndex( nIndex - 1 ), uno::UNO_QUERY ); + + } + // populate map with drawing::XShapes + if ( xShape.is() ) + mShapes.push_back( xShape ); + } + uno::Reference< container::XIndexAccess > xIndexAccess( new XNamedObjectCollectionHelper< drawing::XShape >( mShapes ) ); + return xIndexAccess; +} + +uno::Any SAL_CALL +ScVbaShapes::Item( const uno::Any& Index, const uno::Any& Index2 ) throw (uno::RuntimeException) +{ + // I don't think we need to support Array of indices for shapes +/* + if ( Index.getValueTypeClass() == uno::TypeClass_SEQUENCE ) + { + uno::Reference< container::XIndexAccess > xIndexAccess( getShapesByArrayIndices( Index ) ); + // return new collection instance + uno::Reference< XCollection > xShapesCollection( new ScVbaShapes( this->getParent(), mxContext, xIndexAccess ) ); + return uno::makeAny( xShapesCollection ); + } +*/ + return ScVbaShapes_BASE::Item( Index, Index2 ); +} + +uno::Reference< msforms::XShapeRange > SAL_CALL +ScVbaShapes::Range( const uno::Any& shapes ) throw (css::uno::RuntimeException) +{ + // shapes, can be an index or an array of indices + uno::Reference< container::XIndexAccess > xShapes; + if ( shapes.getValueTypeClass() == uno::TypeClass_SEQUENCE ) + xShapes = getShapesByArrayIndices( shapes ); + else + { + // wrap single index into a sequence + uno::Sequence< uno::Any > sIndices(1); + sIndices[ 0 ] = shapes; + uno::Any aIndex; + aIndex <<= sIndices; + xShapes = getShapesByArrayIndices( aIndex ); + } + return new ScVbaShapeRange( getParent(), mxContext, xShapes, m_xDrawPage, m_xModel ); +} + +void SAL_CALL +ScVbaShapes::SelectAll() throw (uno::RuntimeException) +{ + uno::Reference< view::XSelectionSupplier > xSelectSupp( m_xModel->getCurrentController(), uno::UNO_QUERY_THROW ); + try + { + xSelectSupp->select( uno::makeAny( m_xShapes ) ); + } + // viewuno.cxx ScTabViewObj::select will throw IllegalArgumentException + // if one of the shapes is no 'markable' e.g. a button + // the method still works + catch( lang::IllegalArgumentException& ) + { + } +} + +uno::Reference< drawing::XShape > +ScVbaShapes::createShape( rtl::OUString service ) throw (css::uno::RuntimeException) +{ + uno::Reference< lang::XMultiServiceFactory > xMSF( m_xModel, uno::UNO_QUERY_THROW ); + uno::Reference< drawing::XShape > xShape( xMSF->createInstance( service ), uno::UNO_QUERY_THROW ); + return xShape; +} + +uno::Any +ScVbaShapes::AddRectangle( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, uno::Any aRange ) throw (css::uno::RuntimeException) +{ + rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.RectangleShape" ) ); + sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX ); + sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY ); + sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth ); + sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight ); + + uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW ); + m_xShapes->add( xShape ); + + rtl::OUString sName = createName( rtl::OUString::createFromAscii( "Rectangle" ) ); + setDefaultShapeProperties( xShape ); + setShape_NameProperty( xShape, sName ); + + awt::Point aMovePositionIfRange(0, 0); + awt::Point position; + position.X = nXPos - aMovePositionIfRange.X; + position.Y = nYPos - aMovePositionIfRange.Y; + xShape->setPosition( position ); + + awt::Size size; + size.Height = nHeight; + size.Width = nWidth; + xShape->setSize( size ); + + ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ); + pScVbaShape->setRange( aRange ); + return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) ); +} + +uno::Any +ScVbaShapes::AddEllipse( sal_Int32 startX, sal_Int32 startY, sal_Int32 nLineWidth, sal_Int32 nLineHeight, uno::Any aRange ) throw (css::uno::RuntimeException) +{ + rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.EllipseShape" ) ); + sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( startX ); + sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( startY ); + sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth ); + sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight ); + + uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW ); + m_xShapes->add( xShape ); + + awt::Point aMovePositionIfRange( 0, 0 ); + //TODO helperapi using a writer document + /* + XDocument xDocument = (XDocument)getParent(); + if (AnyConverter.isVoid(_aRange)) + { + _aRange = xDocument.Range(new Integer(0), new Integer(1)); + // Top&Left in Word is Top&Left of the paper and not the writeable area. + aMovePositionIfRange = calculateTopLeftMargin((HelperInterfaceAdaptor)xDocument); + } + + setShape_AnchorTypeAndRangeProperty(xShape, _aRange); + */ + rtl::OUString name = createName( rtl::OUString::createFromAscii( "Oval" )); + setDefaultShapeProperties(xShape); + setShape_NameProperty(xShape, name); + + awt::Point position; + position.X = nXPos - aMovePositionIfRange.X; + position.Y = nYPos - aMovePositionIfRange.Y; + xShape->setPosition(position); + + awt::Size size; + size.Height = nHeight; + size.Width = nWidth; + xShape->setSize(size); + + ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ); + pScVbaShape->setRange( aRange ); + return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) ); +} + +//helpeapi calc +uno::Any SAL_CALL +ScVbaShapes::AddLine( sal_Int32 StartX, sal_Int32 StartY, sal_Int32 endX, sal_Int32 endY ) throw (uno::RuntimeException) +{ + sal_Int32 nLineWidth = endX - StartX; + sal_Int32 nLineHeight = endY - StartY; + + sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( nLineHeight ); + sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( nLineWidth ); + sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( StartX ); + sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( StartY ); + + uno::Reference< drawing::XShape > xShape( createShape( rtl::OUString::createFromAscii("com.sun.star.drawing.LineShape") ), uno::UNO_QUERY_THROW ); + m_xShapes->add( xShape ); + + awt::Point aMovePositionIfRange( 0, 0 ); + + rtl::OUString name = createName( rtl::OUString::createFromAscii( "Line" ) ); + setDefaultShapeProperties(xShape); + setShape_NameProperty(xShape, name); + + awt::Point position; + position.X = nXPos - aMovePositionIfRange.X; + position.Y = nYPos - aMovePositionIfRange.Y; + xShape->setPosition(position); + + awt::Size size; + size.Height = nHeight; + size.Width = nWidth; + xShape->setSize(size); + + ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ); + return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) ); +} + +uno::Any SAL_CALL +ScVbaShapes::AddShape( sal_Int32 _nType, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException) +{ + uno::Any _aAnchor; + if (_nType == office::MsoAutoShapeType::msoShapeRectangle) + { + return AddRectangle(_nLeft, _nTop, _nWidth, _nHeight, _aAnchor); + } + else if (_nType == office::MsoAutoShapeType::msoShapeOval) + { + return AddEllipse(_nLeft, _nTop, _nWidth, _nHeight, _aAnchor); + } + return uno::Any(); +} + +uno::Any SAL_CALL +ScVbaShapes::AddTextbox( sal_Int32 _nOrientation, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException) +{ + uno::Reference< lang::XServiceInfo > xServiceInfo( m_xModel, uno::UNO_QUERY_THROW ); + if( xServiceInfo->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) ) + { + return AddTextboxInWriter( _nOrientation, _nLeft, _nTop, _nWidth, _nHeight ); + } + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); +} + +uno::Any +ScVbaShapes::AddTextboxInWriter( sal_Int32 /*_nOrientation*/, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException) +{ + rtl::OUString sCreateShapeName( rtl::OUString::createFromAscii( "com.sun.star.drawing.TextShape" ) ); + sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( _nLeft ); + sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( _nTop ); + sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( _nWidth ); + sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( _nHeight ); + + uno::Reference< drawing::XShape > xShape( createShape( sCreateShapeName ), uno::UNO_QUERY_THROW ); + m_xShapes->add( xShape ); + + setDefaultShapeProperties(xShape); + + rtl::OUString sName = createName( rtl::OUString::createFromAscii( "Text Box") ); + setShape_NameProperty( xShape, sName ); + + awt::Size size; + size.Height = nHeight; + size.Width = nWidth; + xShape->setSize(size); + + uno::Reference< beans::XPropertySet > xShapeProps( xShape, uno::UNO_QUERY_THROW ); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "AnchorType" ), uno::makeAny( text::TextContentAnchorType_AT_PAGE ) ); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrientRelation" ), uno::makeAny( text::RelOrientation::PAGE_LEFT ) ); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrient" ), uno::makeAny( text::HoriOrientation::NONE ) ); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "HoriOrientPosition" ), uno::makeAny( nXPos ) ); + + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrientRelation" ), uno::makeAny( text::RelOrientation::PAGE_FRAME ) ); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrient" ), uno::makeAny( text::VertOrientation::NONE ) ); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "VertOrientPosition" ), uno::makeAny( nYPos ) ); + + // set to visible + drawing::LineStyle aLineStyle = drawing::LineStyle_SOLID; + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LineStyle" ), uno::makeAny( aLineStyle ) ); + // set to font + sal_Int16 nLayerId = 1; + rtl::OUString sLayerName = rtl::OUString::createFromAscii("Heaven"); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LayerID" ), uno::makeAny( nLayerId ) ); + xShapeProps->setPropertyValue( rtl::OUString::createFromAscii( "LayerName" ), uno::makeAny( sLayerName ) ); + + + ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ); + return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) ); +} + +uno::Any +ScVbaShapes::AddShape( const rtl::OUString& sService, const rtl::OUString& sName, sal_Int32 _nLeft, sal_Int32 _nTop, sal_Int32 _nWidth, sal_Int32 _nHeight ) throw (uno::RuntimeException) +{ + sal_Int32 nXPos = Millimeter::getInHundredthsOfOneMillimeter( _nLeft ); + sal_Int32 nYPos = Millimeter::getInHundredthsOfOneMillimeter( _nTop ); + sal_Int32 nWidth = Millimeter::getInHundredthsOfOneMillimeter( _nWidth ); + sal_Int32 nHeight = Millimeter::getInHundredthsOfOneMillimeter( _nHeight ); + + uno::Reference< drawing::XShape > xShape( createShape( sService ), uno::UNO_QUERY_THROW ); + m_xShapes->add( xShape ); + + setDefaultShapeProperties(xShape); + setShape_NameProperty( xShape, sName ); + + awt::Point aMovePositionIfRange( 0, 0 ); + awt::Point position; + position.X = nXPos - aMovePositionIfRange.X; + position.Y = nYPos - aMovePositionIfRange.Y; + xShape->setPosition(position); + + awt::Size size; + size.Height = nHeight; + size.Width = nWidth; + xShape->setSize(size); + + ScVbaShape *pScVbaShape = new ScVbaShape( getParent(), mxContext, xShape, m_xShapes, m_xModel, ScVbaShape::getType( xShape ) ); + return uno::makeAny( uno::Reference< msforms::XShape > ( pScVbaShape ) ); +} +void +ScVbaShapes::setDefaultShapeProperties( uno::Reference< drawing::XShape > xShape ) throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW ); + xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillStyle" ), uno::makeAny( rtl::OUString::createFromAscii( "SOLID" ) ) ); + xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "FillColor"), uno::makeAny( sal_Int32(0xFFFFFF) ) ); + xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextWordWrap"), uno::makeAny( text::WrapTextMode_THROUGHT ) ); + //not find in OOo2.3 + //xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "Opaque"), uno::makeAny( sal_True ) ); +} + +void +ScVbaShapes::setShape_NameProperty( uno::Reference< css::drawing::XShape > xShape, rtl::OUString sName ) +{ + uno::Reference< beans::XPropertySet > xPropertySet( xShape, uno::UNO_QUERY_THROW ); + try + { + xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "Name" ), uno::makeAny( sName ) ); + } + catch( script::BasicErrorException e ) + { + } +} + +rtl::OUString +ScVbaShapes::createName( rtl::OUString sName ) +{ + sal_Int32 nActNumber = 1 + m_nNewShapeCount; + m_nNewShapeCount++; + sName += rtl::OUString::valueOf( nActNumber ); + return sName; +} + +#if 0 +//TODO helperapi using a writer document +awt::Point +calculateTopLeftMargin( uno::Reference< XHelperInterface > xDocument ) +{ + awt::Point aPoint( 0, 0 ); + uno::Reference< frame::XModel > xModel( xDocument, uno::UNO_QUERY_THROW ); + return awt::Point(); +} +#endif diff --git a/vbahelper/source/vbahelper/vbatextframe.cxx b/vbahelper/source/vbahelper/vbatextframe.cxx new file mode 100644 index 000000000000..de15992fe49e --- /dev/null +++ b/vbahelper/source/vbahelper/vbatextframe.cxx @@ -0,0 +1,166 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#include <vbahelper/helperdecl.hxx> +#include <com/sun/star/drawing/TextFitToSizeType.hpp> +#include <com/sun/star/text/XText.hpp> +#include <vbahelper/vbatextframe.hxx> + +using namespace ::ooo::vba; +using namespace ::com::sun::star; + +VbaTextFrame::VbaTextFrame( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< drawing::XShape > xShape ) : VbaTextFrame_BASE( xParent, xContext ), m_xShape( xShape ) +{ + m_xPropertySet.set( m_xShape, uno::UNO_QUERY_THROW ); +} + +void +VbaTextFrame::setAsMSObehavior() +{ + //set property TextWordWrap default as False. + // TextFitToSize control the text content. it seems we should set the default as False. + // com.sun.star.drawing.TextFitToSizeType.NONE + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextWordWrap" ), uno::makeAny( sal_False ) ); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextFitToSize" ), uno::makeAny( drawing::TextFitToSizeType_NONE ) ); +} + +sal_Int32 VbaTextFrame::getMargin( rtl::OUString sMarginType ) +{ + sal_Int32 nMargin = 0; + uno::Any aMargin = m_xPropertySet->getPropertyValue( sMarginType ); + aMargin >>= nMargin; + return nMargin; +} + +void VbaTextFrame::setMargin( rtl::OUString sMarginType, float fMargin ) +{ + sal_Int32 nMargin = Millimeter::getInHundredthsOfOneMillimeter( fMargin ); + m_xPropertySet->setPropertyValue( sMarginType, uno::makeAny( nMargin ) ); +} + +// Attributes +sal_Bool SAL_CALL +VbaTextFrame::getAutoSize() throw (uno::RuntimeException) +{ + // I don't know why, but in OOo, TextAutoGrowHeight is the property control autosize. not TextFitToSize. + // TextFitToSize control the text content. + // and in mso, there isnot option TextWordWrap which means auto wrap. the default is False. + sal_Bool bAutosize = sal_False; + uno::Any aTextAutoGrowHeight = m_xPropertySet->getPropertyValue( rtl::OUString::createFromAscii( "TextAutoGrowHeight" ) ); + aTextAutoGrowHeight >>= bAutosize; + return bAutosize; +} + +void SAL_CALL +VbaTextFrame::setAutoSize( sal_Bool _autosize ) throw (uno::RuntimeException) +{ + setAsMSObehavior(); + m_xPropertySet->setPropertyValue( rtl::OUString::createFromAscii( "TextAutoGrowHeight" ), uno::makeAny( _autosize ) ); +} + +float SAL_CALL +VbaTextFrame::getMarginBottom() throw (uno::RuntimeException) +{ + sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextLowerDistance" ) ); + float fMargin = (float)Millimeter::getInPoints( nMargin ); + return fMargin; +} + +void SAL_CALL +VbaTextFrame::setMarginBottom( float _marginbottom ) throw (uno::RuntimeException) +{ + setMargin( rtl::OUString::createFromAscii( "TextLowerDistance" ), _marginbottom ); +} + +float SAL_CALL +VbaTextFrame::getMarginTop() throw (uno::RuntimeException) +{ + sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextUpperDistance" ) ); + float fMargin = (float)Millimeter::getInPoints( nMargin ); + return fMargin; +} + +void SAL_CALL +VbaTextFrame::setMarginTop( float _margintop ) throw (uno::RuntimeException) +{ + setMargin( rtl::OUString::createFromAscii( "TextUpperDistance" ), _margintop ); +} + +float SAL_CALL +VbaTextFrame::getMarginLeft() throw (uno::RuntimeException) +{ + sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextLeftDistance" ) ); + float fMargin = (float)Millimeter::getInPoints( nMargin ); + return fMargin; +} + +void SAL_CALL +VbaTextFrame::setMarginLeft( float _marginleft ) throw (uno::RuntimeException) +{ + setMargin( rtl::OUString::createFromAscii( "TextLeftDistance" ), _marginleft ); +} + +float SAL_CALL +VbaTextFrame::getMarginRight() throw (uno::RuntimeException) +{ + sal_Int32 nMargin = getMargin( rtl::OUString::createFromAscii( "TextRightDistance" ) ); + float fMargin = (float)Millimeter::getInPoints( nMargin ); + return fMargin; +} + +void SAL_CALL +VbaTextFrame::setMarginRight( float _marginright ) throw (uno::RuntimeException) +{ + setMargin( rtl::OUString::createFromAscii( "TextRightDistance" ), _marginright ); +} + + +// Methods +uno::Any SAL_CALL +VbaTextFrame::Characters() throw (uno::RuntimeException) +{ + throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() ); +} + +rtl::OUString& +VbaTextFrame::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaTextFrame") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +VbaTextFrame::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.msforms.TextFrame" ) ); + } + return aServiceNames; +} + diff --git a/vbahelper/source/vbahelper/vbawindowbase.cxx b/vbahelper/source/vbahelper/vbawindowbase.cxx new file mode 100644 index 000000000000..132caef8b5e1 --- /dev/null +++ b/vbahelper/source/vbahelper/vbawindowbase.cxx @@ -0,0 +1,177 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#include "vbahelper/vbawindowbase.hxx" +#include "vbahelper/helperdecl.hxx" +#include <com/sun/star/awt/PosSize.hpp> + +using namespace ::com::sun::star; +using namespace ::ooo::vba; + +VbaWindowBase::VbaWindowBase( + const uno::Reference< XHelperInterface >& xParent, + const uno::Reference< uno::XComponentContext >& xContext, + const css::uno::Reference< css::frame::XModel >& xModel, + const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) : + WindowBaseImpl_BASE( xParent, xContext ), + m_xModel( xModel, uno::UNO_SET_THROW ) +{ + construct( xController ); +} + +VbaWindowBase::VbaWindowBase( uno::Sequence< uno::Any > const & args, + uno::Reference< uno::XComponentContext > const & xContext ) throw (uno::RuntimeException) : + WindowBaseImpl_BASE( getXSomethingFromArgs< XHelperInterface >( args, 0, false ), xContext ), + m_xModel( getXSomethingFromArgs< frame::XModel >( args, 1, false ) ) +{ + construct( getXSomethingFromArgs< frame::XController >( args, 2 ) ); +} + +sal_Bool SAL_CALL +VbaWindowBase::getVisible() throw (uno::RuntimeException) +{ + return getWindow2()->isVisible(); +} + +void SAL_CALL +VbaWindowBase::setVisible( sal_Bool _visible ) throw (uno::RuntimeException) +{ + getWindow2()->setVisible( _visible ); +} + +void setPosSize( const uno::Reference< awt::XWindow >& xWindow, sal_Int32 nValue, sal_Int16 nFlag ) +{ + css::awt::Rectangle aRect = xWindow->getPosSize(); + switch( nFlag ) + { + case css::awt::PosSize::X: + xWindow->setPosSize( nValue, aRect.Y, 0, 0, css::awt::PosSize::X ); + break; + case css::awt::PosSize::Y: + xWindow->setPosSize( aRect.X, nValue, 0, 0, css::awt::PosSize::Y ); + break; + case css::awt::PosSize::WIDTH: + xWindow->setPosSize( 0, 0, nValue, aRect.Height, css::awt::PosSize::WIDTH ); + break; + case css::awt::PosSize::HEIGHT: + xWindow->setPosSize( 0, 0, aRect.Width, nValue, css::awt::PosSize::HEIGHT ); + break; + default: + break; + } +} + +sal_Int32 SAL_CALL +VbaWindowBase::getHeight() throw (uno::RuntimeException) +{ + return getWindow()->getPosSize().Height; +} + +void SAL_CALL +VbaWindowBase::setHeight( sal_Int32 _height ) throw (uno::RuntimeException) +{ + setPosSize( getWindow(), _height, css::awt::PosSize::HEIGHT ); +} + +sal_Int32 SAL_CALL +VbaWindowBase::getLeft() throw (uno::RuntimeException) +{ + return getWindow()->getPosSize().X; +} + +void SAL_CALL +VbaWindowBase::setLeft( sal_Int32 _left ) throw (uno::RuntimeException) +{ + setPosSize( getWindow(), _left, css::awt::PosSize::X ); +} + +sal_Int32 SAL_CALL +VbaWindowBase::getTop() throw (uno::RuntimeException) +{ + return getWindow()->getPosSize().Y; +} + +void SAL_CALL +VbaWindowBase::setTop( sal_Int32 _top ) throw (uno::RuntimeException) +{ + setPosSize( getWindow(), _top, css::awt::PosSize::Y ); +} + +sal_Int32 SAL_CALL +VbaWindowBase::getWidth() throw (uno::RuntimeException) +{ + return getWindow()->getPosSize().Width; +} + +void SAL_CALL +VbaWindowBase::setWidth( sal_Int32 _width ) throw (uno::RuntimeException) +{ + setPosSize( getWindow(), _width, css::awt::PosSize::WIDTH ); +} + +rtl::OUString& +VbaWindowBase::getServiceImplName() +{ + static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("VbaWindowBase") ); + return sImplName; +} + +uno::Sequence< rtl::OUString > +VbaWindowBase::getServiceNames() +{ + static uno::Sequence< rtl::OUString > aServiceNames; + if ( aServiceNames.getLength() == 0 ) + { + aServiceNames.realloc( 1 ); + aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.VbaWindowBase" ) ); + } + return aServiceNames; +} + +uno::Reference< frame::XController > VbaWindowBase::getController() throw (css::uno::RuntimeException) +{ + return uno::Reference< frame::XController >( m_xController, uno::UNO_SET_THROW ); +} + +uno::Reference< awt::XWindow > VbaWindowBase::getWindow() throw (uno::RuntimeException) +{ + return uno::Reference< awt::XWindow >( m_xWindow, uno::UNO_SET_THROW ); +} + +uno::Reference< awt::XWindow2 > VbaWindowBase::getWindow2() throw (uno::RuntimeException) +{ + return uno::Reference< awt::XWindow2 >( getWindow(), uno::UNO_QUERY_THROW ); +} + +void VbaWindowBase::construct( const uno::Reference< frame::XController >& xController ) throw (uno::RuntimeException) +{ + if( !xController.is() ) throw uno::RuntimeException(); + uno::Reference< frame::XFrame > xFrame( xController->getFrame(), uno::UNO_SET_THROW ); + uno::Reference< awt::XWindow > xWindow( xFrame->getContainerWindow(), uno::UNO_SET_THROW ); + m_xController = xController; + m_xWindow = xWindow; +} diff --git a/vbahelper/util/msforms.component b/vbahelper/util/msforms.component new file mode 100644 index 000000000000..98ce4a8451d4 --- /dev/null +++ b/vbahelper/util/msforms.component @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +* +* Copyright 2000, 2010 Oracle and/or its affiliates. +* +* OpenOffice.org - a multi-platform office productivity suite +* +* This file is part of OpenOffice.org. +* +* OpenOffice.org is free software: you can redistribute it and/or modify +* it under the terms of the GNU Lesser General Public License version 3 +* only, as published by the Free Software Foundation. +* +* OpenOffice.org is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Lesser General Public License version 3 for more details +* (a copy is included in the LICENSE file that accompanied this code). +* +* You should have received a copy of the GNU Lesser General Public License +* version 3 along with OpenOffice.org. If not, see +* <http://www.openoffice.org/license.html> +* for a copy of the LGPLv3 License. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="ControlProviderImpl"> + <service name="ooo.vba.ControlProvider"/> + </implementation> + <implementation name="ScVbaUserForm"> + <service name="ooo.vba.msforms.UserForm"/> + </implementation> +</component> |