diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /UnoControls | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'UnoControls')
25 files changed, 6098 insertions, 0 deletions
diff --git a/UnoControls/IwyuFilter_UnoControls.yaml b/UnoControls/IwyuFilter_UnoControls.yaml new file mode 100644 index 000000000..998e200af --- /dev/null +++ b/UnoControls/IwyuFilter_UnoControls.yaml @@ -0,0 +1,12 @@ +--- +assumeFilename: UnoControls/source/base/basecontrol.cxx +blacklist: + UnoControls/inc/multiplexer.hxx: + # Don't propose hxx -> h change in URE libs + - cppuhelper/interfacecontainer.hxx + UnoControls/source/inc/OConnectionPointContainerHelper.hxx: + # Don't propose hxx -> h change in URE libs + - cppuhelper/interfacecontainer.hxx + UnoControls/source/controls/framecontrol.cxx: + # Needed for use in cppu::UnoType template + - com/sun/star/awt/XControlContainer.hpp diff --git a/UnoControls/Library_ctl.mk b/UnoControls/Library_ctl.mk new file mode 100644 index 000000000..f7953e80e --- /dev/null +++ b/UnoControls/Library_ctl.mk @@ -0,0 +1,43 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Library_Library,ctl)) + +$(eval $(call gb_Library_set_include,ctl,\ + $$(INCLUDE) \ + -I$(SRCDIR)/UnoControls/inc \ + -I$(SRCDIR)/UnoControls/source/inc \ +)) + +$(eval $(call gb_Library_use_sdk_api,ctl)) + +$(eval $(call gb_Library_use_libraries,ctl,\ + comphelper \ + cppu \ + cppuhelper \ + sal \ + tl \ +)) + +$(eval $(call gb_Library_set_componentfile,ctl,UnoControls/util/ctl)) + +$(eval $(call gb_Library_add_exception_objects,ctl,\ + UnoControls/source/base/basecontainercontrol \ + UnoControls/source/base/basecontrol \ + UnoControls/source/base/multiplexer \ + UnoControls/source/base/registercontrols \ + UnoControls/source/controls/OConnectionPointContainerHelper \ + UnoControls/source/controls/OConnectionPointHelper \ + UnoControls/source/controls/framecontrol \ + UnoControls/source/controls/progressbar \ + UnoControls/source/controls/progressmonitor \ + UnoControls/source/controls/statusindicator \ +)) + +# vim:set noet sw=4 ts=4: diff --git a/UnoControls/Makefile b/UnoControls/Makefile new file mode 100644 index 000000000..d22b9aca9 --- /dev/null +++ b/UnoControls/Makefile @@ -0,0 +1,24 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This file incorporates work covered by the following license notice: +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed +# with this work for additional information regarding copyright +# ownership. The ASF licenses this file to you under the Apache +# License, Version 2.0 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.apache.org/licenses/LICENSE-2.0 . +# + +module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +include $(module_directory)/../solenv/gbuild/partial_build.mk + +# vim: set noet sw=4 ts=4: diff --git a/UnoControls/Module_UnoControls.mk b/UnoControls/Module_UnoControls.mk new file mode 100644 index 000000000..ce9fdb380 --- /dev/null +++ b/UnoControls/Module_UnoControls.mk @@ -0,0 +1,16 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +$(eval $(call gb_Module_Module,UnoControls)) + +$(eval $(call gb_Module_add_targets,UnoControls,\ + Library_ctl \ +)) + +# vim:set noet sw=4 ts=4: diff --git a/UnoControls/README b/UnoControls/README new file mode 100644 index 000000000..72348dc37 --- /dev/null +++ b/UnoControls/README @@ -0,0 +1 @@ +Separate process and thread for progress bars, etc. diff --git a/UnoControls/inc/basecontainercontrol.hxx b/UnoControls/inc/basecontainercontrol.hxx new file mode 100644 index 000000000..56e2f9373 --- /dev/null +++ b/UnoControls/inc/basecontainercontrol.hxx @@ -0,0 +1,154 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <memory> +#include <vector> + +#include "basecontrol.hxx" +#include <com/sun/star/awt/XControlContainer.hpp> + +namespace unocontrols { + +struct IMPL_ControlInfo +{ + css::uno::Reference< css::awt::XControl > xControl; + OUString sName; +}; + +class BaseContainerControl : public css::awt::XControlModel + , public css::awt::XControlContainer + , public BaseControl +{ +public: + + BaseContainerControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + + virtual ~BaseContainerControl() override; + + // XInterface + + /** + @short give answer, if interface is supported + @descr The interfaces are searched by type. + + @seealso XInterface + + @param "rType" is the type of searched interface. + + @return Any information about found interface + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Any SAL_CALL queryInterface( + const css::uno::Type& aType + ) override; + + // XTypeProvider + + /** + @short get information about supported interfaces + @seealso XTypeProvider + @return Sequence of types of all supported interfaces + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; + + // XAggregation + + virtual css::uno::Any SAL_CALL queryAggregation( + const css::uno::Type& aType + ) override; + + // XControl + + virtual void SAL_CALL createPeer( + const css::uno::Reference< css::awt::XToolkit >& xToolkit , + const css::uno::Reference< css::awt::XWindowPeer >& xParent + ) override; + + virtual sal_Bool SAL_CALL setModel( + const css::uno::Reference< css::awt::XControlModel >& xModel + ) override; + + virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override; + + // XComponent + + virtual void SAL_CALL dispose() override; + + // XEventListener + + virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) override; + + // XControlContainer + + virtual void SAL_CALL addControl( + const OUString& sName , + const css::uno::Reference< css::awt::XControl >& xControl + ) override; + + virtual void SAL_CALL removeControl( + const css::uno::Reference< css::awt::XControl >& xControl + ) override; + + virtual void SAL_CALL setStatusText( + const OUString& sStatusText + ) override; + + virtual css::uno::Reference< css::awt::XControl > SAL_CALL getControl( + const OUString& sName + ) override; + + virtual css::uno::Sequence< css::uno::Reference< css::awt::XControl > > SAL_CALL getControls() override; + + // XWindow + + virtual void SAL_CALL setVisible( sal_Bool bVisible ) override; + +protected: + using OComponentHelper::disposing; + + virtual css::awt::WindowDescriptor impl_getWindowDescriptor( + const css::uno::Reference< css::awt::XWindowPeer >& xParentPeer + ) override; + + + virtual void impl_paint( + sal_Int32 nX , + sal_Int32 nY , + const css::uno::Reference< css::awt::XGraphics >& xGraphics + ) override; + +private: + // list of pointer of "struct IMPL_ControlInfo" to hold child-controls + ::std::vector< std::unique_ptr<IMPL_ControlInfo> > maControlInfoList; + + ::cppu::OMultiTypeInterfaceContainerHelper m_aListeners; + +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/inc/basecontrol.hxx b/UnoControls/inc/basecontrol.hxx new file mode 100644 index 000000000..495664626 --- /dev/null +++ b/UnoControls/inc/basecontrol.hxx @@ -0,0 +1,331 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/awt/XPaintListener.hpp> +#include <com/sun/star/awt/XWindowListener.hpp> +#include <com/sun/star/awt/XControl.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XView.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <osl/mutex.hxx> +#include <cppuhelper/component.hxx> +#include <rtl/ref.hxx> + +namespace com::sun::star::uno { class XComponentContext; } +namespace com::sun::star::awt { class XFocusListener; } +namespace com::sun::star::awt { class XMouseListener; } +namespace com::sun::star::awt { class XMouseMotionListener; } +namespace com::sun::star::awt { struct PaintEvent; } +namespace com::sun::star::awt { struct WindowEvent; } +namespace unocontrols { class OMRCListenerMultiplexerHelper; } + +namespace unocontrols { + +struct IMPL_MutexContainer +{ + // Is necessary to initialize "BaseControl" and make this class thread-safe. + ::osl::Mutex m_aMutex; +}; + +class BaseControl : public css::lang::XServiceInfo + , public css::awt::XPaintListener + , public css::awt::XWindowListener + , public css::awt::XView + , public css::awt::XWindow + , public css::awt::XControl + , public IMPL_MutexContainer + , public ::cppu::OComponentHelper +{ +public: + BaseControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + + virtual ~BaseControl() override; + + // XInterface + + /** + @short give answer, if interface is supported + @descr The interfaces are searched by type. + + @seealso XInterface + + @param "rType" is the type of searched interface. + + @return Any information about found interface + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Any SAL_CALL queryInterface( + const css::uno::Type& aType + ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + // XTypeProvider + + /** + @short get information about supported interfaces + @seealso XTypeProvider + @return Sequence of types of all supported interfaces + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; + + /** + @short get implementation id + @descr This ID is necessary for UNO-caching. If there no ID, cache is disabled. + Another way, cache is enabled. + + @seealso XTypeProvider + @return ID as Sequence of byte + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override; + + // XAggregation + + virtual void SAL_CALL setDelegator( + const css::uno::Reference< css::uno::XInterface >& xDelegator + ) override; + + virtual css::uno::Any SAL_CALL queryAggregation( + const css::uno::Type& aType + ) override; + + // XServiceInfo + + virtual sal_Bool SAL_CALL supportsService( + const OUString& sServiceName + ) override; + + virtual OUString SAL_CALL getImplementationName() override; + + virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + + // XComponent + + virtual void SAL_CALL dispose() override; + + virtual void SAL_CALL addEventListener( + const css::uno::Reference< css::lang::XEventListener >& xListener + ) override; + + virtual void SAL_CALL removeEventListener( + const css::uno::Reference< css::lang::XEventListener >& xListener + ) override; + + // XControl + + virtual void SAL_CALL createPeer( + const css::uno::Reference< css::awt::XToolkit >& xToolkit, + const css::uno::Reference< css::awt::XWindowPeer >& xParent + ) override; + + virtual void SAL_CALL setContext( + const css::uno::Reference< css::uno::XInterface >& xContext + ) override; + + virtual sal_Bool SAL_CALL setModel( + const css::uno::Reference< css::awt::XControlModel >& xModel + ) override = 0; + + virtual void SAL_CALL setDesignMode( sal_Bool bOn ) override; + + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getContext() override; + + virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override = 0; + + virtual css::uno::Reference< css::awt::XWindowPeer > SAL_CALL getPeer() override; + + virtual css::uno::Reference< css::awt::XView > SAL_CALL getView() override; + + virtual sal_Bool SAL_CALL isDesignMode() override; + + virtual sal_Bool SAL_CALL isTransparent() override; + + // XWindow + + virtual void SAL_CALL setPosSize( sal_Int32 nX , + sal_Int32 nY , + sal_Int32 nWidth , + sal_Int32 nHeight , + sal_Int16 nFlags ) override; + + virtual void SAL_CALL setVisible( sal_Bool bVisible ) override; + + virtual void SAL_CALL setEnable( sal_Bool bEnable ) override; + + virtual void SAL_CALL setFocus() override; + + virtual css::awt::Rectangle SAL_CALL getPosSize() override; + + virtual void SAL_CALL addWindowListener( + const css::uno::Reference< css::awt::XWindowListener >& xListener + ) override; + + virtual void SAL_CALL addFocusListener( + const css::uno::Reference< css::awt::XFocusListener >& xListener + ) override; + + virtual void SAL_CALL addKeyListener( + const css::uno::Reference< css::awt::XKeyListener >& xListener ) override; + + virtual void SAL_CALL addMouseListener( + const css::uno::Reference< css::awt::XMouseListener >& xListener + ) override; + + virtual void SAL_CALL addMouseMotionListener( + const css::uno::Reference< css::awt::XMouseMotionListener >& xListener + ) override; + + virtual void SAL_CALL addPaintListener( + const css::uno::Reference< css::awt::XPaintListener >& xListener + ) override; + + virtual void SAL_CALL removeWindowListener( + const css::uno::Reference< css::awt::XWindowListener >& xListener + ) override; + + virtual void SAL_CALL removeFocusListener( + const css::uno::Reference< css::awt::XFocusListener >& xListener + ) override; + + virtual void SAL_CALL removeKeyListener( + const css::uno::Reference< css::awt::XKeyListener >& xListener + ) override; + + virtual void SAL_CALL removeMouseListener( + const css::uno::Reference< css::awt::XMouseListener >& xListener + ) override; + + virtual void SAL_CALL removeMouseMotionListener( + const css::uno::Reference< css::awt::XMouseMotionListener >& xListener + ) override; + + virtual void SAL_CALL removePaintListener( + const css::uno::Reference< css::awt::XPaintListener >& xListener + ) override; + + // XView + + virtual void SAL_CALL draw( sal_Int32 nX , + sal_Int32 nY ) override; + + virtual sal_Bool SAL_CALL setGraphics( + const css::uno::Reference< css::awt::XGraphics >& xDevice + ) override; + + virtual void SAL_CALL setZoom( float fZoomX , + float fZoomY ) override; + + virtual css::uno::Reference< css::awt::XGraphics > SAL_CALL getGraphics() override; + + virtual css::awt::Size SAL_CALL getSize() override; + + // css::lang::XEventListener + + virtual void SAL_CALL disposing( + const css::lang::EventObject& rSource + ) override; + + // XPaintListener + + virtual void SAL_CALL windowPaint( + const css::awt::PaintEvent& rEvent + ) override; + + // XWindowListener + + virtual void SAL_CALL windowResized( const css::awt::WindowEvent& aEvent ) override; + virtual void SAL_CALL windowMoved( const css::awt::WindowEvent& aEvent ) override; + virtual void SAL_CALL windowShown( const css::lang::EventObject& aEvent ) override; + virtual void SAL_CALL windowHidden( const css::lang::EventObject& aEvent ) override; + +protected: + using OComponentHelper::disposing; + + const css::uno::Reference< css::uno::XComponentContext >& impl_getComponentContext() const { return m_xComponentContext;} + + const css::uno::Reference< css::awt::XWindow >& impl_getPeerWindow() const { return m_xPeerWindow;} + + const css::uno::Reference< css::awt::XGraphics >& impl_getGraphicsPeer() const { return m_xGraphicsPeer;} + + sal_Int32 impl_getWidth() const { return m_nWidth;} + + sal_Int32 impl_getHeight() const { return m_nHeight;} + + virtual css::awt::WindowDescriptor impl_getWindowDescriptor( + const css::uno::Reference< css::awt::XWindowPeer >& xParentPeer + ); + + virtual void impl_paint( sal_Int32 nX , + sal_Int32 nY , + const css::uno::Reference< css::awt::XGraphics >& xGraphics ); + + virtual void impl_recalcLayout( const css::awt::WindowEvent& aEvent ); + + const css::uno::Reference< css::uno::XInterface >& impl_getDelegator() const { return m_xDelegator;} + +private: + OMRCListenerMultiplexerHelper* impl_getMultiplexer(); + + css::uno::Reference< css::uno::XComponentContext > m_xComponentContext; + css::uno::Reference< css::uno::XInterface > m_xDelegator; + rtl::Reference<OMRCListenerMultiplexerHelper> m_xMultiplexer; // multiplex events + css::uno::Reference< css::uno::XInterface > m_xContext; + css::uno::Reference< css::awt::XWindowPeer > m_xPeer; + css::uno::Reference< css::awt::XWindow > m_xPeerWindow; + css::uno::Reference< css::awt::XGraphics > m_xGraphicsView; // graphics for css::awt::XView-operations + css::uno::Reference< css::awt::XGraphics > m_xGraphicsPeer; // graphics for painting on a peer + sal_Int32 m_nX; // Position ... + sal_Int32 m_nY; + sal_Int32 m_nWidth; // ... and size of window + sal_Int32 m_nHeight; + bool m_bVisible; // Some state flags + bool m_bInDesignMode; + bool m_bEnable; +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/inc/multiplexer.hxx b/UnoControls/inc/multiplexer.hxx new file mode 100644 index 000000000..1c5aa98ca --- /dev/null +++ b/UnoControls/inc/multiplexer.hxx @@ -0,0 +1,233 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/awt/XKeyListener.hpp> +#include <com/sun/star/awt/XPaintListener.hpp> +#include <com/sun/star/awt/XMouseMotionListener.hpp> +#include <com/sun/star/awt/XWindowListener.hpp> +#include <com/sun/star/awt/XTopWindowListener.hpp> +#include <com/sun/star/awt/XMouseListener.hpp> +#include <com/sun/star/awt/XFocusListener.hpp> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/weakref.hxx> +#include <cppuhelper/interfacecontainer.hxx> + +namespace com::sun::star::awt { class XWindow; } +namespace com::sun::star::awt { struct KeyEvent; } +namespace com::sun::star::awt { struct MouseEvent; } +namespace com::sun::star::awt { struct PaintEvent; } +namespace com::sun::star::awt { struct WindowEvent; } + +namespace unocontrols { + +class OMRCListenerMultiplexerHelper final : public css::awt::XFocusListener + , public css::awt::XWindowListener + , public css::awt::XKeyListener + , public css::awt::XMouseListener + , public css::awt::XMouseMotionListener + , public css::awt::XPaintListener + , public css::awt::XTopWindowListener + , public ::cppu::OWeakObject +{ +public: + + /** + @short constructor + @descr Create a Multiplexer of XWindowEvents. + @param rControl The control. All listeners think that this is the original broadcaster. + @param rPeer The peer from which the original events are dispatched. Null is allowed. + */ + + OMRCListenerMultiplexerHelper( const css::uno::Reference< css::awt::XWindow >& xControl , + const css::uno::Reference< css::awt::XWindow >& xPeer ); + + /** + @short copy-constructor + @descr + @param rCopyInstance C++-Reference to instance to make copy from. + */ + + OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper& aCopyInstance ); + + virtual ~OMRCListenerMultiplexerHelper() override; + + // XInterface + + /** + @short give answer, if interface is supported + @descr The interfaces are searched by type. + + @seealso XInterface + + @param "rType" is the type of searched interface. + + @return Any information about found interface + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + OMRCListenerMultiplexerHelper& operator= ( const OMRCListenerMultiplexerHelper& aCopyInstance ); + + // container methods + + /** + @short Remove all listeners from the previous set peer and add the needed listeners to rPeer. + @param rPeer The peer from which the original events are dispatched. Null is allowed. + */ + + void setPeer( const css::uno::Reference< css::awt::XWindow >& xPeer ); + + /** + @short Remove all listeners and send a disposing message. + */ + + void disposeAndClear(); + + /** + @short Add the specified listener to the source. + */ + + void advise( const css::uno::Type& aType , + const css::uno::Reference< css::uno::XInterface >& xListener ); + + /** + @short Remove the specified listener from the source. + */ + + void unadvise( const css::uno::Type& aType , + const css::uno::Reference< css::uno::XInterface >& xListener ); + + // XEventListener + + virtual void SAL_CALL disposing(const css::lang::EventObject& aSource) override; + + // XFocusListener + + virtual void SAL_CALL focusGained(const css::awt::FocusEvent& aEvent ) override; + + virtual void SAL_CALL focusLost(const css::awt::FocusEvent& aEvent ) override; + + // XWindowListener + + virtual void SAL_CALL windowResized(const css::awt::WindowEvent& aEvent ) override; + + virtual void SAL_CALL windowMoved(const css::awt::WindowEvent& aEvent ) override; + + virtual void SAL_CALL windowShown(const css::lang::EventObject& aEvent ) override; + + virtual void SAL_CALL windowHidden(const css::lang::EventObject& aEvent ) override; + + // XKeyListener + + virtual void SAL_CALL keyPressed( const css::awt::KeyEvent& aEvent ) override; + + virtual void SAL_CALL keyReleased( const css::awt::KeyEvent& aEvent ) override; + + // XMouseListener + + virtual void SAL_CALL mousePressed(const css::awt::MouseEvent& aEvent ) override; + + virtual void SAL_CALL mouseReleased(const css::awt::MouseEvent& aEvent ) override; + + virtual void SAL_CALL mouseEntered(const css::awt::MouseEvent& aEvent ) override; + + virtual void SAL_CALL mouseExited(const css::awt::MouseEvent& aEvent ) override; + + // XMouseMotionListener + + virtual void SAL_CALL mouseDragged(const css::awt::MouseEvent& aEvent ) override; + + virtual void SAL_CALL mouseMoved(const css::awt::MouseEvent& aEvent ) override; + + // XPaintListener + + virtual void SAL_CALL windowPaint(const css::awt::PaintEvent& aEvent ) override; + + // XTopWindowListener + + virtual void SAL_CALL windowOpened( const css::lang::EventObject& aEvent ) override; + + virtual void SAL_CALL windowClosing( const css::lang::EventObject& aEvent ) override; + + virtual void SAL_CALL windowClosed( const css::lang::EventObject& aEvent ) override; + + virtual void SAL_CALL windowMinimized( const css::lang::EventObject& aEvent ) override; + + virtual void SAL_CALL windowNormalized( const css::lang::EventObject& aEvent ) override; + + virtual void SAL_CALL windowActivated( const css::lang::EventObject& aEvent ) override; + + virtual void SAL_CALL windowDeactivated( const css::lang::EventObject& aEvent ) override; + +private: + + /** + @short Remove the listener from the peer. + @param xPeer The peer from which the listener is removed. + @param rType The listener type, which specify the type of the listener. + */ + + void impl_adviseToPeer( const css::uno::Reference< css::awt::XWindow >& xPeer , + const css::uno::Type& aType ); + + /** + @short Add the listener to the peer. + @param xPeer The peer to which the listener is added. + @param rType The listener type, which specify the type of the listener. + */ + + void impl_unadviseFromPeer( const css::uno::Reference< css::awt::XWindow >& xPeer , + const css::uno::Type& aType ); + +// private variables + +private: + ::osl::Mutex m_aMutex; + css::uno::Reference< css::awt::XWindow > m_xPeer; /// The source of the events. Normally this is the peer object. + css::uno::WeakReference< css::awt::XWindow > m_xControl; + ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerHolder; + +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/base/basecontainercontrol.cxx b/UnoControls/source/base/basecontainercontrol.cxx new file mode 100644 index 000000000..dda72799d --- /dev/null +++ b/UnoControls/source/base/basecontainercontrol.cxx @@ -0,0 +1,392 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <basecontainercontrol.hxx> + +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <com/sun/star/container/ContainerEvent.hpp> +#include <com/sun/star/container/XContainerListener.hpp> +#include <com/sun/star/awt/XControlContainer.hpp> + +// namespaces + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::container; + +namespace unocontrols { + +// construct/destruct + +BaseContainerControl::BaseContainerControl( const Reference< XComponentContext >& rxContext ) + : BaseControl ( rxContext ) + , m_aListeners ( m_aMutex ) +{ +} + +BaseContainerControl::~BaseContainerControl() +{ +} + +// XInterface + +Any SAL_CALL BaseContainerControl::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + Reference< XInterface > xDel = BaseControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XTypeProvider + +Sequence< Type > SAL_CALL BaseContainerControl::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XControlContainer>::get(), + BaseControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation + +Any SAL_CALL BaseContainerControl::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XControlModel* > ( this ) , + static_cast< XControlContainer* > ( this ) + ) + ); + + // If searched interface supported by this class ... + if ( aReturn.hasValue() ) + { + // ... return this information. + return aReturn; + } + else + { + // Else; ... ask baseclass for interfaces! + return BaseControl::queryAggregation( aType ); + } +} + +// XControl + +void SAL_CALL BaseContainerControl::createPeer( const Reference< XToolkit >& xToolkit , + const Reference< XWindowPeer >& xParent ) +{ + if ( !getPeer().is() ) + { + // create own peer + BaseControl::createPeer( xToolkit, xParent ); + + // create peers at all children + Sequence< Reference< XControl > > seqControlList = getControls(); + + for ( auto& rxControl : seqControlList ) + { + rxControl->createPeer( xToolkit, getPeer() ); + } + } +} + +// XControl + +sal_Bool SAL_CALL BaseContainerControl::setModel( const Reference< XControlModel >& ) +{ + // This object has NO model. + return false; +} + +// XControl + +Reference< XControlModel > SAL_CALL BaseContainerControl::getModel() +{ + // This object has NO model. + // return (XControlModel*)this; + return Reference< XControlModel >(); +} + +// XComponent + +void SAL_CALL BaseContainerControl::dispose() +{ + // Tell everything that this container is now gone. + // It's faster if you listen to both the control and the container. + + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // remove listeners + EventObject aObject; + + aObject.Source.set( static_cast<XControlContainer*>(this), UNO_QUERY ); + m_aListeners.disposeAndClear( aObject ); + + // remove controls + const Sequence< Reference< XControl > > seqCtrls = getControls(); + + maControlInfoList.clear(); + + for ( Reference< XControl > const & control : seqCtrls ) + { + control->removeEventListener ( static_cast< XEventListener* >( static_cast< XWindowListener* >( this ) ) ); + control->dispose ( ); + } + + // call baseclass + BaseControl::dispose(); +} + +// XEventListener + +void SAL_CALL BaseContainerControl::disposing( const EventObject& rEvent ) +{ + Reference< XControl > xControl( rEvent.Source, UNO_QUERY ); + + // "removeControl" remove only, when control is an active control + removeControl( xControl ); +} + +// XControlContainer + +void SAL_CALL BaseContainerControl::addControl ( const OUString& rName, const Reference< XControl > & rControl ) +{ + if ( !rControl.is () ) + return; + + // take memory for new item + IMPL_ControlInfo* pNewControl = new IMPL_ControlInfo; + + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // set control + pNewControl->sName = rName; + pNewControl->xControl = rControl; + + // and insert in list + maControlInfoList.emplace_back( pNewControl ); + + // initialize new control + pNewControl->xControl->setContext ( static_cast<OWeakObject*>(this) ); + pNewControl->xControl->addEventListener ( static_cast< XEventListener* >( static_cast< XWindowListener* >( this ) ) ); + + // when container has a peer... + if (getPeer().is()) + { + // ... then create a peer on child + pNewControl->xControl->createPeer ( getPeer()->getToolkit(), getPeer() ); + } + + // Send message to all listener + OInterfaceContainerHelper* pInterfaceContainer = m_aListeners.getContainer( cppu::UnoType<XContainerListener>::get()); + + if (pInterfaceContainer) + { + // Build event + ContainerEvent aEvent; + + aEvent.Source = *this; + aEvent.Element <<= rControl; + + // Get all listener + OInterfaceIteratorHelper aIterator (*pInterfaceContainer); + + // Send event + while ( aIterator.hasMoreElements() ) + { + static_cast<XContainerListener*>(aIterator.next())->elementInserted (aEvent); + } + } +} + +// XControlContainer + +void SAL_CALL BaseContainerControl::removeControl ( const Reference< XControl > & rControl ) +{ + if ( rControl.is() ) + { + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + size_t nControls = maControlInfoList.size(); + + for ( size_t n = 0; n < nControls; n++ ) + { + // Search for right control + IMPL_ControlInfo* pControl = maControlInfoList[ n ].get(); + if ( rControl == pControl->xControl ) + { + //.is it found ... remove listener from control + pControl->xControl->removeEventListener (static_cast< XEventListener* >( static_cast< XWindowListener* >( this ) )); + pControl->xControl->setContext ( Reference< XInterface > () ); + + // ... free memory + maControlInfoList.erase(maControlInfoList.begin() + n); + + // Send message to all other listener + OInterfaceContainerHelper * pInterfaceContainer = m_aListeners.getContainer( cppu::UnoType<XContainerListener>::get()); + + if (pInterfaceContainer) + { + ContainerEvent aEvent; + + aEvent.Source = *this; + aEvent.Element <<= rControl; + + OInterfaceIteratorHelper aIterator (*pInterfaceContainer); + + while ( aIterator.hasMoreElements() ) + { + static_cast<XContainerListener*>(aIterator.next())->elementRemoved (aEvent); + } + } + // Break "for" ! + break; + } + } + } +} + +// XControlContainer + +void SAL_CALL BaseContainerControl::setStatusText ( const OUString& rStatusText ) +{ + // go down to each parent + Reference< XControlContainer > xContainer ( getContext(), UNO_QUERY ); + + if ( xContainer.is () ) + { + xContainer->setStatusText ( rStatusText ); + } +} + +// XControlContainer + +Reference< XControl > SAL_CALL BaseContainerControl::getControl ( const OUString& rName ) +{ + // Ready for multithreading + MutexGuard aGuard ( Mutex::getGlobalMutex() ); + + size_t nControls = maControlInfoList.size(); + + // Search for right control + for( size_t nCount = 0; nCount < nControls; ++nCount ) + { + IMPL_ControlInfo* pSearchControl = maControlInfoList[ nCount ].get(); + + if ( pSearchControl->sName == rName ) + { + // We have found it ... + // Break operation and return. + return pSearchControl->xControl; + } + } + + // We have not found it ... return NULL. + return Reference< XControl > (); +} + +// XControlContainer + +Sequence< Reference< XControl > > SAL_CALL BaseContainerControl::getControls () +{ + // Ready for multithreading + MutexGuard aGuard ( Mutex::getGlobalMutex() ); + + size_t nControls = maControlInfoList.size(); + size_t nCount = 0; + Sequence< Reference< XControl > > aDescriptor ( nControls ); + Reference< XControl > * pDestination = aDescriptor.getArray (); + + // Copy controls to sequence + for( nCount = 0; nCount < nControls; ++nCount ) + { + IMPL_ControlInfo* pCopyControl = maControlInfoList[ nCount ].get(); + pDestination [ nCount ] = pCopyControl->xControl; + } + + // Return sequence + return aDescriptor; +} + +// XWindow + +void SAL_CALL BaseContainerControl::setVisible ( sal_Bool bVisible ) +{ + // override baseclass definition + BaseControl::setVisible ( bVisible ); + + // is it a top window ? + if ( !getContext().is() && bVisible ) + { + // then show it automatically + createPeer ( Reference< XToolkit > (), Reference< XWindowPeer > () ); + } +} + +// protected method + +WindowDescriptor BaseContainerControl::impl_getWindowDescriptor ( const Reference< XWindowPeer > & rParentPeer ) +{ + WindowDescriptor aDescriptor; + + aDescriptor.Type = WindowClass_CONTAINER; + aDescriptor.WindowServiceName = "window"; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = rParentPeer; + aDescriptor.Bounds = getPosSize (); + aDescriptor.WindowAttributes = 0; + + return aDescriptor; +} + +// protected method + +void BaseContainerControl::impl_paint ( sal_Int32 /*nX*/, sal_Int32 /*nY*/, const Reference< XGraphics > & /*rGraphics*/ ) +{ +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/base/basecontrol.cxx b/UnoControls/source/base/basecontrol.cxx new file mode 100644 index 000000000..fc9d0b890 --- /dev/null +++ b/UnoControls/source/base/basecontrol.cxx @@ -0,0 +1,750 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <basecontrol.hxx> +#include <multiplexer.hxx> + +#include <com/sun/star/awt/XDevice.hpp> +#include <com/sun/star/awt/WindowAttribute.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/Toolkit.hpp> +#include <cppuhelper/supportsservice.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> + +// namespaces + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; + +namespace unocontrols { + +#define DEFAULT_X 0 +#define DEFAULT_Y 0 +#define DEFAULT_WIDTH 100 +#define DEFAULT_HEIGHT 100 +#define DEFAULT_VISIBLE false +#define DEFAULT_INDESIGNMODE false +#define DEFAULT_ENABLE true + +// construct/destruct + +BaseControl::BaseControl( const Reference< XComponentContext >& rxContext ) + : IMPL_MutexContainer ( ) + , OComponentHelper ( m_aMutex ) + , m_xComponentContext ( rxContext ) + , m_nX ( DEFAULT_X ) + , m_nY ( DEFAULT_Y ) + , m_nWidth ( DEFAULT_WIDTH ) + , m_nHeight ( DEFAULT_HEIGHT ) + , m_bVisible ( DEFAULT_VISIBLE ) + , m_bInDesignMode ( DEFAULT_INDESIGNMODE ) + , m_bEnable ( DEFAULT_ENABLE ) +{ +} + +BaseControl::~BaseControl() +{ +} + +// XInterface + +Any SAL_CALL BaseControl::queryInterface( const Type& rType ) +{ + Any aReturn; + if ( m_xDelegator.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = m_xDelegator->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL BaseControl::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OComponentHelper::acquire(); +} + +// XInterface + +void SAL_CALL BaseControl::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OComponentHelper::release(); +} + +// XTypeProvider + +Sequence< Type > SAL_CALL BaseControl::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XPaintListener>::get(), + cppu::UnoType<XWindowListener>::get(), + cppu::UnoType<XView>::get(), + cppu::UnoType<XWindow>::get(), + cppu::UnoType<XServiceInfo>::get(), + cppu::UnoType<XControl>::get(), + OComponentHelper::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XTypeProvider + +Sequence< sal_Int8 > SAL_CALL BaseControl::getImplementationId() +{ + return css::uno::Sequence<sal_Int8>(); +} + +// XAggregation + +void SAL_CALL BaseControl::setDelegator( const Reference< XInterface >& xDel ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + m_xDelegator = xDel; +} + +// XAggregation + +Any SAL_CALL BaseControl::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XPaintListener*> ( this ) , + static_cast< XWindowListener*> ( this ) , + static_cast< XView* > ( this ) , + static_cast< XWindow* > ( this ) , + static_cast< XServiceInfo* > ( this ) , + static_cast< XControl* > ( this ) + ) + ); + + // If searched interface supported by this class ... + if ( aReturn.hasValue() ) + { + // ... return this information. + return aReturn; + } + else + { + // Else; ... ask baseclass for interfaces! + return OComponentHelper::queryAggregation( aType ); + } +} + +// XServiceInfo + +OUString SAL_CALL BaseControl::getImplementationName() +{ + return OUString(); +} + +// XServiceInfo + +sal_Bool SAL_CALL BaseControl::supportsService( const OUString& sServiceName ) +{ + return cppu::supportsService(this, sServiceName); +} + +// XServiceInfo + +Sequence< OUString > SAL_CALL BaseControl::getSupportedServiceNames() +{ + return Sequence< OUString >(); +} + +// XComponent + +void SAL_CALL BaseControl::dispose() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + if ( m_xMultiplexer.is() ) + { + // to all other paint, focus, etc. + m_xMultiplexer->disposeAndClear(); + } + + // set the service manager to disposed + OComponentHelper::dispose(); + + // release context and peer + m_xContext.clear(); + if ( m_xPeer.is() ) + { + if ( m_xGraphicsPeer.is() ) + { + removePaintListener( this ); + removeWindowListener( this ); + m_xGraphicsPeer.clear(); + } + + m_xPeer->dispose(); + m_xPeerWindow.clear(); + m_xPeer.clear(); + + if ( m_xMultiplexer.is() ) + { + // take changes on multiplexer + m_xMultiplexer->setPeer( Reference< XWindow >() ); + } + } + + // release view + if ( m_xGraphicsView.is() ) + { + m_xGraphicsView.clear(); + } +} + +// XComponent + +void SAL_CALL BaseControl::addEventListener( const Reference< XEventListener >& xListener ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + OComponentHelper::addEventListener( xListener ); +} + +// XComponent + +void SAL_CALL BaseControl::removeEventListener( const Reference< XEventListener >& xListener ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + OComponentHelper::removeEventListener( xListener ); +} + +// XControl + +void SAL_CALL BaseControl::createPeer( const Reference< XToolkit >& xToolkit , + const Reference< XWindowPeer >& xParentPeer ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + if ( !m_xPeer.is() ) + { + // use method "BaseControl::getWindowDescriptor()" to change window attributes! + WindowDescriptor aDescriptor = impl_getWindowDescriptor( xParentPeer ); + + if ( m_bVisible ) + { + aDescriptor.WindowAttributes |= WindowAttribute::SHOW; + } + + // very slow under remote conditions! + // create the window on the server + Reference< XToolkit > xLocalToolkit = xToolkit; + if ( !xLocalToolkit.is() ) + { + // but first create well known toolkit, if it not exist + xLocalToolkit.set( Toolkit::create(m_xComponentContext), UNO_QUERY_THROW ); + } + m_xPeer = xLocalToolkit->createWindow( aDescriptor ); + m_xPeerWindow.set( m_xPeer, UNO_QUERY ); + + if ( m_xPeerWindow.is() ) + { + if ( m_xMultiplexer.is() ) + { + m_xMultiplexer->setPeer( m_xPeerWindow ); + } + + // create new reference to xgraphics for painting on a peer + // and add a paint listener + Reference< XDevice > xDevice( m_xPeerWindow, UNO_QUERY ); + + if ( xDevice.is() ) + { + m_xGraphicsPeer = xDevice->createGraphics(); + } + + if ( m_xGraphicsPeer.is() ) + { + addPaintListener( this ); + addWindowListener( this ); + } + + m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, PosSize::POSSIZE ); + m_xPeerWindow->setEnable( m_bEnable ); + m_xPeerWindow->setVisible( m_bVisible && !m_bInDesignMode ); + } + } +} + +// XControl + +void SAL_CALL BaseControl::setContext( const Reference< XInterface >& xContext ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + m_xContext = xContext; +} + +// XControl + +void SAL_CALL BaseControl::setDesignMode( sal_Bool bOn ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + m_bInDesignMode = bOn; +} + +// XControl + +Reference< XInterface > SAL_CALL BaseControl::getContext() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_xContext; +} + +// XControl + +Reference< XWindowPeer > SAL_CALL BaseControl::getPeer() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_xPeer; +} + +// XControl + +Reference< XView > SAL_CALL BaseControl::getView() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return this; +} + +// XControl + +sal_Bool SAL_CALL BaseControl::isDesignMode() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_bInDesignMode; +} + +// XControl + +sal_Bool SAL_CALL BaseControl::isTransparent() +{ + return false; +} + +// XWindow + +void SAL_CALL BaseControl::setPosSize( sal_Int32 nX , + sal_Int32 nY , + sal_Int32 nWidth , + sal_Int32 nHeight , + sal_Int16 nFlags ) +{ + // - change size and position of window and save the values + + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + bool bChanged = false; + + if ( nFlags & PosSize::X ) + { + bChanged |= m_nX != nX; + m_nX = nX; + } + + if ( nFlags & PosSize::Y ) + { + bChanged |= m_nY != nY; + m_nY = nY; + } + + if ( nFlags & PosSize::WIDTH ) + { + bChanged |= m_nWidth != nWidth; + m_nWidth = nWidth; + } + + if ( nFlags & PosSize::HEIGHT ) + { + bChanged |= m_nHeight != nHeight; + m_nHeight = nHeight; + } + + if ( bChanged && m_xPeerWindow.is() ) + { + m_xPeerWindow->setPosSize( m_nX, m_nY, m_nWidth, m_nHeight, nFlags ); + } +} + +// XWindow + +void SAL_CALL BaseControl::setVisible( sal_Bool bVisible ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Set new state of flag + m_bVisible = bVisible; + + if ( m_xPeerWindow.is() ) + { + // Set it also on peerwindow + m_xPeerWindow->setVisible( m_bVisible ); + } +} + +// XWindow + +void SAL_CALL BaseControl::setEnable( sal_Bool bEnable ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Set new state of flag + m_bEnable = bEnable; + + if ( m_xPeerWindow.is() ) + { + // Set it also on peerwindow + m_xPeerWindow->setEnable( m_bEnable ); + } +} + +// XWindow + +void SAL_CALL BaseControl::setFocus() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + if ( m_xPeerWindow.is() ) + { + m_xPeerWindow->setFocus(); + } +} + +// XWindow + +Rectangle SAL_CALL BaseControl::getPosSize() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return Rectangle( m_nX, m_nY , m_nWidth, m_nHeight ); +} + +// XWindow + +void SAL_CALL BaseControl::addWindowListener( const Reference< XWindowListener >& xListener ) +{ + impl_getMultiplexer()->advise( cppu::UnoType<XWindowListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::addFocusListener( const Reference< XFocusListener >& xListener ) +{ + impl_getMultiplexer()->advise( cppu::UnoType<XFocusListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::addKeyListener( const Reference< XKeyListener >& xListener ) +{ + impl_getMultiplexer()->advise( cppu::UnoType<XKeyListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::addMouseListener( const Reference< XMouseListener >& xListener ) +{ + impl_getMultiplexer()->advise( cppu::UnoType<XMouseListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::addMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) +{ + impl_getMultiplexer()->advise( cppu::UnoType<XMouseMotionListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::addPaintListener( const Reference< XPaintListener >& xListener ) +{ + impl_getMultiplexer()->advise( cppu::UnoType<XPaintListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::removeWindowListener( const Reference< XWindowListener >& xListener ) +{ + impl_getMultiplexer()->unadvise( cppu::UnoType<XWindowListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::removeFocusListener( const Reference< XFocusListener >& xListener ) +{ + impl_getMultiplexer()->unadvise( cppu::UnoType<XFocusListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::removeKeyListener( const Reference< XKeyListener >& xListener ) +{ + impl_getMultiplexer()->unadvise( cppu::UnoType<XKeyListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::removeMouseListener( const Reference< XMouseListener >& xListener ) +{ + impl_getMultiplexer()->unadvise( cppu::UnoType<XMouseListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::removeMouseMotionListener( const Reference< XMouseMotionListener >& xListener ) +{ + impl_getMultiplexer()->unadvise( cppu::UnoType<XMouseMotionListener>::get(), xListener ); +} + +// XWindow + +void SAL_CALL BaseControl::removePaintListener( const Reference< XPaintListener >& xListener ) +{ + impl_getMultiplexer()->unadvise( cppu::UnoType<XPaintListener>::get(), xListener ); +} + +// XView + +void SAL_CALL BaseControl::draw( sal_Int32 nX , + sal_Int32 nY ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // - paint to a view + // - use the method "paint()" + // - see also "windowPaint()" + impl_paint( nX, nY, m_xGraphicsView ); +} + +// XView + +sal_Bool SAL_CALL BaseControl::setGraphics( const Reference< XGraphics >& xDevice ) +{ + // - set the graphics for a view + // - in this class exist 2 graphics-member ... one for peer[_xGraphicsPeer] and one for view[_xGraphicsView] + // - they are used by "windowPaint() and draw()", forwarded to "paint ()" + bool bReturn = false; + if ( xDevice.is() ) + { + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + m_xGraphicsView = xDevice; + bReturn = true; + } + + return bReturn; +} + +// XView + +void SAL_CALL BaseControl::setZoom( float /*fZoomX*/ , + float /*fZoomY*/ ) +{ + // Not implemented yet +} + +// XView + +Reference< XGraphics > SAL_CALL BaseControl::getGraphics() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return m_xGraphicsView; +} + +// XView + +Size SAL_CALL BaseControl::getSize() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + return Size( m_nWidth, m_nHeight ); +} + +// XEventListener + +void SAL_CALL BaseControl::disposing( const EventObject& /*aSource*/ ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // - release ALL references + // - it must be !!! + if ( m_xGraphicsPeer.is() ) + { + removePaintListener( this ); + removeWindowListener( this ); + m_xGraphicsPeer.clear(); + } + + if ( m_xGraphicsView.is() ) + { + m_xGraphicsView.clear(); + } +} + +// XPaintListener + +void SAL_CALL BaseControl::windowPaint( const PaintEvent& /*aEvent*/ ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // - repaint the peer + // - use the method "paint ()" for painting on a peer and a print device !!! + // - see also "draw ()" + impl_paint( 0, 0, m_xGraphicsPeer ); +} + +// XWindowListener + +void SAL_CALL BaseControl::windowResized( const WindowEvent& aEvent ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + m_nWidth = aEvent.Width; + m_nHeight = aEvent.Height; + WindowEvent aMappedEvent = aEvent; + aMappedEvent.X = 0; + aMappedEvent.Y = 0; + impl_recalcLayout( aMappedEvent ); +} + +// XWindowListener + +void SAL_CALL BaseControl::windowMoved( const WindowEvent& aEvent ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + m_nWidth = aEvent.Width; + m_nHeight = aEvent.Height; + WindowEvent aMappedEvent = aEvent; + aMappedEvent.X = 0; + aMappedEvent.Y = 0; + impl_recalcLayout( aMappedEvent ); +} + +// XWindowListener + +void SAL_CALL BaseControl::windowShown( const EventObject& /*aEvent*/ ) +{ +} + +// XWindowListener + +void SAL_CALL BaseControl::windowHidden( const EventObject& /*aEvent*/ ) +{ +} + +// protected method + +WindowDescriptor BaseControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer ) +{ + // - used from "createPeer()" to set the values of a css::awt::WindowDescriptor !!! + // - if you will change the descriptor-values, you must override this virtual function + // - the caller must release the memory for this dynamical descriptor !!! + + WindowDescriptor aDescriptor; + + aDescriptor.Type = WindowClass_SIMPLE; + aDescriptor.WindowServiceName = "window"; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = xParentPeer; + aDescriptor.Bounds = getPosSize (); + aDescriptor.WindowAttributes = 0; + + return aDescriptor; +} + +// protected method + +void BaseControl::impl_paint( sal_Int32 /*nX*/ , + sal_Int32 /*nY*/ , + const Reference< XGraphics >& /*xGraphics*/ ) +{ + // - one paint method for peer AND view !!! + // (see also => "windowPaint()" and "draw()") + // - not used in this implementation, but it's not necessary to make it pure virtual !!! +} + +// protected method + +void BaseControl::impl_recalcLayout( const WindowEvent& /*aEvent*/ ) +{ + // We need as virtual function to support automatically resizing of derived controls! + // But we make it not pure virtual because it's not necessary for all derived classes! +} + +// private method + +OMRCListenerMultiplexerHelper* BaseControl::impl_getMultiplexer() +{ + if ( !m_xMultiplexer.is() ) + { + m_xMultiplexer = new OMRCListenerMultiplexerHelper( static_cast<XWindow*>(this), m_xPeerWindow ); + } + + return m_xMultiplexer.get(); +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/base/multiplexer.cxx b/UnoControls/source/base/multiplexer.cxx new file mode 100644 index 000000000..3b51249d0 --- /dev/null +++ b/UnoControls/source/base/multiplexer.cxx @@ -0,0 +1,444 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <multiplexer.hxx> + +#include <osl/diagnose.h> +#include <cppuhelper/queryinterface.hxx> + +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/XTopWindow.hpp> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::lang; + +namespace unocontrols { + +// macros + +#define MULTIPLEX( INTERFACE, METHOD, EVENTTYP, EVENT ) \ + \ + /* First get all interfaces from container with right type.*/ \ + OInterfaceContainerHelper* pContainer = m_aListenerHolder.getContainer( cppu::UnoType<INTERFACE>::get() ); \ + /* Do the follow only, if elements in container exist.*/ \ + if( pContainer != nullptr ) \ + { \ + OInterfaceIteratorHelper aIterator( *pContainer ); \ + EVENTTYP aLocalEvent = EVENT; \ + /* Remark: The control is the event source not the peer.*/ \ + /* We must change the source of the event. */ \ + aLocalEvent.Source = m_xControl; \ + /* Is the control not destroyed? */ \ + if( aLocalEvent.Source.is() ) \ + { \ + if( aIterator.hasMoreElements() ) \ + { \ + INTERFACE * pListener = static_cast<INTERFACE *>(aIterator.next()); \ + try \ + { \ + pListener->METHOD( aLocalEvent ); \ + } \ + catch(const RuntimeException& ) \ + { \ + /* Ignore all system exceptions from the listener! */ \ + } \ + } \ + } \ + } + +// construct/destruct + +OMRCListenerMultiplexerHelper::OMRCListenerMultiplexerHelper( const Reference< XWindow >& xControl , + const Reference< XWindow >& xPeer ) + : m_xPeer ( xPeer ) + , m_xControl ( xControl ) + , m_aListenerHolder ( m_aMutex ) +{ +} + +OMRCListenerMultiplexerHelper::OMRCListenerMultiplexerHelper( const OMRCListenerMultiplexerHelper& aCopyInstance ) + : XFocusListener() + , XWindowListener() + , XKeyListener() + , XMouseListener() + , XMouseMotionListener() + , XPaintListener() + , XTopWindowListener() + , OWeakObject(aCopyInstance) + , m_aListenerHolder ( m_aMutex ) +{ +} + +OMRCListenerMultiplexerHelper::~OMRCListenerMultiplexerHelper() +{ +} + +// XInterface + +Any SAL_CALL OMRCListenerMultiplexerHelper::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( rType , + static_cast< XWindowListener* > ( this ) , + static_cast< XKeyListener* > ( this ) , + static_cast< XFocusListener* > ( this ) , + static_cast< XMouseListener* > ( this ) , + static_cast< XMouseMotionListener* > ( this ) , + static_cast< XPaintListener* > ( this ) , + static_cast< XTopWindowListener* > ( this ) , + static_cast< XTopWindowListener* > ( this ) + ) + ); + + // If searched interface supported by this class ... + if ( aReturn.hasValue() ) + { + // ... return this information. + return aReturn; + } + else + { + // Else; ... ask baseclass for interfaces! + return OWeakObject::queryInterface( rType ); + } +} + +// XInterface + +void SAL_CALL OMRCListenerMultiplexerHelper::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::acquire(); +} + +// XInterface + +void SAL_CALL OMRCListenerMultiplexerHelper::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::release(); +} + +// container method + +void OMRCListenerMultiplexerHelper::setPeer( const Reference< XWindow >& xPeer ) +{ + MutexGuard aGuard( m_aMutex ); + if( m_xPeer != xPeer ) + { + if( m_xPeer.is() ) + { + // get all types from the listener added to the peer + const Sequence< Type > aContainedTypes = m_aListenerHolder.getContainedTypes(); + // loop over all listener types and remove the listeners from the peer + for( const auto& rContainedType : aContainedTypes ) + impl_unadviseFromPeer( m_xPeer, rContainedType ); + } + m_xPeer = xPeer; + if( m_xPeer.is() ) + { + // get all types from the listener added to the peer + const Sequence< Type > aContainedTypes = m_aListenerHolder.getContainedTypes(); + // loop over all listener types and add the listeners to the peer + for( const auto& rContainedType : aContainedTypes ) + impl_adviseToPeer( m_xPeer, rContainedType ); + } + } +} + +// container method + +void OMRCListenerMultiplexerHelper::disposeAndClear() +{ + EventObject aEvent; + aEvent.Source = m_xControl; + m_aListenerHolder.disposeAndClear( aEvent ); +} + +// container method + +void OMRCListenerMultiplexerHelper::advise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + MutexGuard aGuard( m_aMutex ); + if( m_aListenerHolder.addInterface( aType, xListener ) == 1 ) + { + // the first listener is added + if( m_xPeer.is() ) + { + impl_adviseToPeer( m_xPeer, aType ); + } + } +} + +// container method + +void OMRCListenerMultiplexerHelper::unadvise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + MutexGuard aGuard( m_aMutex ); + if( m_aListenerHolder.removeInterface( aType, xListener ) == 0 ) + { + // the last listener is removed + if ( m_xPeer.is() ) + { + impl_unadviseFromPeer( m_xPeer, aType ); + } + } +} + +// XEventListener + +void SAL_CALL OMRCListenerMultiplexerHelper::disposing( const EventObject& /*aSource*/ ) +{ + MutexGuard aGuard( m_aMutex ); + // peer is disposed, clear the reference + m_xPeer.clear(); +} + +// XFcousListener + +void OMRCListenerMultiplexerHelper::focusGained(const FocusEvent& aEvent ) +{ + MULTIPLEX( XFocusListener, focusGained, FocusEvent, aEvent ) +} + +// XFcousListener + +void OMRCListenerMultiplexerHelper::focusLost(const FocusEvent& aEvent ) +{ + MULTIPLEX( XFocusListener, focusLost, FocusEvent, aEvent ) +} + +// XWindowListener + +void OMRCListenerMultiplexerHelper::windowResized(const WindowEvent& aEvent ) +{ + MULTIPLEX( XWindowListener, windowResized, WindowEvent, aEvent ) +} + +// XWindowListener + +void OMRCListenerMultiplexerHelper::windowMoved(const WindowEvent& aEvent ) +{ + MULTIPLEX( XWindowListener, windowMoved, WindowEvent, aEvent ) +} + +// XWindowListener + +void OMRCListenerMultiplexerHelper::windowShown(const EventObject& aEvent ) +{ + MULTIPLEX( XWindowListener, windowShown, EventObject, aEvent ) +} + +// XWindowListener + +void OMRCListenerMultiplexerHelper::windowHidden(const EventObject& aEvent ) +{ + MULTIPLEX( XWindowListener, windowHidden, EventObject, aEvent ) +} + +// XKeyListener + +void OMRCListenerMultiplexerHelper::keyPressed(const KeyEvent& aEvent) +{ + MULTIPLEX( XKeyListener, keyPressed, KeyEvent, aEvent ) +} + +// XKeyListener + +void OMRCListenerMultiplexerHelper::keyReleased(const KeyEvent& aEvent) +{ + MULTIPLEX( XKeyListener, keyReleased, KeyEvent, aEvent ) +} + +// XMouseListener + +void OMRCListenerMultiplexerHelper::mousePressed(const MouseEvent& aEvent) +{ + MULTIPLEX( XMouseListener, mousePressed, MouseEvent, aEvent ) +} + +// XMouseListener + +void OMRCListenerMultiplexerHelper::mouseReleased(const MouseEvent& aEvent) +{ + MULTIPLEX( XMouseListener, mouseReleased, MouseEvent, aEvent ) +} + +// XMouseListener + +void OMRCListenerMultiplexerHelper::mouseEntered(const MouseEvent& aEvent) +{ + MULTIPLEX( XMouseListener, mouseEntered, MouseEvent, aEvent ) +} + +// XMouseListener + +void OMRCListenerMultiplexerHelper::mouseExited(const MouseEvent& aEvent) +{ + MULTIPLEX( XMouseListener, mouseExited, MouseEvent, aEvent ) +} + +// XMouseMotionListener + +void OMRCListenerMultiplexerHelper::mouseDragged(const MouseEvent& aEvent) +{ + MULTIPLEX( XMouseMotionListener, mouseDragged, MouseEvent, aEvent ) +} + +// XMouseMotionListener + +void OMRCListenerMultiplexerHelper::mouseMoved(const MouseEvent& aEvent) +{ + MULTIPLEX( XMouseMotionListener, mouseMoved, MouseEvent, aEvent ) +} + +// XPaintListener + +void OMRCListenerMultiplexerHelper::windowPaint(const PaintEvent& aEvent) +{ + MULTIPLEX( XPaintListener, windowPaint, PaintEvent, aEvent ) +} + +// XTopWindowListener + +void OMRCListenerMultiplexerHelper::windowOpened(const EventObject& aEvent) +{ + MULTIPLEX( XTopWindowListener, windowOpened, EventObject, aEvent ) +} + +// XTopWindowListener + +void OMRCListenerMultiplexerHelper::windowClosing( const EventObject& aEvent ) +{ + MULTIPLEX( XTopWindowListener, windowClosing, EventObject, aEvent ) +} + +// XTopWindowListener + +void OMRCListenerMultiplexerHelper::windowClosed( const EventObject& aEvent ) +{ + MULTIPLEX( XTopWindowListener, windowClosed, EventObject, aEvent ) +} + +// XTopWindowListener + +void OMRCListenerMultiplexerHelper::windowMinimized( const EventObject& aEvent ) +{ + MULTIPLEX( XTopWindowListener, windowMinimized, EventObject, aEvent ) +} + +// XTopWindowListener + +void OMRCListenerMultiplexerHelper::windowNormalized( const EventObject& aEvent ) +{ + MULTIPLEX( XTopWindowListener, windowNormalized, EventObject, aEvent ) +} + +// XTopWindowListener + +void OMRCListenerMultiplexerHelper::windowActivated( const EventObject& aEvent ) +{ + MULTIPLEX( XTopWindowListener, windowActivated, EventObject, aEvent ) +} + +// XTopWindowListener + +void OMRCListenerMultiplexerHelper::windowDeactivated( const EventObject& aEvent ) +{ + MULTIPLEX( XTopWindowListener, windowDeactivated, EventObject, aEvent ) +} + +// protected method + +void OMRCListenerMultiplexerHelper::impl_adviseToPeer( const Reference< XWindow >& xPeer , + const Type& aType ) +{ + // add a listener to the source (peer) + if( aType == cppu::UnoType<XWindowListener>::get()) + xPeer->addWindowListener( this ); + else if( aType == cppu::UnoType<XKeyListener>::get()) + xPeer->addKeyListener( this ); + else if( aType == cppu::UnoType<XFocusListener>::get()) + xPeer->addFocusListener( this ); + else if( aType == cppu::UnoType<XMouseListener>::get()) + xPeer->addMouseListener( this ); + else if( aType == cppu::UnoType<XMouseMotionListener>::get()) + xPeer->addMouseMotionListener( this ); + else if( aType == cppu::UnoType<XPaintListener>::get()) + xPeer->addPaintListener( this ); + else if( aType == cppu::UnoType<XTopWindowListener>::get()) + { + Reference< XTopWindow > xTop( xPeer, UNO_QUERY ); + if( xTop.is() ) + xTop->addTopWindowListener( this ); + } + else + { + OSL_FAIL( "unknown listener" ); + } +} + +// protected method + +void OMRCListenerMultiplexerHelper::impl_unadviseFromPeer( const Reference< XWindow >& xPeer , + const Type& aType ) +{ + // the last listener is removed, remove the listener from the source (peer) + if( aType == cppu::UnoType<XWindowListener>::get()) + xPeer->removeWindowListener( this ); + else if( aType == cppu::UnoType<XKeyListener>::get()) + xPeer->removeKeyListener( this ); + else if( aType == cppu::UnoType<XFocusListener>::get()) + xPeer->removeFocusListener( this ); + else if( aType == cppu::UnoType<XMouseListener>::get()) + xPeer->removeMouseListener( this ); + else if( aType == cppu::UnoType<XMouseMotionListener>::get()) + xPeer->removeMouseMotionListener( this ); + else if( aType == cppu::UnoType<XPaintListener>::get()) + xPeer->removePaintListener( this ); + else if( aType == cppu::UnoType<XTopWindowListener>::get()) + { + Reference< XTopWindow > xTop( xPeer, UNO_QUERY ); + if( xTop.is() ) + xTop->removeTopWindowListener( this ); + } + else + { + OSL_FAIL( "unknown listener" ); + } +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/base/registercontrols.cxx b/UnoControls/source/base/registercontrols.cxx new file mode 100644 index 000000000..40a51b8e8 --- /dev/null +++ b/UnoControls/source/base/registercontrols.cxx @@ -0,0 +1,122 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <comphelper/processfactory.hxx> +#include <cppuhelper/factory.hxx> + +#include <framecontrol.hxx> +#include <progressbar.hxx> +#include <progressmonitor.hxx> +#include <statusindicator.hxx> + +namespace com::sun::star::lang { class XMultiServiceFactory; } + +namespace { + +/// @throws css::uno::Exception +css::uno::Reference<css::uno::XInterface> FrameControl_createInstance( + css::uno::Reference<css::lang::XMultiServiceFactory> const & + rServiceManager) +{ + return static_cast<cppu::OWeakObject *>( + new unocontrols::FrameControl( + comphelper::getComponentContext(rServiceManager))); +} + +/// @throws css::uno::Exception +css::uno::Reference<css::uno::XInterface> ProgressBar_createInstance( + css::uno::Reference<css::lang::XMultiServiceFactory> const & + rServiceManager) +{ + return static_cast<cppu::OWeakObject *>( + new unocontrols::ProgressBar( + comphelper::getComponentContext(rServiceManager))); +} + +/// @throws css::uno::Exception +css::uno::Reference<css::uno::XInterface> +ProgressMonitor_createInstance( + css::uno::Reference<css::lang::XMultiServiceFactory> const & + rServiceManager) +{ + return static_cast<cppu::OWeakObject *>( + new unocontrols::ProgressMonitor( + comphelper::getComponentContext(rServiceManager))); +} + +/// @throws css::uno::Exception +css::uno::Reference<css::uno::XInterface> +StatusIndicator_createInstance( + css::uno::Reference<css::lang::XMultiServiceFactory> const & + rServiceManager) +{ + return static_cast<cppu::OWeakObject *>( + new unocontrols::StatusIndicator( + comphelper::getComponentContext(rServiceManager))); +} + +} + +extern "C" SAL_DLLPUBLIC_EXPORT void * ctl_component_getFactory( + char const * pImplName, void * pServiceManager, SAL_UNUSED_PARAMETER void *) +{ + css::uno::Reference<css::lang::XMultiServiceFactory > smgr( + static_cast<css::lang::XMultiServiceFactory *>(pServiceManager)); + css::uno::Reference<css::lang::XSingleServiceFactory> fac; + if (unocontrols::FrameControl::impl_getStaticImplementationName() + .equalsAscii(pImplName)) + { + fac = cppu::createSingleFactory( + smgr, unocontrols::FrameControl::impl_getStaticImplementationName(), + &FrameControl_createInstance, + unocontrols::FrameControl::impl_getStaticSupportedServiceNames()); + } else if (unocontrols::ProgressBar::impl_getStaticImplementationName() + .equalsAscii(pImplName)) + { + fac = cppu::createSingleFactory( + smgr, unocontrols::ProgressBar::impl_getStaticImplementationName(), + &ProgressBar_createInstance, + unocontrols::ProgressBar::impl_getStaticSupportedServiceNames()); + } else if (unocontrols::ProgressMonitor::impl_getStaticImplementationName() + .equalsAscii(pImplName)) + { + fac = cppu::createSingleFactory( + smgr, + unocontrols::ProgressMonitor::impl_getStaticImplementationName(), + &ProgressMonitor_createInstance, + unocontrols::ProgressMonitor::impl_getStaticSupportedServiceNames()); + } else if (unocontrols::StatusIndicator::impl_getStaticImplementationName() + .equalsAscii(pImplName)) + { + fac = cppu::createSingleFactory( + smgr, + unocontrols::StatusIndicator::impl_getStaticImplementationName(), + &StatusIndicator_createInstance, + unocontrols::StatusIndicator::impl_getStaticSupportedServiceNames()); + } + if (fac.is()) { + fac->acquire(); + } + return fac.get(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/OConnectionPointContainerHelper.cxx b/UnoControls/source/controls/OConnectionPointContainerHelper.cxx new file mode 100644 index 000000000..6d24cbb1f --- /dev/null +++ b/UnoControls/source/controls/OConnectionPointContainerHelper.cxx @@ -0,0 +1,140 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <OConnectionPointContainerHelper.hxx> + +#include <OConnectionPointHelper.hxx> + +#include <cppuhelper/queryinterface.hxx> + +// namespaces + +using namespace ::osl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +namespace unocontrols { + +// construct/destruct + +OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex& aMutex ) + : m_aSharedMutex ( aMutex ) + , m_aMultiTypeContainer ( aMutex ) +{ +} + +OConnectionPointContainerHelper::~OConnectionPointContainerHelper() +{ +} + +// XInterface + +Any SAL_CALL OConnectionPointContainerHelper::queryInterface( const Type& aType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Ask for my own supported interfaces ... + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XConnectionPointContainer* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = OWeakObject::queryInterface( aType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL OConnectionPointContainerHelper::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::acquire(); +} + +// XInterface + +void SAL_CALL OConnectionPointContainerHelper::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::release(); +} + +// XConnectionPointContainer + +Sequence< Type > SAL_CALL OConnectionPointContainerHelper::getConnectionPointTypes() +{ + // Container is threadsafe himself ! + return m_aMultiTypeContainer.getContainedTypes(); +} + +// XConnectionPointContainer + +Reference< XConnectionPoint > SAL_CALL OConnectionPointContainerHelper::queryConnectionPoint( const Type& aType ) +{ + // Set default return value, if method failed. + Reference< XConnectionPoint > xConnectionPoint; + + // Get all elements of the container, which have the searched type. + OInterfaceContainerHelper* pSpecialContainer = m_aMultiTypeContainer.getContainer( aType ); + if ( pSpecialContainer && pSpecialContainer->getLength() > 0 ) + { + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // If this container contains elements, build a connectionpoint-instance. + xConnectionPoint = new OConnectionPointHelper( m_aSharedMutex, this, aType ); + } + + return xConnectionPoint; +} + +// XConnectionPointContainer + +void SAL_CALL OConnectionPointContainerHelper::advise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Container is threadsafe himself ! + m_aMultiTypeContainer.addInterface( aType, xListener ); +} + +// XConnectionPointContainer + +void SAL_CALL OConnectionPointContainerHelper::unadvise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Container is threadsafe himself ! + m_aMultiTypeContainer.removeInterface( aType, xListener ); +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/OConnectionPointHelper.cxx b/UnoControls/source/controls/OConnectionPointHelper.cxx new file mode 100644 index 000000000..f2c99421d --- /dev/null +++ b/UnoControls/source/controls/OConnectionPointHelper.cxx @@ -0,0 +1,227 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <OConnectionPointHelper.hxx> + +#include <OConnectionPointContainerHelper.hxx> + +#include <com/sun/star/lang/InvalidListenerException.hpp> +#include <cppuhelper/queryinterface.hxx> + +// namespaces + +using namespace ::osl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; + +namespace unocontrols { + +// construct/destruct + +OConnectionPointHelper::OConnectionPointHelper( + Mutex& aMutex , + OConnectionPointContainerHelper* pContainerImplementation , + Type const & aType +) : m_aSharedMutex ( aMutex ) + , m_oContainerWeakReference ( pContainerImplementation ) + , m_pContainerImplementation ( pContainerImplementation ) + , m_aInterfaceType ( aType ) +{ +} + +OConnectionPointHelper::~OConnectionPointHelper() +{ +} + +// XInterface + +Any SAL_CALL OConnectionPointHelper::queryInterface( const Type& aType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Ask for my own supported interfaces ... + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XConnectionPoint* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = OWeakObject::queryInterface( aType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL OConnectionPointHelper::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::acquire(); +} + +// XInterface + +void SAL_CALL OConnectionPointHelper::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + OWeakObject::release(); +} + +// XConnectionPoint + +Type SAL_CALL OConnectionPointHelper::getConnectionType() +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + + // Set default return value, if method failed. + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + } + + // If container reference valid, return right type of supported interfaces of THIS connectionpoint. + Type aReturnType = m_aInterfaceType; + // Don't forget this! + impl_UnlockContainer(); + + return aReturnType; +} + +// XConnectionPoint + +Reference< XConnectionPointContainer > SAL_CALL OConnectionPointHelper::getConnectionPointContainer() +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed! + return Reference< XConnectionPointContainer >( m_oContainerWeakReference.get(), UNO_QUERY ); +} + +// XConnectionPoint + +void SAL_CALL OConnectionPointHelper::advise( const Reference< XInterface >& xListener ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + + // If type of listener not the same for this special container ... + Any aCheckType = xListener->queryInterface( m_aInterfaceType ); + if ( aCheckType.hasValue() ) + { + // ... throw an exception. + throw InvalidListenerException(); + } + + // ListenerExistException is obsolete!? + // It's the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!? + // You can add a listener more than one time at XConnectionPointContainer, but here only one ... + + // Operation is permitted only, if reference to container is valid! + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + } + // Forward it to OConnectionPointHelperContainer! + m_pContainerImplementation->advise( m_aInterfaceType, xListener ); + // Don't forget this! + impl_UnlockContainer(); +} + +// XConnectionPoint + +void SAL_CALL OConnectionPointHelper::unadvise( const Reference< XInterface >& xListener ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // Operation is permitted only, if reference to container is valid! + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + + } + // Forward it to OConnectionPointHelperContainer! + m_pContainerImplementation->unadvise( m_aInterfaceType, xListener ); + // Don't forget this! + impl_UnlockContainer(); +} + +// XConnectionPoint + +Sequence< Reference< XInterface > > SAL_CALL OConnectionPointHelper::getConnections() +{ + // Ready for multithreading + MutexGuard aGuard( m_aSharedMutex ); + // Operation is permitted only, if reference to container is valid! + if ( !impl_LockContainer() ) + { + throw RuntimeException("Container does not exist!"); + } + // Set default return value, if method failed. + Sequence< Reference< XInterface > > seqReturnConnections; + // Get reference to private member of OConnectionPointHelperContainer! + OMultiTypeInterfaceContainerHelper& aSharedContainer = m_pContainerImplementation->impl_getMultiTypeContainer(); + // Get pointer to specialized container which hold all interfaces of searched type. + OInterfaceContainerHelper* pSpecialContainer = aSharedContainer.getContainer( m_aInterfaceType ); + // Get elements of searched type, if some else exist. + if ( pSpecialContainer != nullptr ) + { + seqReturnConnections = pSpecialContainer->getElements(); + } + // Don't forget this! + impl_UnlockContainer(); + + return seqReturnConnections; +} + +// private method + +bool OConnectionPointHelper::impl_LockContainer() +{ + // Convert weakreference to hard uno3-reference and return state. + // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed. + // Don't forget to "unlock" this reference! + m_xLock = m_oContainerWeakReference.get(); + return m_xLock.is(); +} + +// private method + +void OConnectionPointHelper::impl_UnlockContainer() +{ + // Free hard uno3-reference to container. + // see also "impl_LockContainer()" + m_xLock.clear(); +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/framecontrol.cxx b/UnoControls/source/controls/framecontrol.cxx new file mode 100644 index 000000000..004facf6f --- /dev/null +++ b/UnoControls/source/controls/framecontrol.cxx @@ -0,0 +1,470 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <framecontrol.hxx> +#include <OConnectionPointContainerHelper.hxx> + +#include <com/sun/star/awt/XControlContainer.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/frame/Frame.hpp> +#include <com/sun/star/frame/FrameSearchFlag.hpp> +#include <com/sun/star/frame/XDispatch.hpp> +#include <com/sun/star/util/URLTransformer.hpp> +#include <com/sun/star/util/XURLTransformer.hpp> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> +#include <osl/diagnose.h> + +// namespaces + +using namespace ::osl; +using namespace ::cppu; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::frame; +using namespace ::com::sun::star::util; + +namespace unocontrols { + +namespace { + +enum PropertyHandle // values represent index in PropertyArray +{ // for FrameControl + Componenturl = 0, + Frame = 1, + Loaderarguments = 2 +}; + +} + +// construct/destruct + +FrameControl::FrameControl( const Reference< XComponentContext >& rxContext) + : BaseControl ( rxContext ) + , OBroadcastHelper ( m_aMutex ) + , OPropertySetHelper ( *static_cast< OBroadcastHelper * >(this) ) + , m_aConnectionPointContainer ( new OConnectionPointContainerHelper(m_aMutex) ) +{ +} + +FrameControl::~FrameControl() +{ +} + +// XInterface + +Any SAL_CALL FrameControl::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + Reference< XInterface > xDel = BaseControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL FrameControl::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface + +void SAL_CALL FrameControl::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider + +Sequence< Type > SAL_CALL FrameControl::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XControlContainer>::get(), + cppu::UnoType<XConnectionPointContainer>::get(), + BaseControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation + +Any SAL_CALL FrameControl::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XControlModel* > ( this ) , + static_cast< XConnectionPointContainer* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = OPropertySetHelper::queryInterface( aType ); + if ( !aReturn.hasValue() ) + { + aReturn = BaseControl::queryAggregation( aType ); + } + } + + return aReturn; +} + +OUString FrameControl::getImplementationName() +{ + return impl_getStaticImplementationName(); +} + +css::uno::Sequence<OUString> FrameControl::getSupportedServiceNames() +{ + return impl_getStaticSupportedServiceNames(); +} + +// XControl + +void SAL_CALL FrameControl::createPeer( const Reference< XToolkit >& xToolkit , + const Reference< XWindowPeer >& xParentPeer ) +{ + BaseControl::createPeer( xToolkit, xParentPeer ); + if ( impl_getPeerWindow().is() ) + { + if( !m_sComponentURL.isEmpty() ) + { + impl_createFrame( getPeer(), m_sComponentURL, m_seqLoaderArguments ); + } + } +} + +// XControl + +sal_Bool SAL_CALL FrameControl::setModel( const Reference< XControlModel >& /*xModel*/ ) +{ + // We have no model. + return false; +} + +// XControl + +Reference< XControlModel > SAL_CALL FrameControl::getModel() +{ + // We have no model. + return Reference< XControlModel >(); +} + +// XControl + +void SAL_CALL FrameControl::dispose() +{ + impl_deleteFrame(); + BaseControl::dispose(); +} + +// XView + +sal_Bool SAL_CALL FrameControl::setGraphics( const Reference< XGraphics >& /*xDevice*/ ) +{ + // it is not possible to print this control + return false; +} + +// XView + +Reference< XGraphics > SAL_CALL FrameControl::getGraphics() +{ + // when it's not possible to set graphics ! then it's possible to return null + return Reference< XGraphics >(); +} + +// XConnectionPointContainer + +Sequence< Type > SAL_CALL FrameControl::getConnectionPointTypes() +{ + // Forwarded to helper class + return m_aConnectionPointContainer->getConnectionPointTypes(); +} + +// XConnectionPointContainer + +Reference< XConnectionPoint > SAL_CALL FrameControl::queryConnectionPoint( const Type& aType ) +{ + // Forwarded to helper class + return m_aConnectionPointContainer->queryConnectionPoint( aType ); +} + +// XConnectionPointContainer + +void SAL_CALL FrameControl::advise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Forwarded to helper class + m_aConnectionPointContainer->advise( aType, xListener ); +} + +// XConnectionPointContainer + +void SAL_CALL FrameControl::unadvise( const Type& aType , + const Reference< XInterface >& xListener ) +{ + // Forwarded to helper class + m_aConnectionPointContainer->unadvise( aType, xListener ); +} + +// impl but public method to register service + +Sequence< OUString > FrameControl::impl_getStaticSupportedServiceNames() +{ + return { "com.sun.star.frame.FrameControl" }; +} + +// impl but public method to register service + +OUString FrameControl::impl_getStaticImplementationName() +{ + return "stardiv.UnoControls.FrameControl"; +} + +// OPropertySetHelper + +sal_Bool FrameControl::convertFastPropertyValue( Any& rConvertedValue , + Any& rOldValue , + sal_Int32 nHandle , + const Any& rValue ) +{ + bool bReturn = false; + switch (nHandle) + { + case PropertyHandle::Componenturl : rConvertedValue = rValue; + rOldValue <<= m_sComponentURL; + bReturn = true; + break; + + case PropertyHandle::Loaderarguments : rConvertedValue = rValue; + rOldValue <<= m_seqLoaderArguments; + bReturn = true; + break; + } + + if ( !bReturn ) + { + throw IllegalArgumentException(); + } + + return bReturn; +} + +// OPropertySetHelper + +void FrameControl::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle , + const Any& rValue ) +{ + // this method only set the value + MutexGuard aGuard (m_aMutex); + switch (nHandle) + { + case PropertyHandle::Componenturl : rValue >>= m_sComponentURL; + if (getPeer().is()) + { + impl_createFrame ( getPeer(), m_sComponentURL, m_seqLoaderArguments ); + } + break; + + case PropertyHandle::Loaderarguments : rValue >>= m_seqLoaderArguments; + break; + + default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." ); + } +} + +// OPropertySetHelper + +void FrameControl::getFastPropertyValue( Any& rRet , + sal_Int32 nHandle ) const +{ + MutexGuard aGuard ( Mutex::getGlobalMutex() ); + + switch (nHandle) + { + case PropertyHandle::Componenturl : rRet <<= m_sComponentURL; + break; + + case PropertyHandle::Loaderarguments : rRet <<= m_seqLoaderArguments; + break; + + case PropertyHandle::Frame : rRet <<= m_xFrame; + break; + + default : OSL_ENSURE ( nHandle == -1, "This is an invalid property handle." ); + } +} + +// OPropertySetHelper + +IPropertyArrayHelper& FrameControl::getInfoHelper() +{ + // Create a table that map names to index values. + // attention: properties need to be sorted by name! + static OPropertyArrayHelper ourPropertyInfo( + { + Property( "ComponentUrl", PropertyHandle::Componenturl, cppu::UnoType<OUString>::get(), + PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ), + Property( "Frame", PropertyHandle::Frame, cppu::UnoType<XFrame>::get(), + PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT ), + Property( "LoaderArguments", PropertyHandle::Loaderarguments, cppu::UnoType<Sequence<PropertyValue>>::get(), + PropertyAttribute::BOUND | PropertyAttribute::CONSTRAINED ) + }, + true ); + + return ourPropertyInfo; +} + +// OPropertySetHelper + +Reference< XPropertySetInfo > SAL_CALL FrameControl::getPropertySetInfo() +{ + // Create structure of propertysetinfo for baseclass "OPropertySetHelper". + // (Use method "getInfoHelper()".) + static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); + + return xInfo; +} + +// BaseControl + +WindowDescriptor FrameControl::impl_getWindowDescriptor( const Reference< XWindowPeer >& xParentPeer ) +{ + WindowDescriptor aDescriptor; + + aDescriptor.Type = WindowClass_CONTAINER; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = xParentPeer; + aDescriptor.Bounds = getPosSize (); + aDescriptor.WindowAttributes = 0; + + return aDescriptor; +} + +// private method + +void FrameControl::impl_createFrame( const Reference< XWindowPeer >& xPeer , + const OUString& rURL , + const Sequence< PropertyValue >& rArguments ) +{ + Reference< XFrame2 > xOldFrame; + Reference< XFrame2 > xNewFrame; + + { + MutexGuard aGuard ( m_aMutex ); + xOldFrame = m_xFrame; + } + + xNewFrame = Frame::create( impl_getComponentContext() ); + + Reference< XWindow > xWP ( xPeer, UNO_QUERY ); + xNewFrame->initialize ( xWP ); + + // option + //xFrame->setName( "WhatYouWant" ); + + Reference< XURLTransformer > xTrans = URLTransformer::create( impl_getComponentContext() ); + // load file + URL aURL; + aURL.Complete = rURL; + xTrans->parseStrict( aURL ); + + Reference< XDispatch > xDisp = xNewFrame->queryDispatch ( aURL, OUString (), FrameSearchFlag::SELF ); + if (xDisp.is()) + { + xDisp->dispatch ( aURL, rArguments ); + } + + // set the frame + { + MutexGuard aGuard ( m_aMutex ); + m_xFrame = xNewFrame; + } + + // notify the listeners + sal_Int32 nFrameId = PropertyHandle::Frame; + Any aNewFrame ( &xNewFrame, cppu::UnoType<XFrame>::get()); + Any aOldFrame ( &xOldFrame, cppu::UnoType<XFrame>::get()); + + fire ( &nFrameId, &aNewFrame, &aOldFrame, 1, false ); + + if (xOldFrame.is()) + { + xOldFrame->dispose (); + } +} + +// private method + +void FrameControl::impl_deleteFrame() +{ + Reference< XFrame2 > xOldFrame; + Reference< XFrame2 > xNullFrame; + + { + // do not dispose the frame in this guarded section (deadlock?) + MutexGuard aGuard( m_aMutex ); + xOldFrame = m_xFrame; + m_xFrame.clear(); + } + + // notify the listeners + sal_Int32 nFrameId = PropertyHandle::Frame; + Any aNewFrame( &xNullFrame, cppu::UnoType<XFrame2>::get()); + Any aOldFrame( &xOldFrame, cppu::UnoType<XFrame2>::get()); + fire( &nFrameId, &aNewFrame, &aOldFrame, 1, false ); + + // dispose the frame + if( xOldFrame.is() ) + xOldFrame->dispose(); +} + + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/progressbar.cxx b/UnoControls/source/controls/progressbar.cxx new file mode 100644 index 000000000..37ac9e379 --- /dev/null +++ b/UnoControls/source/controls/progressbar.cxx @@ -0,0 +1,410 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <progressbar.hxx> + +#include <com/sun/star/awt/XGraphics.hpp> +#include <tools/debug.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <limits.h> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; + +namespace unocontrols { + +// construct/destruct + +ProgressBar::ProgressBar( const Reference< XComponentContext >& rxContext ) + : BaseControl ( rxContext ) + , m_bHorizontal ( PROGRESSBAR_DEFAULT_HORIZONTAL ) + , m_aBlockSize ( PROGRESSBAR_DEFAULT_BLOCKDIMENSION ) + , m_nForegroundColor ( PROGRESSBAR_DEFAULT_FOREGROUNDCOLOR ) + , m_nBackgroundColor ( PROGRESSBAR_DEFAULT_BACKGROUNDCOLOR ) + , m_nMinRange ( PROGRESSBAR_DEFAULT_MINRANGE ) + , m_nMaxRange ( PROGRESSBAR_DEFAULT_MAXRANGE ) + , m_nBlockValue ( PROGRESSBAR_DEFAULT_BLOCKVALUE ) + , m_nValue ( PROGRESSBAR_DEFAULT_VALUE ) +{ +} + +ProgressBar::~ProgressBar() +{ +} + +// XInterface + +Any SAL_CALL ProgressBar::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + Reference< XInterface > xDel = BaseControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL ProgressBar::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface + +void SAL_CALL ProgressBar::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider + +Sequence< Type > SAL_CALL ProgressBar::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XControlModel>::get(), + cppu::UnoType<XProgressBar>::get(), + BaseControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation + +Any SAL_CALL ProgressBar::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XControlModel* > ( this ) , + static_cast< XProgressBar* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = BaseControl::queryAggregation( aType ); + } + + return aReturn; +} + +// XProgressBar + +void SAL_CALL ProgressBar::setForegroundColor( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // Safe color for later use. + m_nForegroundColor = Color(nColor); + + // Repaint control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); +} + +// XProgressBar + +void SAL_CALL ProgressBar::setBackgroundColor ( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // Safe color for later use. + m_nBackgroundColor = Color(nColor); + + // Repaint control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); +} + +// XProgressBar + +void SAL_CALL ProgressBar::setValue ( sal_Int32 nValue ) +{ + // This method is defined for follow things: + // 1) Values >= _nMinRange + // 2) Values <= _nMaxRange + + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // save impossible cases + // This method is only defined for valid values + DBG_ASSERT ( (( nValue >= m_nMinRange ) && ( nValue <= m_nMaxRange )), "ProgressBar::setValue()\nNot valid value.\n" ); + + // If new value not valid ... do nothing in release version! + if ( + ( nValue >= m_nMinRange ) && + ( nValue <= m_nMaxRange ) + ) + { + // New value is ok => save this + m_nValue = nValue; + + // Repaint to display changes + impl_paint ( 0, 0, impl_getGraphicsPeer() ); + } +} + +// XProgressBar + +void SAL_CALL ProgressBar::setRange ( sal_Int32 nMin, sal_Int32 nMax ) +{ + // This method is defined for follow things: + // 1) All values of sal_Int32 + // 2) Min < Max + // 3) Min > Max + + // save impossible cases + // This method is only defined for valid values + // If you ignore this, the release version will produce an error "division by zero" in "ProgressBar::setValue()"! + DBG_ASSERT ( ( nMin != nMax ) , "ProgressBar::setRange()\nValues for MIN and MAX are the same. This is not allowed!\n" ); + + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + // control the values for min and max + if ( nMin < nMax ) + { + // Take correct Min and Max + m_nMinRange = nMin; + m_nMaxRange = nMax; + } + else + { + // Change Min and Max automatically + m_nMinRange = nMax; + m_nMaxRange = nMin; + } + + // assure that m_nValue is within the range + if (!(m_nMinRange < m_nValue && m_nValue < m_nMaxRange)) + m_nValue = m_nMinRange; + + impl_recalcRange (); + + // Do not repaint the control at this place!!! + // An old "m_nValue" is set and can not be correct for this new range. + // Next call of "ProgressBar::setValue()" do this. +} + +// XProgressBar + +sal_Int32 SAL_CALL ProgressBar::getValue () +{ + // Ready for multithreading + MutexGuard aGuard (m_aMutex); + + return m_nValue; +} + +// XWindow + +void SAL_CALL ProgressBar::setPosSize ( + sal_Int32 nX, + sal_Int32 nY, + sal_Int32 nWidth, + sal_Int32 nHeight, + sal_Int16 nFlags +) +{ + // Take old size BEFORE you set the new values at baseclass! + // You will control changes. At the other way, the values are the same! + Rectangle aBasePosSize = getPosSize (); + BaseControl::setPosSize (nX, nY, nWidth, nHeight, nFlags); + + // Do only, if size has changed. + if ( + ( nWidth != aBasePosSize.Width ) || + ( nHeight != aBasePosSize.Height ) + ) + { + impl_recalcRange ( ); + impl_paint ( 0, 0, impl_getGraphicsPeer () ); + } +} + +// XControl + +sal_Bool SAL_CALL ProgressBar::setModel( const Reference< XControlModel >& /*xModel*/ ) +{ + // A model is not possible for this control. + return false; +} + +// XControl + +Reference< XControlModel > SAL_CALL ProgressBar::getModel() +{ + // A model is not possible for this control. + return Reference< XControlModel >(); +} + +// impl but public method to register service + +Sequence< OUString > ProgressBar::impl_getStaticSupportedServiceNames() +{ + return css::uno::Sequence<OUString>(); +} + +// impl but public method to register service + +OUString ProgressBar::impl_getStaticImplementationName() +{ + return "stardiv.UnoControls.ProgressBar"; +} + +// protected method + +void ProgressBar::impl_paint ( sal_Int32 nX, sal_Int32 nY, const Reference< XGraphics > & rGraphics ) +{ + // save impossible cases + DBG_ASSERT ( rGraphics.is(), "ProgressBar::paint()\nCalled with invalid Reference< XGraphics > ." ); + + // This paint method is not buffered !! + // Every request paint the completely control. ( but only, if peer exist ) + if ( rGraphics.is () ) + { + MutexGuard aGuard (m_aMutex); + + // Clear background + // (same color for line and fill) + rGraphics->setFillColor ( sal_Int32(m_nBackgroundColor) ); + rGraphics->setLineColor ( sal_Int32(m_nBackgroundColor) ); + rGraphics->drawRect ( nX, nY, impl_getWidth(), impl_getHeight() ); + + // same color for line and fill for blocks + rGraphics->setFillColor ( sal_Int32(m_nForegroundColor) ); + rGraphics->setLineColor ( sal_Int32(m_nForegroundColor) ); + + sal_Int32 nBlockStart = 0; // = left site of new block + sal_Int32 nBlockCount = m_nBlockValue!=0.00 ? static_cast<sal_Int32>((m_nValue-m_nMinRange)/m_nBlockValue) : 0; // = number of next block + + // Draw horizontal progressbar + // decision in "recalcRange()" + if (m_bHorizontal) + { + // Step to left side of window + nBlockStart = nX; + + for ( sal_Int32 i=1; i<=nBlockCount; ++i ) + { + // step free field + nBlockStart += PROGRESSBAR_FREESPACE; + // paint block + rGraphics->drawRect (nBlockStart, nY+PROGRESSBAR_FREESPACE, m_aBlockSize.Width, m_aBlockSize.Height); + // step next free field + nBlockStart += m_aBlockSize.Width; + } + } + // draw vertical progressbar + // decision in "recalcRange()" + else + { + // step to bottom side of window + nBlockStart = nY+impl_getHeight(); + nBlockStart -= m_aBlockSize.Height; + + for ( sal_Int32 i=1; i<=nBlockCount; ++i ) + { + // step free field + nBlockStart -= PROGRESSBAR_FREESPACE; + // paint block + rGraphics->drawRect (nX+PROGRESSBAR_FREESPACE, nBlockStart, m_aBlockSize.Width, m_aBlockSize.Height); + // step next free field + nBlockStart -= m_aBlockSize.Height; + } + } + + // Paint shadow border around the progressbar + rGraphics->setLineColor ( PROGRESSBAR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( nX, nY, impl_getWidth(), nY ); + rGraphics->drawLine ( nX, nY, nX , impl_getHeight() ); + + rGraphics->setLineColor ( PROGRESSBAR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 ); + } +} + +// protected method + +void ProgressBar::impl_recalcRange () +{ + MutexGuard aGuard (m_aMutex); + + sal_Int32 nWindowWidth = impl_getWidth(); + sal_Int32 nWindowHeight = impl_getHeight(); + double fBlockHeight; + double fBlockWidth; + double fMaxBlocks; + + if( nWindowWidth > nWindowHeight ) + { + m_bHorizontal = true; + fBlockHeight = (nWindowHeight-(2*PROGRESSBAR_FREESPACE)); + fBlockWidth = fBlockHeight; + fMaxBlocks = nWindowWidth/(fBlockWidth+PROGRESSBAR_FREESPACE); + } + else + { + m_bHorizontal = false; + fBlockWidth = (nWindowWidth-(2*PROGRESSBAR_FREESPACE)); + fBlockHeight = fBlockWidth; + fMaxBlocks = nWindowHeight/(fBlockHeight+PROGRESSBAR_FREESPACE); + } + + double fRange = m_nMaxRange-m_nMinRange; + double fBlockValue = fRange/fMaxBlocks; + + m_nBlockValue = fBlockValue; + m_aBlockSize.Height = static_cast<sal_Int32>(fBlockHeight); + m_aBlockSize.Width = static_cast<sal_Int32>(fBlockWidth); +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/progressmonitor.cxx b/UnoControls/source/controls/progressmonitor.cxx new file mode 100644 index 000000000..782782509 --- /dev/null +++ b/UnoControls/source/controls/progressmonitor.cxx @@ -0,0 +1,868 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <progressmonitor.hxx> + +#include <com/sun/star/awt/XFixedText.hpp> +#include <com/sun/star/awt/XGraphics.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/typeprovider.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <rtl/ustrbuf.hxx> +#include <tools/debug.hxx> +#include <algorithm> + +#include <progressbar.hxx> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; + +using ::std::vector; + +#define FIXEDTEXT_SERVICENAME "com.sun.star.awt.UnoControlFixedText" +#define FIXEDTEXT_MODELNAME "com.sun.star.awt.UnoControlFixedTextModel" +#define CONTROLNAME_TEXT "Text" // identifier the control in container +#define CONTROLNAME_PROGRESSBAR "ProgressBar" +#define BUTTON_SERVICENAME "com.sun.star.awt.UnoControlButton" +#define CONTROLNAME_BUTTON "Button" +#define BUTTON_MODELNAME "com.sun.star.awt.UnoControlButtonModel" +#define DEFAULT_BUTTONLABEL "Abbrechen" + +namespace unocontrols { + +ProgressMonitor::ProgressMonitor( const css::uno::Reference< XComponentContext >& rxContext ) + : BaseContainerControl ( rxContext ) +{ + // It's not allowed to work with member in this method (refcounter !!!) + // But with a HACK (++refcount) its "OK" :-( + osl_atomic_increment(&m_refCount); + + // Create instances for fixedtext, button and progress ... + + m_xTopic_Top.set ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xText_Top.set ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xTopic_Bottom.set( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xText_Bottom.set ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xButton.set ( rxContext->getServiceManager()->createInstanceWithContext( BUTTON_SERVICENAME, rxContext ), UNO_QUERY ); + m_xProgressBar = new ProgressBar(rxContext); + + // ... cast controls to Reference< XControl > (for "setModel"!) ... + css::uno::Reference< XControl > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Button ( m_xButton , UNO_QUERY ); + + // ... set models ... + xRef_Topic_Top->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Text_Top->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Topic_Bottom->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Text_Bottom->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + xRef_Button->setModel ( css::uno::Reference< XControlModel > ( rxContext->getServiceManager()->createInstanceWithContext( BUTTON_MODELNAME, rxContext ), UNO_QUERY ) ); + // ProgressBar has no model !!! + + // ... and add controls to basecontainercontrol! + addControl ( CONTROLNAME_TEXT, xRef_Topic_Top ); + addControl ( CONTROLNAME_TEXT, xRef_Text_Top ); + addControl ( CONTROLNAME_TEXT, xRef_Topic_Bottom ); + addControl ( CONTROLNAME_TEXT, xRef_Text_Bottom ); + addControl ( CONTROLNAME_BUTTON, xRef_Button ); + addControl ( CONTROLNAME_PROGRESSBAR, m_xProgressBar.get() ); + + // FixedText make it automatically visible by himself ... but not the progressbar !!! + // it must be set explicitly + m_xProgressBar->setVisible( true ); + + // Reset to defaults !!! + // (progressbar take automatically its own defaults) + m_xButton->setLabel ( DEFAULT_BUTTONLABEL ); + m_xTopic_Top->setText ( PROGRESSMONITOR_DEFAULT_TOPIC ); + m_xText_Top->setText ( PROGRESSMONITOR_DEFAULT_TEXT ); + m_xTopic_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TOPIC ); + m_xText_Bottom->setText ( PROGRESSMONITOR_DEFAULT_TEXT ); + + osl_atomic_decrement(&m_refCount); +} + +ProgressMonitor::~ProgressMonitor() +{ + impl_cleanMemory (); +} + +// XInterface +Any SAL_CALL ProgressMonitor::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + css::uno::Reference< XInterface > xDel = BaseContainerControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface +void SAL_CALL ProgressMonitor::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface +void SAL_CALL ProgressMonitor::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider +Sequence< Type > SAL_CALL ProgressMonitor::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XLayoutConstrains>::get(), + cppu::UnoType<XButton>::get(), + cppu::UnoType<XProgressMonitor>::get(), + BaseContainerControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation +Any SAL_CALL ProgressMonitor::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XLayoutConstrains* > ( this ) , + static_cast< XButton* > ( this ) , + static_cast< XProgressMonitor* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = BaseControl::queryAggregation( aType ); + } + + return aReturn; +} + +// XProgressMonitor +void SAL_CALL ProgressMonitor::addText( + const OUString& rTopic, + const OUString& rText, + sal_Bool bbeforeProgress +) +{ + // Safe impossible cases + // Check valid call of this method. + DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ), "ProgressMonitor::addText()\nCall without valid parameters!\n"); + DBG_ASSERT ( !(impl_searchTopic ( rTopic, bbeforeProgress ) != nullptr ), "ProgressMonitor::addText()\nThe text already exist.\n" ); + + // Do nothing (in Release), if topic already exist. + if ( impl_searchTopic ( rTopic, bbeforeProgress ) != nullptr ) + { + return; + } + + // Else ... take memory for new item ... + std::unique_ptr<IMPL_TextlistItem> pTextItem(new IMPL_TextlistItem); + + // Set values ... + pTextItem->sTopic = rTopic; + pTextItem->sText = rText; + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // ... and insert it in right list. + if ( bbeforeProgress ) + { + maTextlist_Top.push_back( std::move(pTextItem) ); + } + else + { + maTextlist_Bottom.push_back( std::move(pTextItem) ); + } + + // ... update window + impl_rebuildFixedText (); + impl_recalcLayout (); +} + +// XProgressMonitor +void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbeforeProgress ) +{ + // Safe impossible cases + // Check valid call of this method. + DBG_ASSERT ( impl_debug_checkParameter ( rTopic ), "ProgressMonitor::removeText()\nCall without valid parameters!" ); + + // Search the topic ... + IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress ); + + if ( pSearchItem != nullptr ) + { + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // ... delete item from right list ... + if ( bbeforeProgress ) + { + auto itr = std::find_if( maTextlist_Top.begin(), maTextlist_Top.end(), + [&] (std::unique_ptr<IMPL_TextlistItem> const &p) + { return p.get() == pSearchItem; } ); + if (itr != maTextlist_Top.end()) + maTextlist_Top.erase(itr); + } + else + { + auto itr = std::find_if( maTextlist_Bottom.begin(), maTextlist_Bottom.end(), + [&] (std::unique_ptr<IMPL_TextlistItem> const &p) + { return p.get() == pSearchItem; } ); + if (itr != maTextlist_Bottom.end()) + maTextlist_Bottom.erase(itr); + } + + delete pSearchItem; + + // ... and update window. + impl_rebuildFixedText (); + impl_recalcLayout (); + } +} + +// XProgressMonitor +void SAL_CALL ProgressMonitor::updateText ( + const OUString& rTopic, + const OUString& rText, + sal_Bool bbeforeProgress +) +{ + // Safe impossible cases + // Check valid call of this method. + DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ), "ProgressMonitor::updateText()\nCall without valid parameters!\n" ); + + // Search topic ... + IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress ); + + if ( pSearchItem != nullptr ) + { + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // ... update text ... + pSearchItem->sText = rText; + + // ... and update window. + impl_rebuildFixedText (); + impl_recalcLayout (); + } +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setForegroundColor ( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setForegroundColor ( nColor ); +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setBackgroundColor ( sal_Int32 nColor ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setBackgroundColor ( nColor ); +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setValue ( sal_Int32 nValue ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setValue ( nValue ); +} + +// XProgressBar +void SAL_CALL ProgressMonitor::setRange ( sal_Int32 nMin, sal_Int32 nMax ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + m_xProgressBar->setRange ( nMin, nMax ); +} + +// XProgressBar +sal_Int32 SAL_CALL ProgressMonitor::getValue () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + return m_xProgressBar->getValue (); +} + +// XButton +void SAL_CALL ProgressMonitor::addActionListener ( const css::uno::Reference< XActionListener > & rListener ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->addActionListener ( rListener ); + } +} + +// XButton +void SAL_CALL ProgressMonitor::removeActionListener ( const css::uno::Reference< XActionListener > & rListener ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->removeActionListener ( rListener ); + } +} + +// XButton +void SAL_CALL ProgressMonitor::setLabel ( const OUString& rLabel ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->setLabel ( rLabel ); + } +} + +// XButton +void SAL_CALL ProgressMonitor::setActionCommand ( const OUString& rCommand ) +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + if ( m_xButton.is () ) + { + m_xButton->setActionCommand ( rCommand ); + } +} + +// XLayoutConstrains +Size SAL_CALL ProgressMonitor::getMinimumSize () +{ + return Size (PROGRESSMONITOR_DEFAULT_WIDTH, PROGRESSMONITOR_DEFAULT_HEIGHT); +} + +// XLayoutConstrains +Size SAL_CALL ProgressMonitor::getPreferredSize () +{ + // Ready for multithreading + ClearableMutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + css::uno::Reference< XLayoutConstrains > xTopicLayout_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTopicLayout_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xButtonLayout ( m_xButton , UNO_QUERY ); + + Size aTopicSize_Top = xTopicLayout_Top->getPreferredSize (); + Size aTopicSize_Bottom = xTopicLayout_Bottom->getPreferredSize (); + Size aButtonSize = xButtonLayout->getPreferredSize (); + Rectangle aTempRectangle = m_xProgressBar->getPosSize(); + Size aProgressBarSize( aTempRectangle.Width, aTempRectangle.Height ); + + aGuard.clear (); + + // calc preferred size of progressmonitor + sal_Int32 nWidth = 3 * PROGRESSMONITOR_FREEBORDER; + nWidth += aProgressBarSize.Width; + + sal_Int32 nHeight = 6 * PROGRESSMONITOR_FREEBORDER; + nHeight += aTopicSize_Top.Height; + nHeight += aProgressBarSize.Height; + nHeight += aTopicSize_Bottom.Height; + nHeight += 2; // 1 for black line, 1 for white line = 3D-Line! + nHeight += aButtonSize.Height; + + // norm to minimum + if ( nWidth < PROGRESSMONITOR_DEFAULT_WIDTH ) + { + nWidth = PROGRESSMONITOR_DEFAULT_WIDTH; + } + if ( nHeight < PROGRESSMONITOR_DEFAULT_HEIGHT ) + { + nHeight = PROGRESSMONITOR_DEFAULT_HEIGHT; + } + + // return to caller + return Size ( nWidth, nHeight ); +} + +// XLayoutConstrains +Size SAL_CALL ProgressMonitor::calcAdjustedSize ( const Size& /*rNewSize*/ ) +{ + return getPreferredSize (); +} + +// XControl +void SAL_CALL ProgressMonitor::createPeer ( const css::uno::Reference< XToolkit > & rToolkit, const css::uno::Reference< XWindowPeer > & rParent ) +{ + if (!getPeer().is()) + { + BaseContainerControl::createPeer ( rToolkit, rParent ); + + // If user forget to call "setPosSize()", we have still a correct size. + // And a "MinimumSize" IS A "MinimumSize"! + // We change not the position of control at this point. + Size aDefaultSize = getMinimumSize (); + setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE ); + } +} + +// XControl +sal_Bool SAL_CALL ProgressMonitor::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ ) +{ + // We have no model. + return false; +} + +// XControl +css::uno::Reference< XControlModel > SAL_CALL ProgressMonitor::getModel () +{ + // We have no model. + // return (XControlModel*)this; + return css::uno::Reference< XControlModel > (); +} + +// XComponent +void SAL_CALL ProgressMonitor::dispose () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // "removeControl()" control the state of a reference + css::uno::Reference< XControl > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XControl > xRef_Button ( m_xButton , UNO_QUERY ); + + removeControl ( xRef_Topic_Top ); + removeControl ( xRef_Text_Top ); + removeControl ( xRef_Topic_Bottom ); + removeControl ( xRef_Text_Bottom ); + removeControl ( xRef_Button ); + removeControl ( m_xProgressBar.get() ); + + // don't use "...->clear ()" or "... = XFixedText ()" + // when other hold a reference at this object !!! + xRef_Topic_Top->dispose (); + xRef_Text_Top->dispose (); + xRef_Topic_Bottom->dispose (); + xRef_Text_Bottom->dispose (); + xRef_Button->dispose (); + m_xProgressBar->dispose(); + + BaseContainerControl::dispose (); +} + +// XWindow +void SAL_CALL ProgressMonitor::setPosSize ( sal_Int32 nX, sal_Int32 nY, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int16 nFlags ) +{ + Rectangle aBasePosSize = getPosSize (); + BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags); + + // if position or size changed + if ( + ( nWidth != aBasePosSize.Width ) || + ( nHeight != aBasePosSize.Height) + ) + { + // calc new layout for controls + impl_recalcLayout (); + // clear background (!) + // [Children were repainted in "recalcLayout" by setPosSize() automatically!] + getPeer()->invalidate(2); + // and repaint the control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); + } +} + +// impl but public method to register service +Sequence< OUString > ProgressMonitor::impl_getStaticSupportedServiceNames() +{ + return css::uno::Sequence<OUString>(); +} + +// impl but public method to register service +OUString ProgressMonitor::impl_getStaticImplementationName() +{ + return "stardiv.UnoControls.ProgressMonitor"; +} + +// protected method +void ProgressMonitor::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics ) +{ + if (rGraphics.is()) + { + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // paint shadowed border around the progressmonitor + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 ); + + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( nX, nY, impl_getWidth(), nY ); + rGraphics->drawLine ( nX, nY, nX , impl_getHeight() ); + + // Paint 3D-line + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y ); + + rGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 ); + } +} + +// private method +void ProgressMonitor::impl_recalcLayout () +{ + sal_Int32 nX_Button; + sal_Int32 nY_Button; + sal_Int32 nWidth_Button; + sal_Int32 nHeight_Button; + + sal_Int32 nX_ProgressBar; + sal_Int32 nY_ProgressBar; + sal_Int32 nWidth_ProgressBar; + sal_Int32 nHeight_ProgressBar; + + sal_Int32 nX_Text_Top; + sal_Int32 nY_Text_Top; + sal_Int32 nWidth_Text_Top; + sal_Int32 nHeight_Text_Top; + + sal_Int32 nX_Topic_Top; + sal_Int32 nY_Topic_Top; + sal_Int32 nWidth_Topic_Top; + sal_Int32 nHeight_Topic_Top; + + sal_Int32 nX_Text_Bottom; + sal_Int32 nY_Text_Bottom; + sal_Int32 nWidth_Text_Bottom; + sal_Int32 nHeight_Text_Bottom; + + sal_Int32 nX_Topic_Bottom; + sal_Int32 nY_Topic_Bottom; + sal_Int32 nWidth_Topic_Bottom; + sal_Int32 nHeight_Topic_Bottom; + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + css::uno::Reference< XLayoutConstrains > xTopicLayout_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTextLayout_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTopicLayout_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xTextLayout_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XLayoutConstrains > xButtonLayout ( m_xButton , UNO_QUERY ); + + Size aTopicSize_Top = xTopicLayout_Top->getPreferredSize (); + Size aTextSize_Top = xTextLayout_Top->getPreferredSize (); + Size aTopicSize_Bottom = xTopicLayout_Bottom->getPreferredSize (); + Size aTextSize_Bottom = xTextLayout_Bottom->getPreferredSize (); + Size aButtonSize = xButtonLayout->getPreferredSize (); + + // calc position and size of child controls + // Button has preferred size! + nWidth_Button = aButtonSize.Width; + nHeight_Button = aButtonSize.Height; + + // Left column before progressbar has preferred size and fixed position. + // But "Width" is oriented on left column below progressbar to!!! "max(...)" + nX_Topic_Top = PROGRESSMONITOR_FREEBORDER; + nY_Topic_Top = PROGRESSMONITOR_FREEBORDER; + nWidth_Topic_Top = std::max( aTopicSize_Top.Width, aTopicSize_Bottom.Width ); + nHeight_Topic_Top = aTopicSize_Top.Height; + + // Right column before progressbar has relative position to left column ... + // ... and a size as rest of dialog size! + nX_Text_Top = nX_Topic_Top+nWidth_Topic_Top+PROGRESSMONITOR_FREEBORDER; + nY_Text_Top = nY_Topic_Top; + nWidth_Text_Top = std::max ( aTextSize_Top.Width, aTextSize_Bottom.Width ); + // Fix size of this column to minimum! + sal_Int32 nSummaryWidth = nWidth_Text_Top+nWidth_Topic_Top+(3*PROGRESSMONITOR_FREEBORDER); + if ( nSummaryWidth < PROGRESSMONITOR_DEFAULT_WIDTH ) + nWidth_Text_Top = PROGRESSMONITOR_DEFAULT_WIDTH-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER); + // Fix size of column to maximum! + if ( nSummaryWidth > impl_getWidth() ) + nWidth_Text_Top = impl_getWidth()-nWidth_Topic_Top-(3*PROGRESSMONITOR_FREEBORDER); + nHeight_Text_Top = nHeight_Topic_Top; + + // Position of progressbar is relative to columns before. + // Progressbar.Width = Dialog.Width !!! + // Progressbar.Height = Button.Height + nX_ProgressBar = nX_Topic_Top; + nY_ProgressBar = nY_Topic_Top+nHeight_Topic_Top+PROGRESSMONITOR_FREEBORDER; + nWidth_ProgressBar = PROGRESSMONITOR_FREEBORDER+nWidth_Topic_Top+nWidth_Text_Top; + nHeight_ProgressBar = nHeight_Button; + + // Oriented by left column before progressbar. + nX_Topic_Bottom = nX_Topic_Top; + nY_Topic_Bottom = nY_ProgressBar+nHeight_ProgressBar+PROGRESSMONITOR_FREEBORDER; + nWidth_Topic_Bottom = nWidth_Topic_Top; + nHeight_Topic_Bottom = aTopicSize_Bottom.Height; + + // Oriented by right column before progressbar. + nX_Text_Bottom = nX_Topic_Bottom+nWidth_Topic_Bottom+PROGRESSMONITOR_FREEBORDER; + nY_Text_Bottom = nY_Topic_Bottom; + nWidth_Text_Bottom = nWidth_Text_Top; + nHeight_Text_Bottom = nHeight_Topic_Bottom; + + // Oriented by progressbar. + nX_Button = nX_ProgressBar+nWidth_ProgressBar-nWidth_Button; + nY_Button = nY_Topic_Bottom+nHeight_Topic_Bottom+PROGRESSMONITOR_FREEBORDER; + + // Calc offsets to center controls + sal_Int32 nDx; + sal_Int32 nDy; + + nDx = ( (2*PROGRESSMONITOR_FREEBORDER)+nWidth_ProgressBar ); + nDy = ( (6*PROGRESSMONITOR_FREEBORDER)+nHeight_Topic_Top+nHeight_ProgressBar+nHeight_Topic_Bottom+2+nHeight_Button ); + + // At this point use original dialog size to center controls! + nDx = (impl_getWidth ()/2)-(nDx/2); + nDy = (impl_getHeight()/2)-(nDy/2); + + if ( nDx<0 ) + { + nDx=0; + } + if ( nDy<0 ) + { + nDy=0; + } + + // Set new position and size on all controls + css::uno::Reference< XWindow > xRef_Topic_Top ( m_xTopic_Top , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Text_Top ( m_xText_Top , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Topic_Bottom ( m_xTopic_Bottom , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Text_Bottom ( m_xText_Bottom , UNO_QUERY ); + css::uno::Reference< XWindow > xRef_Button ( m_xButton , UNO_QUERY ); + + xRef_Topic_Top->setPosSize ( nDx+nX_Topic_Top , nDy+nY_Topic_Top , nWidth_Topic_Top , nHeight_Topic_Top , 15 ); + xRef_Text_Top->setPosSize ( nDx+nX_Text_Top , nDy+nY_Text_Top , nWidth_Text_Top , nHeight_Text_Top , 15 ); + xRef_Topic_Bottom->setPosSize ( nDx+nX_Topic_Bottom , nDy+nY_Topic_Bottom , nWidth_Topic_Bottom , nHeight_Topic_Bottom , 15 ); + xRef_Text_Bottom->setPosSize ( nDx+nX_Text_Bottom , nDy+nY_Text_Bottom , nWidth_Text_Bottom , nHeight_Text_Bottom , 15 ); + xRef_Button->setPosSize ( nDx+nX_Button , nDy+nY_Button , nWidth_Button , nHeight_Button , 15 ); + m_xProgressBar->setPosSize( nDx+nX_ProgressBar, nDy+nY_ProgressBar, nWidth_ProgressBar, nHeight_ProgressBar, 15 ); + + m_a3DLine.X = nDx+nX_Topic_Top; + m_a3DLine.Y = nDy+nY_Topic_Bottom+nHeight_Topic_Bottom+(PROGRESSMONITOR_FREEBORDER/2); + m_a3DLine.Width = nWidth_ProgressBar; + m_a3DLine.Height = nHeight_ProgressBar; + + // All childcontrols make an implicit repaint in setPosSize()! + // Make it also for this 3D-line ... + css::uno::Reference< XGraphics > xGraphics = impl_getGraphicsPeer (); + + xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_SHADOW ); + xGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y ); + + xGraphics->setLineColor ( PROGRESSMONITOR_LINECOLOR_BRIGHT ); + xGraphics->drawLine ( m_a3DLine.X, m_a3DLine.Y+1, m_a3DLine.X+m_a3DLine.Width, m_a3DLine.Y+1 ); +} + +// private method +void ProgressMonitor::impl_rebuildFixedText () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // Rebuild fixedtext before progress + + // Rebuild left site of text + if (m_xTopic_Top.is()) + { + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & pSearchItem : maTextlist_Top) + { + aCollectString.append(pSearchItem->sTopic).append("\n"); + } + + m_xTopic_Top->setText ( aCollectString.makeStringAndClear() ); + } + + // Rebuild right site of text + if (m_xText_Top.is()) + { + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & pSearchItem : maTextlist_Top) + { + aCollectString.append(pSearchItem->sText).append("\n"); + } + + m_xText_Top->setText ( aCollectString.makeStringAndClear() ); + } + + // Rebuild fixedtext below progress + + // Rebuild left site of text + if (m_xTopic_Bottom.is()) + { + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & pSearchItem : maTextlist_Bottom) + { + aCollectString.append(pSearchItem->sTopic).append("\n"); + } + + m_xTopic_Bottom->setText ( aCollectString.makeStringAndClear() ); + } + + // Rebuild right site of text + if (m_xText_Bottom.is()) + { + OUStringBuffer aCollectString; + + // Collect all topics from list and format text. + // "\n" MUST BE at the end of line!!! => Else ... topic and his text are not in the same line!!! + for (auto const & pSearchItem : maTextlist_Bottom) + { + aCollectString.append(pSearchItem->sText).append("\n"); + } + + m_xText_Bottom->setText ( aCollectString.makeStringAndClear() ); + } +} + +// private method +void ProgressMonitor::impl_cleanMemory () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // Delete all of lists. + maTextlist_Top.clear(); + maTextlist_Bottom.clear(); +} + +// private method +IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( const OUString& rTopic, bool bbeforeProgress ) +{ + // Get right textlist for following operations. + ::std::vector< std::unique_ptr<IMPL_TextlistItem> >* pTextList; + + // Ready for multithreading + { + MutexGuard aGuard(m_aMutex); + + if (bbeforeProgress) + { + pTextList = &maTextlist_Top; + } + else + { + pTextList = &maTextlist_Bottom; + } + } + // Switch off guard. + + // Search the topic in textlist. + size_t nPosition = 0; + size_t nCount = pTextList->size(); + + for ( nPosition = 0; nPosition < nCount; ++nPosition ) + { + auto pSearchItem = pTextList->at( nPosition ).get(); + + if ( pSearchItem->sTopic == rTopic ) + { + // We have found this topic... return a valid pointer. + return pSearchItem; + } + } + + // We haven't found this topic... return a nonvalid pointer. + return nullptr; +} + +// debug methods + +// addText, updateText +bool ProgressMonitor::impl_debug_checkParameter ( + const OUString& rTopic, + const OUString& rText +) { + if ( rTopic.isEmpty() ) return false; // "" + + if ( rText.isEmpty() ) return false; // "" + + // Parameter OK ... return true. + return true; +} + +// removeText +bool ProgressMonitor::impl_debug_checkParameter ( const OUString& rTopic ) +{ + if ( rTopic.isEmpty() ) return false; // "" + + // Parameter OK ... return true. + return true; +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/controls/statusindicator.cxx b/UnoControls/source/controls/statusindicator.cxx new file mode 100644 index 000000000..033c787d0 --- /dev/null +++ b/UnoControls/source/controls/statusindicator.cxx @@ -0,0 +1,462 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <statusindicator.hxx> + +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/awt/XFixedText.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <cppuhelper/queryinterface.hxx> +#include <cppuhelper/typeprovider.hxx> + +#include <progressbar.hxx> + +using namespace ::cppu; +using namespace ::osl; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::task; + +#define FIXEDTEXT_SERVICENAME "com.sun.star.awt.UnoControlFixedText" +#define FIXEDTEXT_MODELNAME "com.sun.star.awt.UnoControlFixedTextModel" +#define CONTROLNAME_TEXT "Text" // identifier the control in container +#define CONTROLNAME_PROGRESSBAR "ProgressBar" // -||- + +namespace unocontrols { + +// construct/destruct + +StatusIndicator::StatusIndicator( const css::uno::Reference< XComponentContext >& rxContext ) + : BaseContainerControl ( rxContext ) +{ + // It's not allowed to work with member in this method (refcounter !!!) + // But with a HACK (++refcount) its "OK" :-( + osl_atomic_increment(&m_refCount); + + // Create instances for fixedtext and progress ... + m_xText.set( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_SERVICENAME, rxContext ), UNO_QUERY ); + m_xProgressBar = new ProgressBar(rxContext); + // ... cast controls to css::uno::Reference< XControl > and set model ... + // ( ProgressBar has no model !!! ) + css::uno::Reference< XControl > xTextControl ( m_xText , UNO_QUERY ); + xTextControl->setModel( css::uno::Reference< XControlModel >( rxContext->getServiceManager()->createInstanceWithContext( FIXEDTEXT_MODELNAME, rxContext ), UNO_QUERY ) ); + // ... and add controls to basecontainercontrol! + addControl( CONTROLNAME_TEXT, xTextControl ); + addControl( CONTROLNAME_PROGRESSBAR, m_xProgressBar.get() ); + // FixedText make it automatically visible by himself ... but not the progressbar !!! + // it must be set explicitly + m_xProgressBar->setVisible( true ); + // Reset to defaults !!! + // (progressbar take automatically its own defaults) + m_xText->setText( "" ); + + osl_atomic_decrement(&m_refCount); +} + +StatusIndicator::~StatusIndicator() {} + +// XInterface + +Any SAL_CALL StatusIndicator::queryInterface( const Type& rType ) +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + Any aReturn; + css::uno::Reference< XInterface > xDel = BaseContainerControl::impl_getDelegator(); + if ( xDel.is() ) + { + // If a delegator exists, forward question to its queryInterface. + // Delegator will ask its own queryAggregation! + aReturn = xDel->queryInterface( rType ); + } + else + { + // If a delegator is unknown, forward question to own queryAggregation. + aReturn = queryAggregation( rType ); + } + + return aReturn; +} + +// XInterface + +void SAL_CALL StatusIndicator::acquire() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::acquire(); +} + +// XInterface + +void SAL_CALL StatusIndicator::release() throw() +{ + // Attention: + // Don't use mutex or guard in this method!!! Is a method of XInterface. + + // Forward to baseclass + BaseControl::release(); +} + +// XTypeProvider + +Sequence< Type > SAL_CALL StatusIndicator::getTypes() +{ + static OTypeCollection ourTypeCollection( + cppu::UnoType<XLayoutConstrains>::get(), + cppu::UnoType<XStatusIndicator>::get(), + BaseContainerControl::getTypes() ); + + return ourTypeCollection.getTypes(); +} + +// XAggregation + +Any SAL_CALL StatusIndicator::queryAggregation( const Type& aType ) +{ + // Ask for my own supported interfaces ... + // Attention: XTypeProvider and XInterface are supported by OComponentHelper! + Any aReturn ( ::cppu::queryInterface( aType , + static_cast< XLayoutConstrains* > ( this ) , + static_cast< XStatusIndicator* > ( this ) + ) + ); + + // If searched interface not supported by this class ... + if ( !aReturn.hasValue() ) + { + // ... ask baseclasses. + aReturn = BaseControl::queryAggregation( aType ); + } + + return aReturn; +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::start( const OUString& sText, sal_Int32 nRange ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Initialize status controls with given values. + m_xText->setText( sText ); + m_xProgressBar->setRange( 0, nRange ); + // force repaint ... fixedtext has changed ! + impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,impl_getWidth(),impl_getHeight(),0,0,0,0) ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::end() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Clear values of status controls. + m_xText->setText( OUString() ); + m_xProgressBar->setValue( 0 ); + setVisible( false ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::setText( const OUString& sText ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Take text on right control + m_xText->setText( sText ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::setValue( sal_Int32 nValue ) +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Take value on right control + m_xProgressBar->setValue( nValue ); +} + +// XStatusIndicator + +void SAL_CALL StatusIndicator::reset() +{ + // Ready for multithreading + MutexGuard aGuard( m_aMutex ); + + // Clear values of status controls. + // (Don't hide the window! User will reset current values ... but he will not finish using of indicator!) + m_xText->setText( OUString() ); + m_xProgressBar->setValue( 0 ); +} + +// XLayoutConstrains + +Size SAL_CALL StatusIndicator::getMinimumSize () +{ + return Size (STATUSINDICATOR_DEFAULT_WIDTH, STATUSINDICATOR_DEFAULT_HEIGHT); +} + +// XLayoutConstrains + +Size SAL_CALL StatusIndicator::getPreferredSize () +{ + // Ready for multithreading + ClearableMutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + css::uno::Reference< XLayoutConstrains > xTextLayout ( m_xText, UNO_QUERY ); + Size aTextSize = xTextLayout->getPreferredSize(); + + aGuard.clear (); + + // calc preferred size of status indicator + sal_Int32 nWidth = impl_getWidth(); + sal_Int32 nHeight = (2*STATUSINDICATOR_FREEBORDER)+aTextSize.Height; + + // norm to minimum + if ( nWidth<STATUSINDICATOR_DEFAULT_WIDTH ) + { + nWidth = STATUSINDICATOR_DEFAULT_WIDTH; + } + if ( nHeight<STATUSINDICATOR_DEFAULT_HEIGHT ) + { + nHeight = STATUSINDICATOR_DEFAULT_HEIGHT; + } + + // return to caller + return Size ( nWidth, nHeight ); +} + +// XLayoutConstrains + +Size SAL_CALL StatusIndicator::calcAdjustedSize ( const Size& /*rNewSize*/ ) +{ + return getPreferredSize (); +} + +// XControl + +void SAL_CALL StatusIndicator::createPeer ( + const css::uno::Reference< XToolkit > & rToolkit, + const css::uno::Reference< XWindowPeer > & rParent +) +{ + if( !getPeer().is() ) + { + BaseContainerControl::createPeer( rToolkit, rParent ); + + // If user forget to call "setPosSize()", we have still a correct size. + // And a "MinimumSize" IS A "MinimumSize"! + // We change not the position of control at this point. + Size aDefaultSize = getMinimumSize (); + setPosSize ( 0, 0, aDefaultSize.Width, aDefaultSize.Height, PosSize::SIZE ); + } +} + +// XControl + +sal_Bool SAL_CALL StatusIndicator::setModel ( const css::uno::Reference< XControlModel > & /*rModel*/ ) +{ + // We have no model. + return false; +} + +// XControl + +css::uno::Reference< XControlModel > SAL_CALL StatusIndicator::getModel () +{ + // We have no model. + // return (XControlModel*)this; + return css::uno::Reference< XControlModel > (); +} + +// XComponent + +void SAL_CALL StatusIndicator::dispose () +{ + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // "removeControl()" control the state of a reference + css::uno::Reference< XControl > xTextControl ( m_xText , UNO_QUERY ); + + removeControl( xTextControl ); + removeControl( m_xProgressBar.get() ); + + // don't use "...->clear ()" or "... = XFixedText ()" + // when other hold a reference at this object !!! + xTextControl->dispose(); + m_xProgressBar->dispose(); + BaseContainerControl::dispose(); +} + +// XWindow + +void SAL_CALL StatusIndicator::setPosSize ( + sal_Int32 nX, + sal_Int32 nY, + sal_Int32 nWidth, + sal_Int32 nHeight, + sal_Int16 nFlags +) +{ + Rectangle aBasePosSize = getPosSize (); + BaseContainerControl::setPosSize (nX, nY, nWidth, nHeight, nFlags); + + // if position or size changed + if ( + ( nWidth != aBasePosSize.Width ) || + ( nHeight != aBasePosSize.Height) + ) + { + // calc new layout for controls + impl_recalcLayout ( WindowEvent(static_cast< OWeakObject* >(this),0,0,nWidth,nHeight,0,0,0,0) ); + // clear background (!) + // [Children were repainted in "recalcLayout" by setPosSize() automatically!] + getPeer()->invalidate(2); + // and repaint the control + impl_paint ( 0, 0, impl_getGraphicsPeer() ); + } +} + +// impl but public method to register service + +Sequence< OUString > StatusIndicator::impl_getStaticSupportedServiceNames() +{ + return css::uno::Sequence<OUString>(); +} + +// impl but public method to register service + +OUString StatusIndicator::impl_getStaticImplementationName() +{ + return "stardiv.UnoControls.StatusIndicator"; +} + +// protected method + +WindowDescriptor StatusIndicator::impl_getWindowDescriptor( const css::uno::Reference< XWindowPeer >& xParentPeer ) +{ + WindowDescriptor aDescriptor; + + aDescriptor.Type = WindowClass_SIMPLE; + aDescriptor.WindowServiceName = "floatingwindow"; + aDescriptor.ParentIndex = -1; + aDescriptor.Parent = xParentPeer; + aDescriptor.Bounds = getPosSize (); + + return aDescriptor; +} + +// protected method + +void StatusIndicator::impl_paint ( sal_Int32 nX, sal_Int32 nY, const css::uno::Reference< XGraphics > & rGraphics ) +{ + // This paint method is not buffered! + // Every request paint the completely control. (But only, if peer exist) + if ( rGraphics.is () ) + { + MutexGuard aGuard (m_aMutex); + + // background = gray + css::uno::Reference< XWindowPeer > xPeer( impl_getPeerWindow(), UNO_QUERY ); + if( xPeer.is() ) + xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR ); + + // FixedText background = gray + css::uno::Reference< XControl > xTextControl( m_xText, UNO_QUERY ); + xPeer = xTextControl->getPeer(); + if( xPeer.is() ) + xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR ); + + // Progress background = gray + xPeer = m_xProgressBar->getPeer(); + if( xPeer.is() ) + xPeer->setBackground( STATUSINDICATOR_BACKGROUNDCOLOR ); + + // paint shadow border + rGraphics->setLineColor ( STATUSINDICATOR_LINECOLOR_BRIGHT ); + rGraphics->drawLine ( nX, nY, impl_getWidth(), nY ); + rGraphics->drawLine ( nX, nY, nX , impl_getHeight() ); + + rGraphics->setLineColor ( STATUSINDICATOR_LINECOLOR_SHADOW ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, impl_getWidth()-1, nY ); + rGraphics->drawLine ( impl_getWidth()-1, impl_getHeight()-1, nX , impl_getHeight()-1 ); + } +} + +// protected method + +void StatusIndicator::impl_recalcLayout ( const WindowEvent& aEvent ) +{ + sal_Int32 nX_ProgressBar; + sal_Int32 nY_ProgressBar; + sal_Int32 nWidth_ProgressBar; + sal_Int32 nHeight_ProgressBar; + sal_Int32 nX_Text; + sal_Int32 nY_Text; + sal_Int32 nWidth_Text; + sal_Int32 nHeight_Text; + + // Ready for multithreading + MutexGuard aGuard ( m_aMutex ); + + // get information about required place of child controls + Size aWindowSize ( aEvent.Width, aEvent.Height ); + css::uno::Reference< XLayoutConstrains > xTextLayout ( m_xText, UNO_QUERY ); + Size aTextSize = xTextLayout->getPreferredSize(); + + if( aWindowSize.Width < STATUSINDICATOR_DEFAULT_WIDTH ) + { + aWindowSize.Width = STATUSINDICATOR_DEFAULT_WIDTH; + } + if( aWindowSize.Height < STATUSINDICATOR_DEFAULT_HEIGHT ) + { + aWindowSize.Height = STATUSINDICATOR_DEFAULT_HEIGHT; + } + + // calc position and size of child controls + nX_Text = STATUSINDICATOR_FREEBORDER; + nY_Text = STATUSINDICATOR_FREEBORDER; + nWidth_Text = aTextSize.Width; + nHeight_Text = aTextSize.Height; + + nX_ProgressBar = nX_Text+nWidth_Text+STATUSINDICATOR_FREEBORDER; + nY_ProgressBar = nY_Text; + nWidth_ProgressBar = aWindowSize.Width-nWidth_Text-(3*STATUSINDICATOR_FREEBORDER); + nHeight_ProgressBar = nHeight_Text; + + // Set new position and size on all controls + css::uno::Reference< XWindow > xTextWindow ( m_xText , UNO_QUERY ); + + xTextWindow->setPosSize ( nX_Text , nY_Text , nWidth_Text , nHeight_Text , 15 ); + m_xProgressBar->setPosSize( nX_ProgressBar, nY_ProgressBar, nWidth_ProgressBar, nHeight_ProgressBar, 15 ); +} + +} // namespace unocontrols + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/inc/OConnectionPointContainerHelper.hxx b/UnoControls/source/inc/OConnectionPointContainerHelper.hxx new file mode 100644 index 000000000..a1a8a3417 --- /dev/null +++ b/UnoControls/source/inc/OConnectionPointContainerHelper.hxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/lang/XConnectionPointContainer.hpp> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/interfacecontainer.hxx> + +namespace com::sun::star::lang { class XConnectionPoint; } + +namespace unocontrols { + +class OConnectionPointContainerHelper final : public css::lang::XConnectionPointContainer + , public ::cppu::OWeakObject +{ +public: + OConnectionPointContainerHelper( ::osl::Mutex& aMutex ); + + virtual ~OConnectionPointContainerHelper() override; + + // XInterface + + /** + @short give answer, if interface is supported + @descr The interfaces are searched by type. + + @seealso XInterface + + @param "rType" is the type of searched interface. + + @return Any information about found interface + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + // XConnectionPointContainer + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getConnectionPointTypes() override; + + virtual css::uno::Reference< css::lang::XConnectionPoint > SAL_CALL queryConnectionPoint( + const css::uno::Type& aType + ) override; + + virtual void SAL_CALL advise( + const css::uno::Type& aType , + const css::uno::Reference< css::uno::XInterface >& xListener + ) override; + + virtual void SAL_CALL unadvise( + const css::uno::Type& aType , + const css::uno::Reference< css::uno::XInterface >& xListener + ) override; + + // public but impl method! + // Is necessary to get container member at OConnectionPoint-instance. + // Impl methods are not threadsafe! + // "Parent" function must do this. + ::cppu::OMultiTypeInterfaceContainerHelper& impl_getMultiTypeContainer() { return m_aMultiTypeContainer; } + +private: + ::osl::Mutex& m_aSharedMutex; + ::cppu::OMultiTypeInterfaceContainerHelper m_aMultiTypeContainer; // Container to hold listener +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/inc/OConnectionPointHelper.hxx b/UnoControls/source/inc/OConnectionPointHelper.hxx new file mode 100644 index 000000000..f075b071a --- /dev/null +++ b/UnoControls/source/inc/OConnectionPointHelper.hxx @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/lang/XConnectionPoint.hpp> +#include <cppuhelper/weak.hxx> +#include <cppuhelper/weakref.hxx> + +namespace com::sun::star::lang { class XConnectionPointContainer; } +namespace unocontrols { class OConnectionPointContainerHelper; } + +namespace unocontrols { + +class OConnectionPointHelper final : public css::lang::XConnectionPoint + , public ::cppu::OWeakObject +{ +public: + OConnectionPointHelper( ::osl::Mutex& aMutex , + OConnectionPointContainerHelper* pContainerImplementation , + css::uno::Type const & aType ); + + virtual ~OConnectionPointHelper() override; + + // XInterface + + /** + @short give answer, if interface is supported + @descr The interfaces are searched by type. + + @seealso XInterface + + @param "rType" is the type of searched interface. + + @return Any information about found interface + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + // XConnectionPoint + + virtual css::uno::Type SAL_CALL getConnectionType() override; + + virtual css::uno::Reference< css::lang::XConnectionPointContainer > SAL_CALL getConnectionPointContainer() override; + + virtual void SAL_CALL advise( + const css::uno::Reference< css::uno::XInterface >& xListener + ) override; + + virtual void SAL_CALL unadvise( const css::uno::Reference< css::uno::XInterface >& xListener ) override; + + virtual css::uno::Sequence< css::uno::Reference< css::uno::XInterface > > SAL_CALL getConnections() override; + +private: + bool impl_LockContainer(); + + void impl_UnlockContainer(); + +private: + + ::osl::Mutex& m_aSharedMutex; + css::uno::WeakReference< css::lang::XConnectionPointContainer > m_oContainerWeakReference; // Reference to container-class!. Don't use Reference<...> + // It is a ring-reference => and must be a wekreference! + OConnectionPointContainerHelper* m_pContainerImplementation; + css::uno::Type m_aInterfaceType; + css::uno::Reference< css::uno::XInterface > m_xLock; +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/inc/framecontrol.hxx b/UnoControls/source/inc/framecontrol.hxx new file mode 100644 index 000000000..dad27d8f8 --- /dev/null +++ b/UnoControls/source/inc/framecontrol.hxx @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/lang/XConnectionPointContainer.hpp> +#include <cppuhelper/propshlp.hxx> +#include <rtl/ref.hxx> + +#include <basecontrol.hxx> + +namespace com::sun::star::beans { struct PropertyValue; } +namespace com::sun::star::frame { class XFrame2; } +namespace unocontrols { class OConnectionPointContainerHelper; } + +namespace unocontrols { + +class FrameControl final : public css::awt::XControlModel + , public css::lang::XConnectionPointContainer + , public BaseControl // This order is necessary for right initialization of m_aMutex! + , public ::cppu::OBroadcastHelper + , public ::cppu::OPropertySetHelper +{ +public: + + FrameControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + + virtual ~FrameControl() override; + + // XInterface + + virtual css::uno::Any SAL_CALL queryInterface( + const css::uno::Type& aType + ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + // XTypeProvider + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; + + // XAggregation + + css::uno::Any SAL_CALL queryAggregation( + const css::uno::Type& aType + ) override; + + OUString SAL_CALL getImplementationName() override; + + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + + // XControl + + virtual void SAL_CALL createPeer( + const css::uno::Reference< css::awt::XToolkit >& xToolkit , + const css::uno::Reference< css::awt::XWindowPeer >& xParent + ) override; + + virtual sal_Bool SAL_CALL setModel( + const css::uno::Reference< css::awt::XControlModel >& xModel + ) override; + + virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override; + + // XComponent + + virtual void SAL_CALL dispose() override; + + // XView + + virtual sal_Bool SAL_CALL setGraphics( + const css::uno::Reference< css::awt::XGraphics >& xDevice + ) override; + + virtual css::uno::Reference< css::awt::XGraphics > SAL_CALL getGraphics() override; + + // XConnectionPointContainer + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getConnectionPointTypes() override; + + virtual css::uno::Reference< css::lang::XConnectionPoint > SAL_CALL queryConnectionPoint( + const css::uno::Type& aType + ) override; + + virtual void SAL_CALL advise( + const css::uno::Type& aType , + const css::uno::Reference< css::uno::XInterface >& xListener + ) override; + + virtual void SAL_CALL unadvise( + const css::uno::Type& aType , + const css::uno::Reference< css::uno::XInterface >& xListener + ) override; + + // impl but public methods to register service! + + static css::uno::Sequence< OUString > impl_getStaticSupportedServiceNames(); + + static OUString impl_getStaticImplementationName(); + +private: + + using OPropertySetHelper::getFastPropertyValue; + + // OPropertySetHelper + + virtual sal_Bool SAL_CALL convertFastPropertyValue( + css::uno::Any& rConvertedValue , + css::uno::Any& rOldValue , + sal_Int32 nHandle , + const css::uno::Any& rValue + ) override; + + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle , + const css::uno::Any& rValue + ) override; + + virtual void SAL_CALL getFastPropertyValue( css::uno::Any& rValue , + sal_Int32 nHandle ) const override; + + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override; + + // XPropertySet + + css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override; + + // BaseControl + + virtual css::awt::WindowDescriptor impl_getWindowDescriptor( + const css::uno::Reference< css::awt::XWindowPeer >& xParentPeer + ) override; + + void impl_createFrame( const css::uno::Reference< css::awt::XWindowPeer >& xPeer , + const OUString& sURL , + const css::uno::Sequence< css::beans::PropertyValue >& seqArguments ); + + void impl_deleteFrame(); + + css::uno::Reference< css::frame::XFrame2 > m_xFrame; + OUString m_sComponentURL; + css::uno::Sequence< css::beans::PropertyValue > m_seqLoaderArguments; + rtl::Reference<OConnectionPointContainerHelper> m_aConnectionPointContainer; + +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/inc/progressbar.hxx b/UnoControls/source/inc/progressbar.hxx new file mode 100644 index 000000000..a85fd731d --- /dev/null +++ b/UnoControls/source/inc/progressbar.hxx @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/awt/XProgressBar.hpp> + +#include <tools/color.hxx> + +#include <basecontrol.hxx> + +namespace unocontrols { + +#define PROGRESSBAR_FREESPACE 4 +#define PROGRESSBAR_DEFAULT_HORIZONTAL true +#define PROGRESSBAR_DEFAULT_BLOCKDIMENSION Size(1,1) +#define PROGRESSBAR_DEFAULT_BACKGROUNDCOLOR sal_Int32(Color( 0x00, 0xC0, 0xC0, 0xC0 )) // lightgray +#define PROGRESSBAR_DEFAULT_FOREGROUNDCOLOR sal_Int32(Color( 0x00, 0x00, 0x00, 0x80 )) // blue +#define PROGRESSBAR_DEFAULT_MINRANGE INT_MIN +#define PROGRESSBAR_DEFAULT_MAXRANGE INT_MAX +#define PROGRESSBAR_DEFAULT_BLOCKVALUE 1 +#define PROGRESSBAR_DEFAULT_VALUE PROGRESSBAR_DEFAULT_MINRANGE +#define PROGRESSBAR_LINECOLOR_BRIGHT sal_Int32(Color( 0x00, 0xFF, 0xFF, 0xFF )) // white +#define PROGRESSBAR_LINECOLOR_SHADOW sal_Int32(Color( 0x00, 0x00, 0x00, 0x00 )) // black + +class ProgressBar final : public css::awt::XControlModel + , public css::awt::XProgressBar + , public BaseControl +{ +public: + + ProgressBar( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + + virtual ~ProgressBar() override; + + // XInterface + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + // XTypeProvider + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; + + // XAggregation + + css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& aType ) override; + + // XProgressBar + + virtual void SAL_CALL setForegroundColor( sal_Int32 nColor ) override; + + virtual void SAL_CALL setBackgroundColor( sal_Int32 nColor ) override; + + virtual void SAL_CALL setValue( sal_Int32 nValue ) override; + + virtual void SAL_CALL setRange( + sal_Int32 nMin , + sal_Int32 nMax + ) override; + + virtual sal_Int32 SAL_CALL getValue() override; + + // XWindow + + virtual void SAL_CALL setPosSize( + sal_Int32 nX , + sal_Int32 nY , + sal_Int32 nWidth , + sal_Int32 nHeight , + sal_Int16 nFlags + ) override; + + // XControl + + virtual sal_Bool SAL_CALL setModel( + const css::uno::Reference< css::awt::XControlModel >& xModel + ) override; + + virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override; + + // BaseControl + + static css::uno::Sequence< OUString > impl_getStaticSupportedServiceNames(); + + static OUString impl_getStaticImplementationName(); + +private: + virtual void impl_paint( + sal_Int32 nX , + sal_Int32 nY , + const css::uno::Reference< css::awt::XGraphics >& xGraphics + ) override; + + void impl_recalcRange(); + + bool m_bHorizontal; // orientation for steps [true=horizontal/false=vertical] + css::awt::Size m_aBlockSize; // width and height of a block [>=0,0] + Color m_nForegroundColor; // (alpha,r,g,b) + Color m_nBackgroundColor; // (alpha,r,g,b) + sal_Int32 m_nMinRange; // lowest value = 0% [long, <_nMaxRange] + sal_Int32 m_nMaxRange; // highest value = 100% [long, >_nMinRange] + double m_nBlockValue; // value for one block [long, >0] + sal_Int32 m_nValue; // value for progress [long] + +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/inc/progressmonitor.hxx b/UnoControls/source/inc/progressmonitor.hxx new file mode 100644 index 000000000..779270205 --- /dev/null +++ b/UnoControls/source/inc/progressmonitor.hxx @@ -0,0 +1,254 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/awt/XProgressMonitor.hpp> +#include <com/sun/star/awt/XButton.hpp> +#include <com/sun/star/awt/XLayoutConstrains.hpp> +#include <rtl/ref.hxx> + +#include <vector> +#include <memory> + +#include <basecontainercontrol.hxx> + +namespace com::sun::star::awt { class XFixedText; } +namespace com::sun::star::awt { class XControlModel; } + +namespace unocontrols { + +class ProgressBar; + +#define PROGRESSMONITOR_FREEBORDER 10 // border around and between the controls +#define PROGRESSMONITOR_DEFAULT_TOPIC "" +#define PROGRESSMONITOR_DEFAULT_TEXT "" +#define PROGRESSMONITOR_LINECOLOR_BRIGHT sal_Int32(Color( 0x00, 0xFF, 0xFF, 0xFF )) // white +#define PROGRESSMONITOR_LINECOLOR_SHADOW sal_Int32(Color( 0x00, 0x00, 0x00, 0x00 )) // black +#define PROGRESSMONITOR_DEFAULT_WIDTH 350 +#define PROGRESSMONITOR_DEFAULT_HEIGHT 100 + +/// Item of TextList +struct IMPL_TextlistItem +{ + OUString sTopic; /// Left site of textline in dialog + OUString sText; /// Right site of textline in dialog +}; + +class ProgressMonitor final : public css::awt::XLayoutConstrains + , public css::awt::XButton + , public css::awt::XProgressMonitor + , public BaseContainerControl +{ +public: + ProgressMonitor( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + + virtual ~ProgressMonitor() override; + + // XInterface + + /** + @short give answer, if interface is supported + @descr The interfaces are searched by type. + + @seealso XInterface + + @param "rType" is the type of searched interface. + + @return Any information about found interface + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + // XTypeProvider + + /** + @short get information about supported interfaces + @seealso XTypeProvider + @return Sequence of types of all supported interfaces + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; + + // XAggregation + + virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& aType ) override; + + // XProgressMonitor + + /** + @short add topic to dialog + @descr Add a topic with a text in right textlist (used for FixedText-member).<BR> + ( "beforeProgress" fix the right list ). The dialog metric is recalculated. + + @seealso removeText(), updateText() + + @param sTopic Name of topic<BR> + [sTopic != "" && sTopic != NULL] + @param sText Value of topic<BR> + [sText != "" && sText != NULL] + @param bbeforeProgress Position of topic<BR> + [True => before progressbar / False => below progressbar] + @onerror DEBUG = Assertion<BR> + RELEASE = nothing + */ + + virtual void SAL_CALL addText( + const OUString& sTopic , + const OUString& sText , + sal_Bool bbeforeProgress + ) override; + + virtual void SAL_CALL removeText( + const OUString& sTopic , + sal_Bool bbeforeProgress + ) override; + + virtual void SAL_CALL updateText( + const OUString& sTopic , + const OUString& sText , + sal_Bool bbeforeProgress + ) override; + + // XProgressBar + + virtual void SAL_CALL setForegroundColor( sal_Int32 nColor ) override; + + virtual void SAL_CALL setBackgroundColor( sal_Int32 nColor ) override; + + virtual void SAL_CALL setValue( sal_Int32 nValue ) override; + + virtual void SAL_CALL setRange( sal_Int32 nMin , + sal_Int32 nMax ) override; + + virtual sal_Int32 SAL_CALL getValue() override; + + // XButton + + virtual void SAL_CALL addActionListener( + const css::uno::Reference< css::awt::XActionListener >& xListener + ) override; + + virtual void SAL_CALL removeActionListener( + const css::uno::Reference< css::awt::XActionListener >& xListener + ) override; + + virtual void SAL_CALL setLabel( const OUString& sLabel ) override; + + virtual void SAL_CALL setActionCommand( const OUString& sCommand ) override; + + // XLayoutConstrains + + virtual css::awt::Size SAL_CALL getMinimumSize() override; + + virtual css::awt::Size SAL_CALL getPreferredSize() override; + + virtual css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override; + + // XControl + + virtual void SAL_CALL createPeer( + const css::uno::Reference< css::awt::XToolkit >& xToolkit , + const css::uno::Reference< css::awt::XWindowPeer >& xParent + ) override; + + virtual sal_Bool SAL_CALL setModel( const css::uno::Reference< css::awt::XControlModel >& xModel ) override; + + virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override; + + // XComponent + + virtual void SAL_CALL dispose() override; + + // XWindow + + virtual void SAL_CALL setPosSize( sal_Int32 nX , + sal_Int32 nY , + sal_Int32 nWidth , + sal_Int32 nHeight , + sal_Int16 nFlags ) override; + + // BaseControl + + static css::uno::Sequence< OUString > impl_getStaticSupportedServiceNames(); + + static OUString impl_getStaticImplementationName(); + +private: + virtual void impl_paint( sal_Int32 nX , + sal_Int32 nY , + const css::uno::Reference< css::awt::XGraphics >& xGraphics ) override; + + using BaseControl::impl_recalcLayout; + + void impl_recalcLayout(); + + void impl_rebuildFixedText(); + + void impl_cleanMemory(); + + IMPL_TextlistItem* impl_searchTopic( const OUString& sTopic , bool bbeforeProgress ); + +// debug methods + + static bool impl_debug_checkParameter( const OUString& sTopic, const OUString& sText ); // addText, updateText + static bool impl_debug_checkParameter( const OUString& rTopic ); // removeText + +// private variables + +private: + ::std::vector < std::unique_ptr<IMPL_TextlistItem> > maTextlist_Top; // Elements before progress + css::uno::Reference< css::awt::XFixedText > m_xTopic_Top; // (used, if parameter "beforeProgress"=true in "addText, updateText, removeText") + css::uno::Reference< css::awt::XFixedText > m_xText_Top; + + ::std::vector < std::unique_ptr<IMPL_TextlistItem> > maTextlist_Bottom; // Elements below of progress + css::uno::Reference< css::awt::XFixedText > m_xTopic_Bottom; // (used, if parameter "beforeProgress"=false in "addText, updateText, removeText") + css::uno::Reference< css::awt::XFixedText > m_xText_Bottom; + + rtl::Reference<ProgressBar> m_xProgressBar; + css::uno::Reference< css::awt::XButton > m_xButton; + css::awt::Rectangle m_a3DLine; +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/source/inc/statusindicator.hxx b/UnoControls/source/inc/statusindicator.hxx new file mode 100644 index 000000000..658062c15 --- /dev/null +++ b/UnoControls/source/inc/statusindicator.hxx @@ -0,0 +1,178 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <com/sun/star/awt/XLayoutConstrains.hpp> +#include <com/sun/star/task/XStatusIndicator.hpp> +#include <rtl/ref.hxx> + +#include <basecontainercontrol.hxx> + +namespace com::sun::star::awt { class XControlModel; } +namespace com::sun::star::awt { class XFixedText; } +namespace com::sun::star::awt { class XGraphics; } +namespace com::sun::star::awt { class XToolkit; } +namespace com::sun::star::awt { class XWindowPeer; } + +namespace unocontrols { + +class ProgressBar; + +#define STATUSINDICATOR_FREEBORDER 5 // border around and between the controls +#define STATUSINDICATOR_BACKGROUNDCOLOR sal_Int32(Color( 0x00, 0xC0, 0xC0, 0xC0 )) // lightgray +#define STATUSINDICATOR_LINECOLOR_BRIGHT sal_Int32(Color( 0x00, 0xFF, 0xFF, 0xFF )) // white +#define STATUSINDICATOR_LINECOLOR_SHADOW sal_Int32(Color( 0x00, 0x00, 0x00, 0x00 )) // black +#define STATUSINDICATOR_DEFAULT_WIDTH 300 +#define STATUSINDICATOR_DEFAULT_HEIGHT 25 + +class StatusIndicator final : public css::awt::XLayoutConstrains + , public css::task::XStatusIndicator + , public BaseContainerControl +{ +public: + StatusIndicator( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + + virtual ~StatusIndicator() override; + + // XInterface + + /** + @short give answer, if interface is supported + @descr The interfaces are searched by type. + + @seealso XInterface + + @param "rType" is the type of searched interface. + + @return Any information about found interface + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; + + /** + @short increment refcount + @seealso XInterface + @seealso release() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL acquire() throw() override; + + /** + @short decrement refcount + @seealso XInterface + @seealso acquire() + @onerror A RuntimeException is thrown. + */ + + virtual void SAL_CALL release() throw() override; + + // XTypeProvider + + /** + @short get information about supported interfaces + @seealso XTypeProvider + @return Sequence of types of all supported interfaces + + @onerror A RuntimeException is thrown. + */ + + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override; + + // XAggregation + + virtual css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& aType ) override; + + // XStatusIndicator + + virtual void SAL_CALL start( + const OUString& sText , + sal_Int32 nRange + ) override; + + virtual void SAL_CALL end() override; + + virtual void SAL_CALL reset() override; + + virtual void SAL_CALL setText( const OUString& sText ) override; + + virtual void SAL_CALL setValue( sal_Int32 nValue ) override; + + // XLayoutConstrains + + virtual css::awt::Size SAL_CALL getMinimumSize() override; + + virtual css::awt::Size SAL_CALL getPreferredSize() override; + + virtual css::awt::Size SAL_CALL calcAdjustedSize( const css::awt::Size& aNewSize ) override; + + // XControl + + virtual void SAL_CALL createPeer( + const css::uno::Reference< css::awt::XToolkit >& xToolkit , + const css::uno::Reference< css::awt::XWindowPeer >& xParent + ) override; + + virtual sal_Bool SAL_CALL setModel( const css::uno::Reference< css::awt::XControlModel >& xModel ) override; + + virtual css::uno::Reference< css::awt::XControlModel > SAL_CALL getModel() override; + + // XComponent + + virtual void SAL_CALL dispose() override; + + // XWindow + + virtual void SAL_CALL setPosSize( sal_Int32 nX , + sal_Int32 nY , + sal_Int32 nWidth , + sal_Int32 nHeight , + sal_Int16 nFlags ) override; + + // BaseControl + + static css::uno::Sequence< OUString > impl_getStaticSupportedServiceNames(); + + static OUString impl_getStaticImplementationName(); + +private: + virtual css::awt::WindowDescriptor impl_getWindowDescriptor( + const css::uno::Reference< css::awt::XWindowPeer >& xParentPeer + ) override; + + virtual void impl_paint ( + sal_Int32 nX, + sal_Int32 nY, + const css::uno::Reference< css::awt::XGraphics > & rGraphics + ) override; + + virtual void impl_recalcLayout( const css::awt::WindowEvent& aEvent ) override; + + css::uno::Reference< css::awt::XFixedText > m_xText; + rtl::Reference<ProgressBar> m_xProgressBar; + +}; + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/UnoControls/util/ctl.component b/UnoControls/util/ctl.component new file mode 100644 index 000000000..3c0437d96 --- /dev/null +++ b/UnoControls/util/ctl.component @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + --> + +<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" + prefix="ctl" xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="stardiv.UnoControls.FrameControl"> + <service name="com.sun.star.frame.FrameControl"/> + </implementation> + <implementation name="stardiv.UnoControls.ProgressBar"/> + <implementation name="stardiv.UnoControls.ProgressMonitor"/> + <implementation name="stardiv.UnoControls.StatusIndicator"/> +</component> |