LibreOffice Module sfx2 (master) 1
thumbnailviewitem.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
22#include "thumbnailviewacc.hxx"
23
36#include <vcl/event.hxx>
37#include <vcl/graph.hxx>
38#include <vcl/mnemonic.hxx>
39#include <vcl/outdev.hxx>
40#include <vcl/texteng.hxx>
41#include <bitmaps.hlst>
44
45
46using namespace basegfx;
47using namespace basegfx::utils;
48using namespace ::com::sun::star;
49using namespace drawinglayer::attribute;
50using namespace drawinglayer::primitive2d;
51
53 : mrParent(rView)
54 , mnId(nId)
55 , mbVisible(true)
56 , mbBorder(true)
57 , mbSelected(false)
58 , mbHover(false)
59 , mbPinned(false)
60 , mbPinnedDocumentHighlighted(false)
61 , maPinnedDocumentBitmap(BMP_PIN_DOC)
62 , maPinnedDocumentBitmapHiglighted(BMP_PIN_DOC_HIGHLIGHTED)
63{
64}
65
67{
68 if( mxAcc.is() )
69 {
70 static_cast< ThumbnailViewItemAcc* >( mxAcc.get() )->ParentDestroyed();
71 }
72}
73
74void ThumbnailViewItem::show (bool bVisible)
75{
77}
78
80{
81 mbSelected = state;
82}
83
85{
86 mbHover = state;
87}
88
90{
91 bool bNeedsPaint = false;
92
93 if (bVisible && getDrawArea().Contains(rPoint))
94 {
95 if (!isHighlighted())
96 bNeedsPaint = true;
97 setHighlight(true);
98 }
99 else
100 {
101 if (isHighlighted())
102 bNeedsPaint = true;
103 setHighlight(false);
104 }
105
106 const ::tools::Rectangle aPinPosRectangle(maPinPos, maPinnedDocumentBitmap.GetSizePixel());
107 if (bVisible && aPinPosRectangle.Contains(rPoint))
108 {
110 bNeedsPaint = true;
112 }
113 else
114 {
116 bNeedsPaint = true;
118 }
119
120 if (bNeedsPaint)
121 return getDrawArea();
122
123 return ::tools::Rectangle();
124}
125
126void ThumbnailViewItem::setTitle (const OUString& rTitle)
127{
128 if (mrParent.renameItem(this, rTitle))
129 maTitle = rTitle;
130}
131
132uno::Reference< accessibility::XAccessible > const & ThumbnailViewItem::GetAccessible( bool bIsTransientChildrenDisabled )
133{
134 if( !mxAcc.is() )
135 mxAcc = new ThumbnailViewItemAcc( this, bIsTransientChildrenDisabled );
136
137 return mxAcc;
138}
139
140void ThumbnailViewItem::setDrawArea (const ::tools::Rectangle &area)
141{
142 maDrawArea = area;
143}
144
146 const tools::Long nPadding, sal_uInt32 nMaxTextLength,
147 const ThumbnailItemAttributes *pAttrs)
148{
150 aTextDev.setFontAttribute(pAttrs->aFontAttr,
151 pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
152 css::lang::Locale() );
153
154 Size aImageSize = maPreview1.GetSizePixel();
155
156 // Calculate thumbnail position
157 const Point aPos = maDrawArea.TopCenter();
158 maPrev1Pos = aPos + Point(-aImageSize.Width() / 2, nPadding + (nThumbnailHeight - aImageSize.Height()) / 2);
159
160 // Calculate pin position
161 maPinPos = maDrawArea.TopLeft() + Point(nPadding, nPadding);
162
163 // Calculate text position
164 maTextPos = aPos + Point(-aTextDev.getTextWidth(maTitle, 0, nMaxTextLength) / 2, nThumbnailHeight + nPadding * 2);
165}
166
168 const ThumbnailItemAttributes *pAttrs)
169{
170 BColor aFillColor = pAttrs->aFillColor;
172 double fTransparence = 0.0;
173
174 // Draw background
175 if( mbSelected && mbHover)
176 aFillColor = pAttrs->aSelectHighlightColor;
177 else if (mbSelected || mbHover)
178 {
179 aFillColor = pAttrs->aHighlightColor;
180 if (mbHover)
181 fTransparence = pAttrs->fHighlightTransparence;
182 }
183
184 sal_uInt32 nPrimitive = 0;
187 aFillColor,
188 fTransparence,
189 0.0,
190 true));
191
192 // Draw thumbnail
193 Point aPos = maPrev1Pos;
194 Size aImageSize = maPreview1.GetSizePixel();
195
197 createTranslateB2DHomMatrix(aPos.X(),aPos.Y()),
199 B2DRange(
200 B2DPoint(0,0),
201 B2DPoint(aImageSize.Width(),aImageSize.Height())),
202 false)
203 ));
204
205 // tdf#38742 - draw pinned icon
206 if (mbPinned)
207 {
208 const BitmapEx& aBitmapEx
211 new DiscreteBitmapPrimitive2D(aBitmapEx, B2DPoint(maPinPos.X(), maPinPos.Y())));
212 }
213 else if (mbHover)
214 aSeq[nPrimitive++]
217
218
219 if (mbBorder)
220 {
221 // draw thumbnail borders
222 float fWidth = aImageSize.Width() - 1;
223 float fHeight = aImageSize.Height() - 1;
224 float fPosX = maPrev1Pos.getX();
225 float fPosY = maPrev1Pos.getY();
226
227 B2DPolygon aBounds;
228 aBounds.append(B2DPoint(fPosX,fPosY));
229 aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
230 aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
231 aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
232 aBounds.setClosed(true);
233
235 }
236
237 // Draw text below thumbnail
239
240 pProcessor->process(aSeq);
241}
242
244{
245 // adjust text drawing position according to text font
247 aTextDev.setFontAttribute(
248 pAttrs->aFontAttr,
249 pAttrs->aFontSize.getX(),
250 pAttrs->aFontSize.getY(),
251 css::lang::Locale());
252
253 aPos.setY(aPos.getY() + aTextDev.getTextHeight());
254
255 sal_Int32 nMnemonicPos = -1;
256 OUString aOrigText(mrParent.isDrawMnemonic() ? removeMnemonicFromString(rText, nMnemonicPos) : rText);
257
258 TextEngine aTextEngine;
260 pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(), 0,
261 css::lang::Locale()));
263 aTextEngine.SetText(aOrigText);
264
265 sal_Int32 nPrimitives = rSeq.size();
266 sal_Int32 nFinalPrimCount = nPrimitives + aTextEngine.GetLineCount(0);
267 rSeq.resize(nFinalPrimCount);
268
269 // Create the text primitives
270 sal_Int32 nLineStart = 0;
271 OUString aText(aOrigText);
272 for (sal_Int32 i=0; i < aTextEngine.GetLineCount(0); ++i)
273 {
274 sal_Int32 nLineLength = aTextEngine.GetLineLen(0, i);
275 double nLineWidth = aTextDev.getTextWidth (aText, nLineStart, nLineLength);
276
277 bool bTooLong = (aPos.getY() + aTextEngine.GetCharHeight()) > maDrawArea.Bottom();
278 if (bTooLong && (nLineLength + nLineStart) < aOrigText.getLength())
279 {
280 // Add the '...' to the last line to show, even though it may require to shorten the line
281 double nDotsWidth = aTextDev.getTextWidth("...",0,3);
282
283 sal_Int32 nLength = nLineLength - 1;
284 while ( nDotsWidth + aTextDev.getTextWidth(aText, nLineStart, nLength) > maDrawArea.getOpenWidth() && nLength > 0)
285 {
286 --nLength;
287 }
288
289 aText = OUString::Concat(aText.subView(0, nLineStart+nLength)) + "...";
290 nLineLength = nLength + 3;
291 }
292
293 double nLineX = maDrawArea.Left() + (maDrawArea.getOpenWidth() - nLineWidth) / 2.0;
294
296 pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
297 nLineX, double( aPos.Y() ) ) );
298
299 // setup color
300 BColor aTextColor = pAttrs->aTextColor;
301 if(mbSelected)
302 {
303 if (mbHover)
304 aTextColor = pAttrs->aSelectHighlightTextColor;
305 else
306 aTextColor = pAttrs->aHighlightTextColor;
307 }
308
310 new TextSimplePortionPrimitive2D(aTextMatrix,
311 aText, nLineStart, nLineLength,
312 std::vector<double>(),
313 {},
314 pAttrs->aFontAttr,
315 css::lang::Locale(),
316 aTextColor));
317
318 if (nMnemonicPos != -1 && nMnemonicPos >= nLineStart && nMnemonicPos < nLineStart + nLineLength)
319 {
320 rSeq.resize(nFinalPrimCount + 1);
321
322 auto aTextArray = aTextDev.getTextArray(aText, nLineStart, nLineLength, true);
323
324 auto nPos = nMnemonicPos - nLineStart;
325 auto lc_x1 = nPos ? aTextArray[nPos - 1] : 0;
326 auto lc_x2 = aTextArray[nPos];
327 auto fMnemonicWidth = std::abs(lc_x1 - lc_x2);
328 auto fMnemonicHeight = aTextDev.getUnderlineHeight();
329
330 auto fPosX = nLineX + std::min(lc_x1, lc_x2);
331 auto fPosY = aPos.Y() + aTextDev.getUnderlineOffset();
332
333 B2DPolygon aLine;
334 aLine.append(B2DPoint(fPosX, fPosY));
335 aLine.append(B2DPoint(fPosX + fMnemonicWidth, fPosY));
336
337 drawinglayer::attribute::LineAttribute aLineAttribute(Color(aTextColor).getBColor(), fMnemonicHeight);
338
340 new PolygonStrokePrimitive2D(std::move(aLine), aLineAttribute));
341 }
342
343 nLineStart += nLineLength;
344 aPos.setY(aPos.getY() + aTextEngine.GetCharHeight());
345
346 if (bTooLong)
347 break;
348 }
349}
350
353{
354 return new PolygonHairlinePrimitive2D(rPolygon, Color(128, 128, 128).getBColor());
355}
356
357/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nLineWidth
BaseContainerNodeSharedPtr & mrParent
const Size & GetSizePixel() const
constexpr tools::Long Y() const
void setY(tools::Long nY)
constexpr tools::Long X() const
constexpr tools::Long getX() const
constexpr tools::Long getY() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
sal_uInt16 GetLineCount(sal_uInt32 nParagraph) const
sal_Int32 GetLineLen(sal_uInt32 nParagraph, sal_uInt16 nLine) const
void SetMaxTextWidth(tools::Long nWidth)
tools::Long GetCharHeight() const
void SetText(const OUString &rStr)
void SetFont(const vcl::Font &rFont)
static rtl::Reference< drawinglayer::primitive2d::PolygonHairlinePrimitive2D > createBorderLine(const basegfx::B2DPolygon &rPolygon)
void show(bool bVisible)
void setHighlight(bool state)
bool isHighlighted() const
css::uno::Reference< css::accessibility::XAccessible > const & GetAccessible(bool bIsTransientChildrenDisabled)
css::uno::Reference< css::accessibility::XAccessible > mxAcc
void calculateItemsPosition(const tools::Long nThumbnailHeight, const tools::Long nPadding, sal_uInt32 nMaxTextLength, const ThumbnailItemAttributes *pAttrs)
ThumbnailViewItem(ThumbnailView &rView, sal_uInt16 nId)
BitmapEx maPinnedDocumentBitmapHiglighted
ThumbnailView & mrParent
virtual tools::Rectangle updateHighlight(bool bVisible, const Point &rPoint)
Updates own highlight status based on the aPoint position.
void setSelection(bool state)
tools::Rectangle maDrawArea
void addTextPrimitives(const OUString &rText, const ThumbnailItemAttributes *pAttrs, Point aPos, drawinglayer::primitive2d::Primitive2DContainer &rSeq)
const tools::Rectangle & getDrawArea() const
virtual void Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor, const ThumbnailItemAttributes *pAttrs)
void setDrawArea(const tools::Rectangle &area)
void setTitle(const OUString &rTitle)
Class to display thumbnails with their names below their respective icons.
virtual bool renameItem(ThumbnailViewItem *pItem, const OUString &sNewTitle)
bool isDrawMnemonic() const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void setClosed(bool bNew)
TYPE getX() const
TYPE getY() const
void setFontAttribute(const attribute::FontAttribute &rFontAttribute, double fFontScaleX, double fFontScaleY, const css::lang::Locale &rLocale)
double getTextWidth(const OUString &rText, sal_uInt32 nIndex, sal_uInt32 nLength) const
::std::vector< double > getTextArray(const OUString &rText, sal_uInt32 nIndex, sal_uInt32 nLength, bool bCaret=false) const
void process(const primitive2d::Primitive2DContainer &rSource)
constexpr Point TopLeft() const
constexpr Point TopCenter() const
tools::Long getOpenWidth() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
sal_uInt16 mnId
sal_uInt16 nPos
Definition: linksrc.cxx:118
Sequence< sal_Int8 > aSeq
Definition: lnkbase2.cxx:83
VCL_DLLPUBLIC OUString removeMnemonicFromString(OUString const &rStr, sal_Int32 &rMnemonicPos)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
rtl::Reference< BasePrimitive2D > Primitive2DReference
vcl::Font getVclFontFromFontAttribute(const attribute::FontAttribute &rFontAttribute, double fFontScaleX, double fFontScaleY, double fFontRotation, const css::lang::Locale &rLocale)
int i
long Long
sal_Int16 nId
basegfx::BColor aSelectHighlightColor
basegfx::BColor aSelectHighlightTextColor
basegfx::B2DVector aFontSize
basegfx::BColor aHighlightTextColor
basegfx::BColor aHighlightColor
drawinglayer::attribute::FontAttribute aFontAttr
bool mbVisible
const int THUMBNAILVIEW_ITEM_CORNER
bool bVisible
sal_Int32 nLength