LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/control - thumbnailviewitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 73 0.0 %
Date: 2012-12-27 Functions: 0 12 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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sfx2/thumbnailviewitem.hxx>
      21             : 
      22             : #include "thumbnailviewacc.hxx"
      23             : 
      24             : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      25             : #include <basegfx/range/b2drectangle.hxx>
      26             : #include <basegfx/vector/b2dsize.hxx>
      27             : #include <basegfx/polygon/b2dpolygon.hxx>
      28             : #include <drawinglayer/attribute/fillbitmapattribute.hxx>
      29             : #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
      30             : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
      31             : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      32             : #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
      33             : #include <drawinglayer/primitive2d/textprimitive2d.hxx>
      34             : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      35             : #include <vcl/button.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : 
      38             : using namespace basegfx;
      39             : using namespace basegfx::tools;
      40             : using namespace ::com::sun::star;
      41             : using namespace drawinglayer::attribute;
      42             : using namespace drawinglayer::primitive2d;
      43             : 
      44           0 : ThumbnailViewItem::ThumbnailViewItem(ThumbnailView &rView)
      45             :     : mrParent(rView)
      46             :     , mnId(0)
      47             :     , mbVisible(true)
      48             :     , mbSelected(false)
      49             :     , mbHover(false)
      50           0 :     , mpxAcc(NULL)
      51             : {
      52           0 : }
      53             : 
      54           0 : ThumbnailViewItem::~ThumbnailViewItem()
      55             : {
      56           0 :     if( mpxAcc )
      57             :     {
      58           0 :         static_cast< ThumbnailViewItemAcc* >( mpxAcc->get() )->ParentDestroyed();
      59           0 :         delete mpxAcc;
      60             :     }
      61           0 : }
      62             : 
      63           0 : void ThumbnailViewItem::show (bool bVisible)
      64             : {
      65           0 :     mbVisible = bVisible;
      66           0 : }
      67             : 
      68           0 : void ThumbnailViewItem::setSelection (bool state)
      69             : {
      70           0 :     mbSelected = state;
      71           0 : }
      72             : 
      73           0 : void ThumbnailViewItem::setHighlight (bool state)
      74             : {
      75           0 :     mbHover = state;
      76           0 : }
      77             : 
      78           0 : uno::Reference< accessibility::XAccessible > ThumbnailViewItem::GetAccessible( bool bIsTransientChildrenDisabled )
      79             : {
      80           0 :     if( !mpxAcc )
      81           0 :         mpxAcc = new uno::Reference< accessibility::XAccessible >( new ThumbnailViewItemAcc( this, bIsTransientChildrenDisabled ) );
      82             : 
      83           0 :     return *mpxAcc;
      84             : }
      85             : 
      86           0 : void ThumbnailViewItem::setDrawArea (const Rectangle &area)
      87             : {
      88           0 :     maDrawArea = area;
      89           0 : }
      90             : 
      91           0 : void ThumbnailViewItem::calculateItemsPosition (const long nThumbnailHeight, const long nDisplayHeight,
      92             :                                                 const long nPadding, sal_uInt32 nMaxTextLenght,
      93             :                                                 const ThumbnailItemAttributes *pAttrs)
      94             : {
      95           0 :     drawinglayer::primitive2d::TextLayouterDevice aTextDev;
      96             :     aTextDev.setFontAttribute(pAttrs->aFontAttr,
      97             :                               pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
      98           0 :                               com::sun::star::lang::Locale() );
      99             : 
     100           0 :     Size aRectSize = maDrawArea.GetSize();
     101           0 :     Size aImageSize = maPreview1.GetSizePixel();
     102             : 
     103             :     // Calculate thumbnail position
     104           0 :     Point aPos = maDrawArea.TopLeft();
     105           0 :     aPos.X() = maDrawArea.getX() + (aRectSize.Width()-aImageSize.Width())/2;
     106           0 :     aPos.Y() = maDrawArea.getY() + nPadding + (nThumbnailHeight-aImageSize.Height())/2;
     107           0 :     maPrev1Pos = aPos;
     108             : 
     109             :     // Calculate text position
     110           0 :     aPos.Y() = maDrawArea.getY() + nThumbnailHeight + nPadding;
     111           0 :     aPos.Y() = aPos.Y() + aTextDev.getTextHeight() + (nDisplayHeight - aTextDev.getTextHeight())/2;
     112           0 :     aPos.X() = maDrawArea.Left() + (aRectSize.Width() - aTextDev.getTextWidth(maTitle,0,nMaxTextLenght))/2;
     113           0 :     maTextPos = aPos;
     114           0 : }
     115             : 
     116           0 : void ThumbnailViewItem::setSelectClickHdl (const Link &link)
     117             : {
     118           0 :     maClickHdl = link;
     119           0 : }
     120             : 
     121           0 : void ThumbnailViewItem::Paint (drawinglayer::processor2d::BaseProcessor2D *pProcessor,
     122             :                                const ThumbnailItemAttributes *pAttrs)
     123             : {
     124           0 :     BColor aFillColor = pAttrs->aFillColor;
     125           0 :     Primitive2DSequence aSeq(4);
     126             : 
     127             :     // Draw background
     128           0 :     if ( mbSelected || mbHover )
     129           0 :         aFillColor = pAttrs->aHighlightColor;
     130             : 
     131           0 :     aSeq[0] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
     132             :                                                B2DPolyPolygon(Polygon(maDrawArea,5,5).getB2DPolygon()),
     133           0 :                                                aFillColor));
     134             : 
     135             :     // Draw thumbnail
     136           0 :     Point aPos = maPrev1Pos;
     137           0 :     Size aImageSize = maPreview1.GetSizePixel();
     138             : 
     139           0 :     aSeq[1] = Primitive2DReference( new FillBitmapPrimitive2D(
     140           0 :                                         createTranslateB2DHomMatrix(aPos.X(),aPos.Y()),
     141             :                                         FillBitmapAttribute(maPreview1,
     142             :                                                             B2DPoint(0,0),
     143           0 :                                                             B2DVector(aImageSize.Width(),aImageSize.Height()),
     144             :                                                             false)
     145           0 :                                         ));
     146             : 
     147             :     // draw thumbnail borders
     148           0 :     float fWidth = aImageSize.Width();
     149           0 :     float fHeight = aImageSize.Height();
     150           0 :     float fPosX = maPrev1Pos.getX();
     151           0 :     float fPosY = maPrev1Pos.getY();
     152             : 
     153           0 :     B2DPolygon aBounds;
     154           0 :     aBounds.append(B2DPoint(fPosX,fPosY));
     155           0 :     aBounds.append(B2DPoint(fPosX+fWidth,fPosY));
     156           0 :     aBounds.append(B2DPoint(fPosX+fWidth,fPosY+fHeight));
     157           0 :     aBounds.append(B2DPoint(fPosX,fPosY+fHeight));
     158           0 :     aBounds.setClosed(true);
     159             : 
     160           0 :     aSeq[2] = Primitive2DReference(createBorderLine(aBounds));
     161             : 
     162             :     // Draw centered text below thumbnail
     163           0 :     aPos = maTextPos;
     164             : 
     165             :     // Create the text primitive
     166             :     basegfx::B2DHomMatrix aTextMatrix( createScaleTranslateB2DHomMatrix(
     167             :                 pAttrs->aFontSize.getX(), pAttrs->aFontSize.getY(),
     168           0 :                 double( aPos.X() ), double( aPos.Y() ) ) );
     169             : 
     170           0 :     aSeq[3] = Primitive2DReference(
     171             :                 new TextSimplePortionPrimitive2D(aTextMatrix,
     172             :                                                  maTitle,0,pAttrs->nMaxTextLenght,
     173             :                                                  std::vector< double >( ),
     174             :                                                  pAttrs->aFontAttr,
     175             :                                                  com::sun::star::lang::Locale(),
     176           0 :                                                  Color(COL_BLACK).getBColor() ) );
     177             : 
     178           0 :     pProcessor->process(aSeq);
     179           0 : }
     180             : 
     181             : drawinglayer::primitive2d::PolygonHairlinePrimitive2D*
     182           0 : ThumbnailViewItem::createBorderLine (const basegfx::B2DPolygon& rPolygon)
     183             : {
     184           0 :     return new PolygonHairlinePrimitive2D(rPolygon, Color(186,186,186).getBColor());
     185             : }
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
     188             : 
     189             : 

Generated by: LCOV version 1.10