[comp.windows.x] Need help with D.Young's example?

wolf@cbnewsh.att.com (thomas.wolf) (08/22/90)

I'm in the process of learning to write my own widgets and have found
Douglas Young's book extremely helpful.  I am curious, however, as to
the following:

In Chapter 12's example of the simple "Dial" widget, some defaults are
set in Dial.c (foreground, indicatorColor, etc.) in the resources[] array.
I found that modifying these defaults and recompiling resulted in the
expected changes at run-time, _except_ when I changed the defauts for
XtNforeground.  No matter what color I specified, the program would always
set the foreground color to "Black" (ie. the little line segments in his
dial widget would always be black.)

If, on the other hand, I specify the foreground color at run-time (with
the command-line option '-fg') it is correctly displayed by the program.

Why is this so?  I have the feeling I'm missing a basic point.
I have the same problem with widgets I've begun to write.  Any help would
really be appreciated,

Tom

-- 
+-------------------------------------+ "Stupid" questions are better than
| Thomas Wolf   | (201) 949-8063      | no questions at all. No answer is
| Bell Labs, NJ | wolf@spanky.att.com | better than a stupid one.
+-------------------------------------+

mikey@eukanuba.wpd.sgi.com (Mike Yang) (08/22/90)

In article <1990Aug21.235152.8328@cbnewsh.att.com>, wolf@cbnewsh.att.com
(thomas.wolf) writes:
|> In Chapter 12's example of the simple "Dial" widget, some defaults
are
|> set in Dial.c (foreground, indicatorColor, etc.) in the resources[]
array.
|> I found that modifying these defaults and recompiling resulted in
the
|> expected changes at run-time, _except_ when I changed the defauts
for
|> XtNforeground.  No matter what color I specified, the program would
always
|> set the foreground color to "Black" (ie. the little line segments in
his
|> dial widget would always be black.)
|> 
|> If, on the other hand, I specify the foreground color at run-time
(with
|> the command-line option '-fg') it is correctly displayed by the
program.

The XtResource list for the Dial widget doesn't specify resource
values -- it specifies resources used and gives default values.  The
reason why changing the defaults worked for all the resources other
than XtNforeground is that these resources probably didn't have
specified values (they're unique to Dial) so their defaults are used.

XtNforeground, however, is a common resource.  If you specify some
value for it (e.g. your .Xdefaults) somewhere, its default will never
be used.  Using the -fg switch overrides whatever specification is out
there, so its effect is noticable.

-----------------------------------------------------------------------
                 Mike Yang        Silicon Graphics, Inc.
               mikey@sgi.com           415/335-1786