merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / toolbox / tbxitem.cxx
blobf0efa2da90483e8482da771edfd03c41e754dea4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbxitem.cxx,v $
10 * $Revision: 1.70.80.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #ifdef SOLARIS
35 // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
36 #include <ctime>
37 #endif
39 #include <string> // prevent conflict with STL includes
40 #include <com/sun/star/uno/Reference.h>
41 #include <com/sun/star/frame/XFrame.hpp>
42 #include <com/sun/star/awt/XWindow.hpp>
43 #include <com/sun/star/util/URL.hpp>
44 #include <com/sun/star/util/XURLTransformer.hpp>
45 #include <com/sun/star/frame/XController.hpp>
46 #include <com/sun/star/lang/XUnoTunnel.hpp>
47 #include <com/sun/star/document/MacroExecMode.hpp>
48 #include <com/sun/star/document/UpdateDocMode.hpp>
49 #include <com/sun/star/frame/XComponentLoader.hpp>
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <com/sun/star/frame/XLayoutManager.hpp>
53 #include <com/sun/star/frame/status/ItemStatus.hpp>
54 #include <com/sun/star/frame/status/ItemState.hpp>
55 #include <com/sun/star/ui/XUIElementFactory.hpp>
56 #include <com/sun/star/frame/XModuleManager.hpp>
57 #include <com/sun/star/container/XNameAccess.hpp>
58 #include <com/sun/star/ui/XUIFunctionListener.hpp>
59 #include <com/sun/star/frame/status/Visibility.hpp>
60 #include <com/sun/star/document/CorruptedFilterConfigurationException.hpp>
61 #include <svtools/eitem.hxx>
62 #include <svtools/stritem.hxx>
63 #include <svtools/intitem.hxx>
64 #include <svtools/imageitm.hxx>
65 #include <svtools/visitem.hxx>
66 #include <svtools/urlbmk.hxx>
67 #include <vcl/toolbox.hxx>
68 #include <svtools/moduleoptions.hxx>
70 #include <svtools/imagemgr.hxx>
71 #include <comphelper/processfactory.hxx>
72 #include <framework/addonmenu.hxx>
73 #include <framework/addonsoptions.hxx>
74 #include <framework/menuconfiguration.hxx>
75 #include <framework/sfxhelperfunctions.hxx>
76 #include <vcl/taskpanelist.hxx>
77 #ifndef _TOOLKIT_UNOHLP_HXX
78 #include <toolkit/helper/vclunohelper.hxx>
79 #endif
80 #include <svtools/menuoptions.hxx>
81 #include <svtools/miscopt.hxx>
83 #ifndef GCC
84 #endif
86 #include <sfx2/tbxctrl.hxx>
87 #include <sfx2/mnumgr.hxx>
88 #include <sfx2/dispatch.hxx>
89 #include "fltfnc.hxx"
90 #include <sfx2/msg.hxx>
91 #include <sfx2/msgpool.hxx>
92 #include "statcach.hxx"
93 #include <sfx2/viewfrm.hxx>
94 #include "arrdecl.hxx"
95 #include "sfxtypes.hxx"
96 #include <sfx2/macrconf.hxx>
97 #include <sfx2/genlink.hxx>
98 #include "sfxresid.hxx"
99 #include <sfx2/sfx.hrc>
100 #include <sfx2/module.hxx>
101 #include <sfx2/docfile.hxx>
102 #include <sfx2/docfac.hxx>
103 #include "referers.hxx"
104 #include <sfx2/frmhtmlw.hxx>
105 #include <sfx2/app.hxx>
106 #include <sfx2/unoctitm.hxx>
107 #include "helpid.hrc"
108 #include "workwin.hxx"
109 #include "imgmgr.hxx"
110 #include "virtmenu.hxx"
111 #include <sfx2/viewfrm.hxx>
112 #include <sfx2/module.hxx>
113 #include "imagemgr.hxx"
115 #include <comphelper/uieventslogger.hxx>
116 #include <com/sun/star/frame/XModuleManager.hpp>
118 //using namespace ::com::sun::star::awt;
119 using namespace ::com::sun::star::beans;
120 using namespace ::com::sun::star::frame;
121 using namespace ::com::sun::star::frame::status;
122 using namespace ::com::sun::star::lang;
123 using namespace ::com::sun::star::uno;
124 using namespace ::com::sun::star::util;
125 using namespace ::com::sun::star::container;
126 using namespace ::com::sun::star::frame;
127 using namespace ::com::sun::star::ui;
129 //====================================================================
131 SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, TRUE);
132 SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem);
134 static Window* GetTopMostParentSystemWindow( Window* pWindow )
136 OSL_ASSERT( pWindow );
137 if ( pWindow )
139 // ->manually search topmost system window
140 // required because their might be another system window between this and the top window
141 pWindow = pWindow->GetParent();
142 SystemWindow* pTopMostSysWin = NULL;
143 while ( pWindow )
145 if ( pWindow->IsSystemWindow() )
146 pTopMostSysWin = (SystemWindow*)pWindow;
147 pWindow = pWindow->GetParent();
149 pWindow = pTopMostSysWin;
150 OSL_ASSERT( pWindow );
151 return pWindow;
154 return NULL;
157 svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const Reference< XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const ::rtl::OUString& aCommandURL )
159 ::vos::OGuard aGuard( Application::GetSolarMutex() );
161 URL aTargetURL;
162 aTargetURL.Complete = aCommandURL;
163 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
164 xTrans->parseStrict( aTargetURL );
165 if ( aTargetURL.Arguments.getLength() )
166 return NULL;
168 SfxObjectShell* pObjShell = NULL;
169 Reference < XController > xController;
170 Reference < XModel > xModel;
171 if ( rFrame.is() )
173 xController = rFrame->getController();
174 if ( xController.is() )
175 xModel = xController->getModel();
178 if ( xModel.is() )
180 // Get tunnel from model to retrieve the SfxObjectShell pointer from it
181 ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xModel, UNO_QUERY );
182 if ( xObj.is() )
184 ::com::sun::star::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
185 sal_Int64 nHandle = xObj->getSomething( aSeq );
186 if ( nHandle )
187 pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
191 SfxModule* pModule = pObjShell ? pObjShell->GetModule() : NULL;
192 SfxSlotPool* pSlotPool = 0;
194 if ( pModule )
195 pSlotPool = pModule->GetSlotPool();
196 else
197 pSlotPool = &(SfxSlotPool::GetSlotPool( NULL ));
199 const SfxSlot* pSlot = pSlotPool->GetUnoSlot( aTargetURL.Path );
200 if ( pSlot )
202 USHORT nSlotId = pSlot->GetSlotId();
203 if ( nSlotId > 0 )
204 return SfxToolBoxControl::CreateControl( nSlotId, nID, pToolbox, pModule );
207 return NULL;
210 struct SfxToolBoxControl_Impl
212 ToolBox* pBox;
213 BOOL bShowString;
214 USHORT nSelectModifier;
215 SfxTbxCtrlFactory* pFact;
216 USHORT nTbxId;
217 USHORT nSlotId;
218 SfxPopupWindow* mpFloatingWindow;
219 SfxPopupWindow* mpPopupWindow;
220 Reference< XUIElement > mxUIElement;
222 DECL_LINK( WindowEventListener, VclSimpleEvent* );
225 IMPL_LINK( SfxToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent )
227 if ( pEvent &&
228 pEvent->ISA( VclWindowEvent ) &&
229 (( pEvent->GetId() == VCLEVENT_WINDOW_MOVE ) ||
230 ( pEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE )))
232 Window* pWindow( ((VclWindowEvent*)pEvent)->GetWindow() );
233 if (( pWindow == mpFloatingWindow ) &&
234 ( mpPopupWindow != 0 ))
236 delete mpPopupWindow;
237 mpPopupWindow = 0;
241 return 1;
244 //--------------------------------------------------------------------
246 SfxToolBoxControl::SfxToolBoxControl(
247 USHORT nSlotID,
248 USHORT nID,
249 ToolBox& rBox,
250 BOOL bShowStringItems )
251 : svt::ToolboxController()
253 pImpl = new SfxToolBoxControl_Impl;
255 pImpl->pBox = &rBox;
256 pImpl->bShowString = bShowStringItems;
257 pImpl->nSelectModifier = 0;
258 pImpl->pFact = 0;
259 pImpl->nTbxId = nID;
260 pImpl->nSlotId = nSlotID;
261 pImpl->mpFloatingWindow = 0;
262 pImpl->mpPopupWindow = 0;
265 //--------------------------------------------------------------------
267 SfxToolBoxControl::~SfxToolBoxControl()
269 if ( pImpl->mxUIElement.is() )
271 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
272 xComponent->dispose();
274 pImpl->mxUIElement = 0;
275 delete pImpl;
278 //--------------------------------------------------------------------
280 ToolBox& SfxToolBoxControl::GetToolBox() const
282 return *pImpl->pBox;
284 unsigned short SfxToolBoxControl::GetId() const
286 return pImpl->nTbxId;
288 unsigned short SfxToolBoxControl::GetSlotId() const
290 return pImpl->nSlotId;
293 //--------------------------------------------------------------------
295 void SAL_CALL SfxToolBoxControl::dispose() throw (::com::sun::star::uno::RuntimeException)
297 if ( m_bDisposed )
298 return;
300 svt::ToolboxController::dispose();
302 // Remove and destroy our item window at our toolbox
303 ::vos::OGuard aGuard( Application::GetSolarMutex() );
304 Window* pWindow = pImpl->pBox->GetItemWindow( pImpl->nTbxId );
305 pImpl->pBox->SetItemWindow( pImpl->nTbxId, 0 );
306 delete pWindow;
308 // Dispose an open sub toolbar. It's possible that we have an open
309 // sub toolbar while we get disposed. Therefore we have to dispose
310 // it now! Not doing so would result in a crash. The sub toolbar
311 // gets destroyed asynchronously and would access a non-existing
312 // parent toolbar! See #126569#
313 if ( pImpl->mxUIElement.is() )
315 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
316 xComponent->dispose();
318 pImpl->mxUIElement = 0;
320 // Delete my popup windows
321 delete pImpl->mpFloatingWindow;
322 delete pImpl->mpPopupWindow;
324 pImpl->mpFloatingWindow = 0;
325 pImpl->mpPopupWindow = 0;
328 //--------------------------------------------------------------------
329 void SfxToolBoxControl::RegisterToolBoxControl( SfxModule* pMod, SfxTbxCtrlFactory* pFact)
331 SFX_APP()->RegisterToolBoxControl_Impl( pMod, pFact );
334 SfxToolBoxControl* SfxToolBoxControl::CreateControl( USHORT nSlotId, USHORT nTbxId, ToolBox *pBox, SfxModule* pMod )
336 ::vos::OGuard aGuard( Application::GetSolarMutex() );
338 SfxToolBoxControl *pCtrl;
339 SfxApplication *pApp = SFX_APP();
341 SfxSlotPool *pSlotPool;
342 if ( pMod )
343 pSlotPool = pMod->GetSlotPool();
344 else
345 pSlotPool = &SfxSlotPool::GetSlotPool();
346 TypeId aSlotType = pSlotPool->GetSlotType( nSlotId );
347 if ( aSlotType )
349 if ( pMod )
351 SfxTbxCtrlFactArr_Impl *pFactories = pMod->GetTbxCtrlFactories_Impl();
352 if ( pFactories )
354 SfxTbxCtrlFactArr_Impl &rFactories = *pFactories;
355 USHORT nFactory;
356 const USHORT nCount = rFactories.Count();
358 // search for a factory with the given slot id
359 for( nFactory = 0; nFactory < nCount; ++nFactory )
360 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
361 break;
363 if( nFactory == nCount )
365 // if no factory exists for the given slot id, see if we
366 // have a generic factory with the correct slot type and slot id == 0
367 for ( nFactory = 0; nFactory < nCount; ++nFactory )
368 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
369 break;
372 if( nFactory < nCount )
374 pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
375 pCtrl->pImpl->pFact = rFactories[nFactory];
376 return pCtrl;
381 SfxTbxCtrlFactArr_Impl &rFactories = pApp->GetTbxCtrlFactories_Impl();
382 USHORT nFactory;
383 const USHORT nCount = rFactories.Count();
385 for( nFactory = 0; nFactory < nCount; ++nFactory )
386 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
387 break;
389 if( nFactory == nCount )
391 // if no factory exists for the given slot id, see if we
392 // have a generic factory with the correct slot type and slot id == 0
393 for( nFactory = 0; nFactory < nCount; ++nFactory )
394 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
395 break;
398 if( nFactory < nCount )
400 pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
401 pCtrl->pImpl->pFact = rFactories[nFactory];
402 return pCtrl;
406 return NULL;
409 SfxItemState SfxToolBoxControl::GetItemState(
410 const SfxPoolItem* pState )
411 /* [Beschreibung]
413 Statische Methode zum Ermitteln des Status des SfxPoolItem-Pointers,
414 in der Methode <SfxControllerItem::StateChanged(const SfxPoolItem*)>
415 zu verwenden.
417 [R"uckgabewert]
419 SfxItemState SFX_ITEM_UNKNOWN
420 Enabled, aber keine weitere Statusinformation
421 verf"ugbar. Typisch f"ur <Slot>s, die allenfalls
422 zeitweise disabled sind, aber ihre Darstellung sonst
423 nicht "andern.
425 SFX_ITEM_DISABLED
426 Disabled und keine weiter Statusinformation
427 verf"ugbar. Alle anderen ggf. angezeigten Werte sollten
428 auf den Default zur"uckgesetzt werden.
430 SFX_ITEM_DONTCARE
431 Enabled aber es waren nur uneindeutige Werte
432 verf"ugbar (also keine, die abgefragt werden k"onnen).
434 SFX_ITEM_AVAILABLE
435 Enabled und mit verf"ugbarem Wert, der von 'pState'
436 erfragbar ist. Der Typ ist dabei im gesamten
437 Programm eindeutig und durch den Slot festgelegt.
441 return !pState
442 ? SFX_ITEM_DISABLED
443 : IsInvalidItem(pState)
444 ? SFX_ITEM_DONTCARE
445 : pState->ISA(SfxVoidItem) && !pState->Which()
446 ? SFX_ITEM_UNKNOWN
447 : SFX_ITEM_AVAILABLE;
450 void SfxToolBoxControl::Dispatch(
451 const Reference< XDispatchProvider >& rProvider,
452 const rtl::OUString& rCommand,
453 Sequence< ::PropertyValue >& aArgs )
455 if ( rProvider.is() )
457 ::com::sun::star::util::URL aTargetURL;
458 aTargetURL.Complete = rCommand;
459 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
460 rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
461 UNO_QUERY );
462 xTrans->parseStrict( aTargetURL );
464 Reference < XDispatch > xDispatch = rProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
465 if ( xDispatch.is() )
466 xDispatch->dispatch( aTargetURL, aArgs );
470 void SfxToolBoxControl::Dispatch( const ::rtl::OUString& aCommand, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
472 Reference < XController > xController;
474 ::vos::OGuard aGuard( Application::GetSolarMutex() );
475 if ( getFrameInterface().is() )
476 xController = getFrameInterface()->getController();
478 Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
479 if ( xProvider.is() )
481 ::com::sun::star::util::URL aTargetURL;
482 aTargetURL.Complete = aCommand;
483 getURLTransformer()->parseStrict( aTargetURL );
485 Reference < XDispatch > xDispatch = xProvider->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
486 if ( xDispatch.is() )
488 if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
490 ::rtl::OUString sAppName;
493 static ::rtl::OUString our_aModuleManagerName = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
494 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager =
495 ::comphelper::getProcessServiceFactory();
496 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
497 xServiceManager->createInstance(our_aModuleManagerName)
498 , ::com::sun::star::uno::UNO_QUERY_THROW);
499 ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
500 getFrameInterface(), UNO_QUERY_THROW);
501 sAppName = xModuleManager->identify(xFrame);
502 } catch(::com::sun::star::uno::Exception&) {}
503 Sequence<PropertyValue> source;
504 ::comphelper::UiEventsLogger::appendDispatchOrigin(source, sAppName, ::rtl::OUString::createFromAscii("SfxToolBoxControl"));
505 ::comphelper::UiEventsLogger::logDispatch(aTargetURL, source);
507 xDispatch->dispatch( aTargetURL, aArgs );
512 // XInterface
513 Any SAL_CALL SfxToolBoxControl::queryInterface( const Type & rType )
514 throw(::com::sun::star::uno::RuntimeException)
516 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
517 SAL_STATIC_CAST( ::com::sun::star::awt::XDockableWindowListener*, this ),
518 SAL_STATIC_CAST( ::com::sun::star::frame::XSubToolbarController*, this ));
519 return (aRet.hasValue() ? aRet : svt::ToolboxController::queryInterface( rType ));
522 void SAL_CALL SfxToolBoxControl::acquire() throw()
524 OWeakObject::acquire();
527 void SAL_CALL SfxToolBoxControl::release() throw()
529 OWeakObject::release();
532 void SAL_CALL SfxToolBoxControl::disposing( const ::com::sun::star::lang::EventObject& aEvent )
533 throw( ::com::sun::star::uno::RuntimeException )
535 svt::ToolboxController::disposing( aEvent );
538 // XStatusListener
539 void SAL_CALL SfxToolBoxControl::statusChanged( const FeatureStateEvent& rEvent )
540 throw ( ::com::sun::star::uno::RuntimeException )
542 SfxViewFrame* pViewFrame = NULL;
543 Reference < XController > xController;
545 ::vos::OGuard aGuard( Application::GetSolarMutex() );
546 if ( getFrameInterface().is() )
547 xController = getFrameInterface()->getController();
549 Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
550 if ( xProvider.is() )
552 Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
553 if ( xDisp.is() )
555 Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
556 SfxOfficeDispatch* pDisp = NULL;
557 if ( xTunnel.is() )
559 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
560 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
563 if ( pDisp )
564 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
568 USHORT nSlotId = 0;
569 SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
570 const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
571 if ( pSlot )
572 nSlotId = pSlot->GetSlotId();
573 else if ( m_aCommandURL == rEvent.FeatureURL.Path )
574 nSlotId = GetSlotId();
576 if ( nSlotId > 0 )
578 if ( rEvent.Requery )
579 svt::ToolboxController::statusChanged( rEvent );
580 else
582 SfxItemState eState = SFX_ITEM_DISABLED;
583 SfxPoolItem* pItem = NULL;
584 if ( rEvent.IsEnabled )
586 eState = SFX_ITEM_AVAILABLE;
587 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
589 if ( pType == ::getVoidCppuType() )
591 pItem = new SfxVoidItem( nSlotId );
592 eState = SFX_ITEM_UNKNOWN;
594 else if ( pType == ::getBooleanCppuType() )
596 sal_Bool bTemp = false;
597 rEvent.State >>= bTemp ;
598 pItem = new SfxBoolItem( nSlotId, bTemp );
600 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
602 sal_uInt16 nTemp = 0;
603 rEvent.State >>= nTemp ;
604 pItem = new SfxUInt16Item( nSlotId, nTemp );
606 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
608 sal_uInt32 nTemp = 0;
609 rEvent.State >>= nTemp ;
610 pItem = new SfxUInt32Item( nSlotId, nTemp );
612 else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
614 ::rtl::OUString sTemp ;
615 rEvent.State >>= sTemp ;
616 pItem = new SfxStringItem( nSlotId, sTemp );
618 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
620 ItemStatus aItemStatus;
621 rEvent.State >>= aItemStatus;
622 eState = aItemStatus.State;
623 pItem = new SfxVoidItem( nSlotId );
625 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
627 Visibility aVisibilityStatus;
628 rEvent.State >>= aVisibilityStatus;
629 pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
631 else
633 if ( pSlot )
634 pItem = pSlot->GetType()->CreateItem();
635 if ( pItem )
637 pItem->SetWhich( nSlotId );
638 pItem->PutValue( rEvent.State );
640 else
641 pItem = new SfxVoidItem( nSlotId );
645 StateChanged( nSlotId, eState, pItem );
646 delete pItem;
651 // XSubToolbarController
652 ::sal_Bool SAL_CALL SfxToolBoxControl::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
654 return sal_False;
657 ::rtl::OUString SAL_CALL SfxToolBoxControl::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
659 return rtl::OUString();
662 void SAL_CALL SfxToolBoxControl::functionSelected( const ::rtl::OUString& /*aCommand*/ ) throw (::com::sun::star::uno::RuntimeException)
664 // must be implemented by sub-class
667 void SAL_CALL SfxToolBoxControl::updateImage() throw (::com::sun::star::uno::RuntimeException)
669 // must be implemented by sub-class
672 // XToolbarController
673 void SAL_CALL SfxToolBoxControl::execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException)
675 ::vos::OGuard aGuard( Application::GetSolarMutex() );
676 Select( (USHORT)KeyModifier );
678 void SAL_CALL SfxToolBoxControl::click() throw (::com::sun::star::uno::RuntimeException)
680 ::vos::OGuard aGuard( Application::GetSolarMutex() );
681 Click();
684 void SAL_CALL SfxToolBoxControl::doubleClick() throw (::com::sun::star::uno::RuntimeException)
686 ::vos::OGuard aGuard( Application::GetSolarMutex() );
687 DoubleClick();
690 Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createPopupWindow() throw (::com::sun::star::uno::RuntimeException)
692 ::vos::OGuard aGuard( Application::GetSolarMutex() );
693 Window* pWindow = CreatePopupWindow();
694 if ( pWindow )
695 return VCLUnoHelper::GetInterface( pWindow );
696 else
697 return Reference< ::com::sun::star::awt::XWindow >();
700 Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createItemWindow( const Reference< ::com::sun::star::awt::XWindow >& rParent ) throw (::com::sun::star::uno::RuntimeException)
702 ::vos::OGuard aGuard( Application::GetSolarMutex() );
703 return VCLUnoHelper::GetInterface( CreateItemWindow( VCLUnoHelper::GetWindow( rParent )));
706 // XDockableWindowListener
707 void SAL_CALL SfxToolBoxControl::startDocking( const ::com::sun::star::awt::DockingEvent& )
708 throw (::com::sun::star::uno::RuntimeException)
711 ::com::sun::star::awt::DockingData SAL_CALL SfxToolBoxControl::docking( const ::com::sun::star::awt::DockingEvent& )
712 throw (::com::sun::star::uno::RuntimeException)
714 return ::com::sun::star::awt::DockingData();
717 void SAL_CALL SfxToolBoxControl::endDocking( const ::com::sun::star::awt::EndDockingEvent& )
718 throw (::com::sun::star::uno::RuntimeException)
722 sal_Bool SAL_CALL SfxToolBoxControl::prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& )
723 throw (::com::sun::star::uno::RuntimeException)
725 return sal_False;
728 void SAL_CALL SfxToolBoxControl::toggleFloatingMode( const ::com::sun::star::lang::EventObject& )
729 throw (::com::sun::star::uno::RuntimeException)
733 void SAL_CALL SfxToolBoxControl::closed( const ::com::sun::star::lang::EventObject& )
734 throw (::com::sun::star::uno::RuntimeException)
738 void SAL_CALL SfxToolBoxControl::endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& aEvent )
739 throw (::com::sun::star::uno::RuntimeException)
741 ::vos::OGuard aGuard( Application::GetSolarMutex() );
743 ::rtl::OUString aSubToolBarResName;
744 if ( pImpl->mxUIElement.is() )
746 Reference< XPropertySet > xPropSet( pImpl->mxUIElement, UNO_QUERY );
747 if ( xPropSet.is() )
751 xPropSet->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ))) >>= aSubToolBarResName;
753 catch ( com::sun::star::beans::UnknownPropertyException& )
756 catch ( com::sun::star::lang::WrappedTargetException& )
761 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
762 xComponent->dispose();
764 pImpl->mxUIElement = 0;
766 // if the toolbar was teared-off recreate it and place it at the given position
767 if( aEvent.bTearoff )
769 Reference< XUIElement > xUIElement;
770 Reference< XLayoutManager > xLayoutManager = getLayoutManager();
772 if ( !xLayoutManager.is() )
773 return;
775 xLayoutManager->createElement( aSubToolBarResName );
776 xUIElement = xLayoutManager->getElement( aSubToolBarResName );
777 if ( xUIElement.is() )
779 Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
781 Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
782 Reference< ::com::sun::star::beans::XPropertySet > xProp( xUIElement, UNO_QUERY );
783 if ( xSubToolBar.is() && xProp.is() )
785 rtl::OUString aPersistentString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
788 Window* pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
789 ToolBox* pToolBar( 0 );
790 if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
792 pToolBar = (ToolBox *)pTbxWindow;
794 Any a;
795 a = xProp->getPropertyValue( aPersistentString );
796 xProp->setPropertyValue( aPersistentString, makeAny( sal_False ));
798 xLayoutManager->hideElement( aSubToolBarResName );
799 xLayoutManager->floatWindow( aSubToolBarResName );
801 xLayoutManager->setElementPos( aSubToolBarResName, aEvent.FloatingPosition );
802 xLayoutManager->showElement( aSubToolBarResName );
804 xProp->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" )), a );
807 catch ( ::com::sun::star::uno::RuntimeException& )
809 throw;
811 catch ( ::com::sun::star::uno::Exception& )
819 ::Size SfxToolBoxControl::getPersistentFloatingSize( const Reference< XFrame >& /*xFrame*/, const ::rtl::OUString& /*rSubToolBarResName*/ )
821 ::Size aToolboxSize;
822 return aToolboxSize;
825 void SfxToolBoxControl::createAndPositionSubToolBar( const ::rtl::OUString& rSubToolBarResName )
827 ::vos::OGuard aGuard( Application::GetSolarMutex() );
829 if ( pImpl->pBox )
831 static WeakReference< XUIElementFactory > xWeakUIElementFactory;
833 USHORT nItemId = pImpl->pBox->GetDownItemId();
835 if ( !nItemId )
836 return;
838 // create element with factory
839 Reference< XMultiServiceFactory > xServiceManager = getServiceManager();
840 Reference< XFrame > xFrame = getFrameInterface();
841 Reference< XUIElement > xUIElement;
842 Reference< XUIElementFactory > xUIEementFactory;
844 xUIEementFactory = xWeakUIElementFactory;
845 if ( !xUIEementFactory.is() )
847 xUIEementFactory = Reference< XUIElementFactory >(
848 xServiceManager->createInstance(
849 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
850 "com.sun.star.ui.UIElementFactoryManager" ))),
851 UNO_QUERY );
852 xWeakUIElementFactory = xUIEementFactory;
855 Sequence< PropertyValue > aPropSeq( 3 );
856 aPropSeq[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
857 aPropSeq[0].Value <<= xFrame;
858 aPropSeq[1].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
859 aPropSeq[1].Value <<= sal_False;
860 aPropSeq[2].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PopupMode" ));
861 aPropSeq[2].Value <<= sal_True;
865 xUIElement = xUIEementFactory->createUIElement( rSubToolBarResName, aPropSeq );
867 catch ( ::com::sun::star::container::NoSuchElementException& )
870 catch ( IllegalArgumentException& )
874 if ( xUIElement.is() )
876 Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
878 Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
879 if ( xSubToolBar.is() )
881 Reference< ::com::sun::star::awt::XDockableWindow > xDockWindow( xSubToolBar, UNO_QUERY );
882 xDockWindow->addDockableWindowListener( Reference< ::com::sun::star::awt::XDockableWindowListener >(
883 static_cast< OWeakObject * >( this ), UNO_QUERY ));
884 xDockWindow->enableDocking( sal_True );
886 // keep refererence to UIElement to avoid its destruction
887 if ( pImpl->mxUIElement.is() )
889 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
890 xComponent->dispose();
892 pImpl->mxUIElement = xUIElement;
894 Window* pParentTbxWindow( pImpl->pBox );
895 Window* pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
896 ToolBox* pToolBar( 0 );
897 if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
898 pToolBar = (ToolBox *)pTbxWindow;
900 if ( pToolBar )
902 pToolBar->SetParent( pParentTbxWindow );
903 ::Size aSize = getPersistentFloatingSize( xFrame, rSubToolBarResName );
904 if ( aSize.Width() == 0 || aSize.Height() == 0 )
906 // calc and set size for popup mode
907 aSize = pToolBar->CalcPopupWindowSizePixel();
909 pToolBar->SetSizePixel( aSize );
911 // open subtoolbox in popup mode
912 Window::GetDockingManager()->StartPopupMode( pImpl->pBox, pToolBar );
919 //--------------------------------------------------------------------
921 void SfxToolBoxControl::SetPopupWindow( SfxPopupWindow* pWindow )
923 pImpl->mpPopupWindow = pWindow;
924 pImpl->mpPopupWindow->SetPopupModeEndHdl( LINK( this, SfxToolBoxControl, PopupModeEndHdl ));
925 pImpl->mpPopupWindow->SetDeleteLink_Impl( LINK( this, SfxToolBoxControl, ClosePopupWindow ));
928 //--------------------------------------------------------------------
930 IMPL_LINK( SfxToolBoxControl, PopupModeEndHdl, void *, EMPTYARG )
932 if ( pImpl->mpPopupWindow->IsVisible() )
934 // Replace floating window with popup window and destroy
935 // floating window instance.
936 delete pImpl->mpFloatingWindow;
937 pImpl->mpFloatingWindow = pImpl->mpPopupWindow;
938 pImpl->mpPopupWindow = 0;
939 // We also need to know when the user tries to use the
940 // floating window.
941 pImpl->mpFloatingWindow->AddEventListener( LINK( pImpl, SfxToolBoxControl_Impl, WindowEventListener ));
943 else
945 // Popup window has been closed by the user. No replacement, instance
946 // will destroy itself.
947 pImpl->mpPopupWindow = 0;
950 return 1;
953 //--------------------------------------------------------------------
954 IMPL_LINK( SfxToolBoxControl, ClosePopupWindow, SfxPopupWindow *, pWindow )
956 if ( pWindow == pImpl->mpFloatingWindow )
957 pImpl->mpFloatingWindow = 0;
958 else
959 pImpl->mpPopupWindow = 0;
961 return 1;
964 //--------------------------------------------------------------------
966 void SfxToolBoxControl::StateChanged
968 USHORT nId,
969 SfxItemState eState,
970 const SfxPoolItem* pState
973 DBG_MEMTEST();
974 DBG_ASSERT( pImpl->pBox != 0, "setting state to dangling ToolBox" );
976 if ( GetId() >= SID_OBJECTMENU0 && GetId() <= SID_OBJECTMENU_LAST )
977 return;
979 // enabled/disabled-Flag pauschal korrigieren
980 pImpl->pBox->EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
982 USHORT nItemBits = pImpl->pBox->GetItemBits( GetId() );
983 nItemBits &= ~TIB_CHECKABLE;
984 TriState eTri = STATE_NOCHECK;
985 switch ( eState )
987 case SFX_ITEM_AVAILABLE:
989 if ( pState->ISA(SfxBoolItem) )
991 // BoolItem fuer checken
992 if ( ((const SfxBoolItem*)pState)->GetValue() )
993 eTri = STATE_CHECK;
994 nItemBits |= TIB_CHECKABLE;
996 else if ( pState->ISA(SfxEnumItemInterface) &&
997 ((SfxEnumItemInterface *)pState)->HasBoolValue())
999 // EnumItem wie Bool behandeln
1000 if ( ((const SfxEnumItemInterface *)pState)->GetBoolValue() )
1001 eTri = STATE_CHECK;
1002 nItemBits |= TIB_CHECKABLE;
1004 else if ( pImpl->bShowString && pState->ISA(SfxStringItem) )
1005 pImpl->pBox->SetItemText(nId, ((const SfxStringItem*)pState)->GetValue() );
1006 break;
1009 case SFX_ITEM_DONTCARE:
1011 eTri = STATE_DONTKNOW;
1012 nItemBits |= TIB_CHECKABLE;
1016 pImpl->pBox->SetItemState( GetId(), eTri );
1017 pImpl->pBox->SetItemBits( GetId(), nItemBits );
1020 //--------------------------------------------------------------------
1022 void SfxToolBoxControl::Select( USHORT nModifier )
1024 pImpl->nSelectModifier = nModifier;
1025 Select( BOOL((nModifier & KEY_MOD1)!=0) );
1028 //--------------------------------------------------------------------
1030 void SfxToolBoxControl::Select( BOOL /*bMod1*/ )
1032 if(::comphelper::UiEventsLogger::isEnabled()) //#i88653# #i102805#
1034 ::rtl::OUString sAppName;
1037 static ::rtl::OUString our_aModuleManagerName = ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
1038 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xServiceManager =
1039 ::comphelper::getProcessServiceFactory();
1040 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager > xModuleManager(
1041 xServiceManager->createInstance(our_aModuleManagerName)
1042 , ::com::sun::star::uno::UNO_QUERY_THROW);
1043 sAppName = xModuleManager->identify(m_xFrame);
1044 } catch(::com::sun::star::uno::Exception&) {}
1045 Sequence<PropertyValue> vSource;
1046 ::comphelper::UiEventsLogger::appendDispatchOrigin(vSource, sAppName, ::rtl::OUString::createFromAscii("SfxToolBoxControl"));
1047 URL aURL;
1048 aURL.Complete = m_aCommandURL;
1049 ::comphelper::UiEventsLogger::logDispatch(aURL, vSource);
1051 svt::ToolboxController::execute( pImpl->nSelectModifier );
1054 //--------------------------------------------------------------------
1056 void SfxToolBoxControl::DoubleClick()
1060 //--------------------------------------------------------------------
1062 void SfxToolBoxControl::Click()
1066 //--------------------------------------------------------------------
1068 SfxPopupWindowType SfxToolBoxControl::GetPopupWindowType() const
1070 return SFX_POPUPWINDOW_NONE;
1073 //--------------------------------------------------------------------
1075 SfxPopupWindow* SfxToolBoxControl::CreatePopupWindow()
1077 return 0;
1080 SfxPopupWindow* SfxToolBoxControl::CreatePopupWindowCascading()
1082 return 0;
1085 //--------------------------------------------------------------------
1087 Window* SfxToolBoxControl::CreateItemWindow( Window * )
1089 return 0;
1092 //--------------------------------------------------------------------
1094 SfxFrameStatusListener::SfxFrameStatusListener(
1095 const Reference< XMultiServiceFactory >& rServiceManager,
1096 const Reference< XFrame >& xFrame,
1097 SfxStatusListenerInterface* pCallee ) :
1098 svt::FrameStatusListener( rServiceManager, xFrame ),
1099 m_pCallee( pCallee )
1103 //--------------------------------------------------------------------
1105 SfxFrameStatusListener::~SfxFrameStatusListener()
1109 //--------------------------------------------------------------------
1111 // XStatusListener
1112 void SAL_CALL SfxFrameStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent )
1113 throw ( ::com::sun::star::uno::RuntimeException )
1115 SfxViewFrame* pViewFrame = NULL;
1116 Reference < XController > xController;
1118 ::vos::OGuard aGuard( Application::GetSolarMutex() );
1119 if ( m_xFrame.is() )
1120 xController = m_xFrame->getController();
1122 Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
1123 if ( xProvider.is() )
1125 Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, ::rtl::OUString(), 0 );
1126 if ( xDisp.is() )
1128 Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
1129 SfxOfficeDispatch* pDisp = NULL;
1130 if ( xTunnel.is() )
1132 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
1133 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
1136 if ( pDisp )
1137 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
1141 USHORT nSlotId = 0;
1142 SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
1143 const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
1144 if ( pSlot )
1145 nSlotId = pSlot->GetSlotId();
1147 if ( nSlotId > 0 )
1149 if ( rEvent.Requery )
1151 // requery for the notified state
1152 addStatusListener( rEvent.FeatureURL.Complete );
1154 else
1156 SfxItemState eState = SFX_ITEM_DISABLED;
1157 SfxPoolItem* pItem = NULL;
1158 if ( rEvent.IsEnabled )
1160 eState = SFX_ITEM_AVAILABLE;
1161 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
1163 if ( pType == ::getVoidCppuType() )
1165 pItem = new SfxVoidItem( nSlotId );
1166 eState = SFX_ITEM_UNKNOWN;
1168 else if ( pType == ::getBooleanCppuType() )
1170 sal_Bool bTemp = false;
1171 rEvent.State >>= bTemp ;
1172 pItem = new SfxBoolItem( nSlotId, bTemp );
1174 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
1176 sal_uInt16 nTemp = 0;
1177 rEvent.State >>= nTemp ;
1178 pItem = new SfxUInt16Item( nSlotId, nTemp );
1180 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
1182 sal_uInt32 nTemp = 0;
1183 rEvent.State >>= nTemp ;
1184 pItem = new SfxUInt32Item( nSlotId, nTemp );
1186 else if ( pType == ::getCppuType((const ::rtl::OUString*)0) )
1188 ::rtl::OUString sTemp ;
1189 rEvent.State >>= sTemp ;
1190 pItem = new SfxStringItem( nSlotId, sTemp );
1192 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
1194 ItemStatus aItemStatus;
1195 rEvent.State >>= aItemStatus;
1196 eState = aItemStatus.State;
1197 pItem = new SfxVoidItem( nSlotId );
1199 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
1201 Visibility aVisibilityStatus;
1202 rEvent.State >>= aVisibilityStatus;
1203 pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
1205 else
1207 if ( pSlot )
1208 pItem = pSlot->GetType()->CreateItem();
1209 if ( pItem )
1211 pItem->SetWhich( nSlotId );
1212 pItem->PutValue( rEvent.State );
1214 else
1215 pItem = new SfxVoidItem( nSlotId );
1219 if ( m_pCallee )
1220 m_pCallee->StateChanged( nSlotId, eState, pItem );
1221 delete pItem;
1226 //--------------------------------------------------------------------
1228 SfxPopupWindow::SfxPopupWindow(
1229 USHORT nId,
1230 const Reference< XFrame >& rFrame,
1231 WinBits nBits ) :
1232 FloatingWindow( SFX_APP()->GetTopWindow(), nBits )
1233 , m_bFloating(FALSE)
1234 , m_bCascading( FALSE )
1235 , m_nId( nId )
1236 , m_xFrame( rFrame )
1237 , m_pStatusListener( 0 )
1239 m_xServiceManager = ::comphelper::getProcessServiceFactory();
1241 Window* pWindow = GetTopMostParentSystemWindow( this );
1242 if ( pWindow )
1243 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1246 //--------------------------------------------------------------------
1248 SfxPopupWindow::SfxPopupWindow(
1249 USHORT nId,
1250 const Reference< XFrame >& rFrame,
1251 const ResId &rId ) :
1252 FloatingWindow( SFX_APP()->GetTopWindow(), rId )
1253 , m_bFloating(FALSE)
1254 , m_bCascading( FALSE )
1255 , m_nId( nId )
1256 , m_xFrame( rFrame )
1257 , m_pStatusListener( 0 )
1259 m_xServiceManager = ::comphelper::getProcessServiceFactory();
1261 Window* pWindow = GetTopMostParentSystemWindow( this );
1262 if ( pWindow )
1263 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1266 //--------------------------------------------------------------------
1268 SfxPopupWindow::SfxPopupWindow(
1269 USHORT nId,
1270 const Reference< XFrame >& rFrame,
1271 Window* pParentWindow,
1272 WinBits nBits ) :
1273 FloatingWindow( pParentWindow, nBits )
1274 , m_bFloating(FALSE)
1275 , m_bCascading( FALSE )
1276 , m_nId( nId )
1277 , m_xFrame( rFrame )
1278 , m_pStatusListener( 0 )
1280 m_xServiceManager = ::comphelper::getProcessServiceFactory();
1282 Window* pWindow = GetTopMostParentSystemWindow( this );
1283 if ( pWindow )
1284 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1287 //--------------------------------------------------------------------
1289 SfxPopupWindow::SfxPopupWindow(
1290 USHORT nId,
1291 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
1292 Window* pParentWindow,
1293 const ResId &rId ) :
1294 FloatingWindow( pParentWindow, rId )
1295 , m_bFloating(FALSE)
1296 , m_bCascading( FALSE )
1297 , m_nId( nId )
1298 , m_xFrame( rFrame )
1299 , m_pStatusListener( 0 )
1301 m_xServiceManager = ::comphelper::getProcessServiceFactory();
1303 Window* pWindow = GetTopMostParentSystemWindow( this );
1304 if ( pWindow )
1305 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1308 //--------------------------------------------------------------------
1310 SfxPopupWindow::~SfxPopupWindow()
1312 if ( m_xStatusListener.is() )
1314 m_xStatusListener->dispose();
1315 m_xStatusListener.clear();
1318 Window* pWindow = GetTopMostParentSystemWindow( this );
1319 if ( pWindow )
1320 ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( this );
1323 //--------------------------------------------------------------------
1325 SfxFrameStatusListener* SfxPopupWindow::GetOrCreateStatusListener()
1327 if ( !m_xStatusListener.is() )
1329 m_pStatusListener = new SfxFrameStatusListener(
1330 m_xServiceManager,
1331 m_xFrame,
1332 this );
1333 m_xStatusListener = Reference< XComponent >( static_cast< cppu::OWeakObject* >(
1334 m_pStatusListener ), UNO_QUERY );
1337 return m_pStatusListener;
1340 //--------------------------------------------------------------------
1342 void SfxPopupWindow::BindListener()
1344 GetOrCreateStatusListener();
1345 if ( m_xStatusListener.is() )
1346 m_pStatusListener->bindListener();
1349 //--------------------------------------------------------------------
1351 void SfxPopupWindow::UnbindListener()
1353 GetOrCreateStatusListener();
1354 if ( m_xStatusListener.is() )
1355 m_pStatusListener->unbindListener();
1358 //--------------------------------------------------------------------
1360 void SfxPopupWindow::AddStatusListener( const rtl::OUString& rCommandURL )
1362 GetOrCreateStatusListener();
1363 if ( m_xStatusListener.is() )
1364 m_pStatusListener->addStatusListener( rCommandURL );
1367 //--------------------------------------------------------------------
1369 void SfxPopupWindow::RemoveStatusListener( const rtl::OUString& rCommandURL )
1371 GetOrCreateStatusListener();
1372 if ( m_xStatusListener.is() )
1373 m_pStatusListener->removeStatusListener( rCommandURL );
1376 //--------------------------------------------------------------------
1378 void SfxPopupWindow::UpdateStatus( const rtl::OUString& rCommandURL )
1380 GetOrCreateStatusListener();
1381 if ( m_xStatusListener.is() )
1382 m_pStatusListener->updateStatus( rCommandURL );
1385 //--------------------------------------------------------------------
1387 BOOL SfxPopupWindow::Close()
1389 m_bFloating = FALSE;
1390 FloatingWindow::Close();
1392 Delete(0);
1393 return TRUE;
1396 //--------------------------------------------------------------------
1398 void SfxPopupWindow::PopupModeEnd()
1400 //! to allow PopupModeEndHdl to be called
1401 FloatingWindow::PopupModeEnd();
1403 if ( IsVisible() )
1405 // wurde abgerissen
1406 DeleteFloatingWindow();
1407 m_bFloating = TRUE;
1409 else
1410 Close();
1413 //--------------------------------------------------------------------
1415 void SfxPopupWindow::DeleteFloatingWindow()
1417 if ( m_bFloating )
1419 Hide();
1420 Delete(0);
1424 //--------------------------------------------------------------------
1426 void SfxPopupWindow::MouseMove( const ::MouseEvent& rMEvt )
1428 if ( m_bCascading == FALSE )
1429 FloatingWindow::MouseMove( rMEvt );
1430 else
1432 // MouseMove-Event an die Children forwarden
1433 ::Point aPos = rMEvt.GetPosPixel();
1434 ::Point aScrPos = OutputToScreenPixel( aPos );
1435 USHORT i = 0;
1436 Window* pWindow = GetChild( i );
1437 while ( pWindow )
1439 ::MouseEvent aMEvt( pWindow->ScreenToOutputPixel( aScrPos ),
1440 rMEvt.GetClicks(), rMEvt.GetMode(),
1441 rMEvt.GetButtons(), rMEvt.GetModifier() );
1442 pWindow->MouseMove( rMEvt );
1443 pWindow->Update();
1444 i++;
1445 pWindow = GetChild( i );
1450 //--------------------------------------------------------------------
1452 void SfxPopupWindow::StartCascading()
1454 m_bCascading= TRUE;
1457 void SfxPopupWindow::EndCascading()
1459 m_bCascading = FALSE;
1462 //--------------------------------------------------------------------
1464 SfxPopupWindow* SfxPopupWindow::Clone() const
1466 /* [Beschreibung]
1468 Diese Methode mu\s "uberladen werden, um dieses Popup auch im
1469 Presentations-Modus anzuzeigen. Sie wird gerufen, wenn ein Show()
1470 sinnlos w"are, da der Parent nicht das Presentations-Window ist.
1471 Beim neu erzeugen wird automatisch das neue Top-Window verwendet, so
1472 da\s der Parent das Presentations-Window ist und das neue Popup somit
1473 sichtbar ist.
1477 return 0;
1480 //--------------------------------------------------------------------
1482 void SfxPopupWindow::StateChanged(
1483 USHORT /*nSID*/,
1484 SfxItemState eState,
1485 const SfxPoolItem* /*pState*/ )
1486 /* [Bescheibung]
1488 Siehe auch <SfxControllerItem::StateChanged()>. Au\serdem wird
1489 bei eState==SFX_ITEM_DISABLED das Popup gehided und in allen anderen
1490 F"allen, falls es floating ist, wieder angezeigt. Daher mu\s die
1491 Basisklasse i.d.R. gerufen werden.
1493 Es findet wegen des Parents eine Sonderbehandlung f"ur den
1494 Presentationsmodus statt.
1499 if ( SFX_ITEM_DISABLED == eState )
1501 Hide();
1503 else if ( m_bFloating )
1505 Show( TRUE, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
1509 //--------------------------------------------------------------------
1511 IMPL_LINK( SfxPopupWindow, Delete, void *, EMPTYARG )
1513 if ( m_aDeleteLink.IsSet() )
1514 m_aDeleteLink.Call( this );
1515 delete this;
1516 return 0;
1519 //--------------------------------------------------------------------
1521 SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( USHORT nSlotId, USHORT nId, ToolBox& rBox )
1522 : SfxToolBoxControl( nSlotId, nId, rBox )
1523 , bBigImages( FALSE )
1524 , pMenu( 0 )
1526 rBox.SetHelpId( nId, HID_TBXCONTROL_FILENEW );
1527 rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN);
1529 // Determine the current background color of the menus
1530 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1531 m_nSymbolsStyle = rSettings.GetSymbolsStyle();
1532 m_bWasHiContrastMode = rSettings.GetMenuColor().IsDark();
1533 m_bShowMenuImages = rSettings.GetUseImagesInMenus();
1535 SetImage( String() );
1538 SfxAppToolBoxControl_Impl::~SfxAppToolBoxControl_Impl()
1540 delete pMenu;
1543 //_____________________________________________________
1545 it return the existing state of the given URL in the popupmenu of this toolbox control.
1547 If the given URL can be located as an action command of one menu item of the
1548 popup menu of this control, we return TRUE. Otherwhise we return FALSE.
1549 Further we return a fallback URL, in case we have to return FALSE. Because
1550 the outside code must select a valid item of the popup menu everytime ...
1551 and we define it here. By the way this m ethod was written to handle
1552 error situations gracefully. E.g. it can be called during creation time
1553 but then we have no valid menu. For this case we know another fallback URL.
1554 Then we return the private:factory/ URL of the default factory.
1556 @param *pMenu
1557 pounts to the popup menu, on which item we try to locate the given URL
1558 Can be NULL! Search will be supressed then.
1560 @param sURL
1561 the URL for searching
1563 @param pFallback
1564 contains the fallback URL in case we return FALSE
1565 Must point to valid memory!
1567 @param pImage
1568 contains the image of the menu for the URL.
1570 @return TRUE - if URL could be located as an item of the popup menu.
1571 FALSE - otherwhise.
1573 BOOL Impl_ExistURLInMenu( const PopupMenu *pMenu ,
1574 String &sURL ,
1575 String *pFallback ,
1576 Image *pImage )
1578 BOOL bValidFallback = FALSE;
1579 if (pMenu && sURL.Len())
1581 USHORT c = pMenu->GetItemCount();
1582 for (USHORT p=0; p<c; ++p)
1584 USHORT nId = pMenu->GetItemId(p);
1585 String aCmd( pMenu->GetItemCommand(nId) );
1587 if (!bValidFallback && aCmd.Len())
1589 *pFallback = aCmd;
1590 bValidFallback = TRUE;
1593 if (aCmd.Search(sURL)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667#
1595 sURL = aCmd;
1596 *pImage = pMenu->GetItemImage( nId );
1597 return TRUE;
1602 if (!bValidFallback)
1604 *pFallback = DEFINE_CONST_UNICODE("private:factory/");
1605 *pFallback += String(SvtModuleOptions().GetDefaultModuleName());
1608 return FALSE;
1611 long Select_Impl( void* pHdl, void* pVoid );
1613 SfxPopupWindow* SfxAppToolBoxControl_Impl::CreatePopupWindow()
1615 ToolBox& rBox = GetToolBox();
1616 ::Rectangle aRect( rBox.GetItemRect( GetId() ) );
1618 if ( !pMenu )
1620 ::framework::MenuConfiguration aConf( m_xServiceManager );
1621 if ( m_aCommandURL.equalsAscii( ".uno:AddDirect" ))
1622 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
1623 else
1624 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
1627 if ( pMenu )
1629 pMenu->SetSelectHdl( Link( NULL, Select_Impl ) );
1630 pMenu->SetActivateHdl( LINK( this, SfxAppToolBoxControl_Impl, Activate ));
1631 rBox.SetItemDown( GetId(), TRUE );
1632 USHORT nSelected = pMenu->Execute( &rBox, aRect, POPUPMENU_EXECUTE_DOWN );
1633 if ( nSelected )
1635 aLastURL = pMenu->GetItemCommand( nSelected );
1636 SetImage( pMenu->GetItemCommand( nSelected ) );
1639 rBox.SetItemDown( GetId(), FALSE );
1642 return 0;
1645 void SfxAppToolBoxControl_Impl::SetImage( const String &rURL )
1647 /* We accept URL's here only, which exist as items of our internal popup menu.
1648 All other ones will be ignored and a fallback is used ... */
1649 String aURL = rURL;
1650 String sFallback;
1651 Image aMenuImage;
1652 BOOL bValid = Impl_ExistURLInMenu(pMenu,aURL,&sFallback,&aMenuImage);
1653 if (!bValid)
1654 aURL = sFallback;
1656 BOOL bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
1657 BOOL bHC = GetToolBox().GetBackground().GetColor().IsDark();
1658 Image aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL ), bBig, bHC );
1659 if ( !aImage )
1660 aImage = !!aMenuImage ? aMenuImage :
1661 SvFileInformationManager::GetImage( INetURLObject( aURL ), bBig, bHC );
1662 Size aBigSize( GetToolBox().GetDefaultImageSize() );
1663 if ( bBig && aImage.GetSizePixel() != aBigSize )
1665 BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
1666 aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
1667 GetToolBox().SetItemImage( GetId(), Image( aScaleBmpEx ) );
1669 else
1670 GetToolBox().SetItemImage( GetId(), aImage );
1671 aLastURL = aURL;
1674 void SfxAppToolBoxControl_Impl::StateChanged
1676 USHORT nSlotId,
1677 SfxItemState eState,
1678 const SfxPoolItem* pState
1681 if ( pState && pState->ISA(SfxStringItem) )
1683 // Important step for following SetImage() call!
1684 // It needs the valid pMenu item to fullfill it's specification
1685 // to check for supported URLs ...
1686 if ( !pMenu )
1688 ::framework::MenuConfiguration aConf( m_xServiceManager );
1689 // This toolbox controller is used for two popup menus (new documents and wizards!). Create the correct
1690 // popup menu according to the slot ID our controller has been initialized with.
1691 if ( nSlotId == SID_NEWDOCDIRECT )
1692 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
1693 else
1694 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
1697 GetToolBox().EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
1698 SetImage(((const SfxStringItem*)pState)->GetValue());
1700 else
1701 SfxToolBoxControl::StateChanged( nSlotId, eState, pState );
1704 //--------------------------------------------------------------------
1706 void SfxAppToolBoxControl_Impl::Select( BOOL bMod1 )
1708 if( aLastURL.Len() )
1710 URL aTargetURL;
1711 Reference< XDispatch > xDispatch;
1712 Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
1714 if ( xDispatchProvider.is() )
1716 aTargetURL.Complete = aLastURL;
1717 getURLTransformer()->parseStrict( aTargetURL );
1719 ::rtl::OUString aTarget( ::rtl::OUString::createFromAscii( "_default" ));
1720 if ( pMenu )
1722 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1723 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
1725 if ( pMenuAttributes )
1726 aTarget = pMenuAttributes->aTargetFrame;
1729 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
1731 if ( xDispatch.is() )
1733 Sequence< PropertyValue > aArgs( 1 );
1735 aArgs[0].Name = ::rtl::OUString::createFromAscii( "Referer" );
1736 aArgs[0].Value = makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER ));
1738 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1739 pExecuteInfo->xDispatch = xDispatch;
1740 pExecuteInfo->aTargetURL = aTargetURL;
1741 pExecuteInfo->aArgs = aArgs;
1742 Application::PostUserEvent( STATIC_LINK(0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
1746 else
1747 SfxToolBoxControl::Select( bMod1 );
1750 //--------------------------------------------------------------------
1751 long Select_Impl( void* /*pHdl*/, void* pVoid )
1753 Menu* pMenu = (Menu*)pVoid;
1754 String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) );
1756 if( !aURL.Len() )
1757 return 0;
1759 Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop =
1760 Reference < ::com::sun::star::frame::XFramesSupplier >( ::comphelper::getProcessServiceFactory()->createInstance(
1761 DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
1762 Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop, UNO_QUERY );
1764 URL aTargetURL;
1765 aTargetURL.Complete = aURL;
1766 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
1767 rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
1768 UNO_QUERY );
1769 xTrans->parseStrict( aTargetURL );
1771 Reference < XDispatchProvider > xProv( xFrame, UNO_QUERY );
1772 Reference < XDispatch > xDisp;
1773 if ( xProv.is() )
1775 if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
1776 xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 );
1777 else
1779 ::rtl::OUString aTargetFrame( ::rtl::OUString::createFromAscii( "_blank" ) );
1780 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1781 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
1783 if ( pMenuAttributes )
1784 aTargetFrame = pMenuAttributes->aTargetFrame;
1786 xDisp = xProv->queryDispatch( aTargetURL, aTargetFrame , 0 );
1790 if ( xDisp.is() )
1792 SfxAppToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppToolBoxControl_Impl::ExecuteInfo;
1793 pExecuteInfo->xDispatch = xDisp;
1794 pExecuteInfo->aTargetURL = aTargetURL;
1795 pExecuteInfo->aArgs = Sequence< PropertyValue >();
1796 Application::PostUserEvent( STATIC_LINK( 0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
1799 return TRUE;
1802 IMPL_LINK( SfxAppToolBoxControl_Impl, Activate, Menu *, pActMenu )
1804 if ( pActMenu )
1806 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1807 ULONG nSymbolsStyle = rSettings.GetSymbolsStyle();
1808 BOOL bIsHiContrastMode = rSettings.GetMenuColor().IsDark();
1809 BOOL bShowMenuImages = rSettings.GetUseImagesInMenus();
1811 if (( nSymbolsStyle != m_nSymbolsStyle ) ||
1812 ( bIsHiContrastMode != m_bWasHiContrastMode ) ||
1813 ( bShowMenuImages != m_bShowMenuImages ))
1815 m_nSymbolsStyle = nSymbolsStyle;
1816 m_bWasHiContrastMode = bIsHiContrastMode;
1817 m_bShowMenuImages = bShowMenuImages;
1819 USHORT nCount = pActMenu->GetItemCount();
1820 for ( USHORT nSVPos = 0; nSVPos < nCount; nSVPos++ )
1822 USHORT nId = pActMenu->GetItemId( nSVPos );
1823 if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
1825 if ( bShowMenuImages )
1827 sal_Bool bImageSet = sal_False;
1828 ::rtl::OUString aImageId;
1829 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1830 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nId );
1832 if ( pMenuAttributes )
1833 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
1835 if ( aImageId.getLength() > 0 )
1837 Reference< ::com::sun::star::frame::XFrame > xFrame;
1838 Image aImage = GetImage( xFrame, aImageId, FALSE, bIsHiContrastMode );
1839 if ( !!aImage )
1841 bImageSet = sal_True;
1842 pActMenu->SetItemImage( nId, aImage );
1846 String aCmd( pActMenu->GetItemCommand( nId ) );
1847 if ( !bImageSet && aCmd.Len() )
1849 Image aImage = SvFileInformationManager::GetImage(
1850 INetURLObject(aCmd), FALSE, bIsHiContrastMode );
1851 if ( !!aImage )
1852 pActMenu->SetItemImage( nId, aImage );
1855 else
1856 pActMenu->SetItemImage( nId, Image() );
1861 return TRUE;
1864 return FALSE;
1867 //--------------------------------------------------------------------
1869 IMPL_STATIC_LINK_NOINSTANCE( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
1871 /* i62706: Don't catch all exceptions. We hide all problems here and are not able
1872 to handle them on higher levels.
1876 // Asynchronous execution as this can lead to our own destruction!
1877 // Framework can recycle our current frame and the layout manager disposes all user interface
1878 // elements if a component gets detached from its frame!
1879 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
1882 catch (const ::com::sun::star::document::CorruptedFilterConfigurationException& exFilters)
1884 throw exFilters;
1886 catch (const Exception& )
1890 delete pExecuteInfo;
1891 return 0;
1894 //--------------------------------------------------------------------
1896 void SfxAppToolBoxControl_Impl::Click( )