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

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Copyright 2012 LibreOffice contributors.
       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/templateview.hxx>
      11                 :            : 
      12                 :            : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      13                 :            : #include <basegfx/point/b2dpoint.hxx>
      14                 :            : #include <basegfx/range/b2drange.hxx>
      15                 :            : #include <basegfx/vector/b2dvector.hxx>
      16                 :            : #include <drawinglayer/attribute/fillbitmapattribute.hxx>
      17                 :            : #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
      18                 :            : #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
      19                 :            : #include <drawinglayer/primitive2d/textprimitive2d.hxx>
      20                 :            : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      21                 :            : #include <sfx2/sfxresid.hxx>
      22                 :            : #include <sfx2/templateviewitem.hxx>
      23                 :            : #include <vcl/edit.hxx>
      24                 :            : 
      25                 :            : #include "templateview.hrc"
      26                 :            : 
      27                 :            : #define EDIT_HEIGHT 20
      28                 :            : 
      29                 :            : using namespace basegfx;
      30                 :            : using namespace basegfx::tools;
      31                 :            : using namespace drawinglayer::attribute;
      32                 :            : using namespace drawinglayer::primitive2d;
      33                 :            : 
      34                 :          0 : TemplateView::TemplateView (Window *pParent)
      35                 :            :     : ThumbnailView(pParent,WB_VSCROLL),
      36                 :            :       maCloseImg(SfxResId(IMG_TEMPLATE_VIEW_CLOSE)),
      37                 :            :       mbRenderTitle(true),
      38                 :            :       mnId(0),
      39 [ #  # ][ #  # ]:          0 :       mpEditName(new Edit(this, WB_BORDER | WB_HIDE))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      40                 :            : {
      41                 :          0 :     mnHeaderHeight = 30;
      42                 :          0 : }
      43                 :            : 
      44         [ #  # ]:          0 : TemplateView::~TemplateView ()
      45                 :            : {
      46 [ #  # ][ #  # ]:          0 :     delete mpEditName;
      47         [ #  # ]:          0 : }
      48                 :            : 
      49                 :          0 : void TemplateView::setName (const OUString &rName)
      50                 :            : {
      51                 :          0 :     maName = rName;
      52 [ #  # ][ #  # ]:          0 :     mpEditName->SetText(OUString());
                 [ #  # ]
      53                 :          0 : }
      54                 :            : 
      55                 :          0 : void TemplateView::Paint (const Rectangle &rRect)
      56                 :            : {
      57         [ #  # ]:          0 :     ThumbnailView::Paint(rRect);
      58                 :            : 
      59                 :          0 :     int nCount = 0;
      60                 :          0 :     int nMaxCount = 1;
      61                 :            : 
      62         [ #  # ]:          0 :     if (mbRenderTitle)
      63                 :          0 :         ++nMaxCount;
      64                 :            : 
      65         [ #  # ]:          0 :     Primitive2DSequence aSeq(nMaxCount);
      66         [ #  # ]:          0 :     TextLayouterDevice aTextDev;
      67                 :            : 
      68                 :            :     // Draw centered region name
      69                 :          0 :     Point aPos;
      70                 :          0 :     Size aWinSize = GetOutputSizePixel();
      71                 :            : 
      72         [ #  # ]:          0 :     if (mbRenderTitle)
      73                 :            :     {
      74 [ #  # ][ #  # ]:          0 :         aPos.X() = (aWinSize.getWidth() - aTextDev.getTextWidth(maName,0,maName.getLength()))/2;
                 [ #  # ]
      75 [ #  # ][ #  # ]:          0 :         aPos.Y() = aTextDev.getTextHeight() + (mnHeaderHeight - aTextDev.getTextHeight())/2;
      76                 :            : 
      77                 :            :         basegfx::B2DHomMatrix aTextMatrix( createScaleTranslateB2DHomMatrix(
      78                 :            :                     mpItemAttrs->aFontSize.getX(), mpItemAttrs->aFontSize.getY(),
      79         [ #  # ]:          0 :                     double( aPos.X() ), double( aPos.Y() ) ) );
      80                 :            : 
      81         [ #  # ]:          0 :         aSeq[nCount++] = Primitive2DReference(
      82                 :            :                     new TextSimplePortionPrimitive2D(aTextMatrix,
      83                 :          0 :                                                      maName,0,maName.getLength(),
      84                 :            :                                                      std::vector< double >( ),
      85                 :            :                                                      mpItemAttrs->aFontAttr,
      86                 :            :                                                      com::sun::star::lang::Locale(),
      87   [ #  #  #  # ]:          0 :                                                      Color(COL_BLACK).getBColor() ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      88                 :            :     }
      89                 :            : 
      90                 :            :     // Draw close icon
      91         [ #  # ]:          0 :     Size aImageSize = maCloseImg.GetSizePixel();
      92                 :            : 
      93                 :          0 :     aPos.Y() = (mnHeaderHeight - aImageSize.Height())/2;
      94                 :          0 :     aPos.X() = aWinSize.Width() - aImageSize.Width() - aPos.Y();
      95                 :            : 
      96         [ #  # ]:          0 :     aSeq[nCount] = Primitive2DReference( new FillBitmapPrimitive2D(
      97                 :          0 :                                         createTranslateB2DHomMatrix(aPos.X(),aPos.Y()),
      98                 :            :                                         FillBitmapAttribute(maCloseImg.GetBitmapEx(),
      99                 :            :                                                             B2DPoint(0,0),
     100                 :          0 :                                                             B2DVector(aImageSize.Width(),aImageSize.Height()),
     101                 :            :                                                             false)
     102 [ #  # ][ #  # ]:          0 :                                         ));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     103                 :            : 
     104 [ #  # ][ #  # ]:          0 :     mpProcessor->process(aSeq);
                 [ #  # ]
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : void TemplateView::InsertItems (const std::vector<TemplateItemProperties> &rTemplates)
     108                 :            : {
     109         [ #  # ]:          0 :     for (size_t i = 0, n = rTemplates.size(); i < n; ++i )
     110                 :            :     {
     111         [ #  # ]:          0 :         TemplateViewItem *pItem = new TemplateViewItem(*this,this);
     112                 :          0 :         const TemplateItemProperties *pCur = &rTemplates[i];
     113                 :            : 
     114                 :          0 :         pItem->mnId = pCur->nId;
     115                 :          0 :         pItem->maTitle = pCur->aName;
     116                 :          0 :         pItem->setPath(pCur->aPath);
     117                 :          0 :         pItem->setFileType(pCur->aType);
     118                 :          0 :         pItem->maPreview1 = pCur->aThumbnail;
     119         [ #  # ]:          0 :         pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
     120                 :            : 
     121         [ #  # ]:          0 :         mItemList.push_back(pItem);
     122                 :            :     }
     123                 :            : 
     124                 :          0 :     CalculateItemPositions();
     125                 :            : 
     126                 :          0 :     Invalidate();
     127                 :          0 : }
     128                 :            : 
     129                 :          0 : void TemplateView::Resize()
     130                 :            : {
     131                 :            :     // Set editbox size and position
     132         [ #  # ]:          0 :     Size aWinSize = GetOutputSize();
     133                 :            : 
     134                 :          0 :     Size aEditSize(aWinSize.getWidth()/2,EDIT_HEIGHT);
     135                 :            : 
     136                 :          0 :     Point aPos;
     137                 :          0 :     aPos.X() = (aWinSize.getWidth() - aEditSize.getWidth())/2;
     138                 :          0 :     aPos.Y() = (mnHeaderHeight - aEditSize.getHeight())/2;
     139                 :            : 
     140         [ #  # ]:          0 :     mpEditName->SetPosSizePixel(aPos,aEditSize);
     141                 :            : 
     142         [ #  # ]:          0 :     ThumbnailView::Resize();
     143                 :          0 : }
     144                 :            : 
     145                 :          0 : void TemplateView::MouseButtonDown (const MouseEvent &rMEvt)
     146                 :            : {
     147         [ #  # ]:          0 :     if (rMEvt.IsLeft())
     148                 :            :     {
     149                 :            :         // Check if we are editing title
     150 [ #  # ][ #  # ]:          0 :         if (mpEditName->IsVisible())
     151                 :            :         {
     152         [ #  # ]:          0 :             mpEditName->Show(false);
     153                 :          0 :             mbRenderTitle = true;
     154                 :            : 
     155                 :            :             // Update name if its not empty
     156 [ #  # ][ #  # ]:          0 :             OUString aTmp = mpEditName->GetText();
                 [ #  # ]
     157                 :            : 
     158         [ #  # ]:          0 :             if (!aTmp.isEmpty())
     159                 :            :             {
     160 [ #  # ][ #  # ]:          0 :                 PostUserEvent(LINK(this,TemplateView,ChangeNameHdl));
     161                 :            :             }
     162                 :            :             else
     163                 :            :             {
     164 [ #  # ][ #  # ]:          0 :                 mpEditName->SetText(OUString());
                 [ #  # ]
     165         [ #  # ]:          0 :                 Invalidate();
     166                 :            :             }
     167                 :            : 
     168                 :          0 :             return;
     169                 :            :         }
     170                 :            : 
     171                 :          0 :         Size aWinSize = GetOutputSizePixel();
     172         [ #  # ]:          0 :         Size aImageSize = maCloseImg.GetSizePixel();
     173                 :            : 
     174                 :          0 :         Point aPos;
     175                 :          0 :         aPos.Y() = (mnHeaderHeight - aImageSize.Height())/2;
     176                 :          0 :         aPos.X() = aWinSize.Width() - aImageSize.Width() - aPos.Y();
     177                 :            : 
     178         [ #  # ]:          0 :         Rectangle aImgRect(aPos,aImageSize);
     179                 :            : 
     180 [ #  # ][ #  # ]:          0 :         if (aImgRect.IsInside(rMEvt.GetPosPixel()))
     181                 :            :         {
     182         [ #  # ]:          0 :             maCloseHdl.Call(this);
     183                 :            :         }
     184                 :            :         else
     185                 :            :         {
     186         [ #  # ]:          0 :             drawinglayer::primitive2d::TextLayouterDevice aTextDev;
     187                 :            :             aTextDev.setFontAttribute(mpItemAttrs->aFontAttr,
     188                 :            :                                       mpItemAttrs->aFontSize.getX(), mpItemAttrs->aFontSize.getY(),
     189         [ #  # ]:          0 :                                       com::sun::star::lang::Locale() );
     190                 :            : 
     191 [ #  # ][ #  # ]:          0 :             float fTextWidth = aTextDev.getTextWidth(maName,0,maName.getLength());
                 [ #  # ]
     192                 :            : 
     193                 :          0 :             aPos.X() = (aWinSize.getWidth() - fTextWidth)/2;
     194         [ #  # ]:          0 :             aPos.Y() = (mnHeaderHeight - aTextDev.getTextHeight())/2;
     195                 :            : 
     196 [ #  # ][ #  # ]:          0 :             Rectangle aTitleRect(aPos,Size(fTextWidth,aTextDev.getTextHeight()));
     197                 :            : 
     198 [ #  # ][ #  # ]:          0 :             if (aTitleRect.IsInside(rMEvt.GetPosPixel()))
     199                 :            :             {
     200                 :          0 :                 mbRenderTitle = false;
     201                 :            : 
     202         [ #  # ]:          0 :                 Invalidate();
     203         [ #  # ]:          0 :                 mpEditName->Show();
     204         [ #  # ]:          0 :             }
     205                 :            :         }
     206                 :            :     }
     207                 :            : 
     208                 :          0 :     ThumbnailView::MouseButtonDown(rMEvt);
     209                 :            : }
     210                 :            : 
     211                 :          0 : void TemplateView::OnItemDblClicked(ThumbnailViewItem *pItem)
     212                 :            : {
     213                 :          0 :     maDblClickHdl.Call(pItem);
     214                 :          0 : }
     215                 :            : 
     216                 :          0 : IMPL_LINK_NOARG(TemplateView, ChangeNameHdl)
     217                 :            : {
     218                 :          0 :     OUString aTmp = maName;
     219 [ #  # ][ #  # ]:          0 :     maName = mpEditName->GetText();
                 [ #  # ]
     220                 :            : 
     221 [ #  # ][ #  # ]:          0 :     if (!maChangeNameHdl.Call(this))
     222                 :          0 :         maName = aTmp;
     223                 :            : 
     224 [ #  # ][ #  # ]:          0 :     mpEditName->SetText(OUString());
                 [ #  # ]
     225                 :            : 
     226         [ #  # ]:          0 :     Invalidate();
     227                 :          0 :     return 0;
     228                 :            : }
     229                 :            : 
     230                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     231                 :            : 
     232                 :            : 

Generated by: LCOV version 1.10