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>
267ca83afaSAriel Constenla-Haile #include <framework/menuconfiguration.hxx>
277ca83afaSAriel Constenla-Haile #include <toolkit/awt/vclxmenu.hxx>
2810b918a5SAriel Constenla-Haile #include <comphelper/processfactory.hxx>
2910b918a5SAriel Constenla-Haile #include <svtools/imagemgr.hxx>
3010b918a5SAriel Constenla-Haile #include <svtools/miscopt.hxx>
3110b918a5SAriel Constenla-Haile #include <toolkit/helper/vclunohelper.hxx>
3210b918a5SAriel Constenla-Haile #include <tools/urlobj.hxx>
3310b918a5SAriel Constenla-Haile #include <unotools/moduleoptions.hxx>
3410b918a5SAriel Constenla-Haile #include <vcl/svapp.hxx>
3510b918a5SAriel Constenla-Haile #include <vcl/toolbox.hxx>
3610b918a5SAriel Constenla-Haile #include <vos/mutex.hxx>
3710b918a5SAriel Constenla-Haile
3810b918a5SAriel Constenla-Haile #include <com/sun/star/awt/PopupMenuDirection.hpp>
3910b918a5SAriel Constenla-Haile #include <com/sun/star/frame/PopupMenuControllerFactory.hpp>
407ca83afaSAriel Constenla-Haile #include <com/sun/star/frame/XDispatchProvider.hpp>
4110b918a5SAriel Constenla-Haile
4210b918a5SAriel Constenla-Haile #define UNO_COMMAND_RECENT_FILE_LIST ".uno:RecentFileList"
437ca83afaSAriel Constenla-Haile #define SFX_REFERER_USER "private:user"
4410b918a5SAriel Constenla-Haile
4510b918a5SAriel Constenla-Haile using rtl::OUString;
4610b918a5SAriel Constenla-Haile namespace css = ::com::sun::star;
4710b918a5SAriel Constenla-Haile
4810b918a5SAriel Constenla-Haile namespace framework
4910b918a5SAriel Constenla-Haile {
5010b918a5SAriel Constenla-Haile
PopupMenuToolbarController(const css::uno::Reference<css::uno::XComponentContext> & xContext,const OUString & rPopupCommand)5110b918a5SAriel Constenla-Haile PopupMenuToolbarController::PopupMenuToolbarController(
5210b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext,
5310b918a5SAriel Constenla-Haile const OUString &rPopupCommand )
5410b918a5SAriel Constenla-Haile : svt::ToolboxController()
5510b918a5SAriel Constenla-Haile , m_xContext( xContext )
5610b918a5SAriel Constenla-Haile , m_bHasController( sal_False )
5710b918a5SAriel Constenla-Haile , m_aPopupCommand( rPopupCommand )
5810b918a5SAriel Constenla-Haile {
5910b918a5SAriel Constenla-Haile }
6010b918a5SAriel Constenla-Haile
~PopupMenuToolbarController()6110b918a5SAriel Constenla-Haile PopupMenuToolbarController::~PopupMenuToolbarController()
6210b918a5SAriel Constenla-Haile {
6310b918a5SAriel Constenla-Haile }
6410b918a5SAriel Constenla-Haile
dispose()6510b918a5SAriel Constenla-Haile void SAL_CALL PopupMenuToolbarController::dispose()
6610b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException )
6710b918a5SAriel Constenla-Haile {
6810b918a5SAriel Constenla-Haile svt::ToolboxController::dispose();
6910b918a5SAriel Constenla-Haile
7010b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex );
7110b918a5SAriel Constenla-Haile if( m_xPopupMenuController.is() )
7210b918a5SAriel Constenla-Haile {
7310b918a5SAriel Constenla-Haile css::uno::Reference< css::lang::XComponent > xComponent(
7410b918a5SAriel Constenla-Haile m_xPopupMenuController, css::uno::UNO_QUERY );
7510b918a5SAriel Constenla-Haile if( xComponent.is() )
7610b918a5SAriel Constenla-Haile {
7710b918a5SAriel Constenla-Haile try
7810b918a5SAriel Constenla-Haile {
7910b918a5SAriel Constenla-Haile xComponent->dispose();
8010b918a5SAriel Constenla-Haile }
8110b918a5SAriel Constenla-Haile catch (...)
8210b918a5SAriel Constenla-Haile {}
8310b918a5SAriel Constenla-Haile }
8410b918a5SAriel Constenla-Haile m_xPopupMenuController.clear();
8510b918a5SAriel Constenla-Haile }
8610b918a5SAriel Constenla-Haile
8710b918a5SAriel Constenla-Haile m_xContext.clear();
8810b918a5SAriel Constenla-Haile m_xPopupMenuFactory.clear();
8910b918a5SAriel Constenla-Haile m_xPopupMenu.clear();
9010b918a5SAriel Constenla-Haile }
9110b918a5SAriel Constenla-Haile
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)9210b918a5SAriel Constenla-Haile void SAL_CALL PopupMenuToolbarController::initialize(
9310b918a5SAriel Constenla-Haile const css::uno::Sequence< css::uno::Any >& aArguments )
9410b918a5SAriel Constenla-Haile throw ( css::uno::Exception, css::uno::RuntimeException )
9510b918a5SAriel Constenla-Haile {
9610b918a5SAriel Constenla-Haile ToolboxController::initialize( aArguments );
9710b918a5SAriel Constenla-Haile
9810b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex );
9910b918a5SAriel Constenla-Haile if ( !m_aPopupCommand.getLength() )
10010b918a5SAriel Constenla-Haile m_aPopupCommand = m_aCommandURL;
10110b918a5SAriel Constenla-Haile
10210b918a5SAriel Constenla-Haile try
10310b918a5SAriel Constenla-Haile {
10410b918a5SAriel Constenla-Haile m_xPopupMenuFactory.set(
10510b918a5SAriel Constenla-Haile css::frame::PopupMenuControllerFactory::create( m_xContext ) );
10610b918a5SAriel Constenla-Haile m_bHasController = m_xPopupMenuFactory->hasController(
10710b918a5SAriel Constenla-Haile m_aPopupCommand, getModuleName() );
10810b918a5SAriel Constenla-Haile }
10910b918a5SAriel Constenla-Haile catch (const css::uno::Exception& e)
11010b918a5SAriel Constenla-Haile {
11110b918a5SAriel Constenla-Haile OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s",
11210b918a5SAriel Constenla-Haile rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
11310b918a5SAriel Constenla-Haile (void) e;
11410b918a5SAriel Constenla-Haile }
11510b918a5SAriel Constenla-Haile
11610b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
11710b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
11810b918a5SAriel Constenla-Haile if ( pToolBox )
11910b918a5SAriel Constenla-Haile {
12010b918a5SAriel Constenla-Haile ToolBoxItemBits nCurStyle( pToolBox->GetItemBits( m_nToolBoxId ) );
12110b918a5SAriel Constenla-Haile ToolBoxItemBits nSetStyle( getDropDownStyle() );
12210b918a5SAriel Constenla-Haile pToolBox->SetItemBits( m_nToolBoxId,
12310b918a5SAriel Constenla-Haile m_bHasController ?
12410b918a5SAriel Constenla-Haile nCurStyle | nSetStyle :
12510b918a5SAriel Constenla-Haile nCurStyle & ~nSetStyle );
12610b918a5SAriel Constenla-Haile }
12710b918a5SAriel Constenla-Haile
12810b918a5SAriel Constenla-Haile }
12910b918a5SAriel Constenla-Haile
13010b918a5SAriel Constenla-Haile void SAL_CALL
statusChanged(const css::frame::FeatureStateEvent & rEvent)13110b918a5SAriel Constenla-Haile PopupMenuToolbarController::statusChanged(
13210b918a5SAriel Constenla-Haile const css::frame::FeatureStateEvent& rEvent )
13310b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException )
13410b918a5SAriel Constenla-Haile {
13510b918a5SAriel Constenla-Haile // TODO move to base class
13610b918a5SAriel Constenla-Haile
13710b918a5SAriel Constenla-Haile svt::ToolboxController::statusChanged( rEvent );
13810b918a5SAriel Constenla-Haile enable( rEvent.IsEnabled );
13910b918a5SAriel Constenla-Haile }
14010b918a5SAriel Constenla-Haile
14110b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindow > SAL_CALL
createPopupWindow()14210b918a5SAriel Constenla-Haile PopupMenuToolbarController::createPopupWindow()
14310b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException )
14410b918a5SAriel Constenla-Haile {
14510b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindow > xRet;
14610b918a5SAriel Constenla-Haile
14710b918a5SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex );
14810b918a5SAriel Constenla-Haile if ( !m_bHasController )
14910b918a5SAriel Constenla-Haile return xRet;
15010b918a5SAriel Constenla-Haile
15110b918a5SAriel Constenla-Haile createPopupMenuController();
15210b918a5SAriel Constenla-Haile
15310b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
15410b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
15510b918a5SAriel Constenla-Haile if ( !pToolBox )
15610b918a5SAriel Constenla-Haile return xRet;
15710b918a5SAriel Constenla-Haile
15810b918a5SAriel Constenla-Haile pToolBox->SetItemDown( m_nToolBoxId, sal_True );
15910b918a5SAriel Constenla-Haile sal_uInt16 nId = m_xPopupMenu->execute(
16010b918a5SAriel Constenla-Haile css::uno::Reference< css::awt::XWindowPeer >( getParent(), css::uno::UNO_QUERY ),
16110b918a5SAriel Constenla-Haile VCLUnoHelper::ConvertToAWTRect( pToolBox->GetItemRect( m_nToolBoxId ) ),
16210b918a5SAriel Constenla-Haile css::awt::PopupMenuDirection::EXECUTE_DEFAULT );
16310b918a5SAriel Constenla-Haile pToolBox->SetItemDown( m_nToolBoxId, sal_False );
16410b918a5SAriel Constenla-Haile
16510b918a5SAriel Constenla-Haile if ( nId )
16610b918a5SAriel Constenla-Haile functionExecuted( m_xPopupMenu->getCommand( nId ) );
16710b918a5SAriel Constenla-Haile
16810b918a5SAriel Constenla-Haile return xRet;
16910b918a5SAriel Constenla-Haile }
17010b918a5SAriel Constenla-Haile
functionExecuted(const OUString &)17110b918a5SAriel Constenla-Haile void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/)
17210b918a5SAriel Constenla-Haile {
17310b918a5SAriel Constenla-Haile }
17410b918a5SAriel Constenla-Haile
getDropDownStyle() const17510b918a5SAriel Constenla-Haile sal_uInt16 PopupMenuToolbarController::getDropDownStyle() const
17610b918a5SAriel Constenla-Haile {
17710b918a5SAriel Constenla-Haile return TIB_DROPDOWN;
17810b918a5SAriel Constenla-Haile }
17910b918a5SAriel Constenla-Haile
createPopupMenuController()18010b918a5SAriel Constenla-Haile void PopupMenuToolbarController::createPopupMenuController()
18110b918a5SAriel Constenla-Haile {
18210b918a5SAriel Constenla-Haile if( !m_bHasController )
18310b918a5SAriel Constenla-Haile return;
18410b918a5SAriel Constenla-Haile
18510b918a5SAriel Constenla-Haile if ( !m_xPopupMenuController.is() )
18610b918a5SAriel Constenla-Haile {
18710b918a5SAriel Constenla-Haile css::uno::Sequence< css::uno::Any > aArgs( 2 );
18810b918a5SAriel Constenla-Haile css::beans::PropertyValue aProp;
18910b918a5SAriel Constenla-Haile
19010b918a5SAriel Constenla-Haile aProp.Name = DECLARE_ASCII( "Frame" );
19110b918a5SAriel Constenla-Haile aProp.Value <<= m_xFrame;
19210b918a5SAriel Constenla-Haile aArgs[0] <<= aProp;
19310b918a5SAriel Constenla-Haile
19410b918a5SAriel Constenla-Haile aProp.Name = DECLARE_ASCII( "ModuleIdentifier" );
19510b918a5SAriel Constenla-Haile aProp.Value <<= getModuleName();
19610b918a5SAriel Constenla-Haile aArgs[1] <<= aProp;
19710b918a5SAriel Constenla-Haile try
19810b918a5SAriel Constenla-Haile {
19910b918a5SAriel Constenla-Haile m_xPopupMenu.set(
20010b918a5SAriel Constenla-Haile m_xContext->getServiceManager()->createInstanceWithContext(
20110b918a5SAriel Constenla-Haile DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), m_xContext ),
20210b918a5SAriel Constenla-Haile css::uno::UNO_QUERY_THROW );
20310b918a5SAriel Constenla-Haile m_xPopupMenuController.set(
20410b918a5SAriel Constenla-Haile m_xPopupMenuFactory->createInstanceWithArgumentsAndContext(
20510b918a5SAriel Constenla-Haile m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW );
20610b918a5SAriel Constenla-Haile
20710b918a5SAriel Constenla-Haile m_xPopupMenuController->setPopupMenu( m_xPopupMenu );
20810b918a5SAriel Constenla-Haile }
20910b918a5SAriel Constenla-Haile catch ( const css::uno::Exception &e )
21010b918a5SAriel Constenla-Haile {
21110b918a5SAriel Constenla-Haile m_xPopupMenu.clear();
21210b918a5SAriel Constenla-Haile OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s",
21310b918a5SAriel Constenla-Haile rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
21410b918a5SAriel Constenla-Haile (void) e;
21510b918a5SAriel Constenla-Haile }
21610b918a5SAriel Constenla-Haile }
21710b918a5SAriel Constenla-Haile }
21810b918a5SAriel Constenla-Haile
21910b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( WizardsToolbarController,
22010b918a5SAriel Constenla-Haile ::cppu::OWeakObject,
22110b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
22210b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.WizardsToolbarController")
22310b918a5SAriel Constenla-Haile )
22410b918a5SAriel Constenla-Haile
22510b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( WizardsToolbarController, {} )
22610b918a5SAriel Constenla-Haile
WizardsToolbarController(const css::uno::Reference<css::uno::XComponentContext> & xContext)22710b918a5SAriel Constenla-Haile WizardsToolbarController::WizardsToolbarController(
22810b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext )
22910b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext )
23010b918a5SAriel Constenla-Haile {
23110b918a5SAriel Constenla-Haile }
23210b918a5SAriel Constenla-Haile
getDropDownStyle() const23310b918a5SAriel Constenla-Haile sal_uInt16 WizardsToolbarController::getDropDownStyle() const
23410b918a5SAriel Constenla-Haile {
23510b918a5SAriel Constenla-Haile return TIB_DROPDOWNONLY;
23610b918a5SAriel Constenla-Haile }
23710b918a5SAriel Constenla-Haile
23810b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( OpenToolbarController,
23910b918a5SAriel Constenla-Haile ::cppu::OWeakObject,
24010b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
24110b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.OpenToolbarController")
24210b918a5SAriel Constenla-Haile )
24310b918a5SAriel Constenla-Haile
24410b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( OpenToolbarController, {} )
24510b918a5SAriel Constenla-Haile
OpenToolbarController(const css::uno::Reference<css::uno::XComponentContext> & xContext)24610b918a5SAriel Constenla-Haile OpenToolbarController::OpenToolbarController(
24710b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext )
24810b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext, DECLARE_ASCII( UNO_COMMAND_RECENT_FILE_LIST ) )
24910b918a5SAriel Constenla-Haile {
25010b918a5SAriel Constenla-Haile }
25110b918a5SAriel Constenla-Haile
25210b918a5SAriel Constenla-Haile
25310b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( NewToolbarController,
25410b918a5SAriel Constenla-Haile ::cppu::OWeakObject,
25510b918a5SAriel Constenla-Haile DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
25610b918a5SAriel Constenla-Haile DECLARE_ASCII("org.apache.openoffice.comp.framework.NewToolbarController")
25710b918a5SAriel Constenla-Haile )
25810b918a5SAriel Constenla-Haile
25910b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( NewToolbarController, {} )
26010b918a5SAriel Constenla-Haile
NewToolbarController(const css::uno::Reference<css::uno::XComponentContext> & xContext)26110b918a5SAriel Constenla-Haile NewToolbarController::NewToolbarController(
26210b918a5SAriel Constenla-Haile const css::uno::Reference< css::uno::XComponentContext >& xContext )
26310b918a5SAriel Constenla-Haile : PopupMenuToolbarController( xContext )
26410b918a5SAriel Constenla-Haile {
26510b918a5SAriel Constenla-Haile }
26610b918a5SAriel Constenla-Haile
26710b918a5SAriel Constenla-Haile void SAL_CALL
initialize(const css::uno::Sequence<css::uno::Any> & aArguments)26889d8a215SAriel Constenla-Haile NewToolbarController::initialize(
26989d8a215SAriel Constenla-Haile const css::uno::Sequence< css::uno::Any >& aArguments )
27089d8a215SAriel Constenla-Haile throw ( css::uno::Exception, css::uno::RuntimeException )
27189d8a215SAriel Constenla-Haile {
27289d8a215SAriel Constenla-Haile PopupMenuToolbarController::initialize( aArguments );
27389d8a215SAriel Constenla-Haile
27489d8a215SAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex );
27589d8a215SAriel Constenla-Haile createPopupMenuController();
27689d8a215SAriel Constenla-Haile }
27789d8a215SAriel Constenla-Haile
27889d8a215SAriel Constenla-Haile void SAL_CALL
statusChanged(const css::frame::FeatureStateEvent & rEvent)27910b918a5SAriel Constenla-Haile NewToolbarController::statusChanged(
28010b918a5SAriel Constenla-Haile const css::frame::FeatureStateEvent& rEvent )
28110b918a5SAriel Constenla-Haile throw ( css::uno::RuntimeException )
28210b918a5SAriel Constenla-Haile {
28310b918a5SAriel Constenla-Haile if ( rEvent.IsEnabled )
28410b918a5SAriel Constenla-Haile {
28510b918a5SAriel Constenla-Haile OUString aState;
28610b918a5SAriel Constenla-Haile rEvent.State >>= aState;
28710b918a5SAriel Constenla-Haile // set the image even if the state is not a string
28810b918a5SAriel Constenla-Haile // this will set the image of the default module
28910b918a5SAriel Constenla-Haile setItemImage( aState );
29010b918a5SAriel Constenla-Haile }
29110b918a5SAriel Constenla-Haile
29210b918a5SAriel Constenla-Haile enable( rEvent.IsEnabled );
29310b918a5SAriel Constenla-Haile }
29410b918a5SAriel Constenla-Haile
2957ca83afaSAriel Constenla-Haile void SAL_CALL
execute(sal_Int16)2967ca83afaSAriel Constenla-Haile NewToolbarController::execute( sal_Int16 /*KeyModifier*/ )
2977ca83afaSAriel Constenla-Haile throw ( css::uno::RuntimeException )
2987ca83afaSAriel Constenla-Haile {
2997ca83afaSAriel Constenla-Haile osl::MutexGuard aGuard( m_aMutex );
3007ca83afaSAriel Constenla-Haile if ( !m_aLastURL.getLength() )
3017ca83afaSAriel Constenla-Haile return;
3027ca83afaSAriel Constenla-Haile
3037ca83afaSAriel Constenla-Haile OUString aTarget( RTL_CONSTASCII_USTRINGPARAM( "_default" ) );
3047ca83afaSAriel Constenla-Haile if ( m_xPopupMenu.is() )
3057ca83afaSAriel Constenla-Haile {
3067ca83afaSAriel Constenla-Haile // TODO investigate how to wrap Get/SetUserValue in css::awt::XMenu
3077ca83afaSAriel Constenla-Haile MenuConfiguration::Attributes* pMenuAttributes( 0 );
308*9b1ae0e5SAriel Constenla-Haile VCLXPopupMenu* pTkPopupMenu =
309*9b1ae0e5SAriel Constenla-Haile ( VCLXPopupMenu * ) VCLXMenu::GetImplementation( m_xPopupMenu );
3107ca83afaSAriel Constenla-Haile
3117ca83afaSAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
3127ca83afaSAriel Constenla-Haile PopupMenu* pVCLPopupMenu = dynamic_cast< PopupMenu * >( pTkPopupMenu->GetMenu() );
3137ca83afaSAriel Constenla-Haile if ( pVCLPopupMenu )
3147ca83afaSAriel Constenla-Haile pMenuAttributes = reinterpret_cast< MenuConfiguration::Attributes* >(
3157ca83afaSAriel Constenla-Haile pVCLPopupMenu->GetUserValue( pVCLPopupMenu->GetCurItemId() ) );
3167ca83afaSAriel Constenla-Haile
3177ca83afaSAriel Constenla-Haile if ( pMenuAttributes )
3187ca83afaSAriel Constenla-Haile aTarget = pMenuAttributes->aTargetFrame;
3197ca83afaSAriel Constenla-Haile }
3207ca83afaSAriel Constenla-Haile
3217ca83afaSAriel Constenla-Haile css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
3227ca83afaSAriel Constenla-Haile aArgs[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer" ));
3237ca83afaSAriel Constenla-Haile aArgs[0].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER ) );
3247ca83afaSAriel Constenla-Haile
3257ca83afaSAriel Constenla-Haile dispatchCommand( m_aLastURL, aArgs, aTarget );
3267ca83afaSAriel Constenla-Haile }
3277ca83afaSAriel Constenla-Haile
functionExecuted(const OUString & rCommand)32810b918a5SAriel Constenla-Haile void NewToolbarController::functionExecuted( const OUString &rCommand )
32910b918a5SAriel Constenla-Haile {
33010b918a5SAriel Constenla-Haile setItemImage( rCommand );
33110b918a5SAriel Constenla-Haile }
33210b918a5SAriel Constenla-Haile
33310b918a5SAriel Constenla-Haile /**
33410b918a5SAriel Constenla-Haile it return the existing state of the given URL in the popupmenu of this toolbox control.
33510b918a5SAriel Constenla-Haile
33610b918a5SAriel Constenla-Haile If the given URL can be located as an action command of one menu item of the
33710b918a5SAriel Constenla-Haile popup menu of this control, we return sal_True. Otherwhise we return sal_False.
33810b918a5SAriel Constenla-Haile Further we return a fallback URL, in case we have to return sal_False. Because
33910b918a5SAriel Constenla-Haile the outside code must select a valid item of the popup menu everytime ...
34010b918a5SAriel Constenla-Haile and we define it here. By the way this m ethod was written to handle
34110b918a5SAriel Constenla-Haile error situations gracefully. E.g. it can be called during creation time
34210b918a5SAriel Constenla-Haile but then we have no valid menu. For this case we know another fallback URL.
34310b918a5SAriel Constenla-Haile Then we return the private:factory/ URL of the default factory.
34410b918a5SAriel Constenla-Haile
34510b918a5SAriel Constenla-Haile @param rPopupMenu
34610b918a5SAriel Constenla-Haile pounts to the popup menu, on which item we try to locate the given URL
34710b918a5SAriel Constenla-Haile Can be NULL! Search will be supressed then.
34810b918a5SAriel Constenla-Haile
34910b918a5SAriel Constenla-Haile @param sURL
35010b918a5SAriel Constenla-Haile the URL for searching
35110b918a5SAriel Constenla-Haile
35210b918a5SAriel Constenla-Haile @param sFallback
35310b918a5SAriel Constenla-Haile contains the fallback URL in case we return FALSE
35410b918a5SAriel Constenla-Haile Must point to valid memory!
35510b918a5SAriel Constenla-Haile
35610b918a5SAriel Constenla-Haile @param aImage
35710b918a5SAriel Constenla-Haile contains the image of the menu for the URL.
35810b918a5SAriel Constenla-Haile
35910b918a5SAriel Constenla-Haile @return sal_True - if URL could be located as an item of the popup menu.
36010b918a5SAriel Constenla-Haile sal_False - otherwhise.
36110b918a5SAriel Constenla-Haile */
Impl_ExistURLInMenu(const css::uno::Reference<css::awt::XPopupMenu> & rPopupMenu,OUString & sURL,OUString & sFallback,Image & aImage)36210b918a5SAriel Constenla-Haile static sal_Bool Impl_ExistURLInMenu(
36310b918a5SAriel Constenla-Haile const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu,
36410b918a5SAriel Constenla-Haile OUString &sURL,
36510b918a5SAriel Constenla-Haile OUString &sFallback,
36610b918a5SAriel Constenla-Haile Image &aImage )
36710b918a5SAriel Constenla-Haile {
36810b918a5SAriel Constenla-Haile sal_Bool bValidFallback( sal_False );
36910b918a5SAriel Constenla-Haile sal_uInt16 nCount( 0 );
370dc055bd2SAriel Constenla-Haile if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) != 0 && sURL.getLength() )
37110b918a5SAriel Constenla-Haile {
37210b918a5SAriel Constenla-Haile for ( sal_uInt16 n = 0; n < nCount; ++n )
37310b918a5SAriel Constenla-Haile {
37410b918a5SAriel Constenla-Haile sal_uInt16 nId = rPopupMenu->getItemId( n );
37510b918a5SAriel Constenla-Haile OUString aCmd( rPopupMenu->getCommand( nId ) );
37610b918a5SAriel Constenla-Haile
37710b918a5SAriel Constenla-Haile if ( !bValidFallback && aCmd.getLength() )
37810b918a5SAriel Constenla-Haile {
37910b918a5SAriel Constenla-Haile sFallback = aCmd;
38010b918a5SAriel Constenla-Haile bValidFallback = sal_True;
38110b918a5SAriel Constenla-Haile }
38210b918a5SAriel Constenla-Haile
38310b918a5SAriel Constenla-Haile // match even if the menu command is more detailed
38410b918a5SAriel Constenla-Haile // (maybe an additional query) #i28667#
38510b918a5SAriel Constenla-Haile if ( aCmd.match( sURL ) )
38610b918a5SAriel Constenla-Haile {
38710b918a5SAriel Constenla-Haile sURL = aCmd;
38810b918a5SAriel Constenla-Haile const css::uno::Reference< css::graphic::XGraphic > xGraphic(
38910b918a5SAriel Constenla-Haile rPopupMenu->getItemImage( nId ) );
39010b918a5SAriel Constenla-Haile if ( xGraphic.is() )
39110b918a5SAriel Constenla-Haile aImage = Image( xGraphic );
39210b918a5SAriel Constenla-Haile return sal_True;
39310b918a5SAriel Constenla-Haile }
39410b918a5SAriel Constenla-Haile }
39510b918a5SAriel Constenla-Haile }
39610b918a5SAriel Constenla-Haile
39710b918a5SAriel Constenla-Haile if ( !bValidFallback )
39810b918a5SAriel Constenla-Haile {
39910b918a5SAriel Constenla-Haile rtl::OUStringBuffer aBuffer;
40010b918a5SAriel Constenla-Haile aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) );
40110b918a5SAriel Constenla-Haile aBuffer.append( SvtModuleOptions().GetDefaultModuleName() );
40210b918a5SAriel Constenla-Haile sFallback = aBuffer.makeStringAndClear();
40310b918a5SAriel Constenla-Haile }
40410b918a5SAriel Constenla-Haile
40510b918a5SAriel Constenla-Haile return sal_False;
40610b918a5SAriel Constenla-Haile }
40710b918a5SAriel Constenla-Haile
40810b918a5SAriel Constenla-Haile /** We accept URL's here only, which exist as items of our internal popup menu.
40910b918a5SAriel Constenla-Haile All other ones will be ignored and a fallback is used.
41010b918a5SAriel Constenla-Haile */
setItemImage(const OUString & rCommand)41110b918a5SAriel Constenla-Haile void NewToolbarController::setItemImage( const OUString &rCommand )
41210b918a5SAriel Constenla-Haile {
41310b918a5SAriel Constenla-Haile vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
41410b918a5SAriel Constenla-Haile ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
41510b918a5SAriel Constenla-Haile if ( !pToolBox )
41610b918a5SAriel Constenla-Haile return;
41710b918a5SAriel Constenla-Haile
41810b918a5SAriel Constenla-Haile OUString aURL = rCommand;
41910b918a5SAriel Constenla-Haile OUString sFallback;
42010b918a5SAriel Constenla-Haile Image aMenuImage;
42110b918a5SAriel Constenla-Haile
42210b918a5SAriel Constenla-Haile sal_Bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) );
42389d8a215SAriel Constenla-Haile if ( !bValid )
42410b918a5SAriel Constenla-Haile aURL = sFallback;
42510b918a5SAriel Constenla-Haile
42610b918a5SAriel Constenla-Haile sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
42710b918a5SAriel Constenla-Haile sal_Bool bHC = pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode();
42810b918a5SAriel Constenla-Haile
42910b918a5SAriel Constenla-Haile INetURLObject aURLObj( aURL );
43010b918a5SAriel Constenla-Haile Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig, bHC );
43110b918a5SAriel Constenla-Haile if ( !aImage )
43289d8a215SAriel Constenla-Haile aImage = !!aMenuImage ?
43389d8a215SAriel Constenla-Haile aMenuImage :
43489d8a215SAriel Constenla-Haile SvFileInformationManager::GetImage( aURLObj, bBig, bHC );
43510b918a5SAriel Constenla-Haile
43610b918a5SAriel Constenla-Haile // if everything failed, just use the image associated with the toolbar item command
43710b918a5SAriel Constenla-Haile if ( !aImage )
43810b918a5SAriel Constenla-Haile return;
43910b918a5SAriel Constenla-Haile
44010b918a5SAriel Constenla-Haile Size aBigSize( pToolBox->GetDefaultImageSize() );
44110b918a5SAriel Constenla-Haile if ( bBig && aImage.GetSizePixel() != aBigSize )
44210b918a5SAriel Constenla-Haile {
44310b918a5SAriel Constenla-Haile BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
44410b918a5SAriel Constenla-Haile aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
44510b918a5SAriel Constenla-Haile pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
44610b918a5SAriel Constenla-Haile }
44710b918a5SAriel Constenla-Haile else
44810b918a5SAriel Constenla-Haile pToolBox->SetItemImage( m_nToolBoxId, aImage );
4497ca83afaSAriel Constenla-Haile
4507ca83afaSAriel Constenla-Haile m_aLastURL = aURL;
45110b918a5SAriel Constenla-Haile }
45210b918a5SAriel Constenla-Haile
45310b918a5SAriel Constenla-Haile
45410b918a5SAriel Constenla-Haile }
455