home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OStatusLine.cpp < prev    next >
C/C++ Source or Header  |  1997-01-05  |  7KB  |  245 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OStatusLine.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. // $Header: W:/Projects/OCL/Source/rcs/OStatusLine.cpp 1.50 1996/08/11 23:49:31 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OStatusLine.hpp>
  40.  
  41. OStatusLine::OStatusLine(const ULONG id,
  42.                          const HWND parentWindow,
  43.                          const BOOL DDStyle)
  44.   : OFrame(id, FCF_NOBYTEALIGN, CS_SIZEREDRAW),
  45.     ddStyle(DDStyle)
  46. {
  47.  setParent(parentWindow);
  48.  setOwner(parentWindow);
  49.  initStatlineDefaults();
  50. }
  51.  
  52.  
  53. OStatusLine::OStatusLine(const ULONG id,
  54.                          const OFrame& parentWindow,
  55.                          const BOOL DDStyle)
  56.   : OFrame(id, FCF_NOBYTEALIGN, CS_SIZEREDRAW),
  57.     ddStyle(DDStyle)
  58. {
  59.  setParent(parentWindow.hwnd);
  60.  setOwner(parentWindow.hwnd);
  61.  initStatlineDefaults();
  62. }
  63.  
  64.  
  65. OStatusLine::OStatusLine(const ULONG id,
  66.                          const pOFrame parentWindow,
  67.                          const BOOL DDStyle)
  68.   : OFrame(id, FCF_NOBYTEALIGN, CS_SIZEREDRAW),
  69.     ddStyle(DDStyle)
  70. {
  71.  initStatlineDefaults().setParent(parentWindow->hwnd).setOwner(parentWindow->hwnd);
  72. }
  73.  
  74.  
  75. OStatusLine::~OStatusLine()
  76.   {}
  77.  
  78.  
  79. PSZ OStatusLine::isOfType() const
  80. {
  81.  return("OStatusLine");
  82. }
  83.  
  84.  
  85. OStatusLine& OStatusLine::initStatlineDefaults()
  86. {
  87.  orientation = DT_LEFT | DT_VCENTER;
  88.  readOnly = FALSE;
  89.  statlineText << (PSZ) "";
  90.  pparms.Fore = SYSCLR_WINDOWTEXT;
  91.  if (ddStyle)
  92.    pparms.Back = SYSCLR_BUTTONMIDDLE;
  93.  else
  94.    pparms.Back = SYSCLR_WINDOW;
  95.  return(*this);
  96. }
  97.  
  98.  
  99. OStatusLine& OStatusLine::createStatusLine()
  100. {
  101.  createFrame("OStatusLine");
  102.  setFont("8.Helv");
  103.  showFrame();
  104.  return(*this);
  105. }
  106.  
  107.  
  108. OStatusLine& OStatusLine::refreshText()
  109. {
  110.  WinInvalidateRect(hwnd, 0, TRUE);
  111.  return(*this);
  112. }
  113.  
  114.  
  115. OStatusLine& OStatusLine::setText(PCSZ text)
  116. {
  117.  if ((text) && (!readOnly)) {
  118.    statlineText << (PSZ) " ";
  119.    statlineText + (PSZ) text;
  120.    statlineText + (PSZ) " ";
  121.    refreshText(); }
  122.  return(*this);
  123. }
  124.  
  125.  
  126. ULONG OStatusLine::getHeight()
  127. {
  128.  ULONG statlineHeight;
  129.  
  130.  hps = WinGetPS(client);
  131.  WinQueryWindowRect(HWND_DESKTOP, &rcl);
  132.  WinDrawText(hps, 1, " ", &rcl, 0L, 0L, orientation | DT_QUERYEXTENT);
  133.  WinFillRect(hps, &rcl, pparms.Back);
  134.  WinReleasePS(hps);
  135.  statlineHeight = rcl.yTop - rcl.yBottom + 10;
  136.  return(statlineHeight);
  137. }
  138.  
  139. ULONG OStatusLine::getWidth()
  140. {
  141.  ULONG statlineWidth;
  142.  
  143.  hps = WinGetPS(client);
  144.  WinQueryWindowRect(HWND_DESKTOP, &rcl);
  145.  WinDrawText(hps, strlen(statlineText), statlineText,
  146.              &rcl, 0L, 0L, orientation | DT_QUERYEXTENT);
  147.  WinFillRect(hps, &rcl, pparms.Back);
  148.  WinReleasePS(hps);
  149.  
  150.  statlineWidth = rcl.xRight - rcl.xLeft + 10;
  151.  return(statlineWidth);
  152. }
  153.  
  154.  
  155. OStatusLine& OStatusLine::setOrientation(const ULONG Orientation)
  156. {
  157.  orientation = Orientation;
  158.  return(*this);
  159. }
  160.  
  161.  
  162. OStatusLine& OStatusLine::setRDOnly(BOOL readonly)
  163. {
  164.  readOnly = readonly;
  165.  return(*this);
  166. }
  167.  
  168.  
  169. BOOL OStatusLine::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  170. {
  171.  switch(msg)
  172.    {
  173.     case WM_PAINT:
  174.      if (ddStyle)
  175.       {
  176.        ULONG   height = getHeight() - 3;
  177.        ULONG   width  = 0;
  178.        ULONG   offset = 3;
  179.        POINTL  ptl;
  180.  
  181.        hps = WinBeginPaint(hwnd, 0, NULL);
  182.        WinQueryWindowRect(hwnd, &rcl);
  183.        width =  rcl.xRight - rcl.xLeft;
  184.    
  185.        GpiCreateLogColorTable(hps, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL);
  186.        GpiSetColor(hps, pparms.Back);
  187.        ptl.x = width; ptl.y = height;
  188.        GpiBox(hps, DRO_FILL, &ptl, 0, 0);
  189.        GpiSetColor(hps, CLR_WHITE);
  190.        ptl.x = ptl.y = 0;
  191.        GpiMove(hps, &ptl);
  192.        ptl.x = 0; ptl.y = height;
  193.        GpiLine(hps, &ptl);
  194.        ptl.x = width; ptl.y = height;
  195.        GpiLine(hps, &ptl);
  196.        GpiSetColor(hps, CLR_DARKGRAY);
  197.        ptl.x = width; ptl.y = 0;
  198.        GpiLine(hps, &ptl);
  199.        ptl.x = ptl.y = 0;
  200.        GpiLine(hps, &ptl);
  201.        GpiSetColor(hps, CLR_WHITE);
  202.        ptl.x = ptl.y = offset;
  203.        GpiMove(hps, &ptl);
  204.        ptl.x = width - offset; ptl.y = offset;
  205.        GpiLine(hps, &ptl);
  206.        ptl.x = width - offset; ptl.y = height - offset;
  207.        GpiLine(hps, &ptl);
  208.        GpiSetColor(hps, CLR_DARKGRAY);
  209.        ptl.x = offset; ptl.y = height - offset;
  210.        GpiLine(hps, &ptl);
  211.        ptl.x = ptl.y = offset;
  212.        GpiLine(hps, &ptl);
  213.        rcl.xLeft = 3;
  214.        WinDrawText(hps, strlen(statlineText), statlineText, &rcl,
  215.                    pparms.Fore, pparms.Back, orientation);
  216.        WinEndPaint(hps);
  217.       }
  218.      else
  219.       {
  220.        hps = WinBeginPaint(hwnd, 0, 0);
  221.        GpiCreateLogColorTable(hps, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL);
  222.        WinQueryWindowRect(hwnd, &rcl);
  223.        GpiSetColor(hps, pparms.Back);
  224.        GpiBox(hps, DRO_FILL, (PPOINTL) &rcl.xRight, 0L, 0L);
  225.        WinDrawText(hps, strlen(statlineText), statlineText, &rcl,
  226.                    pparms.Fore, pparms.Back, orientation | DT_ERASERECT);
  227.        WinEndPaint(hps);
  228.       } 
  229.      break;
  230.  
  231.     default:
  232.       return(OFrame::OCommand(msg, mp1, mp1));
  233.    }
  234.  return(TRUE);
  235.  
  236. #ifdef __BCPLUSPLUS__
  237.   #pragma warn -par
  238. #endif
  239. }
  240. #ifdef __BCPLUSPLUS__
  241.   #pragma warn .par
  242. #endif
  243.  
  244. // end of source
  245.