home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDSCANP.C < prev    next >
C/C++ Source or Header  |  1992-12-06  |  6KB  |  202 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. /*          Scan Parameters          */
  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( CODE7, AddPLst, str_cube, EdScanP)
  36.  
  37. void AddPLst( HWND hControl, int idx, BOOL scroll )
  38. {
  39.  int i;
  40.  WORD ElWidth;
  41.  HANDLE hDC;
  42.  
  43.  hDC = GetDC( hControl );
  44.  ElWidth = 5 + LOWORD( GetTextExtent( hDC, scp[idx].title, _fstrlen(scp[idx].title) ) );
  45.  SetTextJustification( hDC, 0, 0 );
  46.  ReleaseDC( hControl, hDC );
  47.  if( ElWidth > lbWidth )
  48.  {
  49.   lbWidth = ElWidth;
  50.   SendMessage( hControl, LB_SETHORIZONTALEXTENT, lbWidth, 0 );
  51.  }
  52.  SendMessage( hControl, LB_INSERTSTRING, -1, (DWORD) scp[idx].title );
  53.  if( scroll ) SendMessage( hControl, WM_VSCROLL, SB_BOTTOM, 0 );
  54. }
  55.  
  56. void str_cube( int tsel, LPSTR buff )
  57. {
  58.    switch( tsel )
  59.    {
  60.     case 0: wsprintf( buff, "0 selected" );
  61.             break;
  62.     case 1: wsprintf( buff, "line" );
  63.             break;
  64.     case 2: wsprintf( buff, "rectangle" );
  65.             break;
  66.     case 3: wsprintf( buff, "cube" );
  67.             break;
  68.     default:wsprintf( buff, "%dD hypercube", tsel );
  69.    }
  70. }
  71.  
  72. BOOL FAR PASCAL EdScanP(HWND hDlg, WORD Message, WORD wParam, LONG lParam)
  73. {
  74.  static int tsel;
  75.  static HWND hAvail, hSelect, hLow, hDimens,
  76.              hHigh, hDens, hTDens, hLog, hS1, hS2;
  77.  int  i, j, nsel, len;
  78.  char buff[128];
  79.  
  80.  switch(Message)
  81.  {
  82.   case WM_INITDIALOG:
  83.    /* allocate memory for the mirror                */
  84.    hScp = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, sizespar );
  85.    if( hScp == NULL )
  86.    {
  87.     LoadString(hInst, IDS_ERR_NOEXEC, szString, sizeof(szString));
  88.     MessageBox(hDlg, szString, NULL, MB_ICONEXCLAMATION);
  89.     EndDialog(hDlg, FALSE);
  90.     return TRUE;
  91.    }
  92.  
  93.    /* lock the memory block                            */
  94.    scp  = (struct sp huge *) GlobalLock( hScp );
  95.  
  96.    /* copy params to its mirror                                    */
  97.    _fmemcpy( (void __far *) scp,
  98.              (void __far *) spar,
  99.              (size_t) sizespar );
  100.  
  101.    /* get handles to controls                        */
  102.    hAvail = GetDlgItem( hDlg, IDC_PARAMLST );
  103.    hSelect = GetDlgItem( hDlg, IDC_SELECT );
  104.    hS1 = GetDlgItem( hDlg, IDSTAT_3 );
  105.    hS2 = GetDlgItem( hDlg, IDSTAT_4 );
  106.  
  107.    /* initialize hAvail: add all output elements    */
  108.    for( i=0, lbWidth=0; i<nscanpar; i++ )
  109.     AddPLst( hAvail, i, FALSE );
  110.  
  111.    /* copy the number of selected to mirror            */
  112.    tsel = totscan;
  113.    /* initialize hSelect: add all selected elements    */
  114.    for( i=0, lbWidth=0; i<tsel; i++ )
  115.     for( j=0; j<nscanpar; j++ )
  116.      if( (scp[j].idx-1) ==  i )
  117.       AddPLst( hSelect, j, TRUE );
  118.    /* show number of available parameters            */
  119.    wsprintf( (LPSTR) buff, "%d available", nscanpar );
  120.    SendMessage( hS2, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  121.    /* show the dimensions of the hypercube            */
  122.    str_cube( tsel, (LPSTR) buff );
  123.    SendMessage( hS1, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  124.  
  125.    InvalidateRect( hDlg, NULL, FALSE );
  126.    return TRUE;
  127.  
  128.   case WM_COMMAND:
  129.    switch(wParam)
  130.    {
  131.     case IDC_PARAMLST:
  132.      if( HIWORD( lParam ) == LBN_DBLCLK )
  133.      {
  134.       /* get the newly selected element in the available box        */
  135.       nsel = (int) SendMessage( hAvail, LB_GETCURSEL, 0, 0 );
  136.       if( nsel != LB_ERR )
  137.        if( scp[nsel].idx == 0 )
  138.        {
  139.         scp[nsel].idx = ++tsel;
  140.         AddPLst( hSelect, nsel, TRUE );
  141.         str_cube( tsel, (LPSTR) buff );
  142.         SendMessage( hS1, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  143.        }
  144.       return TRUE;
  145.      }
  146.      else return FALSE;
  147.  
  148.     case IDC_SELECT:
  149.      if( HIWORD( lParam ) == LBN_DBLCLK )
  150.      {
  151.       /* get the index of the element selected                    */
  152.       nsel = (int) SendMessage( hSelect, LB_GETCURSEL, 0, 0 );
  153.       if( nsel != LB_ERR )
  154.       {
  155.        SendMessage( hSelect, LB_DELETESTRING, (WORD) nsel, 0 );
  156.        for( i=0; i<nscanpar; i++ )
  157.        {
  158.         if( scp[i].idx > nsel+1) scp[i].idx--;
  159.         else if( scp[i].idx == nsel+1) scp[i].idx = 0;
  160.        }
  161.        tsel--;
  162.        str_cube( tsel, (LPSTR) buff );
  163.        SendMessage( hS1, WM_SETTEXT, 0, (DWORD)(LPSTR) buff );
  164.       }
  165.       return TRUE;
  166.      }
  167.      else return FALSE;
  168.  
  169.     case IDC_HELP:            /* Help on this Dialog Box                */
  170.         WinHelp( hDlg, (LPSTR) szHelpFile, HELP_KEY, (DWORD) (LPSTR) "Scan parameters" );
  171.      return TRUE;
  172.  
  173.     case IDOK:
  174.      /* copy the number of selected from mirror                */
  175.      totscan = tsel;
  176.      /* copy params back from its mirror                                */
  177.      _fmemcpy( (void __far *) spar,
  178.                (void __far *) scp,
  179.                (size_t) sizespar );
  180.      /* unlock and free the mirror memory block             */
  181.      GlobalUnlock( hScp );
  182.      GlobalFree( hScp );
  183.      /* signal that changes have been made                    */
  184.      notsaved = 1;
  185.      EndDialog(hDlg, TRUE);
  186.      return TRUE;
  187.  
  188.     case IDCANCEL:
  189.      /* unlock and free the mirror memory block             */
  190.      GlobalUnlock( hScp );
  191.      GlobalFree( hScp );
  192.      EndDialog(hDlg, FALSE);
  193.      return TRUE;
  194.    }    /* End of WM_COMMAND                                 */
  195.    return FALSE;
  196.  
  197.   default:
  198.    return FALSE;
  199.  }
  200. } /* End of METABMsgProc                                      */
  201.  
  202.