Kaydet (Commit) 288f0029 authored tarafından José Guilherme Vanz's avatar José Guilherme Vanz Kaydeden (comit) Markus Mohrhard

fdo#52622 - Reduce copy and paste code

This commit removes copy and paste code, creating a constructor for it

Change-Id: I7a66cfda7fc7c11308d155a7a890352fdacfaacc
Reviewed-on: https://gerrit.libreoffice.org/6356Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst 63f70564
......@@ -802,19 +802,6 @@ void SpellDialog::SetLanguage( sal_uInt16 nLang )
m_pLanguageLB->SelectLanguage( nLang );
}
static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
{
Image aRes;
OUString aTmp;
osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
Graphic aGraphic;
const OUString aFilterName( IMP_PNG );
if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
{
aRes = Image( aGraphic.GetBitmapEx() );
}
return aRes;
}
void SpellDialog::SetTitle_Impl(LanguageType nLang)
{
OUString sTitle = rParent.HasGrammarChecking() ? m_sTitleSpellingGrammar : m_sTitleSpelling;
......@@ -876,7 +863,7 @@ int SpellDialog::InitUserDicts()
xSvcInfo->getImplementationName()) );
if (!aDictionaryImageUrl.isEmpty())
{
Image aImage( lcl_GetImageFromPngUrl( aDictionaryImageUrl ) );
Image aImage( aDictionaryImageUrl );
pMenu->SetItemImage( nItemId, aImage );
}
}
......
......@@ -862,26 +862,6 @@ sal_Bool EditView::IsWrongSpelledWordAtPos( const Point& rPosPixel, sal_Bool bMa
return pImpEditView->IsWrongSpelledWord( aPaM , bMarkIfWrong );
}
static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
{
Image aRes;
OUString aTmp;
osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
// OString aPath = OString( aTmp.getStr(), aTmp.getLength(), osl_getThreadTextEncoding() );
#if defined(WNT)
// aTmp = lcl_Win_GetShortPathName( aTmp );
#endif
Graphic aGraphic;
const OUString aFilterName( IMP_PNG );
if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
{
aRes = Image( aGraphic.GetBitmapEx() );
}
return aRes;
}
void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
{
DBG_CHKTHIS( EditView, 0 );
......@@ -1036,7 +1016,7 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link* pCallBack )
xSvcInfo->getImplementationName()) );
if (!aDictionaryImageUrl.isEmpty() )
{
Image aImage( lcl_GetImageFromPngUrl( aDictionaryImageUrl ) );
Image aImage( aDictionaryImageUrl );
pInsertMenu->SetItemImage( nPos, aImage );
}
}
......
......@@ -58,6 +58,7 @@ public:
Image( const Bitmap& rBitmap, const Bitmap& rMaskBitmap );
Image( const Bitmap& rBitmap, const Color& rColor );
Image( const ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic >& rxGraphic );
Image( const OUString &rFileUrl );
~Image();
Size GetSizePixel() const;
......
......@@ -128,27 +128,6 @@ void InsertVerbs_Impl( SfxBindings* pBindings, const com::sun::star::uno::Sequen
}
}
//--------------------------------------------------------------------
static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
{
Image aRes;
OUString aTmp;
osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
Graphic aGraphic;
const OUString aFilterName( IMP_PNG );
if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
{
aRes = Image( aGraphic.GetBitmapEx() );
}
return aRes;
}
PopupMenu* InsertThesaurusSubmenu_Impl( SfxBindings* pBindings, Menu* pSVMenu )
{
......@@ -188,7 +167,7 @@ PopupMenu* InsertThesaurusSubmenu_Impl( SfxBindings* pBindings, Menu* pSVMenu )
OUString sThesImplName( aHelper.GetThesImplName( aLocale ) );
OUString aSynonymsImageUrl( aCfg.GetSynonymsContextImage( sThesImplName ) );
if (!sThesImplName.isEmpty() && !aSynonymsImageUrl.isEmpty())
aImage = Image( lcl_GetImageFromPngUrl( aSynonymsImageUrl ) );
aImage = Image( aSynonymsImageUrl );
for (sal_uInt16 i = 0; (size_t)i < nNumSynonyms; ++i)
{
......
......@@ -228,22 +228,6 @@ void SwSpellPopup::fillLangPopupMenu(
pPopupMenu->InsertItem( nLangItemIdStart + MN_MORE_OFFSET, OUString(SW_RES( STR_LANGSTATUS_MORE )), 0 );
}
static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
{
Image aRes;
OUString aTmp;
osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
Graphic aGraphic;
const OUString aFilterName( IMP_PNG );
if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
{
aRes = Image( aGraphic.GetBitmapEx() );
}
return aRes;
}
OUString RetrieveLabelFromCommand( const OUString& aCmdURL )
{
OUString aLabel;
......@@ -322,7 +306,7 @@ SwSpellPopup::SwSpellPopup(
if (xNamed.is())
{
aSuggestionImageUrl = aCfg.GetSpellAndGrammarContextSuggestionImage( xNamed->getName() );
aImage = Image( lcl_GetImageFromPngUrl( aSuggestionImageUrl ) );
aImage = Image( aSuggestionImageUrl );
}
}
......@@ -416,7 +400,7 @@ SwSpellPopup::SwSpellPopup(
xSvcInfo->getImplementationName() ) );
if (!aDictionaryImageUrl.isEmpty())
{
Image aImage( lcl_GetImageFromPngUrl( aDictionaryImageUrl ) );
Image aImage( aDictionaryImageUrl );
pMenu->SetItemImage( nItemId, aImage );
}
}
......@@ -537,7 +521,7 @@ aInfo16( SW_RES(IMG_INFO_16) )
if (xInfo.is())
{
aSuggestionImageUrl = SvtLinguConfig().GetSpellAndGrammarContextSuggestionImage( xInfo->getImplementationName() );
aImage = Image( lcl_GetImageFromPngUrl( aSuggestionImageUrl ) );
aImage = Image( aSuggestionImageUrl );
}
}
......
......@@ -21,6 +21,7 @@
#include <boost/scoped_array.hpp>
#include <osl/file.hxx>
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#include <tools/rc.h>
......@@ -29,6 +30,7 @@
#include <vcl/settings.hxx>
#include <vcl/outdev.hxx>
#include <vcl/graph.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/svapp.hxx>
#include <vcl/image.hxx>
#include <vcl/imagerepository.hxx>
......@@ -151,6 +153,20 @@ Image::Image( const uno::Reference< graphic::XGraphic >& rxGraphic ) :
ImplInit( aGraphic.GetBitmapEx() );
}
Image::Image( const OUString &rFileUrl ) :
mpImplData( NULL )
{
DBG_CTOR( Image, NULL );
OUString aTmp;
osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
Graphic aGraphic;
const OUString aFilterName( IMP_PNG );
if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
{
ImplInit( aGraphic.GetBitmapEx() );
}
}
Image::~Image()
{
DBG_DTOR( Image, NULL );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment