home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / s / spconv / !Spconv / c / wimputils < prev   
Encoding:
Text File  |  1994-09-16  |  4.1 KB  |  199 lines

  1. /* Program: wimputils.c  V2.06 - By Tim Moore (17th Sept 1994)
  2.  *
  3.  * Purpose: General wimp utilities, to provide via header
  4.  *
  5.  */
  6.  
  7. /******** RISC-OS LIBRARIES **********/
  8.  
  9. #include "wimp.h"
  10. #include "wimpt.h"
  11. #include "win.h"
  12. #include "werr.h"
  13. #include "dbox.h"
  14. #include "template.h"
  15.  
  16. /******** STANDARD LIBRARIES *********/
  17.  
  18. #include <string.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21.  
  22. /******** HEADER FILE FOR THIS ******/
  23.  
  24. #include "wimputils.h"
  25.  
  26.  
  27. /***************************** WINDOW UTILS *****************************/
  28.  
  29. BOOL Wimp_Utils_Create_Window(char *Name, wimp_w *Handle)
  30. {
  31.   wimp_wind *Window;    /* Pointer to window definition */
  32.  
  33.   /* Find template for the window */
  34.     Window = template_syshandle(Name);
  35.     if (Window == 0)
  36.       return FALSE;
  37.  
  38.   /* Create the window, dealing with errors */
  39.   return (wimpt_complain(wimp_create_wind(Window, Handle)) == 0);
  40. }
  41.  
  42.  
  43. void Wimp_Utils_Redraw_Window(wimp_w Handle)
  44. {
  45.   /* Redrawing the window here does nothing - just go through the loop */
  46.   int            More;
  47.   wimp_redrawstr r;
  48.  
  49.   /* Start the redraw */
  50.   r.w = Handle;
  51.   wimpt_noerr(wimp_redraw_wind(&r, &More));
  52.  
  53.   /* Do the redraw loop */
  54.   while (More)
  55.   {
  56.     wimp_get_rectangle(&r, &More);
  57.   }
  58. }
  59.  
  60.  
  61.  
  62. BOOL Wimp_Utils_Open_Window(wimp_w Handle,BOOL Window_Limit,BOOL Window_Open)
  63. {
  64.   BOOL Success = FALSE;
  65.  
  66.   /* Open the window - check limit for only one allowed */
  67.   if (Window_Open && Window_Limit)
  68.     werr(FALSE, "Only one window may be opened");
  69.   else
  70.   {
  71.     wimp_wstate  State;
  72.  
  73.     /* Get the state of the window */
  74.     if (wimpt_complain(wimp_get_wind_state(Handle, &State)) == 0)
  75.     {
  76.       State.o.behind = -1;          /* Make sure window is opened in front */
  77.       wimpt_noerr(wimp_open_wind(&State.o));
  78.       Success = TRUE;
  79.     }
  80.   }
  81.   return (Success);
  82. }
  83.  
  84. char *Wimp_Utils_Get_Icon_Text(wimp_w Window, wimp_i Icon, char *Text)
  85. {
  86.   wimp_icon Result;
  87.   wimp_get_icon_info(Window,Icon,&Result);
  88.   if ((Result.flags & wimp_INDIRECT) !=0)
  89.   {
  90.     strcpy(Text, Result.data.indirecttext.buffer);
  91.   }
  92.   else
  93.   {
  94.     werr(FALSE,"Icon not indirected!");
  95.     strcpy(Text, "");
  96.   }
  97.   return(Text);
  98.  
  99. }
  100.  
  101.  
  102. void Wimp_Utils_Put_Icon_Text(wimp_w Window, wimp_i Icon, char *Text)
  103. {
  104.   wimp_icon Icon_Info;
  105.  
  106.   wimp_get_icon_info(Window,Icon,&Icon_Info);
  107.   if ((Icon_Info.flags & wimp_INDIRECT) !=0)
  108.   {
  109.     strcpy(Icon_Info.data.indirecttext.buffer, Text);
  110.     wimp_set_icon_state(Window,Icon,0,0);
  111.   }
  112.   else
  113.   {
  114.     werr(FALSE,"Icon not indirected!");
  115.   }
  116. }
  117.  
  118.  
  119. /* wimp_utils_icon_empty
  120.  * Check if an icon is empty
  121.  * Parameters:
  122.  *    window : window handle
  123.  *    icon   : icon number
  124.  *
  125.  * ERROR IN THIS ? - NOT INCLUDED AT MOMENT!!!!
  126. BOOL wimp_utils_icon_empty(wimp_w window, wimp_i icon)
  127. {
  128.   char temp_string[256]="";
  129.  
  130.   strcpy(temp_string,wimp_utils_get_icon_text(window, icon));
  131.  
  132.   if (strlen(temp_string) > 0)
  133.     return (FALSE);
  134.   else
  135.     return (TRUE);
  136. } */
  137.  
  138.  
  139. void Wimp_Utils_Disable_Icon(wimp_w Window, wimp_i Icon)
  140. {
  141.   wimp_set_icon_state(Window,Icon,wimp_INOSELECT,wimp_INOSELECT);
  142. }
  143.  
  144.  
  145.  
  146. void Wimp_Utils_Enable_Icon(wimp_w Window, wimp_i Icon)
  147. {
  148.   wimp_set_icon_state(Window,Icon,0,wimp_INOSELECT);
  149. }
  150.  
  151.  
  152. BOOL Wimp_Utils_Isselected(wimp_w Window, wimp_i Icon)
  153. {
  154.   wimp_icon Icon_Info;
  155.  
  156.   wimp_get_icon_info(Window,Icon,&Icon_Info);
  157.   if ((Icon_Info.flags & wimp_ISELECTED) !=0)
  158.      return TRUE;
  159.   else
  160.      return FALSE;
  161. }
  162.  
  163.  
  164. void Wimp_Utils_Program_Info(char *Temp_Name, Version_Info The_Version_Info)
  165. {
  166.   dbox  d;  /* Dialogue box handle */
  167.  
  168.   /* Create the dialogue box */
  169.   if (d = dbox_new(Temp_Name), d != NULL)
  170.   {
  171.     /* Fill in the version details, all others should be set in template
  172.      * file.
  173.      */
  174.     dbox_setfield(d, The_Version_Info.Version_Ic, The_Version_Info.Version);
  175.  
  176.     /* Show the dialogue box */
  177.     dbox_show(d);
  178.  
  179.     /* Keep it on the screen as long as needed */
  180.     dbox_fillin(d);
  181.  
  182.     /* Dispose of the dialogue box */
  183.     dbox_dispose(&d);
  184.   }
  185. }
  186.  
  187. void Wimp_Utils_Help(char *Text, wimp_msgstr *Msg)
  188. {
  189.     Msg->hdr.your_ref = Msg->hdr.my_ref;
  190.     Msg->hdr.action = wimp_MHELPREPLY;
  191.     Msg->hdr.size = 256;
  192.     sprintf(Msg->data.helpreply.text, Text);
  193.     wimpt_noerr(wimp_sendmessage(wimp_ESEND, Msg,
  194.                                     Msg->hdr.task));
  195. }
  196.  
  197.  
  198. /* end of wimputils.c */
  199.