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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // (c) Matthias Stübner 1994
  5. // OValueSet.cpp
  6.  
  7.  
  8. /*
  9.  * Redistribution and use in source and binary forms, with or without
  10.  * modification, are permitted provided that the following conditions
  11.  * are met:
  12.  * 1. Redistributions of source code must retain the above copyright
  13.  *    notice, this list of conditions and the following disclaimer.
  14.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  15.  *    endorse or promote products derived from this software
  16.  *    without specific prior written permission.
  17.  * 3. See OCL.INF for a detailed copyright notice.
  18.  *
  19.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  20.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  23.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29.  * SUCH DAMAGE.
  30.  */
  31.  
  32. // $Header: W:/Projects/OCL/Source/rcs/OValueSet.cpp 1.50 1996/08/11 23:49:34 B.STEIN Release $
  33.  
  34. #define __OCL_SOURCE__
  35.  
  36. #define OINCL_OSTRING
  37. #define OINCL_BASE
  38.  
  39. #include <ocl.hpp>
  40. #include <OValueSet.hpp>
  41.  
  42.  
  43. OValueSet::OValueSet(const ULONG id,
  44.                      const HWND  Parent,      // becomes parent and owner of the set
  45.                      const ULONG Rows,
  46.                      const ULONG Columns,
  47.                      const ULONG Margin,
  48.                      const ULONG Style)
  49.  : OWindow(id, 0, 0),
  50.    rows(Rows),
  51.    columns(Columns),
  52.    margin(Margin)
  53. {
  54.  parent = Parent;
  55.  owner  = Parent;
  56.  style  = Style;
  57. }
  58.  
  59.  
  60. OValueSet::OValueSet(const ULONG id,
  61.                      const OFrame& Parent,   // becomes parent and owner of the set
  62.                      const ULONG Rows,
  63.                      const ULONG Columns,
  64.                      const ULONG Margin,
  65.                      const ULONG Style)
  66.  : OWindow(id, 0, 0),
  67.    rows(Rows),
  68.    columns(Columns),
  69.    margin(Margin)
  70. {
  71.  parent = Parent.hwnd;
  72.  owner  = Parent.hwnd;
  73.  style  = Style;
  74. }
  75.  
  76.  
  77. OValueSet::OValueSet(const ULONG id,
  78.                      const pOFrame Parent,   // becomes parent and owner of the set
  79.                      const ULONG Rows,
  80.                      const ULONG Columns,
  81.                      const ULONG Margin,
  82.                      const ULONG Style)
  83.  : OWindow(id, 0, 0),
  84.    rows(Rows),
  85.    columns(Columns),
  86.    margin(Margin)
  87. {
  88.  parent = Parent->hwnd;
  89.  owner  = Parent->hwnd;
  90.  style  = Style;
  91. }
  92.  
  93.  
  94. // dtor
  95.  
  96. OValueSet::~OValueSet()
  97.   {}
  98.  
  99.  
  100. PSZ OValueSet::isOfType() const
  101. {
  102.  return("OValueSet");
  103. }
  104.  
  105.  
  106. OValueSet& OValueSet::createValueSet(const SHORT x, const SHORT y,
  107.                                const SHORT cx, const SHORT cy)
  108. {
  109.  ctlData.cbSize = sizeof(VSCDATA);
  110.  ctlData.usRowCount = rows;
  111.  ctlData.usColumnCount = columns;
  112.  
  113.  if ((hwnd = WinCreateWindow(parent, WC_VALUESET, NULL,
  114.                              style | WS_VISIBLE,
  115.                              x, y, cx, cy,
  116.                              owner, HWND_TOP,
  117.                              res, &ctlData, NULL)) == NULLHANDLE)
  118.    throw OPMException(OCL::error(163), 0);
  119.  
  120.  return(*this);
  121. }
  122.  
  123.  
  124.  
  125. BOOL OValueSet::queryItem(ULONG row, ULONG col)
  126. {
  127.  ULONG itemInfo = 0;
  128.  
  129.  memset(&selected, 0, sizeof(vsItem));
  130.  
  131.  switch(queryItemAttr(row, col))
  132.   {
  133.    case VIA_TEXT: {
  134.      VSTEXT vstext;
  135.      CHAR   Buffer[100];
  136.  
  137.      vstext.ulBufLen = 100;
  138.      vstext.pszItemText = Buffer;
  139.      WinSendMsg(hwnd, VM_QUERYITEM, MPFROM2SHORT(row, col), MPFROMP(&vstext));
  140.      selected.text << Buffer;
  141.      break; }
  142.  
  143.    case VIA_ICON:
  144.      itemInfo = (ULONG) WinSendMsg(hwnd, VM_QUERYITEM, MPFROM2SHORT(row, col), NULL);
  145.      selected.icon = (HPOINTER) itemInfo;
  146.      break;
  147.  
  148.    case VIA_BITMAP:
  149.      itemInfo = (ULONG) WinSendMsg(hwnd, VM_QUERYITEM, MPFROM2SHORT(row, col), NULL);
  150.      selected.icon = (HBITMAP) itemInfo;
  151.      break;
  152.  
  153.    case VIA_RGB:
  154.      itemInfo = (ULONG) WinSendMsg(hwnd, VM_QUERYITEM, MPFROM2SHORT(row, col), NULL);
  155.      selected.rgb.bRed = (BYTE) itemInfo / 65536;
  156.      itemInfo %= 65536;
  157.      selected.rgb.bGreen = (BYTE) itemInfo / 256;
  158.      selected.rgb.bBlue = (BYTE) itemInfo % 256;
  159.      break;
  160.  
  161.    case VIA_COLORINDEX:
  162.      selected.colorIndex = itemInfo;
  163.      break;
  164.   }
  165.  return(itemInfo != 0);
  166. }
  167.  
  168.  
  169.  
  170. ULONG OValueSet::queryItemAttr(ULONG row, ULONG col)
  171. {
  172.  return((ULONG)WinSendMsg(hwnd, VM_QUERYITEMATTR, MPFROM2SHORT(row, col), NULL));
  173. }
  174.  
  175.  
  176.  
  177. ULONG OValueSet::queryMetrics(ULONG fMetric)
  178. {
  179.  return((ULONG)WinSendMsg(hwnd, VM_QUERYMETRICS, MPFROMSHORT(fMetric), NULL));
  180. }
  181.  
  182.  
  183.  
  184. BOOL  OValueSet::querySelected()
  185. {
  186.  MRESULT temp;
  187.  
  188.  temp = WinSendMsg(hwnd, VM_QUERYSELECTEDITEM, NULL, NULL);
  189.  if (temp)
  190.   {
  191.    selected.row = SHORT1FROMMP(temp);
  192.    selected.col = SHORT2FROMMP(temp);
  193.    return(TRUE);
  194.   }
  195.  return(FALSE);
  196. }
  197.  
  198.  
  199.  
  200. BOOL OValueSet::selectItem(ULONG row, ULONG col)
  201. {
  202.  return((BOOL)WinSendMsg(hwnd, VM_SELECTITEM, MPFROM2SHORT(row, col), NULL));
  203. }
  204.  
  205.  
  206. BOOL OValueSet::setItem(ULONG row, ULONG col, ULONG itemInfo)
  207. {
  208.  BOOL fSuccess = TRUE;
  209.  
  210.  if (row == 0)
  211.   {
  212.    for (ULONG rowCount = 1; ((rowCount <= rows) && (fSuccess)); rowCount++)
  213.      fSuccess = setItem(rowCount, col, itemInfo);
  214.    return(fSuccess);
  215.   }
  216.  
  217.  if (col == 0)
  218.   {
  219.    for (ULONG colCount = 1; ((colCount <= columns) && (fSuccess)); colCount++)
  220.      fSuccess = setItem(row, colCount, itemInfo);
  221.    return(fSuccess);
  222.   }
  223.  
  224.  return((BOOL)WinSendMsg(hwnd, VM_SETITEM, MPFROM2SHORT(row, col), MPFROMLONG(itemInfo)));
  225. }
  226.  
  227.  
  228.  
  229. BOOL OValueSet::setItemAttr(ULONG row, ULONG col, ULONG attribute, BOOL set)
  230. {
  231.  BOOL fSuccess = TRUE;
  232.  
  233.  if (row == 0)
  234.   {
  235.    for (ULONG rowCount = 1; ((rowCount <= rows) && (fSuccess)); rowCount++)
  236.      fSuccess = setItemAttr(rowCount, col, attribute, set);
  237.    return(fSuccess);
  238.   }
  239.  
  240.  if (col == 0)
  241.   {
  242.    for (ULONG colCount = 1; ((colCount <= columns) && (fSuccess)); colCount++)
  243.      fSuccess = setItemAttr(row, colCount, attribute, set);
  244.    return(fSuccess);
  245.   }
  246.  
  247.  return((BOOL)WinSendMsg(hwnd, VM_SETITEMATTR,
  248.                          MPFROM2SHORT(row, col), MPFROM2SHORT(attribute, set)));
  249. }
  250.  
  251.  
  252. BOOL OValueSet::setMetrics(ULONG fMetric, ULONG itemInfo)
  253. {
  254.  return((BOOL)WinSendMsg(hwnd, VM_SETMETRICS, MPFROMSHORT(fMetric), MPFROMSHORT(itemInfo)));
  255. }
  256.  
  257.  
  258. // end of source
  259.