~maddevelopers/mg5amcnlo/2.9.4

« back to all changes in this revision

Viewing changes to vendor/StdHEP/mcfio/src/help.c

pass to v2.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
*                                                                              *
 
3
* help.c -- Nirvana help display                                               *
 
4
*                                                                              *
 
5
* Copyright (c) 1991 Universities Research Association, Inc.                   *
 
6
* All rights reserved.                                                         *
 
7
*                                                                              *
 
8
* This material resulted from work developed under a Government Contract and   *
 
9
* is subject to the following license:  The Government retains a paid-up,      *
 
10
* nonexclusive, irrevocable worldwide license to reproduce, prepare derivative *
 
11
* works, perform publicly and display publicly by or for the Government,       *
 
12
* including the right to distribute to other Government contractors.  Neither  *
 
13
* the United States nor the United States Department of Energy, nor any of     *
 
14
* their employees, makes any warrenty, express or implied, or assumes any      *
 
15
* legal liability or responsibility for the accuracy, completeness, or         *
 
16
* usefulness of any information, apparatus, product, or process disclosed, or  *
 
17
* represents that its use would not infringe privately owned rights.           *
 
18
*                                                                              *
 
19
* Fermilab Nirvana GUI Library                                                 *
 
20
* November 13, 1991                                                            *
 
21
*                                                                              *
 
22
* Written by Mark Edel                                                         *
 
23
*                                                                              *
 
24
*******************************************************************************/
 
25
static char SCCSID[] = "@(#)help.c      1.6     8/19/94";
 
26
#include <stdio.h>
 
27
#include <Xm/Xm.h>
 
28
#include <Xm/Form.h>
 
29
#include <Xm/Text.h>
 
30
#include <Xm/PushB.h>
 
31
#include <Xm/RowColumn.h>
 
32
#include <Xm/CascadeB.h>
 
33
#include <Xm/ScrolledW.h>
 
34
#include <Xm/ScrollBar.h>
 
35
#include <Xm/Label.h>
 
36
#include "misc.h"
 
37
#include "help.h"
 
38
 
 
39
#define MAX_HELP_BM_WIDTH 640   /* Max width of a help bitmap before
 
40
                                   using a horizontal scroll bar */
 
41
#define MAX_HELP_BM_HEIGHT 400  /* Max height of a help bitmap before
 
42
                                   using a vertical scroll bar */
 
43
#define SCROLL_BAR_WIDTH 31     /* Amount of padding to add to set the width
 
44
                                   of a scrolled window including a scroll bar
 
45
                                   from the width of its contents */
 
46
#define SCROLL_FRAME_WIDTH 12   /* Amount of padding to add to set the width
 
47
                                   of a scrolled window with no scroll bar
 
48
                                   from the width of its contents */
 
49
 
 
50
static void dismissCB(Widget w, caddr_t clientData, caddr_t callData);
 
51
static void bitmapDismissCB(Widget w, Pixmap pmToDestroy, caddr_t callData);
 
52
static void helpMenuCB(Widget w, helpMenuInfo *info, caddr_t callData);
 
53
 
 
54
/*
 
55
** CreateHelpPulldownMenu
 
56
**
 
57
** Creates a working help menu. The caller should supply a parent menu bar
 
58
** or menu pane, and a null terminated array of pointers to menuInfo data
 
59
** structures.  If menuBar is a menu bar, the help menu will appear as a
 
60
** top level pulldown menu on the right of the menu bar.  If it is a menu
 
61
** pane, the help menu will appear as a sub-menu at the last item position.
 
62
** CreateHelpPulldownMenu creates the Help cascade button as well as the
 
63
** the menu pane and its contents.  The button has the name "Help", and
 
64
** the mnemonic "H" by default.  The data pointed to by menuInfo is not
 
65
** copied, so the caller must not deallocate it after passing it to
 
66
** CreateHelpPulldownMenu (we expect this to be used mostly with statically
 
67
** allocated help text).  menuInfo is an array of pointers to structures
 
68
** rather than the structures themselves, so programs which have several
 
69
** help menus can share items among them.
 
70
**
 
71
** Parameters
 
72
**
 
73
**      menuBar         Menu bar or menu pane in which to insert the help menu
 
74
**      menuInfo        Pointer to a null terminated array of pointers
 
75
**                      to helpMenuInfo data structures.  This data is not
 
76
**                      copied and must remain in place after the call
 
77
**                      to  CreateHelpPulldownMenu
 
78
**
 
79
** Return Value
 
80
**
 
81
**      Returns the Help cascade button.  To get the menu pane of the new
 
82
**      menu, read the value of XmNsubMenuId from the returned widget.
 
83
*/
 
84
Widget CreateHelpPulldownMenu(Widget menuBar, helpMenuInfo **menuInfo)
 
85
{
 
86
    Widget menu, cascade;
 
87
    char widgetName[20];
 
88
    helpMenuInfo **info;
 
89
    XmString s1;
 
90
    int i;
 
91
 
 
92
    /* create the menu pane and fill in its items from the menuInfo array */
 
93
    menu = XmCreatePulldownMenu(menuBar, "help", NULL, 0);
 
94
    for (i=1, info=menuInfo; *info!=NULL; i++, info++) {
 
95
        sprintf(widgetName, "help%d", i);
 
96
        AddMenuItem(menu, widgetName, (**info).topic, (**info).mnemonic,
 
97
                "", "", (XtCallbackProc)helpMenuCB, *info);
 
98
        if ((**info).sepAfter) {
 
99
            sprintf(widgetName, "sep%d", i);
 
100
            AddMenuSeparator(menu, widgetName);
 
101
        }
 
102
    }
 
103
 
 
104
    /* create the cascade button with name "Help" and mnemonic 'H' */
 
105
    cascade = XtVaCreateManagedWidget("help", xmCascadeButtonWidgetClass,
 
106
            menuBar, XmNlabelString, s1=XmStringCreateSimple("Help"),
 
107
            XmNmnemonic, 'H', XmNsubMenuId, menu, 0);
 
108
    XmStringFree(s1);
 
109
    
 
110
    /* set the menu up as the designated help menu (puts it on the right
 
111
       of a menu bar or bottom of a submenu) */
 
112
    XtVaSetValues(menuBar, XmNmenuHelpWidget, cascade, 0);
 
113
 
 
114
    return cascade;
 
115
}
 
116
 
 
117
/*
 
118
** CreateHelpDialog
 
119
**
 
120
** Display a simple scrolled text dialog to present help information.
 
121
** Closing the dialog destroys it.
 
122
**
 
123
** Parameters
 
124
**
 
125
**      parent          Parent widget for dialog
 
126
**      title           Window title for the dialog
 
127
**      text            Null terminated string containing the text to present
 
128
**
 
129
** Return Value
 
130
**
 
131
**      Returns the top non-shell widget of the new dialog.
 
132
*/
 
133
Widget CreateHelpDialog(Widget parent, char *title, char *text)
 
134
{
 
135
    Widget form, button, textW;
 
136
    XmString st1;
 
137
    Arg al[20];
 
138
    int ac;
 
139
 
 
140
    form = XmCreateFormDialog(parent, "helpForm", NULL, 0);
 
141
    XtVaSetValues(form, XmNshadowThickness, 0, 0);
 
142
 
 
143
    ac = 0;
 
144
    XtSetArg(al[ac], XmNlabelString, st1=XmStringCreateSimple("Dismiss")); ac++;
 
145
    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_FORM);  ac++;
 
146
    XtSetArg(al[ac], XmNtopAttachment, XmATTACH_NONE);  ac++;
 
147
    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_POSITION);  ac++;
 
148
    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_POSITION);  ac++;
 
149
    XtSetArg(al[ac], XmNleftPosition, 35);  ac++;
 
150
    XtSetArg(al[ac], XmNrightPosition, 65);  ac++;
 
151
    button = XmCreatePushButton(form, "dismiss", al, ac);
 
152
    XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)dismissCB, NULL);
 
153
    XmStringFree(st1);
 
154
    XtManageChild(button);
 
155
    XtVaSetValues(form, XmNdefaultButton, button, 0);
 
156
    
 
157
    ac = 0;
 
158
    XtSetArg(al[ac], XmNrows, 15);  ac++;
 
159
    XtSetArg(al[ac], XmNcolumns, 60);  ac++;
 
160
    XtSetArg(al[ac], XmNresizeHeight, False);  ac++;
 
161
    XtSetArg(al[ac], XmNtraversalOn, False); ac++;
 
162
    XtSetArg(al[ac], XmNwordWrap, True);  ac++;
 
163
    XtSetArg(al[ac], XmNscrollHorizontal, False);  ac++;
 
164
    XtSetArg(al[ac], XmNspacing, 0);  ac++;
 
165
    XtSetArg(al[ac], XmNeditMode, XmMULTI_LINE_EDIT);  ac++;
 
166
    XtSetArg(al[ac], XmNeditable, False);  ac++;
 
167
    XtSetArg(al[ac], XmNvalue, text);  ac++;
 
168
    XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM);  ac++;
 
169
    XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM);  ac++;
 
170
    XtSetArg(al[ac], XmNbottomAttachment, XmATTACH_WIDGET);  ac++;
 
171
    XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM);  ac++;
 
172
    XtSetArg(al[ac], XmNbottomWidget, button);  ac++;
 
173
    textW = XmCreateScrolledText(form, "helpText", al, ac);
 
174
    XtManageChild(textW);
 
175
    
 
176
    XtVaSetValues(XtParent(form), XmNtitle, title, 0);
 
177
    ManageDialogCenteredOnPointer(form);
 
178
    
 
179
    return form;
 
180
}
 
181
 
 
182
/*
 
183
** CreateBitmapHelpDialog
 
184
**
 
185
** Display a simple scrolled bitmap dialog to present help information.
 
186
** Closing the dialog destroys it.
 
187
**
 
188
** Parameters
 
189
**
 
190
**      parent          Parent widget for dialog
 
191
**      title           Window title for the dialog
 
192
**      bits            Null terminated string containing the text to present
 
193
**      width           Width of the bitmap in pixels
 
194
**      height          height ot the bitmap in pixels
 
195
**
 
196
** Return Value
 
197
**
 
198
**      Returns the top non-shell widget of the new dialog.
 
199
*/
 
200
Widget CreateBitmapHelpDialog(Widget parent, char *title, char *bits,
 
201
        int width, int height)
 
202
{
 
203
    Widget form, button, scrollW;
 
204
    XmString st1;
 
205
    Pixmap labelPixmap;
 
206
    Pixel fg, bg;
 
207
    int swWidth, swHeight, s;
 
208
 
 
209
    /* create a form dialog to hold everything */
 
210
    form = XmCreateFormDialog(parent, "helpForm", NULL, 0);
 
211
    XtVaSetValues(form, XmNshadowThickness, 0, 0);
 
212
    
 
213
    /* decide on a width and height for the scrolled window */
 
214
    swWidth = (width > MAX_HELP_BM_WIDTH ? MAX_HELP_BM_WIDTH : width) +
 
215
          (height > MAX_HELP_BM_HEIGHT ? SCROLL_BAR_WIDTH : SCROLL_FRAME_WIDTH);
 
216
    swHeight = (height > MAX_HELP_BM_HEIGHT ? MAX_HELP_BM_HEIGHT : height) +
 
217
            (width > MAX_HELP_BM_WIDTH ? SCROLL_BAR_WIDTH : SCROLL_FRAME_WIDTH);
 
218
 
 
219
    /* create a pixmap to display from the bit data, the pixmap must be
 
220
       of the same depth as the window it will be drawn to */
 
221
    XtVaGetValues(form, XmNforeground, &fg, XmNbackground, &bg, 0);
 
222
    labelPixmap = XCreatePixmapFromBitmapData(XtDisplay(parent),
 
223
            RootWindowOfScreen(XtScreen(parent)), bits, width, height,
 
224
            fg, bg, DefaultDepthOfScreen(XtScreen(parent)));
 
225
 
 
226
    /* create the widgets in the window: a dismiss button, and a scrolled
 
227
       window containing a pixmap-displaying label */
 
228
    button = XtVaCreateManagedWidget("dismiss", xmPushButtonWidgetClass, form,
 
229
            XmNlabelString, st1=XmStringCreateSimple("Dismiss"),
 
230
            XmNbottomAttachment, XmATTACH_FORM,
 
231
            XmNtopAttachment, XmATTACH_NONE,
 
232
            XmNleftAttachment, XmATTACH_POSITION,
 
233
            XmNrightAttachment, XmATTACH_POSITION,
 
234
            XmNleftPosition, 35,
 
235
            XmNrightPosition, 65, 0);
 
236
    XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)bitmapDismissCB,
 
237
            (char *)labelPixmap);
 
238
    XmStringFree(st1);
 
239
    XtVaSetValues(form, XmNdefaultButton, button, 0);
 
240
    scrollW = XtVaCreateManagedWidget("scroll", xmScrolledWindowWidgetClass,
 
241
            form,
 
242
            XmNwidth, swWidth,
 
243
            XmNheight, swHeight,
 
244
            XmNspacing, 0,
 
245
            XmNscrollingPolicy, XmAUTOMATIC,
 
246
            XmNtopAttachment, XmATTACH_FORM,
 
247
            XmNleftAttachment, XmATTACH_FORM,
 
248
            XmNbottomAttachment, XmATTACH_WIDGET,
 
249
            XmNrightAttachment, XmATTACH_FORM,
 
250
            XmNbottomWidget, button, 0);
 
251
    XtVaCreateManagedWidget("bitmap", xmLabelWidgetClass,  scrollW,
 
252
            XmNlabelType, XmPIXMAP,
 
253
            XmNlabelPixmap, labelPixmap, 0);
 
254
    
 
255
    /* set the title of the window */
 
256
    XtVaSetValues(XtParent(form), XmNtitle, title, 0);
 
257
    
 
258
    /* pop up and return wigit id of the help dialog just created */
 
259
    ManageDialogCenteredOnPointer(form);
 
260
    return form;
 
261
}
 
262
 
 
263
static void dismissCB(Widget w, caddr_t clientData, caddr_t callData)
 
264
{
 
265
    XtDestroyWidget(XtParent(w));
 
266
}
 
267
 
 
268
static void bitmapDismissCB(Widget w, Pixmap pmToDestroy, caddr_t callData)
 
269
{
 
270
    XFreePixmap(XtDisplay(w), pmToDestroy);
 
271
    XtDestroyWidget(XtParent(w));
 
272
}
 
273
 
 
274
static void helpMenuCB(Widget w, helpMenuInfo *info, caddr_t callData)
 
275
{
 
276
    if (info->type == HELP_TEXT)
 
277
        CreateHelpDialog(w, info->topic, info->text);
 
278
    else /* HELP_BITMAP */
 
279
        CreateBitmapHelpDialog(w, info->topic, info->text, info->width,
 
280
                info->height);
 
281
}