added elementary layout, clock. prototyped plugin configuration
[ego.git] / src / lib / elementary.c
blob77045f3706f55dc4ac25c265fbe903ac02d6a621
1 #include "class.h"
2 #include "object.h"
3 #include "macro.h"
4 #include <Evas.h>
6 /*
7 * Elementary callback
8 */
10 static void
11 elm_callback (void *data, Evas_Object *obj, void *event_info)
13 luaobj_Ref *ref1 = evas_object_data_get (obj, "luaobj");
14 luaobj_Ref *ref2 = data;
15 luaobj_get_ref (ref1->L, ref2);
16 luaobj_get_ref (ref1->L, ref1);
17 if (lua_pcall (ref1->L, 1, 0, 0))
18 fprintf (stderr, "elm_callback: %s\n", lua_tostring (ref1->L, -1));
20 #define ELM_CB(FUNC, NAME) \
21 static int \
22 FUNC (lua_State *L) \
23 { \
24 luaobj_Object *obj = (luaobj_Object *) lua_touserdata (L, 1); \
25 evas_object_smart_callback_add ( \
26 obj->data, \
27 NAME, \
28 elm_callback, \
29 (void *) luaobj_new_ref (L, 2)); \
30 return 0; \
34 * Elementary Icon
37 static int
38 licon_set_file (lua_State *L)
40 luaobj_Object *obj = (luaobj_Object *) lua_touserdata (L, 1);
41 int key = luaL_checknumber (L, 2);
42 char buf [256];
43 sprintf (buf, "images/%i", key);
44 lua_getfield (L, LUA_REGISTRYINDEX, "ego_file");
45 const char *file = luaL_checkstring (L, -1);
46 elm_icon_file_set (obj->data, file, buf);
47 return 0;
50 SET_STRING (licon_set_standard, elm_icon_standard_set);
51 SET_BOOL (licon_set_smooth, elm_icon_smooth_set);
52 SET_BOOL (licon_set_no_scale, elm_icon_no_scale_set);
53 SET_TAB2BOOL (licon_set_scale, elm_icon_scale_set);
54 SET_BOOL (licon_set_fill_outside, elm_icon_fill_outside_set);
56 const struct luaL_Reg lNil[] = {
57 {NULL, NULL} // sentinel
60 const struct luaL_Reg lIcon_set[] = {
61 {"file", licon_set_file},
62 {"standard", licon_set_standard},
63 {"smooth", licon_set_smooth},
64 {"no_scale", licon_set_no_scale},
65 {"scale", licon_set_scale},
66 {"fill_outside", licon_set_fill_outside},
67 {NULL, NULL} // sentinel
70 const luaobj_Reg mIcon = {
71 lNil,
72 lNil,
73 lIcon_set,
74 lNil
77 const luaobj_Reg *cIcon[] = {
78 &mClass,
79 &mObject,
80 &mIcon,
81 NULL
85 * Elementary Box
88 SET_BOOL (lbox_set_horizontal, elm_box_horizontal_set);
89 SET_BOOL (lbox_set_homogenous, elm_box_homogenous_set);
90 FN_OBJ (lbox_fn_pack_start, elm_box_pack_start);
91 FN_OBJ (lbox_fn_pack_end, elm_box_pack_end);
92 FN_2OBJ (lbox_fn_pack_before, elm_box_pack_before);
93 FN_2OBJ (lbox_fn_pack_after, elm_box_pack_after);
95 const struct luaL_Reg lBox_set[] = {
96 {"horizontal", lbox_set_horizontal},
97 {"homogenous", lbox_set_homogenous},
98 {NULL, NULL} // sentinel
101 const struct luaL_Reg lBox_fn[] = {
102 {"pack_start", lbox_fn_pack_start},
103 {"pack_end", lbox_fn_pack_end},
104 {"pack_before", lbox_fn_pack_before},
105 {"pack_after", lbox_fn_pack_after},
106 {NULL, NULL} // sentinel
109 const luaobj_Reg mBox = {
110 lNil,
111 lNil,
112 lBox_set,
113 lBox_fn
116 const luaobj_Reg *cBox[] = {
117 &mClass,
118 &mObject,
119 &mBox,
120 NULL
124 * Elementary Button
127 SET_STRING (lbutton_set_label, elm_button_label_set);
128 SET_OBJ (lbutton_set_icon, elm_button_icon_set);
129 ELM_CB (lbutton_set_clicked, "clicked")
131 const struct luaL_Reg lButton_set[] = {
132 {"label", lbutton_set_label},
133 {"icon", lbutton_set_icon},
134 {"clicked", lbutton_set_clicked},
135 {NULL, NULL} // sentinel
138 const luaobj_Reg mButton = {
139 lNil,
140 lNil,
141 lButton_set,
142 lNil
145 const luaobj_Reg *cButton[] = {
146 &mClass,
147 &mObject,
148 &mButton,
149 NULL
153 * Elementary Scroller
156 SET_OBJ (lscroller_set_content, elm_scroller_content_set);
157 SET_TAB2BOOL (lscroller_set_content_min_limit, elm_scroller_content_min_limit);
159 const struct luaL_Reg lScroller_set[] = {
160 {"content", lscroller_set_content},
161 {"content_min_limit", lscroller_set_content_min_limit},
162 {NULL, NULL} // sentinel
165 const luaobj_Reg mScroller = {
166 lNil,
167 lNil,
168 lScroller_set,
169 lNil
172 const luaobj_Reg *cScroller[] = {
173 &mClass,
174 &mObject,
175 &mScroller,
176 NULL
180 * Elementary Label
183 SET_STRING (llabel_set_label, elm_label_label_set);
185 const struct luaL_Reg lLabel_set[] = {
186 {"label", llabel_set_label},
187 {NULL, NULL} // sentinel
190 const luaobj_Reg mLabel = {
191 lNil,
192 lNil,
193 lLabel_set,
194 lNil
197 const luaobj_Reg *cLabel[] = {
198 &mClass,
199 &mObject,
200 &mLabel,
201 NULL
205 * Elementary Toggle
208 SET_STRING (ltoggle_set_label, elm_toggle_label_set);
209 SET_OBJ (ltoggle_set_icon, elm_toggle_icon_set);
210 SET_TAB2STRING (ltoggle_set_states_labels, elm_toggle_states_labels_set);
211 SET_BOOL (ltoggle_set_state, elm_toggle_state_set);
212 ELM_CB (ltoggle_set_changed, "changed")
214 static int
215 ltoggle_get_state (lua_State *L)
217 luaobj_Object *obj = (luaobj_Object *) lua_touserdata (L, 1);
218 int state;
219 elm_toggle_state_pointer_set (obj->data, &state);
220 lua_pushnumber (L, state);
221 return 1;
224 const struct luaL_Reg lToggle_get[] = {
225 {"state", ltoggle_get_state},
226 {NULL, NULL} // sentinel
229 const struct luaL_Reg lToggle_set[] = {
230 {"label", ltoggle_set_label},
231 {"icon", ltoggle_set_icon},
232 {"states_labels", ltoggle_set_states_labels},
233 {"state", ltoggle_set_state},
234 {"changed", ltoggle_set_changed},
235 {NULL, NULL} // sentinel
238 const luaobj_Reg mToggle = {
239 lNil,
240 lToggle_get,
241 lToggle_set,
242 lNil
245 const luaobj_Reg *cToggle[] = {
246 &mClass,
247 &mObject,
248 &mToggle,
249 NULL
253 * Elementary Frame
256 SET_STRING (lframe_set_label, elm_frame_label_set);
257 SET_OBJ (lframe_set_content, elm_frame_content_set);
259 const struct luaL_Reg lFrame_set[] = {
260 {"label", lframe_set_label},
261 {"content", lframe_set_content},
262 {NULL, NULL} // sentinel
265 const luaobj_Reg mFrame = {
266 lNil,
267 lNil,
268 lFrame_set,
269 lNil
272 const luaobj_Reg *cFrame[] = {
273 &mClass,
274 &mObject,
275 &mFrame,
276 NULL
280 * Elementary Table
283 SET_BOOL (ltable_set_homogenous, elm_table_homogenous_set);
285 static int
286 ltable_fn_pack (lua_State *L)
288 luaobj_Object *obj = (luaobj_Object *) lua_touserdata (L, 1);
289 luaobj_Object *pac = (luaobj_Object *) lua_touserdata (L, 2);
290 elm_table_pack (
291 obj->data, pac->data,
292 luaL_checkint (L, 3), luaL_checkint (L, 4), // x, y
293 luaL_checkint (L, 5), luaL_checkint (L, 6)); // w, h
294 return 0;
297 const struct luaL_Reg lTable_set[] = {
298 {"homogenous", ltable_set_homogenous},
299 {NULL, NULL} // sentinel
302 const struct luaL_Reg lTable_fn[] = {
303 {"pack", ltable_fn_pack},
304 {NULL, NULL} // sentinel
307 const luaobj_Reg mTable = {
308 lNil,
309 lNil,
310 lTable_set,
311 lTable_fn
314 const luaobj_Reg *cTable[] = {
315 &mClass,
316 &mObject,
317 &mTable,
318 NULL
321 GET_STRING (lentry_get_entry, elm_entry_entry_get);
322 GET_STRING (lentry_get_selection, elm_entry_selection_get);
323 SET_BOOL (lentry_set_single_line, elm_entry_single_line_set);
324 SET_BOOL (lentry_set_password, elm_entry_password_set);
325 SET_STRING (lentry_set_entry, elm_entry_entry_set);
326 SET_BOOL (lentry_set_line_wrap, elm_entry_line_wrap_set);
327 SET_BOOL (lentry_set_editable, elm_entry_editable_set);
328 FN_STRING (lentry_fn_entry_insert, elm_entry_entry_insert);
330 ELM_CB (lentry_set_changed, "changed")
331 ELM_CB (lentry_set_selection_start, "selection,start")
332 ELM_CB (lentry_set_selection_changed, "selection,changed")
333 ELM_CB (lentry_set_selection_cleared, "selection,cleared")
334 ELM_CB (lentry_set_selection_paste, "selection,paste")
335 ELM_CB (lentry_set_selection_copy, "selection,copy")
336 ELM_CB (lentry_set_selection_cut, "selection,cut")
337 ELM_CB (lentry_set_cursor_changed, "cursor,changed")
338 ELM_CB (lentry_set_anchor_clicked, "anchor,clicked")
339 ELM_CB (lentry_set_activated, "activated")
341 const struct luaL_Reg lEntry_get[] = {
342 {"entry", lentry_get_entry},
343 {"selection", lentry_get_selection},
344 {NULL, NULL} // sentinel
347 const struct luaL_Reg lEntry_set[] = {
348 {"single_line", lentry_set_single_line},
349 {"password", lentry_set_password},
350 {"entry", lentry_set_entry},
351 {"line_wrap", lentry_set_line_wrap},
352 {"editable", lentry_set_editable},
354 {"changed", lentry_set_changed},
355 {"selection,start", lentry_set_selection_start},
356 {"selection,changed", lentry_set_selection_changed},
357 {"selection,cleard", lentry_set_selection_cleared},
358 {"selection,paste", lentry_set_selection_paste},
359 {"selection,copy", lentry_set_selection_copy},
360 {"selection,cut", lentry_set_selection_cut},
361 {"cursor,changed", lentry_set_cursor_changed},
362 {"anchor,clicked", lentry_set_anchor_clicked},
363 {"activated", lentry_set_activated},
365 {NULL, NULL} // sentinel
368 const struct luaL_Reg lEntry_fn[] = {
369 {"entry_insert", lentry_fn_entry_insert},
370 {NULL, NULL} // sentinel
373 const luaobj_Reg mEntry = {
374 lNil,
375 lEntry_get,
376 lEntry_set,
377 lEntry_fn
380 const luaobj_Reg *cEntry[] = {
381 &mClass,
382 &mObject,
383 &mEntry,
384 NULL
388 * Elementary Bubble
391 SET_STRING (lbubble_set_label, elm_bubble_label_set);
392 SET_STRING (lbubble_set_info, elm_bubble_info_set);
393 SET_OBJ (lbubble_set_content, elm_bubble_content_set);
394 SET_OBJ (lbubble_set_icon, elm_bubble_icon_set);
396 const struct luaL_Reg lBubble_set[] = {
397 {"label", lbubble_set_label},
398 {"content", lbubble_set_content},
399 {"info", lbubble_set_info},
400 {"icon", lbubble_set_icon},
401 {NULL, NULL} // sentinel
404 const luaobj_Reg mBubble = {
405 lNil,
406 lNil,
407 lBubble_set,
408 lNil
411 const luaobj_Reg *cBubble[] = {
412 &mClass,
413 &mObject,
414 &mBubble,
415 NULL
419 * Elementary Hover
422 SET_OBJ (lhover_set_target, elm_hover_target_set);
423 SET_OBJ (lhover_set_parent, elm_hover_parent_set);
424 SET_STRING (lhover_set_style, elm_hover_style_set);
425 ELM_CB (lhover_set_clicked, "clicked")
427 static int
428 lhover_set_content (lua_State *L)
430 luaobj_Object *obj = (luaobj_Object *) lua_touserdata (L, 1);
431 lua_rawgeti (L, 2, 1);
432 lua_rawgeti (L, 2, 2);
433 luaobj_Object *con = (luaobj_Object *) lua_touserdata (L, -1);
434 elm_hover_content_set (
435 obj->data,
436 luaL_checkstring (L, -2),
437 con->data);
438 return 0;
441 const struct luaL_Reg lHover_set[] = {
442 {"target", lhover_set_target},
443 {"parent", lhover_set_parent},
444 {"content", lhover_set_content},
445 {"style", lhover_set_style},
446 {"clicked", lhover_set_clicked},
447 {NULL, NULL} // sentinel
450 const luaobj_Reg mHover = {
451 lNil,
452 lNil,
453 lHover_set,
454 lNil
457 const luaobj_Reg *cHover[] = {
458 &mClass,
459 &mObject,
460 &mHover,
461 NULL
465 * Elementary Layout
468 static int
469 llayout_set_group (lua_State *L)
471 luaobj_Object *obj = (luaobj_Object *) lua_touserdata (L, 1);
472 const char *group = luaL_checkstring (L, 2);
473 lua_getfield (L, LUA_REGISTRYINDEX, "ego_file");
474 const char *file = luaL_checkstring (L, -1);
475 elm_layout_file_set (obj->data, file, group);
476 return 0;
479 static int
480 llayout_set_content (lua_State *L)
482 luaobj_Object *obj = (luaobj_Object *) lua_touserdata (L, 1);
483 lua_rawgeti (L, 2, 1);
484 lua_rawgeti (L, 2, 2);
485 luaobj_Object *con = (luaobj_Object *) lua_touserdata (L, -1);
486 elm_layout_content_set (
487 obj->data,
488 luaL_checkstring (L, -2),
489 con->data);
490 return 0;
493 const struct luaL_Reg lLayout_set[] = {
494 {"group", llayout_set_group},
495 {"content", llayout_set_content},
496 {NULL, NULL} // sentinel
499 const luaobj_Reg mLayout = {
500 lNil,
501 lNil,
502 lLayout_set,
503 lNil
506 const luaobj_Reg *cLayout[] = {
507 &mClass,
508 &mObject,
509 &mLayout,
510 NULL
514 * Elementary Clock
517 SET_TAB3INTEGER (lclock_set_time, elm_clock_time_set);
518 GET_TAB3INTEGER (lclock_get_time, elm_clock_time_get);
519 SET_BOOL (lclock_set_edit, elm_clock_edit_set);
520 SET_BOOL (lclock_set_show_am_pm, elm_clock_show_am_pm_set);
521 SET_BOOL (lclock_set_show_seconds, elm_clock_show_seconds_set);
523 const struct luaL_Reg lClock_set[] = {
524 {"time", lclock_set_time},
525 {"edit", lclock_set_edit},
526 {"show_am_pm", lclock_set_show_am_pm},
527 {"show_seconds", lclock_set_show_seconds},
528 {NULL, NULL} // sentinel
531 const struct luaL_Reg lClock_get[] = {
532 {"time", lclock_get_time},
533 {NULL, NULL} // sentinel
536 const luaobj_Reg mClock = {
537 lNil,
538 lClock_get,
539 lClock_set,
540 lNil
543 const luaobj_Reg *cClock[] = {
544 &mClass,
545 &mObject,
546 &mClock,
547 NULL