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

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.  * MessagesMiscell.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   MAUI
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   This file is intends for MMI SMS APP.
  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.  *
  87.  * removed!
  88.  * removed!
  89.  * removed!
  90.  *
  91.  * removed!
  92.  * removed!
  93.  * removed!
  94.  *
  95.  * removed!
  96.  * removed!
  97.  * removed!
  98.  *
  99.  * removed!
  100.  * removed!
  101.  * removed!
  102.  *
  103.  * removed!
  104.  * removed!
  105.  * removed!
  106.  *
  107.  * removed!
  108.  * removed!
  109.  * removed!
  110.  *
  111.  * removed!
  112.  * removed!
  113.  * removed!
  114.  *
  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.  * removed!
  160.  * removed!
  161.  * removed!
  162.  *
  163.  * removed!
  164.  * removed!
  165.  * removed!
  166.  *
  167.  * removed!
  168.  * removed!
  169.  * removed!
  170.  *
  171.  * removed!
  172.  * removed!
  173.  * removed!
  174.  *
  175.  * removed!
  176.  * removed!
  177.  * removed!
  178.  *
  179.  * removed!
  180.  * removed!
  181.  * removed!
  182.  *
  183.  * removed!
  184.  * removed!
  185.  * removed!
  186.  *
  187.  * removed!
  188.  * removed!
  189.  * removed!
  190.  *
  191.  * removed!
  192.  * removed!
  193.  * removed!
  194.  *
  195.  * removed!
  196.  * removed!
  197.  * removed!
  198.  *
  199.  * removed!
  200.  * removed!
  201.  * removed!
  202.  *
  203.  * removed!
  204.  * removed!
  205.  * removed!
  206.  *
  207.  * removed!
  208.  * removed!
  209.  * removed!
  210.  *
  211.  * removed!
  212.  * removed!
  213.  * removed!
  214.  *
  215.  * removed!
  216.  * removed!
  217.  * removed!
  218.  *
  219.  * removed!
  220.  * removed!
  221.  * removed!
  222.  *
  223.  * removed!
  224.  * removed!
  225.  * removed!
  226.  *
  227.  * removed!
  228.  * removed!
  229.  * removed!
  230.  *
  231.  * removed!
  232.  * removed!
  233.  * removed!
  234.  *
  235.  * removed!
  236.  * removed!
  237.  * removed!
  238.  *
  239.  * removed!
  240.  * removed!
  241.  * removed!
  242.  *
  243.  * removed!
  244.  * removed!
  245.  * removed!
  246.  *
  247.  * removed!
  248.  * removed!
  249.  * removed!
  250.  *
  251.  * removed!
  252.  * removed!
  253.  * removed!
  254.  *
  255.  * removed!
  256.  * removed!
  257.  * removed!
  258.  *
  259.  * removed!
  260.  * removed!
  261.  * removed!
  262.  *
  263.  * removed!
  264.  * removed!
  265.  * removed!
  266.  *
  267.  * removed!
  268.  * removed!
  269.  * removed!
  270.  *
  271.  *------------------------------------------------------------------------------
  272.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  273.  *============================================================================
  274.  ****************************************************************************/
  275. /**
  276.  * Copyright Notice
  277.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  278.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  279.  *  (It is illegal to remove this copyright notice from this software or any
  280.  *  portion of it)
  281.  */
  282. /******************************************************************************
  283.    FILENAME : MessagesMiscell.c
  284.    PURPOSE     : 
  285.    REMARKS     : nil
  286.    AUTHOR      : Magesh k 
  287.    DATE     : 01-01-2003
  288. ******************************************************************************/
  289. #ifdef __MOD_SMSAL__
  290. /*  Include: MMI header file */
  291. #include "MMI_features.h"
  292. #include "stdC.h"
  293. #include "L4Dr1.h"
  294. #include "PixtelDataTypes.h"
  295. /* ... Add More MMI header */
  296. #include "EventsGprot.h"
  297. #include "HistoryGprot.h"
  298. #include "GlobalMenuItems.h"
  299. #include "GlobalConstants.h"
  300. #include "Globaldefs.h"
  301. #include "wgui_categories.h"
  302. #include "CustMenuRes.h"
  303. #include "CommonScreens.h"
  304. #include "Unicodexdcl.h"
  305. #include "TimerEvents.h"
  306. #include "DebugInitDef.h"
  307. #include "ProtocolEvents.h"
  308. /* ...Add MSG header */
  309. #include "customer_ps_inc.h"
  310. #include "mmi_msg_context.h"
  311. #include "MessagesL4Def.h"
  312. #include "MessagesResourceData.h"
  313. #include "MessagesMiscell.h"
  314. #include "MessagesExDcl.h"
  315. #include "SmsGuiInterfaceProt.h"
  316. #include "SmsGuiInterfaceType.h"
  317. #include "SmsPsHandler.h"
  318. #include "CellBroadcastType.h"
  319. // #include "QueueGprot.h"
  320. #include "Gui_ems.h"
  321. #include "wgui_ems.h"
  322. #include "wgui_categories_ems.h"//062706 revise
  323. #include "GSM7BitDefaultAlphabet.h"
  324. #include "SimDetectionGProt.h"
  325. /*  */
  326. #include "CSP.h"
  327. #include "IdleAppDef.h"
  328. #include "CallManagementGprot.h"
  329. #include "CallStructureManagementProt.h"
  330. #include "PhoneBookGprot.h"
  331. #include "SSCStringHandle.h"
  332. #include "AlarmFrameworkProt.h"
  333. #include "ProfileGprots.h"
  334. #include "gpioInc.h"
  335. #include "KeyBrd.h"
  336. #include "SubLCDHistoryGprot.h"
  337. /*  */
  338. #ifdef __MMI_MESSAGES_CLUB__
  339. #include "mmiapi_res.h"
  340. #endif 
  341. #if defined(OBIGO_SUPPORT) && defined(MMS_SUPPORT)
  342. #include "Wap.h"
  343. #endif 
  344. #ifdef __MMI_MESSAGES_CHAT__
  345. #include "ChatAppGprot.h"
  346. #include "ChatAppDef.h"
  347. #include "ChatGtype.h"
  348. #endif /* __MMI_MESSAGES_CHAT__ */ 
  349. #if defined(__MMI_MESSAGES_TEMPLATE__)
  350. #include "NVRAMEnum.h"
  351. #include "NVRAMProt.h"
  352. #include "NVRAMType.h"
  353. #if defined(_MUTILANG_TEMPLATE_) || defined(__MMI_MESSAGES_SIMCHINESE_TEMPLATE__)
  354. #include "FontRes.h"
  355. #include "FontDcl.h"
  356. #include "SSCStringHandle.h"
  357. #endif /* defined(_MUTILANG_TEMPLATE_) || defined(__MMI_MESSAGES_SIMCHINESE_TEMPLATE__) */ 
  358. #endif /* defined(__MMI_MESSAGES_TEMPLATE__) */ 
  359. #ifdef MMI_ON_HARDWARE_P
  360. #include "nvram_user_defs.h"
  361. #endif 
  362. #include "SMSApi.h"
  363. #include "SMSStruct.h"
  364. #include "SMSFunc.h"
  365. #ifdef __MMI_UNIFIED_MESSAGE__
  366. #include "UnifiedMessageDef.h"
  367. #include "UnifiedMessageGProt.h"
  368. #include "DateTimeGprot.h"
  369. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  370. #ifdef __MMI_UNIFIED_COMPOSER__
  371. #include "UnifiedComposerDef.h"
  372. #include "UnifiedComposerGProt.h"
  373. #endif /* __MMI_UNIFIED_COMPOSER__ */ 
  374. #if defined(__MMI_MESSAGES_TEMPLATE__)
  375. #ifndef NVRAM_SMS_TEMPL_RECORD_SIZE
  376. #define NVRAM_SMS_TEMPL_RECORD_SIZE      84
  377. #endif 
  378. #ifndef NVRAM_SMS_RECORD_TOTAL
  379. #define NVRAM_SMS_RECORD_TOTAL         31
  380. #endif 
  381. const U16 templateStrings[] = 
  382. {
  383.     STR_SMS_TEMPLATE_1,
  384.     STR_SMS_TEMPLATE_2,
  385.     STR_SMS_TEMPLATE_3,
  386.     STR_SMS_TEMPLATE_4,
  387.     STR_SMS_TEMPLATE_5,
  388.     STR_SMS_TEMPLATE_6,
  389.     STR_SMS_TEMPLATE_7,
  390.     STR_SMS_TEMPLATE_8,
  391.     STR_SMS_TEMPLATE_9,
  392.     STR_SMS_TEMPLATE_10
  393. };
  394. #ifdef _MUTILANG_TEMPLATE_
  395. #define TOTAL_TEMPLATE_LANGUAGE        3
  396. extern pBOOL IsTrChineseSet(void);
  397. extern pBOOL IsSmChineseSet(void);
  398. #endif /* _MUTILANG_TEMPLATE_ */ 
  399. #if defined(_MUTILANG_TEMPLATE_) || defined(__MMI_MESSAGES_SIMCHINESE_TEMPLATE__)
  400. static U8 currLang[SSC_SIZE];
  401. extern sLanguageDetails *gLanguageArray;
  402. extern U16 gCurrLangIndex;
  403. #endif /* defined(_MUTILANG_TEMPLATE_) || defined(__MMI_MESSAGES_SIMCHINESE_TEMPLATE__) */ /* _MUTILANG_TEMPLATE_, __MMI_MESSAGES_SIMCHINESE_TEMPLATE__ */
  404. #endif /* defined(__MMI_MESSAGES_TEMPLATE__) */ 
  405. #ifdef __MMI_MESSAGES_CHAT__
  406. static U8 NewChatMessageFromXxxStr[(MAX_PHONE_NUMBER_OR_NAME_LENGTH + 1) * ENCODING_LENGTH];
  407. U16 gChatMsgFlag;   /* Added By Alok */
  408. void GetNewChatMsgIndDisplayString(U8 *number, U8 length, U8 type);
  409. PU8 GetNewChatSmsIndDisplayStr(void);
  410. #endif /* __MMI_MESSAGES_CHAT__ */ 
  411. static FuncPtr endKeyDownFuncPtr = NULL;
  412. static U16 messagesCurrScrnID;
  413. static U8 *strBuff = NULL;
  414. extern msg_msgbox_info_struct msgbox_info;
  415. extern PendingSaveSendDataStruct PendingSaveSendData;
  416. extern U16 GetCmMarkerScrnID(void);
  417. extern EMSData *GetEMSDataForView(EMSData **p, U8 force);
  418. extern MMI_ALERT_TYPE GetMtCallAlertTypeEnum(void);
  419. extern kal_uint16 wap_get_screen_id(void);
  420. #include "gui_config.h"
  421. extern const U8 AsciiToDefaultArray[];
  422. extern const U8 ExtendedAsciiToDefaultArray[];
  423. extern const U8 DefaultToExtendedAsciiArray[];
  424. extern const U8 DefaultToAsciiArray[];
  425. /*****************************************************************************
  426.  * FUNCTION
  427.  *  IsMMIInIdleState
  428.  * DESCRIPTION
  429.  *  Check if MMI is in idle state (idle screen or screen saver)
  430.  * PARAMETERS
  431.  *  void
  432.  * RETURNS
  433.  *  1: idle, 0: non-idle
  434.  *****************************************************************************/
  435. U16 IsMMIInIdleState(void)
  436. {
  437.     /*----------------------------------------------------------------*/
  438.     /* Local Variables                                                */
  439.     /*----------------------------------------------------------------*/
  440.     /*----------------------------------------------------------------*/
  441.     /* Code Body                                                      */
  442.     /*----------------------------------------------------------------*/
  443.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  444.                          "* [MessagesMiscell.c] IsMMIInIdleState IsOnIdleScreen=%d,ScreenSaverRunFlag=%d*n",
  445.                          g_idle_context.IsOnIdleScreen, g_idle_context.ScreenSaverRunFlag));
  446.     if (g_idle_context.IsOnIdleScreen || g_idle_context.ScreenSaverRunFlag)
  447.     {
  448.         return 1;
  449.     }
  450.     else
  451.     {
  452.         return 0;
  453.     }
  454. }
  455. /*****************************************************************************
  456.  * FUNCTION
  457.  *  IsKeyPadLockState
  458.  * DESCRIPTION
  459.  *  Check if MMI is in keypad lock state
  460.  * PARAMETERS
  461.  *  void
  462.  * RETURNS
  463.  *  keypad lock flag (1: lock, 0: unlock)
  464.  *****************************************************************************/
  465. U8 IsKeyPadLockState(void)
  466. {
  467.     /*----------------------------------------------------------------*/
  468.     /* Local Variables                                                */
  469.     /*----------------------------------------------------------------*/
  470.     /*----------------------------------------------------------------*/
  471.     /* Code Body                                                      */
  472.     /*----------------------------------------------------------------*/
  473.     return g_keylock_context.gKeyPadLockFlag;
  474. }
  475. /*****************************************************************************
  476.  * FUNCTION
  477.  *  mmi_msg_set_phb_send_case
  478.  * DESCRIPTION
  479.  *  Set PhbSmsInterfaceState
  480.  * PARAMETERS
  481.  *  PhbSmsInterfaceState        [IN]        
  482.  *  a(?)                        [IN]        PhbSmsInterfaceState
  483.  * RETURNS
  484.  *  void
  485.  *****************************************************************************/
  486. void mmi_msg_set_phb_send_case(U8 PhbSmsInterfaceState)
  487. {
  488.     /*----------------------------------------------------------------*/
  489.     /* Local Variables                                                */
  490.     /*----------------------------------------------------------------*/
  491.     /*----------------------------------------------------------------*/
  492.     /* Code Body                                                      */
  493.     /*----------------------------------------------------------------*/
  494.     g_msg_cntx.PhbSmsInterfaceState = PhbSmsInterfaceState;
  495. }
  496. /*****************************************************************************
  497.  * FUNCTION
  498.  *  GetCurrEndKeyDownHandler
  499.  * DESCRIPTION
  500.  *  Get current end key down handler
  501.  * PARAMETERS
  502.  *  void
  503.  * RETURNS
  504.  *  void
  505.  *****************************************************************************/
  506. void GetCurrEndKeyDownHandler(void)
  507. {
  508.     /*----------------------------------------------------------------*/
  509.     /* Local Variables                                                */
  510.     /*----------------------------------------------------------------*/
  511.     /*----------------------------------------------------------------*/
  512.     /* Code Body                                                      */
  513.     /*----------------------------------------------------------------*/
  514.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] GetCurrEndKeyDownHandler -------*n"));
  515.     endKeyDownFuncPtr = NULL;
  516.     endKeyDownFuncPtr = GetKeyHandler(KEY_END, KEY_EVENT_DOWN);
  517. }
  518. /*****************************************************************************
  519.  * FUNCTION
  520.  *  ExecCurrEndKeyDownHandler
  521.  * DESCRIPTION
  522.  *  Execute current end key down handler
  523.  * PARAMETERS
  524.  *  void
  525.  * RETURNS
  526.  *  void
  527.  *****************************************************************************/
  528. void ExecCurrEndKeyDownHandler(void)
  529. {
  530.     /*----------------------------------------------------------------*/
  531.     /* Local Variables                                                */
  532.     /*----------------------------------------------------------------*/
  533.     /*----------------------------------------------------------------*/
  534.     /* Code Body                                                      */
  535.     /*----------------------------------------------------------------*/
  536.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] ExecCurrEndKeyDownHandler -------*n"));
  537.     if (endKeyDownFuncPtr != NULL)
  538.     {
  539.         (*endKeyDownFuncPtr) ();
  540.     }
  541. }
  542. /*****************************************************************************
  543.  * FUNCTION
  544.  *  GetMessagesCurrScrnID
  545.  * DESCRIPTION
  546.  *  Get MSG current screen ID
  547.  * PARAMETERS
  548.  *  void
  549.  * RETURNS
  550.  *  messagesCurrScrnID
  551.  *****************************************************************************/
  552. U16 GetMessagesCurrScrnID(void)
  553. {
  554.     /*----------------------------------------------------------------*/
  555.     /* Local Variables                                                */
  556.     /*----------------------------------------------------------------*/
  557.     /*----------------------------------------------------------------*/
  558.     /* Code Body                                                      */
  559.     /*----------------------------------------------------------------*/
  560.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*[MessagesMiscell.c] GetMessagesCurrScrnID = %d", messagesCurrScrnID));
  561.     return messagesCurrScrnID;
  562. }
  563. /*****************************************************************************
  564.  * FUNCTION
  565.  *  SetMessagesCurrScrnID
  566.  * DESCRIPTION
  567.  *  Set MSG current screen ID
  568.  * PARAMETERS
  569.  *  scrnID      [IN]        
  570.  *  a(?)        [IN]        Screen ID
  571.  * RETURNS
  572.  *  void
  573.  *****************************************************************************/
  574. void SetMessagesCurrScrnID(U16 scrnID)
  575. {
  576.     /*----------------------------------------------------------------*/
  577.     /* Local Variables                                                */
  578.     /*----------------------------------------------------------------*/
  579.     /*----------------------------------------------------------------*/
  580.     /* Code Body                                                      */
  581.     /*----------------------------------------------------------------*/
  582.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*[MessagesMiscell.c] SetMessagesCurrScrnID= %d", messagesCurrScrnID));
  583.     messagesCurrScrnID = scrnID;
  584. }
  585. /*****************************************************************************
  586.  * FUNCTION
  587.  *  SetMessagesScrnIdToDelHistoryNodes
  588.  * DESCRIPTION
  589.  *  Set MSG screen ID for delete start
  590.  * PARAMETERS
  591.  *  StartScrnId     [IN]        
  592.  *  a(?)            [IN]        Start screen ID
  593.  * RETURNS
  594.  *  void
  595.  *****************************************************************************/
  596. void SetMessagesScrnIdToDelHistoryNodes(U16 StartScrnId)
  597. {
  598.     /*----------------------------------------------------------------*/
  599.     /* Local Variables                                                */
  600.     /*----------------------------------------------------------------*/
  601.     /*----------------------------------------------------------------*/
  602.     /* Code Body                                                      */
  603.     /*----------------------------------------------------------------*/
  604.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  605.                          "*-------[MessagesMiscell.c] SetMessagesScrnIdToDelHistoryNodes -------*n"));
  606.     g_msg_cntx.MessagesScrnIdToDelHistoryNodes = StartScrnId;
  607.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] screen id = %d -------*n",
  608.                          g_msg_cntx.MessagesScrnIdToDelHistoryNodes));
  609. }
  610. /*****************************************************************************
  611.  * FUNCTION
  612.  *  SetMessagesScrnIdDelUpToHistoryNodes
  613.  * DESCRIPTION
  614.  *  Set MSG screen ID for delete start
  615.  * PARAMETERS
  616.  *  StartScrnId     [IN]        
  617.  *  a(?)            [IN]        Start screen ID
  618.  * RETURNS
  619.  *  void
  620.  *****************************************************************************/
  621. void SetMessagesScrnIdDelUpToHistoryNodes(U16 StartScrnId)
  622. {
  623.     /*----------------------------------------------------------------*/
  624.     /* Local Variables                                                */
  625.     /*----------------------------------------------------------------*/
  626.     /*----------------------------------------------------------------*/
  627.     /* Code Body                                                      */
  628.     /*----------------------------------------------------------------*/
  629.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  630.                          "*-------[MessagesMiscell.c] SetMessagesScrnIdDelUpToHistoryNodes -------*n"));
  631.     g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes = StartScrnId;
  632.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] screen id = %d -------*n",
  633.                          g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes));
  634. }
  635. /*****************************************************************************
  636.  * FUNCTION
  637.  *  DeleteMessagesHistoryNodes
  638.  * DESCRIPTION
  639.  *  Delete between MSG screens
  640.  * PARAMETERS
  641.  *  void
  642.  * RETURNS
  643.  *  void
  644.  *****************************************************************************/
  645. void DeleteMessagesHistoryNodes(void)
  646. {
  647.     /*----------------------------------------------------------------*/
  648.     /* Local Variables                                                */
  649.     /*----------------------------------------------------------------*/
  650.     /*----------------------------------------------------------------*/
  651.     /* Code Body                                                      */
  652.     /*----------------------------------------------------------------*/
  653.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] DeleteMessagesHistoryNodes -------*n"));
  654.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] Deleteted from %d -------*n",
  655.                          g_msg_cntx.MessagesScrnIdToDelHistoryNodes));
  656.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] Deleteted upto %d -------*n",
  657.                          g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes));
  658.     if (IsScreenPresent(g_msg_cntx.MessagesScrnIdToDelHistoryNodes) &&
  659.         IsScreenPresent(g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes))
  660.     {
  661.         if (DeleteBetweenScreen
  662.             (g_msg_cntx.MessagesScrnIdToDelHistoryNodes, g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes))
  663.         {
  664.             PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*---[MessagesMiscell.c] Deleteted scrn id from %d to %d ---*n",
  665.                                  g_msg_cntx.MessagesScrnIdToDelHistoryNodes,
  666.                                  g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes));
  667.             g_msg_cntx.MessagesScrnIdToDelHistoryNodes = MESSAGES_SCR_ID_DEFINES_MAX;
  668.             g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes = MESSAGES_SCR_ID_DEFINES_MAX;
  669.             return;
  670.         }
  671.     }
  672.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*---[MessagesMiscell.c] Not deleteted scrn id from %d to %d ---*n",
  673.                          g_msg_cntx.MessagesScrnIdToDelHistoryNodes, g_msg_cntx.MessagesScrnIdDelUptoHistoryNodes));
  674. }
  675. /*****************************************************************************
  676.  * FUNCTION
  677.  *  Messages2GoBackHistory
  678.  * DESCRIPTION
  679.  *  Go back two screen history
  680.  * PARAMETERS
  681.  *  void
  682.  * RETURNS
  683.  *  void
  684.  *****************************************************************************/
  685. void Messages2GoBackHistory(void)
  686. {
  687.     /*----------------------------------------------------------------*/
  688.     /* Local Variables                                                */
  689.     /*----------------------------------------------------------------*/
  690.     /*----------------------------------------------------------------*/
  691.     /* Code Body                                                      */
  692.     /*----------------------------------------------------------------*/
  693.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] Messages2GoBackHistory -------*n"));
  694.     GoBacknHistory(1);
  695. }
  696. /*****************************************************************************
  697.  * FUNCTION
  698.  *  Messages4GoBackHistory
  699.  * DESCRIPTION
  700.  *  Go back four screen history
  701.  * PARAMETERS
  702.  *  void
  703.  * RETURNS
  704.  *  void
  705.  *****************************************************************************/
  706. void Messages4GoBackHistory(void)
  707. {
  708.     /*----------------------------------------------------------------*/
  709.     /* Local Variables                                                */
  710.     /*----------------------------------------------------------------*/
  711.     /*----------------------------------------------------------------*/
  712.     /* Code Body                                                      */
  713.     /*----------------------------------------------------------------*/
  714.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] Messages4GoBackHistory -------*n"));
  715.     GoBacknHistory(3);
  716. }
  717. /*****************************************************************************
  718.  * FUNCTION
  719.  *  GetChildMenuIDIndexByParentMenuID
  720.  * DESCRIPTION
  721.  *  This function is just for template.
  722.  * PARAMETERS
  723.  *  parentMenuId        [IN]        
  724.  *  childMenuId         [IN]        
  725.  *  a(?)                [IN]        Parent menu id
  726.  *  b(?)                [IN]        Child menu id
  727.  * RETURNS
  728.  *  index >= 0: child manu id is a child of parent menu id, -1: if not
  729.  *****************************************************************************/
  730. S32 GetChildMenuIDIndexByParentMenuID(U16 parentMenuId, U16 childMenuId)
  731. {
  732.     /*----------------------------------------------------------------*/
  733.     /* Local Variables                                                */
  734.     /*----------------------------------------------------------------*/
  735.     S32 index = 0;
  736.     U16 nMenuItemList[MAX_SUB_MENUS];
  737.     U16 numItems = GetNumOfChild(parentMenuId);
  738.     /*----------------------------------------------------------------*/
  739.     /* Code Body                                                      */
  740.     /*----------------------------------------------------------------*/
  741.     GetSequenceItemIds(parentMenuId, nMenuItemList);
  742.     for (index = 0; index < numItems; index++)
  743.     {
  744.         if (nMenuItemList[index] == childMenuId)
  745.         {
  746.             return index;
  747.         }
  748.     }
  749.     return -1;
  750. }
  751. /*****************************************************************************
  752.  * FUNCTION
  753.  *  GetHiliteIndex
  754.  * DESCRIPTION
  755.  *  Get current highlight index
  756.  * PARAMETERS
  757.  *  nIndex      [IN]        
  758.  *  a(?)        [IN]        Current highlight index
  759.  * RETURNS
  760.  *  void
  761.  *****************************************************************************/
  762. void GetHiliteIndex(S32 nIndex)
  763. {
  764.     /*----------------------------------------------------------------*/
  765.     /* Local Variables                                                */
  766.     /*----------------------------------------------------------------*/
  767.     /*----------------------------------------------------------------*/
  768.     /* Code Body                                                      */
  769.     /*----------------------------------------------------------------*/
  770.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[SmsMoMtGuiInterface.c] GetHiliteIndex -------*n"));
  771.     g_msg_cntx.currHiliteIndex = nIndex;
  772. }
  773. /*****************************************************************************
  774.  * FUNCTION
  775.  *  GetMsgIndex
  776.  * DESCRIPTION
  777.  *  Get current highlight message box index
  778.  * PARAMETERS
  779.  *  nIndex      [IN]        
  780.  *  a(?)        [IN]        Current highlight index
  781.  * RETURNS
  782.  *  void
  783.  *****************************************************************************/
  784. void GetMsgIndex(S32 nIndex)
  785. {
  786.     /*----------------------------------------------------------------*/
  787.     /* Local Variables                                                */
  788.     /*----------------------------------------------------------------*/
  789.     /*----------------------------------------------------------------*/
  790.     /* Code Body                                                      */
  791.     /*----------------------------------------------------------------*/
  792.     g_msg_cntx.currBoxIndex = nIndex;
  793. }
  794. #if defined(__MMI_MESSAGES_EMS__)
  795. /*****************************************************************************
  796.  * FUNCTION
  797.  *  EnableDisableAudioPlayback
  798.  * DESCRIPTION
  799.  *  Decide to enable/disable audio playback
  800.  * PARAMETERS
  801.  *  void
  802.  * RETURNS
  803.  *  void
  804.  *****************************************************************************/
  805. void EnableDisableAudioPlayback(void)
  806. {
  807.     /*----------------------------------------------------------------*/
  808.     /* Local Variables                                                */
  809.     /*----------------------------------------------------------------*/
  810.     MMI_ALERT_TYPE alertType;
  811.     /*----------------------------------------------------------------*/
  812.     /* Code Body                                                      */
  813.     /*----------------------------------------------------------------*/
  814.     alertType = GetMtCallAlertTypeEnum();
  815.     if ((!isInCall()) &&
  816.         (alertType == MMI_RING || alertType == MMI_VIBRATION_AND_RING || alertType == MMI_VIBRATION_THEN_RING))
  817.     {
  818.         EMS_enable_audio_playback();
  819.     }
  820.     else
  821.     {
  822.         EMS_disable_audio_playback();
  823.     }
  824. }
  825. #endif /* defined(__MMI_MESSAGES_EMS__) */ 
  826. /*****************************************************************************
  827.  * FUNCTION
  828.  *  PlayMessageArrivalTone
  829.  * DESCRIPTION
  830.  *  Play message arrival tone
  831.  * PARAMETERS
  832.  *  void
  833.  * RETURNS
  834.  *  void
  835.  *****************************************************************************/
  836. void PlayMessageArrivalTone(void)
  837. {
  838.     /*----------------------------------------------------------------*/
  839.     /* Local Variables                                                */
  840.     /*----------------------------------------------------------------*/
  841.     MMI_ALERT_TYPE alertType;
  842.     /*----------------------------------------------------------------*/
  843.     /* Code Body                                                      */
  844.     /*----------------------------------------------------------------*/
  845.     alertType = GetMtCallAlertTypeEnum();
  846.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] PlayMessageArrivalTone -------*n"));
  847.     if (alertType == MMI_VIBRATION_AND_RING || alertType == MMI_VIBRATION_THEN_RING || alertType == MMI_RING)
  848.     {
  849.         if (!isInCall())
  850.         {
  851.             playRequestedTone(MESSAGE_TONE);
  852.         }
  853.         else
  854.         {
  855.             playRequestedTone(SMS_IN_CALL_TONE);
  856.         }
  857.     }
  858.     if ((alertType == MMI_VIBRATION_ONLY) || (alertType == MMI_VIBRATION_AND_RING) ||
  859.         (alertType == MMI_VIBRATION_THEN_RING))
  860.     {
  861.         if ((!g_alm_frm_cntx.IsAlmTonePlaying) && (!isInCall()))
  862.         {
  863.             PlaySmsVibratorOnce();
  864.         }
  865.     }
  866. }
  867. /*****************************************************************************
  868.  * FUNCTION
  869.  *  InitMessageProtocolEventHandlers
  870.  * DESCRIPTION
  871.  *  Init MSG protocol event handler when boot up
  872.  * PARAMETERS
  873.  *  void
  874.  * RETURNS
  875.  *  void
  876.  *****************************************************************************/
  877. void InitMessageProtocolEventHandlers(void)
  878. {
  879.     /*----------------------------------------------------------------*/
  880.     /* Local Variables                                                */
  881.     /*----------------------------------------------------------------*/
  882.     /*----------------------------------------------------------------*/
  883.     /* Code Body                                                      */
  884.     /*----------------------------------------------------------------*/
  885.     mmi_msg_init_msg_data();
  886.     ResetCBInfoStructs();
  887.     mmi_msg_set_protocol_event_handler();
  888.     InitCellBroadcastProtocolEventHanler(); /* danger!! receiving new CB might cause reading nvram */
  889. }
  890. /*****************************************************************************
  891.  * FUNCTION
  892.  *  InitMessagesApp
  893.  * DESCRIPTION
  894.  *  Init MSG application when go to opening screen
  895.  * PARAMETERS
  896.  *  void
  897.  * RETURNS
  898.  *  void
  899.  *****************************************************************************/
  900. void InitMessagesApp(void)
  901. {
  902.     /*----------------------------------------------------------------*/
  903.     /* Local Variables                                                */
  904.     /*----------------------------------------------------------------*/
  905.     /*----------------------------------------------------------------*/
  906.     /* Code Body                                                      */
  907.     /*----------------------------------------------------------------*/
  908.     InitEMSDataStruct();
  909.     mmi_msg_set_highlight_handler();
  910.     /* mmi_msg_set_protocol_event_handler_after_init (); */
  911.     InitCellBroadcastApp();
  912. }
  913. /*****************************************************************************
  914.  * FUNCTION
  915.  *  DeInitMessagesApp
  916.  * DESCRIPTION
  917.  *  Deinit MSG application
  918.  * PARAMETERS
  919.  *  void
  920.  * RETURNS
  921.  *  void
  922.  *****************************************************************************/
  923. void DeInitMessagesApp(void)
  924. {
  925.     /*----------------------------------------------------------------*/
  926.     /* Local Variables                                                */
  927.     /*----------------------------------------------------------------*/
  928.     /*----------------------------------------------------------------*/
  929.     /* Code Body                                                      */
  930.     /*----------------------------------------------------------------*/
  931. #if defined(__MMI_MESSAGES_TEMPLATE__)
  932.     DeInitTemplates();
  933. #endif 
  934.     mmi_msg_deinit_msg_data();
  935.     DeInitCellBroadcastApp();
  936.     DeInitVoiceMailApp();
  937.     DeInitEMSDataStruct();
  938. }
  939. /*****************************************************************************
  940.  * FUNCTION
  941.  *  RestoreMessagesSettings
  942.  * DESCRIPTION
  943.  *  Restore MSG settings
  944.  * PARAMETERS
  945.  *  void
  946.  * RETURNS
  947.  *  void
  948.  *****************************************************************************/
  949. void RestoreMessagesSettings(void)
  950. {
  951.     /*----------------------------------------------------------------*/
  952.     /* Local Variables                                                */
  953.     /*----------------------------------------------------------------*/
  954.     /*----------------------------------------------------------------*/
  955.     /* Code Body                                                      */
  956.     /*----------------------------------------------------------------*/
  957.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[MessagesMiscell.c] RestoreMessagesSettings -------*n"));
  958.     mmi_msg_restore_cb();
  959. }
  960. /*****************************************************************************
  961.  * FUNCTION
  962.  *  IsMessagesReEntering
  963.  * DESCRIPTION
  964.  *  Check if MSG application is reentered
  965.  * PARAMETERS
  966.  *  void
  967.  * RETURNS
  968.  *  TRUE: MSG application is reentered, FALSE: MSG application is not reentered
  969.  *****************************************************************************/
  970. U8 IsMessagesReEntering(void)
  971. {
  972.     /*----------------------------------------------------------------*/
  973.     /* Local Variables                                                */
  974.     /*----------------------------------------------------------------*/
  975.     /*----------------------------------------------------------------*/
  976.     /* Code Body                                                      */
  977.     /*----------------------------------------------------------------*/
  978.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[SmsMoMtGuiInterface.c] IsMessagesReEntering -------*n"));
  979.     if (!mmi_frm_sms_check_action_pending())
  980.     {
  981.         U16 startScrnId = 0;
  982.         U16 endScrnId = 0;
  983.         PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[SmsMoMtGuiInterface.c] Messages not Busy  -------*n"));
  984.     #if (defined(OBIGO_SUPPORT) || defined (JATAAYU_SUPPORT)) && defined(MMS_SUPPORT)
  985.         if ((IsScreenPresent(wap_get_screen_id())) && (!IsScreenPresent(SCR_ID_MSG_MAIN_MENU_NO_MMS)))
  986.         {
  987.             U16 ScrnId = 0;
  988.             PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  989.                                  "*---[SmsMoMtGuiInterface.c] WAP screen exists and SCR_ID_MSG_MAIN_MENU_NO_MMS not exists   ---*n"));
  990.             if (IsScreenPresent(SCR_ID_MSG_SMS_MAIN_MENU))
  991.             {
  992.                 ScrnId = SCR_ID_MSG_SMS_MAIN_MENU;
  993.             }
  994.         #ifdef __MMI_UNIFIED_MESSAGE__
  995.             else if (IsScreenPresent(SCR_ID_UM_MAIN))
  996.             {
  997.                 startScrnId = SCR_ID_UM_MAIN;
  998.             }
  999.         #ifdef __MMI_UNIFIED_COMPOSER__
  1000.             else if (IsScreenPresent(SCR_ID_UC_EDITOR))
  1001.             {
  1002.                 startScrnId = SCR_ID_UC_EDITOR;
  1003.             }
  1004.         #else /* __MMI_UNIFIED_COMPOSER__ */
  1005.             else if (IsScreenPresent(SCR_ID_UM_WRITE_MSG))
  1006.             {
  1007.                 startScrnId = SCR_ID_UM_WRITE_MSG;
  1008.             }
  1009.         #endif /* __MMI_UNIFIED_COMPOSER__ */
  1010.             else if (IsScreenPresent(SCR_ID_UM_INBOX))
  1011.             {
  1012.                 startScrnId = SCR_ID_UM_INBOX;
  1013.             }
  1014.             else if (IsScreenPresent(SCR_ID_UM_UNSENT))
  1015.             {
  1016.                 startScrnId = SCR_ID_UM_UNSENT;
  1017.             }
  1018.             else if (IsScreenPresent(SCR_ID_UM_SENT))
  1019.             {
  1020.                 startScrnId = SCR_ID_UM_SENT;
  1021.             }
  1022.             else if (IsScreenPresent(SCR_ID_UM_DRAFT))
  1023.             {
  1024.                 startScrnId = SCR_ID_UM_DRAFT;
  1025.             }            
  1026.         #else /* __MMI_UNIFIED_MESSAGE__ */             
  1027.             else if (IsScreenPresent(SCR_ID_MSG_INBOX_LIST))
  1028.             {
  1029.                 ScrnId = SCR_ID_MSG_INBOX_LIST;
  1030.             }
  1031.             else if (IsScreenPresent(SCR_ID_MSG_OUTBOX_LIST))
  1032.             {
  1033.                 ScrnId = SCR_ID_MSG_OUTBOX_LIST;
  1034.             }
  1035.         #endif /* __MMI_UNIFIED_MESSAGE__ */             
  1036.             else if (IsScreenPresent(SCR_ID_MSG_VOICE_MAIL_LIST))
  1037.             {
  1038.                 ScrnId = SCR_ID_MSG_VOICE_MAIL_LIST;
  1039.             }
  1040.             else if (IsScreenPresent(SCR_ID_MSG_WRITE))
  1041.             {
  1042.                 ScrnId = SCR_ID_MSG_WRITE;
  1043.             }
  1044.             else if (IsScreenPresent(SCR_ID_MSG_INBOX_MSG))
  1045.             {
  1046.                 ScrnId = SCR_ID_MSG_INBOX_MSG;
  1047.             }
  1048.             else if (IsScreenPresent(SCR_ID_MSG_DEFAULT_MSG))
  1049.             {
  1050.                 ScrnId = SCR_ID_MSG_DEFAULT_MSG;
  1051.             }
  1052.         #ifdef __MMI_MESSAGES_CHAT__
  1053.             else if (IsScreenPresent(CHAT_SCREEN_ROOM_ID))
  1054.             {
  1055.                 ScrnId = CHAT_SCREEN_ROOM_ID;
  1056.             }
  1057.         #endif /* __MMI_MESSAGES_CHAT__ */ 
  1058.             if (ScrnId)
  1059.             {
  1060.                 PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*---[SmsMoMtGuiInterface.c] sms screen exists   ---*n"));
  1061.                 return TRUE;
  1062.             }
  1063.             return FALSE;
  1064.         }
  1065.         else
  1066.     #endif /* (defined(OBIGO_SUPPORT) || defined (JATAAYU_SUPPORT)) && defined(MMS_SUPPORT) */ 
  1067.         {
  1068.             /* get start screen id */
  1069.             if (IsScreenPresent(SCR_ID_MSG_MAIN_MENU_NO_MMS))
  1070.             {
  1071.                 startScrnId = SCR_ID_MSG_MAIN_MENU_NO_MMS;
  1072.             }
  1073.             else if (IsScreenPresent(SCR_ID_MSG_MAIN_MENU))
  1074.             {
  1075.                 startScrnId = SCR_ID_MSG_MAIN_MENU;
  1076.             }
  1077.         #ifdef __MMI_UNIFIED_MESSAGE__
  1078.             else if (IsScreenPresent(SCR_ID_UM_MAIN))
  1079.             {
  1080.                 startScrnId = SCR_ID_UM_MAIN;
  1081.             }
  1082.         #ifdef __MMI_UNIFIED_COMPOSER__
  1083.             else if (IsScreenPresent(SCR_ID_UC_EDITOR))
  1084.             {
  1085.                 startScrnId = SCR_ID_UC_EDITOR;
  1086.             }
  1087.         #else /* __MMI_UNIFIED_COMPOSER__ */
  1088.             else if (IsScreenPresent(SCR_ID_UM_WRITE_MSG))
  1089.             {
  1090.                 startScrnId = SCR_ID_UM_WRITE_MSG;
  1091.             }
  1092.         #endif /* __MMI_UNIFIED_COMPOSER__ */
  1093.             else if (IsScreenPresent(SCR_ID_UM_INBOX))
  1094.             {
  1095.                 startScrnId = SCR_ID_UM_INBOX;
  1096.             }
  1097.             else if (IsScreenPresent(SCR_ID_UM_UNSENT))
  1098.             {
  1099.                 startScrnId = SCR_ID_UM_UNSENT;
  1100.             }
  1101.             else if (IsScreenPresent(SCR_ID_UM_SENT))
  1102.             {
  1103.                 startScrnId = SCR_ID_UM_SENT;
  1104.             }
  1105.             else if (IsScreenPresent(SCR_ID_UM_DRAFT))
  1106.             {
  1107.                 startScrnId = SCR_ID_UM_DRAFT;
  1108.             }            
  1109.         #else /* __MMI_UNIFIED_MESSAGE__ */ 
  1110.             else if (IsScreenPresent(SCR_ID_MSG_INBOX_LIST))
  1111.             {
  1112.                 startScrnId = SCR_ID_MSG_INBOX_LIST;
  1113.             }
  1114.             else if (IsScreenPresent(SCR_ID_MSG_OUTBOX_LIST))
  1115.             {
  1116.                 startScrnId = SCR_ID_MSG_OUTBOX_LIST;
  1117.             }
  1118.         #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  1119.             else if (IsScreenPresent(SCR_ID_MSG_WRITE))
  1120.             {
  1121.                 startScrnId = SCR_ID_MSG_WRITE;
  1122.             }            
  1123.             else if (IsScreenPresent(SCR_ID_MSG_VOICE_MAIL_LIST))
  1124.             {
  1125.                 startScrnId = SCR_ID_MSG_VOICE_MAIL_LIST;
  1126.             }
  1127.             else if (IsScreenPresent(SCR_ID_MSG_INBOX_MSG))
  1128.             {
  1129.                 startScrnId = SCR_ID_MSG_INBOX_MSG;
  1130.             }
  1131.             else if (IsScreenPresent(SCR_ID_MSG_DEFAULT_MSG))
  1132.             {
  1133.                 startScrnId = SCR_ID_MSG_DEFAULT_MSG;
  1134.             }
  1135.         #ifdef __MMI_MESSAGES_CHAT__
  1136.             else if (IsScreenPresent(CHAT_SCREEN_ROOM_ID))
  1137.             {
  1138.                 startScrnId = CHAT_SCREEN_ROOM_ID;
  1139.             }
  1140.         #endif /* __MMI_MESSAGES_CHAT__ */ 
  1141.             if (startScrnId)
  1142.             {
  1143.                 PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  1144.                                      "*---[MessagesMiscell.c] Start scrn id to be deleteted %d ---*n", startScrnId));
  1145.                 GetPreviousScrnIdOf(GetCmMarkerScrnID(), &endScrnId);
  1146.                 if (endScrnId)
  1147.                 {
  1148.                     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  1149.                                          "*---[MessagesMiscell.c] End scrn id to be deleteted %d ---*n", endScrnId));
  1150.                     if (DeleteBetweenScreen(startScrnId, endScrnId))
  1151.                     {
  1152.                         g_msg_cntx.toDisplayMessageList = TO_DISPLAY_MESSAGE_LIST_NONE;
  1153.                         mmi_frm_sms_delete_action_pending();
  1154.                         PRINT_INFORMATION_2((MMI_TRACE_G6_SMS,
  1155.                                              "*---[MessagesMiscell.c] Deleteted scrn id from %d to %d and action---*n",
  1156.                                              startScrnId, endScrnId));
  1157.                         return FALSE;
  1158.                     }
  1159.                 }
  1160.             }
  1161.             PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*---[MessagesMiscell.c] Not deleteted scrn id from %d to %d ---*n",
  1162.                                  startScrnId, endScrnId));
  1163.             return FALSE;
  1164.         }
  1165.     }
  1166.     else
  1167.     {
  1168.         PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*[SmsMoMtGuiInterface.c] Messages state = %d", g_msg_cntx.msg_status));
  1169.         return TRUE;
  1170.     }
  1171. }
  1172. /*****************************************************************************
  1173.  * FUNCTION
  1174.  *  PreEntryScrMessagesMenuList
  1175.  * DESCRIPTION
  1176.  *  Before entry messages main menu, check if MSG application is reentered.
  1177.  * PARAMETERS
  1178.  *  void
  1179.  * RETURNS
  1180.  *  void
  1181.  *****************************************************************************/
  1182. void PreEntryScrMessagesMenuList(void)
  1183. {
  1184.     /*----------------------------------------------------------------*/
  1185.     /* Local Variables                                                */
  1186.     /*----------------------------------------------------------------*/
  1187.     /*----------------------------------------------------------------*/
  1188.     /* Code Body                                                      */
  1189.     /*----------------------------------------------------------------*/
  1190.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[SmsMoMtGuiInterface.c] PreEntryScrMessagesMenuList -------*n"));
  1191. #ifdef __MMI_UNIFIED_MESSAGE__
  1192.     if (!mmi_um_is_available())
  1193.     {
  1194.         DisplayPopup(
  1195.             (PU8) GetString(STR_GLOBAL_NOT_AVAILABLE),
  1196.             IMG_GLOBAL_ERROR,
  1197.             1,
  1198.             MESSAGES_POPUP_TIME_OUT,
  1199.             (U8) ERROR_TONE);
  1200.     }
  1201. #else /* __MMI_UNIFIED_MESSAGE__ */ 
  1202.     if (IsMessagesReEntering())
  1203.     {
  1204.         DisplayPopup(
  1205.             (PU8) GetString(STR_SMS_MSG_NOT_READY_YET),
  1206.             IMG_GLOBAL_UNFINISHED,
  1207.             1,
  1208.             MESSAGES_POPUP_TIME_OUT,
  1209.             (U8) ERROR_TONE);
  1210.     }
  1211. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  1212.     else
  1213.     {
  1214.         EntryScrMessagesMenuList();
  1215.     }
  1216. }
  1217. /*****************************************************************************
  1218.  * FUNCTION
  1219.  *  EntryScrMessagesMenuList
  1220.  * DESCRIPTION
  1221.  *  Entry messages main menu screen
  1222.  * PARAMETERS
  1223.  *  void
  1224.  * RETURNS
  1225.  *  void
  1226.  *****************************************************************************/
  1227. void EntryScrMessagesMenuList(void)
  1228. {
  1229.     /*----------------------------------------------------------------*/
  1230.     /* Local Variables                                                */
  1231.     /*----------------------------------------------------------------*/
  1232.     U8 *guiBuffer = NULL;
  1233.     U16 numItems = 0;
  1234.     U16 nStrItemList[MAX_SUB_MENUS];
  1235.     U16 itemIcons[MAX_SUB_MENUS];
  1236.     U16 screenId = SCR_ID_MSG_MAIN_MENU;
  1237. #ifdef __MMI_MESSAGES_MULTI_APP__
  1238.     /* S32 menuItemId=-1; */
  1239. #else /* __MMI_MESSAGES_MULTI_APP__ */ 
  1240.     U8 *popUpList[MAX_SUB_MENUS];
  1241.     //S32 menuItemId=-1;
  1242.     //S32 menuItemId1=-1;
  1243. #endif /* __MMI_MESSAGES_MULTI_APP__ */ 
  1244.     /* S32 maskingByte=-1; */
  1245.     U8 **pPopUpList = NULL;
  1246.     /*----------------------------------------------------------------*/
  1247.     /* Code Body                                                      */
  1248.     /*----------------------------------------------------------------*/
  1249. #if defined(__MMI_SMART_MESSAGE_MT__)
  1250.     mmi_nsm_set_msg_type(NORMAL_MESSAGE);
  1251. #endif 
  1252.     AlmEnableSPOF();
  1253. #if (defined(OBIGO_SUPPORT) || defined (JATAAYU_SUPPORT)) && defined(MMS_SUPPORT)
  1254.     if ((isInCall()) || (IsScreenPresent(wap_get_screen_id())))
  1255.     {
  1256.         screenId = SCR_ID_MSG_MAIN_MENU_NO_MMS;
  1257.     }
  1258. #endif /* (defined(OBIGO_SUPPORT) || defined (JATAAYU_SUPPORT)) && defined(MMS_SUPPORT) */ 
  1259.     EntryNewScreen(screenId, mmi_msg_exit_generic, EntryScrMessagesMenuList, NULL);
  1260.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[SmsMoMtGuiInterface.c] EntryScrMessagesMenuList %d-------*n",
  1261.                          screenId));
  1262.     SetParentHandler(MAIN_MENU_MESSAGES_MENUID);
  1263.     RegisterHighlightHandler(ExecuteCurrHiliteHandler);
  1264.     mmi_msg_set_msg_menu_highlight_handler();
  1265. #ifdef __MMI_MESSAGES_MULTI_APP__
  1266. #if (defined(OBIGO_SUPPORT) || defined (JATAAYU_SUPPORT)) && defined(MMS_SUPPORT)
  1267.     //menuItemId=GetChildMenuIDIndexByParentMenuID(MAIN_MENU_MESSAGES_MENUID, MESSAGES_MENU_MMS_MENUID);
  1268.     //if(menuItemId!=-1)
  1269.     //{
  1270.     if (((isInCall() && !GetWapCallPresent())) || (IsScreenPresent(wap_get_screen_id())))
  1271.         /* ResetBit(maskingByte,menuItemId); */
  1272.     {
  1273.         mmi_frm_hide_menu_item(MESSAGES_MENU_MMS_MENUID);
  1274.     }
  1275.     else
  1276.     {
  1277.         if (mmi_bootup_is_sim_valid())
  1278.         {
  1279.             /* Message menu is shown if WLAN is on, not unhide the MMS menu if there is no SIM */
  1280.             mmi_frm_unhide_menu_item(MESSAGES_MENU_MMS_MENUID);
  1281.         }
  1282.     }
  1283.     /* } */
  1284. #endif /* (defined(OBIGO_SUPPORT) || defined (JATAAYU_SUPPORT)) && defined(MMS_SUPPORT) */ 
  1285. #if defined(__MMI_EMAIL__)
  1286.     //menuItemId=GetChildMenuIDIndexByParentMenuID(MAIN_MENU_MESSAGES_MENUID, MENU_ID_EMAIL_MAIN);
  1287.     //if(menuItemId!=-1)
  1288.     //{
  1289.     if (isInCall() && (!GetWapCallPresent()))  /* CSD call */
  1290.         /* ResetBit(maskingByte,menuItemId); */
  1291.     {
  1292.         mmi_frm_hide_menu_item(MENU_ID_EMAIL_MAIN);
  1293.     }
  1294.     else
  1295.     {
  1296.         mmi_frm_unhide_menu_item(MENU_ID_EMAIL_MAIN);
  1297.     }
  1298.     /* } */
  1299. #endif /* defined(__MMI_EMAIL__) */ 
  1300. #if defined(__MMI_IMPS__)
  1301.     //menuItemId=GetChildMenuIDIndexByParentMenuID(MAIN_MENU_MESSAGES_MENUID, MENU_ID_IMPS_MAIN);
  1302.     //if(menuItemId!=-1)
  1303.     //{
  1304.     if (isInCall() && (!GetWapCallPresent()))  /* CSD call */
  1305.         /* ResetBit(maskingByte,menuItemId); */
  1306.     {
  1307.         mmi_frm_hide_menu_item(MENU_ID_IMPS_MAIN);
  1308.     }
  1309.     else
  1310.     {
  1311.         mmi_frm_unhide_menu_item(MENU_ID_IMPS_MAIN);
  1312.     }
  1313.     /* } */
  1314. #endif /* defined(__MMI_IMPS__) */ 
  1315. #else /* __MMI_MESSAGES_MULTI_APP__ */ 
  1316.     /* hint updation */
  1317.     if (mmi_frm_sms_get_sms_list_size(MMI_FRM_SMS_NOBOX) != MMI_FRM_SMS_INVALID_INDEX)
  1318.     {
  1319.         msgbox_info.totalinbox = mmi_frm_sms_get_sms_list_size(MMI_FRM_SMS_APP_INBOX);
  1320.         msgbox_info.totaloutbox = mmi_frm_sms_get_sms_list_size(MMI_FRM_SMS_APP_OUTBOX);
  1321.         msgbox_info.totaldraftbox = mmi_frm_sms_get_sms_list_size(MMI_FRM_SMS_APP_DRAFTS);
  1322.         mmi_msg_set_msg_num_hint(msgbox_info.totalinbox, msgbox_info.totaloutbox, msgbox_info.totaldraftbox);
  1323.         RefreshMessagesMenuList();
  1324.     }
  1325.     ConstructHintsList(MAIN_MENU_MESSAGES_MENUID, popUpList);
  1326.     if (mmi_frm_sms_get_sms_list_size(MMI_FRM_SMS_NOBOX) != MMI_FRM_SMS_INVALID_INDEX)
  1327.     {
  1328.         pPopUpList = popUpList;
  1329.     }
  1330.     else
  1331.     {
  1332.         pPopUpList = NULL;
  1333.     }
  1334.     /* diamond, 2005/07/01 removed for new menu item architecture to CPHS */
  1335. #if 0
  1336. /* under construction !*/
  1337. /* under construction !*/
  1338. /* under construction !*/
  1339. /* under construction !*/
  1340. /* under construction !*/
  1341. /* under construction !*/
  1342. /* under construction !*/
  1343. /* under construction !*/
  1344. /* under construction !*/
  1345. /* under construction !*/
  1346. /* under construction !*/
  1347. /* under construction !*/
  1348. /* under construction !*/
  1349. /* under construction !*/
  1350. /* under construction !*/
  1351. /* under construction !*/
  1352. /* under construction !*/
  1353. /* under construction !*/
  1354. /* under construction !*/
  1355. /* under construction !*/
  1356. /* under construction !*/
  1357. /* under construction !*/
  1358. /* under construction !*/
  1359. /* under construction !*/
  1360. /* under construction !*/
  1361. /* under construction !*/
  1362. /* under construction !*/
  1363. /* under construction !*/
  1364. /* under construction !*/
  1365. #endif /* 0 */ 
  1366. #endif /* __MMI_MESSAGES_MULTI_APP__ */ /* MMS_SUPPORT */
  1367.     //MaskItems(itemIcons,(U8)numItems,maskingByte);
  1368.     //MaskHiliteItems(MAIN_MENU_MESSAGES_MENUID, maskingByte);
  1369.     //numItems=MaskItems(nStrItemList,(U8)numItems,maskingByte);
  1370.     /* diamond, 2005/07/01 add _Ext to menu item functions */
  1371.     numItems = GetNumOfChild_Ext(MAIN_MENU_MESSAGES_MENUID);
  1372.     GetSequenceStringIds_Ext(MAIN_MENU_MESSAGES_MENUID, nStrItemList);
  1373.     GetSequenceImageIds_Ext(MAIN_MENU_MESSAGES_MENUID, itemIcons);
  1374.     g_msg_cntx.currBoxIndex = 0;
  1375.     g_msg_cntx.sendMessageCase = SEND_CASE_SEND_ONLY;
  1376.     g_msg_cntx.PhbSmsInterfaceState = MMI_SEND_ONLY;
  1377.     SetMessagesCurrScrnID(screenId);
  1378.     guiBuffer = GetCurrGuiBuffer(screenId);
  1379.     /* MTK Leo add, mini_tab_bar */
  1380. #ifdef __MMI_WGUI_MINI_TAB_BAR__
  1381.     wgui_enable_mini_tab_bar(MAIN_MENU_MESSAGES_MENUID);
  1382. #endif 
  1383.     /* MTK Leo end */
  1384. #ifdef __MMI_UNIFIED_MESSAGE__
  1385.     ShowCategory52Screen(
  1386.         STR_UM_MAIN_MENU_TITLE_ID,
  1387.         IMG_SMS_ENTRY_SCRN_CAPTION,
  1388.         STR_GLOBAL_OK,
  1389.         IMG_GLOBAL_OK,
  1390.         STR_GLOBAL_BACK,
  1391.         IMG_GLOBAL_BACK,
  1392.         numItems,
  1393.         nStrItemList,
  1394.         itemIcons,
  1395.         (U8 **) pPopUpList,
  1396.         0,
  1397.         0,
  1398.         guiBuffer);
  1399. #else /* __MMI_UNIFIED_MESSAGE__ */ 
  1400.     ShowCategory52Screen(
  1401.         STR_MESSAGE_MAIN_MENU_CAPTION,
  1402.         IMG_SMS_ENTRY_SCRN_CAPTION,
  1403.         STR_GLOBAL_OK,
  1404.         IMG_GLOBAL_OK,
  1405.         STR_GLOBAL_BACK,
  1406.         IMG_GLOBAL_BACK,
  1407.         numItems,
  1408.         nStrItemList,
  1409.         itemIcons,
  1410.         (U8 **) pPopUpList,
  1411.         0,
  1412.         0,
  1413.         guiBuffer);
  1414. #endif /* __MMI_UNIFIED_MESSAGE__ */ 
  1415.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  1416.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  1417. }
  1418. /* SMS use number       // */
  1419. static BOOL IsValidPhnumChar(S32 ch);
  1420. /*****************************************************************************
  1421.  * FUNCTION
  1422.  *  IsAPhoneNumber
  1423.  * DESCRIPTION
  1424.  *  Check if input is a number string
  1425.  * PARAMETERS
  1426.  *  number      [?]         
  1427.  *  a(?)        [IN]        String
  1428.  * RETURNS
  1429.  *  1: input is a number string, 0: input is not a number string
  1430.  *****************************************************************************/
  1431. int IsAPhoneNumber(S8 *number)
  1432. {
  1433.     /*----------------------------------------------------------------*/
  1434.     /* Local Variables                                                */
  1435.     /*----------------------------------------------------------------*/
  1436.     int c = *number;
  1437.     /*----------------------------------------------------------------*/
  1438.     /* Code Body                                                      */
  1439.     /*----------------------------------------------------------------*/
  1440.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[SmsMoMtGuiInterface.c] IsAPhoneNumber -------*n"));
  1441.     if (c != '+' && !IS_NUM(c))
  1442.     {
  1443.         return 0;
  1444.     }
  1445.     do
  1446.     {
  1447.         number += ENCODING_LENGTH;
  1448.         c = *number;
  1449.         if (c && !IS_NUM(c) && !IsValidPhnumChar(c))
  1450.         {
  1451.             return 0;
  1452.         }
  1453.     }
  1454.     while (c);
  1455.     return 1;
  1456. }
  1457. /*****************************************************************************
  1458.  * FUNCTION
  1459.  *  IsValidPhnumChar
  1460.  * DESCRIPTION
  1461.  *  Some special characters should be in use number list as well
  1462.  * PARAMETERS
  1463.  *  ch          [IN]        
  1464.  *  a(?)        [IN]        Character
  1465.  * RETURNS
  1466.  *  1: input is a number string, 0: input is not a number string
  1467.  *****************************************************************************/
  1468. static BOOL IsValidPhnumChar(S32 ch)
  1469. {
  1470.     /*----------------------------------------------------------------*/
  1471.     /* Local Variables                                                */
  1472.     /*----------------------------------------------------------------*/
  1473.     BOOL ret_value;
  1474.     /*----------------------------------------------------------------*/
  1475.     /* Code Body                                                      */
  1476.     /*----------------------------------------------------------------*/
  1477.     switch (ch)
  1478.     {
  1479.         case '+':
  1480.         case '*':
  1481.         case '#':
  1482.         case 'p':
  1483.         case 'P':
  1484.         case 'w':
  1485.         case 'W':
  1486.             ret_value = TRUE;
  1487.             break;
  1488.         default:
  1489.             ret_value = FALSE;
  1490.             break;
  1491.     }
  1492.     return ret_value;
  1493. }
  1494. /*****************************************************************************
  1495.  * FUNCTION
  1496.  *  GetPhoneNumber
  1497.  * DESCRIPTION
  1498.  *  Get phone number if input is not a number string
  1499.  * PARAMETERS
  1500.  *  number      [?]         
  1501.  *  a(?)        [IN]        String
  1502.  * RETURNS
  1503.  *  number string
  1504.  *****************************************************************************/
  1505. S8 *GetPhoneNumber(S8 *number)
  1506. {
  1507.     /*----------------------------------------------------------------*/
  1508.     /* Local Variables                                                */
  1509.     /*----------------------------------------------------------------*/
  1510.     /*----------------------------------------------------------------*/
  1511.     /* Code Body                                                      */
  1512.     /*----------------------------------------------------------------*/
  1513.     PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "*-------[SmsMoMtGuiInterface.c] GetPhoneNumber -------*n"));
  1514.     if (number && !IsAPhoneNumber(number))
  1515.     {
  1516.         number = lookUpName(number);
  1517.     }
  1518.     return number;
  1519. }
  1520. /*****************************************************************************
  1521.  * FUNCTION
  1522.  *  AlreadyExists
  1523.  * DESCRIPTION
  1524.  *  Check if input number string already exists in use number list
  1525.  * PARAMETERS
  1526.  *  thisNum     [?]         
  1527.  *  n           [IN]        
  1528.  *  a(?)        [IN]        Number string
  1529.  *  b(?)        [IN]        Current use number amount
  1530.  * RETURNS
  1531.  *  1: input string exists in use number list, 0: input string doesn't exist in use number list
  1532.  *****************************************************************************/
  1533. int AlreadyExists(S8 *thisNum, int n)
  1534. {
  1535.     /*----------------------------------------------------------------*/
  1536.     /* Local Variables                                                */
  1537.     /*----------------------------------------------------------------*/
  1538.     /*----------------------------------------------------------------*/
  1539.     /* Code Body                                                      */
  1540.     /*----------------------------------------------------------------*/
  1541.     n--;
  1542.     for (; n >= 0; n--)
  1543.     {
  1544.         if (!pfnUnicodeStrcmp(thisNum, g_msg_cntx.numbersList[n]))
  1545.         {
  1546.             return 1;
  1547.         }
  1548.     }
  1549.     return 0;
  1550. }
  1551. /*****************************************************************************
  1552.  * FUNCTION
  1553.  *  GetAsciiOrUCS2Char
  1554.  * DESCRIPTION
  1555.  *  Get Ascii or UCS2 character
  1556.  * PARAMETERS
  1557.  *  buf         [?]         
  1558.  *  a(?)        [IN]        Address of string
  1559.  * RETURNS
  1560.  *  the description of return value, if any.
  1561.  *****************************************************************************/
  1562. S16 GetAsciiOrUCS2Char(S8 *buf)
  1563. {
  1564.     /*----------------------------------------------------------------*/
  1565.     /* Local Variables                                                */
  1566.     /*----------------------------------------------------------------*/
  1567.     /*----------------------------------------------------------------*/
  1568.     /* Code Body                                                      */
  1569.     /*----------------------------------------------------------------*/
  1570.     return (*buf + ((*(buf + 1)) << 8));
  1571. }
  1572. /*****************************************************************************
  1573.  * FUNCTION
  1574.  *  GetAsciiOrUCS2Char_RV
  1575.  * DESCRIPTION
  1576.  *  Get Ascii or UCS2 character
  1577.  * PARAMETERS
  1578.  *  buf         [?]         
  1579.  *  a(?)        [IN]        Address of string
  1580.  * RETURNS
  1581.  *  the description of return value, if any.
  1582.  *****************************************************************************/
  1583. S16 GetAsciiOrUCS2Char_RV(U8 *buf)
  1584. {
  1585.     /*----------------------------------------------------------------*/
  1586.     /* Local Variables                                                */
  1587.     /*----------------------------------------------------------------*/
  1588.     /*----------------------------------------------------------------*/
  1589.     /* Code Body                                                      */
  1590.     /*----------------------------------------------------------------*/
  1591.     return (*(buf + 1) + ((*buf) << 8));
  1592. }
  1593. /*****************************************************************************
  1594.  * FUNCTION
  1595.  *  PutAsciiOrUCS2Char
  1596.  * DESCRIPTION
  1597.  *  Put Ascii or UCS2 chatacter
  1598.  * PARAMETERS
  1599.  *  buf         [?]             
  1600.  *  c           [IN]            
  1601.  *  a(?)        [IN/OUT]        Address of string
  1602.  *  b(?)        [IN]            Input character
  1603.  * RETURNS
  1604.  *  the description of return value, if any.(?)
  1605.  *****************************************************************************/
  1606. void PutAsciiOrUCS2Char(S8 *buf, S16 c)
  1607. {
  1608.     /*----------------------------------------------------------------*/
  1609.     /* Local Variables                                                */
  1610.     /*----------------------------------------------------------------*/
  1611.     /*----------------------------------------------------------------*/
  1612.     /* Code Body                                                      */
  1613.     /*----------------------------------------------------------------*/
  1614.     *buf++ = c & 0xff;
  1615.     *buf = c >> 8;
  1616. }
  1617. /*****************************************************************************
  1618.  * FUNCTION
  1619.  *  IsSymbolValid
  1620.  * DESCRIPTION
  1621.  *  Check if symbol is valid to insert use number
  1622.  * PARAMETERS
  1623.  *  c               [IN]        Current use number record length
  1624.  *  inBracket       [IN]        
  1625.  *  numIndex        [IN]        
  1626.  *  a(?)            [IN]        Input character
  1627.  *  b(?)            [IN]        Bracket waiting flag
  1628.  * RETURNS
  1629.  *  1: symbol is valid, 0: symbol is not valid
  1630.  *****************************************************************************/
  1631. static U8 IsSymbolValid(int c, U8 inBracket, U8 numIndex)
  1632. {
  1633.     /*----------------------------------------------------------------*/
  1634.     /* Local Variables                                                */
  1635.     /*----------------------------------------------------------------*/
  1636.     U8 status = 0;
  1637.     /*----------------------------------------------------------------*/
  1638.     /* Code Body                                                      */
  1639.     /*----------------------------------------------------------------*/
  1640.     if (IS_NUM(c))
  1641.     {
  1642.         return 1;
  1643.     }
  1644.     numIndex = numIndex / ENCODING_LENGTH;
  1645.     switch (c)
  1646.     {
  1647.         case '+':
  1648.             if (numIndex == 0)
  1649.             {
  1650.                 status = 1;
  1651.             }
  1652.             break;
  1653.         case '(':
  1654.             status = 1;
  1655.             break;
  1656.         case ')':
  1657.             if (inBracket)
  1658.             {
  1659.                 status = 1;
  1660.             }
  1661.             break;
  1662.         case 'p':
  1663.         case 'w':
  1664.         case '-':
  1665.             if (numIndex >= USE_NUM_MIN_LENGTH)
  1666.             {
  1667.                 status = 1;
  1668.             }
  1669.             break;
  1670.         default:
  1671.             status = 0;
  1672.     }
  1673.     return status;
  1674. }
  1675. /*****************************************************************************
  1676.  * FUNCTION
  1677.  *  TruncateLastUnwantedSymbols
  1678.  * DESCRIPTION
  1679.  *  Truncate use number last unwanted symbols
  1680.  * PARAMETERS
  1681.  *  buf         [?]             
  1682.  *  len         [IN]            
  1683.  *  a(?)        [IN/OUT]        Address of string
  1684.  *  b(?)        [IN]            String length
  1685.  * RETURNS
  1686.  *  void
  1687.  *****************************************************************************/
  1688. static void TruncateLastUnwantedSymbols(S8 *buf, int len)
  1689. {
  1690.     /*----------------------------------------------------------------*/
  1691.     /* Local Variables                                                */
  1692.     /*----------------------------------------------------------------*/
  1693.     int i, last = 0;
  1694.     int c;
  1695.     /*----------------------------------------------------------------*/
  1696.     /* Code Body                                                      */
  1697.     /*----------------------------------------------------------------*/
  1698.     for (i = 0; i < len; i += ENCODING_LENGTH)
  1699.     {
  1700.         c = GetAsciiOrUCS2Char(&buf[i]);
  1701.         if ((c != 'p') && (c != 'w') && (c != '-'))
  1702.         {
  1703.             last = i;
  1704.         }
  1705.     }
  1706.     if (i > last)
  1707.     {
  1708.         last += ENCODING_LENGTH;
  1709.     }
  1710.     PutAsciiOrUCS2Char(&buf[last], '');
  1711. }
  1712. /*****************************************************************************
  1713.  * FUNCTION
  1714.  *  ObtainNumbersFromMessageText
  1715.  * DESCRIPTION
  1716.  *  Obtain number list from message content
  1717.  * PARAMETERS
  1718.  *  phNumber        [?]         
  1719.  *  smsText         [?]         
  1720.  *  bufLen          [IN]        
  1721.  *  startindex      [IN]        
  1722.  *  a(?)            [IN]        Message phone number
  1723.  *  d(?)            [IN]        Number list start index
  1724.  *  c(?)            [IN]        Message length
  1725.  *  b(?)            [IN]        Message content
  1726.  * RETURNS
  1727.  *  current use number list amount
  1728.  *****************************************************************************/
  1729. U16 ObtainNumbersFromMessageText(char *phNumber, U8 *smsText, U16 bufLen, U8 startindex)
  1730. {
  1731.     /*----------------------------------------------------------------*/
  1732.     /* Local Variables                                                */
  1733.     /*----------------------------------------------------------------*/
  1734.     int i;
  1735.     int c;
  1736.     S8 thisNum[(MAX_DIGITS + 1) * ENCODING_LENGTH];
  1737.     int pickNow = 0;
  1738.     U8 inBracket = 0;
  1739.     int thisNumIndex = 0;
  1740.     int currNumListIndex = startindex;
  1741.     /*----------------------------------------------------------------*/
  1742.     /* Code Body                                                      */
  1743.     /*----------------------------------------------------------------*/
  1744.     if (pfnUnicodeStrlen((S8*) phNumber))
  1745.     {
  1746.         phNumber = GetPhoneNumber(phNumber);
  1747.         if (phNumber)
  1748.         {
  1749.             if (g_msg_cntx.numbersList[currNumListIndex])
  1750.             {
  1751.                 OslMfree(g_msg_cntx.numbersList[currNumListIndex]);
  1752.             }
  1753.             g_msg_cntx.numbersList[currNumListIndex] = OslMalloc((pfnUnicodeStrlen(phNumber) + 2) * ENCODING_LENGTH);
  1754.             pfnUnicodeStrcpy((S8*) g_msg_cntx.numbersList[currNumListIndex], phNumber);
  1755.             currNumListIndex++;
  1756.         }
  1757.     }
  1758.     if (currNumListIndex == MAX_USE_NUMBERS)
  1759.     {
  1760.         return (U16) currNumListIndex;
  1761.     }
  1762.     for (i = 0; i < bufLen;)
  1763.     {
  1764.         c = GetAsciiOrUCS2Char((S8*) & smsText[i]);
  1765.         i += ENCODING_LENGTH;
  1766.         if (IsSymbolValid(c, inBracket, (U8) thisNumIndex) && (thisNumIndex < (MAX_DIGITS - 1) * ENCODING_LENGTH))
  1767.         {
  1768.             if ((c != '-') && (c != '(') && (c != ')'))
  1769.             {
  1770.                 PutAsciiOrUCS2Char(&thisNum[thisNumIndex], (S16) c);
  1771.                 thisNumIndex += ENCODING_LENGTH;
  1772.             }
  1773.             if (c == '(')
  1774.             {
  1775.                 inBracket++;
  1776.             }
  1777.             else if ((c == ')') && inBracket)
  1778.             {
  1779.                 inBracket--;
  1780.             }
  1781.         }
  1782.         else
  1783.         {
  1784.             pickNow = 1;
  1785.             while (thisNumIndex && (i < bufLen))
  1786.             {
  1787.                 if (!IS_NUM(c))
  1788.                 {
  1789.                     /* to handle the scenario number'+'number  ex. "123+123"  should be parsed as 123 and +123, instead of 123 */
  1790.                     if (c == '+')
  1791.                     {
  1792.                         i -= ENCODING_LENGTH;
  1793.                     }
  1794.                 }
  1795.                 /* a stream of number that exceeds 40 digits, the number starting from 41 digits will become the next use number */
  1796.                 else    /* c is a num */
  1797.                 {
  1798.                     i -= ENCODING_LENGTH;
  1799.                 }
  1800.                 break;
  1801.                 // c = GetAsciiOrUCS2Char((S8*) & smsText[i]);
  1802.                 // i += ENCODING_LENGTH;
  1803.             }
  1804.         }
  1805.         if (i >= bufLen)
  1806.         {
  1807.             pickNow = 1;
  1808.         }
  1809.         if (pickNow)
  1810.         {
  1811.             int c1 = 0;
  1812.             pickNow = 0;
  1813.             if (thisNumIndex && ((c1 = GetAsciiOrUCS2Char((S8*) & thisNum[thisNumIndex - ENCODING_LENGTH])) == 'w')
  1814.                 || (c1 == 'p'))
  1815.             {
  1816.                 TruncateLastUnwantedSymbols(thisNum, thisNumIndex);
  1817.             }
  1818.             PutAsciiOrUCS2Char(&thisNum[thisNumIndex], '');
  1819.             if (!AlreadyExists(thisNum, currNumListIndex))
  1820.             {
  1821.                 if (thisNumIndex >= (USE_NUM_MIN_LENGTH * ENCODING_LENGTH))
  1822.                 {
  1823.                     if (g_msg_cntx.numbersList[currNumListIndex])
  1824.                     {
  1825.                         OslMfree(g_msg_cntx.numbersList[currNumListIndex]);
  1826.                     }
  1827.                     g_msg_cntx.numbersList[currNumListIndex] = OslMalloc((pfnUnicodeStrlen(thisNum) + 2) * ENCODING_LENGTH);
  1828.                     pfnUnicodeStrcpy((S8*) g_msg_cntx.numbersList[currNumListIndex], thisNum);
  1829.                     currNumListIndex++;
  1830.                     if (currNumListIndex == MAX_USE_NUMBERS)
  1831.                     {
  1832.                         break;
  1833.                     }
  1834.                 }
  1835.             }
  1836.             thisNumIndex = 0;
  1837.         }
  1838.     }
  1839.     return (U16) currNumListIndex;
  1840. }
  1841. #ifdef __MMI_MESSAGES_CHAT__
  1842. /*****************************************************************************
  1843.  * FUNCTION
  1844.  *  ObtainChatNumbersFromMessageTextWrapper
  1845.  * DESCRIPTION
  1846.  *  Obtain number list from chat message content
  1847.  * PARAMETERS
  1848.  *  phNumber            [?]         
  1849.  *  chatroomindex       [IN]        
  1850.  *  a(?)                [IN]        Message phone number
  1851.  *  b(?)                [IN]        Message room index
  1852.  * RETURNS
  1853.  *  current use number list amount
  1854.  *****************************************************************************/
  1855. U16 ObtainChatNumbersFromMessageTextWrapper(char *phNumber, S16 chatroomindex)
  1856. {
  1857.     /*----------------------------------------------------------------*/
  1858.     /* Local Variables                                                */
  1859.     /*----------------------------------------------------------------*/
  1860.     U16 bufLen = 0;
  1861.     U8 *smsText = NULL;
  1862.     S16 j;
  1863.     U16 currindex = 0;
  1864.     /*----------------------------------------------------------------*/
  1865.     /* Code Body                                                      */
  1866.     /*----------------------------------------------------------------*/
  1867.     for (j = 0; j < GetNumOfMessage(chatroomindex); j++)
  1868.     {
  1869.         smsText = GetMemoryPointer(j, chatroomindex);
  1870.         bufLen = (S16) pfnUnicodeStrlen((PS8) smsText);
  1871.         bufLen = bufLen * ENCODING_LENGTH;
  1872.         if (j == 0)
  1873.         {
  1874.             currindex = ObtainNumbersFromMessageText(phNumber, smsText, bufLen, 0);
  1875.         }
  1876.         else
  1877.         {
  1878.             currindex = ObtainNumbersFromMessageText(NULL, smsText, bufLen, (U8) currindex);
  1879.         }
  1880.         if (currindex == MAX_USE_NUMBERS)
  1881.         {
  1882.             return currindex;
  1883.         }
  1884.     }
  1885.     /* chat room message content is empty but the destination number should still be displayed in the use number list */
  1886.     if (GetNumOfMessage(chatroomindex) == 0)
  1887.     {
  1888.         if (pfnUnicodeStrlen((S8*) phNumber))
  1889.         {
  1890.             phNumber = GetPhoneNumber(phNumber);
  1891.             if (phNumber)
  1892.             {
  1893.                 if (g_msg_cntx.numbersList[currindex])
  1894.                 {
  1895.                     OslMfree(g_msg_cntx.numbersList[currindex]);
  1896.                 }
  1897.                 g_msg_cntx.numbersList[currindex] = OslMalloc((pfnUnicodeStrlen(phNumber) + 2) * ENCODING_LENGTH);
  1898.                 pfnUnicodeStrcpy((S8*) g_msg_cntx.numbersList[currindex], phNumber);
  1899.                 currindex++;
  1900.             }
  1901.         }
  1902.     }
  1903.     return currindex;
  1904. }
  1905. /*****************************************************************************
  1906.  * FUNCTION
  1907.  *  GetNewChatSmsIndDisplayStr
  1908.  * DESCRIPTION
  1909.  *  Get chat message indication string for dislpay
  1910.  * PARAMETERS
  1911.  *  void
  1912.  * RETURNS
  1913.  *  NewChatMessageFromXxxStr
  1914.  *****************************************************************************/
  1915. PU8 GetNewChatSmsIndDisplayStr(void)
  1916. {
  1917.     /*----------------------------------------------------------------*/
  1918.     /* Local Variables                                                */
  1919.     /*----------------------------------------------------------------*/
  1920.     /*----------------------------------------------------------------*/
  1921.     /* Code Body                                                      */
  1922.     /*----------------------------------------------------------------*/
  1923.     PRINT_INFORMATION(("*-------[MessagesIdleApp.c] GetNewSmsIndDisplayStr -------*n"));
  1924.     return NewChatMessageFromXxxStr;
  1925. }
  1926. /*****************************************************************************
  1927.  * FUNCTION
  1928.  *  GetNewChatMsgIndDisplayString
  1929.  * DESCRIPTION
  1930.  *  Compose new chat message indication string
  1931.  * PARAMETERS
  1932.  *  number      [?]         
  1933.  *  length      [IN]        
  1934.  *  type        [IN]        
  1935.  *  a(?)        [IN]        Message phone number
  1936.  *  c(?)        [IN]        Message number type
  1937.  *  b(?)        [IN]        Message number length
  1938.  * RETURNS
  1939.  *  void
  1940.  *****************************************************************************/
  1941. void GetNewChatMsgIndDisplayString(U8 *number, U8 length, U8 type)
  1942. {
  1943.     /*----------------------------------------------------------------*/
  1944.     /* Local Variables                                                */
  1945.     /*----------------------------------------------------------------*/
  1946.     /*----------------------------------------------------------------*/
  1947.     /* Code Body                                                      */
  1948.     /*----------------------------------------------------------------*/
  1949.     PRINT_INFORMATION(("*-------[MessagesIdleApp.c] GetNewMsgIndDisplayString -------*n"));
  1950.     memset(&NewChatMessageFromXxxStr, 0, sizeof(NewChatMessageFromXxxStr));
  1951.     if (length)
  1952.     {
  1953.         PS8 phbName = NULL;
  1954.         PU8 pPhoneNumberPtr = ConvertL4NumberStructToDisplay(number, length, type);
  1955.         phbName = lookUpNumber((S8*) pPhoneNumberPtr);
  1956.         if (phbName != NULL)
  1957.         {
  1958.             if (pfnUnicodeStrcmp(phbName, ""))
  1959.             {
  1960.                 pfnUnicodeStrncpy(
  1961.                     (PS8) NewChatMessageFromXxxStr,
  1962.                     (PS8) phbName,
  1963.                     (U32) (sizeof(NewChatMessageFromXxxStr) / ENCODING_LENGTH) - 1);
  1964.             }
  1965.             else
  1966.             {
  1967.                 pfnUnicodeStrncat(
  1968.                     (PS8) NewChatMessageFromXxxStr,
  1969.                     (PS8) pPhoneNumberPtr,
  1970.                     (U32) (sizeof(NewChatMessageFromXxxStr) / ENCODING_LENGTH) - 1);
  1971.             }
  1972.         }
  1973.         else
  1974.         {
  1975.             pfnUnicodeStrncat(
  1976.                 (PS8) NewChatMessageFromXxxStr,
  1977.                 (PS8) pPhoneNumberPtr,
  1978.                 (U32) (sizeof(NewChatMessageFromXxxStr) / ENCODING_LENGTH) - 1);
  1979.         }
  1980.         if (pPhoneNumberPtr)
  1981.         {
  1982.             OslMfree(pPhoneNumberPtr);
  1983.             pPhoneNumberPtr = NULL;
  1984.         }
  1985.     }
  1986. }
  1987. /*****************************************************************************
  1988.  * FUNCTION
  1989.  *  DeleteChatMsg
  1990.  * DESCRIPTION
  1991.  *  Delete chat message
  1992.  * PARAMETERS
  1993.  *  index       [IN]        
  1994.  *  a(?)        [IN]        Message index
  1995.  * RETURNS
  1996.  *  void
  1997.  *****************************************************************************/
  1998. void DeleteChatMsg(S32 index)
  1999. {
  2000.     /*----------------------------------------------------------------*/
  2001.     /* Local Variables                                                */
  2002.     /*----------------------------------------------------------------*/
  2003.     /*----------------------------------------------------------------*/
  2004.     /* Code Body                                                      */
  2005.     /*----------------------------------------------------------------*/
  2006.     g_msg_cntx.msg_ind_chat_index = (U16) index;
  2007. }
  2008. /*****************************************************************************
  2009.  * FUNCTION
  2010.  *  GetConcatenatedMessage
  2011.  * DESCRIPTION
  2012.  *  Concatenate message for chat room screen
  2013.  * PARAMETERS
  2014.  *  void
  2015.  * RETURNS
  2016.  *  void
  2017.  *****************************************************************************/
  2018. void GetConcatenatedMessage(void)
  2019. {
  2020.     /*----------------------------------------------------------------*/
  2021.     /* Local Variables                                                */
  2022.     /*----------------------------------------------------------------*/
  2023.     EMSData *pEMSdata;
  2024.     /*----------------------------------------------------------------*/
  2025.     /* Code Body                                                      */
  2026.     /*----------------------------------------------------------------*/
  2027.     GetEMSDataForView(&pEMSdata, 1);    /* force to clear old content and initialize */
  2028.     EMSUnPack(pEMSdata, 1, PendingSaveSendData.totalSegments, PendingSaveSendData.TPUD_p, PendingSaveSendData.TPUDLen);
  2029.     return;
  2030. }
  2031. #endif /* __MMI_MESSAGES_CHAT__ */ 
  2032. #ifdef __MMI_MESSAGES_TEMPLATE__
  2033. /*****************************************************************************
  2034.  * FUNCTION
  2035.  *  ReadTemplateFromNVRAM
  2036.  * DESCRIPTION
  2037.  *  Read template from NVRAM
  2038.  * PARAMETERS
  2039.  *  index       [IN]        
  2040.  *  a(?)        [IN]        Index
  2041.  * RETURNS
  2042.  *  void
  2043.  *****************************************************************************/
  2044. void ReadTemplateFromNVRAM(U16 index)
  2045. {
  2046.     /*----------------------------------------------------------------*/
  2047.     /* Local Variables                                                */
  2048.     /*----------------------------------------------------------------*/
  2049.     S16 error;
  2050.     /*----------------------------------------------------------------*/
  2051.     /* Code Body                                                      */
  2052.     /*----------------------------------------------------------------*/
  2053.     if (index >= NVRAM_SMS_RECORD_TOTAL)
  2054.     {
  2055.         PRINT_INFORMATION_2((MMI_TRACE_G6_SMS, "### ERROR: ReadTemplateFromNVRAM: index out of bound"));
  2056.         return;
  2057.     }
  2058.     memset(g_msg_cntx.scratchTemplRec, 0, NVRAM_SMS_TEMPL_RECORD_SIZE + ENCODING_LENGTH);
  2059.     if (ReadRecord(NVRAM_EF_SMS_LID, (U16) (index + 1), g_msg_cntx.scratchTemplRec, NVRAM_SMS_TEMPL_RECORD_SIZE, &error)
  2060.         < 0)
  2061.     {
  2062.         g_msg_cntx.scratchTemplRec[0] = '';
  2063.     }
  2064.     return;
  2065. }
  2066. /*****************************************************************************
  2067.  * FUNCTION
  2068.  *  WriteTemplateToNVRAM
  2069.  * DESCRIPTION
  2070.  *  Write template to NVRAM
  2071.  * PARAMETERS
  2072.  *  index       [IN]        
  2073.  *  a(?)        [IN]        Index
  2074.  * RETURNS
  2075.  *  TRUE: write success, FALSE: write fail
  2076.  *****************************************************************************/
  2077. U8 WriteTemplateToNVRAM(U16 index)
  2078. {
  2079.     /*----------------------------------------------------------------*/
  2080.     /* Local Variables                                                */
  2081.     /*----------------------------------------------------------------*/
  2082.     S16 error;
  2083.     /*----------------------------------------------------------------*/
  2084.     /* Code Body                                                      */
  2085.     /*----------------------------------------------------------------*/
  2086.     if (index >= NVRAM_SMS_RECORD_TOTAL)
  2087.     {
  2088.         return FALSE;
  2089.     }
  2090.     if (WriteRecord
  2091.         (NVRAM_EF_SMS_LID, (U16) (index + 1 + 1), g_msg_cntx.scratchTemplRec, NVRAM_SMS_TEMPL_RECORD_SIZE,
  2092.          &error) != NVRAM_SMS_TEMPL_RECORD_SIZE)
  2093.     {
  2094.         return FALSE;
  2095.     }
  2096.     return TRUE;
  2097. }
  2098. #if defined(_MUTILANG_TEMPLATE_) || defined(__MMI_MESSAGES_SIMCHINESE_TEMPLATE__)
  2099. /*****************************************************************************
  2100.  * FUNCTION
  2101.  *  SetTemplateLanguage
  2102.  * DESCRIPTION
  2103.  *  Set template language
  2104.  * PARAMETERS
  2105.  *  langtype        [IN]        
  2106.  *  a(?)            [IN]        Language type
  2107.  * RETURNS
  2108.  *  void
  2109.  *****************************************************************************/
  2110. void SetTemplateLanguage(U8 langtype)
  2111. {
  2112.     /*----------------------------------------------------------------*/
  2113.     /* Local Variables                                                */
  2114.     /*----------------------------------------------------------------*/
  2115.     U8 i = 0;
  2116.     S16 error;
  2117.     S8 tempLang[SSC_SIZE];
  2118.     /*----------------------------------------------------------------*/
  2119.     /* Code Body                                                      */
  2120.     /*----------------------------------------------------------------*/
  2121.     memset(tempLang, 0, SSC_SIZE);
  2122.     switch (langtype)
  2123.     {
  2124.         case MSG_TEMPLATE_LANG_ENGLISH:
  2125.             memcpy(tempLang, SSC_ENGLISH, SSC_SIZE);
  2126.             break;
  2127.         case MSG_TEMPLATE_LANG_SIMCHINESE:
  2128.             memcpy(tempLang, SSC_SCHINESE, SSC_SIZE);
  2129.             break;
  2130.         case MSG_TEMPLATE_LANG_TRACHINESE:
  2131.             memcpy(tempLang, SSC_TCHINESE, SSC_SIZE);
  2132.             break;
  2133.     }
  2134.     for (i = 0; i < MAX_LANGUAGES; i++)
  2135.     {
  2136.         if (strcmp((PS8) gLanguageArray[i].aLangSSC, (S8*) tempLang) == 0)
  2137.         {
  2138.             if (gCurrLangIndex != i)
  2139.             {
  2140.                 SetCurrentLanguage(i);
  2141.                 WriteValue(NVRAM_SETTING_LANG, &i, DS_BYTE, &error);
  2142.                 break;
  2143.             }
  2144.         }
  2145.     }
  2146. }
  2147. /*****************************************************************************
  2148.  * FUNCTION
  2149.  *  UnsetTemplateLanguage
  2150.  * DESCRIPTION
  2151.  *  Unset template language
  2152.  * PARAMETERS
  2153.  *  void
  2154.  * RETURNS
  2155.  *  void
  2156.  *****************************************************************************/
  2157. void UnsetTemplateLanguage(void)
  2158. {
  2159.     /*----------------------------------------------------------------*/
  2160.     /* Local Variables                                                */
  2161.     /*----------------------------------------------------------------*/
  2162.     U8 i = 0;
  2163.     S16 error;
  2164.     /*----------------------------------------------------------------*/
  2165.     /* Code Body                                                      */
  2166.     /*----------------------------------------------------------------*/
  2167.     for (i = 0; i < MAX_LANGUAGES; i++)
  2168.     {
  2169.         if (strcmp((PS8) gLanguageArray[i].aLangSSC, (PS8) currLang) == 0)
  2170.         {
  2171.             if (gCurrLangIndex != i)
  2172.             {
  2173.                 SetCurrentLanguage(i);
  2174.                 WriteValue(NVRAM_SETTING_LANG, &i, DS_BYTE, &error);
  2175.                 break;
  2176.             }
  2177.         }
  2178.     }
  2179. }
  2180. #endif /* defined(_MUTILANG_TEMPLATE_) || defined(__MMI_MESSAGES_SIMCHINESE_TEMPLATE__) */ 
  2181. /*****************************************************************************
  2182.  * FUNCTION
  2183.  *  WriteDefaultTemplateToNVRAM
  2184.  * DESCRIPTION
  2185.  *  Write default template to NVRAM
  2186.  * PARAMETERS
  2187.  *  void
  2188.  * RETURNS
  2189.  *  void
  2190.  *****************************************************************************/
  2191. U8 WriteDefaultTemplateToNVRAM(void)
  2192. {
  2193.     /*----------------------------------------------------------------*/
  2194.     /* Local Variables                                                */
  2195.     /*----------------------------------------------------------------*/
  2196.     U16 i = 0;
  2197.     S8 *tmpl_str;
  2198.     U8 result;
  2199.     /*----------------------------------------------------------------*/
  2200.     /* Code Body                                                      */
  2201.     /*----------------------------------------------------------------*/
  2202.     for (i = 0; i < NUM_TEMPLATES; i++)
  2203.     {
  2204.         U16 templateindex = i + CalTemplateBase();
  2205.         tmpl_str = GetString(templateStrings[i]);
  2206.         memset(g_msg_cntx.scratchTemplRec, 0, NVRAM_SMS_TEMPL_RECORD_SIZE + ENCODING_LENGTH);
  2207.         if (tmpl_str)
  2208.         {
  2209.             memcpy(g_msg_cntx.scratchTemplRec, tmpl_str, (pfnUnicodeStrlen(tmpl_str) + 1) * ENCODING_LENGTH);
  2210.         }
  2211.         result = WriteTemplateToNVRAM(templateindex);
  2212.         if (result == FALSE)
  2213.         {
  2214.             return FALSE;
  2215.         }
  2216.     }
  2217.     return TRUE;
  2218. }
  2219. /*****************************************************************************
  2220.  * FUNCTION
  2221.  *  InitTemplates
  2222.  * DESCRIPTION
  2223.  *  Init templates
  2224.  * PARAMETERS
  2225.  *  void
  2226.  * RETURNS
  2227.  *  TRUE: init success, FALSE: init fail
  2228.  *****************************************************************************/
  2229. U8 InitTemplates(void)
  2230. {
  2231.     /*----------------------------------------------------------------*/
  2232.     /* Local Variables                                                */
  2233.     /*----------------------------------------------------------------*/
  2234.     static int initDone = 0;
  2235.     static S8 templateSignature[MAX_TEMPLATE_LENGTH + 1] = "AAA";
  2236.     S8 buffer[NVRAM_SMS_TEMPL_RECORD_SIZE];
  2237.     S16 error;
  2238.     int i;
  2239.     /*----------------------------------------------------------------*/
  2240.     /* Code Body                                                      */
  2241.     /*----------------------------------------------------------------*/
  2242.     if (initDone)
  2243.     {
  2244.         return TRUE;
  2245.     }
  2246.     initDone = 1;
  2247.     if (ReadRecord(NVRAM_EF_SMS_LID, 1, buffer, NVRAM_SMS_TEMPL_RECORD_SIZE, &error) < 0)
  2248.     {
  2249.         buffer[0] = '';
  2250.     }
  2251.     if (buffer[0] == 'A')
  2252.     {
  2253.         return TRUE;
  2254.     }
  2255. #if defined (_MUTILANG_TEMPLATE_) || defined (__MMI_MESSAGES_SIMCHINESE_TEMPLATE__)
  2256.     memset(currLang, 0, SSC_SIZE);
  2257.     memcpy(currLang, (PS8) gLanguageArray[gCurrLangIndex].aLangSSC, SSC_SIZE);
  2258. #ifdef _MUTILANG_TEMPLATE_
  2259.     for (i = 0; i < TOTAL_TEMPLATE_LANGUAGE; i++)
  2260.     {
  2261.         SetTemplateLanguage((U8) i);
  2262.         if (!WriteDefaultTemplateToNVRAM())
  2263.         {
  2264.             return FALSE;
  2265.         }
  2266.     }
  2267. #else /* _MUTILANG_TEMPLATE_ */ 
  2268.     SetTemplateLanguage(MSG_TEMPLATE_LANG_SIMCHINESE);
  2269.     if (!WriteDefaultTemplateToNVRAM())
  2270.     {
  2271.         return FALSE;
  2272.     }
  2273. #endif /* _MUTILANG_TEMPLATE_ */ 
  2274.     UnsetTemplateLanguage();
  2275. #else /* defined (_MUTILANG_TEMPLATE_) || defined (__MMI_MESSAGES_SIMCHINESE_TEMPLATE__) */ 
  2276.     if (!WriteDefaultTemplateToNVRAM())
  2277.     {
  2278.         return FALSE;
  2279.     }
  2280. #endif /* defined (_MUTILANG_TEMPLATE_) || defined (__MMI_MESSAGES_SIMCHINESE_TEMPLATE__) */ 
  2281.     if (WriteRecord(NVRAM_EF_SMS_LID, 1, templateSignature, NVRAM_SMS_TEMPL_RECORD_SIZE, &error) <
  2282.         NVRAM_SMS_TEMPL_RECORD_SIZE)
  2283.     {
  2284.         return FALSE;
  2285.     }
  2286.     return TRUE;
  2287. }
  2288. /*****************************************************************************
  2289.  * FUNCTION
  2290.  *  DeInitTemplates
  2291.  * DESCRIPTION
  2292.  *  Deinit templates
  2293.  * PARAMETERS
  2294.  *  void
  2295.  * RETURNS
  2296.  *  void
  2297.  *****************************************************************************/
  2298. void DeInitTemplates(void)
  2299. {
  2300.     /*----------------------------------------------------------------*/
  2301.     /* Local Variables                                                */
  2302.     /*----------------------------------------------------------------*/
  2303.     int i;
  2304.     /*----------------------------------------------------------------*/
  2305.     /* Code Body                                                      */
  2306.     /*----------------------------------------------------------------*/
  2307.     for (i = 0; i < NUM_TEMPLATES; i++)
  2308.     {
  2309.         if (g_msg_cntx.templates[i])
  2310.         {
  2311.             OslMfree(g_msg_cntx.templates[i]);
  2312.             g_msg_cntx.templates[i] = NULL;
  2313.         }
  2314.     }
  2315. }
  2316. /*****************************************************************************
  2317.  * FUNCTION
  2318.  *  LoadTemplatesInDisplayList
  2319.  * DESCRIPTION
  2320.  *  Load templates to display list
  2321.  * PARAMETERS
  2322.  *  void
  2323.  * RETURNS
  2324.  *  void
  2325.  *****************************************************************************/
  2326. void LoadTemplatesInDisplayList(void)
  2327. {
  2328.     /*----------------------------------------------------------------*/
  2329.     /* Local Variables                                                */
  2330.     /*----------------------------------------------------------------*/
  2331.     U16 i;
  2332.     /*----------------------------------------------------------------*/
  2333.     /* Code Body                                                      */
  2334.     /*----------------------------------------------------------------*/
  2335.     DeInitTemplates();
  2336.     for (i = 0; i < NUM_TEMPLATES; i++)
  2337.     {
  2338.         U16 templateindex = i + CalTemplateBase() + 1;
  2339.         ReadTemplateFromNVRAM(templateindex);
  2340.         g_msg_cntx.templates[i] = OslMalloc((pfnUnicodeStrlen(g_msg_cntx.scratchTemplRec) + 1) * ENCODING_LENGTH);
  2341.         pfnUnicodeStrcpy(g_msg_cntx.templates[i], g_msg_cntx.scratchTemplRec);
  2342.     }
  2343. }
  2344. /*****************************************************************************
  2345.  * FUNCTION
  2346.  *  GetTemplatesToEdit
  2347.  * DESCRIPTION
  2348.  *  Get templates to edit.
  2349.  * PARAMETERS
  2350.  *  buffer      [?]             
  2351.  *  index       [IN]            
  2352.  *  a(?)        [IN/OUT]        Address of string
  2353.  *  b(?)        [IN]            Current highlight index
  2354.  * RETURNS
  2355.  *  void
  2356.  *****************************************************************************/
  2357. void GetTemplatesToEdit(S8 *buffer, U32 index)
  2358. {
  2359.     /*----------------------------------------------------------------*/
  2360.     /* Local Variables                                                */
  2361.     /*----------------------------------------------------------------*/
  2362.     /*----------------------------------------------------------------*/
  2363.     /* Code Body                                                      */
  2364.     /*----------------------------------------------------------------*/
  2365.     if (g_msg_cntx.templates[index])
  2366.     {
  2367.         pfnUnicodeStrcpy((PS8) buffer, (PS8) g_msg_cntx.templates[index]);
  2368.     }
  2369.     else
  2370.     {
  2371.         buffer[0] = buffer[1] = '';
  2372.     }
  2373. }
  2374. /*****************************************************************************
  2375.  * FUNCTION
  2376.  *  DeleteTemplate
  2377.  * DESCRIPTION
  2378.  *  Delete template
  2379.  * PARAMETERS
  2380.  *  index       [IN]        
  2381.  *  a(?)        [IN]        Index
  2382.  * RETURNS
  2383.  *  TRUE: delete success, FALSE: delete fail
  2384.  *****************************************************************************/
  2385. U8 DeleteTemplate(U32 index)
  2386. {
  2387.     /*----------------------------------------------------------------*/
  2388.     /* Local Variables                                                */
  2389.     /*----------------------------------------------------------------*/
  2390.     U16 templateindex = (U16) index + CalTemplateBase();
  2391.     U8 result;
  2392.     /*----------------------------------------------------------------*/
  2393.     /* Code Body                                                      */
  2394.     /*----------------------------------------------------------------*/
  2395.     memset(g_msg_cntx.scratchTemplRec, 0, NVRAM_SMS_TEMPL_RECORD_SIZE + ENCODING_LENGTH);
  2396.     result = WriteTemplateToNVRAM(templateindex);
  2397.     return result;
  2398. }
  2399. /*****************************************************************************
  2400.  * FUNCTION
  2401.  *  StoreTemplate
  2402.  * DESCRIPTION
  2403.  *  Store templates
  2404.  * PARAMETERS
  2405.  *  index       [IN]        
  2406.  *  a(?)        [IN]        Index
  2407.  *  b(?)        [IN]        Address of string
  2408.  * RETURNS
  2409.  *  TRUE: store success, FALSE: store fail
  2410.  *****************************************************************************/
  2411. U8 StoreTemplate(U32 index)
  2412. {
  2413.     /*----------------------------------------------------------------*/
  2414.     /* Local Variables                                                */
  2415.     /*----------------------------------------------------------------*/
  2416.     U16 templateindex = (U16) index + CalTemplateBase();
  2417.     U8 result;
  2418.     /*----------------------------------------------------------------*/
  2419.     /* Code Body                                                      */
  2420.     /*----------------------------------------------------------------*/
  2421.     result = WriteTemplateToNVRAM(templateindex);
  2422.     return result;
  2423. }
  2424. /*****************************************************************************
  2425.  * FUNCTION
  2426.  *  CalTemplateBase
  2427.  * DESCRIPTION
  2428.  *  Calculate template base
  2429.  * PARAMETERS
  2430.  *  void
  2431.  * RETURNS
  2432.  *  template base
  2433.  *****************************************************************************/
  2434. U16 CalTemplateBase(void)
  2435. {
  2436. #ifdef _MUTILANG_TEMPLATE_
  2437.     /*----------------------------------------------------------------*/
  2438.     /* Local Variables                                                */
  2439.     /*----------------------------------------------------------------*/
  2440.     U8 tempLangOffset = 0;
  2441.     U16 tempBase = 0;
  2442.     /*----------------------------------------------------------------*/
  2443.     /* Code Body                                                      */
  2444.     /*----------------------------------------------------------------*/
  2445.     if (IsTrChineseSet())
  2446.     {
  2447.         tempLangOffset = (U8) MSG_TEMPLATE_LANG_TRACHINESE;
  2448.     }
  2449.     else if (IsSmChineseSet())
  2450.     {
  2451.         tempLangOffset = (U8) MSG_TEMPLATE_LANG_SIMCHINESE;
  2452.     }
  2453.     else
  2454.     {
  2455.         tempLangOffset = (U8) MSG_TEMPLATE_LANG_ENGLISH;
  2456.     }
  2457.     tempBase = tempLangOffset * NUM_TEMPLATES;
  2458.     return tempBase;
  2459. #else /* _MUTILANG_TEMPLATE_ */ 
  2460.     return 0;
  2461. #endif /* _MUTILANG_TEMPLATE_ */