Annotation of Amaya/amaya/init.c, revision 1.1191
1.17 cvs 1: /*
2: *
1.1128 tollenae 3: * (c) COPYRIGHT INRIA and W3C, 1996-2005 *
1.17 cvs 4: * Please first read the full copyright statement in file COPYRIGHT.
5: *
6: */
1.9 cvs 7:
1.26 cvs 8: /*
9: * Initialization functions and button functions of Amaya application.
10: *
11: * Author: I. Vatton
1.576 cvs 12: * R. Guetari (W3C/INRIA) - Windows version
1.26 cvs 13: */
14:
1.6 cvs 15: /* Included headerfiles */
1.333 cvs 16:
1.926 gully 17: #ifdef _WX
18: #include "wx/wx.h"
19: #endif /* _WX */
20:
1.907 gully 21: #undef THOT_EXPORT
22: #define THOT_EXPORT extern /* defined into css.c */
23: #include "amaya.h"
24:
25: #undef THOT_EXPORT
1.331 cvs 26: #define THOT_EXPORT extern
1.6 cvs 27: #include "css.h"
1.18 cvs 28: #include "trans.h"
1.290 cvs 29: #include "zlib.h"
1.352 cvs 30: #include "profiles.h"
1.1034 gully 31: #include "MENUconf.h"
1.592 cvs 32:
33: /*
34: * A VIRER SUREMENT PAR LA SUITE
35: *
36: *
37: *
38: **/
1.337 cvs 39: #ifdef _GTK
1.891 gully 40: #include "gtkdialogapi.h"
41: extern char LostPicturePath [512];
1.337 cvs 42: #endif /* _GTK */
1.919 cvs 43: #ifdef _WINDOWS
1.1033 cvs 44: #include <commctrl.h>
45: extern char LostPicturePath [512];
1.919 cvs 46: #endif /* _WINDOWS */
1.916 cvs 47: #ifdef _WINGUI
1.891 gully 48: #include "resource.h"
1.916 cvs 49: #endif /* _WINGUI */
1.926 gully 50: #ifdef _WX
1.1096 gully 51: #include "message_wx.h"
1.926 gully 52: #include "wxdialogapi_f.h"
1.1007 gully 53: #include "windowtypes_wx.h"
1.1041 gully 54: #include "paneltypes_wx.h"
1.1027 gully 55: #include "registry_wx.h"
1.1062 gully 56: #include "AmayaWindowIterator.h"
1.1070 gully 57: #include "AmayaParams.h"
58:
59: extern XmlEntity *pMathEntityTable;
1.926 gully 60: #endif /* _WX */
61:
1.1076 gully 62: #include "appdialogue_wx.h"
63:
1.1093 gully 64: #if defined(_GTK)
1.6 cvs 65: #include "stopN.xpm"
66: #include "stopR.xpm"
67: #include "save.xpm"
1.290 cvs 68: #include "saveNo.xpm"
1.6 cvs 69: #include "find.xpm"
1.276 cvs 70: #include "Reload.xpm"
71: #include "Print.xpm"
1.6 cvs 72: #include "Back.xpm"
1.143 cvs 73: #include "BackNo.xpm"
1.6 cvs 74: #include "Forward.xpm"
1.143 cvs 75: #include "ForwardNo.xpm"
1.6 cvs 76: #include "I.xpm"
1.276 cvs 77: #include "INo.xpm"
1.6 cvs 78: #include "B.xpm"
1.276 cvs 79: #include "BNo.xpm"
1.6 cvs 80: #include "T.xpm"
1.276 cvs 81: #include "TNo.xpm"
1.6 cvs 82: #include "H1.xpm"
1.276 cvs 83: #include "H1No.xpm"
1.6 cvs 84: #include "H2.xpm"
1.276 cvs 85: #include "H2No.xpm"
1.6 cvs 86: #include "H3.xpm"
1.276 cvs 87: #include "H3No.xpm"
1.6 cvs 88: #include "Num.xpm"
1.276 cvs 89: #include "NumNo.xpm"
1.6 cvs 90: #include "Bullet.xpm"
1.276 cvs 91: #include "BulletNo.xpm"
1.6 cvs 92: #include "Image.xpm"
1.276 cvs 93: #include "ImageNo.xpm"
1.6 cvs 94: #include "DL.xpm"
1.276 cvs 95: #include "DLNo.xpm"
1.29 cvs 96: #include "Link.xpm"
1.276 cvs 97: #include "LinkNo.xpm"
1.29 cvs 98: #include "Table.xpm"
1.276 cvs 99: #include "TableNo.xpm"
1.311 cvs 100: #include "home.xpm"
1.1093 gully 101: #endif /* #if defned(_GTK) */
1.124 cvs 102:
1.916 cvs 103: #ifdef _WINGUI
1.124 cvs 104: /*
1.1136 gully 105: #ifndef __GNUC__
106: #include <direct.h>
107: #endif
1.124 cvs 108: */
1.398 cvs 109: int Window_Curs;
1.547 cvs 110: char DocToOpen[MAX_LENGTH];
1.916 cvs 111: #endif /* _WINGUI */
1.66 cvs 112:
1.360 cvs 113:
1.18 cvs 114: static int AmayaInitialized = 0;
1.503 cvs 115: static ThotBool NewFile = FALSE;
116: static int NewDocType = 0;
1.683 cvs 117: static int NewDocProfile = 0;
1.1114 vatton 118: static ThotBool NewXML = TRUE;
1.830 vatton 119: static ThotBool BADMimeType = FALSE;
1.904 vatton 120: static ThotBool CriticConfirm = FALSE;
1.1177 vatton 121: static ThotBool CriticCheckError = FALSE;
1.678 vatton 122: /* the open document is the Amaya default page */
123: static ThotBool WelcomePage = FALSE;
1.325 cvs 124: /* we have to mark the initial loading status to avoid to re-open the
125: document view twice */
1.445 cvs 126: static int Loading_method = CE_INIT;
1.315 cvs 127:
1.979 gully 128: #if defined(_GTK) || defined(_WX)
1.891 gully 129: static ThotIcon stopR;
130: static ThotIcon stopN;
131: static ThotIcon iconSave;
132: static ThotIcon iconSaveNo;
133: static ThotIcon iconFind;
134: static ThotIcon iconReload;
135: static ThotIcon iconI;
136: static ThotIcon iconINo;
137: static ThotIcon iconB;
138: static ThotIcon iconBNo;
139: static ThotIcon iconT;
140: static ThotIcon iconTNo;
141: static ThotIcon iconImage;
142: static ThotIcon iconImageNo;
143: static ThotIcon iconBack;
144: static ThotIcon iconBackNo;
145: static ThotIcon iconForward;
146: static ThotIcon iconForwardNo;
147: static ThotIcon iconH1;
148: static ThotIcon iconH1No;
149: static ThotIcon iconH2;
150: static ThotIcon iconH2No;
151: static ThotIcon iconH3;
152: static ThotIcon iconH3No;
153: static ThotIcon iconPrint;
154: static ThotIcon iconBullet;
155: static ThotIcon iconBulletNo;
156: static ThotIcon iconNum;
157: static ThotIcon iconNumNo;
158: static ThotIcon iconDL;
159: static ThotIcon iconDLNo;
160: static ThotIcon iconLink;
161: static ThotIcon iconLinkNo;
162: static ThotIcon iconTable;
163: static ThotIcon iconTableNo;
164: static ThotIcon iconHome;
1.1014 vatton 165: #ifdef _WX
1.994 gully 166: static ThotIcon iconLogo;
1.1014 vatton 167: #endif /* _WX */
1.979 gully 168: #endif /* #if defined(_GTK) || defined(_WX) */
1.124 cvs 169:
1.916 cvs 170: #ifdef _WINGUI
1.168 cvs 171: #define stopR 0
1.276 cvs 172: #define stopN 0
1.168 cvs 173: #define iconBack 1
1.276 cvs 174: #define iconBackNo 1
1.168 cvs 175: #define iconForward 2
1.276 cvs 176: #define iconForwardNo 2
177: #define iconReload 3
178: #define iconSave 4
1.290 cvs 179: #define iconSaveNo 4
1.168 cvs 180: #define iconPrint 5
181: #define iconFind 6
1.276 cvs 182: #define iconI 7
183: #define iconINo 7
184: #define iconB 8
185: #define iconBNo 8
1.168 cvs 186: #define iconT 9
1.276 cvs 187: #define iconTNo 9
1.981 vatton 188: #define iconHome 10
1.276 cvs 189: #define iconImage 11
190: #define iconImageNo 11
1.214 cvs 191: #define iconH1 12
1.276 cvs 192: #define iconH1No 12
193: #define iconH2 13
1.279 cvs 194: #define iconH2No 13
1.214 cvs 195: #define iconH3 14
1.279 cvs 196: #define iconH3No 14
1.214 cvs 197: #define iconBullet 15
1.279 cvs 198: #define iconBulletNo 15
1.214 cvs 199: #define iconNum 16
1.276 cvs 200: #define iconNumNo 16
1.214 cvs 201: #define iconDL 17
1.276 cvs 202: #define iconDLNo 17
1.214 cvs 203: #define iconLink 18
1.276 cvs 204: #define iconLinkNo 18
1.214 cvs 205: #define iconTable 19
1.276 cvs 206: #define iconTableNo 19
1.315 cvs 207:
208: extern int menu_item;
1.273 cvs 209:
210: #include "wininclude.h"
1.916 cvs 211: #endif /* _WINGUI */
1.568 cvs 212: #include "AHTURLTools_f.h"
1.18 cvs 213: #include "css_f.h"
214: #include "EDITORactions_f.h"
215: #include "EDITimage_f.h"
1.27 cvs 216: #include "EDITstyle_f.h"
1.565 cvs 217: #include "fetchXMLname_f.h"
1.652 vatton 218: #ifdef _SVG
1.653 vatton 219: #include "SVGedit_f.h"
1.652 vatton 220: #endif /* _SVG */
1.18 cvs 221: #include "HTMLactions_f.h"
1.66 cvs 222: #include "HTMLbook_f.h"
1.29 cvs 223: #include "HTMLedit_f.h"
1.57 cvs 224: #include "HTMLhistory_f.h"
1.43 cvs 225: #include "HTMLimage_f.h"
1.18 cvs 226: #include "HTMLsave_f.h"
1.920 vatton 227: #include "HTMLtable_f.h"
1.568 cvs 228: #include "html2thot_f.h"
229: #include "Mathedit_f.h"
1.304 cvs 230: #include "MENUconf_f.h"
1.568 cvs 231: #include "init_f.h"
232: #include "query_f.h"
1.289 cvs 233: #include "styleparser_f.h"
1.313 cvs 234: #include "templates_f.h"
1.568 cvs 235: #include "trans_f.h"
1.421 cvs 236: #include "transparse_f.h"
1.568 cvs 237: #include "UIcss_f.h"
1.575 cvs 238: #include "string.h"
1.477 cvs 239: #include "Xml2thot_f.h"
1.1043 vatton 240: #include "XPointer_f.h"
241: #include "anim_f.h"
242: #include "animbuilder_f.h"
243: #include "libmanag_f.h"
244: #ifdef ANNOTATIONS
245: #include "annotlib.h"
246: #include "ANNOTevent_f.h"
247: #include "ANNOTfiles_f.h"
248: #include "ANNOTtools_f.h"
249: #endif /* ANNOTATIONS */
250: #ifdef BOOKMARKS
251: #include "BMevent_f.h"
252: #endif /* BOOKMARKS */
253: #ifdef _WX
254: #include "wxdialogapi_f.h"
255: #endif /* _WX */
256:
1.749 kirschpi 257: #ifdef DAV
1.909 gully 258: #define WEBDAV_EXPORT extern
1.749 kirschpi 259: #include "davlib.h"
260: #include "davlib_f.h"
261: #include "davlibRequests_f.h"
262: #include "davlibUI_f.h"
263: #endif /* DAV */
264:
1.273 cvs 265: extern void InitMathML ();
266:
1.222 cvs 267: /* the structure used for storing the context of the
1.751 vatton 268: GetAmayaDoc_callback function */
1.924 vatton 269: typedef struct _AmayaDoc_context
1.547 cvs 270: {
1.398 cvs 271: Document doc;
272: Document baseDoc;
273: ThotBool history;
274: ThotBool local_link;
1.547 cvs 275: char *target;
1.924 vatton 276: char *documentname; /* the document name */
277: char *initial_url; /* initial loaded URL */
1.547 cvs 278: char *form_data;
1.1190 vatton 279: int method;
1.824 vatton 280: ThotBool inNewWindow;
1.547 cvs 281: TTcbf *cbf;
282: void *ctx_cbf;
1.924 vatton 283: } AmayaDoc_context;
1.177 cvs 284:
1.222 cvs 285: /* the structure used for storing the context of the
286: Reload_callback function */
1.547 cvs 287: typedef struct _RELOAD_context
288: {
1.1184 vatton 289: Document newdoc;
290: char *documentname;
291: char *form_data;
1.1190 vatton 292: int method;
1.1184 vatton 293: int position; /* volume preceding the the first element to be shown */
294: int distance; /* distance from the top of the window to the top of this
1.1136 gully 295: element (% of the window height) */
1.1184 vatton 296: int visibility; /* register the current visibility */
297: ThotBool maparea; /* register the current maparea */
1.222 cvs 298: } RELOAD_context;
1.96 cvs 299:
1.507 cvs 300: typedef enum
1.1136 gully 301: {
302: OpenDocBrowser,
303: HrefAttrBrowser,
304: DocSaveBrowser
305: } TypeBrowserFile;
1.507 cvs 306: TypeBrowserFile WidgetParent;
307:
1.626 vatton 308:
1.9 cvs 309: /*----------------------------------------------------------------------
1.1136 gully 310: DocumentMetaDataAlloc
311: Creates a DocumentMeta element and initializes it to its default
312: values.
1.552 kahan 313: ----------------------------------------------------------------------*/
1.586 cvs 314: DocumentMetaDataElement *DocumentMetaDataAlloc (void)
1.552 kahan 315: {
316: DocumentMetaDataElement *me;
317:
318: me = (DocumentMetaDataElement *) TtaGetMemory (sizeof (DocumentMetaDataElement));
319: memset ((void *) me, 0, sizeof (DocumentMetaDataElement));
320: me->method = CE_ABSOLUTE;
321: return (me);
322: }
323:
324: /*----------------------------------------------------------------------
1.1136 gully 325: DocumentMetaClear
326: Clears the dynamically allocated memory associated to a metadata
327: element. Doesn't free the element or clears any of its other elements.
1.471 kahan 328: ----------------------------------------------------------------------*/
1.586 cvs 329: void DocumentMetaClear (DocumentMetaDataElement *me)
1.471 kahan 330: {
1.602 kahan 331: if (!me)
332: return;
333:
1.1188 vatton 334: TtaFreeMemory (me->form_data);
335: me->form_data = NULL;
336: TtaFreeMemory (me->initial_url);
337: me->initial_url = NULL;
338: TtaFreeMemory (me->content_type);
339: me->content_type = NULL;
340: TtaFreeMemory (me->charset);
341: me->charset = NULL;
342: TtaFreeMemory (me->content_length);
343: me->content_length = NULL;
344: TtaFreeMemory (me->content_location);
345: me->content_location = NULL;
346: TtaFreeMemory (me->full_content_location);
347: me->full_content_location = NULL;
348: TtaFreeMemory (me->reason);
349: me->reason = NULL;
1.471 kahan 350: }
351:
1.549 cvs 352: /*----------------------------------------------------------------------
1.1136 gully 353: DocumentTypeString
354: Returns a string that represents the document type or the current
355: profile.
1.694 kahan 356: ----------------------------------------------------------------------*/
357: char * DocumentTypeString (Document document)
358: {
359: char *result;
1.695 kahan 360: ThotBool isXml;
1.694 kahan 361:
362: result = NULL;
363: switch (DocumentTypes[document])
364: {
365: case docText:
366: result = "Text file";
367: break;
368: case docImage:
369: result = "Image";
370: case docCSS:
1.695 kahan 371: result = "CSS style sheet";
1.694 kahan 372: break;
373: case docSource:
374: result = "Document source";
375: break;
376: case docAnnot:
377: result = "Annotation";
378: break;
379: case docLog:
1.695 kahan 380: result = "Log file";
1.694 kahan 381: break;
382: case docSVG:
383: result = "SVG";
384: break;
385: case docXml:
1.695 kahan 386: result = "XML";
1.694 kahan 387: break;
1.765 cvs 388: case docLibrary:
389: result = "HTML";
390: break;
1.694 kahan 391: default:
392: break;
393: }
394:
1.709 quint 395: if (!result && DocumentMeta[document]) /* try the profiles */
1.694 kahan 396: {
1.695 kahan 397: isXml = DocumentMeta[document]->xmlformat;
1.694 kahan 398: switch (TtaGetDocumentProfile (document))
1.1136 gully 399: {
400: case L_Other:
401: result = "Unknown";
402: break;
403: case L_Xhtml11:
404: result = "XHTML 1.1";
405: break;
406: case L_Basic:
407: result = "XHTML 1.0 Basic";
408: break;
409: case L_Strict:
410: if (isXml)
411: result = "XHTML 1.0 Strict";
412: else
413: result = "HTML Strict";
414: break;
415: case L_Transitional:
416: if (isXml)
417: result = "XHTML 1.0 Transitional";
418: else
419: result = "HTML Transitional";
420: break;
421: case L_MathML:
422: result = "MathML";
423: break;
424: }
1.694 kahan 425: }
426:
427: return (result);
428: }
429:
430: /*----------------------------------------------------------------------
1.1136 gully 431: DocumentInfo
432: Displays the document informations given by the header
1.549 cvs 433: ----------------------------------------------------------------------*/
1.574 cvs 434: void DocumentInfo (Document document, View view)
1.549 cvs 435: {
1.979 gully 436: #if defined(_GTK)
1.575 cvs 437: char *content;
1.562 kahan 438:
1.554 cvs 439: /* Main form */
1.1136 gully 440: TtaNewSheet (BaseDialog + DocInfoForm, TtaGetViewFrame (document, 1),
441: "Document Information",
442: 0, NULL, FALSE, 8, 'L', D_DONE);
443:
444: /* Document information labels */
445: TtaNewLabel (BaseDialog + DocInfoTitle1,
446: BaseDialog + DocInfoForm,
447: "________________");
448:
449: /* Document URL */
450: TtaNewLabel (BaseDialog + DocInfoURLTitle,
451: BaseDialog + DocInfoForm,
452: TtaGetMessage (AMAYA, AM_HREF_VALUE));
453:
454: /* Document type */
455: TtaNewLabel (BaseDialog + DocInfoDocTypeTitle,
456: BaseDialog + DocInfoForm,
457: "Document Type");
458:
459: /* Mime Type */
460: TtaNewLabel (BaseDialog + DocInfoMimeTypeTitle,
461: BaseDialog + DocInfoForm,
462: "MIME Type");
463: /* Charset */
464: TtaNewLabel (BaseDialog + DocInfoCharsetTitle,
465: BaseDialog + DocInfoForm,
466: "Charset");
467:
468: /* Content Length */
469: TtaNewLabel (BaseDialog + DocInfoContentTitle,
470: BaseDialog + DocInfoForm,
471: "Content Length");
472:
473: /* Content Location */
474: TtaNewLabel (BaseDialog + DocInfoLocationTitle,
475: BaseDialog + DocInfoForm,
476: "Content Location");
477:
478: TtaNewLabel (BaseDialog + DocInfoTitle2,
479: BaseDialog + DocInfoForm,
480: "________________");
481:
482: /* Document information contents */
483: TtaNewLabel (BaseDialog + DocInfoContent1,
484: BaseDialog + DocInfoForm,
485: "___________________________________________");
486: /* Document URL */
487: if (DocumentURLs[document] != NULL)
488: content = DocumentURLs[document];
489: else
490: content = TtaGetMessage (AMAYA, AM_UNKNOWN);
491: TtaNewLabel (BaseDialog + DocInfoURL,
492: BaseDialog + DocInfoForm, content);
493:
494: /* Document Type */
495: content = DocumentTypeString (document);
496: if (!content)
497: content = TtaGetMessage (AMAYA, AM_UNKNOWN);
498: TtaNewLabel (BaseDialog + DocInfoDocType,
499: BaseDialog + DocInfoForm, content);
500:
501: /* Mime Type */
502: if (DocumentMeta[document] && DocumentMeta[document]->content_type)
503: content = DocumentMeta[document]->content_type;
504: else
505: content = TtaGetMessage (AMAYA, AM_UNKNOWN);
506: TtaNewLabel (BaseDialog + DocInfoMimeType,
507: BaseDialog + DocInfoForm, content);
508:
509: /* Charset */
510: if (DocumentMeta[document] && DocumentMeta[document]->charset != NULL)
511: content = DocumentMeta[document]->charset;
512: else
513: content = TtaGetMessage (AMAYA, AM_UNKNOWN);
514: TtaNewLabel (BaseDialog + DocInfoCharset,
515: BaseDialog + DocInfoForm, content);
516:
517: /* Content Length */
518: if (DocumentMeta[document] && DocumentMeta[document]->content_length)
519: content = DocumentMeta[document]->content_length;
520: else
521: content = TtaGetMessage (AMAYA, AM_UNKNOWN);
522: TtaNewLabel (BaseDialog + DocInfoContent,
523: BaseDialog + DocInfoForm, content);
524:
525: /* Content Location */
526: if (DocumentMeta[document]
527: && DocumentMeta[document]->full_content_location != NULL)
528: content = DocumentMeta[document]->full_content_location;
529: else
530: content = TtaGetMessage (AMAYA, AM_UNKNOWN);
531: TtaNewLabel (BaseDialog + DocInfoLocation,
532: BaseDialog + DocInfoForm, content);
533:
534: /* end of dialogue */
535: TtaNewLabel (BaseDialog + DocInfoContent2,
536: BaseDialog + DocInfoForm,
537: "___________________________________________");
1.551 kahan 538:
1.1136 gully 539: TtaSetDialoguePosition ();
540: TtaShowDialogue (BaseDialog + DocInfoForm, TRUE);
1.979 gully 541: #endif /* #if defined(_GTK) */
1.891 gully 542:
1.916 cvs 543: #ifdef _WINGUI
1.1136 gully 544: CreateDocumentInfoDlgWindow (TtaGetViewFrame (document, view),
545: document);
1.916 cvs 546: #endif /* _WINGUI */
1.1031 carcone 547: #ifdef _WX
1.1045 vatton 548: ThotBool created = CreateDocInfoDlgWX (BaseDialog + DocInfoForm,
1.1136 gully 549: TtaGetViewFrame (document, view), document);
1.1031 carcone 550: if (created)
551: {
552: TtaSetDialoguePosition ();
553: TtaShowDialogue (BaseDialog + DocInfoForm, FALSE);
554: /* wait for an answer */
555: TtaWaitShowDialogue ();
556: }
557: #endif /* _WX */
1.549 cvs 558: }
1.471 kahan 559:
560: /*----------------------------------------------------------------------
1.1136 gully 561: IsDocumentLoaded returns the document identification if the
562: corresponding document is already loaded or 0.
1.9 cvs 563: ----------------------------------------------------------------------*/
1.586 cvs 564: Document IsDocumentLoaded (char *documentURL, char *form_data)
1.6 cvs 565: {
1.398 cvs 566: int i;
567: ThotBool found;
1.293 cvs 568:
569: if (!documentURL)
570: return ((Document) None);
1.222 cvs 571:
1.293 cvs 572: i = 1;
573: found = FALSE;
574: /* look for the URL into the list of downloaded documents */
575: while (!found && i < DocumentTableLength)
576: {
577: if (DocumentURLs[i])
1.1136 gully 578: {
579: /* compare the url */
580: found = (!strcmp (documentURL, DocumentURLs[i]) ||
581: (DocumentMeta[i]->initial_url &&
582: !strcmp (documentURL, DocumentMeta[i]->initial_url)));
583: /* compare the form_data */
584: if (found && (!((!form_data && !DocumentMeta[i]->form_data) ||
585: (form_data && DocumentMeta[i]->form_data &&
586: !strcmp (form_data, DocumentMeta[i]->form_data)))))
587: found = FALSE;
588: }
1.293 cvs 589: if (!found)
1.1136 gully 590: i++;
1.293 cvs 591: }
592:
593: if (found)
594: /* document is found */
595: return ((Document) i);
596: else
1.405 cvs 597: /* document is not found */
1.293 cvs 598: return ((Document) None);
1.6 cvs 599: }
600:
1.146 cvs 601: /*----------------------------------------------------------------------
1.1136 gully 602: ExtractParameters extract parameters from document nane.
1.9 cvs 603: ----------------------------------------------------------------------*/
1.878 vatton 604: void ExtractParameters (char *aName, char *parameters)
1.6 cvs 605: {
1.1143 cvs 606: long int lg, i;
1.1136 gully 607: char *ptr;
608: char *oldptr;
609:
610: if (!parameters || !aName)
611: /* bad parameters */
612: return;
613:
614: parameters[0] = EOS;
615: lg = strlen (aName);
616: if (lg)
617: {
618: /* the name is not empty */
619: oldptr = ptr = &aName[0];
620: do
621: {
622: ptr = strrchr (oldptr, '?');
623: if (ptr)
624: oldptr = &ptr[1];
625: }
626: while (ptr);
627:
1.1143 cvs 628: i = (long int) (oldptr) - (long int) (aName); /* name length */
1.1136 gully 629: if (i > 1)
630: {
631: aName[i - 1] = EOS;
632: if (i != lg)
633: strcpy (parameters, oldptr);
634: }
635: }
1.6 cvs 636: }
637:
1.451 kahan 638: /*----------------------------------------------------------------------
1.1136 gully 639: FileExistTarget
640: Removes the URL target separator ('#') before verifying if a file
641: exists.
1.451 kahan 642: ----------------------------------------------------------------------*/
1.547 cvs 643: static ThotBool FileExistTarget (char *filename)
1.451 kahan 644: {
1.547 cvs 645: char *ptr;
1.451 kahan 646: ThotBool result;
647:
1.547 cvs 648: ptr = strrchr (filename, '#');
1.451 kahan 649: if (ptr)
1.547 cvs 650: *ptr = EOS;
1.1121 gully 651: result = TtaFileExist(filename);
1.451 kahan 652: if (ptr)
1.547 cvs 653: *ptr = '#';
1.451 kahan 654: return result;
655: }
1.6 cvs 656:
1.9 cvs 657: /*----------------------------------------------------------------------
1.143 cvs 658: SetArrowButton
659: Change the appearance of the Back (if back == TRUE) or Forward button
660: for a given document.
661: ----------------------------------------------------------------------*/
1.1132 vatton 662: void SetArrowButton (Document doc, ThotBool back, ThotBool on)
1.143 cvs 663: {
1.171 cvs 664: int index;
1.309 cvs 665: ThotBool state;
1.276 cvs 666: ThotIcon picture;
1.143 cvs 667:
1.171 cvs 668: if (back)
669: {
1.974 gully 670: index = iBack;
1.171 cvs 671: if (on)
1.1136 gully 672: {
673: state = TRUE;
674: picture = iconBack;
675: TtaSetItemOn (doc, 1, File, BBack);
676: if (DocumentSource[doc])
677: /* update the document source too */
678: TtaSetItemOn (DocumentSource[doc], 1, File, BBack);
679: }
1.171 cvs 680: else
1.1136 gully 681: {
1.169 cvs 682: state = FALSE;
1.1136 gully 683: picture = iconBackNo;
684: TtaSetItemOff (doc, 1, File, BBack);
685: if (DocumentSource[doc])
686: /* update the document source too */
687: TtaSetItemOff (DocumentSource[doc], 1, File, BBack);
688: }
1.171 cvs 689: }
690: else
691: {
1.974 gully 692: index = iForward;
1.171 cvs 693: if (on)
1.1136 gully 694: {
695: state = TRUE;
696: picture = iconForward;
697: TtaSetItemOn (doc, 1, File, BForward);
698: if (DocumentSource[doc])
699: /* update the document source too */
700: TtaSetItemOn (DocumentSource[doc], 1, File, BForward);
701: }
702: else
703: {
704: state = FALSE;
705: picture = iconForwardNo;
706: TtaSetItemOff (doc, 1, File, BForward);
707: if (DocumentSource[doc])
708: /* update the document source too */
709: TtaSetItemOff (DocumentSource[doc], 1, File, BForward);
710: }
1.171 cvs 711: }
1.1084 gully 712: #ifndef _WX
1.1132 vatton 713: TtaChangeButton (doc, 1, index, picture, state);
714: if (DocumentSource[doc])
715: TtaChangeButton (DocumentSource[doc], 1, index, picture, state);
1.1084 gully 716: #endif /* _WX */
1.171 cvs 717: }
718:
719: /*----------------------------------------------------------------------
1.1136 gully 720: ResetStop resets the stop button state
1.171 cvs 721: ----------------------------------------------------------------------*/
1.692 vatton 722: void ResetStop (Document document)
1.171 cvs 723: {
1.836 vatton 724: if (document)
1.171 cvs 725: {
1.836 vatton 726: if (FilesLoading[document] != 0)
1.1136 gully 727: FilesLoading[document]--;
1.836 vatton 728: if (FilesLoading[document] == 0)
1.1136 gully 729: /* The last object associated to the document has been loaded */
730: {
731: if (TtaGetViewFrame (document, 1) != 0)
732: /* this document is displayed */
733: {
734: if(!(DocNetworkStatus[document] & AMAYA_NET_ERROR) &&
735: (DocNetworkStatus[document] & AMAYA_NET_ACTIVE))
736: /* if there was no error message, display the LOADED message */
737: TtaSetStatus (document, 1,
738: TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
1.1084 gully 739: #ifndef _WX
1.1136 gully 740: TtaChangeButton (document, 1, iStop, stopN, FALSE);
1.1084 gully 741: #else /* _WX */
1.1136 gully 742: TtaEnableAction(document, "StopTransfer", FALSE);
1.1084 gully 743: #endif /* _WX */
1.1136 gully 744: }
745: DocNetworkStatus[document] = AMAYA_NET_INACTIVE;
746: }
1.171 cvs 747: }
1.143 cvs 748: }
749:
750: /*----------------------------------------------------------------------
1.1136 gully 751: ActiveTransfer initialize the current transfer
1.9 cvs 752: ----------------------------------------------------------------------*/
1.836 vatton 753: void ActiveTransfer (Document document)
1.6 cvs 754: {
1.836 vatton 755: if (document)
756: {
757: DocNetworkStatus[document] = AMAYA_NET_ACTIVE;
758: FilesLoading[document] = 1;
759: if (TtaGetViewFrame (document, 1) != 0)
1.1136 gully 760: /* this document is displayed */
1.1084 gully 761: #ifndef _WX
1.1136 gully 762: TtaChangeButton (document, 1, iStop, stopR, TRUE);
1.1084 gully 763: #else /* _WX */
1.1136 gully 764: TtaEnableAction(document, "StopTransfer", TRUE);
1.1084 gully 765: #endif /* _WX */
1.836 vatton 766: }
1.6 cvs 767: }
768:
1.73 cvs 769: /*----------------------------------------------------------------------
1.1136 gully 770: SetStopButton Activates the stop button if it's turned off
1.192 cvs 771: ----------------------------------------------------------------------*/
1.836 vatton 772: void SetStopButton (Document document)
1.192 cvs 773: {
1.836 vatton 774: if (document)
1.396 cvs 775: {
1.836 vatton 776: if (document != DocBook)
1.1136 gully 777: {
778: if (DocNetworkStatus[document] != AMAYA_NET_ACTIVE)
779: DocNetworkStatus[document] = AMAYA_NET_ACTIVE;
780: if (FilesLoading[document] == 0)
781: FilesLoading[document] = 1;
782: }
1.836 vatton 783:
784: if (TtaGetViewFrame (document, 1) != 0)
1.1084 gully 785: #ifndef _WX
1.1136 gully 786: /* this document is displayed */
787: TtaChangeButton (document, 1, iStop, stopR, TRUE);
1.1084 gully 788: #else /* _WX */
1.1136 gully 789: TtaEnableAction(document, "StopTransfer", TRUE);
1.1084 gully 790: #endif /* _WX */
1.396 cvs 791: }
1.192 cvs 792: }
1.249 cvs 793:
794:
795: /*----------------------------------------------------------------------
1.1136 gully 796: SetFormReadWrite
797: Set ReadWrite access to input elements
1.249 cvs 798: ----------------------------------------------------------------------*/
1.836 vatton 799: static void SetFormReadWrite (Element el, Document doc)
1.249 cvs 800: {
1.1136 gully 801: ElementType elType;
802: Element child, next;
1.249 cvs 803:
1.1136 gully 804: while (el)
805: {
806: /* look at all elements within this form */
807: elType = TtaGetElementType (el);
808: child = TtaGetFirstChild (el);
809: next = el;
810: TtaNextSibling (&next);
811: switch (elType.ElTypeNum)
812: {
813: case HTML_EL_Input:
814: case HTML_EL_Text_Input:
815: case HTML_EL_Password_Input:
816: case HTML_EL_File_Input:
817: case HTML_EL_Option:
818: case HTML_EL_Text_Area: /* it's a Text_Area */
819: TtaSetAccessRight (child, ReadWrite, doc);
820: child = NULL;
821: break;
822: default:
823: break;
824: }
825: if (child != NULL)
826: SetFormReadWrite (child, doc);
827: el = next;
828: }
1.249 cvs 829: }
830:
831:
832: /*----------------------------------------------------------------------
1.1136 gully 833: Update the save button and the corresponding menu entry according to the
834: document status.
1.310 cvs 835: ----------------------------------------------------------------------*/
1.791 vatton 836: void DocStatusUpdate (Document doc, ThotBool modified)
1.310 cvs 837: {
1.352 cvs 838: Document otherDoc;
839:
1.791 vatton 840: if (modified && TtaGetDocumentAccessMode (doc))
1.479 cvs 841: /* the document has been modified and is not in Read-Only mode */
1.310 cvs 842: {
1.1136 gully 843: TtaSetItemOn (doc, 1, File, BSave);
1.1084 gully 844: #ifndef _WX
1.1136 gully 845: TtaChangeButton (doc, 1, iSave, iconSave, TRUE);
1.1084 gully 846: #endif /* _WX */
1.479 cvs 847: /* if we have a pair source/structured document allow synchronization */
1.1136 gully 848: otherDoc = DocumentSource[doc];
849: if (!otherDoc)
850: otherDoc = GetDocFromSource (doc);
851: if (otherDoc)
852: {
853: TtaSetItemOn (doc, 1, File, BSynchro);
854: TtaSetItemOn (otherDoc, 1, File, BSynchro);
855: }
856: else if (DocumentTypes[doc] == docCSS)
857: TtaSetItemOn (doc, 1, File, BSynchro);
1.310 cvs 858: }
859: else
1.880 quint 860: /* the document is no longer modified */
1.310 cvs 861: {
1.880 quint 862: TtaSetItemOff (doc, 1, File, BSave);
1.1084 gully 863: #ifndef _WX
1.1090 gully 864: TtaChangeButton (doc, 1, iSave, iconSaveNo, FALSE);
1.1084 gully 865: #endif /* _WX */
1.791 vatton 866: if (TtaIsDocumentUpdated (doc))
1.1136 gully 867: {
868: /* if we have a pair source/structured document allow synchronization */
869: otherDoc = DocumentSource[doc];
870: if (!otherDoc)
871: otherDoc = GetDocFromSource (doc);
872: if (otherDoc)
873: {
1.1168 cvs 874: TtaSetItemOn (doc, 1, File, BSynchro);
875: TtaSetItemOn (otherDoc, 1, File, BSynchro);
876: }
877: else if (DocumentTypes[doc] == docCSS)
878: TtaSetItemOn (doc, 1, File, BSynchro);
879: }
880: else
881: {
882: /* if we have a pair source/structured document allow synchronization */
883: otherDoc = DocumentSource[doc];
884: if (!otherDoc)
885: otherDoc = GetDocFromSource (doc);
886: if (otherDoc)
887: {
1.1136 gully 888: TtaSetItemOff (doc, 1, File, BSynchro);
889: TtaSetItemOff (otherDoc, 1, File, BSynchro);
890: }
891: else if (DocumentTypes[doc] == docCSS)
892: TtaSetItemOff (doc, 1, File, BSynchro);
1.1168 cvs 893: }
1.310 cvs 894: }
895: }
1.249 cvs 896:
897: /*----------------------------------------------------------------------
1.951 vatton 898: SetCharsetMenuOff sets Off the charset menu in the current view.
899: ----------------------------------------------------------------------*/
900: static void SetCharsetMenuOff (Document doc, View view)
901: {
902: TtaSetItemOff (doc, view, File, BUTF_8);
903: TtaSetItemOff (doc, view, File, BISO_8859_1);
904: TtaSetItemOff (doc, view, File, BISO_8859_15);
905: TtaSetItemOff (doc, view, File, BWINDOWS_1252);
906: TtaSetItemOff (doc, view, File, BISO_8859_2);
907: TtaSetItemOff (doc, view, File, BWINDOWS_1250);
908: TtaSetItemOff (doc, view, File, BISO_8859_3);
909: TtaSetItemOff (doc, view, File, BISO_8859_4);
910: TtaSetItemOff (doc, view, File, BWINDOWS_1257);
911: TtaSetItemOff (doc, view, File, BISO_8859_5);
912: TtaSetItemOff (doc, view, File, BWINDOWS_1251);
913: TtaSetItemOff (doc, view, File, BKOI8_R);
914: TtaSetItemOff (doc, view, File, BISO_8859_6);
915: TtaSetItemOff (doc, view, File, BWINDOWS_1256);
916: TtaSetItemOff (doc, view, File, BISO_8859_7);
917: TtaSetItemOff (doc, view, File, BWINDOWS_1253);
918: TtaSetItemOff (doc, view, File, BISO_8859_8);
919: TtaSetItemOff (doc, view, File, BWINDOWS_1255);
920: TtaSetItemOff (doc, view, File, BISO_8859_9);
921: TtaSetItemOff (doc, view, File, BWINDOWS_1254);
1.1163 vatton 922: TtaSetItemOff (doc, view, File, BGB_2312);
1.951 vatton 923: TtaSetItemOff (doc, view, File, BISO_2022_JP);
924: TtaSetItemOff (doc, view, File, BEUC_JP);
925: TtaSetItemOff (doc, view, File, BSHIFT_JIS);
926: }
927:
928: /*----------------------------------------------------------------------
1.950 vatton 929: SetTableMenuOff sets Off the table menu in the current view.
930: ----------------------------------------------------------------------*/
931: void SetTableMenuOff (Document doc, View view)
932: {
933: TtaSetItemOff (doc, view, Types, BCaption);
934: TtaSetItemOff (doc, view, Types, BColgroup);
935: TtaSetItemOff (doc, view, Types, BCol);
936: TtaSetItemOff (doc, view, Types, BTHead);
937: TtaSetItemOff (doc, view, Types, BTBody);
938: TtaSetItemOff (doc, view, Types, BTFoot);
939: TtaSetItemOff (doc, view, Types, BDataCell);
940: TtaSetItemOff (doc, view, Types, BHeadingCell);
941: TtaSetItemOff (doc, view, Types, BCellHExtend);
942: TtaSetItemOff (doc, view, Types, BCellVExtend);
943: TtaSetItemOff (doc, view, Types, BCellHShrink);
944: TtaSetItemOff (doc, view, Types, BCellVShrink);
945: TtaSetItemOff (doc, view, Types, BSelectRow);
946: TtaSetItemOff (doc, view, Types, BCreateRowB);
947: TtaSetItemOff (doc, view, Types, BCreateRowA);
948: TtaSetItemOff (doc, view, Types, BSelectColumn);
949: TtaSetItemOff (doc, view, Types, BCreateColumnB);
950: TtaSetItemOff (doc, view, Types, BCreateColumnA);
951: TtaSetItemOff (doc, view, Types, BPasteBefore);
952: TtaSetItemOff (doc, view, Types, BPasteAfter);
953: TtaSetItemOff (doc, view, XMLTypes, BMCellHExtend);
954: TtaSetItemOff (doc, view, XMLTypes, BMCellVExtend);
955: TtaSetItemOff (doc, view, XMLTypes, BMCellHShrink);
956: TtaSetItemOff (doc, view, XMLTypes, BMCellVShrink);
957: TtaSetItemOff (doc, view, XMLTypes, BMSelectRow);
958: TtaSetItemOff (doc, view, XMLTypes, BMCreateRowB);
959: TtaSetItemOff (doc, view, XMLTypes, BMCreateRowA);
960: TtaSetItemOff (doc, view, XMLTypes, BMSelectColumn);
961: TtaSetItemOff (doc, view, XMLTypes, BMCreateColumnB);
962: TtaSetItemOff (doc, view, XMLTypes, BMCreateColumnA);
963: TtaSetItemOff (doc, view, XMLTypes, BMPasteBefore);
964: TtaSetItemOff (doc, view, XMLTypes, BMPasteAfter);
965: }
966:
967: /*----------------------------------------------------------------------
1.1158 vatton 968: SetTableMenuOn sets On the table menu in the current view.
1.950 vatton 969: ----------------------------------------------------------------------*/
970: void SetTableMenuOn (Document doc, View view)
971: {
972: if (TableMenuActive)
973: {
974: /* a table element is selected */
975: TtaSetItemOn (doc, view, Types, BCaption);
976: TtaSetItemOn (doc, view, Types, BColgroup);
977: TtaSetItemOn (doc, view, Types, BCol);
978: TtaSetItemOn (doc, view, Types, BTHead);
979: TtaSetItemOn (doc, view, Types, BTBody);
980: TtaSetItemOn (doc, view, Types, BTFoot);
981: TtaSetItemOn (doc, view, Types, BDataCell);
982: TtaSetItemOn (doc, view, Types, BHeadingCell);
983: TtaSetItemOn (doc, view, Types, BCellHExtend);
984: TtaSetItemOn (doc, view, Types, BCellVExtend);
985: TtaSetItemOn (doc, view, Types, BCellHShrink);
986: TtaSetItemOn (doc, view, Types, BCellVShrink);
987: TtaSetItemOn (doc, view, Types, BSelectRow);
988: TtaSetItemOn (doc, view, Types, BCreateRowB);
989: TtaSetItemOn (doc, view, Types, BCreateRowA);
990: TtaSetItemOn (doc, view, Types, BSelectColumn);
991: TtaSetItemOn (doc, view, Types, BCreateColumnB);
992: TtaSetItemOn (doc, view, Types, BCreateColumnA);
993: }
1.952 vatton 994: else
995: {
996: TtaSetItemOff (doc, view, Types, BCaption);
997: TtaSetItemOff (doc, view, Types, BColgroup);
998: TtaSetItemOff (doc, view, Types, BCol);
999: TtaSetItemOff (doc, view, Types, BTHead);
1000: TtaSetItemOff (doc, view, Types, BTBody);
1001: TtaSetItemOff (doc, view, Types, BTFoot);
1002: TtaSetItemOff (doc, view, Types, BDataCell);
1003: TtaSetItemOff (doc, view, Types, BHeadingCell);
1004: TtaSetItemOff (doc, view, Types, BCellHExtend);
1005: TtaSetItemOff (doc, view, Types, BCellVExtend);
1006: TtaSetItemOff (doc, view, Types, BCellHShrink);
1007: TtaSetItemOff (doc, view, Types, BCellVShrink);
1008: TtaSetItemOff (doc, view, Types, BSelectRow);
1009: TtaSetItemOff (doc, view, Types, BCreateRowB);
1010: TtaSetItemOff (doc, view, Types, BCreateRowA);
1011: TtaSetItemOff (doc, view, Types, BSelectColumn);
1012: TtaSetItemOff (doc, view, Types, BCreateColumnB);
1013: TtaSetItemOff (doc, view, Types, BCreateColumnA);
1014: TtaSetItemOff (doc, view, Types, BPasteBefore);
1015: TtaSetItemOff (doc, view, Types, BPasteAfter);
1016: }
1.950 vatton 1017: if (MTableMenuActive)
1018: {
1019: /* a matrice element is selected */
1020: TtaSetItemOn (doc, view, XMLTypes, BMCellHExtend);
1021: TtaSetItemOn (doc, view, XMLTypes, BMCellVExtend);
1022: TtaSetItemOn (doc, view, XMLTypes, BMCellHShrink);
1023: TtaSetItemOn (doc, view, XMLTypes, BMCellVShrink);
1024: TtaSetItemOn (doc, view, XMLTypes, BMSelectRow);
1025: TtaSetItemOn (doc, view, XMLTypes, BMCreateRowB);
1026: TtaSetItemOn (doc, view, XMLTypes, BMCreateRowA);
1027: TtaSetItemOn (doc, view, XMLTypes, BMSelectColumn);
1028: TtaSetItemOn (doc, view, XMLTypes, BMCreateColumnB);
1029: TtaSetItemOn (doc, view, XMLTypes, BMCreateColumnA);
1030: }
1.952 vatton 1031: else
1032: {
1033: TtaSetItemOff (doc, view, XMLTypes, BMCellHExtend);
1034: TtaSetItemOff (doc, view, XMLTypes, BMCellVExtend);
1035: TtaSetItemOff (doc, view, XMLTypes, BMCellHShrink);
1036: TtaSetItemOff (doc, view, XMLTypes, BMCellVShrink);
1037: TtaSetItemOff (doc, view, XMLTypes, BMSelectRow);
1038: TtaSetItemOff (doc, view, XMLTypes, BMCreateRowB);
1039: TtaSetItemOff (doc, view, XMLTypes, BMCreateRowA);
1040: TtaSetItemOff (doc, view, XMLTypes, BMSelectColumn);
1041: TtaSetItemOff (doc, view, XMLTypes, BMCreateColumnB);
1042: TtaSetItemOff (doc, view, XMLTypes, BMCreateColumnA);
1043: TtaSetItemOff (doc, view, XMLTypes, BMPasteBefore);
1044: TtaSetItemOff (doc, view, XMLTypes, BMPasteAfter);
1045: }
1.950 vatton 1046: }
1047:
1.518 cvs 1048:
1049: /*----------------------------------------------------------------------
1.1136 gully 1050: UpdateEditorMenus
1051: Update windows menus for the Editor mode
1.518 cvs 1052: ----------------------------------------------------------------------*/
1.938 vatton 1053: void UpdateEditorMenus (Document doc)
1.518 cvs 1054: {
1.985 vatton 1055: View view;
1.932 vatton 1056: int profile;
1057: ThotBool isXhtml11;
1.527 cvs 1058:
1.932 vatton 1059: profile = TtaGetDocumentProfile (doc);
1060: isXhtml11 = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat &&
1.1136 gully 1061: profile != L_Strict && profile != L_Basic);
1.938 vatton 1062:
1.1084 gully 1063: #ifndef _WX
1.938 vatton 1064: /* update specific menu entries */
1.981 vatton 1065: TtaUpdateMenus (doc, 1, FALSE);
1.1084 gully 1066: #endif /* _WX */
1067:
1.958 cvs 1068: /* Update the doctype menu */
1069: UpdateDoctypeMenu (doc);
1.1165 vatton 1070: #ifdef _WX
1071: /* structure information is active only in the structure view */
1072: if (profile == L_Basic)
1073: {
1074: TtaSetItemOff (doc, 1, Types, BStyle);
1075: TtaSetItemOff (doc, 1, Types, BScript);
1076: TtaSetItemOff (doc, 1, Types, BNoScript);
1077: }
1078: else
1079: {
1080: TtaSetItemOn (doc, 1, Types, BStyle);
1081: TtaSetItemOn (doc, 1, Types, BScript);
1082: TtaSetItemOn (doc, 1, Types, BNoScript);
1083: }
1084: #else /* _WX */
1.938 vatton 1085: /* structure information is active only in the structure view */
1086: TtaSetItemOff (doc, 1, Types, BStyle);
1087: TtaSetItemOff (doc, 1, Types, BComment);
1088: TtaSetItemOff (doc, 1, Types, BBase);
1089: TtaSetItemOff (doc, 1, Types, BMeta);
1090: TtaSetItemOff (doc, 1, Types, BLink);
1091: TtaSetItemOff (doc, 1, Types, BScript);
1092: TtaSetItemOff (doc, 1, Types, BNoScript);
1093: TtaSetItemOff (doc, 1, XMLTypes, BXMLComment);
1.1092 gully 1094: #endif /* _WX */
1.943 vatton 1095: /* invalid all table edits as long as the selection is out of a table */
1.948 vatton 1096: if (TtaIsDocumentSelected (doc))
1.950 vatton 1097: SetTableMenuOn (doc, 1);
1098: else
1099: SetTableMenuOff (doc, 1);
1.1084 gully 1100:
1101: #ifndef _WX
1102: /* SG: I dont understand why these items are enabled here ...
1103: * because SwitchUndo, SwitchPaste functions do the work before */
1.598 cvs 1104: TtaSetItemOn (doc, 1, Edit_, BUndo);
1105: TtaSetItemOn (doc, 1, Edit_, BRedo);
1106: TtaSetItemOn (doc, 1, Edit_, BCut);
1107: TtaSetItemOn (doc, 1, Edit_, BPaste);
1108: TtaSetItemOn (doc, 1, Edit_, BClear);
1.1084 gully 1109: #endif /* _WX */
1.791 vatton 1110:
1.598 cvs 1111: if (DocumentTypes[doc] == docHTML ||
1.952 vatton 1112: DocumentTypes[doc] == docAnnot ||
1.598 cvs 1113: DocumentTypes[doc] == docSVG ||
1114: DocumentTypes[doc] == docMath ||
1.735 cvs 1115: DocumentTypes[doc] == docXml ||
1.598 cvs 1116: DocumentTypes[doc] == docImage)
1.518 cvs 1117: {
1.598 cvs 1118: TtaSetItemOn (doc, 1, Edit_, BSpellCheck);
1119: TtaSetMenuOn (doc, 1, Style);
1.932 vatton 1120: if (DocumentTypes[doc] == docMath)
1.1136 gully 1121: {
1122: SwitchIconMath (doc, 1, TRUE);
1123: TtaSetMenuOn (doc, 1, XMLTypes);
1124: TtaSetItemOn (doc, 1, Edit_, BTransform);
1125: }
1126: else
1127: {
1128: if (DocumentTypes[doc] == docHTML)
1129: {
1130: if (isXhtml11)
1131: TtaSetMenuOn (doc, 1, XMLTypes);
1132: else
1133: TtaSetMenuOff (doc, 1, XMLTypes);
1134: TtaSetItemOn (doc, 1, Edit_, BTransform);
1135: }
1136: else if (DocumentTypes[doc] != docImage)
1137: TtaSetMenuOn (doc, 1, XMLTypes);
1138: TtaSetMenuOn (doc, 1, Types);
1139: TtaSetMenuOn (doc, 1, Links);
1.1084 gully 1140:
1141: #ifndef _WX
1.1136 gully 1142: TtaChangeButton (doc, 1, iI, iconI, TRUE);
1143: TtaChangeButton (doc, 1, iB, iconB, TRUE);
1144: TtaChangeButton (doc, 1, iT, iconT, TRUE);
1145: TtaChangeButton (doc, 1, iImage, iconImage, TRUE);
1146: TtaChangeButton (doc, 1, iH1, iconH1, TRUE);
1147: TtaChangeButton (doc, 1, iH2, iconH2, TRUE);
1148: TtaChangeButton (doc, 1, iH3, iconH3, TRUE);
1149: TtaChangeButton (doc, 1, iBullet, iconBullet, TRUE);
1150: TtaChangeButton (doc, 1, iNum, iconNum, TRUE);
1151: TtaChangeButton (doc, 1, iDL, iconDL, TRUE);
1152: TtaChangeButton (doc, 1, iTable, iconTable, TRUE);
1153: TtaChangeButton (doc, 1, iLink, iconLink, TRUE);
1.1084 gully 1154: #endif /* _WX */
1155:
1.1136 gully 1156: SwitchIconMath (doc, 1, TRUE);
1.652 vatton 1157: #ifdef _SVG
1.1136 gully 1158: SwitchIconGraph (doc, 1, TRUE);
1159: SwitchIconLibrary (doc, 1, TRUE);
1.847 cheyroul 1160: #ifdef _GL
1.1136 gully 1161: SwitchIconAnimPlay (doc, 1, TRUE);
1.847 cheyroul 1162: #endif /*_GL*/
1.799 vatton 1163: #endif /* _SVG */
1.1136 gully 1164: }
1.518 cvs 1165:
1.598 cvs 1166: view = TtaGetViewFromName (doc, "Structure_view");
1167: if (view != 0 && TtaIsViewOpen (doc, view))
1.1136 gully 1168: {
1169: /* update specific menu entries */
1.1084 gully 1170: #ifndef _WX
1.1136 gully 1171: TtaUpdateMenus (doc, view, FALSE);
1172: TtaSetItemOff (doc, view, File, BShowLogFile);
1173: TtaSetItemOff (doc, view, File, BSynchro);
1.1158 vatton 1174: SetTableMenuOff (doc, view); /* no table commands */
1.1136 gully 1175: #endif /* _WX */
1176: TtaSetItemOn (doc, view, Edit_, BCut);
1177: TtaSetItemOn (doc, view, Edit_, BPaste);
1178: TtaSetItemOn (doc, view, Edit_, BClear);
1179: TtaSetItemOn (doc, view, Edit_, BSpellCheck);
1180: TtaSetItemOn (doc, view, Edit_, BTransform);
1181: if (DocumentTypes[doc] != docMath)
1182: {
1183: TtaSetMenuOn (doc, view, Types);
1184: if (DocumentTypes[doc] != docHTML || isXhtml11)
1185: TtaSetMenuOn (doc, view, XMLTypes);
1186: }
1187: }
1.598 cvs 1188: view = TtaGetViewFromName (doc, "Alternate_view");
1189: if (view != 0 && TtaIsViewOpen (doc, view))
1.1136 gully 1190: {
1191: /* update specific menu entries */
1.1084 gully 1192: #ifndef _WX
1.1136 gully 1193: TtaUpdateMenus (doc, view, FALSE);
1194: TtaSetItemOff (doc, view, File, BShowLogFile);
1195: TtaSetItemOff (doc, view, File, BSynchro);
1196: /* structure information is active only in the structure view */
1197: TtaSetItemOff (doc, view, Types, BStyle);
1198: TtaSetItemOff (doc, view, Types, BComment);
1199: TtaSetItemOff (doc, view, Types, BBase);
1200: TtaSetItemOff (doc, view, Types, BMeta);
1201: TtaSetItemOff (doc, view, Types, BLink);
1202: TtaSetItemOff (doc, view, Types, BScript);
1203: TtaSetItemOff (doc, view, Types, BNoScript);
1204: TtaSetItemOff (doc, view, XMLTypes, BXMLComment);
1.1158 vatton 1205: SetTableMenuOff (doc, view); /* no table commands */
1206: SetCharsetMenuOff (doc, view); /* no charset commands */
1.1136 gully 1207: #endif /* _WX */
1208: TtaSetItemOn (doc, view, Edit_, BCut);
1209: TtaSetItemOn (doc, view, Edit_, BPaste);
1210: TtaSetItemOn (doc, view, Edit_, BClear);
1211: TtaSetItemOn (doc, view, Edit_, BSpellCheck);
1212: if (isXhtml11)
1213: TtaSetMenuOn (doc, view, XMLTypes);
1214: }
1.598 cvs 1215: view = TtaGetViewFromName (doc, "Links_view");
1216: if (view != 0 && TtaIsViewOpen (doc, view))
1.1136 gully 1217: {
1218: /* update specific menu entries */
1.1084 gully 1219: #ifndef _WX
1.1136 gully 1220: TtaUpdateMenus (doc, view, FALSE);
1221: TtaSetItemOff (doc, view, File, BShowLogFile);
1222: TtaSetItemOff (doc, view, File, BSynchro);
1223: /* structure information is active only in the structure view */
1224: TtaSetItemOff (doc, view, Types, BStyle);
1225: TtaSetItemOff (doc, view, Types, BComment);
1226: TtaSetItemOff (doc, view, Types, BBase);
1227: TtaSetItemOff (doc, view, Types, BMeta);
1228: TtaSetItemOff (doc, view, Types, BLink);
1229: TtaSetItemOff (doc, view, Types, BScript);
1230: TtaSetItemOff (doc, view, Types, BNoScript);
1231: TtaSetItemOff (doc, view, XMLTypes, BXMLComment);
1.1158 vatton 1232: SetTableMenuOff (doc, view); /* no table commands */
1.1136 gully 1233: #endif /* _WX */
1234: TtaSetItemOn (doc, view, Edit_, BCut);
1235: TtaSetItemOn (doc, view, Edit_, BPaste);
1236: TtaSetItemOn (doc, view, Edit_, BClear);
1237: TtaSetItemOn (doc, view, Edit_, BSpellCheck);
1238: TtaSetItemOn (doc, view, Edit_, BTransform);
1239: if (DocumentTypes[doc] != docMath)
1240: {
1241: TtaSetMenuOn (doc, view, Types);
1242: if (DocumentTypes[doc] != docHTML || isXhtml11)
1243: TtaSetMenuOn (doc, view, XMLTypes);
1244: }
1245: }
1.598 cvs 1246: view = TtaGetViewFromName (doc, "Table_of_contents");
1247: if (view != 0 && TtaIsViewOpen (doc, view))
1.1136 gully 1248: {
1249: /* update specific menu entries */
1.1084 gully 1250: #ifndef _WX
1.1136 gully 1251: TtaUpdateMenus (doc, view, FALSE);
1252: TtaSetItemOff (doc, view, File, BShowLogFile);
1253: TtaSetItemOff (doc, view, File, BSynchro);
1254: /* structure information is active only in the structure view */
1255: TtaSetItemOff (doc, view, Types, BStyle);
1256: TtaSetItemOff (doc, view, Types, BComment);
1257: TtaSetItemOff (doc, view, Types, BBase);
1258: TtaSetItemOff (doc, view, Types, BMeta);
1259: TtaSetItemOff (doc, view, Types, BLink);
1260: TtaSetItemOff (doc, view, Types, BScript);
1261: TtaSetItemOff (doc, view, Types, BNoScript);
1262: TtaSetItemOff (doc, view, XMLTypes, BXMLComment);
1.1158 vatton 1263: SetTableMenuOff (doc, view); /* no table commands */
1.1136 gully 1264: #endif /* _WX */
1265: TtaSetItemOn (doc, view, Edit_, BCut);
1266: TtaSetItemOn (doc, view, Edit_, BPaste);
1267: TtaSetItemOn (doc, view, Edit_, BClear);
1268: TtaSetItemOn (doc, view, Edit_, BSpellCheck);
1269: TtaSetItemOn (doc, view, Edit_, BTransform);
1270: if (isXhtml11)
1271: TtaSetMenuOn (doc, view, XMLTypes);
1272: }
1.518 cvs 1273: }
1274: }
1275:
1.171 cvs 1276:
1277: /*----------------------------------------------------------------------
1.617 cvs 1278: ShowLogFile
1279: Show error messages generated by the parser.
1.1136 gully 1280: -----------------------------------------------------------------------*/
1.659 vatton 1281: void ShowLogFile (Document doc, View view)
1.617 cvs 1282: {
1.1178 vatton 1283: char fileName[200];
1.617 cvs 1284: int newdoc;
1285:
1.1126 vatton 1286: if (DocumentTypes[doc] == docSource)
1287: doc = GetDocFromSource (doc);
1288: if (doc)
1.863 vatton 1289: {
1.1126 vatton 1290: sprintf (fileName, "%s%c%d%cPARSING.ERR",
1.1136 gully 1291: TempFileDirectory, DIR_SEP, doc, DIR_SEP);
1.1190 vatton 1292: newdoc = GetAmayaDoc (fileName, NULL, 0, doc, CE_LOG, FALSE,
1.1136 gully 1293: NULL, NULL);
1.1126 vatton 1294: /* store the relation with the original document */
1295: if (newdoc)
1.1136 gully 1296: {
1297: DocumentSource[newdoc] = doc;
1298: TtaSetStatus (newdoc, 1, " ", NULL);
1299: }
1.863 vatton 1300: }
1.617 cvs 1301: }
1302:
1303: /*----------------------------------------------------------------------
1304: OpenParsingErrors
1305: ----------------------------------------------------------------------*/
1.659 vatton 1306: ThotBool OpenParsingErrors (Document document)
1.617 cvs 1307: {
1.1178 vatton 1308: char fileName[200];
1.617 cvs 1309:
1.1109 vatton 1310: if (document == 0)
1311: return FALSE;
1312:
1.617 cvs 1313: sprintf (fileName, "%s%c%d%cPARSING.ERR",
1.1136 gully 1314: TempFileDirectory, DIR_SEP, document, DIR_SEP);
1.1109 vatton 1315: /* check what error file is open */
1316: if (DocumentTypes[document] == docCSS)
1317: {
1318: CSSErrFile = TtaWriteOpen (fileName);
1319: if ((CSSErrFile == NULL))
1.1136 gully 1320: return FALSE;
1.1109 vatton 1321: else
1.1136 gully 1322: fprintf (CSSErrFile, TtaGetMessage (AMAYA, AM_LINK_LINE));
1.1109 vatton 1323: }
1.617 cvs 1324: else
1.1109 vatton 1325: {
1.1136 gully 1326: ErrFile = TtaWriteOpen (fileName);
1327: if ((ErrFile == NULL))
1328: return FALSE;
1329: else
1330: fprintf (ErrFile, TtaGetMessage (AMAYA, AM_LINK_LINE));
1.1109 vatton 1331: }
1.1136 gully 1332: return TRUE;
1.617 cvs 1333: }
1334:
1335: /*----------------------------------------------------------------------
1336: RemoveParsingErrors
1337: ----------------------------------------------------------------------*/
1.659 vatton 1338: void RemoveParsingErrors (Document document)
1.617 cvs 1339: {
1.1178 vatton 1340: char htmlErrFile[200];
1.617 cvs 1341:
1342: sprintf (htmlErrFile, "%s%c%d%cPARSING.ERR",
1.1136 gully 1343: TempFileDirectory, DIR_SEP, document, DIR_SEP);
1.617 cvs 1344: if (TtaFileExist (htmlErrFile))
1345: TtaFileUnlink (htmlErrFile);
1346: }
1347:
1348: /*----------------------------------------------------------------------
1349: CleanUpParsingErrors
1350: Initialize the 'PARSING.ERR' file and the related global variables
1351: ----------------------------------------------------------------------*/
1.659 vatton 1352: void CleanUpParsingErrors ()
1.617 cvs 1353: {
1354: HTMLErrorsFound = FALSE;
1355: XMLErrorsFound = FALSE;
1356: CSSErrorsFound = FALSE;
1357: XMLErrorsFoundInProfile = FALSE;
1358: XMLNotWellFormed = FALSE;
1.986 vatton 1359: XMLInvalidToken = FALSE;
1.617 cvs 1360: XMLUnknownEncoding = FALSE;
1361: XMLCharacterNotSupported = FALSE;
1362: /* close the error file */
1363: if (ErrFile)
1364: {
1.1050 vatton 1365: TtaWriteClose (ErrFile);
1.617 cvs 1366: ErrFile = NULL;
1367: }
1368: }
1369:
1370: /*----------------------------------------------------------------------
1371: CheckParsingErrors
1372: Checks the errors during the parsing of the document and active
1373: (or not) the Show Log File menu entry
1374: ----------------------------------------------------------------------*/
1.659 vatton 1375: void CheckParsingErrors (Document doc)
1.617 cvs 1376: {
1.1177 vatton 1377: char *ptr;
1.1178 vatton 1378: char fileName[200];
1379: char text [200];
1.1108 vatton 1380: #ifndef _WX
1.702 vatton 1381: int prof;
1.1108 vatton 1382: #endif /* _WX */
1.1178 vatton 1383: ThotBool closeLog = FALSE;
1.680 cvs 1384:
1.1177 vatton 1385: // Avoid recursive call
1386: if (CriticCheckError)
1387: return;
1388: CriticCheckError = TRUE;
1.1066 cvs 1389: #ifndef _WINGUI
1390: CloseLogs (doc);
1391: closeLog = TRUE;
1392: #endif /* _WINGUI */
1393:
1.830 vatton 1394: if (BADMimeType)
1395: {
1396: /* the mime type doesn't match the doctype */
1.1136 gully 1397: InitConfirm (doc, 1, TtaGetMessage (AMAYA, AM_INVALID_MIMETYPE));
1.830 vatton 1398: BADMimeType = FALSE;
1.1136 gully 1399: }
1.659 vatton 1400: if (ErrFile)
1.617 cvs 1401: {
1402: /* Active the menu entry */
1.995 vatton 1403: TtaSetItemOn (doc, 1, File, BShowLogFile);
1.1126 vatton 1404: if (DocumentSource[doc])
1.1136 gully 1405: /* update the document source too */
1406: TtaSetItemOn (DocumentSource[doc], 1, File, BShowLogFile);
1.1126 vatton 1407:
1.986 vatton 1408: if (XMLCharacterNotSupported || XMLInvalidToken)
1.1136 gully 1409: {
1410: /* Invalid characters */
1411: if (XMLInvalidToken)
1412: ptr = TtaGetMessage (AMAYA, AM_XML_CHARACTER_RETRY);
1413: else
1414: ptr = TtaGetMessage (AMAYA, AM_XML_CHARACTER_ERROR);
1415: InitConfirm3L (doc, 1,
1416: TtaGetMessage (AMAYA, AM_XML_CHARACTER_ERROR),
1417: TtaGetMessage (AMAYA, AM_XML_CHARACTER_RETRY),
1418: NULL, FALSE);
1419: CleanUpParsingErrors ();
1420: }
1.986 vatton 1421: else if (XMLNotWellFormed)
1.1136 gully 1422: {
1423: /* Raise a popup message */
1424: /* The document is not well-formed */
1.1177 vatton 1425: if (DocumentTypes[doc] == docHTML &&
1426: (!DocumentMeta[doc] || !DocumentMeta[doc]->compound))
1.1136 gully 1427: {
1.1177 vatton 1428: ptr = TtaGetMessage (AMAYA, AM_XML_RETRY);
1.1178 vatton 1429: // save the original log file
1430: sprintf (fileName, "%s%c%d%cPARSING.ERR",
1431: TempFileDirectory, DIR_SEP, doc, DIR_SEP);
1432: strcpy (text, fileName);
1433: strcat (text, ".org");
1434: CleanUpParsingErrors ();
1435: CloseLogs (doc);
1436: TtaFileUnlink (text);
1437: TtaFileRename (fileName, text);
1438: ParseAsHTML (doc, 1);
1.1186 vatton 1439: // reset XML format for future saving
1440: DocumentMeta[doc]->xmlformat = TRUE;
1.1178 vatton 1441: // restore the original log file
1442: CleanUpParsingErrors ();
1443: CloseLogs (doc);
1444: TtaFileUnlink (fileName);
1445: TtaFileRename (text, fileName);
1446: closeLog = TRUE;
1.1177 vatton 1447: if (SavingDocument && SavingDocument == DocumentSource[doc])
1.1136 gully 1448: {
1.1177 vatton 1449: ConfirmError (doc, 1, ptr,
1450: TtaGetMessage (AMAYA, AM_SAVE_ANYWAY),
1451: NULL);
1452: if (!ExtraChoice && !UserAnswer)
1453: // GTK or WX version: stop the save process
1454: SavingDocument = 0;
1.1136 gully 1455: }
1.1177 vatton 1456: else
1457: {
1.1178 vatton 1458: //InitConfirm3L (doc, 1, ptr, NULL, NULL, FALSE);
1.1177 vatton 1459: ConfirmError (doc, 1, ptr,
1460: TtaGetMessage (AMAYA, AM_AFILTER_SHOW),
1461: NULL);
1462: if (ExtraChoice || UserAnswer)
1463: {
1.1187 vatton 1464: ShowSource (doc, 1);
1.1178 vatton 1465: // GTK or WX version: show errors
1466: ShowLogFile (doc, 1);
1.1177 vatton 1467: }
1468: }
1469: }
1470: else
1471: {
1472: ptr = TtaGetMessage (AMAYA, AM_XML_ERROR);
1473: if (SavingDocument == DocumentSource[doc])
1474: // stop the save process
1475: SavingDocument = 0;
1476: // Set the document in read-only mode
1477: TtaSetDocumentAccessMode (doc, 0);
1478: ConfirmError (doc, 1, ptr,
1479: TtaGetMessage (AMAYA, AM_AFILTER_SHOW),
1480: NULL);
1.1178 vatton 1481: if (ExtraChoice || UserAnswer)
1.1177 vatton 1482: {
1.1178 vatton 1483: // GTK or WX version: show errors
1.1177 vatton 1484: CleanUpParsingErrors ();
1485: CloseLogs (doc);
1486: closeLog = TRUE;
1487: ShowLogFile (doc, 1);
1488: ShowSource (doc, 1);
1489: }
1.1136 gully 1490: }
1491: }
1.1108 vatton 1492: #ifndef _WX
1.659 vatton 1493: else if (XMLErrorsFoundInProfile)
1.1136 gully 1494: {
1495: /* Some elements or attributes are not supported */
1496: /* in the current document profile */
1497: prof = TtaGetDocumentProfile (doc);
1498: if (prof == L_Basic)
1499: {
1.1178 vatton 1500: strcpy (text, TtaGetMessage (AMAYA, AM_XML_PROFILE));
1501: strcat (text, " XHTML Basic");
1.1136 gully 1502: }
1503: else if (prof == L_Strict)
1504: {
1.1178 vatton 1505: strcpy (text, TtaGetMessage (AMAYA, AM_XML_PROFILE));
1.1136 gully 1506: if (DocumentMeta[doc]->xmlformat)
1.1178 vatton 1507: strcat (text, " XHTML 1.0 Strict");
1.1136 gully 1508: else
1.1178 vatton 1509: strcat (text, " HTML 4.0 Strict");
1.1136 gully 1510: }
1511: else if (prof == L_Xhtml11)
1512: {
1.1178 vatton 1513: strcpy (text, TtaGetMessage (AMAYA, AM_XML_PROFILE));
1514: strcat (text, " XHTML 1.1");
1.1136 gully 1515: }
1516: else
1.1178 vatton 1517: strcpy (text, "");
1.1136 gully 1518:
1.1178 vatton 1519: InitConfirm3L (doc, 1, text, NULL,
1.1136 gully 1520: TtaGetMessage (AMAYA, AM_XML_WARNING), FALSE);
1521: CleanUpParsingErrors ();
1522: if (UserAnswer)
1523: {
1524: CloseLogs (doc);
1525: closeLog = TRUE;
1526: ShowLogFile (doc, 1);
1527: ShowSource (doc, 1);
1528: }
1529: }
1.740 cvs 1530: else if (XMLErrorsFound)
1.1136 gully 1531: {
1532: /* Parsing errors detected */
1.1178 vatton 1533: strcpy (text, "");
1.1136 gully 1534: InitConfirm (doc, 1, TtaGetMessage (AMAYA, AM_XML_WARNING));
1535: CleanUpParsingErrors ();
1536: if (UserAnswer)
1537: {
1538: CloseLogs (doc);
1539: closeLog = TRUE;
1540: ShowLogFile (doc, 1);
1541: ShowSource (doc, 1);
1542: }
1543: }
1.1108 vatton 1544: #endif /* _WX */
1.659 vatton 1545: CleanUpParsingErrors ();
1.1108 vatton 1546: if (!closeLog)
1.1136 gully 1547: {
1548: CloseLogs (doc);
1549: TtaSetItemOn (doc, 1, File, BShowLogFile);
1550: if (DocumentSource[doc])
1551: /* update the document source too */
1552: TtaSetItemOn (DocumentSource[doc], 1, File, BShowLogFile);
1553: }
1.617 cvs 1554: }
1555: else
1.1136 gully 1556: {
1557: CloseLogs (doc);
1558: TtaSetItemOff (doc, 1, File, BShowLogFile);
1559: if (DocumentSource[doc])
1560: /* update the document source too */
1561: TtaSetItemOff (DocumentSource[doc], 1, File, BShowLogFile);
1562: }
1.1177 vatton 1563: CriticCheckError = FALSE;
1.617 cvs 1564: }
1565:
1566:
1567: /*----------------------------------------------------------------------
1.1136 gully 1568: UpdateTransfer updates the status of the current transfer
1.73 cvs 1569: ----------------------------------------------------------------------*/
1.659 vatton 1570: void UpdateTransfer (Document document)
1.73 cvs 1571: {
1.836 vatton 1572: if (document)
1573: FilesLoading[document]++;
1.73 cvs 1574: }
1.6 cvs 1575:
1.9 cvs 1576: /*----------------------------------------------------------------------
1.1136 gully 1577: StopTransfer stops the current transfer
1.9 cvs 1578: ----------------------------------------------------------------------*/
1.659 vatton 1579: void StopTransfer (Document document, View view)
1.6 cvs 1580: {
1.171 cvs 1581: if (document == 0)
1582: return;
1583: else if (document == DocBook)
1.136 cvs 1584: {
1.171 cvs 1585: /* Make Book function stopped */
1586: DocBook = 0;
1587: /* stop transfer of the sub-document */
1.136 cvs 1588: StopRequest (document);
1.171 cvs 1589: StopRequest (IncludedDocument);
1590: FilesLoading[document] = 0;
1591: DocNetworkStatus[document] = AMAYA_NET_INACTIVE;
1.136 cvs 1592: }
1.171 cvs 1593: else if (DocNetworkStatus[document] & AMAYA_NET_ACTIVE)
1594: {
1595: if (TtaGetViewFrame (document, 1) != 0)
1.1084 gully 1596: #ifndef _WX
1.1136 gully 1597: TtaChangeButton (document, 1, iStop, stopN, FALSE);
1.1084 gully 1598: #else /* _WX */
1.1136 gully 1599: TtaEnableAction(document, "StopTransfer", FALSE);
1.1084 gully 1600: #endif /* _WX */
1.118 cvs 1601: StopRequest (document);
1602: FilesLoading[document] = 0;
1603: DocNetworkStatus[document] = AMAYA_NET_INACTIVE;
1.375 cvs 1604: TtaSetStatus (document, 1,
1.1136 gully 1605: TtaGetMessage (AMAYA, AM_LOAD_ABORT),
1606: NULL);
1.118 cvs 1607: }
1.6 cvs 1608: }
1.680 cvs 1609:
1.756 vatton 1610: /*----------------------------------------------------------------------
1.810 vatton 1611: CompleteUrl
1612: In case of a user typed url without protocol specification
1613: and filepath like url (the ~ or / url beginning),
1614: we add the http:// (more conveniant when you often type urls)
1615: so that you can now enter w3.org directly in the url bar.
1616: Return TRUE if the URL changed.
1.756 vatton 1617: ----------------------------------------------------------------------*/
1.810 vatton 1618: static ThotBool CompleteUrl(char **url)
1.673 cheyroul 1619: {
1.1159 vatton 1620: char *s, *ptr;
1.673 cheyroul 1621:
1.1159 vatton 1622: if (IsFilePath (*url))
1623: {
1624: // remove file:
1625: ptr = &((*(url))[5]);
1626: s = (char *)TtaGetMemory (MAX_LENGTH);
1627: s[0] = EOS;
1.1182 cvs 1628: *url = s;
1.1159 vatton 1629: if (ptr[0] == '/' && ptr[1] == '/' && ptr[2] == '/')
1630: ptr = &ptr[2];
1631: #ifdef _WINDOWS
1.1182 cvs 1632: else if (ptr[0] == '/' && ptr[1] == '/' && ptr[3] == ':')
1633: ptr = &ptr[2];
1.1159 vatton 1634: if (ptr[1] != ':')
1635: {
1636: char *ptr2;
1637: // add a default device
1638: ptr2 = getenv ("HOMEDRIVE");
1639: if (ptr2)
1640: strcpy (s, ptr2);
1641: else
1642: strcpy (s, "c:");
1.1160 cvs 1643: s= &s[2];
1.1159 vatton 1644: }
1645: #endif /* _WINDOWS */
1.1160 cvs 1646: while (*ptr != EOS)
1647: {
1648: if (*ptr == '/')
1649: *s = DIR_SEP;
1650: else
1651: *s = *ptr;
1652: s++;
1653: ptr++;
1654: }
1655: *s = EOS;
1.1159 vatton 1656: return TRUE;
1657: }
1658: else if (**url != DIR_SEP
1.673 cheyroul 1659: && **url != '~'
1.1072 cvs 1660: #ifdef _WINDOWS
1.674 cvs 1661: && (*(url))[1] != ':'
1.1072 cvs 1662: #endif /* _WINDOWS */
1.673 cheyroul 1663: && !IsW3Path (*url)
1664: && (strlen (*url) + 8) < MAX_LENGTH)
1.1136 gully 1665: {
1.1121 gully 1666: if (!TtaFileExist(*url))
1.1136 gully 1667: {
1668: s = (char *)TtaGetMemory (MAX_LENGTH);
1669: strcpy (s, "http://");
1670: strcat (s, *url);
1671: *url = s;
1672: return TRUE;
1673: }
1674: }
1.810 vatton 1675: return FALSE;
1.673 cheyroul 1676: }
1677:
1.6 cvs 1678:
1.9 cvs 1679: /*----------------------------------------------------------------------
1.1136 gully 1680: TextURL
1681: The Address text field in a document window has been modified by the user
1682: Load the corresponding document in that window.
1.9 cvs 1683: ----------------------------------------------------------------------*/
1.798 vatton 1684: static void TextURL (Document doc, View view, char *text)
1.6 cvs 1685: {
1.547 cvs 1686: char *s = NULL;
1687: char *url;
1.810 vatton 1688: ThotBool change, updated;
1.6 cvs 1689:
1.810 vatton 1690: updated = FALSE;
1.123 cvs 1691: if (text)
1692: {
1.422 cvs 1693: /* remove any trailing '\n' chars that may have gotten there
1.1136 gully 1694: after a cut and paste */
1.422 cvs 1695: change = RemoveNewLines (text);
1.558 cvs 1696: if (IsW3Path (text))
1.1136 gully 1697: url = text;
1.558 cvs 1698: else
1.1136 gully 1699: {
1700: s = (char *)TtaGetMemory (MAX_LENGTH);
1701: updated = CompleteUrl (&text);
1702: change = NormalizeFile (text, s, AM_CONV_NONE);
1703: if (updated)
1704: /* free the allocated string */
1705: TtaFreeMemory (text);
1706: url = s;
1707: }
1.941 vatton 1708:
1.1022 gully 1709: if (!DontReplaceOldDoc && !CanReplaceCurrentDocument (doc, view))
1.1136 gully 1710: {
1711: /* restore the previous value @@ */
1712: AddURLInCombobox (DocumentURLs[doc], NULL, FALSE);
1713: TtaSetTextZone (doc, view, URL_list);
1714: /* cannot load the new document */
1715: TtaSetStatus (doc, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), url);
1716: /* abort the command */
1717: TtaFreeMemory (s);
1718: return;
1719: }
1.123 cvs 1720: else
1.1136 gully 1721: /* do the same thing as a callback form open document form */
1722: CallbackDialogue (BaseDialog + URLName, STRING_DATA, url);
1.941 vatton 1723:
1.799 vatton 1724: TtaFreeMemory (s);
1.1022 gully 1725: DontReplaceOldDoc = FALSE;
1.558 cvs 1726: CurrentDocument = doc;
1.547 cvs 1727: CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
1.123 cvs 1728: }
1.6 cvs 1729: }
1730:
1.9 cvs 1731: /*----------------------------------------------------------------------
1.1136 gully 1732: SetWindowTitle
1733: Change the title of all windows (if view == 0) of document targetDoc
1734: or only the title of the window associated with the specified view.
1735: if it's not 0.
1736: The new title is the content of the TITLE element of document sourceDoc.
1737: If document sourceDoc does not have any TITLE element, nothing happen.
1.376 cvs 1738: ----------------------------------------------------------------------*/
1.568 cvs 1739: void SetWindowTitle (Document sourceDoc, Document targetDoc, View view)
1.376 cvs 1740: {
1.1136 gully 1741: ElementType elType;
1742: Element root, title;
1.935 quint 1743: #ifdef _SVG
1.1136 gully 1744: Element child;
1.935 quint 1745: #endif /* _SVG */
1.1136 gully 1746: SSchema docSSchema;
1.376 cvs 1747:
1.1136 gully 1748: title = NULL;
1749: root = TtaGetRootElement (sourceDoc);
1750: docSSchema = TtaGetDocumentSSchema (sourceDoc);
1751: if (!strcmp (TtaGetSSchemaName (docSSchema), "HTML"))
1752: /* sourceDoc is a HTML document */
1753: {
1754: /* search the Title element in sourceDoc */
1755: elType.ElSSchema = docSSchema;
1756: elType.ElTypeNum = HTML_EL_TITLE;
1757: title = TtaSearchTypedElement (elType, SearchForward, root);
1758: }
1.935 quint 1759: #ifdef _SVG
1.1136 gully 1760: else if (!strcmp (TtaGetSSchemaName (docSSchema), "SVG"))
1761: {
1762: child = TtaGetFirstChild (root);
1763: while (child && !title)
1764: {
1765: elType = TtaGetElementType (child);
1766: if (elType.ElSSchema == docSSchema &&
1767: elType.ElTypeNum == SVG_EL_title)
1768: title = child;
1769: else
1770: TtaNextSibling (&child);
1771: }
1772: }
1.935 quint 1773: #endif /* _SVG */
1.1136 gully 1774: if (title)
1775: UpdateTitle (title, sourceDoc);
1.376 cvs 1776: }
1777:
1778: /*----------------------------------------------------------------------
1.370 cvs 1779: InitFormAnswer
1780: Dialogue form for answering text, user name and password
1.9 cvs 1781: ----------------------------------------------------------------------*/
1.710 vatton 1782: void InitFormAnswer (Document document, View view, const char *auth_realm,
1.1136 gully 1783: char *server)
1.6 cvs 1784: {
1.1043 vatton 1785: #ifdef _GTK
1.1136 gully 1786: char *label;
1.370 cvs 1787:
1.1136 gully 1788: TtaNewForm (BaseDialog + FormAnswer, TtaGetViewFrame (document, view),
1789: TtaGetMessage (AMAYA, AM_GET_AUTHENTICATION),
1790: TRUE, 1, 'L', D_CANCEL);
1791:
1792: label = (char *)TtaGetMemory (((server) ? strlen (server) : 0)
1793: + strlen (TtaGetMessage (AMAYA,
1794: AM_AUTHENTICATION_REALM_SERVER))
1795: + ((auth_realm) ? strlen (auth_realm) : 0)
1796: + 20); /*a bit more than enough memory */
1797: sprintf (label, TtaGetMessage (AMAYA, AM_AUTHENTICATION_REALM_SERVER),
1798: ((auth_realm) ? auth_realm : ""),
1799: ((server) ? server : ""));
1800: TtaNewLabel (BaseDialog + RealmText, BaseDialog + FormAnswer,
1801: label);
1802: TtaFreeMemory (label);
1.370 cvs 1803:
1.1136 gully 1804: TtaNewTextForm (BaseDialog + NameText, BaseDialog + FormAnswer,
1805: TtaGetMessage (AMAYA, AM_NAME), NAME_LENGTH, 1, FALSE);
1806: TtaNewPwdForm (BaseDialog + PasswordText, BaseDialog + FormAnswer,
1807: TtaGetMessage (AMAYA, AM_PASSWORD), NAME_LENGTH, 1, TRUE);
1.891 gully 1808:
1.1136 gully 1809: TtaSetTextForm (BaseDialog + NameText, Answer_name);
1810: TtaSetTextForm (BaseDialog + PasswordText, Answer_password);
1811: TtaSetDialoguePosition ();
1812: TtaShowDialogue (BaseDialog + FormAnswer, FALSE);
1813: TtaWaitShowDialogue ();
1814: if (UserAnswer &&
1815: (Answer_name[0] == EOS || Answer_password[0] == EOS))
1816: {
1817: /* no login name or password, retry */
1818: TtaSetTextForm (BaseDialog + NameText, Answer_name);
1819: TtaSetTextForm (BaseDialog + PasswordText, Answer_password);
1820: TtaSetDialoguePosition ();
1821: TtaShowDialogue (BaseDialog + FormAnswer, FALSE);
1822: TtaWaitShowDialogue ();
1823: }
1.1043 vatton 1824: #endif /* _GTK */
1825: #ifdef _WX
1.1136 gully 1826: ThotBool created;
1.891 gully 1827:
1.1136 gully 1828: created = CreateAuthentDlgWX (BaseDialog + FormAnswer,
1829: TtaGetViewFrame (document, view),
1830: (char *)auth_realm, server);
1831: if (created)
1832: TtaShowDialogue (BaseDialog + FormAnswer, FALSE);
1833: TtaWaitShowDialogue ();
1.1043 vatton 1834: #endif /* _WX */
1.916 cvs 1835: #ifdef _WINGUI
1.1136 gully 1836: CreateAuthenticationDlgWindow (TtaGetViewFrame (document, view),
1837: (char *)auth_realm, server);
1.916 cvs 1838: #endif /* _WINGUI */
1.891 gully 1839:
1.369 cvs 1840: }
1841:
1.659 vatton 1842:
1.369 cvs 1843: /*----------------------------------------------------------------------
1844: InitInfo
1845: Displays a message box with the given info text
1846: ----------------------------------------------------------------------*/
1.605 cvs 1847: void InitInfo (char *label, char *info)
1.369 cvs 1848: {
1.547 cvs 1849: if (!info || *info == EOS)
1.369 cvs 1850: return;
1.916 cvs 1851: #ifdef _WINGUI
1.369 cvs 1852: MessageBox (NULL, info, label, MB_OK);
1.1044 vatton 1853: #endif /* _WINGUI */
1.979 gully 1854: #if defined(_GTK) || defined(_WX)
1.369 cvs 1855: TtaDisplayMessage (CONFIRM, info, NULL);
1.979 gully 1856: #endif /* #if defined(_GTK) || defined(_WX) */
1.6 cvs 1857: }
1858:
1.9 cvs 1859: /*----------------------------------------------------------------------
1860: ----------------------------------------------------------------------*/
1.720 cvs 1861: void ConfirmError (Document document, View view, char *label,
1.1136 gully 1862: char *extrabutton, char *confirmbutton)
1.659 vatton 1863: {
1.1044 vatton 1864: #ifdef _GTK
1.1136 gully 1865: char s[MAX_LENGTH];
1866: int i, n;
1.659 vatton 1867:
1.1136 gully 1868: i = 0;
1.1177 vatton 1869: n = 0;
1870: if (confirmbutton)
1871: {
1872: strcpy (&s[i], confirmbutton);
1873: i += strlen (&s[i]) + 1;
1874: n++;
1875: }
1.1136 gully 1876: if (extrabutton)
1877: {
1878: /* display 3 buttons: extrabutton - show - cancel */
1879: strcpy (&s[i], extrabutton);
1880: n++;
1881: }
1882: TtaNewSheet (BaseDialog + ConfirmForm, TtaGetViewFrame (document, view),
1883: TtaGetMessage (LIB, TMSG_LIB_CONFIRM),
1.1181 vatton 1884: n, s, TRUE, 2, 'L', D_DISCARD);
1.1136 gully 1885: TtaNewLabel (BaseDialog + ConfirmText, BaseDialog + ConfirmForm, label);
1886: TtaSetDialoguePosition ();
1887: TtaShowDialogue (BaseDialog + ConfirmForm, FALSE);
1888: /* wait for an answer */
1889: TtaWaitShowDialogue ();
1.1044 vatton 1890: #endif /* _GTK */
1.964 gully 1891: #ifdef _WX
1.1044 vatton 1892: ThotBool created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
1.1136 gully 1893: TtaGetViewFrame (document, view),
1894: NULL, extrabutton, confirmbutton,
1895: label, NULL, NULL);
1.998 gully 1896: if (created)
1897: {
1898: TtaSetDialoguePosition ();
1899: TtaShowDialogue (BaseDialog + ConfirmForm, FALSE);
1900: /* wait for an answer */
1901: TtaWaitShowDialogue ();
1902: }
1.964 gully 1903: #endif /* _WX */
1.1044 vatton 1904: #ifdef _WINGUI
1.1180 cvs 1905: if (confirmbutton)
1906: CreateInitConfirmDlgWindow (TtaGetViewFrame (document, view),
1907: extrabutton, confirmbutton, label);
1908: else
1909: CreateInitConfirmDlgWindow (TtaGetViewFrame (document, view),
1910: confirmbutton, extrabutton, label);
1.1044 vatton 1911: #endif /* _WINGUI */
1.1136 gully 1912: /* remove the critic section */
1913: CriticConfirm = FALSE;
1.659 vatton 1914: }
1915:
1916: /*----------------------------------------------------------------------
1917: ----------------------------------------------------------------------*/
1.605 cvs 1918: void InitConfirm3L (Document document, View view, char *label1, char *label2,
1.1136 gully 1919: char *label3, ThotBool withCancel)
1.430 cvs 1920: {
1.934 vatton 1921: /* IV: This widget can't be called twice, but it happens when downloading a
1922: document with protected images. This is a quick silution to avoid the
1923: sigsev, although it doesn't fix the problem */
1924: if (CriticConfirm)
1925: return;
1926: else
1927: CriticConfirm = TRUE;
1.904 vatton 1928:
1.1044 vatton 1929: #ifdef _GTK
1.467 cvs 1930: /* Confirm form */
1931: if (withCancel)
1932: TtaNewForm (BaseDialog + ConfirmForm, TtaGetViewFrame (document, view),
1.1136 gully 1933: TtaGetMessage (LIB, TMSG_LIB_CONFIRM), FALSE, 3, 'L', D_CANCEL);
1.467 cvs 1934: else
1935: TtaNewDialogSheet (BaseDialog + ConfirmForm, TtaGetViewFrame (document, view),
1.1136 gully 1936: TtaGetMessage(LIB, TMSG_LIB_CONFIRM),
1937: 1, TtaGetMessage(LIB, TMSG_LIB_CONFIRM),
1938: FALSE, 3, 'L');
1.934 vatton 1939: /* open as many label widgets as \n we find in the label */
1940: if (label1 && *label1 != EOS)
1941: TtaNewLabel (BaseDialog + Label1, BaseDialog + ConfirmForm, label1);
1942: else
1943: TtaNewLabel (BaseDialog + Label1, BaseDialog + ConfirmForm, "");
1944: /* open as many label widgets as \n we find in the label */
1945: if (label2 && *label2 != EOS)
1946: TtaNewLabel (BaseDialog + Label2, BaseDialog + ConfirmForm, label2);
1947: else
1948: TtaNewLabel (BaseDialog + Label2, BaseDialog + ConfirmForm, "");
1949: if (label3 && *label3 != EOS)
1950: TtaNewLabel (BaseDialog + Label3, BaseDialog + ConfirmForm, label3);
1951: else
1952: TtaNewLabel (BaseDialog + Label3, BaseDialog + ConfirmForm, "");
1953: TtaSetDialoguePosition ();
1954: TtaShowDialogue (BaseDialog + ConfirmForm, FALSE);
1955: /* wait for an answer */
1956: TtaWaitShowDialogue ();
1.1043 vatton 1957: #endif /* _GTK */
1.1044 vatton 1958: #ifdef _WX
1.1061 vatton 1959: char *confirm = NULL;
1960: if (withCancel)
1961: confirm = TtaGetMessage (LIB, TMSG_LIB_CONFIRM);
1.1044 vatton 1962: ThotBool created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
1.1136 gully 1963: TtaGetViewFrame (document, view),
1964: NULL /* title */,
1965: NULL /* extra */,
1966: confirm,
1967: label1, label2, label3);
1.1044 vatton 1968: if (created)
1969: {
1970: TtaSetDialoguePosition ();
1971: TtaShowDialogue (BaseDialog + ConfirmForm, FALSE);
1972: /* wait for an answer */
1973: TtaWaitShowDialogue ();
1.1167 vatton 1974: if (AmayaIsAlive ())
1975: TtaDestroyDialogue (BaseDialog + ConfirmForm);
1.1044 vatton 1976: }
1977: #endif /* _WX */
1.916 cvs 1978: #ifdef _WINGUI
1.934 vatton 1979: CreateInitConfirm3LDlgWindow (TtaGetViewFrame (document, view),
1.1136 gully 1980: TtaGetMessage (LIB, TMSG_LIB_CONFIRM),
1981: label1, label2, label3, withCancel);
1.916 cvs 1982: #endif /* _WINGUI */
1.1044 vatton 1983: CriticConfirm = FALSE;
1.430 cvs 1984: }
1985:
1986: /*----------------------------------------------------------------------
1987: ----------------------------------------------------------------------*/
1.655 vatton 1988: void InitConfirm (Document document, View view, char *label)
1.6 cvs 1989: {
1.934 vatton 1990: /* Confirm form */
1991: /* JK: This widget can't be called twice, but it happens when downloading a
1992: document with protected images. This is a quick silution to avoid the
1993: sigsev, although it doesn't fix the problem */
1994: if (CriticConfirm)
1995: return;
1996: else
1997: CriticConfirm = TRUE;
1.443 kahan 1998:
1.1044 vatton 1999: #ifdef _GTK
1.934 vatton 2000: TtaNewForm (BaseDialog + ConfirmForm, TtaGetViewFrame (document, view),
1.1136 gully 2001: TtaGetMessage (LIB, TMSG_LIB_CONFIRM), TRUE, 2, 'L', D_CANCEL);
1.934 vatton 2002: TtaNewLabel (BaseDialog + ConfirmText, BaseDialog + ConfirmForm, label);
2003: TtaSetDialoguePosition ();
2004: TtaShowDialogue (BaseDialog + ConfirmForm, FALSE);
2005: /* wait for an answer */
2006: TtaWaitShowDialogue ();
1.1044 vatton 2007: #endif /* _GTK */
1.926 gully 2008: #ifdef _WX
1.1044 vatton 2009: ThotBool created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
1.1136 gully 2010: TtaGetViewFrame (document, view),
2011: NULL /* title */,
2012: NULL /* extra */,
2013: TtaGetMessage (LIB, TMSG_LIB_CONFIRM),
2014: label, NULL, NULL);
1.998 gully 2015: if (created)
2016: {
2017: TtaSetDialoguePosition ();
2018: TtaShowDialogue (BaseDialog + ConfirmForm, FALSE);
2019: /* wait for an answer */
2020: TtaWaitShowDialogue ();
2021: }
1.926 gully 2022: #endif /* _WX */
1.1044 vatton 2023: #ifdef _WINGUI
2024: CreateInitConfirmDlgWindow (TtaGetViewFrame (document, view),
1.1136 gully 2025: NULL, NULL, label);
1.1044 vatton 2026: #endif /* _WINGUI */
2027: /* remove the critic section */
2028: CriticConfirm = FALSE;
1.6 cvs 2029: }
2030:
1.618 kahan 2031: /*----------------------------------------------------------------------
2032: InitCharset
2033: Asks the user for the charset of a given URL. Used when saving a
2034: document with an unknown charset.
2035: ----------------------------------------------------------------------*/
2036: void InitCharset (Document document, View view, char *url)
2037: {
1.979 gully 2038: #if defined(_GTK)
1.626 vatton 2039: char s[MAX_LENGTH]; /* general purpose buffer */
2040: int i;
1.618 kahan 2041:
1.626 vatton 2042: i = 0;
2043: strcpy (&s[i], "Bus-ascii");
2044: i += strlen (&s[i]) + 1;
2045: strcpy (&s[i], "BUTF-8");
2046: i += strlen (&s[i]) + 1;
2047: strcpy (&s[i], "Biso-8859-1");
2048: i += strlen (&s[i]) + 1;
2049: if (!strcmp (UserCharset, "us-ascii"))
2050: i = 0;
1.628 vatton 2051: else if (!strcmp (UserCharset, "iso-8859-1"))
2052: i = 2;
2053: else
1.626 vatton 2054: i = 1;
2055:
2056: TtaNewForm (BaseDialog + CharsetForm, TtaGetViewFrame (document, view),
1.1136 gully 2057: TtaGetMessage (AMAYA, AM_SELECT_CHARSET), TRUE, 1, 'L', D_CANCEL);
1.626 vatton 2058: /* radio buttons */
2059: TtaNewSubmenu (BaseDialog + CharsetSel, BaseDialog + CharsetForm, 0,
1.1136 gully 2060: NULL, 3, s, NULL, 0, FALSE);
1.626 vatton 2061: TtaSetMenuForm (BaseDialog + CharsetSel, i);
2062:
2063: TtaSetDialoguePosition ();
2064: TtaShowDialogue (BaseDialog + CharsetForm, FALSE);
2065: /* wait for an answer */
2066: TtaWaitShowDialogue ();
1.979 gully 2067: #endif /* defined(_GTK) */
1.891 gully 2068:
1.916 cvs 2069: #ifdef _WINGUI
1.626 vatton 2070: CreateCharsetDlgWindow (TtaGetViewFrame (document, view));
1.916 cvs 2071: #endif /* _WINGUI */
1.891 gully 2072:
1.618 kahan 2073: }
2074:
2075: /*----------------------------------------------------------------------
2076: InitMimeType
2077: Asks the user for the MIME type of a given URL. Used when saving a
2078: document with an unknown MIME type.
2079: ----------------------------------------------------------------------*/
1.634 kahan 2080: void InitMimeType (Document document, View view, char *url, char *status)
1.618 kahan 2081: {
1.626 vatton 2082: char *mimetypes_list;
2083: int nbmimetypes;
2084:
2085: if (DocumentTypes[document] == docImage)
2086: {
2087: mimetypes_list = "image/png\0"
1.1136 gully 2088: "image/jpeg\0"
2089: "image/gif\0"
2090: "image/x-bitmap\0"
2091: "image/x-xpicmap\0";
1.635 kahan 2092: nbmimetypes = 5;
1.626 vatton 2093: }
2094: else if (DocumentTypes[document] == docSVG)
2095: {
1.734 kahan 2096: mimetypes_list = AM_SVG_MIME_TYPE"\0"
1.1136 gully 2097: "application/xml\0"
2098: "text/xml\0";
1.729 kahan 2099: nbmimetypes = 4;
1.626 vatton 2100: }
1.729 kahan 2101: else if (DocumentTypes[document] == docMath)
2102: {
1.734 kahan 2103: mimetypes_list = AM_MATHML_MIME_TYPE"\0"
1.1136 gully 2104: "application/xml\0"
2105: "text/xml\0";
1.729 kahan 2106: nbmimetypes = 3;
2107: }
2108: else if (DocumentTypes[document] == docHTML && DocumentMeta[document] &&
1.1136 gully 2109: DocumentMeta[document]->xmlformat)
1.729 kahan 2110: {
1.734 kahan 2111: mimetypes_list = AM_XHTML_MIME_TYPE"\0"
1.1136 gully 2112: "text/html\0"
2113: "application/xml\0"
2114: "text/xml\0";
1.729 kahan 2115: nbmimetypes = 4;
2116: }
2117: else
1.626 vatton 2118: {
2119: mimetypes_list = "text/html\0"
1.1136 gully 2120: AM_XHTML_MIME_TYPE"\0"
2121: "application/xml\0"
2122: "text/xml\0"
2123: "text/plain\0"
2124: "text/css\0"
2125: "application/smil\0";
1.779 kahan 2126: nbmimetypes = 7;
1.626 vatton 2127: }
1.618 kahan 2128:
1.979 gully 2129: #if defined(_GTK)
1.1136 gully 2130: TtaNewForm (BaseDialog + MimeTypeForm, TtaGetViewFrame (document, view),
2131: TtaGetMessage (AMAYA, AM_SELECT_MIMETYPE), TRUE, 1, 'L', D_CANCEL);
2132: /* selector */
2133: TtaNewSelector (BaseDialog + MimeTypeSel, BaseDialog + MimeTypeForm, NULL,
2134: nbmimetypes, mimetypes_list, 4, NULL, TRUE, FALSE);
2135: /* status */
2136: if (status && *status)
2137: TtaNewLabel (BaseDialog + MimeFormStatus, BaseDialog + MimeTypeForm, status);
2138: else
2139: TtaNewLabel (BaseDialog + MimeFormStatus, BaseDialog + MimeTypeForm,
2140: " ");
2141: TtaSetSelector (BaseDialog + MimeTypeSel, -1, UserMimeType);
2142:
2143: TtaSetDialoguePosition ();
2144: TtaShowDialogue (BaseDialog + MimeTypeForm, FALSE);
2145: /* wait for an answer */
2146: TtaWaitShowDialogue ();
1.979 gully 2147: #endif /* #if defined(_GTK) */
1.891 gully 2148:
1.916 cvs 2149: #ifdef _WINGUI
1.1136 gully 2150: CreateMimeTypeDlgWindow (TtaGetViewFrame (document, view), nbmimetypes,
2151: mimetypes_list);
1.916 cvs 2152: #endif /* _WINGUI */
1.618 kahan 2153: }
1.501 cvs 2154:
1.500 cvs 2155: /*-------------------------------------------------------------------------
1.501 cvs 2156: BrowserForm
1.500 cvs 2157: Initializes a form that ask the URI of the opened or new created document.
2158: -------------------------------------------------------------------------*/
1.678 vatton 2159: static void BrowserForm (Document doc, View view, char *urlname)
1.500 cvs 2160: {
1.979 gully 2161: #if defined(_GTK)
1.1136 gully 2162: char s[MAX_LENGTH];
2163: int i;
2164: char tempfile[MAX_LENGTH];
2165:
2166: /* Dialogue form for open URL or local */
2167: i = 0;
2168: strcpy (&s[i], TtaGetMessage (LIB, TMSG_LIB_CONFIRM));
2169: i += strlen (&s[i]) + 1;
2170: strcpy (&s[i], TtaGetMessage (AMAYA, AM_CLEAR));
2171: i += strlen (&s[i]) + 1;
2172: strcpy (&s[i], TtaGetMessage (AMAYA, AM_PARSE));
1.500 cvs 2173:
1.1136 gully 2174: TtaNewSheet (BaseDialog + FileBrowserForm, TtaGetViewFrame (doc, 1),
2175: TtaGetMessage (AMAYA, AM_FILE_BROWSER), 3, s,
2176: TRUE, 2, 'L', D_CANCEL);
2177: TtaNewTextForm (BaseDialog + FileBrowserText, BaseDialog + FileBrowserForm,
2178: TtaGetMessage (AMAYA, AM_SELECTION), 50, 1, TRUE);
2179: TtaNewLabel (BaseDialog + FileBrowserLocalName,
2180: BaseDialog + FileBrowserForm, " ");
2181:
2182: /* initialise the text fields in the dialogue box */
2183: tempfile[0] = EOS;
2184: if (urlname[0] != EOS)
2185: NormalizeFile (urlname, tempfile, AM_CONV_NONE);
1.507 cvs 2186:
1.1136 gully 2187: if (tempfile[0] != EOS && !IsW3Path (tempfile))
2188: {
2189: /* it's a local file,
2190: initialize the file selector to the current position */
2191: if (TtaCheckDirectory (tempfile))
2192: {
2193: strcpy (DirectoryName, tempfile);
2194: DocumentName[0] = EOS;
2195: }
2196: else
2197: TtaExtractName (tempfile, DirectoryName, DocumentName);
2198: }
2199: /* use the last selection in other cases */
2200: if (DirectoryName[0] == EOS)
2201: {
2202: getcwd (DirectoryName, MAX_LENGTH);
2203: DocumentName[0] = EOS;
2204: }
2205: strcpy (s, DirectoryName);
2206: strcat (s, DIR_STR);
2207: strcat (s, DocumentName);
2208: TtaListDirectory (DirectoryName, BaseDialog + FileBrowserForm,
2209: TtaGetMessage (LIB, TMSG_DOC_DIR),
2210: BaseDialog + BrowserDirSelect, ScanFilter,
2211: TtaGetMessage (AMAYA, AM_FILES),
2212: BaseDialog + BrowserDocSelect);
2213: TtaNewTextForm (BaseDialog + FileBrowserFilter,
2214: BaseDialog + FileBrowserForm,
2215: TtaGetMessage (AMAYA, AM_PARSE), 10, 1, TRUE);
2216:
2217: TtaSetTextForm (BaseDialog + FileBrowserText, s);
2218: TtaSetTextForm (BaseDialog + FileBrowserFilter, ScanFilter);
2219: TtaSetDialoguePosition ();
2220: TtaShowDialogue (BaseDialog + FileBrowserForm, FALSE);
1.979 gully 2221: #endif /* #if defined(_GTK)*/
1.500 cvs 2222: }
1.6 cvs 2223:
1.9 cvs 2224: /*----------------------------------------------------------------------
1.325 cvs 2225: InitOpenDocForm initializes a form that ask the URI of the opened or
2226: new created document.
1.1173 vatton 2227: The parameter name gives a proposed document name (New document).
1.564 cvs 2228: The parameter title gives the title of the the form.
1.9 cvs 2229: ----------------------------------------------------------------------*/
1.760 cvs 2230: static void InitOpenDocForm (Document doc, View view, char *name, char *title,
1.1136 gully 2231: DocumentType docType)
1.6 cvs 2232: {
1.1128 tollenae 2233: char s [MAX_LENGTH];
1.1182 cvs 2234: char *thotdir;
1.564 cvs 2235: ThotBool remote;
1.1173 vatton 2236: #ifdef _WX
2237: wxString homedir;
1.1182 cvs 2238: #else /* _WX */
2239: #ifdef _WINDOWS
2240: char *d;
2241: #endif /* _WINDOWS */
2242: char *homedir;
1.1173 vatton 2243: #endif /* _WX */
1.979 gully 2244: #if defined(_GTK)
1.558 cvs 2245: int i;
1.6 cvs 2246:
1.558 cvs 2247: /* Dialogue form for open URL or local */
2248: i = 0;
2249: strcpy (&s[i], TtaGetMessage (AMAYA, AM_OPEN_URL));
2250: i += strlen (&s[i]) + 1;
2251: strcpy (&s[i], TtaGetMessage (AMAYA, AM_BROWSE));
2252: i += strlen (&s[i]) + 1;
2253: strcpy (&s[i], TtaGetMessage (AMAYA, AM_CLEAR));
1.10 cvs 2254:
1.558 cvs 2255: TtaNewSheet (BaseDialog + OpenForm, TtaGetViewFrame (doc, view),
1.1136 gully 2256: title, 3, s, TRUE, 2, 'L', D_CANCEL);
1.558 cvs 2257: TtaNewTextForm (BaseDialog + URLName, BaseDialog + OpenForm,
1.1136 gully 2258: TtaGetMessage (AMAYA, AM_LOCATION), 50, 1, TRUE);
1.558 cvs 2259: TtaNewLabel (BaseDialog + LocalName, BaseDialog + OpenForm, " ");
1.979 gully 2260: #endif /* #if defined(_GTK) */
1.564 cvs 2261:
2262: CurrentDocument = doc;
2263: /* generate the right name and URI */
2264: TtaExtractName (DocumentURLs[doc], s, DocumentName);
2265: remote = IsW3Path (DocumentURLs[doc]);
2266: if (remote)
1.558 cvs 2267: {
1.564 cvs 2268: if (name[0] != EOS)
1.1136 gully 2269: {
2270: strcpy (LastURLName, s);
2271: strcat (LastURLName, URL_STR);
2272: strcat (LastURLName, name);
2273: }
1.564 cvs 2274: else
1.1136 gully 2275: strcpy (LastURLName, DocumentURLs[doc]);
1.564 cvs 2276: strcpy (s, LastURLName);
1.558 cvs 2277: }
2278: else
2279: {
1.678 vatton 2280: /* check if it's the default Welcome page */
1.760 cvs 2281: if (name[0] == EOS)
1.1136 gully 2282: {
2283: if (DocumentURLs[doc])
2284: strcpy (s, DocumentURLs[doc]);
2285: else
2286: s[0] = EOS;
2287: }
2288: else
2289: {
1.1173 vatton 2290: // Avoid to create new documents into Amaya space
2291: thotdir = TtaGetEnvString ("THOTDIR");
2292: if (!strncmp (s, thotdir, strlen (thotdir)))
2293: {
1.1182 cvs 2294: #ifdef _WX
1.1173 vatton 2295: homedir = TtaGetHomeDir();
2296: strcpy(s, (const char *)homedir.mb_str(wxConvUTF8));
1.1182 cvs 2297: #else /* _WX */
2298: #ifdef _WINDOWS
2299: d = getenv ("HOMEDRIVE");
2300: homedir = getenv ("HOMEPATH");
2301: if (d && *d && homedir)
2302: sprintf (s, "%s%s", d, homedir);
2303: #else /* _WINDOWS */
2304: homedir = getenv ("HOME");
2305: if (homedir)
2306: strcpy(s, homedir);
2307: #endif /* _WINDOWS */
2308: #endif /* _WX */
1.1173 vatton 2309: }
1.1136 gully 2310: strcpy (DirectoryName, s);
2311: strcpy (DocumentName, name);
2312: strcat (s, DIR_STR);
2313: strcat (s, name);
2314: }
1.587 cvs 2315: strcpy (LastURLName, s);
1.558 cvs 2316: }
1.564 cvs 2317:
1.916 cvs 2318: #ifdef _WINGUI
1.766 cheyroul 2319: CreateOpenDocDlgWindow (TtaGetViewFrame (doc, view), title, s, name,
1.1136 gully 2320: DocSelect, DirSelect, docType);
1.979 gully 2321: #endif /* _WINGUI */
2322:
2323: #ifdef _WX
1.998 gully 2324: {
2325: ThotBool created;
1.1025 gully 2326: /* here we pass also 'URL_list', because we want generate a combobox choice list */
1.998 gully 2327: created = CreateOpenDocDlgWX( BaseDialog + OpenForm,
1.1136 gully 2328: TtaGetViewFrame (doc, view), title, URL_list, s, name,
2329: DocSelect, DirSelect, docType, NewFile );
1.998 gully 2330: if (created)
2331: {
1.1136 gully 2332: TtaSetDialoguePosition ();
2333: TtaShowDialogue (BaseDialog + OpenForm, TRUE);
1.998 gully 2334: }
2335: }
1.979 gully 2336: #endif /* _WX */
1.891 gully 2337:
1.979 gully 2338: #if defined(_GTK)
1.564 cvs 2339: TtaSetTextForm (BaseDialog + URLName, s);
1.558 cvs 2340: TtaSetDialoguePosition ();
2341: TtaShowDialogue (BaseDialog + OpenForm, TRUE);
1.979 gully 2342: #endif /* defined(_GTK) */
1.891 gully 2343:
1.6 cvs 2344: }
2345:
1.9 cvs 2346: /*----------------------------------------------------------------------
2347: ----------------------------------------------------------------------*/
1.564 cvs 2348: void OpenDoc (Document doc, View view)
1.485 cvs 2349: {
1.1078 gully 2350: #ifndef _WX
1.1136 gully 2351: if (CanReplaceCurrentDocument (doc, view))
2352: {
2353: /* load the new document */
2354: DontReplaceOldDoc = FALSE;
2355: InNewWindow = FALSE;
1.1078 gully 2356: #endif /* _WX */
1.1024 gully 2357: /* no specific type requested */
1.1136 gully 2358: InitOpenDocForm (doc, view, "",
2359: TtaGetMessage (AMAYA, AM_OPEN_DOCUMENT), docText);
1.1078 gully 2360: #ifndef _WX
1.1136 gully 2361: }
1.1078 gully 2362: #endif /* _WX */
1.485 cvs 2363: }
2364:
2365: /*----------------------------------------------------------------------
2366: ----------------------------------------------------------------------*/
1.564 cvs 2367: void OpenDocInNewWindow (Document document, View view)
1.6 cvs 2368: {
1.1078 gully 2369: #ifndef _WX
1.1024 gully 2370: DontReplaceOldDoc = TRUE;
2371: InNewWindow = TRUE;
1.1078 gully 2372: #endif /* _WX */
1.1024 gully 2373: /* no specific type requested */
2374: InitOpenDocForm (document, view, "",
1.1136 gully 2375: TtaGetMessage (AMAYA, AM_OPEN_IN_NEW_WINDOW),
2376: docText);
1.6 cvs 2377: }
2378:
1.1024 gully 2379: /*----------------------------------------------------------------------
1.445 cvs 2380: OpenNew: create a new document
1.9 cvs 2381: ----------------------------------------------------------------------*/
1.683 cvs 2382: void OpenNew (Document document, View view, int docType, int docProfile)
1.315 cvs 2383: {
2384: /* create a new document */
1.1022 gully 2385: DontReplaceOldDoc = TRUE;
1.503 cvs 2386: NewFile = TRUE;
2387: NewDocType = docType;
1.683 cvs 2388: NewDocProfile = docProfile;
1.1114 vatton 2389: NewXML = TRUE;
1.503 cvs 2390: if (NewDocType == docHTML)
1.683 cvs 2391: {
1.819 vatton 2392: /* will scan html documents */
2393: strcpy (ScanFilter, "*.*htm*");
1.683 cvs 2394: if (docProfile == L_Basic)
1.1136 gully 2395: InitOpenDocForm (document, view, "New.html",
2396: TtaGetMessage (AMAYA, AM_NEW_HTML_BASIC), docHTML);
1.683 cvs 2397: else if (docProfile == L_Strict)
1.1136 gully 2398: InitOpenDocForm (document, view, "New.html",
2399: TtaGetMessage (AMAYA, AM_NEW_HTML_STRICT), docHTML);
1.1114 vatton 2400: else if (docProfile == L_Transitional)
1.1136 gully 2401: InitOpenDocForm (document, view, "New.html",
2402: TtaGetMessage (AMAYA, AM_NEW_HTML_TRANSITIONAL), docHTML);
1.683 cvs 2403: else
1.1136 gully 2404: InitOpenDocForm (document, view, "New.html",
2405: TtaGetMessage (AMAYA, AM_NEW_HTML11), docHTML);
2406: }
1.503 cvs 2407: else if (NewDocType == docMath)
1.819 vatton 2408: {
2409: /* will scan html documents */
2410: strcpy (ScanFilter, "*.mml");
1.1136 gully 2411: InitOpenDocForm (document, view, "New.mml",
2412: TtaGetMessage (AMAYA, AM_NEW_MATHML), docMath);
1.819 vatton 2413: }
1.503 cvs 2414: else if (NewDocType == docSVG)
1.819 vatton 2415: {
2416: /* will scan html documents */
2417: strcpy (ScanFilter, "*.svg");
1.968 vatton 2418: InitOpenDocForm (document, view, "New.svg",
1.1136 gully 2419: TtaGetMessage (AMAYA, AM_NEW_SVG), docSVG);
1.819 vatton 2420: }
1.315 cvs 2421: else
1.819 vatton 2422: {
2423: /* will scan html documents */
2424: strcpy (ScanFilter, "*.css");
1.968 vatton 2425: InitOpenDocForm (document, view, "New.css",
1.1136 gully 2426: TtaGetMessage (AMAYA, AM_NEW_CSS), docCSS);
1.819 vatton 2427: }
1.315 cvs 2428: }
2429:
2430: /*----------------------------------------------------------------------
1.311 cvs 2431: Load the Home page
2432: ----------------------------------------------------------------------*/
1.593 cvs 2433: void GoToHome (Document doc, View view)
1.311 cvs 2434: {
1.547 cvs 2435: char *s, *lang;
1.311 cvs 2436:
1.339 cvs 2437: s = TtaGetEnvString ("HOME_PAGE");
1.492 cvs 2438: lang = TtaGetVarLANG ();
1.589 cvs 2439:
1.492 cvs 2440: if (s == NULL)
2441: {
1.678 vatton 2442: /* the open document is the Amaya default page */
2443: WelcomePage = TRUE;
1.492 cvs 2444: s = TtaGetEnvString ("THOTDIR");
1.589 cvs 2445: sprintf (LastURLName, "%s%camaya%c%s.%s",
1.1136 gully 2446: s, DIR_SEP, DIR_SEP, AMAYA_PAGE, lang);
1.492 cvs 2447: if (!TtaFileExist (LastURLName))
1.1136 gully 2448: sprintf (LastURLName, "%s%camaya%c%s",
2449: s, DIR_SEP, DIR_SEP, AMAYA_PAGE);
1.492 cvs 2450: }
2451: else
1.547 cvs 2452: strcpy (LastURLName, s);
1.678 vatton 2453:
1.625 cvs 2454: if (doc == 0 || CanReplaceCurrentDocument (doc, view))
1.589 cvs 2455: {
2456: /* load the HOME document */
1.1022 gully 2457: DontReplaceOldDoc = FALSE;
1.589 cvs 2458: CurrentDocument = doc;
2459: CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
2460: }
1.311 cvs 2461: }
2462:
1.1014 vatton 2463:
1.714 cvs 2464: /*----------------------------------------------------------------------
2465: UpdateDoctypeMenu
2466: ----------------------------------------------------------------------*/
1.958 cvs 2467: void UpdateDoctypeMenu (Document doc)
1.714 cvs 2468: {
1.717 cvs 2469: DocumentType docType;
2470: SSchema nature;
1.1014 vatton 2471: char *ptr;
1.1163 vatton 2472: ThotBool useMathML, useSVG, useHTML, useMath, withDocType;
1.717 cvs 2473:
1.714 cvs 2474: docType = DocumentTypes[doc];
1.942 vatton 2475: if (docType != docText && docType != docCSS &&
1.995 vatton 2476: docType != docSource && docType != docLog && docType != docBookmark &&
1.958 cvs 2477: TtaGetDocumentAccessMode (doc))
1.939 cvs 2478: {
1.942 vatton 2479: /* look for a MathML or SVG nature within the document */
2480: nature = NULL;
2481: useMathML = useSVG = useHTML = FALSE;
2482: do
1.1136 gully 2483: {
2484: TtaNextNature (doc, &nature);
2485: if (nature)
2486: {
2487: ptr = TtaGetSSchemaName (nature);
2488: if (!strcmp (ptr, "MathML"))
2489: useMathML = TRUE;
2490: else if (!strcmp (ptr, "SVG"))
2491: useSVG = TRUE;
2492: }
2493: }
1.942 vatton 2494: while (nature);
2495:
1.1163 vatton 2496: HasADoctype (doc, &withDocType, &useMath);
1.1162 vatton 2497: if (withDocType)
1.1136 gully 2498: {
2499: /* there is a Doctype */
2500: TtaSetItemOn (doc, 1, File, BRemoveDoctype);
2501: TtaSetItemOff (doc, 1, File, BAddDoctype);
2502: }
2503: else
2504: {
2505: /* there is no Doctype */
2506: TtaSetItemOff (doc, 1, File, BRemoveDoctype);
2507: if (docType == docHTML ||
2508: (!useMathML && !useSVG && !useHTML))
2509: TtaSetItemOn (doc, 1, File, BAddDoctype);
2510: else
2511: /* no Doctype available */
2512: TtaSetItemOff (doc, 1, File, BAddDoctype);
2513: }
1.942 vatton 2514:
2515: if (docType == docHTML)
1.1136 gully 2516: {
2517: /* allow to change the DocType:
2518: A confirmation will be requested if some attribues
2519: or elements may be lost */
2520: if (TtaGetDocumentProfile(doc) == L_Xhtml11) /* already done */
2521: TtaSetItemOff (doc, 1, File, BDoctypeXhtml11);
2522: else
2523: TtaSetItemOn (doc, 1, File, BDoctypeXhtml11);
2524:
2525: if (TtaGetDocumentProfile(doc) == L_Transitional &&
2526: DocumentMeta[doc]->xmlformat == TRUE) /* already done */
2527: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlTransitional);
2528: else
2529: TtaSetItemOn (doc, 1, File, BDoctypeXhtmlTransitional);
2530:
2531: if (TtaGetDocumentProfile(doc) == L_Strict &&
2532: DocumentMeta[doc]->xmlformat == TRUE) /* already done */
2533: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlStrict);
2534: else
2535: TtaSetItemOn (doc, 1, File, BDoctypeXhtmlStrict);
2536:
2537: if (TtaGetDocumentProfile(doc) == L_Basic) /* already done */
2538: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlBasic);
2539: else
2540: TtaSetItemOn (doc, 1, File, BDoctypeXhtmlBasic);
2541:
2542: if (TtaGetDocumentProfile(doc) == L_Transitional &&
2543: DocumentMeta[doc]->xmlformat != TRUE) /* already done */
2544: TtaSetItemOff (doc, 1, File, BDoctypeHtmlTransitional);
2545: else
2546: TtaSetItemOn (doc, 1, File, BDoctypeHtmlTransitional);
2547:
2548: if (TtaGetDocumentProfile(doc) == L_Strict &&
2549: DocumentMeta[doc]->xmlformat != TRUE) /* already done */
2550: TtaSetItemOff (doc, 1, File, BDoctypeHtmlStrict);
2551: else
2552: TtaSetItemOn (doc, 1, File, BDoctypeHtmlStrict);
2553: }
2554: else
2555: {
2556: TtaSetItemOff (doc, 1, File, BDoctypeXhtml11);
2557: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlTransitional);
2558: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlStrict);
2559: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlBasic);
2560: TtaSetItemOff (doc, 1, File, BDoctypeHtmlTransitional);
2561: TtaSetItemOff (doc, 1, File, BDoctypeHtmlStrict);
2562: }
2563: }
2564: else
2565: {
2566: TtaSetItemOff (doc, 1, File, BRemoveDoctype);
2567: TtaSetItemOff (doc, 1, File, BAddDoctype);
2568: TtaSetItemOff (doc, 1, File, BDoctypeXhtml11);
2569: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlTransitional);
2570: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlStrict);
2571: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlBasic);
2572: TtaSetItemOff (doc, 1, File, BDoctypeHtmlTransitional);
2573: TtaSetItemOff (doc, 1, File, BDoctypeHtmlStrict);
2574: }
1.714 cvs 2575: }
1.6 cvs 2576:
1.9 cvs 2577: /*----------------------------------------------------------------------
1.724 kahan 2578: AddDirAttributeToDocEl
2579: Set the HTML attribute dir on the Document element
2580: ----------------------------------------------------------------------*/
2581: void AddDirAttributeToDocEl (Document doc)
2582: {
2583: Element root;
2584: Attribute attr;
2585: AttributeType attrType;
2586:
2587: root = TtaGetMainRoot (doc);
2588: if (root)
2589: {
2590: attrType.AttrSSchema = TtaGetSSchema ("HTML", doc);
2591: if (!attrType.AttrSSchema)
1.1136 gully 2592: return;
1.724 kahan 2593: attrType.AttrTypeNum = HTML_ATTR_dir;
2594: attr = TtaNewAttribute (attrType);
2595: TtaAttachAttribute (root, attr, doc);
2596: TtaSetAttributeValue (attr, HTML_ATTR_dir_VAL_ltr_, root, doc);
2597: }
2598: }
1.1005 vatton 2599: /*----------------------------------------------------------------------
2600: GiveWindowGeometry
2601: Gets registered window parameters
2602: ----------------------------------------------------------------------*/
2603: static void GiveWindowGeometry (Document doc, int docType, int method,
1.1136 gully 2604: int *x, int *y, int *w, int *h)
1.1005 vatton 2605: {
2606: char *label;
2607:
2608: /* get the window geometry */
1.1018 vatton 2609: if (docType == docAnnot)
2610: label = "Annot_Formatted_view";
2611: else if (docType == docBookmark)
2612: label = "Topics_Formatted_view";
2613: #ifndef _WX
2614: else if (docType == docSource)
2615: label = "Source_view";
2616: else
2617: label = "Formatted_view";
2618: #else /* _WX */
2619: else
2620: label = "Wx_Window";
2621: #endif /* _WX */
2622: TtaGetViewGeometry (doc, label, x, y, w, h);
2623:
2624: #ifdef _WX
2625: if (w == 0 || h == 0)
2626: TtaGetViewGeometry (doc, "Formatted_view", x, y, w, h);
2627: #else /* _WX */
2628: if (docType == docMath)
2629: {
2630: *h = 300;
2631: *w = 580;
2632: }
2633: #endif /* _WX */
2634:
2635: /* change the position slightly to avoid hiding completely the main
2636: view of other documents */
2637: *x = *x + (doc - 1) * 10;
2638: *y = *y + (doc - 1) * 10;
1.1005 vatton 2639: if (docType == docLog)
2640: {
2641: *x += 100;
2642: *y += 60;
2643: *h = 300;
2644: *w = 550;
2645: }
2646: else if (method == CE_HELP || docType == docBookmark)
2647: {
1.1018 vatton 2648: *x += 300;
1.1005 vatton 2649: *y += 200;
2650: *h = 500;
2651: *w = 800;
2652: }
2653: else if (docType == docLibrary)
2654: {
1.1018 vatton 2655: *x += 300;
1.1005 vatton 2656: *y += 200;
2657: *h = 500;
2658: *w = 400;
2659: }
2660: }
1.724 kahan 2661:
2662: /*----------------------------------------------------------------------
1.1134 gully 2663: InitDocAndView prepares the main view of a new document.
2664: logFile is TRUE if the new view is created to display a log file
2665: sourceOfDoc is not zero when we're opening the source view of a document.
2666: params:
2667: + Document oldDoc: the old document id
2668: + ThotBool replaceOldDoc: true if the new doc should replace the old one
2669: + ThotBool inNewWindow: true if the new doc should be created in a new window
2670: + ...
1.9 cvs 2671: ----------------------------------------------------------------------*/
1.942 vatton 2672: Document InitDocAndView (Document oldDoc, ThotBool replaceOldDoc,
1.1134 gully 2673: ThotBool inNewWindow,
1.926 gully 2674: char *docname, DocumentType docType,
1.1134 gully 2675: Document sourceOfDoc, ThotBool readOnly, int profile,
1.1190 vatton 2676: int method)
1.6 cvs 2677: {
1.926 gully 2678: Document doc; /* the new doc */
1.527 cvs 2679: View mainView, structView, altView, linksView, tocView;
1.699 cvs 2680: Element root, comment, leaf;
2681: ElementType elType;
1.1005 vatton 2682: char buffer[MAX_LENGTH];
1.527 cvs 2683: int x, y, w, h;
1.1184 vatton 2684: int requested_doc, visibility = 5;
1.699 cvs 2685: Language lang;
1.985 vatton 2686: ThotBool isOpen, reinitialized = FALSE, show;
1.972 gully 2687: /* specific to wxWidgets user interface */
2688: /* ------------------------------------ */
1.1005 vatton 2689: /* this is the window id identifying where the document should be shown
2690: * this window_id is a document attribute and the corresponding
2691: * window widget has been allocated before this function call */
1.915 gully 2692: int window_id = -1;
1.926 gully 2693: /* this is the page id identifying where the document should be shown
2694: * into a window (window_id), each page can contain one or more documents */
2695: int page_id = -1;
1.972 gully 2696: /* this is the choosen position in the given page (top or bottom) */
2697: int page_position = 0;
2698: /* ------------------------------------ */
1.1005 vatton 2699:
1.916 cvs 2700: #ifdef _WINGUI
1.276 cvs 2701: Window_Curs = IDC_WINCURSOR;
1.916 cvs 2702: #endif /* _WINGUI */
1.349 cvs 2703:
2704: /* is there any editing function available */
2705: if (!TtaCanEdit ())
1.479 cvs 2706: /* change the document status */
2707: readOnly = TRUE;
1.638 kahan 2708:
1.1086 gully 2709: #ifdef _WX
2710: /* if it is a source document, reload its corresponding document */
2711: if (DocumentTypes[oldDoc] == docSource)
2712: oldDoc = GetDocFromSource (oldDoc);
1.1088 gully 2713:
2714: /* if the old doc doesn't exist it's not possible to create a new tab,
2715: * just open it in a new window */
2716: if (oldDoc == 0 && inNewWindow == 0)
2717: inNewWindow = TRUE;
1.1086 gully 2718: #endif /* _WX */
2719:
1.518 cvs 2720: /* previous document */
1.1005 vatton 2721: doc = oldDoc;
1.1084 gully 2722: if (replaceOldDoc && oldDoc>0)
1.338 cvs 2723: /* the new document will replace another document in the same window */
1.276 cvs 2724: {
1.1184 vatton 2725: // transmit the visibility to the new document
2726: visibility = TtaGetSensibility (doc, 1);
1.915 gully 2727: #ifdef _WX
1.1107 gully 2728: /* get the old document window */
2729: window_id = TtaGetDocumentWindowId( doc, -1 );
2730: /* get the old document page id */
2731: TtaGetDocumentPageId( doc, -1, &page_id, &page_position );
2732: /* force the document's page position because sometime oldDoc is
2733: a source document placed on the bottom part of the page */
2734: page_position = 1;
1.915 gully 2735: #endif /* _WX */
1.505 cvs 2736: if (DocumentTypes[doc] == docHTML ||
1.1107 gully 2737: DocumentTypes[doc] == docSVG ||
2738: DocumentTypes[doc] == docXml ||
2739: DocumentTypes[doc] == docMath ||
2740: DocumentTypes[doc] == docLibrary)
2741: {
2742: /* close the Alternate view if it is open */
2743: altView = TtaGetViewFromName (doc, "Alternate_view");
2744: if (altView != 0 && TtaIsViewOpen (doc, altView))
2745: TtaCloseView (doc, altView);
2746: /* close the Structure view if it is open */
2747: structView = TtaGetViewFromName (doc, "Structure_view");
2748: if (structView != 0 && TtaIsViewOpen (doc, structView))
2749: TtaCloseView (doc, structView);
2750: /* close the Links view if it is open */
2751: linksView = TtaGetViewFromName (doc, "Links_view");
2752: if (linksView != 0 && TtaIsViewOpen (doc, linksView))
2753: TtaCloseView (doc, linksView);
2754: /* close the Table_of_contents view if it is open */
2755: tocView = TtaGetViewFromName (doc, "Table_of_contents");
2756: if (tocView != 0 && TtaIsViewOpen (doc, tocView))
2757: TtaCloseView (doc, tocView);
2758: }
2759: /* remove the current selection */
2760: TtaUnselect (doc);
2761: UpdateContextSensitiveMenus (doc);
1.1175 cvs 2762: #ifdef _WX
2763: HideHSplitToggle (doc, 1);
2764: HideVSplitToggle (doc, 1);
2765: #endif /* _WX */
1.1107 gully 2766: TtaFreeView (doc, 1);
2767: isOpen = TRUE;
2768: /* use the same document identifier */
2769: requested_doc = doc;
2770: oldDoc = 0; /* the previous document doesn't exist any more */
2771: /* The toolkit has to do its job now */
2772: TtaHandlePendingEvents ();
2773: }
2774: else if (inNewWindow)
2775: {
2776: /* open the new document in a fresh window */
2777: isOpen = FALSE;
2778: requested_doc = 0;
2779: }
2780: else
2781: {
2782: /* open the new document in the same window but in a fresh page */
2783: requested_doc = 0;
1.915 gully 2784: #ifdef _WX
1.1107 gully 2785: isOpen = TRUE;
2786: if (docType == docSource)
2787: {
2788: /* if the document is a source view, open it into the same page as formatted view */
2789: window_id = TtaGetDocumentWindowId( doc, -1 );
2790: TtaGetDocumentPageId( doc, -1, &page_id, &page_position );
2791: page_position = 2;
2792: }
2793: else
2794: {
2795: window_id = TtaGetDocumentWindowId( doc, -1 );
2796: wxASSERT(window_id > 0);
2797: page_id = TtaGetFreePageId( window_id );
2798: page_position = 1;
2799: }
1.1005 vatton 2800: #else /* _WX */
1.1107 gully 2801: isOpen = FALSE; /* the menu and icons are already created */
1.915 gully 2802: #endif /* _WX */
1.1107 gully 2803: }
1.10 cvs 2804:
1.1134 gully 2805: /* Init the new document */
2806: if (docType == docText || docType == docCSS ||
2807: docType == docSource || docType == docLog)
2808: doc = TtaInitDocument ("TextFile", docname, requested_doc);
2809: else if (docType == docAnnot)
2810: doc = TtaInitDocument ("Annot", docname, requested_doc);
1.844 kahan 2811: #ifdef BOOKMARKS
1.1134 gully 2812: else if (docType == docBookmark)
2813: doc = TtaInitDocument ("Topics", docname, requested_doc);
1.844 kahan 2814: #endif /* BOOKMARKS */
1.1134 gully 2815: else if (docType == docSVG)
2816: doc = TtaInitDocument ("SVG", docname, requested_doc);
2817: else if (docType == docMath)
2818: doc = TtaInitDocument ("MathML", docname, requested_doc);
1.616 cvs 2819: #ifdef XML_GENERIC
1.1134 gully 2820: else if (docType == docXml)
2821: doc = TtaInitDocument ("XML", docname, requested_doc);
1.616 cvs 2822: #endif /* XML_GENERIC */
1.1134 gully 2823: else
2824: doc = TtaInitDocument ("HTML", docname, requested_doc);
2825: if (doc >= DocumentTableLength)
2826: {
2827: TtaCloseDocument (doc);
2828: doc = 0;
2829: }
2830: else if (doc > 0)
2831: {
2832: /* assign a presentation model to the document */
2833: if (docType == docText || docType == docCSS ||
2834: docType == docSource || docType == docLog)
2835: TtaSetPSchema (doc, "TextFileP");
2836: else if (docType == docAnnot)
2837: {
2838: TtaSetPSchema (doc, "AnnotP");
2839: profile = L_Annot; /* force the profile */
2840: }
1.844 kahan 2841: #ifdef BOOKMARKS
1.1134 gully 2842: else if (docType == docBookmark)
2843: {
2844: TtaSetPSchema (doc, "TopicsP");
2845: profile = L_Bookmarks; /* force the profile */
2846: }
1.844 kahan 2847: #endif /* BOOKMARKS */
1.1134 gully 2848: else if (docType == docSVG)
2849: TtaSetPSchema (doc, "SVGP");
2850: else if (docType == docMath)
2851: TtaSetPSchema (doc, "MathMLP");
1.616 cvs 2852: #ifdef XML_GENERIC
1.1134 gully 2853: else if (docType == docXml)
2854: TtaSetPSchema (doc, "XMLP");
1.616 cvs 2855: #endif /* XML_GENERIC */
1.388 cvs 2856: /* @@ shouldn't we have a Color and BW case for annots too? */
1.1134 gully 2857: else
2858: {
2859: if (TtaGetScreenDepth () > 1)
2860: TtaSetPSchema (doc, "HTMLP");
2861: else
2862: TtaSetPSchema (doc, "HTMLPBW");
2863: /* set attribute dir on the Document element. */
2864: AddDirAttributeToDocEl (doc);
2865: }
2866: if (docType == docSVG || docType == docMath)
2867: /* add a comment proudly claiming that the document was created by
2868: Amaya */
2869: {
2870: root = TtaGetRootElement (doc);
2871: elType = TtaGetElementType (root);
2872: if (docType == docSVG)
2873: elType.ElTypeNum = SVG_EL_XMLcomment;
2874: else
2875: elType.ElTypeNum = MathML_EL_XMLcomment;
2876: comment = TtaNewTree (doc, elType, "");
2877: TtaSetStructureChecking (FALSE, doc);
2878: TtaInsertSibling (comment, root, TRUE, doc);
2879: TtaSetStructureChecking (TRUE, doc);
2880: strcpy (buffer, " Created by ");
2881: strcat (buffer, TtaGetAppName());
2882: strcat (buffer, " ");
2883: strcat (buffer, TtaGetAppVersion());
2884: strcat (buffer, ", see http://www.w3.org/Amaya/ ");
2885: leaf = TtaGetFirstLeaf (comment);
2886: lang = TtaGetLanguageIdFromScript('L');
2887: TtaSetTextContent (leaf, (unsigned char *)buffer, lang, doc);
2888: }
2889: if (docType == docBookmark)
2890: TtaSetNotificationMode (doc, 0); /* we don't need notif. in bookmarks */
2891: else
2892: TtaSetNotificationMode (doc, 1);
1.915 gully 2893:
1.1134 gully 2894: /* store the profile of the new document */
2895: TtaSetDocumentProfile (doc, profile);
2896: /* gets registered window parameters */
2897: GiveWindowGeometry (doc, docType, method, &x, &y, &w, &h);
1.964 gully 2898: #ifdef _WX
1.1134 gully 2899: /* create a new window if needed */
2900: if (window_id == -1)
2901: {
2902: /* get the window parent because the log should stay on top of his parent */
2903: int parent_window_id = TtaGetDocumentWindowId( oldDoc, -1 );
2904: if (docType == docLog)
2905: {
2906: window_id = TtaMakeWindow(x, y, w, h, WXAMAYAWINDOW_SIMPLE, parent_window_id );
2907: }
2908: else
2909: {
2910: /* a normal window should never had a parent ! */
2911: window_id = TtaMakeWindow(x, y, w, h, WXAMAYAWINDOW_NORMAL, 0 );
2912: }
2913: page_id = TtaGetFreePageId( window_id );
2914: page_position = 1;
2915: }
1.964 gully 2916: #endif /* _WX */
2917:
1.1084 gully 2918: #ifdef _WX
1.1134 gully 2919: /* init the internal default documents menus states : enable/disable, toggle/untoggle
2920: * need to be done before frame creation because the active frame will use it to refresh the menus */
2921: if (!replaceOldDoc || !isOpen)
2922: TtaInitMenuItemStats(doc);
2923: TtaInitTopMenuStats(doc);
1.1084 gully 2924: #endif /* _WX */
2925:
1.338 cvs 2926: /* open the main view */
1.1134 gully 2927: if (docType == docLog)
2928: /* without menu bar */
2929: mainView = TtaOpenMainView (doc, DocumentTypeNames[docType], x, y, w, h, FALSE, FALSE,
2930: window_id, page_id, page_position);
2931: else if (docType == docLibrary && method == CE_RELATIVE)
2932: /* without menu bar */
2933: mainView = TtaOpenMainView (doc, DocumentTypeNames[docType], x, y, w, h, FALSE, TRUE,
2934: window_id, page_id, page_position);
2935: else
2936: mainView = TtaOpenMainView (doc, DocumentTypeNames[docType], x, y, w, h, TRUE, TRUE,
2937: window_id, page_id, page_position);
2938: if (mainView == 0)
2939: {
2940: TtaCloseDocument (doc);
2941: return (0);
2942: }
1.1104 gully 2943:
2944: #ifdef _WX
1.1134 gully 2945: /* init the zoom factor to 0 if the document isn't replaced */
2946: if (!replaceOldDoc/* && docType!=docSource*/)
2947: TtaSetZoom (doc, -1, 0);
1.1104 gully 2948: #endif /* _WX */
1.946 gully 2949:
1.1005 vatton 2950: /* update the menus according to the profile */
1.458 cvs 2951: /* By default no log file */
1.1134 gully 2952: TtaSetItemOff (doc, 1, File, BShowLogFile);
1.1139 tollenae 2953: #ifndef TEMPLATES
2954: TtaSetItemOff (doc, 1, File, BTemplate);
2955: #endif /* TEMPLATES */
1.872 kahan 2956:
1.940 cvs 2957: #ifndef DAV /* don't active the WebDAV menu if flag is off */
1.1134 gully 2958: TtaSetMenuOff (doc, 1, Cooperation_);
2959: TtaSetItemOff (doc, 1, Edit_, BCoopConfig);
1.940 cvs 2960: #endif /* DAV */
2961:
1.1134 gully 2962: /* do we have to redraw buttons and menus? */
2963: reinitialized = (docType != DocumentTypes[doc]);
2964: if (docType == docLog || docType == docLibrary || docType == docSource)
2965: {
1.1084 gully 2966: #ifdef _WX
2967: #ifdef _SVG
1.1134 gully 2968: if (docType == docLibrary)
2969: {
2970: /* Initialize SVG Library Buffer string */
2971: TtaAddTextZone (doc, 1, TtaGetMessage (AMAYA, AM_OPEN_URL),
2972: FALSE, (Proc)OpenLibraryCallback, SVGlib_list);
2973: }
1.1084 gully 2974: #endif /* _SVG */
2975: #endif /* _WX */
2976:
2977: #ifndef _WX
1.1134 gully 2978: TtcSwitchButtonBar (doc, 1); /* no button bar */
2979: if (docType != docLibrary)
2980: TtcSwitchCommands (doc, 1); /* no command open */
2981: else
2982: {
1.884 vatton 2983: #ifdef _SVG
1.1134 gully 2984: /* Initialize SVG Library Buffer string */
2985: TtaAddTextZone (doc, 1, TtaGetMessage (AMAYA, AM_OPEN_URL),
2986: FALSE, (Proc)OpenLibraryCallback, SVGlib_list);
1.930 vatton 2987: #endif /* _SVG */
1.1134 gully 2988: }
1.1084 gully 2989: #endif /* _WX */
1.1134 gully 2990: }
2991: else if (!isOpen)
2992: /* if isOpen is true, it means that a new window has been opened for this document
2993: * we must initialize each things that must be initialized once for the window */
2994: {
2995: /* create the button bar */
1.1150 vatton 2996: #ifndef _WX
1.1134 gully 2997: /* use a new window: Create all buttons */
2998: iStop =TtaAddButton (doc, 1, stopN, (Proc)StopTransfer,"StopTransfer",
2999: TtaGetMessage (LIB,TMSG_BUTTON_INTERRUPT),
3000: TBSTYLE_BUTTON, FALSE);
3001: iBack = TtaAddButton (doc, 1, iconBackNo, (Proc)GotoPreviousHTML,
3002: "GotoPreviousHTML",
3003: TtaGetMessage (LIB,TMSG_BUTTON_PREVIOUS),
3004: TBSTYLE_BUTTON, FALSE);
3005: iForward = TtaAddButton (doc, 1, iconForwardNo, (Proc)GotoNextHTML,
3006: "GotoNextHTML",
3007: TtaGetMessage (LIB,TMSG_BUTTON_NEXT),
3008: TBSTYLE_BUTTON, FALSE);
3009: iReload = TtaAddButton (doc, 1, iconReload, (Proc)Reload, "Reload",
3010: TtaGetMessage (LIB,TMSG_BUTTON_RELOAD),
3011: TBSTYLE_BUTTON, TRUE);
3012: iHome = TtaAddButton (doc, 1, iconHome, (Proc)GoToHome, "GoToHome",
3013: TtaGetMessage (LIB,TMSG_BUTTON_HOME),
3014: TBSTYLE_BUTTON, TRUE);
3015: /* SEPARATOR */
3016: TtaAddButton (doc, 1, None, NULL, NULL, NULL, TBSTYLE_SEP, FALSE);
3017: iSave = TtaAddButton (doc, 1, iconSaveNo, (Proc)SaveDocument,
3018: "SaveDocument",
3019: TtaGetMessage (LIB,TMSG_BUTTON_SAVE),
3020: TBSTYLE_BUTTON, FALSE);
3021: iPrint = TtaAddButton (doc, 1, iconPrint, (Proc)SetupAndPrint, "SetupAndPrint",
3022: TtaGetMessage (LIB,TMSG_BUTTON_PRINT),
3023: TBSTYLE_BUTTON, TRUE);
3024: iFind = TtaAddButton (doc, 1, iconFind, (Proc)TtcSearchText,
3025: "TtcSearchText",
3026: TtaGetMessage (LIB,TMSG_BUTTON_SEARCH),
3027: TBSTYLE_BUTTON, TRUE);
3028: /* SEPARATOR */
3029: TtaAddButton (doc, 1, None, NULL, NULL, NULL, TBSTYLE_SEP, FALSE);
3030: iI = TtaAddButton (doc, 1, iconI, (Proc)SetOnOffEmphasis,
3031: "SetOnOffEmphasis",
3032: TtaGetMessage (LIB,TMSG_BUTTON_ITALICS),
3033: TBSTYLE_CHECK, TRUE);
3034: iB = TtaAddButton (doc, 1, iconB, (Proc)SetOnOffStrong, "SetOnOffStrong",
3035: TtaGetMessage (LIB,TMSG_BUTTON_BOLD),
3036: TBSTYLE_CHECK, TRUE);
3037: iT = TtaAddButton (doc, 1, iconT, (Proc)SetOnOffCode, "SetOnOffCode",
3038: TtaGetMessage (LIB,TMSG_BUTTON_CODE),
3039: TBSTYLE_CHECK, TRUE);
3040: /* SEPARATOR */
3041: TtaAddButton (doc, 1, None, NULL, NULL, NULL, TBSTYLE_SEP, FALSE);
3042: iImage = TtaAddButton (doc, 1, iconImage, (Proc)CreateImage,
3043: "CreateImage",
3044: TtaGetMessage (LIB,TMSG_BUTTON_IMG),
3045: TBSTYLE_BUTTON, TRUE);
3046: iH1 = TtaAddButton (doc, 1, iconH1, (Proc)CreateHeading1,
3047: "CreateHeading1",
3048: TtaGetMessage (LIB,TMSG_BUTTON_H1),
3049: TBSTYLE_BUTTON, TRUE);
3050: iH2 = TtaAddButton (doc, 1, iconH2, (Proc)CreateHeading2,
3051: "CreateHeading2",
3052: TtaGetMessage (LIB,TMSG_BUTTON_H2),
3053: TBSTYLE_BUTTON, TRUE);
3054: iH3 = TtaAddButton (doc, 1, iconH3, (Proc)CreateHeading3,
3055: "CreateHeading3",
3056: TtaGetMessage (LIB,TMSG_BUTTON_H3),
3057: TBSTYLE_BUTTON, TRUE);
3058: iBullet = TtaAddButton (doc, 1, iconBullet, (Proc)CreateList,
3059: "CreateList",
3060: TtaGetMessage (LIB,TMSG_BUTTON_UL),
3061: TBSTYLE_BUTTON, TRUE);
3062: iNum = TtaAddButton (doc, 1, iconNum, (Proc)CreateNumberedList,
3063: "CreateNumberedList",
3064: TtaGetMessage (LIB,TMSG_BUTTON_OL),
3065: TBSTYLE_BUTTON, TRUE);
3066: iDL = TtaAddButton (doc, 1, iconDL, (Proc)CreateDefinitionList,
3067: "CreateDefinitionList",
3068: TtaGetMessage (LIB,TMSG_BUTTON_DL),
3069: TBSTYLE_BUTTON, TRUE);
3070: iLink = TtaAddButton (doc, 1, iconLink, (Proc)CreateOrChangeLink,
3071: "CreateOrChangeLink",
3072: TtaGetMessage (LIB,TMSG_BUTTON_LINK),
3073: TBSTYLE_BUTTON, TRUE);
3074: iTable = TtaAddButton (doc, 1, iconTable, (Proc)CreateTable,
3075: "CreateTable",
3076: TtaGetMessage (LIB,TMSG_BUTTON_TABLE),
3077: TBSTYLE_BUTTON, TRUE);
3078: AddMathButton (doc, 1);
1.652 vatton 3079: #ifdef _SVG
1.1134 gully 3080: AddGraphicsButton (doc, 1);
3081: AddLibraryButton (doc, 1);
1.847 cheyroul 3082: #ifdef _GL
1.1134 gully 3083: AddAnimPlayButton (doc, 1);
1.847 cheyroul 3084: #endif /*_GL*/
1.799 vatton 3085: #endif /* _SVG */
1.1005 vatton 3086: #endif /* _WX */
1.1077 gully 3087:
3088: #ifndef _WX
1.1134 gully 3089: TtaAddTextZone (doc, 1, TtaGetMessage (AMAYA, AM_OPEN_URL),
3090: TRUE, (Proc)TextURL, URL_list);
1.1077 gully 3091: #endif /* _WX */
1.393 cvs 3092:
1.1106 vatton 3093: #if defined(_GTK) || defined(_WINGUI)
1.1134 gully 3094: /* initial state for menu entries */
3095: TtaSetItemOff (doc, 1, File, BBack);
3096: TtaSetItemOff (doc, 1, File, BForward);
3097: TtaSetItemOff (doc, 1, File, BSave);
3098: TtaSetItemOff (doc, 1, File, BSynchro);
3099:
3100: /* button bar On/Off => TODO for WX */
3101: if (SButtons[doc] && docType != docBookmark)
3102: TtaSetToggleItem (doc, 1, Views, TShowButtonbar, TRUE);
3103: else
3104: /* hide buttons */
3105: TtcSwitchButtonBar (doc, 1);
1.1073 gully 3106:
1.1134 gully 3107: /* Url bar On/Off => TODO for WX */
3108: if (SAddress[doc])
3109: TtaSetToggleItem (doc, 1, Views, TShowTextZone, TRUE);
3110: else
3111: /* hide the address */
3112: TtcSwitchCommands (doc, 1);
3113:
3114: /* MapArea menu item */
3115: TtaSetToggleItem (doc, 1, Views, TShowMapAreas, MapAreas[doc]);
3116: TtaSetMenuOff (doc, 1, Attributes_);
3117:
1.1175 cvs 3118: /* SplitView menu items */
3119: TtaSetToggleItem (doc, 1, Views, TSplitHorizontally, HSplit[doc]);
3120: TtaSetToggleItem (doc, 1, Views, TSplitVertically, VSplit[doc]);
3121:
3122: TtaSetMenuOff (doc, 1, Attributes_);
3123:
1.1134 gully 3124: /* if we open the new document in a new view, control */
3125: /* is transferred from previous document to new document */
3126: if (oldDoc != doc && oldDoc != 0)
3127: {
3128: ResetStop (oldDoc);
3129: /* clear the status line of previous document */
3130: TtaSetStatus (oldDoc, 1, " ", NULL);
3131: ActiveTransfer (doc);
3132: }
1.1106 vatton 3133: #endif /* _GTK || _WINGUI */
1.1084 gully 3134:
3135:
1.1134 gully 3136: } /* isOpen */
3137: }
1.1073 gully 3138:
1.1134 gully 3139: if (!replaceOldDoc || !isOpen)
3140: {
1.1073 gully 3141: #ifdef _WX
1.1134 gully 3142: /* initial state for menu entries */
3143: TtaSetItemOff (doc, 1, File, BBack);
3144: TtaSetItemOff (doc, 1, File, BForward);
3145: TtaSetItemOff (doc, 1, File, BSave);
3146: TtaSetItemOff (doc, 1, File, BSynchro);
3147: TtaSetMenuOff (doc, 1, Attributes_);
3148:
3149: /* init MapAreas menu item */
3150: TtaSetToggleItem (doc, 1, Views, TShowMapAreas, MapAreas[doc]);
1.1073 gully 3151: #endif /* _WX */
1.1134 gully 3152: }
1.276 cvs 3153:
1.1150 vatton 3154: /* store the new document type */
3155: DocumentTypes[doc] = docType;
1.976 gully 3156: #if _WX
3157: /* now be sure that the urlbar is setup */
1.1077 gully 3158: TtaAddTextZone ( doc, 1, TtaGetMessage (AMAYA, AM_OPEN_URL),
3159: TRUE, (Proc)TextURL, URL_list );
1.1150 vatton 3160: #endif /* _WX */
1.1077 gully 3161:
1.1151 vatton 3162: if ((DocumentTypes[doc] == docHTML ||
1.1150 vatton 3163: DocumentTypes[doc] == docSVG ||
3164: DocumentTypes[doc] == docXml ||
3165: DocumentTypes[doc] == docMath ||
3166: DocumentTypes[doc] == docLibrary)
1.1151 vatton 3167: #ifndef _WX
3168: && !replaceOldDoc
3169: #endif /* _WX */
3170: )
1.994 gully 3171: {
1.1150 vatton 3172: /* init show target menu item */
3173: TtaGetEnvBoolean ("SHOW_TARGET", &show);
3174: if (show)
3175: ShowTargets (doc, 1);
3176: else
3177: TtaSetToggleItem (doc, 1, Views, TShowTargets, FALSE);
1.994 gully 3178: }
1.1134 gully 3179: if (reinitialized || !isOpen)
3180: {
1.1184 vatton 3181: if (reinitialized && visibility == 4)
3182: {
3183: // restore the visibility
3184: TtaSetSensibility (doc, 1, visibility);
3185: TtaSetToggleItem (doc, 1, Views, TShowTargets, TRUE);
3186: }
1.1134 gully 3187: /* now update menus and buttons according to the document status */
3188: if (DocumentTypes[doc] == docLog ||
3189: DocumentTypes[doc] == docLibrary ||
3190: DocumentTypes[doc] == docBookmark)
3191: {
1.1152 vatton 3192: if (DocumentTypes[doc] != docBookmark)
1.1134 gully 3193: {
3194: TtaSetItemOff (doc, 1, File, BHtmlBasic);
3195: TtaSetItemOff (doc, 1, File, BHtmlStrict);
3196: TtaSetItemOff (doc, 1, File, BHtml11);
3197: TtaSetItemOff (doc, 1, File, BHtmlTransitional);
3198: TtaSetItemOff (doc, 1, File, BMathml);
3199: TtaSetItemOff (doc, 1, File, BSvg);
3200: TtaSetItemOff (doc, 1, File, BTemplate);
3201: TtaSetItemOff (doc, 1, File, BCss);
3202: TtaSetItemOff (doc, 1, File, BOpenDoc);
3203: TtaSetItemOff (doc, 1, File, BReload);
3204: TtaSetItemOff (doc, 1, File, BBack);
3205: TtaSetItemOff (doc, 1, File, BForward);
1.1013 vatton 3206: #ifdef ANNOTATIONS
1.1134 gully 3207: TtaSetMenuOff (doc, 1, Annotations_);
3208: TtaSetItemOff (doc, 1, Edit_, BConfigAnnotations);
1.1013 vatton 3209: #endif /* ANNOTATIONS */
1.1134 gully 3210: }
3211: TtaSetItemOff (doc, 1, File, BSave);
3212: TtaSetItemOff (doc, 1, File, BSynchro);
3213: TtaSetItemOff (doc, 1, File, BDocInfo);
3214: TtaSetItemOff (doc, 1, File, BSetUpandPrint);
3215: TtaSetItemOff (doc, 1, File, BPrint);
3216: SetCharsetMenuOff (doc, 1); /* no charset commands */
3217: /* invalid the DoctypeMenu */
3218: TtaSetItemOff (doc, 1, File, BRemoveDoctype);
3219: TtaSetItemOff (doc, 1, File, BAddDoctype);
3220: TtaSetItemOff (doc, 1, File, BDoctypeXhtml11);
3221: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlTransitional);
3222: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlStrict);
3223: TtaSetItemOff (doc, 1, File, BDoctypeXhtmlBasic);
3224: TtaSetItemOff (doc, 1, File, BDoctypeHtmlTransitional);
3225: TtaSetItemOff (doc, 1, File, BDoctypeHtmlStrict);
3226: TtaSetItemOff (doc, 1, Edit_, BTransform);
3227: TtaSetMenuOff (doc, 1, Types);
3228: TtaSetMenuOff (doc, 1, XMLTypes);
3229: TtaSetMenuOff (doc, 1, Links);
3230: TtaSetMenuOff (doc, 1, Views);
3231: TtaSetMenuOff (doc, 1, Style);
3232: TtaSetMenuOff (doc, 1, Attributes_);
3233: TtaSetMenuOff (doc, 1, Help_);
3234: if (docType != docBookmark)
3235: {
3236: TtaSetItemOff (doc, 1, File, BExit);
3237: TtaSetMenuOff (doc, 1, Edit_);
3238: if (docType != docLibrary)
3239: TtaSetDocumentAccessMode (doc, 0);
3240: }
3241: }
3242: else if (DocumentTypes[doc] == docText ||
3243: DocumentTypes[doc] == docSource ||
3244: DocumentTypes[doc] == docCSS ||
3245: DocumentTypes[doc] == docMath)
3246: {
1.1156 vatton 3247: #ifdef _WX
3248: TtaSetMenuOn (doc, 1, Style);
3249: if (DocumentTypes[doc] == docMath)
3250: {
3251: TtaSetItemOn (doc, 1, Style, BCreateClass);
3252: TtaSetItemOn (doc, 1, Style, BShowAppliedStyle);
3253: TtaSetItemOn (doc, 1, Style, BLinkCSS);
3254: TtaSetItemOn (doc, 1, Style, BOpenCSS);
3255: TtaSetItemOn (doc, 1, Style, BDisableCSS);
3256: TtaSetItemOn (doc, 1, Style, BEnableCSS);
3257: TtaSetItemOn (doc, 1, Style, BRemoveCSS);
3258: }
3259: else
3260: {
3261: TtaSetItemOff (doc, 1, Style, BCreateClass);
3262: TtaSetItemOff (doc, 1, Style, BShowAppliedStyle);
3263: TtaSetItemOff (doc, 1, Style, BLinkCSS);
3264: TtaSetItemOff (doc, 1, Style, BOpenCSS);
3265: TtaSetItemOff (doc, 1, Style, BDisableCSS);
3266: TtaSetItemOff (doc, 1, Style, BEnableCSS);
3267: TtaSetItemOff (doc, 1, Style, BRemoveCSS);
3268: }
3269: #else /* _WX */
3270: if (DocumentTypes[doc] == docMath)
3271: TtaSetMenuOn (doc, 1, Style);
3272: else
3273: TtaSetMenuOff (doc, 1, Style);
1.1134 gully 3274: TtaChangeButton (doc, 1, iI, iconINo, FALSE);
3275: TtaChangeButton (doc, 1, iB, iconBNo, FALSE);
3276: TtaChangeButton (doc, 1, iT, iconTNo, FALSE);
3277: TtaChangeButton (doc, 1, iImage, iconImageNo, FALSE);
3278: TtaChangeButton (doc, 1, iH1, iconH1No, FALSE);
3279: TtaChangeButton (doc, 1, iH2, iconH2No, FALSE);
3280: TtaChangeButton (doc, 1, iH3, iconH3No, FALSE);
3281: TtaChangeButton (doc, 1, iBullet, iconBulletNo, FALSE);
3282: TtaChangeButton (doc, 1, iNum, iconNumNo, FALSE);
3283: TtaChangeButton (doc, 1, iDL, iconDLNo, FALSE);
3284: TtaChangeButton (doc, 1, iTable, iconTableNo, FALSE);
3285: TtaChangeButton (doc, 1, iLink, iconLinkNo, FALSE);
3286: #endif /* _WX */
3287: TtaSetItemOff (doc, 1, Views, TShowMapAreas);
3288: TtaSetItemOff (doc, 1, Views, TShowTargets);
3289: TtaSetMenuOff (doc, 1, Doctype1);
3290: TtaSetMenuOff (doc, 1, Types);
3291: TtaSetMenuOff (doc, 1, Links);
3292: if (DocumentTypes[doc] == docMath)
3293: {
3294: TtaSetItemOff (doc, 1, XMLTypes, BShowLibrary);
3295: TtaSetItemOff (doc, 1, XMLTypes, BAddNewModel);
3296: TtaSetMenuOn (doc, 1, XMLTypes);
3297: TtaSetMenuOn (doc, 1, Views);
3298: TtaSetMenuOn (doc, 1, Attributes_);
1.1005 vatton 3299: #ifdef _SVG
1.1134 gully 3300: SwitchIconGraph (doc, 1, FALSE);
3301: SwitchIconLibrary (doc, 1, FALSE);
1.1005 vatton 3302: #endif /* _SVG */
1.1134 gully 3303: }
3304: else
3305: {
1.1003 vatton 3306: #ifdef _WX
1.1134 gully 3307: if (DocumentTypes[doc] != docSource)
1.1003 vatton 3308: #endif /* _WX */
1.1134 gully 3309: TtaSetMenuOff (doc, 1, Views);
3310: TtaSetItemOff (doc, 1, Edit_, BTransform);
3311: SwitchIconMath (doc, 1, FALSE);
3312: TtaSetMenuOff (doc, 1, XMLTypes);
3313: TtaSetMenuOff (doc, 1, Attributes_);
1.1005 vatton 3314: #ifdef ANNOTATIONS
1.1134 gully 3315: TtaSetMenuOff (doc, 1, Annotations_);
1.1005 vatton 3316: #endif /* ANNOTATIONS */
1.1134 gully 3317: }
3318: }
3319: else if (DocumentTypes[doc] == docAnnot)
3320: {
1.1087 gully 3321: #ifndef _WX
1.1134 gully 3322: TtcSwitchCommands (doc, 1); /* no command open */
1.1087 gully 3323: #endif /* _WX */
1.1134 gully 3324: TtaSetItemOff (doc, 1, Views, BShowAlternate);
3325: TtaSetItemOff (doc, 1, Views, BShowToC);
3326: TtaSetItemOff (doc, 1, Views, BShowSource);
3327: TtaSetItemOff (doc, 1, Views, BShowTimeLine);
3328: }
3329: else
3330: {
3331: TtaSetMenuOn (doc, 1, Views);
3332: TtaSetItemOn (doc, 1, Views, TShowTargets);
3333: TtaSetItemOn (doc, 1, Views, BShowLinks);
3334: /* turn off the assign annotation buttons (should be
3335: contextual */
3336: TtaSetItemOff (doc, 1, Annotations_, BReplyToAnnotation);
3337: TtaSetItemOff (doc, 1, Annotations_, BMoveAnnotSel);
3338: TtaSetItemOff (doc, 1, Annotations_, BMoveAnnotXPtr);
3339: TtaSetItemOff (doc, 1, Annotations_, BPostAnnot);
3340: if (DocumentTypes[doc] == docHTML)
3341: {
3342: TtaSetItemOn (doc, 1, Views, TShowMapAreas);
3343: TtaSetItemOn (doc, 1, Views, BShowAlternate);
3344: TtaSetItemOn (doc, 1, Views, BShowToC);
3345: TtaSetItemOn (doc, 1, Types, BTitle);
3346: if (profile == L_Strict || profile == L_Basic)
3347: {
3348: TtaSetMenuOff (doc, 1, XMLTypes);
3349: TtaSetItemOff (doc, 1, Views, BShowTimeLine);
3350: }
3351: else
3352: TtaSetItemOn (doc, 1, Views, BShowTimeLine);
3353: }
3354: else
3355: {
3356: TtaSetItemOff (doc, 1, Views, TShowMapAreas);
3357: TtaSetItemOff (doc, 1, Views, BShowToC);
3358: if (DocumentTypes[doc] == docSVG)
3359: {
3360: TtaSetItemOn (doc, 1, Views, BShowAlternate);
3361: TtaSetItemOff (doc, 1, Types, BTitle);
3362: TtaSetItemOn (doc, 1, Views, BShowTimeLine);
3363: }
3364: else
3365: {
3366: TtaSetItemOff (doc, 1, Views, BShowAlternate);
3367: TtaSetItemOff (doc, 1, Views, BShowTimeLine);
3368: }
3369: }
3370: }
3371: }
1.1098 gully 3372:
3373: #ifdef _WX
1.1134 gully 3374: // show the window if it's not allready done
3375: TtaShowWindow( window_id, TRUE );
1.1098 gully 3376: #endif /* _WX */
3377:
1.1134 gully 3378: return (doc);
1.6 cvs 3379: }
3380:
1.9 cvs 3381: /*----------------------------------------------------------------------
1.938 vatton 3382: CreateHTMLContainer create an HTML container for an image
1.248 cvs 3383: ----------------------------------------------------------------------*/
1.547 cvs 3384: static void CreateHTMLContainer (char *pathname, char *docname,
1.1136 gully 3385: char *tempfile, ThotBool local)
1.248 cvs 3386: {
3387: FILE *file;
1.547 cvs 3388: char *tempfile_new;
3389: char *ptr;
1.248 cvs 3390:
3391: if (!local)
3392: {
3393: /* Rename the current downloaded file (an image) so that we can
1.1136 gully 3394: find it easily next time around.
3395: The convention is to change the image's extension to 'html',
3396: and give the HTML's container the image's extension */
1.907 gully 3397: tempfile_new = (char *)TtaGetMemory (strlen (tempfile) + strlen (docname) + 10);
1.547 cvs 3398: strcpy (tempfile_new, tempfile);
3399: ptr = strrchr (tempfile_new, DIR_SEP);
1.248 cvs 3400: ptr++;
1.547 cvs 3401: strcpy (ptr, docname);
1.906 vatton 3402: SetContainerImageName (tempfile_new);
3403: TtaFileUnlink (tempfile_new);
3404: if (TtaFileCopyUncompress (tempfile, tempfile_new))
1.1136 gully 3405: /* copy done */
3406: TtaFileUnlink (tempfile);
1.248 cvs 3407: else
1.1136 gully 3408: /* change the tempfile name */
3409: sprintf (tempfile_new, "%s", tempfile);
1.248 cvs 3410: TtaFreeMemory (tempfile_new);
3411: }
3412: /* create a temporary file for the container and make Amaya think
3413: that it is the current downloaded file */
1.1050 vatton 3414: file = TtaWriteOpen (tempfile);
1.805 vatton 3415: fprintf (file, "<html><head><title>%s</title></head><body>", docname);
1.248 cvs 3416: if (local)
1.1119 quint 3417: fprintf (file, "<img src=\"%s\" alt=\"iamge\">", pathname);
1.248 cvs 3418: else
1.1119 quint 3419: fprintf (file, "<img src=\"internal:%s\" alt=\"iamge\">", pathname);
1.638 kahan 3420: fprintf (file, "</body></html>");
1.1050 vatton 3421: TtaWriteClose (file);
1.248 cvs 3422: }
3423:
3424: /*----------------------------------------------------------------------
1.254 cvs 3425: MoveImageFile moves an image file (related to an HTML container) from
3426: one directory to another
3427: ----------------------------------------------------------------------*/
3428: static void MoveImageFile (Document source_doc, Document dest_doc,
1.1136 gully 3429: char *documentname)
1.254 cvs 3430: {
1.547 cvs 3431: char *source;
3432: char *target;
3433: char *imagefile;
3434: char *ptr;
1.254 cvs 3435:
3436: /* generate the name of the file where is stored the image */
1.907 gully 3437: imagefile = (char *)TtaGetMemory (strlen (documentname) + 6);
1.547 cvs 3438: strcpy (imagefile, documentname);
3439: ptr = strrchr (imagefile, '.');
1.268 cvs 3440: if (!ptr)
1.1136 gully 3441: strcat (imagefile, ".html");
1.268 cvs 3442: else
1.1136 gully 3443: strcpy (&(ptr[1]), "html");
1.268 cvs 3444:
1.254 cvs 3445: /* create the source and dest file names */
1.907 gully 3446: source = (char *)TtaGetMemory (strlen (TempFileDirectory) + strlen (imagefile) + 6);
1.547 cvs 3447: sprintf (source, "%s%c%d%c%s",
1.1136 gully 3448: TempFileDirectory, DIR_SEP, source_doc, DIR_SEP, imagefile);
1.907 gully 3449: target = (char *)TtaGetMemory (strlen (TempFileDirectory) + strlen (imagefile) + 6);
1.547 cvs 3450: sprintf (target, "%s%c%d%c%s",
1.1136 gully 3451: TempFileDirectory, DIR_SEP, dest_doc, DIR_SEP, imagefile);
1.254 cvs 3452:
3453: /* move the file */
3454: TtaFileCopy (source, target);
3455: TtaFileUnlink (source);
3456:
3457: TtaFreeMemory (source);
3458: TtaFreeMemory (target);
3459: TtaFreeMemory (imagefile);
3460: }
3461:
3462: /*----------------------------------------------------------------------
1.1136 gully 3463: ReparseAs
3464: Load current document considering it's a HTML document and/or
3465: with a new charset (charset != UNDEFINED_CHARSET).
1.569 cvs 3466: ----------------------------------------------------------------------*/
1.951 vatton 3467: void ReparseAs (Document doc, View view, ThotBool asHTML,
1.1136 gully 3468: CHARSET charset)
1.569 cvs 3469: {
1.951 vatton 3470: CHARSET doc_charset;
3471: DocumentType thotType;
3472: char *localFile = NULL;
1.950 vatton 3473: char documentname[MAX_LENGTH];
1.951 vatton 3474: char s[MAX_LENGTH], charsetname[MAX_LENGTH];
3475: int i, parsingLevel;
1.966 vatton 3476: ThotBool plaintext;
1.1163 vatton 3477: ThotBool xmlDec, withDoctype, isXML, useMath, isKnown;
1.950 vatton 3478:
3479: if (DocumentURLs[doc] == NULL ||
3480: (asHTML && !DocumentMeta[doc]->xmlformat))
3481: /* the document is not concerned by this option */
3482: return;
3483: if (!CanReplaceCurrentDocument (doc, view))
3484: /* abort the command */
3485: return;
1.569 cvs 3486:
1.950 vatton 3487: /* Initialize the LogFile variables */
3488: CleanUpParsingErrors ();
3489: /* remove the PARSING.ERR file */
3490: RemoveParsingErrors (doc);
3491: /* Remove the previous namespaces declaration */
3492: TtaFreeNamespaceDeclarations (doc);
1.951 vatton 3493: localFile = GetLocalPath (doc, DocumentURLs[doc]);
3494: TtaExtractName (localFile, s, documentname);
1.950 vatton 3495: for (i = 1; i < DocumentTableLength; i++)
3496: if (DocumentURLs[i] != NULL && DocumentSource[i] == doc)
3497: {
1.1136 gully 3498: DocumentSource[i] = 0;
3499: if (DocumentTypes[i] == docLog)
3500: {
3501: /* close the window of the log file attached to the
3502: current document */
3503: TtaCloseDocument (i);
3504: TtaFreeMemory (DocumentURLs[i]);
3505: DocumentURLs[i] = NULL;
3506: /* switch off the button Show Log file */
3507: TtaSetItemOff (doc, 1, File, BShowLogFile);
3508: }
1.950 vatton 3509: }
1.569 cvs 3510:
1.950 vatton 3511: /* Removes all CSS informations linked with the document */
3512: RemoveDocCSSs (doc);
3513: /* Free access keys table */
3514: TtaRemoveDocAccessKeys (doc);
3515: if (asHTML)
1.1169 vatton 3516: {
3517: DocumentMeta[doc]->xmlformat = FALSE;
3518: DocumentMeta[doc]->compound = FALSE;
3519: }
1.950 vatton 3520: if (charset != UNDEFINED_CHARSET &&
3521: charset != TtaGetDocumentCharset (doc))
3522: {
3523: /* Update the charset info */
3524: TtaSetDocumentCharset (doc, charset, FALSE);
3525: if (DocumentMeta[doc]->charset)
1.1136 gully 3526: TtaFreeMemory (DocumentMeta[doc]->charset);
1.950 vatton 3527: DocumentMeta[doc]->charset = TtaStrdup (TtaGetCharsetName (charset));
3528: }
3529: /* parse with the HTML parser */
3530: if (DocumentMeta[doc]->xmlformat)
1.951 vatton 3531: {
3532: /* check if there is an XML declaration with a charset declaration */
3533: charsetname[0] = EOS;
1.1163 vatton 3534: CheckDocHeader (localFile, &xmlDec, &withDoctype, &isXML, &useMath, &isKnown,
1.1136 gully 3535: &parsingLevel, &doc_charset, charsetname, &thotType);
1.953 cvs 3536: StartXmlParser (doc, localFile, documentname, s,
1.1163 vatton 3537: localFile, xmlDec, withDoctype, useMath, FALSE);
1.951 vatton 3538: }
1.950 vatton 3539: else
1.951 vatton 3540: {
3541: plaintext = (DocumentTypes[doc] == docCSS ||
1.1136 gully 3542: DocumentTypes[doc] == docText);
1.956 cvs 3543: StartParser (doc, localFile, documentname, s, localFile, plaintext, FALSE);
1.951 vatton 3544: }
1.950 vatton 3545:
3546: /* fetch and display all images referred by the document */
3547: DocNetworkStatus[doc] = AMAYA_NET_ACTIVE;
3548: FetchAndDisplayImages (doc, AMAYA_LOAD_IMAGE, NULL);
3549: DocNetworkStatus[doc] = AMAYA_NET_INACTIVE;
1.966 vatton 3550: if (!asHTML &&
1.986 vatton 3551: !XMLNotWellFormed && !XMLInvalidToken && !XMLCharacterNotSupported &&
1.966 vatton 3552: !XMLErrorsFoundInProfile && !XMLErrorsFound)
1.962 vatton 3553: {
1.966 vatton 3554: /* No error found -> Update the source of the document */
1.962 vatton 3555: TtaSetDocumentModified (doc);
3556: Synchronize (doc, view);
1.966 vatton 3557: TtaSetDocumentUnmodified (doc);
1.962 vatton 3558: }
1.950 vatton 3559: /* check parsing errors */
3560: CheckParsingErrors (doc);
1.951 vatton 3561: TtaFreeMemory (localFile);
1.950 vatton 3562: }
1.845 cvs 3563:
1.950 vatton 3564: /*----------------------------------------------------------------------
1.1136 gully 3565: ParseAsHTML
3566: Load current document considering it's a HTML document
1.950 vatton 3567: ----------------------------------------------------------------------*/
3568: void ParseAsHTML (Document doc, View view)
3569: {
1.1177 vatton 3570: char *localFile = NULL;
3571: char documentname[MAX_LENGTH];
3572: char s[MAX_LENGTH];
3573:
3574: /* Initialize the LogFile variables */
3575: CleanUpParsingErrors ();
3576: /* remove the PARSING.ERR file */
3577: RemoveParsingErrors (doc);
3578: /* Remove the previous namespaces declaration */
3579: TtaFreeNamespaceDeclarations (doc);
3580: localFile = GetLocalPath (doc, DocumentURLs[doc]);
3581: TtaExtractName (localFile, s, documentname);
3582: /* Removes all CSS informations linked with the document */
3583: RemoveDocCSSs (doc);
3584: /* Free access keys table */
3585: TtaRemoveDocAccessKeys (doc);
1.1179 vatton 3586: // ignore the XML format
3587: if (DocumentMeta && DocumentMeta[doc]->xmlformat)
3588: DocumentMeta[doc]->xmlformat = FALSE;
1.1177 vatton 3589: StartParser (doc, localFile, documentname, s, localFile, FALSE, FALSE);
1.1179 vatton 3590: // restore the XML format
3591: if (DocumentMeta && DocumentMeta[doc]->xmlformat)
3592: DocumentMeta[doc]->xmlformat = TRUE;
1.1177 vatton 3593: /* fetch and display all images referred by the document */
3594: DocNetworkStatus[doc] = AMAYA_NET_ACTIVE;
3595: FetchAndDisplayImages (doc, AMAYA_LOAD_IMAGE, NULL);
3596: DocNetworkStatus[doc] = AMAYA_NET_INACTIVE;
3597: /* check parsing errors */
3598: CheckParsingErrors (doc);
3599: TtaFreeMemory (localFile);
1.569 cvs 3600: }
3601:
1.935 quint 3602: #ifdef _SVG
3603: /*----------------------------------------------------------------------
3604: DisplaySVGtitle
3605: Get the first child of the root element of document doc that is of
3606: type title and display it as the title of the document window.
3607: doc must be a SVG document.
3608: ----------------------------------------------------------------------*/
3609: static void DisplaySVGtitle (Document doc)
3610: {
3611: Element root, child;
3612: SSchema SVGschema;
3613: ElementType elType;
3614: ThotBool found;
3615:
3616: root = TtaGetRootElement (doc);
3617: SVGschema = TtaGetDocumentSSchema (doc);
3618: child = TtaGetFirstChild (root);
3619: found = FALSE;
3620: while (child && !found)
3621: {
3622: elType = TtaGetElementType (child);
3623: if (elType.ElSSchema == SVGschema && elType.ElTypeNum == SVG_EL_title)
1.1136 gully 3624: found = TRUE;
1.935 quint 3625: else
1.1136 gully 3626: TtaNextSibling (&child);
1.935 quint 3627: }
3628: if (found)
3629: UpdateTitle (child, doc);
3630: }
3631: #endif /* _SVG */
3632:
1.569 cvs 3633: /*----------------------------------------------------------------------
1.542 cvs 3634: LoadDocument parses the new document and stores its path (or
1.220 cvs 3635: URL) into the document table.
1.290 cvs 3636: For a local loading, the parameter tempfile must be an empty string.
3637: For a remote loading, the parameter tempfile gives the file name that
3638: contains the current copy of the remote file.
1.1185 vatton 3639: Parameter realdocname is not NULL when the document is restored
1.9 cvs 3640: ----------------------------------------------------------------------*/
1.1129 tollenae 3641: Document LoadDocument (Document doc, char *pathname,
1.1136 gully 3642: char *form_data, char *initial_url,
3643: int method, char *tempfile,
3644: char *documentname, AHTHeaders *http_headers,
1.1185 vatton 3645: ThotBool history, ThotBool *inNewWindow,
3646: char *realdocname)
1.6 cvs 3647: {
1.293 cvs 3648: CSSInfoPtr css;
1.861 vatton 3649: PInfoPtr pInfo;
1.163 cvs 3650: Document newdoc = 0;
1.276 cvs 3651: DocumentType docType;
1.721 kahan 3652: #ifdef ANNOTATIONS
1.782 vatton 3653: DocumentType annotBodyType = docHTML;
1.721 kahan 3654: #endif /* ANNOTATIONS */
1.518 cvs 3655: CHARSET charset, httpcharset;
3656: CHARSET metacharset = UNDEFINED_CHARSET;
1.924 vatton 3657: char charsetname[MAX_LENGTH];
1.547 cvs 3658: char *charEncoding;
3659: char *tempdir;
1.924 vatton 3660: char *s, *localdoc;
1.1188 vatton 3661: char *content_type, *reason;
1.551 kahan 3662: char *http_content_type;
1.163 cvs 3663: int i, j;
1.905 vatton 3664: int docProfile;
3665: DocumentType thotType;
3666: char local_content_type[MAX_LENGTH];
1.461 cvs 3667: ThotBool unknown;
1.905 vatton 3668: ThotBool contentImage, contentText, contentApplication;
1.309 cvs 3669: ThotBool plainText;
1.1163 vatton 3670: ThotBool xmlDec, withDoctype, useMath, isXML, isknown;
1.917 kahan 3671: ThotBool isRDF;
1.248 cvs 3672:
1.917 kahan 3673: isRDF = FALSE;
1.464 cvs 3674: docType = docText;
1.461 cvs 3675: unknown = TRUE;
1.924 vatton 3676: tempdir = localdoc = NULL;
1.557 cvs 3677: charsetname[0] = EOS;
1.621 cvs 3678: local_content_type[0] = EOS;
1.551 kahan 3679: http_content_type = HTTP_headers (http_headers, AM_HTTP_CONTENT_TYPE);
1.1060 quint 3680: /* sometimes video or audio content is sent with an erroneous mime-type
3681: "text/plain". In that case, ignore the mime-type (glitch) */
3682: if (http_content_type && !strcmp (http_content_type, "text/plain") &&
3683: IsUndisplayedName (pathname))
3684: http_content_type = NULL;
1.551 kahan 3685: /* make a copy we can modify */
3686: if (http_content_type)
3687: content_type = TtaStrdup (http_content_type);
3688: else
3689: content_type = NULL;
3690:
1.726 cvs 3691: /* Check informations within the document */
1.547 cvs 3692: if (tempfile[0] != EOS)
1.924 vatton 3693: s = tempfile;
1.457 cvs 3694: else
1.924 vatton 3695: s = pathname;
1.922 cvs 3696:
1.1163 vatton 3697: CheckDocHeader (s, &xmlDec, &withDoctype, &isXML, &useMath, &isknown,
1.1136 gully 3698: &docProfile, &charset, charsetname, &thotType);
1.461 cvs 3699:
1.726 cvs 3700: /* Check charset information in a meta */
1.537 cvs 3701: if (charset == UNDEFINED_CHARSET)
1.924 vatton 3702: CheckCharsetInMeta (s, &metacharset, charsetname);
1.922 cvs 3703:
1.542 cvs 3704: if (method == CE_CSS)
3705: {
3706: /* we're loading a CSS file */
3707: docType = docCSS;
1.1018 vatton 3708: /* if a CSS document has a xml header, CheckDocHeader will detect that the document is XML !
3709: * (ex: http://www.inrialpes.fr has a css with a xml header :( )
3710: * when we know that the document is CSS (method == CE_CSS) we should force docType to docCSS */
3711: isXML = FALSE;
3712: unknown = FALSE;
3713: }
3714: else if (method == CE_LOG)
3715: {
3716: docType = docLog;
1.996 gully 3717: isXML = FALSE;
1.542 cvs 3718: unknown = FALSE;
3719: }
1.996 gully 3720: else if (content_type == NULL || content_type[0] == EOS)
1.728 cvs 3721: /* Local document - no content type */
1.163 cvs 3722: {
1.461 cvs 3723: /* check file name extension */
1.534 cvs 3724: if (isXML)
1.1136 gully 3725: {
3726: /* it seems to be a XML document */
3727: if (DocumentTypes[doc] == docLibrary)
3728: docType = docLibrary;
3729: else
3730: docType = thotType;
3731: unknown = FALSE;
3732: if (IsRDFName (pathname))
3733: isRDF = TRUE;
3734: }
1.917 kahan 3735: else if (IsRDFName (pathname))
1.1136 gully 3736: {
3737: /* it's an RDF document. By default we assume we will
3738: parse it as generic XML */
3739: docType = thotType;
3740: isRDF = TRUE;
3741: unknown = FALSE;
3742: }
3743: else if (IsCSSName (pathname))
3744: {
3745: docType = docCSS;
3746: docProfile = L_CSS;
3747: unknown = FALSE;
3748: }
3749: else if (IsTextName (pathname))
3750: {
3751: docType = docText;
3752: docProfile = L_Other;
3753: unknown = FALSE;
3754: }
1.478 cvs 3755: else if (IsImageName (pathname))
1.1136 gully 3756: {
3757: /* It's a local image file that we can display. We change the
3758: doctype flag so that we can create an HTML container later on */
3759: docType = docImage;
3760: unknown = FALSE;
3761: docProfile = L_Transitional;
3762: }
3763: else if (IsMathMLName (pathname))
3764: {
3765: docType = docMath;
3766: docProfile = L_MathML;
3767: isXML = TRUE;
3768: unknown = FALSE;
3769: }
3770: else if (IsSVGName (pathname))
3771: {
3772: docType = docSVG;
3773: docProfile = L_SVG;
3774: isXML = TRUE;
3775: unknown = FALSE;
3776: }
1.777 cvs 3777: #ifdef XML_GENERIC
3778: else if (IsXMLName (pathname))
1.1136 gully 3779: {
3780: docType = docXml;
3781: docProfile = L_Other;
3782: isXML = TRUE;
3783: unknown = FALSE;
3784: }
1.777 cvs 3785: #endif /* XML_GENERIC */
1.884 vatton 3786: #ifdef _SVG
1.765 cvs 3787: else if (IsLibraryName (pathname))
1.1136 gully 3788: {
3789: docType = docLibrary;
3790: unknown = FALSE;
3791: }
1.884 vatton 3792: #endif /* _SVG */
1.905 vatton 3793: else if (docProfile != L_Other || IsHTMLName (pathname))
1.1136 gully 3794: {
3795: /* it seems to be an HTML document */
3796: docType = docHTML;
3797: unknown = FALSE;
3798: }
1.621 cvs 3799: /* Assign a content type to that local document */
1.917 kahan 3800: if (isRDF)
1.1136 gully 3801: strcpy (local_content_type , "application/xml+rdf");
1.917 kahan 3802: else if (docType == docCSS)
1.1136 gully 3803: strcpy (local_content_type , "text/css");
1.747 kahan 3804: else if (docType == docMath)
1.1136 gully 3805: strcpy (local_content_type , AM_MATHML_MIME_TYPE);
1.621 cvs 3806: else if (docType == docSVG)
1.1136 gully 3807: strcpy (local_content_type , AM_SVG_MIME_TYPE);
1.621 cvs 3808: else if (docType == docXml)
1.1136 gully 3809: strcpy (local_content_type , "text/xml");
1.621 cvs 3810: else if (docType == docText || docType == docCSS ||
1.1136 gully 3811: docType == docSource || docType == docLog )
3812: strcpy (local_content_type , "text/plain");
1.768 vatton 3813: else if (docType == docHTML || docType == docLibrary)
1.1136 gully 3814: /* not defined yet */
3815: local_content_type[0] = EOS;
1.621 cvs 3816: }
1.1136 gully 3817: else
3818: /* The server returned a content type */
3819: {
3820: i = 0;
3821: while (content_type[i] != URL_SEP && content_type[i] != EOS)
3822: i++;
3823: if (content_type[i] == URL_SEP)
3824: {
3825: content_type[i] = EOS;
3826: j = i+1;
3827: while (content_type[j] != ';' && content_type[j] != EOS)
3828: j++;
3829: if (content_type[j] == ';')
3830: content_type[j] = EOS;
3831: contentText = !strcasecmp (content_type, "text");
3832: contentApplication = !strcasecmp (content_type, "application");
3833: contentImage = !strcasecmp (content_type, "image");
3834: if (contentText &&
3835: !strncasecmp (&content_type[i+1], "html", 4))
3836: {
3837: if (thotType == docSVG)
3838: {
3839: /* ignore the mime type */
3840: isXML = TRUE;
3841: docType = thotType;
3842: BADMimeType = TRUE;
3843: }
3844: else if (thotType == docMath)
3845: {
3846: /* ignore the mime type */
3847: isXML = TRUE;
3848: docType = thotType;
3849: BADMimeType = TRUE;
3850: }
3851: else
3852: {
3853: /* it's an HTML document */
3854: docType = docHTML;
3855: if (docProfile == L_Other)
3856: docProfile = L_Transitional;
3857: }
3858: unknown = FALSE;
3859: }
3860: else if (contentApplication &&
3861: !strncasecmp (&content_type[i+1], "html", 4))
3862: {
3863: /* it's an HTML document */
3864: docType = docHTML;
3865: if (docProfile == L_Other)
3866: docProfile = L_Transitional;
3867: unknown = FALSE;
3868: }
3869: else if ((contentText || contentApplication) &&
3870: (!strncasecmp (&content_type[i+1], "xhtml+xml", 9) ||
3871: !strncasecmp (&content_type[i+1], "xhtml", 5)))
3872: {
3873: /* it's an xhtml document */
3874: isXML = TRUE;
3875: docType = docHTML;
3876: if (docProfile == L_Other)
3877: docProfile = L_Transitional;
3878: unknown = FALSE;
3879: }
3880: else if ((contentText || contentApplication) &&
3881: !strncasecmp (&content_type[i+1], "xml", 3) &&
3882: content_type[i+1+3] == EOS)
3883: {
3884: /* Served as an XML document */
3885: if (isXML && isknown &&
3886: (thotType == docHTML ||
3887: thotType == docSVG ||
3888: thotType == docMath))
3889: /* This type comes from the doctype or a namespace declaration */
3890: docType = thotType;
3891: else
3892: {
1.707 cvs 3893: #ifdef XML_GENERIC
1.1136 gully 3894: docType = docXml;
1.707 cvs 3895: #else /* XML_GENERIC */
1.1136 gully 3896: docType = docText;
1.707 cvs 3897: #endif /* XML_GENERIC */
1.1136 gully 3898: docProfile = L_Other;
3899: }
3900: isXML = TRUE;
3901: unknown = FALSE;
3902: }
3903: else if (contentText &&
3904: !strncasecmp (&content_type[i+1], "css", 3))
3905: {
3906: docType = docCSS;
3907: docProfile = L_Other;
3908: unknown = FALSE;
3909: }
3910: else if ((contentText || contentApplication) &&
3911: (!strncasecmp (&content_type[i+1], "mathml", 6) ||
3912: !strncasecmp (&content_type[i+1], "x-mathml", 8)))
3913: {
3914: /* it's an MathML document */
3915: isXML = TRUE;
3916: docType = docMath;
3917: docProfile = L_MathML;
3918: unknown = FALSE;
3919: }
3920: else if (contentText)
3921: {
3922: docType = docText;
3923: docProfile = L_Other;
3924: unknown = FALSE;
3925: }
3926: else if (contentApplication &&
3927: (!strncasecmp (&content_type[i+1], "x-sh", 4) ||
3928: !strncasecmp (&content_type[i+1], "x-javascript", 12)))
3929: {
3930: docType = docText;
3931: docProfile = L_Other;
3932: unknown = FALSE;
3933: }
3934: else if (contentApplication &&
3935: !strncasecmp (&content_type[i+1], "xml-dtd", 7))
3936: {
3937: /* it's an DTD document */
3938: docType = docText;
3939: docProfile = L_Other;
3940: unknown = FALSE;
3941: }
3942: else if (MultipleBookmarks() &&
3943: !strncasecmp (&content_type[i+1], "rdf+xml", 7))
3944: {
3945: /* it's an RDF document. By default we assume we will
3946: parse it as generic XML */
3947: isXML = TRUE;
3948: isRDF = TRUE;
1.917 kahan 3949: #ifdef XML_GENERIC
1.1136 gully 3950: docType = docXml;
1.917 kahan 3951: #else /* XML_GENERIC */
1.1136 gully 3952: docType = docText;
1.917 kahan 3953: #endif /* XML_GENERIC */
1.1136 gully 3954: docProfile = L_Other;
3955: unknown = FALSE;
3956: }
3957: else if (contentApplication &&
3958: !strncasecmp (&content_type[i+1], "smil", 4))
3959: {
3960: /* it's a SMIL document. We handle it as an XML one */
3961: isXML = TRUE;
1.779 kahan 3962: #ifdef XML_GENERIC
1.1136 gully 3963: docType = docXml;
1.779 kahan 3964: #else /* XML_GENERIC */
1.1136 gully 3965: docType = docText;
1.779 kahan 3966: #endif /* XML_GENERIC */
1.1136 gully 3967: docProfile = L_Other;
3968: unknown = FALSE;
3969: }
3970: else if (contentApplication &&
3971: !strncasecmp (&content_type[i+1], "octet-stream", 12) &&
3972: thotType == docSVG)
3973: {
3974: /* it's a SVG document. We handle it as an XML one */
3975: isXML = TRUE;
3976: docType = thotType;
3977: unknown = FALSE;
3978: }
3979: else if (contentImage &&
3980: !strncasecmp (&content_type[i+1], "svg", 3))
3981: {
3982: /* it's an XML document */
3983: isXML = TRUE;
3984: docType = docSVG;
3985: docProfile = L_Other;
3986: unknown = FALSE;
3987: }
3988: else if (contentImage)
3989: {
3990: /* we'll generate a HTML document */
3991: if (IsImageType (&content_type[i+1]))
3992: {
3993: docType = docImage;
3994: unknown = FALSE;
3995: docProfile = L_Transitional;
3996: }
3997: }
3998: }
3999: }
1.917 kahan 4000:
4001: #ifdef BOOKMARKS
1.1136 gully 4002: if (isRDF)
4003: {
4004: /* verify if it contains bookmarks */
4005: /* we detected some bookmarks, in this rdf document */
4006: if (BM_Open (pathname, s))
4007: docType = docBookmark;
4008: }
1.917 kahan 4009: #endif /* BOOKMARKS */
1.714 cvs 4010:
1.547 cvs 4011: if (unknown && tempfile[0] != EOS)
1.163 cvs 4012: {
1.726 cvs 4013: /* The document is not a supported format and cannot be parsed */
1.163 cvs 4014: /* rename the temporary file */
1.547 cvs 4015: strcpy (SavingFile, tempfile);
1.163 cvs 4016: SavingDocument = 0;
4017: SavingObject = 0;
1.924 vatton 4018: localdoc = (char *)TtaGetMemory (MAX_LENGTH);
4019: TtaExtractName (pathname, tempfile, localdoc);
1.163 cvs 4020: /* reinitialize directories and document lists */
1.547 cvs 4021: strcpy (SavePath, DirectoryName);
1.924 vatton 4022: strcpy (SaveName, localdoc);
4023: strcpy (localdoc, SavePath);
4024: strcat (localdoc, DIR_STR);
4025: strcat (localdoc, SaveName);
1.163 cvs 4026: ResetStop (doc);
1.924 vatton 4027: InitSaveObjectForm (doc, 1, SavingFile, localdoc);
1.163 cvs 4028: }
1.547 cvs 4029: else if (pathname[0] != EOS)
1.163 cvs 4030: {
1.287 cvs 4031: if (method != CE_MAKEBOOK)
1.1136 gully 4032: {
4033: /* do not register and open the document view */
4034: if (DocumentURLs[doc])
4035: {
4036: /* save the URL of the old document in the history, if the same
4037: window is reused, i.e. if the old document has not been
4038: modified */
4039: if (history && !TtaIsDocumentModified (doc))
4040: AddDocHistory (doc, DocumentURLs[doc],
4041: DocumentMeta[doc]->initial_url,
4042: DocumentMeta[doc]->form_data,
4043: DocumentMeta[doc]->method);
4044: }
4045:
4046: if (method == CE_RELATIVE)
4047: {
4048: if (TtaIsDocumentModified (doc) || docType == docCSS)
4049: {
4050: /* open a new window to display the new document */
4051: newdoc = InitDocAndView (doc,
4052: FALSE /* replaceOldDoc */,
4053: TRUE /* inNewWindow */,
4054: documentname, docType, 0, FALSE,
1.1190 vatton 4055: docProfile, method);
1.1136 gully 4056: ResetStop (doc);
4057: /* clear the status line of previous document */
4058: TtaSetStatus (doc, 1, " ", NULL);
4059: ActiveTransfer (newdoc);
4060: }
4061: else
4062: /* replace the current document by a new one */
4063: newdoc = InitDocAndView (doc,
4064: TRUE /* replaceOldDoc */,
4065: FALSE /* inNewWindow */,
4066: documentname, docType, 0, FALSE,
1.1190 vatton 4067: docProfile, method);
1.1136 gully 4068: }
4069: else if (method == CE_ABSOLUTE || method == CE_HELP ||
4070: method == CE_FORM_POST || method == CE_FORM_GET)
4071: /* replace the current document by a new one */
4072: newdoc = InitDocAndView (doc,
4073: TRUE /* replaceOldDoc */,
4074: FALSE /* inNewWindow */,
4075: documentname, docType, 0, FALSE,
1.1190 vatton 4076: docProfile, method);
1.388 cvs 4077: #ifdef ANNOTATIONS
1.1136 gully 4078: else if (method == CE_ANNOT) /* && docType == docHTML) */
4079: {
4080: /* create the body */
4081: ANNOT_CreateBodyTree (doc, docType);
4082: /* and remember its type of the body */
4083: annotBodyType = docType;
4084: docType = docAnnot;
4085: newdoc = doc;
4086: }
1.388 cvs 4087: #endif /* ANNOTATIONS */
1.1136 gully 4088: else if (method == CE_LOG)
4089: {
4090: docType = docLog;
4091: newdoc = doc;
4092: #ifdef _WX
4093: /* the LOG window labels have UTF8 charset on wxWidgets interface */
4094: charset = UTF_8;
4095: #endif /* _WX */
4096: }
4097: else if (docType != DocumentTypes[doc] && DocumentTypes[doc] != docLibrary)
4098: /* replace the current document by a new one */
4099: newdoc = InitDocAndView (doc,
4100: TRUE /* replaceOldDoc */,
4101: FALSE /* inNewWindow */,
4102: documentname, docType, 0, FALSE,
1.1190 vatton 4103: docProfile, method);
1.1136 gully 4104: else
4105: {
4106: /* document already initialized */
4107: newdoc = doc;
4108: /* store the profile of the new document */
4109: /* and update the menus according to it */
4110: TtaSetDocumentProfile (newdoc, docProfile);
4111: }
4112: }
1.287 cvs 4113: else
1.1136 gully 4114: newdoc = doc;
1.682 cvs 4115:
1.305 cvs 4116: if (docType == docImage)
1.1136 gully 4117: /* create an HTML container */
4118: {
4119: if (content_type)
4120: /* it's an image downloaded from the web */
4121: CreateHTMLContainer (pathname, documentname, tempfile, FALSE);
4122: else
4123: {
4124: /* It's a local image file */
4125: sprintf (tempfile, "%s%c%d%c%s", TempFileDirectory,
4126: DIR_SEP, newdoc, DIR_SEP, "contain.html");
4127: CreateHTMLContainer (pathname, documentname, tempfile, TRUE);
4128: }
4129: }
1.305 cvs 4130:
1.163 cvs 4131: /* what we have to do if doc and targetDocument are different */
1.547 cvs 4132: if (tempfile[0] != EOS)
1.1136 gully 4133: {
4134: /* It is a document loaded from the Web */
4135: if (!TtaFileExist (tempfile))
4136: {
4137: /* Nothing is loaded */
4138: ResetStop (doc);
4139: TtaFreeMemory (content_type);
4140: return (0);
4141: }
4142: /* we have to rename the temporary file */
4143: /* allocate and initialize a teporary document */
4144: localdoc = GetLocalPath (newdoc, pathname);
4145: TtaFileUnlink (localdoc);
4146: if (doc != newdoc)
4147: {
4148: /* now we can rename the local name of a remote document */
4149: TtaFileCopy (tempfile, localdoc);
4150: TtaFileUnlink (tempfile);
4151: /* if it's an IMAGEfile, we copy it too to the new directory */
4152: if (DocumentTypes[newdoc] == docImage)
4153: MoveImageFile (doc, newdoc, documentname);
4154: }
4155: else if (DocumentTypes[newdoc] == docCSS)
4156: TtaFileCopy (tempfile, localdoc);
4157: /* now we can rename the local name of a remote document */
4158: else
4159: /* now we can rename the local name of a remote document */
4160: TtaFileRename (tempfile, localdoc);
4161: }
4162: else
4163: {
4164: /* store a copy of the local document */
4165: /* allocate and initialize a teporary document */
4166: localdoc = GetLocalPath (newdoc, pathname);
1.1128 tollenae 4167:
1.1136 gully 4168: TtaFileCopy (pathname, localdoc);
4169: }
1.352 cvs 4170:
1.917 kahan 4171: #ifdef BOOKMARKS
4172: if (docType == docBookmark)
1.1136 gully 4173: /* update the corresponding bookmark context to point to the new tmpfile */
4174: BM_TempFileSet (pathname, localdoc);
1.917 kahan 4175: #endif /* BOOKMARKS */
4176:
4177:
1.352 cvs 4178: /* store a copy of CSS files in the directory 0 */
1.479 cvs 4179: if (DocumentTypes[newdoc] == docCSS)
1.1136 gully 4180: {
4181: css = SearchCSS (0, pathname, NULL, &pInfo);
4182: if (css == NULL)
4183: {
4184: /* store a copy of this new CSS context in .amaya/0 */
4185: s = GetLocalPath (0, pathname);
4186: TtaFileCopy (localdoc, s);
4187: /* initialize a new CSS context */
4188: if (UserCSS && !strcmp (pathname, UserCSS))
4189: AddCSS (newdoc, 0, CSS_USER_STYLE, CSS_ALL, NULL, s, NULL);
4190: else
4191: AddCSS (newdoc, 0, CSS_EXTERNAL_STYLE, CSS_ALL, pathname, s, NULL);
4192: TtaFreeMemory (s);
4193: }
4194: else
4195: css->doc = newdoc;
4196: }
1.163 cvs 4197:
4198: /* save the document name into the document table */
1.1185 vatton 4199: if (realdocname)
4200: s = TtaStrdup (realdocname);
4201: else
1.924 vatton 4202: s = TtaStrdup (pathname);
1.163 cvs 4203: if (DocumentURLs[newdoc] != NULL)
1.1136 gully 4204: {
4205: TtaFreeMemory (DocumentURLs[newdoc]);
4206: DocumentURLs[newdoc] = NULL;
4207: }
1.473 kahan 4208: /* if the document was already loaded, warn the user */
4209: if (IsDocumentLoaded (s, form_data))
1.1136 gully 4210: InitConfirm3L (newdoc, 1, TtaGetMessage (AMAYA, AM_DOUBLE_LOAD),
4211: TtaGetMessage (AMAYA, AM_UNSAVE), NULL, FALSE);
1.163 cvs 4212: DocumentURLs[newdoc] = s;
1.473 kahan 4213:
1.222 cvs 4214: /* save the document's formdata into the document table */
4215: if (DocumentMeta[newdoc] != NULL)
1.1136 gully 4216: DocumentMetaClear (DocumentMeta[newdoc]);
1.380 cvs 4217: else
1.1136 gully 4218: DocumentMeta[newdoc] = DocumentMetaDataAlloc ();
1.575 cvs 4219: DocumentMeta[newdoc]->form_data = TtaStrdup (form_data);
1.547 cvs 4220: if (initial_url && strcmp (pathname, initial_url))
1.1136 gully 4221: DocumentMeta[newdoc]->initial_url = TtaStrdup (initial_url);
1.471 kahan 4222: else
1.1136 gully 4223: DocumentMeta[newdoc]->initial_url = NULL;
1.1188 vatton 4224: reason = HTTP_headers (http_headers, AM_HTTP_REASON);
1.1189 vatton 4225: if (reason && strcasecmp (reason, "OK"))
1.1188 vatton 4226: DocumentMeta[newdoc]->reason = TtaStrdup (reason);
1.1190 vatton 4227: DocumentMeta[newdoc]->method = method;
1.728 cvs 4228: DocumentSource[newdoc] = 0;
1.461 cvs 4229: DocumentMeta[newdoc]->xmlformat = isXML;
1.1169 vatton 4230: DocumentMeta[newdoc]->compound = FALSE;
1.222 cvs 4231:
1.516 cvs 4232: /* Set character encoding */
1.557 cvs 4233: DocumentMeta[newdoc]->charset = NULL;
1.457 cvs 4234: charEncoding = HTTP_headers (http_headers, AM_HTTP_CHARSET);
4235: httpcharset = TtaGetCharset (charEncoding);
1.557 cvs 4236:
1.1139 tollenae 4237: #ifdef TEMPLATES
1.1140 tollenae 4238: DocumentMeta[newdoc]->template_version = NULL;
1.1139 tollenae 4239: #endif /* TEMPLATES */
4240:
1.743 vatton 4241: if (httpcharset != UNDEFINED_CHARSET && charEncoding)
1.1136 gully 4242: {
4243: TtaSetDocumentCharset (newdoc, httpcharset, FALSE);
4244: DocumentMeta[newdoc]->charset = TtaStrdup (charEncoding);
4245: }
1.743 vatton 4246: else if (charset != UNDEFINED_CHARSET)
1.1136 gully 4247: {
4248: TtaSetDocumentCharset (newdoc, charset, FALSE);
4249: DocumentMeta[newdoc]->charset = TtaStrdup (charsetname);
4250: }
1.516 cvs 4251: else if (metacharset != UNDEFINED_CHARSET)
1.1136 gully 4252: {
4253: TtaSetDocumentCharset (newdoc, metacharset, FALSE);
4254: DocumentMeta[newdoc]->charset = TtaStrdup (charsetname);
4255: }
1.557 cvs 4256: else if (charsetname[0] != EOS)
1.1136 gully 4257: DocumentMeta[newdoc]->charset = TtaStrdup (charsetname);
1.557 cvs 4258:
1.562 kahan 4259: /*
4260: ** copy some HTTP headers to the metadata
4261: */
4262: /* content-type */
1.551 kahan 4263: if (http_content_type)
1.1188 vatton 4264: DocumentMeta[newdoc]->content_type = TtaStrdup (http_content_type);
1.962 vatton 4265: else if (local_content_type[0] != EOS)
1.1136 gully 4266: /* assign a content type to the local files */
4267: DocumentMeta[newdoc]->content_type = TtaStrdup (local_content_type);
1.551 kahan 4268: else
1.1136 gully 4269: DocumentMeta[newdoc]->content_type = NULL;
1.562 kahan 4270: /* content-length */
4271: s = HTTP_headers (http_headers, AM_HTTP_CONTENT_LENGTH);
4272: if (s)
1.1136 gully 4273: DocumentMeta[newdoc]->content_length = TtaStrdup (s);
1.562 kahan 4274: else
1.1136 gully 4275: DocumentMeta[newdoc]->content_length = NULL;
1.781 kahan 4276: /* simplified content-location */
1.647 kahan 4277: s = HTTP_headers (http_headers, AM_HTTP_CONTENT_LOCATION);
4278: if (s)
1.1136 gully 4279: DocumentMeta[newdoc]->content_location = TtaStrdup (s);
1.647 kahan 4280: else
1.1136 gully 4281: DocumentMeta[newdoc]->content_location = NULL;
1.781 kahan 4282: /* full content-location */
4283: s = HTTP_headers (http_headers, AM_HTTP_FULL_CONTENT_LOCATION);
4284: if (s)
1.1136 gully 4285: DocumentMeta[newdoc]->full_content_location = TtaStrdup (s);
1.781 kahan 4286: else
1.1136 gully 4287: DocumentMeta[newdoc]->full_content_location = NULL;
1.562 kahan 4288:
1.163 cvs 4289: if (TtaGetViewFrame (newdoc, 1) != 0)
1.1136 gully 4290: /* this document is displayed */
4291: {
4292: if (DocumentTypes[newdoc] != docLog)
4293: {
1.923 vatton 4294: #ifdef _SVG
1.1136 gully 4295: if (DocumentTypes[newdoc] == docLibrary)
4296: {
4297: SelectLibraryFromPath (DocumentURLs[newdoc]);
4298: TtaSetTextZone (newdoc, 1, SVGlib_list);
4299: }
4300: else
1.1018 vatton 4301: #endif /* _SVG */
1.1136 gully 4302: TtaSetTextZone (newdoc, 1, URL_list);
4303: }
4304: }
1.222 cvs 4305:
1.907 gully 4306: tempdir = (char *)TtaGetMemory (MAX_LENGTH);
1.924 vatton 4307: TtaExtractName (localdoc, tempdir, documentname);
1.332 cvs 4308: /* Now we forget the method CE_INIT. It's a standard method */
4309: if (DocumentMeta[newdoc]->method == CE_INIT)
1.1136 gully 4310: DocumentMeta[newdoc]->method = CE_ABSOLUTE;
1.447 cvs 4311:
1.711 cvs 4312: if (docType == docHTML ||
1.1136 gully 4313: docType == docSVG ||
1.713 kahan 4314: #ifdef ANNOTATIONS
1.1136 gully 4315: (docType == docAnnot && annotBodyType != docText) ||
1.713 kahan 4316: #endif /* ANNOTATIONS */
1.1136 gully 4317: docType == docBookmark ||
4318: docType == docXml ||
4319: docType == docLibrary ||
4320: docType == docMath)
4321: plainText = FALSE;
1.474 cvs 4322: else
1.1136 gully 4323: plainText = (docProfile == L_Other || docProfile == L_CSS);
1.917 kahan 4324:
4325: #ifdef BOOKMARKS
4326: if (docType == docBookmark)
1.1136 gully 4327: BM_ViewBookmarks (newdoc, 1, FALSE);
1.917 kahan 4328: else
4329: #endif /* BOOKMARKS */
1.1136 gully 4330: /* Calls the corresponding parser */
4331: if (DocumentMeta[newdoc]->xmlformat && !plainText)
4332: StartXmlParser (newdoc, localdoc, documentname, tempdir,
1.1163 vatton 4333: pathname, xmlDec, withDoctype, useMath, FALSE);
1.1136 gully 4334: else
4335: StartParser (newdoc, localdoc, documentname, tempdir,
4336: pathname, plainText, FALSE);
1.485 cvs 4337:
1.163 cvs 4338: TtaFreeMemory (tempdir);
1.717 cvs 4339:
4340: /* Update the Doctype menu */
1.983 vatton 4341: UpdateEditorMenus (newdoc);
4342:
1.824 vatton 4343: if (*inNewWindow || newdoc != doc)
1.1136 gully 4344: /* the document is displayed in a different window */
4345: /* reset the history of the new window */
4346: InitDocHistory (newdoc);
1.935 quint 4347:
4348: #ifdef _SVG
4349: if (docType == docSVG)
1.1136 gully 4350: /* for a SVG document, get the first title element that is a child
4351: of the SVG root element and display its contents as the window
4352: title */
4353: DisplaySVGtitle (newdoc);
1.935 quint 4354: #endif /* _SVG */
4355:
1.546 cvs 4356: /* the document is loaded now */
1.824 vatton 4357: *inNewWindow = FALSE;
1.1128 tollenae 4358:
1.336 cvs 4359: #ifdef ANNOTATIONS
1.721 kahan 4360: /* store the annotation body type (we have to wait until now as
1.1136 gully 4361: the metadata didn't exist before) */
1.721 kahan 4362: if (docType == docAnnot)
1.1136 gully 4363: ANNOT_bodyType_set (newdoc, annotBodyType);
1.336 cvs 4364: #endif /* ANNOTATIONS */
1.163 cvs 4365: }
1.1166 vatton 4366: #ifdef _WX
4367: // refresh the XML panel
4368: TtaRefreshElementMenu (newdoc, 1);
4369: #endif /* _WX */
1.551 kahan 4370: TtaFreeMemory (content_type);
1.924 vatton 4371: TtaFreeMemory (localdoc);
1.163 cvs 4372: return (newdoc);
1.6 cvs 4373: }
1.247 cvs 4374:
4375: /*----------------------------------------------------------------------
1.245 cvs 4376: Reload_callback
1.924 vatton 4377: The urlName is encoded with the default charset.
1.9 cvs 4378: ----------------------------------------------------------------------*/
1.585 cvs 4379: void Reload_callback (int doc, int status, char *urlName,
1.1136 gully 4380: char *outputfile, AHTHeaders *http_headers,
4381: void * context)
1.177 cvs 4382: {
1.617 cvs 4383: Document newdoc;
1.585 cvs 4384: char *tempfile;
4385: char *documentname;
4386: char *form_data;
1.792 vatton 4387: char *initial_url, *ptr;
1.1190 vatton 4388: int method;
1.782 vatton 4389: Document res = 0;
1.585 cvs 4390: Element el;
4391: RELOAD_context *ctx;
1.1184 vatton 4392: int visibility;
1.808 vatton 4393: ThotBool stopped_flag = FALSE, keep;
1.177 cvs 4394:
1.222 cvs 4395: /* restore the context associated with the request */
4396: ctx = (RELOAD_context *) context;
4397: documentname = ctx->documentname;
4398: newdoc = ctx->newdoc;
4399: form_data = ctx->form_data;
4400: method = ctx->method;
1.1184 vatton 4401: visibility = ctx->visibility;
4402: MapAreas[doc] = ctx->maparea;
1.903 quint 4403: if (!DocumentURLs[doc])
4404: /* the user has closed the corresponding document. Just free resources */
4405: {
4406: TtaFreeMemory (documentname);
4407: if (form_data)
1.1136 gully 4408: TtaFreeMemory (form_data);
1.903 quint 4409: TtaFreeMemory (ctx);
4410: return;
4411: }
4412:
1.177 cvs 4413: tempfile = outputfile;
4414: if (status == 0)
1.1136 gully 4415: {
4416: TtaSetCursorWatch (0, 0);
4417:
4418: /* a bit of acrobatics so that we can retain the initial_url
4419: without reallocating memory */
4420: initial_url = DocumentMeta[doc]->initial_url;
4421: DocumentMeta[doc]->initial_url = NULL;
1.471 kahan 4422:
1.1136 gully 4423: RemoveParsingErrors (newdoc);
4424: /* add the URI in the combobox string */
4425: if (method != CE_MAKEBOOK && method != CE_ANNOT &&
4426: method != CE_LOG && method != CE_HELP &&
4427: DocumentTypes[newdoc] != docLibrary &&
4428: status == 0)
4429: {
4430: /* add the URI in the combobox string */
4431: keep = (method == CE_ABSOLUTE || method == CE_INIT);
4432: if (form_data && method == CE_FORM_GET)
4433: AddURLInCombobox (urlName, form_data, keep);
4434: else
4435: AddURLInCombobox (urlName, NULL, keep);
4436: }
4437: /* parse and display the document, res contains the new document
4438: identifier, as given by the thotlib */
4439: res = LoadDocument (newdoc, urlName, form_data, NULL, method,
1.1185 vatton 4440: tempfile, documentname, http_headers, FALSE,
4441: &DontReplaceOldDoc, NULL);
1.1136 gully 4442: UpdateEditorMenus (doc);
1.1184 vatton 4443: if (visibility == 4)
4444: {
4445: // restore the visibility
4446: TtaSetSensibility (doc, 1, visibility);
4447: TtaSetToggleItem (doc, 1, Views, TShowTargets, TRUE);
4448: }
4449: if (MapAreas[doc])
4450: // set Map areas visible
4451: TtaSetToggleItem (doc, 1, Views, TShowMapAreas, TRUE);
1.1136 gully 4452:
4453: if (res == 0)
4454: {
4455: /* cannot load the document */
4456: ResetStop(newdoc);
4457: newdoc = 0;
4458: TtaFreeMemory (initial_url);
4459: }
4460: else if (newdoc != res)
4461: {
4462: newdoc = res;
4463: /* restore the initial_url */
4464: DocumentMeta[newdoc]->initial_url = initial_url;
4465: }
1.535 kahan 4466:
1.1136 gully 4467: if (newdoc)
4468: {
4469: W3Loading = 0; /* loading is complete now */
1.510 kahan 4470: #ifdef ANNOTATIONS
1.1136 gully 4471: /* if it's an annotation, add the existing metadata */
4472: if (DocumentTypes[newdoc] == docAnnot)
4473: ANNOT_ReloadAnnotMeta (newdoc);
4474: /* auto-load the annotations associated with the document */
4475: if (ANNOT_CanAnnotate (newdoc))
4476: ANNOT_AutoLoad (newdoc, 1);
1.510 kahan 4477: #endif /* ANNOTATIONS */
1.1136 gully 4478: TtaHandlePendingEvents ();
4479: /* fetch and display all images referred by the document */
4480: stopped_flag = FetchAndDisplayImages (newdoc, AMAYA_NOCACHE | AMAYA_LOAD_IMAGE, NULL);
4481: if (stopped_flag == FALSE)
4482: {
4483: TtaResetCursor (0, 0);
4484: /* show the document at the same position as before Reload */
4485: el = ElementAtPosition (newdoc, ctx->position);
4486: TtaShowElement (newdoc, 1, el, ctx->distance);
4487: }
4488: }
4489: }
1.471 kahan 4490:
1.506 kahan 4491: if (stopped_flag == FALSE && newdoc)
1.1035 vatton 4492: {
4493: ResetStop (newdoc);
4494: #ifdef _GL
4495: if (FilesLoading[newdoc] == 0 &&
1.1136 gully 4496: TtaGetViewFrame (newdoc, 1) != 0)
4497: /* all files included in this document have been loaded and the
4498: document is displayed. Animations can be played now */
4499: TtaPlay (newdoc, 1);
1.1035 vatton 4500: #endif /* _GL */
4501: }
1.621 cvs 4502:
4503: /* check parsing errors */
4504: CheckParsingErrors (newdoc);
4505:
1.792 vatton 4506: if (DocumentTypes[newdoc] == docCSS)
4507: {
4508: /* reapply the CSS to relative documents */
4509: ptr = GetLocalPath (newdoc, DocumentURLs[newdoc]);
4510: UpdateStyleSheet (DocumentURLs[newdoc], ptr);
4511: TtaFreeMemory (ptr);
4512: }
1.749 kirschpi 4513: #ifdef DAV
1.1136 gully 4514: /* MKP: if document has been loaded, we are *
4515: * able to discovery if the document is locked. *
4516: * do a lock discovery, set LockIndicator button */
4517: if (W3Loading == 0 && res> 0)
1.754 kirschpi 4518: {
1.749 kirschpi 4519: DAVLockDiscovery (newdoc);
4520: DAVSetLockIndicator(newdoc);
1.754 kirschpi 4521: }
1.924 vatton 4522: #endif /* DAV */
1.749 kirschpi 4523:
1.1136 gully 4524: if (DocumentTypes[newdoc] == docBookmark && TtaIsDocumentModified (newdoc))
4525: DocStatusUpdate (newdoc, TRUE);
4526: else
4527: DocStatusUpdate (newdoc, FALSE);
1.987 kahan 4528:
1.177 cvs 4529: TtaFreeMemory (documentname);
1.222 cvs 4530: if (form_data)
4531: TtaFreeMemory (form_data);
4532: TtaFreeMemory (ctx);
1.177 cvs 4533: }
4534:
4535:
4536: /*----------------------------------------------------------------------
1.245 cvs 4537: Reload
1.177 cvs 4538: ----------------------------------------------------------------------*/
1.585 cvs 4539: void Reload (Document doc, View view)
1.6 cvs 4540: {
1.1136 gully 4541: char *tempfile;
4542: char *pathname;
4543: char *documentname;
4544: char *form_data;
1.1190 vatton 4545: int method;
1.1136 gully 4546: RELOAD_context *ctx;
4547: int toparse;
4548: int mode;
4549: int position;
4550: int distance;
4551:
4552: /* if it is a source document, reload its corresponding document */
4553: if (DocumentTypes[doc] == docSource)
1.1164 cvs 4554: #ifdef _WX
4555: {
4556: Synchronize (doc, 1);
4557: doc = GetDocFromSource (doc);
4558: }
4559: #else /* _WX */
1.1136 gully 4560: doc = GetDocFromSource (doc);
1.1164 cvs 4561: #endif /* _WX */
1.1136 gully 4562:
4563: if (DocumentURLs[doc] == NULL)
4564: /* the document has not been loaded yet */
4565: return;
1.1069 gully 4566:
1.1136 gully 4567: /* abort all current exchanges concerning this document */
4568: StopTransfer (doc, 1);
4569: if (!CanReplaceCurrentDocument (doc, view))
4570: /* abort the command */
4571: return;
4572: /* reload the document */
4573: pathname = (char *)TtaGetMemory (MAX_LENGTH);
4574: documentname = (char *)TtaGetMemory (MAX_LENGTH);
4575: /* if the document is a template, restore the template script URL */
4576: if (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_TEMPLATE)
4577: ReloadTemplateParams (&(DocumentURLs[doc]), &(DocumentMeta[doc]->method));
4578: NormalizeURL (DocumentURLs[doc], 0, pathname, documentname, NULL);
4579:
4580: if (!IsW3Path (pathname) && !TtaFileExist (pathname))
4581: {
4582: /* Free Memory */
4583: TtaFreeMemory (pathname);
4584: TtaFreeMemory (documentname);
4585: /* cannot reload this document */
1.6 cvs 4586: return;
1.1136 gully 4587: }
4588:
4589: if (DocumentMeta[doc]->form_data)
4590: form_data = TtaStrdup (DocumentMeta[doc]->form_data);
4591: else
4592: form_data = NULL;
4593:
4594: if (DocumentTypes[doc] == docAnnot)
4595: method = CE_ANNOT;
4596: else
4597: method = DocumentMeta[doc]->method;
4598:
4599: /* get the current position in the document */
4600: position = RelativePosition (doc, &distance);
4601:
4602: W3Loading = doc; /* this document is currently in load */
4603: mode = AMAYA_ASYNC | AMAYA_NOCACHE | AMAYA_FLUSH_REQUEST;
4604:
4605: if (method == CE_FORM_POST)
4606: mode |= AMAYA_FORM_POST;
4607:
4608: tempfile = (char *)TtaGetMemory (MAX_LENGTH);
4609: tempfile[0] = EOS;
4610: toparse = 0;
4611: ActiveTransfer (doc);
4612: /* Create the context for the callback */
4613: ctx = (RELOAD_context*)TtaGetMemory (sizeof (RELOAD_context));
4614: ctx->newdoc = doc;
4615: ctx->documentname = documentname;
4616: ctx->form_data = form_data;
4617: ctx->method = method;
4618: ctx->position = position;
4619: ctx->distance = distance;
1.1184 vatton 4620: ctx->visibility = TtaGetSensibility (doc, 1);
4621: ctx->maparea = MapAreas[doc];
1.1136 gully 4622: if (IsW3Path (pathname))
4623: {
4624: /* load the document from the Web */
4625: toparse = GetObjectWWW (doc, 0, pathname, form_data, tempfile,
4626: mode,
4627: NULL, NULL, (void (*)(int, int, char*, char*, const AHTHeaders*, void*)) Reload_callback,
4628: (void *) ctx, YES, NULL);
4629: }
4630: else if (TtaFileExist (pathname))
4631: Reload_callback (doc, 0, pathname, tempfile, NULL, (void *) ctx);
4632:
4633: TtaFreeMemory (tempfile);
4634: TtaFreeMemory (pathname);
4635: TtaHandlePendingEvents ();
1.6 cvs 4636: }
4637:
1.9 cvs 4638: /*----------------------------------------------------------------------
4639: ----------------------------------------------------------------------*/
1.585 cvs 4640: void ShowTargets (Document document, View view)
1.219 cvs 4641: {
1.220 cvs 4642: int visibility;
1.229 cvs 4643: View tocView;
1.219 cvs 4644:
4645: visibility = TtaGetSensibility (document, view);
4646: if (visibility == 4)
4647: {
4648: visibility = 5;
4649: TtaSetToggleItem (document, 1, Views, TShowTargets, FALSE);
4650: }
4651: else
4652: {
4653: visibility = 4;
4654: TtaSetToggleItem (document, 1, Views, TShowTargets, TRUE);
4655: }
1.229 cvs 4656: /* Change visibility threshold in the main view */
1.219 cvs 4657: TtaSetSensibility (document, view, visibility);
1.229 cvs 4658: /* Change visibility threshold in the table of content view if it's open */
1.408 cvs 4659: tocView = TtaGetViewFromName (document, "Table_of_contents");
1.529 cvs 4660: if (tocView && TtaIsViewOpen (document, tocView))
1.1136 gully 4661: TtaSetSensibility (document, tocView, visibility);
1.219 cvs 4662: }
4663:
4664:
4665: /*----------------------------------------------------------------------
4666: ----------------------------------------------------------------------*/
1.585 cvs 4667: void ZoomIn (Document document, View view)
1.206 cvs 4668: {
4669: int zoom, zoomVal;
1.585 cvs 4670: char *zoomStr;
1.206 cvs 4671:
4672: zoom = TtaGetZoom (document, view);
4673: if (zoom < 10)
4674: {
4675: zoom++;
4676: TtaSetZoom (document, view, zoom);
4677: }
4678:
4679: /* compare to the standard value? */
1.339 cvs 4680: zoomStr = TtaGetEnvString ("ZOOM");
1.206 cvs 4681: if (zoomStr == NULL)
4682: zoomVal = 0;
4683: else
4684: {
1.607 cvs 4685: sscanf (zoomStr, "%d", &zoomVal);
1.206 cvs 4686: if (zoomVal > 10 || zoomVal < -10)
1.1136 gully 4687: zoomVal = 0;
1.206 cvs 4688: }
4689: if (zoom > zoomVal)
4690: TtaSetToggleItem (document, 1, Views, TZoomIn, TRUE);
4691: else
4692: TtaSetToggleItem (document, 1, Views, TZoomIn, FALSE);
4693: if (zoom < zoomVal)
4694: TtaSetToggleItem (document, 1, Views, TZoomOut, TRUE);
4695: else
4696: TtaSetToggleItem (document, 1, Views, TZoomOut, FALSE);
4697: }
4698:
4699: /*----------------------------------------------------------------------
4700: ----------------------------------------------------------------------*/
1.585 cvs 4701: void ZoomOut (Document document, View view)
1.206 cvs 4702: {
4703: int zoom, zoomVal;
1.585 cvs 4704: char *zoomStr;
1.206 cvs 4705:
4706: zoom = TtaGetZoom (document, view);
4707: if (zoom > -10)
4708: {
4709: zoom--;
4710: TtaSetZoom (document, view, zoom);
4711: }
4712:
4713: /* compare to the standard value? */
1.339 cvs 4714: zoomStr = TtaGetEnvString ("ZOOM");
1.206 cvs 4715: if (zoomStr == NULL)
4716: zoomVal = 0;
4717: else
4718: {
1.607 cvs 4719: sscanf (zoomStr, "%d", &zoomVal);
1.206 cvs 4720: if (zoomVal > 10 || zoomVal < -10)
1.1136 gully 4721: zoomVal = 0;
1.206 cvs 4722: }
4723: if (zoom > zoomVal)
4724: TtaSetToggleItem (document, 1, Views, TZoomIn, TRUE);
4725: else
4726: TtaSetToggleItem (document, 1, Views, TZoomIn, FALSE);
4727: if (zoom < zoomVal)
4728: TtaSetToggleItem (document, 1, Views, TZoomOut, TRUE);
4729: else
4730: TtaSetToggleItem (document, 1, Views, TZoomOut, FALSE);
1.275 cvs 4731: }
4732:
4733: /*----------------------------------------------------------------------
1.338 cvs 4734: ShowSource
1.691 cvs 4735: Display the source code of a document
1.206 cvs 4736: ----------------------------------------------------------------------*/
1.1005 vatton 4737: void ShowSource (Document doc, View view)
1.334 cvs 4738: {
1.1136 gully 4739: CHARSET charset;
4740: char *localFile;
4741: char *s;
4742: char documentname[MAX_LENGTH];
4743: char tempdir[MAX_LENGTH];
4744: Document sourceDoc;
4745: NotifyElement event;
4746:
4747: if (!DocumentURLs[doc])
4748: /* the document is not loaded yet */
4749: return;
4750: if (DocumentTypes[doc] != docHTML &&
4751: DocumentTypes[doc] != docSVG &&
4752: DocumentTypes[doc] != docXml &&
4753: DocumentTypes[doc] != docLibrary &&
4754: DocumentTypes[doc] != docMath)
4755: /* it's not an HTML or an XML document */
4756: return;
4757: if (DocumentSource[doc])
4758: /* the source code of this document is already shown */
4759: /* raise its window */
4760: TtaRaiseView (DocumentSource[doc], 1);
4761: else
4762: {
4763: /* save the current state of the document into the temporary file */
4764: localFile = GetLocalPath (doc, DocumentURLs[doc]);
4765: if (TtaIsDocumentModified (doc) || !TtaFileExist (localFile))
4766: {
4767: SetNamespacesAndDTD (doc);
4768: if (DocumentTypes[doc] == docLibrary ||
4769: DocumentTypes[doc] == docHTML)
4770: {
4771: if (TtaGetDocumentProfile (doc) == L_Xhtml11)
4772: TtaExportDocumentWithNewLineNumbers (doc, localFile,
4773: "HTMLT11");
4774: else if (DocumentMeta[doc]->xmlformat)
4775: TtaExportDocumentWithNewLineNumbers (doc, localFile,
4776: "HTMLTX");
4777: else
4778: TtaExportDocumentWithNewLineNumbers (doc, localFile,
4779: "HTMLT");
4780: }
4781: else if (DocumentTypes[doc] == docSVG)
4782: TtaExportDocumentWithNewLineNumbers (doc, localFile,
4783: "SVGT");
4784: else if (DocumentTypes[doc] == docMath)
4785: TtaExportDocumentWithNewLineNumbers (doc, localFile,
4786: "MathMLT");
1.616 cvs 4787: #ifdef XML_GENERIC
1.1136 gully 4788: else if (DocumentTypes[doc] == docXml)
4789: TtaExportDocumentWithNewLineNumbers (doc, localFile, NULL);
1.616 cvs 4790: #endif /* XML_GENERIC */
1.1136 gully 4791: }
1.1005 vatton 4792:
1.1136 gully 4793: TtaExtractName (localFile, tempdir, documentname);
4794: /* open a window for the source code */
1.1005 vatton 4795: #ifdef _WX
1.1136 gully 4796: sourceDoc = InitDocAndView (doc,
4797: FALSE /* replaceOldDoc */,
4798: FALSE /* inNewWindow */,
4799: documentname, (DocumentType)docSource, doc, FALSE,
4800: TtaGetDocumentProfile (doc),
1.1190 vatton 4801: (int)CE_ABSOLUTE);
1.972 gully 4802: #else /* _WX */
1.1136 gully 4803: sourceDoc = InitDocAndView (doc,
4804: FALSE /* replaceOldDoc */,
4805: TRUE /* inNewWindow */,
4806: documentname, (DocumentType)docSource, doc, FALSE,
1.1190 vatton 4807: L_Other, (int)CE_ABSOLUTE);
1.1136 gully 4808: #endif /* _WX */
4809:
4810: if (sourceDoc > 0)
4811: {
4812: DocumentSource[doc] = sourceDoc;
4813: s = TtaStrdup (DocumentURLs[doc]);
4814: DocumentURLs[sourceDoc] = s;
4815: DocumentMeta[sourceDoc] = DocumentMetaDataAlloc ();
4816: DocumentMeta[sourceDoc]->form_data = NULL;
4817: DocumentMeta[sourceDoc]->initial_url = NULL;
4818: DocumentMeta[sourceDoc]->method = CE_ABSOLUTE;
4819: DocumentMeta[sourceDoc]->xmlformat = FALSE;
1.1169 vatton 4820: DocumentMeta[sourceDoc]->compound = FALSE;
1.1136 gully 4821: /* copy the MIME type, charset, and content location */
4822: if (DocumentMeta[doc]->content_type)
4823: DocumentMeta[sourceDoc]->content_type = TtaStrdup (DocumentMeta[doc]->content_type);
4824: if (DocumentMeta[doc]->charset)
4825: DocumentMeta[sourceDoc]->charset = TtaStrdup (DocumentMeta[doc]->charset);
4826: if (DocumentMeta[doc]->content_location)
4827: DocumentMeta[sourceDoc]->content_location = TtaStrdup (DocumentMeta[doc]->content_location);
4828: if (DocumentMeta[doc]->full_content_location)
4829: DocumentMeta[sourceDoc]->full_content_location = TtaStrdup (DocumentMeta[doc]->full_content_location);
4830: DocumentTypes[sourceDoc] = docSource;
4831: charset = TtaGetDocumentCharset (doc);
4832: if (charset == UNDEFINED_CHARSET)
4833: {
4834: if (DocumentMeta[doc]->xmlformat)
4835: TtaSetDocumentCharset (SavingDocument, UTF_8, FALSE);
4836: else
4837: TtaSetDocumentCharset (SavingDocument, ISO_8859_1, FALSE);
4838: }
4839: else
4840: TtaSetDocumentCharset (sourceDoc, charset, FALSE);
4841: DocNetworkStatus[sourceDoc] = AMAYA_NET_INACTIVE;
4842: StartParser (sourceDoc, localFile, documentname, tempdir,
4843: localFile, TRUE, FALSE);
4844: SetWindowTitle (doc, sourceDoc, 0);
4845: /* Switch the synchronization entry */
4846: if (TtaIsDocumentModified (doc))
1.1169 vatton 4847: {
4848: // views are synchronized
4849: TtaSetDocumentModified (sourceDoc);
4850: TtaSetDocumentUnupdated (sourceDoc);
4851: TtaSetDocumentUnupdated (doc);
4852: //DocStatusUpdate (doc, TRUE);
4853: }
1.1136 gully 4854: /* Synchronize selections */
4855: event.document = doc;
4856: event.element = NULL;
4857: UpdateEditorMenus (sourceDoc);
4858: SetCharsetMenuOff (sourceDoc, 1);
4859: /* update back/forward buttons */
4860: if (HasPreviousDoc (doc))
4861: SetArrowButton (DocumentSource[doc], TRUE, TRUE);
4862: else
4863: SetArrowButton (DocumentSource[doc], TRUE, FALSE);
4864: if (HasNextDoc (doc))
4865: SetArrowButton (DocumentSource[doc], FALSE, TRUE);
4866: else
4867: SetArrowButton (DocumentSource[doc], FALSE, FALSE);
4868:
1.1175 cvs 4869: #ifdef _WX
4870: /* update toggle buttons */
4871: if (HSplit[doc] == TRUE && VSplit[doc] == FALSE)
4872: ShowHSplitToggle (sourceDoc, 1);
4873: if (HSplit[doc] == FALSE && VSplit[doc] == TRUE)
4874: ShowVSplitToggle (sourceDoc, 1);
4875: #endif /* _WX */
4876:
1.1136 gully 4877: // check if a parsing error is detected
4878: sprintf (tempdir, "%s%c%d%cPARSING.ERR",
4879: TempFileDirectory, DIR_SEP, doc, DIR_SEP);
4880: if (TtaFileExist (tempdir))
4881: TtaSetItemOn (sourceDoc, 1, File, BShowLogFile);
4882: SynchronizeSourceView (&event);
4883: }
4884: TtaFreeMemory (localFile);
4885: }
1.1075 gully 4886:
4887: /* the new opened view must get the focus */
4888: TtaRedirectFocus();
4889: }
4890:
4891: /*----------------------------------------------------------------------
4892: ShowFormatted
4893: Open the formatted view(s) of a document. (or give it focus)
4894: ----------------------------------------------------------------------*/
4895: void ShowFormatted (Document doc, View view)
4896: {
4897: View structView;
4898: int x, y, w, h;
4899: char structureName[30];
4900:
4901: if (DocumentTypes[doc] == docSource)
4902: /* work on the formatted document */
4903: doc = GetDocFromSource (doc);
4904: strcpy (structureName, "Formatted_view");
4905: structView = TtaGetViewFromName (doc, structureName);
4906: if (structView != 0 && TtaIsViewOpen (doc, structView))
4907: TtaRaiseView (doc, structView);
4908: else
4909: {
4910: TtaGetViewGeometry (doc, structureName, &x, &y, &w, &h);
4911: structView = TtaOpenView (doc, structureName, x, y, w, h);
4912: if (structView != 0)
1.1136 gully 4913: {
1.1084 gully 4914: #ifndef _WX
1.1136 gully 4915: TtcSwitchButtonBar (doc, structView); /* no button bar */
4916: TtcSwitchCommands (doc, structView); /* no command open */
1.1084 gully 4917: #endif /* _WX */
1.1136 gully 4918: UpdateEditorMenus (doc);
4919: }
1.1075 gully 4920: }
4921: SetWindowTitle (doc, doc, 0);
4922:
4923: /* the new opened view must get the focus */
4924: TtaRedirectFocus();
1.334 cvs 4925: }
4926:
4927: /*----------------------------------------------------------------------
1.407 cvs 4928: ShowStructure
1.735 cvs 4929: Open the structure view(s) of a document.
1.334 cvs 4930: ----------------------------------------------------------------------*/
1.938 vatton 4931: void ShowStructure (Document doc, View view)
1.6 cvs 4932: {
1.950 vatton 4933: View structView;
4934: int x, y, w, h;
4935: char structureName[30];
4936:
1.1058 vatton 4937: if (DocumentTypes[doc] == docSource)
4938: /* work on the formatted document */
4939: doc = GetDocFromSource (doc);
1.950 vatton 4940: strcpy (structureName, "Structure_view");
4941: structView = TtaGetViewFromName (doc, structureName);
4942: if (structView != 0 && TtaIsViewOpen (doc, structView))
4943: TtaRaiseView (doc, structView);
4944: else
4945: {
4946: TtaGetViewGeometry (doc, structureName, &x, &y, &w, &h);
4947: structView = TtaOpenView (doc, structureName, x, y, w, h);
4948: if (structView != 0)
1.1136 gully 4949: {
1.1084 gully 4950: #ifndef _WX
1.1136 gully 4951: TtcSwitchButtonBar (doc, structView); /* no button bar */
4952: TtcSwitchCommands (doc, structView); /* no command open */
1.1084 gully 4953: #endif /* _WX */
1.1136 gully 4954: UpdateEditorMenus (doc);
4955: }
1.950 vatton 4956: }
4957: SetWindowTitle (doc, doc, 0);
1.1075 gully 4958:
4959: /* the new opened view must get the focus */
4960: TtaRedirectFocus();
1.6 cvs 4961: }
4962:
1.9 cvs 4963: /*----------------------------------------------------------------------
1.407 cvs 4964: ShowAlternate
1.735 cvs 4965: Open the Alternate view of a document.
1.9 cvs 4966: ----------------------------------------------------------------------*/
1.938 vatton 4967: void ShowAlternate (Document doc, View view)
1.6 cvs 4968: {
1.950 vatton 4969: View altView;
4970: int x, y, w, h;
1.6 cvs 4971:
1.1058 vatton 4972: if (DocumentTypes[doc] == docSource)
4973: /* work on the formatted document */
4974: doc = GetDocFromSource (doc);
1.950 vatton 4975: altView = TtaGetViewFromName (doc, "Alternate_view");
4976: if (view == altView)
4977: TtaRaiseView (doc, view);
4978: else if (altView != 0 && TtaIsViewOpen (doc, altView))
4979: TtaRaiseView (doc, altView);
4980: else
4981: {
4982: TtaGetViewGeometry (doc, "Alternate_view", &x, &y, &w, &h);
4983: altView = TtaOpenView (doc, "Alternate_view", x, y, w, h);
4984: if (altView != 0)
1.1136 gully 4985: {
4986: SetWindowTitle (doc, doc, altView);
1.1084 gully 4987: #ifndef _WX
1.1136 gully 4988: TtcSwitchButtonBar (doc, altView); /* no button bar */
4989: TtcSwitchCommands (doc, altView); /* no command open */
1.1084 gully 4990: #endif /* _WX */
1.1136 gully 4991: UpdateEditorMenus (doc);
4992: }
1.950 vatton 4993: }
1.1075 gully 4994:
4995: /* the new opened view must get the focus */
4996: TtaRedirectFocus();
1.6 cvs 4997: }
4998:
4999:
1.9 cvs 5000: /*----------------------------------------------------------------------
1.407 cvs 5001: ShowLinks
1.735 cvs 5002: Open the Links view of a document
1.48 cvs 5003: ----------------------------------------------------------------------*/
1.938 vatton 5004: void ShowLinks (Document doc, View view)
1.48 cvs 5005: {
1.950 vatton 5006: View linksView;
5007: int x, y, w, h;
1.48 cvs 5008:
1.1058 vatton 5009: if (DocumentTypes[doc] == docSource)
5010: /* work on the formatted document */
5011: doc = GetDocFromSource (doc);
1.950 vatton 5012: linksView = TtaGetViewFromName (doc, "Links_view");
5013: if (view == linksView)
5014: TtaRaiseView (doc, view);
5015: else if (linksView != 0 && TtaIsViewOpen (doc, linksView))
5016: TtaRaiseView (doc, linksView);
5017: else
5018: {
5019: TtaGetViewGeometry (doc, "Links_view", &x, &y, &w, &h);
5020: linksView = TtaOpenView (doc, "Links_view", x, y, w, h);
5021: if (linksView != 0)
1.1136 gully 5022: {
5023: SetWindowTitle (doc, doc, linksView);
1.1084 gully 5024: #ifndef _WX
1.1136 gully 5025: TtcSwitchButtonBar (doc, linksView); /* no button bar */
5026: TtcSwitchCommands (doc, linksView); /* no command open */
1.1084 gully 5027: #endif /* _WX */
1.1136 gully 5028: UpdateEditorMenus (doc);
5029: }
1.950 vatton 5030: }
1.1075 gully 5031:
5032: /* the new opened view must get the focus */
5033: TtaRedirectFocus();
1.48 cvs 5034: }
5035:
5036:
5037: /*----------------------------------------------------------------------
1.407 cvs 5038: ShowToC
1.735 cvs 5039: Open the Table of content view of a document
1.48 cvs 5040: ----------------------------------------------------------------------*/
1.938 vatton 5041: void ShowToC (Document doc, View view)
1.48 cvs 5042: {
1.950 vatton 5043: View tocView;
5044: int x, y, w, h;
1.48 cvs 5045:
1.1058 vatton 5046: if (DocumentTypes[doc] == docSource)
5047: /* work on the formatted document */
5048: doc = GetDocFromSource (doc);
1.950 vatton 5049: tocView = TtaGetViewFromName (doc, "Table_of_contents");
5050: if (view == tocView)
5051: TtaRaiseView (doc, view);
5052: else if (tocView != 0 && TtaIsViewOpen (doc, tocView))
5053: TtaRaiseView (doc, tocView);
5054: else
5055: {
5056: TtaGetViewGeometry (doc, "Table_of_contents", &x, &y, &w, &h);
5057: tocView = TtaOpenView (doc, "Table_of_contents", x, y, w, h);
5058: if (tocView != 0)
1.1136 gully 5059: {
5060: SetWindowTitle (doc, doc, tocView);
1.1084 gully 5061: #ifndef _WX
1.1136 gully 5062: TtcSwitchButtonBar (doc, tocView); /* no button bar */
5063: TtcSwitchCommands (doc, tocView); /* no command open */
1.1084 gully 5064: #endif /* _WX */
1.1136 gully 5065: UpdateEditorMenus (doc);
5066: }
1.950 vatton 5067: }
1.1075 gully 5068:
5069: /* the new opened view must get the focus */
5070: TtaRedirectFocus();
1.6 cvs 5071: }
5072:
5073:
1.9 cvs 5074: /*----------------------------------------------------------------------
1.1136 gully 5075: RequestView: Thot request to open a view to show the current selection
1.1040 vatton 5076: ----------------------------------------------------------------------*/
5077: ThotBool RequestView (NotifyDialog *event)
5078: {
1.1136 gully 5079: ShowStructure (event->document, event->view);
5080: /* Inform Thot that the view is open by Amaya */
5081: return TRUE;
1.1040 vatton 5082: }
5083:
5084: /*----------------------------------------------------------------------
1.1136 gully 5085: ViewToClose
1.22 cvs 5086: ----------------------------------------------------------------------*/
1.878 vatton 5087: ThotBool ViewToClose (NotifyDialog *event)
1.22 cvs 5088: {
1.1136 gully 5089: Document document;
5090: View view, structView, altView, linksView, tocView;
5091:
5092: view = event->view;
5093: document = event->document;
5094: structView = TtaGetViewFromName (document, "Structure_view");
5095: altView = TtaGetViewFromName (document, "Alternate_view");
5096: linksView = TtaGetViewFromName (document, "Links_view");
5097: tocView = TtaGetViewFromName (document, "Table_of_contents");
5098: if (view != 1)
5099: {
5100: /* Save the current view geometry */
5101: if (view == structView)
5102: SaveGeometryOnExit (document, "Structure_view");
5103: if (view == altView)
5104: SaveGeometryOnExit (document, "Alternate_view");
5105: if (view == linksView)
5106: SaveGeometryOnExit (document, "Links_view");
5107: if (view == tocView)
5108: SaveGeometryOnExit (document, "Table_of_contents");
5109: /* let Thot perform normal operation */
5110: return FALSE;
5111: }
5112: else if (DocumentTypes[document] == docLibrary)
5113: {
5114: if (TtaIsDocumentModified (document))
5115: {
5116: InitConfirm (document, view, TtaGetMessage (AMAYA, AM_SAVE_DISK));
5117: if (UserAnswer)
5118: SaveDocument (document, view);
5119: TtaSetDocumentUnmodified (document);
5120: }
5121: }
1.1170 vatton 5122: else if (DocumentTypes[document] == docSource)
5123: TtaSetDocumentUnmodified (document);
1.1136 gully 5124: else if (!CanReplaceCurrentDocument (document, view))
5125: /* abort the command and don't let Thot perform normal operation */
5126: return TRUE;
1.22 cvs 5127:
1.1136 gully 5128: SaveGeometryOnExit (document, NULL); /* Save geometry of every view */
5129: if (structView!= 0 && TtaIsViewOpen (document, structView))
5130: TtaCloseView (document, structView);
5131: if (altView != 0 && TtaIsViewOpen (document, altView))
5132: TtaCloseView (document, altView);
5133: if (linksView != 0 && TtaIsViewOpen (document, linksView))
5134: TtaCloseView (document, linksView);
5135: if (tocView != 0 && TtaIsViewOpen (document, tocView))
5136: TtaCloseView (document, tocView);
1.946 gully 5137:
1.1136 gully 5138: /* let Thot perform normal operation */
5139: return FALSE;
1.22 cvs 5140: }
5141:
1.193 cvs 5142: /*----------------------------------------------------------------------
1.924 vatton 5143: The urlName is encoded with the default charset.
1.193 cvs 5144: ----------------------------------------------------------------------*/
1.751 vatton 5145: void GetAmayaDoc_callback (int newdoc, int status, char *urlName,
1.1136 gully 5146: char *outputfile, AHTHeaders *http_headers,
5147: void * context)
1.177 cvs 5148: {
1.799 vatton 5149: Element elFound;
5150: Document doc;
5151: Document res;
1.924 vatton 5152: AmayaDoc_context *ctx;
1.799 vatton 5153: TTcbf *cbf;
1.1190 vatton 5154: int method;
1.799 vatton 5155: void *ctx_cbf;
5156: char tempdocument[MAX_LENGTH];
5157: char *tempfile;
5158: char *target;
5159: char *pathname;
5160: char *initial_url;
5161: char *documentname;
5162: char *form_data;
5163: char *s;
5164: int i;
1.824 vatton 5165: ThotBool inNewWindow;
1.799 vatton 5166: ThotBool ok, keep;
5167: ThotBool stopped_flag = FALSE;
5168: ThotBool local_link;
5169:
5170: /* restore GETHTMLDocument's context */
1.924 vatton 5171: ctx = (AmayaDoc_context *) context;
1.799 vatton 5172: if (!ctx)
5173: return;
5174: doc = ctx->doc;
5175: target = ctx->target;
5176: documentname = ctx->documentname;
5177: initial_url = ctx->initial_url;
5178: form_data = ctx->form_data;
5179: cbf = ctx->cbf;
5180: ctx_cbf = ctx->ctx_cbf;
5181: method = ctx->method;
5182: local_link = ctx->local_link;
1.824 vatton 5183: inNewWindow = ctx->inNewWindow;
1.799 vatton 5184: ok = TRUE;
1.907 gully 5185: pathname = (char *)TtaGetMemory (MAX_LENGTH + 1);
1.799 vatton 5186: strncpy (pathname, urlName, MAX_LENGTH);
5187: pathname[MAX_LENGTH] = EOS;
1.907 gully 5188: tempfile = (char *)TtaGetMemory (MAX_LENGTH + 1);
1.799 vatton 5189: if (method != CE_MAKEBOOK && method != CE_ANNOT &&
5190: method != CE_LOG && method != CE_HELP &&
1.805 vatton 5191: DocumentTypes[newdoc] != docLibrary &&
5192: status == 0)
1.799 vatton 5193: {
5194: /* add the URI in the combobox string */
5195: keep = (method == CE_ABSOLUTE || method == CE_INIT);
1.839 kahan 5196: if (form_data && method == CE_FORM_GET)
1.1136 gully 5197: AddURLInCombobox (pathname, form_data, keep);
1.839 kahan 5198: else
1.1136 gully 5199: AddURLInCombobox (pathname, NULL, keep);
1.799 vatton 5200: }
5201: if (outputfile != NULL)
1.1136 gully 5202: {
5203: strncpy (tempfile, outputfile, MAX_LENGTH);
5204: tempfile[MAX_LENGTH] = EOS;
5205: }
5206: else
5207: tempfile[0] = EOS;
5208:
5209: /* now the new window is open */
5210: if (inNewWindow && (method == CE_RELATIVE || method == CE_ABSOLUTE))
5211: /* don't free the current loaded document */
5212: method = CE_INIT;
5213: if (!local_link)
5214: {
5215: /* memorize the initial newdoc value in doc because LoadDocument */
5216: /* will open a new document if newdoc is a modified document */
5217: if (status == 0)
5218: {
5219: /* the document was successfully loaded */
5220: if (IsW3Path (pathname))
5221: NormalizeURL (pathname, 0, tempdocument, documentname, NULL);
5222: /* parse and display the document */
5223: res = LoadDocument (newdoc, pathname, form_data,
5224: initial_url, method,
5225: tempfile, documentname,
1.1185 vatton 5226: http_headers, ctx->history, &inNewWindow, NULL);
1.1136 gully 5227: W3Loading = 0; /* loading is complete now */
5228: if (res == 0)
5229: {
5230: /* cannot load the document */
5231: ResetStop(newdoc);
5232: newdoc = 0;
5233: ok = FALSE;
5234: }
5235: else if (newdoc != res)
5236: newdoc = res;
5237: if (ok)
5238: {
5239: /* fetch and display all images referred by the document */
5240: if (method == CE_MAKEBOOK)
5241: stopped_flag = FetchAndDisplayImages (newdoc,
5242: AMAYA_LOAD_IMAGE | AMAYA_MBOOK_IMAGE,
5243: NULL);
5244: else
5245: {
5246: stopped_flag = FetchAndDisplayImages (newdoc, AMAYA_LOAD_IMAGE, NULL);
1.560 kahan 5247: #ifdef ANNOTATIONS
1.1136 gully 5248: /* if it's an annotation, add the existing metadata */
5249: if (DocumentTypes[newdoc] == docAnnot)
5250: ANNOT_LoadAnnotation (ctx->baseDoc, newdoc);
5251: /* auto-load the annotations associated with the document */
5252: if (ANNOT_CanAnnotate (newdoc))
5253: ANNOT_AutoLoad (newdoc, 1);
1.563 kahan 5254: #endif /* ANNOTATIONS */
1.1136 gully 5255: }
5256: }
5257: /* check parsing errors */
5258: if (DocumentTypes[newdoc] == docLog || method == CE_MAKEBOOK)
5259: CleanUpParsingErrors ();
5260: else
5261: CheckParsingErrors (newdoc);
5262: }
5263: else
5264: {
5265: /* a stop or an error occured */
5266: if (DocumentURLs[newdoc] == NULL)
5267: {
5268: /* save the document name into the document table */
5269: s = TtaStrdup (pathname);
5270: DocumentURLs[newdoc] = s;
5271: if (DocumentTypes[newdoc] == docLibrary)
5272: {
1.884 vatton 5273: #ifdef _SVG
1.1136 gully 5274: SelectLibraryFromPath (DocumentURLs[newdoc]);
5275: TtaSetTextZone (newdoc, 1, SVGlib_list);
1.884 vatton 5276: #endif /* _SVG */
1.1136 gully 5277: }
5278: else
5279: TtaSetTextZone (newdoc, 1, URL_list);
5280: /* save the document's formdata into the document table */
5281: if (DocumentMeta[newdoc])
5282: DocumentMetaClear (DocumentMeta[(int) newdoc]);
5283: else
5284: DocumentMeta[newdoc] = DocumentMetaDataAlloc ();
5285: DocumentMeta[newdoc]->form_data = TtaStrdup (form_data);
5286: if (strcmp (pathname, initial_url))
5287: DocumentMeta[newdoc]->initial_url = TtaStrdup (initial_url);
5288: else
5289: DocumentMeta[newdoc]->initial_url = NULL;
5290: DocumentMeta[newdoc]->method = method;
5291: DocumentMeta[newdoc]->xmlformat = FALSE;
1.1169 vatton 5292: DocumentMeta[newdoc]->compound = FALSE;
1.1136 gully 5293: DocumentSource[newdoc] = 0;
5294: ResetStop(newdoc);
5295: }
5296: W3Loading = 0; /* loading is complete now */
5297: ResetStop(newdoc);
5298: ok = FALSE;
5299: if (status == -2)
5300: {
5301: s = HTTP_headers (http_headers, AM_HTTP_REASON);
5302: if (!s)
5303: s = "";
5304: sprintf (tempdocument, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), pathname);
5305: InitConfirm3L (newdoc, 1, tempdocument, s, NULL, FALSE);
5306: }
5307: }
5308:
5309: if (ok && !stopped_flag)
5310: {
5311: ResetStop (newdoc);
1.945 quint 5312: #ifdef _GL
1.1136 gully 5313: if (FilesLoading[newdoc] == 0 &&
5314: TtaGetViewFrame (newdoc, 1) != 0)
5315: /* all files included in this document have been loaded and the
5316: document is displayed. Animations can be played now */
5317: TtaPlay (newdoc, 1);
1.945 quint 5318: #endif /* _GL */
1.1136 gully 5319: }
5320: }
5321:
5322: /* select the target if present */
5323: if (ok && !stopped_flag && target != NULL && target[0] != EOS &&
5324: newdoc != 0)
5325: {
5326: /* attribute HREF contains the NAME of a target anchor */
5327: elFound = SearchNAMEattribute (newdoc, target, NULL, NULL);
5328: if (elFound != NULL)
5329: {
5330: /* show the target element in all views */
5331: for (i = 1; i < 4; i++)
5332: if (TtaIsViewOpen (newdoc, i))
5333: TtaShowElement (newdoc, i, elFound, 0);
5334: }
5335: }
1.177 cvs 5336:
1.1136 gully 5337: /*** if stopped_flag == true, how to deal with cbf? */
5338: if (cbf)
5339: (*cbf) (newdoc, status, pathname, tempfile, NULL, ctx_cbf);
1.182 cvs 5340:
1.749 kirschpi 5341:
5342: #ifdef DAV
1.1136 gully 5343: /* MKP: if document has been loaded, we are *
5344: * able to discovery if the document is locked. *
5345: * do a lock discovery, set LockIndicator button */
5346: if (W3Loading == 0)
1.754 kirschpi 5347: {
1.749 kirschpi 5348: DAVLockDiscovery (newdoc);
5349: DAVSetLockIndicator(newdoc);
1.754 kirschpi 5350: }
1.749 kirschpi 5351: #endif
5352:
1.1136 gully 5353: TtaFreeMemory (target);
5354: TtaFreeMemory (documentname);
5355: TtaFreeMemory (initial_url);
5356: TtaFreeMemory (pathname);
5357: TtaFreeMemory (tempfile);
5358: if (form_data)
5359: TtaFreeMemory (form_data);
5360: TtaFreeMemory (ctx);
5361: /* check if a refresh is requested */
1.1100 vatton 5362: CheckRefresh (newdoc);
1.177 cvs 5363: }
1.22 cvs 5364:
5365: /*----------------------------------------------------------------------
1.799 vatton 5366: GetAmayaDoc loads the document if it is not loaded yet and calls the
5367: parser if the document can be parsed.
1.1136 gully 5368: - urlname: can be relative or absolute address.
5369: It's encoded with the default charset.
5370: - form_data: the text to be posted.
5371: - doc: the document which can be removed if not updated.
5372: - baseDoc: the document which urlname is relative to.
5373: - method: CE_FORM_POST for a post request, CE_RELATIVE for a double
5374: click.
5375: - history: record the URL in the browsing history
1.9 cvs 5376: ----------------------------------------------------------------------*/
1.924 vatton 5377: Document GetAmayaDoc (char *urlname, char *form_data,
1.1190 vatton 5378: Document doc, Document baseDoc, int method,
1.1136 gully 5379: ThotBool history, TTcbf *cbf, void *ctx_cbf)
1.6 cvs 5380: {
1.874 vatton 5381: Document newdoc, refdoc;
1.861 vatton 5382: CSSInfoPtr css;
5383: PInfoPtr pInfo;
1.924 vatton 5384: AmayaDoc_context *ctx = NULL;
1.861 vatton 5385: char *tempfile;
5386: char *parameters;
5387: char *target;
1.924 vatton 5388: char *initial_url;
1.861 vatton 5389: char *documentname;
5390: char *content_type = NULL;
5391: int toparse;
5392: int mode;
5393: int docType;
5394: ThotBool ok;
1.10 cvs 5395:
1.861 vatton 5396: /* Extract parameters if necessary */
1.924 vatton 5397: if (strlen (urlname) > MAX_LENGTH - 1)
1.861 vatton 5398: {
5399: TtaSetStatus (baseDoc, 1, TtaGetMessage (AMAYA, AM_TOO_LONG_URL), "512");
5400: return (0);
5401: }
1.1105 gully 5402: #ifndef _WX
1.861 vatton 5403: else
5404: /* clean up the status line */
5405: TtaSetStatus (baseDoc, 1, " ", NULL);
1.1105 gully 5406: #endif /* _WX */
5407:
1.1132 vatton 5408: /* check if the request comes from the source document */
5409: if (doc && DocumentTypes[doc] == docSource)
5410: doc = GetDocFromSource (doc);
1.861 vatton 5411: ok = TRUE;
1.907 gully 5412: target = (char *)TtaGetMemory (MAX_LENGTH);
5413: documentname = (char *)TtaGetMemory (MAX_LENGTH);
5414: parameters = (char *)TtaGetMemory (MAX_LENGTH);
5415: tempfile = (char *)TtaGetMemory (MAX_LENGTH);
1.861 vatton 5416: tempfile[0] = EOS;
1.924 vatton 5417: initial_url = (char *)TtaGetMemory (MAX_LENGTH);
5418: ExtractParameters (urlname, parameters);
1.861 vatton 5419: /* Extract the target if necessary */
1.924 vatton 5420: ExtractTarget (urlname, target);
1.861 vatton 5421: /* Add the base content if necessary */
5422: if (method == CE_RELATIVE || method == CE_FORM_GET ||
5423: method == CE_FORM_POST || method == CE_MAKEBOOK)
1.924 vatton 5424: NormalizeURL (urlname, baseDoc, initial_url, documentname, NULL);
1.861 vatton 5425: else
1.1136 gully 5426: NormalizeURL (urlname, 0, initial_url, documentname, NULL);
1.861 vatton 5427: /* check the document suffix */
5428: if (IsMathMLName (documentname))
5429: docType = docMath;
5430: else if (IsSVGName (documentname))
5431: docType = docSVG;
5432: else if (IsCSSName (documentname))
5433: docType = docCSS;
5434: else if (IsTextName (documentname))
1.1136 gully 5435: docType = docText;
1.616 cvs 5436: #ifdef XML_GENERIC
1.861 vatton 5437: else if (IsXMLName (documentname))
5438: docType = docXml;
1.616 cvs 5439: #endif /* XML_GENERIC */
1.884 vatton 5440: #ifdef _SVG
1.861 vatton 5441: else if (IsLibraryName (documentname))
5442: docType = docLibrary;
1.884 vatton 5443: #endif /* _SVG */
1.861 vatton 5444: else if (method == CE_CSS)
5445: docType = docCSS;
1.1018 vatton 5446: else if (method == CE_LOG)
5447: docType = docLog;
1.861 vatton 5448: else
5449: docType = docHTML;
5450:
1.1136 gully 5451: /* we skip the file: prefix if it is present and do other local
5452: file urls conversions */
1.924 vatton 5453: if (!IsW3Path (initial_url))
1.861 vatton 5454: {
5455: /* we take the long way around to get the result
1.1136 gully 5456: of normalizeFile, as the function doesn't allocate
5457: memory dynamically (note: this can generate some MAX_LENGTH
5458: problems) */
1.861 vatton 5459: if (method == CE_RELATIVE || method == CE_FORM_GET ||
1.1136 gully 5460: method == CE_ANNOT || method == CE_FORM_POST ||
5461: method == CE_MAKEBOOK)
5462: /* we're following a link, so do all the convertions on
5463: the URL */
5464: NormalizeFile (initial_url, tempfile, AM_CONV_ALL);
1.861 vatton 5465: else
1.1136 gully 5466: NormalizeFile (initial_url, tempfile, AM_CONV_NONE);
1.924 vatton 5467: strcpy (initial_url, tempfile);
1.861 vatton 5468: tempfile[0] = EOS;
5469: }
1.336 cvs 5470:
1.861 vatton 5471: /* check if the user is already browsing the document in another window */
5472: if (method == CE_FORM_GET)
5473: {
1.924 vatton 5474: newdoc = IsDocumentLoaded (initial_url, form_data);
1.861 vatton 5475: /* we don't concatenate the new parameters as we give preference
1.1136 gully 5476: to the form data */
1.861 vatton 5477: }
5478: else
5479: {
5480: /* concatenate the parameters before making the test */
5481: if (parameters[0] != EOS)
1.1136 gully 5482: {
5483: strcat (initial_url, "?");
5484: strcat (initial_url, parameters);
5485: }
1.861 vatton 5486: /* if it's a POST form, we search the document using the
1.1136 gully 5487: form_data */
1.861 vatton 5488: if (method == CE_FORM_POST)
1.1136 gully 5489: newdoc = IsDocumentLoaded (initial_url, form_data);
1.861 vatton 5490: else
1.1136 gully 5491: newdoc = IsDocumentLoaded (initial_url, NULL);
1.861 vatton 5492: }
1.471 kahan 5493:
1.861 vatton 5494: if (newdoc != 0)
5495: /* the document is already loaded */
5496: {
5497: if (newdoc == doc)
1.1136 gully 5498: /* it's a move in the same document */
5499: {
5500: if (history)
5501: /* record the current position in the history */
5502: AddDocHistory (newdoc, DocumentURLs[newdoc],
5503: DocumentMeta[doc]->initial_url,
5504: DocumentMeta[doc]->form_data,
5505: DocumentMeta[doc]->method);
5506: }
5507: else
5508: /* following the link to another open window */
5509: {
5510: /* raise its window */
5511: TtaRaiseView (newdoc, 1);
5512: /* don't add it to the doc's historic */
5513: history = FALSE;
5514: }
1.861 vatton 5515: }
1.185 cvs 5516:
1.861 vatton 5517: /* Create the context for the callback */
1.924 vatton 5518: ctx = (AmayaDoc_context*)TtaGetMemory (sizeof (AmayaDoc_context));
1.861 vatton 5519: ctx->doc = doc;
5520: ctx->baseDoc = baseDoc;
5521: ctx->history = history;
5522: ctx->target = target;
5523: ctx->documentname = documentname;
1.924 vatton 5524: ctx->initial_url = TtaStrdup (initial_url);
1.861 vatton 5525: if (form_data)
5526: ctx->form_data = TtaStrdup (form_data);
5527: else
5528: ctx->form_data = NULL;
5529: ctx->method = method;
5530: ctx->cbf = cbf;
5531: ctx->ctx_cbf = ctx_cbf;
5532: ctx->local_link = 0;
1.1022 gully 5533: ctx->inNewWindow = DontReplaceOldDoc;
1.185 cvs 5534:
1.861 vatton 5535: toparse = 0;
5536: if (newdoc == 0)
5537: {
1.924 vatton 5538: /*
1.1136 gully 5539: DocumentURLs and DocHistory are coded in the default charset */
1.861 vatton 5540: /* document not loaded yet */
5541: if ((method == CE_RELATIVE || method == CE_FORM_GET ||
1.1136 gully 5542: method == CE_FORM_POST || method == CE_MAKEBOOK ||
5543: method == CE_ANNOT) &&
5544: !IsW3Path (initial_url) && !TtaFileExist (initial_url))
5545: {
5546: /* the target document doesn't exist */
5547: TtaSetStatus (baseDoc, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), initial_url);
5548: ok = FALSE; /* do not continue */
5549: }
1.861 vatton 5550: else if (method == CE_LOG)
1.1136 gully 5551: /* need to create a new window for the document */
5552: newdoc = InitDocAndView ( baseDoc, /* SG: 'doc' is always NULL, maybe it should be baseDoc */
5553: FALSE /* replaceOldDoc */,
5554: TRUE /* inNewWindow */,
5555: documentname, (DocumentType)docLog, 0, FALSE,
1.1190 vatton 5556: L_Other, method);
1.861 vatton 5557: else if (method == CE_HELP)
1.1136 gully 5558: {
5559: /* add the URI in the combobox string */
5560: AddURLInCombobox (initial_url, NULL, FALSE);
1.1022 gully 5561: #ifdef _WX
1.1136 gully 5562: /* need to create a new window for the document */
5563: newdoc = InitDocAndView (baseDoc,
1.1088 gully 5564: !DontReplaceOldDoc /* replaceOldDoc */,
5565: InNewWindow /* inNewWindow */,
1.1136 gully 5566: documentname, (DocumentType)docType, 0, TRUE,
1.1190 vatton 5567: L_Other, method);
1.1022 gully 5568: #else /* _WX */
1.1136 gully 5569: /* need to create a new window for the document */
5570: newdoc = InitDocAndView (doc,
1.926 gully 5571: FALSE /* replaceOldDoc */,
5572: TRUE /* inNewWindow */,
1.1136 gully 5573: documentname, (DocumentType)docType, 0, TRUE,
1.1190 vatton 5574: L_Other, method);
1.1022 gully 5575: #endif /* _WX */
1.1136 gully 5576: if (newdoc)
5577: {
5578: /* help document has to be in read-only mode */
1.1084 gully 5579: #ifndef _WX
1.1136 gully 5580: TtcSwitchCommands (newdoc, 1); /* no command open */
1.1084 gully 5581: #endif /* _WX */
1.1136 gully 5582: TtaSetToggleItem (newdoc, 1, Views, TShowTextZone, FALSE);
5583: TtaSetMenuOff (newdoc, 1, Help_);
5584: }
5585: }
1.452 cvs 5586: #ifdef ANNOTATIONS
1.861 vatton 5587: else if (method == CE_ANNOT)
1.1136 gully 5588: {
5589: /* need to create a new window for the document */
5590: newdoc = InitDocAndView (doc,
1.926 gully 5591: FALSE /* replaceOldDoc */,
5592: TRUE /* inNewWindow */,
1.1136 gully 5593: documentname, (DocumentType)docAnnot, 0, FALSE,
1.1190 vatton 5594: L_Annot, method);
1.1136 gully 5595: /* we're downloading an annotation, fix the accept_header
5596: (thru the content_type variable) to application/rdf */
5597: content_type = "application/rdf";
5598: }
1.452 cvs 5599: #endif /* ANNOTATIONS */
1.1022 gully 5600: else if (doc == 0 || DontReplaceOldDoc)
1.1136 gully 5601: {
5602: /* In case of initial document, open the view before loading */
5603: /* add the URI in the combobox string */
5604: AddURLInCombobox (initial_url, NULL, FALSE);
5605: newdoc = InitDocAndView (doc,
1.926 gully 5606: FALSE /* replaceOldDoc */,
5607: #ifndef _WX
5608: TRUE /* inNewWindow */,
5609: #else /* _WX */
1.1136 gully 5610: InNewWindow /* inNewWindow */,
1.926 gully 5611: #endif /* _WX */
1.1136 gully 5612: documentname, (DocumentType)docType, 0, FALSE,
1.1190 vatton 5613: L_Other, method);
1.1136 gully 5614: }
5615: else
5616: {
5617: newdoc = doc;
5618: /* stop current transfer for previous document */
5619: if (method != CE_MAKEBOOK)
5620: StopTransfer (baseDoc, 1);
5621: else
5622: /* temporary docs to make a book are not in ReadOnly mode */
5623: DocumentTypes[newdoc] = docHTML;
5624: }
1.861 vatton 5625:
5626: if (newdoc == 0)
1.1136 gully 5627: /* cannot display the new document */
5628: ok = FALSE;
1.861 vatton 5629: if (ok)
1.1136 gully 5630: {
5631: /* this document is currently in load */
5632: W3Loading = newdoc;
5633: ActiveTransfer (newdoc);
5634: /* set up the transfer mode */
5635: mode = AMAYA_ASYNC | AMAYA_FLUSH_REQUEST;
5636:
5637: if (method == CE_FORM_POST)
5638: mode = mode | AMAYA_FORM_POST | AMAYA_NOCACHE;
5639: else if (method == CE_MAKEBOOK)
5640: mode = AMAYA_ASYNC;
5641:
5642: if (IsW3Path (initial_url))
5643: {
5644: css = SearchCSS (0, initial_url, NULL, &pInfo);
5645: if (method == CE_MAKEBOOK || method == CE_RELATIVE)
5646: /* add the referer field in the GET */
5647: refdoc = doc;
5648: else
5649: refdoc = 0;
5650: if ((css == NULL) || (css != NULL && newdoc == doc))
5651: toparse = GetObjectWWW (newdoc, refdoc, initial_url, form_data,
5652: tempfile, mode, NULL, NULL,
5653: (void (*)(int, int, char*, char*, const AHTHeaders*, void*)) GetAmayaDoc_callback,
5654: (void *) ctx, YES, content_type);
5655: else
5656: {
5657: /* it was already loaded, we need to open it */
5658: TtaSetStatus (newdoc, 1,
5659: TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
5660: /* just take a copy of the local temporary file */
5661: strcpy (tempfile, css->localName);
5662: GetAmayaDoc_callback (newdoc, 0, initial_url,
5663: tempfile, NULL, (void *) ctx);
5664: TtaHandlePendingEvents ();
5665: }
5666: }
5667: else
5668: {
5669: /* wasn't a document off the web, we need to open it */
5670: TtaSetStatus (newdoc, 1,
5671: TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED),
5672: NULL);
5673: GetAmayaDoc_callback (newdoc, 0, initial_url, tempfile,
5674: NULL, (void *) ctx);
5675: TtaHandlePendingEvents ();
5676: }
5677: }
1.861 vatton 5678: }
5679: else if (ok && newdoc != 0)
5680: {
5681: /* following a local link */
5682: TtaSetStatus (newdoc, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
5683: ctx->local_link = 1;
1.924 vatton 5684: GetAmayaDoc_callback (newdoc, 0, initial_url, tempfile, NULL, (void *) ctx);
1.861 vatton 5685: TtaHandlePendingEvents ();
5686: }
5687:
5688: if (ok == FALSE)
5689: /* if the document isn't loaded off the web (because of an error, or
5690: because it was already loaded), we invoke the callback function */
5691: {
5692: if (ctx->form_data)
1.1136 gully 5693: TtaFreeMemory (ctx->form_data);
1.861 vatton 5694: TtaFreeMemory (ctx->initial_url);
5695: if (ctx)
1.1136 gully 5696: TtaFreeMemory (ctx);
1.861 vatton 5697: if (cbf)
1.1136 gully 5698: (*cbf) (newdoc, -1, initial_url, tempfile, NULL, ctx_cbf);
1.861 vatton 5699: /* Free the memory associated with the context */
5700: TtaFreeMemory (target);
5701: TtaFreeMemory (documentname);
5702: }
5703: TtaFreeMemory (parameters);
5704: TtaFreeMemory (tempfile);
1.924 vatton 5705: TtaFreeMemory (initial_url);
1.1022 gully 5706: DontReplaceOldDoc = FALSE;
1.861 vatton 5707: return (newdoc);
1.6 cvs 5708: }
5709:
1.9 cvs 5710: /*----------------------------------------------------------------------
1.706 cvs 5711: ChangeDoctype
1.711 cvs 5712: Mofity the doctype declaration for a HTML document saved as XML
5713: and vice-versa.
1.706 cvs 5714: isXml indicates is the new doctype corresponds to an XML document
5715: ----------------------------------------------------------------------*/
1.905 vatton 5716: static void ChangeDoctype (ThotBool isXml)
1.706 cvs 5717: {
5718: int profile;
5719: Document doc;
5720: ElementType elType;
1.840 cvs 5721: Element root, htmlRoot, doctype, doctypeLine, prevLine, text;
1.706 cvs 5722:
5723: doc = SavingDocument;
5724: root = TtaGetMainRoot (doc);
5725: elType.ElSSchema = TtaGetDocumentSSchema (doc);
5726: if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
5727: return;
1.840 cvs 5728:
5729: /* Update the namespace declaration for the HTML element */
5730: elType.ElTypeNum = HTML_EL_HTML;
5731: htmlRoot = TtaSearchTypedElement (elType, SearchForward, root);
5732: if (!htmlRoot)
5733: return;
5734: if (isXml)
5735: TtaSetANamespaceDeclaration (doc, htmlRoot, NULL, XHTML_URI);
5736: else
5737: TtaFreeElemNamespaceDeclarations (doc, htmlRoot);
5738:
5739: /* Search the DOCTYPE element */
1.706 cvs 5740: elType.ElTypeNum = HTML_EL_DOCTYPE;
5741: doctype = TtaSearchTypedElement (elType, SearchForward, root);
5742: if (!doctype)
5743: return;
5744:
5745: /* Remove the previous doctype element */
5746: TtaDeleteTree (doctype, doc);
5747:
5748: profile = TtaGetDocumentProfile (doc);
1.723 quint 5749: /* Don't check the Thot abstract tree against the structure schema. */
1.1051 vatton 5750: TtaSetStructureChecking (FALSE, doc);
1.706 cvs 5751:
5752: doctype = TtaNewElement (doc, elType);
5753: TtaInsertFirstChild (&doctype, root, doc);
1.712 cvs 5754: /* Make the DOCTYPE element read-only */
5755: TtaSetAccessRight (doctype, ReadOnly, doc);
1.706 cvs 5756: /* create the first DOCTYPE_line element */
5757: elType.ElTypeNum = HTML_EL_DOCTYPE_line;
5758: doctypeLine = TtaNewElement (doc, elType);
5759: TtaInsertFirstChild (&doctypeLine, doctype, doc);
5760: elType.ElTypeNum = 1;
5761: text = TtaNewElement (doc, elType);
5762: if (text != NULL)
5763: {
5764: TtaInsertFirstChild (&text, doctypeLine, SavingDocument);
5765: if (isXml)
1.1136 gully 5766: {
5767: /* XML document */
5768: if (profile == L_Strict)
5769: TtaSetTextContent (text, (unsigned char *)DOCTYPE1_XHTML10_STRICT, Latin_Script, doc);
5770: else
5771: TtaSetTextContent (text, (unsigned char *)DOCTYPE1_XHTML10_TRANSITIONAL, Latin_Script, doc);
5772: }
5773: else
5774: {
5775: /* HTML document */
5776: if (profile == L_Strict)
5777: TtaSetTextContent (text, (unsigned char *)DOCTYPE1_HTML_STRICT, Latin_Script, doc);
5778: else
5779: TtaSetTextContent (text, (unsigned char *)DOCTYPE1_HTML_TRANSITIONAL, Latin_Script, doc);
5780: }
1.706 cvs 5781: }
5782: /* create the second DOCTYPE_line element */
5783: elType.ElTypeNum = HTML_EL_DOCTYPE_line;
5784: prevLine = doctypeLine;
5785: doctypeLine = TtaNewElement (doc, elType);
5786: TtaInsertSibling (doctypeLine, prevLine, FALSE, doc);
5787: elType.ElTypeNum = 1;
5788: text = TtaNewElement (doc, elType);
5789: if (text != NULL)
5790: {
5791: TtaInsertFirstChild (&text, doctypeLine, doc);
5792: if (isXml)
1.1136 gully 5793: {
5794: /* XML document */
5795: if (profile == L_Strict)
5796: TtaSetTextContent (text, (unsigned char *)DOCTYPE2_XHTML10_STRICT, Latin_Script, doc);
5797: else
5798: TtaSetTextContent (text, (unsigned char *)DOCTYPE2_XHTML10_TRANSITIONAL, Latin_Script, doc);
5799: }
5800: else
5801: {
5802: /* HTML document */
5803: if (profile == L_Strict)
5804: TtaSetTextContent (text, (unsigned char *)DOCTYPE2_HTML_STRICT, Latin_Script, doc);
5805: else
5806: TtaSetTextContent (text, (unsigned char *)DOCTYPE2_HTML_TRANSITIONAL, Latin_Script, doc);
5807: }
1.706 cvs 5808: }
1.1051 vatton 5809: TtaSetStructureChecking (TRUE, doc);
1.706 cvs 5810: }
5811:
5812: /*----------------------------------------------------------------------
1.1136 gully 5813: UpdateSaveAsButtons
5814: Maintain consistency between buttons in the Save As dialog box
1.139 cvs 5815: ----------------------------------------------------------------------*/
1.678 vatton 5816: static void UpdateSaveAsButtons ()
1.139 cvs 5817: {
1.1136 gully 5818: #if defined(_GTK)
1.140 cvs 5819: int active;
5820:
1.626 vatton 5821: if (SaveAsHTML || SaveAsXML)
5822: active = 1;
1.140 cvs 5823: else
1.515 cvs 5824: active = 0;
1.915 gully 5825: TtaRedrawMenuEntry (BaseDialog + ToggleSave, 0, NULL, (ThotColor)-1, active);
5826: TtaRedrawMenuEntry (BaseDialog + ToggleSave, 1, NULL, (ThotColor)-1, active);
1.1136 gully 5827: #endif /* defined(_GTK) */
1.139 cvs 5828: }
5829:
5830: /*----------------------------------------------------------------------
1.1136 gully 5831: SetFileSuffix
5832: Set the suffix of the file name used for saving a document
1.139 cvs 5833: ----------------------------------------------------------------------*/
1.548 cvs 5834: static void SetFileSuffix ()
1.139 cvs 5835: {
1.548 cvs 5836: char suffix[6];
5837: char *filename;
5838: int i, len;
1.139 cvs 5839:
1.756 vatton 5840: if (SavingDocument && SaveName[0] != EOS)
1.445 cvs 5841: {
1.1136 gully 5842: if (SaveAsHTML)
1.547 cvs 5843: strcpy (suffix, "html");
1.1136 gully 5844: else if (SaveAsXML)
1.548 cvs 5845: strcpy (suffix, "html");
1.1136 gully 5846: else if (SaveAsText)
1.547 cvs 5847: strcpy (suffix, "txt");
1.1136 gully 5848: else
1.445 cvs 5849: return;
1.139 cvs 5850:
1.1136 gully 5851: /* looks for a suffix at the end of the document name */
5852: len = strlen (SaveName);
5853: for (i = len-1; i > 0 && SaveName[i] != '.'; i--);
5854: if (SaveName[i] != '.')
5855: {
5856: /* there is no suffix */
5857: i = len;
5858: SaveName[i++] = '.';
5859: }
5860: else
5861: {
5862: /* there is a suffix */
5863: i++;
5864: if (strncmp (suffix, &SaveName[i], 3) == 0)
5865: /* the requested suffix is already here. Do nothing */
5866: i = 0;
1.916 cvs 5867: #ifdef _WINGUI
1.1136 gully 5868: strcpy (DocToOpen, SavePath);
5869: if (strchr (SavePath, '/'))
5870: strcat (DocToOpen, URL_STR);
5871: else
5872: strcat (DocToOpen, DIR_STR);
5873: strcat (DocToOpen, SaveName);
1.916 cvs 5874: #endif /* _WINGUI */
1.1136 gully 5875: }
1.445 cvs 5876:
1.1136 gully 5877: if (i > 0)
5878: {
5879: /* change or append the suffix */
5880: strcpy (&SaveName[i], suffix);
5881: /* display the new filename in the dialog box */
5882: filename = (char *)TtaGetMemory (MAX_LENGTH);
5883: strcpy (filename, SavePath);
5884: if (strchr (SavePath, '/'))
5885: strcat (filename, URL_STR);
5886: else
5887: strcat (filename, DIR_STR);
5888: strcat (filename, SaveName);
1.891 gully 5889:
1.916 cvs 5890: #ifdef _WINGUI
1.1136 gully 5891: sprintf (DocToOpen, filename);
1.916 cvs 5892: #endif /* _WINGUI */
1.891 gully 5893:
1.1136 gully 5894: #ifdef _GTK
5895: TtaSetTextForm (BaseDialog + NameSave, filename);
5896: #endif /* defined(_GTK) */
5897:
5898: #ifdef _WX
5899: strcpy(SaveFileName, filename);
5900: #endif /* _WX */
5901:
5902: TtaFreeMemory (filename);
5903: }
5904: else
5905: {
5906: #ifdef _WX
5907: SaveFileName[0] = EOS;
5908: #endif /* _WX */
5909: }
1.445 cvs 5910: }
1.139 cvs 5911: }
5912:
5913: /*----------------------------------------------------------------------
1.1136 gully 5914: Callback procedure for dialogue events.
1.9 cvs 5915: ----------------------------------------------------------------------*/
1.599 cvs 5916: void CallbackDialogue (int ref, int typedata, char *data)
1.6 cvs 5917: {
1.1137 vatton 5918: Document doc = 0;
1.626 vatton 5919: char tempfile[MAX_LENGTH];
5920: char tempname[MAX_LENGTH];
1.1053 cvs 5921: char sep, *ptr;
1.1143 cvs 5922: long int val;
1.1144 cvs 5923: #ifdef _WX
1.896 cvs 5924: int i;
1.1144 cvs 5925: #endif /* _WX */
1.810 vatton 5926: ThotBool change, updated;
1.126 cvs 5927:
1.547 cvs 5928: if (typedata == STRING_DATA && data && strchr (data, '/'))
5929: sep = URL_SEP;
1.389 cvs 5930: else
1.547 cvs 5931: sep = DIR_SEP;
1.1143 cvs 5932: val = (long int) data;
1.968 vatton 5933: if (ref - BaseDialog == OptionMenu)
5934: /* a popup menu corresponding to a SELECT element */
5935: ReturnOption = val;
1.756 vatton 5936: else switch (ref - BaseDialog)
5937: {
5938: case OpenForm:
5939: /* *********Load URL or local document********* */
5940: if (val == 1)
1.1134 gully 5941: /* Confirm */
5942: {
1.1078 gully 5943: #ifdef _WX
1.1137 vatton 5944: /* get the current document (CurrentDocument not valid) */
5945: TtaGiveActiveView (&doc, &i);
1.1138 vatton 5946: if (DocumentSource[doc] && DocumentTypes[doc] != docSource)
5947: /* it could be a log or show document */
5948: doc = DocumentSource[doc];
1.1137 vatton 5949: CurrentDocument = doc;
5950: if ((CurrentDocument == 0) || /* this is the first loaded doc */
5951: (!InNewWindow && DontReplaceOldDoc) || /* in a new tab */
5952: (InNewWindow) || /* in a new window */
5953: (!DontReplaceOldDoc && CanReplaceCurrentDocument(CurrentDocument, 1)) /* wants to replace the current document */
1.1134 gully 5954: )
5955: {
1.1171 cvs 5956: #else /* _WX */
1.1183 vatton 5957: /* Do not destroy this dialog on WX to prevent a crash on mac version */
5958: TtaDestroyDialogue (BaseDialog + OpenForm);
1.1171 cvs 5959: TtaDestroyDialogue (BaseDialog + FileBrowserForm);
1.1078 gully 5960: #endif /* _WX */
1.1134 gully 5961: if (LastURLName[0] != EOS)
5962: {
5963: TtaSetStatus (CurrentDocument, 1,
5964: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
5965: DocumentName);
5966: /* update the list of URLs */
5967: if (NewFile)
1.1137 vatton 5968: InitializeNewDoc (LastURLName, NewDocType,
5969: doc, NewDocProfile, NewXML);
1.1134 gully 5970: /* load an URL */
5971: else if (DontReplaceOldDoc)
1.1137 vatton 5972: GetAmayaDoc (LastURLName, NULL, doc, doc,
1.1190 vatton 5973: Loading_method,
1.1137 vatton 5974: FALSE, NULL, NULL);
1.1134 gully 5975: else
5976: GetAmayaDoc (LastURLName, NULL, CurrentDocument,
1.1190 vatton 5977: CurrentDocument, Loading_method,
1.1137 vatton 5978: TRUE, NULL, NULL);
1.1134 gully 5979: }
5980: else if (DirectoryName[0] != EOS && DocumentName[0] != EOS)
5981: {
5982: /* load a local file */
5983: strcpy (tempfile, DirectoryName);
5984: strcat (tempfile, DIR_STR);
5985: strcat (tempfile, DocumentName);
5986: /* update the list of URLs */
5987: NormalizeFile (tempfile, tempname, AM_CONV_ALL);
1.1137 vatton 5988: if (NewFile)
5989: InitializeNewDoc (tempfile, NewDocType,
5990: doc, NewDocProfile, NewXML);
5991: else if (FileExistTarget (tempname))
1.1134 gully 5992: {
5993: if (DontReplaceOldDoc)
1.1137 vatton 5994: GetAmayaDoc (tempfile, NULL,
5995: doc, doc,
1.1190 vatton 5996: Loading_method,
1.1134 gully 5997: FALSE, NULL, NULL);
5998: else
5999: GetAmayaDoc (tempfile, NULL, CurrentDocument,
1.1190 vatton 6000: CurrentDocument, Loading_method,
1.1134 gully 6001: TRUE, NULL, NULL);
6002: }
6003: else
6004: {
1.1183 vatton 6005: #ifdef IV
1.1134 gully 6006: if (IsMathMLName (tempfile))
6007: NewDocType = docMath;
6008: else if (IsSVGName (tempfile))
6009: NewDocType = docSVG;
6010: else if (IsCSSName (tempfile))
6011: NewDocType = docCSS;
1.616 cvs 6012: #ifdef XML_GENERIC
1.1134 gully 6013: else if (IsXMLName (tempfile))
6014: NewDocType = docXml;
1.616 cvs 6015: #endif /* XML_GENERIC */
1.884 vatton 6016: #ifdef _SVG
1.1134 gully 6017: else if (IsLibraryName (tempfile))
6018: NewDocType = docLibrary;
1.884 vatton 6019: #endif /* _SVG */
1.1134 gully 6020: else
6021: NewDocType = docHTML;
6022: InitializeNewDoc (tempfile, NewDocType, CurrentDocument,
6023: NewDocProfile, NewXML);
1.1183 vatton 6024: #endif /* IV */
6025: NotFoundDoc (tempfile, CurrentDocument);
1.1134 gully 6026: }
6027: }
6028: else if (DocumentName[0] != EOS)
6029: {
6030: ptr = DocumentName;
6031: updated = CompleteUrl (&ptr);
6032: if (updated)
6033: {
6034: strcpy (DocumentName, ptr);
6035: TtaFreeMemory (ptr);
6036: }
6037: /* update the list of URLs */
6038: if (DontReplaceOldDoc)
1.1137 vatton 6039: GetAmayaDoc (DocumentName, NULL, doc, doc,
1.1190 vatton 6040: Loading_method,
1.1137 vatton 6041: FALSE, NULL, NULL);
1.1134 gully 6042: else
6043: GetAmayaDoc (DocumentName, NULL, CurrentDocument,
1.1190 vatton 6044: CurrentDocument, Loading_method,
1.1137 vatton 6045: TRUE, NULL, NULL);
1.1134 gully 6046: }
6047: else if (DirectoryName[0] != EOS)
6048: TtaSetStatus (CurrentDocument, 1,
6049: TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
6050: DirectoryName);
6051: else
6052: TtaSetStatus (CurrentDocument, 1,
6053: TtaGetMessage (AMAYA, AM_CANNOT_LOAD), "");
6054: NewFile = FALSE;
6055: CurrentDocument = 0;
1.1078 gully 6056: #ifdef _WX
1.1134 gully 6057: }
1.1078 gully 6058: #endif /* _WX */
1.1134 gully 6059: }
1.756 vatton 6060: else if (val == 2)
1.1134 gully 6061: {
6062: /* Browse button */
1.979 gully 6063: #if defined(_GTK) || defined(_WX)
1.1134 gully 6064: WidgetParent = OpenDocBrowser;
6065: BrowserForm (CurrentDocument, 1, &LastURLName[0]);
1.979 gully 6066: #endif /* defined(_GTK) || defined(_WX) */
1.1134 gully 6067: }
1.756 vatton 6068: else if (val == 3)
1.1134 gully 6069: {
6070: /* Clear button */
6071: LastURLName[0] = EOS;
6072: DirectoryName[0] = EOS;
6073: DocumentName[0] = EOS;
1.979 gully 6074: #if defined(_GTK) || defined(_WX)
1.1134 gully 6075: TtaSetTextForm (BaseDialog + URLName, LastURLName);
1.979 gully 6076: #endif /* defined(_GTK) || defined(_WX) */
1.1134 gully 6077: }
1.998 gully 6078: #ifdef _WX
6079: else if (val == 0)
1.1134 gully 6080: {
6081: /* if the user has clicked on Cancel button, just destroy the dialog */
6082: TtaDestroyDialogue ( ref );
6083: }
1.998 gully 6084: #endif /* _WX */
1.756 vatton 6085: else if (NewFile)
1.1134 gully 6086: {
6087: /* the command is aborted */
6088: CheckAmayaClosed ();
6089: NewFile = FALSE;
6090: }
1.756 vatton 6091: break;
1.485 cvs 6092:
1.1078 gully 6093: /* this callback is used to select a destination for the new open document :
6094: * 0 = replace current one
6095: * 1 = in new tab
6096: * 2 = in new window */
6097: case OpenLocation:
6098: {
1.1134 gully 6099: if (val == 0) /* replace old doc */
6100: {
6101: DontReplaceOldDoc = FALSE;
6102: InNewWindow = FALSE;
6103: }
6104: else if (val == 1) /* in new tab */
6105: {
6106: DontReplaceOldDoc = TRUE;
6107: InNewWindow = FALSE;
6108: }
6109: else if (val == 2) /* in new window */
6110: {
6111: DontReplaceOldDoc = TRUE;
6112: InNewWindow = TRUE;
6113: }
1.1078 gully 6114: }
6115: break;
1.1114 vatton 6116: case DocInfoDocType:
6117: /* only used by WX version to get back the new profile */
6118: if (NewDocType == docHTML)
1.1134 gully 6119: {
6120: if (!strstr (data, "XHTML"))
6121: NewXML = FALSE;
6122: if (strstr (data, "Strict"))
6123: NewDocProfile = L_Strict;
6124: else if (strstr (data, "Basic"))
6125: NewDocProfile = L_Basic;
6126: else if (strstr (data, "Transitional"))
6127: NewDocProfile = L_Transitional;
6128: else if (NewXML)
6129: NewDocProfile = L_Xhtml11;
6130: else
6131: NewDocProfile = L_Transitional;
6132: }
1.1114 vatton 6133: break;
1.756 vatton 6134: case URLName:
6135: RemoveNewLines (data);
1.810 vatton 6136: ptr = data;
6137: updated = CompleteUrl (&ptr);
6138: if (IsW3Path (ptr))
1.1134 gully 6139: {
6140: /* save the URL name */
6141: strcpy (LastURLName, ptr);
6142: DocumentName[0] = EOS;
6143: }
1.756 vatton 6144: else
1.1134 gully 6145: {
6146: LastURLName[0] = EOS;
6147: change = NormalizeFile (ptr, tempfile, AM_CONV_NONE);
6148: if (!IsW3Path (tempfile))
6149: {
6150: if (TtaCheckDirectory (tempfile))
6151: {
6152: strcpy (DirectoryName, tempfile);
6153: DocumentName[0] = EOS;
6154: }
6155: else
6156: TtaExtractName (tempfile, DirectoryName, DocumentName);
6157: }
6158: else
6159: {
6160: /* save the URL name */
6161: strcpy (LastURLName, tempfile);
6162: DocumentName[0] = EOS;
6163: }
6164: }
1.810 vatton 6165: if (updated)
1.1134 gully 6166: TtaFreeMemory (ptr);
1.756 vatton 6167: break;
1.485 cvs 6168:
1.756 vatton 6169: case DirSelect:
1.916 cvs 6170: #ifdef _WINGUI
1.756 vatton 6171: sprintf (DirectoryName, "%s", data);
1.950 vatton 6172: #endif /* _WINGUI */
1.979 gully 6173: #if defined(_GTK) || defined(_WX)
1.756 vatton 6174: if (DirectoryName[0] != EOS)
1.1134 gully 6175: {
6176: if (!strcmp (data, ".."))
6177: {
6178: /* suppress last directory */
6179: strcpy (tempname, DirectoryName);
6180: TtaExtractName (tempname, DirectoryName, tempfile);
6181: }
6182: else
6183: {
6184: strcat (DirectoryName, DIR_STR);
6185: strcat (DirectoryName, data);
6186: }
6187: TtaSetTextForm (BaseDialog + URLName, DirectoryName);
6188: TtaListDirectory (DirectoryName, BaseDialog + OpenForm,
6189: TtaGetMessage (LIB, TMSG_DOC_DIR),
6190: BaseDialog + DirSelect, ScanFilter,
6191: TtaGetMessage (AMAYA, AM_FILES),
6192: BaseDialog + DocSelect);
6193: DocumentName[0] = EOS;
6194: }
1.979 gully 6195: #endif /* defined(_GTK) || defined(_WX) */
1.756 vatton 6196: break;
1.950 vatton 6197:
1.756 vatton 6198: case DocSelect:
6199: if (DirectoryName[0] == EOS)
1.1134 gully 6200: /* set path on current directory */
6201: getcwd (DirectoryName, MAX_LENGTH);
1.756 vatton 6202: /* Extract suffix from document name */
6203: strcpy (DocumentName, data);
6204: LastURLName[0] = EOS;
6205: /* construct the document full name */
6206: strcpy (tempfile, DirectoryName);
6207: strcat (tempfile, DIR_STR);
6208: strcat (tempfile, DocumentName);
1.979 gully 6209: #if defined(_GTK) || defined(_WX)
1.756 vatton 6210: TtaSetTextForm (BaseDialog + URLName, tempfile);
1.979 gully 6211: #endif /* defined(_GTK) || defined(_WX) */
1.756 vatton 6212: break;
1.950 vatton 6213:
1.756 vatton 6214: case ConfirmForm:
6215: /* *********Confirm********* */
6216: UserAnswer = (val == 1);
1.947 vatton 6217: ExtraChoice = (val == 2);
1.756 vatton 6218: TtaDestroyDialogue (BaseDialog + ConfirmForm);
6219: break;
1.950 vatton 6220:
1.756 vatton 6221: case FilterText:
6222: /* Filter value */
6223: if (strlen (data) <= NAME_LENGTH)
1.1134 gully 6224: strcpy (ScanFilter, data);
1.979 gully 6225: #if defined(_GTK) || defined(_WX)
1.756 vatton 6226: else
1.1134 gully 6227: TtaSetTextForm (BaseDialog + FilterText, ScanFilter);
1.979 gully 6228: #endif /* defined(_GTK) || defined(_WX) */
1.756 vatton 6229: break;
1.950 vatton 6230:
1.756 vatton 6231: case FormAnswer:
6232: /* *********Get an answer********* */
6233: if (val == 0)
1.1134 gully 6234: {
6235: /* no answer */
6236: Answer_text[0] = EOS;
6237: Answer_name[0] = EOS;
6238: Answer_password[0] = EOS;
6239: UserAnswer = 0;
6240: }
1.756 vatton 6241: else
1.1134 gully 6242: UserAnswer = 1;
1.756 vatton 6243: TtaDestroyDialogue (BaseDialog + FormAnswer);
6244: break;
1.950 vatton 6245:
1.756 vatton 6246: case AnswerText:
6247: strncpy (Answer_text, data, MAX_LENGTH);
6248: Answer_text[MAX_LENGTH - 1] = EOS;
6249: break;
1.950 vatton 6250:
1.756 vatton 6251: case NameText:
6252: strncpy (Answer_name, data, NAME_LENGTH);
6253: Answer_text[NAME_LENGTH - 1] = EOS;
6254: break;
1.950 vatton 6255:
1.756 vatton 6256: case PasswordText:
1.1130 cvs 6257: #ifdef _WX
1.756 vatton 6258: i = strlen (data);
6259: if (i < NAME_LENGTH - 1)
1.1134 gully 6260: {
6261: Lg_password = 0;
6262: while (Lg_password < i)
6263: {
6264: /* a new char */
6265: Answer_password[Lg_password] = data[Lg_password];
6266: Display_password[Lg_password] = '*';
6267: Answer_password[++Lg_password] = EOS;
6268: Display_password[Lg_password] = EOS;
6269: }
6270: }
1.756 vatton 6271: else
1.1134 gully 6272: Answer_password[NAME_LENGTH - 1] = EOS;
1.1130 cvs 6273: #endif /* _WX */
1.891 gully 6274: #ifdef _GTK
1.756 vatton 6275: strncpy (Answer_password, data, NAME_LENGTH);
6276: Answer_password[NAME_LENGTH - 1] = EOS;
1.659 vatton 6277: #endif /* _GTK */
1.756 vatton 6278: break;
6279:
1.1134 gully 6280: /* *********Save document as********* */
1.756 vatton 6281: case RadioSave:
6282: /* Output format */
6283: switch (val)
1.1134 gully 6284: {
6285: case 0: /* "Save as HTML" button */
6286: SaveAsHTML = TRUE;
6287: SaveAsXML = FALSE;
6288: SaveAsText = FALSE;
6289: UpdateSaveAsButtons ();
6290: SetFileSuffix ();
6291: break;
6292: case 1: /* "Save as XML" button */
6293: SaveAsXML = TRUE;
6294: SaveAsHTML = FALSE;
6295: SaveAsText = FALSE;
6296: UpdateSaveAsButtons ();
6297: SetFileSuffix ();
6298: /* Set the document charset */
6299: if (TtaGetDocumentCharset (SavingDocument) == UNDEFINED_CHARSET)
6300: TtaSetDocumentCharset (SavingDocument, ISO_8859_1, FALSE);
6301: break;
6302: case 2: /* "Save as Text" button */
6303: SaveAsText = TRUE;
6304: SaveAsHTML = FALSE;
6305: SaveAsXML = FALSE;
1.1015 cvs 6306: #if defined(_GTK)
1.1134 gully 6307: TtaSetToggleMenu (BaseDialog + ToggleSave, 1, SaveAsXML);
6308: TtaSetToggleMenu (BaseDialog + ToggleSave, 0, SaveAsHTML);
6309: UpdateSaveAsButtons ();
1.1015 cvs 6310: #endif /* defined(_GTK) */
1.891 gully 6311:
1.1134 gully 6312: SetFileSuffix ();
6313: break;
6314: }
1.756 vatton 6315: break;
1.950 vatton 6316:
1.756 vatton 6317: case ToggleSave:
6318: switch (val)
1.1134 gully 6319: {
6320: case 0: /* "Copy Images" button */
6321: CopyImages = !CopyImages;
6322: break;
6323: case 1: /* "Transform URLs" button */
6324: UpdateURLs = !UpdateURLs;
6325: break;
6326: }
1.756 vatton 6327: break;
6328: case SaveForm:
6329: if (val == 1)
1.1134 gully 6330: /* "Confirm" Button */
6331: {
6332: /* protect against saving without a MIME type */
6333: if (SavingDocument != 0)
6334: {
6335: if (DocumentTypes[SavingDocument] == docHTML &&
6336: DocumentMeta[SavingDocument])
6337: {
6338: if (DocumentMeta[SavingDocument]->xmlformat && SaveAsHTML)
6339: /* XHTML -> HTML */
6340: ChangeDoctype (FALSE);
6341: if (!DocumentMeta[SavingDocument]->xmlformat && SaveAsXML)
6342: /* HTML -> XHTML */
6343: ChangeDoctype (TRUE);
6344: }
1.840 cvs 6345:
1.1134 gully 6346: if ((!DocumentMeta[SavingDocument]
6347: || !DocumentMeta[SavingDocument]->content_type
6348: || DocumentMeta[SavingDocument]->content_type[0] == EOS)
6349: && (UserMimeType[0] == EOS))
6350: {
1.891 gully 6351:
1.979 gully 6352: #if defined(_GTK) || defined(_WX)
1.1134 gully 6353: TtaNewLabel (BaseDialog + SaveFormStatus,
6354: BaseDialog + SaveForm,
6355: TtaGetMessage (AMAYA, AM_INVALID_MIMETYPE));
1.979 gully 6356: #endif /* defined(_GTK) || defined(_WX) */
1.916 cvs 6357: #ifdef _WINGUI
1.1134 gully 6358: SaveAsDlgStatus (TtaGetMessage (AMAYA, AM_INVALID_MIMETYPE));
1.916 cvs 6359: #endif /* _WINGUI */
1.1134 gully 6360: break;
6361: }
6362: }
6363: TtaDestroyDialogue (BaseDialog + SaveForm);
1.1187 vatton 6364: if (SavingDocument)
1.1134 gully 6365: DoSaveAs (UserCharset, UserMimeType);
1.1187 vatton 6366: else if (SavingObject)
6367: {
6368: DoSaveObjectAs ();
6369: // make sure the saving is closed
6370: SavingObject = 0;
6371: }
1.1134 gully 6372: /* Move the information into LastURLName or DirectoryName */
6373: if (IsW3Path (SavePath))
6374: {
6375: strcpy (LastURLName, SavePath);
6376: strcat (LastURLName, "/");
6377: strcat (LastURLName, SaveName);
6378: DirectoryName[0] = EOS;
6379: }
6380: else
6381: {
6382: LastURLName[0] = EOS;
6383: strcpy (DirectoryName, SavePath);
6384: strcat (DocumentName, SaveName);
6385: }
6386: }
1.756 vatton 6387: else if (val == 2)
1.1134 gully 6388: /* "Browse" button */
6389: {
1.979 gully 6390: #if defined(_GTK) || defined(_WX)
1.1134 gully 6391: WidgetParent = DocSaveBrowser;
6392: strcpy (LastURLName, SavePath);
6393: strcat (LastURLName, DIR_STR);
6394: strcat (LastURLName, SaveName);
6395: BrowserForm (SavingDocument, 1, LastURLName);
1.979 gully 6396: #endif /* defined(_GTK) || defined(_WX) */
1.1134 gully 6397: }
1.756 vatton 6398: else if (val == 3)
1.1134 gully 6399: /* "Clear" button */
6400: {
6401: if (SavingDocument != 0)
6402: {
6403: SavePath[0] = EOS;
6404: SaveImgsURL[0] = EOS;
6405: SaveName[0] = EOS;
1.1015 cvs 6406: #if defined(_GTK)
1.1134 gully 6407: TtaSetTextForm (BaseDialog + NameSave, SaveImgsURL);
6408: TtaSetTextForm (BaseDialog + ImgDirSave, SaveImgsURL);
1.1015 cvs 6409: #endif /* defined(_GTK) */
1.1134 gully 6410: }
6411: }
1.756 vatton 6412: else if (val == 4)
1.1134 gully 6413: /* "Charset" button */
6414: {
6415: if (SavingDocument != 0)
6416: {
6417: if (DocumentTypes[SavingDocument] != docImage)
6418: {
6419: /* clear the status message */
1.1015 cvs 6420: #if defined(_GTK)
1.1134 gully 6421: TtaNewLabel (BaseDialog + SaveFormStatus,
6422: BaseDialog + SaveForm, " ");
1.1015 cvs 6423: #endif /* defined(_GTK) */
1.916 cvs 6424: #ifdef _WINGUI
1.1134 gully 6425: SaveAsDlgStatus ("");
1.916 cvs 6426: #endif /* _WINGUI */
1.1134 gully 6427: InitCharset (SavingDocument, 1, SavePath);
6428: if (SaveFormTmp[0] != EOS)
6429: {
6430: strcpy (UserCharset, SaveFormTmp);
1.1015 cvs 6431: #if defined(_GTK)
1.1134 gully 6432: TtaNewLabel (BaseDialog + CharsetSave,
6433: BaseDialog + SaveForm, UserCharset);
1.1015 cvs 6434: #endif /* #if defined(_GTK) */
1.1134 gully 6435: }
6436: }
6437: else
6438: {
1.979 gully 6439: #if defined(_GTK) || defined(_WX)
1.1134 gully 6440: TtaNewLabel (BaseDialog + SaveFormStatus,
6441: BaseDialog + SaveForm,
6442: TtaGetMessage (AMAYA, AM_NOCHARSET_SUPPORT));
1.979 gully 6443: #endif /* #if defined(_GTK) || defined(_WX) */
1.916 cvs 6444: #ifdef _WINGUI
1.1134 gully 6445: SaveAsDlgStatus (TtaGetMessage (AMAYA, AM_NOCHARSET_SUPPORT));
1.916 cvs 6446: #endif /* _WINGUI */
1.1134 gully 6447: }
6448: }
6449: }
1.756 vatton 6450: else if (val == 5)
1.1134 gully 6451: /* "MIME type" button */
6452: {
6453: if (SavingDocument != 0)
6454: {
6455: if (SavePath[0])
6456: {
6457: /* clear the status message */
1.891 gully 6458:
1.979 gully 6459: #if defined(_GTK) || defined(_WX)
1.1134 gully 6460: TtaNewLabel (BaseDialog + SaveFormStatus,
6461: BaseDialog + SaveForm,
6462: " ");
1.979 gully 6463: #endif /* #if defined(_GTK) || defined(_WX) */
1.916 cvs 6464: #ifdef _WINGUI
1.1134 gully 6465: SaveAsDlgStatus ("");
1.916 cvs 6466: #endif /* _WINGUI */
1.1134 gully 6467: InitMimeType (SavingDocument, 1, SavePath, NULL);
6468: if (SaveFormTmp[0] != EOS)
6469: {
6470: strcpy (UserMimeType, SaveFormTmp);
1.979 gully 6471: #if defined(_GTK) || defined(_WX)
1.1134 gully 6472: TtaNewLabel (BaseDialog + MimeTypeSave,
6473: BaseDialog + SaveForm, UserMimeType);
1.979 gully 6474: #endif /* #if defined(_GTK) || defined(_WX) */
1.1134 gully 6475: }
6476: }
6477: else
6478: {
1.979 gully 6479: #if defined(_GTK) || defined(_WX)
1.1134 gully 6480: TtaNewLabel (BaseDialog + SaveFormStatus,
6481: BaseDialog + SaveForm,
6482: TtaGetMessage (AMAYA, AM_NOMIMETYPE_SUPPORT));
1.979 gully 6483: #endif /* #if defined(_GTK) || defined(_WX) */
1.916 cvs 6484: #ifdef _WINGUI
1.1134 gully 6485: SaveAsDlgStatus (TtaGetMessage (AMAYA, AM_NOMIMETYPE_SUPPORT));
1.916 cvs 6486: #endif /* _WINGUI */
1.1134 gully 6487: }
6488: }
6489: }
1.756 vatton 6490: else
1.1134 gully 6491: /* "Cancel" button */
6492: {
6493: TtaDestroyDialogue (BaseDialog + SaveForm);
1.1187 vatton 6494: if (SavingObject)
1.1134 gully 6495: /* delete temporary file */
6496: DeleteTempObjectFile ();
6497: SavingDocument = 0;
6498: SavingObject = 0;
6499: }
1.756 vatton 6500: break;
1.950 vatton 6501:
1.756 vatton 6502: case NameSave:
6503: /* Document location */
6504: if (!IsW3Path (data))
1.1134 gully 6505: change = NormalizeFile (data, tempfile, AM_CONV_NONE);
1.756 vatton 6506: else
1.1134 gully 6507: strcpy (tempfile, data);
1.756 vatton 6508:
6509: if (*tempfile && tempfile[strlen (tempfile) - 1] == sep)
1.1134 gully 6510: {
6511: strcpy (SavePath, tempfile);
6512: SaveName[0] = EOS;
6513: }
1.756 vatton 6514: else
1.1134 gully 6515: {
6516: /* Extract document name */
6517: if (SavingDocument != 0)
6518: TtaExtractName (tempfile, SavePath, SaveName);
6519: else
6520: TtaExtractName (tempfile, SavePath, ObjectName);
6521: }
1.756 vatton 6522: break;
1.950 vatton 6523:
1.756 vatton 6524: case ImgDirSave:
6525: /* Image directory */
6526: if (!IsW3Path (data))
1.1134 gully 6527: change = NormalizeFile (data, SaveImgsURL, AM_CONV_NONE);
1.756 vatton 6528: else
1.1134 gully 6529: strcpy (SaveImgsURL, data);
1.756 vatton 6530: break;
1.950 vatton 6531:
1.756 vatton 6532: case ConfirmSave:
6533: /* *********SaveConfirm********* */
6534: UserAnswer = (val == 1);
6535: TtaDestroyDialogue (BaseDialog + ConfirmSave);
6536: if (!UserAnswer)
1.1134 gully 6537: {
6538: SavingDocument = 0;
6539: SavingObject = 0;
6540: }
1.756 vatton 6541: break;
1.84 cvs 6542:
1.756 vatton 6543: case AttrHREFForm:
6544: /* *********HREF Attribute*********** */
6545: if (val == 1)
1.1134 gully 6546: {
6547: /* Confirm button */
6548: if (AttrHREFvalue[0] != EOS)
6549: /* create an attribute HREF for the Link_Anchor */
6550: SetREFattribute (AttrHREFelement, AttrHREFdocument,
6551: AttrHREFvalue, NULL);
6552: TtaDestroyDialogue (BaseDialog + AttrHREFForm);
6553: TtaDestroyDialogue (BaseDialog + FileBrowserForm);
6554: }
1.756 vatton 6555: else if (val == 2)
1.1134 gully 6556: /* Browse button */
6557: {
1.979 gully 6558: #if defined(_GTK) || defined(_WX)
1.1134 gully 6559: if (LinkAsXmlCSS || LinkAsCSS)
6560: strcpy (ScanFilter, "*.css");
6561: else if (!strcmp (ScanFilter, "*.css"))
6562: strcpy (ScanFilter, "*");
6563: WidgetParent = HrefAttrBrowser;
6564: BrowserForm (AttrHREFdocument, 1, &AttrHREFvalue[0]);
1.979 gully 6565: #endif /* #if defined(_GTK) || defined(_WX) */
1.1134 gully 6566: }
1.756 vatton 6567: else if (val == 3)
1.1134 gully 6568: /* allow one to click the target */
6569: SelectDestination (AttrHREFdocument, AttrHREFelement, AttrHREFundoable, TRUE);
1.852 vatton 6570: else if (val == 4)
1.1134 gully 6571: {
6572: /* Clear button */
6573: AttrHREFvalue[0] = EOS;
1.979 gully 6574: #if defined(_GTK) || defined(_WX)
1.1134 gully 6575: TtaSetTextForm (BaseDialog + AttrHREFText, AttrHREFvalue);
1.979 gully 6576: #endif /* #if defined(_GTK) || defined(_WX) */
1.1134 gully 6577: }
1.756 vatton 6578: else
1.1134 gully 6579: /* Cancel button */
6580: if (IsNewAnchor)
6581: {
6582: LinkAsCSS = FALSE;
6583: LinkAsXmlCSS = FALSE;
6584: /* remove the link if it was just created */
1.1172 vatton 6585: //TtaCancelLastRegisteredSequence (AttrHREFdocument);
6586: DoDeleteAnchor (AttrHREFdocument, 1, FALSE);
1.1134 gully 6587: TtaCancelLastRegisteredSequence (AttrHREFdocument);
6588: }
1.756 vatton 6589: break;
1.212 cvs 6590:
1.756 vatton 6591: case AttrHREFText:
6592: /* save the HREF name */
1.758 vatton 6593: RemoveNewLines (data);
6594: if (IsW3Path (data))
1.1134 gully 6595: {
6596: /* save the URL name */
6597: strcpy (AttrHREFvalue, data);
6598: DocumentName[0] = EOS;
6599: }
1.756 vatton 6600: else
1.1134 gully 6601: {
6602: change = NormalizeFile (data, tempfile, AM_CONV_NONE);
6603: if (TtaCheckDirectory (tempfile))
6604: {
6605: strcpy (DirectoryName, tempfile);
6606: DocumentName[0] = EOS;
6607: }
6608: else
6609: TtaExtractName (tempfile, DirectoryName, DocumentName);
6610: strcpy (AttrHREFvalue, tempfile);
6611: }
1.756 vatton 6612: break;
6613:
6614: /* *********File Browser*********** */
6615: case FileBrowserForm:
6616: if (val == 1)
1.1134 gully 6617: {
6618: /* Confirm button */
6619: /* it's no longer the default Welcome page */
6620: WelcomePage = FALSE;
1.979 gully 6621: #if defined(_GTK) || defined(_WX)
1.1134 gully 6622: /* this code is only valid under Unix. */
6623: /* In Windows, we're using a system widget */
6624: strcpy (tempfile, DirectoryName);
6625: strcat (tempfile, DIR_STR);
6626: strcat (tempfile, DocumentName);
6627: if (WidgetParent == HrefAttrBrowser)
6628: {
6629: TtaSetTextForm (BaseDialog + AttrHREFText, tempfile);
6630: strcpy (AttrHREFvalue, tempfile);
6631: CallbackDialogue (BaseDialog + AttrHREFForm, INTEGER_DATA, (char *) 1);
6632: }
6633: else if (WidgetParent == OpenDocBrowser)
6634: {
6635: TtaSetTextForm (BaseDialog + URLName, tempfile);
6636: CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
6637: }
6638: else if (WidgetParent == DocSaveBrowser)
6639: {
6640: TtaSetTextForm (BaseDialog + NameSave, tempfile);
6641: CallbackDialogue (BaseDialog + NameSave, STRING_DATA, tempfile);
6642: }
6643: /* remove the browsing dialogue */
6644: TtaDestroyDialogue (ref);
1.979 gully 6645: #endif /* defined(_GTK) || defined(_WX) */
1.1134 gully 6646: }
1.756 vatton 6647: else if (val == 2)
1.1134 gully 6648: /* Clear button */
6649: {
6650: if (WidgetParent == OpenDocBrowser)
6651: {
6652: LastURLName[0] = EOS;
1.979 gully 6653: #if defined(_GTK) || defined(_WX)
1.1134 gully 6654: TtaSetTextForm (BaseDialog + FileBrowserText, LastURLName);
1.979 gully 6655: #endif /* #if defined(_GTK) || defined(_WX) */
1.891 gully 6656:
1.1134 gully 6657: }
6658: else if (WidgetParent == HrefAttrBrowser)
6659: {
6660: tempname[0] = EOS;
1.979 gully 6661: #if defined(_GTK) || defined(_WX)
1.1134 gully 6662: TtaSetTextForm (BaseDialog + FileBrowserText, tempname);
1.979 gully 6663: #endif /* #if defined(_GTK) || defined(_WX) */
1.1134 gully 6664: }
6665: }
1.756 vatton 6666: else if (val == 3)
1.1134 gully 6667: /* Filter button */
6668: {
6669: /* reinitialize directories and document lists */
6670: TtaListDirectory (DirectoryName, BaseDialog + FileBrowserForm,
6671: TtaGetMessage (LIB, TMSG_DOC_DIR),
6672: BaseDialog + BrowserDirSelect,
6673: ScanFilter, TtaGetMessage (AMAYA, AM_FILES),
6674: BaseDialog + BrowserDocSelect);
6675: }
1.756 vatton 6676: break;
6677:
6678: case FileBrowserText:
6679: RemoveNewLines (data);
6680: if (IsW3Path (data))
1.1134 gully 6681: {
6682: DocumentName[0] = EOS;
6683: }
1.756 vatton 6684: else
1.1134 gully 6685: {
6686: change = NormalizeFile (data, tempfile, AM_CONV_NONE);
6687: if (TtaCheckDirectory (tempfile))
6688: {
6689: strcpy (DirectoryName, tempfile);
6690: DocumentName[0] = EOS;
6691: }
6692: else
6693: TtaExtractName (tempfile, DirectoryName, DocumentName);
6694: strcpy (AttrHREFvalue, tempfile);
6695: }
1.756 vatton 6696: break;
6697:
6698: /* *********Browser DirSelect*********** */
6699: case BrowserDirSelect:
1.916 cvs 6700: #ifdef _WINGUI
1.756 vatton 6701: sprintf (DirectoryName, "%s", data);
1.916 cvs 6702: #endif /* _WINGUI */
1.979 gully 6703: #if defined(_GTK) || defined(_WX)
1.756 vatton 6704: if (DirectoryName[0] != EOS)
1.1134 gully 6705: {
6706: if (!strcmp (data, ".."))
6707: {
6708: /* suppress last directory */
6709: strcpy (tempname, DirectoryName);
6710: TtaExtractName (tempname, DirectoryName, tempfile);
6711: if (DirectoryName[0] == EOS)
6712: strcpy (DirectoryName, DIR_STR);
6713: }
6714: else
6715: {
6716: strcat (DirectoryName, DIR_STR);
6717: strcat (DirectoryName, data);
6718: }
1.756 vatton 6719:
1.1134 gully 6720: if (WidgetParent == OpenDocBrowser)
6721: LastURLName[0] = EOS;
1.756 vatton 6722:
1.1134 gully 6723: TtaSetTextForm (BaseDialog + FileBrowserText, DirectoryName);
6724: TtaListDirectory (DirectoryName, BaseDialog + FileBrowserForm,
6725: TtaGetMessage (LIB, TMSG_DOC_DIR),
6726: BaseDialog + BrowserDirSelect, ScanFilter,
6727: TtaGetMessage (AMAYA, AM_FILES),
6728: BaseDialog + BrowserDocSelect);
6729: DocumentName[0] = EOS;
6730: }
1.979 gully 6731: #endif /* #if defined(_GTK) || defined(_WX) */
1.756 vatton 6732: break;
6733:
6734: /* *********Browser DocSelect*********** */
6735: case BrowserDocSelect:
6736: /* set path on current directory */
6737: if (DirectoryName[0] == EOS)
1.1134 gully 6738: getcwd (DirectoryName, MAX_LENGTH);
1.756 vatton 6739: /* Extract suffix from document name */
6740: strcpy (DocumentName, data);
6741: if (WidgetParent == OpenDocBrowser)
1.1134 gully 6742: LastURLName[0] = EOS;
1.756 vatton 6743: /* construct the document full name */
6744: strcpy (tempfile, DirectoryName);
6745: strcat (tempfile, DIR_STR);
6746: strcat (tempfile, DocumentName);
1.979 gully 6747: #if defined(_GTK) || defined(_WX)
1.756 vatton 6748: TtaSetTextForm (BaseDialog + FileBrowserText, tempfile);
1.979 gully 6749: #endif /* #if defined(_GTK) || defined(_WX) */
1.756 vatton 6750: break;
6751:
6752: /* *********Browser Filter*********** */
6753: case FileBrowserFilter:
6754: /* Filter value */
6755: if (strlen(data) <= NAME_LENGTH)
1.1134 gully 6756: strcpy (ScanFilter, data);
1.979 gully 6757: #if defined(_GTK) || defined(_WX)
1.756 vatton 6758: else
1.1134 gully 6759: TtaSetTextForm (BaseDialog + BrowserFilterText, ScanFilter);
1.979 gully 6760: #endif /* #if defined(_GTK) || defined(_WX) */
1.756 vatton 6761: break;
6762:
6763: case TitleForm:
6764: /* ********Change the document title*********** */
6765: TtaDestroyDialogue (BaseDialog + TitleForm);
6766: if (val == 1)
1.1134 gully 6767: SetNewTitle (CurrentDocument);
1.756 vatton 6768: break;
6769:
6770: case TitleText:
6771: /* new document name */
6772: strncpy (Answer_text, data, MAX_LENGTH);
6773: Answer_text[MAX_LENGTH - 1] = EOS;
6774: break;
6775:
6776: case ClassForm:
6777: case ClassSelect:
6778: case AClassForm:
6779: case AClassSelect:
6780: StyleCallbackDialogue (ref, typedata, data);
6781: break;
6782:
6783: case TableForm:
6784: /* *********Table Form*********** */
6785: UserAnswer = (val == 1);
6786: TtaDestroyDialogue (BaseDialog + TableForm);
6787: break;
6788: case TableRows:
6789: NumberRows = val;
6790: break;
6791: case TableCols:
6792: NumberCols = val;
6793: break;
6794: case TableBorder:
6795: TBorder = val;
6796: break;
6797: case MathEntityForm:
6798: /* ********* MathML entity form ********* */
6799: if (val == 0)
1.1134 gully 6800: /* no answer */
6801: MathMLEntityName[0] = EOS;
1.1047 vatton 6802: TtaDestroyDialogue (ref);
1.756 vatton 6803: break;
6804: case MathEntityText:
6805: strncpy (MathMLEntityName, data, MAX_LENGTH);
6806: MathMLEntityName[MAX_LENGTH - 1] = EOS;
6807: break;
6808: case MakeIdMenu:
6809: switch (val)
1.1134 gully 6810: {
6811: case 1:
6812: CreateRemoveIDAttribute (IdElemName, IdDoc, TRUE, IdApplyToSelection);
1.979 gully 6813: #if defined(_GTK) || defined(_WX)
1.1134 gully 6814: /* and show the status */
6815: TtaNewLabel (BaseDialog + mIdStatus,
6816: BaseDialog + MakeIdMenu,
6817: IdStatus);
1.979 gully 6818: #endif /* #if defined(_GTK) || defined(_WX) */
1.1134 gully 6819: break;
6820: case 2:
6821: CreateRemoveIDAttribute (IdElemName, IdDoc, FALSE, IdApplyToSelection);
1.979 gully 6822: #if defined(_GTK) || defined(_WX)
1.1134 gully 6823: /* and show the status */
6824: TtaNewLabel (BaseDialog + mIdStatus,
6825: BaseDialog + MakeIdMenu,
6826: IdStatus);
1.979 gully 6827: #endif /* #if defined(_GTK) || defined(_WX) */
1.1134 gully 6828: break;
6829: }
1.756 vatton 6830: break;
6831: case mElemName:
6832: strncpy (IdElemName, data, MAX_LENGTH);
6833: IdElemName[MAX_LENGTH - 1] = EOS;
6834: break;
6835: case mIdUseSelection:
1.1117 gully 6836: IdApplyToSelection = (val != 0);
1.756 vatton 6837: break;
6838: /* Charset Save As menu */
6839: case CharsetForm:
6840: {
1.1134 gully 6841: switch (val)
6842: {
6843: case 0:
6844: SaveFormTmp[0] = EOS;
6845: TtaDestroyDialogue (ref);
6846: break;
6847: case 1:
6848: TtaDestroyDialogue (ref);
6849: break;
6850: }
1.756 vatton 6851: }
6852: break;
6853: case CharsetSel:
6854: switch (val)
1.1134 gully 6855: {
6856: case 0:
6857: strcpy (SaveFormTmp, "us-ascii");
6858: break;
6859: case 1:
6860: strcpy (SaveFormTmp, "UTF-8");
6861: break;
6862: case 2:
6863: strcpy (SaveFormTmp, "iso-8859-1");
6864: break;
6865: case 3:
6866: strcpy (SaveFormTmp, "iso-8859-2");
6867: break;
6868: }
1.756 vatton 6869: break;
1.618 kahan 6870:
1.756 vatton 6871: /* MIME type Save As menu */
6872: case MimeTypeForm:
6873: {
1.1134 gully 6874: switch (val)
6875: {
6876: case 0:
6877: SaveFormTmp[0] = EOS;
6878: TtaDestroyDialogue (ref);
6879: break;
6880: case 1:
6881: {
6882: char *src, *dst;
6883: /* filter the UserMimeType */
6884: src = dst = SaveFormTmp;
6885: while (*src)
6886: {
6887: if (!isascii (*src)
6888: || (!isalnum (*src) && *src != '/' && *src != '-'
6889: && *src != '+'))
6890: {
6891: /* skip the character */
6892: src++;
6893: continue;;
6894: }
1.756 vatton 6895:
1.1134 gully 6896: if (isupper (*src))
6897: /* convert to lower case */
6898: *dst = tolower (*src);
6899: else
6900: *dst = *src;
6901: src++;
6902: dst++;
6903: }
6904: *dst = EOS;
6905: /* validate the mime type */
6906: if (SaveFormTmp[0] == EOS ||!strchr (SaveFormTmp, '/'))
6907: {
6908: SaveFormTmp[0] = EOS;
1.1021 cvs 6909: #if defined(_GTK)
1.1134 gully 6910: InitMimeType (SavingDocument, 1, SavePath,
6911: TtaGetMessage (AMAYA, AM_INVALID_MIMETYPE));
1.1021 cvs 6912: #endif /* _GTK */
1.916 cvs 6913: #ifdef _WINGUI
1.1134 gully 6914: /* the Window dialog won't be closed */
6915: MimeTypeDlgStatus (TtaGetMessage (AMAYA, AM_INVALID_MIMETYPE));
1.916 cvs 6916: #endif /* _WINGUI */
1.1134 gully 6917: }
6918: else
6919: TtaDestroyDialogue (ref);
6920: }
6921: break;
6922: }
1.756 vatton 6923: }
6924: break;
6925: case MimeTypeSel:
6926: if (data)
1.1134 gully 6927: strcpy (SaveFormTmp, data);
1.756 vatton 6928: else
1.1134 gully 6929: SaveFormTmp[0] = EOS;
1.756 vatton 6930: break;
6931: }
1.6 cvs 6932: }
1.18 cvs 6933:
1.9 cvs 6934: /*----------------------------------------------------------------------
1.924 vatton 6935: RestoreOneAmayaDoc restores a saved file doc is the suggested doc to
6936: be loaded or 0.
1.230 cvs 6937: docname is the original name of the document.
6938: tempdoc is the name of the saved file.
1.233 cvs 6939: Return the new recovered document
1.924 vatton 6940: URIs are encoded with the default charset.
1.230 cvs 6941: ----------------------------------------------------------------------*/
1.588 cvs 6942: static int RestoreOneAmayaDoc (Document doc, char *tempdoc, char *docname,
1.1136 gully 6943: DocumentType docType, ThotBool iscrash)
1.333 cvs 6944: {
1.873 cvs 6945: AHTHeaders http_headers;
6946: char content_type[MAX_LENGTH];
1.1128 tollenae 6947: char tempfile[MAX_LENGTH];
1.1185 vatton 6948: int newdoc;
1.873 cvs 6949: ThotBool stopped_flag;
1.333 cvs 6950:
6951: W3Loading = doc;
6952: BackupDocument = doc;
6953: TtaExtractName (tempdoc, DirectoryName, DocumentName);
1.873 cvs 6954: AddURLInCombobox (docname, NULL, TRUE);
1.926 gully 6955: newdoc = InitDocAndView (doc,
1.927 vatton 6956: FALSE /* replaceOldDoc */,
6957: TRUE /* inNewWindow */,
6958: DocumentName, (DocumentType)docType, 0, FALSE,
1.1190 vatton 6959: L_Other, CE_ABSOLUTE);
1.1136 gully 6960: if (newdoc != 0)
1.333 cvs 6961: {
6962: /* load the saved file */
6963: W3Loading = newdoc;
6964: if (IsW3Path (docname))
1.1136 gully 6965: {
6966: /* it's a remote file */
1.603 kahan 6967:
1.1136 gully 6968: /* clear the headers */
6969: memset ((void *) &http_headers, 0, sizeof (AHTHeaders));
6970: if (docType == docHTML)
6971: {
6972: strcpy (content_type, "text/html");
6973: http_headers.content_type = content_type;
6974: }
6975: else
6976: http_headers.content_type = NULL;
6977: LoadDocument (newdoc, docname, NULL, NULL, CE_ABSOLUTE,
1.1185 vatton 6978: tempdoc, DocumentName, &http_headers, FALSE,
6979: &DontReplaceOldDoc, docname);
1.1136 gully 6980: }
6981: else
6982: {
6983: /* it's a local file */
6984: tempfile[0] = EOS;
6985: /* load the temporary file */
6986: LoadDocument (newdoc, tempdoc, NULL, NULL, CE_ABSOLUTE,
1.1185 vatton 6987: tempfile, DocumentName, NULL, FALSE,
6988: &DontReplaceOldDoc, docname);
1.1136 gully 6989: /* change its URL */
6990: TtaFreeMemory (DocumentURLs[newdoc]);
6991: DocumentURLs[newdoc] = TtaStrdup (docname);
6992: DocumentSource[newdoc] = 0;
6993: /* add the URI in the combobox string */
6994: AddURLInCombobox (docname, NULL, FALSE);
6995: TtaSetTextZone (newdoc, 1, URL_list);
6996: /* change its directory name */
6997: TtaSetDocumentDirectory (newdoc, DirectoryName);
6998: }
1.359 cvs 6999: TtaSetDocumentModified (newdoc);
1.333 cvs 7000: W3Loading = 0; /* loading is complete now */
7001: DocNetworkStatus[newdoc] = AMAYA_NET_ACTIVE;
1.627 cvs 7002: stopped_flag = FetchAndDisplayImages (newdoc, AMAYA_LOAD_IMAGE, NULL);
1.333 cvs 7003: if (!stopped_flag)
1.1136 gully 7004: {
1.1185 vatton 7005: ResetStop (newdoc);
1.1136 gully 7006: DocNetworkStatus[newdoc] = AMAYA_NET_INACTIVE;
7007: /* almost one file is restored */
7008: TtaSetStatus (newdoc, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED),
7009: NULL);
7010: }
1.617 cvs 7011: /* check parsing errors */
7012: CheckParsingErrors (newdoc);
1.333 cvs 7013: /* unlink this saved file */
1.890 cvs 7014: if (iscrash)
1.1136 gully 7015: TtaFileUnlink (tempdoc);
1.333 cvs 7016: }
7017: BackupDocument = 0;
7018: return (newdoc);
7019: }
7020:
7021:
1.230 cvs 7022: /*----------------------------------------------------------------------
1.890 cvs 7023: RestoreAmayaDocs
7024: Checks if Amaya has previously crashed.
7025: The file Crash.amaya gives the list of saved files.
7026: The file AutoSave.dat gives the list of auto-saved files
1.220 cvs 7027: ----------------------------------------------------------------------*/
1.678 vatton 7028: static ThotBool RestoreAmayaDocs ()
1.220 cvs 7029: {
1.890 cvs 7030: FILE *f;
7031: char tempname[MAX_LENGTH], tempdoc[MAX_LENGTH];
7032: char docname[MAX_LENGTH];
7033: char line[MAX_LENGTH * 2];
7034: int docType, i, j;
1.904 vatton 7035: ThotBool aDoc, iscrash, restore;
1.890 cvs 7036:
7037: /* no document is opened */
7038: aDoc = FALSE;
7039: iscrash = FALSE;
1.220 cvs 7040:
7041: /* check if Amaya has crashed */
1.547 cvs 7042: sprintf (tempname, "%s%cCrash.amaya", TempFileDirectory, DIR_SEP);
1.890 cvs 7043: if (TtaFileExist (tempname))
7044: iscrash = TRUE;
1.899 vatton 7045: else if (!AmayaUniqueInstance)
7046: return FALSE;
1.890 cvs 7047: else
7048: sprintf (tempname, "%s%cAutoSave.dat", TempFileDirectory, DIR_SEP);
7049:
1.276 cvs 7050: if (TtaFileExist (tempname))
7051: {
7052: InitConfirm (0, 0, TtaGetMessage (AMAYA, AM_RELOAD_FILES));
1.904 vatton 7053: restore = UserAnswer;
1.1050 vatton 7054: f = TtaReadOpen (tempname);
1.454 cvs 7055: if (f != NULL)
1.1125 gully 7056: {
7057: DontReplaceOldDoc = TRUE;
7058: i = 0;
7059: line[i] = EOS;
7060: fread (&line[i], 1, 1, f);
7061: while (line[0] == '"')
7062: {
7063: /* get the temp name */
7064: do
7065: {
7066: i++;
7067: fread (&line[i], 1, 1, f);
7068: }
7069: while (line[i] != '"');
7070: line[i] = EOS;
7071: strcpy (tempdoc, &line[1]);
7072: /* skip spaces and the next first " */
7073: do
7074: {
7075: i++;
7076: fread (&line[i], 1, 1, f);
7077: }
7078: while (line[i] != '"');
7079: /* get the origin name */
7080: j = i + 1;
7081: do
7082: {
7083: i++;
7084: fread (&line[i], 1, 1, f);
7085: }
7086: while (line[i] != '"');
7087: line[i] = EOS;
7088: strcpy (docname, &line[j]);
7089: /* skip spaces */
7090: do
7091: {
7092: i++;
7093: fread (&line[i], 1, 1, f);
7094: }
7095: while (line[i] == ' ');
7096: /* get the docType */
7097: j = i;
7098: do
7099: {
7100: i++;
7101: fread (&line[i], 1, 1, f);
7102: }
7103: while (line[i] != '\n');
7104: line[i] = EOS;
7105: sscanf (&line[j], "%d", &docType);
7106: if (tempdoc[0] != EOS && TtaFileExist (tempdoc))
7107: {
7108: if (restore)
7109: {
7110: if (RestoreOneAmayaDoc (0, tempdoc, docname,
7111: (DocumentType) docType, iscrash))
7112: aDoc = TRUE;
7113: }
7114: else
7115: /* unlink this saved file */
7116: TtaFileUnlink (tempdoc);
7117: }
7118: /* next saved file */
7119: i = 0;
7120: line[i] = EOS;
7121: fread (&line[i], 1, 1, f);
7122: }
7123: DontReplaceOldDoc = FALSE;
7124: TtaReadClose (f);
7125: }
1.901 vatton 7126:
1.890 cvs 7127: if (iscrash)
1.1125 gully 7128: {
7129: TtaFileUnlink (tempname);
7130: sprintf (tempname, "%s%cAutoSave.dat", TempFileDirectory, DIR_SEP);
7131: if (TtaFileExist (tempname))
7132: {
7133: f = TtaReadOpen (tempname);
7134: if (f != NULL)
7135: {
7136: i = 0;
7137: line[i] = EOS;
7138: fread (&line[i], 1, 1, f);
7139: while (line[0] == '"')
7140: {
7141: /* get the temp name */
7142: do
7143: {
7144: i++;
7145: fread (&line[i], 1, 1, f);
7146: }
7147: while (line[i] != '"');
7148: line[i] = EOS;
7149: strcpy (tempdoc, &line[1]);
7150: /* skip spaces and the next first " */
7151: do
7152: {
7153: i++;
7154: fread (&line[i], 1, 1, f);
7155: }
7156: while (line[i] != '"');
7157: /* get the origin name */
7158: j = i + 1;
7159: do
7160: {
7161: i++;
7162: fread (&line[i], 1, 1, f);
7163: }
7164: while (line[i] != '"');
7165: line[i] = EOS;
7166: strcpy (docname, &line[j]);
7167: /* skip spaces */
7168: do
7169: {
7170: i++;
7171: fread (&line[i], 1, 1, f);
7172: }
7173: while (line[i] == ' ');
7174: /* get the docType */
7175: j = i;
7176: do
7177: {
7178: i++;
7179: fread (&line[i], 1, 1, f);
7180: }
7181: while (line[i] != '\n');
7182: line[i] = EOS;
7183: sscanf (&line[j], "%d", &docType);
7184: if (tempdoc[0] != EOS && TtaFileExist (tempdoc))
7185: /* unlink the auto-saved file */
7186: TtaFileUnlink (tempdoc);
7187: /*next auto-saved file */
7188: i = 0;
7189: line[i] = EOS;
7190: fread (&line[i], 1, 1, f);
7191: }
7192: TtaReadClose (f);
7193: }
7194: TtaFileUnlink (tempname);
7195: }
7196: }
1.890 cvs 7197: else
1.1125 gully 7198: {
7199: if (!UserAnswer)
7200: TtaFileUnlink (tempname);
7201: }
1.454 cvs 7202: }
1.220 cvs 7203: return (aDoc);
7204: }
7205:
1.333 cvs 7206:
1.220 cvs 7207: /*----------------------------------------------------------------------
1.314 cvs 7208: CheckMakeDirectory verifies if a directory name exists. If it doesn't
7209: exist, it tries to create it. If recusive == TRUE, it tries to create
7210: all the intermediary directories.
7211: Returns TRUE if the operation succeeds, FALSE otherwise.
7212: ----------------------------------------------------------------------*/
1.547 cvs 7213: ThotBool CheckMakeDirectory (char *name, ThotBool recursive)
1.314 cvs 7214: {
1.394 cvs 7215: ThotBool i;
1.547 cvs 7216: char *tmp_name;
7217: char *ptr;
7218: char tmp_char;
1.314 cvs 7219:
7220: /* protection against bad calls */
1.547 cvs 7221: if (!name || *name == EOS)
1.314 cvs 7222: return FALSE;
7223:
7224: /* does the directory exist? */
1.1188 vatton 7225: i = TtaMakeDirectory (name);
7226: if (i)
1.314 cvs 7227: return TRUE;
1.1188 vatton 7228: else
1.314 cvs 7229: {
1.1188 vatton 7230: /* no, try to create it then */
1.314 cvs 7231: /* don't do anything else */
7232: if (!recursive)
1.1136 gully 7233: return FALSE;
1.314 cvs 7234:
7235: /* try to create all the missing directories up to name */
1.575 cvs 7236: tmp_name = TtaStrdup (name);
1.314 cvs 7237: ptr = tmp_name;
1.1191 ! vatton 7238: #ifdef _WINDOWS
! 7239: if (*ptr != EOS && ptr[1] == ':')
! 7240: ptr += 2;
! 7241: #endif /* _WINDOWS */
! 7242: if (*ptr == DIR_SEP)
! 7243: ptr++;
1.314 cvs 7244: /* create all the intermediary directories */
1.547 cvs 7245: while (*ptr != EOS)
1.1136 gully 7246: {
7247: if (*ptr != DIR_SEP)
7248: ptr++;
7249: else
7250: {
7251: tmp_char = *ptr;
7252: *ptr = EOS;
7253: i = TtaMakeDirectory (tmp_name);
7254: if (!i)
7255: {
7256: TtaFreeMemory (tmp_name);
7257: return FALSE;
7258: }
7259: *ptr = tmp_char;
7260: ptr++;
7261: }
7262: }
1.314 cvs 7263: /* create the last dir */
7264: i = TtaMakeDirectory (tmp_name);
7265: TtaFreeMemory (tmp_name);
7266: if (!i)
1.1136 gully 7267: return FALSE;
1.314 cvs 7268: }
7269: return TRUE;
7270: }
7271:
1.379 cvs 7272: /*----------------------------------------------------------------------
1.1136 gully 7273: FreeAmayaIcons cleans up icons objects.
1.946 gully 7274: ----------------------------------------------------------------------*/
7275: void FreeAmayaIcons ()
7276: {
1.1136 gully 7277: /* free allocated icons */
1.946 gully 7278: #if defined(_WX)
7279: if (stopR)
7280: delete stopR;
7281: if (stopN)
7282: delete stopN;
7283: if (iconSave)
7284: delete iconSave;
7285: if (iconSaveNo)
7286: delete iconSaveNo;
7287: if (iconFind)
7288: delete iconFind;
7289: if (iconReload)
7290: delete iconReload;
7291: if (iconHome)
7292: delete iconHome;
7293: if (iconI)
7294: delete iconI;
7295: if (iconINo)
7296: delete iconINo;
7297: if (iconB)
7298: delete iconB;
7299: if (iconBNo)
7300: delete iconBNo;
7301: if (iconT)
7302: delete iconT;
7303: if (iconTNo)
7304: delete iconTNo;
7305: if (iconBack)
7306: delete iconBack;
7307: if (iconBackNo)
7308: delete iconBackNo;
7309: if (iconForward)
7310: delete iconForward;
7311: if (iconForwardNo)
7312: delete iconForwardNo;
7313: if (iconH1)
7314: delete iconH1;
7315: if (iconH1No)
7316: delete iconH1No;
7317: if (iconH2)
7318: delete iconH2;
7319: if (iconH2No)
7320: delete iconH2No;
7321: if (iconH3)
7322: delete iconH3;
7323: if (iconH3No)
7324: delete iconH3No;
7325: if (iconPrint)
7326: delete iconPrint;
7327: if (iconBullet)
7328: delete iconBullet;
7329: if (iconBulletNo)
7330: delete iconBulletNo;
7331: if (iconNum)
7332: delete iconNum;
7333: if (iconNumNo)
7334: delete iconNumNo;
7335: if (iconImage)
7336: delete iconImage;
7337: if (iconImageNo)
7338: delete iconImageNo;
7339: if (iconDL)
7340: delete iconDL;
7341: if (iconDLNo)
7342: delete iconDLNo;
7343: if (iconLink)
7344: delete iconLink;
7345: if (iconLinkNo)
7346: delete iconLinkNo;
7347: if (iconTable)
7348: delete iconTable;
7349: if (iconTableNo)
7350: delete iconTableNo;
1.994 gully 7351: if (iconLogo)
7352: delete iconLogo;
1.946 gully 7353:
7354: stopR = (ThotIcon) 0;
7355: stopN = (ThotIcon) 0;
7356: iconSave = (ThotIcon) 0;
7357: iconSaveNo = (ThotIcon) 0;
7358: iconFind = (ThotIcon) 0;
7359: iconReload = (ThotIcon) 0;
7360: iconHome = (ThotIcon) 0;
7361: iconI = (ThotIcon) 0;
7362: iconINo = (ThotIcon) 0;
7363: iconB = (ThotIcon) 0;
7364: iconBNo = (ThotIcon) 0;
7365: iconT = (ThotIcon) 0;
7366: iconTNo = (ThotIcon) 0;
7367: iconBack = (ThotIcon) 0;
7368: iconBackNo = (ThotIcon) 0;
7369: iconForward = (ThotIcon) 0;
7370: iconForwardNo = (ThotIcon) 0;
7371: iconH1 = (ThotIcon) 0;
7372: iconH1No = (ThotIcon) 0;
7373: iconH2 = (ThotIcon) 0;
7374: iconH2No = (ThotIcon) 0;
7375: iconH3 = (ThotIcon) 0;
7376: iconH3No = (ThotIcon) 0;
7377: iconPrint = (ThotIcon) 0;
7378: iconBullet = (ThotIcon) 0;
7379: iconBulletNo = (ThotIcon) 0;
7380: iconNum = (ThotIcon) 0;
7381: iconNumNo = (ThotIcon) 0;
7382: iconImage = (ThotIcon) 0;
7383: iconImageNo = (ThotIcon) 0;
7384: iconDL = (ThotIcon) 0;
7385: iconDLNo = (ThotIcon) 0;
7386: iconLink = (ThotIcon) 0;
7387: iconLinkNo = (ThotIcon) 0;
7388: iconTable = (ThotIcon) 0;
7389: iconTableNo = (ThotIcon) 0;
1.994 gully 7390: iconLogo = (ThotIcon) 0;
1.946 gully 7391: #endif /* defined(_WX) */
7392: }
7393:
7394: /*----------------------------------------------------------------------
1.1136 gully 7395: FreeAmayaStructures cleans up memory ressources.
1.379 cvs 7396: ----------------------------------------------------------------------*/
1.678 vatton 7397: void FreeAmayaStructures ()
1.379 cvs 7398: {
7399: if (LastURLName)
7400: {
7401: /* now exit the application */
7402: TtaFreeMemory (LastURLName);
7403: LastURLName = NULL;
7404: TtaFreeMemory (DocumentName);
7405: TtaFreeMemory (DirectoryName);
7406: TtaFreeMemory (SavePath);
7407: TtaFreeMemory (SaveName);
7408: TtaFreeMemory (ObjectName);
7409: TtaFreeMemory (SaveImgsURL);
7410: TtaFreeMemory (SavingFile);
1.601 cvs 7411: TtaFreeMemory (SavedDocumentURL);
1.379 cvs 7412: TtaFreeMemory (AttrHREFvalue);
7413: TtaFreeMemory (UserCSS);
1.795 vatton 7414: TtaFreeMemory (URL_list);
1.1128 tollenae 7415: TtaFreeMemory (Template_list);
1.890 cvs 7416: TtaFreeMemory (AutoSave_list);
1.379 cvs 7417: FreeHTMLParser ();
1.447 cvs 7418: FreeXmlParserContexts ();
1.379 cvs 7419: FreeDocHistory ();
7420: FreeTransform ();
7421: QueryClose ();
1.946 gully 7422:
7423: FreeAmayaIcons ();
7424:
7425: /* free mathml allocations */
7426: FreeMathML();
7427:
7428: /* free svg allocations */
7429: FreeSVG ();
7430:
1.379 cvs 7431: #ifdef ANNOTATIONS
1.567 kahan 7432: XPointer_bufferFree ();
1.379 cvs 7433: ANNOT_Quit ();
7434: #endif /* ANNOTATIONS */
1.856 kahan 7435: #ifdef BOOKMARKS
7436: BM_Quit ();
7437: #endif /* BOOKMARKS */
1.807 kahan 7438: FreeAmayaCache ();
1.379 cvs 7439: }
7440: }
7441:
1.314 cvs 7442:
7443: /*----------------------------------------------------------------------
1.882 vatton 7444: InitAmaya intializes Amaya variables and open the first document window.
1.9 cvs 7445: ----------------------------------------------------------------------*/
1.678 vatton 7446: void InitAmaya (NotifyEvent * event)
1.6 cvs 7447: {
1.1136 gully 7448: char *s;
7449: char *ptr;
7450: int i;
7451: ThotBool restoredDoc;
7452: ThotBool map, add, bt;
1.10 cvs 7453:
1.1136 gully 7454: if (AmayaInitialized)
7455: return;
7456: AmayaInitialized = 1;
1.1149 quint 7457: ErrFile = NULL;
7458: CSSErrFile = NULL;
1.1136 gully 7459: W3Loading = 0;
7460: BackupDocument = 0;
7461: /* the first window should be open in a new window */
7462: InNewWindow = TRUE;
7463: /* initialize status */
7464: SelectionDoc = 0;
7465: ParsedDoc = 0;
7466: ParsedCSS = 0;
1.1177 vatton 7467: Error_DocURL = NULL; /* no current error */
1.1136 gully 7468: SelectionInPRE = FALSE;
7469: SelectionInComment = FALSE;
7470: SelectionInEM = FALSE;
7471: SelectionInSTRONG = FALSE;
7472: SelectionInCITE = FALSE;
7473: SelectionInABBR = FALSE;
7474: SelectionInACRONYM = FALSE;
7475: SelectionInINS = FALSE;
7476: SelectionInDEL = FALSE;
7477: SelectionInDFN = FALSE;
7478: SelectionInCODE = FALSE;
7479: SelectionInVAR = FALSE;
7480: SelectionInSAMP = FALSE;
7481: SelectionInKBD = FALSE;
7482: SelectionInI = FALSE;
7483: SelectionInB = FALSE;
7484: SelectionInTT = FALSE;
7485: SelectionInBIG = FALSE;
7486: SelectionInSMALL = FALSE;
7487: Synchronizing = FALSE;
7488: TableMenuActive = FALSE;
7489: MTableMenuActive = FALSE;
7490: IdElemName[0] = EOS;
7491: /* Initialize the LogFile variables */
7492: CleanUpParsingErrors ();
7493: /* we're not linking an external CSS */
7494: LinkAsCSS = FALSE;
7495: LinkAsXmlCSS = FALSE;
1.326 cvs 7496:
1.1136 gully 7497: /* initialize icons */
1.974 gully 7498: #ifdef _WX
1.1136 gully 7499: stopR = (ThotIcon) 0;
7500: stopN = (ThotIcon) 0;
7501: iconSave = (ThotIcon) 0;
7502: iconSaveNo = (ThotIcon) 0;
7503: iconFind = (ThotIcon) 0;
7504: iconReload = (ThotIcon) 0;
7505: iconHome = (ThotIcon) 0;
7506: iconBack = (ThotIcon) 0;
7507: iconBackNo = (ThotIcon) 0;
7508: iconForward = (ThotIcon) 0;
7509: iconForwardNo = (ThotIcon) 0;
7510: iconPrint = (ThotIcon) 0;
7511: iconI = (ThotIcon) 0;
7512: iconINo = (ThotIcon) 0;
7513: iconB = (ThotIcon) 0;
7514: iconBNo = (ThotIcon) 0;
7515: iconT = (ThotIcon) 0;
7516: iconTNo = (ThotIcon) 0;
7517: iconH1 = (ThotIcon) 0;
7518: iconH1No = (ThotIcon) 0;
7519: iconH2 = (ThotIcon) 0;
7520: iconH2No = (ThotIcon) 0;
7521: iconH3 = (ThotIcon) 0;
7522: iconH3No = (ThotIcon) 0;
7523: iconBullet = (ThotIcon) 0;
7524: iconBulletNo = (ThotIcon) 0;
7525: iconNum = (ThotIcon) 0;
7526: iconNumNo = (ThotIcon) 0;
7527: iconImage = (ThotIcon) 0;
7528: iconImageNo = (ThotIcon) 0;
7529: iconDL = (ThotIcon) 0;
7530: iconDLNo = (ThotIcon) 0;
7531: iconLink = (ThotIcon) 0;
7532: iconLinkNo = (ThotIcon) 0;
7533: iconTable = (ThotIcon) 0;
7534: iconTableNo = (ThotIcon) 0;
7535: iconLogo = (ThotIcon) 0;
1.974 gully 7536: #endif /* _WX */
1.993 vatton 7537: #ifdef _GTK
1.1136 gully 7538: stopR = (ThotIcon) TtaCreatePixmapLogo (stopR_xpm);
7539: stopN = (ThotIcon) TtaCreatePixmapLogo (stopN_xpm);
7540: iconSave = (ThotIcon) TtaCreatePixmapLogo (save_xpm);
7541: iconSaveNo = (ThotIcon) TtaCreatePixmapLogo (saveNo_xpm);
7542: iconFind = (ThotIcon) TtaCreatePixmapLogo (find_xpm);
7543: iconReload = (ThotIcon) TtaCreatePixmapLogo (Reload_xpm);
7544: iconHome = (ThotIcon) TtaCreatePixmapLogo (home_xpm);
7545: iconI = (ThotIcon) TtaCreatePixmapLogo (I_xpm);
7546: iconINo = (ThotIcon) TtaCreatePixmapLogo (INo_xpm);
7547: iconB = (ThotIcon) TtaCreatePixmapLogo (B_xpm);
7548: iconBNo = (ThotIcon) TtaCreatePixmapLogo (BNo_xpm);
7549: iconT = (ThotIcon) TtaCreatePixmapLogo (T_xpm);
7550: iconTNo = (ThotIcon) TtaCreatePixmapLogo (TNo_xpm);
7551: iconBack = (ThotIcon) TtaCreatePixmapLogo (Back_xpm);
7552: iconBackNo = (ThotIcon) TtaCreatePixmapLogo (BackNo_xpm);
7553: iconForward = (ThotIcon) TtaCreatePixmapLogo (Forward_xpm);
7554: iconForwardNo = (ThotIcon) TtaCreatePixmapLogo (ForwardNo_xpm);
7555: iconH1 = (ThotIcon) TtaCreatePixmapLogo (H1_xpm);
7556: iconH1No = (ThotIcon) TtaCreatePixmapLogo (H1No_xpm);
7557: iconH2 = (ThotIcon) TtaCreatePixmapLogo (H2_xpm);
7558: iconH2No = (ThotIcon) TtaCreatePixmapLogo (H2No_xpm);
7559: iconH3 = (ThotIcon) TtaCreatePixmapLogo (H3_xpm);
7560: iconH3No = (ThotIcon) TtaCreatePixmapLogo (H3No_xpm);
7561: iconPrint = (ThotIcon) TtaCreatePixmapLogo (Print_xpm);
7562: iconBullet = (ThotIcon) TtaCreatePixmapLogo (Bullet_xpm);
7563: iconBulletNo = (ThotIcon) TtaCreatePixmapLogo (BulletNo_xpm);
7564: iconNum = (ThotIcon) TtaCreatePixmapLogo (Num_xpm);
7565: iconNumNo = (ThotIcon) TtaCreatePixmapLogo (NumNo_xpm);
7566: iconImage = (ThotIcon) TtaCreatePixmapLogo (Image_xpm);
7567: iconImageNo = (ThotIcon) TtaCreatePixmapLogo (ImageNo_xpm);
7568: iconDL = (ThotIcon) TtaCreatePixmapLogo (DL_xpm);
7569: iconDLNo = (ThotIcon) TtaCreatePixmapLogo (DLNo_xpm);
7570: iconLink = (ThotIcon) TtaCreatePixmapLogo (Link_xpm);
7571: iconLinkNo = (ThotIcon) TtaCreatePixmapLogo (LinkNo_xpm);
7572: iconTable = (ThotIcon) TtaCreatePixmapLogo (Table_xpm);
7573: iconTableNo = (ThotIcon) TtaCreatePixmapLogo (TableNo_xpm);
1.974 gully 7574: #endif /* _GTK */
1.891 gully 7575:
1.1136 gully 7576: /* init transformation callback */
7577: TtaSetTransformCallback ((Func) TransformIntoType);
7578: TargetName = NULL;
7579: TtaSetAccessKeyFunction ((Proc) AccessKeyHandler);
1.1162 vatton 7580: TtaSetEntityFunction ((Proc4) MapEntityByCode);
1.1163 vatton 7581: TtaSetDoctypeFunction ((Proc3) HasADoctype);
1.1136 gully 7582: TtaSetCopyAndCutFunction ((Proc) RegisterURLSavedElements);
7583: TtaSetCopyCellFunction ((Proc3) CopyCell);
7584: TtaSetCopyRowFunction ((Proc3) CopyRow);
7585: TtaSetNextCellInColumnFunction ((Proc5) NextCellInColumn);
7586: /* Initialize the Amaya user and tmp directories */
7587: s = TtaGetEnvString ("APP_TMPDIR");
7588: if (!CheckMakeDirectory (s, TRUE))
7589: /* try to use the default value */
7590: {
7591: s = TtaGetDefEnvString ("APP_TMPDIR");
7592: if (CheckMakeDirectory (s, TRUE))
7593: /* make it the current user one */
7594: TtaSetEnvString ("APP_TMPDIR", s, TRUE);
7595: else
7596: /* didn't work, so we exit */
7597: {
7598: sprintf (TempFileDirectory,
7599: TtaGetMessage (AMAYA, AM_CANNOT_CREATE_DIRECTORY), s);
1.916 cvs 7600: #ifdef _WINGUI
1.1136 gully 7601: MessageBox (NULL, TempFileDirectory, "Error", MB_OK);
1.916 cvs 7602: #endif /* _WINGUI */
1.979 gully 7603: #if defined(_GTK) || defined(_WX)
1.1136 gully 7604: fprintf (stderr, TempFileDirectory);
1.979 gully 7605: #endif /* defined(_GTK) || defined(_WX) */
1.1136 gully 7606: exit (1);
7607: }
7608: }
7609:
7610: /* add the temporary directory in document path */
7611: strcpy (TempFileDirectory, s);
7612: TtaAppendDocumentPath (TempFileDirectory);
1.916 cvs 7613: #ifdef _WINGUI
1.1136 gully 7614: s = TtaGetEnvString ("APP_HOME");
7615: if (!CheckMakeDirectory (s, TRUE))
7616: /* didn't work, so we exit */
7617: {
7618: sprintf (TempFileDirectory,
7619: TtaGetMessage (AMAYA, AM_CANNOT_CREATE_DIRECTORY), s);
7620: MessageBox (NULL, TempFileDirectory, "Error", MB_OK);
7621: exit (1);
7622: }
1.916 cvs 7623: #endif /* _WINGUI */
1.1136 gully 7624: /*
7625: * Build the User preferences file name:
7626: * $HOME/.amaya/amaya.css on Unix platforms
7627: * $HOME\amaya\amaya.css on Windows platforms
7628: */
7629: ptr = (char *)TtaGetMemory (MAX_LENGTH);
7630: sprintf (ptr, "%s%c%s.css", s, DIR_SEP, TtaGetAppName());
7631: UserCSS = TtaStrdup (ptr);
7632: InitUserStyleSheet (UserCSS);
7633: TtaFreeMemory (ptr);
1.1147 vatton 7634: /* check if the new location is set */
7635: ptr = TtaGetEnvString ("NEW_LOCATION");
7636: if (ptr == NULL)
7637: {
7638: i = 0;
7639: TtaGetEnvInt("OPENING_LOCATION", &i);
7640: TtaSetEnvInt ("NEW_LOCATION", i+1, TRUE);/* new tab */
7641: }
7642: else
7643: ptr = NULL;
1.1136 gully 7644:
7645: /* Initialize environment variables if they are not defined */
7646: TtaSetEnvBoolean ("SHOW_BUTTONS", TRUE, FALSE);
7647: TtaSetEnvBoolean ("SHOW_ADDRESS", TRUE, FALSE);
7648: TtaSetEnvBoolean ("SHOW_MAP_AREAS", FALSE, FALSE);
7649: TtaSetEnvBoolean ("SHOW_TARGET", FALSE, FALSE);
1.1146 tollenae 7650: TtaSetEnvBoolean ("SHOW_TEMPLATES", TRUE, FALSE);
1.1136 gully 7651: TtaSetEnvBoolean ("LOAD_IMAGES", TRUE, FALSE);
7652: TtaSetEnvBoolean ("LOAD_OBJECTS", TRUE, FALSE);
7653: TtaSetEnvBoolean ("LOAD_CSS", TRUE, FALSE);
7654: TtaSetEnvBoolean ("SEND_REFERER", FALSE, FALSE);
1.1157 vatton 7655: #ifdef _WX
7656: TtaSetEnvBoolean ("CLOSE_WHEN_APPLY", TRUE, FALSE);
7657: #endif /* _WX */
1.1136 gully 7658: /* get current value */
7659: TtaGetEnvBoolean ("SHOW_BUTTONS", &bt);
7660: TtaGetEnvBoolean ("SHOW_ADDRESS", &add);
7661: TtaGetEnvBoolean ("SHOW_MAP_AREAS", &map);
7662: /* Create and intialize resources needed for each document */
7663: /* Style sheets are strored in directory .amaya/0 */
7664: for (i = 0; i < DocumentTableLength; i++)
7665: {
7666: /* initialize document table */
7667: DocumentURLs[i] = NULL;
7668: DocumentTypes[i] = docHTML;
7669: DocumentSource[i] = 0;
7670: DocumentMeta[i] = NULL;
7671: MapAreas[i] = map;
1.1175 cvs 7672: HSplit[i] = FALSE;
7673: VSplit[i] = FALSE;
1.1136 gully 7674: SButtons[i] = bt;
7675: SAddress[i] = add;
7676: /* initialize history */
7677: InitDocHistory (i);
7678: }
7679:
7680: /* allocate working buffers */
7681: LastURLName = (char *)TtaGetMemory (MAX_LENGTH);
7682: LastURLName[0] = EOS;
7683: DirectoryName = (char *)TtaGetMemory (MAX_LENGTH);
7684: DirectoryName[0] = EOS;
7685: SavedDocumentURL = NULL;
7686: /* set path on current directory */
1.1093 gully 7687: #ifdef _WX
1.1136 gully 7688: wxString homedir = TtaGetHomeDir();
7689: strcpy(DirectoryName, (const char *)homedir.mb_str(wxConvUTF8));
1.1093 gully 7690: #else /* _WX */
1.959 cvs 7691: #ifdef _WINDOWS
1.1136 gully 7692: s = getenv ("HOMEDRIVE");
7693: ptr = getenv ("HOMEPATH");
7694: if (s && *s && ptr)
7695: {
7696: sprintf (DirectoryName, "%s%s", s, ptr);
7697: s = NULL;
7698: ptr = NULL;
7699: }
1.960 vatton 7700: #else /* _WINDOWS */
1.1136 gully 7701: s = getenv ("HOME");
7702: if (s && *s)
7703: {
7704: strcpy (DirectoryName, s);
7705: s = NULL;
7706: }
1.959 cvs 7707: #endif /* _WINDOWS */
1.1093 gully 7708: #endif /* _WX */
1.1136 gully 7709: if (DirectoryName[0] == EOS || !TtaDirExists (DirectoryName))
7710: getcwd (DirectoryName, MAX_LENGTH);
7711: DocumentName = (char *)TtaGetMemory (MAX_LENGTH);
7712: memset (DocumentName, EOS, MAX_LENGTH);
7713: SavePath = (char *)TtaGetMemory (MAX_LENGTH);
7714: SavePath[0] = EOS;
7715: SaveName = (char *)TtaGetMemory (MAX_LENGTH);
7716: SaveName[0] = EOS;
7717: ObjectName = (char *)TtaGetMemory (MAX_LENGTH);
7718: ObjectName[0] = EOS;
7719: SaveImgsURL = (char *)TtaGetMemory (MAX_LENGTH);
7720: SaveImgsURL[0] = EOS;
7721: strcpy (ScanFilter, "*.*htm*");
7722: SaveAsHTML = TRUE;
7723: SaveAsXML = FALSE;
7724: SaveAsText = FALSE;
7725: CopyImages = FALSE;
7726: UpdateURLs = FALSE;
7727: SavingFile = (char *)TtaGetMemory (MAX_LENGTH);
7728: AttrHREFvalue = (char *)TtaGetMemory (MAX_LENGTH);
7729: AttrHREFvalue[0] = EOS;
1.6 cvs 7730:
7731: #ifdef WITH_SOCKS
1.1136 gully 7732: SOCKSinit ("amaya");
1.6 cvs 7733: #endif
7734:
1.1136 gully 7735: /* initialize parser mapping table and HTLib */
7736: InitMapping ();
1.10 cvs 7737:
1.1136 gully 7738: /* Define the backup function */
7739: TtaSetBackup (BackUpDocs);
1.890 cvs 7740:
1.1136 gully 7741: /* Define the auto-save function */
7742: TtaSetAutoSave ((Proc)GenerateAutoSavedDoc);
7743: /* Define the auto-save interval */
7744: TtaGetEnvInt ("AUTO_SAVE", &AutoSave_Interval);
7745: TtaSetDocumentBackUpInterval (AutoSave_Interval);
7746:
7747: TtaSetApplicationQuit (FreeAmayaStructures);
7748: TtaSetDocStatusUpdate ((Proc) DocStatusUpdate);
7749: AMAYA = TtaGetMessageTable ("amayamsg", AMAYA_MSG_MAX);
7750: /* allocate callbacks for amaya */
7751: BaseDialog = TtaSetCallback ((Proc)CallbackDialogue, MAX_REF);
7752: /* init the Picture context */
7753: InitImage ();
7754: /* init the Picture context */
7755: InitPrint ();
7756: /* init the CSS context */
7757: InitCSS ();
7758: /* initialize the structure transformation context */
7759: InitTransform ();
7760: /* initialize automaton for the HTML parser */
7761: InitAutomaton ();
7762: /* initialize the configuration menu context */
7763: InitConfMenu ();
1.336 cvs 7764: #ifdef ANNOTATIONS
1.1136 gully 7765: ANNOT_Init ();
1.336 cvs 7766: #endif /* ANNOTATIONS */
1.1136 gully 7767: /* initialize the libwww */
7768: QueryInit ();
7769: /* initialize the Amaya cache */
7770: InitAmayaCache ();
1.899 vatton 7771: /* now we know if it's a unique instance */
1.856 kahan 7772: #ifdef BOOKMARKS
1.1136 gully 7773: BM_Init ();
1.856 kahan 7774: #endif /* BOOKMARKS */
1.1033 cvs 7775: #ifdef _WINDOWS
1.1136 gully 7776: sprintf (LostPicturePath, "%s\\amaya\\lost.gif", TtaGetEnvString ("THOTDIR"));
1.1033 cvs 7777: #endif /* _WINDOWS */
1.831 cheyroul 7778: #ifdef _GTK
1.1136 gully 7779: sprintf (LostPicturePath, "%s/amaya/lost.gif", TtaGetEnvString ("THOTDIR"));
1.831 cheyroul 7780: #endif /* _GTK */
1.1136 gully 7781: InitMathML ();
1.799 vatton 7782: #ifdef _SVG
1.1136 gully 7783: InitSVG ();
7784: InitSVGAnim ();
7785: /*InitSVGLibraryManagerStructure ();*/
7786: InitLibrary();
1.824 vatton 7787: #endif /* _SVG */
1.1136 gully 7788: /* MKP: disable "Cooperation" menu if DAV is not defined or
7789: * initialize davlib module otherwise */
1.749 kirschpi 7790: #ifdef DAV
1.1136 gully 7791: InitDAV ();
1.857 vatton 7792: #else /* DAV */
1.1136 gully 7793: DAVLibEnable = FALSE;
1.749 kirschpi 7794: #endif /* DAV */
1.1136 gully 7795: URL_list = NULL;
7796: URL_list_len = 0;
7797: InitStringForCombobox ();
7798:
7799: AutoSave_list = NULL;
7800: AutoSave_list_len = 0;
7801: InitAutoSave ();
7802:
7803: CurrentDocument = 0;
7804: DocBook = 0;
7805: DontReplaceOldDoc = FALSE;
7806: restoredDoc = RestoreAmayaDocs ();
7807: s = NULL;
7808: if (restoredDoc)
7809: {
7810: /* old documents are restored */
7811: TtaFreeMemory (ptr);
7812: return;
7813: }
7814: #ifdef _WX
7815: int arg_doc_id = 1;
7816: while (arg_doc_id < appArgc)
7817: {
7818: s = appArgv[arg_doc_id];
7819: OpenNewDocFromArgv(s);
7820: arg_doc_id++;
7821: }
7822: /* load the homepage if nothing has been found in the command line */
7823: if (arg_doc_id == 1)
7824: OpenNewDocFromArgv(NULL);
1.1095 gully 7825: #else /* _WX */
1.1136 gully 7826: if (appArgc % 2 == 0)
7827: /* The last argument in the command line is the document to be opened */
7828: s = appArgv[appArgc - 1];
1.1057 gully 7829:
1.1136 gully 7830: // load the document with its url (s)
7831: OpenNewDocFromArgv(s);
1.1095 gully 7832: #endif /* _WX */
7833:
1.1057 gully 7834:
1.1136 gully 7835: TtaFreeMemory (ptr);
7836: ptr = NULL;
7837: Loading_method = CE_ABSOLUTE;
1.1057 gully 7838:
7839: #ifdef _WX
1.1136 gully 7840: /* register openurl callback in order to call it when twice amaya instance are running */
7841: TtaRegisterOpenURLCallback( (void (*)(void*))OpenNewDocFromArgv );
1.1070 gully 7842:
1.1136 gully 7843: /* send math entities to MathML panel */
7844: AmayaParams p;
1.1154 vatton 7845: p.param1 = 1; /* init action */
1.1136 gully 7846: p.param2 = (void*)pMathEntityTable;
7847: TtaSendDataToPanel( WXAMAYA_PANEL_SPECHAR, p );
1.1057 gully 7848: #endif /* _WX */
7849: }
7850:
7851: /*----------------------------------------------------------------------
7852: ----------------------------------------------------------------------*/
7853: void OpenNewDocFromArgv( char * url )
7854: {
7855: int i;
7856: char ptr[MAX_LENGTH];
7857: char * s = url;
7858:
1.1088 gully 7859: #ifdef _WX
7860: /* load the document in the default location */
1.1148 vatton 7861: LoadDefaultOpeningLocation (TRUE);
1.1088 gully 7862: #endif /* _WX */
7863:
1.1057 gully 7864: if (s == NULL || s[0] == EOS)
7865: /* no argument: display the Home Page */
7866: s = TtaGetEnvString ("HOME_PAGE");
7867: if (URL_list && s && !strcasecmp (s, "$PREV"))
7868: {
7869: /* no argument and no Home: display the previous open URI */
7870: for (i = 0; URL_list[i] != EOS && URL_list[i] != EOL; i++)
1.1135 gully 7871: ptr[i] = URL_list[i];
1.1057 gully 7872: ptr[i] = EOS;
7873: s = ptr;
7874: }
7875:
7876: if (s == NULL || s[0] == EOS)
7877: {
7878: /* no argument, no Home, and no previous page: display default Amaya URL */
7879: GoToHome (0, 1);
7880: }
7881: else if (IsW3Path (s))
7882: {
7883: /* it's a remote document */
7884: strcpy (LastURLName, s);
7885: CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
7886: }
7887: else
7888: {
7889: NormalizeFile (s, LastURLName, AM_CONV_NONE);
7890: if (IsW3Path (LastURLName))
1.1135 gully 7891: {
7892: /* if the command line paremeter
7893: is a url without http://
7894: it's a remote document or
7895: a new file (doesn't exist yet )
7896: in the current path */
7897: strcpy (s, LastURLName);
7898: CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
7899: }
1.1057 gully 7900: else
1.1135 gully 7901: {
7902: /* check if it is an absolute or a relative name */
1.961 vatton 7903: #ifdef _WINDOWS
1.1135 gully 7904: if (LastURLName[0] == DIR_SEP || LastURLName[1] == ':')
1.961 vatton 7905: #else /* _WINDOWS */
1.1135 gully 7906: if (LastURLName[0] == DIR_SEP)
1.963 vatton 7907: #endif /* _WINDOWS */
1.795 vatton 7908: /* it is an absolute name */
1.1135 gully 7909: TtaExtractName (LastURLName, DirectoryName, DocumentName);
7910: else
7911: {
7912: /* it is a relative name */
7913: getcwd (DirectoryName, MAX_LENGTH);
7914: strcpy (DocumentName, LastURLName);
7915: }
7916: /* start with the local document */
7917: LastURLName[0] = EOS;
7918: CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
7919: }
1.1057 gully 7920: }
1.6 cvs 7921: }
7922:
1.40 cvs 7923: /*----------------------------------------------------------------------
1.60 cvs 7924: ChangeAttrOnRoot
7925: If the root element of the document does not have an attribute of
7926: type attrNum, create one.
7927: If the root has such an attribute, delete it.
1.48 cvs 7928: ----------------------------------------------------------------------*/
1.727 vatton 7929: void ChangeAttrOnRoot (Document doc, int attrNum)
1.48 cvs 7930: {
1.732 vatton 7931: Element root, el;
7932: AttributeType attrType;
7933: Attribute attr;
7934: int position;
7935: int distance;
7936: ThotBool docModified;
1.48 cvs 7937:
1.727 vatton 7938: docModified = TtaIsDocumentModified (doc);
7939: root = TtaGetRootElement (doc);
1.732 vatton 7940: /* get the current position in the document */
7941: position = RelativePosition (doc, &distance);
1.727 vatton 7942: TtaSetDisplayMode (doc, NoComputedDisplay);
7943: attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
7944: attrType.AttrTypeNum = attrNum;
7945: attr = TtaGetAttribute (root, attrType);
7946: if (attr != NULL)
7947: /* the root element has that attribute. Remove it */
7948: TtaRemoveAttribute (root, attr, doc);
7949: else
7950: /* the root element does not have that attribute. Create it */
7951: {
7952: attr = TtaNewAttribute (attrType);
1.965 quint 7953: TtaSetAttributeValue (attr, 1, NULL, doc);
1.727 vatton 7954: TtaAttachAttribute (root, attr, doc);
7955: }
7956: if (!docModified)
7957: {
7958: TtaSetDocumentUnmodified (doc);
7959: /* switch Amaya buttons and menus */
7960: DocStatusUpdate (doc, docModified);
7961: }
7962: TtaSetDisplayMode (doc, DisplayImmediately);
1.732 vatton 7963: /* show the document at the same position */
7964: el = ElementAtPosition (doc, position);
7965: TtaShowElement (doc, 1, el, distance);
1.60 cvs 7966: }
7967:
7968: /*----------------------------------------------------------------------
1.1046 gully 7969: ShowPanel
7970: show/hide the side panel
7971: ----------------------------------------------------------------------*/
7972: void ShowPanel (Document doc, View view)
7973: {
1.1054 gully 7974: #ifdef _WX
7975: int frame_id = GetWindowNumber (doc, view);
7976: TtaToggleOnOffSidePanel( frame_id );
7977: #endif /* _WX */
1.1046 gully 7978: }
7979:
7980: /*----------------------------------------------------------------------
7981: FullScreen
7982: enable/disable fullscreen
7983: ----------------------------------------------------------------------*/
7984: void FullScreen (Document doc, View view)
7985: {
1.1055 gully 7986: #ifdef _WX
7987: int frame_id = GetWindowNumber (doc, view);
7988: TtaToggleOnOffFullScreen( frame_id );
7989: #endif /* _WX */
1.1046 gully 7990: }
7991:
7992: /*----------------------------------------------------------------------
1.1127 vatton 7993: SplitHorizontally
7994: split horizontally the view
1.1046 gully 7995: ----------------------------------------------------------------------*/
1.1127 vatton 7996: void SplitHorizontally (Document doc, View view)
1.1175 cvs 7997: {
1.1054 gully 7998: #ifdef _WX
7999: int frame_id = GetWindowNumber (doc, view);
1.1127 vatton 8000: TtaSplitViewHorizontally( frame_id );
1.1110 gully 8001: #endif /* _WX */
8002: }
8003:
8004: /*----------------------------------------------------------------------
1.1127 vatton 8005: SplitVertically
8006: split vertically the view
1.1110 gully 8007: ----------------------------------------------------------------------*/
1.1127 vatton 8008: void SplitVertically (Document doc, View view)
1.1110 gully 8009: {
8010: #ifdef _WX
8011: int frame_id = GetWindowNumber (doc, view);
1.1127 vatton 8012: TtaSplitViewVertically( frame_id );
1.1054 gully 8013: #endif /* _WX */
1.1046 gully 8014: }
8015:
8016: /*----------------------------------------------------------------------
1.1175 cvs 8017: ShowHSplitToggle
8018: Show toggle mark
8019: ----------------------------------------------------------------------*/
8020: void ShowHSplitToggle (Document doc, View view)
8021: {
8022: #ifdef _WX
8023: HSplit[doc] = TRUE;
8024: TtaSetToggleItem (doc, view, Views, TSplitHorizontally, HSplit[doc]);
8025: // Set V toggle off
8026: HideVSplitToggle (doc, view);
8027: // Update the document source toggle
8028: if (DocumentSource[doc])
8029: {
8030: HSplit[DocumentSource[doc]] = TRUE;
8031: TtaSetToggleItem (DocumentSource[doc], 1, Views,
8032: TSplitHorizontally, HSplit[DocumentSource[doc]]);
8033: }
8034: #endif /* _WX */
8035: }
8036: /*----------------------------------------------------------------------
8037: ShowVSplitToggle
8038: Show toggle mark
8039: ----------------------------------------------------------------------*/
8040: void ShowVSplitToggle (Document doc, View view)
8041: {
8042: #ifdef _WX
8043: VSplit[doc] = TRUE;
8044: TtaSetToggleItem (doc, view, Views, TSplitVertically, VSplit[doc]);
8045: // Set H toggle off
8046: HideHSplitToggle (doc, view);
8047: // Update the document source toggle
8048: if (DocumentSource[doc])
8049: {
8050: VSplit[DocumentSource[doc]] = TRUE;
8051: TtaSetToggleItem (DocumentSource[doc], 1, Views,
8052: TSplitVertically, VSplit[DocumentSource[doc]]);
8053: }
8054: #endif /* _WX */
8055: }
8056:
8057: /*----------------------------------------------------------------------
8058: HideHSplitToggle
8059: Hide toggle mark
8060: ----------------------------------------------------------------------*/
8061: void HideHSplitToggle (Document doc, View view)
8062: {
8063: #ifdef _WX
8064: HSplit[doc] = FALSE;
8065: TtaSetToggleItem (doc, view, Views, TSplitHorizontally, HSplit[doc]);
8066: // Update the document source toggle
8067: if (DocumentSource[doc])
8068: {
8069: HSplit[DocumentSource[doc]] = FALSE;
8070: TtaSetToggleItem (DocumentSource[doc], 1, Views,
8071: TSplitHorizontally, HSplit[DocumentSource[doc]]);
8072: }
8073: #endif /* _WX */
8074: }
8075:
8076: /*----------------------------------------------------------------------
8077: HideVSplitToggle
8078: Hide toggle mark
8079: ----------------------------------------------------------------------*/
8080: void HideVSplitToggle (Document doc, View view)
8081: {
8082: #ifdef _WX
8083: VSplit[doc] = FALSE;
8084: TtaSetToggleItem (doc, view, Views, TSplitVertically, VSplit[doc]);
8085: // Update the document source toggle
8086: if (DocumentSource[doc])
8087: {
8088: VSplit[DocumentSource[doc]] = FALSE;
8089: TtaSetToggleItem (DocumentSource[doc], 1, Views,
8090: TSplitVertically, VSplit[DocumentSource[doc]]);
8091: }
8092: #endif /* _WX */
8093: }
8094:
8095: /*----------------------------------------------------------------------
1.60 cvs 8096: ShowMapAreas
8097: Execute the "Show Map Areas" command
8098: ----------------------------------------------------------------------*/
1.646 cvs 8099: void ShowMapAreas (Document doc, View view)
1.60 cvs 8100: {
1.916 cvs 8101: #ifdef _WINGUI
1.646 cvs 8102: int frame = GetWindowNumber (doc, view);
1.176 cvs 8103:
1.645 vatton 8104: if (frame == 0 || frame > 10)
8105: TtaError (ERR_invalid_parameter);
8106: else
8107: {
1.1184 vatton 8108: HMENU hmenu = WIN_GetMenu (frame);
1.646 cvs 8109: if (!MapAreas[doc])
1.1136 gully 8110: {
1.176 cvs 8111: CheckMenuItem (hmenu, menu_item, MF_BYCOMMAND | MF_CHECKED);
1.646 cvs 8112: MapAreas[doc] = TRUE;
1.1136 gully 8113: }
1.645 vatton 8114: else
1.1136 gully 8115: {
8116: hmenu = WIN_GetMenu (frame);
8117: CheckMenuItem (hmenu, menu_item, MF_BYCOMMAND | MF_UNCHECKED);
8118: MapAreas[doc] = FALSE;
8119: }
8120: }
1.916 cvs 8121: #endif /* _WINGUI */
1.891 gully 8122:
1.979 gully 8123: #if defined(_GTK) || defined(_WX)
1.646 cvs 8124: MapAreas[doc] = !MapAreas[doc];
1.1113 vatton 8125: TtaSetToggleItem (doc, view, Views, TShowMapAreas, MapAreas[doc]);
8126: #endif /* _GTK || _WX */
1.646 cvs 8127: ChangeAttrOnRoot (doc, HTML_ATTR_ShowAreas);
8128: }
8129:
8130: /*----------------------------------------------------------------------
1.772 vatton 8131: ShowButtons
8132: Execute the "Show Buttons" command
8133: ----------------------------------------------------------------------*/
8134: void ShowButtons (Document doc, View view)
8135: {
1.891 gully 8136:
1.916 cvs 8137: #ifdef _WINGUI
1.772 vatton 8138: int frame = GetWindowNumber (doc, view);
8139:
8140: if (frame == 0 || frame > 10)
8141: TtaError (ERR_invalid_parameter);
8142: else
8143: {
8144: HMENU hmenu = WIN_GetMenu (frame);
8145: if (!SButtons[doc])
1.1136 gully 8146: {
1.772 vatton 8147: CheckMenuItem (hmenu, menu_item, MF_BYCOMMAND | MF_CHECKED);
8148: SButtons[doc] = TRUE;
1.1136 gully 8149: }
1.772 vatton 8150: else
1.1136 gully 8151: {
8152: hmenu = WIN_GetMenu (frame);
8153: CheckMenuItem (hmenu, menu_item, MF_BYCOMMAND | MF_UNCHECKED);
8154: SButtons[doc] = FALSE;
8155: }
8156: }
1.916 cvs 8157: #endif /* _WINGUI */
1.891 gully 8158:
1.979 gully 8159: #if defined(_GTK) || defined(_WX)
1.772 vatton 8160: SButtons[doc] = !SButtons[doc];
1.979 gully 8161: #endif /* #if defined(_GTK) || defined(_WX) */
1.891 gully 8162:
1.772 vatton 8163: TtaSetToggleItem (doc, 1, Views, TShowButtonbar, SButtons[doc]);
1.1084 gully 8164: #ifndef _WX
1.772 vatton 8165: TtcSwitchButtonBar (doc, view);
1.1084 gully 8166: #endif /* _WX */
1.772 vatton 8167: }
8168:
8169: /*----------------------------------------------------------------------
8170: ShowAddress
8171: Execute the "Show Address" command
8172: ----------------------------------------------------------------------*/
8173: void ShowAddress (Document doc, View view)
8174: {
1.891 gully 8175:
1.916 cvs 8176: #ifdef _WINGUI
1.772 vatton 8177: int frame = GetWindowNumber (doc, view);
8178:
8179: if (frame == 0 || frame > 10)
8180: TtaError (ERR_invalid_parameter);
8181: else
8182: {
8183: HMENU hmenu = WIN_GetMenu (frame);
8184: if (!SAddress[doc])
1.1136 gully 8185: {
1.772 vatton 8186: CheckMenuItem (hmenu, menu_item, MF_BYCOMMAND | MF_CHECKED);
8187: SAddress[doc] = TRUE;
1.1136 gully 8188: }
1.772 vatton 8189: else
1.1136 gully 8190: {
8191: hmenu = WIN_GetMenu (frame);
8192: CheckMenuItem (hmenu, menu_item, MF_BYCOMMAND | MF_UNCHECKED);
8193: SAddress[doc] = FALSE;
8194: }
8195: }
1.916 cvs 8196: #endif /* _WINGUI */
1.891 gully 8197:
1.979 gully 8198: #if defined(_GTK) || defined(_WX)
1.772 vatton 8199: SAddress[doc] = !SAddress[doc];
1.979 gully 8200: #endif /* #if defined(_GTK) || defined(_WX) */
1.891 gully 8201:
1.772 vatton 8202: TtaSetToggleItem (doc, 1, Views, TShowTextZone, SAddress[doc]);
1.1087 gully 8203: #ifndef _WX
1.772 vatton 8204: TtcSwitchCommands (doc, view);
1.1087 gully 8205: #endif /* _WX */
1.772 vatton 8206: }
8207:
8208: /*----------------------------------------------------------------------
1.486 kahan 8209: MakeIDMenu
8210: A menu for adding or removing ID attributes in a document
8211: ----------------------------------------------------------------------*/
1.595 cvs 8212: void MakeIDMenu (Document doc, View view)
1.486 kahan 8213: {
1.979 gully 8214: #if defined(_GTK) || defined(_WX)
1.1037 vatton 8215: int i;
1.547 cvs 8216: char s[MAX_LENGTH];
1.979 gully 8217: #endif /* #if defined(_GTK) || defined(_WX) */
1.486 kahan 8218:
8219: /* initialize the global variables */
1.495 kahan 8220: IdStatus[0] = EOS;
1.494 kahan 8221: IdDoc = doc;
1.486 kahan 8222:
8223: /* Create the dialogue form */
1.979 gully 8224: #if defined(_GTK) || defined(_WX)
1.486 kahan 8225: i = 0;
1.857 vatton 8226: strcpy (&s[i], TtaGetMessage (AMAYA, ADD_ID));
1.547 cvs 8227: i += strlen (&s[i]) + 1;
1.857 vatton 8228: strcpy (&s[i], TtaGetMessage (AMAYA, REMOVE_ID));
1.486 kahan 8229: TtaNewSheet (BaseDialog + MakeIdMenu,
1.1136 gully 8230: TtaGetViewFrame (doc, view),
8231: TtaGetMessage (AMAYA, ADD_REMOVE_ID),
8232: 2, s, FALSE, 6, 'L', D_DONE);
1.486 kahan 8233: TtaNewTextForm (BaseDialog + mElemName,
1.1136 gully 8234: BaseDialog + MakeIdMenu,
8235: TtaGetMessage (AMAYA, ENTER_ELEMENT_NAME),
8236: 10, 1, FALSE);
1.857 vatton 8237: TtaSetTextForm (BaseDialog + mElemName, IdElemName);
1.495 kahan 8238: /* apply operation in */
1.857 vatton 8239: i = 0;
8240: sprintf (&s[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_IN_WHOLE_DOC));
1.547 cvs 8241: i += strlen (&s[i]) + 1;
1.857 vatton 8242: sprintf (&s[i], "%s%s", "B", TtaGetMessage (LIB, TMSG_WITHIN_SEL));
1.495 kahan 8243: TtaNewSubmenu (BaseDialog + mIdUseSelection,
1.1136 gully 8244: BaseDialog + MakeIdMenu, 0,
8245: TtaGetMessage (AMAYA, APPLY_OPERATION),
8246: 2, s,
8247: NULL, 0 /* no max length */, FALSE);
1.495 kahan 8248: /* status label */
8249: TtaNewLabel (BaseDialog + mIdStatus,
1.1136 gully 8250: BaseDialog + MakeIdMenu,
8251: " ");
1.495 kahan 8252: /* select the current radio button */
8253: TtaSetMenuForm (BaseDialog + mIdUseSelection, IdApplyToSelection);
1.486 kahan 8254: TtaSetDialoguePosition ();
8255: TtaShowDialogue (BaseDialog + MakeIdMenu, TRUE);
1.979 gully 8256: #endif /* #if defined(_GTK) || defined(_WX) */
1.891 gully 8257:
1.916 cvs 8258: #ifdef _WINGUI
1.494 kahan 8259: CreateMakeIDDlgWindow (TtaGetViewFrame (doc, view));
1.916 cvs 8260: #endif /* _WINGUI */
1.1063 gully 8261:
8262: #ifdef _WX
8263: wxASSERT_MSG(false, _T("TODO: MakeIDMenu"));
8264: #endif /* _WX */
1.486 kahan 8265: }
1.6 cvs 8266:
1.9 cvs 8267: /*----------------------------------------------------------------------
1.1136 gully 8268: CheckAmayaClosed closes the application when there is any more
8269: opened document
1.379 cvs 8270: ----------------------------------------------------------------------*/
1.678 vatton 8271: void CheckAmayaClosed ()
1.379 cvs 8272: {
8273: int i;
8274:
8275: /* is it the last loaded document ? */
8276: i = 1;
8277: while (i < DocumentTableLength && DocumentURLs[i] == NULL)
8278: i++;
8279:
8280: if (i == DocumentTableLength)
1.771 cvs 8281: {
1.836 vatton 8282: /* remove images loaded by shared CSS style sheets */
8283: RemoveDocumentImages (0);
1.884 vatton 8284: #ifdef _SVG
8285: SVGLIB_FreeDocumentResource ();
8286: #endif /* _SVG */
1.900 vatton 8287: /* remove the AutoSave file */
1.771 cvs 8288: TtaQuit ();
8289: }
1.379 cvs 8290: }
8291:
1.1017 gully 8292: /*----------------------------------------------------------------------
1.1136 gully 8293: CloseTab close the current active page
8294: Shortcut : CTRL x + CTRL p
1.1017 gully 8295: ----------------------------------------------------------------------*/
1.1023 gully 8296: void AmayaCloseTab (Document doc, View view)
1.1017 gully 8297: {
8298: #ifdef _WX
8299: int page_id = -1;
8300: int page_position = 0;
8301: int window_id = 0;
8302:
8303: window_id = TtaGetDocumentWindowId( doc, view );
1.1103 vatton 8304: if (TtaUniqueTabInWindow (doc))
8305: TtaCloseWindow( window_id );
8306: else
8307: {
8308: /* Get the window id and page id of current document and
1.1136 gully 8309: close the corresponding page */
1.1103 vatton 8310: TtaGetDocumentPageId( doc, view, &page_id, &page_position );
8311: TtaClosePage( window_id, page_id );
1.1017 gully 8312:
1.1103 vatton 8313: /* Close the windows if it contains no more page */
8314: TtaCleanUpWindow( window_id );
8315: }
1.1017 gully 8316: #endif /* _WX */
8317: }
1.379 cvs 8318:
8319: /*----------------------------------------------------------------------
1.9 cvs 8320: ----------------------------------------------------------------------*/
1.1023 gully 8321: void AmayaCloseWindow (Document doc, View view)
1.365 cvs 8322: {
1.1020 gully 8323: /* Save the current windows geometry */
8324: SaveGeometryOnExit( doc, NULL);
8325: #ifdef _WX
8326: /* get the document's parent window and try to close it */
8327: int window_id = TtaGetDocumentWindowId( doc, view );
8328: TtaCloseWindow( window_id );
8329: #else /* _WX */
1.1058 vatton 8330: if (DocumentURLs[doc] && view == 1)
8331: {
8332: TtcCloseDocument (doc, view);
8333: if (!W3Loading)
1.1136 gully 8334: CheckAmayaClosed ();
1.1058 vatton 8335: }
8336: else
8337: TtcCloseView (doc, view);
1.1020 gully 8338: #endif /* _WX */
1.365 cvs 8339: }
8340:
8341: /*----------------------------------------------------------------------
8342: ----------------------------------------------------------------------*/
1.678 vatton 8343: void AmayaClose (Document document, View view)
1.6 cvs 8344: {
1.992 gully 8345: #ifdef _WX
1.1062 gully 8346: AmayaWindowIterator it;
8347: for( it.first(); !it.isDone(); it.next() )
1.992 gully 8348: {
8349: /* close each window one by one */
1.1062 gully 8350: TtaCloseWindow( it.currentWindowId() );
1.992 gully 8351: }
8352: #endif /* _WX */
8353:
8354: #ifndef _WX
1.1136 gully 8355: int i;
8356: ThotBool documentClosed;
8357:
8358: /* invalid current loading */
8359: W3Loading = 0;
1.6 cvs 8360:
1.1136 gully 8361: documentClosed = TRUE;
1.56 cvs 8362:
1.1136 gully 8363: /* Save the current windows geometry */
8364: SaveGeometryOnExit( document, NULL );
1.925 cvs 8365:
1.1136 gully 8366: /* free each loaded document */
8367: for (i = 1; i < DocumentTableLength; i++)
8368: if (DocumentURLs[i] != NULL)
8369: {
8370: TtcCloseDocument (i, 1);
8371: documentClosed = (DocumentURLs[i] == NULL);
8372: if (!documentClosed)
8373: return;
8374: }
8375: /* remove images loaded by shared CSS style sheets */
8376: RemoveDocumentImages (0);
1.884 vatton 8377: #ifdef _SVG
1.1136 gully 8378: SVGLIB_FreeDocumentResource ();
1.884 vatton 8379: #endif /* _SVG */
1.1136 gully 8380: TtaQuit ();
1.992 gully 8381: #endif /* _WX */
1.783 cvs 8382: }
8383:
8384:
8385: /*----------------------------------------------------------------------
1.924 vatton 8386: AddURLInCombobox adds the new pathname in the combobox list.
1.890 cvs 8387: Store that URL into the file only if keep is TRUE.
1.924 vatton 8388: URIs are encoded with the default charset.
1.794 vatton 8389: ----------------------------------------------------------------------*/
1.924 vatton 8390: void AddURLInCombobox (char *pathname, char *form_data, ThotBool keep)
1.794 vatton 8391: {
1.1067 cvs 8392: char *urlstring, *app_home, *ptr, *url;
8393: int i, j, len, nb, end;
8394: FILE *file = NULL;
8395: unsigned char *localname;
1.1093 gully 8396: CHARSET encoding;
1.794 vatton 8397:
1.924 vatton 8398: if (pathname == NULL || pathname[0] == EOS)
1.794 vatton 8399: return;
1.839 kahan 8400: if (form_data && form_data[0] != EOS)
8401: {
1.924 vatton 8402: url = (char *)TtaGetMemory (strlen (pathname) + strlen (form_data) + 2);
8403: sprintf (url, "%s?%s", pathname, form_data);
1.839 kahan 8404: }
8405: else
1.924 vatton 8406: url = TtaStrdup (pathname);
1.794 vatton 8407: urlstring = (char *) TtaGetMemory (MAX_LENGTH);
8408: /* open the file list_url.dat into APP_HOME directory */
8409: app_home = TtaGetEnvString ("APP_HOME");
1.1093 gully 8410: #ifdef _WX
1.1135 gully 8411: /* force url encoding to utf8 */
1.1093 gully 8412: sprintf (urlstring, "%s%clist_url_utf8.dat", app_home, DIR_SEP);
8413: encoding = UTF_8;
8414: #else /* _WX */
1.794 vatton 8415: sprintf (urlstring, "%s%clist_url.dat", app_home, DIR_SEP);
1.1093 gully 8416: encoding = TtaGetLocaleCharset();
8417: #endif /* _WX */
1.794 vatton 8418: /* keep the previous list */
8419: ptr = URL_list;
8420: /* create a new list */
1.798 vatton 8421: len = strlen (url) + 1;
1.794 vatton 8422: i = 0;
8423: j = len;
8424: nb = 1;
1.798 vatton 8425: URL_list_len = URL_list_len + len + 1;
1.907 gully 8426: URL_list = (char *)TtaGetMemory (URL_list_len);
1.1115 vatton 8427: if (keep)
8428: file = TtaWriteOpen (urlstring);
1.799 vatton 8429: *urlstring = EOS;
8430: if (!keep || file)
1.794 vatton 8431: {
8432: /* put the new url */
8433: strcpy (URL_list, url);
1.799 vatton 8434: if (keep)
1.1135 gully 8435: {
8436: if (encoding != UTF_8)
8437: {
8438: localname = TtaConvertMbsToByte ((unsigned char *)url, encoding);
8439: fprintf (file, "\"%s\"\n", localname);
8440: TtaFreeMemory (localname);
8441: }
8442: else
8443: fprintf (file, "\"%s\"\n", url);
8444: }
1.799 vatton 8445: if (ptr && *ptr != EOS)
1.1135 gully 8446: {
8447: /* now write other urls */
8448: while (ptr[i] != EOS && nb < GetMaxURLList())
8449: {
8450: end = strlen (&ptr[i]) + 1;
8451: if ((URL_list_keep || i != 0) &&
8452: (end != len || strncmp (url, &ptr[i], len)))
8453: {
8454: /* add the newline between two urls */
8455: strcpy (&URL_list[j], &ptr[i]);
8456: if (keep)
8457: {
8458: if (encoding != UTF_8)
8459: {
8460: localname = TtaConvertMbsToByte ((unsigned char *)&ptr[i], encoding);
8461: fprintf (file, "\"%s\"\n", localname);
8462: TtaFreeMemory (localname);
8463: }
8464: else
8465: fprintf (file, "\"%s\"\n", &ptr[i]);
8466: }
8467: j += end;
8468: nb++;
8469: }
8470: i += end;
8471: }
8472: }
1.814 cvs 8473:
1.798 vatton 8474: URL_list[j] = EOS;
1.799 vatton 8475: URL_list_keep = keep;
1.1115 vatton 8476: if (keep)
1.1135 gully 8477: TtaWriteClose (file);
1.794 vatton 8478: }
8479: TtaFreeMemory (ptr);
8480: TtaFreeMemory (urlstring);
1.825 vatton 8481: TtaFreeMemory (url);
1.794 vatton 8482: }
8483:
8484: /*----------------------------------------------------------------------
1.783 cvs 8485: InitStringForCombobox
1.794 vatton 8486: Initializes the URLs string for combobox
1.783 cvs 8487: ----------------------------------------------------------------------*/
1.794 vatton 8488: void InitStringForCombobox ()
1.783 cvs 8489: {
1.1102 cvs 8490: unsigned char *urlstring, c;
1.814 cvs 8491: char *app_home;
8492: FILE *file;
1.1102 cvs 8493: int i, nb, len;
1.1093 gully 8494: CHARSET encoding;
1.794 vatton 8495:
8496: /* remove the previous list */
8497: TtaFreeMemory (URL_list);
1.803 vatton 8498: URL_list_keep = TRUE;
1.907 gully 8499: urlstring = (unsigned char *) TtaGetMemory (MAX_LENGTH);
1.794 vatton 8500: /* open the file list_url.dat into APP_HOME directory */
1.785 cheyroul 8501: app_home = TtaGetEnvString ("APP_HOME");
1.1093 gully 8502:
8503: #ifdef _WX
1.1135 gully 8504: /* force url encoding to utf8 */
1.1093 gully 8505: sprintf ((char *)urlstring, "%s%clist_url_utf8.dat", app_home, DIR_SEP);
8506: encoding = UTF_8;
8507: #else /* _WX */
1.907 gully 8508: sprintf ((char *)urlstring, "%s%clist_url.dat", app_home, DIR_SEP);
1.1093 gully 8509: encoding = TtaGetLocaleCharset();
8510: #endif /* _WX */
8511:
1.907 gully 8512: file = TtaReadOpen ((char *)urlstring);
1.784 cheyroul 8513: *urlstring = EOS;
1.794 vatton 8514: if (file)
1.783 cvs 8515: {
1.794 vatton 8516: /* get the size of the file */
8517: fseek (file, 0L, 2); /* end of the file */
1.1135 gully 8518: URL_list_len = (ftell (file) * 4) + GetMaxURLList() + 4;
1.907 gully 8519: URL_list = (char *)TtaGetMemory (URL_list_len);
1.890 cvs 8520: URL_list[0] = EOS;
1.794 vatton 8521: fseek (file, 0L, 0); /* beginning of the file */
8522: /* initialize the list by reading the file */
8523: i = 0;
8524: nb = 0;
1.820 vatton 8525: while (TtaReadByte (file, &c))
1.1135 gully 8526: {
8527: if (c == '"')
8528: {
8529: len = 0;
8530: urlstring[len] = EOS;
8531: while (len < MAX_LENGTH && TtaReadByte (file, &c) && c != EOL)
8532: {
8533: if (c == '"')
8534: urlstring[len] = EOS;
8535: else if (c == 13)
8536: urlstring[len] = EOS;
8537: else
8538: urlstring[len++] = (char)c;
8539: }
8540: urlstring[len] = EOS;
8541: if (i > 0 && len)
8542: /* add an EOS between two urls */
8543: URL_list[i++] = EOS;
8544: if (len)
8545: {
8546: nb++;
8547: strcpy ((char *)&URL_list[i], (char *)urlstring);
8548: i += len;
8549: }
8550: }
8551: }
1.820 vatton 8552: URL_list[i + 1] = EOS;
1.890 cvs 8553: TtaReadClose (file);
8554: }
8555: TtaFreeMemory (urlstring);
8556: }
8557:
8558:
8559: /*----------------------------------------------------------------------
8560: RemoveDocFromSaveList remove the file from the AutoSave list
8561: ----------------------------------------------------------------------*/
1.924 vatton 8562: void RemoveDocFromSaveList (char *name, char *initial_url, int doctype)
1.890 cvs 8563: {
1.924 vatton 8564: char *urlstring, *app_home, *ptr, *list_item;
1.890 cvs 8565: char *ptr_end, *ptr_beg;
1.897 vatton 8566: int i, j, len, nb, end;
1.890 cvs 8567: FILE *file = NULL;
8568:
1.924 vatton 8569: if (name == NULL || name[0] == EOS)
1.890 cvs 8570: return;
8571: if (initial_url == NULL || initial_url[0] == EOS)
8572: return;
8573: /* keep the previous list */
8574: ptr = AutoSave_list;
8575: /* create a new list */
1.907 gully 8576: AutoSave_list = (char *)TtaGetMemory (AutoSave_list_len + 1);
1.924 vatton 8577: len = strlen (initial_url) + strlen (name) + 1;
1.898 quint 8578: len += 17; /*doctype + quotation marks + spaces */
1.907 gully 8579: list_item = (char *)TtaGetMemory (len);
1.924 vatton 8580: sprintf (list_item, "\"%s\" \"%s\" %d", name, initial_url, doctype);
1.890 cvs 8581: /* open the file AutoSave.dat into APP_HOME directory */
8582: app_home = TtaGetEnvString ("APP_HOME");
1.902 vatton 8583: urlstring = (char *) TtaGetMemory (MAX_LENGTH);
1.890 cvs 8584: sprintf (urlstring, "%s%cAutoSave.dat", app_home, DIR_SEP);
8585:
8586: if (TtaFileExist (urlstring))
8587: {
8588: file = TtaWriteOpen (urlstring);
1.913 vatton 8589: if (file && AutoSave_list)
1.1136 gully 8590: {
8591: i = 0;
8592: j = 0;
8593: nb = 0;
8594: /* remove the line (write other urls) */
8595: if (ptr && *ptr != EOS)
8596: {
8597: while (ptr[i] != EOS && nb <= MAX_AutoSave_list)
8598: {
8599: end = strlen (&ptr[i]) + 1;
8600: ptr_end = strrchr (&ptr[i], '\"');
8601: if (ptr_end)
8602: {
8603: *ptr_end = EOS;
8604: ptr_beg = strrchr (&ptr[i], '\"');
8605: if (ptr_beg)
8606: {
8607: ptr_beg++;
8608: if (strcmp (initial_url, ptr_beg))
8609: {
8610: /* keep this entry */
8611: *ptr_end = '\"';
8612: strcpy (&AutoSave_list[j], &ptr[i]);
8613: AutoSave_list_len += end;
8614: fprintf (file, "%s\n", &ptr[i]);
8615: j += end;
8616: nb++;
8617: }
8618: }
8619: *ptr_end = '\"';
8620: }
8621: i += end;
8622: }
8623: }
8624: AutoSave_list[j] = EOS;
8625: TtaWriteClose (file);
8626: /* remove the backup file */
8627: if (j == 0 && TtaFileExist (urlstring))
8628: {
8629: TtaFileUnlink (urlstring);
8630: TtaFreeMemory (AutoSave_list);
8631: AutoSave_list = NULL;
8632: AutoSave_list_len = 0;
8633: }
8634: }
1.890 cvs 8635: }
8636: else
8637: {
8638: TtaFreeMemory (AutoSave_list);
8639: AutoSave_list = NULL;
8640: AutoSave_list_len = 0;
8641: }
8642:
1.924 vatton 8643: TtaFreeMemory (ptr);
8644: TtaFreeMemory (urlstring);
8645: TtaFreeMemory (list_item);
1.890 cvs 8646: }
8647:
8648: /*----------------------------------------------------------------------
8649: AddDocInSaveList adds the new URL into the AutoSave list
8650: ----------------------------------------------------------------------*/
1.924 vatton 8651: void AddDocInSaveList (char *name, char *initial_url, int doctype)
1.890 cvs 8652: {
1.924 vatton 8653: char *urlstring, *app_home, *ptr;
1.890 cvs 8654: char *ptr_end, *ptr_beg;
1.897 vatton 8655: int i, j, len, nb, end;
1.890 cvs 8656: FILE *file = NULL;
8657:
1.897 vatton 8658: if (AutoSave_Interval == 0)
1.890 cvs 8659: return;
1.924 vatton 8660: if (name == NULL || name[0] == EOS)
1.890 cvs 8661: return;
8662: if (initial_url == NULL || initial_url[0] == EOS)
8663: return;
8664: /* keep the previous list */
8665: ptr = AutoSave_list;
8666: /* create a new list */
1.924 vatton 8667: len = strlen (initial_url) + strlen (name) + 1;
1.890 cvs 8668: len += 7; /*doctype + quotation marks + spaces */
1.907 gully 8669: AutoSave_list = (char *)TtaGetMemory (AutoSave_list_len + len + 1);
1.890 cvs 8670:
8671: /* open the file AutoSave.dat into APP_HOME directory */
8672: urlstring = (char *) TtaGetMemory (MAX_LENGTH);
8673: app_home = TtaGetEnvString ("APP_HOME");
8674: sprintf (urlstring, "%s%cAutoSave.dat", app_home, DIR_SEP);
8675: file = TtaWriteOpen (urlstring);
8676: *urlstring = EOS;
8677:
8678: if (file)
8679: {
8680: i = 0;
8681: j = len;
8682: nb = 1;
8683: /* put the new line */
1.924 vatton 8684: sprintf (AutoSave_list, "\"%s\" \"%s\" %d", name, initial_url, doctype);
1.890 cvs 8685: AutoSave_list_len = len + 1;
8686: fprintf (file, "%s\n", AutoSave_list);
8687: if (ptr && *ptr != EOS)
1.1136 gully 8688: {
8689: /* now write other urls */
8690: while (ptr[i] != EOS && nb < MAX_AutoSave_list)
8691: {
8692: end = strlen (&ptr[i]) + 1;
8693:
8694: ptr_end = strrchr (&ptr[i], '\"');
8695: if (ptr_end)
8696: {
8697: *ptr_end = EOS;
8698: ptr_beg = strrchr (&ptr[i], '\"');
8699: if (ptr_beg)
8700: {
8701: ptr_beg++;
8702: if ((end != len) || (strcmp (initial_url, ptr_beg)))
8703: {
8704: /* copy the url */
8705: *ptr_end = '\"';
8706: strcpy (&AutoSave_list[j], &ptr[i]);
8707: AutoSave_list_len += end;
8708: fprintf (file, "%s\n", &ptr[i]);
8709: j += end;
8710: nb++;
8711: }
8712: }
8713: *ptr_end = '\"';
8714: }
8715: i += end;
8716: }
8717: }
1.890 cvs 8718: AutoSave_list[j] = EOS;
8719: TtaWriteClose (file);
8720: }
1.924 vatton 8721:
8722: TtaFreeMemory (ptr);
8723: TtaFreeMemory (urlstring);
1.890 cvs 8724: }
8725:
8726: /*----------------------------------------------------------------------
8727: InitAutoSave list
8728: ----------------------------------------------------------------------*/
8729: void InitAutoSave ()
8730: {
8731: unsigned char *urlstring, c;
8732: char *app_home;
8733: FILE *file;
1.897 vatton 8734: int i, nb, len;
1.890 cvs 8735:
8736: /* remove the previous list */
8737: TtaFreeMemory (AutoSave_list);
8738: AutoSave_list = NULL;
8739: AutoSave_list_len = 0;
1.907 gully 8740: urlstring = (unsigned char *) TtaGetMemory (MAX_LENGTH);
1.890 cvs 8741: /* open the file AutoSave.dat into APP_HOME directory */
8742: app_home = TtaGetEnvString ("APP_HOME");
1.907 gully 8743: sprintf ((char *)urlstring, "%s%cAutoSave.dat", app_home, DIR_SEP);
8744: file = TtaReadOpen ((char *)urlstring);
1.890 cvs 8745: *urlstring = EOS;
8746: if (file)
8747: {
8748: /* get the size of the file */
8749: fseek (file, 0L, 2); /* end of the file */
1.1135 gully 8750: AutoSave_list_len = ftell (file) + GetMaxURLList() + 4;
1.907 gully 8751: AutoSave_list = (char *)TtaGetMemory (AutoSave_list_len);
1.1138 vatton 8752: AutoSave_list[0] = EOS;
1.890 cvs 8753: fseek (file, 0L, 0); /* beginning of the file */
8754: /* initialize the list by reading the file */
8755: i = 0;
8756: nb = 0;
8757: while (TtaReadByte (file, &c))
1.1136 gully 8758: {
8759: if (c == '"')
8760: {
8761: len = 0;
8762: urlstring[len] = EOS;
8763: while (len < MAX_LENGTH && TtaReadByte (file, &c) && c != EOL)
8764: {
8765: if (c == '"')
8766: urlstring[len] = EOS;
8767: else if (c == 13)
8768: urlstring[len] = EOS;
8769: else
8770: urlstring[len++] = (char)c;
8771: }
8772: urlstring[len] = EOS;
8773: if (i > 0 && len)
8774: /* add an EOS between two urls */
8775: AutoSave_list[i++] = EOS;
8776: if (len)
8777: {
8778: nb++;
8779: strcpy ((char *)&AutoSave_list[i], (char *)urlstring);
8780: i += len;
8781: }
8782: }
8783: }
1.890 cvs 8784: AutoSave_list[i + 1] = EOS;
1.794 vatton 8785: TtaReadClose (file);
1.783 cvs 8786: }
8787: TtaFreeMemory (urlstring);
1.6 cvs 8788: }
1.964 gully 8789:
8790: /*----------------------------------------------------------------------
8791: SaveGeometryOnExit
8792: save the current document geometry only if "Save geometry on exit" is enable
8793: ----------------------------------------------------------------------*/
1.967 vatton 8794: void SaveGeometryOnExit (int document, const char * view_name)
1.964 gully 8795: {
8796: ThotBool saveGeometry = FALSE;
1.967 vatton 8797:
1.964 gully 8798: TtaGetEnvBoolean ("SAVE_GEOMETRY", &saveGeometry);
8799: if (saveGeometry)
8800: /* Save the current windows geometry */
8801: SetGeometryConf ( document, view_name );
8802: }
1.1088 gully 8803:
8804: /*----------------------------------------------------------------------
1.1147 vatton 8805: LoadDefaultOpeningLocation controls where the new document is displayed
8806: The parameter noReplace says the replace is not allowed
1.1088 gully 8807: ----------------------------------------------------------------------*/
1.1147 vatton 8808: void LoadDefaultOpeningLocation (ThotBool noReplace)
1.1088 gully 8809: {
1.1147 vatton 8810: int where_id = 1;
1.1088 gully 8811:
8812: /* get the default location in thotrc */
1.1147 vatton 8813: TtaGetEnvInt ("NEW_LOCATION", &where_id);
8814: if (noReplace && where_id == 0)
8815: where_id++; /* zero based in the config file */
1.1088 gully 8816:
8817: ThotCallback(BaseDialog + OpenLocation , INTEGER_DATA, (char*)where_id);
8818: }
1.1128 tollenae 8819:
1.1135 gully 8820: /*----------------------------------------------------------------------
8821: GetMaxURLList()
8822: returns the max urls which can be stored
8823: ----------------------------------------------------------------------*/
8824: int GetMaxURLList()
8825: {
8826: int max;
8827: TtaSetDefEnvString ("MAX_URL_LIST", "20", FALSE); // by default 20 urls
8828: TtaGetEnvInt ("MAX_URL_LIST", &max);
8829: return max;
8830: }
8831:
8832: /*----------------------------------------------------------------------
8833: SetMaxURLList()
8834: set a new limit for : max urls which can be stored
8835: ----------------------------------------------------------------------*/
8836: void SetMaxURLList(int max)
8837: {
8838: TtaSetEnvInt ("MAX_URL_LIST", max, TRUE);
8839: }
8840:
8841: /*----------------------------------------------------------------------
8842: ClearURLList()
8843: empty the url list
8844: ----------------------------------------------------------------------*/
8845: void ClearURLList()
8846: {
8847: char * app_home;
8848: char filename[MAX_LENGTH];
8849: FILE * file = NULL;
8850:
8851: /* cleanup the urllist variable */
8852: URL_list[0] = EOS;
8853:
8854: /* cleanup the urllist file */
8855: app_home = TtaGetEnvString ("APP_HOME");
8856: #ifdef _WX
8857: /* force url encoding to utf8 */
8858: sprintf ((char *)filename, "%s%clist_url_utf8.dat", app_home, DIR_SEP);
8859: #else /* _WX */
8860: sprintf ((char *)filename, "%s%clist_url.dat", app_home, DIR_SEP);
8861: #endif /* _WX */
8862: file = TtaWriteOpen(filename);
8863: TtaWriteClose(file);
1.1128 tollenae 8864:
1.1135 gully 8865: #ifdef _WX
8866: /* then cleanup the combobox widget */
8867: AmayaWindowIterator it;
8868: for( it.first(); !it.isDone(); it.next() )
8869: {
8870: /* empty url list on each windows */
8871: TtaEmptyURLBar( it.currentWindowId() );
8872: }
8873: #endif /* _WX */
8874: }
Webmaster