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

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for 
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #                                      
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    Icon.GetText.c
  12.     Author:  Copyright © 1992, 1993 Jason Williams
  13.     Version: 1.00 (14 Jul 1993)
  14.     Purpose: Retrieves the text/spritename from an icon
  15. */
  16.  
  17. #include "DeskLib:Wimp.h"
  18. #include "DeskLib:WimpSWIs.h"
  19. #include "DeskLib:Icon.h"
  20.  
  21. #include <string.h>
  22.  
  23.  
  24. extern void Icon_GetText(window_handle w, icon_handle i, char *text)
  25. /*
  26.  * Copies the text string from the icon (sprite name, text, or indirected)
  27.  * into the array pointed to by "text"
  28.  */
  29. {
  30.   icon_block istate;
  31.   char       *buffer;
  32.   int        len = wimp_MAXNAME;
  33.  
  34.   text[0] = 0;  /* return NULL string if anything goes wrong */
  35.  
  36.   Wimp_GetIconState(w, i, &istate);
  37.   if (istate.flags.data.indirected)
  38.   {
  39.     if (istate.flags.data.text)
  40.     {
  41.       buffer = istate.data.indirecttext.buffer;
  42.       len    = istate.data.indirecttext.bufflen;
  43.     }
  44.     else
  45.       if (istate.flags.data.sprite)
  46.         buffer = (char *) istate.data.indirectsprite.name;
  47.   }
  48.   else
  49.     buffer = istate.data.text;                           /* text/sprite name */
  50.  
  51.   strncpy(text, buffer, len);                            /* text/sprite name */
  52.   text[len] = 0;
  53. }
  54.