1 /*
2  * widgets/common.h - common widget functions or callbacks
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 #ifndef LUAKIT_WIDGETS_COMMON_H
22 #define LUAKIT_WIDGETS_COMMON_H
23 
24 #include "clib/widget.h"
25 
26 #define LUAKIT_WIDGET_INDEX_COMMON(widget)            \
27     case L_TK_PARENT:                                \
28       return luaH_widget_get_parent(L, widget);      \
29     case L_TK_FOCUSED:                                \
30       return luaH_widget_get_focused(L, widget);      \
31     case L_TK_VISIBLE:                                \
32       return luaH_widget_get_visible(L, widget);      \
33     case L_TK_TOOLTIP:                                \
34       return luaH_widget_get_tooltip(L, widget);      \
35     case L_TK_WIDTH:                                  \
36       return luaH_widget_get_width(L, widget);        \
37     case L_TK_HEIGHT:                                 \
38       return luaH_widget_get_height(L, widget);       \
39     case L_TK_MIN_SIZE:                               \
40       return luaH_widget_get_min_size(L, widget);     \
41     case L_TK_ALIGN:                                  \
42       return luaH_widget_get_align(L, widget);        \
43     case L_TK_CHILDREN:                               \
44       return luaH_widget_get_children(L, widget);     \
45     case L_TK_SHOW:                                   \
46       lua_pushcfunction(L, luaH_widget_show);         \
47       return 1;                                       \
48     case L_TK_HIDE:                                   \
49       lua_pushcfunction(L, luaH_widget_hide);         \
50       return 1;                                       \
51     case L_TK_FOCUS:                                  \
52       lua_pushcfunction(L, luaH_widget_focus);        \
53       return 1;                                       \
54     case L_TK_DESTROY:                                \
55       lua_pushcfunction(L, luaH_widget_destroy);      \
56       return 1;                                       \
57     case L_TK_REPLACE:                                \
58       lua_pushcfunction(L, luaH_widget_replace);      \
59       return 1;                                       \
60     case L_TK_SEND_KEY:                               \
61       lua_pushcfunction(L, luaH_widget_send_key);     \
62       return 1;                                       \
63 
64 #define LUAKIT_WIDGET_NEWINDEX_COMMON(widget)         \
65     case L_TK_VISIBLE:                                \
66       luaH_widget_set_visible(L, widget);             \
67       break;                                          \
68     case L_TK_TOOLTIP:                                \
69       luaH_widget_set_tooltip(L, widget);             \
70       break;                                          \
71     case L_TK_MIN_SIZE:                               \
72       luaH_widget_set_min_size(L, widget);            \
73       break;                                          \
74     case L_TK_ALIGN:                                  \
75       luaH_widget_set_align(L, widget);               \
76       break;                                          \
77 
78 #define LUAKIT_WIDGET_BIN_INDEX_COMMON(widget)        \
79     case L_TK_CHILD:                                  \
80       return luaH_widget_get_child(L, widget);
81 
82 #define LUAKIT_WIDGET_BIN_NEWINDEX_COMMON(widget)     \
83     case L_TK_CHILD:                                  \
84       luaH_widget_set_child(L, widget);               \
85       break;
86 
87 #define LUAKIT_WIDGET_CONTAINER_INDEX_COMMON(widget)  \
88     case L_TK_REMOVE:                                 \
89       lua_pushcfunction(L, luaH_widget_remove);       \
90       return 1;                                       \
91 
92 #define LUAKIT_WIDGET_SIGNAL_COMMON(w)                       \
93     "signal::destroy",         G_CALLBACK(destroy_cb),    w, \
94     "signal::size-allocate",   G_CALLBACK(resize_cb),     w, \
95     "signal::focus-in-event",  G_CALLBACK(focus_cb),      w, \
96     "signal::focus-out-event", G_CALLBACK(focus_cb),      w, \
97     "signal::parent-set",      G_CALLBACK(parent_set_cb), w,
98 
99 gboolean button_cb(GtkWidget*, GdkEventButton*, widget_t*);
100 gboolean scroll_cb(GtkWidget*, GdkEventScroll*, widget_t*);
101 gboolean mouse_cb(GtkWidget*, GdkEventCrossing*, widget_t*);
102 gboolean focus_cb(GtkWidget*, GdkEventFocus*, widget_t*);
103 gboolean key_press_cb(GtkWidget*, GdkEventKey*, widget_t*);
104 gboolean key_release_cb(GtkWidget*, GdkEventKey*, widget_t*);
105 gboolean true_cb();
106 
107 gint luaH_widget_destroy(lua_State*);
108 gint luaH_widget_focus(lua_State*);
109 gint luaH_widget_get_child(lua_State*, widget_t*);
110 gint luaH_widget_get_children(lua_State*, widget_t*);
111 gint luaH_widget_hide(lua_State*);
112 gint luaH_widget_remove(lua_State*);
113 gint luaH_widget_set_child(lua_State*, widget_t*);
114 gint luaH_widget_show(lua_State*);
115 gint luaH_widget_replace(lua_State*);
116 gint luaH_widget_send_key(lua_State *);
117 gint luaH_widget_get_parent(lua_State *L, widget_t *w);
118 gint luaH_widget_get_focused(lua_State *L, widget_t*);
119 gint luaH_widget_get_visible(lua_State *L, widget_t*);
120 gint luaH_widget_get_width(lua_State *L, widget_t*);
121 gint luaH_widget_get_height(lua_State *L, widget_t*);
122 gint luaH_widget_set_visible(lua_State *L, widget_t*);
123 gint luaH_widget_set_tooltip(lua_State *L, widget_t *w);
124 gint luaH_widget_get_tooltip(lua_State *L, widget_t *w);
125 gint luaH_widget_set_min_size(lua_State *L, widget_t *w);
126 gint luaH_widget_get_min_size(lua_State *L, widget_t *w);
127 gint luaH_widget_set_align(lua_State *L, widget_t *w);
128 gint luaH_widget_get_align(lua_State *L, widget_t *w);
129 
130 
131 void add_cb(GtkContainer*, GtkWidget*, widget_t*);
132 void parent_set_cb(GtkWidget*, GtkWidget*, widget_t*);
133 void resize_cb(GtkWidget*, GdkRectangle *, widget_t *);
134 void remove_cb(GtkContainer*, GtkWidget*, widget_t*);
135 void destroy_cb(GtkWidget* UNUSED(win), widget_t *w);
136 void widget_destructor(widget_t*);
137 
138 #endif
139 
140 // vim: ft=c:et:sw=4:ts=8:sts=4:tw=80
141