diff options
Diffstat (limited to 'odk/examples/cpp/complextoolbarcontrols')
19 files changed, 2073 insertions, 0 deletions
diff --git a/odk/examples/cpp/complextoolbarcontrols/Addons.xcu b/odk/examples/cpp/complextoolbarcontrols/Addons.xcu new file mode 100644 index 000000000000..52ef0d376ca4 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/Addons.xcu @@ -0,0 +1,170 @@ +<?xml version='1.0' encoding='UTF-8'?> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Addons" oor:package="org.openoffice.Office"> + <node oor:name="AddonUI"> + <node oor:name="OfficeToolBar"> + <node oor:name="com.sun.star.comp.framework.addon.complextoolbarcontrols" oor:op="replace"> + <node oor:name="m1" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command1</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Image Button</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>ImageButton</value> + </prop> + </node> + <node oor:name="m2" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command2</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">ComboBox</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Combobox</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>200</value> + </prop> + </node> + <node oor:name="m3" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>private:separator</value> + </prop> + </node> + <node oor:name="m4" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command5</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Spinfield</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Spinfield</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>70</value> + </prop> + </node> + <node oor:name="m5" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>private:separator</value> + </prop> + </node> + <node oor:name="m6" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command6</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Editfield</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Editfield</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>130</value> + </prop> + </node> + <node oor:name="m7" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>private:separator</value> + </prop> + </node> + <node oor:name="m8" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command7</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Dropdownbox</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>Dropdownbox</value> + </prop> + <prop oor:name="Width" oor:type="xs:long"> + <value>80</value> + </prop> + </node> + <node oor:name="m9" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command3</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Toggle Dropdown Button</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>ToggleDropdownButton</value> + </prop> + </node> + <node oor:name="m10" oor:op="replace"> + <prop oor:name="URL" oor:type="xs:string"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command4</value> + </prop> + <prop oor:name="Title" oor:type="xs:string"> + <value xml:lang="en-US">Dropdown Button</value> + </prop> + <prop oor:name="Target" oor:type="xs:string"> + <value>_self</value> + </prop> + <prop oor:name="Context" oor:type="xs:string"> + <value>com.sun.star.text.TextDocument,com.sun.star.sheet.SpreadsheetDocument</value> + </prop> + <prop oor:name="ControlType" oor:type="xs:string"> + <value>DropdownButton</value> + </prop> + </node> + </node> + </node> + <node oor:name="Images"> + <node oor:name="vnd.demo.complextoolbarcontrols.image1" oor:op="replace"> + <prop oor:name="URL"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:Command1</value> + </prop> + <node oor:name="UserDefinedImages"> + <prop oor:name="ImageSmallURL" oor:type="xs:string"> + <value>%origin%/logo_small.png</value> + </prop> + <prop oor:name="ImageBigURL" oor:type="xs:string"> + <value>%origin%/logo_big.png</value> + </prop> + </node> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx b/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx new file mode 100644 index 000000000000..506e9c7b297e --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/CalcListener.cxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include "MyListener.h" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +void SAL_CALL CalcListener::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException) +{ +} + +void SAL_CALL CalcListener::disposing( const com::sun::star::lang::EventObject& aSource ) throw( com::sun::star::uno::RuntimeException ) +{ +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/CalcWindowState.xcu b/odk/examples/cpp/complextoolbarcontrols/CalcWindowState.xcu new file mode 100644 index 000000000000..dbb79464f8a0 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/CalcWindowState.xcu @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="CalcWindowState" oor:package="org.openoffice.Office.UI"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolbar/addon_com.sun.star.comp.framework.addon.complextoolbarcontrols" oor:op="replace"> + <prop oor:name="ContextSensitive" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">Complex Toolbar Controls</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>true</value> + </prop> + <prop oor:name="Docked" oor:type="xs:boolean"> + <value>false</value> + </prop> + </node> + </node> + </node> +</oor:component-data>
\ No newline at end of file diff --git a/odk/examples/cpp/complextoolbarcontrols/Jobs.xcu b/odk/examples/cpp/complextoolbarcontrols/Jobs.xcu new file mode 100644 index 000000000000..342b6fe3120e --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/Jobs.xcu @@ -0,0 +1,23 @@ +<?xml version='1.0' encoding='UTF-8'?> + +<oor:component-data oor:name="Jobs" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="Jobs"> + <node oor:name="DemoAddOn" oor:op="replace"> + <prop oor:name="Service"> + <value>vnd.demo.NewDocListener</value> + </prop> + </node> + </node> + <node oor:name="Events"> + <node oor:name="OnNew" oor:op="replace"> + <node oor:name="JobList"> + <node oor:name="DemoAddOn" oor:op="replace"/> + </node> + </node> + <node oor:name="OnLoad" oor:op="replace"> + <node oor:name="JobList"> + <node oor:name="DemoAddOn" oor:op="replace"/> + </node> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx new file mode 100644 index 000000000000..e0011e93d3e1 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.cxx @@ -0,0 +1,147 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include "ListenerHelper.h" + +using com::sun::star::frame::XFrame; +using com::sun::star::frame::XDispatch; +using com::sun::star::frame::XStatusListener; +using com::sun::star::lang::XEventListener; +using com::sun::star::lang::EventObject; +using com::sun::star::uno::Reference; +using com::sun::star::uno::RuntimeException; +using com::sun::star::frame::FeatureStateEvent; + +static AllListeners aListeners; + +void ListenerHelper::AddListener( + const Reference < XFrame >& xFrame, + const Reference < XStatusListener > xControl, + const ::rtl::OUString& aCommand ) +{ + sal_uInt32 i=0; + sal_uInt32 nSize = aListeners.size(); + for ( i=0; i<nSize; i++ ) + if ( aListeners[i].xFrame == xFrame ) + break; + + OSL_ENSURE( i<nSize, "No dispatch found for this listener!" ); + aListeners[i].aContainer[aCommand].push_back( xControl ); +} + +void ListenerHelper::RemoveListener( + const Reference < XFrame >& xFrame, + const Reference < XStatusListener > xControl, + const ::rtl::OUString& aCommand ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; i<nSize; i++ ) + { + if ( aListeners[i].xFrame == xFrame ) + { + StatusListeners& aL = aListeners[i].aContainer[aCommand]; + StatusListeners::iterator aIter = aL.begin(); + while ( aIter != aL.end() ) + { + if ( (*aIter) == xControl ) + { + aL.erase( aIter ); + break; + } + + aIter++; + } + } + } +} + +void ListenerHelper::Notify( + const Reference < XFrame >& xFrame, + const ::rtl::OUString& aCommand, + FeatureStateEvent& rEvent ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; i<nSize; i++ ) + { + if ( aListeners[i].xFrame == xFrame ) + { + rEvent.Source = aListeners[i].xDispatch; + StatusListeners& aL = aListeners[i].aContainer[aCommand]; + StatusListeners::iterator aIter = aL.begin(); + while ( aIter != aL.end() ) + { + (*aIter)->statusChanged( rEvent ); + aIter++; + } + } + } +} + +com::sun::star::uno::Reference < XDispatch > ListenerHelper::GetDispatch( + const Reference < XFrame >& xFrame, + const ::rtl::OUString& aCommand ) +{ + sal_uInt32 nSize = aListeners.size(); + for ( sal_uInt32 i=0; i<nSize; i++ ) + { + if ( aListeners[i].xFrame == xFrame ) + return aListeners[i].xDispatch; + } + + return Reference < XDispatch >(); +} + +void ListenerHelper::AddDispatch( + const Reference < XDispatch > xDispatch, + const Reference < XFrame >& xFrame, + const ::rtl::OUString& aCommand ) +{ + ListenerItem aItem; + aItem.xFrame = xFrame; + aItem.xDispatch = xDispatch; + aListeners.push_back( aItem ); + xFrame->addEventListener( new ListenerItemEventListener( xFrame ) ); +} + +void SAL_CALL ListenerItemEventListener::disposing( const EventObject& aEvent) throw (RuntimeException) +{ + AllListeners::iterator aIter = aListeners.begin(); + while ( aIter != aListeners.end() ) + { + if ( (*aIter).xFrame == mxFrame ) + { + aListeners.erase( aIter ); + break; + } + + aIter++; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.h b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.h new file mode 100644 index 000000000000..8aa8621ac841 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/ListenerHelper.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#include <vector> +#include <hash_map> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/FeatureStateEvent.hpp> +#include <com/sun/star/frame/XDispatch.hpp> + +#include <rtl/ustring.hxx> +#include <cppuhelper/implbase1.hxx> + +struct hashObjectName_Impl +{ + size_t operator()(const ::rtl::OUString Str) const + { + return (size_t)Str.hashCode(); + } +}; + +struct eqObjectName_Impl +{ + sal_Bool operator()(const ::rtl::OUString Str1, const ::rtl::OUString Str2) const + { + return ( Str1 == Str2 ); + } +}; + +typedef std::vector < com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > > StatusListeners; + +typedef std::hash_map +< + ::rtl::OUString, + StatusListeners, + hashObjectName_Impl, + eqObjectName_Impl +> +ListenerMap; + +// For every frame there is *one* Dispatch object for all possible commands +// this struct contains an array of listeners for every supported command +// these arrays are accessed by a hash_map (with the command string as index) +struct ListenerItem +{ + ListenerMap aContainer; + ::com::sun::star::uno::Reference< com::sun::star::frame::XDispatch > xDispatch; + ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame > xFrame; +}; + +typedef std::vector < ListenerItem > AllListeners; + +class ListenerHelper +{ +public: + void AddListener( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > xControl, + const ::rtl::OUString& aCommand ); + void RemoveListener( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const com::sun::star::uno::Reference < com::sun::star::frame::XStatusListener > xControl, + const ::rtl::OUString& aCommand ); + void Notify( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const ::rtl::OUString& aCommand, + com::sun::star::frame::FeatureStateEvent& rEvent ); + com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > GetDispatch( + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const ::rtl::OUString& aCommand ); + void AddDispatch( + const com::sun::star::uno::Reference < com::sun::star::frame::XDispatch > xDispatch, + const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame, + const ::rtl::OUString& aCommand ); +}; + +class ListenerItemEventListener : public cppu::WeakImplHelper1 < ::com::sun::star::lang::XEventListener > +{ + ::com::sun::star::uno::Reference< com::sun::star::frame::XFrame > mxFrame; +public: + ListenerItemEventListener( const com::sun::star::uno::Reference < com::sun::star::frame::XFrame >& xFrame) + : mxFrame(xFrame) + {} + virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/Makefile b/odk/examples/cpp/complextoolbarcontrols/Makefile new file mode 100644 index 000000000000..a21590d03d67 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/Makefile @@ -0,0 +1,166 @@ + #************************************************************************* +# +# The Contents of this file are made available subject to the terms of +# the BSD license. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of Sun Microsystems, Inc. nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE +# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +#************************************************************************** + +# Builds the complextoolbarcontrols C++ component example of the SDK. + +PRJ=../../.. +SETTINGS=$(PRJ)/settings + +include $(SETTINGS)/settings.mk +include $(SETTINGS)/std.mk +include $(SETTINGS)/dk.mk + +# Define non-platform/compiler specific settings +COMP_NAME=complextoolbarcontrols +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +OUT_COMP_INC=$(OUT_INC)/$(COMP_NAME) +OUT_COMP_GEN=$(OUT_MISC)/$(COMP_NAME) +OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME) +COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT) +COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)") +COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml +COMP_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map + +REGISTERFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_register_component.flag +COMP_TYPEFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_types.flag + +CXXFILES = \ + MyProtocolHandler.cxx \ + MyJob.cxx \ + MyListener.cxx \ + WriterListener.cxx \ + CalcListener.cxx \ + ListenerHelper.cxx \ + exports.cxx + +SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES)) + + +# Targets +.PHONY: ALL +ALL : \ + Example + +include $(SETTINGS)/stdtarget.mk + +$(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(CC) $(CC_FLAGS) $(STL_INCLUDES) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< + + +$(COMP_MAPFILE) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE) +ifeq "$(OS)" "MACOSX" + nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE) +endif + +ifeq "$(OS)" "WIN" +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) + -$(MKDIR) $(subst /,$(PS),$(@D)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)) + $(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \ + /MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib + $(LINK_MANIFEST) +else +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE) + -$(MKDIR) $(subst /,$(PS),$(@D)) + $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ + $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB) +ifeq "$(OS)" "MACOSX" + $(INSTALL_NAME_URELIBS) $@ +endif +endif + +# rule for component package manifest +$(OUT_COMP_GEN)/%/manifest.xml : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@ + @echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)Addons.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)WriterWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)CalcWindowState.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)ProtocolHandler.xcu$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-component;type=native;platform=$(UNOPKG_PLATFORM)$(QM)" >> $@ + @echo $(SQM) $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_GEN)/,,$(UNOPKG_PLATFORM)/$(@D))).uno.$(SHAREDLIB_EXT)$(QM)"/$(CSEP) >> $@ + @echo $(OSEP)/manifest:manifest$(CSEP) >> $@ + +# rule for component package file +$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) Addons.xcu ProtocolHandler.xcu WriterWindowState.xcu CalcWindowState.xcu $(COMP_UNOPKG_MANIFEST) + -$(MKDIR) $(subst /,$(PS),$(@D)) && $(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + -$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + $(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM)) + cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F) + $(SDK_ZIP) -u $@ Addons.xcu ProtocolHandler.xcu WriterWindowState.xcu CalcWindowState.xcu logo_small.png logo_big.png + cd $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml + +$(REGISTERFLAG) : $(COMP_PACKAGE) +ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES" + -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) + $(DEPLOYTOOL) $(COMP_PACKAGE_URL) + @echo flagged > $(subst /,$(PS),$@) +else + @echo -------------------------------------------------------------------------------- + @echo If you want to install your component automatically, please set the environment + @echo variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only + @echo possible if no office instance is running. + @echo -------------------------------------------------------------------------------- +endif + +Example : $(REGISTERFLAG) + @echo -------------------------------------------------------------------------------- + @echo The "$(QM)ProtocolHandler$(QM)" addon component was installed if SDK_AUTO_DEPLOYMENT = YES. + @echo You can use this component inside your office installation, see the example + @echo description. + @echo -------------------------------------------------------------------------------- + +run: $(COMP1_REGISTERFLAG) + "$(OFFICE_PROGRAM_PATH)$(PS)soffice" -writer + + +.PHONY: clean +clean : + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN)) + -$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) diff --git a/odk/examples/cpp/complextoolbarcontrols/MyJob.cxx b/odk/examples/cpp/complextoolbarcontrols/MyJob.cxx new file mode 100644 index 000000000000..c4a6218d4c40 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyJob.cxx @@ -0,0 +1,110 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include "MyJob.h" +#include <osl/diagnose.h> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <com/sun/star/document/XEventBroadcaster.hpp> + +using rtl::OUString; +using com::sun::star::uno::Sequence; +using com::sun::star::uno::Reference; +using com::sun::star::uno::Any; +using com::sun::star::uno::UNO_QUERY; +using com::sun::star::uno::XInterface; +using com::sun::star::uno::Exception; +using com::sun::star::uno::RuntimeException; +using com::sun::star::lang::IllegalArgumentException; +using com::sun::star::lang::XMultiServiceFactory; +using com::sun::star::beans::NamedValue; +using com::sun::star::document::XEventBroadcaster; + +Any SAL_CALL MyJob::execute( const Sequence< NamedValue >& aArguments ) + throw ( IllegalArgumentException, Exception, RuntimeException ) +{ + Reference < XEventBroadcaster > xBrd( mxMSF->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.GlobalEventBroadcaster")) ), UNO_QUERY ); + Reference < com::sun::star::document::XEventListener > xLstner( mxMSF->createInstance( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Office.MyListener")) ), UNO_QUERY ); + if ( xBrd.is() ) + xBrd->addEventListener( xLstner ); + return Any(); +} + +OUString MyJob_getImplementationName () + throw (RuntimeException) +{ + return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.comp.Office.MyJob" ) ); +} + +#define SERVICE_NAME "com.sun.star.task.Job" + +sal_Bool SAL_CALL MyJob_supportsService( const OUString& ServiceName ) + throw (RuntimeException) +{ + return ServiceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( SERVICE_NAME ) ); +} + +Sequence< OUString > SAL_CALL MyJob_getSupportedServiceNames( ) + throw (RuntimeException) +{ + Sequence < OUString > aRet(1); + OUString* pArray = aRet.getArray(); + pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( SERVICE_NAME ) ); + return aRet; +} + +#undef SERVICE_NAME + +Reference< XInterface > SAL_CALL MyJob_createInstance( const Reference< XMultiServiceFactory > & rSMgr) + throw( Exception ) +{ + return (cppu::OWeakObject*) new MyJob( rSMgr ); +} + +// XServiceInfo +OUString SAL_CALL MyJob::getImplementationName( ) + throw (RuntimeException) +{ + return MyJob_getImplementationName(); +} + +sal_Bool SAL_CALL MyJob::supportsService( const OUString& rServiceName ) + throw (RuntimeException) +{ + return MyJob_supportsService( rServiceName ); +} + +Sequence< OUString > SAL_CALL MyJob::getSupportedServiceNames( ) + throw (RuntimeException) +{ + return MyJob_getSupportedServiceNames(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyJob.h b/odk/examples/cpp/complextoolbarcontrols/MyJob.h new file mode 100644 index 000000000000..3f2989f7be80 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyJob.h @@ -0,0 +1,152 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#ifndef _MyJob_HXX + +#define _MyJob_HXX + + + +#ifndef _COM_SUN_STAR_TASK_XJOB_HPP_ + +#include <com/sun/star/task/XJob.hpp> + +#endif + +#ifndef _COM_SUN_STAR_LANG_XSERVICEINFO_HPP_ + +#include <com/sun/star/lang/XServiceInfo.hpp> + +#endif + +#ifndef _CPPUHELPER_IMPLBASE2_HXX_ + +#include <cppuhelper/implbase2.hxx> + +#endif + + + +namespace com + +{ + + namespace sun + + { + + namespace star + + { + + namespace frame + + { + + class XModel; + + class XFrame; + + } + + + + namespace beans + + { + + struct NamedValue; + + } + + } + + } + +} + + + +class MyJob : public cppu::WeakImplHelper2 + +< + + com::sun::star::task::XJob, + + com::sun::star::lang::XServiceInfo + +> + +{ + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + + + +public: + + MyJob( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF) + + : mxMSF( rxMSF ) {} + + virtual ~MyJob() {} + + + + // XJob + + virtual ::com::sun::star::uno::Any SAL_CALL execute( + + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& Arguments ) + + throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + + + // XServiceInfo + + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + + throw (::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + + throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + + throw (::com::sun::star::uno::RuntimeException); + +}; + + + +::rtl::OUString MyJob_getImplementationName() + + throw ( ::com::sun::star::uno::RuntimeException ); + + + +sal_Bool SAL_CALL MyJob_supportsService( const ::rtl::OUString& ServiceName ) + + throw ( ::com::sun::star::uno::RuntimeException ); + + + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MyJob_getSupportedServiceNames( ) + + throw ( ::com::sun::star::uno::RuntimeException ); + + + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > + +SAL_CALL MyJob_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) + + throw ( ::com::sun::star::uno::Exception ); + + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyListener.cxx b/odk/examples/cpp/complextoolbarcontrols/MyListener.cxx new file mode 100644 index 000000000000..73934563ad55 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyListener.cxx @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include "MyListener.h" +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/document/XEventBroadcaster.hpp> + +namespace css = ::com::sun::star; + +/*----------------------------------------------------- + 20.11.2003 11:31 +-----------------------------------------------------*/ +MyListener::MyListener(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) + : m_xSMGR(xSMGR) +{} + +/*----------------------------------------------------- + 20.11.2003 11:32 +-----------------------------------------------------*/ +MyListener::~MyListener() +{} + +/*----------------------------------------------------- + 20.11.2003 12:04 +-----------------------------------------------------*/ +css::uno::Any SAL_CALL MyListener::execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments) + throw (css::lang::IllegalArgumentException, + css::uno::Exception, + css::uno::RuntimeException) +{ + css::uno::Sequence< css::beans::NamedValue > lEnv; + + sal_Int32 i = 0; + sal_Int32 c = lArguments.getLength(); + const css::beans::NamedValue* p = lArguments.getConstArray(); + for (i=0; i<c; ++i) + { + if (p[i].Name.equalsAscii("Environment")) + { + p[i].Value >>= lEnv; + break; + } + } + + css::uno::Reference< css::frame::XModel > xModel; + + c = lEnv.getLength(); + p = lEnv.getConstArray(); + for (i=0; i<c; ++i) + { + if (p[i].Name.equalsAscii("Model")) + { + p[i].Value >>= xModel; + break; + } + if (p[i].Name.equalsAscii("Frame")) + { + css::uno::Reference< css::frame::XController > xController; + css::uno::Reference< css::frame::XFrame > xFrame; + p[i].Value >>= xFrame; + if (xFrame.is()) + xController = xFrame->getController(); + if (xController.is()) + xModel = xController->getModel(); + break; + } + } + + if (!xModel.is()) + return css::uno::Any(); + + css::uno::Reference< css::lang::XServiceInfo > xInfo(xModel, css::uno::UNO_QUERY); + sal_Bool bCalc = xInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadsheetDocument"))); + sal_Bool bWriter = ( + xInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument"))) && + !xInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.WebDocument"))) && + !xInfo->supportsService(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.GlobalDocument"))) + ); + + // Wir interessieren uns nur für Writer und Calc. Werden hier aber für + // alle neu geöffneten Dokumente benachrichtigt ... + if (!bCalc && !bWriter) + return css::uno::Any(); + + void* pListener = 0; + if (bCalc) + pListener = (void*)(new CalcListener(m_xSMGR)); + else + if (bWriter) + pListener = (void*)(new WriterListener(m_xSMGR)); + + css::uno::Reference< css::document::XEventListener > xDocListener (static_cast< css::document::XEventListener* >(pListener), css::uno::UNO_QUERY); + css::uno::Reference< css::document::XEventBroadcaster > xDocBroadcaster (xModel , css::uno::UNO_QUERY); + + xDocBroadcaster->addEventListener(xDocListener); + + return css::uno::Any(); +} + +/*----------------------------------------------------- + 20.11.2003 12:13 +-----------------------------------------------------*/ +::rtl::OUString SAL_CALL MyListener::getImplementationName() + throw (css::uno::RuntimeException) +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(MYLISTENER_IMPLEMENTATIONNAME)); +} + +/*----------------------------------------------------- + 20.11.2003 12:13 +-----------------------------------------------------*/ +css::uno::Sequence< ::rtl::OUString > SAL_CALL MyListener::getSupportedServiceNames() + throw (css::uno::RuntimeException) +{ + css::uno::Sequence< ::rtl::OUString > lNames(1); + lNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(MYLISTENER_SERVICENAME)); + return lNames; +} + +/*----------------------------------------------------- + 20.11.2003 12:14 +-----------------------------------------------------*/ +sal_Bool SAL_CALL MyListener::supportsService(const ::rtl::OUString& sServiceName) + throw (css::uno::RuntimeException) +{ + return ( + sServiceName.equalsAscii(MYLISTENER_SERVICENAME) || + sServiceName.equalsAscii("com.sun.star.task.Job" ) + ); +} + +/*----------------------------------------------------- + 20.11.2003 11:31 +-----------------------------------------------------*/ +css::uno::Reference< css::uno::XInterface > MyListener::st_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) +{ + MyListener* pListener = new MyListener(xSMGR); + css::uno::Reference< css::uno::XInterface > xListener(static_cast< css::task::XJob* >(pListener), css::uno::UNO_QUERY); + return xListener; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyListener.h b/odk/examples/cpp/complextoolbarcontrols/MyListener.h new file mode 100644 index 000000000000..24caa9d31d31 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyListener.h @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#ifndef _MyListener_HXX +#define _MyListener_HXX + +#include <com/sun/star/uno/Reference.h> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/task/XJob.hpp> +#include <com/sun/star/document/XEventListener.hpp> +#include <cppuhelper/implbase1.hxx> +#include <cppuhelper/implbase2.hxx> + +#define MYLISTENER_IMPLEMENTATIONNAME "vnd.My.impl.NewDocListener" +#define MYLISTENER_SERVICENAME "vnd.My.NewDocListener" + +namespace css = ::com::sun::star; + +/*--------------------------------------------------- + * Registriert sich in der Office Konfiguration als Job. + * Dieser wird dann für alle neu geöffneten Dokumente automatisch + * gerufen. Man bekommt eine Reference auf das geöffnete Dokument + * überreicht und kann dann prüfen, ob es ein unterstütztes Format + * hat. (Wir interessieren uns ja schließlich nur für Writer/Calc Dokumente.) + * + * @see CalcListener + * @see WriterListener + */ +class MyListener : public cppu::WeakImplHelper2< css::task::XJob , + css::lang::XServiceInfo > +{ + private: + css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR; + + public: + MyListener(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); + virtual ~MyListener(); + + // XJob + virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments) + throw (css::lang::IllegalArgumentException, + css::uno::Exception, + css::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName() + throw (css::uno::RuntimeException); + + virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& sServiceName) + throw (css::uno::RuntimeException); + + virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() + throw (css::uno::RuntimeException); + + public: + + static css::uno::Reference< css::uno::XInterface > st_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); +}; + +class CalcListener : public cppu::WeakImplHelper1< css::document::XEventListener > +{ + private: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + + + public: + CalcListener(const css::uno::Reference< css::lang::XMultiServiceFactory > &rxMSF) + : mxMSF( rxMSF ) + {} + + virtual ~CalcListener() + {} + + // document.XEventListener + virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent) + throw (css::uno::RuntimeException); + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) + throw (css::uno::RuntimeException); +}; + +class WriterListener : public cppu::WeakImplHelper1< css::document::XEventListener > +{ + private: + css::uno::Reference< css::lang::XMultiServiceFactory > mxMSF; + + public: + WriterListener(const css::uno::Reference< css::lang::XMultiServiceFactory >& rxMSF); + + virtual ~WriterListener() + {} + + // document.XEventListener + virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent) + throw (css::uno::RuntimeException); + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) + throw (css::uno::RuntimeException); +}; + +#endif // _MyListener_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx new file mode 100644 index 000000000000..8bec59245220 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.cxx @@ -0,0 +1,542 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include "ListenerHelper.h" +#include "MyProtocolHandler.h" +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XController.hpp> +#include <com/sun/star/frame/DispatchDescriptor.hpp> +#include <com/sun/star/text/XTextViewCursorSupplier.hpp> +#include <com/sun/star/text/XTextViewCursor.hpp> +#include <com/sun/star/text/XTextCursor.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/frame/ControlCommand.hpp> +#include <com/sun/star/frame/ControlEvent.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XControlNotificationListener.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/awt/XWindowPeer.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/XMessageBox.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/system/XSystemShellExecute.hpp> +#include <com/sun/star/system/SystemShellExecuteFlags.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/container/XContainerQuery.hpp> + +#include <osl/file.hxx> + +using namespace com::sun::star::uno; +using namespace com::sun::star::frame; +using com::sun::star::lang::XMultiServiceFactory; +using com::sun::star::beans::PropertyValue; +using com::sun::star::util::URL; +using com::sun::star::text::XTextViewCursorSupplier; +using com::sun::star::text::XTextViewCursor; +using com::sun::star::text::XTextCursor; +using com::sun::star::sheet::XSpreadsheetView; +using com::sun::star::frame::XModel; +using com::sun::star::text::XTextRange; +using com::sun::star::text::XTextDocument; +using com::sun::star::beans::NamedValue; +using namespace com::sun::star::awt; +using com::sun::star::view::XSelectionSupplier; +using namespace com::sun::star::system; + +ListenerHelper aListenerHelper; + +void BaseDispatch::ShowMessageBox( const Reference< XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText ) +{ + if ( !mxToolkit.is() ) + mxToolkit = Reference< XToolkit > ( mxMSF->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.awt.Toolkit" ))), UNO_QUERY ); + if ( rFrame.is() && mxToolkit.is() ) + { + // describe window properties. + WindowDescriptor aDescriptor; + aDescriptor.Type = WindowClass_MODALTOP; + aDescriptor.WindowServiceName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "infobox" )); + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = Reference< XWindowPeer >( rFrame->getContainerWindow(), UNO_QUERY ); + aDescriptor.Bounds = Rectangle(0,0,300,200); + aDescriptor.WindowAttributes = WindowAttribute::BORDER | WindowAttribute::MOVEABLE | WindowAttribute::CLOSEABLE; + + Reference< XWindowPeer > xPeer = mxToolkit->createWindow( aDescriptor ); + if ( xPeer.is() ) + { + Reference< XMessageBox > xMsgBox( xPeer, UNO_QUERY ); + if ( xMsgBox.is() ) + { + xMsgBox->setCaptionText( aTitle ); + xMsgBox->setMessageText( aMsgText ); + xMsgBox->execute(); + } + } + } +} + +void BaseDispatch::SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled ) +{ + Reference < XDispatch > xDispatch = + aListenerHelper.GetDispatch( mxFrame, aURL.Path ); + + FeatureStateEvent aEvent; + + aEvent.FeatureURL = aURL; + aEvent.Source = xDispatch; + aEvent.IsEnabled = bEnabled; + aEvent.Requery = sal_False; + + ControlCommand aCtrlCmd; + aCtrlCmd.Command = rCommand; + aCtrlCmd.Arguments = rArgs; + + aEvent.State <<= aCtrlCmd; + aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent ); +} + +void BaseDispatch::SendCommandTo( const Reference< XStatusListener >& xControl, const URL& aURL, const ::rtl::OUString& rCommand, const Sequence< NamedValue >& rArgs, sal_Bool bEnabled ) +{ + FeatureStateEvent aEvent; + + aEvent.FeatureURL = aURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = bEnabled; + aEvent.Requery = sal_False; + + ControlCommand aCtrlCmd; + aCtrlCmd.Command = rCommand; + aCtrlCmd.Arguments = rArgs; + + aEvent.State <<= aCtrlCmd; + xControl->statusChanged( aEvent ); +} + +void SAL_CALL MyProtocolHandler::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException) +{ + Reference < XFrame > xFrame; + if ( aArguments.getLength() ) + { + // das erste Argument ist immer der Frame, da ein ProtocolHandler den braucht um Zugriff + // auf den Context zu haben, in dem er aufgerufen wird + aArguments[0] >>= xFrame; + mxFrame = xFrame; + } +} + +Reference< XDispatch > SAL_CALL MyProtocolHandler::queryDispatch( const URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ) + throw( RuntimeException ) +{ + Reference < XDispatch > xRet; + if ( !mxFrame.is() ) + return 0; + + Reference < XController > xCtrl = mxFrame->getController(); + if ( xCtrl.is() && !aURL.Protocol.compareToAscii("vnd.demo.complextoolbarcontrols.demoaddon:") ) + { + Reference < XTextViewCursorSupplier > xCursor( xCtrl, UNO_QUERY ); + Reference < XSpreadsheetView > xView( xCtrl, UNO_QUERY ); + if ( !xCursor.is() && !xView.is() ) + // ohne ein entsprechendes Dokument funktioniert der Handler nicht + return xRet; + + if ( aURL.Path.equalsAscii("Command1" ) || + aURL.Path.equalsAscii("Command2" ) || + aURL.Path.equalsAscii("Command3" ) || + aURL.Path.equalsAscii("Command4" ) || + aURL.Path.equalsAscii("Command5" ) || + aURL.Path.equalsAscii("Command6" ) || + aURL.Path.equalsAscii("Command7" ) ) + { + xRet = aListenerHelper.GetDispatch( mxFrame, aURL.Path ); + if ( !xRet.is() ) + { + xRet = xCursor.is() ? (BaseDispatch*) new WriterDispatch( mxMSF, mxFrame ) : + (BaseDispatch*) new CalcDispatch( mxMSF, mxFrame ); + aListenerHelper.AddDispatch( xRet, mxFrame, aURL.Path ); + } + } + } + + return xRet; +} + +Sequence < Reference< XDispatch > > SAL_CALL MyProtocolHandler::queryDispatches( const Sequence < DispatchDescriptor >& seqDescripts ) + throw( RuntimeException ) +{ + sal_Int32 nCount = seqDescripts.getLength(); + Sequence < Reference < XDispatch > > lDispatcher( nCount ); + + for( sal_Int32 i=0; i<nCount; ++i ) + lDispatcher[i] = queryDispatch( seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags ); + + return lDispatcher; +} + +::rtl::OUString MyProtocolHandler_getImplementationName () + throw (RuntimeException) +{ + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(MYPROTOCOLHANDLER_IMPLEMENTATIONNAME)); +} + +sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName ) + throw (RuntimeException) +{ + return ( + ServiceName.equalsAscii(MYPROTOCOLHANDLER_SERVICENAME ) || + ServiceName.equalsAscii("com.sun.star.frame.ProtocolHandler") + ); +} + +Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames( ) + throw (RuntimeException) +{ + Sequence < ::rtl::OUString > aRet(1); + aRet[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(MYPROTOCOLHANDLER_SERVICENAME)); + return aRet; +} + +#undef SERVICE_NAME + +Reference< XInterface > SAL_CALL MyProtocolHandler_createInstance( const Reference< XMultiServiceFactory > & rSMgr) + throw( Exception ) +{ + return (cppu::OWeakObject*) new MyProtocolHandler( rSMgr ); +} + +// XServiceInfo +::rtl::OUString SAL_CALL MyProtocolHandler::getImplementationName( ) + throw (RuntimeException) +{ + return MyProtocolHandler_getImplementationName(); +} + +sal_Bool SAL_CALL MyProtocolHandler::supportsService( const ::rtl::OUString& rServiceName ) + throw (RuntimeException) +{ + return MyProtocolHandler_supportsService( rServiceName ); +} + +Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler::getSupportedServiceNames( ) + throw (RuntimeException) +{ + return MyProtocolHandler_getSupportedServiceNames(); +} + +void SAL_CALL BaseDispatch::dispatch( const URL& aURL, const Sequence < PropertyValue >& lArgs ) throw (RuntimeException) +{ + /* Its neccessary to hold this object alive, till this method finish. + May the outside dispatch cache (implemented by the menu/toolbar!) + forget this instance during de-/activation of frames (focus!). + + E.g. An open db beamer in combination with the My-Dialog + can force such strange situation :-( + */ + Reference< XInterface > xSelfHold(static_cast< XDispatch* >(this), UNO_QUERY); + + if ( !aURL.Protocol.compareToAscii("vnd.demo.complextoolbarcontrols.demoaddon:") ) + { + if ( !aURL.Path.compareToAscii("Command1" ) ) + { + // open the OpenOffice.org web page + ::rtl::OUString sURL(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://www.openoffice.org"))); + Reference< XSystemShellExecute > xSystemShellExecute( mxMSF->createInstance( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.system.SystemShellExecute"))), UNO_QUERY ); + if ( xSystemShellExecute.is() ) + { + try + + { + xSystemShellExecute->execute( sURL, ::rtl::OUString(), SystemShellExecuteFlags::DEFAULTS ); + } + catch( Exception& rEx ) + { + (void)rEx; + } + } + } + else if ( !aURL.Path.compareToAscii("Command2" ) ) + { + // remove the text if it's in our list + Sequence< NamedValue > aRemoveArgs( 1 ); + aRemoveArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )); + aRemoveArgs[0].Value <<= maComboBoxText; + SendCommand( aURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RemoveEntryText")), aRemoveArgs, sal_True ); + + // add the new text to the start of the list + Sequence< NamedValue > aInsertArgs( 2 ); + aInsertArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" )); + aInsertArgs[0].Value <<= sal_Int32( 0 ); + aInsertArgs[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Text" )); + aInsertArgs[1].Value <<= maComboBoxText; + SendCommand( aURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InsertEntry")), aInsertArgs, sal_True ); + } + else if ( !aURL.Path.compareToAscii("Command3" ) ) + { + // Retrieve the text argument from the sequence property value + rtl::OUString aText; + for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ ) + { + if ( lArgs[i].Name.equalsAsciiL( "Text", 4 )) + { + lArgs[i].Value >>= aText; + break; + } + } + + // create new URL to address the combox box + URL aCmdURL; + aCmdURL.Path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Command2")); + aCmdURL.Protocol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.demo.complextoolbarcontrols.demoaddon:")); + aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol; + + // set the selected item as text into the combobox + Sequence< NamedValue > aArgs( 1 ); + aArgs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Text")); + aArgs[0].Value <<= aText; + SendCommand( aCmdURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetText")), aArgs, sal_True ); + } + else if ( !aURL.Path.compareToAscii("Command4" ) ) + { + // Retrieve the text argument from the sequence property value + rtl::OUString aText; + for ( sal_Int32 i = 0; i < lArgs.getLength(); i++ ) + { + if ( lArgs[i].Name.equalsAsciiL( "Text", 4 )) + { + lArgs[i].Value >>= aText; + break; + } + } + + // just enable this command + + // set enable flag according to selection + if ( aText.equalsAscii( "Button Disabled" )) + mbButtonEnabled = sal_False; + else + mbButtonEnabled = sal_True; + + // create new URL to address the image button + URL aCmdURL; + aCmdURL.Path = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Command1")); + aCmdURL.Protocol = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("vnd.demo.complextoolbarcontrols.demoaddon:")); + aCmdURL.Complete = aCmdURL.Path + aCmdURL.Protocol; + + // create and initialize FeatureStateEvent with IsEnabled + ::com::sun::star::frame::FeatureStateEvent aEvent; + aEvent.FeatureURL = aCmdURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = mbButtonEnabled; + aEvent.Requery = sal_False; + aEvent.State <<= Any(); + + // Notify listener about new state + Reference < XDispatch > xDispatch = aListenerHelper.GetDispatch( mxFrame, aURL.Path ); + aListenerHelper.Notify( mxFrame, aEvent.FeatureURL.Path, aEvent ); + } + else if ( !aURL.Path.compareToAscii("Command5" ) ) + { + } + } +} + +void SAL_CALL BaseDispatch::addStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException) +{ + if ( aURL.Protocol.equalsAscii("vnd.demo.complextoolbarcontrols.demoaddon:") ) + { + if ( aURL.Path.equalsAscii("Command1" ) ) + { + // just enable this command + ::com::sun::star::frame::FeatureStateEvent aEvent; + aEvent.FeatureURL = aURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = mbButtonEnabled; + aEvent.Requery = sal_False; + aEvent.State <<= Any(); + xControl->statusChanged( aEvent ); + } + else if ( aURL.Path.equalsAscii("Command2" ) ) + { + // just enable this command + ::com::sun::star::frame::FeatureStateEvent aEvent; + aEvent.FeatureURL = aURL; + aEvent.Source = (::com::sun::star::frame::XDispatch*) this; + aEvent.IsEnabled = sal_True; + aEvent.Requery = sal_False; + aEvent.State <<= Any(); + xControl->statusChanged( aEvent ); + } + else if ( aURL.Path.equalsAscii("Command3" ) ) + { + // A toggle dropdown box is normally used for a group of commands + // where the user can select the last issued command easily. + // E.g. a typical command group would be "Insert shape" + Sequence< NamedValue > aArgs( 1 ); + + // send command to set context menu content + Sequence< rtl::OUString > aContextMenu( 3 ); + aContextMenu[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Command 1")); + aContextMenu[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Command 2")); + aContextMenu[2] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Command 3")); + + aArgs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("List")); + aArgs[0].Value <<= aContextMenu; + SendCommandTo( xControl, aURL, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetList")), aArgs, sal_True ); + + // send command to check item on pos=0 + aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" )); + aArgs[0].Value <<= sal_Int32( 0 ); + SendCommandTo( xControl, aURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CheckItemPos")), aArgs, sal_True ); + } + else if ( aURL.Path.equalsAscii("Command4" ) ) + { + // A dropdown box is normally used for a group of dependent modes, where + // the user can only select one. The modes cannot be combined. + // E.g. a typical group would be left,right,center,block. + Sequence< NamedValue > aArgs( 1 ); + + // send command to set context menu content + Sequence< rtl::OUString > aContextMenu( 2 ); + aContextMenu[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Button Enabled")); + aContextMenu[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Button Disabled")); + + aArgs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("List")); + aArgs[0].Value <<= aContextMenu; + SendCommandTo( xControl, aURL, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetList")), aArgs, sal_True ); + + // set position according to enable/disable state of button + sal_Int32 nPos( mbButtonEnabled ? 0 : 1 ); + + // send command to check item on pos=0 + aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Pos" )); + aArgs[0].Value <<= nPos; + SendCommandTo( xControl, aURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CheckItemPos")), aArgs, sal_True ); + } + else if ( aURL.Path.equalsAscii("Command5" ) ) + { + // A spin button + Sequence< NamedValue > aArgs( 5 ); + + // send command to initialize spin button + aArgs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Value")); + aArgs[0].Value <<= double( 0.0 ); + aArgs[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UpperLimit")); + aArgs[1].Value <<= double( 10.0 ); + aArgs[2].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LowerLimit")); + aArgs[2].Value <<= double( 0.0 ); + aArgs[3].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Step")); + aArgs[3].Value <<= double( 0.1 ); + aArgs[4].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OutputFormat")); + aArgs[4].Value <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%.2f cm")); + + SendCommandTo( xControl, aURL, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetValues")), aArgs, sal_True ); + } + else if ( aURL.Path.equalsAscii("Command7" ) ) + { + // A dropdown box is normally used for a group of commands + // where the user can select one of a defined set. + Sequence< NamedValue > aArgs( 1 ); + + // send command to set context menu content + Sequence< rtl::OUString > aList( 10 ); + aList[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("White")); + aList[1] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Black")); + aList[2] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Red")); + aList[3] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Blue")); + aList[4] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Green")); + aList[5] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Grey")); + aList[6] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Yellow")); + aList[7] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Orange")); + aList[8] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Brown")); + aList[9] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Pink")); + + aArgs[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("List")); + aArgs[0].Value <<= aList; + SendCommandTo( xControl, aURL, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetList")), aArgs, sal_True ); + } + + aListenerHelper.AddListener( mxFrame, xControl, aURL.Path ); + } +} + +void SAL_CALL BaseDispatch::removeStatusListener( const Reference< XStatusListener >& xControl, const URL& aURL ) throw (RuntimeException) +{ + aListenerHelper.RemoveListener( mxFrame, xControl, aURL.Path ); +} + +void SAL_CALL BaseDispatch::controlEvent( const ControlEvent& Event ) throw (RuntimeException) +{ + if ( Event.aURL.Protocol.equalsAscii("vnd.demo.complextoolbarcontrols.demoaddon:" )) + { + if ( Event.aURL.Path.equalsAscii( "Command2" )) + { + // We get notifications whenever the text inside the combobox has been changed. + // We store the new text into a member. + if ( Event.Event.equalsAscii( "TextChanged" )) + { + rtl::OUString aNewText; + sal_Bool bHasText( sal_False ); + for ( sal_Int32 i = 0; i < Event.aInformation.getLength(); i++ ) + { + if ( Event.aInformation[i].Name.equalsAsciiL( "Text", 4 )) + { + bHasText = Event.aInformation[i].Value >>= aNewText; + break; + } + } + + if ( bHasText ) + maComboBoxText = aNewText; + } + } + } +} + +BaseDispatch::BaseDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& rServiceName ) + : mxMSF( rxMSF ) + , mxFrame( xFrame ) + , msDocService( rServiceName ) + , mbButtonEnabled( sal_True ) +{ +} + + +BaseDispatch::~BaseDispatch() +{ + mxFrame.clear(); + mxMSF.clear(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h new file mode 100644 index 000000000000..747514272fed --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/MyProtocolHandler.h @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +#ifndef _MyProtocolHandler_HXX +#define _MyProtocolHandler_HXX + +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <com/sun/star/frame/XControlNotificationListener.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/NamedValue.hpp> +#include <cppuhelper/implbase3.hxx> +#ifndef _CPPUHELPER_IMPLBASE2_HXX +#include <cppuhelper/implbase2.hxx> +#endif +#include <com/sun/star/awt/XToolkit.hpp> + +#define MYPROTOCOLHANDLER_IMPLEMENTATIONNAME "vnd.demo.Impl.ProtocolHandler" +#define MYPROTOCOLHANDLER_SERVICENAME "vnd.demo.ProtocolHandler" + +namespace com +{ + namespace sun + { + namespace star + { + namespace frame + { + class XModel; + class XFrame; + } + } + } +} + + +class MyProtocolHandler : public cppu::WeakImplHelper3 +< + com::sun::star::frame::XDispatchProvider, + com::sun::star::lang::XInitialization, + com::sun::star::lang::XServiceInfo +> +{ +private: + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame; + +public: + MyProtocolHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF) + : mxMSF( rxMSF ) {} + + // XDispatchProvider + virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > + SAL_CALL queryDispatch( const ::com::sun::star::util::URL& aURL, + const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags ) + throw( ::com::sun::star::uno::RuntimeException ); + virtual ::com::sun::star::uno::Sequence < ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > > + SAL_CALL queryDispatches( + const ::com::sun::star::uno::Sequence < ::com::sun::star::frame::DispatchDescriptor >& seqDescriptor ) + throw( ::com::sun::star::uno::RuntimeException ); + + // XInitialization + virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + + // XServiceInfo + virtual ::rtl::OUString SAL_CALL getImplementationName( ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) + throw (::com::sun::star::uno::RuntimeException); +}; + +::rtl::OUString MyProtocolHandler_getImplementationName() + throw ( ::com::sun::star::uno::RuntimeException ); + +sal_Bool SAL_CALL MyProtocolHandler_supportsService( const ::rtl::OUString& ServiceName ) + throw ( ::com::sun::star::uno::RuntimeException ); + +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL MyProtocolHandler_getSupportedServiceNames( ) + throw ( ::com::sun::star::uno::RuntimeException ); + +::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > +SAL_CALL MyProtocolHandler_createInstance( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & rSMgr) + throw ( ::com::sun::star::uno::Exception ); + +class BaseDispatch : public cppu::WeakImplHelper2 +< + ::com::sun::star::frame::XDispatch, + ::com::sun::star::frame::XControlNotificationListener +> +{ +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > mxFrame; + ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxMSF; + ::com::sun::star::uno::Reference< ::com::sun::star::awt::XToolkit > mxToolkit; + ::rtl::OUString msDocService; + ::rtl::OUString maComboBoxText; + sal_Bool mbButtonEnabled; + +public: + BaseDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame, const ::rtl::OUString& rServiceName ); + + virtual ~BaseDispatch(); + + void ShowMessageBox( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& rFrame, const ::rtl::OUString& aTitle, const ::rtl::OUString& aMsgText ); + void SendCommand( const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rArgs, sal_Bool bEnabled ); + void SendCommandTo( const com::sun::star::uno::Reference< com::sun::star::frame::XStatusListener >& xControl, const com::sun::star::util::URL& aURL, const ::rtl::OUString& rCommand, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::NamedValue >& rArgs, sal_Bool bEnabled ); + + // XDispatch + virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& lArgs ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, + const ::com::sun::star::util::URL& aURL ) throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeStatusListener( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XStatusListener >& xControl, + const ::com::sun::star::util::URL& aURL ) throw (::com::sun::star::uno::RuntimeException); + + // XControlNotificationListener + virtual void SAL_CALL controlEvent( const ::com::sun::star::frame::ControlEvent& Event ) + throw (::com::sun::star::uno::RuntimeException); +}; + +class WriterDispatch : public BaseDispatch +{ +public: + WriterDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) + : BaseDispatch( rxMSF, xFrame, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextDocument" ) ) ) + {} +}; + +class CalcDispatch : public BaseDispatch +{ +public: + CalcDispatch( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF, + const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& xFrame ) + : BaseDispatch( rxMSF, xFrame, ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sheet.SpreadSheetDocument" ) ) ) + {} +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/ProtocolHandler.xcu b/odk/examples/cpp/complextoolbarcontrols/ProtocolHandler.xcu new file mode 100644 index 000000000000..3bab74410a24 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/ProtocolHandler.xcu @@ -0,0 +1,10 @@ +<?xml version='1.0' encoding='UTF-8'?> +<oor:component-data oor:name="ProtocolHandler" oor:package="org.openoffice.Office" xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <node oor:name="HandlerSet"> + <node oor:name="vnd.demo.ProtocolHandler" oor:op="replace"> + <prop oor:name="Protocols" oor:type="oor:string-list"> + <value>vnd.demo.complextoolbarcontrols.demoaddon:*</value> + </prop> + </node> + </node> +</oor:component-data> diff --git a/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx b/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx new file mode 100644 index 000000000000..a45e217248d6 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/WriterListener.cxx @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include "MyListener.h" + + +#include <com/sun/star/lang/XMultiServiceFactory.hpp> + +void SAL_CALL WriterListener::notifyEvent( const ::com::sun::star::document::EventObject& aEvent ) throw (com::sun::star::uno::RuntimeException) +{ +} + +void SAL_CALL WriterListener::disposing( const com::sun::star::lang::EventObject& aSource ) throw( com::sun::star::uno::RuntimeException ) +{ +} + +WriterListener::WriterListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > &rxMSF) + : mxMSF( rxMSF ) +{ +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/WriterWindowState.xcu b/odk/examples/cpp/complextoolbarcontrols/WriterWindowState.xcu new file mode 100644 index 000000000000..fd5453eba348 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/WriterWindowState.xcu @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="WriterWindowState" oor:package="org.openoffice.Office.UI"> + <node oor:name="UIElements"> + <node oor:name="States"> + <node oor:name="private:resource/toolbar/addon_com.sun.star.comp.framework.addon.complextoolbarcontrols" oor:op="replace"> + <prop oor:name="ContextSensitive" oor:type="xs:boolean"> + <value>false</value> + </prop> + <prop oor:name="UIName" oor:type="xs:string"> + <value xml:lang="en-US">Complex Toolbar Controls</value> + </prop> + <prop oor:name="Visible" oor:type="xs:boolean"> + <value>true</value> + </prop> + <prop oor:name="Docked" oor:type="xs:boolean"> + <value>false</value> + </prop> + </node> + </node> + </node> +</oor:component-data>
\ No newline at end of file diff --git a/odk/examples/cpp/complextoolbarcontrols/exports.cxx b/odk/examples/cpp/complextoolbarcontrols/exports.cxx new file mode 100644 index 000000000000..34e54f5fc3e8 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/exports.cxx @@ -0,0 +1,123 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + + +#include <stdio.h> + +#include <osl/mutex.hxx> +#include <osl/thread.h> +#include <cppuhelper/factory.hxx> +#include <rtl/ustring.hxx> +#include <rtl/ustrbuf.hxx> +#include <sal/types.h> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> + +#include "MyProtocolHandler.h" +#include "MyListener.h" + +namespace css = ::com::sun::star; + +static void writeInfo(const css::uno::Reference< css::registry::XRegistryKey >& xRegistryKey , + const char* pImplementationName, + const char* pServiceName ) +{ + ::rtl::OUStringBuffer sKey(256); + sKey.append (::rtl::OUString::createFromAscii(pImplementationName)); + sKey.appendAscii("/UNO/SERVICES/"); + sKey.append (::rtl::OUString::createFromAscii(pServiceName)); + + xRegistryKey->createKey(sKey.makeStringAndClear()); +} + +extern "C" +{ +//================================================================================================== +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char** ppEnvTypeName, + uno_Environment** ppEnv ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} + +//================================================================================================== +SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void* pServiceManager, + void* pRegistryKey ) +{ + if (!pRegistryKey) + return sal_False; + + try + { + css::uno::Reference< css::registry::XRegistryKey > xKey(reinterpret_cast< css::registry::XRegistryKey* >(pRegistryKey), css::uno::UNO_QUERY); + + writeInfo( xKey, MYLISTENER_IMPLEMENTATIONNAME , MYLISTENER_SERVICENAME ); + writeInfo( xKey, MYPROTOCOLHANDLER_IMPLEMENTATIONNAME, MYPROTOCOLHANDLER_SERVICENAME ); + + return sal_True; + } + catch(const css::registry::InvalidRegistryException&) + { OSL_ENSURE( sal_False, "### InvalidRegistryException!" ); } + + return sal_False; +} + +//================================================================================================== +SAL_DLLPUBLIC_EXPORT void* SAL_CALL component_getFactory(const sal_Char* pImplName , + void* pServiceManager, + void* pRegistryKey ) +{ + if ( !pServiceManager || !pImplName ) + return 0; + + css::uno::Reference< css::lang::XSingleServiceFactory > xFactory ; + css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR (reinterpret_cast< css::lang::XMultiServiceFactory* >(pServiceManager), css::uno::UNO_QUERY); + ::rtl::OUString sImplName = ::rtl::OUString::createFromAscii(pImplName); + + if (sImplName.equalsAscii(MYLISTENER_IMPLEMENTATIONNAME)) + { + css::uno::Sequence< ::rtl::OUString > lNames(1); + lNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(MYLISTENER_IMPLEMENTATIONNAME)); + xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyListener::st_createInstance, lNames); + } + else + if (sImplName.equalsAscii(MYPROTOCOLHANDLER_IMPLEMENTATIONNAME)) + { + css::uno::Sequence< ::rtl::OUString > lNames(1); + lNames[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(MYPROTOCOLHANDLER_SERVICENAME)); + xFactory = ::cppu::createSingleFactory(xSMGR, sImplName, MyProtocolHandler_createInstance, lNames); + } + + if (!xFactory.is()) + return 0; + + xFactory->acquire(); + return xFactory.get(); +} + +} // extern C + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/odk/examples/cpp/complextoolbarcontrols/logo_big.png b/odk/examples/cpp/complextoolbarcontrols/logo_big.png Binary files differnew file mode 100644 index 000000000000..23dd24109dc6 --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/logo_big.png diff --git a/odk/examples/cpp/complextoolbarcontrols/logo_small.png b/odk/examples/cpp/complextoolbarcontrols/logo_small.png Binary files differnew file mode 100644 index 000000000000..c24b4e27554b --- /dev/null +++ b/odk/examples/cpp/complextoolbarcontrols/logo_small.png |