summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <quikee@gmail.com>2012-06-28 00:19:28 +0200
committerTomaž Vajngerl <quikee@gmail.com>2012-06-28 00:27:47 +0200
commit7a3ae89a12b2c11e90d3f0c76293ddb63203bd2a (patch)
tree0882ad037d36e6d2281d22e8dbffbb635ca7c138 /svx
parente18655e47530f1e399cb546a6001fa0aa0f1873c (diff)
Enable menu option "Edit witn External Tool.." for Calc.
Currently it was only possible to use "Exit with External Tool.." menu option in Writer. Now it is also possible to use this in Calc and in future Draw and Impress. Code has been refactored and extacted out of "sw" into "svx", so other components can use it. Currently there is no cleanup of temporary images after processing was done, and also pinging for changes are still active even when editing in external tool is done. This behavior will be changed in the future. Change-Id: I09969d44dfddbf9183b30ff3fffa2d201c7ae40f
Diffstat (limited to 'svx')
-rw-r--r--svx/Library_svxcore.mk1
-rw-r--r--svx/Package_inc.mk3
-rw-r--r--svx/inc/globlmn_tmpl.hrc5
-rw-r--r--svx/inc/svx/extedit.hxx54
-rw-r--r--svx/inc/svx/svxids.hrc4
-rw-r--r--svx/sdi/svx.sdi25
-rw-r--r--svx/source/core/extedit.cxx170
7 files changed, 258 insertions, 4 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk
index beda9bd52366..8361ec162224 100644
--- a/svx/Library_svxcore.mk
+++ b/svx/Library_svxcore.mk
@@ -92,6 +92,7 @@ $(eval $(call gb_Library_use_external,svxcore,icuuc))
$(eval $(call gb_Library_add_exception_objects,svxcore,\
svx/source/core/coreservices \
+ svx/source/core/extedit \
svx/source/customshapes/EnhancedCustomShape2d \
svx/source/customshapes/EnhancedCustomShapeGeometry \
svx/source/customshapes/EnhancedCustomShapeTypeNames \
diff --git a/svx/Package_inc.mk b/svx/Package_inc.mk
index df90d0fc74cc..b6888d1a12a3 100644
--- a/svx/Package_inc.mk
+++ b/svx/Package_inc.mk
@@ -2,7 +2,7 @@
#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
+#
# Copyright 2000, 2011 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
@@ -553,5 +553,6 @@ $(eval $(call gb_Package_add_file,svx_inc,inc/svx/svxdllapi.h,svx/svxdllapi.h))
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/colrctrl.hxx,svx/colrctrl.hxx))
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/fmdpage.hxx,svx/fmdpage.hxx))
$(eval $(call gb_Package_add_file,svx_inc,inc/svx/sxmtpitm.hxx,svx/sxmtpitm.hxx))
+$(eval $(call gb_Package_add_file,svx_inc,inc/svx/extedit.hxx,svx/extedit.hxx))
# vim: set noet sw=4 ts=4:
diff --git a/svx/inc/globlmn_tmpl.hrc b/svx/inc/globlmn_tmpl.hrc
index f6b8f73b170c..e85bd91398f8 100644
--- a/svx/inc/globlmn_tmpl.hrc
+++ b/svx/inc/globlmn_tmpl.hrc
@@ -257,6 +257,11 @@
Command = ".uno:ImageMapDialog" ; \
Text [ en-US ] = "ImageMap" ; \
+#define ITEM_EXTERNAL_EDIT \
+ Identifier = SID_EXTERNAL_EDIT ; \
+ Command = ".uno:ExternalEdit" ; \
+ Text [ en-US ] = "Edit with External Tool..." ; \
+
#define ITEM_VIEW_ATTR_ZOOM \
Identifier = SID_ATTR_ZOOM ; \
Command = ".uno:Zoom" ; \
diff --git a/svx/inc/svx/extedit.hxx b/svx/inc/svx/extedit.hxx
new file mode 100644
index 000000000000..b286ad825af1
--- /dev/null
+++ b/svx/inc/svx/extedit.hxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * [ Surendran Mahendran <surenspost@gmail.com>]
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+#ifndef _EXTEDIT_HXX
+#define _EXTEDIT_HXX
+
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <vcl/graph.hxx>
+#include <svtools/grfmgr.hxx>
+#include <vcl/timer.hxx>
+#include "svx/svxdllapi.h"
+
+class SVX_DLLPUBLIC ExternalToolEdit
+{
+public:
+ GraphicObject* m_pGraphicObject;
+ rtl::OUString m_aFileName;
+
+ ExternalToolEdit();
+ virtual ~ExternalToolEdit();
+
+ virtual void Update( Graphic& aGraphic ) = 0;
+ void Edit( GraphicObject *pGraphic );
+
+
+ DECL_LINK( StartListeningEvent, void *pEvent );
+
+ static void threadWorker( void *pThreadData );
+ static void HandleCloseEvent( ExternalToolEdit* pData );
+};
+
+
+#endif
diff --git a/svx/inc/svx/svxids.hrc b/svx/inc/svx/svxids.hrc
index fca583186b5f..918d44d60b95 100644
--- a/svx/inc/svx/svxids.hrc
+++ b/svx/inc/svx/svxids.hrc
@@ -955,9 +955,10 @@
#define SID_INSERT_FORM_SPIN (SID_SVX_START+1110)
#define SID_INSERT_FORM_VSCROLL (SID_SVX_START+1111)
#define SID_INSERT_FORM_HSCROLL (SID_SVX_START+1112)
+#define SID_EXTERNAL_EDIT (SID_SVX_START+1113)
// IMPORTANT NOTE: adjust SID_SVX_FIRSTFREE, when adding new slot id
-#define SID_SVX_FIRSTFREE (SID_INSERT_FORM_HSCROLL + 1)
+#define SID_SVX_FIRSTFREE (SID_EXTERNAL_EDIT + 1)
// --------------------------------------------------------------------------
// Overflow check for slot IDs
@@ -970,4 +971,3 @@
#endif // #ifndef _SVX_SVXIDS_HRC
// ******************************************************************* EOF
-
diff --git a/svx/sdi/svx.sdi b/svx/sdi/svx.sdi
index 5e1917576bb6..8b168c8eabde 100644
--- a/svx/sdi/svx.sdi
+++ b/svx/sdi/svx.sdi
@@ -5948,6 +5948,30 @@ SfxBoolItem ImageMapExecute SID_IMAP_EXEC
GroupId = GID_EDIT;
]
+SfxVoidItem ExternalEdit SID_EXTERNAL_EDIT
+
+[
+ /* flags: */
+ AutoUpdate = FALSE,
+ Cachable = Cachable,
+ FastCall = FALSE,
+ HasCoreId = FALSE,
+ HasDialog = FALSE,
+ ReadOnlyDoc = TRUE,
+ Toggle = FALSE,
+ Container = FALSE,
+ RecordAbsolute = FALSE,
+ RecordPerSet;
+ Synchron;
+
+ /* config: */
+ AccelConfig = TRUE,
+ MenuConfig = TRUE,
+ StatusBarConfig = FALSE,
+ ToolBoxConfig = TRUE,
+ GroupId = GID_GRAPHIC;
+]
+
//--------------------------------------------------------------------------
SfxBoolItem Init3D SID_3D_INIT
@@ -15323,4 +15347,3 @@ SfxVoidItem PrepareMailExport SID_MAIL_PREPAREEXPORT
ToolBoxConfig = FALSE,
GroupId = GID_EXPLORER;
]
-
diff --git a/svx/source/core/extedit.cxx b/svx/source/core/extedit.cxx
new file mode 100644
index 000000000000..eddb16acd4b4
--- /dev/null
+++ b/svx/source/core/extedit.cxx
@@ -0,0 +1,170 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (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.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Initial Developer of the Original Code is
+ * [ Surendran Mahendran <surenspost@gmail.com>]
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include <svx/extedit.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/bindings.hxx>
+#include <osl/file.hxx>
+#include <osl/thread.hxx>
+#include <osl/process.h>
+#include <osl/time.h>
+#include <svtools/filter.hxx>
+#include <svtools/filechangedchecker.hxx>
+#include <svx/xoutbmp.hxx>
+#include <unotools/ucbstreamhelper.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/cvtgrf.hxx>
+
+#include "com/sun/star/system/XSystemShellExecute.hpp"
+#include "com/sun/star/system/SystemShellExecuteFlags.hpp"
+#include <comphelper/processfactory.hxx>
+
+#include <boost/bind.hpp>
+
+using namespace ::com::sun::star;
+ExternalToolEdit::ExternalToolEdit()
+{}
+
+ExternalToolEdit::~ExternalToolEdit()
+{}
+
+void ExternalToolEdit::HandleCloseEvent(ExternalToolEdit* pData)
+{
+ Graphic newGraphic;
+
+ //import the temp file image stream into the newGraphic
+ SvStream* pStream = utl::UcbStreamHelper::CreateStream(pData->m_aFileName, STREAM_READ);
+ if(pStream)
+ {
+ GraphicConverter::Import(*pStream, newGraphic);
+
+ // Now update the Graphic in the shell by re-reading from the newGraphic
+ // TODO: Make this action Undoable !
+ //rSh->ReRead(aEmptyStr, aEmptyStr, (const Graphic*) &newGraphic);
+ pData->Update( newGraphic );
+
+ delete(pStream);
+ }
+}
+
+IMPL_LINK (ExternalToolEdit, StartListeningEvent, void*, pEvent)
+{
+ //Start an event listener implemented via VCL timeout
+ ExternalToolEdit* pData = ( ExternalToolEdit* )pEvent;
+ String aURL( pData->m_aFileName );
+
+ new FileChangedChecker(
+ pData->m_aFileName,
+ ::boost::bind(&HandleCloseEvent, pData));
+
+ return 0;
+}
+
+void ExternalToolEdit::threadWorker(void* pThreadData)
+{
+ ExternalToolEdit* pData = (ExternalToolEdit*) pThreadData;
+
+ // Make an asynchronous call to listen to the event of temporary image file
+ // getting changed
+ Application::PostUserEvent( LINK( NULL, ExternalToolEdit, StartListeningEvent ), pThreadData);
+
+ uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
+ ::comphelper::getProcessServiceFactory()->createInstance(
+ DEFINE_CONST_UNICODE("com.sun.star.system.SystemShellExecute") ), uno::UNO_QUERY_THROW );
+ xSystemShellExecute->execute( pData->m_aFileName, rtl::OUString(), com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
+}
+
+
+void GetPreferedExtension( String &rExt, const Graphic &rGrf )
+{
+ // then propose the "best" filter using the native-info, if applicable
+ const sal_Char* pExt = "png";
+ switch( const_cast<Graphic&>(rGrf).GetLink().GetType() )
+ {
+ case GFX_LINK_TYPE_NATIVE_GIF:
+ pExt = "gif";
+ break;
+ case GFX_LINK_TYPE_NATIVE_TIF:
+ pExt = "tif";
+ break;
+ case GFX_LINK_TYPE_NATIVE_WMF:
+ pExt = "wmf";
+ break;
+ case GFX_LINK_TYPE_NATIVE_MET:
+ pExt = "met";
+ break;
+ case GFX_LINK_TYPE_NATIVE_PCT:
+ pExt = "pct";
+ break;
+ case GFX_LINK_TYPE_NATIVE_JPG:
+ pExt = "jpg";
+ break;
+ default:
+ break;
+ }
+ rExt.AssignAscii( pExt );
+}
+
+void ExternalToolEdit::Edit( GraphicObject* pGraphicObject )
+{
+ //Get the graphic from the GraphicObject
+ m_pGraphicObject = pGraphicObject;
+ const Graphic aGraphic = pGraphicObject->GetGraphic();
+
+ //get the Preferred File Extension for this graphic
+ String fExtension;
+ GetPreferedExtension(fExtension, aGraphic);
+
+ //Create the temp File
+ rtl::OUString tempFileBase, tempFileName;
+ oslFileHandle pHandle;
+ osl::FileBase::createTempFile(0, &pHandle, &tempFileBase);
+
+ // Move it to a file name with image extension properly set
+ tempFileName = tempFileBase + rtl::OUString(String('.')) + rtl::OUString(fExtension);
+ osl::File::move(tempFileBase, tempFileName);
+
+ //Write Graphic to the Temp File
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ sal_uInt16 nFilter(rGraphicFilter.GetExportFormatNumber(fExtension));
+ String aFilter(rGraphicFilter.GetExportFormatShortName(nFilter));
+ String sPath(tempFileName);
+
+ // Write the Graphic to the file now
+ XOutBitmap::WriteGraphic(aGraphic, sPath, aFilter, XOUTBMP_USE_NATIVE_IF_POSSIBLE|XOUTBMP_DONT_EXPAND_FILENAME);
+
+ // There is a possiblity that sPath extnesion might have been changed if the
+ // provided extension is not writable
+ tempFileName = rtl::OUString(sPath);
+
+ //Create a thread
+ rtl_uString* aFileName = new rtl_uString();
+ rtl_uString_newFromAscii(
+ &aFileName,
+ rtl::OUStringToOString(tempFileName, RTL_TEXTENCODING_UTF8).getStr());
+ m_aFileName = aFileName;
+ // Create the data that is needed by the thread later
+ osl_createThread(ExternalToolEdit::threadWorker, this);
+}