| 218 g_string_append_c(string, '|'); |
217 g_string_append_c(string, '|'); |
| 219 |
218 |
| 220 if (len > tree->columns[i].width) |
219 if (len > tree->columns[i].width) |
| 221 { |
220 { |
| 222 len = tree->columns[i].width; |
221 len = tree->columns[i].width; |
| 223 ell = TRUE; |
222 } |
| 224 } |
223 |
| 225 |
224 text = g_utf8_offset_to_pointer(col->text, len - fl); |
| 226 text = g_utf8_offset_to_pointer(col->text, len - fl - ell); |
|
| 227 string = g_string_append_len(string, col->text, text - col->text); |
225 string = g_string_append_len(string, col->text, text - col->text); |
| 228 if (len < tree->columns[i].width) |
226 if (len < tree->columns[i].width) |
| 229 g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); |
227 g_string_append_printf(string, "%*s", tree->columns[i].width - len, ""); |
| 230 else if (ell) |
|
| 231 { |
|
| 232 g_string_append_unichar(string, (gunichar)2026); |
|
| 233 } |
|
| 234 } |
228 } |
| 235 return g_string_free(string, FALSE); |
229 return g_string_free(string, FALSE); |
| |
230 } |
| |
231 |
| |
232 static void |
| |
233 tree_mark_columns(GntTree *tree, int pos, int y, chtype type) |
| |
234 { |
| |
235 GntWidget *widget = GNT_WIDGET(tree); |
| |
236 int i; |
| |
237 int x = pos; |
| |
238 |
| |
239 for (i = 0; i < tree->ncol - 1; i++) |
| |
240 { |
| |
241 x += tree->columns[i].width; |
| |
242 mvwaddch(widget->window, y, x + i, type); |
| |
243 } |
| 236 } |
244 } |
| 237 |
245 |
| 238 static void |
246 static void |
| 239 redraw_tree(GntTree *tree) |
247 redraw_tree(GntTree *tree) |
| 240 { |
248 { |
| 253 if (tree->current == NULL) |
261 if (tree->current == NULL) |
| 254 tree->current = tree->root; |
262 tree->current = tree->root; |
| 255 |
263 |
| 256 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); |
264 wbkgd(widget->window, COLOR_PAIR(GNT_COLOR_NORMAL)); |
| 257 |
265 |
| |
266 start = 0; |
| |
267 if (tree->show_title) |
| |
268 { |
| |
269 int i; |
| |
270 int x = pos; |
| |
271 |
| |
272 mvwhline(widget->window, pos + 1, pos, ACS_HLINE | COLOR_PAIR(GNT_COLOR_NORMAL), |
| |
273 widget->priv.width - pos - 1); |
| |
274 |
| |
275 for (i = 0; i < tree->ncol; i++) |
| |
276 { |
| |
277 mvwprintw(widget->window, pos, x + i, tree->columns[i].title); |
| |
278 x += tree->columns[i].width; |
| |
279 } |
| |
280 if (pos) |
| |
281 tree_mark_columns(tree, pos, 0, ACS_TTEE | COLOR_PAIR(GNT_COLOR_NORMAL)); |
| |
282 tree_mark_columns(tree, pos, pos + 1, ACS_PLUS | COLOR_PAIR(GNT_COLOR_NORMAL)); |
| |
283 tree_mark_columns(tree, pos, pos, ACS_VLINE | COLOR_PAIR(GNT_COLOR_NORMAL)); |
| |
284 start = 2; |
| |
285 } |
| |
286 |
| 258 row = tree->top; |
287 row = tree->top; |
| 259 for (start = pos; row && start < widget->priv.height - pos; |
288 for (start = start + pos; row && start < widget->priv.height - pos; |
| 260 start++, row = get_next(row)) |
289 start++, row = get_next(row)) |
| 261 { |
290 { |
| 262 char *str; |
291 char *str; |
| 263 int wr; |
292 int wr; |
| 264 |
293 |
| 301 wbkgdset(widget->window, '\0' | attr); |
330 wbkgdset(widget->window, '\0' | attr); |
| 302 mvwprintw(widget->window, start, pos, str); |
331 mvwprintw(widget->window, start, pos, str); |
| 303 whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1)); |
332 whline(widget->window, ' ', widget->priv.width - pos * 2 - g_utf8_strlen(str, -1)); |
| 304 tree->bottom = row; |
333 tree->bottom = row; |
| 305 g_free(str); |
334 g_free(str); |
| |
335 tree_mark_columns(tree, pos, start, ACS_VLINE | attr); |
| 306 } |
336 } |
| 307 |
337 |
| 308 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); |
338 wbkgdset(widget->window, '\0' | COLOR_PAIR(GNT_COLOR_NORMAL)); |
| 309 while (start < widget->priv.height - pos) |
339 while (start < widget->priv.height - pos) |
| 310 { |
340 { |
| 311 mvwhline(widget->window, start, pos, ' ', |
341 mvwhline(widget->window, start, pos, ' ', |
| 312 widget->priv.width - pos * 2); |
342 widget->priv.width - pos * 2); |
| |
343 tree_mark_columns(tree, pos, start, ACS_VLINE); |
| 313 start++; |
344 start++; |
| 314 } |
345 } |
| 315 |
346 |
| 316 gnt_widget_queue_update(widget); |
347 gnt_widget_queue_update(widget); |
| 317 } |
348 } |
| 422 |
453 |
| 423 static void |
454 static void |
| 424 gnt_tree_destroy(GntWidget *widget) |
455 gnt_tree_destroy(GntWidget *widget) |
| 425 { |
456 { |
| 426 GntTree *tree = GNT_TREE(widget); |
457 GntTree *tree = GNT_TREE(widget); |
| |
458 int i; |
| 427 |
459 |
| 428 g_hash_table_destroy(tree->hash); |
460 g_hash_table_destroy(tree->hash); |
| 429 g_list_free(tree->list); |
461 g_list_free(tree->list); |
| |
462 |
| |
463 for (i = 0; i < tree->ncol; i++) |
| |
464 { |
| |
465 g_free(tree->columns[i].title); |
| |
466 } |
| |
467 g_free(tree->columns); |
| 430 } |
468 } |
| 431 |
469 |
| 432 static void |
470 static void |
| 433 gnt_tree_class_init(GntTreeClass *klass) |
471 gnt_tree_class_init(GntTreeClass *klass) |
| 434 { |
472 { |
| 811 tree->columns = g_new0(struct _GntTreeColInfo, col); |
849 tree->columns = g_new0(struct _GntTreeColInfo, col); |
| 812 while (col--) |
850 while (col--) |
| 813 { |
851 { |
| 814 tree->columns[col].width = 15; |
852 tree->columns[col].width = 15; |
| 815 } |
853 } |
| |
854 tree->show_title = FALSE; |
| 816 |
855 |
| 817 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); |
856 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); |
| 818 gnt_widget_set_take_focus(widget, TRUE); |
857 gnt_widget_set_take_focus(widget, TRUE); |
| 819 |
858 |
| 820 return widget; |
859 return widget; |
| 834 col->span = 1; |
873 col->span = 1; |
| 835 col->text = g_strdup(va_arg(args, const char *)); |
874 col->text = g_strdup(va_arg(args, const char *)); |
| 836 |
875 |
| 837 row->columns = g_list_append(row->columns, col); |
876 row->columns = g_list_append(row->columns, col); |
| 838 } |
877 } |
| |
878 va_end(args); |
| 839 |
879 |
| 840 return row; |
880 return row; |
| 841 } |
881 } |
| 842 |
882 |
| 843 void gnt_tree_set_col_width(GntTree *tree, int col, int width) |
883 void gnt_tree_set_col_width(GntTree *tree, int col, int width) |
| 845 g_return_if_fail(col < tree->ncol); |
885 g_return_if_fail(col < tree->ncol); |
| 846 |
886 |
| 847 tree->columns[col].width = width; |
887 tree->columns[col].width = width; |
| 848 } |
888 } |
| 849 |
889 |
| |
890 void gnt_tree_set_column_titles(GntTree *tree, ...) |
| |
891 { |
| |
892 int i; |
| |
893 va_list args; |
| |
894 |
| |
895 va_start(args, tree); |
| |
896 for (i = 0; i < tree->ncol; i++) |
| |
897 { |
| |
898 const char *title = va_arg(args, const char *); |
| |
899 tree->columns[i].title = g_strdup(title); |
| |
900 } |
| |
901 va_end(args); |
| |
902 } |
| |
903 |
| |
904 void gnt_tree_set_show_title(GntTree *tree, gboolean set) |
| |
905 { |
| |
906 tree->show_title = set; |
| |
907 } |
| |
908 |