home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / sysutils / mshell / source / dlg.c < prev    next >
Text File  |  1993-10-16  |  8KB  |  268 lines

  1. // dlg.c  - dialog procs
  2.  
  3. // os2 includes
  4. #define INCL_PM
  5. #define INCL_SPL
  6. #define INCL_SPLDOSPRINT
  7. #include <os2.h>
  8.  
  9. // c includes
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. // app includes
  15. #include "def.h"
  16. #include "mshell.h"
  17. #include "pmassert.h"
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26. // ----------------------------------------------------------------------
  27. // at pch, put a J for job, Q for queue
  28. // return the index of the item selected or LIT_NONE if none
  29.  
  30.  
  31. #define LEN_SHORTWORK  32
  32. #define IS_NONE         0
  33. #define IS_QUEUE        1
  34. #define IS_JOB          2
  35.  
  36. LONG WhichSelected( HWND hwndListbox, PULONG pulWhich, PULONG pulJob, PSZ pszQueue )
  37. {
  38.   LONG  iSel;
  39.   int   i;
  40.   char  szWork[ LEN_SHORTWORK ];
  41.   PCHAR pch;
  42.  
  43.  
  44.   // firewalls
  45.   *pszQueue = 0;
  46.  
  47.  
  48.   iSel = (LONG) WinSendMsg( hwndListbox, LM_QUERYSELECTION, (MPARAM)LIT_FIRST, 0 );
  49.   if( LIT_NONE == iSel ) {
  50.     *pulWhich = IS_NONE;
  51.   } else {
  52.     WinSendMsg( hwndListbox, LM_QUERYITEMTEXT, MPFROM2SHORT( (SHORT)iSel, LEN_SHORTWORK-1 ), (MPARAM)szWork );
  53.     switch( *szWork ) {
  54.     case ' ':
  55.       // jobs have a blank as the first char on the line;
  56.       // figure out job number
  57.       // figure out what queue this job is in
  58.       *pulWhich = IS_JOB;
  59.       szWork[ LEN_SHORTWORK-1 ] = 0;
  60.       *pulJob = atol( szWork );
  61.       pmassert( (HAB)0, *pulJob );
  62.       // walk back up the job until I find the queue for it
  63.       for( i = iSel-1; i > -1; i-- ) {
  64.         WinSendMsg( hwndListbox, LM_QUERYITEMTEXT, MPFROM2SHORT( (SHORT)i, LEN_SHORTWORK-1 ), (MPARAM)szWork );
  65.         if( *szWork != ' ' ) {
  66.           // found the queue name
  67.           pch = strchr( szWork, ' ' );
  68.           *pch = 0;
  69.           strcpy( pszQueue, szWork );
  70.           break;
  71.         }
  72.       }
  73.       pmassert( (HAB)0,  *pszQueue );
  74.       break;
  75.     default:          // otherwise it is a queue; figure out queue name
  76.       *pulWhich = IS_QUEUE;
  77.       pch = strchr( szWork, ' ' );
  78.       *pch = 0;
  79.       strcpy( pszQueue, szWork );
  80.       break;
  81.     }
  82.   }
  83.   return iSel;
  84. }
  85.  
  86.  
  87. // ----------------------------------------------------------------------
  88.  
  89. MRESULT EXPENTRY SpoolerDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  90. {
  91.   CHAR           szWork[ LEN_WORKSTRING ];
  92.   PGLOBALS       pg;
  93.   PPRJINFO2      pj2;
  94.   PPRQINFO3      pq3;
  95.   PSZ            pszStatus;
  96.   PVOID          pvBuffer;
  97.   ULONG          ulJob;
  98.   ULONG          cReturned;
  99.   ULONG          cTotal;
  100.   ULONG          cbNeeded;
  101.   ULONG          rc;
  102.   ULONG          ul;
  103.   int            i, j;
  104.   static PSZ     pszJobPaused   = "Paused";
  105.   static PSZ     pszJobPrinting = "Printing";
  106.   static PSZ     pszJobSpooling = "Job spooling";
  107.   static PSZ     pszQueueError  = "Queue Error";
  108.   static PSZ     pszQueuePaused = "Queue Paused";
  109.   static PSZ     pszReady       = "";
  110.   static HWND    hwndListbox;
  111.  
  112.   switch( msg ) {
  113.   case WM_INITDLG:
  114.     // store the pointer to globals that is coming in in mp2 in window words
  115.     pg = (PGLOBALS) mp2;
  116.     WinSetWindowULong( hwnd, QWL_USER, (ULONG) pg );
  117.     // for simplicity, use a mono-spaced font in listbox
  118.     hwndListbox = WinWindowFromID( hwnd, IDC_LISTBOX );
  119.     pmassert( pg->hab, hwndListbox );
  120.     strcpy(  szWork, "10.Courier"  );
  121.     WinSetPresParam( hwndListbox, PP_FONTNAMESIZE, strlen( szWork )+1, szWork );
  122.     break;
  123.  
  124.  
  125.   case WM_COMMAND:
  126.     switch( SHORT1FROMMP( mp1 )) {
  127.     case IDC_REFRESH:
  128.       // need to enumerate queues; call to get size needed
  129.       rc = SplEnumQueue( NULL,          // local machine
  130.                          4,             // info level
  131.                          NULL,          // pvBuffer in next call
  132.                          0,             // count of bytes in pvBuffer
  133.                          &cReturned,    // number of queues returned
  134.                          &cTotal,       // total number of queues
  135.                          &cbNeeded,     // number bytes needed to store
  136.                          NULL );        // reserved
  137.  
  138.       if( 0 == cTotal ) {
  139.         // this system has no printers defined
  140.         WinMessageBox( HWND_DESKTOP, hwnd, "You have no printers defined.", CAPTION, 0, MB_CANCEL );
  141.         return FALSE;
  142.       }
  143.       // allocate memory to store the enumerated queue information
  144.       pvBuffer = malloc( cbNeeded ) ;
  145.       pmassert( pg->hab, pvBuffer );
  146.       // call to get data for real
  147.       rc = SplEnumQueue( NULL, 4, pvBuffer, cbNeeded, &cReturned, &cTotal, &cbNeeded, NULL );
  148.       pmassert( pg->hab, 0 == rc );
  149.       // disable listbox painting
  150.       WinEnableWindowUpdate( hwndListbox, FALSE );
  151.       // delete all items currently in the listbox
  152.       WinSendMsg( hwndListbox, LM_DELETEALL, 0, 0 );
  153.       // walk the buffer returned; see page 7-36 PM Prog Ref Vol 1 for OS2 2.0
  154.       pq3 = (PPRQINFO3)pvBuffer;
  155.       for( i=0; i < cReturned; i++ ) {
  156.         // figure out queue status
  157.         switch( PRQ_STATUS_MASK & pq3->fsStatus ) {
  158.         case  PRQ_ACTIVE:
  159.           pszStatus = pszReady;
  160.           break;
  161.         case  PRQ_PAUSED:
  162.           pszStatus = pszQueuePaused;
  163.           break;
  164.         case  PRQ_ERROR:
  165.         case  PRQ_PENDING:
  166.           pszStatus = pszQueueError;
  167.           break;
  168.         }
  169.         sprintf( szWork, "%-12s %4d job(s) %s", pq3->pszName, pq3->cJobs, pszStatus  );
  170.         WinSendMsg( hwndListbox, LM_INSERTITEM, (MPARAM) LIT_END, (MPARAM) szWork );
  171.         // snag a local copy of job count
  172.         ulJob = pq3->cJobs;
  173.         // bump queue pointer up one; this makes it point to the first job info for this queue
  174.         // except in the case where cJobs is zero, then it points to next queue
  175.         pq3++;
  176.         pj2 = (PPRJINFO2)pq3;
  177.         for( j=0; j < ulJob; j++ ) {
  178.           // figure out job status
  179.           switch( 0x0003 & pj2->fsStatus ) {
  180.           case 1:
  181.             pszStatus = pszJobPaused;
  182.             break;
  183.           case 2:
  184.             pszStatus = pszJobSpooling;
  185.             break;
  186.           case 3:
  187.             pszStatus = pszJobPrinting;
  188.             break;
  189.           default:
  190.             pszStatus = pszReady;
  191.             break;
  192.           }
  193.           sprintf( szWork, "%5d %-10s %-10s %s",  pj2->uJobId, pj2->pszDocument, pj2->pszComment, pszStatus );
  194.           WinSendMsg( hwndListbox, LM_INSERTITEM, (MPARAM) LIT_END, (MPARAM) szWork );
  195.           pj2++;
  196.         }
  197.         // job pointer pj2 now points past jobs and at the next queue
  198.         pq3 = (PPRQINFO3)pj2;
  199.       }
  200.       // enable listbox painting
  201.       WinEnableWindowUpdate( hwndListbox, TRUE  );
  202.       // done with this memory for now
  203.       free( pvBuffer );
  204.       return (MRESULT) 0;
  205.  
  206.  
  207.     case IDC_HOLD:
  208.       WhichSelected( hwndListbox, &ul, &ulJob, szWork );
  209.       switch( ul ) {
  210.       case IS_NONE:
  211.         break;
  212.       case IS_QUEUE:
  213.         SplHoldQueue( NULL, szWork );
  214.         break;
  215.       case IS_JOB:
  216.         SplHoldJob( NULL, szWork, ulJob );
  217.         break;
  218.       }
  219.       WinPostMsg( hwnd, WM_COMMAND, (MPARAM)IDC_REFRESH, 0 );
  220.       return (MRESULT) 0;
  221.  
  222.  
  223.  
  224.     case IDC_RELEASE:
  225.       WhichSelected( hwndListbox, &ul, &ulJob, szWork );
  226.       switch( ul ) {
  227.       case IS_NONE:
  228.         break;
  229.       case IS_QUEUE:
  230.         SplReleaseQueue( NULL, szWork );
  231.         break;
  232.       case IS_JOB:
  233.         SplReleaseJob( NULL, szWork, ulJob );
  234.         break;
  235.       }
  236.       WinPostMsg( hwnd, WM_COMMAND, (MPARAM)IDC_REFRESH, 0 );
  237.       return (MRESULT) 0;
  238.  
  239.  
  240.  
  241.     case IDC_DELETE:
  242.       WhichSelected( hwndListbox, &ul, &ulJob, szWork );
  243.       switch( ul ) {
  244.       case IS_NONE:
  245.       case IS_QUEUE:
  246.         break;
  247.       case IS_JOB:
  248.         SplDeleteJob( NULL, szWork, ulJob );
  249.         break;
  250.       }
  251.       WinPostMsg( hwnd, WM_COMMAND, (MPARAM)IDC_REFRESH, 0 );
  252.       return (MRESULT) 0;
  253.  
  254.  
  255.  
  256.     case DID_OK:
  257.     case DID_CANCEL:
  258.       pg = (PGLOBALS) WinQueryWindowULong( hwnd, QWL_USER );
  259.       WinSetWindowPos( hwnd, (HWND)0, 0,0,0,0, SWP_HIDE | SWP_DEACTIVATE );
  260.       break;
  261.     }
  262.     return (MRESULT) 0;
  263.   }
  264.   return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  265. }
  266.  
  267.  
  268.