110b918a5SAriel Constenla-Haile /************************************************************** 210b918a5SAriel Constenla-Haile * 310b918a5SAriel Constenla-Haile * Licensed to the Apache Software Foundation (ASF) under one 410b918a5SAriel Constenla-Haile * or more contributor license agreements. See the NOTICE file 510b918a5SAriel Constenla-Haile * distributed with this work for additional information 610b918a5SAriel Constenla-Haile * regarding copyright ownership. The ASF licenses this file 710b918a5SAriel Constenla-Haile * to you under the Apache License, Version 2.0 (the 810b918a5SAriel Constenla-Haile * "License"); you may not use this file except in compliance 910b918a5SAriel Constenla-Haile * with the License. You may obtain a copy of the License at 1010b918a5SAriel Constenla-Haile * 1110b918a5SAriel Constenla-Haile * http://www.apache.org/licenses/LICENSE-2.0 1210b918a5SAriel Constenla-Haile * 1310b918a5SAriel Constenla-Haile * Unless required by applicable law or agreed to in writing, 1410b918a5SAriel Constenla-Haile * software distributed under the License is distributed on an 1510b918a5SAriel Constenla-Haile * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1610b918a5SAriel Constenla-Haile * KIND, either express or implied. See the License for the 1710b918a5SAriel Constenla-Haile * specific language governing permissions and limitations 1810b918a5SAriel Constenla-Haile * under the License. 1910b918a5SAriel Constenla-Haile * 2010b918a5SAriel Constenla-Haile *************************************************************/ 2110b918a5SAriel Constenla-Haile 2210b918a5SAriel Constenla-Haile // MARKER(update_precomp.py): autogen include statement, do not remove 2310b918a5SAriel Constenla-Haile #include "precompiled_framework.hxx" 2410b918a5SAriel Constenla-Haile 2510b918a5SAriel Constenla-Haile #include <uielement/popuptoolbarcontroller.hxx> 2610b918a5SAriel Constenla-Haile #include <comphelper/processfactory.hxx> 2710b918a5SAriel Constenla-Haile #include <svtools/imagemgr.hxx> 2810b918a5SAriel Constenla-Haile #include <svtools/miscopt.hxx> 2910b918a5SAriel Constenla-Haile #include <toolkit/helper/vclunohelper.hxx> 3010b918a5SAriel Constenla-Haile #include <tools/urlobj.hxx> 3110b918a5SAriel Constenla-Haile #include <unotools/moduleoptions.hxx> 3210b918a5SAriel Constenla-Haile #include <vcl/svapp.hxx> 3310b918a5SAriel Constenla-Haile #include <vcl/toolbox.hxx> 3410b918a5SAriel Constenla-Haile #include <vos/mutex.hxx> 3510b918a5SAriel Constenla-Haile 3610b918a5SAriel Constenla-Haile #include <com/sun/star/awt/PopupMenuDirection.hpp> 3710b918a5SAriel Constenla-Haile #include <com/sun/star/frame/PopupMenuControllerFactory.hpp> 3810b918a5SAriel Constenla-Haile 3910b918a5SAriel Constenla-Haile 4010b918a5SAriel Constenla-Haile #define UNO_COMMAND_RECENT_FILE_LIST ".uno:RecentFileList" 4110b918a5SAriel Constenla-Haile 4210b918a5SAriel Constenla-Haile using rtl::OUString; 4310b918a5SAriel Constenla-Haile namespace css = ::com::sun::star; 4410b918a5SAriel Constenla-Haile 4510b918a5SAriel Constenla-Haile namespace framework 4610b918a5SAriel Constenla-Haile { 4710b918a5SAriel Constenla-Haile 4810b918a5SAriel Constenla-Haile PopupMenuToolbarController::PopupMenuToolbarController( 4910b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext, 5010b918a5SAriel Constenla-Haile const OUString &rPopupCommand ) 5110b918a5SAriel Constenla-Haile : svt::ToolboxController() 5210b918a5SAriel Constenla-Haile , m_xContext( xContext ) 5310b918a5SAriel Constenla-Haile , m_bHasController( sal_False ) 5410b918a5SAriel Constenla-Haile , m_aPopupCommand( rPopupCommand ) 5510b918a5SAriel Constenla-Haile { 5610b918a5SAriel Constenla-Haile } 5710b918a5SAriel Constenla-Haile 5810b918a5SAriel Constenla-Haile PopupMenuToolbarController::~PopupMenuToolbarController() 5910b918a5SAriel Constenla-Haile { 6010b918a5SAriel Constenla-Haile } 6110b918a5SAriel Constenla-Haile 6210b918a5SAriel Constenla-Haile void SAL_CALL PopupMenuToolbarController::dispose() 6310b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 6410b918a5SAriel Constenla-Haile { 6510b918a5SAriel Constenla-Haile svt::ToolboxController::dispose(); 6610b918a5SAriel Constenla-Haile 6710b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex ); 6810b918a5SAriel Constenla-Haile if( m_xPopupMenuController.is() ) 6910b918a5SAriel Constenla-Haile { 7010b918a5SAriel Constenla-Haile css::uno::Reference< css::lang::XComponent > xComponent( 7110b918a5SAriel Constenla-Haile m_xPopupMenuController, css::uno::UNO_QUERY ); 7210b918a5SAriel Constenla-Haile if( xComponent.is() ) 7310b918a5SAriel Constenla-Haile { 7410b918a5SAriel Constenla-Haile try 7510b918a5SAriel Constenla-Haile { 7610b918a5SAriel Constenla-Haile xComponent->dispose(); 7710b918a5SAriel Constenla-Haile } 7810b918a5SAriel Constenla-Haile catch (...) 7910b918a5SAriel Constenla-Haile {} 8010b918a5SAriel Constenla-Haile } 8110b918a5SAriel Constenla-Haile m_xPopupMenuController.clear(); 8210b918a5SAriel Constenla-Haile } 8310b918a5SAriel Constenla-Haile 8410b918a5SAriel Constenla-Haile m_xContext.clear(); 8510b918a5SAriel Constenla-Haile m_xPopupMenuFactory.clear(); 8610b918a5SAriel Constenla-Haile m_xPopupMenu.clear(); 8710b918a5SAriel Constenla-Haile } 8810b918a5SAriel Constenla-Haile 8910b918a5SAriel Constenla-Haile void SAL_CALL PopupMenuToolbarController::initialize( 9010b918a5SAriel Constenla-Haile const css::uno::Sequence< css::uno::Any >& aArguments ) 9110b918a5SAriel Constenla-Haile throw ( css::uno::Exception, css::uno::RuntimeException ) 9210b918a5SAriel Constenla-Haile { 9310b918a5SAriel Constenla-Haile ToolboxController::initialize( aArguments ); 9410b918a5SAriel Constenla-Haile 9510b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex ); 9610b918a5SAriel Constenla-Haile if ( !m_aPopupCommand.getLength() ) 9710b918a5SAriel Constenla-Haile m_aPopupCommand = m_aCommandURL; 9810b918a5SAriel Constenla-Haile 9910b918a5SAriel Constenla-Haile try 10010b918a5SAriel Constenla-Haile { 10110b918a5SAriel Constenla-Haile m_xPopupMenuFactory.set( 10210b918a5SAriel Constenla-Haile css::frame::PopupMenuControllerFactory::create( m_xContext ) ); 10310b918a5SAriel Constenla-Haile m_bHasController = m_xPopupMenuFactory->hasController( 10410b918a5SAriel Constenla-Haile m_aPopupCommand, getModuleName() ); 10510b918a5SAriel Constenla-Haile } 10610b918a5SAriel Constenla-Haile catch (const css::uno::Exception& e) 10710b918a5SAriel Constenla-Haile { 10810b918a5SAriel Constenla-Haile OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s", 10910b918a5SAriel Constenla-Haile rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); 11010b918a5SAriel Constenla-Haile (void) e; 11110b918a5SAriel Constenla-Haile } 11210b918a5SAriel Constenla-Haile 11310b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 11410b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) ); 11510b918a5SAriel Constenla-Haile if ( pToolBox ) 11610b918a5SAriel Constenla-Haile { 11710b918a5SAriel Constenla-Haile ToolBoxItemBits nCurStyle( pToolBox->GetItemBits( m_nToolBoxId ) ); 11810b918a5SAriel Constenla-Haile ToolBoxItemBits nSetStyle( getDropDownStyle() ); 11910b918a5SAriel Constenla-Haile pToolBox->SetItemBits( m_nToolBoxId, 12010b918a5SAriel Constenla-Haile m_bHasController ? 12110b918a5SAriel Constenla-Haile nCurStyle | nSetStyle : 12210b918a5SAriel Constenla-Haile nCurStyle & ~nSetStyle ); 12310b918a5SAriel Constenla-Haile } 12410b918a5SAriel Constenla-Haile 12510b918a5SAriel Constenla-Haile } 12610b918a5SAriel Constenla-Haile 12710b918a5SAriel Constenla-Haile void SAL_CALL 12810b918a5SAriel Constenla-Haile PopupMenuToolbarController::statusChanged( 12910b918a5SAriel Constenla-Haile const css::frame::FeatureStateEvent& rEvent ) 13010b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 13110b918a5SAriel Constenla-Haile { 13210b918a5SAriel Constenla-Haile // TODO move to base class 13310b918a5SAriel Constenla-Haile 13410b918a5SAriel Constenla-Haile svt::ToolboxController::statusChanged( rEvent ); 13510b918a5SAriel Constenla-Haile enable( rEvent.IsEnabled ); 13610b918a5SAriel Constenla-Haile } 13710b918a5SAriel Constenla-Haile 13810b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindow > SAL_CALL 13910b918a5SAriel Constenla-Haile PopupMenuToolbarController::createPopupWindow() 14010b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 14110b918a5SAriel Constenla-Haile { 14210b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindow > xRet; 14310b918a5SAriel Constenla-Haile 14410b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex ); 14510b918a5SAriel Constenla-Haile if ( !m_bHasController ) 14610b918a5SAriel Constenla-Haile return xRet; 14710b918a5SAriel Constenla-Haile 14810b918a5SAriel Constenla-Haile createPopupMenuController(); 14910b918a5SAriel Constenla-Haile 15010b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 15110b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) ); 15210b918a5SAriel Constenla-Haile if ( !pToolBox ) 15310b918a5SAriel Constenla-Haile return xRet; 15410b918a5SAriel Constenla-Haile 15510b918a5SAriel Constenla-Haile pToolBox->SetItemDown( m_nToolBoxId, sal_True ); 15610b918a5SAriel Constenla-Haile sal_uInt16 nId = m_xPopupMenu->execute( 15710b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindowPeer >( getParent(), css::uno::UNO_QUERY ), 15810b918a5SAriel Constenla-Haile VCLUnoHelper::ConvertToAWTRect( pToolBox->GetItemRect( m_nToolBoxId ) ), 15910b918a5SAriel Constenla-Haile css::awt::PopupMenuDirection::EXECUTE_DEFAULT ); 16010b918a5SAriel Constenla-Haile pToolBox->SetItemDown( m_nToolBoxId, sal_False ); 16110b918a5SAriel Constenla-Haile 16210b918a5SAriel Constenla-Haile if ( nId ) 16310b918a5SAriel Constenla-Haile functionExecuted( m_xPopupMenu->getCommand( nId ) ); 16410b918a5SAriel Constenla-Haile 16510b918a5SAriel Constenla-Haile return xRet; 16610b918a5SAriel Constenla-Haile } 16710b918a5SAriel Constenla-Haile 16810b918a5SAriel Constenla-Haile void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/) 16910b918a5SAriel Constenla-Haile { 17010b918a5SAriel Constenla-Haile } 17110b918a5SAriel Constenla-Haile 17210b918a5SAriel Constenla-Haile sal_uInt16 PopupMenuToolbarController::getDropDownStyle() const 17310b918a5SAriel Constenla-Haile { 17410b918a5SAriel Constenla-Haile return TIB_DROPDOWN; 17510b918a5SAriel Constenla-Haile } 17610b918a5SAriel Constenla-Haile 17710b918a5SAriel Constenla-Haile void PopupMenuToolbarController::createPopupMenuController() 17810b918a5SAriel Constenla-Haile { 17910b918a5SAriel Constenla-Haile if( !m_bHasController ) 18010b918a5SAriel Constenla-Haile return; 18110b918a5SAriel Constenla-Haile 18210b918a5SAriel Constenla-Haile if ( !m_xPopupMenuController.is() ) 18310b918a5SAriel Constenla-Haile { 18410b918a5SAriel Constenla-Haile css::uno::Sequence< css::uno::Any > aArgs( 2 ); 18510b918a5SAriel Constenla-Haile css::beans::PropertyValue aProp; 18610b918a5SAriel Constenla-Haile 18710b918a5SAriel Constenla-Haile aProp.Name = DECLARE_ASCII( "Frame" ); 18810b918a5SAriel Constenla-Haile aProp.Value <<= m_xFrame; 18910b918a5SAriel Constenla-Haile aArgs[0] <<= aProp; 19010b918a5SAriel Constenla-Haile 19110b918a5SAriel Constenla-Haile aProp.Name = DECLARE_ASCII( "ModuleIdentifier" ); 19210b918a5SAriel Constenla-Haile aProp.Value <<= getModuleName(); 19310b918a5SAriel Constenla-Haile aArgs[1] <<= aProp; 19410b918a5SAriel Constenla-Haile try 19510b918a5SAriel Constenla-Haile { 19610b918a5SAriel Constenla-Haile m_xPopupMenu.set( 19710b918a5SAriel Constenla-Haile m_xContext->getServiceManager()->createInstanceWithContext( 19810b918a5SAriel Constenla-Haile DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), m_xContext ), 19910b918a5SAriel Constenla-Haile css::uno::UNO_QUERY_THROW ); 20010b918a5SAriel Constenla-Haile m_xPopupMenuController.set( 20110b918a5SAriel Constenla-Haile m_xPopupMenuFactory->createInstanceWithArgumentsAndContext( 20210b918a5SAriel Constenla-Haile m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW ); 20310b918a5SAriel Constenla-Haile 20410b918a5SAriel Constenla-Haile m_xPopupMenuController->setPopupMenu( m_xPopupMenu ); 20510b918a5SAriel Constenla-Haile } 20610b918a5SAriel Constenla-Haile catch ( const css::uno::Exception &e ) 20710b918a5SAriel Constenla-Haile { 20810b918a5SAriel Constenla-Haile m_xPopupMenu.clear(); 20910b918a5SAriel Constenla-Haile OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s", 21010b918a5SAriel Constenla-Haile rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); 21110b918a5SAriel Constenla-Haile (void) e; 21210b918a5SAriel Constenla-Haile } 21310b918a5SAriel Constenla-Haile } 21410b918a5SAriel Constenla-Haile } 21510b918a5SAriel Constenla-Haile 21610b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( WizardsToolbarController, 21710b918a5SAriel Constenla-Haile ::cppu::OWeakObject, 21810b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"), 21910b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.WizardsToolbarController") 22010b918a5SAriel Constenla-Haile ) 22110b918a5SAriel Constenla-Haile 22210b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( WizardsToolbarController, {} ) 22310b918a5SAriel Constenla-Haile 22410b918a5SAriel Constenla-Haile WizardsToolbarController::WizardsToolbarController( 22510b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext ) 22610b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext ) 22710b918a5SAriel Constenla-Haile { 22810b918a5SAriel Constenla-Haile } 22910b918a5SAriel Constenla-Haile 23010b918a5SAriel Constenla-Haile sal_uInt16 WizardsToolbarController::getDropDownStyle() const 23110b918a5SAriel Constenla-Haile { 23210b918a5SAriel Constenla-Haile return TIB_DROPDOWNONLY; 23310b918a5SAriel Constenla-Haile } 23410b918a5SAriel Constenla-Haile 23510b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( OpenToolbarController, 23610b918a5SAriel Constenla-Haile ::cppu::OWeakObject, 23710b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"), 23810b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.OpenToolbarController") 23910b918a5SAriel Constenla-Haile ) 24010b918a5SAriel Constenla-Haile 24110b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( OpenToolbarController, {} ) 24210b918a5SAriel Constenla-Haile 24310b918a5SAriel Constenla-Haile OpenToolbarController::OpenToolbarController( 24410b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext ) 24510b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext, DECLARE_ASCII( UNO_COMMAND_RECENT_FILE_LIST ) ) 24610b918a5SAriel Constenla-Haile { 24710b918a5SAriel Constenla-Haile } 24810b918a5SAriel Constenla-Haile 24910b918a5SAriel Constenla-Haile 25010b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( NewToolbarController, 25110b918a5SAriel Constenla-Haile ::cppu::OWeakObject, 25210b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"), 25310b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.NewToolbarController") 25410b918a5SAriel Constenla-Haile ) 25510b918a5SAriel Constenla-Haile 25610b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( NewToolbarController, {} ) 25710b918a5SAriel Constenla-Haile 25810b918a5SAriel Constenla-Haile NewToolbarController::NewToolbarController( 25910b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext ) 26010b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext ) 26110b918a5SAriel Constenla-Haile { 26210b918a5SAriel Constenla-Haile } 26310b918a5SAriel Constenla-Haile 26410b918a5SAriel Constenla-Haile void SAL_CALL 26510b918a5SAriel Constenla-Haile NewToolbarController::statusChanged( 26610b918a5SAriel Constenla-Haile const css::frame::FeatureStateEvent& rEvent ) 26710b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException ) 26810b918a5SAriel Constenla-Haile { 26910b918a5SAriel Constenla-Haile if ( rEvent.IsEnabled ) 27010b918a5SAriel Constenla-Haile { 27110b918a5SAriel Constenla-Haile OUString aState; 27210b918a5SAriel Constenla-Haile rEvent.State >>= aState; 27310b918a5SAriel Constenla-Haile // set the image even if the state is not a string 27410b918a5SAriel Constenla-Haile // this will set the image of the default module 27510b918a5SAriel Constenla-Haile setItemImage( aState ); 27610b918a5SAriel Constenla-Haile } 27710b918a5SAriel Constenla-Haile 27810b918a5SAriel Constenla-Haile enable( rEvent.IsEnabled ); 27910b918a5SAriel Constenla-Haile } 28010b918a5SAriel Constenla-Haile 28110b918a5SAriel Constenla-Haile void NewToolbarController::functionExecuted( const OUString &rCommand ) 28210b918a5SAriel Constenla-Haile { 28310b918a5SAriel Constenla-Haile setItemImage( rCommand ); 28410b918a5SAriel Constenla-Haile } 28510b918a5SAriel Constenla-Haile 28610b918a5SAriel Constenla-Haile /** 28710b918a5SAriel Constenla-Haile it return the existing state of the given URL in the popupmenu of this toolbox control. 28810b918a5SAriel Constenla-Haile 28910b918a5SAriel Constenla-Haile If the given URL can be located as an action command of one menu item of the 29010b918a5SAriel Constenla-Haile popup menu of this control, we return sal_True. Otherwhise we return sal_False. 29110b918a5SAriel Constenla-Haile Further we return a fallback URL, in case we have to return sal_False. Because 29210b918a5SAriel Constenla-Haile the outside code must select a valid item of the popup menu everytime ... 29310b918a5SAriel Constenla-Haile and we define it here. By the way this m ethod was written to handle 29410b918a5SAriel Constenla-Haile error situations gracefully. E.g. it can be called during creation time 29510b918a5SAriel Constenla-Haile but then we have no valid menu. For this case we know another fallback URL. 29610b918a5SAriel Constenla-Haile Then we return the private:factory/ URL of the default factory. 29710b918a5SAriel Constenla-Haile 29810b918a5SAriel Constenla-Haile @param rPopupMenu 29910b918a5SAriel Constenla-Haile pounts to the popup menu, on which item we try to locate the given URL 30010b918a5SAriel Constenla-Haile Can be NULL! Search will be supressed then. 30110b918a5SAriel Constenla-Haile 30210b918a5SAriel Constenla-Haile @param sURL 30310b918a5SAriel Constenla-Haile the URL for searching 30410b918a5SAriel Constenla-Haile 30510b918a5SAriel Constenla-Haile @param sFallback 30610b918a5SAriel Constenla-Haile contains the fallback URL in case we return FALSE 30710b918a5SAriel Constenla-Haile Must point to valid memory! 30810b918a5SAriel Constenla-Haile 30910b918a5SAriel Constenla-Haile @param aImage 31010b918a5SAriel Constenla-Haile contains the image of the menu for the URL. 31110b918a5SAriel Constenla-Haile 31210b918a5SAriel Constenla-Haile @return sal_True - if URL could be located as an item of the popup menu. 31310b918a5SAriel Constenla-Haile sal_False - otherwhise. 31410b918a5SAriel Constenla-Haile */ 31510b918a5SAriel Constenla-Haile static sal_Bool Impl_ExistURLInMenu( 31610b918a5SAriel Constenla-Haile const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu, 31710b918a5SAriel Constenla-Haile OUString &sURL, 31810b918a5SAriel Constenla-Haile OUString &sFallback, 31910b918a5SAriel Constenla-Haile Image &aImage ) 32010b918a5SAriel Constenla-Haile { 32110b918a5SAriel Constenla-Haile sal_Bool bValidFallback( sal_False ); 32210b918a5SAriel Constenla-Haile sal_uInt16 nCount( 0 ); 323*dc055bd2SAriel Constenla-Haile if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) != 0 && sURL.getLength() ) 32410b918a5SAriel Constenla-Haile { 32510b918a5SAriel Constenla-Haile for ( sal_uInt16 n = 0; n < nCount; ++n ) 32610b918a5SAriel Constenla-Haile { 32710b918a5SAriel Constenla-Haile sal_uInt16 nId = rPopupMenu->getItemId( n ); 32810b918a5SAriel Constenla-Haile OUString aCmd( rPopupMenu->getCommand( nId ) ); 32910b918a5SAriel Constenla-Haile 33010b918a5SAriel Constenla-Haile if ( !bValidFallback && aCmd.getLength() ) 33110b918a5SAriel Constenla-Haile { 33210b918a5SAriel Constenla-Haile sFallback = aCmd; 33310b918a5SAriel Constenla-Haile bValidFallback = sal_True; 33410b918a5SAriel Constenla-Haile } 33510b918a5SAriel Constenla-Haile 33610b918a5SAriel Constenla-Haile // match even if the menu command is more detailed 33710b918a5SAriel Constenla-Haile // (maybe an additional query) #i28667# 33810b918a5SAriel Constenla-Haile if ( aCmd.match( sURL ) ) 33910b918a5SAriel Constenla-Haile { 34010b918a5SAriel Constenla-Haile sURL = aCmd; 34110b918a5SAriel Constenla-Haile const css::uno::Reference< css::graphic::XGraphic > xGraphic( 34210b918a5SAriel Constenla-Haile rPopupMenu->getItemImage( nId ) ); 34310b918a5SAriel Constenla-Haile if ( xGraphic.is() ) 34410b918a5SAriel Constenla-Haile aImage = Image( xGraphic ); 34510b918a5SAriel Constenla-Haile return sal_True; 34610b918a5SAriel Constenla-Haile } 34710b918a5SAriel Constenla-Haile } 34810b918a5SAriel Constenla-Haile } 34910b918a5SAriel Constenla-Haile 35010b918a5SAriel Constenla-Haile if ( !bValidFallback ) 35110b918a5SAriel Constenla-Haile { 35210b918a5SAriel Constenla-Haile rtl::OUStringBuffer aBuffer; 35310b918a5SAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) ); 35410b918a5SAriel Constenla-Haile aBuffer.append( SvtModuleOptions().GetDefaultModuleName() ); 35510b918a5SAriel Constenla-Haile sFallback = aBuffer.makeStringAndClear(); 35610b918a5SAriel Constenla-Haile } 35710b918a5SAriel Constenla-Haile 35810b918a5SAriel Constenla-Haile return sal_False; 35910b918a5SAriel Constenla-Haile } 36010b918a5SAriel Constenla-Haile 36110b918a5SAriel Constenla-Haile /** We accept URL's here only, which exist as items of our internal popup menu. 36210b918a5SAriel Constenla-Haile All other ones will be ignored and a fallback is used. 36310b918a5SAriel Constenla-Haile */ 36410b918a5SAriel Constenla-Haile void NewToolbarController::setItemImage( const OUString &rCommand ) 36510b918a5SAriel Constenla-Haile { 36610b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() ); 36710b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) ); 36810b918a5SAriel Constenla-Haile if ( !pToolBox ) 36910b918a5SAriel Constenla-Haile return; 37010b918a5SAriel Constenla-Haile 37110b918a5SAriel Constenla-Haile OUString aURL = rCommand; 37210b918a5SAriel Constenla-Haile OUString sFallback; 37310b918a5SAriel Constenla-Haile Image aMenuImage; 37410b918a5SAriel Constenla-Haile 37510b918a5SAriel Constenla-Haile sal_Bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) ); 37610b918a5SAriel Constenla-Haile // do not change aURL if Impl_ExistURLInMenu returned sal_False 37710b918a5SAriel Constenla-Haile // this allows later initialization of the PopupMenuController on createPopupWindow() 37810b918a5SAriel Constenla-Haile // and works even if SvFileInformationManager does not know the module 37910b918a5SAriel Constenla-Haile if ( !aURL.getLength() ) 38010b918a5SAriel Constenla-Haile aURL = sFallback; 38110b918a5SAriel Constenla-Haile 38210b918a5SAriel Constenla-Haile sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge(); 38310b918a5SAriel Constenla-Haile sal_Bool bHC = pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode(); 38410b918a5SAriel Constenla-Haile 38510b918a5SAriel Constenla-Haile INetURLObject aURLObj( aURL ); 38610b918a5SAriel Constenla-Haile Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig, bHC ); 38710b918a5SAriel Constenla-Haile if ( !aImage ) 38810b918a5SAriel Constenla-Haile { 38910b918a5SAriel Constenla-Haile if ( !!aMenuImage ) 39010b918a5SAriel Constenla-Haile aImage = aMenuImage; 39110b918a5SAriel Constenla-Haile else if ( !bValid ) 39210b918a5SAriel Constenla-Haile // If SvFileInformationManager didn't know the module, try with the default 39310b918a5SAriel Constenla-Haile aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( sFallback ), bBig, bHC ); 39410b918a5SAriel Constenla-Haile 39510b918a5SAriel Constenla-Haile if ( !aImage ) 39610b918a5SAriel Constenla-Haile aImage = SvFileInformationManager::GetImage( aURLObj, bBig, bHC ); 39710b918a5SAriel Constenla-Haile } 39810b918a5SAriel Constenla-Haile 39910b918a5SAriel Constenla-Haile // if everything failed, just use the image associated with the toolbar item command 40010b918a5SAriel Constenla-Haile if ( !aImage ) 40110b918a5SAriel Constenla-Haile return; 40210b918a5SAriel Constenla-Haile 40310b918a5SAriel Constenla-Haile Size aBigSize( pToolBox->GetDefaultImageSize() ); 40410b918a5SAriel Constenla-Haile if ( bBig && aImage.GetSizePixel() != aBigSize ) 40510b918a5SAriel Constenla-Haile { 40610b918a5SAriel Constenla-Haile BitmapEx aScaleBmpEx( aImage.GetBitmapEx() ); 40710b918a5SAriel Constenla-Haile aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE ); 40810b918a5SAriel Constenla-Haile pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) ); 40910b918a5SAriel Constenla-Haile } 41010b918a5SAriel Constenla-Haile else 41110b918a5SAriel Constenla-Haile pToolBox->SetItemImage( m_nToolBoxId, aImage ); 41210b918a5SAriel Constenla-Haile } 41310b918a5SAriel Constenla-Haile 41410b918a5SAriel Constenla-Haile 41510b918a5SAriel Constenla-Haile } 416