[comp.windows.x.motif] User settable resources in UIL

mattf@milton.u.washington.edu (Matthew Freedman) (10/05/90)

Does anybody know how to create new, user-settable resources which can be
referenced from a UIL module? In particular, I have several distinct fonts
and colors which I use in different widgets in my application. Right now they
are defined in UIL, i.e. 
  text_font : font('Adobe-New Century Schoolbook-Medium-R-Normal--12-*-*-*-*-*-*-*');

and in various arguments sections of objects I will say
  XmNfontList = text_font;

The problem is that I need to make the fonts (and colors)
usable-settable at run-time. The obvious choice is to do so in a
resource file, but the only way I can see to do this is to individually
specify the fontList resource for each and every widget or widget-class
which used a certain font.  I would much rather create a new resource
called textFont, and allow the user to specify a value for that, and
have my uil-defined widgets use it as needed.

If I was building the interface directly in C without UIL, I know I could
use an XtResource array and XtGetApplicationResources to define new
resource names, but how can I export those to uil-defined widgets? 

This is very important, because the application needs to run well on a
variety of different displays, and some of them seem to have radically
different font sizes and names available. I also need to do the same
with colors so that the application will look decent in monochrome as 
well as color.

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
= Matthew M. Freedman                                                 =
= U. of Washington Information Systems       mattf@cac.washington.edu =
= 4545 15th Ave. NE; 4th Floor               (206) 543-5593           =
= Seattle, WA  98105                                                  =
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

mattf@milton.u.washington.edu (Matthew Freedman) (10/08/90)

Nobody has responded yet to my question on user-settable resources in UIL,
but I have made a little progress myself.  If anybody knows if there is
a good way of doing this, would you *please* tell me.

Originally I asked... 
> Does anybody know how to create new, user-settable resources which can be
> referenced from a UIL module? In particular, I have several distinct fonts
> and colors which I use in different widgets in my application. Right now they
> are defined in UIL, i.e. 
> text_font : font('Adobe-New Century Schoolbook-Medium-R-Normal--12-*-*-*-*-*-*-*');
> 
> and in various arguments sections of objects I will say
> XmNfontList = text_font;
> 
> The problem is that I need to make the fonts (and colors)
> user-settable at run-time. The obvious choice is to do so in a
> resource file, but the only way I can see to do this is to individually
> specify the fontList resource for each and every widget or widget-class
> which used a certain font.  I would much rather create a new resource
> called textFont, and allow the user to specify a value for that, and
> have my uil-defined widgets use it as needed.
> 
> If I was building the interface directly in C without UIL, I know I could
> use an XtResource array and XtGetApplicationResources to define new
> resource names, but how can I export those to uil-defined widgets? 
> 
> This is very important, because the application needs to run well on a
> variety of different displays, and some of them seem to have radically
> different font sizes and names available. I also need to do the same
> with colors so that the application will look decent in monochrome as 
> well as color.

Upon further research, I discovered that the man page for MrmRegisterNames
says that the names registered can not only refer to callback functions,
but to "pointers to user-defined data, or any other values". That sounds
like the perfect solution -- create new font and color resources normally,
through Xt, then register them with UIL via MrmRegisterNames, right?
Well I tried this in several variations, but I can not get UIL to find the
value. The 'exported' declaration-modifier apparently causes UIL to look
in the other UID files, but nowhere else.  How do you get UIL to accept
values other than callback names via MrmRegisterNames???

The only solution I have come up with would be to add a pair of new 
creation callbacks, called setFont() and setColor() to each widget
which needs a user-settable font or color, and have those callbacks 
get the appropriate values as Xt resources, and use XtSetValues to change the 
widgets as they are created.  This ought to work, but it is obviously
a stupid hack, and there *must* be a better way (UIL could not be *that*
lame, could it?)

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
= Matthew M. Freedman                                                 =
= U. of Washington Information Systems       mattf@cac.washington.edu =
= 4545 15th Ave. NE; 4th Floor               (206) 543-5593           =
= Seattle, WA  98105                                                  =
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

gstiehl@convex.com (Greg Stiehl) (10/09/90)

> Upon further research, I discovered that the man page for MrmRegisterNames
> says that the names registered can not only refer to callback functions,
> but to "pointers to user-defined data, or any other values". That sounds
> like the perfect solution -- create new font and color resources normally,
> through Xt, then register them with UIL via MrmRegisterNames, right?
> Well I tried this in several variations, but I can not get UIL to find the
> value. The 'exported' declaration-modifier apparently causes UIL to look
> in the other UID files, but nowhere else.  How do you get UIL to accept
> values other than callback names via MrmRegisterNames???

identifier is what you need to use in the uil code.  Here's an example:

In your C program:

    static int              width = 50;
    static MrmRegisterArg   regvec[] = {
                                {"width", (caddr_t)&width},
                            };
    static MrmCount         regnum = XtNumber(regvec);

    MrmRegisterNames (regvec, regnum);

And in your UIL file:

    identifier width;

Then you should be able to use width anywhere in the UIL file.

----------
Greg Stiehl
Convex Computer Corporation
3000 Waterview Pkwy
Richardson, TX  75080
(214) 497-4715
gstiehl@convex.com

marbru@auto-trol.UUCP (Martin Brunecky) (10/09/90)

In article <8768@milton.u.washington.edu> mattf@milton.u.washington.edu (Matthew Freedman) writes:
>Nobody has responded yet to my question on user-settable resources in UIL,
>but I have made a little progress myself.  If anybody knows if there is
>a good way of doing this, would you *please* tell me.
>
>Originally I asked... 
>> Does anybody know how to create new, user-settable resources which can be
>> referenced from a UIL module? In particular, I have several distinct fonts
>> and colors which I use in different widgets in my application. Right now they
>> are defined in UIL, i.e. 
>> text_font : font('Adobe-New Century Schoolbook-Medium-R-Normal--12-*-*-*-*-*-*-*');
>> 
>> and in various arguments sections of objects I will say
>> XmNfontList = text_font;
>> 
>> The problem is that I need to make the fonts (and colors)
>> user-settable at run-time. The obvious choice is to do so in a
>> resource file, but the only way I can see to do this is to individually

>a stupid hack, and there *must* be a better way (UIL could not be *that*
>lame, could it?)

     It sure can ....

 I'v given up on UIL just about a year ago ... so there might be a way with UIL.

 Now, your description is not quite clear.
 If you want to have those things settable at RUNTIME, dynamically, than with UIL
 you are totally out of luck. Similarly with resource database. The only way
 to CHANGE widget once it has been created is XtSetValues. Period.
 [yeeeh, I am just working on something to make it easier, but it's not quite there]

 If by USER SETTABLE you mean that somewhere AT THE BEGINNING, before widgets are
 created, the user can choose colors and/or fonts, BEFORE those widgets get created,
 you can do it with Xrm resource database. You can load resource definitions
 into your resource database at any time - it's just a database (though a silly one).

 You can do XrmDatabase db = XtDatabase(display)

 followed by:
   XrmPutStringResource( db, "*button.foreground", "red" );

 Note that if you want to get really fancy, you may allocate a writeable color cell,
 and say
   XrmPutResource( db, "*button.foreground", XtRPixel, (XrmValue*) &color_cell);
 so that the user can update such color dynamically ....

 Also note that you can put a list of resources to define with the mechanism above
 into the database as well, as an application resource .....

 Just keep in mind that Xrm database is a database (may be a silly one, yeeeh-),
 and it only happens to be loaded automatically by the XtIntrinsics. You can
 query it, populate it, even replace with an empty one, if you wish.


 [ born to bash UIL ]
-- 
=*= Opinions presented here are solely of my own and not those of Auto-trol =*=
Martin Brunecky                   marbru@auto-trol.COM
(303) 252-2499                    {...}ncar!ico!auto-trol!marbru
Auto-trol Technology Corp. 12500 North Washington St., Denver, CO 80241-2404