LCOV - code coverage report
Current view: top level - vcl/source/window - keycod.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 21 43 48.8 %
Date: 2015-06-13 12:38:46 Functions: 3 5 60.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 <salinst.hxx>
      21             : #include <salframe.hxx>
      22             : #include <svdata.hxx>
      23             : 
      24             : #include <vcl/window.hxx>
      25             : #include <vcl/keycod.hxx>
      26             : 
      27             : #include <tools/rc.h>
      28             : 
      29             : static const sal_uInt16 aImplKeyFuncTab[(static_cast<int>(KeyFuncType::FRONT)+1)*4] =
      30             : {
      31             :     0, 0, 0, 0,                                                    // KeyFuncType::DONTKNOW
      32             :     KEY_N | KEY_MOD1, 0, 0, 0,                                     // KeyFuncType::NEW
      33             :     KEY_O | KEY_MOD1, KEY_OPEN, 0, 0,                              // KeyFuncType::OPEN
      34             :     KEY_S | KEY_MOD1, 0, 0, 0,                                     // KeyFuncType::SAVE
      35             :     KEY_S | KEY_SHIFT | KEY_MOD1, 0, 0, 0,                         // KeyFuncType::SAVEAS
      36             :     KEY_P | KEY_MOD1, 0, 0, 0,                                     // KeyFuncType::PRINT
      37             :     KEY_W | KEY_MOD1, KEY_F4 | KEY_MOD1, 0, 0,                     // KeyFuncType::CLOSE
      38             :     KEY_Q | KEY_MOD1, KEY_F4 | KEY_MOD2, 0, 0,                     // KeyFuncType::QUIT
      39             :     KEY_X | KEY_MOD1, KEY_DELETE | KEY_SHIFT, KEY_CUT, 0,          // KeyFuncType::CUT
      40             :     KEY_C | KEY_MOD1, KEY_INSERT | KEY_MOD1, KEY_COPY, 0,          // KeyFuncType::COPY
      41             :     KEY_V | KEY_MOD1, KEY_INSERT | KEY_SHIFT, KEY_PASTE, 0,        // KeyFuncType::PASTE
      42             :     KEY_Z | KEY_MOD1, KEY_BACKSPACE | KEY_MOD2, KEY_UNDO, 0,       // KeyFuncType::UNDO
      43             :     KEY_Y | KEY_MOD1, KEY_UNDO | KEY_SHIFT, 0, 0,                  // KeyFuncType::REDO
      44             :     KEY_DELETE, 0, 0, 0,                                           // KeyFuncType::DELETE
      45             :     KEY_REPEAT, 0, 0, 0,                                           // KeyFuncType::REPEAT
      46             :     KEY_F | KEY_MOD1, KEY_FIND, 0, 0,                              // KeyFuncType::FIND
      47             :     KEY_F | KEY_SHIFT | KEY_MOD1, KEY_SHIFT | KEY_FIND, 0, 0,      // KeyFuncType::FINDBACKWARD
      48             :     KEY_RETURN | KEY_MOD2, 0, 0, 0,                                // KeyFuncType::PROPERTIES
      49             :     0, 0, 0, 0                                                     // KeyFuncType::FRONT
      50             : };
      51             : 
      52          17 : bool ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 )
      53             : {
      54          17 :     size_t nIndex = static_cast<size_t>(eFunc);
      55          17 :     nIndex *= 4;
      56             : 
      57             :     assert(nIndex + 3 < SAL_N_ELEMENTS(aImplKeyFuncTab) && "bad key code index");
      58          17 :     if (nIndex + 3  >= SAL_N_ELEMENTS(aImplKeyFuncTab))
      59             :     {
      60           0 :         rCode1 = rCode2 = rCode3 = rCode4 = 0;
      61           0 :         return false;
      62             :     }
      63             : 
      64          17 :     rCode1 = aImplKeyFuncTab[nIndex];
      65          17 :     rCode2 = aImplKeyFuncTab[nIndex+1];
      66          17 :     rCode3 = aImplKeyFuncTab[nIndex+2];
      67          17 :     rCode4 = aImplKeyFuncTab[nIndex+3];
      68          17 :     return true;
      69             : }
      70             : 
      71           0 : vcl::KeyCode::KeyCode( KeyFuncType eFunction )
      72             : {
      73             :     sal_uInt16 nDummy;
      74           0 :     ImplGetKeyCode( eFunction, nKeyCodeAndModifiers, nDummy, nDummy, nDummy );
      75           0 :     eFunc = eFunction;
      76           0 : }
      77             : 
      78           0 : vcl::KeyCode::KeyCode( const ResId& rResId )
      79             :     : nKeyCodeAndModifiers(0)
      80           0 :     , eFunc(KeyFuncType::DONTKNOW)
      81             : {
      82           0 :     rResId.SetRT( RSC_KEYCODE );
      83             : 
      84           0 :     ResMgr* pResMgr = rResId.GetResMgr();
      85           0 :     if ( pResMgr && pResMgr->GetResource( rResId ) )
      86             :     {
      87           0 :         pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
      88             : 
      89           0 :         sal_uLong nKeyCode  = pResMgr->ReadLong();
      90           0 :         sal_uLong nModifier = pResMgr->ReadLong();
      91           0 :         sal_uLong nKeyFunc  = pResMgr->ReadLong();
      92             : 
      93           0 :         eFunc = (KeyFuncType)nKeyFunc;
      94           0 :         if ( eFunc != KeyFuncType::DONTKNOW )
      95             :         {
      96             :             sal_uInt16 nDummy;
      97           0 :             ImplGetKeyCode( eFunc, nKeyCodeAndModifiers, nDummy, nDummy, nDummy );
      98             :         }
      99             :         else
     100           0 :             nKeyCodeAndModifiers = sal::static_int_cast<sal_uInt16>(nKeyCode | nModifier);
     101             :     }
     102           0 : }
     103             : 
     104       43192 : OUString vcl::KeyCode::GetName( vcl::Window* pWindow ) const
     105             : {
     106       43192 :     if ( !pWindow )
     107       43192 :         pWindow = ImplGetDefaultWindow();
     108       43192 :     return pWindow ? pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) : "";
     109             : }
     110             : 
     111          11 : KeyFuncType vcl::KeyCode::GetFunction() const
     112             : {
     113          11 :     if ( eFunc != KeyFuncType::DONTKNOW )
     114           0 :         return eFunc;
     115             : 
     116          11 :     sal_uInt16 nCompCode = GetModifier() | GetCode();
     117          11 :     if ( nCompCode )
     118             :     {
     119          18 :         for ( sal_uInt16 i = (sal_uInt16)KeyFuncType::NEW; i < (sal_uInt16)KeyFuncType::FRONT; i++ )
     120             :         {
     121             :             sal_uInt16 nKeyCode1;
     122             :             sal_uInt16 nKeyCode2;
     123             :             sal_uInt16 nKeyCode3;
     124             :             sal_uInt16 nKeyCode4;
     125          17 :             ImplGetKeyCode( (KeyFuncType)i, nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
     126          17 :             if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
     127           0 :                 return (KeyFuncType)i;
     128             :         }
     129             :     }
     130             : 
     131          11 :     return KeyFuncType::DONTKNOW;
     132             : }
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11