/** * mx_button_group_add: * @group: A #MxButtonGroup * @button: A #MxButton * * Add @button to the #MxButtonGroup. * */ void mx_button_group_add (MxButtonGroup *group, MxButton *button) { MxButtonGroupPrivate *priv; g_return_if_fail (MX_IS_BUTTON_GROUP (group)); g_return_if_fail (MX_IS_BUTTON (button)); priv = group->priv; priv->children = g_slist_prepend (priv->children, button); g_signal_connect (button, "notify::toggled", G_CALLBACK (button_toggled_notify_cb), group); g_signal_connect (button, "button-press-event", G_CALLBACK (button_click_intercept), group); g_signal_connect (button, "button-release-event", G_CALLBACK (button_click_intercept), group); g_object_weak_ref (G_OBJECT (button), (GWeakNotify) button_weak_notify, group); if (!priv->allow_no_active && !priv->active_button) mx_button_set_toggled (button, TRUE); }
/** * mx_button_get_icon_position: * @button: A #MxButton * * Retrieves the icon's relative position to the text. * * Returns: A #MxPosition * * Since: 1.2 */ MxPosition mx_button_get_icon_position (MxButton *button) { g_return_val_if_fail (MX_IS_BUTTON (button), MX_POSITION_LEFT); return button->priv->icon_position; }
/** * mx_button_get_toggled: * @button: a #MxButton * * Get the state of the button that is in toggle mode. * * Returns: #TRUE if the button is toggled, or #FALSE if not */ gboolean mx_button_get_toggled (MxButton *button) { g_return_val_if_fail (MX_IS_BUTTON (button), FALSE); return button->priv->is_toggled; }
/** * mx_button_get_action: * @button: A #MxButton * * Retrieves the #MxAction associated with @button. * * Returns: (transfer none): A #MxAction * * Since: 1.2 */ MxAction * mx_button_get_action (MxButton *button) { g_return_val_if_fail (MX_IS_BUTTON (button), NULL); return button->priv->action; }
/** * mx_button_get_label: * @button: a #MxButton * * Get the text displayed on the button * * Returns: the text for the button. This must not be freed by the application */ const gchar * mx_button_get_label (MxButton *button) { g_return_val_if_fail (MX_IS_BUTTON (button), NULL); return button->priv->text; }
/** * mx_button_get_label_visible: * @button: A #MxButton * * Retrieves the visibility of the text associated with the button's action. * * Returns: %TRUE if the text is visible, %FALSE otherwise * * Since: 1.2 */ gboolean mx_button_get_label_visible (MxButton *button) { g_return_val_if_fail (MX_IS_BUTTON (button), FALSE); return button->priv->label_visible; }
/** * mx_button_get_icon_name: * @button: a #MxButton * * Get the icon-name being used on the button. * * Returns: the icon-name. This must not be freed by the application. %NULL if * no icon has been set * * Since: 1.2 */ const gchar * mx_button_get_icon_name (MxButton *button) { g_return_val_if_fail (MX_IS_BUTTON (button), NULL); return button->priv->icon_name ? button->priv->icon_name : button->priv->style_icon_name; }
/** * mx_button_get_icon_size: * @button: a #MxButton * * Retrieves the icon-size being used for the displayed icon inside the button. * * Returns: The icon-size being used for the button icon, in pixels * * Since: 1.2 */ guint mx_button_get_icon_size (MxButton *button) { g_return_val_if_fail (MX_IS_BUTTON (button), 0); return button->priv->icon_size ? button->priv->icon_size : button->priv->style_icon_size; }
/** * mx_button_set_is_toggle: * @button: a #MxButton * @toggle: #TRUE or #FALSE * * Enables or disables toggle mode for the button. In toggle mode, the active * state will be "toggled" when the user clicks the button. */ void mx_button_set_is_toggle (MxButton *button, gboolean toggle) { g_return_if_fail (MX_IS_BUTTON (button)); button->priv->is_toggle = toggle; g_object_notify (G_OBJECT (button), "is-toggle"); }
/** * mx_button_set_icon_visible: * @button: A #MxButton * @visible: %TRUE if the icon should be visible * * Sets the visibility of the icon associated with the button's action. * * Since: 1.2 */ void mx_button_set_icon_visible (MxButton *button, gboolean visible) { MxButtonPrivate *priv; g_return_if_fail (MX_IS_BUTTON (button)); priv = button->priv; if (priv->icon_visible != visible) { priv->icon_visible = visible; mx_button_update_contents (button); g_object_notify (G_OBJECT (button), "icon-visible"); } }
/** * mx_button_set_toggled: * @button: a #MxButton * @toggled: #TRUE or #FALSE * * Sets the toggled state of the button. This is only really useful if the * button has #toggle-mode mode set to #TRUE. */ void mx_button_set_toggled (MxButton *button, gboolean toggled) { g_return_if_fail (MX_IS_BUTTON (button)); if (button->priv->is_toggled != toggled) { button->priv->is_toggled = toggled; if (toggled) mx_stylable_style_pseudo_class_add (MX_STYLABLE (button), "checked"); else mx_stylable_style_pseudo_class_remove (MX_STYLABLE (button), "checked"); g_object_notify (G_OBJECT (button), "toggled"); } }
/** * mx_button_set_icon_position: * @button: A #MxButton * @position: A #MxPosition * * Sets the icon position, relative to the text on the button. * * Since: 1.2 */ void mx_button_set_icon_position (MxButton *button, MxPosition position) { MxButtonPrivate *priv; g_return_if_fail (MX_IS_BUTTON (button)); priv = button->priv; if (priv->icon_position != position) { priv->icon_position = position; mx_button_update_contents (button); g_object_notify (G_OBJECT (button), "icon-position"); } }
/** * mx_button_group_add: * @group: A #MxButtonGroup * @button: A #MxButton * * Add @button to the #MxButtonGroup. * */ void mx_button_group_add (MxButtonGroup *group, MxButton *button) { g_return_if_fail (MX_IS_BUTTON_GROUP (group)); g_return_if_fail (MX_IS_BUTTON (button)); group->priv->children = g_slist_prepend (group->priv->children, button); g_signal_connect (button, "notify::toggled", G_CALLBACK (button_toggled_notify_cb), group); g_signal_connect (button, "button-press-event", G_CALLBACK (button_click_intercept), group); g_signal_connect (button, "button-release-event", G_CALLBACK (button_click_intercept), group); g_object_weak_ref (G_OBJECT (button), (GWeakNotify) button_weak_notify, group); }
/** * mx_button_set_icon_name: * @button: a #MxButton * @icon_name: (allow-none): icon-name to use on the button * * Sets the icon-name used to display an icon on the button. Setting %NULL * will remove the icon name, or resort to the icon-name set in the current * style. Setting an icon name overrides any icon set in the style. * * Since: 1.2 */ void mx_button_set_icon_name (MxButton *button, const gchar *icon_name) { MxButtonPrivate *priv; g_return_if_fail (MX_IS_BUTTON (button)); priv = button->priv; g_free (priv->icon_name); priv->icon_name = g_strdup (icon_name); mx_icon_set_icon_name (MX_ICON (priv->icon), icon_name ? icon_name : priv->style_icon_name); mx_button_update_contents (button); g_object_notify (G_OBJECT (button), "icon-name"); }
/** * mx_button_set_icon_size: * @button: a #MxButton * * Sets the icon-size to use for the icon displayed inside the button. This will * override the icon-size set in the style. Setting a value of %0 resets to the * size from the style. * * Since: 1.2 */ void mx_button_set_icon_size (MxButton *button, guint icon_size) { MxButtonPrivate *priv; g_return_if_fail (MX_IS_BUTTON (button)); priv = button->priv; if (priv->icon_size != icon_size) { priv->icon_size = icon_size; mx_icon_set_icon_size (MX_ICON (priv->icon), icon_size ? icon_size : priv->style_icon_size); g_object_notify (G_OBJECT (button), "icon-size"); } }
/** * mx_button_set_action: * @button: A #MxButton * @action: A #MxAction * * Sets @action as the action for @button. @Button will take its label and * icon from @action. * * Since: 1.2 */ void mx_button_set_action (MxButton *button, MxAction *action) { MxButtonPrivate *priv; const gchar *display_name; g_return_if_fail (MX_IS_BUTTON (button)); g_return_if_fail (MX_IS_ACTION (action)); priv = button->priv; if (priv->action) g_object_unref (priv->action); if (priv->action_label_binding) g_object_unref (priv->action_label_binding); if (priv->action_icon_binding) g_object_unref (priv->action_icon_binding); priv->action = g_object_ref_sink (action); display_name = mx_action_get_display_name (action); mx_icon_set_icon_name (MX_ICON (priv->icon), mx_action_get_icon (action)); clutter_text_set_text (CLUTTER_TEXT (priv->label), (display_name) ? display_name : ""); /* bind action properties to button properties */ priv->action_label_binding = g_object_bind_property (action, "display-name", priv->label, "text", 0); priv->action_icon_binding = g_object_bind_property (action, "icon", priv->icon, "icon-name", 0); mx_button_update_contents (button); }
/** * mx_button_set_label: * @button: a #MxButton * @text: text to set the label to * * Sets the text displayed on the button */ void mx_button_set_label (MxButton *button, const gchar *text) { MxButtonPrivate *priv; g_return_if_fail (MX_IS_BUTTON (button)); priv = button->priv; g_free (priv->text); if (text) priv->text = g_strdup (text); else priv->text = g_strdup (""); clutter_text_set_text (CLUTTER_TEXT (priv->label), priv->text); mx_button_update_contents (button); g_object_notify (G_OBJECT (button), "label"); }
/** * mx_button_group_set_active_button: * @group: A #MxButtonGroup * @button: (allow-none): A #MxButton * * Set the current active button in the group. The previous active button will * have #MxButton:toggled set to #FALSE. * */ void mx_button_group_set_active_button (MxButtonGroup *group, MxButton *button) { MxButtonGroupPrivate *priv; g_return_if_fail (MX_IS_BUTTON_GROUP (group)); g_return_if_fail (button == NULL || MX_IS_BUTTON (button)); priv = group->priv; if (button == priv->active_button) return; if (priv->active_button) mx_button_set_toggled (priv->active_button, FALSE); if (button) mx_button_set_toggled (button, TRUE); priv->active_button = button; g_object_notify (G_OBJECT (group), "active-button"); }
/** * mx_button_group_remove: * @group: A #MxButtonGroup * @button: A #MxButton * * Remove @button from the #MxButtonGroup * */ void mx_button_group_remove (MxButtonGroup *group, MxButton *button) { GSList *l, *prev = NULL, *next; MxButtonGroupPrivate *priv; gboolean found; g_return_if_fail (MX_IS_BUTTON_GROUP (group)); g_return_if_fail (MX_IS_BUTTON (button)); priv = group->priv; /* check the button exists in this group */ found = FALSE; for (l = priv->children; l; l = g_slist_next (l)) { if ((MxButton*) l->data == button) { found = TRUE; break; } prev = l; } if (!found) return; next = g_slist_next (l); priv->children = g_slist_remove (priv->children, button); g_signal_handlers_disconnect_by_func (button, button_toggled_notify_cb, group); g_signal_handlers_disconnect_by_func (button, button_click_intercept, group); g_object_weak_unref (G_OBJECT (button), (GWeakNotify) button_weak_notify, group); if (priv->active_button == button) { /* Try and select another button if the one we've removed is active. * But we shouldn't do this in the case where we allow no active button. */ if (priv->allow_no_active) { mx_button_group_set_active_button (group, NULL); } else if (prev) { mx_button_group_set_active_button (group, (MxButton *) prev->data); } else if (next) { mx_button_group_set_active_button (group, (MxButton *) next->data); } else if (priv->children) { mx_button_group_set_active_button (group, (MxButton *) priv->children->data); } else { mx_button_group_set_active_button (group, NULL); } } }