1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir #include <accelerators/keymapping.hxx> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir //_______________________________________________ 33*cdf0e10cSrcweir // own includes 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <macros/generic.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir //_______________________________________________ 38*cdf0e10cSrcweir // interface includes 39*cdf0e10cSrcweir #include <com/sun/star/awt/Key.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //_______________________________________________ 42*cdf0e10cSrcweir // other includes 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir //_______________________________________________ 45*cdf0e10cSrcweir // namespace 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir namespace framework 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir //_______________________________________________ 51*cdf0e10cSrcweir // helper 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir KeyMapping::KeyIdentifierInfo KeyMapping::KeyIdentifierMap[] = 54*cdf0e10cSrcweir { 55*cdf0e10cSrcweir {css::awt::Key::NUM0 , "KEY_0" }, 56*cdf0e10cSrcweir {css::awt::Key::NUM1 , "KEY_1" }, 57*cdf0e10cSrcweir {css::awt::Key::NUM2 , "KEY_2" }, 58*cdf0e10cSrcweir {css::awt::Key::NUM3 , "KEY_3" }, 59*cdf0e10cSrcweir {css::awt::Key::NUM4 , "KEY_4" }, 60*cdf0e10cSrcweir {css::awt::Key::NUM5 , "KEY_5" }, 61*cdf0e10cSrcweir {css::awt::Key::NUM6 , "KEY_6" }, 62*cdf0e10cSrcweir {css::awt::Key::NUM7 , "KEY_7" }, 63*cdf0e10cSrcweir {css::awt::Key::NUM8 , "KEY_8" }, 64*cdf0e10cSrcweir {css::awt::Key::NUM9 , "KEY_9" }, 65*cdf0e10cSrcweir {css::awt::Key::A , "KEY_A" }, 66*cdf0e10cSrcweir {css::awt::Key::B , "KEY_B" }, 67*cdf0e10cSrcweir {css::awt::Key::C , "KEY_C" }, 68*cdf0e10cSrcweir {css::awt::Key::D , "KEY_D" }, 69*cdf0e10cSrcweir {css::awt::Key::E , "KEY_E" }, 70*cdf0e10cSrcweir {css::awt::Key::F , "KEY_F" }, 71*cdf0e10cSrcweir {css::awt::Key::G , "KEY_G" }, 72*cdf0e10cSrcweir {css::awt::Key::H , "KEY_H" }, 73*cdf0e10cSrcweir {css::awt::Key::I , "KEY_I" }, 74*cdf0e10cSrcweir {css::awt::Key::J , "KEY_J" }, 75*cdf0e10cSrcweir {css::awt::Key::K , "KEY_K" }, 76*cdf0e10cSrcweir {css::awt::Key::L , "KEY_L" }, 77*cdf0e10cSrcweir {css::awt::Key::M , "KEY_M" }, 78*cdf0e10cSrcweir {css::awt::Key::N , "KEY_N" }, 79*cdf0e10cSrcweir {css::awt::Key::O , "KEY_O" }, 80*cdf0e10cSrcweir {css::awt::Key::P , "KEY_P" }, 81*cdf0e10cSrcweir {css::awt::Key::Q , "KEY_Q" }, 82*cdf0e10cSrcweir {css::awt::Key::R , "KEY_R" }, 83*cdf0e10cSrcweir {css::awt::Key::S , "KEY_S" }, 84*cdf0e10cSrcweir {css::awt::Key::T , "KEY_T" }, 85*cdf0e10cSrcweir {css::awt::Key::U , "KEY_U" }, 86*cdf0e10cSrcweir {css::awt::Key::V , "KEY_V" }, 87*cdf0e10cSrcweir {css::awt::Key::W , "KEY_W" }, 88*cdf0e10cSrcweir {css::awt::Key::X , "KEY_X" }, 89*cdf0e10cSrcweir {css::awt::Key::Y , "KEY_Y" }, 90*cdf0e10cSrcweir {css::awt::Key::Z , "KEY_Z" }, 91*cdf0e10cSrcweir {css::awt::Key::F1 , "KEY_F1" }, 92*cdf0e10cSrcweir {css::awt::Key::F2 , "KEY_F2" }, 93*cdf0e10cSrcweir {css::awt::Key::F3 , "KEY_F3" }, 94*cdf0e10cSrcweir {css::awt::Key::F4 , "KEY_F4" }, 95*cdf0e10cSrcweir {css::awt::Key::F5 , "KEY_F5" }, 96*cdf0e10cSrcweir {css::awt::Key::F6 , "KEY_F6" }, 97*cdf0e10cSrcweir {css::awt::Key::F7 , "KEY_F7" }, 98*cdf0e10cSrcweir {css::awt::Key::F8 , "KEY_F8" }, 99*cdf0e10cSrcweir {css::awt::Key::F9 , "KEY_F9" }, 100*cdf0e10cSrcweir {css::awt::Key::F10 , "KEY_F10" }, 101*cdf0e10cSrcweir {css::awt::Key::F11 , "KEY_F11" }, 102*cdf0e10cSrcweir {css::awt::Key::F12 , "KEY_F12" }, 103*cdf0e10cSrcweir {css::awt::Key::F13 , "KEY_F13" }, 104*cdf0e10cSrcweir {css::awt::Key::F14 , "KEY_F14" }, 105*cdf0e10cSrcweir {css::awt::Key::F15 , "KEY_F15" }, 106*cdf0e10cSrcweir {css::awt::Key::F16 , "KEY_F16" }, 107*cdf0e10cSrcweir {css::awt::Key::F17 , "KEY_F17" }, 108*cdf0e10cSrcweir {css::awt::Key::F18 , "KEY_F18" }, 109*cdf0e10cSrcweir {css::awt::Key::F19 , "KEY_F19" }, 110*cdf0e10cSrcweir {css::awt::Key::F20 , "KEY_F20" }, 111*cdf0e10cSrcweir {css::awt::Key::F21 , "KEY_F21" }, 112*cdf0e10cSrcweir {css::awt::Key::F22 , "KEY_F22" }, 113*cdf0e10cSrcweir {css::awt::Key::F23 , "KEY_F23" }, 114*cdf0e10cSrcweir {css::awt::Key::F24 , "KEY_F24" }, 115*cdf0e10cSrcweir {css::awt::Key::F25 , "KEY_F25" }, 116*cdf0e10cSrcweir {css::awt::Key::F26 , "KEY_F26" }, 117*cdf0e10cSrcweir {css::awt::Key::DOWN , "KEY_DOWN" }, 118*cdf0e10cSrcweir {css::awt::Key::UP , "KEY_UP" }, 119*cdf0e10cSrcweir {css::awt::Key::LEFT , "KEY_LEFT" }, 120*cdf0e10cSrcweir {css::awt::Key::RIGHT , "KEY_RIGHT" }, 121*cdf0e10cSrcweir {css::awt::Key::HOME , "KEY_HOME" }, 122*cdf0e10cSrcweir {css::awt::Key::END , "KEY_END" }, 123*cdf0e10cSrcweir {css::awt::Key::PAGEUP , "KEY_PAGEUP" }, 124*cdf0e10cSrcweir {css::awt::Key::PAGEDOWN , "KEY_PAGEDOWN" }, 125*cdf0e10cSrcweir {css::awt::Key::RETURN , "KEY_RETURN" }, 126*cdf0e10cSrcweir {css::awt::Key::ESCAPE , "KEY_ESCAPE" }, 127*cdf0e10cSrcweir {css::awt::Key::TAB , "KEY_TAB" }, 128*cdf0e10cSrcweir {css::awt::Key::BACKSPACE , "KEY_BACKSPACE" }, 129*cdf0e10cSrcweir {css::awt::Key::SPACE , "KEY_SPACE" }, 130*cdf0e10cSrcweir {css::awt::Key::INSERT , "KEY_INSERT" }, 131*cdf0e10cSrcweir {css::awt::Key::DELETE , "KEY_DELETE" }, 132*cdf0e10cSrcweir {css::awt::Key::ADD , "KEY_ADD" }, 133*cdf0e10cSrcweir {css::awt::Key::SUBTRACT , "KEY_SUBTRACT" }, 134*cdf0e10cSrcweir {css::awt::Key::MULTIPLY , "KEY_MULTIPLY" }, 135*cdf0e10cSrcweir {css::awt::Key::DIVIDE , "KEY_DIVIDE" }, 136*cdf0e10cSrcweir {css::awt::Key::POINT , "KEY_POINT" }, 137*cdf0e10cSrcweir {css::awt::Key::COMMA , "KEY_COMMA" }, 138*cdf0e10cSrcweir {css::awt::Key::LESS , "KEY_LESS" }, 139*cdf0e10cSrcweir {css::awt::Key::GREATER , "KEY_GREATER" }, 140*cdf0e10cSrcweir {css::awt::Key::EQUAL , "KEY_EQUAL" }, 141*cdf0e10cSrcweir {css::awt::Key::OPEN , "KEY_OPEN" }, 142*cdf0e10cSrcweir {css::awt::Key::CUT , "KEY_CUT" }, 143*cdf0e10cSrcweir {css::awt::Key::COPY , "KEY_COPY" }, 144*cdf0e10cSrcweir {css::awt::Key::PASTE , "KEY_PASTE" }, 145*cdf0e10cSrcweir {css::awt::Key::UNDO , "KEY_UNDO" }, 146*cdf0e10cSrcweir {css::awt::Key::REPEAT , "KEY_REPEAT" }, 147*cdf0e10cSrcweir {css::awt::Key::FIND , "KEY_FIND" }, 148*cdf0e10cSrcweir {css::awt::Key::PROPERTIES , "KEY_PROPERTIES" }, 149*cdf0e10cSrcweir {css::awt::Key::FRONT , "KEY_FRONT" }, 150*cdf0e10cSrcweir {css::awt::Key::CONTEXTMENU , "KEY_CONTEXTMENU"}, 151*cdf0e10cSrcweir {css::awt::Key::HELP , "KEY_HELP" }, 152*cdf0e10cSrcweir {css::awt::Key::MENU , "KEY_MENU" }, 153*cdf0e10cSrcweir {css::awt::Key::HANGUL_HANJA , "KEY_HANGUL_HANJA"}, 154*cdf0e10cSrcweir {css::awt::Key::DECIMAL , "KEY_DECIMAL" }, 155*cdf0e10cSrcweir {css::awt::Key::TILDE , "KEY_TILDE" }, 156*cdf0e10cSrcweir {css::awt::Key::QUOTELEFT , "KEY_QUOTELEFT" }, 157*cdf0e10cSrcweir {0 , "" } // mark the end of this array! 158*cdf0e10cSrcweir }; 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //----------------------------------------------- 161*cdf0e10cSrcweir KeyMapping::KeyMapping() 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir sal_Int32 i = 0; 164*cdf0e10cSrcweir while(KeyIdentifierMap[i].Code != 0) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir ::rtl::OUString sIdentifier = ::rtl::OUString::createFromAscii(KeyIdentifierMap[i].Identifier); 167*cdf0e10cSrcweir sal_Int16 nCode = KeyIdentifierMap[i].Code; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir m_lIdentifierHash[sIdentifier] = nCode ; 170*cdf0e10cSrcweir m_lCodeHash [nCode] = sIdentifier; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir ++i; 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //----------------------------------------------- 177*cdf0e10cSrcweir KeyMapping::~KeyMapping() 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir //----------------------------------------------- 182*cdf0e10cSrcweir sal_uInt16 KeyMapping::mapIdentifierToCode(const ::rtl::OUString& sIdentifier) 183*cdf0e10cSrcweir throw(css::lang::IllegalArgumentException) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir Identifier2CodeHash::const_iterator pIt = m_lIdentifierHash.find(sIdentifier); 186*cdf0e10cSrcweir if (pIt != m_lIdentifierHash.end()) 187*cdf0e10cSrcweir return pIt->second; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir // Its not well known identifier - but may be a pure key code formated as string ... 190*cdf0e10cSrcweir // Check and convert it! 191*cdf0e10cSrcweir sal_uInt16 nCode = 0; 192*cdf0e10cSrcweir if (!KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(sIdentifier, nCode)) 193*cdf0e10cSrcweir throw css::lang::IllegalArgumentException( 194*cdf0e10cSrcweir DECLARE_ASCII("Cant map given identifier to a valid key code value."), 195*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >(), 196*cdf0e10cSrcweir 0); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir return (sal_uInt16)nCode; 199*cdf0e10cSrcweir } 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir //----------------------------------------------- 202*cdf0e10cSrcweir ::rtl::OUString KeyMapping::mapCodeToIdentifier(sal_uInt16 nCode) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir Code2IdentifierHash::const_iterator pIt = m_lCodeHash.find(nCode); 205*cdf0e10cSrcweir if (pIt != m_lCodeHash.end()) 206*cdf0e10cSrcweir return pIt->second; 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir // If we have no well known identifier - use the pure code value! 209*cdf0e10cSrcweir return ::rtl::OUString::valueOf((sal_Int32)nCode); 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir //----------------------------------------------- 213*cdf0e10cSrcweir sal_Bool KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(const ::rtl::OUString& sIdentifier, 214*cdf0e10cSrcweir sal_uInt16& rCode ) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir sal_Int32 nCode = sIdentifier.toInt32(); 217*cdf0e10cSrcweir if (nCode > 0) 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir rCode = (sal_uInt16)nCode; 220*cdf0e10cSrcweir return sal_True; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // 0 is normaly an error of the called method toInt32() ... 224*cdf0e10cSrcweir // But we must be aware, that the identifier is "0"! 225*cdf0e10cSrcweir rCode = 0; 226*cdf0e10cSrcweir return sIdentifier.equalsAscii("0"); 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir } // namespace framework 230