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.

  1. 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.

  2. 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 not?

  3. Create a new application, boxes, whose widget instance hierarchy is as follows. Supply the remaining widget instance names yourself.
              toplevel (Shell)
             "...instance name..."
                    |
                box1 (Box)
                  "    "
                    |
        ----------------------------
        |                          |
    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?

  4. 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 flop.

    If any of the resource settings must be hardcoded, justify why.