forked from darktable-org/darktable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbutton.c
More file actions
80 lines (67 loc) · 2.57 KB
/
Copy pathbutton.c
File metadata and controls
80 lines (67 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
This file is part of darktable,
copyright (c) 2015 Jeremy Rosen
darktable is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
darktable is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with darktable. If not, see <http://www.gnu.org/licenses/>.
*/
#include "lua/widget/common.h"
#include "lua/types.h"
static dt_lua_widget_type_t button_type = {
.name = "button",
.gui_init = NULL,
.gui_cleanup = NULL,
.alloc_size = sizeof(dt_lua_widget_t),
.parent= &widget_type
};
static void clicked_callback(GtkButton *widget, gpointer user_data)
{
dt_lua_do_chunk_async(dt_lua_widget_trigger_callback,
LUA_ASYNC_TYPENAME,"lua_widget",user_data,
LUA_ASYNC_TYPENAME,"const char*","clicked",
LUA_ASYNC_DONE);
}
static int label_member(lua_State *L)
{
lua_button button;
luaA_to(L,lua_button,&button,1);
if(lua_gettop(L) > 2) {
const char * label = luaL_checkstring(L,3);
gtk_button_set_label(GTK_BUTTON(button->widget),label);
return 0;
}
lua_pushstring(L,gtk_button_get_label(GTK_BUTTON(button->widget)));
return 1;
}
static int tostring_member(lua_State *L)
{
lua_button widget;
luaA_to(L, lua_button, &widget, 1);
const gchar *text = gtk_button_get_label(GTK_BUTTON(widget->widget));
gchar *res = g_strdup_printf("%s (\"%s\")", G_OBJECT_TYPE_NAME(widget->widget), text ? text : "");
lua_pushstring(L, res);
g_free(res);
return 1;
}
int dt_lua_init_widget_button(lua_State* L)
{
dt_lua_init_widget_type(L,&button_type,lua_button,GTK_TYPE_BUTTON);
lua_pushcfunction(L, tostring_member);
lua_pushcclosure(L, dt_lua_gtk_wrap, 1);
dt_lua_type_setmetafield(L, lua_button, "__tostring");
lua_pushcfunction(L,label_member);
lua_pushcclosure(L,dt_lua_gtk_wrap,1);
dt_lua_type_register(L, lua_button, "label");
dt_lua_widget_register_gtk_callback(L,lua_button,"clicked","clicked_callback",G_CALLBACK(clicked_callback));
return 0;
}
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-space on;