diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2016-03-12 14:13:35 -0600 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-03-12 21:19:58 +0000 |
commit | 02de3a5206c7633d62ebc43edad37747e2c7a1de (patch) | |
tree | 4f856978cb5773607023453f839c5085050ac91d | |
parent | bc573d62203d6001fac95d93107cd181882b5cf2 (diff) |
vcl graph: stop abusing a pointer for a bool
Change-Id: I816fe3a52c03fa5a3fd372492985783f9f6ff91c
Reviewed-on: https://gerrit.libreoffice.org/23181
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/vcl/graph.hxx | 3 | ||||
-rw-r--r-- | vcl/inc/impgraph.hxx | 7 | ||||
-rw-r--r-- | vcl/source/filter/graphicfilter.cxx | 30 | ||||
-rw-r--r-- | vcl/source/gdi/graph.cxx | 10 | ||||
-rw-r--r-- | vcl/source/gdi/impgraph.cxx | 24 |
5 files changed, 45 insertions, 29 deletions
diff --git a/include/vcl/graph.hxx b/include/vcl/graph.hxx index 7514f8767016..0c10149c30a8 100644 --- a/include/vcl/graph.hxx +++ b/include/vcl/graph.hxx @@ -198,7 +198,8 @@ public: GraphicReader* GetContext(); void SetContext( GraphicReader* pReader ); - + void SetDummyContext(bool value); + bool IsDummyContext(); private: friend class GraphicObject; diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx index 2eac350eb3b2..5f26354904d9 100644 --- a/vcl/inc/impgraph.hxx +++ b/vcl/inc/impgraph.hxx @@ -49,7 +49,7 @@ private: sal_uLong mnRefCount; bool mbSwapOut; bool mbSwapUnderway; - + bool mbDummyContext; SvgDataPtr maSvgData; private: @@ -115,8 +115,7 @@ private: GraphicReader* ImplGetContext() { return mpContext;} void ImplSetContext( GraphicReader* pReader ); - -private: + void ImplSetDummyContext( bool value ) { mbDummyContext = value; } bool ImplReadEmbedded( SvStream& rIStream ); bool ImplWriteEmbedded( SvStream& rOStream ); @@ -128,7 +127,7 @@ private: bool ImplSwapOut( SvStream* pOStm ); bool ImplIsSwapOut() const { return mbSwapOut;} - + bool ImplIsDummyContext() const { return mbDummyContext; } void ImplSetLink( const GfxLink& ); GfxLink ImplGetLink(); bool ImplIsLink() const; diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx index 5720ef90028b..5f7ddcc185f3 100644 --- a/vcl/source/filter/graphicfilter.cxx +++ b/vcl/source/filter/graphicfilter.cxx @@ -1326,7 +1326,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat sal_uInt16 nStatus; GraphicReader* pContext = rGraphic.GetContext(); GfxLinkType eLinkType = GFX_LINK_TYPE_NONE; - bool bDummyContext = ( pContext == reinterpret_cast<GraphicReader*>(1) ); + bool bDummyContext = rGraphic.IsDummyContext(); const bool bLinkSet = rGraphic.IsLink(); FilterConfigItem* pFilterConfigItem = nullptr; @@ -1376,7 +1376,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat { if( bDummyContext ) { - rGraphic.SetContext( nullptr ); + rGraphic.SetDummyContext( false ); nStreamBegin = 0; } else @@ -1387,7 +1387,7 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat // if pending, return GRFILTER_OK in order to request more bytes if( rIStream.GetError() == ERRCODE_IO_PENDING ) { - rGraphic.SetContext( reinterpret_cast<GraphicReader*>(1) ); + rGraphic.SetDummyContext(true); rIStream.ResetError(); rIStream.Seek( nStreamBegin ); return (sal_uInt16) ImplSetError( GRFILTER_OK ); @@ -1418,8 +1418,8 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat { if( aFilterName.equalsIgnoreAsciiCase( IMP_GIF ) ) { - if( rGraphic.GetContext() == reinterpret_cast<GraphicReader*>(1) ) - rGraphic.SetContext( nullptr ); + if( rGraphic.IsDummyContext()) + rGraphic.SetDummyContext( false ); if( !ImportGIF( rIStream, rGraphic ) ) nStatus = GRFILTER_FILTERERROR; @@ -1428,8 +1428,8 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat } else if( aFilterName.equalsIgnoreAsciiCase( IMP_PNG ) ) { - if ( rGraphic.GetContext() == reinterpret_cast<GraphicReader*>(1) ) - rGraphic.SetContext( nullptr ); + if( rGraphic.IsDummyContext()) + rGraphic.SetDummyContext( false ); vcl::PNGReader aPNGReader( rIStream ); @@ -1486,8 +1486,8 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat } else if( aFilterName.equalsIgnoreAsciiCase( IMP_JPEG ) ) { - if( rGraphic.GetContext() == reinterpret_cast<GraphicReader*>(1) ) - rGraphic.SetContext( nullptr ); + if( rGraphic.IsDummyContext()) + rGraphic.SetDummyContext( false ); // set LOGSIZE flag always, if not explicitly disabled // (see #90508 and #106763) @@ -1501,8 +1501,8 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat } else if( aFilterName.equalsIgnoreAsciiCase( IMP_SVG ) ) { - if( rGraphic.GetContext() == reinterpret_cast<GraphicReader*>(1) ) - rGraphic.SetContext( nullptr ); + if( rGraphic.IsDummyContext()) + rGraphic.SetDummyContext( false ); const sal_uInt32 nStreamPosition(rIStream.Tell()); const sal_uInt32 nStreamLength(rIStream.Seek(STREAM_SEEK_TO_END) - nStreamPosition); @@ -1571,16 +1571,16 @@ sal_uInt16 GraphicFilter::ImportGraphic( Graphic& rGraphic, const OUString& rPat } else if( aFilterName.equalsIgnoreAsciiCase( IMP_XBM ) ) { - if( rGraphic.GetContext() == reinterpret_cast<GraphicReader*>(1) ) - rGraphic.SetContext( nullptr ); + if( rGraphic.IsDummyContext()) + rGraphic.SetDummyContext( false ); if( !ImportXBM( rIStream, rGraphic ) ) nStatus = GRFILTER_FILTERERROR; } else if( aFilterName.equalsIgnoreAsciiCase( IMP_XPM ) ) { - if( rGraphic.GetContext() == reinterpret_cast<GraphicReader*>(1) ) - rGraphic.SetContext( nullptr ); + if( rGraphic.IsDummyContext()) + rGraphic.SetDummyContext( false ); if( !ImportXPM( rIStream, rGraphic ) ) nStatus = GRFILTER_FILTERERROR; diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx index 2c14d8f3bc9a..b46efa024dad 100644 --- a/vcl/source/gdi/graph.cxx +++ b/vcl/source/gdi/graph.cxx @@ -506,6 +506,16 @@ void Graphic::SetContext( GraphicReader* pReader ) mpImpGraphic->ImplSetContext( pReader ); } +void Graphic::SetDummyContext( bool value ) +{ + mpImpGraphic->ImplSetDummyContext( value ); +} + +bool Graphic::IsDummyContext() +{ + return mpImpGraphic->ImplIsDummyContext(); +} + bool Graphic::SwapOut() { ImplTestRefCount(); diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx index 21d2119e7a99..a8f1d0c7301b 100644 --- a/vcl/source/gdi/impgraph.cxx +++ b/vcl/source/gdi/impgraph.cxx @@ -98,7 +98,8 @@ ImpGraphic::ImpGraphic() : mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), mbSwapOut ( false ), - mbSwapUnderway ( false ) + mbSwapUnderway ( false ), + mbDummyContext ( false ) { } @@ -111,7 +112,8 @@ ImpGraphic::ImpGraphic( const ImpGraphic& rImpGraphic ) : mnSizeBytes ( rImpGraphic.mnSizeBytes ), mnRefCount ( 1UL ), mbSwapOut ( rImpGraphic.mbSwapOut ), - mbSwapUnderway ( false ) + mbSwapUnderway ( false ), + mbDummyContext ( rImpGraphic.mbDummyContext ) { if( mpSwapFile ) mpSwapFile->nRefCount++; @@ -142,7 +144,8 @@ ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) : mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), mbSwapOut ( false ), - mbSwapUnderway ( false ) + mbSwapUnderway ( false ), + mbDummyContext ( false ) { } @@ -156,7 +159,8 @@ ImpGraphic::ImpGraphic( const BitmapEx& rBitmapEx ) : mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), mbSwapOut ( false ), - mbSwapUnderway ( false ) + mbSwapUnderway ( false ), + mbDummyContext ( false ) { } @@ -170,6 +174,7 @@ ImpGraphic::ImpGraphic(const SvgDataPtr& rSvgDataPtr) mnRefCount( 1UL ), mbSwapOut( false ), mbSwapUnderway( false ), + mbDummyContext ( false ), maSvgData(rSvgDataPtr) { } @@ -184,7 +189,8 @@ ImpGraphic::ImpGraphic( const Animation& rAnimation ) : mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), mbSwapOut ( false ), - mbSwapUnderway ( false ) + mbSwapUnderway ( false ), + mbDummyContext ( false ) { } @@ -198,16 +204,15 @@ ImpGraphic::ImpGraphic( const GDIMetaFile& rMtf ) : mnSizeBytes ( 0UL ), mnRefCount ( 1UL ), mbSwapOut ( false ), - mbSwapUnderway ( false ) + mbSwapUnderway ( false ), + mbDummyContext ( false ) { } ImpGraphic::~ImpGraphic() { ImplClear(); - - if( reinterpret_cast<sal_uLong>(mpContext) > 1UL ) - delete mpContext; + delete mpContext; } ImpGraphic& ImpGraphic::operator=( const ImpGraphic& rImpGraphic ) @@ -939,6 +944,7 @@ sal_uLong ImpGraphic::ImplGetAnimationLoopCount() const void ImpGraphic::ImplSetContext( GraphicReader* pReader ) { mpContext = pReader; + mbDummyContext = false; } bool ImpGraphic::ImplReadEmbedded( SvStream& rIStm ) |