LCOV - code coverage report
Current view: top level - include/svtools - ivctrl.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 19 39 48.7 %
Date: 2015-06-13 12:38:46 Functions: 19 28 67.9 %
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_IVCTRL_HXX
      21             : #define INCLUDED_SVTOOLS_IVCTRL_HXX
      22             : 
      23             : #include <svtools/svtdllapi.h>
      24             : #include <vcl/ctrl.hxx>
      25             : #include <tools/link.hxx>
      26             : #include <tools/contnr.hxx>
      27             : #include <vcl/image.hxx>
      28             : #include <vcl/seleng.hxx>
      29             : #include <o3tl/typed_flags_set.hxx>
      30             : 
      31             : class ResId;
      32             : class Point;
      33             : class SvxIconChoiceCtrl_Impl;
      34             : class Image;
      35             : 
      36             : enum class SvxIconViewFlags
      37             : {
      38             :     NONE           = 0x0000,
      39             :     POS_LOCKED     = 0x0001,
      40             :     SELECTED       = 0x0002,
      41             :     FOCUSED        = 0x0004,
      42             :     IN_USE         = 0x0008,
      43             :     CURSORED       = 0x0010, // Border around image
      44             :     POS_MOVED      = 0x0020, // Moved by Drag and Drop, but not logged
      45             :     DROP_TARGET    = 0x0040, // Set in QueryDrop
      46             :     BLOCK_EMPHASIS = 0x0080, // Do not paint Emphasis
      47             :     PRED_SET       = 0x0400, // Predecessor moved
      48             : };
      49             : namespace o3tl
      50             : {
      51             :     template<> struct typed_flags<SvxIconViewFlags> : is_typed_flags<SvxIconViewFlags, 0x04ff> {};
      52             : }
      53             : 
      54             : enum SvxIconChoiceCtrlTextMode
      55             : {
      56             :     IcnShowTextFull = 1,        //  Enlarge BoundRect southwards
      57             :     IcnShowTextShort,           // Shorten with "..."
      58             :     IcnShowTextSmart,           // Show all text (not implemented)
      59             :     IcnShowTextDontKnow         // Settings of the View
      60             : };
      61             : 
      62             : enum SvxIconChoiceCtrlPositionMode
      63             : {
      64             :     IcnViewPositionModeFree = 0,                // Free pixel-perfekt positioning
      65             :     IcnViewPositionModeAutoArrange = 1,         // Auto arrange
      66             :     IcnViewPositionModeAutoAdjust = 2,          // Auto adjust
      67             :     IcnViewPositionModeLast = IcnViewPositionModeAutoAdjust
      68             : };
      69             : 
      70             : class SvxIconChoiceCtrlEntry
      71             : {
      72             :     Image aImage;
      73             : 
      74             :     OUString aText;
      75             :     OUString aQuickHelpText;
      76             :     void*  pUserData;
      77             : 
      78             :     friend class SvxIconChoiceCtrl_Impl;
      79             :     friend class IcnCursor_Impl;
      80             :     friend class EntryList_Impl;
      81             :     friend class IcnGridMap_Impl;
      82             : 
      83             :     Rectangle               aRect;              // Bounding-Rect of the entry
      84             :     Rectangle               aGridRect;          // Only valid in Grid-mode
      85             :     sal_uLong                   nPos;
      86             : 
      87             :     /*
      88             :         The insert position in the Insertlist is equal to the (sort) order stated at the Insert
      89             :         (-> Order of the anchors in the anchors-list!). In "AutoArrange" mode the visible order
      90             :         can differ. The entries will be linked because of this.
      91             :     */
      92             :     SvxIconChoiceCtrlEntry*         pblink;     // backward (linker neighbour)
      93             :     SvxIconChoiceCtrlEntry*         pflink;     // forward  (rechter neighbour)
      94             : 
      95             :     SvxIconChoiceCtrlTextMode       eTextMode;
      96             :     sal_uInt16                      nX,nY;      // for keyboard control
      97             :     SvxIconViewFlags                nFlags;
      98             : 
      99         235 :     void                    ClearFlags( SvxIconViewFlags nMask ) { nFlags &= (~nMask); }
     100           3 :     void                    SetFlags( SvxIconViewFlags nMask ) { nFlags |= nMask; }
     101           3 :     void                    AssignFlags( SvxIconViewFlags _nFlags ) { nFlags = _nFlags; }
     102             : 
     103             :     // set left neighbour (A <-> B  ==>  A <-> this <-> B)
     104           0 :     void                    SetBacklink( SvxIconChoiceCtrlEntry* pA )
     105             :                             {
     106           0 :                                 pA->pflink->pblink = this;      // X <- B
     107           0 :                                 this->pflink = pA->pflink;      // X -> B
     108           0 :                                 this->pblink = pA;              // A <- X
     109           0 :                                 pA->pflink = this;              // A -> X
     110           0 :                             }
     111             :     // Unlink (A <-> this <-> B  ==>  A <-> B)
     112           0 :     void                    Unlink()
     113             :                             {
     114           0 :                                 this->pblink->pflink = this->pflink;
     115           0 :                                 this->pflink->pblink = this->pblink;
     116           0 :                                 this->pflink = 0;
     117           0 :                                 this->pblink = 0;
     118           0 :                             }
     119             : 
     120             : public:
     121             :                             SvxIconChoiceCtrlEntry( const OUString& rText, const Image& rImage, SvxIconViewFlags nFlags = SvxIconViewFlags::NONE );
     122          20 :                             ~SvxIconChoiceCtrlEntry () {}
     123             : 
     124             :     void                    SetImage ( const Image& rImage ) { aImage = rImage; }
     125          24 :     Image                   GetImage () const { return aImage; }
     126          28 :     void                    SetText ( const OUString& rText ) { aText = rText; }
     127         128 :     OUString                GetText () const { return aText; }
     128             :     OUString SVT_DLLPUBLIC  GetDisplayText() const;
     129           0 :     void                    SetQuickHelpText( const OUString& rText ) { aQuickHelpText = rText; }
     130           0 :     OUString                GetQuickHelpText() const { return aQuickHelpText; }
     131          48 :     void                    SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
     132         200 :     void*                   GetUserData () { return pUserData; }
     133             : 
     134             :     const Rectangle &       GetBoundRect() const { return aRect; }
     135             : 
     136             :     void                    SetFocus ( bool bSet )
     137             :                                      { nFlags = ( bSet ? nFlags | SvxIconViewFlags::FOCUSED : nFlags & ~SvxIconViewFlags::FOCUSED ); }
     138             : 
     139          48 :     SvxIconChoiceCtrlTextMode   GetTextMode() const { return eTextMode; }
     140          75 :     SvxIconViewFlags        GetFlags() const { return nFlags; }
     141         570 :     bool                    IsSelected() const { return bool(nFlags & SvxIconViewFlags::SELECTED); }
     142          36 :     bool                    IsFocused() const { return bool(nFlags & SvxIconViewFlags::FOCUSED); }
     143             :     bool                    IsInUse() const { return bool(nFlags & SvxIconViewFlags::IN_USE); }
     144          24 :     bool                    IsCursored() const { return bool(nFlags & SvxIconViewFlags::CURSORED); }
     145          24 :     bool                    IsDropTarget() const { return bool(nFlags & SvxIconViewFlags::DROP_TARGET); }
     146          24 :     bool                    IsBlockingEmphasis() const { return bool(nFlags & SvxIconViewFlags::BLOCK_EMPHASIS); }
     147         492 :     bool                    IsPosLocked() const { return bool(nFlags & SvxIconViewFlags::POS_LOCKED); }
     148             :     // Only set at AutoArrange. The head of the list is accessible via SvxIconChoiceCtrl::GetPredecessorHead
     149             :     SvxIconChoiceCtrlEntry*         GetSuccessor() const { return pflink; }
     150             :     SvxIconChoiceCtrlEntry*         GetPredecessor() const { return pblink; }
     151             : 
     152             : //  sal_Unicode             GetMnemonicChar() const;
     153             : };
     154             : 
     155             : enum SvxIconChoiceCtrlColumnAlign
     156             : {
     157             :     IcnViewAlignLeft = 1,
     158             :     IcnViewAlignRight,
     159             :     IcnViewAlignCenter
     160             : };
     161             : 
     162           0 : class SvxIconChoiceCtrlColumnInfo
     163             : {
     164             :     OUString                aColText;
     165             :     Image                   aColImage;
     166             :     long                    nWidth;
     167             :     SvxIconChoiceCtrlColumnAlign    eAlignment;
     168             :     sal_uInt16                  nSubItem;
     169             : 
     170             : public:
     171           0 :                             SvxIconChoiceCtrlColumnInfo( sal_uInt16 nSub, long nWd,
     172             :                                 SvxIconChoiceCtrlColumnAlign eAlign ) :
     173           0 :                                 nWidth( nWd ), eAlignment( eAlign ), nSubItem( nSub ) {}
     174             :                             SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& );
     175             : 
     176             :     void                    SetText( const OUString& rText ) { aColText = rText; }
     177             :     void                    SetImage( const Image& rImg ) { aColImage = rImg; }
     178           0 :     void                    SetWidth( long nWd ) { nWidth = nWd; }
     179             :     void                    SetAlignment( SvxIconChoiceCtrlColumnAlign eAlign ) { eAlignment = eAlign; }
     180             :     void                    SetSubItem( sal_uInt16 nSub) { nSubItem = nSub; }
     181             : 
     182             :     const OUString&         GetText() const { return aColText; }
     183             :     const Image&            GetImage() const { return aColImage; }
     184           0 :     long                    GetWidth() const { return nWidth; }
     185             :     SvxIconChoiceCtrlColumnAlign    GetAlignment() const { return eAlignment; }
     186             :     sal_uInt16                  GetSubItem() const { return nSubItem; }
     187             : };
     188             : 
     189             : 
     190             : /*
     191             :     Window-Bits:
     192             :         WB_ICON             // Text beneth the icon
     193             :         WB_SMALL_ICON       // Text right to the icon, position does not mind
     194             :         WB_DETAILS          // Text right to the icon, limited positioning
     195             :         WB_BORDER
     196             :         WB_NOHIDESELECTION  // Draw selection inaktively, if not focused.
     197             :         WB_NOHSCROLL
     198             :         WB_NOVSCROLL
     199             :         WB_NOSELECTION
     200             :         WB_SMART_ARRANGE    // Keep Vis-Area at arrange
     201             :         WB_ALIGN_TOP        // Align line vy line LTR
     202             :         WB_ALIGN_LEFT       // Align columns from top to bottom
     203             :         WB_NODRAGSELECTION  // No selection with tracking rectangle
     204             :         WB_NOCOLUMNHEADER   // No Headerbar in Details view (Headerbar not implemented)
     205             :         WB_NOPOINTERFOCUS   // No GrabFocus at MouseButtonDown
     206             :         WB_HIGHLIGHTFRAME   // The entry beneth the mouse willbe highlighted
     207             :         WB_NOASYNCSELECTHDL // Do not collect events -> Selection handlers will be called synchronously
     208             : */
     209             : 
     210             : #define WB_ICON                 WB_RECTSTYLE
     211             : #define WB_SMALLICON            WB_SMALLSTYLE
     212             : #define WB_DETAILS              WB_VCENTER
     213             : #define WB_NOHSCROLL            WB_SPIN
     214             : #define WB_NOVSCROLL            WB_DRAG
     215             : #define WB_NOSELECTION          WB_REPEAT
     216             : #define WB_NODRAGSELECTION      WB_PATHELLIPSIS
     217             : #define WB_SMART_ARRANGE        WB_PASSWORD
     218             : #define WB_ALIGN_TOP            WB_TOP
     219             : #define WB_ALIGN_LEFT           WB_LEFT
     220             : #define WB_NOCOLUMNHEADER       WB_CENTER
     221             : #define WB_HIGHLIGHTFRAME       WB_INFO
     222             : #define WB_NOASYNCSELECTHDL     WB_NOLABEL
     223             : 
     224             : class MnemonicGenerator;
     225             : 
     226             : class SVT_DLLPUBLIC SvtIconChoiceCtrl : public Control
     227             : {
     228             :     friend class SvxIconChoiceCtrl_Impl;
     229             : 
     230             :     Link<>                  _aClickIconHdl;
     231             :     Link<>                  _aDocRectChangedHdl;
     232             :     Link<>                  _aVisRectChangedHdl;
     233             :     KeyEvent*               _pCurKeyEvent;
     234             :     SvxIconChoiceCtrl_Impl* _pImp;
     235             :     bool                    _bAutoFontColor;
     236             : 
     237             : protected:
     238             : 
     239             :     virtual void        KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
     240             :     void                DocumentRectChanged();
     241             :     void                VisibleRectChanged();
     242             :     virtual void        Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
     243             :     virtual void        Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) SAL_OVERRIDE;
     244             :     virtual void        MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     245             :     virtual void        MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     246             :     virtual void        MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     247             :     virtual void        Resize() SAL_OVERRIDE;
     248             :     virtual void        GetFocus() SAL_OVERRIDE;
     249             :     virtual void        LoseFocus() SAL_OVERRIDE;
     250             :     void                ClickIcon();
     251             :     virtual void        StateChanged( StateChangedType nType ) SAL_OVERRIDE;
     252             :     virtual void        DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
     253             :     virtual void        RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
     254             :     static void         DrawEntryImage(
     255             :                             SvxIconChoiceCtrlEntry* pEntry,
     256             :                             const Point& rPos,
     257             :                             OutputDevice& rDev );
     258             : 
     259             :     static OUString      GetEntryText(
     260             :                             SvxIconChoiceCtrlEntry* pEntry,
     261             :                             bool bInplaceEdit );
     262             : 
     263             :     virtual void        FillLayoutData() const SAL_OVERRIDE;
     264             : 
     265             :     void                CallImplEventListeners(sal_uLong nEvent, void* pData);
     266             : 
     267             : public:
     268             : 
     269             :                         SvtIconChoiceCtrl( vcl::Window* pParent, WinBits nWinStyle = WB_ICON | WB_BORDER );
     270             :     virtual             ~SvtIconChoiceCtrl();
     271             :     virtual void        dispose() SAL_OVERRIDE;
     272             : 
     273             :     void                SetStyle( WinBits nWinStyle );
     274             :     WinBits             GetStyle() const;
     275             : 
     276             :     bool                SetChoiceWithCursor ( bool bDo = true );
     277             : 
     278             :     void                SetFont( const vcl::Font& rFont );
     279             :     void                SetPointFont( const vcl::Font& rFont );
     280             : 
     281           7 :     void                SetClickHdl( const Link<>& rLink ) { _aClickIconHdl = rLink; }
     282           0 :     const Link<>&       GetClickHdl() const { return _aClickIconHdl; }
     283             : 
     284             :     using OutputDevice::SetBackground;
     285             :     void                SetBackground( const Wallpaper& rWallpaper );
     286             : 
     287             :     void                ArrangeIcons();
     288             : 
     289             : 
     290             :     SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText,
     291             :                                          const Image& rImage,
     292             :                                          sal_uLong nPos = CONTAINER_APPEND,
     293             :                                          const Point* pPos = 0,
     294             :                                          SvxIconViewFlags nFlags = SvxIconViewFlags::NONE
     295             :                                        );
     296             : 
     297             :     /** creates automatic mnemonics for all icon texts in the control
     298             : 
     299             :     @param _rUsedMnemonics
     300             :         a MnemonicGenerator at which some other mnemonics are already registered.
     301             :         This can be used if the control needs to share the "mnemonic space" with other elements,
     302             :         such as a menu bar.
     303             :     */
     304             :     void                CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
     305             : 
     306             :     bool                DoKeyInput( const KeyEvent& rKEvt );
     307             : 
     308             :     bool                IsEntryEditing() const;
     309             : 
     310             :     sal_uLong                   GetEntryCount() const;
     311             :     SvxIconChoiceCtrlEntry* GetEntry( sal_uLong nPos ) const;
     312             :     sal_uLong                   GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const;
     313             :     using Window::SetCursor;
     314             :     void                    SetCursor( SvxIconChoiceCtrlEntry* pEntry );
     315             :     SvxIconChoiceCtrlEntry* GetCursor() const;
     316             : 
     317             :     // Re-calculation of cached view-data and invalidatiopn of those in the view
     318             :     void                    InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
     319             : 
     320             :     // bHit == false: Entry is selectd, if the BoundRect is selected
     321             :     //      == true : Bitmap or Text must be selected
     322             :     SvxIconChoiceCtrlEntry* GetEntry( const Point& rPosPixel, bool bHit = false ) const;
     323             : 
     324             :     // sal_uLong is the position of the selected element in the list
     325             :     SvxIconChoiceCtrlEntry* GetSelectedEntry( sal_uLong& rPos ) const;
     326             : 
     327             : #ifdef DBG_UTIL
     328             :     void                        SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry = 0 );
     329             : #endif
     330             : 
     331             :     void                SetFontColorToBackground ( bool bDo = true ) { _bAutoFontColor = bDo; }
     332          48 :     bool                AutoFontColor () { return _bAutoFontColor; }
     333             : 
     334             :     Point               GetPixelPos( const Point& rPosLogic ) const;
     335             :     void                SetSelectionMode( SelectionMode eMode );
     336             : 
     337             :     Rectangle           GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
     338             :     Rectangle           GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
     339             : 
     340             :     void                SetNoSelection();
     341             : 
     342             :     // ACCESSIBILITY ==========================================================
     343             : 
     344             :     /** Creates and returns the accessible object of the Box. */
     345             :     virtual ::com::sun::star::uno::Reference<
     346             :         ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
     347             : };
     348             : 
     349             : #endif // INCLUDED_SVTOOLS_IVCTRL_HXX
     350             : 
     351             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11