PageRenderTime 46ms CodeModel.GetById 19ms 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
  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 == DocBook)
  1409. {
  1410. /* Make Book function stopped */
  1411. DocBook = 0;
  1412. /* stop transfer of the sub-document */
  1413. StopRequest (document);
  1414. StopRequest (IncludedDocument);
  1415. FilesLoading[document] = 0;
  1416. DocNetworkStatus[document] = AMAYA_NET_INACTIVE;
  1417. }
  1418. else if (DocNetworkStatus[document] & AMAYA_NET_ACTIVE)
  1419. {
  1420. if (TtaGetViewFrame (document, 1) != 0)
  1421. TtaEnableAction(document, "StopTransfer", FALSE);
  1422. StopRequest (document);
  1423. FilesLoading[document] = 0;
  1424. DocNetworkStatus[document] = AMAYA_NET_INACTIVE;
  1425. TtaSetStatus (document, 1,
  1426. TtaGetMessage (AMAYA, AM_LOAD_ABORT),
  1427. NULL);
  1428. }
  1429. }
  1430. /*----------------------------------------------------------------------
  1431. CompleteUrl
  1432. In case of a user typed url without protocol specification
  1433. and filepath like url (the ~ or / url beginning),
  1434. we add the http:// (more conveniant when you often type urls)
  1435. so that you can now enter w3.org directly in the url bar.
  1436. Return TRUE if the URL changed.
  1437. ----------------------------------------------------------------------*/
  1438. static ThotBool CompleteUrl(char **url)
  1439. {
  1440. char *s, *ptr;
  1441. if (IsFilePath (*url))
  1442. {
  1443. // remove file:
  1444. ptr = &((*(url))[5]);
  1445. s = (char *)TtaGetMemory (MAX_LENGTH);
  1446. s[0] = EOS;
  1447. *url = s;
  1448. #ifdef _WINDOWS
  1449. if (ptr[0] == '/' && ptr[1] == '/' && ptr[2] == '/')
  1450. ptr = &ptr[3];
  1451. else if (ptr[0] == '/' && ptr[1] == '/' && ptr[3] == ':')
  1452. ptr = &ptr[2];
  1453. if (ptr[1] != ':')
  1454. {
  1455. char *ptr2;
  1456. // add a default device
  1457. ptr2 = getenv ("HOMEDRIVE");
  1458. if (ptr2)
  1459. strcpy (s, ptr2);
  1460. else
  1461. strcpy (s, "c:");
  1462. s= &s[2];
  1463. }
  1464. #else /* _WINDOWS */
  1465. if (ptr[0] == '/' && ptr[1] == '/' && ptr[2] == '/')
  1466. ptr = &ptr[2];
  1467. #endif /* _WINDOWS */
  1468. while (*ptr != EOS)
  1469. {
  1470. if (*ptr == '/')
  1471. *s = DIR_SEP;
  1472. else
  1473. *s = *ptr;
  1474. s++;
  1475. ptr++;
  1476. }
  1477. *s = EOS;
  1478. return TRUE;
  1479. }
  1480. else if (**url != DIR_SEP
  1481. && **url != '~'
  1482. #ifdef _WINDOWS
  1483. && (*(url))[1] != ':'
  1484. #endif /* _WINDOWS */
  1485. && !IsW3Path (*url)
  1486. && (strlen (*url) + 8) < MAX_LENGTH)
  1487. {
  1488. if (!TtaFileExist(*url))
  1489. {
  1490. s = (char *)TtaGetMemory (MAX_LENGTH);
  1491. strcpy (s, "http://");
  1492. strcat (s, *url);
  1493. *url = s;
  1494. return TRUE;
  1495. }
  1496. }
  1497. return FALSE;
  1498. }
  1499. /*----------------------------------------------------------------------
  1500. TextURL
  1501. The Address text field in a document window has been modified by the user
  1502. Load the corresponding document in that window.
  1503. ----------------------------------------------------------------------*/
  1504. static void TextURL (Document doc, View view, char *text, intptr_t noreplace)
  1505. {
  1506. char *s = NULL;
  1507. char *url;
  1508. ThotBool change, updated;
  1509. updated = FALSE;
  1510. if (text && text[0] != EOS)
  1511. {
  1512. /* remove any trailing '\n' chars that may have gotten there
  1513. after a cut and paste */
  1514. change = RemoveNewLines (text);
  1515. if (IsW3Path (text))
  1516. url = text;
  1517. else
  1518. {
  1519. s = (char *)TtaGetMemory (MAX_LENGTH);
  1520. updated = CompleteUrl (&text);
  1521. change = NormalizeFile (text, s, AM_CONV_NONE);
  1522. if (updated)
  1523. /* free the allocated string */
  1524. TtaFreeMemory (text);
  1525. url = s;
  1526. }
  1527. if (DocumentTypes[doc] == docSource)
  1528. doc = GetDocFromSource (doc);
  1529. if (DocumentURLs[doc] && url &&
  1530. !strcmp (DocumentURLs[doc], url))
  1531. {
  1532. // nothing to do
  1533. TtaFreeMemory (s);
  1534. return;
  1535. }
  1536. if (noreplace != 0)
  1537. //ask the user choice
  1538. LoadDefaultOpeningLocation (FALSE);
  1539. else
  1540. DontReplaceOldDoc = FALSE;
  1541. if (!DontReplaceOldDoc && !CanReplaceCurrentDocument (doc, view))
  1542. {
  1543. /* restore the previous value @@ */
  1544. AddURLInCombobox (DocumentURLs[doc], NULL, FALSE);
  1545. TtaSetTextZone (doc, view, URL_list);
  1546. /* cannot load the new document */
  1547. TtaSetStatus (doc, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), url);
  1548. /* abort the command */
  1549. TtaFreeMemory (s);
  1550. return;
  1551. }
  1552. else
  1553. /* do the same thing as a callback form open document form */
  1554. CallbackDialogue (BaseDialog + URLName, STRING_DATA, url);
  1555. TtaFreeMemory (s);
  1556. NewFile = FALSE;
  1557. CurrentDocument = doc;
  1558. CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
  1559. }
  1560. }
  1561. /*----------------------------------------------------------------------
  1562. SetWindowTitle
  1563. Change the title of all windows (if view == 0) of document targetDoc
  1564. or only the title of the window associated with the specified view.
  1565. if it's not 0.
  1566. The new title is the content of the TITLE element of document sourceDoc.
  1567. If document sourceDoc does not have any TITLE element, nothing happen.
  1568. ----------------------------------------------------------------------*/
  1569. void SetWindowTitle (Document sourceDoc, Document targetDoc, View view)
  1570. {
  1571. ElementType elType;
  1572. Element root, title;
  1573. #ifdef _SVG
  1574. Element child;
  1575. #endif /* _SVG */
  1576. SSchema docSSchema;
  1577. title = NULL;
  1578. root = TtaGetRootElement (sourceDoc);
  1579. docSSchema = TtaGetDocumentSSchema (sourceDoc);
  1580. if (!strcmp (TtaGetSSchemaName (docSSchema), "HTML"))
  1581. /* sourceDoc is a HTML document */
  1582. {
  1583. /* search the Title element in sourceDoc */
  1584. elType.ElSSchema = docSSchema;
  1585. elType.ElTypeNum = HTML_EL_TITLE;
  1586. title = TtaSearchTypedElement (elType, SearchForward, root);
  1587. }
  1588. #ifdef _SVG
  1589. else if (!strcmp (TtaGetSSchemaName (docSSchema), "SVG"))
  1590. {
  1591. child = TtaGetFirstChild (root);
  1592. while (child && !title)
  1593. {
  1594. elType = TtaGetElementType (child);
  1595. if (elType.ElSSchema == docSSchema &&
  1596. elType.ElTypeNum == SVG_EL_title)
  1597. title = child;
  1598. else
  1599. TtaNextSibling (&child);
  1600. }
  1601. }
  1602. #endif /* _SVG */
  1603. if (title)
  1604. UpdateTitle (title, sourceDoc);
  1605. }
  1606. /*----------------------------------------------------------------------
  1607. InitFormAnswer
  1608. Dialogue form for answering text, user name and password
  1609. ----------------------------------------------------------------------*/
  1610. void InitFormAnswer (Document document, View view, const char *auth_realm,
  1611. char *server, int i_auth)
  1612. {
  1613. char name[MAX_LENGTH];
  1614. char passwd[MAX_LENGTH];
  1615. ThotBool created;
  1616. name[0] = EOS;
  1617. passwd[0] = EOS;
  1618. GetPasswordTable (i_auth, &name[0], &passwd[0]);
  1619. created = CreateAuthentDlgWX (BaseDialog + FormAnswer,
  1620. TtaGetViewFrame (document, view),
  1621. (char *)auth_realm, server, name, passwd);
  1622. if (created)
  1623. {
  1624. TtaSetDialoguePosition ();
  1625. TtaShowDialogue (BaseDialog + FormAnswer, FALSE, FALSE);
  1626. }
  1627. TtaWaitShowDialogue ();
  1628. }
  1629. /*----------------------------------------------------------------------
  1630. InitInfo
  1631. Displays a message box with the given info text
  1632. ----------------------------------------------------------------------*/
  1633. void InitInfo (const char *label, const char *info)
  1634. {
  1635. if (!info || *info == EOS)
  1636. return;
  1637. TtaDisplayMessage (CONFIRM, info, NULL);
  1638. }
  1639. /*----------------------------------------------------------------------
  1640. InitAlert
  1641. Displays a non-modal window for the "window.alert()" javascript function
  1642. ----------------------------------------------------------------------*/
  1643. void InitAlert(Document document, View view, char *label)
  1644. {
  1645. #ifdef _JAVA
  1646. char title[10];
  1647. ThotBool created;
  1648. strcpy(title, "Alert");
  1649. created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
  1650. TtaGetViewFrame (document, view),
  1651. title, NULL, NULL,
  1652. label, NULL, NULL);
  1653. if (created)
  1654. {
  1655. TtaSetDialoguePosition ();
  1656. TtaShowDialogue (BaseDialog + ConfirmForm, FALSE, TRUE);
  1657. /* wait for an answer */
  1658. TtaWaitShowDialogue ();
  1659. }
  1660. /* remove the critic section */
  1661. CriticConfirm = FALSE;
  1662. #endif /* _JAVA */
  1663. }
  1664. /*----------------------------------------------------------------------
  1665. ----------------------------------------------------------------------*/
  1666. void ConfirmError (Document document, View view, char *label,
  1667. char *extrabutton, char *confirmbutton)
  1668. {
  1669. ThotBool created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
  1670. TtaGetViewFrame (document, view),
  1671. NULL, extrabutton, confirmbutton,
  1672. label, NULL, NULL);
  1673. if (created)
  1674. {
  1675. TtaSetDialoguePosition ();
  1676. TtaShowDialogue (BaseDialog + ConfirmForm, FALSE, TRUE);
  1677. /* wait for an answer */
  1678. TtaWaitShowDialogue ();
  1679. }
  1680. /* remove the critic section */
  1681. CriticConfirm = FALSE;
  1682. }
  1683. /*----------------------------------------------------------------------
  1684. ----------------------------------------------------------------------*/
  1685. void ConfirmError3L (Document document, View view, char *label1, char *label2,
  1686. char *label3, char *extrabutton, char *confirmbutton)
  1687. {
  1688. ThotBool created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
  1689. TtaGetViewFrame (document, view),
  1690. NULL, extrabutton, confirmbutton,
  1691. label1, label2, label3);
  1692. if (created)
  1693. {
  1694. TtaSetDialoguePosition ();
  1695. TtaShowDialogue (BaseDialog + ConfirmForm, FALSE, TRUE);
  1696. /* wait for an answer */
  1697. TtaWaitShowDialogue ();
  1698. }
  1699. /* remove the critic section */
  1700. CriticConfirm = FALSE;
  1701. }
  1702. /*----------------------------------------------------------------------
  1703. ----------------------------------------------------------------------*/
  1704. void InitConfirm3L (Document document, View view, const char *label1, const char *label2,
  1705. const char *label3, ThotBool withCancel)
  1706. {
  1707. /* IV: This widget can't be called twice, but it happens when downloading a
  1708. document with protected images. This is a quick silution to avoid the
  1709. sigsev, although it doesn't fix the problem */
  1710. if (CriticConfirm)
  1711. return;
  1712. else
  1713. CriticConfirm = TRUE;
  1714. char *confirm = NULL;
  1715. if (withCancel)
  1716. confirm = TtaGetMessage (LIB, TMSG_LIB_CONFIRM);
  1717. ThotBool created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
  1718. TtaGetViewFrame (document, view),
  1719. NULL /* title */,
  1720. NULL /* extra */,
  1721. confirm,
  1722. label1, label2, label3);
  1723. if (created)
  1724. {
  1725. TtaSetDialoguePosition ();
  1726. TtaShowDialogue (BaseDialog + ConfirmForm, FALSE, TRUE);
  1727. /* wait for an answer */
  1728. TtaWaitShowDialogue ();
  1729. //if (AmayaIsAlive ())
  1730. // TtaDestroyDialogue (BaseDialog + ConfirmForm);
  1731. }
  1732. CriticConfirm = FALSE;
  1733. }
  1734. /*----------------------------------------------------------------------
  1735. ----------------------------------------------------------------------*/
  1736. void InitConfirm (Document document, View view, char *label)
  1737. {
  1738. /* Confirm form */
  1739. /* JK: This widget can't be called twice, but it happens when downloading a
  1740. document with protected images. This is a quick silution to avoid the
  1741. sigsev, although it doesn't fix the problem */
  1742. if (CriticConfirm)
  1743. return;
  1744. else
  1745. CriticConfirm = TRUE;
  1746. ThotBool created = CreateInitConfirmDlgWX (BaseDialog + ConfirmForm,
  1747. TtaGetViewFrame (document, view),
  1748. NULL /* title */,
  1749. NULL /* extra */,
  1750. TtaGetMessage (LIB, TMSG_LIB_CONFIRM),
  1751. label, NULL, NULL);
  1752. if (created)
  1753. {
  1754. TtaSetDialoguePosition ();
  1755. TtaShowDialogue (BaseDialog + ConfirmForm, FALSE, TRUE);
  1756. /* wait for an answer */
  1757. TtaWaitShowDialogue ();
  1758. }
  1759. /* remove the critic section */
  1760. CriticConfirm = FALSE;
  1761. }
  1762. /*----------------------------------------------------------------------
  1763. InitCharset
  1764. Asks the user for the charset of a given URL. Used when saving a
  1765. document with an unknown charset.
  1766. ----------------------------------------------------------------------*/
  1767. void InitCharset (Document document, View view, char *url)
  1768. {
  1769. }
  1770. /*----------------------------------------------------------------------
  1771. InitMimeType
  1772. Asks the user for the MIME type of a given URL. Used when saving a
  1773. document with an unknown MIME type.
  1774. ----------------------------------------------------------------------*/
  1775. void InitMimeType (Document document, View view, char *url, char *status)
  1776. {
  1777. const char *mimetypes_list;
  1778. int nbmimetypes;
  1779. if (DocumentTypes[document] == docImage)
  1780. {
  1781. mimetypes_list = "image/png\0"
  1782. "image/jpeg\0"
  1783. "image/gif\0"
  1784. "image/x-bitmap\0"
  1785. "image/x-xpicmap\0";
  1786. nbmimetypes = 5;
  1787. }
  1788. else if (DocumentTypes[document] == docSVG)
  1789. {
  1790. mimetypes_list = AM_SVG_MIME_TYPE"\0"
  1791. "application/xml\0"
  1792. "text/xml\0";
  1793. nbmimetypes = 4;
  1794. }
  1795. else if (DocumentTypes[document] == docMath)
  1796. {
  1797. mimetypes_list = AM_MATHML_MIME_TYPE"\0"
  1798. "application/xml\0"
  1799. "text/xml\0";
  1800. nbmimetypes = 3;
  1801. }
  1802. else if (DocumentTypes[document] == docHTML && DocumentMeta[document] &&
  1803. DocumentMeta[document]->xmlformat)
  1804. {
  1805. mimetypes_list = AM_XHTML_MIME_TYPE"\0"
  1806. "text/html\0"
  1807. "application/xml\0"
  1808. "text/xml\0";
  1809. nbmimetypes = 4;
  1810. }
  1811. else
  1812. {
  1813. mimetypes_list = "text/html\0"
  1814. AM_XHTML_MIME_TYPE"\0"
  1815. "application/xml\0"
  1816. "text/xml\0"
  1817. "text/plain\0"
  1818. "text/css\0"
  1819. "application/smil\0";
  1820. nbmimetypes = 7;
  1821. }
  1822. }
  1823. /*-------------------------------------------------------------------------
  1824. BrowserForm
  1825. Initializes a form that ask the URI of the opened or new created document.
  1826. -------------------------------------------------------------------------*/
  1827. static void BrowserForm (Document doc, View view, char *urlname)
  1828. {
  1829. }
  1830. /*----------------------------------------------------------------------
  1831. InitOpenDocForm initializes a form that ask the URI of the opened or
  1832. new created document.
  1833. The parameter name gives a proposed document name (New document).
  1834. The parameter title gives the title of the the form.
  1835. ----------------------------------------------------------------------*/
  1836. static void InitOpenDocForm (Document doc, View view, const char *name,
  1837. const char *title, DocumentType docType)
  1838. {
  1839. char s[MAX_LENGTH];
  1840. char *thotdir, *docdir;
  1841. ThotBool remote;
  1842. ThotBool created;
  1843. CurrentDocument = doc;
  1844. /* generate the right name and URI */
  1845. thotdir = TtaGetEnvString ("THOTDIR");
  1846. if (DocumentURLs[doc] && !strcmp (DocumentURLs[doc], "empty"))
  1847. {
  1848. strcpy (DocumentName, DocumentURLs[doc]);
  1849. strncpy (s, thotdir,MAX_LENGTH-1);
  1850. s[MAX_LENGTH-1] = EOS;
  1851. }
  1852. else
  1853. TtaExtractName (DocumentURLs[doc], s, DocumentName);
  1854. remote = IsW3Path (DocumentURLs[doc]);
  1855. if (remote)
  1856. {
  1857. if (name[0] != EOS)
  1858. {
  1859. strcpy (LastURLName, s);
  1860. strcat (LastURLName, URL_STR);
  1861. strcat (LastURLName, name);
  1862. }
  1863. else
  1864. strcpy (LastURLName, DocumentURLs[doc]);
  1865. strcpy (s, LastURLName);
  1866. }
  1867. else
  1868. {
  1869. /* check if it's the default Welcome page */
  1870. if (name[0] == EOS)
  1871. {
  1872. if (DocumentURLs[doc])
  1873. strcpy (s, DocumentURLs[doc]);
  1874. else
  1875. s[0] = EOS;
  1876. }
  1877. else
  1878. {
  1879. // Avoid to create new documents into Amaya space
  1880. if (!strncmp (s, thotdir, strlen (thotdir)))
  1881. {
  1882. docdir = TtaGetDocumentsDir();
  1883. strcpy (s, docdir);
  1884. }
  1885. strcpy (DirectoryName, s);
  1886. strcpy (DocumentName, name);
  1887. strcat (s, DIR_STR);
  1888. strcat (s, name);
  1889. }
  1890. strcpy (LastURLName, s);
  1891. }
  1892. /* here we pass also 'URL_list', because we want generate a combobox choice list */
  1893. created = CreateOpenDocDlgWX( BaseDialog + OpenForm,
  1894. TtaGetViewFrame (doc, view), title, URL_list, s,
  1895. docType, doc, NewFile );
  1896. if (created)
  1897. {
  1898. TtaSetDialoguePosition ();
  1899. TtaShowDialogue (BaseDialog + OpenForm, TRUE, TRUE);
  1900. }
  1901. }
  1902. /*----------------------------------------------------------------------
  1903. ----------------------------------------------------------------------*/
  1904. void OpenDoc (Document doc, View view)
  1905. {
  1906. NewFile = FALSE;
  1907. /* no specific type requested */
  1908. InitOpenDocForm (doc, view, "",
  1909. TtaGetMessage (LIB, TMSG_BUTTON_OPEN), docText);
  1910. }
  1911. /*----------------------------------------------------------------------
  1912. ----------------------------------------------------------------------*/
  1913. void OpenDocInNewWindow (Document document, View view)
  1914. {
  1915. NewFile = FALSE;
  1916. /* no specific type requested */
  1917. InitOpenDocForm (document, view, "",
  1918. TtaGetMessage (AMAYA, AM_OPEN_IN_NEW_WINDOW),
  1919. docText);
  1920. }
  1921. /*----------------------------------------------------------------------
  1922. OpenNew: create a new document
  1923. ----------------------------------------------------------------------*/
  1924. void OpenNew (Document document, View view, int docType, int docProfile)
  1925. {
  1926. char name[100];
  1927. char *s, *compound;
  1928. /* create a new document */
  1929. DontReplaceOldDoc = TRUE;
  1930. NewFile = TRUE;
  1931. NewDocType = docType;
  1932. NewDocProfile = docProfile;
  1933. NewXML = TRUE;
  1934. Answer_text[0] = EOS;
  1935. strcpy (name, TtaGetMessage (AMAYA, AM_NEW));
  1936. if (NewDocType == docHTML)
  1937. {
  1938. s = TtaGetEnvString ("XHTML_Profile");
  1939. compound = TtaGetMessage (AMAYA, AM_COMPOUND_DOCUMENT);
  1940. if (s && compound && !strcmp (s, compound))
  1941. strcat (name,".xml");
  1942. else
  1943. strcat (name,".html");
  1944. InitOpenDocForm (document, view, name,
  1945. TtaGetMessage (LIB, TMSG_BUTTON_NEW), docHTML);
  1946. /* will scan html documents */
  1947. strcpy (ScanFilter, "*.*htm*");
  1948. }
  1949. else if (NewDocType == docMath)
  1950. {
  1951. /* will scan html documents */
  1952. strcat (name,".mml");
  1953. strcpy (ScanFilter, "*.mml");
  1954. InitOpenDocForm (document, view, name,
  1955. TtaGetMessage (AMAYA, AM_NEW_MATHML), docMath);
  1956. }
  1957. else if (NewDocType == docSVG)
  1958. {
  1959. /* will scan html documents */
  1960. strcat (name,".svg");
  1961. strcpy (ScanFilter, "*.svg");
  1962. InitOpenDocForm (document, view, name,
  1963. TtaGetMessage (AMAYA, AM_NEW_SVG), docSVG);
  1964. }
  1965. else if (NewDocType == docTemplate)
  1966. {
  1967. /* will scan html documents */
  1968. strcat (name,".xtl");
  1969. strcpy (ScanFilter, "*.xtl");
  1970. InitOpenDocForm (document, view, name,
  1971. TtaGetMessage (LIB, TemplateLibrary), docLibrary);
  1972. }
  1973. else
  1974. {
  1975. /* will scan html documents */
  1976. strcat (name,".css");
  1977. strcpy (ScanFilter, "*.css");
  1978. InitOpenDocForm (document, view, name,
  1979. TtaGetMessage (AMAYA, AM_NEW_CSS), docCSS);
  1980. }
  1981. }
  1982. /*----------------------------------------------------------------------
  1983. Load the Home page
  1984. ----------------------------------------------------------------------*/
  1985. void GoToHome (Document doc, View view)
  1986. {
  1987. char *s, *lang;
  1988. s = TtaGetEnvString ("HOME_PAGE");
  1989. lang = TtaGetVarLANG ();
  1990. if (s == NULL)
  1991. {
  1992. /* the open document is the Amaya default page */
  1993. WelcomePage = TRUE;
  1994. s = TtaGetEnvString ("THOTDIR");
  1995. sprintf (LastURLName, "%s%camaya%c%s.%s",
  1996. s, DIR_SEP, DIR_SEP, AMAYA_PAGE, lang);
  1997. if (!TtaFileExist (LastURLName))
  1998. sprintf (LastURLName, "%s%camaya%c%s",
  1999. s, DIR_SEP, DIR_SEP, AMAYA_PAGE);
  2000. }
  2001. else
  2002. strcpy (LastURLName, s);
  2003. //if (doc == 0 || CanReplaceCurrentDocument (doc, view))
  2004. {
  2005. /* load the HOME document */
  2006. DontReplaceOldDoc = TRUE;
  2007. CurrentDocument = doc;
  2008. CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
  2009. }
  2010. }
  2011. /*----------------------------------------------------------------------
  2012. UpdateDoctypeMenu
  2013. ----------------------------------------------------------------------*/
  2014. void UpdateDoctypeMenu (Document doc)
  2015. {
  2016. DocumentType docType;
  2017. SSchema nature;
  2018. char *ptr;
  2019. int profile, extraProfile;
  2020. ThotBool useMathML, useSVG, useHTML, useMath, withDocType;
  2021. docType = DocumentTypes[doc];
  2022. if (docType != docText && docType != docCSS &&
  2023. docType != docSource && docType != docLog && docType != docBookmark &&
  2024. TtaGetDocumentAccessMode (doc))
  2025. {
  2026. /* look for a MathML or SVG nature within the document */
  2027. nature = NULL;
  2028. useMathML = useSVG = useHTML = FALSE;
  2029. do
  2030. {
  2031. TtaNextNature (doc, &nature);
  2032. if (nature)
  2033. {
  2034. ptr = TtaGetSSchemaName (nature);
  2035. if (!strcmp (ptr, "MathML"))
  2036. useMathML = TRUE;
  2037. else if (!strcmp (ptr, "SVG"))
  2038. useSVG = TRUE;
  2039. }
  2040. }
  2041. while (nature);
  2042. HasADoctype (doc, &withDocType, &useMath);
  2043. if (withDocType)
  2044. {
  2045. /* there is a Doctype */
  2046. TtaSetItemOn (doc, 1, Tools, BRemoveDoctype);
  2047. TtaSetItemOff (doc, 1, Tools, BAddDoctype);
  2048. }
  2049. else
  2050. {
  2051. /* there is no Doctype */
  2052. TtaSetItemOff (doc, 1, Tools, BRemoveDoctype);
  2053. if (docType == docHTML ||
  2054. (!useMathML && !useSVG && !useHTML))
  2055. TtaSetItemOn (doc, 1, Tools, BAddDoctype);
  2056. else
  2057. /* no Doctype available */
  2058. TtaSetItemOff (doc, 1, Tools, BAddDoctype);
  2059. }
  2060. if (docType == docHTML)
  2061. {
  2062. /* Allow to change the DocType: */
  2063. /* A confirmation is requested if some attributes or elements are lost */
  2064. profile = TtaGetDocumentProfile (doc);
  2065. extraProfile = TtaGetDocumentExtraProfile (doc);
  2066. if (profile == L_Xhtml11)
  2067. /* already done */
  2068. {
  2069. if (extraProfile == L_RDFa)
  2070. {
  2071. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlRDFa);
  2072. TtaSetItemOn (doc, 1, Tools, BDoctypeXhtml11);
  2073. }
  2074. else
  2075. {
  2076. TtaSetItemOn (doc, 1, Tools, BDoctypeXhtmlRDFa);
  2077. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtml11);
  2078. }
  2079. }
  2080. else
  2081. {
  2082. TtaSetItemOn (doc, 1, Tools, BDoctypeXhtml11);
  2083. TtaSetItemOn (doc, 1, Tools, BDoctypeXhtmlRDFa);
  2084. }
  2085. if (profile == L_Transitional &&
  2086. DocumentMeta[doc]->xmlformat == TRUE) /* already done */
  2087. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlTransitional);
  2088. else
  2089. TtaSetItemOn (doc, 1, Tools, BDoctypeXhtmlTransitional);
  2090. if (profile == L_Strict &&
  2091. DocumentMeta[doc]->xmlformat == TRUE) /* already done */
  2092. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlStrict);
  2093. else
  2094. TtaSetItemOn (doc, 1, Tools, BDoctypeXhtmlStrict);
  2095. if (profile == L_Basic) /* already done */
  2096. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlBasic);
  2097. else
  2098. TtaSetItemOn (doc, 1, Tools, BDoctypeXhtmlBasic);
  2099. if (profile == L_Transitional &&
  2100. DocumentMeta[doc]->xmlformat != TRUE) /* already done */
  2101. TtaSetItemOff (doc, 1, Tools, BDoctypeHtmlTransitional);
  2102. else
  2103. TtaSetItemOn (doc, 1, Tools, BDoctypeHtmlTransitional);
  2104. if (profile == L_Strict &&
  2105. DocumentMeta[doc]->xmlformat != TRUE) /* already done */
  2106. TtaSetItemOff (doc, 1, Tools, BDoctypeHtmlStrict);
  2107. else
  2108. TtaSetItemOn (doc, 1, Tools, BDoctypeHtmlStrict);
  2109. }
  2110. else
  2111. {
  2112. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtml11);
  2113. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlTransitional);
  2114. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlStrict);
  2115. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlBasic);
  2116. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlRDFa);
  2117. TtaSetItemOff (doc, 1, Tools, BDoctypeHtmlTransitional);
  2118. TtaSetItemOff (doc, 1, Tools, BDoctypeHtmlStrict);
  2119. }
  2120. }
  2121. else
  2122. {
  2123. TtaSetItemOff (doc, 1, Tools, BRemoveDoctype);
  2124. TtaSetItemOff (doc, 1, Tools, BAddDoctype);
  2125. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtml11);
  2126. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlTransitional);
  2127. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlStrict);
  2128. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlBasic);
  2129. TtaSetItemOff (doc, 1, Tools, BDoctypeXhtmlRDFa);
  2130. TtaSetItemOff (doc, 1, Tools, BDoctypeHtmlTransitional);
  2131. TtaSetItemOff (doc, 1, Tools, BDoctypeHtmlStrict);
  2132. }
  2133. }
  2134. /*----------------------------------------------------------------------
  2135. AddDirAttributeToDocEl
  2136. Set the HTML attribute dir on the Document element
  2137. ----------------------------------------------------------------------*/
  2138. void AddDirAttributeToDocEl (Document doc)
  2139. {
  2140. Element root;
  2141. Attribute attr;
  2142. AttributeType attrType;
  2143. root = TtaGetMainRoot (doc);
  2144. if (root)
  2145. {
  2146. attrType.AttrSSchema = TtaGetSSchema ("HTML", doc);
  2147. if (!attrType.AttrSSchema)
  2148. return;
  2149. attrType.AttrTypeNum = HTML_ATTR_dir;
  2150. attr = TtaNewAttribute (attrType);
  2151. TtaAttachAttribute (root, attr, doc);
  2152. TtaSetAttributeValue (attr, HTML_ATTR_dir_VAL_ltr_, root, doc);
  2153. }
  2154. }
  2155. /*----------------------------------------------------------------------
  2156. GiveWindowGeometry
  2157. Gets registered window parameters
  2158. ----------------------------------------------------------------------*/
  2159. static void GiveWindowGeometry (Document doc, int docType, int method,
  2160. int *x, int *y, int *w, int *h)
  2161. {
  2162. const char *label;
  2163. /* get the window geometry */
  2164. if (docType == docAnnot)
  2165. label = "Annot_Formatted_view";
  2166. else if (docType == docBookmark)
  2167. label = "Topics_Formatted_view";
  2168. else
  2169. label = "Wx_Window";
  2170. TtaGetViewGeometry (doc, label, x, y, w, h);
  2171. if (*w == 0 || *h == 0)
  2172. TtaGetViewGeometry (doc, "Formatted_view", x, y, w, h);
  2173. /* change the position slightly to avoid hiding completely the main
  2174. view of other documents */
  2175. *x = *x + (doc - 1) * 10;
  2176. *y = *y + (doc - 1) * 10;
  2177. if (docType == docLog)
  2178. {
  2179. *x += 100;
  2180. *y += 60;
  2181. *h = 300;
  2182. *w = 600;
  2183. }
  2184. else if (method == CE_HELP || docType == docBookmark)
  2185. {
  2186. *x += 300;
  2187. *y += 200;
  2188. *h = 600;
  2189. *w = 700;
  2190. }
  2191. else if (docType == docLibrary)
  2192. {
  2193. *x += 300;
  2194. *y += 200;
  2195. *h = 500;
  2196. *w = 400;
  2197. }
  2198. }
  2199. /*----------------------------------------------------------------------
  2200. WhereOpenView finds out where to open the view according to parameters
  2201. oldDoc is the current active document
  2202. doc is the new document (often doc = oldDoc except for a undisplayed
  2203. alredy loaded document)
  2204. replaceOldDoc, inNewWindow, etc. give containts
  2205. The function returns windowId, pageId and pagePosition
  2206. ----------------------------------------------------------------------*/
  2207. void WhereOpenView (Document oldDoc, Document doc, ThotBool replaceOldDoc,
  2208. ThotBool inNewWindow, DocumentType docType, int method,
  2209. int* windowId, int* pageId, int* pagePosition,
  2210. int* _visibility, ThotBool* isOpen, int* requestedDoc)
  2211. {
  2212. int window_id = -1,
  2213. page_id = -1,
  2214. page_position = 0,
  2215. visibility = 5,
  2216. requested_doc;
  2217. View structView, altView, linksView, tocView;
  2218. ThotBool is_open;
  2219. /* if the old doc doesn't exist it's not possible to create a new tab,
  2220. * just open it in a new window */
  2221. if (oldDoc == 0)
  2222. inNewWindow = TRUE;
  2223. /* previous document */
  2224. if (method != CE_HELP &&
  2225. DocumentURLs[oldDoc] && !strcmp (DocumentURLs[oldDoc], "empty"))
  2226. // load by default in the current empty page
  2227. replaceOldDoc = TRUE;
  2228. if (replaceOldDoc && oldDoc > 0)
  2229. /* the new document will replace another document in the same window */
  2230. {
  2231. // transmit the visibility to the new document
  2232. visibility = TtaGetSensibility (oldDoc, 1);
  2233. /* get the old document window */
  2234. window_id = TtaGetDocumentWindowId (oldDoc, -1 );
  2235. // if the document is loaded but not displayed
  2236. // doc and oldDoc are different
  2237. /* get the document page id */
  2238. TtaGetDocumentPageId (doc, -1, &page_id, &page_position);
  2239. /* force the document's page position because sometime oldDoc is
  2240. a source document placed on the bottom part of the page */
  2241. page_position = 1;
  2242. if (IsXMLDocType (doc))
  2243. {
  2244. /* close the Alternate view if it is open */
  2245. altView = TtaGetViewFromName (doc, "Alternate_view");
  2246. if (altView != 0 && TtaIsViewOpen (doc, altView))
  2247. TtaCloseView (doc, altView);
  2248. /* close the Structure view if it is open */
  2249. structView = TtaGetViewFromName (doc, "Structure_view");
  2250. if (structView != 0 && TtaIsViewOpen (doc, structView))
  2251. TtaCloseView (doc, structView);
  2252. /* close the Links view if it is open */
  2253. linksView = TtaGetViewFromName (doc, "Links_view");
  2254. if (linksView != 0 && TtaIsViewOpen (doc, linksView))
  2255. TtaCloseView (doc, linksView);
  2256. /* close the Table_of_contents view if it is open */
  2257. tocView = TtaGetViewFromName (doc, "Table_of_contents");
  2258. if (tocView != 0 && TtaIsViewOpen (doc, tocView))
  2259. TtaCloseView (doc, tocView);
  2260. }
  2261. /* remove the current selection */
  2262. TtaUnselect (doc);
  2263. UpdateContextSensitiveMenus (doc, 1);
  2264. HideHSplitToggle (doc, 1);
  2265. HideVSplitToggle (doc, 1);
  2266. TtaFreeView (doc, 1);
  2267. is_open = TRUE;
  2268. /* use the same document identifier */
  2269. requested_doc = doc;
  2270. oldDoc = 0; /* the previous document doesn't exist any more */
  2271. /* The toolkit has to do its job now */
  2272. TtaHandlePendingEvents ();
  2273. }
  2274. else if (docType == docAnnot || method == CE_HELP)
  2275. {
  2276. if (method == CE_HELP)
  2277. window_id = TtaGetHelpWindowId();
  2278. else
  2279. window_id = TtaGetAnnotWindowId();
  2280. if (window_id != -1)
  2281. {
  2282. // the annotation window is already open
  2283. inNewWindow = FALSE;
  2284. is_open = TRUE;
  2285. page_id = TtaGetFreePageId( window_id );
  2286. page_position = 1;
  2287. }
  2288. else
  2289. is_open = FALSE;
  2290. requested_doc = 0;
  2291. }
  2292. else if (inNewWindow)
  2293. {
  2294. /* open the new document in a fresh window */
  2295. is_open = FALSE;
  2296. requested_doc = 0;
  2297. }
  2298. else
  2299. {
  2300. /* open the new document in the same window but in a fresh page */
  2301. requested_doc = 0;
  2302. is_open = TRUE;
  2303. if (docType == docSource)
  2304. {
  2305. /* source view is open it into the same page as formatted view */
  2306. window_id = TtaGetDocumentWindowId(oldDoc, -1 );
  2307. TtaGetDocumentPageId( doc, -1, &page_id, &page_position );
  2308. page_position = 2;
  2309. }
  2310. else
  2311. {
  2312. // the document is displayed in a window
  2313. window_id = TtaGetDocumentWindowId(oldDoc, -1 );
  2314. if (window_id < 0)
  2315. window_id = TtaGetDocumentWindowId(doc, -1 );
  2316. page_id = TtaGetFreePageId( window_id );
  2317. page_position = 1;
  2318. }
  2319. }
  2320. *windowId = window_id;
  2321. *pageId = page_id;
  2322. *pagePosition = page_position;
  2323. *isOpen = is_open;
  2324. *_visibility = visibility;
  2325. *requestedDoc = requested_doc;
  2326. }
  2327. /*----------------------------------------------------------------------
  2328. ----------------------------------------------------------------------*/
  2329. View InitView (Document oldDoc, Document doc,
  2330. ThotBool replaceOldDoc, ThotBool inNewWindow, ThotBool isOpen,
  2331. int window_id, int page_id, int page_position,
  2332. DocumentType docType, int method)
  2333. {
  2334. View mainView;
  2335. int x, y, w, h;
  2336. ThotBool reinitialized = FALSE;
  2337. TtaSetDisplayMode(doc, NoComputedDisplay);
  2338. /* gets registered window parameters */
  2339. GiveWindowGeometry (doc, docType, method, &x, &y, &w, &h);
  2340. /* create a new window if needed */
  2341. if (window_id == -1)
  2342. {
  2343. /* get the parent window because the log should stay on top of his parent */
  2344. int parent_window_id = TtaGetDocumentWindowId( oldDoc, -1 );
  2345. switch(docType)
  2346. {
  2347. case docLog:
  2348. case docLibrary:
  2349. window_id = TtaMakeWindow(x, y, w, h, WXAMAYAWINDOW_SIMPLE, parent_window_id );
  2350. break;
  2351. case docCSS:
  2352. window_id = TtaMakeWindow(x, y, w, h, WXAMAYAWINDOW_CSS, 0 );
  2353. break;
  2354. case docAnnot:
  2355. window_id = TtaMakeWindow(x, y, w, h, WXAMAYAWINDOW_ANNOT, 0 );
  2356. break;
  2357. default:
  2358. if (method == CE_HELP)
  2359. window_id = TtaMakeWindow(x, y, w, h, WXAMAYAWINDOW_HELP, 0 );
  2360. else
  2361. /* a normal window should never had a parent ! */
  2362. window_id = TtaMakeWindow(x, y, w, h, WXAMAYAWINDOW_NORMAL, 0 );
  2363. break;
  2364. }
  2365. page_id = TtaGetFreePageId( window_id );
  2366. page_position = 1;
  2367. }
  2368. /* init default documents menus states: enable/disable, toggle/untoggle
  2369. * need to be done before frame creation because the active frame will
  2370. * use it to refresh the menus */
  2371. if (!replaceOldDoc || !isOpen)
  2372. TtaInitMenuItemStats(doc);
  2373. TtaInitTopMenuStats(doc);
  2374. /* open the main view */
  2375. if (docType == docLog)
  2376. {
  2377. /* without menu bar */
  2378. mainView = TtaOpenMainView (doc, DocumentTypeNames[docType], x, y,
  2379. w, h, FALSE, FALSE,
  2380. window_id, page_id, page_position);
  2381. if (docType == docLog)
  2382. // apply style attached to log files
  2383. SetStyleOfLog (doc);
  2384. }
  2385. else if (docType == docLibrary && method == CE_RELATIVE)
  2386. /* without menu bar */
  2387. mainView = TtaOpenMainView (doc, DocumentTypeNames[docType], x, y,
  2388. w, h, FALSE, TRUE,
  2389. window_id, page_id, page_position);
  2390. else
  2391. mainView = TtaOpenMainView (doc, DocumentTypeNames[docType], x, y,
  2392. w, h, TRUE, TRUE,
  2393. window_id, page_id, page_position);
  2394. if(mainView==0)
  2395. return 0;
  2396. /* init the zoom factor to 0 if the document isn't replaced */
  2397. if (!replaceOldDoc)
  2398. TtaSetZoom (doc, -1, 0);
  2399. /* update the menus according to the profile */
  2400. /* By default no log file */
  2401. #ifndef DAV /* don't active the WebDAV menu if flag is off */
  2402. TtaSetMenuOff (doc, 1, Cooperation_);
  2403. #endif /* DAV */
  2404. TtaSetDisplayMode(doc, DisplayImmediately);
  2405. /* do we have to redraw buttons and menus? */
  2406. reinitialized = (docType != DocumentTypes[doc]);
  2407. return mainView;
  2408. }
  2409. /*----------------------------------------------------------------------
  2410. ----------------------------------------------------------------------*/
  2411. void PostInitView(Document doc, DocumentType docType, int visibility,
  2412. ThotBool replaceOldDoc, ThotBool isOpen)
  2413. {
  2414. ThotBool reinitialized = TRUE, show;
  2415. if (!replaceOldDoc || !isOpen)
  2416. {
  2417. /* initial state for menu entries */
  2418. TtaSetItemOff (doc, 1, File, BBack);
  2419. TtaSetItemOff (doc, 1, File, BForward);
  2420. TtaSetItemOff (doc, 1, File, BSave);
  2421. TtaSetItemOff (doc, 1, File, BSaveAll);
  2422. TtaSetItemOff (doc, 1, File, BSynchro);
  2423. /* init MapAreas menu item */
  2424. TtaSetToggleItem (doc, 1, Views, TShowMapAreas, MapAreas[doc]);
  2425. TtaGetEnvBoolean ("BROWSE_TOOLBAR", &show);
  2426. TtaSetToggleItem (doc, 1, Views, TShowBrowsingBar, show);
  2427. TtaGetEnvBoolean ("EDIT_TOOLBAR", &show);
  2428. TtaSetToggleItem (doc, 1, Views, TShowEditingBar, show);
  2429. }
  2430. /* store the new document type */
  2431. DocumentTypes[doc] = docType;
  2432. /* switch off the button Show Log file */
  2433. UpdateLogFile (doc, FALSE);
  2434. /* now be sure that the urlbar is setup */
  2435. //if (DocumentURLs[doc] && strcmp (DocumentURLs[doc], "empty"))
  2436. TtaAddTextZone ( doc, 1, TtaGetMessage (AMAYA, AM_OPEN_URL),
  2437. TRUE, (Proc)TextURL, URL_list );
  2438. if (IsXMLDocType (doc))
  2439. {
  2440. /* init show target menu item */
  2441. TtaGetEnvBoolean ("SHOW_TARGET", &show);
  2442. if (show)
  2443. ShowTargets (doc, 1);
  2444. else
  2445. TtaSetToggleItem (doc, 1, Views, TShowTargets, FALSE);
  2446. }
  2447. if (reinitialized || !isOpen)
  2448. {
  2449. if (reinitialized && visibility == 4)
  2450. {
  2451. // restore the visibility
  2452. TtaSetSensibility (doc, 1, visibility);
  2453. TtaSetToggleItem (doc, 1, Views, TShowTargets, TRUE);
  2454. }
  2455. /* now update menus and buttons according to the document status */
  2456. if (DocumentTypes[doc] == docLog ||
  2457. DocumentTypes[doc] == docLibrary ||
  2458. DocumentTypes[doc] == docBookmark)
  2459. {
  2460. if (DocumentTypes[doc] != docBookmark)
  2461. {
  2462. TtaSetItemOff (doc, 1, File, BMathml);
  2463. TtaSetItemOff (doc, 1, File, BSvg);
  2464. TtaSetItemOff (doc, 1, File, BCss);
  2465. TtaSetItemOff (doc, 1, File, BOpenDoc);
  2466. TtaSetItemOff (doc, 1, File, BReload);
  2467. TtaSetItemOff (doc, 1, File, BBack);
  2468. TtaSetItemOff (doc, 1, File, BForward);
  2469. #ifdef ANNOTATIONS
  2470. TtaSetMenuOff (doc, 1, Annotations_);
  2471. #endif /* ANNOTATIONS */
  2472. }
  2473. TtaSetItemOff (doc, 1, File, BSave);
  2474. TtaSetItemOff (doc, 1, File, BSaveAll);
  2475. TtaSetItemOff (doc, 1, File, BSynchro);
  2476. TtaSetItemOff (doc, 1, File, BSetUpandPrint);
  2477. TtaSetItemOff (doc, 1, File, BPrint);
  2478. SetCharsetMenuOff (doc, 1); /* no charset commands */
  2479. /* invalid the DoctypeMenu */
  2480. TtaSetMenuOff (doc, 1, Types);
  2481. TtaSetMenuOff (doc, 1, Tools);
  2482. TtaSetMenuOff (doc, 1, Links);
  2483. TtaSetMenuOff (doc, 1, Views);
  2484. TtaSetMenuOff (doc, 1, Style);
  2485. TtaSetMenuOff (doc, 1, Help_);
  2486. if (docType != docBookmark)
  2487. {
  2488. TtaSetItemOff (doc, 1, File, BExit);
  2489. TtaSetMenuOff (doc, 1, Edit_);
  2490. if (docType != docLibrary)
  2491. TtaSetDocumentAccessMode (doc, 0);
  2492. }
  2493. }
  2494. else if (DocumentTypes[doc] == docText ||
  2495. DocumentTypes[doc] == docSource ||
  2496. DocumentTypes[doc] == docCSS ||
  2497. DocumentTypes[doc] == docMath)
  2498. {
  2499. if (DocumentTypes[doc] != docText)
  2500. TtaSetMenuOn (doc, 1, Style);
  2501. if (DocumentTypes[doc] == docMath)
  2502. {
  2503. TtaSetItemOn (doc, 1, Style, BCreateClass);
  2504. TtaSetItemOn (doc, 1, Style, BShowAppliedStyle);
  2505. TtaSetItemOn (doc, 1, Style, BLinkCSS);
  2506. TtaSetItemOn (doc, 1, Style, BOpenCSS);
  2507. TtaSetItemOn (doc, 1, Style, BDisableCSS);
  2508. TtaSetItemOn (doc, 1, Style, BEnableCSS);
  2509. TtaSetItemOn (doc, 1, Style, BRemoveCSS);
  2510. }
  2511. else
  2512. {
  2513. TtaSetItemOff (doc, 1, Style, BCreateClass);
  2514. TtaSetItemOff (doc, 1, Style, BShowAppliedStyle);
  2515. TtaSetItemOff (doc, 1, Style, BLinkCSS);
  2516. TtaSetItemOff (doc, 1, Style, BOpenCSS);
  2517. TtaSetItemOff (doc, 1, Style, BDisableCSS);
  2518. TtaSetItemOff (doc, 1, Style, BEnableCSS);
  2519. TtaSetItemOff (doc, 1, Style, BRemoveCSS);
  2520. TtaSetMenuOff (doc, 1, Types);
  2521. }
  2522. TtaSetItemOff (doc, 1, Views, TShowMapAreas);
  2523. TtaSetItemOff (doc, 1, Views, TShowTargets);
  2524. TtaSetMenuOff (doc, 1, Doctype1);
  2525. TtaSetMenuOff (doc, 1, Links);
  2526. if (DocumentTypes[doc] == docMath)
  2527. TtaSetMenuOn (doc, 1, Views);
  2528. else
  2529. {
  2530. //if (DocumentTypes[doc] != docSource)
  2531. // TtaSetMenuOff (doc, 1, Views);
  2532. TtaSetItemOff (doc, 1, Tools, BTransform);
  2533. #ifdef ANNOTATIONS
  2534. TtaSetMenuOff (doc, 1, Annotations_);
  2535. #endif /* ANNOTATIONS */
  2536. }
  2537. }
  2538. else if (DocumentTypes[doc] == docAnnot)
  2539. {
  2540. TtaSetItemOff (doc, 1, Views, BShowAlternate);
  2541. TtaSetItemOff (doc, 1, Views, BShowToC);
  2542. TtaSetItemOff (doc, 1, Views, BShowSource);
  2543. }
  2544. else
  2545. {
  2546. TtaSetMenuOn (doc, 1, Views);
  2547. TtaSetItemOn (doc, 1, Views, TShowTargets);
  2548. TtaSetItemOn (doc, 1, Views, BShowLinks);
  2549. /* turn off the assign annotation buttons (should be
  2550. contextual */
  2551. /* TtaSetItemOff (doc, 1, Tools, BReplyToAnnotation);
  2552. TtaSetItemOff (doc, 1, Tools, BMoveAnnotSel);
  2553. TtaSetItemOff (doc, 1, Tools, BMoveAnnotXPtr);
  2554. TtaSetItemOff (doc, 1, Tools, BPostAnnot);*/
  2555. if (DocumentTypes[doc] == docHTML)
  2556. {
  2557. TtaSetItemOn (doc, 1, Views, TShowMapAreas);
  2558. TtaSetItemOn (doc, 1, Views, BShowAlternate);
  2559. TtaSetItemOn (doc, 1, Views, BShowToC);
  2560. // TtaSetItemOn (doc, 1, Tools, BTitle);
  2561. }
  2562. else
  2563. {
  2564. TtaSetItemOff (doc, 1, Views, TShowMapAreas);
  2565. TtaSetItemOff (doc, 1, Views, BShowToC);
  2566. if (DocumentTypes[doc] == docSVG)
  2567. {
  2568. TtaSetItemOn (doc, 1, Views, BShowAlternate);
  2569. // TtaSetItemOff (doc, 1, Tools, BTitle);
  2570. }
  2571. else
  2572. TtaSetItemOff (doc, 1, Views, BShowAlternate);
  2573. }
  2574. }
  2575. }
  2576. }
  2577. #include "templateUtils_f.h"
  2578. /*----------------------------------------------------------------------
  2579. InitDocAndView prepares the main view of a new document.
  2580. logFile is TRUE if the new view is created to display a log file
  2581. sourceOfDoc is not zero when we're opening the source view of a document.
  2582. params:
  2583. + Document oldDoc: the old document id
  2584. + ThotBool replaceOldDoc: true if the new doc should replace the old one
  2585. + ThotBool inNewWindow: true if the new doc should be created in a new window
  2586. + ...
  2587. ----------------------------------------------------------------------*/
  2588. Document InitDocAndView (Document oldDoc, ThotBool replaceOldDoc, ThotBool inNewWindow,
  2589. const char *docname, DocumentType docType, Document sourceOfDoc,
  2590. ThotBool readOnly, int profile, int extraProfile, int method)
  2591. {
  2592. Document doc; /* the new doc */
  2593. View mainView;
  2594. Element root, comment, leaf;
  2595. ElementType elType;
  2596. char buffer[MAX_LENGTH];
  2597. int requested_doc, visibility = 5;
  2598. Language lang;
  2599. ThotBool isOpen;
  2600. /* specific to wxWidgets user interface */
  2601. /* ------------------------------------ */
  2602. /* this is the window id identifying where the document should be shown
  2603. * this window_id is a document attribute and the corresponding
  2604. * window widget has been allocated before this function call */
  2605. int window_id = -1;
  2606. /* this is the page id identifying where the document should be shown
  2607. * into a window (window_id), each page can contain one or more documents */
  2608. int page_id = -1;
  2609. /* this is the choosen position in the given page (top or bottom) */
  2610. int page_position = 0;
  2611. /* ------------------------------------ */
  2612. /* is there any editing function available */
  2613. if (!TtaCanEdit ())
  2614. /* change the document status */
  2615. readOnly = TRUE;
  2616. /* if it is a source document, reload its corresponding document */
  2617. if (DocumentTypes[oldDoc] == docSource)
  2618. oldDoc = GetDocFromSource (oldDoc);
  2619. /* Where open the new document ? in which window ? */
  2620. WhereOpenView(oldDoc, oldDoc, replaceOldDoc, inNewWindow, docType, method,
  2621. &window_id, &page_id, &page_position, &visibility, &isOpen, &requested_doc);
  2622. /* Init the new document */
  2623. if (docType == docText || docType == docCSS ||
  2624. docType == docSource || docType == docLog)
  2625. doc = TtaInitDocument ("TextFile", docname, CurrentNameSpace, requested_doc);
  2626. else if (docType == docAnnot)
  2627. doc = TtaInitDocument ("Annot", docname, CurrentNameSpace, requested_doc);
  2628. #ifdef BOOKMARKS
  2629. else if (docType == docBookmark)
  2630. doc = TtaInitDocument ("Topics", docname, CurrentNameSpace, requested_doc);
  2631. #endif /* BOOKMARKS */
  2632. else if (docType == docSVG)
  2633. doc = TtaInitDocument ("SVG", docname, CurrentNameSpace, requested_doc);
  2634. else if (docType == docMath)
  2635. doc = TtaInitDocument ("MathML", docname, CurrentNameSpace, requested_doc);
  2636. #ifdef TEMPLATES
  2637. else if (docType == docTemplate)
  2638. doc = TtaInitDocument ("Template", docname, CurrentNameSpace, requested_doc);
  2639. #endif /* TEMPLATES */
  2640. #ifdef XML_GENERIC
  2641. else if (docType == docXml)
  2642. doc = TtaInitDocument ("XML", docname, CurrentNameSpace, requested_doc);
  2643. #endif /* XML_GENERIC */
  2644. else
  2645. doc = TtaInitDocument ("HTML", docname, CurrentNameSpace, requested_doc);
  2646. if (doc >= DocumentTableLength)
  2647. {
  2648. TtaCloseDocument (doc);
  2649. doc = 0;
  2650. }
  2651. else if (doc > 0)
  2652. {
  2653. /* assign a presentation model to the document */
  2654. if (docType == docLog)
  2655. TtaSetPSchema (doc, "TextFilePLOG");
  2656. else if (docType == docText || docType == docCSS ||
  2657. docType == docSource)
  2658. TtaSetPSchema (doc, "TextFileP");
  2659. else if (docType == docAnnot)
  2660. {
  2661. TtaSetPSchema (doc, "AnnotP");
  2662. profile = L_Annot; /* force the profile */
  2663. }
  2664. #ifdef BOOKMARKS
  2665. else if (docType == docBookmark)
  2666. {
  2667. TtaSetPSchema (doc, "TopicsP");
  2668. profile = L_Bookmarks; /* force the profile */
  2669. }
  2670. #endif /* BOOKMARKS */
  2671. else if (docType == docSVG)
  2672. TtaSetPSchema (doc, "SVGP");
  2673. else if (docType == docMath)
  2674. TtaSetPSchema (doc, "MathMLP");
  2675. #ifdef TEMPLATES
  2676. else if (docType == docTemplate)
  2677. TtaSetPSchema (doc, "TemplateP");
  2678. #endif /* TEMPLATES */
  2679. #ifdef XML_GENERIC
  2680. else if (docType == docXml)
  2681. TtaSetPSchema (doc, "XMLP");
  2682. #endif /* XML_GENERIC */
  2683. /* @@ shouldn't we have a Color and BW case for annots too? */
  2684. else
  2685. {
  2686. if (TtaGetScreenDepth () > 1)
  2687. TtaSetPSchema (doc, "HTMLP");
  2688. else
  2689. TtaSetPSchema (doc, "HTMLPBW");
  2690. /* set attribute dir on the Document element. */
  2691. AddDirAttributeToDocEl (doc);
  2692. }
  2693. if (docType == docSVG || docType == docMath)
  2694. /* add a comment proudly claiming that the document was created by
  2695. Amaya */
  2696. {
  2697. root = TtaGetRootElement (doc);
  2698. elType = TtaGetElementType (root);
  2699. if (docType == docSVG)
  2700. elType.ElTypeNum = SVG_EL_XMLcomment;
  2701. else
  2702. elType.ElTypeNum = MathML_EL_XMLcomment;
  2703. comment = TtaNewTree (doc, elType, "");
  2704. TtaSetStructureChecking (FALSE, doc);
  2705. TtaInsertSibling (comment, root, TRUE, doc);
  2706. TtaSetStructureChecking (TRUE, doc);
  2707. strcpy (buffer, " Created by ");
  2708. strcat (buffer, TtaGetAppName());
  2709. strcat (buffer, " ");
  2710. strcat (buffer, TtaGetAppVersion());
  2711. strcat (buffer, ", see http://www.w3.org/Amaya/ ");
  2712. leaf = TtaGetFirstLeaf (comment);
  2713. lang = TtaGetLanguageIdFromScript('L');
  2714. TtaSetTextContent (leaf, (unsigned char *)buffer, lang, doc);
  2715. }
  2716. if (docType == docBookmark)
  2717. TtaSetNotificationMode (doc, 0); /* we don't need notif. in bookmarks */
  2718. else
  2719. TtaSetNotificationMode (doc, 1);
  2720. /* store the profile of the new document */
  2721. TtaSetDocumentProfile (doc, profile, extraProfile);
  2722. if (method == CE_MAKEBOOK || method == CE_TEMPLATE)
  2723. // it's not necessary to create the document window
  2724. return doc;
  2725. DocumentTypes[doc] = docType;
  2726. mainView = InitView(oldDoc, doc, replaceOldDoc, inNewWindow, isOpen,
  2727. window_id, page_id, page_position, docType, method);
  2728. if (mainView == 0)
  2729. {
  2730. TtaCloseDocument (doc);
  2731. return (0);
  2732. }
  2733. }
  2734. PostInitView(doc, docType, visibility, replaceOldDoc, isOpen);
  2735. // show the window if it's not allready done
  2736. TtaShowWindow( window_id, TRUE );
  2737. return (doc);
  2738. }
  2739. /*----------------------------------------------------------------------
  2740. CreateHTMLContainer create an HTML container for an image
  2741. ----------------------------------------------------------------------*/
  2742. static void CreateHTMLContainer (char *pathname, char *docname,
  2743. char *tempfile, ThotBool local)
  2744. {
  2745. FILE *file;
  2746. char *tempfile_new;
  2747. char *ptr;
  2748. if (!local)
  2749. {
  2750. /* Rename the current downloaded file (an image) so that we can
  2751. find it easily next time around.
  2752. The convention is to change the image's extension to 'html',
  2753. and give the HTML's container the image's extension */
  2754. tempfile_new = (char *)TtaGetMemory (strlen (tempfile) + strlen (docname) + 10);
  2755. strcpy (tempfile_new, tempfile);
  2756. ptr = strrchr (tempfile_new, DIR_SEP);
  2757. ptr++;
  2758. strcpy (ptr, docname);
  2759. SetContainerImageName (tempfile_new);
  2760. TtaFileUnlink (tempfile_new);
  2761. if (TtaFileCopyUncompress (tempfile, tempfile_new))
  2762. /* copy done */
  2763. TtaFileUnlink (tempfile);
  2764. else
  2765. /* change the tempfile name */
  2766. sprintf (tempfile_new, "%s", tempfile);
  2767. TtaFreeMemory (tempfile_new);
  2768. }
  2769. /* create a temporary file for the container and make Amaya think
  2770. that it is the current downloaded file */
  2771. file = TtaWriteOpen (tempfile);
  2772. fprintf (file, "<html><head><title>%s</title></head><body>", docname);
  2773. if (local)
  2774. fprintf (file, "<img src=\"%s\" alt=\"image\">", pathname);
  2775. else
  2776. fprintf (file, "<img src=\"internal:%s\" alt=\"image\" width=\"100%%\">", pathname);
  2777. fprintf (file, "</body></html>");
  2778. TtaWriteClose (file);
  2779. }
  2780. /*----------------------------------------------------------------------
  2781. MoveImageFile moves an image file (related to an HTML container) from
  2782. one directory to another
  2783. ----------------------------------------------------------------------*/
  2784. static void MoveImageFile (Document source_doc, Document dest_doc,
  2785. char *documentname)
  2786. {
  2787. char *source;
  2788. char *target;
  2789. char *imagefile;
  2790. char *ptr;
  2791. /* generate the name of the file where is stored the image */
  2792. imagefile = (char *)TtaGetMemory (strlen (documentname) + 6);
  2793. strcpy (imagefile, documentname);
  2794. ptr = strrchr (imagefile, '.');
  2795. if (!ptr)
  2796. strcat (imagefile, ".html");
  2797. else
  2798. strcpy (&(ptr[1]), "html");
  2799. /* create the source and dest file names */
  2800. source = (char *)TtaGetMemory (strlen (TempFileDirectory) + strlen (imagefile) + 6);
  2801. sprintf (source, "%s%c%d%c%s",
  2802. TempFileDirectory, DIR_SEP, source_doc, DIR_SEP, imagefile);
  2803. target = (char *)TtaGetMemory (strlen (TempFileDirectory) + strlen (imagefile) + 6);
  2804. sprintf (target, "%s%c%d%c%s",
  2805. TempFileDirectory, DIR_SEP, dest_doc, DIR_SEP, imagefile);
  2806. /* move the file */
  2807. TtaFileCopy (source, target);
  2808. TtaFileUnlink (source);
  2809. TtaFreeMemory (source);
  2810. TtaFreeMemory (target);
  2811. TtaFreeMemory (imagefile);
  2812. }
  2813. /*----------------------------------------------------------------------
  2814. ReparseAs
  2815. Load current document considering it's a HTML document and/or
  2816. with a new charset (charset != UNDEFINED_CHARSET).
  2817. ----------------------------------------------------------------------*/
  2818. void ReparseAs (Document doc, View view, ThotBool asHTML,
  2819. CHARSET charset)
  2820. {
  2821. CHARSET doc_charset;
  2822. DocumentType thotType;
  2823. char *localFile = NULL;
  2824. char documentname[MAX_LENGTH];
  2825. char s[MAX_LENGTH], charsetname[MAX_LENGTH];
  2826. int i, parsingLevel, extraProfile;
  2827. ThotBool plaintext;
  2828. ThotBool xmlDec, withDoctype, isXML, useMath, isKnown;
  2829. if (DocumentURLs[doc] == NULL ||
  2830. (asHTML && !DocumentMeta[doc]->xmlformat))
  2831. /* the document is not concerned by this option */
  2832. return;
  2833. if (!CanReplaceCurrentDocument (doc, view))
  2834. /* abort the command */
  2835. return;
  2836. /* Initialize the LogFile variables */
  2837. CleanUpParsingErrors ();
  2838. /* remove the PARSING.ERR file */
  2839. RemoveParsingErrors (doc);
  2840. /* Remove the previous namespaces declaration */
  2841. TtaFreeNamespaceDeclarations (doc);
  2842. localFile = GetLocalPath (doc, DocumentURLs[doc]);
  2843. TtaExtractName (localFile, s, documentname);
  2844. for (i = 1; i < DocumentTableLength; i++)
  2845. if (DocumentURLs[i] != NULL && DocumentSource[i] == doc)
  2846. {
  2847. DocumentSource[i] = 0;
  2848. if (DocumentTypes[i] == docLog)
  2849. {
  2850. /* close the window of the log file attached to the
  2851. current document */
  2852. TtaCloseDocument (i);
  2853. TtaFreeMemory (DocumentURLs[i]);
  2854. DocumentURLs[i] = NULL;
  2855. /* switch off the button Show Log file */
  2856. UpdateLogFile (doc, FALSE);
  2857. }
  2858. }
  2859. /* Removes all CSS informations linked with the document */
  2860. RemoveDocCSSs (doc, FALSE);
  2861. /* Free access keys table */
  2862. TtaRemoveDocAccessKeys (doc);
  2863. if (asHTML)
  2864. {
  2865. DocumentMeta[doc]->xmlformat = FALSE;
  2866. DocumentMeta[doc]->compound = FALSE;
  2867. }
  2868. if (charset != UNDEFINED_CHARSET &&
  2869. charset != TtaGetDocumentCharset (doc))
  2870. {
  2871. /* Update the charset info */
  2872. TtaSetDocumentCharset (doc, charset, FALSE);
  2873. if (DocumentMeta[doc]->charset)
  2874. TtaFreeMemory (DocumentMeta[doc]->charset);
  2875. DocumentMeta[doc]->charset = TtaStrdup (TtaGetCharsetName (charset));
  2876. }
  2877. /* parse with the HTML parser */
  2878. if (DocumentMeta[doc]->xmlformat)
  2879. {
  2880. /* check if there is an XML declaration with a charset declaration */
  2881. charsetname[0] = EOS;
  2882. CheckDocHeader (localFile, &xmlDec, &withDoctype, &isXML, &useMath, &isKnown,
  2883. &parsingLevel, &doc_charset, charsetname, &thotType, &extraProfile);
  2884. StartXmlParser (doc, localFile, documentname, s,
  2885. localFile, xmlDec, withDoctype, useMath, FALSE);
  2886. }
  2887. else
  2888. {
  2889. plaintext = (DocumentTypes[doc] == docCSS ||
  2890. DocumentTypes[doc] == docText);
  2891. StartParser (doc, localFile, documentname, s, localFile, plaintext, FALSE);
  2892. }
  2893. /* fetch and display all images referred by the document */
  2894. DocNetworkStatus[doc] = AMAYA_NET_ACTIVE;
  2895. FetchAndDisplayImages (doc, AMAYA_LOAD_IMAGE, NULL);
  2896. DocNetworkStatus[doc] = AMAYA_NET_INACTIVE;
  2897. if (!asHTML &&
  2898. !XMLNotWellFormed && !XMLInvalidToken && !XMLCharacterNotSupported &&
  2899. !XMLErrorsFoundInProfile && !XMLErrorsFound)
  2900. {
  2901. /* No error found -> Update the source of the document */
  2902. TtaSetDocumentModified (doc);
  2903. Synchronize (doc, view);
  2904. TtaSetDocumentUnmodified (doc);
  2905. }
  2906. /* check parsing errors */
  2907. CheckParsingErrors (doc);
  2908. TtaFreeMemory (localFile);
  2909. }
  2910. /*----------------------------------------------------------------------
  2911. ParseAsHTML
  2912. Load current document considering it's a HTML document
  2913. ----------------------------------------------------------------------*/
  2914. void ParseAsHTML (Document doc, View view)
  2915. {
  2916. char *localFile = NULL;
  2917. char documentname[MAX_LENGTH];
  2918. char s[MAX_LENGTH];
  2919. /* Initialize the LogFile variables */
  2920. CleanUpParsingErrors ();
  2921. /* remove the PARSING.ERR file */
  2922. RemoveParsingErrors (doc);
  2923. /* Remove the previous namespaces declaration */
  2924. TtaFreeNamespaceDeclarations (doc);
  2925. localFile = GetLocalPath (doc, DocumentURLs[doc]);
  2926. TtaExtractName (localFile, s, documentname);
  2927. /* Removes all CSS informations linked with the document */
  2928. RemoveDocCSSs (doc, FALSE);
  2929. /* Free access keys table */
  2930. TtaRemoveDocAccessKeys (doc);
  2931. // ignore the XML format
  2932. if (DocumentMeta[doc]->xmlformat)
  2933. DocumentMeta[doc]->xmlformat = FALSE;
  2934. StartParser (doc, localFile, documentname, s, localFile, FALSE, FALSE);
  2935. // restore the XML format
  2936. if (DocumentMeta[doc]->xmlformat)
  2937. DocumentMeta[doc]->xmlformat = TRUE;
  2938. /* fetch and display all images referred by the document */
  2939. DocNetworkStatus[doc] = AMAYA_NET_ACTIVE;
  2940. FetchAndDisplayImages (doc, AMAYA_LOAD_IMAGE, NULL);
  2941. DocNetworkStatus[doc] = AMAYA_NET_INACTIVE;
  2942. /* check parsing errors */
  2943. CheckParsingErrors (doc);
  2944. TtaFreeMemory (localFile);
  2945. }
  2946. #ifdef _SVG
  2947. /*----------------------------------------------------------------------
  2948. DisplaySVGtitle
  2949. Get the first child of the root element of document doc that is of
  2950. type title and display it as the title of the document window.
  2951. doc must be a SVG document.
  2952. ----------------------------------------------------------------------*/
  2953. static void DisplaySVGtitle (Document doc)
  2954. {
  2955. Element root, child;
  2956. SSchema SVGschema;
  2957. ElementType elType;
  2958. ThotBool found;
  2959. root = TtaGetRootElement (doc);
  2960. SVGschema = TtaGetDocumentSSchema (doc);
  2961. child = TtaGetFirstChild (root);
  2962. found = FALSE;
  2963. while (child && !found)
  2964. {
  2965. elType = TtaGetElementType (child);
  2966. if (elType.ElSSchema == SVGschema && elType.ElTypeNum == SVG_EL_title)
  2967. found = TRUE;
  2968. else
  2969. TtaNextSibling (&child);
  2970. }
  2971. if (found)
  2972. UpdateTitle (child, doc);
  2973. }
  2974. #endif /* _SVG */
  2975. /*----------------------------------------------------------------------
  2976. LoadDocument parses the new document and stores its path (or
  2977. URL) into the document table.
  2978. For a local loading, the parameter tempfile must be an empty string.
  2979. For a remote loading, the parameter tempfile gives the file name that
  2980. contains the current copy of the remote file.
  2981. Parameter realdocname is not NULL when the document is restored
  2982. ----------------------------------------------------------------------*/
  2983. Document LoadDocument (Document doc, char *pathname,
  2984. char *form_data, char *initial_url,
  2985. int method, char *tempfile,
  2986. char *documentname, AHTHeaders *http_headers,
  2987. ThotBool history, ThotBool *inNewWindow,
  2988. char *realdocname)
  2989. {
  2990. CSSInfoPtr css;
  2991. PInfoPtr pInfo;
  2992. Document newdoc = 0;
  2993. DocumentType docType;
  2994. #ifdef ANNOTATIONS
  2995. DocumentType annotBodyType = docHTML;
  2996. #endif /* ANNOTATIONS */
  2997. CHARSET charset, httpcharset;
  2998. CHARSET metacharset = UNDEFINED_CHARSET;
  2999. char charsetname[MAX_LENGTH];
  3000. char *charEncoding;
  3001. char *tempdir;
  3002. char *s, *localdoc;
  3003. char *content_type, *reason;
  3004. char *http_content_type;
  3005. int i, j;
  3006. int docProfile, extraProfile;
  3007. DocumentType thotType;
  3008. char local_content_type[MAX_LENGTH];
  3009. ThotBool unknown;
  3010. ThotBool contentImage, contentText, contentApplication;
  3011. ThotBool plainText;
  3012. ThotBool xmlDec, withDoctype, useMath, isXML, isknown;
  3013. ThotBool isRDF;
  3014. isRDF = FALSE;
  3015. unknown = TRUE;
  3016. tempdir = localdoc = NULL;
  3017. charsetname[0] = EOS;
  3018. local_content_type[0] = EOS;
  3019. http_content_type = HTTP_headers (http_headers, AM_HTTP_CONTENT_TYPE);
  3020. /* sometimes video or audio content is sent with an erroneous mime-type
  3021. "text/plain". In that case, ignore the mime-type (glitch) */
  3022. if (http_content_type && !strcmp (http_content_type, "text/plain") &&
  3023. IsUndisplayedName (pathname))
  3024. http_content_type = NULL;
  3025. /* make a copy we can modify */
  3026. if (http_content_type)
  3027. content_type = TtaStrdup (http_content_type);
  3028. else
  3029. content_type = NULL;
  3030. /* Check informations within the document */
  3031. if (tempfile[0] != EOS)
  3032. s = tempfile;
  3033. else
  3034. s = pathname;
  3035. CheckDocHeader (s, &xmlDec, &withDoctype, &isXML, &useMath, &isknown,
  3036. &docProfile, &charset, charsetname, &thotType, &extraProfile);
  3037. docType = thotType;
  3038. /* Check charset information in a meta */
  3039. if (charset == UNDEFINED_CHARSET)
  3040. CheckCharsetInMeta (s, &metacharset, charsetname);
  3041. if (method == CE_CSS)
  3042. {
  3043. /* we're loading a CSS file */
  3044. docType = docCSS;
  3045. /* if a CSS document has a xml header, CheckDocHeader will detect that the document is XML !
  3046. * (ex: http://www.inrialpes.fr has a css with a xml header :( )
  3047. * when we know that the document is CSS (method == CE_CSS) we should force docType to docCSS */
  3048. docProfile = L_CSS;
  3049. isXML = FALSE;
  3050. unknown = FALSE;
  3051. }
  3052. else if (method == CE_LOG)
  3053. {
  3054. docType = docLog;
  3055. isXML = FALSE;
  3056. unknown = FALSE;
  3057. }
  3058. else if (content_type == NULL || content_type[0] == EOS)
  3059. /* Local document - no content type */
  3060. {
  3061. /* check file name extension */
  3062. if (isXML)
  3063. {
  3064. /* it seems to be a XML document */
  3065. if (DocumentTypes[doc] == docLibrary && thotType == docHTML)
  3066. docType = docLibrary;
  3067. else
  3068. docType = thotType;
  3069. unknown = FALSE;
  3070. if (IsRDFName (pathname))
  3071. isRDF = TRUE;
  3072. else if (IsXMLStruct (pathname))
  3073. {
  3074. // only display the source of this document
  3075. docType = docText;
  3076. docProfile = L_TEXT;
  3077. isXML = FALSE;
  3078. }
  3079. }
  3080. else if (IsRDFName (pathname))
  3081. {
  3082. /* it's an RDF document. By default we assume we will
  3083. parse it as generic XML */
  3084. docType = thotType;
  3085. isRDF = TRUE;
  3086. unknown = FALSE;
  3087. }
  3088. else if (IsCSSName (pathname))
  3089. {
  3090. docType = docCSS;
  3091. docProfile = L_CSS;
  3092. unknown = FALSE;
  3093. }
  3094. else if (IsTextName (pathname))
  3095. {
  3096. docType = docText;
  3097. docProfile = L_TEXT;
  3098. unknown = FALSE;
  3099. }
  3100. else if (IsImageName (pathname))
  3101. {
  3102. /* It's a local image file that we can display. We change the
  3103. doctype flag so that we can create an HTML container later on */
  3104. docType = docImage;
  3105. unknown = FALSE;
  3106. docProfile = L_Transitional;
  3107. }
  3108. else if (IsMathMLName (pathname))
  3109. {
  3110. docType = docMath;
  3111. docProfile = L_MathML;
  3112. isXML = TRUE;
  3113. unknown = FALSE;
  3114. }
  3115. else if (IsSVGName (pathname))
  3116. {
  3117. docType = docSVG;
  3118. docProfile = L_SVG;
  3119. isXML = TRUE;
  3120. unknown = FALSE;
  3121. }
  3122. #ifdef XML_GENERIC
  3123. else if (IsXMLName (pathname))
  3124. {
  3125. docType = docXml;
  3126. isXML = TRUE;
  3127. if (IsXMLStruct (s))
  3128. {
  3129. // only display the source of this document
  3130. docType = docText;
  3131. docProfile = L_TEXT;
  3132. isXML = FALSE;
  3133. }
  3134. docProfile = L_Other;
  3135. unknown = FALSE;
  3136. }
  3137. #endif /* XML_GENERIC */
  3138. else if (docProfile != L_Other || IsHTMLName (pathname))
  3139. {
  3140. /* it seems to be an HTML document */
  3141. docType = docHTML;
  3142. unknown = FALSE;
  3143. }
  3144. else
  3145. unknown = (thotType != docHTML);
  3146. /* Assign a content type to that local document */
  3147. if (isRDF)
  3148. strcpy (local_content_type , "application/xml+rdf");
  3149. else if (docType == docCSS)
  3150. strcpy (local_content_type , "text/css");
  3151. else if (docType == docMath)
  3152. strcpy (local_content_type , AM_MATHML_MIME_TYPE);
  3153. else if (docType == docSVG)
  3154. strcpy (local_content_type , AM_SVG_MIME_TYPE);
  3155. else if (docType == docXml || docType == docTemplate)
  3156. strcpy (local_content_type , "text/xml");
  3157. else if (docType == docText || docType == docCSS ||
  3158. docType == docSource || docType == docLog )
  3159. strcpy (local_content_type , "text/plain");
  3160. else if (docType == docHTML || docType == docLibrary)
  3161. /* not defined yet */
  3162. local_content_type[0] = EOS;
  3163. }
  3164. else
  3165. /* The server returned a content type */
  3166. {
  3167. i = 0;
  3168. while (content_type[i] != URL_SEP && content_type[i] != EOS)
  3169. i++;
  3170. if (content_type[i] == URL_SEP)
  3171. {
  3172. content_type[i] = EOS;
  3173. j = i+1;
  3174. while (content_type[j] != ';' && content_type[j] != EOS)
  3175. j++;
  3176. if (content_type[j] == ';')
  3177. content_type[j] = EOS;
  3178. contentText = !strcasecmp (content_type, "text");
  3179. contentApplication = !strcasecmp (content_type, "application");
  3180. contentImage = !strcasecmp (content_type, "image");
  3181. if (contentText &&
  3182. !strncasecmp (&content_type[i+1], "html", 4))
  3183. {
  3184. if (thotType == docSVG)
  3185. {
  3186. /* ignore the mime type */
  3187. isXML = TRUE;
  3188. docType = thotType;
  3189. docProfile = L_SVG;
  3190. BADMimeType = TRUE;
  3191. }
  3192. else if (thotType == docMath)
  3193. {
  3194. /* ignore the mime type */
  3195. isXML = TRUE;
  3196. docType = thotType;
  3197. docProfile = L_MathML;
  3198. BADMimeType = TRUE;
  3199. }
  3200. else
  3201. {
  3202. /* it's an HTML document */
  3203. docType = docHTML;
  3204. if (docProfile == L_Other)
  3205. docProfile = L_Transitional;
  3206. }
  3207. unknown = FALSE;
  3208. }
  3209. else if (contentApplication &&
  3210. !strncasecmp (&content_type[i+1], "html", 4))
  3211. {
  3212. /* it's an HTML document */
  3213. docType = docHTML;
  3214. if (docProfile == L_Other)
  3215. docProfile = L_Transitional;
  3216. unknown = FALSE;
  3217. }
  3218. else if ((contentText || contentApplication) &&
  3219. (!strncasecmp (&content_type[i+1], "xhtml+xml", 9) ||
  3220. !strncasecmp (&content_type[i+1], "xhtml", 5)))
  3221. {
  3222. /* it's an xhtml document */
  3223. isXML = TRUE;
  3224. docType = docHTML;
  3225. if (docProfile == L_Other)
  3226. docProfile = L_Transitional;
  3227. unknown = FALSE;
  3228. }
  3229. else if ((contentText || contentApplication) &&
  3230. !strncasecmp (&content_type[i+1], "xml", 3) &&
  3231. content_type[i+1+3] == EOS)
  3232. {
  3233. /* Served as an XML document */
  3234. if (isXML && isknown &&
  3235. (thotType == docHTML ||
  3236. thotType == docSVG ||
  3237. thotType == docMath))
  3238. /* This type comes from the doctype or a namespace declaration */
  3239. docType = thotType;
  3240. else
  3241. {
  3242. #ifdef XML_GENERIC
  3243. docType = docXml;
  3244. isXML = TRUE;
  3245. if (IsXMLStruct (s))
  3246. {
  3247. // only display the source of this document
  3248. docType = docText;
  3249. isXML = FALSE;
  3250. docProfile = L_TEXT;
  3251. }
  3252. #else /* XML_GENERIC */
  3253. docType = docText;
  3254. docProfile = L_TEXT;
  3255. #endif /* XML_GENERIC */
  3256. }
  3257. unknown = FALSE;
  3258. }
  3259. else if (contentText &&
  3260. !strncasecmp (&content_type[i+1], "css", 3))
  3261. {
  3262. docType = docCSS;
  3263. docProfile = L_CSS;
  3264. unknown = FALSE;
  3265. }
  3266. else if ((contentText || contentApplication) &&
  3267. (!strncasecmp (&content_type[i+1], "mathml", 6) ||
  3268. !strncasecmp (&content_type[i+1], "x-mathml", 8)))
  3269. {
  3270. /* it's an MathML document */
  3271. isXML = TRUE;
  3272. docType = docMath;
  3273. docProfile = L_MathML;
  3274. unknown = FALSE;
  3275. }
  3276. else if (contentText)
  3277. {
  3278. docType = docText;
  3279. docProfile = L_TEXT;
  3280. unknown = FALSE;
  3281. }
  3282. else if (contentApplication &&
  3283. (!strncasecmp (&content_type[i+1], "x-sh", 4) ||
  3284. !strncasecmp (&content_type[i+1], "x-javascript", 12)))
  3285. {
  3286. docType = docText;
  3287. docProfile = L_TEXT;
  3288. unknown = FALSE;
  3289. }
  3290. else if (contentApplication &&
  3291. !strncasecmp (&content_type[i+1], "xml-dtd", 7))
  3292. {
  3293. /* it's an DTD document */
  3294. docType = docText;
  3295. docProfile = L_TEXT;
  3296. unknown = FALSE;
  3297. }
  3298. else if (MultipleBookmarks() &&
  3299. !strncasecmp (&content_type[i+1], "rdf+xml", 7))
  3300. {
  3301. /* it's an RDF document. By default we assume we will
  3302. parse it as generic XML */
  3303. isXML = TRUE;
  3304. isRDF = TRUE;
  3305. #ifdef XML_GENERIC
  3306. docType = docXml;
  3307. docProfile = L_Other;
  3308. #else /* XML_GENERIC */
  3309. docType = docText;
  3310. docProfile = L_TEXT;
  3311. #endif /* XML_GENERIC */
  3312. unknown = FALSE;
  3313. }
  3314. else if (contentApplication &&
  3315. !strncasecmp (&content_type[i+1], "smil", 4))
  3316. {
  3317. /* it's a SMIL document. We handle it as an XML one */
  3318. isXML = TRUE;
  3319. #ifdef XML_GENERIC
  3320. docType = docXml;
  3321. #else /* XML_GENERIC */
  3322. docType = docText;
  3323. #endif /* XML_GENERIC */
  3324. docProfile = L_Other;
  3325. unknown = FALSE;
  3326. }
  3327. else if (contentApplication &&
  3328. !strncasecmp (&content_type[i+1], "octet-stream", 12) &&
  3329. thotType == docSVG)
  3330. {
  3331. /* it's a SVG document. We handle it as an XML one */
  3332. isXML = TRUE;
  3333. docType = thotType;
  3334. unknown = FALSE;
  3335. }
  3336. else if (contentImage &&
  3337. !strncasecmp (&content_type[i+1], "svg", 3))
  3338. {
  3339. /* it's an XML document */
  3340. isXML = TRUE;
  3341. docType = docSVG;
  3342. docProfile = L_SVG;
  3343. unknown = FALSE;
  3344. }
  3345. else if (contentImage)
  3346. {
  3347. /* we'll generate a HTML document */
  3348. if (IsImageType (&content_type[i+1]))
  3349. {
  3350. docType = docImage;
  3351. unknown = FALSE;
  3352. docProfile = L_Transitional;
  3353. }
  3354. }
  3355. }
  3356. }
  3357. #ifdef BOOKMARKS
  3358. if (isRDF)
  3359. {
  3360. /* verify if it contains bookmarks */
  3361. /* we detected some bookmarks, in this rdf document */
  3362. if (BM_Open (pathname, s))
  3363. docType = docBookmark;
  3364. }
  3365. #endif /* BOOKMARKS */
  3366. if (unknown && tempfile[0] != EOS)
  3367. {
  3368. /* The document is not a supported format and cannot be parsed */
  3369. /* rename the temporary file */
  3370. strcpy (SavingFile, tempfile);
  3371. SavingDocument = 0;
  3372. SavingObject = 0;
  3373. TtaFreeMemory (localdoc);
  3374. // generate the saving path
  3375. localdoc = (char *)TtaGetMemory (MAX_LENGTH);
  3376. TtaExtractName (pathname, tempfile, localdoc);
  3377. /* reinitialize directories and document lists */
  3378. strcpy (SavePath, DirectoryName);
  3379. strcpy (SaveName, localdoc);
  3380. strcpy (localdoc, SavePath);
  3381. strcat (localdoc, DIR_STR);
  3382. strcat (localdoc, SaveName);
  3383. ResetStop (doc);
  3384. InitSaveObjectForm (doc, 1, SavingFile, localdoc);
  3385. }
  3386. else if (pathname[0] != EOS)
  3387. {
  3388. if (method != CE_MAKEBOOK && method != CE_TEMPLATE)
  3389. {
  3390. /* do not register and open the document view */
  3391. if (DocumentURLs[doc])
  3392. {
  3393. /* save the URL of the old document in the history, if the same
  3394. window is reused, i.e. if the old document has not been
  3395. modified */
  3396. if (history && !TtaIsDocumentModified (doc))
  3397. AddDocHistory (doc, DocumentURLs[doc],
  3398. DocumentMeta[doc]->initial_url,
  3399. DocumentMeta[doc]->form_data,
  3400. DocumentMeta[doc]->method);
  3401. }
  3402. if (method == CE_RELATIVE)
  3403. {
  3404. if (TtaIsDocumentModified (doc) || docType == docCSS)
  3405. {
  3406. /* open a new window to display the new document */
  3407. newdoc = InitDocAndView (doc,
  3408. FALSE /* replaceOldDoc */,
  3409. TRUE /* inNewWindow */,
  3410. documentname, docType, 0, FALSE,
  3411. docProfile, extraProfile, method);
  3412. ResetStop (doc);
  3413. /* clear the status line of previous document */
  3414. TtaSetStatus (doc, 1, " ", NULL);
  3415. ActiveTransfer (newdoc);
  3416. }
  3417. else
  3418. /* replace the current document by a new one */
  3419. newdoc = InitDocAndView (doc,
  3420. TRUE /* replaceOldDoc */,
  3421. FALSE /* inNewWindow */,
  3422. documentname, docType, 0, FALSE,
  3423. docProfile, extraProfile, method);
  3424. }
  3425. else if (method == CE_ABSOLUTE || method == CE_HELP ||
  3426. method == CE_FORM_POST || method == CE_FORM_GET)
  3427. /* replace the current document by a new one */
  3428. newdoc = InitDocAndView (doc,
  3429. TRUE /* replaceOldDoc */,
  3430. FALSE /* inNewWindow */,
  3431. documentname, docType, 0, FALSE,
  3432. docProfile, extraProfile, method);
  3433. #ifdef ANNOTATIONS
  3434. else if (method == CE_ANNOT) /* && docType == docHTML) */
  3435. {
  3436. /* create the body */
  3437. ANNOT_CreateBodyTree (doc, docType);
  3438. /* and remember its type of the body */
  3439. annotBodyType = docType;
  3440. docType = docAnnot;
  3441. newdoc = doc;
  3442. }
  3443. #endif /* ANNOTATIONS */
  3444. else if (method == CE_LOG)
  3445. {
  3446. docType = docLog;
  3447. newdoc = doc;
  3448. /* the LOG window labels have UTF8 charset on wxWidgets interface */
  3449. charset = UTF_8;
  3450. }
  3451. else if (docType != DocumentTypes[doc] && DocumentTypes[doc] != docLibrary)
  3452. /* replace the current document by a new one */
  3453. newdoc = InitDocAndView (doc,
  3454. TRUE /* replaceOldDoc */,
  3455. FALSE /* inNewWindow */,
  3456. documentname, docType, 0, FALSE,
  3457. docProfile, extraProfile, method);
  3458. else
  3459. {
  3460. /* document already initialized */
  3461. newdoc = doc;
  3462. /* store the profile of the new document */
  3463. /* and update the menus according to it */
  3464. TtaSetDocumentProfile (newdoc, docProfile, extraProfile);
  3465. }
  3466. }
  3467. else
  3468. newdoc = doc;
  3469. DocumentTypes[newdoc] = docType;
  3470. if (docType == docImage)
  3471. /* create an HTML container */
  3472. {
  3473. if (content_type)
  3474. /* it's an image downloaded from the web */
  3475. CreateHTMLContainer (pathname, documentname, tempfile, FALSE);
  3476. else
  3477. {
  3478. /* It's a local image file */
  3479. sprintf (tempfile, "%s%c%d%c%s", TempFileDirectory,
  3480. DIR_SEP, newdoc, DIR_SEP, "contain.html");
  3481. CreateHTMLContainer (pathname, documentname, tempfile, TRUE);
  3482. }
  3483. }
  3484. localdoc = GetLocalPath (newdoc, pathname);
  3485. /* what we have to do if doc and targetDocument are different */
  3486. if (method == CE_INSTANCE && TtaFileExist (localdoc))
  3487. // only the temporary file exists
  3488. CheckDocHeader (localdoc, &xmlDec, &withDoctype, &isXML, &useMath, &isknown,
  3489. &docProfile, &charset, charsetname, &thotType, &extraProfile);
  3490. else if (tempfile[0] != EOS)
  3491. {
  3492. /* It is a document loaded from the Web */
  3493. if (!TtaFileExist (tempfile))
  3494. {
  3495. /* Nothing is loaded */
  3496. ResetStop (doc);
  3497. TtaFreeMemory (localdoc);
  3498. TtaFreeMemory (content_type);
  3499. return (0);
  3500. }
  3501. /* we have to rename the temporary file */
  3502. // the loaded file is different
  3503. TtaFileUnlink (localdoc);
  3504. if (doc != newdoc)
  3505. {
  3506. /* now we can rename the local name of a remote document */
  3507. TtaFileCopy (tempfile, localdoc);
  3508. TtaFileUnlink (tempfile);
  3509. /* if it's an IMAGEfile, we copy it too to the new directory */
  3510. if (DocumentTypes[newdoc] == docImage)
  3511. MoveImageFile (doc, newdoc, documentname);
  3512. }
  3513. else if (DocumentTypes[newdoc] == docCSS)
  3514. TtaFileCopy (tempfile, localdoc);
  3515. /* now we can rename the local name of a remote document */
  3516. else
  3517. /* now we can rename the local name of a remote document */
  3518. TtaFileRename (tempfile, localdoc);
  3519. }
  3520. else
  3521. {
  3522. /* store a copy of the local document */
  3523. /* allocate and initialize a teporary document */
  3524. if (method != CE_INSTANCE || !TtaFileExist (localdoc))
  3525. TtaFileCopy (pathname, localdoc);
  3526. }
  3527. #ifdef BOOKMARKS
  3528. if (docType == docBookmark)
  3529. /* update the corresponding bookmark context to point to the new tmpfile */
  3530. BM_TempFileSet (pathname, localdoc);
  3531. #endif /* BOOKMARKS */
  3532. /* store a copy of CSS files in the directory 0 */
  3533. if (DocumentTypes[newdoc] == docCSS)
  3534. {
  3535. css = SearchCSS (0, pathname, NULL, &pInfo);
  3536. if (css == NULL)
  3537. {
  3538. /* store a copy of this new CSS context in .amaya/0 */
  3539. s = GetLocalPath (0, pathname);
  3540. TtaFileCopy (localdoc, s);
  3541. /* initialize a new CSS context */
  3542. if (UserCSS && !strcmp (pathname, UserCSS))
  3543. AddCSS (newdoc, 0, CSS_USER_STYLE, CSS_ALL, NULL, s, NULL);
  3544. else
  3545. AddCSS (newdoc, 0, CSS_EXTERNAL_STYLE, CSS_ALL, pathname, s, NULL);
  3546. TtaFreeMemory (s);
  3547. }
  3548. else
  3549. css->doc = newdoc;
  3550. }
  3551. /* save the document name into the document table */
  3552. if (realdocname)
  3553. s = TtaStrdup (realdocname);
  3554. else
  3555. s = TtaStrdup (pathname);
  3556. if (DocumentURLs[newdoc] != NULL)
  3557. {
  3558. TtaFreeMemory (DocumentURLs[newdoc]);
  3559. DocumentURLs[newdoc] = NULL;
  3560. }
  3561. /* if the document was already loaded, warn the user */
  3562. if (method != CE_TEMPLATE && IsDocumentLoaded (s, form_data))
  3563. InitConfirm3L (newdoc, 1, TtaGetMessage (AMAYA, AM_DOUBLE_LOAD),
  3564. TtaGetMessage (AMAYA, AM_UNSAVE), NULL, FALSE);
  3565. DocumentURLs[newdoc] = s;
  3566. /* save the document's formdata into the document table */
  3567. if (DocumentMeta[newdoc] != NULL)
  3568. DocumentMetaClear (DocumentMeta[newdoc]);
  3569. else
  3570. DocumentMeta[newdoc] = DocumentMetaDataAlloc ();
  3571. DocumentMeta[newdoc]->form_data = TtaStrdup (form_data);
  3572. if (initial_url && strcmp (pathname, initial_url))
  3573. DocumentMeta[newdoc]->initial_url = TtaStrdup (initial_url);
  3574. else
  3575. DocumentMeta[newdoc]->initial_url = NULL;
  3576. reason = HTTP_headers (http_headers, AM_HTTP_REASON);
  3577. if (reason && strcasecmp (reason, "OK"))
  3578. DocumentMeta[newdoc]->reason = TtaStrdup (reason);
  3579. DocumentMeta[newdoc]->method = method;
  3580. DocumentSource[newdoc] = 0;
  3581. DocumentMeta[newdoc]->xmlformat = isXML;
  3582. DocumentMeta[newdoc]->compound = FALSE;
  3583. /* Clear the current status path */
  3584. if (docType != docLog)
  3585. TtaSetStatusSelectedElement (newdoc, 1, NULL);
  3586. /* Set character encoding */
  3587. DocumentMeta[newdoc]->charset = NULL;
  3588. charEncoding = HTTP_headers (http_headers, AM_HTTP_CHARSET);
  3589. httpcharset = TtaGetCharset (charEncoding);
  3590. if (httpcharset != UNDEFINED_CHARSET &&
  3591. httpcharset != UNSUPPORTED_CHARSET && charEncoding)
  3592. {
  3593. TtaSetDocumentCharset (newdoc, httpcharset, FALSE);
  3594. DocumentMeta[newdoc]->charset = TtaStrdup (charEncoding);
  3595. }
  3596. else if (charset != UNDEFINED_CHARSET)
  3597. {
  3598. TtaSetDocumentCharset (newdoc, charset, FALSE);
  3599. DocumentMeta[newdoc]->charset = TtaStrdup (charsetname);
  3600. }
  3601. else if (metacharset != UNDEFINED_CHARSET)
  3602. {
  3603. TtaSetDocumentCharset (newdoc, metacharset, FALSE);
  3604. DocumentMeta[newdoc]->charset = TtaStrdup (charsetname);
  3605. }
  3606. else if (charsetname[0] != EOS)
  3607. DocumentMeta[newdoc]->charset = TtaStrdup (charsetname);
  3608. else if (docType == docCSS || docType == docText)
  3609. {
  3610. TtaSetDocumentCharset (newdoc, ISO_8859_1, FALSE);
  3611. DocumentMeta[newdoc]->charset = TtaStrdup ("iso-8859-1");
  3612. }
  3613. /*
  3614. ** copy some HTTP headers to the metadata
  3615. */
  3616. /* content-type */
  3617. if (http_content_type)
  3618. DocumentMeta[newdoc]->content_type = TtaStrdup (http_content_type);
  3619. else if (local_content_type[0] != EOS)
  3620. /* assign a content type to the local files */
  3621. DocumentMeta[newdoc]->content_type = TtaStrdup (local_content_type);
  3622. else
  3623. DocumentMeta[newdoc]->content_type = NULL;
  3624. /* content-length */
  3625. s = HTTP_headers (http_headers, AM_HTTP_CONTENT_LENGTH);
  3626. if (s)
  3627. DocumentMeta[newdoc]->content_length = TtaStrdup (s);
  3628. else
  3629. DocumentMeta[newdoc]->content_length = NULL;
  3630. /* simplified content-location */
  3631. s = HTTP_headers (http_headers, AM_HTTP_CONTENT_LOCATION);
  3632. if (s)
  3633. DocumentMeta[newdoc]->content_location = TtaStrdup (s);
  3634. else
  3635. DocumentMeta[newdoc]->content_location = NULL;
  3636. /* full content-location */
  3637. s = HTTP_headers (http_headers, AM_HTTP_FULL_CONTENT_LOCATION);
  3638. if (s)
  3639. DocumentMeta[newdoc]->full_content_location = TtaStrdup (s);
  3640. else
  3641. DocumentMeta[newdoc]->full_content_location = NULL;
  3642. if (TtaGetViewFrame (newdoc, 1) != 0)
  3643. /* this document is displayed */
  3644. {
  3645. if (DocumentTypes[newdoc] != docLog)
  3646. {
  3647. #ifdef _SVG
  3648. if (DocumentTypes[newdoc] == docLibrary)
  3649. TtaSetTextZone (newdoc, 1, SVGlib_list);
  3650. else
  3651. #endif /* _SVG */
  3652. TtaSetTextZone (newdoc, 1, URL_list);
  3653. }
  3654. }
  3655. tempdir = (char *)TtaGetMemory (MAX_LENGTH);
  3656. TtaExtractName (localdoc, tempdir, documentname);
  3657. /* Now we forget the method CE_INIT. It's a standard method */
  3658. if (DocumentMeta[newdoc]->method == CE_INIT)
  3659. DocumentMeta[newdoc]->method = CE_ABSOLUTE;
  3660. // Check if we are loading a template
  3661. if (DocumentMeta[newdoc]->method == CE_ABSOLUTE &&
  3662. IsXTiger (documentname))
  3663. DocumentMeta[newdoc]->method = CE_TEMPLATE;
  3664. if (IsXMLDocType (newdoc) ||
  3665. #ifdef ANNOTATIONS
  3666. (docType == docAnnot && annotBodyType != docText) ||
  3667. #endif /* ANNOTATIONS */
  3668. docType == docBookmark)
  3669. plainText = FALSE;
  3670. else
  3671. plainText = (docProfile == L_Other || docProfile == L_CSS || docProfile == L_TEXT);
  3672. #ifdef BOOKMARKS
  3673. if (docType == docBookmark)
  3674. BM_ViewBookmarks (newdoc, 1, FALSE);
  3675. else
  3676. #endif /* BOOKMARKS */
  3677. {
  3678. // Get user information about read IDs
  3679. TtaGetEnvBoolean ("CHECK_READ_IDS", &Check_read_ids);
  3680. /* Calls the corresponding parser */
  3681. if (DocumentMeta[newdoc]->xmlformat && !plainText)
  3682. StartXmlParser (newdoc, localdoc, documentname, tempdir,
  3683. pathname, xmlDec, withDoctype, useMath, FALSE);
  3684. else
  3685. StartParser (newdoc, localdoc, documentname, tempdir,
  3686. pathname, plainText, FALSE);
  3687. }
  3688. TtaFreeMemory (tempdir);
  3689. /* Update the Doctype menu */
  3690. TtaSetDocumentProfile (newdoc, docProfile, extraProfile);
  3691. UpdateEditorMenus (newdoc);
  3692. if (*inNewWindow || newdoc != doc)
  3693. /* the document is displayed in a different window */
  3694. /* reset the history of the new window */
  3695. InitDocHistory (newdoc);
  3696. #ifdef _SVG
  3697. if (docType == docSVG)
  3698. /* for a SVG document, get the first title element that is a child
  3699. of the SVG root element and display its contents as the window
  3700. title */
  3701. DisplaySVGtitle (newdoc);
  3702. #endif /* _SVG */
  3703. /* the document is loaded now */
  3704. *inNewWindow = FALSE;
  3705. #ifdef ANNOTATIONS
  3706. /* store the annotation body type (we have to wait until now as
  3707. the metadata didn't exist before) */
  3708. if (docType == docAnnot)
  3709. ANNOT_bodyType_set (newdoc, annotBodyType);
  3710. #endif /* ANNOTATIONS */
  3711. }
  3712. // refresh the XML panel
  3713. TtaRefreshElementMenu (newdoc, 1);
  3714. TtaFreeMemory (content_type);
  3715. TtaFreeMemory (localdoc);
  3716. TtaClearUndoHistory (newdoc);
  3717. return (newdoc);
  3718. }
  3719. /*----------------------------------------------------------------------
  3720. Reload_callback
  3721. The urlName is encoded with the default charset.
  3722. ----------------------------------------------------------------------*/
  3723. void Reload_callback (int doc, int status, char *urlName, char *outputfile,
  3724. char *proxyName, AHTHeaders *http_headers, void * context)
  3725. {
  3726. Document newdoc;
  3727. char *tempfile;
  3728. char *documentname;
  3729. char *form_data;
  3730. char *initial_url, *ptr;
  3731. int method;
  3732. Document res = 0;
  3733. Element el;
  3734. RELOAD_context *ctx;
  3735. int visibility;
  3736. ThotBool stopped_flag = FALSE, keep;
  3737. ThotBool withStruct = FALSE, withSrc = FALSE;
  3738. #ifdef _JAVA
  3739. /* Switch OFF the Javascipt/DOM engine before loading the document */
  3740. StopJavascript(doc);
  3741. #endif /* _JAVA */
  3742. /* restore the context associated with the request */
  3743. ctx = (RELOAD_context *) context;
  3744. documentname = ctx->documentname;
  3745. newdoc = ctx->newdoc;
  3746. form_data = ctx->form_data;
  3747. method = ctx->method;
  3748. visibility = ctx->visibility;
  3749. MapAreas[doc] = ctx->maparea;
  3750. withSrc = ctx->withSrc;
  3751. withStruct = ctx->withStruct;
  3752. if (!DocumentURLs[doc])
  3753. /* the user has closed the corresponding document. Just free resources */
  3754. {
  3755. TtaFreeMemory (documentname);
  3756. if (form_data)
  3757. TtaFreeMemory (form_data);
  3758. TtaFreeMemory (ctx);
  3759. return;
  3760. }
  3761. tempfile = outputfile;
  3762. if (status == 0)
  3763. {
  3764. TtaSetCursorWatch (0, 0);
  3765. /* a bit of acrobatics so that we can retain the initial_url
  3766. without reallocating memory */
  3767. initial_url = DocumentMeta[doc]->initial_url;
  3768. DocumentMeta[doc]->initial_url = NULL;
  3769. TtaClearUndoHistory (newdoc);
  3770. RemoveParsingErrors (newdoc);
  3771. /* add the URI in the combobox string */
  3772. if (method != CE_MAKEBOOK && method != CE_TEMPLATE && method != CE_ANNOT &&
  3773. method != CE_LOG && method != CE_HELP &&
  3774. DocumentTypes[newdoc] != docLibrary &&
  3775. status == 0)
  3776. {
  3777. /* add the URI in the combobox string */
  3778. keep = (method == CE_ABSOLUTE || method == CE_INIT || method == CE_INSTANCE);
  3779. if (form_data && method == CE_FORM_GET)
  3780. AddURLInCombobox (urlName, form_data, keep);
  3781. else
  3782. AddURLInCombobox (urlName, NULL, keep);
  3783. }
  3784. /* parse and display the document, res contains the new document
  3785. identifier, as given by the thotlib */
  3786. res = LoadDocument (newdoc, urlName, form_data, NULL, method,
  3787. tempfile, documentname, http_headers, FALSE,
  3788. &DontReplaceOldDoc, NULL);
  3789. #ifdef TEMPLATES
  3790. // Fill template internal structures and prepare the instance if any
  3791. Template_FillFromDocument (doc);
  3792. #endif /* TEMPLATES */
  3793. UpdateEditorMenus (doc);
  3794. if (visibility == 4)
  3795. {
  3796. // restore the visibility
  3797. TtaSetSensibility (doc, 1, visibility);
  3798. TtaSetToggleItem (doc, 1, Views, TShowTargets, TRUE);
  3799. }
  3800. if (MapAreas[doc])
  3801. // set Map areas visible
  3802. TtaSetToggleItem (doc, 1, Views, TShowMapAreas, TRUE);
  3803. if (res == 0)
  3804. {
  3805. /* cannot load the document */
  3806. ResetStop(newdoc);
  3807. newdoc = 0;
  3808. TtaFreeMemory (initial_url);
  3809. }
  3810. else if (newdoc != res)
  3811. {
  3812. newdoc = res;
  3813. /* restore the initial_url */
  3814. DocumentMeta[newdoc]->initial_url = initial_url;
  3815. }
  3816. if (newdoc)
  3817. {
  3818. W3Loading = 0; /* loading is complete now */
  3819. #ifdef ANNOTATIONS
  3820. /* if it's an annotation, add the existing metadata */
  3821. if (DocumentTypes[newdoc] == docAnnot)
  3822. ANNOT_ReloadAnnotMeta (newdoc);
  3823. /* auto-load the annotations associated with the document */
  3824. if (ANNOT_CanAnnotate (newdoc))
  3825. ANNOT_AutoLoad (newdoc, 1);
  3826. #endif /* ANNOTATIONS */
  3827. TtaHandlePendingEvents ();
  3828. // set the default icon
  3829. TtaSetPageIcon (newdoc, 1, NULL);
  3830. /* fetch and display all images referred by the document */
  3831. stopped_flag = FetchAndDisplayImages (newdoc, AMAYA_NOCACHE | AMAYA_LOAD_IMAGE, NULL);
  3832. if (stopped_flag == FALSE)
  3833. {
  3834. TtaResetCursor (0, 0);
  3835. /* show the document at the same position as before Reload */
  3836. el = ElementAtPosition (newdoc, ctx->position);
  3837. TtaShowElement (newdoc, 1, el, ctx->distance);
  3838. }
  3839. }
  3840. }
  3841. if (stopped_flag == FALSE && newdoc)
  3842. {
  3843. ResetStop (newdoc);
  3844. #ifdef _GL
  3845. if (FilesLoading[newdoc] == 0 &&
  3846. TtaGetViewFrame (newdoc, 1) != 0)
  3847. /* all files included in this document have been loaded and the
  3848. document is displayed. Animations can be played now */
  3849. TtaPlay (newdoc, 1);
  3850. #endif /* _GL */
  3851. }
  3852. /* check parsing errors */
  3853. CheckParsingErrors (newdoc);
  3854. if (DocumentTypes[newdoc] == docCSS)
  3855. {
  3856. /* reapply the CSS to relative documents */
  3857. ptr = GetLocalPath (newdoc, DocumentURLs[newdoc]);
  3858. UpdateStyleSheet (DocumentURLs[newdoc], ptr);
  3859. TtaFreeMemory (ptr);
  3860. }
  3861. #ifdef DAV
  3862. /* MKP: if document has been loaded, we are *
  3863. * able to discovery if the document is locked. *
  3864. * do a lock discovery, set LockIndicator button */
  3865. if (W3Loading == 0 && res > 0)
  3866. DAVLockDiscovery (newdoc);
  3867. #else /* DAV */
  3868. // no lock/unlock allowed
  3869. TtaSetLockButton (newdoc, 0);
  3870. #endif /* DAV */
  3871. if (DocumentTypes[newdoc] == docBookmark && TtaIsDocumentModified (newdoc))
  3872. DocStatusUpdate (newdoc, TRUE);
  3873. else
  3874. DocStatusUpdate (newdoc, FALSE);
  3875. TtaFreeMemory (documentname);
  3876. if (form_data)
  3877. TtaFreeMemory (form_data);
  3878. TtaFreeMemory (ctx);
  3879. if (withSrc)
  3880. ShowSource (newdoc, 1);
  3881. if (withStruct)
  3882. ShowStructure (newdoc, 1);
  3883. }
  3884. /*----------------------------------------------------------------------
  3885. Reload
  3886. ----------------------------------------------------------------------*/
  3887. void Reload (Document doc, View view)
  3888. {
  3889. RELOAD_context *ctx;
  3890. char *tempfile, *pathname;
  3891. char *documentname, *form_data;
  3892. char viewName[30];
  3893. int toparse, method;
  3894. int mode, position, distance;
  3895. ThotBool withStruct = FALSE, withSrc = FALSE;
  3896. if (DocumentURLs[doc] == NULL)
  3897. /* the document has not been loaded yet */
  3898. return;
  3899. // synchronize information
  3900. HighlightDocument = 0;
  3901. HighlightElement = NULL;
  3902. HighLightAttribute = NULL;
  3903. /* if it is a source document, reload its corresponding document */
  3904. if (DocumentTypes[doc] == docSource)
  3905. {
  3906. doc = GetDocFromSource (doc);
  3907. withSrc = TRUE;
  3908. }
  3909. else if (DocumentTypes[doc] != docCSS &&
  3910. DocumentTypes[doc] != docLog &&
  3911. DocumentTypes[doc] != docText)
  3912. {
  3913. // check if the source or structure view is open
  3914. withSrc = DocumentSource[doc] != 0;
  3915. if (!withSrc)
  3916. {
  3917. strcpy (viewName, "Structure_view");
  3918. view = TtaGetViewFromName (doc, viewName);
  3919. withStruct = (view != 0 && TtaIsViewOpen (doc, view));
  3920. }
  3921. }
  3922. /* abort all current exchanges concerning this document */
  3923. StopTransfer (doc, 1);
  3924. if (!CanReplaceCurrentDocument (doc, 1))
  3925. /* abort the command */
  3926. return;
  3927. /* reload the document */
  3928. pathname = (char *)TtaGetMemory (MAX_LENGTH);
  3929. documentname = (char *)TtaGetMemory (MAX_LENGTH);
  3930. #ifdef TODO
  3931. /* if the document is a template, restore the template script URL */
  3932. if (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_TEMPLATE)
  3933. ReloadTemplateParams (&(DocumentURLs[doc]), &(DocumentMeta[doc]->method));
  3934. #endif //TODO
  3935. NormalizeURL (DocumentURLs[doc], 0, pathname, documentname, NULL);
  3936. if (!IsW3Path (pathname) && !TtaFileExist (pathname))
  3937. {
  3938. /* Free Memory */
  3939. TtaFreeMemory (pathname);
  3940. TtaFreeMemory (documentname);
  3941. /* cannot reload this document */
  3942. return;
  3943. }
  3944. if (DocumentMeta[doc]->form_data)
  3945. form_data = TtaStrdup (DocumentMeta[doc]->form_data);
  3946. else
  3947. form_data = NULL;
  3948. if (DocumentTypes[doc] == docAnnot)
  3949. method = CE_ANNOT;
  3950. else
  3951. method = DocumentMeta[doc]->method;
  3952. /* get the current position in the document */
  3953. position = RelativePosition (doc, &distance);
  3954. W3Loading = doc; /* this document is currently in load */
  3955. mode = AMAYA_ASYNC | AMAYA_NOCACHE | AMAYA_FLUSH_REQUEST;
  3956. if (method == CE_FORM_POST)
  3957. mode |= AMAYA_FORM_POST;
  3958. // force the reload of CSS files
  3959. RemoveDocCSSs (doc, TRUE);
  3960. tempfile = (char *)TtaGetMemory (MAX_LENGTH);
  3961. tempfile[0] = EOS;
  3962. toparse = 0;
  3963. ActiveTransfer (doc);
  3964. /* Create the context for the callback */
  3965. ctx = (RELOAD_context*)TtaGetMemory (sizeof (RELOAD_context));
  3966. ctx->newdoc = doc;
  3967. ctx->documentname = documentname;
  3968. ctx->form_data = form_data;
  3969. ctx->method = method;
  3970. ctx->position = position;
  3971. ctx->distance = distance;
  3972. ctx->visibility = TtaGetSensibility (doc, 1);
  3973. ctx->maparea = MapAreas[doc];
  3974. ctx->withSrc = withSrc;
  3975. ctx->withStruct = withStruct;
  3976. if (IsW3Path (pathname))
  3977. {
  3978. /* load the document from the Web */
  3979. toparse = GetObjectWWW (doc, 0, pathname, form_data,
  3980. tempfile, mode, NULL, NULL,
  3981. (void (*)(int, int, char*, char*, char*, const AHTHeaders*, void*)) Reload_callback,
  3982. (void *) ctx, YES, NULL);
  3983. }
  3984. else if (TtaFileExist (pathname))
  3985. Reload_callback (doc, 0, pathname, tempfile, NULL, NULL, (void *) ctx);
  3986. TtaFreeMemory (tempfile);
  3987. TtaFreeMemory (pathname);
  3988. TtaHandlePendingEvents ();
  3989. }
  3990. /*----------------------------------------------------------------------
  3991. ----------------------------------------------------------------------*/
  3992. void ShowTargets (Document document, View view)
  3993. {
  3994. int visibility;
  3995. View tocView;
  3996. visibility = TtaGetSensibility (document, view);
  3997. if (visibility == 4)
  3998. {
  3999. visibility = 5;
  4000. TtaSetToggleItem (document, 1, Views, TShowTargets, FALSE);
  4001. }
  4002. else
  4003. {
  4004. visibility = 4;
  4005. TtaSetToggleItem (document, 1, Views, TShowTargets, TRUE);
  4006. }
  4007. /* Change visibility threshold in the main view */
  4008. TtaSetSensibility (document, view, visibility);
  4009. /* Change visibility threshold in the table of content view if it's open */
  4010. tocView = TtaGetViewFromName (document, "Table_of_contents");
  4011. if (tocView && TtaIsViewOpen (document, tocView))
  4012. TtaSetSensibility (document, tocView, visibility);
  4013. }
  4014. /*----------------------------------------------------------------------
  4015. ----------------------------------------------------------------------*/
  4016. void ZoomIn (Document document, View view)
  4017. {
  4018. int zoom, zoomVal;
  4019. zoom = TtaGetZoom (document, view);
  4020. if (zoom < 10)
  4021. {
  4022. zoom++;
  4023. TtaSetZoom (document, view, zoom);
  4024. }
  4025. /* compare to the standard value? */
  4026. TtaGetEnvInt ("ZOOM", &zoomVal);
  4027. TtaSetToggleItem (document, 1, Views, TZoomIn, zoom > zoomVal);
  4028. TtaSetToggleItem (document, 1, Views, TZoomOut, zoom < zoomVal);
  4029. }
  4030. /*----------------------------------------------------------------------
  4031. ----------------------------------------------------------------------*/
  4032. void ZoomOut (Document document, View view)
  4033. {
  4034. int zoom, zoomVal;
  4035. zoom = TtaGetZoom (document, view);
  4036. if (zoom > -10)
  4037. {
  4038. zoom--;
  4039. TtaSetZoom (document, view, zoom);
  4040. }
  4041. /* compare to the standard value? */
  4042. TtaGetEnvInt ("ZOOM", &zoomVal);
  4043. TtaSetToggleItem (document, 1, Views, TZoomIn, zoom > zoomVal);
  4044. TtaSetToggleItem (document, 1, Views, TZoomOut, zoom < zoomVal);
  4045. }
  4046. /*----------------------------------------------------------------------
  4047. ----------------------------------------------------------------------*/
  4048. void ZoomNormal (Document document, View view)
  4049. {
  4050. int zoom, zoomVal;
  4051. zoom = TtaGetZoom (document, view);
  4052. TtaGetEnvInt ("ZOOM", &zoomVal);
  4053. if(zoom != zoomVal)
  4054. {
  4055. TtaSetZoom (document, view, zoomVal);
  4056. TtaSetToggleItem (document, 1, Views, TZoomIn, FALSE);
  4057. TtaSetToggleItem (document, 1, Views, TZoomOut, FALSE);
  4058. }
  4059. }
  4060. /*----------------------------------------------------------------------
  4061. ShowSource
  4062. Display the source code of a document
  4063. ----------------------------------------------------------------------*/
  4064. void ShowSource (Document doc, View view)
  4065. {
  4066. Element root;
  4067. CHARSET charset;
  4068. char *localFile;
  4069. char *s;
  4070. char documentname[MAX_LENGTH];
  4071. char tempdir[MAX_LENGTH];
  4072. Document sourceDoc;
  4073. NotifyElement event;
  4074. if (!DocumentURLs[doc])
  4075. /* the document is not loaded yet */
  4076. return;
  4077. if (!IsXMLDocType (doc))
  4078. /* it's not an HTML or an XML document */
  4079. return;
  4080. if (!strcmp (DocumentURLs[doc], "empty"))
  4081. return;
  4082. if (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_HELP)
  4083. return;
  4084. if (DocumentSource[doc])
  4085. /* the source code of this document is already shown */
  4086. /* raise its window */
  4087. TtaRaiseView (DocumentSource[doc], 1);
  4088. else
  4089. {
  4090. /* save the current state of the document into the temporary file */
  4091. localFile = GetLocalPath (doc, DocumentURLs[doc]);
  4092. if (TtaIsDocumentModified (doc) || !TtaFileExist (localFile))
  4093. {
  4094. SetNamespacesAndDTD (doc, FALSE);
  4095. if (DocumentTypes[doc] == docLibrary ||
  4096. DocumentTypes[doc] == docHTML)
  4097. {
  4098. if (TtaGetDocumentProfile (doc) == L_Xhtml11 || TtaGetDocumentProfile (doc) == L_Basic)
  4099. TtaExportDocumentWithNewLineNumbers (doc, localFile,
  4100. "HTMLT11", FALSE);
  4101. else if (DocumentMeta[doc]->xmlformat)
  4102. TtaExportDocumentWithNewLineNumbers (doc, localFile,
  4103. "HTMLTX", FALSE);
  4104. else
  4105. TtaExportDocumentWithNewLineNumbers (doc, localFile,
  4106. "HTMLT", FALSE);
  4107. }
  4108. else if (DocumentTypes[doc] == docSVG)
  4109. TtaExportDocumentWithNewLineNumbers (doc, localFile,
  4110. "SVGT", FALSE);
  4111. else if (DocumentTypes[doc] == docMath)
  4112. TtaExportDocumentWithNewLineNumbers (doc, localFile,
  4113. "MathMLT", FALSE);
  4114. else if (DocumentTypes[doc] == docTemplate)
  4115. TtaExportDocumentWithNewLineNumbers (doc, localFile,
  4116. "TemplateT", FALSE);
  4117. #ifdef XML_GENERIC
  4118. else if (DocumentTypes[doc] == docXml)
  4119. TtaExportDocumentWithNewLineNumbers (doc, localFile, NULL, FALSE);
  4120. #endif /* XML_GENERIC */
  4121. }
  4122. TtaExtractName (localFile, tempdir, documentname);
  4123. /* open a window for the source code */
  4124. sourceDoc = InitDocAndView (doc,
  4125. FALSE /* replaceOldDoc */,
  4126. FALSE /* inNewWindow */,
  4127. documentname, (DocumentType)docSource, doc, FALSE,
  4128. TtaGetDocumentProfile (doc), TtaGetDocumentExtraProfile (doc),
  4129. (int)CE_ABSOLUTE);
  4130. if (sourceDoc > 0)
  4131. {
  4132. DocumentSource[doc] = sourceDoc;
  4133. s = TtaStrdup (DocumentURLs[doc]);
  4134. DocumentURLs[sourceDoc] = s;
  4135. DocumentMeta[sourceDoc] = DocumentMetaDataAlloc ();
  4136. DocumentMeta[sourceDoc]->form_data = NULL;
  4137. DocumentMeta[sourceDoc]->initial_url = NULL;
  4138. DocumentMeta[sourceDoc]->method = CE_ABSOLUTE;
  4139. DocumentMeta[sourceDoc]->xmlformat = FALSE;
  4140. DocumentMeta[sourceDoc]->compound = FALSE;
  4141. /* copy the MIME type, charset, and content location */
  4142. if (DocumentMeta[doc])
  4143. {
  4144. if (DocumentMeta[doc]->content_type)
  4145. DocumentMeta[sourceDoc]->content_type = TtaStrdup (DocumentMeta[doc]->content_type);
  4146. if (DocumentMeta[doc]->charset)
  4147. DocumentMeta[sourceDoc]->charset = TtaStrdup (DocumentMeta[doc]->charset);
  4148. if (DocumentMeta[doc]->content_location)
  4149. DocumentMeta[sourceDoc]->content_location = TtaStrdup (DocumentMeta[doc]->content_location);
  4150. if (DocumentMeta[doc]->full_content_location)
  4151. DocumentMeta[sourceDoc]->full_content_location = TtaStrdup (DocumentMeta[doc]->full_content_location);
  4152. }
  4153. DocumentTypes[sourceDoc] = docSource;
  4154. charset = TtaGetDocumentCharset (doc);
  4155. if (charset == UNDEFINED_CHARSET)
  4156. {
  4157. if (DocumentMeta[doc] && DocumentMeta[doc]->xmlformat)
  4158. TtaSetDocumentCharset (SavingDocument, UTF_8, FALSE);
  4159. else
  4160. TtaSetDocumentCharset (SavingDocument, ISO_8859_1, FALSE);
  4161. }
  4162. else
  4163. TtaSetDocumentCharset (sourceDoc, charset, FALSE);
  4164. DocNetworkStatus[sourceDoc] = AMAYA_NET_INACTIVE;
  4165. StartParser (sourceDoc, localFile, documentname, tempdir,
  4166. localFile, TRUE, FALSE);
  4167. SetWindowTitle (doc, sourceDoc, 0);
  4168. /* Switch the synchronization entry */
  4169. if (TtaIsDocumentModified (doc))
  4170. {
  4171. // views are synchronized
  4172. TtaSetDocumentModified (sourceDoc);
  4173. TtaSetDocumentUnupdated (sourceDoc);
  4174. TtaSetDocumentUnupdated (doc);
  4175. //DocStatusUpdate (doc, TRUE);
  4176. }
  4177. /* Synchronize selections */
  4178. event.document = doc;
  4179. event.element = NULL;
  4180. UpdateEditorMenus (sourceDoc);
  4181. SetCharsetMenuOff (sourceDoc, 1);
  4182. #ifdef TEMPLATES
  4183. // lock source of template instances
  4184. if (IsTemplateInstanceDocument(doc))
  4185. {
  4186. ThotBool allow;
  4187. TtaGetEnvBoolean ("EDIT_SRC_TEMPLATE", &allow);
  4188. root = TtaGetRootElement (sourceDoc);
  4189. if (!allow)
  4190. TtaSetAccessRight (root, ReadOnly, sourceDoc);
  4191. }
  4192. #endif /* TEMPLATES */
  4193. if (DocumentTypes[doc] == docImage)
  4194. {
  4195. root = TtaGetRootElement (sourceDoc);
  4196. TtaSetAccessRight (root, ReadOnly, doc);
  4197. }
  4198. /* update back/forward buttons */
  4199. if (HasPreviousDoc (doc))
  4200. SetArrowButton (DocumentSource[doc], TRUE, TRUE);
  4201. else
  4202. SetArrowButton (DocumentSource[doc], TRUE, FALSE);
  4203. if (HasNextDoc (doc))
  4204. SetArrowButton (DocumentSource[doc], FALSE, TRUE);
  4205. else
  4206. SetArrowButton (DocumentSource[doc], FALSE, FALSE);
  4207. TtaEnableAction(sourceDoc, "StopTransfer", FALSE);;
  4208. /* update toggle buttons */
  4209. if (HSplit[doc] == TRUE && VSplit[doc] == FALSE)
  4210. ShowHSplitToggle (sourceDoc, 1);
  4211. if (HSplit[doc] == FALSE && VSplit[doc] == TRUE)
  4212. ShowVSplitToggle (sourceDoc, 1);
  4213. // check if a parsing error is detected
  4214. sprintf (tempdir, "%s%c%d%cPARSING.ERR",
  4215. TempFileDirectory, DIR_SEP, doc, DIR_SEP);
  4216. if (TtaFileExist (tempdir))
  4217. UpdateLogFile (sourceDoc, TRUE);
  4218. SynchronizeSourceView (&event);
  4219. }
  4220. TtaFreeMemory (localFile);
  4221. }
  4222. /* the new opened view must get the focus */
  4223. TtaRedirectFocus();
  4224. }
  4225. /*----------------------------------------------------------------------
  4226. ShowFormatted
  4227. Open the formatted view(s) of a document. (or give it focus)
  4228. ----------------------------------------------------------------------*/
  4229. void ShowFormatted (Document doc, View view)
  4230. {
  4231. View structView;
  4232. int x, y, w, h;
  4233. char structureName[30];
  4234. if (DocumentTypes[doc] == docSource)
  4235. /* work on the formatted document */
  4236. doc = GetDocFromSource (doc);
  4237. strcpy (structureName, "Formatted_view");
  4238. structView = TtaGetViewFromName (doc, structureName);
  4239. if (structView != 0 && TtaIsViewOpen (doc, structView))
  4240. TtaRaiseView (doc, structView);
  4241. else
  4242. {
  4243. TtaGetViewGeometry (doc, structureName, &x, &y, &w, &h);
  4244. structView = TtaOpenView (doc, structureName, x, y, w, h);
  4245. if (structView != 0)
  4246. UpdateEditorMenus (doc);
  4247. }
  4248. SetWindowTitle (doc, doc, 0);
  4249. /* the new opened view must get the focus */
  4250. TtaRedirectFocus();
  4251. }
  4252. /*----------------------------------------------------------------------
  4253. ShowStructure
  4254. Open the structure view(s) of a document.
  4255. ----------------------------------------------------------------------*/
  4256. void ShowStructure (Document doc, View view)
  4257. {
  4258. View structView;
  4259. int x, y, w, h;
  4260. char structureName[30];
  4261. if (!strcmp (DocumentURLs[doc], "empty"))
  4262. return;
  4263. if (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_HELP)
  4264. return;
  4265. if (DocumentTypes[doc] == docSource)
  4266. /* work on the formatted document */
  4267. doc = GetDocFromSource (doc);
  4268. strcpy (structureName, "Structure_view");
  4269. structView = TtaGetViewFromName (doc, structureName);
  4270. if (structView != 0 && TtaIsViewOpen (doc, structView))
  4271. TtaRaiseView (doc, structView);
  4272. else
  4273. {
  4274. TtaGetViewGeometry (doc, structureName, &x, &y, &w, &h);
  4275. structView = TtaOpenView (doc, structureName, x, y, w, h);
  4276. if (structView != 0)
  4277. UpdateEditorMenus (doc);
  4278. }
  4279. SetWindowTitle (doc, doc, 0);
  4280. /* the new opened view must get the focus */
  4281. TtaRedirectFocus();
  4282. }
  4283. /*----------------------------------------------------------------------
  4284. ShowAlternate
  4285. Open the Alternate view of a document.
  4286. ----------------------------------------------------------------------*/
  4287. void ShowAlternate (Document doc, View view)
  4288. {
  4289. View altView;
  4290. int x, y, w, h;
  4291. if (!strcmp (DocumentURLs[doc], "empty"))
  4292. return;
  4293. if (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_HELP)
  4294. return;
  4295. if (DocumentTypes[doc] == docSource)
  4296. /* work on the formatted document */
  4297. doc = GetDocFromSource (doc);
  4298. altView = TtaGetViewFromName (doc, "Alternate_view");
  4299. if (view == altView)
  4300. TtaRaiseView (doc, view);
  4301. else if (altView != 0 && TtaIsViewOpen (doc, altView))
  4302. TtaRaiseView (doc, altView);
  4303. else
  4304. {
  4305. TtaGetViewGeometry (doc, "Alternate_view", &x, &y, &w, &h);
  4306. altView = TtaOpenView (doc, "Alternate_view", x, y, w, h);
  4307. if (altView != 0)
  4308. {
  4309. SetWindowTitle (doc, doc, altView);
  4310. UpdateEditorMenus (doc);
  4311. }
  4312. }
  4313. /* the new opened view must get the focus */
  4314. TtaRedirectFocus();
  4315. }
  4316. /*----------------------------------------------------------------------
  4317. ShowLinks
  4318. Open the Links view of a document
  4319. ----------------------------------------------------------------------*/
  4320. void ShowLinks (Document doc, View view)
  4321. {
  4322. View linksView;
  4323. int x, y, w, h;
  4324. if (!strcmp (DocumentURLs[doc], "empty"))
  4325. return;
  4326. if (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_HELP)
  4327. return;
  4328. if (DocumentTypes[doc] == docSource)
  4329. /* work on the formatted document */
  4330. doc = GetDocFromSource (doc);
  4331. linksView = TtaGetViewFromName (doc, "Links_view");
  4332. if (view == linksView)
  4333. TtaRaiseView (doc, view);
  4334. else if (linksView != 0 && TtaIsViewOpen (doc, linksView))
  4335. TtaRaiseView (doc, linksView);
  4336. else
  4337. {
  4338. TtaGetViewGeometry (doc, "Links_view", &x, &y, &w, &h);
  4339. linksView = TtaOpenView (doc, "Links_view", x, y, w, h);
  4340. if (linksView != 0)
  4341. {
  4342. SetWindowTitle (doc, doc, linksView);
  4343. UpdateEditorMenus (doc);
  4344. }
  4345. }
  4346. /* the new opened view must get the focus */
  4347. TtaRedirectFocus();
  4348. }
  4349. /*----------------------------------------------------------------------
  4350. ShowToC
  4351. Open the Table of content view of a document
  4352. ----------------------------------------------------------------------*/
  4353. void ShowToC (Document doc, View view)
  4354. {
  4355. View tocView;
  4356. int x, y, w, h;
  4357. if (!strcmp (DocumentURLs[doc], "empty"))
  4358. return;
  4359. if (DocumentMeta[doc] && DocumentMeta[doc]->method == CE_HELP)
  4360. return;
  4361. if (DocumentTypes[doc] == docSource)
  4362. /* work on the formatted document */
  4363. doc = GetDocFromSource (doc);
  4364. tocView = TtaGetViewFromName (doc, "Table_of_contents");
  4365. if (view == tocView)
  4366. TtaRaiseView (doc, view);
  4367. else if (tocView != 0 && TtaIsViewOpen (doc, tocView))
  4368. TtaRaiseView (doc, tocView);
  4369. else
  4370. {
  4371. TtaGetViewGeometry (doc, "Table_of_contents", &x, &y, &w, &h);
  4372. tocView = TtaOpenView (doc, "Table_of_contents", x, y, w, h);
  4373. if (tocView != 0)
  4374. {
  4375. SetWindowTitle (doc, doc, tocView);
  4376. UpdateEditorMenus (doc);
  4377. }
  4378. }
  4379. /* the new opened view must get the focus */
  4380. TtaRedirectFocus();
  4381. }
  4382. /*----------------------------------------------------------------------
  4383. RequestView: Thot request to open a view to show the current selection
  4384. ----------------------------------------------------------------------*/
  4385. ThotBool RequestView (NotifyDialog *event)
  4386. {
  4387. ShowStructure (event->document, event->view);
  4388. /* Inform Thot that the view is not open by Amaya */
  4389. return TRUE;
  4390. }
  4391. /*----------------------------------------------------------------------
  4392. ViewToClose
  4393. ----------------------------------------------------------------------*/
  4394. ThotBool ViewToClose (NotifyDialog *event)
  4395. {
  4396. Document document;
  4397. View view, structView, altView, linksView, tocView;
  4398. view = event->view;
  4399. document = event->document;
  4400. structView = TtaGetViewFromName (document, "Structure_view");
  4401. altView = TtaGetViewFromName (document, "Alternate_view");
  4402. linksView = TtaGetViewFromName (document, "Links_view");
  4403. tocView = TtaGetViewFromName (document, "Table_of_contents");
  4404. if (view != 1)
  4405. {
  4406. /* Save the current view geometry */
  4407. if (view == structView)
  4408. SaveGeometryOnExit (document, "Structure_view");
  4409. if (view == altView)
  4410. SaveGeometryOnExit (document, "Alternate_view");
  4411. if (view == linksView)
  4412. SaveGeometryOnExit (document, "Links_view");
  4413. if (view == tocView)
  4414. SaveGeometryOnExit (document, "Table_of_contents");
  4415. /* let Thot perform normal operation */
  4416. return FALSE;
  4417. }
  4418. else if (DocumentTypes[document] == docLibrary)
  4419. {
  4420. if (TtaIsDocumentModified (document))
  4421. {
  4422. InitConfirm (document, view, TtaGetMessage (AMAYA, AM_SAVE_DISK));
  4423. if (UserAnswer)
  4424. SaveDocument (document, view);
  4425. TtaSetDocumentUnmodified (document);
  4426. }
  4427. }
  4428. else if (DocumentTypes[document] == docSource)
  4429. TtaSetDocumentUnmodified (document);
  4430. else if (!CanReplaceCurrentDocument (document, view))
  4431. /* abort the command and don't let Thot perform normal operation */
  4432. return TRUE;
  4433. SaveGeometryOnExit (document, NULL); /* Save geometry of every view */
  4434. if (structView!= 0 && TtaIsViewOpen (document, structView))
  4435. TtaCloseView (document, structView);
  4436. if (altView != 0 && TtaIsViewOpen (document, altView))
  4437. TtaCloseView (document, altView);
  4438. if (linksView != 0 && TtaIsViewOpen (document, linksView))
  4439. TtaCloseView (document, linksView);
  4440. if (tocView != 0 && TtaIsViewOpen (document, tocView))
  4441. TtaCloseView (document, tocView);
  4442. /* let Thot perform normal operation */
  4443. return FALSE;
  4444. }
  4445. /*----------------------------------------------------------------------
  4446. The urlName is encoded with the default charset.
  4447. ----------------------------------------------------------------------*/
  4448. void GetAmayaDoc_callback (int newdoc, int status, char *urlName, char *outputfile,
  4449. char *proxyName, AHTHeaders *http_headers, void * context)
  4450. {
  4451. Element elFound = NULL, root;
  4452. Document doc;
  4453. Document res;
  4454. DisplayMode dispMode;
  4455. AmayaDoc_context *ctx;
  4456. XTigerTemplate t;
  4457. TTcbf *cbf;
  4458. int method;
  4459. void *ctx_cbf;
  4460. char tempdocument[MAX_LENGTH];
  4461. char proxymsg[MAX_LENGTH];
  4462. char *tempfile;
  4463. char *target;
  4464. char *pathname;
  4465. char *initial_url;
  4466. char *documentname;
  4467. char *form_data;
  4468. char *s;
  4469. int i;
  4470. ThotBool inNewWindow;
  4471. ThotBool ok, keep;
  4472. ThotBool stopped_flag = FALSE;
  4473. ThotBool local_link;
  4474. #ifdef _JAVA
  4475. /* Switch OFF the Javascipt/DOM engine before loading the document */
  4476. StopJavascript(newdoc);
  4477. #endif /* _JAVA */
  4478. /* restore GETHTMLDocument's context */
  4479. ctx = (AmayaDoc_context *) context;
  4480. if (!ctx)
  4481. return;
  4482. doc = ctx->doc;
  4483. target = ctx->target;
  4484. documentname = ctx->documentname;
  4485. initial_url = ctx->initial_url;
  4486. form_data = ctx->form_data;
  4487. cbf = ctx->cbf;
  4488. ctx_cbf = ctx->ctx_cbf;
  4489. method = ctx->method;
  4490. local_link = ctx->local_link;
  4491. inNewWindow = ctx->inNewWindow;
  4492. ok = TRUE;
  4493. pathname = (char *)TtaGetMemory (MAX_LENGTH);
  4494. strncpy (pathname, urlName, MAX_LENGTH / 4);
  4495. pathname[MAX_LENGTH / 4] = EOS;
  4496. tempfile = (char *)TtaGetMemory (MAX_LENGTH);
  4497. if (method != CE_MAKEBOOK && method != CE_TEMPLATE && method != CE_ANNOT &&
  4498. method != CE_LOG && method != CE_HELP &&
  4499. DocumentTypes[newdoc] != docLibrary &&
  4500. status == 0)
  4501. {
  4502. /* add the URI in the combobox string */
  4503. keep = (method == CE_ABSOLUTE || method == CE_INIT);
  4504. if (form_data && method == CE_FORM_GET)
  4505. AddURLInCombobox (pathname, form_data, keep);
  4506. else
  4507. AddURLInCombobox (pathname, NULL, keep);
  4508. }
  4509. if (outputfile != NULL)
  4510. {
  4511. strncpy (tempfile, outputfile, MAX_LENGTH / 4);
  4512. tempfile[MAX_LENGTH / 4] = EOS;
  4513. }
  4514. else
  4515. tempfile[0] = EOS;
  4516. #ifdef TEMPLATES
  4517. if (method != CE_LOG && method != CE_HELP)
  4518. Template_CheckAndPrepareTemplate (urlName);
  4519. #endif /* TEMPLATES */
  4520. /* now the new window is open */
  4521. if (inNewWindow && (method == CE_RELATIVE || method == CE_ABSOLUTE))
  4522. /* don't free the current loaded document */
  4523. method = CE_INIT;
  4524. if (!local_link)
  4525. {
  4526. /* memorize the initial newdoc value in doc because LoadDocument */
  4527. /* will open a new document if newdoc is a modified document */
  4528. if (status == 0)
  4529. {
  4530. /* the document was successfully loaded */
  4531. if (IsW3Path (pathname))
  4532. NormalizeURL (pathname, 0, tempdocument, documentname, NULL);
  4533. /* parse and display the document */
  4534. res = LoadDocument (newdoc, pathname, form_data,
  4535. initial_url, method,
  4536. tempfile, documentname,
  4537. http_headers, ctx->history, &inNewWindow, NULL);
  4538. W3Loading = 0; /* loading is complete now */
  4539. if (res == 0)
  4540. {
  4541. /* cannot load the document */
  4542. ResetStop(newdoc);
  4543. newdoc = 0;
  4544. ok = FALSE;
  4545. }
  4546. else if (newdoc != res)
  4547. newdoc = res;
  4548. if (ok)
  4549. {
  4550. /* fetch and display all images referred by the document */
  4551. if (method == CE_MAKEBOOK || method == CE_TEMPLATE)
  4552. stopped_flag = FetchAndDisplayImages (newdoc,
  4553. AMAYA_LOAD_IMAGE | AMAYA_MBOOK_IMAGE,
  4554. NULL);
  4555. else
  4556. {
  4557. if (method == CE_HELP)
  4558. {
  4559. // make it read only
  4560. root = TtaGetRootElement (newdoc);
  4561. TtaSetAccessRight (root, ReadOnly, newdoc);
  4562. }
  4563. // set the default icon
  4564. TtaSetPageIcon (newdoc, 1, NULL);
  4565. stopped_flag = FetchAndDisplayImages (newdoc, AMAYA_LOAD_IMAGE, NULL);
  4566. #ifdef ANNOTATIONS
  4567. /* if it's an annotation, add the existing metadata */
  4568. if (DocumentTypes[newdoc] == docAnnot)
  4569. ANNOT_LoadAnnotation (ctx->baseDoc, newdoc);
  4570. /* auto-load the annotations associated with the document */
  4571. if (ANNOT_CanAnnotate (newdoc))
  4572. ANNOT_AutoLoad (newdoc, 1);
  4573. #endif /* ANNOTATIONS */
  4574. }
  4575. }
  4576. /* check parsing errors */
  4577. if (DocumentTypes[newdoc] == docLog ||
  4578. method == CE_MAKEBOOK || method == CE_TEMPLATE || method == CE_HELP)
  4579. CleanUpParsingErrors ();
  4580. else
  4581. CheckParsingErrors (newdoc);
  4582. #ifdef TEMPLATES
  4583. // Fill template internal structures and prepare the instance if any
  4584. t = GetXTigerTemplate (pathname);
  4585. if (t)
  4586. {
  4587. dispMode = TtaGetDisplayMode (doc);
  4588. if (dispMode != NoComputedDisplay)
  4589. TtaSetDisplayMode (doc, NoComputedDisplay);
  4590. Template_FillFromDocument (newdoc);
  4591. TtaSetDisplayMode (doc, dispMode);
  4592. if (method == CE_TEMPLATE)
  4593. // avoid positionned boxes to overlap the xt:head
  4594. SetBodyAbsolutePosition (newdoc);
  4595. }
  4596. #endif /* TEMPLATES */
  4597. }
  4598. else
  4599. {
  4600. /* a stop or an error occured */
  4601. if (DocumentURLs[newdoc] == NULL)
  4602. {
  4603. /* save the document name into the document table */
  4604. s = TtaStrdup (pathname);
  4605. DocumentURLs[newdoc] = s;
  4606. if (DocumentTypes[newdoc] == docLibrary)
  4607. {
  4608. #ifdef _SVG
  4609. TtaSetTextZone (newdoc, 1, SVGlib_list);
  4610. #endif /* _SVG */
  4611. }
  4612. else
  4613. TtaSetTextZone (newdoc, 1, URL_list);
  4614. /* save the document's formdata into the document table */
  4615. if (DocumentMeta[newdoc])
  4616. DocumentMetaClear (DocumentMeta[(int) newdoc]);
  4617. else
  4618. DocumentMeta[newdoc] = DocumentMetaDataAlloc ();
  4619. DocumentMeta[newdoc]->form_data = TtaStrdup (form_data);
  4620. if (strcmp (pathname, initial_url))
  4621. DocumentMeta[newdoc]->initial_url = TtaStrdup (initial_url);
  4622. else
  4623. DocumentMeta[newdoc]->initial_url = NULL;
  4624. DocumentMeta[newdoc]->method = method;
  4625. DocumentMeta[newdoc]->xmlformat = FALSE;
  4626. DocumentMeta[newdoc]->compound = FALSE;
  4627. DocumentSource[newdoc] = 0;
  4628. ResetStop(newdoc);
  4629. }
  4630. W3Loading = 0; /* loading is complete now */
  4631. ResetStop(newdoc);
  4632. ok = FALSE;
  4633. if (status == -2)
  4634. {
  4635. s = HTTP_headers (http_headers, AM_HTTP_REASON);
  4636. sprintf (tempdocument, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), pathname);
  4637. if (proxyName != NULL)
  4638. {
  4639. strcpy (proxymsg, "Used proxy: ");
  4640. strcat (proxymsg, proxyName);
  4641. InitConfirm3L (newdoc, 1, tempdocument, s, proxymsg, FALSE);
  4642. }
  4643. else
  4644. InitConfirm3L (newdoc, 1, tempdocument, s, NULL, FALSE);
  4645. }
  4646. }
  4647. if (ok && !stopped_flag &&
  4648. DocumentTypes[newdoc] != docLog &&
  4649. method != CE_MAKEBOOK && method != CE_TEMPLATE)
  4650. {
  4651. ResetStop (newdoc);
  4652. #ifdef _GL
  4653. if (FilesLoading[newdoc] == 0 &&
  4654. TtaGetViewFrame (newdoc, 1) != 0)
  4655. /* all files included in this document have been loaded and the
  4656. document is displayed. Animations can be played now */
  4657. TtaPlay (newdoc, 1);
  4658. #endif /* _GL */
  4659. }
  4660. }
  4661. /* select the target if present */
  4662. if (ok && !stopped_flag && target != NULL && target[0] != EOS &&
  4663. newdoc != 0 && method != CE_MAKEBOOK && method != CE_TEMPLATE)
  4664. {
  4665. /* attribute HREF contains the NAME of a target anchor */
  4666. if (DocumentTypes[newdoc] == docHTML)
  4667. elFound = SearchNAMEattribute (newdoc, target, NULL, NULL);
  4668. else if (DocumentTypes[newdoc] == docText)
  4669. elFound = SearchTextattribute (newdoc, target);
  4670. if (elFound)
  4671. {
  4672. /* show the target element in all views */
  4673. for (i = 1; i < 4; i++)
  4674. if (TtaIsViewOpen (newdoc, i))
  4675. TtaShowElement (newdoc, i, elFound, 0);
  4676. }
  4677. }
  4678. /*** if stopped_flag == true, how to deal with cbf? */
  4679. if (cbf)
  4680. (*cbf) (newdoc, status, pathname, tempfile, NULL, NULL, ctx_cbf);
  4681. if (newdoc && W3Loading == 0)
  4682. #ifdef DAV
  4683. /* MKP: if document has been loaded, we are *
  4684. * able to discovery if the document is locked. *
  4685. * do a lock discovery, set LockIndicator button */
  4686. DAVLockDiscovery (newdoc);
  4687. #else /* DAV */
  4688. // no lock/unlock allowed
  4689. TtaSetLockButton (newdoc, 0);
  4690. #endif /* DAV */
  4691. TtaFreeMemory (target);
  4692. TtaFreeMemory (documentname);
  4693. TtaFreeMemory (initial_url);
  4694. TtaFreeMemory (pathname);
  4695. TtaFreeMemory (tempfile);
  4696. if (form_data)
  4697. TtaFreeMemory (form_data);
  4698. TtaFreeMemory (ctx);
  4699. /* check if a refresh is requested */
  4700. CheckRefresh (newdoc);
  4701. if (IsTemplateInstanceDocument(newdoc))
  4702. {
  4703. ShowStructure (newdoc, 1);
  4704. //SplitVertically (newdoc, 1);
  4705. }
  4706. else if (DocumentTypes[newdoc] == docXml && !DocHasCSS (newdoc))
  4707. // Display the source view
  4708. ShowSource (newdoc, 1);
  4709. }
  4710. /*----------------------------------------------------------------------
  4711. GetAmayaDoc loads the document if it is not loaded yet and calls the
  4712. parser if the document can be parsed.
  4713. - urlname: can be relative or absolute address.
  4714. It's encoded with the default charset.
  4715. - form_data: the text to be posted.
  4716. - doc: the document which can be removed if not updated.
  4717. - baseDoc: the document which urlname is relative to.
  4718. - method: CE_FORM_POST for a post request, CE_RELATIVE for a double
  4719. click.
  4720. - history: record the URL in the browsing history
  4721. ----------------------------------------------------------------------*/
  4722. Document GetAmayaDoc (const char *urlname, const char *form_data,
  4723. Document doc, Document baseDoc, int method,
  4724. ThotBool history, TTcbf *cbf, void *ctx_cbf)
  4725. {
  4726. Document newdoc = 0, refdoc;
  4727. CSSInfoPtr css;
  4728. PInfoPtr pInfo;
  4729. AmayaDoc_context *ctx = NULL;
  4730. CHARSET doc_charset;
  4731. char *tempfile, *parameters;
  4732. char *target, *initial_url;
  4733. char temp_url[MAX_LENGTH], charsetname[MAX_LENGTH];
  4734. char *documentname;
  4735. char lg_uri[10];
  4736. const char *content_type = NULL;
  4737. int parsingLevel, extraProfile;
  4738. int toparse, mode, docType;
  4739. int frame_id;
  4740. int window_id, page_id, page_position, visibility, requested_doc;
  4741. ThotBool xmlDec, withDoctype, isXML, useMath, isKnown;
  4742. ThotBool ok, isOpen;
  4743. if (W3Loading && W3Loading == doc)
  4744. return (0);
  4745. /* Extract parameters if necessary */
  4746. if (urlname == 0)
  4747. return (0);
  4748. if (strlen (urlname) > MAX_LENGTH / 4)
  4749. {
  4750. sprintf (lg_uri, "%d", MAX_LENGTH);
  4751. TtaSetStatus (baseDoc, 1, TtaGetMessage (AMAYA, AM_TOO_LONG_URL), lg_uri);
  4752. return (0);
  4753. }
  4754. /* check if the request comes from the source document */
  4755. if (doc && DocumentTypes[doc] == docSource)
  4756. doc = GetDocFromSource (doc);
  4757. ok = TRUE;
  4758. if (IsXTiger (DocumentURLs[doc]) || IsXTigerLibrary (DocumentURLs[doc]))
  4759. // cannot replace a template by a document
  4760. DontReplaceOldDoc = TRUE;
  4761. target = (char *)TtaGetMemory (MAX_LENGTH);
  4762. documentname = (char *)TtaGetMemory (MAX_LENGTH);
  4763. parameters = (char *)TtaGetMemory (MAX_LENGTH);
  4764. tempfile = (char *)TtaGetMemory (MAX_LENGTH);
  4765. tempfile[0] = EOS;
  4766. initial_url = (char *)TtaGetMemory (MAX_LENGTH);
  4767. strncpy(temp_url, urlname, MAX_LENGTH / 4);
  4768. temp_url[MAX_LENGTH / 4] = EOS;
  4769. /* Extract parameters if any */
  4770. ExtractParameters (temp_url, parameters);
  4771. /* Extract the target if necessary */
  4772. ExtractTarget (temp_url, target);
  4773. /* Add the base content if necessary */
  4774. if (method == CE_RELATIVE || method == CE_FORM_GET ||
  4775. method == CE_FORM_POST || method == CE_MAKEBOOK || method == CE_TEMPLATE)
  4776. NormalizeURL (temp_url, baseDoc, initial_url, documentname, NULL);
  4777. else
  4778. NormalizeURL (temp_url, 0, initial_url, documentname, NULL);
  4779. // check if the page is displayed in the help window
  4780. if (DocumentMeta[baseDoc] && DocumentMeta[baseDoc]->method == CE_HELP)
  4781. method = CE_HELP;
  4782. /* check the document suffix */
  4783. if (IsMathMLName (documentname))
  4784. docType = docMath;
  4785. else if (IsSVGName (documentname))
  4786. docType = docSVG;
  4787. else if (IsCSSName (documentname))
  4788. docType = docCSS;
  4789. else if (IsXTigerLibrary (documentname))
  4790. docType = docTemplate;
  4791. else if (IsXTiger (documentname) || IsXMLName (documentname))
  4792. {
  4793. if (IsXTiger (documentname))
  4794. // a template cannot replace another document
  4795. DontReplaceOldDoc = TRUE;
  4796. docType = docXml;
  4797. //TODO Check that urlname is a valid URL
  4798. if (!IsW3Path (temp_url) && TtaFileExist (temp_url))
  4799. {
  4800. CheckDocHeader(temp_url, &xmlDec, &withDoctype, &isXML, &useMath,
  4801. &isKnown, &parsingLevel, &doc_charset,
  4802. charsetname, (DocumentType*)&docType, &extraProfile);
  4803. if (docType == docText)
  4804. docType = docXml;
  4805. }
  4806. }
  4807. else if (method == CE_CSS)
  4808. docType = docCSS;
  4809. else if (method == CE_LOG)
  4810. docType = docLog;
  4811. else if (IsTextName (documentname))
  4812. docType = docText;
  4813. else
  4814. docType = docHTML;
  4815. /* we skip the file: prefix if it is present and do other local
  4816. file urls conversions */
  4817. if (!IsW3Path (initial_url))
  4818. {
  4819. /* we take the long way around to get the result
  4820. of normalizeFile, as the function doesn't allocate
  4821. memory dynamically (note: this can generate some MAX_LENGTH
  4822. problems) */
  4823. if (method == CE_RELATIVE || method == CE_FORM_GET ||
  4824. method == CE_ANNOT || method == CE_FORM_POST ||
  4825. method == CE_MAKEBOOK || method == CE_TEMPLATE)
  4826. /* we're following a link, so do all the convertions on
  4827. the URL */
  4828. NormalizeFile (initial_url, tempfile, AM_CONV_ALL);
  4829. else
  4830. NormalizeFile (initial_url, tempfile, AM_CONV_NONE);
  4831. strcpy (initial_url, tempfile);
  4832. tempfile[0] = EOS;
  4833. }
  4834. /* check if the user is already browsing the document in another window */
  4835. if (method == CE_FORM_GET)
  4836. {
  4837. newdoc = IsDocumentLoaded (initial_url, form_data);
  4838. /* we don't concatenate the new parameters as we give preference
  4839. to the form data */
  4840. }
  4841. else
  4842. {
  4843. /* concatenate the parameters before making the test */
  4844. if (parameters[0] != EOS)
  4845. {
  4846. strcat (initial_url, "?");
  4847. strcat (initial_url, parameters);
  4848. }
  4849. /* if it's a POST form, we search the document using the
  4850. form_data */
  4851. if (method == CE_FORM_POST)
  4852. newdoc = IsDocumentLoaded (initial_url, form_data);
  4853. else if (method != CE_TEMPLATE)
  4854. newdoc = IsDocumentLoaded (initial_url, NULL);
  4855. }
  4856. if (newdoc != 0)
  4857. /* the document is already loaded */
  4858. {
  4859. if (newdoc == doc)
  4860. /* it's a move in the same document */
  4861. {
  4862. if (history)
  4863. /* record the current position in the history */
  4864. AddDocHistory (newdoc, DocumentURLs[newdoc],
  4865. DocumentMeta[doc]->initial_url,
  4866. DocumentMeta[doc]->form_data,
  4867. DocumentMeta[doc]->method);
  4868. }
  4869. else
  4870. /* following the link to another open window */
  4871. {
  4872. /* raise its window */
  4873. frame_id = GetWindowNumber (newdoc, 1);
  4874. if(frame_id != 0)
  4875. TtaRaiseView (newdoc, 1);
  4876. else
  4877. {
  4878. /* Where open the new document ? in which window ? */
  4879. WhereOpenView(doc, newdoc, FALSE, InNewWindow, (DocumentType)docType, method,
  4880. &window_id, &page_id, &page_position, &visibility, &isOpen, &requested_doc);
  4881. InitView(doc, newdoc, FALSE, InNewWindow, isOpen,
  4882. window_id, page_id, page_position, (DocumentType)docType, method);
  4883. PostInitView(newdoc, (DocumentType)docType, visibility,
  4884. !DontReplaceOldDoc, isOpen);
  4885. TtaShowWindow( window_id, TRUE );
  4886. }
  4887. /* don't add it to the doc's historic */
  4888. history = FALSE;
  4889. }
  4890. }
  4891. /* Create the context for the callback */
  4892. ctx = (AmayaDoc_context*)TtaGetMemory (sizeof (AmayaDoc_context));
  4893. ctx->doc = doc;
  4894. ctx->baseDoc = baseDoc;
  4895. ctx->history = history;
  4896. ctx->target = target;
  4897. ctx->documentname = documentname;
  4898. ctx->initial_url = TtaStrdup (initial_url);
  4899. if (form_data)
  4900. ctx->form_data = TtaStrdup (form_data);
  4901. else
  4902. ctx->form_data = NULL;
  4903. ctx->method = method;
  4904. ctx->cbf = cbf;
  4905. ctx->ctx_cbf = ctx_cbf;
  4906. ctx->local_link = 0;
  4907. ctx->inNewWindow = DontReplaceOldDoc;
  4908. toparse = 0;
  4909. if (newdoc == 0)
  4910. {
  4911. /*
  4912. DocumentURLs and DocHistory are coded in the default charset */
  4913. /* document not loaded yet */
  4914. if ((method == CE_RELATIVE || method == CE_FORM_GET ||
  4915. method == CE_FORM_POST || method == CE_MAKEBOOK || method == CE_TEMPLATE ||
  4916. method == CE_ANNOT) &&
  4917. !IsW3Path (initial_url) && !TtaFileExist (initial_url))
  4918. {
  4919. /* the target document doesn't exist */
  4920. TtaSetStatus (baseDoc, 1, TtaGetMessage (AMAYA, AM_CANNOT_LOAD), initial_url);
  4921. ok = FALSE; /* do not continue */
  4922. }
  4923. else if (method == CE_LOG)
  4924. /* need to create a new window for the document */
  4925. newdoc = InitDocAndView ( baseDoc, /* SG: 'doc' is always NULL, maybe it should be baseDoc */
  4926. FALSE /* replaceOldDoc */,
  4927. TRUE /* inNewWindow */,
  4928. documentname, (DocumentType)docLog, 0, FALSE,
  4929. L_Other, 0, method);
  4930. else if (method == CE_HELP)
  4931. {
  4932. /* add the URI in the combobox string */
  4933. AddURLInCombobox (initial_url, NULL, FALSE);
  4934. /* need to create a new window for the document */
  4935. newdoc = InitDocAndView (baseDoc,
  4936. !DontReplaceOldDoc /* replaceOldDoc */,
  4937. InNewWindow /* inNewWindow */,
  4938. documentname, (DocumentType)docType, 0, TRUE,
  4939. L_Other, 0, method);
  4940. if (newdoc)
  4941. {
  4942. /* help document has to be in read-only mode */
  4943. TtaSetMenuOff (newdoc, 1, Help_);
  4944. }
  4945. }
  4946. #ifdef ANNOTATIONS
  4947. else if (method == CE_ANNOT)
  4948. {
  4949. /* need to create a new window for the document */
  4950. newdoc = InitDocAndView (doc,
  4951. FALSE /* replaceOldDoc */,
  4952. TRUE /* inNewWindow */,
  4953. documentname, (DocumentType)docAnnot, 0, FALSE,
  4954. L_Annot, 0, method);
  4955. /* we're downloading an annotation, fix the accept_header
  4956. (thru the content_type variable) to application/rdf */
  4957. content_type = "application/rdf";
  4958. }
  4959. #endif /* ANNOTATIONS */
  4960. else if (method != CE_MAKEBOOK && (doc == 0 || DontReplaceOldDoc))
  4961. {
  4962. /* In case of initial document, open the view before loading */
  4963. /* add the URI in the combobox string */
  4964. if (method == CE_INSTANCE)
  4965. AddURLInCombobox (initial_url, NULL, TRUE);
  4966. else
  4967. AddURLInCombobox (initial_url, NULL, FALSE);
  4968. newdoc = InitDocAndView (doc,
  4969. FALSE /* replaceOldDoc */,
  4970. InNewWindow /* inNewWindow */,
  4971. documentname, (DocumentType)docType, 0, FALSE,
  4972. L_Other, 0, method);
  4973. }
  4974. else
  4975. {
  4976. newdoc = doc;
  4977. /* stop current transfer for previous document */
  4978. if (method != CE_MAKEBOOK && method != CE_TEMPLATE)
  4979. StopTransfer (baseDoc, 1);
  4980. else
  4981. /* temporary docs to make a book are not in ReadOnly mode */
  4982. DocumentTypes[newdoc] = docHTML;
  4983. }
  4984. if (newdoc == 0)
  4985. /* cannot display the new document */
  4986. ok = FALSE;
  4987. if (ok)
  4988. {
  4989. /* this document is currently in load */
  4990. W3Loading = newdoc;
  4991. ActiveTransfer (newdoc);
  4992. /* set up the transfer mode */
  4993. mode = AMAYA_ASYNC | AMAYA_FLUSH_REQUEST;
  4994. if (method == CE_FORM_POST)
  4995. mode = mode | AMAYA_FORM_POST | AMAYA_NOCACHE;
  4996. else if (method == CE_MAKEBOOK)
  4997. mode = AMAYA_ASYNC;
  4998. else if (method == CE_TEMPLATE)
  4999. mode = AMAYA_SYNC;
  5000. // for new created template instances, the temporary file is parsed
  5001. if (method != CE_INSTANCE && IsW3Path (initial_url))
  5002. {
  5003. css = SearchCSS (0, initial_url, NULL, &pInfo);
  5004. if (method == CE_MAKEBOOK || method == CE_RELATIVE || method == CE_TEMPLATE)
  5005. /* add the referer field in the GET */
  5006. refdoc = doc;
  5007. else
  5008. refdoc = 0;
  5009. if ((css == NULL) || (css != NULL && newdoc == doc))
  5010. toparse = GetObjectWWW (newdoc, refdoc, initial_url, form_data,
  5011. tempfile, mode, NULL, NULL,
  5012. (void (*)(int, int, char*, char*, char*, const AHTHeaders*, void*)) GetAmayaDoc_callback,
  5013. (void *) ctx, YES, content_type);
  5014. else
  5015. {
  5016. /* it was already loaded, we need to open it */
  5017. TtaSetStatus (newdoc, 1,
  5018. TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
  5019. /* just take a copy of the local temporary file */
  5020. strcpy (tempfile, css->localName);
  5021. GetAmayaDoc_callback (newdoc, 0, initial_url, tempfile,
  5022. NULL, NULL, (void *) ctx);
  5023. TtaHandlePendingEvents ();
  5024. }
  5025. }
  5026. else
  5027. {
  5028. if (method == CE_INSTANCE)
  5029. {
  5030. // the temporary file is already there
  5031. char *localFile = GetLocalPath (newdoc, initial_url);
  5032. strcpy (tempfile, localFile);
  5033. TtaFreeMemory (localFile);
  5034. TtaSetDisplayMode (newdoc, NoComputedDisplay);
  5035. }
  5036. /* wasn't a document off the web, we need to open it */
  5037. TtaSetStatus (newdoc, 1,
  5038. TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED),
  5039. NULL);
  5040. GetAmayaDoc_callback (newdoc, 0, initial_url, tempfile,
  5041. NULL, NULL, (void *) ctx);
  5042. TtaHandlePendingEvents ();
  5043. if (method == CE_INSTANCE)
  5044. TtaSetDisplayMode (newdoc, DisplayImmediately);
  5045. }
  5046. }
  5047. }
  5048. else if (ok && newdoc != 0)
  5049. {
  5050. /* following a local link */
  5051. TtaSetStatus (newdoc, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED), NULL);
  5052. ctx->local_link = 1;
  5053. GetAmayaDoc_callback (newdoc, 0, initial_url, tempfile, NULL, NULL, (void *) ctx);
  5054. TtaHandlePendingEvents ();
  5055. }
  5056. if (ok == FALSE)
  5057. /* if the document isn't loaded off the web (because of an error, or
  5058. because it was already loaded), we invoke the callback function */
  5059. {
  5060. if (ctx->form_data)
  5061. TtaFreeMemory (ctx->form_data);
  5062. TtaFreeMemory (ctx->initial_url);
  5063. if (ctx)
  5064. TtaFreeMemory (ctx);
  5065. if (cbf)
  5066. (*cbf) (newdoc, -1, initial_url, tempfile, NULL, NULL, ctx_cbf);
  5067. /* Free the memory associated with the context */
  5068. TtaFreeMemory (target);
  5069. TtaFreeMemory (documentname);
  5070. }
  5071. TtaFreeMemory (parameters);
  5072. TtaFreeMemory (tempfile);
  5073. TtaFreeMemory (initial_url);
  5074. DontReplaceOldDoc = FALSE;
  5075. return (newdoc);
  5076. }
  5077. /*----------------------------------------------------------------------
  5078. ChangeDoctype
  5079. Mofity the doctype declaration for a HTML document saved as XML
  5080. and vice-versa.
  5081. isXml indicates is the new doctype corresponds to an XML document
  5082. ----------------------------------------------------------------------*/
  5083. static void ChangeDoctype (ThotBool isXml)
  5084. {
  5085. int profile;
  5086. Document doc;
  5087. ElementType elType;
  5088. Element root, htmlRoot, doctype, doctypeLine, prevLine, text;
  5089. char *private_dtd;
  5090. doc = SavingDocument;
  5091. root = TtaGetMainRoot (doc);
  5092. elType.ElSSchema = TtaGetDocumentSSchema (doc);
  5093. if (strcmp (TtaGetSSchemaName (elType.ElSSchema), "HTML"))
  5094. return;
  5095. /* Update the namespace declaration for the HTML element */
  5096. elType.ElTypeNum = HTML_EL_HTML;
  5097. htmlRoot = TtaSearchTypedElement (elType, SearchForward, root);
  5098. if (!htmlRoot)
  5099. return;
  5100. if (isXml)
  5101. TtaSetANamespaceDeclaration (doc, htmlRoot, NULL, XHTML_URI);
  5102. else
  5103. TtaFreeElemNamespaceDeclarations (doc, htmlRoot);
  5104. /* Search the DOCTYPE element */
  5105. elType.ElTypeNum = HTML_EL_DOCTYPE;
  5106. doctype = TtaSearchTypedElement (elType, SearchForward, root);
  5107. if (!doctype)
  5108. return;
  5109. /* Remove the previous doctype element */
  5110. TtaDeleteTree (doctype, doc);
  5111. profile = TtaGetDocumentProfile (doc);
  5112. /* Don't check the Thot abstract tree against the structure schema. */
  5113. TtaSetStructureChecking (FALSE, doc);
  5114. doctype = TtaNewElement (doc, elType);
  5115. TtaInsertFirstChild (&doctype, root, doc);
  5116. /* Make the DOCTYPE element read-only */
  5117. TtaSetAccessRight (doctype, ReadOnly, doc);
  5118. /* create the first DOCTYPE_line element */
  5119. elType.ElTypeNum = HTML_EL_DOCTYPE_line;
  5120. doctypeLine = TtaNewElement (doc, elType);
  5121. TtaInsertFirstChild (&doctypeLine, doctype, doc);
  5122. elType.ElTypeNum = 1;
  5123. text = TtaNewElement (doc, elType);
  5124. if (text != NULL)
  5125. {
  5126. TtaInsertFirstChild (&text, doctypeLine, SavingDocument);
  5127. private_dtd = TtaGetEnvString ("LOCAL_HTML_DOCTYPE_1");
  5128. if (private_dtd && private_dtd[0] != EOS)
  5129. TtaSetTextContent (text, (unsigned char*)private_dtd,Latin_Script , doc);
  5130. else if (isXml)
  5131. {
  5132. /* XML document */
  5133. if (profile == L_Strict)
  5134. TtaSetTextContent (text, (unsigned char *)DOCTYPE1_XHTML10_STRICT, Latin_Script, doc);
  5135. else
  5136. TtaSetTextContent (text, (unsigned char *)DOCTYPE1_XHTML10_TRANSITIONAL, Latin_Script, doc);
  5137. }
  5138. else
  5139. {
  5140. /* HTML document */
  5141. if (profile == L_Strict)
  5142. TtaSetTextContent (text, (unsigned char *)DOCTYPE1_HTML_STRICT, Latin_Script, doc);
  5143. else
  5144. TtaSetTextContent (text, (unsigned char *)DOCTYPE1_HTML_TRANSITIONAL, Latin_Script, doc);
  5145. }
  5146. }
  5147. /* create the second DOCTYPE_line element */
  5148. elType.ElTypeNum = HTML_EL_DOCTYPE_line;
  5149. prevLine = doctypeLine;
  5150. doctypeLine = TtaNewElement (doc, elType);
  5151. TtaInsertSibling (doctypeLine, prevLine, FALSE, doc);
  5152. elType.ElTypeNum = 1;
  5153. text = TtaNewElement (doc, elType);
  5154. if (text != NULL)
  5155. {
  5156. TtaInsertFirstChild (&text, doctypeLine, doc);
  5157. private_dtd = TtaGetEnvString ("LOCAL_HTML_DOCTYPE_1");
  5158. if (private_dtd && private_dtd[0] != EOS)
  5159. TtaSetTextContent (text, (unsigned char*)private_dtd,Latin_Script , doc);
  5160. else if (isXml)
  5161. {
  5162. /* XML document */
  5163. if (profile == L_Strict)
  5164. TtaSetTextContent (text, (unsigned char *)DOCTYPE2_XHTML10_STRICT, Latin_Script, doc);
  5165. else
  5166. TtaSetTextContent (text, (unsigned char *)DOCTYPE2_XHTML10_TRANSITIONAL, Latin_Script, doc);
  5167. }
  5168. else
  5169. {
  5170. /* HTML document */
  5171. if (profile == L_Strict)
  5172. TtaSetTextContent (text, (unsigned char *)DOCTYPE2_HTML_STRICT, Latin_Script, doc);
  5173. else
  5174. TtaSetTextContent (text, (unsigned char *)DOCTYPE2_HTML_TRANSITIONAL, Latin_Script, doc);
  5175. }
  5176. }
  5177. TtaSetStructureChecking (TRUE, doc);
  5178. }
  5179. /*----------------------------------------------------------------------
  5180. SetFileSuffix
  5181. Set the suffix of the file name used for saving a document
  5182. ----------------------------------------------------------------------*/
  5183. static void SetFileSuffix ()
  5184. {
  5185. char suffix[6];
  5186. char *filename;
  5187. int i, len;
  5188. if (SavingDocument && SaveName[0] != EOS)
  5189. {
  5190. if (SaveAsHTML)
  5191. strcpy (suffix, "html");
  5192. else if (SaveAsXML)
  5193. strcpy (suffix, "html");
  5194. else if (SaveAsText)
  5195. strcpy (suffix, "txt");
  5196. else
  5197. return;
  5198. /* looks for a suffix at the end of the document name */
  5199. len = strlen (SaveName);
  5200. for (i = len-1; i > 0 && SaveName[i] != '.'; i--);
  5201. if (SaveName[i] != '.')
  5202. {
  5203. /* there is no suffix */
  5204. i = len;
  5205. SaveName[i++] = '.';
  5206. }
  5207. else
  5208. {
  5209. /* there is a suffix */
  5210. i++;
  5211. if (strncmp (suffix, &SaveName[i], 3) == 0)
  5212. /* the requested suffix is already here. Do nothing */
  5213. i = 0;
  5214. }
  5215. if (i > 0)
  5216. {
  5217. /* change or append the suffix */
  5218. strcpy (&SaveName[i], suffix);
  5219. /* display the new filename in the dialog box */
  5220. filename = (char *)TtaGetMemory (MAX_LENGTH);
  5221. strcpy (filename, SavePath);
  5222. if (strchr (SavePath, '/'))
  5223. strcat (filename, URL_STR);
  5224. else
  5225. strcat (filename, DIR_STR);
  5226. strcat (filename, SaveName);
  5227. strcpy(SaveFileName, filename);
  5228. TtaFreeMemory (filename);
  5229. }
  5230. else
  5231. SaveFileName[0] = EOS;
  5232. }
  5233. }
  5234. /*----------------------------------------------------------------------
  5235. Callback procedure for dialogue events.
  5236. ----------------------------------------------------------------------*/
  5237. void CallbackDialogue (int ref, int typedata, char *data)
  5238. {
  5239. Document doc = 0;
  5240. char tempfile[MAX_LENGTH];
  5241. char tempname[MAX_LENGTH];
  5242. char sep, *ptr;
  5243. long int val;
  5244. int i;
  5245. ThotBool change, updated;
  5246. if (typedata == STRING_DATA && data && strchr (data, '/'))
  5247. sep = URL_SEP;
  5248. else
  5249. sep = DIR_SEP;
  5250. val = (long int) data;
  5251. if (ref - BaseDialog == OptionMenu)
  5252. /* a popup menu corresponding to a SELECT element */
  5253. ReturnOption = val;
  5254. else switch (ref - BaseDialog)
  5255. {
  5256. case OpenForm:
  5257. /* *********Load URL or local document********* */
  5258. if (val == 1)
  5259. /* Confirm */
  5260. {
  5261. /* get the current document (CurrentDocument not valid) */
  5262. TtaGiveActiveView (&doc, &i);
  5263. if (DocumentSource[doc] && DocumentTypes[doc] != docSource)
  5264. /* it could be a log or show document */
  5265. doc = DocumentSource[doc];
  5266. CurrentDocument = doc;
  5267. if ((CurrentDocument == 0) || /* this is the first loaded doc */
  5268. (!InNewWindow && DontReplaceOldDoc) || /* in a new tab */
  5269. (InNewWindow) || /* in a new window */
  5270. (!DontReplaceOldDoc && CanReplaceCurrentDocument(CurrentDocument, 1)) /* wants to replace the current document */
  5271. )
  5272. {
  5273. if (LastURLName[0] != EOS)
  5274. {
  5275. /* update the list of URLs */
  5276. if (NewFile)
  5277. InitializeNewDoc (LastURLName, NewDocType,
  5278. doc, NewDocProfile, NewDocExtraProfile, NewXML);
  5279. /* load an URL */
  5280. else if (DontReplaceOldDoc)
  5281. GetAmayaDoc (LastURLName, NULL, doc, doc,
  5282. Loading_method,
  5283. FALSE, NULL, NULL);
  5284. else
  5285. GetAmayaDoc (LastURLName, NULL, CurrentDocument,
  5286. CurrentDocument, Loading_method,
  5287. TRUE, NULL, NULL);
  5288. }
  5289. else if (DirectoryName[0] != EOS && DocumentName[0] != EOS)
  5290. {
  5291. /* load a local file */
  5292. strcpy (tempfile, DirectoryName);
  5293. strcat (tempfile, DIR_STR);
  5294. strcat (tempfile, DocumentName);
  5295. /* update the list of URLs */
  5296. NormalizeFile (tempfile, tempname, AM_CONV_ALL);
  5297. if (NewFile)
  5298. InitializeNewDoc (tempfile, NewDocType,
  5299. doc, NewDocProfile, NewDocExtraProfile, NewXML);
  5300. else if (FileExistTarget (tempname))
  5301. {
  5302. if (DontReplaceOldDoc)
  5303. GetAmayaDoc (tempfile, NULL,
  5304. doc, doc,
  5305. Loading_method,
  5306. FALSE, NULL, NULL);
  5307. else
  5308. GetAmayaDoc (tempfile, NULL, CurrentDocument,
  5309. CurrentDocument, Loading_method,
  5310. TRUE, NULL, NULL);
  5311. }
  5312. else
  5313. {
  5314. #ifdef _JAVA
  5315. StopJavascript(CurrentDocument);
  5316. #endif /* _JAVA */
  5317. NotFoundDoc (tempfile, CurrentDocument);
  5318. }
  5319. }
  5320. else if (DocumentName[0] != EOS)
  5321. {
  5322. ptr = DocumentName;
  5323. updated = CompleteUrl (&ptr);
  5324. if (updated)
  5325. {
  5326. strcpy (DocumentName, ptr);
  5327. TtaFreeMemory (ptr);
  5328. }
  5329. /* update the list of URLs */
  5330. if (DontReplaceOldDoc)
  5331. GetAmayaDoc (DocumentName, NULL, doc, doc,
  5332. Loading_method,
  5333. FALSE, NULL, NULL);
  5334. else
  5335. GetAmayaDoc (DocumentName, NULL, CurrentDocument,
  5336. CurrentDocument, Loading_method,
  5337. TRUE, NULL, NULL);
  5338. }
  5339. else if (DirectoryName[0] != EOS)
  5340. TtaSetStatus (CurrentDocument, 1,
  5341. TtaGetMessage (AMAYA, AM_CANNOT_LOAD),
  5342. DirectoryName);
  5343. else
  5344. TtaSetStatus (CurrentDocument, 1,
  5345. TtaGetMessage (AMAYA, AM_CANNOT_LOAD), "");
  5346. NewFile = FALSE;
  5347. CurrentDocument = 0;
  5348. }
  5349. }
  5350. else if (val == 2)
  5351. {
  5352. /* Browse button */
  5353. WidgetParent = OpenDocBrowser;
  5354. BrowserForm (CurrentDocument, 1, &LastURLName[0]);
  5355. }
  5356. else if (val == 3)
  5357. {
  5358. /* Clear button */
  5359. LastURLName[0] = EOS;
  5360. DirectoryName[0] = EOS;
  5361. DocumentName[0] = EOS;
  5362. }
  5363. else if (val == 0)
  5364. {
  5365. /* if the user has clicked on Cancel button, just destroy the dialog */
  5366. TtaDestroyDialogue ( ref );
  5367. }
  5368. else if (NewFile)
  5369. {
  5370. /* the command is aborted */
  5371. CheckAmayaClosed ();
  5372. NewFile = FALSE;
  5373. }
  5374. break;
  5375. /* this callback is used to select a destination for the new open document :
  5376. * 0 = replace current one
  5377. * 1 = in new tab
  5378. * 2 = in new window */
  5379. case OpenLocation:
  5380. {
  5381. if (val == 0) /* replace old doc */
  5382. {
  5383. DontReplaceOldDoc = FALSE;
  5384. InNewWindow = FALSE;
  5385. }
  5386. else if (val == 1) /* in new tab */
  5387. {
  5388. DontReplaceOldDoc = TRUE;
  5389. InNewWindow = FALSE;
  5390. }
  5391. else if (val == 2) /* in new window */
  5392. {
  5393. DontReplaceOldDoc = TRUE;
  5394. InNewWindow = TRUE;
  5395. }
  5396. }
  5397. break;
  5398. case DocInfoDocType:
  5399. /* only used by WX version to get back the new profile */
  5400. if (NewDocType == docHTML)
  5401. {
  5402. NewDocExtraProfile = 0;
  5403. char *compound = TtaGetMessage (AMAYA, AM_COMPOUND_DOCUMENT);
  5404. if (data && compound && !strcmp (data, compound))
  5405. NewDocProfile = L_Other;
  5406. else
  5407. {
  5408. if (!strstr (data, "XHTML"))
  5409. NewXML = FALSE;
  5410. if (strstr (data, "Strict"))
  5411. NewDocProfile = L_Strict;
  5412. else if (strstr (data, "Basic"))
  5413. NewDocProfile = L_Basic;
  5414. else if (strstr (data, "Transitional"))
  5415. NewDocProfile = L_Transitional;
  5416. else if (NewXML)
  5417. {
  5418. NewDocProfile = L_Xhtml11;
  5419. if (strstr (data, "RDFa"))
  5420. NewDocExtraProfile = L_RDFa;
  5421. }
  5422. else
  5423. NewDocProfile = L_Transitional;
  5424. }
  5425. }
  5426. break;
  5427. case URLName:
  5428. RemoveNewLines (data);
  5429. ptr = data;
  5430. updated = CompleteUrl (&ptr);
  5431. if (IsW3Path (ptr))
  5432. {
  5433. /* save the URL name */
  5434. strcpy (LastURLName, ptr);
  5435. DocumentName[0] = EOS;
  5436. }
  5437. else
  5438. {
  5439. LastURLName[0] = EOS;
  5440. change = NormalizeFile (ptr, tempfile, AM_CONV_NONE);
  5441. if (!IsW3Path (tempfile))
  5442. {
  5443. if (TtaCheckDirectory (tempfile))
  5444. {
  5445. strcpy (DirectoryName, tempfile);
  5446. DocumentName[0] = EOS;
  5447. }
  5448. else
  5449. TtaExtractName (tempfile, DirectoryName, DocumentName);
  5450. }
  5451. else
  5452. {
  5453. /* save the URL name */
  5454. strcpy (LastURLName, tempfile);
  5455. DocumentName[0] = EOS;
  5456. }
  5457. }
  5458. if (updated)
  5459. TtaFreeMemory (ptr);
  5460. break;
  5461. case DirSelect:
  5462. if (DirectoryName[0] != EOS)
  5463. {
  5464. if (!strcmp (data, ".."))
  5465. {
  5466. /* suppress last directory */
  5467. strcpy (tempname, DirectoryName);
  5468. TtaExtractName (tempname, DirectoryName, tempfile);
  5469. }
  5470. else
  5471. {
  5472. strcat (DirectoryName, DIR_STR);
  5473. strcat (DirectoryName, data);
  5474. }
  5475. TtaListDirectory (DirectoryName, BaseDialog + OpenForm,
  5476. TtaGetMessage (LIB, TMSG_DOC_DIR),
  5477. BaseDialog + DirSelect, ScanFilter,
  5478. TtaGetMessage (AMAYA, AM_FILES),
  5479. BaseDialog + DocSelect);
  5480. DocumentName[0] = EOS;
  5481. }
  5482. break;
  5483. case DocSelect:
  5484. if (DirectoryName[0] == EOS)
  5485. /* set path on current directory */
  5486. getcwd (DirectoryName, MAX_LENGTH);
  5487. /* Extract suffix from document name */
  5488. strcpy (DocumentName, data);
  5489. LastURLName[0] = EOS;
  5490. /* construct the document full name */
  5491. strcpy (tempfile, DirectoryName);
  5492. strcat (tempfile, DIR_STR);
  5493. strcat (tempfile, DocumentName);
  5494. break;
  5495. case ConfirmForm:
  5496. /* *********Confirm********* */
  5497. UserAnswer = (val == 1);
  5498. ExtraChoice = (val == 2);
  5499. TtaDestroyDialogue (BaseDialog + ConfirmForm);
  5500. break;
  5501. case FilterText:
  5502. /* Filter value */
  5503. if (strlen (data) <= NAME_LENGTH)
  5504. strcpy (ScanFilter, data);
  5505. break;
  5506. case FormAnswer:
  5507. /* *********Get an answer********* */
  5508. if (val == 0 || val == 2)
  5509. {
  5510. /* no answer */
  5511. Answer_text[0] = EOS;
  5512. Answer_name[0] = EOS;
  5513. Answer_password[0] = EOS;
  5514. UserAnswer = FALSE;
  5515. ExtraChoice = (val == 2);
  5516. }
  5517. else
  5518. UserAnswer = TRUE;
  5519. TtaDestroyDialogue (BaseDialog + FormAnswer);
  5520. break;
  5521. case AnswerText:
  5522. strncpy (Answer_text, data, MAX_LENGTH);
  5523. Answer_text[MAX_LENGTH - 1] = EOS;
  5524. break;
  5525. case NameText:
  5526. strncpy (Answer_name, data, NAME_LENGTH);
  5527. Answer_text[NAME_LENGTH - 1] = EOS;
  5528. break;
  5529. case PasswordText:
  5530. i = strlen (data);
  5531. if (i < NAME_LENGTH - 1)
  5532. {
  5533. Lg_password = 0;
  5534. while (Lg_password < i)
  5535. {
  5536. /* a new char */
  5537. Answer_password[Lg_password] = data[Lg_password];
  5538. Display_password[Lg_password] = '*';
  5539. Answer_password[++Lg_password] = EOS;
  5540. Display_password[Lg_password] = EOS;
  5541. }
  5542. }
  5543. else
  5544. Answer_password[NAME_LENGTH - 1] = EOS;
  5545. break;
  5546. case PasswordSave:
  5547. if (val == 0)
  5548. Answer_save_password = FALSE;
  5549. else
  5550. Answer_save_password = TRUE;
  5551. break;
  5552. i = strlen (data);
  5553. break;
  5554. /* *********Save document as********* */
  5555. case RadioSave:
  5556. /* Output format */
  5557. switch (val)
  5558. {
  5559. case 0: /* "Save as HTML" button */
  5560. SaveAsHTML = TRUE;
  5561. SaveAsXML = FALSE;
  5562. SaveAsText = FALSE;
  5563. SetFileSuffix ();
  5564. break;
  5565. case 1: /* "Save as XML" button */
  5566. SaveAsXML = TRUE;
  5567. SaveAsHTML = FALSE;
  5568. SaveAsText = FALSE;
  5569. SetFileSuffix ();
  5570. /* Set the document charset */
  5571. if (TtaGetDocumentCharset (SavingDocument) == UNDEFINED_CHARSET)
  5572. TtaSetDocumentCharset (SavingDocument, ISO_8859_1, FALSE);
  5573. break;
  5574. case 2: /* "Save as Text" button */
  5575. SaveAsText = TRUE;
  5576. SaveAsHTML = FALSE;
  5577. SaveAsXML = FALSE;
  5578. SetFileSuffix ();
  5579. break;
  5580. }
  5581. break;
  5582. case ToggleSave:
  5583. switch (val)
  5584. {
  5585. case 0: /* "Copy Images" button */
  5586. CopyImages = !CopyImages;
  5587. break;
  5588. case 1: /* "Transform URLs" button */
  5589. UpdateURLs = !UpdateURLs;
  5590. break;
  5591. }
  5592. break;
  5593. case SaveForm:
  5594. if (val == 1)
  5595. /* "Confirm" Button */
  5596. {
  5597. /* protect against saving without a MIME type */
  5598. if (SavingDocument != 0)
  5599. {
  5600. if (DocumentTypes[SavingDocument] == docHTML &&
  5601. DocumentMeta[SavingDocument])
  5602. {
  5603. if (DocumentMeta[SavingDocument]->xmlformat && SaveAsHTML)
  5604. /* XHTML -> HTML */
  5605. ChangeDoctype (FALSE);
  5606. if (!DocumentMeta[SavingDocument]->xmlformat && SaveAsXML)
  5607. /* HTML -> XHTML */
  5608. ChangeDoctype (TRUE);
  5609. }
  5610. if ((!DocumentMeta[SavingDocument]
  5611. || !DocumentMeta[SavingDocument]->content_type
  5612. || DocumentMeta[SavingDocument]->content_type[0] == EOS)
  5613. && (UserMimeType[0] == EOS))
  5614. break;
  5615. }
  5616. TtaDestroyDialogue (BaseDialog + SaveForm);
  5617. if (SavingDocument)
  5618. DoSaveAs (UserCharset, UserMimeType, FALSE);
  5619. else if (SavingObject)
  5620. {
  5621. DoSaveObjectAs ();
  5622. // make sure the saving is closed
  5623. SavingObject = 0;
  5624. }
  5625. /* Move the information into LastURLName or DirectoryName */
  5626. if (IsW3Path (SavePath))
  5627. {
  5628. strcpy (LastURLName, SavePath);
  5629. strcat (LastURLName, "/");
  5630. strcat (LastURLName, SaveName);
  5631. DirectoryName[0] = EOS;
  5632. }
  5633. else
  5634. {
  5635. LastURLName[0] = EOS;
  5636. strcpy (DirectoryName, SavePath);
  5637. strcat (DocumentName, SaveName);
  5638. }
  5639. }
  5640. else if (val == 2)
  5641. /* "Browse" button */
  5642. {
  5643. WidgetParent = DocSaveBrowser;
  5644. strcpy (LastURLName, SavePath);
  5645. strcat (LastURLName, DIR_STR);
  5646. strcat (LastURLName, SaveName);
  5647. BrowserForm (SavingDocument, 1, LastURLName);
  5648. }
  5649. else if (val == 3)
  5650. /* "Clear" button */
  5651. {
  5652. if (SavingDocument != 0)
  5653. {
  5654. SavePath[0] = EOS;
  5655. SaveImgsURL[0] = EOS;
  5656. SaveName[0] = EOS;
  5657. }
  5658. }
  5659. else if (val == 4)
  5660. /* "Charset" button */
  5661. {
  5662. if (SavingDocument != 0)
  5663. {
  5664. if (DocumentTypes[SavingDocument] != docImage)
  5665. {
  5666. /* clear the status message */
  5667. InitCharset (SavingDocument, 1, SavePath);
  5668. if (SaveFormTmp[0] != EOS)
  5669. {
  5670. strcpy (UserCharset, SaveFormTmp);
  5671. }
  5672. }
  5673. }
  5674. }
  5675. else if (val == 5)
  5676. /* "MIME type" button */
  5677. {
  5678. if (SavingDocument != 0)
  5679. {
  5680. if (SavePath[0])
  5681. {
  5682. InitMimeType (SavingDocument, 1, SavePath, NULL);
  5683. if (SaveFormTmp[0] != EOS)
  5684. strcpy (UserMimeType, SaveFormTmp);
  5685. }
  5686. }
  5687. }
  5688. else
  5689. /* "Cancel" button */
  5690. {
  5691. TtaDestroyDialogue (BaseDialog + SaveForm);
  5692. if (SavingObject)
  5693. /* delete temporary file */
  5694. DeleteTempObjectFile ();
  5695. SavingDocument = 0;
  5696. SavingObject = 0;
  5697. }
  5698. break;
  5699. case NameSave:
  5700. /* Document location */
  5701. if (!IsW3Path (data))
  5702. change = NormalizeFile (data, tempfile, AM_CONV_NONE);
  5703. else
  5704. strcpy (tempfile, data);
  5705. if (*tempfile && tempfile[strlen (tempfile) - 1] == sep)
  5706. {
  5707. strcpy (SavePath, tempfile);
  5708. SaveName[0] = EOS;
  5709. }
  5710. else
  5711. {
  5712. /* Extract document name */
  5713. if (SavingDocument != 0)
  5714. TtaExtractName (tempfile, SavePath, SaveName);
  5715. else
  5716. TtaExtractName (tempfile, SavePath, ObjectName);
  5717. }
  5718. break;
  5719. case ImgDirSave:
  5720. /* Image directory */
  5721. if (!IsW3Path (data))
  5722. change = NormalizeFile (data, SaveImgsURL, AM_CONV_NONE);
  5723. else
  5724. strcpy (SaveImgsURL, data);
  5725. break;
  5726. case CssDirSave:
  5727. /* Image directory */
  5728. if (!IsW3Path (data))
  5729. change = NormalizeFile (data, SaveCssURL, AM_CONV_NONE);
  5730. else
  5731. strcpy (SaveImgsURL, data);
  5732. break;
  5733. case ConfirmSave:
  5734. /* *********SaveConfirm********* */
  5735. UserAnswer = (val == 1);
  5736. TtaDestroyDialogue (BaseDialog + ConfirmSave);
  5737. if (!UserAnswer)
  5738. {
  5739. SavingDocument = 0;
  5740. SavingObject = 0;
  5741. }
  5742. break;
  5743. case AttrHREFForm:
  5744. /* *********HREF Attribute*********** */
  5745. if (val == 1)
  5746. {
  5747. /* Confirm button */
  5748. if (AttrHREFvalue[0] != EOS)
  5749. /* create an attribute HREF for the Link_Anchor */
  5750. SetREFattribute (AttrHREFelement, AttrHREFdocument,
  5751. AttrHREFvalue, NULL);
  5752. else
  5753. {
  5754. DoDeleteAnchor (AttrHREFdocument, 1, TRUE);
  5755. IsNewAnchor = FALSE;
  5756. LinkAsCSS = FALSE;
  5757. LinkAsXmlCSS = FALSE;
  5758. LinkAsJavascript = FALSE;
  5759. LinkAsImport = FALSE;
  5760. }
  5761. TtaDestroyDialogue (BaseDialog + AttrHREFForm);
  5762. //TtaDestroyDialogue (BaseDialog + FileBrowserForm);
  5763. }
  5764. else if (val == 2)
  5765. /* Browse button */
  5766. {
  5767. if (LinkAsXmlCSS || LinkAsCSS)
  5768. strcpy (ScanFilter, "*.css");
  5769. else if (LinkAsImport)
  5770. strcpy (ScanFilter, "*.xtl");
  5771. else if (LinkAsJavascript)
  5772. strcpy (ScanFilter, "*.js");
  5773. else if (!strcmp (ScanFilter, "*.css") && !strcmp (ScanFilter, "*.js"))
  5774. strcpy (ScanFilter, "*");
  5775. WidgetParent = HrefAttrBrowser;
  5776. BrowserForm (AttrHREFdocument, 1, &AttrHREFvalue[0]);
  5777. }
  5778. else if (val == 3)
  5779. /* allow one to click the target */
  5780. SelectDestination (AttrHREFdocument, AttrHREFelement, AttrHREFundoable, TRUE);
  5781. else if (val == 4)
  5782. {
  5783. /* Clear button */
  5784. AttrHREFvalue[0] = EOS;
  5785. }
  5786. else
  5787. /* Cancel button */
  5788. if (IsNewAnchor)
  5789. {
  5790. /* remove the link if it was just created */
  5791. TtaCloseUndoSequence (AttrHREFdocument);
  5792. TtaUndoNoRedo (AttrHREFdocument);
  5793. }
  5794. break;
  5795. case AttrHREFText:
  5796. /* save the HREF name */
  5797. RemoveNewLines (data);
  5798. if (IsW3Path (data))
  5799. {
  5800. /* save the URL name */
  5801. strcpy (AttrHREFvalue, data);
  5802. DocumentName[0] = EOS;
  5803. }
  5804. else
  5805. {
  5806. change = NormalizeFile (data, tempfile, AM_CONV_NONE);
  5807. if (TtaCheckDirectory (tempfile))
  5808. {
  5809. strcpy (DirectoryName, tempfile);
  5810. DocumentName[0] = EOS;
  5811. }
  5812. else
  5813. TtaExtractName (tempfile, DirectoryName, DocumentName);
  5814. strcpy (AttrHREFvalue, tempfile);
  5815. }
  5816. break;
  5817. /* *********File Browser*********** */
  5818. case FileBrowserForm:
  5819. if (val == 1)
  5820. {
  5821. /* Confirm button */
  5822. /* it's no longer the default Welcome page */
  5823. WelcomePage = FALSE;
  5824. /* this code is only valid under Unix. */
  5825. /* In Windows, we're using a system widget */
  5826. strcpy (tempfile, DirectoryName);
  5827. strcat (tempfile, DIR_STR);
  5828. strcat (tempfile, DocumentName);
  5829. if (WidgetParent == HrefAttrBrowser)
  5830. {
  5831. strcpy (AttrHREFvalue, tempfile);
  5832. CallbackDialogue (BaseDialog + AttrHREFForm, INTEGER_DATA, (char *) 1);
  5833. }
  5834. else if (WidgetParent == OpenDocBrowser)
  5835. {
  5836. CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
  5837. }
  5838. else if (WidgetParent == DocSaveBrowser)
  5839. {
  5840. CallbackDialogue (BaseDialog + NameSave, STRING_DATA, tempfile);
  5841. }
  5842. /* remove the browsing dialogue */
  5843. TtaDestroyDialogue (ref);
  5844. }
  5845. else if (val == 2)
  5846. /* Clear button */
  5847. {
  5848. if (WidgetParent == OpenDocBrowser)
  5849. {
  5850. LastURLName[0] = EOS;
  5851. }
  5852. else if (WidgetParent == HrefAttrBrowser)
  5853. {
  5854. tempname[0] = EOS;
  5855. }
  5856. }
  5857. else if (val == 3)
  5858. /* Filter button */
  5859. {
  5860. /* reinitialize directories and document lists */
  5861. TtaListDirectory (DirectoryName, BaseDialog + FileBrowserForm,
  5862. TtaGetMessage (LIB, TMSG_DOC_DIR),
  5863. BaseDialog + BrowserDirSelect,
  5864. ScanFilter, TtaGetMessage (AMAYA, AM_FILES),
  5865. BaseDialog + BrowserDocSelect);
  5866. }
  5867. break;
  5868. case FileBrowserText:
  5869. RemoveNewLines (data);
  5870. if (IsW3Path (data))
  5871. {
  5872. DocumentName[0] = EOS;
  5873. }
  5874. else
  5875. {
  5876. change = NormalizeFile (data, tempfile, AM_CONV_NONE);
  5877. if (TtaCheckDirectory (tempfile))
  5878. {
  5879. strcpy (DirectoryName, tempfile);
  5880. DocumentName[0] = EOS;
  5881. }
  5882. else
  5883. TtaExtractName (tempfile, DirectoryName, DocumentName);
  5884. strcpy (AttrHREFvalue, tempfile);
  5885. }
  5886. break;
  5887. /* *********Browser DirSelect*********** */
  5888. case BrowserDirSelect:
  5889. if (DirectoryName[0] != EOS)
  5890. {
  5891. if (!strcmp (data, ".."))
  5892. {
  5893. /* suppress last directory */
  5894. strcpy (tempname, DirectoryName);
  5895. TtaExtractName (tempname, DirectoryName, tempfile);
  5896. if (DirectoryName[0] == EOS)
  5897. strcpy (DirectoryName, DIR_STR);
  5898. }
  5899. else
  5900. {
  5901. strcat (DirectoryName, DIR_STR);
  5902. strcat (DirectoryName, data);
  5903. }
  5904. if (WidgetParent == OpenDocBrowser)
  5905. LastURLName[0] = EOS;
  5906. TtaListDirectory (DirectoryName, BaseDialog + FileBrowserForm,
  5907. TtaGetMessage (LIB, TMSG_DOC_DIR),
  5908. BaseDialog + BrowserDirSelect, ScanFilter,
  5909. TtaGetMessage (AMAYA, AM_FILES),
  5910. BaseDialog + BrowserDocSelect);
  5911. DocumentName[0] = EOS;
  5912. }
  5913. break;
  5914. /* *********Browser DocSelect*********** */
  5915. case BrowserDocSelect:
  5916. /* set path on current directory */
  5917. if (DirectoryName[0] == EOS)
  5918. getcwd (DirectoryName, MAX_LENGTH);
  5919. /* Extract suffix from document name */
  5920. strcpy (DocumentName, data);
  5921. if (WidgetParent == OpenDocBrowser)
  5922. LastURLName[0] = EOS;
  5923. /* construct the document full name */
  5924. strcpy (tempfile, DirectoryName);
  5925. strcat (tempfile, DIR_STR);
  5926. strcat (tempfile, DocumentName);
  5927. break;
  5928. /* *********Browser Filter*********** */
  5929. case FileBrowserFilter:
  5930. /* Filter value */
  5931. if (strlen(data) <= NAME_LENGTH)
  5932. strcpy (ScanFilter, data);
  5933. break;
  5934. case TitleForm:
  5935. /* ********Change the document title*********** */
  5936. TtaDestroyDialogue (BaseDialog + TitleForm);
  5937. if (val == 1)
  5938. SetNewTitle (CurrentDocument);
  5939. break;
  5940. case ListNSForm:
  5941. /* ********Update the NS declaration attached to an element*********** */
  5942. {
  5943. switch (val)
  5944. {
  5945. case 0:
  5946. TtaDestroyDialogue (ref);
  5947. CloseNSDeclaration ();
  5948. break;
  5949. }
  5950. break;
  5951. }
  5952. case ListNSAdd:
  5953. AddaNSDeclaration (data);
  5954. break;
  5955. case ListNSSupp:
  5956. RemoveaNSDeclaration (data);
  5957. break;
  5958. case TitleText:
  5959. /* new document name */
  5960. strncpy (Answer_text, data, MAX_LENGTH);
  5961. Answer_text[MAX_LENGTH - 1] = EOS;
  5962. break;
  5963. case ClassForm:
  5964. case ClassSelect:
  5965. case AClassForm:
  5966. case AClassSelect:
  5967. StyleCallbackDialogue (ref, typedata, data);
  5968. break;
  5969. case TableForm:
  5970. /* *********Table Form*********** */
  5971. UserAnswer = (val == 1);
  5972. TtaDestroyDialogue (BaseDialog + TableForm);
  5973. break;
  5974. case TableRows:
  5975. NumberRows = val;
  5976. break;
  5977. case TableCols:
  5978. NumberCols = val;
  5979. break;
  5980. case MathEntityForm:
  5981. /* ********* MathML entity form ********* */
  5982. if (val == 0)
  5983. /* no answer */
  5984. MathMLEntityName[0] = EOS;
  5985. TtaDestroyDialogue (ref);
  5986. break;
  5987. case MathEntityText:
  5988. strncpy (MathMLEntityName, data, MAX_LENGTH);
  5989. MathMLEntityName[MAX_LENGTH - 1] = EOS;
  5990. break;
  5991. case JavascriptPromptForm:
  5992. if (val == 0)
  5993. /* no answer */
  5994. JavascriptPromptValue[0] = EOS;
  5995. TtaDestroyDialogue (ref);
  5996. break;
  5997. case JavascriptPromptText:
  5998. strncpy (JavascriptPromptValue, data, MAX_LENGTH);
  5999. JavascriptPromptValue[MAX_LENGTH - 1] = EOS;
  6000. break;
  6001. case MakeIdMenu:
  6002. switch (val)
  6003. {
  6004. case 1:
  6005. CreateRemoveIDAttribute (IdElemName, IdDoc, TRUE, IdApplyToSelection);
  6006. break;
  6007. case 2:
  6008. CreateRemoveIDAttribute (IdElemName, IdDoc, FALSE, IdApplyToSelection);
  6009. break;
  6010. }
  6011. break;
  6012. case mElemName:
  6013. strncpy (IdElemName, data, MAX_LENGTH);
  6014. IdElemName[MAX_LENGTH - 1] = EOS;
  6015. break;
  6016. case mIdUseSelection:
  6017. IdApplyToSelection = (val != 0);
  6018. break;
  6019. /* Charset Save As menu */
  6020. case CharsetForm:
  6021. {
  6022. switch (val)
  6023. {
  6024. case 0:
  6025. SaveFormTmp[0] = EOS;
  6026. TtaDestroyDialogue (ref);
  6027. break;
  6028. case 1:
  6029. TtaDestroyDialogue (ref);
  6030. break;
  6031. }
  6032. }
  6033. break;
  6034. case CharsetSel:
  6035. switch (val)
  6036. {
  6037. case 0:
  6038. strcpy (SaveFormTmp, "us-ascii");
  6039. break;
  6040. case 1:
  6041. strcpy (SaveFormTmp, "UTF-8");
  6042. break;
  6043. case 2:
  6044. strcpy (SaveFormTmp, "iso-8859-1");
  6045. break;
  6046. case 3:
  6047. strcpy (SaveFormTmp, "iso-8859-2");
  6048. break;
  6049. }
  6050. break;
  6051. /* MIME type Save As menu */
  6052. case MimeTypeForm:
  6053. {
  6054. switch (val)
  6055. {
  6056. case 0:
  6057. SaveFormTmp[0] = EOS;
  6058. TtaDestroyDialogue (ref);
  6059. break;
  6060. case 1:
  6061. {
  6062. char *src, *dst;
  6063. /* filter the UserMimeType */
  6064. src = dst = SaveFormTmp;
  6065. while (*src)
  6066. {
  6067. if (!isascii (*src)
  6068. || (!isalnum (*src) && *src != '/' && *src != '-'
  6069. && *src != '+'))
  6070. {
  6071. /* skip the character */
  6072. src++;
  6073. continue;;
  6074. }
  6075. if (isupper (*src))
  6076. /* convert to lower case */
  6077. *dst = tolower (*src);
  6078. else
  6079. *dst = *src;
  6080. src++;
  6081. dst++;
  6082. }
  6083. *dst = EOS;
  6084. /* validate the mime type */
  6085. if (SaveFormTmp[0] == EOS ||!strchr (SaveFormTmp, '/'))
  6086. {
  6087. SaveFormTmp[0] = EOS;
  6088. }
  6089. else
  6090. TtaDestroyDialogue (ref);
  6091. }
  6092. break;
  6093. }
  6094. }
  6095. break;
  6096. case MimeTypeSel:
  6097. if (data)
  6098. strcpy (SaveFormTmp, data);
  6099. else
  6100. SaveFormTmp[0] = EOS;
  6101. break;
  6102. }
  6103. }
  6104. /*----------------------------------------------------------------------
  6105. RestoreOneAmayaDoc restores a saved file
  6106. doc is the suggested doc to be loaded or 0.
  6107. docname is the original name of the document.
  6108. tempdoc is the name of the saved file.
  6109. Return the new recovered document
  6110. URIs are encoded with the default charset.
  6111. ----------------------------------------------------------------------*/
  6112. static int RestoreOneAmayaDoc (Document doc, char *tempdoc, char *docname,
  6113. DocumentType docType, ThotBool iscrash)
  6114. {
  6115. AHTHeaders http_headers;
  6116. char content_type[MAX_LENGTH];
  6117. char tempfile[MAX_LENGTH];
  6118. int newdoc;
  6119. ThotBool stopped_flag;
  6120. W3Loading = doc;
  6121. BackupDocument = doc;
  6122. TtaExtractName (tempdoc, DirectoryName, DocumentName);
  6123. AddURLInCombobox (docname, NULL, TRUE);
  6124. newdoc = InitDocAndView (doc,
  6125. FALSE /* replaceOldDoc */,
  6126. TRUE /* inNewWindow */,
  6127. DocumentName, (DocumentType)docType, 0, FALSE,
  6128. L_Other, 0, CE_ABSOLUTE);
  6129. if (newdoc != 0)
  6130. {
  6131. /* load the saved file */
  6132. W3Loading = newdoc;
  6133. if (IsW3Path (docname))
  6134. {
  6135. /* it's a remote file */
  6136. /* clear the headers */
  6137. memset ((void *) &http_headers, 0, sizeof (AHTHeaders));
  6138. if (docType == docHTML)
  6139. {
  6140. strcpy (content_type, "text/html");
  6141. http_headers.content_type = content_type;
  6142. }
  6143. else
  6144. http_headers.content_type = NULL;
  6145. LoadDocument (newdoc, docname, NULL, NULL, CE_ABSOLUTE,
  6146. tempdoc, DocumentName, &http_headers, FALSE,
  6147. &DontReplaceOldDoc, docname);
  6148. }
  6149. else
  6150. {
  6151. /* it's a local file */
  6152. tempfile[0] = EOS;
  6153. /* load the temporary file */
  6154. LoadDocument (newdoc, tempdoc, NULL, NULL, CE_ABSOLUTE,
  6155. tempfile, DocumentName, NULL, FALSE,
  6156. &DontReplaceOldDoc, docname);
  6157. /* change its URL */
  6158. TtaFreeMemory (DocumentURLs[newdoc]);
  6159. DocumentURLs[newdoc] = TtaStrdup (docname);
  6160. DocumentSource[newdoc] = 0;
  6161. /* add the URI in the combobox string */
  6162. AddURLInCombobox (docname, NULL, FALSE);
  6163. TtaSetTextZone (newdoc, 1, URL_list);
  6164. /* change its directory name */
  6165. TtaSetDocumentDirectory (newdoc, DirectoryName);
  6166. }
  6167. TtaSetDocumentModified (newdoc);
  6168. W3Loading = 0; /* loading is complete now */
  6169. DocNetworkStatus[newdoc] = AMAYA_NET_ACTIVE;
  6170. // set the default icon
  6171. TtaSetPageIcon (newdoc, 1, NULL);
  6172. stopped_flag = FetchAndDisplayImages (newdoc, AMAYA_LOAD_IMAGE, NULL);
  6173. if (!stopped_flag)
  6174. {
  6175. ResetStop (newdoc);
  6176. DocNetworkStatus[newdoc] = AMAYA_NET_INACTIVE;
  6177. /* almost one file is restored */
  6178. TtaSetStatus (newdoc, 1, TtaGetMessage (AMAYA, AM_DOCUMENT_LOADED),
  6179. NULL);
  6180. }
  6181. /* check parsing errors */
  6182. CheckParsingErrors (newdoc);
  6183. /* unlink this saved file */
  6184. if (iscrash)
  6185. TtaFileUnlink (tempdoc);
  6186. }
  6187. BackupDocument = 0;
  6188. return (newdoc);
  6189. }
  6190. /*----------------------------------------------------------------------
  6191. RestoreAmayaDocs
  6192. Checks if Amaya has previously crashed.
  6193. The file Crash.amaya gives the list of saved files.
  6194. The file AutoSave.dat gives the list of auto-saved files
  6195. ----------------------------------------------------------------------*/
  6196. static ThotBool RestoreAmayaDocs ()
  6197. {
  6198. FILE *f;
  6199. char tempname[MAX_LENGTH], tempdoc[MAX_LENGTH];
  6200. char docname[MAX_LENGTH];
  6201. char line[MAX_LENGTH];
  6202. int docType, i, j;
  6203. ThotBool aDoc, iscrash, restore;
  6204. /* no document is opened */
  6205. aDoc = FALSE;
  6206. iscrash = FALSE;
  6207. /* check if Amaya has crashed */
  6208. sprintf (tempname, "%s%cCrash.amaya", TempFileDirectory, DIR_SEP);
  6209. if (TtaFileExist (tempname))
  6210. iscrash = TRUE;
  6211. else if (!AmayaUniqueInstance)
  6212. return FALSE;
  6213. else
  6214. sprintf (tempname, "%s%cAutoSave.dat", TempFileDirectory, DIR_SEP);
  6215. if (TtaFileExist (tempname))
  6216. {
  6217. InitConfirm (0, 0, TtaGetMessage (AMAYA, AM_RELOAD_FILES));
  6218. restore = UserAnswer;
  6219. f = TtaReadOpen (tempname);
  6220. if (f != NULL)
  6221. {
  6222. DontReplaceOldDoc = TRUE;
  6223. i = 0;
  6224. line[i] = EOS;
  6225. fread (&line[i], 1, 1, f);
  6226. while (line[0] == '"')
  6227. {
  6228. /* get the temp name */
  6229. do
  6230. {
  6231. i++;
  6232. fread (&line[i], 1, 1, f);
  6233. }
  6234. while (line[i] != '"');
  6235. line[i] = EOS;
  6236. strcpy (tempdoc, &line[1]);
  6237. /* skip spaces and the next first " */
  6238. do
  6239. {
  6240. i++;
  6241. fread (&line[i], 1, 1, f);
  6242. }
  6243. while (line[i] != '"');
  6244. /* get the origin name */
  6245. j = i + 1;
  6246. do
  6247. {
  6248. i++;
  6249. fread (&line[i], 1, 1, f);
  6250. }
  6251. while (line[i] != '"');
  6252. line[i] = EOS;
  6253. strcpy (docname, &line[j]);
  6254. /* skip spaces */
  6255. do
  6256. {
  6257. i++;
  6258. fread (&line[i], 1, 1, f);
  6259. }
  6260. while (line[i] == ' ');
  6261. /* get the docType */
  6262. j = i;
  6263. do
  6264. {
  6265. i++;
  6266. fread (&line[i], 1, 1, f);
  6267. }
  6268. while (line[i] != '\n');
  6269. line[i] = EOS;
  6270. sscanf (&line[j], "%d", &docType);
  6271. if (tempdoc[0] != EOS && TtaFileExist (tempdoc))
  6272. {
  6273. if (restore)
  6274. {
  6275. if (RestoreOneAmayaDoc (0, tempdoc, docname,
  6276. (DocumentType) docType, iscrash))
  6277. aDoc = TRUE;
  6278. }
  6279. else
  6280. /* unlink this saved file */
  6281. TtaFileUnlink (tempdoc);
  6282. }
  6283. /* next saved file */
  6284. i = 0;
  6285. line[i] = EOS;
  6286. fread (&line[i], 1, 1, f);
  6287. }
  6288. DontReplaceOldDoc = FALSE;
  6289. TtaReadClose (f);
  6290. }
  6291. if (iscrash)
  6292. {
  6293. TtaFileUnlink (tempname);
  6294. sprintf (tempname, "%s%cAutoSave.dat", TempFileDirectory, DIR_SEP);
  6295. if (TtaFileExist (tempname))
  6296. {
  6297. f = TtaReadOpen (tempname);
  6298. if (f != NULL)
  6299. {
  6300. i = 0;
  6301. line[i] = EOS;
  6302. fread (&line[i], 1, 1, f);
  6303. while (line[0] == '"')
  6304. {
  6305. /* get the temp name */
  6306. do
  6307. {
  6308. i++;
  6309. fread (&line[i], 1, 1, f);
  6310. }
  6311. while (line[i] != '"');
  6312. line[i] = EOS;
  6313. strcpy (tempdoc, &line[1]);
  6314. /* skip spaces and the next first " */
  6315. do
  6316. {
  6317. i++;
  6318. fread (&line[i], 1, 1, f);
  6319. }
  6320. while (line[i] != '"');
  6321. /* get the origin name */
  6322. j = i + 1;
  6323. do
  6324. {
  6325. i++;
  6326. fread (&line[i], 1, 1, f);
  6327. }
  6328. while (line[i] != '"');
  6329. line[i] = EOS;
  6330. strcpy (docname, &line[j]);
  6331. /* skip spaces */
  6332. do
  6333. {
  6334. i++;
  6335. fread (&line[i], 1, 1, f);
  6336. }
  6337. while (line[i] == ' ');
  6338. /* get the docType */
  6339. j = i;
  6340. do
  6341. {
  6342. i++;
  6343. fread (&line[i], 1, 1, f);
  6344. }
  6345. while (line[i] != '\n');
  6346. line[i] = EOS;
  6347. sscanf (&line[j], "%d", &docType);
  6348. if (tempdoc[0] != EOS && TtaFileExist (tempdoc))
  6349. /* unlink the auto-saved file */
  6350. TtaFileUnlink (tempdoc);
  6351. /*next auto-saved file */
  6352. i = 0;
  6353. line[i] = EOS;
  6354. fread (&line[i], 1, 1, f);
  6355. }
  6356. TtaReadClose (f);
  6357. }
  6358. TtaFileUnlink (tempname);
  6359. }
  6360. }
  6361. else
  6362. {
  6363. if (!UserAnswer)
  6364. TtaFileUnlink (tempname);
  6365. }
  6366. }
  6367. return (aDoc);
  6368. }
  6369. /*----------------------------------------------------------------------
  6370. FreeAmayaStructures cleans up memory ressources.
  6371. ----------------------------------------------------------------------*/
  6372. void FreeAmayaStructures ()
  6373. {
  6374. if (LastURLName)
  6375. {
  6376. /* now exit the application */
  6377. TtaFreeMemory (LastURLName);
  6378. LastURLName = NULL;
  6379. TtaFreeMemory (DocumentName);
  6380. TtaFreeMemory (DirectoryName);
  6381. TtaFreeMemory (SavePath);
  6382. TtaFreeMemory (SaveName);
  6383. TtaFreeMemory (ObjectName);
  6384. TtaFreeMemory (SaveImgsURL);
  6385. TtaFreeMemory (SaveCssURL);
  6386. TtaFreeMemory (SavingFile);
  6387. TtaFreeMemory (SavedDocumentURL);
  6388. TtaFreeMemory (AttrHREFvalue);
  6389. TtaFreeMemory (UserCSS);
  6390. TtaFreeMemory (URL_list);
  6391. TtaFreeMemory (Template_list);
  6392. TtaFreeMemory (AutoSave_list);
  6393. FreeHTMLParser ();
  6394. FreeXmlParserContexts ();
  6395. FreeDocHistory ();
  6396. FreeTransform ();
  6397. QueryClose ();
  6398. /* free mathml allocations */
  6399. FreeMathML();
  6400. /* free svg allocations */
  6401. FreeSVG ();
  6402. /* free last opened tab */
  6403. FreeLastClosedTab ();
  6404. #ifdef ANNOTATIONS
  6405. XPointer_bufferFree ();
  6406. ANNOT_Quit ();
  6407. #endif /* ANNOTATIONS */
  6408. #ifdef BOOKMARKS
  6409. BM_Quit ();
  6410. #endif /* BOOKMARKS */
  6411. #ifdef TEMPLATES
  6412. FreeTemplateRepositoryList ();
  6413. FreeTemplateEnvironment ();
  6414. #endif /* TEMPLATES */
  6415. #ifdef DAV
  6416. FreeDAVPathsList ();
  6417. #endif /* DAV */
  6418. /* Write and free password table */
  6419. WritePasswordTable ();
  6420. FreeAmayaCache ();
  6421. }
  6422. }
  6423. /*----------------------------------------------------------------------
  6424. InitAmaya intializes Amaya variables and open the first document window.
  6425. ----------------------------------------------------------------------*/
  6426. void InitAmaya (NotifyEvent * event)
  6427. {
  6428. char *s;
  6429. char *ptr;
  6430. int i;
  6431. ThotBool restoredDoc;
  6432. ThotBool map;
  6433. if (AmayaInitialized)
  6434. return;
  6435. AmayaInitialized = 1;
  6436. ErrFile = NULL;
  6437. CSSErrFile = NULL;
  6438. IgnoreErrors = FALSE;
  6439. W3Loading = 0;
  6440. BackupDocument = 0;
  6441. DoDialog = TRUE; /* don't update the CSS dialog by default */
  6442. /* the first window should be open in a new window */
  6443. InNewWindow = TRUE;
  6444. /* initialize status */
  6445. SelectionDoc = 0;
  6446. ParsedDoc = 0;
  6447. ParsedCSS = 0;
  6448. Error_DocURL = NULL; /* no current error */
  6449. SelectionInPRE = FALSE;
  6450. SelectionInComment = FALSE;
  6451. SelectionInEM = FALSE;
  6452. SelectionInSTRONG = FALSE;
  6453. SelectionInCITE = FALSE;
  6454. SelectionInABBR = FALSE;
  6455. SelectionInACRONYM = FALSE;
  6456. SelectionInINS = FALSE;
  6457. SelectionInDEL = FALSE;
  6458. SelectionInDFN = FALSE;
  6459. SelectionInCODE = FALSE;
  6460. SelectionInVAR = FALSE;
  6461. SelectionInSAMP = FALSE;
  6462. SelectionInKBD = FALSE;
  6463. SelectionInI = FALSE;
  6464. SelectionInB = FALSE;
  6465. SelectionInTT = FALSE;
  6466. SelectionInBIG = FALSE;
  6467. SelectionInSMALL = FALSE;
  6468. SelectionInSpan = FALSE;
  6469. Synchronizing = FALSE;
  6470. TableMenuActive = FALSE;
  6471. MTableMenuActive = FALSE;
  6472. Check_read_ids = FALSE;
  6473. IdElemName[0] = EOS;
  6474. /* Initialize the LogFile variables */
  6475. CleanUpParsingErrors ();
  6476. /* we're not linking an external CSS */
  6477. LinkAsCSS = FALSE;
  6478. LinkAsXmlCSS = FALSE;
  6479. LinkAsJavascript = FALSE;
  6480. LinkAsImport = FALSE;
  6481. ImgPosition = 0;
  6482. AttrHREFelement = NULL;
  6483. Right_ClickedElement = NULL;
  6484. /* init transformation callback */
  6485. TtaSetTransformCallback ((Func2) TransformIntoType);
  6486. TargetName = NULL;
  6487. TtaSetAccessKeyFunction ((Proc2) AccessKeyHandler);
  6488. TtaSetEntityFunction ((Proc4) MapEntityByCode);
  6489. TtaSetDoctypeFunction ((Proc3) HasADoctype);
  6490. TtaSetCopyAndCutFunction ((Proc1) RegisterURLSavedElements);
  6491. TtaSetCopyCellFunction ((Proc3) CopyCell);
  6492. TtaSetCopyRowFunction ((Proc3) CopyRow);
  6493. TtaSetNextCellInColumnFunction ((Proc5) NextCellInColumn);
  6494. TtaSetFocusChange ((Proc1) FocusChanged);
  6495. TtaSetAttributeChangeFunction ((Proc2) AttributeChange);
  6496. /* Initialize the Amaya user and tmp directories */
  6497. s = TtaGetEnvString ("APP_TMPDIR");
  6498. if (!TtaCheckMakeDirectory (s, TRUE))
  6499. /* try to use the default value */
  6500. {
  6501. s = TtaGetDefEnvString ("APP_TMPDIR");
  6502. if (TtaCheckMakeDirectory (s, TRUE))
  6503. /* make it the current user one */
  6504. TtaSetEnvString ("APP_TMPDIR", s, TRUE);
  6505. else
  6506. /* didn't work, so we exit */
  6507. {
  6508. sprintf (TempFileDirectory,
  6509. TtaGetMessage (AMAYA, AM_CANNOT_CREATE_DIRECTORY), s);
  6510. fprintf (stderr, TempFileDirectory);
  6511. exit (1);
  6512. }
  6513. }
  6514. /* add the temporary directory in document path */
  6515. strncpy (TempFileDirectory, s, MAX_LENGTH / 4 - 10);
  6516. TempFileDirectory[MAX_LENGTH / 4 - 10] = EOS;
  6517. TtaAppendDocumentPath (TempFileDirectory);
  6518. /*
  6519. * Build the User preferences file name:
  6520. * $HOME/.amaya/amaya.css on Unix platforms
  6521. * $HOME\amaya\amaya.css on Windows platforms
  6522. */
  6523. ptr = (char *)TtaGetMemory (MAX_LENGTH);
  6524. sprintf (ptr, "%s%c%s.css", s, DIR_SEP, TtaGetAppName());
  6525. UserCSS = TtaStrdup (ptr);
  6526. InitUserStyleSheet (UserCSS);
  6527. TtaFreeMemory (ptr);
  6528. /* check if the new location is set */
  6529. ptr = TtaGetEnvString ("NEW_LOCATION");
  6530. if (ptr == NULL)
  6531. {
  6532. i = 0;
  6533. TtaGetEnvInt("OPENING_LOCATION", &i);
  6534. TtaSetEnvInt ("NEW_LOCATION", i+1, TRUE);/* new tab */
  6535. }
  6536. else
  6537. ptr = NULL;
  6538. // Table options
  6539. TtaSetEnvInt ("TABLE_ROWS", 2, FALSE);
  6540. TtaSetEnvInt ("TABLE_COLUMNS", 5, FALSE);
  6541. TtaSetEnvInt ("TABLE_BORDER", 1, FALSE);
  6542. TtaSetEnvBoolean ("TABLE_EXTEND_WIDTH", TRUE, FALSE);
  6543. TtaSetEnvBoolean ("TABLE_CAPTION", TRUE, FALSE);
  6544. // SaveAs options
  6545. TtaSetEnvBoolean ("TRANSFORM_URL", TRUE, FALSE);
  6546. TtaSetEnvBoolean ("COPY_IMAGES", FALSE, FALSE);
  6547. TtaSetEnvBoolean ("COPY_CSS", FALSE, FALSE);
  6548. /* Initialize environment variables if they are not defined */
  6549. TtaSetEnvString ("DOCUMENT_CHARSET", "iso-8859-1", FALSE);
  6550. TtaSetEnvString ("LOCAL_HTML_DOCTYPE_1", "", FALSE);
  6551. TtaSetEnvString ("LOCAL_HTML_DOCTYPE_2", "", FALSE);
  6552. TtaSetEnvString ("WIKI_SERVER", "http://sweetwiki.inria.fr/", FALSE);
  6553. TtaSetEnvString ("WIKI_GET_PARAMS", "templateoff=true&xslname=queryoff", FALSE);
  6554. TtaSetEnvString ("WIKI_POST_URI", "http://sweetwiki.inria.fr/interop/data/Tools/OfficeConverter.jsp?web=Main", FALSE);
  6555. TtaSetEnvString ("WIKI_POST_PARAMS", "name=WIKI:name&web=WIKI:hasForWeb", FALSE);
  6556. // set the default access mode
  6557. #ifdef _MACOS
  6558. TtaSetEnvString ("ACCESSKEY_MOD", "Ctrl", FALSE);
  6559. #else /* _MACOS */
  6560. TtaSetEnvString ("ACCESSKEY_MOD", "Alt", FALSE);
  6561. #endif /* _MACOS */
  6562. /* check if an Amaya profile is set */
  6563. ptr = TtaGetEnvString ("CURRENT_PROFILE");
  6564. if (ptr == NULL)
  6565. {
  6566. TtaSetEnvString ("CURRENT_PROFILE", "Advanced", FALSE);
  6567. // Avoid to save previous "AUI_DECORATION"
  6568. SavePANEL_PREFERENCES = 0;
  6569. }
  6570. else
  6571. ptr = NULL;
  6572. TtaSetEnvBoolean ("SHOW_MAP_AREAS", FALSE, FALSE);
  6573. TtaSetEnvBoolean ("SHOW_TARGET", FALSE, FALSE);
  6574. TtaSetEnvBoolean ("LOAD_IMAGES", TRUE, FALSE);
  6575. TtaSetEnvBoolean ("LOAD_OBJECTS", TRUE, FALSE);
  6576. TtaSetEnvBoolean ("LOAD_CSS", TRUE, FALSE);
  6577. TtaSetEnvBoolean ("SEND_REFERER", FALSE, FALSE);
  6578. TtaSetEnvBoolean ("INSERT_NBSP", FALSE, FALSE);
  6579. TtaSetEnvBoolean ("GENERATE_MATHPI", FALSE, FALSE);
  6580. TtaSetEnvBoolean ("EDIT_SRC_TEMPLATE", FALSE, FALSE);
  6581. TtaSetEnvBoolean ("SHOW_PLACEHOLDER", TRUE, FALSE);
  6582. TtaSetEnvBoolean ("CLOSE_WHEN_APPLY", TRUE, FALSE);
  6583. TtaSetEnvBoolean("OPEN_PANEL", TRUE, FALSE);
  6584. TtaSetEnvBoolean("BROWSE_TOOLBAR", TRUE, FALSE);
  6585. TtaSetEnvBoolean("EDIT_TOOLBAR", TRUE, FALSE);
  6586. TtaSetEnvBoolean ("XML_EDIT_MODE", FALSE, FALSE);
  6587. TtaSetEnvBoolean ("USE_XML_DECLARATION", TRUE, FALSE);
  6588. TtaSetEnvBoolean ("COLOR_SOURCE", TRUE, FALSE);
  6589. /* get current value */
  6590. TtaGetEnvBoolean ("SHOW_MAP_AREAS", &map);
  6591. /* Create and intialize resources needed for each document */
  6592. /* Style sheets are strored in directory .amaya/0 */
  6593. for (i = 0; i < DocumentTableLength; i++)
  6594. {
  6595. /* initialize document table */
  6596. DocumentURLs[i] = NULL;
  6597. DocumentTypes[i] = docHTML;
  6598. DocumentSource[i] = 0;
  6599. DocumentMeta[i] = NULL;
  6600. MapAreas[i] = map;
  6601. HSplit[i] = FALSE;
  6602. VSplit[i] = FALSE;
  6603. /* initialize history */
  6604. InitDocHistory (i);
  6605. }
  6606. /* allocate working buffers */
  6607. LastURLName = (char *)TtaGetMemory (MAX_LENGTH);
  6608. LastURLName[0] = EOS;
  6609. DirectoryName = (char *)TtaGetMemory (MAX_LENGTH);
  6610. DirectoryName[0] = EOS;
  6611. SavedDocumentURL = NULL;
  6612. /* set path on current directory */
  6613. wxString homedir = TtaGetHomeDir ();
  6614. strncpy (DirectoryName, (const char *)homedir.mb_str(wxConvUTF8),MAX_LENGTH / 4 - 10);
  6615. DirectoryName[MAX_LENGTH / 4 - 10] = EOS;
  6616. if (DirectoryName[0] == EOS || !TtaDirExists (DirectoryName))
  6617. getcwd (DirectoryName, MAX_LENGTH);
  6618. DocumentName = (char *)TtaGetMemory (MAX_LENGTH);
  6619. memset (DocumentName, EOS, MAX_LENGTH);
  6620. SavePath = (char *)TtaGetMemory (MAX_LENGTH);
  6621. SavePath[0] = EOS;
  6622. SaveName = (char *)TtaGetMemory (MAX_LENGTH);
  6623. SaveName[0] = EOS;
  6624. ObjectName = (char *)TtaGetMemory (MAX_LENGTH);
  6625. ObjectName[0] = EOS;
  6626. SaveImgsURL = (char *)TtaGetMemory (MAX_LENGTH);
  6627. SaveImgsURL[0] = EOS;
  6628. SaveCssURL = (char *)TtaGetMemory (MAX_LENGTH);
  6629. SaveCssURL[0] = EOS;
  6630. strcpy (ScanFilter, "*.*htm*");
  6631. SaveAsHTML = TRUE;
  6632. SaveAsXML = FALSE;
  6633. SaveAsText = FALSE;
  6634. CopyImages = FALSE;
  6635. RemoveTemplate = FALSE;
  6636. UpdateURLs = FALSE;
  6637. SavingFile = (char *)TtaGetMemory (MAX_LENGTH);
  6638. AttrHREFvalue = (char *)TtaGetMemory (MAX_LENGTH);
  6639. AttrHREFvalue[0] = EOS;
  6640. // Initialize the meta dialog
  6641. MetaName = MetaEquiv = MetaContent = NULL;
  6642. #ifdef WITH_SOCKS
  6643. SOCKSinit ("amaya");
  6644. #endif
  6645. /* initialize parser mapping table and HTLib */
  6646. InitMapping ();
  6647. /* Define the backup function */
  6648. TtaSetBackup (BackUpDocs);
  6649. /* Define the auto-save function */
  6650. TtaSetAutoSave ((Proc1)GenerateAutoSavedDoc);
  6651. /* Define the auto-save interval */
  6652. TtaGetEnvInt ("AUTO_SAVE", &AutoSave_Interval);
  6653. TtaSetDocumentBackUpInterval (AutoSave_Interval);
  6654. TtaSetApplicationQuit (FreeAmayaStructures);
  6655. TtaSetDocStatusUpdate ((Proc) DocStatusUpdate);
  6656. AMAYA = TtaGetMessageTable ("amayamsg", AMAYA_MSG_MAX);
  6657. /* allocate callbacks for amaya */
  6658. BaseDialog = TtaSetCallback ((Proc)CallbackDialogue, MAX_REF);
  6659. /* init the Picture context */
  6660. InitImage ();
  6661. /* init the Picture context */
  6662. InitPrint ();
  6663. /* init the CSS context */
  6664. InitCSS ();
  6665. /* initialize the structure transformation context */
  6666. InitTransform ();
  6667. /* initialize automaton for the HTML parser */
  6668. InitAutomaton ();
  6669. /* initialize the configuration menu context */
  6670. InitConfMenu ();
  6671. #ifdef ANNOTATIONS
  6672. ANNOT_Init ();
  6673. #endif /* ANNOTATIONS */
  6674. /* initialize the libwww */
  6675. QueryInit ();
  6676. /* initialize the Amaya cache */
  6677. InitAmayaCache ();
  6678. /* now we know if it's a unique instance */
  6679. #ifdef BOOKMARKS
  6680. BM_Init ();
  6681. #endif /* BOOKMARKS */
  6682. #ifdef _WINDOWS
  6683. sprintf (LostPicturePath, "%s\\amaya\\lost.gif", TtaGetEnvString ("THOTDIR"));
  6684. #endif /* _WINDOWS */
  6685. InitMathML ();
  6686. #ifdef _SVG
  6687. InitSVG ();
  6688. InitSVGAnim ();
  6689. #endif /* _SVG */
  6690. /* MKP: disable "Cooperation" menu if DAV is not defined or
  6691. * initialize davlib module otherwise */
  6692. #ifdef DAV
  6693. InitDAV ();
  6694. #else /* DAV */
  6695. DAVLibEnable = FALSE;
  6696. #endif /* DAV */
  6697. #ifdef TEMPLATES
  6698. InitTemplates();
  6699. #endif
  6700. TtaRegisterDocumentPageTypeFunction(ChooseDocumentPage);
  6701. TtaSetPopupDocContextMenuFunction((PopupDocContextMenuFuction)AmayaPopupDocContextMenu);
  6702. InsertableElement_Init();
  6703. /* Register Amaya-specific ToolPanel classes. */
  6704. RegisterToolPanelClass(CLASSINFO(StyleListToolPanel));
  6705. URL_list = NULL;
  6706. URL_list_len = 0;
  6707. InitStringForCombobox ();
  6708. RDFa_list = NULL;
  6709. RDFa_list_len = 0;
  6710. InitRDFaListForCombobox ();
  6711. AutoSave_list = NULL;
  6712. AutoSave_list_len = 0;
  6713. InitAutoSave ();
  6714. // synchronize information
  6715. HighlightDocument = 0;
  6716. HighlightElement = NULL;
  6717. HighLightAttribute = NULL;
  6718. // load information
  6719. CurrentDocument = 0;
  6720. DocBook = 0;
  6721. DontReplaceOldDoc = FALSE;
  6722. restoredDoc = RestoreAmayaDocs ();
  6723. s = NULL;
  6724. if (restoredDoc)
  6725. {
  6726. /* old documents are restored */
  6727. TtaFreeMemory (ptr);
  6728. return;
  6729. }
  6730. int arg_doc_id = 1;
  6731. while (arg_doc_id < appArgc)
  6732. {
  6733. s = appArgv[arg_doc_id];
  6734. OpenNewDocFromArgv(s);
  6735. arg_doc_id++;
  6736. }
  6737. /* load the homepage if nothing has been found in the command line */
  6738. if (arg_doc_id == 1)
  6739. OpenNewDocFromArgv(NULL);
  6740. TtaFreeMemory (ptr);
  6741. ptr = NULL;
  6742. Loading_method = CE_ABSOLUTE;
  6743. /* register openurl callback in order to call it when twice amaya instance are running */
  6744. TtaRegisterOpenURLCallback( (void (*)(void*))OpenNewDocFromArgv );
  6745. /* send math entities to MathML panel */
  6746. AmayaParams p;
  6747. p.param1 = 1; /* init action */
  6748. p.param2 = (void*)pMathEntityTable;
  6749. TtaSendDataToPanel( WXAMAYA_PANEL_SPECHAR, p );
  6750. /* Show TipOfTheDay dialog. */
  6751. TtaSetEnvBoolean("TIP_OF_THE_DAY_STARTUP", TRUE, FALSE);
  6752. if(TtaShowTipOfTheDayAtStartup())
  6753. TtaShowTipOfTheDay();
  6754. }
  6755. /*----------------------------------------------------------------------
  6756. ----------------------------------------------------------------------*/
  6757. void OpenNewDocFromArgv( char * url )
  6758. {
  6759. int i, doc, view;
  6760. char ptr[MAX_LENGTH];
  6761. char * s = url;
  6762. /* load the document in the default location */
  6763. LoadDefaultOpeningLocation (TRUE);
  6764. if (s == NULL || s[0] == EOS)
  6765. /* no argument: display the Home Page */
  6766. s = TtaGetEnvString ("HOME_PAGE");
  6767. if (URL_list && s && !strcasecmp (s, "$PREV"))
  6768. {
  6769. /* no argument and no Home: display the previous open URI */
  6770. for (i = 0; URL_list[i] != EOS && URL_list[i] != EOL; i++)
  6771. ptr[i] = URL_list[i];
  6772. ptr[i] = EOS;
  6773. s = ptr;
  6774. }
  6775. if (s == NULL || s[0] == EOS)
  6776. {
  6777. /* no argument, no Home, and no previous page: display default Amaya URL */
  6778. GoToHome (0, 1);
  6779. }
  6780. else if (IsW3Path (s))
  6781. {
  6782. /* it's a remote document */
  6783. strncpy (LastURLName, s, MAX_LENGTH / 4);
  6784. LastURLName[MAX_LENGTH / 4] = EOS;
  6785. CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
  6786. }
  6787. else
  6788. {
  6789. NormalizeFile (s, LastURLName, AM_CONV_NONE);
  6790. if (IsW3Path (LastURLName))
  6791. {
  6792. /* if the command line paremeter
  6793. is a url without http://
  6794. it's a remote document or
  6795. a new file (doesn't exist yet )
  6796. in the current path */
  6797. strcpy (s, LastURLName);
  6798. CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
  6799. }
  6800. else
  6801. {
  6802. /* check if it is an absolute or a relative name */
  6803. #ifdef _WINDOWS
  6804. if (LastURLName[0] == DIR_SEP || LastURLName[1] == ':')
  6805. #else /* _WINDOWS */
  6806. if (LastURLName[0] == DIR_SEP)
  6807. #endif /* _WINDOWS */
  6808. /* it is an absolute name */
  6809. TtaExtractName (LastURLName, DirectoryName, DocumentName);
  6810. else
  6811. {
  6812. /* it is a relative name */
  6813. getcwd (DirectoryName, MAX_LENGTH);
  6814. strcpy (DocumentName, LastURLName);
  6815. }
  6816. /* start with the local document */
  6817. LastURLName[0] = EOS;
  6818. NewFile = FALSE;
  6819. CallbackDialogue (BaseDialog + OpenForm, INTEGER_DATA, (char *) 1);
  6820. }
  6821. }
  6822. // raise the view if it is not shown
  6823. TtaGetActiveView (&doc, &view);
  6824. TtaRaiseView (doc, view);
  6825. }
  6826. /*----------------------------------------------------------------------
  6827. ChangeAttrOnRoot
  6828. If the root element of the document does not have an attribute of
  6829. type attrNum, create one.
  6830. If the root has such an attribute, delete it.
  6831. ----------------------------------------------------------------------*/
  6832. void ChangeAttrOnRoot (Document doc, int attrNum)
  6833. {
  6834. Element root, el;
  6835. AttributeType attrType;
  6836. Attribute attr;
  6837. int position;
  6838. int distance;
  6839. ThotBool docModified;
  6840. docModified = TtaIsDocumentModified (doc);
  6841. root = TtaGetRootElement (doc);
  6842. /* get the current position in the document */
  6843. position = RelativePosition (doc, &distance);
  6844. TtaSetDisplayMode (doc, NoComputedDisplay);
  6845. attrType.AttrSSchema = TtaGetDocumentSSchema (doc);
  6846. attrType.AttrTypeNum = attrNum;
  6847. attr = TtaGetAttribute (root, attrType);
  6848. if (attr != NULL)
  6849. /* the root element has that attribute. Remove it */
  6850. TtaRemoveAttribute (root, attr, doc);
  6851. else
  6852. /* the root element does not have that attribute. Create it */
  6853. {
  6854. attr = TtaNewAttribute (attrType);
  6855. TtaSetAttributeValue (attr, 1, NULL, doc);
  6856. TtaAttachAttribute (root, attr, doc);
  6857. }
  6858. if (!docModified)
  6859. {
  6860. TtaSetDocumentUnmodified (doc);
  6861. /* switch Amaya buttons and menus */
  6862. DocStatusUpdate (doc, docModified);
  6863. }
  6864. TtaSetDisplayMode (doc, DisplayImmediately);
  6865. /* show the document at the same position */
  6866. el = ElementAtPosition (doc, position);
  6867. TtaShowElement (doc, 1, el, distance);
  6868. }
  6869. /*----------------------------------------------------------------------
  6870. ShowPanel
  6871. show/hide the side panel
  6872. ----------------------------------------------------------------------*/
  6873. void ShowPanel (Document doc, View view)
  6874. {
  6875. int frame_id = GetWindowNumber (doc, view);
  6876. TtaToggleOnOffSidePanel( frame_id );
  6877. }
  6878. /*----------------------------------------------------------------------
  6879. ShowBrowsingBar
  6880. show/hide the navigation toolbar
  6881. ----------------------------------------------------------------------*/
  6882. void ShowBrowsingBar (Document doc, View view)
  6883. {
  6884. int frame_id = GetWindowNumber (doc, view);
  6885. TtaToggleToolbar( frame_id, 0 );
  6886. }
  6887. /*----------------------------------------------------------------------
  6888. ShowEditingBar
  6889. show/hide the edition toolbar
  6890. ----------------------------------------------------------------------*/
  6891. void ShowEditingBar (Document doc, View view)
  6892. {
  6893. int frame_id = GetWindowNumber (doc, view);
  6894. TtaToggleToolbar( frame_id, 1 );
  6895. }
  6896. /*----------------------------------------------------------------------
  6897. FullScreen
  6898. enable/disable fullscreen
  6899. ----------------------------------------------------------------------*/
  6900. void FullScreen (Document doc, View view)
  6901. {
  6902. int frame_id = GetWindowNumber (doc, view);
  6903. TtaToggleOnOffFullScreen( frame_id );
  6904. }
  6905. /*----------------------------------------------------------------------
  6906. SplitHorizontally
  6907. split horizontally the view
  6908. ----------------------------------------------------------------------*/
  6909. void SplitHorizontally (Document doc, View view)
  6910. {
  6911. int frame_id = GetWindowNumber (doc, view);
  6912. TtaSplitViewHorizontally( frame_id );
  6913. }
  6914. /*----------------------------------------------------------------------
  6915. SplitVertically
  6916. split vertically the view
  6917. ----------------------------------------------------------------------*/
  6918. void SplitVertically (Document doc, View view)
  6919. {
  6920. int frame_id = GetWindowNumber (doc, view);
  6921. TtaSplitViewVertically( frame_id );
  6922. }
  6923. /*----------------------------------------------------------------------
  6924. ShowHSplitToggle
  6925. Show toggle mark
  6926. ----------------------------------------------------------------------*/
  6927. void ShowHSplitToggle (Document doc, View view)
  6928. {
  6929. HSplit[doc] = TRUE;
  6930. TtaSetToggleItem (doc, view, Views, TSplitHorizontally, HSplit[doc]);
  6931. // Set V toggle off
  6932. HideVSplitToggle (doc, view);
  6933. // Update the document source toggle
  6934. if (DocumentSource[doc])
  6935. {
  6936. HSplit[DocumentSource[doc]] = TRUE;
  6937. TtaSetToggleItem (DocumentSource[doc], 1, Views,
  6938. TSplitHorizontally, HSplit[DocumentSource[doc]]);
  6939. }
  6940. }
  6941. /*----------------------------------------------------------------------
  6942. ShowVSplitToggle
  6943. Show toggle mark
  6944. ----------------------------------------------------------------------*/
  6945. void ShowVSplitToggle (Document doc, View view)
  6946. {
  6947. VSplit[doc] = TRUE;
  6948. TtaSetToggleItem (doc, view, Views, TSplitVertically, VSplit[doc]);
  6949. // Set H toggle off
  6950. HideHSplitToggle (doc, view);
  6951. // Update the document source toggle
  6952. if (DocumentSource[doc])
  6953. {
  6954. VSplit[DocumentSource[doc]] = TRUE;
  6955. TtaSetToggleItem (DocumentSource[doc], 1, Views,
  6956. TSplitVertically, VSplit[DocumentSource[doc]]);
  6957. }
  6958. }
  6959. /*----------------------------------------------------------------------
  6960. HideHSplitToggle
  6961. Hide toggle mark
  6962. ----------------------------------------------------------------------*/
  6963. void HideHSplitToggle (Document doc, View view)
  6964. {
  6965. HSplit[doc] = FALSE;
  6966. TtaSetToggleItem (doc, view, Views, TSplitHorizontally, HSplit[doc]);
  6967. // Update the document source toggle
  6968. if (DocumentSource[doc])
  6969. {
  6970. HSplit[DocumentSource[doc]] = FALSE;
  6971. TtaSetToggleItem (DocumentSource[doc], 1, Views,
  6972. TSplitHorizontally, HSplit[DocumentSource[doc]]);
  6973. }
  6974. }
  6975. /*----------------------------------------------------------------------
  6976. HideVSplitToggle
  6977. Hide toggle mark
  6978. ----------------------------------------------------------------------*/
  6979. void HideVSplitToggle (Document doc, View view)
  6980. {
  6981. VSplit[doc] = FALSE;
  6982. TtaSetToggleItem (doc, view, Views, TSplitVertically, VSplit[doc]);
  6983. // Update the document source toggle
  6984. if (DocumentSource[doc])
  6985. {
  6986. VSplit[DocumentSource[doc]] = FALSE;
  6987. TtaSetToggleItem (DocumentSource[doc], 1, Views,
  6988. TSplitVertically, VSplit[DocumentSource[doc]]);
  6989. }
  6990. }
  6991. /*----------------------------------------------------------------------
  6992. ShowMapAreas
  6993. Execute the "Show Map Areas" command
  6994. ----------------------------------------------------------------------*/
  6995. void ShowMapAreas (Document doc, View view)
  6996. {
  6997. MapAreas[doc] = !MapAreas[doc];
  6998. TtaSetToggleItem (doc, view, Views, TShowMapAreas, MapAreas[doc]);
  6999. ChangeAttrOnRoot (doc, HTML_ATTR_ShowAreas);
  7000. }
  7001. /*----------------------------------------------------------------------
  7002. MakeIDMenu
  7003. A menu for adding or removing ID attributes in a document
  7004. ----------------------------------------------------------------------*/
  7005. void MakeIDMenu (Document doc, View view)
  7006. {
  7007. /* initialize the global variables */
  7008. IdStatus[0] = EOS;
  7009. IdDoc = doc;
  7010. if (CreateMakeIdDlgWX (BaseDialog + MakeIdMenu, TtaGetViewFrame (doc, view)))
  7011. {
  7012. TtaSetDialoguePosition ();
  7013. TtaShowDialogue (BaseDialog + MakeIdMenu, FALSE, TRUE);
  7014. }
  7015. }
  7016. /*----------------------------------------------------------------------
  7017. CheckAmayaClosed closes the application when there is no more
  7018. opened document
  7019. ----------------------------------------------------------------------*/
  7020. void CheckAmayaClosed ()
  7021. {
  7022. int i;
  7023. /* is it the last loaded document ? */
  7024. i = 1;
  7025. while (i < DocumentTableLength &&
  7026. (DocumentURLs[i] == NULL ||
  7027. DocumentMeta[i] == NULL ||
  7028. IsInternalTemplateDocument(i) ||
  7029. DocumentMeta[i]->method == CE_HELP))
  7030. i++;
  7031. if (i == DocumentTableLength)
  7032. {
  7033. /* remove images loaded by shared CSS style sheets */
  7034. RemoveLoadedResources (0, &ImageURLs);
  7035. #ifdef _JAVA
  7036. DestroyJavascript ();
  7037. #endif /* _JAVA */
  7038. /* remove the AutoSave file */
  7039. TtaQuit ();
  7040. }
  7041. }
  7042. /*----------------------------------------------------------------------
  7043. CloseDocumentDialogs
  7044. ----------------------------------------------------------------------*/
  7045. void CloseDocumentDialogs (Document doc, View view)
  7046. {
  7047. if (SavingDocument == doc)
  7048. {
  7049. // the dialog widget will be destroyed
  7050. TtaDestroyDialogue (BaseDialog + SaveForm);
  7051. SavingDocument = 0;
  7052. }
  7053. }
  7054. /*----------------------------------------------------------------------
  7055. CloseTab close the current active page
  7056. Shortcut : CTRL x + CTRL p
  7057. ----------------------------------------------------------------------*/
  7058. void AmayaCloseTab (Document doc, View view)
  7059. {
  7060. int page_id = -1;
  7061. int page_position = 0;
  7062. int window_id = 0;
  7063. if (CanReplaceCurrentDocument (doc, view))
  7064. {
  7065. if (DocumentTypes[doc] == docSource)
  7066. {
  7067. // check possible changes in the formatted view
  7068. doc = GetDocFromSource (doc);
  7069. if (!CanReplaceCurrentDocument (doc, view))
  7070. return;
  7071. }
  7072. CloseDocumentDialogs (doc, view);
  7073. window_id = TtaGetDocumentWindowId( doc, view );
  7074. /* Get the window id and page id of current document and
  7075. close the corresponding page */
  7076. TtaGetDocumentPageId( doc, view, &page_id, &page_position );
  7077. if (TtaClosePage( window_id, page_id ))
  7078. TtaCleanUpWindow( window_id );
  7079. }
  7080. }
  7081. /*----------------------------------------------------------------------
  7082. CloseOtherTabs close all tabs but selected
  7083. ----------------------------------------------------------------------*/
  7084. void CloseOtherTabs( Document doc, View view)
  7085. {
  7086. int page_id = -1;
  7087. int page_position = 0;
  7088. int window_id = 0;
  7089. window_id = TtaGetDocumentWindowId( doc, view );
  7090. /* Get the window id and page id of current document and
  7091. close the corresponding page */
  7092. TtaGetDocumentPageId (doc, view, &page_id, &page_position);
  7093. TtaCloseAllPageButThis (window_id, page_id);
  7094. }
  7095. /*----------------------------------------------------------------------
  7096. NewTab open a new tab with an empty page
  7097. ----------------------------------------------------------------------*/
  7098. void NewTab (Document doc, View view)
  7099. {
  7100. char *s = (char *)TtaGetMemory (MAX_LENGTH);
  7101. #ifdef _WINDOWS
  7102. sprintf (s, "%s\\empty", TtaGetEnvString ("THOTDIR"));
  7103. #else /* _WINDOWS */
  7104. sprintf (s, "%s/empty", TtaGetEnvString ("THOTDIR"));
  7105. #endif /* _WINDOWS */
  7106. /* load an empty document */
  7107. ThotCallback (BaseDialog + URLName, STRING_DATA, s);
  7108. DontReplaceOldDoc = TRUE;
  7109. InNewWindow = FALSE;
  7110. ThotCallback (BaseDialog + OpenForm, INTEGER_DATA, (char*)1);
  7111. TtaFreeMemory (s);
  7112. }
  7113. /*----------------------------------------------------------------------
  7114. RefreshTab force the page to refresh
  7115. ----------------------------------------------------------------------*/
  7116. void RefreshTab (Document doc, View view)
  7117. {
  7118. DisplayMode dispMode;
  7119. dispMode = TtaGetDisplayMode (doc);
  7120. if (dispMode == DisplayImmediately)
  7121. {
  7122. TtaSetDisplayMode (doc, NoComputedDisplay);
  7123. RedisplayDoc (doc);
  7124. TtaSetDisplayMode (doc, dispMode);
  7125. //TtaPlay (doc, 1);
  7126. }
  7127. }
  7128. /*----------------------------------------------------------------------
  7129. RefreshAllTabs force all pages to refresh
  7130. ----------------------------------------------------------------------*/
  7131. void RefreshAllTabs (Document doc, View view)
  7132. {
  7133. int i;
  7134. int ref_id = 0, window_id;
  7135. ref_id = TtaGetDocumentWindowId (doc, view);
  7136. if (ref_id == 0)
  7137. return;
  7138. for (i = 1; i < MAX_DOCUMENTS; i++)
  7139. {
  7140. if (DocumentURLs[i])
  7141. {
  7142. window_id = TtaGetDocumentWindowId (i, 1);
  7143. if (window_id == ref_id)
  7144. RefreshTab (i, 1);
  7145. }
  7146. }
  7147. }
  7148. /*----------------------------------------------------------------------
  7149. ----------------------------------------------------------------------*/
  7150. void AmayaCloseWindow (Document doc, View view)
  7151. {
  7152. /* Save the current windows geometry */
  7153. SaveGeometryOnExit( doc, NULL);
  7154. // close all dialogs
  7155. TtaFreeAllCatalogs ();
  7156. /* get the document's parent window and try to close it */
  7157. int window_id = TtaGetDocumentWindowId( doc, view );
  7158. TtaCloseWindow( window_id );
  7159. }
  7160. /*----------------------------------------------------------------------
  7161. ----------------------------------------------------------------------*/
  7162. void AmayaClose (Document document, View view)
  7163. {
  7164. // close all dialogs
  7165. TtaFreeAllCatalogs ();
  7166. AmayaWindowIterator it;
  7167. for( it.first(); !it.isDone(); it.next() )
  7168. {
  7169. /* close each window one by one */
  7170. TtaCloseWindow( it.currentWindowId() );
  7171. }
  7172. }
  7173. /*----------------------------------------------------------------------
  7174. AddURLInCombobox adds the new pathname in the combobox list.
  7175. Store that URL into the file only if keep is TRUE.
  7176. URIs are encoded with the default charset.
  7177. ----------------------------------------------------------------------*/
  7178. void AddURLInCombobox (char *pathname, char *form_data, ThotBool keep)
  7179. {
  7180. char *urlstring, *app_home, *old_list, *url;
  7181. int i, j, len, nb, end, max;
  7182. FILE *file = NULL;
  7183. unsigned char *localname;
  7184. CHARSET encoding;
  7185. if (pathname == NULL || pathname[0] == EOS)
  7186. return;
  7187. if (strlen(pathname) > 100)
  7188. // don't register too long paths
  7189. return;
  7190. if (form_data && form_data[0] != EOS)
  7191. {
  7192. url = (char *)TtaGetMemory (strlen (pathname) + strlen (form_data) + 2);
  7193. sprintf (url, "%s?%s", pathname, form_data);
  7194. }
  7195. else
  7196. url = TtaStrdup (pathname);
  7197. urlstring = (char *) TtaGetMemory (MAX_LENGTH);
  7198. /* open the file list_url.dat into APP_HOME directory */
  7199. app_home = TtaGetEnvString ("APP_HOME");
  7200. /* force url encoding to utf8 */
  7201. sprintf (urlstring, "%s%clist_url_utf8.dat", app_home, DIR_SEP);
  7202. encoding = UTF_8;
  7203. /* keep the previous list */
  7204. old_list = URL_list;
  7205. /* create a new list */
  7206. len = strlen (url) + 1;
  7207. i = 0;
  7208. j = len;
  7209. nb = 1;
  7210. URL_list_len = URL_list_len + len + 1;
  7211. URL_list = (char *)TtaGetMemory (URL_list_len);
  7212. if (keep)
  7213. file = TtaWriteOpen (urlstring);
  7214. *urlstring = EOS;
  7215. if (!keep || file)
  7216. {
  7217. /* put the new url */
  7218. if (!strcmp (url, "empty"))
  7219. // empty is a keyword to display an empty document
  7220. keep = FALSE; // never keep an empty file
  7221. strcpy (URL_list, url);
  7222. if (keep)
  7223. {
  7224. if (encoding != UTF_8)
  7225. {
  7226. localname = TtaConvertMbsToByte ((unsigned char *)url, encoding);
  7227. fprintf (file, "\"%s\"\n", localname);
  7228. TtaFreeMemory (localname);
  7229. }
  7230. else
  7231. fprintf (file, "\"%s\"\n", url);
  7232. }
  7233. max = GetMaxURLList();
  7234. if (old_list && old_list[i] != EOS)
  7235. {
  7236. /* now write other urls */
  7237. while (old_list[i] != EOS && nb < max)
  7238. {
  7239. end = strlen (&old_list[i]) + 1;
  7240. if ((URL_list_keep || i != 0) &&
  7241. (end != len || strncmp (url, &old_list[i], len)))
  7242. {
  7243. /* add the newline between two urls */
  7244. strcpy (&URL_list[j], &old_list[i]);
  7245. if (keep)
  7246. {
  7247. if (encoding != UTF_8)
  7248. {
  7249. localname = TtaConvertMbsToByte ((unsigned char *)&old_list[i], encoding);
  7250. fprintf (file, "\"%s\"\n", localname);
  7251. TtaFreeMemory (localname);
  7252. }
  7253. else
  7254. fprintf (file, "\"%s\"\n", &old_list[i]);
  7255. }
  7256. j += end;
  7257. nb++;
  7258. }
  7259. i += end;
  7260. }
  7261. }
  7262. URL_list[j] = EOS;
  7263. URL_list_keep = keep;
  7264. if (keep)
  7265. TtaWriteClose (file);
  7266. }
  7267. TtaFreeMemory (old_list);
  7268. TtaFreeMemory (urlstring);
  7269. TtaFreeMemory (url);
  7270. }
  7271. /*----------------------------------------------------------------------
  7272. InitStringForCombobox
  7273. Initializes the URLs string for combobox
  7274. ----------------------------------------------------------------------*/
  7275. void InitStringForCombobox ()
  7276. {
  7277. unsigned char *urlstring, c;
  7278. char *app_home;
  7279. FILE *file;
  7280. int i, nb, len;
  7281. /* remove the previous list */
  7282. TtaFreeMemory (URL_list);
  7283. URL_list_keep = TRUE;
  7284. urlstring = (unsigned char *) TtaGetMemory (MAX_LENGTH);
  7285. /* open the file list_url.dat into APP_HOME directory */
  7286. app_home = TtaGetEnvString ("APP_HOME");
  7287. /* force url encoding to utf8 */
  7288. sprintf ((char *)urlstring, "%s%clist_url_utf8.dat", app_home, DIR_SEP);
  7289. file = TtaReadOpen ((char *)urlstring);
  7290. *urlstring = EOS;
  7291. if (file)
  7292. {
  7293. /* get the size of the file */
  7294. fseek (file, 0L, 2); /* end of the file */
  7295. URL_list_len = (ftell (file) * 4) + GetMaxURLList() + 4;
  7296. URL_list = (char *)TtaGetMemory (URL_list_len);
  7297. URL_list[0] = EOS;
  7298. fseek (file, 0L, 0); /* beginning of the file */
  7299. /* initialize the list by reading the file */
  7300. i = 0;
  7301. nb = 0;
  7302. while (TtaReadByte (file, &c))
  7303. {
  7304. if (c == '"')
  7305. {
  7306. len = 0;
  7307. urlstring[len] = EOS;
  7308. while (len < MAX_LENGTH && TtaReadByte (file, &c) && c != EOL)
  7309. {
  7310. if (c == '"')
  7311. urlstring[len] = EOS;
  7312. else if (c == 13)
  7313. urlstring[len] = EOS;
  7314. else
  7315. urlstring[len++] = (char)c;
  7316. }
  7317. urlstring[len] = EOS;
  7318. if (i > 0 && len)
  7319. /* add an EOS between two urls */
  7320. URL_list[i++] = EOS;
  7321. if (len)
  7322. {
  7323. nb++;
  7324. strcpy ((char *)&URL_list[i], (char *)urlstring);
  7325. i += len;
  7326. }
  7327. }
  7328. }
  7329. URL_list[i + 1] = EOS;
  7330. TtaReadClose (file);
  7331. }
  7332. TtaFreeMemory (urlstring);
  7333. }
  7334. /*----------------------------------------------------------------------
  7335. InitRDFaListForCombobox
  7336. Initializes the Namespace list for RDFa
  7337. ----------------------------------------------------------------------*/
  7338. void InitRDFaListForCombobox ()
  7339. {
  7340. unsigned char *urlstring, c;
  7341. char *ptr;
  7342. FILE *file;
  7343. int i, nb, len;
  7344. /* remove the previous list */
  7345. TtaFreeMemory (RDFa_list);
  7346. urlstring = (unsigned char *) TtaGetMemory (MAX_LENGTH);
  7347. /* open the file rdfa_list.dat into config directory */
  7348. ptr = TtaGetEnvString ("THOTDIR");
  7349. strcpy ((char *)urlstring, ptr);
  7350. strcat ((char *)urlstring, DIR_STR);
  7351. strcat ((char *)urlstring, "config");
  7352. strcat ((char *)urlstring, DIR_STR);
  7353. strcat ((char *)urlstring, "rdfa_list.dat");
  7354. file = TtaReadOpen ((char *)urlstring);
  7355. *urlstring = EOS;
  7356. if (file)
  7357. {
  7358. /* get the size of the file */
  7359. fseek (file, 0L, 2); /* end of the file */
  7360. RDFa_list_len = (ftell (file) * 4) + GetMaxURLList() + 4;
  7361. RDFa_list = (char *)TtaGetMemory (RDFa_list_len);
  7362. RDFa_list[0] = EOS;
  7363. fseek (file, 0L, 0); /* beginning of the file */
  7364. /* initialize the list by reading the file */
  7365. i = 0;
  7366. nb = 0;
  7367. while (TtaReadByte (file, &c))
  7368. {
  7369. len = 0;
  7370. urlstring[len] = EOS;
  7371. urlstring[len++] = (char)c;
  7372. while (len < MAX_LENGTH && TtaReadByte (file, &c) && c != EOL)
  7373. {
  7374. if (c == 13)
  7375. urlstring[len] = EOS;
  7376. else
  7377. urlstring[len++] = (char)c;
  7378. }
  7379. urlstring[len] = EOS;
  7380. if (i > 0 && len)
  7381. /* add an EOS between two urls */
  7382. RDFa_list[i++] = EOS;
  7383. if (len)
  7384. {
  7385. nb++;
  7386. strcpy ((char *)&RDFa_list[i], (char *)urlstring);
  7387. i += len;
  7388. }
  7389. }
  7390. RDFa_list[i + 1] = EOS;
  7391. TtaReadClose (file);
  7392. }
  7393. TtaFreeMemory (urlstring);
  7394. }
  7395. /*----------------------------------------------------------------------
  7396. RemoveDocFromSaveList remove the file from the AutoSave list
  7397. ----------------------------------------------------------------------*/
  7398. void RemoveDocFromSaveList (char *name, char *initial_url, int doctype)
  7399. {
  7400. char *urlstring, *app_home, *ptr, *list_item;
  7401. char *ptr_end, *ptr_beg;
  7402. int i, j, len, nb, end;
  7403. FILE *file = NULL;
  7404. if (name == NULL || name[0] == EOS)
  7405. return;
  7406. if (initial_url == NULL || initial_url[0] == EOS)
  7407. return;
  7408. /* keep the previous list */
  7409. ptr = AutoSave_list;
  7410. /* create a new list */
  7411. AutoSave_list = (char *)TtaGetMemory (AutoSave_list_len + 1);
  7412. len = strlen (initial_url) + strlen (name) + 1;
  7413. len += 17; /*doctype + quotation marks + spaces */
  7414. list_item = (char *)TtaGetMemory (len);
  7415. sprintf (list_item, "\"%s\" \"%s\" %d", name, initial_url, doctype);
  7416. /* open the file AutoSave.dat into APP_HOME directory */
  7417. app_home = TtaGetEnvString ("APP_HOME");
  7418. urlstring = (char *) TtaGetMemory (MAX_LENGTH);
  7419. sprintf (urlstring, "%s%cAutoSave.dat", app_home, DIR_SEP);
  7420. if (TtaFileExist (urlstring))
  7421. {
  7422. file = TtaWriteOpen (urlstring);
  7423. if (file && AutoSave_list)
  7424. {
  7425. i = 0;
  7426. j = 0;
  7427. nb = 0;
  7428. /* remove the line (write other urls) */
  7429. if (ptr && *ptr != EOS)
  7430. {
  7431. while (ptr[i] != EOS && nb <= MAX_AutoSave_list)
  7432. {
  7433. end = strlen (&ptr[i]) + 1;
  7434. ptr_end = strrchr (&ptr[i], '\"');
  7435. if (ptr_end)
  7436. {
  7437. *ptr_end = EOS;
  7438. ptr_beg = strrchr (&ptr[i], '\"');
  7439. if (ptr_beg)
  7440. {
  7441. ptr_beg++;
  7442. if (strcmp (initial_url, ptr_beg))
  7443. {
  7444. /* keep this entry */
  7445. *ptr_end = '\"';
  7446. strcpy (&AutoSave_list[j], &ptr[i]);
  7447. AutoSave_list_len += end;
  7448. fprintf (file, "%s\n", &ptr[i]);
  7449. j += end;
  7450. nb++;
  7451. }
  7452. }
  7453. *ptr_end = '\"';
  7454. }
  7455. i += end;
  7456. }
  7457. }
  7458. AutoSave_list[j] = EOS;
  7459. TtaWriteClose (file);
  7460. /* remove the backup file */
  7461. if (j == 0 && TtaFileExist (urlstring))
  7462. {
  7463. TtaFileUnlink (urlstring);
  7464. TtaFreeMemory (AutoSave_list);
  7465. AutoSave_list = NULL;
  7466. AutoSave_list_len = 0;
  7467. }
  7468. }
  7469. }
  7470. else
  7471. {
  7472. TtaFreeMemory (AutoSave_list);
  7473. AutoSave_list = NULL;
  7474. AutoSave_list_len = 0;
  7475. }
  7476. TtaFreeMemory (ptr);
  7477. TtaFreeMemory (urlstring);
  7478. TtaFreeMemory (list_item);
  7479. }
  7480. /*----------------------------------------------------------------------
  7481. AddDocInSaveList adds the new URL into the AutoSave list
  7482. ----------------------------------------------------------------------*/
  7483. void AddDocInSaveList (char *name, char *initial_url, int doctype)
  7484. {
  7485. char *urlstring, *app_home, *ptr;
  7486. char *ptr_end, *ptr_beg;
  7487. int i, j, len, nb, end;
  7488. FILE *file = NULL;
  7489. if (AutoSave_Interval == 0)
  7490. return;
  7491. if (name == NULL || name[0] == EOS)
  7492. return;
  7493. if (initial_url == NULL || initial_url[0] == EOS)
  7494. return;
  7495. /* keep the previous list */
  7496. ptr = AutoSave_list;
  7497. /* create a new list */
  7498. len = strlen (initial_url) + strlen (name) + 1;
  7499. len += 7; /*doctype + quotation marks + spaces */
  7500. AutoSave_list = (char *)TtaGetMemory (AutoSave_list_len + len + 1);
  7501. /* open the file AutoSave.dat into APP_HOME directory */
  7502. urlstring = (char *) TtaGetMemory (MAX_LENGTH);
  7503. app_home = TtaGetEnvString ("APP_HOME");
  7504. sprintf (urlstring, "%s%cAutoSave.dat", app_home, DIR_SEP);
  7505. file = TtaWriteOpen (urlstring);
  7506. *urlstring = EOS;
  7507. if (file)
  7508. {
  7509. i = 0;
  7510. j = len;
  7511. nb = 1;
  7512. /* put the new line */
  7513. sprintf (AutoSave_list, "\"%s\" \"%s\" %d", name, initial_url, doctype);
  7514. AutoSave_list_len = len + 1;
  7515. fprintf (file, "%s\n", AutoSave_list);
  7516. if (ptr && *ptr != EOS)
  7517. {
  7518. /* now write other urls */
  7519. while (ptr[i] != EOS && nb < MAX_AutoSave_list)
  7520. {
  7521. end = strlen (&ptr[i]) + 1;
  7522. ptr_end = strrchr (&ptr[i], '\"');
  7523. if (ptr_end)
  7524. {
  7525. *ptr_end = EOS;
  7526. ptr_beg = strrchr (&ptr[i], '\"');
  7527. if (ptr_beg)
  7528. {
  7529. ptr_beg++;
  7530. if ((end != len) || (strcmp (initial_url, ptr_beg)))
  7531. {
  7532. /* copy the url */
  7533. *ptr_end = '\"';
  7534. strcpy (&AutoSave_list[j], &ptr[i]);
  7535. AutoSave_list_len += end;
  7536. fprintf (file, "%s\n", &ptr[i]);
  7537. j += end;
  7538. nb++;
  7539. }
  7540. }
  7541. *ptr_end = '\"';
  7542. }
  7543. i += end;
  7544. }
  7545. }
  7546. AutoSave_list[j] = EOS;
  7547. TtaWriteClose (file);
  7548. }
  7549. TtaFreeMemory (ptr);
  7550. TtaFreeMemory (urlstring);
  7551. }
  7552. /*----------------------------------------------------------------------
  7553. InitAutoSave list
  7554. ----------------------------------------------------------------------*/
  7555. void InitAutoSave ()
  7556. {
  7557. unsigned char *urlstring, c;
  7558. char *app_home;
  7559. FILE *file;
  7560. int i, nb, len;
  7561. /* remove the previous list */
  7562. TtaFreeMemory (AutoSave_list);
  7563. AutoSave_list = NULL;
  7564. AutoSave_list_len = 0;
  7565. urlstring = (unsigned char *) TtaGetMemory (MAX_LENGTH);
  7566. /* open the file AutoSave.dat into APP_HOME directory */
  7567. app_home = TtaGetEnvString ("APP_HOME");
  7568. sprintf ((char *)urlstring, "%s%cAutoSave.dat", app_home, DIR_SEP);
  7569. file = TtaReadOpen ((char *)urlstring);
  7570. *urlstring = EOS;
  7571. if (file)
  7572. {
  7573. /* get the size of the file */
  7574. fseek (file, 0L, 2); /* end of the file */
  7575. AutoSave_list_len = ftell (file) + GetMaxURLList() + 4;
  7576. AutoSave_list = (char *)TtaGetMemory (AutoSave_list_len);
  7577. AutoSave_list[0] = EOS;
  7578. fseek (file, 0L, 0); /* beginning of the file */
  7579. /* initialize the list by reading the file */
  7580. i = 0;
  7581. nb = 0;
  7582. while (TtaReadByte (file, &c))
  7583. {
  7584. if (c == '"')
  7585. {
  7586. len = 0;
  7587. urlstring[len] = EOS;
  7588. while (len < MAX_LENGTH && TtaReadByte (file, &c) && c != EOL)
  7589. {
  7590. if (c == '"')
  7591. urlstring[len] = EOS;
  7592. else if (c == 13)
  7593. urlstring[len] = EOS;
  7594. else
  7595. urlstring[len++] = (char)c;
  7596. }
  7597. urlstring[len] = EOS;
  7598. if (i > 0 && len)
  7599. /* add an EOS between two urls */
  7600. AutoSave_list[i++] = EOS;
  7601. if (len)
  7602. {
  7603. nb++;
  7604. strcpy ((char *)&AutoSave_list[i], (char *)urlstring);
  7605. i += len;
  7606. }
  7607. }
  7608. }
  7609. AutoSave_list[i + 1] = EOS;
  7610. TtaReadClose (file);
  7611. }
  7612. TtaFreeMemory (urlstring);
  7613. }
  7614. /*----------------------------------------------------------------------
  7615. SaveGeometryOnExit
  7616. save the current document geometry only if "Save geometry on exit" is enable
  7617. ----------------------------------------------------------------------*/
  7618. void SaveGeometryOnExit (int document, const char * view_name)
  7619. {
  7620. ThotBool saveGeometry = FALSE;
  7621. TtaGetEnvBoolean ("SAVE_GEOMETRY", &saveGeometry);
  7622. if (saveGeometry)
  7623. /* Save the current windows geometry */
  7624. SetGeometryConf ( document, view_name );
  7625. }
  7626. /*----------------------------------------------------------------------
  7627. LoadDefaultOpeningLocation controls where the new document is displayed
  7628. The parameter noReplace says the replace is not allowed
  7629. ----------------------------------------------------------------------*/
  7630. void LoadDefaultOpeningLocation (ThotBool noReplace)
  7631. {
  7632. int where_id = 1;
  7633. /* get the default location in thotrc */
  7634. TtaGetEnvInt ("NEW_LOCATION", &where_id);
  7635. if (noReplace && where_id == 0)
  7636. where_id++; /* zero based in the config file */
  7637. ThotCallback(BaseDialog + OpenLocation , INTEGER_DATA, (char*)where_id);
  7638. }
  7639. /*----------------------------------------------------------------------
  7640. GetMaxURLList()
  7641. returns the max urls which can be stored
  7642. ----------------------------------------------------------------------*/
  7643. int GetMaxURLList()
  7644. {
  7645. int max;
  7646. TtaSetDefEnvString ("MAX_URL_LIST", "20", FALSE); // by default 20 urls
  7647. TtaGetEnvInt ("MAX_URL_LIST", &max);
  7648. return max;
  7649. }
  7650. /*----------------------------------------------------------------------
  7651. SetMaxURLList()
  7652. set a new limit for : max urls which can be stored
  7653. ----------------------------------------------------------------------*/
  7654. void SetMaxURLList(int max)
  7655. {
  7656. TtaSetEnvInt ("MAX_URL_LIST", max, TRUE);
  7657. }
  7658. /*----------------------------------------------------------------------
  7659. ClearURLList()
  7660. empty the url list
  7661. ----------------------------------------------------------------------*/
  7662. void ClearURLList()
  7663. {
  7664. char * app_home;
  7665. char filename[MAX_LENGTH];
  7666. FILE * file = NULL;
  7667. /* cleanup the urllist variable */
  7668. URL_list[0] = EOS;
  7669. /* cleanup the urllist file */
  7670. app_home = TtaGetEnvString ("APP_HOME");
  7671. /* force url encoding to utf8 */
  7672. sprintf ((char *)filename, "%s%clist_url_utf8.dat", app_home, DIR_SEP);
  7673. file = TtaWriteOpen(filename);
  7674. TtaWriteClose(file);
  7675. /* then cleanup the combobox widget */
  7676. AmayaWindowIterator it;
  7677. for( it.first(); !it.isDone(); it.next() )
  7678. {
  7679. /* empty url list on each windows */
  7680. TtaEmptyURLBar( it.currentWindowId() );
  7681. }
  7682. }
  7683. #include <wx/sstream.h>
  7684. #include <wx/wfstream.h>
  7685. #include <wx/dir.h>
  7686. #include "../thotlib/internals/h/SMTP.h"
  7687. /*----------------------------------------------------------------------
  7688. * Retrieve a valid temporary directory path.
  7689. * Dont create the file, just assumes that it doesnt exist and can be created.
  7690. * The returned value must be deleted.
  7691. * Returns NULL if any problem occurs.
  7692. * Dont use mktemp because doesnt exist on windows
  7693. ----------------------------------------------------------------------*/
  7694. char* CreateTempDirectory (const char* name)
  7695. {
  7696. static int i = 0, len;
  7697. char buff[MAX_LENGTH];
  7698. char temppath[MAX_LENGTH];
  7699. strncpy(temppath, TtaGetEnvString ("APP_TMPDIR"), MAX_LENGTH / 4);
  7700. temppath[MAX_LENGTH / 4] = EOS;
  7701. len = strlen(temppath);
  7702. if (len == 0)
  7703. return NULL;
  7704. if (temppath[len]!=DIR_SEP)
  7705. {
  7706. temppath[len] = DIR_SEP;
  7707. temppath[len+1] = 0;
  7708. }
  7709. while (i < 10000)
  7710. {
  7711. sprintf(buff, "%s%s%04d", temppath, name, i);
  7712. if (!TtaCheckDirectory(buff))
  7713. {
  7714. if(TtaCheckMakeDirectory(buff, TRUE))
  7715. return TtaStrdup(buff);
  7716. }
  7717. i++;
  7718. }
  7719. return NULL;
  7720. }
  7721. /*----------------------------------------------------------------------
  7722. ----------------------------------------------------------------------*/
  7723. int ChooseDocumentPage(Document doc)
  7724. {
  7725. if (DocumentTypes[doc] == docLibrary)
  7726. return WXAMAYAPAGE_SIMPLE;
  7727. else if (IsXMLDocType (doc))
  7728. return WXAMAYAPAGE_SPLITTABLE;
  7729. else
  7730. return WXAMAYAPAGE_SIMPLE;
  7731. }
  7732. /*----------------------------------------------------------------------
  7733. ----------------------------------------------------------------------*/
  7734. void CloseHelpWindow(Document doc, View view)
  7735. {
  7736. TtaCloseAllHelpWindows ();
  7737. }