home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / gik2 / ewyio2eu.d2x / EWYNAAH.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-04  |  16.7 KB  |  368 lines

  1. /*
  2. GIK/2 1.0.1 EWYNAAH.C 5621-432 (C) COPYRIGHT IBM CORP 1993.  ALL RIGHTS RESERVED.  LICENSED MATERIALS - PROPERTY OF IBM.
  3. */
  4. /**********************************************************************/
  5. /*                                                                    */
  6. /*                     MODULE PROLOGUE                                */
  7. /*                                                                    */
  8. /* COMPONENT NAME:   AIRPLANE EXAMPLE                                 */
  9. /*                                                                    */
  10. /* MODULE NAME:      EWYNAAH.C                                        */
  11. /*                                                                    */
  12. /* DESCRIPTIVE NAME: Graphics Interface Kit/2 - Airplane Example      */
  13. /*                                                                    */
  14. /* PURPOSE:          Customizing code, action handler functions       */
  15. /*                                                                    */
  16. /* COPYRIGHT:        (C) 1993 IBM Corporation                         */
  17. /*                                                                    */
  18. /* DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        */
  19. /* sample code created by IBM Corporation. This sample code is not    */
  20. /* part of any standard or IBM product and is provided to you solely  */
  21. /* for the purpose of assisting you in the development of your        */
  22. /* applications.  The code is provided "AS IS", without               */
  23. /* warranty of any kind.  IBM shall not be liable for any damages     */
  24. /* arising out of your use of the sample code, even if they have been */
  25. /* advised of the possibility of such damages.                        */
  26. /*                                                                    */
  27. /**********************************************************************/
  28. /*--------------------------------------------------------------------*/
  29. /* INCLUDE RELATED DEFINES                                            */
  30. /*--------------------------------------------------------------------*/
  31.  
  32. #define  INCL_DOS                      /* OS/2 definitions            */
  33. #define  INCL_PM                       /* PM definitions              */
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /* HEADER FILES                                                       */
  37. /*--------------------------------------------------------------------*/
  38.  
  39. #include <os2.h>                       /* OS/2 header file            */
  40. #include <ewyga.h>                     /* GIK/2 header file           */
  41. #include "EWYNADF.H"                   /* Generated header file       */
  42. #include "ewyna.h"                     /* Header file                 */
  43. #include "ewynarc.h"                   /* RC-file header              */
  44. #include <math.h>                      /* C library                   */
  45. #include <errno.h>                     /* C library                   */
  46. #include <string.h>                    /* C library                   */
  47. #include <stdlib.h>                    /* C library                   */
  48.  
  49. /*--------------------------------------------------------------------*/
  50. /* LOCAL FUNCTION PROTOTYPES                                          */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. SHORT GSENTRY ActionHandler(DHND,USHORT,MPARAM,MPARAM);
  54.  
  55. /**********************************************************************/
  56. /* ActionHandler                                                      */
  57. /*                                                                    */
  58. /* Parameters:                                                        */
  59. /*    DHND      dhnd      (I):    Diagram handle.                     */
  60. /*    USHORT    menu_id   (I):    Action selected by user.            */
  61. /*    MPARAM    mparam1   (I):    PM-data.                            */
  62. /*    MPARAM    mparam2   (I):    PM-data.                            */
  63. /*                                                                    */
  64. /* Returns:                                                           */
  65. /*    GS_OK                                                           */
  66. /*                                                                    */
  67. /* Description:                                                       */
  68. /*    The function handles all non-generic actions.                   */
  69. /**********************************************************************/
  70.  
  71. SHORT GSENTRY ActionHandler(DHND dhnd,USHORT menu_id,MPARAM mparam1,
  72.                              MPARAM mparam2)
  73. {
  74.   PFLIGHT          pFlight = NULL;     // diagram object data pointer
  75.   PFLIGHT_ENV      pEnv = NULL;        // diagram environment data ptr
  76.   PASS_ID          passId;             // passenger id
  77.   SHND             shnd;               // symbol handle
  78.   HWND             hwndClient;         // client window handle
  79.   SHORT            index;              // array index
  80.   BOOL             found;              // found flag
  81.   SHORT            symType;            // symbol type
  82.   HMODULE          hmodCustomCode;     // custom code module
  83.  
  84.   switch (menu_id)
  85.   {
  86.  
  87.     /*----------------------------------------------------------------*/
  88.     /* Open new diagram.                                              */
  89.     /*----------------------------------------------------------------*/
  90.  
  91.     case  MID_FLIGHT_OPEN :            /* ~Open...                    */
  92.  
  93.       /*--------------------------------------------------------------*/
  94.       /* Trigger generic open action GS_OPEN.                         */
  95.       /*--------------------------------------------------------------*/
  96.  
  97.       GsTriggerGenericAction(dhnd, GE_OPEN, NULL);
  98.  
  99.       /*--------------------------------------------------------------*/
  100.       /* Init airplane symbol handle from diagram data.               */
  101.       /*--------------------------------------------------------------*/
  102.  
  103.       GsGetDiagPointerN(dhnd, 0, (VOID **)&pEnv);
  104.       GsCollectSym(dhnd, GS_NODE, GS_ANY_SYM, GS_UPPER_FIRST);
  105.       while (GsGetCollectedSym(dhnd, &shnd) != GSE_COLLECTION_EMPTY)
  106.       {
  107.         GsGetSymType(dhnd, shnd, &symType);
  108.         if (symType == SYM_AIRPLANE)
  109.         {
  110.           pEnv->shndPlane = shnd;
  111.           GsEndSymCollection(dhnd);
  112.           break;
  113.         }
  114.       }
  115.       break;
  116.  
  117.       /*--------------------------------------------------------------*/
  118.       /* Select all passengers matching the user specified criteria.  */
  119.       /* Note: The last name has to be fully specified. The first name*/
  120.       /* has to be fully specified or left blank for any.             */
  121.       /*--------------------------------------------------------------*/
  122.  
  123.     case  MID_FIND :                   /* ~Find                       */
  124.  
  125.       /*--------------------------------------------------------------*/
  126.       /* Retrive diagram object and environment data pointers.        */
  127.       /*--------------------------------------------------------------*/
  128.  
  129.       GsGetDiagObjectData(dhnd, (PVOID *)&pFlight);
  130.       GsGetDiagPointerN(dhnd, 0, (VOID **)&pEnv);
  131.  
  132.       /*--------------------------------------------------------------*/
  133.       /* Initialize data for dialog                                   */
  134.       /*--------------------------------------------------------------*/
  135.  
  136.       strcpy(passId.lastName, "");
  137.       strcpy(passId.firstName, "");
  138.       GsGetHwnd(dhnd, GS_WIN_MAIN, 0, FID_CLIENT, &hwndClient);
  139.       GsGetCcModuleHandle(dhnd, &hmodCustomCode);
  140.       memcpy(&pEnv->passId, &passId, sizeof(PASSENGER));
  141.  
  142.       /*--------------------------------------------------------------*/
  143.       /* If passenger name has been entered                           */
  144.       /*--------------------------------------------------------------*/
  145.  
  146.       if (WinDlgBox(HWND_DESKTOP,      //
  147.          hwndClient,                   //
  148.          (PFNWP)ViewDlgProc,           //
  149.          hmodCustomCode,               //
  150.          D_ID_FIND,                    //
  151.          (MPARAM)&dhnd) == TRUE)
  152.       {
  153.  
  154.         /*------------------------------------------------------------*/
  155.         /* Retrieve dialog data.                                      */
  156.         /*------------------------------------------------------------*/
  157.  
  158.         memcpy(&passId, &(pEnv->passId), sizeof(PASSENGER));
  159.  
  160.         /*------------------------------------------------------------*/
  161.         /* Deselect all passengers.                                   */
  162.         /*------------------------------------------------------------*/
  163.  
  164.         GsPutAllSymSelection(dhnd, GS_OFF);
  165.  
  166.         /*------------------------------------------------------------*/
  167.         /* Do for each seat on the plane: if the seat is reserved and */
  168.         /* passenger matches the specified criteria, select it.       */
  169.         /*------------------------------------------------------------*/
  170.  
  171.         for (index = 0, found = FALSE; index < MAX_NO_SEATS; index++)
  172.         {
  173.           if ((pFlight->seat[index].status == RESERVED) &&  //
  174.              (strcmp(passId.lastName,  //
  175.              pFlight->seat[index].passId.lastName) == 0) &&  //
  176.              ((strcmp(passId.firstName,  //
  177.              pFlight->seat[index].passId.firstName) == 0) ||  //
  178.              BlanksEmpty(passId.firstName)))
  179.           {
  180.             GsPutSymSelection(dhnd,    //
  181.                pFlight->seat[index].shndPass,  //
  182.                GS_ON);
  183.             found = TRUE;
  184.           }
  185.         }
  186.  
  187.         /*------------------------------------------------------------*/
  188.         /* Display the message if no passenger has been found.        */
  189.         /*------------------------------------------------------------*/
  190.  
  191.         if (!found)
  192.         {
  193.           GsMessageBox(dhnd,
  194.              "There are no passengers with a given name.",  //
  195.              PRG_TITLE, MB_OK, NULL);
  196.         }
  197.       }
  198.       break;
  199.  
  200.       /*--------------------------------------------------------------*/
  201.       /* For each selected passenger, invoke passenger details dialog.*/
  202.       /*--------------------------------------------------------------*/
  203.  
  204.     case  MID_PASSENGER_DETAILS :      /* ~Details                    */
  205.       GsCollectSym(dhnd, GS_NODE, GS_SYM_SELECTED, GS_UPPER_FIRST);
  206.       while (GsGetCollectedSym(dhnd, &shnd) != GSE_COLLECTION_EMPTY)
  207.         PassDetails(dhnd, shnd);
  208.       GsPutAllSymSelection(dhnd, GS_OFF);
  209.       break;
  210.  
  211.       /*--------------------------------------------------------------*/
  212.       /* Set status of selected passengers to confirmed.              */
  213.       /*--------------------------------------------------------------*/
  214.  
  215.     case  MID_PASSENGER_CONFIRMED :    /* ~Confirmed                  */
  216.       SetSelPassStatusForm(dhnd, PASS_OK);
  217.       break;
  218.  
  219.       /*--------------------------------------------------------------*/
  220.       /* Set status of selected passengers to reserved (not           */
  221.       /* confirmed).                                                  */
  222.       /*--------------------------------------------------------------*/
  223.  
  224.     case  MID_PASSENGER_NCONFIRMED :   /* ~Not Confirmed              */
  225.       SetSelPassStatusForm(dhnd, PASS_RESERVED);
  226.       break;
  227.   }
  228.   return  GS_OK;
  229. }
  230.  
  231. /**********************************************************************/
  232. /* ViewDlgProc                                                        */
  233. /*                                                                    */
  234. /* Parameters:                                                        */
  235. /*    HWND   hDlg                                                     */
  236. /*    USHORT msg                                                      */
  237. /*    MPARM  mp1                                                      */
  238. /*    MPARM  mp2                                                      */
  239. /*                                                                    */
  240. /* Returns for WM_COMMAND message:                                    */
  241. /*    TRUE    Passenger name has been entered.                        */
  242. /*    FALSE   Dialog has been canceled.                               */
  243. /*                                                                    */
  244. /* Description:                                                       */
  245. /*    Passenger name entry dialog.                                    */
  246. /**********************************************************************/
  247.  
  248. MRESULT GSENTRY ViewDlgProc(HWND hDlg, //
  249.                              USHORT msg, //
  250.                              MPARAM mp1, //
  251.                              MPARAM mp2)
  252. {
  253.   HWND             hwnd;               // window handle
  254.   DHND             *pdhnd;             // diagram handle pointer
  255.   PFLIGHT_ENV      pEnv = NULL;        // environment data pointer
  256.  
  257.   switch (msg)
  258.   {
  259.  
  260.     /*----------------------------------------------------------------*/
  261.     /* Initialize dialog.                                             */
  262.     /*----------------------------------------------------------------*/
  263.  
  264.     case  WM_INITDLG :
  265.       pdhnd = (DHND *)mp2;
  266.       WinSetWindowPtr(hDlg,
  267.                       QWL_USER,
  268.                       (PVOID)pdhnd);
  269.       GsGetDiagPointerN(*pdhnd, 0, (VOID **)&pEnv);
  270.       WinSendDlgItemMsg(hDlg,
  271.                         ID_LAST_NAME,
  272.                         EM_SETTEXTLIMIT,
  273.                         MPFROM2SHORT(MAX_LAST_NAME,
  274.                                      0),
  275.                         NULL);
  276.       WinSendDlgItemMsg(hDlg,
  277.                         ID_FIRST_NAME,
  278.                         EM_SETTEXTLIMIT,
  279.                         MPFROM2SHORT(MAX_FIRST_NAME,
  280.                                      0),
  281.                         NULL);
  282.       hwnd = WinWindowFromID(hDlg,
  283.                              ID_OK);
  284.       WinEnableWindow(hwnd,
  285.                       FALSE);
  286.       return  FALSE;
  287.  
  288.       /*--------------------------------------------------------------*/
  289.       /* Disable FIND (OK) push button if no last name has been       */
  290.       /* entered.                                                     */
  291.       /*--------------------------------------------------------------*/
  292.  
  293.     case  WM_CONTROL :
  294.       if ((SHORT1FROMMP(mp1) == ID_LAST_NAME ||  //
  295.          SHORT1FROMMP(mp1) == ID_FIRST_NAME) &&  //
  296.          SHORT2FROMMP(mp1) == EN_CHANGE)
  297.       {
  298.         pdhnd = (DHND *)WinQueryWindowPtr(hDlg,
  299.                                           QWL_USER);
  300.         GsGetDiagPointerN(*pdhnd, 0, (VOID **)&pEnv);
  301.         WinQueryDlgItemText(hDlg,
  302.                             ID_LAST_NAME,
  303.                             MAX_LAST_NAME,
  304.                             pEnv->passId.lastName);
  305.         WinQueryDlgItemText(hDlg,
  306.                             ID_FIRST_NAME,
  307.                             MAX_FIRST_NAME,
  308.                             pEnv->passId.firstName);
  309.         hwnd = WinWindowFromID(hDlg,
  310.                                ID_OK);
  311.         if (BlanksEmpty(pEnv->passId.lastName))
  312.           WinEnableWindow(hwnd,
  313.                           FALSE);
  314.         else
  315.           WinEnableWindow(hwnd,
  316.                           TRUE);
  317.       }
  318.       return 0L;
  319.     case  WM_COMMAND :
  320.       pdhnd = (DHND *)WinQueryWindowPtr(hDlg,
  321.                                         QWL_USER);
  322.       GsGetDiagPointerN(*pdhnd, 0, (VOID **)&pEnv);
  323.  
  324.       /*--------------------------------------------------------------*/
  325.       /* Process according to PUSH button pressed:                    */
  326.       /*--------------------------------------------------------------*/
  327.  
  328.       switch (SHORT1FROMMP(mp1))
  329.       {
  330.  
  331.         /*------------------------------------------------------------*/
  332.         /* FIND (OK) - Set pasenger name and exit dialog.             */
  333.         /*------------------------------------------------------------*/
  334.  
  335.         case  ID_OK :
  336.           WinQueryDlgItemText(hDlg,
  337.                               ID_LAST_NAME,
  338.                               MAX_LAST_NAME,
  339.                               pEnv->passId.lastName);
  340.           RemLeadTrailB(pEnv->passId.lastName);
  341.           WinQueryDlgItemText(hDlg,
  342.                               ID_FIRST_NAME,
  343.                               MAX_FIRST_NAME,
  344.                               pEnv->passId.firstName);
  345.           RemLeadTrailB(pEnv->passId.firstName);
  346.           WinDismissDlg(hDlg,
  347.                         TRUE);
  348.           break;
  349.  
  350.           /*----------------------------------------------------------*/
  351.           /* CANCEL - Cancel dialog.                                  */
  352.           /*----------------------------------------------------------*/
  353.  
  354.         case  ID_CANCEL :
  355.           WinDismissDlg(hDlg,
  356.                         FALSE);
  357.           break;
  358.       }
  359.       return  NULL;
  360.     default  :
  361.       break;
  362.   }
  363.   return  WinDefDlgProc(hDlg,
  364.                         msg,
  365.                         mp1,
  366.                         mp2);
  367. }
  368.