Update ooo320-m1
[ooovba.git] / chart2 / source / controller / main / CommandDispatchContainer.cxx
blob8caf4f0b5ff9f3fc2de5601748cde603ad5f8e3f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CommandDispatchContainer.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "CommandDispatchContainer.hxx"
35 #include "UndoCommandDispatch.hxx"
36 #include "StatusBarCommandDispatch.hxx"
37 #include "DisposeHelper.hxx"
38 #include "macros.hxx"
40 #include <comphelper/InlineContainer.hxx>
42 #include <com/sun/star/frame/XDispatchProvider.hpp>
44 using namespace ::com::sun::star;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Sequence;
48 using ::rtl::OUString;
50 namespace chart
53 CommandDispatchContainer::CommandDispatchContainer(
54 const Reference< uno::XComponentContext > & xContext ) :
55 m_xContext( xContext )
57 m_aContainerDocumentCommands =
58 ::comphelper::MakeSet< OUString >
59 ( C2U("AddDirect")) ( C2U("NewDoc")) ( C2U("Open"))
60 ( C2U("Save")) ( C2U("SaveAs")) ( C2U("SendMail"))
61 ( C2U("EditDoc")) ( C2U("ExportDirectToPDF")) ( C2U("PrintDefault"))
65 void CommandDispatchContainer::setModel(
66 const Reference< frame::XModel > & xModel )
68 // remove all existing dispatcher that base on the old model
69 m_aCachedDispatches.clear();
70 DisposeHelper::DisposeAllElements( m_aToBeDisposedDispatches );
71 m_aToBeDisposedDispatches.clear();
72 m_xModel.set( xModel );
75 // void CommandDispatchContainer::setUndoManager(
76 // const Reference< chart2::XUndoManager > & xUndoManager )
77 // {
78 // m_xUndoManager = xUndoManager;
79 // }
81 void CommandDispatchContainer::setFallbackDispatch(
82 const Reference< frame::XDispatch > xFallbackDispatch,
83 const ::std::set< OUString > & rFallbackCommands )
85 OSL_ENSURE(xFallbackDispatch.is(),"Invalid fall back dispatcher!");
86 m_xFallbackDispatcher.set( xFallbackDispatch );
87 m_aFallbackCommands = rFallbackCommands;
88 m_aToBeDisposedDispatches.push_back( m_xFallbackDispatcher );
91 Reference< frame::XDispatch > CommandDispatchContainer::getDispatchForURL(
92 const util::URL & rURL )
94 Reference< frame::XDispatch > xResult;
96 tDispatchMap::const_iterator aIt( m_aCachedDispatches.find( rURL.Complete ));
97 if( aIt != m_aCachedDispatches.end())
99 xResult.set( (*aIt).second );
101 else
103 if( rURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Undo" ))
104 || rURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Redo" )))
106 CommandDispatch * pDispatch = new UndoCommandDispatch( m_xContext, m_xModel );
107 xResult.set( pDispatch );
108 pDispatch->initialize();
109 m_aCachedDispatches[ C2U(".uno:Undo") ].set( xResult );
110 m_aCachedDispatches[ C2U(".uno:Redo") ].set( xResult );
111 m_aToBeDisposedDispatches.push_back( xResult );
113 else if( rURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Context" ))
114 || rURL.Path.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "ModifiedStatus" )))
116 Reference< view::XSelectionSupplier > xSelSupp;
117 if( m_xModel.is())
118 xSelSupp.set( m_xModel->getCurrentController(), uno::UNO_QUERY );
119 CommandDispatch * pDispatch = new StatusBarCommandDispatch( m_xContext, m_xModel, xSelSupp );
120 xResult.set( pDispatch );
121 pDispatch->initialize();
122 m_aCachedDispatches[ C2U(".uno:Context") ].set( xResult );
123 m_aCachedDispatches[ C2U(".uno:ModifiedStatus") ].set( xResult );
124 m_aToBeDisposedDispatches.push_back( xResult );
126 else if( m_xModel.is() &&
127 (m_aContainerDocumentCommands.find( rURL.Path ) != m_aContainerDocumentCommands.end()) )
129 xResult.set( getContainerDispatchForURL( m_xModel->getCurrentController(), rURL ));
130 // ToDo: can those dispatches be cached?
131 m_aCachedDispatches[ rURL.Complete ].set( xResult );
133 else if( m_xFallbackDispatcher.is() &&
134 (m_aFallbackCommands.find( rURL.Path ) != m_aFallbackCommands.end()) )
136 xResult.set( m_xFallbackDispatcher );
137 m_aCachedDispatches[ rURL.Complete ].set( xResult );
141 return xResult;
144 Sequence< Reference< frame::XDispatch > > CommandDispatchContainer::getDispatchesForURLs(
145 const Sequence< frame::DispatchDescriptor > & aDescriptors )
147 sal_Int32 nCount = aDescriptors.getLength();
148 uno::Sequence< uno::Reference< frame::XDispatch > > aRet( nCount );
150 for( sal_Int32 nPos = 0; nPos < nCount; ++nPos )
152 if( aDescriptors[ nPos ].FrameName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("_self")))
153 aRet[ 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_xFallbackDispatcher.clear();
164 m_aFallbackCommands.clear();
167 Reference< frame::XDispatch > CommandDispatchContainer::getContainerDispatchForURL(
168 const Reference< frame::XController > & xChartController,
169 const util::URL & rURL )
171 Reference< frame::XDispatch > xResult;
172 if( xChartController.is())
174 Reference< frame::XFrame > xFrame( xChartController->getFrame());
175 if( xFrame.is())
177 Reference< frame::XDispatchProvider > xDispProv( xFrame->getCreator(), uno::UNO_QUERY );
178 if( xDispProv.is())
179 xResult.set( xDispProv->queryDispatch( rURL, C2U("_self"), 0 ));
182 return xResult;
185 } // namespace chart