LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/vcl - seleng.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 55 38.2 %
Date: 2013-07-09 Functions: 9 19 47.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef _SV_SELENG_HXX
      21             : #define _SV_SELENG_HXX
      22             : 
      23             : #include <vcl/dllapi.h>
      24             : #include <vcl/timer.hxx>
      25             : #include <vcl/event.hxx>
      26             : 
      27             : class Window;
      28             : class CommandEvent;
      29             : 
      30             : // Timerticks
      31             : #define SELENG_DRAGDROP_TIMEOUT     400
      32             : #define SELENG_AUTOREPEAT_INTERVAL  50
      33             : #define SELENG_AUTOREPEAT_INTERVAL_MIN 25
      34             : #define SELENG_AUTOREPEAT_INTERVAL_MAX 300
      35             : 
      36             : enum SelectionMode { NO_SELECTION, SINGLE_SELECTION, RANGE_SELECTION, MULTIPLE_SELECTION };
      37             : 
      38             : // ---------------
      39             : // - FunctionSet -
      40             : // ---------------
      41             : 
      42       20158 : class VCL_DLLPUBLIC FunctionSet
      43             : {
      44             : public:
      45             :     virtual ~FunctionSet() = 0;
      46             : 
      47             :     virtual void    BeginDrag() = 0;
      48             : 
      49             :     virtual void    CreateAnchor() = 0;  // Anker-Pos := Cursor-Pos
      50             :     virtual void    DestroyAnchor() = 0;
      51             : 
      52             :     // move cursor, at the same time match cursor position to the selection
      53             :     // starting at anchor. sal_True == Ok
      54             :     virtual sal_Bool    SetCursorAtPoint( const Point& rPointPixel,
      55             :                                           sal_Bool bDontSelectAtCursor = sal_False ) = 0;
      56             : 
      57             :     virtual sal_Bool    IsSelectionAtPoint( const Point& rPointPixel ) = 0;
      58             :     virtual void        DeselectAtPoint( const Point& rPointPixel ) = 0;
      59             :     // delete anchor & deselect all
      60             :     virtual void        DeselectAll() = 0;
      61             : };
      62             : 
      63             : // -------------------
      64             : // - SelectionEngine -
      65             : // -------------------
      66             : 
      67             : #define SELENG_DRG_ENAB     0x0001
      68             : #define SELENG_IN_SEL       0x0002
      69             : #define SELENG_IN_ADD       0x0004
      70             : #define SELENG_ADD_ALW      0x0008
      71             : #define SELENG_HAS_ANCH     0x0020
      72             : #define SELENG_CMDEVT       0x0040
      73             : #define SELENG_WAIT_UPEVT   0x0080
      74             : #define SELENG_EXPANDONMOVE 0x0100
      75             : 
      76             : class VCL_DLLPUBLIC SelectionEngine
      77             : {
      78             : private:
      79             :     FunctionSet*        pFunctionSet;
      80             :     Window*             pWin;
      81             :     Rectangle           aArea;
      82             :     Timer               aWTimer; // generate fake mouse moves
      83             :     MouseEvent          aLastMove;
      84             :     SelectionMode       eSelMode;
      85             :     sal_uLong               nUpdateInterval;
      86             :     // sensitivity of mouse moves during a selection
      87             :     sal_uInt16              nMouseSensitivity;
      88             :     sal_uInt16              nLockedMods;
      89             :     sal_uInt16              nFlags;
      90             :     DECL_DLLPRIVATE_LINK( ImpWatchDog, void* );
      91             : 
      92             :     inline sal_Bool         ShouldDeselect( sal_Bool bModifierKey1 ) const;
      93             :                                 // determines to deselect or not when Ctrl-key is pressed on CursorPosChanging
      94             : public:
      95             : 
      96             :                         SelectionEngine( Window* pWindow,
      97             :                                          FunctionSet* pFunctions = NULL,
      98             :                                          sal_uLong nAutoRepeatInterval = SELENG_AUTOREPEAT_INTERVAL );
      99             :                         ~SelectionEngine();
     100             : 
     101             :     // sal_True: Event was processed by Selection Engine
     102             :     sal_Bool                SelMouseButtonDown( const MouseEvent& rMEvt );
     103             :     sal_Bool                SelMouseButtonUp( const MouseEvent& rMEvt );
     104             :     sal_Bool                SelMouseMove( const MouseEvent& rMEvt );
     105             : 
     106             :     // Keyboard
     107             :     void                CursorPosChanging( sal_Bool bShift, sal_Bool bMod1 );
     108             : 
     109             :     // is needed to generate a Move event via a Timer
     110             :     // when the mouse is outside the area
     111         742 :     void                SetVisibleArea( const Rectangle rNewArea )
     112         742 :                             { aArea = rNewArea; }
     113             :     const Rectangle&    GetVisibleArea() const { return aArea; }
     114             : 
     115             :     void                SetAddMode( sal_Bool);
     116             :     sal_Bool                IsAddMode() const;
     117             : 
     118             :     void                AddAlways( sal_Bool bOn );
     119             :     sal_Bool                IsAlwaysAdding() const;
     120             : 
     121             :     void                EnableDrag( sal_Bool bOn );
     122             : 
     123             :     void                SetSelectionMode( SelectionMode eMode );
     124         184 :     SelectionMode       GetSelectionMode() const { return eSelMode; }
     125             : 
     126       19706 :     void                SetFunctionSet( FunctionSet* pFuncs )
     127       19706 :                             { pFunctionSet = pFuncs; }
     128          82 :     const FunctionSet*  GetFunctionSet() const { return pFunctionSet; }
     129             : 
     130             :     void                SetMouseSensitivity( sal_uInt16 nSensitivity )
     131             :                             { nMouseSensitivity = nSensitivity; }
     132             :     sal_uInt16              GetMouseSensitivity() const
     133             :                             { return nMouseSensitivity; }
     134             : 
     135           0 :     const Point&        GetMousePosPixel() const
     136           0 :                             { return aLastMove.GetPosPixel(); }
     137           0 :     const MouseEvent&   GetMouseEvent() const { return aLastMove; }
     138             : 
     139             :     void                SetWindow( Window*);
     140           0 :     Window*             GetWindow() const { return pWin; }
     141             : 
     142           0 :     void                LockModifiers( sal_uInt16 nModifiers )
     143           0 :                             { nLockedMods = nModifiers; }
     144         185 :     sal_uInt16              GetLockedModifiers() const { return nLockedMods; }
     145             : 
     146             :     sal_Bool                IsInSelection() const;
     147             :     void                Reset();
     148             : 
     149             :     void                Command( const CommandEvent& rCEvt );
     150             : 
     151             :     sal_Bool                HasAnchor() const;
     152             :     void                SetAnchor( sal_Bool bAnchor );
     153             : 
     154             :     void                SetUpdateInterval( sal_uLong nInterval );
     155             : 
     156             :     // wird im Ctor eingeschaltet
     157         486 :     void                ExpandSelectionOnMouseMove( sal_Bool bExpand = sal_True )
     158             :                         {
     159         486 :                             if( bExpand )
     160         122 :                                 nFlags |= SELENG_EXPANDONMOVE;
     161             :                             else
     162         364 :                                 nFlags &= ~SELENG_EXPANDONMOVE;
     163         486 :                         }
     164             : };
     165             : 
     166          47 : inline sal_Bool SelectionEngine::IsAddMode()  const
     167             : {
     168          47 :     if ( nFlags & (SELENG_IN_ADD | SELENG_ADD_ALW) )
     169           0 :         return sal_True;
     170             :     else
     171          47 :         return sal_False;
     172             : }
     173             : 
     174           0 : inline void SelectionEngine::SetAddMode( sal_Bool bNewMode )
     175             : {
     176           0 :     if ( bNewMode )
     177           0 :         nFlags |= SELENG_IN_ADD;
     178             :     else
     179           0 :         nFlags &= (~SELENG_IN_ADD);
     180           0 : }
     181             : 
     182       20401 : inline void SelectionEngine::EnableDrag( sal_Bool bOn )
     183             : {
     184       20401 :     if ( bOn )
     185       20076 :         nFlags |= SELENG_DRG_ENAB;
     186             :     else
     187         325 :         nFlags &= (~SELENG_DRG_ENAB);
     188       20401 : }
     189             : 
     190           0 : inline void SelectionEngine::AddAlways( sal_Bool bOn )
     191             : {
     192           0 :     if( bOn )
     193           0 :         nFlags |= SELENG_ADD_ALW;
     194             :     else
     195           0 :         nFlags &= (~SELENG_ADD_ALW);
     196           0 : }
     197             : 
     198           0 : inline sal_Bool SelectionEngine::IsAlwaysAdding() const
     199             : {
     200           0 :     if ( nFlags & SELENG_ADD_ALW )
     201           0 :         return sal_True;
     202             :     else
     203           0 :         return sal_False;
     204             : }
     205             : 
     206           0 : inline sal_Bool SelectionEngine::IsInSelection() const
     207             : {
     208           0 :     if ( nFlags & SELENG_IN_SEL )
     209           0 :         return sal_True;
     210             :     else
     211           0 :         return sal_False;
     212             : }
     213             : 
     214           0 : inline sal_Bool SelectionEngine::HasAnchor() const
     215             : {
     216           0 :     if ( nFlags & SELENG_HAS_ANCH )
     217           0 :         return sal_True;
     218             :     else
     219           0 :         return sal_False;
     220             : }
     221             : 
     222           0 : inline void SelectionEngine::SetAnchor( sal_Bool bAnchor )
     223             : {
     224           0 :     if ( bAnchor )
     225           0 :         nFlags |= SELENG_HAS_ANCH;
     226             :     else
     227           0 :         nFlags &= (~SELENG_HAS_ANCH);
     228           0 : }
     229             : 
     230             : #endif  // _SV_SELENG_HXX
     231             : 
     232             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10