home *** CD-ROM | disk | FTP | other *** search
- /*
- * template.c RISC_OSLib template file management
- * Mofidifed by G.K.Saliaris to handle templates embedded in executable
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <string.h>
- #include "swis.h"
-
- #include "os.h"
- #include "wimp.h"
- #include "wimpt.h"
- #include "res.h"
- #include "sprite.h"
- #include "resspr.h"
- #include "werr.h"
- #include "template.h"
- #include "msgs.h"
-
- extern template *_template__list; /* Embedded templates held in private linked list */
-
-
- template *template_find(char *title)
- {
- template *t = _template__list;
- int len = strlen(title);
- while (t != 0)
- {
- char *s = t->name;
- if (strncmp(title, s, len )==0 && s[len]<32) break;
- t=t->next;
- }
- if (t == 0) werr(1, msgs_lookup("template1:Template '%s' not found"), title);
- return(t);
- }
-
-
- template *template_copy(template *from)
- {
- template *to;
- int j;
- int size = sizeof(template) + from->window.nicons * sizeof(wimp_icon);
-
- /* --- copy the template --- */
- to = malloc(size);
- if (to == 0) return 0;
- memcpy(to, from, size);
-
- /* --- allocate and copy workspace --- */
- if (to->workspacesize != 0)
- {
- to->workspace = malloc(to->workspacesize);
- if (to->workspace == 0)
- {
- free(to);
- return 0;
- }
- memcpy(to->workspace, from->workspace, to->workspacesize);
-
- /* - fix up indirect icon pointers - */
- for (j=0; j<to->window.nicons; j++)
- {
- wimp_icon *i = ((wimp_icon *)(&to->window + 1)) + j;
- if ((i->flags & wimp_INDIRECT) != 0)
- {
- i->data.indirecttext.buffer += to->workspace - from->workspace;
- if ((i->flags & wimp_ITEXT) != 0 &&
- ((int) i->data.indirecttext.validstring) > 0)
- i->data.indirecttext.validstring += to->workspace - from->workspace;
- }
- }
-
- /* --- fix up relocated title pointer --- */
- if ((to->window.titleflags & wimp_INDIRECT) != 0)
- to->window.title.indirecttext.buffer += to->workspace - from->workspace;
-
- }
- to->next = 0;
- return(to);
- }
-
-
- BOOL template_loaded(void)
- {
- return ((BOOL)_template__list);
- }
-
-
- void template_init(void)
- {
- template *t = _template__list;
- while (t != 0)
- {
- /* bind sprite area appropriately */
- t->window.spritearea = resspr_area();
- t=t->next;
- }
- return;
- }
-
-
- wimp_wind *template_syshandle(char *name)
- {
- template *tem;
-
- /* find template in linked list */
- if ((tem = template_find(name)) == 0)
- return ((wimp_wind *)0);
-
- /* return pointer to underlying window structure */
- return (&(tem -> window));
- }
-