Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / toolbox / tbxitem.cxx
blobb8913eb5e597fd26e593e1cab2fc90669966092a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #ifdef SOLARIS
22 #include <ctime>
23 #endif
25 #include <string> // prevent conflict with STL includes
26 #include <com/sun/star/uno/Reference.h>
27 #include <com/sun/star/frame/XFrame.hpp>
28 #include <com/sun/star/awt/XPopupMenu.hpp>
29 #include <com/sun/star/awt/XWindow.hpp>
30 #include <com/sun/star/awt/XWindowPeer.hpp>
31 #include <com/sun/star/util/URL.hpp>
32 #include <com/sun/star/util/URLTransformer.hpp>
33 #include <com/sun/star/util/XURLTransformer.hpp>
34 #include <com/sun/star/frame/XController.hpp>
35 #include <com/sun/star/lang/XUnoTunnel.hpp>
36 #include <com/sun/star/document/MacroExecMode.hpp>
37 #include <com/sun/star/document/UpdateDocMode.hpp>
38 #include <com/sun/star/frame/Desktop.hpp>
39 #include <com/sun/star/frame/XComponentLoader.hpp>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <com/sun/star/beans/XPropertySet.hpp>
42 #include <com/sun/star/frame/XLayoutManager.hpp>
43 #include <com/sun/star/frame/XPopupMenuController.hpp>
44 #include <com/sun/star/frame/status/ItemStatus.hpp>
45 #include <com/sun/star/frame/status/ItemState.hpp>
46 #include <com/sun/star/ui/XUIElementFactory.hpp>
47 #include <com/sun/star/frame/XModuleManager.hpp>
48 #include <com/sun/star/container/XNameAccess.hpp>
49 #include <com/sun/star/ui/XUIFunctionListener.hpp>
50 #include <com/sun/star/ui/UIElementFactoryManager.hpp>
51 #include <com/sun/star/frame/status/Visibility.hpp>
52 #include <svl/eitem.hxx>
53 #include <svl/stritem.hxx>
54 #include <svl/intitem.hxx>
55 #include <svl/imageitm.hxx>
56 #include <svl/visitem.hxx>
57 #include <svl/urlbmk.hxx>
58 #include <vcl/toolbox.hxx>
59 #include <unotools/moduleoptions.hxx>
61 #include <svtools/imagemgr.hxx>
62 #include <comphelper/processfactory.hxx>
63 #include <framework/addonmenu.hxx>
64 #include <framework/addonsoptions.hxx>
65 #include <framework/menuconfiguration.hxx>
66 #include <framework/sfxhelperfunctions.hxx>
67 #include <vcl/taskpanelist.hxx>
68 #include <toolkit/helper/vclunohelper.hxx>
69 #include <svtools/menuoptions.hxx>
70 #include <svtools/miscopt.hxx>
72 #include <sfx2/tbxctrl.hxx>
73 #include <sfx2/mnumgr.hxx>
74 #include <sfx2/dispatch.hxx>
75 #include "fltfnc.hxx"
76 #include <sfx2/msg.hxx>
77 #include <sfx2/msgpool.hxx>
78 #include "statcach.hxx"
79 #include <sfx2/viewfrm.hxx>
80 #include "arrdecl.hxx"
81 #include "sfxtypes.hxx"
82 #include <sfx2/genlink.hxx>
83 #include "sfx2/sfxresid.hxx"
84 #include <sfx2/sfx.hrc>
85 #include <sfx2/module.hxx>
86 #include <sfx2/docfile.hxx>
87 #include <sfx2/docfac.hxx>
88 #include "referers.hxx"
89 #include <sfx2/frmhtmlw.hxx>
90 #include <sfx2/app.hxx>
91 #include <sfx2/unoctitm.hxx>
92 #include "helpid.hrc"
93 #include "workwin.hxx"
94 #include "sfx2/imgmgr.hxx"
95 #include "virtmenu.hxx"
96 #include "sfx2/imagemgr.hxx"
98 using namespace ::com::sun::star;
99 using namespace ::com::sun::star::beans;
100 using namespace ::com::sun::star::frame;
101 using namespace ::com::sun::star::frame::status;
102 using namespace ::com::sun::star::lang;
103 using namespace ::com::sun::star::uno;
104 using namespace ::com::sun::star::util;
105 using namespace ::com::sun::star::container;
106 using namespace ::com::sun::star::ui;
108 //====================================================================
110 SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True);
111 SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem);
112 SFX_IMPL_TOOLBOX_CONTROL(SfxRecentFilesToolBoxControl, SfxStringItem);
114 static Window* GetTopMostParentSystemWindow( Window* pWindow )
116 OSL_ASSERT( pWindow );
117 if ( pWindow )
119 // ->manually search topmost system window
120 // required because their might be another system window between this and the top window
121 pWindow = pWindow->GetParent();
122 SystemWindow* pTopMostSysWin = NULL;
123 while ( pWindow )
125 if ( pWindow->IsSystemWindow() )
126 pTopMostSysWin = (SystemWindow*)pWindow;
127 pWindow = pWindow->GetParent();
129 pWindow = pTopMostSysWin;
130 OSL_ASSERT( pWindow );
131 return pWindow;
134 return NULL;
137 svt::ToolboxController* SAL_CALL SfxToolBoxControllerFactory( const Reference< XFrame >& rFrame, ToolBox* pToolbox, unsigned short nID, const OUString& aCommandURL )
139 SolarMutexGuard aGuard;
141 URL aTargetURL;
142 aTargetURL.Complete = aCommandURL;
143 Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
144 xTrans->parseStrict( aTargetURL );
145 if ( !aTargetURL.Arguments.isEmpty() )
146 return NULL;
148 SfxObjectShell* pObjShell = NULL;
149 Reference < XController > xController;
150 Reference < XModel > xModel;
151 if ( rFrame.is() )
153 xController = rFrame->getController();
154 if ( xController.is() )
155 xModel = xController->getModel();
158 if ( xModel.is() )
160 // Get tunnel from model to retrieve the SfxObjectShell pointer from it
161 ::com::sun::star::uno::Reference < ::com::sun::star::lang::XUnoTunnel > xObj( xModel, UNO_QUERY );
162 if ( xObj.is() )
164 ::com::sun::star::uno::Sequence < sal_Int8 > aSeq = SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence();
165 sal_Int64 nHandle = xObj->getSomething( aSeq );
166 if ( nHandle )
167 pObjShell = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
171 SfxModule* pModule = pObjShell ? pObjShell->GetModule() : NULL;
172 SfxSlotPool* pSlotPool = 0;
174 if ( pModule )
175 pSlotPool = pModule->GetSlotPool();
176 else
177 pSlotPool = &(SfxSlotPool::GetSlotPool( NULL ));
179 const SfxSlot* pSlot = pSlotPool->GetUnoSlot( aTargetURL.Path );
180 if ( pSlot )
182 sal_uInt16 nSlotId = pSlot->GetSlotId();
183 if ( nSlotId > 0 )
184 return SfxToolBoxControl::CreateControl( nSlotId, nID, pToolbox, pModule );
187 return NULL;
190 struct SfxToolBoxControl_Impl
192 ToolBox* pBox;
193 sal_Bool bShowString;
194 sal_uInt16 nSelectModifier;
195 SfxTbxCtrlFactory* pFact;
196 sal_uInt16 nTbxId;
197 sal_uInt16 nSlotId;
198 SfxPopupWindow* mpFloatingWindow;
199 SfxPopupWindow* mpPopupWindow;
200 Reference< XUIElement > mxUIElement;
202 DECL_LINK( WindowEventListener, VclSimpleEvent* );
205 IMPL_LINK( SfxToolBoxControl_Impl, WindowEventListener, VclSimpleEvent*, pEvent )
207 if ( pEvent &&
208 pEvent->ISA( VclWindowEvent ) &&
209 (( pEvent->GetId() == VCLEVENT_WINDOW_MOVE ) ||
210 ( pEvent->GetId() == VCLEVENT_WINDOW_ACTIVATE )))
212 Window* pWindow( ((VclWindowEvent*)pEvent)->GetWindow() );
213 if (( pWindow == mpFloatingWindow ) &&
214 ( mpPopupWindow != 0 ))
216 delete mpPopupWindow;
217 mpPopupWindow = 0;
221 return 1;
224 //--------------------------------------------------------------------
226 SfxToolBoxControl::SfxToolBoxControl(
227 sal_uInt16 nSlotID,
228 sal_uInt16 nID,
229 ToolBox& rBox,
230 sal_Bool bShowStringItems )
231 : svt::ToolboxController()
233 pImpl = new SfxToolBoxControl_Impl;
235 pImpl->pBox = &rBox;
236 pImpl->bShowString = bShowStringItems;
237 pImpl->nSelectModifier = 0;
238 pImpl->pFact = 0;
239 pImpl->nTbxId = nID;
240 pImpl->nSlotId = nSlotID;
241 pImpl->mpFloatingWindow = 0;
242 pImpl->mpPopupWindow = 0;
245 //--------------------------------------------------------------------
247 SfxToolBoxControl::~SfxToolBoxControl()
249 if ( pImpl->mxUIElement.is() )
251 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
252 xComponent->dispose();
254 pImpl->mxUIElement = 0;
255 delete pImpl;
258 //--------------------------------------------------------------------
260 ToolBox& SfxToolBoxControl::GetToolBox() const
262 return *pImpl->pBox;
264 unsigned short SfxToolBoxControl::GetId() const
266 return pImpl->nTbxId;
268 unsigned short SfxToolBoxControl::GetSlotId() const
270 return pImpl->nSlotId;
273 //--------------------------------------------------------------------
275 void SAL_CALL SfxToolBoxControl::dispose() throw (::com::sun::star::uno::RuntimeException)
277 if ( m_bDisposed )
278 return;
280 svt::ToolboxController::dispose();
282 // Remove and destroy our item window at our toolbox
283 SolarMutexGuard aGuard;
284 Window* pWindow = pImpl->pBox->GetItemWindow( pImpl->nTbxId );
285 pImpl->pBox->SetItemWindow( pImpl->nTbxId, 0 );
286 delete pWindow;
288 // Dispose an open sub toolbar. It's possible that we have an open
289 // sub toolbar while we get disposed. Therefore we have to dispose
290 // it now! Not doing so would result in a crash. The sub toolbar
291 // gets destroyed asynchronously and would access a non-existing
292 // parent toolbar!
293 if ( pImpl->mxUIElement.is() )
295 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
296 xComponent->dispose();
298 pImpl->mxUIElement = 0;
300 // Delete my popup windows
301 delete pImpl->mpFloatingWindow;
302 delete pImpl->mpPopupWindow;
304 pImpl->mpFloatingWindow = 0;
305 pImpl->mpPopupWindow = 0;
308 //--------------------------------------------------------------------
309 void SfxToolBoxControl::RegisterToolBoxControl( SfxModule* pMod, SfxTbxCtrlFactory* pFact)
311 SFX_APP()->RegisterToolBoxControl_Impl( pMod, pFact );
314 SfxToolBoxControl* SfxToolBoxControl::CreateControl( sal_uInt16 nSlotId, sal_uInt16 nTbxId, ToolBox *pBox, SfxModule* pMod )
316 SolarMutexGuard aGuard;
318 SfxToolBoxControl *pCtrl;
319 SfxApplication *pApp = SFX_APP();
321 SfxSlotPool *pSlotPool;
322 if ( pMod )
323 pSlotPool = pMod->GetSlotPool();
324 else
325 pSlotPool = &SfxSlotPool::GetSlotPool();
326 TypeId aSlotType = pSlotPool->GetSlotType( nSlotId );
327 if ( aSlotType )
329 if ( pMod )
331 SfxTbxCtrlFactArr_Impl *pFactories = pMod->GetTbxCtrlFactories_Impl();
332 if ( pFactories )
334 SfxTbxCtrlFactArr_Impl &rFactories = *pFactories;
335 sal_uInt16 nFactory;
336 const sal_uInt16 nCount = rFactories.size();
338 // search for a factory with the given slot id
339 for( nFactory = 0; nFactory < nCount; ++nFactory )
340 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
341 break;
343 if( nFactory == nCount )
345 // if no factory exists for the given slot id, see if we
346 // have a generic factory with the correct slot type and slot id == 0
347 for ( nFactory = 0; nFactory < nCount; ++nFactory )
348 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
349 break;
352 if( nFactory < nCount )
354 pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
355 pCtrl->pImpl->pFact = rFactories[nFactory];
356 return pCtrl;
361 SfxTbxCtrlFactArr_Impl &rFactories = pApp->GetTbxCtrlFactories_Impl();
362 sal_uInt16 nFactory;
363 const sal_uInt16 nCount = rFactories.size();
365 for( nFactory = 0; nFactory < nCount; ++nFactory )
366 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == nSlotId) )
367 break;
369 if( nFactory == nCount )
371 // if no factory exists for the given slot id, see if we
372 // have a generic factory with the correct slot type and slot id == 0
373 for( nFactory = 0; nFactory < nCount; ++nFactory )
374 if( (rFactories[nFactory]->nTypeId == aSlotType) && (rFactories[nFactory]->nSlotId == 0) )
375 break;
378 if( nFactory < nCount )
380 pCtrl = rFactories[nFactory]->pCtor( nSlotId, nTbxId, *pBox );
381 pCtrl->pImpl->pFact = rFactories[nFactory];
382 return pCtrl;
386 return NULL;
389 SfxItemState SfxToolBoxControl::GetItemState(
390 const SfxPoolItem* pState )
391 /* [Description]
393 Static method for determining the status of the SfxPoolItem-pointer,
394 used in the method <SfxControllerItem::StateChanged(const SfxPoolItem*)>.
396 [Return value]
398 SfxItemState SFX_ITEM_UNKNOWN
399 Enabled, however no further status information is available.
400 Typical for <Slot>s, which are temporarily disabled a
401 anyway but other than that do not change their appearance.
403 SFX_ITEM_DISABLED
404 Disabled, no further status information is available.
405 All other displayed values should be reset to the default
406 if possible.
408 SFX_ITEM_DONTCARE
409 Enabled but there were only ambiguous values available
410 (i.e. none that could be queried).
412 SFX_ITEM_AVAILABLE
413 Enabled and with available values which can be queried
414 through'pState'. The type is thus by the Slot clearly
415 defined in the entire Program.
419 return !pState
420 ? SFX_ITEM_DISABLED
421 : IsInvalidItem(pState)
422 ? SFX_ITEM_DONTCARE
423 : pState->ISA(SfxVoidItem) && !pState->Which()
424 ? SFX_ITEM_UNKNOWN
425 : SFX_ITEM_AVAILABLE;
428 void SfxToolBoxControl::Dispatch(
429 const Reference< XDispatchProvider >& rProvider,
430 const OUString& rCommand,
431 Sequence< ::PropertyValue >& aArgs )
433 if ( rProvider.is() )
435 ::com::sun::star::util::URL aTargetURL;
436 aTargetURL.Complete = rCommand;
437 Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
438 xTrans->parseStrict( aTargetURL );
440 Reference < XDispatch > xDispatch = rProvider->queryDispatch( aTargetURL, OUString(), 0 );
441 if ( xDispatch.is() )
442 xDispatch->dispatch( aTargetURL, aArgs );
446 void SfxToolBoxControl::Dispatch( const OUString& aCommand, ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs )
448 Reference < XController > xController;
450 SolarMutexGuard aGuard;
451 if ( getFrameInterface().is() )
452 xController = getFrameInterface()->getController();
454 Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
455 if ( xProvider.is() )
457 ::com::sun::star::util::URL aTargetURL;
458 aTargetURL.Complete = aCommand;
459 getURLTransformer()->parseStrict( aTargetURL );
461 Reference < XDispatch > xDispatch = xProvider->queryDispatch( aTargetURL, OUString(), 0 );
462 if ( xDispatch.is() )
463 xDispatch->dispatch( aTargetURL, aArgs );
467 // XInterface
468 Any SAL_CALL SfxToolBoxControl::queryInterface( const Type & rType )
469 throw(::com::sun::star::uno::RuntimeException)
471 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
472 (static_cast< ::com::sun::star::awt::XDockableWindowListener* >(this)),
473 (static_cast< ::com::sun::star::frame::XSubToolbarController* >(this)));
474 return (aRet.hasValue() ? aRet : svt::ToolboxController::queryInterface( rType ));
477 void SAL_CALL SfxToolBoxControl::acquire() throw()
479 OWeakObject::acquire();
482 void SAL_CALL SfxToolBoxControl::release() throw()
484 OWeakObject::release();
487 void SAL_CALL SfxToolBoxControl::disposing( const ::com::sun::star::lang::EventObject& aEvent )
488 throw( ::com::sun::star::uno::RuntimeException )
490 svt::ToolboxController::disposing( aEvent );
493 // XStatusListener
494 void SAL_CALL SfxToolBoxControl::statusChanged( const FeatureStateEvent& rEvent )
495 throw ( ::com::sun::star::uno::RuntimeException )
497 SfxViewFrame* pViewFrame = NULL;
498 Reference < XController > xController;
500 SolarMutexGuard aGuard;
501 if ( getFrameInterface().is() )
502 xController = getFrameInterface()->getController();
504 Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
505 if ( xProvider.is() )
507 Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, OUString(), 0 );
508 if ( xDisp.is() )
510 Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
511 SfxOfficeDispatch* pDisp = NULL;
512 if ( xTunnel.is() )
514 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
515 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
518 if ( pDisp )
519 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
523 sal_uInt16 nSlotId = 0;
524 SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
525 const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
526 if ( pSlot )
527 nSlotId = pSlot->GetSlotId();
528 else if ( m_aCommandURL == rEvent.FeatureURL.Path )
529 nSlotId = GetSlotId();
531 if ( nSlotId > 0 )
533 if ( rEvent.Requery )
534 svt::ToolboxController::statusChanged( rEvent );
535 else
537 SfxItemState eState = SFX_ITEM_DISABLED;
538 SfxPoolItem* pItem = NULL;
539 if ( rEvent.IsEnabled )
541 eState = SFX_ITEM_AVAILABLE;
542 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
544 if ( pType == ::getVoidCppuType() )
546 pItem = new SfxVoidItem( nSlotId );
547 eState = SFX_ITEM_UNKNOWN;
549 else if ( pType == ::getBooleanCppuType() )
551 sal_Bool bTemp = false;
552 rEvent.State >>= bTemp ;
553 pItem = new SfxBoolItem( nSlotId, bTemp );
555 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
557 sal_uInt16 nTemp = 0;
558 rEvent.State >>= nTemp ;
559 pItem = new SfxUInt16Item( nSlotId, nTemp );
561 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
563 sal_uInt32 nTemp = 0;
564 rEvent.State >>= nTemp ;
565 pItem = new SfxUInt32Item( nSlotId, nTemp );
567 else if ( pType == ::getCppuType((const OUString*)0) )
569 OUString sTemp ;
570 rEvent.State >>= sTemp ;
571 pItem = new SfxStringItem( nSlotId, sTemp );
573 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
575 ItemStatus aItemStatus;
576 rEvent.State >>= aItemStatus;
577 eState = aItemStatus.State;
578 pItem = new SfxVoidItem( nSlotId );
580 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
582 Visibility aVisibilityStatus;
583 rEvent.State >>= aVisibilityStatus;
584 pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
586 else
588 if ( pSlot )
589 pItem = pSlot->GetType()->CreateItem();
590 if ( pItem )
592 pItem->SetWhich( nSlotId );
593 pItem->PutValue( rEvent.State );
595 else
596 pItem = new SfxVoidItem( nSlotId );
600 StateChanged( nSlotId, eState, pItem );
601 delete pItem;
606 // XSubToolbarController
607 ::sal_Bool SAL_CALL SfxToolBoxControl::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException)
609 return sal_False;
612 OUString SAL_CALL SfxToolBoxControl::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException)
614 return OUString();
617 void SAL_CALL SfxToolBoxControl::functionSelected( const OUString& /*aCommand*/ ) throw (::com::sun::star::uno::RuntimeException)
619 // must be implemented by sub-class
622 void SAL_CALL SfxToolBoxControl::updateImage() throw (::com::sun::star::uno::RuntimeException)
624 // must be implemented by sub-class
627 // XToolbarController
628 void SAL_CALL SfxToolBoxControl::execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException)
630 SolarMutexGuard aGuard;
631 Select( (sal_uInt16)KeyModifier );
633 void SAL_CALL SfxToolBoxControl::click() throw (::com::sun::star::uno::RuntimeException)
635 SolarMutexGuard aGuard;
636 Click();
639 void SAL_CALL SfxToolBoxControl::doubleClick() throw (::com::sun::star::uno::RuntimeException)
641 SolarMutexGuard aGuard;
642 DoubleClick();
645 Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createPopupWindow() throw (::com::sun::star::uno::RuntimeException)
647 SolarMutexGuard aGuard;
648 Window* pWindow = CreatePopupWindow();
649 if ( pWindow )
650 return VCLUnoHelper::GetInterface( pWindow );
651 else
652 return Reference< ::com::sun::star::awt::XWindow >();
655 Reference< ::com::sun::star::awt::XWindow > SAL_CALL SfxToolBoxControl::createItemWindow( const Reference< ::com::sun::star::awt::XWindow >& rParent ) throw (::com::sun::star::uno::RuntimeException)
657 SolarMutexGuard aGuard;
658 return VCLUnoHelper::GetInterface( CreateItemWindow( VCLUnoHelper::GetWindow( rParent )));
661 // XDockableWindowListener
662 void SAL_CALL SfxToolBoxControl::startDocking( const ::com::sun::star::awt::DockingEvent& )
663 throw (::com::sun::star::uno::RuntimeException)
666 ::com::sun::star::awt::DockingData SAL_CALL SfxToolBoxControl::docking( const ::com::sun::star::awt::DockingEvent& )
667 throw (::com::sun::star::uno::RuntimeException)
669 return ::com::sun::star::awt::DockingData();
672 void SAL_CALL SfxToolBoxControl::endDocking( const ::com::sun::star::awt::EndDockingEvent& )
673 throw (::com::sun::star::uno::RuntimeException)
677 sal_Bool SAL_CALL SfxToolBoxControl::prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject& )
678 throw (::com::sun::star::uno::RuntimeException)
680 return sal_False;
683 void SAL_CALL SfxToolBoxControl::toggleFloatingMode( const ::com::sun::star::lang::EventObject& )
684 throw (::com::sun::star::uno::RuntimeException)
688 void SAL_CALL SfxToolBoxControl::closed( const ::com::sun::star::lang::EventObject& )
689 throw (::com::sun::star::uno::RuntimeException)
693 void SAL_CALL SfxToolBoxControl::endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent& aEvent )
694 throw (::com::sun::star::uno::RuntimeException)
696 SolarMutexGuard aGuard;
698 OUString aSubToolBarResName;
699 if ( pImpl->mxUIElement.is() )
701 Reference< XPropertySet > xPropSet( pImpl->mxUIElement, UNO_QUERY );
702 if ( xPropSet.is() )
706 xPropSet->getPropertyValue( OUString( "ResourceURL" )) >>= aSubToolBarResName;
708 catch ( com::sun::star::beans::UnknownPropertyException& )
711 catch ( com::sun::star::lang::WrappedTargetException& )
716 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
717 xComponent->dispose();
719 pImpl->mxUIElement = 0;
721 // if the toolbar was teared-off recreate it and place it at the given position
722 if( aEvent.bTearoff )
724 Reference< XUIElement > xUIElement;
725 Reference< XLayoutManager > xLayoutManager = getLayoutManager();
727 if ( !xLayoutManager.is() )
728 return;
730 xLayoutManager->createElement( aSubToolBarResName );
731 xUIElement = xLayoutManager->getElement( aSubToolBarResName );
732 if ( xUIElement.is() )
734 Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
736 Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
737 Reference< ::com::sun::star::beans::XPropertySet > xProp( xUIElement, UNO_QUERY );
738 if ( xSubToolBar.is() && xProp.is() )
740 OUString aPersistentString( "Persistent" );
743 Window* pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
744 if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
746 Any a;
747 a = xProp->getPropertyValue( aPersistentString );
748 xProp->setPropertyValue( aPersistentString, makeAny( sal_False ));
750 xLayoutManager->hideElement( aSubToolBarResName );
751 xLayoutManager->floatWindow( aSubToolBarResName );
753 xLayoutManager->setElementPos( aSubToolBarResName, aEvent.FloatingPosition );
754 xLayoutManager->showElement( aSubToolBarResName );
756 xProp->setPropertyValue( OUString( "Persistent" ), a );
759 catch ( ::com::sun::star::uno::RuntimeException& )
761 throw;
763 catch ( ::com::sun::star::uno::Exception& )
771 ::Size SfxToolBoxControl::getPersistentFloatingSize( const Reference< XFrame >& /*xFrame*/, const OUString& /*rSubToolBarResName*/ )
773 ::Size aToolboxSize;
774 return aToolboxSize;
777 void SfxToolBoxControl::createAndPositionSubToolBar( const OUString& rSubToolBarResName )
779 SolarMutexGuard aGuard;
781 if ( pImpl->pBox )
783 static WeakReference< XUIElementFactoryManager > xWeakUIElementFactory;
785 sal_uInt16 nItemId = pImpl->pBox->GetDownItemId();
787 if ( !nItemId )
788 return;
790 // create element with factory
791 Reference< XFrame > xFrame = getFrameInterface();
792 Reference< XUIElement > xUIElement;
793 Reference< XUIElementFactoryManager > xUIElementFactory;
795 xUIElementFactory = xWeakUIElementFactory;
796 if ( !xUIElementFactory.is() )
798 xUIElementFactory = UIElementFactoryManager::create( m_xContext );
799 xWeakUIElementFactory = xUIElementFactory;
802 Sequence< PropertyValue > aPropSeq( 3 );
803 aPropSeq[0].Name = OUString( "Frame" );
804 aPropSeq[0].Value <<= xFrame;
805 aPropSeq[1].Name = OUString( "Persistent" );
806 aPropSeq[1].Value <<= sal_False;
807 aPropSeq[2].Name = OUString( "PopupMode" );
808 aPropSeq[2].Value <<= sal_True;
812 xUIElement = xUIElementFactory->createUIElement( rSubToolBarResName, aPropSeq );
814 catch ( ::com::sun::star::container::NoSuchElementException& )
817 catch ( IllegalArgumentException& )
821 if ( xUIElement.is() )
823 Reference< ::com::sun::star::awt::XWindow > xParent = getFrameInterface()->getContainerWindow();
825 Reference< ::com::sun::star::awt::XWindow > xSubToolBar( xUIElement->getRealInterface(), UNO_QUERY );
826 if ( xSubToolBar.is() )
828 Reference< ::com::sun::star::awt::XDockableWindow > xDockWindow( xSubToolBar, UNO_QUERY );
829 xDockWindow->addDockableWindowListener( Reference< ::com::sun::star::awt::XDockableWindowListener >(
830 static_cast< OWeakObject * >( this ), UNO_QUERY ));
831 xDockWindow->enableDocking( sal_True );
833 // keep refererence to UIElement to avoid its destruction
834 if ( pImpl->mxUIElement.is() )
836 Reference< XComponent > xComponent( pImpl->mxUIElement, UNO_QUERY );
837 xComponent->dispose();
839 pImpl->mxUIElement = xUIElement;
841 Window* pParentTbxWindow( pImpl->pBox );
842 Window* pTbxWindow = VCLUnoHelper::GetWindow( xSubToolBar );
843 ToolBox* pToolBar( 0 );
844 if ( pTbxWindow && pTbxWindow->GetType() == WINDOW_TOOLBOX )
845 pToolBar = (ToolBox *)pTbxWindow;
847 if ( pToolBar )
849 pToolBar->SetParent( pParentTbxWindow );
850 ::Size aSize = getPersistentFloatingSize( xFrame, rSubToolBarResName );
851 if ( aSize.Width() == 0 || aSize.Height() == 0 )
853 // calc and set size for popup mode
854 aSize = pToolBar->CalcPopupWindowSizePixel();
856 pToolBar->SetSizePixel( aSize );
858 // open subtoolbox in popup mode
859 Window::GetDockingManager()->StartPopupMode( pImpl->pBox, pToolBar );
866 //--------------------------------------------------------------------
868 void SfxToolBoxControl::SetPopupWindow( SfxPopupWindow* pWindow )
870 pImpl->mpPopupWindow = pWindow;
871 pImpl->mpPopupWindow->SetPopupModeEndHdl( LINK( this, SfxToolBoxControl, PopupModeEndHdl ));
872 pImpl->mpPopupWindow->SetDeleteLink_Impl( LINK( this, SfxToolBoxControl, ClosePopupWindow ));
875 //--------------------------------------------------------------------
877 IMPL_LINK_NOARG(SfxToolBoxControl, PopupModeEndHdl)
879 if ( pImpl->mpPopupWindow->IsVisible() )
881 // Replace floating window with popup window and destroy
882 // floating window instance.
883 delete pImpl->mpFloatingWindow;
884 pImpl->mpFloatingWindow = pImpl->mpPopupWindow;
885 pImpl->mpPopupWindow = 0;
886 // We also need to know when the user tries to use the
887 // floating window.
888 pImpl->mpFloatingWindow->AddEventListener( LINK( pImpl, SfxToolBoxControl_Impl, WindowEventListener ));
890 else
892 // Popup window has been closed by the user. No replacement, instance
893 // will destroy itself.
894 pImpl->mpPopupWindow = 0;
897 return 1;
900 //--------------------------------------------------------------------
901 IMPL_LINK( SfxToolBoxControl, ClosePopupWindow, SfxPopupWindow *, pWindow )
903 if ( pWindow == pImpl->mpFloatingWindow )
904 pImpl->mpFloatingWindow = 0;
905 else
906 pImpl->mpPopupWindow = 0;
908 return 1;
911 //--------------------------------------------------------------------
913 void SfxToolBoxControl::StateChanged
915 sal_uInt16 nId,
916 SfxItemState eState,
917 const SfxPoolItem* pState
920 DBG_ASSERT( pImpl->pBox != 0, "setting state to dangling ToolBox" );
922 if ( GetId() >= SID_OBJECTMENU0 && GetId() <= SID_OBJECTMENU_LAST )
923 return;
925 // enabled/disabled-Flag correcting the lump sum
926 pImpl->pBox->EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
928 sal_uInt16 nItemBits = pImpl->pBox->GetItemBits( GetId() );
929 nItemBits &= ~TIB_CHECKABLE;
930 TriState eTri = STATE_NOCHECK;
931 switch ( eState )
933 case SFX_ITEM_AVAILABLE:
935 if ( pState->ISA(SfxBoolItem) )
937 // BoolItem for checking
938 if ( ((const SfxBoolItem*)pState)->GetValue() )
939 eTri = STATE_CHECK;
940 nItemBits |= TIB_CHECKABLE;
942 else if ( pState->ISA(SfxEnumItemInterface) &&
943 ((SfxEnumItemInterface *)pState)->HasBoolValue())
945 // EnumItem is handled as Bool
946 if ( ((const SfxEnumItemInterface *)pState)->GetBoolValue() )
947 eTri = STATE_CHECK;
948 nItemBits |= TIB_CHECKABLE;
950 else if ( pImpl->bShowString && pState->ISA(SfxStringItem) )
951 pImpl->pBox->SetItemText(nId, ((const SfxStringItem*)pState)->GetValue() );
952 break;
955 case SFX_ITEM_DONTCARE:
957 eTri = STATE_DONTKNOW;
958 nItemBits |= TIB_CHECKABLE;
962 pImpl->pBox->SetItemState( GetId(), eTri );
963 pImpl->pBox->SetItemBits( GetId(), nItemBits );
966 //--------------------------------------------------------------------
968 void SfxToolBoxControl::Select( sal_uInt16 nModifier )
970 pImpl->nSelectModifier = nModifier;
971 Select( sal_Bool((nModifier & KEY_MOD1)!=0) );
974 //--------------------------------------------------------------------
976 void SfxToolBoxControl::Select( sal_Bool /*bMod1*/ )
978 svt::ToolboxController::execute( pImpl->nSelectModifier );
981 //--------------------------------------------------------------------
983 void SfxToolBoxControl::DoubleClick()
987 //--------------------------------------------------------------------
989 void SfxToolBoxControl::Click()
993 //--------------------------------------------------------------------
995 SfxPopupWindowType SfxToolBoxControl::GetPopupWindowType() const
997 return SFX_POPUPWINDOW_NONE;
1000 //--------------------------------------------------------------------
1002 SfxPopupWindow* SfxToolBoxControl::CreatePopupWindow()
1004 return 0;
1007 SfxPopupWindow* SfxToolBoxControl::CreatePopupWindowCascading()
1009 return 0;
1012 //--------------------------------------------------------------------
1014 Window* SfxToolBoxControl::CreateItemWindow( Window * )
1016 return 0;
1019 //--------------------------------------------------------------------
1021 SfxFrameStatusListener::SfxFrameStatusListener(
1022 const Reference< XComponentContext >& rxContext,
1023 const Reference< XFrame >& xFrame,
1024 SfxStatusListenerInterface* pCallee ) :
1025 svt::FrameStatusListener( rxContext, xFrame ),
1026 m_pCallee( pCallee )
1030 //--------------------------------------------------------------------
1032 SfxFrameStatusListener::~SfxFrameStatusListener()
1036 //--------------------------------------------------------------------
1038 // XStatusListener
1039 void SAL_CALL SfxFrameStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent )
1040 throw ( ::com::sun::star::uno::RuntimeException )
1042 SfxViewFrame* pViewFrame = NULL;
1043 Reference < XController > xController;
1045 SolarMutexGuard aGuard;
1046 if ( m_xFrame.is() )
1047 xController = m_xFrame->getController();
1049 Reference < XDispatchProvider > xProvider( xController, UNO_QUERY );
1050 if ( xProvider.is() )
1052 Reference < XDispatch > xDisp = xProvider->queryDispatch( rEvent.FeatureURL, OUString(), 0 );
1053 if ( xDisp.is() )
1055 Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
1056 SfxOfficeDispatch* pDisp = NULL;
1057 if ( xTunnel.is() )
1059 sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
1060 pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
1063 if ( pDisp )
1064 pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
1068 sal_uInt16 nSlotId = 0;
1069 SfxSlotPool& rPool = SfxSlotPool::GetSlotPool( pViewFrame );
1070 const SfxSlot* pSlot = rPool.GetUnoSlot( rEvent.FeatureURL.Path );
1071 if ( pSlot )
1072 nSlotId = pSlot->GetSlotId();
1074 if ( nSlotId > 0 )
1076 if ( rEvent.Requery )
1078 // requery for the notified state
1079 addStatusListener( rEvent.FeatureURL.Complete );
1081 else
1083 SfxItemState eState = SFX_ITEM_DISABLED;
1084 SfxPoolItem* pItem = NULL;
1085 if ( rEvent.IsEnabled )
1087 eState = SFX_ITEM_AVAILABLE;
1088 ::com::sun::star::uno::Type pType = rEvent.State.getValueType();
1090 if ( pType == ::getVoidCppuType() )
1092 pItem = new SfxVoidItem( nSlotId );
1093 eState = SFX_ITEM_UNKNOWN;
1095 else if ( pType == ::getBooleanCppuType() )
1097 sal_Bool bTemp = false;
1098 rEvent.State >>= bTemp ;
1099 pItem = new SfxBoolItem( nSlotId, bTemp );
1101 else if ( pType == ::getCppuType((const sal_uInt16*)0) )
1103 sal_uInt16 nTemp = 0;
1104 rEvent.State >>= nTemp ;
1105 pItem = new SfxUInt16Item( nSlotId, nTemp );
1107 else if ( pType == ::getCppuType((const sal_uInt32*)0) )
1109 sal_uInt32 nTemp = 0;
1110 rEvent.State >>= nTemp ;
1111 pItem = new SfxUInt32Item( nSlotId, nTemp );
1113 else if ( pType == ::getCppuType((const OUString*)0) )
1115 OUString sTemp ;
1116 rEvent.State >>= sTemp ;
1117 pItem = new SfxStringItem( nSlotId, sTemp );
1119 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::ItemStatus*)0) )
1121 ItemStatus aItemStatus;
1122 rEvent.State >>= aItemStatus;
1123 eState = aItemStatus.State;
1124 pItem = new SfxVoidItem( nSlotId );
1126 else if ( pType == ::getCppuType((const ::com::sun::star::frame::status::Visibility*)0) )
1128 Visibility aVisibilityStatus;
1129 rEvent.State >>= aVisibilityStatus;
1130 pItem = new SfxVisibilityItem( nSlotId, aVisibilityStatus.bVisible );
1132 else
1134 if ( pSlot )
1135 pItem = pSlot->GetType()->CreateItem();
1136 if ( pItem )
1138 pItem->SetWhich( nSlotId );
1139 pItem->PutValue( rEvent.State );
1141 else
1142 pItem = new SfxVoidItem( nSlotId );
1146 if ( m_pCallee )
1147 m_pCallee->StateChanged( nSlotId, eState, pItem );
1148 delete pItem;
1153 //--------------------------------------------------------------------
1155 SfxPopupWindow::SfxPopupWindow(
1156 sal_uInt16 nId,
1157 const Reference< XFrame >& rFrame,
1158 WinBits nBits ) :
1159 FloatingWindow( SFX_APP()->GetTopWindow(), nBits )
1160 , m_bFloating(sal_False)
1161 , m_bCascading( sal_False )
1162 , m_nId( nId )
1163 , m_xFrame( rFrame )
1164 , m_pStatusListener( 0 )
1166 Window* pWindow = GetTopMostParentSystemWindow( this );
1167 if ( pWindow )
1168 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1171 //--------------------------------------------------------------------
1173 SfxPopupWindow::SfxPopupWindow(
1174 sal_uInt16 nId,
1175 const Reference< XFrame >& rFrame,
1176 const ResId &rId ) :
1177 FloatingWindow( SFX_APP()->GetTopWindow(), rId )
1178 , m_bFloating(sal_False)
1179 , m_bCascading( sal_False )
1180 , m_nId( nId )
1181 , m_xFrame( rFrame )
1182 , m_pStatusListener( 0 )
1184 Window* pWindow = GetTopMostParentSystemWindow( this );
1185 if ( pWindow )
1186 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1189 //--------------------------------------------------------------------
1191 SfxPopupWindow::SfxPopupWindow(
1192 sal_uInt16 nId,
1193 const Reference< XFrame >& rFrame,
1194 Window* pParentWindow,
1195 WinBits nBits ) :
1196 FloatingWindow( pParentWindow, nBits )
1197 , m_bFloating(sal_False)
1198 , m_bCascading( sal_False )
1199 , m_nId( nId )
1200 , m_xFrame( rFrame )
1201 , m_pStatusListener( 0 )
1203 Window* pWindow = GetTopMostParentSystemWindow( this );
1204 if ( pWindow )
1205 ((SystemWindow *)pWindow)->GetTaskPaneList()->AddWindow( this );
1208 //--------------------------------------------------------------------
1210 SfxPopupWindow::~SfxPopupWindow()
1212 if ( m_xStatusListener.is() )
1214 m_xStatusListener->dispose();
1215 m_xStatusListener.clear();
1218 Window* pWindow = GetTopMostParentSystemWindow( this );
1219 if ( pWindow )
1220 ((SystemWindow *)pWindow)->GetTaskPaneList()->RemoveWindow( this );
1223 //--------------------------------------------------------------------
1225 SfxFrameStatusListener* SfxPopupWindow::GetOrCreateStatusListener()
1227 if ( !m_xStatusListener.is() )
1229 m_pStatusListener = new SfxFrameStatusListener(
1230 ::comphelper::getProcessComponentContext(),
1231 m_xFrame,
1232 this );
1233 m_xStatusListener = Reference< XComponent >( static_cast< cppu::OWeakObject* >(
1234 m_pStatusListener ), UNO_QUERY );
1237 return m_pStatusListener;
1240 //--------------------------------------------------------------------
1242 void SfxPopupWindow::BindListener()
1244 GetOrCreateStatusListener();
1245 if ( m_xStatusListener.is() )
1246 m_pStatusListener->bindListener();
1249 //--------------------------------------------------------------------
1251 void SfxPopupWindow::UnbindListener()
1253 GetOrCreateStatusListener();
1254 if ( m_xStatusListener.is() )
1255 m_pStatusListener->unbindListener();
1258 //--------------------------------------------------------------------
1260 void SfxPopupWindow::AddStatusListener( const OUString& rCommandURL )
1262 GetOrCreateStatusListener();
1263 if ( m_xStatusListener.is() )
1264 m_pStatusListener->addStatusListener( rCommandURL );
1267 //--------------------------------------------------------------------
1269 sal_Bool SfxPopupWindow::Close()
1271 m_bFloating = sal_False;
1272 FloatingWindow::Close();
1274 Delete();
1275 return sal_True;
1278 //--------------------------------------------------------------------
1280 void SfxPopupWindow::PopupModeEnd()
1282 //! to allow PopupModeEndHdl to be called
1283 FloatingWindow::PopupModeEnd();
1285 if ( IsVisible() )
1287 // was teared-off
1288 DeleteFloatingWindow();
1289 m_bFloating = sal_True;
1291 else
1292 Close();
1295 //--------------------------------------------------------------------
1297 void SfxPopupWindow::DeleteFloatingWindow()
1299 if ( m_bFloating )
1301 Hide();
1302 Delete();
1306 //--------------------------------------------------------------------
1308 void SfxPopupWindow::MouseMove( const ::MouseEvent& rMEvt )
1310 if ( m_bCascading == sal_False )
1311 FloatingWindow::MouseMove( rMEvt );
1312 else
1314 // Forward MouseMove-Event to Children
1315 ::Point aPos = rMEvt.GetPosPixel();
1316 ::Point aScrPos = OutputToScreenPixel( aPos );
1317 sal_uInt16 i = 0;
1318 Window* pWindow = GetChild( i );
1319 while ( pWindow )
1321 ::MouseEvent aMEvt( pWindow->ScreenToOutputPixel( aScrPos ),
1322 rMEvt.GetClicks(), rMEvt.GetMode(),
1323 rMEvt.GetButtons(), rMEvt.GetModifier() );
1324 pWindow->MouseMove( rMEvt );
1325 pWindow->Update();
1326 i++;
1327 pWindow = GetChild( i );
1332 //--------------------------------------------------------------------
1334 void SfxPopupWindow::StartCascading()
1336 m_bCascading= sal_True;
1339 //--------------------------------------------------------------------
1341 SfxPopupWindow* SfxPopupWindow::Clone() const
1343 /* [Description]
1345 This method must be overloaded to show this Popup also in the
1346 Presentation-mode. It is called when a Show() would be meaningless
1347 since the parent is no presentation window.
1348 When create a new window the bew Top-Window will be used automatically,
1349 so that the Parent becomes the presentation window and and that the new
1350 Popup therefore becomes visible.
1354 return 0;
1357 //--------------------------------------------------------------------
1359 void SfxPopupWindow::StateChanged(
1360 sal_uInt16 /*nSID*/,
1361 SfxItemState eState,
1362 const SfxPoolItem* /*pState*/ )
1363 /* [Description]
1365 See also <SfxControllerItem::StateChanged()>. In addition the Popup
1366 will become hidden when eState==SFX_ITEM_DISABLED and in all other
1367 cases it will be shown again if it is floating. In general this requires
1368 to call the Base class.
1370 Due to the parent the presentation mode is handled in a special way.
1374 if ( SFX_ITEM_DISABLED == eState )
1376 Hide();
1378 else if ( m_bFloating )
1380 Show( sal_True, SHOW_NOFOCUSCHANGE | SHOW_NOACTIVATE );
1384 //--------------------------------------------------------------------
1386 void SfxPopupWindow::Delete()
1388 if ( m_aDeleteLink.IsSet() )
1389 m_aDeleteLink.Call( this );
1390 delete this;
1393 //--------------------------------------------------------------------
1395 SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
1396 : SfxToolBoxControl( nSlotId, nId, rBox )
1397 , pMenu( 0 )
1399 rBox.SetHelpId( nId, HID_TBXCONTROL_FILENEW );
1400 rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN);
1402 // Determine the current background color of the menus
1403 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1404 m_nSymbolsStyle = rSettings.GetSymbolsStyle();
1405 m_bShowMenuImages = rSettings.GetUseImagesInMenus();
1407 SetImage( String() );
1410 SfxAppToolBoxControl_Impl::~SfxAppToolBoxControl_Impl()
1412 delete pMenu;
1415 //_____________________________________________________
1417 it return the existing state of the given URL in the popupmenu of this toolbox control.
1419 If the given URL can be located as an action command of one menu item of the
1420 popup menu of this control, we return sal_True. Otherwhise we return sal_False.
1421 Further we return a fallback URL, in case we have to return sal_False. Because
1422 the outside code must select a valid item of the popup menu everytime ...
1423 and we define it here. By the way this m ethod was written to handle
1424 error situations gracefully. E.g. it can be called during creation time
1425 but then we have no valid menu. For this case we know another fallback URL.
1426 Then we return the private:factory/ URL of the default factory.
1428 @param *pMenu
1429 pounts to the popup menu, on which item we try to locate the given URL
1430 Can be NULL! Search will be supressed then.
1432 @param sURL
1433 the URL for searching
1435 @param pFallback
1436 contains the fallback URL in case we return FALSE
1437 Must point to valid memory!
1439 @param pImage
1440 contains the image of the menu for the URL.
1442 @return sal_True - if URL could be located as an item of the popup menu.
1443 sal_False - otherwise.
1445 sal_Bool Impl_ExistURLInMenu( const PopupMenu *pMenu ,
1446 String &sURL ,
1447 String *pFallback ,
1448 Image *pImage )
1450 sal_Bool bValidFallback = sal_False;
1451 if (pMenu && sURL.Len())
1453 sal_uInt16 c = pMenu->GetItemCount();
1454 for (sal_uInt16 p=0; p<c; ++p)
1456 sal_uInt16 nId = pMenu->GetItemId(p);
1457 String aCmd( pMenu->GetItemCommand(nId) );
1459 if (!bValidFallback && aCmd.Len())
1461 *pFallback = aCmd;
1462 bValidFallback = sal_True;
1465 if (aCmd.Search(sURL)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667#
1467 sURL = aCmd;
1468 *pImage = pMenu->GetItemImage( nId );
1469 return sal_True;
1474 if (!bValidFallback)
1476 *pFallback = "private:factory/" + SvtModuleOptions().GetDefaultModuleName();
1479 return sal_False;
1482 long Select_Impl( void* pHdl, void* pVoid );
1484 SfxPopupWindow* SfxAppToolBoxControl_Impl::CreatePopupWindow()
1486 ToolBox& rBox = GetToolBox();
1487 ::Rectangle aRect( rBox.GetItemRect( GetId() ) );
1489 if ( !pMenu )
1491 ::framework::MenuConfiguration aConf( m_xContext );
1492 if ( m_aCommandURL == ".uno:AddDirect" )
1493 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
1494 else
1495 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
1498 if ( pMenu )
1500 pMenu->SetSelectHdl( Link( NULL, Select_Impl ) );
1501 pMenu->SetActivateHdl( LINK( this, SfxAppToolBoxControl_Impl, Activate ));
1502 rBox.SetItemDown( GetId(), sal_True );
1503 sal_uInt16 nSelected = pMenu->Execute( &rBox, aRect, POPUPMENU_EXECUTE_DOWN );
1504 if ( nSelected )
1506 aLastURL = pMenu->GetItemCommand( nSelected );
1507 SetImage( pMenu->GetItemCommand( nSelected ) );
1510 rBox.SetItemDown( GetId(), sal_False );
1513 return 0;
1516 void SfxAppToolBoxControl_Impl::SetImage( const String &rURL )
1518 /* We accept URL's here only, which exist as items of our internal popup menu.
1519 All other ones will be ignored and a fallback is used ... */
1520 String aURL = rURL;
1521 String sFallback;
1522 Image aMenuImage;
1523 sal_Bool bValid = Impl_ExistURLInMenu(pMenu,aURL,&sFallback,&aMenuImage);
1524 if (!bValid)
1525 aURL = sFallback;
1527 sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
1528 Image aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL ), bBig );
1529 if ( !aImage )
1530 aImage = !!aMenuImage ? aMenuImage :
1531 SvFileInformationManager::GetImage( INetURLObject( aURL ), bBig );
1532 Size aBigSize( GetToolBox().GetDefaultImageSize() );
1533 if ( bBig && aImage.GetSizePixel() != aBigSize )
1535 BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
1536 aScaleBmpEx.Scale( aBigSize, BMP_SCALE_BESTQUALITY );
1537 GetToolBox().SetItemImage( GetId(), Image( aScaleBmpEx ) );
1539 else
1540 GetToolBox().SetItemImage( GetId(), aImage );
1541 aLastURL = aURL;
1544 void SfxAppToolBoxControl_Impl::StateChanged
1546 sal_uInt16 nSlotId,
1547 SfxItemState eState,
1548 const SfxPoolItem* pState
1551 if ( pState && pState->ISA(SfxStringItem) )
1553 // Important step for following SetImage() call!
1554 // It needs the valid pMenu item to fullfill it's specification
1555 // to check for supported URLs ...
1556 if ( !pMenu )
1558 ::framework::MenuConfiguration aConf( m_xContext );
1559 // This toolbox controller is used for two popup menus (new documents and wizards!). Create the correct
1560 // popup menu according to the slot ID our controller has been initialized with.
1561 if ( nSlotId == SID_NEWDOCDIRECT )
1562 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_NEWMENU );
1563 else
1564 pMenu = aConf.CreateBookmarkMenu( m_xFrame, BOOKMARK_WIZARDMENU );
1567 GetToolBox().EnableItem( GetId(), eState != SFX_ITEM_DISABLED );
1568 SetImage(((const SfxStringItem*)pState)->GetValue());
1570 else
1571 SfxToolBoxControl::StateChanged( nSlotId, eState, pState );
1574 //--------------------------------------------------------------------
1576 void SfxAppToolBoxControl_Impl::Select( sal_Bool bMod1 )
1578 if( aLastURL.Len() )
1580 URL aTargetURL;
1581 Reference< XDispatch > xDispatch;
1582 Reference< XDispatchProvider > xDispatchProvider( getFrameInterface(), UNO_QUERY );
1584 if ( xDispatchProvider.is() )
1586 aTargetURL.Complete = aLastURL;
1587 getURLTransformer()->parseStrict( aTargetURL );
1589 OUString aTarget( OUString("_default"));
1590 if ( pMenu )
1592 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1593 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
1595 if ( pMenuAttributes )
1596 aTarget = pMenuAttributes->aTargetFrame;
1599 xDispatch = xDispatchProvider->queryDispatch( aTargetURL, aTarget, 0 );
1601 if ( xDispatch.is() )
1603 Sequence< PropertyValue > aArgs( 1 );
1605 aArgs[0].Name = OUString("Referer");
1606 aArgs[0].Value = makeAny( OUString(SFX_REFERER_USER ) );
1608 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
1609 pExecuteInfo->xDispatch = xDispatch;
1610 pExecuteInfo->aTargetURL = aTargetURL;
1611 pExecuteInfo->aArgs = aArgs;
1612 Application::PostUserEvent( STATIC_LINK(0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
1616 else
1617 SfxToolBoxControl::Select( bMod1 );
1620 //--------------------------------------------------------------------
1621 long Select_Impl( void* /*pHdl*/, void* pVoid )
1623 Menu* pMenu = (Menu*)pVoid;
1624 String aURL( pMenu->GetItemCommand( pMenu->GetCurItemId() ) );
1626 if( !aURL.Len() )
1627 return 0;
1629 Reference < ::com::sun::star::frame::XDesktop2 > xDesktop =
1630 ::com::sun::star::frame::Desktop::create( ::comphelper::getProcessComponentContext() );
1632 URL aTargetURL;
1633 aTargetURL.Complete = aURL;
1634 Reference < XURLTransformer > xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
1635 xTrans->parseStrict( aTargetURL );
1637 Reference < XDispatch > xDisp;
1638 if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL )
1639 xDisp = xDesktop->queryDispatch( aTargetURL, OUString(), 0 );
1640 else
1642 OUString aTargetFrame( OUString("_blank") );
1643 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1644 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( pMenu->GetCurItemId() );
1646 if ( pMenuAttributes )
1647 aTargetFrame = pMenuAttributes->aTargetFrame;
1649 xDisp = xDesktop->queryDispatch( aTargetURL, aTargetFrame , 0 );
1652 if ( xDisp.is() )
1654 SfxAppToolBoxControl_Impl::ExecuteInfo* pExecuteInfo = new SfxAppToolBoxControl_Impl::ExecuteInfo;
1655 pExecuteInfo->xDispatch = xDisp;
1656 pExecuteInfo->aTargetURL = aTargetURL;
1657 pExecuteInfo->aArgs = Sequence< PropertyValue >();
1658 Application::PostUserEvent( STATIC_LINK( 0, SfxAppToolBoxControl_Impl, ExecuteHdl_Impl), pExecuteInfo );
1661 return sal_True;
1664 IMPL_LINK( SfxAppToolBoxControl_Impl, Activate, Menu *, pActMenu )
1666 if ( pActMenu )
1668 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
1669 sal_uIntPtr nSymbolsStyle = rSettings.GetSymbolsStyle();
1670 sal_Bool bShowMenuImages = rSettings.GetUseImagesInMenus();
1672 if (( nSymbolsStyle != m_nSymbolsStyle ) ||
1673 ( bShowMenuImages != m_bShowMenuImages ))
1675 m_nSymbolsStyle = nSymbolsStyle;
1676 m_bShowMenuImages = bShowMenuImages;
1678 sal_uInt16 nCount = pActMenu->GetItemCount();
1679 for ( sal_uInt16 nSVPos = 0; nSVPos < nCount; nSVPos++ )
1681 sal_uInt16 nId = pActMenu->GetItemId( nSVPos );
1682 if ( pActMenu->GetItemType( nSVPos ) != MENUITEM_SEPARATOR )
1684 if ( bShowMenuImages )
1686 sal_Bool bImageSet = sal_False;
1687 OUString aImageId;
1688 ::framework::MenuConfiguration::Attributes* pMenuAttributes =
1689 (::framework::MenuConfiguration::Attributes*)pMenu->GetUserValue( nId );
1691 if ( pMenuAttributes )
1692 aImageId = pMenuAttributes->aImageId; // Retrieve image id from menu attributes
1694 if ( !aImageId.isEmpty() )
1696 Reference< ::com::sun::star::frame::XFrame > xFrame;
1697 Image aImage = GetImage( xFrame, aImageId, false );
1698 if ( !!aImage )
1700 bImageSet = sal_True;
1701 pActMenu->SetItemImage( nId, aImage );
1705 String aCmd( pActMenu->GetItemCommand( nId ) );
1706 if ( !bImageSet && aCmd.Len() )
1708 Image aImage = SvFileInformationManager::GetImage(
1709 INetURLObject(aCmd), false );
1710 if ( !!aImage )
1711 pActMenu->SetItemImage( nId, aImage );
1714 else
1715 pActMenu->SetItemImage( nId, Image() );
1720 return sal_True;
1723 return sal_False;
1726 //--------------------------------------------------------------------
1728 IMPL_STATIC_LINK_NOINSTANCE( SfxAppToolBoxControl_Impl, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
1730 /* i62706: Don't catch all exceptions. We hide all problems here and are not able
1731 to handle them on higher levels.
1735 // Asynchronous execution as this can lead to our own destruction!
1736 // Framework can recycle our current frame and the layout manager disposes all user interface
1737 // elements if a component gets detached from its frame!
1738 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
1739 delete pExecuteInfo;
1740 return 0;
1743 //--------------------------------------------------------------------
1745 void SfxAppToolBoxControl_Impl::Click( )
1749 //--------------------------------------------------------------------
1751 SfxRecentFilesToolBoxControl::SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
1752 : SfxToolBoxControl( nSlotId, nId, rBox )
1754 rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN);
1757 SfxRecentFilesToolBoxControl::~SfxRecentFilesToolBoxControl()
1761 SfxPopupWindow* SfxRecentFilesToolBoxControl::CreatePopupWindow()
1763 ToolBox& rBox = GetToolBox();
1764 sal_uInt16 nItemId = GetId();
1765 ::Rectangle aRect( rBox.GetItemRect( nItemId ) );
1767 Sequence< Any > aArgs( 2 );
1768 PropertyValue aPropValue;
1770 aPropValue.Name = "CommandURL";
1771 aPropValue.Value <<= OUString( ".uno:RecentFileList" );
1772 aArgs[0] <<= aPropValue;
1774 aPropValue.Name = "Frame";
1775 aPropValue.Value <<= m_xFrame;
1776 aArgs[1] <<= aPropValue;
1778 uno::Reference< frame::XPopupMenuController > xPopupController( m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
1779 "com.sun.star.comp.framework.RecentFilesMenuController", aArgs, m_xContext ), UNO_QUERY );
1781 uno::Reference< awt::XPopupMenu > xPopupMenu( m_xContext->getServiceManager()->createInstanceWithContext(
1782 "com.sun.star.awt.PopupMenu", m_xContext ), uno::UNO_QUERY );
1784 if ( xPopupController.is() && xPopupMenu.is() )
1786 xPopupController->setPopupMenu( xPopupMenu );
1788 rBox.SetItemDown( nItemId, sal_True );
1789 Reference< awt::XWindowPeer > xPeer( getParent(), uno::UNO_QUERY );
1791 if ( xPeer.is() )
1792 xPopupMenu->execute( xPeer, VCLUnoHelper::ConvertToAWTRect( aRect ), 0 );
1794 rBox.SetItemDown( nItemId, sal_False );
1797 return 0;
1800 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */