diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2017-06-27 23:35:08 +0200 |
---|---|---|
committer | Marco Cecchetti <mrcekets@gmail.com> | 2017-08-03 10:58:59 +0200 |
commit | eba883c8a2ce045fc7bd3848d796ca10b7f4ba51 (patch) | |
tree | a6a5684a36725e67a24eab86fa984c38252cb2d9 /chart2/source/controller/main/ChartWindow.cxx | |
parent | xmlsecurity: remove unused XMLEncryption_MSCryptImpl (diff) | |
download | core-eba883c8a2ce045fc7bd3848d796ca10b7f4ba51.tar.gz core-eba883c8a2ce045fc7bd3848d796ca10b7f4ba51.zip |
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 'chart2/source/controller/main/ChartWindow.cxx')
-rw-r--r-- | chart2/source/controller/main/ChartWindow.cxx | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/chart2/source/controller/main/ChartWindow.cxx b/chart2/source/controller/main/ChartWindow.cxx index b03f10164b17..717704fcda27 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(); } @@ -108,6 +117,10 @@ void ChartWindow::PrePaint(vcl::RenderContext& ) void ChartWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) { + if (comphelper::LibreOfficeKit::isActive() + && rRenderContext.GetOutDevType() != OutDevType::OUTDEV_VIRDEV) + return; + m_bInPaint = true; if (m_pOpenGLWindow && m_pOpenGLWindow->IsVisible()) { @@ -301,6 +314,56 @@ void ChartWindow::Invalidate( const vcl::Region& rRegion, InvalidateFlags nFlags } } +void ChartWindow::LogicInvalidate(const tools::Rectangle* pRectangle) +{ + OString sRectangle; + if (!pRectangle) + { + // we have to invalidate the whole chart area not the whole document + sRectangle = GetBoundingBox().toString(); + } + else + { + tools::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 = tools::Rectangle(aRectangle.TopLeft() + aOffset, aRectangle.GetSize()); + } + + sRectangle = aRectangle.toString(); + } + SfxViewShell* pCurrentShell = SfxViewShell::Current(); + SfxLokHelper::notifyInvalidation(pCurrentShell, sRectangle); +} + FactoryFunction ChartWindow::GetUITestFactory() const { return ChartWindowUIObject::create; @@ -311,6 +374,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; +} + +tools::Rectangle ChartWindow::GetBoundingBox() +{ + tools::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 = tools::Rectangle(aOffset, aSize); + } + return aBBox; +} + } //namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |