PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/amaya/init.c

https://github.com/pffy/Amaya-Editor
C | 8244 lines | 6422 code | 507 blank | 1315 comment | 1962 complexity | 6ac534b4467ef1867d7cf58f63e02277 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. *
  3. * (c) COPYRIGHT INRIA and W3C, 1996-2010
  4. * Please first read the full copyright statement in file COPYRIGHT.
  5. *
  6. */
  7. /*
  8. * Initialization functions and button functions of Amaya application.
  9. *
  10. * Author: I. Vatton
  11. * R. Guetari (W3C/INRIA) - Windows version
  12. */
  13. /* Included headerfiles */
  14. #include "wx/wx.h"
  15. #undef THOT_EXPORT
  16. #define THOT_EXPORT extern /* defined into css.c */
  17. #include "amaya.h"
  18. #undef THOT_EXPORT
  19. #define THOT_EXPORT extern
  20. #include "css.h"
  21. #include "trans.h"
  22. #include "zlib.h"
  23. #include "profiles.h"
  24. #include "MENUconf.h"
  25. #include "containers.h"
  26. #include "Elemlist.h"
  27. #include "insertelem_f.h"
  28. #include "tips.h"
  29. #ifdef TEMPLATES
  30. #include "Template.h"
  31. #include "templates.h"
  32. #include "templates_f.h"
  33. #include "templateDeclarations_f.h"
  34. #endif /* TEMPLATES */
  35. #ifdef _WINDOWS
  36. #include <commctrl.h>
  37. extern char LostPicturePath [MAX_LENGTH];
  38. #endif /* _WINDOWS */
  39. #include "message_wx.h"
  40. #include "wxdialogapi_f.h"
  41. #include "windowtypes_wx.h"
  42. #include "paneltypes_wx.h"
  43. #include "registry_wx.h"
  44. #include "appdialogue_wx.h"
  45. #include "AmayaWindowIterator.h"
  46. #include "AmayaParams.h"
  47. #include "Elemlist.h"
  48. #include "wxdialog/StyleListToolPanel.h"
  49. #include "javascript_f.h"
  50. extern XmlEntity *pMathEntityTable;
  51. #include "appdialogue_wx.h"
  52. /* SVG Templates */
  53. char *LastSVGelement = NULL;
  54. char *LastSVGelementTitle = NULL;
  55. ThotBool LastSVGelementIsFilled = FALSE;
  56. /* SVG Style panel */
  57. int Current_Opacity = 100;
  58. ThotBool FillEnabled = FALSE;
  59. int Current_FillColor = -1;
  60. int Current_FillOpacity = 100;
  61. ThotBool StrokeEnabled = TRUE;
  62. int Current_StrokeColor = -1;
  63. int Current_StrokeOpacity = 100;
  64. int Current_StrokeWidth = 1;
  65. /* HTML Style panel */
  66. int Current_Color = -1;
  67. int Current_BackgroundColor = -1;
  68. int SavePANEL_PREFERENCES = 1;
  69. int Current_FontFamily = 1;
  70. int Current_FontSize = 12;
  71. static int AmayaInitialized = 0;
  72. static ThotBool NewFile = FALSE;
  73. static int NewDocType = 0;
  74. static int NewDocProfile = 0;
  75. static int NewDocExtraProfile = 0;
  76. static ThotBool NewXML = TRUE;
  77. static ThotBool BADMimeType = FALSE;
  78. static ThotBool CriticConfirm = FALSE;
  79. static ThotBool CriticCheckError = FALSE;
  80. static ThotBool CriticLogError = FALSE;
  81. /* the open document is the Amaya default page */
  82. static ThotBool WelcomePage = FALSE;
  83. /* we have to mark the initial loading status to avoid to re-open the
  84. document view twice */
  85. static int Loading_method = CE_INIT;
  86. #include "MENUconf.h"
  87. #include "AHTURLTools_f.h"
  88. #include "css_f.h"
  89. #include "document.h"
  90. #include "EDITORactions_f.h"
  91. #include "EDITimage_f.h"
  92. #include "EDITstyle_f.h"
  93. #include "fetchXMLname_f.h"
  94. #ifdef _SVG
  95. #include "SVGedit_f.h"
  96. #endif /* _SVG */
  97. #include "HTMLactions_f.h"
  98. #include "HTMLbook_f.h"
  99. #include "HTMLedit_f.h"
  100. #include "HTMLhistory_f.h"
  101. #include "HTMLimage_f.h"
  102. #include "HTMLpresentation_f.h"
  103. #include "HTMLsave_f.h"
  104. #include "HTMLtable_f.h"
  105. #include "html2thot_f.h"
  106. #include "Mathedit_f.h"
  107. #include "MENUconf_f.h"
  108. #include "init_f.h"
  109. #include "query_f.h"
  110. #include "styleparser_f.h"
  111. #include "trans_f.h"
  112. #include "transparse_f.h"
  113. #include "UIcss_f.h"
  114. #include "string.h"
  115. #include "Xml2thot_f.h"
  116. #include "XPointer_f.h"
  117. #include "anim_f.h"
  118. #include "animbuilder_f.h"
  119. #ifdef ANNOTATIONS
  120. #include "annotlib.h"
  121. #include "ANNOTevent_f.h"
  122. #include "ANNOTfiles_f.h"
  123. #include "ANNOTtools_f.h"
  124. #endif /* ANNOTATIONS */
  125. #ifdef BOOKMARKS
  126. #include "BMevent_f.h"
  127. #endif /* BOOKMARKS */
  128. #include "wxdialogapi_f.h"
  129. #include "archives.h"
  130. #ifdef DAV
  131. #define WEBDAV_EXPORT extern
  132. #include "davlib.h"
  133. #include "davlib_f.h"
  134. #include "davlibRequests_f.h"
  135. #include "davlibUI_f.h"
  136. #endif /* DAV */
  137. extern void InitMathML ();
  138. extern void InitTemplates ();
  139. typedef enum
  140. {
  141. OpenDocBrowser,
  142. HrefAttrBrowser,
  143. DocSaveBrowser
  144. } TypeBrowserFile;
  145. TypeBrowserFile WidgetParent;
  146. /*----------------------------------------------------------------------
  147. ----------------------------------------------------------------------*/
  148. static int AmayaPopupDocContextMenu (int doc, int view, int window,
  149. wxWindow* win, int x, int y)
  150. {
  151. wxMenu *p_menu = TtaGetDocContextMenu ( window );
  152. if (p_menu && doc)
  153. {
  154. #ifdef TEMPLATES
  155. ElementType elType, parentType;
  156. DLList list = NULL;
  157. ForwardIterator iter;
  158. Element el, last, prev, parent;
  159. DLListNode node;
  160. int i, firstChar, lastChar, id = 1000;
  161. wxMenuItem *itemTemplateInsert = NULL,
  162. *itemTemplateAppend = NULL,
  163. *oldInsert = NULL,
  164. *oldAppend = NULL;
  165. wxMenu *menuTemplateInsert = NULL,
  166. *menuTemplateAppend = NULL;
  167. ThotBool bTemplate = IsTemplateInstanceDocument(doc);
  168. ThotBool do_insert = TRUE, do_append = TRUE;
  169. #endif /* TEMPLATES */
  170. #ifdef _SVG
  171. ElementType elementType;
  172. SSchema svgSchema;
  173. #endif /* _SVG */
  174. /* First items of the context menu can be displayed/hidden. */
  175. #define NB_ITEM 16
  176. #define CUT_POS NB_ITEM-6
  177. wxMenuItem* items[NB_ITEM];
  178. ThotBool display_item[NB_ITEM];
  179. /* By default, the first item until the "cut" command
  180. are not displayed... */
  181. for(i = 0; i < CUT_POS; i++)
  182. display_item[i] = FALSE;
  183. /* ... and cut, paste etc are displayed. */
  184. for(i = CUT_POS; i < NB_ITEM; i++)
  185. display_item[i] = TRUE;
  186. /* Is the element a link? */
  187. if (CanFollowTheLink(doc))
  188. {
  189. for(i = 0; i < 4; i++)
  190. display_item[i] = TRUE;
  191. }
  192. #ifdef _SVG
  193. /* Is it an SVG element? */
  194. TtaGiveFirstSelectedElement (doc, &el, &firstChar, &lastChar);
  195. if (el)
  196. {
  197. svgSchema = GetSVGSSchema (doc);
  198. elementType = TtaGetElementType(el);
  199. parent = TtaGetParent (el);
  200. parentType = TtaGetElementType (parent);
  201. if (elementType.ElSSchema == svgSchema && view == 1 &&
  202. parentType.ElSSchema == svgSchema)
  203. {
  204. if(!TtaIsLeaf(elementType) ||
  205. elementType.ElTypeNum == SVG_EL_TEXT_UNIT)
  206. /* Display the SVG transforms if a non-terminal SVG element
  207. or a TEXT_UNIT is selected */
  208. {
  209. display_item[4] = TRUE;
  210. display_item[5] = TRUE;
  211. display_item[6] = TRUE;
  212. display_item[7] = TRUE;
  213. display_item[8] = (elementType.ElTypeNum == SVG_EL_g);
  214. display_item[9] = TRUE;
  215. }
  216. else if(elementType.ElTypeNum == SVG_EL_GRAPHICS_UNIT)
  217. {
  218. /* Remove cut, copy, paste commands */
  219. for(i = 0; i < 3; i++)
  220. display_item[CUT_POS+i] = FALSE;
  221. }
  222. }
  223. }
  224. #endif /* _SVG */
  225. /* Remove all the item that must not be displayed */
  226. for(i = NB_ITEM - 1; i >= 0; i--)
  227. {
  228. if(!display_item[i])
  229. items[i] = p_menu->Remove(p_menu->FindItemByPosition(i));
  230. }
  231. #ifdef TEMPLATES
  232. TtaGiveFirstSelectedElement (doc, &el, &firstChar, &lastChar);
  233. TtaGiveLastSelectedElement (doc, &last, &i, &lastChar);
  234. if (el && el == last && bTemplate)
  235. {
  236. // only one element selected
  237. elType = TtaGetElementType (el);
  238. parent = TtaGetParent (el);
  239. parentType = TtaGetElementType (parent);
  240. if (parent == NULL || TtaIsReadOnly (parent))
  241. do_insert = do_append = FALSE;
  242. else if (!strcmp (TtaGetSSchemaName (parentType.ElSSchema), "Template") &&
  243. parentType.ElTypeNum == Template_EL_useSimple)
  244. do_insert = do_append = FALSE;
  245. else if (TtaIsLeaf (elType))
  246. {
  247. if ((firstChar == 0 && lastChar == 0) || lastChar >= TtaGetElementVolume(el))
  248. // check the end of the enclosing element
  249. TtaNextSibling (&last);
  250. prev = el;
  251. if ((firstChar == 0 && lastChar == 0) || (firstChar == 1 && lastChar == 0))
  252. // check the beginning of the enclosing element
  253. TtaPreviousSibling (&prev);
  254. do_insert = (prev == NULL);
  255. do_append = (last == NULL);
  256. }
  257. if (do_insert || do_append)
  258. {
  259. // prepare insert and apppend submenus
  260. list = InsertableElement_ComputeList (doc, el);
  261. if(DLList_GetSize(list)!=0)
  262. {
  263. menuTemplateInsert = new wxMenu;
  264. menuTemplateAppend = new wxMenu;
  265. iter = DLList_GetForwardIterator (list);
  266. ITERATOR_FOREACH (iter, DLListNode, node)
  267. {
  268. ElemListElement elem = (ElemListElement)node->elem;
  269. if (elem)
  270. {
  271. wxString str = TtaConvMessageToWX(ElemListElement_GetName(elem));
  272. menuTemplateInsert->Append(id, str);
  273. menuTemplateAppend->Append(100 + id++, str);
  274. }
  275. }
  276. // remove standard menu entries
  277. oldAppend = p_menu->Remove (p_menu->FindItemByPosition(p_menu->GetMenuItemCount()-1));
  278. oldInsert = p_menu->Remove (p_menu->FindItemByPosition(p_menu->GetMenuItemCount()-1));
  279. // new insert entry
  280. if (do_insert)
  281. {
  282. itemTemplateInsert = new wxMenuItem (p_menu, oldInsert->GetId(), oldInsert->GetLabel(),
  283. wxT(""), wxITEM_NORMAL, menuTemplateInsert);
  284. itemTemplateInsert->SetBitmap(oldInsert->GetBitmap());
  285. p_menu->Append(itemTemplateInsert);
  286. }
  287. else if (oldInsert)
  288. p_menu->Append(oldInsert);
  289. // new append entry
  290. if (do_append)
  291. {
  292. itemTemplateAppend = new wxMenuItem(p_menu, oldAppend->GetId(), oldAppend->GetLabel(),
  293. wxT(""), wxITEM_NORMAL, menuTemplateAppend);
  294. itemTemplateAppend->SetBitmap(oldAppend->GetBitmap());
  295. p_menu->Append(itemTemplateAppend);
  296. }
  297. else if (oldAppend)
  298. p_menu->Append(oldAppend);
  299. }
  300. else
  301. do_insert = do_append = FALSE;
  302. }
  303. TtaResetEnumContextMenu();
  304. }
  305. #endif /* TEMPLATES */
  306. // display the popup menu
  307. win->PopupMenu (p_menu, win->ScreenToClient(wxPoint(x, y)));
  308. #ifdef TEMPLATES
  309. // manage the selected entry
  310. if (itemTemplateInsert || itemTemplateAppend)
  311. {
  312. id = TtaGetEnumContextMenu();
  313. if(id!=-1)
  314. {
  315. id -= 1000;
  316. DLListNode node = DLList_GetElement(list, id<100?id:id-100);
  317. if(node && node->elem)
  318. InsertableElement_QueryInsertElement((ElemListElement)node->elem, id<100);
  319. }
  320. if (list)
  321. DLList_Destroy(list);
  322. // destroy submenus or remove entries
  323. if (itemTemplateAppend)
  324. p_menu->Destroy(itemTemplateAppend);
  325. else if (oldAppend)
  326. p_menu->Remove (oldAppend);
  327. if (itemTemplateInsert)
  328. p_menu->Destroy(itemTemplateInsert);
  329. else if (oldInsert)
  330. p_menu->Remove (oldInsert);
  331. // reattach standard menu entries
  332. if (oldInsert)
  333. p_menu->Append(oldInsert);
  334. if (oldAppend)
  335. p_menu->Append(oldAppend);
  336. }
  337. #endif /* TEMPLATES */
  338. /* Reinsert the menu items */
  339. for(i = 0; i < NB_ITEM; i++)
  340. {
  341. if(!display_item[i])
  342. p_menu->Insert(i, items[i]);
  343. }
  344. }
  345. return -1;
  346. }
  347. /*----------------------------------------------------------------------
  348. DocumentMetaDataAlloc
  349. Creates a DocumentMeta element and initializes it to its default
  350. values.
  351. ----------------------------------------------------------------------*/
  352. DocumentMetaDataElement *DocumentMetaDataAlloc (void)
  353. {
  354. DocumentMetaDataElement *me;
  355. me = (DocumentMetaDataElement *) TtaGetMemory (sizeof (DocumentMetaDataElement));
  356. memset ((void *) me, 0, sizeof (DocumentMetaDataElement));
  357. me->method = CE_ABSOLUTE;
  358. return (me);
  359. }
  360. /*----------------------------------------------------------------------
  361. DocumentMetaClear
  362. Clears the dynamically allocated memory associated to a metadata
  363. element. Doesn't free the element or clears any of its other elements.
  364. ----------------------------------------------------------------------*/
  365. void DocumentMetaClear (DocumentMetaDataElement *me)
  366. {
  367. if (!me)
  368. return;
  369. TtaFreeMemory (me->form_data);
  370. me->form_data = NULL;
  371. TtaFreeMemory (me->initial_url);
  372. me->initial_url = NULL;
  373. TtaFreeMemory (me->content_type);
  374. me->content_type = NULL;
  375. TtaFreeMemory (me->charset);
  376. me->charset = NULL;
  377. TtaFreeMemory (me->content_length);
  378. me->content_length = NULL;
  379. TtaFreeMemory (me->content_location);
  380. me->content_location = NULL;
  381. TtaFreeMemory (me->full_content_location);
  382. me->full_content_location = NULL;
  383. TtaFreeMemory (me->reason);
  384. me->reason = NULL;
  385. me->link_icon = NULL;
  386. }
  387. /*----------------------------------------------------------------------
  388. IsXMLDocType
  389. Returns TRUE if the DocumentTypes of the document is XML
  390. ----------------------------------------------------------------------*/
  391. ThotBool IsXMLDocType (Document doc)
  392. {
  393. if (DocumentTypes[doc] == docHTML ||
  394. DocumentTypes[doc] == docLibrary ||
  395. DocumentTypes[doc] == docMath ||
  396. DocumentTypes[doc] == docSVG ||
  397. DocumentTypes[doc] == docTemplate ||
  398. DocumentTypes[doc] == docXml)
  399. return TRUE;
  400. else
  401. return FALSE;
  402. }
  403. /*----------------------------------------------------------------------
  404. DocumentTypeString
  405. Returns a string that represents the document type or the current
  406. profile.
  407. ----------------------------------------------------------------------*/
  408. const char * DocumentTypeString (Document document)
  409. {
  410. const char *result;
  411. ThotBool isXml;
  412. result = NULL;
  413. switch (DocumentTypes[document])
  414. {
  415. case docText:
  416. result = "Text file";
  417. break;
  418. case docImage:
  419. result = "Image";
  420. case docCSS:
  421. result = "CSS style sheet";
  422. break;
  423. case docSource:
  424. result = "Document source";
  425. break;
  426. case docAnnot:
  427. result = "Annotation";
  428. break;
  429. case docLog:
  430. result = "Log file";
  431. break;
  432. case docSVG:
  433. result = "SVG";
  434. break;
  435. case docXml:
  436. result = "XML";
  437. break;
  438. case docLibrary:
  439. result = "HTML";
  440. break;
  441. case docTemplate:
  442. result = "XTiger template";
  443. break;
  444. default:
  445. break;
  446. }
  447. if (!result && DocumentMeta[document]) /* try the profiles */
  448. {
  449. isXml = DocumentMeta[document]->xmlformat;
  450. switch (TtaGetDocumentProfile (document))
  451. {
  452. case L_Other:
  453. result = "Unknown";
  454. break;
  455. case L_Xhtml11:
  456. if (TtaGetDocumentExtraProfile(document) == L_RDFa)
  457. result = "XHTML+RDFa";
  458. else
  459. result = "XHTML 1.1";
  460. break;
  461. case L_Basic:
  462. result = "XHTML 1.0 Basic";
  463. break;
  464. case L_Strict:
  465. if (isXml)
  466. result = "XHTML 1.0 Strict";
  467. else
  468. result = "HTML Strict";
  469. break;
  470. case L_Transitional:
  471. if (isXml)
  472. result = "XHTML 1.0 Transitional";
  473. else
  474. result = "HTML Transitional";
  475. break;
  476. case L_MathML:
  477. result = "MathML";
  478. break;
  479. }
  480. }
  481. return (result);
  482. }
  483. /*----------------------------------------------------------------------
  484. DocumentInfo
  485. Displays the document informations given by the header
  486. ----------------------------------------------------------------------*/
  487. void DocumentInfo (Document document, View view)
  488. {
  489. ThotBool created = CreateDocInfoDlgWX (BaseDialog + DocInfoForm,
  490. TtaGetViewFrame (document, view), document);
  491. if (created)
  492. {
  493. TtaSetDialoguePosition ();
  494. TtaShowDialogue (BaseDialog + DocInfoForm, FALSE, TRUE);
  495. /* wait for an answer */
  496. TtaWaitShowDialogue ();
  497. }
  498. }
  499. /*----------------------------------------------------------------------
  500. IsDocumentLoaded returns the document identification if the
  501. corresponding document is already loaded or 0.
  502. ----------------------------------------------------------------------*/
  503. Document IsDocumentLoaded (const char *documentURL, const char *form_data)
  504. {
  505. int i;
  506. ThotBool found;
  507. if (!documentURL)
  508. return ((Document) None);
  509. i = 1;
  510. found = FALSE;
  511. /* look for the URL into the list of downloaded documents */
  512. while (!found && i < DocumentTableLength)
  513. {
  514. if (DocumentURLs[i] && DocumentTypes[i] != docTemplate && DocumentMeta[i])
  515. {
  516. /* compare the url */
  517. found = (!strcmp (documentURL, DocumentURLs[i]) ||
  518. (DocumentMeta[i]->initial_url &&
  519. !strcmp (documentURL, DocumentMeta[i]->initial_url)));
  520. /* compare the form_data */
  521. if (found && (!((!form_data && !DocumentMeta[i]->form_data) ||
  522. (form_data && DocumentMeta[i]->form_data &&
  523. !strcmp (form_data, DocumentMeta[i]->form_data)))))
  524. found = FALSE;
  525. }
  526. if (!found)
  527. i++;
  528. }
  529. if (found)
  530. {
  531. /* document is found */
  532. UpdateEditorMenus ((Document) i);
  533. return ((Document) i);
  534. }
  535. else
  536. /* document is not found */
  537. return ((Document) None);
  538. }
  539. /*----------------------------------------------------------------------
  540. ExtractParameters extract parameters from document nane.
  541. ----------------------------------------------------------------------*/
  542. void ExtractParameters (char *aName, char *parameters)
  543. {
  544. long int lg, i;
  545. char *ptr;
  546. char *oldptr;
  547. if (!parameters || !aName)
  548. /* bad parameters */
  549. return;
  550. parameters[0] = EOS;
  551. lg = strlen (aName);
  552. if (lg)
  553. {
  554. /* the name is not empty */
  555. oldptr = ptr = &aName[0];
  556. do
  557. {
  558. ptr = strrchr (oldptr, '?');
  559. if (ptr)
  560. oldptr = &ptr[1];
  561. }
  562. while (ptr);
  563. i = (long int) (oldptr) - (long int) (aName); /* name length */
  564. if (i > 1)
  565. {
  566. aName[i - 1] = EOS;
  567. if (i != lg)
  568. strcpy (parameters, oldptr);
  569. }
  570. }
  571. }
  572. /*----------------------------------------------------------------------
  573. FileExistTarget
  574. Removes the URL target separator ('#') before verifying if a file
  575. exists.
  576. ----------------------------------------------------------------------*/
  577. static ThotBool FileExistTarget (char *filename)
  578. {
  579. char *ptr;
  580. ThotBool result;
  581. ptr = strrchr (filename, '#');
  582. if (ptr)
  583. *ptr = EOS;
  584. result = TtaFileExist(filename);
  585. if (ptr)
  586. *ptr = '#';
  587. return result;
  588. }
  589. /*----------------------------------------------------------------------
  590. SetArrowButton
  591. Change the appearance of the Back (if back == TRUE) or Forward button
  592. for a given document.
  593. ----------------------------------------------------------------------*/
  594. void SetArrowButton (Document doc, ThotBool back, ThotBool on)
  595. {
  596. ThotBool state;
  597. if (back)
  598. {
  599. if (on)
  600. {
  601. state = TRUE;
  602. TtaSetItemOn (doc, 1, File, BBack);
  603. if (DocumentSource[doc])
  604. /* update the document source too */
  605. TtaSetItemOn (DocumentSource[doc], 1, File, BBack);
  606. }
  607. else
  608. {
  609. state = FALSE;
  610. TtaSetItemOff (doc, 1, File, BBack);
  611. if (DocumentSource[doc])
  612. /* update the document source too */
  613. TtaSetItemOff (DocumentSource[doc], 1, File, BBack);
  614. }
  615. }
  616. else
  617. {
  618. if (on)
  619. {
  620. state = TRUE;
  621. TtaSetItemOn (doc, 1, File, BForward);
  622. if (DocumentSource[doc])
  623. /* update the document source too */
  624. TtaSetItemOn (DocumentSource[doc], 1, File, BForward);
  625. }
  626. else
  627. {
  628. state = FALSE;
  629. TtaSetItemOff (doc, 1, File, BForward);
  630. if (DocumentSource[doc])
  631. /* update the document source too */
  632. TtaSetItemOff (DocumentSource[doc], 1, File, BForward);
  633. }
  634. }
  635. }
  636. /*----------------------------------------------------------------------
  637. ResetStop resets the stop button state
  638. ----------------------------------------------------------------------*/
  639. void ResetStop (Document document)
  640. {
  641. if (document)
  642. {
  643. if (FilesLoading[document] != 0)
  644. FilesLoading[document]--;
  645. if (FilesLoading[document] == 0)
  646. /* The last object associated to the document has been loaded */
  647. {
  648. if (TtaGetViewFrame (document, 1) != 0)
  649. /* this document is displayed */
  650. {
  651. if(!(DocNetworkStatus[document] & AMAYA_NET_ERROR) &&
  652. (DocNetworkStatus[document] & AMAYA_NET_ACTIVE))
  653. /* if there was no error message, display the LOADED message */
  654. TtaSetStatus (document, 1,
  655. TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
  656. TtaEnableAction(document, "StopTransfer", FALSE);
  657. }
  658. DocNetworkStatus[document] = AMAYA_NET_INACTIVE;
  659. }
  660. }
  661. }
  662. /*----------------------------------------------------------------------
  663. ActiveTransfer initialize the current transfer
  664. ----------------------------------------------------------------------*/
  665. void ActiveTransfer (Document document)
  666. {
  667. if (document)
  668. {
  669. DocNetworkStatus[document] = AMAYA_NET_ACTIVE;
  670. FilesLoading[document] = 1;
  671. if (TtaGetViewFrame (document, 1) != 0)
  672. /* this document is displayed */
  673. TtaEnableAction(document, "StopTransfer", TRUE);
  674. }
  675. }
  676. /*----------------------------------------------------------------------
  677. SetStopButton Activates the stop button if it's turned off
  678. ----------------------------------------------------------------------*/
  679. void SetStopButton (Document document)
  680. {
  681. if (document)
  682. {
  683. if (document != DocBook)
  684. {
  685. if (DocNetworkStatus[document] != AMAYA_NET_ACTIVE)
  686. DocNetworkStatus[document] = AMAYA_NET_ACTIVE;
  687. if (FilesLoading[document] == 0)
  688. FilesLoading[document] = 1;
  689. }
  690. if (TtaGetViewFrame (document, 1) != 0)
  691. TtaEnableAction(document, "StopTransfer", TRUE);
  692. }
  693. }
  694. /*----------------------------------------------------------------------
  695. SetFormReadWrite
  696. Set ReadWrite access to input elements
  697. ----------------------------------------------------------------------*/
  698. static void SetFormReadWrite (Element el, Document doc)
  699. {
  700. ElementType elType;
  701. Element child, next;
  702. while (el)
  703. {
  704. /* look at all elements within this form */
  705. elType = TtaGetElementType (el);
  706. child = TtaGetFirstChild (el);
  707. next = el;
  708. TtaNextSibling (&next);
  709. switch (elType.ElTypeNum)
  710. {
  711. case HTML_EL_Input:
  712. case HTML_EL_Text_Input:
  713. case HTML_EL_Password_Input:
  714. case HTML_EL_File_Input:
  715. case HTML_EL_Option:
  716. case HTML_EL_Text_Area: /* it's a Text_Area */
  717. TtaSetAccessRight (child, ReadWrite, doc);
  718. child = NULL;
  719. break;
  720. default:
  721. break;
  722. }
  723. if (child != NULL)
  724. SetFormReadWrite (child, doc);
  725. el = next;
  726. }
  727. }
  728. /*----------------------------------------------------------------------
  729. Update the save button and the corresponding menu entry according to the
  730. document status.
  731. ----------------------------------------------------------------------*/
  732. void DocStatusUpdate (Document doc, ThotBool modified)
  733. {
  734. Document otherDoc, idoc;
  735. ThotBool noDocumentModified;
  736. if (modified && TtaGetDocumentAccessMode (doc))
  737. /* the document has been modified and is not in Read-Only mode */
  738. {
  739. TtaSetItemOn (doc, 1, File, BSave);
  740. // update all document status
  741. for (idoc = 1; idoc < DocumentTableLength; idoc++)
  742. TtaSetItemOn (idoc, 1, File, BSaveAll);
  743. #ifdef _JAVA
  744. StopJavascript (doc);
  745. #endif /* _JAVA */
  746. /* if we have a pair source/structured document allow synchronization */
  747. otherDoc = DocumentSource[doc];
  748. if (!otherDoc)
  749. otherDoc = GetDocFromSource (doc);
  750. if (otherDoc)
  751. {
  752. TtaSetItemOn (doc, 1, File, BSynchro);
  753. TtaSetItemOn (otherDoc, 1, File, BSynchro);
  754. }
  755. else if (DocumentTypes[doc] == docCSS)
  756. TtaSetItemOn (doc, 1, File, BSynchro);
  757. }
  758. else
  759. /* the document is no longer modified */
  760. {
  761. noDocumentModified = TRUE;
  762. for (idoc = 1; noDocumentModified && idoc < DocumentTableLength; idoc++)
  763. {
  764. if (TtaIsDocumentModified (idoc) && idoc != doc)
  765. noDocumentModified = FALSE;
  766. }
  767. TtaSetItemOff (doc, 1, File, BSave);
  768. if (noDocumentModified)
  769. // update all document status
  770. for (idoc = 1; noDocumentModified && idoc < DocumentTableLength; idoc++)
  771. TtaSetItemOff (idoc, 1, File, BSaveAll);
  772. if (TtaIsDocumentUpdated (doc))
  773. {
  774. /* if we have a pair source/structured document allow synchronization */
  775. otherDoc = DocumentSource[doc];
  776. if (!otherDoc)
  777. otherDoc = GetDocFromSource (doc);
  778. if (otherDoc)
  779. {
  780. TtaSetItemOn (doc, 1, File, BSynchro);
  781. TtaSetItemOn (otherDoc, 1, File, BSynchro);
  782. }
  783. else if (DocumentTypes[doc] == docCSS)
  784. TtaSetItemOn (doc, 1, File, BSynchro);
  785. }
  786. else
  787. {
  788. /* if we have a pair source/structured document allow synchronization */
  789. otherDoc = DocumentSource[doc];
  790. if (!otherDoc)
  791. otherDoc = GetDocFromSource (doc);
  792. if (otherDoc)
  793. {
  794. TtaSetItemOff (doc, 1, File, BSynchro);
  795. TtaSetItemOff (otherDoc, 1, File, BSynchro);
  796. }
  797. else if (DocumentTypes[doc] == docCSS)
  798. TtaSetItemOff (doc, 1, File, BSynchro);
  799. }
  800. }
  801. }
  802. /*----------------------------------------------------------------------
  803. SetCharsetMenuOff sets Off the charset menu in the current view.
  804. ----------------------------------------------------------------------*/
  805. static void SetCharsetMenuOff (Document doc, View view)
  806. {
  807. TtaSetItemOff (doc, view, File, BUTF_8);
  808. TtaSetItemOff (doc, view, File, BISO_8859_1);
  809. TtaSetItemOff (doc, view, File, BISO_8859_15);
  810. TtaSetItemOff (doc, view, File, BWINDOWS_1252);
  811. TtaSetItemOff (doc, view, File, BISO_8859_2);
  812. TtaSetItemOff (doc, view, File, BWINDOWS_1250);
  813. TtaSetItemOff (doc, view, File, BISO_8859_3);
  814. TtaSetItemOff (doc, view, File, BISO_8859_4);
  815. TtaSetItemOff (doc, view, File, BWINDOWS_1257);
  816. TtaSetItemOff (doc, view, File, BISO_8859_5);
  817. TtaSetItemOff (doc, view, File, BWINDOWS_1251);
  818. TtaSetItemOff (doc, view, File, BKOI8_R);
  819. TtaSetItemOff (doc, view, File, BISO_8859_6);
  820. TtaSetItemOff (doc, view, File, BWINDOWS_1256);
  821. TtaSetItemOff (doc, view, File, BISO_8859_7);
  822. TtaSetItemOff (doc, view, File, BWINDOWS_1253);
  823. TtaSetItemOff (doc, view, File, BISO_8859_8);
  824. TtaSetItemOff (doc, view, File, BWINDOWS_1255);
  825. TtaSetItemOff (doc, view, File, BISO_8859_9);
  826. TtaSetItemOff (doc, view, File, BWINDOWS_1254);
  827. TtaSetItemOff (doc, view, File, BGB_2312);
  828. TtaSetItemOff (doc, view, File, BISO_2022_JP);
  829. TtaSetItemOff (doc, view, File, BEUC_JP);
  830. TtaSetItemOff (doc, view, File, BSHIFT_JIS);
  831. }
  832. /*----------------------------------------------------------------------
  833. SetTableMenuOff sets Off the table menu in the current view.
  834. ----------------------------------------------------------------------*/
  835. void SetTableMenuOff (Document doc, View view)
  836. {
  837. TtaSetItemOff (doc, view, Types, BCaption);
  838. TtaSetItemOff (doc, view, Types, BTHead);
  839. TtaSetItemOff (doc, view, Types, BTBody);
  840. TtaSetItemOff (doc, view, Types, BTFoot);
  841. TtaSetItemOff (doc, view, Tools, BDataCell);
  842. TtaSetItemOff (doc, view, Tools, BHeadingCell);
  843. TtaSetItemOff (doc, view, Tools, BCellMerge);
  844. TtaSetItemOff (doc, view, Tools, BCellHExtend);
  845. TtaSetItemOff (doc, view, Tools, BCellVExtend);
  846. TtaSetItemOff (doc, view, Tools, BCellHShrink);
  847. TtaSetItemOff (doc, view, Tools, BCellVShrink);
  848. TtaSetItemOff (doc, view, Tools, BSelectRow);
  849. TtaSetItemOff (doc, view, Tools, BCreateRowB);
  850. TtaSetItemOff (doc, view, Tools, BCreateRowA);
  851. TtaSetItemOff (doc, view, Tools, BSelectColumn);
  852. TtaSetItemOff (doc, view, Tools, BCreateColumnB);
  853. TtaSetItemOff (doc, view, Tools, BCreateColumnA);
  854. TtaSetItemOff (doc, view, Tools, BPasteBefore);
  855. TtaSetItemOff (doc, view, Tools, BPasteAfter);
  856. }
  857. /*----------------------------------------------------------------------
  858. SetTableMenuOn sets On the table menu in the current view.
  859. ----------------------------------------------------------------------*/
  860. void SetTableMenuOn (Document doc, View view)
  861. {
  862. if (TableMenuActive)
  863. {
  864. /* a table element is selected */
  865. TtaSetItemOn (doc, view, Types, BCaption);
  866. TtaSetItemOn (doc, view, Types, BTHead);
  867. TtaSetItemOn (doc, view, Types, BTBody);
  868. TtaSetItemOn (doc, view, Types, BTFoot);
  869. TtaSetItemOn (doc, view, Tools, BDataCell);
  870. TtaSetItemOn (doc, view, Tools, BHeadingCell);
  871. }
  872. else
  873. {
  874. TtaSetItemOff (doc, view, Types, BCaption);
  875. TtaSetItemOff (doc, view, Types, BTHead);
  876. TtaSetItemOff (doc, view, Types, BTBody);
  877. TtaSetItemOff (doc, view, Types, BTFoot);
  878. TtaSetItemOff (doc, view, Tools, BDataCell);
  879. TtaSetItemOff (doc, view, Tools, BHeadingCell);
  880. }
  881. if (TableMenuActive || MTableMenuActive)
  882. {
  883. /* a table element is selected */
  884. TtaSetItemOn (doc, view, Tools, BCellMerge);
  885. TtaSetItemOn (doc, view, Tools, BCellHExtend);
  886. TtaSetItemOn (doc, view, Tools, BCellVExtend);
  887. TtaSetItemOn (doc, view, Tools, BCellHShrink);
  888. TtaSetItemOn (doc, view, Tools, BCellVShrink);
  889. TtaSetItemOn (doc, view, Tools, BSelectRow);
  890. TtaSetItemOn (doc, view, Tools, BCreateRowB);
  891. TtaSetItemOn (doc, view, Tools, BCreateRowA);
  892. TtaSetItemOn (doc, view, Tools, BSelectColumn);
  893. TtaSetItemOn (doc, view, Tools, BCreateColumnB);
  894. TtaSetItemOn (doc, view, Tools, BCreateColumnA);
  895. }
  896. else
  897. {
  898. TtaSetItemOff (doc, view, Tools, BCellMerge);
  899. TtaSetItemOff (doc, view, Tools, BCellHExtend);
  900. TtaSetItemOff (doc, view, Tools, BCellVExtend);
  901. TtaSetItemOff (doc, view, Tools, BCellHShrink);
  902. TtaSetItemOff (doc, view, Tools, BCellVShrink);
  903. TtaSetItemOff (doc, view, Tools, BSelectRow);
  904. TtaSetItemOff (doc, view, Tools, BCreateRowB);
  905. TtaSetItemOff (doc, view, Tools, BCreateRowA);
  906. TtaSetItemOff (doc, view, Tools, BSelectColumn);
  907. TtaSetItemOff (doc, view, Tools, BCreateColumnB);
  908. TtaSetItemOff (doc, view, Tools, BCreateColumnA);
  909. TtaSetItemOff (doc, view, Tools, BPasteBefore);
  910. TtaSetItemOff (doc, view, Tools, BPasteAfter);
  911. }
  912. }
  913. /*----------------------------------------------------------------------
  914. UpdateEditorMenus
  915. Update windows menus for the Editor mode
  916. ----------------------------------------------------------------------*/
  917. void UpdateEditorMenus (Document doc)
  918. {
  919. View view;
  920. int profile;
  921. ThotBool isXhtml11;
  922. if (DocumentTypes[doc] == docLog || DocumentTypes[doc] == docBookmark ||
  923. DocumentMeta[doc] == NULL || DocumentMeta[doc]->method == CE_HELP)
  924. return;
  925. // first get menu updates attached to the document profile
  926. TtaUpdateMenus (doc, 1, FALSE);
  927. profile = TtaGetDocumentProfile (doc);
  928. isXhtml11 = (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat &&
  929. profile != L_Strict && profile != L_Basic);
  930. if (DocumentTypes[doc] == docCSS || DocumentTypes[doc] == docText ||
  931. DocumentTypes[doc] == docImage)
  932. TtaSetItemOff (doc, 1, Style, BShowAppliedStyle);
  933. else
  934. TtaSetItemOn (doc, 1, Style, BShowAppliedStyle);
  935. /* update specific menu entries */
  936. if (DocumentTypes[doc] == docHTML)
  937. TtaSetMenuOn (doc, 1, Types);
  938. /* Update the doctype menu */
  939. UpdateDoctypeMenu (doc);
  940. UpdateTemplateMenus (doc);
  941. if (DocumentTypes[doc] == docCSS || DocumentTypes[doc] == docSource ||
  942. DocumentTypes[doc] == docText || DocumentTypes[doc] == docImage)
  943. {
  944. TtaSetMenuOff (doc, 1, Types);
  945. TtaSetMenuOff (doc, 1, Tools);
  946. TtaSetMenuOff (doc, 1, Links);
  947. TtaSetItemOff (doc, 1, Views, TShowMapAreas);
  948. TtaSetItemOff (doc, 1, Views, TShowTargets);
  949. TtaSetItemOff (doc, 1, Views, BShowSource);
  950. if (DocumentTypes[doc] != docSource)
  951. {
  952. TtaSetItemOff (doc, 1, Views, BShowStructure);
  953. TtaSetItemOff (doc, 1, Views, BShowFormatted);
  954. TtaSetItemOff (doc, 1, Views, BShowLinks);
  955. TtaSetItemOff (doc, 1, Views, BShowAlternate);
  956. TtaSetItemOff (doc, 1, Views, BShowToC);
  957. TtaSetItemOff (doc, 1, Views, TSplitHorizontally);
  958. TtaSetItemOff (doc, 1, Views, TSplitVertically);
  959. }
  960. TtaSetMenuOff (doc, 1, Style);
  961. }
  962. else
  963. {
  964. TtaSetItemOn (doc, 1, Views, TShowTargets);
  965. TtaSetItemOn (doc, 1, Views, BShowSource);
  966. TtaSetItemOn (doc, 1, Views, BShowStructure);
  967. TtaSetItemOn (doc, 1, Views, BShowFormatted);
  968. TtaSetItemOn (doc, 1, Views, TSplitHorizontally);
  969. TtaSetItemOn (doc, 1, Views, TSplitVertically);
  970. if (DocumentTypes[doc] == docXml || DocumentTypes[doc] == docTemplate)
  971. {
  972. TtaSetItemOff (doc, 1, Views, BShowAlternate);
  973. TtaSetItemOff (doc, 1, Views, BShowToC);
  974. //TtaSetMenuOff (doc, 1, Style);
  975. }
  976. else if (DocumentTypes[doc] == docHTML)
  977. {
  978. TtaSetItemOn (doc, 1, Views, TShowMapAreas);
  979. TtaSetItemOn (doc, 1, Views, BShowLinks);
  980. TtaSetItemOn (doc, 1, Views, BShowAlternate);
  981. TtaSetItemOn (doc, 1, Views, BShowToC);
  982. /* structure information is active only in the structure view */
  983. if (profile == L_Basic)
  984. {
  985. TtaSetItemOff (doc, 1, Types, BStyle);
  986. TtaSetItemOff (doc, 1, Types, BScript);
  987. TtaSetItemOff (doc, 1, Types, BNoScript);
  988. }
  989. else
  990. {
  991. TtaSetItemOn (doc, 1, Types, BStyle);
  992. TtaSetItemOn (doc, 1, Types, BScript);
  993. TtaSetItemOn (doc, 1, Types, BNoScript);
  994. }
  995. /* invalid all table edits as long as the selection is out of a table */
  996. if (TtaIsDocumentSelected (doc))
  997. SetTableMenuOn (doc, 1);
  998. else
  999. SetTableMenuOff (doc, 1);
  1000. if (IsXMLDocType (doc))
  1001. {
  1002. TtaSetItemOn (doc, 1, Tools, BSpellCheck);
  1003. TtaSetMenuOn (doc, 1, Style);
  1004. if (DocumentTypes[doc] == docMath)
  1005. TtaSetItemOn (doc, 1, Tools, BTransform);
  1006. else
  1007. {
  1008. if (DocumentTypes[doc] == docHTML)
  1009. TtaSetItemOn (doc, 1, Tools, BTransform);
  1010. TtaSetMenuOn (doc, 1, Types);
  1011. TtaSetMenuOn (doc, 1, Links);
  1012. }
  1013. view = TtaGetViewFromName (doc, "Structure_view");
  1014. if (view != 0 && TtaIsViewOpen (doc, view))
  1015. {
  1016. /* update specific menu entries */
  1017. TtaSetItemOn (doc, view, Edit_, BCut);
  1018. TtaSetItemOn (doc, view, Edit_, BPaste);
  1019. TtaSetItemOn (doc, view, Edit_, BClear);
  1020. TtaSetItemOn (doc, view, Tools, BSpellCheck);
  1021. TtaSetItemOn (doc, view, Tools, BTransform);
  1022. if (DocumentTypes[doc] != docMath)
  1023. TtaSetMenuOn (doc, view, Types);
  1024. }
  1025. view = TtaGetViewFromName (doc, "Alternate_view");
  1026. if (view != 0 && TtaIsViewOpen (doc, view))
  1027. {
  1028. /* update specific menu entries */
  1029. TtaSetItemOn (doc, view, Edit_, BCut);
  1030. TtaSetItemOn (doc, view, Edit_, BPaste);
  1031. TtaSetItemOn (doc, view, Edit_, BClear);
  1032. TtaSetItemOn (doc, view, Tools, BSpellCheck);
  1033. }
  1034. view = TtaGetViewFromName (doc, "Links_view");
  1035. if (view != 0 && TtaIsViewOpen (doc, view))
  1036. {
  1037. /* update specific menu entries */
  1038. TtaSetItemOn (doc, view, Edit_, BCut);
  1039. TtaSetItemOn (doc, view, Edit_, BPaste);
  1040. TtaSetItemOn (doc, view, Edit_, BClear);
  1041. TtaSetItemOn (doc, view, Tools, BSpellCheck);
  1042. TtaSetItemOn (doc, view, Tools, BTransform);
  1043. if (DocumentTypes[doc] != docMath)
  1044. TtaSetMenuOn (doc, view, Types);
  1045. }
  1046. view = TtaGetViewFromName (doc, "Table_of_contents");
  1047. if (view != 0 && TtaIsViewOpen (doc, view))
  1048. {
  1049. /* update specific menu entries */
  1050. TtaSetItemOn (doc, view, Edit_, BCut);
  1051. TtaSetItemOn (doc, view, Edit_, BPaste);
  1052. TtaSetItemOn (doc, view, Edit_, BClear);
  1053. TtaSetItemOn (doc, view, Tools, BSpellCheck);
  1054. TtaSetItemOn (doc, view, Tools, BTransform);
  1055. }
  1056. }
  1057. }
  1058. else if (TtaIsDocumentSelected (doc))
  1059. SetTableMenuOn (doc, 1);
  1060. }
  1061. #ifdef _JAVA
  1062. /* Update the javascript menus */
  1063. UpdateJavascriptMenus ();
  1064. #endif /* _JAVA */
  1065. // Is it an annotation ?
  1066. if (DocumentTypes[doc] == docAnnot)
  1067. {
  1068. TtaSetItemOn (doc, 1, Tools, BDeleteAnnot);
  1069. TtaSetItemOn (doc, 1, Tools, BReplyToAnnotation);
  1070. TtaSetItemOn (doc, 1, Tools, BPostAnnot);
  1071. }
  1072. else
  1073. {
  1074. TtaSetItemOff (doc, 1, Tools, BDeleteAnnot);
  1075. TtaSetItemOff (doc, 1, Tools, BReplyToAnnotation);
  1076. TtaSetItemOff (doc, 1, Tools, BPostAnnot);
  1077. }
  1078. TtaRefreshTopMenuStats (doc, -1);
  1079. }
  1080. /*----------------------------------------------------------------------
  1081. StartACopyCommand says that a new copy command starts
  1082. ----------------------------------------------------------------------*/
  1083. void StartACopyCommand (Document doc, View view)
  1084. {
  1085. #ifdef _SVG
  1086. ClearSVGDefs ();
  1087. #endif /* _SVG */
  1088. }
  1089. /*----------------------------------------------------------------------
  1090. ShowLogFile
  1091. Show error messages generated by the parser.
  1092. -----------------------------------------------------------------------*/
  1093. void ShowLogFile (Document doc, View view)
  1094. {
  1095. char fileName[500];
  1096. int newdoc, d;
  1097. // prevent multiple open
  1098. if (CriticLogError)
  1099. return;
  1100. CriticLogError = TRUE;
  1101. if (DocumentTypes[doc] == docSource)
  1102. doc = GetDocFromSource (doc);
  1103. if (doc)
  1104. {
  1105. sprintf (fileName, "%s%c%d%cPARSING.ERR",
  1106. TempFileDirectory, DIR_SEP, doc, DIR_SEP);
  1107. // check if the log file is already open
  1108. for (d = 1; d < MAX_DOCUMENTS; d++)
  1109. {
  1110. if (DocumentURLs[d] && !strcmp (DocumentURLs[d], fileName))
  1111. {
  1112. CriticLogError = FALSE;
  1113. return;
  1114. }
  1115. }
  1116. newdoc = GetAmayaDoc (fileName, NULL, 0, doc, CE_LOG, FALSE,
  1117. NULL, NULL);
  1118. /* store the relation with the original document */
  1119. if (newdoc)
  1120. {
  1121. DocumentSource[newdoc] = doc;
  1122. TtaSetStatus (newdoc, 1, " ", NULL);
  1123. }
  1124. }
  1125. CriticLogError = FALSE;
  1126. }
  1127. /*----------------------------------------------------------------------
  1128. MenuShowLogFile
  1129. Show error messages generated by the parser.
  1130. -----------------------------------------------------------------------*/
  1131. void MenuShowLogFile (Document doc, View view)
  1132. {
  1133. ShowLogFile (doc, view);
  1134. }
  1135. /*----------------------------------------------------------------------
  1136. OpenParsingErrors
  1137. ----------------------------------------------------------------------*/
  1138. ThotBool OpenParsingErrors (Document document)
  1139. {
  1140. char fileName[200];
  1141. if (document == 0 || DocumentTypes[document] == docFree)
  1142. return FALSE;
  1143. sprintf (fileName, "%s%c%d%cPARSING.ERR",
  1144. TempFileDirectory, DIR_SEP, document, DIR_SEP);
  1145. /* check what error file is open */
  1146. if (DocumentTypes[document] == docCSS)
  1147. {
  1148. CSSErrFile = TtaWriteOpen (fileName);
  1149. if ((CSSErrFile == NULL))
  1150. return FALSE;
  1151. else
  1152. fprintf (CSSErrFile, TtaGetMessage (AMAYA, AM_LINK_LINE));
  1153. }
  1154. else
  1155. {
  1156. ErrFile = TtaWriteOpen (fileName);
  1157. if ((ErrFile == NULL))
  1158. return FALSE;
  1159. else
  1160. fprintf (ErrFile, TtaGetMessage (AMAYA, AM_LINK_LINE));
  1161. }
  1162. return TRUE;
  1163. }
  1164. /*----------------------------------------------------------------------
  1165. RemoveParsingErrors
  1166. ----------------------------------------------------------------------*/
  1167. void RemoveParsingErrors (Document document)
  1168. {
  1169. char htmlErrFile[200];
  1170. sprintf (htmlErrFile, "%s%c%d%cPARSING.ERR",
  1171. TempFileDirectory, DIR_SEP, document, DIR_SEP);
  1172. if (TtaFileExist (htmlErrFile))
  1173. TtaFileUnlink (htmlErrFile);
  1174. }
  1175. /*----------------------------------------------------------------------
  1176. HasParsingErrors
  1177. ----------------------------------------------------------------------*/
  1178. ThotBool HasParsingErrors (Document document)
  1179. {
  1180. char htmlErrFile[200];
  1181. sprintf (htmlErrFile, "%s%c%d%cPARSING.ERR",
  1182. TempFileDirectory, DIR_SEP, document, DIR_SEP);
  1183. return TtaFileExist (htmlErrFile);
  1184. }
  1185. /*----------------------------------------------------------------------
  1186. CleanUpParsingErrors
  1187. Initialize the 'PARSING.ERR' file and the related global variables
  1188. ----------------------------------------------------------------------*/
  1189. void CleanUpParsingErrors ()
  1190. {
  1191. HTMLErrorsFound = FALSE;
  1192. XMLErrorsFound = FALSE;
  1193. CSSErrorsFound = FALSE;
  1194. XMLErrorsFoundInProfile = FALSE;
  1195. XMLNotWellFormed = FALSE;
  1196. XMLInvalidToken = FALSE;
  1197. XMLUnknownEncoding = FALSE;
  1198. XMLCharacterNotSupported = FALSE;
  1199. /* close the error file */
  1200. if (ErrFile)
  1201. {
  1202. TtaWriteClose (ErrFile);
  1203. ErrFile = NULL;
  1204. }
  1205. }
  1206. /*----------------------------------------------------------------------
  1207. UpdateLogFile enables/disables the logerror button and the menu entry
  1208. ----------------------------------------------------------------------*/
  1209. void UpdateLogFile (Document doc, ThotBool enable)
  1210. {
  1211. if (doc == 0 || DocumentTypes[doc] == docLog ||
  1212. (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_HELP))
  1213. return;
  1214. TtaToggleLogError (doc, enable);
  1215. if (enable)
  1216. TtaSetItemOn (doc, 1, Views, BShowLogFile);
  1217. else
  1218. TtaSetItemOff (doc, 1, Views, BShowLogFile);
  1219. if (DocumentSource[doc])
  1220. {
  1221. /* update the document source too */
  1222. if (enable)
  1223. TtaSetItemOn (DocumentSource[doc], 1, Views, BShowLogFile);
  1224. else
  1225. TtaSetItemOff (DocumentSource[doc], 1, Views, BShowLogFile);
  1226. }
  1227. }
  1228. /*----------------------------------------------------------------------
  1229. UpdateShowError the logerror button and the menu entry
  1230. ----------------------------------------------------------------------*/
  1231. void UpdateShowError (Document doc, View view)
  1232. {
  1233. char fileName[500];
  1234. if (DocumentTypes[doc] == docSource)
  1235. doc = GetDocFromSource (doc);
  1236. if (doc)
  1237. {
  1238. sprintf (fileName, "%s%c%d%cPARSING.ERR",
  1239. TempFileDirectory, DIR_SEP, doc, DIR_SEP);
  1240. if (TtaFileExist (fileName))
  1241. UpdateLogFile (doc, TRUE);
  1242. else
  1243. UpdateLogFile (doc, FALSE);
  1244. }
  1245. }
  1246. /*----------------------------------------------------------------------
  1247. CheckParsingErrors
  1248. Checks the errors during the parsing of the document and active
  1249. (or not) the Show Log File menu entry
  1250. ----------------------------------------------------------------------*/
  1251. void CheckParsingErrors (Document doc)
  1252. {
  1253. char *ptr;
  1254. char fileName[200];
  1255. char text [200];
  1256. ThotBool closeLog = FALSE;
  1257. ThotBool retry = FALSE;
  1258. // Avoid recursive call
  1259. if (CriticCheckError)
  1260. return;
  1261. CriticCheckError = TRUE;
  1262. CloseLogs (doc);
  1263. closeLog = TRUE;
  1264. #ifdef _JAVA
  1265. /* The document contains error : switch OFF the Javascipt/DOM */
  1266. if(BADMimeType || ErrFile)
  1267. StopJavascript(doc);
  1268. #endif /* _JAVA */
  1269. if (BADMimeType)
  1270. {
  1271. /* the mime type doesn't match the doctype */
  1272. InitConfirm (doc, 1, TtaGetMessage (AMAYA, AM_INVALID_MIMETYPE));
  1273. BADMimeType = FALSE;
  1274. }
  1275. if (ErrFile)
  1276. {
  1277. /* Activate the menu entry */
  1278. UpdateLogFile (doc, TRUE);
  1279. if (XMLCharacterNotSupported || XMLInvalidToken)
  1280. {
  1281. /* Invalid characters */
  1282. if (XMLInvalidToken)
  1283. ptr = TtaGetMessage (AMAYA, AM_XML_CHARACTER_RETRY);
  1284. else
  1285. ptr = TtaGetMessage (AMAYA, AM_XML_CHARACTER_ERROR);
  1286. InitConfirm3L (doc, 1,
  1287. TtaGetMessage (AMAYA, AM_XML_CHARACTER_ERROR),
  1288. TtaGetMessage (AMAYA, AM_XML_CHARACTER_RETRY),
  1289. NULL, FALSE);
  1290. CleanUpParsingErrors ();
  1291. }
  1292. else if (XMLNotWellFormed)
  1293. /* not a well-formed XML document */
  1294. {
  1295. /* If it's a XHTML document, try to read it again, but as plain HTML*/
  1296. retry = FALSE;
  1297. if (DocumentTypes[doc] == docHTML)
  1298. /* it's a XHTML document */
  1299. {
  1300. if (!DocumentMeta[doc] || !DocumentMeta[doc]->compound)
  1301. /* we have not yet encountered any MathML or SVG element in the
  1302. document */
  1303. {
  1304. /* have we already met some namespace declarations with
  1305. prefixes ? The HTML parser cannot handle prefixed tag
  1306. names */
  1307. if (!TtaDocumentUsesNsPrefixes(doc))
  1308. retry = TRUE;
  1309. }
  1310. }
  1311. if (retry)
  1312. {
  1313. ptr = TtaGetMessage (AMAYA, AM_XML_RETRY);
  1314. // save the original log file
  1315. sprintf (fileName, "%s%c%d%cPARSING.ERR",
  1316. TempFileDirectory, DIR_SEP, doc, DIR_SEP);
  1317. strcpy (text, fileName);
  1318. strcat (text, ".org");
  1319. CleanUpParsingErrors ();
  1320. CloseLogs (doc);
  1321. TtaFileUnlink (text);
  1322. TtaFileRename (fileName, text);
  1323. ParseAsHTML (doc, 1);
  1324. // reset XML format for future saving
  1325. DocumentMeta[doc]->xmlformat = TRUE;
  1326. // restore the original log file
  1327. CleanUpParsingErrors ();
  1328. CloseLogs (doc);
  1329. TtaFileUnlink (fileName);
  1330. TtaFileRename (text, fileName);
  1331. closeLog = TRUE;
  1332. if (SavingDocument && SavingDocument == DocumentSource[doc])
  1333. {
  1334. ConfirmError (doc, 1, ptr,
  1335. TtaGetMessage (AMAYA, AM_SAVE_ANYWAY),
  1336. NULL);
  1337. if (!ExtraChoice && !UserAnswer)
  1338. // GTK or WX version: stop the save process
  1339. SavingDocument = 0;
  1340. }
  1341. else
  1342. {
  1343. //InitConfirm3L (doc, 1, ptr, NULL, NULL, FALSE);
  1344. ConfirmError (doc, 1, ptr,
  1345. TtaGetMessage (AMAYA, AM_AFILTER_SHOW),
  1346. NULL);
  1347. if (ExtraChoice || UserAnswer)
  1348. {
  1349. ShowSource (doc, 1);
  1350. // GTK or WX version: show errors
  1351. ShowLogFile (doc, 1);
  1352. }
  1353. }
  1354. }
  1355. else
  1356. // we can't rescue the document
  1357. {
  1358. ptr = TtaGetMessage (AMAYA, AM_XML_ERROR);
  1359. if (SavingDocument == DocumentSource[doc])
  1360. // stop the save process
  1361. SavingDocument = 0;
  1362. // Set the document in read-only mode
  1363. TtaSetDocumentAccessMode (doc, 0);
  1364. ConfirmError (doc, 1, ptr,
  1365. TtaGetMessage (AMAYA, AM_AFILTER_SHOW),
  1366. NULL);
  1367. if (ExtraChoice || UserAnswer)
  1368. {
  1369. // GTK or WX version: show errors
  1370. CleanUpParsingErrors ();
  1371. CloseLogs (doc);
  1372. closeLog = TRUE;
  1373. ShowLogFile (doc, 1);
  1374. ShowSource (doc, 1);
  1375. }
  1376. }
  1377. }
  1378. CleanUpParsingErrors ();
  1379. if (!closeLog)
  1380. {
  1381. CloseLogs (doc);
  1382. UpdateLogFile (doc, TRUE);
  1383. }
  1384. }
  1385. else
  1386. {
  1387. // no log file
  1388. CloseLogs (doc);
  1389. UpdateLogFile (doc, FALSE);
  1390. }
  1391. CriticCheckError = FALSE;
  1392. }
  1393. /*----------------------------------------------------------------------
  1394. UpdateTransfer updates the status of the current transfer
  1395. ----------------------------------------------------------------------*/
  1396. void UpdateTransfer (Document document)
  1397. {
  1398. if (document)
  1399. FilesLoading[document]++;
  1400. }
  1401. /*----------------------------------------------------------------------
  1402. StopTransfer stops the current transfer
  1403. ----------------------------------------------------------------------*/
  1404. void StopTransfer (Document document, View view)
  1405. {
  1406. if (document == 0)
  1407. return;
  1408. else if (document ==

Large files files are truncated, but you can click here to view the full file