home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / bidi / arabic / teldir / teldir.c next >
C/C++ Source or Header  |  1999-05-11  |  59KB  |  1,562 lines

  1. /*************************************************************************
  2. *
  3. *  File Name   : Teldir.c
  4. *
  5. *  Description : This PM sample application demonstates the
  6. *                Arabic PM programming interface.
  7. *
  8. *  Concepts    : PM window creation
  9. *                Menu Creation
  10. *                Dialog box creation
  11. *                Initizalition and display of PM controls
  12. *                Error messages creation
  13. *
  14. *  API's       :
  15. *  -------------
  16. *  DosBeep                   WinDispatchMsg              WinQueryWindowText
  17. *  WinBeginPaint             WinEnableWindowUpdate       WinRegisterClass
  18. *  WinCreateMsgQueue         WinEndPaint                 WinSendMsg
  19. *  WinCreateStdWindow        WinFillRect                 WinSetFocus
  20. *  WinCreateWindow           WinGetMsg                   WinSetLangInfo
  21. *  WinDefDlgProc             WinInitialize               WinSetWindowPos
  22. *  WinDefWindowProc          WinLoadMenu                 WinSetWindowText
  23. *  WinDestroyMsgQueue        WinLoadString               WinTerminate
  24. *  WinDestroyWindow          WinMessageBox               WinUpper
  25. *  WinDismissDlg             WinPostMsg                  WinWindowFromID
  26. *
  27. *
  28. *  Copyright (C) 1992 IBM Corporation
  29. *
  30. *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  31. *      sample code created by IBM Corporation. This sample code is not
  32. *      part of any standard or IBM product and is provided to you solely
  33. *      for  the purpose of assisting you in the development of your
  34. *      applications.  The code is provided "AS IS", without
  35. *      warranty of any kind.  IBM shall not be liable for any damages
  36. *      arising out of your use of the sample code, even if they have been
  37. *      advised of the possibility of such damages.                                                    *
  38. *
  39. ************************************************************************/
  40. /******************************************************************************/
  41. /* A sample PM application to demonstrate the Arabic PM programming interface */
  42. /*                                                                            */
  43. /* The application is a telephone directory that the user can use to save the */
  44. /* person name and his telephone number. He can then search for a specific    */
  45. /* name, delete a name, add a name or update it.                              */
  46. /* The list of names are displayed in a listbox. All the action that can be   */
  47. /* performed on the list of names are shown as radio buttons. The user choose */
  48. /* the action he would like to take by clicking of the appropriate radio      */
  49. /* button, then to perform it, he has to click on the push button at the      */
  50. /* buttom of the panel.                                                       */
  51. /* The name and telephone number are entered through two entry fields.        */
  52. /*                                                                            */
  53. /* To fully understand this program, the reader is assumed to be familiar     */
  54. /* with the PM programming.                                                   */
  55. /******************************************************************************/
  56.  
  57. #define INCL_WIN
  58. #define INCL_WINWINDOWMGR
  59.  
  60. #include   <os2.h>
  61. #include   <pmbidi.h>
  62. #include   <layout.h>
  63.                                   /* Standard C library routine include files */
  64. #include   <string.h>
  65. #include   <io.h>
  66. #include   <stdio.h>
  67. #include   <stdlib.h>
  68.  
  69. #include   "teldir.h"                  /* Include the header file             */
  70.  
  71.                                        /* Global Declarations                 */
  72. #define       Eng_Offset  100         /* Offset of English strings in the */
  73.                                       /* string table in teldir.rc */
  74.  
  75. #define       MESSAGELEN  80          /* Length of string used in reading */
  76.                                       /* messages from teldir.rc */
  77.  
  78. HWND          hwndFrame,              /* handle to the main frame window */
  79.               hwndStatic1,            /* handle to the 1st static text */
  80.               hwndStatic2,            /* handle to the 2nd static text */
  81.               hwndStatic3,            /* handle to the 3rd static text */
  82.               hwndStatic4,            /* handle to the 4th static text */
  83.               hwndListBox,            /* handle to the list box */
  84.               hwndGroupBox,           /* handle to the group box */
  85.               hwndRadioButton1,       /* handles to the radio buttons 1..4 */
  86.               hwndRadioButton2,
  87.               hwndRadioButton3,
  88.               hwndRadioButton4,
  89.               hwndName,               /* handle to entry field for user */
  90.                                       /* entery of the name */
  91.               hwndTel,                /* handle to entry field for user */
  92.                                       /* entry of the telephone number */
  93.               hwndPushButton,         /* handle to push button */
  94.               hWndObject;             /* handle to object window */
  95. HAB           hab;                    /* anchor block for the process */
  96. HMQ           hmq;                    /* handle to the process' message queue */
  97. ULONG         flcreate1;              /* Creation flags */
  98. HWND          hwndc1;                 /* handle to window */
  99. int           Count,                  /* Counter */
  100.               Sel;                    /* The selected button's number */
  101. BOOL          Delete  = FALSE,        /* Flag to indicate that deletion is to */
  102.                                       /* take place */
  103.               Search  = FALSE;        /* Flag to indicate that searching is to */
  104.                                       /* take place */
  105. int           Position,               /* Indicates whether sorting is Ascending*/
  106.                                       /* or Descending */
  107.               Index,                  /* Index of the selected item */
  108.               ItemsLeft;              /* ItemsLeft in List Box */
  109. BOOL          Found;                  /* Indicates whether item was found in */
  110.                                       /* List Box or not */
  111. CHAR          NameStr[100],           /* Arrray to hold the name */
  112.               Temp_Name[100];         /* Arrray to hold the name queried from */
  113.                                       /* entry filed */
  114. CHAR          TelStr[10],             /* Array to hold the telephone number */
  115.               Temp_Tel[10];           /* Arrray to hold the Tel queried from */
  116.                                       /* entry filed */
  117. BOOL          Arb_Layer=TRUE;         /* Bool indicating which layer is active*/
  118.                                       /* TRUE means it is Arabic. FALSE means */
  119.                                       /* it is ENGLISH */
  120. CHAR          DisplayText[MESSAGELEN]; /* Array for holding the message's text */
  121.  
  122.  
  123.  
  124. TELLIST       TelDir[MAX_NAMES];     /* Array to hold names and tel numbers */
  125.  
  126.  
  127. BOOL   fHelpEnabled;             /* flag to determine if help is enabled */
  128. static CHAR szLibName[HELPLIBRARYNAMELEN];
  129. static CHAR szWindowTitle[HELPLIBRARYNAMELEN];
  130. static HWND hwndHelpInstance;
  131. /****************************************************************
  132.  *  Name:   main()
  133.  *
  134.  *  Description: Entry point of program.
  135.  *
  136.  *  Concepts: Obtains anchor block handle and creates message
  137.  *            queue.  Calls the initialization routine.
  138.  *            Creates the main frame window which creates the
  139.  *            main client window.  Polls the message queue
  140.  *            via Get/Dispatch Msg loop.  Upon exiting the
  141.  *            loop, exits.
  142.  *
  143.  *  API's   :  WinInitialize
  144.  *             DosBeep
  145.  *             WinCreateMsgQueue
  146.  *             WinTerminate
  147.  *             WinCreateStdWindow
  148.  *             WinSetWindowText
  149.  *             WinGetMsg
  150.  *             WinDispatchMsg
  151.  *
  152.  *  Parameters: NONE
  153.  *
  154.  *  Returns: VOID
  155.  *
  156. \****************************************************************/
  157. int  main (VOID)
  158. {
  159.     QMSG  qmsg;
  160.  
  161.     hab=WinInitialize(0L);                       /* initialization */
  162.                                                  /* create a message queue */
  163.     hmq=WinCreateMsgQueue(hab,0);
  164.                                            /* Create an object window to   */
  165.                                            /* be the owner of the message  */
  166.                                            /* boxes. They will inherit its */
  167.                                            /* bidi attributes */
  168.     hWndObject = WinCreateWindow(HWND_OBJECT,WC_BUTTON,0L,
  169.                                  BS_AUTORADIOBUTTON, 0,0,0,0,0L,HWND_TOP,
  170.                                  0L,NULL,NULL);
  171.  
  172.                                       /* Register the class for the client */
  173.     WinRegisterClass(hab,"Window1",WinProc1,CS_SIZEREDRAW,0);
  174.  
  175.     flcreate1= FCF_BORDER | FCF_MINBUTTON | FCF_SYSMENU | FCF_ICON |
  176.                FCF_TITLEBAR | FCF_MENU | FCF_TASKLIST | FCF_ACCELTABLE;
  177.  
  178.     hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
  179.                                    WS_VISIBLE,&flcreate1,"Window1","",0L,
  180.                                    0L,IDM_ORGMENU,(PHWND)&hwndc1);
  181.  
  182.  
  183.     /************************* The Arabic PM section *************************/
  184.                                           /* Load Arabic interface initially */
  185.     Arb_Interface();
  186.  
  187.                                             /* The system menu has the same */
  188.                                    /* attributes in both Arabic and English */
  189.                                               /* since it is not translated */
  190.  
  191.     WinSetLangInfo(WinWindowFromID(hwndFrame, FID_SYSMENU), LI_BD_WND_ATTR,
  192.                    BDA_NUMERALS_PASSTHRU | BDA_WND_ORIENT_LTR |
  193.                    BDA_TEXT_ORIENT_LTR,
  194.                    BDAM_NUMERALS | BDAM_WND_ORIENTATION |
  195.                    BDAM_TEXT_ORIENTATION,
  196.                    0L, 0L);
  197.  
  198.     /****************** End of Arabic PM APIs section ************************/
  199.  
  200.     LoadFile();                                  /* fill the list box from */
  201.                                                  /* a file on disk         */
  202.  
  203.                                                 /* Adjust the window position*/
  204.     WinSetWindowPos(hwndFrame,HWND_BOTTOM,7,80,498,385,
  205.                           SWP_MOVE | SWP_SIZE | SWP_ACTIVATE);
  206.  
  207.     WinSendMsg (hwndRadioButton1, BM_SETCHECK, MPFROMSHORT ((USHORT) 1), 0L);
  208.  
  209.     WinSetFocus (HWND_DESKTOP, hwndName);          /* Set focus on the name */
  210.                                                              /* entry field */
  211.  
  212.                                                 /* Set the check mark on the */
  213.                                                 /* Ascending menu item */
  214.     WinSendMsg ( WinWindowFromID (hwndFrame, FID_MENU),
  215.                  MM_SETITEMATTR,
  216.                  MPFROM2SHORT ((USHORT) IDM_ASCENDING, (BOOL) TRUE),
  217.                  MPFROM2SHORT ((USHORT) MIA_CHECKED, (BOOL) MIA_CHECKED));
  218.  
  219.                                                 /* Reset the check mark on   */
  220.                                                 /* the decending menu item */
  221.     WinSendMsg ( WinWindowFromID (hwndFrame, FID_MENU),
  222.                  MM_SETITEMATTR,
  223.                  MPFROM2SHORT ((USHORT) IDM_DESCENDING, (BOOL) TRUE),
  224.                  MPFROM2SHORT ((USHORT) MIA_CHECKED, (BOOL) FALSE));
  225.     while ( WinGetMsg(hab,(PQMSG)&qmsg, (HWND)NULL,0,0))
  226.            WinDispatchMsg( hab, (PQMSG)&qmsg );
  227.  
  228.     DestroyHelpInstance();
  229.     WinDestroyWindow(hwndFrame);
  230.     WinDestroyMsgQueue( hmq );
  231.     WinTerminate( hab );
  232.     return 0;
  233. }    /* End of main */
  234.  
  235. /****************************************************************
  236.  *  Name:   SortList
  237.  *
  238.  *  Description : deletes all items in the names listbox, then inserts
  239.  *                them again either in acending or descending order
  240.  *
  241.  *  Concepts : Sends an LM_DELETEALL message to the list box
  242.  *             to delete all its items.  It then sends an
  243.  *             LM_INSERTITEM message to the same list box to insert
  244.  *             the items according to the value of Position (ascending
  245.  *             or desecnding).
  246.  *
  247.  *  API's : WinSendMsg
  248.  *
  249.  * Parameters   : Position - indicateds whether sorting is
  250.  *                           ascending or descending.
  251.  *
  252.  *  Returns:  VOID
  253.  *
  254.  ****************************************************************/
  255. VOID SortList (int Position)
  256. {
  257.    int i;
  258.  
  259.    WinSendMsg (hwndListBox, LM_DELETEALL, NULL, NULL);
  260.                                             /* Delete all list box items */
  261.    i=0;
  262.    while (i<Count)
  263.    {
  264.       if(strcmp(TelDir[i].Name, "") != 0)
  265.       {
  266.          WinSendMsg (hwndListBox, LM_INSERTITEM,   /* Insert items one by one */
  267.                      MPFROMSHORT ((SHORT) Position),
  268.                      MPFROMP ((PSZ) TelDir[i++].Name));
  269.       }
  270.       else i++;
  271.    }/* endwhile */
  272. }    /* End of SortList */
  273.  
  274. /****************************************************************
  275.  *  Name:   WinProc1
  276.  *
  277.  *  Description : Window procedure for the main clent window.
  278.  *
  279.  *  Concepts : Processes the messages sent to the main client
  280.  *             window.  This routine processes the basic
  281.  *             messages all client windows should process.
  282.  *
  283.  *  API's : WinBeginPaint
  284.  *          WinCreateWindow
  285.  *          WinDefWindowProc
  286.  *          WinEndPaint
  287.  *          WinFillRect
  288.  *          WinMessageBox
  289.  *          WinPostMsg
  290.  *          WinSendMsg
  291.  *          WinSetWindowText
  292.  *          WinWindowFromID
  293.  *
  294.  * Parameters   : hwnd - Window handle to which message is addressed
  295.  *                msg - Message type
  296.  *                mp1 - First message parameter
  297.  *                mp2 - Second message parameter
  298.  *
  299.  *  Returns:  Return values are determined by each message
  300.  *
  301.  ****************************************************************/
  302.  
  303. MRESULT EXPENTRY WinProc1(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  304. {
  305.     HPS          hps;
  306.     RECTL        rc;
  307.     USHORT       Answer;
  308.     CHAR         Name[100];
  309.     CHAR         stext[75];
  310.     USHORT       i;
  311.     HWND         hwndFocus;
  312.     USHORT       ControlID;
  313.  
  314.    switch( msg )
  315.     {
  316.         case WM_CREATE:
  317.             Count = 0;
  318.             Sel = 1;
  319.                                                 /* Create child controls */
  320.  
  321.                                                  /* Text : List of names */
  322.             hwndStatic1=WinCreateWindow(hwnd,WC_STATIC, Message(ID_NAMES_A),
  323.                   SS_TEXT | DT_LEFT | WS_VISIBLE,206,305,270,
  324.                   16,hwnd,HWND_TOP, ID_NAMES_LIST,NULL,NULL);
  325.  
  326.                                                               /* Listbox */
  327.             hwndListBox=WinCreateWindow(hwnd,WC_LISTBOX,"",
  328.                    WS_CLIPCHILDREN | WS_PARENTCLIP |
  329.                    WS_SYNCPAINT | WS_VISIBLE | WS_TABSTOP ,
  330.                    206,160,270,140,hwnd, HWND_TOP, ID_LISTBOX,NULL,NULL);
  331.  
  332.                                         /* Radiobuttons for add, delete */
  333.                                                      /* modify and find */
  334.             hwndRadioButton1=WinCreateWindow(hwnd,WC_BUTTON,Message(ID_ADD_A),
  335.                    BS_AUTORADIOBUTTON | WS_PARENTCLIP |
  336.                    WS_TABSTOP | WS_SYNCPAINT | WS_VISIBLE,
  337.                    60,250,85,25,hwnd,HWND_TOP,
  338.                    ID_ADDNAME,NULL,NULL);
  339.  
  340.             hwndRadioButton2=WinCreateWindow(hwnd,WC_BUTTON,Message(ID_REMOVE_A),
  341.                    BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE,
  342.                    60,225,85,25,hwnd,HWND_TOP,
  343.                    ID_DELETE,NULL,NULL);
  344.  
  345.             hwndRadioButton3=WinCreateWindow(hwnd,WC_BUTTON,Message(ID_MODIFY_A),
  346.                    BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE,
  347.                    60,200,85,25,hwnd,HWND_TOP,
  348.                   ID_UPDATE,NULL,NULL);
  349.  
  350.             hwndRadioButton4=WinCreateWindow(hwnd,WC_BUTTON,Message(ID_FIND_A),
  351.                    BS_AUTORADIOBUTTON | WS_TABSTOP | WS_VISIBLE,
  352.                    60,175,85,25,hwnd,HWND_TOP,
  353.                    ID_SEARCH,NULL,NULL);
  354.  
  355.                                                       /* Groupbox : Choices */
  356.             hwndGroupBox=WinCreateWindow(hwnd,WC_STATIC,Message(ID_CHOICE_A),
  357.                   SS_GROUPBOX | WS_PARENTCLIP |
  358.                   WS_SYNCPAINT | WS_VISIBLE,39,160,120,140,hwnd,HWND_TOP,
  359.                   ID_CHOICES,NULL,NULL);
  360.  
  361.                                                          /* Name entryfield */
  362.             hwndName=WinCreateWindow(hwnd,WC_ENTRYFIELD,"",
  363.                    ES_MARGIN | ES_AUTOSCROLL | WS_TABSTOP |
  364.                    WS_VISIBLE,209,99,264,18,hwnd,HWND_TOP,
  365.                    ID_NAME,NULL,NULL);
  366.  
  367.                                                    /* Telephone entryfield */
  368.             hwndTel=WinCreateWindow(hwnd,WC_ENTRYFIELD,"",
  369.                    ES_MARGIN | ES_AUTOSCROLL | WS_PARENTCLIP | WS_TABSTOP |
  370.                    ES_RIGHT | WS_SYNCPAINT | WS_VISIBLE,43,98,120,19,
  371.                    hwnd,HWND_TOP, ID_TELEPHONE,NULL,NULL);
  372.  
  373.                                                    /* Text : Name */
  374.             hwndStatic3=WinCreateWindow(hwnd,WC_STATIC,Message(ID_ENTERNAME_A),
  375.                   SS_TEXT | DT_LEFT | WS_VISIBLE,
  376.                   209,128,264,20,hwnd,HWND_TOP,
  377.                   ID_INPUT_NAME,NULL,NULL);
  378.  
  379.                                                       /* Text : Telephone */
  380.             hwndStatic4=WinCreateWindow(hwnd,WC_STATIC,Message(ID_TELNUMBER_A),
  381.                   SS_TEXT | DT_LEFT | WS_VISIBLE,43,128,125,21,hwnd,HWND_TOP,
  382.                   ID_TELEPHONE_NUMBER,NULL,NULL);
  383.  
  384.                                                              /* OK button */
  385.             hwndPushButton=WinCreateWindow(hwnd,WC_BUTTON,Message(ID_DO_A),
  386.                    BS_PUSHBUTTON | WS_PARENTCLIP | WS_TABSTOP |
  387.                    WS_SYNCPAINT | WS_VISIBLE,38,21,439,29,hwnd,HWND_TOP,
  388.                   IDM_OK,NULL,NULL);
  389.             break;
  390.  
  391.         case  WM_COMMAND:
  392.             switch(SHORT1FROMMP( mp1 ))
  393.             {
  394.               case IDM_SAVE:     /* Save */
  395.                  SaveData();
  396.                  break;
  397.  
  398.               case IDM_QUIT:     /* Quit */
  399.                  Message(ID_EXIT_A);
  400.                  strcpy(stext,DisplayText);
  401.                  Answer = WinMessageBox(HWND_DESKTOP,
  402.                                         (HWND)hWndObject,
  403.                                         Message(ID_SAVEFILE_A),
  404.                                         stext,
  405.                                         0,
  406.                                         MB_YESNO);
  407.  
  408.                  if(Answer == MBID_YES)
  409.                     SaveData();
  410.                  WinPostMsg (hwnd, WM_QUIT, NULL, NULL);
  411.                  break;
  412.  
  413.               case IDM_ENG:
  414.                  if (Arb_Layer)
  415.                     ChangeLayer();
  416.                  break;
  417.  
  418.               case IDM_ARB:
  419.                  if (!Arb_Layer)
  420.                     ChangeLayer();
  421.                  break;
  422.  
  423.  
  424.               case IDM_HELPEXTENDED:
  425.                                          /* display the help contents */
  426.                   if (fHelpEnabled)
  427.                   {
  428.                     WinSendMsg(hwndHelpInstance, HM_HELP_CONTENTS, NULL, NULL);
  429.                   } /* endif */
  430.                  break;
  431.  
  432.  
  433.               case IDM_ABOUT:     /* About ... */
  434.                      MessageBox(ID_USES_A, ID_INFORMATION_A);
  435.                   break;
  436.  
  437.               case IDM_ASCENDING:                  /* Sort Ascending */
  438.                  WinSendMsg ( WinWindowFromID (hwndFrame, FID_MENU),
  439.                               MM_SETITEMATTR,
  440.                               MPFROM2SHORT ((USHORT) IDM_ASCENDING,
  441.                                             (BOOL) TRUE),
  442.                               MPFROM2SHORT ((USHORT) MIA_CHECKED,
  443.                                             (BOOL) MIA_CHECKED));
  444.                  WinSendMsg ( WinWindowFromID (hwndFrame, FID_MENU),
  445.                               MM_SETITEMATTR,
  446.                               MPFROM2SHORT ((USHORT) IDM_DESCENDING,
  447.                                             (BOOL) TRUE),
  448.                               MPFROM2SHORT ((USHORT) MIA_CHECKED,
  449.                                             (BOOL) FALSE));
  450.                  SortList (LIT_SORTASCENDING);
  451.                  break;
  452.  
  453.               case IDM_DESCENDING:              /* Sort Descending */
  454.                  WinSendMsg ( WinWindowFromID (hwndFrame, FID_MENU),
  455.                               MM_SETITEMATTR,
  456.                               MPFROM2SHORT ((USHORT) IDM_DESCENDING,
  457.                                             (BOOL) TRUE),
  458.                               MPFROM2SHORT ((USHORT) MIA_CHECKED,
  459.                                             (BOOL) MIA_CHECKED));
  460.                  WinSendMsg ( WinWindowFromID (hwndFrame, FID_MENU),
  461.                               MM_SETITEMATTR,
  462.                               MPFROM2SHORT ((USHORT) IDM_ASCENDING,
  463.                                             (BOOL) TRUE),
  464.                               MPFROM2SHORT ((USHORT) MIA_CHECKED,
  465.                                             (BOOL) FALSE));
  466.                  SortList (LIT_SORTDESCENDING);
  467.                  break;
  468.  
  469.               case IDM_OK:             /* Perform required action */
  470.                  Button_Handling();
  471.                  break;
  472.  
  473.              } /* endswitch */
  474.              break;
  475.  
  476.         case WM_CONTROL:
  477.              switch (SHORT2FROMMP(mp1))
  478.              {
  479.                               /* Display telephone number for selected name */
  480.                 case LN_SELECT:
  481.                    if(hwndListBox == (HWND)mp2)
  482.                    {
  483.                       Index = (SHORT) WinSendMsg (hwndListBox, LM_QUERYSELECTION,
  484.                                                MPFROMSHORT ((SHORT) LIT_FIRST),
  485.                                                   NULL);
  486.                       if (Index != LIT_NONE)
  487.                       {
  488.                          WinSendMsg (hwndListBox, LM_QUERYITEMTEXT,
  489.                                             MPFROM2SHORT((SHORT)Index,
  490.                                                          (SHORT)sizeof(Name)),
  491.                                             MPFROMP ((PSZ) Name));
  492.                          i=0;
  493.                          Found = FALSE;
  494.                          while ((i<Count) && (!Found))
  495.                          {
  496.                             if (strcmp(Name, TelDir[i].Name) == 0)
  497.                                 Found = TRUE;
  498.                             else i++;
  499.                          } /* endwhile */
  500.                          if (Found)
  501.                          {
  502.                             WinSetWindowText (hwndName,"");
  503.                             WinSetWindowText (hwndName,TelDir[i].Name);
  504.                             WinSetWindowText (hwndTel,"");
  505.                             WinSetWindowText (hwndTel,TelDir[i].Number);
  506.                          }
  507.                       }
  508.                    }
  509.                    break;
  510.              } /* endswitch */
  511.  
  512.              switch (SHORT1FROMMP(mp1))
  513.              {
  514.                 case ID_ADDNAME:          /*Add */
  515.                    Sel = 1;
  516.                    WinSetWindowText (hwndName,"");
  517.                    WinSetWindowText (hwndTel,"");
  518.                    break;
  519.  
  520.                 case ID_DELETE:     /*Delete*/
  521.                    Sel = 2;
  522.                    WinSetWindowText (hwndName,"");
  523.                    WinSetWindowText (hwndTel,"");
  524.                    break;
  525.  
  526.                 case ID_UPDATE:     /*Update*/
  527.                    Sel = 3 ;
  528.                    break;
  529.  
  530.                 case ID_SEARCH:     /*Search*/
  531.                    Sel = 4 ;
  532.                    WinSetWindowText (hwndName,"");
  533.                    WinSetWindowText (hwndTel,"");
  534.                    break;
  535.              }
  536.            break;
  537.  
  538.         case WM_PAINT:
  539.            hps = WinBeginPaint( hwnd, (HPS)NULL, (PRECTL)&rc );
  540.            WinFillRect( hps, (PRECTL)&rc, SYSCLR_ACTIVETITLETEXT);
  541.            WinEndPaint( hps );
  542.            break;
  543.  
  544.      case WM_HELP:
  545.         // Get the handle of the window that has focus
  546.         hwndFocus = WinQueryFocus(HWND_DESKTOP);
  547.  
  548.         ControlID =(USHORT)WinQueryWindowUShort(hwndFocus,QWS_ID);
  549.  
  550.         // For controls that have help, display the
  551.         // correct help panel
  552.         switch (ControlID)
  553.         {
  554.          case ID_LISTBOX:
  555.          case ID_ADDNAME:
  556.          case ID_DELETE:
  557.          case ID_UPDATE:
  558.          case ID_SEARCH:
  559.          case ID_NAME:
  560.          case ID_TELEPHONE:
  561.          case IDM_OK:
  562.               DisplayHelpPanel(ControlID);
  563.          break;
  564.  
  565.       } /* endswitch */
  566.      break;
  567.  
  568.         default:
  569.            return WinDefWindowProc(hwnd, msg, mp1,mp2);
  570.            break;
  571.     } /* endswirch msg */
  572.     return FALSE;
  573. }  /* End of WinProc1 */
  574.  
  575. /*********************************************************************
  576.  *  Name:   MessageBox
  577.  *
  578.  *  Description : Message Box procedure
  579.  *
  580.  *  Concepts : Displays the warning message box with the message
  581.  *             given in sMsg retrived from the message table
  582.  *             Called whever a message wishes to be displayed to
  583.  *             the user
  584.  *
  585.  *  API's : WinMessageBox
  586.  *
  587.  *  Parameters :  sMsg     - id of message to be retrieved from
  588.  *                            resource file
  589.  *                sTitle   - message box title
  590.  *
  591.  *  Returns: VOID
  592.  *
  593. \****************************************************************/
  594. VOID MessageBox(USHORT sMsg, USHORT sTitle)
  595. {
  596.    CHAR    TitleText[MESSAGELEN];
  597.  
  598.    Message(sTitle);
  599.    strcpy(TitleText, DisplayText);
  600.  
  601.    WinMessageBox( HWND_DESKTOP,
  602.                  (HWND)hWndObject,
  603.                  Message(sMsg),
  604.                  TitleText,
  605.                  0, MB_OK );
  606.  
  607. } /* End of MessageBox */
  608.  
  609. /*********************************************************************
  610.  *  Name:   Button_Handling
  611.  *
  612.  *  Description : Handlind the options of the radio buttons
  613.  *
  614.  *  Concepts : Handles the processing of the options Add, Delete,
  615.  *             Modify and Search.
  616.  *
  617.  *  API's : WinQueryWindowText
  618.  *          WinSendMsg
  619.  *          WinSetWindowText
  620.  *          WinWindowFromID
  621.  *
  622.  *  Parameters :  VOID
  623.  *
  624.  *  Returns: VOID
  625.  *
  626. \****************************************************************/
  627.  
  628. VOID Button_Handling(VOID)
  629. {  ULONG i;
  630.  
  631.    switch(Sel)
  632.   {
  633.      case 1:                           /* Add */
  634.         WinQueryWindowText (hwndName, sizeof(NameStr), NameStr);
  635.         WinQueryWindowText (hwndTel, sizeof(TelStr), TelStr);
  636.         if(strcmp(NameStr,"") != 0)
  637.         {
  638.            if(strcmp(TelStr,"") != 0)
  639.            {
  640.               strcpy(TelDir[Count].Name, NameStr);
  641.               strcpy(TelDir[Count].Number, TelStr);
  642.               Position = LIT_SORTDESCENDING;
  643.               if ( (SHORT) WinSendMsg (
  644.                           WinWindowFromID (hwndFrame, FID_MENU),
  645.                           MM_QUERYITEMATTR,
  646.                           MPFROM2SHORT ((USHORT) IDM_ASCENDING,
  647.                                         (BOOL) TRUE),
  648.                           MPFROMSHORT ((USHORT) MIA_CHECKED)) )
  649.                    Position = LIT_SORTASCENDING;
  650.               Index = (SHORT) WinSendMsg (hwndListBox, LM_INSERTITEM,
  651.                                           MPFROMSHORT ((SHORT) Position),
  652.                                           MPFROMP ((PSZ) TelDir[Count].Name));
  653.               Count++;
  654.               WinSendMsg (hwndListBox, LM_SELECTITEM,
  655.                           MPFROMSHORT ((SHORT) Index),
  656.                           MPFROMSHORT ((BOOL) TRUE));
  657.               break;
  658.            }
  659.            else
  660.               DosBeep (1000, 50);
  661.  
  662.               MessageBox(ID_ERRINADD_A, ID_ERROR_A);
  663.               break;
  664.         }
  665.         else
  666.            DosBeep (1000, 50);
  667.  
  668.            MessageBox(ID_ERRINADD_A, ID_ERROR_A);
  669.            WinSetWindowText (hwndName,"");
  670.            WinSetWindowText (hwndTel,"");
  671.         break;
  672.  
  673.      case 2:                           /* Delete */
  674.         WinQueryWindowText (hwndName, sizeof(NameStr), NameStr);
  675.         if(strcmp(NameStr,"") != 0)
  676.         {
  677.            Index = (SHORT) WinSendMsg (hwndListBox, LM_SEARCHSTRING,
  678.                              MPFROM2SHORT ((USHORT) LSS_CASESENSITIVE,
  679.                                            (SHORT) LIT_FIRST),
  680.                              MPFROMP ((PSZ) NameStr));
  681.            if (Index != LIT_NONE)
  682.               Delete = TRUE;
  683.            else
  684.            {
  685.               DosBeep (1000, 50);
  686.               MessageBox(ID_ERRINREMOVE_A, ID_ERROR_A);
  687.               break;
  688.            }
  689.         }
  690.         else              /* NameStr = "" */
  691.         {
  692.            Index = (SHORT) WinSendMsg (hwndListBox, LM_QUERYSELECTION,
  693.                              MPFROMSHORT ((SHORT) LIT_FIRST),
  694.                              NULL);
  695.            if (Index != LIT_NONE)
  696.            {
  697.               Delete = TRUE;
  698.               WinSendMsg (hwndListBox, LM_QUERYITEMTEXT,
  699.                                 MPFROM2SHORT((SHORT)Index,
  700.                                              (SHORT)sizeof(NameStr)),
  701.                                 MPFROMP ((PSZ) NameStr));
  702.            }
  703.            else
  704.            {
  705.               DosBeep (1000, 50);
  706.  
  707.               MessageBox(ID_ERRINREMOVE_A, ID_ERROR_A);
  708.               break;
  709.            }
  710.         }
  711.         if(Delete)
  712.         {
  713.            ItemsLeft = (SHORT) WinSendMsg (hwndListBox, LM_DELETEITEM,
  714.                                 MPFROMSHORT ((SHORT) Index),
  715.                                 NULL);
  716.            if(ItemsLeft != 0)
  717.            {
  718.               if(Index != 0)
  719.                 WinSendMsg (hwndListBox, LM_SELECTITEM,
  720.                             MPFROMSHORT ((SHORT) Index-1),
  721.                             MPFROMSHORT ((BOOL) TRUE));
  722.               else
  723.               {
  724.                  WinSendMsg (hwndListBox, LM_SELECTITEM,
  725.                              MPFROMSHORT ((SHORT) Index),
  726.                              MPFROMSHORT ((BOOL) TRUE));
  727.               }
  728.            }
  729.            if(ItemsLeft == 1)
  730.            {
  731.               Index = (SHORT) WinSendMsg (hwndListBox, LM_QUERYTOPINDEX,
  732.                                           NULL, NULL);
  733.  
  734.               WinSendMsg (hwndListBox, LM_SELECTITEM,
  735.                           MPFROMSHORT ((SHORT) Index),
  736.                           MPFROMSHORT ((BOOL) TRUE));
  737.            }
  738.            i=0;
  739.            Found = FALSE;
  740.            while ((i<Count) && (!Found))
  741.            {
  742.               if (strcmp(NameStr, TelDir[i].Name) == 0)
  743.                   Found = TRUE;
  744.               else i++;
  745.            } /* endwhile */
  746.            if (Found)
  747.            {
  748.                  strcpy(TelDir[i].Name, "");
  749.                  strcpy(TelDir[i].Number, "");
  750.            }
  751.            WinSetWindowText (hwndName,"");
  752.            WinSetWindowText (hwndTel,"");
  753.         }
  754.         break;
  755.  
  756.      case 3:                           /* Update */
  757.         Index = (SHORT) WinSendMsg (hwndListBox, LM_QUERYSELECTION,
  758.                                     MPFROMSHORT ((SHORT) LIT_FIRST),
  759.                                     NULL);
  760.  
  761.         if (Index != LIT_NONE)
  762.         {
  763.            WinSendMsg (hwndListBox, LM_QUERYITEMTEXT,
  764.                               MPFROM2SHORT((SHORT)Index,
  765.                                            (SHORT)sizeof(NameStr)),
  766.                               MPFROMP ((PSZ) NameStr));
  767.            i=0;
  768.            Found = FALSE;
  769.            while ((i<Count) && (!Found))
  770.            {
  771.               if (strcmp(NameStr, TelDir[i].Name) == 0)
  772.                   Found = TRUE;
  773.               else i++;
  774.            } /* endwhile */
  775.            if (Found)
  776.            {
  777.             WinQueryWindowText (hwndName, sizeof(Temp_Name), Temp_Name);
  778.             WinQueryWindowText (hwndTel, sizeof(Temp_Tel), Temp_Tel);
  779.             if(strcmp(Temp_Name, "") != 0)
  780.             {
  781.              if(strcmp(Temp_Tel, "") != 0)
  782.              {
  783.                if (strcmp(NameStr, Temp_Name) != 0)
  784.                {
  785.                  (SHORT) WinSendMsg (hwndListBox, LM_DELETEITEM,
  786.                                      MPFROMSHORT ((SHORT) Index),
  787.                                      NULL);
  788.                  strcpy(TelDir[i].Name, Temp_Name);
  789.                  strcpy(TelDir[i].Number, Temp_Tel);
  790.                  Position = LIT_SORTDESCENDING;
  791.                  if ( (SHORT) WinSendMsg (
  792.                              WinWindowFromID (hwndFrame, FID_MENU),
  793.                              MM_QUERYITEMATTR,
  794.                              MPFROM2SHORT ((USHORT) IDM_ASCENDING,
  795.                                            (BOOL) TRUE),
  796.                              MPFROMSHORT ((USHORT) MIA_CHECKED)) )
  797.                       Position = LIT_SORTASCENDING;
  798.                  Index = (SHORT) WinSendMsg (hwndListBox, LM_INSERTITEM,
  799.                                              MPFROMSHORT ((SHORT) Position),
  800.                                              MPFROMP ((PSZ) TelDir[i].Name));
  801.                  WinSendMsg (hwndListBox, LM_SELECTITEM,
  802.                              MPFROMSHORT ((SHORT) Index),
  803.                              MPFROMSHORT ((BOOL) TRUE));
  804.                }
  805.                else
  806.                  strcpy(TelDir[i].Number, Temp_Tel);
  807.                  break;
  808.              }
  809.              else
  810.                 DosBeep (1000, 50);
  811.                 MessageBox(ID_ERRINMODIFY_A, ID_ERROR_A);
  812.                 break;
  813.             }
  814.             else
  815.                 DosBeep (1000, 50);
  816.                 MessageBox(ID_ERRINMODIFY_A, ID_ERROR_A);
  817.  
  818.                break;
  819.            }/* end found */
  820.         }/* endif LIT_NONE */
  821.         else
  822.            DosBeep (1000, 50);
  823.            MessageBox(ID_ERRINMODIFY_A, ID_ERROR_A);
  824.         break;
  825.  
  826.      case 4:                           /* Search */
  827.         WinQueryWindowText (hwndName, sizeof(NameStr), NameStr);
  828.         if(strcmp(NameStr,"") != 0)
  829.         {
  830.            Index = (SHORT) WinSendMsg (hwndListBox, LM_SEARCHSTRING,
  831.                              MPFROM2SHORT ((USHORT) LSS_CASESENSITIVE,
  832.                                            (SHORT) LIT_FIRST),
  833.                              MPFROMP ((PSZ) NameStr));
  834.            if (Index != LIT_NONE) {
  835.               Search = TRUE;
  836.               WinSendMsg (hwndListBox, LM_SELECTITEM,
  837.                           MPFROMSHORT ((SHORT) Index),
  838.                           MPFROMSHORT ((BOOL) TRUE));
  839.  
  840.            }
  841.            else
  842.            {
  843.               DosBeep (1000, 50);
  844.               MessageBox(ID_ERRINSEARCH_A, ID_ERROR_A);
  845.               break;
  846.            }
  847.         }
  848.         else              /* NameStr = "" */
  849.         {
  850.            Index = (SHORT) WinSendMsg (hwndListBox, LM_QUERYSELECTION,
  851.                              MPFROMSHORT ((SHORT) LIT_FIRST),
  852.                              NULL);
  853.            if (Index != LIT_NONE)
  854.            {
  855.               Search = TRUE;
  856.               WinSendMsg (hwndListBox, LM_QUERYITEMTEXT,
  857.                                 MPFROM2SHORT((SHORT)Index,
  858.                                              (SHORT)sizeof(NameStr)),
  859.                                 MPFROMP ((PSZ) NameStr));
  860.            }
  861.            else
  862.            {
  863.               DosBeep (1000, 50);
  864.               MessageBox(ID_ERRINSEARCH_A, ID_ERROR_A);
  865.               break;
  866.            }
  867.         }
  868.         if(Search)
  869.         {
  870.            i=0;
  871.            Found = FALSE;
  872.            while ((i<Count) && (!Found))
  873.            {
  874.               if (strcmp(NameStr, TelDir[i].Name) == 0)
  875.                   Found = TRUE;
  876.               else i++;
  877.            } /* endwhile */
  878.            if (Found)
  879.            {
  880.               WinSetWindowText (hwndName,"");
  881.               WinSetWindowText (hwndName,TelDir[i].Name);
  882.               WinSetWindowText (hwndTel,"");
  883.               WinSetWindowText (hwndTel,TelDir[i].Number);
  884.            }
  885.         }
  886.         break;
  887.   } /* endswitch */
  888. }  /* End of Button_Handling */
  889.  
  890. /****************************************************************\
  891.  *  Name:   SaveData
  892.  *
  893.  *  Description : Saves the items to the data file teldir.dat
  894.  *
  895.  *  Concepts : Opens the data file with the write option and saves
  896.  *             the data from memory to the file.
  897.  *
  898.  *  API's : DosBeep
  899.  *
  900.  *  Parameters :  VOID
  901.  *
  902.  *  Returns: VOID
  903.  *
  904. \****************************************************************/
  905.  
  906. VOID SaveData(VOID)
  907. {
  908.   FILE      *Stream;
  909.   ULONG     i;
  910.  
  911.     if ((Stream = fopen ("teldir.dat","w")) != NULL)
  912.     {
  913.        i=0;
  914.        while (i<Count)
  915.        {
  916.              if(strcmp(TelDir[i].Name, "") != 0)
  917.              {
  918.                 fputs (TelDir[i].Name, Stream);
  919.                 fputc ('\n', Stream);
  920.                 fputs (TelDir[i++].Number, Stream);
  921.                 fputc ('\n', Stream);
  922.              }
  923.              else i++;
  924.        }/* endwhile */
  925.        fputc (0x1A,Stream);
  926.        fclose (Stream);
  927.     }/* endif */
  928.     else
  929.       DosBeep (5000L, 2L);
  930. } /* End of SaveData */
  931.  
  932. /****************************************************************\
  933.  *  Name:   LoadFile
  934.  *
  935.  *  Description : Loads the items from the data file teldir.dat
  936.  *
  937.  *  Concepts : Opens the data file with the read option and loads
  938.  *             the data from the file into memory in ascending order.
  939.  *
  940.  *  API's : DosBeep
  941.  *          WinSendMsg
  942.  *
  943.  *  Parameters :  VOID
  944.  *
  945.  *  Returns: VOID
  946.  *
  947. \****************************************************************/
  948. VOID LoadFile(VOID)
  949. {
  950.   int          Num;
  951.   FILE         *Stream;
  952.   BOOL         Elem_Found = FALSE;
  953.  
  954.     if ((Stream = fopen ("teldir.dat", "r")) != NULL)
  955.     {
  956.        Num=0;
  957.        while (!feof(Stream))
  958.        {
  959.             if(fgets(TelDir[Num].Name, sizeof(TelDir[Num].Name), Stream)
  960.                                                                      != NULL)
  961.             {
  962.                TelDir[Num].Name[strlen(TelDir[Num].Name)-1] = 0;
  963.                Elem_Found = TRUE;
  964.                fgets(TelDir[Num].Number, sizeof(TelDir[Num].Number), Stream);
  965.                TelDir[Num].Number[strlen(TelDir[Num].Number)-1] = 0;
  966.                Num++;
  967.             }
  968.        }/* endwhile */
  969.        fclose (Stream);
  970.        if(Elem_Found)
  971.        {
  972.           Count = 0;
  973.           while(Count < Num)
  974.           {
  975.              Position = LIT_SORTASCENDING;
  976.              Index = (SHORT) WinSendMsg (hwndListBox, LM_INSERTITEM,
  977.                                          MPFROMSHORT ((SHORT) Position),
  978.                                          MPFROMP ((PSZ) TelDir[Count].Name));
  979.              Count++;
  980.           }
  981.              WinSendMsg (hwndListBox, LM_SELECTITEM,
  982.                          MPFROMSHORT ((SHORT) 0),
  983.                          MPFROMSHORT ((BOOL) TRUE));
  984.        }
  985.     }/* endif */
  986.     else
  987.       DosBeep (5000L, 2L);
  988. }  /* End of LoadFile */
  989.  
  990.  
  991. /****************************************************************\
  992.  *  Name:   ChangeLayer
  993.  *
  994.  *  Description : Changes the current language
  995.  *
  996.  *  Concepts : Switches the interface language from Arabic to English
  997.  *             and vice versa
  998.  *
  999.  *  API's : None
  1000.  *
  1001.  *  Parameters :  VOID
  1002.  *
  1003.  *  Returns: VOID
  1004.  *
  1005. \****************************************************************/
  1006. VOID ChangeLayer(VOID)
  1007. {
  1008.    if (Arb_Layer){
  1009.       Arb_Layer = FALSE;
  1010.       Eng_Interface();
  1011.    }
  1012.    else{
  1013.       Arb_Layer = TRUE;
  1014.       Arb_Interface();
  1015.    }
  1016. }  /* End of ChangeLayer */
  1017.  
  1018. /****************************************************************\
  1019.  *  Name:   Arb_Interface
  1020.  *
  1021.  *  Description : Arabizes the interface
  1022.  *
  1023.  *  Concepts : Sets the controls' attributes and loads the strings
  1024.  *             to be displayed in each.
  1025.  *
  1026.  *  API's : WinDestroyWindow
  1027.  *          WinEnableWindowUpdate
  1028.  *          WinSetLangInfo
  1029.  *          WinLoadMenu
  1030.  *          WinSendMsg
  1031.  *          WinSetWindowText
  1032.  *          WinWindowFromID
  1033.  *
  1034.  *  Parameters :  VOID
  1035.  *
  1036.  *  Returns: VOID
  1037.  *
  1038. \****************************************************************/
  1039. VOID Arb_Interface(VOID)
  1040. {
  1041.  
  1042.   WinEnableWindowUpdate(hwndFrame, FALSE);
  1043.  
  1044.    // Destroy previous help instance if it exists
  1045.    DestroyHelpInstance();
  1046.    // Load help with current language setting
  1047.    InitHelp();
  1048.                                  /* Set frame and all its children to RTL */
  1049.   WinSetLangInfo(hwndFrame, LI_BD_WND_ATTR,
  1050.                  BDA_WND_ORIENT_RTL | BDA_TEXT_ORIENT_RTL |
  1051.                  BDA_TEXTTYPE_IMPLICIT | BDA_NUMERALS_NATIONAL |
  1052.                  BDA_SYM_SWAP_OFF | BDA_TEXT_DISPLAY_SHAPED,
  1053.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION |
  1054.                  BDAM_TEXTTYPE | BDAM_NUMERALS | BDAM_SYM_SWAP |
  1055.                  BDAM_TEXT_SHAPE,
  1056.                  LIF_CHILD_INHERIT | LIF_WND_REFRESH,
  1057.                  0L);
  1058.  
  1059.                                             /* Set object window to RTL */
  1060.   WinSetLangInfo(hWndObject, LI_BD_WND_ATTR,
  1061.                  BDA_WND_ORIENT_RTL | BDA_TEXT_ORIENT_RTL |
  1062.                  BDA_TEXTTYPE_IMPLICIT | BDA_NUMERALS_NATIONAL |
  1063.                  BDA_SYM_SWAP_OFF | BDA_TEXT_DISPLAY_SHAPED,
  1064.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION |
  1065.                  BDAM_TEXTTYPE | BDAM_NUMERALS | BDAM_SYM_SWAP |
  1066.                  BDAM_TEXT_SHAPE,
  1067.                  0L,
  1068.                  0L);
  1069.  
  1070.                                     /* Set telephone entryfield to LTR */
  1071.                                     /* as numbers are always LTR       */
  1072.   WinSetLangInfo(hwndTel, LI_BD_WND_ATTR,
  1073.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR,
  1074.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1075.                  0L, 0L);
  1076.  
  1077.   WinSetWindowText (hwndStatic1, Message(ID_NAMES_A));
  1078.  
  1079.   WinSetLangInfo(hwndStatic1, LI_BD_WND_ATTR,
  1080.                  BDA_WND_ORIENT_RTL | BDA_TEXT_ORIENT_RTL,
  1081.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1082.                  0L, 0L);
  1083.  
  1084.   WinSetWindowText (hwndStatic3, Message(ID_ENTERNAME_A));
  1085.  
  1086.   WinSetLangInfo(hwndStatic3, LI_BD_WND_ATTR,
  1087.                  BDA_WND_ORIENT_RTL | BDA_TEXT_ORIENT_LTR,
  1088.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1089.                  0L, 0L);
  1090.  
  1091.   WinSetWindowText (hwndStatic4, Message(ID_TELNUMBER_A));
  1092.  
  1093.   WinSetLangInfo(hwndStatic4, LI_BD_WND_ATTR,
  1094.                  BDA_WND_ORIENT_RTL | BDA_TEXT_ORIENT_RTL,
  1095.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1096.                  0L, 0L);
  1097.  
  1098.   WinSetWindowText (hwndGroupBox,"                            ");
  1099.  
  1100.   WinSetLangInfo(hwndGroupBox, LI_BD_WND_ATTR,
  1101.                  BDA_WND_ORIENT_RTL | BDA_TEXT_ORIENT_RTL,
  1102.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1103.                  0L, 0L);
  1104.  
  1105.   WinSetWindowText (hwndGroupBox, Message(ID_CHOICE_A));
  1106.  
  1107.   WinSetWindowText (hwndPushButton, Message(ID_DO_A));
  1108.  
  1109.   WinSetWindowText (hwndRadioButton1, Message(ID_ADD_A));
  1110.  
  1111.   WinSetWindowText (hwndRadioButton2, Message(ID_REMOVE_A));
  1112.  
  1113.   WinSetWindowText (hwndRadioButton3, Message(ID_MODIFY_A));
  1114.  
  1115.   WinSetWindowText (hwndRadioButton4, Message(ID_FIND_A));
  1116.  
  1117.   DisplayTitle (ID_TITLE_A);
  1118.  
  1119.   WinDestroyWindow (WinWindowFromID(hwndFrame, FID_MENU));
  1120.   WinLoadMenu (hwndFrame ,NULLHANDLE, IDM_ORGMENU);
  1121.   WinEnableWindowUpdate(hwndFrame, TRUE);
  1122.   WinSendMsg (hwndFrame, WM_UPDATEFRAME, 0L, 0L);
  1123.  
  1124. } /* End of Arb_Interface */
  1125.  
  1126. /****************************************************************\
  1127.  *  Name:   Eng_Interface
  1128.  *
  1129.  *  Description : Changes the interface to English
  1130.  *
  1131.  *  Concepts : Sets the controls' attributes and loads the strings
  1132.  *             to be displayed in each.
  1133.  *
  1134.  *  API's : WinDestroyWindow
  1135.  *          WinEnableWindowUpdate
  1136.  *          WinSetLangInfo
  1137.  *          WinLoadMenu
  1138.  *          WinSendMsg
  1139.  *          WinSetWindowText
  1140.  *          WinWindowFromID
  1141.  *
  1142.  *  Parameters :  VOID
  1143.  *
  1144.  *  Returns: VOID
  1145.  *
  1146. \****************************************************************/
  1147. VOID Eng_Interface(VOID)
  1148. {
  1149.  
  1150.   WinEnableWindowUpdate(hwndFrame, FALSE);
  1151.  
  1152.    // Destroy previous help instance if it exists
  1153.    DestroyHelpInstance();
  1154.    // Load help with current language setting
  1155.    InitHelp();
  1156.                                  /* Set frame and all its children to LTR */
  1157.   WinSetLangInfo(hwndFrame, LI_BD_WND_ATTR,
  1158.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR |
  1159.                  BDA_TEXTTYPE_IMPLICIT | BDA_NUMERALS_NOMINAL |
  1160.                  BDA_SYM_SWAP_OFF | BDA_TEXT_DISPLAY_SHAPED,
  1161.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION |
  1162.                  BDAM_TEXTTYPE | BDAM_NUMERALS | BDAM_SYM_SWAP |
  1163.                  BDAM_TEXT_SHAPE,
  1164.                  LIF_CHILD_INHERIT | LIF_WND_REFRESH,
  1165.                  0L);
  1166.  
  1167.                                             /* Set object window to LTR */
  1168.   WinSetLangInfo(hWndObject, LI_BD_WND_ATTR,
  1169.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR |
  1170.                  BDA_TEXTTYPE_IMPLICIT | BDA_NUMERALS_NOMINAL |
  1171.                  BDA_SYM_SWAP_OFF | BDA_TEXT_DISPLAY_SHAPED,
  1172.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION |
  1173.                  BDAM_TEXTTYPE | BDAM_NUMERALS | BDAM_SYM_SWAP |
  1174.                  BDAM_TEXT_SHAPE,
  1175.                  0L,
  1176.                  0L);
  1177.  
  1178.   WinSetWindowText (hwndStatic1, Message(ID_NAMES_A));
  1179.  
  1180.  
  1181.   WinSetLangInfo(hwndStatic1, LI_BD_WND_ATTR,
  1182.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR,
  1183.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1184.                  0L, 0L);
  1185.  
  1186.   WinSetWindowText (hwndStatic3, Message(ID_ENTERNAME_A));
  1187.  
  1188.  
  1189.   WinSetLangInfo(hwndStatic3, LI_BD_WND_ATTR,
  1190.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR,
  1191.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1192.                  0L, 0L);
  1193.  
  1194.   WinSetWindowText (hwndStatic4, Message(ID_TELNUMBER_A));
  1195.  
  1196.   WinSetLangInfo(hwndStatic4, LI_BD_WND_ATTR,
  1197.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR,
  1198.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1199.                  0L, 0L);
  1200.  
  1201.   WinSetLangInfo(hwndGroupBox, LI_BD_WND_ATTR,
  1202.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR,
  1203.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1204.                  0L, 0L);
  1205.  
  1206.   WinSetWindowText (hwndGroupBox, Message(ID_CHOICE_A));
  1207.  
  1208.   WinSetWindowText (hwndPushButton, Message(ID_DO_A));
  1209.  
  1210.   WinSetWindowText (hwndRadioButton1, Message(ID_ADD_A));
  1211.  
  1212.   WinSetWindowText (hwndRadioButton2, Message(ID_REMOVE_A));
  1213.  
  1214.   WinSetWindowText (hwndRadioButton3, Message(ID_MODIFY_A));
  1215.  
  1216.   WinSetWindowText (hwndRadioButton4, Message(ID_FIND_A));
  1217.  
  1218.   WinSetLangInfo(WinWindowFromID(hwndFrame, FID_TITLEBAR), LI_BD_WND_ATTR,
  1219.                  BDA_NUMERALS_PASSTHRU | BDA_TEXT_SAVE_SHAPED |
  1220.                  BDA_WND_ORIENT_LTR | BDA_TEXT_ORIENT_LTR,
  1221.                  BDAM_NUMERALS | BDAM_TEXT_SHAPE |
  1222.                  BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION,
  1223.                  0L, 0L);
  1224.  
  1225.                                                /* Set the title bar        */
  1226.                                                /* orientation LtR          */
  1227.   WinSetWindowText(hwndFrame, Message(ID_TITLE_A));     /* Set the title bar text    */
  1228.  
  1229.   WinDestroyWindow (WinWindowFromID(hwndFrame, FID_MENU));
  1230.   WinLoadMenu (hwndFrame ,NULLHANDLE, IDM_ENGLISHMENU);
  1231.   WinEnableWindowUpdate(hwndFrame, TRUE);
  1232.   WinSendMsg (hwndFrame, WM_UPDATEFRAME, 0L, 0L);
  1233.  
  1234. }  /* End of Eng_Interface */
  1235.  
  1236. /*********************************************************************
  1237.  *  Name:   Message
  1238.  *
  1239.  *  Description : Message retrieval procedure
  1240.  *
  1241.  *  Concepts : Returns the wanted string in the global variable
  1242.  *             DisplayText. It checks on the language layer to know
  1243.  *             whether to retrieve the Arabic or English string.
  1244.  *
  1245.  *  API's : DosBeep
  1246.  *          WinLoadString
  1247.  *          WinMessageBox
  1248.  *
  1249.  *  Parameters : iMsg  -  id of string to be retrieved from
  1250.  *                        string table
  1251.  *
  1252.  *  Returns: PCHAR
  1253.  *
  1254. \****************************************************************/
  1255.  
  1256. PCHAR Message(USHORT iMsg)
  1257.  
  1258. {
  1259.  if (!WinLoadString(hab, (HMODULE)0, (SHORT)(Arb_Layer?iMsg:iMsg+ Eng_Offset),
  1260.                         MESSAGELEN, (PSZ)DisplayText))
  1261.       {
  1262.          DosBeep (1000, 50);
  1263.          WinMessageBox(hwndFrame, hwndFrame, "Failed to load string.", "Error", 0, MB_OK | MB_ERROR);
  1264.          return (NULL);
  1265.       }
  1266.    return (DisplayText);
  1267. }  /* End of Message */
  1268.  
  1269.  
  1270. /*********************************************************************
  1271.  *  Name:   DisplayTitle
  1272.  *
  1273.  *  Description : Displays the title bar
  1274.  *
  1275.  *  Concepts : The title bar requires special handling to make
  1276.  *             the string in the task list appear readable.  When
  1277.  *             the DeskTop attributes are VISUAL LTR, the text which
  1278.  *             was saved in typing order would appear reversed in the
  1279.  *             task list.  Therefore, the title bar text which is IMPLICIT
  1280.  *             is going to be converted according to the DeskTop attributes
  1281.  *             to make it like that in the task list.
  1282.  *
  1283.  *  API's : WinSetLangInfo
  1284.  *          WinSetWindowText
  1285.  *          WinUpper
  1286.  *          WinWindowFromID
  1287.  *
  1288.  *  Parameters : iMsg   -   id of string to be retrieved from
  1289.  *                          string table
  1290.  *
  1291.  *  Returns: VOID
  1292.  *
  1293. \****************************************************************/
  1294.  
  1295. VOID DisplayTitle(USHORT iMsg)
  1296. {
  1297.  CHAR         *BidiAttrStr;
  1298.  ULONG        DeskTopAtts;
  1299.  
  1300.  
  1301.   Message(iMsg);            /* DisplayText will hold the title text */
  1302.  
  1303.   DeskTopAtts = WinQueryLangInfo(HWND_DESKTOP, LI_BD_WND_ATTR, BDAM_ALL, 0L);
  1304.  
  1305.   ConvertBidiString(DisplayText, DisplayText,
  1306.                     BDA_TEXT_ORIENT_LTR | BDA_TEXTTYPE_IMPLICIT,
  1307.                     QUERY_BD_VALUE (DeskTopAtts, BDAM_TEXT_ORIENTATION) |
  1308.                     QUERY_BD_VALUE (DeskTopAtts, BDAM_TEXTTYPE),
  1309.                     BDAM_TEXT_ORIENTATION | BDAM_TEXTTYPE);
  1310.  
  1311.              /* To conform with the text in the task list, *
  1312.               * the desktop TEXT_ORIENT and TEXTTYPE are   *
  1313.               * going to be used in the title bar          */
  1314.  
  1315.   WinSetLangInfo(WinWindowFromID(hwndFrame, FID_TITLEBAR), LI_BD_WND_ATTR,
  1316.               BDA_NUMERALS_PASSTHRU | BDA_TEXT_DISPLAY_SHAPED |
  1317.               BDA_WND_ORIENT_RTL |
  1318.               QUERY_BD_VALUE (DeskTopAtts, BDAM_TEXT_ORIENTATION) |
  1319.               QUERY_BD_VALUE (DeskTopAtts, BDAM_TEXTTYPE),
  1320.               BDAM_NUMERALS | BDAM_TEXT_SHAPE |
  1321.               BDAM_WND_ORIENTATION | BDAM_TEXT_ORIENTATION | BDAM_TEXTTYPE,
  1322.               0L, 0L);
  1323.  
  1324.  
  1325.                                                /* Set the title bar        */
  1326.                                                /* orientation RtL          */
  1327.  
  1328.   WinSetWindowText(hwndFrame, DisplayText);        /* Set the title bar text   */
  1329.  
  1330. }  /* End of DisplayTitle */
  1331.  
  1332.  
  1333. /**********************************************************************
  1334.  *
  1335.  *  Name:   ConvertBidiString
  1336.  *
  1337.  *  Description : Converts text according to source and
  1338.  *                target attributes
  1339.  *
  1340.  *  Concepts : The text in SourceStr is transformed using layout
  1341.  *             functions and output to TargetStr.  ConvertBidiString is
  1342.  *             implemented to be general.  It takes source and target
  1343.  *             strings and attributes plus the mask and converts the
  1344.  *             text accordindly.
  1345.  *
  1346.  *  API's : LayoutCreateObject
  1347.  *          LayoutDestroyObject
  1348.  *          LayoutSetValues
  1349.  *          LayoutTransformText
  1350.  *          WinMessageBox
  1351.  *
  1352.  *  Parameters : SourceStr  - the source string
  1353.  *               TargetStr  - the target string where the converted text is put
  1354.  *               SrcBDAtts  - Bidi attributes of the source string
  1355.  *               TrgBDAtts  - Bidi attributes of the target string
  1356.  *               BDMask     - Bidi attributes mask
  1357.  *
  1358.  *  Returns: VOID
  1359.  *
  1360. \****************************************************************/
  1361.  
  1362. VOID ConvertBidiString (PUCHAR SourceStr, PUCHAR TargetStr,
  1363.                         ULONG SrcBDAtts, ULONG TrgBDAtts, ULONG BDMask)
  1364. {
  1365.   LAYOUT_OBJECT   hLayout;
  1366.   LAYOUT_VALUES   Layout[4];
  1367.   APIRET          RC=0;
  1368.   ULONG           index,
  1369.                   ulLength;
  1370.  
  1371.  
  1372.   RC = LayoutCreateObject (Locale_Arabic,&hLayout);
  1373.  
  1374.   if (RC)
  1375.   {
  1376.    WinMessageBox(HWND_DESKTOP, hwndFrame, "Failed to create layout object",
  1377.                 "Bidi text transform - Error",
  1378.                  0, MB_ERROR | MB_OK);
  1379.      return;
  1380.   }
  1381.  
  1382.   ulLength=strlen(SourceStr);
  1383.  
  1384.  
  1385.                                            /* Initialize layout array */
  1386.   Layout[0].name  =  InOutTextDescrMask;
  1387.   Layout[0].value =  &BDMask;
  1388.  
  1389.   Layout[1].name  =  InOnlyTextDescr;
  1390.   Layout[1].value =  &SrcBDAtts;
  1391.  
  1392.   Layout[2].name  =  OutOnlyTextDescr;
  1393.   Layout[2].value =  &TrgBDAtts;
  1394.  
  1395.   Layout[3].name = 0;
  1396.                                                     /* Set layout values */
  1397.   RC = LayoutSetValues (hLayout,Layout,&index);
  1398.   if (RC)
  1399.   {
  1400.    WinMessageBox(HWND_DESKTOP, hwndFrame, "Failed to set layout values",
  1401.                 "Bidi text transform - Error",
  1402.                  0, MB_ERROR | MB_OK);
  1403.      return;
  1404.   }
  1405.                                         /* Do actual text transformation */
  1406.   RC = LayoutTransformText (hLayout,
  1407.                             SourceStr,
  1408.                             &ulLength,
  1409.                             TargetStr,
  1410.                             &ulLength, NULL, NULL, NULL);
  1411.   if (RC)
  1412.   {
  1413.    WinMessageBox(HWND_DESKTOP, hwndFrame, "LayoutTransformText failed",
  1414.                 "Bidi text transform - Error",
  1415.                  0, MB_ERROR | MB_OK);
  1416.    return;
  1417.   }
  1418.  
  1419.   LayoutDestroyObject(hLayout);
  1420.  
  1421.   return;
  1422.  
  1423. }   /* End of ConvertBidiString */
  1424.  
  1425. /****************************************************************\
  1426.  *  Routine for initializing the help manager
  1427.  *--------------------------------------------------------------
  1428.  *
  1429.  *  Name:    InitHelp(VOID)
  1430.  *
  1431.  *  Purpose: Initializes the IPF help facility
  1432.  *
  1433.  *  Usage:   Called every time the interface language is changed
  1434.  *
  1435.  *  Method:  Initializes the HELPINIT structure and creates the help
  1436.  *           instance. If successful, the help instance is associated
  1437.  *           with the main window
  1438.  *
  1439.  *  Returns: VOID
  1440.  *
  1441. \****************************************************************/
  1442. VOID InitHelp(VOID)
  1443. {
  1444.    HELPINIT hini;
  1445.    ULONG    NlsOffset = Arb_Layer ? 0 : Eng_Offset ;
  1446.  
  1447.    /* If we return because of an error, Help will be disabled */
  1448.    fHelpEnabled = FALSE;
  1449.                              /* Initialize help init structure */
  1450.    hini.cb = sizeof(HELPINIT);
  1451.    hini.ulReturnCode = 0;
  1452.                              /* If tutorial added, add name here */
  1453.    hini.pszTutorialName = (PSZ)NULL;
  1454.  
  1455.    hini.phtHelpTable = (PHELPTABLE)MAKELONG(TELDIR_HELP_TABLE,0xFFFF);
  1456.    hini.hmodHelpTableModule = 0;
  1457.    hini.hmodAccelActionBarModule = 0;
  1458.    hini.idAccelTable = 0;
  1459.    hini.idActionBar = 0;
  1460.  
  1461.    if(!WinLoadString(hab,
  1462.                      0,
  1463.                      ID_HELPWINDOWTITLE_A+NlsOffset,
  1464.                      HELPLIBRARYNAMELEN,
  1465.                      (PSZ)szWindowTitle))
  1466.    {
  1467.        MessageBox(ID_ERROR_A, ID_CANNOTLOADSTRING_A);
  1468.        return;
  1469.    }
  1470.    hini.pszHelpWindowTitle = (PSZ)szWindowTitle;
  1471.  
  1472.    hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  1473.  
  1474.    if(!WinLoadString(hab,
  1475.                      0,
  1476.                      ID_HELPLIBRARYNAME_A+NlsOffset,
  1477.                      HELPLIBRARYNAMELEN,
  1478.                      (PSZ)szLibName))
  1479.    {
  1480.        MessageBox(ID_ERROR_A, ID_CANNOTLOADSTRING_A);
  1481.        return;
  1482.    }
  1483.  
  1484.    hini.pszHelpLibraryName = (PSZ)szLibName;
  1485.                                        /* Creating help instance */
  1486.    hwndHelpInstance = WinCreateHelpInstance(hab, &hini);
  1487.  
  1488.    if(hwndHelpInstance == 0L || hini.ulReturnCode)
  1489.    {
  1490.        MessageBox(ID_ERROR_A, ID_HELPLOADERROR_A);
  1491.        return;
  1492.    }
  1493.                              /* Associate help instance with main frame */
  1494.    if(!WinAssociateHelpInstance(hwndHelpInstance, hwndFrame))
  1495.    {
  1496.        MessageBox(ID_ERROR_A, ID_HELPLOADERROR_A);
  1497.        return;
  1498.    }
  1499.  
  1500.    /* Help manager is successfully initialized so set flag to TRUE */
  1501.    fHelpEnabled = TRUE;
  1502.    return;
  1503.  
  1504. }   /* InitHelp() */
  1505.  
  1506. /****************************************************************\
  1507.  *  Displays the help panel indicated
  1508.  *--------------------------------------------------------------
  1509.  *
  1510.  *  Name:    DisplayHelpPanel(LONG idPanel)
  1511.  *
  1512.  *  Purpose: Displays the help panel whose id is given
  1513.  *
  1514.  *  Usage:   Called whenever a help panel is desired to be displayed,
  1515.  *           from the WM_HELP processing.
  1516.  *
  1517.  *  Method:  Sends HM_DISPLAY_HELP message to the help instance
  1518.  *
  1519.  *  Returns: VOID
  1520.  *
  1521. \****************************************************************/
  1522. VOID DisplayHelpPanel(LONG idPanel)
  1523.                         /* ID of the help panel to be displayed */
  1524. {
  1525.     if(fHelpEnabled)
  1526.         if((LONG)WinSendMsg(hwndHelpInstance,
  1527.                       HM_DISPLAY_HELP,
  1528.                       MPFROMLONG(MAKELONG(idPanel, NULL)),
  1529.                       MPFROMSHORT(HM_RESOURCEID)))
  1530.  
  1531.             MessageBox(ID_ERROR_A,
  1532.                        ID_HELPDISPLAYERROR_A);
  1533.     return;
  1534.  
  1535. }   /* DisplayHelpPanel() */
  1536.  
  1537. /****************************************************************\
  1538.  *  Destroys the help instance
  1539.  *--------------------------------------------------------------
  1540.  *
  1541.  *  Name:    DestroyHelpInstance(VOID)
  1542.  *
  1543.  *  Purpose: Destroys the help instance for the application
  1544.  *
  1545.  *  Usage:   Called when switching interface language and
  1546.  *           after exit from message loop
  1547.  *
  1548.  *  Method:  Calls WinDestroyHelpInstance() to destroy the help instance
  1549.  *
  1550.  *  Returns: VOID
  1551.  *
  1552. \****************************************************************/
  1553. VOID DestroyHelpInstance(VOID)
  1554. {
  1555.     if(hwndHelpInstance != 0L)
  1556.     {
  1557.         WinDestroyHelpInstance(hwndHelpInstance);
  1558.     }
  1559.     return;
  1560.  
  1561. }   /* DestroyHelpInstance() */
  1562.