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