1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir #ifndef DBAUI_GENERICCONTROLLER_HXX
31*cdf0e10cSrcweir #include "genericcontroller.hxx"
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef _COMPHELPER_UNO3_HXX_
34*cdf0e10cSrcweir #include <comphelper/uno3.hxx>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #ifndef _TOOLKIT_AWT_VCLXWINDOW_HXX_
37*cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
40*cdf0e10cSrcweir #include "browserids.hxx"
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX //autogen
43*cdf0e10cSrcweir #include <vcl/svapp.hxx>
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
46*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #ifndef DBAUI_DATAVIEW_HXX
49*cdf0e10cSrcweir #include "dataview.hxx"
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
52*cdf0e10cSrcweir #include <tools/debug.hxx>
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir #ifndef TOOLS_DIAGNOSE_EX_H
55*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
58*cdf0e10cSrcweir #include "dbustrings.hrc"
59*cdf0e10cSrcweir #endif
60*cdf0e10cSrcweir #ifndef _VCL_STDTEXT_HXX
61*cdf0e10cSrcweir #include <vcl/stdtext.hxx>
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
64*cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
65*cdf0e10cSrcweir #endif
66*cdf0e10cSrcweir #include <framework/titlehelper.hxx>
67*cdf0e10cSrcweir #ifndef _COMPHELPER_SEQUENCE_HXX_
68*cdf0e10cSrcweir #include <comphelper/sequence.hxx>
69*cdf0e10cSrcweir #endif
70*cdf0e10cSrcweir #ifndef _COMPHELPER_EXTRACT_HXX_
71*cdf0e10cSrcweir #include <comphelper/extract.hxx>
72*cdf0e10cSrcweir #endif
73*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XDATASOURCE_HPP_
74*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDataSource.hpp>
75*cdf0e10cSrcweir #endif
76*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
77*cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
78*cdf0e10cSrcweir #endif
79*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_XCOMPLETEDCONNECTION_HPP_
80*cdf0e10cSrcweir #include <com/sun/star/sdb/XCompletedConnection.hpp>
81*cdf0e10cSrcweir #endif
82*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
83*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
84*cdf0e10cSrcweir #endif
85*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
86*cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp>
87*cdf0e10cSrcweir #endif
88*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XCLOSEABLE_HPP_
89*cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
90*cdf0e10cSrcweir #endif
91*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
92*cdf0e10cSrcweir #include "UITools.hxx"
93*cdf0e10cSrcweir #endif
94*cdf0e10cSrcweir #ifndef _DBAUI_COMMON_TYPES_HXX_
95*cdf0e10cSrcweir #include "commontypes.hxx"
96*cdf0e10cSrcweir #endif
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir #ifndef _SV_WAITOBJ_HXX
99*cdf0e10cSrcweir #include <vcl/waitobj.hxx>
100*cdf0e10cSrcweir #endif
101*cdf0e10cSrcweir #ifndef _URLOBJ_HXX
102*cdf0e10cSrcweir #include <tools/urlobj.hxx>
103*cdf0e10cSrcweir #endif
104*cdf0e10cSrcweir #ifndef SVTOOLS_URIHELPER_HXX
105*cdf0e10cSrcweir #include <svl/urihelper.hxx>
106*cdf0e10cSrcweir #endif
107*cdf0e10cSrcweir #ifndef _DBAUI_DATASOURCECONNECTOR_HXX_
108*cdf0e10cSrcweir #include "datasourceconnector.hxx"
109*cdf0e10cSrcweir #endif
110*cdf0e10cSrcweir #ifndef INCLUDED_SVTOOLS_MODULEOPTIONS_HXX
111*cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
112*cdf0e10cSrcweir #endif
113*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
114*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp>
115*cdf0e10cSrcweir #endif
116*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_FRAME_STATUS_VISIBILITY_HPP_
117*cdf0e10cSrcweir #include <com/sun/star/frame/status/Visibility.hpp>
118*cdf0e10cSrcweir #endif
119*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XMODIFIABLE_HPP_
120*cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
121*cdf0e10cSrcweir #endif
122*cdf0e10cSrcweir #ifndef _RTL_USTRING_HXX_
123*cdf0e10cSrcweir #include <rtl/ustring.hxx>
124*cdf0e10cSrcweir #endif
125*cdf0e10cSrcweir #ifndef _RTL_LOGFILE_HXX_
126*cdf0e10cSrcweir #include <rtl/logfile.hxx>
127*cdf0e10cSrcweir #endif
128*cdf0e10cSrcweir #include <algorithm>
129*cdf0e10cSrcweir #include <hash_map>
130*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
131*cdf0e10cSrcweir #include <limits>
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir using namespace ::com::sun::star;
134*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
135*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
136*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
137*cdf0e10cSrcweir using namespace ::com::sun::star::frame::status;
138*cdf0e10cSrcweir using namespace ::com::sun::star::util;
139*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
140*cdf0e10cSrcweir using namespace ::com::sun::star::container;
141*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
142*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
143*cdf0e10cSrcweir using namespace ::com::sun::star::task;
144*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
145*cdf0e10cSrcweir using namespace ::com::sun::star;
146*cdf0e10cSrcweir using namespace ::dbtools;
147*cdf0e10cSrcweir using namespace ::comphelper;
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir // -------------------------------------------------------------------------
150*cdf0e10cSrcweir #define ALL_FEATURES	            -1
151*cdf0e10cSrcweir #define FIRST_USER_DEFINED_FEATURE  ( ::std::numeric_limits< sal_uInt16 >::max() - 1000 )
152*cdf0e10cSrcweir #define LAST_USER_DEFINED_FEATURE   ( ::std::numeric_limits< sal_uInt16 >::max()        )
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir // -------------------------------------------------------------------------
155*cdf0e10cSrcweir typedef ::std::hash_map< sal_Int16, sal_Int16 > CommandHashMap;
156*cdf0e10cSrcweir typedef ::std::list< DispatchInformation > DispatchInfoList;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir // -------------------------------------------------------------------------
160*cdf0e10cSrcweir const ::rtl::OUString& getConfirmDeletionURL()
161*cdf0e10cSrcweir {
162*cdf0e10cSrcweir 	static const ::rtl::OUString sConfirmDeletionURL( RTL_CONSTASCII_USTRINGPARAM( ".uno:FormSlots/ConfirmDeletion" ) );
163*cdf0e10cSrcweir 	return sConfirmDeletionURL;
164*cdf0e10cSrcweir }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir namespace dbaui
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir //==========================================================================
170*cdf0e10cSrcweir //= UserDefinedFeatures
171*cdf0e10cSrcweir //==========================================================================
172*cdf0e10cSrcweir class UserDefinedFeatures
173*cdf0e10cSrcweir {
174*cdf0e10cSrcweir public:
175*cdf0e10cSrcweir     UserDefinedFeatures( const Reference< XController >& _rxController );
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir     FeatureState    getState( const URL& _rFeatureURL );
178*cdf0e10cSrcweir     void            execute( const URL& _rFeatureURL, const Sequence< PropertyValue>& _rArgs );
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir private:
181*cdf0e10cSrcweir     ::com::sun::star::uno::WeakReference< XController > m_aController;
182*cdf0e10cSrcweir };
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir //--------------------------------------------------------------------------
185*cdf0e10cSrcweir UserDefinedFeatures::UserDefinedFeatures( const Reference< XController >& _rxController )
186*cdf0e10cSrcweir     :m_aController( _rxController )
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir //--------------------------------------------------------------------------
191*cdf0e10cSrcweir FeatureState UserDefinedFeatures::getState( const URL& /*_rFeatureURL*/ )
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir     // for now, enable all the time
194*cdf0e10cSrcweir     // TODO: we should ask the dispatcher. However, this is laborious, since you cannot ask a dispatcher
195*cdf0e10cSrcweir     // directly, but need to add a status listener.
196*cdf0e10cSrcweir     FeatureState aState;
197*cdf0e10cSrcweir     aState.bEnabled = sal_True;
198*cdf0e10cSrcweir     return aState;
199*cdf0e10cSrcweir }
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir //--------------------------------------------------------------------------
202*cdf0e10cSrcweir void UserDefinedFeatures::execute( const URL& _rFeatureURL, const Sequence< PropertyValue>& _rArgs )
203*cdf0e10cSrcweir {
204*cdf0e10cSrcweir     try
205*cdf0e10cSrcweir     {
206*cdf0e10cSrcweir         Reference< XController > xController( (Reference< XController >)m_aController, UNO_SET_THROW );
207*cdf0e10cSrcweir         Reference< XDispatchProvider > xDispatchProvider( xController->getFrame(), UNO_QUERY_THROW );
208*cdf0e10cSrcweir         Reference< XDispatch > xDispatch( xDispatchProvider->queryDispatch(
209*cdf0e10cSrcweir             _rFeatureURL,
210*cdf0e10cSrcweir             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_self" ) ),
211*cdf0e10cSrcweir             FrameSearchFlag::AUTO
212*cdf0e10cSrcweir         ) );
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir         if ( xDispatch == xController )
215*cdf0e10cSrcweir         {
216*cdf0e10cSrcweir             OSL_ENSURE( false, "UserDefinedFeatures::execute: the controller shouldn't be the dispatcher here!" );
217*cdf0e10cSrcweir             xDispatch.clear();
218*cdf0e10cSrcweir         }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir         if ( xDispatch.is() )
221*cdf0e10cSrcweir             xDispatch->dispatch( _rFeatureURL, _rArgs );
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir     catch( const Exception& )
224*cdf0e10cSrcweir     {
225*cdf0e10cSrcweir     	DBG_UNHANDLED_EXCEPTION();
226*cdf0e10cSrcweir     }
227*cdf0e10cSrcweir }
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir //==========================================================================
230*cdf0e10cSrcweir //= OGenericUnoController_Data
231*cdf0e10cSrcweir //==========================================================================
232*cdf0e10cSrcweir struct OGenericUnoController_Data
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir     ::sfx2::UserInputInterception   m_aUserInputInterception;
235*cdf0e10cSrcweir     UserDefinedFeatures             m_aUserDefinedFeatures;
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir     OGenericUnoController_Data( OGenericUnoController& _rController, ::osl::Mutex& _rMutex )
238*cdf0e10cSrcweir         :m_aUserInputInterception( _rController, _rMutex )
239*cdf0e10cSrcweir         ,m_aUserDefinedFeatures( _rController.getXController() )
240*cdf0e10cSrcweir     {
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir };
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir //==========================================================================
245*cdf0e10cSrcweir //= OGenericUnoController
246*cdf0e10cSrcweir //==========================================================================
247*cdf0e10cSrcweir DBG_NAME(OGenericUnoController)
248*cdf0e10cSrcweir // -------------------------------------------------------------------------
249*cdf0e10cSrcweir OGenericUnoController::OGenericUnoController(const Reference< XMultiServiceFactory >& _rM)
250*cdf0e10cSrcweir 	:OGenericUnoController_Base( getMutex() )
251*cdf0e10cSrcweir 	,m_pView(NULL)
252*cdf0e10cSrcweir #ifdef DBG_UTIL
253*cdf0e10cSrcweir     ,m_bDescribingSupportedFeatures( false )
254*cdf0e10cSrcweir #endif
255*cdf0e10cSrcweir 	,m_aAsyncInvalidateAll(LINK(this, OGenericUnoController, OnAsyncInvalidateAll))
256*cdf0e10cSrcweir 	,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask))
257*cdf0e10cSrcweir 	,m_xServiceFactory(_rM)
258*cdf0e10cSrcweir     ,m_aCurrentFrame( *this )
259*cdf0e10cSrcweir 	,m_bPreview(sal_False)
260*cdf0e10cSrcweir 	,m_bReadOnly(sal_False)
261*cdf0e10cSrcweir 	,m_bCurrentlyModified(sal_False)
262*cdf0e10cSrcweir     ,m_bExternalTitle(sal_False)
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
265*cdf0e10cSrcweir     {
266*cdf0e10cSrcweir         m_pData.reset( new OGenericUnoController_Data( *this, getMutex() ) );
267*cdf0e10cSrcweir     }
268*cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir     DBG_CTOR(OGenericUnoController,NULL);
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 	try
273*cdf0e10cSrcweir 	{
274*cdf0e10cSrcweir 		m_xUrlTransformer = Reference< XURLTransformer > (_rM->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer")), UNO_QUERY);
275*cdf0e10cSrcweir 	}
276*cdf0e10cSrcweir 	catch(Exception&)
277*cdf0e10cSrcweir 	{
278*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
279*cdf0e10cSrcweir 	}
280*cdf0e10cSrcweir }
281*cdf0e10cSrcweir 
282*cdf0e10cSrcweir #ifdef WNT
283*cdf0e10cSrcweir // -----------------------------------------------------------------------------
284*cdf0e10cSrcweir OGenericUnoController::OGenericUnoController()
285*cdf0e10cSrcweir 	:OGenericUnoController_Base( getMutex() )
286*cdf0e10cSrcweir 	,m_pView(NULL)
287*cdf0e10cSrcweir #ifdef DBG_UTIL
288*cdf0e10cSrcweir     ,m_bDescribingSupportedFeatures( false )
289*cdf0e10cSrcweir #endif
290*cdf0e10cSrcweir 	,m_aAsyncInvalidateAll(LINK(this, OGenericUnoController, OnAsyncInvalidateAll))
291*cdf0e10cSrcweir 	,m_aAsyncCloseTask(LINK(this, OGenericUnoController, OnAsyncCloseTask))
292*cdf0e10cSrcweir     ,m_aCurrentFrame( *this )
293*cdf0e10cSrcweir 	,m_bPreview(sal_False)
294*cdf0e10cSrcweir 	,m_bReadOnly(sal_False)
295*cdf0e10cSrcweir 	,m_bCurrentlyModified(sal_False)
296*cdf0e10cSrcweir {
297*cdf0e10cSrcweir     OSL_ENSURE( false, "OGenericUnoController::OGenericUnoController: illegal call!" );
298*cdf0e10cSrcweir     // This ctor only exists because the MSVC compiler complained about an unresolved external
299*cdf0e10cSrcweir     // symbol. It should not be used at all. Since using it yields strange runtime problems,
300*cdf0e10cSrcweir     // we simply abort here.
301*cdf0e10cSrcweir     abort();
302*cdf0e10cSrcweir }
303*cdf0e10cSrcweir #endif
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir // -----------------------------------------------------------------------------
306*cdf0e10cSrcweir OGenericUnoController::~OGenericUnoController()
307*cdf0e10cSrcweir {
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     DBG_DTOR(OGenericUnoController,NULL);
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir // -----------------------------------------------------------------------------
313*cdf0e10cSrcweir sal_Bool OGenericUnoController::Construct(Window* /*pParent*/)
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir 	OSL_ENSURE( getView(), "the view is NULL!" );
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir 	if ( getView() )
318*cdf0e10cSrcweir 	{
319*cdf0e10cSrcweir 		getView()->Construct();
320*cdf0e10cSrcweir 		getView()->Show();
321*cdf0e10cSrcweir 	}
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir     m_aSupportedFeatures.clear();
324*cdf0e10cSrcweir 	fillSupportedFeatures();
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 	// create the database context
327*cdf0e10cSrcweir 	DBG_ASSERT(getORB().is(), "OGenericUnoController::Construct need a service factory!");
328*cdf0e10cSrcweir 	try
329*cdf0e10cSrcweir 	{
330*cdf0e10cSrcweir 		m_xDatabaseContext = Reference< XNameAccess >(getORB()->createInstance(SERVICE_SDB_DATABASECONTEXT), UNO_QUERY);
331*cdf0e10cSrcweir 	}
332*cdf0e10cSrcweir 	catch(Exception&)
333*cdf0e10cSrcweir 	{
334*cdf0e10cSrcweir 		DBG_ERROR("OGenericUnoController::Construct: could not create (or start listening at) the database context!");
335*cdf0e10cSrcweir 	}
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir 	if (!m_xDatabaseContext.is())
338*cdf0e10cSrcweir 	{		// at least notify the user. Though the whole component does not make any sense without the database context ...
339*cdf0e10cSrcweir 		ShowServiceNotAvailableError(getView(), String(SERVICE_SDB_DATABASECONTEXT), sal_True);
340*cdf0e10cSrcweir 	}
341*cdf0e10cSrcweir 	return sal_True;
342*cdf0e10cSrcweir }
343*cdf0e10cSrcweir //------------------------------------------------------------------------------
344*cdf0e10cSrcweir IMPL_LINK(OGenericUnoController, OnAsyncInvalidateAll, void*, EMPTYARG)
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir 	if ( !OGenericUnoController_Base::rBHelper.bInDispose && !OGenericUnoController_Base::rBHelper.bDisposed )
347*cdf0e10cSrcweir 		InvalidateFeature_Impl();
348*cdf0e10cSrcweir 	return 0L;
349*cdf0e10cSrcweir }
350*cdf0e10cSrcweir // -----------------------------------------------------------------------------
351*cdf0e10cSrcweir void OGenericUnoController::impl_initialize()
352*cdf0e10cSrcweir {
353*cdf0e10cSrcweir }
354*cdf0e10cSrcweir // -------------------------------------------------------------------------
355*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException)
356*cdf0e10cSrcweir {
357*cdf0e10cSrcweir 	vos::OGuard aSolarGuard( Application::GetSolarMutex() );
358*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	Reference< XWindow >		xParent;
361*cdf0e10cSrcweir 	Reference< XFrame > xFrame;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir 	PropertyValue aValue;
364*cdf0e10cSrcweir 	const Any* pIter	= aArguments.getConstArray();
365*cdf0e10cSrcweir 	const Any* pEnd 	= pIter + aArguments.getLength();
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir 	for ( ; pIter != pEnd; ++pIter )
368*cdf0e10cSrcweir 	{
369*cdf0e10cSrcweir 		if ( ( *pIter >>= aValue ) && ( 0 == aValue.Name.compareToAscii( "Frame" ) ) )
370*cdf0e10cSrcweir 		{
371*cdf0e10cSrcweir             xFrame.set(aValue.Value,UNO_QUERY_THROW);
372*cdf0e10cSrcweir 		}
373*cdf0e10cSrcweir         /* #i42316#
374*cdf0e10cSrcweir 		else if ( ( *pIter >>= aValue ) && ( 0 == aValue.Name.compareToAscii( "ReadOnly" ) ) )
375*cdf0e10cSrcweir 		{
376*cdf0e10cSrcweir 			aValue.Value >>= m_bReadOnly;
377*cdf0e10cSrcweir 		}
378*cdf0e10cSrcweir         */
379*cdf0e10cSrcweir 		else if ( ( *pIter >>= aValue ) && ( 0 == aValue.Name.compareToAscii( "Preview" ) ) )
380*cdf0e10cSrcweir 		{
381*cdf0e10cSrcweir 			aValue.Value >>= m_bPreview;
382*cdf0e10cSrcweir             m_bReadOnly = sal_True;
383*cdf0e10cSrcweir 		}
384*cdf0e10cSrcweir 	}
385*cdf0e10cSrcweir 	try
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir 		if ( !xFrame.is() )
388*cdf0e10cSrcweir             throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "need a frame" ) ), *this, 1 );
389*cdf0e10cSrcweir 
390*cdf0e10cSrcweir         xParent = xFrame->getContainerWindow();
391*cdf0e10cSrcweir 		VCLXWindow* pParentComponent = VCLXWindow::GetImplementation(xParent);
392*cdf0e10cSrcweir 		Window* pParentWin = pParentComponent ? pParentComponent->GetWindow() : NULL;
393*cdf0e10cSrcweir 		if (!pParentWin)
394*cdf0e10cSrcweir 		{
395*cdf0e10cSrcweir 			throw IllegalArgumentException( ::rtl::OUString::createFromAscii( "Parent window is null" ), *this, 1 );
396*cdf0e10cSrcweir 		}
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir         m_aInitParameters.assign( aArguments );
399*cdf0e10cSrcweir 		Construct( pParentWin );
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir         ODataView* pView = getView();
402*cdf0e10cSrcweir         if ( !pView )
403*cdf0e10cSrcweir             throw RuntimeException( ::rtl::OUString::createFromAscii( "unable to create a view" ), *this );
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 		if ( m_bReadOnly || m_bPreview )
406*cdf0e10cSrcweir 			pView->EnableInput( sal_False );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir         impl_initialize();
409*cdf0e10cSrcweir 	}
410*cdf0e10cSrcweir 	catch(Exception& e)
411*cdf0e10cSrcweir 	{
412*cdf0e10cSrcweir 		// no one clears my view if I won't
413*cdf0e10cSrcweir 		::std::auto_ptr<Window> aTemp(m_pView);
414*cdf0e10cSrcweir 		m_pView = NULL;
415*cdf0e10cSrcweir 		throw;
416*cdf0e10cSrcweir 	}
417*cdf0e10cSrcweir }
418*cdf0e10cSrcweir 
419*cdf0e10cSrcweir //------------------------------------------------------------------------------
420*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::acquire(  ) throw ()
421*cdf0e10cSrcweir {
422*cdf0e10cSrcweir 	OGenericUnoController_Base::acquire();
423*cdf0e10cSrcweir }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir //------------------------------------------------------------------------------
426*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::release(  ) throw ()
427*cdf0e10cSrcweir {
428*cdf0e10cSrcweir 	OGenericUnoController_Base::release();
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir // -------------------------------------------------------------------------
432*cdf0e10cSrcweir void OGenericUnoController::startFrameListening( const Reference< XFrame >& _rxFrame )
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir     if ( _rxFrame.is() )
435*cdf0e10cSrcweir 	    _rxFrame->addFrameActionListener( this );
436*cdf0e10cSrcweir }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir // -------------------------------------------------------------------------
439*cdf0e10cSrcweir void OGenericUnoController::stopFrameListening( const Reference< XFrame >& _rxFrame )
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir 	if ( _rxFrame.is() )
442*cdf0e10cSrcweir 		_rxFrame->removeFrameActionListener( this );
443*cdf0e10cSrcweir }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir // -------------------------------------------------------------------------
446*cdf0e10cSrcweir void OGenericUnoController::disposing(const EventObject& Source) throw( RuntimeException )
447*cdf0e10cSrcweir {
448*cdf0e10cSrcweir 	// our frame ?
449*cdf0e10cSrcweir 	if ( Source.Source == getFrame() )
450*cdf0e10cSrcweir 		stopFrameListening( getFrame() );
451*cdf0e10cSrcweir }
452*cdf0e10cSrcweir //------------------------------------------------------------------------
453*cdf0e10cSrcweir void OGenericUnoController::modified(const EventObject& aEvent) throw( RuntimeException )
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
456*cdf0e10cSrcweir 	if ( !isDataSourceReadOnly() )
457*cdf0e10cSrcweir 	{
458*cdf0e10cSrcweir 		Reference<XModifiable> xModi(aEvent.Source,UNO_QUERY);
459*cdf0e10cSrcweir 		if ( xModi.is() )
460*cdf0e10cSrcweir 			m_bCurrentlyModified = xModi->isModified(); // can only be reset by save
461*cdf0e10cSrcweir 		else
462*cdf0e10cSrcweir 			m_bCurrentlyModified = sal_True;
463*cdf0e10cSrcweir 	}
464*cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_SAVEDOC);
465*cdf0e10cSrcweir 	InvalidateFeature(ID_BROWSER_UNDO);
466*cdf0e10cSrcweir }
467*cdf0e10cSrcweir // -----------------------------------------------------------------------
468*cdf0e10cSrcweir Reference< XWindow > SAL_CALL OGenericUnoController::getComponentWindow() throw (RuntimeException)
469*cdf0e10cSrcweir {
470*cdf0e10cSrcweir 	return VCLUnoHelper::GetInterface( getView() );
471*cdf0e10cSrcweir }
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir // -----------------------------------------------------------------------
474*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OGenericUnoController::getViewControllerName() throw (::com::sun::star::uno::RuntimeException)
475*cdf0e10cSrcweir {
476*cdf0e10cSrcweir     return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) );
477*cdf0e10cSrcweir }
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir // -----------------------------------------------------------------------
480*cdf0e10cSrcweir Sequence< PropertyValue > SAL_CALL OGenericUnoController::getCreationArguments() throw (RuntimeException)
481*cdf0e10cSrcweir {
482*cdf0e10cSrcweir     // currently we do not support any creation args, so anything passed to XModel2::createViewController would be
483*cdf0e10cSrcweir     // lost, so we can equally return an empty sequence here
484*cdf0e10cSrcweir     return Sequence< PropertyValue >();
485*cdf0e10cSrcweir }
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir // -----------------------------------------------------------------------
488*cdf0e10cSrcweir void OGenericUnoController::attachFrame( const Reference< XFrame >& _rxFrame ) throw( RuntimeException )
489*cdf0e10cSrcweir {
490*cdf0e10cSrcweir     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
491*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     stopFrameListening( m_aCurrentFrame.getFrame() );
494*cdf0e10cSrcweir 	Reference< XFrame > xFrame = m_aCurrentFrame.attachFrame( _rxFrame );
495*cdf0e10cSrcweir 	startFrameListening( xFrame );
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 	loadMenu( xFrame );
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir 	if ( getView() )
500*cdf0e10cSrcweir 		getView()->attachFrame( xFrame );
501*cdf0e10cSrcweir }
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir // -----------------------------------------------------------------------------
504*cdf0e10cSrcweir struct CommandCollector : public ::std::unary_function< SupportedFeatures::value_type, void>
505*cdf0e10cSrcweir {
506*cdf0e10cSrcweir 	sal_uInt16  m_nFeature;
507*cdf0e10cSrcweir 	StringBag&  m_rFeatureCommands;
508*cdf0e10cSrcweir 	CommandCollector( sal_uInt16 _nFeature, StringBag& _rFeatureCommands )
509*cdf0e10cSrcweir         :m_nFeature        ( _nFeature         )
510*cdf0e10cSrcweir         ,m_rFeatureCommands( _rFeatureCommands )
511*cdf0e10cSrcweir     {
512*cdf0e10cSrcweir     }
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir 	void operator() ( const SupportedFeatures::value_type& lhs )
515*cdf0e10cSrcweir 	{
516*cdf0e10cSrcweir 		if ( lhs.second.nFeatureId == m_nFeature )
517*cdf0e10cSrcweir 			m_rFeatureCommands.insert( lhs.first );
518*cdf0e10cSrcweir 	}
519*cdf0e10cSrcweir };
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir // -----------------------------------------------------------------------
522*cdf0e10cSrcweir namespace
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir     typedef ::std::vector< Any >    States;
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir     // ...................................................................
527*cdf0e10cSrcweir     void    lcl_notifyMultipleStates( XStatusListener& _rListener, FeatureStateEvent& _rEvent, const States& _rStates )
528*cdf0e10cSrcweir     {
529*cdf0e10cSrcweir         for (   States::const_iterator state = _rStates.begin();
530*cdf0e10cSrcweir                 state != _rStates.end();
531*cdf0e10cSrcweir                 ++state
532*cdf0e10cSrcweir             )
533*cdf0e10cSrcweir         {
534*cdf0e10cSrcweir             _rEvent.State = *state;
535*cdf0e10cSrcweir             _rListener.statusChanged( _rEvent );
536*cdf0e10cSrcweir         }
537*cdf0e10cSrcweir     }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir     // ...................................................................
540*cdf0e10cSrcweir     void    lcl_collectStates( const FeatureState& _rFeatureState, States& _out_rStates )
541*cdf0e10cSrcweir     {
542*cdf0e10cSrcweir         // order matters, due to a bug in framework which resets the check state when any non-boolean event
543*cdf0e10cSrcweir         // arrives
544*cdf0e10cSrcweir         // #i68215# is the bug to (re-)introduce this "ordered" notification here
545*cdf0e10cSrcweir         // #i67882# is the bug which was caused by the real fix which we did in framework
546*cdf0e10cSrcweir         // #i68216# is the bug which requests to fix the code in Draw which relies on
547*cdf0e10cSrcweir         //          framework's implementation details
548*cdf0e10cSrcweir         // 2006-08-07 / frank.schoenheit@sun.com
549*cdf0e10cSrcweir         if ( !!_rFeatureState.sTitle )
550*cdf0e10cSrcweir             _out_rStates.push_back( makeAny( *_rFeatureState.sTitle ) );
551*cdf0e10cSrcweir         if ( !!_rFeatureState.bChecked )
552*cdf0e10cSrcweir             _out_rStates.push_back( makeAny( (sal_Bool)*_rFeatureState.bChecked ) );
553*cdf0e10cSrcweir         if ( !!_rFeatureState.bInvisible )
554*cdf0e10cSrcweir             _out_rStates.push_back( makeAny( Visibility( !*_rFeatureState.bInvisible ) ) );
555*cdf0e10cSrcweir         if ( _rFeatureState.aValue.hasValue() )
556*cdf0e10cSrcweir             _out_rStates.push_back( _rFeatureState.aValue );
557*cdf0e10cSrcweir         if ( _out_rStates.empty() )
558*cdf0e10cSrcweir             _out_rStates.push_back( Any() );
559*cdf0e10cSrcweir     }
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir // -----------------------------------------------------------------------
563*cdf0e10cSrcweir void OGenericUnoController::ImplBroadcastFeatureState(const ::rtl::OUString& _rFeature, const Reference< XStatusListener > & xListener, sal_Bool _bIgnoreCache)
564*cdf0e10cSrcweir {
565*cdf0e10cSrcweir 	sal_uInt16 nFeat = m_aSupportedFeatures[ _rFeature ].nFeatureId;
566*cdf0e10cSrcweir 	FeatureState aFeatState( GetState( nFeat ) );
567*cdf0e10cSrcweir 
568*cdf0e10cSrcweir 	FeatureState& rCachedState = m_aStateCache[nFeat];	// creates if neccessary
569*cdf0e10cSrcweir 	if ( !_bIgnoreCache )
570*cdf0e10cSrcweir 	{
571*cdf0e10cSrcweir 		// check if we really need to notify the listeners : this method may be called much more often than needed, so check
572*cdf0e10cSrcweir 		// the cached state of the feature
573*cdf0e10cSrcweir 		sal_Bool bAlreadyCached = ( m_aStateCache.find(nFeat) != m_aStateCache.end() );
574*cdf0e10cSrcweir 		if ( bAlreadyCached )
575*cdf0e10cSrcweir             if  (   ( rCachedState.bEnabled == aFeatState.bEnabled )
576*cdf0e10cSrcweir                 &&  ( rCachedState.bChecked == aFeatState.bChecked )
577*cdf0e10cSrcweir                 &&  ( rCachedState.bInvisible == aFeatState.bInvisible )
578*cdf0e10cSrcweir                 &&  ( rCachedState.sTitle == aFeatState.sTitle )
579*cdf0e10cSrcweir                 )
580*cdf0e10cSrcweir             return;
581*cdf0e10cSrcweir 	}
582*cdf0e10cSrcweir 	rCachedState = aFeatState;
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 	FeatureStateEvent aEvent;
585*cdf0e10cSrcweir 	aEvent.FeatureURL.Complete = _rFeature;
586*cdf0e10cSrcweir 	if (m_xUrlTransformer.is())
587*cdf0e10cSrcweir 		m_xUrlTransformer->parseStrict(aEvent.FeatureURL);
588*cdf0e10cSrcweir 	aEvent.Source		= (XDispatch*)this;
589*cdf0e10cSrcweir 	aEvent.IsEnabled	= aFeatState.bEnabled;
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir     // collect all states to be notified
592*cdf0e10cSrcweir     States aStates;
593*cdf0e10cSrcweir     lcl_collectStates( aFeatState, aStates );
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 	// a special listener ?
596*cdf0e10cSrcweir 	if ( xListener.is() )
597*cdf0e10cSrcweir         lcl_notifyMultipleStates( *xListener.get(), aEvent, aStates );
598*cdf0e10cSrcweir 	else
599*cdf0e10cSrcweir 	{	// no -> iterate through all listeners responsible for the URL
600*cdf0e10cSrcweir         StringBag aFeatureCommands;
601*cdf0e10cSrcweir 		::std::for_each(
602*cdf0e10cSrcweir             m_aSupportedFeatures.begin(),
603*cdf0e10cSrcweir             m_aSupportedFeatures.end(),
604*cdf0e10cSrcweir             CommandCollector( nFeat, aFeatureCommands )
605*cdf0e10cSrcweir         );
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir 		// it is possible that listeners are registered or revoked while
608*cdf0e10cSrcweir 		// we are notifying them, so we must use a copy of m_arrStatusListener, not
609*cdf0e10cSrcweir 		// m_arrStatusListener itself
610*cdf0e10cSrcweir 		// #121276# / 2005-05-19 / frank.schoenheit@sun.com
611*cdf0e10cSrcweir 		Dispatch aNotifyLoop( m_arrStatusListener );
612*cdf0e10cSrcweir 		DispatchIterator iterSearch = aNotifyLoop.begin();
613*cdf0e10cSrcweir 		DispatchIterator iterEnd = aNotifyLoop.end();
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir 		while (iterSearch != iterEnd)
616*cdf0e10cSrcweir 		{
617*cdf0e10cSrcweir 			DispatchTarget& rCurrent = *iterSearch;
618*cdf0e10cSrcweir 			if ( aFeatureCommands.find( rCurrent.aURL.Complete ) != aFeatureCommands.end() )
619*cdf0e10cSrcweir 			{
620*cdf0e10cSrcweir 				aEvent.FeatureURL = rCurrent.aURL;
621*cdf0e10cSrcweir                 lcl_notifyMultipleStates( *rCurrent.xListener.get(), aEvent, aStates );
622*cdf0e10cSrcweir 			}
623*cdf0e10cSrcweir 			++iterSearch;
624*cdf0e10cSrcweir 		}
625*cdf0e10cSrcweir 	}
626*cdf0e10cSrcweir 
627*cdf0e10cSrcweir }
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir //------------------------------------------------------------------------------
630*cdf0e10cSrcweir sal_Bool OGenericUnoController::isFeatureSupported( sal_Int32 _nId )
631*cdf0e10cSrcweir {
632*cdf0e10cSrcweir 	SupportedFeatures::iterator aFeaturePos = ::std::find_if(
633*cdf0e10cSrcweir 		m_aSupportedFeatures.begin(),
634*cdf0e10cSrcweir 		m_aSupportedFeatures.end(),
635*cdf0e10cSrcweir 		::std::bind2nd( CompareFeatureById(), _nId )
636*cdf0e10cSrcweir 	);
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir     return ( m_aSupportedFeatures.end() != aFeaturePos && aFeaturePos->first.getLength());
639*cdf0e10cSrcweir }
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir // -----------------------------------------------------------------------
642*cdf0e10cSrcweir void OGenericUnoController::InvalidateFeature(const ::rtl::OUString& _rURLPath, const Reference< XStatusListener > & _xListener, sal_Bool _bForceBroadcast)
643*cdf0e10cSrcweir {
644*cdf0e10cSrcweir 	ImplInvalidateFeature( m_aSupportedFeatures[ _rURLPath ].nFeatureId, _xListener, _bForceBroadcast );
645*cdf0e10cSrcweir }
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir // -----------------------------------------------------------------------------
648*cdf0e10cSrcweir void OGenericUnoController::InvalidateFeature_Impl()
649*cdf0e10cSrcweir {
650*cdf0e10cSrcweir #ifdef DBG_UTIL
651*cdf0e10cSrcweir 	static sal_Int32 s_nRecursions = 0;
652*cdf0e10cSrcweir 	++s_nRecursions;
653*cdf0e10cSrcweir #endif
654*cdf0e10cSrcweir 
655*cdf0e10cSrcweir 	sal_Bool bEmpty = sal_True;
656*cdf0e10cSrcweir 	FeatureListener aNextFeature;
657*cdf0e10cSrcweir 	{
658*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aFeatureMutex);
659*cdf0e10cSrcweir 		bEmpty = m_aFeaturesToInvalidate.empty();
660*cdf0e10cSrcweir 		if (!bEmpty)
661*cdf0e10cSrcweir 			aNextFeature = m_aFeaturesToInvalidate.front();
662*cdf0e10cSrcweir 	}
663*cdf0e10cSrcweir 	while(!bEmpty)
664*cdf0e10cSrcweir 	{
665*cdf0e10cSrcweir 		if ( ALL_FEATURES == aNextFeature.nId )
666*cdf0e10cSrcweir 		{
667*cdf0e10cSrcweir 			InvalidateAll_Impl();
668*cdf0e10cSrcweir 			break;
669*cdf0e10cSrcweir 		}
670*cdf0e10cSrcweir 		else
671*cdf0e10cSrcweir 		{
672*cdf0e10cSrcweir 			SupportedFeatures::iterator aFeaturePos = ::std::find_if(
673*cdf0e10cSrcweir 				m_aSupportedFeatures.begin(),
674*cdf0e10cSrcweir 				m_aSupportedFeatures.end(),
675*cdf0e10cSrcweir 				::std::bind2nd( CompareFeatureById(), aNextFeature.nId )
676*cdf0e10cSrcweir 			);
677*cdf0e10cSrcweir 
678*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
679*cdf0e10cSrcweir             if ( m_aSupportedFeatures.end() == aFeaturePos )
680*cdf0e10cSrcweir             {
681*cdf0e10cSrcweir                 ::rtl::OString sMessage( "OGenericUnoController::InvalidateFeature_Impl: feature id " );
682*cdf0e10cSrcweir                 sMessage += ::rtl::OString::valueOf( aNextFeature.nId );
683*cdf0e10cSrcweir                 sMessage += ::rtl::OString( " has been invalidated, but is not supported!" );
684*cdf0e10cSrcweir                 OSL_ENSURE( false, sMessage.getStr() );
685*cdf0e10cSrcweir             }
686*cdf0e10cSrcweir #endif
687*cdf0e10cSrcweir 			if ( m_aSupportedFeatures.end() != aFeaturePos )
688*cdf0e10cSrcweir 				// we really know this feature
689*cdf0e10cSrcweir 				ImplBroadcastFeatureState( aFeaturePos->first, aNextFeature.xListener, aNextFeature.bForceBroadcast );
690*cdf0e10cSrcweir 		}
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aFeatureMutex);
693*cdf0e10cSrcweir 		m_aFeaturesToInvalidate.pop_front();
694*cdf0e10cSrcweir 		bEmpty = m_aFeaturesToInvalidate.empty();
695*cdf0e10cSrcweir 		if (!bEmpty)
696*cdf0e10cSrcweir 			aNextFeature = m_aFeaturesToInvalidate.front();
697*cdf0e10cSrcweir 	}
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir #ifdef DBG_UTIL
700*cdf0e10cSrcweir 	--s_nRecursions;
701*cdf0e10cSrcweir #endif
702*cdf0e10cSrcweir }
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir // -----------------------------------------------------------------------
705*cdf0e10cSrcweir void OGenericUnoController::ImplInvalidateFeature( sal_Int32 _nId, const Reference< XStatusListener >& _xListener, sal_Bool _bForceBroadcast )
706*cdf0e10cSrcweir {
707*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
708*cdf0e10cSrcweir     if ( _nId != -1 )
709*cdf0e10cSrcweir     {
710*cdf0e10cSrcweir 	    SupportedFeatures::iterator aFeaturePos = ::std::find_if(
711*cdf0e10cSrcweir 		    m_aSupportedFeatures.begin(),
712*cdf0e10cSrcweir 		    m_aSupportedFeatures.end(),
713*cdf0e10cSrcweir 		    ::std::bind2nd( CompareFeatureById(), _nId )
714*cdf0e10cSrcweir 	    );
715*cdf0e10cSrcweir         OSL_ENSURE( aFeaturePos != m_aSupportedFeatures.end(), "OGenericUnoController::ImplInvalidateFeature: invalidating an unsupported feature is suspicious, at least!" );
716*cdf0e10cSrcweir     }
717*cdf0e10cSrcweir #endif
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir 	FeatureListener aListener;
720*cdf0e10cSrcweir 	aListener.nId               = _nId;
721*cdf0e10cSrcweir 	aListener.xListener         = _xListener;
722*cdf0e10cSrcweir 	aListener.bForceBroadcast   = _bForceBroadcast;
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 	sal_Bool bWasEmpty;
725*cdf0e10cSrcweir 	{
726*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aFeatureMutex );
727*cdf0e10cSrcweir 		bWasEmpty = m_aFeaturesToInvalidate.empty();
728*cdf0e10cSrcweir 		m_aFeaturesToInvalidate.push_back( aListener );
729*cdf0e10cSrcweir 	}
730*cdf0e10cSrcweir 
731*cdf0e10cSrcweir 	if ( bWasEmpty )
732*cdf0e10cSrcweir 		m_aAsyncInvalidateAll.Call();
733*cdf0e10cSrcweir }
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir // -----------------------------------------------------------------------
736*cdf0e10cSrcweir void OGenericUnoController::InvalidateFeature(sal_uInt16 _nId, const Reference< XStatusListener > & _xListener, sal_Bool _bForceBroadcast)
737*cdf0e10cSrcweir {
738*cdf0e10cSrcweir 	ImplInvalidateFeature( _nId, _xListener, _bForceBroadcast );
739*cdf0e10cSrcweir }
740*cdf0e10cSrcweir 
741*cdf0e10cSrcweir // -----------------------------------------------------------------------
742*cdf0e10cSrcweir void OGenericUnoController::InvalidateAll()
743*cdf0e10cSrcweir {
744*cdf0e10cSrcweir 	ImplInvalidateFeature( ALL_FEATURES, NULL, sal_True );
745*cdf0e10cSrcweir }
746*cdf0e10cSrcweir 
747*cdf0e10cSrcweir // -----------------------------------------------------------------------------
748*cdf0e10cSrcweir void OGenericUnoController::InvalidateAll_Impl()
749*cdf0e10cSrcweir {
750*cdf0e10cSrcweir 	// ---------------------------------
751*cdf0e10cSrcweir 	// invalidate all aupported features
752*cdf0e10cSrcweir 
753*cdf0e10cSrcweir 	for (   SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.begin();
754*cdf0e10cSrcweir             aIter != m_aSupportedFeatures.end();
755*cdf0e10cSrcweir             ++aIter
756*cdf0e10cSrcweir         )
757*cdf0e10cSrcweir 		ImplBroadcastFeatureState( aIter->first, NULL, sal_True );
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir 	{
760*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aFeatureMutex);
761*cdf0e10cSrcweir 		DBG_ASSERT(m_aFeaturesToInvalidate.size(), "OGenericUnoController::InvalidateAll_Impl: to be called from within InvalidateFeature_Impl only!");
762*cdf0e10cSrcweir 		m_aFeaturesToInvalidate.pop_front();
763*cdf0e10cSrcweir 		if(!m_aFeaturesToInvalidate.empty())
764*cdf0e10cSrcweir 			m_aAsyncInvalidateAll.Call();
765*cdf0e10cSrcweir 	}
766*cdf0e10cSrcweir }
767*cdf0e10cSrcweir 
768*cdf0e10cSrcweir // -----------------------------------------------------------------------
769*cdf0e10cSrcweir Reference< XDispatch >	OGenericUnoController::queryDispatch(const URL& aURL, const ::rtl::OUString& aTargetFrameName, sal_Int32 nSearchFlags) throw( RuntimeException )
770*cdf0e10cSrcweir {
771*cdf0e10cSrcweir 	Reference< XDispatch > xReturn;
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::queryDispatch: shouldn't this be filled at construction time?" );
774*cdf0e10cSrcweir     if ( m_aSupportedFeatures.empty() )
775*cdf0e10cSrcweir         fillSupportedFeatures();
776*cdf0e10cSrcweir 
777*cdf0e10cSrcweir 	// URL's we can handle ourself?
778*cdf0e10cSrcweir 	if  (   aURL.Complete.equals( getConfirmDeletionURL() )
779*cdf0e10cSrcweir         ||  (   ( m_aSupportedFeatures.find( aURL.Complete ) != m_aSupportedFeatures.end() )
780*cdf0e10cSrcweir             &&  !isUserDefinedFeature( aURL.Complete )
781*cdf0e10cSrcweir             )
782*cdf0e10cSrcweir         )
783*cdf0e10cSrcweir 	{
784*cdf0e10cSrcweir 		xReturn = this;
785*cdf0e10cSrcweir 	}
786*cdf0e10cSrcweir 	// no? -> ask the slave dispatcher
787*cdf0e10cSrcweir 	else if ( m_xSlaveDispatcher.is() )
788*cdf0e10cSrcweir 	{
789*cdf0e10cSrcweir 		xReturn = m_xSlaveDispatcher->queryDispatch(aURL, aTargetFrameName, nSearchFlags);
790*cdf0e10cSrcweir 	}
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir 	// outta here
793*cdf0e10cSrcweir 	return xReturn;
794*cdf0e10cSrcweir }
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir // -----------------------------------------------------------------------
797*cdf0e10cSrcweir Sequence< Reference< XDispatch > > OGenericUnoController::queryDispatches(const Sequence< DispatchDescriptor >& aDescripts) throw( RuntimeException )
798*cdf0e10cSrcweir {
799*cdf0e10cSrcweir 	Sequence< Reference< XDispatch > > aReturn;
800*cdf0e10cSrcweir 	sal_Int32 nLen = aDescripts.getLength();
801*cdf0e10cSrcweir 	if ( nLen )
802*cdf0e10cSrcweir 	{
803*cdf0e10cSrcweir 		aReturn.realloc( nLen );
804*cdf0e10cSrcweir 				Reference< XDispatch >* pReturn 	= aReturn.getArray();
805*cdf0e10cSrcweir 		const	Reference< XDispatch >* pReturnEnd	= aReturn.getArray() + nLen;
806*cdf0e10cSrcweir 		const	DispatchDescriptor* 	pDescripts	= aDescripts.getConstArray();
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir 		for ( ; pReturn != pReturnEnd; ++ pReturn, ++pDescripts )
809*cdf0e10cSrcweir 		{
810*cdf0e10cSrcweir 			*pReturn = queryDispatch( pDescripts->FeatureURL, pDescripts->FrameName, pDescripts->SearchFlags );
811*cdf0e10cSrcweir 		}
812*cdf0e10cSrcweir 	}
813*cdf0e10cSrcweir 
814*cdf0e10cSrcweir 	return aReturn;
815*cdf0e10cSrcweir }
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir // -----------------------------------------------------------------------
818*cdf0e10cSrcweir Reference< XDispatchProvider >	OGenericUnoController::getSlaveDispatchProvider(void) throw( RuntimeException )
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir 	return m_xSlaveDispatcher;
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir // -----------------------------------------------------------------------
824*cdf0e10cSrcweir void OGenericUnoController::setSlaveDispatchProvider(const Reference< XDispatchProvider > & _xNewProvider) throw( RuntimeException )
825*cdf0e10cSrcweir {
826*cdf0e10cSrcweir 	m_xSlaveDispatcher = _xNewProvider;
827*cdf0e10cSrcweir }
828*cdf0e10cSrcweir 
829*cdf0e10cSrcweir // -----------------------------------------------------------------------
830*cdf0e10cSrcweir Reference< XDispatchProvider >	OGenericUnoController::getMasterDispatchProvider(void) throw( RuntimeException )
831*cdf0e10cSrcweir {
832*cdf0e10cSrcweir 	return m_xMasterDispatcher;
833*cdf0e10cSrcweir }
834*cdf0e10cSrcweir 
835*cdf0e10cSrcweir // -----------------------------------------------------------------------
836*cdf0e10cSrcweir void OGenericUnoController::setMasterDispatchProvider(const Reference< XDispatchProvider > & _xNewProvider) throw( RuntimeException )
837*cdf0e10cSrcweir {
838*cdf0e10cSrcweir 	m_xMasterDispatcher = _xNewProvider;
839*cdf0e10cSrcweir }
840*cdf0e10cSrcweir 
841*cdf0e10cSrcweir // -----------------------------------------------------------------------
842*cdf0e10cSrcweir void OGenericUnoController::dispatch(const URL& _aURL, const Sequence< PropertyValue >& aArgs) throw(RuntimeException)
843*cdf0e10cSrcweir {
844*cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
845*cdf0e10cSrcweir     // Since the fix for #123967#, the SolarMutex is not locked anymore when the framework calls into
846*cdf0e10cSrcweir     // here. So, lock it ourself. The real solution would be to lock it only in the places
847*cdf0e10cSrcweir     // where it's needed, but a) this might turn out difficult, since we then also need to care
848*cdf0e10cSrcweir     // for locking in the proper order (SolarMutex and m_aMutex), and b) this would be too many places
849*cdf0e10cSrcweir     // for the time frame of the fix.
850*cdf0e10cSrcweir     // #i52602# / frank.schoenheit@sun.com / 2005-07-29
851*cdf0e10cSrcweir 
852*cdf0e10cSrcweir #ifdef TIMELOG
853*cdf0e10cSrcweir     ::rtl::OString sLog( "OGenericUnoController::dispatch( '" );
854*cdf0e10cSrcweir     sLog += ::rtl::OString( _aURL.Main.getStr(), _aURL.Main.getLength(), osl_getThreadTextEncoding() );
855*cdf0e10cSrcweir     sLog += ::rtl::OString( "' )" );
856*cdf0e10cSrcweir     RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "frank.schoenheit@sun.com", sLog.getStr() );
857*cdf0e10cSrcweir #endif
858*cdf0e10cSrcweir 
859*cdf0e10cSrcweir     executeChecked(_aURL,aArgs);
860*cdf0e10cSrcweir }
861*cdf0e10cSrcweir 
862*cdf0e10cSrcweir // -----------------------------------------------------------------------
863*cdf0e10cSrcweir void OGenericUnoController::addStatusListener(const Reference< XStatusListener > & aListener, const URL& _rURL) throw(RuntimeException)
864*cdf0e10cSrcweir {
865*cdf0e10cSrcweir     // parse the ULR now and here, this saves later parsing in each notification round
866*cdf0e10cSrcweir     URL aParsedURL( _rURL );
867*cdf0e10cSrcweir 	if ( m_xUrlTransformer.is() )
868*cdf0e10cSrcweir 		m_xUrlTransformer->parseStrict( aParsedURL );
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir     // remeber the listener together with the URL
871*cdf0e10cSrcweir 	m_arrStatusListener.insert( m_arrStatusListener.end(), DispatchTarget( aParsedURL, aListener ) );
872*cdf0e10cSrcweir 
873*cdf0e10cSrcweir     // initially broadcast the state
874*cdf0e10cSrcweir 	ImplBroadcastFeatureState( aParsedURL.Complete, aListener, sal_True );
875*cdf0e10cSrcweir 		// force the new state to be broadcasted to the new listener
876*cdf0e10cSrcweir }
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir // -----------------------------------------------------------------------
879*cdf0e10cSrcweir void OGenericUnoController::removeStatusListener(const Reference< XStatusListener > & aListener, const URL& _rURL) throw(RuntimeException)
880*cdf0e10cSrcweir {
881*cdf0e10cSrcweir 	DispatchIterator iterSearch = m_arrStatusListener.begin();
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir 	sal_Bool bRemoveForAll = (_rURL.Complete.getLength() == 0);
884*cdf0e10cSrcweir 	while ( iterSearch != m_arrStatusListener.end() )
885*cdf0e10cSrcweir 	{
886*cdf0e10cSrcweir 		DispatchTarget& rCurrent = *iterSearch;
887*cdf0e10cSrcweir 		if	(	(rCurrent.xListener == aListener)
888*cdf0e10cSrcweir 			&&	(	bRemoveForAll
889*cdf0e10cSrcweir 				||	(rCurrent.aURL.Complete.equals(_rURL.Complete))
890*cdf0e10cSrcweir 				)
891*cdf0e10cSrcweir 			)
892*cdf0e10cSrcweir 		{
893*cdf0e10cSrcweir 			m_arrStatusListener.erase( iterSearch );
894*cdf0e10cSrcweir 			if (!bRemoveForAll)
895*cdf0e10cSrcweir 				// remove the listener only for the given URL, so we can exit the loop after deletion
896*cdf0e10cSrcweir 				break;
897*cdf0e10cSrcweir 		}
898*cdf0e10cSrcweir 		else
899*cdf0e10cSrcweir 			++iterSearch;
900*cdf0e10cSrcweir 	}
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::removeStatusListener: shouldn't this be filled at construction time?" );
903*cdf0e10cSrcweir     if ( m_aSupportedFeatures.empty() )
904*cdf0e10cSrcweir         fillSupportedFeatures();
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir 	SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find(_rURL.Complete);
907*cdf0e10cSrcweir 	if (aIter != m_aSupportedFeatures.end())
908*cdf0e10cSrcweir 	{	// clear the cache for that feature
909*cdf0e10cSrcweir 		StateCacheIterator aCachePos = m_aStateCache.find( aIter->second.nFeatureId );
910*cdf0e10cSrcweir 		if ( aCachePos != m_aStateCache.end() )
911*cdf0e10cSrcweir 			m_aStateCache.erase( aCachePos );
912*cdf0e10cSrcweir 	}
913*cdf0e10cSrcweir 
914*cdf0e10cSrcweir 	// now remove the listener from the deque
915*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aFeatureMutex );
916*cdf0e10cSrcweir 	m_aFeaturesToInvalidate.erase(
917*cdf0e10cSrcweir 		::std::remove_if(	m_aFeaturesToInvalidate.begin(),
918*cdf0e10cSrcweir 							m_aFeaturesToInvalidate.end(),
919*cdf0e10cSrcweir 							::std::bind2nd(FindFeatureListener(),aListener))
920*cdf0e10cSrcweir 		,m_aFeaturesToInvalidate.end());
921*cdf0e10cSrcweir }
922*cdf0e10cSrcweir // -----------------------------------------------------------------------------
923*cdf0e10cSrcweir void OGenericUnoController::releaseNumberForComponent()
924*cdf0e10cSrcweir {
925*cdf0e10cSrcweir     try
926*cdf0e10cSrcweir     {
927*cdf0e10cSrcweir         Reference< XUntitledNumbers > xUntitledProvider(getPrivateModel(), UNO_QUERY      );
928*cdf0e10cSrcweir         if ( xUntitledProvider.is() )
929*cdf0e10cSrcweir             xUntitledProvider->releaseNumberForComponent(static_cast<XWeak*>(this));
930*cdf0e10cSrcweir     }
931*cdf0e10cSrcweir     catch( const Exception& )
932*cdf0e10cSrcweir 	{
933*cdf0e10cSrcweir         // NII
934*cdf0e10cSrcweir 	}
935*cdf0e10cSrcweir }
936*cdf0e10cSrcweir // -----------------------------------------------------------------------
937*cdf0e10cSrcweir void OGenericUnoController::disposing()
938*cdf0e10cSrcweir {
939*cdf0e10cSrcweir 	{
940*cdf0e10cSrcweir 		EventObject aDisposeEvent;
941*cdf0e10cSrcweir 		aDisposeEvent.Source = static_cast<XWeak*>(this);
942*cdf0e10cSrcweir 		Dispatch aStatusListener = m_arrStatusListener;
943*cdf0e10cSrcweir 		Dispatch::iterator aEnd = aStatusListener.end();
944*cdf0e10cSrcweir 		for (Dispatch::iterator aIter = aStatusListener.begin(); aIter != aEnd; ++aIter)
945*cdf0e10cSrcweir 		{
946*cdf0e10cSrcweir 			aIter->xListener->disposing(aDisposeEvent);
947*cdf0e10cSrcweir 		}
948*cdf0e10cSrcweir 		m_arrStatusListener.clear();
949*cdf0e10cSrcweir 	}
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir 	m_xDatabaseContext = NULL;
952*cdf0e10cSrcweir 	{
953*cdf0e10cSrcweir 		::osl::MutexGuard aGuard( m_aFeatureMutex);
954*cdf0e10cSrcweir 		m_aAsyncInvalidateAll.CancelCall();
955*cdf0e10cSrcweir 		m_aFeaturesToInvalidate.clear();
956*cdf0e10cSrcweir 	}
957*cdf0e10cSrcweir 
958*cdf0e10cSrcweir     releaseNumberForComponent();
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir 	// check out from all the objects we are listening
961*cdf0e10cSrcweir 	// the frame
962*cdf0e10cSrcweir 	stopFrameListening( m_aCurrentFrame.getFrame() );
963*cdf0e10cSrcweir     m_aCurrentFrame.attachFrame( NULL );
964*cdf0e10cSrcweir 
965*cdf0e10cSrcweir     m_xMasterDispatcher = NULL;
966*cdf0e10cSrcweir     m_xSlaveDispatcher = NULL;
967*cdf0e10cSrcweir     m_xServiceFactory = NULL;
968*cdf0e10cSrcweir 	m_xTitleHelper.clear();
969*cdf0e10cSrcweir     m_xUrlTransformer.clear();
970*cdf0e10cSrcweir     m_aInitParameters.clear();
971*cdf0e10cSrcweir }
972*cdf0e10cSrcweir 
973*cdf0e10cSrcweir // -----------------------------------------------------------------------------
974*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::addEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
975*cdf0e10cSrcweir {
976*cdf0e10cSrcweir     // disambiguate
977*cdf0e10cSrcweir     OGenericUnoController_Base::WeakComponentImplHelperBase::addEventListener( xListener );
978*cdf0e10cSrcweir }
979*cdf0e10cSrcweir 
980*cdf0e10cSrcweir // -----------------------------------------------------------------------------
981*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::removeEventListener( const Reference< XEventListener >& xListener ) throw (RuntimeException)
982*cdf0e10cSrcweir {
983*cdf0e10cSrcweir     // disambiguate
984*cdf0e10cSrcweir     OGenericUnoController_Base::WeakComponentImplHelperBase::removeEventListener( xListener );
985*cdf0e10cSrcweir }
986*cdf0e10cSrcweir 
987*cdf0e10cSrcweir //------------------------------------------------------------------------------
988*cdf0e10cSrcweir void OGenericUnoController::frameAction(const FrameActionEvent& aEvent) throw( RuntimeException )
989*cdf0e10cSrcweir {
990*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
991*cdf0e10cSrcweir     if ( aEvent.Frame == m_aCurrentFrame.getFrame() )
992*cdf0e10cSrcweir         m_aCurrentFrame.frameAction( aEvent.Action );
993*cdf0e10cSrcweir }
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir //------------------------------------------------------------------------------
996*cdf0e10cSrcweir void OGenericUnoController::implDescribeSupportedFeature( const sal_Char* _pAsciiCommandURL,
997*cdf0e10cSrcweir         sal_uInt16 _nFeatureId, sal_Int16 _nCommandGroup )
998*cdf0e10cSrcweir {
999*cdf0e10cSrcweir #ifdef DBG_UTIL
1000*cdf0e10cSrcweir     DBG_ASSERT( m_bDescribingSupportedFeatures, "OGenericUnoController::implDescribeSupportedFeature: bad timing for this call!" );
1001*cdf0e10cSrcweir #endif
1002*cdf0e10cSrcweir     OSL_PRECOND( _nFeatureId < FIRST_USER_DEFINED_FEATURE, "OGenericUnoController::implDescribeSupportedFeature: invalid feature id!" );
1003*cdf0e10cSrcweir 
1004*cdf0e10cSrcweir     ControllerFeature aFeature;
1005*cdf0e10cSrcweir     aFeature.Command = ::rtl::OUString::createFromAscii( _pAsciiCommandURL );
1006*cdf0e10cSrcweir     aFeature.nFeatureId = _nFeatureId;
1007*cdf0e10cSrcweir     aFeature.GroupId = _nCommandGroup;
1008*cdf0e10cSrcweir 
1009*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1010*cdf0e10cSrcweir     OSL_ENSURE( m_aSupportedFeatures.find( aFeature.Command ) == m_aSupportedFeatures.end(),
1011*cdf0e10cSrcweir         "OGenericUnoController::implDescribeSupportedFeature: this feature is already there!" );
1012*cdf0e10cSrcweir #endif
1013*cdf0e10cSrcweir     m_aSupportedFeatures[ aFeature.Command ] = aFeature;
1014*cdf0e10cSrcweir }
1015*cdf0e10cSrcweir 
1016*cdf0e10cSrcweir //------------------------------------------------------------------------------
1017*cdf0e10cSrcweir void OGenericUnoController::describeSupportedFeatures()
1018*cdf0e10cSrcweir {
1019*cdf0e10cSrcweir     // add all supported features
1020*cdf0e10cSrcweir     implDescribeSupportedFeature( ".uno:Copy", ID_BROWSER_COPY, CommandGroup::EDIT );
1021*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:Cut", ID_BROWSER_CUT, CommandGroup::EDIT );
1022*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:Paste", ID_BROWSER_PASTE, CommandGroup::EDIT );
1023*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:ClipboardFormatItems", ID_BROWSER_CLIPBOARD_FORMAT_ITEMS );
1024*cdf0e10cSrcweir 	implDescribeSupportedFeature( ".uno:DSBEditDoc", ID_BROWSER_EDITDOC, CommandGroup::DOCUMENT );
1025*cdf0e10cSrcweir }
1026*cdf0e10cSrcweir 
1027*cdf0e10cSrcweir //------------------------------------------------------------------------------
1028*cdf0e10cSrcweir FeatureState OGenericUnoController::GetState( sal_uInt16 _nId ) const
1029*cdf0e10cSrcweir {
1030*cdf0e10cSrcweir 	FeatureState aReturn;
1031*cdf0e10cSrcweir 		// (disabled automatically)
1032*cdf0e10cSrcweir 
1033*cdf0e10cSrcweir 	switch ( _nId )
1034*cdf0e10cSrcweir 	{
1035*cdf0e10cSrcweir 		case ID_BROWSER_UNDO:
1036*cdf0e10cSrcweir 		case ID_BROWSER_SAVEDOC:
1037*cdf0e10cSrcweir 			aReturn.bEnabled = sal_True;
1038*cdf0e10cSrcweir 			break;
1039*cdf0e10cSrcweir         default:
1040*cdf0e10cSrcweir             aReturn = m_pData->m_aUserDefinedFeatures.getState( getURLForId( _nId ) );
1041*cdf0e10cSrcweir             break;
1042*cdf0e10cSrcweir 	}
1043*cdf0e10cSrcweir 
1044*cdf0e10cSrcweir 	return aReturn;
1045*cdf0e10cSrcweir }
1046*cdf0e10cSrcweir 
1047*cdf0e10cSrcweir //------------------------------------------------------------------------------
1048*cdf0e10cSrcweir void OGenericUnoController::Execute( sal_uInt16 _nId, const Sequence< PropertyValue>& _rArgs )
1049*cdf0e10cSrcweir {
1050*cdf0e10cSrcweir     OSL_ENSURE( isUserDefinedFeature( _nId ),
1051*cdf0e10cSrcweir         "OGenericUnoController::Execute: responsible for user defined features only!" );
1052*cdf0e10cSrcweir 
1053*cdf0e10cSrcweir     // user defined features can be handled by dispatch interceptors resp. protocol handlers only.
1054*cdf0e10cSrcweir     // So, we need to do a queryDispatch, and dispatch the URL
1055*cdf0e10cSrcweir     m_pData->m_aUserDefinedFeatures.execute( getURLForId( _nId ), _rArgs );
1056*cdf0e10cSrcweir }
1057*cdf0e10cSrcweir 
1058*cdf0e10cSrcweir //------------------------------------------------------------------------------
1059*cdf0e10cSrcweir URL OGenericUnoController::getURLForId(sal_Int32 _nId) const
1060*cdf0e10cSrcweir {
1061*cdf0e10cSrcweir 	URL aReturn;
1062*cdf0e10cSrcweir 	if ( m_xUrlTransformer.is() )
1063*cdf0e10cSrcweir 	{
1064*cdf0e10cSrcweir 		SupportedFeatures::const_iterator aIter = ::std::find_if(
1065*cdf0e10cSrcweir 			m_aSupportedFeatures.begin(),
1066*cdf0e10cSrcweir 			m_aSupportedFeatures.end(),
1067*cdf0e10cSrcweir 			::std::bind2nd( CompareFeatureById(), _nId )
1068*cdf0e10cSrcweir 		);
1069*cdf0e10cSrcweir 
1070*cdf0e10cSrcweir 		if ( m_aSupportedFeatures.end() != aIter && aIter->first.getLength() )
1071*cdf0e10cSrcweir 		{
1072*cdf0e10cSrcweir 			aReturn.Complete = aIter->first;
1073*cdf0e10cSrcweir 			m_xUrlTransformer->parseStrict( aReturn );
1074*cdf0e10cSrcweir 		}
1075*cdf0e10cSrcweir 	}
1076*cdf0e10cSrcweir 	return aReturn;
1077*cdf0e10cSrcweir }
1078*cdf0e10cSrcweir 
1079*cdf0e10cSrcweir //-------------------------------------------------------------------------
1080*cdf0e10cSrcweir bool OGenericUnoController::isUserDefinedFeature( const sal_uInt16 _nFeatureId ) const
1081*cdf0e10cSrcweir {
1082*cdf0e10cSrcweir     return ( _nFeatureId >= FIRST_USER_DEFINED_FEATURE ) && ( _nFeatureId < LAST_USER_DEFINED_FEATURE );
1083*cdf0e10cSrcweir }
1084*cdf0e10cSrcweir 
1085*cdf0e10cSrcweir //-------------------------------------------------------------------------
1086*cdf0e10cSrcweir bool OGenericUnoController::isUserDefinedFeature( const ::rtl::OUString& _rFeatureURL ) const
1087*cdf0e10cSrcweir {
1088*cdf0e10cSrcweir     SupportedFeatures::const_iterator pos = m_aSupportedFeatures.find( _rFeatureURL );
1089*cdf0e10cSrcweir     OSL_PRECOND( pos != m_aSupportedFeatures.end(),
1090*cdf0e10cSrcweir         "OGenericUnoController::isUserDefinedFeature: this is no supported feature at all!" );
1091*cdf0e10cSrcweir 
1092*cdf0e10cSrcweir     return ( pos != m_aSupportedFeatures.end() ) ? isUserDefinedFeature( pos->second.nFeatureId ) : false;
1093*cdf0e10cSrcweir }
1094*cdf0e10cSrcweir 
1095*cdf0e10cSrcweir //-------------------------------------------------------------------------
1096*cdf0e10cSrcweir sal_Bool SAL_CALL OGenericUnoController::supportsService(const ::rtl::OUString& ServiceName) throw(RuntimeException)
1097*cdf0e10cSrcweir {
1098*cdf0e10cSrcweir 	Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
1099*cdf0e10cSrcweir 
1100*cdf0e10cSrcweir 	const ::rtl::OUString* pArray = aSupported.getConstArray();
1101*cdf0e10cSrcweir 	const ::rtl::OUString* pArrayEnd = aSupported.getConstArray() + aSupported.getLength();
1102*cdf0e10cSrcweir 
1103*cdf0e10cSrcweir 	for ( ;( pArray != pArrayEnd ) && !pArray->equals( ServiceName ); ++pArray )
1104*cdf0e10cSrcweir 		;
1105*cdf0e10cSrcweir 	return pArray != pArrayEnd;
1106*cdf0e10cSrcweir }
1107*cdf0e10cSrcweir 
1108*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1109*cdf0e10cSrcweir void OGenericUnoController::startConnectionListening(const Reference< XConnection >& _rxConnection)
1110*cdf0e10cSrcweir {
1111*cdf0e10cSrcweir 	// we have to remove ourself before dispoing the connection
1112*cdf0e10cSrcweir 	Reference< XComponent >  xComponent(_rxConnection, UNO_QUERY);
1113*cdf0e10cSrcweir 	if (xComponent.is())
1114*cdf0e10cSrcweir 		xComponent->addEventListener(static_cast<XFrameActionListener*>(this));
1115*cdf0e10cSrcweir }
1116*cdf0e10cSrcweir 
1117*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1118*cdf0e10cSrcweir void OGenericUnoController::stopConnectionListening(const Reference< XConnection >& _rxConnection)
1119*cdf0e10cSrcweir {
1120*cdf0e10cSrcweir 	// we have to remove ourself before dispoing the connection
1121*cdf0e10cSrcweir 	Reference< XComponent >  xComponent(_rxConnection, UNO_QUERY);
1122*cdf0e10cSrcweir 	if (xComponent.is())
1123*cdf0e10cSrcweir 		xComponent->removeEventListener(static_cast<XFrameActionListener*>(this));
1124*cdf0e10cSrcweir }
1125*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1126*cdf0e10cSrcweir Reference< XConnection > OGenericUnoController::connect( const Reference< XDataSource>& _xDataSource,
1127*cdf0e10cSrcweir     ::dbtools::SQLExceptionInfo* _pErrorInfo )
1128*cdf0e10cSrcweir {
1129*cdf0e10cSrcweir 	WaitObject aWaitCursor( getView() );
1130*cdf0e10cSrcweir 
1131*cdf0e10cSrcweir 	ODatasourceConnector aConnector( getORB(), getView(), ::rtl::OUString() );
1132*cdf0e10cSrcweir 	Reference< XConnection > xConnection = aConnector.connect( _xDataSource, _pErrorInfo );
1133*cdf0e10cSrcweir 	startConnectionListening( xConnection );
1134*cdf0e10cSrcweir 
1135*cdf0e10cSrcweir 	return xConnection;
1136*cdf0e10cSrcweir }
1137*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1138*cdf0e10cSrcweir Reference< XConnection > OGenericUnoController::connect( const ::rtl::OUString& _rDataSourceName,
1139*cdf0e10cSrcweir     const ::rtl::OUString& _rContextInformation, ::dbtools::SQLExceptionInfo* _pErrorInfo )
1140*cdf0e10cSrcweir {
1141*cdf0e10cSrcweir 	WaitObject aWaitCursor( getView() );
1142*cdf0e10cSrcweir 
1143*cdf0e10cSrcweir 	ODatasourceConnector aConnector( getORB(), getView(), _rContextInformation );
1144*cdf0e10cSrcweir 	Reference<XConnection> xConnection = aConnector.connect( _rDataSourceName, _pErrorInfo );
1145*cdf0e10cSrcweir 	startConnectionListening( xConnection );
1146*cdf0e10cSrcweir 
1147*cdf0e10cSrcweir 	return xConnection;
1148*cdf0e10cSrcweir }
1149*cdf0e10cSrcweir 
1150*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1151*cdf0e10cSrcweir void OGenericUnoController::showError(const SQLExceptionInfo& _rInfo)
1152*cdf0e10cSrcweir {
1153*cdf0e10cSrcweir 	::dbaui::showError(_rInfo,getView(),getORB());
1154*cdf0e10cSrcweir }
1155*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1156*cdf0e10cSrcweir Reference< XLayoutManager > OGenericUnoController::getLayoutManager(const Reference< XFrame >& _xFrame) const
1157*cdf0e10cSrcweir {
1158*cdf0e10cSrcweir 	Reference< XPropertySet > xPropSet( _xFrame, UNO_QUERY );
1159*cdf0e10cSrcweir     Reference< XLayoutManager > xLayoutManager;
1160*cdf0e10cSrcweir 	if ( xPropSet.is() )
1161*cdf0e10cSrcweir     {
1162*cdf0e10cSrcweir         try
1163*cdf0e10cSrcweir         {
1164*cdf0e10cSrcweir 			xLayoutManager.set(xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ))),UNO_QUERY);
1165*cdf0e10cSrcweir         }
1166*cdf0e10cSrcweir         catch ( Exception& )
1167*cdf0e10cSrcweir         {
1168*cdf0e10cSrcweir         }
1169*cdf0e10cSrcweir     }
1170*cdf0e10cSrcweir 	return xLayoutManager;
1171*cdf0e10cSrcweir }
1172*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1173*cdf0e10cSrcweir void OGenericUnoController::loadMenu(const Reference< XFrame >& _xFrame)
1174*cdf0e10cSrcweir {
1175*cdf0e10cSrcweir     Reference< XLayoutManager > xLayoutManager = getLayoutManager(_xFrame);
1176*cdf0e10cSrcweir     if ( xLayoutManager.is() )
1177*cdf0e10cSrcweir 	{
1178*cdf0e10cSrcweir 		xLayoutManager->lock();
1179*cdf0e10cSrcweir         xLayoutManager->createElement( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" )));
1180*cdf0e10cSrcweir 		xLayoutManager->createElement( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/toolbar/toolbar" )));
1181*cdf0e10cSrcweir 		xLayoutManager->unlock();
1182*cdf0e10cSrcweir 		xLayoutManager->doLayout();
1183*cdf0e10cSrcweir 	}
1184*cdf0e10cSrcweir 
1185*cdf0e10cSrcweir     onLoadedMenu( xLayoutManager );
1186*cdf0e10cSrcweir }
1187*cdf0e10cSrcweir 
1188*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1189*cdf0e10cSrcweir void OGenericUnoController::onLoadedMenu(const Reference< XLayoutManager >& /*_xLayoutManager*/)
1190*cdf0e10cSrcweir {
1191*cdf0e10cSrcweir     // not interested in
1192*cdf0e10cSrcweir }
1193*cdf0e10cSrcweir 
1194*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1195*cdf0e10cSrcweir void OGenericUnoController::closeTask()
1196*cdf0e10cSrcweir {
1197*cdf0e10cSrcweir 	m_aAsyncCloseTask.Call();
1198*cdf0e10cSrcweir }
1199*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1200*cdf0e10cSrcweir IMPL_LINK(OGenericUnoController, OnAsyncCloseTask, void*, EMPTYARG)
1201*cdf0e10cSrcweir {
1202*cdf0e10cSrcweir 	if ( !OGenericUnoController_Base::rBHelper.bInDispose )
1203*cdf0e10cSrcweir 	{
1204*cdf0e10cSrcweir         try
1205*cdf0e10cSrcweir         {
1206*cdf0e10cSrcweir             Reference< util::XCloseable > xCloseable( m_aCurrentFrame.getFrame(), UNO_QUERY_THROW );
1207*cdf0e10cSrcweir             xCloseable->close( sal_False ); // false - holds the owner ship for this frame inside this object!
1208*cdf0e10cSrcweir         }
1209*cdf0e10cSrcweir         catch( const Exception& )
1210*cdf0e10cSrcweir         {
1211*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
1212*cdf0e10cSrcweir         }
1213*cdf0e10cSrcweir 	}
1214*cdf0e10cSrcweir 	return 0L;
1215*cdf0e10cSrcweir }
1216*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1217*cdf0e10cSrcweir Any SAL_CALL OGenericUnoController::getViewData(void) throw( RuntimeException )
1218*cdf0e10cSrcweir {
1219*cdf0e10cSrcweir 	return Any();
1220*cdf0e10cSrcweir }
1221*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1222*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::restoreViewData(const Any& /*Data*/) throw( RuntimeException )
1223*cdf0e10cSrcweir {
1224*cdf0e10cSrcweir }
1225*cdf0e10cSrcweir 
1226*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1227*cdf0e10cSrcweir Reference< XModel > SAL_CALL OGenericUnoController::getModel(void) throw( RuntimeException )
1228*cdf0e10cSrcweir {
1229*cdf0e10cSrcweir     return Reference< XModel >();
1230*cdf0e10cSrcweir }
1231*cdf0e10cSrcweir 
1232*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1233*cdf0e10cSrcweir Reference< XFrame > SAL_CALL OGenericUnoController::getFrame(void) throw( RuntimeException )
1234*cdf0e10cSrcweir {
1235*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
1236*cdf0e10cSrcweir     return m_aCurrentFrame.getFrame();
1237*cdf0e10cSrcweir }
1238*cdf0e10cSrcweir 
1239*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1240*cdf0e10cSrcweir sal_Bool SAL_CALL OGenericUnoController::attachModel(const Reference< XModel > & /*xModel*/) throw( RuntimeException )
1241*cdf0e10cSrcweir {
1242*cdf0e10cSrcweir     OSL_ENSURE( false, "OGenericUnoController::attachModel: not supported!" );
1243*cdf0e10cSrcweir     return sal_False;
1244*cdf0e10cSrcweir }
1245*cdf0e10cSrcweir 
1246*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1247*cdf0e10cSrcweir void OGenericUnoController::executeUnChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue >& aArgs)
1248*cdf0e10cSrcweir {
1249*cdf0e10cSrcweir 	Execute(_nCommandId, aArgs);
1250*cdf0e10cSrcweir }
1251*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1252*cdf0e10cSrcweir void OGenericUnoController::executeUnChecked(const util::URL& _rCommand, const Sequence< PropertyValue >& aArgs)
1253*cdf0e10cSrcweir {
1254*cdf0e10cSrcweir     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::executeUnChecked: shouldn't this be filled at construction time?" );
1255*cdf0e10cSrcweir     if ( m_aSupportedFeatures.empty() )
1256*cdf0e10cSrcweir         fillSupportedFeatures();
1257*cdf0e10cSrcweir 
1258*cdf0e10cSrcweir     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCommand.Complete );
1259*cdf0e10cSrcweir 	if (aIter != m_aSupportedFeatures.end())
1260*cdf0e10cSrcweir 		Execute( aIter->second.nFeatureId, aArgs );
1261*cdf0e10cSrcweir }
1262*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1263*cdf0e10cSrcweir void OGenericUnoController::executeChecked(const util::URL& _rCommand, const Sequence< PropertyValue >& aArgs)
1264*cdf0e10cSrcweir {
1265*cdf0e10cSrcweir     OSL_PRECOND( !m_aSupportedFeatures.empty(), "OGenericUnoController::executeChecked: shouldn't this be filled at construction time?" );
1266*cdf0e10cSrcweir     if ( m_aSupportedFeatures.empty() )
1267*cdf0e10cSrcweir         fillSupportedFeatures();
1268*cdf0e10cSrcweir 
1269*cdf0e10cSrcweir     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCommand.Complete );
1270*cdf0e10cSrcweir 	if ( aIter != m_aSupportedFeatures.end() )
1271*cdf0e10cSrcweir 	{
1272*cdf0e10cSrcweir 		sal_uInt16 nFeatureId = aIter->second.nFeatureId;
1273*cdf0e10cSrcweir 		if ( GetState( nFeatureId ).bEnabled )
1274*cdf0e10cSrcweir 			Execute( nFeatureId, aArgs );
1275*cdf0e10cSrcweir 	}
1276*cdf0e10cSrcweir }
1277*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1278*cdf0e10cSrcweir //------------------------------------------------------------------------------
1279*cdf0e10cSrcweir namespace
1280*cdf0e10cSrcweir {
1281*cdf0e10cSrcweir 	::rtl::OUString lcl_getModuleHelpModuleName( const Reference< XFrame >& _rxFrame )
1282*cdf0e10cSrcweir 	{
1283*cdf0e10cSrcweir 		const sal_Char* pReturn = NULL;
1284*cdf0e10cSrcweir 
1285*cdf0e10cSrcweir 		try
1286*cdf0e10cSrcweir 		{
1287*cdf0e10cSrcweir 			// get the model of the document in the given frame
1288*cdf0e10cSrcweir 			Reference< XController > xController;
1289*cdf0e10cSrcweir 			if ( _rxFrame.is() )
1290*cdf0e10cSrcweir 				xController = _rxFrame->getController();
1291*cdf0e10cSrcweir 			Reference< XModel > xModel;
1292*cdf0e10cSrcweir 			if ( xController.is() )
1293*cdf0e10cSrcweir 				xModel = xController->getModel();
1294*cdf0e10cSrcweir 			Reference< XServiceInfo > xSI( xModel, UNO_QUERY );
1295*cdf0e10cSrcweir 
1296*cdf0e10cSrcweir 			if ( !xSI.is() )
1297*cdf0e10cSrcweir 			{	// try to go up the frame hierarchy
1298*cdf0e10cSrcweir 
1299*cdf0e10cSrcweir 				Reference< XFrame > xParentFrame;
1300*cdf0e10cSrcweir 				if ( _rxFrame.is() )
1301*cdf0e10cSrcweir 					xParentFrame = xParentFrame.query( _rxFrame->getCreator() );
1302*cdf0e10cSrcweir 				// did we find a parent frame? Which is no top-level frame?
1303*cdf0e10cSrcweir 				if ( xParentFrame.is() && !_rxFrame->isTop() )
1304*cdf0e10cSrcweir 					// TODO: to prevent framework assertions, re-insert this "isTop" once 98303 is fixed
1305*cdf0e10cSrcweir 					return lcl_getModuleHelpModuleName( xParentFrame );
1306*cdf0e10cSrcweir 			}
1307*cdf0e10cSrcweir 			else
1308*cdf0e10cSrcweir 			{
1309*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1310*cdf0e10cSrcweir 				Sequence< ::rtl::OUString > sServiceNames = xSI->getSupportedServiceNames();
1311*cdf0e10cSrcweir 				const ::rtl::OUString* pLoop = sServiceNames.getConstArray();
1312*cdf0e10cSrcweir 				for ( sal_Int32 i=0; i<sServiceNames.getLength(); ++i, ++pLoop )
1313*cdf0e10cSrcweir 				{
1314*cdf0e10cSrcweir 					sal_Int32 nDummy = 0;
1315*cdf0e10cSrcweir                     (void)nDummy;
1316*cdf0e10cSrcweir 				}
1317*cdf0e10cSrcweir #endif
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir 				// check which service we know ....
1320*cdf0e10cSrcweir 				static const sal_Char* pTransTable[] = {
1321*cdf0e10cSrcweir 					"com.sun.star.sdb.OfficeDatabaseDocument","sdatabase",
1322*cdf0e10cSrcweir                     "com.sun.star.report.ReportDefinition","sdatabase",
1323*cdf0e10cSrcweir 					"com.sun.star.text.TextDocument",	"swriter",
1324*cdf0e10cSrcweir 					"com.sun.star.sheet.SpreadsheetDocument", "scalc",
1325*cdf0e10cSrcweir 					"com.sun.star.presentation.PresentationDocument", "simpress",
1326*cdf0e10cSrcweir 					"com.sun.star.drawing.DrawingDocument", "sdraw",
1327*cdf0e10cSrcweir 					"com.sun.star.formula.FormularProperties", "smath",
1328*cdf0e10cSrcweir 					"com.sun.star.chart.ChartDocument", "schart"
1329*cdf0e10cSrcweir 				};
1330*cdf0e10cSrcweir 				OSL_ENSURE( ( sizeof( pTransTable ) / sizeof( pTransTable[0] ) ) % 2 == 0,
1331*cdf0e10cSrcweir 					"lcl_getModuleHelpModuleName: odd size of translation table!" );
1332*cdf0e10cSrcweir 
1333*cdf0e10cSrcweir 				// loop through the table
1334*cdf0e10cSrcweir 				sal_Int32 nTableEntries = ( sizeof( pTransTable ) / sizeof( pTransTable[0] ) ) / 2;
1335*cdf0e10cSrcweir 				const sal_Char** pDocumentService = pTransTable;
1336*cdf0e10cSrcweir 				const sal_Char** pHelpModuleName = pTransTable + 1;
1337*cdf0e10cSrcweir 				for ( sal_Int32 j=0; j<nTableEntries; ++j )
1338*cdf0e10cSrcweir 				{
1339*cdf0e10cSrcweir 					if ( xSI->supportsService( ::rtl::OUString::createFromAscii( *pDocumentService ) ) )
1340*cdf0e10cSrcweir 					{	// found a table entry which matches the model's services
1341*cdf0e10cSrcweir 						pReturn = *pHelpModuleName;
1342*cdf0e10cSrcweir 						break;
1343*cdf0e10cSrcweir 					}
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir 					++pDocumentService; ++pDocumentService;
1346*cdf0e10cSrcweir 					++pHelpModuleName; ++pHelpModuleName;
1347*cdf0e10cSrcweir 				}
1348*cdf0e10cSrcweir 			}
1349*cdf0e10cSrcweir 
1350*cdf0e10cSrcweir 			if ( !pReturn )
1351*cdf0e10cSrcweir 			{
1352*cdf0e10cSrcweir 				// could not determine the document type we're living in
1353*cdf0e10cSrcweir 				// ->fallback
1354*cdf0e10cSrcweir 				SvtModuleOptions aModOpt;
1355*cdf0e10cSrcweir 				if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SWRITER ) )
1356*cdf0e10cSrcweir 					pReturn = "swriter";
1357*cdf0e10cSrcweir 				else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
1358*cdf0e10cSrcweir 					pReturn = "sdatabase";
1359*cdf0e10cSrcweir 				else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCALC ) )
1360*cdf0e10cSrcweir 					pReturn = "scalc";
1361*cdf0e10cSrcweir 				else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SIMPRESS ) )
1362*cdf0e10cSrcweir 					pReturn = "simpress";
1363*cdf0e10cSrcweir 				else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SDRAW ) )
1364*cdf0e10cSrcweir 					pReturn = "sdraw";
1365*cdf0e10cSrcweir 				else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SMATH ) )
1366*cdf0e10cSrcweir 					pReturn = "smath";
1367*cdf0e10cSrcweir 				else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SCHART ) )
1368*cdf0e10cSrcweir 					pReturn = "schart";
1369*cdf0e10cSrcweir 				else if ( aModOpt.IsModuleInstalled( SvtModuleOptions::E_SBASIC ) )
1370*cdf0e10cSrcweir 					pReturn = "sbasic";
1371*cdf0e10cSrcweir 				else
1372*cdf0e10cSrcweir 				{
1373*cdf0e10cSrcweir 					OSL_ENSURE( sal_False, "lcl_getModuleHelpModuleName: no installed module found" );
1374*cdf0e10cSrcweir 				}
1375*cdf0e10cSrcweir 			}
1376*cdf0e10cSrcweir 		}
1377*cdf0e10cSrcweir         catch( const Exception& )
1378*cdf0e10cSrcweir         {
1379*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
1380*cdf0e10cSrcweir         }
1381*cdf0e10cSrcweir 
1382*cdf0e10cSrcweir 		if ( !pReturn )
1383*cdf0e10cSrcweir 			pReturn = "swriter";
1384*cdf0e10cSrcweir 
1385*cdf0e10cSrcweir 		return ::rtl::OUString::createFromAscii( pReturn );
1386*cdf0e10cSrcweir 	}
1387*cdf0e10cSrcweir }
1388*cdf0e10cSrcweir 
1389*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1390*cdf0e10cSrcweir 
1391*cdf0e10cSrcweir void OGenericUnoController::openHelpAgent(rtl::OUString const& _suHelpStringURL )
1392*cdf0e10cSrcweir {
1393*cdf0e10cSrcweir     rtl::OUString suURL(_suHelpStringURL);
1394*cdf0e10cSrcweir     rtl::OUString sLanguage = rtl::OUString::createFromAscii("Language=");
1395*cdf0e10cSrcweir     if (suURL.indexOf(sLanguage) == -1)
1396*cdf0e10cSrcweir     {
1397*cdf0e10cSrcweir         AppendConfigToken(suURL, sal_False /* sal_False := add '&' */ );
1398*cdf0e10cSrcweir     }
1399*cdf0e10cSrcweir     URL aURL;
1400*cdf0e10cSrcweir     aURL.Complete = suURL;
1401*cdf0e10cSrcweir 
1402*cdf0e10cSrcweir     openHelpAgent( aURL );
1403*cdf0e10cSrcweir }
1404*cdf0e10cSrcweir 
1405*cdf0e10cSrcweir void OGenericUnoController::openHelpAgent(const rtl::OString& _sHelpId)
1406*cdf0e10cSrcweir {
1407*cdf0e10cSrcweir 	openHelpAgent( createHelpAgentURL( lcl_getModuleHelpModuleName( getFrame() ), _sHelpId ) );
1408*cdf0e10cSrcweir }
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir void OGenericUnoController::openHelpAgent( const URL& _rURL )
1411*cdf0e10cSrcweir {
1412*cdf0e10cSrcweir 	try
1413*cdf0e10cSrcweir 	{
1414*cdf0e10cSrcweir         URL aURL( _rURL );
1415*cdf0e10cSrcweir 
1416*cdf0e10cSrcweir         if ( m_xUrlTransformer.is() )
1417*cdf0e10cSrcweir             m_xUrlTransformer->parseStrict(aURL);
1418*cdf0e10cSrcweir 
1419*cdf0e10cSrcweir 		Reference< XDispatchProvider > xDispProv( m_aCurrentFrame.getFrame(), UNO_QUERY );
1420*cdf0e10cSrcweir 		Reference< XDispatch > xHelpDispatch;
1421*cdf0e10cSrcweir 		if ( xDispProv.is() )
1422*cdf0e10cSrcweir 			xHelpDispatch = xDispProv->queryDispatch(aURL, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_helpagent")), FrameSearchFlag::PARENT | FrameSearchFlag::SELF);
1423*cdf0e10cSrcweir 		OSL_ENSURE(xHelpDispatch.is(), "SbaTableQueryBrowser::openHelpAgent: could not get a dispatcher!");
1424*cdf0e10cSrcweir 		if (xHelpDispatch.is())
1425*cdf0e10cSrcweir 		{
1426*cdf0e10cSrcweir 			xHelpDispatch->dispatch(aURL, Sequence< PropertyValue >());
1427*cdf0e10cSrcweir 		}
1428*cdf0e10cSrcweir 	}
1429*cdf0e10cSrcweir     catch( const Exception& )
1430*cdf0e10cSrcweir     {
1431*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
1432*cdf0e10cSrcweir     }
1433*cdf0e10cSrcweir }
1434*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1435*cdf0e10cSrcweir Reference< awt::XWindow> OGenericUnoController::getTopMostContainerWindow() const
1436*cdf0e10cSrcweir {
1437*cdf0e10cSrcweir 	Reference< ::com::sun::star::awt::XWindow> xWindow;
1438*cdf0e10cSrcweir 
1439*cdf0e10cSrcweir     // get the top most window
1440*cdf0e10cSrcweir     Reference< XFrame > xFrame( m_aCurrentFrame.getFrame() );
1441*cdf0e10cSrcweir 	if ( xFrame.is() )
1442*cdf0e10cSrcweir 	{
1443*cdf0e10cSrcweir 		xWindow = xFrame->getContainerWindow();
1444*cdf0e10cSrcweir 
1445*cdf0e10cSrcweir         while ( xFrame.is() && !xFrame->isTop() )
1446*cdf0e10cSrcweir 		{
1447*cdf0e10cSrcweir 			xFrame.set( xFrame->getCreator(), UNO_QUERY );
1448*cdf0e10cSrcweir 		}
1449*cdf0e10cSrcweir 		if ( xFrame.is() )
1450*cdf0e10cSrcweir 			xWindow = xFrame->getContainerWindow();
1451*cdf0e10cSrcweir 	}
1452*cdf0e10cSrcweir 	return xWindow;
1453*cdf0e10cSrcweir }
1454*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1455*cdf0e10cSrcweir Reference< XTitle > OGenericUnoController::impl_getTitleHelper_throw()
1456*cdf0e10cSrcweir {
1457*cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1458*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
1459*cdf0e10cSrcweir 
1460*cdf0e10cSrcweir     if ( ! m_xTitleHelper.is ())
1461*cdf0e10cSrcweir     {
1462*cdf0e10cSrcweir         Reference< XUntitledNumbers > xUntitledProvider(getPrivateModel(), UNO_QUERY      );
1463*cdf0e10cSrcweir         Reference< XController >      xThis(static_cast< XController* >(this), UNO_QUERY_THROW);
1464*cdf0e10cSrcweir 
1465*cdf0e10cSrcweir         ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(m_xServiceFactory);
1466*cdf0e10cSrcweir         m_xTitleHelper.set( static_cast< ::cppu::OWeakObject* >(pHelper), UNO_QUERY_THROW);
1467*cdf0e10cSrcweir 
1468*cdf0e10cSrcweir         pHelper->setOwner                   (xThis            );
1469*cdf0e10cSrcweir         pHelper->connectWithUntitledNumbers (xUntitledProvider);
1470*cdf0e10cSrcweir     }
1471*cdf0e10cSrcweir 
1472*cdf0e10cSrcweir     return m_xTitleHelper;
1473*cdf0e10cSrcweir }
1474*cdf0e10cSrcweir 
1475*cdf0e10cSrcweir //=============================================================================
1476*cdf0e10cSrcweir // XTitle
1477*cdf0e10cSrcweir ::rtl::OUString SAL_CALL OGenericUnoController::getTitle()
1478*cdf0e10cSrcweir     throw (RuntimeException)
1479*cdf0e10cSrcweir {
1480*cdf0e10cSrcweir     ::osl::MutexGuard aGuard( getMutex() );
1481*cdf0e10cSrcweir     if ( m_bExternalTitle )
1482*cdf0e10cSrcweir         return impl_getTitleHelper_throw()->getTitle ();
1483*cdf0e10cSrcweir     return getPrivateTitle() + impl_getTitleHelper_throw()->getTitle ();
1484*cdf0e10cSrcweir }
1485*cdf0e10cSrcweir 
1486*cdf0e10cSrcweir //=============================================================================
1487*cdf0e10cSrcweir // XTitle
1488*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::setTitle(const ::rtl::OUString& sTitle)
1489*cdf0e10cSrcweir     throw (RuntimeException)
1490*cdf0e10cSrcweir {
1491*cdf0e10cSrcweir     vos::OGuard aSolarGuard( Application::GetSolarMutex() );
1492*cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getMutex() );
1493*cdf0e10cSrcweir     m_bExternalTitle = sal_True;
1494*cdf0e10cSrcweir     impl_getTitleHelper_throw()->setTitle (sTitle);
1495*cdf0e10cSrcweir }
1496*cdf0e10cSrcweir 
1497*cdf0e10cSrcweir //=============================================================================
1498*cdf0e10cSrcweir // XTitleChangeBroadcaster
1499*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::addTitleChangeListener(const Reference< XTitleChangeListener >& xListener)
1500*cdf0e10cSrcweir     throw (RuntimeException)
1501*cdf0e10cSrcweir {
1502*cdf0e10cSrcweir     Reference< XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(), UNO_QUERY);
1503*cdf0e10cSrcweir     if (xBroadcaster.is ())
1504*cdf0e10cSrcweir         xBroadcaster->addTitleChangeListener (xListener);
1505*cdf0e10cSrcweir }
1506*cdf0e10cSrcweir 
1507*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1508*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::removeTitleChangeListener(const Reference< XTitleChangeListener >& xListener)
1509*cdf0e10cSrcweir     throw (RuntimeException)
1510*cdf0e10cSrcweir {
1511*cdf0e10cSrcweir     Reference< XTitleChangeBroadcaster > xBroadcaster(impl_getTitleHelper_throw(), UNO_QUERY);
1512*cdf0e10cSrcweir     if (xBroadcaster.is ())
1513*cdf0e10cSrcweir         xBroadcaster->removeTitleChangeListener (xListener);
1514*cdf0e10cSrcweir }
1515*cdf0e10cSrcweir 
1516*cdf0e10cSrcweir // =============================================================================
1517*cdf0e10cSrcweir // XUserInputInterception
1518*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1519*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::addKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException)
1520*cdf0e10cSrcweir {
1521*cdf0e10cSrcweir     if ( _rxHandler.is() )
1522*cdf0e10cSrcweir         m_pData->m_aUserInputInterception.addKeyHandler( _rxHandler );
1523*cdf0e10cSrcweir }
1524*cdf0e10cSrcweir 
1525*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1526*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::removeKeyHandler( const Reference< XKeyHandler >& _rxHandler ) throw (RuntimeException)
1527*cdf0e10cSrcweir {
1528*cdf0e10cSrcweir     m_pData->m_aUserInputInterception.removeKeyHandler( _rxHandler );
1529*cdf0e10cSrcweir }
1530*cdf0e10cSrcweir 
1531*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1532*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::addMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException)
1533*cdf0e10cSrcweir {
1534*cdf0e10cSrcweir     if ( _rxHandler.is() )
1535*cdf0e10cSrcweir         m_pData->m_aUserInputInterception.addMouseClickHandler( _rxHandler );
1536*cdf0e10cSrcweir }
1537*cdf0e10cSrcweir 
1538*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1539*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::removeMouseClickHandler( const Reference< XMouseClickHandler >& _rxHandler ) throw (RuntimeException)
1540*cdf0e10cSrcweir {
1541*cdf0e10cSrcweir     m_pData->m_aUserInputInterception.removeMouseClickHandler( _rxHandler );
1542*cdf0e10cSrcweir }
1543*cdf0e10cSrcweir 
1544*cdf0e10cSrcweir // =============================================================================
1545*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1546*cdf0e10cSrcweir void OGenericUnoController::executeChecked(sal_uInt16 _nCommandId, const Sequence< PropertyValue >& aArgs)
1547*cdf0e10cSrcweir {
1548*cdf0e10cSrcweir 	if ( isCommandEnabled(_nCommandId) )
1549*cdf0e10cSrcweir 		Execute(_nCommandId, aArgs);
1550*cdf0e10cSrcweir }
1551*cdf0e10cSrcweir 
1552*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1553*cdf0e10cSrcweir sal_Bool OGenericUnoController::isCommandEnabled(sal_uInt16 _nCommandId) const
1554*cdf0e10cSrcweir {
1555*cdf0e10cSrcweir 	return GetState( _nCommandId ).bEnabled;
1556*cdf0e10cSrcweir }
1557*cdf0e10cSrcweir 
1558*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1559*cdf0e10cSrcweir sal_uInt16 OGenericUnoController::registerCommandURL( const ::rtl::OUString& _rCompleteCommandURL )
1560*cdf0e10cSrcweir {
1561*cdf0e10cSrcweir     if ( !_rCompleteCommandURL.getLength() )
1562*cdf0e10cSrcweir         return 0;
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCompleteCommandURL );
1565*cdf0e10cSrcweir 	if ( aIter != m_aSupportedFeatures.end() )
1566*cdf0e10cSrcweir 		return aIter->second.nFeatureId;
1567*cdf0e10cSrcweir 
1568*cdf0e10cSrcweir     // this is a previously unkwnon command
1569*cdf0e10cSrcweir     sal_uInt16 nFeatureId = FIRST_USER_DEFINED_FEATURE;
1570*cdf0e10cSrcweir     while ( isFeatureSupported( nFeatureId ) && ( nFeatureId < LAST_USER_DEFINED_FEATURE ) )
1571*cdf0e10cSrcweir         ++nFeatureId;
1572*cdf0e10cSrcweir     if ( nFeatureId == LAST_USER_DEFINED_FEATURE )
1573*cdf0e10cSrcweir     {
1574*cdf0e10cSrcweir         OSL_ENSURE( false, "OGenericUnoController::registerCommandURL: no more space for user defined features!" );
1575*cdf0e10cSrcweir         return 0L;
1576*cdf0e10cSrcweir     }
1577*cdf0e10cSrcweir 
1578*cdf0e10cSrcweir     ControllerFeature aFeature;
1579*cdf0e10cSrcweir     aFeature.Command = _rCompleteCommandURL;
1580*cdf0e10cSrcweir     aFeature.nFeatureId = nFeatureId;
1581*cdf0e10cSrcweir     aFeature.GroupId = CommandGroup::INTERNAL;
1582*cdf0e10cSrcweir     m_aSupportedFeatures[ aFeature.Command ] = aFeature;
1583*cdf0e10cSrcweir 
1584*cdf0e10cSrcweir     return nFeatureId;
1585*cdf0e10cSrcweir }
1586*cdf0e10cSrcweir 
1587*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1588*cdf0e10cSrcweir void OGenericUnoController::notifyHiContrastChanged()
1589*cdf0e10cSrcweir {
1590*cdf0e10cSrcweir }
1591*cdf0e10cSrcweir 
1592*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1593*cdf0e10cSrcweir sal_Bool OGenericUnoController::isDataSourceReadOnly() const
1594*cdf0e10cSrcweir {
1595*cdf0e10cSrcweir     return sal_False;
1596*cdf0e10cSrcweir }
1597*cdf0e10cSrcweir 
1598*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1599*cdf0e10cSrcweir Reference< XController > OGenericUnoController::getXController() throw( RuntimeException )
1600*cdf0e10cSrcweir {
1601*cdf0e10cSrcweir     return this;
1602*cdf0e10cSrcweir }
1603*cdf0e10cSrcweir 
1604*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1605*cdf0e10cSrcweir bool OGenericUnoController::interceptUserInput( const NotifyEvent& _rEvent )
1606*cdf0e10cSrcweir {
1607*cdf0e10cSrcweir     return m_pData->m_aUserInputInterception.handleNotifyEvent( _rEvent );
1608*cdf0e10cSrcweir }
1609*cdf0e10cSrcweir 
1610*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1611*cdf0e10cSrcweir sal_Bool OGenericUnoController::isCommandChecked(sal_uInt16 _nCommandId) const
1612*cdf0e10cSrcweir {
1613*cdf0e10cSrcweir     FeatureState aState = GetState( _nCommandId );
1614*cdf0e10cSrcweir 
1615*cdf0e10cSrcweir 	return aState.bChecked && (sal_Bool)*aState.bChecked;
1616*cdf0e10cSrcweir }
1617*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1618*cdf0e10cSrcweir sal_Bool OGenericUnoController::isCommandEnabled( const ::rtl::OUString& _rCompleteCommandURL ) const
1619*cdf0e10cSrcweir {
1620*cdf0e10cSrcweir     OSL_ENSURE( _rCompleteCommandURL.getLength(), "OGenericUnoController::isCommandEnabled: Empty command url!" );
1621*cdf0e10cSrcweir 
1622*cdf0e10cSrcweir 	sal_Bool bIsEnabled = sal_False;
1623*cdf0e10cSrcweir     SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.find( _rCompleteCommandURL );
1624*cdf0e10cSrcweir 	if ( aIter != m_aSupportedFeatures.end() )
1625*cdf0e10cSrcweir 		bIsEnabled = isCommandEnabled( aIter->second.nFeatureId );
1626*cdf0e10cSrcweir 
1627*cdf0e10cSrcweir 	return bIsEnabled;
1628*cdf0e10cSrcweir }
1629*cdf0e10cSrcweir 
1630*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1631*cdf0e10cSrcweir Sequence< ::sal_Int16 > SAL_CALL OGenericUnoController::getSupportedCommandGroups() throw (RuntimeException)
1632*cdf0e10cSrcweir {
1633*cdf0e10cSrcweir     CommandHashMap aCmdHashMap;
1634*cdf0e10cSrcweir 	for (   SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.begin();
1635*cdf0e10cSrcweir             aIter != m_aSupportedFeatures.end();
1636*cdf0e10cSrcweir             ++aIter
1637*cdf0e10cSrcweir         )
1638*cdf0e10cSrcweir         if ( aIter->second.GroupId != CommandGroup::INTERNAL )
1639*cdf0e10cSrcweir             aCmdHashMap.insert( CommandHashMap::value_type( aIter->second.GroupId, 0 ));
1640*cdf0e10cSrcweir 
1641*cdf0e10cSrcweir     Sequence< sal_Int16 > aCommandGroups( aCmdHashMap.size() );
1642*cdf0e10cSrcweir     ::std::transform( aCmdHashMap.begin(),
1643*cdf0e10cSrcweir         aCmdHashMap.end(),
1644*cdf0e10cSrcweir         aCommandGroups.getArray(),
1645*cdf0e10cSrcweir         ::std::select1st< CommandHashMap::value_type >()
1646*cdf0e10cSrcweir     );
1647*cdf0e10cSrcweir 
1648*cdf0e10cSrcweir     return aCommandGroups;
1649*cdf0e10cSrcweir }
1650*cdf0e10cSrcweir 
1651*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1652*cdf0e10cSrcweir Sequence< DispatchInformation > SAL_CALL OGenericUnoController::getConfigurableDispatchInformation( ::sal_Int16 CommandGroup ) throw (RuntimeException)
1653*cdf0e10cSrcweir {
1654*cdf0e10cSrcweir     DispatchInfoList    aInformationList;
1655*cdf0e10cSrcweir     DispatchInformation aDispatchInfo;
1656*cdf0e10cSrcweir     for (   SupportedFeatures::const_iterator aIter = m_aSupportedFeatures.begin();
1657*cdf0e10cSrcweir             aIter != m_aSupportedFeatures.end();
1658*cdf0e10cSrcweir             ++aIter
1659*cdf0e10cSrcweir         )
1660*cdf0e10cSrcweir     {
1661*cdf0e10cSrcweir         if ( sal_Int16( aIter->second.GroupId ) == CommandGroup )
1662*cdf0e10cSrcweir         {
1663*cdf0e10cSrcweir             aDispatchInfo = aIter->second;
1664*cdf0e10cSrcweir             aInformationList.push_back( aDispatchInfo );
1665*cdf0e10cSrcweir         }
1666*cdf0e10cSrcweir     }
1667*cdf0e10cSrcweir 
1668*cdf0e10cSrcweir     Sequence< DispatchInformation > aInformation( aInformationList.size() );
1669*cdf0e10cSrcweir     ::std::transform( aInformationList.begin(),
1670*cdf0e10cSrcweir         aInformationList.end(),
1671*cdf0e10cSrcweir         aInformation.getArray(),
1672*cdf0e10cSrcweir         ::std::identity< DispatchInformation >()
1673*cdf0e10cSrcweir     );
1674*cdf0e10cSrcweir 
1675*cdf0e10cSrcweir     return aInformation;
1676*cdf0e10cSrcweir }
1677*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1678*cdf0e10cSrcweir void OGenericUnoController::fillSupportedFeatures()
1679*cdf0e10cSrcweir {
1680*cdf0e10cSrcweir #ifdef DBG_UTIL
1681*cdf0e10cSrcweir     m_bDescribingSupportedFeatures = true;
1682*cdf0e10cSrcweir #endif
1683*cdf0e10cSrcweir 	describeSupportedFeatures();
1684*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1685*cdf0e10cSrcweir #ifdef DBG_UTIL
1686*cdf0e10cSrcweir     m_bDescribingSupportedFeatures = false;
1687*cdf0e10cSrcweir #endif
1688*cdf0e10cSrcweir }
1689*cdf0e10cSrcweir 
1690*cdf0e10cSrcweir 
1691*cdf0e10cSrcweir void SAL_CALL OGenericUnoController::dispose() throw(::com::sun::star::uno::RuntimeException)
1692*cdf0e10cSrcweir {
1693*cdf0e10cSrcweir 	::vos::OGuard aSolarGuard(Application::GetSolarMutex());
1694*cdf0e10cSrcweir 	OGenericUnoController_Base::dispose();
1695*cdf0e10cSrcweir }
1696*cdf0e10cSrcweir }   // namespace dbaui
1697*cdf0e10cSrcweir 
1698