framework::PopupMenuController clean-up

Changed the name, it is not a PopupMenuController, but a ToolbarController that shows a PopupMenu filled at runtime by a PopupMenuController

Make it a base class for other ToolbarController components, there is no sense to make it a component by itself

Use this base class for three new pure UNO ToolbarController's

Notes:

merged as: a659ac906aa2d0dfd6d10e40d8a5a6d2d70cc8fc
diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk
index db55c57..d541867 100644
--- a/framework/Library_fwk.mk
+++ b/framework/Library_fwk.mk
@@ -112,11 +112,11 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
    framework/source/loadenv/loadenv \
    framework/source/loadenv/targethelper \
    framework/source/register/registerservices \
    framework/source/services/ContextChangeEventMultiplexer \
    framework/source/services/autorecovery \
    framework/source/services/backingcomp \
    framework/source/services/backingwindow \
    framework/source/services/desktop \
    framework/source/services/ContextChangeEventMultiplexer \
    framework/source/services/frame \
    framework/source/services/modelwinservice \
    framework/source/services/modulemanager \
@@ -154,6 +154,7 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
    framework/source/uielement/menubarmerger \
    framework/source/uielement/menubarwrapper \
    framework/source/uielement/objectmenucontroller \
    framework/source/uielement/popuptoolbarcontroller \
    framework/source/uielement/panelwindow \
    framework/source/uielement/panelwrapper \
    framework/source/uielement/progressbarwrapper \
@@ -175,8 +176,8 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
    framework/source/uifactory/factoryconfiguration \
    framework/source/uifactory/menubarfactory \
    framework/source/uifactory/statusbarfactory \
    framework/source/uifactory/uicontrollerfactory \
    framework/source/uifactory/toolboxfactory \
    framework/source/uifactory/uicontrollerfactory \
    framework/source/uifactory/uielementfactorymanager \
    framework/source/uifactory/windowcontentfactorymanager \
    framework/source/xml/acceleratorconfigurationreader \
diff --git a/framework/Library_fwl.mk b/framework/Library_fwl.mk
index 04aa707..3347c7c 100644
--- a/framework/Library_fwl.mk
+++ b/framework/Library_fwl.mk
@@ -73,7 +73,6 @@ $(eval $(call gb_Library_add_exception_objects,fwl,\
    framework/source/uielement/langselectionmenucontroller \
    framework/source/uielement/macrosmenucontroller \
    framework/source/uielement/newmenucontroller \
    framework/source/uielement/popupmenucontroller \
    framework/source/uielement/toolbarsmenucontroller \
))

diff --git a/framework/inc/uielement/popupmenucontroller.hxx b/framework/inc/uielement/popupmenucontroller.hxx
deleted file mode 100644
index e00ff9c..0000000
--- a/framework/inc/uielement/popupmenucontroller.hxx
+++ /dev/null
@@ -1,76 +0,0 @@
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 *************************************************************/



#ifndef __FRAMEWORK_POPUPMENUCONTROLLER_HXX_
#define __FRAMEWORK_POPUPMENUCONTROLLER_HXX_

#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/frame/XPopupMenuController.hpp>

#include "svtools/toolboxcontroller.hxx"
#include "boost/scoped_ptr.hpp"

#include <macros/xserviceinfo.hxx>

class Window;

namespace framework
{
class PopupMenuControllerImpl;

class PopupMenuController : public svt::ToolboxController, public ::com::sun::star::lang::XServiceInfo
{
public:
    PopupMenuController( const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rServiceManager );
    ~PopupMenuController();

    // XInterface
    virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL acquire() throw ();
    virtual void SAL_CALL release() throw ();

    // XServiceInfo
    DECLARE_XSERVICEINFO

    // XComponent
    virtual void SAL_CALL dispose() throw (::com::sun::star::uno::RuntimeException);

    // XStatusListener
    virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );

    // XToolbarController
    virtual void SAL_CALL execute( sal_Int16 KeyModifier ) throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL click() throw (::com::sun::star::uno::RuntimeException);
    virtual void SAL_CALL doubleClick() throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() throw (::com::sun::star::uno::RuntimeException);
    virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createItemWindow( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >& Parent ) throw (::com::sun::star::uno::RuntimeException);

    bool CreatePopupMenuController() throw (::com::sun::star::uno::Exception);

    ::com::sun::star::uno::Reference< ::com::sun::star::frame::XPopupMenuController > mxPopupMenuController;
    ::com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu > mxPopupMenu;
};

} // namespace framework

#endif // __FRAMEWORK_POPUPMENUCONTROLLER_HXX_
diff --git a/framework/inc/uielement/popuptoolbarcontroller.hxx b/framework/inc/uielement/popuptoolbarcontroller.hxx
new file mode 100644
index 0000000..f42adbd
--- /dev/null
+++ b/framework/inc/uielement/popuptoolbarcontroller.hxx
@@ -0,0 +1,100 @@
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 *************************************************************/

#ifndef __FRAMEWORK_UIELEMENT_POPUPMENU_TOOLBARCONTROLLER_HXX__
#define __FRAMEWORK_UIELEMENT_POPUPMENU_TOOLBARCONTROLLER_HXX__

#include <com/sun/star/awt/XPopupMenu.hpp>
#include <com/sun/star/frame/XPopupMenuController.hpp>
#include <com/sun/star/frame/XUIControllerFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <cppuhelper/implbase1.hxx>
#include <macros/xserviceinfo.hxx>
#include <svtools/toolboxcontroller.hxx>

namespace framework
{
    class PopupMenuToolbarController : public svt::ToolboxController
    {
    public:
        virtual ~PopupMenuToolbarController();

        // XComponent
        virtual void SAL_CALL dispose() throw ( ::com::sun::star::uno::RuntimeException );
        // XInitialization
        virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
        // XToolbarController
        virtual ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow > SAL_CALL createPopupWindow() throw (::com::sun::star::uno::RuntimeException);
        // XStatusListener
        virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent ) throw ( ::com::sun::star::uno::RuntimeException );

    protected:
        PopupMenuToolbarController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
                                    const ::rtl::OUString &rPopupCommand = rtl::OUString() );
        virtual void functionExecuted( const rtl::OUString &rCommand );
        virtual sal_uInt16 getDropDownStyle() const;
        void createPopupMenuController();

        com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >      m_xContext;
        sal_Bool                                                                      m_bHasController;
        com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >             m_xPopupMenu;

    private:
        rtl::OUString                                                                 m_aPopupCommand;
        com::sun::star::uno::Reference< com::sun::star::frame::XUIControllerFactory > m_xPopupMenuFactory;
        com::sun::star::uno::Reference< com::sun::star::frame::XPopupMenuController > m_xPopupMenuController;
    };

    class OpenToolbarController : public PopupMenuToolbarController
    {
    public:
        OpenToolbarController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );

        // XServiceInfo
        DECLARE_XSERVICEINFO
    };

    class NewToolbarController : public PopupMenuToolbarController
    {
    public:
        NewToolbarController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );

        // XServiceInfo
        DECLARE_XSERVICEINFO
    private:
        void functionExecuted( const rtl::OUString &rCommand );
        void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& rEvent ) throw ( ::com::sun::star::uno::RuntimeException );
        void setItemImage( const rtl::OUString &rCommand );
    };

    class WizardsToolbarController : public PopupMenuToolbarController
    {
    public:
        WizardsToolbarController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext );

        // XServiceInfo
        DECLARE_XSERVICEINFO
    private:
        sal_uInt16 getDropDownStyle() const;
    };
}

#endif
diff --git a/framework/source/register/registerservices.cxx b/framework/source/register/registerservices.cxx
index f7ef107..725a80f 100644
--- a/framework/source/register/registerservices.cxx
+++ b/framework/source/register/registerservices.cxx
@@ -85,6 +85,7 @@
#include <services/substitutepathvars.hxx>
#include <services/pathsettings.hxx>
#include <services/ContextChangeEventMultiplexer.hxx>
#include <uielement/popuptoolbarcontroller.hxx>

COMPONENTGETIMPLEMENTATIONENVIRONMENT

