Add `bind.but({mods}, num, func)` for mouse bindings & add mouse binds
[luakit.git] / widgets / eventbox.c
blob21feefe1b2b7a2487bad3a396b2d51fd6580eca4
1 /*
2 * widgets/eventbox.c - gtk eventbox widget
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_eventbox_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_SET_CHILD:
37 lua_pushcfunction(L, luaH_widget_set_child);
38 return 1;
40 case L_TK_GET_CHILD:
41 lua_pushcfunction(L, luaH_widget_get_child);
42 return 1;
44 case L_TK_BG:
45 lua_pushstring(L, g_object_get_data(G_OBJECT(w->widget), "bg"));
46 return 1;
48 case L_TK_SHOW:
49 lua_pushcfunction(L, luaH_widget_show);
50 return 1;
52 case L_TK_HIDE:
53 lua_pushcfunction(L, luaH_widget_hide);
54 return 1;
56 default:
57 break;
59 return 0;
62 static gint
63 luaH_eventbox_newindex(lua_State *L, luakit_token_t token)
65 size_t len;
66 widget_t *w = luaH_checkudata(L, 1, &widget_class);
67 const gchar *tmp;
68 GdkColor c;
70 switch(token)
72 case L_TK_BG:
73 tmp = luaL_checklstring(L, 3, &len);
74 if (!gdk_color_parse(tmp, &c)) {
75 warn("invalid color: %s", tmp);
76 return 0;
79 gtk_widget_modify_bg(GTK_WIDGET(w->widget), GTK_STATE_NORMAL, &c);
80 g_object_set_data_full(G_OBJECT(w->widget), "bg", g_strdup(tmp), g_free);
81 break;
83 default:
84 return 0;
87 return luaH_object_emit_property_signal(L, 1);
90 static void
91 eventbox_destructor(widget_t *w)
93 gtk_widget_destroy(w->widget);
96 widget_t *
97 widget_eventbox(widget_t *w)
99 w->index = luaH_eventbox_index;
100 w->newindex = luaH_eventbox_newindex;
101 w->destructor = eventbox_destructor;
103 w->widget = gtk_event_box_new();
104 g_object_set_data(G_OBJECT(w->widget), "widget", (gpointer) w);
105 gtk_widget_show(w->widget);
107 g_object_connect((GObject*)w->widget,
108 "signal::add", (GCallback)add_cb, w,
109 "signal::button-press-event", (GCallback)button_press_cb, w,
110 "signal::parent-set", (GCallback)parent_set_cb, w,
111 "signal::remove", (GCallback)remove_cb, w,
112 NULL);
114 return w;
117 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80