home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / source / xslider.cpp < prev    next >
C/C++ Source or Header  |  1997-04-05  |  7KB  |  221 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<BR>
  30.             XString* buffer      buffer to hold the text
  31. */
  32. void XSlider::GetScaleText(const SHORT tickNumber, XString * buffer)
  33. {
  34.     WinSendMsg(winhandle, SLM_QUERYSCALETEXT, MPFROM2SHORT(tickNumber, 512), MPFROMP(buffer->GetBuffer(512)));
  35.     buffer->ReleaseBuffer();
  36. }
  37.  
  38.  
  39. /*@ XSlider :: XSlider(const XWindow * owner, const XRect * rec, const USHORT id, const ULONG style, const char *font)
  40. @group constructors/destructors
  41. @remarks Constructs a XSlider
  42. @parameters <t '°' c=2>
  43.                 °XWindow * owner      °the owner of the XSlider
  44.             °XRect * rect         °the rectangle
  45.             °USHORT id            °id of the window
  46.             °ULONG style          °style, valid values are:
  47.                                             <t '°' c=1>
  48.                                     °SL_HORIZONTAL
  49.                                     °SL_VERTICAL
  50.                                     °SL_CENTER
  51.                                     °SL_BOTTOM
  52.                                     °SL_TOP
  53.                                     °SL_LEFT
  54.                                     °SL_RIGHT
  55.                                     °SL_SNAPTOINCREMENT
  56.                                     °SL_BUTTONSBOTTOM
  57.                                     °SL_BUTTONSTOP
  58.                                     °SL_BUTTONSLEFT
  59.                                     °SL_BUTTONSRIGHT
  60.                                     °SL_READONLY
  61.                                     °SL_RIBBONSTRIP
  62.                                     °SL_HOMEBOTTOM
  63.                                     °SL_HOMETOP
  64.                                     °SL_HOMELEFT
  65.                                     °SL_HOMERIGHT
  66.                                     °SL_PRIMARYSCALE1
  67.                                     °SL_PRIMARYSCALE2
  68.                                             </t>
  69.                                 (can be or-ed)
  70.                 °char * font                °font to use, e.g. "8.Helv"
  71.                 </t>
  72. */
  73. 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)
  74. {
  75. }
  76.  
  77.  
  78. /*@ XSlider::SetScales(const USHORT scale1Incr, const USHORT scale1Space, const USHORT scale2Incr, const USHORT scale2Space)
  79. @group misc
  80. @remarks Set scales 1 or 2 (depending if SL_PRIMARYSCALE1 or SL_PRIMARYSCALE2 is set)
  81. @parameters <t '°' c=2>
  82.                 °USHORT scale1Incr    °increments for scale 1
  83.             °USHORT scale1Space   °spaceing between increments for scale 1
  84.             °USHORT scale2Incr    °increments for scale 2 (default is 0)
  85.             °USHORT scale2Space   °spaceing between increments for scale 2 (default is 0)
  86.                 </t>
  87. */
  88. void XSlider::SetScales(const USHORT scale1Incr, const USHORT scale1Space, const USHORT scale2Incr, const USHORT scale2Space)
  89. {
  90.     SLDCDATA data;
  91.  
  92.     data.cbSize = sizeof(data);
  93.     data.usScale1Increments = scale1Incr;
  94.     data.usScale2Increments = scale2Incr;
  95.     data.usScale1Spacing = scale1Space;
  96.     data.usScale2Spacing = scale2Space;
  97.  
  98.     WNDPARAMS params;
  99.  
  100.     params.fsStatus = WPM_CTLDATA;
  101.     params.cbCtlData = sizeof(data);
  102.     params.pCtlData = &data;
  103.  
  104.     WinSendMsg(winhandle, WM_SETWINDOWPARAMS, MPFROMP(¶ms), 0);
  105. }
  106.  
  107.  
  108. /*@ XSlider::SetTickSize(const SHORT tickNumber, const SHORT tickLength) 
  109. @group size
  110. @remarks Set the size of a tick
  111. @parameters SHORT tickNumber     the tick to change (zero-based index)<BR>
  112.             SHORT tickLength     length of the tick in pixels
  113. */
  114. void XSlider::SetTickSize(const SHORT tickNumber, const SHORT tickLength) const
  115. {
  116.     WinSendMsg(winhandle, SLM_SETTICKSIZE, MPFROM2SHORT(tickNumber, tickLength), 0);
  117. }
  118.  
  119.  
  120. /*@ XSlider::SetScaleText(const SHORT tickNumber, const char *text)
  121. @group text functions
  122. @remarks Add a text to a tick
  123. @parameters SHORT tickNumber     the tick to get the text (zero-based index)<BR>
  124.             char * text          text to add
  125. */
  126. void XSlider::SetScaleText(const SHORT tickNumber, const char *text) const
  127. {
  128.     WinSendMsg(winhandle, SLM_SETSCALETEXT, MPFROMSHORT(tickNumber), MPFROMP(text));
  129. }
  130.  
  131.  
  132. /*@ XSlider::AddDetent(const SHORT detentPos)
  133. @group detents
  134. @remarks Add a detend to the primary scale
  135. @parameters SHORT pos   position of the detent
  136. @returns    LONG the id of the detent
  137. */
  138. LONG XSlider::AddDetent(const SHORT detentPos) const
  139. {
  140.     return (LONG) WinSendMsg(winhandle, SLM_ADDDETENT, MPFROMSHORT(detentPos), 0);
  141. }
  142.  
  143.  
  144. /*@ XSlider::RemoveDetent(const LONG detentID)
  145. @group detents
  146. @remarks Removes a detend from the primary scale
  147. @parameters LONG the id of the detent to remove
  148. */
  149. void XSlider::RemoveDetent(const LONG detentID) const
  150. {
  151.     WinSendMsg(winhandle, SLM_REMOVEDETENT, (MPARAM) detentID, 0);
  152. }
  153.  
  154.  
  155. /*@ XSlider::SetSliderPos(const LONG pos)
  156. @group set/get value
  157. @remarks Set the sliders position
  158. @parameters LONG pos    the new position
  159. */
  160. void XSlider::SetSliderPos(const LONG pos) const
  161. {
  162.     WinSendMsg(winhandle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE), (MPARAM) pos);
  163. }
  164.  
  165.  
  166. /*@ XSlider::GetSliderPos(void)
  167. @group set/get value
  168. @remarks Returns the sliders position
  169. @returns LONG  position
  170. */
  171. LONG XSlider::GetSliderPos(void) const
  172. {
  173.     return (LONG) SHORT2FROMMR(WinSendMsg(winhandle, SLM_QUERYSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_RANGEVALUE), 0));
  174. }
  175.  
  176.  
  177. /*@ XSlider::SetSliderSize(const SHORT length, const SHORT breadth)
  178. @group size
  179. @remarks Set the size of the slider
  180. @parameters SHORT length     length of the slider<BR>
  181.             SHORT breadth    breadth
  182. */
  183. void XSlider::SetSliderSize(const SHORT length, const SHORT breadth) const
  184. {
  185.     WinSendMsg(winhandle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SLIDERARMDIMENSIONS, 0), MPFROM2SHORT(length, breadth));
  186. }
  187.  
  188.  
  189. /*@ XSlider::SetShaftSize(const SHORT size)
  190. @group size
  191. @remarks Set the size of the shaft
  192. @parameters SHORT size  new size of the shaft
  193. */
  194. void XSlider::SetShaftSize(const SHORT size) const
  195. {
  196.     WinSendMsg(winhandle, SLM_SETSLIDERINFO, MPFROM2SHORT(SMA_SHAFTDIMENSIONS, 0), MPFROMSHORT(size));
  197. }
  198.  
  199.  
  200. 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)
  201. {
  202.     SetScales(101, 0, 101, 0);
  203.     if (showScale)
  204.     {
  205.         SetTickSize(SMA_SETALLTICKS, 2);
  206.         SetTickSize(0, 5);
  207.         SetTickSize(25, 5);
  208.         SetTickSize(50, 5);
  209.         SetTickSize(75, 5);
  210.         SetTickSize(100, 5);
  211.     }
  212.     if (showText)
  213.     {
  214.         SetScaleText(0, "0");
  215.         SetScaleText(25, "25");
  216.         SetScaleText(50, "50");
  217.         SetScaleText(75, "75");
  218.         SetScaleText(100, "100");
  219.     }
  220. }
  221.