LCOV - code coverage report
Current view: top level - vcl/source/window - keycod.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 20 40 50.0 %
Date: 2014-04-11 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[(KEYFUNC_FRONT+1)*4] =
      30             : {
      31             :     0, 0, 0, 0,                                                    // KEYFUNC_DONTKNOW
      32             :     KEY_N | KEY_MOD1, 0, 0, 0,                                     // KEYFUNC_NEW
      33             :     KEY_O | KEY_MOD1, KEY_OPEN, 0, 0,                              // KEYFUNC_OPEN
      34             :     KEY_S | KEY_MOD1, 0, 0, 0,                                     // KEYFUNC_SAVE
      35             :     KEY_S | KEY_SHIFT | KEY_MOD1, 0, 0, 0,                         // KEYFUNC_SAVEAS
      36             :     KEY_P | KEY_MOD1, 0, 0, 0,                                     // KEYFUNC_PRINT
      37             :     KEY_W | KEY_MOD1, KEY_F4 | KEY_MOD1, 0, 0,                     // KEYFUNC_CLOSE
      38             :     KEY_Q | KEY_MOD1, KEY_F4 | KEY_MOD2, 0, 0,                     // KEYFUNC_QUIT
      39             :     KEY_X | KEY_MOD1, KEY_DELETE | KEY_SHIFT, KEY_CUT, 0,          // KEYFUNC_CUT
      40             :     KEY_C | KEY_MOD1, KEY_INSERT | KEY_MOD1, KEY_COPY, 0,          // KEYFUNC_COPY
      41             :     KEY_V | KEY_MOD1, KEY_INSERT | KEY_SHIFT, KEY_PASTE, 0,        // KEYFUNC_PASTE
      42             :     KEY_Z | KEY_MOD1, KEY_BACKSPACE | KEY_MOD2, KEY_UNDO, 0,       // KEYFUNC_UNDO
      43             :     KEY_Y | KEY_MOD1, KEY_UNDO | KEY_SHIFT, 0, 0,                  // KEYFUNC_REDO
      44             :     KEY_DELETE, 0, 0, 0,                                           // KEYFUNC_DELETE
      45             :     KEY_REPEAT, 0, 0, 0,                                           // KEYFUNC_REPEAT
      46             :     KEY_F | KEY_MOD1, KEY_FIND, 0, 0,                              // KEYFUNC_FIND
      47             :     KEY_F | KEY_SHIFT | KEY_MOD1, KEY_SHIFT | KEY_FIND, 0, 0,      // KEYFUNC_FINDBACKWARD
      48             :     KEY_RETURN | KEY_MOD2, 0, 0, 0,                                // KEYFUNC_PROPERTIES
      49             :     0, 0, 0, 0                                                     // KEYFUNC_FRONT
      50             : };
      51             : 
      52          17 : void ImplGetKeyCode( KeyFuncType eFunc, sal_uInt16& rCode1, sal_uInt16& rCode2, sal_uInt16& rCode3, sal_uInt16& rCode4 )
      53             : {
      54          17 :     sal_uInt16 nIndex = (sal_uInt16)eFunc;
      55          17 :     nIndex *= 4;
      56          17 :     rCode1 = aImplKeyFuncTab[nIndex];
      57          17 :     rCode2 = aImplKeyFuncTab[nIndex+1];
      58          17 :     rCode3 = aImplKeyFuncTab[nIndex+2];
      59          17 :         rCode4 = aImplKeyFuncTab[nIndex+3];
      60          17 : }
      61             : 
      62           0 : KeyCode::KeyCode( KeyFuncType eFunction )
      63             : {
      64             :     sal_uInt16 nDummy;
      65           0 :     ImplGetKeyCode( eFunction, nCode, nDummy, nDummy, nDummy );
      66           0 :     eFunc = eFunction;
      67           0 : }
      68             : 
      69           0 : KeyCode::KeyCode( const ResId& rResId )
      70             :     : nCode(0)
      71           0 :     , eFunc(KEYFUNC_DONTKNOW)
      72             : {
      73           0 :     rResId.SetRT( RSC_KEYCODE );
      74             : 
      75           0 :     ResMgr* pResMgr = rResId.GetResMgr();
      76           0 :     if ( pResMgr && pResMgr->GetResource( rResId ) )
      77             :     {
      78           0 :         pResMgr->Increment( sizeof( RSHEADER_TYPE ) );
      79             : 
      80           0 :         sal_uLong nKeyCode  = pResMgr->ReadLong();
      81           0 :         sal_uLong nModifier = pResMgr->ReadLong();
      82           0 :         sal_uLong nKeyFunc  = pResMgr->ReadLong();
      83             : 
      84           0 :         eFunc = (KeyFuncType)nKeyFunc;
      85           0 :         if ( eFunc != KEYFUNC_DONTKNOW )
      86             :         {
      87             :             sal_uInt16 nDummy;
      88           0 :             ImplGetKeyCode( eFunc, nCode, nDummy, nDummy, nDummy );
      89             :         }
      90             :         else
      91           0 :             nCode = sal::static_int_cast<sal_uInt16>(nKeyCode | nModifier);
      92             :     }
      93           0 : }
      94             : 
      95       34861 : OUString KeyCode::GetName( Window* pWindow ) const
      96             : {
      97       34861 :     if ( !pWindow )
      98       34861 :         pWindow = ImplGetDefaultWindow();
      99       34861 :     return pWindow ? pWindow->ImplGetFrame()->GetKeyName( GetFullCode() ) : "";
     100             : }
     101             : 
     102           1 : KeyFuncType KeyCode::GetFunction() const
     103             : {
     104           1 :     if ( eFunc != KEYFUNC_DONTKNOW )
     105           0 :         return eFunc;
     106             : 
     107           1 :     sal_uInt16 nCompCode = GetModifier() | GetCode();
     108           1 :     if ( nCompCode )
     109             :     {
     110          18 :         for ( sal_uInt16 i = (sal_uInt16)KEYFUNC_NEW; i < (sal_uInt16)KEYFUNC_FRONT; i++ )
     111             :         {
     112             :             sal_uInt16 nKeyCode1;
     113             :             sal_uInt16 nKeyCode2;
     114             :             sal_uInt16 nKeyCode3;
     115             :                         sal_uInt16 nKeyCode4;
     116          17 :             ImplGetKeyCode( (KeyFuncType)i, nKeyCode1, nKeyCode2, nKeyCode3, nKeyCode4 );
     117          17 :             if ( (nCompCode == nKeyCode1) || (nCompCode == nKeyCode2) || (nCompCode == nKeyCode3) || (nCompCode == nKeyCode4) )
     118           0 :                 return (KeyFuncType)i;
     119             :         }
     120             :     }
     121             : 
     122           1 :     return KEYFUNC_DONTKNOW;
     123             : }
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10