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 <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>
33 
34 using namespace com::sun::star;
35 
37 {
38  return static_cast<XBitmapEntry*>( XPropertyList::Get(nIndex) );
39 }
40 
41 uno::Reference< container::XNameContainer > XPatternList::createInstance()
42 {
43  return uno::Reference< container::XNameContainer >(
44  SvxUnoXBitmapTable_createInstance( this ), uno::UNO_QUERY );
45 }
46 
48 {
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);
53 
54  aArray.fill(0);
55 
56  // white/white bitmap
57  aStr.append(" 1");
59  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
60 
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';
66  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
67 
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';
73  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
74 
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';
80  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
81 
82  return true;
83 }
84 
85 BitmapEx XPatternList::CreateBitmap( long nIndex, const Size& rSize ) const
86 {
87  assert( nIndex < Count() );
88 
89  if(nIndex < Count())
90  {
91  BitmapEx rBitmapEx = GetBitmap( nIndex )->GetGraphicObject().GetGraphic().GetBitmapEx();
93  pVirtualDevice->SetOutputSizePixel(rSize);
94 
95  if(rBitmapEx.IsTransparent())
96  {
97  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
98 
99  if(rStyleSettings.GetPreviewUsesCheckeredBackground())
100  {
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);
105 
106  pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
107  }
108  else
109  {
110  pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
111  pVirtualDevice->Erase();
112  }
113  }
114 
115  if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
116  {
117  rBitmapEx.Scale(rSize);
118  pVirtualDevice->DrawBitmapEx(Point(0, 0), rBitmapEx);
119  }
120  else
121  {
122  const Size aBitmapSize(rBitmapEx.GetSizePixel());
123 
124  for(long y(0); y < rSize.Height(); y += aBitmapSize.Height())
125  {
126  for(long x(0); x < rSize.Width(); x += aBitmapSize.Width())
127  {
128  pVirtualDevice->DrawBitmapEx(
129  Point(x, y),
130  rBitmapEx);
131  }
132  }
133  }
134  rBitmapEx = pVirtualDevice->GetBitmapEx(Point(0, 0), rSize);
135  return rBitmapEx;
136  }
137  else
138  return BitmapEx();
139 }
140 
142 {
143  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
144  const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
145  return CreateBitmap(nIndex, rSize);
146 }
147 
148 BitmapEx XPatternList::GetBitmapForPreview( long nIndex, const Size& rSize )
149 {
150  return CreateBitmap(nIndex, rSize);
151 }
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
XPropertyEntry * Get(long nIndex) const
Definition: xtable.cxx:135
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
long Height() const
virtual bool Create() override
Definition: xtabptrn.cxx:47
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool GetPreviewUsesCheckeredBackground() const
BitmapEx GetBitmapForPreview(long nIndex, const Size &rSize)
Definition: xtabptrn.cxx:148
constexpr::Color COL_LIGHTRED(0xFF, 0x00, 0x00)
float x
const Size & GetListBoxPreviewDefaultPixelSize() const
uno::Reference< uno::XInterface > SvxUnoXBitmapTable_createInstance(XPropertyList *pTable)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
float y
Count
const Color & GetFieldColor() const
bool IsTransparent() const
BitmapEx createHistorical8x8FromArray(std::array< sal_uInt8, 64 > const &pArray, Color aColorPix, Color aColorBack)
virtual css::uno::Reference< css::container::XNameContainer > createInstance() override
Definition: xtabptrn.cxx:41
XBitmapEntry * GetBitmap(long nIndex) const
Definition: xtabptrn.cxx:36
virtual BitmapEx CreateBitmapForUI(long nIndex) override
Definition: xtabptrn.cxx:141
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
constexpr::Color COL_LIGHTBLUE(0x00, 0x00, 0xFF)
BitmapEx CreateBitmap(long nIndex, const Size &rSize) const
Definition: xtabptrn.cxx:85
const Size & GetSizePixel() const
aStr