[comp.windows.x] textedit && scrolledwindow - Can they live together ?

yosi@taux01.UUCP (Yosi Ben-Harush) (11/01/89)

Hi!

I am working on a HP9000 using X11R3, X Intrinsics and HP X Widgets.

In my application I have a textedit widget whose parent is a scrolledwindow
widget.
I am writing in a textedit widget by using XwTextInsert(). The text is
written correctly, however the textedit does not scroll until I am writing at 
the end of the window.

The problem can be solved by setting the size of the textedit widget to be the
same as the size of the scrolledwindow, but then the scrollbar has no effect.

The scrolledwindow parent is a vpaned window.

How can I create a textedit inside a scrolledwindow so that the textedit will 
scroll and how can I also use the scrollbar ?

Thanks,
Yosi Ben-Harosh

The following is the source of a simple program which demonstrates my problem. 

/*
1. The widget tree is:
			TopLevel Shell
			      |
			    Vpaned
			      |
	+---------------------------------------------+
	|                                             |
  scrolledwindow                                 textedit
	|                                        (TextEdit2)
    textedit
   (TextEdit1)

2. When you type "a" into TextEdit2 the string "string A\n" is inserted in 
TextEdit1.

3. When you type "b" into TextEdit2 the string "string B\n" is inserted in
TextEdit1.

4. When you type "q" into TextEdit2 the program exits.

5. In order to understand the problem, you should type "ababab" into TextEdit2.
The following will display in TextEdit1:
First string
string A
string B
string A
string B
string A
string B

6. Now when you type "a" into TextEdit2 you will see that TextEdit1 did not
scroll.

7. compilation command:
	cc -o test test.c -lXw -lXt -lX11
*/

#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/keysym.h>
#include <Xw/Xw.h>
#include <Xw/TextEdit.h>
#include <Xw/SWindow.h>
#include <Xw/VPW.h>

Widget toplevel, wpane,  w2_scroll, TextEdit1, TextEdit2;

void EventHandler(w, eventdata, event)
Widget w;
XKeyEvent *event;
caddr_t eventdata;
{
	char buffer[40];
	int bufsize=40;
	KeySym keysym;
	XComposeStatus compose;

	XLookupString(event, buffer, bufsize, &keysym, &compose);
	switch (keysym) {
	case XK_a:
		XwTextInsert(TextEdit1,  "string A\n"); break;
	case XK_b:
		XwTextInsert(TextEdit1,  "string B\n"); break;
	case XK_q:
		exit(); break;
	}
}

void main (argc, argv)
int argc;
char **argv;
{
	Arg args[2];
	int n;

	toplevel = XtInitialize (argv[0], NULL, NULL, 0, &argc, argv);
	wpane = XtCreateManagedWidget("pWindow",XwvPanedWidgetClass,toplevel, 
		args, 0);

	n = 0;
	XtSetArg(args[n], XtNheight, 100);  n++;
	w2_scroll = XtCreateManagedWidget("sWindow",XwswindowWidgetClass, 
		wpane, args, n);

	n = 0;
#ifdef HEIGHT
	XtSetArg(args[n], XtNheight, 100);  n++;
#endif
	TextEdit1 = XtCreateManagedWidget("TextEdit1", XwtexteditWidgetClass,
	    w2_scroll, args, n);

	n = 0;
	XtSetArg(args[n], XtNheight, 200);  n++;
	TextEdit2 = XtCreateManagedWidget("TextEdit2", XwtexteditWidgetClass,
	    wpane, args, n);
	XtAddEventHandler(TextEdit2, 
	    KeyPressMask, FALSE, EventHandler, (caddr_t)NULL);

	XtRealizeWidget(toplevel);
	XwTextInsert(TextEdit1,  "First string \n");

	XtMainLoop();
}
-- 
	Yosi Ben-Harosh		yosi@taux01.nsc.com or yosi@nsc.nsc.com
National Semiconductor (Israel) P.O.B. 3007, Herzlia 46104, Israel
Tel. +972 52 522256  TWX: 33691, fax: +972-52-558322
34 48 E / 32 10 N			(My other cpu is a NS32532)