LCOV - code coverage report
Current view: top level - sc/source/ui/docshell - autostyl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 83 0.0 %
Date: 2012-08-25 Functions: 0 23 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 180 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <time.h>
      31                 :            : 
      32                 :            : #include "attrib.hxx"
      33                 :            : #include "autostyl.hxx"
      34                 :            : #include "docsh.hxx"
      35                 :            : #include "sc.hrc"
      36                 :            : 
      37         [ #  # ]:          0 : struct ScAutoStyleInitData
      38                 :            : {
      39                 :            :     ScRange aRange;
      40                 :            :     String  aStyle1;
      41                 :            :     sal_uLong   nTimeout;
      42                 :            :     String  aStyle2;
      43                 :            : 
      44                 :          0 :     ScAutoStyleInitData( const ScRange& rR, const String& rSt1, sal_uLong nT, const String& rSt2 ) :
      45         [ #  # ]:          0 :         aRange(rR), aStyle1(rSt1), nTimeout(nT), aStyle2(rSt2) {}
      46                 :            : };
      47                 :            : 
      48                 :          0 : struct ScAutoStyleData
      49                 :            : {
      50                 :            :     sal_uLong   nTimeout;
      51                 :            :     ScRange aRange;
      52                 :            :     String  aStyle;
      53                 :            : 
      54                 :          0 :     ScAutoStyleData( sal_uLong nT, const ScRange& rR, const String& rT ) :
      55                 :          0 :         nTimeout(nT), aRange(rR), aStyle(rT) {}
      56                 :            : };
      57                 :            : 
      58                 :          0 : inline sal_uLong TimeNow()          // Sekunden
      59                 :            : {
      60                 :          0 :     return (sal_uLong) time(0);
      61                 :            : }
      62                 :            : 
      63                 :            : namespace {
      64                 :            : 
      65                 :          0 : class FindByRange : public ::std::unary_function<ScAutoStyleData, bool>
      66                 :            : {
      67                 :            :     ScRange maRange;
      68                 :            : public:
      69                 :          0 :     FindByRange(const ScRange& r) : maRange(r) {}
      70                 :          0 :     bool operator() (const ScAutoStyleData& rData) const { return rData.aRange == maRange; }
      71                 :            : };
      72                 :            : 
      73                 :            : class FindByTimeout : public ::std::unary_function<ScAutoStyleData, bool>
      74                 :            : {
      75                 :            :     sal_uLong mnTimeout;
      76                 :            : public:
      77                 :          0 :     FindByTimeout(sal_uLong n) : mnTimeout(n) {}
      78                 :          0 :     bool operator() (const ScAutoStyleData& rData) const { return rData.nTimeout >= mnTimeout; }
      79                 :            : };
      80                 :            : 
      81                 :            : struct FindNonZeroTimeout : public ::std::unary_function<ScAutoStyleData, bool>
      82                 :            : {
      83                 :          0 :     bool operator() (const ScAutoStyleData& rData) const
      84                 :            :     {
      85                 :          0 :         return rData.nTimeout != 0;
      86                 :            :     }
      87                 :            : };
      88                 :            : 
      89                 :            : }
      90                 :            : 
      91                 :          0 : ScAutoStyleList::ScAutoStyleList(ScDocShell* pShell) :
      92 [ #  # ][ #  # ]:          0 :     pDocSh( pShell )
                 [ #  # ]
      93                 :            : {
      94         [ #  # ]:          0 :     aTimer.SetTimeoutHdl( LINK( this, ScAutoStyleList, TimerHdl ) );
      95         [ #  # ]:          0 :     aInitTimer.SetTimeoutHdl( LINK( this, ScAutoStyleList, InitHdl ) );
      96         [ #  # ]:          0 :     aInitTimer.SetTimeout( 0 );
      97                 :          0 : }
      98                 :            : 
      99 [ #  # ][ #  # ]:          0 : ScAutoStyleList::~ScAutoStyleList()
                 [ #  # ]
     100                 :            : {
     101                 :          0 : }
     102                 :            : 
     103                 :            : //  initial short delay (asynchronous call)
     104                 :            : 
     105                 :          0 : void ScAutoStyleList::AddInitial( const ScRange& rRange, const String& rStyle1,
     106                 :            :                                     sal_uLong nTimeout, const String& rStyle2 )
     107                 :            : {
     108         [ #  # ]:          0 :     aInitials.push_back(new ScAutoStyleInitData( rRange, rStyle1, nTimeout, rStyle2 ));
     109                 :          0 :     aInitTimer.Start();
     110                 :          0 : }
     111                 :            : 
     112                 :          0 : IMPL_LINK_NOARG(ScAutoStyleList, InitHdl)
     113                 :            : {
     114         [ #  # ]:          0 :     boost::ptr_vector<ScAutoStyleInitData>::iterator iter;
     115 [ #  # ][ #  # ]:          0 :     for (iter = aInitials.begin(); iter != aInitials.end(); ++iter)
         [ #  # ][ #  # ]
                 [ #  # ]
     116                 :            :     {
     117                 :            :         //  apply first style immediately
     118 [ #  # ][ #  # ]:          0 :         pDocSh->DoAutoStyle(iter->aRange,iter->aStyle1);
                 [ #  # ]
     119                 :            : 
     120                 :            :         //  add second style to list
     121 [ #  # ][ #  # ]:          0 :         if (iter->nTimeout)
     122 [ #  # ][ #  # ]:          0 :             AddEntry(iter->nTimeout,iter->aRange,iter->aStyle2 );
         [ #  # ][ #  # ]
     123                 :            :     }
     124                 :            : 
     125         [ #  # ]:          0 :     aInitials.clear();
     126                 :            : 
     127                 :          0 :     return 0;
     128                 :            : }
     129                 :            : 
     130                 :          0 : void ScAutoStyleList::AddEntry( sal_uLong nTimeout, const ScRange& rRange, const String& rStyle )
     131                 :            : {
     132         [ #  # ]:          0 :     aTimer.Stop();
     133                 :          0 :     sal_uLong nNow = TimeNow();
     134                 :            : 
     135                 :            :     // Remove the first item with the same range.
     136                 :            :     ::boost::ptr_vector<ScAutoStyleData>::iterator itr =
     137 [ #  # ][ #  # ]:          0 :         ::std::find_if(aEntries.begin(), aEntries.end(), FindByRange(rRange));
                 [ #  # ]
     138                 :            : 
     139 [ #  # ][ #  # ]:          0 :     if (itr != aEntries.end())
                 [ #  # ]
     140         [ #  # ]:          0 :         aEntries.erase(itr);
     141                 :            : 
     142                 :            :     //  Timeouts von allen Eintraegen anpassen
     143                 :            : 
     144 [ #  # ][ #  # ]:          0 :     if (!aEntries.empty() && nNow != nTimerStart)
                 [ #  # ]
     145                 :            :     {
     146                 :            :         OSL_ENSURE(nNow>nTimerStart, "Zeit laeuft rueckwaerts?");
     147         [ #  # ]:          0 :         AdjustEntries((nNow-nTimerStart)*1000);
     148                 :            :     }
     149                 :            : 
     150                 :            :     //  Einfuege-Position suchen
     151                 :            :     boost::ptr_vector<ScAutoStyleData>::iterator iter =
     152 [ #  # ][ #  # ]:          0 :         ::std::find_if(aEntries.begin(), aEntries.end(), FindByTimeout(nTimeout));
                 [ #  # ]
     153                 :            : 
     154 [ #  # ][ #  # ]:          0 :     aEntries.insert(iter,new ScAutoStyleData(nTimeout,rRange,rStyle));
                 [ #  # ]
     155                 :            : 
     156                 :            :     //  abgelaufene ausfuehren, Timer neu starten
     157                 :            : 
     158         [ #  # ]:          0 :     ExecuteEntries();
     159         [ #  # ]:          0 :     StartTimer(nNow);
     160                 :          0 : }
     161                 :            : 
     162                 :          0 : void ScAutoStyleList::AdjustEntries( sal_uLong nDiff )  // Millisekunden
     163                 :            : {
     164         [ #  # ]:          0 :     boost::ptr_vector<ScAutoStyleData>::iterator iter;
     165 [ #  # ][ #  # ]:          0 :     for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
         [ #  # ][ #  # ]
                 [ #  # ]
     166                 :            :     {
     167 [ #  # ][ #  # ]:          0 :         if (iter->nTimeout <= nDiff)
     168         [ #  # ]:          0 :             iter->nTimeout = 0;                 // abgelaufen
     169                 :            :         else
     170         [ #  # ]:          0 :             iter->nTimeout -= nDiff;                // weiterzaehlen
     171                 :            :     }
     172                 :          0 : }
     173                 :            : 
     174                 :          0 : void ScAutoStyleList::ExecuteEntries()
     175                 :            : {
     176                 :            :     // Execute and remove all items with timeout == 0 from the begin position
     177                 :            :     // until the first item with non-zero timeout value.
     178 [ #  # ][ #  # ]:          0 :     ::boost::ptr_vector<ScAutoStyleData>::iterator itr = aEntries.begin(), itrEnd = aEntries.end();
     179 [ #  # ][ #  # ]:          0 :     for (; itr != itrEnd; ++itr)
                 [ #  # ]
     180                 :            :     {
     181 [ #  # ][ #  # ]:          0 :         if (itr->nTimeout)
     182                 :          0 :             break;
     183                 :            : 
     184 [ #  # ][ #  # ]:          0 :         pDocSh->DoAutoStyle(itr->aRange, itr->aStyle);
                 [ #  # ]
     185                 :            :     }
     186                 :            :     // At this point itr should be on the first item with non-zero timeout, or
     187                 :            :     // the end position in case all items have timeout == 0.
     188 [ #  # ][ #  # ]:          0 :     aEntries.erase(aEntries.begin(), itr);
     189                 :          0 : }
     190                 :            : 
     191                 :          0 : void ScAutoStyleList::ExecuteAllNow()
     192                 :            : {
     193         [ #  # ]:          0 :     aTimer.Stop();
     194                 :            : 
     195         [ #  # ]:          0 :     boost::ptr_vector<ScAutoStyleData>::iterator iter;
     196 [ #  # ][ #  # ]:          0 :     for (iter = aEntries.begin(); iter != aEntries.end(); ++iter)
         [ #  # ][ #  # ]
                 [ #  # ]
     197 [ #  # ][ #  # ]:          0 :         pDocSh->DoAutoStyle(iter->aRange,iter->aStyle);
                 [ #  # ]
     198                 :            : 
     199         [ #  # ]:          0 :     aEntries.clear();
     200                 :          0 : }
     201                 :            : 
     202                 :          0 : void ScAutoStyleList::StartTimer( sal_uLong nNow )      // Sekunden
     203                 :            : {
     204                 :            :     // ersten Eintrag mit Timeout != 0 suchen
     205                 :            :     boost::ptr_vector<ScAutoStyleData>::iterator iter =
     206 [ #  # ][ #  # ]:          0 :         ::std::find_if(aEntries.begin(),aEntries.end(), FindNonZeroTimeout());
                 [ #  # ]
     207                 :            : 
     208 [ #  # ][ #  # ]:          0 :     if (iter != aEntries.end())
                 [ #  # ]
     209                 :            :     {
     210 [ #  # ][ #  # ]:          0 :         aTimer.SetTimeout(iter->nTimeout);
     211         [ #  # ]:          0 :         aTimer.Start();
     212                 :            :     }
     213                 :            : 
     214                 :          0 :     nTimerStart = nNow;
     215                 :          0 : }
     216                 :            : 
     217                 :          0 : IMPL_LINK_NOARG(ScAutoStyleList, TimerHdl)
     218                 :            : {
     219                 :          0 :     sal_uLong nNow = TimeNow();
     220                 :          0 :     AdjustEntries(aTimer.GetTimeout());             // eingestellte Wartezeit
     221                 :          0 :     ExecuteEntries();
     222                 :          0 :     StartTimer(nNow);
     223                 :            : 
     224                 :          0 :     return 0;
     225                 :            : }
     226                 :            : 
     227                 :            : 
     228                 :            : 
     229                 :            : 
     230                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10