home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opmsam.zip / PRINTDLG.CPP < prev    next >
C/C++ Source or Header  |  1993-07-15  |  3KB  |  136 lines

  1. /*  VCS_ID
  2.  *  $Filename:   printdlg.cxx
  3.  *  $Author  :   John Pompeii
  4.  *  $Revision:   1.1  $
  5.  *  $Date:   28 Dec 1991 14:18:36  $
  6.  */
  7.  
  8. extern "C"
  9. {
  10.     #include <stdio.h>
  11. }
  12.  
  13. #define InclForms
  14. #define InclPrinters
  15. #define InclProfiles
  16.  
  17. #include <ObjectPM.hpp>
  18. #include "printdlg.hpp"
  19.  
  20. // This class implements a dialog for choosing a printer.  This dialog
  21. // is implemented using the FormsManager.  
  22.  
  23. PrintDlg :: PrintDlg(wWindow *parent, wPrinterSetup *_origSetup) : wFormWindow (D_PRINTERS, 1, 1, DlgModal)
  24. {
  25.     wButtonField *bfldp;
  26.  
  27.     AddField( bfldp = new wPushButtonField(B_JOBPROP) );
  28.     bfldp->SetFieldClickFn(FORMMETHOD(PrintDlg,ProcJobProperties));
  29.  
  30.     AddListRegion( prLReg = new wListRegion(L_PRINTERLIST, LrNoClear | LrNoDelete) );
  31.  
  32.     // define the list-box columns
  33.  
  34.     prLReg->SetIndent(8);
  35.     prLReg->AddGroupObject(NULL, 62);
  36.     prLReg->AddGroupObject(NULL, 4, ColBlank);
  37.     prLReg->AddGroupObject(NULL, 154);
  38.     prLReg->AddGroupObject(NULL, 4, ColBlank);
  39.     prLReg->AddGroupObject(NULL, 40);
  40.  
  41.     SetActionButtons(B_CANCEL, B_OK, NULL);
  42.     origSetup = _origSetup;
  43.     currSetup = _origSetup;
  44.     currPrinter = -1;
  45.     fChanged = FALSE;
  46.  
  47.     FormUp(parent);
  48. }
  49.  
  50. PrintDlg :: ~PrintDlg()
  51. {
  52.     delete prlist;
  53. }
  54.  
  55. short PrintDlg :: Init()
  56. {
  57.     HourGlass();
  58.     wPrinterInfo pi;
  59.  
  60.     prlist = pi.EnumPrintDestinations();
  61.  
  62.     if (!prlist || !prlist->Entries())
  63.     {
  64.         DisableActionButton();
  65.         GetField(B_JOBPROP)->Disable();
  66.     }
  67.     else
  68.     {
  69.         char buf[80];
  70.         short i = 0;
  71.  
  72.         for (prlist->First(); prlist->Current(); prlist->Next(), i++)
  73.         {
  74.             wPrinterSetup *p = prlist->Current();
  75.             sprintf(buf, "%s!T%s!T%s", (const char *)p->GetPhysicalName(), 
  76.                     (const char *)p->GetObjectName(), 
  77.                     (const char *)p->GetPort());
  78.  
  79.             prLReg->InsertItemText(buf);
  80.  
  81.             if (origSetup->GetPort() == p->GetPort())
  82.                 currPrinter = i;
  83.         }
  84.         if (currPrinter >= 0)
  85.             prLReg->SelectItem(currPrinter);
  86.     }
  87.     HourGlass();
  88.     return TRUE;
  89. }
  90.  
  91. short PrintDlg :: ProcJobProperties(wButtonField *)
  92. {
  93.     short item = prLReg->GetCurrentItem();
  94.     if (item != currPrinter)
  95.      {
  96.          currSetup = (*prlist)[item];
  97.         currPrinter = item;
  98.     }
  99.     fChanged++;
  100.  
  101.     currSetup->PostJobProperties();
  102.     return TRUE;
  103. }
  104.  
  105. short PrintDlg :: Save()
  106. {
  107.     short item = prLReg->GetCurrentItem();
  108.     if (item != currPrinter)
  109.      {
  110.          currSetup = (*prlist)[item];
  111.         fChanged++;
  112.     }
  113.  
  114.     if (currSetup != origSetup)
  115.     {
  116.         // remove the PrinterSetup object from the list
  117.         // to prevent it from being deleted when "prlist" is
  118.         // deleted in our constructor
  119.  
  120.         if (prlist->Find(currSetup))
  121.             prlist->Remove();
  122.  
  123.         delete origSetup;
  124.     }
  125.  
  126.     return TRUE;
  127. }
  128.  
  129. short PrintDlg :: ConfirmQuit()
  130. {
  131.     currSetup = origSetup;
  132.     fChanged = FALSE;
  133.  
  134.     return TRUE;
  135. }
  136.