home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool_main.zip / ool / source / xslider.cpp < prev    next >
C/C++ Source or Header  |  1998-04-06  |  7KB  |  250 lines

  1. #include "xslider.h"
  2. #include "xstring.h"
  3. #include "xindicat.h"
  4.  
  5.  
  6. /*@
  7. @class XSlider
  8. @parent XControl
  9. @type overview
  10. @symbol _
  11. */
  12.  
  13.  
  14. /*@ XSlider::GetDetentPos(const LONG detentID)
  15. @group detents
  16. @remarks Get position of a detent
  17. @parameters LONG id of the detent
  18. @returns    USHORT positionin pixels
  19. */
  20. USHORT XSlider::GetDetentPos(const LONG detentID) const
  21. {
  22.    return SHORT1FROMMR(WinSendMsg(winhandle, SLM_QUERYDETENTPOS, (MPARAM) detentID, 0));
  23. }
  24.  
  25.  
  26. /*@ XSlider::GetScaleText(const SHORT tickNumber, XString * buffer)
  27. @group text functions
  28. @remarks Get the text of a tick
  29. @parameters SHORT tickNumber     the tick
  30. <BR>
  31.             XString* buffer      buffer to hold the text
  32. */
  33. void XSlider::GetScaleText(const SHORT tickNumber, XString * buffer) const
  34. {
  35.    WinSendMsg(winhandle, SLM_QUERYSCALETEXT, MPFROM2SHORT(tickNumber, 512), MPFROMP(buffer->GetBuffer(512)));
  36.    buffer->ReleaseBuffer();
  37. }
  38.  
  39.  
  40. /*@ XSlider :: XSlider(const XWindow * owner, const XRect& rec, const USHORT id, const ULONG style, const char *font)
  41. @group constructors/destructors
  42. @remarks Constructs a XSlider
  43. @parameters <t '°' c=2>
  44.             °XWindow * owner      °the owner of the XSlider
  45.             °XRect& rect         °the rectangle
  46.             °USHORT id            °id of the window
  47.             °ULONG style          °style, valid values are:
  48. <BR>
  49. SL_HORIZONTAL
  50. <BR>
  51. SL_VERTICAL
  52. <BR>
  53. SL_CENTER
  54. <BR>
  55. SL_BOTTOM
  56. <BR>
  57. SL_TOP
  58. <BR>
  59. SL_LEFT
  60. <BR>
  61. SL_RIGHT
  62. <BR>
  63. SL_SNAPTOINCREMENT
  64. <BR>
  65. SL_BUTTONSBOTTOM
  66. <BR>
  67. SL_BUTTONSTOP
  68. <BR>
  69. SL_BUTTONSLEFT
  70. <BR>
  71. SL_BUTTONSRIGHT
  72. <BR>
  73. SL_READONLY
  74. <BR>
  75. SL_RIBBONSTRIP
  76. <BR>
  77. SL_HOMEBOTTOM
  78. <BR>
  79. SL_HOMETOP
  80. <BR>
  81. SL_HOMELEFT
  82. <BR>
  83. SL_HOMERIGHT
  84. <BR>
  85. SL_PRIMARYSCALE1
  86. <BR>
  87. SL_PRIMARYSCALE2
  88. <BR>
  89.                                 (can be or-ed)
  90.             °char * font            °font to use, e.g. "8.Helv"
  91.             </t>
  92. */
  93. XSlider :: XSlider(const XWindow * owner, const XRect& rec, const USHORT id, const ULONG style, const char *font):XControl(&rec, style, owner, "", WC_SLIDER, id, font)
  94. {
  95. }
  96.  
  97.  
  98. /*@ XSlider::SetScales(const USHORT scale1Incr, const USHORT scale1Space, const USHORT scale2Incr, const USHORT scale2Space)
  99. @group misc
  100. @remarks Set scales 1 or 2 (depending if SL_PRIMARYSCALE1 or SL_PRIMARYSCALE2 is set)
  101. @parameters <t '°' c=2>
  102.             °USHORT scale1Incr    °increments for scale 1
  103.             °USHORT scale1Space   °spaceing between increments for scale 1
  104.             °USHORT scale2Incr    °increments for scale 2 (default is 0)
  105.             °USHORT scale2Space   °spaceing between increments for scale 2 (default is 0)
  106.             </t>
  107. */
  108. void XSlider::SetScales(const USHORT scale1Incr, const USHORT scale1Space, const USHORT scale2Incr, const USHORT scale2Space)
  109. {
  110.    SLDCDATA data;
  111.  
  112.    data.cbSize = sizeof(data);
  113.    data.usScale1Increments = scale1Incr;
  114.    data.usScale2Increments = scale2Incr;
  115.    data.usScale1Spacing = scale1Space;
  116.    data.usScale2Spacing = scale2Space;
  117.  
  118.    WNDPARAMS params;
  119.  
  120.    params.fsStatus = WPM_CTLDATA;
  121.    params.cbCtlData = sizeof(data);
  122.    params.pCtlData = &data;
  123.  
  124.    WinSendMsg(winhandle, WM_SETWINDOWPARAMS, MPFROMP(¶ms), 0);
  125. }
  126.  
  127.  
  128. /*@ XSlider::SetTickSize(const SHORT tickNumber, const SHORT tickLength)
  129. @group size
  130. @remarks Set the size of a tick
  131. @parameters
  132. <t '°' c=2>
  133. °SHORT °the tick to change (zero-based index)
  134. °SHORT °length of the tick in pixels
  135. </t>
  136. */
  137. void XSlider::SetTickSize(const SHORT tickNumber, const SHORT tickLength) const
  138. {
  139.    WinSendMsg(winhandle, SLM_SETTICKSIZE, MPFROM2SHORT(tickNumber, tickLength), 0);
  140. }
  141.  
  142.  
  143. /*@ XSlider::SetScaleText(const SHORT tickNumber, const char *text)
  144. @group text functions
  145. @remarks Add a text to a tick
  146. @parameters
  147. <t '°' c=2>
  148. °SHORT °the tick to get the text (zero-based index)
  149. °char * °text to add
  150. </t>
  151. */
  152. void XSlider::SetScaleText(const SHORT tickNumber, const char *text) const
  153. {
  154.    WinSendMsg(winhandle, SLM_SETSCALETEXT, MPFROMSHORT(tickNumber), MPFROMP(text));
  155. }
  156.  
  157.  
  158. /*@ XSlider::AddDetent(const SHORT detentPos)
  159. @group detents
  160. @remarks Add a detend to the primary scale
  161. @parameters SHORT pos   position of the detent
  162. @returns    LONG the id of the detent
  163. */
  164. LONG XSlider::AddDetent(const SHORT detentPos) const
  165. {
  166.    return (LONG) WinSendMsg(winhandle, SLM_ADDDETENT, MPFROMSHORT(detentPos), 0);
  167. }
  168.  
  169.  
  170. /*@ XSlider::RemoveDetent(const LONG detentID)
  171. @group detents
  172. @remarks Removes a detend from the primary scale
  173. @parameters LONG the id of the detent to remove
  174. */
  175. void XSlider::RemoveDetent(const LONG detentID) const
  176. {
  177.    WinSendMsg(winhandle, SLM_REMOVEDETENT, (MPARAM) detentID, 0);
  178. }
  179.  
  180.  
  181. /*@ XSlider::SetSliderPos(const LONG pos)
  182. @group set/get value
  183. @remarks Set the sliders position
  184. @parameters LONG the new position
  185. */
  186. void XSlider::SetSliderPos(const LONG pos) const
  187. {
  188.    WinSendMsg(winhandle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE), (MPARAM) pos);
  189. }
  190.  
  191.  
  192. /*@ XSlider::GetSliderPos(void)
  193. @group set/get value
  194. @remarks Returns the sliders position
  195. @returns LONG  position
  196. */
  197. LONG XSlider::GetSliderPos(void) const
  198. {
  199.    return (LONG) SHORT2FROMMR(WinSendMsg(winhandle, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE), 0));
  200. }
  201.  
  202.  
  203. /*@ XSlider::SetSliderSize(const SHORT length, const SHORT breadth)
  204. @group size
  205. @remarks Set the size of the slider
  206. @parameters
  207. <t '°' c=2>
  208. °SHORT °length of the slider
  209. °SHORT °breadth
  210. </t>
  211. */
  212. void XSlider::SetSliderSize(const SHORT length, const SHORT breadth) const
  213. {
  214.    WinSendMsg(winhandle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMDIMENSIONS, 0), MPFROM2SHORT(length, breadth));
  215. }
  216.  
  217.  
  218. /*@ XSlider::SetShaftSize(const SHORT size)
  219. @group size
  220. @remarks Set the size of the shaft
  221. @parameters SHORT size  new size of the shaft
  222. */
  223. void XSlider::SetShaftSize(const SHORT size) const
  224. {
  225.    WinSendMsg(winhandle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SHAFTDIMENSIONS, 0), MPFROMSHORT(size));
  226. }
  227.  
  228.  
  229. XIndicator :: XIndicator(const XWindow * owner, const XRect& rec, const USHORT id, const BOOL showScale, const BOOL showText, const char *font):XSlider(owner, rec, id, SL_RIBBONSTRIP | SL_READONLY | WIN_VISIBLE | SL_HOMELEFT | SL_LEFT | SL_HORIZONTAL)
  230. {
  231.    SetScales(101, 0, 101, 0);
  232.    if (showScale)
  233.    {
  234.       SetTickSize(SMA_SETALLTICKS, 2);
  235.       SetTickSize(0, 5);
  236.       SetTickSize(25, 5);
  237.       SetTickSize(50, 5);
  238.       SetTickSize(75, 5);
  239.       SetTickSize(100, 5);
  240.    }
  241.    if (showText)
  242.    {
  243.       SetScaleText(0, "0");
  244.       SetScaleText(25, "25");
  245.       SetScaleText(50, "50");
  246.       SetScaleText(75, "75");
  247.       SetScaleText(100, "100");
  248.    }
  249. }
  250.