Пример #1
0
/*
 * Sets the properties of the widget. This is used for both applying the
 * properties changed in the property editor, and also for loading.
 */
static void
gb_menu_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data)
{
  gboolean input_label = TRUE, input_rest = TRUE;
  GtkAccelGroup *accel_group;
  guint key;
  GdkModifierType modifiers;

  /* We only support loading the properties here. */
  if (data->action != GB_LOADING)
    return;

#ifdef USE_GNOME
  /* Check for a stock menu item. */
  if (glade_project_get_gnome_support (data->project))
    {
      GnomeUIInfo *uiinfo;
      gchar *stock_item;
      GtkWidget *label;
      gint stock_item_index;

      stock_item = gb_widget_input_string (data, "stock_item");
      if (stock_item && stock_item[0])
	{
	  /* Special case for the NEW_SUBTREE. */
	  if (!strcmp (stock_item, "GNOMEUIINFO_MENU_NEW_SUBTREE"))
	    {
	      stock_item_index = GladeStockMenuItemNew;
	    }
	  else
	    {
	      stock_item_index = glade_util_string_array_index (GladeStockMenuItemSymbols, GladeStockMenuItemSize, stock_item);
	    }

	  if (stock_item_index != -1)
	    {
	      uiinfo = &GladeStockMenuItemValues[stock_item_index];
	      if (uiinfo->type == GNOME_APP_UI_ITEM_CONFIGURABLE)
		gnome_app_ui_configure_configurable (uiinfo);

	      /* Note that we don't have to worry about the pixmap, since if
		 it had a pixmap it would be a GtkImageMenuItem. */

	      label = gtk_accel_label_new ("");
	      gtk_label_set_text_with_mnemonic (GTK_LABEL (label),
						uiinfo->label);
	      gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
	      gtk_widget_show (label);
	      gtk_accel_label_set_accel_widget (GTK_ACCEL_LABEL (label),
						widget);
	      gtk_container_add (GTK_CONTAINER (widget), label);

	      /* Add the configured accelerator key. */
	      if (uiinfo->accelerator_key != 0 && widget->parent
		  && GTK_IS_MENU (widget->parent))
		{
		  accel_group = GTK_MENU (widget->parent)->accel_group;
		  gtk_widget_add_accelerator (widget, "activate", accel_group,
					      uiinfo->accelerator_key,
					      uiinfo->ac_mods,
					      GTK_ACCEL_VISIBLE);
		}

	      /* Remember the index of the stock item. */
	      gtk_object_set_data (GTK_OBJECT (widget),
				   GladeMenuItemStockIndexKey,
				   GINT_TO_POINTER (stock_item_index));

	      /* The 'New' item can have a label. The rest can't. */
	      if (stock_item_index != GladeStockMenuItemNew)
		input_label = FALSE;
	      input_rest = FALSE;
	    }
	  else
	    {
#ifdef FIXME
	      load_add_error_message_with_tag (data,
					       GLADE_LINE_PROPERTY,
					       _("Invalid stock menu item"),
					       "stock_item", stock_item);
#endif
	    }
	}
    }
#endif

  if (input_label)
    gb_widget_input_child_label (widget, data, Label);

  if (input_rest)
    {
      /* FIXME: should this be somewhere else? */
      /* If we are loading, install the 'activate' accelerator, if it has one,
	 so that is is visible. */
      if (data->action == GB_LOADING && widget->parent
	  && GTK_IS_MENU (widget->parent))
	{
	  int i;

	  for (i = 0; i < data->widget_info->n_accels; i++)
	    {
	      if (!strcmp (data->widget_info->accels[i].signal, "activate"))
		{
		  key = data->widget_info->accels[i].key;
		  modifiers = data->widget_info->accels[i].modifiers;
		  accel_group = GTK_MENU (widget->parent)->accel_group;
		  gtk_widget_add_accelerator (widget, "activate", accel_group,
					      key, modifiers,
					      GTK_ACCEL_VISIBLE);
		  break;
		}
	    }
	}
    }
}
Пример #2
0
/*
 * Sets the properties of the widget. This is used for both applying the
 * properties changed in the property editor, and also for loading.
 */
static void
gb_radio_button_set_properties (GtkWidget * widget, GbWidgetSetArgData * data)
{
  gboolean state, indicator;
  gchar *group_name;
  GSList *group = NULL, *current_group;
  GbFindGroupData find_group_data;

  if (gb_toolbar_is_toolbar_button (widget))
    {
      gb_toolbar_input_child_label (widget, data, Label);
      gb_toolbar_input_child_icon (widget, data, Icon);
    }
  else
    {
      gb_widget_input_child_label (widget, data, Label);
    }

  state = gb_widget_input_bool (data, State);
  if (data->apply)
    {
      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), state);
      if (state)
	data->widget_data->flags |= GLADE_ACTIVE;
      else
	data->widget_data->flags &= ~GLADE_ACTIVE;
    }

  indicator = gb_widget_input_bool (data, Indicator);
  if (data->apply)
    gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (widget), indicator);

  /* Find any widgets in given group and set this widgets group.
     If group is NULL try to find radiobuttons with same parent and use
     their group. If these don't succeed, set group to NULL. */
  group_name = gb_widget_input_combo (data, Group);
  if (data->apply)
    {
      if (group_name && group_name[0] == '\0')
	group_name = NULL;
      current_group = gtk_radio_button_group (GTK_RADIO_BUTTON (widget));

      if (group_name == NULL)
	gtk_container_foreach (GTK_CONTAINER (widget->parent),
			       (GtkCallback) find_parents_group, &group);
      else
	{
	  find_group_data.group_name = group_name;
	  find_group_data.group = NULL;
	  find_group (gtk_widget_get_toplevel (widget), &find_group_data);
	  group = find_group_data.group;
	}

      g_free (gtk_object_get_data (GTK_OBJECT (widget), Group));
      gtk_object_set_data (GTK_OBJECT (widget), Group, g_strdup (group_name));

      /* This crashes if we set the group to NULL, so we have to reset the
         group ourself. We only set the group if it has changed. */
      if (group)
	{
	  if (group != current_group)
	    {
	      if (current_group->data == widget)
		current_group = current_group->next;
	      gtk_radio_button_set_group (GTK_RADIO_BUTTON (widget), group);
	      gb_radio_button_update_radio_group (current_group);
	      gb_radio_button_update_radio_group (gtk_radio_button_group (GTK_RADIO_BUTTON (widget)));
	    }
	}
      else
	{
	  if (g_slist_length (current_group) != 1)
	    {
	      current_group = gb_radio_button_reset_radio_group (widget);
	      gb_radio_button_update_radio_group (current_group);
	      gb_radio_button_update_radio_group (gtk_radio_button_group (GTK_RADIO_BUTTON (widget)));
	    }
	}
    }
}
Пример #3
0
/*
 * Sets the properties of the widget. This is used for both applying the
 * properties changed in the property editor, and also for loading.
 */
static void
gb_list_item_set_properties (GtkWidget * widget, GbWidgetSetArgData * data)
{
  gb_widget_input_child_label (widget, data, Label);
}