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 
31 using namespace com::sun::star;
32 
34 {
35  return static_cast<XBitmapEntry*>( XPropertyList::Get(nIndex) );
36 }
37 
38 uno::Reference< container::XNameContainer > XPatternList::createInstance()
39 {
40  return uno::Reference< container::XNameContainer >(
41  SvxUnoXBitmapTable_createInstance( this ), uno::UNO_QUERY );
42 }
43 
45 {
46  OUStringBuffer aStr(SvxResId(RID_SVXSTR_PATTERN));
47  std::array<sal_uInt8,64> aArray;
48  BitmapEx aBitmap;
49  const sal_Int32 nLen(aStr.getLength() - 1);
50 
51  aArray.fill(0);
52 
53  // white/white bitmap
54  aStr.append(" 1");
56  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
57 
58  // black/white bitmap
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;
61  aStr[nLen] = '2';
63  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
64 
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;
68  aStr[nLen] = '3';
70  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
71 
72  // lightblue/white bitmap
73  aArray[24] = 1; aArray[25] = 1; aArray[26] = 1;
74  aArray[29] = 1; aArray[30] = 1; aArray[31] = 1;
75  aStr[nLen] = '4';
77  Insert(std::make_unique<XBitmapEntry>(Graphic(aBitmap), aStr.toString()));
78 
79  return true;
80 }
81 
82 BitmapEx XPatternList::CreateBitmap( tools::Long nIndex, const Size& rSize ) const
83 {
84  assert( nIndex < Count() );
85 
86  if(nIndex < Count())
87  {
88  BitmapEx rBitmapEx = GetBitmap( nIndex )->GetGraphicObject().GetGraphic().GetBitmapEx();
90  pVirtualDevice->SetOutputSizePixel(rSize);
91 
92  if(rBitmapEx.IsTransparent())
93  {
94  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
95 
96  if(rStyleSettings.GetPreviewUsesCheckeredBackground())
97  {
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);
102 
103  pVirtualDevice->DrawCheckered(aNull, rSize, nLen, aW, aG);
104  }
105  else
106  {
107  pVirtualDevice->SetBackground(rStyleSettings.GetFieldColor());
108  pVirtualDevice->Erase();
109  }
110  }
111 
112  if(rBitmapEx.GetSizePixel().Width() >= rSize.Width() && rBitmapEx.GetSizePixel().Height() >= rSize.Height())
113  {
114  rBitmapEx.Scale(rSize);
115  pVirtualDevice->DrawBitmapEx(Point(0, 0), rBitmapEx);
116  }
117  else
118  {
119  const Size aBitmapSize(rBitmapEx.GetSizePixel());
120 
121  for(tools::Long y(0); y < rSize.Height(); y += aBitmapSize.Height())
122  {
123  for(tools::Long x(0); x < rSize.Width(); x += aBitmapSize.Width())
124  {
125  pVirtualDevice->DrawBitmapEx(
126  Point(x, y),
127  rBitmapEx);
128  }
129  }
130  }
131  rBitmapEx = pVirtualDevice->GetBitmapEx(Point(0, 0), rSize);
132  return rBitmapEx;
133  }
134  else
135  return BitmapEx();
136 }
137 
139 {
140  const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
141  const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
142  return CreateBitmap(nIndex, rSize);
143 }
144 
146 {
147  return CreateBitmap(nIndex, rSize);
148 }
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool Create() override
Definition: xtabptrn.cxx:44
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
long Long
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
bool GetPreviewUsesCheckeredBackground() const
float x
const Size & GetListBoxPreviewDefaultPixelSize() const
uno::Reference< uno::XInterface > SvxUnoXBitmapTable_createInstance(XPropertyList *pTable)
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:25
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTRED
float y
Count
tools::Long Width() const
const Color & GetFieldColor() const
XPropertyEntry * Get(tools::Long nIndex) const
Definition: xtable.cxx:131
bool IsTransparent() const
BitmapEx GetBitmapForPreview(tools::Long nIndex, const Size &rSize)
Definition: xtabptrn.cxx:145
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:38
BitmapEx CreateBitmap(tools::Long nIndex, const Size &rSize) const
Definition: xtabptrn.cxx:82
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
tools::Long Height() const
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_LIGHTBLUE
virtual BitmapEx CreateBitmapForUI(tools::Long nIndex) override
Definition: xtabptrn.cxx:138
XBitmapEntry * GetBitmap(tools::Long nIndex) const
Definition: xtabptrn.cxx:33
const Size & GetSizePixel() const
aStr