include/vcl/GestureEvent.hxx | 42 ++++++ include/vcl/commandevent.hxx | 24 +++ include/vcl/svapp.hxx | 3 include/vcl/vclevent.hxx | 1 vcl/inc/salwtype.hxx | 14 +- vcl/inc/widgetdraw/WidgetDefinition.hxx | 66 ++++------ vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx | 13 + vcl/qa/cppunit/widgetdraw/data/definition1.xml | 8 - vcl/source/app/svapp.cxx | 68 +++++++++- vcl/source/gdi/FileDefinitionWidgetDraw.cxx | 99 ++++++--------- vcl/source/gdi/WidgetDefinition.cxx | 31 +--- vcl/source/gdi/WidgetDefinitionReader.cxx | 25 --- vcl/source/window/commandevent.cxx | 9 + vcl/source/window/winproc.cxx | 44 ++++++ 14 files changed, 284 insertions(+), 163 deletions(-)
New commits: commit 6b476080da0678faa59606ef814760bd4235de24 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Mon Mar 25 18:05:35 2019 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Mar 26 01:30:45 2019 +0100 tdf#124146 add (general) gesture event support to VCL Change-Id: I766930bb35071442e132b91477cd3d55e8f00f48 Reviewed-on: https://gerrit.libreoffice.org/69655 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/vcl/GestureEvent.hxx b/include/vcl/GestureEvent.hxx new file mode 100644 index 000000000000..2070fc76d39a --- /dev/null +++ b/include/vcl/GestureEvent.hxx @@ -0,0 +1,42 @@ +/* -*- 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/. + * + */ + +#ifndef INCLUDED_VCL_GESTUREEVENT_HXX +#define INCLUDED_VCL_GESTUREEVENT_HXX + +#include <vcl/dllapi.h> + +enum class GestureEventType +{ + PanningBegin, + PanningUpdate, + PanningEnd +}; + +enum class PanningOrientation +{ + Horizontal, + Vertical +}; + +class VCL_DLLPUBLIC GestureEvent +{ +public: + sal_Int32 mnX; + sal_Int32 mnY; + GestureEventType meEventType; + + sal_Int32 mnOffset; + PanningOrientation meOrientation; +}; + +#endif // INCLUDED_VCL_GESTUREEVENT_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/commandevent.hxx b/include/vcl/commandevent.hxx index 88185efde077..a3ee2fb73c99 100644 --- a/include/vcl/commandevent.hxx +++ b/include/vcl/commandevent.hxx @@ -27,6 +27,7 @@ #include <vcl/keycodes.hxx> #include <o3tl/typed_flags_set.hxx> #include <rtl/ustring.hxx> +#include <vcl/GestureEvent.hxx> class CommandExtTextInputData; class CommandWheelData; @@ -37,6 +38,8 @@ class CommandMediaData; class CommandSelectionChangeData; class CommandSwipeData; class CommandLongPressData; +class CommandGestureData; + enum class CommandEventId; enum class ExtTextInputAttr { @@ -86,6 +89,7 @@ public: const CommandSelectionChangeData* GetSelectionChangeData() const; const CommandSwipeData* GetSwipeData() const; const CommandLongPressData* GetLongPressData() const; + const CommandGestureData* GetGestureData() const; }; class VCL_DLLPUBLIC CommandExtTextInputData @@ -300,6 +304,25 @@ public: double getY() const { return mnY; } }; +class VCL_DLLPUBLIC CommandGestureData +{ +public: + double const mfX; + double const mfY; + GestureEventType const meEventType; + + double const mfOffset; + PanningOrientation const meOrientation; + + CommandGestureData(double fX, double fY, GestureEventType eEventType, double fOffset, PanningOrientation eOrientation) + : mfX(fX) + , mfY(fY) + , meEventType(eEventType) + , mfOffset(fOffset) + , meOrientation(eOrientation) + {} +}; + enum class CommandEventId { NONE = 0, @@ -323,6 +346,7 @@ enum class CommandEventId QueryCharPosition = 20, Swipe = 21, LongPress = 22, + Gesture = 23, }; #endif // INCLUDED_VCL_COMMANDEVENT_HXX diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx index 712f75a0f09d..d89a23e54a13 100644 --- a/include/vcl/svapp.hxx +++ b/include/vcl/svapp.hxx @@ -63,6 +63,7 @@ class WorkWindow; class NotifyEvent; class KeyEvent; class MouseEvent; +class GestureEvent; struct ImplSVEvent; struct ConvertData; @@ -747,6 +748,8 @@ public: */ static ImplSVEvent * PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent ); + static ImplSVEvent* PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent); + /** Remove mouse and keypress events from a window... any also zoom and scroll events if the platform supports it. diff --git a/include/vcl/vclevent.hxx b/include/vcl/vclevent.hxx index 26cf1a681c2b..4ba071715b6a 100644 --- a/include/vcl/vclevent.hxx +++ b/include/vcl/vclevent.hxx @@ -170,6 +170,7 @@ enum class VclEventId WindowShow, WindowStartDocking, // pData = DockingData WindowToggleFloating, + WindowGestureEvent, }; class VCL_DLLPUBLIC VclSimpleEvent diff --git a/vcl/inc/salwtype.hxx b/vcl/inc/salwtype.hxx index 4fab141bbca3..3585c018ba52 100644 --- a/vcl/inc/salwtype.hxx +++ b/vcl/inc/salwtype.hxx @@ -24,6 +24,7 @@ #include <rtl/ref.hxx> #include <rtl/ustring.hxx> #include <tools/solar.h> +#include <vcl/GestureEvent.hxx> class LogicalFontInstance; class SalGraphics; @@ -82,7 +83,9 @@ enum class SalEvent { StartReconversion, QueryCharPosition, Swipe, - LongPress + LongPress, + ExternalGesture, + Gesture, }; // MOUSELEAVE must send, when the pointer leave the client area and @@ -255,6 +258,15 @@ struct SalLongPressEvent long mnY; }; +struct SalGestureEvent +{ + GestureEventType meEventType; + PanningOrientation meOrientation; + double mfOffset; + long mnX; + long mnY; +}; + typedef void (*SALTIMERPROC)(); #endif // INCLUDED_VCL_INC_SALWTYPE_HXX diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx index c3f3b07827f0..ca29108bc37e 100644 --- a/vcl/source/app/svapp.cxx +++ b/vcl/source/app/svapp.cxx @@ -133,11 +133,26 @@ struct ImplPostEventData ImplSVEvent * mnEventId; KeyEvent maKeyEvent; MouseEvent maMouseEvent; - - ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const KeyEvent& rKeyEvent ) : - mnEvent( nEvent ), mpWin( pWin ), mnEventId( nullptr ), maKeyEvent( rKeyEvent ) {} - ImplPostEventData( VclEventId nEvent, vcl::Window* pWin, const MouseEvent& rMouseEvent ) : - mnEvent( nEvent ), mpWin( pWin ), mnEventId( nullptr ), maMouseEvent( rMouseEvent ) {} + GestureEvent maGestureEvent; + + ImplPostEventData(VclEventId nEvent, vcl::Window* pWin, const KeyEvent& rKeyEvent) + : mnEvent(nEvent) + , mpWin(pWin) + , mnEventId(nullptr) + , maKeyEvent(rKeyEvent) + {} + ImplPostEventData(VclEventId nEvent, vcl::Window* pWin, const MouseEvent& rMouseEvent) + : mnEvent(nEvent) + , mpWin(pWin) + , mnEventId(nullptr) + , maMouseEvent(rMouseEvent) + {} + ImplPostEventData(VclEventId nEvent, vcl::Window* pWin, const GestureEvent& rGestureEvent) + : mnEvent(nEvent) + , mpWin(pWin) + , mnEventId(nullptr) + , maGestureEvent(rGestureEvent) + {} }; Application* GetpApp() @@ -829,7 +844,43 @@ ImplSVEvent * Application::PostKeyEvent( VclEventId nEvent, vcl::Window *pWin, K return nEventId; } -ImplSVEvent * Application::PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent ) +ImplSVEvent* Application::PostGestureEvent(VclEventId nEvent, vcl::Window* pWin, GestureEvent const * pGestureEvent) +{ + const SolarMutexGuard aGuard; + ImplSVEvent * nEventId = nullptr; + + if (pWin && pGestureEvent) + { + Point aTransformedPosition(pGestureEvent->mnX, pGestureEvent->mnY); + + aTransformedPosition.AdjustX(pWin->GetOutOffXPixel()); + aTransformedPosition.AdjustY(pWin->GetOutOffYPixel()); + + const GestureEvent aGestureEvent{ + sal_Int32(aTransformedPosition.X()), + sal_Int32(aTransformedPosition.Y()), + pGestureEvent->meEventType, + pGestureEvent->mnOffset, + pGestureEvent->meOrientation + }; + + std::unique_ptr<ImplPostEventData> pPostEventData(new ImplPostEventData(nEvent, pWin, aGestureEvent)); + + nEventId = PostUserEvent( + LINK( nullptr, Application, PostEventHandler ), + pPostEventData.get()); + + if (nEventId) + { + pPostEventData->mnEventId = nEventId; + ImplGetSVData()->maAppData.maPostedEventList.emplace_back(pWin, pPostEventData.release()); + } + } + + return nEventId; +} + +ImplSVEvent* Application::PostMouseEvent( VclEventId nEvent, vcl::Window *pWin, MouseEvent const * pMouseEvent ) { const SolarMutexGuard aGuard; ImplSVEvent * nEventId = nullptr; @@ -896,6 +947,11 @@ IMPL_STATIC_LINK( Application, PostEventHandler, void*, pCallData, void ) pEventData = &pData->maKeyEvent; break; + case VclEventId::WindowGestureEvent: + nEvent = SalEvent::ExternalGesture; + pEventData = &pData->maGestureEvent; + break; + default: nEvent = SalEvent::NONE; pEventData = nullptr; diff --git a/vcl/source/window/commandevent.cxx b/vcl/source/window/commandevent.cxx index c8b486e7fc59..06e974c9fc6a 100644 --- a/vcl/source/window/commandevent.cxx +++ b/vcl/source/window/commandevent.cxx @@ -186,4 +186,13 @@ const CommandLongPressData* CommandEvent::GetLongPressData() const return nullptr; } +const CommandGestureData* CommandEvent::GetGestureData() const +{ + if (mnCommand == CommandEventId::Gesture) + return static_cast<const CommandGestureData*>(mpData); + else + return nullptr; +} + + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index b0e1ea918115..3ebcc2650d4a 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -28,6 +28,7 @@ #include <vcl/unohelp.hxx> #include <vcl/timer.hxx> #include <vcl/event.hxx> +#include <vcl/GestureEvent.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <vcl/cursor.hxx> @@ -1550,6 +1551,30 @@ static bool ImplHandleLongPress(vcl::Window *pWindow, const SalLongPressEvent& r return aHandler.HandleEvent(); } +class HandleGeneralGestureEvent : public HandleGestureEvent +{ +private: + CommandGestureData m_aGestureData; + +public: + HandleGeneralGestureEvent(vcl::Window* pWindow, const SalGestureEvent& rEvent) + : HandleGestureEvent(pWindow, Point(rEvent.mnX, rEvent.mnY)) + , m_aGestureData(rEvent.mnX, rEvent.mnY, rEvent.meEventType, rEvent.mfOffset, rEvent.meOrientation) + { + } + + virtual bool CallCommand(vcl::Window* pWindow, const Point& /*rMousePos*/) override + { + return ImplCallCommand(pWindow, CommandEventId::Gesture, &m_aGestureData); + } +}; + +static bool ImplHandleGestureEvent(vcl::Window* pWindow, const SalGestureEvent& rEvent) +{ + HandleGeneralGestureEvent aHandler(pWindow, rEvent); + return aHandler.HandleEvent(); +} + static void ImplHandlePaint( vcl::Window* pWindow, const tools::Rectangle& rBoundRect, bool bImmediateUpdate ) { // system paint events must be checked for re-mirroring @@ -2537,7 +2562,26 @@ bool ImplWindowFrameProc( vcl::Window* _pWindow, SalEvent nEvent, const void* pE bRet = ImplHandleLongPress(pWindow, *static_cast<const SalLongPressEvent*>(pEvent)); break; + case SalEvent::ExternalGesture: + { + auto const * pGestureEvent = static_cast<GestureEvent const *>(pEvent); + + SalGestureEvent aSalGestureEvent; + aSalGestureEvent.mfOffset = pGestureEvent->mnOffset; + aSalGestureEvent.mnX = pGestureEvent->mnX; + aSalGestureEvent.mnY = pGestureEvent->mnY; + aSalGestureEvent.meEventType = pGestureEvent->meEventType; + aSalGestureEvent.meOrientation = pGestureEvent->meOrientation; + bRet = ImplHandleGestureEvent(pWindow, aSalGestureEvent); + } + break; + case SalEvent::Gesture: + { + auto const * aSalGestureEvent = static_cast<SalGestureEvent const *>(pEvent); + bRet = ImplHandleGestureEvent(pWindow, *aSalGestureEvent); + } + break; default: SAL_WARN( "vcl.layout", "ImplWindowFrameProc(): unknown event (" << static_cast<int>(nEvent) << ")" ); break; commit d3922a93a096e07ab54e91fd0dd7c86302f33b78 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Fri Mar 22 10:16:39 2019 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Mar 26 01:30:31 2019 +0100 Rename DrawCommand* to WidgetDrawAction*, remove unused circ draw Change-Id: Icef900e75255d477812a198fdb29e0cdebba35b8 Reviewed-on: https://gerrit.libreoffice.org/69654 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/inc/widgetdraw/WidgetDefinition.hxx b/vcl/inc/widgetdraw/WidgetDefinition.hxx index 77baf0922cd8..d5f5b3728abd 100644 --- a/vcl/inc/widgetdraw/WidgetDefinition.hxx +++ b/vcl/inc/widgetdraw/WidgetDefinition.hxx @@ -24,32 +24,40 @@ namespace vcl { -enum class DrawCommandType +enum class WidgetDrawActionType { RECTANGLE, - CIRCLE, LINE, IMAGE, EXTERNAL }; -class VCL_DLLPUBLIC DrawCommand +class VCL_DLLPUBLIC WidgetDrawAction { public: - DrawCommand(DrawCommandType aType) + WidgetDrawAction(WidgetDrawActionType aType) : maType(aType) - , mnStrokeWidth(-1) { } - DrawCommandType maType; + WidgetDrawActionType maType; +}; + +class VCL_DLLPUBLIC WidgetDrawActionShape : public WidgetDrawAction +{ +public: + WidgetDrawActionShape(WidgetDrawActionType aType) + : WidgetDrawAction(aType) + , mnStrokeWidth(-1) + { + } Color maStrokeColor; Color maFillColor; sal_Int32 mnStrokeWidth; }; -class VCL_DLLPUBLIC RectangleDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionRectangle : public WidgetDrawActionShape { public: sal_Int32 mnRx; @@ -60,8 +68,8 @@ public: float mfX2; float mfY2; - RectangleDrawCommand() - : DrawCommand(DrawCommandType::RECTANGLE) + WidgetDrawActionRectangle() + : WidgetDrawActionShape(WidgetDrawActionType::RECTANGLE) , mnRx(0) , mnRy(0) , mfX1(0.0f) @@ -72,25 +80,7 @@ public: } }; -class VCL_DLLPUBLIC CircleDrawCommand : public DrawCommand -{ -public: - float mfX1; - float mfY1; - float mfX2; - float mfY2; - - CircleDrawCommand() - : DrawCommand(DrawCommandType::CIRCLE) - , mfX1(0.0f) - , mfY1(0.0f) - , mfX2(1.0f) - , mfY2(1.0f) - { - } -}; - -class VCL_DLLPUBLIC LineDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionLine : public WidgetDrawActionShape { public: float mfX1; @@ -98,30 +88,30 @@ public: float mfX2; float mfY2; - LineDrawCommand() - : DrawCommand(DrawCommandType::LINE) + WidgetDrawActionLine() + : WidgetDrawActionShape(WidgetDrawActionType::LINE) { } }; -class VCL_DLLPUBLIC ImageDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionImage : public WidgetDrawAction { public: OUString msSource; - ImageDrawCommand() - : DrawCommand(DrawCommandType::IMAGE) + WidgetDrawActionImage() + : WidgetDrawAction(WidgetDrawActionType::IMAGE) { } }; -class VCL_DLLPUBLIC ExternalSourceDrawCommand : public DrawCommand +class VCL_DLLPUBLIC WidgetDrawActionExternal : public WidgetDrawAction { public: OUString msSource; - ExternalSourceDrawCommand() - : DrawCommand(DrawCommandType::EXTERNAL) + WidgetDrawActionExternal() + : WidgetDrawAction(WidgetDrawActionType::EXTERNAL) { } }; @@ -179,12 +169,10 @@ public: OString const& sSelected, OString const& sButtonValue, OString const& sExtra); - std::vector<std::shared_ptr<DrawCommand>> mpDrawCommands; + std::vector<std::shared_ptr<WidgetDrawAction>> mpWidgetDrawActions; void addDrawRectangle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, float fX1, float fY1, float fX2, float fY2, sal_Int32 nRx, sal_Int32 nRy); - void addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, Color aFillColor, float fX1, - float fY1, float fX2, float fY2); void addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2, float fY2); diff --git a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx index 75dc559067fc..843f449b7901 100644 --- a/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx +++ b/vcl/qa/cppunit/widgetdraw/WidgetDefinitionReaderTest.cxx @@ -62,10 +62,11 @@ void WidgetDefinitionReaderTest::testRead() CPPUNIT_ASSERT_EQUAL(size_t(2), aStates.size()); - CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpDrawCommands.size()); - CPPUNIT_ASSERT_EQUAL(vcl::DrawCommandType::RECTANGLE, - aStates[0]->mpDrawCommands[0]->maType); - CPPUNIT_ASSERT_EQUAL(vcl::DrawCommandType::CIRCLE, aStates[0]->mpDrawCommands[1]->maType); + CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpWidgetDrawActions.size()); + CPPUNIT_ASSERT_EQUAL(vcl::WidgetDrawActionType::RECTANGLE, + aStates[0]->mpWidgetDrawActions[0]->maType); + CPPUNIT_ASSERT_EQUAL(vcl::WidgetDrawActionType::LINE, + aStates[0]->mpWidgetDrawActions[1]->maType); } // Radiobutton @@ -75,7 +76,7 @@ void WidgetDefinitionReaderTest::testRead() ->getStates(ControlType::Radiobutton, ControlPart::Entire, ControlState::NONE, ImplControlValue(ButtonValue::On)); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); - CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpDrawCommands.size()); + CPPUNIT_ASSERT_EQUAL(size_t(2), aStates[0]->mpWidgetDrawActions.size()); } { @@ -84,7 +85,7 @@ void WidgetDefinitionReaderTest::testRead() ->getStates(ControlType::Radiobutton, ControlPart::Entire, ControlState::NONE, ImplControlValue(ButtonValue::Off)); CPPUNIT_ASSERT_EQUAL(size_t(1), aStates.size()); - CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpDrawCommands.size()); + CPPUNIT_ASSERT_EQUAL(size_t(1), aStates[0]->mpWidgetDrawActions.size()); } } diff --git a/vcl/qa/cppunit/widgetdraw/data/definition1.xml b/vcl/qa/cppunit/widgetdraw/data/definition1.xml index 4fb1c4230853..041e8fc24754 100644 --- a/vcl/qa/cppunit/widgetdraw/data/definition1.xml +++ b/vcl/qa/cppunit/widgetdraw/data/definition1.xml @@ -56,7 +56,7 @@ <part value="Entire"> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="any"> <rect stroke="#808080" fill="#FFFFFF" stroke-width="1.0" rx="5" ry="5" margin="1"/> - <circ stroke="#808080" fill="#808080" stroke-width="1.0" margin="1"/> + <line stroke="#808080" fill="#808080" stroke-width="1.0"/> </state> <state enabled="true" focused="any" pressed="any" rollover="true" default="true" selected="any" button-value="any"> <rect stroke="#808080" fill="#808080" stroke-width="1.0" rx="5" ry="5" margin="1"/> @@ -71,11 +71,11 @@ <radiobutton> <part value="Entire"> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="false"> - <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> + <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> </state> <state enabled="any" focused="any" pressed="any" rollover="any" default="any" selected="any" button-value="true"> - <circ stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> - <circ stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/> + <rect stroke="#007AFF" fill="#FFFFFF" stroke-width="1" margin="0"/> + <rect stroke="#007AFF" fill="#007AFF" stroke-width="1" margin="3"/> </state> </part> </radiobutton> diff --git a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx index 1263c1a12aee..0cfe446f53a3 100644 --- a/vcl/source/gdi/FileDefinitionWidgetDraw.cxx +++ b/vcl/source/gdi/FileDefinitionWidgetDraw.cxx @@ -253,97 +253,76 @@ void drawFromDrawCommands(gfx::DrawRoot const& rDrawRoot, SalGraphics& rGraphics } } -void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCommands, +void munchDrawCommands(std::vector<std::shared_ptr<WidgetDrawAction>> const& rDrawActions, SalGraphics& rGraphics, long nX, long nY, long nWidth, long nHeight) { - for (std::shared_ptr<DrawCommand> const& pDrawCommand : rDrawCommands) + for (std::shared_ptr<WidgetDrawAction> const& pDrawAction : rDrawActions) { - switch (pDrawCommand->maType) + switch (pDrawAction->maType) { - case DrawCommandType::RECTANGLE: + case WidgetDrawActionType::RECTANGLE: { - auto const& rRectDrawCommand - = static_cast<RectangleDrawCommand const&>(*pDrawCommand); + auto const& rWidgetDraw + = static_cast<WidgetDrawActionRectangle const&>(*pDrawAction); basegfx::B2DRectangle rRect( - nX + (nWidth * rRectDrawCommand.mfX1), nY + (nHeight * rRectDrawCommand.mfY1), - nX + (nWidth * rRectDrawCommand.mfX2), nY + (nHeight * rRectDrawCommand.mfY2)); + nX + (nWidth * rWidgetDraw.mfX1), nY + (nHeight * rWidgetDraw.mfY1), + nX + (nWidth * rWidgetDraw.mfX2), nY + (nHeight * rWidgetDraw.mfY2)); basegfx::B2DPolygon aB2DPolygon = basegfx::utils::createPolygonFromRect( - rRect, rRectDrawCommand.mnRx / rRect.getWidth() * 2.0, - rRectDrawCommand.mnRy / rRect.getHeight() * 2.0); + rRect, rWidgetDraw.mnRx / rRect.getWidth() * 2.0, + rWidgetDraw.mnRy / rRect.getHeight() * 2.0); rGraphics.SetLineColor(); - rGraphics.SetFillColor(rRectDrawCommand.maFillColor); + rGraphics.SetFillColor(rWidgetDraw.maFillColor); rGraphics.DrawPolyPolygon(basegfx::B2DHomMatrix(), basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr); - rGraphics.SetLineColor(rRectDrawCommand.maStrokeColor); + rGraphics.SetLineColor(rWidgetDraw.maStrokeColor); rGraphics.SetFillColor(); - rGraphics.DrawPolyLine(basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, - basegfx::B2DVector(rRectDrawCommand.mnStrokeWidth, - rRectDrawCommand.mnStrokeWidth), - basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, - 0.0f, false, nullptr); + rGraphics.DrawPolyLine( + basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, + basegfx::B2DVector(rWidgetDraw.mnStrokeWidth, rWidgetDraw.mnStrokeWidth), + basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, 0.0f, false, nullptr); } break; - case DrawCommandType::CIRCLE: + case WidgetDrawActionType::LINE: { - auto const& rCircleDrawCommand - = static_cast<CircleDrawCommand const&>(*pDrawCommand); - - basegfx::B2DRectangle rRect(nX + (nWidth * rCircleDrawCommand.mfX1), - nY + (nHeight * rCircleDrawCommand.mfY1), - nX + (nWidth * rCircleDrawCommand.mfX2), - nY + (nHeight * rCircleDrawCommand.mfY2)); - - basegfx::B2DPolygon aB2DPolygon = basegfx::utils::createPolygonFromEllipse( - rRect.getCenter(), rRect.getWidth() / 2.0, rRect.getHeight() / 2.0); - - rGraphics.SetLineColor(rCircleDrawCommand.maStrokeColor); - rGraphics.SetFillColor(rCircleDrawCommand.maFillColor); - rGraphics.DrawPolyPolygon(basegfx::B2DHomMatrix(), - basegfx::B2DPolyPolygon(aB2DPolygon), 0.0f, nullptr); - } - break; - case DrawCommandType::LINE: - { - auto const& rLineDrawCommand = static_cast<LineDrawCommand const&>(*pDrawCommand); + auto const& rWidgetDraw = static_cast<WidgetDrawActionLine const&>(*pDrawAction); Point aRectPoint(nX + 1, nY + 1); Size aRectSize(nWidth - 1, nHeight - 1); rGraphics.SetFillColor(); - rGraphics.SetLineColor(rLineDrawCommand.maStrokeColor); + rGraphics.SetLineColor(rWidgetDraw.maStrokeColor); basegfx::B2DPolygon aB2DPolygon{ - { aRectPoint.X() + (aRectSize.Width() * rLineDrawCommand.mfX1), - aRectPoint.Y() + (aRectSize.Height() * rLineDrawCommand.mfY1) }, - { aRectPoint.X() + (aRectSize.Width() * rLineDrawCommand.mfX2), - aRectPoint.Y() + (aRectSize.Height() * rLineDrawCommand.mfY2) }, + { aRectPoint.X() + (aRectSize.Width() * rWidgetDraw.mfX1), + aRectPoint.Y() + (aRectSize.Height() * rWidgetDraw.mfY1) }, + { aRectPoint.X() + (aRectSize.Width() * rWidgetDraw.mfX2), + aRectPoint.Y() + (aRectSize.Height() * rWidgetDraw.mfY2) }, }; - rGraphics.DrawPolyLine(basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, - basegfx::B2DVector(rLineDrawCommand.mnStrokeWidth, - rLineDrawCommand.mnStrokeWidth), - basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, - 0.0f, false, nullptr); + rGraphics.DrawPolyLine( + basegfx::B2DHomMatrix(), aB2DPolygon, 0.0f, + basegfx::B2DVector(rWidgetDraw.mnStrokeWidth, rWidgetDraw.mnStrokeWidth), + basegfx::B2DLineJoin::Round, css::drawing::LineCap_ROUND, 0.0f, false, nullptr); } break; - case DrawCommandType::IMAGE: + case WidgetDrawActionType::IMAGE: { - double nScaleFactor = 1.0; + double nScaleFactor = 2.0; if (comphelper::LibreOfficeKit::isActive()) nScaleFactor = comphelper::LibreOfficeKit::getDPIScale(); - auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand); + auto const& rWidgetDraw = static_cast<WidgetDrawActionImage const&>(*pDrawAction); auto& rCacheImages = ImplGetSVData()->maGDIData.maThemeImageCache; - OUString rCacheKey = rDrawCommand.msSource + "@" + OUString::number(nScaleFactor); + OUString rCacheKey = rWidgetDraw.msSource + "@" + OUString::number(nScaleFactor); auto& aIterator = rCacheImages.find(rCacheKey); BitmapEx aBitmap; if (aIterator == rCacheImages.end()) { - SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ); + SvFileStream aFileStream(rWidgetDraw.msSource, StreamMode::READ); vcl::bitmap::loadFromSvg(aFileStream, "", aBitmap, nScaleFactor); if (!!aBitmap) @@ -377,19 +356,20 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom } } break; - case DrawCommandType::EXTERNAL: + case WidgetDrawActionType::EXTERNAL: { - auto const& rDrawCommand = static_cast<ImageDrawCommand const&>(*pDrawCommand); + auto const& rWidgetDraw + = static_cast<WidgetDrawActionExternal const&>(*pDrawAction); auto& rCacheDrawCommands = ImplGetSVData()->maGDIData.maThemeDrawCommandsCache; - auto& aIterator = rCacheDrawCommands.find(rDrawCommand.msSource); + auto& aIterator = rCacheDrawCommands.find(rWidgetDraw.msSource); gfx::DrawRoot aDrawRoot; if (aIterator == rCacheDrawCommands.end()) { - SvFileStream aFileStream(rDrawCommand.msSource, StreamMode::READ); + SvFileStream aFileStream(rWidgetDraw.msSource, StreamMode::READ); uno::Reference<uno::XComponentContext> xContext( comphelper::getProcessComponentContext()); @@ -412,7 +392,7 @@ void munchDrawCommands(std::vector<std::shared_ptr<DrawCommand>> const& rDrawCom if (pDrawRoot) { rCacheDrawCommands.insert( - std::make_pair(rDrawCommand.msSource, *pDrawRoot)); + std::make_pair(rWidgetDraw.msSource, *pDrawRoot)); drawFromDrawCommands(*pDrawRoot, rGraphics, nX, nY, nWidth, nHeight); } } @@ -444,7 +424,8 @@ bool FileDefinitionWidgetDraw::resolveDefinition(ControlType eType, ControlPart // use last defined state auto const& pState = aStates.back(); { - munchDrawCommands(pState->mpDrawCommands, m_rGraphics, nX, nY, nWidth, nHeight); + munchDrawCommands(pState->mpWidgetDrawActions, m_rGraphics, nX, nY, nWidth, + nHeight); bOK = true; } } diff --git a/vcl/source/gdi/WidgetDefinition.cxx b/vcl/source/gdi/WidgetDefinition.cxx index 668fe74bf403..6eb6ae7fa3ac 100644 --- a/vcl/source/gdi/WidgetDefinition.cxx +++ b/vcl/source/gdi/WidgetDefinition.cxx @@ -134,7 +134,7 @@ void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStro Color aFillColor, float fX1, float fY1, float fX2, float fY2, sal_Int32 nRx, sal_Int32 nRy) { - auto pCommand(std::make_shared<RectangleDrawCommand>()); + auto pCommand(std::make_shared<WidgetDrawActionRectangle>()); pCommand->maStrokeColor = aStrokeColor; pCommand->maFillColor = aFillColor; pCommand->mnStrokeWidth = nStrokeWidth; @@ -144,49 +144,34 @@ void WidgetDefinitionState::addDrawRectangle(Color aStrokeColor, sal_Int32 nStro pCommand->mfY1 = fY1; pCommand->mfX2 = fX2; pCommand->mfY2 = fY2; - mpDrawCommands.push_back(std::move(pCommand)); -} - -void WidgetDefinitionState::addDrawCircle(Color aStrokeColor, sal_Int32 nStrokeWidth, - Color aFillColor, float fX1, float fY1, float fX2, - float fY2) -{ - auto pCommand(std::make_shared<CircleDrawCommand>()); - pCommand->maStrokeColor = aStrokeColor; - pCommand->maFillColor = aFillColor; - pCommand->mnStrokeWidth = nStrokeWidth; - pCommand->mfX1 = fX1; - pCommand->mfY1 = fY1; - pCommand->mfX2 = fX2; - pCommand->mfY2 = fY2; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } void WidgetDefinitionState::addDrawLine(Color aStrokeColor, sal_Int32 nStrokeWidth, float fX1, float fY1, float fX2, float fY2) { - auto pCommand(std::make_shared<LineDrawCommand>()); + auto pCommand(std::make_shared<WidgetDrawActionLine>()); pCommand->maStrokeColor = aStrokeColor; pCommand->mnStrokeWidth = nStrokeWidth; pCommand->mfX1 = fX1; pCommand->mfY1 = fY1; pCommand->mfX2 = fX2; pCommand->mfY2 = fY2; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } void WidgetDefinitionState::addDrawImage(OUString const& sSource) { - auto pCommand(std::make_shared<ImageDrawCommand>()); + auto pCommand(std::make_shared<WidgetDrawActionImage>()); pCommand->msSource = sSource; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } void WidgetDefinitionState::addDrawExternal(OUString const& sSource) { - auto pCommand(std::make_unique<ExternalSourceDrawCommand>()); + auto pCommand(std::make_unique<WidgetDrawActionExternal>()); pCommand->msSource = sSource; - mpDrawCommands.push_back(std::move(pCommand)); + mpWidgetDrawActions.push_back(std::move(pCommand)); } } // end vcl namespace diff --git a/vcl/source/gdi/WidgetDefinitionReader.cxx b/vcl/source/gdi/WidgetDefinitionReader.cxx index c183cb717e9c..f825addd0042 100644 --- a/vcl/source/gdi/WidgetDefinitionReader.cxx +++ b/vcl/source/gdi/WidgetDefinitionReader.cxx @@ -226,31 +226,6 @@ void WidgetDefinitionReader::readDrawingDefinition(tools::XmlWalker& rWalker, rpState->addDrawRectangle(aStrokeColor, nStrokeWidth, aFillColor, fX1, fY1, fX2, fY2, nRx, nRy); } - else if (rWalker.name() == "circ") - { - Color aStrokeColor; - readColor(rWalker.attribute("stroke"), aStrokeColor); - Color aFillColor; - readColor(rWalker.attribute("fill"), aFillColor); - OString sStrokeWidth = rWalker.attribute("stroke-width"); - sal_Int32 nStrokeWidth = -1; - if (!sStrokeWidth.isEmpty()) - nStrokeWidth = sStrokeWidth.toInt32(); - - OString sX1 = rWalker.attribute("x1"); - float fX1 = sX1.isEmpty() ? 0.0 : sX1.toFloat(); - - OString sY1 = rWalker.attribute("y1"); - float fY1 = sY1.isEmpty() ? 0.0 : sY1.toFloat(); - - OString sX2 = rWalker.attribute("x2"); - float fX2 = sX2.isEmpty() ? 1.0 : sX2.toFloat(); - - OString sY2 = rWalker.attribute("y2"); - float fY2 = sY2.isEmpty() ? 1.0 : sY2.toFloat(); - - rpState->addDrawCircle(aStrokeColor, nStrokeWidth, aFillColor, fX1, fY1, fX2, fY2); - } else if (rWalker.name() == "line") { Color aStrokeColor; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits