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
);
74 LUAKIT_WIDGET_INDEX_COMMON
76 /* push class methods */
77 PF_CASE(GET_ALIGNMENT
, luaH_label_get_alignment
);
78 PF_CASE(GET_PADDING
, luaH_label_get_padding
);
79 PF_CASE(SET_ALIGNMENT
, luaH_label_set_alignment
);
80 PF_CASE(SET_PADDING
, luaH_label_set_padding
);
81 /* push string properties */
82 PS_CASE(FG
, g_object_get_data(G_OBJECT(w
->widget
), "fg"))
83 PS_CASE(FONT
, g_object_get_data(G_OBJECT(w
->widget
), "font"))
84 PS_CASE(TEXT
, gtk_label_get_label(GTK_LABEL(w
->widget
)))
85 /* push boolean properties */
86 PB_CASE(SELECTABLE
, gtk_label_get_selectable(GTK_LABEL(w
->widget
)))
89 warn("unknown property: %s", luaL_checkstring(L
, 2));
96 luaH_label_newindex(lua_State
*L
, luakit_token_t token
)
99 widget_t
*w
= luaH_checkudata(L
, 1, &widget_class
);
102 PangoFontDescription
*font
;
107 gtk_label_set_markup(GTK_LABEL(w
->widget
),
108 luaL_checklstring(L
, 3, &len
));
112 tmp
= luaL_checklstring(L
, 3, &len
);
113 if (!gdk_color_parse(tmp
, &c
)) {
114 warn("invalid color: %s", tmp
);
118 gtk_widget_modify_fg(GTK_WIDGET(w
->widget
), GTK_STATE_NORMAL
, &c
);
119 g_object_set_data_full(G_OBJECT(w
->widget
), "fg", g_strdup(tmp
), g_free
);
123 tmp
= luaL_checklstring(L
, 3, &len
);
124 font
= pango_font_description_from_string(tmp
);
125 gtk_widget_modify_font(GTK_WIDGET(w
->widget
), font
);
126 g_object_set_data_full(G_OBJECT(w
->widget
), "font", g_strdup(tmp
), g_free
);
129 case L_TK_SELECTABLE
:
130 gtk_label_set_selectable(GTK_LABEL(w
->widget
), luaH_checkboolean(L
, 3));
134 warn("unknown property: %s", luaL_checkstring(L
, 2));
138 return luaH_object_emit_property_signal(L
, 1);
142 widget_label(widget_t
*w
)
144 w
->index
= luaH_label_index
;
145 w
->newindex
= luaH_label_newindex
;
146 w
->destructor
= widget_destructor
;
148 /* create gtk label widget as main widget */
149 w
->widget
= gtk_label_new(NULL
);
150 g_object_set_data(G_OBJECT(w
->widget
), "widget", (gpointer
) w
);
152 /* setup default settings */
153 gtk_label_set_selectable(GTK_LABEL(w
->widget
), FALSE
);
154 gtk_label_set_use_markup(GTK_LABEL(w
->widget
), TRUE
);
155 gtk_misc_set_alignment(GTK_MISC(w
->widget
), 0, 0);
156 gtk_misc_set_padding(GTK_MISC(w
->widget
), 2, 2);
158 g_object_connect((GObject
*)w
->widget
,
159 "signal::focus-in-event", (GCallback
)focus_cb
, w
,
160 "signal::focus-out-event", (GCallback
)focus_cb
, w
,
161 "signal::key-press-event", (GCallback
)key_press_cb
, w
,
162 "signal::parent-set", (GCallback
)parent_set_cb
, w
,
165 gtk_widget_show(w
->widget
);
169 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80