1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tbxitem.cxx,v $
10 * $Revision: 1.70.80.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
35 // HACK: prevent conflict between STLPORT and Workshop headers on Solaris 8
39 #include <string> // prevent conflict with STL includes
40 #include <com/sun/star/uno/Reference.h>
41 #include <com/sun/star/frame/XFrame.hpp>
42 #include <com/sun/star/awt/XWindow.hpp>
43 #include <com/sun/star/util/URL.hpp>
44 #include <com/sun/star/util/XURLTransformer.hpp>
45 #include <com/sun/star/frame/XController.hpp>
46 #include <com/sun/star/lang/XUnoTunnel.hpp>
47 #include <com/sun/star/document/MacroExecMode.hpp>
48 #include <com/sun/star/document/UpdateDocMode.hpp>
49 #include <com/sun/star/frame/XComponentLoader.hpp>
50 #include <com/sun/star/beans/PropertyValue.hpp>
51 #include <com/sun/star/beans/XPropertySet.hpp>
52 #include <com/sun/star/frame/XLayoutManager.hpp>
53 #include <com/sun/star/frame/status/ItemStatus.hpp>
54 #include <com/sun/star/frame/status/ItemState.hpp>
55 #include <com/sun/star/ui/XUIElementFactory.hpp>
56 #include <com/sun/star/frame/XModuleManager.hpp>
57 #include <com/sun/star/container/XNameAccess.hpp>
58 #include <com/sun/star/ui/XUIFunctionListener.hpp>
59 #include <com/sun/star/frame/status/Visibility.hpp>
60 #include <com/sun/star/document/CorruptedFilterConfigurationException.hpp>
61 #include <svtools/eitem.hxx>
62 #include <svtools/stritem.hxx>
63 #include <svtools/intitem.hxx>
64 #include <svtools/imageitm.hxx>
65 #include <svtools/visitem.hxx>
66 #include <svtools/urlbmk.hxx>
67 #include <vcl/toolbox.hxx>
68 #include <svtools/moduleoptions.hxx>
70 #include <svtools/imagemgr.hxx>
71 #include <comphelper/processfactory.hxx>
72 #include <framework/addonmenu.hxx>
73 #include <framework/addonsoptions.hxx>
74 #include <framework/menuconfiguration.hxx>
75 #include <framework/sfxhelperfunctions.hxx>
76 #include <vcl/taskpanelist.hxx>
77 #ifndef _TOOLKIT_UNOHLP_HXX
78 #include <toolkit/helper/vclunohelper.hxx>
80 #include <svtools/menuoptions.hxx>
81 #include <svtools/miscopt.hxx>
86 #include <sfx2/tbxctrl.hxx>
87 #include <sfx2/mnumgr.hxx>
88 #include <sfx2/dispatch.hxx>
90 #include <sfx2/msg.hxx>
91 #include <sfx2/msgpool.hxx>
92 #include "statcach.hxx"
93 #include <sfx2/viewfrm.hxx>
94 #include "arrdecl.hxx"
95 #include "sfxtypes.hxx"
96 #include <sfx2/macrconf.hxx>
97 #include <sfx2/genlink.hxx>
98 #include "sfxresid.hxx"
99 #include <sfx2/sfx.hrc>
100 #include <sfx2/module.hxx>
101 #include <sfx2/docfile.hxx>
102 #include <sfx2/docfac.hxx>
103 #include "referers.hxx"
104 #include <sfx2/frmhtmlw.hxx>
105 #include <sfx2/app.hxx>
106 #include <sfx2/unoctitm.hxx>
107 #include "helpid.hrc"
108 #include "workwin.hxx"
109 #include "imgmgr.hxx"
110 #include "virtmenu.hxx"
111 #include <sfx2/viewfrm.hxx>
112 #include <sfx2/module.hxx>
113 #include "imagemgr.hxx"
115 #include <comphelper/uieventslogger.hxx>
116 #include <com/sun/star/frame/XModuleManager.hpp>
118 //using namespace ::com::sun::star::awt;
119 using namespace ::com::sun::star::beans
;
120 using namespace ::com::sun::star::frame
;
121 using namespace ::com::sun::star::frame::status
;
122 using namespace ::com::sun::star::lang
;
123 using namespace ::com::sun::star::uno
;
124 using namespace ::com::sun::star::util
;
125 using namespace ::com::sun::star::container
;
126 using namespace ::com::sun::star::frame
;
127 using namespace ::com::sun::star::ui
;
129 //====================================================================
131 SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl
, SfxStringItem
, TRUE
);
132 SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl
, SfxStringItem
);
134 static Window
* GetTopMostParentSystemWindow( Window
* pWindow
)
136 OSL_ASSERT( pWindow
);
139 // ->manually search topmost system window
140 // required because their might be another system window between this and the top window
141 pWindow
= pWindow
->GetParent();
142 SystemWindow
* pTopMostSysWin
= NULL
;
145 if ( pWindow
->IsSystemWindow() )
146 pTopMostSysWin
= (SystemWindow
*)pWindow
;
147 pWindow
= pWindow
->GetParent();
149 pWindow
= pTopMostSysWin
;
150 OSL_ASSERT( pWindow
);
157 svt::ToolboxController
* SAL_CALL
SfxToolBoxControllerFactory( const Reference
< XFrame
>& rFrame
, ToolBox
* pToolbox
, unsigned short nID
, const ::rtl::OUString
& aCommandURL
)
159 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
162 aTargetURL
.Complete
= aCommandURL
;
163 Reference
< XURLTransformer
> xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY
);
164 xTrans
->parseStrict( aTargetURL
);
165 if ( aTargetURL
.Arguments
.getLength() )
168 SfxObjectShell
* pObjShell
= NULL
;
169 Reference
< XController
> xController
;
170 Reference
< XModel
> xModel
;
173 xController
= rFrame
->getController();
174 if ( xController
.is() )
175 xModel
= xController
->getModel();
180 // Get tunnel from model to retrieve the SfxObjectShell pointer from it
181 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XUnoTunnel
> xObj( xModel
, UNO_QUERY
);
184 ::com::sun::star::uno::Sequence
< sal_Int8
> aSeq
= SvGlobalName( SFX_GLOBAL_CLASSID
).GetByteSequence();
185 sal_Int64 nHandle
= xObj
->getSomething( aSeq
);
187 pObjShell
= reinterpret_cast< SfxObjectShell
* >( sal::static_int_cast
< sal_IntPtr
>( nHandle
));
191 SfxModule
* pModule
= pObjShell
? pObjShell
->GetModule() : NULL
;
192 SfxSlotPool
* pSlotPool
= 0;
195 pSlotPool
= pModule
->GetSlotPool();
197 pSlotPool
= &(SfxSlotPool::GetSlotPool( NULL
));
199 const SfxSlot
* pSlot
= pSlotPool
->GetUnoSlot( aTargetURL
.Path
);
202 USHORT nSlotId
= pSlot
->GetSlotId();
204 return SfxToolBoxControl::CreateControl( nSlotId
, nID
, pToolbox
, pModule
);
210 struct SfxToolBoxControl_Impl
214 USHORT nSelectModifier
;
215 SfxTbxCtrlFactory
* pFact
;
218 SfxPopupWindow
* mpFloatingWindow
;
219 SfxPopupWindow
* mpPopupWindow
;
220 Reference
< XUIElement
> mxUIElement
;
222 DECL_LINK( WindowEventListener
, VclSimpleEvent
* );
225 IMPL_LINK( SfxToolBoxControl_Impl
, WindowEventListener
, VclSimpleEvent
*, pEvent
)
228 pEvent
->ISA( VclWindowEvent
) &&
229 (( pEvent
->GetId() == VCLEVENT_WINDOW_MOVE
) ||
230 ( pEvent
->GetId() == VCLEVENT_WINDOW_ACTIVATE
)))
232 Window
* pWindow( ((VclWindowEvent
*)pEvent
)->GetWindow() );
233 if (( pWindow
== mpFloatingWindow
) &&
234 ( mpPopupWindow
!= 0 ))
236 delete mpPopupWindow
;
244 //--------------------------------------------------------------------
246 SfxToolBoxControl::SfxToolBoxControl(
250 BOOL bShowStringItems
)
251 : svt::ToolboxController()
253 pImpl
= new SfxToolBoxControl_Impl
;
256 pImpl
->bShowString
= bShowStringItems
;
257 pImpl
->nSelectModifier
= 0;
260 pImpl
->nSlotId
= nSlotID
;
261 pImpl
->mpFloatingWindow
= 0;
262 pImpl
->mpPopupWindow
= 0;
265 //--------------------------------------------------------------------
267 SfxToolBoxControl::~SfxToolBoxControl()
269 if ( pImpl
->mxUIElement
.is() )
271 Reference
< XComponent
> xComponent( pImpl
->mxUIElement
, UNO_QUERY
);
272 xComponent
->dispose();
274 pImpl
->mxUIElement
= 0;
278 //--------------------------------------------------------------------
280 ToolBox
& SfxToolBoxControl::GetToolBox() const
284 unsigned short SfxToolBoxControl::GetId() const
286 return pImpl
->nTbxId
;
288 unsigned short SfxToolBoxControl::GetSlotId() const
290 return pImpl
->nSlotId
;
293 //--------------------------------------------------------------------
295 void SAL_CALL
SfxToolBoxControl::dispose() throw (::com::sun::star::uno::RuntimeException
)
300 svt::ToolboxController::dispose();
302 // Remove and destroy our item window at our toolbox
303 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
304 Window
* pWindow
= pImpl
->pBox
->GetItemWindow( pImpl
->nTbxId
);
305 pImpl
->pBox
->SetItemWindow( pImpl
->nTbxId
, 0 );
308 // Dispose an open sub toolbar. It's possible that we have an open
309 // sub toolbar while we get disposed. Therefore we have to dispose
310 // it now! Not doing so would result in a crash. The sub toolbar
311 // gets destroyed asynchronously and would access a non-existing
312 // parent toolbar! See #126569#
313 if ( pImpl
->mxUIElement
.is() )
315 Reference
< XComponent
> xComponent( pImpl
->mxUIElement
, UNO_QUERY
);
316 xComponent
->dispose();
318 pImpl
->mxUIElement
= 0;
320 // Delete my popup windows
321 delete pImpl
->mpFloatingWindow
;
322 delete pImpl
->mpPopupWindow
;
324 pImpl
->mpFloatingWindow
= 0;
325 pImpl
->mpPopupWindow
= 0;
328 //--------------------------------------------------------------------
329 void SfxToolBoxControl::RegisterToolBoxControl( SfxModule
* pMod
, SfxTbxCtrlFactory
* pFact
)
331 SFX_APP()->RegisterToolBoxControl_Impl( pMod
, pFact
);
334 SfxToolBoxControl
* SfxToolBoxControl::CreateControl( USHORT nSlotId
, USHORT nTbxId
, ToolBox
*pBox
, SfxModule
* pMod
)
336 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
338 SfxToolBoxControl
*pCtrl
;
339 SfxApplication
*pApp
= SFX_APP();
341 SfxSlotPool
*pSlotPool
;
343 pSlotPool
= pMod
->GetSlotPool();
345 pSlotPool
= &SfxSlotPool::GetSlotPool();
346 TypeId aSlotType
= pSlotPool
->GetSlotType( nSlotId
);
351 SfxTbxCtrlFactArr_Impl
*pFactories
= pMod
->GetTbxCtrlFactories_Impl();
354 SfxTbxCtrlFactArr_Impl
&rFactories
= *pFactories
;
356 const USHORT nCount
= rFactories
.Count();
358 // search for a factory with the given slot id
359 for( nFactory
= 0; nFactory
< nCount
; ++nFactory
)
360 if( (rFactories
[nFactory
]->nTypeId
== aSlotType
) && (rFactories
[nFactory
]->nSlotId
== nSlotId
) )
363 if( nFactory
== nCount
)
365 // if no factory exists for the given slot id, see if we
366 // have a generic factory with the correct slot type and slot id == 0
367 for ( nFactory
= 0; nFactory
< nCount
; ++nFactory
)
368 if( (rFactories
[nFactory
]->nTypeId
== aSlotType
) && (rFactories
[nFactory
]->nSlotId
== 0) )
372 if( nFactory
< nCount
)
374 pCtrl
= rFactories
[nFactory
]->pCtor( nSlotId
, nTbxId
, *pBox
);
375 pCtrl
->pImpl
->pFact
= rFactories
[nFactory
];
381 SfxTbxCtrlFactArr_Impl
&rFactories
= pApp
->GetTbxCtrlFactories_Impl();
383 const USHORT nCount
= rFactories
.Count();
385 for( nFactory
= 0; nFactory
< nCount
; ++nFactory
)
386 if( (rFactories
[nFactory
]->nTypeId
== aSlotType
) && (rFactories
[nFactory
]->nSlotId
== nSlotId
) )
389 if( nFactory
== nCount
)
391 // if no factory exists for the given slot id, see if we
392 // have a generic factory with the correct slot type and slot id == 0
393 for( nFactory
= 0; nFactory
< nCount
; ++nFactory
)
394 if( (rFactories
[nFactory
]->nTypeId
== aSlotType
) && (rFactories
[nFactory
]->nSlotId
== 0) )
398 if( nFactory
< nCount
)
400 pCtrl
= rFactories
[nFactory
]->pCtor( nSlotId
, nTbxId
, *pBox
);
401 pCtrl
->pImpl
->pFact
= rFactories
[nFactory
];
409 SfxItemState
SfxToolBoxControl::GetItemState(
410 const SfxPoolItem
* pState
)
413 Statische Methode zum Ermitteln des Status des SfxPoolItem-Pointers,
414 in der Methode <SfxControllerItem::StateChanged(const SfxPoolItem*)>
419 SfxItemState SFX_ITEM_UNKNOWN
420 Enabled, aber keine weitere Statusinformation
421 verf"ugbar. Typisch f"ur <Slot>s, die allenfalls
422 zeitweise disabled sind, aber ihre Darstellung sonst
426 Disabled und keine weiter Statusinformation
427 verf"ugbar. Alle anderen ggf. angezeigten Werte sollten
428 auf den Default zur"uckgesetzt werden.
431 Enabled aber es waren nur uneindeutige Werte
432 verf"ugbar (also keine, die abgefragt werden k"onnen).
435 Enabled und mit verf"ugbarem Wert, der von 'pState'
436 erfragbar ist. Der Typ ist dabei im gesamten
437 Programm eindeutig und durch den Slot festgelegt.
443 : IsInvalidItem(pState
)
445 : pState
->ISA(SfxVoidItem
) && !pState
->Which()
447 : SFX_ITEM_AVAILABLE
;
450 void SfxToolBoxControl::Dispatch(
451 const Reference
< XDispatchProvider
>& rProvider
,
452 const rtl::OUString
& rCommand
,
453 Sequence
< ::PropertyValue
>& aArgs
)
455 if ( rProvider
.is() )
457 ::com::sun::star::util::URL aTargetURL
;
458 aTargetURL
.Complete
= rCommand
;
459 Reference
< XURLTransformer
> xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
460 rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
462 xTrans
->parseStrict( aTargetURL
);
464 Reference
< XDispatch
> xDispatch
= rProvider
->queryDispatch( aTargetURL
, ::rtl::OUString(), 0 );
465 if ( xDispatch
.is() )
466 xDispatch
->dispatch( aTargetURL
, aArgs
);
470 void SfxToolBoxControl::Dispatch( const ::rtl::OUString
& aCommand
, ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyValue
>& aArgs
)
472 Reference
< XController
> xController
;
474 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
475 if ( getFrameInterface().is() )
476 xController
= getFrameInterface()->getController();
478 Reference
< XDispatchProvider
> xProvider( xController
, UNO_QUERY
);
479 if ( xProvider
.is() )
481 ::com::sun::star::util::URL aTargetURL
;
482 aTargetURL
.Complete
= aCommand
;
483 getURLTransformer()->parseStrict( aTargetURL
);
485 Reference
< XDispatch
> xDispatch
= xProvider
->queryDispatch( aTargetURL
, ::rtl::OUString(), 0 );
486 if ( xDispatch
.is() )
488 if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
490 ::rtl::OUString sAppName
;
493 static ::rtl::OUString our_aModuleManagerName
= ::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager");
494 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
> xServiceManager
=
495 ::comphelper::getProcessServiceFactory();
496 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XModuleManager
> xModuleManager(
497 xServiceManager
->createInstance(our_aModuleManagerName
)
498 , ::com::sun::star::uno::UNO_QUERY_THROW
);
499 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> xFrame(
500 getFrameInterface(), UNO_QUERY_THROW
);
501 sAppName
= xModuleManager
->identify(xFrame
);
502 } catch(::com::sun::star::uno::Exception
&) {}
503 Sequence
<PropertyValue
> source
;
504 ::comphelper::UiEventsLogger::appendDispatchOrigin(source
, sAppName
, ::rtl::OUString::createFromAscii("SfxToolBoxControl"));
505 ::comphelper::UiEventsLogger::logDispatch(aTargetURL
, source
);
507 xDispatch
->dispatch( aTargetURL
, aArgs
);
513 Any SAL_CALL
SfxToolBoxControl::queryInterface( const Type
& rType
)
514 throw(::com::sun::star::uno::RuntimeException
)
516 ::com::sun::star::uno::Any aRet
= ::cppu::queryInterface( rType
,
517 SAL_STATIC_CAST( ::com::sun::star::awt::XDockableWindowListener
*, this ),
518 SAL_STATIC_CAST( ::com::sun::star::frame::XSubToolbarController
*, this ));
519 return (aRet
.hasValue() ? aRet
: svt::ToolboxController::queryInterface( rType
));
522 void SAL_CALL
SfxToolBoxControl::acquire() throw()
524 OWeakObject::acquire();
527 void SAL_CALL
SfxToolBoxControl::release() throw()
529 OWeakObject::release();
532 void SAL_CALL
SfxToolBoxControl::disposing( const ::com::sun::star::lang::EventObject
& aEvent
)
533 throw( ::com::sun::star::uno::RuntimeException
)
535 svt::ToolboxController::disposing( aEvent
);
539 void SAL_CALL
SfxToolBoxControl::statusChanged( const FeatureStateEvent
& rEvent
)
540 throw ( ::com::sun::star::uno::RuntimeException
)
542 SfxViewFrame
* pViewFrame
= NULL
;
543 Reference
< XController
> xController
;
545 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
546 if ( getFrameInterface().is() )
547 xController
= getFrameInterface()->getController();
549 Reference
< XDispatchProvider
> xProvider( xController
, UNO_QUERY
);
550 if ( xProvider
.is() )
552 Reference
< XDispatch
> xDisp
= xProvider
->queryDispatch( rEvent
.FeatureURL
, ::rtl::OUString(), 0 );
555 Reference
< XUnoTunnel
> xTunnel( xDisp
, UNO_QUERY
);
556 SfxOfficeDispatch
* pDisp
= NULL
;
559 sal_Int64 nImplementation
= xTunnel
->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
560 pDisp
= reinterpret_cast< SfxOfficeDispatch
* >( sal::static_int_cast
< sal_IntPtr
>( nImplementation
));
564 pViewFrame
= pDisp
->GetDispatcher_Impl()->GetFrame();
569 SfxSlotPool
& rPool
= SfxSlotPool::GetSlotPool( pViewFrame
);
570 const SfxSlot
* pSlot
= rPool
.GetUnoSlot( rEvent
.FeatureURL
.Path
);
572 nSlotId
= pSlot
->GetSlotId();
573 else if ( m_aCommandURL
== rEvent
.FeatureURL
.Path
)
574 nSlotId
= GetSlotId();
578 if ( rEvent
.Requery
)
579 svt::ToolboxController::statusChanged( rEvent
);
582 SfxItemState eState
= SFX_ITEM_DISABLED
;
583 SfxPoolItem
* pItem
= NULL
;
584 if ( rEvent
.IsEnabled
)
586 eState
= SFX_ITEM_AVAILABLE
;
587 ::com::sun::star::uno::Type pType
= rEvent
.State
.getValueType();
589 if ( pType
== ::getVoidCppuType() )
591 pItem
= new SfxVoidItem( nSlotId
);
592 eState
= SFX_ITEM_UNKNOWN
;
594 else if ( pType
== ::getBooleanCppuType() )
596 sal_Bool bTemp
= false;
597 rEvent
.State
>>= bTemp
;
598 pItem
= new SfxBoolItem( nSlotId
, bTemp
);
600 else if ( pType
== ::getCppuType((const sal_uInt16
*)0) )
602 sal_uInt16 nTemp
= 0;
603 rEvent
.State
>>= nTemp
;
604 pItem
= new SfxUInt16Item( nSlotId
, nTemp
);
606 else if ( pType
== ::getCppuType((const sal_uInt32
*)0) )
608 sal_uInt32 nTemp
= 0;
609 rEvent
.State
>>= nTemp
;
610 pItem
= new SfxUInt32Item( nSlotId
, nTemp
);
612 else if ( pType
== ::getCppuType((const ::rtl::OUString
*)0) )
614 ::rtl::OUString sTemp
;
615 rEvent
.State
>>= sTemp
;
616 pItem
= new SfxStringItem( nSlotId
, sTemp
);
618 else if ( pType
== ::getCppuType((const ::com::sun::star::frame::status::ItemStatus
*)0) )
620 ItemStatus aItemStatus
;
621 rEvent
.State
>>= aItemStatus
;
622 eState
= aItemStatus
.State
;
623 pItem
= new SfxVoidItem( nSlotId
);
625 else if ( pType
== ::getCppuType((const ::com::sun::star::frame::status::Visibility
*)0) )
627 Visibility aVisibilityStatus
;
628 rEvent
.State
>>= aVisibilityStatus
;
629 pItem
= new SfxVisibilityItem( nSlotId
, aVisibilityStatus
.bVisible
);
634 pItem
= pSlot
->GetType()->CreateItem();
637 pItem
->SetWhich( nSlotId
);
638 pItem
->PutValue( rEvent
.State
);
641 pItem
= new SfxVoidItem( nSlotId
);
645 StateChanged( nSlotId
, eState
, pItem
);
651 // XSubToolbarController
652 ::sal_Bool SAL_CALL
SfxToolBoxControl::opensSubToolbar() throw (::com::sun::star::uno::RuntimeException
)
657 ::rtl::OUString SAL_CALL
SfxToolBoxControl::getSubToolbarName() throw (::com::sun::star::uno::RuntimeException
)
659 return rtl::OUString();
662 void SAL_CALL
SfxToolBoxControl::functionSelected( const ::rtl::OUString
& /*aCommand*/ ) throw (::com::sun::star::uno::RuntimeException
)
664 // must be implemented by sub-class
667 void SAL_CALL
SfxToolBoxControl::updateImage() throw (::com::sun::star::uno::RuntimeException
)
669 // must be implemented by sub-class
672 // XToolbarController
673 void SAL_CALL
SfxToolBoxControl::execute( sal_Int16 KeyModifier
) throw (::com::sun::star::uno::RuntimeException
)
675 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
676 Select( (USHORT
)KeyModifier
);
678 void SAL_CALL
SfxToolBoxControl::click() throw (::com::sun::star::uno::RuntimeException
)
680 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
684 void SAL_CALL
SfxToolBoxControl::doubleClick() throw (::com::sun::star::uno::RuntimeException
)
686 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
690 Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
SfxToolBoxControl::createPopupWindow() throw (::com::sun::star::uno::RuntimeException
)
692 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
693 Window
* pWindow
= CreatePopupWindow();
695 return VCLUnoHelper::GetInterface( pWindow
);
697 return Reference
< ::com::sun::star::awt::XWindow
>();
700 Reference
< ::com::sun::star::awt::XWindow
> SAL_CALL
SfxToolBoxControl::createItemWindow( const Reference
< ::com::sun::star::awt::XWindow
>& rParent
) throw (::com::sun::star::uno::RuntimeException
)
702 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
703 return VCLUnoHelper::GetInterface( CreateItemWindow( VCLUnoHelper::GetWindow( rParent
)));
706 // XDockableWindowListener
707 void SAL_CALL
SfxToolBoxControl::startDocking( const ::com::sun::star::awt::DockingEvent
& )
708 throw (::com::sun::star::uno::RuntimeException
)
711 ::com::sun::star::awt::DockingData SAL_CALL
SfxToolBoxControl::docking( const ::com::sun::star::awt::DockingEvent
& )
712 throw (::com::sun::star::uno::RuntimeException
)
714 return ::com::sun::star::awt::DockingData();
717 void SAL_CALL
SfxToolBoxControl::endDocking( const ::com::sun::star::awt::EndDockingEvent
& )
718 throw (::com::sun::star::uno::RuntimeException
)
722 sal_Bool SAL_CALL
SfxToolBoxControl::prepareToggleFloatingMode( const ::com::sun::star::lang::EventObject
& )
723 throw (::com::sun::star::uno::RuntimeException
)
728 void SAL_CALL
SfxToolBoxControl::toggleFloatingMode( const ::com::sun::star::lang::EventObject
& )
729 throw (::com::sun::star::uno::RuntimeException
)
733 void SAL_CALL
SfxToolBoxControl::closed( const ::com::sun::star::lang::EventObject
& )
734 throw (::com::sun::star::uno::RuntimeException
)
738 void SAL_CALL
SfxToolBoxControl::endPopupMode( const ::com::sun::star::awt::EndPopupModeEvent
& aEvent
)
739 throw (::com::sun::star::uno::RuntimeException
)
741 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
743 ::rtl::OUString aSubToolBarResName
;
744 if ( pImpl
->mxUIElement
.is() )
746 Reference
< XPropertySet
> xPropSet( pImpl
->mxUIElement
, UNO_QUERY
);
751 xPropSet
->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" ))) >>= aSubToolBarResName
;
753 catch ( com::sun::star::beans::UnknownPropertyException
& )
756 catch ( com::sun::star::lang::WrappedTargetException
& )
761 Reference
< XComponent
> xComponent( pImpl
->mxUIElement
, UNO_QUERY
);
762 xComponent
->dispose();
764 pImpl
->mxUIElement
= 0;
766 // if the toolbar was teared-off recreate it and place it at the given position
767 if( aEvent
.bTearoff
)
769 Reference
< XUIElement
> xUIElement
;
770 Reference
< XLayoutManager
> xLayoutManager
= getLayoutManager();
772 if ( !xLayoutManager
.is() )
775 xLayoutManager
->createElement( aSubToolBarResName
);
776 xUIElement
= xLayoutManager
->getElement( aSubToolBarResName
);
777 if ( xUIElement
.is() )
779 Reference
< ::com::sun::star::awt::XWindow
> xParent
= getFrameInterface()->getContainerWindow();
781 Reference
< ::com::sun::star::awt::XWindow
> xSubToolBar( xUIElement
->getRealInterface(), UNO_QUERY
);
782 Reference
< ::com::sun::star::beans::XPropertySet
> xProp( xUIElement
, UNO_QUERY
);
783 if ( xSubToolBar
.is() && xProp
.is() )
785 rtl::OUString
aPersistentString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
788 Window
* pTbxWindow
= VCLUnoHelper::GetWindow( xSubToolBar
);
789 ToolBox
* pToolBar( 0 );
790 if ( pTbxWindow
&& pTbxWindow
->GetType() == WINDOW_TOOLBOX
)
792 pToolBar
= (ToolBox
*)pTbxWindow
;
795 a
= xProp
->getPropertyValue( aPersistentString
);
796 xProp
->setPropertyValue( aPersistentString
, makeAny( sal_False
));
798 xLayoutManager
->hideElement( aSubToolBarResName
);
799 xLayoutManager
->floatWindow( aSubToolBarResName
);
801 xLayoutManager
->setElementPos( aSubToolBarResName
, aEvent
.FloatingPosition
);
802 xLayoutManager
->showElement( aSubToolBarResName
);
804 xProp
->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" )), a
);
807 catch ( ::com::sun::star::uno::RuntimeException
& )
811 catch ( ::com::sun::star::uno::Exception
& )
819 ::Size
SfxToolBoxControl::getPersistentFloatingSize( const Reference
< XFrame
>& /*xFrame*/, const ::rtl::OUString
& /*rSubToolBarResName*/ )
825 void SfxToolBoxControl::createAndPositionSubToolBar( const ::rtl::OUString
& rSubToolBarResName
)
827 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
831 static WeakReference
< XUIElementFactory
> xWeakUIElementFactory
;
833 USHORT nItemId
= pImpl
->pBox
->GetDownItemId();
838 // create element with factory
839 Reference
< XMultiServiceFactory
> xServiceManager
= getServiceManager();
840 Reference
< XFrame
> xFrame
= getFrameInterface();
841 Reference
< XUIElement
> xUIElement
;
842 Reference
< XUIElementFactory
> xUIEementFactory
;
844 xUIEementFactory
= xWeakUIElementFactory
;
845 if ( !xUIEementFactory
.is() )
847 xUIEementFactory
= Reference
< XUIElementFactory
>(
848 xServiceManager
->createInstance(
849 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
850 "com.sun.star.ui.UIElementFactoryManager" ))),
852 xWeakUIElementFactory
= xUIEementFactory
;
855 Sequence
< PropertyValue
> aPropSeq( 3 );
856 aPropSeq
[0].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
857 aPropSeq
[0].Value
<<= xFrame
;
858 aPropSeq
[1].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Persistent" ));
859 aPropSeq
[1].Value
<<= sal_False
;
860 aPropSeq
[2].Name
= rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PopupMode" ));
861 aPropSeq
[2].Value
<<= sal_True
;
865 xUIElement
= xUIEementFactory
->createUIElement( rSubToolBarResName
, aPropSeq
);
867 catch ( ::com::sun::star::container::NoSuchElementException
& )
870 catch ( IllegalArgumentException
& )
874 if ( xUIElement
.is() )
876 Reference
< ::com::sun::star::awt::XWindow
> xParent
= getFrameInterface()->getContainerWindow();
878 Reference
< ::com::sun::star::awt::XWindow
> xSubToolBar( xUIElement
->getRealInterface(), UNO_QUERY
);
879 if ( xSubToolBar
.is() )
881 Reference
< ::com::sun::star::awt::XDockableWindow
> xDockWindow( xSubToolBar
, UNO_QUERY
);
882 xDockWindow
->addDockableWindowListener( Reference
< ::com::sun::star::awt::XDockableWindowListener
>(
883 static_cast< OWeakObject
* >( this ), UNO_QUERY
));
884 xDockWindow
->enableDocking( sal_True
);
886 // keep refererence to UIElement to avoid its destruction
887 if ( pImpl
->mxUIElement
.is() )
889 Reference
< XComponent
> xComponent( pImpl
->mxUIElement
, UNO_QUERY
);
890 xComponent
->dispose();
892 pImpl
->mxUIElement
= xUIElement
;
894 Window
* pParentTbxWindow( pImpl
->pBox
);
895 Window
* pTbxWindow
= VCLUnoHelper::GetWindow( xSubToolBar
);
896 ToolBox
* pToolBar( 0 );
897 if ( pTbxWindow
&& pTbxWindow
->GetType() == WINDOW_TOOLBOX
)
898 pToolBar
= (ToolBox
*)pTbxWindow
;
902 pToolBar
->SetParent( pParentTbxWindow
);
903 ::Size aSize
= getPersistentFloatingSize( xFrame
, rSubToolBarResName
);
904 if ( aSize
.Width() == 0 || aSize
.Height() == 0 )
906 // calc and set size for popup mode
907 aSize
= pToolBar
->CalcPopupWindowSizePixel();
909 pToolBar
->SetSizePixel( aSize
);
911 // open subtoolbox in popup mode
912 Window::GetDockingManager()->StartPopupMode( pImpl
->pBox
, pToolBar
);
919 //--------------------------------------------------------------------
921 void SfxToolBoxControl::SetPopupWindow( SfxPopupWindow
* pWindow
)
923 pImpl
->mpPopupWindow
= pWindow
;
924 pImpl
->mpPopupWindow
->SetPopupModeEndHdl( LINK( this, SfxToolBoxControl
, PopupModeEndHdl
));
925 pImpl
->mpPopupWindow
->SetDeleteLink_Impl( LINK( this, SfxToolBoxControl
, ClosePopupWindow
));
928 //--------------------------------------------------------------------
930 IMPL_LINK( SfxToolBoxControl
, PopupModeEndHdl
, void *, EMPTYARG
)
932 if ( pImpl
->mpPopupWindow
->IsVisible() )
934 // Replace floating window with popup window and destroy
935 // floating window instance.
936 delete pImpl
->mpFloatingWindow
;
937 pImpl
->mpFloatingWindow
= pImpl
->mpPopupWindow
;
938 pImpl
->mpPopupWindow
= 0;
939 // We also need to know when the user tries to use the
941 pImpl
->mpFloatingWindow
->AddEventListener( LINK( pImpl
, SfxToolBoxControl_Impl
, WindowEventListener
));
945 // Popup window has been closed by the user. No replacement, instance
946 // will destroy itself.
947 pImpl
->mpPopupWindow
= 0;
953 //--------------------------------------------------------------------
954 IMPL_LINK( SfxToolBoxControl
, ClosePopupWindow
, SfxPopupWindow
*, pWindow
)
956 if ( pWindow
== pImpl
->mpFloatingWindow
)
957 pImpl
->mpFloatingWindow
= 0;
959 pImpl
->mpPopupWindow
= 0;
964 //--------------------------------------------------------------------
966 void SfxToolBoxControl::StateChanged
970 const SfxPoolItem
* pState
974 DBG_ASSERT( pImpl
->pBox
!= 0, "setting state to dangling ToolBox" );
976 if ( GetId() >= SID_OBJECTMENU0
&& GetId() <= SID_OBJECTMENU_LAST
)
979 // enabled/disabled-Flag pauschal korrigieren
980 pImpl
->pBox
->EnableItem( GetId(), eState
!= SFX_ITEM_DISABLED
);
982 USHORT nItemBits
= pImpl
->pBox
->GetItemBits( GetId() );
983 nItemBits
&= ~TIB_CHECKABLE
;
984 TriState eTri
= STATE_NOCHECK
;
987 case SFX_ITEM_AVAILABLE
:
989 if ( pState
->ISA(SfxBoolItem
) )
991 // BoolItem fuer checken
992 if ( ((const SfxBoolItem
*)pState
)->GetValue() )
994 nItemBits
|= TIB_CHECKABLE
;
996 else if ( pState
->ISA(SfxEnumItemInterface
) &&
997 ((SfxEnumItemInterface
*)pState
)->HasBoolValue())
999 // EnumItem wie Bool behandeln
1000 if ( ((const SfxEnumItemInterface
*)pState
)->GetBoolValue() )
1002 nItemBits
|= TIB_CHECKABLE
;
1004 else if ( pImpl
->bShowString
&& pState
->ISA(SfxStringItem
) )
1005 pImpl
->pBox
->SetItemText(nId
, ((const SfxStringItem
*)pState
)->GetValue() );
1009 case SFX_ITEM_DONTCARE
:
1011 eTri
= STATE_DONTKNOW
;
1012 nItemBits
|= TIB_CHECKABLE
;
1016 pImpl
->pBox
->SetItemState( GetId(), eTri
);
1017 pImpl
->pBox
->SetItemBits( GetId(), nItemBits
);
1020 //--------------------------------------------------------------------
1022 void SfxToolBoxControl::Select( USHORT nModifier
)
1024 pImpl
->nSelectModifier
= nModifier
;
1025 Select( BOOL((nModifier
& KEY_MOD1
)!=0) );
1028 //--------------------------------------------------------------------
1030 void SfxToolBoxControl::Select( BOOL
/*bMod1*/ )
1032 svt::ToolboxController::execute( pImpl
->nSelectModifier
);
1035 //--------------------------------------------------------------------
1037 void SfxToolBoxControl::DoubleClick()
1041 //--------------------------------------------------------------------
1043 void SfxToolBoxControl::Click()
1047 //--------------------------------------------------------------------
1049 SfxPopupWindowType
SfxToolBoxControl::GetPopupWindowType() const
1051 return SFX_POPUPWINDOW_NONE
;
1054 //--------------------------------------------------------------------
1056 SfxPopupWindow
* SfxToolBoxControl::CreatePopupWindow()
1061 SfxPopupWindow
* SfxToolBoxControl::CreatePopupWindowCascading()
1066 //--------------------------------------------------------------------
1068 Window
* SfxToolBoxControl::CreateItemWindow( Window
* )
1073 //--------------------------------------------------------------------
1075 SfxFrameStatusListener::SfxFrameStatusListener(
1076 const Reference
< XMultiServiceFactory
>& rServiceManager
,
1077 const Reference
< XFrame
>& xFrame
,
1078 SfxStatusListenerInterface
* pCallee
) :
1079 svt::FrameStatusListener( rServiceManager
, xFrame
),
1080 m_pCallee( pCallee
)
1084 //--------------------------------------------------------------------
1086 SfxFrameStatusListener::~SfxFrameStatusListener()
1090 //--------------------------------------------------------------------
1093 void SAL_CALL
SfxFrameStatusListener::statusChanged( const ::com::sun::star::frame::FeatureStateEvent
& rEvent
)
1094 throw ( ::com::sun::star::uno::RuntimeException
)
1096 SfxViewFrame
* pViewFrame
= NULL
;
1097 Reference
< XController
> xController
;
1099 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
1100 if ( m_xFrame
.is() )
1101 xController
= m_xFrame
->getController();
1103 Reference
< XDispatchProvider
> xProvider( xController
, UNO_QUERY
);
1104 if ( xProvider
.is() )
1106 Reference
< XDispatch
> xDisp
= xProvider
->queryDispatch( rEvent
.FeatureURL
, ::rtl::OUString(), 0 );
1109 Reference
< XUnoTunnel
> xTunnel( xDisp
, UNO_QUERY
);
1110 SfxOfficeDispatch
* pDisp
= NULL
;
1113 sal_Int64 nImplementation
= xTunnel
->getSomething(SfxOfficeDispatch::impl_getStaticIdentifier());
1114 pDisp
= reinterpret_cast< SfxOfficeDispatch
* >( sal::static_int_cast
< sal_IntPtr
>( nImplementation
));
1118 pViewFrame
= pDisp
->GetDispatcher_Impl()->GetFrame();
1123 SfxSlotPool
& rPool
= SfxSlotPool::GetSlotPool( pViewFrame
);
1124 const SfxSlot
* pSlot
= rPool
.GetUnoSlot( rEvent
.FeatureURL
.Path
);
1126 nSlotId
= pSlot
->GetSlotId();
1130 if ( rEvent
.Requery
)
1132 // requery for the notified state
1133 addStatusListener( rEvent
.FeatureURL
.Complete
);
1137 SfxItemState eState
= SFX_ITEM_DISABLED
;
1138 SfxPoolItem
* pItem
= NULL
;
1139 if ( rEvent
.IsEnabled
)
1141 eState
= SFX_ITEM_AVAILABLE
;
1142 ::com::sun::star::uno::Type pType
= rEvent
.State
.getValueType();
1144 if ( pType
== ::getVoidCppuType() )
1146 pItem
= new SfxVoidItem( nSlotId
);
1147 eState
= SFX_ITEM_UNKNOWN
;
1149 else if ( pType
== ::getBooleanCppuType() )
1151 sal_Bool bTemp
= false;
1152 rEvent
.State
>>= bTemp
;
1153 pItem
= new SfxBoolItem( nSlotId
, bTemp
);
1155 else if ( pType
== ::getCppuType((const sal_uInt16
*)0) )
1157 sal_uInt16 nTemp
= 0;
1158 rEvent
.State
>>= nTemp
;
1159 pItem
= new SfxUInt16Item( nSlotId
, nTemp
);
1161 else if ( pType
== ::getCppuType((const sal_uInt32
*)0) )
1163 sal_uInt32 nTemp
= 0;
1164 rEvent
.State
>>= nTemp
;
1165 pItem
= new SfxUInt32Item( nSlotId
, nTemp
);
1167 else if ( pType
== ::getCppuType((const ::rtl::OUString
*)0) )
1169 ::rtl::OUString sTemp
;
1170 rEvent
.State
>>= sTemp
;
1171 pItem
= new SfxStringItem( nSlotId
, sTemp
);
1173 else if ( pType
== ::getCppuType((const ::com::sun::star::frame::status::ItemStatus
*)0) )
1175 ItemStatus aItemStatus
;
1176 rEvent
.State
>>= aItemStatus
;
1177 eState
= aItemStatus
.State
;
1178 pItem
= new SfxVoidItem( nSlotId
);
1180 else if ( pType
== ::getCppuType((const ::com::sun::star::frame::status::Visibility
*)0) )
1182 Visibility aVisibilityStatus
;
1183 rEvent
.State
>>= aVisibilityStatus
;
1184 pItem
= new SfxVisibilityItem( nSlotId
, aVisibilityStatus
.bVisible
);
1189 pItem
= pSlot
->GetType()->CreateItem();
1192 pItem
->SetWhich( nSlotId
);
1193 pItem
->PutValue( rEvent
.State
);
1196 pItem
= new SfxVoidItem( nSlotId
);
1201 m_pCallee
->StateChanged( nSlotId
, eState
, pItem
);
1207 //--------------------------------------------------------------------
1209 SfxPopupWindow::SfxPopupWindow(
1211 const Reference
< XFrame
>& rFrame
,
1213 FloatingWindow( SFX_APP()->GetTopWindow(), nBits
)
1214 , m_bFloating(FALSE
)
1215 , m_bCascading( FALSE
)
1217 , m_xFrame( rFrame
)
1218 , m_pStatusListener( 0 )
1220 m_xServiceManager
= ::comphelper::getProcessServiceFactory();
1222 Window
* pWindow
= GetTopMostParentSystemWindow( this );
1224 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->AddWindow( this );
1227 //--------------------------------------------------------------------
1229 SfxPopupWindow::SfxPopupWindow(
1231 const Reference
< XFrame
>& rFrame
,
1232 const ResId
&rId
) :
1233 FloatingWindow( SFX_APP()->GetTopWindow(), rId
)
1234 , m_bFloating(FALSE
)
1235 , m_bCascading( FALSE
)
1237 , m_xFrame( rFrame
)
1238 , m_pStatusListener( 0 )
1240 m_xServiceManager
= ::comphelper::getProcessServiceFactory();
1242 Window
* pWindow
= GetTopMostParentSystemWindow( this );
1244 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->AddWindow( this );
1247 //--------------------------------------------------------------------
1249 SfxPopupWindow::SfxPopupWindow(
1251 const Reference
< XFrame
>& rFrame
,
1252 Window
* pParentWindow
,
1254 FloatingWindow( pParentWindow
, nBits
)
1255 , m_bFloating(FALSE
)
1256 , m_bCascading( FALSE
)
1258 , m_xFrame( rFrame
)
1259 , m_pStatusListener( 0 )
1261 m_xServiceManager
= ::comphelper::getProcessServiceFactory();
1263 Window
* pWindow
= GetTopMostParentSystemWindow( this );
1265 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->AddWindow( this );
1268 //--------------------------------------------------------------------
1270 SfxPopupWindow::SfxPopupWindow(
1272 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rFrame
,
1273 Window
* pParentWindow
,
1274 const ResId
&rId
) :
1275 FloatingWindow( pParentWindow
, rId
)
1276 , m_bFloating(FALSE
)
1277 , m_bCascading( FALSE
)
1279 , m_xFrame( rFrame
)
1280 , m_pStatusListener( 0 )
1282 m_xServiceManager
= ::comphelper::getProcessServiceFactory();
1284 Window
* pWindow
= GetTopMostParentSystemWindow( this );
1286 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->AddWindow( this );
1289 //--------------------------------------------------------------------
1291 SfxPopupWindow::~SfxPopupWindow()
1293 if ( m_xStatusListener
.is() )
1295 m_xStatusListener
->dispose();
1296 m_xStatusListener
.clear();
1299 Window
* pWindow
= GetTopMostParentSystemWindow( this );
1301 ((SystemWindow
*)pWindow
)->GetTaskPaneList()->RemoveWindow( this );
1304 //--------------------------------------------------------------------
1306 SfxFrameStatusListener
* SfxPopupWindow::GetOrCreateStatusListener()
1308 if ( !m_xStatusListener
.is() )
1310 m_pStatusListener
= new SfxFrameStatusListener(
1314 m_xStatusListener
= Reference
< XComponent
>( static_cast< cppu::OWeakObject
* >(
1315 m_pStatusListener
), UNO_QUERY
);
1318 return m_pStatusListener
;
1321 //--------------------------------------------------------------------
1323 void SfxPopupWindow::BindListener()
1325 GetOrCreateStatusListener();
1326 if ( m_xStatusListener
.is() )
1327 m_pStatusListener
->bindListener();
1330 //--------------------------------------------------------------------
1332 void SfxPopupWindow::UnbindListener()
1334 GetOrCreateStatusListener();
1335 if ( m_xStatusListener
.is() )
1336 m_pStatusListener
->unbindListener();
1339 //--------------------------------------------------------------------
1341 void SfxPopupWindow::AddStatusListener( const rtl::OUString
& rCommandURL
)
1343 GetOrCreateStatusListener();
1344 if ( m_xStatusListener
.is() )
1345 m_pStatusListener
->addStatusListener( rCommandURL
);
1348 //--------------------------------------------------------------------
1350 void SfxPopupWindow::RemoveStatusListener( const rtl::OUString
& rCommandURL
)
1352 GetOrCreateStatusListener();
1353 if ( m_xStatusListener
.is() )
1354 m_pStatusListener
->removeStatusListener( rCommandURL
);
1357 //--------------------------------------------------------------------
1359 void SfxPopupWindow::UpdateStatus( const rtl::OUString
& rCommandURL
)
1361 GetOrCreateStatusListener();
1362 if ( m_xStatusListener
.is() )
1363 m_pStatusListener
->updateStatus( rCommandURL
);
1366 //--------------------------------------------------------------------
1368 BOOL
SfxPopupWindow::Close()
1370 m_bFloating
= FALSE
;
1371 FloatingWindow::Close();
1377 //--------------------------------------------------------------------
1379 void SfxPopupWindow::PopupModeEnd()
1381 //! to allow PopupModeEndHdl to be called
1382 FloatingWindow::PopupModeEnd();
1387 DeleteFloatingWindow();
1394 //--------------------------------------------------------------------
1396 void SfxPopupWindow::DeleteFloatingWindow()
1405 //--------------------------------------------------------------------
1407 void SfxPopupWindow::MouseMove( const ::MouseEvent
& rMEvt
)
1409 if ( m_bCascading
== FALSE
)
1410 FloatingWindow::MouseMove( rMEvt
);
1413 // MouseMove-Event an die Children forwarden
1414 ::Point aPos
= rMEvt
.GetPosPixel();
1415 ::Point aScrPos
= OutputToScreenPixel( aPos
);
1417 Window
* pWindow
= GetChild( i
);
1420 ::MouseEvent
aMEvt( pWindow
->ScreenToOutputPixel( aScrPos
),
1421 rMEvt
.GetClicks(), rMEvt
.GetMode(),
1422 rMEvt
.GetButtons(), rMEvt
.GetModifier() );
1423 pWindow
->MouseMove( rMEvt
);
1426 pWindow
= GetChild( i
);
1431 //--------------------------------------------------------------------
1433 void SfxPopupWindow::StartCascading()
1438 void SfxPopupWindow::EndCascading()
1440 m_bCascading
= FALSE
;
1443 //--------------------------------------------------------------------
1445 SfxPopupWindow
* SfxPopupWindow::Clone() const
1449 Diese Methode mu\s "uberladen werden, um dieses Popup auch im
1450 Presentations-Modus anzuzeigen. Sie wird gerufen, wenn ein Show()
1451 sinnlos w"are, da der Parent nicht das Presentations-Window ist.
1452 Beim neu erzeugen wird automatisch das neue Top-Window verwendet, so
1453 da\s der Parent das Presentations-Window ist und das neue Popup somit
1461 //--------------------------------------------------------------------
1463 void SfxPopupWindow::StateChanged(
1465 SfxItemState eState
,
1466 const SfxPoolItem
* /*pState*/ )
1469 Siehe auch <SfxControllerItem::StateChanged()>. Au\serdem wird
1470 bei eState==SFX_ITEM_DISABLED das Popup gehided und in allen anderen
1471 F"allen, falls es floating ist, wieder angezeigt. Daher mu\s die
1472 Basisklasse i.d.R. gerufen werden.
1474 Es findet wegen des Parents eine Sonderbehandlung f"ur den
1475 Presentationsmodus statt.
1480 if ( SFX_ITEM_DISABLED
== eState
)
1484 else if ( m_bFloating
)
1486 Show( TRUE
, SHOW_NOFOCUSCHANGE
| SHOW_NOACTIVATE
);
1490 //--------------------------------------------------------------------
1492 IMPL_LINK( SfxPopupWindow
, Delete
, void *, EMPTYARG
)
1494 if ( m_aDeleteLink
.IsSet() )
1495 m_aDeleteLink
.Call( this );
1500 //--------------------------------------------------------------------
1502 SfxAppToolBoxControl_Impl::SfxAppToolBoxControl_Impl( USHORT nSlotId
, USHORT nId
, ToolBox
& rBox
)
1503 : SfxToolBoxControl( nSlotId
, nId
, rBox
)
1504 , bBigImages( FALSE
)
1507 rBox
.SetHelpId( nId
, HID_TBXCONTROL_FILENEW
);
1508 rBox
.SetItemBits( nId
, rBox
.GetItemBits( nId
) | TIB_DROPDOWN
);
1510 // Determine the current background color of the menus
1511 const StyleSettings
& rSettings
= Application::GetSettings().GetStyleSettings();
1512 m_nSymbolsStyle
= rSettings
.GetSymbolsStyle();
1513 m_bWasHiContrastMode
= rSettings
.GetMenuColor().IsDark();
1514 m_bShowMenuImages
= SvtMenuOptions().IsMenuIconsEnabled();
1516 SetImage( String() );
1519 SfxAppToolBoxControl_Impl::~SfxAppToolBoxControl_Impl()
1524 //_____________________________________________________
1526 it return the existing state of the given URL in the popupmenu of this toolbox control.
1528 If the given URL can be located as an action command of one menu item of the
1529 popup menu of this control, we return TRUE. Otherwhise we return FALSE.
1530 Further we return a fallback URL, in case we have to return FALSE. Because
1531 the outside code must select a valid item of the popup menu everytime ...
1532 and we define it here. By the way this m ethod was written to handle
1533 error situations gracefully. E.g. it can be called during creation time
1534 but then we have no valid menu. For this case we know another fallback URL.
1535 Then we return the private:factory/ URL of the default factory.
1538 pounts to the popup menu, on which item we try to locate the given URL
1539 Can be NULL! Search will be supressed then.
1542 the URL for searching
1545 contains the fallback URL in case we return FALSE
1546 Must point to valid memory!
1549 contains the image of the menu for the URL.
1551 @return TRUE - if URL could be located as an item of the popup menu.
1554 BOOL
Impl_ExistURLInMenu( const PopupMenu
*pMenu
,
1559 BOOL bValidFallback
= FALSE
;
1560 if (pMenu
&& sURL
.Len())
1562 USHORT c
= pMenu
->GetItemCount();
1563 for (USHORT p
=0; p
<c
; ++p
)
1565 USHORT nId
= pMenu
->GetItemId(p
);
1566 String
aCmd( pMenu
->GetItemCommand(nId
) );
1568 if (!bValidFallback
&& aCmd
.Len())
1571 bValidFallback
= TRUE
;
1574 if (aCmd
.Search(sURL
)==0)//match even if the menu command is more detailed (maybe an additional query) #i28667#
1577 *pImage
= pMenu
->GetItemImage( nId
);
1583 if (!bValidFallback
)
1585 *pFallback
= DEFINE_CONST_UNICODE("private:factory/");
1586 *pFallback
+= String(SvtModuleOptions().GetDefaultModuleName());
1592 long Select_Impl( void* pHdl
, void* pVoid
);
1594 SfxPopupWindow
* SfxAppToolBoxControl_Impl::CreatePopupWindow()
1596 ToolBox
& rBox
= GetToolBox();
1597 ::Rectangle
aRect( rBox
.GetItemRect( GetId() ) );
1601 ::framework::MenuConfiguration
aConf( m_xServiceManager
);
1602 if ( m_aCommandURL
.equalsAscii( ".uno:AddDirect" ))
1603 pMenu
= aConf
.CreateBookmarkMenu( m_xFrame
, BOOKMARK_NEWMENU
);
1605 pMenu
= aConf
.CreateBookmarkMenu( m_xFrame
, BOOKMARK_WIZARDMENU
);
1610 pMenu
->SetSelectHdl( Link( NULL
, Select_Impl
) );
1611 pMenu
->SetActivateHdl( LINK( this, SfxAppToolBoxControl_Impl
, Activate
));
1612 rBox
.SetItemDown( GetId(), TRUE
);
1613 USHORT nSelected
= pMenu
->Execute( &rBox
, aRect
, POPUPMENU_EXECUTE_DOWN
);
1616 aLastURL
= pMenu
->GetItemCommand( nSelected
);
1617 SetImage( pMenu
->GetItemCommand( nSelected
) );
1620 rBox
.SetItemDown( GetId(), FALSE
);
1626 void SfxAppToolBoxControl_Impl::SetImage( const String
&rURL
)
1628 /* We accept URL's here only, which exist as items of our internal popup menu.
1629 All other ones will be ignored and a fallback is used ... */
1633 BOOL bValid
= Impl_ExistURLInMenu(pMenu
,aURL
,&sFallback
,&aMenuImage
);
1637 BOOL bBig
= SvtMiscOptions().AreCurrentSymbolsLarge();
1638 BOOL bHC
= GetToolBox().GetBackground().GetColor().IsDark();
1639 Image aImage
= SvFileInformationManager::GetImageNoDefault( INetURLObject( aURL
), bBig
, bHC
);
1641 aImage
= !!aMenuImage
? aMenuImage
:
1642 SvFileInformationManager::GetImage( INetURLObject( aURL
), bBig
, bHC
);
1643 Size
aBigSize( GetToolBox().GetDefaultImageSize() );
1644 if ( bBig
&& aImage
.GetSizePixel() != aBigSize
)
1646 BitmapEx
aScaleBmpEx( aImage
.GetBitmapEx() );
1647 aScaleBmpEx
.Scale( aBigSize
, BMP_SCALE_INTERPOLATE
);
1648 GetToolBox().SetItemImage( GetId(), Image( aScaleBmpEx
) );
1651 GetToolBox().SetItemImage( GetId(), aImage
);
1655 void SfxAppToolBoxControl_Impl::StateChanged
1658 SfxItemState eState
,
1659 const SfxPoolItem
* pState
1662 if ( pState
&& pState
->ISA(SfxStringItem
) )
1664 // Important step for following SetImage() call!
1665 // It needs the valid pMenu item to fullfill it's specification
1666 // to check for supported URLs ...
1669 ::framework::MenuConfiguration
aConf( m_xServiceManager
);
1670 // This toolbox controller is used for two popup menus (new documents and wizards!). Create the correct
1671 // popup menu according to the slot ID our controller has been initialized with.
1672 if ( nSlotId
== SID_NEWDOCDIRECT
)
1673 pMenu
= aConf
.CreateBookmarkMenu( m_xFrame
, BOOKMARK_NEWMENU
);
1675 pMenu
= aConf
.CreateBookmarkMenu( m_xFrame
, BOOKMARK_WIZARDMENU
);
1678 GetToolBox().EnableItem( GetId(), eState
!= SFX_ITEM_DISABLED
);
1679 SetImage(((const SfxStringItem
*)pState
)->GetValue());
1682 SfxToolBoxControl::StateChanged( nSlotId
, eState
, pState
);
1685 //--------------------------------------------------------------------
1687 void SfxAppToolBoxControl_Impl::Select( BOOL bMod1
)
1689 if( aLastURL
.Len() )
1692 Reference
< XDispatch
> xDispatch
;
1693 Reference
< XDispatchProvider
> xDispatchProvider( getFrameInterface(), UNO_QUERY
);
1695 if ( xDispatchProvider
.is() )
1697 aTargetURL
.Complete
= aLastURL
;
1698 getURLTransformer()->parseStrict( aTargetURL
);
1700 ::rtl::OUString
aTarget( ::rtl::OUString::createFromAscii( "_default" ));
1703 ::framework::MenuConfiguration::Attributes
* pMenuAttributes
=
1704 (::framework::MenuConfiguration::Attributes
*)pMenu
->GetUserValue( pMenu
->GetCurItemId() );
1706 if ( pMenuAttributes
)
1707 aTarget
= pMenuAttributes
->aTargetFrame
;
1710 xDispatch
= xDispatchProvider
->queryDispatch( aTargetURL
, aTarget
, 0 );
1712 if ( xDispatch
.is() )
1714 Sequence
< PropertyValue
> aArgs( 1 );
1716 aArgs
[0].Name
= ::rtl::OUString::createFromAscii( "Referer" );
1717 aArgs
[0].Value
= makeAny( ::rtl::OUString::createFromAscii( SFX_REFERER_USER
));
1719 ExecuteInfo
* pExecuteInfo
= new ExecuteInfo
;
1720 pExecuteInfo
->xDispatch
= xDispatch
;
1721 pExecuteInfo
->aTargetURL
= aTargetURL
;
1722 pExecuteInfo
->aArgs
= aArgs
;
1723 Application::PostUserEvent( STATIC_LINK(0, SfxAppToolBoxControl_Impl
, ExecuteHdl_Impl
), pExecuteInfo
);
1728 SfxToolBoxControl::Select( bMod1
);
1731 //--------------------------------------------------------------------
1732 long Select_Impl( void* /*pHdl*/, void* pVoid
)
1734 Menu
* pMenu
= (Menu
*)pVoid
;
1735 String
aURL( pMenu
->GetItemCommand( pMenu
->GetCurItemId() ) );
1740 Reference
< ::com::sun::star::frame::XFramesSupplier
> xDesktop
=
1741 Reference
< ::com::sun::star::frame::XFramesSupplier
>( ::comphelper::getProcessServiceFactory()->createInstance(
1742 DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY
);
1743 Reference
< ::com::sun::star::frame::XFrame
> xFrame( xDesktop
, UNO_QUERY
);
1746 aTargetURL
.Complete
= aURL
;
1747 Reference
< XURLTransformer
> xTrans( ::comphelper::getProcessServiceFactory()->createInstance(
1748 rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )),
1750 xTrans
->parseStrict( aTargetURL
);
1752 Reference
< XDispatchProvider
> xProv( xFrame
, UNO_QUERY
);
1753 Reference
< XDispatch
> xDisp
;
1756 if ( aTargetURL
.Protocol
.compareToAscii("slot:") == COMPARE_EQUAL
)
1757 xDisp
= xProv
->queryDispatch( aTargetURL
, ::rtl::OUString(), 0 );
1760 ::rtl::OUString
aTargetFrame( ::rtl::OUString::createFromAscii( "_blank" ) );
1761 ::framework::MenuConfiguration::Attributes
* pMenuAttributes
=
1762 (::framework::MenuConfiguration::Attributes
*)pMenu
->GetUserValue( pMenu
->GetCurItemId() );
1764 if ( pMenuAttributes
)
1765 aTargetFrame
= pMenuAttributes
->aTargetFrame
;
1767 xDisp
= xProv
->queryDispatch( aTargetURL
, aTargetFrame
, 0 );
1773 SfxAppToolBoxControl_Impl::ExecuteInfo
* pExecuteInfo
= new SfxAppToolBoxControl_Impl::ExecuteInfo
;
1774 pExecuteInfo
->xDispatch
= xDisp
;
1775 pExecuteInfo
->aTargetURL
= aTargetURL
;
1776 pExecuteInfo
->aArgs
= Sequence
< PropertyValue
>();
1777 Application::PostUserEvent( STATIC_LINK( 0, SfxAppToolBoxControl_Impl
, ExecuteHdl_Impl
), pExecuteInfo
);
1783 IMPL_LINK( SfxAppToolBoxControl_Impl
, Activate
, Menu
*, pActMenu
)
1787 const StyleSettings
& rSettings
= Application::GetSettings().GetStyleSettings();
1788 ULONG nSymbolsStyle
= rSettings
.GetSymbolsStyle();
1789 BOOL bIsHiContrastMode
= rSettings
.GetMenuColor().IsDark();
1790 BOOL bShowMenuImages
= SvtMenuOptions().IsMenuIconsEnabled();
1792 if (( nSymbolsStyle
!= m_nSymbolsStyle
) ||
1793 ( bIsHiContrastMode
!= m_bWasHiContrastMode
) ||
1794 ( bShowMenuImages
!= m_bShowMenuImages
))
1796 m_nSymbolsStyle
= nSymbolsStyle
;
1797 m_bWasHiContrastMode
= bIsHiContrastMode
;
1798 m_bShowMenuImages
= bShowMenuImages
;
1800 USHORT nCount
= pActMenu
->GetItemCount();
1801 for ( USHORT nSVPos
= 0; nSVPos
< nCount
; nSVPos
++ )
1803 USHORT nId
= pActMenu
->GetItemId( nSVPos
);
1804 if ( pActMenu
->GetItemType( nSVPos
) != MENUITEM_SEPARATOR
)
1806 if ( bShowMenuImages
)
1808 sal_Bool bImageSet
= sal_False
;
1809 ::rtl::OUString aImageId
;
1810 ::framework::MenuConfiguration::Attributes
* pMenuAttributes
=
1811 (::framework::MenuConfiguration::Attributes
*)pMenu
->GetUserValue( nId
);
1813 if ( pMenuAttributes
)
1814 aImageId
= pMenuAttributes
->aImageId
; // Retrieve image id from menu attributes
1816 if ( aImageId
.getLength() > 0 )
1818 Reference
< ::com::sun::star::frame::XFrame
> xFrame
;
1819 Image aImage
= GetImage( xFrame
, aImageId
, FALSE
, bIsHiContrastMode
);
1822 bImageSet
= sal_True
;
1823 pActMenu
->SetItemImage( nId
, aImage
);
1827 String
aCmd( pActMenu
->GetItemCommand( nId
) );
1828 if ( !bImageSet
&& aCmd
.Len() )
1830 Image aImage
= SvFileInformationManager::GetImage(
1831 INetURLObject(aCmd
), FALSE
, bIsHiContrastMode
);
1833 pActMenu
->SetItemImage( nId
, aImage
);
1837 pActMenu
->SetItemImage( nId
, Image() );
1848 //--------------------------------------------------------------------
1850 IMPL_STATIC_LINK_NOINSTANCE( SfxAppToolBoxControl_Impl
, ExecuteHdl_Impl
, ExecuteInfo
*, pExecuteInfo
)
1852 /* i62706: Don't catch all exceptions. We hide all problems here and are not able
1853 to handle them on higher levels.
1857 // Asynchronous execution as this can lead to our own destruction!
1858 // Framework can recycle our current frame and the layout manager disposes all user interface
1859 // elements if a component gets detached from its frame!
1860 pExecuteInfo
->xDispatch
->dispatch( pExecuteInfo
->aTargetURL
, pExecuteInfo
->aArgs
);
1863 catch (const ::com::sun::star::document::CorruptedFilterConfigurationException& exFilters)
1867 catch (const Exception& )
1871 delete pExecuteInfo
;
1875 //--------------------------------------------------------------------
1877 void SfxAppToolBoxControl_Impl::Click( )