gwenhywfar 5.10.1
gtk3/w_combobox.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Sun May 16 2010
3 copyright : (C) 2010 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * Please see toplevel file COPYING for license details *
8 ***************************************************************************/
9
10
11typedef struct W_COMBOBOX W_COMBOBOX;
12struct W_COMBOBOX {
14};
15
16
18
19
20
21
22static GWENHYWFAR_CB
25 GWEN_UNUSED int index,
26 int value,
27 GWEN_UNUSED int doSignal)
28{
29 GtkWidget *g;
30 W_COMBOBOX *xw;
31
32 assert(w);
34 assert(xw);
35
37 assert(g);
38
39 switch (prop) {
41 gtk_widget_set_sensitive(GTK_WIDGET(g), (value==0)?FALSE:TRUE);
42 return 0;
43
45 gtk_widget_grab_focus(GTK_WIDGET(g));
46 return 0;
47
49 gtk_combo_box_set_active(GTK_COMBO_BOX(g), value);
50 return 0;
51
53 GtkListStore *store;
54
55 store=GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(g)));
56 assert(store);
57 gtk_list_store_clear(store);
59 return 0;
60 }
61
62
63 default:
64 break;
65 }
66
68 "Function is not appropriate for this type of widget (%s)",
70 return GWEN_ERROR_INVALID;
71}
72
73
74
75
76static GWENHYWFAR_CB
79 GWEN_UNUSED int index,
80 int defaultValue)
81{
82 GtkWidget *g;
83
85 assert(g);
86
87 switch (prop) {
89 return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0;
90
92 return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0;
93 return 0;
94
96 gint i;
97
98 i=gtk_combo_box_get_active(GTK_COMBO_BOX(g));
99 if (i==-1)
100 return defaultValue;
101 else
102 return i;
103 }
104
106 GtkListStore *store;
107 gint i;
108
109 store=GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(g)));
110 assert(store);
111 i=gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);
112 return i;
113 }
114
115 default:
116 break;
117 }
118
120 "Function is not appropriate for this type of widget (%s)",
122 return defaultValue;
123}
124
125
126
127static GWENHYWFAR_CB
130 GWEN_UNUSED int index,
131 const char *value,
132 GWEN_UNUSED int doSignal)
133{
134 GtkWidget *g;
135 W_COMBOBOX *xw;
136
137 assert(w);
139 assert(xw);
140
142 assert(g);
143
144 switch (prop) {
146 /* undefined */
147 break;
148
150 GtkListStore *store;
151 GtkTreeIter iter;
152
153 store=GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(g)));
154 assert(store);
155
156 gtk_list_store_append(store, &iter);
157 gtk_list_store_set(store, &iter, 0, value, -1);
158 GWEN_StringList_AppendString(xw->entries, value, 0, 0);
159 return 0;
160 }
161
163 GtkListStore *store;
164
165 store=GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(g)));
166 assert(store);
167 gtk_list_store_clear(store);
169 return 0;
170 }
171
172 default:
173 break;
174 }
175
177 "Function is not appropriate for this type of widget (%s)",
179 return GWEN_ERROR_INVALID;
180}
181
182
183
184static GWENHYWFAR_CB
187 int index,
188 const char *defaultValue)
189{
190 GtkWidget *g;
191 W_COMBOBOX *xw;
192
193 assert(w);
195 assert(xw);
196
198 assert(g);
199
200 switch (prop) {
202 const char *s;
203
204 s=GWEN_StringList_StringAt(xw->entries, index);
205 if (s && *s)
206 return s;
207 else
208 return defaultValue;
209 }
210
211 default:
212 break;
213 }
214
216 "Function is not appropriate for this type of widget (%s)",
218 return defaultValue;
219}
220
221
222
223static void changed_handler(GWEN_UNUSED GtkWidget *comboBox, gpointer data)
224{
225 GWEN_WIDGET *w;
226 int rv;
227
228 w=data;
229 assert(w);
237}
238
239
240
242{
243 W_COMBOBOX *xw;
244
245 xw=(W_COMBOBOX *) p;
248}
249
250
251
253{
254 W_COMBOBOX *xw;
255 GtkWidget *g;
256 GtkCellRenderer *cr;
257 GtkListStore *store;
258 uint32_t flags;
259 GWEN_WIDGET *wParent;
260
261 flags=GWEN_Widget_GetFlags(w);
262 wParent=GWEN_Widget_Tree_GetParent(w);
263
264 /* create widget */
265 store=gtk_list_store_new(1, G_TYPE_STRING);
266 if (flags & GWEN_WIDGET_FLAGS_READONLY)
267 g=gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
268 else {
269 /* TODO: why the heck does *this* combo box have two columns in the list?? */
270 g=gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(store));
271 gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(g), 0);
272 }
273 g_object_unref(store);
274
275 cr=gtk_cell_renderer_text_new();
276 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(g), cr, TRUE);
277 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(g), cr, "text", 0, NULL);
278
282
285
290
291 g_signal_connect(g,
292 "changed",
293 G_CALLBACK(changed_handler),
294 w);
295
296 if (wParent)
298
299 return 0;
300}
301
302
#define NULL
Definition: binreloc.c:300
#define DBG_WARN(dbg_logger, format, args...)
Definition: debug.h:125
int GWEN_Dialog_EmitSignal(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition: dialog.c:321
@ GWEN_DialogEvent_ResultAccept
Definition: dialog.h:122
@ GWEN_DialogEvent_ResultReject
Definition: dialog.h:123
#define GWEN_WIDGET_FLAGS_READONLY
Definition: dialog.h:63
GWEN_DIALOG_PROPERTY
Definition: dialog.h:260
@ GWEN_DialogProperty_AddValue
Definition: dialog.h:268
@ GWEN_DialogProperty_ValueCount
Definition: dialog.h:270
@ GWEN_DialogProperty_ClearValues
Definition: dialog.h:269
@ GWEN_DialogProperty_Enabled
Definition: dialog.h:267
@ GWEN_DialogProperty_Value
Definition: dialog.h:264
@ GWEN_DialogProperty_Focus
Definition: dialog.h:276
@ GWEN_DialogEvent_TypeActivated
Definition: dialog.h:102
#define GWEN_ERROR_INVALID
Definition: error.h:67
static void GWENHYWFAR_CB Gtk3Gui_WComboBox_FreeData(GWEN_UNUSED void *bp, void *p)
static GWENHYWFAR_CB int Gtk3Gui_WComboBox_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int value, GWEN_UNUSED int doSignal)
static void changed_handler(GWEN_UNUSED GtkWidget *comboBox, gpointer data)
static GWENHYWFAR_CB int Gtk3Gui_WComboBox_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int defaultValue)
static GWENHYWFAR_CB const char * Gtk3Gui_WComboBox_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
int Gtk3Gui_WComboBox_Setup(GWEN_WIDGET *w)
static GWENHYWFAR_CB int Gtk3Gui_WComboBox_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, const char *value, GWEN_UNUSED int doSignal)
#define GTK3_DIALOG_WIDGET_CONTENT
#define GTK3_DIALOG_WIDGET_REAL
void Gtk3Gui_Dialog_Leave(GWEN_DIALOG *dlg, int result)
#define GWEN_UNUSED
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:292
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271
#define GWEN_LOGDOMAIN
Definition: logger.h:35
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
Definition: stringlist.c:62
void GWEN_StringList_Clear(GWEN_STRINGLIST *sl)
Definition: stringlist.c:228
int GWEN_StringList_AppendString(GWEN_STRINGLIST *sl, const char *s, int take, int checkDouble)
Definition: stringlist.c:245
const char * GWEN_StringList_StringAt(const GWEN_STRINGLIST *sl, int idx)
Definition: stringlist.c:730
GWEN_STRINGLIST * GWEN_StringList_new(void)
Definition: stringlist.c:50
struct GWEN_STRINGLISTSTRUCT GWEN_STRINGLIST
Definition: stringlist.h:56
GWEN_STRINGLIST * entries
GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
Definition: widget.c:732
GWEN_DIALOG * GWEN_Widget_GetTopDialog(const GWEN_WIDGET *w)
Definition: widget.c:102
const char * GWEN_Widget_GetName(const GWEN_WIDGET *w)
Definition: widget.c:320
GWEN_WIDGET_GETINTPROPERTY_FN GWEN_Widget_SetGetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETINTPROPERTY_FN fn)
Definition: widget.c:702
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition: widget.c:828
void GWEN_Widget_SetImplData(GWEN_WIDGET *w, int index, void *ptr)
Store a pointer with the widget.
Definition: widget.c:136
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition: widget.c:122
GWEN_WIDGET_SETINTPROPERTY_FN GWEN_Widget_SetSetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETINTPROPERTY_FN fn)
Definition: widget.c:687
uint32_t GWEN_Widget_GetFlags(const GWEN_WIDGET *w)
Definition: widget.c:149
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition: widget.c:452
GWEN_DIALOG * GWEN_Widget_GetDialog(const GWEN_WIDGET *w)
Definition: widget.c:92
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition: widget.c:185
GWEN_WIDGET_SETCHARPROPERTY_FN GWEN_Widget_SetSetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETCHARPROPERTY_FN fn)
Definition: widget.c:717
struct GWEN_WIDGET GWEN_WIDGET
Definition: widget_be.h:34