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 
29 #include <svx/xtable.hxx>
35 #include <memory>
36 
37 using namespace com::sun::star;
38 
39 XLineEndList::XLineEndList( const OUString& rPath, const OUString& rReferer )
40  : XPropertyList( XPropertyListType::LineEnd, rPath, rReferer )
41 {
42 }
43 
45 {
46 }
47 
49 {
50  return static_cast<XLineEndEntry*>( XPropertyList::Get(nIndex) );
51 }
52 
53 uno::Reference< container::XNameContainer > XLineEndList::createInstance()
54 {
55  return uno::Reference< container::XNameContainer >(
56  SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
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  {
89  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
90  const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
91 
92  const Size aSize(rSize.Width() * 2, rSize.Height());
93 
94  // prepare line geometry
95  basegfx::B2DPolygon aLine;
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 
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);
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  if(pProcessor2D)
152  {
153  const drawinglayer::primitive2d::Primitive2DContainer aSequence { aLineStartEndPrimitive };
154 
155  pProcessor2D->process(aSequence);
156  pProcessor2D.reset();
157  }
158 
159  // get result bitmap and scale
160  aRetval = pVirtualDevice->GetBitmapEx(Point(0, 0), pVirtualDevice->GetOutputSizePixel());
161  }
162 
163  return aRetval;
164 }
165 
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
XPropertyEntry * Get(long nIndex) const
Definition: xtable.cxx:131
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
long Height() const
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool GetPreviewUsesCheckeredBackground() const
const Size & GetListBoxPreviewDefaultPixelSize() const
const Color & GetFieldTextColor() const
void Insert(std::unique_ptr< XPropertyEntry > pEntry, long nIndex=std::numeric_limits< long >::max())
Definition: xtable.cxx:177
uno::Reference< uno::XInterface > SvxUnoXLineEndTable_createInstance(XPropertyList *pTable)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
bool GetHighContrastMode() const
virtual ~XLineEndList() override
Definition: xtablend.cxx:44
std::unique_ptr< BaseProcessor2D > createPixelProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
B2DPolygon createPolygonFromCircle(const B2DPoint &rCenter, double fRadius)
XPropertyListType
Definition: xtable.hxx:131
virtual BitmapEx CreateBitmapForUI(long nIndex) override
Definition: xtablend.cxx:82
XLineEndEntry * GetLineEnd(long nIndex) const
Definition: xtablend.cxx:48
XLineEndList(const OUString &rPath, const OUString &rReferer)
Definition: xtablend.cxx:39
const Color & GetFieldColor() const
virtual bool Create() override
Definition: xtablend.cxx:59
LineEnd
void setClosed(bool bNew)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
long Count() const
Definition: xtable.cxx:121
basegfx::BColor getBColor() const
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtablend.cxx:53
static sal_uInt16 GetListBoxPreviewDefaultLineWidth()