Add P{B,F,N,S}_CASE & LUAKIT_WIDGET_{,BIN_}INDEX_COMMON macros
[luakit.git] / widgets / eventbox.c
blob928fcc5ff545c878733ecedc9360498386e016e3
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 LUAKIT_WIDGET_INDEX_COMMON
33 LUAKIT_WIDGET_BIN_INDEX_COMMON
35 /* push string properties */
36 PS_CASE(BG, g_object_get_data(G_OBJECT(w->widget), "bg"))
38 default:
39 break;
41 return 0;
44 static gint
45 luaH_eventbox_newindex(lua_State *L, luakit_token_t token)
47 size_t len;
48 widget_t *w = luaH_checkudata(L, 1, &widget_class);
49 const gchar *tmp;
50 GdkColor c;
52 switch(token)
54 case L_TK_BG:
55 tmp = luaL_checklstring(L, 3, &len);
56 if (!gdk_color_parse(tmp, &c))
57 luaL_argerror(L, 3, "unable to parse colour");
58 gtk_widget_modify_bg(GTK_WIDGET(w->widget), GTK_STATE_NORMAL, &c);
59 g_object_set_data_full(G_OBJECT(w->widget), "bg", g_strdup(tmp), g_free);
60 break;
62 default:
63 return 0;
66 return luaH_object_emit_property_signal(L, 1);
69 widget_t *
70 widget_eventbox(widget_t *w)
72 w->index = luaH_eventbox_index;
73 w->newindex = luaH_eventbox_newindex;
74 w->destructor = widget_destructor;
76 w->widget = gtk_event_box_new();
77 g_object_set_data(G_OBJECT(w->widget), "widget", (gpointer) w);
78 gtk_widget_show(w->widget);
80 g_object_connect((GObject*)w->widget,
81 "signal::add", (GCallback)add_cb, w,
82 "signal::button-release-event", (GCallback)button_release_cb, w,
83 "signal::parent-set", (GCallback)parent_set_cb, w,
84 "signal::remove", (GCallback)remove_cb, w,
85 NULL);
87 return w;
90 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80