home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 2 / DATAFILE_PDCD2.iso / utilities2 / desklib / Libraries / Icon / c / SetCaret < prev    next >
Encoding:
Text File  |  1993-05-11  |  1.2 KB  |  50 lines

  1. #include "Wimp.h"
  2. #include "WimpSWIs.h"
  3.  
  4. extern void Icon_SetCaret(window_handle window, icon_handle icon)
  5. /*
  6.  * This routine sets the caret within the requested icon. It places the
  7.  * caret at the (righthand) end of the text in the icon. If the icon is not
  8.  * a text icon, then the function returns quietly
  9.  */
  10. {
  11.   caret_block caret;
  12.  
  13.   caret.window = window;
  14.   caret.icon   = icon;
  15.  
  16.   if (window >= 0 && icon >= 0)
  17.   {
  18.     icon_block    istate;
  19.     register char *buff;
  20.     register int  index, maxlen;
  21.  
  22.     Wimp_GetIconState(window, icon, &istate);
  23.  
  24.     if (!istate.flags.data.text || istate.flags.data.shaded)
  25.       return;          /* Not a text icon, or is shaded, so can't grab caret */
  26.  
  27.     if (istate.flags.data.indirected)
  28.     {
  29.       maxlen = istate.data.indirecttext.bufflen;
  30.       buff   = istate.data.indirecttext.buffer;
  31.     }
  32.     else
  33.     {
  34.       maxlen = 12;
  35.       buff = istate.data.text;
  36.     }
  37.  
  38.     index = 0;                                 /* Place caret at end of text */
  39.     while(index < maxlen && buff[index]>31)
  40.       index++;
  41.     caret.index = index;
  42.   }
  43.   else
  44.     caret.index = 0;
  45.  
  46.   caret.offset.y = caret.offset.x = 0;
  47.   caret.height = -1;
  48.   Wimp_SetCaretPosition(&caret);
  49. }
  50.