1 /* ///////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/treeentry_gtk.c
3 // Purpose: GtkTreeEntry implementation
5 // Copyright: (c) 2006 Ryan Norton
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////// */
12 #define G_GNUC_INTERNAL
16 #include "wx/gtk/private/treeentry_gtk.h"
21 The main reason for this class is to have a holder for both a string
22 and userdata for us to use in wxListXXX classes.
24 This is transformable to a string for the Gtk implementations,
25 and the string passed in is duplicated and freed upon destruction.
27 As mentioned the real magic here is the transforming it to a string
28 which lets us use it as a entry in a GtkTreeView/GtkListStore
29 and still display it. Otherwise we would need to implement our
34 static void wx_tree_entry_class_init(void* g_class
, void* class_data
);
35 static void wx_tree_entry_string_transform_func(const GValue
*src_value
,
37 static void wx_tree_entry_dispose(GObject
* obj
);
39 static GObjectClass
* parent_class
;
45 return WX_TREE_ENTRY(g_object_new(WX_TYPE_TREE_ENTRY
, NULL
));
49 wx_tree_entry_get_type()
51 static GType tree_entry_type
= 0;
55 const GTypeInfo tree_entry_info
=
59 NULL
, /* base_finalize */
60 wx_tree_entry_class_init
,
61 NULL
, /* class_finalize */
62 NULL
, /* class_data */
65 NULL
, /* instance_init */
66 NULL
/* value_table */
68 tree_entry_type
= g_type_register_static (G_TYPE_OBJECT
, "wxTreeEntry",
71 g_value_register_transform_func(tree_entry_type
, G_TYPE_STRING
,
72 wx_tree_entry_string_transform_func
);
75 return tree_entry_type
;
78 char* wx_tree_entry_get_collate_key(wxTreeEntry
* entry
)
80 if (entry
->collate_key
== NULL
)
82 char* temp
= g_utf8_casefold(entry
->label
, -1);
83 entry
->collate_key
= g_utf8_collate_key(temp
, -1);
86 return entry
->collate_key
;
89 char* wx_tree_entry_get_label(wxTreeEntry
* entry
)
91 g_assert(WX_IS_TREE_ENTRY(entry
));
95 void* wx_tree_entry_get_userdata(wxTreeEntry
* entry
)
97 g_assert(WX_IS_TREE_ENTRY(entry
));
98 return entry
->userdata
;
101 void wx_tree_entry_set_label(wxTreeEntry
* entry
, const char* label
)
103 g_assert(WX_IS_TREE_ENTRY(entry
));
105 /* free previous if it exists */
108 g_free(entry
->label
);
109 g_free(entry
->collate_key
);
112 entry
->label
= g_strdup(label
);
113 entry
->collate_key
= NULL
;
116 void wx_tree_entry_set_userdata(wxTreeEntry
* entry
, void* userdata
)
118 g_assert(WX_IS_TREE_ENTRY(entry
));
119 entry
->userdata
= userdata
;
122 void wx_tree_entry_set_destroy_func(wxTreeEntry
* entry
,
123 wxTreeEntryDestroy destroy_func
,
124 gpointer destroy_func_data
)
126 g_assert(WX_IS_TREE_ENTRY(entry
));
127 entry
->destroy_func
= destroy_func
;
128 entry
->destroy_func_data
= destroy_func_data
;
132 static void wx_tree_entry_class_init(void* g_class
, void* class_data
)
134 GObjectClass
* gobject_class
= G_OBJECT_CLASS(g_class
);
135 gobject_class
->dispose
= wx_tree_entry_dispose
;
136 parent_class
= G_OBJECT_CLASS(g_type_class_peek_parent(g_class
));
139 static void wx_tree_entry_string_transform_func(const GValue
*src_value
,
143 void* src_ptr
= g_value_peek_pointer(src_value
);
145 /* Make sure src is a treeentry and dest can hold a string */
146 g_assert(WX_IS_TREE_ENTRY(src_ptr
));
147 g_assert(G_VALUE_HOLDS(dest_value
, G_TYPE_STRING
));
149 entry
= WX_TREE_ENTRY(src_ptr
);
150 g_value_set_string(dest_value
, entry
->label
);
153 static void wx_tree_entry_dispose(GObject
* obj
)
157 g_assert(WX_IS_TREE_ENTRY(obj
));
159 entry
= WX_TREE_ENTRY(obj
);
161 /* free label if it exists */
164 g_free(entry
->label
);
165 g_free(entry
->collate_key
);
167 entry
->collate_key
= NULL
;
170 /* call destroy callback if it exists */
171 if(entry
->destroy_func
)
173 (*entry
->destroy_func
) (entry
, entry
->destroy_func_data
);
174 entry
->destroy_func
= NULL
;
175 entry
->destroy_func_data
= NULL
;
179 entry
->userdata
= NULL
;
181 parent_class
->dispose(obj
);