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
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
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.
196d739b60SAndrew Rist  *
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 
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 
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 
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 
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 
142cdf0e10cSrcweir GenericToolbarController::~GenericToolbarController()
143cdf0e10cSrcweir {
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
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 
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;
189cdf0e10cSrcweir         Sequence<PropertyValue>   aArgs( 1 );
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         // Add key modifier to argument list
192cdf0e10cSrcweir         aArgs[0].Name  = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "KeyModifier" ));
193cdf0e10cSrcweir         aArgs[0].Value <<= KeyModifier;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         aTargetURL.Complete = aCommandURL;
196cdf0e10cSrcweir         xURLTransformer->parseStrict( aTargetURL );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         // Execute dispatch asynchronously
199cdf0e10cSrcweir         ExecuteInfo* pExecuteInfo = new ExecuteInfo;
200cdf0e10cSrcweir         pExecuteInfo->xDispatch     = xDispatch;
201cdf0e10cSrcweir         pExecuteInfo->aTargetURL    = aTargetURL;
202cdf0e10cSrcweir         pExecuteInfo->aArgs         = aArgs;
203cdf0e10cSrcweir         if(::comphelper::UiEventsLogger::isEnabled()) //#i88653#
204cdf0e10cSrcweir             UiEventLogHelper(::rtl::OUString::createFromAscii("GenericToolbarController")).log( m_xServiceManager, m_xFrame, aTargetURL, aArgs);
205cdf0e10cSrcweir         Application::PostUserEvent( STATIC_LINK(0, GenericToolbarController , ExecuteHdl_Impl), pExecuteInfo );
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir }
208cdf0e10cSrcweir 
209cdf0e10cSrcweir void GenericToolbarController::statusChanged( const FeatureStateEvent& Event )
210cdf0e10cSrcweir throw ( RuntimeException )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
213cdf0e10cSrcweir 
214cdf0e10cSrcweir     if ( m_bDisposed )
215cdf0e10cSrcweir         return;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     if ( m_pToolbar )
218cdf0e10cSrcweir     {
219cdf0e10cSrcweir         m_pToolbar->EnableItem( m_nID, Event.IsEnabled );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir         sal_uInt16 nItemBits = m_pToolbar->GetItemBits( m_nID );
222cdf0e10cSrcweir         nItemBits &= ~TIB_CHECKABLE;
223cdf0e10cSrcweir         TriState eTri = STATE_NOCHECK;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir         sal_Bool        bValue = sal_Bool();
226cdf0e10cSrcweir         rtl::OUString   aStrValue;
227cdf0e10cSrcweir         ItemStatus      aItemState;
228cdf0e10cSrcweir         Visibility      aItemVisibility;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         if (( Event.State >>= bValue ) && !m_bEnumCommand )
231cdf0e10cSrcweir         {
232cdf0e10cSrcweir             // Boolean, treat it as checked/unchecked
233cdf0e10cSrcweir             if ( m_bMadeInvisible )
234cdf0e10cSrcweir                 m_pToolbar->ShowItem( m_nID, sal_True );
235cdf0e10cSrcweir             m_pToolbar->CheckItem( m_nID, bValue );
236cdf0e10cSrcweir             if ( bValue )
237cdf0e10cSrcweir                 eTri = STATE_CHECK;
238cdf0e10cSrcweir             nItemBits |= TIB_CHECKABLE;
239cdf0e10cSrcweir         }
240cdf0e10cSrcweir         else if ( Event.State >>= aStrValue )
241cdf0e10cSrcweir         {
242cdf0e10cSrcweir             if ( m_bEnumCommand )
243cdf0e10cSrcweir             {
244cdf0e10cSrcweir                 if ( aStrValue == m_aEnumCommand )
245cdf0e10cSrcweir                     bValue = sal_True;
246cdf0e10cSrcweir                 else
247cdf0e10cSrcweir                     bValue = sal_False;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir                 m_pToolbar->CheckItem( m_nID, bValue );
250cdf0e10cSrcweir                 if ( bValue )
251cdf0e10cSrcweir                     eTri = STATE_CHECK;
252cdf0e10cSrcweir                 nItemBits |= TIB_CHECKABLE;
253cdf0e10cSrcweir             }
254cdf0e10cSrcweir             else
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 // Replacement for place holders
257cdf0e10cSrcweir                 if ( aStrValue.matchAsciiL( "($1)", 4 ))
258cdf0e10cSrcweir                 {
259cdf0e10cSrcweir 				    String aResStr = String( FwkResId( STR_UPDATEDOC ));
260cdf0e10cSrcweir                     rtl::OUString aTmp( aResStr );
261cdf0e10cSrcweir                     aTmp += rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ));
262cdf0e10cSrcweir                     aTmp += aStrValue.copy( 4 );
263cdf0e10cSrcweir                     aStrValue = aTmp;
264cdf0e10cSrcweir                 }
265cdf0e10cSrcweir                 else if ( aStrValue.matchAsciiL( "($2)", 4 ))
266cdf0e10cSrcweir                 {
267cdf0e10cSrcweir 				    String aResStr = String( FwkResId( STR_CLOSEDOC_ANDRETURN ));
268cdf0e10cSrcweir                     rtl::OUString aTmp( aResStr );
269cdf0e10cSrcweir                     aTmp += aStrValue.copy( 4 );
270cdf0e10cSrcweir                     aStrValue = aTmp;
271cdf0e10cSrcweir                 }
272cdf0e10cSrcweir                 else if ( aStrValue.matchAsciiL( "($3)", 4 ))
273cdf0e10cSrcweir                 {
274cdf0e10cSrcweir 				    String aResStr = String( FwkResId( STR_SAVECOPYDOC ));
275cdf0e10cSrcweir                     rtl::OUString aTmp( aResStr );
276cdf0e10cSrcweir                     aTmp += aStrValue.copy( 4 );
277cdf0e10cSrcweir                     aStrValue = aTmp;
278cdf0e10cSrcweir                 }
279cdf0e10cSrcweir                 ::rtl::OUString aText( MnemonicGenerator::EraseAllMnemonicChars( aStrValue ) );
280cdf0e10cSrcweir                 m_pToolbar->SetItemText( m_nID, aText );
281cdf0e10cSrcweir                 m_pToolbar->SetQuickHelpText( m_nID, aText );
282cdf0e10cSrcweir             }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir             if ( m_bMadeInvisible )
285cdf0e10cSrcweir                 m_pToolbar->ShowItem( m_nID, sal_True );
286cdf0e10cSrcweir         }
287cdf0e10cSrcweir         else if (( Event.State >>= aItemState ) && !m_bEnumCommand )
288cdf0e10cSrcweir         {
289cdf0e10cSrcweir             eTri = STATE_DONTKNOW;
290cdf0e10cSrcweir             nItemBits |= TIB_CHECKABLE;
291cdf0e10cSrcweir             if ( m_bMadeInvisible )
292cdf0e10cSrcweir                 m_pToolbar->ShowItem( m_nID, sal_True );
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir         else if ( Event.State >>= aItemVisibility )
295cdf0e10cSrcweir         {
296cdf0e10cSrcweir             m_pToolbar->ShowItem( m_nID, aItemVisibility.bVisible );
297cdf0e10cSrcweir             m_bMadeInvisible = !aItemVisibility.bVisible;
298cdf0e10cSrcweir         }
299cdf0e10cSrcweir         else if ( m_bMadeInvisible )
300cdf0e10cSrcweir             m_pToolbar->ShowItem( m_nID, sal_True );
301cdf0e10cSrcweir 
302cdf0e10cSrcweir         m_pToolbar->SetItemState( m_nID, eTri );
303cdf0e10cSrcweir         m_pToolbar->SetItemBits( m_nID, nItemBits );
304cdf0e10cSrcweir     }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( GenericToolbarController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
308cdf0e10cSrcweir {
309cdf0e10cSrcweir    const sal_uInt32 nRef = Application::ReleaseSolarMutex();
310cdf0e10cSrcweir    try
311cdf0e10cSrcweir    {
312cdf0e10cSrcweir         // Asynchronous execution as this can lead to our own destruction!
313cdf0e10cSrcweir         // Framework can recycle our current frame and the layout manager disposes all user interface
314cdf0e10cSrcweir         // elements if a component gets detached from its frame!
315cdf0e10cSrcweir         pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
316cdf0e10cSrcweir    }
317cdf0e10cSrcweir    catch ( Exception& )
318cdf0e10cSrcweir    {
319cdf0e10cSrcweir    }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir    Application::AcquireSolarMutex( nRef );
322cdf0e10cSrcweir    delete pExecuteInfo;
323cdf0e10cSrcweir    return 0;
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir 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 )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir MenuToolbarController::~MenuToolbarController()
331cdf0e10cSrcweir {
332cdf0e10cSrcweir     try
333cdf0e10cSrcweir     {
334cdf0e10cSrcweir         if ( m_xMenuManager.is() )
335cdf0e10cSrcweir             m_xMenuManager->dispose();
336cdf0e10cSrcweir     }
337cdf0e10cSrcweir     catch( Exception& ) {}
338cdf0e10cSrcweir     if ( pMenu )
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         delete pMenu;
341cdf0e10cSrcweir         pMenu = NULL;
342cdf0e10cSrcweir     }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir }
345cdf0e10cSrcweir 
346cdf0e10cSrcweir class Toolbarmenu : public PopupMenu
347cdf0e10cSrcweir {
348cdf0e10cSrcweir     public:
349cdf0e10cSrcweir     Toolbarmenu();
350cdf0e10cSrcweir     ~Toolbarmenu();
351cdf0e10cSrcweir };
352cdf0e10cSrcweir 
353cdf0e10cSrcweir Toolbarmenu::Toolbarmenu()
354cdf0e10cSrcweir {
355cdf0e10cSrcweir     OSL_TRACE("**** contstructing Toolbarmenu 0x%x", this );
356cdf0e10cSrcweir }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir Toolbarmenu::~Toolbarmenu()
359cdf0e10cSrcweir {
360cdf0e10cSrcweir     OSL_TRACE("**** destructing Toolbarmenu 0x%x", this );
361cdf0e10cSrcweir }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir void SAL_CALL MenuToolbarController::click() throw (RuntimeException)
364cdf0e10cSrcweir {
365cdf0e10cSrcweir     createPopupWindow();
366cdf0e10cSrcweir }
367cdf0e10cSrcweir 
368cdf0e10cSrcweir Reference< XWindow > SAL_CALL
369cdf0e10cSrcweir MenuToolbarController::createPopupWindow() throw (::com::sun::star::uno::RuntimeException)
370cdf0e10cSrcweir {
371cdf0e10cSrcweir     if ( !pMenu )
372cdf0e10cSrcweir     {
373cdf0e10cSrcweir         Reference< XDispatchProvider > xDispatch;
374cdf0e10cSrcweir         Reference< XURLTransformer > xURLTransformer( m_xServiceManager->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.URLTransformer" ))), UNO_QUERY );
375cdf0e10cSrcweir         pMenu = new Toolbarmenu();
376cdf0e10cSrcweir         m_xMenuManager.set( new MenuBarManager( m_xServiceManager, m_xFrame, xURLTransformer, xDispatch, m_aModuleIdentifier, pMenu, sal_True, sal_True ) );
377cdf0e10cSrcweir         if ( m_xMenuManager.is() )
378cdf0e10cSrcweir         {
379cdf0e10cSrcweir             MenuBarManager* pMgr = dynamic_cast< MenuBarManager* >( m_xMenuManager.get() );
380cdf0e10cSrcweir             pMgr->SetItemContainer( m_xMenuDesc );
381cdf0e10cSrcweir         }
382cdf0e10cSrcweir     }
383cdf0e10cSrcweir 
384*d21a9fb0SAriel Constenla-Haile     if ( !pMenu || !m_pToolbar )
385*d21a9fb0SAriel Constenla-Haile         return NULL;
386*d21a9fb0SAriel Constenla-Haile 
387*d21a9fb0SAriel Constenla-Haile     OSL_ENSURE ( pMenu->GetItemCount(), "Empty PopupMenu!" );
388*d21a9fb0SAriel Constenla-Haile 
389cdf0e10cSrcweir     ::Rectangle aRect( m_pToolbar->GetItemRect( m_nID ) );
390cdf0e10cSrcweir     pMenu->Execute( m_pToolbar, aRect, POPUPMENU_EXECUTE_DOWN );
391*d21a9fb0SAriel Constenla-Haile 
392*d21a9fb0SAriel Constenla-Haile     return NULL;
393cdf0e10cSrcweir }
394cdf0e10cSrcweir } // namespace
395cdf0e10cSrcweir 
396