fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / framework / source / uielement / imagebuttontoolbarcontroller.cxx
blob34e761f22f6a26a2c398862d60f0c6492ead9737
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/imagebuttontoolbarcontroller.hxx"
22 #include <framework/addonsoptions.hxx>
24 #include <com/sun/star/util/XURLTransformer.hpp>
25 #include <com/sun/star/frame/XDispatchProvider.hpp>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/frame/XControlNotificationListener.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <osl/mutex.hxx>
31 #include <comphelper/getexpandeduri.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <unotools/ucbstreamhelper.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/mnemonic.hxx>
36 #include <vcl/window.hxx>
37 #include <vcl/graph.hxx>
38 #include <vcl/bitmap.hxx>
39 #include <vcl/graphicfilter.hxx>
40 #include <vcl/toolbox.hxx>
41 #include <svtools/miscopt.hxx>
42 #include <boost/scoped_ptr.hpp>
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::awt;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::beans;
48 using namespace ::com::sun::star::lang;
49 using namespace ::com::sun::star::frame;
50 using namespace ::com::sun::star::util;
52 const ::Size aImageSizeSmall( 16, 16 );
53 const ::Size aImageSizeBig( 26, 26 );
55 namespace framework
58 static void SubstituteVariables( OUString& aURL )
60 aURL = comphelper::getExpandedUri(
61 comphelper::getProcessComponentContext(), aURL);
64 ImageButtonToolbarController::ImageButtonToolbarController(
65 const Reference< XComponentContext >& rxContext,
66 const Reference< XFrame >& rFrame,
67 ToolBox* pToolbar,
68 sal_uInt16 nID,
69 const OUString& aCommand ) :
70 ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
72 bool bBigImages( SvtMiscOptions().AreCurrentSymbolsLarge() );
74 Image aImage = AddonsOptions().GetImageFromURL( aCommand, bBigImages, true );
76 // Height will be controlled by scaling according to button height
77 m_pToolbar->SetItemImage( m_nID, aImage );
80 ImageButtonToolbarController::~ImageButtonToolbarController()
84 void SAL_CALL ImageButtonToolbarController::dispose()
85 throw ( RuntimeException, std::exception )
87 SolarMutexGuard aSolarMutexGuard;
88 ComplexToolbarController::dispose();
91 void ImageButtonToolbarController::executeControlCommand( const ::com::sun::star::frame::ControlCommand& rControlCommand )
93 SolarMutexGuard aSolarMutexGuard;
94 // i73486 to be downward compatible use old and "wrong" also!
95 if( rControlCommand.Command == "SetImag" ||
96 rControlCommand.Command == "SetImage" )
98 for ( sal_Int32 i = 0; i < rControlCommand.Arguments.getLength(); i++ )
100 if ( rControlCommand.Arguments[i].Name == "URL" )
102 OUString aURL;
103 rControlCommand.Arguments[i].Value >>= aURL;
105 SubstituteVariables( aURL );
107 Image aImage;
108 if ( ReadImageFromURL( SvtMiscOptions().AreCurrentSymbolsLarge(),
109 aURL,
110 aImage ))
112 m_pToolbar->SetItemImage( m_nID, aImage );
114 // send notification
115 uno::Sequence< beans::NamedValue > aInfo( 1 );
116 aInfo[0].Name = "URL";
117 aInfo[0].Value <<= aURL;
118 addNotifyInfo( OUString( "ImageChanged" ),
119 getDispatchFromCommand( m_aCommandURL ),
120 aInfo );
121 break;
128 bool ImageButtonToolbarController::ReadImageFromURL( bool bBigImage, const OUString& aImageURL, Image& aImage )
130 boost::scoped_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream( aImageURL, STREAM_STD_READ ));
131 if ( pStream && ( pStream->GetErrorCode() == 0 ))
133 // Use graphic class to also support more graphic formats (bmp,png,...)
134 Graphic aGraphic;
136 GraphicFilter& rGF = GraphicFilter::GetGraphicFilter();
137 rGF.ImportGraphic( aGraphic, OUString(), *pStream, GRFILTER_FORMAT_DONTKNOW );
139 BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
141 const ::Size aSize = bBigImage ? aImageSizeBig : aImageSizeSmall; // Sizes used for toolbar images
143 ::Size aBmpSize = aBitmapEx.GetSizePixel();
144 if ( aBmpSize.Width() > 0 && aBmpSize.Height() > 0 )
146 ::Size aNoScaleSize( aBmpSize.Width(), aSize.Height() );
147 if ( aBmpSize != aNoScaleSize )
148 aBitmapEx.Scale( aNoScaleSize, BmpScaleFlag::BestQuality );
149 aImage = Image( aBitmapEx );
150 return true;
154 return false;
157 } // namespace
159 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */