summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2017-06-27 23:35:08 +0200
committerMarco Cecchetti <mrcekets@gmail.com>2017-08-03 10:58:59 +0200
commiteba883c8a2ce045fc7bd3848d796ca10b7f4ba51 (patch)
treea6a5684a36725e67a24eab86fa984c38252cb2d9 /sw
parent166f13ef65b4a0eb9927eff2ffe5bac319785ee7 (diff)
lok - add support for in place chart editing
This commit add a minimal support for editing chart embedded in a spreadsheet or a text document or a presentation. Graphic objects can be moved and resized, text objects can be edited. Change-Id: I8e637dabf328a94bd6bb0e309a245302cff421d8 Reviewed-on: https://gerrit.libreoffice.org/39342 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Marco Cecchetti <mrcekets@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/unotxdoc.hxx2
-rw-r--r--sw/source/core/view/viewsh.cxx29
-rw-r--r--sw/source/uibase/uno/unotxdoc.cxx89
3 files changed, 117 insertions, 3 deletions
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index ccbfb62589cd..9316b919137e 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -415,6 +415,8 @@ public:
virtual bool isMimeTypeSupported() override;
/// @see vcl::ITiledRenderable::setClientVisibleArea().
virtual void setClientVisibleArea(const tools::Rectangle& rRectangle) override;
+ /// @see vcl::ITiledRenderable::setClientZoom.
+ virtual void setClientZoom(int nTilePixelWidth_, int nTilePixelHeight_, int nTileTwipWidth_, int nTileTwipHeight_) override;
/// @see vcl::ITiledRenderable::getPointer().
virtual Pointer getPointer() override;
/// @see vcl::ITiledRenderable::getTrackedChanges().
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 8a79a0896b60..2a2d46c95c39 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -25,6 +25,7 @@
#include <svx/srchdlg.hxx>
#include <svx/svdobj.hxx>
#include <sfx2/viewsh.hxx>
+#include <sfx2/ipclient.hxx>
#include <drawdoc.hxx>
#include <swwait.hxx>
#include <swmodule.hxx>
@@ -1885,10 +1886,12 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int contextWidth, int contex
rDevice.SetMapMode(aMapMode);
// Update scaling of SwEditWin and its sub-widgets, needed for comments.
+ sal_uInt16 nOldZoomValue = 0;
if (GetWin() && GetWin()->GetMapMode().GetScaleX() != scaleX)
{
double fScale = scaleX;
SwViewOption aOption(*GetViewOptions());
+ nOldZoomValue = aOption.GetZoom();
aOption.SetZoom(fScale * 100);
ApplyViewOptions(aOption);
// Make sure the map mode (disabled in SwXTextDocument::initializeForTiledRendering()) is still disabled.
@@ -1918,6 +1921,32 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int contextWidth, int contex
pPostItMgr->PaintTile(rDevice);
// SwViewShell's output device tear down
+
+ // A view shell can get a PaintTile call for a tile at a zoom level
+ // different from the one, the related client really is.
+ // In such a case it is better to reset the current scale value to
+ // the original one, since such a value should be in synchronous with
+ // the zoom level in the client (see setClientZoom).
+ // At present the zoom value returned by GetViewOptions()->GetZoom() is
+ // used in SwXTextDocument methods (postMouseEvent and setGraphicSelection)
+ // for passing the correct mouse position to an edited chart (if any).
+ if (nOldZoomValue !=0)
+ {
+ SwViewOption aOption(*GetViewOptions());
+ aOption.SetZoom(nOldZoomValue);
+ ApplyViewOptions(aOption);
+
+ // Changing the zoom value doesn't always trigger the updating of
+ // the client ole object area, so we call it directly.
+ SfxInPlaceClient* pIPClient = GetSfxViewShell()->GetIPClient();
+ if (pIPClient)
+ {
+ pIPClient->VisAreaChanged();
+ }
+ // Make sure the map mode (disabled in SwXTextDocument::initializeForTiledRendering()) is still disabled.
+ GetWin()->EnableMapMode(false);
+ }
+
mpOut = pSaveOut;
comphelper::LibreOfficeKit::setTiledPainting(false);
}
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index aca79a13c678..1e2473fdc6f8 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -37,6 +37,8 @@
#include <toolkit/helper/vclunohelper.hxx>
#include <toolkit/awt/vclxdevice.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <sfx2/lokcharthelper.hxx>
+#include <sfx2/ipclient.hxx>
#include <editeng/svxacorr.hxx>
#include <editeng/acorrcfg.hxx>
#include <cmdid.h>
@@ -166,6 +168,8 @@
#include <comphelper/servicehelper.hxx>
#include <memory>
+#define TWIPS_PER_PIXEL 15
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::text;
using namespace ::com::sun::star::i18n;
@@ -3078,6 +3082,9 @@ void SwXTextDocument::paintTile( VirtualDevice &rDevice,
SwViewShell* pViewShell = pDocShell->GetWrtShell();
pViewShell->PaintTile(rDevice, nOutputWidth, nOutputHeight,
nTilePosX, nTilePosY, nTileWidth, nTileHeight);
+
+ LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
+ nTilePosX, nTilePosY, nTileWidth, nTileHeight);
}
Size SwXTextDocument::getDocumentSize()
@@ -3158,6 +3165,34 @@ void SwXTextDocument::setClientVisibleArea(const tools::Rectangle& rRectangle)
pView->ForcePageUpDownOffset(2 * rRectangle.GetHeight() / 3);
}
+void SwXTextDocument::setClientZoom(int nTilePixelWidth_, int /*nTilePixelHeight_*/,
+ int nTileTwipWidth_, int /*nTileTwipHeight_*/)
+{
+ // Here we set the zoom value as it has been set by the user in the client.
+ // This value is used in postMouseEvent and setGraphicSelection methods
+ // for in place chart editing. We assume that x and y scale is rougly
+ // the same.
+ // Indeed we could set mnTilePixelWidth, mnTilePixelHeight, mnTileTwipWidth,
+ // mnTileTwipHeight data members of this class but they are not very useful
+ // since we need to be able to retrieve the zoom value for each view shell.
+ SfxInPlaceClient* pIPClient = pDocShell->GetView()->GetIPClient();
+ if (pIPClient)
+ {
+ SwViewShell* pWrtViewShell = pDocShell->GetWrtShell();
+ double fScale = nTilePixelWidth_ * TWIPS_PER_PIXEL / (nTileTwipWidth_ * 1.0);
+ SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
+ if (aOption.GetZoom() != fScale * 100)
+ {
+ aOption.SetZoom(fScale * 100);
+ pWrtViewShell->ApplyViewOptions(aOption);
+
+ // Changing the zoom value doesn't always trigger the updating of
+ // the client ole object area, so we call it directly.
+ pIPClient->VisAreaChanged();
+ }
+ }
+}
+
Pointer SwXTextDocument::getPointer()
{
SolarMutexGuard aGuard;
@@ -3322,6 +3357,11 @@ void SwXTextDocument::initializeForTiledRendering(const css::uno::Sequence<css::
}
}
+ // Set the initial zoom value to 1; usually it is set in setClientZoom and
+ // SwViewShell::PaintTile; zoom value is used for chart in place
+ // editing, see postMouseEvent and setGraphicSelection methods.
+ aViewOption.SetZoom(1 * 100);
+
aViewOption.SetPostIts(comphelper::LibreOfficeKit::isTiledAnnotations());
pViewShell->ApplyViewOptions(aViewOption);
@@ -3354,16 +3394,25 @@ void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
{
SolarMutexGuard aGuard;
- SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
+ vcl::Window* pWindow = &(pDocShell->GetView()->GetEditWin());
+
+ SfxViewShell* pViewShell = pDocShell->GetView();
+ LokChartHelper aChartHelper(pViewShell);
+ vcl::Window* pChartWindow = aChartHelper.GetWindow();
+ if (pChartWindow)
+ {
+ pWindow = pChartWindow;
+ }
+
KeyEvent aEvent(nCharCode, nKeyCode, 0);
switch (nType)
{
case LOK_KEYEVENT_KEYINPUT:
- rEditWin.KeyInput(aEvent);
+ pWindow->KeyInput(aEvent);
break;
case LOK_KEYEVENT_KEYUP:
- rEditWin.KeyUp(aEvent);
+ pWindow->KeyUp(aEvent);
break;
default:
assert(false);
@@ -3375,6 +3424,26 @@ void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int
{
SolarMutexGuard aGuard;
+ SwViewShell* pWrtViewShell = pDocShell->GetWrtShell();
+ SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
+ double fScale = aOption.GetZoom() / (TWIPS_PER_PIXEL * 100.0);
+
+ // check if user hit a chart which is being edited by him
+ SfxViewShell* pViewShell = pDocShell->GetView();
+ LokChartHelper aChartHelper(pViewShell);
+ if (aChartHelper.postMouseEvent(nType, nX, nY,
+ nCount, nButtons, nModifier,
+ fScale, fScale))
+ return;
+
+ // check if the user hit a chart which is being edited by someone else
+ // and, if so, skip current mouse event
+ if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
+ {
+ if (LokChartHelper::HitAny(Point(nX, nY)))
+ return;
+ }
+
SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
Point aPos(nX , nY);
MouseEvent aEvent(aPos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier);
@@ -3406,6 +3475,11 @@ void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
{
SolarMutexGuard aGuard;
+ SfxViewShell* pViewShell = pDocShell->GetView();
+ LokChartHelper aChartHelper(pViewShell);
+ if (aChartHelper.setTextSelection(nType, nX, nY))
+ return;
+
SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
switch (nType)
{
@@ -3504,6 +3578,15 @@ void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
{
SolarMutexGuard aGuard;
+ SwViewShell* pWrtViewShell = pDocShell->GetWrtShell();
+ SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
+ double fScale = aOption.GetZoom() / (TWIPS_PER_PIXEL * 100.0);
+
+ SfxViewShell* pViewShell = pDocShell->GetView();
+ LokChartHelper aChartHelper(pViewShell);
+ if (aChartHelper.setGraphicSelection(nType, nX, nY, fScale, fScale))
+ return;
+
SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
switch (nType)
{