#ifndef lint
static char Xrcsid[] = "$XConsortium:
xfontsel.c,v 1.16 89/12/12 14:10:48 rws
Exp $";
#endif
...
#include <X11/Xaw/Viewport.h>
#include <X11/Xmu/Atoms.h>
/*
* For the ToolTalk demonstration, add the
* following line to include
* the ToolTalk header file:
*/
#include <desktop/tt_c.h>
/* ToolTalk header file */
#define MIN_APP_DEFAULTS_VERSION 1
...
void SetCurrentFont();
Boolean IsXLFDFontName();
/*
* For the ToolTalk demonstration, add the
* following lines to tell
* Xfontsel how to handle a ToolTalk message:
*/
void dieFromToolTalkError();
/* Fail if error occurs */
void processToolTalkMessage();
/* Process ToolTalk message */
void ReplyToMessage();
/* Reply to ToolTalk message */
Tt_message replymsg;
typedef void (*XtProc)();
...
int matchingFontCount;
static Boolean anyDisabled = False;
Widget ownButton;
/*
* For the ToolTalk demonstration, add the
* next line to add
* the apply button to change the font:
*/
Widget applyButton;
/* Add apply button */
Widget fieldBox;
/*
* For the ToolTalk demonstration, add
* the next line to add
* a command box to make the font change:
*/
Widget commandBox;
/* Make commandBox global */
Widget countLabel;
...
void main(argc, argv)
unsigned int argc;
char **argv;
{
Widget topLevel, pane;
/*
* For the ToolTalk demonstration,
* add the following lines:
*/
int ttmark, ttfd;
/* ToolTalk mark, ToolTalk file descriptor */
char *procid;
/* Process identifier */
Tt_status ttrc;
/* ToolTalk status */
topLevel = XtInitialize( NULL,
"XFontSel", options, XtNumber(options),
&argc, argv );
...
pane = XtCreateManagedWidget("pane"
,panedWidgetClass,topLevel,NZ);
{
/*
* For the ToolTalk demonstration,
* make the command box widget
* global; change the line
* Widget commandBox,
* fieldBox, currentFontName, viewPort;
* as follows:
*/
Widget
/* commandBox, fieldBox, currentFontName,*/ viewPort;
commandBox = XtCreateManagedWidget("commandBox
",formWidgetClass,pane,NZ);
{
...
ownButton =
XtCreateManagedWidget("ownButton"
,toggleWidgetClass,commandBox,NZ);
/*
* For the ToolTalk demonstration, add the
* following lines to create
* an apply button for the font change:
*/
applyButton =
XtVaCreateManagedWidget("applyButton",
commandWidgetClass,
commandBox,
XtNlabel, "apply",
XtNfromHoriz, ownButton,
XtNleft, XtChainLeft,
XtNright, XtChainLeft,
0);
countLabel =
XtCreateManagedWidget("countLabel"
,labelWidgetClass,commandBox,NZ);
XtAddCallback(quitButton, XtNcallback, Quit,
NULL);
XtAddCallback(ownButton,XtNcallback,
OwnSelection,(XtPointer)True);
/*
* For the ToolTalk demonstration, add the
* following line to notify
* Xedit when the apply button has been pressed:
*/
XtAddCallback(applyButton,
XtNcallback,ReplyToMessage, NULL);
}
fieldBox = XtCreateManagedWidget("fieldBox",
boxWidgetClass, pane, NZ);
...
{
int f;
for (f = 0; f < FIELD_COUNT; f++)
currentFont.value_index[f] = -1;
}
/*
* For the ToolTalk demonstration,
* add the following lines
* to make the top of stack the ToolTalk
* session and set
* it to be the default session.
*/
ttmark = tt_mark();
ttrc = tt_default_session_set(
/* set the default session .. */
tt_X_session(
/* .. to the X session for .. */
DisplayString(
/* .. the X server displaying ..*/
XtDisplay(top))));
/* .. our top window... */
/*
* Fail if no default session
*/
dieFromToolTalkError("tt_default_session_set"
,ttrc);
procid = tt_open();
/*
* Fail if no proces identifier
*/
dieFromToolTalkError("tt_open"
,tt_ptr_error(procid));
ttfd = tt_fd();
/*
* Fail if no ToolTalk file descriptor
*/
dieFromToolTalkError("tt_fd"
,tt_int_error(ttfd));
ttrc = tt_ptype_declare("xfontsel");
/*
* Fail if ptype not declared
*/
dieFromToolTalkError("tt_ptype_declare"
,tt_int_error(ttfd));
ttrc = tt_session_join(tt_default_session());
/*
* Fail if unable to join session
*/
dieFromToolTalkError("tt_session_join",ttrc);
/*
* Add input
*/
XtAddInput(ttfd, (XtPointer)XtInputReadMask,
processToolTalkMessage, 0);
XtAppMainLoop(appCtx);
tt_close();
/* End ToolTalk session */
tt_release(ttmark);
/* Free space */
}
...
Boolean field_bits[FIELD_COUNT];
int max_field;
if (*fontName == DELIM) field++;
/*
*
* For the ToolTalk demonstration,
* use the standard routines
* instead of BSD; change the line
* bzero( field_bits, sizeof(field_bits) );
* to read as follows:
*
*/
memset( field_bits, 0, sizeof(field_bits) );
if (Matches(pattern, fontName++, field_bits,
&max_field)) {
...
XtDisownSelection(w, XA_PRIMARY, time);
XtSetSensitive(currentFontName, False);
}
/*
* For the ToolTalk Demonstration,
* add the following lines:
*/
}
void dieFromToolTalkError(procname, errid) /* Fail if error occurs */
char *procname;
/* Process name */
Tt_status errid;
/* Error identifier */
{
/*
* Don't die on warnings or TT_OK.
*/
if (tt_is_err(errid)) {
fprintf(stderr,"%s returned ToolTalk error:
%s\n",
procname, tt_status_message(errid));
exit(1);
}
}
void processToolTalkMessage()
/* Process message */
{
int ttmark;
/* ToolTalk mark */
Tt_message incoming;
/* Incoming message */
ttmark = tt_mark();
incoming = tt_message_receive();
/* Receive message */
/*
* It's possible that the file descriptor
* may become active but
* there's not actually a ToolTalk message
* for us.
*/
if (incoming == 0) return;
if (tt_is_err(tt_ptr_error(incoming))) {
dieFromToolTalkError("tt_message_receive",
tt_ptr_error(incoming));
}
if (0==strcmp(tt_message_op(incoming),"
GetFontName")) {
/*
* This is the message we expected.
* If we're already
* busy, reject it. Otherwise activate
* the "apply" button.
*/
if (replymsg) {
tt_message_reject(incoming);
tt_message_destroy(incoming);
tt_release(ttmark);
return;
}
XtVaSetValues(applyButton, XtNsensitive,
TRUE, 0);
replymsg = incoming;
tt_release(ttmark);
return;
}
/*
* This is not a message we recognize.
* If it's a request, or a notice that
* caused us to start, fail it.
*/
if (tt_message_class(incoming) == TT_REQUEST ||
tt_message_status(incoming) ==
TT_WRN_START_MESSAGE) {
tt_message_fail(incoming);
}
tt_message_destroy(incoming);
tt_release(ttmark);
}
/*
* Called when the Apply button is pressed.
* Replies to the outstanding
* message and turn off the Apply button.
*/
/* ARGSUSED */
void ReplyToMessage(w, msg, wdata)
Widget w;
caddr_t msg;
caddr_t wdata;
{
tt_message_arg_val_set(replymsg, 0,
currentFontNameString);
tt_message_reply(replymsg);
tt_message_destroy(replymsg);
replymsg = 0;
XtVaSetValues(applyButton, XtNsensitive, FALSE,
0);
}
|