Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / sfx2 / source / control / templateviewitem.cxx
blob3dd20a30fd64c76b2c84bd7f65add67986a1ffe4
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/.
8 */
10 #include <templateviewitem.hxx>
12 #include <basegfx/matrix/b2dhommatrixtools.hxx>
13 #include <basegfx/polygon/b2dpolygon.hxx>
14 #include <drawinglayer/attribute/fillgraphicattribute.hxx>
15 #include <drawinglayer/primitive2d/fillgraphicprimitive2d.hxx>
16 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
17 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
18 #include <drawinglayer/primitive2d/PolyPolygonSelectionPrimitive2D.hxx>
19 #include <drawinglayer/primitive2d/discretebitmapprimitive2d.hxx>
20 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
21 #include <tools/poly.hxx>
22 #include <vcl/graph.hxx>
24 #include <bitmaps.hlst>
26 using namespace basegfx;
27 using namespace basegfx::utils;
28 using namespace drawinglayer::attribute;
29 using namespace drawinglayer::primitive2d;
31 TemplateViewItem::TemplateViewItem (ThumbnailViewBase &rView, sal_uInt16 nId)
32 : ThumbnailViewItem(rView, nId),
33 mnRegionId(USHRT_MAX),
34 mnDocId(USHRT_MAX),
35 maDefaultBitmap(BMP_DEFAULT),
36 mbIsDefaultTemplate(false)
40 TemplateViewItem::~TemplateViewItem ()
44 ::tools::Rectangle TemplateViewItem::getDefaultIconArea() const
46 ::tools::Rectangle aArea(getDrawArea());
47 Size aSize(maDefaultBitmap.GetSizePixel());
49 return ::tools::Rectangle(
50 Point(aArea.Left() + THUMBNAILVIEW_ITEM_CORNER, aArea.Top() + THUMBNAILVIEW_ITEM_CORNER),
51 aSize);
54 void TemplateViewItem::Paint(drawinglayer::processor2d::BaseProcessor2D *pProcessor,
55 const ThumbnailItemAttributes *pAttrs)
57 BColor aFillColor = pAttrs->aFillColor;
59 drawinglayer::primitive2d::Primitive2DContainer aSeq(5);
60 double fTransparence = 0.0;
62 // Draw background
63 if( mbSelected && mbHover)
64 aFillColor = pAttrs->aSelectHighlightColor;
65 else if (mbSelected || mbHover)
67 aFillColor = pAttrs->aHighlightColor;
68 if (mbHover)
69 fTransparence = pAttrs->fHighlightTransparence;
72 aSeq[0] = drawinglayer::primitive2d::Primitive2DReference(
73 new PolyPolygonSelectionPrimitive2D( B2DPolyPolygon(::tools::Polygon(maDrawArea,5,5).getB2DPolygon()),
74 aFillColor,
75 fTransparence,
76 0.0,
77 true));
79 // Draw thumbnail
80 Size aImageSize = maPreview1.GetSizePixel();
82 float fWidth = aImageSize.Width();
83 float fHeight = aImageSize.Height();
84 float fPosX = maPrev1Pos.getX();
85 float fPosY = maPrev1Pos.getY();
87 B2DPolygon aBounds;
88 aBounds.append(B2DPoint(fPosX,fPosY));
89 aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
90 aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
91 aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
92 aBounds.setClosed(true);
94 aSeq[1] = drawinglayer::primitive2d::Primitive2DReference( new PolyPolygonColorPrimitive2D(
95 B2DPolyPolygon(aBounds), COL_WHITE.getBColor()));
97 aSeq[2] = drawinglayer::primitive2d::Primitive2DReference( new FillGraphicPrimitive2D(
98 createTranslateB2DHomMatrix(maPrev1Pos.X(),maPrev1Pos.Y()),
99 FillGraphicAttribute(Graphic(maPreview1),
100 B2DRange(
101 B2DPoint(0,0),
102 B2DPoint(aImageSize.Width(),aImageSize.Height())),
103 false)
106 // draw thumbnail borders
107 aSeq[3] = drawinglayer::primitive2d::Primitive2DReference(createBorderLine(aBounds));
109 if(mbIsDefaultTemplate)
111 Point aIconPos(getDefaultIconArea().TopLeft());
113 aSeq[4] = drawinglayer::primitive2d::Primitive2DReference(new DiscreteBitmapPrimitive2D( maDefaultBitmap,
114 B2DPoint(aIconPos.X(), aIconPos.Y())));
117 addTextPrimitives(maTitle, pAttrs, maTextPos, aSeq);
119 pProcessor->process(aSeq);
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */