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 
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 );
1595bd54fd8SAriel Constenla-Haile     WindowAlign eAlign( pToolBox->GetAlign() );
16010b918a5SAriel Constenla-Haile     sal_uInt16 nId = m_xPopupMenu->execute(
16110b918a5SAriel Constenla-Haile         css::uno::Reference< css::awt::XWindowPeer >( getParent(), css::uno::UNO_QUERY ),
16210b918a5SAriel Constenla-Haile         VCLUnoHelper::ConvertToAWTRect( pToolBox->GetItemRect( m_nToolBoxId ) ),
1635bd54fd8SAriel Constenla-Haile         ( eAlign == WINDOWALIGN_TOP || eAlign == WINDOWALIGN_BOTTOM ) ?
1645bd54fd8SAriel Constenla-Haile             css::awt::PopupMenuDirection::EXECUTE_DOWN :
1655bd54fd8SAriel Constenla-Haile             css::awt::PopupMenuDirection::EXECUTE_RIGHT );
16610b918a5SAriel Constenla-Haile     pToolBox->SetItemDown( m_nToolBoxId, sal_False );
16710b918a5SAriel Constenla-Haile 
16810b918a5SAriel Constenla-Haile     if ( nId )
16910b918a5SAriel Constenla-Haile         functionExecuted( m_xPopupMenu->getCommand( nId ) );
17010b918a5SAriel Constenla-Haile 
17110b918a5SAriel Constenla-Haile     return xRet;
17210b918a5SAriel Constenla-Haile }
17310b918a5SAriel Constenla-Haile 
17410b918a5SAriel Constenla-Haile void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/)
17510b918a5SAriel Constenla-Haile {
17610b918a5SAriel Constenla-Haile }
17710b918a5SAriel Constenla-Haile 
17810b918a5SAriel Constenla-Haile sal_uInt16 PopupMenuToolbarController::getDropDownStyle() const
17910b918a5SAriel Constenla-Haile {
18010b918a5SAriel Constenla-Haile     return TIB_DROPDOWN;
18110b918a5SAriel Constenla-Haile }
18210b918a5SAriel Constenla-Haile 
18310b918a5SAriel Constenla-Haile void PopupMenuToolbarController::createPopupMenuController()
18410b918a5SAriel Constenla-Haile {
18510b918a5SAriel Constenla-Haile     if( !m_bHasController )
18610b918a5SAriel Constenla-Haile         return;
18710b918a5SAriel Constenla-Haile 
18810b918a5SAriel Constenla-Haile     if ( !m_xPopupMenuController.is() )
18910b918a5SAriel Constenla-Haile     {
19010b918a5SAriel Constenla-Haile         css::uno::Sequence< css::uno::Any > aArgs( 2 );
19110b918a5SAriel Constenla-Haile         css::beans::PropertyValue aProp;
19210b918a5SAriel Constenla-Haile 
19310b918a5SAriel Constenla-Haile         aProp.Name = DECLARE_ASCII( "Frame" );
19410b918a5SAriel Constenla-Haile         aProp.Value <<= m_xFrame;
19510b918a5SAriel Constenla-Haile         aArgs[0] <<= aProp;
19610b918a5SAriel Constenla-Haile 
19710b918a5SAriel Constenla-Haile         aProp.Name = DECLARE_ASCII( "ModuleIdentifier" );
19810b918a5SAriel Constenla-Haile         aProp.Value <<= getModuleName();
19910b918a5SAriel Constenla-Haile         aArgs[1] <<= aProp;
20010b918a5SAriel Constenla-Haile         try
20110b918a5SAriel Constenla-Haile         {
20210b918a5SAriel Constenla-Haile             m_xPopupMenu.set(
20310b918a5SAriel Constenla-Haile                 m_xContext->getServiceManager()->createInstanceWithContext(
20410b918a5SAriel Constenla-Haile                     DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), m_xContext ),
20510b918a5SAriel Constenla-Haile                         css::uno::UNO_QUERY_THROW );
20610b918a5SAriel Constenla-Haile             m_xPopupMenuController.set(
20710b918a5SAriel Constenla-Haile                 m_xPopupMenuFactory->createInstanceWithArgumentsAndContext(
20810b918a5SAriel Constenla-Haile                     m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW );
20910b918a5SAriel Constenla-Haile 
21010b918a5SAriel Constenla-Haile             m_xPopupMenuController->setPopupMenu( m_xPopupMenu );
21110b918a5SAriel Constenla-Haile         }
21210b918a5SAriel Constenla-Haile         catch ( const css::uno::Exception &e )
21310b918a5SAriel Constenla-Haile         {
21410b918a5SAriel Constenla-Haile             m_xPopupMenu.clear();
21510b918a5SAriel Constenla-Haile             OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s",
21610b918a5SAriel Constenla-Haile                        rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
21710b918a5SAriel Constenla-Haile             (void) e;
21810b918a5SAriel Constenla-Haile         }
21910b918a5SAriel Constenla-Haile     }
22010b918a5SAriel Constenla-Haile }
22110b918a5SAriel Constenla-Haile 
22210b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( WizardsToolbarController,
22310b918a5SAriel Constenla-Haile                                     ::cppu::OWeakObject,
22410b918a5SAriel Constenla-Haile                                     DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
22510b918a5SAriel Constenla-Haile                                     DECLARE_ASCII("org.apache.openoffice.comp.framework.WizardsToolbarController")
22610b918a5SAriel Constenla-Haile                                    )
22710b918a5SAriel Constenla-Haile 
22810b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( WizardsToolbarController, {} )
22910b918a5SAriel Constenla-Haile 
23010b918a5SAriel Constenla-Haile WizardsToolbarController::WizardsToolbarController(
23110b918a5SAriel Constenla-Haile     const css::uno::Reference< css::uno::XComponentContext >& xContext )
23210b918a5SAriel Constenla-Haile     : PopupMenuToolbarController( xContext )
23310b918a5SAriel Constenla-Haile {
23410b918a5SAriel Constenla-Haile }
23510b918a5SAriel Constenla-Haile 
23610b918a5SAriel Constenla-Haile sal_uInt16 WizardsToolbarController::getDropDownStyle() const
23710b918a5SAriel Constenla-Haile {
23810b918a5SAriel Constenla-Haile     return TIB_DROPDOWNONLY;
23910b918a5SAriel Constenla-Haile }
24010b918a5SAriel Constenla-Haile 
24110b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( OpenToolbarController,
24210b918a5SAriel Constenla-Haile                                     ::cppu::OWeakObject,
24310b918a5SAriel Constenla-Haile                                     DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
24410b918a5SAriel Constenla-Haile                                     DECLARE_ASCII("org.apache.openoffice.comp.framework.OpenToolbarController")
24510b918a5SAriel Constenla-Haile                                    )
24610b918a5SAriel Constenla-Haile 
24710b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( OpenToolbarController, {} )
24810b918a5SAriel Constenla-Haile 
24910b918a5SAriel Constenla-Haile OpenToolbarController::OpenToolbarController(
25010b918a5SAriel Constenla-Haile     const css::uno::Reference< css::uno::XComponentContext >& xContext )
25110b918a5SAriel Constenla-Haile     : PopupMenuToolbarController( xContext, DECLARE_ASCII( UNO_COMMAND_RECENT_FILE_LIST ) )
25210b918a5SAriel Constenla-Haile {
25310b918a5SAriel Constenla-Haile }
25410b918a5SAriel Constenla-Haile 
25510b918a5SAriel Constenla-Haile 
25610b918a5SAriel Constenla-Haile DEFINE_XSERVICEINFO_MULTISERVICE_2( NewToolbarController,
25710b918a5SAriel Constenla-Haile                                     ::cppu::OWeakObject,
25810b918a5SAriel Constenla-Haile                                     DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
25910b918a5SAriel Constenla-Haile                                     DECLARE_ASCII("org.apache.openoffice.comp.framework.NewToolbarController")
26010b918a5SAriel Constenla-Haile                                    )
26110b918a5SAriel Constenla-Haile 
26210b918a5SAriel Constenla-Haile DEFINE_INIT_SERVICE( NewToolbarController, {} )
26310b918a5SAriel Constenla-Haile 
26410b918a5SAriel Constenla-Haile NewToolbarController::NewToolbarController(
26510b918a5SAriel Constenla-Haile     const css::uno::Reference< css::uno::XComponentContext >& xContext )
26610b918a5SAriel Constenla-Haile     : PopupMenuToolbarController( xContext )
26710b918a5SAriel Constenla-Haile {
26810b918a5SAriel Constenla-Haile }
26910b918a5SAriel Constenla-Haile 
27089d8a215SAriel Constenla-Haile void SAL_CALL
27189d8a215SAriel Constenla-Haile NewToolbarController::initialize(
27289d8a215SAriel Constenla-Haile     const css::uno::Sequence< css::uno::Any >& aArguments )
27389d8a215SAriel Constenla-Haile throw ( css::uno::Exception, css::uno::RuntimeException )
27489d8a215SAriel Constenla-Haile {
27589d8a215SAriel Constenla-Haile     PopupMenuToolbarController::initialize( aArguments );
27689d8a215SAriel Constenla-Haile 
27789d8a215SAriel Constenla-Haile     osl::MutexGuard aGuard( m_aMutex );
27889d8a215SAriel Constenla-Haile     createPopupMenuController();
27989d8a215SAriel Constenla-Haile }
28089d8a215SAriel Constenla-Haile 
28110b918a5SAriel Constenla-Haile void SAL_CALL
28210b918a5SAriel Constenla-Haile NewToolbarController::statusChanged(
28310b918a5SAriel Constenla-Haile     const css::frame::FeatureStateEvent& rEvent )
28410b918a5SAriel Constenla-Haile     throw ( css::uno::RuntimeException )
28510b918a5SAriel Constenla-Haile {
28610b918a5SAriel Constenla-Haile     if ( rEvent.IsEnabled )
28710b918a5SAriel Constenla-Haile     {
28810b918a5SAriel Constenla-Haile         OUString aState;
28910b918a5SAriel Constenla-Haile         rEvent.State >>= aState;
29010b918a5SAriel Constenla-Haile         // set the image even if the state is not a string
29110b918a5SAriel Constenla-Haile         // this will set the image of the default module
29210b918a5SAriel Constenla-Haile         setItemImage( aState );
29310b918a5SAriel Constenla-Haile     }
29410b918a5SAriel Constenla-Haile 
29510b918a5SAriel Constenla-Haile     enable( rEvent.IsEnabled );
29610b918a5SAriel Constenla-Haile }
29710b918a5SAriel Constenla-Haile 
2987ca83afaSAriel Constenla-Haile void SAL_CALL
2997ca83afaSAriel Constenla-Haile NewToolbarController::execute( sal_Int16 /*KeyModifier*/ )
3007ca83afaSAriel Constenla-Haile     throw ( css::uno::RuntimeException )
3017ca83afaSAriel Constenla-Haile {
3027ca83afaSAriel Constenla-Haile     osl::MutexGuard aGuard( m_aMutex );
3037ca83afaSAriel Constenla-Haile     if ( !m_aLastURL.getLength() )
3047ca83afaSAriel Constenla-Haile         return;
3057ca83afaSAriel Constenla-Haile 
3067ca83afaSAriel Constenla-Haile     OUString aTarget( RTL_CONSTASCII_USTRINGPARAM( "_default" ) );
3077ca83afaSAriel Constenla-Haile     if ( m_xPopupMenu.is() )
3087ca83afaSAriel Constenla-Haile     {
3097ca83afaSAriel Constenla-Haile         // TODO investigate how to wrap Get/SetUserValue in css::awt::XMenu
3107ca83afaSAriel Constenla-Haile         MenuConfiguration::Attributes* pMenuAttributes( 0 );
3119b1ae0e5SAriel Constenla-Haile         VCLXPopupMenu*  pTkPopupMenu =
3129b1ae0e5SAriel Constenla-Haile             ( VCLXPopupMenu * ) VCLXMenu::GetImplementation( m_xPopupMenu );
3137ca83afaSAriel Constenla-Haile 
3147ca83afaSAriel Constenla-Haile         vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
3157ca83afaSAriel Constenla-Haile         PopupMenu* pVCLPopupMenu = dynamic_cast< PopupMenu * >( pTkPopupMenu->GetMenu() );
3167ca83afaSAriel Constenla-Haile         if ( pVCLPopupMenu )
3177ca83afaSAriel Constenla-Haile             pMenuAttributes = reinterpret_cast< MenuConfiguration::Attributes* >(
3187ca83afaSAriel Constenla-Haile                 pVCLPopupMenu->GetUserValue( pVCLPopupMenu->GetCurItemId() ) );
3197ca83afaSAriel Constenla-Haile 
3207ca83afaSAriel Constenla-Haile         if ( pMenuAttributes )
3217ca83afaSAriel Constenla-Haile             aTarget = pMenuAttributes->aTargetFrame;
3227ca83afaSAriel Constenla-Haile     }
3237ca83afaSAriel Constenla-Haile 
3247ca83afaSAriel Constenla-Haile     css::uno::Sequence< css::beans::PropertyValue > aArgs( 1 );
3257ca83afaSAriel Constenla-Haile     aArgs[0].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "Referer"  ));
3267ca83afaSAriel Constenla-Haile     aArgs[0].Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( SFX_REFERER_USER ) );
3277ca83afaSAriel Constenla-Haile 
3287ca83afaSAriel Constenla-Haile     dispatchCommand( m_aLastURL, aArgs, aTarget );
3297ca83afaSAriel Constenla-Haile }
3307ca83afaSAriel Constenla-Haile 
33110b918a5SAriel Constenla-Haile void NewToolbarController::functionExecuted( const OUString &rCommand )
33210b918a5SAriel Constenla-Haile {
33310b918a5SAriel Constenla-Haile     setItemImage( rCommand );
33410b918a5SAriel Constenla-Haile }
33510b918a5SAriel Constenla-Haile 
33610b918a5SAriel Constenla-Haile /**
33710b918a5SAriel Constenla-Haile     it return the existing state of the given URL in the popupmenu of this toolbox control.
33810b918a5SAriel Constenla-Haile 
33910b918a5SAriel Constenla-Haile     If the given URL can be located as an action command of one menu item of the
340*4e7d57d8Smseidel     popup menu of this control, we return sal_True. Otherwise we return sal_False.
34110b918a5SAriel Constenla-Haile     Further we return a fallback URL, in case we have to return sal_False. Because
34207a3d7f1SPedro Giffuni     the outside code must select a valid item of the popup menu every time ...
343*4e7d57d8Smseidel     and we define it here. By the way this method was written to handle
34410b918a5SAriel Constenla-Haile     error situations gracefully. E.g. it can be called during creation time
34510b918a5SAriel Constenla-Haile     but then we have no valid menu. For this case we know another fallback URL.
34610b918a5SAriel Constenla-Haile     Then we return the private:factory/ URL of the default factory.
34710b918a5SAriel Constenla-Haile 
34810b918a5SAriel Constenla-Haile     @param  rPopupMenu
34910b918a5SAriel Constenla-Haile                 pounts to the popup menu, on which item we try to locate the given URL
35007a3d7f1SPedro Giffuni                 Can be NULL! Search will be suppressed then.
35110b918a5SAriel Constenla-Haile 
35210b918a5SAriel Constenla-Haile     @param  sURL
35310b918a5SAriel Constenla-Haile                 the URL for searching
35410b918a5SAriel Constenla-Haile 
35510b918a5SAriel Constenla-Haile     @param  sFallback
35610b918a5SAriel Constenla-Haile                 contains the fallback URL in case we return FALSE
35710b918a5SAriel Constenla-Haile                 Must point to valid memory!
35810b918a5SAriel Constenla-Haile 
35910b918a5SAriel Constenla-Haile     @param  aImage
36010b918a5SAriel Constenla-Haile                 contains the image of the menu for the URL.
36110b918a5SAriel Constenla-Haile 
36210b918a5SAriel Constenla-Haile     @return sal_True - if URL could be located as an item of the popup menu.
363*4e7d57d8Smseidel             sal_False - otherwise.
36410b918a5SAriel Constenla-Haile */
36510b918a5SAriel Constenla-Haile static sal_Bool Impl_ExistURLInMenu(
36610b918a5SAriel Constenla-Haile     const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu,
36710b918a5SAriel Constenla-Haile     OUString &sURL,
36810b918a5SAriel Constenla-Haile     OUString &sFallback,
36910b918a5SAriel Constenla-Haile     Image &aImage )
37010b918a5SAriel Constenla-Haile {
37110b918a5SAriel Constenla-Haile     sal_Bool bValidFallback( sal_False );
37210b918a5SAriel Constenla-Haile     sal_uInt16 nCount( 0 );
373dc055bd2SAriel Constenla-Haile     if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) != 0 && sURL.getLength() )
37410b918a5SAriel Constenla-Haile     {
37510b918a5SAriel Constenla-Haile         for ( sal_uInt16 n = 0; n < nCount; ++n )
37610b918a5SAriel Constenla-Haile         {
37710b918a5SAriel Constenla-Haile             sal_uInt16 nId = rPopupMenu->getItemId( n );
37810b918a5SAriel Constenla-Haile             OUString aCmd( rPopupMenu->getCommand( nId ) );
37910b918a5SAriel Constenla-Haile 
38010b918a5SAriel Constenla-Haile             if ( !bValidFallback && aCmd.getLength() )
38110b918a5SAriel Constenla-Haile             {
38210b918a5SAriel Constenla-Haile                 sFallback = aCmd;
38310b918a5SAriel Constenla-Haile                 bValidFallback = sal_True;
38410b918a5SAriel Constenla-Haile             }
38510b918a5SAriel Constenla-Haile 
38610b918a5SAriel Constenla-Haile             // match even if the menu command is more detailed
38710b918a5SAriel Constenla-Haile             // (maybe an additional query) #i28667#
38810b918a5SAriel Constenla-Haile             if ( aCmd.match( sURL ) )
38910b918a5SAriel Constenla-Haile             {
39010b918a5SAriel Constenla-Haile                 sURL = aCmd;
39110b918a5SAriel Constenla-Haile                 const css::uno::Reference< css::graphic::XGraphic > xGraphic(
39210b918a5SAriel Constenla-Haile                     rPopupMenu->getItemImage( nId ) );
39310b918a5SAriel Constenla-Haile                 if ( xGraphic.is() )
39410b918a5SAriel Constenla-Haile                     aImage = Image( xGraphic );
39510b918a5SAriel Constenla-Haile                 return sal_True;
39610b918a5SAriel Constenla-Haile             }
39710b918a5SAriel Constenla-Haile         }
39810b918a5SAriel Constenla-Haile     }
39910b918a5SAriel Constenla-Haile 
40010b918a5SAriel Constenla-Haile     if ( !bValidFallback )
40110b918a5SAriel Constenla-Haile     {
40210b918a5SAriel Constenla-Haile         rtl::OUStringBuffer aBuffer;
40310b918a5SAriel Constenla-Haile         aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) );
40410b918a5SAriel Constenla-Haile         aBuffer.append( SvtModuleOptions().GetDefaultModuleName() );
40510b918a5SAriel Constenla-Haile         sFallback = aBuffer.makeStringAndClear();
40610b918a5SAriel Constenla-Haile     }
40710b918a5SAriel Constenla-Haile 
40810b918a5SAriel Constenla-Haile     return sal_False;
40910b918a5SAriel Constenla-Haile }
41010b918a5SAriel Constenla-Haile 
41110b918a5SAriel Constenla-Haile /** We accept URL's here only, which exist as items of our internal popup menu.
41210b918a5SAriel Constenla-Haile     All other ones will be ignored and a fallback is used.
41310b918a5SAriel Constenla-Haile  */
41410b918a5SAriel Constenla-Haile void NewToolbarController::setItemImage( const OUString &rCommand )
41510b918a5SAriel Constenla-Haile {
41610b918a5SAriel Constenla-Haile     vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
41710b918a5SAriel Constenla-Haile     ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
41810b918a5SAriel Constenla-Haile     if ( !pToolBox )
41910b918a5SAriel Constenla-Haile         return;
42010b918a5SAriel Constenla-Haile 
42110b918a5SAriel Constenla-Haile     OUString aURL = rCommand;
42210b918a5SAriel Constenla-Haile     OUString sFallback;
42310b918a5SAriel Constenla-Haile     Image aMenuImage;
42410b918a5SAriel Constenla-Haile 
42510b918a5SAriel Constenla-Haile     sal_Bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) );
42689d8a215SAriel Constenla-Haile     if ( !bValid )
42710b918a5SAriel Constenla-Haile         aURL = sFallback;
42810b918a5SAriel Constenla-Haile 
42910b918a5SAriel Constenla-Haile     sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
43010b918a5SAriel Constenla-Haile     sal_Bool bHC = pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode();
43110b918a5SAriel Constenla-Haile 
43210b918a5SAriel Constenla-Haile     INetURLObject aURLObj( aURL );
43310b918a5SAriel Constenla-Haile     Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig, bHC );
43410b918a5SAriel Constenla-Haile     if ( !aImage )
43589d8a215SAriel Constenla-Haile         aImage = !!aMenuImage ?
43689d8a215SAriel Constenla-Haile             aMenuImage :
43789d8a215SAriel Constenla-Haile             SvFileInformationManager::GetImage( aURLObj, bBig, bHC );
43810b918a5SAriel Constenla-Haile 
43910b918a5SAriel Constenla-Haile     // if everything failed, just use the image associated with the toolbar item command
44010b918a5SAriel Constenla-Haile     if ( !aImage )
44110b918a5SAriel Constenla-Haile         return;
44210b918a5SAriel Constenla-Haile 
44310b918a5SAriel Constenla-Haile     Size aBigSize( pToolBox->GetDefaultImageSize() );
44410b918a5SAriel Constenla-Haile     if ( bBig && aImage.GetSizePixel() != aBigSize )
44510b918a5SAriel Constenla-Haile     {
44610b918a5SAriel Constenla-Haile         BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
44710b918a5SAriel Constenla-Haile         aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
44810b918a5SAriel Constenla-Haile         pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
44910b918a5SAriel Constenla-Haile     }
45010b918a5SAriel Constenla-Haile     else
45110b918a5SAriel Constenla-Haile         pToolBox->SetItemImage( m_nToolBoxId, aImage );
4527ca83afaSAriel Constenla-Haile 
4537ca83afaSAriel Constenla-Haile     m_aLastURL = aURL;
45410b918a5SAriel Constenla-Haile }
45510b918a5SAriel Constenla-Haile 
45610b918a5SAriel Constenla-Haile 
45710b918a5SAriel Constenla-Haile }
458