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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OListBox.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/OListBox.cpp 1.50 1996/08/11 23:49:21 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OListBox.hpp>
  40.  
  41.  
  42.  
  43. OListBox::OListBox(const ULONG id,
  44.                    const HWND Parent,
  45.                    const ULONG Style,
  46.                    BOOL autoScrolling)
  47.   : OWindow(id, 0, 0),
  48.     autoScroll(autoScrolling)
  49. {
  50.  parent = Parent;
  51.  owner = Parent;
  52.  style = Style;
  53. }
  54.  
  55.  
  56.  
  57. OListBox::OListBox(const ULONG id,
  58.                    const OFrame& Parent,
  59.                    const ULONG Style,
  60.                    BOOL autoScrolling)
  61.   : OWindow(id, 0, 0),
  62.     autoScroll(autoScrolling)
  63. {
  64.  parent = Parent.hwnd;
  65.  owner = Parent.hwnd;
  66.  style = Style;
  67. }
  68.  
  69.  
  70.  
  71. OListBox::OListBox(const ULONG id,
  72.                    const pOFrame Parent,
  73.                    const ULONG Style,
  74.                    BOOL autoScrolling)
  75.   : OWindow(id, 0, 0),
  76.     autoScroll(autoScrolling)
  77. {
  78.  parent = Parent->hwnd;
  79.  owner = Parent->hwnd;
  80.  style = Style;
  81. }
  82.  
  83.  
  84.  
  85. OListBox::~OListBox()
  86.   {}
  87.  
  88.  
  89. PSZ OListBox::isOfType() const
  90.  return("OListBox"); 
  91. }
  92.  
  93.  
  94.  
  95. OListBox& OListBox::createListBox(const ULONG x, const ULONG y,
  96.                                   const ULONG cx, const ULONG cy)
  97. {
  98.  if ((hwnd = WinCreateWindow(parent, WC_LISTBOX, "",
  99.                              style | WS_VISIBLE,
  100.                              x, y, cx, cy, owner, HWND_TOP,
  101.                              res, NULL, NULL)) == NULLHANDLE)
  102.    throw OPMException(OCL::error(153), 0);
  103.  
  104.  return(*this);
  105. }
  106.  
  107.  
  108.  
  109. BOOL OListBox::deleteAll()
  110. {
  111.  return((BOOL)WinSendMsg(hwnd, LM_DELETEALL, NULL, NULL));
  112. }
  113.  
  114.  
  115.  
  116. ULONG OListBox::deleteItem(const ULONG itemIndex)
  117. {
  118.  return((ULONG)WinSendMsg(hwnd, LM_DELETEITEM, MPFROMSHORT(itemIndex), NULL));
  119. }
  120.  
  121.  
  122.  
  123. ULONG OListBox::insertItem(PCSZ text, const ULONG itemIndex)
  124. {
  125.  ULONG ul = 0;
  126.  
  127.  if (text)
  128.    ul = (ULONG)WinSendMsg(hwnd, LM_INSERTITEM, MPFROMSHORT(itemIndex), MPFROMP(text));
  129.  if (autoScroll)
  130.    auto_scroll();
  131.  return(ul);
  132. }
  133.  
  134.  
  135. ULONG OListBox::queryItemCount()
  136. {
  137.  return((ULONG)WinSendMsg(hwnd, LM_QUERYITEMCOUNT, NULL, NULL));
  138. }
  139.  
  140.  
  141. ULONG OListBox::queryItemHandle(const ULONG itemIndex)
  142. {
  143.  return((ULONG)WinSendMsg(hwnd, LM_QUERYITEMHANDLE, MPFROMSHORT(itemIndex), NULL));
  144. }
  145.  
  146.  
  147. ULONG OListBox::queryItemText(OString& Buffer, const ULONG itemIndex)
  148. {
  149.  PSZ   tmp = new CHAR[2*CCHMAXPATH];
  150.  ULONG ul;
  151.  
  152.  ul = (ULONG) WinSendMsg(hwnd, LM_QUERYITEMTEXT, MPFROM2SHORT(itemIndex, 2*CCHMAXPATH), MPFROMP(tmp));
  153.  Buffer << tmp;
  154.  delete[] tmp;
  155.  return(ul);
  156. }
  157.  
  158.  
  159. ULONG OListBox::queryItemTextLength(const ULONG itemIndex)
  160. {
  161.  return((ULONG)WinSendMsg(hwnd, LM_QUERYITEMTEXTLENGTH, MPFROMSHORT(itemIndex), NULL));
  162. }
  163.  
  164.  
  165. ULONG OListBox::querySelection(const ULONG itemStart)
  166. {
  167.  return((ULONG)WinSendMsg(hwnd, LM_QUERYSELECTION, MPFROMSHORT(itemStart), NULL));
  168. }
  169.  
  170.  
  171. ULONG OListBox::queryTopItem()
  172. {
  173.  return((ULONG)WinSendMsg(hwnd, LM_QUERYTOPINDEX, NULL, NULL));
  174. }
  175.  
  176.  
  177.  
  178. ULONG OListBox::searchString(PCSZ text, 
  179.                              const ULONG itemStart,
  180.                              const ULONG command)
  181. {
  182.  if (text)
  183.    return((ULONG)WinSendMsg(hwnd, LM_SEARCHSTRING, MPFROM2SHORT(command, itemStart), MPFROMP(text)));
  184.  return(0);
  185. }
  186.  
  187.  
  188.  
  189. BOOL  OListBox::selectItem(const ULONG itemIndex, const BOOL state)
  190. {
  191.  return((BOOL)WinSendMsg(hwnd, LM_SELECTITEM, MPFROMSHORT(itemIndex), MPFROMSHORT(state)));
  192. }
  193.  
  194.  
  195. BOOL  OListBox::setItemHandle(const ULONG itemIndex, const ULONG handle)
  196. {
  197.  return((BOOL)WinSendMsg(hwnd, LM_SETITEMHANDLE, MPFROMSHORT(itemIndex), MPFROMSHORT(handle)));
  198. }
  199.  
  200.  
  201. BOOL  OListBox::setItemHeight(const ULONG newHeight)
  202. {
  203.  return((BOOL)WinSendMsg(hwnd, LM_SETITEMHEIGHT, MPFROMSHORT(newHeight), NULL));
  204. }
  205.  
  206.  
  207. BOOL OListBox::setItemText(const ULONG itemIndex, PCSZ text)
  208. {
  209.  if (text)
  210.    return((BOOL)WinSendMsg(hwnd, LM_SETITEMTEXT, MPFROMSHORT(itemIndex), MPFROMP(text)));
  211.  return(FALSE);
  212. }
  213.  
  214.  
  215. BOOL  OListBox::setToTop(const ULONG itemIndex)
  216. {
  217.  return((BOOL)WinSendMsg(hwnd, LM_SETTOPINDEX, MPFROMSHORT(itemIndex), NULL));
  218. }
  219.  
  220.  
  221. void OListBox::auto_scroll()
  222. {
  223.  FONTMETRICS FontMetrics;
  224.  
  225.  WinQueryWindowRect(hwnd, &rcl);
  226.  hps = WinGetPS(hwnd);
  227.  GpiQueryFontMetrics(hps, sizeof(FONTMETRICS), &FontMetrics);
  228.  WinReleasePS(hps);
  229.  if (queryItemCount() > ((rcl.yTop - rcl.yBottom) / FontMetrics.lMaxBaselineExt))
  230.   {
  231.    if ((rcl.yTop - rcl.yBottom) % FontMetrics.lMaxBaselineExt)
  232.      setToTop(queryTopItem()+2); 
  233.    else
  234.      setToTop(queryTopItem()+1); 
  235.   }
  236. }
  237.  
  238. OListBox&  OListBox::setAutoScroll(BOOL autoScrolling)
  239. {
  240.  autoScroll = autoScrolling;
  241.  return(*this);
  242. }
  243.  
  244. // end of source
  245.