Set destructor = NULL in destroy func to prevent it being called twice
[luakit.git] / widgets / textbutton.c
blob941118acb8ea723e2599abbf00febafdf6563953
1 /*
2 * widgets/textbutton.c - gtk button with label
4 * Copyright (C) 2010 Mason Larobina <mason.larobina@gmail.com>
5 * Copyright (C) 2007-2009 Julien Danjou <julien@danjou.info>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "luah.h"
23 #include "widgets/common.h"
25 static gint
26 luaH_textbutton_index(lua_State *L, luakit_token_t token)
28 widget_t *w = luaH_checkudata(L, 1, &widget_class);
30 switch (token)
32 LUAKIT_WIDGET_INDEX_COMMON
34 /* push string properties */
35 PS_CASE(LABEL, gtk_button_get_label(GTK_BUTTON(w->widget)))
37 default:
38 break;
40 return 0;
43 static gint
44 luaH_textbutton_newindex(lua_State *L, luakit_token_t token)
46 size_t len;
47 widget_t *w = luaH_checkudata(L, 1, &widget_class);
49 switch(token)
51 case L_TK_LABEL:
52 gtk_button_set_label(GTK_BUTTON(w->widget),
53 luaL_checklstring(L, 3, &len));
54 break;
56 default:
57 return 0;
60 return luaH_object_emit_property_signal(L, 1);
63 static void
64 clicked_cb(GtkWidget *b, widget_t *w)
66 (void) b;
67 lua_State *L = globalconf.L;
68 luaH_object_push(L, w->ref);
69 luaH_object_emit_signal(L, -1, "clicked", 0, 0);
70 lua_pop(L, 1);
73 widget_t *
74 widget_textbutton(widget_t *w)
76 w->index = luaH_textbutton_index;
77 w->newindex = luaH_textbutton_newindex;
78 w->destructor = widget_destructor;
80 w->widget = gtk_button_new();
81 g_object_set_data(G_OBJECT(w->widget), "widget", (gpointer) w);
82 gtk_button_set_focus_on_click(GTK_BUTTON(w->widget), FALSE);
84 g_object_connect((GObject*)w->widget,
85 "signal::clicked", (GCallback)clicked_cb, w,
86 "signal::focus-in-event", (GCallback)focus_cb, w,
87 "signal::focus-out-event", (GCallback)focus_cb, w,
88 "signal::parent-set", (GCallback)parent_set_cb, w,
89 NULL);
91 gtk_widget_show(w->widget);
92 return w;
95 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80