void widget_table_removeselected(variable *var) { gchar *string; gchar *value; gint column = 0; gint count; gint row; gint selectionmode = GTK_SELECTION_SINGLE; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ if (var->widget_tag_attr) { /* Get current selection-mode (there's no function to do this) */ if ((value = get_tag_attribute(var->widget_tag_attr, "selection-mode"))) selectionmode = atoi(value); /* Get exported-column */ if ((value = get_tag_attribute(var->widget_tag_attr, "exported-column"))) column = atoi(value); } #ifdef DEBUG_CONTENT fprintf(stderr, "%s(): widget=%p selectionmode=%i column=%i\n", __func__, var->Widget, selectionmode, column); #endif if (selectionmode == GTK_SELECTION_NONE) { /* Nothing to do */ } else if (selectionmode == GTK_SELECTION_MULTIPLE) { /* I'm assuming that selection is updated on row removal so * it's likely not a good idea to iterate in a for loop */ count = g_list_length(GTK_CLIST(var->Widget)->selection); while (count) { row = (gint)g_list_nth_data(GTK_CLIST(var->Widget)->selection, 0); gtk_clist_remove(GTK_CLIST(var->Widget), row); count = g_list_length(GTK_CLIST(var->Widget)->selection); } } else { /* Default GTK_SELECTION_SINGLE and GTK_SELECTION_BROWSE. * * There does not appear to be a way to get the selected item(s) * outside of the select-row signal callback but I found this * recommended technique from here: * https://mail.gnome.org/archives/gtk-app-devel-list/1999-April/msg00033.html */ if (g_list_length(GTK_CLIST(var->Widget)->selection)) { row = (gint)g_list_nth_data(GTK_CLIST(var->Widget)->selection, 0); gtk_clist_remove(GTK_CLIST(var->Widget), row); } } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
GtkWidget *widget_hscale_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GtkWidget *widget; gdouble range_min = 0; gdouble range_max = 100; gdouble range_step = 1; gdouble range_value = 0; gchar *value; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Thunor: These "range-*" names are consistent with the spinbutton widget */ if (attr) { if (!(value = get_tag_attribute(attr, "range-min"))) value = get_tag_attribute(attr, "scale-min"); if (value) range_min = atof(value); if (!(value = get_tag_attribute(attr, "range-max"))) value = get_tag_attribute(attr, "scale-max"); if (value) range_max = atof(value); if (!(value = get_tag_attribute(attr, "range-step"))) value = get_tag_attribute(attr, "scale-step"); if (value) range_step = atof(value); if (!(value = get_tag_attribute(attr, "range-value"))) value = get_tag_attribute(attr, "scale-value"); if (value) range_value = atof(value); } if (Type == WIDGET_HSCALE) { #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk3 so I've added the newly recommended equivalent */ widget = gtk_hscale_new_with_range(range_min, range_max, range_step); #else widget = gtk_scale_new_with_range(GTK_ORIENTATION_HORIZONTAL, range_min, range_max, range_step); #endif } else { #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk3 so I've added the newly recommended equivalent */ widget = gtk_vscale_new_with_range(range_min, range_max, range_step); #else widget = gtk_scale_new_with_range(GTK_ORIENTATION_VERTICAL, range_min, range_max, range_step); #endif } gtk_range_set_value(GTK_RANGE(widget), range_value); #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
GtkWidget *widget_hscale_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GtkWidget *widget; gdouble range_min = 0; gdouble range_max = 100; gdouble range_step = 1; gdouble range_value = 0; gchar *value; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Thunor: These "range-*" names are consistent with the spinbutton widget */ if (attr) { if (!(value = get_tag_attribute(attr, "range-min"))) value = get_tag_attribute(attr, "scale-min"); if (value) range_min = atof(value); if (!(value = get_tag_attribute(attr, "range-max"))) value = get_tag_attribute(attr, "scale-max"); if (value) range_max = atof(value); if (!(value = get_tag_attribute(attr, "range-step"))) value = get_tag_attribute(attr, "scale-step"); if (value) range_step = atof(value); if (!(value = get_tag_attribute(attr, "range-value"))) value = get_tag_attribute(attr, "scale-value"); if (value) range_value = atof(value); } if (Type == WIDGET_HSCALE) { widget = gtk_hscale_new_with_range(range_min, range_max, range_step); } else { widget = gtk_vscale_new_with_range(range_min, range_max, range_step); } gtk_range_set_value(GTK_RANGE(widget), range_value); #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
gchar *widget_table_envvar_all_construct(variable *var) { gchar *line; gchar *string; gchar *text; gchar *value; gint column = 0; gint retval; gint row = 0; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ /* Which column should we export */ if (var->widget_tag_attr) { /* Get exported-column */ if ((value = get_tag_attribute(var->widget_tag_attr, "exported-column"))) column = atoi(value); } /* Where's the GtkCList row count? It's not such a problem as * gtk_clist_get_text() returns 0 if it's not available at which * point we'll stop */ line = g_strdup_printf("%s_ALL=\"", var->Name); retval = gtk_clist_get_text(GTK_CLIST(var->Widget), row, column, &string); while (retval) { if (row == 0) { text = g_strconcat(line, "'", string, "'", NULL); } else { text = g_strconcat(line, " '", string, "'", NULL); } g_free(line); line = text; row++; retval = gtk_clist_get_text(GTK_CLIST(var->Widget), row, column, &string); } string = g_strconcat(line, "\"\n", NULL); g_free(line); #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return string; }
/*********************************************************************** * Create * ***********************************************************************/ GtkWidget *widget_hbox_create( AttributeSet *Attr, tag_attr *attr, gint Type) { gchar *value; gint border_width; gint n; gint original_expand, original_fill; gint space_expand, space_fill; GtkWidget *widget; stackelement s; variable *var; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* The spacing value here is the GtkBox "spacing" property * and therefore can be overridden with a spacing="0" tag * attribute*/ #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk3 so I've added the newly recommended equivalent */ widget = gtk_hbox_new(FALSE, 5); #else widget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); gtk_box_set_homogeneous(GTK_BOX(widget), FALSE); #endif if (attr && (value = get_tag_attribute(attr, "margin"))) { /* Deprecated */ border_width = atoi(value); gtk_container_set_border_width(GTK_CONTAINER(widget), border_width); } /* Calculate values for expand and fill at the container level */ space_expand = project_space_expand; if (attr && ((value = get_tag_attribute(attr, "space-expand")))) { if ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1)) { space_expand = TRUE; } else { space_expand = FALSE; } } space_fill = project_space_fill; if (attr && ((value = get_tag_attribute(attr, "space-fill")))) { if ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1)) { space_fill = TRUE; } else { space_fill = FALSE; } } /* Pack the widgets into the container */ s = pop(); for (n = s.nwidgets - 1; n >= 0; --n) { /* Calculate values for expand and fill at the widget level */ var = find_variable_by_widget(s.widgets[n]); if (var && var->widget_tag_attr && ((value = get_tag_attribute(var->widget_tag_attr, "space-expand")))) { if ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1)) { space_expand = TRUE; } else { space_expand = FALSE; } } if (var && var->widget_tag_attr && ((value = get_tag_attribute(var->widget_tag_attr, "space-fill")))) { if ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1)) { space_fill = TRUE; } else { space_fill = FALSE; } } /* Thunor: The entry widget here is being packed with expand * and fill set to true but not in the vbox or frame, so I'll * mark this temp temp as it could be a bug */ if (s.widgettypes[n] == WIDGET_EDIT || s.widgettypes[n] == WIDGET_FRAME || s.widgettypes[n] == WIDGET_SCROLLEDW || s.widgettypes[n] == WIDGET_ENTRY) { original_expand = original_fill = TRUE; } else { original_expand = original_fill = FALSE; } if (space_expand != -1) original_expand = space_expand; if (space_fill != -1) original_fill = space_fill; #ifdef DEBUG_CONTENT fprintf(stderr, "%s(): hbox expand=%i fill=%i\n", __func__, original_expand, original_fill); #endif gtk_box_pack_end(GTK_BOX(widget), s.widgets[n], original_expand, original_fill, 0); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
/*********************************************************************** * Refresh * ***********************************************************************/ void widget_timer_refresh(variable *var) { GList *element; gchar *act; gchar text[256]; gchar *value; gint initialised = FALSE; gint milliseconds = FALSE; guint interval = 1; guint timer_id; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_timer_input_by_command(var, act + 8); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_timer_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_timer_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Create the timer */ if (var->widget_tag_attr && (value = get_tag_attribute(var->widget_tag_attr, "milliseconds")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { milliseconds = TRUE; interval = 1000; /* Set default of 1000ms */ } if (var->widget_tag_attr && (value = get_tag_attribute(var->widget_tag_attr, "interval"))) { interval = atoi(value); } if (milliseconds) { /* Precision in milliseconds */ timer_id = g_timeout_add( interval, widget_timer_timer_callback, (gpointer)var); } else { /* Precision in seconds (default) */ timer_id = g_timeout_add_seconds( interval, widget_timer_timer_callback, (gpointer)var); } /* Store the timer_id as a piece of widget data */ g_object_set_data(G_OBJECT(var->Widget), "_timer-id", (gpointer)timer_id); /* Set the text of the label to its variable name */ sprintf(text, "<span fgcolor='white' bgcolor='darkred'> %s </span>", attributeset_get_first(&element, var->Attributes, ATTR_VARIABLE)); gtk_label_set_markup(GTK_LABEL(var->Widget), text); /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_LABEL)) fprintf(stderr, "%s(): <label> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) fprintf(stderr, "%s(): <default> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_HEIGHT)) fprintf(stderr, "%s(): <height> not implemented for this widget.\n", __func__); if (attributeset_is_avail(var->Attributes, ATTR_WIDTH)) fprintf(stderr, "%s(): <width> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
/*********************************************************************** * Create * ***********************************************************************/ GtkWidget *widget_table_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GList *element; GtkWidget *widget; gchar *value; gint column; gint sort_function; list_t *sliced; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ if (attributeset_is_avail(Attr, ATTR_LABEL)) { sliced = linecutter(g_strdup(attributeset_get_first( &element, Attr, ATTR_LABEL)), '|'); widget = gtk_clist_new_with_titles(sliced->n_lines, sliced->line); if (sliced) list_t_free(sliced); /* Free linecutter memory */ } else { widget = gtk_clist_new(1); /* 1 column */ } if (attr) { /* Get sort-function (custom) */ if ((value = get_tag_attribute(attr, "sort-function"))) { sort_function = atoi(value); if (sort_function == 1) { gtk_clist_set_compare_func(GTK_CLIST(widget), widget_table_natcmp); } else if (sort_function == 2) { gtk_clist_set_compare_func(GTK_CLIST(widget), widget_table_natcasecmp); } } /* Get sort-type (auto-sort will require this preset) */ if ((value = get_tag_attribute(attr, "sort-type"))) { gtk_clist_set_sort_type(GTK_CLIST(widget), atoi(value)); } /* Get sort-column (custom) */ if ((value = get_tag_attribute(attr, "sort-column"))) { gtk_clist_set_sort_column(GTK_CLIST(widget), atoi(value)); } /* Get auto-sort (custom) */ if ((value = get_tag_attribute(attr, "auto-sort")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { gtk_clist_set_auto_sort(GTK_CLIST(widget), TRUE); } else { gtk_clist_set_auto_sort(GTK_CLIST(widget), FALSE); } /* Get column-header-active (custom) */ if ((value = get_tag_attribute(attr, "column-header-active"))) { sliced = linecutter(g_strdup(value), '|'); for (column = 0; column < sliced->n_lines; column++) { if ((strcasecmp(sliced->line[column], "true") == 0) || (strcasecmp(sliced->line[column], "yes") == 0) || (atoi(sliced->line[column]) == 1)) { gtk_clist_column_title_active(GTK_CLIST(widget), column); } else { gtk_clist_column_title_passive(GTK_CLIST(widget), column); } } if (sliced) list_t_free(sliced); /* Free linecutter memory */ } /* Get column-visible (custom) */ if ((value = get_tag_attribute(attr, "column-visible"))) { sliced = linecutter(g_strdup(value), '|'); for (column = 0; column < sliced->n_lines; column++) { if ((strcasecmp(sliced->line[column], "true") == 0) || (strcasecmp(sliced->line[column], "yes") == 0) || (atoi(sliced->line[column]) == 1)) { gtk_clist_set_column_visibility(GTK_CLIST(widget), column, TRUE); } else { gtk_clist_set_column_visibility(GTK_CLIST(widget), column, FALSE); } } if (sliced) list_t_free(sliced); /* Free linecutter memory */ } } #else fprintf(stderr, "%s(): The table (GtkCList) widget has been removed from GTK+ 3 and tree is recommended as a replacement.\n", __func__); exit(EXIT_FAILURE); #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
/*********************************************************************** * Refresh * ***********************************************************************/ void widget_table_refresh(variable *var) { GList *element; gchar *act; gchar *value; gint freeze_thaw = FALSE; gint initialised = FALSE; gint selected_row; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ /* Get initialised state of widget */ if (g_object_get_data(G_OBJECT(var->Widget), "_initialised") != NULL) initialised = (gint)g_object_get_data(G_OBJECT(var->Widget), "_initialised"); if (var->widget_tag_attr) { /* Get freeze-thaw (custom) */ if ((value = get_tag_attribute(var->widget_tag_attr, "freeze-thaw")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { freeze_thaw = TRUE; gtk_clist_freeze(GTK_CLIST(var->Widget)); } } /* The <input> tag... */ act = attributeset_get_first(&element, var->Attributes, ATTR_INPUT); while (act) { if (input_is_shell_command(act)) widget_table_input_by_command(var, act + 8, TRUE); /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0 && strlen(act) > 5) { if (!initialised) { /* Check for file-monitor and create if requested */ widget_file_monitor_try_create(var, act + 5); } widget_table_input_by_file(var, act + 5); } act = attributeset_get_next(&element, var->Attributes, ATTR_INPUT); } /* The <item> tags... */ if (attributeset_is_avail(var->Attributes, ATTR_ITEM)) widget_table_input_by_items(var); /* Initialise these only once at start-up */ if (!initialised) { /* Apply directives */ if (attributeset_is_avail(var->Attributes, ATTR_DEFAULT)) fprintf(stderr, "%s(): <default> not implemented for this widget.\n", __func__); if ((attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "false")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "disabled")) || /* Deprecated */ (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "no")) || (attributeset_cmp_left(var->Attributes, ATTR_SENSITIVE, "0"))) gtk_widget_set_sensitive(var->Widget, FALSE); /* Connect signals */ g_signal_connect(G_OBJECT(var->Widget), "select-row", G_CALLBACK(on_any_widget_select_row_event), (gpointer)var->Attributes); g_signal_connect(G_OBJECT(var->Widget), "click-column", G_CALLBACK(widget_table_click_column_callback), (gpointer)var); } /* Thaw a freeze? */ if (freeze_thaw) gtk_clist_thaw(GTK_CLIST(var->Widget)); if (var->widget_tag_attr) { /* Get columns-autosize (custom) Redundant: Works weirdly on initialisation. if ((value = get_tag_attribute(var->widget_tag_attr, "columns-autosize")) && ((strcasecmp(value, "true") == 0) || (strcasecmp(value, "yes") == 0) || (atoi(value) == 1))) { gtk_clist_columns_autosize(GTK_CLIST(var->Widget)); } */ /* Get selected-row (custom) */ if ((value = get_tag_attribute(var->widget_tag_attr, "selected-row"))) { selected_row = atoi(value); if (selected_row >= 0) gtk_clist_select_row(GTK_CLIST(var->Widget), selected_row, 0); } } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif }
gchar *widget_table_envvar_construct(GtkWidget *widget) { gchar *line; gchar *string; gchar *text; gchar *value; gint column = 0; gint count; gint initialrow; gint row; gint selectionmode = GTK_SELECTION_SINGLE; variable *var = find_variable_by_widget(widget); #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif #if !GTK_CHECK_VERSION(3,0,0) /* gtk3: Deprecated in gtk2 and now gone */ if (var->widget_tag_attr) { /* Get current selection-mode (there's no function to do this) */ if ((value = get_tag_attribute(var->widget_tag_attr, "selection-mode"))) selectionmode = atoi(value); /* Get exported-column */ if ((value = get_tag_attribute(var->widget_tag_attr, "exported-column"))) column = atoi(value); } #ifdef DEBUG_CONTENT fprintf(stderr, "%s(): widget=%p selectionmode=%i column=%i\n", __func__, widget, selectionmode, column); #endif if (selectionmode == GTK_SELECTION_NONE) { /* The API says that this is OK but a critical error gets dumped * to the terminal and it doesn't actually prevent selection so * it's not a usable selection mode */ string = g_strdup(""); /* Nothing is selected */ } else if (selectionmode == GTK_SELECTION_MULTIPLE) { initialrow = TRUE; line = g_strdup(""); for (count = 0; count < g_list_length(GTK_CLIST(widget)->selection); count++) { row = (gint)g_list_nth_data(GTK_CLIST(widget)->selection, count); gtk_clist_get_text(GTK_CLIST(widget), row, column, &string); if (initialrow) { text = g_strconcat(line, string, NULL); initialrow = FALSE; } else { text = g_strconcat(line, "\n", string, NULL); } g_free(line); line = text; } string = line; } else { /* Default GTK_SELECTION_SINGLE and GTK_SELECTION_BROWSE. * * There does not appear to be a way to get the selected item(s) * outside of the select-row signal callback but I found this * recommended technique from here: * https://mail.gnome.org/archives/gtk-app-devel-list/1999-April/msg00033.html */ if (g_list_length(GTK_CLIST(widget)->selection)) { row = (gint)g_list_nth_data(GTK_CLIST(widget)->selection, 0); gtk_clist_get_text(GTK_CLIST(widget), row, column, &value); string = g_strdup(value); } else { string = g_strdup(""); } } #endif #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return string; }
/*********************************************************************** * Create * ***********************************************************************/ GtkWidget *widget_window_create( AttributeSet *Attr, tag_attr *attr, gint Type) { gchar *value; GError *error = NULL; GList *accel_group = NULL; GList *element; gint border_width; GtkWidget *widget; stackelement s; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif /* Create the window widget */ widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); /* Set a default window title */ attributeset_set_if_unset(Attr, ATTR_LABEL, PACKAGE); gtk_window_set_title(GTK_WINDOW(widget), attributeset_get_first(&element, Attr, ATTR_LABEL)); /* Set a default title bar theme icon */ gtk_window_set_icon_name(GTK_WINDOW(widget), PACKAGE); /* If requested set a title bar image by filename */ if (attr) { if ((value = get_tag_attribute(attr, "image-name"))) gtk_window_set_icon_from_file(GTK_WINDOW(widget), find_pixmap(value), &error); } /* Set a default border width */ border_width = 5; if (attr && (value = get_tag_attribute(attr, "margin"))) /* Deprecated */ border_width = atoi(value); gtk_container_set_border_width(GTK_CONTAINER(widget), border_width); /* If we have geometry given in the command line, we set that */ if (have_geometry_dxdy) gtk_widget_set_usize(widget, geometry_dx, geometry_dy); if (have_geometry_xy) gtk_widget_set_uposition(widget, geometry_x, geometry_y); if (option_centering) gtk_window_set_position(GTK_WINDOW(widget), GTK_WIN_POS_CENTER_ALWAYS); /* Pop the widgets that the window will contain and add them */ s = pop(); gtk_container_add(GTK_CONTAINER(widget), s.widgets[0]); /* Thunor: Each menu created will have an accelerator group * for its menuitems which will require adding to the window */ if (accel_groups) { accel_group = g_list_first(accel_groups); while (accel_group) { gtk_window_add_accel_group(GTK_WINDOW(widget), GTK_ACCEL_GROUP(accel_group->data)); #ifdef DEBUG fprintf(stderr, "%s: Adding accel_group=%p to window\n", __func__, accel_group->data); #endif accel_group = accel_group->next; } g_list_free(accel_groups); accel_groups = NULL; } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }
GtkWidget *widget_pixmap_create( AttributeSet *Attr, tag_attr *attr, gint Type) { GError *error = NULL; GList *element; GtkIconTheme *icon_theme; GtkWidget *widget = NULL; GdkPixbuf *pixbuf; gchar *act; gchar *file_name; gchar *icon_name = NULL; gchar *stock_name = NULL; gchar *value; gint width = -1, height = -1; gint theme_icon_size = 32; gint stock_icon_size = GTK_ICON_SIZE_DND; #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Entering.\n", __func__); #endif if (attributeset_is_avail(Attr, ATTR_HEIGHT)) height = atoi(attributeset_get_first(&element, Attr, ATTR_HEIGHT)); if (attributeset_is_avail(Attr, ATTR_WIDTH)) width = atoi(attributeset_get_first(&element, Attr, ATTR_WIDTH)); /* The <input> tag... */ act = attributeset_get_first(&element, Attr, ATTR_INPUT); while (act) { #ifdef DEBUG_CONTENT fprintf(stderr, "%s(): act=%s\n", __func__, act); #endif /* input file stock = "File:", input file = "File:/path/to/file" */ if (strncasecmp(act, "file:", 5) == 0) { if ((stock_name = attributeset_get_this_tagattr(&element, Attr, ATTR_INPUT, "stock")) != NULL) { /* Get stock-icon-size (custom) */ if (attr && (value = get_tag_attribute(attr, "stock-icon-size"))) stock_icon_size = atoi(value); widget = gtk_image_new_from_stock(stock_name, stock_icon_size); break; /* Only one image is required */ } if ((icon_name = attributeset_get_this_tagattr(&element, Attr, ATTR_INPUT, "icon")) != NULL) { icon_theme = gtk_icon_theme_get_default(); /* Use the height or width dimension to override the default size */ if (height > -1) theme_icon_size = height; else if (width > -1) theme_icon_size = width; /* Get theme-icon-size (custom) */ if (attr && (value = get_tag_attribute(attr, "theme-icon-size"))) theme_icon_size = atoi(value); pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, theme_icon_size, 0, &error); if (pixbuf) { widget = gtk_image_new_from_pixbuf(pixbuf); /* pixbuf is no longer required and should be unreferenced */ g_object_unref(pixbuf); } else { /* pixbuf is null (file not found) so by using this * function gtk will substitute a broken image icon */ widget = gtk_image_new_from_file(""); } break; /* Only one image is required */ } if (strlen(act) > 5) { file_name = act + 5; if (width == -1 && height == -1) { /* Handle unscaled images */ widget = gtk_image_new_from_file(find_pixmap(file_name)); } else { /* Handle scaled images */ pixbuf = gdk_pixbuf_new_from_file_at_size( find_pixmap(file_name), width, height, NULL); if (pixbuf) { widget = gtk_image_new_from_pixbuf(pixbuf); /* pixbuf is no longer required and should be unreferenced */ g_object_unref(pixbuf); } else { /* pixbuf is null (file not found) so by using this * function gtk will substitute a broken image icon */ widget = gtk_image_new_from_file(""); } } break; /* Only one image is required */ } } act = attributeset_get_next(&element, Attr, ATTR_INPUT); } if (widget == NULL) { /* No input file directive found so by using this * function gtk will substitute a broken image icon */ widget = gtk_image_new_from_file(""); } #ifdef DEBUG_TRANSITS fprintf(stderr, "%s(): Exiting.\n", __func__); #endif return widget; }