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