Пример #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_spin_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  gint update_policy;
  GtkAdjustment *adj = GTK_SPIN_BUTTON (widget)->adjustment;

  if (data->create_widget)
    {
      source_add_decl (data, "  GObject *%s_adj;\n", data->real_wname);
      source_add (data,
		"  %s_adj = G_OBJECT(gtk_adjustment_new (%.12g, %.12g, %.12g, %.12g, %.12g, %.12g));\n",
		  data->real_wname, adj->value, adj->lower, adj->upper,
		  adj->step_increment, adj->page_increment, adj->page_size);
      source_add (data,
		  "  %s = gtk_spin_button_new (GTK_ADJUSTMENT (%s_adj), %.12g, %d);\n",
		  data->wname, data->real_wname,
		  GTK_SPIN_BUTTON (widget)->climb_rate,
		  GTK_SPIN_BUTTON (widget)->digits);
    }
  gb_widget_write_standard_source (widget, data);

  if (GTK_SPIN_BUTTON (widget)->numeric)
    {
      source_add (data,
		  "  gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (%s), TRUE);\n",
		  data->wname);
    }

  update_policy = GTK_SPIN_BUTTON (widget)->update_policy;
  if (update_policy != GTK_UPDATE_ALWAYS)
    {
      source_add (data,
		  "  gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (%s), GTK_UPDATE_IF_VALID);\n",
		  data->wname);
    }

  if (GTK_SPIN_BUTTON (widget)->snap_to_ticks)
      source_add (data,
		  "  gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (%s), TRUE);\n",
		  data->wname);

  if (GTK_SPIN_BUTTON (widget)->wrap)
    source_add (data,
		"  gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (%s), TRUE);\n",
		data->wname);
}
Пример #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_option_menu_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  GbWriteMenuItemSourceData write_data;

  if (data->create_widget)
    {
      source_add (data, "  %s = gtk_option_menu_new ();\n", data->wname);
    }

  gb_widget_write_standard_source (widget, data);

  source_add_decl (data, "  GtkWidget *%s_menu;\n", data->real_wname);

  source_add (data, "  %s_menu = gtk_menu_new ();\n", data->real_wname);

  /* Make sure the temporary menuitem widget is declared, if we need it. */
  if (GTK_MENU_SHELL (GTK_OPTION_MENU (widget)->menu)->children)
    source_ensure_decl (data, "  GtkWidget *glade_menuitem;\n");

  write_data.option_menu = widget;
  write_data.data = data;
  write_data.index = 0;
  write_data.selected_index = 0;
  gtk_container_foreach (GTK_CONTAINER (GTK_OPTION_MENU (widget)->menu),
			 (GtkCallback) add_menuitem_to_source, &write_data);

  source_add (data,
	    "  gtk_option_menu_set_menu (GTK_OPTION_MENU (%s), %s_menu);\n",
	      data->wname, data->real_wname);

  if (write_data.selected_index != 0)
    source_add (data,
	      "  gtk_option_menu_set_history (GTK_OPTION_MENU (%s), %i);\n",
		data->wname, write_data.selected_index);
}
Пример #3
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_combo_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  gchar *wname, *child_name;
  gboolean value_in_list, ok_if_empty;

  if (data->create_widget)
    {
      source_add (data, "  %s = gtk_combo_new ();\n", data->wname);
    }

  gb_widget_write_standard_source (widget, data);

  value_in_list = gtk_object_get_data (GTK_OBJECT (widget), ValueInList)
    != NULL ? TRUE : FALSE;
  if (value_in_list)
    {
      ok_if_empty = gtk_object_get_data (GTK_OBJECT (widget), OKIfEmpty)
	!= NULL ? TRUE : FALSE;
      source_add (data,
		  "  gtk_combo_set_value_in_list (GTK_COMBO (%s), %s, %s);\n",
		  data->wname,
		  value_in_list ? "TRUE" : "FALSE",
		  ok_if_empty ? "TRUE" : "FALSE");
    }


  if (GTK_COMBO (widget)->case_sensitive)
    {
      source_add (data,
		  "  gtk_combo_set_case_sensitive (GTK_COMBO (%s), TRUE);\n",
		  data->wname);
    }
  if (!GTK_COMBO (widget)->use_arrows)
    {
      source_add (data,
		  "  gtk_combo_set_use_arrows (GTK_COMBO (%s), FALSE);\n",
		  data->wname);
    }
  if (GTK_COMBO (widget)->use_arrows_always)
    {
      source_add (data,
		  "  gtk_combo_set_use_arrows_always (GTK_COMBO (%s), TRUE);\n",
		  data->wname);
    }

  if (is_simple_combo (widget) > 0)
    {
      source_add_decl (data, "  GList *%s_items = NULL;\n", data->real_wname);
      gtk_container_foreach (GTK_CONTAINER (GTK_COMBO (widget)->list),
			   (GtkCallback) write_items_source_callback, data);
      source_add (data,
		  "  gtk_combo_set_popdown_strings (GTK_COMBO (%s), %s_items);\n",
		  data->wname, data->real_wname);
      source_add (data, "  g_list_free (%s_items);\n", data->real_wname);
    }


  /* We output the source code for the children here, since the code should
     not include calls to create the widgets. We need to specify that the
     names used are like: "GTK_COMBO (<combo-name>)->entry".
     We need to remember the dialog's name since data->wname
     will be overwritten. */
  wname = g_strdup (data->wname);

  source_add (data, "\n");
  child_name = gtk_widget_get_name (GTK_COMBO (widget)->entry);
  child_name = source_create_valid_identifier (child_name);
  source_add (data, "  %s = GTK_COMBO (%s)->entry;\n",
	      child_name, wname);
  g_free (child_name);
  data->create_widget = FALSE;
  gb_widget_write_source (GTK_COMBO (widget)->entry, data);

  g_free (wname);
  data->write_children = FALSE;
}
Пример #4
0
void
gb_window_write_standard_source (GtkWidget * widget,
				 GbWidgetWriteSourceData * data,
				 gchar *title_p,
				 gchar *type_p,
				 gchar *position_p,
				 gchar *modal_p,
				 gchar *default_width_p,
				 gchar *default_height_p,
				 gchar *shrink_p,
				 gchar *grow_p,
				 gchar *auto_shrink_p,
				 gchar *wmname_p,
				 gchar *wmclass_p,
				 gchar *resizable_p,
				 gchar *destroy_with_parent_p,
				 gchar *icon_p)
{
  gint type, position, default_width, default_height;
#if 0
  gchar *wmname, *wmclass;
#endif

  if (title_p)
    {
      if (GTK_WINDOW (widget)->title
	  && strlen (GTK_WINDOW (widget)->title) > 0)
	source_add (data, "  gtk_window_set_title (GTK_WINDOW (%s), %s);\n",
		    data->wname,
		    source_make_string (GTK_WINDOW (widget)->title,
					data->use_gettext));
    }

  if (type_p)
    {
      type = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget),
						   type_p));
      if (type != GTK_WINDOW_TOPLEVEL)
	{
	  /* Note: there is no gtk_window_set_type () */
	  source_add (data, "  GTK_WINDOW (%s)->type = %s;\n",
		      data->wname, GbTypeSymbols[type]);
	}
    }

  if (position_p)
    {
      position = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget),
						       position_p));
      if (GbPositionValues[position] != GTK_WIN_POS_NONE)
	{
	  source_add (data,
		      "  gtk_window_set_position (GTK_WINDOW (%s), %s);\n",
		      data->wname, GbPositionSymbols[position]);
	}
    }

  if (modal_p)
    {
      if (gtk_object_get_data (GTK_OBJECT (widget), modal_p))
	{
	  source_add (data,
		      "  gtk_window_set_modal (GTK_WINDOW (%s), TRUE);\n",
		      data->wname);
	}
    }

  if (default_width_p && default_height_p)
    {
      default_width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget),
							    DefaultWidth));
      default_height = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget),
							     DefaultHeight));
      if (default_width || default_height )
	{
	  source_add (data,
		      "  gtk_window_set_default_size (GTK_WINDOW (%s), %i, %i);\n",
		      data->wname,
		      default_width ? default_width : -1,
		      default_height ? default_height : -1);
	}
    }

#if 0
  if (shrink_p && grow_p)
    {
      if (GTK_WINDOW (widget)->allow_grow != TRUE
	  || GTK_WINDOW (widget)->allow_shrink != FALSE)
	source_add (data,
		    "  gtk_window_set_policy (GTK_WINDOW (%s), %s, %s, %s);\n",
		    data->wname,
		    GTK_WINDOW (widget)->allow_shrink ? "TRUE" : "FALSE",
		    GTK_WINDOW (widget)->allow_grow ? "TRUE" : "FALSE",
		    "FALSE");
    }
#endif

#if 0
  /* These aren't necessary, and have been used incorrectly for ages. */
  if (wmname_p && wmclass_p)
    {
      wmname = gtk_object_get_data (GTK_OBJECT (widget), wmname_p);
      wmclass = gtk_object_get_data (GTK_OBJECT (widget), wmclass_p);
      if (wmname || wmclass)
	{
	  source_add (data,
		      "  gtk_window_set_wmclass (GTK_WINDOW (%s), %s,",
		      data->wname,
		      wmname ? source_make_string (wmname, FALSE) : "\"\"");
	  source_add (data, " %s);\n",
		      wmclass ? source_make_string (wmclass, FALSE) : "\"\"");
	}
    }
#endif

  if (resizable_p)
    {
      if (!gtk_window_get_resizable (GTK_WINDOW (widget)))
	source_add (data,
		    "  gtk_window_set_resizable (GTK_WINDOW (%s), FALSE);\n",
		    data->wname);
    }

  if (destroy_with_parent_p)
    {
      if (gtk_window_get_destroy_with_parent (GTK_WINDOW (widget)))
	source_add (data,
	"  gtk_window_set_destroy_with_parent (GTK_WINDOW (%s), TRUE);\n",
		    data->wname);
    }

  if (icon_p)
    {
      gchar *filename = gtk_object_get_data (GTK_OBJECT (widget), icon_p);
      if (filename && *filename)
	{
	  char *pixbuf_name = g_strdup_printf ("%s_icon_pixbuf", data->wname);

	  source_add_decl (data, "  GdkPixbuf *%s;\n", pixbuf_name);
	  source_create_pixbuf (data, pixbuf_name, filename);
	  source_add (data,
		      "  if (%s)\n"
		      "    {\n"
		      "      gtk_window_set_icon (GTK_WINDOW (%s), %s);\n"
		      "      gdk_pixbuf_unref (%s);\n"
		      "    }\n",
		      pixbuf_name,
		      data->wname, pixbuf_name,
		      pixbuf_name);

	  g_free (pixbuf_name);
	}
    }
}
Пример #5
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_gnome_message_box_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  GtkWidget *pixmap, *label;
  gchar *label_text;
  gint type_index;
  gchar *wname, *child_name;

  get_message_box_widgets (widget, &pixmap, &label);
  g_return_if_fail (pixmap != NULL);
  g_return_if_fail (label != NULL);

  type_index = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget),
						     MessageBoxType));
  gtk_label_get (GTK_LABEL (label), &label_text);

  if (data->create_widget)
    {
      source_add (data,
		  "  /* We create it with an OK button, and then remove the button, to work\n"
		  "     around a bug in gnome-libs. */\n"
		  "  %s = gnome_message_box_new (%s,\n"
		  "                              %s,\n"
		  "                              GNOME_STOCK_BUTTON_OK, NULL);\n",
		  data->wname,
		  source_make_string (label_text, data->use_gettext),
		  GbMessageBoxTypeSymbols[type_index]);

      source_add (data,
		  "  gtk_container_remove (GTK_CONTAINER (GNOME_DIALOG (%s)->action_area), GNOME_DIALOG (%s)->buttons->data);\n"
		  "  GNOME_DIALOG (%s)->buttons = NULL;\n",
		  data->wname, data->wname, data->wname);
    }

  gb_widget_write_standard_source (widget, data);

  gb_window_write_standard_source (widget, data,
				   Title, NULL, Position, Modal,
				   DefaultWidth, DefaultHeight,
				   Shrink, Grow, AutoShrink,
				   WMName, WMClass);

  if (!GNOME_DIALOG (widget)->click_closes)
    {
      source_add (data,
		  "  gnome_dialog_set_close (GNOME_DIALOG (%s), FALSE);\n",
		  data->wname);
    }

  if (GNOME_DIALOG (widget)->just_hide)
    {
      source_add (data,
		  "  gnome_dialog_close_hides (GNOME_DIALOG (%s), TRUE);\n",
		  data->wname);
    }


  /* We output the source code for the children here, since the code should
     not include calls to create the widgets. We need to specify that the
     names used are like: "GTK_DIALOG (<dialog-name>)->vbox".
     We need to remember the dialog's name since data->wname
     will be overwritten. */
  wname = g_strdup (data->wname);

  source_add (data, "\n");
  child_name = gtk_widget_get_name (GNOME_DIALOG (widget)->vbox);
  child_name = source_create_valid_identifier (child_name);
  source_add (data, "  %s = GNOME_DIALOG (%s)->vbox;\n",
	      child_name, wname);
  g_free (child_name);
  data->create_widget = FALSE;
  gb_widget_write_source (GNOME_DIALOG (widget)->vbox, data);

  /* action_area is a child of vbox so I had to add a kludge to stop it
     being written as a normal child - we need to do it here so that we
     don't output code to create it. */
  child_name = gtk_widget_get_name (GNOME_DIALOG (widget)->action_area);
  child_name = source_create_valid_identifier (child_name);

  data->create_widget = FALSE;
  gb_widget_write_source (GNOME_DIALOG (widget)->action_area, data);

  /* We need to move this after the above, because GnomeMessageBox doesn't
     actually create the action_area until a button is added. Note that this
     means we mustn't set any properties of the action_area above, (see
     gbhbuttonbox.c), and the GnomeMessageBox must have at least one button. */
  source_add (data, "  %s = GNOME_DIALOG (%s)->action_area;\n",
	      child_name, wname);

  /* Copied from gb_widget_write_standard_source(), until we decide on a better
     way to structure this. */
  source_add_decl (data, "  GtkWidget *%s;\n", child_name);

  /* If there aren't any buttons the pointer may be NULL, so we add a test. */
  if (data->set_widget_names)
    source_add (data,
		"  if (%s != NULL)\n"
		"    gtk_widget_set_name (%s, \"%s\");\n",
		child_name, child_name, child_name);

  if (!data->use_component_struct)
    {
      source_add (data,
		  "  gtk_widget_ref (%s);\n"
		  "  gtk_object_set_data_full (GTK_OBJECT (%s), %s, %s,\n"
		  "                            (GtkDestroyNotify) gtk_widget_unref);\n",
		  child_name,
		  data->component_name,
		  source_make_string (child_name, FALSE),
		  child_name);
    }

  g_free (child_name);

  g_free (wname);
  data->write_children = FALSE;
}
Пример #6
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_gnome_druid_page_standard_write_source (GtkWidget * widget,
					   GbWidgetWriteSourceData * data)
{
  GnomeDruidPageStandard *page;
  gchar *filename, *title;
  gchar *wname, *child_name;
  GdkColor title_color, background_color, logo_background_color;
  gboolean title_color_set, background_color_set, logo_background_color_set;

  page = GNOME_DRUID_PAGE_STANDARD (widget);

  /* We do this to make sure the colors are set. */
  gtk_widget_ensure_style (widget);

  if (data->create_widget)
    {
      source_add (data,
		  "  %s = gnome_druid_page_standard_new ();\n",
		  data->wname);
    }

  gb_widget_write_standard_source (widget, data);

  g_object_get (G_OBJECT (widget),
		"title-foreground-set", &title_color_set,
		"title-foreground-gdk", &title_color,
		"background-set", &background_color_set,
		"background-gdk", &background_color,
		"logo-background-set", &logo_background_color_set,
		"logo-background-gdk", &logo_background_color,
		"title", &title,
		NULL);

  if (background_color_set)
    {
      source_add_decl (data,
		       "  GdkColor %s_bg_color = { 0, %i, %i, %i };\n",
		       data->real_wname,
		       background_color.red, background_color.green, background_color.blue);
      source_add (data,
		  "  gnome_druid_page_standard_set_background (GNOME_DRUID_PAGE_STANDARD (%s), &%s_bg_color);\n",
		  data->wname, data->real_wname);
    }

  if (logo_background_color_set)
    {
      source_add_decl (data,
		       "  GdkColor %s_logo_bg_color = { 0, %i, %i, %i };\n",
		       data->real_wname,
		       logo_background_color.red, logo_background_color.green, logo_background_color.blue);
      source_add (data,
		  "  gnome_druid_page_standard_set_logo_background (GNOME_DRUID_PAGE_STANDARD (%s), &%s_logo_bg_color);\n",
		  data->wname, data->real_wname);
    }

  if (title_color_set)
    {
      source_add_decl (data,
		       "  GdkColor %s_title_color = { 0, %i, %i, %i };\n",
		       data->real_wname,
		       title_color.red, title_color.green, title_color.blue);
      source_add (data,
		  "  gnome_druid_page_standard_set_title_foreground (GNOME_DRUID_PAGE_STANDARD (%s), &%s_title_color);\n",
		  data->wname, data->real_wname);
    }

  if (gtk_object_get_data (GTK_OBJECT (widget), ContentsBackgroundColor))
    {
      GdkColor *color = &page->contents_background;
      source_add_decl (data,
		       "  GdkColor %s_contents_bg_color = { 0, %i, %i, %i };\n",
		       data->real_wname,
		       color->red, color->green, color->blue);
      source_add (data,
		  "  gnome_druid_page_standard_set_contents_background (GNOME_DRUID_PAGE_STANDARD (%s), &%s_contents_bg_color);\n",
		  data->wname, data->real_wname);
    }

  if (title && *title)
    {
      gboolean translatable, context;
      gchar *comments;

      glade_util_get_translation_properties (widget, Title, &translatable,
					     &comments, &context);
      source_add_translator_comments (data, translatable, comments);

      source_add (data,
		  "  gnome_druid_page_standard_set_title (GNOME_DRUID_PAGE_STANDARD (%s), %s);\n",
		  data->wname,
		  source_make_string_full (title, data->use_gettext && translatable, context));
    }
  g_free (title);

  filename = gtk_object_get_data (GTK_OBJECT (widget), LogoImage);
  if (filename && filename[0])
    {
      source_ensure_decl (data, "  GdkPixbuf *tmp_pixbuf;\n");

      source_add (data,
		  "  tmp_pixbuf = create_pixbuf (\"%s/%s\");\n"
		  "  if (tmp_pixbuf)\n"
		  "    {\n"
		  "      gnome_druid_page_standard_set_logo (GNOME_DRUID_PAGE_STANDARD (%s),\n"
		  "                                          tmp_pixbuf);\n"
		  "      gdk_pixbuf_unref (tmp_pixbuf);\n"
		  "    }\n",
		  data->program_name, g_basename (filename), data->wname);
    }

  filename = gtk_object_get_data (GTK_OBJECT (widget), TopWatermark);
  if (filename && filename[0])
    {
      source_ensure_decl (data, "  GdkPixbuf *tmp_pixbuf;\n");

      source_add (data,
		  "  tmp_pixbuf = create_pixbuf (\"%s/%s\");\n"
		  "  if (tmp_pixbuf)\n"
		  "    {\n"
		  "      gnome_druid_page_standard_set_top_watermark (GNOME_DRUID_PAGE_STANDARD (%s),\n"
		  "                                                   tmp_pixbuf);\n"
		  "      gdk_pixbuf_unref (tmp_pixbuf);\n"
		  "    }\n",
		  data->program_name, g_basename (filename), data->wname);
    }

  /* We output the source code for the children here, since the code should
     not include calls to create the widgets. We need to specify that the
     names used are like: "GTK_COMBO (<combo-name>)->entry".
     We need to remember the dialog's name since data->wname
     will be overwritten. */
  wname = g_strdup (data->wname);

  source_add (data, "\n");
  child_name = (char*) gtk_widget_get_name (GNOME_DRUID_PAGE_STANDARD (widget)->vbox);
  child_name = source_create_valid_identifier (child_name);
  source_add (data, "  %s = GNOME_DRUID_PAGE_STANDARD (%s)->vbox;\n",
	      child_name, wname);
  g_free (child_name);
  data->create_widget = FALSE;
  gb_widget_write_source (GNOME_DRUID_PAGE_STANDARD (widget)->vbox, data);

  g_free (wname);
  data->write_children = FALSE;
}
Пример #7
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_gnome_pixmap_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data)
{
  gchar *filename;
  gboolean scaled;
  gint width, height;

  filename = gtk_object_get_data (GTK_OBJECT (widget), Filename);
  if (filename && !*filename)
    filename = NULL;
  scaled = gtk_object_get_data (GTK_OBJECT (widget), Scaled) != NULL
    ? TRUE : FALSE;
  width = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Width));
  height = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Height));

  if (data->create_widget)
    {
      source_add (data,
		  "  %s = g_object_new (GNOME_TYPE_PIXMAP, NULL);\n",
		  data->wname);
    }

  if (filename)
    {
      filename = (gchar*) g_basename (filename);

      source_add_decl (data, "  gchar *%s_filename;\n", data->real_wname);
      /* FIXME: Should convert filename to a valid C string? */
      source_add (data,
		  "  %s_filename = gnome_program_locate_file (NULL,\n"
		  "    GNOME_FILE_DOMAIN_APP_PIXMAP, \"%s/%s\", TRUE, NULL);\n"
		  "  if (%s_filename)\n",
		  data->real_wname,
		  data->program_name, filename,
		  data->real_wname);

      if (scaled)
	{
	  source_add (data,
		      "    gnome_pixmap_load_file_at_size (GNOME_PIXMAP (%s), %s_filename, %i, %i);\n",
		      data->wname, data->real_wname, width, height);
	}
      else
	{
	  source_add (data,
		      "    gnome_pixmap_load_file (GNOME_PIXMAP (%s), %s_filename);\n",
		      data->wname, data->real_wname);
	}

      source_add (data,
		  "  else\n"
		  "    g_warning (%s, ",
		  source_make_string ("Couldn't find pixmap file: %s",
				      data->use_gettext));
      source_add (data,
		  "%s);\n",
		  source_make_string (filename, FALSE));

      source_add (data,  "  g_free (%s_filename);\n", data->real_wname);
    }

  gb_widget_write_standard_source (widget, data);
}