LCOV - code coverage report
Current view: top level - include/svtools - ctrlbox.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 56 3.6 %
Date: 2015-06-13 12:38:46 Functions: 2 27 7.4 %
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             : #ifndef INCLUDED_SVTOOLS_CTRLBOX_HXX
      21             : #define INCLUDED_SVTOOLS_CTRLBOX_HXX
      22             : 
      23             : #include <svtools/svtdllapi.h>
      24             : 
      25             : #include <vcl/lstbox.hxx>
      26             : #include <vcl/combobox.hxx>
      27             : #include <vcl/image.hxx>
      28             : #include <vcl/virdev.hxx>
      29             : #include <vcl/metric.hxx>
      30             : #include <vcl/field.hxx>
      31             : 
      32             : #include <com/sun/star/table/BorderLineStyle.hpp>
      33             : #include <o3tl/typed_flags_set.hxx>
      34             : 
      35             : class FontList;
      36             : class ImplColorListData;
      37             : class ImpLineListData;
      38             : 
      39             : typedef ::std::vector< ImplColorListData*    > ImpColorList;
      40             : typedef ::std::vector< ImpLineListData*      > ImpLineList;
      41             : typedef ::std::vector< vcl::FontInfo         > ImplFontList;
      42             : 
      43             : /*************************************************************************
      44             : 
      45             : Description
      46             : ============
      47             : 
      48             : class ColorListBox
      49             : 
      50             : Description
      51             : 
      52             : Allows color selection
      53             : 
      54             : --------------------------------------------------------------------------
      55             : 
      56             : class LineListBox
      57             : 
      58             : Description
      59             : 
      60             : Allows selection of line styles and sizes. Not that before first insert,
      61             : units and window size need to be set. Supported units are typographic point
      62             : (pt) and millimeters (mm). For SourceUnit, pt, mm and twips are supported.
      63             : All scalar numbers in 1/100 of the corresponding unit.
      64             : 
      65             : Line1 is the outer, Line2 the inner line, Distance is the distance between
      66             : these two lines. If Line2 == 0, only Line1 will be shown. Defaults for
      67             : source and target unit are FUNIT_POINT.
      68             : 
      69             : SetColor() sets the line color.
      70             : 
      71             : Remarks
      72             : 
      73             : Contrary to a simple ListBox, user-specific data are not supported.
      74             : If UpdateMode is disabled, no data should be read, no selections
      75             : should be set, and the return code shall be ignore, as in these are
      76             : not defined in this mode. Also the bit WinBit WB_SORT may not be set.
      77             : 
      78             : --------------------------------------------------------------------------
      79             : 
      80             : class FontNameBox
      81             : 
      82             : Description
      83             : 
      84             : Allows selection of fonts. The ListBox will be filled using Fill parameter,
      85             : which is pointer to an FontList object.
      86             : 
      87             : Calling EnableWYSIWYG() enables rendering the font name in the currently
      88             : selected font.
      89             : 
      90             : See also
      91             : 
      92             : FontList; FontStyleBox; FontSizeBox; FontNameMenu
      93             : 
      94             : --------------------------------------------------------------------------
      95             : 
      96             : class FontStyleBox
      97             : 
      98             : Description
      99             : 
     100             : Allows select of FontStyle's. The parameter Fill points to a list
     101             : of available font styles for the font.
     102             : 
     103             : Reproduced styles are always added - this could change in future, as
     104             : potentially not all applications [Draw,Equation,FontWork] can properly
     105             : handle synthetic fonts. On filling, the previous name will be retained
     106             : if possible.
     107             : 
     108             : For DontKnow, the FontStyleBox should be filled with OUString(),
     109             : so it will contain a list with the default attributes. The currently
     110             : shown style probably needs to be reset by the application.
     111             : 
     112             : See also
     113             : 
     114             : FontList; FontNameBox; FontSizeBox;
     115             : 
     116             : --------------------------------------------------------------------------
     117             : 
     118             : class FontSizeBox
     119             : 
     120             : Description
     121             : 
     122             : Allows selection of font sizes. The values are retrieved via GetValue()
     123             : and set via SetValue(). The Fill parameter fills the ListBox with the
     124             : available sizes for the passed font.
     125             : 
     126             : All sizes are in 1/10 typographic point (pt).
     127             : 
     128             : The passed FontList must be retained until the next fill call.
     129             : 
     130             : Additionally it supports an relative mod, which allows entering
     131             : percentage values. This, eg., can be useful for template dialogs.
     132             : This mode can only be enabled, but not disabled again.
     133             : 
     134             : For DontKnow the FontSizeBox should be filled FontInfo(), so it will
     135             : contain an list with the standard sizes. Th currently shown size
     136             : probably needs to be reset by the application.
     137             : 
     138             : See also
     139             : 
     140             : FontList; FontNameBox; FontStyleBox; FontSizeMenu
     141             : 
     142             : *************************************************************************/
     143             : 
     144             : class SVT_DLLPUBLIC ColorListBox : public ListBox
     145             : {
     146             :     ImpColorList*   pColorList; // separate liste, in case of user data are required from outside
     147             :     Size            aImageSize;
     148             : 
     149             :     using Window::ImplInit;
     150             :     SVT_DLLPRIVATE void         ImplInit();
     151             :     SVT_DLLPRIVATE void         ImplDestroyColorEntries();
     152             : 
     153             : public:
     154             :                     ColorListBox( vcl::Window* pParent,
     155             :                                   WinBits nWinStyle = WB_BORDER );
     156             :                     ColorListBox( vcl::Window* pParent, const ResId& rResId );
     157             :     virtual         ~ColorListBox();
     158             :     virtual void    dispose() SAL_OVERRIDE;
     159             : 
     160             :     virtual void    UserDraw( const UserDrawEvent& rUDEvt ) SAL_OVERRIDE;
     161             : 
     162             :     using ListBox::InsertEntry;
     163             :     sal_Int32   InsertEntry( const OUString& rStr,
     164             :                                  sal_Int32  nPos = LISTBOX_APPEND );
     165             :     sal_Int32   InsertEntry( const Color& rColor, const OUString& rStr,
     166             :                                  sal_Int32  nPos = LISTBOX_APPEND );
     167             :     void            InsertAutomaticEntryColor(const Color &rAutoColorValue);
     168           0 :     bool            IsAutomaticSelected() { return !GetSelectEntryPos(); }
     169             :     using ListBox::RemoveEntry;
     170             :     void    RemoveEntry( sal_Int32  nPos );
     171             :     void    Clear();
     172             :     void            CopyEntries( const ColorListBox& rBox );
     173             : 
     174             :     using ListBox::GetEntryPos;
     175             :     sal_Int32   GetEntryPos( const Color& rColor ) const;
     176             :     Color   GetEntryColor( sal_Int32  nPos ) const;
     177             :     Size            GetImageSize() const { return aImageSize; }
     178             : 
     179           0 :     void            SelectEntry( const OUString& rStr, bool bSelect = true )
     180           0 :                         { ListBox::SelectEntry( rStr, bSelect ); }
     181             :     void            SelectEntry( const Color& rColor, bool bSelect = true );
     182             :     Color           GetSelectEntryColor( sal_Int32  nSelIndex = 0 ) const;
     183           0 :     bool            IsEntrySelected(const OUString& rStr ) const
     184             :     {
     185           0 :         return ListBox::IsEntrySelected(rStr);
     186             :     }
     187             : 
     188           0 :     bool            IsEntrySelected(const Color& rColor) const
     189             :     {
     190           0 :         sal_Int32  nPos = GetEntryPos( rColor );
     191           0 :         if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     192           0 :             return IsEntryPosSelected( nPos );
     193             :         else
     194           0 :             return false;
     195             :     }
     196             : 
     197             : private:
     198             :                     ColorListBox( const ColorListBox& ) SAL_DELETED_FUNCTION;
     199             :     ColorListBox&   operator =( const ColorListBox& ) SAL_DELETED_FUNCTION;
     200             : 
     201             :     void            SetEntryData( sal_Int32  nPos, void* pNewData );
     202             :     void*           GetEntryData( sal_Int32  nPos ) const;
     203             : };
     204             : 
     205           0 : inline void ColorListBox::SelectEntry( const Color& rColor, bool bSelect )
     206             : {
     207           0 :     sal_Int32  nPos = GetEntryPos( rColor );
     208           0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     209           0 :         ListBox::SelectEntryPos( nPos, bSelect );
     210           0 : }
     211             : 
     212           0 : inline Color ColorListBox::GetSelectEntryColor( sal_Int32  nSelIndex ) const
     213             : {
     214           0 :     sal_Int32  nPos = GetSelectEntryPos( nSelIndex );
     215           0 :     Color aColor;
     216           0 :     if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     217           0 :         aColor = GetEntryColor( nPos );
     218           0 :     return aColor;
     219             : }
     220             : 
     221             : /**
     222             :     Class computing border widths shared between Line style listbox and the
     223             :     SvxBorderLine implementation.
     224             : 
     225             :     This class doesn't know anything about units: it all depends on the different
     226             :     values set. A border is composed of 2 lines separated by a gap. The computed
     227             :     widths are the ones of each line and the gap and they can either be fix or vary.
     228             : 
     229             :     The #m_nflags member will define which widths will vary (value 0 means that all
     230             :     widths are fixed). The available flags are:
     231             :      - CHANGE_LINE1
     232             :      - CHANGE_LINE2
     233             :      - CHANGE_DIST
     234             : 
     235             :     For each line, the rate member is used as a multiplication factor is the width
     236             :     isn't fixed. Otherwise it is the width in the unit expected by the client code.
     237             :  */
     238             : enum class BorderWidthImplFlags
     239             : {
     240             :     FIXED           = 0,
     241             :     CHANGE_LINE1    = 1,
     242             :     CHANGE_LINE2    = 2,
     243             :     CHANGE_DIST     = 4,
     244             :     ADAPT_DIST      = 8,
     245             : };
     246             : namespace o3tl
     247             : {
     248             :     template<> struct typed_flags<BorderWidthImplFlags> : is_typed_flags<BorderWidthImplFlags, 0x0f> {};
     249             : }
     250             : class SVT_DLLPUBLIC BorderWidthImpl
     251             : {
     252             :     BorderWidthImplFlags m_nFlags;
     253             :     double m_nRate1;
     254             :     double m_nRate2;
     255             :     double m_nRateGap;
     256             : 
     257             : public:
     258             : 
     259             :     BorderWidthImpl( BorderWidthImplFlags nFlags = BorderWidthImplFlags::CHANGE_LINE1, double nRate1 = 0.0,
     260             :             double nRate2 = 0.0, double nRateGap = 0.0 );
     261             : 
     262             :     BorderWidthImpl& operator= ( const BorderWidthImpl& r );
     263             :     bool operator== ( const BorderWidthImpl& r ) const;
     264             : 
     265             :     long GetLine1 ( long nWidth ) const;
     266             :     long GetLine2( long nWidth ) const;
     267             :     long GetGap( long nWidth ) const;
     268             : 
     269             :     long GuessWidth( long nLine1, long nLine2, long nGap );
     270             : 
     271       63437 :     bool IsEmpty( ) const { return (0 == m_nRate1) && (0 == m_nRate2); }
     272     3057756 :     bool IsDouble( ) const { return (0 != m_nRate1) && (0 != m_nRate2);  }
     273             : };
     274             : 
     275           0 : inline Color sameColor( Color rMain )
     276             : {
     277           0 :     return rMain;
     278             : }
     279             : 
     280           0 : inline Color sameDistColor( Color /*rMain*/, Color rDefault )
     281             : {
     282           0 :     return rDefault;
     283             : }
     284             : 
     285             : class SVT_DLLPUBLIC LineListBox : public ListBox
     286             : {
     287             :     ImpLineList*    pLineList;
     288             :     long            m_nWidth;
     289             :     OUString        m_sNone;
     290             : 
     291             :     ScopedVclPtr<VirtualDevice>   aVirDev;
     292             :     Size            aTxtSize;
     293             :     Color           aColor;
     294             :     Color           maPaintCol;
     295             :     FieldUnit       eUnit;
     296             :     FieldUnit       eSourceUnit;
     297             : 
     298             :     SVT_DLLPRIVATE void         ImpGetLine( long nLine1, long nLine2, long nDistance,
     299             :                                     Color nColor1, Color nColor2, Color nColorDist,
     300             :                                     sal_uInt16 nStyle, Bitmap& rBmp );
     301             :     using Window::ImplInit;
     302             :     SVT_DLLPRIVATE void         ImplInit();
     303             :     bool            UpdatePaintLineColor();       // returns sal_True if maPaintCol has changed
     304             :     virtual void    DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
     305             : 
     306             :     void            UpdateEntries( long nOldWidth );
     307             :     sal_Int32       GetStylePos( sal_Int32  nListPos, long nWidth );
     308             : 
     309             : public:
     310             :     typedef Color (*ColorFunc)(Color);
     311             :     typedef Color (*ColorDistFunc)(Color, Color);
     312             : 
     313             :                     LineListBox( vcl::Window* pParent, WinBits nWinStyle = WB_BORDER );
     314             :     virtual         ~LineListBox();
     315             :     virtual void    dispose() SAL_OVERRIDE;
     316             : 
     317             :     /** Set the width in Twips */
     318             :     void            SetWidth( long nWidth );
     319           0 :     long            GetWidth() const { return m_nWidth; }
     320             :     void            SetNone( const OUString& sNone );
     321             : 
     322             :     using ListBox::InsertEntry;
     323             :     /** Insert a listbox entry with all widths in Twips. */
     324             :     void            InsertEntry(const BorderWidthImpl& rWidthImpl,
     325             :                         sal_uInt16 nStyle, long nMinWidth = 0,
     326             :                         ColorFunc pColor1Fn = &sameColor,
     327             :                         ColorFunc pColor2Fn = &sameColor,
     328             :                         ColorDistFunc pColorDistFn = &sameDistColor);
     329             : 
     330             :     using ListBox::GetEntryPos;
     331             :     sal_Int32  GetEntryPos( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID ) const;
     332             :     sal_uInt16          GetEntryStyle( sal_Int32  nPos ) const;
     333             : 
     334             :     void            SelectEntry( const OUString& rStr, bool bSelect = true ) { ListBox::SelectEntry( rStr, bSelect ); }
     335             :     void SelectEntry( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID, bool bSelect = true );
     336             :     sal_uInt16          GetSelectEntryStyle( sal_Int32  nSelIndex = 0 ) const;
     337             :     bool            IsEntrySelected(const OUString& rStr) const
     338             :     {
     339             :         return ListBox::IsEntrySelected(rStr);
     340             :     }
     341             :     bool IsEntrySelected( sal_uInt16 nStyle = com::sun::star::table::BorderLineStyle::SOLID ) const
     342             :     {
     343             :         sal_Int32  nPos = GetEntryPos( nStyle );
     344             :         if ( nPos != LISTBOX_ENTRY_NOTFOUND )
     345             :             return IsEntryPosSelected( nPos );
     346             :         else
     347             :             return false;
     348             :     }
     349             : 
     350           0 :     inline void     SetUnit( FieldUnit eNewUnit ) { eUnit = eNewUnit; }
     351             :     inline FieldUnit    GetUnit() const { return eUnit; }
     352           0 :     inline void     SetSourceUnit( FieldUnit eNewUnit ) { eSourceUnit = eNewUnit; }
     353             :     inline FieldUnit    GetSourceUnit() const { return eSourceUnit; }
     354             : 
     355             :     void            SetColor( const Color& rColor );
     356           0 :     Color           GetColor() const { return aColor; }
     357             : 
     358             : protected:
     359             : 
     360             :     inline const Color&    GetPaintColor() const;
     361             :     Color   GetColorLine1( sal_Int32  nPos = 0 );
     362             :     Color   GetColorLine2( sal_Int32  nPos = 0 );
     363             :     Color   GetColorDist( sal_Int32  nPos = 0 );
     364             : 
     365             : private:
     366             :                     LineListBox( const LineListBox& ) SAL_DELETED_FUNCTION;
     367             :     LineListBox&    operator =( const LineListBox& ) SAL_DELETED_FUNCTION;
     368             :     void            SetEntryData( sal_Int32  nPos, void* pNewData );
     369             :     void*           GetEntryData( sal_Int32  nPos ) const;
     370             : };
     371             : 
     372           0 : inline void LineListBox::SetColor( const Color& rColor )
     373             : {
     374           0 :     aColor = rColor;
     375             : 
     376           0 :     UpdateEntries( m_nWidth );
     377           0 : }
     378             : 
     379           0 : const Color& LineListBox::GetPaintColor() const
     380             : {
     381           0 :     return maPaintCol;
     382             : }
     383             : 
     384           0 : inline void LineListBox::SetWidth( long nWidth )
     385             : {
     386           0 :     long nOldWidth = m_nWidth;
     387           0 :     m_nWidth = nWidth;
     388           0 :     UpdateEntries( nOldWidth );
     389           0 : }
     390             : 
     391           0 : inline void LineListBox::SetNone( const OUString& sNone )
     392             : {
     393           0 :     m_sNone = sNone;
     394           0 : }
     395             : 
     396             : class SVT_DLLPUBLIC FontNameBox : public ComboBox
     397             : {
     398             : private:
     399             :     ImplFontList*   mpFontList;
     400             :     bool            mbWYSIWYG;
     401             :     OUString        maFontMRUEntriesFile;
     402             : 
     403             :     SVT_DLLPRIVATE void         ImplCalcUserItemSize();
     404             :     SVT_DLLPRIVATE void         ImplDestroyFontList();
     405             : 
     406             : protected:
     407             :     void            LoadMRUEntries( const OUString& aFontMRUEntriesFile, sal_Unicode cSep = ';' );
     408             :     void            SaveMRUEntries( const OUString& aFontMRUEntriesFile, sal_Unicode cSep = ';' ) const;
     409             : public:
     410             :                     FontNameBox( vcl::Window* pParent,
     411             :                                  WinBits nWinStyle = WB_SORT );
     412             :     virtual         ~FontNameBox();
     413             :     virtual void    dispose() SAL_OVERRIDE;
     414             : 
     415             :     virtual void    UserDraw( const UserDrawEvent& rUDEvt ) SAL_OVERRIDE;
     416             : 
     417             :     void            Fill( const FontList* pList );
     418             : 
     419             :     void            EnableWYSIWYG( bool bEnable = true );
     420             :     bool            IsWYSIWYGEnabled() const { return mbWYSIWYG; }
     421             : 
     422             : private:
     423             :     void            InitFontMRUEntriesFile();
     424             : 
     425             :                     FontNameBox( const FontNameBox& ) SAL_DELETED_FUNCTION;
     426             :     FontNameBox&    operator =( const FontNameBox& ) SAL_DELETED_FUNCTION;
     427             : };
     428             : 
     429           0 : class SVT_DLLPUBLIC FontStyleBox : public ComboBox
     430             : {
     431             :     OUString        aLastStyle;
     432             : 
     433             :     Size            aOptimalSize;
     434             : 
     435             : private:
     436             :     using ComboBox::SetText;
     437             : public:
     438             :     FontStyleBox( vcl::Window* pParent, WinBits nBits );
     439             : 
     440             :     virtual void    Select() SAL_OVERRIDE;
     441             :     virtual void    LoseFocus() SAL_OVERRIDE;
     442             :     virtual void    Modify() SAL_OVERRIDE;
     443             :     virtual Size    GetOptimalSize() const SAL_OVERRIDE;
     444             : 
     445             :     void            SetText( const OUString& rText ) SAL_OVERRIDE;
     446             :     void            Fill( const OUString& rName, const FontList* pList );
     447             : 
     448             : private:
     449             :                     FontStyleBox( const FontStyleBox& ) SAL_DELETED_FUNCTION;
     450             :     FontStyleBox&   operator =( const FontStyleBox& ) SAL_DELETED_FUNCTION;
     451             : };
     452             : 
     453           0 : inline void FontStyleBox::SetText( const OUString& rText )
     454             : {
     455           0 :     aLastStyle = rText;
     456           0 :     ComboBox::SetText( rText );
     457           0 : }
     458             : 
     459           0 : class SVT_DLLPUBLIC FontSizeBox : public MetricBox
     460             : {
     461             :     vcl::FontInfo       aFontInfo;
     462             :     const FontList* pFontList;
     463             :     sal_uInt16          nRelMin;
     464             :     sal_uInt16          nRelMax;
     465             :     sal_uInt16          nRelStep;
     466             :     short           nPtRelMin;
     467             :     short           nPtRelMax;
     468             :     short           nPtRelStep;
     469             :     bool            bRelativeMode:1,
     470             :                     bRelative:1,
     471             :                     bPtRelative:1,
     472             :                     bStdSize:1;
     473             : 
     474             :     using Window::ImplInit;
     475             :     SVT_DLLPRIVATE void         ImplInit();
     476             : 
     477             : protected:
     478             :     virtual OUString CreateFieldText( sal_Int64 nValue ) const SAL_OVERRIDE;
     479             : 
     480             : public:
     481             :                     FontSizeBox( vcl::Window* pParent, WinBits nWinStyle = 0 );
     482             : 
     483             :     void            Reformat() SAL_OVERRIDE;
     484             :     void            Modify() SAL_OVERRIDE;
     485             : 
     486             :     void            Fill( const vcl::FontInfo* pInfo, const FontList* pList );
     487             : 
     488             :     void            EnableRelativeMode( sal_uInt16 nMin = 50, sal_uInt16 nMax = 150,
     489             :                                         sal_uInt16 nStep = 5 );
     490             :     void            EnablePtRelativeMode( short nMin = -200, short nMax = 200,
     491             :                                           short nStep = 10 );
     492           0 :     bool            IsRelativeMode() const { return bRelativeMode; }
     493             :     void            SetRelative( bool bRelative = false );
     494           0 :     bool            IsRelative() const { return bRelative; }
     495           0 :     void            SetPtRelative( bool bPtRel = true )
     496           0 :                         { bPtRelative = bPtRel; SetRelative( true ); }
     497           0 :     bool            IsPtRelative() const { return bPtRelative; }
     498             : 
     499             :     virtual void    SetValue( sal_Int64 nNewValue, FieldUnit eInUnit ) SAL_OVERRIDE;
     500             :     virtual void    SetValue( sal_Int64 nNewValue  ) SAL_OVERRIDE;
     501             :     virtual sal_Int64   GetValue( FieldUnit eOutUnit ) const SAL_OVERRIDE;
     502             :     virtual sal_Int64   GetValue() const SAL_OVERRIDE;
     503             : 
     504             : private:
     505             :                     FontSizeBox( const FontSizeBox& ) SAL_DELETED_FUNCTION;
     506             :     FontSizeBox&    operator =( const FontSizeBox& ) SAL_DELETED_FUNCTION;
     507             : };
     508             : 
     509             : #endif // INCLUDED_SVTOOLS_CTRLBOX_HXX
     510             : 
     511             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11