|
I wasn't sure you wanted the address of a data structure or the address
of a function so this does both.
#include "DwtWidget.h"
#define CS(c) (DwtLatin1String(c)) /* compound string converter */
#define MAKE_PUSH(parent,name,callback) \
DwtPushButton (parent, name, 0, 0, CS (name), callback, NULL)
static ApplicationShellWidget toplevel;
static MainWindowWidget main_widget;
static DialogWidget top_dialog;
void function_one (); /* forward dec's */
void function_two ();
typedef struct _magic /* a data structure which is */
{ /* common to all widgets */
char * data;
}
MagicRec, *Magic;
MagicRec my_magic; /* the global instance */
static void data_cb ();
static DwtCallback data_callback[] =
{
data_cb, NULL,
NULL
};
static void function_cb ();
static DwtCallback function_callback[] =
{
function_cb, NULL,
NULL
};
set_something (w, which, what)
Widget w;
char *which, *what;
{
Arg al[25];
int ac = 0;
XtSetArg (al[0], which, what);
XtSetValues (w, al, 1);
}
get_something (w, which, what)
Widget w;
char *which, *what;
{
Arg al[25];
int ac = 0;
XtSetArg (al[0], which, what);
XtGetValues (w, al, 1);
}
static Widget
build_dialog_box (parent)
Widget parent;
{
Widget d;
d = DwtDialogBox ( parent,
"dialog",
FALSE,
30, 100,
CS ("dialog title"),
DwtWorkarea,
NULL,
NULL);
XtManageChild (d);
XtManageChild (
DwtPushButton (d, "", 0, 0, CS ("Data one"), data_callback, NULL));
XtManageChild (
DwtPushButton (d, "", 0, 20, CS ("Data two"), data_callback, NULL));
function_callback[0].tag = function_one;
XtManageChild (
DwtPushButton (d, "", 200, 0, CS ("Function one"), function_callback, NULL));
function_callback[0].tag = function_two;
XtManageChild (
DwtPushButton (d, "", 200, 20, CS ("Function two"), function_callback, NULL));
return (d);
}
static void
data_cb (w, tag, reason)
Widget w;
caddr_t tag;
caddr_t reason;
{
Magic m = (Magic) tag; /* retrieve global data */
printf ("in push callback, tag = %s\n", m->data);
}
static void
function_cb (w, tag, reason)
Widget w;
caddr_t tag;
caddr_t reason;
{
VoidProc t = (VoidProc) tag; /* make into function */
(*t) ();
}
void
function_one ()
{
printf ("in function one\n");
}
void
function_two ()
{
printf ("in function two\n");
}
main (argc, argv)
int argc;
char **argv;
{
my_magic.data = "real magic"; /* init global data */
data_callback[0].tag = &my_magic; /* put pointer in tag of callbacks */
toplevel = XtInitialize("gt", "gt", NULL, 0, &argc, argv);
set_something (toplevel, XtNallowShellResize, "TRUE");
main_widget = DwtMainWindow (toplevel, "TESTING", 100, 100, 0, 0);
XtManageChild (main_widget);
top_dialog = build_dialog_box (main_widget);
XtRealizeWidget (toplevel);
XtMainLoop();
}
|