This chapter provides details about the VkEZ library and its EZ convenience functions. It includes the following sections:
One problem for many developers new to IRIS IM is the amount of knowledge required to build working applications. Although RapidApp significantly reduces the knowledge needed to create application interfaces, you still need significant knowledge of IRIS IM to begin getting values from widgets, displaying data, or dynamically configuring widgets.
For example, the simple calculator program described in Chapter 1, “RapidApp Tour,” requires that you know how to extract the contents of two text fields, convert the strings to integers, and add them back to the third text field. To do this simple operation, you must either know about the XtSetValues()/XtGetValues() functions and that the text widgets have an XmNvalue resource, or you must know about the XmTextFieldGetString()/XmTextFieldSetString() functions.
Neither of these approaches is hard, but the fact that you have to know the interface for each type of widget can make seemingly simple tasks difficult. There are over 700 functions in IRIS IM, Xt, and Xlib, and although XmTextFieldGetString() and XmTextFieldSetString() are easy to use, you have to know they exist before you can actually use them.
The VkEZ package is a utility that makes it easier to perform simple operations in some cases. The package is not a general-purpose “widget wrapper” library and normally you shouldn't use it in production code—especially if you are concerned about the performance of your application. The VkEZ utility provides an easy-to-remember API for common operations. It is suitable for use in prototypes, demos, and applications in which performance isn't a concern. Instead of memorizing dozens or perhaps hundreds of IRIS IM functions, VkEZ requires that you remember only a few simple operations that you can apply to all widgets.
At its simplest, the VkEZ package provides a few operations you can apply to nearly any widget. You can use the “=”, “<<“, or “+=” operators to assign, or append data to a widget. The exact meaning of the operator varies with the widget but should normally “do the right thing.” You can also retrieve the “value” of a widget simply by an implicit or explicit cast to the desired type. Again, the actual data returned depends on the widget. Retrieving the “String” of a Text widget yields the contents of the text field; retrieving the “String” of a List widget yields the text of the selected item. Retrieving an integer from a Scale widget gets the current value of the scale. Asking for the integer value of a text field returns the results of calling atoi() on the contents of the field.
To use a VkEZ operation, you must enclose the widget to be used in “EZ()”, like this:
EZ(widget) |
Then you can use the VkEZ operators to set and retrieve data from the widgets. For example, in the calculator example you can set the value of the _result text field to be the sum of the _value1 and _value2 widgets, like this:
EZ(_result) = (int) EZ(_value1) + (int) EZ(_value2); |
You can also use the C++ “<<” operator to append data. For example, you can implement a more verbose form of the above example as follows:
EZ(_result) = ""; // Clear the text field
EZ(_result) << "The result of " << EZ(_value1) << " + "
<< EZ(_value2) << " = "
<< (int) EZ(_value1) + (int) EZ(_value2);
|
If the _value1 widget contains the string “10” and _value2 contains “20,” this places the following string in the _result text field:
The result of 10 + 20 = 30 |
![]() | Note: The VkEZ package is designed for quick prototypes and ease of learning. The implementation is inefficient and offers no real advantage over the IRIS IM API other than simplicity. Use the VkEZ utilities sparingly, and for production-quality programs, plan to replace all uses with the more direct mechanisms supported by IRIS IM. When you are ready to replace the EZ functions with production code, you should be able to find all occurrences of “EZ” quite easily in your editor. |
For more detailed information about the widgets and operations supported, see “VkEZ Operators.”
The VkEZ package relies on a simple model that assumes you want to do the most obvious operation for a given widget. For example, assume you want to increment a Dial widget, represented by the data member _dial, by 10 each time a particular function is called. In the function, you can write:
EZ(_dial) += 10; |
Suppose you want to tie two dials, _dial1 and _dial2, together so that _dial2 always displays 1/2 the value of _dial1. You can do so by including the following code in the function invoked when _dial1 changes value:
EZ(_dial2) = (int) EZ(_dial1) / 2; |
List widgets can be difficult to work with, and EZ provides an easy way to set, add, or retrieve the contents of a list. For example, you can display a list of strings in a List widget like this:
EZ(_list) = "red, green, blue"; |
You can add colors later with:
EZ(_list) += "yellow, orange"; |
or:
EZ(_list) << "yellow, orange"; |
The VkEZ package also provides access to several common IRIS IM resources. For example, you can set or get the width, height, or position of a widget. The following code segment displays a string in a text widget named _text that reports the width of a _button widget:
EZ(_text) = "The width of the button is "
<< EZ(_button).width << " pixels";
|
You can set the width of a label widget, _label, to be the same as another, _longlabel, with:
EZ(_label).width = EZ(_longlabel).width; |
You can set a color using:
EZ(_label).foreground = "blue"; |
You can even use colors defined by schemes as shown in this example:
EZ(_label).background =
"SGI_DYNAMIC AlternateBackgroundColor1";
|
For more information on the VkEZ features, see “VkEZ Operators.”
VkEZ has two kinds of operators:
General operators, which are applied directly to the object. For example:
EZ(widget) = "a label"; |
Operators that are applied to an attribute (resource) supported by the widget. For example:
EZ(widget).foreground = "red"; |
The description of each operator lists the widgets that support that operator and defines how the operator works on each widget.
String() returns a character string from the widget. For example:
strcpy(buffer, EZ(text)); |
This example copies the contents of a text widget into buffer.
The following list describes the behavior of this operator for each widget that supports it.
| XmLabel, XmLabelGadget, and subclasses | | |
| XmText, XmTextField | | |
| XmList | returns the text associated with the currently selected item |
int() returns an integer value from the widget. For example:
int value = EZ(dial); |
This example assigns the current value of a dial widget to value.
The following list describes the behavior of this operator for each widget that supports it.
| XmToggleButton and XmToggleButtonGadget |
| |
| XmScrollbar, XmScale |
| |
| SgDial | returns the current position of the pointer | |
| XmText, XmTextField |
| |
| XmList | returns the currently selected position |
EZ& operator=(int); EZ& operator=(float); EZ& operator=(const char *); |
Assignment operators assign integer, floating point, and character values to a widget. For example:
EZ(text) = 12345; |
This example displays the integer 12345 in a text field.
The following list describes the behavior of the integer assignment operator for each widget that supports it.
| XmToggle, XmToggleButtonGadget |
| |
| XmScrollbar, XmScale |
| |
| SgDial | sets the current pointer position to the specified value | |
| XmLabel, XmLabelGadget, and subclasses (except toggle) |
| |
| XmText, XmTextField |
| |
| XmList | sets the current position index to the specified value |
The following list describes the behavior of the floating point assignment operator for each widget that supports it.
| XmScrollbar, XmScale |
| |
| SgDial | sets the current pointer position to the integer equivalent of the specified value (the floating point value is truncated) | |
| XmLabel, XmLabelGadget and subclasses |
| |
| XmText, XmTextField |
| |
| XmList | sets the current position index to the integer equivalent of the specified value (the floating point value is truncated) |
The following list describes the behavior of the character string assignment operator for each widget that supports it.
| XmScale | sets the title to the specified string | |
| XmLabel, XmLabelGadget, and subclasses |
| |
| XmText, XmTextField |
| |
| XmList | treats the specified string as comma-separated list of items and sets the list widget to display the new items, removing old contents |
EZ& operator+=(int); EZ& operator+=(float); EZ& operator+=(const char *); EZ& operator<<(int); EZ& operator<<(float); EZ& operator<<(const char *); |
Append operators append the right side expression to the current value of a widget. Logically, the += operators make more sense for numerical operations, while the << operators seem more suitable for strings, but they are actually equivalent and either can be used.
The following list describes the behavior of the integer and floating point append operators for each widget that supports them.
| XmToggle, XmToggleButtonGadget |
| ||
does nothing, while
| |||
sets toggle if it is not already set | |||
| XmScale, XmScrollbar |
| ||
| SgDial | increases the position of the pointer by the specified value | ||
| XmLabel, XmLabelGadget, and subclasses |
| ||
| XmText, XmTextField |
| ||
| XmList | increments the current position index by the specified value |
The following list describes the behavior of the character string append operator for each widget that supports it.
| XmLabel, XmLabelGadget and subclasses |
| |
| XmScale | appends the give string to the current value of the XmNtitle resource | |
| XmText, XmTextField |
| |
| XmList | treats the string as a comma-separated list of items and adds the items to the list widget's current contents |
EZ& operator-=(int); |
The decrement operator decrements the current value associated with a widget.
The following list describes the behavior of the decrement operator for each widget that supports it.
| XmToggle, XmToggleButtonGadget |
does nothing, while
unsets toggle if it is not already unset | |||
| XmScale, XmScrollbar |
| |||
| SgDial | decreases the position of the pointer by the specified value | |||
| XmList | decrements the current position index by the specified value |
The following are attributes that can be modified using VkEZ:
Attributes supported by all widgets: border, width, height, x, y
Attributes supported by all widgets that have setting support for Pixel or char *: background, foreground
Attributes supported by XmLabel, XmLabelGadget and subclasses: label
Attributes supported by XmScale, XmScrollBar, SgDial: value, minimum, maximum
Each of these attributes can be retrieved or set. For example:
int width = EZ(widget).width; EZ(widget).width = 20; EZ(widget).foreground = "red"; Pixel index = EZ(widget).background; |