diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-06-26 14:28:29 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-06-26 18:13:10 +0200 |
commit | b08292b918f264c4f012ef8c543062cb23ad3b7b (patch) | |
tree | 7440515c823cf896ca31f9d5c03d41e612997d83 /framework/source | |
parent | 5d296183072dc7cfe7a9985c38388b56f37d873c (diff) |
weld FixedImageControl
Change-Id: I13f3480794232a9c203ae047a4fcad372988b8b8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97235
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'framework/source')
-rw-r--r-- | framework/source/uielement/FixedImageToolbarController.cxx | 67 |
1 files changed, 51 insertions, 16 deletions
diff --git a/framework/source/uielement/FixedImageToolbarController.cxx b/framework/source/uielement/FixedImageToolbarController.cxx index cfc987d97d3f..a666261b0f03 100644 --- a/framework/source/uielement/FixedImageToolbarController.cxx +++ b/framework/source/uielement/FixedImageToolbarController.cxx @@ -19,9 +19,10 @@ #include <uielement/FixedImageToolbarController.hxx> +#include <vcl/graph.hxx> #include <vcl/svapp.hxx> #include <vcl/toolbox.hxx> -#include <vcl/fixed.hxx> +#include <vcl/InterimItemWindow.hxx> #include <svtools/miscopt.hxx> #include <svtools/imgdef.hxx> #include <framework/addonsoptions.hxx> @@ -36,21 +37,60 @@ using namespace ::com::sun::star::util; namespace framework { +class FixedImageControl final : public InterimItemWindow +{ +public: + FixedImageControl(vcl::Window* pParent, const OUString& rCommand); + virtual ~FixedImageControl() override; + virtual void dispose() override; + virtual void GetFocus() override + { + if (m_xWidget) + m_xWidget->grab_focus(); + InterimItemWindow::GetFocus(); + } + DECL_LINK(KeyInputHdl, const ::KeyEvent&, bool); + +private: + std::unique_ptr<weld::Image> m_xWidget; +}; + +FixedImageControl::FixedImageControl(vcl::Window* pParent, const OUString& rCommand) + : InterimItemWindow(pParent, "svt/ui/fixedimagecontrol.ui", "FixedImageControl") + , m_xWidget(m_xBuilder->weld_image("image")) +{ + m_xWidget->connect_key_press(LINK(this, FixedImageControl, KeyInputHdl)); + + bool bBigImages(SvtMiscOptions().AreCurrentSymbolsLarge()); + auto xImage + = Graphic(AddonsOptions().GetImageFromURL(rCommand, bBigImages, true)).GetXGraphic(); + m_xWidget->set_image(xImage); + + SetSizePixel(get_preferred_size()); +} + +IMPL_LINK(FixedImageControl, KeyInputHdl, const ::KeyEvent&, rKEvt, bool) +{ + return ChildKeyInput(rKEvt); +} + +FixedImageControl::~FixedImageControl() { disposeOnce(); } + +void FixedImageControl::dispose() +{ + m_xWidget.reset(); + InterimItemWindow::dispose(); +} + FixedImageToolbarController::FixedImageToolbarController( const Reference<XComponentContext>& rxContext, const Reference<XFrame>& rFrame, - ToolBox* pToolbar, sal_uInt16 nID, const OUString& aCommand) - : ComplexToolbarController(rxContext, rFrame, pToolbar, nID, aCommand) + ToolBox* pToolbar, sal_uInt16 nID, const OUString& rCommand) + : ComplexToolbarController(rxContext, rFrame, pToolbar, nID, rCommand) , m_eSymbolSize(SvtMiscOptions().GetCurrentSymbolsSize()) { - m_pFixedImageControl = VclPtr<FixedImage>::Create(m_xToolbar, 0); + m_pFixedImageControl = VclPtr<FixedImageControl>::Create(m_xToolbar, rCommand); m_xToolbar->SetItemWindow(m_nID, m_pFixedImageControl); - bool bBigImages(SvtMiscOptions().AreCurrentSymbolsLarge()); - - Image aImage(AddonsOptions().GetImageFromURL(aCommand, bBigImages, true)); - m_pFixedImageControl->SetImage(aImage); - m_pFixedImageControl->SetSizePixel(m_pFixedImageControl->GetOptimalSize()); - SvtMiscOptions().AddListenerLink(LINK(this, FixedImageToolbarController, MiscOptionsChanged)); } @@ -79,7 +119,7 @@ void FixedImageToolbarController::CheckAndUpdateImages() m_eSymbolSize = eNewSymbolSize; // Refresh images if requested - auto aSize(m_pFixedImageControl->GetOptimalSize()); + ::Size aSize(16, 16); if (m_eSymbolSize == SFX_SYMBOLS_SIZE_LARGE) { aSize.setWidth(26); @@ -90,11 +130,6 @@ void FixedImageToolbarController::CheckAndUpdateImages() aSize.setWidth(32); aSize.setHeight(32); } - else - { - aSize.setWidth(16); - aSize.setHeight(16); - } m_pFixedImageControl->SetSizePixel(aSize); } |