summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorSzymon Kłos <eszkadev@gmail.com>2015-07-07 16:44:59 +0200
committerSzymon Kłos <eszkadev@gmail.com>2015-07-16 09:53:32 +0200
commitce722af0cce170a2aac3a5e01cd66e6c24fba63c (patch)
tree4915fbc22ac6ddfd09c2858c3d8653a72f0e6bae /framework
parent1ceb7bc53b347deb93e7cca415b90e71057cfac5 (diff)
'Save As' popup menu in the Writer's toolbar
Change-Id: I1b1cb7fcd2ae0e0f50e4d8e3900bc416435e60bf
Diffstat (limited to 'framework')
-rw-r--r--framework/Library_fwk.mk1
-rw-r--r--framework/inc/classes/resource.hrc1
-rw-r--r--framework/source/classes/resource.src5
-rw-r--r--framework/source/uielement/saveasmenucontroller.cxx191
-rw-r--r--framework/util/fwk.component4
5 files changed, 202 insertions, 0 deletions
diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk
index 197910160c33..d07f8b97e37f 100644
--- a/framework/Library_fwk.mk
+++ b/framework/Library_fwk.mk
@@ -144,6 +144,7 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
framework/source/uielement/popuptoolbarcontroller \
framework/source/uielement/progressbarwrapper \
framework/source/uielement/recentfilesmenucontroller \
+ framework/source/uielement/saveasmenucontroller \
framework/source/uielement/spinfieldtoolbarcontroller \
framework/source/uielement/statusbar \
framework/source/uielement/statusbaritem \
diff --git a/framework/inc/classes/resource.hrc b/framework/inc/classes/resource.hrc
index 6620c99ca509..2b1ea1c56f31 100644
--- a/framework/inc/classes/resource.hrc
+++ b/framework/inc/classes/resource.hrc
@@ -51,6 +51,7 @@
#define STR_CLEAR_RECENT_FILES_HELP (RID_STR_START+24)
#define STR_LANGSTATUS_HINT (RID_STR_START+25)
#define STR_OPEN_REMOTE (RID_STR_START+26)
+#define STR_REMOTE_FILE (RID_STR_START+27)
#define POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION (RID_MENU_START+0)
diff --git a/framework/source/classes/resource.src b/framework/source/classes/resource.src
index 0ef53ae2fed5..4f8ce0e7e5a3 100644
--- a/framework/source/classes/resource.src
+++ b/framework/source/classes/resource.src
@@ -119,6 +119,11 @@ String STR_OPEN_REMOTE
Text [ en-US ] = "Open remote file";
};
+String STR_REMOTE_FILE
+{
+ Text [ en-US ] = "Remote file";
+};
+
String STR_TOOLBAR_TITLE_ADDON
{
Text [ en-US ] = "Add-On %num%";
diff --git a/framework/source/uielement/saveasmenucontroller.cxx b/framework/source/uielement/saveasmenucontroller.cxx
new file mode 100644
index 000000000000..7e4fd92db865
--- /dev/null
+++ b/framework/source/uielement/saveasmenucontroller.cxx
@@ -0,0 +1,191 @@
+/* -*- 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 .
+ */
+
+#include <classes/resource.hrc>
+#include <classes/fwkresid.hxx>
+
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <osl/file.hxx>
+#include <osl/mutex.hxx>
+#include <rtl/ref.hxx>
+#include <svtools/popupmenucontrollerbase.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/historyoptions.hxx>
+#include <vcl/menu.hxx>
+#include <vcl/svapp.hxx>
+
+using namespace css;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::beans;
+using namespace com::sun::star::util;
+using namespace framework;
+
+namespace {
+
+static const char CMD_SAVE_REMOTE[] = ".uno:OpenRemote"; // TODO
+
+class SaveAsMenuController : public svt::PopupMenuControllerBase
+{
+ using svt::PopupMenuControllerBase::disposing;
+
+public:
+ SaveAsMenuController( const uno::Reference< uno::XComponentContext >& xContext );
+ virtual ~SaveAsMenuController();
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
+ {
+ return OUString("com.sun.star.comp.framework.SaveAsMenuController");
+ }
+
+ virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
+ throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
+ {
+ return cppu::supportsService(this, ServiceName);
+ }
+
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
+ throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
+ {
+ css::uno::Sequence< OUString > aSeq(1);
+ aSeq[0] = "com.sun.star.frame.PopupMenuController";
+ return aSeq;
+ }
+
+ // XStatusListener
+ virtual void SAL_CALL statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
+
+ // XMenuListener
+ virtual void SAL_CALL itemSelected( const awt::MenuEvent& rEvent ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
+ virtual void SAL_CALL itemActivated( const awt::MenuEvent& rEvent ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
+ // XEventListener
+ virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
+
+private:
+ virtual void impl_setPopupMenu() SAL_OVERRIDE;
+
+ void fillPopupMenu( com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >& rPopupMenu );
+
+ bool m_bDisabled : 1;
+};
+
+SaveAsMenuController::SaveAsMenuController( const uno::Reference< uno::XComponentContext >& xContext ) :
+ svt::PopupMenuControllerBase( xContext ),
+ m_bDisabled( false )
+{
+}
+
+SaveAsMenuController::~SaveAsMenuController()
+{
+}
+
+// private function
+void SaveAsMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
+{
+ VCLXPopupMenu* pPopupMenu = static_cast<VCLXPopupMenu *>(VCLXMenu::GetImplementation( rPopupMenu ));
+ PopupMenu* pVCLPopupMenu = 0;
+
+ SolarMutexGuard aSolarMutexGuard;
+
+ resetPopupMenu( rPopupMenu );
+ if ( pPopupMenu )
+ pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu());
+
+ if ( pVCLPopupMenu )
+ {
+ // Open remote menu entry
+ pVCLPopupMenu->InsertItem( sal_uInt16( 0 ),
+ FWK_RESSTR( STR_REMOTE_FILE ) );
+ pVCLPopupMenu->SetItemCommand( sal_uInt16( 0 ),
+ OUString( CMD_SAVE_REMOTE ) );
+ }
+}
+
+// XEventListener
+void SAL_CALL SaveAsMenuController::disposing( const EventObject& ) throw ( RuntimeException, std::exception )
+{
+ Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
+
+ osl::MutexGuard aLock( m_aMutex );
+ m_xFrame.clear();
+ m_xDispatch.clear();
+
+ if ( m_xPopupMenu.is() )
+ m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
+ m_xPopupMenu.clear();
+}
+
+// XStatusListener
+void SAL_CALL SaveAsMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException, std::exception )
+{
+ osl::MutexGuard aLock( m_aMutex );
+ m_bDisabled = !Event.IsEnabled;
+}
+
+void SAL_CALL SaveAsMenuController::itemSelected( const css::awt::MenuEvent& rEvent ) throw (RuntimeException, std::exception)
+{
+ Reference< css::awt::XPopupMenu > xPopupMenu;
+
+ osl::ClearableMutexGuard aLock( m_aMutex );
+ xPopupMenu = m_xPopupMenu;
+ aLock.clear();
+
+ if ( xPopupMenu.is() )
+ {
+ const OUString aCommand( xPopupMenu->getCommand( rEvent.MenuId ) );
+ OSL_TRACE( "SaveAsMenuController::itemSelected() - Command : %s",
+ OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() );
+
+ if ( aCommand == CMD_SAVE_REMOTE )
+ {
+ Sequence< PropertyValue > aArgsList( 0 );
+ dispatchCommand( CMD_SAVE_REMOTE, aArgsList );
+ }
+ }
+}
+
+void SAL_CALL SaveAsMenuController::itemActivated( const css::awt::MenuEvent& ) throw (RuntimeException, std::exception)
+{
+ osl::MutexGuard aLock( m_aMutex );
+ impl_setPopupMenu();
+}
+
+// XPopupMenuController
+void SaveAsMenuController::impl_setPopupMenu()
+{
+ if ( m_xPopupMenu.is() )
+ fillPopupMenu( m_xPopupMenu );
+}
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
+com_sun_star_comp_framework_SaveAsMenuController_get_implementation(
+ css::uno::XComponentContext *context,
+ css::uno::Sequence<css::uno::Any> const &)
+{
+ return cppu::acquire(new SaveAsMenuController(context));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/framework/util/fwk.component b/framework/util/fwk.component
index 477d524cac34..ad1678222417 100644
--- a/framework/util/fwk.component
+++ b/framework/util/fwk.component
@@ -117,6 +117,10 @@
constructor="com_sun_star_comp_framework_RecentFilesMenuController_get_implementation">
<service name="com.sun.star.frame.PopupMenuController"/>
</implementation>
+ <implementation name="com.sun.star.comp.framework.SaveAsMenuController"
+ constructor="com_sun_star_comp_framework_SaveAsMenuController_get_implementation">
+ <service name="com.sun.star.frame.PopupMenuController"/>
+ </implementation>
<implementation name="com.sun.star.comp.framework.StatusBarControllerFactory"
constructor="com_sun_star_comp_framework_StatusBarControllerFactory_get_implementation">
<service name="com.sun.star.frame.StatusbarControllerFactory"/>