home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / biology / gsrc208a.zip / EDUDKT.C < prev    next >
C/C++ Source or Header  |  1992-11-24  |  9KB  |  303 lines

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