diff options
Diffstat (limited to 'sd/source/ui/inc/tools')
-rw-r--r-- | sd/source/ui/inc/tools/AsynchronousCall.hxx | 92 | ||||
-rwxr-xr-x | sd/source/ui/inc/tools/AsynchronousTask.hxx | 55 | ||||
-rw-r--r-- | sd/source/ui/inc/tools/ConfigurationAccess.hxx | 152 | ||||
-rwxr-xr-x | sd/source/ui/inc/tools/IconCache.hxx | 79 | ||||
-rw-r--r-- | sd/source/ui/inc/tools/IdleDetection.hxx | 91 | ||||
-rwxr-xr-x | sd/source/ui/inc/tools/PropertySet.hxx | 150 | ||||
-rwxr-xr-x | sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx | 108 | ||||
-rwxr-xr-x | sd/source/ui/inc/tools/SlotStateListener.hxx | 160 | ||||
-rwxr-xr-x | sd/source/ui/inc/tools/TimerBasedTaskExecution.hxx | 99 |
9 files changed, 986 insertions, 0 deletions
diff --git a/sd/source/ui/inc/tools/AsynchronousCall.hxx b/sd/source/ui/inc/tools/AsynchronousCall.hxx new file mode 100644 index 000000000000..e123afaa06fe --- /dev/null +++ b/sd/source/ui/inc/tools/AsynchronousCall.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 SD_ASYNCHRONOUS_CALL_HXX +#define SD_ASYNCHRONOUS_CALL_HXX + +#include <vcl/timer.hxx> +#include <memory> +#include <boost/function.hpp> + +namespace sd { namespace tools { + + +/** Store a function object and execute it asynchronous. + + The features of this class are: + a) It provides a wrapper around a VCL Timer so that generic function + objects can be used. + b) When more than one function objects are posted to be executed later + then the pending ones are erased and only the last one will actually be + executed. + + Use this class like this: + aInstanceOfAsynchronousCall.Post( + ::boost::bind( + ::std::mem_fun(&DrawViewShell::SwitchPage), + pDrawViewShell, + 11)); +*/ +class AsynchronousCall +{ +public: + /** Create a new asynchronous call. Each object of this class processes + one (semantical) type of call. + */ + AsynchronousCall (void); + + ~AsynchronousCall (void); + + /** Post a function object that is to be executed asynchronously. When + this method is called while the current function object has not bee + executed then the later is destroyed and only the given function + object will be executed. + @param rFunction + The function object that may be called asynchronously in the + near future. + @param nTimeoutInMilliseconds + The timeout in milliseconds until the function object is + executed. + */ + typedef ::boost::function0<void> AsynchronousFunction; + void Post ( + const AsynchronousFunction& rFunction, + sal_uInt32 nTimeoutInMilliseconds=10); + +private: + Timer maTimer; + /** The function object that will be executed when the TimerCallback + function is called the next time. This pointer may be NULL. + */ + ::std::auto_ptr<AsynchronousFunction> mpFunction; + DECL_LINK(TimerCallback,Timer*); +}; + + +} } // end of namespace ::sd::tools + +#endif diff --git a/sd/source/ui/inc/tools/AsynchronousTask.hxx b/sd/source/ui/inc/tools/AsynchronousTask.hxx new file mode 100755 index 000000000000..f3135d3fcce7 --- /dev/null +++ b/sd/source/ui/inc/tools/AsynchronousTask.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 SD_ASYNCHRONOUS_TASK_HXX +#define SD_ASYNCHRONOUS_TASK_HXX + +namespace sd { namespace tools { + +/** Interface for the asynchronous execution of a task. This interface + allows an controller to run the task either timer based with a fixed + amount of time between the steps or thread based one step right after + the other. +*/ +class AsynchronousTask +{ +public: + /** Run the next step of the task. After HasNextStep() returns false + this method should ignore further calls. + */ + virtual void RunNextStep (void) = 0; + + /** Return <TRUE/> when there is at least one more step to execute. + When the task has been executed completely then <FALSE/> is + returned. + */ + virtual bool HasNextStep (void) = 0; +}; + +} } // end of namespace ::sd::tools + +#endif diff --git a/sd/source/ui/inc/tools/ConfigurationAccess.hxx b/sd/source/ui/inc/tools/ConfigurationAccess.hxx new file mode 100644 index 000000000000..953012dfa668 --- /dev/null +++ b/sd/source/ui/inc/tools/ConfigurationAccess.hxx @@ -0,0 +1,152 @@ +/************************************************************************* + * + * 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 SD_TOOLS_CONFIGURATION_ACCESS_HXX +#define SD_TOOLS_CONFIGURATION_ACCESS_HXX + +#include <rtl/ustring.hxx> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <vector> +#include <boost/function.hpp> + +namespace css = ::com::sun::star; + +namespace sd { namespace tools { + +/** This class gives access to the configuration. Create an object of this + class for one node of the configuration. This will be the root node. + Its children are then accessible through the new ConfigurationAccess + object. +*/ +class ConfigurationAccess +{ +public: + enum WriteMode { READ_WRITE, READ_ONLY }; + + /** Create a new object to access the configuration entries below the + given root. + @param rsRootName + Name of the root. + @param eMode + This flag specifies whether to give read-write or read-only + access. + */ + ConfigurationAccess( + const ::rtl::OUString& rsRootName, + const WriteMode eMode); + + ConfigurationAccess( + const css::uno::Reference<css::uno::XComponentContext>& rxContext, + const ::rtl::OUString& rsRootName, + const WriteMode eMode); + + /** Return a configuration node below the root of the called object. + @param rsPathToNode + The relative path from the root (as given the constructor) to + the node. + @return + The type of the returned node varies with the requested node. + It is empty when the node was not found. + */ + css::uno::Any GetConfigurationNode ( + const ::rtl::OUString& rsPathToNode); + + /** Return a configuration node below the given node. + @param rxNode + The node that acts as root to the given relative path. + @param rsPathToNode + The relative path from the given node to the requested node. + @return + The type of the returned node varies with the requested node. + It is empty when the node was not found. + */ + static css::uno::Any GetConfigurationNode ( + const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode, + const ::rtl::OUString& rsPathToNode); + + /** Write any changes that have been made back to the configuration. + This call is ignored when the called ConfigurationAccess object was + not create with read-write mode. + */ + void CommitChanges (void); + + /** This functor is typically called for every item in a set. Its two + parameters are the name of key item (often of no further interest) + and the value of the item. + */ + typedef ::boost::function<void( + const ::rtl::OUString&, + const std::vector<css::uno::Any>&) > Functor; + + /** Execute a functor for all elements of the given container. + @param rxContainer + The container is a XNameAccess to a list of the configuration. + This can be a node returned by GetConfigurationNode(). + @param rArguments + The functor is called with arguments that are children of each + element of the container. The set of children is specified this + list. + @param rFunctor + The functor to be executed for some or all of the elements in + the given container. + */ + static void ForAll ( + const css::uno::Reference<css::container::XNameAccess>& rxContainer, + const ::std::vector<rtl::OUString>& rArguments, + const Functor& rFunctor); + + /** Fill a list with the string contents of all sub-elements in the given container. + @param rxContainer + The container is a XNameAccess to a list of the configuration. + This can be a node returned by GetConfigurationNode(). + @param rsArgument + This specifies which string children of the elements in the + container are to be inserted into the list. The specified child + has to be of type string. + @param rList + The list to be filled. + */ + static void FillList( + const css::uno::Reference<css::container::XNameAccess>& rxContainer, + const ::rtl::OUString& rsArgument, + ::std::vector<rtl::OUString>& rList); + +private: + css::uno::Reference<css::uno::XInterface> mxRoot; + + void Initialize ( + const css::uno::Reference<css::lang::XMultiServiceFactory>& rxProvider, + const ::rtl::OUString& rsRootName, + const WriteMode eMode); +}; + +} } // end of namespace sd::tools + +#endif diff --git a/sd/source/ui/inc/tools/IconCache.hxx b/sd/source/ui/inc/tools/IconCache.hxx new file mode 100755 index 000000000000..b0619ea4b2d7 --- /dev/null +++ b/sd/source/ui/inc/tools/IconCache.hxx @@ -0,0 +1,79 @@ +/************************************************************************* + * + * 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 SD_ICON_CACHE_HXX +#define SD_ICON_CACHE_HXX + +#include "SdGlobalResourceContainer.hxx" +#include <vcl/image.hxx> + +namespace sd { + +/** This simple class stores frequently used icons so that the classes that + use the icons do not have to store them in every one of their + instances. + + Icons are adressed over their resource id and are loaded on demand. + + This cache acts like a singleton with a lifetime equal to that of the sd + module. +*/ +class IconCache + : public SdGlobalResource +{ +public: + /** The lifetime of the returned reference is limited to that of the sd + module. + */ + static IconCache& Instance (void); + + /** Return the icon with the given resource id. + @return + The returned Image may be empty when there is no icon for the + given id or an error occured. Should not happen under normal + circumstances. + */ + Image GetIcon (sal_uInt16 nResourceId); + +private: + class Implementation; + ::std::auto_ptr<Implementation> mpImpl; + + /** The constructor creates the one instance of the cache and registers + it at the SdGlobalResourceContainer to limit is lifetime to that of + the sd module. + */ + IconCache (void); + + /** This destructor is called by SdGlobalResourceContainer. + */ + virtual ~IconCache (void); +}; + +} // end of namespace sd + +#endif diff --git a/sd/source/ui/inc/tools/IdleDetection.hxx b/sd/source/ui/inc/tools/IdleDetection.hxx new file mode 100644 index 000000000000..3369dc1dd177 --- /dev/null +++ b/sd/source/ui/inc/tools/IdleDetection.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 SD_IDLE_DETECTION_HXX +#define SD_IDLE_DETECTION_HXX + +#include <sal/types.h> + +class Window; + +namespace sd { namespace tools { + +/** Detect whether the system is idle and some time consuming operation may + be carried out. This class ditinguishes between different states of + idle-ness. +*/ +class IdleDetection +{ +public: + /** When GetIdleState() returns this value, then the system is idle. + */ + static const sal_Int32 IDET_IDLE = 0x0000; + + /** There are system event pending. + */ + static const sal_Int32 IDET_SYSTEM_EVENT_PENDING = 0x0001; + + /** A full screen slide show is running and is active. In contrast + there may be a full screen show be running in an inactive window, + i.e. in the background. + */ + static const sal_Int32 IDET_FULL_SCREEN_SHOW_ACTIVE = 0x0002; + + /** A slide show is running in a window. + */ + static const sal_Int32 IDET_WINDOW_SHOW_ACTIVE = 0x0004; + + /** A window is being painted. + */ + static const sal_Int32 IDET_WINDOW_PAINTING = 0x0008; + + /** Determine whether the system is idle. + @param pWindow + When a valid Window pointer is given then it is checked + whether the window is currently being painting. + @return + This method either returns IDET_IDLE or a combination of + IdleStates values or-ed together that describe what the system + is currently doing so that the caller can decide what to do. + */ + static sal_Int32 GetIdleState (const ::Window* pWindow = NULL); + +private: + /** Check whether there are input events pending. + */ + static sal_Int32 CheckInputPending (void); + + /** Check whether a slide show is running full screen or in a window. + */ + static sal_Int32 CheckSlideShowRunning (void); + + static sal_Int32 CheckWindowPainting (const ::Window& rWindow); +}; + +} } // end of namespace ::sd::tools + +#endif diff --git a/sd/source/ui/inc/tools/PropertySet.hxx b/sd/source/ui/inc/tools/PropertySet.hxx new file mode 100755 index 000000000000..998b4f0e2142 --- /dev/null +++ b/sd/source/ui/inc/tools/PropertySet.hxx @@ -0,0 +1,150 @@ +/************************************************************************* + * + * 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 SD_TOOLS_PROPERTY_SET_HXX +#define SD_TOOLS_PROPERTY_SET_HXX + +#include <cppuhelper/basemutex.hxx> +#include <cppuhelper/compbase1.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <boost/scoped_ptr.hpp> +#include <map> + +namespace css = ::com::sun::star; + +namespace sd { namespace tools { + +namespace { + typedef ::cppu::WeakComponentImplHelper1 < + css::beans::XPropertySet + > PropertySetInterfaceBase; +} + + +/** A very simple implementation of the XPropertySet interface. It does not + support constrained properties and thus does not support vetoable + listeners. It does not support the optional property set info. + + In order to use it you have to derive from this class and implement the + GetPropertyValue() and SetPropertyValue() methods. +*/ +class PropertySet + : protected ::cppu::BaseMutex, + public PropertySetInterfaceBase +{ +public: + explicit PropertySet (void); + virtual ~PropertySet (void); + + virtual void SAL_CALL disposing (void); + + // XPropertySet + + virtual css::uno::Reference<css::beans::XPropertySetInfo> + SAL_CALL getPropertySetInfo (void) + throw(css::uno::RuntimeException); + + virtual void SAL_CALL setPropertyValue ( + const rtl::OUString& rsPropertyName, + const css::uno::Any& rsPropertyValue) + throw(css::beans::UnknownPropertyException, + css::beans::PropertyVetoException, + css::lang::IllegalArgumentException, + css::lang::WrappedTargetException, + css::uno::RuntimeException); + + virtual css::uno::Any SAL_CALL getPropertyValue (const rtl::OUString& rsPropertyName) + throw(css::beans::UnknownPropertyException, + css::lang::WrappedTargetException, + css::uno::RuntimeException); + + virtual void SAL_CALL addPropertyChangeListener ( + const rtl::OUString& rsPropertyName, + const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener) + throw(css::beans::UnknownPropertyException, + css::lang::WrappedTargetException, + css::uno::RuntimeException); + + virtual void SAL_CALL removePropertyChangeListener ( + const rtl::OUString& rsPropertyName, + const css::uno::Reference<css::beans::XPropertyChangeListener>& rxListener) + throw(css::beans::UnknownPropertyException, + css::lang::WrappedTargetException, + css::uno::RuntimeException); + + virtual void SAL_CALL addVetoableChangeListener ( + const rtl::OUString& rsPropertyName, + const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener) + throw(css::beans::UnknownPropertyException, + css::lang::WrappedTargetException, + css::uno::RuntimeException); + + virtual void SAL_CALL removeVetoableChangeListener ( + const rtl::OUString& rsPropertyName, + const css::uno::Reference<css::beans::XVetoableChangeListener>& rxListener) + throw(css::beans::UnknownPropertyException, + css::lang::WrappedTargetException, + css::uno::RuntimeException); + +protected: + /** Return the requested property value. + @throw com::sun::star::beans::UnknownPropertyException when the + property is not supported. + */ + virtual css::uno::Any GetPropertyValue (const ::rtl::OUString& rsPropertyName) = 0; + /** Set the given property value. + @return the old value. + @throw com::sun::star::beans::UnknownPropertyException when the + property is not supported. + */ + virtual css::uno::Any SetPropertyValue ( + const ::rtl::OUString& rsPropertyName, + const css::uno::Any& rValue) = 0; + +private: + typedef ::std::multimap<rtl::OUString, + css::uno::Reference<css::beans::XPropertyChangeListener> > ChangeListenerContainer; + ::boost::scoped_ptr<ChangeListenerContainer> mpChangeListeners; + + /** Call all listeners that are registered for the given property name. + Call this method with an empty property name to call listeners that + are registered for all properties. + */ + void CallListeners ( + const rtl::OUString& rsPropertyName, + const css::beans::PropertyChangeEvent& rEvent); + + /** This method throws a DisposedException when the object has already been + disposed. + */ + void ThrowIfDisposed (void) + throw (css::lang::DisposedException); +}; + +} } // end of namespace ::sd::tools + +#endif diff --git a/sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx b/sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx new file mode 100755 index 000000000000..d0661a61636b --- /dev/null +++ b/sd/source/ui/inc/tools/SdGlobalResourceContainer.hxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * 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 SD_GLOBAL_RESOURCE_CONTAINER_HXX +#define SD_GLOBAL_RESOURCE_CONTAINER_HXX + +#include "sdmod.hxx" +#include <memory> +#include <boost/shared_ptr.hpp> +#include <com/sun/star/uno/XInterface.hpp> + +namespace css = ::com::sun::star; + +namespace sd { + +class SdGlobalResource +{ +public: + virtual ~SdGlobalResource (void) {}; +}; + +/** The purpose of this container is to hold references to resources that + are globally available to all interested objects and to destroy them + when the sd module is destroyed. Examples for resources can be + containers of bitmaps or the container of master pages used by the + MasterPagesSelector objects in the task panel. + + It works like a singleton in that there is one instance per sd module. + Resources can be added (by themselves or their owners) to the + container. The main task of the container is the destruction of all + resources that have been added to it. + + As you may note, there is no method to get a resource from the + container. It is the task of the resource to provide other means of + access to it. + + The reason for this design is not to have to change the SdModule + destructor every time when there is a new resource. This is done by + reversing the dependency between module and resource: the resource knows + about the module--this container class to be more precisely--and tells + it to destroy the resource when the sd module is at the end of its + lifetime. +*/ +class SdGlobalResourceContainer +{ +public: + static SdGlobalResourceContainer& Instance (void); + + /** Add a resource to the container. The ownership of the resource is + transferred to the container. The resource is destroyed when the + container is destroyed, i.e. when the sd module is destroyed. + + When in doubt, use the shared_ptr variant of this method. + */ + void AddResource (::std::auto_ptr<SdGlobalResource> pResource); + + /** Add a resource to the container. By using a shared_ptr and + releasing it only when the SgGlobalResourceContainer is destroyed + the given resource is kept alive at least that long. When at the + time of the destruction of SgGlobalResourceContainer no other + references exist the resource is destroyed as well. + */ + void AddResource (::boost::shared_ptr<SdGlobalResource> pResource); + + /** Add a resource that is implemented as UNO object. Destruction + (when the sd modules is unloaded) is done by a) calling dispose() + when the XComponent is supported and by b) releasing the reference. + */ + void AddResource (const ::css::uno::Reference<css::uno::XInterface>& rxResource); + +protected: + friend class ::SdModule; + friend class ::std::auto_ptr<SdGlobalResourceContainer>; + + class Implementation; + ::std::auto_ptr<Implementation> mpImpl; + + SdGlobalResourceContainer (void); + ~SdGlobalResourceContainer (void); +}; + +} // end of namespace sd + +#endif diff --git a/sd/source/ui/inc/tools/SlotStateListener.hxx b/sd/source/ui/inc/tools/SlotStateListener.hxx new file mode 100755 index 000000000000..1f45aef331ab --- /dev/null +++ b/sd/source/ui/inc/tools/SlotStateListener.hxx @@ -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. + * + ************************************************************************/ + +#ifndef SD_TOOLS_SLOT_STATE_LISTENER_HXX +#define SD_TOOLS_SLOT_STATE_LISTENER_HXX + +#include "MutexOwner.hxx" +#include <com/sun/star/frame/XStatusListener.hpp> +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/FeatureStateEvent.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTIOIN_HPP_ +#include <com/sun/star/lang/DisposedException.hpp> +#endif +#include <com/sun/star/lang/XComponent.hpp> +#include <cppuhelper/compbase1.hxx> +#include <tools/link.hxx> + +namespace sd { namespace tools { + + +typedef cppu::WeakComponentImplHelper1< + ::com::sun::star::frame::XStatusListener + > SlotStateListenerInterfaceBase; + + +/** Listen for state changes of slots. This class has been created in order + to be informed when the support for vertical writing changes but it can + be used to relay state changes of other slots as well. +*/ +class SlotStateListener + : protected MutexOwner, + public SlotStateListenerInterfaceBase +{ +public: + /** This convenience version of the constructor takes all parameters + that are necessary to observe a single slot. See descriptions of + the SetCallback(), ConnectToFrame(), and ObserveSlot() methods for + explanations about the parameters. + */ + SlotStateListener ( + Link& rCallback, + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatchProvider>& rxDispatchProvider, + const ::rtl::OUString& rSlotName); + + /** The constructor de-registers all remaining listeners. Usually a prior + dispose() call should have done that already. + */ + virtual ~SlotStateListener (void); + + /** Set the callback to the given value. Whenever one of the observed + slots changes its state this callback is informed about it. + Changing the callback does not release the listeners. + @throws DisposedException + */ + void SetCallback (const Link& rCallback); + + /** Set the frame whose slots shall be observed. When an object of this + class is already observing slots of another frame then these + listeners are released first. + @throws DisposedException + */ + void ConnectToDispatchProvider ( + const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XDispatchProvider>& rxDispatchProvider); + + /** Observe the slot specified by the given name. Note that + ConnectToFrame() has to have been called earlier. + @param rSlotName + The name of the slot to observe. An example is + ".uno:VerticalTextState". + @throws DisposedException + */ + void ObserveSlot (const ::rtl::OUString& rSlotName); + + //===== frame::XStatusListener ========================================== + + /** Called by slot state change broadcasters. In turn the callback is + informed about the state chage. + @throws DisposedException + */ + virtual void SAL_CALL + statusChanged ( + const ::com::sun::star::frame::FeatureStateEvent& rState) + throw (::com::sun::star::uno::RuntimeException); + + //===== lang::XEventListener ============================================ + + virtual void SAL_CALL + disposing(const com::sun::star::lang::EventObject& rEvent) + throw(com::sun::star::uno::RuntimeException); + +protected: + /** This method is called by the WeakComponentImplHelper base class in + reaction to a XComponent::dispose() call. It releases all currently + active listeners. + */ + virtual void SAL_CALL disposing (void); + +private: + Link maCallback; + + /** Remember the URLs that describe slots whose state changes we are + listening to. + */ + typedef ::std::vector<com::sun::star::util::URL> RegisteredURLList; + RegisteredURLList maRegisteredURLList; + + ::com::sun::star::uno::WeakReference< + ::com::sun::star::frame::XDispatchProvider> mxDispatchProviderWeak; + + /** Deregister all currently active state change listeners. + */ + void ReleaseListeners (void); + + /** This method throws a DisposedException when the object has already been + disposed. + */ + void ThrowIfDisposed (void) + throw (::com::sun::star::lang::DisposedException); + + /** Transform the given string into a URL object. + */ + ::com::sun::star::util::URL MakeURL (const ::rtl::OUString& rSlotName) const; + + /** Return an XDispatch object for the given URL. + */ + ::com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> + GetDispatch ( + const ::com::sun::star::util::URL& rURL) const; +}; + +} } // end of namespace ::sd::tools + +#endif diff --git a/sd/source/ui/inc/tools/TimerBasedTaskExecution.hxx b/sd/source/ui/inc/tools/TimerBasedTaskExecution.hxx new file mode 100755 index 000000000000..33ec3ccd9993 --- /dev/null +++ b/sd/source/ui/inc/tools/TimerBasedTaskExecution.hxx @@ -0,0 +1,99 @@ +/************************************************************************* + * + * 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 SD_TIMER_BASED_TASK_EXECUTION_HXX +#define SD_TIMER_BASED_TASK_EXECUTION_HXX + +#include <vcl/timer.hxx> + +#include <boost/shared_ptr.hpp> + +namespace sd { namespace tools { + +class AsynchronousTask; + +/** Execute an AsynchronousTask timer based, i.e. every + nMillisecondsBetweenSteps milliseconds as much steps are executed as fit + into a nMaxTimePerStep millisecond intervall. + + When a task is executed completely, i.e. HasNextStep() returns <FALSE/>, + the TimerBasedTaskExecution destroys itself. This, of course, works + only if the creating instance does not hold a shared_ptr to that object. +*/ +class TimerBasedTaskExecution +{ +public: + /** Create a new object of this class. + @param rpTask + The AsynchronousTask that is to be executed. + @param nMillisecondsBetweenSteps + Wait at least this long between the execution of steps. Note + that more than one step may be executed in succession. + @param nMaxTimePerStep + The maximal time for executing steps without yielding control. + */ + static ::boost::shared_ptr<TimerBasedTaskExecution> Create ( + const ::boost::shared_ptr<AsynchronousTask>& rpTask, + sal_uInt32 nMillisecondsBetweenSteps, + sal_uInt32 nMaxTimePerStep); + + /** Stop the execution of the task and release the shared pointer to + itself so that it will eventually be destroyed. + */ + void Release (void); + + /** Convenience method that calls Release() on the given task. It + checks the given weak_ptr for being expired and catches bad_weak_ptr + exceptions. + */ + static void ReleaseTask (const ::boost::weak_ptr<TimerBasedTaskExecution>& rpTask); + +private: + ::boost::shared_ptr<AsynchronousTask> mpTask; + Timer maTimer; + /** This shared_ptr to this is used to destroy a TimerBasedTaskExecution + object when its task has been executed completely. + */ + ::boost::shared_ptr<TimerBasedTaskExecution> mpSelf; + sal_uInt32 mnMaxTimePerStep; + + TimerBasedTaskExecution ( + const ::boost::shared_ptr<AsynchronousTask>& rpTask, + sal_uInt32 nMillisecondsBetweenSteps, + sal_uInt32 nMaxTimePerStep); + ~TimerBasedTaskExecution (void); + void SetSelf (const ::boost::shared_ptr<TimerBasedTaskExecution>& rpSelf); + + class Deleter; + friend class Deleter; + + DECL_LINK(TimerCallback,Timer*); +}; + +} } // end of namespace ::sd::tools + +#endif |