home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / Libraries / Icon / c / SetTextRJ < prev    next >
Encoding:
Text File  |  1994-05-29  |  1.6 KB  |  62 lines

  1. /* Icon_SetTextRJ
  2.  * (c) Copyright 1993 Erik do Kort
  3.  */
  4.  
  5. #include <string.h>
  6. #include "DeskLib:Icon.h"
  7. #include "DeskLib:Wimp.h"
  8. #include "DeskLib:WimpSWIs.h"
  9.  
  10.  
  11. extern void Icon_SetTextRJ(window_handle w, icon_handle i, char *text)
  12. /*
  13.  * Copies the text string into the icon's indirected string buffer (and redraws)
  14.  * This text is "right justified", meaning that if the text doesn't fit,
  15.  * it is truncated at the *LEFT*-hand side, and preceded by a '...' char
  16.  * If unable to set the text (incorrect icon type), it returns quietly
  17.  * If text passed in is a NULL pointer, sets icon text to '\0'
  18.  */
  19. {
  20.   icon_block  istate;
  21.   int         empty = 0;
  22.   caret_block caret;
  23.   int         len;
  24.  
  25.   if (text == NULL)
  26.     text = (char *)∅
  27.  
  28.   Wimp_GetIconState(w, i, &istate);
  29.   if (istate.flags.value & (icon_TEXT | icon_INDIRECTED))
  30.   {
  31.     /* Indirected text icon, so set text field - ensure no buffer overflow
  32.      */
  33.     register int  textlength = strlen(text) + 1 ;
  34.     register int  bufflength = istate.data.indirecttext.bufflen ;
  35.     register char *buffer    = istate.data.indirecttext.buffer ;
  36.     if ( bufflength < textlength )
  37.     {
  38.       text += textlength - bufflength ;
  39.       if ( bufflength > 2 )
  40.       {
  41.         *buffer++ = '\x8c' ;
  42.         text += 1 ;
  43.       }
  44.     }
  45.     strcpy(buffer, text) ;
  46.  
  47.     /* Ensure caret isn't beyond end of text */
  48.     Wimp_GetCaretPosition( &caret );
  49.     if ( caret.window == w && caret.icon == i )
  50.     {
  51.       len = strlen( istate.data.indirecttext.buffer );
  52.       if ( caret.index > len )
  53.       {
  54.         caret.index = len;
  55.         Wimp_SetCaretPosition( &caret );
  56.       }
  57.     }
  58.  
  59.     Wimp_SetIconState(w, i, 0, 0);
  60.   }
  61. }
  62.