KeyBrd.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:75k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  * Keybrd.C
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for keypad processing
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * removed!
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * removed!
  82.  *
  83.  * removed!
  84.  * removed!
  85.  * removed!
  86.  * removed!
  87.  *
  88.  * removed!
  89.  * removed!
  90.  * removed!
  91.  *
  92.  * removed!
  93.  * removed!
  94.  * removed!
  95.  *
  96.  * removed!
  97.  * removed!
  98.  * removed!
  99.  *
  100.  * removed!
  101.  * removed!
  102.  * removed!
  103.  *
  104.  * removed!
  105.  * removed!
  106.  * removed!
  107.  *
  108.  * removed!
  109.  * removed!
  110.  * removed!
  111.  * removed!
  112.  * removed!
  113.  *
  114.  * removed!
  115.  * removed!
  116.  * removed!
  117.  * removed!
  118.  *
  119.  * removed!
  120.  * removed!
  121.  * removed!
  122.  *
  123.  * removed!
  124.  * removed!
  125.  * removed!
  126.  *
  127.  * removed!
  128.  * removed!
  129.  * removed!
  130.  *
  131.  * removed!
  132.  * removed!
  133.  * removed!
  134.  *
  135.  * removed!
  136.  * removed!
  137.  * removed!
  138.  *
  139.  * removed!
  140.  * removed!
  141.  * removed!
  142.  *
  143.  * removed!
  144.  * removed!
  145.  * removed!
  146.  *
  147.  * removed!
  148.  * removed!
  149.  * removed!
  150.  *
  151.  * removed!
  152.  * removed!
  153.  * removed!
  154.  *
  155.  * removed!
  156.  * removed!
  157.  * removed!
  158.  *
  159.  *------------------------------------------------------------------------------
  160.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  161.  *============================================================================
  162.  ****************************************************************************/
  163. /**
  164.  * Copyright Notice
  165.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  166.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  167.  *  (It is illegal to remove this copyright notice from this software or any
  168.  *  portion of it)
  169.  */
  170. /**************************************************************
  171.    FILENAME : KeyBrd.c
  172.    PURPOSE     : Key Board Handler 
  173.    REMARKS     : nil
  174.    AUTHOR      : Neeraj Sharma
  175.    DATE     : Aug 25, 2003
  176. **************************************************************/
  177. /*  Include: MMI header file */
  178. #include "MMI_features.h"
  179. #include "stdC.h"
  180. #include "L4Dr1.h"
  181. #include "PixtelDataTypes.h"
  182. #include "KeyBrd.h"
  183. #include "TimerEvents.h"
  184. #include "AudioInc.h"
  185. #include "GlobalConstants.h"
  186. #include "ThrdOsInterface.h"
  187. #include "DebugInitDef.h"
  188. #include "FrameworkStruct.h"
  189. #include "SettingProfile.h"
  190. #include "IdleAppDef.h"
  191. #include "QueueGprot.h"
  192. #include "taskinit.h"   /* amitM */
  193. #include "MMITaskProt.h"
  194. #include "WrapperGprot.h"
  195. #include "ProfileGprots.h"
  196. #include "L4Dr.h"
  197. #include "kbd_table.h"
  198. #include "MMI_trc.h"
  199. #include "EventsGprot.h"
  200. #include "gpioInc.h"
  201. #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
  202. #include "wgui_touch_screen.h"
  203. #endif 
  204. #include "ScreenRotationGprot.h"
  205. #include "kbd_table.h"
  206. #include "ProfilingEngine.h"
  207. #include "SimDetectionGprot.h"
  208. extern U8 processUpRepeatKey;
  209. extern U8 pressKey;
  210. /***************************************************************************** 
  211. * Define
  212. *****************************************************************************/
  213. #define MAX_PRESENTALLKEYS sizeof(PresentAllKeys)/sizeof(PresentAllKeys[0])
  214. #define MAX_PRESENTDIGITSKEYS sizeof(PresentDigitsKeys)/sizeof(PresentDigitsKeys[0])
  215. #define MAX_KEYPADMAP   sizeof(nKeyPadMap)/sizeof(nKeyPadMap[0])
  216. mmi_frm_context_struct g_mmi_frm_cntx;
  217. mmi_frm_context_struct *frm_p = &g_mmi_frm_cntx;
  218. /***************************************************************************** 
  219. * Local Variable
  220. *****************************************************************************/
  221. static U16 currKeyPadTone = 0xFFFF;
  222. static mmi_key_types_enum nKeyPadStatus[MAX_KEYS];
  223. /* allow multiple keys's processing at the same time */
  224. static MMI_BOOL g_kbd_concurrent_key_mode = MMI_FALSE;
  225. /* how many key under pressing  */
  226. static U8 key_is_pressing_count = 0;
  227. static MMI_BOOL g_process_key_in_high_frequency = MMI_FALSE;
  228. /***************************************************************************** 
  229. * Global Variable
  230. *****************************************************************************/
  231. extern oslMsgqid mmi_ext_qid;
  232. extern MMI_BOOL g_keypad_flag;
  233. extern drv_get_key_func keypad_ptr;
  234. U32 g_2step_key_num = 0;
  235. U16 g_2step_keyCode[MAX_KEYS];
  236. const U16 PresentDigitsKeys[] = {KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9};
  237. const U16 PresentAllKeys[] = 
  238. {
  239.     KEY_0,
  240.     KEY_1,
  241.     KEY_2,
  242.     KEY_3,
  243.     KEY_4,
  244.     KEY_5,
  245.     KEY_6,
  246.     KEY_7,
  247.     KEY_8,
  248.     KEY_9,
  249.     KEY_LSK,
  250.     KEY_RSK,
  251.     KEY_UP_ARROW,
  252.     KEY_DOWN_ARROW,
  253.     KEY_LEFT_ARROW,
  254.     KEY_RIGHT_ARROW,
  255.     KEY_SEND,
  256.     KEY_END,
  257.     KEY_STAR,
  258.     KEY_POUND,
  259.     KEY_VOL_UP,
  260.     KEY_VOL_DOWN,
  261.     KEY_CLEAR,
  262.     KEY_CAMERA,
  263.     KEY_WAP,
  264.     KEY_EXTRA_1,
  265.     KEY_EXTRA_2,
  266.     KEY_PLAY_STOP,
  267.     KEY_PLAY_STOP,
  268.     KEY_BACK,
  269.     KEY_POWER
  270. //KP Jerry add on 2007-4-23 start  
  271.     ,KEY_LEFT_SHORTCUT
  272.     ,KEY_RIGHT_SHORTCUT
  273. //KP Jerry add on 2007-4-23 end
  274. };
  275. #ifndef MMI_ON_WIN32
  276. static const KeyPadMap nKeyPadMap[] = 
  277. {
  278.     {DEVICE_KEY_0, KEY_0, KEY_TIMER_ID0, TONE_DTMF_0, DEVICE_AUDIO_PLAY_INFINITE},
  279.     {DEVICE_KEY_1, KEY_1, KEY_TIMER_ID1, TONE_DTMF_1, DEVICE_AUDIO_PLAY_INFINITE},
  280.     {DEVICE_KEY_2, KEY_2, KEY_TIMER_ID2, TONE_DTMF_2, DEVICE_AUDIO_PLAY_INFINITE},
  281.     {DEVICE_KEY_3, KEY_3, KEY_TIMER_ID3, TONE_DTMF_3, DEVICE_AUDIO_PLAY_INFINITE},
  282.     {DEVICE_KEY_4, KEY_4, KEY_TIMER_ID4, TONE_DTMF_4, DEVICE_AUDIO_PLAY_INFINITE},
  283.     {DEVICE_KEY_5, KEY_5, KEY_TIMER_ID5, TONE_DTMF_5, DEVICE_AUDIO_PLAY_INFINITE},
  284.     {DEVICE_KEY_6, KEY_6, KEY_TIMER_ID6, TONE_DTMF_6, DEVICE_AUDIO_PLAY_INFINITE},
  285.     {DEVICE_KEY_7, KEY_7, KEY_TIMER_ID7, TONE_DTMF_7, DEVICE_AUDIO_PLAY_INFINITE},
  286.     {DEVICE_KEY_8, KEY_8, KEY_TIMER_ID8, TONE_DTMF_8, DEVICE_AUDIO_PLAY_INFINITE},
  287.     {DEVICE_KEY_9, KEY_9, KEY_TIMER_ID9, TONE_DTMF_9, DEVICE_AUDIO_PLAY_INFINITE},
  288.     {DEVICE_KEY_STAR, KEY_STAR, KEY_TIMER_ID10, TONE_KEY_STAR, DEVICE_AUDIO_PLAY_INFINITE},
  289.     {DEVICE_KEY_HASH, KEY_POUND, KEY_TIMER_ID11, TONE_KEY_HASH, DEVICE_AUDIO_PLAY_INFINITE},
  290.     {DEVICE_KEY_VOL_UP, KEY_VOL_UP, KEY_TIMER_ID12, TONE_KEY_VOL_UP, DEVICE_AUDIO_PLAY_ONCE},
  291.     {DEVICE_KEY_VOL_DOWN, KEY_VOL_DOWN, KEY_TIMER_ID13, TONE_KEY_VOL_DOWN, DEVICE_AUDIO_PLAY_ONCE},
  292.     {DEVICE_KEY_UP, KEY_UP_ARROW, KEY_TIMER_ID14, TONE_KEY_UP, DEVICE_AUDIO_PLAY_ONCE},
  293.     {DEVICE_KEY_DOWN, KEY_DOWN_ARROW, KEY_TIMER_ID15, TONE_KEY_DOWN, DEVICE_AUDIO_PLAY_ONCE},
  294.     {DEVICE_KEY_LEFT, KEY_LEFT_ARROW, KEY_TIMER_ID16, TONE_KEY_LEFT, DEVICE_AUDIO_PLAY_ONCE},
  295.     {DEVICE_KEY_RIGHT, KEY_RIGHT_ARROW, KEY_TIMER_ID17, TONE_KEY_RIGHT, DEVICE_AUDIO_PLAY_ONCE},
  296.     {DEVICE_KEY_MENU, KEY_ENTER, KEY_TIMER_ID18, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},
  297.     {DEVICE_KEY_FUNCTION, KEY_QUICK_ACS, KEY_TIMER_ID19, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},
  298.     {DEVICE_KEY_SK_LEFT, KEY_LSK, KEY_TIMER_ID20, TONE_KEY_SK_LEFT, DEVICE_AUDIO_PLAY_ONCE},
  299.     {DEVICE_KEY_SK_RIGHT, KEY_RSK, KEY_TIMER_ID21, TONE_KEY_SK_RIGHT, DEVICE_AUDIO_PLAY_ONCE},
  300.     {DEVICE_KEY_SEND, KEY_SEND, KEY_TIMER_ID22, TONE_KEY_SEND, DEVICE_AUDIO_PLAY_ONCE},
  301.     {DEVICE_KEY_END, KEY_END, KEY_TIMER_ID23, TONE_KEY_END, DEVICE_AUDIO_PLAY_ONCE},
  302.     {DEVICE_KEY_POWER, KEY_POWER, KEY_TIMER_ID24, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},        /* 24 IMPORTANT :This will be power key */
  303.     {DEVICE_KEY_CLEAR, KEY_CLEAR, KEY_TIMER_ID25, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},
  304.     {DEVICE_KEY_EXT_FUNC1, KEY_EXTRA_1, KEY_TIMER_ID27, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},
  305.     {DEVICE_KEY_EXT_FUNC2, KEY_EXTRA_2, KEY_TIMER_ID28, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},
  306.     {DEVICE_KEY_MP3_PLAY_STOP, KEY_PLAY_STOP, KEY_TIMER_ID29, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},
  307.     {DEVICE_KEY_MP3_FWD, KEY_FWD, KEY_TIMER_ID30, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE},
  308.     {DEVICE_KEY_MP3_BACK, KEY_BACK, KEY_TIMER_ID31, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE}
  309. //KP Jerry add on 2007-4-23 start  
  310.     ,{DEVICE_KEY_MP3_SHORTCUT, KEY_LEFT_SHORTCUT, KEY_TIMER_ID32, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE}
  311.     ,{DEVICE_KEY_WAP_SHORTCUT, KEY_RIGHT_SHORTCUT, KEY_TIMER_ID33, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE}
  312. //KP Jerry add on 2007-4-23 end    
  313. };
  314. #else /* MMI_ON_WIN32 */ 
  315. /* 
  316.  * virtual-Key Code is defined in "WINUSER.H", and "WINDOWS.H" includes "WINUSER.H" 
  317.  *
  318.  * Constant name           Value (hexadecimal) 
  319.  *-------------------------------------------------
  320.  * #define VK_SPACE          0x20
  321.  * #define VK_PRIOR          0x21
  322.  * #define VK_NEXT           0x22
  323.  * #define VK_END            0x23
  324.  * #define VK_HOME           0x24
  325.  * #define VK_LEFT           0x25
  326.  * #define VK_UP             0x26
  327.  * #define VK_RIGHT          0x27
  328.  * #define VK_DOWN           0x28
  329.  * #define VK_SELECT         0x29
  330.  * #define VK_PRINT          0x2A
  331.  * #define VK_EXECUTE        0x2B
  332.  * #define VK_SNAPSHOT       0x2C
  333.  * #define VK_INSERT         0x2D
  334.  * #define VK_DELETE         0x2E
  335.  * #define VK_HELP           0x2F
  336.  *
  337.  * [ VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) ]
  338.  * [ VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) ]
  339.  *
  340.  * #define VK_LWIN           0x5B
  341.  * #define VK_RWIN           0x5C
  342.  * #define VK_APPS           0x5D
  343.  * 
  344.  * #define VK_NUMPAD0        0x60
  345.  * #define VK_NUMPAD1        0x61
  346.  * #define VK_NUMPAD2        0x62
  347.  * #define VK_NUMPAD3        0x63
  348.  * #define VK_NUMPAD4        0x64
  349.  * #define VK_NUMPAD5        0x65
  350.  * #define VK_NUMPAD6        0x66
  351.  * #define VK_NUMPAD7        0x67
  352.  * #define VK_NUMPAD8        0x68
  353.  * #define VK_NUMPAD9        0x69
  354.  * #define VK_MULTIPLY       0x6A
  355.  * #define VK_ADD            0x6B
  356.  * #define VK_SEPARATOR      0x6C
  357.  * #define VK_SUBTRACT       0x6D
  358.  * #define VK_DECIMAL        0x6E
  359.  * #define VK_DIVIDE         0x6F
  360.  * #define VK_F1             0x70
  361.  * #define VK_F2             0x71
  362.  * #define VK_F3             0x72
  363.  * #define VK_F4             0x73
  364.  * #define VK_F5             0x74
  365.  * #define VK_F6             0x75
  366.  * #define VK_F7             0x76
  367.  * #define VK_F8             0x77
  368.  * #define VK_F9             0x78
  369.  * #define VK_F10            0x79
  370.  * #define VK_F11            0x7A
  371.  * #define VK_F12            0x7B
  372.  * #define VK_F13            0x7C
  373.  * #define VK_F14            0x7D
  374.  * #define VK_F15            0x7E
  375.  * #define VK_F16            0x7F
  376.  * #define VK_F17            0x80
  377.  * #define VK_F18            0x81
  378.  * #define VK_F19            0x82
  379.  * #define VK_F20            0x83
  380.  * #define VK_F21            0x84
  381.  * #define VK_F22            0x85
  382.  * #define VK_F23            0x86
  383.  * #define VK_F24            0x87
  384.  *
  385.  */
  386. static const KeyPadMap nKeyPadMap[] = 
  387. {
  388.     {KEY_0, KEY_0, KEY_TIMER_ID0, TONE_DTMF_0, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD0 /* 0 */ },
  389.     {KEY_1, KEY_1, KEY_TIMER_ID1, TONE_DTMF_1, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD1 /* 1 */ },
  390.     {KEY_2, KEY_2, KEY_TIMER_ID2, TONE_DTMF_2, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD2 /* 2 */ },
  391.     {KEY_3, KEY_3, KEY_TIMER_ID3, TONE_DTMF_3, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD3 /* 3 */ },
  392.     {KEY_4, KEY_4, KEY_TIMER_ID4, TONE_DTMF_4, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD4 /* 4 */ },
  393.     {KEY_5, KEY_5, KEY_TIMER_ID5, TONE_DTMF_5, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD5 /* 5 */ },
  394.     {KEY_6, KEY_6, KEY_TIMER_ID6, TONE_DTMF_6, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD6 /* 6 */ },
  395.     {KEY_7, KEY_7, KEY_TIMER_ID7, TONE_DTMF_7, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD7 /* 7 */ },
  396.     {KEY_8, KEY_8, KEY_TIMER_ID8, TONE_DTMF_8, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD8 /* 8 */ },
  397.     {KEY_9, KEY_9, KEY_TIMER_ID9, TONE_DTMF_9, DEVICE_AUDIO_PLAY_INFINITE, VK_NUMPAD9 /* 9 */ },
  398.     {KEY_LSK, KEY_LSK, KEY_TIMER_ID10, TONE_KEY_STAR, DEVICE_AUDIO_PLAY_INFINITE, VK_INSERT /* Ins */ },
  399.     {KEY_RSK, KEY_RSK, KEY_TIMER_ID11, TONE_KEY_HASH, DEVICE_AUDIO_PLAY_INFINITE, VK_PRIOR /* PgUp */ },
  400.     {KEY_UP_ARROW, KEY_UP_ARROW, KEY_TIMER_ID12, TONE_KEY_VOL_UP, DEVICE_AUDIO_PLAY_ONCE, VK_UP /* Up */ },
  401.     {KEY_DOWN_ARROW, KEY_DOWN_ARROW, KEY_TIMER_ID13, TONE_KEY_VOL_DOWN, DEVICE_AUDIO_PLAY_ONCE, VK_DOWN /* Down */ },
  402.     {KEY_LEFT_ARROW, KEY_LEFT_ARROW, KEY_TIMER_ID14, TONE_KEY_LEFT, DEVICE_AUDIO_PLAY_ONCE, VK_LEFT /* Left */ },
  403.     {KEY_RIGHT_ARROW, KEY_RIGHT_ARROW, KEY_TIMER_ID15, TONE_KEY_RIGHT, DEVICE_AUDIO_PLAY_ONCE, VK_RIGHT /* Right */ },
  404.     {KEY_SEND, KEY_SEND, KEY_TIMER_ID16, TONE_KEY_SEND, DEVICE_AUDIO_PLAY_ONCE, VK_DELETE /* Del */ },
  405.     {KEY_END, KEY_END, KEY_TIMER_ID17, TONE_KEY_END, DEVICE_AUDIO_PLAY_ONCE, VK_NEXT /* PgDn */ },
  406.     {KEY_CLEAR, KEY_CLEAR, KEY_TIMER_ID25, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, VK_END /* End */ },
  407.     {KEY_STAR, KEY_STAR, KEY_TIMER_ID19, TONE_KEY_STAR, DEVICE_AUDIO_PLAY_INFINITE, VK_DIVIDE /* / */ },
  408.     {KEY_POUND, KEY_POUND, KEY_TIMER_ID20, TONE_KEY_HASH, DEVICE_AUDIO_PLAY_INFINITE, VK_MULTIPLY /* * */ },
  409.     {KEY_VOL_UP, KEY_VOL_UP, KEY_TIMER_ID21, TONE_KEY_VOL_UP, DEVICE_AUDIO_PLAY_ONCE, VK_ADD /* + */ },
  410.     {KEY_VOL_DOWN, KEY_VOL_DOWN, KEY_TIMER_ID22, TONE_KEY_VOL_DOWN, DEVICE_AUDIO_PLAY_ONCE, VK_SUBTRACT /* - */ },
  411.     {KEY_INVALID, KEY_INVALID, KEY_TIMER_ID_NONE, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, 0 /* None */ },
  412.     {KEY_QUICK_ACS, KEY_QUICK_ACS, KEY_TIMER_ID19, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, VK_BACK /* Backspace */ },
  413.     {KEY_ENTER, KEY_ENTER, KEY_TIMER_ID18, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, VK_RETURN /* Enter */ },
  414.     {KEY_EXTRA_1, KEY_EXTRA_1, KEY_TIMER_ID27, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, VK_F1 /* F1 */ },
  415.     {KEY_EXTRA_2, KEY_EXTRA_2, KEY_TIMER_ID28, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, VK_F2 /* F2 */ },
  416.     {KEY_PLAY_STOP, KEY_PLAY_STOP, KEY_TIMER_ID29, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, 0 /* TBD */},
  417.     {KEY_FWD, KEY_FWD, KEY_TIMER_ID30, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, 0 /* TBD */},
  418.     {KEY_BACK, KEY_BACK, KEY_TIMER_ID31, TONE_KEY_NORMAL, DEVICE_AUDIO_PLAY_ONCE, 0 /* TBD */}
  419. };
  420. #endif /* MMI_ON_WIN32 */ 
  421. extern void IdleHandleKeypadLockProcess(void);
  422. #if defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__)
  423. extern U8 CanPlayHumanVoiceKeyTone(void);
  424. #endif 
  425. #if defined(__MMI_CUST_KEYPAD_TONE__)
  426. extern U8 CanPlayCustKeyTone(void);
  427. #endif 
  428. #if defined(MMI_ON_WIN32)
  429. extern void MMI_system_keybord_handler(S32 key_code, S32 key_state);
  430. #endif 
  431. extern void ShutdownSystemOperation(void);
  432. /*****************************************************************************
  433.  * FUNCTION
  434.  *  InitProcessKeyEvent
  435.  * DESCRIPTION
  436.  *  To init the process key handler for preprocessing and postprocessing.
  437.  * PARAMETERS
  438.  *  void
  439.  *  U32(?)      [IN]        MsgType, U16 KeyMapIndex
  440.  * RETURNS
  441.  *  void
  442.  *****************************************************************************/
  443. void InitProcessKeyEvent(void)
  444. {
  445.     /*----------------------------------------------------------------*/
  446.     /* Local Variables                                                */
  447.     /*----------------------------------------------------------------*/
  448.     U16 i = 0;
  449.     /*----------------------------------------------------------------*/
  450.     /* Code Body                                                      */
  451.     /*----------------------------------------------------------------*/
  452.     for (i = 0; i < MAX_KEYS; i++)
  453.     {
  454.         nKeyPadStatus[i] = KEY_EVENT_UP;
  455.         key_is_pressing_count = 0;
  456.     }
  457. }
  458. /*****************************************************************************
  459.  * FUNCTION
  460.  *  KeyEventHandler
  461.  * DESCRIPTION
  462.  *  To handle the key event.
  463.  * PARAMETERS
  464.  *  eventKey        [IN]        
  465.  * RETURNS
  466.  *  void
  467.  *****************************************************************************/
  468. static void KeyEventHandler(KEYBRD_MESSAGE *eventKey)
  469. {
  470.     /*----------------------------------------------------------------*/
  471.     /* Local Variables                                                */
  472.     /*----------------------------------------------------------------*/
  473.     /*----------------------------------------------------------------*/
  474.     /* Code Body                                                      */
  475.     /*----------------------------------------------------------------*/
  476.     /* Preprocess the keypad handler */
  477.     mmi_kbd_app_key_hdlr(eventKey);
  478.     if (g_mmi_frm_cntx.kbd_pre_func)
  479.     {
  480.         g_mmi_frm_cntx.kbd_pre_func(eventKey);
  481.     }
  482.     /* Process the register App keypad handler */
  483.     ExecuteCurrKeyHandler((S16) eventKey->nKeyCode, (S16) eventKey->nMsgType);
  484.     if (g_mmi_frm_cntx.kbd_post_func)
  485.     {
  486.         g_mmi_frm_cntx.kbd_post_func(eventKey);
  487.     }
  488. }
  489. /*****************************************************************************
  490.  * FUNCTION
  491.  *  mmi_frm_get_2step_keys
  492.  * DESCRIPTION
  493.  *  To get the 2 step keys of handset.
  494.  *  The function should be called in MMI_Init()
  495.  * PARAMETERS
  496.  *  void
  497.  *  KEYBRD_MESSAGE(?)       [IN]        *eventKey
  498.  * RETURNS
  499.  *  void
  500.  *****************************************************************************/
  501. extern void kbd_find_2step(kal_uint32 *number, kal_uint8 *two_step);
  502. void mmi_frm_get_2step_keys(void)
  503. {
  504.     /*----------------------------------------------------------------*/
  505.     /* Local Variables                                                */
  506.     /*----------------------------------------------------------------*/
  507.     U32 i;
  508.     U8 _2step_key[MAX_KEYS];
  509.     /*----------------------------------------------------------------*/
  510.     /* Code Body                                                      */
  511.     /*----------------------------------------------------------------*/
  512.     memset(_2step_key, 0, sizeof(U8) * MAX_KEYS);
  513.     memset(g_2step_keyCode, 0, sizeof(U16) * MAX_KEYS);
  514. #ifndef MMI_ON_WIN32
  515.     kbd_find_2step(&g_2step_key_num, _2step_key);
  516. #endif 
  517.     for (i = 0; i < g_2step_key_num; i++)
  518.     {
  519.         g_2step_keyCode[i] = nKeyPadMap[_2step_key[i]].nMMIKeyCode;
  520.     }
  521. }
  522. /*****************************************************************************
  523.  * FUNCTION
  524.  *  mmi_frm_is_2step_keyCode
  525.  * DESCRIPTION
  526.  *  To get the 2 step keys of handset.
  527.  *  The function should be called in MMI_Init()
  528.  * PARAMETERS
  529.  *  keyCode                 [IN]        
  530.  *  KEYBRD_MESSAGE(?)       [IN]        *eventKey
  531.  * RETURNS
  532.  *  MMI_TRUE - it's 2 step key
  533.  *  MMI_FALSE - it isn't 2 step key
  534.  *****************************************************************************/
  535. static MMI_BOOL mmi_frm_is_2step_keyCode(U16 keyCode)
  536. {
  537.     /*----------------------------------------------------------------*/
  538.     /* Local Variables                                                */
  539.     /*----------------------------------------------------------------*/
  540.     U32 i;
  541.     /*----------------------------------------------------------------*/
  542.     /* Code Body                                                      */
  543.     /*----------------------------------------------------------------*/
  544.     for (i = 0; i < g_2step_key_num; i++)
  545.     {
  546.         if (keyCode == g_2step_keyCode[i])
  547.         {
  548.             return MMI_TRUE;
  549.         }
  550.     }
  551.     return MMI_FALSE;
  552. }
  553. /*****************************************************************************
  554.  * FUNCTION
  555.  *  ProcessKeyEvent
  556.  * DESCRIPTION
  557.  *  To send the key events to MMI task
  558.  * PARAMETERS
  559.  *  MsgType         [IN]        
  560.  *  KeyMapIndex     [IN]        
  561.  * RETURNS
  562.  *  void
  563.  *****************************************************************************/
  564. /* TBD */
  565. #define DRV_WM_ENABLE_TWOKEY_DETECTION             5
  566. #define DRV_WM_DISABLE_TWOKEY_DETECTION               6
  567. void ProcessKeyEvent(U32 MsgType, U16 KeyMapIndex)
  568. {
  569.     /*----------------------------------------------------------------*/
  570.     /* Local Variables                                                */
  571.     /*----------------------------------------------------------------*/
  572.     /*----------------------------------------------------------------*/
  573.     /* Code Body                                                      */
  574.     /*----------------------------------------------------------------*/
  575.     MMI_ASSERT(KeyMapIndex < MAX_KEYPADMAP);
  576.     MMI_ASSERT(nKeyPadMap[KeyMapIndex].nMMIKeyCode != KEY_INVALID);
  577.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_PROC_KEYEVENT_HDLR, MsgType, nKeyPadMap[KeyMapIndex].nMMIKeyCode));
  578.     if (MsgType == WM_KEYPRESS)
  579.     {
  580.         if (nKeyPadStatus[KeyMapIndex] == KEY_EVENT_UP)
  581.         {
  582.             KEYBRD_MESSAGE KeyBrdMsg;
  583.             KeyBrdMsg.nKeyCode = nKeyPadMap[KeyMapIndex].nMMIKeyCode;
  584.             if (mmi_frm_is_2step_keyCode(KeyBrdMsg.nKeyCode))
  585.             {
  586.                 nKeyPadStatus[KeyMapIndex] = KEY_HALF_PRESS_DOWN;
  587.                 key_is_pressing_count++;
  588.                 KeyBrdMsg.nMsgType = KEY_HALF_PRESS_DOWN;
  589.             }
  590.             else
  591.             {
  592.                 nKeyPadStatus[KeyMapIndex] = KEY_EVENT_DOWN;    /* same with KEY_FULL_PRESS_DOWN */
  593.                 key_is_pressing_count++;
  594.                 KeyBrdMsg.nMsgType = KEY_EVENT_DOWN;
  595.             }
  596.             KeyEventHandler((KEYBRD_MESSAGE*) & KeyBrdMsg);
  597.         #ifdef MMI_ON_WIN32
  598.             StartTimer(nKeyPadMap[KeyMapIndex].nTimerId, KEYTIMER_LONGPRESS, (FuncPtr) KeyTimerExpiryProc);
  599.         #endif 
  600.         }
  601.         else
  602.         {
  603.             /* Ignore the event */
  604.         }
  605.     }
  606.     else if (MsgType == WM_KEYRELEASE)
  607.     {
  608.         if ((nKeyPadStatus[KeyMapIndex] == KEY_EVENT_DOWN)
  609.             || (nKeyPadStatus[KeyMapIndex] == KEY_LONG_PRESS)
  610.             || (nKeyPadStatus[KeyMapIndex] == KEY_REPEAT) || (nKeyPadStatus[KeyMapIndex] == KEY_HALF_PRESS_DOWN))
  611.         {
  612.             KEYBRD_MESSAGE KeyBrdMsg;
  613.         #ifdef MMI_ON_WIN32
  614.             /* stop timer as early as possible. avoid timer expire later */
  615.             StopTimer(nKeyPadMap[KeyMapIndex].nTimerId);
  616.         #endif /* MMI_ON_WIN32 */ 
  617.             nKeyPadStatus[KeyMapIndex] = KEY_EVENT_UP;
  618.             key_is_pressing_count--;
  619.             KeyBrdMsg.nMsgType = KEY_EVENT_UP;
  620.             KeyBrdMsg.nKeyCode = nKeyPadMap[KeyMapIndex].nMMIKeyCode;
  621.             KeyEventHandler((KEYBRD_MESSAGE*) & KeyBrdMsg);
  622.         }
  623.         else
  624.         {
  625.             /* Ignore the event */
  626.         }
  627.     }
  628.     /* ++Robin, modified by Max Chen */
  629. #ifndef MMI_ON_WIN32
  630.     else if (MsgType == DRV_WM_KEYLONGPRESS)
  631.     {
  632.         if (nKeyPadStatus[KeyMapIndex] == KEY_EVENT_DOWN)
  633.         {
  634.             KEYBRD_MESSAGE KeyBrdMsg;
  635.             nKeyPadStatus[KeyMapIndex] = KEY_LONG_PRESS;
  636.             KeyBrdMsg.nMsgType = KEY_LONG_PRESS;
  637.             KeyBrdMsg.nKeyCode = nKeyPadMap[KeyMapIndex].nMMIKeyCode;
  638.             KeyEventHandler((KEYBRD_MESSAGE*) & KeyBrdMsg);
  639.         }
  640.         else
  641.         {
  642.             /* Ignore the event */
  643.         }
  644.     }
  645.     else if (MsgType == DRV_WM_KEYREPEATED)
  646.     {
  647.         if ((nKeyPadStatus[KeyMapIndex] == KEY_LONG_PRESS) || (nKeyPadStatus[KeyMapIndex] == KEY_REPEAT))
  648.         {
  649.             KEYBRD_MESSAGE KeyBrdMsg;
  650.             nKeyPadStatus[KeyMapIndex] = KEY_REPEAT;
  651.             KeyBrdMsg.nMsgType = KEY_REPEAT;
  652.             KeyBrdMsg.nKeyCode = nKeyPadMap[KeyMapIndex].nMMIKeyCode;
  653.             KeyEventHandler((KEYBRD_MESSAGE*) & KeyBrdMsg);
  654.         }
  655.         else
  656.         {
  657.             /* Ignore the event */
  658.         }
  659.     }
  660.     else if (MsgType == DRV_WM_KEYFULLPRESS)
  661.     {
  662.         /*
  663.          * Only in two-stage key will have KEY_FULL_PRESS_DOWN, and it followed after KEY_HALF_PRESS_DOWN
  664.          */
  665.         if (nKeyPadStatus[KeyMapIndex] == KEY_HALF_PRESS_DOWN)
  666.         {
  667.             KEYBRD_MESSAGE KeyBrdMsg;
  668.             nKeyPadStatus[KeyMapIndex] = KEY_EVENT_DOWN;
  669.             KeyBrdMsg.nMsgType = KEY_EVENT_DOWN;
  670.             KeyBrdMsg.nKeyCode = nKeyPadMap[KeyMapIndex].nMMIKeyCode;
  671.             KeyEventHandler((struct KEYBRD_MESSAGE*)&KeyBrdMsg);
  672.         }
  673.         else
  674.         {
  675.             /* Ignore the event */
  676.         }
  677.     }
  678.     else if (MsgType == DRV_WM_ENABLE_TWOKEY_DETECTION || MsgType == DRV_WM_DISABLE_TWOKEY_DETECTION)
  679.     {
  680.         /* Ignore the event */
  681.     }
  682. #endif /* MMI_ON_WIN32 */ 
  683.     else
  684.     {
  685.         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_PROC_KEYEVENT_HDLR));
  686.         MMI_ASSERT(0);
  687.     }
  688. }
  689. #ifdef MMI_ON_WIN32
  690. #define CHECK_SIMPLY_HANDLE_MULTIPLEKEY(type, id)                       
  691.    {                                                                    
  692.       static U16  lastId = 0xffff;                                      
  693.       if (mmi_kbd_get_concurrent_mode() == MMI_FALSE)                   
  694.       {                                                                 
  695.       if (type == WM_KEYPRESS)                                          
  696.       {                                                                 
  697.          if (lastId == 0xffff)                                          
  698.          {  /* update lastId */                                         
  699.             lastId = id;                                                
  700.          }                                                              
  701.          else if (lastId != id)                                         
  702.          {  /* previous key isn't release but another key is pressed */ 
  703.             /* release the previous key first */                         
  704.             /* then continue to press the current key */                
  705.             ProcessKeyEvent(WM_KEYRELEASE, lastId);                     
  706.             lastKeyId = i;                                              
  707.          }                                                              
  708.       }                                                                 
  709.       else  /* WM_KEYRELEASE */                                         
  710.       {  /* reset lastId */                                             
  711.          lastId = 0xffff;                                               
  712.       }                                                                 
  713.       }                                                                 
  714.    }
  715. /*****************************************************************************
  716.  * FUNCTION
  717.  *  ProcessPCKeyEvent
  718.  * DESCRIPTION
  719.  *  This function is to convert the W32 key to MMI keys.
  720.  * PARAMETERS
  721.  *  MsgType         [IN]        Type of key event
  722.  *  KeyBrdMsg       [?]         
  723.  *  KeyMsg(?)       [IN]        Key structure
  724.  * RETURNS
  725.  *  void
  726.  *****************************************************************************/
  727. U8 ProcessPCKeyEvent(U32 MsgType, KEYBRD_MESSAGE *KeyBrdMsg)
  728. {
  729.     /*----------------------------------------------------------------*/
  730.     /* Local Variables                                                */
  731.     /*----------------------------------------------------------------*/
  732.     U16 i;
  733.     static U16 lastKeyId = 0xffff;  /* initial value (magic number) */
  734.     /*----------------------------------------------------------------*/
  735.     /* Code Body                                                      */
  736.     /*----------------------------------------------------------------*/
  737.     if ((MsgType == WM_KEYBRD_PRESS) || (MsgType == WM_KEYBRD_RELEASE))
  738.     {
  739.         /* 
  740.          * handle the key event from the keyboard event
  741.          * find keyCode in nHotKey of nKeyPadMap's table
  742.          */
  743.         for (i = 0; i < MAX_KEYPADMAP; i++)
  744.         {
  745.             if (KeyBrdMsg->nKeyCode == nKeyPadMap[i].nHotKey)
  746.             {
  747.                 if (MsgType == WM_KEYBRD_PRESS)
  748.                 {
  749.                     MsgType = WM_KEYPRESS;
  750.                 }
  751.                 else
  752.                 {
  753.                     MsgType = WM_KEYRELEASE;
  754.                 }
  755.                 CHECK_SIMPLY_HANDLE_MULTIPLEKEY(MsgType, i) ProcessKeyEvent(MsgType, i);
  756.                 return MMI_TRUE;
  757.             }
  758.         }
  759.     }
  760.     else if ((MsgType == WM_KEYPRESS) || (MsgType == WM_KEYRELEASE))
  761.     {
  762.         /* 
  763.          * handle the key event from the mouse event
  764.          * find keyCode in nKeyCode of nKeyPadMap's table
  765.          */
  766.         for (i = 0; i < MAX_KEYPADMAP; i++)
  767.         {
  768.             if (KeyBrdMsg->nKeyCode == nKeyPadMap[i].nKeyCode)
  769.             {
  770.                 CHECK_SIMPLY_HANDLE_MULTIPLEKEY(MsgType, i);
  771.                 ProcessKeyEvent(MsgType, i);    /* Msg type press or release & keymap index */
  772.                 return MMI_TRUE;
  773.             }
  774.         }
  775.     }
  776.     /* Not handle this message */
  777.     return MMI_FALSE;
  778. }
  779. /*****************************************************************************
  780.  * FUNCTION
  781.  *  mmi_frm_set_key_handle_in_high_frequency
  782.  * DESCRIPTION
  783.  *  The dummy function for PC simulator
  784.  * PARAMETERS
  785.  *  is_enable       [IN]        
  786.  *  a(?)            [IN]        Is_enable
  787.  * RETURNS
  788.  *  void
  789.  *****************************************************************************/
  790. void mmi_frm_set_key_handle_in_high_frequency(MMI_BOOL is_enable)
  791. {
  792.     /*----------------------------------------------------------------*/
  793.     /* Local Variables                                                */
  794.     /*----------------------------------------------------------------*/
  795.     /*----------------------------------------------------------------*/
  796.     /* Code Body                                                      */
  797.     /*----------------------------------------------------------------*/
  798.     /* do nothing */
  799. }
  800. /*****************************************************************************
  801.  * FUNCTION
  802.  *  KeyTimerExpiryProc
  803.  * DESCRIPTION
  804.  *  Timer expiry procedure
  805.  * PARAMETERS
  806.  *  idEvent         [?]         
  807.  *  handle(?)       [IN]        To window
  808.  * RETURNS
  809.  *  void
  810.  *****************************************************************************/
  811. void KeyTimerExpiryProc(void *idEvent)
  812. {
  813.     /*----------------------------------------------------------------*/
  814.     /* Local Variables                                                */
  815.     /*----------------------------------------------------------------*/
  816.     U16 i;
  817.     MMI_BOOL bNeedToDo = MMI_FALSE;
  818.     /*----------------------------------------------------------------*/
  819.     /* Code Body                                                      */
  820.     /*----------------------------------------------------------------*/
  821.     /* Check the timer ID */
  822.     if ((KEY_TIMER_ID0 <= (U32) idEvent) && ((U32) idEvent < UI_TIMER_ID_BASE))
  823.     {
  824.         for (i = 0; i < MAX_KEYPADMAP; i++)
  825.         {
  826.             bNeedToDo = MMI_FALSE;
  827.             if (((S32) idEvent) == nKeyPadMap[i].nTimerId)
  828.             {
  829.                 /* Check the keypad status. It should not be KEY_EVENT_UP */
  830.                 if (nKeyPadStatus[i] == KEY_EVENT_DOWN)
  831.                 {
  832.                     nKeyPadStatus[i] = KEY_LONG_PRESS;
  833.                     bNeedToDo = MMI_TRUE;
  834.                 }
  835.                 else if ((nKeyPadStatus[i] == KEY_LONG_PRESS) || (nKeyPadStatus[i] == KEY_REPEAT))
  836.                 {
  837.                     nKeyPadStatus[i] = KEY_REPEAT;
  838.                     bNeedToDo = MMI_TRUE;
  839.                 }
  840.                 /* stop the timer even the keypad status is KEY_EVENT_UP */
  841.                 StopTimer(nKeyPadMap[i].nTimerId);
  842.                 /* Only the */
  843.                 if (bNeedToDo == MMI_TRUE)
  844.                 {
  845.                     KEYBRD_MESSAGE KeyBrdMsg;
  846.                     KeyBrdMsg.nMsgType = nKeyPadStatus[i];
  847.                     KeyBrdMsg.nKeyCode = nKeyPadMap[i].nMMIKeyCode;
  848.                     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_PROC_TIMER_EVENT_HDLR, KeyBrdMsg.nMsgType,
  849.                                KeyBrdMsg.nKeyCode));
  850.                     KeyEventHandler((KEYBRD_MESSAGE*) & KeyBrdMsg);
  851.                     StartTimer(nKeyPadMap[i].nTimerId, KEYTIMER_REPEAT, (FuncPtr) KeyTimerExpiryProc);
  852.                 }
  853.                 break;
  854.             }
  855.         }
  856.     }
  857.     else
  858.     {
  859.         MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_ERROR_KEY_TIMER_EXPIRY_HDLR, (U32) idEvent));
  860.         MMI_ASSERT(0);
  861.     }
  862. }
  863. /* MTK added, Max to solve power on race condition 0730 */
  864. #else
  865. /*****************************************************************************
  866.  * FUNCTION
  867.  *  InitKeypadBeforePWRON
  868.  * DESCRIPTION
  869.  *  Initializes keypad before power on
  870.  * PARAMETERS
  871.  *  void
  872.  * RETURNS
  873.  *  void
  874.  *****************************************************************************/
  875. void InitKeypadBeforePWRON(void)
  876. {
  877.     /*----------------------------------------------------------------*/
  878.     /* Local Variables                                                */
  879.     /*----------------------------------------------------------------*/
  880.     /*----------------------------------------------------------------*/
  881.     /* Code Body                                                      */
  882.     /*----------------------------------------------------------------*/
  883.     SetProtocolEventHandler(KeyHandleBeforePWRON, MSG_ID_MMI_EQ_KEYPAD_DETECT_IND);
  884. }
  885. /*****************************************************************************
  886.  * FUNCTION
  887.  *  KeyHandleBeforePWRON
  888.  * DESCRIPTION
  889.  *  This function detects key presses before power on
  890.  * PARAMETERS
  891.  *  paraBuff        [IN]        
  892.  * RETURNS
  893.  *  void
  894.  *****************************************************************************/
  895. void KeyHandleBeforePWRON(void *paraBuff)
  896. {
  897.     /*----------------------------------------------------------------*/
  898.     /* Local Variables                                                */
  899.     /*----------------------------------------------------------------*/
  900.     mmi_eq_keypad_detect_ind_struct *p;
  901.     kbd_data k;
  902.     /*----------------------------------------------------------------*/
  903.     /* Code Body                                                      */
  904.     /*----------------------------------------------------------------*/
  905.     p = (mmi_eq_keypad_detect_ind_struct*) paraBuff;
  906.     while ((*(p->func)) (&k) == KAL_TRUE);
  907. }
  908. /*****************************************************************************
  909.  * FUNCTION
  910.  *  mmi_frm_convert_process_key_event
  911.  * DESCRIPTION
  912.  *  convert the driver key event type to MMI key event type
  913.  *  and process the key event
  914.  * PARAMETERS
  915.  *  Keyevent        [IN]        
  916.  *  KeyMapIndex     [IN]        
  917.  *  a(?)            [IN]        ParaBuff
  918.  * RETURNS
  919.  *  void
  920.  *****************************************************************************/
  921. #if defined(__MMI_SCREEN_ROTATE__)
  922. static mmi_frm_screen_rotate_enum key_rotate = MMI_FRM_SCREEN_ROTATE_0;
  923. #endif 
  924. void mmi_frm_convert_process_key_event(U32 Keyevent, U16 KeyMapIndex)
  925. {
  926.     /*----------------------------------------------------------------*/
  927.     /* Local Variables                                                */
  928.     /*----------------------------------------------------------------*/
  929.     /*----------------------------------------------------------------*/
  930.     /* Code Body                                                      */
  931.     /*----------------------------------------------------------------*/
  932.     if (Keyevent == WM_KEYPRESS)
  933.     {
  934.     #ifdef __MMI_SCREEN_ROTATE__
  935.         key_rotate = mmi_frm_get_screen_rotate();
  936.     #endif 
  937.     }
  938. #ifdef __MMI_INTERACTIVE_PROFILNG__
  939.     if (Keyevent == WM_KEYPRESS)
  940.     {
  941.         mmi_frm_profiling_interactive_start3();
  942.     }
  943.     else if (Keyevent == WM_KEYRELEASE)
  944.     {
  945.         mmi_frm_profiling_interactive_start2();
  946.     }
  947. #endif /* __MMI_INTERACTIVE_PROFILNG__ */ 
  948. #ifdef __MMI_SCREEN_ROTATE__
  949.     switch (key_rotate)
  950.     {
  951.         case MMI_FRM_SCREEN_ROTATE_270:
  952.             switch (KeyMapIndex)
  953.             {
  954.                 case DEVICE_KEY_UP:
  955.                     KeyMapIndex = DEVICE_KEY_LEFT;
  956.                     break;
  957.                 case DEVICE_KEY_DOWN:
  958.                     KeyMapIndex = DEVICE_KEY_RIGHT;
  959.                     break;
  960.                 case DEVICE_KEY_LEFT:
  961.                     KeyMapIndex = DEVICE_KEY_DOWN;
  962.                     break;
  963.                 case DEVICE_KEY_RIGHT:
  964.                     KeyMapIndex = DEVICE_KEY_UP;
  965.                     break;
  966.             }
  967.             break;
  968.     }
  969. #endif /* __MMI_SCREEN_ROTATE__ */ 
  970.     ProcessKeyEvent(Keyevent, KeyMapIndex);
  971.     if (Keyevent == WM_KEYRELEASE)
  972.     {
  973.     #ifdef __MMI_SCREEN_ROTATE__
  974.         key_rotate = MMI_FRM_SCREEN_ROTATE_0;
  975.     #endif 
  976.     }
  977. #ifdef __MMI_INTERACTIVE_PROFILNG__
  978.     if (Keyevent == WM_KEYPRESS)
  979.     {
  980.         mmi_frm_profiling_interactive_end3();
  981.     }
  982.     else if (Keyevent == WM_KEYRELEASE)
  983.     {
  984.         mmi_frm_profiling_interactive_end2();
  985.         mmi_frm_profiling_interactive_show((U8*) L"K", MMI_FRM_PROFILING_MASK_2 | MMI_FRM_PROFILING_MASK_3);
  986.     }
  987. #endif /* __MMI_INTERACTIVE_PROFILNG__ */ 
  988. }
  989. /*****************************************************************************
  990.  * FUNCTION
  991.  *  mmi_frm_set_key_handle_in_high_frequency
  992.  * DESCRIPTION
  993.  *  This function is to process the keypad handler in high frequency mode
  994.  * PARAMETERS
  995.  *  is_enable       [IN]        
  996.  *  a(?)            [IN]        Is_enable
  997.  * RETURNS
  998.  *  void
  999.  *****************************************************************************/
  1000. void mmi_frm_set_key_handle_in_high_frequency(MMI_BOOL is_enable)
  1001. {
  1002.     /*----------------------------------------------------------------*/
  1003.     /* Local Variables                                                */
  1004.     /*----------------------------------------------------------------*/
  1005.     /*----------------------------------------------------------------*/
  1006.     /* Code Body                                                      */
  1007.     /*----------------------------------------------------------------*/
  1008.     g_process_key_in_high_frequency = is_enable;
  1009. }
  1010. /*****************************************************************************
  1011.  * FUNCTION
  1012.  *  mmi_frm_key_handle
  1013.  * DESCRIPTION
  1014.  *  This function is to process the keypad handler.
  1015.  * PARAMETERS
  1016.  *  paraBuff        [?]         
  1017.  *  a(?)            [IN]        ParaBuff
  1018.  * RETURNS
  1019.  *  void
  1020.  *****************************************************************************/
  1021. void mmi_frm_key_handle(void *paraBuff)
  1022. {
  1023.     /*----------------------------------------------------------------*/
  1024.     /* Local Variables                                                */
  1025.     /*----------------------------------------------------------------*/
  1026.     kbd_data k;
  1027.     U32 msg_count;
  1028.     mmi_eq_keypad_detect_ind_struct *p;
  1029.     /*----------------------------------------------------------------*/
  1030.     /* Code Body                                                      */
  1031.     /*----------------------------------------------------------------*/
  1032.     if (paraBuff != NULL)
  1033.     {
  1034.         drv_get_key_func new_key_ptr;
  1035.         p = (mmi_eq_keypad_detect_ind_struct*) paraBuff;
  1036.         new_key_ptr = (drv_get_key_func) (p->func);
  1037.         if (new_key_ptr != keypad_ptr)
  1038.         {
  1039.             ClearKeyEvents();
  1040.         }
  1041.         keypad_ptr = new_key_ptr;
  1042.     }
  1043.     while (1)
  1044.     {
  1045.         if ((*(keypad_ptr)) (&k) == MMI_TRUE)
  1046.         {
  1047.             if (k.Keydata[0] != KEY_INVALID)
  1048.             {
  1049.                 static U8 is_allow_key_action = MMI_TRUE;
  1050.             #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
  1051.                 kal_bool is_pen_enabled, is_pen_down;
  1052.                 mmi_pen_get_state(&is_pen_enabled, &is_pen_down);
  1053.             #endif /* defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__) */ 
  1054.             #if defined(__MMI_SLEEP_OUT_BACKLIGHT_ON__)
  1055.                 if ((IsBacklightOn() == MMI_FALSE) && (k.Keyevent == WM_KEYPRESS))
  1056.                 {
  1057.                     //KP Jerry modify for LCD Backlight don't open when press any key during keypad been locked on 2007-4-4 start
  1058.                     #ifdef __MMI_LCD_OFF_WHEN_ANYKEY_PRESSED_AND_KEYPAD_LOCKED__
  1059.       if(g_keylock_context.gKeyPadLockFlag)
  1060.                     {
  1061.                         if( (k.Keydata[0] == DEVICE_KEY_SEND) || (k.Keydata[0] == DEVICE_KEY_END) || (k.Keydata[0] == DEVICE_KEY_SK_RIGHT) ) 
  1062.        TurnOnBacklight(1); /* timer backlight control */
  1063.                     }
  1064.       else
  1065.       {
  1066.           TurnOnBacklight(1); /* timer backlight control */
  1067.       }
  1068.       #else
  1069.       TurnOnBacklight(1); /* timer backlight control */     
  1070.       #endif    
  1071.       //KP Jerry modify for LCD Backlight don't open when press any key during keypad been locked on 2007-4-4 end   
  1072.                     is_allow_key_action = MMI_FALSE;
  1073.                 }
  1074.                 else
  1075.             #endif /* defined(__MMI_SLEEP_OUT_BACKLIGHT_ON__) */ 
  1076.             #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
  1077.                 if (is_pen_down && (k.Keyevent == WM_KEYPRESS))
  1078.                 {
  1079.                     is_allow_key_action = MMI_FALSE;
  1080.                 }
  1081.                 else
  1082.             #endif /* defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__) */ 
  1083.                 if ((k.Keyevent == WM_KEYRELEASE) && (is_allow_key_action == MMI_FALSE))
  1084.                 {
  1085.                     is_allow_key_action = MMI_TRUE;
  1086.                 }
  1087.                 else if (is_allow_key_action == MMI_TRUE)
  1088.                 {
  1089.                     if ((k.Keyevent == WM_KEYPRESS) && (mmi_kbd_get_key_is_pressing_count() == 0))
  1090.                     {
  1091.                     #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
  1092.                         mmi_pen_disable();
  1093.                     #endif 
  1094.                     }
  1095.                     mmi_frm_convert_process_key_event(k.Keyevent, k.Keydata[0]);
  1096.                     if ((k.Keyevent == WM_KEYRELEASE) && (mmi_kbd_get_key_is_pressing_count() == 0))
  1097.                     {
  1098.                     #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
  1099.                         mmi_pen_enable();
  1100.                     #endif 
  1101.                     }
  1102.                 }
  1103.             }
  1104.             msg_get_ext_queue_info(mmi_ext_qid, &msg_count);
  1105.             if (msg_count > 0 || OslNumOfCircularQMsgs() > 0)
  1106.             {
  1107.                 g_keypad_flag = MMI_TRUE;
  1108.                 break;
  1109.             }
  1110.         }
  1111.         else
  1112.         {
  1113.             g_keypad_flag = MMI_FALSE;
  1114.             break;
  1115.         }
  1116.     }   /* while(1) */
  1117. }
  1118. #endif /* MMI_ON_WIN32 */
  1119. /*****************************************************************************
  1120.  * FUNCTION
  1121.  *  StopCurrentKeyPadTone
  1122.  * DESCRIPTION
  1123.  *  Stops Current keypad tone
  1124.  * PARAMETERS
  1125.  *  void
  1126.  * RETURNS
  1127.  *  void
  1128.  *****************************************************************************/
  1129. void StopCurrentKeyPadTone(void)
  1130. {
  1131.     /*----------------------------------------------------------------*/
  1132.     /* Local Variables                                                */
  1133.     /*----------------------------------------------------------------*/
  1134.     /*----------------------------------------------------------------*/
  1135.     /* Code Body                                                      */
  1136.     /*----------------------------------------------------------------*/
  1137.     if (currKeyPadTone != 0xFFFF)
  1138.     {
  1139.         AudioStopReq(currKeyPadTone);
  1140.         currKeyPadTone = 0xFFFF;
  1141.     }
  1142. }
  1143. /*****************************************************************************
  1144.  * FUNCTION
  1145.  *  ClearKeyEvents
  1146.  * DESCRIPTION
  1147.  *  Clears Keyboard buffer
  1148.  * PARAMETERS
  1149.  *  void
  1150.  * RETURNS
  1151.  *  void
  1152.  *****************************************************************************/
  1153. void ClearKeyEvents(void)
  1154. {
  1155. #ifndef MMI_ON_WIN32
  1156.     /*----------------------------------------------------------------*/
  1157.     /* Local Variables                                                */
  1158.     /*----------------------------------------------------------------*/
  1159.     extern drv_get_key_func keypad_ptr;
  1160.     kbd_data k;
  1161.     /*----------------------------------------------------------------*/
  1162.     /* Code Body                                                      */
  1163.     /*----------------------------------------------------------------*/
  1164.     MMI_TRACE((MMI_TRACE_G1_FRM, MMI_FRM_INFO_CLEAR_KEY_EVENTS_HDLR));
  1165.     if (keypad_ptr != NULL)
  1166.     {
  1167.         while ((*(keypad_ptr)) (&k) == KAL_TRUE)
  1168.         {
  1169.             /* restore state of keys */
  1170.             if (k.Keydata[0] != KEY_INVALID)
  1171.             {
  1172.                 mmi_kbd_reset_key_state(k.Keyevent, k.Keydata[0]);
  1173.             }
  1174.         }
  1175.     }
  1176.     processUpRepeatKey = 0;
  1177.     pressKey = 0;   /* 0- full up, 1- half down, 2- full down */
  1178.     StopCurrentKeyPadTone();
  1179. #if defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__)
  1180.     /*
  1181.      * We disable pen on key down and enable pen on key up. 
  1182.      * * If key down and key up events are not paired, pen is not enabled again.
  1183.      */
  1184.     mmi_pen_enable();
  1185. #endif /* defined(__MMI_TOUCH_SCREEN__) || defined(__MMI_HANDWRITING_PAD__) */ 
  1186. #endif /* MMI_ON_WIN32 */ 
  1187. }
  1188. #if defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__)
  1189. /*****************************************************************************
  1190.  * FUNCTION
  1191.  *  GetHumanVoiceToneID
  1192.  * DESCRIPTION
  1193.  *  
  1194.  * PARAMETERS
  1195.  *  MMIKeyCode      [IN]        
  1196.  * RETURNS
  1197.  *  
  1198.  *****************************************************************************/
  1199. S16 GetHumanVoiceToneID(S16 MMIKeyCode)
  1200. {
  1201.     /*----------------------------------------------------------------*/
  1202.     /* Local Variables                                                */
  1203.     /*----------------------------------------------------------------*/
  1204.     S16 i;
  1205.     U8 keypad_tone_type = GetKeypadToneType();
  1206.     /*----------------------------------------------------------------*/
  1207.     /* Code Body                                                      */
  1208.     /*----------------------------------------------------------------*/
  1209.     if (keypad_tone_type >= KEYPAD_TONE_HUMAN_VOICE_1 && keypad_tone_type <= KEYPAD_TONE_HUMAN_VOICE_6)
  1210.     {
  1211.         if (!CanPlayHumanVoiceKeyTone())
  1212.         {
  1213.             return -1;
  1214.         }
  1215.         if (MMIKeyCode >= KEY_0 && MMIKeyCode <= KEY_9)
  1216.         {
  1217.             i = MMIKeyCode - KEY_0;
  1218.         }
  1219.         else if (MMIKeyCode == KEY_STAR)
  1220.         {
  1221.             i = 10;
  1222.         }
  1223.         else if (MMIKeyCode == KEY_POUND)
  1224.         {
  1225.             i = 11;
  1226.         }
  1227.         else
  1228.         {
  1229.             i = -1;
  1230.         }
  1231.         if (i >= 0)
  1232.         {
  1233.             return (S16) ((keypad_tone_type - KEYPAD_TONE_HUMAN_VOICE_1) * 13 + i + MIN_HUMAN_VOICE_ID);
  1234.         }
  1235.     }
  1236.     return -1;
  1237. }
  1238. #endif /* defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__) */ 
  1239. #if defined(__MMI_CUST_KEYPAD_TONE__)
  1240. /*****************************************************************************
  1241.  * FUNCTION
  1242.  *  GetCustKeyPadToneID
  1243.  * DESCRIPTION
  1244.  *  
  1245.  * PARAMETERS
  1246.  *  MMIKeyCode      [IN]        
  1247.  * RETURNS
  1248.  *  
  1249.  *****************************************************************************/
  1250. S16 GetCustKeyPadToneID(S16 MMIKeyCode)
  1251. {
  1252.     /*----------------------------------------------------------------*/
  1253.     /* Local Variables                                                */
  1254.     /*----------------------------------------------------------------*/
  1255.     U8 keypad_tone_type = GetKeypadToneType();
  1256.     /*----------------------------------------------------------------*/
  1257.     /* Code Body                                                      */
  1258.     /*----------------------------------------------------------------*/
  1259.     if (keypad_tone_type >= KEYPAD_TONE_CUST_1 && keypad_tone_type <= KEYPAD_TONE_CUST_6)
  1260.     {
  1261.         if (!CanPlayCustKeyTone())
  1262.         {
  1263.             return -1;
  1264.         }
  1265.         return (S16) (keypad_tone_type - KEYPAD_TONE_CUST_1 + MIN_KEYPAD_TONE_ID);
  1266.     }
  1267.     return -1;
  1268. }
  1269. #endif /* defined(__MMI_CUST_KEYPAD_TONE__) */ 
  1270. /*****************************************************************************
  1271.  * FUNCTION
  1272.  *  GetKeypadTone
  1273.  * DESCRIPTION
  1274.  *  
  1275.  * PARAMETERS
  1276.  *  MMIKeyCode      [IN]        
  1277.  * RETURNS
  1278.  *  
  1279.  *****************************************************************************/
  1280. U16 GetKeypadTone(S16 MMIKeyCode)
  1281. {
  1282.     /*----------------------------------------------------------------*/
  1283.     /* Local Variables                                                */
  1284.     /*----------------------------------------------------------------*/
  1285.     U8 is_found = MMI_FALSE;
  1286.     S16 i;
  1287.     /*----------------------------------------------------------------*/
  1288.     /* Code Body                                                      */
  1289.     /*----------------------------------------------------------------*/
  1290. #if defined(__MMI_CUST_KEYPAD_TONE__)
  1291.     if ((i = GetCustKeyPadToneID(MMIKeyCode)) >= 0)
  1292.     {
  1293.         return (U16) i;
  1294.     }
  1295. #endif /* defined(__MMI_CUST_KEYPAD_TONE__) */ 
  1296. #if defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__)
  1297.     /* MTK added by Tim for human voice keypad tone */
  1298.     if ((i = GetHumanVoiceToneID(MMIKeyCode)) >= 0)
  1299.     {
  1300.         return (U16) i;
  1301.     }
  1302. #endif /* defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__) */ 
  1303.     for (i = 0; i < MAX_KEYPADMAP; i++)
  1304.     {
  1305.         if (MMIKeyCode == nKeyPadMap[i].nMMIKeyCode)
  1306.         {
  1307.             is_found = MMI_TRUE;
  1308.             break;
  1309.         }
  1310.     }
  1311.     MMI_ASSERT(is_found == MMI_TRUE);
  1312.     return (U16) nKeyPadMap[i].KeyPadTone;
  1313. }
  1314. /*****************************************************************************
  1315.  * FUNCTION
  1316.  *  GetCurKeypadTone
  1317.  * DESCRIPTION
  1318.  *  
  1319.  * PARAMETERS
  1320.  *  void
  1321.  * RETURNS
  1322.  *  
  1323.  *****************************************************************************/
  1324. U16 GetCurKeypadTone(void)
  1325. {
  1326.     /*----------------------------------------------------------------*/
  1327.     /* Local Variables                                                */
  1328.     /*----------------------------------------------------------------*/
  1329.     /*----------------------------------------------------------------*/
  1330.     /* Code Body                                                      */
  1331.     /*----------------------------------------------------------------*/
  1332.     return currKeyPadTone;
  1333. }
  1334. /*****************************************************************************
  1335.  * FUNCTION
  1336.  *  SetCurKeypadTone
  1337.  * DESCRIPTION
  1338.  *  
  1339.  * PARAMETERS
  1340.  *  KeyTone     [IN]        
  1341.  * RETURNS
  1342.  *  
  1343.  *****************************************************************************/
  1344. U8 SetCurKeypadTone(U16 KeyTone)
  1345. {
  1346.     /*----------------------------------------------------------------*/
  1347.     /* Local Variables                                                */
  1348.     /*----------------------------------------------------------------*/
  1349.     /*----------------------------------------------------------------*/
  1350.     /* Code Body                                                      */
  1351.     /*----------------------------------------------------------------*/
  1352.     currKeyPadTone = KeyTone;
  1353.     return MMI_TRUE;
  1354. }
  1355. /*****************************************************************************
  1356.  * FUNCTION
  1357.  *  GetKeypadDuration
  1358.  * DESCRIPTION
  1359.  *  
  1360.  * PARAMETERS
  1361.  *  MMIKeyCode      [IN]        
  1362.  * RETURNS
  1363.  *  
  1364.  *****************************************************************************/
  1365. U8 GetKeypadDuration(S16 MMIKeyCode)
  1366. {
  1367.     /*----------------------------------------------------------------*/
  1368.     /* Local Variables                                                */
  1369.     /*----------------------------------------------------------------*/
  1370.     U8 is_found = MMI_FALSE;
  1371.     U16 i;
  1372.     /*----------------------------------------------------------------*/
  1373.     /* Code Body                                                      */
  1374.     /*----------------------------------------------------------------*/
  1375. #if defined(__MMI_CUST_KEYPAD_TONE__)
  1376.     if (GetCustKeyPadToneID(MMIKeyCode) >= 0)
  1377.     {
  1378.         return DEVICE_AUDIO_PLAY_ONCE;
  1379.     }
  1380. #endif /* defined(__MMI_CUST_KEYPAD_TONE__) */ 
  1381. #if defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__)
  1382.     /* MTK added by Tim for human voice keypad tone */
  1383.     if (GetHumanVoiceToneID(MMIKeyCode) >= 0)
  1384.     {
  1385.         return DEVICE_AUDIO_PLAY_ONCE;
  1386.     }
  1387. #endif /* defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__) */ 
  1388.     for (i = 0; i < MAX_KEYPADMAP; i++)
  1389.     {
  1390.         if (MMIKeyCode == nKeyPadMap[i].nMMIKeyCode)
  1391.         {
  1392.             is_found = MMI_TRUE;
  1393.             break;
  1394.         }
  1395.     }
  1396.     MMI_ASSERT(is_found == MMI_TRUE);
  1397.     /* return KeyToneMap[KeyCode].KeyPadDuration; */
  1398.     return nKeyPadMap[i].KeyPadDuration;
  1399. }
  1400. /*****************************************************************************
  1401.  * FUNCTION
  1402.  *  mmi_kbd_reverse_code
  1403.  * DESCRIPTION
  1404.  *  This function reversly get the key code of L4/Driver.
  1405.  * PARAMETERS
  1406.  *  mmi_key_code        [IN]        Key code of MMI
  1407.  * RETURNS
  1408.  *  key code of L4/Driver
  1409.  *****************************************************************************/
  1410. S16 mmi_kbd_reverse_code(S16 mmi_key_code)
  1411. {
  1412.     /*----------------------------------------------------------------*/
  1413.     /* Local Variables                                                */
  1414.     /*----------------------------------------------------------------*/
  1415.     MMI_BOOL is_found = MMI_FALSE;
  1416.     U16 i;
  1417.     /*----------------------------------------------------------------*/
  1418.     /* Code Body                                                      */
  1419.     /*----------------------------------------------------------------*/
  1420.     for (i = 0; i < MAX_KEYPADMAP; i++)
  1421.     {
  1422.         if (mmi_key_code == nKeyPadMap[i].nMMIKeyCode)
  1423.         {
  1424.             is_found = MMI_TRUE;
  1425.             break;
  1426.         }
  1427.     }
  1428.     MMI_ASSERT(is_found == MMI_TRUE);
  1429.     /* in current disign, keycode is equavlent to key code */
  1430.     MMI_ASSERT(i == nKeyPadMap[i].nKeyCode);
  1431.     PRINT_INFORMATION_2((MMI_TRACE_G1_FRM, "mmi_kbd_reverse_code: return %d n", nKeyPadMap[i].nKeyCode));
  1432.     return (nKeyPadMap[i].nKeyCode);
  1433. }
  1434. /*****************************************************************************
  1435.  * FUNCTION
  1436.  *  mmi_kbd_reset_key_state
  1437.  * DESCRIPTION
  1438.  *  This function set the keypad state according corrent key event.
  1439.  *  But keypad handler is not executed.
  1440.  * PARAMETERS
  1441.  *  MsgType         [IN]        Type of key event
  1442.  *  KeyMapIndex     [IN]        Key index
  1443.  * RETURNS
  1444.  *  void
  1445.  *****************************************************************************/
  1446. void mmi_kbd_reset_key_state(U32 MsgType, U16 KeyMapIndex)
  1447. {
  1448.     /*----------------------------------------------------------------*/
  1449.     /* Local Variables                                                */
  1450.     /*----------------------------------------------------------------*/
  1451.     /*----------------------------------------------------------------*/
  1452.     /* Code Body                                                      */
  1453.     /*----------------------------------------------------------------*/
  1454.     if (MsgType == WM_KEYPRESS)
  1455.     {
  1456.         nKeyPadStatus[KeyMapIndex] = KEY_EVENT_DOWN;
  1457.         key_is_pressing_count++;
  1458.     }
  1459.     else if (MsgType == WM_KEYRELEASE)
  1460.     {
  1461.         nKeyPadStatus[KeyMapIndex] = KEY_EVENT_UP;
  1462.         key_is_pressing_count--;
  1463.     }
  1464.     /*
  1465.      * else 
  1466.      * others won't change key state.
  1467.      */
  1468. }
  1469. /*****************************************************************************
  1470.  * FUNCTION
  1471.  *  GetMaxPresentAllKeys
  1472.  * DESCRIPTION
  1473.  *  This function is to get all MMI keys.
  1474.  * PARAMETERS
  1475.  *  void
  1476.  * RETURNS
  1477.  *  void
  1478.  *****************************************************************************/
  1479. U8 GetMaxPresentAllKeys(void)
  1480. {
  1481.     /*----------------------------------------------------------------*/
  1482.     /* Local Variables                                                */
  1483.     /*----------------------------------------------------------------*/
  1484.     /*----------------------------------------------------------------*/
  1485.     /* Code Body                                                      */
  1486.     /*----------------------------------------------------------------*/
  1487.     return MAX_PRESENTALLKEYS;
  1488. }
  1489. /*****************************************************************************
  1490.  * FUNCTION
  1491.  *  GetMaxPresentDigitsKeys
  1492.  * DESCRIPTION
  1493.  *  This function is to get all MMI digits keys.
  1494.  * PARAMETERS
  1495.  *  void
  1496.  * RETURNS
  1497.  *  void
  1498.  *****************************************************************************/
  1499. U8 GetMaxPresentDigitsKeys(void)
  1500. {
  1501.     /*----------------------------------------------------------------*/
  1502.     /* Local Variables                                                */
  1503.     /*----------------------------------------------------------------*/
  1504.     /*----------------------------------------------------------------*/
  1505.     /* Code Body                                                      */
  1506.     /*----------------------------------------------------------------*/
  1507.     return MAX_PRESENTDIGITSKEYS;
  1508. }
  1509. /*****************************************************************************
  1510.  * FUNCTION
  1511.  *  mmi_frm_kbd_set_tone_state
  1512.  * DESCRIPTION
  1513.  *  This function is to chage the state of keypad tone.
  1514.  *  To prevent abnormal cases, keypad tone will be stopped before state changed.
  1515.  * PARAMETERS
  1516.  *  state       [IN]        
  1517.  * RETURNS
  1518.  *  void
  1519.  *****************************************************************************/
  1520. void mmi_frm_kbd_set_tone_state(mmi_frm_kbd_tone_state_enum state)
  1521. {
  1522.     /*----------------------------------------------------------------*/
  1523.     /* Local Variables                                                */
  1524.     /*----------------------------------------------------------------*/
  1525.     /*----------------------------------------------------------------*/
  1526.     /* Code Body                                                      */
  1527.     /*----------------------------------------------------------------*/
  1528.     /* not stop original keypage tone. next key tone is able to stop previous tone if still exist */ 
  1529.     // StopCurrentKeyPadTone();
  1530.     frm_p->key_tone_state = state;
  1531. }
  1532. /*****************************************************************************
  1533.  * FUNCTION
  1534.  *  mmi_frm_kbd_get_key_tone_state
  1535.  * DESCRIPTION
  1536.  *  Get the state to see if keypad tone is disabled
  1537.  * PARAMETERS
  1538.  *  void
  1539.  * RETURNS
  1540.  *  state of keypad tone.
  1541.  *****************************************************************************/
  1542. mmi_frm_kbd_tone_state_enum mmi_frm_kbd_get_key_tone_state(void)
  1543. {
  1544.     /*----------------------------------------------------------------*/
  1545.     /* Local Variables                                                */
  1546.     /*----------------------------------------------------------------*/
  1547.     /*----------------------------------------------------------------*/
  1548.     /* Code Body                                                      */
  1549.     /*----------------------------------------------------------------*/
  1550.     return frm_p->key_tone_state;
  1551. }
  1552. /*****************************************************************************
  1553.  * FUNCTION
  1554.  *  mmi_frm_kbd_reg_pre_key_hdlr
  1555.  * DESCRIPTION
  1556.  *  Regiester function to execute before general keypad handler.
  1557.  * PARAMETERS
  1558.  *  func        [IN]        
  1559.  * RETURNS
  1560.  *  state of keypad tone.(?)
  1561.  *****************************************************************************/
  1562. void mmi_frm_kbd_reg_pre_key_hdlr(PsKeyProcessCBPtr func)
  1563. {
  1564.     /*----------------------------------------------------------------*/
  1565.     /* Local Variables                                                */
  1566.     /*----------------------------------------------------------------*/
  1567.     /*----------------------------------------------------------------*/
  1568.     /* Code Body                                                      */
  1569.     /*----------------------------------------------------------------*/
  1570.     frm_p->kbd_pre_func = func;
  1571. }
  1572. /*****************************************************************************
  1573.  * FUNCTION
  1574.  *  mmi_frm_kbd_reg_post_key_hdlr
  1575.  * DESCRIPTION
  1576.  *  Regiester function to execute afer general keypad handler.
  1577.  * PARAMETERS
  1578.  *  func        [IN]        
  1579.  * RETURNS
  1580.  *  state of keypad tone.(?)
  1581.  *****************************************************************************/
  1582. void mmi_frm_kbd_reg_post_key_hdlr(PsKeyProcessCBPtr func)
  1583. {
  1584.     /*----------------------------------------------------------------*/
  1585.     /* Local Variables                                                */
  1586.     /*----------------------------------------------------------------*/
  1587.     /*----------------------------------------------------------------*/
  1588.     /* Code Body                                                      */
  1589.     /*----------------------------------------------------------------*/
  1590.     frm_p->kbd_post_func = func;
  1591. }
  1592. /*****************************************************************************
  1593.  * FUNCTION
  1594.  *  mmi_frm_kbd_is_tone_enabled
  1595.  * DESCRIPTION
  1596.  *  Function to check if keypad tone can be played or not
  1597.  * PARAMETERS
  1598.  *  key_code        [IN]        Key code
  1599.  *  key_type        [IN]        Key type
  1600.  * RETURNS
  1601.  *  TRUE if the keypad tone shall be played by framework; otherwise, FALSE.
  1602.  *****************************************************************************/
  1603. BOOL mmi_frm_kbd_is_tone_enabled(S16 key_code, S16 key_type)
  1604. {
  1605.     /*----------------------------------------------------------------*/
  1606.     /* Local Variables                                                */
  1607.     /*----------------------------------------------------------------*/
  1608.     U8 tone_type = GetKeypadToneType();
  1609.     /*----------------------------------------------------------------*/
  1610.     /* Code Body                                                      */
  1611.     /*----------------------------------------------------------------*/
  1612.     if (tone_type == KEYPAD_SILENT  /* silent profile */
  1613.         || frm_p->key_tone_state == MMI_KEY_TONE_DISABLED)
  1614.     {
  1615.         return FALSE;
  1616.     }
  1617.     else if (frm_p->key_tone_state == MMI_KEY_VOL_TONE_DISABLED)
  1618.     {
  1619.         /* disable volume keypad tone */
  1620.         if (key_code == KEY_VOL_UP || key_code == KEY_VOL_DOWN)
  1621.         {
  1622.             return FALSE;
  1623.         }
  1624.     }
  1625.     else if (frm_p->key_tone_state == MMI_KEY_VOL_UP_DOWN_TONE_DISABLED)
  1626.     {
  1627.         /* disable volume keypad tone */
  1628.         if (key_code == KEY_VOL_UP || key_code == KEY_VOL_DOWN || 
  1629.             key_code == KEY_UP_ARROW || key_code == KEY_DOWN_ARROW)
  1630.         {
  1631.             return FALSE;
  1632.         }
  1633.     }
  1634.     else if (frm_p->key_tone_state == MMI_KEY_RIGHT_LEFT_ARROW_TONE_DISABLED)
  1635.     {
  1636.         if (key_code == KEY_RIGHT_ARROW || key_code == KEY_LEFT_ARROW)
  1637.         {
  1638.             return FALSE;
  1639.         }
  1640.     }
  1641.     return TRUE;
  1642. }
  1643. /*****************************************************************************
  1644.  * FUNCTION
  1645.  *  mmi_frm_play_keypad_tone
  1646.  * DESCRIPTION
  1647.  *  Function to play corresponding keypad tone
  1648.  * PARAMETERS
  1649.  *  key_code        [IN]        Key code
  1650.  * RETURNS
  1651.  *  void
  1652.  *****************************************************************************/
  1653. void mmi_frm_play_keypad_tone(S16 key_code)
  1654. {
  1655.     /*----------------------------------------------------------------*/
  1656.     /* Local Variables                                                */
  1657.     /*----------------------------------------------------------------*/
  1658.     U8 tone_type = GetKeypadToneType();
  1659.     /*----------------------------------------------------------------*/
  1660.     /* Code Body                                                      */
  1661.     /*----------------------------------------------------------------*/
  1662.     if (tone_type == KEYPAD_CLICK)
  1663.     {
  1664.         AudioPlayReq(TONE_KEY_CLICK, DEVICE_AUDIO_PLAY_ONCE);
  1665.     }
  1666.     else
  1667.     {
  1668.         SetCurKeypadTone(GetKeypadTone(key_code));
  1669.         frm_p->key_tone_id = GetCurKeypadTone();
  1670.         frm_p->key_tone_duration = GetKeypadDuration(key_code);
  1671.         AudioPlayReq(frm_p->key_tone_id, frm_p->key_tone_duration);
  1672.     }
  1673. }
  1674. /*****************************************************************************
  1675.  * FUNCTION
  1676.  *  mmi_frm_stop_keypad_tone
  1677.  * DESCRIPTION
  1678.  *  Function to stop corresponding keypad tone
  1679.  * PARAMETERS
  1680.  *  key_code        [IN]        Key code
  1681.  * RETURNS
  1682.  *  void
  1683.  *****************************************************************************/
  1684. void mmi_frm_stop_keypad_tone(S16 key_code)
  1685. {
  1686.     /*----------------------------------------------------------------*/
  1687.     /* Local Variables                                                */
  1688.     /*----------------------------------------------------------------*/
  1689.     U8 tone_type = GetKeypadToneType();
  1690.     /*----------------------------------------------------------------*/
  1691.     /* Code Body                                                      */
  1692.     /*----------------------------------------------------------------*/
  1693.     if (tone_type == KEYPAD_TONE)
  1694.     {
  1695.         SetCurKeypadTone(0xFFFF);
  1696.         if (GetKeypadDuration(key_code) == DEVICE_AUDIO_PLAY_INFINITE)
  1697.         {
  1698.             AudioStopReq(GetKeypadTone(key_code));
  1699.         }
  1700.     }
  1701. #if defined(__MMI_CUST_KEYPAD_TONE__)
  1702.     else if (tone_type >= KEYPAD_TONE_CUST_1 && tone_type <= KEYPAD_TONE_CUST_6
  1703. #if defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__)
  1704.              && frm_p->key_tone_id < MIN_HUMAN_VOICE_ID)    /* MIN_KEYPAD_TONE_ID > MIN_HUMAN_VOICE_ID */
  1705. #else 
  1706.              && frm_p->key_tone_id < MIN_KEYPAD_TONE_ID)
  1707. #endif 
  1708. {
  1709.     SetCurKeypadTone(0xFFFF);
  1710.     if (frm_p->key_tone_duration == DEVICE_AUDIO_PLAY_INFINITE)
  1711.     {
  1712.         AudioStopReq(frm_p->key_tone_id);
  1713.     }
  1714. }
  1715. #endif /* defined(__MMI_CUST_KEYPAD_TONE__) */ 
  1716. #if defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__)
  1717.     else
  1718. if (tone_type >= KEYPAD_TONE_HUMAN_VOICE_1 && tone_type <= KEYPAD_TONE_HUMAN_VOICE_6 && frm_p->key_tone_id < MIN_HUMAN_VOICE_ID)        /* MIN_KEYPAD_TONE_ID > MIN_HUMAN_VOICE_ID */
  1719. {
  1720.     SetCurKeypadTone(0xFFFF);
  1721.     if (frm_p->key_tone_duration == DEVICE_AUDIO_PLAY_INFINITE)
  1722.     {
  1723.         AudioStopReq(frm_p->key_tone_id);
  1724.     }
  1725. }
  1726. #endif /* defined(__MMI_HUMAN_VOICE_KEYPAD_TONE__) */ 
  1727. }
  1728. /*****************************************************************************
  1729.  * FUNCTION
  1730.  *  mmi_kbn_key_tone_hdlr
  1731.  * DESCRIPTION
  1732.  *  Function to handle general keypad tones
  1733.  * PARAMETERS
  1734.  *  eventKey        [IN]        Key event
  1735.  * RETURNS
  1736.  *  TRUE if general key tone plays; otherwise, FALSE.
  1737.  *****************************************************************************/
  1738. U8 mmi_kbn_key_tone_hdlr(KEYBRD_MESSAGE *eventKey)
  1739. {
  1740.     /*----------------------------------------------------------------*/
  1741.     /* Local Variables                                                */
  1742.     /*----------------------------------------------------------------*/
  1743.     /*----------------------------------------------------------------*/
  1744.     /* Code Body                                                      */
  1745.     /*----------------------------------------------------------------*/
  1746.     /* MTK added by JL 031220 for mute microphone to avoid the conflict with speaker and cause the DTMF frequency error */
  1747.     PRINT_INFORMATION_2((MMI_TRACE_G1_FRM, "key event <<code %d, type %d>> n", eventKey->nKeyCode,
  1748.                          eventKey->nMsgType));
  1749.     if (eventKey->nKeyCode == KEY_INVALID)
  1750.     {
  1751.         return MMI_TRUE;
  1752.     }
  1753.     /* To Play Tones */
  1754.     if (eventKey->nMsgType == KEY_EVENT_DOWN)
  1755.     {
  1756.         if (mmi_frm_kbd_is_tone_enabled(eventKey->nKeyCode, eventKey->nMsgType))
  1757.         {
  1758.             mmi_frm_play_keypad_tone(eventKey->nKeyCode);
  1759.         }
  1760.     }
  1761.     else if (eventKey->nMsgType == KEY_EVENT_UP)
  1762.     {
  1763.         mmi_frm_stop_keypad_tone(eventKey->nKeyCode);
  1764.     }
  1765.     #ifdef MMI_ON_WIN32
  1766.     if (((S16) eventKey->nMsgType == WM_KEYBRD_PRESS || (S16) eventKey->nMsgType == WM_KEYBRD_RELEASE))
  1767.     {
  1768.         MMI_system_keybord_handler((S16) eventKey->nKeyCode, (S16) eventKey->nMsgType);
  1769.         return MMI_TRUE;
  1770.     }
  1771.     #endif /* MMI_ON_WIN32 */ /* 0 */
  1772.     //move to Framework ExecuteCurrKeyHandler((S16)eventKey->nKeyCode,(S16)eventKey->nMsgType);
  1773.     //To continue to handler framework process, if false.
  1774.     return MMI_FALSE;
  1775. }
  1776. /*****************************************************************************
  1777.  * FUNCTION
  1778.  *  mmi_kbd_app_key_hdlr
  1779.  * DESCRIPTION
  1780.  *  Function to handle general appplication events
  1781.  * PARAMETERS
  1782.  *  eventKey        [?]         
  1783.  *  key_code(?)     [IN]        Key code
  1784.  * RETURNS
  1785.  *  U8, if return true, Framework will not control the key, otherwse.
  1786.  *****************************************************************************/
  1787. extern void mmi_idle_key_event_backlight_check(void);
  1788. extern void mmi_idle_key_event_keypad_lock_check(KEYBRD_MESSAGE *eventKey);
  1789. U8 mmi_kbd_app_key_hdlr(KEYBRD_MESSAGE *eventKey)
  1790. {
  1791.     /*----------------------------------------------------------------*/
  1792.     /* Local Variables                                                */
  1793.     /*----------------------------------------------------------------*/
  1794.     /*----------------------------------------------------------------*/
  1795.     /* Code Body                                                      */
  1796.     /*----------------------------------------------------------------*/
  1797.     /* diamond, 2006/02/06 Move these checking codes to idleapp.c */
  1798.     mmi_idle_key_event_backlight_check();
  1799.     mmi_idle_key_event_keypad_lock_check(eventKey);
  1800.     return mmi_kbn_key_tone_hdlr(eventKey);
  1801. }
  1802. /*****************************************************************************
  1803.  * FUNCTION
  1804.  *  mmi_kbd_set_concurrent_mode
  1805.  * DESCRIPTION
  1806.  *  Function to trun on/off concurrent mode. Key concurrent mode is to allow
  1807.  *  application handling (through call-back) concurrent two-key events on keypad.
  1808.  *  For example, user presses "up arrow" key while "left arrow" is pressing.
  1809.  *  In general cases, the mode is turned off to prevent applicaiton to make mistake
  1810.  *  at processing key events.
  1811.  * PARAMETERS
  1812.  *  mode        [IN]        Concurrent mode
  1813.  * RETURNS
  1814.  *  void
  1815.  *****************************************************************************/
  1816. void mmi_kbd_set_concurrent_mode(MMI_BOOL mode)
  1817. {
  1818. #if defined(__TWO_KEY_DETECTION_SWITCHABLE__)
  1819.     /*----------------------------------------------------------------*/
  1820.     /* Local Variables                                                */
  1821.     /*----------------------------------------------------------------*/
  1822.     /*----------------------------------------------------------------*/
  1823.     /* Code Body                                                      */
  1824.     /*----------------------------------------------------------------*/
  1825. #if !defined(MMI_ON_WIN32)
  1826.     if (mode == MMI_TRUE)
  1827.     {
  1828.         /* enable 2 key simultanenous detection */
  1829.         kbd_two_key_detection_switch(KAL_TRUE);
  1830.     }
  1831.     else
  1832.     {
  1833.         /* disable 2 key simultanenous detection */
  1834.         kbd_two_key_detection_switch(KAL_FALSE);
  1835.     }
  1836. #endif /* !defined(MMI_ON_WIN32) */ 
  1837.     ClearKeyEvents();
  1838.     g_kbd_concurrent_key_mode = mode;
  1839. #endif /* defined(__TWO_KEY_DETECTION_SWITCHABLE__) */ 
  1840.     return;
  1841. }
  1842. /*****************************************************************************
  1843.  * FUNCTION
  1844.  *  mmi_kbd_get_concurrent_mode
  1845.  * DESCRIPTION
  1846.  *  Function to handle transparent mode
  1847.  * PARAMETERS
  1848.  *  void
  1849.  * RETURNS
  1850.  *  MMI_TRUE if at coucurrent mode; MMI_FALSE if not.
  1851.  *****************************************************************************/
  1852. MMI_BOOL mmi_kbd_get_concurrent_mode(void)
  1853. {
  1854.     /*----------------------------------------------------------------*/
  1855.     /* Local Variables                                                */
  1856.     /*----------------------------------------------------------------*/
  1857.     /*----------------------------------------------------------------*/
  1858.     /* Code Body                                                      */
  1859.     /*----------------------------------------------------------------*/
  1860.     return g_kbd_concurrent_key_mode;
  1861. }
  1862. /*****************************************************************************
  1863.  * FUNCTION
  1864.  *  mmi_kbd_get_key_is_pressing_count
  1865.  * DESCRIPTION
  1866.  *  Function to query count of keys are under pressing state
  1867.  * PARAMETERS
  1868.  *  void
  1869.  * RETURNS
  1870.  *  count of keys are under pressing state
  1871.  *****************************************************************************/
  1872. U8 mmi_kbd_get_key_is_pressing_count(void)
  1873. {
  1874.     /*----------------------------------------------------------------*/
  1875.     /* Local Variables                                                */
  1876.     /*----------------------------------------------------------------*/
  1877.     /*----------------------------------------------------------------*/
  1878.     /* Code Body                                                      */
  1879.     /*----------------------------------------------------------------*/
  1880.     return key_is_pressing_count;
  1881. }
  1882. /*****************************************************************************
  1883.  * FUNCTION
  1884.  mmi_frm_set_default_power_onoff_key
  1885.  * DESCRIPTION
  1886.  *  set power on/off key to default handler
  1887.  * PARAMETERS
  1888.  *  void
  1889.  * RETURNS
  1890.  *  void
  1891.  *****************************************************************************/
  1892. void mmi_frm_set_default_power_onoff_key(void)
  1893. {
  1894. #ifdef __MMI_POWER_ON_OFF_BY_POWER_KEY__
  1895.     SetKeyHandler(NULL, KEY_END, KEY_LONG_PRESS);
  1896.     SetKeyHandler(ShutdownSystemOperation, KEY_POWER, KEY_LONG_PRESS);
  1897. #else
  1898.     SetKeyHandler(ShutdownSystemOperation, KEY_END, KEY_LONG_PRESS);
  1899. #endif /* __MMI_POWER_ON_OFF_BY_POWER_KEY__ */
  1900. }