[comp.windows.x] Xtk Resource Converters

hill@nicmad.UUCP (Ray Hill) (05/25/88)

				X toolkit Experts:
				------------------

Where is the correct place to add resource converters? (ie. XtAddConverter)

I tried the "class_initialize" procedure for the widget that uses the new 
resource type but that is to late. I need the new resource type before creating
the first widget of this type. If I try to use the converter before creating the
first widget Xt warns: 

	"X Toolkit Warning: No type converter registered for ...".

Widgets created after the first one are allowed to use the converter without
problems through "XtConvert" . "XtSetValues" also works great by putting the
converted values exactly where they are wanted.

But telling our application programmers: "Always create a widget of this type
and then destroy it before creating any widgets you want to use" is not 
acceptable.

Xt is finding the resource converter when doing default resource stuff.
(ie. XtResources and app-defaults stuff) It works since this happens after the
"class_initialize" procedure has been called.

So far I haven't been able to get Xt to put the defaults into the "Rec" 
structure though. I know its calling the converter but I haven't found out where
its putting my results yet.  But hopefully that's a simple bug I track down.


					Ray Hill (hill@nicmad)
					(608) 271-3333  X-2103

haynes@WSL.DEC.COM (05/26/88)

This is one of the reasons I hate C. In a reasonable language you would
have module initialization happen automatically at program startup.
Since C doesn't do this, you have to do your own initialization
MANUALLY. We do some of this for you with the static class
initializers, where the class initialization code gets called before
the first instance of that class is created, however the mechanism
should be more general.

It should be possible for a package that exports functionality, like a
resource type converter, to have it's initalizer called automatically.
Unfortunately no such mechanism exists, and implementing *automatic*
package initialization in C is hard. So I'm afraid you're stuck with
either initializing all of your classes manually, and registering the
type converter in the class initialization code, or providing an
explicit intializer for your stuff, and requiring your clients to call it.

	Wish we had a modern language to do this in...
	-- Charles