LCOV - code coverage report
Current view: top level - sfx2/source/control - templateabstractview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 122 0.0 %
Date: 2012-08-25 Functions: 0 24 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 172 0.0 %

           Branch data     Line data    Source code
       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                 :            : 
      10                 :            : #include <sfx2/templateabstractview.hxx>
      11                 :            : 
      12                 :            : #include <comphelper/processfactory.hxx>
      13                 :            : #include <sfx2/templateview.hxx>
      14                 :            : #include <sfx2/templateviewitem.hxx>
      15                 :            : #include <unotools/ucbstreamhelper.hxx>
      16                 :            : #include <vcl/pngread.hxx>
      17                 :            : 
      18                 :            : #include <com/sun/star/embed/ElementModes.hpp>
      19                 :            : #include <com/sun/star/embed/XStorage.hpp>
      20                 :            : #include <com/sun/star/lang/XComponent.hpp>
      21                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      22                 :            : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      23                 :            : 
      24                 :          0 : bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
      25                 :            : {
      26                 :          0 :     const TemplateViewItem *pTempItem = static_cast<const TemplateViewItem*>(pItem);
      27                 :            : 
      28         [ #  # ]:          0 :     if (mApp == FILTER_APP_WRITER)
      29                 :            :     {
      30                 :          0 :         return pTempItem->getFileType() == "OpenDocument Text" ||
      31 [ #  # ][ #  # ]:          0 :                 pTempItem->getFileType() == "OpenDocument Text Template";
      32                 :            :     }
      33         [ #  # ]:          0 :     else if (mApp == FILTER_APP_CALC)
      34                 :            :     {
      35                 :          0 :         return pTempItem->getFileType() == "OpenDocument Spreadsheet" ||
      36 [ #  # ][ #  # ]:          0 :                 pTempItem->getFileType() == "OpenDocument Spreadsheet Template";
      37                 :            :     }
      38         [ #  # ]:          0 :     else if (mApp == FILTER_APP_IMPRESS)
      39                 :            :     {
      40                 :          0 :         return pTempItem->getFileType() == "OpenDocument Presentation" ||
      41 [ #  # ][ #  # ]:          0 :                 pTempItem->getFileType() == "OpenDocument Presentation Template";
      42                 :            :     }
      43         [ #  # ]:          0 :     else if (mApp == FILTER_APP_DRAW)
      44                 :            :     {
      45                 :          0 :         return pTempItem->getFileType() == "OpenDocument Drawing" ||
      46 [ #  # ][ #  # ]:          0 :                 pTempItem->getFileType() == "OpenDocument Drawing Template";
      47                 :            :     }
      48                 :            : 
      49                 :          0 :     return true;
      50                 :            : }
      51                 :            : 
      52                 :          0 : bool ViewFilter_Keyword::operator ()(const ThumbnailViewItem *pItem)
      53                 :            : {
      54                 :            :     assert(pItem);
      55                 :            : 
      56                 :          0 :     return pItem->maTitle.matchIgnoreAsciiCase(maKeyword);
      57                 :            : }
      58                 :            : 
      59                 :          0 : TemplateAbstractView::TemplateAbstractView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
      60                 :            :     : ThumbnailView(pParent,nWinStyle,bDisableTransientChildren),
      61 [ #  # ][ #  # ]:          0 :       mpItemView(new TemplateView(this))
                 [ #  # ]
      62                 :            : {
      63         [ #  # ]:          0 :     mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl));
      64                 :          0 : }
      65                 :            : 
      66                 :          0 : TemplateAbstractView::TemplateAbstractView(Window *pParent, const ResId &rResId, bool bDisableTransientChildren)
      67                 :            :     : ThumbnailView(pParent,rResId,bDisableTransientChildren),
      68 [ #  # ][ #  # ]:          0 :       mpItemView(new TemplateView(this))
                 [ #  # ]
      69                 :            : {
      70         [ #  # ]:          0 :     mpItemView->setItemStateHdl(LINK(this,TemplateAbstractView,OverlayItemStateHdl));
      71                 :          0 : }
      72                 :            : 
      73                 :          0 : TemplateAbstractView::~TemplateAbstractView ()
      74                 :            : {
      75 [ #  # ][ #  # ]:          0 :     delete mpItemView;
      76         [ #  # ]:          0 : }
      77                 :            : 
      78                 :          0 : void TemplateAbstractView::setItemDimensions(long ItemWidth, long ThumbnailHeight, long DisplayHeight, int itemPadding)
      79                 :            : {
      80                 :          0 :     ThumbnailView::setItemDimensions(ItemWidth,ThumbnailHeight,DisplayHeight,itemPadding);
      81                 :            : 
      82                 :          0 :     mpItemView->setItemDimensions(ItemWidth,ThumbnailHeight,DisplayHeight,itemPadding);
      83                 :          0 : }
      84                 :            : 
      85                 :          0 : sal_uInt16 TemplateAbstractView::getOverlayRegionId() const
      86                 :            : {
      87                 :          0 :     return mpItemView->getId();
      88                 :            : }
      89                 :            : 
      90                 :          0 : const OUString &TemplateAbstractView::getOverlayName() const
      91                 :            : {
      92                 :          0 :     return mpItemView->getName();
      93                 :            : }
      94                 :            : 
      95                 :          0 : bool TemplateAbstractView::isOverlayVisible () const
      96                 :            : {
      97                 :          0 :     return mpItemView->IsVisible();
      98                 :            : }
      99                 :            : 
     100                 :          0 : void TemplateAbstractView::deselectOverlayItems()
     101                 :            : {
     102                 :          0 :     mpItemView->deselectItems();
     103                 :          0 : }
     104                 :            : 
     105                 :          0 : void TemplateAbstractView::deselectOverlayItem(const sal_uInt16 nItemId)
     106                 :            : {
     107                 :          0 :     mpItemView->deselectItem(nItemId);
     108                 :          0 : }
     109                 :            : 
     110                 :          0 : void TemplateAbstractView::sortOverlayItems(const boost::function<bool (const ThumbnailViewItem*,
     111                 :            :                                                                         const ThumbnailViewItem*) > &func)
     112                 :            : {
     113                 :          0 :     mpItemView->sortItems(func);
     114                 :          0 : }
     115                 :            : 
     116                 :          0 : void TemplateAbstractView::filterTemplatesByKeyword(const OUString &rKeyword)
     117                 :            : {
     118         [ #  # ]:          0 :     if (mpItemView->IsVisible())
     119 [ #  # ][ #  # ]:          0 :         mpItemView->filterItems(ViewFilter_Keyword(rKeyword));
                 [ #  # ]
     120                 :          0 : }
     121                 :            : 
     122                 :          0 : void TemplateAbstractView::setOverlayDblClickHdl(const Link &rLink)
     123                 :            : {
     124                 :          0 :     mpItemView->setDblClickHdl(rLink);
     125                 :          0 : }
     126                 :            : 
     127                 :          0 : void TemplateAbstractView::setOverlayCloseHdl(const Link &rLink)
     128                 :            : {
     129                 :          0 :     mpItemView->setCloseHdl(rLink);
     130                 :          0 : }
     131                 :            : 
     132                 :          0 : BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long height)
     133                 :            : {
     134                 :          0 :     BitmapEx aImg = rImg;
     135                 :            : 
     136         [ #  # ]:          0 :     int sWidth = std::min(aImg.GetSizePixel().getWidth(),width);
     137         [ #  # ]:          0 :     int sHeight = std::min(aImg.GetSizePixel().getHeight(),height);
     138                 :            : 
     139         [ #  # ]:          0 :     aImg.Scale(Size(sWidth,sHeight),BMP_SCALE_INTERPOLATE);
     140                 :            : 
     141                 :          0 :     return aImg;
     142                 :            : }
     143                 :            : 
     144                 :          0 : BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width, long height)
     145                 :            : {
     146                 :            :     using namespace ::com::sun::star;
     147                 :            :     using namespace ::com::sun::star::uno;
     148                 :            : 
     149                 :            :     // Load the thumbnail from a template document.
     150                 :          0 :     uno::Reference<io::XInputStream> xIStream;
     151                 :            : 
     152         [ #  # ]:          0 :     uno::Reference< lang::XMultiServiceFactory > xServiceManager (comphelper::getProcessServiceFactory());
     153                 :            : 
     154         [ #  # ]:          0 :     if (xServiceManager.is())
     155                 :            :     {
     156                 :            :         try
     157                 :            :         {
     158                 :            :             uno::Reference<lang::XSingleServiceFactory> xStorageFactory(
     159         [ #  # ]:          0 :                 xServiceManager->createInstance( "com.sun.star.embed.StorageFactory"),
     160 [ #  # ][ #  # ]:          0 :                 uno::UNO_QUERY);
     161                 :            : 
     162         [ #  # ]:          0 :             if (xStorageFactory.is())
     163                 :            :             {
     164         [ #  # ]:          0 :                 uno::Sequence<uno::Any> aArgs (2);
     165 [ #  # ][ #  # ]:          0 :                 aArgs[0] <<= msURL;
     166 [ #  # ][ #  # ]:          0 :                 aArgs[1] <<= embed::ElementModes::READ;
     167                 :            :                 uno::Reference<embed::XStorage> xDocStorage (
     168         [ #  # ]:          0 :                     xStorageFactory->createInstanceWithArguments(aArgs),
     169 [ #  # ][ #  # ]:          0 :                     uno::UNO_QUERY);
     170                 :            : 
     171                 :            :                 try
     172                 :            :                 {
     173         [ #  # ]:          0 :                     if (xDocStorage.is())
     174                 :            :                     {
     175                 :            :                         uno::Reference<embed::XStorage> xStorage (
     176         [ #  # ]:          0 :                             xDocStorage->openStorageElement(
     177                 :            :                                 "Thumbnails",
     178         [ #  # ]:          0 :                                 embed::ElementModes::READ));
     179         [ #  # ]:          0 :                         if (xStorage.is())
     180                 :            :                         {
     181                 :            :                             uno::Reference<io::XStream> xThumbnailCopy (
     182 [ #  # ][ #  # ]:          0 :                                 xStorage->cloneStreamElement("thumbnail.png"));
     183         [ #  # ]:          0 :                             if (xThumbnailCopy.is())
     184 [ #  # ][ #  # ]:          0 :                                 xIStream = xThumbnailCopy->getInputStream();
                 [ #  # ]
     185         [ #  # ]:          0 :                         }
     186                 :            :                     }
     187                 :            :                 }
     188         [ #  # ]:          0 :                 catch (const uno::Exception& rException)
     189                 :            :                 {
     190                 :            :                     OSL_TRACE (
     191                 :            :                         "caught exception while trying to access Thumbnail/thumbnail.png of %s: %s",
     192                 :            :                         ::rtl::OUStringToOString(msURL,
     193                 :            :                             RTL_TEXTENCODING_UTF8).getStr(),
     194                 :            :                         ::rtl::OUStringToOString(rException.Message,
     195                 :            :                             RTL_TEXTENCODING_UTF8).getStr());
     196                 :            :                 }
     197                 :            : 
     198                 :            :                 try
     199                 :            :                 {
     200                 :            :                     // An (older) implementation had a bug - The storage
     201                 :            :                     // name was "Thumbnail" instead of "Thumbnails".  The
     202                 :            :                     // old name is still used as fallback but this code can
     203                 :            :                     // be removed soon.
     204         [ #  # ]:          0 :                     if ( ! xIStream.is())
     205                 :            :                     {
     206                 :            :                         uno::Reference<embed::XStorage> xStorage (
     207         [ #  # ]:          0 :                             xDocStorage->openStorageElement( "Thumbnail",
     208         [ #  # ]:          0 :                                 embed::ElementModes::READ));
     209         [ #  # ]:          0 :                         if (xStorage.is())
     210                 :            :                         {
     211                 :            :                             uno::Reference<io::XStream> xThumbnailCopy (
     212 [ #  # ][ #  # ]:          0 :                                 xStorage->cloneStreamElement("thumbnail.png"));
     213         [ #  # ]:          0 :                             if (xThumbnailCopy.is())
     214 [ #  # ][ #  # ]:          0 :                                 xIStream = xThumbnailCopy->getInputStream();
                 [ #  # ]
     215         [ #  # ]:          0 :                         }
     216                 :            :                     }
     217                 :            :                 }
     218         [ #  # ]:          0 :                 catch (const uno::Exception& rException)
     219                 :            :                 {
     220                 :            :                     OSL_TRACE (
     221                 :            :                         "caught exception while trying to access Thumbnails/thumbnail.png of %s: %s",
     222                 :            :                         ::rtl::OUStringToOString(msURL,
     223                 :            :                             RTL_TEXTENCODING_UTF8).getStr(),
     224                 :            :                         ::rtl::OUStringToOString(rException.Message,
     225                 :            :                             RTL_TEXTENCODING_UTF8).getStr());
     226         [ #  # ]:          0 :                 }
     227         [ #  # ]:          0 :             }
     228                 :            :         }
     229         [ #  # ]:          0 :         catch (const uno::Exception& rException)
     230                 :            :         {
     231                 :            :             OSL_TRACE (
     232                 :            :                 "caught exception while trying to access tuhmbnail of %s: %s",
     233                 :            :                 ::rtl::OUStringToOString(msURL,
     234                 :            :                     RTL_TEXTENCODING_UTF8).getStr(),
     235                 :            :                 ::rtl::OUStringToOString(rException.Message,
     236                 :            :                     RTL_TEXTENCODING_UTF8).getStr());
     237                 :            :         }
     238                 :            :     }
     239                 :            : 
     240                 :            :     // Extract the image from the stream.
     241         [ #  # ]:          0 :     BitmapEx aThumbnail;
     242         [ #  # ]:          0 :     if (xIStream.is())
     243                 :            :     {
     244                 :            :         ::std::auto_ptr<SvStream> pStream (
     245         [ #  # ]:          0 :             ::utl::UcbStreamHelper::CreateStream (xIStream));
     246         [ #  # ]:          0 :         ::vcl::PNGReader aReader (*pStream);
     247 [ #  # ][ #  # ]:          0 :         aThumbnail = aReader.Read ();
         [ #  # ][ #  # ]
                 [ #  # ]
     248                 :            :     }
     249                 :            : 
     250 [ #  # ][ #  # ]:          0 :     return TemplateAbstractView::scaleImg(aThumbnail,width,height);
     251                 :            : }
     252                 :            : 
     253                 :          0 : void TemplateAbstractView::Resize()
     254                 :            : {
     255         [ #  # ]:          0 :     mpItemView->SetSizePixel(GetSizePixel());
     256                 :          0 : }
     257                 :            : 
     258                 :          0 : void TemplateAbstractView::Paint(const Rectangle &rRect)
     259                 :            : {
     260         [ #  # ]:          0 :     if (!mpItemView->IsVisible())
     261                 :          0 :         ThumbnailView::Paint(rRect);
     262                 :          0 : }
     263                 :            : 
     264                 :          0 : void TemplateAbstractView::DrawItem(ThumbnailViewItem *pItem)
     265                 :            : {
     266         [ #  # ]:          0 :     if (!mpItemView->IsVisible())
     267                 :          0 :         ThumbnailView::DrawItem(pItem);
     268                 :          0 : }
     269                 :            : 
     270                 :          0 : void TemplateAbstractView::OnSelectionMode (bool bMode)
     271                 :            : {
     272         [ #  # ]:          0 :     if (mpItemView->IsVisible())
     273                 :            :     {
     274                 :          0 :         mbSelectionMode = bMode;
     275                 :          0 :         mpItemView->setSelectionMode(bMode);
     276                 :            :     }
     277                 :            :     else
     278                 :          0 :         ThumbnailView::OnSelectionMode(bMode);
     279                 :          0 : }
     280                 :            : 
     281                 :          0 : IMPL_LINK(TemplateAbstractView, OverlayItemStateHdl, const ThumbnailViewItem*, pItem)
     282                 :            : {
     283                 :          0 :     maOverlayItemStateHdl.Call((void*)pItem);
     284                 :          0 :     return 0;
     285                 :            : }
     286                 :            : 
     287                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10