| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <svtools/popupwindowcontroller.hxx> |
| 14 |
#include <svtools/toolbarmenu.hxx> |
| 15 |
#include <ChartColorPalettes.hxx> |
| 16 |
|
| 17 |
namespace chart |
| 18 |
{ |
| 19 |
class ChartColorPaletteHelper; |
| 20 |
|
| 21 |
namespace sidebar |
| 22 |
{ |
| 23 |
struct IColorPaletteHandler |
| 24 |
{ |
| 25 |
virtual ~IColorPaletteHandler() = default; |
| 26 |
|
| 27 |
virtual void createDiagramSnapshot() = 0; |
| 28 |
virtual void restoreOriginalDiagram() = 0; |
| 29 |
|
| 30 |
virtual void select(ChartColorPaletteType eType, sal_uInt32 nIndex) = 0; |
| 31 |
virtual void apply(const ChartColorPalette* pColorPalette) = 0; |
| 32 |
[[nodiscard]] virtual std::shared_ptr<ChartColorPaletteHelper> getHelper() const = 0; |
| 33 |
[[nodiscard]] virtual ChartColorPaletteType getType() const = 0; |
| 34 |
[[nodiscard]] virtual sal_uInt32 getIndex() const = 0; |
| 35 |
}; |
| 36 |
|
| 37 |
class ChartColorPaletteControl final : public svt::PopupWindowController |
| 38 |
{ |
| 39 |
std::shared_ptr<IColorPaletteHandler> mpHandler; |
| 40 |
ChartColorPaletteType meColorPaletteType; |
| 41 |
sal_uInt32 mnColorPaletteIndex; |
| 42 |
|
| 43 |
public: |
| 44 |
explicit ChartColorPaletteControl( |
| 45 |
const css::uno::Reference<css::uno::XComponentContext>& rContext); |
| 46 |
|
| 47 |
// XInitialization |
| 48 |
void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override; |
| 49 |
|
| 50 |
// XServiceInfo |
| 51 |
OUString SAL_CALL getImplementationName() override; |
| 52 |
css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; |
| 53 |
|
| 54 |
void SAL_CALL execute(sal_Int16 nKeyModifier) override; |
| 55 |
void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) override; |
| 56 |
|
| 57 |
~ChartColorPaletteControl() override; |
| 58 |
|
| 59 |
void setColorPaletteHandler(const std::shared_ptr<IColorPaletteHandler>& rColorPaletteHandler); |
| 60 |
std::shared_ptr<ChartColorPaletteHelper> getColorPaletteHelper() const; |
| 61 |
ChartColorPaletteType getColorPaletteType() const; |
| 62 |
sal_uInt32 getColorPaletteIndex() const; |
| 63 |
void dispatchColorPaletteCommand(ChartColorPaletteType eType, sal_uInt32 nIndex) const; |
| 64 |
void applyColorPalette(const ChartColorPalette* pColorPalette) const; |
| 65 |
void updateStatus(bool bForce = false); |
| 66 |
|
| 67 |
void createDiagramSnapshot() const; |
| 68 |
void restoreOriginalDiagram() const; |
| 69 |
|
| 70 |
private: |
| 71 |
std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override; |
| 72 |
VclPtr<vcl::Window> createVclPopupWindow(vcl::Window* pParent) override; |
| 73 |
|
| 74 |
void renderSelectedColorPalette(const VclPtr<VirtualDevice>& pDev) const; |
| 75 |
}; |
| 76 |
|
| 77 |
class ChartColorPalettePopup final : public WeldToolbarPopup |
| 78 |
{ |
| 79 |
rtl::Reference<ChartColorPaletteControl> mxControl; |
| 80 |
std::unique_ptr<ChartColorPalettes> mxColorfulPalettes; |
| 81 |
std::unique_ptr<ChartColorPalettes> mxMonoPalettes; |
| 82 |
|
| 83 |
ChartColorPaletteType meHighlightedItemType; |
| 84 |
sal_uInt16 mnHighlightedItemId; |
| 85 |
bool mbItemSelected; |
| 86 |
|
| 87 |
DECL_LINK(SelectColorfulPaletteHdl, weld::IconView&, bool); |
| 88 |
DECL_LINK(SelectMonoPaletteHdl, weld::IconView&, bool); |
| 89 |
sal_uInt32 SelectPaletteHdl(const std::unique_ptr<ChartColorPalettes>& xPalettes); |
| 90 |
|
| 91 |
DECL_LINK(ColorfulMouseMoveHdl, const MouseEvent&, bool); |
| 92 |
DECL_LINK(MonoMouseMoveHdl, const MouseEvent&, bool); |
| 93 |
void MouseMoveHdl(const std::unique_ptr<ChartColorPalettes>& xPalettes, |
| 94 |
ChartColorPaletteType eHlItemType); |
| 95 |
|
| 96 |
void GrabFocus() override; |
| 97 |
|
| 98 |
void selectItem(ChartColorPaletteType eType, sal_uInt32 nIndex) const; |
| 99 |
void initColorPalettes() const; |
| 100 |
|
| 101 |
public: |
| 102 |
ChartColorPalettePopup(ChartColorPaletteControl* pControl, weld::Widget* pParent); |
| 103 |
~ChartColorPalettePopup() override; |
| 104 |
}; |
| 105 |
} // end namespace sidebar |
| 106 |
} // end namespace chart |
| 107 |
|
| 108 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |