/* * 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_label_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { if (data->create_widget) { const gchar *label_text = gtk_label_get_label (GTK_LABEL (widget)); if (gtk_label_get_use_underline (GTK_LABEL (widget))) source_add (data, " %s = gtk_label_new_with_mnemonic (%s);\n", data->wname, source_make_string (label_text, data->use_gettext)); else source_add (data, " %s = gtk_label_new (%s);\n", data->wname, source_make_string (label_text, data->use_gettext)); } gb_widget_write_standard_source (widget, data); gb_label_write_standard_source (widget, data, Label, UseUnderline, UseMarkup, Justify, Wrap, Selectable, XAlign, YAlign, XPad, YPad, FocusTarget); }
static void add_menuitem_to_source (GtkWidget * widget, GbWriteMenuItemSourceData * write_data) { gchar *label_text; GtkWidget *menuitem, *child = GTK_BIN (widget)->child; menuitem = GTK_OPTION_MENU (write_data->option_menu)->menu_item; if (child == NULL && menuitem == widget) { child = GTK_BUTTON (write_data->option_menu)->child; write_data->selected_index = write_data->index; } if (child && GTK_IS_LABEL (child)) { gtk_label_get (GTK_LABEL (child), &label_text); source_add (write_data->data, " glade_menuitem = gtk_menu_item_new_with_label (%s);\n" " gtk_widget_show (glade_menuitem);\n" " gtk_menu_append (GTK_MENU (%s_menu), glade_menuitem);\n", source_make_string (label_text, write_data->data->use_gettext), write_data->data->real_wname); } write_data->index++; }
/* * 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_file_selection_write_source (GtkWidget * widget, GbWidgetWriteSourceData *data) { gchar *wname, *child_name; if (data->create_widget) { source_add (data, " %s = gtk_file_selection_new (%s);\n", data->wname, source_make_string (GTK_WINDOW (widget)->title, data->use_gettext)); } gb_widget_write_standard_source (widget, data); /* The title is already set above, so we pass NULL to skip it. */ gb_window_write_standard_source (widget, data, NULL, Type, Position, Modal, DefaultWidth, DefaultHeight, Shrink, Grow, AutoShrink, WMName, WMClass, Resizable, DestroyWithParent, Icon); if (GTK_FILE_SELECTION (widget)->fileop_c_dir == NULL) { source_add (data, " gtk_file_selection_hide_fileop_buttons (GTK_FILE_SELECTION (%s));\n", data->wname); } /* We output the source code for the buttons here, but we don't want them to be created. 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 = (gchar*) gtk_widget_get_name (GTK_FILE_SELECTION (widget)->ok_button); child_name = source_create_valid_identifier (child_name); source_add (data, " %s = GTK_FILE_SELECTION (%s)->ok_button;\n", child_name, wname); g_free (child_name); data->create_widget = FALSE; gb_widget_write_source (GTK_FILE_SELECTION (widget)->ok_button, data); child_name = (gchar*) gtk_widget_get_name (GTK_FILE_SELECTION (widget)->cancel_button); child_name = source_create_valid_identifier (child_name); source_add (data, " %s = GTK_FILE_SELECTION (%s)->cancel_button;\n", child_name, wname); g_free (child_name); data->create_widget = FALSE; gb_widget_write_source (GTK_FILE_SELECTION (widget)->cancel_button, data); g_free (wname); data->write_children = FALSE; }
static void write_items_source_callback (GtkWidget * item, GbWidgetWriteSourceData * data) { gchar *label_text; gtk_label_get (GTK_LABEL (GTK_BIN (item)->child), &label_text); /* The (gpointer) cast is just to keep g++ happy. */ source_add (data, " %s_items = g_list_append (%s_items, (gpointer) %s);\n", data->real_wname, data->real_wname, source_make_string (label_text, data->use_gettext)); }
/* * 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_app_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { gchar *appname; gboolean translatable, context; gchar *comments; if (data->create_widget) { appname = glade_project_get_name (data->project); appname = appname ? source_make_string (appname, FALSE) : "\"\""; appname = g_strdup (appname); glade_util_get_translation_properties (widget, Title, &translatable, &comments, &context); source_add_translator_comments (data, translatable, comments); /* Note that this assumes that we use the same appname for each GnomeApp. FIXME: I think this is correct, but I'm not sure. Note also that we don't translate the project name. Maybe we should.*/ source_add (data, " %s = gnome_app_new (%s, %s);\n", data->wname, appname, GTK_WINDOW (widget)->title ? source_make_string_full (GTK_WINDOW (widget)->title, data->use_gettext && translatable, context) : "NULL"); g_free (appname); } gb_widget_write_standard_source (widget, data); /* The title is already set above, so we pass NULL to skip it. */ gb_window_write_standard_source (widget, data, NULL, Type, Position, Modal, DefaultWidth, DefaultHeight, Shrink, Grow, AutoShrink, IconName, FocusOnMap, Resizable, DestroyWithParent, Icon, Role, TypeHint, SkipTaskbar, SkipPager, Decorated, Gravity, Urgency); if (!GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), EnableLayoutConfig))) { source_add (data, " gnome_app_enable_layout_config (GNOME_APP (%s), FALSE);\n", data->wname); } }
/* * 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_accel_label_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { if (data->create_widget) { const gchar *label_text = gtk_label_get_label (GTK_LABEL (widget)); source_add (data, " %s = gtk_accel_label_new (%s);\n", data->wname, source_make_string (label_text, data->use_gettext)); } gb_widget_write_standard_source (widget, data); if (gtk_label_get_use_underline (GTK_LABEL (widget))) source_add (data, " gtk_label_set_use_underline (%s, TRUE);\n", data->wname); }
/* * 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_icon_entry_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { gchar *title, *history_id; gint max_saved; gboolean translatable, context; gchar *comments; title = gtk_object_get_data (GTK_OBJECT (widget), Title); if (title && title[0] == '\0') title = NULL; history_id = gtk_object_get_data (GTK_OBJECT (widget), HistoryID); if (history_id && history_id[0] == '\0') history_id = NULL; if (data->create_widget) { glade_util_get_translation_properties (widget, Title, &translatable, &comments, &context); source_add_translator_comments (data, translatable, comments); source_add (data, " %s = gnome_icon_entry_new (%s, ", data->wname, history_id ? source_make_string (history_id, FALSE) : "NULL"); source_add (data, "%s);\n", title ? source_make_string_full (title, data->use_gettext && translatable, context) : "NULL"); } gb_widget_write_standard_source (widget, data); /* Note that GLADE_DEFAULT_MAX_HISTORY_SAVED is copied from gnome-entry.c */ max_saved = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), MaxSaved)); if (max_saved != GLADE_DEFAULT_MAX_HISTORY_SAVED) source_add (data, " gnome_entry_set_max_saved (GNOME_ENTRY (gnome_icon_entry_gnome_entry (GNOME_ICON_ENTRY (%s))), %i);\n", data->wname, max_saved); }
/* * 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_href_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { gboolean translatable, context; gchar *comments; if (data->create_widget) { gchar *url, *label_text; g_object_get (G_OBJECT (widget), "url", &url, "text", &label_text, NULL); glade_util_get_translation_properties (widget, HRefURL, &translatable, &comments, &context); source_add_translator_comments (data, translatable, comments); source_add (data, " %s = gnome_href_new (%s, ", data->wname, url && *url ? source_make_string (url, FALSE) : "\"\""); source_add (data, "%s);\n", source_make_string_full (label_text, data->use_gettext && translatable, context)); } gb_widget_write_standard_source (widget, data); if (!gtk_button_get_focus_on_click (GTK_BUTTON (widget))) { source_add (data, " gtk_button_set_focus_on_click (GTK_BUTTON (%s), FALSE);\n", data->wname); } }
/* * 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); } }
/* * 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_box_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { gchar *items, *pos, *items_end; gboolean translatable, context; gchar *comments; gboolean add_tearoffs, focus_on_click; items = pos = gtk_object_get_data (GTK_OBJECT (widget), Items); glade_util_get_translation_properties (widget, Items, &translatable, &comments, &context); if (data->create_widget) { /* If any items have been entered, we create a simple text combo, otherwise we create a bare combo without a model, so the user can setup the model in their code. */ /* NOTE: Creating it without a model causes problems so we always create a model now. Users can still set the model to something else. */ #if 0 if (items && items[0]) { source_add (data, " %s = gtk_combo_box_new_text ();\n", data->wname); } else { source_add (data, " %s = gtk_combo_box_new ();\n", data->wname); } #endif source_add (data, " %s = gtk_combo_box_text_new ();\n", data->wname); } gb_widget_write_standard_source (widget, data); if (items && items[0]) { items_end = &items[strlen (items)]; while (pos < items_end) { gchar *item_end = strchr (pos, '\n'); if (item_end == NULL) item_end = items_end; *item_end = '\0'; source_add (data, " gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (%s), %s);\n", data->wname, source_make_string (pos, data->use_gettext && translatable)); if (item_end != items_end) *item_end = '\n'; pos = item_end + 1; } } g_object_get (G_OBJECT (widget), "add_tearoffs", &add_tearoffs, "focus_on_click", &focus_on_click, NULL); if (add_tearoffs) { source_add (data, " gtk_combo_box_set_add_tearoffs (GTK_COMBO_BOX (%s), TRUE);\n", data->wname); } if (!focus_on_click) { source_add (data, " gtk_combo_box_set_focus_on_click (GTK_COMBO_BOX (%s), FALSE);\n", data->wname); } }
/* * 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_custom_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { gchar *creation_func, *string1, *string2; gint int1, int2; time_t last_mod_time; creation_func = gtk_object_get_data (GTK_OBJECT (widget), CreationFunction); string1 = gtk_object_get_data (GTK_OBJECT (widget), String1); string2 = gtk_object_get_data (GTK_OBJECT (widget), String2); int1 = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Int1)); int2 = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (widget), Int2)); /* If no creation function has been set, we skip the widget. */ if (creation_func == NULL) return; creation_func = source_create_valid_identifier (creation_func); /* Output "" if the strings are NULL, for consistency. */ if (string1 == NULL) string1 = ""; if (string2 == NULL) string2 = ""; if (string1) string1 = g_strdup (source_make_string (string1, FALSE)); if (string2) string2 = g_strdup (source_make_string (string2, FALSE)); /* Example output: custom1 = create_custom1 ("custom1", "string1", "string2", 5, 10); */ source_add (data, " %s = %s (%s, %s, %s, %i, %i);\n", data->wname, creation_func, source_make_string (data->real_wname, FALSE), string1 ? string1 : "NULL", string2 ? string2 : "NULL", int1, int2); gb_widget_write_standard_source (widget, data); /* Add declaration of creation function and empty function, just like a signal handler. We need a last_modification_time property. */ last_mod_time = gb_custom_get_last_mod_time (widget); if (data->creating_callback_files || (last_mod_time > data->last_write_time)) { source_add_to_buffer (data, GLADE_CALLBACK_DECLARATIONS, "\nGtkWidget*\n" "%s (gchar *widget_name, gchar *string1, gchar *string2,\n" " gint int1, gint int2);\n", creation_func); source_add_to_buffer (data, GLADE_CALLBACK_SOURCE, "\nGtkWidget*\n" "%s (gchar *widget_name, gchar *string1, gchar *string2,\n" " gint int1, gint int2)\n" "{\n\n}\n\n", creation_func); } g_free (creation_func); g_free (string1); g_free (string2); }
/* * 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_bonobo_dock_item_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { /* If we are in a GnomeApp's dock, we don't create the dock item here, or add it to the BonoboDock, since it is created automatically when the item is added to the GnomeApp. */ if (glade_gnome_is_app_dock_item (widget) && !BONOBO_DOCK_ITEM (widget)->is_floating) { return; } if (data->create_widget) { BonoboDockItemBehavior behavior; const gchar *prefix = "\n "; const gchar *prefix2 = "\n | "; behavior = BONOBO_DOCK_ITEM (widget)->behavior; source_add (data, " %s = bonobo_dock_item_new (%s,", data->wname, source_make_string (data->real_wname, FALSE)); if (behavior == 0) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NORMAL);\n", prefix); } else { if (behavior & BONOBO_DOCK_ITEM_BEH_EXCLUSIVE) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_EXCLUSIVE", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_FLOATING", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_LOCKED) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_LOCKED", prefix); } source_add (data, ");\n"); } } gb_widget_write_standard_source (widget, data); }
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); } } }
/* * 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_tool_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { GladeFindGroupData find_data; GtkWidget *group_widget; gchar *stock_id, *label, *icon_name; gchar buffer[256], *group_name; gboolean translatable, context; gchar *comments; stock_id = gtk_object_get_data (GTK_OBJECT (widget), GladeToolButtonStockIDKey); icon_name = gtk_object_get_data (GTK_OBJECT (widget), GladeToolButtonIconKey); label = (gchar*) gtk_tool_button_get_label (GTK_TOOL_BUTTON (widget)); glade_util_get_translation_properties (widget, Label, &translatable, &comments, &context); find_data.group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (widget)); find_data.found_widget = NULL; gb_widget_children_foreach (widget->parent, (GtkCallback) find_radio_group, &find_data); group_widget = find_data.found_widget; if (!group_widget) { g_warning ("Radiotoolbutton has no group"); group_widget = widget; } group_name = (char*) gtk_widget_get_name (group_widget); group_name = source_create_valid_identifier (group_name); sprintf (buffer, " GSList *%s_group = NULL;\n", group_name); source_ensure_decl (data, buffer); if (data->create_widget) { if (stock_id) { /* Stock Button */ source_add (data, " %s = (GtkWidget*) gtk_radio_tool_button_new_from_stock (NULL, %s);\n", data->wname, source_make_string (stock_id, FALSE)); } else if (icon_name) { /* Icon and Label */ source_add (data, " %s = (GtkWidget*) gtk_radio_tool_button_new (NULL);\n", data->wname); source_add_translator_comments (data, translatable, comments); source_add (data, " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", data->wname, label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); source_ensure_decl (data, " GtkWidget *tmp_image;\n"); if (glade_util_check_is_stock_id (icon_name)) { source_add (data, " tmp_image = gtk_image_new_from_stock (\"%s\", tmp_toolbar_icon_size);\n", icon_name); } else { source_create_pixmap (data, "tmp_image", icon_name); } source_add (data, " gtk_widget_show (tmp_image);\n"); source_add (data, " gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (%s), tmp_image);\n", data->wname); } else { /* Just a Label */ source_add (data, " %s = (GtkWidget*) gtk_radio_tool_button_new (NULL);\n", data->wname); source_add_translator_comments (data, translatable, comments); source_add (data, " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", data->wname, label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); } } gb_widget_write_standard_source (widget, data); source_add (data, " gtk_radio_tool_button_set_group (GTK_RADIO_TOOL_BUTTON (%s), %s_group);\n", data->wname, group_name); source_add (data, " %s_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (%s));\n", group_name, data->wname); if (data->widget_data->flags & GLADE_ACTIVE) { source_add (data, " gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (%s), TRUE);\n", data->wname); } if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) { source_add (data, " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", data->wname); } if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) { source_add (data, " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", data->wname); } if (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))) { source_add (data, " gtk_tool_item_set_is_important (GTK_TOOL_ITEM (%s), TRUE);\n", data->wname); } g_free (group_name); }
/* Outputs source to add a child menu to a BonoboDock. */ static void gb_bonobo_dock_item_write_add_child_source (GtkWidget * parent, const gchar *parent_name, GtkWidget *child, GbWidgetWriteSourceData * data) { GnomeApp *app; /* If we're adding a dock item to a GnomeApp's dock, we use the special functions to add it here. */ if ((app = glade_gnome_is_app_dock_item (parent))) { /* Children of floating items are added as normal. */ if (BONOBO_DOCK_ITEM (parent)->is_floating) { source_add (data, " gtk_container_add (GTK_CONTAINER (%s), %s);\n", parent_name, data->wname); } else if (GTK_IS_MENU_BAR (child)) { source_add (data, " gnome_app_create_menus (GNOME_APP (%s), %s_uiinfo);\n", data->component_name, data->real_wname); /* Output the code to install the menu hints, if the GnomeApp has a status bar. This must be output after the code to create the GnomeAppBar is output, so we add it to the same buffer as the signal connections. */ if (app->statusbar) { source_add_to_buffer (data, GLADE_SIGNAL_CONNECTIONS, " gnome_app_install_menu_hints (GNOME_APP (%s), %s_uiinfo);\n", data->component_name, data->real_wname); } } else { BonoboDockPlacement placement; BonoboDockItemBehavior behavior; const gchar *placement_string; gint idx, band_num, position, offset; gchar *prefix, *prefix2; if (gb_bonobo_dock_item_find_position (BONOBO_DOCK_ITEM (parent), &placement, &band_num, &position, &offset)) { idx = glade_util_int_array_index (GladePlacementValues, GladePlacementSize, placement); if (idx == -1) { g_warning ("BonoboDock placement not found"); placement = 0; } placement_string = GladePlacementSymbols[idx]; if (GTK_IS_TOOLBAR (child)) { source_add (data, " gnome_app_add_toolbar (GNOME_APP (%s), GTK_TOOLBAR (%s), %s,\n", data->component_name, data->wname, source_make_string (data->wname, FALSE)); } else { source_add (data, " gnome_app_add_docked (GNOME_APP (%s), %s, %s,\n", data->component_name, data->wname, source_make_string (data->wname, FALSE)); } source_add (data, " "); behavior = BONOBO_DOCK_ITEM (parent)->behavior; prefix = ""; prefix2 = "\n | "; if (behavior == BONOBO_DOCK_ITEM_BEH_NORMAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NORMAL", prefix); } else { if (behavior & BONOBO_DOCK_ITEM_BEH_EXCLUSIVE) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_EXCLUSIVE", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_FLOATING) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_FLOATING", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_NEVER_HORIZONTAL", prefix); prefix = prefix2; } if (behavior & BONOBO_DOCK_ITEM_BEH_LOCKED) { source_add (data, "%sBONOBO_DOCK_ITEM_BEH_LOCKED", prefix); prefix = prefix2; } } source_add (data, ",\n" " %s, %i, %i, %i);\n", placement_string, band_num, position, offset); } } } else { g_warning ("Skipping adding dock item to parent - unimplemented."); } }
/* * 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_bonobo_control_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { char *moniker = gtk_object_get_data (GTK_OBJECT (widget), Moniker); BonoboControlFrame *cf; Bonobo_PropertyBag pb; GList *key_list, *names; if (data->create_widget) { /* Currently we don't support BonoboWindow, so it will always be NIL, but if we ever do, then it just needs to set bonobo_uic when it is created. */ source_ensure_decl (data, " Bonobo_UIContainer bonobo_uic = CORBA_OBJECT_NIL;\n"); source_add (data, " %s = bonobo_widget_new_control (%s, bonobo_uic);\n", data->wname, source_make_string (moniker, FALSE)); } gb_widget_write_standard_source (widget, data); cf = bonobo_widget_get_control_frame (BONOBO_WIDGET (widget)); if (!cf) return; pb = bonobo_control_frame_get_control_property_bag (cf, NULL); source_ensure_decl (data, " BonoboControlFrame *bonobo_cf;\n"); source_ensure_decl (data, " Bonobo_PropertyBag bonobo_pb;\n"); source_add (data, " bonobo_cf = bonobo_widget_get_control_frame (BONOBO_WIDGET (%s));\n", data->wname); source_add (data, " bonobo_pb = bonobo_control_frame_get_control_property_bag (bonobo_cf, NULL);\n"); key_list = bonobo_pbclient_get_keys (pb, NULL); for (names = key_list; names; names = names->next) { CORBA_TypeCode tc; tc = bonobo_pbclient_get_type (pb, names->data, NULL); switch (tc->kind) { case CORBA_tk_boolean: { gboolean val = bonobo_pbclient_get_boolean (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_boolean (bonobo_pb, %s, %s, NULL);\n", source_make_string (names->data, FALSE), val ? "TRUE" : "FALSE"); break; } case CORBA_tk_string: { char *val = bonobo_pbclient_get_string (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_string (bonobo_pb, %s,", source_make_string (names->data, FALSE)); source_add (data, " %s, NULL);\n", source_make_string (val, data->use_gettext)); g_free (val); break; } case CORBA_tk_ulong: { gulong val = bonobo_pbclient_get_ulong (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_ulong (bonobo_pb, %s, %lu, NULL);\n", source_make_string (names->data, FALSE), val); break; } case CORBA_tk_long: { glong val = bonobo_pbclient_get_long (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_long (bonobo_pb, %s, %li, NULL);\n", source_make_string (names->data, FALSE), val); break; } case CORBA_tk_short: { gshort val = bonobo_pbclient_get_short (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_short (bonobo_pb, %s, %i, NULL);\n", source_make_string (names->data, FALSE), val); break; } case CORBA_tk_ushort: { gushort val = bonobo_pbclient_get_ushort (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_ushort (bonobo_pb, %s, %u, NULL);\n", source_make_string (names->data, FALSE), val); break; } case CORBA_tk_float: { gfloat val = bonobo_pbclient_get_float (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_float (bonobo_pb, %s, %g, NULL);\n", source_make_string (names->data, FALSE), val); break; } case CORBA_tk_double: { gdouble val = bonobo_pbclient_get_double (pb, names->data, NULL); source_add (data, " bonobo_pbclient_set_double (bonobo_pb, %s, %g, NULL);\n", source_make_string (names->data, FALSE), val); break; } default: g_warning ("Unhandled type %d", tc->kind); break; } } bonobo_pbclient_free_keys (key_list); }
/* * 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; }
/* * 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_toggle_tool_button_write_source (GtkWidget * widget, GbWidgetWriteSourceData * data) { gchar *stock_id, *label, *icon_name; gboolean translatable, context; gchar *comments; stock_id = gtk_object_get_data (GTK_OBJECT (widget), GladeToolButtonStockIDKey); icon_name = gtk_object_get_data (GTK_OBJECT (widget), GladeToolButtonIconKey); label = (gchar*) gtk_tool_button_get_label (GTK_TOOL_BUTTON (widget)); glade_util_get_translation_properties (widget, Label, &translatable, &comments, &context); if (data->create_widget) { if (stock_id) { /* Stock Button */ source_add (data, " %s = (GtkWidget*) gtk_toggle_tool_button_new_from_stock (%s);\n", data->wname, source_make_string (stock_id, FALSE)); } else if (icon_name) { /* Icon and Label */ source_add (data, " %s = (GtkWidget*) gtk_toggle_tool_button_new ();\n", data->wname); source_add_translator_comments (data, translatable, comments); source_add (data, " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", data->wname, label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); source_ensure_decl (data, " GtkWidget *tmp_image;\n"); if (glade_util_check_is_stock_id (icon_name)) { source_add (data, " tmp_image = gtk_image_new_from_stock (\"%s\", tmp_toolbar_icon_size);\n", icon_name); } else { source_create_pixmap (data, "tmp_image", icon_name); } source_add (data, " gtk_widget_show (tmp_image);\n"); source_add (data, " gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (%s), tmp_image);\n", data->wname); } else { /* Just a Label */ source_add (data, " %s = (GtkWidget*) gtk_toggle_tool_button_new ();\n", data->wname); source_add_translator_comments (data, translatable, comments); source_add (data, " gtk_tool_button_set_label (GTK_TOOL_BUTTON (%s), %s);\n", data->wname, label ? source_make_string_full (label, data->use_gettext && translatable, context) : "NULL"); } } gb_widget_write_standard_source (widget, data); if (data->widget_data->flags & GLADE_ACTIVE) { source_add (data, " gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (%s), TRUE);\n", data->wname); } if (gtk_object_get_data (GTK_OBJECT (widget), VisibleHorz) != NULL) { source_add (data, " gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (%s), FALSE);\n", data->wname); } if (gtk_object_get_data (GTK_OBJECT (widget), VisibleVert) != NULL) { source_add (data, " gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (%s), FALSE);\n", data->wname); } if (gtk_tool_item_get_is_important (GTK_TOOL_ITEM (widget))) { source_add (data, " gtk_tool_item_set_is_important (GTK_TOOL_ITEM (%s), TRUE);\n", data->wname); } }
/* * 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); }