LibreOffice Module svx (master) 1
xtablend.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 <XPropertyTable.hxx>
21#include <vcl/virdev.hxx>
22
23#include <vcl/svapp.hxx>
24#include <vcl/settings.hxx>
25
26#include <svx/strings.hrc>
27#include <svx/dialmgr.hxx>
28#include <osl/diagnose.h>
29
30#include <svx/xtable.hxx>
36#include <memory>
37
38using namespace com::sun::star;
39
40XLineEndList::XLineEndList( const OUString& rPath, const OUString& rReferer )
41 : XPropertyList( XPropertyListType::LineEnd, rPath, rReferer )
42{
43}
44
46{
47}
48
50{
51 return static_cast<XLineEndEntry*>( XPropertyList::Get(nIndex) );
52}
53
54uno::Reference< container::XNameContainer > XLineEndList::createInstance()
55{
57}
58
60{
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 ) ) );
67
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 ) ) );
75
77 Insert( std::make_unique<XLineEndEntry>( basegfx::B2DPolyPolygon(aCircle), SvxResId( RID_SVXSTR_CIRCLE ) ) );
78
79 return true;
80}
81
83{
84 BitmapEx aRetval;
85 OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
86
87 if(nIndex < Count())
88 {
90 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
91
92 const Size aSize(rSize.Width() * 2, rSize.Height());
93
94 // prepare line geometry
96 const double fBorderDistance(aSize.Height() * 0.1);
97
98 aLine.append(basegfx::B2DPoint(fBorderDistance, aSize.Height() / 2));
99 aLine.append(basegfx::B2DPoint(aSize.Width() - fBorderDistance, aSize.Height() / 2));
100
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);
107
109 const double fArrowHeight(aSize.Height() - (2.0 * fBorderDistance));
110 const drawinglayer::attribute::LineStartEndAttribute aLineStartEndAttribute(
111 fArrowHeight,
112 aLineEnd,
113 false);
114
115 // prepare line primitive
116 const drawinglayer::primitive2d::Primitive2DReference aLineStartEndPrimitive(
118 aLine,
119 aLineAttribute,
120 aLineStartEndAttribute,
121 aLineStartEndAttribute));
122
123 // prepare VirtualDevice
125 const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
126
127 pVirtualDevice->SetOutputSizePixel(aSize);
128 pVirtualDevice->SetDrawMode(rStyleSettings.GetHighContrastMode()
129 ? DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient
130 : DrawModeFlags::Default);
131
132 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
133 {
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);
139 }
140 else
141 {
142 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
143 pVirtualDevice->Erase();
144 }
145
146 // create processor and draw primitives
147 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
148 *pVirtualDevice,
149 aNewViewInformation2D));
150
151 const drawinglayer::primitive2d::Primitive2DContainer aSequence { aLineStartEndPrimitive };
152
153 pProcessor2D->process(aSequence);
154 pProcessor2D.reset();
155
156 // get result bitmap and scale
157 aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
158 }
159
160 return aRetval;
161}
162
163/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< container::XNameContainer > SvxUnoXLineEndTable_createInstance(XPropertyList &rTable) noexcept
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
basegfx::BColor getBColor() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool GetPreviewUsesCheckeredBackground() const
const Color & GetFieldTextColor() const
bool GetHighContrastMode() const
const Color & GetFieldColor() const
static sal_uInt16 GetListBoxPreviewDefaultLineWidth()
const Size & GetListBoxPreviewDefaultPixelSize() const
XLineEndList(const OUString &rPath, const OUString &rReferer)
Definition: xtablend.cxx:40
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtablend.cxx:54
virtual bool Create() override
Definition: xtablend.cxx:59
virtual ~XLineEndList() override
Definition: xtablend.cxx:45
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtablend.cxx:82
XLineEndEntry * GetLineEnd(tools::Long nIndex) const
Definition: xtablend.cxx:49
tools::Long Count() const
Definition: xtable.cxx:122
void Insert(std::unique_ptr< XPropertyEntry > pEntry, tools::Long nIndex=std::numeric_limits< tools::Long >::max())
Definition: xtable.cxx:178
XPropertyEntry * Get(tools::Long nIndex) const
Definition: xtable.cxx:132
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
void setClosed(bool bNew)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
sal_Int32 nIndex
LineEnd
B2DPolygon createPolygonFromCircle(const B2DPoint &rCenter, double fRadius)
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
long Long
XPropertyListType
Definition: xtable.hxx:131