Esempio n. 1
0
/*
 * Writes the source code needed to create this widget.
 * You have to output everything necessary to create the widget here, though
 * there are some convenience functions to help.
 */
static void
gb_menu_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  GtkWidget *child = GTK_BIN (widget)->child;
  gchar *label_text;
  gboolean translatable, context;
  gchar *comments;

#ifdef USE_GNOME
  if (data->project->gnome_support)
    {
      glade_gnome_write_menu_item_source (GTK_MENU_ITEM (widget), data);
      return;
    }
#endif

  if (child && GTK_IS_LABEL (child) && !GB_IS_GB_WIDGET (child))
    {
      glade_util_get_translation_properties (widget, Label, &translatable,
					     &comments, &context);
      source_add_translator_comments (data, translatable, comments);

      label_text = glade_util_get_label_text (child);
      source_add (data, "  %s = gtk_menu_item_new_with_mnemonic (%s);\n",
		  data->wname,
		  source_make_string_full (label_text, data->use_gettext && translatable, context));
      g_free (label_text);
    }
  else
    {
      source_add (data, "  %s = gtk_menu_item_new ();\n", data->wname);
    }

  gb_widget_write_standard_source (widget, data);
}
Esempio n. 2
0
/*
 * Writes the source code needed to create this widget.
 * You have to output everything necessary to create the widget here, though
 * there are some convenience functions to help.
 */
static void
gb_radio_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  GtkWidget *child = GTK_BUTTON (widget)->child;
  gchar *label_text;
  gchar buffer[256];

  gchar *group_name = gtk_object_get_data (GTK_OBJECT (widget), Group);
  if (!group_name)
    group_name = gtk_widget_get_name (widget->parent);

  if (data->create_widget)
    {
      if (gb_toolbar_is_toolbar_button (widget))
	{
	  gb_toolbar_write_toolbar_button_source (widget, data);
	}
      else
	{
	  /* Make sure the temporary group list variable is declared. */
	  group_name = source_create_valid_identifier (group_name);
	  sprintf (buffer, "  GSList *%s_group = NULL;\n", group_name);
	  source_ensure_decl (data, buffer);

	  if (child && GTK_IS_LABEL (child) && !GB_IS_GB_WIDGET (child))
	    {
	      label_text = glade_util_get_label_text (GTK_BIN (widget)->child);
	      /* If there is an underlined accelerator, set up the signal. */
	      if (strchr (label_text, '_'))
		{
		  source_add (data,
			      "  %s = gtk_radio_button_new_with_label (%s_group, \"\");\n",
			      data->wname, group_name);
		  gb_button_write_uline_accel_source (widget, data,
						      label_text);
		}
	      else
		{
		  source_add (data,
			      "  %s = gtk_radio_button_new_with_label (%s_group, %s);\n",
			      data->wname, group_name,
			      source_make_string (label_text,
						  data->use_gettext));
		}
	      g_free (label_text);
	    }
	  else
	    {
	      source_add (data, "  %s = gtk_radio_button_new (%s_group);\n",
			  data->wname, group_name);
	    }
	  source_add (data,
		      "  %s_group = gtk_radio_button_group (GTK_RADIO_BUTTON (%s));\n",
		      group_name, data->wname);
	  g_free (group_name);
	}
    }
  gb_widget_write_standard_source (widget, data);

  if (data->widget_data->flags & GLADE_ACTIVE)
    {
      source_add (data,
	  "  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (%s), TRUE);\n",
		  data->wname);
    }
  if (!GTK_TOGGLE_BUTTON (widget)->draw_indicator)
    {
      source_add (data,
	  "  gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (%s), FALSE);\n",
		  data->wname);
    }
}