Line data Source code
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 :
20 :
21 : #include "CommandDispatchContainer.hxx"
22 : #include "UndoCommandDispatch.hxx"
23 : #include "StatusBarCommandDispatch.hxx"
24 : #include "DisposeHelper.hxx"
25 : #include "macros.hxx"
26 : #include "ChartController.hxx"
27 : #include "DrawCommandDispatch.hxx"
28 : #include "ShapeController.hxx"
29 :
30 : #include <comphelper/InlineContainer.hxx>
31 :
32 : #include <com/sun/star/frame/XDispatchProvider.hpp>
33 :
34 : using namespace ::com::sun::star;
35 :
36 : using ::com::sun::star::uno::Reference;
37 : using ::com::sun::star::uno::Sequence;
38 :
39 : namespace chart
40 : {
41 :
42 17 : CommandDispatchContainer::CommandDispatchContainer(
43 : const Reference< uno::XComponentContext > & xContext, ChartController* pController )
44 : :m_xContext( xContext )
45 : ,m_pChartController( pController )
46 : ,m_pDrawCommandDispatch( NULL )
47 17 : ,m_pShapeController( NULL )
48 : {
49 17 : m_aContainerDocumentCommands =
50 : ::comphelper::MakeSet< OUString >
51 34 : ("AddDirect") ("NewDoc") ("Open")
52 51 : ("Save") ("SaveAs") ("SendMail")
53 51 : ("EditDoc") ("ExportDirectToPDF") ("PrintDefault")
54 17 : ;
55 17 : }
56 :
57 33 : void CommandDispatchContainer::setModel(
58 : const Reference< frame::XModel > & xModel )
59 : {
60 : // remove all existing dispatcher that base on the old model
61 33 : m_aCachedDispatches.clear();
62 33 : DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
63 33 : m_aToBeDisposedDispatches.clear();
64 33 : m_xModel = xModel;
65 33 : }
66 :
67 17 : void CommandDispatchContainer::setChartDispatch(
68 : const Reference< frame::XDispatch > xChartDispatch,
69 : const ::std::set< OUString > & rChartCommands )
70 : {
71 : OSL_ENSURE(xChartDispatch.is(),"Invalid fall back dispatcher!");
72 17 : m_xChartDispatcher.set( xChartDispatch );
73 17 : m_aChartCommands = rChartCommands;
74 17 : m_aToBeDisposedDispatches.push_back( m_xChartDispatcher );
75 17 : }
76 :
77 786 : Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
78 : const util::URL & rURL )
79 : {
80 786 : Reference< frame::XDispatch > xResult;
81 786 : tDispatchMap::const_iterator aIt( m_aCachedDispatches.find( rURL.Complete ));
82 786 : if( aIt != m_aCachedDispatches.end())
83 : {
84 55 : xResult.set( (*aIt).second );
85 : }
86 : else
87 : {
88 731 : uno::Reference< frame::XModel > xModel( m_xModel );
89 :
90 731 : if( xModel.is() && ( rURL.Path == "Undo" || rURL.Path == "Redo" ) )
91 : {
92 17 : CommandDispatch * pDispatch = new UndoCommandDispatch( m_xContext, xModel );
93 17 : xResult.set( pDispatch );
94 17 : pDispatch->initialize();
95 17 : m_aCachedDispatches[ ".uno:Undo" ].set( xResult );
96 17 : m_aCachedDispatches[ ".uno:Redo" ].set( xResult );
97 17 : m_aToBeDisposedDispatches.push_back( xResult );
98 : }
99 714 : else if( xModel.is() && ( rURL.Path == "Context" || rURL.Path == "ModifiedStatus" ) )
100 : {
101 17 : Reference< view::XSelectionSupplier > xSelSupp( xModel->getCurrentController(), uno::UNO_QUERY );
102 17 : CommandDispatch * pDispatch = new StatusBarCommandDispatch( m_xContext, xModel, xSelSupp );
103 17 : xResult.set( pDispatch );
104 17 : pDispatch->initialize();
105 17 : m_aCachedDispatches[ ".uno:Context" ].set( xResult );
106 17 : m_aCachedDispatches[ ".uno:ModifiedStatus" ].set( xResult );
107 17 : m_aToBeDisposedDispatches.push_back( xResult );
108 : }
109 3485 : else if( xModel.is() &&
110 3485 : (m_aContainerDocumentCommands.find( rURL.Path ) != m_aContainerDocumentCommands.end()) )
111 : {
112 153 : xResult.set( getContainerDispatchForURL( xModel->getCurrentController(), rURL ));
113 : // ToDo: can those dispatches be cached?
114 153 : m_aCachedDispatches[ rURL.Complete ].set( xResult );
115 : }
116 2720 : else if( m_xChartDispatcher.is() &&
117 2720 : (m_aChartCommands.find( rURL.Path ) != m_aChartCommands.end()) )
118 : {
119 204 : xResult.set( m_xChartDispatcher );
120 204 : m_aCachedDispatches[ rURL.Complete ].set( xResult );
121 : }
122 : // #i12587# support for shapes in chart
123 : // Note, that the chart dispatcher must be queried first, because
124 : // the chart dispatcher is the default dispatcher for all context
125 : // sensitive commands.
126 340 : else if ( m_pDrawCommandDispatch && m_pDrawCommandDispatch->isFeatureSupported( rURL.Complete ) )
127 : {
128 238 : xResult.set( m_pDrawCommandDispatch );
129 238 : m_aCachedDispatches[ rURL.Complete ].set( xResult );
130 : }
131 102 : else if ( m_pShapeController && m_pShapeController->isFeatureSupported( rURL.Complete ) )
132 : {
133 0 : xResult.set( m_pShapeController );
134 0 : m_aCachedDispatches[ rURL.Complete ].set( xResult );
135 731 : }
136 : }
137 :
138 786 : return xResult;
139 : }
140 :
141 0 : Sequence< Reference< frame::XDispatch > > CommandDispatchContainer::getDispatchesForURLs(
142 : const Sequence< frame::DispatchDescriptor > & aDescriptors )
143 : {
144 0 : sal_Int32 nCount = aDescriptors.getLength();
145 0 : uno::Sequence< uno::Reference< frame::XDispatch > > aRet( nCount );
146 :
147 0 : for( sal_Int32 nPos = 0; nPos < nCount; ++nPos )
148 : {
149 0 : if ( aDescriptors[ nPos ].FrameName == "_self" )
150 0 : aRet[ nPos ] = getDispatchForURL( aDescriptors[ nPos ].FeatureURL );
151 : }
152 0 : return aRet;
153 : }
154 :
155 17 : void CommandDispatchContainer::DisposeAndClear()
156 : {
157 17 : m_aCachedDispatches.clear();
158 17 : DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
159 17 : m_aToBeDisposedDispatches.clear();
160 17 : m_xChartDispatcher.clear();
161 17 : m_aChartCommands.clear();
162 17 : m_pChartController = NULL;
163 17 : m_pDrawCommandDispatch = NULL;
164 17 : m_pShapeController = NULL;
165 17 : }
166 :
167 153 : Reference< frame::XDispatch > CommandDispatchContainer::getContainerDispatchForURL(
168 : const Reference< frame::XController > & xChartController,
169 : const util::URL & rURL )
170 : {
171 153 : Reference< frame::XDispatch > xResult;
172 153 : if( xChartController.is())
173 : {
174 153 : Reference< frame::XFrame > xFrame( xChartController->getFrame());
175 153 : if( xFrame.is())
176 : {
177 136 : Reference< frame::XDispatchProvider > xDispProv( xFrame->getCreator(), uno::UNO_QUERY );
178 136 : if( xDispProv.is())
179 136 : xResult.set( xDispProv->queryDispatch( rURL, "_self", 0 ));
180 153 : }
181 : }
182 153 : return xResult;
183 : }
184 :
185 17 : void CommandDispatchContainer::setDrawCommandDispatch( DrawCommandDispatch* pDispatch )
186 : {
187 17 : m_pDrawCommandDispatch = pDispatch;
188 17 : m_aToBeDisposedDispatches.push_back( Reference< frame::XDispatch >( pDispatch ) );
189 17 : }
190 :
191 17 : void CommandDispatchContainer::setShapeController( ShapeController* pController )
192 : {
193 17 : m_pShapeController = pController;
194 17 : m_aToBeDisposedDispatches.push_back( Reference< frame::XDispatch >( pController ) );
195 17 : }
196 :
197 33 : } // namespace chart
198 :
199 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|