version 1.240, 2009/08/17 15:28:52
|
version 1.241, 2009/08/18 14:33:16
|
Line 1405 void Template_FillFromDocument (Document
|
Line 1405 void Template_FillFromDocument (Document
|
Template_CheckAndPrepareTemplate checks if the document is a template |
Template_CheckAndPrepareTemplate checks if the document is a template |
or a library and prepare XTigerTemplate structure to use it. |
or a library and prepare XTigerTemplate structure to use it. |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
ThotBool Template_CheckAndPrepareTemplate(char* docURL) |
ThotBool Template_CheckAndPrepareTemplate (char* docURL) |
{ |
{ |
#ifdef TEMPLATES |
#ifdef TEMPLATES |
XTigerTemplate t = NULL; //GetXTigerTemplate(docURL); |
XTigerTemplate t = NULL; //GetXTigerTemplate(docURL); |
|
|
if (IsXTiger(docURL)) |
if (IsXTiger (docURL)) |
{ |
{ |
#ifdef TEMPLATE_DEBUG |
#ifdef TEMPLATE_DEBUG |
printf("Template_CheckAndPrepareTemplate %s templTemplate\n", docURL); |
printf("Template_CheckAndPrepareTemplate %s templTemplate\n", docURL); |
Line 1418 ThotBool Template_CheckAndPrepareTemplat
|
Line 1418 ThotBool Template_CheckAndPrepareTemplat
|
t = LookForXTigerTemplate (docURL); |
t = LookForXTigerTemplate (docURL); |
t->state |= templTemplate; |
t->state |= templTemplate; |
} |
} |
else if (IsXTigerLibrary(docURL)) |
else if (IsXTigerLibrary (docURL)) |
{ |
{ |
#ifdef TEMPLATE_DEBUG |
#ifdef TEMPLATE_DEBUG |
printf("Template_CheckAndPrepareTemplate %s templLibrary\n", docURL); |
printf("Template_CheckAndPrepareTemplate %s templLibrary\n", docURL); |
Line 1519 void Template_CheckAndPrepareInstance (c
|
Line 1519 void Template_CheckAndPrepareInstance (c
|
ClosingTemplateDocument |
ClosingTemplateDocument |
Callback called before closing a document which uses templates. |
Callback called before closing a document which uses templates. |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
ThotBool ClosingTemplateDocument(NotifyDialog* dialog) |
ThotBool ClosingTemplateDocument (NotifyDialog* dialog) |
{ |
{ |
#ifdef TEMPLATES |
#ifdef TEMPLATES |
XTigerTemplate t = GetXTigerDocTemplate(dialog->document); |
XTigerTemplate t = GetXTigerDocTemplate (dialog->document); |
if (t) |
if (t) |
Template_RemoveReference(t); |
Template_RemoveReference(t); |
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
Line 1538 ThotBool IsTemplateElement (Element elem
|
Line 1538 ThotBool IsTemplateElement (Element elem
|
#ifdef TEMPLATES |
#ifdef TEMPLATES |
ElementType elType; |
ElementType elType; |
|
|
elType = TtaGetElementType(elem); |
elType = TtaGetElementType (elem); |
if (elType.ElSSchema) |
if (elType.ElSSchema) |
return (strcmp(TtaGetSSchemaName(elType.ElSSchema) , "Template") == 0); |
return (strcmp (TtaGetSSchemaName(elType.ElSSchema) , "Template") == 0); |
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
return FALSE; |
return FALSE; |
} |
} |
Line 1550 ThotBool IsTemplateElement (Element elem
|
Line 1550 ThotBool IsTemplateElement (Element elem
|
GetFirstTemplateParentElement |
GetFirstTemplateParentElement |
Return the first element which has "Template" as schema name or null. |
Return the first element which has "Template" as schema name or null. |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
Element GetFirstTemplateParentElement(Element elem) |
Element GetFirstTemplateParentElement (Element elem) |
{ |
{ |
#ifdef TEMPLATES |
#ifdef TEMPLATES |
ElementType elType; |
ElementType elType; |
Line 1912 void UpdateTemplateMenus (Document doc)
|
Line 1912 void UpdateTemplateMenus (Document doc)
|
TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeatComp); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeatComp); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateFreeBox); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateFreeBox); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateUnion); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateUnion); |
|
TtaSetItemOff (doc, 1, Tools, BTemplateCreateImport); |
} |
} |
else if (DocumentURLs[doc] && DocumentTypes[doc] != docSource && |
else if (DocumentURLs[doc] && DocumentTypes[doc] != docSource && |
(IsXTiger (DocumentURLs[doc]) || IsXTigerLibrary (DocumentURLs[doc]))) |
(IsXTiger (DocumentURLs[doc]) || IsXTigerLibrary (DocumentURLs[doc]))) |
Line 1925 void UpdateTemplateMenus (Document doc)
|
Line 1926 void UpdateTemplateMenus (Document doc)
|
TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeatComp); |
TtaSetItemOn (doc, 1, Tools, BTemplateCreateRepeatComp); |
TtaSetItemOn (doc, 1, Tools, BTemplateCreateFreeBox); |
TtaSetItemOn (doc, 1, Tools, BTemplateCreateFreeBox); |
TtaSetItemOn (doc, 1, Tools, BTemplateCreateUnion); |
TtaSetItemOn (doc, 1, Tools, BTemplateCreateUnion); |
|
TtaSetItemOn (doc, 1, Tools, BTemplateCreateImport); |
} |
} |
else |
else |
{ |
{ |
Line 1937 void UpdateTemplateMenus (Document doc)
|
Line 1939 void UpdateTemplateMenus (Document doc)
|
TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeatComp); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateRepeatComp); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateFreeBox); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateFreeBox); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateUnion); |
TtaSetItemOff (doc, 1, Tools, BTemplateCreateUnion); |
|
TtaSetItemOff (doc, 1, Tools, BTemplateCreateImport); |
} |
} |
} |
} |
|
|
Line 1960 void UninstanciateTemplateDocument(Docum
|
Line 1963 void UninstanciateTemplateDocument(Docum
|
Allocate XTigerTemplate structure for instance and initialize template |
Allocate XTigerTemplate structure for instance and initialize template |
url and template version. |
url and template version. |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
void Template_PrepareInstance(char *fileName, Document doc, char* template_version, char* template_url) |
void Template_PrepareInstance (char *url, Document doc, |
|
char* template_version, char* template_url) |
{ |
{ |
#ifdef TEMPLATES |
#ifdef TEMPLATES |
XTigerTemplate t = GetXTigerTemplate(fileName); |
XTigerTemplate t = GetXTigerTemplate (url); |
if (!t) |
if (!t) |
t = NewXTigerTemplate(fileName); |
t = NewXTigerTemplate (url); |
t->state = templInstance; |
t->state = templInstance; |
t->templateVersion = TtaStrdup (template_version); |
t->templateVersion = TtaStrdup (template_version); |
//t->uri = TtaStrdup (fileName); // already done |
//t->uri = TtaStrdup (fileName); // already done |
t->base_uri = TtaStrdup (template_url); |
t->base_uri = TtaStrdup (template_url); |
t->doc = doc; |
t->doc = doc; |
t->ref = 1; |
t->ref = 1; |
|
#endif /* TEMPLATES */ |
|
} |
|
|
|
/*---------------------------------------------------------------------- |
|
Template_PrepareLibrary |
|
Allocate XTigerTemplate structure for a library and initialize template |
|
url and template version. |
|
----------------------------------------------------------------------*/ |
|
void Template_PrepareLibrary (char *url, Document doc, char* template_version) |
|
{ |
|
#ifdef TEMPLATES |
|
XTigerTemplate t = GetXTigerTemplate(url); |
|
if (!t) |
|
t = NewXTigerTemplate (url); |
|
t->state = templLibrary; |
|
t->templateVersion = TtaStrdup (template_version); |
|
//t->uri = TtaStrdup (fileName); // already done |
|
t->doc = doc; |
|
t->ref = 1; |
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
} |
} |
|
|
Line 1981 void Template_PrepareInstance(char *file
|
Line 2003 void Template_PrepareInstance(char *file
|
SetDocumentAsXTigerTemplate |
SetDocumentAsXTigerTemplate |
Set the document template structure as template. |
Set the document template structure as template. |
----------------------------------------------------------------------*/ |
----------------------------------------------------------------------*/ |
void SetDocumentAsXTigerTemplate(Document doc) |
void SetDocumentAsXTigerTemplate (Document doc) |
{ |
{ |
#ifdef TEMPLATES |
#ifdef TEMPLATES |
XTigerTemplate t = GetXTigerDocTemplate(doc); |
XTigerTemplate t = GetXTigerDocTemplate (doc); |
if (t) |
if (t) |
t->state |= templTemplate; |
t->state |= templTemplate; |
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
Line 2150 void TemplateCreateTextBox (Document doc
|
Line 2172 void TemplateCreateTextBox (Document doc
|
#endif /* TEMPLATES */ |
#endif /* TEMPLATES */ |
} |
} |
|
|
|
/*---------------------------------------------------------------------- |
|
TemplateCreateImport |
|
Create a xt:import |
|
----------------------------------------------------------------------*/ |
|
void TemplateCreateImport (Document doc, View view) |
|
{ |
|
#ifdef TEMPLATES |
|
#endif /* TEMPLATES */ |
|
} |
|
|
|
|
/*---------------------------------------------------------------------- |
/*---------------------------------------------------------------------- |
TemplateCreateFreeBox |
TemplateCreateFreeBox |
Line 2655 Element Template_CreateUseFromSelection
|
Line 2687 Element Template_CreateUseFromSelection
|
DisplayMode dispMode; |
DisplayMode dispMode; |
Element selElem, selElem2, parent, parent2; |
Element selElem, selElem2, parent, parent2; |
Element use = NULL, comp, prev, next; |
Element use = NULL, comp, prev, next; |
ElementType selType, selType2, useType; |
ElementType selType, selType2, useType, compType; |
SSchema sstempl, sshtml; |
SSchema sstempl, sshtml; |
XTigerTemplate t; |
XTigerTemplate t; |
int firstChar, lastChar, firstChar2, lastChar2; |
int firstChar, lastChar, firstChar2, lastChar2; |
Line 2690 Element Template_CreateUseFromSelection
|
Line 2722 Element Template_CreateUseFromSelection
|
|
|
if (firstChar == 0 && firstChar2 == 0 && parent == parent2) |
if (firstChar == 0 && firstChar2 == 0 && parent == parent2) |
{ |
{ |
if (selType.ElSSchema == sstempl) |
if (selType.ElSSchema == sstempl && |
|
(selType.ElTypeNum == Template_EL_useEl || |
|
selType.ElTypeNum == Template_EL_useSimple)) |
{ |
{ |
// The selection is a template element. |
// The selection is a template element. |
switch(selType.ElTypeNum) |
// TODO query to add/remove some types |
|
if (TtaGetElementVolume(selElem) == 0) |
{ |
{ |
case Template_EL_useEl: |
proposed = Template_GetAllDeclarations(t, TRUE, TRUE, TRUE); |
case Template_EL_useSimple: |
checked = GetAttributeStringValueFromNum (selElem, Template_ATTR_types, NULL); |
// TODO query to add/remove some types |
option = GetAttributeIntValueFromNum (selElem, Template_ATTR_option); |
if (TtaGetElementVolume(selElem) == 0) |
opt = (option == Template_ATTR_option_VAL_option_set); |
|
if (QueryUseFromUser (proposed, checked, buffer, 128, &types, &opt)) |
{ |
{ |
proposed = Template_GetAllDeclarations(t, TRUE, TRUE, TRUE); |
SetAttributeStringValueWithUndo(selElem, Template_ATTR_types, types); |
checked = GetAttributeStringValueFromNum (selElem, Template_ATTR_types, NULL); |
SetAttributeStringValueWithUndo(selElem, Template_ATTR_title, buffer); |
option = GetAttributeIntValueFromNum (selElem, Template_ATTR_option); |
if (opt) |
opt = (option == Template_ATTR_option_VAL_option_set); |
SetAttributeIntValue (selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_set, TRUE); |
if (QueryUseFromUser (proposed, checked, buffer, 128, &types, &opt)) |
else |
{ |
SetAttributeIntValue (selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_unset, TRUE); |
SetAttributeStringValueWithUndo(selElem, Template_ATTR_types, types); |
// register document modification |
SetAttributeStringValueWithUndo(selElem, Template_ATTR_title, buffer); |
TtaSetDocumentModified (doc); |
if (opt) |
|
SetAttributeIntValue (selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_set, TRUE); |
|
else |
|
SetAttributeIntValue (selElem, Template_ATTR_option, Template_ATTR_option_VAL_option_unset, TRUE); |
|
// register document modification |
|
TtaSetDocumentModified (doc); |
|
} |
|
TtaFreeMemory (proposed); |
|
TtaFreeMemory (checked); |
|
TtaFreeMemory (types); |
|
createComp = FALSE; |
|
} |
} |
break; |
TtaFreeMemory (proposed); |
default: |
TtaFreeMemory (checked); |
// Do nothing |
TtaFreeMemory (types); |
break; |
createComp = FALSE; |
} |
} |
} |
} |
else if (selElem != selElem2 && |
else if (selElem != selElem2 && |
Line 2765 Element Template_CreateUseFromSelection
|
Line 2790 Element Template_CreateUseFromSelection
|
TtaGetElementVolume(selElem) == 0))) |
TtaGetElementVolume(selElem) == 0))) |
// Create a block-level xt:use instead of selection. |
// Create a block-level xt:use instead of selection. |
use = Template_CreateEmptyBlockUse (doc); |
use = Template_CreateEmptyBlockUse (doc); |
|
else if (selType.ElSSchema == sstempl) |
|
{ |
|
prev = next = NULL; |
|
if (selType.ElSSchema == sstempl && |
|
selType.ElTypeNum == Template_EL_component) |
|
next = selElem; |
|
else if (selType.ElSSchema == sstempl && |
|
selType.ElTypeNum == Template_EL_union) |
|
prev = selElem; |
|
else if (selType.ElSSchema == sstempl && |
|
(selType.ElTypeNum == Template_EL_head || |
|
selType.ElTypeNum == Template_EL_Template || |
|
selType.ElTypeNum == Template_EL_component)) |
|
parent = selElem; |
|
else |
|
{ |
|
selType.ElSSchema = sstempl; |
|
selType.ElTypeNum = Template_EL_head; |
|
parent = TtaGetExactTypedAncestor (selElem, selType); |
|
if (parent == NULL) |
|
{ |
|
selType.ElTypeNum = Template_EL_Template; |
|
parent = TtaGetExactTypedAncestor (selElem, selType); |
|
} |
|
if (parent == NULL) |
|
return NULL; |
|
selType.ElTypeNum = Template_EL_component; |
|
prev = TtaGetExactTypedAncestor (selElem, selType); |
|
} |
|
|
|
if (QueryComponentFromUser (buffer, 128)) |
|
{ |
|
compType.ElSSchema = sstempl; |
|
compType.ElTypeNum = Template_EL_component; |
|
comp = TtaNewElement (doc, compType); |
|
if (prev) |
|
TtaInsertSibling (comp, prev, FALSE, doc); |
|
else if (next) |
|
TtaInsertSibling (comp, next, TRUE, doc); |
|
else |
|
TtaInsertFirstChild (&comp, parent, doc); |
|
SetAttributeStringValue (comp, Template_ATTR_name, buffer); |
|
// generate a content |
|
selElem = TtaGetFirstChild (comp); |
|
if (selElem == NULL) |
|
{ |
|
selType.ElSSchema = sstempl; |
|
selType.ElTypeNum = Template_EL_TemplateObject; |
|
selElem = TtaNewElement (doc, selType); |
|
TtaInsertFirstChild (&selElem, comp, doc); |
|
} |
|
TtaRegisterElementCreate (comp, doc); |
|
TtaSelectElement (doc, selElem); |
|
// register document modification |
|
TtaSetDocumentModified (doc); |
|
} |
|
} |
else |
else |
{ |
{ |
if (dispMode == DisplayImmediately) |
if (dispMode == DisplayImmediately) |
Line 2800 Element Template_CreateUseFromSelection
|
Line 2882 Element Template_CreateUseFromSelection
|
if (createComp) |
if (createComp) |
{ |
{ |
// Create a component from selection and a use using it |
// Create a component from selection and a use using it |
comp = Template_CreateComponentFromSelection(doc); |
comp = Template_CreateComponentFromSelection (doc); |
if (comp) |
if (comp) |
{ |
{ |
useType.ElSSchema = sstempl; |
useType.ElSSchema = sstempl; |