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

  1. /*
  2. GIK/2 1.0.1 EWYEAEH.C 5621-432 (C) COPYRIGHT IBM CORP 1991, 1993.  ALL RIGHTS RESERVED.  LICENSED MATERIALS - PROPERTY OF IBM.
  3. */
  4. /**********************************************************************/
  5. /*                                                                    */
  6. /*                         MODULE PROLOGUE                            */
  7. /*                                                                    */
  8. /* COMPONENT NAME:   Data Flow Diagram (DFD) Example                  */
  9. /*                                                                    */
  10. /*                                                                    */
  11. /* MODULE NAME:      EWYEAEH.C                                        */
  12. /*                                                                    */
  13. /* PURPOSE:                                                           */
  14. /*                                                                    */
  15. /*   This module contains the event handler functions for the         */
  16. /*   DFD example.                                                     */
  17. /*                                                                    */
  18. /* COPYRIGHT:        (C) 1991, 1993 IBM Corporation                   */
  19. /*                                                                    */
  20. /* DISCLAIMER OF WARRANTIES.  The following [enclosed] code is        */
  21. /* sample code created by IBM Corporation. This sample code is not    */
  22. /* part of any standard or IBM product and is provided to you solely  */
  23. /* for the purpose of assisting you in the development of your        */
  24. /* applications.  The code is provided "AS IS", without               */
  25. /* warranty of any kind.  IBM shall not be liable for any damages     */
  26. /* arising out of your use of the sample code, even if they have been */
  27. /* advised of the possibility of such damages.                        */
  28. /**********************************************************************/
  29. /*--------------------------------------------------------------------*/
  30. /* INCLUDE RELATED DEFINES                                            */
  31. /*--------------------------------------------------------------------*/
  32.  
  33. #define  INCL_DOS                      /* OS/2 definitions            */
  34. #define  INCL_PM                       /* PM definitions              */
  35.  
  36. /*--------------------------------------------------------------------*/
  37. /* HEADER FILES                                                       */
  38. /*--------------------------------------------------------------------*/
  39.  
  40. #include <os2.h>                       /* OS/2 header file            */
  41. #include <ewyga.h>                     /* GIK/2 header file           */
  42. #include "ewyeadf.h"                   /* Generated header file       */
  43. #include <string.h>                    /* 'C' string handling         */
  44. #include <stdlib.h>                    /* 'C' memory handling         */
  45. #include "ewyearc.h"                   /* Dialog constants header     */
  46. #include "ewyea.h"                     /* Header shared with RC-file  */
  47.  
  48. /*--------------------------------------------------------------------*/
  49. /* LOCAL FUNCTION PROTOTYPES                                          */
  50. /*--------------------------------------------------------------------*/
  51.  
  52. SHORT GSENTRY EvDoubleClick(DHND,SHORT,EVS_DOUBLE_CLICK *);
  53.  
  54. SHORT GSENTRY EvInit(DHND,SHORT,EVS_INIT *);
  55. SHORT GSENTRY EvMenu(DHND,SHORT,EVS_MENU *);
  56. SHORT GSENTRY EvNew(DHND,SHORT,VOID *);
  57. SHORT GSENTRY EvExitEnd(DHND,SHORT,EVS_EXIT_END *);
  58.  
  59. /**********************************************************************/
  60. /* EvDoubleClick                                                      */
  61. /*                                                                    */
  62. /* Parameters:                                                        */
  63. /*    DHND                     dhnd  (I): Diagram handle.             */
  64. /*    SHORT                    ev_id (I): Identifies the event.       */
  65. /*    EVS_DOUBLE_CLICK         *pEvs (I): Pointer to instance of event*/
  66. /*                                        data type.                  */
  67. /*     SHND   shnd (I):            Handle of the symbol               */
  68. /*     SHORT  part_ref (I):        Reference number of the symbol part*/
  69. /*     USHORT button (I):          Mouse button that is pressed       */
  70. /*                                 It is one of the following:        */
  71. /*                                   GS_MB1                           */
  72. /*                                   GS_MB2                           */
  73. /*                                                                    */
  74. /* Returns:                                                           */
  75. /*   GS_NO        Any changes made to symbols remain and the action   */
  76. /*                stops.                                              */
  77. /*   GS_NO_1      Any changes made to symbols remain and the action   */
  78. /*                stops.                                              */
  79. /*   GS_RESTORE   Any changes made to symbols since the last undo     */
  80. /*                checkpoint are undone and the action stops.         */
  81. /*   GS_RESTORE_1 Any changes made to symbols since the last undo     */
  82. /*                checkpoint are undone and the action stops.         */
  83. /*   GS_YES       The default processing continues.                   */
  84. /*                                                                    */
  85. /* Description:                                                       */
  86. /*    The function handles the event EV_DOUBLE_CLICK.                 */
  87. /**********************************************************************/
  88.  
  89. SHORT GSENTRY EvDoubleClick(DHND dhnd,SHORT ev_id,EVS_DOUBLE_CLICK *pEvs
  90. )
  91. {
  92.   PTOOLDATA        pToolData;         // ptr to appl. data structure
  93.   SHORT            type;               // type of symbol
  94.   HWND             hWndC;              // client window handle
  95.   DLG_DATA         DlgData;            // symbol data
  96.  
  97.   /********************************************************************/
  98.   /* Get the type of symbol that was hit and prepare the parameters.  */
  99.   /********************************************************************/
  100.  
  101.   GsGetSymType(dhnd, pEvs->shnd, &type); // get type of symbol hit
  102. //
  103.   pToolData = NULL;
  104.   GsGetDiagPointerN(dhnd, PTOOLDATA_ID, (PVOID *)&pToolData);
  105.   pToolData->dhnd = dhnd;              // diagram handle
  106.   pToolData->shnd = pEvs->shnd;        // symbol handle
  107. //
  108.   GsGetHwnd(dhnd, GS_WIN_MAIN, 0, FID_CLIENT, &hWndC); // get client handle
  109. //
  110.   if (pEvs->part_ref != FN_NAME)
  111.   {
  112.  
  113.     /*----------------------------------------------------------------*/
  114.     /* Get the data from the object data buffer and check if the file */
  115.     /* specification of a diagram was specified.                      */
  116.     /*----------------------------------------------------------------*/
  117.  
  118.     GsGetSymObjectData(dhnd, pEvs->shnd, &DlgData,  //
  119.        sizeof(DLG_DATA));
  120. //
  121.     if (strlen(DlgData.szRefDiag) > 0) // refinement exists ?
  122.       PerformRefinement(dhnd, pEvs->shnd);
  123.     else
  124.     if (WinDlgBox(HWND_DESKTOP,        // Display the refinement
  125.        hWndC,                          // dialog. This allows the
  126.        SAMPLE_RefDlgProc,              // user to specify an
  127.        pToolData->hResModule,          // existing diagram.
  128.        DID_REF,                        //
  129.        (PVOID)pToolData))
  130.       PerformRefinement(dhnd, pEvs->shnd);
  131.   }
  132.   return  GS_YES;
  133. }
  134.  
  135. /**********************************************************************/
  136. /* EvInit                                                             */
  137. /*                                                                    */
  138. /* Parameters:                                                        */
  139. /*    DHND                     dhnd  (I): Diagram handle.             */
  140. /*    SHORT                    ev_id (I): Identifies the event.       */
  141. /*    EVS_INIT                 *pEvs (I): Pointer to instance of event*/
  142. /*                                        data type.                  */
  143. /*     VOID *pInit_data (I):       Pointer passed from the customizing*/
  144. /*                                 code to the parameter pInit_data of*/
  145. /*                                 the GIK/2 function GsInitWin       */
  146. /*     HAB  hab (I):               Handle to anchor block             */
  147. /*     HWND hwnd_client (I):       Handle to client window            */
  148. /*     HWND hwnd_frame (I):        Handle to frame window             */
  149. /*                                                                    */
  150. /* Returns:                                                           */
  151. /*   GS_NO        The window is closed.                               */
  152. /*   GS_YES       The initialization of the GIK/2 window continues.   */
  153. /*                                                                    */
  154. /* Description:                                                       */
  155. /*    The function handles the event EV_INIT.                         */
  156. /**********************************************************************/
  157.  
  158. SHORT GSENTRY EvInit(DHND dhnd,SHORT ev_id,EVS_INIT *pEvs)
  159. {
  160.   CHAR             szLoadError[ERROR_MSG_SIZE]; // error msg
  161.   PTOOLDATA        pToolData;         // ptr to appl. data structure
  162.   DLG_DATA         DlgData;            // symbol data
  163.   static int       topdiag;
  164.  
  165.   /********************************************************************/
  166.   /* Allocate the data structure for this application.                */
  167.   /********************************************************************/
  168.  
  169.   pToolData = (PTOOLDATA)malloc(sizeof(TOOLDATA));
  170.   memset(pToolData, '\0', sizeof(TOOLDATA)); // reset
  171. //
  172.   if (topdiag)                  // parameter passed to this instance
  173.   {
  174.  
  175.     /*----------------------------------------------------------------*/
  176.     /* Get the symbol handle and the diagram handle of the parent     */
  177.     /* symbol in the parent diagram and store it.                     */
  178.     /*----------------------------------------------------------------*/
  179.  
  180.     pToolData->shndPar = ((PTOOLDATA)pEvs->pInit_data)->shnd;
  181.     pToolData->dhndPar = ((PTOOLDATA)pEvs->pInit_data)->dhnd;
  182.  
  183.     /*----------------------------------------------------------------*/
  184.     /* Store the diagram handle of this instance in the parent symbol.*/
  185.     /*----------------------------------------------------------------*/
  186.  
  187.     GsGetSymObjectData(pToolData->dhndPar, pToolData->shndPar,  //
  188.        &DlgData, sizeof(DLG_DATA));
  189.     DlgData.dhndRef = dhnd;
  190.     GsPutSymObjectData(pToolData->dhndPar, pToolData->shndPar,  //
  191.        &DlgData, sizeof(DLG_DATA));
  192.  
  193.     /*----------------------------------------------------------------*/
  194.     /* Store the handle of the resource module.                       */
  195.     /*----------------------------------------------------------------*/
  196.  
  197.     pToolData->hResModule = ((PTOOLDATA)pEvs->pInit_data)->hResModule;
  198.  
  199.     /*----------------------------------------------------------------*/
  200.     /* Load the application icon from the resource module.            */
  201.     /*----------------------------------------------------------------*/
  202.  
  203.     GsUseIcon(dhnd, pToolData->hResModule, SAMPLE_ICON, GS_WIN_MAIN);
  204.   }
  205.   else
  206.   {
  207.     topdiag = 1;
  208.  
  209.     /*----------------------------------------------------------------*/
  210.     /* Load the resource NLS module.                                  */
  211.     /*----------------------------------------------------------------*/
  212.  
  213.     if (DosLoadModule(szLoadError, sizeof(szLoadError), NLS_RESOURCE,
  214.        &(pToolData->hResModule)))
  215.     {
  216.  
  217.       /****************************************************************/
  218.       /* ** nls dll not in current path, have a second try **         */
  219.       /****************************************************************/
  220.  
  221.       if (DosLoadModule(szLoadError, sizeof(szLoadError),
  222.          NLS_RESOURCE_2ND_TRY, &(pToolData->hResModule)))
  223.       {
  224.  
  225.         /**************************************************************/
  226.         /* ** sorry, dll somewhere else **                            */
  227.         /**************************************************************/
  228.  
  229.         GsMessageBox(dhnd, szLoadError, EV_INIT_TITLE, MB_OK, NULL); // error !
  230.         return  GS_NO;                 // do not proceed
  231.       }
  232.     }
  233.  
  234.     /*----------------------------------------------------------------*/
  235.     /* Load the application icon from the resource module.            */
  236.     /*----------------------------------------------------------------*/
  237.  
  238.     GsUseIcon(dhnd, pToolData->hResModule, SAMPLE_ICON, GS_WIN_MAIN);
  239.   }
  240.  
  241.   /********************************************************************/
  242.   /* Store the pointer to the data structure in the diagram record.   */
  243.   /********************************************************************/
  244.  
  245.   GsPutDiagPointerN(dhnd, PTOOLDATA_ID, pToolData);
  246.   GsPutDiagModify(dhnd, GS_NO);
  247.   return  GS_YES;
  248. }
  249.  
  250. /**********************************************************************/
  251. /* EvMenu                                                             */
  252. /*                                                                    */
  253. /* Parameters:                                                        */
  254. /*    DHND                     dhnd  (I): Diagram handle.             */
  255. /*    SHORT                    ev_id (I): Identifies the event.       */
  256. /*    EVS_MENU                 *pEvs (I): Pointer to instance of event*/
  257. /*                                        data type.                  */
  258. /*     SHORT  win_id (I):          Identification of the window       */
  259. /*                                 It is one of the following:        */
  260. /*                                   GS_WIN_MAIN                      */
  261. /*                                   GS_WIN_OV                        */
  262. /*     USHORT menu_id (I):         Identifier of the menu bar choice  */
  263. /*                                                                    */
  264. /* Returns:                                                           */
  265. /*   GS_NO        Any changes made to symbols remain and the action   */
  266. /*                stops.                                              */
  267. /*   GS_NO_1      Any changes made to symbols remain and the action   */
  268. /*                stops.                                              */
  269. /*   GS_RESTORE   Any changes made to symbols since the last undo     */
  270. /*                checkpoint are undone and the action stops.         */
  271. /*   GS_RESTORE_1 Any changes made to symbols since the last undo     */
  272. /*                checkpoint are undone and the action stops.         */
  273. /*   GS_YES       The default processing continues.                   */
  274. /*                                                                    */
  275. /* Description:                                                       */
  276. /*    The function handles the event EV_MENU.                         */
  277. /**********************************************************************/
  278.  
  279. SHORT GSENTRY EvMenu(DHND dhnd,SHORT ev_id,EVS_MENU *pEvs)
  280. {
  281.   SHND             shnd;               // symbol handle
  282.   SHORT            ConnCnt = 0;        // counter link
  283.   SHORT            NodeCnt = 0;        // counter node
  284.   DLG_DATA         DlgData;            // symbol data
  285.   SHORT            symType;            // symbol type
  286.   SHORT            symForm;            // symbol form
  287.  
  288.   /********************************************************************/
  289.   /* Disable all non-generic actions.                                 */
  290.   /********************************************************************/
  291.  
  292.   GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_CONTROLFLOW, GS_OFF);
  293.   GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_DATAFLOW, GS_OFF);
  294.   GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_REFINE, GS_OFF);
  295.   GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_UNREFINE, GS_OFF);
  296.  
  297.   /********************************************************************/
  298.   /* Check if a link is selected.                                     */
  299.   /********************************************************************/
  300.  
  301.   GsCollectSym(dhnd, GS_LINK, GS_SYM_SELECTED, GS_UPPER_FIRST);
  302.   while (GsGetCollectedSym(dhnd, &shnd) != GSE_COLLECTION_EMPTY)
  303.   {
  304.     ConnCnt++;
  305.   }
  306.  
  307.   /********************************************************************/
  308.   /* Count all selected nodes.                                        */
  309.   /********************************************************************/
  310.  
  311.   GsCollectSym(dhnd, GS_NODE, GS_SYM_SELECTED, GS_UPPER_FIRST);
  312.   while (GsGetCollectedSym(dhnd, &shnd) != GSE_COLLECTION_EMPTY)
  313.     NodeCnt++;
  314.  
  315.   /********************************************************************/
  316.   /* If exactly one function is selected, enable the refinement       */
  317.   /* action, if this function has a refinement diagram, enable the    */
  318.   /* unrefine action.                                                 */
  319.   /********************************************************************/
  320.  
  321.   if (NodeCnt == 1 && ConnCnt == 0)
  322.   {
  323.     GsGetFirstSym(dhnd, GS_NODE, GS_SYM_SELECTED, GS_UPPER_FIRST, &shnd)
  324.        ;
  325.     GsGetSymType(dhnd, shnd, &symType);
  326.     if (symType == FUNCTION)
  327.     {
  328.       GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_REFINE, GS_ON);
  329. //
  330.       GsGetSymObjectData(dhnd, shnd, &DlgData, sizeof(DLG_DATA));
  331.       if (strlen(DlgData.szRefDiag) > 0)
  332.         GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN,  //
  333.            AH_UNREFINE, GS_ON);
  334.     }
  335.   }
  336.  
  337.   /********************************************************************/
  338.   /* If more than one links are selected, enable the link style       */
  339.   /* actions.                                                         */
  340.   /********************************************************************/
  341.  
  342.   if (NodeCnt == 0 && ConnCnt > 1)
  343.   {
  344.     GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_CONTROLFLOW, GS_OFF);
  345.     GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_DATAFLOW, GS_OFF);
  346.   }
  347.   if (NodeCnt == 0 && ConnCnt == 1)
  348.   {
  349.     GsGetFirstSym(dhnd, GS_LINK, GS_SYM_SELECTED, GS_UPPER_FIRST, &shnd)
  350.        ;
  351.     GsGetSymForm(dhnd, shnd, &symForm);
  352.     if (symForm == F_CONTROLFLOW)
  353.     {
  354.       GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_DATAFLOW, GS_ON);
  355.       GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_CONTROLFLOW, GS_OFF);
  356.     }
  357.     if (symForm == F_DATAFLOW)
  358.     {
  359.       GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_DATAFLOW, GS_OFF);
  360.       GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_CONTROLFLOW, GS_ON);
  361.     }
  362.     GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_REFINE, GS_OFF);
  363.     GsPutMenuItemEnabled(dhnd, GS_WIN_MAIN, AH_UNREFINE, GS_OFF);
  364.   }
  365. //
  366.   return  GS_YES;
  367. }
  368.  
  369. /**********************************************************************/
  370. /* EvNew                                                              */
  371. /*                                                                    */
  372. /* Parameters:                                                        */
  373. /*    DHND                     dhnd  (I): Diagram handle.             */
  374. /*    SHORT                    ev_id (I): Identifies the event.       */
  375. /*    VOID                     *pEvs (I): Pointer to instance of event*/
  376. /*                                        data type.                  */
  377. /*                                                                    */
  378. /* Returns:                                                           */
  379. /*   GS_NO        Any changes made to symbols remain and the action   */
  380. /*                stops.                                              */
  381. /*   GS_NO_1      Any changes made to symbols remain and the action   */
  382. /*                stops.                                              */
  383. /*   GS_RESTORE   Any changes made to symbols since the last undo     */
  384. /*                checkpoint are undone and the action stops.         */
  385. /*   GS_RESTORE_1 Any changes made to symbols since the last undo     */
  386. /*                checkpoint are undone and the action stops.         */
  387. /*   GS_YES       The default processing continues.                   */
  388. /*                                                                    */
  389. /* Description:                                                       */
  390. /*    The function handles the event EV_NEW.                          */
  391. /**********************************************************************/
  392.  
  393. SHORT GSENTRY EvNew(DHND dhnd,SHORT ev_id,VOID *pEvs)
  394. {
  395.   PTOOLDATA        pToolData;         // ptr to appl. data structure
  396.  
  397.   /********************************************************************/
  398.   /* Reinitialize the data structure for this instance.               */
  399.   /********************************************************************/
  400.  
  401.   pToolData = NULL;
  402.   GsGetDiagPointerN(dhnd, PTOOLDATA_ID, (PVOID *)&pToolData); // get ptr
  403. //
  404.   pToolData->shnd = pToolData->shndPar = (SHND)0L;
  405.   pToolData->dhnd = pToolData->dhndPar = (DHND)0L;
  406.   return  GS_YES;
  407. }
  408.  
  409. /**********************************************************************/
  410. /* EvExitEnd                                                          */
  411. /*                                                                    */
  412. /* Parameters:                                                        */
  413. /*    DHND                     dhnd  (I): Diagram handle.             */
  414. /*    SHORT                    ev_id (I): Identifies the event.       */
  415. /*    EVS_EXIT_END             *pEvs (I): Pointer to instance of event*/
  416. /*                                        data type.                  */
  417. /*     SHORT close (I):            Indicator that specifies whether   */
  418. /*                                 the event is triggered during the  */
  419. /*                                 processing of the WM_CLOSE or the  */
  420. /*                                 WM_DESTROY message                 */
  421. /*                                 It is one of the following:        */
  422. /*                                   GS_YES. The WM_CLOSE message is  */
  423. /*                                           processed.               */
  424. /*                                   GS_NO.  The WM_DESTROY message is*/
  425. /*                                           processed.               */
  426. /*     HAB   hab (I):              Handle to anchor block             */
  427. /*     HWND  hwnd_client (I):      Handle to client window            */
  428. /*     HWND  hwnd_frame (I):       Handle to frame window             */
  429. /*                                                                    */
  430. /* Returns:                                                           */
  431. /*   GS_NO        Any changes made to symbols remain and the action   */
  432. /*                stops.                                              */
  433. /*   GS_NO_1      Any changes made to symbols remain and the action   */
  434. /*                stops.                                              */
  435. /*   GS_RESTORE   Any changes made to symbols since the last undo     */
  436. /*                checkpoint are undone and the action stops.         */
  437. /*   GS_RESTORE_1 Any changes made to symbols since the last undo     */
  438. /*                checkpoint are undone and the action stops.         */
  439. /*   GS_YES       The default processing continues.                   */
  440. /*                                                                    */
  441. /* Description:                                                       */
  442. /*    The function handles the event EV_EXIT_END.                     */
  443. /**********************************************************************/
  444.  
  445. SHORT GSENTRY EvExitEnd(DHND dhnd,SHORT ev_id,EVS_EXIT_END *pEvs)
  446. {
  447.   PTOOLDATA        pToolData;         // ptr to appl. data structure
  448.   PTOOLDATA        pRefToolData;      // ptr to appl. data structure
  449.   DLG_DATA         DlgData;            // symbol data
  450.   SHND             shnd;               // symbol handle
  451.  
  452.   /********************************************************************/
  453.   /* Get the pointer to the data structure.                           */
  454.   /********************************************************************/
  455.  
  456.   pToolData = NULL;
  457.   GsGetDiagPointerN(dhnd, PTOOLDATA_ID, (PVOID *)&pToolData); // get ptr
  458.   if (pToolData)                       // for safety
  459.   {
  460.  
  461.     /*----------------------------------------------------------------*/
  462.     /* Reinitialize the pointer to the refinement diagram in the      */
  463.     /* application data of the parent symbol in the parent diagram.   */
  464.     /*----------------------------------------------------------------*/
  465.  
  466.     if (pToolData->shndPar)         // if the parent diagram is open
  467.     {
  468.       GsGetSymObjectData(pToolData->dhndPar, pToolData->shndPar,  //
  469.          &DlgData, sizeof(DLG_DATA));
  470.       DlgData.dhndRef = 0L;
  471.       GsPutSymObjectData(pToolData->dhndPar, pToolData->shndPar,  //
  472.          &DlgData, sizeof(DLG_DATA));
  473.     }
  474.  
  475.     /*----------------------------------------------------------------*/
  476.     /* Loop over all node symbols and if they have a refinement       */
  477.     /* diagram open, reset the pointer to this instance in the        */
  478.     /* refinement diagram.                                            */
  479.     /*----------------------------------------------------------------*/
  480.  
  481.     GsCollectSym(dhnd, GS_NODE, GS_ANY_SYM, GS_UPPER_FIRST);
  482.     while (GsGetCollectedSym(dhnd, &shnd) != GSE_COLLECTION_EMPTY)
  483.     {
  484.       GsGetSymObjectData(dhnd, shnd,   //
  485.          &DlgData, sizeof(DLG_DATA));
  486.       if (DlgData.dhndRef)
  487.       {
  488.         pRefToolData = NULL;
  489.         GsGetDiagPointerN(DlgData.dhndRef, PTOOLDATA_ID,  //
  490.            (PVOID *)&pRefToolData);
  491.         pRefToolData->dhndPar = 0L;
  492.         pRefToolData->shndPar = 0L;
  493.       }
  494.     }
  495.  
  496.     /******************************************************************/
  497.     /* Free the data structure for this instance.                     */
  498.     /******************************************************************/
  499. //    DosFreeSeg(SELECTOROF(pToolData)); // free it
  500.  
  501.     free(pToolData);
  502.     GsPutDiagPointerN(dhnd, PTOOLDATA_ID, NULL); // reset
  503.   }
  504.   return  GS_YES;
  505. }
  506.  
  507. /**********************************************************************/
  508. /* SAMPLE_RefDlgProc                                                  */
  509. /*                                                                    */
  510. /* Parameters:                                                        */
  511. /*    HWND   hDlg (I):          Window handle of dialog box           */
  512. /*    ULONG msg  (I):          Message                                */
  513. /*    MPARAM mp1  (I):          Parameter 1                           */
  514. /*    MPARAM mp2  (I):          Parameter 2                           */
  515. /*                                                                    */
  516. /* Returns:                                                           */
  517. /*    MRESULT (TRUE or FALSE) depending on processing.                */
  518. /*                                                                    */
  519. /* Description:                                                       */
  520. /*    This is the dialog box window procedure for the refinement      */
  521. /*    action. The data entered is stored in the object data buffer    */
  522. /*    of the selected function symbol.                                */
  523. /**********************************************************************/
  524.  
  525. MRESULT GSENTRY SAMPLE_RefDlgProc(HWND hDlg, //
  526.                                    ULONG msg, //
  527.                                    MPARAM mp1, //
  528.                                    MPARAM mp2)
  529. {
  530.   static PTOOLDATA pToolData;         // ptr to appl. data structure
  531.   static DLG_DATA  DlgData;            // symbol data
  532.  
  533.   switch (msg)
  534.   {
  535.     case  WM_INITDLG :
  536.  
  537.       /*--------------------------------------------------------------*/
  538.       /* Get the pointer to the application data and retrieve the     */
  539.       /* symbol data.                                                 */
  540.       /*--------------------------------------------------------------*/
  541.  
  542.       pToolData = (PTOOLDATA)LONGFROMMP(mp2); // remember ptr
  543.       GsGetSymObjectData(pToolData->dhnd, pToolData->shnd, &DlgData,
  544.          sizeof(DLG_DATA));
  545.       break;
  546. //
  547.     case  WM_CONTROL :
  548.       switch (SHORT1FROMMP(mp1))
  549.       {
  550.  
  551.         /*------------------------------------------------------------*/
  552.         /* Store what has been entered by the user.                   */
  553.         /*------------------------------------------------------------*/
  554.  
  555.         case  DID_REF_NAME :
  556.           WinQueryWindowText(WinWindowFromID(hDlg,
  557.                                              DID_REF_NAME),
  558.                              GS_FILE_SPEC_LEN,
  559.                              DlgData.szRefDiag);
  560.           break;
  561.         default  :
  562.           break;
  563.       }
  564.       break;
  565. //
  566.     case  WM_COMMAND :
  567.       switch (SHORT1FROMMP(mp1))
  568.       {
  569.         case  DID_REF_OK :
  570.  
  571.           /*----------------------------------------------------------*/
  572.           /* Store the refinement information in the function symbol. */
  573.           /*----------------------------------------------------------*/
  574.  
  575.           GsPutSymObjectData(pToolData->dhnd, pToolData->shnd, &DlgData,
  576.              sizeof(DlgData));
  577. //
  578.           WinDismissDlg(hDlg,          // dismiss the dialog
  579.                         TRUE);
  580.           break;
  581. //
  582.         case  DID_REF_CANCEL :
  583.         case  DID_CANCEL :
  584.           WinDismissDlg(hDlg,          // dismiss the dialog
  585.                         FALSE);
  586.           break;
  587.         default  :
  588.           break;
  589.       }
  590.       break;
  591. //
  592.     default  :
  593.       return  WinDefDlgProc(hDlg,
  594.                             msg,
  595.                             mp1,
  596.                             mp2);
  597.   }
  598.  
  599.   return (MPARAM)FALSE;
  600. }
  601.  
  602. /**********************************************************************/
  603. /* PerformRefinement                                                  */
  604. /*                                                                    */
  605. /* Parameters:                                                        */
  606. /*    DHND      dhnd   (I):       Diagram handle.                     */
  607. /*    SHND      shnd  (I):        Symbol handle.                      */
  608. /*                                                                    */
  609. /* Returns:                                                           */
  610. /*    Nothing.                                                        */
  611. /*                                                                    */
  612. /* Description:                                                       */
  613. /*    The function performs a refinement action, i.e. invokes         */
  614. /*    another instance of the data-flow diagram editor and optionally */
  615. /*    opens a diagram.                                                */
  616. /**********************************************************************/
  617.  
  618. VOID PerformRefinement(DHND dhnd,      //
  619.                         SHND shnd)
  620. {
  621.   PTOOLDATA        pToolData;         // ptr to appl. data structure
  622.   HWND             hWndF;              // frame window handle
  623.   HWND             hWndFrameOld;       // frame window handle
  624.   HWND             hWndHelp;           // frame window handle
  625.   DHND             dhndNew;            // new diagram handle
  626.   DLG_DATA         DlgData;            // symbol data
  627.   CHAR             filespec[GS_FILE_SPEC_LEN+1]; // design file spec
  628.   SHND             shndNew;            // symbol handle
  629.   HAB              hab;
  630.  
  631.   /********************************************************************/
  632.   /* Get the pointer to the data structure.                           */
  633.   /********************************************************************/
  634.  
  635.   pToolData = NULL;
  636.   GsGetDiagPointerN(dhnd, PTOOLDATA_ID, (PVOID *)&pToolData);
  637.  
  638.   /********************************************************************/
  639.   /* Prepare parameter.                                               */
  640.   /********************************************************************/
  641.  
  642.   pToolData->shnd = shnd;              // prepare parameters
  643.   pToolData->dhnd = dhnd;
  644.  
  645.   /********************************************************************/
  646.   /* Get the application data from the object data buffer.            */
  647.   /********************************************************************/
  648.  
  649.   GsGetSymObjectData(dhnd, shnd, &DlgData, sizeof(DLG_DATA));
  650.  
  651.   /********************************************************************/
  652.   /* Perform the refinement.                                          */
  653.   /********************************************************************/
  654.  
  655.   if (DlgData.dhndRef)
  656.   {
  657.  
  658.     /*----------------------------------------------------------------*/
  659.     /* If the refinement diagram is already open, activate it.        */
  660.     /*----------------------------------------------------------------*/
  661.  
  662.     GsGetHwnd(DlgData.dhndRef, GS_WIN_MAIN, 0, 0, &hWndF); // get frame handle
  663.     WinSetActiveWindow(HWND_DESKTOP,   // make window active
  664.                        hWndF);
  665.   }
  666.   else
  667.   {
  668.  
  669.     /*----------------------------------------------------------------*/
  670.     /* Bring up another instance of the editor.                       */
  671.     /*----------------------------------------------------------------*/
  672.  
  673.     GsGetDesignFileSpec(dhnd, filespec, sizeof(filespec));
  674.     if (GsInitWin(&dhndNew, NULL, filespec, pToolData,  //
  675.        HWND_DESKTOP, 1))
  676.       GsMessageBox(dhnd, REF_ERROR, EV_DOUBLE_CLICK_TITLE, MB_OK, NULL);
  677.     else
  678.     if (strlen(DlgData.szRefDiag) != 0)
  679.       if (GsOpen(dhndNew, DlgData.szRefDiag) == GS_OK)
  680.       {
  681.  
  682.         /*------------------------------------------------------------*/
  683.         /* Reset dhndRef in symbols of opened diagram.                */
  684.         /*------------------------------------------------------------*/
  685.  
  686.         GsCollectSym(dhndNew, GS_NODE, GS_ANY_SYM, GS_UPPER_FIRST);
  687.         while (GsGetCollectedSym(dhndNew, &shndNew) !=
  688.            GSE_COLLECTION_EMPTY)
  689.         {
  690.           GsGetSymObjectData(dhndNew, shndNew, &DlgData,  //
  691.              sizeof(DLG_DATA));
  692.           DlgData.dhndRef = 0L;
  693.           GsPutSymObjectData(dhndNew, shndNew, &DlgData,  //
  694.              sizeof(DLG_DATA));
  695.           GsPutDiagModify(dhndNew, GS_NO);
  696.         }
  697.  
  698.         /*------------------------------------------------------------*/
  699.         /* Make refinement symbol part visible.                       */
  700.         /*------------------------------------------------------------*/
  701.  
  702.         GsPutPartVisibility(dhnd, shnd, FN_REFINEMENT, GS_ON);
  703.  
  704.         /*------------------------------------------------------------*/
  705.         /* Refresh the screen of the parent.                          */
  706.         /*------------------------------------------------------------*/
  707.  
  708.         GsUpdateGraphics(dhnd);
  709.       }
  710.       else
  711.       {
  712.  
  713.         /*------------------------------------------------------------*/
  714.         /* Open failed, reinitialize the refinement information.      */
  715.         /*------------------------------------------------------------*/
  716.  
  717.         GsGetSymObjectData(dhnd, shnd, &DlgData, sizeof(DLG_DATA));
  718.         DlgData.szRefDiag[0] = '\0';
  719.         GsPutSymObjectData(dhnd, shnd, &DlgData, sizeof(DLG_DATA));
  720.       }
  721.     GsGetSymObjectData(dhnd, shnd, &DlgData, sizeof(DLG_DATA));
  722.     if (DlgData.szRefDiag[0] != '\0')
  723.     {
  724.  
  725.       /*--------------------------------------------------------------*/
  726.       /* Make refinement symbol part visible.                         */
  727.       /*--------------------------------------------------------------*/
  728.  
  729.       GsPutPartVisibility(dhnd, shnd, FN_REFINEMENT, GS_ON);
  730.  
  731.       /*--------------------------------------------------------------*/
  732.       /* Refresh the screen of the parent.                            */
  733.       /*--------------------------------------------------------------*/
  734.  
  735.       GsUpdateGraphics(dhnd);
  736.     }
  737.  
  738.     /******************************************************************/
  739.     /* Get the help window hwnd from the old window and associate /*  */
  740.     /* it with the refined window handle.                             */
  741.     /******************************************************************/
  742.  
  743.     GsGetHwnd(dhnd, GS_WIN_MAIN, 0, 0, &hWndFrameOld); // get frame handle
  744.     GsGetHwnd(dhndNew, GS_WIN_MAIN, 0, 0, &hWndF); // get frame handle
  745.     hWndHelp = WinQueryHelpInstance(hWndFrameOld);
  746.     GsGetHab(&hab);
  747.     WinGetLastError(hab);
  748.     if (!WinAssociateHelpInstance(hWndHelp, hWndF))
  749.     {
  750.       WinGetLastError(hab);
  751.       GsMessageBox(dhndNew, HELP_LOAD_ERROR, HELP_LOAD_ERROR_TITLE,
  752.          MB_OK, NULL);
  753.     }
  754.   }
  755. }
  756.  
  757. /**********************************************************************/
  758. /* DefineRefinement                                                   */
  759. /*                                                                    */
  760. /* Parameters:                                                        */
  761. /*    DHND      dhnd   (I):       Diagram handle.                     */
  762. /*    SHND      shnd   (I):       Symbol handle.                      */
  763. /*                                                                    */
  764. /* Returns:                                                           */
  765. /*    Nothing.                                                        */
  766. /*                                                                    */
  767. /* Description:                                                       */
  768. /*    The function defines a refinement for the save and save-as      */
  769. /*    actions.                                                        */
  770. /**********************************************************************/
  771.  
  772. VOID DefineRefinement(DHND dhnd)
  773. {
  774.   PTOOLDATA        pToolData;         // ptr to appl. data structure
  775.   CHAR             fileSpec[GS_FILE_SPEC_LEN+1]; // file specification
  776.   DLG_DATA         DlgData;            // symbol data
  777.  
  778.   pToolData = NULL;
  779.   GsGetDiagPointerN(dhnd, PTOOLDATA_ID, (PVOID *)&pToolData); // get ptr
  780.  
  781.   /********************************************************************/
  782.   /* If the parent symbol handle is null, the current diagram is the  */
  783.   /* top diagram. In this case no file specification is stored.       */
  784.   /********************************************************************/
  785.  
  786.   if (!pToolData->shndPar)
  787.     return ;
  788.  
  789.   /********************************************************************/
  790.   /* Get the application data structure of the parent symbol.         */
  791.   /********************************************************************/
  792.  
  793.   GsGetSymObjectData(pToolData->dhndPar, pToolData->shndPar,  //
  794.      &DlgData, sizeof(DLG_DATA));
  795.  
  796.   /********************************************************************/
  797.   /* Remember the file specification in the application data of the   */
  798.   /* parent symbol.                                                   */
  799.   /********************************************************************/
  800.  
  801.   GsGetFileSpec(dhnd, fileSpec, GS_FILE_SPEC_LEN);
  802.   strcpy(DlgData.szRefDiag, fileSpec);
  803.   GsPutSymObjectData(pToolData->dhndPar, pToolData->shndPar,  //
  804.      &DlgData, sizeof(DLG_DATA));
  805.  
  806.   /********************************************************************/
  807.   /* Make refinement symbol part visible.                             */
  808.   /********************************************************************/
  809.  
  810.   GsPutPartVisibility(pToolData->dhndPar, pToolData->shndPar,
  811.      FN_REFINEMENT, GS_ON);
  812.  
  813.   /********************************************************************/
  814.   /* Refresh the screen of the parent.                                */
  815.   /********************************************************************/
  816.  
  817.   GsUpdateGraphics(pToolData->dhndPar);
  818. }
  819.