summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-02-16 16:13:38 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-02-19 10:13:00 +0100
commit6fbb6d80fe6203ff6f84ee85ca625b6e60bf5bae (patch)
tree1482de217efaafface8b1fa82ecd2320b82a1a68
parent2ab300bfa18cdcc91a9311c4c9710254b0ad7753 (diff)
use std::array in createHistorical8x8FromArray
to make the assumption about the size of the array obvious in the code. Change-Id: I7ebe0b037e3be38f7e33c0160742f829288bb474 Reviewed-on: https://gerrit.libreoffice.org/49938 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--cui/source/tabpages/tppattern.cxx6
-rw-r--r--include/svx/dlgctrl.hxx17
-rw-r--r--include/svx/xbtmpit.hxx3
-rw-r--r--svx/source/accessibility/svxpixelctlaccessiblecontext.cxx8
-rw-r--r--svx/source/dialog/dlgctrl.cxx39
-rw-r--r--svx/source/xoutdev/xattrbmp.cxx2
-rw-r--r--svx/source/xoutdev/xtabptrn.cxx4
7 files changed, 35 insertions, 44 deletions
diff --git a/cui/source/tabpages/tppattern.cxx b/cui/source/tabpages/tppattern.cxx
index 443f5d95f7f0..8933c5fbe18c 100644
--- a/cui/source/tabpages/tppattern.cxx
+++ b/cui/source/tabpages/tppattern.cxx
@@ -60,7 +60,7 @@ class SvxBitmapCtl
{
private:
Color aPixelColor, aBackgroundColor;
- const sal_uInt16* pBmpArray;
+ std::array<sal_uInt8,64> const * pBmpArray;
public:
// Constructor: BitmapCtl for SvxPixelCtl
@@ -74,10 +74,10 @@ public:
{
if (!pBmpArray)
return BitmapEx();
- return createHistorical8x8FromArray(pBmpArray, aPixelColor, aBackgroundColor);
+ return createHistorical8x8FromArray(*pBmpArray, aPixelColor, aBackgroundColor);
}
- void SetBmpArray( const sal_uInt16* pPixel ) { pBmpArray = pPixel; }
+ void SetBmpArray( std::array<sal_uInt8,64> const & pPixel ) { pBmpArray = &pPixel; }
void SetPixelColor( Color aColor ) { aPixelColor = aColor; }
void SetBackgroundColor( Color aColor ) { aBackgroundColor = aColor; }
};
diff --git a/include/svx/dlgctrl.hxx b/include/svx/dlgctrl.hxx
index 26cfb511700c..0cf9220cb34f 100644
--- a/include/svx/dlgctrl.hxx
+++ b/include/svx/dlgctrl.hxx
@@ -27,6 +27,7 @@
#include <svx/xtable.hxx>
#include <rtl/ref.hxx>
#include <o3tl/typed_flags_set.hxx>
+#include <array>
class XOBitmap;
class XOutdevItemPool;
@@ -147,11 +148,12 @@ public:
class SAL_WARN_UNUSED SVX_DLLPUBLIC SvxPixelCtl final : public Control
{
private:
- sal_uInt16 nLines, nSquares;
+ static sal_uInt16 constexpr nLines = 8;
+ static sal_uInt16 constexpr nSquares = nLines * nLines;
Color aPixelColor;
Color aBackgroundColor;
Size aRectSize;
- sal_uInt16* pPixel;
+ std::array<sal_uInt8,nSquares> maPixelData;
bool bPaintable;
//Add member identifying position
Point aFocusPosition;
@@ -163,10 +165,9 @@ private:
void ChangePixel( sal_uInt16 nPixel );
public:
- SvxPixelCtl( vcl::Window* pParent, sal_uInt16 nNumber = 8 );
+ SvxPixelCtl( vcl::Window* pParent );
virtual ~SvxPixelCtl() override;
- virtual void dispose() override;
virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
@@ -178,15 +179,15 @@ public:
void SetPixelColor( const Color& rCol ) { aPixelColor = rCol; }
void SetBackgroundColor( const Color& rCol ) { aBackgroundColor = rCol; }
- sal_uInt16 GetLineCount() const { return nLines; }
+ static sal_uInt16 GetLineCount() { return nLines; }
- sal_uInt16 GetBitmapPixel( const sal_uInt16 nPixelNumber );
- sal_uInt16* GetBitmapPixelPtr() { return pPixel; }
+ sal_uInt8 GetBitmapPixel( const sal_uInt16 nPixelNumber ) const;
+ std::array<sal_uInt8,64> const & GetBitmapPixelPtr() const { return maPixelData; }
void SetPaintable( bool bTmp ) { bPaintable = bTmp; }
void Reset();
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override;
- long GetSquares() const { return nSquares ; }
+ static long GetSquares() { return nSquares ; }
long GetWidth() const { return aRectSize.getWidth() ; }
long GetHeight() const { return aRectSize.getHeight() ; }
diff --git a/include/svx/xbtmpit.hxx b/include/svx/xbtmpit.hxx
index b9ced7c42fb0..7c2e2fa2582c 100644
--- a/include/svx/xbtmpit.hxx
+++ b/include/svx/xbtmpit.hxx
@@ -23,6 +23,7 @@
#include <svx/svxdllapi.h>
#include <svx/xit.hxx>
#include <svtools/grfmgr.hxx>
+#include <array>
class SdrModel;
class BitmapColor;
@@ -30,7 +31,7 @@ class BitmapColor;
// helper to construct historical 8x8 bitmaps with two colors
-BitmapEx SVX_DLLPUBLIC createHistorical8x8FromArray(sal_uInt16 const * pArray, Color aColorPix, Color aColorBack);
+BitmapEx SVX_DLLPUBLIC createHistorical8x8FromArray(std::array<sal_uInt8,64> const & pArray, Color aColorPix, Color aColorBack);
bool SVX_DLLPUBLIC isHistorical8x8(const BitmapEx& rBitmapEx, BitmapColor& o_rBack, BitmapColor& o_rFront);
diff --git a/svx/source/accessibility/svxpixelctlaccessiblecontext.cxx b/svx/source/accessibility/svxpixelctlaccessiblecontext.cxx
index 37c0aabd7b47..7e8aee7af76e 100644
--- a/svx/source/accessibility/svxpixelctlaccessiblecontext.cxx
+++ b/svx/source/accessibility/svxpixelctlaccessiblecontext.cxx
@@ -74,7 +74,7 @@ uno::Reference< XAccessibleContext > SvxPixelCtlAccessible::getAccessibleContext
sal_Int32 SvxPixelCtlAccessible::getAccessibleChildCount( )
{
::osl::MutexGuard aGuard( m_aMutex );
- return mrPixelCtl.GetSquares();
+ return SvxPixelCtl::GetSquares();
}
uno::Reference< XAccessible > SvxPixelCtlAccessible::getAccessibleChild( sal_Int32 i )
{
@@ -450,7 +450,7 @@ void SvxPixelCtlAccessible::NotifyChild(long nIndex,bool bSelect ,bool bCheck)
uno::Reference<XAccessible> SvxPixelCtlAccessible::CreateChild (long nIndex,Point mPoint)
{
bool bPixelColorOrBG = mrPixelCtl.GetBitmapPixel(sal_uInt16(nIndex)) != 0;
- Size size(mrPixelCtl.GetWidth() / mrPixelCtl.GetLineCount(),mrPixelCtl.GetHeight() / mrPixelCtl.GetLineCount());
+ Size size(mrPixelCtl.GetWidth() / SvxPixelCtl::GetLineCount(), mrPixelCtl.GetHeight() / SvxPixelCtl::GetLineCount());
uno::Reference<XAccessible> xChild;
xChild = new SvxPixelCtlAccessibleChild(mrPixelCtl,
bPixelColorOrBG,
@@ -794,8 +794,8 @@ tools::Rectangle const & SvxPixelCtlAccessibleChild::GetBoundingBox()
OUString SvxPixelCtlAccessibleChild::GetName()
{
- sal_Int32 nXIndex = mnIndexInParent % mrParentWindow.GetLineCount();
- sal_Int32 nYIndex = mnIndexInParent / mrParentWindow.GetLineCount();
+ sal_Int32 nXIndex = mnIndexInParent % SvxPixelCtl::GetLineCount();
+ sal_Int32 nYIndex = mnIndexInParent / SvxPixelCtl::GetLineCount();
OUString str = "("
+ OUString::number(nXIndex)
diff --git a/svx/source/dialog/dlgctrl.cxx b/svx/source/dialog/dlgctrl.cxx
index d7f47cc015bc..b6eeafb7ed0f 100644
--- a/svx/source/dialog/dlgctrl.cxx
+++ b/svx/source/dialog/dlgctrl.cxx
@@ -722,20 +722,15 @@ long SvxPixelCtl::ShowPosition( const Point &pt)
}
-SvxPixelCtl::SvxPixelCtl(vcl::Window* pParent, sal_uInt16 nNumber)
+SvxPixelCtl::SvxPixelCtl(vcl::Window* pParent)
: Control(pParent, WB_BORDER)
- , nLines(nNumber)
, bPaintable(true)
, aFocusPosition(0,0)
{
- assert(nLines); // can't have no lines
SetPixelColor( Color( COL_BLACK ) );
SetBackgroundColor( Color( COL_WHITE ) );
SetLineColor( Color( COL_LIGHTGRAY ) );
-
- nSquares = nLines * nLines;
- pPixel = new sal_uInt16[ nSquares ];
- memset(pPixel, 0, nSquares * sizeof(sal_uInt16));
+ maPixelData.fill(0);
}
void SvxPixelCtl::Resize()
@@ -749,27 +744,21 @@ Size SvxPixelCtl::GetOptimalSize() const
return LogicToPixel(Size(72, 72), MapMode(MapUnit::MapAppFont));
}
-VCL_BUILDER_FACTORY_ARGS(SvxPixelCtl, 8)
+VCL_BUILDER_FACTORY(SvxPixelCtl)
SvxPixelCtl::~SvxPixelCtl( )
{
disposeOnce();
}
-void SvxPixelCtl::dispose()
-{
- delete []pPixel;
- Control::dispose();
-}
-
// Changes the foreground or Background color
void SvxPixelCtl::ChangePixel( sal_uInt16 nPixel )
{
- if( *( pPixel + nPixel) == 0 )
- *( pPixel + nPixel) = 1; // could be extended to more colors
+ if( maPixelData[nPixel] == 0 )
+ maPixelData[nPixel] = 1; // could be extended to more colors
else
- *( pPixel + nPixel) = 0;
+ maPixelData[nPixel] = 0;
}
// The clicked rectangle is identified, to change its color
@@ -819,7 +808,7 @@ void SvxPixelCtl::Paint( vcl::RenderContext& rRenderContext, const tools::Rectan
//Draw Rectangles (squares)
rRenderContext.SetLineColor();
- sal_uInt16 nLastPixel = *pPixel ? 0 : 1;
+ sal_uInt16 nLastPixel = maPixelData[0];
for (i = 0; i < nLines; i++)
{
@@ -831,9 +820,9 @@ void SvxPixelCtl::Paint( vcl::RenderContext& rRenderContext, const tools::Rectan
aPtTl.X() = aRectSize.Width() * j / nLines + 1;
aPtBr.X() = aRectSize.Width() * (j + 1) / nLines - 1;
- if (*(pPixel + i * nLines + j) != nLastPixel)
+ if (maPixelData[i * nLines + j] != nLastPixel)
{
- nLastPixel = *(pPixel + i * nLines + j);
+ nLastPixel = maPixelData[i * nLines + j];
// Change color: 0 -> Background color
rRenderContext.SetFillColor(nLastPixel ? aPixelColor : aBackgroundColor);
}
@@ -996,18 +985,18 @@ void SvxPixelCtl::SetXBitmap(const BitmapEx& rBitmapEx)
const BitmapColor aColor(pRead->GetColor(i/8, i%8));
if (aColor == aBack)
- *(pPixel + i) = 0;
+ maPixelData[i] = 0;
else
- *(pPixel + i) = 1;
+ maPixelData[i] = 1;
}
}
}
// Returns a specific pixel
-sal_uInt16 SvxPixelCtl::GetBitmapPixel( const sal_uInt16 nPixel )
+sal_uInt8 SvxPixelCtl::GetBitmapPixel( const sal_uInt16 nPixel ) const
{
- return *( pPixel + nPixel );
+ return maPixelData[nPixel];
}
// Resets to the original state of the control
@@ -1015,7 +1004,7 @@ sal_uInt16 SvxPixelCtl::GetBitmapPixel( const sal_uInt16 nPixel )
void SvxPixelCtl::Reset()
{
// clear pixel area
- memset(pPixel, 0, nSquares * sizeof(sal_uInt16));
+ maPixelData.fill(0);
Invalidate();
}
diff --git a/svx/source/xoutdev/xattrbmp.cxx b/svx/source/xoutdev/xattrbmp.cxx
index 336f84d9c2a8..8e28d1ab2646 100644
--- a/svx/source/xoutdev/xattrbmp.cxx
+++ b/svx/source/xoutdev/xattrbmp.cxx
@@ -144,7 +144,7 @@ XFillBitmapItem::XFillBitmapItem(const XFillBitmapItem& rItem)
{
}
-BitmapEx createHistorical8x8FromArray(sal_uInt16 const *pArray, Color aColorPix, Color aColorBack)
+BitmapEx createHistorical8x8FromArray(std::array<sal_uInt8,64> const & pArray, Color aColorPix, Color aColorBack)
{
vcl::bitmap::RawBitmap aBitmap(Size(8, 8));
diff --git a/svx/source/xoutdev/xtabptrn.cxx b/svx/source/xoutdev/xtabptrn.cxx
index 40e38cb3e331..a42be9e1e6b5 100644
--- a/svx/source/xoutdev/xtabptrn.cxx
+++ b/svx/source/xoutdev/xtabptrn.cxx
@@ -48,11 +48,11 @@ uno::Reference< container::XNameContainer > XPatternList::createInstance()
bool XPatternList::Create()
{
OUStringBuffer aStr(SvxResId(RID_SVXSTR_PATTERN));
- sal_uInt16 aArray[64];
+ std::array<sal_uInt8,64> aArray;
BitmapEx aBitmap;
const sal_Int32 nLen(aStr.getLength() - 1);
- memset(aArray, 0, sizeof(aArray));
+ aArray.fill(0);
// white/white bitmap
aStr.append(" 1");