@@ -127,6 +128,9 @@ COMPONENTGETFACTORY (   IFFACTORY( ::framework::URLTransformer                  
                        IFFACTORY( ::framework::TabWindowService                        )   else
                        IFFACTORY( ::framework::SubstitutePathVariables                 )   else
                        IFFACTORY( ::framework::PathSettings                            )   else
                        IFFACTORY( ::framework::ContextChangeEventMultiplexer           )
                        IFFACTORY( ::framework::ContextChangeEventMultiplexer           )   else
                        IFFACTORY( ::framework::OpenToolbarController                   )   else
                        IFFACTORY( ::framework::NewToolbarController                    )   else
                        IFFACTORY( ::framework::WizardsToolbarController                )
            )

diff --git a/framework/source/register/registertemp.cxx b/framework/source/register/registertemp.cxx
index 7221950..6429624 100644
--- a/framework/source/register/registertemp.cxx
+++ b/framework/source/register/registertemp.cxx
@@ -66,7 +66,6 @@
#include <uielement/macrosmenucontroller.hxx>
#include <uielement/newmenucontroller.hxx>
#include <uielement/toolbarsmenucontroller.hxx>
#include <uielement/popupmenucontroller.hxx>

COMPONENTGETIMPLEMENTATIONENVIRONMENT

@@ -87,6 +86,5 @@ COMPONENTGETFACTORY (   IFFACTORY( ::framework::MediaTypeDetectionHelper        
                        IFFACTORY( ::framework::FooterMenuController                    )   else
                        IFFACTORY( ::framework::HeaderMenuController                    )   else
                        IFFACTORY( ::framework::LanguageSelectionMenuController         )   else
                        IFFACTORY( ::framework::Oxt_Handler                             )   else
                        IFFACTORY( ::framework::PopupMenuController                     )
                        IFFACTORY( ::framework::Oxt_Handler                             )
                    )
diff --git a/framework/source/uielement/popupmenucontroller.cxx b/framework/source/uielement/popupmenucontroller.cxx
deleted file mode 100644
index 4c45e4e..0000000
--- a/framework/source/uielement/popupmenucontroller.cxx
+++ /dev/null
@@ -1,244 +0,0 @@
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 *************************************************************/



// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_framework.hxx"

#include <com/sun/star/awt/XPopupMenu.hpp>
#include <com/sun/star/frame/XPopupMenuController.hpp>

#include <toolkit/helper/vclunohelper.hxx>
//#include <toolkit/unohlp.hxx>

#include <rtl/ref.hxx>

#include <vcl/toolbox.hxx>
#include <vcl/menu.hxx>
#include <vcl/svapp.hxx>
#include <vos/mutex.hxx>

#include "uielement/popupmenucontroller.hxx"
#include "services.h"

using rtl::OUString;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::beans;

// --------------------------------------------------------------------


namespace framework
{

DEFINE_XSERVICEINFO_MULTISERVICE        (   PopupMenuController                         ,
                                            OWeakObject                      ,
                                            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.ToolbarController" ) )            ,
                                            ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.framework.PopupMenuController" ) )
                                        )

DEFINE_INIT_SERVICE                     (   PopupMenuController, {} )

class PopupMenuControllerImpl
{
};

//========================================================================
// class PopupMenuController REMOVE REMOVE REMOVE
//========================================================================

PopupMenuController::PopupMenuController( const Reference< lang::XMultiServiceFactory >& rServiceManager )
: svt::ToolboxController( rServiceManager, Reference< frame::XFrame >(), OUString() )
{
}

// --------------------------------------------------------------------

PopupMenuController::~PopupMenuController()
{
}

// --------------------------------------------------------------------
// XInterface
// --------------------------------------------------------------------

Any SAL_CALL PopupMenuController::queryInterface( const Type& aType )  throw (RuntimeException)
{
    Any a( ToolboxController::queryInterface( aType ) );
    if ( a.hasValue() )
        return a;

    return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
}

// --------------------------------------------------------------------

void SAL_CALL PopupMenuController::acquire() throw ()
{
    ToolboxController::acquire();
}

// --------------------------------------------------------------------

void SAL_CALL PopupMenuController::release() throw ()
{
    ToolboxController::release();
}

// --------------------------------------------------------------------
// XComponent
// --------------------------------------------------------------------

void SAL_CALL PopupMenuController::dispose() throw (RuntimeException)
{
    if( mxPopupMenuController.is() )
    {
        Reference< XComponent > xComponent( mxPopupMenuController, UNO_QUERY );
        if( xComponent.is() )
            xComponent->dispose();
        mxPopupMenuController.clear();
    }

    mxPopupMenu.clear();

    svt::ToolboxController::dispose();
}

// --------------------------------------------------------------------
// XStatusListener
// --------------------------------------------------------------------

void SAL_CALL PopupMenuController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException )
{
    svt::ToolboxController::statusChanged(rEvent);
    enable( rEvent.IsEnabled );
}

// --------------------------------------------------------------------
// XToolbarController
// --------------------------------------------------------------------

void SAL_CALL PopupMenuController::execute( sal_Int16 KeyModifier ) throw (RuntimeException)
{
    svt::ToolboxController::execute( KeyModifier );
}

// --------------------------------------------------------------------

void SAL_CALL PopupMenuController::click() throw (RuntimeException)
{
    svt::ToolboxController::click();
}

// --------------------------------------------------------------------

void SAL_CALL PopupMenuController::doubleClick() throw (RuntimeException)
{
    svt::ToolboxController::doubleClick();
}

// --------------------------------------------------------------------

bool PopupMenuController::CreatePopupMenuController() throw (Exception)
{
    Reference< XMultiComponentFactory > xPopupMenuControllerRegistration( getServiceManager()->createInstance( SERVICENAME_POPUPMENUCONTROLLERFACTORY ), UNO_QUERY_THROW );

    Sequence< Any > aSeq( 2 );
    PropertyValue aPropValue;

    aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" ));
    aPropValue.Value <<= getModuleName();
    aSeq[0] <<= aPropValue;
    aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Frame" ));
    aPropValue.Value <<= m_xFrame;
    aSeq[1] <<= aPropValue;

    Reference< XPropertySet >      xProps( getServiceManager(), UNO_QUERY_THROW );
    Reference< XComponentContext > xComponentContext( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), UNO_QUERY_THROW );

    Reference< XPopupMenuController > xPopupMenuController( xPopupMenuControllerRegistration->createInstanceWithArgumentsAndContext( getCommandURL(), aSeq, xComponentContext ), UNO_QUERY );
    if ( xPopupMenuController.is() )
    {
        mxPopupMenuController = xPopupMenuController;
        return true;
    }
    return false;
}

Reference< awt::XWindow > SAL_CALL PopupMenuController::createPopupWindow() throw (RuntimeException)
{
    ::vos::OGuard aSolarLock(Application::GetSolarMutex());

    Reference< awt::XWindow > xRet;

    try
    {
        ToolBox* pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
        if( !pToolBox )
            return xRet;

        // get selected button
        sal_uInt16 nItemId = pToolBox->GetDownItemId();
        if( !nItemId )
            return xRet;

        ::Rectangle aRect( pToolBox->GetItemRect( nItemId ) );

        if( !mxPopupMenuController.is() && !CreatePopupMenuController() )
            return xRet;

        if( !mxPopupMenu.is() )
        {
            mxPopupMenu = Reference< awt::XPopupMenu >( getServiceManager()->createInstance( DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ) ), UNO_QUERY_THROW );
            mxPopupMenuController->setPopupMenu( mxPopupMenu );
        }
        else
        {
            mxPopupMenuController->updatePopupMenu();

        }
        pToolBox->SetItemDown( nItemId, sal_True );
        Reference< awt::XWindowPeer > xPeer( getParent(), UNO_QUERY_THROW );
        mxPopupMenu->execute( xPeer, VCLUnoHelper::ConvertToAWTRect( aRect ), 0 );
        pToolBox->SetItemDown( nItemId, sal_False );
    }
    catch( Exception& )
    {
    }

    return xRet;
}

