LCOV - code coverage report
Current view: top level - include/svtools - ivctrl.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 19 41 46.3 %
Date: 2014-04-11 Functions: 19 30 63.3 %
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             : 
      30             : class ResId;
      31             : class Point;
      32             : class SvxIconChoiceCtrl_Impl;
      33             : class Image;
      34             : 
      35             : #define ICNVIEW_FLAG_POS_LOCKED     0x0001
      36             : #define ICNVIEW_FLAG_SELECTED       0x0002
      37             : #define ICNVIEW_FLAG_FOCUSED        0x0004
      38             : #define ICNVIEW_FLAG_IN_USE         0x0008
      39             : #define ICNVIEW_FLAG_CURSORED       0x0010 // Rahmen um Image
      40             : #define ICNVIEW_FLAG_POS_MOVED      0x0020 // per D&D verschoben aber nicht gelockt
      41             : #define ICNVIEW_FLAG_DROP_TARGET    0x0040 // im QueryDrop gesetzt
      42             : #define ICNVIEW_FLAG_BLOCK_EMPHASIS 0x0080 // Emphasis nicht painten
      43             : #define ICNVIEW_FLAG_USER1          0x0100
      44             : #define ICNVIEW_FLAG_USER2          0x0200
      45             : #define ICNVIEW_FLAG_PRED_SET       0x0400 // Predecessor wurde umgesetzt
      46             : 
      47             : enum SvxIconChoiceCtrlTextMode
      48             : {
      49             :     IcnShowTextFull = 1,        // BoundRect nach unten aufplustern
      50             :     IcnShowTextShort,           // Abkuerzung mit "..."
      51             :     IcnShowTextSmart,           // Text komplett anzeigen, wenn moeglich (n.i.)
      52             :     IcnShowTextDontKnow         // Einstellung der View
      53             : };
      54             : 
      55             : enum SvxIconChoiceCtrlPositionMode
      56             : {
      57             :     IcnViewPositionModeFree = 0,                // freies pixelgenaues Positionieren
      58             :     IcnViewPositionModeAutoArrange = 1,         // automatisches Ausrichten
      59             :     IcnViewPositionModeAutoAdjust = 2,          // automatisches Anordnen
      60             :     IcnViewPositionModeLast = IcnViewPositionModeAutoAdjust
      61             : };
      62             : 
      63             : class SvxIconChoiceCtrlEntry
      64             : {
      65             :     Image aImage;
      66             : 
      67             :     OUString aText;
      68             :     OUString aQuickHelpText;
      69             :     void*  pUserData;
      70             : 
      71             :     friend class SvxIconChoiceCtrl_Impl;
      72             :     friend class IcnCursor_Impl;
      73             :     friend class EntryList_Impl;
      74             :     friend class IcnGridMap_Impl;
      75             : 
      76             :     Rectangle               aRect;              // Bounding-Rect des Entries
      77             :     Rectangle               aGridRect;          // nur gesetzt im Grid-Modus
      78             :     sal_uLong                   nPos;
      79             : 
      80             :     // die Eintragsposition in der Eintragsliste entspricht der beim Insert vorgegebenen
      81             :     // [Sortier-]Reihenfolge (->Reihenfolge der Anker in der Ankerliste!). Im AutoArrange-Modus
      82             :     // kann die sichtbare Reihenfolge aber anders sein. Die Eintraege werden deshalb dann
      83             :     // verkettet
      84             :     SvxIconChoiceCtrlEntry*         pblink;     // backward (linker Nachbar)
      85             :     SvxIconChoiceCtrlEntry*         pflink;     // forward  (rechter Nachbar)
      86             : 
      87             :     SvxIconChoiceCtrlTextMode       eTextMode;
      88             :     sal_uInt16                  nX,nY;      // fuer Tastatursteuerung
      89             :     sal_uInt16                  nFlags;
      90             : 
      91         178 :     void                    ClearFlags( sal_uInt16 nMask ) { nFlags &= (~nMask); }
      92           5 :     void                    SetFlags( sal_uInt16 nMask ) { nFlags |= nMask; }
      93           2 :     void                    AssignFlags( sal_uInt16 _nFlags ) { nFlags = _nFlags; }
      94             : 
      95             :     // setzt den linken Nachbarn (A <-> B  ==>  A <-> this <-> B)
      96           0 :     void                    SetBacklink( SvxIconChoiceCtrlEntry* pA )
      97             :                             {
      98           0 :                                 pA->pflink->pblink = this;      // X <- B
      99           0 :                                 this->pflink = pA->pflink;      // X -> B
     100           0 :                                 this->pblink = pA;              // A <- X
     101           0 :                                 pA->pflink = this;              // A -> X
     102           0 :                             }
     103             :     // loest eine Verbindung (A <-> this <-> B  ==>  A <-> B)
     104           0 :     void                    Unlink()
     105             :                             {
     106           0 :                                 this->pblink->pflink = this->pflink;
     107           0 :                                 this->pflink->pblink = this->pblink;
     108           0 :                                 this->pflink = 0;
     109           0 :                                 this->pblink = 0;
     110           0 :                             }
     111             : 
     112             : public:
     113             :                             SvxIconChoiceCtrlEntry( const OUString& rText, const Image& rImage, sal_uInt16 nFlags = 0 );
     114           4 :                             ~SvxIconChoiceCtrlEntry () {}
     115             : 
     116           0 :     void                    SetImage ( const Image& rImage ) { aImage = rImage; }
     117          15 :     Image                   GetImage () const { return aImage; }
     118          20 :     void                    SetText ( const OUString& rText ) { aText = rText; }
     119          98 :     OUString                GetText () const { return aText; }
     120             :     OUString SVT_DLLPUBLIC  GetDisplayText() const;
     121           0 :     void                    SetQuickHelpText( const OUString& rText ) { aQuickHelpText = rText; }
     122           0 :     OUString                GetQuickHelpText() const { return aQuickHelpText; }
     123          24 :     void                    SetUserData ( void* _pUserData ) { pUserData = _pUserData; }
     124         124 :     void*                   GetUserData () { return pUserData; }
     125             : 
     126           0 :     const Rectangle &       GetBoundRect() const { return aRect; }
     127             : 
     128             :     void                    SetFocus ( bool bSet )
     129             :                                      { nFlags = ( bSet ? nFlags | ICNVIEW_FLAG_FOCUSED : nFlags & ~ICNVIEW_FLAG_FOCUSED ); }
     130             : 
     131          43 :     SvxIconChoiceCtrlTextMode   GetTextMode() const { return eTextMode; }
     132          78 :     sal_uInt16              GetFlags() const { return nFlags; }
     133         375 :     bool                    IsSelected() const { return ((nFlags & ICNVIEW_FLAG_SELECTED) !=0); }
     134          19 :     bool                    IsFocused() const { return ((nFlags & ICNVIEW_FLAG_FOCUSED) !=0); }
     135             :     bool                    IsInUse() const { return ((nFlags & ICNVIEW_FLAG_IN_USE) !=0); }
     136          15 :     bool                    IsCursored() const { return ((nFlags & ICNVIEW_FLAG_CURSORED) !=0); }
     137          15 :     bool                    IsDropTarget() const { return ((nFlags & ICNVIEW_FLAG_DROP_TARGET) !=0); }
     138          15 :     bool                    IsBlockingEmphasis() const { return ((nFlags & ICNVIEW_FLAG_BLOCK_EMPHASIS) !=0); }
     139         372 :     bool                    IsPosLocked() const { return ((nFlags & ICNVIEW_FLAG_POS_LOCKED) !=0); }
     140             : 
     141             :     // Nur bei AutoArrange gesetzt. Den Kopf der Liste gibts per SvxIconChoiceCtrl::GetPredecessorHead
     142             :     SvxIconChoiceCtrlEntry*         GetSuccessor() const { return pflink; }
     143             :     SvxIconChoiceCtrlEntry*         GetPredecessor() const { return pblink; }
     144             : 
     145             : //  sal_Unicode             GetMnemonicChar() const;
     146             : };
     147             : 
     148             : enum SvxIconChoiceCtrlColumnAlign
     149             : {
     150             :     IcnViewAlignLeft = 1,
     151             :     IcnViewAlignRight,
     152             :     IcnViewAlignCenter
     153             : };
     154             : 
     155           0 : class SvxIconChoiceCtrlColumnInfo
     156             : {
     157             :     OUString                aColText;
     158             :     Image                   aColImage;
     159             :     long                    nWidth;
     160             :     SvxIconChoiceCtrlColumnAlign    eAlignment;
     161             :     sal_uInt16                  nSubItem;
     162             : 
     163             : public:
     164           0 :                             SvxIconChoiceCtrlColumnInfo( sal_uInt16 nSub, long nWd,
     165             :                                 SvxIconChoiceCtrlColumnAlign eAlign ) :
     166           0 :                                 nWidth( nWd ), eAlignment( eAlign ), nSubItem( nSub ) {}
     167             :                             SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& );
     168             : 
     169             :     void                    SetText( const OUString& rText ) { aColText = rText; }
     170             :     void                    SetImage( const Image& rImg ) { aColImage = rImg; }
     171           0 :     void                    SetWidth( long nWd ) { nWidth = nWd; }
     172             :     void                    SetAlignment( SvxIconChoiceCtrlColumnAlign eAlign ) { eAlignment = eAlign; }
     173             :     void                    SetSubItem( sal_uInt16 nSub) { nSubItem = nSub; }
     174             : 
     175             :     const OUString&         GetText() const { return aColText; }
     176             :     const Image&            GetImage() const { return aColImage; }
     177           0 :     long                    GetWidth() const { return nWidth; }
     178             :     SvxIconChoiceCtrlColumnAlign    GetAlignment() const { return eAlignment; }
     179             :     sal_uInt16                  GetSubItem() const { return nSubItem; }
     180             : };
     181             : 
     182             : 
     183             : /*
     184             :     Window-Bits:
     185             :         WB_ICON             // Text unter dem Icon
     186             :         WB_SMALL_ICON       // Text rechts neben Icon, beliebige Positionierung
     187             :         WB_DETAILS          // Text rechts neben Icon, eingeschraenkte Posit.
     188             :         WB_BORDER
     189             :         WB_NOHIDESELECTION  // Selektion inaktiv zeichnen, wenn kein Fokus
     190             :         WB_NOHSCROLL
     191             :         WB_NOVSCROLL
     192             :         WB_NOSELECTION
     193             :         WB_SMART_ARRANGE    // im Arrange die Vis-Area beibehalten
     194             :         WB_ALIGN_TOP        // Anordnung zeilenweise von links nach rechts
     195             :         WB_ALIGN_LEFT       // Anordnung spaltenweise von oben nach unten
     196             :         WB_NODRAGSELECTION  // Keine Selektion per Tracking-Rect
     197             :         WB_NOCOLUMNHEADER   // keine Headerbar in Detailsview (Headerbar not implemented)
     198             :         WB_NOPOINTERFOCUS   // Kein GrabFocus im MouseButtonDown
     199             :         WB_HIGHLIGHTFRAME   // der unter der Maus befindliche Eintrag wird hervorgehoben
     200             :         WB_NOASYNCSELECTHDL // Selektionshandler synchron aufrufen, d.h. Events nicht sammeln
     201             : */
     202             : 
     203             : #define WB_ICON                 WB_RECTSTYLE
     204             : #define WB_SMALLICON            WB_SMALLSTYLE
     205             : #define WB_DETAILS              WB_VCENTER
     206             : #define WB_NOHSCROLL            WB_SPIN
     207             : #define WB_NOVSCROLL            WB_DRAG
     208             : #define WB_NOSELECTION          WB_REPEAT
     209             : #define WB_NODRAGSELECTION      WB_PATHELLIPSIS
     210             : #define WB_SMART_ARRANGE        WB_PASSWORD
     211             : #define WB_ALIGN_TOP            WB_TOP
     212             : #define WB_ALIGN_LEFT           WB_LEFT
     213             : #define WB_NOCOLUMNHEADER       WB_CENTER
     214             : #define WB_HIGHLIGHTFRAME       WB_INFO
     215             : #define WB_NOASYNCSELECTHDL     WB_NOLABEL
     216             : 
     217             : class MnemonicGenerator;
     218             : 
     219             : class SVT_DLLPUBLIC SvtIconChoiceCtrl : public Control
     220             : {
     221             :     friend class SvxIconChoiceCtrl_Impl;
     222             : 
     223             :     Link                    _aClickIconHdl;
     224             :     Link                    _aDocRectChangedHdl;
     225             :     Link                    _aVisRectChangedHdl;
     226             :     KeyEvent*               _pCurKeyEvent;
     227             :     SvxIconChoiceCtrl_Impl* _pImp;
     228             :     bool                    _bAutoFontColor;
     229             : 
     230             : protected:
     231             : 
     232             :     virtual void        KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
     233             :     virtual bool        EditedEntry( SvxIconChoiceCtrlEntry*, const OUString& rNewText, bool bCancelled );
     234             :     virtual void        DocumentRectChanged();
     235             :     virtual void        VisibleRectChanged();
     236             :     virtual bool        EditingEntry( SvxIconChoiceCtrlEntry* pEntry );
     237             :     virtual void        Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
     238             :     virtual void        Paint( const Rectangle& rRect ) SAL_OVERRIDE;
     239             :     virtual void        MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     240             :     virtual void        MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     241             :     virtual void        MouseMove( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     242             :     virtual void        Resize() SAL_OVERRIDE;
     243             :     virtual void        GetFocus() SAL_OVERRIDE;
     244             :     virtual void        LoseFocus() SAL_OVERRIDE;
     245             :     virtual void        ClickIcon();
     246             :     virtual void        StateChanged( StateChangedType nType ) SAL_OVERRIDE;
     247             :     virtual void        DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
     248             :     virtual void        RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
     249             :     virtual void        DrawEntryImage(
     250             :                             SvxIconChoiceCtrlEntry* pEntry,
     251             :                             const Point& rPos,
     252             :                             OutputDevice& rDev );
     253             : 
     254             :     OUString            GetEntryText(
     255             :                             SvxIconChoiceCtrlEntry* pEntry,
     256             :                             bool bInplaceEdit );
     257             : 
     258             :     virtual void        FillLayoutData() const SAL_OVERRIDE;
     259             : 
     260             :     void                CallImplEventListeners(sal_uLong nEvent, void* pData);
     261             : 
     262             : public:
     263             : 
     264             :                         SvtIconChoiceCtrl( Window* pParent, WinBits nWinStyle = WB_ICON | WB_BORDER );
     265             :     virtual             ~SvtIconChoiceCtrl();
     266             : 
     267             :     void                SetStyle( WinBits nWinStyle );
     268             :     WinBits             GetStyle() const;
     269             : 
     270             :     bool                SetChoiceWithCursor ( bool bDo = true );
     271             : 
     272             :     void                SetFont( const Font& rFont );
     273             :     void                SetPointFont( const Font& rFont );
     274             : 
     275           5 :     void                SetClickHdl( const Link& rLink ) { _aClickIconHdl = rLink; }
     276           0 :     const Link&         GetClickHdl() const { return _aClickIconHdl; }
     277             : 
     278             :     using OutputDevice::SetBackground;
     279             :     void                SetBackground( const Wallpaper& rWallpaper );
     280             : 
     281             :     void                ArrangeIcons();
     282             : 
     283             : 
     284             :     SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText,
     285             :                                          const Image& rImage,
     286             :                                          sal_uLong nPos = CONTAINER_APPEND,
     287             :                                          const Point* pPos = 0,
     288             :                                          sal_uInt16 nFlags = 0
     289             :                                        );
     290             : 
     291             :     /** creates automatic mnemonics for all icon texts in the control
     292             :     */
     293             :     void                CreateAutoMnemonics( void );
     294             : 
     295             :     /** creates automatic mnemonics for all icon texts in the control
     296             : 
     297             :     @param _rUsedMnemonics
     298             :         a MnemonicGenerator at which some other mnemonics are already registered.
     299             :         This can be used if the control needs to share the "mnemonic space" with other elements,
     300             :         such as a menu bar.
     301             :     */
     302             :     void                CreateAutoMnemonics( MnemonicGenerator& _rUsedMnemonics );
     303             : 
     304             :     bool                DoKeyInput( const KeyEvent& rKEvt );
     305             : 
     306             :     bool                IsEntryEditing() const;
     307             : 
     308             :     sal_uLong                   GetEntryCount() const;
     309             :     SvxIconChoiceCtrlEntry* GetEntry( sal_uLong nPos ) const;
     310             :     sal_uLong                   GetEntryListPos( SvxIconChoiceCtrlEntry* pEntry ) const;
     311             :     using Window::SetCursor;
     312             :     void                    SetCursor( SvxIconChoiceCtrlEntry* pEntry );
     313             :     SvxIconChoiceCtrlEntry* GetCursor() const;
     314             : 
     315             :     // Neu-Berechnung gecachter View-Daten und Invalidierung im Fenster
     316             :     void                    InvalidateEntry( SvxIconChoiceCtrlEntry* pEntry );
     317             : 
     318             :     // bHit==sal_False: Eintrag gilt als getroffen, wenn Position im BoundRect liegt
     319             :     //     ==sal_True : Bitmap oder Text muss getroffen sein
     320             :     SvxIconChoiceCtrlEntry* GetEntry( const Point& rPosPixel, bool bHit = false ) const;
     321             : 
     322             :     // in dem sal_uLong wird die Position in der Liste des gefunden Eintrags zurueckgegeben
     323             :     SvxIconChoiceCtrlEntry* GetSelectedEntry( sal_uLong& rPos ) const;
     324             : 
     325             : #ifdef DBG_UTIL
     326             :     void                        SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry = 0 );
     327             : #endif
     328             : 
     329             :     virtual bool        HasBackground() const;
     330             :     virtual bool        HasFont() const;
     331             :     virtual bool        HasFontTextColor() const;
     332             :     virtual bool        HasFontFillColor() const;
     333             : 
     334             :     void                SetFontColorToBackground ( bool bDo = true ) { _bAutoFontColor = bDo; }
     335          30 :     bool                AutoFontColor () { return _bAutoFontColor; }
     336             : 
     337             :     Point               GetPixelPos( const Point& rPosLogic ) const;
     338             :     void                SetSelectionMode( SelectionMode eMode );
     339             : 
     340             :     Rectangle           GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const;
     341             :     Rectangle           GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const;
     342             : 
     343             :     void                SetNoSelection();
     344             : 
     345             :     // ACCESSIBILITY ==========================================================
     346             : 
     347             :     /** Creates and returns the accessible object of the Box. */
     348             :     virtual ::com::sun::star::uno::Reference<
     349             :         ::com::sun::star::accessibility::XAccessible > CreateAccessible() SAL_OVERRIDE;
     350             : };
     351             : 
     352             : #endif // INCLUDED_SVTOOLS_IVCTRL_HXX
     353             : 
     354             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10