1 /*
2  * widgets/eventbox.c - gtk eventbox widget
3  *
4  * Copyright © 2010 Mason Larobina <mason.larobina@gmail.com>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include "luah.h"
22 #include "widgets/common.h"
23 
24 static gint
luaH_eventbox_index(lua_State * L,widget_t * w,luakit_token_t token)25 luaH_eventbox_index(lua_State *L, widget_t *w, luakit_token_t token)
26 {
27     switch(token) {
28       LUAKIT_WIDGET_INDEX_COMMON(w)
29       LUAKIT_WIDGET_BIN_INDEX_COMMON(w)
30       LUAKIT_WIDGET_CONTAINER_INDEX_COMMON(w)
31 
32       /* push string properties */
33       PS_CASE(BG, g_object_get_data(G_OBJECT(w->widget), "bg"))
34 
35       default:
36         break;
37     }
38     return 0;
39 }
40 
41 static gint
luaH_eventbox_newindex(lua_State * L,widget_t * w,luakit_token_t token)42 luaH_eventbox_newindex(lua_State *L, widget_t *w, luakit_token_t token)
43 {
44     size_t len;
45     const gchar *tmp;
46     GdkRGBA c;
47 
48     switch(token) {
49       LUAKIT_WIDGET_NEWINDEX_COMMON(w)
50       LUAKIT_WIDGET_BIN_NEWINDEX_COMMON(w)
51 
52       case L_TK_BG:
53         tmp = luaL_checklstring(L, 3, &len);
54         if (!gdk_rgba_parse(&c, tmp))
55             luaL_argerror(L, 3, "unable to parse colour");
56 #if GTK_CHECK_VERSION(3,16,0)
57         widget_set_css_properties(w, "background-color", tmp, NULL);
58 #else
59         gtk_widget_override_background_color(GTK_WIDGET(w->widget), GTK_STATE_FLAG_NORMAL, &c);
60 #endif
61         g_object_set_data_full(G_OBJECT(w->widget), "bg", g_strdup(tmp), g_free);
62         break;
63 
64       default:
65         return 0;
66     }
67 
68     return luaH_object_property_signal(L, 1, token);
69 }
70 
71 widget_t *
widget_eventbox(lua_State * UNUSED (L),widget_t * w,luakit_token_t UNUSED (token))72 widget_eventbox(lua_State *UNUSED(L), widget_t *w, luakit_token_t UNUSED(token))
73 {
74     w->index = luaH_eventbox_index;
75     w->newindex = luaH_eventbox_newindex;
76 
77     w->widget = gtk_event_box_new();
78     gtk_widget_show(w->widget);
79 
80     g_object_connect(G_OBJECT(w->widget),
81       LUAKIT_WIDGET_SIGNAL_COMMON(w)
82       "signal::add",                  G_CALLBACK(add_cb),        w,
83       "signal::button-press-event",   G_CALLBACK(button_cb),     w,
84       "signal::button-release-event", G_CALLBACK(button_cb),     w,
85       "signal::scroll-event",         G_CALLBACK(scroll_cb),     w,
86       "signal::enter-notify-event",   G_CALLBACK(mouse_cb),      w,
87       "signal::leave-notify-event",   G_CALLBACK(mouse_cb),      w,
88       NULL);
89 
90     return w;
91 }
92 
93 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80
94