File: help.c

package info (click to toggle)
mpsql 2.1-2
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 3,528 kB
  • ctags: 4,886
  • sloc: ansic: 35,184; makefile: 3,761; sh: 44
file content (1505 lines) | stat: -rw-r--r-- 46,391 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
/************************************************************************/
/* Module : help.c		         			        */
/* Purpose: help subsystem entry                                 	*/
/* Mod. By: Keith R. Davis				                */
/* Date   : 12/8/95					                */
/* Notes  : Copyright(c) 1996-98 Mutiny Bay Software	                */
/*          Copyright(c) 1995 ipvr stuttgart and thomas harrer          */
/*          modified source to correctly install icon pixmap and added  */
/*          tooltips.                                                   */
/************************************************************************/

/* X11 and Motif includes.  */
#include <X11/Intrinsic.h>
#include <X11/cursorfont.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/Protocols.h>
#include <Xm/PanedW.h>
#include <X11/xpm.h>

#ifdef PRIVATE_DEBUG
#include <X11/IntrinsicP.h>
#include <X11/ShellP.h>
#endif /* PRIVATE_DEBUG  */

/* application definitions  */
#include "HTML.h"

/* help widget definitions  */
#include "help.h"
#include "helpp.h"
#include "actionarea.h"
#include "contexthelp.h"
#include "language.h"
#include "image.h"
#include "load.h"
#include "buffer.h"
#include "util.h"
#include "path.h"
#include "bcache.h"
#include "imageutil.h"
#include "tooltip.h"         

/* -------------------------------------------------------------------- *
**  module and library identification
** -------------------------------------------------------------------- */
#ifdef RCSID
/* module  */
static char rcsid [] =
    "$Id: help.c,v 1.91 1995/06/28 12:59:30 thomas Exp $";
/* library (values will be read from version.h) */
static char system_name [] = "$Release name: " _system_name_ "$";
static char system_version [] = "$Release version: " _system_version_ "$";
static char system_date [] = "$Release date: " _system_date_ "$";
#endif /* RCSID */

/* -------------------------------------------------------------------- *
**  private type:	help_structure_t
** -------------------------------------------------------------------- *
**  help widget structure:
**  
**  toplevel - help_shell - pane
**                      _____|______
**                     |            |
**                   help       actionarea (rowcol)
**                     |            |
**               (help_view)    (subwidgets from module actionarea)
**   (subwidget html widget)
**
** -------------------------------------------------------------------- */
typedef struct help_structure_s  {

    Widget 	help_shell;
    Widget 	pane;
    Widget 	help;
    Widget 	action_area;
    Widget	help_view;
    int 	is_up;		/* create if 0, map if 1. */

} help_structure_t;

/* -------------------------------------------------------------------- *
**  private type:	history_t
** 			history for file-anchor pairs (linked list). 
** -------------------------------------------------------------------- */
typedef struct history_s  {

    char* 	name;		/* filename and anchor.			*/
    char* 	refname;	/* currently the document title.	*/
    int 	element_id;	/* current position in html widget.	*/
    struct 	history_s* next;

} history_t;

/* -------------------------------------------------------------------- *
**  private type:	icon_t
**			type for icon pixmaps.
** -------------------------------------------------------------------- */
typedef struct icon_s {

    Pixmap	icon_pixmap;	/* BadPixmap if there is no pixmap.	*/
    Pixmap	icon_mask;	/* BadPixmap if there is no mask.	*/

} icon_t;

/* -------------------------------------------------------------------- *
**  libhelp resources
**  libhelp resources can be set by the application (the user of the
**  help service) via the function help_set_resource.
**
**  list of resources. add new resources here.
** -------------------------------------------------------------------- */
static resource_t help_resources[] =  {
    {help_class_name, help_string,  (XtPointer) "Libhelp"},
    {help_standalone, help_boolean, (XtPointer) 0}, 
    {help_index,      help_string,  (XtPointer) "index.html"},
    {help_update,     help_string,  (XtPointer) 0},
    /* meeningless in libhelp. provided for libhlpclient.  */
    {help_server,     help_int,     NO_SERVER},	
    {help_end_of_resources, help_boolean, NULL},	
};

/* -------------------------------------------------------------------- *
**  local prototypes
** -------------------------------------------------------------------- */
/* functions for setting help texts.  */
static void 	set_help_text (Widget, char*, int);
static void	set_file_and_anchor (Widget, char*, int);
static void	set_text_check_scroll (Widget, char*, char*, char*,
                                       int, char*, void*);
/* history handling.  */
static void 	add_history (Widget, char*, char*);
static void 	history_add_current_id (Widget);

/* image wrapper.  */
static ImageInfo* resolve_img_wrapper (Widget, char*, int);

/* callbacks  */
static void 	popdown_help (Widget, XtPointer, XtPointer);
static void 	anchor_cb (Widget, XtPointer, XtPointer);
static void 	push_cb (Widget, XtPointer, XtPointer);
static void 	form_cb (Widget, XtPointer, XtPointer);

/* pushbutton actions  */
static void 	go_last (void);
static void 	move_vertical (Widget, XEvent*, const char*);
static void 	compose_history (void);
static void 	compose_index (void);

/* icon  */
static void	add_icon (Widget);

/* state  */
static void 	set_state (int);

/* update  */
static void	help_flush (void);

/* -------------------------------------------------------------------- *
**  action (XtActionProc's)
** -------------------------------------------------------------------- */
/* action prototypes  */
static void help_scroll_up (Widget, XEvent*, String*, Cardinal*);
static void help_scroll_down (Widget, XEvent*, String*, Cardinal*);
static void help_scroll_home (Widget, XEvent*, String*, Cardinal*);
static void help_action_index (Widget, XEvent*, String*, Cardinal*);
static void help_action_history (Widget, XEvent*, String*, Cardinal*);
static void help_action_back (Widget, XEvent*, String*, Cardinal*);
static void help_action_dismiss (Widget, XEvent*, String*, Cardinal*);
static void help_cancel (Widget, XEvent*, String*, Cardinal*);
static void help_about (Widget, XEvent*, String*, Cardinal*);
static void help_reload (Widget, XEvent*, String*, Cardinal*);

/* action record  */
static XtActionsRec help_actions [] = {
{ "help_scroll_down", 	 (XtActionProc) help_scroll_down },
{ "help_scroll_up", 	 (XtActionProc) help_scroll_up   },
{ "help_scroll_home", 	 (XtActionProc) help_scroll_home },
{ "help_action_index",	 (XtActionProc) help_action_index },
{ "help_action_history", (XtActionProc) help_action_history },
{ "help_action_back",	 (XtActionProc) help_action_back },
{ "help_action_dismiss", (XtActionProc) help_action_dismiss },
{ "help_cancel",         (XtActionProc) help_cancel },
{ "help_about",          (XtActionProc) help_about },
{ "help_reload",         (XtActionProc) help_reload },
#ifdef TOOLTIP
{ "PopupTooltip",        (XtActionProc) PopupTooltip   },
{ "PopdownTooltip",      (XtActionProc) PopdownTooltip },
#endif
};

/* -------------------------------------------------------------------- *
**  translations (for the help view).
** -------------------------------------------------------------------- */
static char help_translations[] = 
"a <Key>v:		help_scroll_up()\n"
"m <Key>v:		help_scroll_up()\n"
"<Key>osfUp:		help_scroll_up()\n"
"<Key>osfPageUp:	help_scroll_up()\n"

"c <Key>v:		help_scroll_down()\n"
"<Key>space:		help_scroll_down()\n"
"<Key>osfDown:		help_scroll_down()\n" 
"<Key>osfPageDown:	help_scroll_down()\n"
"<Key>osfBeginLine:	help_scroll_home()\n"
"<Key>osfBeginData:	help_scroll_home()\n"

"<Key>h:		help_action_history()\n"
"<Key>i:		help_action_index()\n"
"<Key>b:		help_action_back()\n"
"<Key>q:		help_action_dismiss()\n"
"<Key>osfCancel:	help_cancel()\n"

/* undocumented features.  */
"c a <Key>?:		help_about()\n"
"c m <Key>?:		help_about()\n"
"c a <Key>r:		help_reload()\n"
"c m <Key>r:		help_reload()\n"
"c <Key>l:		help_reload()\n"
;

#ifdef TOOLTIP
static char tooltip_trans[] =
"<EnterWindow>:PopupTooltip()\n"
"<LeaveWindow>:PopdownTooltip()\n"
;
#endif

/* -------------------------------------------------------------------- *
**  global data 
** -------------------------------------------------------------------- */
/* Widget structure for help. */
static help_structure_t* 	hs = NULL;  

/* counter to distinguish pages.*/
static unsigned long 		this_html_no = 0;

/* the history list anchor */
static history_t* 		history = NULL;     

/*
 *  history flags: %%% ugly, we should write a history module %%% 
 *  0 means document has history, 1 means no history.  
 */
/* currrent_type: this information for the currently displayed document  */
static int			current_type = 0;
/* this information for the new document that is to be displayd.  */
static int			next_type = 0;

/* libhelp browser has it's own icon.  */
#ifdef COLOR_PIXMAPS
#include <../pixmaps/help/color/libhelp_icon.xpm>
#else
#include <../pixmaps/help/bw/libhelp_icon.xpm>
#endif
/* -------------------------------------------------------------------- *
** ------------- public procs -----------------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	help_set_resource
**
**  purpose:		sets a internal resource for the help
**			subsystem. Xt resources cannot be used because
**			we hide the implementation of the help
**			system from the application. the application 
**			has no anchor to identify the help system as
**			a shell or a widget or something else.
** -------------------------------------------------------------------- *
**  args:		resource symbol (declared in help.h) and
**			a value (of type XtPointer)
**  precondition:	- 
**  postcondition:	resource value is set if symbol was valid
**			else ignored
** -------------------------------------------------------------------- */
void
help_set_resource (/* i  */ int 	symbol,
 		   /* i  */ XtPointer	value)
{
    int i = 0;
    
    execute ("help_set_resource");
    
    while (help_resources[i].resource != help_end_of_resources) {
	if (help_resources[i].resource == symbol) {
	    help_resources[i].value = (XtPointer) value;
	}
	i++;
    }
}

/* -------------------------------------------------------------------- *
**  procedure-name:	get_help
**
**  purpose:		provides entry to the help facility.
**			
**			the help system can run as a standalone or as 
**			a child of an application. In the latter case 
**			it creates it's own toplevel shell (and only 
**			pops it down if dismiss is pressed) else it
**			creates it's widget structure in the parents
**			shell.
**			
**			the creation of shells and the internal states
**			of the help system are hided from the application.
**			
** -------------------------------------------------------------------- *
**  args:		XtCallbackProc args:
**			Widget parent (toplevel).
**			XtPointer call_data: (char*)help file and anchor.
**			XtPointer client_data: unused.
**  precondition:	toolkit must be initialized. parent must be created.
**  postcondition:	help window is created or raised.
** -------------------------------------------------------------------- */
void
get_help (/* i  */ Widget	parent,
	  /* i  */ XtPointer	call_data,
	  /* -  */ XtPointer	client_data)
{
    Atom 	del_atom;	/* Atom to catch delete */
    char* 	class_name;	/* application class. */
    int 	is_shell = 1;
    int         i;
    
    /* buttons in the action area.  */
    static action_t actions[] = {
        { action_dismiss, (XtCallbackProc) push_cb },
        { action_index,   (XtCallbackProc) push_cb },
        { action_history, (XtCallbackProc) push_cb },
        { action_back, 	  (XtCallbackProc) push_cb },
        { action_up, 	  (XtCallbackProc) push_cb },
        { action_down, 	  (XtCallbackProc) push_cb },
    };

    execute ("get_help");

    /*
     *  the global variable hs is a pointer to the widget structure.
     *  it is initialized to NULL at module initialization.
     *  if it is NULL we need to create it and the whole help window.
     *  if not, we just need to raise the window and display the
     *  requested help text.
     */
    if (hs) {

	if (help_resources[help_update].value) {
	    help_flush ();
	}

	/* if it is already up: display the desired help text.  */
	set_help_text (hs->help, (char*) call_data, 0);

	XMapRaised (XtDisplay (hs->help_shell), XtWindow (hs->help_shell));
	if (hs->is_up == 0) {
	    XtPopup (hs->help_shell, XtGrabNone);
	    hs->is_up = 1;
	}
	return;
    }

    /*
     *  if the client initializes libhelp with NULL Widget we complain.
     */
    if (!parent) {
	fprintf (stderr, 
		 "get_help needs a valid parent Widget "
		 "(at the 1st call)\n");
	exit (EXIT_FAILURE);
    }
    
    /* initialize the help system  */
    checked_malloc (hs, 1, help_structure_t); /* never freed ! */
    class_name = (char*) help_resources [help_class_name].value;

    /* create a shell if we not use the existing (in a standalone help).  */
    if ((int) help_resources [help_standalone].value == 1) {
	
	hs->help_shell = parent; /* toplevel */
	is_shell = 0;
	
    } else {

	hs->help_shell = XtVaAppCreateShell 
	    ("help", class_name, 
	     topLevelShellWidgetClass, XtDisplay (parent), 
	     XmNdeleteResponse,        XmDO_NOTHING,
	     XmNiconic, 	       (XtArgVal) False,
	     XmNtitle,                 "MPSQL - Help",
	     NULL);
    }

#ifdef TOOLTIP
    InitializeTooltip (XtDisplay(hs->help_shell),"help");
#endif

    add_icon (hs->help_shell);
    editres_support (hs->help_shell);

    hs->pane = XtVaCreateWidget 
	("pane", xmPanedWindowWidgetClass, hs->help_shell,
	 XmNsashWidth,  1,
	 XmNsashHeight, 1,
	 NULL);  
    context_help (hs->pane, cx_browser);

     /*
     *  create the action buttons. set the sensitive states for the
     *  buttons with respect to the available data and the state at
     *  startup (back is insensitive, index too if there is no index
     *  specified).
     */
    /* begin   */ {
	int pane_size = 68;
	/*Widget form = XtVaCreateManagedWidget
	    ("form", xmFormWidgetClass, hs->pane, 
	     XmNpaneMaximum, pane_size,
	     XmNpaneMinimum, pane_size, NULL);*/

	Widget form = XtVaCreateManagedWidget
	    ("form", xmFormWidgetClass, hs->pane, NULL);

	hs->action_area = 
	    create_actionarea (form, actions, XtNumber (actions));

    }
    
    /* create the HTML widget.  */
    hs->help = XtVaCreateManagedWidget 
	("help_text", htmlWidgetClass, hs->pane,
	 WbNresolveImageFunction, 	(long) resolve_img_wrapper,
	 XmNresizePolicy,    		XmRESIZE_ANY,
	 XmNresizable,       		True,
	 XmNshadowThickness, 		2,
	 XmNtopOffset, 	 		5,
	 XmNbottomOffset, 		5, 
	 XmNleftOffset, 		5, 
	 XmNrightOffset, 		5,
	 NULL);
    context_help (hs->help, cx_browser);
    
    /*
     *  add translations to the help view. we want keyboard actions 
     *  for scrolling up and down.
     */

    /* actions and translations are set in their own block */ {
	XtAppContext app_context;
	
	app_context = XtWidgetToApplicationContext (hs->help_shell);
	
	XtAppAddActions (app_context, help_actions, 
			 XtNumber (help_actions));

	XtVaGetValues (hs->help, 
		       WbNview,	(long)(&hs->help_view),
		       NULL);

	context_help (hs->help_view, cx_browser);
	
	XtOverrideTranslations (hs->help_view, 
				XtParseTranslationTable (help_translations));

#ifdef TOOLTIP
	for(i=0; i<number_of_actions; i++) {
	  XtOverrideTranslations(actionrec[i].w, XtParseTranslationTable (tooltip_trans));
	}
#endif
    }
    /* begin  */ {
	Widget vsb; 
	Widget hsb;
	
	XtVaGetValues (hs->help, 
		       XmNverticalScrollBar, (XtPointer) (&vsb), 
		       XmNhorizontalScrollBar, (XtPointer) (&hsb), 
		       NULL);

	if (vsb) context_help (vsb, cx_browser);
	if (hsb) context_help (hsb, cx_browser);
    }
 
    if ((char*) help_resources[help_index].value == NULL) {
	actions_set_sensitive (action_index, False);
    }

    if (!history) {
	actions_set_sensitive (action_back, False);
    } else if (!history->next) {
	actions_set_sensitive (action_back, False);
    }

    actions_set_sensitive (action_history, False);
    actions_set_sensitive (action_up, False);
    actions_set_sensitive (action_down, False);

    /* Register HTML Anchor callback.  */
    XtAddCallback (hs->help, WbNanchorCallback, 
		   (XtCallbackProc) anchor_cb, (XtPointer) 0);
    /* Register  the forms callback.   */
    XtAddCallback (hs->help, WbNsubmitFormCallback,
		   (XtCallbackProc) form_cb, (XtPointer) 0);

    set_help_text (hs->help, (char*) call_data, 0);

    XtManageChild (hs->pane);
    /* prevent it from deleting.  */

    if (is_shell == 1) {
	XtPopup (hs->help_shell, XtGrabNone);
	hs->is_up = 1;

	del_atom = XmInternAtom (XtDisplay(parent), "WM_DELETE_WINDOW", False);
	XmAddWMProtocolCallback (hs->help_shell, del_atom,
				 (XtCallbackProc) popdown_help, 
				 (XtPointer)hs->help_shell);
    }
    
    return;
}

/* -------------------------------------------------------------------- *
** ------------- icon procs -------------------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	add_icon
**
**  purpose:		creates the icon pixmap and stores it into the 
**			shell's resource list
** -------------------------------------------------------------------- */
static void
add_icon (/* i  */ Widget shell)
{
    static icon_t* 	icon = NULL;
    Window 		window;

    execute ("add_icon");
    
    XtVaGetValues (shell, XmNiconWindow, (XtArgVal) &window, NULL);

    if (!window) {
      SetupIcon(shell, libhelp_icon_xpm);
    }
}

/* -------------------------------------------------------------------- *
** ------------- html handling procs ----------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	set_help_text
**
**  purpose:		sets the help text and adds the history entry.
** -------------------------------------------------------------------- */
static void
set_help_text (/* i  */ Widget 	w,
	       /* i  */ char* 	ref,
	       /* i  */ int 	element_id)
{    
    char*	title_text;	/* for history text line.  */

    execute ("set_help_text");

    /* explicitly state that this page has a history.  */
    next_type = 0;
    
    /* first we display the reference.  */
    set_file_and_anchor (w, ref, element_id);

    /* we need the title of the html document for history lines */ 
    XtVaGetValues (hs->help, WbNtitleText, (long) &title_text, NULL);

    if (!title_text) {
	title_text = str_no_title;
    }

    /* then we add the reference together with the title to the history. */
    /* begin  */ {
	char* current = bcache_current ();
	if (current) {
	    add_history (w, current, title_text);
	    checked_free (current); /* allocated by load.c  */
	}
    }
}

/* -------------------------------------------------------------------- *
**  procedure-name:	set_file_and_anchor
**
**  purpose:		sets the help text without adding history.
**			either load the html file or uses it if it is 
**			already in the global buffer.
** -------------------------------------------------------------------- */
static void
set_file_and_anchor (/* i  */ Widget 	w,
		     /* i  */ char* 	ref,
		     /* i  */ int 	element_id)
{    
    /* local data.  */
    buffer_t*	buf = NULL;

    execute ("set_file_and_anchor");

    /* loading takes real time. so we change to watch cursor.  */
    set_state (1);

    /* we read in the text (or a warning). buf is valid after this call. */
    buf = read_html_file (ref);

    /* now we display the document.  */
    this_html_no++;
    set_text_check_scroll (w, bf_the_buffer (buf), "\0", "\0", 
			   element_id, get_anchor (ref), NULL);
}

/* -------------------------------------------------------------------- *
**  procedure-name:	set_text_check_scroll
**
**  purpose:		wrapper for HTMLSetText that
**			checks the scrollbars and set cursor icons.
** -------------------------------------------------------------------- */
static void
set_text_check_scroll (/* i  */ Widget 	w, 
		       /* i  */ char*	text, 
		       /* i  */ char*	header_text,
		       /* i  */ char*	footer_text, 
		       /* i  */ int 	element_id,
		       /* i  */ char*	target_anchor, 
		       /* i  */ void*	ptr)
{
    execute ("set_text_check_scroll");

    /*
     *  while work is in progress we change our cursor-icon to a 
     *  watch on the help shells window.
     */
    set_state (1);
    
    /*
     *  we need to remember the current position in the document for 
     *  restoring it on history requests. %%% ugly %%%
     */
    if (current_type == 0) history_add_current_id (w);
    current_type = next_type;
    
    /* now we call the html widget interface function.  */
    HTMLSetText (w, text, header_text, footer_text, element_id, 
		 target_anchor, ptr);


    /* begin  */ {

	Widget scroll_bar;
	/*
	 *  the initial state for up and down buttons is insensitive.
	 *  so as long as there is no scrollbar, the buttons remain in
	 *  this state. if there are scrollbars, we change the state
	 *  to sensitive, if the vertical scrollbar is managed.
	 */

	XtVaGetValues (hs->help, XmNverticalScrollBar, 
		       (XtPointer) (&scroll_bar), NULL);

	if (scroll_bar) {
	    if (XtIsManaged (scroll_bar) == True) {
		actions_set_sensitive (action_up,   True);
		actions_set_sensitive (action_down, True);
	    } else {
		actions_set_sensitive (action_up,   False);
		actions_set_sensitive (action_down, False);
	    }
	}
    }
    set_state (0);
}

/* -------------------------------------------------------------------- *
** ------------- callbacks ----------------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	popdown_help
**
**  purpose:		pops down help window
** -------------------------------------------------------------------- */
static void
popdown_help (/* i  */ Widget w,
	      /* -  */ XtPointer call_data,     /* ignored  */
	      /* -  */ XtPointer client_data)   /* ignored  */
{
    execute ("popdown_help");

    /* we leave the application here if we run standalone.  */
    if ((int)help_resources[help_standalone].value == 1) {
	exit (0);
    }

    /* else we just popdown help's toplevel shell.  */
    if (hs) {
	XtPopdown (hs->help_shell);
	hs->is_up = 0; 
    }
    return;
}

