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

  1. #include "Wimp.h"
  2. #include "WimpSWIs.h"
  3. #include "Coord.h"
  4. #include "Icon.h"
  5.  
  6. #include "string.h"
  7.  
  8.  
  9. extern void Icon_SetText(window_handle w, icon_handle i, char *text)
  10. /*
  11.  * Copies the text string into the icon's indirected string buffer (and redraws)
  12.  * If unable to set the text (incorrect icon type), it returns quietly
  13.  * If text passed in is a NULL pointer, sets icon text to " "
  14.  */
  15. {
  16.   icon_block istate;
  17.   char       temp[2] = " ";
  18.  
  19.   if (text == NULL)
  20.     text = temp;
  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.     strncpy(istate.data.indirecttext.buffer, text,
  27.               istate.data.indirecttext.bufflen - 1);
  28.     istate.data.indirecttext.buffer[istate.data.indirecttext.bufflen-1] = 0;
  29.     
  30.     Wimp_SetIconState(w, i, 0, 0);
  31.   }
  32. }
  33.