home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / srcos2 / vradioc.cpp < prev    next >
C/C++ Source or Header  |  1999-02-03  |  7KB  |  191 lines

  1. //===============================================================
  2. // vradiocc.cxx - RadioButtons - Windows
  3. //
  4. // Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
  5. //
  6. // This file is part of the V C++ GUI Framework, and is covered
  7. // under the terms of the GNU Library General Public License,
  8. // Version 2. This library has NO WARRANTY. See the source file
  9. // vapp.cxx for more complete information about license terms.
  10. //===============================================================
  11. #include <v/vos2.h>     // for OS/2 stuff
  12. #include <v/vradioc.h>  // our definitions
  13. #include <v/vcmdprnt.h> // a command parent
  14. #include <v/vapp.h>
  15. #include <v/vutil.h>
  16.  
  17.   vRadioButtonCmd* vRadioButtonCmd::_RBList = 0;      // empty list to start
  18.  
  19. //================>>> vRadioButtonCmd::vRadioButtonCmd <<<=====================
  20.   vRadioButtonCmd::vRadioButtonCmd(vCmdParent* dp, CommandObject* dc) : vCmd(dp, dc)
  21.   {
  22.     SysDebug(Constructor,"vRadioButtonCmd::vRadioButtonCmd() constructor\n")
  23.     initialize();                       // and initialize
  24.   }
  25.  
  26. //================>>> vRadioButtonCmd::vRadioButtonCmd <<<=====================
  27.   vRadioButtonCmd::vRadioButtonCmd(const vRadioButtonCmd& r) : vCmd(r)
  28.   {
  29.     vSysError("vRadioButtonCmd - V semantics do not support copy constructors!");
  30.   }
  31.  
  32. //===========>>> vRadioButtonCmd::~vRadioButtonCmd <<<======================
  33.   vRadioButtonCmd::~vRadioButtonCmd()
  34.   {
  35.     // We have to remove ourself from the list of all RBs
  36.  
  37.     SysDebug(Destructor,"vRadioButtonCmd::~vRadioButtonCmd() destructor\n")
  38.     if (_RBList == this)                // first one special
  39.     {
  40.       _RBList = _nextRB;
  41.     }
  42.     else
  43.     {
  44.       for (vRadioButtonCmd* rbl = _RBList ; rbl != 0 ; rbl = rbl->_nextRB)
  45.       {
  46.         if (rbl->_nextRB == this)           // we found ourself!
  47.     {
  48.       rbl->_nextRB = _nextRB;         // unlink us
  49.       break;
  50.     }
  51.       }
  52.     }
  53.   }
  54.  
  55. //=====================>>> vRadioButtonCmd::initialize <<<=======================
  56.   void vRadioButtonCmd::initialize(void)
  57.   {
  58.     // build a button command for use in a parent window
  59.  
  60.     _nextRB = _RBList;          // add us in to front of list
  61.     _RBList = this;
  62.     long style = WS_TABSTOP | WS_GROUP | BS_RADIOBUTTON;        // default for a button
  63.  
  64.     if (!(dlgCmd->attrs & CA_Hidden))   // Check for Hidden
  65.       style |= WS_VISIBLE;
  66.     if (_parentWin->_dialogType == aCmdBar)
  67.       style |= BS_NOPOINTERFOCUS;   // don't want focus in Command Bars
  68.  
  69.     CopyToLocal();                      // Make local copies of CmdObject
  70.  
  71.     _w = LabelWidth(_title) + 14;            // set my width
  72.     _h = 8;
  73.  
  74.     _parentWin->SetPosition(_x, _y, _w, _h+3, dlgCmd->cFrame, dlgCmd->cRightOf,
  75.      dlgCmd->cBelow);
  76.     _y += 2;    // Center better
  77.  
  78.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y, _w, _h, _cmdId,
  79.     style, WC_BUTTON, _title, NULL, 0, NULL);
  80.   }
  81.  
  82. //================>>> vRadioButtonCmd::ResetItemValue <<<======================
  83.   void vRadioButtonCmd::ResetItemValue(void)
  84.   {
  85.     // We have to toggle things
  86.     if (_retVal == _origVal)    // No op if no change
  87.       return;
  88.     _retVal = _origVal;         // restore
  89.     WinCheckButton(_parentWin->getParent(), _cmdId, _retVal);
  90.  
  91.     // let parent window handle now
  92.     _parentWin->ProcessCmd(_cmdId, _retVal, dlgCmd->cmdType);
  93.   }
  94.  
  95. //==================>>> vRadioButtonCmd::GetCmdValue <<<=========================
  96.   int vRadioButtonCmd::GetCmdValue(ItemVal id) VCONST
  97.   {
  98.     if (id != _cmdId)
  99.       return -1;
  100.     return _retVal;
  101.   }
  102.  
  103. //================>>> vRadioButtonCmd::SetCmdVal <<<========================
  104.   void vRadioButtonCmd::SetCmdVal(ItemVal val, ItemSetType st)
  105.   {
  106.     SysDebug1(Misc,"vRadioButtonCmd::SetCmdVal(val:%d)\n",val)
  107.     HWND myHwnd = GetMyHwnd(_cmdId);
  108.     if (st == Sensitive)
  109.     {
  110.       _Sensitive = val;               // set
  111.       WinEnableWindow(myHwnd, val);
  112.     }
  113.     else if (st == Hidden)              // hide or unhide
  114.     {
  115.       if (val)
  116.       {
  117.     WinShowWindow(myHwnd,FALSE);
  118.       }
  119.       else
  120.       {
  121.     WinShowWindow(myHwnd,TRUE);
  122.       }
  123.     }
  124.  
  125.     else if (st == Value || st == Checked)
  126.     {
  127.       _retVal = val;                  // set
  128.       if (_retVal)                    // Need to turn off other
  129.       {
  130.     // We have to toggle things, so scan the list of all radio buttons,
  131.     // searching for other buttons in the same frame
  132.     ItemVal ourFrame = dlgCmd->cFrame;          // remember our frame
  133.     for (vRadioButtonCmd* rbl = _RBList ; rbl != 0 ; rbl = rbl->_nextRB)
  134.     {
  135.       CommandObject* dc = rbl->dlgCmd;        // shorthand
  136.       if (dc->cFrame == ourFrame)             // Radio Button in same frame
  137.       {
  138.         if (rbl->_retVal && rbl->_cmdId != _cmdId)  // This one was ON, turn off
  139.         {
  140.           rbl->_retVal = 0;                       // toggle
  141.           WinCheckButton(_parentWin->getParent(),rbl->_cmdId, 0);
  142.           break;
  143.         }
  144.       }
  145.     } /*for*/
  146.       }
  147.       WinCheckButton(_parentWin->getParent(), _cmdId, val);
  148.     }
  149.   }
  150.  
  151. //================>>> vRadioButtonCmd::SetCmdStr <<<=========================
  152.   void vRadioButtonCmd::SetCmdStr(VCONST char *str)
  153.   {
  154.     SysDebug1(Misc,"vRadioButtonCmd::SetCmdStr(str:%s)\n",str)
  155.     WinSetDlgItemText(_parentWin->getParent(), _cmdId, str);
  156.     _title = str;
  157.   }
  158.  
  159. //====================>>> vRadioButtonCmd::CmdCallback <<<=======================
  160.   void vRadioButtonCmd::CmdCallback(UINT uMsg, MPARAM mp1, MPARAM mp2)
  161.   {
  162.     // We have to toggle things, so scan the list of all radio buttons,
  163.     // searching for other buttons in the same frame
  164.     ItemVal ourFrame = dlgCmd->cFrame;          // remember our frame
  165.     for (vRadioButtonCmd* rbl = _RBList ; rbl != 0 ; rbl = rbl->_nextRB)
  166.     {
  167.       CommandObject* dc = rbl->dlgCmd;        // shorthand
  168.       if (dc->cFrame == ourFrame)             // Radio Button in same frame
  169.       {
  170.         if (rbl->_retVal && rbl->_cmdId != _cmdId)  // This one was ON, turn off
  171.         {
  172.           rbl->_retVal = 0;                       // toggle
  173.       WinCheckButton(_parentWin->getParent(),rbl->_cmdId, 0);
  174.  
  175.       // inform parent of change
  176.       _parentWin->ProcessCmd(rbl->_cmdId, rbl->_retVal, dc->cmdType);
  177.       break;
  178.     }
  179.       }
  180.     }
  181.     // Now, we need to turn this RadioButton ON
  182.     if (!_retVal)
  183.     {
  184.       _retVal = 1;                    // toggle
  185.       SetCmdVal(1,Checked);
  186.       // and let the parent window know about the change
  187.       _parentWin->ProcessCmd(_cmdId, _retVal, dlgCmd->cmdType);
  188.     }
  189.   }
  190.  
  191.