xref: /trunk/main/sfx2/source/toolbox/tbxitem.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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_sfx2.hxx"
26 
27 #ifdef SOLARIS
28 // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
29 #include <ctime>
30 #endif
31 
32 #include <string>           // prevent conflict with STL includes
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/frame/XFrame.hpp>
35 #include <com/sun/star/awt/XWindow.hpp>
36 #include <com/sun/star/util/URL.hpp>
37 #include <com/sun/star/util/XURLTransformer.hpp>
38 #include <com/sun/star/frame/XController.hpp>
39 #include <com/sun/star/lang/XUnoTunnel.hpp>
40 #include <com/sun/star/document/MacroExecMode.hpp>
41 #include <com/sun/star/document/UpdateDocMode.hpp>
42 #include <com/sun/star/frame/XComponentLoader.hpp>
43 #include <com/sun/star/beans/PropertyValue.hpp>
44 #include <com/sun/star/beans/XPropertySet.hpp>
45 #include <com/sun/star/frame/XLayoutManager.hpp>
46 #include <com/sun/star/frame/status/ItemStatus.hpp>
47 #include <com/sun/star/frame/status/ItemState.hpp>
48 #include <com/sun/star/ui/XUIElementFactory.hpp>
49 #include <com/sun/star/frame/XModuleManager.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/ui/XUIFunctionListener.hpp>
52 #include <com/sun/star/frame/status/Visibility.hpp>
53 #include <com/sun/star/document/CorruptedFilterConfigurationException.hpp>
54 #include <svl/eitem.hxx>
55 #include <svl/stritem.hxx>
56 #include <svl/intitem.hxx>
57 #include <svl/imageitm.hxx>
58 #include <svl/visitem.hxx>
59 #include <svl/urlbmk.hxx>
60 #include <vcl/toolbox.hxx>
61 #include <unotools/moduleoptions.hxx>
62 
63 #include <svtools/imagemgr.hxx>
64 #include <comphelper/processfactory.hxx>
65 #include <framework/addonmenu.hxx>
66 #include <framework/addonsoptions.hxx>
67 #include <framework/menuconfiguration.hxx>
68 #include <framework/sfxhelperfunctions.hxx>
69 #include <vcl/taskpanelist.hxx>
70 #ifndef _TOOLKIT_UNOHLP_HXX
71 #include <toolkit/helper/vclunohelper.hxx>
72 #endif
73 #include <svtools/menuoptions.hxx>
74 #include <svtools/miscopt.hxx>
75 
76 #ifndef GCC
77 #endif
78 
79 #include <sfx2/tbxctrl.hxx>
80 #include <sfx2/mnumgr.hxx>
81 #include <sfx2/dispatch.hxx>
82 #include "fltfnc.hxx"
83 #include <sfx2/msg.hxx>
84 #include <sfx2/msgpool.hxx>
85 #include "statcach.hxx"
86 #include <sfx2/viewfrm.hxx>
87 #include "arrdecl.hxx"
88 #include "sfxtypes.hxx"
89 #include <sfx2/genlink.hxx>
90 #include "sfx2/sfxresid.hxx"
91 #include <sfx2/sfx.hrc>
92 #include <sfx2/module.hxx>
93 #include <sfx2/docfile.hxx>
94 #include <sfx2/docfac.hxx>
95 #include "referers.hxx"
96 #include <sfx2/frmhtmlw.hxx>
97 #include <sfx2/app.hxx>
98 #include <sfx2/unoctitm.hxx>
99 #include "helpid.hrc"
100 #include "workwin.hxx"
101 #include "sfx2/imgmgr.hxx"
102 #include "virtmenu.hxx"
103 #include <sfx2/viewfrm.hxx>
104 #include <sfx2/module.hxx>
105 #include "sfx2/imagemgr.hxx"
106 
107 #include <comphelper/uieventslogger.hxx>
108 #include <com/sun/star/frame/XModuleManager.hpp>
109 
110 //using namespace ::com::sun::star::awt;
111 using namespace ::com::sun::star::beans;
112 using namespace ::com::sun::star::frame;
113 using namespace ::com::sun::star::frame::status;
114 using namespace ::com::sun::star::lang;
115 using namespace ::com::sun::star::uno;
116 using namespace ::com::sun::star::util;
117 using namespace ::com::sun::star::container;
118 using namespace ::com::sun::star::frame;
119 using namespace ::com::sun::star::ui;
120 
121 //====================================================================
122 
123 SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True);
124 
GetTopMostParentSystemWindow(Window * pWindow)125 static Window* GetTopMostParentSystemWindow( Window* pWindow )
126 {
127     OSL_ASSERT( pWindow );
128     if ( pWindow )
129     {
130         // ->manually search topmost system window
131         // required because there might be another system window between this and the top window
132         pWindow = pWindow->GetParent();
133         SystemWindow* pTopMostSysWin = NULL;
134         while ( pWindow )
135         {
136             if ( pWindow->IsSystemWindow() )
137                 pTopMostSysWin = (SystemWindow*)pWindow;
138             pWindow = pWindow->GetParent();
139         }
140         pWindow = pTopMostSysWin;
141         OSL_ASSERT( pWindow );
142         return pWindow;
143     }
144 
145     return NULL;
146 }
147 
SfxToolBoxControllerFactory(const Reference<XFrame> & rFrame,ToolBox * pToolbox,unsigned short nID,const::rtl::OUString & aCommandURL)148 svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const Reference< XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const ::rtl::OUString& aCommandURL )
149 {
150     ::vos::OGuard aGuard( Application::GetSolarMutex() );
151 
152     URL aTargetURL;
153     aTargetURL.Complete = aCommandURL;
154     Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
155     xTrans->parseStrict( aTargetURL );
156     if ( aTargetURL.Arguments.getLength() )
157         return NULL;
158 
159     SfxObjectShell* pObjShell = NULL;
160     Reference < XController > xController;
161     Reference < XModel > xModel;
162     if ( rFrame.is() )
163     {
164         xController = rFrame->getController();
165         if ( xController.is() )
166             xModel = xController->getModel();
167     }
168 
169     if ( xModel.is() )
170     {
171         // Get tunnel from model to retrieve the SfxObjectShell pointer from it
172         ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xModel, UNO_QUERY );
173         if ( xObj.is() )
174         {
175             ::com::sun::star::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
176             sal_Int64 nHandle = xObj->getSomething( aSeq );
177             if ( nHandle )
178                 pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
179         }
180     }
181 
182     SfxModule*     pModule   = pObjShell ? pObjShell->GetModule() : NULL;
183     SfxSlotPool*   pSlotPool = 0;
184 
185     if ( pModule )
186         pSlotPool = pModule->GetSlotPool();
187     else
188         pSlotPool = &(SfxSlotPool::GetSlotPool( NULL ));
189 
190     const SfxSlot* pSlot = pSlotPool->GetUnoSlot( aTargetURL.Path );
191     if ( pSlot )
192     {
193         sal_uInt16 nSlotId = pSlot->GetSlotId();
194         if ( nSlotId > 0 )
195             return SfxToolBoxControl::CreateControl( nSlotId, nID, pToolbox, pModule );
196     }
197 
198     return NULL;
199 }
200 
201 struct SfxToolBoxControl_Impl
202 {
203     ToolBox*                pBox;
204     sal_Bool                    bShowString;
205     sal_uInt16                  nSelectModifier;
206     SfxTbxCtrlFactory*      pFact;
207     sal_uInt16                  nTbxId;
208     sal_uInt16                  nSlotId;
209     SfxPopupWindow*         mpFloatingWindow;
210     SfxPopupWindow*         mpPopupWindow;
211     Reference< XUIElement > mxUIElement;
212 
213     DECL_LINK( WindowEventListener, VclSimpleEvent* );
214 };
215 
IMPL_LINK(SfxToolBoxControl_Impl,WindowEventListener,VclSimpleEvent *,pEvent)216 IMPL_LINK( SfxToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent )
217 {
218     if ( pEvent &&
219          pEvent->ISA( VclWindowEvent ) &&
220          (( pEvent->GetId() == VCLEVENT_WINDOW_MOVE ) ||
221           ( pEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE )))
222     {
223         Window* pWindow( ((VclWindowEvent*)pEvent)->GetWindow() );
224         if (( pWindow == mpFloatingWindow ) &&
225             ( mpPopupWindow != 0 ))
226         {
227             delete mpPopupWindow;
228             mpPopupWindow = 0;
229         }
230     }
231 
232     return 1;
233 }
234 
235 //--------------------------------------------------------------------
236 
SfxToolBoxControl(sal_uInt16 nSlotID,sal_uInt16 nID,ToolBox & rBox,sal_Bool bShowStringItems)237 SfxToolBoxControl::SfxToolBoxControl(
238     sal_uInt16          nSlotID,
239     sal_uInt16          nID,
240     ToolBox&        rBox,
241     sal_Bool            bShowStringItems     )
242 :   svt::ToolboxController()
243 {
244     pImpl = new SfxToolBoxControl_Impl;
245 
246     pImpl->pBox = &rBox;
247     pImpl->bShowString = bShowStringItems;
248     pImpl->nSelectModifier = 0;
249     pImpl->pFact = 0;
250     pImpl->nTbxId = nID;
251     pImpl->nSlotId = nSlotID;
252     pImpl->mpFloatingWindow = 0;
253     pImpl->mpPopupWindow = 0;
254 }
255 
256 //--------------------------------------------------------------------
257 
~SfxToolBoxControl()258 SfxToolBoxControl::~SfxToolBoxControl()
259 {
260     if ( pImpl->mxUIElement.is() )
261     {
262         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
263         xComponent->dispose();
264     }
265     pImpl->mxUIElement = 0;
266     delete pImpl;
267 }
268 
269 //--------------------------------------------------------------------
270 
GetToolBox() const271 ToolBox& SfxToolBoxControl::GetToolBox() const
272 {
273     return *pImpl->pBox;
274 }
GetId() const275 unsigned short SfxToolBoxControl::GetId() const
276 {
277     return pImpl->nTbxId;
278 }
GetSlotId() const279 unsigned short SfxToolBoxControl::GetSlotId() const
280 {
281     return pImpl->nSlotId;
282 }
283 
284 //--------------------------------------------------------------------
285 
dispose()286 void SAL_CALL SfxToolBoxControl::dispose()
287 {
288     if ( m_bDisposed )
289         return;
290 
291     svt::ToolboxController::dispose();
292 
293     // Remove and destroy our item window at our toolbox
294     ::vos::OGuard aGuard( Application::GetSolarMutex() );
295     Window* pWindow = pImpl->pBox->GetItemWindow( pImpl->nTbxId );
296     pImpl->pBox->SetItemWindow( pImpl->nTbxId, 0 );
297     delete pWindow;
298 
299     // Dispose an open sub toolbar. It's possible that we have an open
300     // sub toolbar while we get disposed. Therefore we have to dispose
301     // it now! Not doing so would result in a crash. The sub toolbar
302     // gets destroyed asynchronously and would access a non-existing
303     // parent toolbar! See #126569#
304     if ( pImpl->mxUIElement.is() )
305     {
306         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
307         xComponent->dispose();
308     }
309     pImpl->mxUIElement = 0;
310 
311     // Delete my popup windows
312     delete pImpl->mpFloatingWindow;
313     delete pImpl->mpPopupWindow;
314 
315     pImpl->mpFloatingWindow = 0;
316     pImpl->mpPopupWindow = 0;
317 }
318 
319 //--------------------------------------------------------------------
RegisterToolBoxControl(SfxModule * pMod,SfxTbxCtrlFactory * pFact)320 void SfxToolBoxControl::RegisterToolBoxControl( SfxModule* pMod, SfxTbxCtrlFactory* pFact)
321 {
322     SFX_APP()->RegisterToolBoxControl_Impl( pMod, pFact );
323 }
324 
CreateControl(sal_uInt16 nSlotId,sal_uInt16 nTbxId,ToolBox * pBox,SfxModule * pMod)325 SfxToolBoxControl* SfxToolBoxControl::CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule* pMod  )
326 {
327     ::vos::OGuard aGuard( Application::GetSolarMutex() );
328 
329     SfxToolBoxControl *pCtrl;
330     SfxApplication *pApp = SFX_APP();
331 
332     SfxSlotPool *pSlotPool;
333     if ( pMod )
334         pSlotPool = pMod->GetSlotPool();
335     else
336         pSlotPool = &SfxSlotPool::GetSlotPool();
337     TypeId aSlotType = pSlotPool->GetSlotType( nSlotId );
338     if ( aSlotType )
339     {
340         if ( pMod )
341         {
342             SfxTbxCtrlFactArr_Impl *pFactories = pMod->GetTbxCtrlFactories_Impl();
343             if ( pFactories )
344             {
345                 SfxTbxCtrlFactArr_Impl &rFactories = *pFactories;
346                 sal_uInt16 nFactory;
347                 const sal_uInt16 nCount = rFactories.Count();
348 
349                 // search for a factory with the given slot id
350                 for( nFactory = 0; nFactory < nCount; ++nFactory )
351                     if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
352                         break;
353 
354                 if( nFactory == nCount )
355                 {
356                     // if no factory exists for the given slot id, see if we
357                     // have a generic factory with the correct slot type and slot id == 0
358                     for ( nFactory = 0; nFactory < nCount; ++nFactory )
359                         if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
360                             break;
361                 }
362 
363                 if( nFactory < nCount )
364                 {
365                     pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
366                     pCtrl->pImpl->pFact = rFactories[nFactory];
367                     return pCtrl;
368                 }
369             }
370         }
371 
372         SfxTbxCtrlFactArr_Impl &rFactories = pApp->GetTbxCtrlFactories_Impl();
373         sal_uInt16 nFactory;
374         const sal_uInt16 nCount = rFactories.Count();
375 
376         for( nFactory = 0; nFactory < nCount; ++nFactory )
377             if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
378                 break;
379 
380         if( nFactory == nCount )
381         {
382             // if no factory exists for the given slot id, see if we
383             // have a generic factory with the correct slot type and slot id == 0
384             for( nFactory = 0; nFactory < nCount; ++nFactory )
385                 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
386                     break;
387         }
388 
389         if( nFactory < nCount )
390         {
391             pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
392             pCtrl->pImpl->pFact = rFactories[nFactory];
393             return pCtrl;
394         }
395     }
396 
397     return NULL;
398 }
399 
GetItemState(const SfxPoolItem * pState)400 SfxItemState SfxToolBoxControl::GetItemState(
401     const SfxPoolItem* pState )
402 /*  [Beschreibung]
403 
404     Statische Methode zum Ermitteln des Status des SfxPoolItem-Pointers,
405     in der Methode <SfxControllerItem::StateChanged(const SfxPoolItem*)>
406     zu verwenden.
407 
408     [R"uckgabewert]
409 
410     SfxItemState        SFX_ITEM_UNKNOWN
411                         Enabled, aber keine weitere Statusinformation
412                         verf"ugbar. Typisch f"ur <Slot>s, die allenfalls
413                         zeitweise disabled sind, aber ihre Darstellung sonst
414                         nicht "andern.
415 
416                         SFX_ITEM_DISABLED
417                         Disabled und keine weiter Statusinformation
418                         verf"ugbar. Alle anderen ggf. angezeigten Werte sollten
419                         auf den Default zur"uckgesetzt werden.
420 
421                         SFX_ITEM_DONTCARE
422                         Enabled aber es waren nur uneindeutige Werte
423                         verf"ugbar (also keine, die abgefragt werden k"onnen).
424 
425                         SFX_ITEM_AVAILABLE
426                         Enabled und mit verf"ugbarem Wert, der von 'pState'
427                         erfragbar ist. Der Typ ist dabei im gesamten
428                         Programm eindeutig und durch den Slot festgelegt.
429 */
430 
431 {
432     return !pState
433                 ? SFX_ITEM_DISABLED
434                 : IsInvalidItem(pState)
435                     ? SFX_ITEM_DONTCARE
436                     : pState->ISA(SfxVoidItem) && !pState->Which()
437                         ? SFX_ITEM_UNKNOWN
438                         : SFX_ITEM_AVAILABLE;
439 }
440 
Dispatch(const Reference<XDispatchProvider> & rProvider,const rtl::OUString & rCommand,Sequence<::PropertyValue> & aArgs)441 void SfxToolBoxControl::Dispatch(
442     const Reference< XDispatchProvider >& rProvider,
443     const rtl::OUString& rCommand,
444     Sequence< ::PropertyValue >& aArgs )
445 {
446     if ( rProvider.is() )
447     {
448         ::com::sun::star::util::URL aTargetURL;
449         aTargetURL.Complete = rCommand;
450         Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
451                                             rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
452                                           UNO_QUERY );
453         xTrans->parseStrict( aTargetURL );
454 
455         Reference < XDispatch > xDispatch = rProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
456         if ( xDispatch.is() )
457             xDispatch->dispatch( aTargetURL, aArgs );
458     }
459 }
460 
Dispatch(const::rtl::OUString & aCommand,::com::sun::star::uno::Sequence<::com::sun::star::beans::PropertyValue> & aArgs)461 void SfxToolBoxControl::Dispatch( const ::rtl::OUString& aCommand, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
462 {
463     Reference < XController > xController;
464 
465     ::vos::OGuard aGuard( Application::GetSolarMutex() );
466     if ( getFrameInterface().is() )
467         xController = getFrameInterface()->getController();
468 
469     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
470     if ( xProvider.is() )
471     {
472         ::com::sun::star::util::URL aTargetURL;
473         aTargetURL.Complete = aCommand;
474         getURLTransformer()->parseStrict( aTargetURL );
475 
476         Reference < XDispatch > xDispatch = xProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
477         if ( xDispatch.is() )
478         {
479             if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
480             {
481                 ::rtl::OUString sAppName;
482                 try
483                 {
484                     static ::rtl::OUString our_aModuleManagerName = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
485                     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager =
486                         ::comphelper::getProcessServiceFactory();
487                     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
488                         xServiceManager->createInstance(our_aModuleManagerName)
489                         , ::com::sun::star::uno::UNO_QUERY_THROW);
490                     ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
491                         getFrameInterface(), UNO_QUERY_THROW);
492                     sAppName = xModuleManager->identify(xFrame);
493                 } catch(::com::sun::star::uno::Exception&) {}
494                 Sequence<PropertyValue> source;
495                 ::comphelper::UiEventsLogger::appendDispatchOrigin(source, sAppName, ::rtl::OUString::createFromAscii("SfxToolBoxControl"));
496                 ::comphelper::UiEventsLogger::logDispatch(aTargetURL, source);
497             }
498             xDispatch->dispatch( aTargetURL, aArgs );
499         }
500     }
501 }
502 
503 // XInterface
queryInterface(const Type & rType)504 Any SAL_CALL SfxToolBoxControl::queryInterface( const Type & rType )
505 {
506     ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
507                                         SAL_STATIC_CAST( ::com::sun::star::awt::XDockableWindowListener*, this ),
508                                         SAL_STATIC_CAST( ::com::sun::star::frame::XSubToolbarController*, this ));
509     return (aRet.hasValue() ? aRet : svt::ToolboxController::queryInterface( rType ));
510 }
511 
acquire()512 void SAL_CALL SfxToolBoxControl::acquire() throw()
513 {
514     OWeakObject::acquire();
515 }
516 
release()517 void SAL_CALL SfxToolBoxControl::release() throw()
518 {
519     OWeakObject::release();
520 }
521 
disposing(const::com::sun::star::lang::EventObject & aEvent)522 void SAL_CALL SfxToolBoxControl::disposing( const ::com::sun::star::lang::EventObject& aEvent )
523 {
524     svt::ToolboxController::disposing( aEvent );
525 }
526 
527 // XStatusListener
statusChanged(const FeatureStateEvent & rEvent)528 void SAL_CALL SfxToolBoxControl::statusChanged( const FeatureStateEvent& rEvent )
529 {
530     SfxViewFrame* pViewFrame = NULL;
531     Reference < XController > xController;
532 
533     ::vos::OGuard aGuard( Application::GetSolarMutex() );
534     if ( getFrameInterface().is() )
535         xController = getFrameInterface()->getController();
536 
537     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
538     if ( xProvider.is() )
539     {
540         Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
541         if ( xDisp.is() )
542         {
543             Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
544             SfxOfficeDispatch* pDisp = NULL;
545             if ( xTunnel.is() )
546             {
547                 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
548                 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
549             }
550 
551             if ( pDisp )
552                 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
553         }
554     }
555 
556     sal_uInt16 nSlotId = 0;
557     SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
558     const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
559     if ( pSlot )
560         nSlotId = pSlot->GetSlotId();
561     else if ( m_aCommandURL == rEvent.FeatureURL.Path )
562         nSlotId = GetSlotId();
563 
564     if ( nSlotId > 0 )
565     {
566         if ( rEvent.Requery )
567             svt::ToolboxController::statusChanged( rEvent );
568         else
569         {
570             SfxItemState eState = SFX_ITEM_DISABLED;
571             SfxPoolItem* pItem = NULL;
572             if ( rEvent.IsEnabled )
573             {
574                 eState = SFX_ITEM_AVAILABLE;
575                 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
576 
577                 if ( pType == ::getVoidCppuType() )
578                 {
579                     pItem = new SfxVoidItem( nSlotId );
580                     eState = SFX_ITEM_UNKNOWN;
581                 }
582                 else if ( pType == ::getBooleanCppuType() )
583                 {
584                     sal_Bool bTemp = false;
585                     rEvent.State >>= bTemp ;
586                     pItem = new SfxBoolItem( nSlotId, bTemp );
587                 }
588                 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
589                 {
590                     sal_uInt16 nTemp = 0;
591                     rEvent.State >>= nTemp ;
592                     pItem = new SfxUInt16Item( nSlotId, nTemp );
593                 }
594                 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
595                 {
596                     sal_uInt32 nTemp = 0;
597                     rEvent.State >>= nTemp ;
598                     pItem = new SfxUInt32Item( nSlotId, nTemp );
599                 }
600                 else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
601                 {
602                     ::rtl::OUString sTemp ;
603                     rEvent.State >>= sTemp ;
604                     pItem = new SfxStringItem( nSlotId, sTemp );
605                 }
606                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
607                 {
608                     ItemStatus aItemStatus;
609                     rEvent.State >>= aItemStatus;
610                     eState = aItemStatus.State;
611                     pItem = new SfxVoidItem( nSlotId );
612                 }
613                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
614                 {
615                     Visibility aVisibilityStatus;
616                     rEvent.State >>= aVisibilityStatus;
617                     pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
618                 }
619                 else
620                 {
621                     if ( pSlot )
622                         pItem = pSlot->GetType()->CreateItem();
623                     if ( pItem )
624                     {
625                         pItem->SetWhich( nSlotId );
626                         pItem->PutValue( rEvent.State );
627                     }
628                     else
629                         pItem = new SfxVoidItem( nSlotId );
630                 }
631             }
632 
633             StateChanged( nSlotId, eState, pItem );
634             delete pItem;
635         }
636     }
637 }
638 
639 // XSubToolbarController
opensSubToolbar()640 ::sal_Bool SAL_CALL SfxToolBoxControl::opensSubToolbar()
641 {
642     return sal_False;
643 }
644 
getSubToolbarName()645 ::rtl::OUString SAL_CALL SfxToolBoxControl::getSubToolbarName()
646 {
647     return rtl::OUString();
648 }
649 
functionSelected(const::rtl::OUString &)650 void SAL_CALL SfxToolBoxControl::functionSelected( const ::rtl::OUString& /*aCommand*/ )
651 {
652     // must be implemented by sub-class
653 }
654 
updateImage()655 void SAL_CALL SfxToolBoxControl::updateImage()
656 {
657     // must be implemented by sub-class
658 }
659 
660 // XToolbarController
execute(sal_Int16 KeyModifier)661 void SAL_CALL SfxToolBoxControl::execute( sal_Int16 KeyModifier )
662 {
663     ::vos::OGuard aGuard( Application::GetSolarMutex() );
664     Select( (sal_uInt16)KeyModifier );
665 }
click()666 void SAL_CALL SfxToolBoxControl::click()
667 {
668     ::vos::OGuard aGuard( Application::GetSolarMutex() );
669     Click();
670 }
671 
doubleClick()672 void SAL_CALL SfxToolBoxControl::doubleClick()
673 {
674     ::vos::OGuard aGuard( Application::GetSolarMutex() );
675     DoubleClick();
676 }
677 
createPopupWindow()678 Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createPopupWindow()
679 {
680     ::vos::OGuard aGuard( Application::GetSolarMutex() );
681     Window* pWindow = CreatePopupWindow();
682     if ( pWindow )
683         return VCLUnoHelper::GetInterface( pWindow );
684     else
685         return Reference< ::com::sun::star::awt::XWindow >();
686 }
687 
createItemWindow(const Reference<::com::sun::star::awt::XWindow> & rParent)688 Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createItemWindow( const Reference< ::com::sun::star::awt::XWindow >& rParent )
689 {
690     ::vos::OGuard aGuard( Application::GetSolarMutex() );
691     return VCLUnoHelper::GetInterface( CreateItemWindow( VCLUnoHelper::GetWindow( rParent )));
692 }
693 
694 // XDockableWindowListener
startDocking(const::com::sun::star::awt::DockingEvent &)695 void SAL_CALL SfxToolBoxControl::startDocking( const ::com::sun::star::awt::DockingEvent& )
696 {
697 }
docking(const::com::sun::star::awt::DockingEvent &)698 ::com::sun::star::awt::DockingData SAL_CALL SfxToolBoxControl::docking( const ::com::sun::star::awt::DockingEvent& )
699 {
700     return ::com::sun::star::awt::DockingData();
701 }
702 
endDocking(const::com::sun::star::awt::EndDockingEvent &)703 void SAL_CALL SfxToolBoxControl::endDocking( const ::com::sun::star::awt::EndDockingEvent& )
704 {
705 }
706 
prepareToggleFloatingMode(const::com::sun::star::lang::EventObject &)707 sal_Bool SAL_CALL SfxToolBoxControl::prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& )
708 {
709     return sal_False;
710 }
711 
toggleFloatingMode(const::com::sun::star::lang::EventObject &)712 void SAL_CALL SfxToolBoxControl::toggleFloatingMode( const ::com::sun::star::lang::EventObject& )
713 {
714 }
715 
closed(const::com::sun::star::lang::EventObject &)716 void SAL_CALL SfxToolBoxControl::closed( const ::com::sun::star::lang::EventObject& )
717 {
718 }
719 
endPopupMode(const::com::sun::star::awt::EndPopupModeEvent & aEvent)720 void SAL_CALL SfxToolBoxControl::endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& aEvent )
721 {
722     ::vos::OGuard aGuard( Application::GetSolarMutex() );
723 
724     ::rtl::OUString aSubToolBarResName;
725     if ( pImpl->mxUIElement.is() )
726     {
727         Reference< XPropertySet > xPropSet( pImpl->mxUIElement, UNO_QUERY );
728         if ( xPropSet.is() )
729         {
730             try
731             {
732                 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ))) >>= aSubToolBarResName;
733             }
734             catch ( com::sun::star::beans::UnknownPropertyException& )
735             {
736             }
737             catch ( com::sun::star::lang::WrappedTargetException& )
738             {
739             }
740         }
741 
742         Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
743         xComponent->dispose();
744     }
745     pImpl->mxUIElement = 0;
746 
747     // if the toolbar was teared-off recreate it and place it at the given position
748     if( aEvent.bTearoff )
749     {
750         Reference< XUIElement >     xUIElement;
751         Reference< XLayoutManager > xLayoutManager = getLayoutManager();
752 
753         if ( !xLayoutManager.is() )
754             return;
755 
756         xLayoutManager->createElement( aSubToolBarResName );
757         xUIElement = xLayoutManager->getElement( aSubToolBarResName );
758         if ( xUIElement.is() )
759         {
760             Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
761 
762             Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
763             Reference< ::com::sun::star::beans::XPropertySet > xProp( xUIElement, UNO_QUERY );
764             if ( xSubToolBar.is() && xProp.is() )
765             {
766                 rtl::OUString aPersistentString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
767                 try
768                 {
769                     Window*  pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
770                     ToolBox* pToolBar( 0 );
771                     if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
772                     {
773                         pToolBar = (ToolBox *)pTbxWindow;
774 
775                         Any a;
776                         a = xProp->getPropertyValue( aPersistentString );
777                         xProp->setPropertyValue( aPersistentString, makeAny( sal_False ));
778 
779                         xLayoutManager->hideElement( aSubToolBarResName );
780                         xLayoutManager->floatWindow( aSubToolBarResName );
781 
782                         xLayoutManager->setElementPos( aSubToolBarResName, aEvent.FloatingPosition );
783                         xLayoutManager->showElement( aSubToolBarResName );
784 
785                         xProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" )), a );
786                     }
787                 }
788                 catch ( ::com::sun::star::uno::RuntimeException& )
789                 {
790                     throw;
791                 }
792                 catch ( ::com::sun::star::uno::Exception& )
793                 {
794                 }
795             }
796         }
797     }
798 }
799 
getPersistentFloatingSize(const Reference<XFrame> &,const::rtl::OUString &)800 ::Size  SfxToolBoxControl::getPersistentFloatingSize( const Reference< XFrame >& /*xFrame*/, const ::rtl::OUString& /*rSubToolBarResName*/ )
801 {
802     ::Size  aToolboxSize;
803     return aToolboxSize;
804 }
805 
createAndPositionSubToolBar(const::rtl::OUString & rSubToolBarResName)806 void SfxToolBoxControl::createAndPositionSubToolBar( const ::rtl::OUString& rSubToolBarResName )
807 {
808     ::vos::OGuard aGuard( Application::GetSolarMutex() );
809 
810     if ( pImpl->pBox )
811     {
812         static WeakReference< XUIElementFactory > xWeakUIElementFactory;
813 
814         sal_uInt16 nItemId = pImpl->pBox->GetDownItemId();
815 
816         if ( !nItemId )
817             return;
818 
819         // create element with factory
820         Reference< XMultiServiceFactory >   xServiceManager = getServiceManager();
821         Reference< XFrame >                 xFrame          = getFrameInterface();
822         Reference< XUIElement >             xUIElement;
823         Reference< XUIElementFactory >      xUIEementFactory;
824 
825         xUIEementFactory = xWeakUIElementFactory;
826         if ( !xUIEementFactory.is() )
827         {
828             xUIEementFactory = Reference< XUIElementFactory >(
829                 xServiceManager->createInstance(
830                     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
831                         "com.sun.star.ui.UIElementFactoryManager" ))),
832                 UNO_QUERY );
833             xWeakUIElementFactory = xUIEementFactory;
834         }
835 
836         Sequence< PropertyValue > aPropSeq( 3 );
837         aPropSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
838         aPropSeq[0].Value <<= xFrame;
839         aPropSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
840         aPropSeq[1].Value <<= sal_False;
841         aPropSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PopupMode" ));
842         aPropSeq[2].Value <<= sal_True;
843 
844         try
845         {
846             xUIElement = xUIEementFactory->createUIElement( rSubToolBarResName, aPropSeq );
847         }
848         catch ( ::com::sun::star::container::NoSuchElementException& )
849         {
850         }
851         catch ( IllegalArgumentException& )
852         {
853         }
854 
855         if ( xUIElement.is() )
856         {
857             Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
858 
859             Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
860             if ( xSubToolBar.is() )
861             {
862                 Reference< ::com::sun::star::awt::XDockableWindow > xDockWindow( xSubToolBar, UNO_QUERY );
863                 xDockWindow->addDockableWindowListener( Reference< ::com::sun::star::awt::XDockableWindowListener >(
864                     static_cast< OWeakObject * >( this ), UNO_QUERY ));
865                 xDockWindow->enableDocking( sal_True );
866 
867                 // keep reference to UIElement to avoid its destruction
868                 if ( pImpl->mxUIElement.is() )
869                 {
870                     Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
871                     xComponent->dispose();
872                 }
873                 pImpl->mxUIElement = xUIElement;
874 
875                 Window*  pParentTbxWindow( pImpl->pBox );
876                 Window*  pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
877                 ToolBox* pToolBar( 0 );
878                 if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
879                     pToolBar = (ToolBox *)pTbxWindow;
880 
881                 if ( pToolBar )
882                 {
883                     pToolBar->SetParent( pParentTbxWindow );
884                     ::Size aSize = getPersistentFloatingSize( xFrame, rSubToolBarResName );
885                     if ( aSize.Width() == 0 || aSize.Height() == 0 )
886                     {
887                         // calc and set size for popup mode
888                         aSize = pToolBar->CalcPopupWindowSizePixel();
889                     }
890                     pToolBar->SetSizePixel( aSize );
891 
892                     // open subtoolbox in popup mode
893                     Window::GetDockingManager()->StartPopupMode( pImpl->pBox, pToolBar );
894                 }
895             }
896         }
897     }
898 }
899 
900 //--------------------------------------------------------------------
901 
SetPopupWindow(SfxPopupWindow * pWindow)902 void SfxToolBoxControl::SetPopupWindow( SfxPopupWindow* pWindow )
903 {
904     pImpl->mpPopupWindow = pWindow;
905     pImpl->mpPopupWindow->SetPopupModeEndHdl( LINK( this, SfxToolBoxControl, PopupModeEndHdl ));
906     pImpl->mpPopupWindow->SetDeleteLink_Impl( LINK( this, SfxToolBoxControl, ClosePopupWindow ));
907 }
908 
909 //--------------------------------------------------------------------
910 
IMPL_LINK(SfxToolBoxControl,PopupModeEndHdl,void *,EMPTYARG)911 IMPL_LINK( SfxToolBoxControl, PopupModeEndHdl, void *, EMPTYARG )
912 {
913     if ( pImpl->mpPopupWindow->IsVisible() )
914     {
915         // Replace floating window with popup window and destroy
916         // floating window instance.
917         delete pImpl->mpFloatingWindow;
918         pImpl->mpFloatingWindow = pImpl->mpPopupWindow;
919         pImpl->mpPopupWindow    = 0;
920         // We also need to know when the user tries to use the
921         // floating window.
922         pImpl->mpFloatingWindow->AddEventListener( LINK( pImpl, SfxToolBoxControl_Impl, WindowEventListener ));
923     }
924     else
925     {
926         // Popup window has been closed by the user. No replacement, instance
927         // will destroy itself.
928         pImpl->mpPopupWindow = 0;
929     }
930 
931     return 1;
932 }
933 
934 //--------------------------------------------------------------------
IMPL_LINK(SfxToolBoxControl,ClosePopupWindow,SfxPopupWindow *,pWindow)935 IMPL_LINK( SfxToolBoxControl, ClosePopupWindow, SfxPopupWindow *, pWindow )
936 {
937     if ( pWindow == pImpl->mpFloatingWindow )
938         pImpl->mpFloatingWindow = 0;
939     else
940         pImpl->mpPopupWindow = 0;
941 
942     return 1;
943 }
944 
945 //--------------------------------------------------------------------
946 
StateChanged(sal_uInt16 nId,SfxItemState eState,const SfxPoolItem * pState)947 void SfxToolBoxControl::StateChanged
948 (
949     sal_uInt16              nId,
950     SfxItemState        eState,
951     const SfxPoolItem*  pState
952 )
953 {
954     DBG_MEMTEST();
955     DBG_ASSERT( pImpl->pBox != 0, "setting state to dangling ToolBox" );
956 
957     if ( GetId() >= SID_OBJECTMENU0 && GetId() <= SID_OBJECTMENU_LAST )
958         return;
959 
960     // enabled/disabled-Flag pauschal korrigieren
961     pImpl->pBox->EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
962 
963     sal_uInt16 nItemBits = pImpl->pBox->GetItemBits( GetId() );
964     nItemBits &= ~TIB_CHECKABLE;
965     TriState eTri = STATE_NOCHECK;
966     switch ( eState )
967     {
968         case SFX_ITEM_AVAILABLE:
969         {
970             if ( pState->ISA(SfxBoolItem) )
971             {
972                 // BoolItem fuer checken
973                 if ( ((const SfxBoolItem*)pState)->GetValue() )
974                     eTri = STATE_CHECK;
975                 nItemBits |= TIB_CHECKABLE;
976             }
977             else if ( pState->ISA(SfxEnumItemInterface) &&
978                 ((SfxEnumItemInterface *)pState)->HasBoolValue())
979             {
980                 // EnumItem wie Bool behandeln
981                 if ( ((const SfxEnumItemInterface *)pState)->GetBoolValue() )
982                     eTri = STATE_CHECK;
983                 nItemBits |= TIB_CHECKABLE;
984             }
985             else if ( pImpl->bShowString && pState->ISA(SfxStringItem) )
986                 pImpl->pBox->SetItemText(nId, ((const SfxStringItem*)pState)->GetValue() );
987             break;
988         }
989 
990         case SFX_ITEM_DONTCARE:
991         {
992             eTri = STATE_DONTKNOW;
993             nItemBits |= TIB_CHECKABLE;
994         }
995     }
996 
997     pImpl->pBox->SetItemState( GetId(), eTri );
998     pImpl->pBox->SetItemBits( GetId(), nItemBits );
999 }
1000 
1001 //--------------------------------------------------------------------
1002 
Select(sal_uInt16 nModifier)1003 void SfxToolBoxControl::Select( sal_uInt16 nModifier )
1004 {
1005     pImpl->nSelectModifier = nModifier;
1006     Select( sal_Bool((nModifier & KEY_MOD1)!=0) );
1007 }
1008 
1009 //--------------------------------------------------------------------
1010 
Select(sal_Bool)1011 void SfxToolBoxControl::Select( sal_Bool /*bMod1*/ )
1012 {
1013     if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# #i102805#
1014     {
1015         ::rtl::OUString sAppName;
1016         try
1017         {
1018             static ::rtl::OUString our_aModuleManagerName = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
1019             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager =
1020                 ::comphelper::getProcessServiceFactory();
1021             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
1022                 xServiceManager->createInstance(our_aModuleManagerName)
1023                 , ::com::sun::star::uno::UNO_QUERY_THROW);
1024             sAppName = xModuleManager->identify(m_xFrame);
1025         } catch(::com::sun::star::uno::Exception&) {}
1026         Sequence<PropertyValue> vSource;
1027         ::comphelper::UiEventsLogger::appendDispatchOrigin(vSource, sAppName, ::rtl::OUString::createFromAscii("SfxToolBoxControl"));
1028         URL aURL;
1029         aURL.Complete = m_aCommandURL;
1030         ::comphelper::UiEventsLogger::logDispatch(aURL, vSource);
1031     }
1032     svt::ToolboxController::execute( pImpl->nSelectModifier );
1033 }
1034 
1035 //--------------------------------------------------------------------
1036 
DoubleClick()1037 void SfxToolBoxControl::DoubleClick()
1038 {
1039 }
1040 
1041 //--------------------------------------------------------------------
1042 
Click()1043 void SfxToolBoxControl::Click()
1044 {
1045 }
1046 
1047 //--------------------------------------------------------------------
1048 
GetPopupWindowType() const1049 SfxPopupWindowType SfxToolBoxControl::GetPopupWindowType() const
1050 {
1051     return SFX_POPUPWINDOW_NONE;
1052 }
1053 
1054 //--------------------------------------------------------------------
1055 
CreatePopupWindow()1056 SfxPopupWindow* SfxToolBoxControl::CreatePopupWindow()
1057 {
1058     return 0;
1059 }
1060 
CreatePopupWindowCascading()1061 SfxPopupWindow* SfxToolBoxControl::CreatePopupWindowCascading()
1062 {
1063     return 0;
1064 }
1065 
1066 //--------------------------------------------------------------------
1067 
CreateItemWindow(Window *)1068 Window* SfxToolBoxControl::CreateItemWindow( Window * )
1069 {
1070     return 0;
1071 }
1072 
1073 //--------------------------------------------------------------------
1074 
SfxFrameStatusListener(const Reference<XMultiServiceFactory> & rServiceManager,const Reference<XFrame> & xFrame,SfxStatusListenerInterface * pCallee)1075 SfxFrameStatusListener::SfxFrameStatusListener(
1076     const Reference< XMultiServiceFactory >& rServiceManager,
1077     const Reference< XFrame >& xFrame,
1078     SfxStatusListenerInterface* pCallee ) :
1079     svt::FrameStatusListener( rServiceManager, xFrame ),
1080     m_pCallee( pCallee )
1081 {
1082 }
1083 
1084 //--------------------------------------------------------------------
1085 
~SfxFrameStatusListener()1086 SfxFrameStatusListener::~SfxFrameStatusListener()
1087 {
1088 }
1089 
1090 //--------------------------------------------------------------------
1091 
1092 // XStatusListener
statusChanged(const::com::sun::star::frame::FeatureStateEvent & rEvent)1093 void SAL_CALL SfxFrameStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent )
1094 {
1095     SfxViewFrame* pViewFrame = NULL;
1096     Reference < XController > xController;
1097 
1098     ::vos::OGuard aGuard( Application::GetSolarMutex() );
1099     if ( m_xFrame.is() )
1100         xController = m_xFrame->getController();
1101 
1102     Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
1103     if ( xProvider.is() )
1104     {
1105         Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
1106         if ( xDisp.is() )
1107         {
1108             Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
1109             SfxOfficeDispatch* pDisp = NULL;
1110             if ( xTunnel.is() )
1111             {
1112                 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
1113                 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
1114             }
1115 
1116             if ( pDisp )
1117                 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
1118         }
1119     }
1120 
1121     sal_uInt16 nSlotId = 0;
1122     SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
1123     const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
1124     if ( pSlot )
1125         nSlotId = pSlot->GetSlotId();
1126 
1127     if ( nSlotId > 0 )
1128     {
1129         if ( rEvent.Requery )
1130         {
1131             // requery for the notified state
1132             addStatusListener( rEvent.FeatureURL.Complete );
1133         }
1134         else
1135         {
1136             SfxItemState eState = SFX_ITEM_DISABLED;
1137             SfxPoolItem* pItem = NULL;
1138             if ( rEvent.IsEnabled )
1139             {
1140                 eState = SFX_ITEM_AVAILABLE;
1141                 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
1142 
1143                 if ( pType == ::getVoidCppuType() )
1144                 {
1145                     pItem = new SfxVoidItem( nSlotId );
1146                     eState = SFX_ITEM_UNKNOWN;
1147                 }
1148                 else if ( pType == ::getBooleanCppuType() )
1149                 {
1150                     sal_Bool bTemp = false;
1151                     rEvent.State >>= bTemp ;
1152                     pItem = new SfxBoolItem( nSlotId, bTemp );
1153                 }
1154                 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
1155                 {
1156                     sal_uInt16 nTemp = 0;
1157                     rEvent.State >>= nTemp ;
1158                     pItem = new SfxUInt16Item( nSlotId, nTemp );
1159                 }
1160                 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
1161                 {
1162                     sal_uInt32 nTemp = 0;
1163                     rEvent.State >>= nTemp ;
1164                     pItem = new SfxUInt32Item( nSlotId, nTemp );
1165                 }
1166                 else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
1167                 {
1168                     ::rtl::OUString sTemp ;
1169                     rEvent.State >>= sTemp ;
1170                     pItem = new SfxStringItem( nSlotId, sTemp );
1171                 }
1172                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
1173                 {
1174                     ItemStatus aItemStatus;
1175                     rEvent.State >>= aItemStatus;
1176                     eState = aItemStatus.State;
1177                     pItem = new SfxVoidItem( nSlotId );
1178                 }
1179                 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
1180                 {
1181                     Visibility aVisibilityStatus;
1182                     rEvent.State >>= aVisibilityStatus;
1183                     pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
1184                 }
1185                 else
1186                 {
1187                     if ( pSlot )
1188                         pItem = pSlot->GetType()->CreateItem();
1189                     if ( pItem )
1190                     {
1191                         pItem->SetWhich( nSlotId );
1192                         pItem->PutValue( rEvent.State );
1193                     }
1194                     else
1195                         pItem = new SfxVoidItem( nSlotId );
1196                 }
1197             }
1198 
1199             if ( m_pCallee )
1200                 m_pCallee->StateChanged( nSlotId, eState, pItem );
1201             delete pItem;
1202         }
1203     }
1204 }
1205 
1206 //--------------------------------------------------------------------
1207 
SfxPopupWindow(sal_uInt16 nId,const Reference<XFrame> & rFrame,WinBits nBits)1208 SfxPopupWindow::SfxPopupWindow(
1209     sal_uInt16 nId,
1210     const Reference< XFrame >& rFrame,
1211     WinBits nBits ) :
1212     FloatingWindow( SFX_APP()->GetTopWindow(), nBits )
1213     , m_bFloating(sal_False)
1214     , m_bCascading( sal_False )
1215     , m_nId( nId )
1216     , m_xFrame( rFrame )
1217     , m_pStatusListener( 0 )
1218 {
1219     m_xServiceManager = ::comphelper::getProcessServiceFactory();
1220 
1221     Window* pWindow = GetTopMostParentSystemWindow( this );
1222     if ( pWindow )
1223         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1224 }
1225 
1226 //--------------------------------------------------------------------
1227 
SfxPopupWindow(sal_uInt16 nId,const Reference<XFrame> & rFrame,const ResId & rId)1228 SfxPopupWindow::SfxPopupWindow(
1229     sal_uInt16 nId,
1230     const Reference< XFrame >& rFrame,
1231     const ResId &rId ) :
1232     FloatingWindow( SFX_APP()->GetTopWindow(), rId )
1233     , m_bFloating(sal_False)
1234     , m_bCascading( sal_False )
1235     , m_nId( nId )
1236     , m_xFrame( rFrame )
1237     , m_pStatusListener( 0 )
1238 {
1239     m_xServiceManager = ::comphelper::getProcessServiceFactory();
1240 
1241     Window* pWindow = GetTopMostParentSystemWindow( this );
1242     if ( pWindow )
1243         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1244 }
1245 
1246 //--------------------------------------------------------------------
1247 
SfxPopupWindow(sal_uInt16 nId,const Reference<XFrame> & rFrame,Window * pParentWindow,WinBits nBits)1248 SfxPopupWindow::SfxPopupWindow(
1249     sal_uInt16 nId,
1250     const Reference< XFrame >& rFrame,
1251     Window* pParentWindow,
1252     WinBits nBits ) :
1253     FloatingWindow( pParentWindow, nBits )
1254     , m_bFloating(sal_False)
1255     , m_bCascading( sal_False )
1256     , m_nId( nId )
1257     , m_xFrame( rFrame )
1258     , m_pStatusListener( 0 )
1259 {
1260     m_xServiceManager = ::comphelper::getProcessServiceFactory();
1261 
1262     Window* pWindow = GetTopMostParentSystemWindow( this );
1263     if ( pWindow )
1264         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1265 }
1266 
1267 //--------------------------------------------------------------------
1268 
SfxPopupWindow(sal_uInt16 nId,const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & rFrame,Window * pParentWindow,const ResId & rId)1269 SfxPopupWindow::SfxPopupWindow(
1270     sal_uInt16 nId,
1271     const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
1272     Window* pParentWindow,
1273     const ResId &rId ) :
1274     FloatingWindow( pParentWindow, rId )
1275     , m_bFloating(sal_False)
1276     , m_bCascading( sal_False )
1277     , m_nId( nId )
1278     , m_xFrame( rFrame )
1279     , m_pStatusListener( 0 )
1280 {
1281     m_xServiceManager = ::comphelper::getProcessServiceFactory();
1282 
1283     Window* pWindow = GetTopMostParentSystemWindow( this );
1284     if ( pWindow )
1285         ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1286 }
1287 
1288 //--------------------------------------------------------------------
1289 
~SfxPopupWindow()1290 SfxPopupWindow::~SfxPopupWindow()
1291 {
1292     if ( m_xStatusListener.is() )
1293     {
1294         m_xStatusListener->dispose();
1295         m_xStatusListener.clear();
1296     }
1297 
1298     Window* pWindow = GetTopMostParentSystemWindow( this );
1299     if ( pWindow )
1300         ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( this );
1301 }
1302 
1303 //--------------------------------------------------------------------
1304 
GetOrCreateStatusListener()1305 SfxFrameStatusListener* SfxPopupWindow::GetOrCreateStatusListener()
1306 {
1307     if ( !m_xStatusListener.is() )
1308     {
1309         m_pStatusListener = new SfxFrameStatusListener(
1310                                     m_xServiceManager,
1311                                     m_xFrame,
1312                                     this );
1313         m_xStatusListener = Reference< XComponent >( static_cast< cppu::OWeakObject* >(
1314                                                         m_pStatusListener ), UNO_QUERY );
1315     }
1316 
1317     return m_pStatusListener;
1318 }
1319 
1320 //--------------------------------------------------------------------
1321 
BindListener()1322 void SfxPopupWindow::BindListener()
1323 {
1324     GetOrCreateStatusListener();
1325     if ( m_xStatusListener.is() )
1326         m_pStatusListener->bindListener();
1327 }
1328 
1329 //--------------------------------------------------------------------
1330 
UnbindListener()1331 void SfxPopupWindow::UnbindListener()
1332 {
1333     GetOrCreateStatusListener();
1334     if ( m_xStatusListener.is() )
1335         m_pStatusListener->unbindListener();
1336 }
1337 
1338 //--------------------------------------------------------------------
1339 
AddStatusListener(const rtl::OUString & rCommandURL)1340 void SfxPopupWindow::AddStatusListener( const rtl::OUString& rCommandURL )
1341 {
1342     GetOrCreateStatusListener();
1343     if ( m_xStatusListener.is() )
1344         m_pStatusListener->addStatusListener( rCommandURL );
1345 }
1346 
1347 //--------------------------------------------------------------------
1348 
RemoveStatusListener(const rtl::OUString & rCommandURL)1349 void SfxPopupWindow::RemoveStatusListener( const rtl::OUString& rCommandURL )
1350 {
1351     GetOrCreateStatusListener();
1352     if ( m_xStatusListener.is() )
1353         m_pStatusListener->removeStatusListener( rCommandURL );
1354 }
1355 
1356 //--------------------------------------------------------------------
1357 
UpdateStatus(const rtl::OUString & rCommandURL)1358 void SfxPopupWindow::UpdateStatus( const rtl::OUString& rCommandURL )
1359 {
1360     GetOrCreateStatusListener();
1361     if ( m_xStatusListener.is() )
1362         m_pStatusListener->updateStatus( rCommandURL );
1363 }
1364 
1365 //--------------------------------------------------------------------
1366 
Close()1367 sal_Bool SfxPopupWindow::Close()
1368 {
1369     m_bFloating = sal_False;
1370     FloatingWindow::Close();
1371 
1372     Delete(0);
1373     return sal_True;
1374 }
1375 
1376 //--------------------------------------------------------------------
1377 
PopupModeEnd()1378 void SfxPopupWindow::PopupModeEnd()
1379 {
1380     //! to allow PopupModeEndHdl to be called
1381     FloatingWindow::PopupModeEnd();
1382 
1383     if ( IsVisible() )
1384     {
1385         // wurde abgerissen
1386         DeleteFloatingWindow();
1387         m_bFloating = sal_True;
1388     }
1389     else
1390         Close();
1391 }
1392 
1393 //--------------------------------------------------------------------
1394 
DeleteFloatingWindow()1395 void SfxPopupWindow::DeleteFloatingWindow()
1396 {
1397     if ( m_bFloating )
1398     {
1399         Hide();
1400         Delete(0);
1401     }
1402 }
1403 
1404 //--------------------------------------------------------------------
1405 
MouseMove(const::MouseEvent & rMEvt)1406 void SfxPopupWindow::MouseMove( const ::MouseEvent& rMEvt )
1407 {
1408     if ( m_bCascading == sal_False )
1409         FloatingWindow::MouseMove( rMEvt );
1410     else
1411     {
1412         // MouseMove-Event an die Children forwarden
1413         ::Point       aPos = rMEvt.GetPosPixel();
1414         ::Point       aScrPos = OutputToScreenPixel( aPos );
1415         sal_uInt16 i = 0;
1416         Window* pWindow = GetChild( i );
1417         while ( pWindow )
1418         {
1419             ::MouseEvent aMEvt( pWindow->ScreenToOutputPixel( aScrPos ),
1420                               rMEvt.GetClicks(), rMEvt.GetMode(),
1421                               rMEvt.GetButtons(), rMEvt.GetModifier() );
1422             pWindow->MouseMove( rMEvt );
1423             pWindow->Update();
1424             i++;
1425             pWindow = GetChild( i );
1426         }
1427     }
1428 }
1429 
1430 //--------------------------------------------------------------------
1431 
StartCascading()1432 void SfxPopupWindow::StartCascading()
1433 {
1434     m_bCascading= sal_True;
1435 }
1436 
EndCascading()1437 void SfxPopupWindow::EndCascading()
1438 {
1439     m_bCascading = sal_False;
1440 }
1441 
1442 //--------------------------------------------------------------------
1443 
Clone() const1444 SfxPopupWindow* SfxPopupWindow::Clone() const
1445 
1446 /*  [Beschreibung]
1447 
1448     Diese Methode mu\s "uberladen werden, um dieses Popup auch im
1449     Presentations-Modus anzuzeigen. Sie wird gerufen, wenn ein Show()
1450     sinnlos w"are, da der Parent nicht das Presentations-Window ist.
1451     Beim neu erzeugen wird automatisch das neue Top-Window verwendet, so
1452     da\s der Parent das Presentations-Window ist und das neue Popup somit
1453     sichtbar ist.
1454 */
1455 
1456 {
1457     return 0;
1458 }
1459 
1460 //--------------------------------------------------------------------
1461 
StateChanged(sal_uInt16,SfxItemState eState,const SfxPoolItem *)1462 void SfxPopupWindow::StateChanged(
1463     sal_uInt16 /*nSID*/,
1464     SfxItemState eState,
1465     const SfxPoolItem* /*pState*/ )
1466 /*  [Bescheibung]
1467 
1468     Siehe auch <SfxControllerItem::StateChanged()>. Au\serdem wird
1469     bei eState==SFX_ITEM_DISABLED das Popup gehided und in allen anderen
1470     F"allen, falls es floating ist, wieder angezeigt. Daher mu\s die
1471     Basisklasse i.d.R. gerufen werden.
1472 
1473     Es findet wegen des Parents eine Sonderbehandlung f"ur den
1474     Presentationsmodus statt.
1475 
1476 */
1477 
1478 {
1479     if ( SFX_ITEM_DISABLED == eState )
1480     {
1481         Hide();
1482     }
1483     else if ( m_bFloating )
1484     {
1485         Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
1486     }
1487 }
1488 
1489 //--------------------------------------------------------------------
1490 
IMPL_LINK(SfxPopupWindow,Delete,void *,EMPTYARG)1491 IMPL_LINK( SfxPopupWindow, Delete, void *, EMPTYARG )
1492 {
1493     if ( m_aDeleteLink.IsSet() )
1494         m_aDeleteLink.Call( this );
1495     delete this;
1496     return 0;
1497 }
1498 
1499 //--------------------------------------------------------------------
1500