/src/libreoffice/framework/source/uielement/imagebuttontoolbarcontroller.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/imagebuttontoolbarcontroller.hxx> |
21 | | |
22 | | #include <framework/addonsoptions.hxx> |
23 | | |
24 | | #include <com/sun/star/uno/XComponentContext.hpp> |
25 | | |
26 | | #include <comphelper/getexpandeduri.hxx> |
27 | | #include <comphelper/processfactory.hxx> |
28 | | #include <tools/stream.hxx> |
29 | | #include <unotools/ucbstreamhelper.hxx> |
30 | | #include <vcl/svapp.hxx> |
31 | | #include <vcl/graph.hxx> |
32 | | #include <vcl/graphicfilter.hxx> |
33 | | #include <vcl/toolbox.hxx> |
34 | | #include <svtools/miscopt.hxx> |
35 | | #include <memory> |
36 | | |
37 | | using namespace ::com::sun::star; |
38 | | using namespace ::com::sun::star::uno; |
39 | | using namespace ::com::sun::star::beans; |
40 | | using namespace ::com::sun::star::frame; |
41 | | |
42 | | const ::Size aImageSizeSmall( 16, 16 ); |
43 | | const ::Size aImageSizeBig( 26, 26 ); |
44 | | |
45 | | namespace framework |
46 | | { |
47 | | |
48 | | static void SubstituteVariables( OUString& aURL ) |
49 | 0 | { |
50 | 0 | aURL = comphelper::getExpandedUri( |
51 | 0 | comphelper::getProcessComponentContext(), aURL); |
52 | 0 | } |
53 | | |
54 | | ImageButtonToolbarController::ImageButtonToolbarController( |
55 | | const Reference< XComponentContext >& rxContext, |
56 | | const Reference< XFrame >& rFrame, |
57 | | ToolBox* pToolbar, |
58 | | ToolBoxItemId nID, |
59 | | const OUString& aCommand ) : |
60 | 0 | ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand ) |
61 | 0 | { |
62 | 0 | bool bBigImages( SvtMiscOptions::AreCurrentSymbolsLarge() ); |
63 | |
|
64 | 0 | Image aImage(AddonsOptions().GetImageFromURL(aCommand, bBigImages, true)); |
65 | | |
66 | | // Height will be controlled by scaling according to button height |
67 | 0 | m_xToolbar->SetItemImage( m_nID, aImage ); |
68 | 0 | } Unexecuted instantiation: framework::ImageButtonToolbarController::ImageButtonToolbarController(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::ImageButtonToolbarController::ImageButtonToolbarController(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&) |
69 | | |
70 | | ImageButtonToolbarController::~ImageButtonToolbarController() |
71 | 0 | { |
72 | 0 | } |
73 | | |
74 | | void ImageButtonToolbarController::executeControlCommand( const css::frame::ControlCommand& rControlCommand ) |
75 | 0 | { |
76 | 0 | SolarMutexGuard aSolarMutexGuard; |
77 | | // i73486 to be downward compatible use old and "wrong" also! |
78 | 0 | if( rControlCommand.Command != "SetImag" && |
79 | 0 | rControlCommand.Command != "SetImage" ) |
80 | 0 | return; |
81 | | |
82 | 0 | for ( const NamedValue& rArg : rControlCommand.Arguments ) |
83 | 0 | { |
84 | 0 | if ( rArg.Name == "URL" ) |
85 | 0 | { |
86 | 0 | OUString aURL; |
87 | 0 | rArg.Value >>= aURL; |
88 | |
|
89 | 0 | SubstituteVariables( aURL ); |
90 | |
|
91 | 0 | Image aImage; |
92 | 0 | if ( ReadImageFromURL( SvtMiscOptions::AreCurrentSymbolsLarge(), |
93 | 0 | aURL, |
94 | 0 | aImage )) |
95 | 0 | { |
96 | 0 | m_xToolbar->SetItemImage( m_nID, aImage ); |
97 | | |
98 | | // send notification |
99 | 0 | uno::Sequence< beans::NamedValue > aInfo { { u"URL"_ustr, css::uno::Any(aURL) } }; |
100 | 0 | addNotifyInfo( u"ImageChanged"_ustr, |
101 | 0 | getDispatchFromCommand( m_aCommandURL ), |
102 | 0 | aInfo ); |
103 | 0 | break; |
104 | 0 | } |
105 | 0 | } |
106 | 0 | } |
107 | 0 | } |
108 | | |
109 | | // static |
110 | | bool ImageButtonToolbarController::ReadImageFromURL( bool bBigImage, const OUString& aImageURL, Image& aImage ) |
111 | 0 | { |
112 | 0 | std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aImageURL, StreamMode::STD_READ )); |
113 | 0 | if ( !pStream || ( pStream->GetErrorCode() != ERRCODE_NONE )) |
114 | 0 | return false; |
115 | | |
116 | | // Use graphic class to also support more graphic formats (bmp,png,...) |
117 | 0 | Graphic aGraphic; |
118 | |
|
119 | 0 | GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); |
120 | 0 | rGF.ImportGraphic( aGraphic, u"", *pStream ); |
121 | |
|
122 | 0 | Bitmap aBitmap = aGraphic.GetBitmap(); |
123 | |
|
124 | 0 | const ::Size aSize = bBigImage ? aImageSizeBig : aImageSizeSmall; // Sizes used for toolbar images |
125 | |
|
126 | 0 | ::Size aBmpSize = aBitmap.GetSizePixel(); |
127 | 0 | if ( !aBmpSize.IsEmpty() ) |
128 | 0 | { |
129 | 0 | ::Size aNoScaleSize( aBmpSize.Width(), aSize.Height() ); |
130 | 0 | if ( aBmpSize != aNoScaleSize ) |
131 | 0 | aBitmap.Scale( aNoScaleSize, BmpScaleFlag::BestQuality ); |
132 | 0 | aImage = Image( aBitmap ); |
133 | 0 | return true; |
134 | 0 | } |
135 | | |
136 | 0 | return false; |
137 | 0 | } |
138 | | |
139 | | } // namespace |
140 | | |
141 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |