DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T x

⟦1ddfbb144⟧ TextFile

    Length: 5087 (0x13df)
    Types: TextFile
    Names: »xdialog.c«

Derivation

└─⟦8648bda34⟧ Bits:30007244 EUUGD5_II: X11R5
    └─⟦2ca9b63e1⟧ »./contrib-1/contrib-1.00« 
        └─⟦a8392fb20⟧ 
            └─⟦this⟧ »contrib/examples/OReilly/Vol4/ch12/xdialog.c« 

TextFile

/*
 * Copyright 1989 O'Reilly and Associates, Inc.
 * See ../Copyright for complete rights and liability information.
 */


/* 
 *  xdialog.c
 */

/*
 *  So that we can use fprintf:
 */
#include <stdio.h>

/* 
 * Standard Toolkit include files:
 */
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>

#include <X11/Shell.h>

/*
 * Public include files for widgets used in this file.
 */
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Box.h>
#include <X11/Xaw/Dialog.h>

/*
 * The popup shell ID is global because both dialog and pshell
 * are needed in the dialogDone callback, and both can't be
 * passed in without creating a structure.
 */
Widget pshell, pressme, quit;

/*
 * dialog button
 */
/*ARGSUSED*/
void PopupDialog(w, client_data, call_data)
Widget w;
XtPointer client_data;  /* cast to topLevel */
XtPointer call_data;
{
    Widget topLevel = (Widget) client_data;
    Position x, y;
    Dimension width, height;

    /*
     * get the coordinates of the middle of topLevel widget.
     */
    XtVaGetValues(topLevel, 
            XtNwidth, &width,
            XtNheight, &height,
            NULL);
    
    /*
     * translate coordinates in application top-level window
     * into coordinates from root window origin.
     */
    XtTranslateCoords(topLevel,                /* Widget */
            (Position) width/2,        /* x */
            (Position) height/2,       /* y */
            &x, &y);          /* coords on root window */

    /* move popup shell to this position (it's not visible yet) */
    XtVaSetValues(pshell, 
            XtNx, x,
            XtNy, y,
            NULL);
}

/*
 * dialog done button
 */
/*ARGSUSED*/
void DialogDone(w, client_data, call_data)
Widget w;
XtPointer client_data;  /* cast to dialog */
XtPointer call_data;  /* unused */
{
    Widget dialog = (Widget) client_data;
    String string;

    XtPopdown(pshell);

    XtSetSensitive(pressme, TRUE);

    /*
     * Changes to XawDialogGetValueString in R4
     */
    string = XawDialogGetValueString(dialog);

    printf("User typed: %s\n", string);
}

/*
 * quit button callback function
 */
/*ARGSUSED*/
void Quit(w, client_data, call_data)
Widget w;
XtPointer client_data, call_data;
{ 
    exit(0); 
}

/* Action for remapping Return */
void ReturnAction();

main(argc, argv)
int argc;
char **argv;
{
    XtAppContext app_context;
    Widget box, topLevel, dialog, dialogDone;
	XtTranslations trans;
	static XtActionsRec remap_return[] = {
		{"returnAction", ReturnAction, },
	};

    topLevel = XtVaAppInitialize(
        &app_context,       /* Application context */
        "XDialog",  /* application class name */
        NULL, 0,            /* command line option list */
        &argc, argv,        /* command line args */
        NULL,               /* for missing app-defaults file */
        NULL);              /* terminate varargs list */

    box = XtCreateManagedWidget(
        "box",  /* widget name */
        boxWidgetClass, /* widget class */
        topLevel,   /* parent widget*/
        NULL,   /* argument list*/
        0   /* arglist size */
        );

    quit = XtCreateManagedWidget(
        "quit", /* widget name */
        commandWidgetClass, /* widget class */
        box,    /* parent widget*/
        NULL,   /* argument list*/
        0   /* arglist size */
        );

    pressme = XtCreateManagedWidget(
        "pressme",  /* widget name   */
        commandWidgetClass, /* widget class */
        box,    /* parent widget*/
        NULL,   /* argument list*/
        0   /* arglist size */
        );

    pshell = XtCreatePopupShell(
            "pshell",
            transientShellWidgetClass,
            topLevel,
            NULL,
            0
            );

    dialog = XtCreateManagedWidget(
            "dialog",               /* widget name   */
            dialogWidgetClass,              /* widget class */
            pshell,                         /* parent widget*/
            NULL,                    /* argument list*/
            0           /* arglist size */
            );

    dialogDone = XtCreateManagedWidget(
            "dialogDone",           /* widget name   */
            commandWidgetClass,             /* widget class */
            dialog,                         /* parent widget*/
            NULL,               /* argument list*/
            0      /* arglist size */
            );

    XtAddCallback(quit, XtNcallback, Quit, 0);

    XtAddCallback(dialogDone, XtNcallback, DialogDone, dialog);

    XtAddCallback(pressme, XtNcallback, PopupDialog, topLevel);
    XtAddCallback(pressme, XtNcallback, XtCallbackExclusive, pshell);

   /*create widgets*/

	XtAppAddActions(app_context, remap_return, XtNumber(remap_return));
	trans = XtParseTranslationTable("#override <KeyPress>Return: returnAction()");
	XtOverrideTranslations(dialog, trans);


    XtRealizeWidget(topLevel);

    XtAppMainLoop(app_context);
}

static void ReturnAction(w, event, params, num_params)
Widget w;
XButtonEvent *event;
String *params; 
Cardinal *num_params;
{
        printf("action B executed\n");
}