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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OButton.cpp
  5.  
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31.  
  32. // $Header: W:/Projects/OCL/Source/rcs/OButton.cpp 1.50 1996/08/11 23:49:09 B.STEIN Release $
  33.  
  34. #define __OCL_SOURCE__
  35.  
  36. #define OINCL_OSTRING
  37. #define OINCL_BASE
  38.  
  39. #include <ocl.hpp>
  40. #include <OButton.hpp>
  41.  
  42.  
  43. OButton::OButton(ULONG   id,
  44.                  HWND    Parent,
  45.                  ULONG   Style,
  46.                  ULONG   x,
  47.                  ULONG   y,
  48.                  ULONG   cx,
  49.                  ULONG   cy)
  50.  : OWindow(id, Style, 0)
  51. {
  52.  sizepos.x  = x;
  53.  sizepos.y  = y;
  54.  sizepos.cx = cx;
  55.  sizepos.cy = cy;
  56. }
  57.  
  58.  
  59. OButton::OButton(ULONG   id,
  60.                  OFrame& Parent,
  61.                  ULONG   Style,
  62.                  ULONG   x,
  63.                  ULONG   y,
  64.                  ULONG   cx,
  65.                  ULONG   cy)
  66.  : OWindow(id, Style, 0)
  67. {
  68.  parent     = Parent.client;
  69.  owner      = Parent.client; 
  70.  sizepos.x  = x;
  71.  sizepos.y  = y;
  72.  sizepos.cx = cx;
  73.  sizepos.cy = cy;
  74. }
  75.  
  76.  
  77. OButton::OButton(ULONG   id,
  78.                  pOFrame Parent,
  79.                  ULONG   Style,
  80.                  ULONG   x,
  81.                  ULONG   y,
  82.                  ULONG   cx,
  83.                  ULONG   cy)
  84.  : OWindow(id, Style, 0)
  85. {
  86.  parent     = Parent->client;
  87.  owner      = Parent->client; 
  88.  sizepos.x  = x;
  89.  sizepos.y  = y;
  90.  sizepos.cx = cx;
  91.  sizepos.cy = cy;
  92. }
  93.  
  94.  
  95.  
  96. OButton& OButton::createButton()
  97. {
  98.  if ((hwnd = WinCreateWindow(parent, WC_BUTTON,
  99.              "", style | WS_VISIBLE,
  100.              sizepos.x, sizepos.y,
  101.              sizepos.cx, sizepos.cy,
  102.              owner, HWND_TOP, res, NULL, NULL))
  103.              == NULLHANDLE)
  104.    throw OPMException(OCL::error(150), 0);
  105.  return(*this);
  106. }   
  107.  
  108.  
  109.  
  110. OButton::~OButton()
  111.   {}
  112.  
  113.  
  114. PSZ OButton::isOfType() const
  115. {
  116.  return("OButton");
  117. }
  118.  
  119.  
  120. ULONG OButton::queryState()
  121. {
  122.  return((ULONG)WinSendMsg(hwnd, BM_QUERYCHECK, NULL, NULL));
  123. }
  124.   
  125. BOOL OButton::isChecked()
  126. {
  127.  return(queryState() == 1);
  128. }
  129.  
  130.  
  131. BOOL OButton::isHilited()
  132. {
  133.  return((BOOL)WinSendMsg(hwnd, BM_QUERYHILITE, NULL, NULL));
  134. }
  135.  
  136.  
  137. OButton& OButton::check()
  138. {
  139.  return(setState(TRUE));
  140. }
  141.  
  142. OButton& OButton::uncheck()
  143. {
  144.  return(setState(FALSE));
  145. }
  146.  
  147. OButton& OButton::setState(ULONG state)
  148. {
  149.  WinSendMsg(hwnd, BM_SETCHECK, MPFROMSHORT(state), NULL);
  150.  return(*this);
  151. }
  152.  
  153. OButton& OButton::setDefault(BOOL displayDefault)
  154. {
  155.  WinSendMsg(hwnd, BM_SETDEFAULT, MPFROMSHORT(displayDefault), NULL);
  156.  return(*this);
  157. }
  158.  
  159. OButton& OButton::setHilite(BOOL hiliteState)
  160. {
  161.  WinSendMsg(hwnd, BM_SETHILITE, MPFROMSHORT(hiliteState), NULL);
  162.  return(*this);
  163. }
  164.  
  165. OButton& OButton::click(BOOL down)  
  166. {
  167.  WinSendMsg(hwnd, BM_CLICK, MPFROMSHORT(down), NULL);
  168.  return(*this);
  169. }
  170.  
  171.  
  172. // end of source
  173.