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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // (c) 1994 Matthias Stübner
  5. // All Rights Reserved
  6. // OSlider.cpp
  7.  
  8.  
  9. /*
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  16.  *    endorse or promote products derived from this software
  17.  *    without specific prior written permission.
  18.  * 3. See OCL.INF for a detailed copyright notice.
  19.  *
  20.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  21.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30.  * SUCH DAMAGE.
  31.  */
  32.  
  33. // $Header: W:/Projects/OCL/Source/rcs/OSlider.cpp 1.50 1996/08/11 23:49:30 B.STEIN Release $
  34.  
  35. #define __OCL_SOURCE__
  36.  
  37. #define OINCL_OSTRING
  38. #define OINCL_BASE
  39.  
  40. #include <ocl.hpp>
  41. #include <OSlider.hpp>
  42.  
  43.  
  44. OSlider::OSlider(const ULONG id,
  45.                  const HWND  Parent,  // becomes parent and owner of the slider
  46.                  const ULONG scale1,
  47.                  const ULONG space1,
  48.                  const ULONG scale2,
  49.                  const ULONG space2,
  50.                  const ULONG Style)
  51.   : OWindow(id, 0, 0),
  52.     Scale1(scale1),
  53.     Space1(space1),
  54.     Scale2(scale2),
  55.     Space2(space2)
  56. {
  57.  parent = Parent;
  58.  owner  = Parent;
  59.  style  = Style;
  60. }
  61.  
  62.  
  63. OSlider::OSlider(const ULONG id,
  64.                  const OFrame& Parent,
  65.                  const ULONG scale1,
  66.                  const ULONG space1,
  67.                  const ULONG scale2,
  68.                  const ULONG space2,
  69.                  const ULONG Style)
  70.   : OWindow(id, 0, 0),
  71.     Scale1(scale1),
  72.     Space1(space1),
  73.     Scale2(scale2),
  74.     Space2(space2)
  75. {
  76.  parent = Parent.hwnd;
  77.  owner  = Parent.hwnd;
  78.  style  = Style;
  79. }
  80.  
  81.  
  82. OSlider::OSlider(const ULONG id,
  83.                  const pOFrame Parent,
  84.                  const ULONG scale1,
  85.                  const ULONG space1,
  86.                  const ULONG scale2,
  87.                  const ULONG space2,
  88.                  const ULONG Style)
  89.  : OWindow(id, 0, 0),
  90.    Scale1(scale1),
  91.    Space1(space1),
  92.    Scale2(scale2),
  93.    Space2(space2)
  94. {
  95.  parent = Parent->hwnd;
  96.  owner  = Parent->hwnd;
  97.  style  = Style;
  98. }
  99.  
  100.  
  101. // dtor
  102. OSlider::~OSlider()
  103.   {}
  104.  
  105.  
  106. PSZ OSlider::isOfType() const
  107.  return("OSlider"); 
  108. }
  109.  
  110.  
  111. OSlider& OSlider::createSlider(const SHORT x, const SHORT y, 
  112.                            const SHORT cx, const SHORT cy)
  113. {
  114.  ctlData.cbSize = sizeof(SLDCDATA);
  115.  ctlData.usScale1Increments = Scale1;
  116.  ctlData.usScale1Spacing = Space1;
  117.  ctlData.usScale2Increments = Scale2;
  118.  ctlData.usScale2Spacing = Space2;
  119.  
  120.  if ((hwnd = WinCreateWindow(parent, WC_SLIDER, NULL,
  121.                              style | WS_VISIBLE,
  122.                              x, y, cx, cy,
  123.                              owner, HWND_TOP, 0,
  124.                              (PVOID)&ctlData, NULL)) == NULLHANDLE)
  125.    throw OPMException(OCL::error(170), 0);
  126.  
  127.  return (*this);
  128. }
  129.  
  130.  
  131. OWindow& OSlider::inherit(const HWND Parent)
  132. {
  133.  OWindow::inherit(Parent);
  134.  return(createSlider());
  135. }
  136.  
  137.  
  138. OSlider& OSlider::setSliderStyles(const ULONG Style)
  139. {
  140.  style = Style;
  141.  return(*this); 
  142. }
  143.  
  144.  
  145. OSlider& OSlider::setSliderSize(const ULONG x, const ULONG y, 
  146.                             const ULONG cx, const ULONG cy)
  147. {
  148.  sizepos.x = x;
  149.  sizepos.y = y;
  150.  sizepos.cx = cx;
  151.  sizepos.cy = cy;
  152.  WinSetWindowPos(hwnd, HWND_TOP, x, y, cx, cy, SWP_SIZE);
  153.  return(*this);
  154. }
  155.  
  156.  
  157. OSlider& OSlider::setSliderArmSize(ULONG x, ULONG y)
  158. {
  159.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETSLIDERINFO,
  160.                        MPFROMSHORT (SMA_SLIDERARMDIMENSIONS),
  161.                        MPFROM2SHORT (x,y)))
  162.    throw OPMException(OCL::error(171), 0);
  163.    
  164.  return(*this);
  165. }
  166.  
  167. OSlider& OSlider::setSliderArmPos(SHORT pos)
  168. {
  169.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETSLIDERINFO,
  170.                        MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),
  171.                        MPFROMSHORT(pos)))
  172.    throw OPMException(OCL::error(172), 0);
  173.  
  174.  return(*this);
  175. }
  176.  
  177. OSlider& OSlider::setSliderShaftPos(SHORT x, SHORT y)
  178. {
  179.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETSLIDERINFO,
  180.                        MPFROMSHORT (SMA_SHAFTPOSITION),
  181.                        MPFROM2SHORT (x, y)))
  182.    throw OPMException(OCL::error(173), 0);
  183.  
  184.  return(*this);
  185. }
  186.  
  187.  
  188. OSlider& OSlider::setSliderShaftDim(SHORT dim)
  189. {
  190.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETSLIDERINFO,
  191.                        MPFROMSHORT (SMA_SHAFTDIMENSIONS),
  192.                        MPFROMSHORT (dim)))
  193.    throw OPMException(OCL::error(174), 0);
  194.  
  195.  return(*this);
  196. }
  197.  
  198. OSlider& OSlider::setSliderScaleText(PCSZ Text, USHORT pos)
  199. {
  200.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETSCALETEXT,
  201.                        MPFROMSHORT (pos),MPFROMP(Text)))
  202.    throw OPMException(OCL::error(175), 0);
  203.  
  204.  return(*this);
  205. }
  206.  
  207. OSlider& OSlider::setTickSize(ULONG size, ULONG num)
  208. {
  209.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETTICKSIZE,
  210.                        MPFROM2SHORT (num,size), NULL))
  211.    throw OPMException(OCL::error(176), 0);
  212.  
  213.  return(*this);
  214. }
  215.  
  216. ULONG OSlider::addDetent(SHORT pos)
  217. {
  218.  return((ULONG) WinSendMsg(hwnd, SLM_ADDDETENT, MPFROMSHORT (pos), 0));
  219. }
  220.  
  221. ULONG OSlider::getDetentPos(ULONG id)
  222. {
  223.  return(LONGFROMMP(WinSendMsg(hwnd, SLM_QUERYDETENTPOS, MPFROMLONG(id), 0)));
  224. }
  225.  
  226.  
  227. PSZ OSlider::getScaleText(SHORT loc, PSZ buf,SHORT len)
  228. {
  229.  WinSendMsg(hwnd, SLM_QUERYSCALETEXT,
  230.             MPFROM2SHORT(loc,len),MPFROMP(buf));
  231.  return((PSZ)buf);
  232. }
  233.  
  234. OSlider& OSlider::getSliderShaftDim(SHORT *lenght, SHORT *height)
  235. {
  236.  ULONG  tmp;
  237.  
  238.  tmp = LONGFROMMP(WinSendMsg(hwnd,SLM_QUERYSLIDERINFO,
  239.                              MPFROM2SHORT(SMA_SHAFTDIMENSIONS,SMA_INCREMENTVALUE),0));
  240.  *lenght = SHORT1FROMMP(tmp);
  241.  *height = SHORT2FROMMP(tmp);
  242.  
  243.  return(*this);
  244. }
  245.  
  246. OSlider& OSlider::getSliderShaftPos(SHORT *x, SHORT *y)
  247. {
  248.  ULONG   tmp;
  249.  
  250.  tmp = LONGFROMMP(WinSendMsg(hwnd,SLM_QUERYSLIDERINFO,
  251.                              MPFROM2SHORT(SMA_SHAFTPOSITION,SMA_INCREMENTVALUE),0));
  252.  *x = SHORT1FROMMP(tmp);
  253.  *y = SHORT2FROMMP(tmp);
  254.  
  255.  return(*this);
  256. }
  257.  
  258. OSlider& OSlider::getSliderArmSize(SHORT *x, SHORT *y)
  259. {
  260.  ULONG   tmp;
  261.  
  262.  tmp = LONGFROMMP(WinSendMsg(hwnd,SLM_QUERYSLIDERINFO,
  263.                              MPFROM2SHORT(SMA_SLIDERARMDIMENSIONS,SMA_INCREMENTVALUE),0));
  264.  *x = SHORT1FROMMP(tmp);
  265.  *y = SHORT2FROMMP(tmp);
  266.  
  267.  return(*this);
  268. }
  269.  
  270. ULONG OSlider::getSliderArmPos()
  271. {
  272.  return((ULONG)WinSendMsg(hwnd,SLM_QUERYSLIDERINFO,
  273.                           MPFROM2SHORT(SMA_SLIDERARMPOSITION,SMA_INCREMENTVALUE),0));
  274. }
  275.  
  276. ULONG OSlider::getTickSize(SHORT pos)
  277. {
  278.  return((ULONG)WinSendMsg(hwnd,SLM_QUERYTICKSIZE, MPFROMSHORT(pos), 0));
  279. }
  280.  
  281.  
  282. OSlider& OSlider::incSliderArm(SHORT delta)
  283. {
  284.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETSLIDERINFO,
  285.             MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
  286.             MPFROMSHORT((ULONG)WinSendMsg(hwnd, SLM_QUERYSLIDERINFO,
  287.             MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),NULL) + delta)))
  288.    throw OPMException(OCL::error(177), 0);
  289.  
  290.  return(*this);
  291. }
  292.  
  293.  
  294. OSlider& OSlider::decSliderArm(SHORT delta)
  295. {
  296.  if (!(BOOL)WinSendMsg(hwnd, SLM_SETSLIDERINFO,
  297.             MPFROM2SHORT (SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
  298.             MPFROMSHORT((ULONG)WinSendMsg(hwnd, SLM_QUERYSLIDERINFO,
  299.             MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),NULL) - delta)))
  300.    throw OPMException(OCL::error(178), 0);
  301.  
  302.  return(*this);
  303. }
  304.  
  305.  
  306.  
  307. OSlider& OSlider::drawSliderElement(POWNERITEM  item, COLOR color)
  308. {
  309.  WinQueryWindowRect(item->hwnd, &item->rclItem);
  310.  GpiSetColor(item->hps, color);
  311.  GpiBox(item->hps, DRO_FILL, (PPOINTL) &item->rclItem.xRight, 0L, 0L);
  312.  return(*this);
  313. }
  314.  
  315. // end of source
  316.