LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/svtools - valueset.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 10 0.0 %
Date: 2012-12-27 Functions: 0 9 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             :  * 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 _VALUESET_HXX
      21             : #define _VALUESET_HXX
      22             : 
      23             : #include "svtools/svtdllapi.h"
      24             : 
      25             : #include <vcl/ctrl.hxx>
      26             : #include <vcl/virdev.hxx>
      27             : #include <vcl/timer.hxx>
      28             : #include <vector>
      29             : 
      30             : class MouseEvent;
      31             : class TrackingEvent;
      32             : class HelpEvent;
      33             : class KeyEvent;
      34             : class DataChangedEvent;
      35             : class ScrollBar;
      36             : 
      37             : struct ValueSetItem;
      38             : typedef ::std::vector< ValueSetItem* > ValueItemList;
      39             : 
      40             : #ifdef _SV_VALUESET_CXX
      41             : class ValueSetAcc;
      42             : class ValueItemAcc;
      43             : #endif
      44             : 
      45             : /*************************************************************************
      46             : 
      47             : Description
      48             : ============
      49             : 
      50             : class ValueSet
      51             : 
      52             : This class allows the selection of an item. In the process items are
      53             : drawn side by side. The selection of items can be more clear than in a
      54             : ListBox shape for example in case of colors or samples.
      55             : The amount of columns drawn by the control and whether the items
      56             : should be encircled can be specified. Optional a NoSelection or name
      57             : field could be shown. By default image and color items are supported.
      58             : Items could be drawn by oneself if InsertItem() is only called with
      59             : an ID. To achieve this the UserDraw handler needs to be overloaded. The
      60             : description text could be specified afterwards in case of UserDraw
      61             : and any other items.
      62             : 
      63             : Cross references
      64             : 
      65             : class ListBox
      66             : 
      67             : --------------------------------------------------------------------------
      68             : 
      69             : WinBits
      70             : 
      71             : WB_RADIOSEL         If set the selection will be drawn like an
      72             :                     ImageRadioButton. This does only make sense if the image
      73             :                     is at least 8 pixel smaller on each side than the item
      74             :                     and also WB_DOUBLEBORDER is set and as color
      75             :                     COL_WINDOWWORKSPACE is specified.
      76             : WB_FLATVALUESET     Flat Look (if you set WB_ITEMBORDER or WB_DOUBLEBORDER,
      77             :                     then you get extra border space, but the Borders
      78             :                     aren't painted),
      79             : WB_ITEMBORDER       Items will be bordered
      80             : WB_DOUBLEBORDER     Items will be bordered twice. Additionally WB_ITEMBORDER
      81             :                     has to be set, as otherwise this WinBit wouldn't have any
      82             :                     effect. It is needed if there are items with a white
      83             :                     background, since otherwise the 3D effect wouldn't be
      84             :                     recognizable.
      85             : WB_NAMEFIELD        There is a namefield, where the name of an item will be
      86             :                     shown.
      87             : WB_NONEFIELD        There is a NoSelection field which can be selected if
      88             :                     0 is passed along with SelectItem. Respectively
      89             :                     GetSelectItemId() returns 0 if this field or nothing
      90             :                     is selected. This field shows the text which is specified
      91             :                     by SetText() respectively no one, if no text was set. With
      92             :                     SetNoSelection() the selection can be disabled.
      93             : WB_VSCROLL          A scroolbar will be always shown. The visible number of
      94             :                     lines have to be specified with SetLineCount() if this
      95             :                     flag is set.
      96             : WB_BORDER           A border will be drawn around the window.
      97             : WB_NOPOINTERFOCUS   The focus won't be gathered, if the control was pressed by
      98             :                     the mouse.
      99             : WB_TABSTOP          It is possible to jump into the ValueSet with the tab key.
     100             : WB_NOTABSTOP        It is not possible to jump into the ValueSet with the
     101             :                     tab key.
     102             : WB_NO_DIRECTSELECT  Cursor travelling doesn't call select immediately. To
     103             :                     execute the selection <RETURN> has to be pressed.
     104             : --------------------------------------------------------------------------
     105             : 
     106             : The number of columns must be either set with SetColCount() or
     107             : SetItemWidth(). If the number of colums is specified by SetColCount()
     108             : the width of the items will be calculated by the visible range.
     109             : If the items should have a static width, it has to be specified
     110             : with SetItemWidth(). In this case the number of columns will be calculated
     111             : by the visible range.
     112             : 
     113             : The number of rows is given by the number of items / number of columns. The
     114             : number of visible rows must either specified by SetLineCount() or
     115             : SetItemWidth(). If the number of visible rows is specified by SetLineCount(),
     116             : the height of the items will be calculated from the visible height. If the
     117             : items should have a fixed height it has to be specified with SetItemHeight().
     118             : In this case the number of visible rows is then calculated from the visible
     119             : height. If the number of visible rows is neither specified by SetLineCount()
     120             : nor by SetItemHeight() all rows will be shown. The height of the items will
     121             : be calculated by the visible height. If the number of visible rows is
     122             : specified by SetLineCount() or SetItemHeight() ValueSet does scroll
     123             : automatically when more lines are available, as are visible. If scrolling
     124             : should be also possible with a ScrollBar  WB_VSCROLL needs to be set.
     125             : 
     126             : The distance between the items can be increased by SetExtraSpacing(). The
     127             : distance, which will be shown between two items (both in x and in y), is
     128             : measured in pixels.
     129             : 
     130             : The exact window size for a specific item size can be calculated by
     131             : CalcWindowSizePixel(). To do this all relevant data (number of columns/...)
     132             : have to be specified and if no number of rows was set, all items need to
     133             : be inserted. If the window was created with WB_BORDER/Border=sal_True the
     134             : size has to be specified with SetOutputSizePixel(). In other cases different
     135             : size-methods can be used. With CalcItemSize() the inner and outer size of
     136             : an item could be calculated (for this the free space defined by
     137             : SetExtraSpacing() will not be included).
     138             : 
     139             : The background color could be specified by SetColor(), with which the image
     140             : or UserDraw items will be underlayed. If no color is specified the the color
     141             : of other windows (WindowColor) will be used for the background.
     142             : 
     143             : --------------------------------------------------------------------------
     144             : 
     145             : At first all items should be inserted and only then Show() should be called
     146             : since the output area will be precomputed. If this is not done the first
     147             : Paint will appear a little bit slower. Therefore the Control, if it is loaded
     148             : from the resource and only supplied with items during runtime, should be
     149             : loaded with Hide = sal_True and then displayed with Show().
     150             : 
     151             : In case of a visible Control the creation of the new output area could be
     152             : activated before Paint by calling Format().
     153             : 
     154             : --------------------------------------------------------------------------
     155             : 
     156             : If Drag and Drop will be called from the ValueSet the Command-Handler has to
     157             : be overloaded. From this StartDrag needs to be called. If this method returns
     158             : sal_True the drag-process could be initiated by  ExecuteDrag(), otherwise no
     159             : processing will take place. This method makes sure that ValueSet stops its
     160             : processing and as appropriate selects the entry. Therefore the calling of
     161             : Select-Handler within this function must be expected.
     162             : 
     163             : For dropping QueryDrop() and Drop() need to be overloaded and ShowDropPos()
     164             : and HideDropPos() should be called within these methods.
     165             : To show the insertion point ShowDropPos() has to be called within the
     166             : QueryDrop-Handler. ShowDropPos() also scrolls the ValueSet if the passed
     167             : position is located at the window border. Furthermore ShowDropPos() returns
     168             : the position, at which the item should be inserted respectively which
     169             : insertion point was shown. If no insertion point was determined
     170             : VALUESET_ITEM_NOTFOUND will be returned. If the window was left during dragging
     171             : or the drag process is terminated HideDropPos() should be called in any case.
     172             : 
     173             : --------------------------------------------------------------------------
     174             : 
     175             : This class is currently still in the SV-Tools. That's why the ValueSet needs
     176             : to be loaded as a Control out of the resource and the desired WinBits have
     177             : to be set (before Show) with SetStyle().
     178             : 
     179             : *************************************************************************/
     180             : 
     181             : // ------------------
     182             : // - ValueSet types -
     183             : // ------------------
     184             : 
     185             : #define WB_RADIOSEL             ((WinBits)0x00008000)
     186             : #define WB_ITEMBORDER           ((WinBits)0x00010000)
     187             : #define WB_DOUBLEBORDER         ((WinBits)0x00020000)
     188             : #define WB_NAMEFIELD            ((WinBits)0x00040000)
     189             : #define WB_NONEFIELD            ((WinBits)0x00080000)
     190             : #define WB_FLATVALUESET         ((WinBits)0x02000000)
     191             : #define WB_NO_DIRECTSELECT      ((WinBits)0x04000000)
     192             : #define WB_MENUSTYLEVALUESET    ((WinBits)0x08000000)
     193             : 
     194             : // ------------
     195             : // - ValueSet -
     196             : // ------------
     197             : 
     198             : #define VALUESET_APPEND         ((sal_uInt16)-1)
     199             : #define VALUESET_ITEM_NOTFOUND  ((sal_uInt16)-1)
     200             : 
     201             : class SVT_DLLPUBLIC ValueSet : public Control
     202             : {
     203             : private:
     204             : 
     205             :     VirtualDevice   maVirDev;
     206             :     Timer           maTimer;
     207             :     ValueItemList   mItemList;
     208             :     ValueSetItem*   mpNoneItem;
     209             :     ScrollBar*      mpScrBar;
     210             :     Rectangle       maNoneItemRect;
     211             :     Rectangle       maItemListRect;
     212             :     long            mnItemWidth;
     213             :     long            mnItemHeight;
     214             :     long            mnTextOffset;
     215             :     long            mnVisLines;
     216             :     long            mnLines;
     217             :     long            mnUserItemWidth;
     218             :     long            mnUserItemHeight;
     219             :     sal_uInt16          mnSelItemId;
     220             :     sal_uInt16          mnHighItemId;
     221             :     sal_uInt16          mnCols;
     222             :     sal_uInt16          mnCurCol;
     223             :     sal_uInt16          mnUserCols;
     224             :     sal_uInt16          mnUserVisLines;
     225             :     sal_uInt16          mnFirstLine;
     226             :     sal_uInt16          mnSpacing;
     227             :     sal_uInt16          mnFrameStyle;
     228             :     bool            mbFormat : 1;
     229             :     bool            mbHighlight : 1;
     230             :     bool            mbSelection : 1;
     231             :     bool            mbNoSelection : 1;
     232             :     bool            mbDrawSelection : 1;
     233             :     bool            mbBlackSel : 1;
     234             :     bool            mbDoubleSel : 1;
     235             :     bool            mbScroll : 1;
     236             :     bool            mbFullMode : 1;
     237             :     bool            mbIsTransientChildrenDisabled : 1;
     238             :     bool            mbHasVisibleItems : 1;
     239             :     Color           maColor;
     240             :     Link            maDoubleClickHdl;
     241             :     Link            maSelectHdl;
     242             :     Link            maHighlightHdl;
     243             : 
     244             : #ifdef _SV_VALUESET_CXX
     245             :     friend class ValueSetAcc;
     246             :     friend class ValueItemAcc;
     247             :     using Control::ImplInitSettings;
     248             :     using Window::ImplInit;
     249             :     SVT_DLLPRIVATE void         ImplInit();
     250             :     SVT_DLLPRIVATE void         ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
     251             :     SVT_DLLPRIVATE void         ImplInitScrollBar();
     252             :     SVT_DLLPRIVATE void         ImplDeleteItems();
     253             :     SVT_DLLPRIVATE void         ImplFormatItem( ValueSetItem* pItem, Rectangle aRect );
     254             :     SVT_DLLPRIVATE void         ImplDrawItemText( const XubString& rStr );
     255             :     SVT_DLLPRIVATE void         ImplDrawSelect( sal_uInt16 nItemId, const bool bFocus, const bool bDrawSel );
     256             :     SVT_DLLPRIVATE void         ImplDrawSelect();
     257             :     SVT_DLLPRIVATE void         ImplHideSelect( sal_uInt16 nItemId );
     258             :     SVT_DLLPRIVATE void         ImplHighlightItem( sal_uInt16 nItemId, bool bIsSelection = true );
     259             :     SVT_DLLPRIVATE void         ImplDraw();
     260             :     using Window::ImplScroll;
     261             :     SVT_DLLPRIVATE bool         ImplScroll( const Point& rPos );
     262             :     SVT_DLLPRIVATE size_t       ImplGetItem( const Point& rPoint, bool bMove = false ) const;
     263             :     SVT_DLLPRIVATE ValueSetItem*    ImplGetItem( size_t nPos );
     264             :     SVT_DLLPRIVATE ValueSetItem*    ImplGetFirstItem();
     265             :     SVT_DLLPRIVATE sal_uInt16          ImplGetVisibleItemCount() const;
     266             :     SVT_DLLPRIVATE ValueSetItem*    ImplGetVisibleItem( sal_uInt16 nVisiblePos );
     267             :     SVT_DLLPRIVATE void         ImplInsertItem( ValueSetItem *const pItem, const size_t nPos );
     268             :     SVT_DLLPRIVATE Rectangle    ImplGetItemRect( size_t nPos ) const;
     269             :     SVT_DLLPRIVATE void            ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
     270             :     SVT_DLLPRIVATE bool         ImplHasAccessibleListeners();
     271             :     SVT_DLLPRIVATE void         ImplTracking( const Point& rPos, bool bRepeat );
     272             :     SVT_DLLPRIVATE void         ImplEndTracking( const Point& rPos, bool bCancel );
     273             :     DECL_DLLPRIVATE_LINK( ImplScrollHdl, ScrollBar* );
     274             :     DECL_DLLPRIVATE_LINK( ImplTimerHdl, void* );
     275             : #endif
     276             : 
     277             :     // Forbidden and not implemented.
     278             :     ValueSet (const ValueSet &);
     279             :     ValueSet & operator= (const ValueSet &);
     280             : 
     281             : protected:
     282             : 
     283             :     bool            StartDrag( const CommandEvent& rCEvt, Region& rRegion );
     284             : 
     285             : protected:
     286             : 
     287             :     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
     288             : 
     289             : public:
     290             :                     ValueSet( Window* pParent, WinBits nWinStyle, bool bDisableTransientChildren = false );
     291             :                     ValueSet( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false );
     292             :                     ~ValueSet();
     293             : 
     294             :     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
     295             :     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
     296             :     virtual void    MouseMove( const MouseEvent& rMEvt );
     297             :     virtual void    Tracking( const TrackingEvent& rMEvt );
     298             :     virtual void    KeyInput( const KeyEvent& rKEvt );
     299             :     virtual void    Command( const CommandEvent& rCEvt );
     300             :     virtual void    Paint( const Rectangle& rRect );
     301             :     virtual void    GetFocus();
     302             :     virtual void    LoseFocus();
     303             :     virtual void    Resize();
     304             :     virtual void    RequestHelp( const HelpEvent& rHEvt );
     305             :     virtual void    StateChanged( StateChangedType nStateChange );
     306             :     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
     307             : 
     308             :     virtual void    Select();
     309             :     virtual void    DoubleClick();
     310             :     virtual void    UserDraw( const UserDrawEvent& rUDEvt );
     311             : 
     312             :     void            InsertItem( sal_uInt16 nItemId, const Image& rImage,
     313             :                                 size_t nPos = VALUESET_APPEND );
     314             :     void            InsertItem( sal_uInt16 nItemId, const Color& rColor,
     315             :                                 size_t nPos = VALUESET_APPEND );
     316             :     void            InsertItem( sal_uInt16 nItemId,
     317             :                                 const Image& rImage, const XubString& rStr,
     318             :                                 size_t nPos = VALUESET_APPEND );
     319             :     void            InsertItem( sal_uInt16 nItemId,
     320             :                                 const Color& rColor, const XubString& rStr,
     321             :                                 size_t nPos = VALUESET_APPEND );
     322             :     void            InsertItem( sal_uInt16 nItemId,
     323             :                                 size_t nPos = VALUESET_APPEND );
     324             :     void            RemoveItem( sal_uInt16 nItemId );
     325             : 
     326             :     void            Clear();
     327             : 
     328             :     size_t          GetItemCount() const;
     329             :     size_t          GetItemPos( sal_uInt16 nItemId ) const;
     330             :     sal_uInt16          GetItemId( size_t nPos ) const;
     331             :     sal_uInt16          GetItemId( const Point& rPos ) const;
     332             :     Rectangle       GetItemRect( sal_uInt16 nItemId ) const;
     333             : 
     334             :     void            EnableFullItemMode( bool bFullMode = true );
     335             :     bool            IsFullItemModeEnabled() const { return mbFullMode; }
     336             :     void            SetColCount( sal_uInt16 nNewCols = 1 );
     337           0 :     sal_uInt16          GetColCount() const { return mnUserCols; }
     338             :     void            SetLineCount( sal_uInt16 nNewLines = 0 );
     339           0 :     sal_uInt16          GetLineCount() const { return mnUserVisLines; }
     340             :     void            SetItemWidth( long nItemWidth = 0 );
     341             :     long            GetItemWidth() const { return mnUserItemWidth; }
     342             :     void            SetItemHeight( long nLineHeight = 0 );
     343             :     long            GetItemHeight() const { return mnUserItemHeight; }
     344             :     sal_uInt16          GetFirstLine() const { return mnFirstLine; }
     345             : 
     346             :     void            SelectItem( sal_uInt16 nItemId );
     347           0 :     sal_uInt16          GetSelectItemId() const { return mnSelItemId; }
     348           0 :     bool            IsItemSelected( sal_uInt16 nItemId ) const
     349           0 :                         { return !mbNoSelection && (nItemId == mnSelItemId); }
     350             :     void            SetNoSelection();
     351           0 :     bool            IsNoSelection() const { return mbNoSelection; }
     352             : 
     353             :     void            SetItemImage( sal_uInt16 nItemId, const Image& rImage );
     354             :     Image           GetItemImage( sal_uInt16 nItemId ) const;
     355             :     void            SetItemColor( sal_uInt16 nItemId, const Color& rColor );
     356             :     Color           GetItemColor( sal_uInt16 nItemId ) const;
     357             :     void            SetItemData( sal_uInt16 nItemId, void* pData );
     358             :     void*           GetItemData( sal_uInt16 nItemId ) const;
     359             :     void            SetItemText( sal_uInt16 nItemId, const XubString& rStr );
     360             :     XubString       GetItemText( sal_uInt16 nItemId ) const;
     361             :     void            SetColor( const Color& rColor );
     362           0 :     void            SetColor() { SetColor( Color( COL_TRANSPARENT ) ); }
     363             :     Color           GetColor() const { return maColor; }
     364           0 :     bool            IsColor() const { return maColor.GetTransparency() == 0; }
     365             : 
     366             :     void            SetExtraSpacing( sal_uInt16 nNewSpacing );
     367             :     sal_uInt16          GetExtraSpacing() { return mnSpacing; }
     368             : 
     369             :     void            Format();
     370             : 
     371             :     void            StartSelection();
     372             :     void            EndSelection();
     373             : 
     374             :     Size            CalcWindowSizePixel( const Size& rItemSize,
     375             :                                          sal_uInt16 nCalcCols = 0,
     376             :                                          sal_uInt16 nCalcLines = 0 );
     377             :     Size            CalcItemSizePixel( const Size& rSize, bool bOut = true ) const;
     378             :     long            GetScrollWidth() const;
     379             : 
     380           0 :     void            SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
     381             :     const Link&     GetSelectHdl() const { return maSelectHdl; }
     382           0 :     void            SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; }
     383             :     const Link&     GetDoubleClickHdl() const { return maDoubleClickHdl; }
     384             : 
     385             :     void            SetHighlightHdl( const Link& rLink );
     386             : };
     387             : 
     388             : #endif  // _VALUESET_HXX
     389             : 
     390             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10