2 * widgets/label.c - gtk text area 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/>.
23 #include "widgets/common.h"
26 luaH_label_set_alignment(lua_State
*L
)
28 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
29 gfloat xalign
= luaL_checknumber(L
, 2);
30 gfloat yalign
= luaL_checknumber(L
, 3);
31 gtk_misc_set_alignment(GTK_MISC(w
->widget
), xalign
, yalign
);
36 luaH_label_get_alignment(lua_State
*L
)
38 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
39 gfloat xalign
, yalign
;
40 gtk_misc_get_alignment(GTK_MISC(w
->widget
), &xalign
, &yalign
);
41 lua_pushnumber(L
, xalign
);
42 lua_pushnumber(L
, yalign
);
47 luaH_label_set_padding(lua_State
*L
)
49 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
50 gint xpad
= luaL_checknumber(L
, 2);
51 gint ypad
= luaL_checknumber(L
, 3);
52 gtk_misc_set_padding(GTK_MISC(w
->widget
), xpad
, ypad
);
57 luaH_label_get_padding(lua_State
*L
)
59 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
61 gtk_misc_get_padding(GTK_MISC(w
->widget
), &xpad
, &ypad
);
62 lua_pushnumber(L
, xpad
);
63 lua_pushnumber(L
, ypad
);
68 luaH_label_index(lua_State
*L
, luakit_token_t token
)
70 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
75 lua_pushcfunction(L
, luaH_widget_destroy
);
79 lua_pushstring(L
, gtk_label_get_label(GTK_LABEL(w
->widget
)));
82 case L_TK_SET_ALIGNMENT
:
83 lua_pushcfunction(L
, luaH_label_set_alignment
);
86 case L_TK_GET_ALIGNMENT
:
87 lua_pushcfunction(L
, luaH_label_get_alignment
);
90 case L_TK_SET_PADDING
:
91 lua_pushcfunction(L
, luaH_label_set_padding
);
94 case L_TK_GET_PADDING
:
95 lua_pushcfunction(L
, luaH_label_get_padding
);
99 lua_pushstring(L
, g_object_get_data(G_OBJECT(w
->widget
), "fg"));
103 lua_pushstring(L
, g_object_get_data(G_OBJECT(w
->widget
), "font"));
107 lua_pushcfunction(L
, luaH_widget_show
);
111 lua_pushcfunction(L
, luaH_widget_hide
);
114 case L_TK_SELECTABLE
:
115 lua_pushboolean(L
, gtk_label_get_selectable(GTK_LABEL(w
->widget
)));
119 warn("unknown property: %s", luaL_checkstring(L
, 2));
126 luaH_label_newindex(lua_State
*L
, luakit_token_t token
)
129 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
132 PangoFontDescription
*font
;
137 gtk_label_set_markup(GTK_LABEL(w
->widget
),
138 luaL_checklstring(L
, 3, &len
));
142 tmp
= luaL_checklstring(L
, 3, &len
);
143 if (!gdk_color_parse(tmp
, &c
)) {
144 warn("invalid color: %s", tmp
);
148 gtk_widget_modify_fg(GTK_WIDGET(w
->widget
), GTK_STATE_NORMAL
, &c
);
149 g_object_set_data_full(G_OBJECT(w
->widget
), "fg", g_strdup(tmp
), g_free
);
153 tmp
= luaL_checklstring(L
, 3, &len
);
154 font
= pango_font_description_from_string(tmp
);
155 gtk_widget_modify_font(GTK_WIDGET(w
->widget
), font
);
156 g_object_set_data_full(G_OBJECT(w
->widget
), "font", g_strdup(tmp
), g_free
);
159 case L_TK_SELECTABLE
:
160 gtk_label_set_selectable(GTK_LABEL(w
->widget
), luaH_checkboolean(L
, 3));
164 warn("unknown property: %s", luaL_checkstring(L
, 2));
168 return luaH_object_emit_property_signal(L
, 1);
172 label_destructor(widget_t
*w
)
174 gtk_widget_destroy(w
->widget
);
178 widget_label(widget_t
*w
)
180 w
->index
= luaH_label_index
;
181 w
->newindex
= luaH_label_newindex
;
182 w
->destructor
= label_destructor
;
184 /* create gtk label widget as main widget */
185 w
->widget
= gtk_label_new(NULL
);
186 g_object_set_data(G_OBJECT(w
->widget
), "widget", (gpointer
) w
);
188 /* setup default settings */
189 gtk_label_set_selectable(GTK_LABEL(w
->widget
), FALSE
);
190 gtk_label_set_use_markup(GTK_LABEL(w
->widget
), TRUE
);
191 gtk_misc_set_alignment(GTK_MISC(w
->widget
), 0, 0);
192 gtk_misc_set_padding(GTK_MISC(w
->widget
), 2, 2);
194 g_object_connect((GObject
*)w
->widget
,
195 "signal::focus-in-event", (GCallback
)focus_cb
, w
,
196 "signal::focus-out-event", (GCallback
)focus_cb
, w
,
197 "signal::key-press-event", (GCallback
)key_press_cb
, w
,
198 "signal::parent-set", (GCallback
)parent_set_cb
, w
,
201 gtk_widget_show(w
->widget
);
205 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80