LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sfx2/source/control - thumbnailview.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 637 0.2 %
Date: 2013-07-09 Functions: 2 54 3.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10