[comp.windows.x] Error in Athena widget documentation

gram@uctcs.uucp (Graham Wheeler) (10/02/90)

I have solved one of my two previous errors (reading text from the widget
itself). The other problem is still bugging me 8-). The Athena Widget
docs are also incorrect, it seems. THe problem I am refering to is
clearing the internal 'changes' flag of the AsciiSrc widget. I quote
from the docs: (p83)

***************************************************************************
5.6.2.3 Seeing if the Source has Changed

To find out if the text buffer in an AsciiSrc object has changed since the
last time it was saved with XawAsciiSave or queried use XawAsciiSourceChanged.

Boolean XawAsciiSourceChanged(w)
Widget w;

w	Specifies the AsciiSrc object

This function will return True if the source has changed since the last
time it was saved OR QUERIED. The internal change flag is reset whenever
the string is queried via XtGetValues or the buffer is saved via XawAsciiSave.

***************************************************************************

This is not true - the only time the flag is cleared is in calls to
XawAsciiSave. This means that if you load up a different file into a
AsciiText widget, and you modified but did not save the previous file,
the change flag will still be set - not very desirable behaviour.

As the changes flag is internal, I decided to try to hack this one,
and wrote the following function:

#include <X11/IntrinsicP.h>
#include <X11/Xaw/XawInit.h>
#include <X11/Xaw/AsciiSrcP.h>

void XawClearAsciiSrcFlag(w)
Widget w;
{
   printf("Flag was %s\n",((AsciiSrcObject)w)->ascii_src.changes ? "TRUE" : "FALSE");
   ((AsciiSrcObject)w)->ascii_src.changes = FALSE;
   printf("Flag is now %s\n",((AsciiSrcObject)w)->ascii_src.changes ? "TRUE" : "FALSE");
}

I then called this function from my editor program as follows:

/* Clear the Source-modified flag */
    printf("Before call: %s\n",FileChanged() ? "true" : "false");
    XawClearAsciiSrcFlag(EdSrcWidget);
    printf("After call: %s\n",FileChanged() ? "true" : "false");

The FileChanged routine is:

Boolean FileChanged()
{
  return (Boolean)XawAsciiSourceChanged(EdSrcWidget);
}

The EdSrcWidget is extracted from the AsciiText widget on an earlier
occasion. Now the going really gets weird! The stdout output that results
when I run this code is:

Before call: true
Flag was FALSE
Flag is now FALSE
After call: true

If you consider that the XawAsciiSourceChanged routine simply returns
the value of the flag (something like:

Boolean XawAsciiSourceChanged(w)
Widget w;
{
	return ((AsciiSrcObject)w)->ascii_src.changes;
}

) then the behaviour of this code seems inexplicable (to me, anyway). In
each case I pass the same widget through, but the Xaw routine sees the flag
as false whereas my hack sees it as true.

SOMEBODY OUT THERE, PLEASE HELP ME! Should I have myself committed?







Graham Wheeler		      |	"Don't bother me,
Data Network Architectures Lab|		I'm reading a `Crisis'!"
Dept. of Computer Science     | Internet: <gram.uctcs@f4.n494.z5.fidonet.org>
University of Cape Town       |     BANG: <...uunet!ddsw1!olsa99!uctcs!gram>

gram@uctcs.uucp (Graham Wheeler) (10/02/90)

The plot keeps thickening. I decided to modify the AsciiSrc.c distribution
file of the Athena widgets. What I did was add a line to XawAsciiSrcChanged
to print the address of the changes flag, so that I could compare it with
the address modified in my own XawClearAsciiFlag routine. When I compile
and link with a local copy of AsciiSrc.c, my program suddenly works!

Things are getting out of hand... I'm going to try to extract the library
copy of the object file and compare the two object files to see if that
sheds more light on the matter.


Graham Wheeler		      |	"Don't bother me,
Data Network Architectures Lab|		I'm reading a `Crisis'!"
Dept. of Computer Science     | Internet: <gram.uctcs@f4.n494.z5.fidonet.org>
University of Cape Town       |     BANG: <...uunet!ddsw1!olsa99!uctcs!gram>

gram@uctcs.uucp (Graham Wheeler) (10/02/90)

Well, I have solved the problem. I need to define ASCII_DISK before the
#include <AsciiSrcP.h>, otherwise the data structures are different and
so the flag addresses don't correspond. Sorry about the wasted bandwidth
on this one, but this may help others avoid falling in the same trap.
My original critique of the Athena widget documentation still holds,
however.

Graham Wheeler		      |	"Don't bother me,
Data Network Architectures Lab|		I'm reading a `Crisis'!"
Dept. of Computer Science     | Internet: <gram.uctcs@f4.n494.z5.fidonet.org>
University of Cape Town       |     BANG: <...uunet!ddsw1!olsa99!uctcs!gram>