| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
#pragma once |
| 20 |
|
| 21 |
#include "CommandDispatch.hxx" |
| 22 |
#include <com/sun/star/view/XSelectionChangeListener.hpp> |
| 23 |
#include <cppuhelper/implbase.hxx> |
| 24 |
#include <rtl/ref.hxx> |
| 25 |
|
| 26 |
#include <memory> |
| 27 |
|
| 28 |
namespace com::sun::star::view { class XSelectionSupplier; } |
| 29 |
|
| 30 |
namespace chart |
| 31 |
{ |
| 32 |
|
| 33 |
class ChartController; |
| 34 |
class CommandDispatchContainer; |
| 35 |
|
| 36 |
namespace impl |
| 37 |
{ |
| 38 |
struct ModelState; |
| 39 |
struct ControllerState; |
| 40 |
|
| 41 |
// #i63017# : need to implement the XSelectionChangeListener in order |
| 42 |
// to update the ControllerState when the selection changes. |
| 43 |
typedef ::cppu::ImplInheritanceHelper< |
| 44 |
CommandDispatch, |
| 45 |
css::view::XSelectionChangeListener > |
| 46 |
ControllerCommandDispatch_Base; |
| 47 |
} |
| 48 |
|
| 49 |
/** This class is a CommandDispatch that is responsible for all commands that |
| 50 |
the ChartController supports. |
| 51 |
|
| 52 |
This class determines which commands are currently available (via the model |
| 53 |
state) and if an available command is called forwards it to the |
| 54 |
ChartController. |
| 55 |
*/ |
| 56 |
class ControllerCommandDispatch final : public impl::ControllerCommandDispatch_Base |
| 57 |
{ |
| 58 |
public: |
| 59 |
explicit ControllerCommandDispatch( |
| 60 |
const css::uno::Reference< css::uno::XComponentContext > & xContext, |
| 61 |
ChartController* pController, CommandDispatchContainer* pContainer ); |
| 62 |
virtual ~ControllerCommandDispatch() override; |
| 63 |
|
| 64 |
// late initialisation, especially for adding as listener |
| 65 |
virtual void initialize() override; |
| 66 |
|
| 67 |
bool commandAvailable(const OUString& rCommand) const; |
| 68 |
bool commandHandled(const OUString& rCommand) const; |
| 69 |
|
| 70 |
protected: |
| 71 |
// ____ XDispatch ____ |
| 72 |
virtual void SAL_CALL dispatch( |
| 73 |
const css::util::URL& URL, |
| 74 |
const css::uno::Sequence< css::beans::PropertyValue >& Arguments ) override; |
| 75 |
|
| 76 |
// ____ WeakComponentImplHelperBase ____ |
| 77 |
/// is called when this is disposed |
| 78 |
virtual void disposing(std::unique_lock<std::mutex>& rGuard) override; |
| 79 |
|
| 80 |
// ____ XEventListener (base of XModifyListener) ____ |
| 81 |
virtual void SAL_CALL disposing( |
| 82 |
const css::lang::EventObject& Source ) override; |
| 83 |
|
| 84 |
virtual void fireStatusEvent( |
| 85 |
const OUString & rURL, |
| 86 |
const css::uno::Reference< css::frame::XStatusListener > & xSingleListener ) override; |
| 87 |
|
| 88 |
// ____ XModifyListener ____ |
| 89 |
virtual void SAL_CALL modified( |
| 90 |
const css::lang::EventObject& aEvent ) override; |
| 91 |
|
| 92 |
// ____ XSelectionChangeListener ____ |
| 93 |
virtual void SAL_CALL selectionChanged( |
| 94 |
const css::lang::EventObject& aEvent ) override; |
| 95 |
|
| 96 |
private: |
| 97 |
void fireStatusEventForURLImpl( |
| 98 |
const OUString & rURL, |
| 99 |
const css::uno::Reference< css::frame::XStatusListener > & xSingleListener ); |
| 100 |
|
| 101 |
void updateCommandAvailability(); |
| 102 |
|
| 103 |
bool isShapeControllerCommandAvailable( const OUString& rCommand ); |
| 104 |
|
| 105 |
rtl::Reference<ChartController> m_xChartController; |
| 106 |
css::uno::Reference< css::view::XSelectionSupplier > m_xSelectionSupplier; |
| 107 |
css::uno::Reference< css::frame::XDispatch > m_xDispatch; |
| 108 |
|
| 109 |
std::unique_ptr< impl::ModelState > m_apModelState; |
| 110 |
std::unique_ptr< impl::ControllerState > m_apControllerState; |
| 111 |
|
| 112 |
mutable std::map< OUString, bool > m_aCommandAvailability; |
| 113 |
mutable std::map< OUString, css::uno::Any > m_aCommandArguments; |
| 114 |
|
| 115 |
CommandDispatchContainer* m_pDispatchContainer; |
| 116 |
}; |
| 117 |
|
| 118 |
} // namespace chart |
| 119 |
|
| 120 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |