libgimpwidgets: add gimp_prop_int_radio_frame,box_new()

This commit is contained in:
Michael Natterer 2019-10-03 15:59:09 +02:00
parent 68f9b540c7
commit d02d97e310
3 changed files with 146 additions and 1 deletions

View file

@ -895,7 +895,7 @@ gimp_prop_enum_radio_frame_new (GObject *config,
* If you want to assign a label to the group of radio buttons, use
* gimp_prop_enum_radio_frame_new() instead of this function.
*
* Returns: (transfer full): A #GtkVBox containing the radio buttons.
* Returns: (transfer full): A #GtkBox containing the radio buttons.
*
* Since: 2.4
*/
@ -953,6 +953,142 @@ gimp_prop_enum_radio_box_new (GObject *config,
return vbox;
}
/**
* gimp_prop_int_radio_frame_new:
* @config: Object to which property is attached.
* @property_name: Name of enum property controlled by the radio buttons.
* @title: Label for the frame holding the buttons
* @store: #GimpIntStore holding list of labels, values, etc.
*
* Creates a group of radio buttons which function to set and display
* the specified int property. If @title is %NULL, the
* @property_name's nick will be used as label of the returned frame.
*
* Returns: (transfer full): A #GimpFrame containing the radio buttons.
*
* Since: 3.0
*/
GtkWidget *
gimp_prop_int_radio_frame_new (GObject *config,
const gchar *property_name,
const gchar *title,
GimpIntStore *store)
{
GParamSpec *param_spec;
GtkWidget *frame;
GtkWidget *box;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (GIMP_IS_INT_STORE (store), NULL);
param_spec = check_param_spec_w (config, property_name,
G_TYPE_PARAM_INT, G_STRFUNC);
if (! param_spec)
return NULL;
if (! title)
title = g_param_spec_get_nick (param_spec);
frame = gimp_frame_new (title);
box = gimp_prop_int_radio_box_new (config, property_name, store);
gtk_container_add (GTK_CONTAINER (frame), box);
gtk_widget_show (box);
gtk_widget_show (frame);
return frame;
}
/**
* gimp_prop_int_radio_box_new:
* @config: Object to which property is attached.
* @property_name: Name of enum property controlled by the radio buttons.
* @store: #GimpIntStore holding list of labels, values, etc.
*
* Creates a group of radio buttons which function to set and display
* the specified int property. If you want to assign a label to the
* group of radio buttons, use gimp_prop_int_radio_frame_new()
* instead of this function.
*
* Returns: (transfer full): A #GtkBox containing the radio buttons.
*
* Since: 3.0
*/
GtkWidget *
gimp_prop_int_radio_box_new (GObject *config,
const gchar *property_name,
GimpIntStore *store)
{
GParamSpec *param_spec;
GtkWidget *vbox;
GtkWidget *button = NULL;
GtkTreeModel *model;
GtkTreeIter iter;
gboolean iter_valid;
GSList *group = NULL;
gint value;
g_return_val_if_fail (G_IS_OBJECT (config), NULL);
g_return_val_if_fail (property_name != NULL, NULL);
g_return_val_if_fail (GIMP_IS_INT_STORE (store), NULL);
param_spec = check_param_spec_w (config, property_name,
G_TYPE_PARAM_INT, G_STRFUNC);
if (! param_spec)
return NULL;
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
model = GTK_TREE_MODEL (store);
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
iter_valid;
iter_valid = gtk_tree_model_iter_next (model, &iter))
{
gchar *label;
gtk_tree_model_get (model, &iter,
GIMP_INT_STORE_LABEL, &label,
GIMP_INT_STORE_VALUE, &value,
-1);
button = gtk_radio_button_new_with_mnemonic (group, label);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
g_free (label);
group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
g_object_set_data (G_OBJECT (button), "gimp-item-data",
GINT_TO_POINTER (value));
g_signal_connect (button, "toggled",
G_CALLBACK (gimp_prop_radio_button_callback),
config);
}
g_object_get (config,
property_name, &value,
NULL);
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (button), value);
set_radio_spec (G_OBJECT (button), param_spec);
connect_notify (config, property_name,
G_CALLBACK (gimp_prop_radio_button_notify),
button);
g_object_set_data (G_OBJECT (vbox), "radio-button", button);
gtk_widget_show (vbox);
return vbox;
}
/***********/
/* label */

View file

@ -54,6 +54,13 @@ GtkWidget * gimp_prop_expander_new (GObject *config,
GtkWidget * gimp_prop_int_combo_box_new (GObject *config,
const gchar *property_name,
GimpIntStore *store);
GtkWidget * gimp_prop_int_radio_frame_new (GObject *config,
const gchar *property_name,
const gchar *title,
GimpIntStore *store);
GtkWidget * gimp_prop_int_radio_box_new (GObject *config,
const gchar *property_name,
GimpIntStore *store);
/* GParamGType */

View file

@ -331,6 +331,8 @@ EXPORTS
gimp_prop_hscale_new
gimp_prop_icon_image_new
gimp_prop_int_combo_box_new
gimp_prop_int_radio_box_new
gimp_prop_int_radio_frame_new
gimp_prop_label_new
gimp_prop_memsize_entry_new
gimp_prop_opacity_entry_new