1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
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>
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
);
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
;
125 if ( pWindow
->IsSystemWindow() )
126 pTopMostSysWin
= (SystemWindow
*)pWindow
;
127 pWindow
= pWindow
->GetParent();
129 pWindow
= pTopMostSysWin
;
130 OSL_ASSERT( pWindow
);
137 svt::ToolboxController
* SAL_CALL
SfxToolBoxControllerFactory( const Reference
< XFrame
>& rFrame
, ToolBox
* pToolbox
, unsigned short nID
, const OUString
& aCommandURL
)
139 SolarMutexGuard aGuard
;
142 aTargetURL
.Complete
= aCommandURL
;
143 Reference
< XURLTransformer
> xTrans( URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
144 xTrans
->parseStrict( aTargetURL
);
145 if ( !aTargetURL
.Arguments
.isEmpty() )
148 SfxObjectShell
* pObjShell
= NULL
;
149 Reference
< XController
> xController
;
150 Reference
< XModel
> xModel
;
153 xController
= rFrame
->getController();
154 if ( xController
.is() )
155 xModel
= xController
->getModel();
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
);
164 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq
= SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence();
165 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
167 pObjShell
= reinterpret_cast< SfxObjectShell
* >( sal::static_int_cast
< sal_IntPtr
>( nHandle
));
171 SfxModule
* pModule
= pObjShell
? pObjShell
->GetModule() : NULL
;
172 SfxSlotPool
* pSlotPool
= 0;
175 pSlotPool
= pModule
->GetSlotPool();
177 pSlotPool
= &(SfxSlotPool::GetSlotPool( NULL
));
179 const SfxSlot
* pSlot
= pSlotPool
->GetUnoSlot( aTargetURL
.Path
);
182 sal_uInt16 nSlotId
= pSlot
->GetSlotId();
184 return SfxToolBoxControl::CreateControl( nSlotId
, nID
, pToolbox
, pModule
);
190 struct SfxToolBoxControl_Impl
193 sal_Bool bShowString
;
194 sal_uInt16 nSelectModifier
;
195 SfxTbxCtrlFactory
* pFact
;
198 SfxPopupWindow
* mpFloatingWindow
;
199 SfxPopupWindow
* mpPopupWindow
;
200 Reference
< XUIElement
> mxUIElement
;
202 DECL_LINK( WindowEventListener
, VclSimpleEvent
* );
205 IMPL_LINK( SfxToolBoxControl_Impl
, WindowEventListener
, VclSimpleEvent
*, 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
;
224 //--------------------------------------------------------------------
226 SfxToolBoxControl::SfxToolBoxControl(
230 sal_Bool bShowStringItems
)
231 : svt::ToolboxController()
233 pImpl
= new SfxToolBoxControl_Impl
;
236 pImpl
->bShowString
= bShowStringItems
;
237 pImpl
->nSelectModifier
= 0;
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;
258 //--------------------------------------------------------------------
260 ToolBox
& SfxToolBoxControl::GetToolBox() const
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
)
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 );
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
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
;
323 pSlotPool
= pMod
->GetSlotPool();
325 pSlotPool
= &SfxSlotPool::GetSlotPool();
326 TypeId aSlotType
= pSlotPool
->GetSlotType( nSlotId
);
331 SfxTbxCtrlFactArr_Impl
*pFactories
= pMod
->GetTbxCtrlFactories_Impl();
334 SfxTbxCtrlFactArr_Impl
&rFactories
= *pFactories
;
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
) )
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) )
352 if( nFactory
< nCount
)
354 pCtrl
= rFactories
[nFactory
]->pCtor( nSlotId
, nTbxId
, *pBox
);
355 pCtrl
->pImpl
->pFact
= rFactories
[nFactory
];
361 SfxTbxCtrlFactArr_Impl
&rFactories
= pApp
->GetTbxCtrlFactories_Impl();
363 const sal_uInt16 nCount
= rFactories
.size();
365 for( nFactory
= 0; nFactory
< nCount
; ++nFactory
)
366 if( (rFactories
[nFactory
]->nTypeId
== aSlotType
) && (rFactories
[nFactory
]->nSlotId
== nSlotId
) )
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) )
378 if( nFactory
< nCount
)
380 pCtrl
= rFactories
[nFactory
]->pCtor( nSlotId
, nTbxId
, *pBox
);
381 pCtrl
->pImpl
->pFact
= rFactories
[nFactory
];
389 SfxItemState
SfxToolBoxControl::GetItemState(
390 const SfxPoolItem
* pState
)
393 Static method for determining the status of the SfxPoolItem-pointer,
394 used in the method <SfxControllerItem::StateChanged(const SfxPoolItem*)>.
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.
404 Disabled, no further status information is available.
405 All other displayed values should be reset to the default
409 Enabled but there were only ambiguous values available
410 (i.e. none that could be queried).
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.
421 : IsInvalidItem(pState
)
423 : pState
->ISA(SfxVoidItem
) && !pState
->Which()
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
);
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
);
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 );
510 Reference
< XUnoTunnel
> xTunnel( xDisp
, UNO_QUERY
);
511 SfxOfficeDispatch
* pDisp
= NULL
;
514 sal_Int64 nImplementation
= xTunnel
->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
515 pDisp
= reinterpret_cast< SfxOfficeDispatch
* >( sal::static_int_cast
< sal_IntPtr
>( nImplementation
));
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
);
527 nSlotId
= pSlot
->GetSlotId();
528 else if ( m_aCommandURL
== rEvent
.FeatureURL
.Path
)
529 nSlotId
= GetSlotId();
533 if ( rEvent
.Requery
)
534 svt::ToolboxController::statusChanged( rEvent
);
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) )
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
);
589 pItem
= pSlot
->GetType()->CreateItem();
592 pItem
->SetWhich( nSlotId
);
593 pItem
->PutValue( rEvent
.State
);
596 pItem
= new SfxVoidItem( nSlotId
);
600 StateChanged( nSlotId
, eState
, pItem
);
606 // XSubToolbarController
607 ::sal_Bool SAL_CALL
SfxToolBoxControl::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException
)
612 OUString SAL_CALL
SfxToolBoxControl::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException
)
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
;
639 void SAL_CALL
SfxToolBoxControl::doubleClick() throw (::com::sun::star::uno::RuntimeException
)
641 SolarMutexGuard aGuard
;
645 Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
SfxToolBoxControl::createPopupWindow() throw (::com::sun::star::uno::RuntimeException
)
647 SolarMutexGuard aGuard
;
648 Window
* pWindow
= CreatePopupWindow();
650 return VCLUnoHelper::GetInterface( pWindow
);
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
)
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
);
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() )
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
)
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
& )
763 catch ( ::com::sun::star::uno::Exception
& )
771 ::Size
SfxToolBoxControl::getPersistentFloatingSize( const Reference
< XFrame
>& /*xFrame*/, const OUString
& /*rSubToolBarResName*/ )
777 void SfxToolBoxControl::createAndPositionSubToolBar( const OUString
& rSubToolBarResName
)
779 SolarMutexGuard aGuard
;
783 static WeakReference
< XUIElementFactoryManager
> xWeakUIElementFactory
;
785 sal_uInt16 nItemId
= pImpl
->pBox
->GetDownItemId();
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
;
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
888 pImpl
->mpFloatingWindow
->AddEventListener( LINK( pImpl
, SfxToolBoxControl_Impl
, WindowEventListener
));
892 // Popup window has been closed by the user. No replacement, instance
893 // will destroy itself.
894 pImpl
->mpPopupWindow
= 0;
900 //--------------------------------------------------------------------
901 IMPL_LINK( SfxToolBoxControl
, ClosePopupWindow
, SfxPopupWindow
*, pWindow
)
903 if ( pWindow
== pImpl
->mpFloatingWindow
)
904 pImpl
->mpFloatingWindow
= 0;
906 pImpl
->mpPopupWindow
= 0;
911 //--------------------------------------------------------------------
913 void SfxToolBoxControl::StateChanged
917 const SfxPoolItem
* pState
920 DBG_ASSERT( pImpl
->pBox
!= 0, "setting state to dangling ToolBox" );
922 if ( GetId() >= SID_OBJECTMENU0
&& GetId() <= SID_OBJECTMENU_LAST
)
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
;
933 case SFX_ITEM_AVAILABLE
:
935 if ( pState
->ISA(SfxBoolItem
) )
937 // BoolItem for checking
938 if ( ((const SfxBoolItem
*)pState
)->GetValue() )
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() )
948 nItemBits
|= TIB_CHECKABLE
;
950 else if ( pImpl
->bShowString
&& pState
->ISA(SfxStringItem
) )
951 pImpl
->pBox
->SetItemText(nId
, ((const SfxStringItem
*)pState
)->GetValue() );
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()
1007 SfxPopupWindow
* SfxToolBoxControl::CreatePopupWindowCascading()
1012 //--------------------------------------------------------------------
1014 Window
* SfxToolBoxControl::CreateItemWindow( Window
* )
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 //--------------------------------------------------------------------
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 );
1055 Reference
< XUnoTunnel
> xTunnel( xDisp
, UNO_QUERY
);
1056 SfxOfficeDispatch
* pDisp
= NULL
;
1059 sal_Int64 nImplementation
= xTunnel
->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
1060 pDisp
= reinterpret_cast< SfxOfficeDispatch
* >( sal::static_int_cast
< sal_IntPtr
>( nImplementation
));
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
);
1072 nSlotId
= pSlot
->GetSlotId();
1076 if ( rEvent
.Requery
)
1078 // requery for the notified state
1079 addStatusListener( rEvent
.FeatureURL
.Complete
);
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) )
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
);
1135 pItem
= pSlot
->GetType()->CreateItem();
1138 pItem
->SetWhich( nSlotId
);
1139 pItem
->PutValue( rEvent
.State
);
1142 pItem
= new SfxVoidItem( nSlotId
);
1147 m_pCallee
->StateChanged( nSlotId
, eState
, pItem
);
1153 //--------------------------------------------------------------------
1155 SfxPopupWindow::SfxPopupWindow(
1157 const Reference
< XFrame
>& rFrame
,
1159 FloatingWindow( SFX_APP()->GetTopWindow(), nBits
)
1160 , m_bFloating(sal_False
)
1161 , m_bCascading( sal_False
)
1163 , m_xFrame( rFrame
)
1164 , m_pStatusListener( 0 )
1166 Window
* pWindow
= GetTopMostParentSystemWindow( this );
1168 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->AddWindow( this );
1171 //--------------------------------------------------------------------
1173 SfxPopupWindow::SfxPopupWindow(
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
)
1181 , m_xFrame( rFrame
)
1182 , m_pStatusListener( 0 )
1184 Window
* pWindow
= GetTopMostParentSystemWindow( this );
1186 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->AddWindow( this );
1189 //--------------------------------------------------------------------
1191 SfxPopupWindow::SfxPopupWindow(
1193 const Reference
< XFrame
>& rFrame
,
1194 Window
* pParentWindow
,
1196 FloatingWindow( pParentWindow
, nBits
)
1197 , m_bFloating(sal_False
)
1198 , m_bCascading( sal_False
)
1200 , m_xFrame( rFrame
)
1201 , m_pStatusListener( 0 )
1203 Window
* pWindow
= GetTopMostParentSystemWindow( this );
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 );
1220 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->RemoveWindow( this );
1223 //--------------------------------------------------------------------
1225 SfxFrameStatusListener
* SfxPopupWindow::GetOrCreateStatusListener()
1227 if ( !m_xStatusListener
.is() )
1229 m_pStatusListener
= new SfxFrameStatusListener(
1230 ::comphelper::getProcessComponentContext(),
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();
1278 //--------------------------------------------------------------------
1280 void SfxPopupWindow::PopupModeEnd()
1282 //! to allow PopupModeEndHdl to be called
1283 FloatingWindow::PopupModeEnd();
1288 DeleteFloatingWindow();
1289 m_bFloating
= sal_True
;
1295 //--------------------------------------------------------------------
1297 void SfxPopupWindow::DeleteFloatingWindow()
1306 //--------------------------------------------------------------------
1308 void SfxPopupWindow::MouseMove( const ::MouseEvent
& rMEvt
)
1310 if ( m_bCascading
== sal_False
)
1311 FloatingWindow::MouseMove( rMEvt
);
1314 // Forward MouseMove-Event to Children
1315 ::Point aPos
= rMEvt
.GetPosPixel();
1316 ::Point aScrPos
= OutputToScreenPixel( aPos
);
1318 Window
* pWindow
= GetChild( i
);
1321 ::MouseEvent
aMEvt( pWindow
->ScreenToOutputPixel( aScrPos
),
1322 rMEvt
.GetClicks(), rMEvt
.GetMode(),
1323 rMEvt
.GetButtons(), rMEvt
.GetModifier() );
1324 pWindow
->MouseMove( rMEvt
);
1327 pWindow
= GetChild( i
);
1332 //--------------------------------------------------------------------
1334 void SfxPopupWindow::StartCascading()
1336 m_bCascading
= sal_True
;
1339 //--------------------------------------------------------------------
1341 SfxPopupWindow
* SfxPopupWindow::Clone() const
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.
1357 //--------------------------------------------------------------------
1359 void SfxPopupWindow::StateChanged(
1360 sal_uInt16
/*nSID*/,
1361 SfxItemState eState
,
1362 const SfxPoolItem
* /*pState*/ )
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
)
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 );
1393 //--------------------------------------------------------------------
1395 SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( sal_uInt16 nSlotId
, sal_uInt16 nId
, ToolBox
& rBox
)
1396 : SfxToolBoxControl( nSlotId
, nId
, rBox
)
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()
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.
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.
1433 the URL for searching
1436 contains the fallback URL in case we return FALSE
1437 Must point to valid memory!
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
,
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())
1462 bValidFallback
= sal_True
;
1465 if (aCmd
.Search(sURL
)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667#
1468 *pImage
= pMenu
->GetItemImage( nId
);
1474 if (!bValidFallback
)
1476 *pFallback
= "private:factory/" + SvtModuleOptions().GetDefaultModuleName();
1482 long Select_Impl( void* pHdl
, void* pVoid
);
1484 SfxPopupWindow
* SfxAppToolBoxControl_Impl::CreatePopupWindow()
1486 ToolBox
& rBox
= GetToolBox();
1487 ::Rectangle
aRect( rBox
.GetItemRect( GetId() ) );
1491 ::framework::MenuConfiguration
aConf( m_xContext
);
1492 if ( m_aCommandURL
== ".uno:AddDirect" )
1493 pMenu
= aConf
.CreateBookmarkMenu( m_xFrame
, BOOKMARK_NEWMENU
);
1495 pMenu
= aConf
.CreateBookmarkMenu( m_xFrame
, BOOKMARK_WIZARDMENU
);
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
);
1506 aLastURL
= pMenu
->GetItemCommand( nSelected
);
1507 SetImage( pMenu
->GetItemCommand( nSelected
) );
1510 rBox
.SetItemDown( GetId(), sal_False
);
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 ... */
1523 sal_Bool bValid
= Impl_ExistURLInMenu(pMenu
,aURL
,&sFallback
,&aMenuImage
);
1527 sal_Bool bBig
= SvtMiscOptions().AreCurrentSymbolsLarge();
1528 Image aImage
= SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL
), bBig
);
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
) );
1540 GetToolBox().SetItemImage( GetId(), aImage
);
1544 void SfxAppToolBoxControl_Impl::StateChanged
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 ...
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
);
1564 pMenu
= aConf
.CreateBookmarkMenu( m_xFrame
, BOOKMARK_WIZARDMENU
);
1567 GetToolBox().EnableItem( GetId(), eState
!= SFX_ITEM_DISABLED
);
1568 SetImage(((const SfxStringItem
*)pState
)->GetValue());
1571 SfxToolBoxControl::StateChanged( nSlotId
, eState
, pState
);
1574 //--------------------------------------------------------------------
1576 void SfxAppToolBoxControl_Impl::Select( sal_Bool bMod1
)
1578 if( aLastURL
.Len() )
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"));
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
);
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() ) );
1629 Reference
< ::com::sun::star::frame::XDesktop2
> xDesktop
=
1630 ::com::sun::star::frame::Desktop::create( ::comphelper::getProcessComponentContext() );
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 );
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 );
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
);
1664 IMPL_LINK( SfxAppToolBoxControl_Impl
, Activate
, Menu
*, 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
;
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 );
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 );
1711 pActMenu
->SetItemImage( nId
, aImage
);
1715 pActMenu
->SetItemImage( nId
, Image() );
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
;
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
);
1792 xPopupMenu
->execute( xPeer
, VCLUnoHelper::ConvertToAWTRect( aRect
), 0 );
1794 rBox
.SetItemDown( nItemId
, sal_False
);
1800 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */