LCOV - code coverage report
Current view: top level - vcl/source/window - accmgr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 105 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 5 0.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 <tools/debug.hxx>
      21             : 
      22             : #include <accel.h>
      23             : #include <vcl/accel.hxx>
      24             : #include <accmgr.hxx>
      25             : 
      26           0 : ImplAccelManager::~ImplAccelManager()
      27             : {
      28           0 :     delete mpAccelList;
      29           0 :     delete mpSequenceList;
      30           0 : }
      31             : 
      32           0 : bool ImplAccelManager::InsertAccel( Accelerator* pAccel )
      33             : {
      34           0 :     if ( !mpAccelList ) {
      35           0 :         mpAccelList = new ImplAccelList;
      36             :     } else {
      37           0 :         for ( size_t i = 0, n = mpAccelList->size(); i < n; ++i ) {
      38           0 :             if ( (*mpAccelList)[ i ] == pAccel ) {
      39           0 :                 return false;
      40             :             }
      41             :         }
      42             :     }
      43             : 
      44           0 :     mpAccelList->insert( mpAccelList->begin(), pAccel );
      45           0 :     return true;
      46             : }
      47             : 
      48           0 : void ImplAccelManager::RemoveAccel( Accelerator* pAccel )
      49             : {
      50             :     // do we have a list ?
      51           0 :     if ( !mpAccelList )
      52           0 :         return;
      53             : 
      54             :     //e.g. #i90599#. Someone starts typing a sequence in a dialog, but doesn't
      55             :     //end it, and then closes the dialog, deleting the accelerators. So if
      56             :     //we're removing an accelerator that a sub-accelerator which is in the
      57             :     //sequence list, throw away the entire sequence
      58           0 :     if ( mpSequenceList ) {
      59           0 :         for (sal_uInt16 i = 0; i < pAccel->GetItemCount(); ++i) {
      60           0 :             Accelerator* pSubAccel = pAccel->GetAccel( pAccel->GetItemId(i) );
      61           0 :             for ( size_t j = 0, n = mpSequenceList->size(); j < n; ++j ) {
      62           0 :                 if ( (*mpSequenceList)[ j ] == pSubAccel ) {
      63           0 :                     EndSequence( true );
      64           0 :                     i = pAccel->GetItemCount();
      65           0 :                     break;
      66             :                 }
      67             :             }
      68             :         }
      69             :     }
      70             : 
      71             :     // throw it away
      72           0 :     for ( ImplAccelList::iterator it = mpAccelList->begin();
      73           0 :           it != mpAccelList->end();
      74             :           ++it
      75             :     ) {
      76           0 :         if ( *it == pAccel ) {
      77           0 :             mpAccelList->erase( it );
      78           0 :             break;
      79             :         }
      80             :     }
      81             : }
      82             : 
      83           0 : void ImplAccelManager::EndSequence( bool bCancel )
      84             : {
      85             :     // are we in a list ?
      86           0 :     if ( !mpSequenceList )
      87           0 :         return;
      88             : 
      89             :     // call all deactivate-handler of the accelerators in the list
      90           0 :     for ( size_t i = 0, n = mpSequenceList->size(); i < n; ++i )
      91             :     {
      92           0 :         Accelerator* pTempAccel = (*mpSequenceList)[ i ];
      93           0 :         bool bDel = false;
      94           0 :         pTempAccel->mbIsCancel = bCancel;
      95           0 :         pTempAccel->mpDel = &bDel;
      96           0 :         pTempAccel->Deactivate();
      97           0 :         if ( !bDel )
      98             :         {
      99           0 :             pTempAccel->mbIsCancel = false;
     100           0 :             pTempAccel->mpDel = NULL;
     101             :         }
     102             :     }
     103             : 
     104             :     // delete sequence-list
     105           0 :     delete mpSequenceList;
     106           0 :     mpSequenceList = NULL;
     107             : }
     108             : 
     109           0 : bool ImplAccelManager::IsAccelKey( const vcl::KeyCode& rKeyCode, sal_uInt16 nRepeat )
     110             : {
     111             :     Accelerator* pAccel;
     112             : 
     113             :     // do we have accelerators ??
     114           0 :     if ( !mpAccelList )
     115           0 :         return false;
     116           0 :     if ( mpAccelList->empty() )
     117           0 :         return false;
     118             : 
     119             :     // are we in a sequence ?
     120           0 :     if ( mpSequenceList )
     121             :     {
     122           0 :         pAccel = mpSequenceList->empty() ? NULL : (*mpSequenceList)[ 0 ];
     123             : 
     124             :         // not found ?
     125           0 :         if ( !pAccel )
     126             :         {
     127             :             // abort sequence
     128           0 :             FlushAccel();
     129           0 :             return false;
     130             :         }
     131             : 
     132             :         // can the entry be found ?
     133           0 :         ImplAccelEntry* pEntry = pAccel->ImplGetAccelData( rKeyCode );
     134           0 :         if ( pEntry )
     135             :         {
     136           0 :             Accelerator* pNextAccel = pEntry->mpAccel;
     137             : 
     138             :             // is an accelerator coupled ?
     139           0 :             if ( pNextAccel )
     140             :             {
     141             : 
     142           0 :                 mpSequenceList->insert( mpSequenceList->begin(), pNextAccel );
     143             : 
     144             :                 // call Activate-Handler of the new one
     145           0 :                 pNextAccel->Activate();
     146           0 :                 return true;
     147             :             }
     148             :             else
     149             :             {
     150             :                 // it is there already !
     151           0 :                 if ( pEntry->mbEnabled )
     152             :                 {
     153             :                     // stop sequence (first call deactivate-handler)
     154           0 :                     EndSequence();
     155             : 
     156             :                     // set accelerator of the actuel item
     157             :                     // and call the handler
     158           0 :                     bool bDel = false;
     159           0 :                     pAccel->maCurKeyCode    = rKeyCode;
     160           0 :                     pAccel->mnCurId         = pEntry->mnId;
     161           0 :                     pAccel->mnCurRepeat     = nRepeat;
     162           0 :                     pAccel->mpDel           = &bDel;
     163           0 :                     pAccel->Select();
     164             : 
     165             :                     // did the accelerator survive the call
     166           0 :                     if ( !bDel )
     167             :                     {
     168           0 :                         pAccel->maCurKeyCode    = vcl::KeyCode();
     169           0 :                         pAccel->mnCurId         = 0;
     170           0 :                         pAccel->mnCurRepeat     = 0;
     171           0 :                         pAccel->mpDel           = NULL;
     172             :                     }
     173             : 
     174           0 :                     return true;
     175             :                 }
     176             :                 else
     177             :                 {
     178             :                     // stop sequence as the accelerator was disbled
     179             :                     // transfer the key (to the system)
     180           0 :                     FlushAccel();
     181           0 :                     return false;
     182             :                 }
     183             :             }
     184             :         }
     185             :         else
     186             :         {
     187             :             // wrong key => stop sequence
     188           0 :             FlushAccel();
     189           0 :             return false;
     190             :         }
     191             :     }
     192             : 
     193             :     // step through the list of accelerators
     194           0 :     for ( size_t i = 0, n = mpAccelList->size(); i < n; ++i )
     195             :     {
     196           0 :         pAccel = (*mpAccelList)[ i ];
     197             : 
     198             :         // is the entry contained ?
     199           0 :         ImplAccelEntry* pEntry = pAccel->ImplGetAccelData( rKeyCode );
     200           0 :         if ( pEntry )
     201             :         {
     202           0 :             Accelerator* pNextAccel = pEntry->mpAccel;
     203             : 
     204             :             // is an accelerator assigned ?
     205           0 :             if ( pNextAccel )
     206             :             {
     207             : 
     208             :                 // create sequence list
     209           0 :                 mpSequenceList = new ImplAccelList;
     210           0 :                 mpSequenceList->insert( mpSequenceList->begin(), pAccel     );
     211           0 :                 mpSequenceList->insert( mpSequenceList->begin(), pNextAccel );
     212             : 
     213             :                 // call activate-Handler of the new one
     214           0 :                 pNextAccel->Activate();
     215             : 
     216           0 :                 return true;
     217             :             }
     218             :             else
     219             :             {
     220             :                 // already assigned !
     221           0 :                 if ( pEntry->mbEnabled )
     222             :                 {
     223             :                     // first call activate/aeactivate-Handler
     224           0 :                     pAccel->Activate();
     225           0 :                     pAccel->Deactivate();
     226             : 
     227             :                     // define accelerator of the actual item
     228             :                     // and call the handler
     229           0 :                     bool bDel = false;
     230           0 :                     pAccel->maCurKeyCode    = rKeyCode;
     231           0 :                     pAccel->mnCurId         = pEntry->mnId;
     232           0 :                     pAccel->mnCurRepeat     = nRepeat;
     233           0 :                     pAccel->mpDel           = &bDel;
     234           0 :                     pAccel->Select();
     235             : 
     236             :                     // if the accelerator did survive the call
     237           0 :                     if ( !bDel )
     238             :                     {
     239           0 :                         pAccel->maCurKeyCode    = vcl::KeyCode();
     240           0 :                         pAccel->mnCurId         = 0;
     241           0 :                         pAccel->mnCurRepeat     = 0;
     242           0 :                         pAccel->mpDel           = NULL;
     243             :                     }
     244             : 
     245           0 :                     return true;
     246             :                 }
     247             :                 else
     248           0 :                     return false;
     249             :             }
     250             :         }
     251             :     }
     252             : 
     253           0 :     return false;
     254             : }
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11