Bump version to 6.4-15
[LibreOffice.git] / svx / source / xoutdev / xtabptrn.cxx
blob9f73b5175763e2f009af093247610823d1fdbda4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svx/XPropertyTable.hxx>
22 #include <vcl/virdev.hxx>
23 #include <svl/itemset.hxx>
24 #include <sfx2/docfile.hxx>
25 #include <svx/strings.hrc>
26 #include <svx/dialmgr.hxx>
27 #include <svx/xtable.hxx>
28 #include <svx/xpool.hxx>
29 #include <svx/xbtmpit.hxx>
30 #include <vcl/settings.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/BitmapTools.hxx>
34 using namespace com::sun::star;
36 XBitmapEntry* XPatternList::GetBitmap(long nIndex) const
38 return static_cast<XBitmapEntry*>( XPropertyList::Get(nIndex) );
41 uno::Reference< container::XNameContainer > XPatternList::createInstance()
43 return uno::Reference< container::XNameContainer >(
44 SvxUnoXBitmapTable_createInstance( this ), uno::UNO_QUERY );
47 bool XPatternList::Create()
49 OUStringBuffer aStr(SvxResId(RID_SVXSTR_PATTERN));
50 std::array<sal_uInt8,64> aArray;
51 BitmapEx aBitmap;
52 const sal_Int32 nLen(aStr.getLength() - 1);
54 aArray.fill(0);
56 // white/white bitmap
57 aStr.append(" 1");
58 aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_WHITE, COL_WHITE);
59 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
61 // black/white bitmap
62 aArray[ 0] = 1; aArray[ 9] = 1; aArray[18] = 1; aArray[27] = 1;
63 aArray[36] = 1; aArray[45] = 1; aArray[54] = 1; aArray[63] = 1;
64 aStr[nLen] = '2';
65 aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_BLACK, COL_WHITE);
66 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
68 // lightred/white bitmap
69 aArray[ 7] = 1; aArray[14] = 1; aArray[21] = 1; aArray[28] = 1;
70 aArray[35] = 1; aArray[42] = 1; aArray[49] = 1; aArray[56] = 1;
71 aStr[nLen] = '3';
72 aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_LIGHTRED, COL_WHITE);
73 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
75 // lightblue/white bitmap
76 aArray[24] = 1; aArray[25] = 1; aArray[26] = 1;
77 aArray[29] = 1; aArray[30] = 1; aArray[31] = 1;
78 aStr[nLen] = '4';
79 aBitmap = vcl::bitmap::createHistorical8x8FromArray(aArray, COL_LIGHTBLUE, COL_WHITE);
80 Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
82 return true;
85 BitmapEx XPatternList::CreateBitmap( long nIndex, const Size& rSize ) const
87 assert( nIndex < Count() );
89 if(nIndex < Count())
91 BitmapEx rBitmapEx = GetBitmap( nIndex )->GetGraphicObject().GetGraphic().GetBitmapEx();
92 ScopedVclPtrInstance< VirtualDevice > pVirtualDevice;
93 pVirtualDevice->SetOutputSizePixel(rSize);
95 if(rBitmapEx.IsTransparent())
97 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
99 if(rStyleSettings.GetPreviewUsesCheckeredBackground())
101 const Point aNull(0, 0);
102 static const sal_uInt32 nLen(8);
103 static const Color aW(COL_WHITE);
104 static const Color aG(0xef, 0xef, 0xef);
106 pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
108 else
110 pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
111 pVirtualDevice->Erase();
115 if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
117 rBitmapEx.Scale(rSize);
118 pVirtualDevice->DrawBitmapEx(Point(0, 0), rBitmapEx);
120 else
122 const Size aBitmapSize(rBitmapEx.GetSizePixel());
124 for(long y(0); y < rSize.Height(); y += aBitmapSize.Height())
126 for(long x(0); x < rSize.Width(); x += aBitmapSize.Width())
128 pVirtualDevice->DrawBitmapEx(
129 Point(x, y),
130 rBitmapEx);
134 rBitmapEx = pVirtualDevice->GetBitmapEx(Point(0, 0), rSize);
135 return rBitmapEx;
137 else
138 return BitmapEx();
141 BitmapEx XPatternList::CreateBitmapForUI( long nIndex )
143 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
144 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
145 return CreateBitmap(nIndex, rSize);
148 BitmapEx XPatternList::GetBitmapForPreview( long nIndex, const Size& rSize )
150 return CreateBitmap(nIndex, rSize);
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */