APPENDIX C |
Getters and Setters |
Getters and setters are provided for those widgets which can have a value or a state. This appendix lists the available getters and setters for each of those widgets. These routines are toolkit-independent. To use them, you must first define a Group containing the widget(s) and then set up a Smart Code callback. For more information on these subjects, see:
1. | Chapter 15, "Groups", starting on page 479. |
2. | Chapter 16, "Get/Set Smart Code", starting on page 487. |
3. | Chapter 17, "Thin Client Smart Code", starting on page 503. |
4. | Chapter 18, "Internet Smart Code", starting on page 537. |
The widgets covered here are:
Label and Button |
Toggle |
Text Field, Text and Scrolled Text |
Scale |
List and Scrolled List |
Option Menu |
Radio Box |
A table is provided for each widget which shows the X resource which can be accessed using a getter and a setter. One is the default - this is the one which is accessed from the server. The server simply does a get or a set of the "value" of a widget. The "value" is this default.For each widget, an example of how to use the getters and setters is given in separate subsections for C, C++ and Java code.
There are extensive online reference documents. Open the following file in an HTML browser for a list of contents:$XDROOT/lib/locale/<YourLocale>/sc/index.html
where XDROOT is the install directory of your X-Designer and
YourLocale is the locale you are using. If you are unsure about your
locale, try typing locale into a terminal window. This prints out your
locale information. Use the string assigned to LANG. Example locales are:In addition, once you have generated code, you have a file called index.html in the directory where your code was generated. This contains hypertext links giving you access to the online reference material.
Resource Name |
Type |
|
Value |
char * |
Default |
Sensitive |
int |
|
and Button
In C code, use the SC_GET and SC_SET macros. These macros take the resource name (i.e. what you are getting/setting) as the first parameter and the Group component as the second. For SC_SET, the third parameter is the new value. See Chapter 16, "Get/Set Smart Code", starting on page 487 for more details.This example gets and sets the value of a label. label1 is a member of group mygroup.
char * val = SC_GET(Value,mygroup->label1);SC_SET(Value,mygroup->label1,"my label");
In C++, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above, it gets and sets the value of a label. "label1" is a member of Group mygroup:
mygroup_c * g = (mygroup_c *) getGroup();char * val = g->label1->getValue();g->label1->setValue("my label");
In Java, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above; it gets and sets the value of a label. "label1" is a member of Group mygroup:
mygroup_c g = (mygroup_c ) getGroup();String val = g.label1.getValue();g.label1.setValue("my label");
Resource Name |
Type |
|
State |
int1 |
Default |
Sensitive |
int |
|
1 For Java, State is boolean. |
In C code, use the SC_GET and SC_SET macros. These macros take the resource name (i.e. what you are getting/setting) as the first parameter and the Group component as the second. For SC_SET, the third parameter is the new value. See Chapter 16, "Get/Set Smart Code", starting on page 487 for more details.This example gets and sets the state (whether or not it is set) of a toggle. "toggle1" and "toggle2" are members of group mygroup.
int state = SC_GET(State,mygroup->toggle1);SC_SET(State,mygroup->toggle2, state);
In C++, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above, it gets the state of one toggle and sets the state of another. "toggle1" and "toggle2" are members of Group mygroup:
mygroup_c * g = (mygroup_c *) getGroup();int state = g->toggle1->getState();g->toggle2->setState(state);
In Java, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above; it gets and sets the state of a toggle. "toggle1" and "toggle2" are members of Group mygroup:
mygroup_c g = (mygroup_c ) getGroup();boolean state = g.toggle1.getState();g.toggle2.setState(state);Note that "state" is a boolean here - for C and C++ it would be an int.
Getters and Setters for text controls are available through the SC_GET() and SC_SET() macros, defined in groups_c/sc_types.h.
TABLE 28-3 Available Getters/Setters for Text Resource Name
Type
Value
char *
Default
Sensitive
int
In C code, use the SC_GET and SC_SET macros. These macros take the resource name (i.e. what you are getting/setting) as the first parameter and the Group component as the second. For SC_SET, the third parameter is the new value. See Chapter 16, "Get/Set Smart Code", starting on page 487 for more details.This example gets and sets the value (that is, the contents) of a text. text1 is a member of group mygroup.
char * contents = SC_GET(Value,mygroup->text1);SC_SET(Value,mygroup->text1,"a new string");
In C++, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above, it gets and sets the contents of a text. "text1" is a member of Group mygroup:
mygroup_c * g = (mygroup_c *) getGroup();char * contents = g->text1->getValue();g->text1->setValue("a new string");
In Java, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above; it gets and sets the contents of a text. "text1" is a member of Group mygroup:
mygroup_c g = (mygroup_c ) getGroup();String contents = g.text1.getValue();g.text1.setValue("a new string");
Resource Name |
Type |
|
Value |
int |
Default |
Sensitive |
int |
|
In C code, use the SC_GET and SC_SET macros. These macros take the resource name (i.e. what you are getting/setting) as the first parameter and the Group component as the second. For SC_SET, the third parameter is the new value. See Chapter 16, "Get/Set Smart Code", starting on page 487 for more details.This example gets and sets the value (that is, the number on the scale) of a scale widget. scale1 is a member of group mygroup.
int val = SC_GET(Value,mygroup->scale1);SC_SET(Value,mygroup->scale1, 1);
In C++, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above, it gets and sets the scale number of a scale widget. "scale1" is a member of Group mygroup:
mygroup_c * g = (mygroup_c *) getGroup();int scaleValue = g->scale1->getValue();g->scale1->setValue(1);
In Java, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above; it gets and sets the scale number of a scale widget. "scale1" is a member of Group mygroup:
mygroup_c g = (mygroup_c ) getGroup();int scaleValue = g.scale1.getValue();g.scale1.setValue(1);
Resource Name |
Type |
|
Items |
char ** |
|
Sensitive |
int |
|
SelectedItems |
char ** |
Default |
and Scrolled List
In C code, use the SC_GET and SC_SET macros. These macros take the resource name (i.e. what you are getting/setting) as the first parameter and the Group component as the second. For SC_SET, the third parameter is the new value. See Chapter 16, "Get/Set Smart Code", starting on page 487 for more details.This example gets and sets the list of selected items of the list widget. list1 is a member of group mygroup. The list of selected items is a null terminated array of strings.
char ** my_stringlist = SC_GET(SelectedItems,mygroup->list1);SC_SET(SelectedItems,mygroup->list1,a_new_stringlist);
In C++, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above, it gets and sets the selected items in a list widget. "list1" is a member of Group mygroup. The list of selected items is a null terminated array of strings.
mygroup_c * g = (mygroup_c *) getGroup();char ** my_stringlist = g->list1->getSelectedItems();g->list1->setSelectedItems(a_new_stringlist);
In Java, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above; it gets and sets the selected items in a list widget. "list1" is a member of Group mygroup. Use the Java built-in "<array>.length" to find out how many Strings there are in the array.
mygroup_c g = (mygroup_c ) getGroup();String [] my_stringlist = g.list1.getSelectedItems();int how_many = my_stringlist.length;g.list1.setSelectedItems(a_new_stringlist);
Resource Name |
Type |
|
Label |
char * |
|
Sensitive |
int |
|
SelectionByName1 |
char * |
|
SelectionByIndex |
int |
Default |
1 This is the string being displayed and not the widget name. |
In C code, use the SC_GET and SC_SET macros. These macros take the resource name (i.e. what you are getting/setting) as the first parameter and the Group component as the second. For SC_SET, the third parameter is the new value. See Chapter 16, "Get/Set Smart Code", starting on page 487 for more details.This example gets and sets the selected item in the optionmenu. optionMenu1 is a member of group mygroup.
char * val = SC_GET(SelectionByName, mygroup->optionMenu1);SC_SET(SelectionByName,mygroup->optionMenu1, "Option 1");
In C++, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above, it gets and sets the selected item in the option menu. "optionMenu1" is a member of Group mygroup:
mygroup_c * g = (mygroup_c *) getGroup();char * val = g->optionMenu1->getSelectionByName();g->optionMenu1->setSelectionByName("Option 2");
In Java, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above; it gets and sets the selected item in the option menu. "optionMenu1" is a member of Group mygroup:
mygroup_c g = (mygroup_c ) getGroup();String val = g.optionMenu1.getSelectionByName();g.optionMenu1.setSelectionByName("Option 3");
Resource Name |
Type |
|
Label |
char * |
|
Sensitive |
int |
|
SelectionByName1 |
char * |
|
SelectionByIndex |
int |
Default |
1 This is the string being displayed and not the widget name. |
In C code, use the SC_GET and SC_SET macros. These macros take the resource name (i.e. what you are getting/setting) as the first parameter and the Group component as the second. For SC_SET, the third parameter is the new value. See Chapter 16, "Get/Set Smart Code", starting on page 487 for more details.This example gets and sets the label of the selected item in a radiobox widget. radiobox1 is a member of group mygroup.
char * str = SC_GET(SelectionByName, mygroup->radiobox1);SC_SET(SelectionByName,mygroup->radiobox1, "The text to show");
In C++, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above, it gets and sets the label of the selected item in a radiobox widget. "radiobox1" is a member of Group mygroup:
mygroup_c * g = (mygroup_c *) getGroup();char * str = g->radiobox1->getSelectionByName();g->radiobox1->setSelectionByName("The text to show");
In Java, the Group is a class, the group member is a variable of this class and is a class itself and the getters and setters are methods of the Group member's class.This example is the same as the C code example above; it gets and sets the scale number of a scale widget. "scale1" is a member of Group mygroup:
mygroup_c g = (mygroup_c ) getGroup();String str = g.radiobox1.getSelectionByName();g.radiobox1.setSelectionByName("The text to show");