/** 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;
}
Example #2
0
/**
 * pango_tab_array_set_tab:
 * @tab_array: a #PangoTabArray
 * @tab_index: the index of a tab stop
 * @alignment: tab alignment
 * @location: tab location in Pango units
 *
 * Sets the alignment and location of a tab stop.
 * @alignment must always be #PANGO_TAB_LEFT in the current
 * implementation.
 *
 **/
void
pango_tab_array_set_tab  (PangoTabArray *tab_array,
			  gint           tab_index,
			  PangoTabAlign  alignment,
			  gint           location)
{
  g_return_if_fail (tab_array != NULL);
  g_return_if_fail (tab_index >= 0);
  g_return_if_fail (alignment == PANGO_TAB_LEFT);
  g_return_if_fail (location >= 0);

  if (tab_index >= tab_array->size)
    pango_tab_array_resize (tab_array, tab_index + 1);

  tab_array->tabs[tab_index].alignment = alignment;
  tab_array->tabs[tab_index].location = location;
}