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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OEntryField.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/OEntryField.cpp 1.50 1996/08/11 23:49:15 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OEntryField.hpp>
  40.  
  41.  
  42.  
  43. OEntryField::OEntryField(const ULONG id,
  44.                          const HWND Parent,
  45.                          const ULONG Style,
  46.                          const ULONG Limit)
  47.   : OWindow(id, 0, 0),
  48.     limit(Limit)
  49. {
  50.  parent = Parent;
  51.  owner = Parent;
  52.  style = Style;
  53. }
  54.  
  55.  
  56.  
  57. OEntryField::OEntryField(const ULONG id,
  58.                          const OFrame& Parent,
  59.                          const ULONG Style,
  60.                          const ULONG Limit)
  61.   : OWindow(id, 0, 0),
  62.     limit(Limit)
  63. {
  64.  parent = Parent.hwnd;
  65.  owner = Parent.hwnd;
  66.  style = Style;
  67. }
  68.  
  69.  
  70.  
  71. OEntryField::OEntryField(const ULONG id,
  72.                          const pOFrame Parent,
  73.                          const ULONG Style,
  74.                          const ULONG Limit)
  75.   : OWindow(id, 0, 0),
  76.     limit(Limit)
  77. {
  78.  parent = Parent->hwnd;
  79.  owner = Parent->hwnd;
  80.  style = Style;
  81. }
  82.  
  83.  
  84.  
  85. OEntryField::~OEntryField()
  86.   {}
  87.  
  88.  
  89. PSZ OEntryField::isOfType() const
  90.  return("OEntryField"); 
  91. }
  92.  
  93.  
  94.  
  95. OEntryField& OEntryField::createEntryField(const ULONG x, const ULONG y, 
  96.                                            const ULONG cx, const ULONG cy)
  97. {
  98.  if ((hwnd = WinCreateWindow(parent, WC_ENTRYFIELD, "",
  99.                              style | WS_VISIBLE,
  100.                              x, y, cx, cy, owner, HWND_TOP,
  101.                              res, NULL, NULL)) == NULLHANDLE)
  102.    throw OPMException(OCL::error(158), 0);
  103.  
  104.  setTextLimit(limit);
  105.  return(*this);
  106. }
  107.  
  108.  
  109.  
  110. OWindow& OEntryField::inherit(const HWND hwndDlg)
  111. {
  112.  OWindow::inherit(hwndDlg);
  113.  setTextLimit(limit);
  114.  return(*this);
  115. }
  116.  
  117. BOOL  OEntryField::getText(OString& Buffer)
  118. {
  119.  OString temp(limit+1);
  120.  ULONG   charsRead;
  121.  
  122.  if ((charsRead = (ULONG) WinQueryWindowText(hwnd, limit+1, temp)) != 0)
  123.    Buffer << temp;
  124.  else
  125.    Buffer << (PSZ) NULL;
  126.  return(charsRead != 0);
  127. }
  128.  
  129.  
  130.  
  131. BOOL  OEntryField::setText(PCSZ text)
  132. {
  133.  if (text)
  134.    return(WinSetWindowText(hwnd, (PSZ)text));
  135.  else
  136.    return(WinSetWindowText(hwnd, ""));
  137. }
  138.  
  139.  
  140.  
  141. BOOL  OEntryField::cutText()
  142. {
  143.  return((BOOL)WinSendMsg(hwnd, EM_CUT, NULL, NULL));
  144. }
  145.  
  146.  
  147. BOOL  OEntryField::copyText()
  148. {
  149.  return((BOOL)WinSendMsg(hwnd, EM_COPY, NULL, NULL));
  150. }
  151.  
  152.  
  153. BOOL  OEntryField::pasteText()
  154. {
  155.  return((BOOL)WinSendMsg(hwnd, EM_PASTE, NULL, NULL));
  156. }
  157.  
  158.  
  159. BOOL  OEntryField::clearText()
  160. {
  161.  return((BOOL)WinSendMsg(hwnd, EM_CLEAR, NULL, NULL));
  162. }
  163.  
  164.  
  165. BOOL  OEntryField::queryChanged()
  166. {
  167.  return((BOOL)WinSendMsg(hwnd, EM_QUERYCHANGED, NULL, NULL));
  168. }
  169.  
  170.  
  171. ULONG OEntryField::queryFirstChar()
  172. {
  173.  return((ULONG)WinSendMsg(hwnd, EM_QUERYFIRSTCHAR, NULL, NULL));
  174. }
  175.  
  176.  
  177.  
  178. BOOL  OEntryField::queryRDOnly()
  179. {
  180.  return((BOOL)WinSendMsg(hwnd, EM_QUERYREADONLY, NULL, NULL));
  181. }
  182.  
  183.  
  184. BOOL  OEntryField::querySelection(USHORT& firstChar, USHORT& lastChar)
  185. {
  186.  MRESULT temp = WinSendMsg(hwnd, EM_QUERYSEL, NULL, NULL);
  187.  
  188.  return((temp != NULL) &&
  189.         ((firstChar = SHORT1FROMMP(temp)) != 0) &&
  190.         ((lastChar = SHORT2FROMMP(temp)) != 0));
  191. }
  192.  
  193.  
  194.  
  195. BOOL  OEntryField::setFirstChar(const USHORT first)
  196. {
  197.  return((BOOL)WinSendMsg(hwnd, EM_SETFIRSTCHAR, MPFROMSHORT(first), NULL));
  198. }
  199.  
  200.  
  201. BOOL  OEntryField::setInsertMode(const BOOL insert)
  202. {
  203.  return((BOOL)WinSendMsg(hwnd, EM_SETINSERTMODE, MPFROMSHORT(insert), NULL));
  204. }
  205.  
  206.  
  207. BOOL  OEntryField::setRDOnly(const BOOL readOnly)
  208. {
  209.  return((BOOL)WinSendMsg(hwnd, EM_SETREADONLY, MPFROMSHORT(readOnly), NULL));
  210. }
  211.  
  212.  
  213. BOOL  OEntryField::setSelection(const USHORT firstChar, const USHORT lastChar)
  214. {
  215.  return((BOOL)WinSendMsg(hwnd, EM_SETSEL, MPFROM2SHORT(firstChar, lastChar), NULL));
  216. }
  217.  
  218.  
  219. BOOL  OEntryField::setTextLimit(const USHORT limit)
  220. {
  221.  return((BOOL)WinSendMsg(hwnd, EM_SETTEXTLIMIT, MPFROMSHORT(limit), NULL));
  222. }
  223.  
  224.  
  225. // end of source
  226.