home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / GTakPM / Source / GTPMWin.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  12KB  |  388 lines

  1. // GTakPM
  2. // (c) Benjamin Stein 1994
  3. // All Rights Reserved
  4. // GTPMWin.cpp
  5.  
  6. // $Header: W:/Projects/OCL/Samples/GTakPM/Source/rcs/GTPMWin.cpp 1.50 1996/08/11 23:48:08 B.STEIN Release $
  7.  
  8.  
  9. #include "..\Source\GTakPM.hpp"
  10.  
  11.  
  12. GTPMWin::GTPMWin()
  13.  : OFrame(GTPM_ICO, 
  14.           FCF_SIZEBORDER | 
  15.           FCF_ICON | 
  16.           FCF_TASKLIST | 
  17.           FCF_SYSMENU | 
  18.           FCF_MINMAX | 
  19.           FCF_TITLEBAR | 
  20.           FCF_SHELLPOSITION,
  21.           CS_SIZEREDRAW | CS_HITTEST),
  22.    wasOutOfContainer(TRUE),
  23.    showMonitor(FALSE),
  24.    processing (FALSE),
  25.    toolbar    (NULL),
  26.    tapebar    (NULL),
  27.    monitor    (NULL),
  28.    Drives     (NULL),
  29.    Files      (NULL),
  30.    statline   (NULL),
  31.    frameMenu  (NULLHANDLE),
  32.    expander   (this, >PMWin::expandFolder, 65536), 
  33.    backupThr  (this, >PMWin::backup, 65536), 
  34.    restoreThr (this, >PMWin::restore, 65536), 
  35.    pmpipe     ((PSZ)NULL, (PSZ)NULL),
  36.    bmp_monitor   (HWND_DESKTOP, CMD_MONITOR,       NULLHANDLE, 32, 32),
  37.    bmp_rescan    (HWND_DESKTOP, CMD_RESCAN,        NULLHANDLE, 32, 32),
  38.    bmp_procedures(HWND_DESKTOP, CMD_PROCEDURES,    NULLHANDLE, 32, 32),
  39.    bmp_tape      (HWND_DESKTOP, CMD_TAPE,          NULLHANDLE, 32, 32),
  40.    bmp_backup    (HWND_DESKTOP, CMD_BACKUP,        NULLHANDLE, 32, 32),
  41.    bmp_restore   (HWND_DESKTOP, CMD_RESTORE,       NULLHANDLE, 32, 32),
  42.    bmp_compare   (HWND_DESKTOP, CMD_COMPARE,       NULLHANDLE, 32, 32),
  43.    bmp_settings  (HWND_DESKTOP, CMD_SETTINGS,      NULLHANDLE, 32, 32),
  44.    bmp_quit      (HWND_DESKTOP, CMD_QUIT,          NULLHANDLE, 32, 32),
  45.    bmp_load      (HWND_DESKTOP, TAPEBAR_LOAD,      NULLHANDLE, 32, 32),
  46.    bmp_unload    (HWND_DESKTOP, TAPEBAR_UNLOAD,    NULLHANDLE, 32, 32),
  47.    bmp_rewind    (HWND_DESKTOP, TAPEBAR_REWIND,    NULLHANDLE, 32, 32),
  48.    bmp_erase     (HWND_DESKTOP, TAPEBAR_ERASE,     NULLHANDLE, 32, 32),
  49.    bmp_eraseq    (HWND_DESKTOP, TAPEBAR_ERASEQ,    NULLHANDLE, 32, 32),
  50.    bmp_lock      (HWND_DESKTOP, TAPEBAR_LOCK,      NULLHANDLE, 32, 32),
  51.    bmp_unlock    (HWND_DESKTOP, TAPEBAR_UNLOCK,    NULLHANDLE, 32, 32),
  52.    bmp_stop_asap (HWND_DESKTOP, TAPEBAR_STOP_ASAP, NULLHANDLE, 32, 32),
  53.    btn_monitor   (CMD_MONITOR,       this, &bmp_monitor,    "Monitor on/off"),
  54.    btn_rescan    (CMD_RESCAN,        this, &bmp_rescan,     "Rescan Drives"),
  55.    btn_procedures(CMD_PROCEDURES,    this, &bmp_procedures, "Procedures"),
  56.    btn_tape      (CMD_TAPE,          this, &bmp_tape,       "Device Information"),
  57.    btn_backup    (CMD_BACKUP,        this, &bmp_backup,     "Backup"),
  58.    btn_restore   (CMD_RESTORE,       this, &bmp_restore,    "Restore"),
  59.    btn_compare   (CMD_COMPARE,       this, &bmp_compare,    "Compare"),
  60.    btn_settings  (CMD_SETTINGS,      this, &bmp_settings,   "Settings"),
  61.    btn_quit      (CMD_QUIT,          this, &bmp_quit,       "Quit"),
  62.    btn_load      (TAPEBAR_LOAD,      this, &bmp_load,       "Load"),
  63.    btn_unload    (TAPEBAR_UNLOAD,    this, &bmp_unload,     "Unload"),
  64.    btn_rewind    (TAPEBAR_REWIND,    this, &bmp_rewind,     "Rewind"),
  65.    btn_erase     (TAPEBAR_ERASE,     this, &bmp_erase,      "Erase"),
  66.    btn_eraseq    (TAPEBAR_ERASEQ,    this, &bmp_eraseq,     "Erase Quick"),
  67.    btn_lock      (TAPEBAR_LOCK,      this, &bmp_lock,       "Lock"),
  68.    btn_unlock    (TAPEBAR_UNLOCK,    this, &bmp_unlock,     "Unlock"),
  69.    btn_stop_asap (TAPEBAR_STOP_ASAP, this, &bmp_stop_asap,  "Stop current operation!")
  70. {
  71. #ifdef __TK21__
  72.  PSZ   tapeEnv;
  73. #else
  74.  PCSZ  tapeEnv;
  75. #endif 
  76.  
  77.  DosError(FERR_DISABLEHARDERR);
  78.  
  79.  if (!DosScanEnv("TAPE", &tapeEnv))
  80.    tape = new Tape(&pmpipe, (PSZ)tapeEnv, 0);
  81.  else
  82.    tape = new Tape(&pmpipe, "C:\\GTAKPM.TAR", 0);
  83.    
  84.  createFrame("GTakPM Develop");
  85.  
  86.  frameMenu = WinLoadMenu(frame, NULLHANDLE, GTPM_MENU);
  87.  if (!frameMenu)
  88.    throwGTPM(ERROR_LOAD_MENU);
  89.  
  90.  // setup toolbar
  91.  toolbar = new OButtonBar(GTPM_TOOLBAR, this);
  92.  toolbar->setButtonDimensions(40, 40); // set size of buttons
  93.  toolbar->setPicSize(32);              // set size of button pictures
  94.  toolbar->buttons.add(btn_monitor);
  95.  toolbar->buttons.add(btn_rescan);   
  96.  toolbar->buttons.add(btn_procedures);
  97.  toolbar->buttons.add(btn_tape);      
  98.  toolbar->buttons.add(btn_backup);    
  99.  toolbar->buttons.add(btn_restore);   
  100.  toolbar->buttons.add(btn_compare);   
  101.  toolbar->buttons.add(btn_settings);  
  102.  toolbar->createButtonBar();
  103.  
  104.  // setup tapebar
  105.  tapebar = new OButtonBar(GTPM_TAPEBAR, this);
  106.  tapebar->setButtonDimensions(40, 40); // set size of buttons
  107.  tapebar->setPicSize(32);              // set size of button pictures
  108.  tapebar->buttons.add(btn_quit);      
  109.  tapebar->buttons.add(btn_load);      
  110.  tapebar->buttons.add(btn_unload);    
  111.  tapebar->buttons.add(btn_rewind);    
  112.  tapebar->buttons.add(btn_erase);     
  113.  tapebar->buttons.add(btn_eraseq);    
  114.  tapebar->buttons.add(btn_lock);      
  115.  tapebar->buttons.add(btn_unlock);    
  116.  tapebar->buttons.add(btn_stop_asap); 
  117.  tapebar->createButtonBar();
  118.  
  119.  
  120. // setup statuslines
  121.  statline = new OStatusLine(GTPM_STATLINE, this, TRUE); 
  122.  statline->style |= FCF_BORDER;
  123.  statline->createStatusLine();
  124.  
  125. // setup listboxes
  126.  
  127.  Excludes = new OListBox(GTPM_EX, this, LS_NOADJUSTPOS | LS_HORZSCROLL);
  128.  Excludes->createListBox(0,0,0,0);
  129.  Excludes->setBackColor(SYSCLR_WINDOW); 
  130.  Excludes->setForeColor(SYSCLR_WINDOWTEXT);
  131.  Excludes->setFont("8.Helv");
  132.  
  133.  Includes = new OListBox(GTPM_INC, this, LS_NOADJUSTPOS | LS_HORZSCROLL);
  134.  Includes->createListBox(0,0,0,0);
  135.  Includes->setBackColor(SYSCLR_WINDOW);
  136.  Includes->setForeColor(SYSCLR_WINDOWTEXT);
  137.  Includes->setFont("8.Helv");
  138.  
  139.  monitor  = new OListBox(GTPM_MON, this, LS_NOADJUSTPOS | LS_HORZSCROLL, TRUE);
  140.  monitor->createListBox(0,0,0,0);
  141.  monitor->setBackColor(SYSCLR_WINDOW);
  142.  monitor->setForeColor(SYSCLR_WINDOWTEXT);
  143.  monitor->setFont("8.Helv");
  144.  
  145. // setup containers
  146.  
  147.  Drives = new DrivesCnr(this);
  148.  Drives->winText << ("Drives");
  149.  Drives->createContainer();
  150.  Drives->setBackColor(SYSCLR_WINDOW);
  151.  Drives->setForeColor(SYSCLR_WINDOWTEXT);
  152.  Drives->setFont("8.Helv");
  153.  
  154.  Files = new FilesCnr(this);
  155.  Files->winText << ("Files");
  156.  Files->createContainer();
  157.  Files->setBackColor(SYSCLR_WINDOW);
  158.  Files->setForeColor(SYSCLR_WINDOWTEXT);
  159.  Files->setFont("8.Helv");
  160.  
  161.  pmpipe.setNotify(this);
  162.  
  163. // ready
  164.  statline->setText("Ready");
  165. }
  166.  
  167.  
  168.  
  169. GTPMWin::~GTPMWin()
  170. {
  171.  if (Drives) delete Drives;
  172.  if (Files) delete Files;
  173.  if (toolbar) delete toolbar;
  174.  if (tapebar) delete tapebar;
  175.  if (statline) delete statline;
  176.  if (tape) delete tape;
  177.  if (monitor) delete monitor;
  178.    
  179.  
  180. void GTPMWin::resizeClients(MPARAM sizeparms)
  181. {
  182.  ULONG width      = SHORT1FROMMP(sizeparms);
  183.  ULONG height     = SHORT2FROMMP(sizeparms);
  184.  ULONG lineHeight, cnrHeight;
  185.  
  186.  if ((!statline) || (!toolbar) || 
  187.      (!Drives) || (!Files) || (!monitor) ||
  188.      (!Includes) || (!Excludes) || (!tapebar))
  189.     return;   // please don't trap!
  190.  
  191.  lineHeight = statline->getHeight();
  192.  cnrHeight = lineHeight + 3*tapebar->getHeight();
  193.  
  194. // set toolbar
  195.  WinSetWindowPos(toolbar->frame, HWND_TOP,
  196.                  0,
  197.                  height - toolbar->getHeight(),
  198.                  width, 
  199.                  toolbar->getHeight(),
  200.                  SWP_SIZE | SWP_MOVE);
  201.  
  202. // set tapebar
  203.  WinSetWindowPos(tapebar->frame, HWND_TOP,
  204.                  0,
  205.                  lineHeight,
  206.                  width, 
  207.                  tapebar->getHeight(),
  208.                  SWP_SIZE | SWP_MOVE);
  209.  
  210. // set includes LB
  211.  WinSetWindowPos(Includes->hwnd, HWND_TOP,
  212.                  0,
  213.                  lineHeight + tapebar->getHeight(),
  214.                  width/2, 
  215.                  2*tapebar->getHeight(),
  216.                  SWP_SIZE | SWP_MOVE);
  217.  
  218. // set excludes LB
  219.  WinSetWindowPos(Excludes->hwnd, HWND_TOP,
  220.                  width/2,
  221.                  lineHeight + tapebar->getHeight(),
  222.                  width/2, 
  223.                  2*tapebar->getHeight(),
  224.                  SWP_SIZE | SWP_MOVE);
  225.  
  226. // set statline
  227.  WinSetWindowPos(statline->frame, HWND_TOP, 
  228.                  0, 
  229.                  0,
  230.                  width,
  231.                  lineHeight,
  232.                  SWP_SIZE | SWP_MOVE);
  233. if ((!processing) && (!showMonitor)) {
  234.   // set Drives
  235.    WinSetWindowPos(Drives->hwnd, HWND_TOP,
  236.                    0,
  237.                    cnrHeight,
  238.                    width/2,
  239.                    height - toolbar->getHeight() - cnrHeight,
  240.                    SWP_SIZE | SWP_MOVE);
  241.   // set Files
  242.    WinSetWindowPos(Files->hwnd, HWND_TOP,
  243.                    width/2,
  244.                    cnrHeight,
  245.                    width/2,
  246.                    height - toolbar->getHeight() - cnrHeight,
  247.                    SWP_SIZE | SWP_MOVE);
  248.   // set monitor LB
  249.    WinSetWindowPos(monitor->hwnd, HWND_TOP,
  250.                    0, 0, 0, 0,
  251.                    SWP_SIZE | SWP_MOVE); }
  252.  else {
  253.   // set Drives
  254.    WinSetWindowPos(Drives->hwnd, HWND_TOP,
  255.                    0, 0, 0, 0,
  256.                    SWP_SIZE | SWP_MOVE);
  257.   // set Files
  258.    WinSetWindowPos(Files->hwnd, HWND_TOP,
  259.                    0, 0, 0, 0,
  260.                    SWP_SIZE | SWP_MOVE);
  261.   // set monitor LB
  262.    WinSetWindowPos(monitor->hwnd, HWND_TOP,
  263.                    0,
  264.                    cnrHeight,
  265.                    width, 
  266.                    height - toolbar->getHeight() - cnrHeight,
  267.                    SWP_SIZE | SWP_MOVE); }
  268. }
  269.  
  270.  
  271. BOOL GTPMWin::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  272. {
  273.  switch(msg)
  274.   {
  275.    case WM_SIZE:
  276.     resizeClients(mp2);
  277.     break;
  278.  
  279.    case WM_COMMAND:
  280.      return(command(mp1, mp2));
  281.  
  282.    case WM_CONTROL:
  283.      return(control(mp1, mp2));
  284.  
  285.    case WM_HITTEST:
  286.      if ((wasOutOfContainer) && (statline) && (tapebar))
  287.       {
  288.        ULONG  topControls, bottomControls;
  289.  
  290.        WinQueryWindowPos(Files->hwnd, &sizepos);
  291.        bottomControls = statline->getHeight() + tapebar->getHeight();
  292.        topControls = bottomControls + sizepos.cy;
  293.        if ((SHORT2FROMMP(mp1) < topControls) &&
  294.            (SHORT2FROMMP(mp1) > bottomControls))
  295.       {
  296.          statline->setText("File Selection");
  297.          wasOutOfContainer = FALSE; }
  298.       }
  299.      break;
  300.  
  301.    case WM_APPTERMINATENOTIFY: {
  302.     CHAR    retMsg[25];
  303.     ULONG   rc = SHORT1FROMMP(mp2);
  304.  
  305.     processing = FALSE;
  306.     if (rc != 0)
  307.       sprintf(retMsg, "Error! rc = %ld", rc);
  308.     else
  309.       sprintf(retMsg, "Done.");
  310.     if (!pmpipe.printer.isRunning())
  311.       pmpipe.printer.stop();
  312.     monitor->insertItem(retMsg);
  313.     break; }
  314.  
  315.    case WM_CLOSE:
  316.     OFrame::OCommand(msg, mp1, mp2);
  317.     GTPMApp::GTakPM->forceQuit();
  318.     delete this;
  319.     break;
  320.  
  321.    default:
  322.     return(OFrame::OCommand(msg, mp1, mp2));
  323.   } 
  324.  return(TRUE); 
  325.  
  326.  
  327. void GTPMWin::expandFolder()
  328. {
  329.  pDirInfo record = Drives->queryEmphasis();
  330.  
  331.  if(record)
  332.    Drives->recurse(record, FALSE, record->selected);
  333. }
  334.  
  335.  
  336. void GTPMWin::addExclude(PSZ str)
  337. {
  338.  OString  string("- ");
  339.  
  340.  string + str;
  341.  Excludes->insertItem(string, LIT_SORTASCENDING);
  342. }
  343.  
  344. void GTPMWin::addInclude(PSZ str)
  345. {
  346.  OString  string("+ ");
  347.  
  348.  string + str;
  349.  Includes->insertItem(string, LIT_SORTASCENDING);
  350. }
  351.  
  352.  
  353. void GTPMWin::updateListbox(PSZ str)
  354. {
  355.  ULONG     item;
  356.  
  357.  while ((item = Includes->searchString(str, 
  358.                           LIT_FIRST, 
  359.                           LSS_SUBSTRING | LSS_CASESENSITIVE)) != LIT_NONE)
  360.    Includes->deleteItem(item);
  361.  while ((item = Excludes->searchString(str, 
  362.                           LIT_FIRST, 
  363.                           LSS_SUBSTRING | LSS_CASESENSITIVE)) != LIT_NONE)
  364.    Excludes->deleteItem(item);
  365. }
  366.  
  367.  
  368. void GTPMWin::printout()
  369. {
  370.  OPMinit     init;
  371.  
  372.  while(pmpipe.pipe)
  373.   {
  374.    if (pmpipe.pipe.getline(pmpipe.readBuffer, pmpipe.bufferSize))
  375.     {
  376.      pmpipe.readBuffer.rightCut('\r');
  377.      if (!monitor->insertItem(pmpipe.readBuffer)) {
  378.        monitor->deleteAll();
  379.        monitor->insertItem(pmpipe.readBuffer); }
  380.     }
  381.   }
  382. }
  383.  
  384.  
  385. // end of source
  386.