[Libreoffice-commits] core.git: cui/source editeng/source include/vcl sfx2/source sw/source vcl/source

José Guilherme Vanz vanz at libreoffice.org
Sun Oct 20 05:26:04 PDT 2013


 cui/source/dialogs/SpellDialog.cxx  |   15 +--------------
 editeng/source/editeng/editview.cxx |   22 +---------------------
 include/vcl/image.hxx               |    1 +
 sfx2/source/menu/mnumgr.cxx         |   23 +----------------------
 sw/source/ui/lingu/olmenu.cxx       |   22 +++-------------------
 vcl/source/gdi/image.cxx            |   16 ++++++++++++++++
 6 files changed, 23 insertions(+), 76 deletions(-)

New commits:
commit 288f0029c69ab0532165877637a146f774d5e740
Author: José Guilherme Vanz <vanz at libreoffice.org>
Date:   Sun Oct 20 01:43:00 2013 -0200

    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/6356
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/cui/source/dialogs/SpellDialog.cxx b/cui/source/dialogs/SpellDialog.cxx
index 0686caf..d32a172 100644
--- a/cui/source/dialogs/SpellDialog.cxx
+++ b/cui/source/dialogs/SpellDialog.cxx
@@ -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 );
                 }
             }
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 8f331c8..18b0c9a 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -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 );
                         }
                     }
diff --git a/include/vcl/image.hxx b/include/vcl/image.hxx
index dc027f4..f7b34e7 100644
--- a/include/vcl/image.hxx
+++ b/include/vcl/image.hxx
@@ -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;
diff --git a/sfx2/source/menu/mnumgr.cxx b/sfx2/source/menu/mnumgr.cxx
index 23c917c..344834a 100644
--- a/sfx2/source/menu/mnumgr.cxx
+++ b/sfx2/source/menu/mnumgr.cxx
@@ -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)
             {
diff --git a/sw/source/ui/lingu/olmenu.cxx b/sw/source/ui/lingu/olmenu.cxx
index 4537896..4e8cfd5 100644
--- a/sw/source/ui/lingu/olmenu.cxx
+++ b/sw/source/ui/lingu/olmenu.cxx
@@ -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 );
             }
         }
 
diff --git a/vcl/source/gdi/image.cxx b/vcl/source/gdi/image.cxx
index 32bd324..33fd919 100644
--- a/vcl/source/gdi/image.cxx
+++ b/vcl/source/gdi/image.cxx
@@ -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 );


More information about the Libreoffice-commits mailing list