Path: utzoo!attcan!uunet!mcsun!ukc!pyrltd!root44!kieron From: kieron@root.co.uk (Kieron Drake) Newsgroups: comp.windows.x Subject: Re: Novice Xt questions Message-ID: <2440@root44.co.uk> Date: 19 Sep 90 11:34:53 GMT References: <9009171346.AA17823@expo.lcs.mit.edu> <2420@root44.co.uk> Organization: UniSoft Ltd., London, England Lines: 119 ( 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