tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / chart2 / source / controller / main / CommandDispatchContainer.cxx
blob31b49c76889cf96e9da4b58be9d52c6da7b34bcc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <CommandDispatchContainer.hxx>
21 #include "UndoCommandDispatch.hxx"
22 #include "StatusBarCommandDispatch.hxx"
23 #include <DisposeHelper.hxx>
24 #include "DrawCommandDispatch.hxx"
25 #include "ShapeController.hxx"
26 #include <ChartModel.hxx>
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>
33 #include <o3tl/sorted_vector.hxx>
35 using namespace ::com::sun::star;
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::Sequence;
40 namespace chart
43 CommandDispatchContainer::CommandDispatchContainer(
44 const Reference< uno::XComponentContext > & xContext )
45 :m_xContext( xContext )
46 ,m_pDrawCommandDispatch( nullptr )
47 ,m_pShapeController( nullptr )
51 void CommandDispatchContainer::setModel(
52 const rtl::Reference<::chart::ChartModel> & xModel )
54 // remove all existing dispatcher that base on the old model
55 m_aCachedDispatches.clear();
56 DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
57 m_aToBeDisposedDispatches.clear();
58 m_xModel = xModel.get();
61 void CommandDispatchContainer::setChartDispatch(
62 const Reference< frame::XDispatch >& rChartDispatch,
63 const o3tl::sorted_vector< std::u16string_view > & rChartCommands )
65 OSL_ENSURE(rChartDispatch.is(),"Invalid fall back dispatcher!");
66 m_xChartDispatcher.set( rChartDispatch );
67 m_aChartCommands = rChartCommands;
68 m_aToBeDisposedDispatches.push_back( m_xChartDispatcher );
71 Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
72 const util::URL & rURL )
74 static const o3tl::sorted_vector< std::u16string_view > s_aContainerDocumentCommands {
75 u"AddDirect", u"NewDoc", u"Open",
76 u"Save", u"SaveAs", u"SendMail",
77 u"EditDoc", u"ExportDirectToPDF", u"PrintDefault"};
79 Reference< frame::XDispatch > xResult;
80 tDispatchMap::const_iterator aIt( m_aCachedDispatches.find( rURL.Complete ));
81 if( aIt != m_aCachedDispatches.end())
83 xResult.set( (*aIt).second );
85 else
87 rtl::Reference< ::chart::ChartModel > xModel( m_xModel );
89 if( xModel.is() && ( rURL.Path == "Undo" || rURL.Path == "Redo" ||
90 rURL.Path == "GetUndoStrings" || rURL.Path == "GetRedoStrings" ) )
92 rtl::Reference<CommandDispatch> pDispatch = new UndoCommandDispatch( m_xContext, xModel );
93 xResult.set( pDispatch );
94 pDispatch->initialize();
95 m_aCachedDispatches[ u".uno:Undo"_ustr ].set( xResult );
96 m_aCachedDispatches[ u".uno:Redo"_ustr ].set( xResult );
97 m_aCachedDispatches[ u".uno:GetUndoStrings"_ustr ].set( xResult );
98 m_aCachedDispatches[ u".uno:GetRedoStrings"_ustr ].set( xResult );
99 m_aToBeDisposedDispatches.push_back( xResult );
101 else if( xModel.is() && ( rURL.Path == "Context" || rURL.Path == "ModifiedStatus" ) )
103 Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY );
104 rtl::Reference<CommandDispatch> pDispatch = new StatusBarCommandDispatch( m_xContext, xModel, xSelSupp );
105 xResult.set( pDispatch );
106 pDispatch->initialize();
107 m_aCachedDispatches[ u".uno:Context"_ustr ].set( xResult );
108 m_aCachedDispatches[ u".uno:ModifiedStatus"_ustr ].set( xResult );
109 m_aToBeDisposedDispatches.push_back( xResult );
111 else if( xModel.is() &&
112 (s_aContainerDocumentCommands.find( std::u16string_view(rURL.Path) ) != s_aContainerDocumentCommands.end()) )
114 xResult.set( getContainerDispatchForURL( xModel->getCurrentController(), rURL ));
115 // ToDo: can those dispatches be cached?
116 m_aCachedDispatches[ rURL.Complete ].set( xResult );
118 else if( m_xChartDispatcher.is() &&
119 (m_aChartCommands.find( rURL.Path ) != m_aChartCommands.end()) )
121 xResult.set( m_xChartDispatcher );
122 m_aCachedDispatches[ rURL.Complete ].set( xResult );
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.
128 else if ( m_pDrawCommandDispatch && m_pDrawCommandDispatch->isFeatureSupported( rURL.Complete ) )
130 xResult.set( m_pDrawCommandDispatch );
131 m_aCachedDispatches[ rURL.Complete ].set( xResult );
133 else if ( m_pShapeController && m_pShapeController->isFeatureSupported( rURL.Complete ) )
135 xResult.set( m_pShapeController );
136 m_aCachedDispatches[ rURL.Complete ].set( xResult );
140 return xResult;
143 Sequence< Reference< frame::XDispatch > > CommandDispatchContainer::getDispatchesForURLs(
144 const Sequence< frame::DispatchDescriptor > & aDescriptors )
146 sal_Int32 nCount = aDescriptors.getLength();
147 uno::Sequence< uno::Reference< frame::XDispatch > > aRet( nCount );
148 auto aRetRange = asNonConstRange(aRet);
150 for( sal_Int32 nPos = 0; nPos < nCount; ++nPos )
152 if ( aDescriptors[ nPos ].FrameName == "_self" )
153 aRetRange[ nPos ] = getDispatchForURL( aDescriptors[ nPos ].FeatureURL );
155 return aRet;
158 void CommandDispatchContainer::DisposeAndClear()
160 m_aCachedDispatches.clear();
161 DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
162 m_aToBeDisposedDispatches.clear();
163 m_xChartDispatcher.clear();
164 m_aChartCommands.clear();
165 m_pDrawCommandDispatch = nullptr;
166 m_pShapeController = nullptr;
169 Reference< frame::XDispatch > CommandDispatchContainer::getContainerDispatchForURL(
170 const Reference< frame::XController > & xChartController,
171 const util::URL & rURL )
173 Reference< frame::XDispatch > xResult;
174 if( xChartController.is())
176 Reference< frame::XFrame > xFrame( xChartController->getFrame());
177 if( xFrame.is())
179 Reference< frame::XDispatchProvider > xDispProv( xFrame->getCreator(), uno::UNO_QUERY );
180 if( xDispProv.is())
181 xResult.set( xDispProv->queryDispatch( rURL, u"_self"_ustr, 0 ));
184 return xResult;
187 void CommandDispatchContainer::setDrawCommandDispatch( DrawCommandDispatch* pDispatch )
189 m_pDrawCommandDispatch = pDispatch;
190 m_aToBeDisposedDispatches.emplace_back( pDispatch );
193 void CommandDispatchContainer::setShapeController( ShapeController* pController )
195 m_pShapeController = pController;
196 m_aToBeDisposedDispatches.emplace_back( pController );
199 } // namespace chart
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */