Mercurial > pidgin.yaz
comparison finch/libgnt/gnttree.c @ 15970:790d1d003825
Allow making some columns invisible.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Fri, 30 Mar 2007 05:32:40 +0000 |
parents | 0ab73bf1fef1 |
children | 05d347516fcd |
comparison
equal
deleted
inserted
replaced
15969:43182e0e58c0 | 15970:790d1d003825 |
---|---|
220 update_row_text(GntTree *tree, GntTreeRow *row) | 220 update_row_text(GntTree *tree, GntTreeRow *row) |
221 { | 221 { |
222 GString *string = g_string_new(NULL); | 222 GString *string = g_string_new(NULL); |
223 GList *iter; | 223 GList *iter; |
224 int i; | 224 int i; |
225 gboolean notfirst = FALSE; | |
225 | 226 |
226 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) | 227 for (i = 0, iter = row->columns; i < tree->ncol && iter; i++, iter = iter->next) |
227 { | 228 { |
228 GntTreeCol *col = iter->data; | 229 GntTreeCol *col = iter->data; |
229 const char *text; | 230 const char *text; |
230 int len = gnt_util_onscreen_width(col->text, NULL); | 231 int len = gnt_util_onscreen_width(col->text, NULL); |
231 int fl = 0; | 232 int fl = 0; |
232 gboolean cut = FALSE; | 233 gboolean cut = FALSE; |
234 | |
235 if (tree->columns[i].invisible) | |
236 continue; | |
233 | 237 |
234 if (i == 0) | 238 if (i == 0) |
235 { | 239 { |
236 if (row->choice) | 240 if (row->choice) |
237 { | 241 { |
256 fl = TAB_SIZE * find_depth(row); | 260 fl = TAB_SIZE * find_depth(row); |
257 g_string_append_printf(string, "%*s", fl, ""); | 261 g_string_append_printf(string, "%*s", fl, ""); |
258 } | 262 } |
259 len += fl; | 263 len += fl; |
260 } | 264 } |
265 else if (notfirst) | |
266 g_string_append_c(string, '|'); | |
261 else | 267 else |
262 g_string_append_c(string, '|'); | 268 g_string_append_c(string, ' '); |
269 | |
270 notfirst = TRUE; | |
263 | 271 |
264 if (len > tree->columns[i].width) { | 272 if (len > tree->columns[i].width) { |
265 len = tree->columns[i].width - 1; | 273 len = tree->columns[i].width - 1; |
266 cut = TRUE; | 274 cut = TRUE; |
267 } | 275 } |
279 g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); | 287 g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); |
280 } | 288 } |
281 return g_string_free(string, FALSE); | 289 return g_string_free(string, FALSE); |
282 } | 290 } |
283 | 291 |
292 #define NEXT_X x += tree->columns[i].width + (i > 0 ? 1 : 0) | |
293 | |
284 static void | 294 static void |
285 tree_mark_columns(GntTree *tree, int pos, int y, chtype type) | 295 tree_mark_columns(GntTree *tree, int pos, int y, chtype type) |
286 { | 296 { |
287 GntWidget *widget = GNT_WIDGET(tree); | 297 GntWidget *widget = GNT_WIDGET(tree); |
288 int i; | 298 int i; |
289 int x = pos; | 299 int x = pos; |
300 gboolean notfirst = FALSE; | |
290 | 301 |
291 for (i = 0; i < tree->ncol - 1; i++) | 302 for (i = 0; i < tree->ncol - 1; i++) |
292 { | 303 { |
293 x += tree->columns[i].width; | 304 if (!tree->columns[i].invisible) { |
294 mvwaddch(widget->window, y, x + i, type); | 305 notfirst = TRUE; |
306 NEXT_X; | |
307 } | |
308 if (!tree->columns[i+1].invisible && notfirst) | |
309 mvwaddch(widget->window, y, x, type); | |
295 } | 310 } |
296 } | 311 } |
297 | 312 |
298 static void | 313 static void |
299 redraw_tree(GntTree *tree) | 314 redraw_tree(GntTree *tree) |
325 int i; | 340 int i; |
326 int x = pos; | 341 int x = pos; |
327 | 342 |
328 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), | 343 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), |
329 widget->priv.width - pos - 1); | 344 widget->priv.width - pos - 1); |
330 | 345 mvwhline(widget->window, pos, pos, ' ' | COLOR_PAIR(GNT_COLOR_NORMAL), |
346 widget->priv.width - pos - 1); | |
347 | |
331 for (i = 0; i < tree->ncol; i++) | 348 for (i = 0; i < tree->ncol; i++) |
332 { | 349 { |
333 mvwaddstr(widget->window, pos, x + i, tree->columns[i].title); | 350 if (tree->columns[i].invisible) { |
334 x += tree->columns[i].width; | 351 continue; |
352 } | |
353 mvwaddstr(widget->window, pos, x + 1, tree->columns[i].title); | |
354 NEXT_X; | |
335 } | 355 } |
336 if (pos) | 356 if (pos) |
337 { | 357 { |
338 tree_mark_columns(tree, pos, 0, ACS_TTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); | 358 tree_mark_columns(tree, pos, 0, ACS_TTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); |
339 tree_mark_columns(tree, pos, widget->priv.height - pos, | 359 tree_mark_columns(tree, pos, widget->priv.height - pos, |
489 if (widget->priv.width == 0) | 509 if (widget->priv.width == 0) |
490 { | 510 { |
491 GntTree *tree = GNT_TREE(widget); | 511 GntTree *tree = GNT_TREE(widget); |
492 int i, width = 0; | 512 int i, width = 0; |
493 for (i = 0; i < tree->ncol; i++) | 513 for (i = 0; i < tree->ncol; i++) |
494 width += tree->columns[i].width; | 514 if (!tree->columns[i].invisible) |
495 widget->priv.width = width + i; | 515 width += tree->columns[i].width + 1; |
516 widget->priv.width = width; | |
496 } | 517 } |
497 } | 518 } |
498 | 519 |
499 static void | 520 static void |
500 gnt_tree_map(GntWidget *widget) | 521 gnt_tree_map(GntWidget *widget) |
1482 } | 1503 } |
1483 | 1504 |
1484 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); | 1505 twidth = 1 + 2 * (!GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(tree), GNT_WIDGET_NO_BORDER)); |
1485 for (i = 0; i < tree->ncol; i++) { | 1506 for (i = 0; i < tree->ncol; i++) { |
1486 gnt_tree_set_col_width(tree, i, widths[i]); | 1507 gnt_tree_set_col_width(tree, i, widths[i]); |
1487 twidth += widths[i] + (tree->show_separator ? 1 : 0) + 1; | 1508 if (!tree->columns[i].invisible) |
1509 twidth += widths[i] + (tree->show_separator ? 1 : 0) + 1; | |
1488 } | 1510 } |
1489 g_free(widths); | 1511 g_free(widths); |
1490 | 1512 |
1491 gnt_widget_get_size(GNT_WIDGET(tree), NULL, &height); | 1513 gnt_widget_get_size(GNT_WIDGET(tree), NULL, &height); |
1492 gnt_widget_set_size(GNT_WIDGET(tree), twidth, height); | 1514 gnt_widget_set_size(GNT_WIDGET(tree), twidth, height); |
1497 g_hash_table_foreach_remove(tree->hash, return_true, NULL); | 1519 g_hash_table_foreach_remove(tree->hash, return_true, NULL); |
1498 g_hash_table_destroy(tree->hash); | 1520 g_hash_table_destroy(tree->hash); |
1499 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); | 1521 tree->hash = g_hash_table_new_full(hash, eq, kd, free_tree_row); |
1500 } | 1522 } |
1501 | 1523 |
1524 void gnt_tree_set_column_visible(GntTree *tree, int col, gboolean vis) | |
1525 { | |
1526 g_return_if_fail(col < tree->ncol); | |
1527 tree->columns[col].invisible = !vis; | |
1528 } | |
1529 |