CS551 - Self-Study Exercises
Exercise 4: Controlling Resource Settings
This assignment is intended to help you explore the different ways in which
resources can be specified and manipulated. It also introduces two
color-related X clients.
The "template" application you write can be very useful in checking out the
fine points of X features; you may want to save copies of one or more of
the evolving versions.
You should have read Chapter 2.1-2.3 in Nye and O'Reilly, Vol. 4,
before starting this exercise.
- Use your knowledge of how resource settings work to find (in the
manpage) the resource for xedit that enables automatic backup
files. Add the appropriate resource setting to your copy of file
Xedit. [Hint: If it worked, subsequent invocations of
xedit will move the most-recent-version to .BAK
whenever you save a file.
- Examine the code for labels that you downloaded in Exercise
1, and determine how it works.
Draw the instance hierarchy on a sheet of paper. [Hint: it
should specify three things for each widget in the program --
class, widget variable name, and widget instance name.]
In fill_box, note the use of (void) before each call
to XtCreateManagedWidget that instantiates a new Label.
Use your knowledge of C to explain what effect this has, and
what the advantage of doing it this way is.
Could the Boxes have been created in the same way? Why or why
- Create a new application, boxes, whose widget instance
hierarchy is as follows. Supply the remaining widget instance names
button (Command) box2 (Box)
"Click to Quit" " "
box3 (Box) title (Label)
" " "Long Label Goes Here"
Clicking the button should quit the application. The application should
rely entirely on X's default resource values (that is, you do not need
any resource file). Streamline your application so that it has the
fewest number of statements possible to accomplish the needed actions,
but do not sacrifice readability.
From the appearance of the Boxes, deduce what rules X uses to set
the default size.
According to X conventions, what should the name of the resource
file for this application be?
- Create a separate version of the resource file for each of the
following scenarios, in each case adding the minimum number of
resources to those you used for step (2). As you go along, save the
settings you used in a file. (Hint: learn to use the
xcolors and xco clients, which you will find on
If any of the resource settings must be hardcoded, justify why.
- Scenario A: The background of the button is a pale green, and
all other backgrounds are cream-colored.
- Scenario B: The background of box2 is a medium gray, like the
gray on the "Use Control-S and Control-R" bar of xedit when you use
the course defaults; all other backgrounds (including box2's children)
- Scenario C: The background of box1, box3, and label is a pale
pink; all other backgrounds remain white (hint: this does not require more
than two resource settings).
- Scenario D: Box3 is half the width of the long label box, and
the space inside box2 surrounding box3 and label is twice as large as the
space (in box1) surrounding box2. Make sure the height of box3 doesn't
change (or if it stays the same for you, see what very minor change in the
resource setting will cause box3 to become taller).
- Scenario E: The button has a border outline that is a dark
red and is four times as thick as the other borders.