home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDDAT.C < prev    next >
C/C++ Source or Header  |  1993-08-26  |  11KB  |  317 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992, 1993  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*         GWSIM - Simulation        */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*             data specs            */
  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 "commdlg.h"
  29. #include "defines.h"                    /* symbols also used in .DLG files        */
  30. #include "globals.h"                    /* gepasi's own symbols                    */
  31. #include "gwsim.h"                        /* macros, function prototypes, etc.    */
  32. #include "gep2.h"                        /* gepasi's variables                    */
  33. #include "simgvar.h"                    /* global variables                        */
  34. #include "strtbl.h"                        /* symbols for the string table            */
  35. #include "basic.h"
  36.  
  37. #pragma alloc_text( CODE6, AddElLst, EdDat)
  38.  
  39. void AddElLst( HWND hControl, struct ou huge * oel, int idx, BOOL scroll )
  40. {
  41.  int i;
  42.  WORD ElWidth;
  43.  HANDLE hDC;
  44.  
  45.  hDC = GetDC( hControl );
  46.  ElWidth = 5 + LOWORD( GetTextExtent( hDC, oel[idx].title, _fstrlen(oel[idx].title) ) );
  47.  SetTextJustification( hDC, 0, 0 );
  48.  ReleaseDC( hControl, hDC );
  49.  if( ElWidth > lbWidth )
  50.  {
  51.   lbWidth = ElWidth;
  52.   SendMessage( hControl, LB_SETHORIZONTALEXTENT, lbWidth, 0 );
  53.  }
  54.  SendMessage( hControl, LB_INSERTSTRING, -1, (DWORD) oel[idx].title );
  55.  if( scroll ) SendMessage( hControl, WM_VSCROLL, SB_BOTTOM, 0 );
  56. }
  57.  
  58.  
  59. BOOL FAR PASCAL EdDat(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  60. {
  61.  static int tsel;
  62.  static HWND hAvail, hDatLst, hSep, hFName,
  63.              hWidth, hStatEl, hStatDat;
  64.  HWND hRadio;
  65.  int  i, j, nsel;
  66.  char buff[128];
  67.  static char DName[256];
  68.  static char DTitle[13];
  69.  char *p;
  70.  
  71.  switch(Message)
  72.  {
  73.   case WM_INITDIALOG:
  74.    /* allocate memory for the mirror                */
  75.    hOel = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, sizeoutp );
  76.    if( hOel == NULL )
  77.    {
  78.     LoadString(hInst, IDS_ERR_NOEXEC, szString, sizeof(szString));
  79.     MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  80.     EndDialog(hDlg, FALSE);
  81.     return TRUE;
  82.    }
  83.  
  84.    /* lock the memory block                            */
  85.    oel  = (struct ou huge *) GlobalLock( hOel );
  86.  
  87.    /* copy params to its mirror                                    */
  88.    _fmemcpy( (void __far *) oel,
  89.              (void __far *) outpel,
  90.              (size_t) sizeoutp );
  91.    strcpy( DName, DatName );
  92.    strcpy( DTitle, DatTitle );
  93.  
  94.    /* get handles to controls                        */
  95.    hAvail = GetDlgItem( hDlg, IDC_PARAMLST );
  96.    hDatLst = GetDlgItem( hDlg, IDC_DAT );
  97.    hSep = GetDlgItem( hDlg, IDC_SEPAR );
  98.    hWidth = GetDlgItem( hDlg, IDC_WIDTH );
  99.    hStatEl = GetDlgItem( hDlg, IDSTAT_6 );
  100.    hStatDat = GetDlgItem( hDlg, IDSTAT_7 );
  101.    hFName = GetDlgItem( hDlg, IDC_FILENAME );
  102.  
  103.    /* initialize hAvail: add all output elements    */
  104.    for( i=0, lbWidth=0; i<noutpel; i++ )
  105.     AddElLst( hAvail, oel, i, FALSE );
  106.  
  107.    /* copy the number of selected to mirror            */
  108.    tsel = totsel;
  109.    /* initialize hDatLst: add all selected elements    */
  110.    for( i=0, lbWidth=0; i<tsel; i++ )
  111.     for( j=0; j<noutpel; j++ )
  112.      if( (oel[j].idx-1) == (unsigned int) i )
  113.       AddElLst( hDatLst, oel, j, TRUE );
  114.  
  115.    /* write the number of output elements in hStat    */
  116.    wsprintf( (LPSTR) buff, "%d items", noutpel );
  117.    SendMessage( hStatEl, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  118.  
  119.    wsprintf( (LPSTR) buff, "%d selected", tsel );
  120.    SendMessage( hStatDat, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  121.  
  122.    /* initialize IDC_SEPAR                            */
  123.    SendMessage( hSep, CB_INSERTSTRING, -1, (DWORD)(LPSTR) "space" );
  124.    SendMessage( hSep, CB_INSERTSTRING, -1, (DWORD)(LPSTR) "comma" );
  125.    SendMessage( hSep, CB_INSERTSTRING, -1, (DWORD)(LPSTR) "tab" );
  126.    wsprintf( (LPSTR) buff, "%s",
  127.              (options.datsep==0) ? (LPSTR) "space" :
  128.              (options.datsep==1) ? (LPSTR) "comma" :
  129.              (LPSTR) "tab" );
  130.    SendMessage( hSep, CB_SELECTSTRING, -1, (DWORD)(LPSTR) buff );
  131.  
  132.    /* initialize IDC_WIDTH                            */
  133.    for( i=8; i<=25; i++ )
  134.    {
  135.     wsprintf( (LPSTR) buff, "%d", i );
  136.     SendMessage( hWidth, CB_INSERTSTRING, -1, (DWORD)(LPSTR) buff );
  137.    }
  138.    SendMessage( hWidth, CB_SETCURSEL, (WORD) (options.datwidth-8), 0 );
  139.  
  140.    /* initialize "Apply to"                            */
  141.    if( options.dyn && options.ss )
  142.     SendDlgItemMessage( hDlg, IDRB_3E+options.datss,  BM_SETCHECK, (WORD) 1, 0 );
  143.    else
  144.    {
  145.     if( !options.dyn )
  146.     {
  147.      hRadio = GetDlgItem( hDlg, IDRB_3E );
  148.      SendMessage( hRadio, BM_SETCHECK, 0, 0 );
  149.      EnableWindow( hRadio, FALSE );
  150.      options.datss = 1;
  151.      SendDlgItemMessage( hDlg, IDRB_3I,  BM_SETCHECK, (WORD) 1, 0 );
  152.     }
  153.     if( !options.ss )
  154.     {
  155.      hRadio = GetDlgItem( hDlg, IDRB_3I );
  156.      SendMessage( hRadio, BM_SETCHECK, 0, 0 );
  157.      EnableWindow( hRadio, FALSE );
  158.      options.datss = 0;
  159.      SendDlgItemMessage( hDlg, IDRB_3E,  BM_SETCHECK, (WORD) 1, 0 );
  160.     }
  161.    }
  162.  
  163.    /* set the check on the appropriate radio button    */
  164.    SendDlgItemMessage( hDlg, IDRB_0E+options.dattit, BM_SETCHECK, (WORD) 1, 0 );
  165.    SendDlgItemMessage( hDlg, IDRB_2E+options.datmca, BM_SETCHECK, (WORD) 1, 0 );
  166.  
  167.    SendDlgItemMessage( hDlg, IDRB_9I, BM_SETCHECK, (WORD) options.append, 0 );
  168.    SendDlgItemMessage( hDlg, IDRB_9E, BM_SETCHECK, (WORD) options.quotes, 0 );
  169.  
  170.    /* set the filename                                 */
  171.    SendMessage( hFName, WM_SETTEXT, 0, (DWORD)(LPSTR) DTitle );
  172.  
  173.    InvalidateRect( hDlg, NULL, FALSE );
  174.    return TRUE;
  175.  
  176.   case WM_COMMAND:
  177.    switch(wParam)
  178.    {
  179.     case IDC_PARAMLST:
  180.      if( HIWORD( lParam ) == LBN_DBLCLK )
  181.      {
  182.       /* get the index of the element selected                    */
  183.       nsel = (int) SendMessage( hAvail, LB_GETCURSEL, 0, 0 );
  184.       if( nsel != LB_ERR )
  185.        if( oel[nsel].idx == 0 )
  186.        {
  187.         oel[nsel].idx = tsel+1;
  188.         tsel++;
  189.         AddElLst( hDatLst, oel, nsel, TRUE );
  190.         SendMessage( hDatLst, LB_SETCURSEL, (WORD) tsel, 0 );
  191.         wsprintf( (LPSTR) buff, "%d selected", tsel );
  192.         SendMessage( hStatDat, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  193.        }
  194.       return TRUE;
  195.      }
  196.      else return FALSE;
  197.  
  198.     case IDC_DAT:
  199.      if( HIWORD( lParam ) == LBN_DBLCLK )
  200.      {
  201.       /* get the index of the element selected                    */
  202.       nsel = (int) SendMessage( hDatLst, LB_GETCURSEL, 0, 0 );
  203.       if( nsel != LB_ERR )
  204.       {
  205.        SendMessage( hDatLst, LB_DELETESTRING, (WORD) nsel, 0 );
  206.        for( i=0; i<noutpel; i++ )
  207.        {
  208.         if( oel[i].idx > (unsigned int) nsel+1) oel[i].idx--;
  209.         else if( oel[i].idx == (unsigned int) nsel+1) oel[i].idx = 0;
  210.        }
  211.        tsel--;
  212.        wsprintf( (LPSTR) buff, "%d selected", tsel );
  213.        SendMessage( hStatDat, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  214.       }
  215.       return TRUE;
  216.      }
  217.      else return FALSE;
  218.  
  219.     case IDC_DEL:
  220.      SendMessage( hDatLst, LB_RESETCONTENT, 0, 0 );
  221.      for( i=0; i<noutpel; i++ ) oel[i].idx = 0;
  222.      tsel = 0;
  223.      SendMessage( hStatDat, WM_SETTEXT, 0, (DWORD)(LPSTR) "0 selected" );
  224.      return TRUE;
  225.  
  226.     case IDC_UP:
  227.       nsel = (int) SendMessage( hDatLst, LB_GETCURSEL, 0, 0 );
  228.       if( (nsel>0) && (nsel != LB_ERR) )
  229.       {
  230.        SendMessage( hDatLst, LB_DELETESTRING, (WORD) nsel, 0 );
  231.        for( i=0; i<noutpel; i++ )
  232.        {
  233.         if( oel[i].idx == (unsigned int) nsel+1)
  234.         {
  235.          oel[i].idx--;
  236.          SendMessage( hDatLst, LB_INSERTSTRING, (WORD) nsel-1, (DWORD) oel[i].title );
  237.         }
  238.         else if( oel[i].idx == (unsigned int) nsel) oel[i].idx++;
  239.        }
  240.        SendMessage( hDatLst, LB_SETCURSEL, (WORD) nsel-1, 0 );
  241.       }
  242.      return TRUE;
  243.  
  244.     case IDC_HELP:            /* Help on this Dialog Box                */
  245.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Data file format" );
  246.         return TRUE;
  247.  
  248.     case IDC_FILE:
  249.      if( GetOFileName( hDlg,
  250.                          (LPSTR) &DName[0], sizeof( DName ),
  251.                         (LPSTR) "Simulation results data file",
  252.                          (LPSTR) "simulation results (*.DAT)\0*.DAT\0all files (*.*)\0*.*\0" ) )
  253.      {
  254.       GetFileTitle( (LPSTR) DName, (LPSTR) DTitle, sizeof(DTitle) );
  255.       SendMessage( hFName, WM_SETTEXT, 0, (DWORD)(LPSTR) DTitle );
  256.      }
  257.      return TRUE;
  258.  
  259.     case IDOK:
  260.      /* get the titles option                                            */
  261.      for( i=0; i<3; i++)
  262.       if( SendDlgItemMessage( hDlg, IDRB_0E+i, BM_GETCHECK, 0, 0 ) )
  263.        options.dattit = i;
  264.      /* get the quotes option */
  265.      if( SendDlgItemMessage( hDlg, IDRB_9E, BM_GETCHECK, 0, 0 ) )
  266.       options.quotes = 1;
  267.      else options.quotes = 0;
  268.      /* get the append option */
  269.      if( SendDlgItemMessage( hDlg, IDRB_9I, BM_GETCHECK, 0, 0 ) )
  270.       options.append = 1;
  271.      else options.append = 0;
  272.      /* get the MCA options                                                */
  273.      if( SendDlgItemMessage( hDlg, IDRB_2E, BM_GETCHECK, 0, 0 ) )
  274.       options.datmca = 0;
  275.      else options.datmca = 1;
  276.      /* get the MCA options                                                */
  277.      if( SendDlgItemMessage( hDlg, IDRB_3E, BM_GETCHECK, 0, 0 ) )
  278.       options.datss = 0;
  279.      else options.datss = 1;
  280.  
  281.      /* get the separator                                                */
  282.      options.datsep = (int) SendMessage( hSep, CB_GETCURSEL, 0, 0 );
  283.      /* get the width of columns                                        */
  284.      nsel = (int) SendMessage( hWidth, CB_GETCURSEL, 0, 0 );
  285.      options.datwidth = 8 + nsel;
  286.  
  287.      /* copy the number of selected from mirror                */
  288.      totsel = tsel;
  289.      /* copy params back from its mirror                                */
  290.      _fmemcpy( (void __far *) outpel,
  291.                (void __far *) oel,
  292.                (size_t) sizeoutp );
  293.      strcpy( DatName, DName );
  294.      strcpy( DatTitle, DTitle );
  295.      /* unlock and free the mirror memory block             */
  296.      GlobalUnlock( hOel );
  297.      GlobalFree( hOel );
  298.      /* signal that changes have been made                    */
  299.      notsaved = 1;
  300.      EndDialog(hDlg, TRUE);
  301.      return TRUE;
  302.  
  303.     case IDCANCEL:
  304.      /* unlock and free the mirror memory block             */
  305.      GlobalUnlock( hOel );
  306.      GlobalFree( hOel );
  307.      EndDialog(hDlg, FALSE);
  308.      return TRUE;
  309.    }    /* End of WM_COMMAND                                 */
  310.    return FALSE;
  311.  
  312.   default:
  313.    return FALSE;
  314.  }
  315. }
  316.  
  317.