Annotation of Amaya/amaya/templates.c, revision 1.214
1.1 cvs 1: /*
2: *
1.162 vatton 3: * COPYRIGHT INRIA and W3C, 1996-2008
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
1.206 kia 7:
1.1 cvs 8: /*
1.51 francesc 9: * Authors: Francesc Campoy Flores
1.210 vatton 10: * Emilien Kia
1.1 cvs 11: *
12: */
13:
1.194 kia 14:
1.1 cvs 15: #define THOT_EXPORT extern
16: #include "amaya.h"
17: #include "document.h"
1.99 kia 18: #include "undo.h"
1.90 kia 19: #include "containers.h"
20: #include "Elemlist.h"
1.92 kia 21: #include "templates.h"
22:
1.46 vatton 23: #ifdef TEMPLATES
24: #include "Template.h"
1.52 vatton 25: #include "templateDeclarations.h"
1.140 vatton 26:
27: #include "html2thot_f.h"
1.174 kia 28: #include "HTMLedit_f.h"
1.122 kia 29: #include "templates_f.h"
1.89 kia 30: #include "templateUtils_f.h"
1.67 quint 31: #include "templateLoad_f.h"
32: #include "templateDeclarations_f.h"
1.76 vatton 33: #include "templateInstantiate_f.h"
1.145 kia 34: #include "Templatebuilder_f.h"
1.28 tollenae 35: #include "appdialogue_wx.h"
1.29 tollenae 36: #include "init_f.h"
1.46 vatton 37: #include "wxdialogapi_f.h"
1.60 francesc 38: #include "AHTURLTools_f.h"
1.52 vatton 39: #endif /* TEMPLATES */
1.1 cvs 40:
1.87 kia 41: #include "fetchXMLname_f.h"
1.83 kia 42: #include "MENUconf.h"
43:
44: /* Paths from which looking for templates.*/
45: static Prop_Templates_Path *TemplateRepositoryPaths;
1.209 vatton 46: // register the parent repeat of the new created use
47: static Element Creating_repeat = NULL;
48:
1.83 kia 49:
1.87 kia 50: /*----------------------------------------------------------------------
51: IsTemplateInstanceDocument: Test if a document is a template instance
52: doc : Document to test
53: return : TRUE if the document is a template instance
54: ----------------------------------------------------------------------*/
1.106 vatton 55: ThotBool IsTemplateInstanceDocument(Document doc)
56: {
1.87 kia 57: #ifdef TEMPLATES
1.213 vatton 58: // check first indicators
59: if (DocumentMeta[doc])
60: {
61: if (DocumentMeta[doc]->method == CE_INSTANCE)
62: return TRUE;
63: else if (DocumentMeta[doc]->method == CE_TEMPLATE)
64: return FALSE;
65: }
1.171 kia 66: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.209 vatton 67: if (t)
1.210 vatton 68: return ((t->state & templInstance) != 0);
1.171 kia 69: else
70: return FALSE;
71: #else /* TEMPLATES */
1.88 cvs 72: return FALSE;
1.206 kia 73: #endif /* TEMPLATES */
1.87 kia 74: }
75:
1.83 kia 76: /*----------------------------------------------------------------------
1.109 kia 77: IsTemplateDocument: Test if a document is a template (not an instance)
78: doc : Document to test
1.167 kia 79: return : TRUE if the document is a template
1.109 kia 80: ----------------------------------------------------------------------*/
1.183 vatton 81: ThotBool IsTemplateDocument (Document doc)
1.109 kia 82: {
83: #ifdef TEMPLATES
1.171 kia 84: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.183 vatton 85: if (t)
86: return ((t->state & templTemplate) != 0);
1.171 kia 87: else
88: return FALSE;
1.206 kia 89: #endif /* TEMPLATES */
1.171 kia 90: return FALSE;
91: }
92:
93:
94: /*----------------------------------------------------------------------
1.210 vatton 95: GetUsedTypeName returns the name of the current used type or the first
96: name of the types attribute
97: The returned string must be freed
98: ----------------------------------------------------------------------*/
99: char *GetUsedTypeName (Element el)
100: {
101: char *name = NULL;
102: #ifdef TEMPLATES
103: char *ptr;
104:
105: if (IsTemplateElement (el))
106: {
107: name = GetAttributeStringValueFromNum (el, Template_ATTR_currentType, NULL);
108: if (name == NULL)
109: {
110: // use the first type
111: name = GetAttributeStringValueFromNum (el, Template_ATTR_types, NULL);
112: if (name)
113: {
114: ptr = strstr (name, " ");
115: if (ptr)
116: *ptr = EOS;
117: }
118: return name;
119: }
120: }
121: #endif /* TEMPLATES */
122: return name;
123: }
124:
125: /*----------------------------------------------------------------------
1.214 ! vatton 126: IsInLineTemplateElement returns TRUE if the template element can be
! 127: inserted into a paragraph
! 128: ----------------------------------------------------------------------*/
! 129: ThotBool IsInLineTemplateElement (Element el, Document doc)
! 130: {
! 131: #ifdef TEMPLATES
! 132: XTigerTemplate t;
! 133: ElementType elType;
! 134: Declaration dec;
! 135: char *name = NULL;
! 136:
! 137: elType = TtaGetElementType (el);
! 138: if (elType.ElTypeNum == Template_EL_useEl ||
! 139: elType.ElTypeNum == Template_EL_useSimple)
! 140: {
! 141: t = GetXTigerDocTemplate(doc);
! 142: if (t)
! 143: {
! 144: name = GetUsedTypeName (el);
! 145: dec = Template_GetDeclaration (t, name);
! 146: TtaFreeMemory (name);
! 147: if (dec)
! 148: return !dec->blockLevel;
! 149: else
! 150: return FALSE;
! 151: }
! 152: }
! 153: #else /* TEMPLATES */
! 154: #endif /* TEMPLATES */
! 155: return FALSE;
! 156: }
! 157:
! 158: /*----------------------------------------------------------------------
1.171 kia 159: Test if a document is an internal template.
160: (no instance is opened and it is not edited)
161: ----------------------------------------------------------------------*/
162: ThotBool IsInternalTemplateDocument(Document doc)
163: {
164: #ifdef TEMPLATES
165: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.209 vatton 166: if (t)
1.214 ! vatton 167: return (t->state & templInternal) != 0;
1.171 kia 168: else
169: return FALSE;
170: #else /* TEMPLATES */
1.109 kia 171: return FALSE;
1.206 kia 172: #endif /* TEMPLATES */
1.171 kia 173: }
174:
175: /*----------------------------------------------------------------------
176: Return the URL of an instance template.
177: ----------------------------------------------------------------------*/
178: char* GetDocumentInstanceTemplateUrl(Document doc)
179: {
180: #ifdef TEMPLATES
181: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.209 vatton 182: if (t)
1.171 kia 183: return t->base_uri;
184: else
185: return FALSE;
186: #else /* TEMPLATES */
187: return NULL;
1.206 kia 188: #endif /* TEMPLATES */
1.109 kia 189: }
190:
1.146 vatton 191: /*----------------------------------------------------------------------
192: CheckPromptIndicator checks if the element is a prompt text unit
193: ----------------------------------------------------------------------*/
194: ThotBool CheckPromptIndicator (Element el, Document doc)
195: {
196: #ifdef TEMPLATES
197: ElementType elType;
198: Element parent;
199: AttributeType attrType;
200: Attribute att;
201: SSchema templateSSchema;
202:
1.173 vatton 203: if (!IsTemplateInstanceDocument(doc))
204: /* let Thot perform normal operation */
205: return FALSE;
1.146 vatton 206: elType = TtaGetElementType (el);
207: templateSSchema = TtaGetSSchema ("Template", doc);
208: if (elType.ElTypeNum == HTML_EL_TEXT_UNIT)
209: {
210: parent = TtaGetParent (el);
211: elType = TtaGetElementType (parent);
212: while (parent && elType.ElSSchema != templateSSchema)
213: {
214: parent = TtaGetParent (parent);
215: elType = TtaGetElementType (parent);
216: }
217: if (parent &&
218: (elType.ElTypeNum == Template_EL_useEl ||
219: elType.ElTypeNum == Template_EL_useSimple))
220: {
221: // there is a parent template use
222: attrType.AttrSSchema = elType.ElSSchema;
223: attrType.AttrTypeNum = Template_ATTR_prompt;
224: att = TtaGetAttribute (parent, attrType);
225: if (att)
1.151 quint 226: {
227: TtaSelectElement (doc, el);
228: return TRUE;
229: }
1.146 vatton 230: }
231: }
232: #endif /* TEMPLATES */
1.173 vatton 233: /* let Thot perform normal operation */
1.146 vatton 234: return FALSE;
235: }
236:
237: /*----------------------------------------------------------------------
238: RemovePromptIndicator removes the enclosing prompt indicator
239: ----------------------------------------------------------------------*/
1.153 vatton 240: ThotBool RemovePromptIndicator (NotifyOnTarget *event)
1.146 vatton 241: {
242: #ifdef TEMPLATES
243: ElementType elType;
1.153 vatton 244: Element parent, el;
1.146 vatton 245: AttributeType attrType;
246: Attribute att;
1.153 vatton 247: Document doc;
1.146 vatton 248: SSchema templateSSchema;
249:
1.153 vatton 250: el = event->element;
251: doc = event->document;
1.146 vatton 252: elType = TtaGetElementType (el);
253: templateSSchema = TtaGetSSchema ("Template", doc);
1.153 vatton 254: parent = TtaGetParent (el);
255: elType = TtaGetElementType (parent);
256: while (parent && elType.ElSSchema != templateSSchema)
1.146 vatton 257: {
1.153 vatton 258: parent = TtaGetParent (parent);
1.146 vatton 259: elType = TtaGetElementType (parent);
1.153 vatton 260: }
261: if (parent &&
262: (elType.ElTypeNum == Template_EL_useEl ||
263: elType.ElTypeNum == Template_EL_useSimple))
264: {
265: // there is a parent template use
266: attrType.AttrSSchema = elType.ElSSchema;
267: attrType.AttrTypeNum = Template_ATTR_prompt;
268: att = TtaGetAttribute (parent, attrType);
269: if (att)
1.146 vatton 270: {
1.153 vatton 271: TtaRegisterAttributeDelete (att, parent, doc);
272: TtaRemoveAttribute (parent, att, doc);
1.146 vatton 273: }
274: }
275: #endif /* TEMPLATES */
1.153 vatton 276: return FALSE; /* let Thot perform normal operation */
1.146 vatton 277: }
278:
1.109 kia 279:
280: /*----------------------------------------------------------------------
1.108 vatton 281: AllocTemplateRepositoryListElement: allocates an element for the list
282: of template repositories.
1.83 kia 283: path : path of the new element
284: return : address of the new element
285: ----------------------------------------------------------------------*/
286: void* AllocTemplateRepositoryListElement (const char* path, void* prevElement)
287: {
1.129 vatton 288: Prop_Templates_Path *element;
289:
290: element = (Prop_Templates_Path*)TtaGetMemory (sizeof(Prop_Templates_Path));
291: memset (element, 0, sizeof(Prop_Templates_Path));
292: strncpy (element->Path, path, MAX_LENGTH - 1);
1.83 kia 293: if (prevElement)
1.129 vatton 294: {
295: element->NextPath = ((Prop_Templates_Path*)prevElement)->NextPath;
296: ((Prop_Templates_Path*)prevElement)->NextPath = element;
297: }
1.83 kia 298: return element;
299: }
300:
301:
302: /*----------------------------------------------------------------------
303: FreeTemplateRepositoryList: Free the list of template repositories.
304: list : address of the list (address of the first element).
305: ----------------------------------------------------------------------*/
306: void FreeTemplateRepositoryList (void* list)
307: {
1.131 vatton 308: Prop_Templates_Path **l = (Prop_Templates_Path**) list;
309: Prop_Templates_Path *element = *l;
310:
1.83 kia 311: l = NULL;
312: while (element)
1.209 vatton 313: {
314: Prop_Templates_Path* next = element->NextPath;
315: TtaFreeMemory (element);
316: element = next;
317: }
1.83 kia 318: }
319:
320: /*----------------------------------------------------------------------
321: CopyTemplateRepositoryList: Copy a list of template repositories.
322: src : address of the list (address of the first element).
323: dst : address where copy the list
324: ----------------------------------------------------------------------*/
1.91 vatton 325: static void CopyTemplateRepositoryList (const Prop_Templates_Path** src,
326: Prop_Templates_Path** dst)
1.83 kia 327: {
328: Prop_Templates_Path *element=NULL, *current=NULL;
1.206 kia 329:
1.131 vatton 330: if (*src)
1.209 vatton 331: {
332: *dst = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));
333: (*dst)->NextPath = NULL;
334: strcpy((*dst)->Path, (*src)->Path);
335:
336: element = (*src)->NextPath;
337: current = *dst;
338: }
1.83 kia 339:
1.106 vatton 340: while (element)
341: {
1.209 vatton 342: current->NextPath = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));
343: current = current->NextPath;
344: current->NextPath = NULL;
345: strcpy(current->Path, element->Path);
346: element = element->NextPath;
1.106 vatton 347: }
1.83 kia 348: }
349:
350: /*----------------------------------------------------------------------
351: LoadTemplateRepositoryList: Load the list of template repositories.
352: list : address of the list (address of the first element).
353: return : the number of readed repository paths.
354: ----------------------------------------------------------------------*/
355: static int LoadTemplateRepositoryList (Prop_Templates_Path** list)
356: {
357: Prop_Templates_Path *element, *current = NULL;
358: char *path, *homePath;
359: unsigned char *c;
360: int nb = 0;
361: FILE *file;
1.206 kia 362:
1.131 vatton 363: //clean up the curent list
364: FreeTemplateRepositoryList (list);
365:
366: // open the file
1.83 kia 367: path = (char *) TtaGetMemory (MAX_LENGTH);
1.86 vatton 368: homePath = TtaGetEnvString ("APP_HOME");
1.106 vatton 369: sprintf (path, "%s%ctemplates.dat", homePath, DIR_SEP);
1.83 kia 370: file = TtaReadOpen ((char *)path);
1.84 kia 371: if (!file)
1.209 vatton 372: {
373: /* The config file dont exist, create it. */
374: file = TtaWriteOpen ((char *)path);
375: fprintf (file, "http://www.w3.org/Amaya/Templates/cv.xtd\n");
376: fprintf (file, "http://www.w3.org/Amaya/Templates/slides.xtd\n");
377: fprintf (file, "http://www.w3.org/Amaya/Templates/ACM-Proc-Article.xtd\n");
378: TtaWriteClose (file);
379: /* Retry to open it.*/
380: file = TtaReadOpen ((char *)path);
381: }
1.206 kia 382:
1.83 kia 383: if (file)
1.129 vatton 384: {
1.131 vatton 385: // read the file
1.129 vatton 386: c = (unsigned char*)path;
387: *c = EOS;
388: while (TtaReadByte (file, c))
389: {
390: if (*c == 13 || *c == EOL)
391: *c = EOS;
392: if (*c == EOS && c != (unsigned char*)path )
393: {
394: element = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));
395: element->NextPath = NULL;
396: strcpy (element->Path, path);
1.148 kia 397:
1.129 vatton 398: if (*list == NULL)
1.206 kia 399: *list = element;
1.129 vatton 400: else
401: current->NextPath = element;
402: current = element;
403: nb++;
1.83 kia 404:
1.129 vatton 405: c = (unsigned char*) path;
406: *c = EOS;
407: }
408: else
409: c++;
410: }
411: if (c != (unsigned char*)path && *path != EOS)
412: {
413: element = (Prop_Templates_Path*) TtaGetMemory (sizeof(Prop_Templates_Path));
414: *(c+1) = EOS;
415: strcpy (element->Path, path);
416: element->NextPath = NULL;
1.148 kia 417:
1.129 vatton 418: if (*list == NULL)
1.206 kia 419: *list = element;
1.129 vatton 420: else
421: current->NextPath = element;
422: nb++;
423: }
424: TtaReadClose (file);
1.83 kia 425: }
426: TtaFreeMemory(path);
427: return nb;
428: }
429:
430: /*----------------------------------------------------------------------
431: SaveTemplateRepositoryList: Save the list of template repositories.
432: list : address of the list (address of the first element).
433: ----------------------------------------------------------------------*/
434: static void SaveTemplateRepositoryList (const Prop_Templates_Path** list)
435: {
436: const Prop_Templates_Path *element;
437: char *path, *homePath;
438: unsigned char *c;
439: FILE *file;
440:
441: path = (char *) TtaGetMemory (MAX_LENGTH);
442: homePath = TtaGetEnvString ("APP_HOME");
1.106 vatton 443: sprintf (path, "%s%ctemplates.dat", homePath, DIR_SEP);
1.83 kia 444:
445: file = TtaWriteOpen ((char *)path);
446: c = (unsigned char*)path;
447: *c = EOS;
448: if (file)
449: {
1.209 vatton 450: element = *list;
451: while (element)
452: {
453: fprintf(file, "%s\n", element->Path);
454: element = element->NextPath;
455: }
456: TtaWriteClose (file);
1.83 kia 457: }
458: }
459:
460: /*----------------------------------------------------------------------
461: GetTemplateRepositoryList: Get the list of template repositories from template environment.
462: list : address of the list (address of the first element).
463: ----------------------------------------------------------------------*/
464: void GetTemplateRepositoryList (void* list)
465: {
466: Prop_Templates_Path** l = (Prop_Templates_Path**) list;
467: CopyTemplateRepositoryList((const Prop_Templates_Path**)&TemplateRepositoryPaths, l);
468: }
469:
470: /*----------------------------------------------------------------------
471: SetTemplateRepositoryList: Set the list of template repositories environment.
472: list : address of the list (address of the first element).
473: ----------------------------------------------------------------------*/
474: void SetTemplateRepositoryList (const void* list)
475: {
476: const Prop_Templates_Path** l = (const Prop_Templates_Path**) list;
477: CopyTemplateRepositoryList((const Prop_Templates_Path**)l, &TemplateRepositoryPaths);
478: SaveTemplateRepositoryList((const Prop_Templates_Path**)&TemplateRepositoryPaths);
479: }
480:
481: /*-----------------------------------------------------------------------
1.209 vatton 482: InitTemplates
483: Initializes the annotation library
1.83 kia 484: -----------------------------------------------------------------------*/
485: void InitTemplates ()
486: {
487: TtaSetEnvBoolean ("SHOW_TEMPLATES", TRUE, FALSE);
1.131 vatton 488: LoadTemplateRepositoryList (&TemplateRepositoryPaths);
1.83 kia 489: }
490:
491:
1.1 cvs 492: /*----------------------------------------------------------------------
1.206 kia 493: Load a template and create the instance file - update images and
1.108 vatton 494: stylesheets related to the template.
495: ----------------------------------------------------------------------*/
496: void CreateInstanceOfTemplate (Document doc, char *templatename, char *docname)
497: {
498: #ifdef TEMPLATES
1.170 vatton 499: DocumentType docType;
500: int len, i;
501: char *s;
502: char suffix[6];
503: ThotBool dontReplace = DontReplaceOldDoc;
1.108 vatton 504:
505: if (!IsW3Path (docname) && TtaFileExist (docname))
506: {
507: s = (char *)TtaGetMemory (strlen (docname) +
508: strlen (TtaGetMessage (AMAYA, AM_OVERWRITE_CHECK)) + 2);
509: sprintf (s, TtaGetMessage (AMAYA, AM_OVERWRITE_CHECK), docname);
510: InitConfirm (0, 0, s);
511: TtaFreeMemory (s);
512: if (!UserAnswer)
513: return;
514: }
1.170 vatton 515: docType = LoadTemplate (0, templatename);
516: if (docType != docFree)
1.165 kia 517: {
1.170 vatton 518: /* check if the file suffix is conform to the document type */
519: s = (char *)TtaGetMemory (strlen (docname) + 10);
520: strcpy (s, docname);
521: if (!IsXMLName (docname))
522: {
523: // by default no suffix is added
524: suffix[0] = EOS;
525: if (IsMathMLName (docname) && docType != docMath)
526: strcpy (suffix, "mml");
527: else if (IsSVGName (docname) && docType != docSVG)
528: strcpy (suffix, "svg");
529: else if (IsHTMLName (docname) && docType != docHTML)
530: strcpy (suffix, "xml");
531: if (suffix[0] != EOS)
532: {
533: // change or update the suffix
534: len = strlen (s);
535: for (i = len-1; i > 0 && s[i] != '.'; i--);
536: if (s[i] != '.')
537: {
538: /* there is no suffix */
539: s[i++] = '.';
540: strcpy (&s[i], suffix);
541: }
542: else
543: {
544: /* there is a suffix */
545: i++;
546: strcpy (&s[i], suffix);
547: }
548: }
549: }
550: // now create the instance
1.165 kia 551: DontReplaceOldDoc = dontReplace;
1.177 vatton 552: CreateInstance (templatename, s, docname, docType, doc);
1.170 vatton 553: TtaFreeMemory (s);
1.165 kia 554: }
1.108 vatton 555: #endif /* TEMPLATES */
556: }
557:
1.53 vatton 558:
1.109 kia 559:
1.52 vatton 560: /*----------------------------------------------------------------------
1.107 kia 561: PreventReloadingTemplate
562: Prevent reloading a template.
563: You must call AllowReloadingTemplate when finish.
564: Usefull for reload an instance without reloading the template.
565: ----------------------------------------------------------------------*/
566: void PreventReloadingTemplate(char* template_url)
567: {
568: #ifdef TEMPLATES
1.178 kia 569: Template_AddReference(GetXTigerTemplate (template_url));
1.107 kia 570: #endif /* TEMPLATES */
571: }
572:
573: /*----------------------------------------------------------------------
574: AllowReloadingTemplate
575: Allow reloading a template.
576: You must call it after each PreventReloadingTemplate call.
577: ----------------------------------------------------------------------*/
578: void AllowReloadingTemplate(char* template_url)
579: {
580: #ifdef TEMPLATES
1.178 kia 581: Template_RemoveReference(GetXTigerTemplate (template_url));
1.206 kia 582: #endif /* TEMPLATES */
1.107 kia 583: }
584:
585:
1.137 vatton 586: /*----------------------------------------------------------------------
587: ----------------------------------------------------------------------*/
1.134 kia 588: ThotBool isEOSorWhiteSpace (const char c)
589: {
1.137 vatton 590: return c == SPACE || c == TAB || c == EOL || c ==__CR__ || c == EOS;
591: }
592: ThotBool isWhiteSpace (const char c)
593: {
594: return c == SPACE || c == TAB || c == EOL || c ==__CR__;
1.134 kia 595: }
596:
1.107 kia 597: /*----------------------------------------------------------------------
1.87 kia 598: giveItems : Lists type items from string
599: example : "one two three" is extracted to {one, two, three}
600: note : item type are setted to SimpleTypeNat
601: text : text from which list items
602: size : size of text in characters
603: items : address of exctracted item list
604: nbitems : items number in items list
1.52 vatton 605: ----------------------------------------------------------------------*/
1.76 vatton 606: void giveItems (char *text, int size, struct menuType **items, int *nbitems)
1.1 cvs 607: {
1.70 quint 608: #ifdef TEMPLATES
1.148 kia 609: ThotBool inElement = TRUE;
1.52 vatton 610: struct menuType *menu;
611: char *iter;
1.148 kia 612: char temp[128];
1.52 vatton 613: int i;
1.148 kia 614: int labelSize;
1.28 tollenae 615:
1.148 kia 616: *nbitems = 1;
617: for (i = 0; i < size; i++)
1.52 vatton 618: {
619: if (isEOSorWhiteSpace (text[i]))
620: {
621: if (inElement)
622: inElement = FALSE;
623: }
624: else if (!inElement)
625: {
626: inElement = TRUE;
627: (*nbitems)++;
628: }
629: }
1.51 francesc 630:
1.148 kia 631: menu = (struct menuType*) TtaGetMemory (sizeof (struct menuType)* *nbitems);
632: iter = text;
633: for (i = 0; i < *nbitems; i++)
634: {
1.52 vatton 635: labelSize = 0;
1.137 vatton 636: while (isWhiteSpace (*iter))
1.52 vatton 637: iter++;
1.137 vatton 638: if (*iter != EOS)
639: {
640: while (!isEOSorWhiteSpace (*iter))
641: {
642: temp[labelSize++] = *iter;
643: iter++;
644: }
1.52 vatton 645:
1.137 vatton 646: temp[labelSize] = EOS;
647: menu[i].label = (char *) TtaStrdup (temp);
648: menu[i].type = SimpleTypeNat; /* @@@@@ ???? @@@@@ */
1.52 vatton 649: }
650: }
1.137 vatton 651: *items = menu;
1.70 quint 652: #endif /* TEMPLATES */
1.28 tollenae 653: }
1.37 tollenae 654:
1.70 quint 655: #ifdef TEMPLATES
1.52 vatton 656: /*----------------------------------------------------------------------
657: ----------------------------------------------------------------------*/
658: static char *createMenuString (const struct menuType* items, const int nbItems)
659: {
660: char *result, *iter;
1.148 kia 661: int size = 0;
1.52 vatton 662: int i;
663:
1.148 kia 664: for (i=0; i < nbItems; i++)
665: size += 2 + strlen (items[i].label);
1.52 vatton 666:
1.148 kia 667: result = (char *) TtaGetMemory (size);
668: iter = result;
669: for (i=0; i < nbItems; i++)
1.52 vatton 670: {
671: *iter = 'B';
672: ++iter;
1.148 kia 673:
1.52 vatton 674: strcpy (iter, items[i].label);
675: iter += strlen (items[i].label)+1;
676: }
1.148 kia 677: return result;
1.36 tollenae 678: }
1.71 quint 679: #endif /* TEMPLATES */
1.29 tollenae 680:
1.185 kia 681:
682: /*----------------------------------------------------------------------
1.71 quint 683: UseToBeCreated
684: An new use element will be created by the user through some generic editing
685: command
686: -----------------------------------------------------------------------*/
687: ThotBool UseToBeCreated (NotifyElement *event)
688: {
689: #ifdef TEMPLATES
1.122 kia 690: ElementType parentType;
1.206 kia 691: SSchema templateSSchema = TtaGetSSchema ("Template", event->document);
1.130 vatton 692: if (templateSSchema)
1.209 vatton 693: {
694: parentType = TtaGetElementType (event->element);
695: if (parentType.ElSSchema == templateSSchema &&
696: parentType.ElTypeNum == Template_EL_repeat)
697: {
698: if (Template_CanInsertRepeatChild (event->element))
699: return TemplateElementWillBeCreated (event);
700: else
701: return TRUE; //don't let Thot do the job
702: }
703: else
704: return TemplateElementWillBeCreated (event);
705: }
1.52 vatton 706: #endif /* TEMPLATES */
1.71 quint 707: return FALSE; /* let Thot perform normal operation */
708: }
709:
710: /*----------------------------------------------------------------------
711: UseCreated
712: A new "use" element has just been created by the user with a generic editing
713: command.
714: -----------------------------------------------------------------------*/
715: void UseCreated (NotifyElement *event)
716: {
717: #ifdef TEMPLATES
1.148 kia 718: Document doc = event->document;
719: Element el = event->element;
1.117 kia 720: Element parent;
721: Element first;
722: ElementType parentType;
723: XTigerTemplate t;
724: SSchema templateSSchema;
1.130 vatton 725: char* types, *text = NULL;
1.148 kia 726:
1.112 vatton 727: if (!TtaGetDocumentAccessMode(doc))
1.110 kia 728: return;
729:
1.72 quint 730: if (TtaGetFirstChild (el))
731: /* this Use element has already some content. It has already been
732: instanciated */
733: return;
1.117 kia 734:
1.171 kia 735: t = GetXTigerDocTemplate (doc);
1.71 quint 736: if (!t)
737: return; // no template ?!?!
1.101 kia 738:
1.138 vatton 739: templateSSchema = TtaGetSSchema ("Template", doc);
1.117 kia 740: parent = TtaGetParent(el);
741: parentType = TtaGetElementType(parent);
1.148 kia 742:
1.130 vatton 743: if (parentType.ElSSchema == templateSSchema &&
744: parentType.ElTypeNum == Template_EL_repeat)
1.117 kia 745: {
1.209 vatton 746: first = TtaGetFirstChild (parent);
747: if (first == el)
748: TtaNextSibling (&first);
749: if (first)
750: {
751: types = GetAttributeStringValueFromNum (first, Template_ATTR_types, NULL);
752: if (types)
753: {
754: SetAttributeStringValueWithUndo (el, Template_ATTR_types, types);
755: text = GetAttributeStringValueFromNum (el, Template_ATTR_title, NULL);
756: SetAttributeStringValueWithUndo (first, Template_ATTR_title, text);
757: TtaFreeMemory (text);
758: text = GetAttributeStringValueFromNum (el, Template_ATTR_currentType, NULL);
759: SetAttributeStringValueWithUndo (first, Template_ATTR_currentType, text);
760: TtaFreeMemory (text);
761: TtaFreeMemory (types);
762: }
763: }
1.117 kia 764: }
765:
1.76 vatton 766: InstantiateUse (t, el, doc, TRUE);
1.71 quint 767: #endif /* TEMPLATES */
768: }
1.29 tollenae 769:
1.89 kia 770:
1.98 kia 771: /*----------------------------------------------------------------------
772: Template_CanInsertRepeatChild
773: Test if a xt:repeat child can be inserted (number between params min and max).
774: @param el element (xt:repeat) to test
775: @return True if an element can be inserted.
776: ----------------------------------------------------------------------*/
777: ThotBool Template_CanInsertRepeatChild(Element el)
778: {
779: #ifdef TEMPLATES
1.154 vatton 780: char *max;
781: int maxVal, curVal;
782: Element child;
1.148 kia 783:
1.104 kia 784: max = GetAttributeStringValueFromNum(el, Template_ATTR_maxOccurs, NULL);
1.191 kia 785: if (max && max[0]!=EOS)
1.104 kia 786: {
1.154 vatton 787: if (!strcmp(max, "*"))
788: {
789: TtaFreeMemory(max);
790: return TRUE;
791: }
792: maxVal = atoi (max);
793: TtaFreeMemory (max);
1.104 kia 794: curVal = 0;
1.105 vatton 795: for (child = TtaGetFirstChild(el); child; TtaNextSibling(&child))
1.104 kia 796: curVal++;
1.154 vatton 797: return (curVal < maxVal);
1.104 kia 798: }
799: else
1.98 kia 800: return TRUE;
801: #endif /* TEMPLATES */
802: return FALSE;
803: }
1.96 kia 804:
1.89 kia 805:
1.92 kia 806: #ifdef TEMPLATES
1.99 kia 807: /*----------------------------------------------------------------------
808: QueryStringFromMenu
809: Show a context menu to query a choice.
810: @param items space-separated choice list string.
811: @return The choosed item string or NULL if none.
812: ----------------------------------------------------------------------*/
1.138 vatton 813: static char* QueryStringFromMenu (Document doc, char* items)
1.90 kia 814: {
815: int nbitems, size;
816: struct menuType *itemlist;
817: char *menuString;
818: char *result = NULL;
1.148 kia 819:
1.138 vatton 820: if (!TtaGetDocumentAccessMode (doc))
1.112 vatton 821: return NULL;
822: if (items == NULL)
1.110 kia 823: return NULL;
1.138 vatton 824: size = strlen (items);
825: if (size == 0)
826: return NULL;
1.90 kia 827: giveItems (items, size, &itemlist, &nbitems);
828: menuString = createMenuString (itemlist, nbitems);
1.206 kia 829: TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL,
1.90 kia 830: nbitems, menuString , NULL, false, 'L');
831: TtaFreeMemory (menuString);
832: ReturnOption = -1;
833: TtaShowDialogue (BaseDialog + OptionMenu, FALSE);
834: TtaWaitShowProcDialogue ();
835: TtaDestroyDialogue (BaseDialog + OptionMenu);
1.148 kia 836:
1.112 vatton 837: if (ReturnOption!=-1)
1.209 vatton 838: {
839: result = TtaStrdup(itemlist[ReturnOption].label);
840: }
1.206 kia 841:
1.90 kia 842: TtaFreeMemory (itemlist);
843: return result;
844: }
1.92 kia 845: #endif /* TEMPLATES */
1.90 kia 846:
1.158 kia 847: #ifdef AMAYA_DEBUG
848: void FillInsertableElemList (Document doc, Element elem, DLList list);
849: #endif /* AMAYA_DEBUG */
1.162 vatton 850: /*----------------------------------------------------------------------
851: ----------------------------------------------------------------------*/
852: char *Template_GetListTypes (XTigerTemplate t, Element el)
853: {
854: #ifdef TEMPLATES
855: char *listtypes = NULL, *types;
856:
857: types = GetAttributeStringValueFromNum (el, Template_ATTR_types, NULL);
858: if (types)
859: listtypes = Template_ExpandTypes (t, types, el, FALSE);
860: return listtypes;
861: #endif /* TEMPLATES */
862: }
1.158 kia 863:
1.56 francesc 864: /*----------------------------------------------------------------------
1.138 vatton 865: BagButtonClicked
866: Called when a bag button is clicked.
867: Can be called for useEl, useSimple or bag.
868: If called for useEl or useSimple, the new element must be added after.
869: If called for bag, the element must be added before all.
1.206 kia 870:
1.138 vatton 871: Shows a menu with all the types that can be used in the bag.
872: ----------------------------------------------------------------------*/
873: ThotBool BagButtonClicked (NotifyElement *event)
874: {
875: #ifdef TEMPLATES
876: Document doc = event->document;
877: Element el = event->element;
878: ElementType elType;
879: XTigerTemplate t;
880: Declaration decl;
881: Element bagEl = el;
882: Element firstEl;
883: Element newEl = NULL;
884: View view;
885: SSchema templateSSchema;
1.162 vatton 886: char *listtypes = NULL;
887: char *result = NULL;
1.138 vatton 888: ThotBool oldStructureChecking;
889: DisplayMode dispMode;
890:
1.182 vatton 891: if (!TtaGetDocumentAccessMode (doc))
1.138 vatton 892: return TRUE;
1.182 vatton 893: if (!IsTemplateInstanceDocument (doc))
894: return FALSE; /* let Thot perform normal operation */
1.148 kia 895:
1.138 vatton 896: TtaGetActiveView (&doc, &view);
897: if (view != 1)
898: return FALSE; /* let Thot perform normal operation */
899:
900: TtaCancelSelection (doc);
1.206 kia 901: templateSSchema = TtaGetSSchema ("Template", doc);
1.171 kia 902: t = GetXTigerDocTemplate(doc);
1.138 vatton 903: elType = TtaGetElementType (el);
904: while (bagEl &&
905: (elType.ElSSchema != templateSSchema ||
906: elType.ElTypeNum != Template_EL_bag))
907: {
908: bagEl = TtaGetParent (bagEl);
909: elType = TtaGetElementType (bagEl);
910: }
911:
912: if (bagEl)
1.209 vatton 913: {
914: listtypes = Template_GetListTypes (t, bagEl);
915: if (listtypes)
916: {
1.158 kia 917: #ifdef AMAYA_DEBUG
1.209 vatton 918: printf("BagButtonClicked : \n > %s\n", listtypes);
919: // {
920: // DLList list = DLList_Create();
921: // FillInsertableElemList (doc, TtaGetFirstChild(bagEl), list);
922: // DLListNode node;
923: // ForwardIterator iter = DLList_GetForwardIterator(list);
924: // ITERATOR_FOREACH(iter, DLListNode, node)
925: // {
926: // ElemListElement elem = (ElemListElement)node->elem;
927: // printf(" + %s\n", ElemListElement_GetName(elem));
928: // }
929: // DLList_Destroy(list);
930: // }
1.158 kia 931: #endif /* AMAYA_DEBUG */
1.209 vatton 932: result = QueryStringFromMenu (doc, listtypes);
933: TtaFreeMemory (listtypes);
934: if (result)
935: {
936: decl = Template_GetDeclaration (t, result);
937: if (decl)
938: {
939: dispMode = TtaGetDisplayMode (doc);
940: if (dispMode == DisplayImmediately)
941: /* don't set NoComputedDisplay
942: -> it breaks down views formatting when Enter generates new elements */
943: TtaSetDisplayMode (doc, DeferredDisplay);
944:
945: /* Prepare insertion.*/
946: oldStructureChecking = TtaGetStructureChecking (doc);
947: TtaSetStructureChecking (FALSE, doc);
948: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
949:
950: /* Insert */
951: if (el == bagEl)
952: {
953: el = TtaGetFirstChild (el);
954: TtaSelectElement (doc, el);
955: TtaInsertAnyElement (doc, TRUE);
956: }
957: else
958: {
959: TtaSelectElement (doc, el);
960: TtaInsertAnyElement (doc, FALSE);
961: }
962: newEl = Template_InsertBagChild (doc, bagEl, decl, FALSE);
963:
964: /* Finish insertion.*/
965: TtaCloseUndoSequence (doc);
966: TtaSetDocumentModified (doc);
967: TtaSetStructureChecking (oldStructureChecking, doc);
968: // restore the display
969: TtaSetDisplayMode (doc, dispMode);
970: firstEl = GetFirstEditableElement (newEl);
971: if (firstEl)
972: {
973: TtaSelectElement (doc, firstEl);
974: TtaSetStatusSelectedElement (doc, view, firstEl);
975: }
976: else
977: {
978: TtaSelectElement (doc, newEl);
979: TtaSetStatusSelectedElement (doc, view, newEl);
980: }
981: }
982: }
983: }
984: TtaFreeMemory (result);
985: }
1.138 vatton 986: #endif /* TEMPLATES */
987: return TRUE; /* don't let Thot perform normal operation */
988: }
989:
990: /*----------------------------------------------------------------------
1.209 vatton 991: DoReplicateUseElement insert a new element after the el child of
992: repeatEl or as the first child of repeatEl.
993: ----------------------------------------------------------------------*/
994: void DoReplicateUseElement (XTigerTemplate t, Document doc, int view,
995: Element el, Element repeatEl, char *name)
996: {
997: Declaration decl;
998: Element newEl, firstEl, prevRepeat;
999: ThotBool oldStructureChecking;
1000: DisplayMode dispMode;
1001:
1002: if (repeatEl == Creating_repeat)
1003: return;
1004: prevRepeat = Creating_repeat;
1005: Creating_repeat = repeatEl;
1006:
1007: decl = Template_GetDeclaration (t, name);
1008: if (decl)
1009: {
1010: dispMode = TtaGetDisplayMode (doc);
1011: if (dispMode == DisplayImmediately)
1012: /* don't set NoComputedDisplay
1013: -> it breaks down views formatting when Enter generates new elements */
1014: TtaSetDisplayMode (doc, DeferredDisplay);
1015: /* Prepare insertion.*/
1016: oldStructureChecking = TtaGetStructureChecking (doc);
1017: TtaSetStructureChecking (FALSE, doc);
1018: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
1019: /* Insert. */
1020: if (el == repeatEl)
1021: newEl = Template_InsertRepeatChildAfter (doc, repeatEl, decl, NULL);
1022: else
1023: newEl = Template_InsertRepeatChildAfter (doc, repeatEl, decl, el);
1024:
1025: /* Finish insertion.*/
1026: TtaCloseUndoSequence(doc);
1027: TtaSetDocumentModified (doc);
1028: TtaSetStructureChecking (oldStructureChecking, doc);
1029:
1030: // restore the display
1031: TtaSetDisplayMode (doc, dispMode);
1032: firstEl = GetFirstEditableElement (newEl);
1033: if (firstEl)
1034: {
1035: TtaSelectElement (doc, firstEl);
1036: TtaSetStatusSelectedElement (doc, view, firstEl);
1037: }
1038: else
1039: {
1040: TtaSelectElement (doc, newEl);
1041: TtaSetStatusSelectedElement (doc, view, newEl);
1042: }
1043: }
1044: Creating_repeat = prevRepeat;
1045: }
1046:
1047: /*----------------------------------------------------------------------
1.79 quint 1048: RepeatButtonClicked
1.89 kia 1049: Called when a repeat button is clicked.
1050: Can be called for useEl, useSimple or repeat.
1051: If called for useEl or useSimple, the new element must be added after.
1052: If called for repeat, the element must be added before all.
1.206 kia 1053:
1.56 francesc 1054: Shows a menu with all the types that can be used in a use element.
1055: ----------------------------------------------------------------------*/
1.79 quint 1056: ThotBool RepeatButtonClicked (NotifyElement *event)
1.56 francesc 1057: {
1058: #ifdef TEMPLATES
1.89 kia 1059: Document doc = event->document;
1060: Element el = event->element;
1061: ElementType elType;
1.90 kia 1062: XTigerTemplate t;
1063: Element repeatEl = el;
1064: Element firstEl;
1.95 kia 1065: View view;
1.162 vatton 1066: char *listtypes = NULL;
1067: char *result = NULL;
1.104 kia 1068:
1.112 vatton 1069: if (!TtaGetDocumentAccessMode(doc))
1.110 kia 1070: return TRUE;
1.182 vatton 1071: if (!IsTemplateInstanceDocument (doc))
1072: return FALSE; /* let Thot perform normal operation */
1.148 kia 1073:
1.95 kia 1074: TtaGetActiveView (&doc, &view);
1075: if (view != 1)
1076: return FALSE; /* let Thot perform normal operation */
1077:
1.89 kia 1078: TtaCancelSelection(doc);
1.171 kia 1079: t = GetXTigerDocTemplate(doc);
1.89 kia 1080: elType = TtaGetElementType(el);
1.138 vatton 1081: while (elType.ElTypeNum != Template_EL_repeat)
1.179 kia 1082: {
1083: repeatEl = TtaGetParent(repeatEl);
1084: if (repeatEl == NULL)
1085: break;
1086: elType = TtaGetElementType(repeatEl);
1087: }
1.112 vatton 1088: if (repeatEl)
1.90 kia 1089: {
1.179 kia 1090: if (Template_CanInsertRepeatChild (repeatEl))
1091: {
1092: firstEl = TtaGetFirstChild (repeatEl);
1093: listtypes = Template_GetListTypes (t, firstEl);
1094: if (listtypes)
1095: {
1.158 kia 1096: #ifdef AMAYA_DEBUG
1.179 kia 1097: printf("RepeatButtonClicked : \n > %s\n", listtypes);
1.158 kia 1098: #endif /* AMAYA_DEBUG */
1.179 kia 1099:
1100: result = QueryStringFromMenu (doc, listtypes);
1101: TtaFreeMemory (listtypes);
1102: if (result)
1.209 vatton 1103: DoReplicateUseElement (t, doc, view, el, repeatEl, result);
1.104 kia 1104: }
1.179 kia 1105: TtaFreeMemory(result);
1106: DumpSubtree(repeatEl, doc, 0);
1107:
1108: }
1109: else /* if (Template_CanInsertRepeatChild(repeatEl)) */
1110: {
1111: TtaSetStatus(doc, view, TtaGetMessage (AMAYA, AM_NUMBER_OCCUR_HAVE_MAX), NULL);
1.98 kia 1112: }
1113: }
1.77 vatton 1114: return TRUE; /* don't let Thot perform normal operation */
1.57 francesc 1115: #endif /* TEMPLATES */
1.94 kia 1116: return TRUE;
1117: }
1118:
1119: /*----------------------------------------------------------------------
1120: UseButtonClicked
1121: Shows a menu with all the types that can be used in a use element.
1122: ----------------------------------------------------------------------*/
1123: ThotBool UseButtonClicked (NotifyElement *event)
1124: {
1125: #ifdef TEMPLATES
1126: Document doc = event->document;
1127: Element el = event->element;
1.99 kia 1128: Element child;
1.214 ! vatton 1129: ElementType elType, childType;
1.94 kia 1130: XTigerTemplate t;
1131: Declaration decl;
1132: Element firstEl;
1133: Element newEl = NULL;
1134: char* types;
1135: ThotBool oldStructureChecking;
1.95 kia 1136: View view;
1.133 vatton 1137: char* listtypes = NULL;
1138: char* result = NULL;
1.95 kia 1139:
1.182 vatton 1140: if (!TtaGetDocumentAccessMode (doc))
1.110 kia 1141: return TRUE;
1.182 vatton 1142: if (!IsTemplateInstanceDocument (doc))
1143: return FALSE; /* let Thot perform normal operation */
1.206 kia 1144:
1.95 kia 1145: TtaGetActiveView (&doc, &view);
1146: if (view != 1)
1147: return FALSE; /* let Thot perform normal operation */
1.148 kia 1148:
1.94 kia 1149: TtaCancelSelection(doc);
1.171 kia 1150: t = GetXTigerDocTemplate(doc);
1.94 kia 1151: if (!t)
1152: return FALSE; /* let Thot perform normal operation */
1153:
1.214 ! vatton 1154: elType = TtaGetElementType (el);
! 1155: firstEl = TtaGetFirstChild (el);
! 1156: childType = TtaGetElementType (firstEl);
! 1157: if (firstEl &&
! 1158: // TemplateObject is just a place holder
! 1159: (childType.ElSSchema != elType.ElSSchema ||
! 1160: childType.ElTypeNum != Template_EL_TemplateObject))
! 1161: RepeatButtonClicked(event);
1.94 kia 1162: else
1163: {
1.209 vatton 1164: types = GetAttributeStringValueFromNum(el, Template_ATTR_types, NULL);
1165: if (types)
1166: {
1167: listtypes = Template_ExpandTypes(t, types, NULL, FALSE);
1.158 kia 1168: #ifdef AMAYA_DEBUG
1.209 vatton 1169: printf("UseButtonClicked : \n > %s\n", listtypes);
1.158 kia 1170: #endif /* AMAYA_DEBUG */
1.206 kia 1171:
1.209 vatton 1172: result = QueryStringFromMenu(doc, listtypes);
1173: if (result)
1174: {
1175: decl = Template_GetDeclaration(t, result);
1176: if (decl)
1177: {
1178: /* Prepare insertion.*/
1179: oldStructureChecking = TtaGetStructureChecking (doc);
1180: TtaSetStructureChecking (FALSE, doc);
1181: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
1.206 kia 1182:
1.209 vatton 1183: /* Insert */
1184: newEl = Template_InsertUseChildren(doc, el, decl);
1185: for (child = TtaGetFirstChild(newEl); child; TtaNextSibling(&child))
1186: {
1.213 vatton 1187: TtaRegisterElementCreate (child, doc);
1.209 vatton 1188: }
1.206 kia 1189:
1.209 vatton 1190: TtaChangeTypeOfElement(el, doc, Template_EL_useSimple);
1.213 vatton 1191: TtaRegisterElementTypeChange (el, Template_EL_useEl, doc);
1.206 kia 1192:
1.209 vatton 1193: /* xt:currentType attribute.*/
1194: SetAttributeStringValueWithUndo(el, Template_ATTR_currentType, result);
1.206 kia 1195:
1.209 vatton 1196: /* Finish insertion. */
1197: TtaCloseUndoSequence(doc);
1198: TtaSetDocumentModified (doc);
1199: TtaSetStructureChecking (oldStructureChecking, doc);
1.206 kia 1200:
1.213 vatton 1201: firstEl = GetFirstEditableElement (newEl);
1.209 vatton 1202: if (firstEl)
1203: {
1204: TtaSelectElement (doc, firstEl);
1.213 vatton 1205: TtaSetStatusSelectedElement (doc, view, firstEl);
1.209 vatton 1206: }
1207: else
1208: {
1209: TtaSelectElement (doc, newEl);
1210: TtaSetStatusSelectedElement(doc, view, newEl);
1211: }
1212: }
1213: }
1214: }
1215: TtaFreeMemory(types);
1216: TtaFreeMemory(listtypes);
1217: TtaFreeMemory(result);
1218: }
1.148 kia 1219:
1.94 kia 1220: return TRUE;
1221: #endif /* TEMPLATES */
1.56 francesc 1222: return TRUE;
1223: }
1.64 francesc 1224:
1.89 kia 1225:
1.103 kia 1226: /*----------------------------------------------------------------------
1227: UseSimpleButtonClicked
1228: ----------------------------------------------------------------------*/
1229: ThotBool UseSimpleButtonClicked (NotifyElement *event)
1230: {
1231: #ifdef TEMPLATES
1.181 vatton 1232: ElementType elType, parentType;
1233: AttributeType attrType;
1234: Attribute att;
1235:
1.182 vatton 1236: if (!TtaGetDocumentAccessMode (event->document))
1.110 kia 1237: return TRUE;
1.182 vatton 1238: if (!IsTemplateInstanceDocument (event->document))
1239: return FALSE; /* let Thot perform normal operation */
1.110 kia 1240:
1.181 vatton 1241: elType = TtaGetElementType (event->element);
1242: attrType.AttrSSchema = elType.ElSSchema;
1243: attrType.AttrTypeNum = Template_ATTR_option;
1244: att = TtaGetAttribute (event->element, attrType);
1245: if (att)
1246: return OptionButtonClicked (event);
1.206 kia 1247:
1.181 vatton 1248: parentType = TtaGetElementType (TtaGetParent( event->element));
1.112 vatton 1249: if (parentType.ElTypeNum == Template_EL_repeat)
1.138 vatton 1250: return RepeatButtonClicked (event);
1251: else if (parentType.ElTypeNum == Template_EL_bag)
1252: return BagButtonClicked (event);
1.206 kia 1253: #endif /* TEMPLATES */
1.103 kia 1254: return FALSE;
1255: }
1.94 kia 1256:
1257: /*----------------------------------------------------------------------
1258: OptionButtonClicked
1259: ----------------------------------------------------------------------*/
1260: ThotBool OptionButtonClicked (NotifyElement *event)
1261: {
1262: #ifdef TEMPLATES
1.145 kia 1263: Element useEl, contentEl, next;
1.182 vatton 1264: ElementType useType;
1.94 kia 1265: Document doc;
1266: XTigerTemplate t;
1267: View view;
1268:
1.182 vatton 1269: if (!TtaGetDocumentAccessMode (event->document))
1.110 kia 1270: return TRUE;
1.182 vatton 1271: if (!IsTemplateInstanceDocument (event->document))
1272: return FALSE; /* let Thot perform normal operation */
1.110 kia 1273:
1.94 kia 1274: TtaGetActiveView (&doc, &view);
1275: if (view != 1)
1276: return FALSE; /* let Thot perform normal operation */
1.110 kia 1277:
1.94 kia 1278: doc = event->document;
1.182 vatton 1279: useEl = event->element;
1.145 kia 1280: if (!useEl)
1.94 kia 1281: return FALSE; /* let Thot perform normal operation */
1.145 kia 1282: useType = TtaGetElementType (useEl);
1.182 vatton 1283: if (useType.ElTypeNum != Template_EL_useEl &&
1284: useType.ElTypeNum != Template_EL_useSimple)
1.94 kia 1285: return FALSE;
1286:
1.145 kia 1287: TtaOpenUndoSequence(doc, NULL, NULL, 0, 0);
1.94 kia 1288: TtaCancelSelection (doc);
1.145 kia 1289: contentEl = TtaGetFirstChild (useEl);
1290: if (!contentEl)
1.94 kia 1291: /* the "use" element is empty. Instantiate it */
1292: {
1.171 kia 1293: t = GetXTigerDocTemplate (doc);
1.94 kia 1294: if (!t)
1295: return FALSE; // no template ?!?!
1.145 kia 1296: InstantiateUse (t, useEl, doc, TRUE);
1.94 kia 1297: }
1298: else
1299: /* remove the content of the "use" element */
1300: {
1301: do
1302: {
1.145 kia 1303: next = contentEl;
1.94 kia 1304: TtaNextSibling (&next);
1.145 kia 1305: TtaRegisterElementDelete(contentEl, doc);
1306: TtaDeleteTree (contentEl, doc);
1307: contentEl = next;
1.94 kia 1308: }
1309: while (next);
1.145 kia 1310: if (NeedAMenu (useEl, doc))
1311: {
1312: TtaChangeTypeOfElement (useEl, doc, Template_EL_useEl);
1313: TtaRegisterElementTypeChange(useEl, Template_EL_useSimple, doc);
1314: }
1.94 kia 1315: }
1316: TtaSelectElement (doc, event->element);
1.145 kia 1317: TtaCloseUndoSequence(doc);
1.94 kia 1318: return TRUE; /* don't let Thot perform normal operation */
1319: #endif /* TEMPLATES */
1320: return TRUE;
1321: }
1322:
1.191 kia 1323:
1324:
1.111 vatton 1325: /*----------------------------------------------------------------------
1.191 kia 1326: Template_FillFromDocument
1327: Fill XTigerTemplate structure with the content of the document.
1328: Load dependencies if needed.
1.111 vatton 1329: ----------------------------------------------------------------------*/
1.191 kia 1330: void Template_FillFromDocument (Document doc)
1.111 vatton 1331: {
1332: #ifdef TEMPLATES
1.191 kia 1333: XTigerTemplate t = GetXTigerTemplate (DocumentURLs[doc]);
1334: Element root;
1.206 kia 1335:
1.193 vatton 1336: if (t)
1.111 vatton 1337: {
1.193 vatton 1338: #ifdef AMAYA_DEBUG
1.212 vatton 1339: printf("Template_FillFromDocument state: %d\n", t->state);
1.193 vatton 1340: #endif
1.191 kia 1341: SetTemplateDocument (t, doc);
1.210 vatton 1342: Template_PrepareTemplate(t, doc);
1.209 vatton 1343: if (IsTemplateInstanceDocument(doc))
1.144 vatton 1344: {
1.193 vatton 1345: #ifdef AMAYA_DEBUG
1.191 kia 1346: printf(" > instance\n");
1.193 vatton 1347: #endif
1.144 vatton 1348: // fix all access rights in the instance
1.191 kia 1349: root = TtaGetRootElement (doc);
1350: TtaSetAccessRight (root, ReadOnly, doc);
1.166 kia 1351: Template_FixAccessRight (t, root, doc);
1.144 vatton 1352: TtaUpdateAccessRightInViews (doc, root);
1353: }
1.193 vatton 1354: #ifdef AMAYA_DEBUG
1.209 vatton 1355: else if (t->state&templLibraryFlag)
1.191 kia 1356: printf(" > library\n");
1.209 vatton 1357: else if (t->state&templTemplate)
1.191 kia 1358: printf(" > template\n");
1.206 kia 1359: #endif
1.191 kia 1360: // Mark loaded
1361: t->state |= templloaded;
1362: TtaSetDocumentUnmodified (doc);
1363: UpdateTemplateMenus (doc);
1.206 kia 1364:
1365: #ifdef AMAYA_DEBUG
1.191 kia 1366: DumpAllDeclarations();
1367: #endif /* AMAYA_DEBUG */
1368: }
1369: #endif /* TEMPLATES */
1370: }
1371:
1372:
1373: /*----------------------------------------------------------------------
1374: Template_CheckAndPrepareTemplate checks if the document is a template
1375: or a library and prepare XTigerTemplate structure to use it.
1376: ----------------------------------------------------------------------*/
1377: ThotBool Template_CheckAndPrepareTemplate(char* docURL)
1378: {
1379: #ifdef TEMPLATES
1380: XTigerTemplate t = NULL; //GetXTigerTemplate(docURL);
1.193 vatton 1381:
1.212 vatton 1382: if (IsXTiger(docURL))
1383: {
1.193 vatton 1384: #ifdef AMAYA_DEBUG
1.212 vatton 1385: printf("Template_CheckAndPrepareTemplate %s templTemplate\n", docURL);
1.193 vatton 1386: #endif
1.191 kia 1387: t = LookForXTigerTemplate(docURL);
1388: t->state |= templTemplate;
1.111 vatton 1389: }
1.193 vatton 1390: else if (IsXTigerLibrary(docURL))
1.191 kia 1391: {
1.212 vatton 1392: #ifdef AMAYA_DEBUG
1393: printf("Template_CheckAndPrepareTemplate %s templLibrary\n", docURL);
1394: #endif
1.191 kia 1395: t = LookForXTigerLibrary(docURL);
1396: t->state |= templLibrary;
1397: }
1.193 vatton 1398: return t != NULL;
1.111 vatton 1399: #endif /* TEMPLATES */
1.191 kia 1400: return FALSE;
1.111 vatton 1401: }
1.94 kia 1402:
1.191 kia 1403:
1.66 vatton 1404: /*----------------------------------------------------------------------
1.213 vatton 1405: Template_CheckAndPrepareInstance checks if it is a template instance.
1.108 vatton 1406: If it's an instance and the template is not loaded, load it into a
1407: temporary file
1.66 vatton 1408: ----------------------------------------------------------------------*/
1.213 vatton 1409: void Template_CheckAndPrepareInstance (char *localFileName, Document doc,
1410: char* docURL)
1.65 francesc 1411: {
1412: #ifdef TEMPLATES
1.76 vatton 1413: XTigerTemplate t;
1.103 kia 1414: char *content, *ptr, *begin;
1.76 vatton 1415: gzFile stream;
1416: char buffer[2000];
1.77 vatton 1417: int res;
1.213 vatton 1418: char *template_version = NULL, *template_url = NULL;
1.65 francesc 1419:
1.171 kia 1420: stream = TtaGZOpen (localFileName);
1.76 vatton 1421: if (stream != 0)
1.65 francesc 1422: {
1.76 vatton 1423: res = gzread (stream, buffer, 1999);
1424: if (res >= 0)
1.65 francesc 1425: {
1.81 vatton 1426: buffer[res] = EOS;
1.103 kia 1427: begin = strstr (buffer, "<?xtiger");
1.206 kia 1428:
1.112 vatton 1429: if (begin)
1.209 vatton 1430: {
1431: // Search for template version
1432: ptr = strstr (begin, "templateVersion");
1433: if (ptr)
1434: ptr = strstr (ptr, "=");
1435: if (ptr)
1436: ptr = strstr (ptr, "\"");
1437: if (ptr)
1438: {
1439: // template URI
1440: content = &ptr[1];
1441: ptr = strstr (content, "\"");
1442: }
1443: if (ptr)
1444: {
1445: *ptr = EOS;
1446: //Get now the template URI
1447: template_version = TtaStrdup (content);
1448: *ptr = '"';
1449: }
1450:
1451: // Search for template uri
1452: ptr = strstr (begin, "template");
1453: if (ptr && ptr[8] != 'V')
1454: ptr = strstr (ptr, "=");
1455: if (ptr)
1456: ptr = strstr (ptr, "\"");
1457: if (ptr)
1458: {
1459: // template URI
1460: content = &ptr[1];
1461: ptr = strstr (content, "\"");
1462: }
1463: if (ptr)
1464: {
1465: *ptr = EOS;
1466: //Get now the template URI
1467: template_url = TtaStrdup (content);
1468:
1469: t = GetXTigerTemplate (template_url);
1470: if (!t)
1471: {
1472: LoadTemplate (doc, template_url);
1473: t = GetXTigerTemplate(template_url);
1474: }
1475: Template_PrepareInstance(docURL, doc, template_version, template_url);
1476: Template_AddReference (t);
1477: *ptr = '"';
1478: }
1479: }
1.65 francesc 1480: }
1481: }
1.171 kia 1482: TtaFreeMemory(template_version);
1483: TtaFreeMemory(template_url);
1.76 vatton 1484: TtaGZClose (stream);
1.65 francesc 1485: #endif /* TEMPLATES */
1486: }
1487:
1.64 francesc 1488: /*----------------------------------------------------------------------
1.178 kia 1489: ClosingTemplateDocument
1490: Callback called before closing a document which uses templates.
1.64 francesc 1491: ----------------------------------------------------------------------*/
1.178 kia 1492: ThotBool ClosingTemplateDocument(NotifyDialog* dialog)
1.64 francesc 1493: {
1.65 francesc 1494: #ifdef TEMPLATES
1.171 kia 1495: XTigerTemplate t = GetXTigerDocTemplate(dialog->document);
1.209 vatton 1496: if (t)
1497: Template_RemoveReference(t);
1.65 francesc 1498: #endif /* TEMPLATES */
1499: return FALSE;
1.64 francesc 1500: }
1.87 kia 1501:
1502: /*----------------------------------------------------------------------
1.120 kia 1503: IsTemplateElement
1.138 vatton 1504: Test if an element is a template element.
1.87 kia 1505: ----------------------------------------------------------------------*/
1.140 vatton 1506: ThotBool IsTemplateElement (Element elem)
1.87 kia 1507: {
1508: #ifdef TEMPLATES
1.138 vatton 1509: ElementType elType;
1510:
1511: elType = TtaGetElementType(elem);
1512: if (elType.ElSSchema)
1.164 kia 1513: return (strcmp(TtaGetSSchemaName(elType.ElSSchema) , "Template") == 0);
1.138 vatton 1514: #endif /* TEMPLATES */
1.87 kia 1515: return FALSE;
1516: }
1517:
1518:
1519: /*----------------------------------------------------------------------
1520: GetFirstTemplateParentElement
1.138 vatton 1521: Return the first element which has "Template" as schema name or null.
1.87 kia 1522: ----------------------------------------------------------------------*/
1523: Element GetFirstTemplateParentElement(Element elem)
1524: {
1525: #ifdef TEMPLATES
1.138 vatton 1526: ElementType elType;
1527:
1528: elem = TtaGetParent (elem);
1529: elType = TtaGetElementType(elem);
1530: while (elem && strcmp(TtaGetSSchemaName(elType.ElSSchema), "Template"))
1.209 vatton 1531: {
1532: elem = TtaGetParent (elem);
1533: elType = TtaGetElementType(elem);
1534: }
1.87 kia 1535: return elem;
1536: #else
1537: return NULL;
1538: #endif /* TEMPLATES */
1539: }
1.101 kia 1540:
1.103 kia 1541:
1.101 kia 1542: /*----------------------------------------------------------------------
1.209 vatton 1543: IsBeginningSelected
1544: Returns TRUE if the selection is athe beginning of an element
1545: ----------------------------------------------------------------------*/
1546: ThotBool IsBeginningSelected (Element el, Document doc)
1547: {
1548: Element selElem, prev;
1549: int firstChar, lastChar;
1550:
1551: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
1552: if (firstChar <= 1 && lastChar < firstChar)
1553: {
1554: while (selElem && selElem != el)
1555: {
1556: prev = selElem;
1557: TtaPreviousSibling (&prev);
1558: if (prev)
1559: return FALSE;
1560: selElem = TtaGetParent (selElem);
1561: }
1562: return TRUE;
1563: }
1564: return FALSE;
1565: }
1566:
1567: /*----------------------------------------------------------------------
1.102 vatton 1568: TemplateElementWillBeCreated
1.101 kia 1569: Processed when an element will be created in a template context.
1570: ----------------------------------------------------------------------*/
1.102 vatton 1571: ThotBool TemplateElementWillBeCreated (NotifyElement *event)
1.101 kia 1572: {
1.103 kia 1573: #ifdef TEMPLATES
1.209 vatton 1574: ElementType elType = event->elementType;
1575: Element parent = event->element;
1576: ElementType parentType = TtaGetElementType(parent);
1577: Element ancestor, el, next;
1578: ElementType ancestorType;
1579: SSchema templateSSchema;
1580: XTigerTemplate t;
1581: char *types, *ptr, *name = NULL;
1582: int len, view, i, doc = event->document;
1583: ThotBool b;
1.101 kia 1584:
1.209 vatton 1585: if (event->info == 1)
1.115 kia 1586: return FALSE;
1587:
1.193 vatton 1588: #ifdef AMAYA_DEBUG
1.185 kia 1589: printf("TemplateElementWillBeCreated\n");
1.193 vatton 1590: #endif
1.209 vatton 1591: if (!TtaGetDocumentAccessMode(doc))
1.110 kia 1592: return TRUE;
1593:
1.209 vatton 1594: templateSSchema = TtaGetSSchema ("Template", doc);
1.102 vatton 1595: if (templateSSchema == NULL)
1596: return FALSE; // let Thot do the job
1.115 kia 1597:
1.113 kia 1598: // Fisrt, test if in a xt:bag or in a base-element xt:use
1.209 vatton 1599: if (parentType.ElSSchema == templateSSchema)
1.113 kia 1600: ancestor = parent;
1601: else
1.147 vatton 1602: ancestor = GetFirstTemplateParentElement (parent);
1.113 kia 1603:
1.147 vatton 1604: if (ancestor)
1.209 vatton 1605: {
1606: ancestorType = TtaGetElementType(ancestor);
1607: if (ancestorType.ElTypeNum == Template_EL_bag)
1608: {
1609: // only check the use child
1610: if (ancestor != parent)
1611: return FALSE; // let Thot do the job
1612: if (elType.ElSSchema == templateSSchema &&
1613: (elType.ElTypeNum == Template_EL_useSimple ||
1614: elType.ElTypeNum == Template_EL_useEl))
1615: return FALSE;
1616: return !Template_CanInsertElementInBagElement (doc, elType, ancestor);
1617: }
1618: else if (ancestorType.ElTypeNum == Template_EL_repeat)
1619: {
1620: if (elType.ElSSchema != templateSSchema ||
1621: (elType.ElTypeNum != Template_EL_useSimple &&
1622: elType.ElTypeNum != Template_EL_useEl))
1623: return TRUE; // don't let Thot do the job
1.210 vatton 1624: t = GetXTigerDocTemplate (doc);
1.209 vatton 1625: el = NULL;
1626: i = 0;
1627: next = TtaGetFirstChild (ancestor);
1628: while (next && i < event->position)
1629: {
1630: el = next;
1631: TtaNextSibling (&next);
1632: i++;
1633: }
1634: if (el)
1635: next = el;
1.210 vatton 1636: name = GetUsedTypeName (next);
1.209 vatton 1637: DoReplicateUseElement (t, doc, view, el, ancestor, name);
1638: TtaFreeMemory(name);
1639: return TRUE; // don't let Thot do the job
1640: }
1641: else if (ancestorType.ElTypeNum == Template_EL_useSimple ||
1642: ancestorType.ElTypeNum == Template_EL_useEl)
1643: {
1644: // only check the bag child @@@ will be check exclude/include later
1645: if (elType.ElSSchema == templateSSchema &&
1646: (elType.ElTypeNum == Template_EL_useSimple ||
1647: elType.ElTypeNum == Template_EL_useEl))
1648: return TRUE; // don't let Thot do the job
1649: if (ancestor != parent)
1650: return TtaIsReadOnly (parent); // let or not Thot do the job
1651: types = GetAttributeStringValueFromNum (ancestor, Template_ATTR_currentType, NULL);
1652: b = Template_CanInsertElementInUse (doc, elType, types,
1653: parent, event->position);
1654: if (types && !b)
1655: {
1656: // check with equivalent component
1657: name = (char *)GetXMLElementName (elType, doc);
1658: if (name)
1659: {
1660: len = strlen (name);
1661: ptr = strstr (types, name);
1662: if (ptr && len &&
1663: (ptr == types || ptr[-1] == SPACE) &&
1664: (ptr[len] == EOS || ptr[len] == SPACE))
1665: {
1666: parent = TtaGetParent(ancestor);
1667: parentType = TtaGetElementType(parent);
1668: if (parentType.ElSSchema == templateSSchema &&
1669: parentType.ElTypeNum == Template_EL_repeat)
1670: {
1671: // duplicate the current use
1672: TtaGetActiveView (&doc, &view);
1673: t = GetXTigerDocTemplate(doc);
1674: if (IsBeginningSelected (ancestor, doc))
1675: TtaPreviousSibling (&ancestor);
1676: DoReplicateUseElement (t, doc, view, ancestor, parent, name);
1677: }
1678: }
1679: }
1680: }
1681: TtaFreeMemory(types);
1682: return !b;
1683: }
1684: else if (ancestorType.ElTypeNum == Template_EL_component)
1685: // allow all changes
1.116 kia 1686: return FALSE;
1.113 kia 1687: }
1.206 kia 1688:
1.210 vatton 1689: if (!IsTemplateInstanceDocument(doc) &&
1690: elType.ElSSchema == templateSSchema &&
1.209 vatton 1691: (elType.ElTypeNum == Template_EL_TEXT_UNIT ||
1692: elType.ElTypeNum == Template_EL_component))
1693: return FALSE;
1694: // Cannot insert.
1.113 kia 1695: return TRUE;
1.101 kia 1696: #endif /* TEMPLATES*/
1.102 vatton 1697: return FALSE;
1.101 kia 1698: }
1699:
1700: /*----------------------------------------------------------------------
1701: TemplateElementWillBeDeleted
1702: Processed when an element will be deleted in a template context.
1703: ----------------------------------------------------------------------*/
1704: ThotBool TemplateElementWillBeDeleted (NotifyElement *event)
1705: {
1.107 kia 1706: #ifdef TEMPLATES
1707: Document doc = event->document;
1708: Element elem = event->element;
1.163 vatton 1709: Element xtElem, parent = NULL, sibling;
1.117 kia 1710: ElementType xtType, elType;
1.107 kia 1711: char* type;
1712: Declaration dec;
1.115 kia 1713: SSchema templateSSchema;
1.107 kia 1714: XTigerTemplate t;
1.156 vatton 1715: ThotBool selparent = FALSE;
1.206 kia 1716:
1.209 vatton 1717: if (event->info==1)
1.115 kia 1718: return FALSE;
1719:
1.112 vatton 1720: if (!TtaGetDocumentAccessMode(event->document))
1.110 kia 1721: return TRUE;
1722:
1.138 vatton 1723: templateSSchema = TtaGetSSchema ("Template", event->document);
1.107 kia 1724: if (templateSSchema == NULL)
1725: return FALSE; // let Thot do the job
1.206 kia 1726:
1.192 kia 1727: t = GetXTigerDocTemplate(doc);
1.209 vatton 1728: if (Template_IsTemplate(t)||Template_IsLibrary(t))
1.192 kia 1729: return FALSE; // If template or library, pass to specialized functions.
1.122 kia 1730:
1.107 kia 1731: xtElem = GetFirstTemplateParentElement(elem);
1.112 vatton 1732: if (xtElem)
1.209 vatton 1733: {
1734: xtType = TtaGetElementType(xtElem);
1735:
1.206 kia 1736:
1737:
1.209 vatton 1738: if (xtType.ElTypeNum==Template_EL_bag)
1739: {
1740: elType = TtaGetElementType(elem);
1741: if (elType.ElSSchema==templateSSchema &&
1742: (elType.ElTypeNum==Template_EL_useSimple || elType.ElTypeNum==Template_EL_useEl))
1743: {
1744: // Remove element manually.
1745: TtaOpenUndoSequence(doc, elem, elem, 0, 0);
1746: TtaRegisterElementDelete(elem, doc);
1747: TtaDeleteTree(elem, doc);
1748: TtaCloseUndoSequence(doc);
1749: return TRUE;
1750: }
1751: else
1752: return FALSE; // xt:bag always allow remove children.
1753: }
1754: else if (xtType.ElTypeNum == Template_EL_useSimple ||
1755: xtType.ElTypeNum == Template_EL_useEl)
1756: {
1757: parent = TtaGetParent(elem);
1758: if (xtElem != parent)
1759: {
1760: type = GetAttributeStringValueFromNum (xtElem, Template_ATTR_currentType, NULL);
1761: dec = Template_GetDeclaration(t, type);
1762: TtaFreeMemory (type);
1.109 kia 1763:
1.209 vatton 1764: if (dec && dec->nature == XmlElementNat)
1765: return FALSE; // Can remove element only if in xt:use current type is base language element.
1766: else
1767: return TRUE;
1768: }
1769: }
1770: else if (xtType.ElTypeNum == Template_EL_repeat)
1.156 vatton 1771: {
1.209 vatton 1772: sibling = TtaGetSuccessor (elem);
1.156 vatton 1773: if (sibling == NULL)
1.209 vatton 1774: {
1775: // there is no next element
1776: sibling = TtaGetPredecessor (elem);
1777: if (sibling == NULL)
1778: selparent = TRUE;
1779: }
1780: TtaRegisterElementDelete(elem, doc);
1781: TtaDeleteTree(elem, doc);
1782: InstantiateRepeat(t, xtElem, doc, TRUE);
1783: if (selparent)
1784: // look for the new sibling
1785: sibling = TtaGetFirstChild (parent);
1786: if (sibling)
1787: TtaSelectElement(doc, sibling);
1788: else
1789: TtaSelectElement(doc, parent);
1790: return TRUE;
1.156 vatton 1791: }
1.107 kia 1792: }
1.206 kia 1793:
1.109 kia 1794: //TODO Test if current element is use or repeat.
1795: // Because if an element is delete and it is the unique child of its parent,
1.206 kia 1796: // the parent intends to destroy itself.
1797:
1.107 kia 1798: return TRUE;
1799: #else /* TEMPLATES */
1.101 kia 1800: return FALSE;
1.107 kia 1801: #endif /* TEMPLATES */
1.101 kia 1802: }
1803:
1.109 kia 1804: /*----------------------------------------------------------------------
1805: CurrentTypeWillBeExported
1806: Check if the xt:currentType attribute can be exported
1807: ----------------------------------------------------------------------*/
1808: ThotBool CurrentTypeWillBeExported (NotifyAttribute *event)
1809: {
1810: #ifdef TEMPLATES
1.110 kia 1811:
1.112 vatton 1812: if (!TtaGetDocumentAccessMode(event->document))
1.110 kia 1813: return TRUE;
1814:
1.112 vatton 1815: if (IsTemplateDocument(event->document))
1.109 kia 1816: return TRUE;
1817: #endif /* TEMPLATES */
1818: return FALSE;
1819: }
1.127 kia 1820:
1821: /*----------------------------------------------------------------------
1822: TemplateAttrInMenu
1823: Called by Thot when building the Attributes menu for template elements.
1824: ----------------------------------------------------------------------*/
1825: ThotBool TemplateAttrInMenu (NotifyAttribute * event)
1826: {
1827: #ifdef TEMPLATES
1828: // Prevent from showing attributes for template instance but not templates.
1.209 vatton 1829: if (IsTemplateInstanceDocument(event->document))
1.127 kia 1830: return TRUE;
1831: else
1832: #endif /* TEMPLATES */
1833: return FALSE;
1834: }
1.160 kia 1835:
1.167 kia 1836: /*----------------------------------------------------------------------
1.168 kia 1837: CreateTemplateFromDocument
1838: Create a template from the current document.
1.167 kia 1839: ----------------------------------------------------------------------*/
1840: void CreateTemplateFromDocument(Document doc, View view)
1841: {
1.171 kia 1842: #ifdef TEMPLATES
1.205 vatton 1843: char buffer[MAX_LENGTH], suffix[10];
1.196 vatton 1844:
1.204 vatton 1845: if (IsW3Path (DocumentURLs[doc]) &&
1.205 vatton 1846: DocumentMeta[doc] && DocumentMeta[doc]->full_content_location)
1847: {
1.209 vatton 1848: // use the location instead of the current URI
1.206 kia 1849:
1.209 vatton 1850: strcpy (buffer, DocumentMeta[doc]->full_content_location);
1.205 vatton 1851: }
1.204 vatton 1852: else
1853: strcpy (buffer, DocumentURLs[doc]);
1854:
1855: // remove the current suffix
1856: TtaExtractSuffix (buffer, suffix);
1.196 vatton 1857: // the new suffix
1.168 kia 1858: strcat(buffer, ".xtd");
1859: DontReplaceOldDoc = TRUE;
1860: CreateTemplate(doc, buffer);
1.204 vatton 1861: // by default .xtd files are xml files
1862: TtaSetDocumentCharset (doc, UTF_8, FALSE);
1.171 kia 1863: #endif /* TEMPLATES */
1.167 kia 1864: }
1865:
1.169 kia 1866: /*----------------------------------------------------------------------
1867: UpdateTemplateMenus
1868: ----------------------------------------------------------------------*/
1869: void UpdateTemplateMenus (Document doc)
1870: {
1.196 vatton 1871: if (IsTemplateInstanceDocument(doc))
1.180 kia 1872: {
1873: // Instance document
1874: TtaSetItemOff (doc, 1, Tools, BCreateTemplateFromDocument);
1875: TtaSetItemOff (doc, 1, Tools, BTemplateCreateTextBox);
1.187 kia 1876: TtaSetItemOff (doc, 1, Tools, BTemplateCreateUseBox);
1.195 kia 1877: TtaSetItemOff (doc, 1, Tools, BTemplateCreateUseCompBox);
1878: TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeat);
1879: TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeatComp);
1.180 kia 1880: TtaSetItemOff (doc, 1, Tools, BTemplateCreateFreeBox);
1.196 vatton 1881: TtaSetItemOff (doc, 1, Tools, BTemplateCreateUnion);
1.180 kia 1882: }
1.213 vatton 1883: else if (DocumentURLs[doc] && DocumentTypes[doc] != docSource &&
1884: IsXTiger (DocumentURLs[doc]))
1.180 kia 1885: {
1886: // Template document
1887: TtaSetItemOff (doc, 1, Tools, BCreateTemplateFromDocument);
1888: TtaSetItemOn (doc, 1, Tools, BTemplateCreateTextBox);
1.187 kia 1889: TtaSetItemOn (doc, 1, Tools, BTemplateCreateUseBox);
1.195 kia 1890: TtaSetItemOn (doc, 1, Tools, BTemplateCreateUseCompBox);
1891: TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeat);
1892: TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeatComp);
1.206 kia 1893: TtaSetItemOn (doc, 1, Tools, BTemplateCreateFreeBox);
1.196 vatton 1894: TtaSetItemOn (doc, 1, Tools, BTemplateCreateUnion);
1.180 kia 1895: }
1.169 kia 1896: else
1.180 kia 1897: {
1898: //Standard document
1899: TtaSetItemOn (doc, 1, Tools, BCreateTemplateFromDocument);
1900: TtaSetItemOff (doc, 1, Tools, BTemplateCreateTextBox);
1.187 kia 1901: TtaSetItemOff (doc, 1, Tools, BTemplateCreateUseBox);
1.195 kia 1902: TtaSetItemOff (doc, 1, Tools, BTemplateCreateUseCompBox);
1903: TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeat);
1904: TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeatComp);
1.180 kia 1905: TtaSetItemOff (doc, 1, Tools, BTemplateCreateFreeBox);
1.196 vatton 1906: TtaSetItemOff (doc, 1, Tools, BTemplateCreateUnion);
1.180 kia 1907: }
1.169 kia 1908: }
1.171 kia 1909:
1910: /*----------------------------------------------------------------------
1911: UninstanciateTemplateDocument
1912: An instance of a template is tranformed into a template-less docuemnt.
1913: Remove link between XTigerTemplate structure and document.
1914: ----------------------------------------------------------------------*/
1915: void UninstanciateTemplateDocument(Document doc)
1916: {
1917: #ifdef TEMPLATES
1918: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.209 vatton 1919: if (t)
1.171 kia 1920: Template_Close(t);
1.206 kia 1921: #endif /* TEMPLATES */
1.171 kia 1922: }
1923:
1924:
1925: /*----------------------------------------------------------------------
1926: Template_PrepareInstance
1927: Allocate XTigerTemplate structure for instance and initialize template
1928: url and template version.
1929: ----------------------------------------------------------------------*/
1930: void Template_PrepareInstance(char *fileName, Document doc, char* template_version, char* template_url)
1931: {
1932: #ifdef TEMPLATES
1933: XTigerTemplate t = GetXTigerTemplate(fileName);
1.209 vatton 1934: if (!t)
1.171 kia 1935: t = NewXTigerTemplate(fileName);
1936: t->state = templInstance;
1.213 vatton 1937: t->templateVersion = TtaStrdup (template_version);
1938: t->base_uri = TtaStrdup (template_url);
1.171 kia 1939: t->doc = doc;
1.178 kia 1940: t->ref = 1;
1.206 kia 1941:
1.171 kia 1942: #endif /* TEMPLATES */
1943: }
1944:
1945:
1946: /*----------------------------------------------------------------------
1947: SetDocumentAsXTigerTemplate
1948: Set the document template structure as template.
1949: ----------------------------------------------------------------------*/
1950: void SetDocumentAsXTigerTemplate(Document doc)
1951: {
1952: #ifdef TEMPLATES
1953: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.209 vatton 1954: if (t)
1.171 kia 1955: t->state |= templTemplate;
1.206 kia 1956: #endif /* TEMPLATES */
1.171 kia 1957: }
1958:
1959: /*----------------------------------------------------------------------
1960: SetDocumentAsXTigerLibrary
1961: Set the document template structure as template library.
1962: ----------------------------------------------------------------------*/
1963: void SetDocumentAsXTigerLibrary(Document doc)
1964: {
1965: #ifdef TEMPLATES
1966: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.209 vatton 1967: if (t)
1.171 kia 1968: t->state |= templLibrary;
1.206 kia 1969: #endif /* TEMPLATES */
1.171 kia 1970: }
1.174 kia 1971:
1972:
1973: /*----------------------------------------------------------------------
1974: TemplateCreateTextBox
1975: Create a xt:use types="string" box around the selection.
1976: ----------------------------------------------------------------------*/
1977: void TemplateCreateTextBox(Document doc, View view)
1978: {
1979: #ifdef TEMPLATES
1980: Element selElem;
1981: ElementType selType;
1982: int firstChar, lastChar;
1983: SSchema sstempl = TtaGetSSchema ("Template", doc);
1984: ElementType useType;
1985: Element use;
1986: char buffer[128];
1.189 kia 1987: ThotBool oldStructureChecking;
1.206 kia 1988:
1.174 kia 1989: char *title = TtaGetMessage (AMAYA, AM_TEMPLATE_USESTRING);
1.184 vatton 1990: char *label = TtaGetMessage (AMAYA, AM_TEMPLATE_LABEL);
1.174 kia 1991:
1992: if (!TtaGetDocumentAccessMode(doc))
1993: return;
1.206 kia 1994:
1.209 vatton 1995: if (doc && TtaGetDocumentAccessMode(doc) && sstempl &&
1.174 kia 1996: IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
1997: {
1998: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
1.209 vatton 1999: if (selElem)
1.174 kia 2000: {
2001: selType = TtaGetElementType(selElem);
1.209 vatton 2002: if (!TtaIsLeaf(selType))
1.174 kia 2003: {
2004: selElem = TtaGetFirstLeaf(selElem);
2005: selType = TtaGetElementType(selElem);
2006: firstChar = lastChar = 0;
2007: }
1.207 vatton 2008: if (selType.ElTypeNum == 1)
1.174 kia 2009: {
1.207 vatton 2010: // request the element label
1.174 kia 2011: QueryStringFromUser(label, title, buffer, 127);
1.207 vatton 2012: if (buffer[0] == EOS)
2013: return;
2014:
1.174 kia 2015: useType.ElSSchema = sstempl;
2016: useType.ElTypeNum = Template_EL_useSimple;
1.189 kia 2017: oldStructureChecking = TtaGetStructureChecking (doc);
2018: TtaSetStructureChecking (FALSE, doc);
2019:
1.209 vatton 2020: if (firstChar==0)
1.174 kia 2021: {
2022: use = TtaNewElement(doc, useType);
1.209 vatton 2023: if (use)
1.174 kia 2024: {
2025: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
2026: TtaInsertSibling(use, selElem, FALSE, doc);
2027: TtaRegisterElementCreate(use, doc);
2028: TtaRegisterElementDelete (selElem, doc);
2029: TtaRemoveTree(selElem, doc);
2030: TtaInsertFirstChild(&selElem, use, doc);
2031: TtaRegisterElementDelete (selElem, doc);
2032: SetAttributeStringValue(use, Template_ATTR_types, "string");
2033: SetAttributeStringValue(use, Template_ATTR_title, buffer);
2034: TtaCloseUndoSequence(doc);
2035: TtaSelectElement(doc, use);
2036: }
2037: }
2038: else
2039: {
2040: GenerateInlineElement(Template_EL_useSimple, sstempl, 0, "", TRUE);
2041: TtaGiveFirstSelectedElement(doc, &use, &firstChar, &lastChar);
2042: selType = TtaGetElementType(use);
1.209 vatton 2043: if (selType.ElSSchema==sstempl && selType.ElTypeNum==Template_EL_useSimple)
1.174 kia 2044: {
2045: SetAttributeStringValue(use, Template_ATTR_types, "string");
1.206 kia 2046: SetAttributeStringValue(use, Template_ATTR_title, buffer);
1.174 kia 2047: }
2048: }
1.206 kia 2049:
1.189 kia 2050: TtaSetStructureChecking (oldStructureChecking, doc);
1.206 kia 2051:
1.174 kia 2052: }
1.206 kia 2053:
1.174 kia 2054: }
2055: }
2056: #endif /* TEMPLATES */
2057: }
2058:
2059:
2060: /*----------------------------------------------------------------------
2061: TemplateCreateFreeBox
2062: Create a xt:bag types="string" box around the selection.
2063: ----------------------------------------------------------------------*/
2064: void TemplateCreateFreeBox(Document doc, View view)
2065: {
2066: #ifdef TEMPLATES
1.185 kia 2067: Element selElem, selElem2, parent, parent2, current, child = NULL;
1.174 kia 2068: ElementType selType, selType2;
2069: int firstChar, lastChar, firstChar2, lastChar2;
2070: SSchema sstempl = TtaGetSSchema ("Template", doc);
2071:
2072: ElementType bagType;
2073: Element bag;
2074: char buffer[128];
2075:
2076: char *title = TtaGetMessage (AMAYA, AM_TEMPLATE_BAGANY);
1.184 vatton 2077: char *label = TtaGetMessage (AMAYA, AM_TEMPLATE_LABEL);
1.174 kia 2078:
2079: if (!TtaGetDocumentAccessMode(doc))
2080: return;
1.206 kia 2081:
1.209 vatton 2082: if (doc && TtaGetDocumentAccessMode(doc) && sstempl &&
1.174 kia 2083: IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
2084: {
2085: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
2086: TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);
1.207 vatton 2087: if (selElem && selElem2)
2088: {
2089: // request the element label
2090: QueryStringFromUser(label, title, buffer, 127);
2091: if (buffer[0] == EOS)
2092: return;
1.206 kia 2093:
1.174 kia 2094: selType = TtaGetElementType(selElem);
2095: selType2 = TtaGetElementType(selElem2);
2096: bagType.ElSSchema = sstempl;
2097: bagType.ElTypeNum = Template_EL_bag;
1.185 kia 2098: parent = TtaGetParent(selElem);
2099: parent2 = TtaGetParent(selElem2);
1.206 kia 2100:
1.209 vatton 2101: if (firstChar==0 && firstChar2==0 && parent == parent2)
1.174 kia 2102: {
1.185 kia 2103: ThotBool oldStructureChecking;
2104: DisplayMode dispMode;
2105: dispMode = TtaGetDisplayMode (doc);
2106: if (dispMode == DisplayImmediately)
2107: TtaSetDisplayMode (doc, DeferredDisplay);
2108: oldStructureChecking = TtaGetStructureChecking (doc);
2109: TtaSetStructureChecking (FALSE, doc);
2110:
2111: // Create and insert xt:bag element
2112: bag = TtaNewElement(doc, bagType);
2113: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
2114: TtaInsertSibling(bag, selElem, TRUE, doc);
2115: TtaRegisterElementCreate(bag, doc);
2116:
2117: TtaNextSibling(&selElem2);
1.209 vatton 2118: while (selElem!=selElem2)
1.174 kia 2119: {
1.185 kia 2120: current = selElem;
2121: TtaNextSibling(&selElem);
1.206 kia 2122:
1.185 kia 2123: TtaRegisterElementDelete (current, doc);
2124: TtaRemoveTree(current, doc);
1.209 vatton 2125: if (child)
1.185 kia 2126: TtaInsertSibling(current, child, FALSE, doc);
2127: else
2128: TtaInsertFirstChild(¤t, bag, doc);
2129: TtaRegisterElementDelete (current, doc);
2130: child = current;
1.174 kia 2131: }
1.206 kia 2132:
1.185 kia 2133: SetAttributeStringValue(bag, Template_ATTR_types, "any");
2134: SetAttributeStringValue(bag, Template_ATTR_title, buffer);
2135: TtaCloseUndoSequence(doc);
2136: TtaSelectElement(doc, bag);
1.206 kia 2137:
1.185 kia 2138: TtaSetStructureChecking (oldStructureChecking, doc);
2139: TtaSetDisplayMode (doc, dispMode);
1.174 kia 2140: }
2141: }
2142: }
2143: #endif /* TEMPLATES */
2144: }
2145:
1.180 kia 2146: /*----------------------------------------------------------------------
1.198 kia 2147: TemplateCreateUnion
2148: Create a xt:union around the selection.
2149: ----------------------------------------------------------------------*/
2150: void TemplateCreateUnion(Document doc, View view)
2151: {
2152: #ifdef TEMPLATES
1.199 kia 2153: SSchema sstempl = TtaGetSSchema ("Template", doc);
2154: Element head, sibling, unionEl;
2155: ElementType unionType;
2156: XTigerTemplate t = GetXTigerDocTemplate(doc);
2157: char *proposed, *name = NULL, *types=NULL;
1.200 kia 2158:
2159: Element selElem;
2160: ElementType selType;
2161: int firstChar, lastChar;
1.206 kia 2162:
2163:
1.209 vatton 2164: if (t && sstempl)
1.199 kia 2165: {
1.200 kia 2166: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
2167: selType = TtaGetElementType(selElem);
1.209 vatton 2168: if (selType.ElSSchema==sstempl && selType.ElTypeNum==Template_EL_union)
1.200 kia 2169: Template_ModifyUnionElement(doc, selElem);
2170: else
1.199 kia 2171: {
1.200 kia 2172: proposed = Template_GetAllDeclarations(t, TRUE, FALSE, TRUE);
1.209 vatton 2173: if (QueryUnionFromUser(proposed, NULL, &name, &types, TRUE))
1.200 kia 2174: {
2175: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
1.206 kia 2176:
1.200 kia 2177: head = TemplateFindHead(doc);
2178: sibling = TtaGetLastChild(head);
1.206 kia 2179:
1.200 kia 2180: unionType.ElSSchema = sstempl;
2181: unionType.ElTypeNum = Template_EL_union;
2182: unionEl = TtaNewElement(doc, unionType);
1.206 kia 2183:
1.209 vatton 2184: if (sibling)
1.200 kia 2185: TtaInsertSibling(unionEl, sibling, FALSE, doc);
2186: else
2187: {
2188: sibling = unionEl;
2189: TtaInsertFirstChild(&sibling, head, doc);
2190: }
2191: Template_SetName(doc, unionEl, name, TRUE);
1.206 kia 2192:
1.200 kia 2193: SetAttributeStringValue(unionEl, Template_ATTR_includeAt, types);
2194: TtaSetAccessRight(unionEl, ReadOnly, doc);
1.206 kia 2195:
1.200 kia 2196: TtaRegisterElementCreate(unionEl, doc);
1.206 kia 2197:
1.200 kia 2198: TtaSelectElement(doc, unionEl);
2199: TtaCloseUndoSequence(doc);
1.206 kia 2200:
1.200 kia 2201: Template_DeclareNewUnion (t, name, types, "");
2202: TtaFreeMemory(proposed);
2203: TtaFreeMemory(name);
2204: TtaFreeMemory(types);
1.206 kia 2205: }
1.200 kia 2206: }
1.206 kia 2207: }
1.199 kia 2208:
1.200 kia 2209: #endif /* TEMPLATES */
2210: }
1.199 kia 2211:
1.200 kia 2212: /*----------------------------------------------------------------------
2213: Template_ModifyUnionElement
2214: Query the user to modify an xt:union
2215: ----------------------------------------------------------------------*/
2216: void Template_ModifyUnionElement(Document doc, Element unionEl)
2217: {
2218: XTigerTemplate t = GetXTigerDocTemplate(doc);
2219: SSchema sstempl = TtaGetSSchema ("Template", doc);
2220: ElementType unionType;
2221: char *proposed, *checked, *name, *types=NULL;
1.206 kia 2222:
1.209 vatton 2223: if (doc && unionEl && t && sstempl)
1.200 kia 2224: {
2225: unionType = TtaGetElementType(unionEl);
1.209 vatton 2226: if (unionType.ElSSchema==sstempl && unionType.ElTypeNum==Template_EL_union)
1.200 kia 2227: {
2228: proposed = Template_GetAllDeclarations(t, TRUE, FALSE, TRUE);
2229: checked = GetAttributeStringValueFromNum(unionEl, Template_ATTR_includeAt, NULL);
2230: name = GetAttributeStringValueFromNum(unionEl, Template_ATTR_name, NULL);
1.209 vatton 2231: if (QueryUnionFromUser(proposed, checked, &name, &types, FALSE))
1.199 kia 2232: {
1.200 kia 2233: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
2234: SetAttributeStringValueWithUndo(unionEl, Template_ATTR_includeAt, types);
2235: TtaCloseUndoSequence(doc);
1.199 kia 2236: }
1.200 kia 2237: TtaFreeMemory(proposed);
2238: TtaFreeMemory(checked);
2239: TtaFreeMemory(name);
2240: TtaFreeMemory(types);
1.199 kia 2241: }
1.200 kia 2242: }
1.198 kia 2243: }
2244:
2245: /*----------------------------------------------------------------------
1.180 kia 2246: TemplateCreateRepeat
2247: Create a xt:repeat around the selection.
2248: ----------------------------------------------------------------------*/
2249: void TemplateCreateRepeat(Document doc, View view)
2250: {
1.198 kia 2251: Template_CreateRepeatFromSelection(doc, FALSE);
2252: }
2253:
2254: /*----------------------------------------------------------------------
2255: TemplateCreateRepeatComp
2256: Create a xt:component with the selection and use it in a new xt:repeat
2257: ----------------------------------------------------------------------*/
2258: void TemplateCreateRepeatComp(Document doc, View view)
2259: {
2260: Template_CreateRepeatFromSelection(doc, TRUE);
2261: }
2262:
2263: /*----------------------------------------------------------------------
2264: Template_CreateRepeatFromSelection
2265: Create a xt:repeat with the selection.
2266: If selection is empty, insert an inline xt:use.
1.206 kia 2267: If createComp is false, create a xt:use with types at the selected block.
1.198 kia 2268: If createComp is true, create a component with the selection.
2269: Return the xt:use element.
2270: ----------------------------------------------------------------------*/
2271: Element Template_CreateRepeatFromSelection(Document doc, ThotBool createComp)
2272: {
1.180 kia 2273: #ifdef TEMPLATES
1.187 kia 2274: ThotBool oldStructureChecking;
2275: DisplayMode dispMode;
2276: Element selElem, selElem2, parent, parent2;
2277: ElementType selType, selType2;
1.180 kia 2278: int firstChar, lastChar, firstChar2, lastChar2;
2279: SSchema sstempl = TtaGetSSchema ("Template", doc);
1.197 kia 2280: const char *title = TtaGetMessage (AMAYA, AM_TEMPLATE_REPEATCOMP);
2281: const char *label = TtaGetMessage (AMAYA, AM_TEMPLATE_REPEATLABEL);
2282: char buffer[128];
1.180 kia 2283:
1.186 kia 2284: ElementType repType;
1.187 kia 2285: Element rep, use;
1.180 kia 2286:
2287: if (!TtaGetDocumentAccessMode(doc))
1.198 kia 2288: return NULL;
1.206 kia 2289:
1.209 vatton 2290: if (doc && TtaGetDocumentAccessMode(doc) && sstempl &&
1.180 kia 2291: IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
2292: {
2293: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
2294: TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);
1.185 kia 2295:
1.209 vatton 2296: if (selElem && selElem2)
1.180 kia 2297: {
1.207 vatton 2298: // request the element label
2299: QueryStringFromUser(label, title, buffer, 127);
2300: if (buffer[0] == EOS)
2301: return NULL;
2302:
1.180 kia 2303: selType = TtaGetElementType(selElem);
2304: selType2 = TtaGetElementType(selElem2);
2305: repType.ElSSchema = sstempl;
1.208 kia 2306: repType.ElTypeNum = Template_EL_repeat;
1.185 kia 2307: parent = TtaGetParent(selElem);
2308: parent2 = TtaGetParent(selElem2);
1.209 vatton 2309: if (firstChar==0 && firstChar2==0 && parent == parent2 && buffer[0]!=0)
1.180 kia 2310: {
1.187 kia 2311: dispMode = TtaGetDisplayMode (doc);
2312: if (dispMode == DisplayImmediately)
2313: TtaSetDisplayMode (doc, DeferredDisplay);
2314: oldStructureChecking = TtaGetStructureChecking (doc);
2315: TtaSetStructureChecking (FALSE, doc);
1.206 kia 2316:
1.209 vatton 2317: if (selElem==selElem2 && selType.ElSSchema==sstempl &&
1.206 kia 2318: (selType.ElTypeNum==Template_EL_useEl ||
1.187 kia 2319: selType.ElTypeNum==Template_EL_useSimple))
2320: use = selElem;
2321: else
1.198 kia 2322: use = Template_CreateUseFromSelection(doc, createComp);
1.209 vatton 2323: if (use)
1.187 kia 2324: {
2325: TtaExtendUndoSequence(doc);
1.206 kia 2326:
1.187 kia 2327: rep = TtaNewElement(doc, repType);
1.206 kia 2328:
1.187 kia 2329: TtaInsertSibling(rep, use, FALSE, doc);
1.197 kia 2330: SetAttributeStringValue(rep, Template_ATTR_title, buffer);
1.187 kia 2331: TtaRegisterElementCreate(rep, doc);
1.206 kia 2332:
1.187 kia 2333: TtaRegisterElementDelete (use, doc);
2334: TtaRemoveTree(use, doc);
1.206 kia 2335:
1.187 kia 2336: TtaInsertFirstChild(&use, rep, doc);
2337: TtaRegisterElementCreate(use, doc);
1.206 kia 2338:
1.187 kia 2339: TtaSelectElement(doc, use);
2340: TtaCloseUndoSequence(doc);
2341: }
1.206 kia 2342:
1.187 kia 2343: TtaSetStructureChecking (oldStructureChecking, doc);
2344: TtaSetDisplayMode (doc, dispMode);
1.198 kia 2345: return rep;
1.187 kia 2346: }
2347: }
2348: }
2349: #endif /* TEMPLATES */
1.198 kia 2350: return NULL;
1.195 kia 2351: }
2352:
1.187 kia 2353: /*----------------------------------------------------------------------
2354: TemplateCreateUseBox
2355: Create a xt:use around the selection.
2356: ----------------------------------------------------------------------*/
2357: void TemplateCreateUseBox(Document doc, View view)
2358: {
2359: #ifdef TEMPLATES
1.197 kia 2360: Template_CreateUseFromSelection(doc, FALSE);
1.187 kia 2361: #endif /* TEMPLATES */
2362: }
2363:
1.194 kia 2364: /*----------------------------------------------------------------------
1.195 kia 2365: TemplateCreateUseCompBox
2366: Create a xt:use around the selection.
2367: ----------------------------------------------------------------------*/
2368: void TemplateCreateUseCompBox(Document doc, View view)
2369: {
2370: #ifdef TEMPLATES
1.197 kia 2371: Template_CreateUseFromSelection(doc, TRUE);
1.195 kia 2372: #endif /* TEMPLATES */
2373: }
2374:
2375: /*----------------------------------------------------------------------
1.194 kia 2376: Template_CreateInlineUse
2377: Create an inline xt:use with the selection.
2378: ----------------------------------------------------------------------*/
1.206 kia 2379: static Element Template_CreateInlineUse(Document doc)
1.194 kia 2380: {
2381: #ifdef TEMPLATES
2382: SSchema sstempl = TtaGetSSchema ("Template", doc);
2383: int firstChar, lastChar;
1.206 kia 2384: Element selElem, use = NULL;
1.194 kia 2385: XTigerTemplate t = GetXTigerDocTemplate(doc);
2386: char *proposed, *label = NULL, *types=NULL;
1.206 kia 2387: ThotBool option;
2388:
1.209 vatton 2389: if (t && sstempl)
1.194 kia 2390: {
2391: proposed = Template_GetInlineLevelDeclarations(t, TRUE, TRUE);
1.209 vatton 2392: if (QueryNewUseFromUser(proposed, &label, &types, &option))
1.194 kia 2393: {
2394: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
2395:
2396: GenerateInlineElement(Template_EL_useEl, sstempl, 0, NULL, TRUE);
1.206 kia 2397:
1.194 kia 2398: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
1.206 kia 2399:
1.197 kia 2400: use = selElem;
2401: TtaNextSibling(&use);
2402:
1.194 kia 2403: SetAttributeStringValue(use, Template_ATTR_title, label);
2404: SetAttributeStringValue(use, Template_ATTR_types, types);
1.206 kia 2405:
1.194 kia 2406: TtaSelectElement(doc, use);
2407: TtaCloseUndoSequence(doc);
2408: }
1.206 kia 2409:
1.194 kia 2410: TtaFreeMemory(proposed);
2411: TtaFreeMemory(label);
2412: TtaFreeMemory(types);
1.206 kia 2413: return use;
2414: }
2415:
1.194 kia 2416: #endif /* TEMPLATES */
2417: return FALSE;
1.206 kia 2418:
1.194 kia 2419: }
2420:
2421: /*----------------------------------------------------------------------
2422: Template_CreateEmptyBlockUse
2423: Create a block xt:use with the selection.
2424: ----------------------------------------------------------------------*/
1.206 kia 2425: static Element Template_CreateEmptyBlockUse(Document doc)
1.194 kia 2426: {
2427: #ifdef TEMPLATES
2428: SSchema sstempl = TtaGetSSchema ("Template", doc);
2429: ElementType useType;
2430: int firstChar, lastChar;
2431: Element selElem, use;
2432: XTigerTemplate t = GetXTigerDocTemplate(doc);
2433: char *proposed, *label = NULL, *types=NULL;
2434: ThotBool option, res = FALSE;
1.206 kia 2435:
2436:
1.209 vatton 2437: if (t && sstempl)
1.194 kia 2438: {
2439: proposed = Template_GetBlockLevelDeclarations(t, TRUE);
1.209 vatton 2440: if (QueryNewUseFromUser(proposed, &label, &types, &option))
1.194 kia 2441: {
2442: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
2443:
2444: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
2445: useType.ElSSchema = sstempl;
2446: useType.ElTypeNum = Template_EL_useEl;
2447: use = TtaNewElement(doc, useType);
1.206 kia 2448:
1.194 kia 2449: TtaInsertSibling(use, selElem, FALSE, doc);
2450: TtaDeleteTree(selElem, doc);
1.206 kia 2451:
1.194 kia 2452: SetAttributeStringValue(use, Template_ATTR_title, label);
2453: SetAttributeStringValue(use, Template_ATTR_types, types);
2454: TtaRegisterElementCreate(use, doc);
2455: res = TRUE;
1.206 kia 2456:
1.194 kia 2457: TtaSelectElement(doc, use);
2458: TtaCloseUndoSequence(doc);
2459:
2460: }
1.206 kia 2461:
1.194 kia 2462: TtaFreeMemory(proposed);
2463: TtaFreeMemory(label);
2464: TtaFreeMemory(types);
1.206 kia 2465: return use;
2466: }
2467:
1.194 kia 2468: #endif /* TEMPLATES */
2469: return FALSE;
2470: }
1.187 kia 2471:
2472: /*----------------------------------------------------------------------
2473: Template_CreateUseFromSelection
2474: Create a xt:use with the selection.
1.197 kia 2475: If selection is empty, insert an inline xt:use.
1.206 kia 2476: If createComp is false, create a xt:use with types at the selected block.
1.197 kia 2477: If createComp is true, create a component with the selection.
2478: Return the xt:use element.
1.187 kia 2479: ----------------------------------------------------------------------*/
1.197 kia 2480: Element Template_CreateUseFromSelection(Document doc, ThotBool createComp)
1.187 kia 2481: {
2482: #ifdef TEMPLATES
1.206 kia 2483: ThotBool oldStructureChecking, option;
1.187 kia 2484: DisplayMode dispMode;
2485: Element selElem, selElem2, parent, parent2;
2486: ElementType selType, selType2;
2487: int firstChar, lastChar, firstChar2, lastChar2;
1.194 kia 2488: SSchema sstempl = TtaGetSSchema ("Template", doc),
1.209 vatton 2489: sshtml = TtaGetSSchema ("HTML", doc);
1.206 kia 2490: XTigerTemplate t;
1.187 kia 2491:
2492: ElementType useType;
2493: Element use = NULL, comp, prev;
1.206 kia 2494: char *proposed, *checked, *types=NULL;
1.187 kia 2495: char buffer[128];
2496: int sz = 128;
2497:
2498: if (!TtaGetDocumentAccessMode(doc))
2499: return NULL;
1.206 kia 2500:
1.208 kia 2501: const char *title = TtaGetMessage (AMAYA, AM_TEMPLATE_USE);
2502: const char *label = TtaGetMessage (AMAYA, AM_NAME);
2503:
2504:
1.209 vatton 2505: if (doc && TtaGetDocumentAccessMode(doc) && sstempl &&
1.187 kia 2506: IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
2507: {
2508: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
2509: TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);
2510:
1.209 vatton 2511: // printf(">> %p %d %d %s (%d)\n", selElem, firstChar, lastChar, TtaGetElementTypeName(TtaGetElementType(selElem)), TtaGetElementType(selElem).ElTypeNum);
2512: // printf(" > %p %d %d %s (%d)\n", selElem2, firstChar2, lastChar2, TtaGetElementTypeName(TtaGetElementType(selElem2)), TtaGetElementType(selElem2).ElTypeNum);
1.206 kia 2513:
2514: t = GetXTigerDocTemplate(doc);
2515:
1.209 vatton 2516: if (selElem && selElem2 && t)
1.187 kia 2517: {
2518: selType = TtaGetElementType(selElem);
2519: selType2 = TtaGetElementType(selElem2);
2520: parent = TtaGetParent(selElem);
2521: parent2 = TtaGetParent(selElem2);
2522:
1.194 kia 2523: dispMode = TtaGetDisplayMode (doc);
2524: if (dispMode == DisplayImmediately)
2525: TtaSetDisplayMode (doc, DeferredDisplay);
2526: oldStructureChecking = TtaGetStructureChecking (doc);
2527: TtaSetStructureChecking (FALSE, doc);
1.206 kia 2528:
1.209 vatton 2529: if (firstChar==0 && firstChar2==0 && parent == parent2)
1.187 kia 2530: {
1.209 vatton 2531: if (selType.ElSSchema==sstempl)
1.206 kia 2532: {
2533: // The selection is a template element.
2534: switch(selType.ElTypeNum)
1.209 vatton 2535: {
1.206 kia 2536: case Template_EL_useEl:
2537: case Template_EL_useSimple:
2538: // TODO query to add/remove some types
1.209 vatton 2539: if (TtaGetElementVolume(selElem)==0)
1.206 kia 2540: {
2541: proposed = Template_GetAllDeclarations(t, TRUE, TRUE, TRUE);
2542: checked = GetAttributeStringValueFromNum(selElem, Template_ATTR_types, NULL);
2543: option = GetAttributeIntValueFromNum(selElem, Template_ATTR_option)==Template_ATTR_option_VAL_option_set;
1.209 vatton 2544: if (QueryUseFromUser(proposed, checked, buffer, 128, &types, &option))
1.206 kia 2545: {
2546: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
2547: SetAttributeStringValueWithUndo(selElem, Template_ATTR_types, types);
2548: SetAttributeStringValueWithUndo(selElem, Template_ATTR_title, buffer);
1.209 vatton 2549: if (option)
1.206 kia 2550: SetAttributeIntValue(selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_set, TRUE);
2551: else
2552: SetAttributeIntValue(selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_unset, TRUE);
2553:
2554: TtaCloseUndoSequence(doc);
2555: }
2556: TtaFreeMemory(proposed);
2557: TtaFreeMemory(checked);
2558: TtaFreeMemory(types);
2559: createComp = FALSE;
2560: }
2561: break;
2562: default:
2563: // Do nothing
2564: break;
1.209 vatton 2565: }
1.206 kia 2566: }
1.209 vatton 2567: else if (selType.ElSSchema==sshtml && (selType.ElTypeNum==HTML_EL_Element ||
2568: selType.ElTypeNum==HTML_EL_Basic_Elem ||
2569: (selType.ElTypeNum==HTML_EL_Paragraph && TtaGetElementVolume(selElem)==0)))
1.206 kia 2570: {
2571: // Create a block-level xt:use instead of selection.
2572:
2573: use = Template_CreateEmptyBlockUse(doc);
2574: }
1.194 kia 2575: else
1.186 kia 2576: {
1.194 kia 2577: prev = selElem;
2578: TtaPreviousSibling(&prev);
1.197 kia 2579:
1.209 vatton 2580: if (createComp)
1.197 kia 2581: {
1.206 kia 2582: // Create a xt:component from selection and create a xt:use using it
1.197 kia 2583: comp = Template_CreateComponentFromSelection(doc);
1.209 vatton 2584: if (comp)
1.197 kia 2585: {
2586: TtaExtendUndoSequence(doc);
1.206 kia 2587:
1.197 kia 2588: useType.ElSSchema = sstempl;
2589: useType.ElTypeNum = Template_EL_useEl;
2590: use = TtaNewElement(doc, useType);
1.209 vatton 2591: if (prev)
1.197 kia 2592: TtaInsertSibling(use, prev, FALSE, doc);
2593: else
2594: TtaInsertFirstChild(&use, parent, doc);
1.206 kia 2595:
1.197 kia 2596: GiveAttributeStringValueFromNum(comp, Template_ATTR_name, buffer, &sz);
2597: SetAttributeStringValue(use, Template_ATTR_types, buffer);
1.208 kia 2598: SetAttributeStringValue(use, Template_ATTR_title, buffer);
1.197 kia 2599: TtaRegisterElementCreate(use, doc);
1.206 kia 2600:
1.197 kia 2601: TtaSelectElement(doc, use);
1.206 kia 2602:
1.197 kia 2603: TtaCloseUndoSequence(doc);
2604: }
2605: }
2606: else
1.194 kia 2607: {
1.208 kia 2608: QueryStringFromUser(label, title, buffer, 127);
2609:
1.197 kia 2610: // Create a xt:use around the selection
2611: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
1.206 kia 2612:
1.197 kia 2613: TtaRegisterElementDelete (selElem, doc);
2614: TtaRemoveTree(selElem, doc);
2615:
1.194 kia 2616: useType.ElSSchema = sstempl;
1.197 kia 2617: useType.ElTypeNum = Template_EL_useSimple;
1.194 kia 2618: use = TtaNewElement(doc, useType);
1.209 vatton 2619: if (prev)
1.194 kia 2620: TtaInsertSibling(use, prev, FALSE, doc);
2621: else
2622: TtaInsertFirstChild(&use, parent, doc);
1.206 kia 2623:
1.197 kia 2624: TtaInsertFirstChild(&selElem, use, doc);
1.206 kia 2625:
1.197 kia 2626: SetAttributeStringValue(use, Template_ATTR_types, TtaGetElementTypeName(TtaGetElementType(selElem)));
1.209 vatton 2627: if (buffer[0]!=EOS)
1.208 kia 2628: SetAttributeStringValue(use, Template_ATTR_title, buffer);
1.206 kia 2629:
1.194 kia 2630: TtaRegisterElementCreate(use, doc);
1.206 kia 2631:
1.194 kia 2632: TtaCloseUndoSequence(doc);
2633: }
1.186 kia 2634: }
2635: }
1.209 vatton 2636: else if (lastChar<firstChar)
2637: use = Template_CreateInlineUse(doc);
1.206 kia 2638:
1.194 kia 2639: TtaSetStructureChecking (oldStructureChecking, doc);
2640: TtaSetDisplayMode (doc, dispMode);
1.206 kia 2641:
1.186 kia 2642: }
2643: }
1.187 kia 2644: return use;
2645: #else /* TEMPLATES */
2646: return NULL;
1.186 kia 2647: #endif /* TEMPLATES */
2648: }
2649:
2650: /*----------------------------------------------------------------------
1.187 kia 2651: Template_CreateComponentFromSelection
1.186 kia 2652: Create a xt:component with the selection and move it into the xt:head.
1.187 kia 2653: Return the xt:component element.
1.186 kia 2654: ----------------------------------------------------------------------*/
1.187 kia 2655: Element Template_CreateComponentFromSelection(Document doc)
1.186 kia 2656: {
2657: #ifdef TEMPLATES
1.187 kia 2658: ThotBool oldStructureChecking;
2659: DisplayMode dispMode;
1.186 kia 2660: Element selElem, selElem2, parent, parent2, current, child, head;
2661: ElementType selType, selType2;
2662: int firstChar, lastChar, firstChar2, lastChar2;
2663: SSchema sstempl = TtaGetSSchema ("Template", doc);
1.192 kia 2664: XTigerTemplate t = GetXTigerDocTemplate(doc);
1.206 kia 2665:
1.186 kia 2666: ElementType compType;
2667: Element comp = NULL;
2668: char buffer[128];
1.200 kia 2669: int sz = 128;
1.185 kia 2670:
1.186 kia 2671: const char *title = TtaGetMessage (AMAYA, AM_TEMPLATE_NEWCOMP);
1.204 vatton 2672: const char *label = TtaGetMessage (AMAYA, AM_NAME);
1.186 kia 2673:
1.209 vatton 2674: if (doc && t && TtaGetDocumentAccessMode(doc) &&
1.186 kia 2675: TtaGetDocumentAccessMode(doc) && sstempl &&
2676: IsTemplateDocument(doc) && !IsTemplateInstanceDocument(doc))
2677: {
2678: TtaGiveFirstSelectedElement(doc, &selElem, &firstChar, &lastChar);
2679: TtaGiveLastSelectedElement(doc, &selElem2, &firstChar2, &lastChar2);
2680:
1.209 vatton 2681: if (selElem && selElem2)
1.186 kia 2682: {
2683: selType = TtaGetElementType(selElem);
2684: selType2 = TtaGetElementType(selElem2);
2685:
2686: QueryStringFromUser(label, title, buffer, 127);
1.209 vatton 2687: if (buffer[0]!=EOS)
1.186 kia 2688: {
1.190 kia 2689: head = TemplateFindHead(doc);
1.206 kia 2690:
1.190 kia 2691: compType.ElSSchema = sstempl;
2692: compType.ElTypeNum = Template_EL_component;
1.206 kia 2693:
1.190 kia 2694: parent = TtaGetParent(selElem);
2695: parent2 = TtaGetParent(selElem2);
1.206 kia 2696:
1.209 vatton 2697: if (head && firstChar==0 && firstChar2==0 && parent == parent2)
1.180 kia 2698: {
1.190 kia 2699: dispMode = TtaGetDisplayMode (doc);
2700: if (dispMode == DisplayImmediately)
2701: TtaSetDisplayMode (doc, DeferredDisplay);
2702: oldStructureChecking = TtaGetStructureChecking (doc);
2703: TtaSetStructureChecking (FALSE, doc);
1.206 kia 2704:
1.190 kia 2705: child = TtaGetLastChild(head);
2706: TtaOpenUndoSequence (doc, NULL, NULL, 0, 0);
2707: comp = TtaNewElement(doc, compType);
1.209 vatton 2708: if (child)
1.190 kia 2709: TtaInsertSibling(comp, child, FALSE, doc);
1.185 kia 2710: else
1.190 kia 2711: TtaInsertFirstChild(&comp, head, doc);
2712: TtaRegisterElementCreate(comp, doc);
1.206 kia 2713:
1.190 kia 2714: TtaNextSibling(&selElem2);
2715: child = NULL;
1.209 vatton 2716: while (selElem!=selElem2)
1.190 kia 2717: {
2718: current = selElem;
2719: TtaNextSibling(&selElem);
1.206 kia 2720:
1.190 kia 2721: TtaRegisterElementDelete (current, doc);
2722: TtaRemoveTree(current, doc);
1.209 vatton 2723: if (child)
1.190 kia 2724: TtaInsertSibling(current, child, FALSE, doc);
2725: else
2726: TtaInsertFirstChild(¤t, comp, doc);
2727: TtaRegisterElementDelete (current, doc);
2728: child = current;
2729: }
1.209 vatton 2730: if (!Template_SetName(doc, comp, buffer, TRUE))
2731: GiveAttributeStringValueFromNum(comp, Template_ATTR_name, buffer, &sz);
1.206 kia 2732:
1.190 kia 2733: TtaCloseUndoSequence(doc);
2734: TtaSelectElement(doc, comp);
1.206 kia 2735:
1.192 kia 2736: Template_DeclareNewComponent(t, buffer, comp);
1.206 kia 2737:
1.190 kia 2738: TtaSetStructureChecking (oldStructureChecking, doc);
2739: TtaSetDisplayMode (doc, dispMode);
1.180 kia 2740: }
2741: }
2742: }
2743: }
1.186 kia 2744: return comp;
1.187 kia 2745: #else /* TEMPLATES */
2746: return NULL;
1.206 kia 2747: #endif /* TEMPLATES */
1.180 kia 2748: }
1.187 kia 2749:
1.192 kia 2750: /*----------------------------------------------------------------------
2751: TemplateComponentWillBeDeleted
2752: Processed when a component element will be deleted in a template context.
2753: ----------------------------------------------------------------------*/
2754: ThotBool TemplateComponentWillBeDeleted (NotifyElement *event)
2755: {
2756: #ifdef TEMPLATES
2757: XTigerTemplate t = GetXTigerDocTemplate(event->document);
2758: char* elemName = GetAttributeStringValueFromNum(event->element, Template_ATTR_name, NULL);
1.206 kia 2759:
1.209 vatton 2760: if (Template_IsUsedComponent(t, event->document, elemName))
1.192 kia 2761: {
2762: TtaDisplaySimpleMessage (CONFIRM, AMAYA, AM_TEMPLATE_USEDCOMP_CANTREMOVE);
2763: return TRUE;
2764: }
1.206 kia 2765: #endif /* TEMPLATES */
1.192 kia 2766: return FALSE;
2767: }
1.187 kia 2768:
1.200 kia 2769: /*----------------------------------------------------------------------
2770: UnionClicked
1.206 kia 2771: Called when a xt:union is clicked
1.200 kia 2772: ----------------------------------------------------------------------*/
2773: void UnionClicked(NotifyElement* event)
2774: {
1.209 vatton 2775: if (event->document && event->element)
1.200 kia 2776: TtaSelectElement(event->document, event->element);
2777: }
2778:
2779: /*----------------------------------------------------------------------
2780: UnionDoubleClicked
1.206 kia 2781: Called when a xt:union is double clicked
1.200 kia 2782: ----------------------------------------------------------------------*/
2783: ThotBool UnionDoubleClicked(NotifyElement* event)
2784: {
2785: Template_ModifyUnionElement(event->document, event->element);
2786: TtaSelectElement(event->document, event->element);
2787: return TRUE;
2788: }
2789:
2790: /*----------------------------------------------------------------------
2791: TemplateNameAttributeDeleted
1.206 kia 2792: Called when a xt:name will be deleted
1.200 kia 2793: ----------------------------------------------------------------------*/
2794: ThotBool TemplateNameAttributeDeleted(NotifyAttribute* event)
2795: {
2796: // Prevent xt:name deletion
2797: return TRUE;
2798: }
2799:
2800: /*----------------------------------------------------------------------
2801: TemplateNameAttributeModified
1.206 kia 2802: Called when a xt:name will be modified
1.200 kia 2803: ----------------------------------------------------------------------*/
2804: ThotBool TemplateNameAttributeModified(NotifyAttribute* event)
2805: {
2806: // Prevent xt:name modification
2807: return TRUE;
2808: }
2809:
2810: /*----------------------------------------------------------------------
2811: TemplateNameAttributeCreated
1.206 kia 2812: Called when a xt:name have been created
1.200 kia 2813: ----------------------------------------------------------------------*/
1.203 vatton 2814: void TemplateNameAttributeCreated(NotifyAttribute* event)
1.200 kia 2815: {
1.202 kia 2816: MakeUniqueName(event->element, event->document, TRUE, FALSE);
1.200 kia 2817: }
2818:
2819:
2820: /*----------------------------------------------------------------------
2821: TemplateNameAttrInMenu
2822: Called by Thot when building the Attributes menu for template elements.
2823: ----------------------------------------------------------------------*/
2824: ThotBool TemplateNameAttrInMenu (NotifyAttribute * event)
2825: {
2826: #ifdef TEMPLATES
2827: ElementType type = TtaGetElementType(event->element);
1.209 vatton 2828: if (type.ElTypeNum==Template_EL_component ||
1.200 kia 2829: type.ElTypeNum==Template_EL_union)
2830: return TRUE;
2831: #endif /* TEMPLATES */
1.209 vatton 2832: return FALSE;
1.200 kia 2833: }
2834:
Webmaster