1
/* Copyright (C) 1998 Chancelier Jean-Philippe */
3
* help.c : The Help browser
5
* George Ferguson, ferguson@cs.rochester.edu, 23 Apr 1993.
9
#include <X11/Intrinsic.h>
10
#include <X11/Shell.h>
11
#include <X11/StringDefs.h>
12
#include <X11/Xaw/Form.h>
13
#include <X11/Xaw/Label.h>
14
#include <X11/Xaw/Viewport.h>
15
#include <X11/Xaw/List.h>
16
#include <X11/Xaw/AsciiText.h>
17
#include <X11/Xaw/Command.h>
18
#include <X11/Xaw/Cardinals.h>
19
#include <X11/Xaw/Paned.h>
22
#include "../sun/h_help.h"
23
#include "../graphics/Math.h"
25
extern Widget toplevel;
26
extern Atom wm_delete_window;
27
extern char *getenv();
28
extern Widget initColors __PARAMS((Widget));
30
/** a terminer : normalement c'est statique plus une action **/
32
void popupHelpPanel();
34
static void initHelpWidgets();
35
static void helpCallback();
36
static void helpCallback1();
37
static void helpDoneAction();
38
static void queryAproposAction();
39
static void MyXawListChange();
40
static int NewString();
45
static Widget helpShell;
46
static Widget helpLabel, helpViewport, helpList, helpList1, helpViewport1;
47
static Widget helpScrollbar;
48
static Widget aproposText;
49
static Widget aproposInfo;
51
static Boolean isPoppedUp;
53
static XtActionsRec actionTable[] =
55
{"help", popupHelpPanel},
56
{"help-done", helpDoneAction},
57
{"query-apropos", queryAproposAction},
60
/*************************************************************
62
*************************************************************/
64
void initHelpActions(appContext)
65
XtAppContext appContext;
67
XtAppAddActions(appContext, actionTable, XtNumber(actionTable));
70
static int using_menu_help =0;
76
XRaiseWindow(XtDisplay(helpShell), XtWindow(helpShell));
79
if (helpShell == NULL)
81
if ( Help_Init() == 1)
83
sciprint("can't use man\r\n");
89
XtPopup(helpShell, XtGrabNone);
95
XtPopup(helpShell, XtGrabNone);
99
int help_popped_status()
101
return(using_menu_help);
104
/**********************************************
105
* Creates the help popup panel
106
*********************************************/
109
static void helpSetHints(topW)
112
XSizeHints size_hints;
113
size_hints.width = 680;
114
size_hints.height = 500;
115
size_hints.min_width = 650;
116
size_hints.min_height = 300;
117
size_hints.flags = /** USPosition |**/ USSize | PMinSize;
118
XSetNormalHints(XtDisplay(topW),XtWindow(topW), &size_hints);
120
* Add a protocol flag indicating we wish to handle
121
* WM_DELETE_WINDOW requests (in fact we ignore it)
123
(void) XSetWMProtocols(XtDisplay(helpShell), XtWindow(topW), &wm_delete_window, 1);
137
DisplayInit("",&dpy,&toplevel);
138
XtSetArg(args[iargs],XtNtitle,"Scilab Help Panel");iargs++;
139
helpShell = XtAppCreateShell("Xscilab","Xscihelp",topLevelShellWidgetClass,dpy,
142
color = initColors(helpShell);
144
/* helpShell = XtCreatePopupShell("helpShell", topLevelShellWidgetClass,
145
toplevel, (ArgList) 0, (Cardinal) 0);
147
form = XtCreateManagedWidget("helpForm", formWidgetClass,
148
color, (ArgList) 0, (Cardinal) 0);
149
helpLabel = XtCreateManagedWidget("helpLabel", labelWidgetClass,
150
form, (ArgList) 0, (Cardinal) 0);
151
sprintf(buf, "This is help for %s", VERSION);
152
if (helpLabel != NULL && buf != NULL) {
153
XtSetArg(args[0], XtNlabel, buf);
154
XtSetValues(helpLabel, args, 1);
156
helpViewport = XtCreateManagedWidget("helpViewport", viewportWidgetClass,
157
form, (ArgList) 0, (Cardinal) 0);
158
helpList = XtCreateManagedWidget("helpList", listWidgetClass,
159
helpViewport, (ArgList) 0, (Cardinal) 0);
161
MyXawListChange(helpList, helpTopicInfo, nTopicInfo, 0, True);
162
XtAddCallback(helpList, XtNcallback, helpCallback, (XtPointer) NULL);
163
helpViewport1 = XtCreateManagedWidget("helpViewport1", viewportWidgetClass,
164
form, (ArgList) 0, (Cardinal) 0);
165
helpList1 = XtCreateManagedWidget("helpList1", listWidgetClass,
166
helpViewport1, (ArgList) 0, (Cardinal) 0);
168
XawListChange(helpList1, helpInfo, nInfo, 0, True);
169
XtAddCallback(helpList1, XtNcallback, helpCallback1, (XtPointer) NULL);
170
(void) XtCreateManagedWidget("helpDoneButton", commandWidgetClass,
171
form, (ArgList) 0, (Cardinal) 0);
172
helpScrollbar = XtNameToWidget(helpViewport, "vertical");
173
(void) XtCreateManagedWidget("aproposLabel", labelWidgetClass,
174
form, (ArgList) 0, (Cardinal) 0);
175
aproposText = XtCreateManagedWidget("aproposText", asciiTextWidgetClass,
176
form, (ArgList) 0, (Cardinal) 0);
177
aproposInfo= XtCreateManagedWidget("aproposInfo",labelWidgetClass,
178
form, (ArgList) 0, (Cardinal) 0);
180
XtRealizeWidget(helpShell);
181
helpSetHints(helpShell);
185
/* meme chose mais appel r'eduit pour appel a partir de C */
187
void help_info(message,str1,str2)
188
char *message,*str1,*str2;
193
sprintf(buf,"%s %s %s",message,str1,str2);
194
XtSetArg(args[n], XtNlabel,buf);n++;
195
XtSetValues(aproposInfo, args, n);
200
/***************************************
201
* Changes the current help list to
203
**************************************/
205
void changeHelpList(i)
210
MyXawListChange(helpList, helpTopicInfo, nTopicInfo, 0, True);
213
/** Changes Widget List with a copy of help **/
215
static void MyXawListChange(w,help,ntopic,f1,f2)
220
static char **help_c=(char **)0,**help_c1;
221
static int ntopic_c=0;
222
if ( CopyListForWidget(&help_c1,help,ntopic,f1,f2) == 1) return;
223
if ( help_c != ( char **) 0) FreeWidgetList( help_c,ntopic_c);
226
XawListChange(w,help_c,ntopic,f1,f2);
229
int CopyListForWidget( help_c,help,ntopic)
230
char ***help_c,**help;
234
*help_c = (char **) MALLOC((ntopic + 1) * sizeof(char *));
235
if ( *help_c == NULL) {
236
sciprint("Not enough memory to allocate help tables\r\n");
239
for ( k = 0 ; k < ntopic ; k++)
243
if ( NewString(&(*help_c)[k],help[k]) == 1)
246
for ( j = 0 ; j < k ; j++ ) FREE((*help_c)[j]);
247
sciprint("Not enough memory to allocate help tables\r\n");
251
for ( k2 = strlen(str) ; k2 > 0 ; k2--)
253
if ( str[k2]=='@' ) str[k2] ='\0';
256
(*help_c)[ntopic]= (char *) 0;
261
static int NewString(hstr,line)
264
*hstr = (char *) MALLOC((strlen(line) + 1) * (sizeof(char)));
265
if ( (*hstr) == NULL)
267
sciprint("Not enough memory to allocate help tables\r\n");
274
int FreeWidgetList( help_c,ntopic)
279
for ( k = 0 ; k < ntopic ; k++ ) FREE(help_c[k]);
283
/************************************************
284
* Changes the state of the help popup
286
************************************************/
289
setHelpShellState(state)
296
XtMapWidget(helpShell);
299
XtUnmapWidget(helpShell);
305
/************************************
306
* Scilab apropos function
307
************************************/
309
static void SciApropos(str)
312
int status = AP.nTopic;
313
if ( SetAproposTopics(str) == 1) return ; /** memory allocation **/
318
/** the previous valid list was an apropos one we clear it **/
320
help_info("No Info on topic ",str,", back to chapter one");
323
help_info("No Info on topic ", str,"");
327
MyXawListChange(helpList, AP.HelpTopic, AP.nTopic, 0, True);
331
/******************************************************************
333
* activate the help ( xless application on the selected topic
334
*****************************************************************/
337
helpCallback(w, client_data, call_data)
339
XtPointer client_data; /* not used */
340
XtPointer call_data; /* returnStruct */
342
int ntopic = ((XawListReturnStruct *) call_data)->list_index;
343
HelpActivate(ntopic) ;
347
helpCallback1(w, client_data, call_data)
349
XtPointer client_data; /* not used */
350
XtPointer call_data; /* returnStruct */
352
int topic = ((XawListReturnStruct *) call_data)->list_index;
353
changeHelpList(topic + 1);
357
/****************************************************
359
****************************************************/
361
static void helpDoneAction(w,event,params,num_params)
362
Widget w; XEvent *event; String *params; Cardinal *num_params;
364
XtPopdown(helpShell);
369
getWidgetString(widget)
374
XtSetArg(args[0], XtNstring, &s);
375
XtGetValues(widget, args, 1);
379
static void queryAproposAction(w,event,params,num_params)
380
Widget w; XEvent *event; String *params; Cardinal *num_params;
383
if ((apropos = getWidgetString(aproposText)) == NULL || *apropos == '\0')
385
help_info("Apropos string is empty ","","");