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