// --------------------------------------------------------------------

Reference< awt::XWindow > SAL_CALL PopupMenuController::createItemWindow( const Reference< awt::XWindow >& /*Parent*/ )  throw (RuntimeException)
{
    return Reference< awt::XWindow >();
}

// --------------------------------------------------------------------

}

diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx b/framework/source/uielement/popuptoolbarcontroller.cxx
new file mode 100644
index 0000000..53530b3
--- /dev/null
+++ b/framework/source/uielement/popuptoolbarcontroller.cxx
@@ -0,0 +1,415 @@
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 *************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_framework.hxx"

#include <uielement/popuptoolbarcontroller.hxx>
#include <comphelper/processfactory.hxx>
#include <svtools/imagemgr.hxx>
#include <svtools/miscopt.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <tools/urlobj.hxx>
#include <unotools/moduleoptions.hxx>
#include <vcl/svapp.hxx>
#include <vcl/toolbox.hxx>
#include <vos/mutex.hxx>

#include <com/sun/star/awt/PopupMenuDirection.hpp>
#include <com/sun/star/frame/PopupMenuControllerFactory.hpp>


#define UNO_COMMAND_RECENT_FILE_LIST    ".uno:RecentFileList"

using rtl::OUString;
namespace css = ::com::sun::star;

namespace framework
{

PopupMenuToolbarController::PopupMenuToolbarController(
    const css::uno::Reference< css::uno::XComponentContext >& xContext,
    const OUString &rPopupCommand )
    : svt::ToolboxController()
    , m_xContext( xContext )
    , m_bHasController( sal_False )
    , m_aPopupCommand( rPopupCommand )
{
}

PopupMenuToolbarController::~PopupMenuToolbarController()
{
}

void SAL_CALL PopupMenuToolbarController::dispose()
throw ( css::uno::RuntimeException )
{
    svt::ToolboxController::dispose();

    osl::MutexGuard aGuard( m_aMutex );
    if( m_xPopupMenuController.is() )
    {
        css::uno::Reference< css::lang::XComponent > xComponent(
            m_xPopupMenuController, css::uno::UNO_QUERY );
        if( xComponent.is() )
        {
            try
            {
                xComponent->dispose();
            }
            catch (...)
            {}
        }
        m_xPopupMenuController.clear();
    }

    m_xContext.clear();
    m_xPopupMenuFactory.clear();
    m_xPopupMenu.clear();
}

void SAL_CALL PopupMenuToolbarController::initialize(
    const css::uno::Sequence< css::uno::Any >& aArguments )
throw ( css::uno::Exception, css::uno::RuntimeException )
{
    ToolboxController::initialize( aArguments );

    osl::MutexGuard aGuard( m_aMutex );
    if ( !m_aPopupCommand.getLength() )
        m_aPopupCommand = m_aCommandURL;

    try
    {
        m_xPopupMenuFactory.set(
            css::frame::PopupMenuControllerFactory::create( m_xContext ) );
        m_bHasController = m_xPopupMenuFactory->hasController(
            m_aPopupCommand, getModuleName() );
    }
    catch (const css::uno::Exception& e)
    {
        OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s",
                   rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
        (void) e;
    }

    vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
    ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
    if ( pToolBox )
    {
        ToolBoxItemBits nCurStyle( pToolBox->GetItemBits( m_nToolBoxId ) );
        ToolBoxItemBits nSetStyle( getDropDownStyle() );
        pToolBox->SetItemBits( m_nToolBoxId,
                               m_bHasController ?
                                    nCurStyle | nSetStyle :
                                    nCurStyle & ~nSetStyle );
    }

}

void SAL_CALL
PopupMenuToolbarController::statusChanged(
    const css::frame::FeatureStateEvent& rEvent )
    throw ( css::uno::RuntimeException )
{
    // TODO move to base class

    svt::ToolboxController::statusChanged( rEvent );
    enable( rEvent.IsEnabled );
}

css::uno::Reference< css::awt::XWindow > SAL_CALL
PopupMenuToolbarController::createPopupWindow()
    throw ( css::uno::RuntimeException )
{
    css::uno::Reference< css::awt::XWindow > xRet;

    osl::MutexGuard aGuard( m_aMutex );
    if ( !m_bHasController )
        return xRet;

    createPopupMenuController();

    vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
    ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
    if ( !pToolBox )
        return xRet;

    pToolBox->SetItemDown( m_nToolBoxId, sal_True );
    sal_uInt16 nId = m_xPopupMenu->execute(
        css::uno::Reference< css::awt::XWindowPeer >( getParent(), css::uno::UNO_QUERY ),
        VCLUnoHelper::ConvertToAWTRect( pToolBox->GetItemRect( m_nToolBoxId ) ),
        css::awt::PopupMenuDirection::EXECUTE_DEFAULT );
    pToolBox->SetItemDown( m_nToolBoxId, sal_False );

    if ( nId )
        functionExecuted( m_xPopupMenu->getCommand( nId ) );

    return xRet;
}

void PopupMenuToolbarController::functionExecuted( const OUString &/*rCommand*/)
{
}

sal_uInt16 PopupMenuToolbarController::getDropDownStyle() const
{
    return TIB_DROPDOWN;
}

void PopupMenuToolbarController::createPopupMenuController()
{
    if( !m_bHasController )
        return;

    if ( !m_xPopupMenuController.is() )
    {
        css::uno::Sequence< css::uno::Any > aArgs( 2 );
        css::beans::PropertyValue aProp;

        aProp.Name = DECLARE_ASCII( "Frame" );
        aProp.Value <<= m_xFrame;
        aArgs[0] <<= aProp;

        aProp.Name = DECLARE_ASCII( "ModuleIdentifier" );
        aProp.Value <<= getModuleName();
        aArgs[1] <<= aProp;
        try
        {
            m_xPopupMenu.set(
                m_xContext->getServiceManager()->createInstanceWithContext(
                    DECLARE_ASCII( "com.sun.star.awt.PopupMenu" ), m_xContext ),
                        css::uno::UNO_QUERY_THROW );
            m_xPopupMenuController.set(
                m_xPopupMenuFactory->createInstanceWithArgumentsAndContext(
                    m_aPopupCommand, aArgs, m_xContext), css::uno::UNO_QUERY_THROW );

            m_xPopupMenuController->setPopupMenu( m_xPopupMenu );
        }
        catch ( const css::uno::Exception &e )
        {
            m_xPopupMenu.clear();
            OSL_TRACE( "PopupMenuToolbarController - caught an exception! %s",
                       rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
            (void) e;
        }
    }
}

DEFINE_XSERVICEINFO_MULTISERVICE_2( WizardsToolbarController,
                                    ::cppu::OWeakObject,
                                    DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
                                    DECLARE_ASCII("org.apache.openoffice.comp.framework.WizardsToolbarController")
                                   )

DEFINE_INIT_SERVICE( WizardsToolbarController, {} )

WizardsToolbarController::WizardsToolbarController(
    const css::uno::Reference< css::uno::XComponentContext >& xContext )
    : PopupMenuToolbarController( xContext )
{
}

sal_uInt16 WizardsToolbarController::getDropDownStyle() const
{
    return TIB_DROPDOWNONLY;
}

DEFINE_XSERVICEINFO_MULTISERVICE_2( OpenToolbarController,
                                    ::cppu::OWeakObject,
                                    DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
                                    DECLARE_ASCII("org.apache.openoffice.comp.framework.OpenToolbarController")
                                   )

DEFINE_INIT_SERVICE( OpenToolbarController, {} )

OpenToolbarController::OpenToolbarController(
    const css::uno::Reference< css::uno::XComponentContext >& xContext )
    : PopupMenuToolbarController( xContext, DECLARE_ASCII( UNO_COMMAND_RECENT_FILE_LIST ) )
{
}


DEFINE_XSERVICEINFO_MULTISERVICE_2( NewToolbarController,
                                    ::cppu::OWeakObject,
                                    DECLARE_ASCII("com.sun.star.frame.ToolbarController"),
                                    DECLARE_ASCII("org.apache.openoffice.comp.framework.NewToolbarController")
                                   )

DEFINE_INIT_SERVICE( NewToolbarController, {} )

NewToolbarController::NewToolbarController(
    const css::uno::Reference< css::uno::XComponentContext >& xContext )
    : PopupMenuToolbarController( xContext )
{
}

void SAL_CALL
NewToolbarController::statusChanged(
    const css::frame::FeatureStateEvent& rEvent )
    throw ( css::uno::RuntimeException )
{
    if ( rEvent.IsEnabled )
    {
        OUString aState;
        rEvent.State >>= aState;
        // set the image even if the state is not a string
        // this will set the image of the default module
        setItemImage( aState );
    }

    enable( rEvent.IsEnabled );
}

void NewToolbarController::functionExecuted( const OUString &rCommand )
{
    setItemImage( rCommand );
}

/**
    it return the existing state of the given URL in the popupmenu of this toolbox control.

    If the given URL can be located as an action command of one menu item of the
    popup menu of this control, we return sal_True. Otherwhise we return sal_False.
    Further we return a fallback URL, in case we have to return sal_False. Because
    the outside code must select a valid item of the popup menu everytime ...
    and we define it here. By the way this m ethod was written to handle
    error situations gracefully. E.g. it can be called during creation time
    but then we have no valid menu. For this case we know another fallback URL.
    Then we return the private:factory/ URL of the default factory.

    @param  rPopupMenu
                pounts to the popup menu, on which item we try to locate the given URL
                Can be NULL! Search will be supressed then.

    @param  sURL
                the URL for searching

    @param  sFallback
                contains the fallback URL in case we return FALSE
                Must point to valid memory!

    @param  aImage
                contains the image of the menu for the URL.

    @return sal_True - if URL could be located as an item of the popup menu.
            sal_False - otherwhise.
*/
static sal_Bool Impl_ExistURLInMenu(
    const css::uno::Reference< css::awt::XPopupMenu > &rPopupMenu,
    OUString &sURL,
    OUString &sFallback,
    Image &aImage )
{
    sal_Bool bValidFallback( sal_False );
    sal_uInt16 nCount( 0 );
    if ( rPopupMenu.is() && ( nCount = rPopupMenu->getItemCount() ) && sURL.getLength() )
    {
        for ( sal_uInt16 n = 0; n < nCount; ++n )
        {
            sal_uInt16 nId = rPopupMenu->getItemId( n );
            OUString aCmd( rPopupMenu->getCommand( nId ) );

            if ( !bValidFallback && aCmd.getLength() )
            {
                sFallback = aCmd;
                bValidFallback = sal_True;
            }

            // match even if the menu command is more detailed
            // (maybe an additional query) #i28667#
            if ( aCmd.match( sURL ) )
            {
                sURL = aCmd;
                const css::uno::Reference< css::graphic::XGraphic > xGraphic(
                    rPopupMenu->getItemImage( nId ) );
                if ( xGraphic.is() )
                    aImage = Image( xGraphic );
                return sal_True;
            }
        }
    }

    if ( !bValidFallback )
    {
        rtl::OUStringBuffer aBuffer;
        aBuffer.appendAscii( RTL_CONSTASCII_STRINGPARAM( "private:factory/" ) );
        aBuffer.append( SvtModuleOptions().GetDefaultModuleName() );
        sFallback = aBuffer.makeStringAndClear();
    }

    return sal_False;
}

/** We accept URL's here only, which exist as items of our internal popup menu.
    All other ones will be ignored and a fallback is used.
 */
void NewToolbarController::setItemImage( const OUString &rCommand )
{
    vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
    ToolBox* pToolBox = static_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
    if ( !pToolBox )
        return;

    OUString aURL = rCommand;
    OUString sFallback;
    Image aMenuImage;

    sal_Bool bValid( Impl_ExistURLInMenu( m_xPopupMenu, aURL, sFallback, aMenuImage ) );
    // do not change aURL if Impl_ExistURLInMenu returned sal_False
    // this allows later initialization of the PopupMenuController on createPopupWindow()
    // and works even if SvFileInformationManager does not know the module
    if ( !aURL.getLength() )
        aURL = sFallback;

    sal_Bool bBig = SvtMiscOptions().AreCurrentSymbolsLarge();
    sal_Bool bHC = pToolBox->GetSettings().GetStyleSettings().GetHighContrastMode();

    INetURLObject aURLObj( aURL );
    Image aImage = SvFileInformationManager::GetImageNoDefault( aURLObj, bBig, bHC );
    if ( !aImage )
    {
        if ( !!aMenuImage )
            aImage =  aMenuImage;
        else if ( !bValid )
            // If SvFileInformationManager didn't know the module, try with the default
            aImage = SvFileInformationManager::GetImageNoDefault( INetURLObject( sFallback ), bBig, bHC );

        if ( !aImage )
            aImage = SvFileInformationManager::GetImage( aURLObj, bBig, bHC );
    }

    // if everything failed, just use the image associated with the toolbar item command
    if ( !aImage )
        return;

    Size aBigSize( pToolBox->GetDefaultImageSize() );
    if ( bBig && aImage.GetSizePixel() != aBigSize )
    {
        BitmapEx aScaleBmpEx( aImage.GetBitmapEx() );
        aScaleBmpEx.Scale( aBigSize, BMP_SCALE_INTERPOLATE );
        pToolBox->SetItemImage( m_nToolBoxId, Image( aScaleBmpEx ) );
    }
    else
        pToolBox->SetItemImage( m_nToolBoxId, aImage );
}


}
diff --git a/framework/util/fwk.component b/framework/util/fwk.component
index c41c25b..1e1e17d 100644
--- a/framework/util/fwk.component
+++ b/framework/util/fwk.component
@@ -142,4 +142,13 @@
  <implementation name="com.sun.star.comp.framework.TabWindowService">
    <service name="com.sun.star.ui.dialogs.TabContainerWindow"/>
  </implementation>
  <implementation name="org.apache.openoffice.comp.framework.OpenToolbarController">
    <service name="com.sun.star.frame.ToolbarController"/>
  </implementation>
  <implementation name="org.apache.openoffice.comp.framework.NewToolbarController">
    <service name="com.sun.star.frame.ToolbarController"/>
  </implementation>
  <implementation name="org.apache.openoffice.comp.framework.WizardsToolbarController">
    <service name="com.sun.star.frame.ToolbarController"/>
  </implementation>
</component>
diff --git a/framework/util/fwl.component b/framework/util/fwl.component
index 4853f6d..d4fda5c 100644
--- a/framework/util/fwl.component
+++ b/framework/util/fwl.component
@@ -63,9 +63,6 @@
  <implementation name="com.sun.star.comp.framework.OXTFileHandler">
    <service name="com.sun.star.frame.ContentHandler"/>
  </implementation>
  <implementation name="com.sun.star.comp.framework.PopupMenuController">
    <service name="com.sun.star.frame.ToolbarController"/>
  </implementation>
  <implementation name="com.sun.star.comp.framework.PopupMenuControllerDispatcher">
    <service name="com.sun.star.frame.ProtocolHandler"/>
  </implementation>
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
index 86c10bb..6b00240 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
@@ -412,6 +412,39 @@
          <value>com.sun.star.svx.UpSearchToolboxController</value>
        </prop>
      </node>
      <node oor:name="org.apache.openoffice.comp.framework.OpenToolbarController" oor:op="replace">
        <prop oor:name="Command">
          <value>.uno:Open</value>
        </prop>
        <prop oor:name="Module">
          <value/>
        </prop>
        <prop oor:name="Controller">
          <value>org.apache.openoffice.comp.framework.OpenToolbarController</value>
        </prop>
      </node>
      <node oor:name="org.apache.openoffice.comp.framework.NewToolbarController" oor:op="replace">
        <prop oor:name="Command">
          <value>.uno:AddDirect</value>
        </prop>
        <prop oor:name="Module">
          <value/>
        </prop>
        <prop oor:name="Controller">
          <value>org.apache.openoffice.comp.framework.NewToolbarController</value>
        </prop>
      </node>
      <node oor:name="org.apache.openoffice.comp.framework.WizardsToolbarController" oor:op="replace">
        <prop oor:name="Command">
          <value>.uno:AutoPilotMenu</value>
        </prop>
        <prop oor:name="Module">
          <value/>
        </prop>
        <prop oor:name="Controller">
          <value>org.apache.openoffice.comp.framework.WizardsToolbarController</value>
        </prop>
      </node>
    </node>
    <node oor:name="StatusBar">
      <node oor:name="c1" oor:op="replace">