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