1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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>
31 using namespace com::sun::star
;
33 XBitmapEntry
* XPatternList::GetBitmap(tools::Long nIndex
) const
35 return static_cast<XBitmapEntry
*>( XPropertyList::Get(nIndex
) );
38 uno::Reference
< container::XNameContainer
> XPatternList::createInstance()
40 return SvxUnoXBitmapTable_createInstance( *this );
43 bool XPatternList::Create()
45 OUStringBuffer
aStr(SvxResId(RID_SVXSTR_PATTERN
));
46 std::array
<sal_uInt8
,64> aArray
;
48 const sal_Int32
nLen(aStr
.getLength() - 1);
54 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_WHITE
, COL_WHITE
);
55 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
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;
61 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_BLACK
, COL_WHITE
);
62 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
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;
68 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_LIGHTRED
, COL_WHITE
);
69 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
71 // lightblue/white bitmap
72 aArray
[24] = 1; aArray
[25] = 1; aArray
[26] = 1;
73 aArray
[29] = 1; aArray
[30] = 1; aArray
[31] = 1;
75 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_LIGHTBLUE
, COL_WHITE
);
76 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
81 BitmapEx
XPatternList::CreateBitmap( tools::Long nIndex
, const Size
& rSize
) const
83 assert( nIndex
< Count() );
87 BitmapEx rBitmapEx
= GetBitmap( nIndex
)->GetGraphicObject().GetGraphic().GetBitmapEx();
88 ScopedVclPtrInstance
< VirtualDevice
> pVirtualDevice
;
89 pVirtualDevice
->SetOutputSizePixel(rSize
);
91 if(rBitmapEx
.IsAlpha())
93 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
95 if(rStyleSettings
.GetPreviewUsesCheckeredBackground())
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);
102 pVirtualDevice
->DrawCheckered(aNull
, rSize
, nLen
, aW
, aG
);
106 pVirtualDevice
->SetBackground(rStyleSettings
.GetFieldColor());
107 pVirtualDevice
->Erase();
111 if(rBitmapEx
.GetSizePixel().Width() >= rSize
.Width() && rBitmapEx
.GetSizePixel().Height() >= rSize
.Height())
113 rBitmapEx
.Scale(rSize
);
114 pVirtualDevice
->DrawBitmapEx(Point(0, 0), rBitmapEx
);
118 const Size
aBitmapSize(rBitmapEx
.GetSizePixel());
120 for(tools::Long
y(0); y
< rSize
.Height(); y
+= aBitmapSize
.Height())
122 for(tools::Long
x(0); x
< rSize
.Width(); x
+= aBitmapSize
.Width())
124 pVirtualDevice
->DrawBitmapEx(
130 rBitmapEx
= pVirtualDevice
->GetBitmapEx(Point(0, 0), rSize
);
137 BitmapEx
XPatternList::CreateBitmapForUI( tools::Long nIndex
)
139 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
140 const Size
& rSize
= rStyleSettings
.GetListBoxPreviewDefaultPixelSize();
141 return CreateBitmap(nIndex
, rSize
);
144 BitmapEx
XPatternList::GetBitmapForPreview( tools::Long nIndex
, const Size
& rSize
)
146 return CreateBitmap(nIndex
, rSize
);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */