Changeset 151 for trunk/src


Ignore:
Timestamp:
Jun 15, 2009, 11:36:17 PM (16 years ago)
Author:
lpino
Message:
  • Implementation of setSelection and getSelection methods
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Scale.java

    r150 r151  
    3838
    3939public class Scale extends Control {
     40        int MAX_RANGE;
     41        int MIN_RANGE;
     42        int INCREMENT;
     43        int pixelRange;
    4044        static final int TrackBarProc;
    4145        static final PSZ TrackBarClass = PSZ.getAtom (OS.WC_SLIDER);
     
    7983    this.parent = parent;
    8084    this.style = style;
     85    MAX_RANGE = 100;
     86    MIN_RANGE = 0;
     87    INCREMENT = 10;
     88
    8189    SLDCDATA sldcData = new SLDCDATA();
    8290    sldcData.usScale1Increments = 10;
    83     //sldcData.usScale2Increments = 10;
    8491    sldcData.usScale1Spacing = 0;
    85     //sldcData.usScale2Spacing = 0;
     92
    8693    handle = OS.WinCreateWindow (
    8794        parent.handle,
     
    9198        0, parent.getHeight (), 0, 0,
    9299        parent.handle,
    93         // to mimic the Windows behavior
    94         OS.HWND_BOTTOM, //OS.HWND_TOP,
     100        OS.HWND_BOTTOM,
    95101        0,
    96102        sldcData,
     
    98104    );
    99105    if (handle == 0) error (SWT.ERROR_NO_HANDLES);
     106   
    100107    OS.WinSetWindowUShort (handle, OS.QWS_ID, (short)(handle & 0xFFFF));
    101 
    102108    OS.WinSendMsg(handle, OS.SLM_SETTICKSIZE, OS.MPFROM2SHORT((short)OS.SMA_SETALLTICKS, (short)6), 0);
    103     System.out.println ("Scale:createHandle " + Integer.toHexString (OS.MPFROM2SHORT((short)OS.SMA_SETALLTICKS, (short)6)));
     109//    OS.WinSendMsg(handle, OS.SLM_SETSLIDERINFO, OS.MPFROM2SHORT((short)OS.SMA_SLIDERARMPOSITION, (short)OS.SMA_INCREMENTVALUE), 1);
    104110    super.register ();
    105111    super.subclass ();
     
    167173
    168174void createHandle () {
    169     System.out.println ("Scale:createHandle");
    170175        super.createHandle ();
    171 //        OS.WinSendMsg(handle, OS.SLM_SETTICKSIZE, OS.MPFROM2SHORT((short)OS.SMA_SETALLTICKS, (short)10), 0);       
    172 //      OS.SendMessage (handle, OS.TBM_SETRANGEMAX, 0, 100);
    173 //      OS.SendMessage (handle, OS.TBM_SETPAGESIZE, 0, 10);
    174 //      OS.SendMessage (handle, OS.TBM_SETTICFREQ, 10, 0);
    175176}
    176177
     
    193194public int getIncrement () {
    194195        checkWidget ();
    195         return OS.WinSendMsg(handle, OS.SLM_QUERYSLIDERINFO, OS.MPFROM2SHORT((short)OS.SMA_SLIDERARMPOSITION, (short)OS.SMA_INCREMENTVALUE), 0);
     196        return 1;
     197//        return OS.WinSendMsg(handle, OS.SLM_QUERYSLIDERINFO, OS.MPFROM2SHORT((short)OS.SMA_SLIDERARMPOSITION, (short)OS.SMA_INCREMENTVALUE), 0);
    196198//      return OS.SendMessage (handle, OS.TBM_GETLINESIZE, 0, 0);
    197199}
     
    207209// * </ul>
    208210// */
    209 //public int getMaximum () {
    210 //      checkWidget ();
     211public int getMaximum () {
     212        checkWidget ();
     213        return MAX_RANGE;
    211214//      return OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
    212 //}
    213 //
     215}
     216
    214217///**
    215218// * Returns the minimum value which the receiver will allow.
     
    222225// * </ul>
    223226// */
    224 //public int getMinimum () {
    225 //      checkWidget ();
    226 //      return OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
    227 //}
    228 //
     227public int getMinimum () {
     228        checkWidget ();
     229        return MIN_RANGE;
     230}
     231
    229232///**
    230233// * Returns the amount that the receiver's value will be
     
    239242// * </ul>
    240243// */
    241 //public int getPageIncrement () {
    242 //      checkWidget ();
     244public int getPageIncrement () {
     245        checkWidget ();
     246        return INCREMENT;
    243247//      return OS.SendMessage (handle, OS.TBM_GETPAGESIZE, 0, 0);
    244 //}
    245 //
     248}
     249
    246250///**
    247251// * Returns the single <em>selection</em> that is the receiver's position.
     
    254258// * </ul>
    255259// */
    256 //public int getSelection () {
    257 //      checkWidget ();
    258 //      return OS.SendMessage (handle, OS.TBM_GETPOS, 0, 0);
    259 //}
    260 //
     260public int getSelection () {
     261        checkWidget ();
     262        int pixelInfo = OS.WinSendMsg(handle, OS.SLM_QUERYSLIDERINFO, OS.MPFROM2SHORT((short)OS.SMA_SLIDERARMPOSITION, (short)OS.SMA_RANGEVALUE ), 0);
     263        int posPixels = OS.SHORT1FROMMP(pixelInfo);
     264        int totalPixels = ((pixelInfo & 0xFFFF0000)>>16) & 0xFFFF;
     265        int pos = ((MAX_RANGE*posPixels)/totalPixels)+1;
     266        return pos;
     267}
     268
    261269///**
    262270// * Removes the listener from the collection of listeners who will
     
    297305// * </ul>
    298306// */
    299 //public void setIncrement (int increment) {
    300 //      checkWidget ();
    301 //      if (increment < 1) return;
    302 //      int minimum = OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
    303 //      int maximum = OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
    304 //      if (increment > maximum - minimum) return;
    305 //      OS.SendMessage (handle, OS.TBM_SETLINESIZE, 0, increment);
    306 //}
    307 //
     307public void setIncrement (int increment) {
     308        checkWidget ();
     309        if (increment < 1) return;
     310        int minimum = MIN_RANGE;
     311        int maximum = MAX_RANGE;
     312        if (increment > maximum - minimum) return;
     313        INCREMENT = increment;
     314}
     315
    308316///**
    309317// * Sets the maximum value which the receiver will allow
     
    318326// * </ul>
    319327// */
    320 //public void setMaximum (int value) {
    321 //      checkWidget ();
     328public void setMaximum (int value) {
     329        checkWidget ();
    322330//      int minimum = OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
    323 //      if (0 <= minimum && minimum < value) {
    324 //              OS.SendMessage (handle, OS.TBM_SETRANGEMAX, 1, value);
    325 //      }
    326 //}
    327 //
     331        if (0 <= MIN_RANGE && MIN_RANGE < value) {
     332                MAX_RANGE = value;
     333        }
     334}
     335
    328336///**
    329337// * Sets the minimum value which the receiver will allow
     
    338346// * </ul>
    339347// */
    340 //public void setMinimum (int value) {
    341 //      checkWidget ();
     348public void setMinimum (int value) {
     349        checkWidget ();
    342350//      int maximum = OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
    343 //      if (0 <= value && value < maximum) {
    344 //              OS.SendMessage (handle, OS.TBM_SETRANGEMIN, 1, value);
    345 //      }
    346 //}
    347 //
     351        if (0 <= value && value < MAX_RANGE) {
     352                MAX_RANGE = value;
     353        }
     354}
     355
    348356///**
    349357// * Sets the amount that the receiver's value will be
     
    359367// * </ul>
    360368// */
    361 //public void setPageIncrement (int pageIncrement) {
    362 //      checkWidget ();
    363 //      if (pageIncrement < 1) return;
    364 //      int minimum = OS.SendMessage (handle, OS.TBM_GETRANGEMIN, 0, 0);
    365 //      int maximum = OS.SendMessage (handle, OS.TBM_GETRANGEMAX, 0, 0);
    366 //      if (pageIncrement > maximum - minimum) return;
     369public void setPageIncrement (int pageIncrement) {
     370        checkWidget ();
     371        if (pageIncrement < 1) return;
     372        int minimum = MIN_RANGE;
     373        int maximum = MAX_RANGE;
     374        if (pageIncrement > maximum - minimum) return;
     375        INCREMENT = pageIncrement;
    367376//      OS.SendMessage (handle, OS.TBM_SETPAGESIZE, 0, pageIncrement);
    368377//      OS.SendMessage (handle, OS.TBM_SETTICFREQ, pageIncrement, 0);
    369 //}
    370 //
     378}
     379
    371380///**
    372381// * Sets the single <em>selection</em> that is the receiver's
     
    381390// * </ul>
    382391// */
    383 //public void setSelection (int value) {
    384 //      checkWidget ();
    385 //      if (value < 0) return;
    386 //      OS.SendMessage (handle, OS.TBM_SETPOS, 1, value);
    387 //}
    388 //
     392public void setSelection (int value) {
     393        checkWidget ();
     394        if (value < 0) return;
     395        int pixels = OS.WinSendMsg(handle, OS.SLM_QUERYSLIDERINFO, OS.MPFROM2SHORT((short)OS.SMA_SLIDERARMPOSITION, (short)OS.SMA_RANGEVALUE ), 0);
     396        int totalPixels = ((pixels & 0xFFFF0000)>>16) & 0xFFFF;
     397        int pixelPos = (value*totalPixels)/MAX_RANGE;
     398        OS.WinSendMsg(handle, OS.SLM_SETSLIDERINFO, OS.MPFROM2SHORT((short)OS.SMA_SLIDERARMPOSITION, (short)OS.SMA_RANGEVALUE), pixelPos);
     399}
     400
    389401int widgetStyle () {
    390402        int bits = super.widgetStyle () | OS.SLS_CENTER | OS.SLS_HOMELEFT | OS.SLS_PRIMARYSCALE1;
Note: See TracChangeset for help on using the changeset viewer.