home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / CUAPROC.C < prev    next >
Text File  |  1995-11-02  |  13KB  |  269 lines

  1. /*****************************************************************************/
  2. /* File:                                             IBM INTERNAL USE ONLY   */
  3. /*   cuaproc.c                                                               */
  4. /*                                                                           */
  5. /* Description:                                                              */
  6. /*                                                                           */
  7. /*   Cua process dialog functions.                                           */
  8. /*                                                                           */
  9. /*...Created 08/29/94                                                        */
  10. /*...                                                                        */
  11. /*****************************************************************************/
  12. #include "all.h"
  13. #include "diaproc.h"                    /* threads dialog data               */
  14.  
  15. #define PIDLEN       7                  /* process id field length.          */
  16.  
  17. /*****************************************************************************/
  18. /* - define frame overhead - 2 spaces for the scroll bar + 2 spaces          */
  19. /*                           for the left and right sides.                   */
  20. /*****************************************************************************/
  21. #define FRAME_OVER_HEAD   6
  22.  
  23. extern uchar   VideoAtr;                /* logical screen attribute          */
  24. extern uchar   ScrollShade1[];          /* scroll bar attributes          701*/
  25. extern uchar   ScrollShade2[];          /* scroll bar attributes          701*/
  26. extern uchar   hilite[];                /* high light field attributes    701*/
  27. extern uchar   normal[];                /* normal field attributes        701*/
  28. extern uchar   ClearField[];            /* clear field attributes         701*/
  29.  
  30. static uchar Header[] = " Pid    Filename";
  31.  
  32. /*****************************************************************************/
  33. /* Cua_showproc()                                                            */
  34. /*                                                                           */
  35. /* Description:                                                              */
  36. /*                                                                           */
  37. /*  Calls functions to handle the process dialog.                            */
  38. /*                                                                           */
  39. /* Parameters:                                                               */
  40. /*                                                                           */
  41. /* Return:                                                                   */
  42. /*****************************************************************************/
  43. void Cua_showproc( void )
  44. {
  45.   GetScrAccess();
  46.   DisplayDialog( &Dia_Proc, TRUE );
  47.   ProcessDialog( &Dia_Proc, &Dia_Proc_Choices, TRUE, NULL );
  48.   RemoveDialog( &Dia_Proc );
  49.   SetScrAccess();
  50.   return;
  51. }
  52.  
  53. /*****************************************************************************/
  54. /* DisplayProcChoice()                                                    701*/
  55. /*                                                                           */
  56. /* Description:                                                              */
  57. /*                                                                           */
  58. /*   Displays the Thread names and other related information in the dialog   */
  59. /* window.                                                                   */
  60. /*                                                                           */
  61. /* Parameters:                                                               */
  62. /*                                                                           */
  63. /*   shell   ->  pointer to a dialog shell structure.                        */
  64. /*   ptr     ->  pointer to a dialog choice structure.                       */
  65. /*                                                                           */
  66. /* Return:                                                                   */
  67. /*   none                                                                    */
  68. /*****************************************************************************/
  69. void  DisplayProcChoice( DIALOGSHELL *shell, DIALOGCHOICE *ptr )
  70. {
  71.   uint     i;
  72.   uint     StartIndex;
  73.   ALLPIDS *pPid;
  74.   char    *cp;
  75.   int      len;
  76.   int      bufsize;
  77.   int      FileNameFieldLen;
  78.   char    *pbuf;
  79.  
  80.   /***************************************************************************/
  81.   /* - allocate memory needed for a single display row.                      */
  82.   /* - define the size of the filename field.                                */
  83.   /***************************************************************************/
  84.   bufsize = shell->width - FRAME_OVER_HEAD;
  85.  
  86.   FileNameFieldLen = bufsize - PIDLEN ;
  87.               pbuf = Talloc( bufsize + 1 );   /* add one for terminating \0. */
  88.  
  89.   /***************************************************************************/
  90.   /* Put the header text and init variables.                                 */
  91.   /***************************************************************************/
  92.   putrc( shell->row + 2, shell->col + 1, Header );
  93.   StartIndex = 1;
  94.  
  95.   /***************************************************************************/
  96.   /* Advance the startindex and -> to process node depending on the skip rows*/
  97.   /***************************************************************************/
  98.   pPid    = GetAllpids();
  99.   for( i = 0; i < ptr->SkipRows; i++ )
  100.   {
  101.     pPid = pPid->next;
  102.     StartIndex++;
  103.   }
  104.  
  105.   /***************************************************************************/
  106.   /* Display the rows that can fit in the window.                            */
  107.   /***************************************************************************/
  108.   for( i = 0; i < ptr->MaxRows; i++, StartIndex++ )
  109.   {
  110.     /*************************************************************************/
  111.     /* Clear the display buffer.                                             */
  112.     /*************************************************************************/
  113.     memset( pbuf, ' ', bufsize );
  114.     if( StartIndex <= ptr->entries )
  115.     {
  116.       /**********************************************************************/
  117.       /*  - Put the pid and name into the buffer using this layout:         */
  118.       /*                                                                    */
  119.       /*   PIDLEN FILENAMELEN                                               */
  120.       /*   |     ||                                                         */
  121.       /*   Pid----Filename----------------------------------------          */
  122.       /*             1112222222222333333333344444444445555555555666         */
  123.       /*   01234567890123456789012345678901234567890123456789012345         */
  124.       /**********************************************************************/
  125.       sprintf( pbuf, "%-6d ", pPid->pid );
  126.  
  127.       cp  = pPid->pFileSpec;
  128.       len = strlen(cp);
  129.       if( len > FileNameFieldLen )
  130.       {
  131.        cp += strlen(cp);
  132.        cp -= FileNameFieldLen;
  133.       }
  134.       strncpy( pbuf+PIDLEN, cp, strlen(cp) );
  135.  
  136.       /***********************************************************************/
  137.       /* - add the buffer termination.                                       */
  138.       /***********************************************************************/
  139.       pbuf[bufsize] = '\0';
  140.  
  141.       /***********************************************************************/
  142.       /* bump to the next process.                                           */
  143.       /***********************************************************************/
  144.       pPid = pPid->next;
  145.     }
  146.     putrc( shell->row + i + shell->SkipLines, shell->col + 2, pbuf );
  147.   }                                                /*      |                */
  148.   Tfree( pbuf );                                    /*      |                */
  149. }                                                  /* offset from left frame*/
  150.  
  151. /*****************************************************************************/
  152. /*                                                                           */
  153. /* ProcessDialogFunction()                                                   */
  154. /*                                                                           */
  155. /* Description:                                                              */
  156. /*                                                                           */
  157. /* This is the function called by ProcessDialog (in pulldown.c) whenever an  */
  158. /* event occurs in the dialog. This fuction handles the events in a way      */
  159. /* specific to this dialog.                                                  */
  160. /*                                                                           */
  161. /* Parameters:                                                               */
  162. /*                                                                           */
  163. /*   shell         input  - Pointer to DIALOGSHELL structure.                */
  164. /*   ptr           input  - Pointer to DIALOGCHOICE structure.               */
  165. /*   nEvent        input  - Pointer to EVENT structure.                      */
  166. /*                                                                           */
  167. /* Return:                                                                   */
  168. /*        = 0     - The caller has to continue processing the dialog.        */
  169. /*       != 0     - The caller can terminate processing the dialog.          */
  170. /*****************************************************************************/
  171. uint  ProcessDialogFunction( DIALOGSHELL *shell, DIALOGCHOICE *ptr,
  172.                              EVENT *nEvent, void *ParamBlock )
  173. {
  174.   int     SelectIndex;
  175.   ALLPIDS *plastproc;
  176.  
  177.  
  178.   SelectIndex = shell->CurrentField + ptr->SkipRows;
  179.   ptr->entries = 0;
  180.   plastproc = GetAllpids( );
  181.  
  182.   while( plastproc != NULL )
  183.   {
  184.    ptr->entries++;
  185.    plastproc = plastproc->next;
  186.   }
  187.  
  188.   switch( nEvent->Value )
  189.   {
  190.     case INIT_DIALOG:
  191.     {
  192.       /*********************************************************************/
  193.       /* This message is sent before displaying elements in display area.  */
  194.       /* It is to initialise the locals in the dialog function.            */
  195.       /*  - Set the field cursor and variables to the first field.         */
  196.       /*  - Set the length of the field highlite bar in normal and hilite  */
  197.       /*    arrays (used in the call to putrc).                            */
  198.       /*  - Return zero to denote continue dialog processing.              */
  199.       /*********************************************************************/
  200.       hilite[1] = normal[1] = (UCHAR)shell->width - SCROLLBARCOLOFFSET - 2;
  201.       putrc( shell->row + 2, shell->col + 2, Header );
  202.       return( 0 );
  203.     }
  204.  
  205.     case ENTER:
  206.      /************************************************************************/
  207.      /* This message is sent if the user clicks on the ENTER button or       */
  208.      /* presses the ENTER key.                                               */
  209.      /*  - Return non zero value to denote the end of dialog processing.     */
  210.      /************************************************************************/
  211.      {
  212.       ALLPIDS         *pGoTo;
  213.       ALLPIDS         *pThisPid;
  214.       DBG_QUE_ELEMENT  Qelement;
  215.       USHORT           ThisPid;
  216.       USHORT           GoToPid;
  217.  
  218.       ThisPid  = (ULONG)DbgGetProcessID();
  219.       pThisPid = GetPid( ThisPid );
  220.  
  221.       pGoTo    = GetPidIndex( SelectIndex );
  222.       GoToPid  = pGoTo->pid;
  223.  
  224.       if( GoToPid != ThisPid )
  225.       {
  226.        Qelement.pid = GoToPid;
  227.        Qelement.sid = ThisPid;
  228.  
  229.        if( (SerialParallel() == SERIAL) && (pGoTo->PidFlags.Executing==FALSE) )
  230.        {
  231.         Qelement.DbgMsgFlags.InformEsp = INFORM_ESP;
  232.  
  233.         SetConnectSema4( &pThisPid->ConnectSema4, FALSE );
  234.  
  235.         SendMsgToDbgQue( DBG_QMSG_CONNECT_ESP, &Qelement, sizeof(Qelement) );
  236.        }
  237.        Qelement.pid = GoToPid;
  238.        SendMsgToDbgQue( DBG_QMSG_SELECT_SESSION, &Qelement, sizeof(Qelement) );
  239.       }
  240.       ptr->SkipRows = 0;
  241.       return( ENTER );
  242.      }
  243.  
  244.     case F1:
  245.     {
  246.       uchar  *HelpMsg;
  247.  
  248.       HelpMsg = GetHelpMsg( HELP_DLG_PROCESSES, NULL,0 );
  249.       CuaShowHelpBox( HelpMsg );
  250.       return( 0 );
  251.     }
  252.  
  253.     case ESC:
  254.     case F10:
  255.     {
  256.       /*********************************************************************/
  257.       /* This message is sent if the user clicks on the CANCEL button or   */
  258.       /* presses the ESC/F10 keys.                                         */
  259.       /*  - Return non zero value to denote the end of dialog processing.  */
  260.       /*********************************************************************/
  261.       ptr->SkipRows = 0;
  262.       return( nEvent->Value );
  263.     }
  264.  
  265.     default:
  266.      return( 0 );
  267.   }
  268. }
  269.