LCOV - code coverage report
Current view: top level - sfx2/source/control - templateabstractview.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 149 0.0 %
Date: 2014-04-14 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

          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/sfxresid.hxx>
      14             : #include <sfx2/templatecontaineritem.hxx>
      15             : #include <sfx2/templateviewitem.hxx>
      16             : #include <tools/urlobj.hxx>
      17             : #include <unotools/ucbstreamhelper.hxx>
      18             : #include <vcl/pngread.hxx>
      19             : 
      20             : #include <basegfx/polygon/b2dpolygon.hxx>
      21             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      22             : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      23             : 
      24             : #include <com/sun/star/embed/ElementModes.hpp>
      25             : #include <com/sun/star/embed/XStorage.hpp>
      26             : #include <com/sun/star/embed/StorageFactory.hpp>
      27             : #include <com/sun/star/lang/XComponent.hpp>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      30             : 
      31             : #include "../doc/doc.hrc"
      32             : #include "templateview.hrc"
      33             : 
      34             : using namespace basegfx;
      35             : using namespace drawinglayer::primitive2d;
      36             : 
      37           0 : bool ViewFilter_Application::isFilteredExtension(FILTER_APPLICATION filter, const OUString &rExt)
      38             : {
      39           0 :     bool bRet = true;
      40             : 
      41           0 :     if (filter == FILTER_APP_WRITER)
      42             :     {
      43           0 :         bRet = rExt == "ott" || rExt == "stw" || rExt == "oth" || rExt == "dot" || rExt == "dotx";
      44             :     }
      45           0 :     else if (filter == FILTER_APP_CALC)
      46             :     {
      47           0 :         bRet = rExt == "ots" || rExt == "stc" || rExt == "xlt" || rExt == "xltm" || rExt == "xltx";
      48             :     }
      49           0 :     else if (filter == FILTER_APP_IMPRESS)
      50             :     {
      51           0 :         bRet = rExt == "otp" || rExt == "sti" || rExt == "pot" || rExt == "potm" || rExt == "potx";
      52             :     }
      53           0 :     else if (filter == FILTER_APP_DRAW)
      54             :     {
      55           0 :         bRet = rExt == "otg" || rExt == "std";
      56             :     }
      57             : 
      58           0 :     return bRet;
      59             : }
      60             : 
      61           0 : bool ViewFilter_Application::isValid (const OUString &rPath) const
      62             : {
      63           0 :     INetURLObject aUrl(rPath);
      64           0 :     return isFilteredExtension(mApp, aUrl.getExtension());
      65             : }
      66             : 
      67           0 : bool ViewFilter_Application::operator () (const ThumbnailViewItem *pItem)
      68             : {
      69           0 :     const TemplateViewItem *pTempItem = dynamic_cast<const TemplateViewItem*>(pItem);
      70           0 :     if (pTempItem)
      71           0 :         return isValid(pTempItem->getPath());
      72             : 
      73           0 :     TemplateContainerItem *pContainerItem = const_cast<TemplateContainerItem*>(dynamic_cast<const TemplateContainerItem*>(pItem));
      74           0 :     if (pContainerItem)
      75             :     {
      76           0 :         std::vector<TemplateItemProperties> &rTemplates = pContainerItem->maTemplates;
      77             : 
      78           0 :         size_t nVisCount = 0;
      79             : 
      80             :         // Clear thumbnails
      81           0 :         pContainerItem->maPreview1.Clear();
      82           0 :         pContainerItem->maPreview2.Clear();
      83           0 :         pContainerItem->maPreview3.Clear();
      84           0 :         pContainerItem->maPreview4.Clear();
      85             : 
      86           0 :         for (size_t i = 0, n = rTemplates.size(); i < n && pContainerItem->HasMissingPreview(); ++i)
      87             :         {
      88           0 :             if (isValid(rTemplates[i].aPath))
      89             :             {
      90           0 :                 ++nVisCount;
      91           0 :                 if ( pContainerItem->maPreview1.IsEmpty( ) )
      92             :                 {
      93           0 :                     pContainerItem->maPreview1 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
      94             :                                                                        TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
      95           0 :                                                                        TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
      96             :                 }
      97           0 :                 else if ( pContainerItem->maPreview2.IsEmpty() )
      98             :                 {
      99           0 :                     pContainerItem->maPreview2 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
     100             :                                                                        TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
     101           0 :                                                                        TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
     102             :                 }
     103           0 :                 else if ( pContainerItem->maPreview3.IsEmpty() )
     104             :                 {
     105           0 :                     pContainerItem->maPreview3 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
     106             :                                                                        TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
     107           0 :                                                                        TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
     108             :                 }
     109           0 :                 else if ( pContainerItem->maPreview4.IsEmpty() )
     110             :                 {
     111           0 :                     pContainerItem->maPreview4 = TemplateAbstractView::scaleImg(rTemplates[i].aThumbnail,
     112             :                                                                        TEMPLATE_THUMBNAIL_MAX_WIDTH*0.75,
     113           0 :                                                                        TEMPLATE_THUMBNAIL_MAX_HEIGHT*0.75);
     114             :                 }
     115             :             }
     116             :         }
     117             :     }
     118           0 :     return true;
     119             : }
     120             : 
     121           0 : bool ViewFilter_Keyword::operator ()(const ThumbnailViewItem *pItem)
     122             : {
     123             :     assert(pItem);
     124             : 
     125           0 :     return pItem->maTitle.matchIgnoreAsciiCase(maKeyword);
     126             : }
     127             : 
     128           0 : TemplateAbstractView::TemplateAbstractView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
     129             :     : ThumbnailView(pParent,nWinStyle,bDisableTransientChildren),
     130             :       mnCurRegionId(0),
     131             :       maAllButton(this, SfxResId(BTN_ALL_TEMPLATES)),
     132           0 :       maFTName(this, SfxResId(FT_NAME))
     133             : {
     134           0 :     maAllButton.Hide();
     135           0 :     maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON);
     136           0 :     maAllButton.SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl));
     137           0 :     maFTName.Hide();
     138           0 : }
     139             : 
     140           0 : TemplateAbstractView::TemplateAbstractView(Window *pParent)
     141             :     : ThumbnailView(pParent),
     142             :       mnCurRegionId(0),
     143             :       maAllButton(this, SfxResId(BTN_ALL_TEMPLATES)),
     144           0 :       maFTName(this, SfxResId(FT_NAME))
     145             : {
     146           0 :     maAllButton.Hide();
     147           0 :     maAllButton.SetStyle(maAllButton.GetStyle() | WB_FLATBUTTON);
     148           0 :     maAllButton.SetClickHdl(LINK(this,TemplateAbstractView,ShowRootRegionHdl));
     149           0 :     maFTName.Hide();
     150           0 : }
     151             : 
     152           0 : TemplateAbstractView::~TemplateAbstractView ()
     153             : {
     154           0 : }
     155             : 
     156           0 : void TemplateAbstractView::insertItem(const TemplateItemProperties &rTemplate)
     157             : {
     158           0 :     const TemplateItemProperties *pCur = &rTemplate;
     159             : 
     160           0 :     TemplateViewItem *pChild = new TemplateViewItem(*this, pCur->nId);
     161           0 :     pChild->mnDocId = pCur->nDocId;
     162           0 :     pChild->mnRegionId = pCur->nRegionId;
     163           0 :     pChild->maTitle = pCur->aName;
     164           0 :     pChild->setPath(pCur->aPath);
     165           0 :     pChild->maPreview1 = pCur->aThumbnail;
     166             : 
     167           0 :     if ( pCur->aThumbnail.IsEmpty() )
     168             :     {
     169             :         // Use the default thumbnail if we have nothing else
     170           0 :         pChild->maPreview1 = TemplateAbstractView::getDefaultThumbnail(pCur->aPath);
     171             :     }
     172             : 
     173           0 :     pChild->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
     174             : 
     175           0 :     AppendItem(pChild);
     176             : 
     177           0 :     CalculateItemPositions();
     178           0 :     Invalidate();
     179           0 : }
     180             : 
     181           0 : void TemplateAbstractView::insertItems(const std::vector<TemplateItemProperties> &rTemplates)
     182             : {
     183           0 :     std::vector<ThumbnailViewItem*> aItems(rTemplates.size());
     184           0 :     for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
     185             :     {
     186             :         //TODO: CHECK IF THE ITEM IS A FOLDER OR NOT
     187           0 :         const TemplateItemProperties *pCur = &rTemplates[i];
     188             : 
     189           0 :         TemplateViewItem *pChild = new TemplateViewItem(*this, pCur->nId);
     190           0 :         pChild->mnDocId = pCur->nDocId;
     191           0 :         pChild->mnRegionId = pCur->nRegionId;
     192           0 :         pChild->maTitle = pCur->aName;
     193           0 :         pChild->setPath(pCur->aPath);
     194           0 :         pChild->maPreview1 = pCur->aThumbnail;
     195             : 
     196           0 :         if ( pCur->aThumbnail.IsEmpty() )
     197             :         {
     198             :             // Use the default thumbnail if we have nothing else
     199           0 :             pChild->maPreview1 = TemplateAbstractView::getDefaultThumbnail(pCur->aPath);
     200             :         }
     201             : 
     202           0 :         pChild->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
     203             : 
     204           0 :         aItems[i] = pChild;
     205             :     }
     206             : 
     207           0 :     updateItems(aItems);
     208           0 : }
     209             : 
     210           0 : sal_uInt16 TemplateAbstractView::getCurRegionId() const
     211             : {
     212           0 :     return mnCurRegionId;
     213             : }
     214             : 
     215           0 : const OUString &TemplateAbstractView::getCurRegionName() const
     216             : {
     217           0 :     return maCurRegionName;
     218             : }
     219             : 
     220           0 : bool TemplateAbstractView::isNonRootRegionVisible () const
     221             : {
     222           0 :     return mnCurRegionId;
     223             : }
     224             : 
     225           0 : void TemplateAbstractView::setOpenRegionHdl(const Link &rLink)
     226             : {
     227           0 :     maOpenRegionHdl = rLink;
     228           0 : }
     229             : 
     230           0 : void TemplateAbstractView::setOpenTemplateHdl(const Link &rLink)
     231             : {
     232           0 :     maOpenTemplateHdl = rLink;
     233           0 : }
     234             : 
     235           0 : BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long height)
     236             : {
     237           0 :     BitmapEx aImg = rImg;
     238             : 
     239           0 :     if (!rImg.IsEmpty())
     240             :     {
     241           0 :         Size aSize = rImg.GetSizePixel();
     242             : 
     243           0 :         if (aSize.Width() == 0)
     244           0 :             aSize.Width() = 1;
     245             : 
     246           0 :         if (aSize.Height() == 0)
     247           0 :             aSize.Height() = 1;
     248             : 
     249             :         // make the picture fit the given width/height constraints
     250           0 :         double nRatio = std::min(double(width)/double(aSize.Width()), double(height)/double(aSize.Height()));
     251             : 
     252           0 :         aImg.Scale(Size(aSize.Width() * nRatio, aSize.Height() * nRatio));
     253             :     }
     254             : 
     255           0 :     return aImg;
     256             : }
     257             : 
     258           0 : BitmapEx TemplateAbstractView::getDefaultThumbnail( const OUString& rPath )
     259             : {
     260           0 :     BitmapEx aImg;
     261           0 :     INetURLObject aUrl(rPath);
     262           0 :     OUString aExt = aUrl.getExtension();
     263             : 
     264           0 :     if ( ViewFilter_Application::isFilteredExtension( FILTER_APP_WRITER, aExt) )
     265           0 :         aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_TEXT ) );
     266           0 :     else if ( ViewFilter_Application::isFilteredExtension( FILTER_APP_CALC, aExt) )
     267           0 :         aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_SHEET ) );
     268           0 :     else if ( ViewFilter_Application::isFilteredExtension( FILTER_APP_IMPRESS, aExt) )
     269           0 :         aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_PRESENTATION ) );
     270           0 :     else if ( ViewFilter_Application::isFilteredExtension( FILTER_APP_DRAW, aExt) )
     271           0 :         aImg = BitmapEx ( SfxResId( SFX_THUMBNAIL_DRAWING ) );
     272             : 
     273           0 :     return aImg;
     274             : }
     275             : 
     276           0 : BitmapEx TemplateAbstractView::fetchThumbnail (const OUString &msURL, long width, long height)
     277             : {
     278           0 :     return TemplateAbstractView::scaleImg(ThumbnailView::readThumbnail(msURL), width, height);
     279             : }
     280             : 
     281           0 : IMPL_LINK_NOARG(TemplateAbstractView, ShowRootRegionHdl)
     282             : {
     283           0 :     showRootRegion();
     284           0 :     return 0;
     285             : }
     286             : 
     287           0 : void TemplateAbstractView::OnItemDblClicked (ThumbnailViewItem *pItem)
     288             : {
     289             :     //Check if the item is a TemplateContainerItem (Folder) or a TemplateViewItem (File)
     290             : 
     291           0 :     TemplateContainerItem* pContainerItem = dynamic_cast<TemplateContainerItem*>(pItem);
     292           0 :     if ( pContainerItem )
     293             :     {
     294             :         // Fill templates
     295             : 
     296           0 :         mnCurRegionId = pContainerItem->mnRegionId+1;
     297           0 :         maCurRegionName = pContainerItem->maTitle;
     298           0 :         maFTName.SetText(maCurRegionName);
     299           0 :         showRegion(pItem);
     300             :     }
     301             :     else
     302             :     {
     303           0 :         maOpenTemplateHdl.Call(pItem);
     304             :     }
     305           0 : }
     306             : 
     307           0 : void TemplateAbstractView::Paint( const Rectangle& rRect )
     308             : {
     309           0 :     ThumbnailView::Paint( rRect );
     310             : 
     311             :     Rectangle aRect(rRect.TopLeft(),
     312           0 :         Point(rRect.BottomRight().X(), mnHeaderHeight));
     313             : 
     314           0 :     drawinglayer::primitive2d::Primitive2DSequence aSeq(1);
     315           0 :     aSeq[0] = drawinglayer::primitive2d::Primitive2DReference(
     316             :         new PolyPolygonColorPrimitive2D(B2DPolyPolygon(Polygon(aRect).getB2DPolygon()),
     317           0 :         BColor(1.0, 1.0, 1.0)));
     318             : 
     319           0 :     mpProcessor->process(aSeq);
     320           0 : }
     321             : 
     322             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10