Ejemplo n.º 1
0
/** Adjust tab stops for the given node to display all the given values.
 *
 * @param model model being handled
 * @param path path of the current node
 * @param iter iter of the current node
 * @param adjust_data data prepared by adjust_tabs
 * @return always FALSE (= never stop)
 */
static gboolean adjust_tabs_for_node(GtkTreeModel * model, GtkTreePath * path,
                                     GtkTreeIter * iter,
                                     struct adjust_data * adjust_data)
{
    char * choice;
    char ** values;
    gint columns;
    gint value_width;
    gint previous_location;
    gint location;
    gint i;

    gtk_tree_model_get(model, iter,
        /* column: */ CHOICE_MODEL_TRANSLATED_VALUE, &choice,
        -1 /* end of list */);
    values = g_strsplit(choice, "\t", 0 /* split all */);

    columns = g_strv_length(values);
    if (pango_tab_array_get_size(adjust_data->tab_array) < columns - 1) {
        pango_tab_array_resize(adjust_data->tab_array, columns - 1);
    }
    previous_location = 0;
    for (i = 0; columns > i + 1; i++) {
        value_width = cdebconf_gtk_get_text_width(
                          adjust_data->widget, values[i]) + COLUMN_SPACING;
        pango_tab_array_get_tab(adjust_data->tab_array, i,
                                NULL /* don't get alignment */, &location);
        if (location - previous_location < value_width) {
            location = previous_location + value_width;
            pango_tab_array_set_tab(adjust_data->tab_array, i, PANGO_TAB_LEFT,
                                    location);
        }
        previous_location = location;
    }

#if 0
    /* DEBUG: dump tabs */
    g_warning("dump after choice: %s", choice);
    for (i = 0; pango_tab_array_get_size(adjust_data->tab_array) > i; i++) {
        pango_tab_array_get_tab(adjust_data->tab_array, i,
                                NULL /* don't get alignment */,
                                &location);
        g_warning("%d: %d", i, location);
    }
#endif

    g_free(choice);
    g_strfreev(values);

    return FALSE;
}
Ejemplo n.º 2
0
static void get_tab_array(PangoTabArray **tabs,
	GtkPrintContext *ctx, GtkTextView *text_view)
{
	gint xft_dpi, loc;
	GtkSettings *settings = gtk_settings_get_default();
	
	g_object_get(settings, "gtk-xft-dpi", &xft_dpi, NULL);
	if ((*tabs = gtk_text_view_get_tabs(text_view))) {
		pango_tab_array_get_tab(*tabs, 0, NULL, &loc);
		pango_tab_array_set_tab(*tabs, 0, PANGO_TAB_LEFT,
			loc * gtk_print_context_get_dpi_x(ctx) / (xft_dpi / PANGO_SCALE));
	}
}