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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OButtonBar.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/OHelpPopup.cpp 1.50 1996/08/11 23:49:17 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OHelpPopup.hpp>
  40. #include <OMessage.hpp>
  41.  
  42. #define OBubbleRes 65001
  43.  
  44.  
  45.  
  46. OHelpPopup::OHelpPopup()
  47.   : OStatusLine(OBubbleRes, HWND_DESKTOP, FALSE),
  48.     showTime(500)
  49. {
  50.  style |= FCF_BORDER;
  51.  setOrientation(DT_CENTER | DT_VCENTER);
  52.  
  53.  try
  54.    {
  55.     createStatusLine();
  56.    }
  57.  catch(OPMException ex)
  58.    {  
  59.     throw OPMException(OCL::error(65), 0, OException::unrecoverable);
  60.    }
  61. }
  62.  
  63.  
  64. OHelpPopup::~OHelpPopup()
  65.  {}
  66.  
  67.  
  68. PSZ OHelpPopup::isOfType() const
  69. {
  70.  return("OHelpPopup");
  71. }
  72.  
  73.  
  74. ULONG OHelpPopup::showTimeout() const
  75. {
  76.  return(showTime);
  77. }
  78.  
  79.  
  80. OStatusLine& OHelpPopup::createStatusLine()
  81. {
  82.  createFrame("OHelpPopup");
  83.  setFont("8.Helv").setBackColor(RGB_YELLOW).setForeColor(RGB_BLACK);
  84.  return(*this);
  85. }
  86.  
  87.  
  88. OHelpPopup& OHelpPopup::setPopupTimeout(ULONG timeout)
  89. {
  90.  showTime = timeout;
  91.  return(*this);
  92. }
  93.  
  94. OHelpPopup& OHelpPopup::startPopupTimer()
  95. {
  96.  WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, OHELP_POPUP_SHOWTIMER, showTime);
  97.  return(*this);
  98. }
  99.  
  100.  
  101. OHelpPopup& OHelpPopup::stopPopupTimer()
  102. {
  103.  WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, OHELP_POPUP_SHOWTIMER);
  104.  return(*this);
  105. }
  106.  
  107.  
  108. OHelpPopup& OHelpPopup::timePopup(PCSZ helpText)
  109. {
  110.  hideFrame();
  111.  
  112.  if (helpText) {
  113.    textToShow << (PSZ) helpText;
  114.    startPopupTimer(); }
  115.  else
  116.    textToShow << (PSZ) NULL;
  117.  return(*this);
  118. }
  119.  
  120. OHelpPopup& OHelpPopup::showPopup(PCSZ helpText)
  121. {
  122.  RECTL   rect;
  123.  POINTL  pointl;
  124.  SWP     swp, swpSys;
  125.  
  126.  hideFrame();
  127.  
  128.  if (!helpText)
  129.    return(*this);
  130.  
  131.  swp.cx = 200;
  132.  swp.cy = 200;
  133.  WinSetWindowPos(frame, NULLHANDLE, 0, 0, swp.cx, swp.cy, SWP_SIZE);
  134.  
  135.  hps = WinGetPS(client);
  136.  
  137.  rect.xLeft   = 0;
  138.  rect.xRight  = 200;
  139.  rect.yBottom = 0;
  140.  rect.yTop    = 200;
  141.  
  142.  WinDrawText(hps, strlen(helpText), (PCH)helpText, &rect, 
  143.              0L, 0L, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT);
  144.  swp.cx = rect.xRight - rect.xLeft + 8;
  145.  WinSetWindowPos(frame, NULLHANDLE, 0, 0, swp.cx, getHeight(), SWP_SIZE);
  146.  WinReleasePS(hps);
  147.  
  148.  setText(helpText);
  149.  
  150.  WinQueryPointerPos(HWND_DESKTOP, &pointl);
  151.  
  152.  swpSys.cx=WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  153.  swpSys.cy=WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  154.  swp.x = ((pointl.x + getWidth())  < swpSys.cx) ?
  155.          pointl.x + 3 : pointl.x - getWidth() - 3;
  156.  swp.y = ((pointl.y + getHeight()) < swpSys.cy) ?
  157.          pointl.y + 3 : pointl.y - getHeight() - 3;
  158.  WinSetWindowPos(frame, HWND_TOP, swp.x, swp.y, swp.cx, swp.cy,
  159.                  SWP_MOVE | SWP_SHOW | SWP_ZORDER);
  160.  return(*this);
  161. }
  162.  
  163.  
  164. OHelpPopup& OHelpPopup::hidePopup()
  165. {
  166.  stopPopupTimer().hideFrame();
  167.  return(*this);
  168. }
  169.  
  170. BOOL OHelpPopup::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  171. {
  172.  switch(msg)
  173.   {
  174.    case WM_TIMER:
  175.     {
  176.      switch(SHORT1FROMMP(mp1))
  177.       {
  178.        case OHELP_POPUP_SHOWTIMER:
  179.         stopPopupTimer();
  180.         showPopup(textToShow);          
  181.         break;
  182.       }
  183.     }
  184.  
  185.    case WM_DESTROY:
  186.      break;
  187.    case WM_CLOSE:
  188.      destroyFrame();
  189.      break;
  190.  
  191.    default:
  192.      return(OStatusLine::OCommand(msg, mp1, mp2));
  193.   } 
  194.  return(TRUE);
  195. }
  196.  
  197.  
  198. // end of source  
  199.