ndd@romeo.cs.duke.edu (Ned D. Danieley) (02/02/89)
X11R2, Sun 3/280 running 3.5, X toolkit. I'm trying to convert some applications from X10 to X11, and have run into a problem. Under X10, I could register an event handler with a window: I would open a window, make a button box and some command buttons, and I could get events either through the command buttons or directly from the window (button clicks or key presses). However, as far as I can tell, there is no way to register an event handler with a window under X11. Am I missing something? I'm trying to avoid writing a special widget, because I have a fair amount of code that assumes a window. If I can't register an event handler, is there a way to use routines like XDrawLine, etc, with a widget? I've tried to get the associated window using XtWindow, but when I try to get the attributes of that window, I get an error. Ned Danieley (ndd@sunbar.mc.duke.edu) Basic Arrhythmia Laboratory Box 3140, Duke University Medical Center Durham, NC 27710 (919) 684-6807 or 684-6942
swick@ATHENA.MIT.EDU (Ralph R. Swick) (02/02/89)
Date: 1 Feb 89 21:33:23 GMT From: romeo!ndd@cs.duke.edu (Ned D. Danieley) I'm trying to convert some applications from X10 to X11, and have run into a problem. Under X10, I could register an event handler with a window: Wow! someone's still using the X10 prototype of Xt. I'm impressed :-) as far as I can tell, there is no way to register an event handler with a window under X11. Am I missing something? No, not really, but yes: In Xt the basic widget handle is an opaque identifier, not a window. You can register event handlers on this opaque identifier which will be invoked whenever the corresponding event(s) arrive for the associated window. You can recover the window id from the widget id with XtWindow(), as you have learned. I'm trying to avoid writing a special widget, because I have a fair amount of code that assumes a window. One thing that went by the wayside with the inversion of Xt into widget records was being able to turn an existing window into a widget. If that's what your existing code is doing, then you will have to do a little more work. You can create an instance of the Core widget class, giving you the smallest possible widget; you can then extract it's window id for use in the rest of your application. Eventually you will really want to learn how to write special-purpose widgets that fit your particular application requirements. Refer to the last section of the R3 "Athena Widgets" documentation for a very brief tutorial/example on writing a simple custom widget. The goal of the widget record and class record "hair" is to facilitate code re-use by allow special-purpose tailoring of existing (widget) code without duplicating everything in its entirety. That's what sub-classing is really all about. If I can't register an event handler, is there a way to use routines like XDrawLine, etc, with a widget? I've tried to get the associated window using XtWindow, but when I try to get the attributes of that window, I get an error. This sounds like a bug, but are you sure the widget has been realized before you use XtWindow()? Xt does an optimization to significantly reduce the number of server requests during application initialization by deferring window creation. This is a big win for servers on small (3 mip :-) machines! Applications are required to explicitly invoke window (hierarchy) creation at the appropriate time (i.e. after they have created "enough" of their widget hierarchy) with XtRealizeWidget. Xt will recursively realize all managed children of a realized widget, so if your XtWindow() is not returning a valid window id, then it is likely that someone forgot an explicit realize or manage request.