A P P E N D I X 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:
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.
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 for more details.
This example gets and sets the value of a label. label1 is a member of group mygroup.
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"); |
int[1] |
||
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 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.
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.
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 for more details.
This example gets and sets the value (that is, the contents) of a text. text1 is a member of group mygroup.
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"); |
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 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.
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:
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 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); |
SelectionByName[2] |
||
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 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"); |
SelectionByName[3] |
||
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 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"); |
Copyright © 2003, Sun Microsystems, Inc. All rights reserved.