/* -------------------------------------------------------------------- *
**  procedure-name:	push_cb
**
**  purpose:		called when button is pressed.
**			depends on the actionarea module.
**			we call the action for the specified button type.
** -------------------------------------------------------------------- */
static void
push_cb (/* i  */ Widget w,
	 /* i  */ XtPointer client_data, /* int: number  */
	 /* i  */ XtPointer call_data)   /* needed for event  */
{
    int action = (int) client_data;
    XmPushButtonCallbackStruct* cbs = 
	(XmPushButtonCallbackStruct*) call_data;

    execute ("push_cb");
    
    set_state (1);

    switch (action) {
      case action_history:
	compose_history ();
	break;
      case action_dismiss:
	popdown_help (w, NULL, NULL);
	break;
      case action_back:	
	go_last ();
	break;
      case action_down:
	move_vertical (w, cbs->event, "PageDownOrRight");
	break;
      case action_up:
	move_vertical (w, cbs->event, "PageUpOrLeft");
	break;
      case action_index: 
	compose_index ();
	break;
      default:
	break;
    }
    set_state (0);

    return;
}

/* -------------------------------------------------------------------- *
**  procedure-name:	anchor_cb
**
**  purpose:		Callback for pressing anchors
** -------------------------------------------------------------------- *
**  args:		Widget w:     HTML widget that calls the callback.
**			client_data:  
**			call_data:    
**  precondition:	callback must be registert to HTML widget.
**  postcondition:	Anchor is followed up and redisplayed.
**  error handling.:	returns.
** -------------------------------------------------------------------- */
static void
anchor_cb (/* i  */ Widget 	w,
	   /* -- */ XtPointer 	client_data,    /* ignored  */
	   /* i  */ XtPointer 	call_data)      /* HTML data  */
{
    char* 		  ref = NULL;
    WbAnchorCallbackData* data = (WbAnchorCallbackData*) call_data;

    execute ("anchor_cb");
    
    if (data->href) {
	checked_strdup (ref, data->href);
    } else {
	checked_strdup (ref, "Unlinked");
    } /* scope ref -> local  */
    
    /*
     *  anchors from the history list have a special format:
     *  they begin with "__hist" followed by the number of the accessed
     *  history entry (reflects the position in the history list).
     */
    if (0 == c_strncmp (ref, "__hist", 6)) {

	history_t* h = history;
	long nr = strtol ((ref + 6), NULL, 0);
	long i = 0;

	hist_trace (("history ref: %s, nr = %d\n", ref, nr));

	while (h) {
	    if (i == nr) break;
	    i++;
	    h = h->next;
	}
	if (!h) {
	    fputs ("inconsistency in anchor_cb\n", stderr);
	    exit (EXIT_FAILURE);
	}
	set_help_text (hs->help, h->name, h->element_id);
	
    } else {
	set_help_text (hs->help, ref, 0);
    }
    
    checked_free (ref);
    return;
}

/* -------------------------------------------------------------------- *
**  procedure-name:	form_cb
**
**  purpose:		called if form is returned from html.
**			yet there is no real implementation for forms.
** -------------------------------------------------------------------- */
static void
form_cb (/* i  */ Widget w,
	 /* i  */ XtPointer call_data,
	 /* i  */ XtPointer client_data)
{
    WbFormCallbackData *cd = (WbFormCallbackData *) client_data;
    buffer_t*	buf = bf_new (); /* scope -> local */
    
    execute ("form_cb");
    
    bf_strcpy (buf, 
	       "<title>libhelp internal form support</title>\n"
	       "<h1>" str_libhelp_icon " Fill out forms</h1>\n"
	       "Forms are not implemented in <b>libhelp</b>. We provide"
	       " this internal page for testing forms. <p>");

    if (!cd) {
	bf_strcat (buf, "Form with no data\n");
    } else  {
	int c;
	
	bf_strcat (buf, "<pre>\n");
	if (cd->href) bf_sprint (buf, "href: %s\n", cd->href);
	if (cd->method) bf_sprint (buf, "method: %s\n", cd->method);
	if (cd->enctype) bf_sprint (buf, "enctype: %s\n", cd->enctype);
	if (cd->enc_entity) bf_sprint (buf, "enc_entity: %s\n", 
					cd->enc_entity);
	for (c = 0; c < cd->attribute_count; c++) {
	    bf_sprint (buf, "name: %s", cd->attribute_names[c]);
	    bf_sprint (buf, "value: %s\n", cd->attribute_values[c]);
	}
	bf_strcat (buf, "</pre>\n");
    }

    /* we flag, that this page has no history entry.  */
    next_type = 1;

    /* bring the page to display.  */
    set_text_check_scroll (hs->help, bf_the_buffer (buf), 
			   "\0", "\0", 0, NULL, NULL);	
    bf_free (buf);

    /* we must make it able to go back!  */
    actions_set_sensitive (action_back, True);

}

/* -------------------------------------------------------------------- *
**  -------------image wrapper ----------------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	resolve_img_wrapper
**
**  purpose:		calls image_resolve with the correct help path
** -------------------------------------------------------------------- */
static ImageInfo*
resolve_img_wrapper (/* i  */ Widget 	w,
		     /* i  */ char*	src,
		     /* i  */ int	no_load)
{
    execute ("resolve_img_wrapper");
    return image_resolve (hs->help, src, this_html_no);
}

/* -------------------------------------------------------------------- *
** ------------- history handling----------------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	add_history
**
**  purpose:		adds a file+anchor pair to the history.
** -------------------------------------------------------------------- */
static void
add_history (/* i  */ Widget 	w,
	     /* i  */ char* 	file_and_anchor,
	     /* i  */ char*	title)
{
    /* to save the name of the current file:  */
    static char* current_file = NULL;
    
    char* 	filename = get_file (file_and_anchor); /* scope: local! */
    char* 	anchor = get_anchor (file_and_anchor); /* just ptr. */
    char* 	title_ref = NULL;
    char* 	address = NULL;
    history_t* 	tmp_hist = NULL;
    int   	len;

    execute ("add_history");

    if (*filename == '\0') {
	checked_free (filename);
	filename = current_file;
    } else  {
	if (current_file) checked_free (current_file);
	current_file = filename;
    } /* filename is now treated as a pointer to current_file. */

    if (anchor && (*anchor != '\0')) {
	/* address is used to compose <file>#<anchor>  */
	len = c_strlen (filename) + c_strlen (anchor) + 2;
	checked_malloc (address, len, char);
	c_strcpy (address, filename);
	c_strcat (address, "#");
	c_strcat (address, anchor);
    } else {
	checked_strdup (address, filename); 
    } /* address scope -> go_last  */

    checked_malloc (tmp_hist, 1, history_t); /* scope -> go_back ! */

    if (title) {
	checked_strdup (title_ref, title);
    } else {
	checked_strdup (title_ref, str_no_title);
    } /* title_ref scope -> go_last.  */
    
    tmp_hist->name = address;
    tmp_hist->refname = title_ref;
    tmp_hist->element_id = 0;
    tmp_hist->next = history;

    history = tmp_hist;
    
    if (history->next) {
	actions_set_sensitive (action_back, True);
    }
    actions_set_sensitive (action_history, True);
}

/* -------------------------------------------------------------------- *
**  procedure-name:	history_add_current_id
**
**  purpose:		adds the current id to the history
** -------------------------------------------------------------------- */
static void
history_add_current_id (/* i  */ Widget w)
{
    int element_id = HTMLPositionToId (w, 0, 0);
    
    execute ("history_add_current_id");
	
    if (history) {
	history->element_id = element_id;
    }
    return;
}

/* -------------------------------------------------------------------- *
** ------------- display and motion -------------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	compose_history
**
**  purpose:		displays the history.
**			we translate the history of visited help anchors
**			into a html document and display it like others.
**			the only difference is, that it does not get a
**			history entry for itself.
** -------------------------------------------------------------------- */
static void 
compose_history (void)
{
    /* initial size for buffer allocation. can grow. */

    history_t* 	h = history;	   /* a pointer to the history.         */
    int 	counter = 0;	   /* unique for each history entry.    */

    execute ("compose_history");
    
   /* the history text has no history entry for itself.  */
    next_type = 1;

    /* if we have no history, we do nothing (rather unlikely).  */
    if (h) {

	static buffer_t* buf = NULL;

	if (!buf) {
	    buf = bf_new ();
	}
	
	/* we first write a header (starting an unnumbered list).  */
	bf_strcpy (buf, 
		   "<title>" str_history "</title>\n"
		   "<h1>" str_history 
		   "</h1>\n");
        
	/*
	 *  add a list entry for each history entry. uses the <li> tag.
	 *  the reference (<href=>) is artificial. it contains the string
	 *  __hist<nr>. the anchor_cb must understand this special reference
	 *  as a history reference.
	 */
	while (h) {

	    char* ptr;

	    /* search the anchor  */
	    ptr = h->name;
	    while (*ptr != '\0') {
		if (*ptr == '#') { ptr++; break; }
		ptr++;
	    }
	
	    /* add the anchor as history text.  */
	    bf_strcat (buf, str_icon_index "<a href=\"");
	    bf_dprint (buf, "__hist%d__\">", counter); counter++;
	    
	    if (*ptr == '\0') {
		/* if we have no anchor we use the document title */
		bf_strcat (buf, h->refname);
	    } else {
		char* new_string = NULL;
		char* ptr2;
		
		checked_strdup (new_string, ptr); /* scope -> local  */
	    
		/* replace '_' with ' '. the app. can use '_' or ' '.  */
		ptr2 = new_string;
		while (*ptr2 != '\0') {
		    if (*ptr2 == '_') *ptr2 = ' ';
		    ptr2++;
		}
		bf_strcat (buf, new_string);
		checked_free (new_string);
	    }

	    bf_strcat (buf, "</a><br>");

	    /* we go on with the next entry  */
	    h = h->next;
	}

	/* ok, we add the current version number and date.  */
	/*bf_strcat (buf, "\n<p>" str_libhelp_bar 
		   "\n<address>libhelp " 
		   _system_version_ " (" _system_date_ ")\n");*/

	
	/* display the new composed history.  */
	set_text_check_scroll (hs->help, bf_the_buffer (buf), 
			       "\0", "\0", 0, NULL, NULL);

	/* allow the user to get back with buttons.  */
	actions_set_sensitive (action_back, True);
    
	/* we do not free buf cause we use it in all calls.  */
    }
}
	
/* -------------------------------------------------------------------- *
**  procedure-name:	compose_index
**
**  purpose:		composes the index.
**			sets the sensitivity of back button.
** -------------------------------------------------------------------- */
static void
compose_index (void)
{
    execute ("compose_index");
    
    if (help_resources[help_index].value) {

	char* string = NULL;
	checked_strdup (string, (char*) help_resources[help_index].value);
	/* scope -> local  */

	if (history) {
	    /* we check history because there could be */
	    /* an error (no valid history) in the first request. */
	    actions_set_sensitive (action_back, True);
	}
	
	next_type = 1;		/* %%% ugly %%% */
	set_file_and_anchor (hs->help, string, 0);
	checked_free (string);
    }
}

