Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!EXPO.LCS.MIT.EDU!kit From: kit@EXPO.LCS.MIT.EDU (Chris D. Peterson) Newsgroups: comp.windows.x Subject: Re: Adding event handlers to windows Message-ID: <9006121416.AA07750@expo.lcs.mit.edu> Date: 12 Jun 90 14:16:54 GMT References: <1445.9006120916@kheops.cmi.no> Sender: root@athena.mit.edu (Wizard A. Root) Organization: The Internet Lines: 47 > Is there a way to add Xt R4 event handlers to windows and not just widgets? > I would rather avoid open up the XtAppMainLoop() and dispatch non-widget > events myself if possible. I'm using properties to share data among loosely > coupled processes, registering the property in the root window which is not > a widget. Would it possible to convert a window to widget using > XtWindowToWidget() and than using the XtAddEventHandler() mechanism. The is no "officially" supported way to do this, but I have been thinking about this problem, and believe that I have a hack that should do the trick. Please keep in mind that I have not tried this, and am not sure it will work, but it does seem reasonable. The trick is that in order for Xt to be able to process events for the window it must have a widget associated with it. If we can figure out a way to assign a widget structure to a window that already exists, then we should be just fine. What I suggest is that you instanciate a widget of class "widgetClass" this is a Core widget. Rather than realizing this widget you should just assign the window in question to its "window" field (This is the kludgey part). Now since this window knows nothing about Xt Geometry management, you cannot manage it, and all the fields in the widget structure are pretty useless since they do not reflect the real state of the widget. Although I suppose you could set them to be correct. This seems simple enough, why could you run into trouble? The problem arises with the implementation of XtWindowToWidget(). Since this function is executed for every event processed it must be FAST. Now it seems reasonable to implement some sort of hash table to make this lookup work quickly. If this hash table is set up automatically in XtRealizeWidget() then you will lose, since your new widget will not be in the hash table. I haven't looked at this code, so I don't know what is happening, I will leave that as a excercise for the reader. Also realize that since this is not explictly supported by the Xt Intrinsics it is inherently non-portable. Different versions of the Xt Intrinsics may implement this differently. I will leave ti to you what is better for you application. Please let me know what you find out, I would be interestd. Chris D. Peterson MIT X Consortium Net: kit@expo.lcs.mit.edu Phone: (617) 253 - 9608 Address: MIT - Room NE43-213