LCOV - code coverage report
Current view: top level - include/sfx2 - thumbnailview.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 3 0.0 %
Date: 2014-04-14 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #ifndef INCLUDED_SFX2_THUMBNAILVIEW_HXX
      11             : #define INCLUDED_SFX2_THUMBNAILVIEW_HXX
      12             : 
      13             : #include <sfx2/dllapi.h>
      14             : 
      15             : #include <vector>
      16             : #include <boost/function.hpp>
      17             : 
      18             : #include <comphelper/processfactory.hxx>
      19             : #include <unotools/ucbstreamhelper.hxx>
      20             : #include <sfx2/thumbnailviewitem.hxx>
      21             : #include <vcl/ctrl.hxx>
      22             : #include <vcl/timer.hxx>
      23             : #include <vcl/pngread.hxx>
      24             : 
      25             : #include <com/sun/star/embed/ElementModes.hpp>
      26             : #include <com/sun/star/embed/XStorage.hpp>
      27             : #include <com/sun/star/embed/StorageFactory.hpp>
      28             : 
      29             : class BitmapEx;
      30             : class MouseEvent;
      31             : class TrackingEvent;
      32             : class HelpEvent;
      33             : class KeyEvent;
      34             : class DataChangedEvent;
      35             : class ScrollBar;
      36             : typedef ::std::vector< ThumbnailViewItem* > ThumbnailValueItemList;
      37             : 
      38             : struct ThumbnailItemAttributes;
      39             : class ThumbnailViewAcc;
      40             : class ThumbnailViewItemAcc;
      41             : 
      42             : namespace drawinglayer {
      43             :     namespace processor2d {
      44             :         class BaseProcessor2D;
      45             :     }
      46             : }
      47             : 
      48             : /*************************************************************************
      49             : 
      50             :     Description
      51             :     ============
      52             : 
      53             :     class ThumbnailView
      54             : 
      55             :     This class allows the selection of an item. In the process items are
      56             :     drawn side by side. The selection of items can be more clear than in a
      57             :     ListBox shape for example in case of colors or samples.
      58             :     The amount of columns drawn by the control and whether the items
      59             :     should be encircled can be specified. Optional a NoSelection or name
      60             :     field could be shown. By default image and color items are supported.
      61             :     Items could be drawn by oneself if InsertItem() is only called with
      62             :     an ID. To achieve this the UserDraw handler needs to be overloaded. The
      63             :     description text could be specified afterwards in case of UserDraw
      64             :     and any other items.
      65             : 
      66             :     Cross references
      67             : 
      68             :     class ListBox
      69             : 
      70             :     --------------------------------------------------------------------------
      71             : 
      72             :     WinBits
      73             : 
      74             :     WB_VSCROLL          A scroolbar will be always shown. The visible number of
      75             :                         lines have to be specified with SetLineCount() if this
      76             :                         flag is set.
      77             :     WB_TABSTOP          It is possible to jump into the ValueSet with the tab key.
      78             :     WB_NOTABSTOP        It is not possible to jump into the ValueSet with the
      79             :                         tab key.
      80             :     --------------------------------------------------------------------------
      81             : 
      82             :     The number of columns must be either set with SetColCount() or
      83             :     SetItemWidth(). If the number of columns is specified by SetColCount()
      84             :     the width of the items will be calculated by the visible range.
      85             :     If the items should have a static width, it has to be specified
      86             :     with SetItemWidth(). In this case the number of columns will be calculated
      87             :     by the visible range.
      88             : 
      89             :     The number of rows is given by the number of items / number of columns. The
      90             :     number of visible rows must either specified by SetLineCount() or
      91             :     SetItemWidth(). If the number of visible rows is specified by SetLineCount(),
      92             :     the height of the items will be calculated from the visible height. If the
      93             :     items should have a fixed height it has to be specified with SetItemHeight().
      94             :     In this case the number of visible rows is then calculated from the visible
      95             :     height. If the number of visible rows is neither specified by SetLineCount()
      96             :     nor by SetItemHeight() all rows will be shown. The height of the items will
      97             :     be calculated by the visible height. If the number of visible rows is
      98             :     specified by SetLineCount() or SetItemHeight() ValueSet does scroll
      99             :     automatically when more lines are available, as are visible. If scrolling
     100             :     should be also possible with a ScrollBar  WB_VSCROLL needs to be set.
     101             : 
     102             :     The distance between the items can be increased by SetExtraSpacing(). The
     103             :     distance, which will be shown between two items (both in x and in y), is
     104             :     measured in pixels.
     105             : 
     106             :     The exact window size for a specific item size can be calculated by
     107             :     CalcWindowSizePixel(). To do this all relevant data (number of columns/...)
     108             :     have to be specified and if no number of rows was set, all items need to
     109             :     be inserted. If the window was created with WB_BORDER/Border=sal_True the
     110             :     size has to be specified with SetOutputSizePixel(). In other cases different
     111             :     size-methods can be used. With CalcItemSize() the inner and outer size of
     112             :     an item could be calculated (for this the free space defined by
     113             :     SetExtraSpacing() will not be included).
     114             : 
     115             :     The background color could be specified by SetColor(), with which the image
     116             :     or UserDraw items will be underlayed. If no color is specified the color
     117             :     of other windows (WindowColor) will be used for the background.
     118             : 
     119             :     --------------------------------------------------------------------------
     120             : 
     121             :     At first all items should be inserted and only then Show() should be called
     122             :     since the output area will be precomputed. If this is not done the first
     123             :     Paint will appear a little bit slower. Therefore the Control, if it is loaded
     124             :     from the resource and only supplied with items during runtime, should be
     125             :     loaded with Hide = sal_True and then displayed with Show().
     126             : 
     127             :     In case of a visible Control the creation of the new output area could be
     128             :     activated before Paint by calling Format().
     129             : 
     130             :     --------------------------------------------------------------------------
     131             : 
     132             :     If Drag and Drop will be called from the ValueSet the Command-Handler has to
     133             :     be overloaded. From this StartDrag needs to be called. If this method returns
     134             :     sal_True the drag-process could be initiated by  ExecuteDrag(), otherwise no
     135             :     processing will take place. This method makes sure that ValueSet stops its
     136             :     processing and as appropriate selects the entry. Therefore the calling of
     137             :     Select-Handler within this function must be expected.
     138             : 
     139             :     For dropping QueryDrop() and Drop() need to be overloaded and ShowDropPos()
     140             :     and HideDropPos() should be called within these methods.
     141             :     To show the insertion point ShowDropPos() has to be called within the
     142             :     QueryDrop-Handler. ShowDropPos() also scrolls the ValueSet if the passed
     143             :     position is located at the window border. Furthermore ShowDropPos() returns
     144             :     the position, at which the item should be inserted respectively which
     145             :     insertion point was shown. If no insertion point was determined
     146             :     VALUESET_ITEM_NOTFOUND will be returned. If the window was left during dragging
     147             :     or the drag process is terminated HideDropPos() should be called in any case.
     148             : 
     149             :     --------------------------------------------------------------------------
     150             : 
     151             :     This class is currently still in the SV-Tools. That's why the ValueSet needs
     152             :     to be loaded as a Control out of the resource and the desired WinBits have
     153             :     to be set (before Show) with SetStyle().
     154             : 
     155             : *************************************************************************/
     156             : 
     157             : /* ThumbnailView types */
     158             : 
     159             : #define THUMBNAILVIEW_APPEND         ((sal_uInt16)-1)
     160             : #define THUMBNAILVIEW_ITEM_NOTFOUND  ((sal_uInt16)-1)
     161             : 
     162             : // Display all the available items in the thumbnail.
     163             : class ViewFilterAll
     164             : {
     165             : public:
     166             : 
     167           0 :     bool operator () (const ThumbnailViewItem*) const
     168             :     {
     169           0 :         return true;
     170             :     }
     171             : };
     172             : 
     173             : /**
     174             :  *
     175             :  *  Class to display thumbnails with their names below their respective icons
     176             :  *
     177             :  **/
     178             : 
     179             : class SFX2_DLLPUBLIC ThumbnailView : public Control
     180             : {
     181             : public:
     182             : 
     183             :     ThumbnailView ( Window* pParent, WinBits nWinStyle = WB_TABSTOP, bool bDisableTransientChildren = false );
     184             : 
     185             :     virtual ~ThumbnailView ();
     186             : 
     187             :     virtual void        MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     188             : 
     189             :     void AppendItem (ThumbnailViewItem *pItem);
     190             : 
     191             :     void RemoveItem( sal_uInt16 nItemId );
     192             : 
     193             :     virtual void Clear();
     194             : 
     195             :     // Change current thumbnail item list with new one (invalidates all pointers to a thumbnail item)
     196             :     void updateItems(const std::vector<ThumbnailViewItem *> &items);
     197             : 
     198             :     size_t GetItemPos( sal_uInt16 nItemId ) const;
     199             : 
     200             :     sal_uInt16 GetItemId( size_t nPos ) const;
     201             : 
     202             :     sal_uInt16 GetItemId( const Point& rPos ) const;
     203             : 
     204             :     sal_uInt16 getNextItemId () const;
     205             : 
     206             :     long GetItemWidth() const { return mnItemWidth; }
     207             : 
     208             :     long GetItemHeight() const { return mnItemHeight; }
     209             : 
     210             :     void setItemMaxTextLength (sal_uInt32 nLength);
     211             : 
     212             :     void setItemDimensions (long ItemWidth, long ThumbnailHeight,
     213             :                             long DisplayHeight, int itemPadding);
     214             : 
     215             :     sal_uInt16 GetFirstLine() const { return mnFirstLine; }
     216             : 
     217             :     void SelectItem( sal_uInt16 nItemId );
     218             : 
     219             :     bool IsItemSelected( sal_uInt16 nItemId ) const;
     220             : 
     221             :     /**
     222             :      *
     223             :      * @brief deselect all current selected items.
     224             :      *
     225             :      **/
     226             : 
     227             :     void deselectItems ();
     228             : 
     229             :     void ShowTooltips( bool bShowTooltips );
     230             : 
     231             :     Color GetColor() const { return maColor; }
     232             : 
     233             :     bool IsColor() const { return maColor.GetTransparency() == 0; }
     234             : 
     235             :     void filterItems (const boost::function<bool (const ThumbnailViewItem*) > &func);
     236             : 
     237             :     void sortItems (const boost::function<bool (const ThumbnailViewItem*,
     238             :                                                 const ThumbnailViewItem*) > &func);
     239             : 
     240           0 :     void setItemStateHdl (const Link &aLink) { maItemStateHdl = aLink; }
     241             : 
     242             :     virtual void Resize() SAL_OVERRIDE;
     243             : 
     244             :     virtual bool renameItem(ThumbnailViewItem* pItem, const OUString& sNewTitle);
     245             : 
     246             :     static BitmapEx readThumbnail(const OUString &msURL);
     247             : 
     248             : protected:
     249             : 
     250             :     virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
     251             : 
     252             :     virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     253             : 
     254             :     virtual void MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     255             : 
     256             :     virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
     257             : 
     258             :     virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
     259             : 
     260             :     virtual void GetFocus() SAL_OVERRIDE;
     261             : 
     262             :     virtual void LoseFocus() SAL_OVERRIDE;
     263             : 
     264             :     virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
     265             : 
     266             :     virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
     267             : 
     268             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
     269             : 
     270             : protected:
     271             : 
     272             :     // Drawing item related functions, override them to make your own custom ones.
     273             : 
     274             :     virtual void DrawItem (ThumbnailViewItem *pItem);
     275             : 
     276             :     virtual void OnItemDblClicked (ThumbnailViewItem *pItem);
     277             : 
     278             : protected:
     279             : 
     280             :     friend class ThumbnailViewAcc;
     281             :     friend class ThumbnailViewItemAcc;
     282             :     using Control::ImplInitSettings;
     283             :     using Window::ImplInit;
     284             : 
     285             :     void CalculateItemPositions ();
     286             :     void MakeItemVisible( sal_uInt16 nId );
     287             : 
     288             :     SFX2_DLLPRIVATE void         ImplInit();
     289             :     SFX2_DLLPRIVATE void         ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
     290             :     SFX2_DLLPRIVATE void         ImplInitScrollBar();
     291             :     SFX2_DLLPRIVATE void         ImplDeleteItems();
     292             :     SFX2_DLLPRIVATE void         ImplDraw();
     293             :     SFX2_DLLPRIVATE size_t       ImplGetItem( const Point& rPoint ) const;
     294             :     SFX2_DLLPRIVATE ThumbnailViewItem*    ImplGetItem( size_t nPos );
     295             :     SFX2_DLLPRIVATE sal_uInt16          ImplGetVisibleItemCount() const;
     296             :     SFX2_DLLPRIVATE ThumbnailViewItem*    ImplGetVisibleItem( sal_uInt16 nVisiblePos );
     297             :     SFX2_DLLPRIVATE void            ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
     298             :     SFX2_DLLPRIVATE bool         ImplHasAccessibleListeners();
     299             :     DECL_DLLPRIVATE_LINK( ImplScrollHdl, ScrollBar* );
     300             : 
     301             :     DECL_LINK(OnItemSelected, ThumbnailViewItem*);
     302             : 
     303             : protected:
     304             : 
     305             :     ThumbnailValueItemList mItemList;
     306             :     ThumbnailValueItemList mFilteredItemList; ///< Cache to store the filtered items
     307             :     ThumbnailValueItemList::iterator mpStartSelRange;
     308             :     ScrollBar* mpScrBar;
     309             :     Rectangle maItemListRect;
     310             :     long mnHeaderHeight;
     311             :     long mnItemWidth;
     312             :     long mnItemHeight;
     313             :     long mnItemPadding;
     314             :     long mnThumbnailHeight;     // Maximum height of the thumbnail
     315             :     long mnDisplayHeight;       // Height of the data display box (name, etc)
     316             :     long mnVisLines;
     317             :     long mnLines;
     318             : 
     319             :     int mnFineness;
     320             : 
     321             :     sal_uInt16 mnCols;
     322             :     sal_uInt16 mnFirstLine;
     323             :     bool mbScroll : 1;
     324             :     bool mbIsTransientChildrenDisabled : 1;
     325             :     bool mbHasVisibleItems : 1;
     326             :     bool mbShowTooltips : 1;
     327             :     Color maColor;
     328             : 
     329             :     Link maItemStateHdl;
     330             :     ThumbnailItemAttributes *mpItemAttrs;
     331             :     drawinglayer::processor2d::BaseProcessor2D *mpProcessor;
     332             :     boost::function<bool (const ThumbnailViewItem*) > maFilterFunc;
     333             : };
     334             : 
     335             : #endif // INCLUDED_SFX2_THUMBNAILVIEW_HXX
     336             : 
     337             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10