/* -------------------------------------------------------------------- *
**  procedure-name:	go_last
**
**  purpose:		goes down one history step. 
**
**  implementation:	uses global history linked list.
** -------------------------------------------------------------------- */
static void
go_last (void)
{
    history_t* tmp_hist;

    execute ("go_last");
    
    if (history) {
    
	/*
	 *  the history has no own history entry. we just go back to the 
	 *  top of history. if the current link is no history, we 
	 *  really go back one item.
	 */
	if (current_type == 1) {

	    tmp_hist = history;

	} else {

	    tmp_hist = history->next;
	    if (!tmp_hist) return;

	    if (history->name) checked_free (history->name);
	    if (history->refname) checked_free (history->refname);
	    checked_free (history);
	    history = NULL;
	}

	hist_trace (("name: %s, id: %d\n", 
		     tmp_hist->name, tmp_hist->element_id));
    
	next_type = 0;
	set_file_and_anchor (hs->help, tmp_hist->name, tmp_hist->element_id);

	history = tmp_hist;

	/* reset the sensitivity state of the buttons.  */
	if (!history) {
	    actions_set_sensitive (action_back, False);
	} else if (!history->next) {
	    actions_set_sensitive (action_back, False);
	}
    }
    return;
}

/* -------------------------------------------------------------------- *
**  procedure-name:	set_state
**
**  purpose:		changes the cursor icon
** -------------------------------------------------------------------- *
**  args:		busy_state: 0 = not busy, 1 = busy.
**  precondition:	help_shell must be set up and managed.
**  return type:	private void
** -------------------------------------------------------------------- */
static void
set_state (/* i  */int	busy_state)
{
#define BUSY_CURSOR XC_watch

    /* permanent data  */
    static int 		is_initialized = 0;
    static int 		is_busy = 0;
    static Cursor 	cursor;

    execute ("set_state");
    
    if (hs) {

	Widget 	shell = hs->help_shell;

	if ((shell) && XtIsRealized (shell)) {

	    Display* 	display = XtDisplay (shell);
	    Window 	window = XtWindow (shell);

	    /* we create the busy cursor once.  */
	    if (is_initialized == 0) {
		cursor = XCreateFontCursor (display, BUSY_CURSOR);
		is_busy = 0;
		is_initialized = 1;
	    }

	    /* and set the cursor according to busy_state argument.  */
	    if (busy_state != is_busy) {

		is_busy = busy_state;
		if (is_busy) {
		    XDefineCursor (display, window, cursor);
		} else {
		    XUndefineCursor (display, window);
		}
		XFlush (display);
	    }
	}
    }
}

/* -------------------------------------------------------------------- *
**  procedure-name:	move_vertical
**
**  purpose:		goes one page up or down.
**
**  implementation:	uses the XmScrollBar actions (command arg).
**			possible actions are:
**			* PageUpOrLeft
**			* PageDownOrRight
**			* TopOrBottom
** -------------------------------------------------------------------- */
static void
move_vertical (/* i  */ Widget w,
	       /* i  */ XEvent* event,
	       /* i  */ const char* command)
{
    Widget sb;
    String params[1];
      
    execute ("move_vertical");
    
    params[0] = "0";

    XtVaGetValues (hs->help, XmNverticalScrollBar, (long)(&sb), NULL);
    if ((sb) && (XtIsManaged (sb) == True)) {
	XtCallActionProc (sb, command, event, params, 1);
    }
} 

