home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDLINKS.C < prev    next >
C/C++ Source or Header  |  1992-12-06  |  10KB  |  323 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*              Links                */
  14. /*            dialog box             */
  15. /*                                   */
  16. /*           QuickC/WIN 1.0          */
  17. /*                                   */
  18. /*   (include here compilers that    */
  19. /*   compiled GWSIM successfully)    */
  20. /*                                   */
  21. /*************************************/
  22.  
  23.  
  24. #include <windows.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <math.h>
  28. #include "defines.h"                    /* symbols also used in .DLG files        */
  29. #include "globals.h"                    /* gepasi's own symbols                    */
  30. #include "gwsim.h"                        /* macros, function prototypes, etc.    */
  31. #include "gep2.h"                        /* gepasi's variables                    */
  32. #include "simgvar.h"                    /* global variables                        */
  33. #include "strtbl.h"                        /* symbols for the string table            */
  34.  
  35. #pragma alloc_text( CODE16, Links, EdLinks)
  36.  
  37. extern void AddPLst( HWND hControl, int idx, BOOL scroll );
  38.  
  39.  
  40. int FAR PASCAL Links(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  41. {
  42.  static HWND hSelect, hButt, hDel;
  43.  int i,j,nRc;
  44.  FARPROC        lpfnProc2;                /* pointer to dialog procedures            */
  45.  
  46.  switch( Message )
  47.  {
  48.   case WM_INITDIALOG:
  49.    /* allocate memory for the mirror                */
  50.    hScp = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, sizespar );
  51.    if( hScp == NULL )
  52.    {
  53.     LoadString(hInst, IDS_ERR_NOEXEC, szString, sizeof(szString));
  54.     MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  55.     EndDialog(hDlg, IDCANCEL);
  56.     return TRUE;
  57.    }
  58.  
  59.    /* lock the memory block                            */
  60.    scp  = (struct sp huge *) GlobalLock( hScp );
  61.  
  62.    /* copy params to its mirror                        */
  63.    _fmemcpy( (void __far *) scp,
  64.              (void __far *) spar,
  65.              (size_t) sizespar );
  66.    nlks = nlinks;
  67.  
  68.    /* get handles for controls                        */
  69.    hSelect = GetDlgItem( hDlg, IDC_SELECT );
  70.    hButt = GetDlgItem( hDlg, IDC_CHANGE );
  71.    hDel = GetDlgItem( hDlg, IDC_DEL );
  72.  
  73.    /* initialize hSelect: add all elements with links    */
  74.    for( i=0, lbWidth=0; i<nlks; i++ )
  75.     for( j=0; j<nscanpar; j++ )
  76.      if( (scp[j].lidx) ==  i )
  77.       AddPLst( hSelect, j, TRUE );
  78.    if( nlks==0 )
  79.    {
  80.     EnableWindow( hButt, FALSE );
  81.     EnableWindow( hDel, FALSE );
  82.    }
  83.    else SendMessage( hSelect, LB_SETCURSEL, 0, 0 );
  84.    return TRUE;
  85.  
  86.   case WM_COMMAND:
  87.    switch(wParam)
  88.    {
  89.     case IDC_ADD:
  90.      lno = nlks;
  91.      lpfnProc2 = MakeProcInstance((FARPROC) EdLinks, hInst);
  92.      nRc = DialogBox(hInst, (LPSTR)"ED_LINK", hDlg, lpfnProc2);
  93.      FreeProcInstance(lpfnProc2);
  94.      if( nRc>=0 )
  95.      {
  96.       AddPLst( hSelect, nRc, TRUE );
  97.       nlks++;
  98.       if( nlks==1 )
  99.       {
  100.        EnableWindow( hButt, TRUE );
  101.        EnableWindow( hDel, TRUE );
  102.       }
  103.      }
  104.      else SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
  105.      return TRUE;
  106.  
  107.     case IDC_CHANGE:
  108.      /* get the index of the element selected                    */
  109.      i = (int) SendMessage( hSelect, LB_GETCURSEL, 0, 0 );
  110.      if( i != LB_ERR )
  111.      {
  112.       lno = i;
  113.       lpfnProc2 = MakeProcInstance((FARPROC) EdLinks, hInst);
  114.       nRc = DialogBox(hInst, (LPSTR)"ED_LINK", hDlg, lpfnProc2);
  115.       FreeProcInstance(lpfnProc2);
  116.       if( nRc==-1 ) SendMessage( hDlg, WM_COMMAND, IDCANCEL, 0 );
  117.       else
  118.       {
  119.        SendMessage( hSelect, LB_DELETESTRING, i, 0 );
  120.        for( j=0; j<nscanpar; j++ )
  121.         if( (scp[j].lidx) ==  i )
  122.          SendMessage( hSelect, LB_INSERTSTRING, i, (DWORD) scp[j].title );
  123.       }
  124.      }
  125.      return TRUE;
  126.  
  127.     case IDC_DEL:
  128.      /* get the index of the element selected                    */
  129.      i = (int) SendMessage( hSelect, LB_GETCURSEL, 0, 0 );
  130.      if( i != LB_ERR )
  131.      {
  132.       for( j=0; j<nscanpar; j++ )
  133.       {
  134.        if( scp[j].lidx > i ) scp[j].lidx--;
  135.        else
  136.         if( (scp[j].lidx) ==  i )
  137.         {
  138.          scp[j].lidx = -1;
  139.          scp[j].operation = 1;
  140.          scp[j].linkedto = -1;
  141.          scp[j].factor = 1;
  142.         }
  143.       }
  144.       nlks--;
  145.       if( nlks==0 )
  146.       {
  147.        EnableWindow( hButt, FALSE );
  148.        EnableWindow( hDel, FALSE );
  149.       }
  150.       SendMessage( hSelect, LB_DELETESTRING, (WORD) i, 0 );
  151.      }
  152.      return TRUE;
  153.  
  154.     case IDC_SELECT:
  155.      if( HIWORD( lParam ) == LBN_DBLCLK )
  156.      {
  157.       SendMessage( hDlg, WM_COMMAND, IDC_CHANGE, 0 );
  158.       return TRUE;
  159.      }
  160.      else return FALSE;
  161.  
  162.     case IDC_HELP:            /* Help on this Dialog Box                */
  163.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Links dialog box" );
  164.      return TRUE;
  165.  
  166.     case IDOK:
  167.      nlinks = nlks;
  168.      /* copy params back from its mirror                                */
  169.      _fmemcpy( (void __far *) spar,
  170.                (void __far *) scp,
  171.                (size_t) sizespar );
  172.      /* unlock and free the mirror memory block             */
  173.      GlobalUnlock( hScp );
  174.      GlobalFree( hScp );
  175.      /* signal that changes have been made                    */
  176.      notsaved = 1;
  177.      EndDialog(hDlg, IDOK);
  178.      return TRUE;
  179.  
  180.     case IDCANCEL:
  181.      /* unlock and free the mirror memory block             */
  182.      GlobalUnlock( hScp );
  183.      GlobalFree( hScp );
  184.      EndDialog(hDlg, IDCANCEL);
  185.      return TRUE;
  186.    }    /* End of WM_COMMAND                                 */
  187.    return FALSE;
  188.  
  189.   default:
  190.    return FALSE;
  191.  }
  192. } /* End of METABMsgProc                                      */
  193.  
  194.  
  195. int FAR PASCAL EdLinks(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  196. {
  197.  static int nsel;
  198.  static HWND hAvail, hSelect, hS1, hS2, hFactor;
  199.  int  i, old;
  200.  char buff[128];
  201.  
  202.  switch(Message)
  203.  {
  204.   case WM_INITDIALOG:
  205.    /* get handles to controls                        */
  206.    hAvail = GetDlgItem( hDlg, IDC_PARAMLST );
  207.    hSelect = GetDlgItem( hDlg, IDC_SELECT );
  208.    hS1 = GetDlgItem( hDlg, IDSTAT_6 );
  209.    hS2 = GetDlgItem( hDlg, IDSTAT_7 );
  210.    hFactor = GetDlgItem( hDlg, IDE_M0 );
  211.  
  212.    /* init hAvail and hSelect: add all output elmnts*/
  213.    for( i=0, lbWidth=0; i<nscanpar; i++ )
  214.    {
  215.     AddPLst( hAvail,  i, FALSE );
  216.     AddPLst( hSelect, i, FALSE );
  217.    }
  218.  
  219.    if( lno==nlks ) i = -1;
  220.    else
  221.    {
  222.     for( i=0; i<nscanpar; i++ )
  223.      if( scp[i].lidx == lno) break;
  224.    }
  225.  
  226.    if( i==-1) strcpy( buff, "1" );
  227.    else gcvt( scp[i].factor, 8, buff );
  228.    SendMessage( hFactor, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  229.  
  230.    if( i==-1 ) buff[0] = '\0';
  231.    else _fstrcpy( (LPSTR) buff, scp[i].title );
  232.    SendMessage( hS1, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  233.    SendMessage( hAvail, LB_SETCURSEL, (WORD) i, 0 );
  234.  
  235.    if( i==-1 ) SendMessage( hSelect, LB_SETCURSEL, (WORD) -1, 0 );
  236.    else SendMessage( hSelect, LB_SETCURSEL, (WORD) scp[i].linkedto, 0 );
  237.  
  238.    if( (i==-1) || (scp[i].linkedto==-1) ) buff[0] = '\0';
  239.    else _fstrcpy( (LPSTR) buff, scp[scp[i].linkedto].title );
  240.    SendMessage( hS2, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  241.  
  242.    nsel = i;
  243.  
  244.    InvalidateRect( hDlg, NULL, FALSE );
  245.    return TRUE;
  246.  
  247.   case WM_COMMAND:
  248.    switch(wParam)
  249.    {
  250.     case IDC_PARAMLST:
  251.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  252.      {
  253.       /* keep the old selection value                                */
  254.       old = nsel;
  255.       /* get the newly selected element in the available box        */
  256.       nsel = (int) SendMessage( hAvail, LB_GETCURSEL, 0, 0 );
  257.       if( nsel != LB_ERR )
  258.       {
  259.        if( old != -1 )
  260.        {
  261.         scp[nsel].lidx = scp[old].lidx;
  262.         scp[nsel].factor = scp[old].factor;
  263.         scp[nsel].operation = scp[old].operation;
  264.         scp[nsel].linkedto = scp[old].linkedto;
  265.         scp[old].lidx = -1;
  266.         scp[old].factor = 1;
  267.         scp[old].operation = 1;
  268.         scp[old].linkedto = -1;
  269.        }
  270.        else
  271.         scp[nsel].lidx = lno;
  272.        SendMessage( hS1, WM_SETTEXT, 0, (DWORD) (LPSTR) scp[nsel].title );
  273.       }
  274.       return TRUE;
  275.      }
  276.      else return FALSE;
  277.  
  278.     case IDC_SELECT:
  279.      if( HIWORD( lParam ) == LBN_SELCHANGE )
  280.      {
  281.       /* get the index of the element selected                    */
  282.       i = (int) SendMessage( hSelect, LB_GETCURSEL, 0, 0 );
  283.       if( (i != LB_ERR) && (nsel != -1) )
  284.       {
  285.        scp[nsel].linkedto = i;
  286.        SendMessage( hS2, WM_SETTEXT, 0, (DWORD)(LPSTR) scp[scp[nsel].linkedto].title );
  287.       }
  288.       return TRUE;
  289.      }
  290.      else return FALSE;
  291.  
  292.     case IDC_HELP:            /* Help on this Dialog Box                */
  293.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Edit link" );
  294.      return TRUE;
  295.  
  296.     case IDOK:
  297.      /* get the value of factor                                            */
  298.      i = (int) SendMessage( hFactor, WM_GETTEXT, 128, (DWORD)(LPSTR) buff );
  299.      if( i>0 ) scp[nsel].factor = strtod( buff, NULL );
  300.      scp[nsel].lidx = lno;
  301.      if( (scp[nsel].factor==HUGE_VAL) || (scp[nsel].factor==-HUGE_VAL) )
  302.      {
  303.       LoadString(hInst, IDS_ERR_OVERFLOW, szString, sizeof(szString));
  304.       MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  305.       SetFocus( hFactor );
  306.       return TRUE;
  307.      }
  308.      EndDialog(hDlg, nsel);
  309.      return TRUE;
  310.  
  311.     case IDCANCEL:
  312.      /* unlock and free the mirror memory block             */
  313.      EndDialog(hDlg, -1 );
  314.      return TRUE;
  315.    }    /* End of WM_COMMAND                                */
  316.    return FALSE;
  317.  
  318.   default:
  319.    return FALSE;
  320.  }
  321. } /* End of METABMsgProc                                    */
  322.  
  323.