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

  1. #include "Wimp.h"
  2. #include "WimpSWIs.h"
  3.  
  4. #include <stdio.h>
  5. #include "string.h"
  6.  
  7.  
  8. extern void Icon_SetInteger(window_handle w, icon_handle i, int value)
  9. /*
  10.  * Sets the given icon's text to hold the number in "value". (and redraws icon)
  11.  * If unable to set the text (incorrect icon type), it returns quietly
  12.  */
  13. {
  14.   icon_block istate;
  15.   char       temp[16];
  16.  
  17.   Wimp_GetIconState(w, i, &istate);
  18.   if (istate.flags.value & (icon_TEXT | icon_INDIRECTED))
  19.   {
  20.     /* Indirected text icon, so set text field - ensure no buffer overflow */
  21.     sprintf(temp, "%d", value);
  22.     strncpy(istate.data.indirecttext.buffer, temp,
  23.               istate.data.indirecttext.bufflen - 1);
  24.     istate.data.indirecttext.buffer[istate.data.indirecttext.bufflen-1] = 0;
  25.     
  26.     Wimp_SetIconState(w, i, 0, 0);
  27.   }
  28. }
  29.