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

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