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

  1. //===============================================================
  2. // vchkboxc.cxx - Checkbox - Windows version
  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/vchkboxc.h> // our definitions
  13. #include <v/vcmdprnt.h> // a command parent
  14. #include <v/vapp.h>
  15. #include <v/vutil.h>
  16. //=================>>> vCheckBoxCmd::~vCheckBoxCmd <<<=======================
  17.   vCheckBoxCmd::~vCheckBoxCmd()
  18.   {
  19.     SysDebug(Destructor,"vCheckBoxCmd::~vCheckBoxCmd() destructor\n")
  20.   }
  21. //=================>>> vCheckBoxCmd::vCheckBoxCmd <<<=======================
  22.   vCheckBoxCmd::vCheckBoxCmd(vCmdParent* dp, CommandObject* dc) :
  23.         vCmd(dp, dc)
  24.   {
  25.     SysDebug(Constructor,"vCheckBoxCmd::vCheckBoxCmd() constructor\n")
  26.     initialize();                       // and initialize
  27.   }
  28. //=====================>>> vCheckBoxCmd::initialize <<<=======================
  29.   void vCheckBoxCmd::initialize(void)
  30.   {
  31.     long style = WS_TABSTOP | WS_GROUP | BS_CHECKBOX;   // default for a button
  32.     if (!(dlgCmd->attrs & CA_Hidden))   // Check for Hidden
  33.     style |= WS_VISIBLE;
  34.     if (_parentWin->_dialogType == aCmdBar)
  35.     style |= BS_NOPOINTERFOCUS;   // don't want focus in Command Bars
  36.  
  37.     CopyToLocal();                      // Make local copies of CmdObject
  38.  
  39.     _w = LabelWidth(_title) + 14;            // set my width
  40.     _h = 10;                             // default height
  41.  
  42.     _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame, dlgCmd->cRightOf,
  43.      dlgCmd->cBelow);
  44.  
  45.     // inc y positions control lower in the allocated dialog space
  46.     // dec h makes control smaller in allocated space
  47.     _y += 3;
  48.     _h -= 3;   // we play this game to get better positioning in a frame
  49.  
  50.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y, _w, _h, _cmdId,
  51.     style, WC_BUTTON, _title, NULL, 0, NULL);
  52.  
  53.   }
  54. //================>>> vCheckBoxCmd::ResetItemValue <<<======================
  55.   void vCheckBoxCmd::ResetItemValue(void)
  56.   {
  57.     // We have to toggle things
  58.     if (_retVal == _origVal)    // No op if no change
  59.         return;
  60.     _retVal = _origVal;         // restore
  61.     if (_retVal)                        // depends on state
  62.       {
  63.         SetCmdVal(1, Checked);
  64.       }
  65.     else
  66.       {
  67.         SetCmdVal(0, Checked);
  68.       }
  69.     // let parent window handle now
  70.     _parentWin->ProcessCmd(_cmdId, _retVal, dlgCmd->cmdType);
  71.   }
  72. //==================>>> vCheckBoxCmd::GetCmdValue <<<=========================
  73.   int vCheckBoxCmd::GetCmdValue(ItemVal id) VCONST
  74.   {
  75.     if (id != _cmdId)
  76.     return -1;
  77.     return _retVal;
  78.   }
  79. //================>>> vCheckBoxCmd::SetCmdVal <<<============================
  80.   void vCheckBoxCmd::SetCmdVal(ItemVal val, ItemSetType st)
  81.   {
  82.     SysDebug2(Misc,"vCheckBoxCmd::SetCmdVal(id:%d val:%d)\n",_cmdId, val)
  83.     HWND myHwnd = GetMyHwnd(_cmdId);
  84.     if (st == Sensitive)
  85.       {
  86.     _Sensitive = val;               // set
  87.     WinEnableWindow (myHwnd, val);
  88.  
  89.       }
  90.     else if (st == Hidden)              // hide or unhide
  91.       {
  92.     if (val)
  93.       {
  94.         WinShowWindow (myHwnd, FALSE);
  95.       }
  96.     else
  97.       {
  98.         WinShowWindow (myHwnd, TRUE);
  99.       }
  100.       }
  101.     else if (st == Value || st == Checked)
  102.       {
  103.     _retVal = val;                  // set
  104.     WinCheckButton(_parentWin->getParent(),_cmdId, val);
  105.       }
  106.   }
  107. //================>>> vCheckBoxCmd::SetCmdStr <<<============================
  108.   void vCheckBoxCmd::SetCmdStr(VCONST char* str)
  109.   {
  110.     SysDebug1(Misc,"vCheckBoxCmd::SetCmdStr(str:%s)\n",str)
  111.     WinSetDlgItemText(_parentWin->getParent(), _cmdId, str);
  112.  
  113.     _title = str;
  114.   }
  115. //====================>>> vCheckBoxCmd::CmdCallback <<<=======================
  116.   void vCheckBoxCmd::CmdCallback(UINT uMsg, MPARAM mp1, MPARAM mp2)
  117.   {
  118.     if (_retVal)                        // depends on state
  119.       {
  120.     SetCmdVal(0, Checked);
  121.       }
  122.     else
  123.       {
  124.     SetCmdVal(1, Checked);
  125.       }
  126.     // let parent window handle now
  127.     _parentWin->ProcessCmd(_cmdId, _retVal, dlgCmd->cmdType);
  128.   }
  129.