home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
n
/
newmarch.zip
/
CROSSES.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-08
|
4KB
|
123 lines
/* Author: $Author: jan $
* File: $Source: /usr/usrs/jan/desktop/X_Book.boo/programs/RCS/crosses.c,v $
* Date: $Date: 1992/09/09 00:09:50 $
* Revision: $Revision: 1.1 $
*/
#include "copyright.h"
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
char Class_name[] = "Crosses";
XmString blank, nought, cross;
int turn; /* 0 = nought, 1 = cross */
/* Callback invoked on Arm action when a
** button is pressed
*/
void
pushed (w, client_d, call_d)
Widget w;
caddr_t client_d, call_d;
{ XmString xmstr;
char str[8];
Arg args[16];
int n;
/* find the current label in the button */
n = 0;
XtSetArg (args[n], XmNlabelString, &xmstr); n++;
XtGetValues (w, args, n);
/* change the label if it is a blank */
if (XmStringCompare (xmstr, blank))
{ n = 0;
if (turn == 0)
XtSetArg (args[n], XmNlabelString,
nought);
else XtSetArg (args[n], XmNlabelString,
cross);
n++;
XtSetValues (w, args, n);
/* update the turn */
turn = (turn + 1) % 2;
}
}
main (argc, argv)
int argc;
char **argv;
{
Widget toplevel, button, rowcol;
Arg args[16];
int i, n;
turn = 0; /* nought always starts */
/* set up the XmStrings */
blank = XmStringCreateLtoR (" ",
XmSTRING_DEFAULT_CHARSET);
/* 3 blank spaces */
nought = XmStringCreateLtoR ("0",
XmSTRING_DEFAULT_CHARSET);
cross = XmStringCreateLtoR ("X",
XmSTRING_DEFAULT_CHARSET);
/* Initialize the intrinsics
with a toplevel widget */
toplevel = XtInitialize (NULL, /* application
name */
Class_name, /* class
name */
NULL, /* options */
0, /* number of
options */
&argc, argv);
/* Create a Row Column with the
following resource values:
all children the same size (PACK_COLUMN)
3 columns (numColumns)
all labels aligned the same way (isAligned)
all labels centered (ALIGNMENT_CENTER)
*/
n = 0;
XtSetArg (args[n], XmNpacking, XmPACK_COLUMN); n++;
XtSetArg (args[n], XmNnumColumns, 3); n++;
XtSetArg (args[n], XmNisAligned, True); n++;
XtSetArg (args[n], XmNentryAlignment,
XmALIGNMENT_CENTER); n++;
rowcol = XmCreateRowColumn (
toplevel,/* parent */
"rowcol", /* name */
args, /* resource
arguments */
n); /* number of
args */
/* create 9 pushbutton children of rowcol with
blank labels.
all buttons are given the same name and
have the same callback, because we don't
need to distinguish them at all.
*/
for (i = 0; i < 9; i++)
{ n = 0;
XtSetArg (args[n], XmNlabelString, blank); n++;
button = XmCreatePushButton (rowcol,
"button", args, n);
XtAddCallback (button, XmNarmCallback,
pushed, NULL);
XtManageChild (button);
}
XtManageChild (rowcol);
/* display all of the widgets */
XtRealizeWidget (toplevel);
/* enter the main processing loop */
XtMainLoop ();
}