fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / macrosmenucontroller.cxx
blob9bcccc489c1ac441f5290319ac6fe232c8d56495
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <uielement/macrosmenucontroller.hxx>
21 #include <uielement/menubarmanager.hxx>
22 #include "services.h"
23 #include <classes/resource.hrc>
24 #include <classes/fwkresid.hxx>
25 #include <framework/imageproducer.hxx>
26 #include <com/sun/star/awt/MenuItemStyle.hpp>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
30 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
31 #include <com/sun/star/frame/XModuleManager.hpp>
32 #include <comphelper/processfactory.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/i18nhelp.hxx>
35 #include <rtl/ustrbuf.hxx>
36 #include "helper/mischelper.hxx"
37 #include "helpid.hrc"
38 #include <osl/mutex.hxx>
40 using namespace com::sun::star::uno;
41 using namespace com::sun::star::lang;
42 using namespace com::sun::star::frame;
43 using namespace com::sun::star::beans;
44 using namespace com::sun::star::util;
45 using namespace com::sun::star::style;
46 using namespace com::sun::star::container;
47 using namespace ::com::sun::star::frame;
49 namespace framework
51 class
52 DEFINE_XSERVICEINFO_MULTISERVICE_2 ( MacrosMenuController ,
53 OWeakObject ,
54 SERVICENAME_POPUPMENUCONTROLLER ,
55 IMPLEMENTATIONNAME_MACROSMENUCONTROLLER
58 DEFINE_INIT_SERVICE ( MacrosMenuController, {} )
60 MacrosMenuController::MacrosMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ) :
61 svt::PopupMenuControllerBase( xContext ),
62 m_xContext( xContext)
66 MacrosMenuController::~MacrosMenuController()
68 OSL_TRACE("calling dtor");
71 // private function
72 void MacrosMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
74 VCLXPopupMenu* pVCLPopupMenu = static_cast<VCLXPopupMenu *>(VCLXMenu::GetImplementation( rPopupMenu ));
75 PopupMenu* pPopupMenu = 0;
77 SolarMutexGuard aSolarMutexGuard;
79 resetPopupMenu( rPopupMenu );
80 if ( pVCLPopupMenu )
81 pPopupMenu = static_cast<PopupMenu *>(pVCLPopupMenu->GetMenu());
83 if (!pPopupMenu)
84 return;
86 // insert basic
87 OUString aCommand(".uno:MacroDialog");
88 OUString aDisplayName = RetrieveLabelFromCommand( aCommand );
89 pPopupMenu->InsertItem( 2, aDisplayName );
90 pPopupMenu->SetItemCommand( 2, aCommand );
92 // insert providers but not basic or java
93 addScriptItems( pPopupMenu, 4);
96 // XEventListener
97 void SAL_CALL MacrosMenuController::disposing( const EventObject& ) throw ( RuntimeException, std::exception )
99 Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
101 osl::MutexGuard aLock( m_aMutex );
102 OSL_TRACE("disposing");
103 m_xFrame.clear();
104 m_xDispatch.clear();
105 m_xContext.clear();
107 if ( m_xPopupMenu.is() )
109 m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
110 OSL_TRACE("removed listener");
112 m_xPopupMenu.clear();
115 // XStatusListener
116 void SAL_CALL MacrosMenuController::statusChanged( const FeatureStateEvent& ) throw ( RuntimeException, std::exception )
118 osl::MutexGuard aLock( m_aMutex );
119 if ( m_xPopupMenu.is() )
121 fillPopupMenu( m_xPopupMenu );
125 // XMenuListener
126 void MacrosMenuController::impl_select(const Reference< XDispatch >& /*_xDispatch*/,const ::com::sun::star::util::URL& aTargetURL)
128 // need to requery, since we handle more than one type of Command
129 // if we don't do this only .uno:ScriptOrganizer commands are executed
130 Reference< XDispatchProvider > xDispatchProvider( m_xFrame, UNO_QUERY );
131 Reference< XDispatch > xDispatch = xDispatchProvider->queryDispatch( aTargetURL, OUString(), 0 );
132 if( xDispatch.is() )
134 ExecuteInfo* pExecuteInfo = new ExecuteInfo;
135 pExecuteInfo->xDispatch = xDispatch;
136 pExecuteInfo->aTargetURL = aTargetURL;
137 Application::PostUserEvent( LINK(0, MacrosMenuController , ExecuteHdl_Impl), pExecuteInfo );
141 IMPL_STATIC_LINK( MacrosMenuController, ExecuteHdl_Impl, ExecuteInfo*, pExecuteInfo )
145 // Asynchronous execution as this can lead to our own destruction!
146 // Framework can recycle our current frame and the layout manager disposes all user interface
147 // elements if a component gets detached from its frame!
148 pExecuteInfo->xDispatch->dispatch( pExecuteInfo->aTargetURL, pExecuteInfo->aArgs );
150 catch ( const Exception& )
153 delete pExecuteInfo;
154 return 0;
157 OUString MacrosMenuController::RetrieveLabelFromCommand(const OUString& rCmdURL)
159 bool bModuleIdentified = !m_aModuleIdentifier.isEmpty();
160 return framework::RetrieveLabelFromCommand(rCmdURL, m_xContext, m_xUICommandLabels, m_xFrame, m_aModuleIdentifier, bModuleIdentified, "Label");
163 void MacrosMenuController::addScriptItems( PopupMenu* pPopupMenu, sal_uInt16 startItemId )
165 const OUString aCmdBase(".uno:ScriptOrganizer?ScriptOrganizer.Language:string=");
166 const OUString ellipsis( "..." );
167 const OUString providerKey("com.sun.star.script.provider.ScriptProviderFor");
168 const OUString languageProviderName("com.sun.star.script.provider.LanguageScriptProvider");
169 sal_uInt16 itemId = startItemId;
170 Reference< XContentEnumerationAccess > xEnumAccess = Reference< XContentEnumerationAccess >( m_xContext->getServiceManager(), UNO_QUERY_THROW );
171 Reference< XEnumeration > xEnum = xEnumAccess->createContentEnumeration ( languageProviderName );
173 while ( xEnum->hasMoreElements() )
175 Reference< XServiceInfo > xServiceInfo;
176 if ( !( xEnum->nextElement() >>= xServiceInfo ) )
178 break;
180 Sequence< OUString > serviceNames = xServiceInfo->getSupportedServiceNames();
182 if ( serviceNames.getLength() > 0 )
184 for ( sal_Int32 index = 0; index < serviceNames.getLength(); index++ )
186 if ( serviceNames[ index ].startsWith( providerKey ) )
188 OUString serviceName = serviceNames[ index ];
189 OUString aCommand = aCmdBase;
190 OUString aDisplayName = serviceName.copy( providerKey.getLength() );
191 if( aDisplayName == "Java" || aDisplayName == "Basic" )
193 // no entries for Java & Basic added elsewhere
194 break;
196 aCommand += aDisplayName;
197 aDisplayName += ellipsis;
198 pPopupMenu->InsertItem( itemId, aDisplayName );
199 pPopupMenu->SetItemCommand( itemId, aCommand );
200 itemId++;
201 break;
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */