1
/*******************************************************************************
3
* help.c -- Nirvana help display *
5
* Copyright (c) 1991 Universities Research Association, Inc. *
6
* All rights reserved. *
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. *
19
* Fermilab Nirvana GUI Library *
22
* Written by Mark Edel *
24
*******************************************************************************/
25
static char SCCSID[] = "@(#)help.c 1.6 8/19/94";
31
#include <Xm/RowColumn.h>
32
#include <Xm/CascadeB.h>
33
#include <Xm/ScrolledW.h>
34
#include <Xm/ScrollBar.h>
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 */
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);
55
** CreateHelpPulldownMenu
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.
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
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.
84
Widget CreateHelpPulldownMenu(Widget menuBar, helpMenuInfo **menuInfo)
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);
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);
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);
120
** Display a simple scrolled text dialog to present help information.
121
** Closing the dialog destroys it.
125
** parent Parent widget for dialog
126
** title Window title for the dialog
127
** text Null terminated string containing the text to present
131
** Returns the top non-shell widget of the new dialog.
133
Widget CreateHelpDialog(Widget parent, char *title, char *text)
135
Widget form, button, textW;
140
form = XmCreateFormDialog(parent, "helpForm", NULL, 0);
141
XtVaSetValues(form, XmNshadowThickness, 0, 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);
154
XtManageChild(button);
155
XtVaSetValues(form, XmNdefaultButton, button, 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);
176
XtVaSetValues(XtParent(form), XmNtitle, title, 0);
177
ManageDialogCenteredOnPointer(form);
183
** CreateBitmapHelpDialog
185
** Display a simple scrolled bitmap dialog to present help information.
186
** Closing the dialog destroys it.
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
198
** Returns the top non-shell widget of the new dialog.
200
Widget CreateBitmapHelpDialog(Widget parent, char *title, char *bits,
201
int width, int height)
203
Widget form, button, scrollW;
207
int swWidth, swHeight, s;
209
/* create a form dialog to hold everything */
210
form = XmCreateFormDialog(parent, "helpForm", NULL, 0);
211
XtVaSetValues(form, XmNshadowThickness, 0, 0);
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);
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)));
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,
235
XmNrightPosition, 65, 0);
236
XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)bitmapDismissCB,
237
(char *)labelPixmap);
239
XtVaSetValues(form, XmNdefaultButton, button, 0);
240
scrollW = XtVaCreateManagedWidget("scroll", xmScrolledWindowWidgetClass,
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);
255
/* set the title of the window */
256
XtVaSetValues(XtParent(form), XmNtitle, title, 0);
258
/* pop up and return wigit id of the help dialog just created */
259
ManageDialogCenteredOnPointer(form);
263
static void dismissCB(Widget w, caddr_t clientData, caddr_t callData)
265
XtDestroyWidget(XtParent(w));
268
static void bitmapDismissCB(Widget w, Pixmap pmToDestroy, caddr_t callData)
270
XFreePixmap(XtDisplay(w), pmToDestroy);
271
XtDestroyWidget(XtParent(w));
274
static void helpMenuCB(Widget w, helpMenuInfo *info, caddr_t callData)
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,