LibreOffice Module vcl (master) 1
ImplImage.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
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>
27#include <comphelper/lok.hxx>
28
29#include <image.h>
30
32 : maBitmapChecksum(0)
33 , maSizePixel(rBitmapEx.GetSizePixel())
34 , maBitmapEx(rBitmapEx)
35{
36}
37
38ImplImage::ImplImage(const OUString &aStockName)
39 : maBitmapChecksum(0)
40 , maStockName(aStockName)
41{
42}
43
44bool ImplImage::loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
45{
46 BitmapEx aBitmapEx;
47
49 sal_Int32 nScalePercentage = -1;
50
51 if (comphelper::LibreOfficeKit::isActive()) // scale at the surface
52 {
53 nScalePercentage = fScale * 100.0;
55 }
56
58 if (!ImageTree::get().loadImage(maStockName, aIconTheme, aBitmapEx, true,
59 nScalePercentage, eScalingFlags))
60 {
61 /* If the uno command has parameters, passed in from a toolbar,
62 * recover from failure by removing the parameters from the file name
63 */
64 if (maStockName.indexOf("%3f") > 0)
65 {
66 sal_Int32 nStart = maStockName.indexOf("%3f");
67 sal_Int32 nEnd = maStockName.lastIndexOf(".");
68
69 OUString aFileName = maStockName.replaceAt(nStart, nEnd - nStart, u"");
70 if (!ImageTree::get().loadImage(aFileName, aIconTheme, aBitmapEx, true,
71 nScalePercentage, eScalingFlags))
72 {
73 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
74 " and " << aFileName << " at " << fScale);
75 return false;
76 }
77 }
78 else
79 {
80 SAL_WARN("vcl", "Failed to load scaled image from " << maStockName <<
81 " at " << fScale);
82 return false;
83 }
84 }
85 rBitmapEx = aBitmapEx;
86 return true;
87}
88
90{
91 Size aRet;
92 if (!isSizeEmpty())
93 aRet = maSizePixel;
94 else if (isStock())
95 {
97 {
99 assert(maBitmapChecksum == 0);
101 aRet = maSizePixel;
102 }
103 else
104 SAL_WARN("vcl", "Failed to load stock icon " << maStockName);
105 }
106 return aRet;
107}
108
110BitmapEx const & ImplImage::getBitmapEx(bool bDisabled)
111{
112 getSizePixel(); // force load, and at unity scale.
113 if (bDisabled)
114 {
115 // Changed since we last generated this.
117 if (maBitmapChecksum != aChecksum ||
119 {
122 maBitmapChecksum = aChecksum;
123 }
124 return maDisabledBitmapEx;
125 }
126
127 return maBitmapEx;
128}
129
130bool ImplImage::isEqual(const ImplImage &ref) const
131{
132 if (isStock() != ref.isStock())
133 return false;
134 if (isStock())
135 return maStockName == ref.maStockName;
136 else
137 return maBitmapEx == ref.maBitmapEx;
138}
139
141{
142 if (isStock())
143 { // check we have the right bitmap cached.
144 // FIXME: DPI scaling should be tied to the outdev really ...
146 Size aTarget(maSizePixel.Width()*fScale,
147 maSizePixel.Height()*fScale);
148 if (maBitmapEx.GetSizePixel() != aTarget)
150 }
151 return getBitmapEx(bDisabled);
152}
153
154/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ImageLoadFlags
Definition: ImageTree.hxx:32
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:760
BitmapChecksum GetChecksum() const
Definition: BitmapEx.cxx:230
bool IsEmpty() const
Definition: BitmapEx.cxx:177
const Size & GetSizePixel() const
Definition: bitmapex.hxx:72
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
static VCL_DLLPUBLIC ImageTree & get()
Definition: ImageTree.cxx:16
BitmapChecksum maBitmapChecksum
Definition: image.h:28
BitmapEx const & getBitmapEx(bool bDisabled=false)
Legacy - the original bitmap.
Definition: ImplImage.cxx:110
BitmapEx maBitmapEx
Original bitmap - or cache of a potentially scaled bitmap.
Definition: image.h:36
bool isSizeEmpty() const
Definition: image.h:63
bool isStock() const
Definition: image.h:45
BitmapEx maDisabledBitmapEx
Definition: image.h:37
Size maSizePixel
if non-empty: cached original size of maStockName else Size of maBitmap
Definition: image.h:30
Size getSizePixel()
get size in co-ordinates not scaled for HiDPI
Definition: ImplImage.cxx:89
ImplImage(const BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:31
bool loadStockAtScale(double fScale, BitmapEx &rBitmapEx)
Definition: ImplImage.cxx:44
bool isEqual(const ImplImage &ref) const
Definition: ImplImage.cxx:130
OUString maStockName
If set - defines the bitmap via images.zip*.
Definition: image.h:32
BitmapEx const & getBitmapExForHiDPI(bool bDisabled=false)
Taking account of HiDPI scaling.
Definition: ImplImage.cxx:140
constexpr tools::Long Height() const
constexpr tools::Long Width() const
OUString DetermineIconTheme() const
Determine which icon theme should be used.
float u
#define SAL_WARN(area, stream)