bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / xoutdev / xtablend.cxx
blob39a963373c717e705f733dee53030410f96da7c7
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 <XPropertyTable.hxx>
21 #include <vcl/virdev.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/settings.hxx>
26 #include <svx/strings.hrc>
27 #include <svx/dialmgr.hxx>
29 #include <svx/xtable.hxx>
30 #include <drawinglayer/attribute/linestartendattribute.hxx>
31 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
32 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
33 #include <drawinglayer/processor2d/processor2dtools.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <memory>
37 using namespace com::sun::star;
39 XLineEndList::XLineEndList( const OUString& rPath, const OUString& rReferer )
40 : XPropertyList( XPropertyListType::LineEnd, rPath, rReferer )
44 XLineEndList::~XLineEndList()
48 XLineEndEntry* XLineEndList::GetLineEnd(tools::Long nIndex) const
50 return static_cast<XLineEndEntry*>( XPropertyList::Get(nIndex) );
53 uno::Reference< container::XNameContainer > XLineEndList::createInstance()
55 return uno::Reference< container::XNameContainer >(
56 SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
59 bool XLineEndList::Create()
61 basegfx::B2DPolygon aTriangle;
62 aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
63 aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
64 aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
65 aTriangle.setClosed(true);
66 Insert( std::make_unique<XLineEndEntry>( basegfx::B2DPolyPolygon(aTriangle), SvxResId( RID_SVXSTR_ARROW ) ) );
68 basegfx::B2DPolygon aSquare;
69 aSquare.append(basegfx::B2DPoint(0.0, 0.0));
70 aSquare.append(basegfx::B2DPoint(10.0, 0.0));
71 aSquare.append(basegfx::B2DPoint(10.0, 10.0));
72 aSquare.append(basegfx::B2DPoint(0.0, 10.0));
73 aSquare.setClosed(true);
74 Insert( std::make_unique<XLineEndEntry>( basegfx::B2DPolyPolygon(aSquare), SvxResId( RID_SVXSTR_SQUARE ) ) );
76 basegfx::B2DPolygon aCircle(basegfx::utils::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
77 Insert( std::make_unique<XLineEndEntry>( basegfx::B2DPolyPolygon(aCircle), SvxResId( RID_SVXSTR_CIRCLE ) ) );
79 return true;
82 BitmapEx XLineEndList::CreateBitmapForUI( tools::Long nIndex )
84 BitmapEx aRetval;
85 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
87 if(nIndex < Count())
89 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
90 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
92 const Size aSize(rSize.Width() * 2, rSize.Height());
94 // prepare line geometry
95 basegfx::B2DPolygon aLine;
96 const double fBorderDistance(aSize.Height() * 0.1);
98 aLine.append(basegfx::B2DPoint(fBorderDistance, aSize.Height() / 2));
99 aLine.append(basegfx::B2DPoint(aSize.Width() - fBorderDistance, aSize.Height() / 2));
101 // prepare LineAttribute
102 const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
103 const double fLineWidth(StyleSettings::GetListBoxPreviewDefaultLineWidth() * 1.1);
104 const drawinglayer::attribute::LineAttribute aLineAttribute(
105 aLineColor,
106 fLineWidth);
108 const basegfx::B2DPolyPolygon aLineEnd(GetLineEnd(nIndex)->GetLineEnd());
109 const double fArrowHeight(aSize.Height() - (2.0 * fBorderDistance));
110 const drawinglayer::attribute::LineStartEndAttribute aLineStartEndAttribute(
111 fArrowHeight,
112 aLineEnd,
113 false);
115 // prepare line primitive
116 const drawinglayer::primitive2d::Primitive2DReference aLineStartEndPrimitive(
117 new drawinglayer::primitive2d::PolygonStrokeArrowPrimitive2D(
118 aLine,
119 aLineAttribute,
120 aLineStartEndAttribute,
121 aLineStartEndAttribute));
123 // prepare VirtualDevice
124 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
125 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
127 pVirtualDevice->SetOutputSizePixel(aSize);
128 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
129 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
130 : DrawModeFlags::Default);
132 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
134 const Point aNull(0, 0);
135 static const sal_uInt32 nLen(8);
136 static const Color aW(COL_WHITE);
137 static const Color aG(0xef, 0xef, 0xef);
138 pVirtualDevice->DrawCheckered(aNull, aSize, nLen, aW, aG);
140 else
142 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
143 pVirtualDevice->Erase();
146 // create processor and draw primitives
147 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
148 *pVirtualDevice,
149 aNewViewInformation2D));
151 const drawinglayer::primitive2d::Primitive2DContainer aSequence { aLineStartEndPrimitive };
153 pProcessor2D->process(aSequence);
154 pProcessor2D.reset();
156 // get result bitmap and scale
157 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
160 return aRetval;
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */