home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OButtonBar.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  10KB  |  391 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. // $Header: W:/Projects/OCL/Source/rcs/OButtonBar.cpp 1.50 1996/08/11 23:49:09 B.STEIN Release $
  31.  
  32. #define __OCL_SOURCE__
  33.  
  34. #define OINCL_OSTRING
  35. #define OINCL_BASE
  36.  
  37. #include <ocl.hpp>
  38. #include <OButtonBar.hpp>
  39.  
  40. #if defined(__EMX__)
  41.   template class OList<OGraphicsButton>;
  42.   template class OIterator<OGraphicsButton>;
  43. #endif 
  44.  
  45.  
  46. OButtonBar::OButtonBar(const ULONG id,
  47.                        const HWND parentWindow,
  48.                        const BOOL bubbleHelp)
  49.   : OFrame(id, FCF_NOBYTEALIGN, CS_SIZEREDRAW | CS_HITTEST),
  50.     orientation(OButtonBar::left2right),
  51.     drawStyle(OButtonBar::fillButton),
  52.     currentButton(0),
  53.     bubbleHelper(bubbleHelp)
  54. {
  55.  setParent(parentWindow);
  56.  setOwner(parentWindow);
  57.  initButtonBarDefaults();
  58. }
  59.  
  60.  
  61. OButtonBar::OButtonBar(const ULONG id,
  62.                        const OFrame& parentWindow, 
  63.                        const BOOL bubbleHelp)
  64.   : OFrame(id, FCF_NOBYTEALIGN, CS_SIZEREDRAW),
  65.     orientation(OButtonBar::left2right),
  66.     drawStyle(OButtonBar::fillButton),
  67.     currentButton(0),
  68.     bubbleHelper(bubbleHelp)
  69. {
  70.  setParent(parentWindow.hwnd);
  71.  setOwner(parentWindow.hwnd);
  72.  initButtonBarDefaults();
  73. }
  74.  
  75. OButtonBar::OButtonBar(const ULONG id,
  76.                        const pOFrame parentWindow, 
  77.                        const BOOL bubbleHelp)
  78.   : OFrame(id, FCF_NOBYTEALIGN, CS_SIZEREDRAW),
  79.     orientation(OButtonBar::left2right),
  80.     drawStyle(OButtonBar::fillButton),
  81.     currentButton(0),
  82.     bubbleHelper(bubbleHelp)
  83. {
  84.  setParent(parentWindow->hwnd);
  85.  setOwner(parentWindow->hwnd);
  86.  initButtonBarDefaults();
  87. }
  88.  
  89.  
  90.  
  91. OButtonBar::~OButtonBar()
  92. {
  93.  buttons.init();
  94. }
  95.  
  96.  
  97. PSZ OButtonBar::isOfType() const
  98.  return("OButtonBar"); 
  99. }
  100.  
  101.  
  102. OButtonBar& OButtonBar::initButtonBarDefaults()
  103. {
  104.  bHeight = 40;
  105.  bWidth = 40;
  106.  picSize = 32;
  107.  pparms.Fore = SYSCLR_WINDOWTEXT;
  108.  pparms.Back = SYSCLR_WINDOW;
  109.  strcpy(pparms.Font, "8.Helv");
  110.  return(*this);
  111. }
  112.  
  113.  
  114. OButtonBar& OButtonBar::createButtonBar()
  115. {
  116.  createFrame("OButtonBar");
  117.  setupButtons();
  118.  return(*this);
  119. }
  120.  
  121.  
  122. OButtonBar& OButtonBar::destroyButtons()
  123. {
  124.  buttons.allElementsDo(btn_destroy);
  125.  return(*this);
  126. }
  127.  
  128.  
  129. OButtonBar& OButtonBar::enableButtons()
  130. {
  131.  buttons.allElementsDo(btn_enable);
  132.  return(*this);
  133. }
  134.  
  135. OButtonBar& OButtonBar::disableButtons()
  136. {
  137.  buttons.allElementsDo(btn_disable);
  138.  return(*this);
  139. }
  140.  
  141. PSZ OButtonBar::requestHelpText(const ULONG id, const BOOL isHandle)
  142. {
  143.  if (!buttons.isEmpty())
  144.   {
  145.    pOGraphicsButton pgrb = buttons.getFirst();
  146.  
  147.    while(pgrb)
  148.    {
  149.     if (((isHandle) && (pgrb->hwnd == id)) ||
  150.        ((!isHandle) && (pgrb->res == id)))
  151.         return(pgrb->helpText);
  152.     pgrb = buttons.getNext();
  153.    }
  154.   }
  155.  return(NULL);
  156. }
  157.  
  158.  
  159. PSZ OButtonBar::requestHelpText()
  160. {
  161.  return(requestHelpText(NULLHANDLE, TRUE));
  162. }
  163.  
  164.  
  165. OButtonBar& OButtonBar::setupButtons()
  166. {
  167.  ULONG i = 0,
  168.        posx = 0,
  169.        posy = 0;
  170.  
  171.  pOGraphicsButton pgrb = buttons.getFirst();
  172.  
  173.  hideFrame();
  174.  
  175.  while(pgrb) 
  176.   {
  177.    switch(orientation) {
  178.      case up2down:
  179.        posx = 0;
  180.        posy = (buttons.numberOfElements() - i - 1)*bHeight;
  181.        break;
  182.      case left2right:
  183.        posx = i*bWidth;
  184.        posy = 0;
  185.        break; }
  186.    
  187.    try
  188.     {
  189.      pgrb->parent     = hwnd;
  190.      pgrb->owner      = hwnd;
  191.      pgrb->sizepos.x  = posx;
  192.      pgrb->sizepos.y  = posy;
  193.      pgrb->sizepos.cx = bWidth;
  194.      pgrb->sizepos.cy = bHeight;
  195.      pgrb->createButton();
  196.     }
  197.    catch(OPMException ex) {}
  198.    i++;
  199.    pgrb = buttons.getNext();
  200.   }
  201.  showFrame();
  202.  return(*this);
  203. }
  204.  
  205.  
  206.  
  207. OButtonBar& OButtonBar::setButtonDimensions(const ULONG height, const ULONG width)
  208. {
  209.  bHeight = height;
  210.  bWidth  = width; 
  211.  return(*this);
  212. }
  213.  
  214.  
  215. OButtonBar& OButtonBar::setPicSize(const ULONG length)
  216. {
  217.  picSize = length;
  218.  return(*this);
  219. }
  220.  
  221.  
  222. OButtonBar& OButtonBar::setOrientation(const ULONG type) 
  223. {
  224.  orientation = type; 
  225.  return(*this);
  226. }
  227.  
  228.  
  229. OButtonBar& OButtonBar::setDrawStyle(const ULONG Style) 
  230. {
  231.  drawStyle = Style; 
  232.  return(*this);
  233. }
  234.  
  235.  
  236. BOOL OButtonBar::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  237. {
  238.  switch(msg)
  239.    {
  240.     case WM_PAINT:
  241.     case WM_ERASEBACKGROUND:
  242.      WinQueryWindowRect(hwnd, &rcl);
  243.      if (orientation == up2down)
  244.       {
  245.        ULONG             newHeight = rcl.yTop - rcl.yBottom;
  246.        ULONG             i = 1;
  247.        pOGraphicsButton  btn = buttons.getFirst();
  248.  
  249.        while(btn)
  250.         {
  251.          WinSetWindowPos(btn->hwnd, HWND_TOP, 0, 
  252.                          newHeight - i*bHeight,
  253.                          bWidth, bHeight, SWP_MOVE | SWP_SHOW | SWP_SIZE);
  254.          i++;
  255.          btn = buttons.getNext();
  256.         }
  257.        } 
  258.      if (drawStyle == OButtonBar::fillButton)
  259.       {
  260.        hps = WinBeginPaint(hwnd, 0, NULL);
  261.        GpiCreateLogColorTable(hps, LCOL_RESET, LCOLF_RGB, 0L, 0L, NULL);
  262.        WinFillRect(hps, &rcl, SYSCLR_BUTTONMIDDLE);
  263.        if (orientation == left2right)
  264.          fillBTN.drawButton(hps,
  265.                             bWidth * buttons.numberOfElements(),
  266.                             0,
  267.                             rcl.xRight - rcl.xLeft - bWidth * buttons.numberOfElements(),  
  268.                             bHeight);
  269.        else
  270.          fillBTN.drawButton(hps,
  271.                             0,
  272.                             0,
  273.                             bWidth,
  274.                             rcl.yTop - rcl.yBottom - bHeight * buttons.numberOfElements());  
  275.        WinEndPaint(hps);
  276.       } 
  277.      break;
  278.  
  279. // the following two messages can be removed when using Warp with Fixpack 16 or up
  280.  
  281.     case WM_MOUSEMOVE:
  282.       if (currentButton != 0)
  283.        {
  284.         currentButton = 0;
  285.         WinSendMsg(parent, WM_CONTROL,
  286.                  MPFROM2SHORT(OBUTTONBAR_MOVEOVER, 0),
  287.                  MPFROMP((PSZ)""));       
  288.        }
  289.       return(FALSE);
  290.  
  291.     case WM_CONTROLPOINTER:
  292.       if (SHORT1FROMMP(mp1) != currentButton)
  293.        {
  294.         pOGraphicsButton button = buttons.getFirst();
  295.  
  296.         currentButton = SHORT1FROMMP(mp1);
  297.         while((button) && (button->res != currentButton))
  298.           button = buttons.getNext();
  299.         if (button)    
  300.             WinSendMsg(parent, WM_CONTROL,
  301.                  MPFROM2SHORT(OBUTTONBAR_MOVEOVER, currentButton),
  302.                  MPFROMP(button->helpText.getText()));       
  303.        }  
  304.       return(FALSE);
  305.  
  306. // end of remove
  307.  
  308.     case WM_CONTROL:
  309.      switch(SHORT1FROMMP(mp1))
  310.       {
  311.        case OGRBTN_WINDOWENTER:
  312.          currentButton = SHORT2FROMMP(mp1);
  313.          if (bubbleHelper)
  314.            bubbleHelpWin.timePopup((PSZ)PVOIDFROMMP(mp2));
  315.          WinSendMsg(parent, WM_CONTROL,
  316.                     MPFROM2SHORT(OBUTTONBAR_MOVEOVER, SHORT2FROMMP(mp1)),
  317.                     MPFROMP((PSZ)PVOIDFROMMP(mp2)));       
  318.          break;
  319.  
  320.        case OGRBTN_WINDOWLEAVE:
  321.          currentButton = 0;
  322.          if (bubbleHelper)
  323.            bubbleHelpWin.hidePopup();
  324.          WinSendMsg(parent, WM_CONTROL,
  325.                     MPFROM2SHORT(OBUTTONBAR_MOVEOVER, SHORT2FROMMP(mp1)),
  326.                     MPFROMP((PSZ)PVOIDFROMMP(mp2)));       
  327.          break;
  328.  
  329.        case OGRBTN_SETHILITE:
  330.          if (bubbleHelper)
  331.             bubbleHelpWin.hidePopup();
  332.          break;        
  333.  
  334.        case OGRBTN_PRESPARAMCHANGED: {
  335.          pOGraphicsButton button = (pOGraphicsButton)PVOIDFROMMP(mp2);
  336.          if (button) {
  337.            button->getFont();
  338.            bubbleHelpWin.setFont(button->pparms.Font); }
  339.          break; }
  340.       }
  341.      break;
  342.  
  343.     case WM_BUTTON1DOWN:
  344.     case WM_BUTTON2DOWN:
  345.     case WM_BUTTON3DOWN:
  346.      {
  347.       pOGraphicsButton button = buttons.getFirst();
  348.  
  349.       while((button) && (button->res != currentButton))
  350.         button = buttons.getNext();
  351.       if (bubbleHelper)
  352.         bubbleHelpWin.hidePopup();
  353.       if (button)
  354.         WinSendMsg(parent, WM_CONTROL, MPFROM2SHORT(msg, button->res), mp1);
  355.      } 
  356.      break;        
  357.     
  358.     case WM_COMMAND:
  359.      WinSendMsg(parent, msg, mp1, mp2);
  360.      break;
  361.  
  362.     case WM_CLOSE:
  363.     case WM_DESTROY:
  364.      destroyButtons();
  365.      break;
  366.  
  367.     default:
  368.      return(OFrame::OCommand(msg, mp1, mp2));
  369.    }
  370.  return(TRUE);
  371. }
  372.  
  373.  
  374. void OButtonBar::_enable::applyToElement (OGraphicsButton* elem)
  375. {
  376.  elem->enable();
  377. }
  378.  
  379. void OButtonBar::_disable::applyToElement (OGraphicsButton* elem)
  380. {
  381.  elem->disable();
  382. }
  383.  
  384. void OButtonBar::_destroy::applyToElement (OGraphicsButton* elem)
  385. {
  386.  elem->destroy();
  387. }
  388.  
  389. // end of source  
  390.