Exemple #1
0
/**
 * mx_combo_box_set_index:
 * @box: A #MxComboBox
 * @index: the index of the list item to set
 *
 * Set the current combo box text from the item at @index in the list.
 *
 */
void
mx_combo_box_set_index (MxComboBox *box,
                        gint        index)
{
  MxComboBoxPrivate *priv;
  GSList *item;
  MxAction *action;
  const gchar *icon_name;

  g_return_if_fail (MX_IS_COMBO_BOX (box));

  priv = box->priv;

  item = g_slist_nth (box->priv->actions, index);

  if (!item)
    {
      box->priv->index = -1;
      clutter_text_set_text ((ClutterText*) box->priv->label, NULL);
      return;
    }

  box->priv->index = index;
  action = (MxAction *)item->data;
  clutter_text_set_text ((ClutterText*) box->priv->label,
                         mx_action_get_display_name (action));

  if (priv->icon)
    {
      clutter_actor_remove_child (CLUTTER_ACTOR (box), priv->icon);
      priv->icon = NULL;
    }

  icon_name = mx_action_get_icon (item->data);
  if (icon_name)
    {
      MxIconTheme *icon_theme;

      icon_theme = mx_icon_theme_get_default ();
      if (mx_icon_theme_has_icon (icon_theme, icon_name))
        {
          priv->icon = mx_icon_new ();
          mx_icon_set_icon_name (MX_ICON (priv->icon), icon_name);
          clutter_actor_add_child (CLUTTER_ACTOR (box), priv->icon);
        }
    }

  g_object_notify (G_OBJECT (box), "index");
  g_object_notify (G_OBJECT (box), "active-text");
  g_object_notify (G_OBJECT (box), "active-icon-name");
}
Exemple #2
0
/**
 * 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);
}