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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OEditor.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OEditor.cpp 1.50 1996/08/11 23:49:14 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OEditor.hpp>
  40. #include <OBuffer.hpp>
  41.  
  42. #if defined(__EMX__)
  43.   template class OThread<OEditor>;
  44. #endif
  45.  
  46.  
  47. OEditor::OEditor(const ULONG id,
  48.                  const HWND Parent, 
  49.                  const ULONG Style)
  50.   : OMLE(id, Parent, Style),
  51.     clearFlag(FALSE),
  52.     loadFileThr(this, &OEditor::loadFile),
  53.     saveFileThr(this, &OEditor::saveFile),
  54.     saveFileAsThr(this, &OEditor::saveFileAs)
  55.  {}
  56.  
  57.  
  58. OEditor::OEditor(const ULONG id,
  59.                  const pOFrame Parent,
  60.                  const ULONG Style)
  61.   : OMLE(id, Parent, Style),
  62.     clearFlag(FALSE),
  63.     loadFileThr(this, &OEditor::loadFile),
  64.     saveFileThr(this, &OEditor::saveFile),
  65.     saveFileAsThr(this, &OEditor::saveFileAs)
  66.  {}
  67.  
  68.  
  69. OEditor::OEditor(const ULONG id,
  70.                  const OFrame& Parent,
  71.                  const ULONG Style)
  72.   : OMLE(id, Parent, Style),
  73.     clearFlag(FALSE),
  74.     loadFileThr(this, &OEditor::loadFile),
  75.     saveFileThr(this, &OEditor::saveFile),
  76.     saveFileAsThr(this, &OEditor::saveFileAs)
  77.  {}
  78.  
  79.  
  80.  
  81. OEditor::~OEditor() {}
  82.  
  83.  
  84. PSZ OEditor::isOfType() const
  85.  return("OEditor"); 
  86. }
  87.  
  88.  
  89. void OEditor::loadFile()
  90. {
  91.  FILEDLG  fdFileDlg;
  92.  HWND     hwndFileDlg;
  93.  
  94.  memset(&fdFileDlg, 0, sizeof(FILEDLG));
  95.  fdFileDlg.cbSize=sizeof(FILEDLG);
  96.  fdFileDlg.fl=FDS_CENTER | FDS_OPEN_DIALOG;
  97.  fdFileDlg.pszTitle="Editor";
  98.  strcpy(fdFileDlg.szFullFile, "*");
  99.  hwndFileDlg=WinFileDlg(HWND_DESKTOP, parent, &fdFileDlg);
  100.  if (hwndFileDlg && (fdFileDlg.lReturn==DID_OK)) {
  101.    deleteAll();
  102.    insertFile(fdFileDlg.szFullFile); }
  103.  openedFile << fdFileDlg.szFullFile;
  104. }
  105.  
  106.  
  107.  
  108. void OEditor::saveFile()
  109. {
  110.  pOBuffer   Buffer;
  111.  HFILE      hf;
  112.  ULONG      cbWritten, ulAction;
  113.  ULONG      SIZE = 8192;
  114.  
  115.  if (!openedFile)
  116.   {
  117.    saveFileAs();
  118.    return;
  119.   }
  120.  
  121.  DosOpen(openedFile, &hf, &ulAction, 0, 0,
  122.          OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS,
  123.          OPEN_SHARE_DENYWRITE | OPEN_ACCESS_WRITEONLY,
  124.          NULL);
  125.  
  126.  Buffer = new OBuffer(SIZE+1, OBuffer::ALLOC);
  127.  
  128.  imexOffset = 0;
  129.  
  130.  while(TRUE)
  131.   {
  132.    if(((cbWritten = getText(Buffer->getPtr(), SIZE)) == 0) ||
  133.        (DosWrite(hf, Buffer, cbWritten, &cbWritten)))
  134.      break;
  135.   }
  136.  
  137.  DosClose(hf);
  138.  delete Buffer;
  139. }
  140.  
  141.  
  142.  
  143. void OEditor::saveFileAs()
  144. {
  145.  FILEDLG  fdFileDlg;
  146.  HWND     hwndFileDlg;
  147.  
  148.  memset(&fdFileDlg, 0, sizeof(FILEDLG));
  149.  fdFileDlg.cbSize=sizeof(FILEDLG);
  150.  fdFileDlg.fl=FDS_CENTER | FDS_SAVEAS_DIALOG;
  151.  fdFileDlg.pszTitle="Editor";
  152.  if (openedFile)
  153.    strcpy(fdFileDlg.szFullFile, openedFile);
  154.  hwndFileDlg=WinFileDlg(HWND_DESKTOP, parent, &fdFileDlg);
  155.  if (hwndFileDlg && (fdFileDlg.lReturn==DID_OK))
  156.   {
  157.    openedFile << fdFileDlg.szFullFile;
  158.    saveFileThr.run();
  159.   }
  160. }
  161.  
  162.  
  163. // end of source
  164.