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

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <sfx2/thumbnailviewitem.hxx>
      30                 :            : 
      31                 :            : #include "thumbnailviewacc.hxx"
      32                 :            : 
      33                 :            : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      34                 :            : #include <basegfx/range/b2drectangle.hxx>
      35                 :            : #include <basegfx/vector/b2dsize.hxx>
      36                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      37                 :            : #include <drawinglayer/attribute/fillbitmapattribute.hxx>
      38                 :            : #include <drawinglayer/primitive2d/borderlineprimitive2d.hxx>
      39                 :            : #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
      40                 :            : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      41                 :            : #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
      42                 :            : #include <drawinglayer/primitive2d/textprimitive2d.hxx>
      43                 :            : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      44                 :            : #include <vcl/button.hxx>
      45                 :            : #include <vcl/svapp.hxx>
      46                 :            : 
      47                 :            : using namespace basegfx;
      48                 :            : using namespace basegfx::tools;
      49                 :            : using namespace ::com::sun::star;
      50                 :            : using namespace drawinglayer::attribute;
      51                 :            : using namespace drawinglayer::primitive2d;
      52                 :            : 
      53                 :          0 : ThumbnailViewItem::ThumbnailViewItem(ThumbnailView &rView, Window *pParent)
      54                 :            :     : mrParent(rView)
      55                 :            :     , mnId(0)
      56                 :            :     , mbVisible(true)
      57                 :            :     , mbSelected(false)
      58                 :            :     , mbHover(false)
      59                 :            :     , mpxAcc(NULL)
      60                 :            :     , mbMode(false)
      61 [ #  # ][ #  # ]:          0 :     , mpSelectBox(new CheckBox(pParent,WB_HIDE | WB_NOPOINTERFOCUS))
         [ #  # ][ #  # ]
      62                 :            : {
      63         [ #  # ]:          0 :     mpSelectBox->SetSizePixel(Size(20,20));
      64         [ #  # ]:          0 :     mpSelectBox->SetClickHdl(LINK(this,ThumbnailViewItem,OnClick));
      65                 :          0 : }
      66                 :            : 
      67                 :          0 : ThumbnailViewItem::~ThumbnailViewItem()
      68                 :            : {
      69         [ #  # ]:          0 :     if( mpxAcc )
      70                 :            :     {
      71 [ #  # ][ #  # ]:          0 :         static_cast< ThumbnailViewItemAcc* >( mpxAcc->get() )->ParentDestroyed();
                 [ #  # ]
      72         [ #  # ]:          0 :         delete mpxAcc;
      73                 :            :     }
      74                 :            : 
      75 [ #  # ][ #  # ]:          0 :     delete mpSelectBox;
      76         [ #  # ]:          0 : }
      77                 :            : 
      78                 :          0 : void ThumbnailViewItem::show (bool bVisible)
      79                 :            : {
      80                 :          0 :     mbVisible = bVisible;
      81                 :            : 
      82         [ #  # ]:          0 :     if (mbMode)
      83                 :          0 :         mpSelectBox->Show(bVisible);
      84         [ #  # ]:          0 :     else if (!bVisible)
      85                 :          0 :         mpSelectBox->Show(bVisible);
      86         [ #  # ]:          0 :     else if (mbSelected)
      87                 :          0 :         mpSelectBox->Show(bVisible);
      88                 :          0 : }
      89                 :            : 
      90                 :          0 : void ThumbnailViewItem::setSelection (bool state)
      91                 :            : {
      92                 :          0 :     mbSelected = state;
      93         [ #  # ]:          0 :     mpSelectBox->SetState(state ? STATE_CHECK : STATE_NOCHECK);
      94                 :            : 
      95         [ #  # ]:          0 :     if (!isHighlighted())
      96                 :          0 :         mpSelectBox->Show(state);
      97                 :          0 : }
      98                 :            : 
      99                 :          0 : void ThumbnailViewItem::setHighlight (bool state)
     100                 :            : {
     101                 :          0 :     mbHover = state;
     102                 :            : 
     103         [ #  # ]:          0 :     if (!isSelected())
     104                 :          0 :         mpSelectBox->Show(state);
     105                 :          0 : }
     106                 :            : 
     107                 :          0 : uno::Reference< accessibility::XAccessible > ThumbnailViewItem::GetAccessible( bool bIsTransientChildrenDisabled )
     108                 :            : {
     109         [ #  # ]:          0 :     if( !mpxAcc )
     110 [ #  # ][ #  # ]:          0 :         mpxAcc = new uno::Reference< accessibility::XAccessible >( new ThumbnailViewItemAcc( this, bIsTransientChildrenDisabled ) );
                 [ #  # ]
     111                 :            : 
     112                 :          0 :     return *mpxAcc;
     113                 :            : }
     114                 :            : 
     115                 :          0 : void ThumbnailViewItem::setDrawArea (const Rectangle &area)
     116                 :            : {
     117                 :          0 :     maDrawArea = area;
     118                 :          0 : }
     119                 :            : 
     120                 :          0 : void ThumbnailViewItem::calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
     121                 :            :                                                 const long nPadding, sal_uInt32 nMaxTextLenght,
     122                 :            :                                                 const ThumbnailItemAttributes *pAttrs)
     123                 :            : {
     124         [ #  # ]:          0 :     drawinglayer::primitive2d::TextLayouterDevice aTextDev;
     125                 :            :     aTextDev.setFontAttribute(pAttrs->aFontAttr,
     126                 :            :                               pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
     127         [ #  # ]:          0 :                               com::sun::star::lang::Locale() );
     128                 :            : 
     129         [ #  # ]:          0 :     Size aRectSize = maDrawArea.GetSize();
     130                 :          0 :     Size aImageSize = maPreview1.GetSizePixel();
     131                 :            : 
     132                 :            :     // Calculate thumbnail position
     133                 :          0 :     Point aPos = maDrawArea.TopLeft();
     134                 :          0 :     aPos.X() = maDrawArea.getX() + (aRectSize.Width()-aImageSize.Width())/2;
     135                 :          0 :     aPos.Y() = maDrawArea.getY() + nPadding + (nThumbnailHeight-aImageSize.Height())/2;
     136                 :          0 :     maPrev1Pos = aPos;
     137                 :            : 
     138                 :            :     // Calculate text position
     139                 :          0 :     aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding;
     140 [ #  # ][ #  # ]:          0 :     aPos.Y() = aPos.Y() + aTextDev.getTextHeight() + (nDisplayHeight - aTextDev.getTextHeight())/2;
     141 [ #  # ][ #  # ]:          0 :     aPos.X() = maDrawArea.Left() + (aRectSize.Width() - aTextDev.getTextWidth(maTitle,0,nMaxTextLenght))/2;
                 [ #  # ]
     142                 :          0 :     maTextPos = aPos;
     143                 :            : 
     144                 :            :     // Calculate checkbox position
     145         [ #  # ]:          0 :     aPos.Y() -= aTextDev.getTextHeight();
     146                 :          0 :     aPos.X() = maDrawArea.Left() + 15;
     147                 :            : 
     148 [ #  # ][ #  # ]:          0 :     mpSelectBox->SetPosPixel(aPos);
     149                 :          0 : }
     150                 :            : 
     151                 :          0 : void ThumbnailViewItem::setSelectionMode (bool mode)
     152                 :            : {
     153                 :          0 :     mbMode = mode;
     154                 :            : 
     155 [ #  # ][ #  # ]:          0 :     if (!mbHover && !mbSelected && mbVisible)
                 [ #  # ]
     156                 :          0 :         mpSelectBox->Show(mode);
     157                 :          0 : }
     158                 :            : 
     159                 :          0 : void ThumbnailViewItem::setSelectClickHdl (const Link &link)
     160                 :            : {
     161                 :          0 :     maClickHdl = link;
     162                 :          0 : }
     163                 :            : 
     164                 :          0 : void ThumbnailViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
     165                 :            :                                const ThumbnailItemAttributes *pAttrs)
     166                 :            : {
     167                 :          0 :     BColor aFillColor = pAttrs->aFillColor;
     168         [ #  # ]:          0 :     Primitive2DSequence aSeq(7);
     169                 :            : 
     170                 :            :     // Draw background
     171 [ #  # ][ #  # ]:          0 :     if ( mbSelected || mbHover )
     172         [ #  # ]:          0 :         aFillColor = pAttrs->aHighlightColor;
     173                 :            : 
     174         [ #  # ]:          0 :     aSeq[0] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
     175                 :            :                                                B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
     176 [ #  # ][ #  # ]:          0 :                                                aFillColor));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     177                 :            : 
     178                 :            :     // Draw thumbnail
     179                 :          0 :     Point aPos = maPrev1Pos;
     180                 :          0 :     Size aImageSize = maPreview1.GetSizePixel();
     181                 :            : 
     182         [ #  # ]:          0 :     aSeq[1] = Primitive2DReference( new FillBitmapPrimitive2D(
     183                 :          0 :                                         createTranslateB2DHomMatrix(aPos.X(),aPos.Y()),
     184                 :            :                                         FillBitmapAttribute(maPreview1,
     185                 :            :                                                             B2DPoint(0,0),
     186                 :          0 :                                                             B2DVector(aImageSize.Width(),aImageSize.Height()),
     187                 :            :                                                             false)
     188 [ #  # ][ #  # ]:          0 :                                         ));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     189                 :            : 
     190                 :            :     // draw thumbnail borders
     191                 :          0 :     float fWidth = aImageSize.Width();
     192                 :          0 :     float fHeight = aImageSize.Height();
     193                 :          0 :     float fPosX = maPrev1Pos.getX();
     194                 :          0 :     float fPosY = maPrev1Pos.getY();
     195                 :            : 
     196         [ #  # ]:          0 :     aSeq[2] = Primitive2DReference(createBorderLine(B2DPoint(fPosX,fPosY),
     197 [ #  # ][ #  # ]:          0 :                                                            B2DPoint(fPosX+fWidth,fPosY)));
         [ #  # ][ #  # ]
     198         [ #  # ]:          0 :     aSeq[3] = Primitive2DReference(createBorderLine(B2DPoint(fPosX+fWidth,fPosY),
     199 [ #  # ][ #  # ]:          0 :                                                            B2DPoint(fPosX+fWidth,fPosY+fHeight)));
         [ #  # ][ #  # ]
     200         [ #  # ]:          0 :     aSeq[4] = Primitive2DReference(createBorderLine(B2DPoint(fPosX+fWidth,fPosY+fHeight),
     201 [ #  # ][ #  # ]:          0 :                                                            B2DPoint(fPosX,fPosY+fHeight)));
         [ #  # ][ #  # ]
     202         [ #  # ]:          0 :     aSeq[5] = Primitive2DReference(createBorderLine(B2DPoint(fPosX,fPosY+fHeight),
     203 [ #  # ][ #  # ]:          0 :                                                            B2DPoint(fPosX,fPosY)));
         [ #  # ][ #  # ]
     204                 :            : 
     205                 :            :     // Draw centered text below thumbnail
     206                 :          0 :     aPos = maTextPos;
     207                 :            : 
     208                 :            :     // Create the text primitive
     209                 :            :     basegfx::B2DHomMatrix aTextMatrix( createScaleTranslateB2DHomMatrix(
     210                 :            :                 pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
     211         [ #  # ]:          0 :                 double( aPos.X() ), double( aPos.Y() ) ) );
     212                 :            : 
     213         [ #  # ]:          0 :     aSeq[6] = Primitive2DReference(
     214                 :            :                 new TextSimplePortionPrimitive2D(aTextMatrix,
     215                 :            :                                                  maTitle,0,pAttrs->nMaxTextLenght,
     216                 :            :                                                  std::vector< double >( ),
     217                 :            :                                                  pAttrs->aFontAttr,
     218                 :            :                                                  com::sun::star::lang::Locale(),
     219 [ #  # ][ #  # ]:          0 :                                                  Color(COL_BLACK).getBColor() ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     220                 :            : 
     221         [ #  # ]:          0 :     pProcessor->process(aSeq);
     222                 :            : 
     223 [ #  # ][ #  # ]:          0 :     if (mbMode || mbHover || mbSelected)
                 [ #  # ]
     224 [ #  # ][ #  # ]:          0 :         mpSelectBox->Paint(maDrawArea);
                 [ #  # ]
     225                 :          0 : }
     226                 :            : 
     227                 :            : drawinglayer::primitive2d::BorderLinePrimitive2D*
     228                 :          0 : ThumbnailViewItem::createBorderLine (const basegfx::B2DPoint &rStart, const basegfx::B2DPoint &rEnd)
     229                 :            : {
     230                 :            :     return new BorderLinePrimitive2D(rStart,rEnd,0.5,0,0,0,0,0,0,
     231                 :            :                                      BColor(),Color(COL_BLACK).getBColor(),BColor(),
     232         [ #  # ]:          0 :                                      false,STYLE_SOLID);
     233                 :            : }
     234                 :            : 
     235                 :          0 : IMPL_LINK (ThumbnailViewItem, OnClick, CheckBox*, )
     236                 :            : {
     237                 :          0 :     mbSelected = mpSelectBox->GetState() == STATE_CHECK;
     238                 :          0 :     mpSelectBox->Invalidate();
     239                 :          0 :     maClickHdl.Call(this);
     240                 :          0 :     return 0;
     241                 :            : }
     242                 :            : 
     243                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     244                 :            : 
     245                 :            : 

Generated by: LCOV version 1.10