home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / utilities / utilst / templ_aof / c / template
Text File  |  1995-04-08  |  3KB  |  115 lines

  1. /*
  2.  *      template.c                       RISC_OSLib template file management
  3.  *      Mofidifed by G.K.Saliaris to handle templates embedded in executable
  4.  */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <string.h>
  10. #include "swis.h"
  11.  
  12. #include "os.h"
  13. #include "wimp.h"
  14. #include "wimpt.h"
  15. #include "res.h"
  16. #include "sprite.h"
  17. #include "resspr.h"
  18. #include "werr.h"
  19. #include "template.h"
  20. #include "msgs.h"
  21.  
  22. extern  template *_template__list;      /* Embedded templates held in private linked list */
  23.  
  24.  
  25. template *template_find(char *title)
  26. {
  27.         template *t = _template__list;
  28.         int len = strlen(title);
  29.         while (t != 0)
  30.         {
  31.                 char *s = t->name;
  32.                 if (strncmp(title, s, len )==0 && s[len]<32)  break;
  33.                 t=t->next;
  34.         }
  35.         if (t == 0) werr(1, msgs_lookup("template1:Template '%s' not found"), title);
  36.         return(t);
  37. }
  38.  
  39.  
  40. template *template_copy(template *from)
  41. {
  42.         template *to;
  43.         int j;
  44.         int size = sizeof(template) + from->window.nicons * sizeof(wimp_icon);
  45.  
  46.         /* --- copy the template --- */
  47.         to = malloc(size);
  48.         if (to == 0) return 0;
  49.         memcpy(to, from, size);
  50.  
  51.         /* --- allocate and copy workspace --- */
  52.         if (to->workspacesize != 0)
  53.         {
  54.                 to->workspace = malloc(to->workspacesize);
  55.                 if (to->workspace == 0)
  56.                 {
  57.                         free(to);
  58.                         return 0;
  59.                 }
  60.                 memcpy(to->workspace, from->workspace, to->workspacesize);
  61.  
  62.                 /* - fix up indirect icon pointers - */
  63.                 for (j=0; j<to->window.nicons; j++)
  64.                 {
  65.                         wimp_icon *i = ((wimp_icon *)(&to->window + 1)) + j;
  66.                         if ((i->flags & wimp_INDIRECT) != 0)
  67.                         {
  68.                                 i->data.indirecttext.buffer += to->workspace - from->workspace;
  69.                                 if ((i->flags & wimp_ITEXT) != 0 &&
  70.                                         ((int) i->data.indirecttext.validstring) > 0)
  71.                                         i->data.indirecttext.validstring += to->workspace - from->workspace;
  72.                         }
  73.                 }
  74.  
  75.                 /* --- fix up relocated title pointer --- */
  76.                 if ((to->window.titleflags & wimp_INDIRECT) != 0)
  77.                         to->window.title.indirecttext.buffer += to->workspace - from->workspace;
  78.  
  79.         }
  80.         to->next = 0;
  81.         return(to);
  82. }
  83.  
  84.  
  85. BOOL template_loaded(void)
  86. {
  87.         return ((BOOL)_template__list);
  88. }
  89.  
  90.  
  91. void template_init(void)
  92. {
  93.         template *t = _template__list;
  94.         while (t != 0)
  95.         {
  96.                 /* bind sprite area appropriately */
  97.                 t->window.spritearea = resspr_area();
  98.                 t=t->next;
  99.         }
  100.         return;
  101. }
  102.  
  103.  
  104. wimp_wind *template_syshandle(char *name)
  105. {
  106.         template *tem;
  107.  
  108.         /* find template in linked list */
  109.         if ((tem = template_find(name)) == 0)
  110.                 return ((wimp_wind *)0);
  111.  
  112.         /* return pointer to underlying window structure */
  113.         return (&(tem -> window));
  114. }
  115.