summaryrefslogtreecommitdiff
path: root/sfx2/source/toolbox
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2013-04-30 10:31:00 +0200
committerJan Holesovsky <kendy@suse.cz>2013-04-30 10:33:15 +0200
commitf60424b29622033ae02491bda328c304ae1bc05d (patch)
tree0bb6ba356685ecefa6d757fd60e4daf9eb1fb4e4 /sfx2/source/toolbox
parentf486c562816fc59dc4d341d0a32a65b1e65eeb92 (diff)
bnc#816516: Implement easy access to the recent documents.
This adds a dropdown to the 'Open' toolbar tool. Change-Id: I5b4aa99476e721c1479152b46bbc79cc0b095318
Diffstat (limited to 'sfx2/source/toolbox')
-rw-r--r--sfx2/source/toolbox/tbxitem.cxx56
1 files changed, 56 insertions, 0 deletions
diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx
index a9e786f30644..8085dccbb643 100644
--- a/sfx2/source/toolbox/tbxitem.cxx
+++ b/sfx2/source/toolbox/tbxitem.cxx
@@ -25,7 +25,9 @@
#include <string> // prevent conflict with STL includes
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/awt/XPopupMenu.hpp>
#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/awt/XWindowPeer.hpp>
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
@@ -38,6 +40,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/XLayoutManager.hpp>
+#include <com/sun/star/frame/XPopupMenuController.hpp>
#include <com/sun/star/frame/status/ItemStatus.hpp>
#include <com/sun/star/frame/status/ItemState.hpp>
#include <com/sun/star/ui/XUIElementFactory.hpp>
@@ -92,6 +95,7 @@
#include "virtmenu.hxx"
#include "sfx2/imagemgr.hxx"
+using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::frame::status;
@@ -105,6 +109,7 @@ using namespace ::com::sun::star::ui;
SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, sal_True);
SFX_IMPL_TOOLBOX_CONTROL(SfxAppToolBoxControl_Impl, SfxStringItem);
+SFX_IMPL_TOOLBOX_CONTROL(SfxRecentFilesToolBoxControl, SfxStringItem);
static Window* GetTopMostParentSystemWindow( Window* pWindow )
{
@@ -1741,4 +1746,55 @@ void SfxAppToolBoxControl_Impl::Click( )
{
}
+//--------------------------------------------------------------------
+
+SfxRecentFilesToolBoxControl::SfxRecentFilesToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
+ : SfxToolBoxControl( nSlotId, nId, rBox )
+{
+ rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | TIB_DROPDOWN);
+}
+
+SfxRecentFilesToolBoxControl::~SfxRecentFilesToolBoxControl()
+{
+}
+
+SfxPopupWindow* SfxRecentFilesToolBoxControl::CreatePopupWindow()
+{
+ ToolBox& rBox = GetToolBox();
+ sal_uInt16 nItemId = GetId();
+ ::Rectangle aRect( rBox.GetItemRect( nItemId ) );
+
+ Sequence< Any > aArgs( 2 );
+ PropertyValue aPropValue;
+
+ aPropValue.Name = "CommandURL";
+ aPropValue.Value <<= OUString( ".uno:RecentFileList" );
+ aArgs[0] <<= aPropValue;
+
+ aPropValue.Name = "Frame";
+ aPropValue.Value <<= m_xFrame;
+ aArgs[1] <<= aPropValue;
+
+ uno::Reference< frame::XPopupMenuController > xPopupController( m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+ "com.sun.star.comp.framework.RecentFilesMenuController", aArgs, m_xContext ), UNO_QUERY );
+
+ uno::Reference< awt::XPopupMenu > xPopupMenu( m_xContext->getServiceManager()->createInstanceWithContext(
+ "com.sun.star.awt.PopupMenu", m_xContext ), uno::UNO_QUERY );
+
+ if ( xPopupController.is() && xPopupMenu.is() )
+ {
+ xPopupController->setPopupMenu( xPopupMenu );
+
+ rBox.SetItemDown( nItemId, sal_True );
+ Reference< awt::XWindowPeer > xPeer( getParent(), uno::UNO_QUERY );
+
+ if ( xPeer.is() )
+ xPopupMenu->execute( xPeer, VCLUnoHelper::ConvertToAWTRect( aRect ), 0 );
+
+ rBox.SetItemDown( nItemId, sal_False );
+ }
+
+ return 0;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */