2 * widgets/box.c - gtk hbox & vbox container widgets
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/>.
23 * - Add `remove(child)` method to remove child widgets from the box
24 * - Add `reorder(child, index)` method to re-order child widgets
25 * - Add `get_children()` method to return a table of widgets in the box
26 * - In the box destructor function detach all child windows
31 #include "widgets/common.h"
33 /* direct wrapper around gtk_box_pack_start */
35 luaH_box_pack_start(lua_State
*L
)
37 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
38 widget_t
*child
= luaH_checkudata(L
, 2, &widget_class
);
39 gboolean expand
= luaH_checkboolean(L
, 3);
40 gboolean fill
= luaH_checkboolean(L
, 4);
41 guint padding
= luaL_checknumber(L
, 5);
42 gtk_box_pack_start(GTK_BOX(w
->widget
), GTK_WIDGET(child
->widget
),
43 expand
, fill
, padding
);
47 /* direct wrapper around gtk_box_pack_end */
49 luaH_box_pack_end(lua_State
*L
)
51 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
52 widget_t
*child
= luaH_checkudata(L
, 2, &widget_class
);
53 gboolean expand
= luaH_checkboolean(L
, 3);
54 gboolean fill
= luaH_checkboolean(L
, 4);
55 guint padding
= luaL_checknumber(L
, 5);
56 gtk_box_pack_end(GTK_BOX(w
->widget
), GTK_WIDGET(child
->widget
),
57 expand
, fill
, padding
);
62 luaH_box_index(lua_State
*L
, luakit_token_t token
)
64 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
69 lua_pushcfunction(L
, luaH_widget_destroy
);
73 lua_pushcfunction(L
, luaH_box_pack_start
);
77 lua_pushcfunction(L
, luaH_box_pack_end
);
80 case L_TK_HOMOGENEOUS
:
81 lua_pushboolean(L
, gtk_box_get_homogeneous(GTK_BOX(w
->widget
)));
85 lua_pushnumber(L
, gtk_box_get_spacing(GTK_BOX(w
->widget
)));
89 lua_pushcfunction(L
, luaH_widget_show
);
93 lua_pushcfunction(L
, luaH_widget_hide
);
103 luaH_box_newindex(lua_State
*L
, luakit_token_t token
)
105 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
109 case L_TK_HOMOGENEOUS
:
110 gtk_box_set_homogeneous(GTK_BOX(w
->widget
), luaH_checkboolean(L
, 3));
114 gtk_box_set_spacing(GTK_BOX(w
->widget
), luaL_checknumber(L
, 3));
121 return luaH_object_emit_property_signal(L
, 1);
125 box_destructor(widget_t
*w
)
127 gtk_widget_destroy(w
->widget
);
130 #define BOX_WIDGET_CONSTRUCTOR(type) \
132 widget_##type(widget_t *w) \
134 w->index = luaH_box_index; \
135 w->newindex = luaH_box_newindex; \
136 w->destructor = box_destructor; \
137 w->widget = gtk_##type##_new(FALSE, 0); \
138 g_object_set_data(G_OBJECT(w->widget), "widget", (gpointer) w); \
139 gtk_widget_show(w->widget); \
140 g_object_connect((GObject*)w->widget, \
141 "signal::add", add_cb, w, \
142 "signal::parent-set", parent_set_cb, w, \
143 "signal::remove", remove_cb, w, \
148 BOX_WIDGET_CONSTRUCTOR(vbox
)
149 BOX_WIDGET_CONSTRUCTOR(hbox
)
151 #undef BOX_WIDGET_CONSTRUCTOR
153 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80