xref: /AOO41X/main/framework/source/uielement/popuptoolbarcontroller.cxx (revision 7ca83afa5f2e8662ebd40bd4e428b69092564614)
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>
26*7ca83afaSAriel Constenla-Haile #include <framework/menuconfiguration.hxx>
27*7ca83afaSAriel 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>
40*7ca83afaSAriel Constenla-Haile #include <com/sun/star/frame/XDispatchProvider.hpp>
4110b918a5SAriel Constenla-Haile 
4210b918a5SAriel Constenla-Haile #define UNO_COMMAND_RECENT_FILE_LIST    ".uno:RecentFileList"
43*7ca83afaSAriel 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 
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 
6110b918a5SAriel Constenla-Haile PopupMenuToolbarController::~PopupMenuToolbarController()
6210b918a5SAriel Constenla-Haile {
6310b918a5SAriel Constenla-Haile }
6410b918a5SAriel Constenla-Haile 
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 
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
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
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 
17110b918a5SAriel Constenla-Haile void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/)
17210b918a5SAriel Constenla-Haile {
17310b918a5SAriel Constenla-Haile }
17410b918a5SAriel Constenla-Haile 
17510b918a5SAriel Constenla-Haile sal_uInt16 PopupMenuToolbarController::getDropDownStyle() const
17610b918a5SAriel Constenla-Haile {
17710b918a5SAriel Constenla-Haile     return TIB_DROPDOWN;
17810b918a5SAriel Constenla-Haile }
17910b918a5SAriel Constenla-Haile 
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 
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 
23310b918a5SAriel 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 
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 
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
26810b918a5SAriel Constenla-Haile NewToolbarController::statusChanged(
26910b918a5SAriel Constenla-Haile     const css::frame::FeatureStateEvent& rEvent )
27010b918a5SAriel Constenla-Haile     throw ( css::uno::RuntimeException )
27110b918a5SAriel Constenla-Haile {
27210b918a5SAriel Constenla-Haile     if ( rEvent.IsEnabled )
27310b918a5SAriel Constenla-Haile     {
27410b918a5SAriel Constenla-Haile         OUString aState;
27510b918a5SAriel Constenla-Haile         rEvent.State >>= aState;
27610b918a5SAriel Constenla-Haile         // set the image even if the state is not a string
27710b918a5SAriel Constenla-Haile         // this will set the image of the default module
27810b918a5SAriel Constenla-Haile         setItemImage( aState );
27910b918a5SAriel Constenla-Haile     }
28010b918a5SAriel Constenla-Haile 
28110b918a5SAriel Constenla-Haile     enable( rEvent.IsEnabled );
28210b918a5SAriel Constenla-Haile }
28310b918a5SAriel Constenla-Haile 
284*7ca83afaSAriel Constenla-Haile void SAL_CALL
285*7ca83afaSAriel Constenla-Haile NewToolbarController::execute( sal_Int16 /*KeyModifier*/ )
286*7ca83afaSAriel Constenla-Haile     throw ( css::uno::RuntimeException )
287*7ca83afaSAriel Constenla-Haile {
288*7ca83afaSAriel Constenla-Haile     osl::MutexGuard aGuard( m_aMutex );
289*7ca83afaSAriel Constenla-Haile     if ( !m_aLastURL.getLength() )
290*7ca83afaSAriel Constenla-Haile         return;
291*7ca83afaSAriel Constenla-Haile 
292*7ca83afaSAriel Constenla-Haile     OUString aTarget( RTL_CONSTASCII_USTRINGPARAM( "_default" ) );
293*7ca83afaSAriel Constenla-Haile     if ( m_xPopupMenu.is() )
294*7ca83afaSAriel Constenla-Haile     {
295*7ca83afaSAriel Constenla-Haile         // TODO investigate how to wrap Get/SetUserValue in css::awt::XMenu
296*7ca83afaSAriel Constenla-Haile         MenuConfiguration::Attributes* pMenuAttributes( 0 );
297*7ca83afaSAriel Constenla-Haile         VCLXPopupMenu*  pTkPopupMenu = dynamic_cast< VCLXPopupMenu * >(
298*7ca83afaSAriel Constenla-Haile             VCLXMenu::GetImplementation( m_xPopupMenu ) );
299*7ca83afaSAriel Constenla-Haile 
300*7ca83afaSAriel Constenla-Haile         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
301*7ca83afaSAriel Constenla-Haile         PopupMenu* pVCLPopupMenu = dynamic_cast< PopupMenu * >( pTkPopupMenu->GetMenu() );
302*7ca83afaSAriel Constenla-Haile         if ( pVCLPopupMenu )
303*7ca83afaSAriel Constenla-Haile             pMenuAttributes = reinterpret_cast< MenuConfiguration::Attributes* >(
304*7ca83afaSAriel Constenla-Haile                 pVCLPopupMenu->GetUserValue( pVCLPopupMenu->GetCurItemId() ) );
305*7ca83afaSAriel Constenla-Haile 
306*7ca83afaSAriel Constenla-Haile         if ( pMenuAttributes )
307*7ca83afaSAriel Constenla-Haile             aTarget = pMenuAttributes->aTargetFrame;
308*7ca83afaSAriel Constenla-Haile     }
309*7ca83afaSAriel Constenla-Haile 
310*7ca83afaSAriel Constenla-Haile     css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
311*7ca83afaSAriel Constenla-Haile     aArgs[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer"  ));
312*7ca83afaSAriel Constenla-Haile     aArgs[0].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER ) );
313*7ca83afaSAriel Constenla-Haile 
314*7ca83afaSAriel Constenla-Haile     dispatchCommand( m_aLastURL, aArgs, aTarget );
315*7ca83afaSAriel Constenla-Haile }
316*7ca83afaSAriel Constenla-Haile 
31710b918a5SAriel Constenla-Haile void NewToolbarController::functionExecuted( const OUString &rCommand )
31810b918a5SAriel Constenla-Haile {
31910b918a5SAriel Constenla-Haile     setItemImage( rCommand );
32010b918a5SAriel Constenla-Haile }
32110b918a5SAriel Constenla-Haile 
32210b918a5SAriel Constenla-Haile /**
32310b918a5SAriel Constenla-Haile     it return the existing state of the given URL in the popupmenu of this toolbox control.
32410b918a5SAriel Constenla-Haile 
32510b918a5SAriel Constenla-Haile     If the given URL can be located as an action command of one menu item of the
32610b918a5SAriel Constenla-Haile     popup menu of this control, we return sal_True. Otherwhise we return sal_False.
32710b918a5SAriel Constenla-Haile     Further we return a fallback URL, in case we have to return sal_False. Because
32810b918a5SAriel Constenla-Haile     the outside code must select a valid item of the popup menu everytime ...
32910b918a5SAriel Constenla-Haile     and we define it here. By the way this m ethod was written to handle
33010b918a5SAriel Constenla-Haile     error situations gracefully. E.g. it can be called during creation time
33110b918a5SAriel Constenla-Haile     but then we have no valid menu. For this case we know another fallback URL.
33210b918a5SAriel Constenla-Haile     Then we return the private:factory/ URL of the default factory.
33310b918a5SAriel Constenla-Haile 
33410b918a5SAriel Constenla-Haile     @param  rPopupMenu
33510b918a5SAriel Constenla-Haile                 pounts to the popup menu, on which item we try to locate the given URL
33610b918a5SAriel Constenla-Haile                 Can be NULL! Search will be supressed then.
33710b918a5SAriel Constenla-Haile 
33810b918a5SAriel Constenla-Haile     @param  sURL
33910b918a5SAriel Constenla-Haile                 the URL for searching
34010b918a5SAriel Constenla-Haile 
34110b918a5SAriel Constenla-Haile     @param  sFallback
34210b918a5SAriel Constenla-Haile                 contains the fallback URL in case we return FALSE
34310b918a5SAriel Constenla-Haile                 Must point to valid memory!
34410b918a5SAriel Constenla-Haile 
34510b918a5SAriel Constenla-Haile     @param  aImage
34610b918a5SAriel Constenla-Haile                 contains the image of the menu for the URL.
34710b918a5SAriel Constenla-Haile 
34810b918a5SAriel Constenla-Haile     @return sal_True - if URL could be located as an item of the popup menu.
34910b918a5SAriel Constenla-Haile             sal_False - otherwhise.
35010b918a5SAriel Constenla-Haile */
35110b918a5SAriel Constenla-Haile static sal_Bool Impl_ExistURLInMenu(
35210b918a5SAriel Constenla-Haile     const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu,
35310b918a5SAriel Constenla-Haile     OUString &sURL,
35410b918a5SAriel Constenla-Haile     OUString &sFallback,
35510b918a5SAriel Constenla-Haile     Image &aImage )
35610b918a5SAriel Constenla-Haile {
35710b918a5SAriel Constenla-Haile     sal_Bool bValidFallback( sal_False );
35810b918a5SAriel Constenla-Haile     sal_uInt16 nCount( 0 );
359dc055bd2SAriel Constenla-Haile     if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) != 0 && sURL.getLength() )
36010b918a5SAriel Constenla-Haile     {
36110b918a5SAriel Constenla-Haile         for ( sal_uInt16 n = 0; n < nCount; ++n )
36210b918a5SAriel Constenla-Haile         {
36310b918a5SAriel Constenla-Haile             sal_uInt16 nId = rPopupMenu->getItemId( n );
36410b918a5SAriel Constenla-Haile             OUString aCmd( rPopupMenu->getCommand( nId ) );
36510b918a5SAriel Constenla-Haile 
36610b918a5SAriel Constenla-Haile             if ( !bValidFallback && aCmd.getLength() )
36710b918a5SAriel Constenla-Haile             {
36810b918a5SAriel Constenla-Haile                 sFallback = aCmd;
36910b918a5SAriel Constenla-Haile                 bValidFallback = sal_True;
37010b918a5SAriel Constenla-Haile             }
37110b918a5SAriel Constenla-Haile 
37210b918a5SAriel Constenla-Haile             // match even if the menu command is more detailed
37310b918a5SAriel Constenla-Haile             // (maybe an additional query) #i28667#
37410b918a5SAriel Constenla-Haile             if ( aCmd.match( sURL ) )
37510b918a5SAriel Constenla-Haile             {
37610b918a5SAriel Constenla-Haile                 sURL = aCmd;
37710b918a5SAriel Constenla-Haile                 const css::uno::Reference< css::graphic::XGraphic > xGraphic(
37810b918a5SAriel Constenla-Haile                     rPopupMenu->getItemImage( nId ) );
37910b918a5SAriel Constenla-Haile                 if ( xGraphic.is() )
38010b918a5SAriel Constenla-Haile                     aImage = Image( xGraphic );
38110b918a5SAriel Constenla-Haile                 return sal_True;
38210b918a5SAriel Constenla-Haile             }
38310b918a5SAriel Constenla-Haile         }
38410b918a5SAriel Constenla-Haile     }
38510b918a5SAriel Constenla-Haile 
38610b918a5SAriel Constenla-Haile     if ( !bValidFallback )
38710b918a5SAriel Constenla-Haile     {
38810b918a5SAriel Constenla-Haile         rtl::OUStringBuffer aBuffer;
38910b918a5SAriel Constenla-Haile         aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) );
39010b918a5SAriel Constenla-Haile         aBuffer.append( SvtModuleOptions().GetDefaultModuleName() );
39110b918a5SAriel Constenla-Haile         sFallback = aBuffer.makeStringAndClear();
39210b918a5SAriel Constenla-Haile     }
39310b918a5SAriel Constenla-Haile 
39410b918a5SAriel Constenla-Haile     return sal_False;
39510b918a5SAriel Constenla-Haile }
39610b918a5SAriel Constenla-Haile 
39710b918a5SAriel Constenla-Haile /** We accept URL's here only, which exist as items of our internal popup menu.
39810b918a5SAriel Constenla-Haile     All other ones will be ignored and a fallback is used.
39910b918a5SAriel Constenla-Haile  */
40010b918a5SAriel Constenla-Haile void NewToolbarController::setItemImage( const OUString &rCommand )
40110b918a5SAriel Constenla-Haile {
40210b918a5SAriel Constenla-Haile     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
40310b918a5SAriel Constenla-Haile     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
40410b918a5SAriel Constenla-Haile     if ( !pToolBox )
40510b918a5SAriel Constenla-Haile         return;
40610b918a5SAriel Constenla-Haile 
40710b918a5SAriel Constenla-Haile     OUString aURL = rCommand;
40810b918a5SAriel Constenla-Haile     OUString sFallback;
40910b918a5SAriel Constenla-Haile     Image aMenuImage;
41010b918a5SAriel Constenla-Haile 
41110b918a5SAriel Constenla-Haile     sal_Bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) );
41210b918a5SAriel Constenla-Haile     // do not change aURL if Impl_ExistURLInMenu returned sal_False
41310b918a5SAriel Constenla-Haile     // this allows later initialization of the PopupMenuController on createPopupWindow()
41410b918a5SAriel Constenla-Haile     // and works even if SvFileInformationManager does not know the module
41510b918a5SAriel Constenla-Haile     if ( !aURL.getLength() )
41610b918a5SAriel Constenla-Haile         aURL = sFallback;
41710b918a5SAriel Constenla-Haile 
41810b918a5SAriel Constenla-Haile     sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
41910b918a5SAriel Constenla-Haile     sal_Bool bHC = pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode();
42010b918a5SAriel Constenla-Haile 
42110b918a5SAriel Constenla-Haile     INetURLObject aURLObj( aURL );
42210b918a5SAriel Constenla-Haile     Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig, bHC );
42310b918a5SAriel Constenla-Haile     if ( !aImage )
42410b918a5SAriel Constenla-Haile     {
42510b918a5SAriel Constenla-Haile         if ( !!aMenuImage )
42610b918a5SAriel Constenla-Haile             aImage =  aMenuImage;
42710b918a5SAriel Constenla-Haile         else if ( !bValid )
42810b918a5SAriel Constenla-Haile             // If SvFileInformationManager didn't know the module, try with the default
42910b918a5SAriel Constenla-Haile             aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( sFallback ), bBig, bHC );
43010b918a5SAriel Constenla-Haile 
43110b918a5SAriel Constenla-Haile         if ( !aImage )
43210b918a5SAriel Constenla-Haile             aImage = SvFileInformationManager::GetImage( aURLObj, bBig, bHC );
43310b918a5SAriel Constenla-Haile     }
43410b918a5SAriel Constenla-Haile 
43510b918a5SAriel Constenla-Haile     // if everything failed, just use the image associated with the toolbar item command
43610b918a5SAriel Constenla-Haile     if ( !aImage )
43710b918a5SAriel Constenla-Haile         return;
43810b918a5SAriel Constenla-Haile 
43910b918a5SAriel Constenla-Haile     Size aBigSize( pToolBox->GetDefaultImageSize() );
44010b918a5SAriel Constenla-Haile     if ( bBig && aImage.GetSizePixel() != aBigSize )
44110b918a5SAriel Constenla-Haile     {
44210b918a5SAriel Constenla-Haile         BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
44310b918a5SAriel Constenla-Haile         aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
44410b918a5SAriel Constenla-Haile         pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
44510b918a5SAriel Constenla-Haile     }
44610b918a5SAriel Constenla-Haile     else
44710b918a5SAriel Constenla-Haile         pToolBox->SetItemImage( m_nToolBoxId, aImage );
448*7ca83afaSAriel Constenla-Haile 
449*7ca83afaSAriel Constenla-Haile     m_aLastURL = aURL;
45010b918a5SAriel Constenla-Haile }
45110b918a5SAriel Constenla-Haile 
45210b918a5SAriel Constenla-Haile 
45310b918a5SAriel Constenla-Haile }
454