LCOV - code coverage report
Current view: top level - include/svtools - svlbitm.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 17 48 35.4 %
Date: 2015-06-13 12:38:46 Functions: 6 19 31.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #ifndef INCLUDED_SVTOOLS_SVLBITM_HXX
      22             : #define INCLUDED_SVTOOLS_SVLBITM_HXX
      23             : 
      24             : #include <svtools/svtdllapi.h>
      25             : #include <tools/link.hxx>
      26             : #include <vcl/image.hxx>
      27             : #include <svtools/treelistbox.hxx>
      28             : #include <o3tl/typed_flags_set.hxx>
      29             : 
      30             : class SvTreeListEntry;
      31             : 
      32             : 
      33             : enum class SvBmp
      34             : {
      35             :     UNCHECKED        = 0,
      36             :     CHECKED          = 1,
      37             :     TRISTATE         = 2,
      38             :     HIUNCHECKED      = 3,
      39             :     HICHECKED        = 4,
      40             :     HITRISTATE       = 5,
      41             :     STATICIMAGE      = 6
      42             : };
      43             : 
      44             : enum class SvItemStateFlags
      45             : {
      46             :     NONE               = 0x00,
      47             :     UNCHECKED          = 0x01,
      48             :     CHECKED            = 0x02,
      49             :     TRISTATE           = 0x04,
      50             :     HILIGHTED          = 0x08
      51             : };
      52             : namespace o3tl
      53             : {
      54             :     template<> struct typed_flags<SvItemStateFlags> : is_typed_flags<SvItemStateFlags, 0x0f> {};
      55             : }
      56             : 
      57             : struct SvLBoxButtonData_Impl;
      58             : 
      59             : class SVT_DLLPUBLIC SvLBoxButtonData
      60             : {
      61             : private:
      62             :     Link<>                  aLink;
      63             :     long                    nWidth;
      64             :     long                    nHeight;
      65             :     SvLBoxButtonData_Impl*  pImpl;
      66             :     bool                    bDataOk;
      67             :     SvButtonState           eState;
      68             :     std::vector<Image>      aBmps;  // indices s. constants BMP_ ....
      69             : 
      70             :     SVT_DLLPRIVATE void     SetWidthAndHeight();
      71             :     SVT_DLLPRIVATE void     InitData( bool bImagesFromDefault,
      72             :                                       bool _bRadioBtn, const Control* pControlForSettings = NULL );
      73             : public:
      74             :                             // include creating default images (CheckBox or RadioButton)
      75             :                             SvLBoxButtonData( const Control* pControlForSettings );
      76             :                             SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn );
      77             : 
      78             :                             ~SvLBoxButtonData();
      79             : 
      80             :     static SvBmp            GetIndex( SvItemStateFlags nItemState );
      81             :     long                    Width();
      82             :     long                    Height();
      83           0 :     void                    SetLink( const Link<>& rLink) { aLink=rLink; }
      84             :     const Link<>&           GetLink() const { return aLink; }
      85             :     bool                    IsRadio();
      86             :     // as buttons are not derived from LinkHdl
      87             :     void                    CallLink();
      88             : 
      89             :     void                    StoreButtonState( SvTreeListEntry* pEntry, SvItemStateFlags nItemFlags );
      90             :     static SvButtonState    ConvertToButtonState( SvItemStateFlags nItemFlags );
      91             : 
      92             :     SvButtonState           GetActButtonState() const { return eState; }
      93             : 
      94             :     SvTreeListEntry*        GetActEntry() const;
      95             : 
      96           0 :     void                    SetImage(SvBmp nIndex, const Image& aImage) { aBmps[(int)nIndex] = aImage; }
      97           0 :     Image&                  GetImage(SvBmp nIndex) { return aBmps[(int)nIndex]; }
      98             : 
      99             :     void                    SetDefaultImages( const Control* pControlForSettings = NULL );
     100             :                                 // set images according to the color scheeme of the Control
     101             :                                 // pControlForSettings == NULL: settings are taken from Application
     102             :     bool                    HasDefaultImages() const;
     103             : };
     104             : 
     105             : // **********************************************************************
     106             : 
     107             : class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem
     108             : {
     109             : protected:
     110             :     OUString maText;
     111             : 
     112             : public:
     113             :     SvLBoxString(SvTreeListEntry*, sal_uInt16 nFlags, const OUString& rText);
     114             :     SvLBoxString();
     115             :     virtual ~SvLBoxString();
     116             : 
     117             :     virtual sal_uInt16 GetType() const SAL_OVERRIDE;
     118             :     virtual void InitViewData(SvTreeListBox* pView,
     119             :                               SvTreeListEntry* pEntry,
     120             :                               SvViewDataItem* pViewData) SAL_OVERRIDE;
     121             : 
     122         142 :     OUString GetText() const
     123             :     {
     124         142 :         return maText;
     125             :     }
     126         202 :     void SetText(const OUString& rText)
     127             :     {
     128         202 :         maText = rText;
     129         202 :     }
     130             : 
     131             :     virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,
     132             :                        vcl::RenderContext& rRenderContext,
     133             :                        const SvViewDataEntry* pView,
     134             :                        const SvTreeListEntry& rEntry) SAL_OVERRIDE;
     135             : 
     136             :     virtual SvLBoxItem* Create() const SAL_OVERRIDE;
     137             :     virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
     138             : };
     139             : 
     140             : class SvLBoxBmp : public SvLBoxItem
     141             : {
     142             :     Image aBmp;
     143             : public:
     144             :     SvLBoxBmp();
     145             :     virtual ~SvLBoxBmp();
     146             :     virtual sal_uInt16 GetType() const SAL_OVERRIDE;
     147             :     virtual void InitViewData( SvTreeListBox*,SvTreeListEntry*,SvViewDataItem* ) SAL_OVERRIDE;
     148             :     virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev,  vcl::RenderContext& rRenderContext,
     149             :                        const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) SAL_OVERRIDE;
     150             :     virtual SvLBoxItem* Create() const SAL_OVERRIDE;
     151             :     virtual void Clone( SvLBoxItem* pSource ) SAL_OVERRIDE;
     152             : };
     153             : 
     154             : 
     155             : class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem
     156             : {
     157             :     bool    isVis;
     158             :     SvLBoxButtonData*   pData;
     159             :     SvLBoxButtonKind eKind;
     160             :     SvItemStateFlags nItemFlags;
     161             : 
     162             :     static void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, vcl::RenderContext& pRenderContext);
     163             : public:
     164             :     // An SvLBoxButton can be of three different kinds: an
     165             :     // enabled checkbox (the normal kind), a disabled checkbox
     166             :     // (which cannot be modified via UI), or a static image
     167             :     // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored
     168             :     // for that kind).
     169             :     SvLBoxButton( SvTreeListEntry* pEntry,
     170             :                   SvLBoxButtonKind eTheKind, sal_uInt16 nFlags,
     171             :                   SvLBoxButtonData* pBData );
     172             :     SvLBoxButton();
     173             :     virtual ~SvLBoxButton();
     174             :     virtual void InitViewData(SvTreeListBox* pView,
     175             :                               SvTreeListEntry* pEntry,
     176             :                               SvViewDataItem* pViewData) SAL_OVERRIDE;
     177             : 
     178             :     virtual sal_uInt16 GetType() const SAL_OVERRIDE;
     179             :     bool ClickHdl(SvTreeListBox* pView, SvTreeListEntry* );
     180             : 
     181             :     virtual void Paint(const Point& rPos,
     182             :                        SvTreeListBox& rOutDev,
     183             :                        vcl::RenderContext& rRenderContext,
     184             :                        const SvViewDataEntry* pView,
     185             :                        const SvTreeListEntry& rEntry) SAL_OVERRIDE;
     186             : 
     187             :     virtual SvLBoxItem* Create() const SAL_OVERRIDE;
     188             : 
     189             :     virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
     190           0 :     SvItemStateFlags GetButtonFlags() const
     191             :     {
     192           0 :         return nItemFlags;
     193             :     }
     194           0 :     bool IsStateChecked() const
     195             :     {
     196           0 :         return bool(nItemFlags & SvItemStateFlags::CHECKED);
     197             :     }
     198           0 :     bool IsStateUnchecked() const
     199             :     {
     200           0 :         return bool(nItemFlags & SvItemStateFlags::UNCHECKED);
     201             :     }
     202           0 :     bool IsStateTristate() const
     203             :     {
     204           0 :         return bool(nItemFlags & SvItemStateFlags::TRISTATE);
     205             :     }
     206           0 :     bool IsStateHilighted() const
     207             :     {
     208           0 :         return bool(nItemFlags & SvItemStateFlags::HILIGHTED);
     209             :     }
     210             :     void SetStateChecked();
     211             :     void SetStateUnchecked();
     212             :     void SetStateTristate();
     213             :     void SetStateHilighted(bool bHilight);
     214             :     void SetStateInvisible();
     215             : 
     216           0 :     SvLBoxButtonKind GetKind() const { return eKind; }
     217             : 
     218             :     // Check whether this button can be modified via UI
     219             :     bool CheckModification() const;
     220             :     SvLBoxButtonData* GetButtonData() const
     221             :     {
     222             :         return pData;
     223             :     }
     224             : };
     225             : 
     226           0 : inline void SvLBoxButton::SetStateChecked()
     227             : {
     228           0 :     nItemFlags &= SvItemStateFlags::HILIGHTED;
     229           0 :     nItemFlags |= SvItemStateFlags::CHECKED;
     230           0 : }
     231             : 
     232           0 : inline void SvLBoxButton::SetStateUnchecked()
     233             : {
     234           0 :     nItemFlags &= SvItemStateFlags::HILIGHTED;
     235           0 :     nItemFlags |= SvItemStateFlags::UNCHECKED;
     236           0 : }
     237           0 : inline void SvLBoxButton::SetStateTristate()
     238             : {
     239           0 :     nItemFlags &= SvItemStateFlags::HILIGHTED;
     240           0 :     nItemFlags |= SvItemStateFlags::TRISTATE;
     241           0 : }
     242           0 : inline void SvLBoxButton::SetStateHilighted( bool bHilight )
     243             : {
     244           0 :     if ( bHilight )
     245           0 :         nItemFlags |= SvItemStateFlags::HILIGHTED;
     246             :     else
     247           0 :         nItemFlags &= ~SvItemStateFlags::HILIGHTED;
     248           0 : }
     249             : 
     250             : struct SvLBoxContextBmp_Impl;
     251             : 
     252             : class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem
     253             : {
     254             :     SvLBoxContextBmp_Impl*  m_pImpl;
     255             : public:
     256             :     SvLBoxContextBmp(SvTreeListEntry* pEntry,
     257             :                      sal_uInt16 nItemFlags,
     258             :                      Image aBmp1,
     259             :                      Image aBmp2,
     260             :                      bool bExpanded);
     261             :     SvLBoxContextBmp();
     262             :     virtual ~SvLBoxContextBmp();
     263             : 
     264             :     virtual sal_uInt16 GetType() const SAL_OVERRIDE;
     265             :     virtual void InitViewData(SvTreeListBox* pView,
     266             :                               SvTreeListEntry* pEntry,
     267             :                               SvViewDataItem* pViewData) SAL_OVERRIDE;
     268             :     virtual void Paint(const Point& rPos,
     269             :                        SvTreeListBox& rOutDev,
     270             :                        vcl::RenderContext& rRenderContext,
     271             :                        const SvViewDataEntry* pView,
     272             :                        const SvTreeListEntry& rEntry) SAL_OVERRIDE;
     273             : 
     274             :     virtual SvLBoxItem* Create() const SAL_OVERRIDE;
     275             :     virtual void Clone(SvLBoxItem* pSource) SAL_OVERRIDE;
     276             : 
     277             : 
     278             :     bool SetModeImages(const Image& rBitmap1, const Image& rBitmap2);
     279             :     void  GetModeImages(Image& rBitmap1, Image& rBitmap2) const;
     280             : 
     281             :     inline void SetBitmap1(const Image& rImage);
     282             :     inline void SetBitmap2(const Image& rImage);
     283             :     inline const Image& GetBitmap1() const;
     284             :     inline const Image& GetBitmap2() const;
     285             : 
     286             : private:
     287             :     Image& implGetImageStore(bool bFirst);
     288             : };
     289             : 
     290           1 : inline void SvLBoxContextBmp::SetBitmap1(const Image& _rImage)
     291             : {
     292           1 :     implGetImageStore(true) = _rImage;
     293           1 : }
     294             : 
     295           1 : inline void SvLBoxContextBmp::SetBitmap2(const Image& _rImage)
     296             : {
     297           1 :     implGetImageStore(false) = _rImage;
     298           1 : }
     299             : 
     300         202 : inline const Image& SvLBoxContextBmp::GetBitmap1() const
     301             : {
     302         202 :     Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(true);
     303         202 :     return rImage;
     304             : }
     305             : 
     306         202 : inline const Image& SvLBoxContextBmp::GetBitmap2() const
     307             : {
     308         202 :     Image& rImage = const_cast<SvLBoxContextBmp*>(this)->implGetImageStore(false);
     309         202 :     return rImage;
     310             : }
     311             : 
     312             : #endif
     313             : 
     314             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11