1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <uielement/FixedImageToolbarController.hxx>
22 #include <vcl/graph.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/toolbox.hxx>
25 #include <vcl/InterimItemWindow.hxx>
26 #include <svtools/miscopt.hxx>
27 #include <svtools/imgdef.hxx>
28 #include <framework/addonsoptions.hxx>
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::frame
;
36 class FixedImageControl final
: public InterimItemWindow
39 FixedImageControl(vcl::Window
* pParent
, const OUString
& rCommand
);
40 virtual ~FixedImageControl() override
;
41 virtual void dispose() override
;
42 DECL_LINK(KeyInputHdl
, const ::KeyEvent
&, bool);
45 std::unique_ptr
<weld::Image
> m_xWidget
;
48 FixedImageControl::FixedImageControl(vcl::Window
* pParent
, const OUString
& rCommand
)
49 : InterimItemWindow(pParent
, u
"svt/ui/fixedimagecontrol.ui"_ustr
, u
"FixedImageControl"_ustr
)
50 , m_xWidget(m_xBuilder
->weld_image(u
"image"_ustr
))
52 InitControlBase(m_xWidget
.get());
54 m_xWidget
->connect_key_press(LINK(this, FixedImageControl
, KeyInputHdl
));
56 bool bBigImages(SvtMiscOptions::AreCurrentSymbolsLarge());
58 = Graphic(AddonsOptions().GetImageFromURL(rCommand
, bBigImages
, true)).GetXGraphic();
59 m_xWidget
->set_image(xImage
);
61 SetSizePixel(get_preferred_size());
64 IMPL_LINK(FixedImageControl
, KeyInputHdl
, const ::KeyEvent
&, rKEvt
, bool)
66 return ChildKeyInput(rKEvt
);
69 FixedImageControl::~FixedImageControl() { disposeOnce(); }
71 void FixedImageControl::dispose()
74 InterimItemWindow::dispose();
77 FixedImageToolbarController::FixedImageToolbarController(
78 const Reference
<XComponentContext
>& rxContext
, const Reference
<XFrame
>& rFrame
,
79 ToolBox
* pToolbar
, ToolBoxItemId nID
, const OUString
& rCommand
)
80 : ComplexToolbarController(rxContext
, rFrame
, pToolbar
, nID
, rCommand
)
81 , m_eSymbolSize(SvtMiscOptions::GetCurrentSymbolsSize())
83 m_pFixedImageControl
= VclPtr
<FixedImageControl
>::Create(m_xToolbar
, rCommand
);
84 m_xToolbar
->SetItemWindow(m_nID
, m_pFixedImageControl
);
86 SvtMiscOptions().AddListenerLink(LINK(this, FixedImageToolbarController
, MiscOptionsChanged
));
89 void SAL_CALL
FixedImageToolbarController::dispose()
91 SolarMutexGuard aSolarMutexGuard
;
92 SvtMiscOptions().RemoveListenerLink(
93 LINK(this, FixedImageToolbarController
, MiscOptionsChanged
));
94 m_xToolbar
->SetItemWindow(m_nID
, nullptr);
95 m_pFixedImageControl
.disposeAndClear();
96 ComplexToolbarController::dispose();
99 void FixedImageToolbarController::executeControlCommand(const css::frame::ControlCommand
&) {}
101 void FixedImageToolbarController::CheckAndUpdateImages()
103 SolarMutexGuard aSolarMutexGuard
;
105 const sal_Int16 eNewSymbolSize
= SvtMiscOptions::GetCurrentSymbolsSize();
107 if (m_eSymbolSize
== eNewSymbolSize
)
110 m_eSymbolSize
= eNewSymbolSize
;
112 // Refresh images if requested
113 ::Size
aSize(16, 16);
114 if (m_eSymbolSize
== SFX_SYMBOLS_SIZE_LARGE
)
119 else if (m_eSymbolSize
== SFX_SYMBOLS_SIZE_32
)
124 m_pFixedImageControl
->SetSizePixel(aSize
);
127 IMPL_LINK_NOARG(FixedImageToolbarController
, MiscOptionsChanged
, LinkParamNone
*, void)
129 CheckAndUpdateImages();
132 } // namespace framework
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */