LibreOffice Module framework (master) 1
imagebuttontoolbarcontroller.cxx
Go to the documentation of this file.
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
21
23
24#include <com/sun/star/uno/XComponentContext.hpp>
25
29#include <vcl/svapp.hxx>
30#include <vcl/graph.hxx>
31#include <vcl/graphicfilter.hxx>
32#include <vcl/toolbox.hxx>
33#include <svtools/miscopt.hxx>
34#include <memory>
35
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::awt;
38using namespace ::com::sun::star::uno;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::lang;
41using namespace ::com::sun::star::frame;
42using namespace ::com::sun::star::util;
43
44const ::Size aImageSizeSmall( 16, 16 );
45const ::Size aImageSizeBig( 26, 26 );
46
47namespace framework
48{
49
50static void SubstituteVariables( OUString& aURL )
51{
54}
55
57 const Reference< XComponentContext >& rxContext,
58 const Reference< XFrame >& rFrame,
59 ToolBox* pToolbar,
60 ToolBoxItemId nID,
61 const OUString& aCommand ) :
62 ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
63{
64 bool bBigImages( SvtMiscOptions::AreCurrentSymbolsLarge() );
65
66 Image aImage(AddonsOptions().GetImageFromURL(aCommand, bBigImages, true));
67
68 // Height will be controlled by scaling according to button height
69 m_xToolbar->SetItemImage( m_nID, aImage );
70}
71
73{
74}
75
77{
78 SolarMutexGuard aSolarMutexGuard;
80}
81
82void ImageButtonToolbarController::executeControlCommand( const css::frame::ControlCommand& rControlCommand )
83{
84 SolarMutexGuard aSolarMutexGuard;
85 // i73486 to be downward compatible use old and "wrong" also!
86 if( rControlCommand.Command != "SetImag" &&
87 rControlCommand.Command != "SetImage" )
88 return;
89
90 for ( const NamedValue& rArg : rControlCommand.Arguments )
91 {
92 if ( rArg.Name == "URL" )
93 {
94 OUString aURL;
95 rArg.Value >>= aURL;
96
98
99 Image aImage;
101 aURL,
102 aImage ))
103 {
104 m_xToolbar->SetItemImage( m_nID, aImage );
105
106 // send notification
107 uno::Sequence< beans::NamedValue > aInfo { { "URL", css::uno::Any(aURL) } };
108 addNotifyInfo( "ImageChanged",
110 aInfo );
111 break;
112 }
113 }
114 }
115}
116
117bool ImageButtonToolbarController::ReadImageFromURL( bool bBigImage, const OUString& aImageURL, Image& aImage )
118{
119 std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aImageURL, StreamMode::STD_READ ));
120 if ( !pStream || ( pStream->GetErrorCode() != ERRCODE_NONE ))
121 return false;
122
123 // Use graphic class to also support more graphic formats (bmp,png,...)
124 Graphic aGraphic;
125
127 rGF.ImportGraphic( aGraphic, u"", *pStream );
128
129 BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
130
131 const ::Size aSize = bBigImage ? aImageSizeBig : aImageSizeSmall; // Sizes used for toolbar images
132
133 ::Size aBmpSize = aBitmapEx.GetSizePixel();
134 if ( !aBmpSize.IsEmpty() )
135 {
136 ::Size aNoScaleSize( aBmpSize.Width(), aSize.Height() );
137 if ( aBmpSize != aNoScaleSize )
138 aBitmapEx.Scale( aNoScaleSize, BmpScaleFlag::BestQuality );
139 aImage = Image( aBitmapEx );
140 return true;
141 }
142
143 return false;
144}
145
146} // namespace
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
const Size & GetSizePixel() const
static GraphicFilter & GetGraphicFilter()
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
bool IsEmpty() const
constexpr tools::Long Width() const
static bool AreCurrentSymbolsLarge()
css::uno::Reference< css::frame::XDispatch > getDispatchFromCommand(const OUString &aCommand) const
virtual void SAL_CALL dispose() override
void addNotifyInfo(const OUString &aEventName, const css::uno::Reference< css::frame::XDispatch > &xDispatch, const css::uno::Sequence< css::beans::NamedValue > &rInfo)
ImageButtonToolbarController(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &rFrame, ToolBox *pToolBar, ToolBoxItemId nID, const OUString &aCommand)
virtual void executeControlCommand(const css::frame::ControlCommand &rControlCommand) override
bool ReadImageFromURL(bool bBigImage, const OUString &aImageURL, Image &aImage)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
URL aURL
float u
#define ERRCODE_NONE
const ::Size aImageSizeBig(26, 26)
const ::Size aImageSizeSmall(16, 16)
COMPHELPER_DLLPUBLIC OUString getExpandedUri(css::uno::Reference< css::uno::XComponentContext > const &context, OUString const &uri)
Reference< XComponentContext > getProcessComponentContext()
static void SubstituteVariables(OUString &aURL)
OUString aCommand