LibreOffice Module svx (master) 1
xtabptrn.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
22#include <vcl/virdev.hxx>
23#include <svx/strings.hrc>
24#include <svx/dialmgr.hxx>
25#include <svx/xtable.hxx>
26#include <rtl/ustrbuf.hxx>
27#include <vcl/settings.hxx>
28#include <vcl/svapp.hxx>
29#include <vcl/BitmapTools.hxx>
30
31using namespace com::sun::star;
32
34{
35 return static_cast<XBitmapEntry*>( XPropertyList::Get(nIndex) );
36}
37
38uno::Reference< container::XNameContainer > XPatternList::createInstance()
39{
41}
42
44{
45 OUStringBuffer aStr(SvxResId(RID_SVXSTR_PATTERN));
46 std::array<sal_uInt8,64> aArray;
47 BitmapEx aBitmap;
48 const sal_Int32 nLen(aStr.getLength() - 1);
49
50 aArray.fill(0);
51
52 // white/white bitmap
53 aStr.append(" 1");
55 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
56
57 // black/white bitmap
58 aArray[ 0] = 1; aArray[ 9] = 1; aArray[18] = 1; aArray[27] = 1;
59 aArray[36] = 1; aArray[45] = 1; aArray[54] = 1; aArray[63] = 1;
60 aStr[nLen] = '2';
62 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
63
64 // lightred/white bitmap
65 aArray[ 7] = 1; aArray[14] = 1; aArray[21] = 1; aArray[28] = 1;
66 aArray[35] = 1; aArray[42] = 1; aArray[49] = 1; aArray[56] = 1;
67 aStr[nLen] = '3';
69 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
70
71 // lightblue/white bitmap
72 aArray[24] = 1; aArray[25] = 1; aArray[26] = 1;
73 aArray[29] = 1; aArray[30] = 1; aArray[31] = 1;
74 aStr[nLen] = '4';
76 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
77
78 return true;
79}
80
82{
83 assert( nIndex < Count() );
84
85 if(nIndex < Count())
86 {
89 pVirtualDevice->SetOutputSizePixel(rSize);
90
91 if(rBitmapEx.IsAlpha())
92 {
94
95 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
96 {
97 const Point aNull(0, 0);
98 static const sal_uInt32 nLen(8);
99 static const Color aW(COL_WHITE);
100 static const Color aG(0xef, 0xef, 0xef);
101
102 pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
103 }
104 else
105 {
106 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
107 pVirtualDevice->Erase();
108 }
109 }
110
111 if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
112 {
113 rBitmapEx.Scale(rSize);
114 pVirtualDevice->DrawBitmapEx(Point(0, 0), rBitmapEx);
115 }
116 else
117 {
118 const Size aBitmapSize(rBitmapEx.GetSizePixel());
119
120 for(tools::Long y(0); y < rSize.Height(); y += aBitmapSize.Height())
121 {
122 for(tools::Long x(0); x < rSize.Width(); x += aBitmapSize.Width())
123 {
124 pVirtualDevice->DrawBitmapEx(
125 Point(x, y),
126 rBitmapEx);
127 }
128 }
129 }
130 rBitmapEx = pVirtualDevice->GetBitmapEx(Point(0, 0), rSize);
131 return rBitmapEx;
132 }
133 else
134 return BitmapEx();
135}
136
138{
139 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
140 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
141 return CreateBitmap(nIndex, rSize);
142}
143
145{
146 return CreateBitmap(nIndex, rSize);
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< container::XNameContainer > SvxUnoXBitmapTable_createInstance(XPropertyList &rTable) noexcept
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
bool IsAlpha() const
const Size & GetSizePixel() const
const Graphic & GetGraphic() const
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
bool GetPreviewUsesCheckeredBackground() const
const Color & GetFieldColor() const
const Size & GetListBoxPreviewDefaultPixelSize() const
const GraphicObject & GetGraphicObject() const
Definition: xtable.hxx:125
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtabptrn.cxx:137
virtual bool Create() override
Definition: xtabptrn.cxx:43
BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size &rSize)
Definition: xtabptrn.cxx:144
BitmapEx CreateBitmap(tools::Long nIndex, const Size &rSize) const
Definition: xtabptrn.cxx:81
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtabptrn.cxx:38
XBitmapEntry * GetBitmap(tools::Long nIndex) const
Definition: xtabptrn.cxx:33
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
constexpr ::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr ::Color COL_LIGHTBLUE(0x00, 0x00, 0xFF)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
float y
float x
sal_Int32 nIndex
aStr
long Long
BitmapEx createHistorical8x8FromArray(std::array< sal_uInt8, 64 > const &pArray, Color aColorPix, Color aColorBack)