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 uno::Reference
< container::XNameContainer
>(
41 SvxUnoXBitmapTable_createInstance( this ), uno::UNO_QUERY
);
44 bool XPatternList::Create()
46 OUStringBuffer
aStr(SvxResId(RID_SVXSTR_PATTERN
));
47 std::array
<sal_uInt8
,64> aArray
;
49 const sal_Int32
nLen(aStr
.getLength() - 1);
55 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_WHITE
, COL_WHITE
);
56 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
59 aArray
[ 0] = 1; aArray
[ 9] = 1; aArray
[18] = 1; aArray
[27] = 1;
60 aArray
[36] = 1; aArray
[45] = 1; aArray
[54] = 1; aArray
[63] = 1;
62 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_BLACK
, COL_WHITE
);
63 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
65 // lightred/white bitmap
66 aArray
[ 7] = 1; aArray
[14] = 1; aArray
[21] = 1; aArray
[28] = 1;
67 aArray
[35] = 1; aArray
[42] = 1; aArray
[49] = 1; aArray
[56] = 1;
69 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_LIGHTRED
, COL_WHITE
);
70 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
72 // lightblue/white bitmap
73 aArray
[24] = 1; aArray
[25] = 1; aArray
[26] = 1;
74 aArray
[29] = 1; aArray
[30] = 1; aArray
[31] = 1;
76 aBitmap
= vcl::bitmap::createHistorical8x8FromArray(aArray
, COL_LIGHTBLUE
, COL_WHITE
);
77 Insert(std::make_unique
<XBitmapEntry
>(Graphic(aBitmap
), aStr
.toString()));
82 BitmapEx
XPatternList::CreateBitmap( tools::Long nIndex
, const Size
& rSize
) const
84 assert( nIndex
< Count() );
88 BitmapEx rBitmapEx
= GetBitmap( nIndex
)->GetGraphicObject().GetGraphic().GetBitmapEx();
89 ScopedVclPtrInstance
< VirtualDevice
> pVirtualDevice
;
90 pVirtualDevice
->SetOutputSizePixel(rSize
);
92 if(rBitmapEx
.IsAlpha())
94 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
96 if(rStyleSettings
.GetPreviewUsesCheckeredBackground())
98 const Point
aNull(0, 0);
99 static const sal_uInt32
nLen(8);
100 static const Color
aW(COL_WHITE
);
101 static const Color
aG(0xef, 0xef, 0xef);
103 pVirtualDevice
->DrawCheckered(aNull
, rSize
, nLen
, aW
, aG
);
107 pVirtualDevice
->SetBackground(rStyleSettings
.GetFieldColor());
108 pVirtualDevice
->Erase();
112 if(rBitmapEx
.GetSizePixel().Width() >= rSize
.Width() && rBitmapEx
.GetSizePixel().Height() >= rSize
.Height())
114 rBitmapEx
.Scale(rSize
);
115 pVirtualDevice
->DrawBitmapEx(Point(0, 0), rBitmapEx
);
119 const Size
aBitmapSize(rBitmapEx
.GetSizePixel());
121 for(tools::Long
y(0); y
< rSize
.Height(); y
+= aBitmapSize
.Height())
123 for(tools::Long
x(0); x
< rSize
.Width(); x
+= aBitmapSize
.Width())
125 pVirtualDevice
->DrawBitmapEx(
131 rBitmapEx
= pVirtualDevice
->GetBitmapEx(Point(0, 0), rSize
);
138 BitmapEx
XPatternList::CreateBitmapForUI( tools::Long nIndex
)
140 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
141 const Size
& rSize
= rStyleSettings
.GetListBoxPreviewDefaultPixelSize();
142 return CreateBitmap(nIndex
, rSize
);
145 BitmapEx
XPatternList::GetBitmapForPreview( tools::Long nIndex
, const Size
& rSize
)
147 return CreateBitmap(nIndex
, rSize
);
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */