xref: /AOO41X/main/framework/source/uielement/generictoolbarcontroller.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_framework.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #ifndef __FRAMEWORK_UIELEMENT_GENERICTOOLBARCONTROLLER_HXX
32*cdf0e10cSrcweir #include "uielement/generictoolbarcontroller.hxx"
33*cdf0e10cSrcweir #endif
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36*cdf0e10cSrcweir //  my own includes
37*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #ifndef __FRAMEWORK_TOOLBAR_HXX_
40*cdf0e10cSrcweir #include "uielement/toolbar.hxx"
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44*cdf0e10cSrcweir //  interface includes
45*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
46*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemStatus.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/frame/status/ItemState.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/frame/status/Visibility.hpp>
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55*cdf0e10cSrcweir //  other includes
56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
57*cdf0e10cSrcweir #include <svtools/toolboxcontroller.hxx>
58*cdf0e10cSrcweir #include <vos/mutex.hxx>
59*cdf0e10cSrcweir #include <vcl/svapp.hxx>
60*cdf0e10cSrcweir #ifndef _VCL_MNEMONIC_HXX_
61*cdf0e10cSrcweir #include <vcl/mnemonic.hxx>
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #include <tools/urlobj.hxx>
64*cdf0e10cSrcweir #include <classes/resource.hrc>
65*cdf0e10cSrcweir #include <classes/fwkresid.hxx>
66*cdf0e10cSrcweir #include <dispatch/uieventloghelper.hxx>
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx>
69*cdf0e10cSrcweir #include <uielement/menubarmanager.hxx>
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir using namespace ::com::sun::star::awt;
72*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
73*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
74*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
75*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
76*cdf0e10cSrcweir using namespace ::com::sun::star::frame::status;
77*cdf0e10cSrcweir using namespace ::com::sun::star::util;
78*cdf0e10cSrcweir using namespace ::com::sun::star::container;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir namespace framework
81*cdf0e10cSrcweir {
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir static sal_Bool isEnumCommand( const rtl::OUString& rCommand )
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     INetURLObject aURL( rCommand );
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     if (( aURL.GetProtocol() == INET_PROT_UNO ) &&
88*cdf0e10cSrcweir         ( aURL.GetURLPath().indexOf( '.' ) != -1))
89*cdf0e10cSrcweir         return sal_True;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     return sal_False;
92*cdf0e10cSrcweir }
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir static rtl::OUString getEnumCommand( const rtl::OUString& rCommand )
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     INetURLObject aURL( rCommand );
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     rtl::OUString   aEnumCommand;
99*cdf0e10cSrcweir     String          aURLPath = aURL.GetURLPath();
100*cdf0e10cSrcweir     xub_StrLen      nIndex   = aURLPath.Search( '.' );
101*cdf0e10cSrcweir     if (( nIndex > 0 ) && ( nIndex < aURLPath.Len() ))
102*cdf0e10cSrcweir         aEnumCommand = aURLPath.Copy( nIndex+1 );
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     return aEnumCommand;
105*cdf0e10cSrcweir }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir static rtl::OUString getMasterCommand( const rtl::OUString& rCommand )
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     rtl::OUString aMasterCommand( rCommand );
110*cdf0e10cSrcweir     INetURLObject aURL( rCommand );
111*cdf0e10cSrcweir     if ( aURL.GetProtocol() == INET_PROT_UNO )
112*cdf0e10cSrcweir     {
113*cdf0e10cSrcweir         sal_Int32 nIndex = aURL.GetURLPath().indexOf( '.' );
114*cdf0e10cSrcweir         if ( nIndex )
115*cdf0e10cSrcweir         {
116*cdf0e10cSrcweir             aURL.SetURLPath( aURL.GetURLPath().copy( 0, nIndex ) );
117*cdf0e10cSrcweir             aMasterCommand = aURL.GetMainURL( INetURLObject::NO_DECODE );
118*cdf0e10cSrcweir         }
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir     return aMasterCommand;
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir struct ExecuteInfo
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch >     xDispatch;
126*cdf0e10cSrcweir     ::com::sun::star::util::URL                                                aTargetURL;
127*cdf0e10cSrcweir     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >  aArgs;
128*cdf0e10cSrcweir };
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir GenericToolbarController::GenericToolbarController( const Reference< XMultiServiceFactory >& rServiceManager,
131*cdf0e10cSrcweir                                                     const Reference< XFrame >&               rFrame,
132*cdf0e10cSrcweir                                                     ToolBox*                                 pToolbar,
133*cdf0e10cSrcweir                                                     sal_uInt16                                   nID,
134*cdf0e10cSrcweir                                                     const ::rtl::OUString&                          aCommand ) :
135*cdf0e10cSrcweir     svt::ToolboxController( rServiceManager, rFrame, aCommand )
136*cdf0e10cSrcweir     ,   m_pToolbar( pToolbar )
137*cdf0e10cSrcweir     ,   m_nID( nID )
138*cdf0e10cSrcweir     ,   m_bEnumCommand( isEnumCommand( aCommand ))
139*cdf0e10cSrcweir     ,   m_bMadeInvisible( sal_False )
140*cdf0e10cSrcweir     ,   m_aEnumCommand( getEnumCommand( aCommand ))
141*cdf0e10cSrcweir {
142*cdf0e10cSrcweir     if ( m_bEnumCommand )
143*cdf0e10cSrcweir         addStatusListener( getMasterCommand( aCommand ) );
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir GenericToolbarController::~GenericToolbarController()
147*cdf0e10cSrcweir {
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir void SAL_CALL GenericToolbarController::dispose()
151*cdf0e10cSrcweir throw ( RuntimeException )
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir     svt::ToolboxController::dispose();
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     m_pToolbar = 0;
158*cdf0e10cSrcweir     m_nID = 0;
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir void SAL_CALL GenericToolbarController::execute( sal_Int16 KeyModifier )
162*cdf0e10cSrcweir throw ( RuntimeException )
163*cdf0e10cSrcweir {
164*cdf0e10cSrcweir     Reference< XDispatch >       xDispatch;
165*cdf0e10cSrcweir     Reference< XURLTransformer > xURLTransformer;
166*cdf0e10cSrcweir     ::rtl::OUString                     aCommandURL;
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir         if ( m_bDisposed )
172*cdf0e10cSrcweir             throw DisposedException();
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir         if ( m_bInitialized &&
175*cdf0e10cSrcweir              m_xFrame.is() &&
176*cdf0e10cSrcweir              m_xServiceManager.is() &&
177*cdf0e10cSrcweir              m_aCommandURL.getLength() )
178*cdf0e10cSrcweir         {
179*cdf0e10cSrcweir             xURLTransformer = Reference< XURLTransformer >( m_xServiceManager->createInstance(
180*cdf0e10cSrcweir                                                                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))),
181*cdf0e10cSrcweir                                                             UNO_QUERY );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir             aCommandURL = m_aCommandURL;
184*cdf0e10cSrcweir             URLToDispatchMap::iterator pIter = m_aListenerMap.find( m_aCommandURL );
185*cdf0e10cSrcweir             if ( pIter != m_aListenerMap.end() )
186*cdf0e10cSrcweir                 xDispatch = pIter->second;
187*cdf0e10cSrcweir         }
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     if ( xDispatch.is() && xURLTransformer.is() )
191*cdf0e10cSrcweir     {
192*cdf0e10cSrcweir         com::sun::star::util::URL aTargetURL;
193*cdf0e10cSrcweir         Sequence<PropertyValue>   aArgs( 1 );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir         // Add key modifier to argument list
196*cdf0e10cSrcweir         aArgs[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
197*cdf0e10cSrcweir         aArgs[0].Value <<= KeyModifier;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir         aTargetURL.Complete = aCommandURL;
200*cdf0e10cSrcweir         xURLTransformer->parseStrict( aTargetURL );
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         // Execute dispatch asynchronously
203*cdf0e10cSrcweir         ExecuteInfo* pExecuteInfo = new ExecuteInfo;
204*cdf0e10cSrcweir         pExecuteInfo->xDispatch     = xDispatch;
205*cdf0e10cSrcweir         pExecuteInfo->aTargetURL    = aTargetURL;
206*cdf0e10cSrcweir         pExecuteInfo->aArgs         = aArgs;
207*cdf0e10cSrcweir         if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
208*cdf0e10cSrcweir             UiEventLogHelper(::rtl::OUString::createFromAscii("GenericToolbarController")).log( m_xServiceManager, m_xFrame, aTargetURL, aArgs);
209*cdf0e10cSrcweir         Application::PostUserEvent( STATIC_LINK(0, GenericToolbarController , ExecuteHdl_Impl), pExecuteInfo );
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir }
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir void GenericToolbarController::statusChanged( const FeatureStateEvent& Event )
214*cdf0e10cSrcweir throw ( RuntimeException )
215*cdf0e10cSrcweir {
216*cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     if ( m_bDisposed )
219*cdf0e10cSrcweir         return;
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     if ( m_pToolbar )
222*cdf0e10cSrcweir     {
223*cdf0e10cSrcweir         m_pToolbar->EnableItem( m_nID, Event.IsEnabled );
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         sal_uInt16 nItemBits = m_pToolbar->GetItemBits( m_nID );
226*cdf0e10cSrcweir         nItemBits &= ~TIB_CHECKABLE;
227*cdf0e10cSrcweir         TriState eTri = STATE_NOCHECK;
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir         sal_Bool        bValue = sal_Bool();
230*cdf0e10cSrcweir         rtl::OUString   aStrValue;
231*cdf0e10cSrcweir         ItemStatus      aItemState;
232*cdf0e10cSrcweir         Visibility      aItemVisibility;
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir         if (( Event.State >>= bValue ) && !m_bEnumCommand )
235*cdf0e10cSrcweir         {
236*cdf0e10cSrcweir             // Boolean, treat it as checked/unchecked
237*cdf0e10cSrcweir             if ( m_bMadeInvisible )
238*cdf0e10cSrcweir                 m_pToolbar->ShowItem( m_nID, sal_True );
239*cdf0e10cSrcweir             m_pToolbar->CheckItem( m_nID, bValue );
240*cdf0e10cSrcweir             if ( bValue )
241*cdf0e10cSrcweir                 eTri = STATE_CHECK;
242*cdf0e10cSrcweir             nItemBits |= TIB_CHECKABLE;
243*cdf0e10cSrcweir         }
244*cdf0e10cSrcweir         else if ( Event.State >>= aStrValue )
245*cdf0e10cSrcweir         {
246*cdf0e10cSrcweir             if ( m_bEnumCommand )
247*cdf0e10cSrcweir             {
248*cdf0e10cSrcweir                 if ( aStrValue == m_aEnumCommand )
249*cdf0e10cSrcweir                     bValue = sal_True;
250*cdf0e10cSrcweir                 else
251*cdf0e10cSrcweir                     bValue = sal_False;
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir                 m_pToolbar->CheckItem( m_nID, bValue );
254*cdf0e10cSrcweir                 if ( bValue )
255*cdf0e10cSrcweir                     eTri = STATE_CHECK;
256*cdf0e10cSrcweir                 nItemBits |= TIB_CHECKABLE;
257*cdf0e10cSrcweir             }
258*cdf0e10cSrcweir             else
259*cdf0e10cSrcweir             {
260*cdf0e10cSrcweir                 // Replacement for place holders
261*cdf0e10cSrcweir                 if ( aStrValue.matchAsciiL( "($1)", 4 ))
262*cdf0e10cSrcweir                 {
263*cdf0e10cSrcweir 				    String aResStr = String( FwkResId( STR_UPDATEDOC ));
264*cdf0e10cSrcweir                     rtl::OUString aTmp( aResStr );
265*cdf0e10cSrcweir                     aTmp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ));
266*cdf0e10cSrcweir                     aTmp += aStrValue.copy( 4 );
267*cdf0e10cSrcweir                     aStrValue = aTmp;
268*cdf0e10cSrcweir                 }
269*cdf0e10cSrcweir                 else if ( aStrValue.matchAsciiL( "($2)", 4 ))
270*cdf0e10cSrcweir                 {
271*cdf0e10cSrcweir 				    String aResStr = String( FwkResId( STR_CLOSEDOC_ANDRETURN ));
272*cdf0e10cSrcweir                     rtl::OUString aTmp( aResStr );
273*cdf0e10cSrcweir                     aTmp += aStrValue.copy( 4 );
274*cdf0e10cSrcweir                     aStrValue = aTmp;
275*cdf0e10cSrcweir                 }
276*cdf0e10cSrcweir                 else if ( aStrValue.matchAsciiL( "($3)", 4 ))
277*cdf0e10cSrcweir                 {
278*cdf0e10cSrcweir 				    String aResStr = String( FwkResId( STR_SAVECOPYDOC ));
279*cdf0e10cSrcweir                     rtl::OUString aTmp( aResStr );
280*cdf0e10cSrcweir                     aTmp += aStrValue.copy( 4 );
281*cdf0e10cSrcweir                     aStrValue = aTmp;
282*cdf0e10cSrcweir                 }
283*cdf0e10cSrcweir                 ::rtl::OUString aText( MnemonicGenerator::EraseAllMnemonicChars( aStrValue ) );
284*cdf0e10cSrcweir                 m_pToolbar->SetItemText( m_nID, aText );
285*cdf0e10cSrcweir                 m_pToolbar->SetQuickHelpText( m_nID, aText );
286*cdf0e10cSrcweir             }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir             if ( m_bMadeInvisible )
289*cdf0e10cSrcweir                 m_pToolbar->ShowItem( m_nID, sal_True );
290*cdf0e10cSrcweir         }
291*cdf0e10cSrcweir         else if (( Event.State >>= aItemState ) && !m_bEnumCommand )
292*cdf0e10cSrcweir         {
293*cdf0e10cSrcweir             eTri = STATE_DONTKNOW;
294*cdf0e10cSrcweir             nItemBits |= TIB_CHECKABLE;
295*cdf0e10cSrcweir             if ( m_bMadeInvisible )
296*cdf0e10cSrcweir                 m_pToolbar->ShowItem( m_nID, sal_True );
297*cdf0e10cSrcweir         }
298*cdf0e10cSrcweir         else if ( Event.State >>= aItemVisibility )
299*cdf0e10cSrcweir         {
300*cdf0e10cSrcweir             m_pToolbar->ShowItem( m_nID, aItemVisibility.bVisible );
301*cdf0e10cSrcweir             m_bMadeInvisible = !aItemVisibility.bVisible;
302*cdf0e10cSrcweir         }
303*cdf0e10cSrcweir         else if ( m_bMadeInvisible )
304*cdf0e10cSrcweir             m_pToolbar->ShowItem( m_nID, sal_True );
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir         m_pToolbar->SetItemState( m_nID, eTri );
307*cdf0e10cSrcweir         m_pToolbar->SetItemBits( m_nID, nItemBits );
308*cdf0e10cSrcweir     }
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( GenericToolbarController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
312*cdf0e10cSrcweir {
313*cdf0e10cSrcweir    const sal_uInt32 nRef = Application::ReleaseSolarMutex();
314*cdf0e10cSrcweir    try
315*cdf0e10cSrcweir    {
316*cdf0e10cSrcweir         // Asynchronous execution as this can lead to our own destruction!
317*cdf0e10cSrcweir         // Framework can recycle our current frame and the layout manager disposes all user interface
318*cdf0e10cSrcweir         // elements if a component gets detached from its frame!
319*cdf0e10cSrcweir         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
320*cdf0e10cSrcweir    }
321*cdf0e10cSrcweir    catch ( Exception& )
322*cdf0e10cSrcweir    {
323*cdf0e10cSrcweir    }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir    Application::AcquireSolarMutex( nRef );
326*cdf0e10cSrcweir    delete pExecuteInfo;
327*cdf0e10cSrcweir    return 0;
328*cdf0e10cSrcweir }
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir MenuToolbarController::MenuToolbarController( const Reference< XMultiServiceFactory >& rServiceManager, const Reference< XFrame >& rFrame, ToolBox* pToolBar, sal_uInt16   nID, const rtl::OUString& aCommand, const rtl::OUString& aModuleIdentifier, const Reference< XIndexAccess >& xMenuDesc ) : GenericToolbarController( rServiceManager, rFrame, pToolBar, nID, aCommand ), m_xMenuDesc( xMenuDesc ), pMenu( NULL ), m_aModuleIdentifier( aModuleIdentifier )
331*cdf0e10cSrcweir {
332*cdf0e10cSrcweir }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir MenuToolbarController::~MenuToolbarController()
335*cdf0e10cSrcweir {
336*cdf0e10cSrcweir     try
337*cdf0e10cSrcweir     {
338*cdf0e10cSrcweir         if ( m_xMenuManager.is() )
339*cdf0e10cSrcweir             m_xMenuManager->dispose();
340*cdf0e10cSrcweir     }
341*cdf0e10cSrcweir     catch( Exception& ) {}
342*cdf0e10cSrcweir     if ( pMenu )
343*cdf0e10cSrcweir     {
344*cdf0e10cSrcweir         delete pMenu;
345*cdf0e10cSrcweir         pMenu = NULL;
346*cdf0e10cSrcweir     }
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir class Toolbarmenu : public PopupMenu
351*cdf0e10cSrcweir {
352*cdf0e10cSrcweir     public:
353*cdf0e10cSrcweir     Toolbarmenu();
354*cdf0e10cSrcweir     ~Toolbarmenu();
355*cdf0e10cSrcweir };
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir Toolbarmenu::Toolbarmenu()
358*cdf0e10cSrcweir {
359*cdf0e10cSrcweir     OSL_TRACE("**** contstructing Toolbarmenu 0x%x", this );
360*cdf0e10cSrcweir }
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir Toolbarmenu::~Toolbarmenu()
363*cdf0e10cSrcweir {
364*cdf0e10cSrcweir     OSL_TRACE("**** destructing Toolbarmenu 0x%x", this );
365*cdf0e10cSrcweir }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir void SAL_CALL MenuToolbarController::click() throw (RuntimeException)
368*cdf0e10cSrcweir {
369*cdf0e10cSrcweir     createPopupWindow();
370*cdf0e10cSrcweir }
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir Reference< XWindow > SAL_CALL
373*cdf0e10cSrcweir MenuToolbarController::createPopupWindow() throw (::com::sun::star::uno::RuntimeException)
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     if ( !pMenu )
376*cdf0e10cSrcweir     {
377*cdf0e10cSrcweir         Reference< XDispatchProvider > xDispatch;
378*cdf0e10cSrcweir         Reference< XURLTransformer > xURLTransformer( m_xServiceManager->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))), UNO_QUERY );
379*cdf0e10cSrcweir         pMenu = new Toolbarmenu();
380*cdf0e10cSrcweir         m_xMenuManager.set( new MenuBarManager( m_xServiceManager, m_xFrame, xURLTransformer, xDispatch, m_aModuleIdentifier, pMenu, sal_True, sal_True ) );
381*cdf0e10cSrcweir         if ( m_xMenuManager.is() )
382*cdf0e10cSrcweir         {
383*cdf0e10cSrcweir             MenuBarManager* pMgr = dynamic_cast< MenuBarManager* >( m_xMenuManager.get() );
384*cdf0e10cSrcweir             pMgr->SetItemContainer( m_xMenuDesc );
385*cdf0e10cSrcweir         }
386*cdf0e10cSrcweir     }
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     ::Rectangle aRect( m_pToolbar->GetItemRect( m_nID ) );
389*cdf0e10cSrcweir     pMenu->Execute( m_pToolbar, aRect, POPUPMENU_EXECUTE_DOWN );
390*cdf0e10cSrcweir     return NULL;
391*cdf0e10cSrcweir }
392*cdf0e10cSrcweir } // namespace
393*cdf0e10cSrcweir 
394