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

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