A widget's resources are set or retrieved using the set and
get accessor methods of the widget, which are the names that correspond directly to the associated resource name. Resource setting methods have a special property that can be sent to a widget to set initial state during widget creation, from inside a create
argBlock.
Create-only (C) resources can
only be set using an
argBlock at widget creation time. An
argBlock is a single argument Smalltalk block of code that is evaluated with the widget being created as its argument. Resources with an (S) designation can also be set in the
argBlock. The
argBlock is evaluated before the widget is fully created, that is, while it is still under construction, but after a Smalltalk object has been created to represent the widget. If
argBlock is not required,
nil can be used for the
argBlock argument, rather than unnecessarily creating an empty block.
Always set resources in the create argBlock wherever possible. Also, unless names are needed for X resource files, use the widget's name to establish a default resource value as described in the widget creation section on page
1. Creating a widget. If the system has more information available at the time of widget creation, it can perform more optimization. On some platforms a significant performance advantage is achieved by setting resources in the create
argBlock rather than immediately after creation, which might cause default widget configuration to have to be "undone".
In the following example, the width and
height resources for a drawing area are explicitly set in an
argBlock when the drawing area widget is created. These specify the size in pixels of the drawing area widget. The size of the shell widget is calculated based on the size of the drawing area widget. In general, when the size of a widget is not explicitly specified, it is calculated based on the size of its children, recursively. The string arguments in the creation messages specify the names of the widgets. By default, the name of the top-level shell appears as the window title.
Multiple resources with set (S) designation can also be set simultaneously after the widget is created using the
setValuesBlock: message, which takes an
argBlock as argument. The
setValuesBlock: method is the recommended way of setting multiple resources for a widget after the widget is created. Normally, after a widget has been created and a resource is modified, which changes a widget's appearance, the widget is redisplayed to show the change. Using a
setValuesBlock is more efficient than setting the resources outside the block because the widget can then optimize updates together, even if several of them change the widget's appearance. The block passed to
setValuesBlock: has the same format as the
argBlock used when creating a widget.
Some resources change their values when the value of a different resource in the same widget is changed. To avoid this "push-down-here-pop-up-there" effect, such resources must be set simultaneously using an
argBlock, either on creation or after creation using
setValuesBlock:.This situation occurs with left/right and top/bottom
CwForm attachment resources, which should always be set in pairs.
Widget methods that are not resource set or get methods are widget function methods. Unlike resource setting messages, function messages can only be sent to widgets after they have been created. While resource methods are used to access or change widget state, function methods typically perform more complex operations, and in some cases modify resource values. While resource get and set methods uniformly require zero arguments and one argument respectively, widget function methods take varying numbers of arguments, depending on the particular function. The
manageChild method is an example of a widget function.
Copyright 2005, 2020 Instantiations, Inc. All rights reserved.