rusty@BOSCO.BERKELEY.EDU (04/15/88)
I can't seem to get a 1 line ascii text widget to work. It mostly
works except when I use the return key then things get screwed up.
Try compiling the following program and then fiddle the scroll bar and
watch the value show up in the text window above. You can also type
something directly into the text window. Then type a return into the
text window and then fiddle the scroll bar again. Not so good. Am I
doing something wrong or is this a bug?
# include <X11/Intrinsic.h>
# include <X11/StringDefs.h>
# include <X11/AsciiText.h>
# include <X11/Scroll.h>
# include <X11/Form.h>
# include <stdio.h>
/* BEGIN BUG */
/*
* the following should have been in Text.h but
* it only appears in TextP.h
*/
typedef struct {
int firstPos;
int length;
char *ptr;
Atom format;
} XtTextBlock, *XtTextBlockPtr;
/* END BUG */
# define THUMB_WIDTH 50
# define TEXT_LEN 6
static Widget thumb_text;
static char thumb_text_buf[128];
static Arg thumb_scroll_args[] = {
{ XtNorientation, (XtArgVal) XtorientHorizontal },
{ XtNlength, (XtArgVal) THUMB_WIDTH },
{ XtNvertDistance, (XtArgVal) 0 }
};
static Arg thumb_text_args[] = {
{ XtNstring, (XtArgVal) thumb_text_buf },
{ XtNeditType, (XtArgVal) XttextEdit },
{ XtNlength, (XtArgVal) TEXT_LEN },
{ XtNwidth, (XtArgVal) THUMB_WIDTH },
};
static void
thumb_proc(w, closure, top)
Widget w;
caddr_t closure;
float top;
{
char buf[128];
XtTextPosition end;
XtTextBlock text;
end = strlen(thumb_text_buf);
sprintf(buf, "%d", (int) (top * 1000.0));
text.ptr = &buf[0];
text.length = strlen(buf);
text.firstPos = 0;
XtTextReplace(thumb_text, (XtTextPosition) 0, end, &text);
}
main(argc, argv)
int argc;
char **argv;
{
Widget top_shell;
Widget thumb_form;
Widget thumb_scroll;
Arg arg;
top_shell = XtInitialize(NULL, "xsetq", NULL, 0, &argc, argv );
if (argc != 1)
syntax();
thumb_form = XtCreateManagedWidget("form", formWidgetClass,
top_shell,
(ArgList) NULL, 0);
thumb_text = XtCreateManagedWidget("text", asciiStringWidgetClass,
thumb_form,
(ArgList) thumb_text_args,
XtNumber(thumb_text_args));
thumb_scroll = XtCreateManagedWidget("scrollbar", scrollbarWidgetClass,
thumb_form,
(ArgList) thumb_scroll_args,
XtNumber(thumb_scroll_args));
XtAddCallback(thumb_scroll, XtNthumbProc, thumb_proc, (caddr_t) NULL);
XtSetArg(arg, XtNfromVert, thumb_text);
XtSetValues(thumb_scroll, &arg, 1);
XtRealizeWidget(top_shell);
XtMainLoop();
}
syntax() {
fprintf(stderr, "usage: text_bug\n");
exit(1);
}swick@ATHENA.MIT.EDU (Ralph R. Swick) (04/22/88)
As currently implemented, the text widget is always willing to scroll vertically, regardless of it's height. I am planning to add a parameter to control this. If you type ^P or resize your shell vertically, you will see the text again.