home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / Libraries / Icon / c / SetDouble < prev    next >
Encoding:
Text File  |  1993-07-14  |  1.1 KB  |  35 lines

  1. #include "Wimp.h"
  2. #include "WimpSWIs.h"
  3.  
  4. #include <stdio.h>
  5. #include "string.h"
  6.  
  7.  
  8. extern void Icon_SetDouble(window_handle w, icon_handle i,
  9.                            double value, int decimalplaces)
  10. /*
  11.  * Sets the given icon's text to hold the number in "value". (and redraws icon)
  12.  * After the decimal place, up to "decimalplaces" digits will be printed
  13.  * If the number is too big (too many digits), it will be truncated to fit
  14.  * (which may completely destroy the value you wished to represent, or
  15.  * just reduce its accuracy)
  16.  * If unable to set the text (incorrect icon type), it returns quietly
  17.  */
  18. {
  19.   icon_block istate;
  20.   char       temp[32], format[16];
  21.  
  22.   Wimp_GetIconState(w, i, &istate);
  23.   if (istate.flags.value & (icon_TEXT | icon_INDIRECTED))
  24.   {
  25.     /* Indirected text icon, so set text field - ensure no buffer overflow */
  26.     sprintf(format, "%%.%df", decimalplaces);
  27.     sprintf(temp, format, value);
  28.     strncpy(istate.data.indirecttext.buffer, temp,
  29.               istate.data.indirecttext.bufflen - 1);
  30.     istate.data.indirecttext.buffer[istate.data.indirecttext.bufflen-1] = 0;
  31.     
  32.     Wimp_SetIconState(w, i, 0, 0);
  33.   }
  34. }
  35.