LCOV - code coverage report
Current view: top level - vcl/source/window - cursor.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 148 217 68.2 %
Date: 2014-04-11 Functions: 21 28 75.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             : #include <vcl/svapp.hxx>
      21             : #include <vcl/timer.hxx>
      22             : #include <vcl/settings.hxx>
      23             : #include <vcl/window.hxx>
      24             : #include <vcl/cursor.hxx>
      25             : 
      26             : #include <window.h>
      27             : 
      28             : #include <tools/poly.hxx>
      29             : 
      30        3090 : struct ImplCursorData
      31             : {
      32             :     AutoTimer       maTimer;            // Timer
      33             :     Point           maPixPos;           // Pixel-Position
      34             :     Point           maPixRotOff;        // Pixel-Offset-Position
      35             :     Size            maPixSize;          // Pixel-Size
      36             :     long            mnPixSlant;         // Pixel-Slant
      37             :     short           mnOrientation;      // Pixel-Orientation
      38             :     unsigned char   mnDirection;        // indicates writing direction
      39             :     sal_uInt16          mnStyle;            // Cursor-Style
      40             :     bool            mbCurVisible;       // Ist Cursor aktuell sichtbar
      41             :     Window*         mpWindow;           // Zugeordnetes Windows
      42             : };
      43             : 
      44       45372 : static void ImplCursorInvert( ImplCursorData* pData )
      45             : {
      46       45372 :     Window* pWindow  = pData->mpWindow;
      47       45372 :     bool    bMapMode = pWindow->IsMapModeEnabled();
      48       45372 :     pWindow->EnableMapMode( false );
      49             :     sal_uInt16 nInvertStyle;
      50       45372 :     if ( pData->mnStyle & CURSOR_SHADOW )
      51           0 :         nInvertStyle = INVERT_50;
      52             :     else
      53       45372 :         nInvertStyle = 0;
      54             : 
      55       45372 :     Rectangle aRect( pData->maPixPos, pData->maPixSize );
      56       45372 :     if ( pData->mnDirection || pData->mnOrientation || pData->mnPixSlant )
      57             :     {
      58          16 :         Polygon aPoly( aRect );
      59          16 :         if( aPoly.GetSize() == 5 )
      60             :         {
      61          16 :             aPoly[1].X() += 1;  // include the right border
      62          16 :             aPoly[2].X() += 1;
      63          16 :             if ( pData->mnPixSlant )
      64             :             {
      65           0 :                 Point aPoint = aPoly.GetPoint( 0 );
      66           0 :                 aPoint.X() += pData->mnPixSlant;
      67           0 :                 aPoly.SetPoint( aPoint, 0 );
      68           0 :                 aPoly.SetPoint( aPoint, 4 );
      69           0 :                 aPoint = aPoly.GetPoint( 1 );
      70           0 :                 aPoint.X() += pData->mnPixSlant;
      71           0 :                 aPoly.SetPoint( aPoint, 1 );
      72             :             }
      73             : 
      74             :             // apply direction flag after slant to use the correct shape
      75          16 :             if ( pData->mnDirection )
      76             :             {
      77          16 :                 Point pAry[7];
      78          16 :                 int delta = 3*aRect.getWidth()+1;
      79          16 :                 if( pData->mnDirection == CURSOR_DIRECTION_LTR )
      80             :                 {
      81             :                     // left-to-right
      82          16 :                     pAry[0] = aPoly.GetPoint( 0 );
      83          16 :                     pAry[1] = aPoly.GetPoint( 1 );
      84          16 :                     pAry[2] = pAry[1];
      85          16 :                     pAry[2].X() += delta;
      86          16 :                     pAry[3] =  pAry[1];
      87          16 :                     pAry[3].Y() += delta;
      88          16 :                     pAry[4] = aPoly.GetPoint( 2 );
      89          16 :                     pAry[5] = aPoly.GetPoint( 3 );
      90          16 :                     pAry[6] = aPoly.GetPoint( 4 );
      91             :                 }
      92           0 :                 else if( pData->mnDirection == CURSOR_DIRECTION_RTL )
      93             :                 {
      94             :                     // right-to-left
      95           0 :                     pAry[0] = aPoly.GetPoint( 0 );
      96           0 :                     pAry[1] = aPoly.GetPoint( 1 );
      97           0 :                     pAry[2] = aPoly.GetPoint( 2 );
      98           0 :                     pAry[3] = aPoly.GetPoint( 3 );
      99           0 :                     pAry[4] = pAry[0];
     100           0 :                     pAry[4].Y() += delta;
     101           0 :                     pAry[5] =  pAry[0];
     102           0 :                     pAry[5].X() -= delta;
     103           0 :                     pAry[6] = aPoly.GetPoint( 4 );
     104             :                 }
     105          16 :                 aPoly = Polygon( 7, pAry);
     106             :             }
     107             : 
     108          16 :             if ( pData->mnOrientation )
     109           0 :                 aPoly.Rotate( pData->maPixRotOff, pData->mnOrientation );
     110          16 :             pWindow->Invert( aPoly, nInvertStyle );
     111          16 :         }
     112             :     }
     113             :     else
     114       45356 :         pWindow->Invert( aRect, nInvertStyle );
     115       45372 :     pWindow->EnableMapMode( bMapMode );
     116       45372 : }
     117             : 
     118       22686 : void Cursor::ImplDraw()
     119             : {
     120       22686 :     if ( mpData && mpData->mpWindow && !mpData->mbCurVisible )
     121             :     {
     122             :         // SAL_DEBUG("Cursor::ImplDraw");
     123       22686 :         Window* pWindow         = mpData->mpWindow;
     124       22686 :         mpData->maPixPos        = pWindow->LogicToPixel( maPos );
     125       22686 :         mpData->maPixSize       = pWindow->LogicToPixel( maSize );
     126       22686 :         mpData->mnPixSlant      = pWindow->LogicToPixel( Size( mnSlant, 0 ) ).Width();
     127       22686 :         mpData->mnOrientation   = mnOrientation;
     128       22686 :         mpData->mnDirection     = mnDirection;
     129             : 
     130             :         // correct the position with the offset
     131       22686 :         mpData->maPixRotOff = mpData->maPixPos;
     132             : 
     133             :         // use width (as set in Settings) if size is 0,
     134       22686 :         if ( !mpData->maPixSize.Width() )
     135       22633 :             mpData->maPixSize.Width() = pWindow->GetSettings().GetStyleSettings().GetCursorSize();
     136             : 
     137             :         // calculate output area and display
     138       22686 :         ImplCursorInvert( mpData );
     139       22686 :         mpData->mbCurVisible = true;
     140             :     }
     141       22686 : }
     142             : 
     143       22686 : void Cursor::ImplRestore()
     144             : {
     145       22686 :     if ( mpData && mpData->mbCurVisible )
     146             :     {
     147             :         // SAL_DEBUG("Cursor::ImplRestore");
     148       22686 :         ImplCursorInvert( mpData );
     149       22686 :         mpData->mbCurVisible = false;
     150             :     }
     151       22686 : }
     152             : 
     153       57591 : void Cursor::ImplDoShow( bool bDrawDirect, bool bRestore )
     154             : {
     155       57591 :     if ( mbVisible )
     156             :     {
     157             :         Window* pWindow;
     158       45319 :         if ( mpWindow )
     159           0 :             pWindow = mpWindow;
     160             :         else
     161             :         {
     162             :             // show the cursor, if there is an active window and the cursor
     163             :             // has been selected in this window
     164       45319 :             pWindow = Application::GetFocusWindow();
     165       45319 :             if ( !pWindow || (pWindow->mpWindowImpl->mpCursor != this) || pWindow->mpWindowImpl->mbInPaint
     166       22168 :                 || !pWindow->mpWindowImpl->mpFrameData->mbHasFocus )
     167       23151 :                 pWindow = NULL;
     168             :         }
     169             : 
     170       45319 :         if ( pWindow )
     171             :         {
     172       22168 :             if ( !mpData )
     173             :             {
     174        1545 :                 mpData = new ImplCursorData;
     175        1545 :                 mpData->mbCurVisible = false;
     176        1545 :                 mpData->maTimer.SetTimeoutHdl( LINK( this, Cursor, ImplTimerHdl ) );
     177             :             }
     178             : 
     179       22168 :             mpData->mpWindow    = pWindow;
     180       22168 :             mpData->mnStyle     = mnStyle;
     181       22168 :             if ( bDrawDirect || bRestore )
     182       22168 :                 ImplDraw();
     183             : 
     184       22168 :             if ( !mpWindow && ! ( ! bDrawDirect && mpData->maTimer.IsActive()) )
     185             :             {
     186       22168 :                 mpData->maTimer.SetTimeout( pWindow->GetSettings().GetStyleSettings().GetCursorBlinkTime() );
     187       22168 :                 if ( mpData->maTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME )
     188           0 :                     mpData->maTimer.Start();
     189       22168 :                 else if ( !mpData->mbCurVisible )
     190           0 :                     ImplDraw();
     191             :             }
     192             :         }
     193             :     }
     194       57591 : }
     195             : 
     196       55161 : bool Cursor::ImplDoHide( bool bSuspend )
     197             : {
     198       55161 :     bool bWasCurVisible = false;
     199       55161 :     if ( mpData && mpData->mpWindow )
     200             :     {
     201       24394 :         bWasCurVisible = mpData->mbCurVisible;
     202       24394 :         if ( mpData->mbCurVisible )
     203       22168 :             ImplRestore();
     204             : 
     205       24394 :         if ( !bSuspend )
     206             :         {
     207       21072 :             mpData->maTimer.Stop();
     208       21072 :             mpData->mpWindow = NULL;
     209             :         }
     210             :     }
     211       55161 :     return bWasCurVisible;
     212             : }
     213             : 
     214       46278 : void Cursor::ImplShow( bool bDrawDirect )
     215             : {
     216       46278 :     ImplDoShow( bDrawDirect, false );
     217       46278 : }
     218             : 
     219       44056 : void Cursor::ImplHide( bool i_bStopTimer )
     220             : {
     221             :     assert( i_bStopTimer );
     222       44056 :     ImplDoHide( !i_bStopTimer );
     223       44056 : }
     224             : 
     225       11313 : void Cursor::ImplResume( bool bRestore )
     226             : {
     227       11313 :     ImplDoShow( false, bRestore );
     228       11313 : }
     229             : 
     230       11105 : bool Cursor::ImplSuspend()
     231             : {
     232       11105 :     return ImplDoHide( true );
     233             : }
     234             : 
     235       67492 : void Cursor::ImplNew()
     236             : {
     237       67492 :     if ( mbVisible && mpData && mpData->mpWindow )
     238             :     {
     239         518 :         if ( mpData->mbCurVisible )
     240         518 :             ImplRestore();
     241             : 
     242         518 :         ImplDraw();
     243         518 :         if ( !mpWindow )
     244             :         {
     245         518 :             if ( mpData->maTimer.GetTimeout() != STYLE_CURSOR_NOBLINKTIME )
     246           0 :                 mpData->maTimer.Start();
     247             :         }
     248             :     }
     249       67492 : }
     250             : 
     251           0 : IMPL_LINK_NOARG(Cursor, ImplTimerHdl)
     252             : {
     253           0 :     if ( mpData->mbCurVisible )
     254           0 :         ImplRestore();
     255             :     else
     256           0 :         ImplDraw();
     257           0 :     return 0;
     258             : }
     259             : 
     260        8416 : Cursor::Cursor()
     261             : {
     262        8416 :     mpData          = NULL;
     263        8416 :     mpWindow        = NULL;
     264        8416 :     mnSlant         = 0;
     265        8416 :     mnOrientation   = 0;
     266        8416 :     mnDirection     = 0;
     267        8416 :     mnStyle         = 0;
     268        8416 :     mbVisible       = false;
     269        8416 : }
     270             : 
     271           0 : Cursor::Cursor( const Cursor& rCursor ) :
     272             :     maSize( rCursor.maSize ),
     273           0 :     maPos( rCursor.maPos )
     274             : {
     275           0 :     mpData          = NULL;
     276           0 :     mpWindow        = NULL;
     277           0 :     mnSlant         = rCursor.mnSlant;
     278           0 :     mnOrientation   = rCursor.mnOrientation;
     279           0 :     mnDirection     = rCursor.mnDirection;
     280           0 :     mnStyle         = 0;
     281           0 :     mbVisible       = rCursor.mbVisible;
     282           0 : }
     283             : 
     284        8398 : Cursor::~Cursor()
     285             : {
     286        8398 :     if ( mpData )
     287             :     {
     288        1545 :         if ( mpData->mbCurVisible )
     289           0 :             ImplRestore();
     290             : 
     291        1545 :         delete mpData;
     292             :     }
     293        8398 : }
     294             : 
     295           0 : void Cursor::SetStyle( sal_uInt16 nStyle )
     296             : {
     297           0 :     if ( mnStyle != nStyle )
     298             :     {
     299           0 :         mnStyle = nStyle;
     300           0 :         ImplNew();
     301             :     }
     302           0 : }
     303             : 
     304       37397 : void Cursor::Show()
     305             : {
     306       37397 :     if ( !mbVisible )
     307             :     {
     308       36326 :         mbVisible = true;
     309       36326 :         ImplShow();
     310             :     }
     311       37397 : }
     312             : 
     313       36362 : void Cursor::Hide()
     314             : {
     315       36362 :     if ( mbVisible )
     316             :     {
     317       34175 :         mbVisible = false;
     318       34175 :         ImplHide( true );
     319             :     }
     320       36362 : }
     321             : 
     322           0 : void Cursor::SetWindow( Window* pWindow )
     323             : {
     324           0 :     if ( mpWindow != pWindow )
     325             :     {
     326           0 :         mpWindow = pWindow;
     327           0 :         ImplNew();
     328             :     }
     329           0 : }
     330             : 
     331       33999 : void Cursor::SetPos( const Point& rPoint )
     332             : {
     333       33999 :     if ( maPos != rPoint )
     334             :     {
     335        6677 :         maPos = rPoint;
     336        6677 :         ImplNew();
     337             :     }
     338       33999 : }
     339             : 
     340       33997 : void Cursor::SetSize( const Size& rSize )
     341             : {
     342       33997 :     if ( maSize != rSize )
     343             :     {
     344        5481 :         maSize = rSize;
     345        5481 :         ImplNew();
     346             :     }
     347       33997 : }
     348             : 
     349        1732 : void Cursor::SetWidth( long nNewWidth )
     350             : {
     351        1732 :     if ( maSize.Width() != nNewWidth )
     352             :     {
     353           0 :         maSize.Width() = nNewWidth;
     354           0 :         ImplNew();
     355             :     }
     356        1732 : }
     357             : 
     358       30965 : void Cursor::SetOrientation( short nNewOrientation )
     359             : {
     360       30965 :     if ( mnOrientation != nNewOrientation )
     361             :     {
     362           0 :         mnOrientation = nNewOrientation;
     363           0 :         ImplNew();
     364             :     }
     365       30965 : }
     366             : 
     367       30979 : void Cursor::SetDirection( unsigned char nNewDirection )
     368             : {
     369       30979 :     if ( mnDirection != nNewDirection )
     370             :     {
     371          27 :         mnDirection = nNewDirection;
     372          27 :         ImplNew();
     373             :     }
     374       30979 : }
     375             : 
     376           0 : Cursor& Cursor::operator=( const Cursor& rCursor )
     377             : {
     378           0 :     maPos           = rCursor.maPos;
     379           0 :     maSize          = rCursor.maSize;
     380           0 :     mnSlant         = rCursor.mnSlant;
     381           0 :     mnOrientation   = rCursor.mnOrientation;
     382           0 :     mnDirection     = rCursor.mnDirection;
     383           0 :     mbVisible       = rCursor.mbVisible;
     384           0 :     ImplNew();
     385             : 
     386           0 :     return *this;
     387             : }
     388             : 
     389           0 : bool Cursor::operator==( const Cursor& rCursor ) const
     390             : {
     391             :     return
     392           0 :         ((maPos         == rCursor.maPos)           &&
     393           0 :          (maSize        == rCursor.maSize)          &&
     394           0 :          (mnSlant       == rCursor.mnSlant)         &&
     395           0 :          (mnOrientation == rCursor.mnOrientation)   &&
     396           0 :          (mnDirection   == rCursor.mnDirection)     &&
     397           0 :          (mbVisible     == rCursor.mbVisible))
     398             :         ;
     399             : }
     400             : 
     401             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10