home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
n
/
newmarch.zip
/
POPUPEDI.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-08
|
5KB
|
208 lines
/* Author: $Author: jan $
* File: $Source: /usr/usrs/jan/desktop/X_Book.boo/programs/RCS/popupedit.c,v $
* Date: $Date: 1992/09/09 00:10:06 $
* Revision: $Revision: 1.1 $
*/
#include "copyright.h"
#include <stdio.h>
#include <Xm/PushB.h>
#include <Xm/Text.h>
#include <Xm/SelectioB.h>
#define MAX_ARGS 20
#if XmVersion == 1000
#define MOTIF_1_0
#endif
char Class_name[] ="XmPopupEditor";
Widget edit_dialog;
char *in_text = "Edit Me";
char *out_text = NULL;
#ifdef MOTIF_1_0
/* to fix a "feature" of a bulletin board in a dialog */
char transLine[] = "<Key>Return: newline()";
#endif
/*------------------------------------------------------
** Save
*/
void edit_saveCB(w, out_text, call_data)
Widget w;
char **out_text;
caddr_t call_data;
{
Widget scrolled_window, edit_text;
Arg args[MAX_ARGS];
/* reclaim space from the old string */
XtFree (*out_text);
/* find the scrolled window */
/* find the text widget */
scrolled_window = XmSelectionBoxGetChild (w,
XmDIALOG_WORK_AREA);
/* the text widget is the scrolled window's
work area child. Get the child from the
workWindow resource */
XtSetArg (args[0], XmNworkWindow, &edit_text);
XtGetValues (scrolled_window, args, 1);
/* get the text string */
*out_text = XmTextGetString(edit_text);
}
void edit_helpCB(w, client_data, call_data)
Widget w;
caddr_t client_data;
caddr_t call_data;
{
/* Should use the CreateHelp routine of earlier.
This is a pretty stupid method, guaranteed to
annoy users:
*/
fprintf(stderr, "help not implemented\n");
}
void edit_cancelCB(w, text, call_data)
Widget w;
char **text;
caddr_t call_data;
{
Widget shell = XtParent(edit_dialog);
*text = NULL;
printf("Edit dialog cancelled\n");
XtUnmanageChild(edit_dialog);
XtDestroyWidget(shell);
}
void
edit_quitCB(w, text, call_data)
Widget w;
char **text;
caddr_t call_data;
{
Widget shell = XtParent(edit_dialog);
printf("Quitting popup edit dialog.\n");
if (*text == NULL)
printf("no edited text saved\n");
else
printf("Edited text was:\n\n%s", *text);
XtUnmanageChild(w);
XtDestroyWidget(shell);
}
PopupEdit(parent, in_text, out_text)
Widget parent;
char *in_text;
char **out_text;
{
int n;
#ifdef MOTIF_1_0
XtTranslations transTable;
#endif
Arg args[MAX_ARGS];
Widget w;
Widget edit_text;
/* create the display window with
** a text widget as
** a popup window
*/
n = 0;
XtSetArg(args[n], XmNautoUnmanage, False); n++;
edit_dialog = XmCreatePromptDialog(parent,
"Popup Editor", args, n);
XtAddCallback (edit_dialog, XmNapplyCallback,
edit_saveCB, out_text);
XtAddCallback (edit_dialog, XmNcancelCallback,
edit_cancelCB, out_text);
XtAddCallback (edit_dialog, XmNhelpCallback,
edit_helpCB, NULL);
XtAddCallback (edit_dialog, XmNokCallback,
edit_quitCB, out_text);
n = 0;
XtSetArg(args[n], XmNscrollingPolicy,
XmAUTOMATIC); n++;
XtSetArg(args[n], XmNeditMode,
XmMULTI_LINE_EDIT); n++;
edit_text = XmCreateScrolledText(edit_dialog,
"edit text",
args, n);
XmTextSetString (edit_text, in_text);
XtManageChild(edit_text);
#ifdef MOTIF_1_0
/* edit_text is a child of a selection box
in a dialog.
A form is a subclass of a bulletin board which
"redefines" the return key in this context.
Fix the return key back to what it should be:
*/
transTable = XtParseTranslationTable(transLine);
XtOverrideTranslations(edit_text, transTable);
#endif
/* Show the apply button
*/
w = XmSelectionBoxGetChild (edit_dialog,
XmDIALOG_APPLY_BUTTON);
XtManageChild (w);
/* and lose the input area
*/
w = XmSelectionBoxGetChild (edit_dialog,
XmDIALOG_TEXT);
XtUnmanageChild (w);
XtManageChild(edit_dialog);
}
void
PushCB(w, client_data, call_data)
Widget w;
caddr_t client_data;
caddr_t call_data;
{
PopupEdit (w, in_text, &out_text);
}
main(argc, argv)
int argc;
char **argv;
{
Widget toplevel;
Widget button;
/* Initialize the intrinsics
with a toplevel widget */
toplevel = XtInitialize(NULL,
Class_name,
NULL,
0,
&argc, argv);
/* Create a widget, with the
toplevel as manager;
*/
button = XmCreatePushButton(toplevel,
"Edit Me",
NULL,
0);
XtAddCallback (button, XmNactivateCallback,
PushCB);
XtManageChild (button);
/* display all of the widgets */
XtRealizeWidget(toplevel);
/* enter the main processing loop */
XtMainLoop();
}