comparison finch/libgnt/gnttree.c @ 18531:da550279d390

Use gobject properties instead of hacks when creating columns in a tree.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 14 Jul 2007 01:31:44 +0000
parents ed17f5530300
children ffa46a399f3c
comparison
equal deleted inserted replaced
18526:09db6fec9dce 18531:da550279d390
35 #define BINARY_DATA(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA) 35 #define BINARY_DATA(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_BINARY_DATA)
36 #define RIGHT_ALIGNED(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED) 36 #define RIGHT_ALIGNED(tree, index) (tree->columns[index].flags & GNT_TREE_COLUMN_RIGHT_ALIGNED)
37 37
38 enum 38 enum
39 { 39 {
40 PROP_0,
41 PROP_COLUMNS,
42 };
43
44 enum
45 {
40 SIG_SELECTION_CHANGED, 46 SIG_SELECTION_CHANGED,
41 SIG_SCROLLED, 47 SIG_SCROLLED,
42 SIG_TOGGLED, 48 SIG_TOGGLED,
43 SIG_COLLAPSED, 49 SIG_COLLAPSED,
44 SIGS, 50 SIGS,
74 gboolean isbinary; 80 gboolean isbinary;
75 int span; /* How many columns does it span? */ 81 int span; /* How many columns does it span? */
76 }; 82 };
77 83
78 static void tree_selection_changed(GntTree *, GntTreeRow *, GntTreeRow *); 84 static void tree_selection_changed(GntTree *, GntTreeRow *, GntTreeRow *);
85 static void _gnt_tree_init_internals(GntTree *tree, int col);
79 86
80 static GntWidgetClass *parent_class = NULL; 87 static GntWidgetClass *parent_class = NULL;
81 static guint signals[SIGS] = { 0 }; 88 static guint signals[SIGS] = { 0 };
82 89
83 static void 90 static void
904 redraw_tree(tree); 911 redraw_tree(tree);
905 return TRUE; 912 return TRUE;
906 } 913 }
907 914
908 static void 915 static void
916 gnt_tree_set_property(GObject *obj, guint prop_id, const GValue *value,
917 GParamSpec *spec)
918 {
919 GntTree *tree = GNT_TREE(obj);
920 switch (prop_id) {
921 case PROP_COLUMNS:
922 _gnt_tree_init_internals(tree, g_value_get_int(value));
923 break;
924 default:
925 break;
926 }
927 }
928
929 static void
930 gnt_tree_get_property(GObject *obj, guint prop_id, GValue *value,
931 GParamSpec *spec)
932 {
933 GntTree *tree = GNT_TREE(obj);
934 switch (prop_id) {
935 case PROP_COLUMNS:
936 g_value_set_int(value, tree->ncol);
937 break;
938 default:
939 break;
940 }
941 }
942
943 static void
909 gnt_tree_class_init(GntTreeClass *klass) 944 gnt_tree_class_init(GntTreeClass *klass)
910 { 945 {
911 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass); 946 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
947 GObjectClass *gclass = G_OBJECT_CLASS(klass);
948
912 parent_class = GNT_WIDGET_CLASS(klass); 949 parent_class = GNT_WIDGET_CLASS(klass);
913 parent_class->destroy = gnt_tree_destroy; 950 parent_class->destroy = gnt_tree_destroy;
914 parent_class->draw = gnt_tree_draw; 951 parent_class->draw = gnt_tree_draw;
915 parent_class->map = gnt_tree_map; 952 parent_class->map = gnt_tree_map;
916 parent_class->size_request = gnt_tree_size_request; 953 parent_class->size_request = gnt_tree_size_request;
917 parent_class->key_pressed = gnt_tree_key_pressed; 954 parent_class->key_pressed = gnt_tree_key_pressed;
918 parent_class->clicked = gnt_tree_clicked; 955 parent_class->clicked = gnt_tree_clicked;
919 parent_class->size_changed = gnt_tree_size_changed; 956 parent_class->size_changed = gnt_tree_size_changed;
957
958 gclass->set_property = gnt_tree_set_property;
959 gclass->get_property = gnt_tree_get_property;
960 g_object_class_install_property(gclass,
961 PROP_COLUMNS,
962 g_param_spec_int("columns", "Columns",
963 "Number of columns in the tree.",
964 1, G_MAXINT, 1,
965 G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
966 )
967 );
920 968
921 signals[SIG_SELECTION_CHANGED] = 969 signals[SIG_SELECTION_CHANGED] =
922 g_signal_new("selection-changed", 970 g_signal_new("selection-changed",
923 G_TYPE_FROM_CLASS(klass), 971 G_TYPE_FROM_CLASS(klass),
924 G_SIGNAL_RUN_LAST, 972 G_SIGNAL_RUN_LAST,
1499 else 1547 else
1500 redraw_tree(tree); 1548 redraw_tree(tree);
1501 tree_selection_changed(tree, row, tree->current); 1549 tree_selection_changed(tree, row, tree->current);
1502 } 1550 }
1503 1551
1504 void _gnt_tree_init_internals(GntTree *tree, int col) 1552 static void _gnt_tree_init_internals(GntTree *tree, int col)
1505 { 1553 {
1554 gnt_tree_destroy(GNT_WIDGET(tree));
1555
1506 tree->ncol = col; 1556 tree->ncol = col;
1507 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row); 1557 tree->hash = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, free_tree_row);
1508 tree->columns = g_new0(struct _GntTreeColInfo, col); 1558 tree->columns = g_new0(struct _GntTreeColInfo, col);
1509 tree->lastvisible = col - 1; 1559 tree->lastvisible = col - 1;
1510 while (col--) 1560 while (col--)
1511 { 1561 {
1512 tree->columns[col].width = 15; 1562 tree->columns[col].width = 15;
1513 } 1563 }
1514 tree->list = NULL; 1564 tree->list = NULL;
1515 tree->show_title = FALSE; 1565 tree->show_title = FALSE;
1566 g_object_notify(G_OBJECT(tree), "columns");
1516 } 1567 }
1517 1568
1518 GntWidget *gnt_tree_new_with_columns(int col) 1569 GntWidget *gnt_tree_new_with_columns(int col)
1519 { 1570 {
1520 GntWidget *widget = g_object_new(GNT_TYPE_TREE, NULL); 1571 GntWidget *widget = g_object_new(GNT_TYPE_TREE,
1521 GntTree *tree = GNT_TREE(widget); 1572 "columns", col,
1522 1573 NULL);
1523 _gnt_tree_init_internals(tree, col); 1574
1524
1525 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW); 1575 GNT_WIDGET_SET_FLAGS(widget, GNT_WIDGET_NO_SHADOW);
1526 gnt_widget_set_take_focus(widget, TRUE); 1576 gnt_widget_set_take_focus(widget, TRUE);
1527 1577
1528 return widget; 1578 return widget;
1529 } 1579 }