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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OMLE.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/OMLE.cpp 1.50 1996/08/11 23:49:22 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OMLE.hpp>
  40.  
  41. #if defined(__EMX__)
  42.   template class OThread<OMLE>;
  43. #endif
  44.  
  45.  
  46. OMLE::OMLE(const ULONG id,
  47.            const HWND Parent,
  48.            const ULONG Style)
  49.      : OWindow(id, 0, 0),
  50.        imex(NULL),
  51.        imexLen(0),
  52.        imexOffset(0),
  53.        insertLargeThr(this, &OMLE::insertLarge)
  54. {
  55.  parent = owner = Parent;
  56.  style = Style;
  57. }
  58.  
  59.  
  60. OMLE::OMLE(const ULONG id,
  61.            const OFrame& Parent,
  62.            const ULONG Style)
  63.      : OWindow(id, 0, 0),
  64.        imex(NULL),
  65.        imexLen(0),
  66.        imexOffset(0),
  67.        insertLargeThr(this, &OMLE::insertLarge)
  68. {
  69.  parent = owner = Parent.hwnd;
  70.  style = Style;
  71. }
  72.  
  73. OMLE::OMLE(const ULONG id,
  74.            const pOFrame Parent,
  75.            const ULONG Style)
  76.      : OWindow(id, 0, 0),
  77.        imex(NULL),
  78.        imexLen(0),
  79.        imexOffset(0),
  80.        insertLargeThr(this, &OMLE::insertLarge)
  81. {
  82.  parent = owner = Parent->hwnd;
  83.  style = Style;
  84. }
  85.  
  86.  
  87.  
  88. OMLE::~OMLE()
  89.   {}
  90.  
  91.  
  92. PSZ OMLE::isOfType() const
  93.  return("OMLE"); 
  94. }
  95.  
  96.  
  97. BOOL OMLE::createMLE(const ULONG x,
  98.                      const ULONG y,
  99.                      const ULONG cx,
  100.                      const ULONG cy)
  101. {
  102.  hwnd = WinCreateWindow(parent, WC_MLE, NULL, style | WS_VISIBLE,
  103.                         x, y, cx, cy,
  104.                         owner, HWND_TOP, 0, NULL, NULL);
  105.  return(hwnd != NULLHANDLE);
  106. }
  107.  
  108.  
  109.  
  110. ULONG OMLE::getText(PVOID out, ULONG len)
  111. {
  112.  ULONG  exported;
  113.  
  114.  WinSendMsg(hwnd, MLM_SETIMPORTEXPORT, MPFROMP((PBYTE)out), MPFROMLONG(len));
  115.  exported = (ULONG) WinSendMsg(hwnd, MLM_EXPORT, MPFROMP(&imexOffset), MPFROMP(&len));
  116.  return(exported);
  117. }
  118.  
  119.  
  120. ULONG OMLE::getText(OString& Buffer)
  121. {
  122.  PSZ   temp = new CHAR[3*CCHMAXPATH];
  123.  ULONG charsRead;
  124.  
  125.  if ((charsRead = (ULONG) WinQueryWindowText(hwnd, 3*CCHMAXPATH, temp)) != 0)
  126.    Buffer << temp;
  127.  else
  128.    Buffer << (PSZ) NULL;
  129.  delete[] temp;
  130.  return(charsRead != 0);
  131. }
  132.  
  133.  
  134.  
  135. ULONG OMLE::setText(PVOID in, ULONG len)
  136. {
  137.  ULONG  inserted = imexOffset;
  138.  
  139.  WinSendMsg(hwnd, MLM_SETIMPORTEXPORT, MPFROMP((PBYTE)in), MPFROMLONG(len));
  140.  WinSendMsg(hwnd, MLM_IMPORT, MPFROMP(&imexOffset), MPFROMP(&len));
  141.  
  142.  inserted = imexOffset - inserted;
  143.  return(inserted);
  144. }
  145.  
  146.  
  147. ULONG OMLE::setText(PSZ text)
  148. {
  149.  if (text)
  150.    return(setText((PVOID)text, strlen(text)+1));
  151.  return(0);
  152. }
  153.  
  154.  
  155.  
  156. BOOL OMLE::insertText(PSZ text)
  157. {
  158.  if (text)
  159.    return((BOOL)WinSendMsg(hwnd, MLM_INSERT, MPFROMP(text), NULL));
  160.  return(FALSE);
  161. }
  162.  
  163.  
  164.  
  165. BOOL OMLE::insertFile(PCSZ fileName)
  166. {
  167.  openedFile << (PSZ) fileName;
  168.  insertLargeThr.run();
  169.  return(TRUE);
  170. }
  171.  
  172.  
  173.  
  174. BOOL OMLE::copy()
  175. {
  176.  return(FALSE);
  177. }
  178.  
  179.  
  180. BOOL OMLE::cut()
  181. {
  182.  return(FALSE);
  183. }
  184.  
  185.  
  186. BOOL OMLE::paste()
  187. {
  188.  return(FALSE);
  189. }
  190.  
  191.  
  192. BOOL OMLE::copy2Clip()
  193. {
  194.  return(FALSE);
  195. }
  196.  
  197.  
  198. BOOL OMLE::cut2Clip()
  199. {
  200.  return(FALSE);
  201. }
  202.  
  203.  
  204. BOOL OMLE::pasteFromClip()
  205. {
  206.  return(FALSE);
  207. }
  208.  
  209.  
  210. BOOL OMLE::clear()
  211. {
  212.  return(TRUE);
  213. }
  214.  
  215.  
  216.  
  217.  
  218. BOOL OMLE::undo()
  219. {
  220.  return(FALSE);
  221. }
  222.  
  223.  
  224.  
  225.  
  226. BOOL OMLE::deleteText(ULONG beginPoint, ULONG count)
  227. {
  228.  return(((ULONG)WinSendMsg(hwnd, MLM_DELETE,
  229.                            MPFROMSHORT(beginPoint), MPFROMSHORT(count))) == count);
  230. }
  231.  
  232. BOOL  OMLE::deleteAll()
  233. {
  234.  return(((ULONG)WinSendMsg(hwnd, MLM_DELETE, 
  235.                            MPFROMSHORT(0), MPFROMSHORT(length()))) == length());
  236. }
  237.  
  238.  
  239. void OMLE::insertLarge()
  240. {
  241.  FILESTATUS fileStatus;
  242.  PBYTE      rBuffer;
  243.  HFILE      hf;
  244.  ULONG      cbRead, ulAction;
  245.  PBYTE      Buffer;
  246.  ULONG      SIZE = 8192;
  247.  
  248.  DosOpen(openedFile, &hf, &ulAction, 0, FILE_NORMAL, FILE_OPEN | FILE_CREATE,
  249.          OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL);
  250.  DosQueryFileInfo(hf, 1, (PVOID)&fileStatus,  sizeof(FILESTATUS));
  251.  DosAllocMem((PPVOID)&rBuffer, fileStatus.cbFile, PAG_READ | PAG_WRITE | PAG_COMMIT);
  252.  memset(rBuffer, 0, fileStatus.cbFileAlloc);
  253.  
  254.  DosRead(hf, rBuffer, fileStatus.cbFile, &cbRead);
  255.  DosClose(hf);
  256.  
  257.  if (!cbRead) {
  258.    DosFreeMem(rBuffer);
  259.    return; }
  260.  
  261.  if (cbRead > SIZE) {
  262.    ULONG steps = cbRead / SIZE;
  263.    ULONG rest = cbRead % SIZE;
  264.  
  265.    Buffer = rBuffer;
  266.    for (ULONG i = 1; i <= steps; ++i) {
  267.      setText(Buffer, SIZE);
  268.      Buffer = Buffer+SIZE; }
  269.    setText(Buffer, rest); }
  270.  else
  271.    setText(rBuffer, fileStatus.cbFile);
  272.  
  273.  DosFreeMem(rBuffer);
  274. }
  275.  
  276.  
  277.  
  278. ULONG OMLE::length()
  279. {
  280.  return((ULONG)WinSendMsg(hwnd, MLM_QUERYFORMATTEXTLENGTH, MPFROMLONG(0), MPFROMLONG(-1)));
  281. }
  282.  
  283.  
  284. ULONG OMLE::lines()
  285. {
  286.  return((ULONG)WinSendMsg(hwnd, MLM_QUERYLINECOUNT, NULL, NULL));
  287. }
  288.  
  289.  
  290.  
  291. BOOL OMLE::changed()
  292. {
  293.  return((BOOL)WinSendMsg(hwnd, MLM_QUERYCHANGED, NULL, NULL));
  294. }
  295.  
  296.  
  297. void OMLE::enableRefresh()
  298. {
  299.  WinSendMsg(hwnd, MLM_ENABLEREFRESH, NULL, NULL);
  300. }
  301.  
  302.  
  303. void OMLE::disableRefresh()
  304. {
  305.  WinSendMsg(hwnd, MLM_DISABLEREFRESH, NULL, NULL);
  306. }
  307.  
  308.  
  309. ULONG OMLE::setFormat(const ULONG format)
  310. {
  311.  return((ULONG)WinSendMsg(hwnd, MLM_FORMAT, MPFROMSHORT(format), NULL));
  312. }
  313.  
  314.  
  315.  
  316. // end of source
  317.