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