diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /include/dbaccess | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream/4%7.4.7.tar.xz libreoffice-upstream/4%7.4.7.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | include/dbaccess/AsynchronousLink.hxx | 60 | ||||
-rw-r--r-- | include/dbaccess/IController.hxx | 120 | ||||
-rw-r--r-- | include/dbaccess/controllerframe.hxx | 79 | ||||
-rw-r--r-- | include/dbaccess/dataview.hxx | 91 | ||||
-rw-r--r-- | include/dbaccess/dbaccessdllapi.h | 34 | ||||
-rw-r--r-- | include/dbaccess/dbaundomanager.hxx | 111 | ||||
-rw-r--r-- | include/dbaccess/dbsubcomponentcontroller.hxx | 208 | ||||
-rw-r--r-- | include/dbaccess/genericcontroller.hxx | 506 |
8 files changed, 1209 insertions, 0 deletions
diff --git a/include/dbaccess/AsynchronousLink.hxx b/include/dbaccess/AsynchronousLink.hxx new file mode 100644 index 000000000..0b63cbed9 --- /dev/null +++ b/include/dbaccess/AsynchronousLink.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <osl/mutex.hxx> +#include <tools/link.hxx> + +struct ImplSVEvent; + +namespace dbaui +{ + + // a helper for multi-threaded handling of async events + + /** handles asynchronous links which may be called in multi-threaded environments + If you use an instance of this class as member of your own class, it will handle + several crucial points for you (for instance the case that somebody posts the + event while another thread tries to delete this event in the _destructor_ of the + class). + */ + class OAsynchronousLink final + { + Link<void*,void> m_aHandler; + ::osl::Mutex m_aEventSafety; + ::osl::Mutex m_aDestructionSafety; + ImplSVEvent * m_nEventId; + DECL_LINK(OnAsyncCall, void*, void); + + public: + /** constructs the object + @param _rHandler The link to be called asynchronously + */ + OAsynchronousLink( const Link<void*,void>& _rHandler ); + ~OAsynchronousLink(); + + bool IsRunning() const { return m_nEventId != nullptr; } + + void Call( void* _pArgument = nullptr ); + void CancelCall(); + }; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/dbaccess/IController.hxx b/include/dbaccess/IController.hxx new file mode 100644 index 000000000..c7374eb80 --- /dev/null +++ b/include/dbaccess/IController.hxx @@ -0,0 +1,120 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_DBACCESS_ICONTROLLER_HXX +#define INCLUDED_DBACCESS_ICONTROLLER_HXX + +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <dbaccess/dbaccessdllapi.h> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace beans { + struct PropertyValue; + } + namespace util { + struct URL; + } + namespace frame { + class XController; + } +} + +class NotifyEvent; + +namespace dbaui +{ + // interface for controller depended calls like commands + class DBACCESS_DLLPUBLIC IController + { + public: + /** executes the given command without checking if it is allowed + @param _rCommand the URL of the command + */ + virtual void executeUnChecked(const css::util::URL& _rCommand, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) = 0; + + /** executes the given command only when it is allowed + @param _rCommand + the URL of the command + */ + virtual void executeChecked(const css::util::URL& _rCommand, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) = 0; + + /** executes the given command without checking if it is allowed + @param _nCommandId + the id of the command URL + */ + virtual void executeUnChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) = 0; + + /** executes the given command only when it is allowed + @param _nCommandId + the id of the command URL + */ + virtual void executeChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) = 0; + + + /** checks if the given Command is enabled + @param _nCommandId + the id of the command URL + + @return + <TRUE/> if the command is allowed, otherwise <FALSE/>. + */ + virtual bool isCommandEnabled(sal_uInt16 _nCommandId) const = 0; + + /** checks if the given Command is enabled + @param _rCompleteCommandURL + the URL of the command + + @return + <TRUE/> if the command is allowed, otherwise <FALSE/>. + */ + virtual bool isCommandEnabled( const OUString& _rCompleteCommandURL ) const = 0; + + /** checks if the selected data source is read only + @return + <TRUE/> if read only, otherwise <FALSE/> + */ + virtual bool isDataSourceReadOnly() const = 0; + + /** provides access to the model of the controller + + This must be the same model as returned by XController::getModel, and might be <NULL/> when + the controller does not have an own model. + + @throws css::uno::RuntimeException + */ + virtual css::uno::Reference< css::frame::XController > + getXController() = 0; + + /** allows interception of user input, aka mouse clicks and key events + */ + virtual bool interceptUserInput( const NotifyEvent& _rEvent ) = 0; + + virtual void SAL_CALL acquire( ) noexcept = 0; + virtual void SAL_CALL release( ) noexcept = 0; + + protected: + ~IController() {} + }; +} +#endif // INCLUDED_DBACCESS_ICONTROLLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/dbaccess/controllerframe.hxx b/include/dbaccess/controllerframe.hxx new file mode 100644 index 000000000..97a9c249d --- /dev/null +++ b/include/dbaccess/controllerframe.hxx @@ -0,0 +1,79 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_DBACCESS_CONTROLLERFRAME_HXX +#define INCLUDED_DBACCESS_CONTROLLERFRAME_HXX + +#include <memory> + +#include <com/sun/star/frame/FrameAction.hpp> +#include <com/sun/star/uno/Reference.hxx> + +namespace com::sun::star { + namespace frame { class XFrame; } +} + +namespace dbaui +{ + + + class IController; + + + //= ControllerFrame + + struct ControllerFrame_Data; + /** helper class to encapsulate the frame which a controller is plugged into, + doing some common actions on it. + */ + class ControllerFrame + { + public: + ControllerFrame( IController& _rController ); + ~ControllerFrame(); + + /// attaches a new frame + const css::uno::Reference< css::frame::XFrame >& + attachFrame( + const css::uno::Reference< css::frame::XFrame >& _rxFrame + ); + + // retrieves the current frame + const css::uno::Reference< css::frame::XFrame >& + getFrame() const; + + /** determines whether the frame is currently active + */ + bool isActive() const; + + /** notifies the instance that a certain frame action happened with our frame + */ + void frameAction( css::frame::FrameAction _eAction ); + + private: + ::std::unique_ptr< ControllerFrame_Data > m_pData; + }; + + +} // namespace dbaui + + +#endif // INCLUDED_DBACCESS_CONTROLLERFRAME_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/dbaccess/dataview.hxx b/include/dbaccess/dataview.hxx new file mode 100644 index 000000000..1c2cacdcf --- /dev/null +++ b/include/dbaccess/dataview.hxx @@ -0,0 +1,91 @@ +/* -*- 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 . + */ +#ifndef INCLUDED_DBACCESS_DATAVIEW_HXX +#define INCLUDED_DBACCESS_DATAVIEW_HXX + +#include <memory> + +#include <com/sun/star/uno/Reference.hxx> +#include <dbaccess/dbaccessdllapi.h> +#include <rtl/ref.hxx> +#include <tools/wintypes.hxx> +#include <vcl/outdev.hxx> +#include <vcl/window.hxx> + +namespace com::sun::star { + namespace frame { class XFrame; } + namespace uno { class XComponentContext; } +} + +namespace svt { + class AcceleratorExecute; +} + +class NotifyEvent; +namespace tools { class Rectangle; } + +namespace dbaui +{ + class IController; + class DBACCESS_DLLPUBLIC ODataView : public vcl::Window + { + css::uno::Reference< css::uno::XComponentContext > m_xContext; // the service factory to work with + + protected: + rtl::Reference<IController> m_xController; // the controller where we reside in + ::std::unique_ptr< ::svt::AcceleratorExecute> m_pAccel; + + public: + ODataView( vcl::Window* pParent, + IController& _rController, + const css::uno::Reference< css::uno::XComponentContext >& , + WinBits nStyle = 0 ); + virtual ~ODataView() override; + virtual void dispose() override; + + /// late construction + virtual void Construct(); + // initialize will be called when after the controller finished his initialize method + virtual void initialize(){} + // window overridables + virtual bool PreNotify( NotifyEvent& rNEvt ) override; + virtual void StateChanged( StateChangedType nStateChange ) override; + + IController& getCommandController() const { return *m_xController; } + + const css::uno::Reference< css::uno::XComponentContext >& getORB() const { return m_xContext;} + + // the default implementation simply calls resizeAll( GetSizePixel() ) + virtual void Resize() override; + + void attachFrame(const css::uno::Reference< css::frame::XFrame >& _xFrame); + protected: + // window overridables + virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& _rRect ) override; + + /// re-arrange all controls, including the toolbox, it's separator, and the "real view" + virtual void resizeAll( const tools::Rectangle& _rPlayground ); + + // re-arrange the controls belonging to the document itself + virtual void resizeDocumentView( tools::Rectangle& _rPlayground ); + }; +} +#endif // INCLUDED_DBACCESS_DATAVIEW_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/dbaccess/dbaccessdllapi.h b/include/dbaccess/dbaccessdllapi.h new file mode 100644 index 000000000..2f3771dce --- /dev/null +++ b/include/dbaccess/dbaccessdllapi.h @@ -0,0 +1,34 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_DBACCESS_DBACCESSDLLAPI_H +#define INCLUDED_DBACCESS_DBACCESSDLLAPI_H + +#include <sal/types.h> + +#if defined(DBACCESS_DLLIMPLEMENTATION) +#define DBACCESS_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define DBACCESS_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define DBACCESS_DLLPRIVATE SAL_DLLPRIVATE + +#endif // INCLUDED_DBACCESS_DBACCESSDLLAPI_H + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/dbaccess/dbaundomanager.hxx b/include/dbaccess/dbaundomanager.hxx new file mode 100644 index 000000000..364b91d6c --- /dev/null +++ b/include/dbaccess/dbaundomanager.hxx @@ -0,0 +1,111 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_DBACCESS_DBAUNDOMANAGER_HXX +#define INCLUDED_DBACCESS_DBAUNDOMANAGER_HXX + +#include <memory> + +#include <com/sun/star/document/XUndoManager.hpp> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <cppuhelper/implbase1.hxx> +#include <dbaccess/dbaccessdllapi.h> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace document { class XUndoAction; } + namespace document { class XUndoManagerListener; } + namespace uno { class XInterface; } +} + +namespace cppu { + class OWeakObject; +} + +namespace osl { + class Mutex; +} + +class SfxUndoManager; + + +namespace dbaui +{ + + + //= UndoManager + + struct UndoManager_Impl; + typedef ::cppu::ImplHelper1< css::document::XUndoManager > UndoManager_Base; + class DBACCESS_DLLPUBLIC UndoManager final : public UndoManager_Base + { + public: + UndoManager( ::cppu::OWeakObject& i_parent, ::osl::Mutex& i_mutex ); + virtual ~UndoManager(); + + SfxUndoManager& GetSfxUndoManager() const; + + // XInterface + virtual void SAL_CALL acquire( ) noexcept override; + virtual void SAL_CALL release( ) noexcept override; + + // XComponent equivalents + void disposing(); + + // XUndoManager + virtual void SAL_CALL enterUndoContext( const OUString& i_title ) override; + virtual void SAL_CALL enterHiddenUndoContext( ) override; + virtual void SAL_CALL leaveUndoContext( ) override; + virtual void SAL_CALL addUndoAction( const css::uno::Reference< css::document::XUndoAction >& i_action ) override; + virtual void SAL_CALL undo( ) override; + virtual void SAL_CALL redo( ) override; + virtual sal_Bool SAL_CALL isUndoPossible( ) override; + virtual sal_Bool SAL_CALL isRedoPossible( ) override; + virtual OUString SAL_CALL getCurrentUndoActionTitle( ) override; + virtual OUString SAL_CALL getCurrentRedoActionTitle( ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getAllUndoActionTitles( ) override; + virtual css::uno::Sequence< OUString > SAL_CALL getAllRedoActionTitles( ) override; + virtual void SAL_CALL clear( ) override; + virtual void SAL_CALL clearRedo( ) override; + virtual void SAL_CALL reset( ) override; + virtual void SAL_CALL addUndoManagerListener( const css::uno::Reference< css::document::XUndoManagerListener >& i_listener ) override; + virtual void SAL_CALL removeUndoManagerListener( const css::uno::Reference< css::document::XUndoManagerListener >& i_listener ) override; + + // XLockable (base of XUndoManager) + virtual void SAL_CALL lock( ) override; + virtual void SAL_CALL unlock( ) override; + virtual sal_Bool SAL_CALL isLocked( ) override; + + // XChild (base of XUndoManager) + virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getParent( ) override; + virtual void SAL_CALL setParent( const css::uno::Reference< css::uno::XInterface >& Parent ) override; + + private: + std::unique_ptr< UndoManager_Impl > m_xImpl; + }; + + +} // namespace dbaui + + +#endif // INCLUDED_DBACCESS_DBAUNDOMANAGER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/dbaccess/dbsubcomponentcontroller.hxx b/include/dbaccess/dbsubcomponentcontroller.hxx new file mode 100644 index 000000000..a1bc687ce --- /dev/null +++ b/include/dbaccess/dbsubcomponentcontroller.hxx @@ -0,0 +1,208 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_DBACCESS_DBSUBCOMPONENTCONTROLLER_HXX +#define INCLUDED_DBACCESS_DBSUBCOMPONENTCONTROLLER_HXX + +#include <memory> + +#include <com/sun/star/document/XScriptInvocationContext.hpp> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/uno/Type.hxx> +#include <com/sun/star/util/XModifiable.hpp> +#include <cppuhelper/implbase.hxx> +#include <dbaccess/dbaccessdllapi.h> +#include <dbaccess/genericcontroller.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> + +namespace com::sun::star { + namespace beans { class XPropertySet; } + namespace beans { struct PropertyValue; } + namespace document { class XEmbeddedScripts; } + namespace frame { class XModel; } + namespace sdbc { class XConnection; } + namespace sdbc { class XDatabaseMetaData; } + namespace uno { class XComponentContext; } + namespace util { class XModifyListener; } + namespace util { class XNumberFormatter; } +} + +namespace dbtools { + class DatabaseMetaData; + class SQLExceptionInfo; +} + +namespace dbaui +{ + //= DBSubComponentController + + typedef ::cppu::ImplInheritanceHelper< OGenericUnoController + , css::document::XScriptInvocationContext + , css::util::XModifiable + > DBSubComponentController_Base; + + struct DBSubComponentController_Impl; + class DBACCESS_DLLPUBLIC DBSubComponentController : public DBSubComponentController_Base + { + private: + ::std::unique_ptr<DBSubComponentController_Impl> m_pImpl; + + private: + /** forces usage of a connection which we do not own + <p>To be used from within XInitialization::initialize, resp. impl_initialize, only.</p> + */ + void initializeConnection( const css::uno::Reference< css::sdbc::XConnection >& _rxForeignConn ); + + protected: + // OGenericUnoController - initialization + virtual void impl_initialize() override; + + // OGenericUnoController + virtual void Execute(sal_uInt16 nId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override; + + virtual css::uno::Reference< css::frame::XModel > getPrivateModel() const override; + + bool impl_isModified() const; + virtual void impl_onModifyChanged(); + + public: + bool isReadOnly() const; + bool isEditable() const; + void setEditable(bool _bEditable); + + + // asking for connection-related stuff + + bool isConnected() const; + + css::uno::Reference< css::sdbc::XDatabaseMetaData > + getMetaData( ) const; + + + // access to the data source / document + OUString getDataSourceName() const; + const css::uno::Reference< css::beans::XPropertySet >& + getDataSource() const; + bool haveDataSource() const; + + css::uno::Reference< css::frame::XModel > + getDatabaseDocument() const; + + /** provides access to the SDB-level database meta data of the current connection + */ + const ::dbtools::DatabaseMetaData& getSdbMetaData() const; + + /** appends an error in the current environment. + */ + void appendError( const OUString& _rErrorMessage ); + + /** clears the error state. + */ + void clearError(); + + /** @return + <TRUE/> when an error was set otherwise <FALSE/> + */ + bool hasError() const; + + /** returns the current error + */ + const ::dbtools::SQLExceptionInfo& getError() const; + + /** displays the current error, or does nothing if there is no current error + */ + void displayError(); + + /** shows an info box with the string conntection lost. + */ + void connectionLostMessage() const; + + /** gives access to the currently used connection + @return + the currently used connection. + */ + const css::uno::Reference< css::sdbc::XConnection >& + getConnection() const; + + /** returns the number formatter + */ + css::uno::Reference< css::util::XNumberFormatter > const & getNumberFormatter() const; + + // css::frame::XController + virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override; + virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > & xModel) override; + + // XScriptInvocationContext + virtual css::uno::Reference< css::document::XEmbeddedScripts > SAL_CALL getScriptContainer() override; + + // XModifiable + virtual sal_Bool SAL_CALL isModified( ) override; + virtual void SAL_CALL setModified( sal_Bool bModified ) override; + + // XModifyBroadcaster + virtual void SAL_CALL addModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override; + virtual void SAL_CALL removeModifyListener( const css::uno::Reference< css::util::XModifyListener >& aListener ) override; + + // XTitle + virtual OUString SAL_CALL getTitle( ) override; + + protected: + DBSubComponentController(const css::uno::Reference< css::uno::XComponentContext>& _rxORB); + virtual ~DBSubComponentController() override; + + void disconnect(); + virtual void reconnect( bool _bUI ); + bool ensureConnected() { + if ( !isConnected() ) reconnect( false ); + return isConnected(); + } + + /** called when our connection is being disposed + <p>The default implementation does a reconnect</p> + */ + virtual void losingConnection( ); + + protected: + // XEventListener + virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override; + + // OComponentHelper + virtual void SAL_CALL disposing() override; + + // XInterface + virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override; + + // XTypeProvider + virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ) override; + + protected: + sal_Int32 getCurrentStartNumber() const; + }; + + +} // namespace dbaui + + +#endif // INCLUDED_DBACCESS_DBSUBCOMPONENTCONTROLLER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/dbaccess/genericcontroller.hxx b/include/dbaccess/genericcontroller.hxx new file mode 100644 index 000000000..50b939791 --- /dev/null +++ b/include/dbaccess/genericcontroller.hxx @@ -0,0 +1,506 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_DBACCESS_GENERICCONTROLLER_HXX +#define INCLUDED_DBACCESS_GENERICCONTROLLER_HXX + +#include <sal/config.h> + +#include <deque> +#include <map> +#include <memory> +#include <vector> + +#include <optional> + +#include <com/sun/star/awt/XUserInputInterception.hpp> +#include <com/sun/star/frame/CommandGroup.hpp> +#include <com/sun/star/frame/DispatchInformation.hpp> +#include <com/sun/star/frame/XController2.hpp> +#include <com/sun/star/frame/XDispatch.hpp> +#include <com/sun/star/frame/XDispatchInformationProvider.hpp> +#include <com/sun/star/frame/XDispatchProviderInterceptor.hpp> +#include <com/sun/star/frame/XLayoutManager.hpp> +#include <com/sun/star/frame/XTitle.hpp> +#include <com/sun/star/frame/XTitleChangeBroadcaster.hpp> +#include <com/sun/star/lang/EventObject.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/Any.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/util/URL.hpp> +#include <com/sun/star/util/XModifyListener.hpp> +#include <comphelper/sharedmutex.hxx> +#include <comphelper/namedvaluecollection.hxx> +#include <connectivity/dbexception.hxx> +#include <cppuhelper/compbase.hxx> +#include <cppuhelper/interfacecontainer.h> +#include <dbaccess/AsynchronousLink.hxx> +#include <dbaccess/controllerframe.hxx> +#include <dbaccess/dbaccessdllapi.h> +#include <dbaccess/IController.hxx> +#include <osl/mutex.hxx> +#include <rtl/ustring.hxx> +#include <sal/types.h> +#include <tools/link.hxx> +#include <vcl/vclptr.hxx> + +namespace com::sun::star { + namespace awt { class XKeyHandler; } + namespace awt { class XMouseClickHandler; } + namespace awt { class XWindow; } + namespace beans { struct PropertyValue; } + namespace frame { class XController; } + namespace frame { class XDispatchProvider; } + namespace frame { class XFrame; } + namespace frame { class XFrameActionListener; } + namespace frame { class XModel; } + namespace frame { class XStatusListener; } + namespace frame { class XTitleChangeListener; } + namespace frame { struct DispatchDescriptor; } + namespace frame { struct FrameActionEvent; } + namespace lang { class XEventListener; } + namespace sdb { class XDatabaseContext; } + namespace sdbc { class XConnection; } + namespace sdbc { class XDataSource; } + namespace ui { class XSidebarProvider; } + namespace uno { class XComponentContext; } + namespace util { class XURLTransformer; } +} + +namespace vcl { class Window; } +namespace weld { class Window; } +class NotifyEvent; + +namespace dbaui +{ + class ODataView; + + template< typename T > + inline bool SAL_CALL operator >>= (const css::uno::Any& _any, std::optional< T >& _value) + { + _value.reset(); // de-init the optional value + + T directValue = T(); + if ( _any >>= directValue ) + _value = directValue; + + return !!_value; + } + + + // = FeatureState + + /** describes the state of a feature + + In opposite to the FeatureStateEvent in css.frame, this one allows for multiple states to be specified at once. + With this, you can for instance specify that a toolbox item is checked, and has a certain title, at the same + time. + */ + struct FeatureState + { + bool bEnabled; + + std::optional<bool> bChecked; + std::optional<bool> bInvisible; + css::uno::Any aValue; + std::optional<OUString> sTitle; + + FeatureState() : bEnabled(false) { } + }; + + + // = helper + + + struct ControllerFeature : public css::frame::DispatchInformation + { + sal_uInt16 nFeatureId; + }; + + + typedef ::std::map < OUString + , ControllerFeature + , ::std::less< OUString > + > SupportedFeatures; + + + class CompareFeatureById + { + const sal_Int32 m_nId; + public: + CompareFeatureById(sal_Int32 _nId) : m_nId(_nId) + {} + + bool operator()( const SupportedFeatures::value_type& _aType ) const + { + return m_nId == _aType.second.nFeatureId; + } + }; + + + struct FeatureListener + { + css::uno::Reference< css::frame::XStatusListener > + xListener; + sal_Int32 nId; + bool bForceBroadcast; + }; + + + class FindFeatureListener + { + const css::uno::Reference< css::frame::XStatusListener >& m_xListener; + public: + FindFeatureListener(const css::uno::Reference< css::frame::XStatusListener >& _xListener) + : m_xListener(_xListener) + {} + + bool operator()( const FeatureListener& lhs ) const + { + return lhs.xListener == m_xListener; + } + }; + + + typedef ::comphelper::SharedMutexBase OGenericUnoController_MBASE; + + typedef ::cppu::WeakComponentImplHelper< css::frame::XDispatch + , css::frame::XDispatchProviderInterceptor + , css::util::XModifyListener + , css::frame::XFrameActionListener + , css::lang::XInitialization + , css::lang::XServiceInfo + , css::frame::XDispatchInformationProvider + , css::frame::XController2 + , css::frame::XTitle + , css::frame::XTitleChangeBroadcaster + , css::awt::XUserInputInterception + > OGenericUnoController_Base; + + struct OGenericUnoController_Data; + + class DBACCESS_DLLPUBLIC OGenericUnoController + :public OGenericUnoController_MBASE + ,public OGenericUnoController_Base + ,public IController + { + private: + SupportedFeatures m_aSupportedFeatures; + ::comphelper::NamedValueCollection + m_aInitParameters; + + ::std::unique_ptr< OGenericUnoController_Data > + m_pData; + VclPtr<ODataView> m_pView; // our (VCL) "main window" + +#ifdef DBG_UTIL + bool m_bDescribingSupportedFeatures; +#endif + + protected: + + // attributes + struct DispatchTarget + { + css::util::URL aURL; + css::uno::Reference< css::frame::XStatusListener > xListener; + + DispatchTarget(const css::util::URL& rURL, const css::uno::Reference< css::frame::XStatusListener >& rRef) : aURL(rURL), xListener(rRef) { } + }; + + typedef std::map<sal_uInt16, FeatureState> StateCache; + typedef std::vector<DispatchTarget> Dispatch; + + ::std::deque< FeatureListener > + m_aFeaturesToInvalidate; + + ::osl::Mutex m_aFeatureMutex; // locked when features are append to or remove from deque + StateCache m_aStateCache; // save the current status of feature state + Dispatch m_arrStatusListener; // all our listeners where we dispatch status changes + OAsynchronousLink m_aAsyncInvalidateAll; + OAsynchronousLink m_aAsyncCloseTask; // called when a task should be closed + + css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer; // needed sometimes + css::uno::Reference< css::uno::XComponentContext > m_xContext; + ControllerFrame m_aCurrentFrame; + css::uno::Reference< css::frame::XDispatchProvider > m_xSlaveDispatcher; // for intercepting dispatches + css::uno::Reference< css::frame::XDispatchProvider > m_xMasterDispatcher; // ditto + css::uno::Reference< css::sdb::XDatabaseContext > m_xDatabaseContext; + css::uno::Reference< css::frame::XTitle > m_xTitleHelper; + + bool m_bPreview; + bool m_bReadOnly; + + bool m_bCurrentlyModified : 1; + bool m_bExternalTitle : 1; + + + // attribute access + using OGenericUnoController_MBASE::getMutex; + ::cppu::OBroadcastHelper& getBroadcastHelper() { return OGenericUnoController_Base::rBHelper; } + + + // methods + OGenericUnoController( const css::uno::Reference< css::uno::XComponentContext >& _rM ); + OGenericUnoController() = delete; + const ::comphelper::NamedValueCollection& + getInitParams() const { return m_aInitParameters; } + + // closes the task when possible + void closeTask(); + + // if getMenu returns a non empty string than this will be dispatched at the frame + virtual void loadMenu(const css::uno::Reference< css::frame::XFrame >& _xFrame); + + /** called when our menu has been loaded into our frame, can be used to load sub toolbars + + @param _xLayoutManager + The layout manager. + */ + virtual void onLoadedMenu(const css::uno::Reference< css::frame::XLayoutManager >& _xLayoutManager); + + // all the features which should be handled by this class + virtual void describeSupportedFeatures(); + + // state of a feature. 'feature' may be the handle of a css::util::URL somebody requested a dispatch interface for OR a toolbar slot. + virtual FeatureState GetState(sal_uInt16 nId) const; + // execute a feature + virtual void Execute(sal_uInt16 nId , const css::uno::Sequence< css::beans::PropertyValue>& aArgs); + + /** describes a feature supported by the controller + + Must not be called outside <member>describeSupportedFeatures</member>. + + @param _rCommandURL + the URL of the feature command + @param _nFeatureId + the id of the feature. Later references to this feature usually happen by id, not by + URL + @param _nCommandGroup + the command group of the feature. This is important for configuring the controller UI + by the user, see also <type scope="css::frame">CommandGroup</type>. + */ + void implDescribeSupportedFeature( + const OUString& _rCommandURL, + sal_uInt16 _nFeatureId, + sal_Int16 _nCommandGroup = css::frame::CommandGroup::INTERNAL + ); + + /** returns <TRUE/> if the feature is supported, otherwise <FALSE/> + @param _nId + The ID of the feature. + */ + bool isFeatureSupported( sal_Int32 _nId ); + + // gets the URL which the given id is assigned to + css::util::URL getURLForId(sal_Int32 _nId) const; + + /** determines whether the given feature ID denotes a user-defined feature + + @see IController::registerCommandURL + */ + static bool isUserDefinedFeature( const sal_uInt16 nFeatureId ); + + /** determines whether the given feature URL denotes a user-defined feature + + @see IController::registerCommandURL + */ + bool isUserDefinedFeature( const OUString& _rFeatureURL ) const; + + // connect to a datasource + css::uno::Reference< css::sdbc::XConnection > connect( + const css::uno::Reference< css::sdbc::XDataSource>& _xDataSource + ); + + // connect to a datasource + css::uno::Reference< css::sdbc::XConnection > connect( + const OUString& _rsDataSourceName, + const OUString& _rContextInformation, + ::dbtools::SQLExceptionInfo* _pErrorInfo + ); + + void startConnectionListening(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection); + void stopConnectionListening(const css::uno::Reference< css::sdbc::XConnection >& _rxConnection); + + /** return the container window of the top most frame + @return + The top most container window, nmay be <NULL/>. + */ + css::uno::Reference< css::awt::XWindow> getTopMostContainerWindow() const; + + // XInitialize will be called inside initialize + virtual void impl_initialize(); + + virtual OUString getPrivateTitle() const { return OUString(); } + + css::uno::Reference< css::frame::XTitle > impl_getTitleHelper_throw(bool bCreateIfNecessary = true); + virtual css::uno::Reference< css::frame::XModel > getPrivateModel() const + { + return css::uno::Reference< css::frame::XModel >(); + } + + virtual void startFrameListening( const css::uno::Reference< css::frame::XFrame >& _rxFrame ); + virtual void stopFrameListening( const css::uno::Reference< css::frame::XFrame >& _rxFrame ); + + void releaseNumberForComponent(); + + virtual ~OGenericUnoController() override; + + private: + void fillSupportedFeatures(); + + void InvalidateAll_Impl(); + void InvalidateFeature_Impl(); + + void ImplInvalidateFeature( sal_Int32 _nId, const css::uno::Reference< css::frame::XStatusListener >& _xListener, bool _bForceBroadcast ); + + void ImplBroadcastFeatureState(const OUString& _rFeature, const css::uno::Reference< css::frame::XStatusListener > & xListener, bool _bIgnoreCache); + + // link methods + DECL_DLLPRIVATE_LINK(OnAsyncInvalidateAll, void*, void); + DECL_DLLPRIVATE_LINK(OnAsyncCloseTask, void*, void); + + public: + const css::uno::Reference< css::uno::XComponentContext >& getORB() const { return m_xContext; } + ODataView* getView() const { return m_pView; } + weld::Window* getFrameWeld() const; + void setView( const VclPtr<ODataView>& i_rView ); + void clearView(); + // shows an error box if the SQLExceptionInfo is valid + void showError(const ::dbtools::SQLExceptionInfo& _rInfo); + + // if there is a css::util::URL translation for the id + // ('handle') then if xListener is NULL the change will be forwarded + // to all listeners to the given css::util::URL + // if there is a toolbar slot with the given id it is updated (the new state is determined via GetState) + // if _bForceBroadcast is sal_True, the current feature state is broadcasted no matter if it is the same as the cached state + void InvalidateFeature(sal_uInt16 nId, const css::uno::Reference< css::frame::XStatusListener > & xListener = nullptr, bool _bForceBroadcast = false); + + /** InvalidateAll invalidates all features currently known + */ + void InvalidateAll(); + // late construction + virtual bool Construct(vcl::Window* pParent); + + /** get the layout manager + @param _xFrame + The frame to ask for the layout manager. + @return + The layout manager of the frame, can be <NULL/> if the frame isn't initialized. + */ + static css::uno::Reference< css::frame::XLayoutManager > getLayoutManager(const css::uno::Reference< css::frame::XFrame >& _xFrame); + + // IController + virtual void executeUnChecked(const css::util::URL& _rCommand, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override; + virtual void executeChecked(const css::util::URL& _rCommand, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override; + virtual void executeUnChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override; + virtual void executeChecked(sal_uInt16 _nCommandId, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override; + virtual bool isCommandEnabled(sal_uInt16 _nCommandId) const override; + virtual bool isCommandEnabled(const OUString& _rCompleteCommandURL) const override; + virtual bool isDataSourceReadOnly() const override; + virtual css::uno::Reference< css::frame::XController > getXController() override; + virtual bool interceptUserInput( const NotifyEvent& _rEvent ) override; + + // misc + bool isCommandChecked(sal_uInt16 _nCommandId) const; + + // css::lang::XEventListener + virtual void SAL_CALL disposing(const css::lang::EventObject& Source) override; + + // css::util::XModifyListener + virtual void SAL_CALL modified(const css::lang::EventObject& aEvent) override; + + // XInterface + virtual void SAL_CALL acquire( ) noexcept override; + virtual void SAL_CALL release( ) noexcept override; + + // css::frame::XController2 + virtual css::uno::Reference< css::awt::XWindow > SAL_CALL getComponentWindow() override; + virtual OUString SAL_CALL getViewControllerName() override; + virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getCreationArguments() override; + + virtual css::uno::Reference< css::ui::XSidebarProvider > SAL_CALL getSidebar() override; + + + // css::frame::XController + virtual void SAL_CALL attachFrame(const css::uno::Reference< css::frame::XFrame > & xFrame) override; + virtual sal_Bool SAL_CALL attachModel(const css::uno::Reference< css::frame::XModel > & xModel) override; + virtual sal_Bool SAL_CALL suspend(sal_Bool bSuspend) override = 0; + virtual css::uno::Any SAL_CALL getViewData() override; + virtual void SAL_CALL restoreViewData(const css::uno::Any& Data) override; + virtual css::uno::Reference< css::frame::XModel > SAL_CALL getModel() override; + virtual css::uno::Reference< css::frame::XFrame > SAL_CALL getFrame() override; + + // css::frame::XDispatch + virtual void SAL_CALL dispatch(const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue>& aArgs) override; + virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL) override; + virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL) override; + + // css::frame::XDispatchProviderInterceptor + virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getSlaveDispatchProvider() override; + virtual void SAL_CALL setSlaveDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > & _xNewProvider) override; + virtual css::uno::Reference< css::frame::XDispatchProvider > SAL_CALL getMasterDispatchProvider() override; + virtual void SAL_CALL setMasterDispatchProvider(const css::uno::Reference< css::frame::XDispatchProvider > & _xNewProvider) override; + + // css::frame::XDispatchProvider + virtual css::uno::Reference< css::frame::XDispatch > SAL_CALL queryDispatch(const css::util::URL& aURL, const OUString& aTargetFrameName, sal_Int32 nSearchFlags) override; + virtual css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > SAL_CALL queryDispatches(const css::uno::Sequence< css::frame::DispatchDescriptor >& aDescripts) override; + + // css::lang::XComponent + virtual void SAL_CALL dispose() override; //LLA: need solar mutex {OGenericUnoController_COMPBASE::dispose(); } + virtual void SAL_CALL disposing() override; + virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > & aListener) override; + virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > & aListener) override; + + // css::frame::XFrameActionListener + virtual void SAL_CALL frameAction(const css::frame::FrameActionEvent& aEvent) override; + // lang::XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override = 0; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence< OUString> SAL_CALL getSupportedServiceNames() override = 0; + + // XDispatchInformationProvider + virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getSupportedCommandGroups() override; + virtual css::uno::Sequence< css::frame::DispatchInformation > SAL_CALL getConfigurableDispatchInformation( ::sal_Int16 ) override; + + // XTitle + virtual OUString SAL_CALL getTitle( ) override; + virtual void SAL_CALL setTitle( const OUString& sTitle ) override; + + // XTitleChangeBroadcaster + virtual void SAL_CALL addTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener ) override; + virtual void SAL_CALL removeTitleChangeListener( const css::uno::Reference< css::frame::XTitleChangeListener >& xListener ) override; + + // XUserInputInterception + virtual void SAL_CALL addKeyHandler( const css::uno::Reference< css::awt::XKeyHandler >& xHandler ) override; + virtual void SAL_CALL removeKeyHandler( const css::uno::Reference< css::awt::XKeyHandler >& xHandler ) override; + virtual void SAL_CALL addMouseClickHandler( const css::uno::Reference< css::awt::XMouseClickHandler >& xHandler ) override; + virtual void SAL_CALL removeMouseClickHandler( const css::uno::Reference< css::awt::XMouseClickHandler >& xHandler ) override; + }; +} + +#endif // INCLUDED_DBACCESS_GENERICCONTROLLER_HXX + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |