Kaydet (Commit) 9622a807 authored tarafından Matúš Kukan's avatar Matúš Kukan

fwk: Constructor feature for RecentFilesMenuController.

Change-Id: I7bb943a6fe7526264e8465faeb7e86adbf3cb737
üst 9f653410
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* 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 .
*/
#ifndef INCLUDED_FRAMEWORK_INC_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX
#define INCLUDED_FRAMEWORK_INC_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX
#include <macros/xserviceinfo.hxx>
#include <svtools/popupmenucontrollerbase.hxx>
namespace framework
{
struct LoadRecentFile
{
::com::sun::star::util::URL aTargetURL;
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgSeq;
::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > xDispatch;
};
class RecentFilesMenuController : public svt::PopupMenuControllerBase
{
using svt::PopupMenuControllerBase::disposing;
public:
RecentFilesMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext );
virtual ~RecentFilesMenuController();
// XServiceInfo
DECLARE_XSERVICEINFO
// XStatusListener
virtual void SAL_CALL statusChanged( const ::com::sun::star::frame::FeatureStateEvent& Event ) throw ( ::com::sun::star::uno::RuntimeException );
// XMenuListener
virtual void SAL_CALL itemSelected( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL itemActivated( const ::com::sun::star::awt::MenuEvent& rEvent ) throw (::com::sun::star::uno::RuntimeException);
// XDispatchProvider
virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatch > SAL_CALL queryDispatch( const ::com::sun::star::util::URL& aURL, const OUString& sTarget, sal_Int32 nFlags ) throw( ::com::sun::star::uno::RuntimeException );
// XDispatch
virtual void SAL_CALL dispatch( const ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& seqProperties ) throw( ::com::sun::star::uno::RuntimeException );
// XEventListener
virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( ::com::sun::star::uno::RuntimeException );
DECL_STATIC_LINK( RecentFilesMenuController, ExecuteHdl_Impl, LoadRecentFile* );
private:
virtual void impl_setPopupMenu();
struct RecentFile
{
OUString aURL;
OUString aTitle;
};
void fillPopupMenu( com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >& rPopupMenu );
void executeEntry( sal_Int32 nIndex );
std::vector< RecentFile > m_aRecentFilesItems;
sal_Bool m_bDisabled : 1;
};
}
#endif // INCLUDED_FRAMEWORK_INC_UIELEMENT_RECENTFILESMENUCONTROLLER_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -47,7 +47,6 @@ ...@@ -47,7 +47,6 @@
#include <uifactory/toolboxfactory.hxx> #include <uifactory/toolboxfactory.hxx>
#include "uiconfiguration/windowstateconfiguration.hxx" #include "uiconfiguration/windowstateconfiguration.hxx"
#include <services/autorecovery.hxx> #include <services/autorecovery.hxx>
#include <uielement/recentfilesmenucontroller.hxx>
#include <uifactory/statusbarfactory.hxx> #include <uifactory/statusbarfactory.hxx>
#include <uiconfiguration/uicategorydescription.hxx> #include <uiconfiguration/uicategorydescription.hxx>
#include <services/sessionlistener.hxx> #include <services/sessionlistener.hxx>
...@@ -74,7 +73,6 @@ COMPONENTGETFACTORY ( fwk, ...@@ -74,7 +73,6 @@ COMPONENTGETFACTORY ( fwk,
IFFACTORY( ::framework::WindowStateConfiguration ) else IFFACTORY( ::framework::WindowStateConfiguration ) else
IFFACTORY( ::framework::ToolbarControllerFactory ) else IFFACTORY( ::framework::ToolbarControllerFactory ) else
IFFACTORY( ::framework::AutoRecovery ) else IFFACTORY( ::framework::AutoRecovery ) else
IFFACTORY( ::framework::RecentFilesMenuController ) else
IFFACTORY( ::framework::StatusBarFactory ) else IFFACTORY( ::framework::StatusBarFactory ) else
IFFACTORY( ::framework::UICategoryDescription ) else IFFACTORY( ::framework::UICategoryDescription ) else
IFFACTORY( ::framework::SessionListener ) else IFFACTORY( ::framework::SessionListener ) else
......
...@@ -17,61 +17,106 @@ ...@@ -17,61 +17,106 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 . * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ */
#include <uielement/recentfilesmenucontroller.hxx>
#include <threadhelp/resetableguard.hxx>
#include "services.h"
#include <classes/resource.hrc> #include <classes/resource.hrc>
#include <classes/fwkresid.hxx> #include <classes/fwkresid.hxx>
#include <com/sun/star/util/XStringWidth.hpp>
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <osl/file.hxx> #include <osl/file.hxx>
#include <osl/mutex.hxx>
#include <rtl/ref.hxx>
#include <svtools/popupmenucontrollerbase.hxx>
#include <tools/urlobj.hxx> #include <tools/urlobj.hxx>
#include <unotools/historyoptions.hxx> #include <unotools/historyoptions.hxx>
#include <vcl/menu.hxx> #include <vcl/menu.hxx>
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <osl/mutex.hxx>
using namespace css;
using namespace com::sun::star::uno; using namespace com::sun::star::uno;
using namespace com::sun::star::lang; using namespace com::sun::star::lang;
using namespace com::sun::star::frame; using namespace com::sun::star::frame;
using namespace com::sun::star::beans; using namespace com::sun::star::beans;
using namespace com::sun::star::util; using namespace com::sun::star::util;
using namespace framework;
#define MAX_MENU_ITEMS 99 #define MAX_MENU_ITEMS 99
namespace {
static const char CMD_CLEAR_LIST[] = ".uno:ClearRecentFileList"; static const char CMD_CLEAR_LIST[] = ".uno:ClearRecentFileList";
static const char CMD_PREFIX[] = "vnd.sun.star.popup:RecentFileList?entry="; static const char CMD_PREFIX[] = "vnd.sun.star.popup:RecentFileList?entry=";
static const char MENU_SHORTCUT[] = "~N. "; static const char MENU_SHORTCUT[] = "~N. ";
namespace framework struct LoadRecentFile
{ {
util::URL aTargetURL;
uno::Sequence< beans::PropertyValue > aArgSeq;
uno::Reference< frame::XDispatch > xDispatch;
};
class RecentFilesStringLength : public ::cppu::WeakImplHelper1< ::com::sun::star::util::XStringWidth > class RecentFilesMenuController : public svt::PopupMenuControllerBase
{ {
public: using svt::PopupMenuControllerBase::disposing;
RecentFilesStringLength() {}
virtual ~RecentFilesStringLength() {}
// XStringWidth public:
sal_Int32 SAL_CALL queryStringWidth( const OUString& aString ) RecentFilesMenuController( const uno::Reference< uno::XComponentContext >& xContext );
throw (::com::sun::star::uno::RuntimeException) virtual ~RecentFilesMenuController();
{
return aString.getLength(); // XServiceInfo
} virtual OUString SAL_CALL getImplementationName()
}; throw (css::uno::RuntimeException)
{
return OUString("com.sun.star.comp.framework.RecentFilesMenuController");
}
virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
throw (css::uno::RuntimeException)
{
return cppu::supportsService(this, ServiceName);
}
DEFINE_XSERVICEINFO_MULTISERVICE_2 ( RecentFilesMenuController , virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
OWeakObject , throw (css::uno::RuntimeException)
SERVICENAME_POPUPMENUCONTROLLER , {
IMPLEMENTATIONNAME_RECENTFILESMENUCONTROLLER css::uno::Sequence< OUString > aSeq(1);
) aSeq[0] = OUString("com.sun.star.frame.PopupMenuController");
return aSeq;
}
// XStatusListener
virtual void SAL_CALL statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException );
// XMenuListener
virtual void SAL_CALL itemSelected( const awt::MenuEvent& rEvent ) throw (uno::RuntimeException);
virtual void SAL_CALL itemActivated( const awt::MenuEvent& rEvent ) throw (uno::RuntimeException);
DEFINE_INIT_SERVICE ( RecentFilesMenuController, {} ) // XDispatchProvider
virtual uno::Reference< frame::XDispatch > SAL_CALL queryDispatch( const util::URL& aURL, const OUString& sTarget, sal_Int32 nFlags ) throw( uno::RuntimeException );
RecentFilesMenuController::RecentFilesMenuController( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext ) : // XDispatch
virtual void SAL_CALL dispatch( const util::URL& aURL, const uno::Sequence< beans::PropertyValue >& seqProperties ) throw( uno::RuntimeException );
// XEventListener
virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( uno::RuntimeException );
DECL_STATIC_LINK( RecentFilesMenuController, ExecuteHdl_Impl, LoadRecentFile* );
private:
virtual void impl_setPopupMenu();
struct RecentFile
{
OUString aURL;
OUString aTitle;
};
void fillPopupMenu( com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >& rPopupMenu );
void executeEntry( sal_Int32 nIndex );
std::vector< RecentFile > m_aRecentFilesItems;
sal_Bool m_bDisabled : 1;
};
RecentFilesMenuController::RecentFilesMenuController( const uno::Reference< uno::XComponentContext >& xContext ) :
svt::PopupMenuControllerBase( xContext ), svt::PopupMenuControllerBase( xContext ),
m_bDisabled( sal_False ) m_bDisabled( sal_False )
{ {
...@@ -96,7 +141,6 @@ void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu > ...@@ -96,7 +141,6 @@ void RecentFilesMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >
if ( pVCLPopupMenu ) if ( pVCLPopupMenu )
{ {
Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST ); Sequence< Sequence< PropertyValue > > aHistoryList = SvtHistoryOptions().GetList( ePICKLIST );
Reference< XStringWidth > xStringLength( new RecentFilesStringLength );
int nPickListMenuItems = ( aHistoryList.getLength() > MAX_MENU_ITEMS ) ? MAX_MENU_ITEMS : aHistoryList.getLength(); int nPickListMenuItems = ( aHistoryList.getLength() > MAX_MENU_ITEMS ) ? MAX_MENU_ITEMS : aHistoryList.getLength();
m_aRecentFilesItems.clear(); m_aRecentFilesItems.clear();
...@@ -377,4 +421,14 @@ IMPL_STATIC_LINK_NOINSTANCE( RecentFilesMenuController, ExecuteHdl_Impl, LoadRec ...@@ -377,4 +421,14 @@ IMPL_STATIC_LINK_NOINSTANCE( RecentFilesMenuController, ExecuteHdl_Impl, LoadRec
} }
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
com_sun_star_comp_framework_RecentFilesMenuController_get_implementation(
css::uno::XComponentContext *context,
css::uno::Sequence<css::uno::Any> const &)
{
rtl::Reference<RecentFilesMenuController> x(new RecentFilesMenuController(context));
x->acquire();
return static_cast<cppu::OWeakObject *>(x.get());
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -93,7 +93,8 @@ ...@@ -93,7 +93,8 @@
<implementation name="com.sun.star.comp.framework.PopupMenuControllerFactory"> <implementation name="com.sun.star.comp.framework.PopupMenuControllerFactory">
<service name="com.sun.star.frame.PopupMenuControllerFactory"/> <service name="com.sun.star.frame.PopupMenuControllerFactory"/>
</implementation> </implementation>
<implementation name="com.sun.star.comp.framework.RecentFilesMenuController"> <implementation name="com.sun.star.comp.framework.RecentFilesMenuController"
constructor="com_sun_star_comp_framework_RecentFilesMenuController_get_implementation">
<service name="com.sun.star.frame.PopupMenuController"/> <service name="com.sun.star.frame.PopupMenuController"/>
</implementation> </implementation>
<implementation name="com.sun.star.comp.framework.StatusBarControllerFactory"> <implementation name="com.sun.star.comp.framework.StatusBarControllerFactory">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment