home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
x
/
xtici.zip
/
xtici
/
widgets
/
TriText.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-28
|
28KB
|
904 lines
/*
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc.
* All Rights Reserved
*
* This file is a component of an X Window System client which uses the Xcms
* Color Management System. TekColor is a trademark of Tektronix, Inc. The
* TekColor Editor is the subject of U.S. and foreign patents pending. The
* term "TekHVC" designates a particular color space that is the subject of
* U.S. Patent No. 4,985,853 (equivalent foreign patents pending).
* Permission is hereby granted to use, copy, modify, sell, and otherwise
* distribute this software and its documentation for the X Window System
* environment, for any purpose and without fee, provided that:
*
* 1. The code and documentation are only used to implement a
* TekColor Editor in an X Window System environment; and
* 2. This copyright and permission notice is reproduced in all copies
* of the code and in supporting documentation.
*
* Permission is granted to modify this code as required to allow it to
* be compiled on any host computer, provided that the functionality of
* the TekColor Editor is not modified in any way. A description of any
* modifications must be sent to Tektronix, Inc. Contact
* Tektronix Inc., P.O. Box 1000, Mail Station 60-850,
* Network Displays Division Engineering, Wilsonville, OR 97070.
*
* Tektronix makes no representation about the suitability of this software
* for any purpose. It is provided "as is" and with all faults.
*
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE,
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE.
*
* NAME
* TriText.c -- the TriText widget
*
* DESCRIPTION
* I needed to do my own layout and text management.
*
* HISTORY
*
* HISTORY END
*
*/
#ifndef LINT
static char *copy_notice = "Copyright 1991 Tektronix, Inc.";
#ifdef RCS_ID
static char *rcsid= "$Header: TriText.c,v 1.2 91/08/22 11:36:39 adamsc Exp $";
#endif /* RCS_ID */
#endif /* LINT */
#include <stdio.h>
#include <X11/IntrinsicP.h>
#include <X11/CoreP.h>
#include <X11/StringDefs.h>
#include <X11/Xmu/Misc.h>
#include <X11/Xaw/XawInit.h>
#include <X11/Xaw/AsciiTextP.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Label.h>
#include "TriTextP.h"
static XtResource resources[] = {
#define offset(field) XtOffset(TriTextWidget, tritext.field)
/* {name, class, type, size, offset, default_type, default_addr}, */
{ XtNblinkRate, XtCBlinkRate, XtRInt, sizeof(int),
offset(blink), XtRImmediate, (XtPointer)0 },
{ XtNlength, XtCLength, XtRInt, sizeof(int),
offset(length), XtRImmediate, (XtPointer)7 },
{ XtNlabelList, XtCLabelList, XtRLabelList, sizeof(String *),
offset(labels), XtRImmediate, (XtPointer)NULL},
{ XtNformat, XtCFormat, XtRString, sizeof(String),
offset(format), XtRImmediate, (XtPointer)NULL },
{ XtNfloatList, XtCFloatList, XtRFloatList, sizeof(XcmsFloat *),
offset(values), XtRImmediate, (XtPointer)NULL },
{ XtNactivateCallback, XtCActivateCallback, XtRCallback,
sizeof(XtCallbackList), offset(activate), XtRCallback, NULL },
{ XtNfocusCallback, XtCFocusCallback, XtRCallback,
sizeof(XtCallbackList), offset(gain), XtRCallback, NULL },
{ XtNlosingFocusCallback, XtCLosingFocusCallback, XtRCallback,
sizeof(XtCallbackList), offset(lose), XtRCallback, NULL },
{ XtNmodifyVerifyCallback, XtCModifyVerifyCallback, XtRCallback,
sizeof(XtCallbackList), offset(verify), XtRCallback, NULL },
#undef offset
};
/* forward declarations for the class struct */
static void ChangeManaged();
static void Destroy();
/* static void Focus(); */
static void Initialize();
/* static void LoseFocus(); */
static void Resize();
static Boolean SetValues();
static XtGeometryResult GeometryManager();
static XtGeometryResult QueryGeometry();
TriTextClassRec triTextClassRec = {
{ /* core_class fields */
/* superclass */ (WidgetClass) &compositeClassRec,
/* class_name */ "TriText",
/* widget_size */ sizeof(TriTextRec),
/* class_initialize */ XawInitializeWidgetSet,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ TRUE,
/* compress_enterleave */ FALSE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ NULL,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ NULL,
/* query_geometry */ QueryGeometry,
/* display_accelerator */ NULL,
/* extension */ NULL
},
{ /* composite fields */
/* geometry manager */ GeometryManager,
/* change managed */ ChangeManaged,
/* insert child */ XtInheritInsertChild,
/* delete child */ XtInheritDeleteChild,
/* extension */ NULL
},
{ /* tri-text fields */
/* extension */ NULL
},
};
WidgetClass triTextWidgetClass = (WidgetClass)&triTextClassRec;
/****************************************************************
*
* Private Procedures
*
****************************************************************/
/* forward declarations of utility functions */
static void CreateChildren();
static void NewValue();
/* static void Verify(); */
static char *warning1 = "Length of text must be positive";
static char *warning2 = "Blink rate must be non-negative";
/*
* Sometime in the future this geometry management could be simplified
* for now just use the box routines.
*
* Do a layout, either actually assigning positions, or just calculating size.
* Returns minimum width and height that will preserve the same layout.
*
*/
static void DoLayout(ttw, width, height, reply_width, reply_height, position)
TriTextWidget ttw;
Dimension width, height;
Dimension *reply_width, *reply_height; /* bounding box */
Boolean position; /* actually reposition the windows? */
{
Cardinal i;
Dimension w, h; /* Width and height needed for widget */
Dimension lw, lh; /* Width and height needed for current line */
Dimension bw, bh; /* Width and height needed for current widget */
register Widget widget; /* Current widget */
int num_mapped_children = 0;
/* TriText width and height */
w = 0;
h = 0;
/* Line width and height */
lh = 0;
lw = 0;
for (i = 0; i < ttw->composite.num_children; i++) {
widget = ttw->composite.children[i];
if (widget->core.managed) {
if (widget->core.mapped_when_managed) num_mapped_children++;
/* Compute widget width */
bw = widget->core.width + 2*widget->core.border_width;
if (lw + bw > width) {
if (lw != 0) {
/* At least one widget on this line, and
* can't fit any more. Start new line.
*/
AssignMax(w, lw);
h += lh;
lh = 0;
lw = 0;
} else if (!position) {
/* too narrow for this widget; we'll assume we can grow */
DoLayout(ttw, lw + bw, height, reply_width,
reply_height, position);
return;
}
}
if (position && (lw != widget->core.x || h != widget->core.y)) {
/* It would be nice to use window gravity, but there isn't
* sufficient fine-grain control to nicely handle all
* situations (e.g. when only the height changes --
* a common case). Explicit unmapping is a cheap hack
* to speed things up & avoid the visual jitter as
* things slide around.
*
* %%% perhaps there should be a client resource to
* control this. If so, we'll have to optimize to
* perform the moves from the correct end so we don't
* force extra exposures as children occlude each other.
*/
if (XtIsRealized(widget) && widget->core.mapped_when_managed)
XUnmapWindow( XtDisplay(widget), XtWindow(widget) );
XtMoveWidget(widget, (int)lw, (int)h);
}
lw += bw;
bh = widget->core.height + 2*widget->core.border_width;
AssignMax(lh, bh);
} /* if managed */
} /* for */
if (position && XtIsRealized((Widget)ttw)) {
if (ttw->composite.num_children == num_mapped_children)
XMapSubwindows( XtDisplay((Widget)ttw), XtWindow((Widget)ttw) );
else {
int i = ttw->composite.num_children;
register Widget *childP = ttw->composite.children;
for (; i > 0; childP++, i--)
if (XtIsRealized(*childP) && XtIsManaged(*childP) &&
(*childP)->core.mapped_when_managed)
XtMapWidget(*childP);
}
}
/* Finish off last line */
if (lw != 0) {
AssignMax(w, lw);
h += lh;
}
*reply_width = Max(w, 1);
*reply_height = Max(h, 1);
}
/*
*
* Calculate preferred size, given constraining box, caching it in the widget.
*
*/
static XtGeometryResult QueryGeometry(widget, constraint, preferred)
Widget widget;
XtWidgetGeometry *constraint, *preferred;
{
TriTextWidget w = (TriTextWidget)widget;
Dimension width /*, height */;
Dimension preferred_width = w->tritext.preferred_width;
Dimension preferred_height = w->tritext.preferred_height;
constraint->request_mode &= CWWidth | CWHeight;
if (constraint->request_mode == 0)
/* parent isn't going to change w or h, so nothing to re-compute */
return XtGeometryYes;
if (constraint->request_mode == w->tritext.last_query_mode &&
(!(constraint->request_mode & CWWidth) ||
constraint->width == w->tritext.last_query_width) &&
(!(constraint->request_mode & CWHeight) ||
constraint->height == w->tritext.last_query_height)) {
/* same query; current preferences are still valid */
preferred->request_mode = CWWidth | CWHeight;
preferred->width = preferred_width;
preferred->height = preferred_height;
if (constraint->request_mode == (CWWidth | CWHeight) &&
constraint->width == preferred_width &&
constraint->height == preferred_height)
return XtGeometryYes;
else
return XtGeometryAlmost;
}
/* else gotta do it the long way...
I have a preference for tall and narrow, so if my width is
constrained, I'll accept it; otherwise, I'll compute the minimum
width that will fit me within the height constraint */
w->tritext.last_query_mode = constraint->request_mode;
w->tritext.last_query_width = constraint->width;
w->tritext.last_query_height= constraint->height;
if (constraint->request_mode & CWWidth)
width = constraint->width;
else { /* if (constraint->request_mode & CWHeight) */
/* let's see if I can become any narrower */
width = 0;
constraint->width = 65535;
}
/* height is currently ignored by DoLayout.
height = (constraint->request_mode & CWHeight) ? constraint->height
: *preferred_height;
*/
DoLayout(w, width, (Dimension)0, &preferred_width, &preferred_height,
FALSE);
if (constraint->request_mode & CWHeight &&
preferred_height > constraint->height) {
/* find minimum width for this height */
if (preferred_width > constraint->width) {
/* punt; over-constrained */
} else {
width = preferred_width;
do { /* find some width big enough to stay within this height */
width *= 2;
if (width > constraint->width)
width = constraint->width;
DoLayout(w, width, (Dimension)0,
&preferred_width, &preferred_height, FALSE);
} while (preferred_height > constraint->height &&
width < constraint->width);
if (width != constraint->width) {
do { /* find minimum width */
width = preferred_width;
DoLayout(w, preferred_width - 1, (Dimension)0,
&preferred_width, &preferred_height, FALSE);
} while (preferred_height < constraint->height);
/* one last time */
DoLayout(w, width, (Dimension)0,
&preferred_width, &preferred_height, FALSE);
}
}
}
preferred->request_mode = CWWidth | CWHeight;
preferred->width = w->tritext.preferred_width = preferred_width;
preferred->height = w->tritext.preferred_height = preferred_height;
if (constraint->request_mode == (CWWidth|CWHeight)
&& constraint->width == preferred_width
&& constraint->height == preferred_height)
return XtGeometryYes;
else
return XtGeometryAlmost;
}
/*
*
* Actually layout the widget
*
*/
static void Resize(w)
Widget w;
{
Dimension junk;
DoLayout((TriTextWidget)w, w->core.width, w->core.height, &junk, &junk,
TRUE);
} /* Resize */
/*
*
* Try to do a new layout within the current width and height;
* if that fails try to resize and do it within the size returned
* by QueryGeometry.
*
* TryNewLayout just says if it's possible, and doesn't actually move the kids
*/
static Boolean TryNewLayout(ttw)
TriTextWidget ttw;
{
Dimension preferred_width, preferred_height;
Dimension proposed_width, proposed_height;
int iterations;
DoLayout(ttw, ttw->core.width, ttw->core.height,
&preferred_width, &preferred_height, FALSE);
/* at this point, preferred_width is guaranteed to not be greater
than ttw->core.width unless some child is larger, so there's no
point in re-computing another layout */
if ((ttw->core.width == preferred_width) &&
(ttw->core.height == preferred_height)) {
/* Same size */
return (TRUE);
}
/* let's see if our parent will go for a new size. */
iterations = 0;
proposed_width = preferred_width;
proposed_height = preferred_height;
do {
switch (XtMakeResizeRequest((Widget)ttw,proposed_width,proposed_height,
&proposed_width, &proposed_height))
{
case XtGeometryYes:
return (TRUE);
case XtGeometryNo:
if (iterations > 0)
/* protect from malicious parents who change their minds */
DoLayout(ttw, ttw->core.width, ttw->core.height,
&preferred_width, &preferred_height, FALSE);
if ((preferred_width <= ttw->core.width) &&
(preferred_height <= ttw->core.height))
return (TRUE);
else
return (FALSE);
case XtGeometryAlmost:
if (proposed_height >= preferred_height &&
proposed_width >= preferred_width) {
/*
* Take it, and assume the parent knows what it is doing.
*
* The parent must accept this since it was returned in
* almost.
*
*/
(void) XtMakeResizeRequest( (Widget)ttw,
proposed_width, proposed_height,
&proposed_width, &proposed_height);
return(TRUE);
}
else if (proposed_width != preferred_width) {
/* recalc bounding box; height might change */
DoLayout(ttw, proposed_width, (Dimension)0,
&preferred_width, &preferred_height, FALSE);
proposed_height = preferred_height;
}
else { /* proposed_height != preferred_height */
XtWidgetGeometry constraints, reply;
constraints.request_mode = CWHeight;
constraints.height = proposed_height;
(void)QueryGeometry((Widget)ttw, &constraints, &reply);
proposed_width = preferred_width;
}
}
iterations++;
} while (iterations < 10);
return (FALSE);
}
/*
*
* Geometry Manager
*
* 'reply' is unused; we say only yeay or nay, never almost.
*
*/
/*ARGSUSED*/
static XtGeometryResult GeometryManager(w, request, reply)
Widget w;
XtWidgetGeometry *request;
XtWidgetGeometry *reply; /* RETURN */
{
Dimension width, height, borderWidth;
TriTextWidget ttw;
/* Position request always denied */
if ((request->request_mode & CWX && request->x != w->core.x) ||
(request->request_mode & CWY && request->y != w->core.y))
return (XtGeometryNo);
/* Size changes must see if the new size can be accomodated */
if (request->request_mode & (CWWidth | CWHeight | CWBorderWidth)) {
/* Make all three fields in the request valid */
if ((request->request_mode & CWWidth) == 0)
request->width = w->core.width;
if ((request->request_mode & CWHeight) == 0)
request->height = w->core.height;
if ((request->request_mode & CWBorderWidth) == 0)
request->border_width = w->core.border_width;
/* Save current size and set to new size */
width = w->core.width;
height = w->core.height;
borderWidth = w->core.border_width;
w->core.width = request->width;
w->core.height = request->height;
w->core.border_width = request->border_width;
/* Decide if new layout works: (1) new widget is smaller,
(2) new widget fits in existing TriText, (3) TriText can be
expanded to allow new widget to fit */
ttw = (TriTextWidget) w->core.parent;
if (TryNewLayout(ttw)) {
/* Fits in existing or new space, relayout */
(*XtClass((Widget)ttw)->core_class.resize)((Widget)ttw);
return (XtGeometryYes);
} else {
/* Cannot satisfy request, change back to original geometry */
w->core.width = width;
w->core.height = height;
w->core.border_width = borderWidth;
return (XtGeometryNo);
}
} /* if any size changes requested */
/* Any stacking changes don't make a difference, so allow if that's all */
return (XtGeometryYes);
}
static void ChangeManaged(w)
Widget w;
{
/* Reconfigure the widget */
(void) TryNewLayout((TriTextWidget)w);
Resize(w);
}
/*
* A superclass for this class could allow any number of rows, just not 3.
* I don't want to deal with additional complexity, fix this if you need it.
*/
#define RowCt 3
static void Warning(widget, message)
Widget widget;
char *message;
{
/* R4 says use XtAppWarningMsg but no information on how to set
* the parameters.
*/
if (!widget)
XtWarning(message);
else
XtAppWarning(XtWidgetToApplicationContext(widget), message);
}
static void Destroy(tri)
TriTextWidget tri;
{
int i;
for (i = 0; i < RowCt; i++) {
if (tri->tritext.plabel[i])
XtFree(tri->tritext.plabel[i]);
}
if (tri->tritext.pformat)
XtFree(tri->tritext.pformat);
}
/* ARGSUSED */
static void Initialize(req, new)
TriTextWidget req, new;
{
int i;
int len;
/* Validate input resources */
if (new->tritext.length <= 0) {
Warning(new, warning1);
new->tritext.length = 7;
}
if (new->tritext.blink < 0) { /* 0 is valid, means no buttons */
Warning(new, warning2);
new->tritext.blink = 0;
}
if (new->tritext.labels) {
for (i = 0; i < RowCt; i++) {
len = strlen(new->tritext.labels[i]) + 1;
new->tritext.plabel[i] = XtMalloc(len);
strcpy(new->tritext.plabel[i], new->tritext.labels[i]);
}
} else {
for (i = 0; i < RowCt; i++)
new->tritext.plabel[i] = NULL;
}
if (new->tritext.format) {
len = strlen(new->tritext.format) + 1;
new->tritext.pformat = (String)XtMalloc(len);
strcpy(new->tritext.pformat, new->tritext.format);
} else {
len = 3;
new->tritext.pformat = (String)XtMalloc(len);
strcpy(new->tritext.pformat, "%f");
}
/* create all of the widgets */
CreateChildren(new);
}
#define BUFLEN 512
/* Most values are passed on to one child or another */
/* ARGSUSED */
static Boolean SetValues(cur, req, new)
TriTextWidget cur, req, new;
{
Arg args[5];
int cnt = 0;
int i;
char buf[BUFLEN]; /* danger, this could overflow */
if (new->tritext.length <= 0) {
Warning(new, warning1);
new->tritext.length = cur->tritext.length;
} else if (new->tritext.length != cur->tritext.length) {
XtSetArg(args[cnt], XtNlength, new->tritext.length); cnt++;
}
if (new->tritext.blink < 0) {
Warning(new, warning2);
new->tritext.blink = cur->tritext.blink;
} else if (new->tritext.blink != cur->tritext.blink) {
XtSetArg(args[cnt], XtNblinkRate, new->tritext.blink); cnt++;
}
/* TODO: probably should allow this */
if (new->tritext.labels != cur->tritext.labels)
Warning(new, "Cannot change labels");
if (new->tritext.format != cur->tritext.format)
Warning(new, "Cannot change format");
if (cnt > 0) {
for (i = 0; i < RowCt; i++)
XtSetValues(new->tritext.wlist[i+RowCt], args, cnt);
}
if (new->tritext.values) {
for (i = 0; i < RowCt; i++) {
/* set the string in each ascii text widget */
bzero (buf, BUFLEN);
sprintf(buf, new->tritext.pformat, new->tritext.values[i]);
XtSetArg (args[0], XtNstring, buf);
XtSetValues (new->tritext.wlist[i+RowCt], args, 1);
}
}
/* possibly set some new values */
return(False); /* there is nothing for this widget to redraw */
}
static void CreateChildren(tri)
TriTextWidget tri;
{
int cnt;
Widget form;
WidgetList wlist = tri->tritext.wlist;
Arg args[15];
XcmsFloat val;
char buf[BUFLEN]; /* danger, this could overflow */
cnt = 0;
XtSetArg(args[cnt], XtNborderWidth, 0); cnt++;
form = XtCreateManagedWidget ("form", formWidgetClass, (Widget)tri,
args, cnt);
tri->tritext.form = form;
/* this is label 1 in the upper left hand corner */
cnt = 0;
if (tri->tritext.plabel[0]) {
XtSetArg(args[cnt], XtNlabel, tri->tritext.plabel[0]); cnt++;
}
wlist[0] = XtCreateWidget("item1", labelWidgetClass, form, args, cnt);
/* this is label 2 just below label 1 */
cnt = 0;
if (tri->tritext.plabel[1]) {
XtSetArg(args[cnt], XtNlabel, tri->tritext.plabel[1]); cnt++;
}
XtSetArg(args[cnt], XtNfromVert, wlist[0]); cnt++;
wlist[1] = XtCreateWidget("item2", labelWidgetClass, form, args, cnt);
/* this is label 3 just below label 2 */
cnt = 0;
if (tri->tritext.plabel[2]) {
XtSetArg(args[cnt], XtNlabel, tri->tritext.plabel[2]); cnt++;
}
XtSetArg(args[cnt], XtNfromVert, wlist[1]); cnt++;
wlist[2] = XtCreateWidget("item3", labelWidgetClass, form, args, cnt);
/* this is text widget 1 just to the right of label 1 */
cnt = 0;
if (tri->tritext.length > 0) {
XtSetArg(args[cnt], XtNlength, tri->tritext.length); cnt++;
}
if (tri->tritext.values)
val = tri->tritext.values[0];
else
val = 0.0;
bzero (buf, BUFLEN);
sprintf(buf, tri->tritext.pformat, val);
XtSetArg(args[cnt], XtNstring, buf); cnt++;
XtSetArg(args[cnt], XtNtype, XawAsciiString); cnt++;
XtSetArg(args[cnt], XtNeditType, XawtextEdit); cnt++;
XtSetArg(args[cnt], XtNuseStringInPlace, False); cnt++;
XtSetArg(args[cnt], XtNresize, XawtextResizeBoth); cnt++;
XtSetArg(args[cnt], XtNfromHoriz, wlist[0]); cnt++;
wlist[3] = XtCreateWidget("text1", asciiTextWidgetClass, form, args, cnt);
XtAddCallback (XawTextGetSource(wlist[3]), XtNcallback, NewValue,
(XtPointer)RowCt);
/* this is text widget 2 just to the right of label 2 */
/* Note the repition of the first 4 args from above */
cnt = 0;
if (tri->tritext.length > 0) {
XtSetArg(args[cnt], XtNlength, tri->tritext.length); cnt++;
}
if (tri->tritext.values)
val = tri->tritext.values[1];
else
val = 0.0;
bzero (buf, BUFLEN);
sprintf(buf, tri->tritext.pformat, val);
XtSetArg(args[cnt], XtNstring, buf); cnt++;
XtSetArg(args[cnt], XtNeditType, XawtextEdit); cnt++;
XtSetArg(args[cnt], XtNuseStringInPlace, False); cnt++;
XtSetArg(args[cnt], XtNresize, XawtextResizeBoth); cnt++;
XtSetArg(args[cnt], XtNfromVert, wlist[3]); cnt++;
XtSetArg(args[cnt], XtNfromHoriz, wlist[1]); cnt++;
wlist[4] = XtCreateWidget("text2", asciiTextWidgetClass, form, args, cnt);
XtAddCallback (XawTextGetSource(wlist[4]), XtNcallback, NewValue,
(XtPointer)(RowCt + 1));
/* this is text widget 3 just to the right of label 3 */
/* Note the repitition of the first 4 args from above */
cnt = 0;
if (tri->tritext.length > 0) {
XtSetArg(args[cnt], XtNlength, tri->tritext.length); cnt++;
}
if (tri->tritext.values)
val = tri->tritext.values[2];
else
val = 0.0;
bzero (buf, BUFLEN);
sprintf(buf, tri->tritext.pformat, val);
XtSetArg(args[cnt], XtNstring, buf); cnt++;
XtSetArg(args[cnt], XtNeditType, XawtextEdit); cnt++;
XtSetArg(args[cnt], XtNuseStringInPlace, False); cnt++;
XtSetArg(args[cnt], XtNresize, XawtextResizeBoth); cnt++;
XtSetArg(args[cnt], XtNfromVert, wlist[4]); cnt++;
XtSetArg(args[cnt], XtNfromHoriz, wlist[2]); cnt++;
wlist[5] = XtCreateWidget("text3", asciiTextWidgetClass, form, args, cnt);
XtAddCallback (XawTextGetSource(wlist[5]), XtNcallback, NewValue,
(XtPointer)(RowCt + 2));
XtManageChildren(wlist, TriTextChildCt);
tri->tritext.numchildren = TriTextChildCt;
/* may need to set the translations on the text widgets. */
/* mytranslations = XtParseTranslationTable(myTranslations);
* XtOverrideTranslations(wlist[3], mytranslations);
* XtOverrideTranslations(wlist[4], mytranslations);
* XtOverrideTranslations(wlist[5], mytranslations);
*/
}
/*
* Callback for focus change; just record which widget is changing,
* then pass through.
*/
/* static void Focus(w, which, call)
* Widget w;
* int which;
* TriCallbackStruct *call;
* {
* TriCallbackStruct tmp;
*
* /* value is not valid for this callback */
/* tmp.value = -1.0;
* tmp.reason = call->reason;
* tmp.event = call->event;
* tmp.index = which - RowCt;
*
* XtCallCallbacks(w, XtNfocusCallback, &tmp);
* }
*
/*
* Callback for focus change; just record which widget is changing,
* then pass through.
*/
/* static void LoseFocus(w, which, call)
* Widget w;
* int which;
* TriCallbackStruct *call;
* {
* TriCallbackStruct tmp;
*
* /* value is not valid for this callback */
/* tmp.value = -1.0;
* tmp.reason = call->reason;
* tmp.event = call->event;
* tmp.index = which - RowCt;
*
* XtCallCallbacks(w, XtNlosingFocusCallback, tmp);
* }
*/
/*
* This callback sets the widget which was modified.
* The change is not effected until the cursor leaves the window.
*/
/* ARGSUSED */
static void NewValue(w, which, call)
Widget w;
int which;
XtPointer call;
{
/* Arg args[1]; */
/* String new; */
TriTextWidget tri = GetTriTextWidget (w);
TriCallbackStruct tmp;
/* double atof(); */
if (!tri)
return;
tmp.reason = CR_ACTIVATE;
tmp.event = NULL;
tmp.index = which - RowCt;
tmp.value = -1.0; /* For now use an illegal value */
/* XtSetArg (args[0], XtNstring, &new); */
/* XtGetValues (w, args, 1); */
/* tmp.value = atof(new); */
XtCallCallbacks((Widget)tri, XtNactivateCallback, &tmp);
/* May want to adjust text widget values based on return value */
}
/*
* Callback for text verify; just pass this through back to the application
*/
/* static void Verify(w, which, call)
* Widget w;
* int which;
* ScaleCallbackStruct *call;
* {
* TriTextWidget tri = (TriTextWidget)XtParent(w);
*
* XtCallCallbacks(tri, XtNmodifyVerifyCallback, call);
* }
*/
void TriTextGetList(tri, list)
TriTextWidget tri;
XcmsFloat *list;
{
Arg arg;
int i;
char *new;
double atof();
for (i = 0; i < RowCt; i++) {
XtSetArg (arg, XtNstring, (XtPointer)&new);
XtGetValues (tri->tritext.wlist[i+RowCt], &arg, 1);
list[i] = atof(new);
}
}
void TriTextSetList(tri, list)
TriTextWidget tri;
XcmsFloat *list;
{
Arg arg;
int i;
char buf[BUFLEN];
for (i = 0; i < RowCt; i++) {
bzero (buf, BUFLEN);
sprintf(buf, tri->tritext.pformat, list[i]);
XtSetArg (arg, XtNstring, buf);
XtSetValues(tri->tritext.wlist[i+RowCt], &arg, 1);
}
}
TriTextWidget GetTriTextWidget(wid)
Widget wid;
{
if (!wid || IsTriText(wid))
return ((TriTextWidget)wid);
return (GetTriTextWidget(XtParent(wid)));
}