Annotation of Amaya/amaya/templates.c, revision 1.64
1.1 cvs 1: /*
2: *
1.27 vatton 3: * COPYRIGHT INRIA and W3C, 1996-2005
1.1 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
1.14 cvs 7:
1.1 cvs 8: /*
1.51 francesc 9: * Authors: Francesc Campoy Flores
1.1 cvs 10: *
11: */
12:
13: #define THOT_EXPORT extern
14: #include "amaya.h"
15: #include "document.h"
1.52 vatton 16:
1.46 vatton 17: #ifdef TEMPLATES
18: #include "Template.h"
1.52 vatton 19: #include "templateDeclarations.h"
1.61 francesc 20: #include "templateLoad.h"
21: #include "templateInstanciation.h"
1.52 vatton 22:
23: struct menuType
24: {
25: char *label;
26: int type;
27: };
28:
1.28 tollenae 29: #include "appdialogue_wx.h"
1.29 tollenae 30: #include "init_f.h"
1.46 vatton 31: #include "wxdialogapi_f.h"
1.60 francesc 32: #include "AHTURLTools_f.h"
33:
1.52 vatton 34: #endif /* TEMPLATES */
1.1 cvs 35:
36: /*----------------------------------------------------------------------
1.51 francesc 37: NewTemplate: Create the "new document from template" dialog
1.1 cvs 38: ----------------------------------------------------------------------*/
1.18 cvs 39: void NewTemplate (Document doc, View view)
1.1 cvs 40: {
1.51 francesc 41: #ifdef TEMPLATES
1.52 vatton 42: char *templateDir = TtaGetEnvString ("TEMPLATES_DIRECTORY");
43: ThotBool created;
1.28 tollenae 44:
1.52 vatton 45: if (templates == NULL)
1.58 francesc 46: InitializeTemplateEnvironment();
1.52 vatton 47: created = CreateNewTemplateDocDlgWX(BaseDialog + OpenTemplate,
1.61 francesc 48: /*TtaGetViewFrame (doc, view)*/NULL, doc,
1.52 vatton 49: TtaGetMessage (AMAYA, AM_NEW_TEMPLATE),templateDir);
1.51 francesc 50:
1.28 tollenae 51: if (created)
1.25 vatton 52: {
1.28 tollenae 53: TtaSetDialoguePosition ();
54: TtaShowDialogue (BaseDialog + OpenTemplate, TRUE);
1.25 vatton 55: }
1.51 francesc 56:
1.52 vatton 57: #endif /* TEMPLATES */
1.1 cvs 58: }
1.25 vatton 59:
1.53 vatton 60: /*----------------------------------------------------------------------
61: Load a template and create the instance file - update images and
62: stylesheets related to the template.
63: ----------------------------------------------------------------------*/
1.61 francesc 64: void CreateInstanceOfTemplate (Document doc, char *templatename, char *docname)
1.53 vatton 65: {
66: #ifdef TEMPLATES
67:
1.60 francesc 68: char *s;
1.61 francesc 69: ThotBool dontRemplace = DontReplaceOldDoc;
1.60 francesc 70:
71: if (!IsW3Path (docname) && TtaFileExist (docname))
72: {
73: s = (char *)TtaGetMemory (strlen (docname) +
74: strlen (TtaGetMessage (AMAYA, AM_OVERWRITE_CHECK)) + 2);
75: sprintf (s, TtaGetMessage (AMAYA, AM_OVERWRITE_CHECK), docname);
76: InitConfirm (0, 0, s);
1.61 francesc 77: TtaFreeMemory (s);
1.62 francesc 78: if (!UserAnswer)
79: return;
80: }
81:
82: LoadTemplate(doc, templatename);
83: DontReplaceOldDoc = dontRemplace;
84: CreateInstance(templatename, docname);
85:
1.53 vatton 86: #endif /* TEMPLATES */
87: }
88:
1.51 francesc 89: #ifdef TEMPLATES
1.52 vatton 90: /*----------------------------------------------------------------------
91: ----------------------------------------------------------------------*/
92: static void giveItems(char *text, int size, struct menuType **items, int *nbitems)
1.1 cvs 93: {
1.52 vatton 94: ThotBool inElement = TRUE;
95: struct menuType *menu;
96: char *iter;
97: char temp[128];
98: int i;
99: int labelSize;
1.28 tollenae 100:
1.52 vatton 101: *nbitems = 1;
102: for (i = 0; i < size; i++)
103: {
104: if (isEOSorWhiteSpace (text[i]))
105: {
106: if (inElement)
107: inElement = FALSE;
108: }
109: else if (!inElement)
110: {
111: inElement = TRUE;
112: (*nbitems)++;
113: }
114: }
1.51 francesc 115:
1.52 vatton 116: menu = (struct menuType*) TtaGetMemory(sizeof(struct menuType)* *nbitems);
117: iter = text;
118: for (i = 0; i < *nbitems; i++)
119: {
120: labelSize = 0;
121: while (isEOSorWhiteSpace (*iter))
122: iter++;
123:
124: while (!isEOSorWhiteSpace (*iter))
125: {
126: temp[labelSize++] = *iter;
127: iter++;
128: }
129:
130: temp[labelSize] = EOS;
131: menu[i].label = (char *) TtaStrdup(temp);
132: menu[i].type = SIMPLE_TYPE;
133: *items = menu;
134: }
1.28 tollenae 135: }
1.37 tollenae 136:
1.52 vatton 137: /*----------------------------------------------------------------------
138: ----------------------------------------------------------------------*/
139: static char *createMenuString (const struct menuType* items, const int nbItems)
140: {
141: char *result, *iter;
142: int size = 0;
143: int i;
144:
145: for (i=0; i < nbItems; i++)
146: size += 2 + strlen (items[i].label);
147:
148: result = (char *) TtaGetMemory(size);
149: iter = result;
150: for (i=0; i < nbItems; i++)
151: {
152: *iter = 'B';
153: ++iter;
1.51 francesc 154:
1.52 vatton 155: strcpy (iter, items[i].label);
156: iter += strlen (items[i].label)+1;
157: }
1.51 francesc 158: return result;
1.36 tollenae 159: }
1.29 tollenae 160:
1.52 vatton 161: #endif /* TEMPLATES */
1.29 tollenae 162:
1.46 vatton 163: /*----------------------------------------------------------------------
1.63 vatton 164: UseMenuClicked
1.51 francesc 165: Shows a menu with all the types that can be used in a use element.
1.46 vatton 166: ----------------------------------------------------------------------*/
1.56 francesc 167: ThotBool UseMenuClicked (NotifyElement *event)
1.39 tollenae 168: {
1.43 tollenae 169: #ifdef TEMPLATES
1.52 vatton 170: Document doc = event->document;
1.63 vatton 171: Element el = event->element;
1.52 vatton 172: ElementType elt = TtaGetElementType(el);
173: Attribute at;
174: AttributeType att;
175: int nbitems, size;
176: struct menuType *items;
177: char *types, *menuString;
1.51 francesc 178:
179: att.AttrSSchema = elt.ElSSchema;
180: att.AttrTypeNum = Template_ATTR_types;
1.52 vatton 181: at = TtaGetAttribute (el, att);
1.51 francesc 182:
1.52 vatton 183: size = TtaGetTextAttributeLength (at);
184: types = (char *) TtaGetMemory (size+1);
185: TtaGiveTextAttributeValue (at, types, &size);
1.39 tollenae 186:
1.52 vatton 187: giveItems (types, size, &items, &nbitems);
188: menuString = createMenuString (items, nbitems);
1.51 francesc 189: TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL,
1.52 vatton 190: nbitems, menuString , NULL, false, 'L');
1.46 vatton 191:
1.51 francesc 192: TtaFreeMemory (menuString);
193: TtaFreeMemory (types);
1.29 tollenae 194:
1.51 francesc 195: TtaShowDialogue (BaseDialog + OptionMenu, FALSE);
196: TtaWaitShowProcDialogue();
197: TtaDestroyDialogue (BaseDialog + OptionMenu);
1.63 vatton 198: return FALSE;
199: #endif /* TEMPLATES */
200: //ReturnOption
201: return TRUE;
202: }
1.42 tollenae 203:
1.63 vatton 204: /*----------------------------------------------------------------------
205: OptionMenuClicked
206: ----------------------------------------------------------------------*/
207: ThotBool OptionMenuClicked (NotifyElement *event)
208: {
209: #ifdef TEMPLATES
210: return FALSE;
1.57 francesc 211: #endif /* TEMPLATES */
1.52 vatton 212: return TRUE;
1.42 tollenae 213: }
1.51 francesc 214:
1.56 francesc 215: /*----------------------------------------------------------------------
1.63 vatton 216: RepeatMenuClicked
1.56 francesc 217: Shows a menu with all the types that can be used in a use element.
218: ----------------------------------------------------------------------*/
1.63 vatton 219: ThotBool RepeatMenuClicked (NotifyElement *event)
1.56 francesc 220: {
221: #ifdef TEMPLATES
1.63 vatton 222: Document doc = event->document;
223: int nbitems, size;
224: struct menuType *items;
225: char *types, *menuString;
226:
227: types = "top end";
228: size = strlen (types);
229: giveItems (types, size, &items, &nbitems);
230: menuString = createMenuString (items, nbitems);
231: TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL,
232: nbitems, menuString , NULL, false, 'L');
233: TtaFreeMemory (menuString);
234: TtaShowDialogue (BaseDialog + OptionMenu, FALSE);
235: TtaWaitShowProcDialogue();
236: TtaDestroyDialogue (BaseDialog + OptionMenu);
237: return FALSE;
1.57 francesc 238: #endif /* TEMPLATES */
1.56 francesc 239: return TRUE;
240: }
1.64 ! francesc 241:
! 242: /*----------------------------------------------------------------------
! 243: ClosingDocument
! 244: Callback called before closing a document. Checks for unused templates.
! 245: ----------------------------------------------------------------------*/
! 246: void ClosingDocument(NotifyDialog* dialog)
! 247: {
! 248: return;
! 249: }
Webmaster