1 static char *rcsid = "$Id: Page.c,v 1.1 1992/05/18 21:43:03 tvr Exp $";
6 void getanddisplaypage(char *topaddress, HText_t * htext,
7 HTextObject_t * htextobject);
8 int matchingstring(char *word);
11 char FindText[256] = "\0";
12 char SearchText[256] = "\0";
14 int SearchCase = FALSE;
17 static int SearchDialogType;
18 static int PageSettingsDialogType;
20 static char *CopyTopAddress;
21 static HText_t *CopyHText;
22 static HTextObject_t *CopyHTextObject;
25 void PageSearchCB(topaddress, htext, htextobject, parameter)
28 HTextObject_t *htextobject;
31 UiDisplaySearchDialog(SearchDialogType);
35 void PageCopyCB(topaddress, htext, htextobject, parameter)
38 HTextObject_t *htextobject;
41 CopyHTextObject = htextobject;
42 CopyTopAddress = strdup(topaddress);
47 void PageListCB(topaddress, htext, htextobject, parameter)
50 HTextObject_t *htextobject;
53 int i = 0, j, stringlength;
54 char **items = (char **) NULL;
55 char **addresses = (char **) NULL;
56 HTextObject_t *tmphtextobject = htext->first;
57 HTAnchor *tmpanchor, *destanchor;
59 while (tmphtextobject)
60 if (tmpanchor = (HTAnchor *) tmphtextobject->anchor) {
61 addresses = (char **) ReAlloc((void *) addresses,
62 ++i * sizeof(char *));
64 HTAnchor_followMainLink((HTAnchor *) tmphtextobject->anchor);
65 addresses[i - 1] = HTAnchor_address(destanchor);
66 items = (char **) ReAlloc((void *) items, i * sizeof(char *));
68 items[i - 1] = (char *) NULL;
69 while (tmphtextobject &&
70 (HTAnchor *) tmphtextobject->anchor == tmpanchor) {
71 stringlength = strlen(tmphtextobject->data);
73 items[i - 1] = (char *) ReAlloc((void *) items[i - 1],
75 strcpy(&items[i - 1][j - stringlength - 1],
76 tmphtextobject->data);
77 items[i - 1][j - 1] = '\0';
78 tmphtextobject = tmphtextobject->next;
81 tmphtextobject = tmphtextobject->next;
83 UiDisplayListDialog(items, addresses, i, StartLoading);
87 void PageLoadToFileCB(topaddress, htext, htextobject, parameter)
90 HTextObject_t *htextobject;
95 if (!htextobject || !htextobject->anchor) {
96 UiDisplayWarningDialog("No active tag", (void (*) (int)) NULL);
99 destanchor = HTAnchor_followMainLink((HTAnchor *) htextobject->anchor);
100 if (ClCanLoadToFile(HTAnchor_address(destanchor)))
101 UiDisplayFileSelection(PageGetPageCB);
103 UiDisplayWarningDialog("Load to file not supported for this tag",
104 (void (*) (int)) NULL);
108 int TruthValue(value)
111 if (value && (!strncasecmp(value, STR_TRUE, strlen(STR_TRUE)) ||
112 !strncasecmp(value, STR_ON, strlen(STR_ON)) ||
113 !strncasecmp(value, STR_YES, strlen(STR_YES))))
119 void PagePrintCB(topaddress, htext, htextobject, parameter)
122 HTextObject_t *htextobject;
125 static void *table = (void *) NULL;
131 table = ConfigGetValue((void *) NULL, C_PRINT);
132 PrintTopMargin = atoi((char *) ConfigGetValue(table, C_TOPMARGIN));
134 atoi((char *) ConfigGetValue(table, C_BOTTOMMARGIN));
135 PrintLeftMargin = atoi((char *) ConfigGetValue(table, C_LEFTMARGIN));
136 PrintWidth = atoi((char *) ConfigGetValue(table, C_WIDTH));
137 if (configstr = (char *) ConfigGetValue(table, C_COMMAND))
138 strcpy(PrintCommand, configstr);
140 strcpy(PrintCommand, "");
141 PrintToFile = TruthValue((char *) ConfigGetValue(table, C_PRINTTOFILE));
142 if (configstr = (char *) ConfigGetValue(table, C_FILENAME))
143 strcpy(PrintFileName, configstr);
145 strcpy(PrintFileName, "");
147 UiDisplayPrintDialog(htext);
150 UiUpdateVariable("PrintTopMargin");
151 UiUpdateVariable("PrintBottomMargin");
152 UiUpdateVariable("PrintLeftMargin");
153 UiUpdateVariable("PrintWidth");
154 UiUpdateVariable("PrintCommand");
155 UiUpdateVariable("PrintToFile");
156 UiUpdateVariable("PrintFileName");
161 void PageSettingsCB(topaddress, htext, htextobject, parameter)
164 HTextObject_t *htextobject;
167 UiDisplayPageSettingsDialog(PageSettingsDialogType);
171 void PageCloseCB(topaddress, htext, htextobject, parameter)
174 HTextObject_t *htextobject;
177 char *address = HTAnchor_address((HTAnchor *) htext->node_anchor);
178 Page_t *toppage, *page;
180 toppage = FindPage(Pages, topaddress);
181 page = FindPage(toppage->Children, address);
183 UiDeletePage(toppage->Address, htext);
184 page->HText = (HText_t *) NULL;
187 page = toppage->Children;
194 HierarchyClose(topaddress, htext, htextobject, parameter);
198 void PagePrevWordCB(topaddress, htext, htextobject, parameter)
201 HTextObject_t *htextobject;
204 HTextObject_t *tmphtextobject;
209 tmphtextobject = htextobject->prev;
211 while (tmphtextobject && !CanBeCursor(tmphtextobject))
212 tmphtextobject = tmphtextobject->prev;
215 UiSetCursor(topaddress, htext, tmphtextobject);
219 void PageNextWordCB(topaddress, htext, htextobject, parameter)
222 HTextObject_t *htextobject;
225 HTextObject_t *tmphtextobject;
230 tmphtextobject = htextobject->next;
232 while (tmphtextobject && !CanBeCursor(tmphtextobject))
233 tmphtextobject = tmphtextobject->next;
236 UiSetCursor(topaddress, htext, tmphtextobject);
240 void PagePrevTagCB(topaddress, htext, htextobject, parameter)
243 HTextObject_t *htextobject;
246 HTextAnchor_t *tmphtanchor;
247 HTAnchor *tmpanchor, *destanchor;
249 HTextObject_t *newhtextobject;
254 tmpanchor = (HTAnchor *) htextobject->anchor;
256 /* Ignore htextobject with same anchor */
257 while (tmpanchor && htextobject &&
258 ((HTAnchor *) htextobject->anchor == tmpanchor))
259 htextobject = htextobject->prev;
261 /* Search for previous anchor */
262 while (htextobject && !htextobject->anchor)
263 htextobject = htextobject->prev;
265 /* No anchor found */
269 /* We want the first word in the tag to be highlighted */
270 while (htextobject->prev &&
271 (htextobject->anchor == htextobject->prev->anchor))
272 htextobject = htextobject->prev;
274 UiSetCursor(topaddress, htext, htextobject);
276 if ((int) parameter == NO_AUTOGET)
279 getanddisplaypage(topaddress, htext, htextobject);
283 void PageNextTagCB(topaddress, htext, htextobject, parameter)
286 HTextObject_t *htextobject;
290 HTextObject_t *newhtextobject;
295 tmpanchor = (HTAnchor *) htextobject->anchor;
297 /* Ignore htextobject with same anchor */
298 while (tmpanchor && htextobject &&
299 ((HTAnchor *) htextobject->anchor == tmpanchor))
300 htextobject = htextobject->next;
302 /* Search for previous anchor */
303 while (htextobject && !htextobject->anchor)
304 htextobject = htextobject->next;
306 /* No anchor found */
310 UiSetCursor(topaddress, htext, htextobject);
312 if ((int) parameter == NO_AUTOGET)
315 getanddisplaypage(topaddress, htext, htextobject);
319 void PageHomeCB(topaddress, htext, htextobject, parameter)
322 HTextObject_t *htextobject;
325 StartLoading(topaddress, topaddress, (char *) NULL);
329 void PageRecallCB(topaddress, htext, htextobject, parameter)
332 HTextObject_t *htextobject;
335 Page_t *toppage, *page;
337 char **items = (char **) NULL;
339 toppage = FindPage(Pages, topaddress);
340 page = toppage->Children;
343 items = (char **) ReAlloc((void *) items, ++i * sizeof(char *));
344 items[i - 1] = strdup(page->Address);
348 UiDisplayRecallDialog(items, i, StartLoading);
352 void PageBackCB(topaddress, htext, htextobject, parameter)
355 HTextObject_t *htextobject;
358 char *address = HTAnchor_address((HTAnchor *) htext->node_anchor);
359 Page_t *toppage, *parentpage, *page;
361 toppage = FindPage(Pages, topaddress);
362 page = FindPage(toppage->Children, address);
364 if (parentpage = page->Parents) {
365 if (parentpage->Next)
366 PageGeneratePopup(parentpage, topaddress);
368 while (parentpage->Next)
369 parentpage = parentpage->Next;
370 StartLoading(parentpage->Address, topaddress, parentpage->Address);
376 PageGeneratePopup(parentpage, topaddress)
380 char **items = (char **) NULL;
384 items = (char **) ReAlloc((void *) items, ++nitems * sizeof(char *));
385 items[nitems - 1] = parentpage->Address;
386 parentpage = parentpage->Next;
389 UiDisplayPopup(StartLoading, topaddress, items, nitems);
394 FindHTextObject(htext, address)
398 HTextObject_t *newhtextobject;
399 HTAnchor *destanchor;
401 newhtextobject = htext->first;
402 while (newhtextobject) {
403 if (newhtextobject->anchor) {
405 HTAnchor_followMainLink((HTAnchor *) newhtextobject->anchor);
406 if (destanchor && !strcmp(HTAnchor_address(destanchor), address))
407 return newhtextobject;
409 newhtextobject = newhtextobject->next;
412 return (HTextObject_t *) NULL;
416 void PagePrevPageCB(topaddress, htext, htextobject, parameter)
419 HTextObject_t *htextobject;
422 char *address = HTAnchor_address((HTAnchor *) htext->node_anchor);
423 Page_t *toppage, *parentpage, *page;
424 HTextObject_t *newhtextobject;
426 toppage = FindPage(Pages, topaddress);
427 page = FindPage(toppage->Children, address);
429 if (parentpage = page->Parents) {
430 if (parentpage->Next)
431 PageGeneratePopup(parentpage, topaddress);
432 while (parentpage->Next)
433 parentpage = parentpage->Next;
434 parentpage = parentpage->ParentPage;
435 if (parentpage->HText) {
436 newhtextobject = FindHTextObject(parentpage->HText, page->Address);
438 PagePrevTagCB(topaddress, parentpage->HText,
439 newhtextobject, (void *) AUTOGET);
441 StartLoading(parentpage->Address, topaddress, (char *) NULL);
446 void PageNextPageCB(topaddress, htext, htextobject, parameter)
449 HTextObject_t *htextobject;
452 char *address = HTAnchor_address((HTAnchor *) htext->node_anchor);
453 Page_t *toppage, *parentpage, *page;
454 HTextObject_t *newhtextobject;
456 toppage = FindPage(Pages, topaddress);
457 page = FindPage(toppage->Children, address);
459 if (parentpage = page->Parents) {
460 if (parentpage->Next)
461 PageGeneratePopup(parentpage, topaddress);
462 while (parentpage->Next)
463 parentpage = parentpage->Next;
464 parentpage = parentpage->ParentPage;
465 if (parentpage->HText) {
466 newhtextobject = FindHTextObject(parentpage->HText, page->Address);
468 PageNextTagCB(topaddress, parentpage->HText,
469 newhtextobject, (void *) AUTOGET);
471 StartLoading(parentpage->Address, topaddress, (char *) NULL);
476 void PageGetPageCB(topaddress, htext, htextobject, parameter)
479 HTextObject_t *htextobject;
482 if (!htextobject || !htextobject->anchor)
486 ClSetFileNameForLoadingToFile((char *) parameter);
488 getanddisplaypage(topaddress, htext, htextobject);
492 void PageClickCB(topaddress, htext, htextobject, parameter)
495 HTextObject_t *htextobject;
498 HTextObject_t *tmphtextobject = htext->first;
501 if (CopyHTextObject && !strcmp(topaddress, CopyTopAddress)
502 && htext == CopyHText)
503 while (tmphtextobject) {
504 if (tmphtextobject == CopyHTextObject ||
505 tmphtextobject == htextobject)
506 state += 1 + (CopyHTextObject == htextobject);
509 if (tmphtextobject->data)
510 UiAddStringToCutBuffer(tmphtextobject->data);
512 UiAddStringToCutBuffer("\n");
513 UiAddStringToCutBuffer((char *) NULL);
514 tmphtextobject = (HTextObject_t *) NULL;
515 Free(CopyTopAddress);
518 if (tmphtextobject->data)
519 UiAddStringToCutBuffer(tmphtextobject->data);
521 UiAddStringToCutBuffer("\n");
524 tmphtextobject = tmphtextobject->next;
528 CopyHTextObject = (HTextObject_t *) NULL;
532 void IndexFindCB(topaddress, htext, htextobject, parameter)
535 HTextObject_t *htextobject;
543 HTMainAnchor = htext->node_anchor; /* Kludguality */
544 newaddress = (char *) HTSearchAddress(FindText); /* missa proto, meeTu? */
546 StartLoading(newaddress, topaddress,
547 HTAnchor_address((HTAnchor *) htext->node_anchor));
552 static char *hiertopaddress;
553 static HText_t *hierhtext;
554 static HTextObject_t *hierhtextobject;
555 static void *hierparameter;
557 void HierarchyCloseCB(topaddress, htext, htextobject, parameter)
560 HTextObject_t *htextobject;
563 hiertopaddress = topaddress;
565 hierhtextobject = htextobject;
566 hierparameter = parameter;
568 UiDisplayWarningDialog("Close hierarchy?", HierarchyNukeCB);
572 void HierarchyNukeCB(button)
575 HierarchyClose(hiertopaddress, hierhtext, hierhtextobject, hierparameter);
579 void HierarchyClose(topaddress, htext, htextobject, parameter)
582 HTextObject_t *htextobject;
587 toppage = FindPage(Pages, topaddress);
589 while (toppage->Children) {
590 if (toppage->Children->HText) {
591 HText_free(toppage->Children->HText);
592 UiDeletePage(toppage->Address, toppage->Children->HText);
594 while (toppage->Children->Parents)
595 DeletePage(&toppage->Children->Parents,
596 toppage->Children->Parents->Address);
597 DeletePage(&toppage->Children, toppage->Children->Address);
600 DeletePage(&Pages, toppage->Address);
604 void SearchBackwardCB(topaddress, htext, htextobject, parameter)
607 HTextObject_t *htextobject;
610 HTextObject_t *newhtextobject;
615 newhtextobject = htextobject->prev;
616 while (newhtextobject && !matchingstring(newhtextobject->data))
617 newhtextobject = newhtextobject->prev;
620 UiSetCursor(topaddress, htext, newhtextobject);
624 void SearchForwardCB(topaddress, htext, htextobject, parameter)
627 HTextObject_t *htextobject;
630 HTextObject_t *newhtextobject;
635 newhtextobject = htextobject->next;
636 while (newhtextobject && !matchingstring(newhtextobject->data))
637 newhtextobject = newhtextobject->next;
640 UiSetCursor(topaddress, htext, newhtextobject);
644 void ConnectionsCB(topaddress, htext, htextobject, parameter)
647 HTextObject_t *htextobject;
650 Connection_t *tmpconnection = Connections;
651 char **listitems = (char **) NULL;
652 void **connections = (void **) NULL;
655 while (tmpconnection) {
656 listitems = (char **) ReAlloc((void *) listitems,
657 ++nitems * sizeof(char *));
658 listitems[nitems - 1] = tmpconnection->Address;
659 connections = (void **) ReAlloc((void *) connections,
660 nitems * sizeof(void *));
661 connections[nitems - 1] = tmpconnection;
662 tmpconnection = tmpconnection->Next;
665 UiDisplayConnectionsDialog(listitems, connections, nitems, KillCB);
669 void KillCB(connection)
672 Connection_t *tmpconnection = (Connection_t *) connection;
674 switch (tmpconnection->Status) {
676 UiDeleteInputFD(tmpconnection->InputId);
679 UiDeleteTimeOut(tmpconnection->TimeOutId);
682 ClCloseConnection(tmpconnection->ClConnection);
683 DeleteConnection(tmpconnection->Address);
687 void ControlPanelCB(topaddress, htext, htextobject, parameter)
690 HTextObject_t *htextobject;
693 UiDisplayControlPanel();
697 void DefaultsCB(topaddress, htext, htextobject, parameter)
700 HTextObject_t *htextobject;
703 UiDisplayDefaultsDialog();
707 void getanddisplaypage(topaddress, htext, htextobject)
710 HTextObject_t *htextobject;
712 HTAnchor *destanchor;
714 destanchor = HTAnchor_followMainLink((HTAnchor *) htextobject->anchor);
715 HTMainAnchor = (HTParentAnchor *) NULL;
717 StartLoading(HTAnchor_address(destanchor),
719 HTAnchor_address((HTAnchor *) htext->node_anchor));
723 int matchingstring(word)
727 int searchlength = strlen(SearchText);
729 while (tmpptr && strlen(tmpptr) >= searchlength) {
731 if (!strncmp(tmpptr, SearchText, searchlength))
733 } else if (!strncasecmp(tmpptr, SearchText, searchlength))