LCOV - code coverage report
Current view: top level - sw/source/core/text - blink.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 52 80 65.0 %
Date: 2014-04-11 Functions: 7 8 87.5 %
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 "viewsh.hxx"
      21             : #include "rootfrm.hxx"
      22             : #include "txtfrm.hxx"
      23             : #include "blink.hxx"
      24             : #include "porlin.hxx"
      25             : #include "porlay.hxx"
      26             : 
      27             : // Sichtbare Zeit:
      28             : #define BLINK_ON_TIME       2400L
      29             : // Nihct sichtbare Zeit:
      30             : #define BLINK_OFF_TIME      800L
      31             : 
      32             : /*************************************************************************
      33             :  * pBlink points to the instance where blinking portions need to register.
      34             :  * If necessary, it needs to be created by SwBlink.
      35             :  * They are then triggered rhythimcally for a repaint. They can query
      36             :  * for being visible or invisible with IsVisible().
      37             :  *************************************************************************/
      38             : SwBlink *pBlink = NULL;
      39             : 
      40           1 : SwBlink::SwBlink()
      41             : {
      42           1 :     bVisible = true;
      43             :     // Prepare the timer
      44           1 :     aTimer.SetTimeout( BLINK_ON_TIME );
      45           1 :     aTimer.SetTimeoutHdl( LINK(this, SwBlink, Blinker) );
      46           1 : }
      47             : 
      48           2 : SwBlink::~SwBlink( )
      49             : {
      50           1 :     aTimer.Stop();
      51           1 : }
      52             : 
      53             : /*************************************************************************
      54             :  * SwBlink::Blinker (timer):
      55             :  * Toggle visibility flag
      56             :  * Determine the repaint rectangle and invalidate them in their OleShells.
      57             :  *************************************************************************/
      58             : 
      59           6 : IMPL_LINK_NOARG(SwBlink, Blinker)
      60             : {
      61           3 :     bVisible = !bVisible;
      62           3 :     if( bVisible )
      63           1 :         aTimer.SetTimeout( BLINK_ON_TIME );
      64             :     else
      65           2 :         aTimer.SetTimeout( BLINK_OFF_TIME );
      66           3 :     if( !aList.empty() )
      67             :     {
      68             : 
      69           3 :         for( SwBlinkList::iterator it = aList.begin(); it != aList.end(); )
      70             :         {
      71           1 :             const SwBlinkPortion* pTmp = &*it;
      72           2 :             if( pTmp->GetRootFrm() &&
      73           1 :                 ((SwRootFrm*)pTmp->GetRootFrm())->GetCurrShell() )
      74             :             {
      75           1 :                 ++it;
      76             : 
      77           1 :                 Point aPos = pTmp->GetPos();
      78             :                 long nWidth, nHeight;
      79           1 :                 switch ( pTmp->GetDirection() )
      80             :                 {
      81             :                     case 900:
      82           0 :                         aPos.X() -= pTmp->GetPortion()->GetAscent();
      83           0 :                         aPos.Y() -= pTmp->GetPortion()->Width();
      84           0 :                         nWidth = pTmp->GetPortion()->SvLSize().Height();
      85           0 :                         nHeight = pTmp->GetPortion()->SvLSize().Width();
      86           0 :                         break;
      87             :                     case 1800:
      88           0 :                         aPos.Y() -= pTmp->GetPortion()->Height() -
      89           0 :                                     pTmp->GetPortion()->GetAscent();
      90           0 :                         aPos.X() -= pTmp->GetPortion()->Width();
      91           0 :                         nWidth = pTmp->GetPortion()->SvLSize().Width();
      92           0 :                         nHeight = pTmp->GetPortion()->SvLSize().Height();
      93           0 :                         break;
      94             :                     case 2700:
      95           0 :                         aPos.X() -= pTmp->GetPortion()->Height() -
      96           0 :                                     pTmp->GetPortion()->GetAscent();
      97           0 :                         nWidth = pTmp->GetPortion()->SvLSize().Height();
      98           0 :                         nHeight = pTmp->GetPortion()->SvLSize().Width();
      99           0 :                         break;
     100             :                     default:
     101           1 :                         aPos.Y() -= pTmp->GetPortion()->GetAscent();
     102           1 :                         nWidth = pTmp->GetPortion()->SvLSize().Width();
     103           1 :                         nHeight = pTmp->GetPortion()->SvLSize().Height();
     104             :                 }
     105             : 
     106           1 :                 Rectangle aRefresh( aPos, Size( nWidth, nHeight ) );
     107           1 :                 aRefresh.Right() += ( aRefresh.Bottom()- aRefresh.Top() ) / 8;
     108           1 :                 ((SwRootFrm*)pTmp->GetRootFrm())
     109           2 :                     ->GetCurrShell()->InvalidateWindows( aRefresh );
     110             :             }
     111             :             else // Portions without a shell can be removed from the list
     112           0 :                 aList.erase( it );
     113             :         }
     114             :     }
     115             :     else // If the list is empty, the timer can be stopped
     116           2 :         aTimer.Stop();
     117           3 :     return 1;
     118             : }
     119             : 
     120         121 : void SwBlink::Insert( const Point& rPoint, const SwLinePortion* pPor,
     121             :                       const SwTxtFrm *pTxtFrm, sal_uInt16 nDir )
     122             : {
     123         121 :     SwBlinkPortion *pBlinkPor = new SwBlinkPortion( pPor, nDir );
     124             : 
     125         121 :     SwBlinkList::iterator it = aList.find( *pBlinkPor );
     126         121 :     if( it != aList.end()  )
     127             :     {
     128           7 :         (*it).SetPos( rPoint );
     129           7 :         delete pBlinkPor;
     130             :     }
     131             :     else
     132             :     {
     133         114 :         pBlinkPor->SetPos( rPoint );
     134         114 :         pBlinkPor->SetRootFrm( pTxtFrm->getRootFrm() );
     135         114 :         aList.insert( pBlinkPor );
     136         114 :         pTxtFrm->SetBlinkPor();
     137         114 :         if( pPor->IsLayPortion() || pPor->IsParaPortion() )
     138           6 :             ((SwLineLayout*)pPor)->SetBlinking();
     139             : 
     140         114 :         if( !aTimer.IsActive() )
     141           2 :             aTimer.Start();
     142             :     }
     143         121 : }
     144             : 
     145           0 : void SwBlink::Replace( const SwLinePortion* pOld, const SwLinePortion* pNew )
     146             : {
     147             :     // setting direction to 0 because direction does not matter
     148             :     // for this operation
     149           0 :     SwBlinkPortion aBlink( pOld, 0 );
     150           0 :     SwBlinkList::iterator it = aList.find( aBlink );
     151           0 :     if( it != aList.end()  )
     152             :     {
     153           0 :         SwBlinkPortion* aTmp = new SwBlinkPortion( &*it, pNew );
     154           0 :         aList.erase( it );
     155           0 :         aList.insert( aTmp );
     156             :     }
     157           0 : }
     158             : 
     159        2153 : void SwBlink::Delete( const SwLinePortion* pPor )
     160             : {
     161             :     // setting direction to 0 because direction does not matter
     162             :     // for this operation
     163        2153 :     SwBlinkPortion aBlink( pPor, 0 );
     164        2153 :     aList.erase( aBlink );
     165        2153 : }
     166             : 
     167          36 : void SwBlink::FrmDelete( const SwRootFrm* pRoot )
     168             : {
     169          72 :     for( SwBlinkList::iterator it = aList.begin(); it != aList.end(); )
     170             :     {
     171           0 :         if( pRoot == (*it).GetRootFrm() )
     172           0 :             aList.erase( it++ );
     173             :         else
     174           0 :             ++it;
     175             :     }
     176          36 : }
     177             : 
     178             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10