/* -------------------------------------------------------------------- *
** ------------- XtActionProcs ----------------------------------------
** -------------------------------------------------------------------- */
/* -------------------------------------------------------------------- *
**  procedure-name:	help_scroll_up
**
**  purpose:		scrolling action (wrapper for move_vertical)
** -------------------------------------------------------------------- */
static void
help_scroll_up (/* i  */ Widget 	w,
		/* i  */ XEvent* 	event,
		/* i  */ String*	string,
		/* i  */ Cardinal*	c)
{
    execute ("help_scroll_up");
    move_vertical (w, event, "PageUpOrLeft");
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_scroll_down
**
**  purpose:		action wrapper for move_vertical
** -------------------------------------------------------------------- */
static void
help_scroll_down (/* i  */ Widget 	w,
		  /* i  */ XEvent* 	event,
		  /* i  */ String*	string,
		  /* i  */ Cardinal*	c)
{
    execute ("help_scroll_down");
    move_vertical (w, event, "PageDownOrRight");
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_scroll_home
**
**  purpose:		action wrapper for move_vertical
** -------------------------------------------------------------------- */
static void
help_scroll_home (/* i  */ Widget 	w,
		  /* i  */ XEvent* 	event,
		  /* i  */ String*	string,
		  /* i  */ Cardinal*	c)
{
    execute ("help_scroll_home");
    move_vertical (w, event, "TopOrBottom");
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_action_index
**
**  purpose:		action wrapper for compose_index
** -------------------------------------------------------------------- */
static void
help_action_index (/* i  */ Widget 	w,
		  /* i  */ XEvent* 	event,
		  /* i  */ String*	string,
		  /* i  */ Cardinal*	c)
{
    execute ("help_action_index");
    compose_index();
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_action_history
**
**  purpose:		action wrapper compose_history
** -------------------------------------------------------------------- */
static void
help_action_history (/* i  */ Widget 	w,
		     /* i  */ XEvent* 	event,
		     /* i  */ String*	string,
		     /* i  */ Cardinal*	c)
{
    execute ("help_action_history");
    compose_history ();
}
/* -------------------------------------------------------------------- *
**  procedure-name:	help_action_back
**
**  purpose:		action wrapper for go last
** -------------------------------------------------------------------- */
static void
help_action_back (/* i  */ Widget 	w,
		  /* i  */ XEvent* 	event,
		  /* i  */ String*	string,
		  /* i  */ Cardinal*	c)
{
    execute ("help_action_back");
    go_last ();
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_action_dismiss
**
**  purpose:		action wrapper for popdown help
** -------------------------------------------------------------------- */
static void
help_action_dismiss (/* i  */ Widget 	w,
		     /* i  */ XEvent* 	event,
		     /* i  */ String*	string,
		     /* i  */ Cardinal*	c)
{
    execute ("help_action_dismiss");
    popdown_help (w, NULL, NULL);
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_cancel
**
**  purpose:		action wrapper for popdown help
** -------------------------------------------------------------------- */
static void
help_cancel (/* i  */ Widget 	w,
	     /* i  */ XEvent* 	event,
	     /* i  */ String*	string,
	     /* i  */ Cardinal*	c)
{
    execute ("help_action_cancel");

    if ((int) help_resources [help_standalone].value != 1) {
	popdown_help (w, NULL, NULL);
    }
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_about
**
**  purpose:		print internal identification
** -------------------------------------------------------------------- */
static void
help_about (/* i  */ Widget 	w,
	    /* i  */ XEvent* 	event,
	    /* i  */ String*	string,
	    /* i  */ Cardinal*	c)
{
    buffer_t*	buf = bf_new (); /* scope -> local */
    char** 	help_path = path_the_helppath (); /* just ptr. */
    char* 	current = bcache_current (); /* scope -> local */
    
    execute ("help_about");
    
    bf_strcpy (buf, 
	       "<title>libhelp internal about</title>\n"
	       "<h1>" str_libhelp_icon " Information</h1>\n"
	       "\n<h3>release identification</h3><blockquote>"
	       "<Release name: " _system_name_
	       "<br>Release version: " _system_version_
	       "<br>Release date: " _system_date_ "</blockquote>");

    /* current document:  */
    if (current) {
	bf_strcat (buf, "<h3>current document</h3>");
	bf_sprint (buf, "<code>%s</code>", current);
	checked_free (current);
    }

    /* libhelp memory: only if mallocdebug is linked.  */

#ifdef MD_MALLOC
    /* begin  */ {
	int overhead = md_overhead ();
	int mem_usage = md_memory_usage () + overhead;
	bf_strcat (buf, "<h3>overall allocation:</h3><blockquote>");
	bf_dprint (buf, "number of allocations: %d", md_number_of_allocs ());
	bf_dprint (buf, "<br>used memory: %d k", (mem_usage / 1024));
	bf_dprint (buf, "<br>debug overhead: %d k\n", (overhead / 1024));
	bf_strcat (buf, "</blockquote>");
    }
#endif     /* MD_MALLOC  */

    /* we add information about buffer usage.  */
    bf_strcat (buf, "<h3>text buffer usage:</h3><blockquote>");
    bf_dprint (buf, "buffers: %d", bf_buffer_usage ());
    bf_dprint (buf, "<br>page size: %d k", bf_page_size () / 1024);
    bf_dprint (buf, "<br>buffer memory: %d k", bf_memory_usage () / 1024);
    bf_dprint (buf, "<br>used memory: %d k", bf_memory_filled () / 1024); 
    bf_strcat (buf, "</blockquote>");

    /* we add information about the image cache.  */
    bf_strcat (buf, "<h3>image cache:</h3><blockquote>");
    bf_dprint (buf, "default slots: %d", the_cache_default_size ());
    bf_dprint (buf, "<br>used slots: %d", the_cache_size ());
    bf_dprint (buf, "<br>memory: %d k", the_cache_mem () / 1024);
    bf_dprint (buf, "<br>colors per image: %d", the_colors ());
    bf_strcat (buf, "</blockquote>");

    if (help_path) {
	int i = 0;
	bf_strcat (buf, "<h3>help path:</h3><blockquote><pre>\n");
	while (help_path[i]) 
	    bf_sprint (buf, "%s\n", help_path[i++]);
	bf_strcat (buf, "</pre></blockquote>\n");
    }	
    

    bf_strcat (buf, "<p>" str_libhelp_bar "\n");

    /* we flag, that this page has no history entry.  */
    next_type = 1;

    /* bring the page to display.  */
    set_text_check_scroll (hs->help, bf_the_buffer (buf), 
			   "\0", "\0", 0, NULL, NULL);
    bf_free (buf);

    /* we must make it able to go back!  */
    actions_set_sensitive (action_back, True);

}
/* -------------------------------------------------------------------- *
**  procedure-name:	help_flush
**
**  purpose:		flushes all buffers.
** -------------------------------------------------------------------- */
static void
help_flush (void)
{
    char* text = NULL;
    checked_strdup (text, "<!-- empty comment -->"); /* scope: local */
    next_type = 1;
    set_text_check_scroll (hs->help, text, "\0", "\0", 0, NULL, NULL);
    checked_free (text);

    /*
     *  the HTML widget is now prepared to reload our text. now it's
     *  save to flush the imagecache and the buffercache. note: this
     *  only affects cached documents. other buffers (e.g. the history
     *  buffer) are not freed.
     */
    bcache_flush ();
    icache_flush ();
}

/* -------------------------------------------------------------------- *
**  procedure-name:	help_reload
**
**  purpose:		flushes all buffers and images and reloads the
** 			current document.
** -------------------------------------------------------------------- */
static void
help_reload (/* i  */ Widget 	w,
	     /* i  */ XEvent* 	event,
	     /* i  */ String*	string,
	     /* i  */ Cardinal*	c)
{
    /* the filename of the current html document.  */
    char* ref = bcache_current (); /* scope: local */

    /* the position in the current html document.  */
    int id = HTMLPositionToId (hs->help, 0, 0);

    execute ("help_reload");

    /*
     *  the HTML widget wants to free the pixmaps before setting the
     *  reloaded text. but it cant, after we flushed the image cache.
     *  so we must give it a change to free the pixmaps before
     *  we free our caches. we do this with an empty text.
     */

    if (ref) {
	help_flush ();
	/*
	 *  we've saved the old current document's ref and id.
	 *  we can redisplay it right now.
	 */
	next_type = 1;
	set_file_and_anchor (hs->help, ref, id);
	current_type = 0;
	checked_free (ref);
    } 
}