LibreOffice Module chart2 (master) 1
CommandDispatchContainer.cxx
Go to the documentation of this file.
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
23#include <DisposeHelper.hxx>
25#include "ShapeController.hxx"
26#include <ChartModel.hxx>
27
28#include <com/sun/star/frame/XDispatchProvider.hpp>
29#include <com/sun/star/view/XSelectionSupplier.hpp>
30#include <osl/diagnose.h>
31#include <rtl/ref.hxx>
32
34
35using namespace ::com::sun::star;
36
37using ::com::sun::star::uno::Reference;
38using ::com::sun::star::uno::Sequence;
39
40namespace chart
41{
42
45 :m_xContext( xContext )
46 ,m_pDrawCommandDispatch( nullptr )
47 ,m_pShapeController( nullptr )
48{
49}
50
53{
54 // remove all existing dispatcher that base on the old model
55 m_aCachedDispatches.clear();
58 m_xModel = xModel.get();
59}
60
62 const Reference< frame::XDispatch >& rChartDispatch,
63 o3tl::sorted_vector< OUString > && rChartCommands )
64{
65 OSL_ENSURE(rChartDispatch.is(),"Invalid fall back dispatcher!");
66 m_xChartDispatcher.set( rChartDispatch );
67 m_aChartCommands = std::move(rChartCommands);
69}
70
72 const util::URL & rURL )
73{
74 static const o3tl::sorted_vector< OUString > s_aContainerDocumentCommands {
75 "AddDirect", "NewDoc", "Open",
76 "Save", "SaveAs", "SendMail",
77 "EditDoc", "ExportDirectToPDF", "PrintDefault"};
78
80 tDispatchMap::const_iterator aIt( m_aCachedDispatches.find( rURL.Complete ));
81 if( aIt != m_aCachedDispatches.end())
82 {
83 xResult.set( (*aIt).second );
84 }
85 else
86 {
88
89 if( xModel.is() && ( rURL.Path == "Undo" || rURL.Path == "Redo" ||
90 rURL.Path == "GetUndoStrings" || rURL.Path == "GetRedoStrings" ) )
91 {
93 xResult.set( pDispatch );
94 pDispatch->initialize();
95 m_aCachedDispatches[ ".uno:Undo" ].set( xResult );
96 m_aCachedDispatches[ ".uno:Redo" ].set( xResult );
97 m_aCachedDispatches[ ".uno:GetUndoStrings" ].set( xResult );
98 m_aCachedDispatches[ ".uno:GetRedoStrings" ].set( xResult );
99 m_aToBeDisposedDispatches.push_back( xResult );
100 }
101 else if( xModel.is() && ( rURL.Path == "Context" || rURL.Path == "ModifiedStatus" ) )
102 {
103 Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY );
105 xResult.set( pDispatch );
106 pDispatch->initialize();
107 m_aCachedDispatches[ ".uno:Context" ].set( xResult );
108 m_aCachedDispatches[ ".uno:ModifiedStatus" ].set( xResult );
109 m_aToBeDisposedDispatches.push_back( xResult );
110 }
111 else if( xModel.is() &&
112 (s_aContainerDocumentCommands.find( rURL.Path ) != s_aContainerDocumentCommands.end()) )
113 {
114 xResult.set( getContainerDispatchForURL( xModel->getCurrentController(), rURL ));
115 // ToDo: can those dispatches be cached?
116 m_aCachedDispatches[ rURL.Complete ].set( xResult );
117 }
118 else if( m_xChartDispatcher.is() &&
119 (m_aChartCommands.find( rURL.Path ) != m_aChartCommands.end()) )
120 {
121 xResult.set( m_xChartDispatcher );
122 m_aCachedDispatches[ rURL.Complete ].set( xResult );
123 }
124 // #i12587# support for shapes in chart
125 // Note, that the chart dispatcher must be queried first, because
126 // the chart dispatcher is the default dispatcher for all context
127 // sensitive commands.
129 {
130 xResult.set( m_pDrawCommandDispatch );
131 m_aCachedDispatches[ rURL.Complete ].set( xResult );
132 }
133 else if ( m_pShapeController && m_pShapeController->isFeatureSupported( rURL.Complete ) )
134 {
135 xResult.set( m_pShapeController );
136 m_aCachedDispatches[ rURL.Complete ].set( xResult );
137 }
138 }
139
140 return xResult;
141}
142
144 const Sequence< frame::DispatchDescriptor > & aDescriptors )
145{
146 sal_Int32 nCount = aDescriptors.getLength();
148 auto aRetRange = asNonConstRange(aRet);
149
150 for( sal_Int32 nPos = 0; nPos < nCount; ++nPos )
151 {
152 if ( aDescriptors[ nPos ].FrameName == "_self" )
153 aRetRange[ nPos ] = getDispatchForURL( aDescriptors[ nPos ].FeatureURL );
154 }
155 return aRet;
156}
157
159{
160 m_aCachedDispatches.clear();
163 m_xChartDispatcher.clear();
165 m_pDrawCommandDispatch = nullptr;
166 m_pShapeController = nullptr;
167}
168
170 const Reference< frame::XController > & xChartController,
171 const util::URL & rURL )
172{
174 if( xChartController.is())
175 {
176 Reference< frame::XFrame > xFrame( xChartController->getFrame());
177 if( xFrame.is())
178 {
179 Reference< frame::XDispatchProvider > xDispProv( xFrame->getCreator(), uno::UNO_QUERY );
180 if( xDispProv.is())
181 xResult.set( xDispProv->queryDispatch( rURL, "_self", 0 ));
182 }
183 }
184 return xResult;
185}
186
188{
189 m_pDrawCommandDispatch = pDispatch;
190 m_aToBeDisposedDispatches.emplace_back( pDispatch );
191}
192
194{
195 m_pShapeController = pController;
196 m_aToBeDisposedDispatches.emplace_back( pController );
197}
198
199} // namespace chart
200
201/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nPos
Reference< uno::XComponentContext > m_xContext
void setModel(const rtl::Reference<::chart::ChartModel > &xModel)
void setDrawCommandDispatch(DrawCommandDispatch *pDispatch)
css::uno::Reference< css::frame::XDispatch > getDispatchForURL(const css::util::URL &rURL)
Returns the dispatch that is able to do the command given in rURL, if implemented here.
css::uno::Sequence< css::uno::Reference< css::frame::XDispatch > > getDispatchesForURLs(const css::uno::Sequence< css::frame::DispatchDescriptor > &aDescriptors)
css::uno::Reference< css::frame::XDispatch > m_xChartDispatcher
css::uno::Reference< css::uno::XComponentContext > m_xContext
CommandDispatchContainer(const css::uno::Reference< css::uno::XComponentContext > &xContext)
static css::uno::Reference< css::frame::XDispatch > getContainerDispatchForURL(const css::uno::Reference< css::frame::XController > &xChartController, const css::util::URL &rURL)
o3tl::sorted_vector< OUString > m_aChartCommands
void setShapeController(ShapeController *pController)
void setChartDispatch(const css::uno::Reference< css::frame::XDispatch > &rChartDispatch, o3tl::sorted_vector< OUString > &&rChartCommands)
Set a chart dispatcher that is used for all commands contained in rChartCommands.
unotools::WeakReference< ::chart::ChartModel > m_xModel
This is a CommandDispatch implementation for drawing objects.
virtual bool isFeatureSupported(const OUString &rCommandURL) override
virtual bool isFeatureSupported(const OUString &rCommandURL)
This is a CommandDispatch implementation for shapes.
This is a CommandDispatch implementation for Undo and Redo.
const_iterator find(const Value &x) const
const_iterator end() const
int nCount
void DisposeAllElements(Container &rContainer)
Reference< XFrame > xFrame
Reference< XModel > xModel