summaryrefslogtreecommitdiff
path: root/chart2
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2017-06-27 23:35:08 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-08-03 12:32:51 +0200
commit0d3a367b5623639e7fdc9ce1ccc277e2597694a0 (patch)
treebd69a33834b9d85fd738c550015461453da5f16f /chart2
parent9a5c39ea56bbac48f30a1a4966caa68697d8b318 (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 object can be moved and resized, text object can be edited. Change-Id: I8e637dabf328a94bd6bb0e309a245302cff421d8 Reviewed-on: https://gerrit.libreoffice.org/40681 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'chart2')
-rw-r--r--chart2/source/controller/inc/ChartController.hxx2
-rw-r--r--chart2/source/controller/inc/ChartWindow.hxx9
-rw-r--r--chart2/source/controller/main/ChartController.cxx15
-rw-r--r--chart2/source/controller/main/ChartController_Tools.cxx35
-rw-r--r--chart2/source/controller/main/ChartController_Window.cxx5
-rw-r--r--chart2/source/controller/main/ChartWindow.cxx110
6 files changed, 174 insertions, 2 deletions
diff --git a/chart2/source/controller/inc/ChartController.hxx b/chart2/source/controller/inc/ChartController.hxx
index 3b3449170eec..7b5b7882e99b 100644
--- a/chart2/source/controller/inc/ChartController.hxx
+++ b/chart2/source/controller/inc/ChartController.hxx
@@ -546,6 +546,8 @@ private:
void executeDispatch_ToggleGridHorizontal();
void executeDispatch_ToggleGridVertical();
+ void executeDispatch_LOKSetTextSelection(int nType, int nX, int nY);
+
void impl_ShapeControllerDispatch( const css::util::URL& rURL,
const css::uno::Sequence< css::beans::PropertyValue >& rArgs );
diff --git a/chart2/source/controller/inc/ChartWindow.hxx b/chart2/source/controller/inc/ChartWindow.hxx
index 6b0feaf440da..7883794a02bf 100644
--- a/chart2/source/controller/inc/ChartWindow.hxx
+++ b/chart2/source/controller/inc/ChartWindow.hxx
@@ -62,6 +62,7 @@ public:
virtual void Invalidate( InvalidateFlags nFlags = InvalidateFlags::NONE ) override;
virtual void Invalidate( const Rectangle& rRect, InvalidateFlags nFlags = InvalidateFlags::NONE ) override;
virtual void Invalidate( const vcl::Region& rRegion, InvalidateFlags nFlags = InvalidateFlags::NONE ) override;
+ virtual void LogicInvalidate( const Rectangle* pRectangle ) override;
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
@@ -69,9 +70,17 @@ public:
ChartController* GetController();
+ virtual bool IsChart() const override { return true; }
+ vcl::Window* GetParentEditWin();
+
+private:
+ // returns the chart bounding box in twips
+ Rectangle GetBoundingBox();
+
private:
ChartController* m_pWindowController;
bool m_bInPaint;
+ VclPtr<vcl::Window> m_pViewShellWindow;
VclPtr<OpenGLWindow> m_pOpenGLWindow;
void adjustHighContrastMode();
diff --git a/chart2/source/controller/main/ChartController.cxx b/chart2/source/controller/main/ChartController.cxx
index d40782f48920..ee622de47b69 100644
--- a/chart2/source/controller/main/ChartController.cxx
+++ b/chart2/source/controller/main/ChartController.cxx
@@ -1137,7 +1137,20 @@ void SAL_CALL ChartController::dispatch(
{
OUString aCommand = rURL.Path;
- if(aCommand == "Paste")
+ if(aCommand == "LOKSetTextSelection")
+ {
+ if (rArgs.getLength() == 3)
+ {
+ sal_Int32 nType = -1;
+ rArgs[0].Value >>= nType;
+ sal_Int32 nX = 0;
+ rArgs[1].Value >>= nX;
+ sal_Int32 nY = 0;
+ rArgs[2].Value >>= nY;
+ executeDispatch_LOKSetTextSelection(nType, nX, nY);
+ }
+ }
+ else if(aCommand == "Paste")
this->executeDispatch_Paste();
else if(aCommand == "Copy" )
this->executeDispatch_Copy();
diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx
index 6ec875364fda..c06234ef7a0b 100644
--- a/chart2/source/controller/main/ChartController_Tools.cxx
+++ b/chart2/source/controller/main/ChartController_Tools.cxx
@@ -52,6 +52,8 @@
#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
#include <com/sun/star/chart/ErrorBarStyle.hpp>
+#include <editeng/editview.hxx>
+#include <editeng/outliner.hxx>
#include <svx/ActionDescriptionProvider.hxx>
#include <svtools/transfer.hxx>
#include <sot/storage.hxx>
@@ -70,6 +72,8 @@
#include <svx/unoapi.hxx>
#include <svx/unopage.hxx>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
+
#include <memory>
using namespace ::com::sun::star;
@@ -927,6 +931,37 @@ void ChartController::executeDispatch_ToggleGridVertical()
}
}
+void ChartController::executeDispatch_LOKSetTextSelection(int nType, int nX, int nY)
+{
+ if (m_pDrawViewWrapper)
+ {
+ if (m_pDrawViewWrapper->IsTextEdit())
+ {
+ OutlinerView* pOutlinerView = m_pDrawViewWrapper->GetTextEditOutlinerView();
+ if (pOutlinerView)
+ {
+ EditView& rEditView = pOutlinerView->GetEditView();
+ Point aPoint(convertTwipToMm100(nX), convertTwipToMm100(nY));
+ switch (nType)
+ {
+ case LOK_SETTEXTSELECTION_START:
+ rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/false, /*bClearMark=*/false);
+ break;
+ case LOK_SETTEXTSELECTION_END:
+ rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/false);
+ break;
+ case LOK_SETTEXTSELECTION_RESET:
+ rEditView.SetCursorLogicPosition(aPoint, /*bPoint=*/true, /*bClearMark=*/true);
+ break;
+ default:
+ assert(false);
+ break;
+ }
+ }
+ }
+ }
+}
+
void ChartController::impl_ShapeControllerDispatch( const util::URL& rURL, const Sequence< beans::PropertyValue >& rArgs )
{
Reference< frame::XDispatch > xDispatch( m_aDispatchContainer.getShapeController() );
diff --git a/chart2/source/controller/main/ChartController_Window.cxx b/chart2/source/controller/main/ChartController_Window.cxx
index 4e7a7912165d..2989e32d4faa 100644
--- a/chart2/source/controller/main/ChartController_Window.cxx
+++ b/chart2/source/controller/main/ChartController_Window.cxx
@@ -866,7 +866,10 @@ void ChartController::execute_MouseButtonUp( const MouseEvent& rMEvt )
else
m_aSelection.resetPossibleSelectionAfterSingleClickWasEnsured();
}
- else if( isDoubleClick(rMEvt) && !bMouseUpWithoutMouseDown /*#i106966#*/ )
+ // In tiled rendering drag mode could be not yet over on the call
+ // that should handle the double-click, so better to perform this check
+ // always.
+ if( isDoubleClick(rMEvt) && !bMouseUpWithoutMouseDown /*#i106966#*/ )
{
Point aMousePixel = rMEvt.GetPosPixel();
execute_DoubleClick( &aMousePixel );
diff --git a/chart2/source/controller/main/ChartWindow.cxx b/chart2/source/controller/main/ChartWindow.cxx
index 21cc0cefc2ab..d50a741cd001 100644
--- a/chart2/source/controller/main/ChartWindow.cxx
+++ b/chart2/source/controller/main/ChartWindow.cxx
@@ -28,6 +28,13 @@
#include <config_features.h>
#include <com/sun/star/chart2/X3DChartWindowProvider.hpp>
+#include <sfx2/ipclient.hxx>
+#include <sfx2/viewsh.hxx>
+#include <sfx2/lokhelper.hxx>
+#include <comphelper/lok.hxx>
+
+#define TWIPS_PER_PIXEL 15
+
using namespace ::com::sun::star;
namespace
@@ -50,6 +57,7 @@ ChartWindow::ChartWindow( ChartController* pController, vcl::Window* pParent, Wi
: Window(pParent, nStyle)
, m_pWindowController( pController )
, m_bInPaint(false)
+ , m_pViewShellWindow( nullptr )
#if HAVE_FEATURE_OPENGL
, m_pOpenGLWindow(VclPtr<OpenGLWindow>::Create(this, false))
#else
@@ -94,6 +102,7 @@ void ChartWindow::dispose()
xUpdatable->update();
}
m_pOpenGLWindow.disposeAndClear();
+ m_pViewShellWindow.clear();
vcl::Window::dispose();
}
@@ -114,6 +123,10 @@ void ChartWindow::PrePaint(vcl::RenderContext& rRenderContext)
void ChartWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
{
+ if (comphelper::LibreOfficeKit::isActive()
+ && rRenderContext.GetOutDevType() != OutDevType::OUTDEV_VIRDEV)
+ return;
+
m_bInPaint = true;
if (m_pOpenGLWindow && m_pOpenGLWindow->IsVisible())
{
@@ -307,6 +320,56 @@ void ChartWindow::Invalidate( const vcl::Region& rRegion, InvalidateFlags nFlags
}
}
+void ChartWindow::LogicInvalidate(const Rectangle* pRectangle)
+{
+ OString sRectangle;
+ if (!pRectangle)
+ {
+ // we have to invalidate the whole chart area not the whole document
+ sRectangle = GetBoundingBox().toString();
+ }
+ else
+ {
+ Rectangle aRectangle(*pRectangle);
+ // When dragging shapes the map mode is disabled.
+ if (IsMapModeEnabled())
+ {
+ if (GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
+ aRectangle = OutputDevice::LogicToLogic(aRectangle, MapUnit::Map100thMM, MapUnit::MapTwip);
+ }
+ else
+ {
+ aRectangle = PixelToLogic(aRectangle, MapMode(MapUnit::MapTwip));
+ }
+
+ vcl::Window* pEditWin = GetParentEditWin();
+ if (pEditWin)
+ {
+ MapMode aCWMapMode = GetMapMode();
+ double fXScale = aCWMapMode.GetScaleX();
+ double fYScale = aCWMapMode.GetScaleY();
+
+ if (!IsMapModeEnabled())
+ {
+ aRectangle.Left() /= fXScale;
+ aRectangle.Right() /= fXScale;
+ aRectangle.Top() /= fYScale;
+ aRectangle.Bottom() /= fYScale;
+ }
+
+ Point aOffset = this->GetOffsetPixelFrom(*pEditWin);
+ aOffset.X() *= (TWIPS_PER_PIXEL / fXScale);
+ aOffset.Y() *= (TWIPS_PER_PIXEL / fYScale);
+
+ aRectangle = Rectangle(aRectangle.TopLeft() + aOffset, aRectangle.GetSize());
+ }
+
+ sRectangle = aRectangle.toString();
+ }
+ SfxViewShell* pCurrentShell = SfxViewShell::Current();
+ SfxLokHelper::notifyInvalidation(pCurrentShell, sRectangle);
+}
+
FactoryFunction ChartWindow::GetUITestFactory() const
{
return ChartWindowUIObject::create;
@@ -317,6 +380,53 @@ ChartController* ChartWindow::GetController()
return m_pWindowController;
}
+vcl::Window* ChartWindow::GetParentEditWin()
+{
+ if (m_pViewShellWindow)
+ return m_pViewShellWindow.get();
+
+ // So, you are thinking, why do not invoke pCurrentShell->GetWindow() ?
+ // Because in Impress the parent edit win is not view shell window.
+ SfxViewShell* pCurrentShell = SfxViewShell::Current();
+ if( pCurrentShell )
+ {
+ SfxInPlaceClient* pIPClient = pCurrentShell->GetIPClient();
+ if (pIPClient)
+ {
+ vcl::Window* pRootWin = pIPClient->GetEditWin();
+ if(pRootWin && pRootWin->IsAncestorOf(*this))
+ {
+ m_pViewShellWindow = pRootWin;
+ return m_pViewShellWindow.get();
+ }
+ }
+ }
+ return nullptr;
+}
+
+Rectangle ChartWindow::GetBoundingBox()
+{
+ Rectangle aBBox;
+
+ vcl::Window* pRootWin = GetParentEditWin();
+ if (pRootWin)
+ {
+ // In all cases, the following code fragment
+ // returns the chart bounding box in twips.
+ MapMode aCWMapMode = GetMapMode();
+ double fXScale = aCWMapMode.GetScaleX();
+ double fYScale = aCWMapMode.GetScaleY();
+ Point aOffset = GetOffsetPixelFrom(*pRootWin);
+ aOffset.X() *= (TWIPS_PER_PIXEL / fXScale);
+ aOffset.Y() *= (TWIPS_PER_PIXEL / fYScale);
+ Size aSize = GetSizePixel();
+ aSize.Width() *= (TWIPS_PER_PIXEL / fXScale);
+ aSize.Height() *= (TWIPS_PER_PIXEL / fYScale);
+ aBBox = Rectangle(aOffset, aSize);
+ }
+ return aBBox;
+}
+
} //namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */