~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to routines/xsci/h_help.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 1998 Chancelier Jean-Philippe */
 
2
/*
 
3
 * help.c : The Help browser 
 
4
 *
 
5
 * George Ferguson, ferguson@cs.rochester.edu, 23 Apr 1993. 
 
6
 */
 
7
 
 
8
#include <stdio.h>
 
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>
 
20
 
 
21
#include "version.h"
 
22
#include "../sun/h_help.h"
 
23
#include "../graphics/Math.h"
 
24
 
 
25
extern Widget   toplevel;
 
26
extern Atom     wm_delete_window;
 
27
extern  char  *getenv();
 
28
extern Widget initColors  __PARAMS((Widget));  
 
29
 
 
30
/** a terminer : normalement c'est statique plus une action **/
 
31
 
 
32
void            popupHelpPanel();
 
33
 
 
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();
 
41
 
 
42
/*
 
43
 * Data defined here 
 
44
 */
 
45
static Widget   helpShell;
 
46
static Widget   helpLabel, helpViewport, helpList, helpList1, helpViewport1;
 
47
static Widget   helpScrollbar;
 
48
static Widget   aproposText;
 
49
static Widget   aproposInfo;
 
50
 
 
51
static Boolean  isPoppedUp;
 
52
 
 
53
static XtActionsRec actionTable[] = 
 
54
{
 
55
  {"help", popupHelpPanel},
 
56
  {"help-done", helpDoneAction},
 
57
  {"query-apropos", queryAproposAction},
 
58
};
 
59
 
 
60
/*************************************************************
 
61
 * Help Popup 
 
62
 *************************************************************/
 
63
 
 
64
void initHelpActions(appContext)
 
65
     XtAppContext    appContext;
 
66
{
 
67
  XtAppAddActions(appContext, actionTable, XtNumber(actionTable));
 
68
}
 
69
 
 
70
static int using_menu_help =0;
 
71
 
 
72
void popupHelpPanel()
 
73
{
 
74
  if (isPoppedUp) 
 
75
    {
 
76
      XRaiseWindow(XtDisplay(helpShell), XtWindow(helpShell));
 
77
      return;
 
78
    }
 
79
  if (helpShell == NULL) 
 
80
    {
 
81
      if ( Help_Init() == 1) 
 
82
        {
 
83
          sciprint("can't use man\r\n");
 
84
          return;
 
85
        }
 
86
      initHelpWidgets();
 
87
      isPoppedUp = True;
 
88
      using_menu_help =1;
 
89
      XtPopup(helpShell, XtGrabNone);
 
90
    }
 
91
  else 
 
92
    {
 
93
      isPoppedUp = True;
 
94
      using_menu_help = 1;
 
95
      XtPopup(helpShell, XtGrabNone);
 
96
    }
 
97
}
 
98
 
 
99
int help_popped_status()
 
100
{
 
101
  return(using_menu_help);
 
102
}
 
103
 
 
104
/**********************************************
 
105
 * Creates the help popup panel 
 
106
 *********************************************/
 
107
 
 
108
 
 
109
static void helpSetHints(topW)
 
110
     Widget topW;
 
111
{
 
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);
 
119
 /*
 
120
  *  Add a protocol flag indicating we wish to handle
 
121
  *  WM_DELETE_WINDOW requests (in fact we ignore it)
 
122
  */
 
123
  (void) XSetWMProtocols(XtDisplay(helpShell), XtWindow(topW), &wm_delete_window, 1);
 
124
}
 
125
 
 
126
 
 
127
static void
 
128
initHelpWidgets()
 
129
{
 
130
  Widget          form,color;
 
131
  char            buf[64];
 
132
  Arg             args[1];
 
133
  Widget toplevel;
 
134
  Display *dpy;
 
135
  int iargs =0;
 
136
 
 
137
  DisplayInit("",&dpy,&toplevel);
 
138
  XtSetArg(args[iargs],XtNtitle,"Scilab Help Panel");iargs++;
 
139
  helpShell = XtAppCreateShell("Xscilab","Xscihelp",topLevelShellWidgetClass,dpy,
 
140
                                      args,iargs);
 
141
 
 
142
  color = initColors(helpShell);
 
143
 
 
144
  /* helpShell = XtCreatePopupShell("helpShell", topLevelShellWidgetClass,
 
145
                                 toplevel, (ArgList) 0, (Cardinal) 0);
 
146
  */
 
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);
 
155
                                        };
 
156
  helpViewport = XtCreateManagedWidget("helpViewport", viewportWidgetClass,
 
157
                                       form, (ArgList) 0, (Cardinal) 0);
 
158
  helpList = XtCreateManagedWidget("helpList", listWidgetClass,
 
159
                                   helpViewport, (ArgList) 0, (Cardinal) 0);
 
160
 
 
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);
 
167
 
 
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);
 
179
 
 
180
  XtRealizeWidget(helpShell);
 
181
  helpSetHints(helpShell);
 
182
}
 
183
 
 
184
 
 
185
/* meme chose mais appel r'eduit pour appel a partir de C */
 
186
 
 
187
void help_info(message,str1,str2)
 
188
     char *message,*str1,*str2;
 
189
{
 
190
  char buf[56];
 
191
  Arg args[1];
 
192
  Cardinal n = 0;
 
193
  sprintf(buf,"%s %s %s",message,str1,str2);
 
194
  XtSetArg(args[n], XtNlabel,buf);n++;
 
195
  XtSetValues(aproposInfo, args, n);
 
196
}
 
197
 
 
198
 
 
199
 
 
200
/***************************************
 
201
 * Changes the current help list to 
 
202
 * chapter i
 
203
 **************************************/
 
204
 
 
205
void changeHelpList(i)
 
206
     int  i;
 
207
{
 
208
  setHelpTopicInfo(i);
 
209
  if (nTopicInfo > 0)
 
210
    MyXawListChange(helpList, helpTopicInfo, nTopicInfo, 0, True);
 
211
}
 
212
 
 
213
/** Changes Widget List with a copy of help **/
 
214
 
 
215
static void MyXawListChange(w,help,ntopic,f1,f2)
 
216
     Widget w;
 
217
     char **help;
 
218
     int ntopic,f1,f2;
 
219
{
 
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);
 
224
  help_c = help_c1;
 
225
  ntopic_c = ntopic;
 
226
  XawListChange(w,help_c,ntopic,f1,f2);
 
227
}
 
228
 
 
229
int CopyListForWidget( help_c,help,ntopic)
 
230
     char ***help_c,**help;
 
231
     int ntopic;
 
232
{
 
233
  int k;
 
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");
 
237
    return(1);
 
238
  }
 
239
  for ( k = 0 ; k < ntopic ; k++)
 
240
    {
 
241
      char *str;
 
242
      int k2;
 
243
      if ( NewString(&(*help_c)[k],help[k]) == 1) 
 
244
        {
 
245
          int j;
 
246
          for ( j = 0 ; j < k ; j++ ) FREE((*help_c)[j]);
 
247
          sciprint("Not enough memory to allocate help tables\r\n");
 
248
          return(1);
 
249
        }
 
250
      str = (*help_c)[k]; 
 
251
      for ( k2 = strlen(str) ; k2 > 0 ; k2--) 
 
252
        {
 
253
          if ( str[k2]=='@' ) str[k2] ='\0';
 
254
        }
 
255
    }
 
256
  (*help_c)[ntopic]= (char *) 0;
 
257
  return(0);
 
258
}
 
259
 
 
260
 
 
261
static int NewString(hstr,line)
 
262
     char **hstr, *line;
 
263
{
 
264
  *hstr = (char *) MALLOC((strlen(line) + 1) * (sizeof(char)));
 
265
  if ( (*hstr) == NULL)
 
266
    {
 
267
      sciprint("Not enough memory to allocate help tables\r\n");
 
268
      return(1);
 
269
    }
 
270
  strcpy(*hstr, line);
 
271
  return(0);
 
272
}
 
273
 
 
274
int FreeWidgetList( help_c,ntopic)
 
275
     char **help_c;
 
276
     int ntopic;
 
277
{
 
278
  int k;
 
279
  for ( k = 0 ; k < ntopic ; k++ ) FREE(help_c[k]);
 
280
  FREE(help_c);
 
281
}
 
282
 
 
283
/************************************************
 
284
 * Changes the state of the help popup 
 
285
 * If it exists 
 
286
 ************************************************/
 
287
 
 
288
void
 
289
setHelpShellState(state)
 
290
     int state;
 
291
{
 
292
  if (!isPoppedUp)
 
293
    return;
 
294
  switch (state) {
 
295
  case NormalState:
 
296
    XtMapWidget(helpShell);
 
297
    break;
 
298
  case IconicState:
 
299
    XtUnmapWidget(helpShell);
 
300
    break;
 
301
  }
 
302
}
 
303
 
 
304
 
 
305
/************************************
 
306
 * Scilab apropos function 
 
307
 ************************************/
 
308
 
 
309
static void SciApropos(str)
 
310
        char           *str;
 
311
{
 
312
  int status = AP.nTopic;
 
313
  if ( SetAproposTopics(str) == 1) return ; /** memory allocation **/
 
314
  if (AP.nTopic == 0) 
 
315
    {
 
316
      if ( status != 0) 
 
317
        {
 
318
          /** the previous valid list was an apropos one we clear it **/
 
319
          changeHelpList(1);
 
320
          help_info("No Info on topic ",str,", back to chapter one");
 
321
        }
 
322
      else
 
323
        help_info("No Info on topic ", str,"");
 
324
      return;
 
325
    }
 
326
  help_info("","","");
 
327
  MyXawListChange(helpList, AP.HelpTopic, AP.nTopic, 0, True);
 
328
}
 
329
 
 
330
 
 
331
/******************************************************************
 
332
 * Callback procedure 
 
333
 * activate the help ( xless application on the selected topic 
 
334
 *****************************************************************/
 
335
 
 
336
static void
 
337
helpCallback(w, client_data, call_data)
 
338
     Widget          w;
 
339
     XtPointer       client_data;       /* not used */
 
340
     XtPointer       call_data; /* returnStruct */
 
341
{
 
342
  int             ntopic = ((XawListReturnStruct *) call_data)->list_index;
 
343
  HelpActivate(ntopic) ;
 
344
}
 
345
 
 
346
static void
 
347
helpCallback1(w, client_data, call_data)
 
348
        Widget          w;
 
349
        XtPointer       client_data;    /* not used */
 
350
        XtPointer       call_data;      /* returnStruct */
 
351
{
 
352
  int             topic = ((XawListReturnStruct *) call_data)->list_index;
 
353
  changeHelpList(topic + 1);
 
354
}
 
355
 
 
356
 
 
357
/****************************************************
 
358
 * Action procedures 
 
359
 ****************************************************/
 
360
 
 
361
static void helpDoneAction(w,event,params,num_params) 
 
362
     Widget w; XEvent *event; String *params; Cardinal *num_params;
 
363
{
 
364
  XtPopdown(helpShell);
 
365
  isPoppedUp = False;
 
366
}
 
367
 
 
368
char           *
 
369
getWidgetString(widget)
 
370
        Widget          widget;
 
371
{
 
372
  Arg             args[1];
 
373
  char           *s;
 
374
  XtSetArg(args[0], XtNstring, &s);
 
375
  XtGetValues(widget, args, 1);
 
376
  return (s);
 
377
}
 
378
 
 
379
static void queryAproposAction(w,event,params,num_params) 
 
380
     Widget w; XEvent *event; String *params; Cardinal *num_params;
 
381
{
 
382
  char           *apropos;
 
383
  if ((apropos = getWidgetString(aproposText)) == NULL || *apropos == '\0') 
 
384
    {
 
385
      help_info("Apropos string is empty ","","");
 
386
      return;
 
387
    } 
 
388
  else 
 
389
    {
 
390
      SciApropos(apropos);
 
391
    }
 
392
}
 
393