home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / Libraries / Icon / c / GetText < prev    next >
Encoding:
Text File  |  1994-05-29  |  1.9 KB  |  63 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, 1994 Jason Williams
  13.     Version: 1.02 (22 May 1994)
  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.   int        index;
  34.  
  35.   text[0] = 0;  /* return NULL string if anything goes wrong */
  36.  
  37.   Wimp_GetIconState(w, i, &istate);
  38.   if (istate.flags.data.indirected)
  39.   {
  40.     if (istate.flags.data.sprite)
  41.         buffer = (char *) istate.data.indirectsprite.name;
  42.     else
  43.     {
  44.       buffer = istate.data.indirecttext.buffer;
  45.       len    = istate.data.indirecttext.bufflen;
  46.     }
  47.   }
  48.   else
  49.     buffer = istate.data.text;                           /* text/sprite name */
  50.  
  51.   strncpy(text, buffer, len);                            /* text/sprite name */
  52.   
  53.   /* Terminate string at first control character, or at end of buffer */
  54.   index = 0;
  55.   while ((index < len) && (buffer[index] >= ' '))
  56.     index++;
  57.     
  58.   if (index < len)
  59.     buffer[index] = NULL;
  60.   else
  61.     buffer[len - 1] = NULL;
  62. }
  63.