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 <sal/log.hxx>
21 #include <vcl/svapp.hxx>
22 #include <vcl/bitmapex.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/BitmapFilter.hxx>
25 #include <vcl/ImageTree.hxx>
26 #include <bitmap/BitmapDisabledImageFilter.hxx>
27 #include <comphelper/lok.hxx>
31 ImplImage::ImplImage(const BitmapEx
&rBitmapEx
)
33 , maSizePixel(rBitmapEx
.GetSizePixel())
34 , maBitmapEx(rBitmapEx
)
38 ImplImage::ImplImage(const OUString
&aStockName
)
40 , maSizePixel() // defer size lookup
41 , maStockName(aStockName
)
45 bool ImplImage::loadStockAtScale(double fScale
, BitmapEx
&rBitmapEx
)
49 ImageLoadFlags eScalingFlags
= ImageLoadFlags::NONE
;
50 sal_Int32 nScalePercentage
= -1;
52 if (comphelper::LibreOfficeKit::isActive()) // scale at the surface
54 nScalePercentage
= fScale
* 100.0;
55 eScalingFlags
= ImageLoadFlags::IgnoreScalingFactor
;
58 OUString aIconTheme
= Application::GetSettings().GetStyleSettings().DetermineIconTheme();
59 if (!ImageTree::get().loadImage(maStockName
, aIconTheme
, aBitmapEx
, true,
60 nScalePercentage
, eScalingFlags
))
62 /* If the uno command has parameters, passed in from a toolbar,
63 * recover from failure by removing the parameters from the file name
65 if (maStockName
.indexOf("%3f") > 0)
67 sal_Int32 nStart
= maStockName
.indexOf("%3f");
68 sal_Int32 nEnd
= maStockName
.lastIndexOf(".");
70 OUString aFileName
= maStockName
.replaceAt(nStart
, nEnd
- nStart
, "");
71 if (!ImageTree::get().loadImage(aFileName
, aIconTheme
, aBitmapEx
, true,
72 nScalePercentage
, eScalingFlags
))
74 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName
<<
75 " and " << aFileName
<< " at " << fScale
);
81 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName
<<
86 rBitmapEx
= aBitmapEx
;
90 Size
ImplImage::getSizePixel()
97 if (loadStockAtScale(1.0, maBitmapEx
))
99 assert(maDisabledBitmapEx
.IsEmpty());
100 assert(maBitmapChecksum
== 0);
101 maSizePixel
= maBitmapEx
.GetSizePixel();
105 SAL_WARN("vcl", "Failed to load stock icon " << maStockName
);
110 /// non-HiDPI compatibility method.
111 BitmapEx
const & ImplImage::getBitmapEx(bool bDisabled
)
113 getSizePixel(); // force load, and at unity scale.
116 // Changed since we last generated this.
117 BitmapChecksum aChecksum
= maBitmapEx
.GetChecksum();
118 if (maBitmapChecksum
!= aChecksum
||
119 maDisabledBitmapEx
.GetSizePixel() != maBitmapEx
.GetSizePixel())
121 maDisabledBitmapEx
= maBitmapEx
;
122 BitmapFilter::Filter(maDisabledBitmapEx
, BitmapDisabledImageFilter());
123 maBitmapChecksum
= aChecksum
;
125 return maDisabledBitmapEx
;
131 bool ImplImage::isEqual(const ImplImage
&ref
) const
133 if (isStock() != ref
.isStock())
136 return maStockName
== ref
.maStockName
;
138 return maBitmapEx
== ref
.maBitmapEx
;
141 BitmapEx
const & ImplImage::getBitmapExForHiDPI(bool bDisabled
)
144 { // check we have the right bitmap cached.
145 // FIXME: DPI scaling should be tied to the outdev really ...
146 double fScale
= comphelper::LibreOfficeKit::getDPIScale();
147 Size
aTarget(maSizePixel
.Width()*fScale
,
148 maSizePixel
.Height()*fScale
);
149 if (maBitmapEx
.GetSizePixel() != aTarget
)
150 loadStockAtScale(fScale
, maBitmapEx
);
152 return getBitmapEx(bDisabled
);
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */