2 Hypertext file browser.
4 Copyright (C) 1994, 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
5 2005, 2006, 2007, 2011, 2013
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 * \brief Source: hypertext file browser
28 * Implements the hypertext file viewer.
29 * The hypertext file is a file that may have one or more nodes. Each
30 * node ends with a ^D character and starts with a bracket, then the
31 * name of the node and then a closing bracket. Right after the closing
32 * bracket a newline is placed. This newline is not to be displayed by
33 * the help viewer and must be skipped - its sole purpose is to faciliate
34 * the work of the people managing the help file template (xnc.hlp) .
36 * Links in the hypertext file are specified like this: the text that
37 * will be highlighted should have a leading ^A, then it comes the
38 * text, then a ^B indicating that highlighting is done, then the name
39 * of the node you want to link to and then a ^C.
41 * The file must contain a ^D at the beginning and at the end of the
42 * file or the program will not be able to detect the end of file.
44 * Lazyness/widgeting attack: This file does use the dialog manager
45 * and uses mainly the dialog to achieve the help work. there is only
46 * one specialized widget and it's only used to forward the mouse messages
47 * to the appropriate routine.
55 #include <sys/types.h>
58 #include "lib/global.h"
60 #include "lib/tty/tty.h"
61 #include "lib/tty/mouse.h"
63 #include "lib/strutil.h"
64 #include "lib/fileloc.h"
66 #include "lib/widget.h"
67 #include "lib/event-types.h"
69 #include "keybind-defaults.h"
72 /*** global variables ****************************************************************************/
74 /*** file scope macro definitions ****************************************************************/
76 #define MAXLINKNAME 80
77 #define HISTORY_SIZE 20
78 #define HELP_WINDOW_WIDTH min(80, COLS - 16)
80 #define STRING_LINK_START "\01"
81 #define STRING_LINK_POINTER "\02"
82 #define STRING_LINK_END "\03"
83 #define STRING_NODE_END "\04"
85 /*** file scope type declarations ****************************************************************/
87 /* Link areas for the mouse */
88 typedef struct Link_Area
91 const char *link_name
;
94 /*** file scope variables ************************************************************************/
96 static char *fdata
= NULL
; /* Pointer to the loaded data file */
97 static int help_lines
; /* Lines in help viewer */
98 static int history_ptr
; /* For the history queue */
99 static const char *main_node
; /* The main node */
100 static const char *last_shown
= NULL
; /* Last byte shown in a screen */
101 static gboolean end_of_node
= FALSE
; /* Flag: the last character of the node shown? */
102 static const char *currentpoint
;
103 static const char *selected_item
;
105 /* The widget variables */
106 static WDialog
*whelp
;
110 const char *page
; /* Pointer to the selected page */
111 const char *link
; /* Pointer to the selected link */
112 } history
[HISTORY_SIZE
];
114 static GSList
*link_area
= NULL
;
115 static gboolean inside_link_area
= FALSE
;
117 static cb_ret_t
help_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
);
119 /*** file scope functions ************************************************************************/
120 /* --------------------------------------------------------------------------------------------- */
122 /** returns the position where text was found in the start buffer
126 search_string (const char *start
, const char *text
)
128 const char *result
= NULL
;
129 char *local_text
= g_strdup (text
);
130 char *d
= local_text
;
131 const char *e
= start
;
133 /* fmt sometimes replaces a space with a newline in the help file */
134 /* Replace the newlines in the link name with spaces to correct the situation */
143 for (d
= local_text
; *e
; e
++)
160 /* --------------------------------------------------------------------------------------------- */
161 /** Searches text in the buffer pointed by start. Search ends
162 * if the CHAR_NODE_END is found in the text.
163 * @return NULL on failure
167 search_string_node (const char *start
, const char *text
)
169 const char *d
= text
;
170 const char *e
= start
;
173 for (; *e
&& *e
!= CHAR_NODE_END
; e
++)
186 /* --------------------------------------------------------------------------------------------- */
187 /** Searches the_char in the buffer pointer by start and searches
188 * it can search forward (direction = 1) or backward (direction = -1)
192 search_char_node (const char *start
, char the_char
, int direction
)
196 for (e
= start
; (*e
!= '\0') && (*e
!= CHAR_NODE_END
); e
+= direction
)
203 /* --------------------------------------------------------------------------------------------- */
204 /** Returns the new current pointer when moved lines lines */
207 move_forward2 (const char *c
, int lines
)
213 for (line
= 0, p
= currentpoint
; (*p
!= '\0') && (*p
!= CHAR_NODE_END
); str_cnext_char (&p
))
216 return currentpoint
= p
;
221 return currentpoint
= c
;
224 /* --------------------------------------------------------------------------------------------- */
227 move_backward2 (const char *c
, int lines
)
233 for (line
= 0, p
= currentpoint
; (*p
!= '\0') && ((int) (p
- fdata
) >= 0); str_cprev_char (&p
))
235 if (*p
== CHAR_NODE_END
)
237 /* We reached the beginning of the node */
238 /* Skip the node headers */
241 return currentpoint
= p
+ 2; /* Skip the newline following the start of the node */
244 if (*(p
- 1) == '\n')
247 return currentpoint
= p
;
249 return currentpoint
= c
;
252 /* --------------------------------------------------------------------------------------------- */
258 currentpoint
= move_forward2 (currentpoint
, i
);
261 /* --------------------------------------------------------------------------------------------- */
264 move_backward (int i
)
266 currentpoint
= move_backward2 (currentpoint
, ++i
);
269 /* --------------------------------------------------------------------------------------------- */
274 while (((int) (currentpoint
> fdata
) > 0) && (*currentpoint
!= CHAR_NODE_END
))
277 while (*currentpoint
!= ']')
279 currentpoint
= currentpoint
+ 2; /* Skip the newline following the start of the node */
280 selected_item
= NULL
;
283 /* --------------------------------------------------------------------------------------------- */
286 move_to_bottom (void)
288 while ((*currentpoint
!= '\0') && (*currentpoint
!= CHAR_NODE_END
))
294 /* --------------------------------------------------------------------------------------------- */
297 help_follow_link (const char *start
, const char *lc_selected_item
)
301 if (lc_selected_item
== NULL
)
304 for (p
= lc_selected_item
; *p
&& *p
!= CHAR_NODE_END
&& *p
!= CHAR_LINK_POINTER
; p
++)
306 if (*p
== CHAR_LINK_POINTER
)
309 char link_name
[MAXLINKNAME
];
312 for (i
= 1; *p
!= CHAR_LINK_END
&& *p
&& *p
!= CHAR_NODE_END
&& i
< MAXLINKNAME
- 3;)
313 link_name
[i
++] = *++p
;
314 link_name
[i
- 1] = ']';
316 p
= search_string (fdata
, link_name
);
319 p
+= 1; /* Skip the newline following the start of the node */
324 /* Create a replacement page with the error message */
325 return _("Help file format error\n");
328 /* --------------------------------------------------------------------------------------------- */
331 select_next_link (const char *current_link
)
335 if (current_link
== NULL
)
338 p
= search_string_node (current_link
, STRING_LINK_END
);
341 p
= search_string_node (p
, STRING_LINK_START
);
347 /* --------------------------------------------------------------------------------------------- */
350 select_prev_link (const char *current_link
)
352 return current_link
== NULL
? NULL
: search_char_node (current_link
- 1, CHAR_LINK_START
, -1);
355 /* --------------------------------------------------------------------------------------------- */
358 start_link_area (int x
, int y
, const char *link_name
)
362 if (inside_link_area
)
363 message (D_NORMAL
, _("Warning"), _("Internal bug: Double start of link area"));
365 /* Allocate memory for a new link area */
366 la
= g_new (Link_Area
, 1);
367 /* Save the beginning coordinates of the link area */
370 /* Save the name of the destination anchor */
371 la
->link_name
= link_name
;
372 link_area
= g_slist_prepend (link_area
, la
);
374 inside_link_area
= TRUE
;
377 /* --------------------------------------------------------------------------------------------- */
380 end_link_area (int x
, int y
)
382 if (inside_link_area
)
384 Link_Area
*la
= (Link_Area
*) link_area
->data
;
385 /* Save the end coordinates of the link area */
388 inside_link_area
= FALSE
;
392 /* --------------------------------------------------------------------------------------------- */
395 clear_link_areas (void)
397 g_slist_foreach (link_area
, (GFunc
) g_free
, NULL
);
398 g_slist_free (link_area
);
400 inside_link_area
= FALSE
;
403 /* --------------------------------------------------------------------------------------------- */
406 help_print_word (WDialog
* h
, GString
* word
, int *col
, int *line
, gboolean add_space
)
408 if (*line
>= help_lines
)
409 g_string_set_size (word
, 0);
414 w
= str_term_width1 (word
->str
);
415 if (*col
+ w
>= HELP_WINDOW_WIDTH
)
421 if (*line
>= help_lines
)
422 g_string_set_size (word
, 0);
425 widget_move (h
, *line
+ 2, *col
+ 2);
426 tty_print_string (word
->str
);
427 g_string_set_size (word
, 0);
434 if (*col
< HELP_WINDOW_WIDTH
- 1)
436 tty_print_char (' ');
447 /* --------------------------------------------------------------------------------------------- */
450 help_show (WDialog
* h
, const char *paint_start
)
454 gboolean painting
= TRUE
;
455 gboolean acs
; /* Flag: Alternate character set active? */
456 gboolean repeat_paint
;
457 int active_col
, active_line
; /* Active link position */
458 char buff
[MB_LEN_MAX
+ 1];
461 word
= g_string_sized_new (32);
463 tty_setcolor (HELP_NORMAL_COLOR
);
466 line
= col
= active_col
= active_line
= 0;
467 repeat_paint
= FALSE
;
471 if ((int) (selected_item
- paint_start
) < 0)
472 selected_item
= NULL
;
476 while ((n
[0] != '\0') && (n
[0] != CHAR_NODE_END
) && (line
< help_lines
))
479 n
= str_cget_next_char (p
);
480 memcpy (buff
, p
, n
- p
);
483 c
= (unsigned char) buff
[0];
486 case CHAR_LINK_START
:
487 if (selected_item
== NULL
)
489 if (p
!= selected_item
)
490 tty_setcolor (HELP_LINK_COLOR
);
493 tty_setcolor (HELP_SLINK_COLOR
);
495 /* Store the coordinates of the link */
496 active_col
= col
+ 2;
497 active_line
= line
+ 2;
499 start_link_area (col
, line
, p
);
501 case CHAR_LINK_POINTER
:
506 help_print_word (h
, word
, &col
, &line
, FALSE
);
507 end_link_area (col
- 1, line
);
508 tty_setcolor (HELP_NORMAL_COLOR
);
517 widget_move (h
, line
+ 2, col
+ 2);
518 tty_print_string (VERSION
);
519 col
+= str_term_width1 (VERSION
);
522 tty_setcolor (HELP_BOLD_COLOR
);
524 case CHAR_FONT_ITALIC
:
525 tty_setcolor (HELP_ITALIC_COLOR
);
527 case CHAR_FONT_NORMAL
:
528 help_print_word (h
, word
, &col
, &line
, FALSE
);
529 tty_setcolor (HELP_NORMAL_COLOR
);
533 help_print_word (h
, word
, &col
, &line
, FALSE
);
538 col
= (col
/ 8 + 1) * 8;
539 if (col
>= HELP_WINDOW_WIDTH
)
548 help_print_word (h
, word
, &col
, &line
, TRUE
);
551 if (painting
&& (line
< help_lines
))
554 /* accumulate symbols in a word */
555 g_string_append (word
, buff
);
556 else if (col
< HELP_WINDOW_WIDTH
)
558 widget_move (h
, line
+ 2, col
+ 2);
560 if ((c
== ' ') || (c
== '.'))
564 tty_print_char (acs_map
[c
]);
566 SLsmg_draw_object (WIDGET (h
)->y
+ line
+ 2, WIDGET (h
)->x
+ col
+ 2,
575 /* print last word */
576 if (n
[0] == CHAR_NODE_END
)
577 help_print_word (h
, word
, &col
, &line
, FALSE
);
580 end_of_node
= line
< help_lines
;
581 tty_setcolor (HELP_NORMAL_COLOR
);
582 if ((int) (selected_item
- last_shown
) >= 0)
584 if ((link_area
== NULL
) || (link_area
->data
== NULL
))
585 selected_item
= NULL
;
588 selected_item
= ((Link_Area
*) link_area
->data
)->link_name
;
593 while (repeat_paint
);
595 g_string_free (word
, TRUE
);
597 /* Position the cursor over a nice link */
599 widget_move (h
, active_line
, active_col
);
602 /* --------------------------------------------------------------------------------------------- */
605 help_event (Gpm_Event
* event
, void *vp
)
607 Widget
*w
= WIDGET (vp
);
608 GSList
*current_area
;
611 if (!mouse_global_in_widget (event
, w
))
612 return MOU_UNHANDLED
;
614 if ((event
->type
& GPM_UP
) == 0)
617 local
= mouse_get_local (event
, w
);
619 /* The event is relative to the dialog window, adjust it: */
623 if ((local
.buttons
& GPM_B_RIGHT
) != 0)
625 currentpoint
= history
[history_ptr
].page
;
626 selected_item
= history
[history_ptr
].link
;
629 history_ptr
= HISTORY_SIZE
- 1;
631 send_message (w
->owner
, NULL
, MSG_DRAW
, 0, NULL
);
635 /* Test whether the mouse click is inside one of the link areas */
636 for (current_area
= link_area
; current_area
!= NULL
; current_area
= g_slist_next (current_area
))
638 Link_Area
*la
= (Link_Area
*) current_area
->data
;
640 /* Test one line link area */
641 if (local
.y
== la
->y1
&& local
.x
>= la
->x1
&& local
.y
== la
->y2
&& local
.x
<= la
->x2
)
644 /* Test two line link area */
645 if (la
->y1
+ 1 == la
->y2
)
648 if (local
.y
== la
->y1
&& local
.x
>= la
->x1
)
650 /* The second line */
651 if (local
.y
== la
->y2
&& local
.x
<= la
->x2
)
654 /* Mouse will not work with link areas of more than two lines */
657 /* Test whether a link area was found */
658 if (current_area
!= NULL
)
660 Link_Area
*la
= (Link_Area
*) current_area
->data
;
662 /* The click was inside a link area -> follow the link */
663 history_ptr
= (history_ptr
+ 1) % HISTORY_SIZE
;
664 history
[history_ptr
].page
= currentpoint
;
665 history
[history_ptr
].link
= la
->link_name
;
666 currentpoint
= help_follow_link (currentpoint
, la
->link_name
);
667 selected_item
= NULL
;
669 else if (local
.y
< 0)
670 move_backward (help_lines
- 1);
671 else if (local
.y
>= help_lines
)
672 move_forward (help_lines
- 1);
673 else if (local
.y
< help_lines
/ 2)
678 /* Show the new node */
679 send_message (w
->owner
, NULL
, MSG_DRAW
, 0, NULL
);
684 /* --------------------------------------------------------------------------------------------- */
688 help_help (WDialog
* h
)
692 history_ptr
= (history_ptr
+ 1) % HISTORY_SIZE
;
693 history
[history_ptr
].page
= currentpoint
;
694 history
[history_ptr
].link
= selected_item
;
696 p
= search_string (fdata
, "[How to use help]");
699 currentpoint
= p
+ 1; /* Skip the newline following the start of the node */
700 selected_item
= NULL
;
701 send_message (h
, NULL
, MSG_DRAW
, 0, NULL
);
705 /* --------------------------------------------------------------------------------------------- */
708 help_index (WDialog
* h
)
710 const char *new_item
;
712 new_item
= search_string (fdata
, "[Contents]");
714 if (new_item
== NULL
)
715 message (D_ERROR
, MSG_ERROR
, _("Cannot find node %s in help file"), "[Contents]");
718 history_ptr
= (history_ptr
+ 1) % HISTORY_SIZE
;
719 history
[history_ptr
].page
= currentpoint
;
720 history
[history_ptr
].link
= selected_item
;
722 currentpoint
= new_item
+ 1; /* Skip the newline following the start of the node */
723 selected_item
= NULL
;
724 send_message (h
, NULL
, MSG_DRAW
, 0, NULL
);
728 /* --------------------------------------------------------------------------------------------- */
731 help_back (WDialog
* h
)
733 currentpoint
= history
[history_ptr
].page
;
734 selected_item
= history
[history_ptr
].link
;
737 history_ptr
= HISTORY_SIZE
- 1;
739 send_message (h
, NULL
, MSG_DRAW
, 0, NULL
); /* FIXME: unneeded? */
742 /* --------------------------------------------------------------------------------------------- */
745 help_next_link (gboolean move_down
)
747 const char *new_item
;
749 new_item
= select_next_link (selected_item
);
750 if (new_item
!= NULL
)
752 selected_item
= new_item
;
753 if ((int) (selected_item
- last_shown
) >= 0)
758 selected_item
= NULL
;
764 selected_item
= NULL
;
767 /* --------------------------------------------------------------------------------------------- */
770 help_prev_link (gboolean move_up
)
772 const char *new_item
;
774 new_item
= select_prev_link (selected_item
);
775 selected_item
= new_item
;
776 if ((selected_item
== NULL
) || (selected_item
< currentpoint
))
780 else if ((link_area
!= NULL
) && (link_area
->data
!= NULL
))
781 selected_item
= ((Link_Area
*) link_area
->data
)->link_name
;
783 selected_item
= NULL
;
787 /* --------------------------------------------------------------------------------------------- */
790 help_next_node (void)
792 const char *new_item
;
794 new_item
= currentpoint
;
795 while ((*new_item
!= '\0') && (*new_item
!= CHAR_NODE_END
))
798 if (*++new_item
== '[')
799 while (*++new_item
!= '\0')
800 if ((*new_item
== ']') && (*++new_item
!= '\0') && (*++new_item
!= '\0'))
802 currentpoint
= new_item
;
803 selected_item
= NULL
;
808 /* --------------------------------------------------------------------------------------------- */
811 help_prev_node (void)
813 const char *new_item
;
815 new_item
= currentpoint
;
816 while (((int) (new_item
- fdata
) > 1) && (*new_item
!= CHAR_NODE_END
))
819 while (((int) (new_item
- fdata
) > 0) && (*new_item
!= CHAR_NODE_END
))
821 while (*new_item
!= ']')
823 currentpoint
= new_item
+ 2;
824 selected_item
= NULL
;
827 /* --------------------------------------------------------------------------------------------- */
830 help_select_link (void)
833 if (selected_item
== NULL
)
835 #ifdef WE_WANT_TO_GO_BACKWARD_ON_KEY_RIGHT
836 /* Is there any reason why the right key would take us
837 * backward if there are no links selected?, I agree
838 * with Torben than doing nothing in this case is better
840 /* If there are no links, go backward in history */
843 history_ptr
= HISTORY_SIZE
- 1;
845 currentpoint
= history
[history_ptr
].page
;
846 selected_item
= history
[history_ptr
].link
;
851 history_ptr
= (history_ptr
+ 1) % HISTORY_SIZE
;
852 history
[history_ptr
].page
= currentpoint
;
853 history
[history_ptr
].link
= selected_item
;
854 currentpoint
= help_follow_link (currentpoint
, selected_item
);
857 selected_item
= NULL
;
860 /* --------------------------------------------------------------------------------------------- */
863 help_execute_cmd (unsigned long command
)
865 cb_ret_t ret
= MSG_HANDLED
;
879 help_prev_link (TRUE
);
882 help_next_link (TRUE
);
885 move_forward (help_lines
- 1);
888 move_backward (help_lines
- 1);
890 case CK_HalfPageDown
:
891 move_forward (help_lines
/ 2);
894 move_backward (help_lines
/ 2);
906 help_next_link (FALSE
);
909 help_prev_link (FALSE
);
921 ret
= MSG_NOT_HANDLED
;
927 /* --------------------------------------------------------------------------------------------- */
930 help_handle_key (WDialog
* h
, int c
)
932 unsigned long command
;
934 command
= keybind_lookup_keymap_command (help_map
, c
);
935 if ((command
== CK_IgnoreKey
) || (help_execute_cmd (command
) == MSG_NOT_HANDLED
))
936 return MSG_NOT_HANDLED
;
938 send_message (h
, NULL
, MSG_DRAW
, 0, NULL
);
942 /* --------------------------------------------------------------------------------------------- */
945 help_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
947 WDialog
*h
= DIALOG (w
);
955 help_lines
= min (LINES
- 4, max (2 * LINES
/ 3, 18));
956 dlg_set_size (h
, help_lines
+ 4, HELP_WINDOW_WIDTH
+ 4);
957 bb
= find_buttonbar (h
);
958 widget_set_size (WIDGET (bb
), LINES
- 1, 0, 1, COLS
);
963 dlg_default_repaint (h
);
964 help_show (h
, currentpoint
);
968 return help_handle_key (h
, parm
);
973 return help_execute_cmd (parm
);
974 /* message from buttonbar */
975 if (sender
== WIDGET (find_buttonbar (h
)))
978 return send_message (data
, NULL
, MSG_ACTION
, parm
, NULL
);
979 return help_execute_cmd (parm
);
981 return MSG_NOT_HANDLED
;
984 return dlg_default_callback (w
, sender
, msg
, parm
, data
);
988 /* --------------------------------------------------------------------------------------------- */
991 interactive_display_finish (void)
996 /* --------------------------------------------------------------------------------------------- */
997 /** translate help file into terminal encoding */
1000 translate_file (char *filedata
)
1003 GString
*translated_data
;
1005 /* initial allocation for largest whole help file */
1006 translated_data
= g_string_sized_new (32 * 1024);
1008 conv
= str_crt_conv_from ("UTF-8");
1010 if (conv
== INVALID_CONV
)
1011 g_string_free (translated_data
, TRUE
);
1016 if (str_convert (conv
, filedata
, translated_data
) != ESTR_FAILURE
)
1017 fdata
= g_string_free (translated_data
, FALSE
);
1021 g_string_free (translated_data
, TRUE
);
1023 str_close_conv (conv
);
1027 /* --------------------------------------------------------------------------------------------- */
1030 md_callback (Widget
* w
, Widget
* sender
, widget_msg_t msg
, int parm
, void *data
)
1035 w
->lines
= help_lines
;
1039 return widget_default_callback (w
, sender
, msg
, parm
, data
);
1043 /* --------------------------------------------------------------------------------------------- */
1046 mousedispatch_new (int y
, int x
, int yl
, int xl
)
1050 w
= g_new (Widget
, 1);
1051 widget_init (w
, y
, x
, yl
, xl
, md_callback
, help_event
);
1055 /* --------------------------------------------------------------------------------------------- */
1056 /*** public functions ****************************************************************************/
1057 /* --------------------------------------------------------------------------------------------- */
1059 /* event callback */
1061 help_interactive_display (const gchar
* event_group_name
, const gchar
* event_name
,
1062 gpointer init_data
, gpointer data
)
1064 const dlg_colors_t help_colors
= {
1065 HELP_NORMAL_COLOR
, /* common text color */
1066 0, /* unused in help */
1067 HELP_BOLD_COLOR
, /* bold text color */
1068 0, /* unused in help */
1069 HELP_TITLE_COLOR
/* title color */
1072 WButtonBar
*help_bar
;
1074 char *hlpfile
= NULL
;
1076 ev_help_t
*event_data
= (ev_help_t
*) data
;
1078 (void) event_group_name
;
1082 if (event_data
->filename
!= NULL
)
1083 g_file_get_contents (event_data
->filename
, &filedata
, NULL
, NULL
);
1085 filedata
= load_mc_home_file (mc_global
.share_data_dir
, MC_HELP
, &hlpfile
);
1087 if (filedata
== NULL
)
1088 message (D_ERROR
, MSG_ERROR
, _("Cannot open file %s\n%s"),
1089 event_data
->filename
? event_data
->filename
: hlpfile
, unix_error_string (errno
));
1093 if (filedata
== NULL
)
1096 translate_file (filedata
);
1103 if ((event_data
->node
== NULL
) || (*event_data
->node
== '\0'))
1104 event_data
->node
= "[main]";
1106 main_node
= search_string (fdata
, event_data
->node
);
1108 if (main_node
== NULL
)
1110 message (D_ERROR
, MSG_ERROR
, _("Cannot find node %s in help file"), event_data
->node
);
1112 /* Fallback to [main], return if it also cannot be found */
1113 main_node
= search_string (fdata
, "[main]");
1114 if (main_node
== NULL
)
1116 interactive_display_finish ();
1121 help_lines
= min (LINES
- 4, max (2 * LINES
/ 3, 18));
1124 dlg_create (TRUE
, 0, 0, help_lines
+ 4, HELP_WINDOW_WIDTH
+ 4,
1125 help_colors
, help_callback
, NULL
, "[Help]", _("Help"),
1126 DLG_TRYUP
| DLG_CENTER
| DLG_WANT_TAB
);
1128 selected_item
= search_string_node (main_node
, STRING_LINK_START
) - 1;
1129 currentpoint
= main_node
+ 1; /* Skip the newline following the start of the node */
1131 for (history_ptr
= HISTORY_SIZE
; history_ptr
;)
1134 history
[history_ptr
].page
= currentpoint
;
1135 history
[history_ptr
].link
= selected_item
;
1138 help_bar
= buttonbar_new (TRUE
);
1139 WIDGET (help_bar
)->y
-= WIDGET (whelp
)->y
;
1140 WIDGET (help_bar
)->x
-= WIDGET (whelp
)->x
;
1142 md
= mousedispatch_new (1, 1, help_lines
, HELP_WINDOW_WIDTH
- 2);
1144 add_widget (whelp
, md
);
1145 add_widget (whelp
, help_bar
);
1147 buttonbar_set_label (help_bar
, 1, Q_ ("ButtonBar|Help"), help_map
, NULL
);
1148 buttonbar_set_label (help_bar
, 2, Q_ ("ButtonBar|Index"), help_map
, NULL
);
1149 buttonbar_set_label (help_bar
, 3, Q_ ("ButtonBar|Prev"), help_map
, NULL
);
1150 buttonbar_set_label (help_bar
, 4, "", help_map
, NULL
);
1151 buttonbar_set_label (help_bar
, 5, "", help_map
, NULL
);
1152 buttonbar_set_label (help_bar
, 6, "", help_map
, NULL
);
1153 buttonbar_set_label (help_bar
, 7, "", help_map
, NULL
);
1154 buttonbar_set_label (help_bar
, 8, "", help_map
, NULL
);
1155 buttonbar_set_label (help_bar
, 9, "", help_map
, NULL
);
1156 buttonbar_set_label (help_bar
, 10, Q_ ("ButtonBar|Quit"), help_map
, NULL
);
1159 interactive_display_finish ();
1160 dlg_destroy (whelp
);
1164 /* --------------------------------------------------------------------------------------------- */