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
|
/***************************************************************************/
/***************************************************************************/
/* */
/* (c) 1995-1998. The Regents of the University of California. All */
/* rights reserved. */
/* */
/* This work was produced at the University of California, Lawrence */
/* Livermore National Laboratory (UC LLNL) under contract no. */
/* W-7405-ENG-48 (Contract 48) between the U.S. Department of Energy */
/* (DOE) and The Regents of the University of California (University) */
/* for the operation of UC LLNL. Copyright is reserved to the */
/* University for purposes of controlled dissemination, */
/* commercialization through formal licensing, or other disposition */
/* under terms of Contract 48; DOE policies, regulations and orders; */
/* and U.S. statutes. The rights of the Federal Government are */
/* reserved under Contract 48 subject to the restrictions agreed upon */
/* by the DOE and University. */
/* */
/* */
/* DISCLAIMER */
/* */
/* This software was prepared as an account of work sponsored by an */
/* agency of the United States Government. Neither the United States */
/* Government nor the University of California nor any of their */
/* employees, makes any warranty, express or implied, or assumes any */
/* liability or responsibility for the accuracy, completeness, or */
/* usefulness of any information, apparatus, product, or process */
/* disclosed, or represents that its specific commercial products, */
/* process, or service by trade name, trademark, manufacturer, or */
/* otherwise, does not necessarily constitute or imply its */
/* endorsement, recommendation, or favoring by the United States */
/* Government or the University of California. The views and opinions */
/* of the authors expressed herein do not necessarily state or reflect */
/* those of the United States Government or the University of */
/* California, and shall not be used for advertising or product */
/* endorsement purposes. */
/* */
/* Permission to use, copy, modify and distribute this software and its */
/* documentation for any non-commercial purpose, without fee, is */
/* hereby granted, provided that the above copyright notice and this */
/* permission notice appear in all copies of the software and */
/* supporting documentation, and that all UC LLNL identification in */
/* the user interface remain unchanged. The title to copyright LLNL */
/* XDIR shall at all times remain with The Regents of the University */
/* of California and users agree to preserve same. Users seeking the */
/* right to make derivative works with LLNL XDIR for commercial */
/* purposes may obtain a license from the Lawrence Livermore National */
/* Laboratory's Technology Transfer Office, P.O. Box 808, L-795, */
/* Livermore, CA 94550. */
/* */
/***************************************************************************/
/***************************************************************************/
#include <ctype.h>
#include <X11/cursorfont.h>
#include <Xm/PanedW.h>
#include <Xm/RowColumn.h>
#include <Xm/Text.h>
#include <Xm/PushB.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include "xdir.h"
struct help_st {
Widget w_dialog;
Widget w_pane;
Widget w_controlArea;
Widget w_topic;
Widget w_text;
Widget w_actionArea;
Widget w_closeButton;
};
static struct help_st *current_help = NULL;
static struct help_st *old_help = NULL;
extern Widget w_toplev;
extern Display *display;
void cb_help_close();
void cb_help_destroy();
struct help_st *create_help_window();
/*
* help_dialog - Pops up a dialog that display the help message specified by
* "text" in a scrolled text window. "topic" identifies the
* help topic to the user. "w_parent" is the widget to center
* the dialog over. If "modal" is True, add the help dialog
* to the modal cascade.
*/
help_dialog(w_parent, modal, topic, text)
Widget w_parent;
int modal;
char *topic;
char **text;
{
int indx = 0;
char *ptr;
char *buf;
int len = 0;
int i;
XmString string;
/* If help dialog already in use, destroy it */
if (current_help) {
old_help = current_help;
XtDestroyWidget(XtParent(old_help->w_dialog));
}
/* Pop up help window */
current_help = create_help_window(w_parent);
add_dialog_to_list(current_help->w_dialog);
traverse_to_widget(current_help->w_closeButton);
/* Add dialog to modal cascade? */
if (modal)
XtAddGrab(XtParent(current_help->w_dialog), False, False);
/* Insert help topic */
string = XmStringCreateSimple(topic);
XtVaSetValues(current_help->w_topic, XmNlabelString, string, NULL);
XmStringFree(string);
XtUnmanageChild(current_help->w_topic); /* Kludge */
XtManageChild(current_help->w_topic); /* Kludge */
/* Insert help message */
for (i=0; text[i]; i++)
len += strlen(text[i])+1;
len++;
buf = XtMalloc(len+1);
for (i=0; text[i]; i++) {
ptr = text[i];
while (*ptr)
buf[indx++] = *ptr++;
if (!isspace(buf[indx-1]))
buf[indx++] = ' ';
}
buf[indx] = '\0';
XtVaSetValues(current_help->w_text, XmNvalue, buf, NULL);
XtFree(buf);
}
/*
* create_help_window - Create window to display a scrollable help message.
* "w_parent" is the widget to center the dialog over.
* Returns a pointer to a help structure.
*/
struct help_st *
create_help_window(w_parent)
Widget w_parent;
{
Arg args[5];
XmString string;
int i;
Dimension height;
struct help_st *help;
/* Allocate help structure */
help = XtNew(struct help_st);
/* Create form dialog */
help->w_dialog = XmCreateFormDialog(w_parent, "help", NULL, 0);
XtAddCallback(help->w_dialog, XmNdestroyCallback, cb_help_destroy,
(XtPointer)NULL);
/* Add callback for the WM_DELETE_WINDOW protocol */
add_wm_delete_window_cb(help->w_dialog, cb_help_close, NULL, False);
/* Create paned window */
help->w_pane = XtVaCreateWidget(
"pane",
xmPanedWindowWidgetClass,
help->w_dialog,
XmNsashWidth, 1,
XmNsashHeight, 1,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL
);
/* Create form widget for control area */
help->w_controlArea = XtVaCreateWidget(
"controlArea",
xmFormWidgetClass,
help->w_pane,
XmNmarginWidth, 6,
XmNmarginHeight, 5,
NULL
);
/* Create label to display topic */
string = XmStringCreateSimple(" ");
help->w_topic= XtVaCreateManagedWidget(
"topic",
xmLabelWidgetClass,
help->w_controlArea,
XmNlabelString, string,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 10,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 13,
NULL
);
XmStringFree(string);
/* Create scrolled text widget to hold message */
i = 0;
XtSetArg(args[i], XmNeditable, False); i++;
XtSetArg(args[i], XmNeditMode, XmMULTI_LINE_EDIT); i++;
XtSetArg(args[i], XmNwordWrap, True); i++;
XtSetArg(args[i], XmNscrollHorizontal, False); i++;
XtSetArg(args[i], XmNcursorPositionVisible, False); i++;
help->w_text = XmCreateScrolledText(help->w_controlArea, "text", args, i);
XtVaSetValues(
XtParent(help->w_text),
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, help->w_topic,
XmNtopOffset, 10,
XmNbottomAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL
);
XtManageChild(help->w_text);
fix_vertical_text_sb_color(help->w_text);
XtManageChild(help->w_controlArea);
/* Create form widget for action area */
help->w_actionArea = XtVaCreateWidget(
"actionArea",
xmFormWidgetClass,
help->w_pane,
NULL
);
/* Create Close button */
string = XmStringCreateSimple("Close");
help->w_closeButton = XtVaCreateManagedWidget(
"closeButton",
xmPushButtonWidgetClass,
help->w_actionArea,
XmNlabelString, string,
XmNshowAsDefault, True,
XmNdefaultButtonShadowThickness, 1,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 40,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, 60,
NULL
);
XmStringFree(string);
XtAddCallback(help->w_closeButton, XmNactivateCallback, cb_help_close,
(XtPointer)NULL);
XtVaSetValues(help->w_dialog, XmNdefaultButton, help->w_closeButton, NULL);
XtManageChild(help->w_actionArea);
/* Freeze height of action area */
XtVaGetValues(help->w_closeButton, XmNheight, &height, NULL);
XtVaSetValues(
help->w_actionArea,
XmNpaneMaximum, height,
XmNpaneMinimum, height,
NULL
);
XtManageChild(help->w_pane);
XtManageChild(help->w_dialog);
return help;
}
/*
* cb_help_close - Callback to close "Help" dialog.
*/
void
cb_help_close(widget, client_data, call_data)
Widget widget;
XtPointer client_data;
XtPointer call_data;
{
/* Get rid of help dialog */
if (current_help)
XtDestroyWidget(XtParent(current_help->w_dialog));
else
fatal_error("*** Bug in cb_help_close()");
}
/*
* cb_help_destroy - Callback to destroy "Help" dialog.
*/
void
cb_help_destroy(widget, client_data, call_data)
Widget widget;
XtPointer client_data;
XtPointer call_data;
{
/* Destroy help dialog */
if (old_help) {
remove_dialog_from_list(old_help->w_dialog);
XtFree((char *)old_help);
old_help = NULL;
} else if (current_help) {
remove_dialog_from_list(current_help->w_dialog);
XtFree((char *)current_help);
current_help = NULL;
} else
fatal_error("Bug in cb_help_destroy()");
}
/*
* cb_contextual_help - Callback to put directory window into "contextual
* help "mode in which the cursor changes to a hand
* until the user clicks on a graphical element in
* the directory window he/she wishes to know more
* about.
*/
void
cb_contextual_help(widget, client_data, call_data)
Widget widget;
XtPointer client_data;
XtPointer call_data;
{
struct dirwin_st *dirwin = (struct dirwin_st *)client_data;
Cursor cursor;
Widget help_widget;
/* Start operation */
if (!start_op(False))
return;
/* Clear error flag */
raise_okflag();
/* Change cursor and wait for user to select widget */
cursor = XCreateFontCursor(display, XC_hand2);
if ((help_widget = XmTrackingLocate(dirwin->w_shell, cursor, True)))
XtCallCallbacks(help_widget, XmNhelpCallback, (XtPointer)NULL);
XFreeCursor(display, cursor);
/* End operation */
end_op();
}
|