home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / code / desklib / Libraries / Icon / c / printf < prev    next >
Encoding:
Text File  |  1994-05-29  |  1.8 KB  |  59 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.printf.c
  12.     Author:  Copyright © 1992, 1993, 1994 Jason Williams
  13.              Concept by Edouard Poor
  14.     Version: 1.02 (12 Mar 1994)
  15.     Purpose: Do a "printf" into an icon's indirected text string
  16. */
  17.  
  18. #include <stdarg.h>
  19. #include <stdio.h>
  20. #include "string.h"
  21.  
  22. #include "Wimp.h"
  23. #include "WimpSWIs.h"
  24.  
  25. extern void Icon_printf(window_handle window, icon_handle icon,
  26.                         char *format, ...)
  27. {
  28.   va_list    argp;
  29.   char       temp[512];   /* Longer strings will break this call */
  30.   icon_block istate;
  31.   caret_block caret;
  32.   int         len;
  33.  
  34.   Wimp_GetIconState(window, icon, &istate);
  35.   if (!istate.flags.data.indirected)
  36.     return;
  37.  
  38.   va_start(argp,format);
  39.   vsprintf(temp, format, argp);
  40.   strncpy(istate.data.indirecttext.buffer, temp,
  41.           istate.data.indirecttext.bufflen - 1);
  42.   istate.data.indirecttext.buffer[istate.data.indirecttext.bufflen - 1] = 0;
  43.   va_end(argp);
  44.  
  45.   /* Ensure caret isn't beyond end of text */
  46.   Wimp_GetCaretPosition( &caret );
  47.   if ( caret.window == window && caret.icon == icon )
  48.   {
  49.     len = strlen( istate.data.indirecttext.buffer );
  50.     if ( caret.index > len )
  51.     {
  52.       caret.index = len;
  53.       Wimp_SetCaretPosition( &caret );
  54.     }
  55.   }
  56.   
  57.   Wimp_SetIconState(window, icon, 0, 0);
  58. }
  59.