]>
Commit | Line | Data |
---|---|---|
4a46cbe8 RR |
1 | /* /////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/gtk/treeentry_gtk.c | |
3 | // Purpose: GtkTreeEntry implementation | |
4 | // Author: Ryan Norton | |
5 | // Id: $Id$ | |
6 | // Copyright: (c) 2006 Ryan Norton | |
7 | // Licence: wxWindows licence | |
8 | /////////////////////////////////////////////////////////////////////////// */ | |
9 | ||
76c32e7b JJ |
10 | #ifdef __VMS |
11 | #include <types.h> | |
87855305 JJ |
12 | typedef pid_t GPid; |
13 | #define G_GNUC_INTERNAL | |
14 | #define GSEAL(x) x | |
76c32e7b JJ |
15 | #endif |
16 | ||
79bca169 | 17 | #include "wx/gtk/private/treeentry_gtk.h" |
4a46cbe8 RR |
18 | |
19 | /* | |
20 | GtkTreeEntry | |
21 | ||
22 | The main reason for this class is to have a holder for both a string | |
23 | and userdata for us to use in wxListXXX classes. | |
24 | ||
25 | This is transformable to a string for the Gtk implementations, | |
26 | and the string passed in is duplicated and freed upon destruction. | |
27 | ||
28 | As mentioned the real magic here is the transforming it to a string | |
29 | which lets us use it as a entry in a GtkTreeView/GtkListStore | |
30 | and still display it. Otherwise we would need to implement our | |
31 | own model etc.. | |
32 | */ | |
33 | ||
34 | /* forwards */ | |
11f1e38e PC |
35 | static void wx_tree_entry_class_init(void* g_class, void* class_data); |
36 | static void wx_tree_entry_string_transform_func(const GValue *src_value, | |
4a46cbe8 | 37 | GValue *dest_value); |
11f1e38e | 38 | static void wx_tree_entry_dispose(GObject* obj); |
4a46cbe8 | 39 | |
ec34e73c | 40 | static GObjectClass* parent_class; |
4a46cbe8 RR |
41 | |
42 | /* public */ | |
11f1e38e PC |
43 | wxTreeEntry* |
44 | wx_tree_entry_new() | |
4a46cbe8 | 45 | { |
11f1e38e | 46 | return WX_TREE_ENTRY(g_object_new(WX_TYPE_TREE_ENTRY, NULL)); |
4a46cbe8 RR |
47 | } |
48 | ||
385e8575 | 49 | GType |
11f1e38e | 50 | wx_tree_entry_get_type() |
4a46cbe8 | 51 | { |
385e8575 | 52 | static GType tree_entry_type = 0; |
4a46cbe8 RR |
53 | |
54 | if (!tree_entry_type) | |
55 | { | |
de4a74e2 | 56 | const GTypeInfo tree_entry_info = |
4a46cbe8 | 57 | { |
3540b72b | 58 | sizeof(GObjectClass), |
4a46cbe8 RR |
59 | NULL, /* base_init */ |
60 | NULL, /* base_finalize */ | |
11f1e38e | 61 | wx_tree_entry_class_init, |
4a46cbe8 RR |
62 | NULL, /* class_finalize */ |
63 | NULL, /* class_data */ | |
11f1e38e | 64 | sizeof(wxTreeEntry), |
4a46cbe8 | 65 | 16, /* n_preallocs */ |
7a12c620 | 66 | NULL, /* instance_init */ |
4eb8ef2d | 67 | NULL /* value_table */ |
4a46cbe8 | 68 | }; |
11f1e38e | 69 | tree_entry_type = g_type_register_static (G_TYPE_OBJECT, "wxTreeEntry", |
9d655692 | 70 | &tree_entry_info, |
4a46cbe8 RR |
71 | (GTypeFlags)0); |
72 | g_value_register_transform_func(tree_entry_type, G_TYPE_STRING, | |
11f1e38e | 73 | wx_tree_entry_string_transform_func); |
4a46cbe8 RR |
74 | } |
75 | ||
76 | return tree_entry_type; | |
77 | } | |
78 | ||
11f1e38e | 79 | char* wx_tree_entry_get_collate_key(wxTreeEntry* entry) |
4a46cbe8 | 80 | { |
442bf2f0 PC |
81 | if (entry->collate_key == NULL) |
82 | { | |
83 | char* temp = g_utf8_casefold(entry->label, -1); | |
84 | entry->collate_key = g_utf8_collate_key(temp, -1); | |
85 | g_free(temp); | |
86 | } | |
4a46cbe8 RR |
87 | return entry->collate_key; |
88 | } | |
89 | ||
11f1e38e | 90 | char* wx_tree_entry_get_label(wxTreeEntry* entry) |
4a46cbe8 | 91 | { |
11f1e38e | 92 | g_assert(WX_IS_TREE_ENTRY(entry)); |
4a46cbe8 RR |
93 | return entry->label; |
94 | } | |
95 | ||
11f1e38e | 96 | void* wx_tree_entry_get_userdata(wxTreeEntry* entry) |
4a46cbe8 | 97 | { |
11f1e38e | 98 | g_assert(WX_IS_TREE_ENTRY(entry)); |
4a46cbe8 RR |
99 | return entry->userdata; |
100 | } | |
101 | ||
11f1e38e | 102 | void wx_tree_entry_set_label(wxTreeEntry* entry, const char* label) |
4a46cbe8 | 103 | { |
11f1e38e | 104 | g_assert(WX_IS_TREE_ENTRY(entry)); |
4a46cbe8 RR |
105 | |
106 | /* free previous if it exists */ | |
107 | if(entry->label) | |
108 | { | |
109 | g_free(entry->label); | |
110 | g_free(entry->collate_key); | |
111 | } | |
112 | ||
113 | entry->label = g_strdup(label); | |
442bf2f0 | 114 | entry->collate_key = NULL; |
4a46cbe8 RR |
115 | } |
116 | ||
11f1e38e | 117 | void wx_tree_entry_set_userdata(wxTreeEntry* entry, void* userdata) |
4a46cbe8 | 118 | { |
11f1e38e | 119 | g_assert(WX_IS_TREE_ENTRY(entry)); |
4a46cbe8 RR |
120 | entry->userdata = userdata; |
121 | } | |
122 | ||
11f1e38e PC |
123 | void wx_tree_entry_set_destroy_func(wxTreeEntry* entry, |
124 | wxTreeEntryDestroy destroy_func, | |
4a46cbe8 RR |
125 | gpointer destroy_func_data) |
126 | { | |
11f1e38e | 127 | g_assert(WX_IS_TREE_ENTRY(entry)); |
9d655692 MR |
128 | entry->destroy_func = destroy_func; |
129 | entry->destroy_func_data = destroy_func_data; | |
4a46cbe8 RR |
130 | } |
131 | ||
132 | /* private */ | |
11f1e38e | 133 | static void wx_tree_entry_class_init(void* g_class, void* class_data) |
4a46cbe8 | 134 | { |
26c7d90f | 135 | GObjectClass* gobject_class = G_OBJECT_CLASS(g_class); |
11f1e38e | 136 | gobject_class->dispose = wx_tree_entry_dispose; |
ec34e73c | 137 | parent_class = G_OBJECT_CLASS(g_type_class_peek_parent(g_class)); |
4a46cbe8 RR |
138 | } |
139 | ||
11f1e38e | 140 | static void wx_tree_entry_string_transform_func(const GValue *src_value, |
4a46cbe8 RR |
141 | GValue *dest_value) |
142 | { | |
11f1e38e | 143 | wxTreeEntry* entry; |
2abf7107 PC |
144 | void* src_ptr = g_value_peek_pointer(src_value); |
145 | ||
4a46cbe8 | 146 | /* Make sure src is a treeentry and dest can hold a string */ |
11f1e38e | 147 | g_assert(WX_IS_TREE_ENTRY(src_ptr)); |
4a46cbe8 RR |
148 | g_assert(G_VALUE_HOLDS(dest_value, G_TYPE_STRING)); |
149 | ||
11f1e38e | 150 | entry = WX_TREE_ENTRY(src_ptr); |
9d655692 | 151 | g_value_set_string(dest_value, entry->label); |
4a46cbe8 RR |
152 | } |
153 | ||
11f1e38e | 154 | static void wx_tree_entry_dispose(GObject* obj) |
4a46cbe8 | 155 | { |
11f1e38e | 156 | wxTreeEntry* entry; |
cdff92b9 | 157 | |
11f1e38e | 158 | g_assert(WX_IS_TREE_ENTRY(obj)); |
4a46cbe8 | 159 | |
11f1e38e | 160 | entry = WX_TREE_ENTRY(obj); |
4a46cbe8 RR |
161 | |
162 | /* free label if it exists */ | |
163 | if(entry->label) | |
164 | { | |
165 | g_free(entry->label); | |
166 | g_free(entry->collate_key); | |
167 | entry->label = NULL; | |
168 | entry->collate_key = NULL; | |
169 | } | |
170 | ||
171 | /* call destroy callback if it exists */ | |
172 | if(entry->destroy_func) | |
173 | { | |
174 | (*entry->destroy_func) (entry, entry->destroy_func_data); | |
175 | entry->destroy_func = NULL; | |
176 | entry->destroy_func_data = NULL; | |
177 | } | |
178 | ||
179 | /* clear userdata */ | |
180 | entry->userdata = NULL; | |
ec34e73c PC |
181 | |
182 | parent_class->dispose(obj); | |
4a46cbe8 | 183 | } |