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::awt
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::frame
;
36 using namespace ::com::sun::star::util
;
40 class FixedImageControl final
: public InterimItemWindow
43 FixedImageControl(vcl::Window
* pParent
, const OUString
& rCommand
);
44 virtual ~FixedImageControl() override
;
45 virtual void dispose() override
;
46 DECL_LINK(KeyInputHdl
, const ::KeyEvent
&, bool);
49 std::unique_ptr
<weld::Image
> m_xWidget
;
52 FixedImageControl::FixedImageControl(vcl::Window
* pParent
, const OUString
& rCommand
)
53 : InterimItemWindow(pParent
, "svt/ui/fixedimagecontrol.ui", "FixedImageControl")
54 , m_xWidget(m_xBuilder
->weld_image("image"))
56 InitControlBase(m_xWidget
.get());
58 m_xWidget
->connect_key_press(LINK(this, FixedImageControl
, KeyInputHdl
));
60 bool bBigImages(SvtMiscOptions().AreCurrentSymbolsLarge());
62 = Graphic(AddonsOptions().GetImageFromURL(rCommand
, bBigImages
, true)).GetXGraphic();
63 m_xWidget
->set_image(xImage
);
65 SetSizePixel(get_preferred_size());
68 IMPL_LINK(FixedImageControl
, KeyInputHdl
, const ::KeyEvent
&, rKEvt
, bool)
70 return ChildKeyInput(rKEvt
);
73 FixedImageControl::~FixedImageControl() { disposeOnce(); }
75 void FixedImageControl::dispose()
78 InterimItemWindow::dispose();
81 FixedImageToolbarController::FixedImageToolbarController(
82 const Reference
<XComponentContext
>& rxContext
, const Reference
<XFrame
>& rFrame
,
83 ToolBox
* pToolbar
, ToolBoxItemId nID
, const OUString
& rCommand
)
84 : ComplexToolbarController(rxContext
, rFrame
, pToolbar
, nID
, rCommand
)
85 , m_eSymbolSize(SvtMiscOptions().GetCurrentSymbolsSize())
87 m_pFixedImageControl
= VclPtr
<FixedImageControl
>::Create(m_xToolbar
, rCommand
);
88 m_xToolbar
->SetItemWindow(m_nID
, m_pFixedImageControl
);
90 SvtMiscOptions().AddListenerLink(LINK(this, FixedImageToolbarController
, MiscOptionsChanged
));
93 void SAL_CALL
FixedImageToolbarController::dispose()
95 SolarMutexGuard aSolarMutexGuard
;
96 SvtMiscOptions().RemoveListenerLink(
97 LINK(this, FixedImageToolbarController
, MiscOptionsChanged
));
98 m_xToolbar
->SetItemWindow(m_nID
, nullptr);
99 m_pFixedImageControl
.disposeAndClear();
100 ComplexToolbarController::dispose();
103 void FixedImageToolbarController::executeControlCommand(const css::frame::ControlCommand
&) {}
105 void FixedImageToolbarController::CheckAndUpdateImages()
107 SolarMutexGuard aSolarMutexGuard
;
109 SvtMiscOptions aMiscOptions
;
110 const sal_Int16 eNewSymbolSize
= aMiscOptions
.GetCurrentSymbolsSize();
112 if (m_eSymbolSize
== eNewSymbolSize
)
115 m_eSymbolSize
= eNewSymbolSize
;
117 // Refresh images if requested
118 ::Size
aSize(16, 16);
119 if (m_eSymbolSize
== SFX_SYMBOLS_SIZE_LARGE
)
124 else if (m_eSymbolSize
== SFX_SYMBOLS_SIZE_32
)
129 m_pFixedImageControl
->SetSizePixel(aSize
);
132 IMPL_LINK_NOARG(FixedImageToolbarController
, MiscOptionsChanged
, LinkParamNone
*, void)
134 CheckAndUpdateImages();
137 } // namespace framework
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */