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

Generated by: LCOV version 1.10