Refactor to silence gcc uninit errors
[luakit.git] / widgets / eventbox.c
blob40993326aed79166a609cfd9e74f0e42f7c51500
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_SET_CHILD:
33 lua_pushcfunction(L, luaH_widget_set_child);
34 return 1;
36 case L_TK_GET_CHILD:
37 lua_pushcfunction(L, luaH_widget_get_child);
38 return 1;
40 case L_TK_BG:
41 lua_pushstring(L, g_object_get_data(G_OBJECT(w->widget), "bg"));
42 return 1;
44 case L_TK_SHOW:
45 lua_pushcfunction(L, luaH_widget_show);
46 return 1;
48 case L_TK_HIDE:
49 lua_pushcfunction(L, luaH_widget_hide);
50 return 1;
52 default:
53 break;
55 return 0;
58 static gint
59 luaH_eventbox_newindex(lua_State *L, luakit_token_t token)
61 size_t len;
62 widget_t *w = luaH_checkudata(L, 1, &widget_class);
63 const gchar *tmp;
64 GdkColor c;
66 switch(token)
68 case L_TK_BG:
69 tmp = luaL_checklstring(L, 3, &len);
70 if (!gdk_color_parse(tmp, &c)) {
71 warn("invalid color: %s", tmp);
72 return 0;
75 gtk_widget_modify_bg(GTK_WIDGET(w->widget), GTK_STATE_NORMAL, &c);
76 g_object_set_data_full(G_OBJECT(w->widget), "bg", g_strdup(tmp), g_free);
77 break;
79 default:
80 return 0;
83 return luaH_object_emit_property_signal(L, 1);
86 static void
87 eventbox_destructor(widget_t *w)
89 gtk_widget_destroy(w->widget);
92 widget_t *
93 widget_eventbox(widget_t *w)
95 w->index = luaH_eventbox_index;
96 w->newindex = luaH_eventbox_newindex;
97 w->destructor = eventbox_destructor;
99 w->widget = gtk_event_box_new();
100 g_object_set_data(G_OBJECT(w->widget), "widget", (gpointer) w);
101 gtk_widget_show(w->widget);
103 g_object_connect((GObject*)w->widget,
104 "signal::add", (GCallback)add_cb, w,
105 "signal::parent-set", (GCallback)parent_set_cb, w,
106 "signal::remove", (GCallback)remove_cb, w,
107 NULL);
109 return w;
112 // vim: ft=c:et:sw=4:ts=8:sts=4:enc=utf-8:tw=80