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

  1. //===============================================================
  2. // vlistc.cxx   - ListCmd - 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/vlistc.h>   // our definitions
  13. #include <v/vcmdprnt.h> // a command parent
  14. #include <v/vapp.h>
  15.  
  16. //=================>>> vListCmd::vListCmd <<<=======================
  17.   vListCmd::vListCmd(vCmdParent* dp, CommandObject* dc) :
  18.         vCmd(dp, dc)
  19.   {
  20.     _maxWidth = 10;
  21.     SysDebug(Constructor,"vListCmd::vListCmd() constructor\n")
  22.  
  23.     CopyToLocal();                      // Make local copies of CmdObject
  24.  
  25.     // First, setup the list
  26.     _listRows = 8;
  27.     if (dlgCmd->attrs & CA_Size)    // Size specified
  28.     {
  29.       if (dlgCmd->size > 0 && dlgCmd->size <= 32)
  30.         _listRows = dlgCmd->size;
  31.     }
  32.  
  33.     SetupList();
  34.  
  35.     _maxWidth = (dlgCmd->attrs & CA_Large) ? (_maxWidth * 3)/2 : _maxWidth;
  36.  
  37.     long style = (_parentWin->_dialogType != aCmdBar)
  38.          ? WS_TABSTOP | WS_GROUP
  39.          : WS_GROUP;
  40.  
  41.     if (!(dlgCmd->attrs & CA_Hidden))   // Check for Hidden
  42.     {
  43.       style |= WS_VISIBLE;
  44.       _isVisible = 1;
  45.     }
  46.     else
  47.       _isVisible = 0;
  48.  
  49.     style |= LS_NOADJUSTPOS;
  50.  
  51.     _w = _maxWidth*4+4;                // set my width
  52.  
  53.     if ((dlgCmd->attrs & CA_ListWidth) && dlgCmd->retVal > _w)
  54.       _w = dlgCmd->retVal;         // CA_ListWidth V 1.18 BEW
  55.  
  56. //    _h = 54;                         // default height (8 rows)
  57.     _h = LONG( (LabelHeight() * _listRows) );  // default height (listRows * 6 each row)
  58.  
  59.     _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame, dlgCmd->cRightOf,
  60.      dlgCmd->cBelow);
  61.  
  62.     _y += 1;
  63.  
  64.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y, _w, _h, _cmdId,
  65.     style, WC_LISTBOX, _title, NULL, 0, NULL);
  66.  
  67.   }
  68. //=======================>>> vListCmd::~vListCmd <<<=======================
  69.   vListCmd::~vListCmd()
  70.   {
  71.     SysDebug(Constructor,"vListCmd::~vListCmd() Destructor\n")
  72.   }
  73. //==================>>> vListCmd::GetCmdValue <<<=========================
  74.   int vListCmd::GetCmdValue(ItemVal id) VCONST
  75.   {
  76.     if (id != _cmdId)
  77.     return -1;
  78.     return _curSelection;       // return currently selected item
  79.   }
  80. //=====================>>> vListCmd::SetCmdVal <<<=========================
  81.   void vListCmd::SetCmdVal(ItemVal val, ItemSetType st)
  82.   {
  83.     SysDebug2(Misc,"vListCmd::SetCmdVal(val:%d, type:%d)\n",val,st)
  84.     HWND myHwnd = GetMyHwnd(_cmdId);
  85.  
  86.     switch (st)
  87.     {
  88.       case Sensitive:
  89.     _Sensitive = val;               // set
  90.     WinEnableWindow (myHwnd, val);
  91.     break;
  92.  
  93.       case Hidden:
  94.     if (val)
  95.         {
  96.       WinShowWindow (myHwnd, FALSE);
  97.           _isVisible = 0;
  98.         }
  99.     else
  100.         {
  101.       WinShowWindow (myHwnd, TRUE);
  102.           _isVisible = 1;
  103.         }
  104.     break;
  105.  
  106.       case ChangeList:
  107.       case ChangeListPtr:
  108.       {
  109.     if (st == ChangeListPtr)
  110.         _itemList = dlgCmd->itemList;
  111.       // Change list is used both for initial display,
  112.       // and when user changes the list.
  113.       WinSendDlgItemMsg(_parentWin->getParent(),
  114.         _cmdId, LM_DELETEALL,0,0); // Clear current
  115.  
  116.       int oldMax = _maxWidth;         // track current max width
  117.       SetupList();                    // resetup the list
  118.       if (oldMax > _maxWidth)
  119.         _maxWidth = oldMax;         // don't let it get narrower
  120.  
  121.       // populate the listbox, disable updates to speed it up
  122.       WinEnableWindowUpdate(myHwnd, FALSE);
  123.       for (int ixx = 0 ; ixx < _numItems ; ++ixx)
  124.       {
  125.         // Add each item to the list
  126. //        WinSendMsg(myHwnd, LM_INSERTITEM, MPFROMLONG(ixx), MPFROMP(_fullList[ixx]));
  127.         WinInsertLboxItem(myHwnd, ixx, _fullList[ixx]);
  128.       }
  129.       WinEnableWindow (myHwnd, _Sensitive);
  130.  
  131.       if (_isVisible)
  132.         WinShowWindow(myHwnd,TRUE);
  133.       else
  134.             WinShowWindow(myHwnd,FALSE);
  135.  
  136.       _curSelection = val;
  137.       WinSendDlgItemMsg(_parentWin->getParent(),
  138.         _cmdId, LM_SELECTITEM, MPFROMLONG(_curSelection), (MPARAM) TRUE);
  139.       return;
  140.       }
  141.  
  142.       case Value:       // select a given item
  143.       {
  144.     if (val >= _numItems )
  145.         return;
  146.     _curSelection = val;    // change the current value
  147.     if (val < 0)            // unselect
  148.       {
  149.         _curSelection = -1;
  150.         return;
  151.       }
  152.     // Now set appropriate _curSelection
  153.     // in windows, -1 means unselect, so this works for both
  154.     WinSendDlgItemMsg(_parentWin->getParent(),
  155.         _cmdId, LM_SELECTITEM, MPFROMLONG(_curSelection), (MPARAM) TRUE);
  156.     break;
  157.       }
  158.     }
  159.   }
  160.  
  161. //====================>>> vListCmd::SetupList <<<=======================
  162.   void vListCmd::SetupList(void)
  163.   {
  164.     // Set up the list for use
  165.     int len;
  166.     _curSelection = -1;
  167.     _fullList = (char**)_itemList;      // private copy of list
  168.     // Calculate widest item and number of items
  169.     for ( _numItems = 0 ; _fullList && _fullList[_numItems] != 0 ; ++_numItems)
  170.       {
  171.     len = strlen(_fullList[_numItems]);     // strlen
  172.     if (len > _maxWidth)
  173.         _maxWidth = len;            // track largest so far
  174.       }
  175.     if (_curSelection < 0)              // make a safe default choice
  176.     _curSelection = 0;
  177.     else if (_curSelection >= _numItems)
  178.     _curSelection = _numItems - 1;
  179.     // Note that at this point _numItems is how many items are
  180.     // in the user supplied list.
  181.   }
  182. //===================>>> vListCmd::CmdCallback <<<=======================
  183.   void vListCmd::CmdCallback(UINT uMsg, MPARAM mp1, MPARAM mp2)
  184.   {
  185.     // See if we are getting a message we care about
  186. //    SysDebug1(OS2Dev,"vListCmd::CmdCallBack \n")
  187.     if (uMsg == WM_CONTROL)
  188.     {
  189.       if (SHORT2FROMMP(mp1) == LN_SELECT || SHORT2FROMMP(mp1) == LN_ENTER)
  190.       {
  191.     // Retrieve the current selection
  192.     if ((_curSelection = (LONG) WinSendDlgItemMsg(_parentWin->getParent(),
  193.         _cmdId, LM_QUERYSELECTION, 0, 0)) ==  LIT_NONE)
  194.     {
  195.       _curSelection = -1;
  196.       return;
  197.     }
  198.  
  199.     if (_curSelection >= _numItems )    // Safety check
  200.       _curSelection = -1;
  201.  
  202.     if (!(dlgCmd->attrs & CA_NoNotify)) // Notify on each selection?
  203.       _parentWin->ProcessCmd(_cmdId, _curSelection, dlgCmd->cmdType);
  204.       }
  205.     }
  206.   }
  207.