comparison console/libgnt/gnttree.c @ 14616:f1f1dcb26d89

[gaim-migrate @ 17344] Add a barebone menu in the buddylist for account actions. (Press Ctrl+o) committer: Tailor Script <tailor@pidgin.im>
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sun, 24 Sep 2006 17:07:38 +0000
parents 62bb53609a36
children b15c2eaeb67f
comparison
equal deleted inserted replaced
14615:bddedf8e4653 14616:f1f1dcb26d89
1 #include "gnttree.h" 1 #include "gnttree.h"
2 #include "gntmarshal.h" 2 #include "gntmarshal.h"
3 #include "gntutils.h"
3 4
4 #include <string.h> 5 #include <string.h>
5 #include <ctype.h> 6 #include <ctype.h>
6 7
7 enum 8 enum
1138 tree->columns = g_new0(struct _GntTreeColInfo, col); 1139 tree->columns = g_new0(struct _GntTreeColInfo, col);
1139 while (col--) 1140 while (col--)
1140 { 1141 {
1141 tree->columns[col].width = 15; 1142 tree->columns[col].width = 15;
1142 } 1143 }
1144 tree->list = NULL;
1143 tree->show_title = FALSE; 1145 tree->show_title = FALSE;
1144 } 1146 }
1145 1147
1146 GntWidget *gnt_tree_new_with_columns(int col) 1148 GntWidget *gnt_tree_new_with_columns(int col)
1147 { 1149 {
1239 void gnt_tree_set_show_separator(GntTree *tree, gboolean set) 1241 void gnt_tree_set_show_separator(GntTree *tree, gboolean set)
1240 { 1242 {
1241 tree->show_separator = set; 1243 tree->show_separator = set;
1242 } 1244 }
1243 1245
1246 void gnt_tree_adjust_columns(GntTree *tree)
1247 {
1248 GntTreeRow *row = tree->root;
1249 int *widths, i, twidth, height;
1250
1251 widths = g_new0(int, tree->ncol);
1252 while (row) {
1253 GList *iter;
1254 for (i = 0, iter = row->columns; iter; iter = iter->next, i++) {
1255 GntTreeCol *col = iter->data;
1256 int w = gnt_util_onscreen_width(col->text, NULL);
1257 if (widths[i] < w)
1258 widths[i] = w;
1259 }
1260 row = row->next;
1261 }
1262
1263 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER));
1264 for (i = 0; i < tree->ncol; i++) {
1265 gnt_tree_set_col_width(tree, i, widths[i]);
1266 twidth += widths[i] + (tree->show_separator ? 1 : 0) + 1;
1267 fprintf(stderr, "column width for col %d: %d\n", i, widths[i]);
1268 }
1269 g_free(widths);
1270
1271 fprintf(stderr, "tree width: %d\n", twidth);
1272 gnt_widget_get_size(GNT_WIDGET(tree), NULL, &height);
1273 gnt_widget_set_size(GNT_WIDGET(tree), twidth, height);
1274 }
1275