/src/libreoffice/framework/source/uielement/FixedImageToolbarController.cxx
Line | Count | Source |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #include <uielement/FixedImageToolbarController.hxx> |
21 | | |
22 | | #include <comphelper/unique_unlock.hxx> |
23 | | #include <vcl/graph.hxx> |
24 | | #include <vcl/svapp.hxx> |
25 | | #include <vcl/toolbox.hxx> |
26 | | #include <vcl/InterimItemWindow.hxx> |
27 | | #include <vcl/weld/Builder.hxx> |
28 | | #include <vcl/weld/Image.hxx> |
29 | | #include <svtools/miscopt.hxx> |
30 | | #include <svtools/imgdef.hxx> |
31 | | #include <framework/addonsoptions.hxx> |
32 | | |
33 | | using namespace ::com::sun::star; |
34 | | using namespace ::com::sun::star::uno; |
35 | | using namespace ::com::sun::star::frame; |
36 | | |
37 | | namespace framework |
38 | | { |
39 | | class FixedImageControl final : public InterimItemWindow |
40 | | { |
41 | | public: |
42 | | FixedImageControl(vcl::Window* pParent, const OUString& rCommand); |
43 | | virtual ~FixedImageControl() override; |
44 | | virtual void dispose() override; |
45 | | DECL_LINK(KeyInputHdl, const ::KeyEvent&, bool); |
46 | | |
47 | | private: |
48 | | std::unique_ptr<weld::Image> m_xWidget; |
49 | | }; |
50 | | |
51 | | FixedImageControl::FixedImageControl(vcl::Window* pParent, const OUString& rCommand) |
52 | 0 | : InterimItemWindow(pParent, u"svt/ui/fixedimagecontrol.ui"_ustr, u"FixedImageControl"_ustr) |
53 | 0 | , m_xWidget(m_xBuilder->weld_image(u"image"_ustr)) |
54 | 0 | { |
55 | 0 | InitControlBase(m_xWidget.get()); |
56 | |
|
57 | 0 | m_xWidget->connect_key_press(LINK(this, FixedImageControl, KeyInputHdl)); |
58 | |
|
59 | 0 | bool bBigImages(SvtMiscOptions::AreCurrentSymbolsLarge()); |
60 | 0 | auto xImage |
61 | 0 | = Graphic(AddonsOptions().GetImageFromURL(rCommand, bBigImages, true)).GetXGraphic(); |
62 | 0 | m_xWidget->set_image(xImage); |
63 | |
|
64 | 0 | SetSizePixel(get_preferred_size()); |
65 | 0 | } Unexecuted instantiation: framework::FixedImageControl::FixedImageControl(vcl::Window*, rtl::OUString const&) Unexecuted instantiation: framework::FixedImageControl::FixedImageControl(vcl::Window*, rtl::OUString const&) |
66 | | |
67 | | IMPL_LINK(FixedImageControl, KeyInputHdl, const ::KeyEvent&, rKEvt, bool) |
68 | 0 | { |
69 | 0 | return ChildKeyInput(rKEvt); |
70 | 0 | } |
71 | | |
72 | 0 | FixedImageControl::~FixedImageControl() { disposeOnce(); } |
73 | | |
74 | | void FixedImageControl::dispose() |
75 | 0 | { |
76 | 0 | m_xWidget.reset(); |
77 | 0 | InterimItemWindow::dispose(); |
78 | 0 | } |
79 | | |
80 | | FixedImageToolbarController::FixedImageToolbarController( |
81 | | const Reference<XComponentContext>& rxContext, const Reference<XFrame>& rFrame, |
82 | | ToolBox* pToolbar, ToolBoxItemId nID, const OUString& rCommand) |
83 | 0 | : ComplexToolbarController(rxContext, rFrame, pToolbar, nID, rCommand) |
84 | 0 | , m_eSymbolSize(SvtMiscOptions::GetCurrentSymbolsSize()) |
85 | 0 | { |
86 | 0 | m_pFixedImageControl = VclPtr<FixedImageControl>::Create(m_xToolbar, rCommand); |
87 | 0 | m_xToolbar->SetItemWindow(m_nID, m_pFixedImageControl); |
88 | |
|
89 | 0 | SvtMiscOptions().AddListenerLink(LINK(this, FixedImageToolbarController, MiscOptionsChanged)); |
90 | 0 | } Unexecuted instantiation: framework::FixedImageToolbarController::FixedImageToolbarController(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&, ToolBox*, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, rtl::OUString const&) Unexecuted instantiation: framework::FixedImageToolbarController::FixedImageToolbarController(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, com::sun::star::uno::Reference<com::sun::star::frame::XFrame> const&, ToolBox*, o3tl::strong_int<unsigned short, ToolBoxItemIdTag>, rtl::OUString const&) |
91 | | |
92 | | void FixedImageToolbarController::disposing(std::unique_lock<std::mutex>& rGuard) |
93 | 0 | { |
94 | 0 | { |
95 | 0 | comphelper::unique_unlock aUnlock(rGuard); |
96 | 0 | SolarMutexGuard aSolarMutexGuard; |
97 | 0 | SvtMiscOptions().RemoveListenerLink( |
98 | 0 | LINK(this, FixedImageToolbarController, MiscOptionsChanged)); |
99 | 0 | m_xToolbar->SetItemWindow(m_nID, nullptr); |
100 | 0 | m_pFixedImageControl.disposeAndClear(); |
101 | 0 | } |
102 | 0 | ComplexToolbarController::disposing(rGuard); |
103 | 0 | } |
104 | | |
105 | 0 | void FixedImageToolbarController::executeControlCommand(const css::frame::ControlCommand&) {} |
106 | | |
107 | | void FixedImageToolbarController::CheckAndUpdateImages() |
108 | 0 | { |
109 | 0 | SolarMutexGuard aSolarMutexGuard; |
110 | |
|
111 | 0 | const sal_Int16 eNewSymbolSize = SvtMiscOptions::GetCurrentSymbolsSize(); |
112 | |
|
113 | 0 | if (m_eSymbolSize == eNewSymbolSize) |
114 | 0 | return; |
115 | | |
116 | 0 | m_eSymbolSize = eNewSymbolSize; |
117 | | |
118 | | // Refresh images if requested |
119 | 0 | ::Size aSize(16, 16); |
120 | 0 | if (m_eSymbolSize == SFX_SYMBOLS_SIZE_LARGE) |
121 | 0 | { |
122 | 0 | aSize.setWidth(26); |
123 | 0 | aSize.setHeight(26); |
124 | 0 | } |
125 | 0 | else if (m_eSymbolSize == SFX_SYMBOLS_SIZE_32) |
126 | 0 | { |
127 | 0 | aSize.setWidth(32); |
128 | 0 | aSize.setHeight(32); |
129 | 0 | } |
130 | 0 | m_pFixedImageControl->SetSizePixel(aSize); |
131 | 0 | } |
132 | | |
133 | | IMPL_LINK_NOARG(FixedImageToolbarController, MiscOptionsChanged, LinkParamNone*, void) |
134 | 0 | { |
135 | 0 | CheckAndUpdateImages(); |
136 | 0 | } |
137 | | |
138 | | } // namespace framework |
139 | | |
140 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |