LCOV - code coverage report
Current view: top level - sfx2/source/control - thumbnailview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 576 0.0 %
Date: 2012-08-25 Functions: 0 55 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 704 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/thumbnailview.hxx>
      11                 :            : #include <sfx2/thumbnailviewitem.hxx>
      12                 :            : 
      13                 :            : #include "thumbnailviewacc.hxx"
      14                 :            : 
      15                 :            : #include <basegfx/color/bcolortools.hxx>
      16                 :            : #include <basegfx/matrix/b2dhommatrixtools.hxx>
      17                 :            : #include <basegfx/range/b2drectangle.hxx>
      18                 :            : #include <basegfx/polygon/b2dpolygon.hxx>
      19                 :            : #include <basegfx/vector/b2dsize.hxx>
      20                 :            : #include <basegfx/vector/b2dvector.hxx>
      21                 :            : #include <drawinglayer/attribute/fillbitmapattribute.hxx>
      22                 :            : #include <drawinglayer/attribute/fontattribute.hxx>
      23                 :            : #include <drawinglayer/primitive2d/fillbitmapprimitive2d.hxx>
      24                 :            : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
      25                 :            : #include <drawinglayer/primitive2d/textlayoutdevice.hxx>
      26                 :            : #include <drawinglayer/primitive2d/textprimitive2d.hxx>
      27                 :            : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
      28                 :            : #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
      29                 :            : #include <rtl/ustring.hxx>
      30                 :            : #include <vcl/decoview.hxx>
      31                 :            : #include <vcl/svapp.hxx>
      32                 :            : #include <vcl/scrbar.hxx>
      33                 :            : #include <vcl/help.hxx>
      34                 :            : 
      35                 :            : #include <com/sun/star/accessibility/AccessibleEventId.hpp>
      36                 :            : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
      37                 :            : 
      38                 :            : using namespace basegfx;
      39                 :            : using namespace basegfx::tools;
      40                 :            : using namespace drawinglayer::attribute;
      41                 :            : using namespace drawinglayer::primitive2d;
      42                 :            : 
      43                 :            : enum
      44                 :            : {
      45                 :            :     ITEM_OFFSET = 4,
      46                 :            :     ITEM_OFFSET_DOUBLE = 6,
      47                 :            :     NAME_LINE_OFF_X = 2,
      48                 :            :     NAME_LINE_OFF_Y = 2,
      49                 :            :     NAME_LINE_HEIGHT = 2,
      50                 :            :     NAME_OFFSET = 2,
      51                 :            :     SCROLL_OFFSET = 4
      52                 :            : };
      53                 :            : 
      54                 :          0 : ThumbnailView::ThumbnailView (Window *pParent, WinBits nWinStyle, bool bDisableTransientChildren)
      55 [ #  # ][ #  # ]:          0 :     : Control( pParent, nWinStyle )
         [ #  # ][ #  # ]
      56                 :            : {
      57         [ #  # ]:          0 :     ImplInit();
      58                 :          0 :     mbIsTransientChildrenDisabled = bDisableTransientChildren;
      59                 :          0 : }
      60                 :            : 
      61                 :          0 : ThumbnailView::ThumbnailView (Window *pParent, const ResId &rResId, bool bDisableTransientChildren)
      62 [ #  # ][ #  # ]:          0 :     : Control( pParent, rResId )
         [ #  # ][ #  # ]
      63                 :            : {
      64         [ #  # ]:          0 :     ImplInit();
      65                 :          0 :     mbIsTransientChildrenDisabled = bDisableTransientChildren;
      66                 :          0 : }
      67                 :            : 
      68         [ #  # ]:          0 : ThumbnailView::~ThumbnailView()
      69                 :            : {
      70                 :            :     com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>
      71                 :            :             xComponent(GetAccessible(sal_False),
      72 [ #  # ][ #  # ]:          0 :                        com::sun::star::uno::UNO_QUERY);
      73                 :            : 
      74         [ #  # ]:          0 :     if (xComponent.is())
      75 [ #  # ][ #  # ]:          0 :         xComponent->dispose ();
      76                 :            : 
      77 [ #  # ][ #  # ]:          0 :     delete mpScrBar;
      78 [ #  # ][ #  # ]:          0 :     delete mpItemAttrs;
      79                 :            : 
      80         [ #  # ]:          0 :     ImplDeleteItems();
      81         [ #  # ]:          0 : }
      82                 :            : 
      83                 :          0 : void ThumbnailView::ImplInit()
      84                 :            : {
      85                 :          0 :     mpScrBar            = NULL;
      86                 :          0 :     mnHeaderHeight      = 0;
      87                 :          0 :     mnItemWidth         = 0;
      88                 :          0 :     mnItemHeight        = 0;
      89                 :          0 :     mnItemPadding = 0;
      90                 :          0 :     mnVisLines          = 0;
      91                 :          0 :     mnLines             = 0;
      92                 :          0 :     mnFirstLine         = 0;
      93                 :          0 :     mnScrBarOffset = 1;
      94                 :          0 :     mnSelItemId         = 0;
      95                 :          0 :     mnHighItemId        = 0;
      96                 :          0 :     mnCols              = 0;
      97                 :          0 :     mnSpacing           = 0;
      98                 :          0 :     mbScroll            = false;
      99                 :          0 :     mbHasVisibleItems   = false;
     100                 :          0 :     mbSelectionMode = false;
     101         [ #  # ]:          0 :     maFilterFunc = ViewFilterAll();
     102                 :          0 :     maColor = GetSettings().GetStyleSettings().GetDialogColor();
     103                 :            : 
     104                 :            :     // Create the processor and process the primitives
     105         [ #  # ]:          0 :     const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
     106         [ #  # ]:          0 :     mpProcessor = drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(*this, aNewViewInfos );
     107                 :            : 
     108 [ #  # ][ #  # ]:          0 :     ImplInitSettings( true, true, true );
     109                 :          0 : }
     110                 :            : 
     111                 :          0 : void ThumbnailView::ImplDeleteItems()
     112                 :            : {
     113                 :          0 :     const size_t n = mItemList.size();
     114                 :            : 
     115         [ #  # ]:          0 :     for ( size_t i = 0; i < n; ++i )
     116                 :            :     {
     117                 :          0 :         ThumbnailViewItem *const pItem = mItemList[i];
     118 [ #  # ][ #  # ]:          0 :         if ( pItem->isVisible() && ImplHasAccessibleListeners() )
                 [ #  # ]
     119                 :            :         {
     120                 :          0 :             ::com::sun::star::uno::Any aOldAny, aNewAny;
     121                 :            : 
     122 [ #  # ][ #  # ]:          0 :             aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
     123         [ #  # ]:          0 :             ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
     124                 :            :         }
     125                 :            : 
     126         [ #  # ]:          0 :         delete pItem;
     127                 :            :     }
     128                 :            : 
     129                 :          0 :     mItemList.clear();
     130                 :          0 : }
     131                 :            : 
     132                 :          0 : void ThumbnailView::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
     133                 :            : {
     134                 :          0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     135                 :            : 
     136         [ #  # ]:          0 :     if ( bFont )
     137                 :            :     {
     138         [ #  # ]:          0 :         Font aFont;
     139         [ #  # ]:          0 :         aFont = rStyleSettings.GetAppFont();
     140 [ #  # ][ #  # ]:          0 :         if ( IsControlFont() )
     141 [ #  # ][ #  # ]:          0 :             aFont.Merge( GetControlFont() );
                 [ #  # ]
     142 [ #  # ][ #  # ]:          0 :         SetZoomedPointFont( aFont );
     143                 :            :     }
     144                 :            : 
     145 [ #  # ][ #  # ]:          0 :     if ( bForeground || bFont )
     146                 :            :     {
     147                 :          0 :         Color aColor;
     148 [ #  # ][ #  # ]:          0 :         if ( IsControlForeground() )
     149         [ #  # ]:          0 :             aColor = GetControlForeground();
     150                 :            :         else
     151                 :          0 :             aColor = rStyleSettings.GetButtonTextColor();
     152         [ #  # ]:          0 :         SetTextColor( aColor );
     153         [ #  # ]:          0 :         SetTextFillColor();
     154                 :            :     }
     155                 :            : 
     156         [ #  # ]:          0 :     if ( bBackground )
     157                 :            :     {
     158                 :          0 :         Color aColor;
     159 [ #  # ][ #  # ]:          0 :         if ( IsControlBackground() )
     160         [ #  # ]:          0 :             aColor = GetControlBackground();
     161                 :            :         else
     162                 :          0 :             aColor = rStyleSettings.GetFaceColor();
     163 [ #  # ][ #  # ]:          0 :         SetBackground( aColor );
                 [ #  # ]
     164                 :            :     }
     165                 :            : 
     166         [ #  # ]:          0 :     mpItemAttrs = new ThumbnailItemAttributes;
     167         [ #  # ]:          0 :     mpItemAttrs->aFillColor = maColor.getBColor();
     168         [ #  # ]:          0 :     mpItemAttrs->aHighlightColor = rStyleSettings.GetHighlightColor().getBColor();
     169         [ #  # ]:          0 :     mpItemAttrs->aFontAttr = getFontAttributeFromVclFont(mpItemAttrs->aFontSize,GetFont(),false,true);
     170                 :          0 :     mpItemAttrs->nMaxTextLenght = -1;
     171                 :          0 : }
     172                 :            : 
     173                 :          0 : void ThumbnailView::ImplInitScrollBar()
     174                 :            : {
     175         [ #  # ]:          0 :     if ( GetStyle() & WB_VSCROLL )
     176                 :            :     {
     177         [ #  # ]:          0 :         if ( !mpScrBar )
     178                 :            :         {
     179         [ #  # ]:          0 :             mpScrBar = new ScrollBar( this, WB_VSCROLL | WB_DRAG );
     180                 :          0 :             mpScrBar->SetScrollHdl( LINK( this, ThumbnailView, ImplScrollHdl ) );
     181                 :            :         }
     182                 :            :         else
     183                 :            :         {
     184                 :            :             // adapt the width because of the changed settings
     185                 :          0 :             long nScrBarWidth = GetSettings().GetStyleSettings().GetScrollBarSize();
     186                 :          0 :             mpScrBar->SetPosSizePixel( 0, 0, nScrBarWidth, 0, WINDOW_POSSIZE_WIDTH );
     187                 :            :         }
     188                 :            :     }
     189                 :          0 : }
     190                 :            : 
     191                 :          0 : void ThumbnailView::DrawItem (ThumbnailViewItem *pItem)
     192                 :            : {
     193         [ #  # ]:          0 :     if (pItem->isVisible())
     194                 :            :     {
     195                 :          0 :         Rectangle aRect = pItem->getDrawArea();
     196                 :            : 
     197 [ #  # ][ #  # ]:          0 :         if ( (aRect.GetHeight() > 0) && (aRect.GetWidth() > 0) )
         [ #  # ][ #  # ]
                 [ #  # ]
     198         [ #  # ]:          0 :             pItem->Paint(mpProcessor,mpItemAttrs);
     199                 :            :     }
     200                 :          0 : }
     201                 :            : 
     202                 :          0 : void ThumbnailView::OnSelectionMode (bool bMode)
     203                 :            : {
     204         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
     205                 :            :     {
     206                 :          0 :         mItemList[i]->setSelectionMode(bMode);
     207                 :            : 
     208         [ #  # ]:          0 :         if (mItemList[i]->isVisible())
     209                 :          0 :             DrawItem(mItemList[i]);
     210                 :            :     }
     211                 :          0 : }
     212                 :            : 
     213                 :          0 : void ThumbnailView::OnItemDblClicked (ThumbnailViewItem*)
     214                 :            : {
     215                 :          0 : }
     216                 :            : 
     217                 :          0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ThumbnailView::CreateAccessible()
     218                 :            : {
     219 [ #  # ][ #  # ]:          0 :     return new ThumbnailViewAcc( this, mbIsTransientChildrenDisabled );
     220                 :            : }
     221                 :            : 
     222                 :          0 : void ThumbnailView::CalculateItemPositions ()
     223                 :            : {
     224 [ #  # ][ #  # ]:          0 :     if (!mnItemHeight || !mnItemWidth)
     225                 :          0 :         return;
     226                 :            : 
     227                 :          0 :     Size        aWinSize = GetOutputSizePixel();
     228                 :          0 :     size_t      nItemCount = mItemList.size();
     229         [ #  # ]:          0 :     WinBits     nStyle = GetStyle();
     230                 :          0 :     ScrollBar*  pDelScrBar = NULL;
     231                 :            : 
     232                 :            :     // consider the scrolling
     233         [ #  # ]:          0 :     if ( nStyle & WB_VSCROLL )
     234         [ #  # ]:          0 :         ImplInitScrollBar();
     235                 :            :     else
     236                 :            :     {
     237         [ #  # ]:          0 :         if ( mpScrBar )
     238                 :            :         {
     239                 :            :             // delete ScrollBar not until later, to prevent recursive calls
     240                 :          0 :             pDelScrBar = mpScrBar;
     241                 :          0 :             mpScrBar = NULL;
     242                 :            :         }
     243                 :            :     }
     244                 :            : 
     245                 :            :     // calculate ScrollBar width
     246                 :          0 :     long nScrBarWidth = 0;
     247         [ #  # ]:          0 :     if ( mpScrBar )
     248         [ #  # ]:          0 :         nScrBarWidth = mpScrBar->GetSizePixel().Width()+mnScrBarOffset;
     249                 :            : 
     250                 :            :     // calculate maximum number of visible columns
     251                 :          0 :     mnCols = (sal_uInt16)((aWinSize.Width()-nScrBarWidth) / (mnItemWidth));
     252                 :            : 
     253         [ #  # ]:          0 :     if (!mnCols)
     254                 :          0 :         mnCols = 1;
     255                 :            : 
     256                 :            :     // calculate maximum number of visible rows
     257                 :          0 :     mnVisLines = (sal_uInt16)((aWinSize.Height()-mnHeaderHeight) / (mnItemHeight));
     258                 :            : 
     259                 :            :     // calculate empty space
     260                 :          0 :     long nHSpace = aWinSize.Width()-nScrBarWidth - mnCols*mnItemWidth;
     261                 :          0 :     long nVSpace = aWinSize.Height()-mnHeaderHeight - mnVisLines*mnItemHeight;
     262                 :          0 :     long nHItemSpace = nHSpace / (mnCols+1);
     263                 :          0 :     long nVItemSpace = nVSpace / (mnVisLines+1);
     264                 :            : 
     265                 :            :     // calculate maximum number of rows
     266                 :            :     // Floor( (M+N-1)/N )==Ceiling( M/N )
     267                 :          0 :     mnLines = (static_cast<long>(nItemCount)+mnCols-1) / mnCols;
     268                 :            : 
     269         [ #  # ]:          0 :     if ( !mnLines )
     270                 :          0 :         mnLines = 1;
     271                 :            : 
     272                 :            :     // check if scroll is needed
     273                 :          0 :     mbScroll = mnLines > mnVisLines;
     274                 :            : 
     275         [ #  # ]:          0 :     if ( mnLines <= mnVisLines )
     276                 :          0 :         mnFirstLine = 0;
     277                 :            :     else
     278                 :            :     {
     279         [ #  # ]:          0 :         if ( mnFirstLine > (sal_uInt16)(mnLines-mnVisLines) )
     280                 :          0 :             mnFirstLine = (sal_uInt16)(mnLines-mnVisLines);
     281                 :            :     }
     282                 :            : 
     283                 :          0 :     mbHasVisibleItems = true;
     284                 :            : 
     285                 :            :     // calculate offsets
     286                 :          0 :     long nStartX = nHItemSpace;
     287                 :          0 :     long nStartY = nVItemSpace + mnHeaderHeight;
     288                 :            : 
     289                 :            :     // calculate and draw items
     290                 :          0 :     long x = nStartX;
     291                 :          0 :     long y = nStartY;
     292                 :            : 
     293                 :            :     // draw items
     294                 :          0 :     size_t nFirstItem = mnFirstLine * mnCols;
     295                 :          0 :     size_t nLastItem = nFirstItem + (mnVisLines * mnCols);
     296                 :          0 :     size_t nTotalItems = mnFirstLine*mnCols + mnVisLines*mnCols;
     297                 :            : 
     298                 :          0 :     maItemListRect.Left() = x;
     299                 :          0 :     maItemListRect.Top() = y;
     300                 :          0 :     maItemListRect.Right() = x + mnCols*(mnItemWidth+nHItemSpace) - nHItemSpace - 1;
     301                 :          0 :     maItemListRect.Bottom() = y + mnVisLines*(mnItemHeight+nVItemSpace) - nVItemSpace - 1;
     302                 :            : 
     303                 :            :     // If want also draw parts of items in the last line,
     304                 :            :     // then we add one more line if parts of these line are
     305                 :            :     // visible
     306         [ #  # ]:          0 :     if ( y+(mnVisLines*(mnItemHeight+nVItemSpace)) < aWinSize.Height() )
     307                 :          0 :         nTotalItems += mnCols;
     308                 :            : 
     309                 :          0 :     size_t nCurCount = 0;
     310         [ #  # ]:          0 :     for ( size_t i = 0; i < nItemCount; i++ )
     311                 :            :     {
     312         [ #  # ]:          0 :         ThumbnailViewItem *const pItem = mItemList[i];
     313                 :            : 
     314 [ #  # ][ #  # ]:          0 :         if (maFilterFunc(pItem))
     315                 :            :         {
     316 [ #  # ][ #  # ]:          0 :             if ((nCurCount >= nFirstItem) && (nCurCount < nLastItem))
     317                 :            :             {
     318         [ #  # ]:          0 :                 if( !pItem->isVisible())
     319                 :            :                 {
     320 [ #  # ][ #  # ]:          0 :                     if ( ImplHasAccessibleListeners() )
     321                 :            :                     {
     322                 :          0 :                         ::com::sun::star::uno::Any aOldAny, aNewAny;
     323                 :            : 
     324 [ #  # ][ #  # ]:          0 :                         aNewAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
     325         [ #  # ]:          0 :                         ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
     326                 :            :                     }
     327                 :            : 
     328         [ #  # ]:          0 :                     pItem->show(true);
     329                 :            : 
     330         [ #  # ]:          0 :                     maItemStateHdl.Call(pItem);
     331                 :            :                 }
     332                 :            : 
     333 [ #  # ][ #  # ]:          0 :                 pItem->setDrawArea(Rectangle( Point(x,y), Size(mnItemWidth, mnItemHeight) ));
     334         [ #  # ]:          0 :                 pItem->calculateItemsPosition(mnThumbnailHeight,mnDisplayHeight,mnItemPadding,mpItemAttrs->nMaxTextLenght,mpItemAttrs);
     335                 :            : 
     336         [ #  # ]:          0 :                 if ( !((nCurCount+1) % mnCols) )
     337                 :            :                 {
     338                 :          0 :                     x = nStartX;
     339                 :          0 :                     y += mnItemHeight+nVItemSpace;
     340                 :            :                 }
     341                 :            :                 else
     342                 :          0 :                     x += mnItemWidth+nHItemSpace;
     343                 :            :             }
     344                 :            :             else
     345                 :            :             {
     346         [ #  # ]:          0 :                 if( pItem->isVisible())
     347                 :            :                 {
     348 [ #  # ][ #  # ]:          0 :                     if ( ImplHasAccessibleListeners() )
     349                 :            :                     {
     350                 :          0 :                         ::com::sun::star::uno::Any aOldAny, aNewAny;
     351                 :            : 
     352 [ #  # ][ #  # ]:          0 :                         aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
     353         [ #  # ]:          0 :                         ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
     354                 :            :                     }
     355                 :            : 
     356         [ #  # ]:          0 :                     pItem->show(false);
     357                 :            : 
     358         [ #  # ]:          0 :                     maItemStateHdl.Call(pItem);
     359                 :            :                 }
     360                 :            : 
     361                 :            :             }
     362                 :            : 
     363                 :          0 :             ++nCurCount;
     364                 :            :         }
     365                 :            :         else
     366                 :            :         {
     367         [ #  # ]:          0 :             if( pItem->isVisible())
     368                 :            :             {
     369 [ #  # ][ #  # ]:          0 :                 if ( ImplHasAccessibleListeners() )
     370                 :            :                 {
     371                 :          0 :                     ::com::sun::star::uno::Any aOldAny, aNewAny;
     372                 :            : 
     373 [ #  # ][ #  # ]:          0 :                     aOldAny <<= pItem->GetAccessible( mbIsTransientChildrenDisabled );
     374         [ #  # ]:          0 :                     ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::CHILD, aOldAny, aNewAny );
     375                 :            :                 }
     376                 :            : 
     377         [ #  # ]:          0 :                 pItem->show(false);
     378                 :            : 
     379         [ #  # ]:          0 :                 maItemStateHdl.Call(pItem);
     380                 :            :             }
     381                 :            :         }
     382                 :            :     }
     383                 :            : 
     384                 :            :     // arrange ScrollBar, set values and show it
     385         [ #  # ]:          0 :     if ( mpScrBar )
     386                 :            :     {
     387                 :          0 :         long nLines = (nCurCount+mnCols-1)/mnCols;
     388                 :            : 
     389                 :          0 :         Point aPos( aWinSize.Width() - nScrBarWidth - mnScrBarOffset, mnHeaderHeight );
     390                 :          0 :         Size aSize( nScrBarWidth - mnScrBarOffset, aWinSize.Height() - mnHeaderHeight );
     391                 :            : 
     392         [ #  # ]:          0 :         mpScrBar->SetPosSizePixel( aPos, aSize );
     393         [ #  # ]:          0 :         mpScrBar->SetRangeMax( (nCurCount+mnCols-1)/mnCols);
     394         [ #  # ]:          0 :         mpScrBar->SetVisibleSize( mnVisLines );
     395         [ #  # ]:          0 :         mpScrBar->SetThumbPos( (long)mnFirstLine );
     396                 :          0 :         long nPageSize = mnVisLines;
     397         [ #  # ]:          0 :         if ( nPageSize < 1 )
     398                 :          0 :             nPageSize = 1;
     399                 :          0 :         mpScrBar->SetPageSize( nPageSize );
     400         [ #  # ]:          0 :         mpScrBar->Show( nLines > mnVisLines );
     401                 :            :     }
     402                 :            : 
     403                 :            :     // delete ScrollBar
     404 [ #  # ][ #  # ]:          0 :     delete pDelScrBar;
     405                 :            : }
     406                 :            : 
     407                 :          0 : bool ThumbnailView::ImplScroll( const Point& rPos )
     408                 :            : {
     409 [ #  # ][ #  # ]:          0 :     if ( !mbScroll || !maItemListRect.IsInside(rPos) )
                 [ #  # ]
     410                 :          0 :         return false;
     411                 :            : 
     412         [ #  # ]:          0 :     const long nScrollOffset = (mnItemHeight <= 16) ? SCROLL_OFFSET/2 : SCROLL_OFFSET;
     413                 :          0 :     bool bScroll = false;
     414                 :            : 
     415         [ #  # ]:          0 :     if ( rPos.Y() <= maItemListRect.Top()+nScrollOffset )
     416                 :            :     {
     417         [ #  # ]:          0 :         if ( mnFirstLine > 0 )
     418                 :            :         {
     419                 :          0 :             --mnFirstLine;
     420                 :          0 :             bScroll = true;
     421                 :            :         }
     422                 :            :     }
     423         [ #  # ]:          0 :     else if ( rPos.Y() >= maItemListRect.Bottom()-nScrollOffset )
     424                 :            :     {
     425         [ #  # ]:          0 :         if ( mnFirstLine < static_cast<sal_uInt16>(mnLines-mnVisLines) )
     426                 :            :         {
     427                 :          0 :             ++mnFirstLine;
     428                 :          0 :             bScroll = true;
     429                 :            :         }
     430                 :            :     }
     431                 :            : 
     432         [ #  # ]:          0 :     if ( !bScroll )
     433                 :          0 :         return false;
     434                 :            : 
     435 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     436                 :          0 :         Invalidate();
     437                 :            : 
     438                 :          0 :     return true;
     439                 :            : }
     440                 :            : 
     441                 :          0 : size_t ThumbnailView::ImplGetItem( const Point& rPos, bool bMove ) const
     442                 :            : {
     443         [ #  # ]:          0 :     if ( !mbHasVisibleItems )
     444                 :            :     {
     445                 :          0 :         return THUMBNAILVIEW_ITEM_NOTFOUND;
     446                 :            :     }
     447                 :            : 
     448         [ #  # ]:          0 :     if ( maItemListRect.IsInside( rPos ) )
     449                 :            :     {
     450         [ #  # ]:          0 :         for (size_t i = 0; i < mItemList.size(); ++i)
     451                 :            :         {
     452 [ #  # ][ #  # ]:          0 :             if (mItemList[i]->isVisible() && mItemList[i]->getDrawArea().IsInside(rPos))
                 [ #  # ]
     453                 :          0 :                 return i;
     454                 :            :         }
     455                 :            : 
     456                 :            :         // return the previously selected item if spacing is set and
     457                 :            :         // the mouse hasn't left the window yet
     458 [ #  # ][ #  # ]:          0 :         if ( bMove && mnSpacing && mnHighItemId )
                 [ #  # ]
     459                 :            :         {
     460                 :          0 :             return GetItemPos( mnHighItemId );
     461                 :            :         }
     462                 :            :     }
     463                 :            : 
     464                 :          0 :     return THUMBNAILVIEW_ITEM_NOTFOUND;
     465                 :            : }
     466                 :            : 
     467                 :          0 : ThumbnailViewItem* ThumbnailView::ImplGetItem( size_t nPos )
     468                 :            : {
     469         [ #  # ]:          0 :     return ( nPos < mItemList.size() ) ? mItemList[nPos] : NULL;
     470                 :            : }
     471                 :            : 
     472                 :          0 : sal_uInt16 ThumbnailView::ImplGetVisibleItemCount() const
     473                 :            : {
     474                 :          0 :     sal_uInt16 nRet = 0;
     475                 :          0 :     const size_t nItemCount = mItemList.size();
     476                 :            : 
     477         [ #  # ]:          0 :     for ( size_t n = 0; n < nItemCount; ++n )
     478                 :            :     {
     479         [ #  # ]:          0 :         if ( mItemList[n]->isVisible() )
     480                 :          0 :             ++nRet;
     481                 :            :     }
     482                 :            : 
     483                 :          0 :     return nRet;
     484                 :            : }
     485                 :            : 
     486                 :          0 : ThumbnailViewItem* ThumbnailView::ImplGetVisibleItem( sal_uInt16 nVisiblePos )
     487                 :            : {
     488                 :          0 :     const size_t nItemCount = mItemList.size();
     489                 :            : 
     490         [ #  # ]:          0 :     for ( size_t n = 0; n < nItemCount; ++n )
     491                 :            :     {
     492                 :          0 :         ThumbnailViewItem *const pItem = mItemList[n];
     493                 :            : 
     494 [ #  # ][ #  # ]:          0 :         if ( pItem->isVisible() && !nVisiblePos-- )
                 [ #  # ]
     495                 :          0 :             return pItem;
     496                 :            :     }
     497                 :            : 
     498                 :          0 :     return NULL;
     499                 :            : }
     500                 :            : 
     501                 :          0 : void ThumbnailView::ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue )
     502                 :            : {
     503                 :          0 :     ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
     504                 :            : 
     505         [ #  # ]:          0 :     if( pAcc )
     506                 :          0 :         pAcc->FireAccessibleEvent( nEventId, rOldValue, rNewValue );
     507                 :          0 : }
     508                 :            : 
     509                 :          0 : bool ThumbnailView::ImplHasAccessibleListeners()
     510                 :            : {
     511                 :          0 :     ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
     512 [ #  # ][ #  # ]:          0 :     return( pAcc && pAcc->HasAccessibleListeners() );
     513                 :            : }
     514                 :            : 
     515                 :          0 : IMPL_LINK( ThumbnailView,ImplScrollHdl, ScrollBar*, pScrollBar )
     516                 :            : {
     517                 :          0 :     sal_uInt16 nNewFirstLine = mnFirstLine;
     518                 :            : 
     519         [ #  # ]:          0 :     if (pScrollBar->GetDelta() > 0)
     520                 :          0 :         nNewFirstLine += 1;
     521                 :            :     else
     522                 :          0 :         nNewFirstLine -= 1;
     523                 :            : 
     524         [ #  # ]:          0 :     if ( nNewFirstLine != mnFirstLine )
     525                 :            :     {
     526                 :          0 :         mnFirstLine = nNewFirstLine;
     527                 :            : 
     528                 :          0 :         CalculateItemPositions();
     529                 :            : 
     530 [ #  # ][ #  # ]:          0 :         if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     531                 :          0 :             Invalidate();
     532                 :            :     }
     533                 :          0 :     return 0;
     534                 :            : }
     535                 :            : 
     536                 :          0 : IMPL_LINK (ThumbnailView, OnItemSelected, ThumbnailViewItem*, pItem)
     537                 :            : {
     538                 :          0 :     maItemStateHdl.Call(pItem);
     539                 :          0 :     return 0;
     540                 :            : }
     541                 :            : 
     542                 :          0 : void ThumbnailView::MouseButtonDown( const MouseEvent& rMEvt )
     543                 :            : {
     544         [ #  # ]:          0 :     if ( rMEvt.IsLeft() )
     545                 :            :     {
     546                 :          0 :         ThumbnailViewItem* pItem = ImplGetItem( ImplGetItem( rMEvt.GetPosPixel() ) );
     547                 :            : 
     548 [ #  # ][ #  # ]:          0 :         if (pItem && pItem->isVisible())
                 [ #  # ]
     549                 :            :         {
     550         [ #  # ]:          0 :             if ( !rMEvt.IsMod2() )
     551                 :            :             {
     552         [ #  # ]:          0 :                 if ( rMEvt.GetClicks() == 1 )
     553                 :            :                 {
     554         [ #  # ]:          0 :                     if (mbSelectionMode)
     555                 :            :                     {
     556                 :          0 :                         pItem->setSelection(!pItem->isSelected());
     557                 :            : 
     558         [ #  # ]:          0 :                         if (!pItem->isHighlighted())
     559                 :          0 :                             DrawItem(pItem);
     560                 :            : 
     561                 :          0 :                         maItemStateHdl.Call(pItem);
     562                 :            :                     }
     563                 :            :                     else
     564                 :            :                     {
     565                 :          0 :                         Rectangle aRect(pItem->getDrawArea());
     566                 :          0 :                         aRect.setY(aRect.getY()+mnItemPadding+mnThumbnailHeight);
     567         [ #  # ]:          0 :                         aRect.SetSize(Size(mnItemWidth,mnDisplayHeight+mnItemPadding));
     568                 :            : 
     569 [ #  # ][ #  # ]:          0 :                         if (aRect.IsInside(rMEvt.GetPosPixel()))
     570                 :            :                         {
     571         [ #  # ]:          0 :                             pItem->setSelection(!pItem->isSelected());
     572                 :            : 
     573         [ #  # ]:          0 :                             if (!pItem->isHighlighted())
     574         [ #  # ]:          0 :                                 DrawItem(pItem);
     575                 :            : 
     576         [ #  # ]:          0 :                             maItemStateHdl.Call(pItem);
     577                 :            :                         }
     578                 :            : 
     579                 :            :                         //StartTracking( STARTTRACK_SCROLLREPEAT );
     580                 :            :                     }
     581                 :            :                 }
     582         [ #  # ]:          0 :                 else if ( rMEvt.GetClicks() == 2 )
     583                 :            :                 {
     584                 :          0 :                     Rectangle aRect(pItem->getDrawArea());
     585         [ #  # ]:          0 :                     aRect.SetSize(Size(mnItemWidth,mnThumbnailHeight));
     586                 :            : 
     587 [ #  # ][ #  # ]:          0 :                     if (!mbSelectionMode && aRect.IsInside(rMEvt.GetPosPixel()))
         [ #  # ][ #  # ]
     588         [ #  # ]:          0 :                         OnItemDblClicked(pItem);
     589                 :            :                 }
     590                 :            :             }
     591                 :            : 
     592                 :          0 :             return;
     593                 :            :         }
     594                 :            :     }
     595                 :            : 
     596                 :          0 :     Control::MouseButtonDown( rMEvt );
     597                 :            : }
     598                 :            : 
     599                 :          0 : void ThumbnailView::MouseButtonUp( const MouseEvent& rMEvt )
     600                 :            : {
     601                 :          0 :     Control::MouseButtonUp( rMEvt );
     602                 :          0 : }
     603                 :            : 
     604                 :          0 : void ThumbnailView::MouseMove( const MouseEvent& rMEvt )
     605                 :            : {
     606                 :          0 :     ThumbnailViewItem* pItem = ImplGetItem( ImplGetItem( rMEvt.GetPosPixel() ) );
     607                 :            : 
     608         [ #  # ]:          0 :     if (pItem)
     609                 :            :     {
     610 [ #  # ][ #  # ]:          0 :         if (mnHighItemId != pItem->mnId && pItem->isVisible())
                 [ #  # ]
     611                 :            :         {
     612                 :          0 :             size_t nPos = GetItemPos(mnHighItemId);
     613                 :            : 
     614         [ #  # ]:          0 :             if (nPos != THUMBNAILVIEW_ITEM_NOTFOUND)
     615                 :            :             {
     616                 :          0 :                 ThumbnailViewItem *pOld = mItemList[nPos];
     617                 :            : 
     618                 :          0 :                 pOld->setHighlight(false);
     619                 :            : 
     620         [ #  # ]:          0 :                 if (!pOld->isSelected())
     621                 :          0 :                     DrawItem(pOld);
     622                 :            :             }
     623                 :            : 
     624                 :          0 :             mnHighItemId = pItem->mnId;
     625                 :          0 :             pItem->setHighlight(true);
     626                 :            : 
     627         [ #  # ]:          0 :             if (!pItem->isSelected())
     628                 :          0 :                 DrawItem(pItem);
     629                 :            :         }
     630                 :            :     }
     631                 :            :     else
     632                 :            :     {
     633         [ #  # ]:          0 :         if (mnHighItemId)
     634                 :            :         {
     635                 :          0 :             size_t nPos = GetItemPos(mnHighItemId);
     636                 :            : 
     637         [ #  # ]:          0 :             if (nPos != THUMBNAILVIEW_ITEM_NOTFOUND)
     638                 :            :             {
     639                 :          0 :                 ThumbnailViewItem *pOld = mItemList[nPos];
     640                 :            : 
     641                 :          0 :                 pOld->setHighlight(false);
     642                 :            : 
     643         [ #  # ]:          0 :                 if (!pOld->isSelected())
     644                 :          0 :                     DrawItem(pOld);
     645                 :            :             }
     646                 :            : 
     647                 :          0 :             mnHighItemId = 0;
     648                 :            :         }
     649                 :            :     }
     650                 :            : 
     651                 :          0 :     Control::MouseMove( rMEvt );
     652                 :          0 : }
     653                 :            : 
     654                 :          0 : void ThumbnailView::Command( const CommandEvent& rCEvt )
     655                 :            : {
     656   [ #  #  #  #  :          0 :     if ( (rCEvt.GetCommand() == COMMAND_WHEEL) ||
           #  # ][ #  # ]
     657                 :          0 :          (rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) ||
     658                 :          0 :          (rCEvt.GetCommand() == COMMAND_AUTOSCROLL) )
     659                 :            :     {
     660         [ #  # ]:          0 :         if ( HandleScrollCommand( rCEvt, NULL, mpScrBar ) )
     661                 :          0 :             return;
     662                 :            :     }
     663                 :            : 
     664                 :          0 :     Control::Command( rCEvt );
     665                 :            : }
     666                 :            : 
     667                 :          0 : void ThumbnailView::Paint( const Rectangle &aRect)
     668                 :            : {
     669                 :          0 :     size_t      nItemCount = mItemList.size();
     670                 :            : 
     671                 :            :     // Draw background
     672         [ #  # ]:          0 :     Primitive2DSequence aSeq(1);
     673         [ #  # ]:          0 :     aSeq[0] = Primitive2DReference( new PolyPolygonColorPrimitive2D(
     674                 :            :                                         B2DPolyPolygon(Polygon(aRect,5,5).getB2DPolygon()),
     675 [ #  # ][ #  # ]:          0 :                                         maColor.getBColor()));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     676                 :            : 
     677         [ #  # ]:          0 :     mpProcessor->process(aSeq);
     678                 :            : 
     679                 :            :     // draw items
     680         [ #  # ]:          0 :     for ( size_t i = 0; i < nItemCount; i++ )
     681                 :            :     {
     682         [ #  # ]:          0 :         ThumbnailViewItem *const pItem = mItemList[i];
     683                 :            : 
     684         [ #  # ]:          0 :         if ( pItem->isVisible() )
     685         [ #  # ]:          0 :             DrawItem(pItem);
     686                 :            :     }
     687                 :            : 
     688 [ #  # ][ #  # ]:          0 :     if ( mpScrBar && mpScrBar->IsVisible() )
         [ #  # ][ #  # ]
     689 [ #  # ][ #  # ]:          0 :         mpScrBar->Paint(aRect);
     690                 :          0 : }
     691                 :            : 
     692                 :          0 : void ThumbnailView::GetFocus()
     693                 :            : {
     694                 :          0 :     Control::GetFocus();
     695                 :            : 
     696                 :            :     // Tell the accessible object that we got the focus.
     697                 :          0 :     ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
     698         [ #  # ]:          0 :     if( pAcc )
     699                 :          0 :         pAcc->GetFocus();
     700                 :          0 : }
     701                 :            : 
     702                 :          0 : void ThumbnailView::LoseFocus()
     703                 :            : {
     704         [ #  # ]:          0 :     if (mnHighItemId)
     705                 :            :     {
     706                 :          0 :         size_t nPos = GetItemPos(mnHighItemId);
     707                 :            : 
     708         [ #  # ]:          0 :         if (nPos != THUMBNAILVIEW_ITEM_NOTFOUND)
     709                 :            :         {
     710                 :          0 :             ThumbnailViewItem *pOld = mItemList[nPos];
     711                 :            : 
     712                 :          0 :             pOld->setHighlight(false);
     713                 :            : 
     714         [ #  # ]:          0 :             if (!pOld->isSelected())
     715                 :          0 :                 DrawItem(pOld);
     716                 :            :         }
     717                 :            : 
     718                 :          0 :         mnHighItemId = 0;
     719                 :            :     }
     720                 :            : 
     721                 :          0 :     Control::LoseFocus();
     722                 :            : 
     723                 :            :     // Tell the accessible object that we lost the focus.
     724                 :          0 :     ThumbnailViewAcc* pAcc = ThumbnailViewAcc::getImplementation( GetAccessible( sal_False ) );
     725         [ #  # ]:          0 :     if( pAcc )
     726                 :          0 :         pAcc->LoseFocus();
     727                 :          0 : }
     728                 :            : 
     729                 :          0 : void ThumbnailView::Resize()
     730                 :            : {
     731                 :          0 :     CalculateItemPositions();
     732                 :            : 
     733 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     734                 :          0 :         Invalidate();
     735                 :          0 :     Control::Resize();
     736                 :          0 : }
     737                 :            : 
     738                 :          0 : void ThumbnailView::StateChanged( StateChangedType nType )
     739                 :            : {
     740                 :          0 :     Control::StateChanged( nType );
     741                 :            : 
     742         [ #  # ]:          0 :     if ( nType == STATE_CHANGE_INITSHOW )
     743                 :            :     {
     744 [ #  # ][ #  # ]:          0 :         if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     745                 :          0 :             Invalidate();
     746                 :            :     }
     747         [ #  # ]:          0 :     else if ( nType == STATE_CHANGE_UPDATEMODE )
     748                 :            :     {
     749 [ #  # ][ #  # ]:          0 :         if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     750                 :          0 :             Invalidate();
     751                 :            :     }
     752         [ #  # ]:          0 :     else if ( nType == STATE_CHANGE_TEXT )
     753                 :            :     {
     754                 :            :     }
     755 [ #  # ][ #  # ]:          0 :     else if ( (nType == STATE_CHANGE_ZOOM) ||
     756                 :            :               (nType == STATE_CHANGE_CONTROLFONT) )
     757                 :            :     {
     758                 :          0 :         ImplInitSettings( true, false, false );
     759                 :          0 :         Invalidate();
     760                 :            :     }
     761         [ #  # ]:          0 :     else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
     762                 :            :     {
     763                 :          0 :         ImplInitSettings( false, true, false );
     764                 :          0 :         Invalidate();
     765                 :            :     }
     766         [ #  # ]:          0 :     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
     767                 :            :     {
     768                 :          0 :         ImplInitSettings( false, false, true );
     769                 :          0 :         Invalidate();
     770                 :            :     }
     771 [ #  # ][ #  # ]:          0 :     else if ( (nType == STATE_CHANGE_STYLE) || (nType == STATE_CHANGE_ENABLE) )
     772                 :            :     {
     773                 :          0 :         ImplInitSettings( false, false, true );
     774                 :          0 :         Invalidate();
     775                 :            :     }
     776                 :          0 : }
     777                 :            : 
     778                 :          0 : void ThumbnailView::DataChanged( const DataChangedEvent& rDCEvt )
     779                 :            : {
     780                 :          0 :     Control::DataChanged( rDCEvt );
     781                 :            : 
     782 [ #  # ][ #  #  :          0 :     if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
          #  #  #  #  #  
                #  #  # ]
     783                 :          0 :          (rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
     784                 :          0 :          (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
     785                 :          0 :          ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
     786                 :          0 :           (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
     787                 :            :     {
     788                 :          0 :         ImplInitSettings( true, true, true );
     789                 :          0 :         Invalidate();
     790                 :            :     }
     791                 :          0 : }
     792                 :            : 
     793                 :          0 : void ThumbnailView::InsertItem( sal_uInt16 nItemId, const BitmapEx& rImage,
     794                 :            :                            const OUString& rText, size_t nPos )
     795                 :            : {
     796         [ #  # ]:          0 :     ThumbnailViewItem* pItem = new ThumbnailViewItem( *this, this );
     797                 :          0 :     pItem->mnId     = nItemId;
     798                 :          0 :     pItem->maPreview1 = rImage;
     799                 :          0 :     pItem->maTitle   = rText;
     800         [ #  # ]:          0 :     pItem->setSelectClickHdl(LINK(this,ThumbnailView,OnItemSelected));
     801                 :          0 :     ImplInsertItem( pItem, nPos );
     802                 :          0 : }
     803                 :            : 
     804                 :          0 : void ThumbnailView::ImplInsertItem( ThumbnailViewItem *const pItem, const size_t nPos )
     805                 :            : {
     806                 :            :     assert(pItem->mnId); // "ItemId == 0"
     807                 :            :     assert(GetItemPos( pItem->mnId ) == THUMBNAILVIEW_ITEM_NOTFOUND); // ItemId already exists
     808                 :            : 
     809         [ #  # ]:          0 :     if ( nPos < mItemList.size() ) {
     810                 :          0 :         ValueItemList::iterator it = mItemList.begin();
     811         [ #  # ]:          0 :         ::std::advance( it, nPos );
     812         [ #  # ]:          0 :         mItemList.insert( it, pItem );
     813                 :            :     } else {
     814                 :          0 :         mItemList.push_back( pItem );
     815                 :            :     }
     816                 :            : 
     817                 :          0 :     CalculateItemPositions();
     818                 :            : 
     819 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     820                 :          0 :         Invalidate();
     821                 :          0 : }
     822                 :            : 
     823                 :          0 : void ThumbnailView::RemoveItem( sal_uInt16 nItemId )
     824                 :            : {
     825                 :          0 :     size_t nPos = GetItemPos( nItemId );
     826                 :            : 
     827         [ #  # ]:          0 :     if ( nPos == THUMBNAILVIEW_ITEM_NOTFOUND )
     828                 :          0 :         return;
     829                 :            : 
     830         [ #  # ]:          0 :     if ( nPos < mItemList.size() ) {
     831                 :          0 :         ValueItemList::iterator it = mItemList.begin();
     832         [ #  # ]:          0 :         ::std::advance( it, nPos );
     833 [ #  # ][ #  # ]:          0 :         delete *it;
                 [ #  # ]
     834         [ #  # ]:          0 :         mItemList.erase( it );
     835                 :            :     }
     836                 :            : 
     837                 :            :     // reset variables
     838 [ #  # ][ #  # ]:          0 :     if ( (mnHighItemId == nItemId) || (mnSelItemId == nItemId) )
     839                 :            :     {
     840                 :          0 :         mnHighItemId    = 0;
     841                 :          0 :         mnSelItemId     = 0;
     842                 :            :     }
     843                 :            : 
     844                 :          0 :     CalculateItemPositions();
     845                 :            : 
     846 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     847                 :          0 :         Invalidate();
     848                 :            : }
     849                 :            : 
     850                 :          0 : void ThumbnailView::Clear()
     851                 :            : {
     852                 :          0 :     ImplDeleteItems();
     853                 :            : 
     854                 :            :     // reset variables
     855                 :          0 :     mnFirstLine     = 0;
     856                 :          0 :     mnHighItemId    = 0;
     857                 :          0 :     mnSelItemId     = 0;
     858                 :            : 
     859                 :          0 :     CalculateItemPositions();
     860                 :            : 
     861 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     862                 :          0 :         Invalidate();
     863                 :          0 : }
     864                 :            : 
     865                 :          0 : size_t ThumbnailView::GetItemCount() const
     866                 :            : {
     867                 :          0 :     return mItemList.size();
     868                 :            : }
     869                 :            : 
     870                 :          0 : size_t ThumbnailView::GetItemPos( sal_uInt16 nItemId ) const
     871                 :            : {
     872         [ #  # ]:          0 :     for ( size_t i = 0, n = mItemList.size(); i < n; ++i ) {
     873         [ #  # ]:          0 :         if ( mItemList[i]->mnId == nItemId ) {
     874                 :          0 :             return i;
     875                 :            :         }
     876                 :            :     }
     877                 :          0 :     return THUMBNAILVIEW_ITEM_NOTFOUND;
     878                 :            : }
     879                 :            : 
     880                 :          0 : sal_uInt16 ThumbnailView::GetItemId( size_t nPos ) const
     881                 :            : {
     882         [ #  # ]:          0 :     return ( nPos < mItemList.size() ) ? mItemList[nPos]->mnId : 0 ;
     883                 :            : }
     884                 :            : 
     885                 :          0 : sal_uInt16 ThumbnailView::GetItemId( const Point& rPos ) const
     886                 :            : {
     887                 :          0 :     size_t nItemPos = ImplGetItem( rPos );
     888         [ #  # ]:          0 :     if ( nItemPos != THUMBNAILVIEW_ITEM_NOTFOUND )
     889                 :          0 :         return GetItemId( nItemPos );
     890                 :            : 
     891                 :          0 :     return 0;
     892                 :            : }
     893                 :            : 
     894                 :          0 : void ThumbnailView::setItemMaxTextLength(sal_uInt32 nLength)
     895                 :            : {
     896                 :          0 :     mpItemAttrs->nMaxTextLenght = nLength;
     897                 :          0 : }
     898                 :            : 
     899                 :          0 : void ThumbnailView::setItemDimensions(long itemWidth, long thumbnailHeight, long displayHeight, int itemPadding)
     900                 :            : {
     901                 :          0 :     mnItemWidth = itemWidth + 2*itemPadding;
     902                 :          0 :     mnThumbnailHeight = thumbnailHeight;
     903                 :          0 :     mnDisplayHeight = displayHeight;
     904                 :          0 :     mnItemPadding = itemPadding;
     905                 :          0 :     mnItemHeight = mnDisplayHeight + mnThumbnailHeight + 2*itemPadding;
     906                 :          0 : }
     907                 :            : 
     908                 :          0 : void ThumbnailView::SelectItem( sal_uInt16 nItemId )
     909                 :            : {
     910                 :          0 :     size_t nItemPos = 0;
     911                 :            : 
     912         [ #  # ]:          0 :     if ( nItemId )
     913                 :            :     {
     914                 :          0 :         nItemPos = GetItemPos( nItemId );
     915         [ #  # ]:          0 :         if ( nItemPos == THUMBNAILVIEW_ITEM_NOTFOUND )
     916                 :          0 :             return;
     917                 :            :     }
     918                 :            : 
     919         [ #  # ]:          0 :     if ( mnSelItemId != nItemId)
     920                 :            :     {
     921         [ #  # ]:          0 :         sal_uInt16 nOldItem = mnSelItemId ? mnSelItemId : 1;
     922                 :          0 :         mnSelItemId = nItemId;
     923                 :            : 
     924 [ #  # ][ #  # ]:          0 :         bool bNewOut = IsReallyVisible() && IsUpdateMode();
     925                 :            : 
     926                 :            :         // if necessary scroll to the visible area
     927 [ #  # ][ #  # ]:          0 :         if ( mbScroll && nItemId )
     928                 :            :         {
     929                 :          0 :             sal_uInt16 nNewLine = (sal_uInt16)(nItemPos / mnCols);
     930         [ #  # ]:          0 :             if ( nNewLine < mnFirstLine )
     931                 :            :             {
     932                 :          0 :                 mnFirstLine = nNewLine;
     933                 :            :             }
     934         [ #  # ]:          0 :             else if ( nNewLine > (sal_uInt16)(mnFirstLine+mnVisLines-1) )
     935                 :            :             {
     936                 :          0 :                 mnFirstLine = (sal_uInt16)(nNewLine-mnVisLines+1);
     937                 :            :             }
     938                 :            :         }
     939                 :            : 
     940         [ #  # ]:          0 :         if ( bNewOut )
     941                 :            :         {
     942 [ #  # ][ #  # ]:          0 :             if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
     943                 :          0 :                 Invalidate();
     944                 :            :         }
     945                 :            : 
     946         [ #  # ]:          0 :         if( ImplHasAccessibleListeners() )
     947                 :            :         {
     948                 :            :             // focus event (deselect)
     949         [ #  # ]:          0 :             if( nOldItem )
     950                 :            :             {
     951         [ #  # ]:          0 :                 const size_t nPos = GetItemPos( nItemId );
     952                 :            : 
     953         [ #  # ]:          0 :                 if( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
     954                 :            :                 {
     955                 :            :                     ThumbnailViewAcc* pItemAcc = ThumbnailViewAcc::getImplementation(
     956 [ #  # ][ #  # ]:          0 :                         mItemList[nPos]->GetAccessible( mbIsTransientChildrenDisabled ) );
     957                 :            : 
     958         [ #  # ]:          0 :                     if( pItemAcc )
     959                 :            :                     {
     960                 :          0 :                         ::com::sun::star::uno::Any aOldAny, aNewAny;
     961         [ #  # ]:          0 :                         if( !mbIsTransientChildrenDisabled )
     962                 :            :                         {
     963                 :            :                             aOldAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
     964 [ #  # ][ #  # ]:          0 :                                 static_cast< ::cppu::OWeakObject* >( pItemAcc ));
     965         [ #  # ]:          0 :                             ImplFireAccessibleEvent (::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
     966                 :            :                         }
     967                 :            :                         else
     968                 :            :                         {
     969         [ #  # ]:          0 :                             aOldAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
     970         [ #  # ]:          0 :                             pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
     971                 :          0 :                         }
     972                 :            :                     }
     973                 :            :                 }
     974                 :            :             }
     975                 :            : 
     976                 :            :             // focus event (select)
     977         [ #  # ]:          0 :             const size_t nPos = GetItemPos( mnSelItemId );
     978                 :            : 
     979                 :          0 :             ThumbnailViewItem* pItem = NULL;
     980         [ #  # ]:          0 :             if( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
     981         [ #  # ]:          0 :                 pItem = mItemList[nPos];
     982                 :            : 
     983                 :          0 :             ThumbnailViewAcc* pItemAcc = NULL;
     984         [ #  # ]:          0 :             if (pItem != NULL)
     985         [ #  # ]:          0 :                 pItemAcc = ThumbnailViewAcc::getImplementation( pItem->GetAccessible( mbIsTransientChildrenDisabled ) );
     986                 :            : 
     987         [ #  # ]:          0 :             if( pItemAcc )
     988                 :            :             {
     989                 :          0 :                 ::com::sun::star::uno::Any aOldAny, aNewAny;
     990         [ #  # ]:          0 :                 if( !mbIsTransientChildrenDisabled )
     991                 :            :                 {
     992                 :            :                     aNewAny <<= ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >(
     993 [ #  # ][ #  # ]:          0 :                         static_cast< ::cppu::OWeakObject* >( pItemAcc ));
     994         [ #  # ]:          0 :                     ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldAny, aNewAny );
     995                 :            :                 }
     996                 :            :                 else
     997                 :            :                 {
     998         [ #  # ]:          0 :                     aNewAny <<= ::com::sun::star::accessibility::AccessibleStateType::FOCUSED;
     999         [ #  # ]:          0 :                     pItemAcc->FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::STATE_CHANGED, aOldAny, aNewAny );
    1000                 :          0 :                 }
    1001                 :            :             }
    1002                 :            : 
    1003                 :            :             // selection event
    1004                 :          0 :             ::com::sun::star::uno::Any aOldAny, aNewAny;
    1005         [ #  # ]:          0 :             ImplFireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventId::SELECTION_CHANGED, aOldAny, aNewAny );
    1006                 :            :         }
    1007                 :            :     }
    1008                 :            : }
    1009                 :            : 
    1010                 :          0 : void ThumbnailView::deselectItem(const sal_uInt16 nItemId)
    1011                 :            : {
    1012         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
    1013                 :            :     {
    1014         [ #  # ]:          0 :         if (mItemList[i]->mnId == nItemId)
    1015                 :            :         {
    1016                 :          0 :             mItemList[i]->setSelection(false);
    1017                 :            : 
    1018                 :          0 :             maItemStateHdl.Call(mItemList[i]);
    1019                 :            : 
    1020 [ #  # ][ #  # ]:          0 :             if (IsReallyVisible() && IsUpdateMode())
                 [ #  # ]
    1021                 :          0 :                 mItemList[i]->Paint(mpProcessor,mpItemAttrs);
    1022                 :            : 
    1023                 :          0 :             break;
    1024                 :            :         }
    1025                 :            :     }
    1026                 :          0 : }
    1027                 :            : 
    1028                 :          0 : void ThumbnailView::deselectItems()
    1029                 :            : {
    1030         [ #  # ]:          0 :     for (size_t i = 0, n = mItemList.size(); i < n; ++i)
    1031                 :            :     {
    1032         [ #  # ]:          0 :         if (mItemList[i]->isSelected())
    1033                 :            :         {
    1034                 :          0 :             mItemList[i]->setSelection(false);
    1035                 :            : 
    1036                 :          0 :             maItemStateHdl.Call(mItemList[i]);
    1037                 :            :         }
    1038                 :            :     }
    1039                 :            : 
    1040 [ #  # ][ #  # ]:          0 :     if (IsReallyVisible() && IsUpdateMode())
                 [ #  # ]
    1041                 :          0 :         Invalidate();
    1042                 :          0 : }
    1043                 :            : 
    1044                 :          0 : OUString ThumbnailView::GetItemText( sal_uInt16 nItemId ) const
    1045                 :            : {
    1046                 :          0 :     size_t nPos = GetItemPos( nItemId );
    1047                 :            : 
    1048         [ #  # ]:          0 :     if ( nPos != THUMBNAILVIEW_ITEM_NOTFOUND )
    1049                 :          0 :         return mItemList[nPos]->maTitle;
    1050                 :            : 
    1051                 :          0 :     return OUString();
    1052                 :            : }
    1053                 :            : 
    1054                 :          0 : void ThumbnailView::SetColor( const Color& rColor )
    1055                 :            : {
    1056                 :          0 :     maColor = rColor;
    1057         [ #  # ]:          0 :     mpItemAttrs->aFillColor = rColor.getBColor();
    1058                 :            : 
    1059 [ #  # ][ #  # ]:          0 :     if ( IsReallyVisible() && IsUpdateMode() )
                 [ #  # ]
    1060                 :          0 :         Invalidate();
    1061                 :          0 : }
    1062                 :            : 
    1063                 :          0 : bool ThumbnailView::StartDrag( const CommandEvent& rCEvt, Region& rRegion )
    1064                 :            : {
    1065         [ #  # ]:          0 :     if ( rCEvt.GetCommand() != COMMAND_STARTDRAG )
    1066                 :          0 :         return false;
    1067                 :            : 
    1068                 :            :     // if necessary abort an existing action
    1069                 :            : 
    1070                 :            :     // Check out if the the clicked on page is selected. If this is not the
    1071                 :            :     // case set it as the current item. We only check mouse actions since
    1072                 :            :     // drag-and-drop can also be triggered by the keyboard
    1073                 :            :     sal_uInt16 nSelId;
    1074         [ #  # ]:          0 :     if ( rCEvt.IsMouseEvent() )
    1075         [ #  # ]:          0 :         nSelId = GetItemId( rCEvt.GetMousePosPixel() );
    1076                 :            :     else
    1077                 :          0 :         nSelId = mnSelItemId;
    1078                 :            : 
    1079                 :            :     // don't activate dragging if no item was clicked on
    1080         [ #  # ]:          0 :     if ( !nSelId )
    1081                 :          0 :         return false;
    1082                 :            : 
    1083                 :            :     // Check out if the page was selected. If not set as current page and
    1084                 :            :     // call select.
    1085         [ #  # ]:          0 :     if ( nSelId != mnSelItemId )
    1086                 :            :     {
    1087         [ #  # ]:          0 :         SelectItem( nSelId );
    1088         [ #  # ]:          0 :         Update();
    1089                 :            :     }
    1090                 :            : 
    1091         [ #  # ]:          0 :     Region aRegion;
    1092                 :            : 
    1093                 :            :     // assign region
    1094         [ #  # ]:          0 :     rRegion = aRegion;
    1095                 :            : 
    1096         [ #  # ]:          0 :     return true;
    1097                 :            : }
    1098                 :            : 
    1099                 :          0 : Size ThumbnailView::CalcWindowSizePixel (sal_uInt16 nCols, sal_uInt16 nLines,
    1100                 :            :                                          sal_uInt16 nItemWidth, sal_uInt16 nItemHeight,
    1101                 :            :                                          sal_uInt16 nItemSpace)
    1102                 :            : {
    1103                 :          0 :     Size aSize(nItemWidth*nCols, nItemHeight*nLines);
    1104                 :            : 
    1105                 :          0 :     aSize.Width()  += nItemSpace*(nCols+1);
    1106                 :          0 :     aSize.Height() += nItemSpace*(nLines+1);
    1107                 :            : 
    1108                 :          0 :     aSize.Height() += mnHeaderHeight;
    1109                 :            : 
    1110                 :            :     // sum possible ScrollBar width
    1111                 :          0 :     aSize.Width() += GetScrollWidth();
    1112                 :            : 
    1113                 :          0 :     return aSize;
    1114                 :            : }
    1115                 :            : 
    1116                 :          0 : long ThumbnailView::GetScrollWidth() const
    1117                 :            : {
    1118         [ #  # ]:          0 :     if ( GetStyle() & WB_VSCROLL )
    1119                 :            :     {
    1120                 :          0 :         ((ThumbnailView*)this)->ImplInitScrollBar();
    1121                 :          0 :         return mpScrBar->GetSizePixel().Width()+mnScrBarOffset;
    1122                 :            :     }
    1123                 :            :     else
    1124                 :          0 :         return 0;
    1125                 :            : }
    1126                 :            : 
    1127                 :          0 : void ThumbnailView::setSelectionMode (bool mode)
    1128                 :            : {
    1129                 :          0 :     mbSelectionMode = mode;
    1130                 :            : 
    1131                 :          0 :     OnSelectionMode(mode);
    1132                 :          0 : }
    1133                 :            : 
    1134                 :          0 : void ThumbnailView::filterItems (const boost::function<bool (const ThumbnailViewItem*) > &func)
    1135                 :            : {
    1136                 :          0 :     mnFirstLine = 0;        // start at the top of the list instead of the current position
    1137                 :          0 :     maFilterFunc = func;
    1138                 :            : 
    1139                 :          0 :     CalculateItemPositions();
    1140                 :            : 
    1141                 :          0 :     Invalidate();
    1142                 :          0 : }
    1143                 :            : 
    1144                 :          0 : void ThumbnailView::sortItems (const boost::function<bool (const ThumbnailViewItem*, const ThumbnailViewItem*) > &func)
    1145                 :            : {
    1146         [ #  # ]:          0 :     std::sort(mItemList.begin(),mItemList.end(),func);
    1147                 :            : 
    1148                 :          0 :     CalculateItemPositions();
    1149                 :            : 
    1150                 :          0 :     Invalidate();
    1151                 :          0 : }
    1152                 :            : 
    1153                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
    1154                 :            : 
    1155                 :            : 

Generated by: LCOV version 1.10