Article View: comp.windows.x
Article #37147Re: Need help with class data of widgets
From: Chris D. Peterson
Date: Wed, 21 Feb 1990 22:22
Date: Wed, 21 Feb 1990 22:22
77 lines
3128 bytes
3128 bytes
> I'm having trouble understanding the use and access of class data for
> widgets. Basically, I would like to have a function that is common to
> a bunch of different widgets that are of different types. For
> example, I have widgets which are subclasses of command widgets and
> widgets which are subclasses of AsciiText. I would like to define
> some sort of generic procedure for both types of widgets so that I can
> nuse the same call for both. I.e.:
> mycommonroutine(object,data);
> where object is either the command widget or the text widget and data
> is just some pointer.
> I'm thinking of using the class data to hold this routine, but then I
> don't know how to access it or even declare it.
In each widget's Private Header file add the function definition
void (*mycommonroutine)();
to the class part structure of your new subclasses. Then when you
statically define your widgetclass you need to add something like the
following to your widgets .c file.
extern Void __CommonRoutine(); /* Tell the compiler that it really exists. */
NewWidgetClassRec newWidetClassRec = {
{
(WidgetClass) SuperClass, /* superclass */
.
.
.
XtInheritQueryGeometry, /* query_geometry */
XtInheritDisplayAccelerator, /* display_accelerator */
NULL /* extension */
}, /* CoreClass fields initialization */
{
XtInheritChangeSensitive /* change_sensitive */
}, /* SimpleClass fields initialization */
{
0, /* field not used */
}, /* LabelClass fields initialization */
{
0, /* field not used */
}, /* CommandClass fields initialization */
{
__CommonRoutine, /* common routine used by
many widgets.
}, /* NewWidgetClass fields initialization */
};
The to call the routine use this code:
(XtClass(w)->new_class_class.mycommonroutine) (w, data);
Kind 'o yucky huh? It is not clear that this really saves anything over
defining the function externally. The only time this is really useful is if you
want a subclass to be able to substitute in a new routine. Otherwise you are
probabally better off just using a global externa function with a unique name.
The other reason to do this is if you control a common superclass. You can
the make this routine static to that superclass, and all subclasses of this
widget have access to that staticly defined function.
Chris D. Peterson
MIT X Consortium
Net: kit@expo.lcs.mit.edu
Phone: (617) 253 - 9608
Address: MIT - Room NE43-213
Technical Details
Message-ID:
<9002212222.AA03015@expo.lcs.mit.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker!bloom-beacon!EXPO.LCS.MIT.EDU!kitReferences:
<47393@lll-winken.LLNL.GOV>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.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: Need help with class data of widgets Message-ID: <9002212222.AA03015@expo.lcs.mit.edu> Date: 21 Feb 90 22:22:17 GMT References: <47393@lll-winken.LLNL.GOV> Sender: daemon@athena.mit.edu (Mr Background) Organization: The Internet Lines: 77