[comp.windows.x] Novice Xt questions

toml@ninja.Solbourne.COM (Tom LaStrange) (09/11/90)

I have just a couple of Xt questions.

1. Is it possible to add event handlers for non-widget windows?  If so,
   how?  If not do I need to break up XtMainLoop and pull off events for
   the window(s) in question before sending them to XtDispatchEvent?

2. Is it possible for me to insert a quark or two in the class and
   instance lists before resources are fetched on widgets?

Thanks,
Tom LaStrange

Solbourne Computer Inc.    ARPA: toml@Solbourne.COM
1900 Pike Rd.              UUCP: ...!{boulder,sun}!stan!toml
Longmont, CO  80501

gildea@ALEXANDER.BBN.COM (Stephen Gildea) (09/17/90)

       Is it possible for me to insert a quark or two in the class and
       instance lists before resources are fetched on widgets?

XtGetApplicationResources allows you to specify additional resources.
The first argument is the widget to associate the resources with.
Another argument is a struct giving the name, class, type, and default
value of your resources.

 < Stephen				Bolt Beranek and Newman Inc.
   gildea@bbn.com			Cambridge, Massachusetts

		"Here's looking at you, kid."

kieron@root.co.uk (Kieron Drake) (09/19/90)

( Apologies if this is a repeat message, but my mailer complained about my
previous attempt to send it.... kieron)

In <9009171346.AA17823@expo.lcs.mit.edu> gildea@ALEXANDER.BBN.COM (Stephen Gildea) writes:
>
>
>       Is it possible for me to insert a quark or two in the class and
>       instance lists before resources are fetched on widgets?
>
>XtGetApplicationResources allows you to specify additional resources.
>The first argument is the widget to associate the resources with.

Actually, this statement is possibly misleading (and if I've been mislead
into thinking it's in error then it must have been misleading :-) ).
Resources got by XtGetApplicationResources are global to the application
and are *not* associated with any particular widget. A widget is indeed
specified as first argument but it is used for the purpose of name and
class prepending to provide the full name and class for resource matching
as well as identifying the appropriate resource database.

>Another argument is a struct giving the name, class, type, and default
>value of your resources.
Plus offsets into which values will be written and another argument is the
base of the structure from which the offsets are calculated. It is this
"base" parameter that specifies which widget or widget class is referenced
by the supplied resource list.

I'm not sure what was meant by "insert a quark or two in the ..." but if
the intention is to provide default values which may be overwritten
by any resource specs. that match then the cleanest way is to provide suitable
default values in the XtResourceList passed to XtGetApplicationResources.
Note that for each widget or widget class that is to be modified a separate
call on XtGetApplicationResources with a suitable base parameter must be made.


Example:

	/* provide a default justification of XtJustifyLeft for a label */
	static XtResource res[] = {
		{ XtNjustify, XtCJustify, XtRJustify, sizeof(XtJustify),
		  XtOffsetOf(LabelRec, label.justify), XtRImmediate,
		  (caddr_t)XtJustifyLeft
		}
	};

	/* .................. */

	the_label_widget = XtCreateManagedWidget("foo", labelWidgetClass,
		top_level_shell, NULL, 0);

	XtGetApplicationResources(top_level_shell, the_label_widget,
		res, XtNumber(res), NULL, 0);

The label widget will be created with justify set from the normal
resource database, superclasses and classes etc. etc  or else the
standard default of XtJustifyCenter if not specified in these.
The subsequent call on XtGetApplicationResources would plough though
the resource database all over again, setting the value yet again if
specified already, else setting to the new default of XtJustifyLeft.

You could also use XtGetValues and XtSetValues or even bodge the resources
field within the core class part of the initialised LabelClassRec referenced
by labelWidgetClass (phew!). This last is a horrible hack but if done before
XtAppInitialize etc. could be used to change the default value to XtJustifyLeft:

void bodge(wc, name, type, addr)
	WidgetClass wc;
	String name;
	String type;
	XtPointer addr;
{
	XtResourceList rl;
	Cardinal nr, i;

	assert(wc != NULL);

	nr = wc->core_class.num_resources;
	rl = wc->core_class.resources;

	assert(nr == 0 || rl != NULL);

	for(i=0; i<nr; i++)
		if (strcmp(rl[i].resource_name, name) == 0) {
			rl[i].default_addr = addr;
			rl[i].default_type = type;
			break;
		}
	/* if we didn't find it then shamefully slink away... shhhhhh. */
}

main(argc, argv)
int argc; char *argv[];
{
	Widget top;
	XtAppContext app_con;

	/* first thing - very dodgy practices! */
	bodge(labelWidgetClass, XtNjustify, XtRImmediate,
			(XtPointer)XtJustifyLeft);
	bodge(commandWidgetClass, XtNjustify, XtRImmediate,
			(XtPointer)XtJustifyRight);

	top = XtAppInitialize(&app_con,........ );

	/* etc. etc. */
}

This is very naughty as it assumes a great deal about the intrinsics. Are
there any cleaner ways to do it without using any of the alternatives
already mentioned? Perhaps I've just misunderstood what was meant by
the original query.

	kieron

-- 
	Kieron Drake
MAIL:	kieron@root.co.uk
SNAIL:	UniSoft Ltd, Saunderson House, Hayne Street, London EC1A 9HH
PHONE:	+44 71 315 6637 (direct) +44 71 315 6600 (switchboard)