The xpm_label_box function could be used to pack xpm's and labels into any widget that can be a container.
Notice in xpm_label_box how there is a call to gtk_widget_get_style. Every widget has a "style", consisting of foreground and background colors for a variety of situations, font selection, and other graphics data relevant to a widget. These style values are defaulted in each widget, and are required by many GDK function calls, such as gdk_pixmap_create_from_xpm, which here is given the "normal" background color. The style data of widgets may be customized, using GTK's rc files.
Also notice the call to gtk_widget_realize after setting the window's border width. This function uses GDK to create the X windows related to the widget. The function is automatically called when you invoke gtk_widget_show for a widget, and so has not been shown in earlier examples. But the call to gdk_pixmap_create_from_xpm requires that its window argument refer to a real X window, so it is necessary to realize the widget before this GDK call.
The Button widget has the following signals:
pressed - emitted when pointer button is pressed within Button widget
released - emitted when pointer button is released within Button widget
clicked - emitted when pointer button is pressed and then released within Button widget
enter - emitted when pointer enters Button widget
leave - emitted when pointer leaves Button widget
6.2 Toggle Buttons
Toggle buttons are derived from normal buttons and are very similar, except they will always be in one of two states, alternated by a click. They may be depressed, and when you click again, they will pop back up. Click again, and they will pop back down.
Toggle buttons are the basis for check buttons and radio buttons, as such, many of the calls used for toggle buttons are inherited by radio and check buttons. I will point these out when we come to them.
Creating a new toggle button:
|
As you can imagine, these work identically to the normal button widget calls. The first creates a blank toggle button, and the second, a button with a label widget already packed into it.
To retrieve the state of the toggle widget, including radio and check buttons, we use a construct as shown in our example below. This tests the state of the toggle, by accessing the active field of the toggle widget's structure, after first using the GTK_TOGGLE_BUTTON macro to cast the widget pointer into a toggle widget pointer. The signal of interest to us emitted by toggle buttons (the toggle button, check button, and radio button widgets) is the "toggled" signal. To check the state of these buttons, set up a signal handler to catch the toggled signal, and access the structure to determine its state. The callback will look something like:
|
To force the state of a toggle button, and its children, the radio and check buttons, use this function:
|
The above call can be used to set the state of the toggle button, and its children the radio and check buttons. Passing in your created button as the first argument, and a TRUE or FALSE for the second state argument to specify whether it should be down (depressed) or up (released). Default is up, or FALSE.
Note that when you use the gtk_toggle_button_set_active() function, and the state is actually changed, it causes the "clicked" signal to be emitted from the button.
|
6.3 Check Buttons
Check buttons inherit many properties and functions from the the toggle buttons above, but look a little different. Rather than being buttons with text inside them, they are small squares with the text to the right of them. These are often used for toggling options on and off in applications.
The two creation functions are similar to those of the normal button.