RangeValueSlider.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /////////////////////////////////////////////////////////////////////////////
  2. // RangeValueSlider.cpp | Implementation of the TCRangeValueSlider class.
  3. #include "RangeValueSlider.h"
  4. /////////////////////////////////////////////////////////////////////////////
  5. // TCRangeValueSlider
  6. /////////////////////////////////////////////////////////////////////////////
  7. // Operations
  8. bool TCRangeValueSlider::Update(ULONG nObjects, ITCRangeValue** ppObjects)
  9. {
  10. // Enable/disable the controls if no objects or more than 1 object
  11. bool bEnable = (1 == nObjects);
  12. if (bEnable)
  13. {
  14. __try
  15. {
  16. // Get the object
  17. ITCRangeValue* pobj = ppObjects[0];
  18. // Save the default value
  19. m_nValueDefault = pobj->DefaultValue;
  20. // Get the range of the value
  21. long nMin = pobj->MinValue;
  22. long nMax = pobj->MaxValue;
  23. long nSteps = nMax + 1 - nMin;
  24. // Set the tick frequency of the slider
  25. long nTickMarks = pobj->TickMarks;
  26. if (nTickMarks)
  27. {
  28. long nTickFreq = nSteps / pobj->TickMarks;
  29. SetTicFreq(nTickFreq);
  30. // Set the page size of the slider to be the same as the tick freq
  31. SetPageSize(nTickFreq);
  32. }
  33. else
  34. {
  35. ClearTics();
  36. }
  37. // Set the line size of the slider
  38. long nGranularity = pobj->Granularity;
  39. SetLineSize(nGranularity);
  40. // Set the range of the slider
  41. SetRange(nMin, nMax, true);
  42. // Set the position of the slider
  43. long nValue = pobj->RangeValue;
  44. SetPos(nValue);
  45. }
  46. __except(1)
  47. {
  48. bEnable = false;
  49. }
  50. }
  51. // Enable/disable the window if no objects or more than 1 object
  52. EnableWindow(bEnable);
  53. // Returnt the enabled flag
  54. return bEnable;
  55. }
  56. HRESULT TCRangeValueSlider::Apply(ULONG nObjects, ITCRangeValue** ppObjects)
  57. {
  58. // Do nothing if no objects or more than 1 object
  59. if (1 != nObjects)
  60. return E_UNEXPECTED;
  61. // Get the object
  62. ITCRangeValue* pobj = ppObjects[0];
  63. // Apply the slider setting to the object
  64. long nValue = GetPos();
  65. return pobj->put_RangeValue(nValue);
  66. }