rc.lua: use http_proxy environment variable
[luakit.git] / widgets / textbutton.c
blobe3c2ebbe0e59c848867e1698e0452cdd69c0aaa8
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 case L_TK_DESTROY:
33 lua_pushcfunction(L, luaH_widget_destroy);
34 return 1;
36 case L_TK_LABEL:
37 lua_pushstring(L, gtk_button_get_label(GTK_BUTTON(w->widget)));
38 return 1;
40 case L_TK_SHOW:
41 lua_pushcfunction(L, luaH_widget_show);
42 return 1;
44 case L_TK_HIDE:
45 lua_pushcfunction(L, luaH_widget_hide);
46 return 1;
48 default:
49 break;
51 return 0;
54 static gint
55 luaH_textbutton_newindex(lua_State *L, luakit_token_t token)
57 size_t len;
58 widget_t *w = luaH_checkudata(L, 1, &widget_class);
60 switch(token)
62 case L_TK_LABEL:
63 gtk_button_set_label(GTK_BUTTON(w->widget),
64 luaL_checklstring(L, 3, &len));
65 break;
67 default:
68 return 0;
71 return luaH_object_emit_property_signal(L, 1);
74 static void
75 clicked_cb(GtkWidget *b, widget_t *w)
77 (void) b;
78 lua_State *L = globalconf.L;
79 luaH_object_push(L, w->ref);
80 luaH_object_emit_signal(L, -1, "clicked", 0, 0);
81 lua_pop(L, 1);
84 static void
85 textbutton_destructor(widget_t *w)
87 gtk_widget_destroy(w->widget);
90 widget_t *
91 widget_textbutton(widget_t *w)
93 w->index = luaH_textbutton_index;
94 w->newindex = luaH_textbutton_newindex;
95 w->destructor = textbutton_destructor;
97 w->widget = gtk_button_new();
98 g_object_set_data(G_OBJECT(w->widget), "widget", (gpointer) w);
99 gtk_button_set_focus_on_click(GTK_BUTTON(w->widget), FALSE);
101 g_object_connect((GObject*)w->widget,
102 "signal::clicked", (GCallback)clicked_cb, w,
103 "signal::focus-in-event", (GCallback)focus_cb, w,
104 "signal::focus-out-event", (GCallback)focus_cb, w,
105 "signal::parent-set", (GCallback)parent_set_cb, w,
106 NULL);
108 gtk_widget_show(w->widget);
109 return w;
112 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80