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

  1. //===============================================================
  2. // vprogrsc.cxx - Progress Bar - 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/vprogrsc.h> // our definitions
  13. #include <v/vcmdprnt.h> // a command parent
  14. #include <v/vapp.h>
  15. #include <v/vutil.h>
  16.  
  17. //=================>>> vProgressCmd::vProgressCmd <<<=======================
  18.   vProgressCmd::vProgressCmd(vCmdParent* dp, CommandObject* dc) :
  19.         vCmd(dp, dc)
  20.   {
  21.     initialize();                       // and initialize
  22.   }
  23. //=======================>>> vProgressCmd::~vProgressCmd <<<===================
  24.   vProgressCmd::~vProgressCmd()
  25.   {
  26.     SysDebug(Constructor,"vProgressCmd::~vProgressCmd() Destructor\n")
  27.   }
  28. //=====================>>> vProgressCmd::initialize <<<=======================
  29.   void vProgressCmd::initialize()
  30.   {
  31.     SysDebug(Constructor,"vProgressCmd::vProgressCmd() constructor\n")
  32.     CopyToLocal();
  33.     long style = SLS_PRIMARYSCALE1 | SLS_READONLY |
  34.          SLS_SNAPTOINCREMENT | SLS_RIBBONSTRIP;
  35.  
  36.     if (_parentWin->_dialogType != aCmdBar)
  37.     style |= WS_TABSTOP | WS_GROUP;  // default for a button
  38.     else
  39.     style |= WS_GROUP;
  40.  
  41.     if (!(dlgCmd->attrs & CA_Hidden))   // Check for Hidden
  42.     style |= WS_VISIBLE;
  43.  
  44.     int* minMax = (int *)_itemList;             // giving range?
  45.     _minVal = 0; _maxVal = 100;                 // default min/max
  46.  
  47.     if (minMax != 0)                            // They gave a range list
  48.       {
  49.     _minVal = minMax[0];
  50.     _maxVal = minMax[1];
  51.       }
  52.  
  53.     if (_minVal > _maxVal)
  54.     {
  55.     SysDebug2(BadVals,"vProgressCmd:vSliderCmd - bad range %d to %d\n",_minVal,_maxVal)
  56.     _minVal = 0; _maxVal = 100;     // make some sense!
  57.     }
  58.  
  59.     if (_retVal < _minVal)      // set a legal value for the top
  60.     _curVal = _minVal;
  61.     else if (_retVal > _maxVal)
  62.     _curVal = _maxVal;
  63.     else
  64.     _curVal = _retVal;
  65.  
  66.  
  67.     // Set the size of the slider
  68.     if (dlgCmd->attrs & CA_Vertical)  // vertical bar
  69.     {
  70.       style |= SLS_VERTICAL | SLS_LEFT;
  71.  
  72.       _h = 56;               // regular size
  73.       _scd.usScale1Increments = 101;
  74.       _scd.usScale1Spacing = 1;
  75.  
  76.       if (dlgCmd->attrs & CA_Large)
  77.       {
  78.     _h = 106;
  79.     _scd.usScale1Increments = 101;
  80.     _scd.usScale1Spacing = 2;
  81.       }
  82.       else if (dlgCmd->attrs & CA_Small)
  83.       {
  84.     _h = 31;
  85.     _scd.usScale1Increments = 51;
  86.     _scd.usScale1Spacing = 1;
  87.       }
  88.       if (dlgCmd->attrs & CA_NoLabel)
  89.     _w = 14;               // no label
  90.       else
  91.       {
  92.     _w = 14;
  93.     // Try to make the width pretty
  94.     char buff[20];
  95.     IntToStr(_minVal,buff);
  96.     _maxWidth = strlen(buff);
  97.     IntToStr(_maxVal,buff);
  98.     int maxW = strlen(buff);
  99.     if (maxW > _maxWidth)
  100.       _maxWidth = maxW;
  101.     _w = 14 + 4*_maxWidth;
  102.       }
  103.       // user override
  104.       if (dlgCmd->size > 0 && dlgCmd->size < 2048)
  105.     _w = 6 + (dlgCmd->size/2);
  106.     }
  107.     else   // horizontal bar
  108.     {
  109.       style |= SLS_HORIZONTAL | SLS_BOTTOM;
  110.  
  111.       _w = 74;    // regular size
  112.       _scd.usScale1Increments = 101;
  113.       _scd.usScale1Spacing = 1;
  114.       if (dlgCmd->attrs & CA_Large)
  115.       {
  116.     _w = 142;
  117.     _scd.usScale1Increments = 101;
  118.     _scd.usScale1Spacing = 2;
  119.       }
  120.       else if (dlgCmd->attrs & CA_Small)
  121.       {
  122.     _w = 42;
  123.     _scd.usScale1Increments = 51;
  124.     _scd.usScale1Spacing = 1;
  125.       }
  126.       if (dlgCmd->attrs & CA_NoLabel)
  127.     _h = 10;               // set my height
  128.       else
  129.     _h = 17;
  130.  
  131.       // user override
  132.       if (dlgCmd->size > 0 && dlgCmd->size < 2048)
  133.     _h = 10 + ((dlgCmd->size*65)/100);
  134.     }
  135.  
  136.     _scd.cbSize = sizeof(SLDCDATA);
  137.     _scd.usScale2Increments = 101;
  138.     _scd.usScale2Spacing = 1;
  139.  
  140.     _parentWin->SetPosition(_x, _y, _w, _h, dlgCmd->cFrame, dlgCmd->cRightOf,
  141.     dlgCmd->cBelow);
  142.  
  143.     if (dlgCmd->attrs & CA_Vertical)
  144.     {
  145.       _y += 2;
  146.       _h -= 2;   // we play this game to get better positioning in a frame
  147.     }
  148.     else if (dlgCmd->attrs & CA_Horizontal)
  149.     {
  150. //      _x += 1;
  151.       _y += 2;
  152.       _h -= 2;   // we play this game to get better positioning in a frame
  153.     }
  154.  
  155.     _CtrlOffset = _parentWin->AddDlgControl(_x, _y, _w, _h, _cmdId,
  156.     style, WC_SLIDER, _title, NULL, _scd.cbSize, &_scd);
  157.  
  158.   }
  159. //==================>>> vProgressCmd::GetCmdValue <<<=========================
  160.   int vProgressCmd::GetCmdValue(ItemVal id) VCONST
  161.   {
  162.     if (id != _cmdId)
  163.     return -1;
  164.     return _curVal;
  165.   }
  166. //=====================>>> vProgressCmd::SetCmdVal <<<=========================
  167.   void vProgressCmd::SetCmdVal(ItemVal val, ItemSetType st)
  168.   {
  169.     SysDebug2(Misc,"vProgressCmd::SetCmdVal(val:%d, type:%d)\n",val,st)
  170.     HWND myHwnd = GetMyHwnd(_cmdId);
  171.  
  172.     switch (st)
  173.     {
  174.       case Sensitive:
  175.     _Sensitive = val;               // set
  176.     WinEnableWindow (myHwnd, val);
  177.     break;
  178.  
  179.       case Hidden:
  180.     if (val)
  181.       WinShowWindow (myHwnd, FALSE);
  182.     else
  183.       WinShowWindow (myHwnd, TRUE);
  184.     break;
  185.  
  186.       case Value:
  187.     if (val < _minVal || val > _maxVal )
  188.       return;
  189.     _curVal = val;
  190.     float frac = val - _minVal;
  191.     frac = frac/(_maxVal - _minVal);
  192.     int percent = (int)( frac * 100 );
  193.     if (dlgCmd->attrs & CA_Small)
  194.       percent /=2;
  195.  
  196.     // Now set appropriate _curVal, scroll
  197.     WinSendMsg (myHwnd, SLM_SETSLIDERINFO,
  198.       MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE), (MPARAM) percent);
  199.  
  200.     // set a few tick marks
  201.     int ticksize=4;
  202.     if (dlgCmd->attrs & CA_Vertical)
  203.        ticksize = 4;
  204.  
  205.     int tickposn[3] = {0, 50, 100};
  206.     if (dlgCmd->attrs & CA_Large)
  207.     {
  208.       tickposn[0] = 0;
  209.       tickposn[1] = 50;
  210.       tickposn[2] = 100;
  211.     }
  212.     else if (dlgCmd->attrs & CA_Small)
  213.     {
  214.       tickposn[0] = 0;
  215.       tickposn[1] = 25;
  216.       tickposn[2] = 50;
  217.     }
  218.  
  219.     for (int i=0; i<3; i++)
  220.       WinSendMsg (myHwnd, SLM_SETTICKSIZE,
  221.           MPFROM2SHORT(tickposn[i], ticksize), (MPARAM) NULL);
  222.     // put text on bar
  223.     if (dlgCmd->attrs & CA_NoLabel)
  224.     {
  225.       WinSendMsg (myHwnd, SLM_SETSCALETEXT, MPFROMSHORT(0), (MPARAM) NULL);
  226.       break;
  227.     }
  228.     else
  229.     {
  230.       char label[40];
  231. #ifdef __BORLANDC__
  232.       ltoa(_curVal, label,10);
  233. #else
  234.       _ltoa(_curVal, label,10);
  235. #endif
  236.       if (dlgCmd->attrs & CA_Small)
  237.         WinSendMsg (myHwnd, SLM_SETSCALETEXT, MPFROMSHORT(25), (MPARAM) label);
  238.       else
  239.         WinSendMsg (myHwnd, SLM_SETSCALETEXT, MPFROMSHORT(50), (MPARAM) label);
  240.       break;
  241.     }
  242.     }
  243.   }
  244. //================>>> vProgressCmd::MEASUREITEM <<<============================
  245.   int vProgressCmd::MEASUREITEM(int id, OWNERITEM* ois)
  246.   {
  247.     return 1;
  248.   }
  249. //================>>> vProgressCmd::DRAWITEM <<<============================
  250.   int vProgressCmd::DRAWITEM(int id, OWNERITEM* ois)
  251.   {
  252.     return 0;
  253.   }
  254.