move config load to sub init and sub init to after launch request to
[framework/uifw/elementary.git] / src / lib / elm_main.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #ifdef HAVE_FORK
6 #include <dlfcn.h> /* dlopen,dlclose,etc */
7 #endif
8
9 #ifdef HAVE_CRT_EXTERNS_H
10 # include <crt_externs.h>
11 #endif
12
13 #ifdef HAVE_EVIL
14 # include <Evil.h>
15 #endif
16
17 #include <Elementary.h>
18 #include "elm_priv.h"
19
20 #define SEMI_BROKEN_QUICKLAUNCH 1
21
22 static Elm_Version _version = { VMAJ, VMIN, VMIC, VREV };
23 EAPI Elm_Version *elm_version = &_version;
24
25 Eina_Bool
26 _elm_dangerous_call_check(const char *call)
27 {
28    char buf[256];
29    const char *eval;
30
31    snprintf(buf, sizeof(buf), "%i.%i.%i.%i", VMAJ, VMIN, VMIC, VREV);
32    eval = getenv("ELM_NO_FINGER_WAGGLING");
33    if ((eval) && (!strcmp(eval, buf)))
34      return 0;
35    printf("ELEMENTARY FINGER WAGGLE!!!!!!!!!!\n"
36           "\n"
37           "  %s() used.\n"
38           "PLEASE see the API documentation for this function. This call\n"
39           "should almost never be used. Only in very special cases.\n"
40           "\n"
41           "To remove this warning please set the environment variable:\n"
42           "  ELM_NO_FINGER_WAGGLING\n"
43           "To the value of the Elementary version + revision number. e.g.:\n"
44           "  1.2.5.40295\n"
45           "\n"
46           ,
47           call);
48    return 1;
49 }
50
51 static Eina_Bool _elm_signal_exit(void *data,
52                                   int   ev_type,
53                                   void *ev);
54
55 static Eina_Prefix *pfx = NULL;
56 char *_elm_appname = NULL;
57 const char *_elm_data_dir = NULL;
58 const char *_elm_lib_dir = NULL;
59 int _elm_log_dom = -1;
60
61 EAPI int ELM_EVENT_POLICY_CHANGED = 0;
62
63 static int _elm_init_count = 0;
64 static int _elm_sub_init_count = 0;
65 static int _elm_ql_init_count = 0;
66 static int _elm_policies[ELM_POLICY_LAST];
67 static Ecore_Event_Handler *_elm_exit_handler = NULL;
68 static Eina_Bool quicklaunch_on = 0;
69
70 static Eina_Bool
71 _elm_signal_exit(void *data  __UNUSED__,
72                  int ev_type __UNUSED__,
73                  void *ev    __UNUSED__)
74 {
75    elm_exit();
76    return ECORE_CALLBACK_PASS_ON;
77 }
78
79 void
80 _elm_rescale(void)
81 {
82    edje_scale_set(_elm_config->scale);
83    _elm_win_rescale(NULL, EINA_FALSE);
84    _elm_ews_wm_rescale(NULL, EINA_FALSE);
85 }
86
87 static void *app_mainfunc = NULL;
88 static const char *app_domain = NULL;
89 static const char *app_checkfile = NULL;
90
91 static const char *app_compile_bin_dir = NULL;
92 static const char *app_compile_lib_dir = NULL;
93 static const char *app_compile_data_dir = NULL;
94 static const char *app_compile_locale_dir = NULL;
95 static const char *app_prefix_dir = NULL;
96 static const char *app_bin_dir = NULL;
97 static const char *app_lib_dir = NULL;
98 static const char *app_data_dir = NULL;
99 static const char *app_locale_dir = NULL;
100
101 static Eina_Prefix *app_pfx = NULL;
102
103 static void
104 _prefix_check(void)
105 {
106    int argc = 0;
107    char **argv = NULL;
108    const char *dirs[4] = { NULL, NULL, NULL, NULL };
109    char *caps = NULL, *p1, *p2;
110
111    if (app_pfx) return;
112    if (!app_domain) return;
113
114    ecore_app_args_get(&argc, &argv);
115    if (argc < 1) return;
116
117    dirs[0] = app_compile_bin_dir;
118    dirs[1] = app_compile_lib_dir;
119    dirs[2] = app_compile_data_dir;
120    dirs[3] = app_compile_locale_dir;
121
122    if (!dirs[1]) dirs[1] = dirs[0];
123    if (!dirs[0]) dirs[0] = dirs[1];
124    if (!dirs[3]) dirs[3] = dirs[2];
125    if (!dirs[2]) dirs[2] = dirs[3];
126
127    if (app_domain)
128      {
129         caps = alloca(strlen(app_domain) + 1);
130         for (p1 = (char *)app_domain, p2 = caps; *p1; p1++, p2++)
131            *p2 = toupper(*p1);
132         *p2 = 0;
133      }
134    app_pfx = eina_prefix_new(argv[0], app_mainfunc, caps, app_domain,
135                              app_checkfile, dirs[0], dirs[1], dirs[2], dirs[3]);
136 }
137
138 static void
139 _prefix_shutdown(void)
140 {
141    if (app_pfx) eina_prefix_free(app_pfx);
142    if (app_domain) eina_stringshare_del(app_domain);
143    if (app_checkfile) eina_stringshare_del(app_checkfile);
144    if (app_compile_bin_dir) eina_stringshare_del(app_compile_bin_dir);
145    if (app_compile_lib_dir) eina_stringshare_del(app_compile_lib_dir);
146    if (app_compile_data_dir) eina_stringshare_del(app_compile_data_dir);
147    if (app_compile_locale_dir) eina_stringshare_del(app_compile_locale_dir);
148    if (app_prefix_dir) eina_stringshare_del(app_prefix_dir);
149    if (app_bin_dir) eina_stringshare_del(app_bin_dir);
150    if (app_lib_dir) eina_stringshare_del(app_lib_dir);
151    if (app_data_dir) eina_stringshare_del(app_data_dir);
152    if (app_locale_dir) eina_stringshare_del(app_locale_dir);
153    app_mainfunc = NULL;
154    app_domain = NULL;
155    app_checkfile = NULL;
156    app_compile_bin_dir = NULL;
157    app_compile_lib_dir = NULL;
158    app_compile_data_dir = NULL;
159    app_compile_locale_dir = NULL;
160    app_prefix_dir = NULL;
161    app_bin_dir = NULL;
162    app_lib_dir = NULL;
163    app_data_dir = NULL;
164    app_locale_dir = NULL;
165    app_pfx = NULL;
166 }
167
168 EAPI int
169 elm_init(int    argc,
170          char **argv)
171 {
172    _elm_init_count++;
173    if (_elm_init_count > 1) return _elm_init_count;
174    elm_quicklaunch_init(argc, argv);
175    elm_quicklaunch_sub_init(argc, argv);
176    _prefix_shutdown();
177    return _elm_init_count;
178 }
179
180 EAPI int
181 elm_shutdown(void)
182 {
183    _elm_init_count--;
184    if (_elm_init_count > 0) return _elm_init_count;
185    _elm_win_shutdown();
186    while (_elm_win_deferred_free) ecore_main_loop_iterate();
187 // wrningz :(
188 //   _prefix_shutdown();
189    elm_quicklaunch_sub_shutdown();
190    elm_quicklaunch_shutdown();
191    return _elm_init_count;
192 }
193
194 EAPI void
195 elm_app_info_set(void *mainfunc, const char *dom, const char *checkfile)
196 {
197    app_mainfunc = mainfunc;
198    eina_stringshare_replace(&app_domain, dom);
199    eina_stringshare_replace(&app_checkfile, checkfile);
200 }
201
202 EAPI void
203 elm_app_compile_bin_dir_set(const char *dir)
204 {
205    eina_stringshare_replace(&app_compile_bin_dir, dir);
206 }
207
208 EAPI void
209 elm_app_compile_lib_dir_set(const char *dir)
210 {
211    eina_stringshare_replace(&app_compile_lib_dir, dir);
212 }
213
214 EAPI void
215 elm_app_compile_data_dir_set(const char *dir)
216 {
217    eina_stringshare_replace(&app_compile_data_dir, dir);
218 }
219
220 EAPI void
221 elm_app_compile_locale_set(const char *dir)
222 {
223    eina_stringshare_replace(&app_compile_locale_dir, dir);
224 }
225
226 EAPI const char *
227 elm_app_prefix_dir_get(void)
228 {
229    if (app_prefix_dir) return app_prefix_dir;
230    _prefix_check();
231   if (!app_pfx) return "";
232    app_prefix_dir = eina_prefix_get(app_pfx);
233    return app_prefix_dir;
234 }
235
236 EAPI const char *
237 elm_app_bin_dir_get(void)
238 {
239    if (app_bin_dir) return app_bin_dir;
240    _prefix_check();
241    if (!app_pfx) return "";
242    app_bin_dir = eina_prefix_bin_get(app_pfx);
243    return app_bin_dir;
244 }
245
246 EAPI const char *
247 elm_app_lib_dir_get(void)
248 {
249    if (app_lib_dir) return app_lib_dir;
250    _prefix_check();
251    if (!app_pfx) return "";
252    app_lib_dir = eina_prefix_lib_get(app_pfx);
253    return app_lib_dir;
254 }
255
256 EAPI const char *
257 elm_app_data_dir_get(void)
258 {
259    if (app_data_dir) return app_data_dir;
260    _prefix_check();
261    if (!app_pfx) return "";
262    app_data_dir = eina_prefix_data_get(app_pfx);
263    return app_data_dir;
264 }
265
266 EAPI const char *
267 elm_app_locale_dir_get(void)
268 {
269    if (app_locale_dir) return app_locale_dir;
270    _prefix_check();
271    if (!app_pfx) return "";
272    app_locale_dir = eina_prefix_locale_get(app_pfx);
273    return app_locale_dir;
274 }
275
276 #ifdef ELM_EDBUS
277 static int _elm_need_e_dbus = 0;
278 #endif
279 EAPI Eina_Bool
280 elm_need_e_dbus(void)
281 {
282 #ifdef ELM_EDBUS
283    if (_elm_need_e_dbus++) return EINA_TRUE;
284    e_dbus_init();
285    return EINA_TRUE;
286 #else
287    return EINA_FALSE;
288 #endif
289 }
290
291 static void
292 _elm_unneed_e_dbus(void)
293 {
294 #ifdef ELM_EDBUS
295    if (--_elm_need_e_dbus) return;
296
297    _elm_need_e_dbus = 0;
298    e_dbus_shutdown();
299 #endif
300 }
301
302 #ifdef ELM_EFREET
303 static int _elm_need_efreet = 0;
304 #endif
305 EAPI Eina_Bool
306 elm_need_efreet(void)
307 {
308 #ifdef ELM_EFREET
309    if (_elm_need_efreet++) return EINA_TRUE;
310    efreet_init();
311    efreet_mime_init();
312    efreet_trash_init();
313     /*
314      {
315         Eina_List **list;
316
317         list = efreet_icon_extra_list_get();
318         if (list)
319           {
320              e_user_dir_concat_static(buf, "icons");
321              *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf));
322              e_prefix_data_concat_static(buf, "data/icons");
323              *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf));
324           }
325      }
326    */
327    return EINA_TRUE;
328 #else
329    return EINA_FALSE;
330 #endif
331 }
332
333 static void
334 _elm_unneed_efreet(void)
335 {
336 #ifdef ELM_EFREET
337    if (--_elm_need_efreet) return;
338
339    _elm_need_efreet = 0;
340    efreet_trash_shutdown();
341    efreet_mime_shutdown();
342    efreet_shutdown();
343 #endif
344 }
345
346 EAPI void
347 elm_quicklaunch_mode_set(Eina_Bool ql_on)
348 {
349    quicklaunch_on = ql_on;
350 }
351
352 EAPI Eina_Bool
353 elm_quicklaunch_mode_get(void)
354 {
355    return quicklaunch_on;
356 }
357
358 EAPI int
359 elm_quicklaunch_init(int    argc,
360                      char **argv)
361 {
362    _elm_ql_init_count++;
363    if (_elm_ql_init_count > 1) return _elm_ql_init_count;
364    eina_init();
365    _elm_log_dom = eina_log_domain_register("elementary", EINA_COLOR_LIGHTBLUE);
366    if (!_elm_log_dom)
367      {
368         EINA_LOG_ERR("could not register elementary log domain.");
369         _elm_log_dom = EINA_LOG_DOMAIN_GLOBAL;
370      }
371
372    eet_init();
373    ecore_init();
374
375 #ifdef HAVE_ELEMENTARY_EMAP
376    emap_init();
377 #endif
378    ecore_app_args_set(argc, (const char **)argv);
379
380    memset(_elm_policies, 0, sizeof(_elm_policies));
381    if (!ELM_EVENT_POLICY_CHANGED)
382      ELM_EVENT_POLICY_CHANGED = ecore_event_type_new();
383
384    ecore_file_init();
385
386    _elm_exit_handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _elm_signal_exit, NULL);
387
388    if (argv) _elm_appname = strdup(ecore_file_file_get(argv[0]));
389
390    pfx = eina_prefix_new(argv ? argv[0] : NULL, elm_quicklaunch_init,
391                          "ELM", "elementary", "config/profile.cfg",
392                          PACKAGE_LIB_DIR, /* don't have a bin dir currently */
393                          PACKAGE_LIB_DIR,
394                          PACKAGE_DATA_DIR,
395                          LOCALE_DIR);
396    if (pfx)
397      {
398         _elm_data_dir = eina_stringshare_add(eina_prefix_data_get(pfx));
399         _elm_lib_dir = eina_stringshare_add(eina_prefix_lib_get(pfx));
400      }
401    if (!_elm_data_dir) _elm_data_dir = eina_stringshare_add("/");
402    if (!_elm_lib_dir) _elm_lib_dir = eina_stringshare_add("/");
403
404    return _elm_ql_init_count;
405 }
406
407 EAPI int
408 elm_quicklaunch_sub_init(int    argc,
409                          char **argv)
410 {
411    _elm_sub_init_count++;
412    if (_elm_sub_init_count > 1) return _elm_sub_init_count;
413    if (quicklaunch_on)
414      {
415         _elm_config_init();
416 #ifdef SEMI_BROKEN_QUICKLAUNCH
417         return _elm_sub_init_count;
418 #endif
419      }
420    if (!quicklaunch_on)
421      {
422         ecore_app_args_set(argc, (const char **)argv);
423         evas_init();
424         edje_init();
425         _elm_module_init();
426         _elm_config_init();
427         _elm_config_sub_init();
428         ecore_evas_init(); // FIXME: check errors
429 #ifdef HAVE_ELEMENTARY_ECORE_IMF
430         ecore_imf_init();
431 #endif
432 #ifdef HAVE_ELEMENTARY_ECORE_CON
433         ecore_con_init();
434         ecore_con_url_init();
435 #endif
436         _elm_ews_wm_init();
437      }
438    return _elm_sub_init_count;
439 }
440
441 EAPI int
442 elm_quicklaunch_sub_shutdown(void)
443 {
444    _elm_sub_init_count--;
445    if (_elm_sub_init_count > 0) return _elm_sub_init_count;
446    if (quicklaunch_on)
447      {
448 #ifdef SEMI_BROKEN_QUICKLAUNCH
449         return _elm_sub_init_count;
450 #endif
451      }
452    if (!quicklaunch_on)
453      {
454         _elm_win_shutdown();
455         _elm_module_shutdown();
456         _elm_ews_wm_shutdown();
457 #ifdef HAVE_ELEMENTARY_ECORE_CON
458         ecore_con_url_shutdown();
459         ecore_con_shutdown();
460 #endif
461 #ifdef HAVE_ELEMENTARY_ECORE_IMF
462         ecore_imf_shutdown();
463 #endif
464         ecore_evas_shutdown();
465         _elm_config_sub_shutdown();
466 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
467         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
468             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
469             ENGINE_COMPARE(ELM_XRENDER_X11) ||
470             ENGINE_COMPARE(ELM_OPENGL_X11) ||
471             ENGINE_COMPARE(ELM_SOFTWARE_SDL) ||
472             ENGINE_COMPARE(ELM_SOFTWARE_16_SDL) ||
473             ENGINE_COMPARE(ELM_OPENGL_SDL) ||
474             ENGINE_COMPARE(ELM_OPENGL_COCOA) ||
475             ENGINE_COMPARE(ELM_SOFTWARE_WIN32) ||
476             ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE) ||
477             ENGINE_COMPARE(ELM_EWS))
478 #undef ENGINE_COMPARE
479           evas_cserve_disconnect();
480         edje_shutdown();
481         evas_shutdown();
482      }
483    return _elm_sub_init_count;
484 }
485
486 EAPI int
487 elm_quicklaunch_shutdown(void)
488 {
489    _elm_ql_init_count--;
490    if (_elm_ql_init_count > 0) return _elm_ql_init_count;
491    if (pfx) eina_prefix_free(pfx);
492    pfx = NULL;
493    eina_stringshare_del(_elm_data_dir);
494    _elm_data_dir = NULL;
495    eina_stringshare_del(_elm_lib_dir);
496    _elm_lib_dir = NULL;
497
498    free(_elm_appname);
499    _elm_appname = NULL;
500
501    _elm_config_shutdown();
502
503    ecore_event_handler_del(_elm_exit_handler);
504    _elm_exit_handler = NULL;
505
506    _elm_theme_shutdown();
507    _elm_unneed_efreet();
508    _elm_unneed_e_dbus();
509    _elm_unneed_ethumb();
510    _elm_unneed_web();
511    ecore_file_shutdown();
512
513 #ifdef HAVE_ELEMENTARY_EMAP
514    emap_shutdown();
515 #endif
516
517    ecore_shutdown();
518    eet_shutdown();
519
520    if ((_elm_log_dom > -1) && (_elm_log_dom != EINA_LOG_DOMAIN_GLOBAL))
521      {
522         eina_log_domain_unregister(_elm_log_dom);
523         _elm_log_dom = -1;
524      }
525
526    _elm_widget_type_clear();
527
528    eina_shutdown();
529    return _elm_ql_init_count;
530 }
531
532 EAPI void
533 elm_quicklaunch_seed(void)
534 {
535 #ifndef SEMI_BROKEN_QUICKLAUNCH
536    if (quicklaunch_on)
537      {
538         Evas_Object *win, *bg, *bt;
539
540         win = elm_win_add(NULL, "seed", ELM_WIN_BASIC);
541         bg = elm_bg_add(win);
542         elm_win_resize_object_add(win, bg);
543         evas_object_show(bg);
544         bt = elm_button_add(win);
545         elm_button_label_set(bt, " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~-_=+\\|]}[{;:'\",<.>/?");
546         elm_win_resize_object_add(win, bt);
547         ecore_main_loop_iterate();
548         evas_object_del(win);
549         ecore_main_loop_iterate();
550 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
551         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
552             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
553             ENGINE_COMPARE(ELM_XRENDER_X11) ||
554             ENGINE_COMPARE(ELM_OPENGL_X11))
555 #undef ENGINE_COMPARE
556           {
557 # ifdef HAVE_ELEMENTARY_X
558              ecore_x_sync();
559 # endif
560           }
561         ecore_main_loop_iterate();
562      }
563 #endif
564 }
565
566 #ifdef HAVE_FORK
567 static void *qr_handle = NULL;
568 #endif
569 static int (*qr_main)(int    argc,
570                       char **argv) = NULL;
571
572 EAPI Eina_Bool
573 elm_quicklaunch_prepare(int argc __UNUSED__,
574                         char   **argv)
575 {
576 #ifdef HAVE_FORK
577    char *exe = elm_quicklaunch_exe_path_get(argv[0]);
578    if (!exe)
579      {
580         ERR("requested quicklaunch binary '%s' does not exist\n", argv[0]);
581         return EINA_FALSE;
582      }
583    else
584      {
585         char *exe2, *p;
586         char *exename;
587
588         exe2 = malloc(strlen(exe) + 1 + 10);
589         strcpy(exe2, exe);
590         p = strrchr(exe2, '/');
591         if (p) p++;
592         else p = exe2;
593         exename = alloca(strlen(p) + 1);
594         strcpy(exename, p);
595         *p = 0;
596         strcat(p, "../lib/");
597         strcat(p, exename);
598         strcat(p, ".so");
599         if (!access(exe2, R_OK | X_OK))
600           {
601              free(exe);
602              exe = exe2;
603           }
604         else
605           free(exe2);
606      }
607    qr_handle = dlopen(exe, RTLD_NOW | RTLD_GLOBAL);
608    if (!qr_handle)
609      {
610         fprintf(stderr, "dlerr: %s\n", dlerror());
611         WRN("dlopen('%s') failed: %s", exe, dlerror());
612         free(exe);
613         return EINA_FALSE;
614      }
615    INF("dlopen('%s') = %p", exe, qr_handle);
616    qr_main = dlsym(qr_handle, "elm_main");
617    INF("dlsym(%p, 'elm_main') = %p", qr_handle, qr_main);
618    if (!qr_main)
619      {
620         WRN("not quicklauncher capable: no elm_main in '%s'", exe);
621         dlclose(qr_handle);
622         qr_handle = NULL;
623         free(exe);
624         return EINA_FALSE;
625      }
626    free(exe);
627    return EINA_TRUE;
628 #else
629    return EINA_FALSE;
630    (void)argv;
631 #endif
632 }
633
634 #ifdef HAVE_FORK
635 static void
636 save_env(void)
637 {
638    int i, size;
639    extern char **environ;
640    char **oldenv, **p;
641
642    oldenv = environ;
643
644    for (i = 0, size = 0; environ[i]; i++)
645      size += strlen(environ[i]) + 1;
646
647    p = malloc((i + 1) * sizeof(char *));
648    if (!p) return;
649
650    environ = p;
651
652    for (i = 0; oldenv[i]; i++)
653      environ[i] = strdup(oldenv[i]);
654    environ[i] = NULL;
655 }
656
657 #endif
658
659 EAPI Eina_Bool
660 elm_quicklaunch_fork(int    argc,
661                      char **argv,
662                      char  *cwd,
663                      void (postfork_func) (void *data),
664                      void  *postfork_data)
665 {
666 #ifdef HAVE_FORK
667    pid_t child;
668    int ret;
669    int real_argc;
670    char **real_argv;
671
672    // FIXME:
673    // need to accept current environment from elementary_run
674    if (!qr_main)
675      {
676         int i;
677         char **args;
678
679         child = fork();
680         if (child > 0) return EINA_TRUE;
681         else if (child < 0)
682           {
683              perror("could not fork");
684              return EINA_FALSE;
685           }
686         setsid();
687         if (chdir(cwd) != 0)
688           perror("could not chdir");
689         args = alloca((argc + 1) * sizeof(char *));
690         for (i = 0; i < argc; i++) args[i] = argv[i];
691         args[argc] = NULL;
692         WRN("%s not quicklaunch capable, fallback...", argv[0]);
693         execvp(argv[0], args);
694         ERR("failed to execute '%s': %s", argv[0], strerror(errno));
695         exit(-1);
696      }
697    child = fork();
698    if (child > 0) return EINA_TRUE;
699    else if (child < 0)
700      {
701         perror("could not fork");
702         return EINA_FALSE;
703      }
704    if (postfork_func) postfork_func(postfork_data);
705
706    if (quicklaunch_on)
707      {
708 #ifdef SEMI_BROKEN_QUICKLAUNCH
709         ecore_app_args_set(argc, (const char **)argv);
710         evas_init();
711         edje_init();
712         _elm_config_sub_init();
713 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
714         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
715             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
716             ENGINE_COMPARE(ELM_XRENDER_X11) ||
717             ENGINE_COMPARE(ELM_OPENGL_X11))
718 #undef ENGINE_COMPARE
719           {
720 # ifdef HAVE_ELEMENTARY_X
721              ecore_x_init(NULL);
722 # endif
723           }
724         ecore_evas_init(); // FIXME: check errors
725         ecore_imf_init();
726         _elm_module_init();
727 #endif
728      }
729
730    setsid();
731    if (chdir(cwd) != 0)
732      perror("could not chdir");
733    // FIXME: this is very linux specific. it changes argv[0] of the process
734    // so ps etc. report what you'd expect. for other unixes and os's this
735    // may just not work
736    save_env();
737    if (argv)
738      {
739         char *lastarg, *p;
740
741         ecore_app_args_get(&real_argc, &real_argv);
742         lastarg = real_argv[real_argc - 1] + strlen(real_argv[real_argc - 1]);
743         for (p = real_argv[0]; p < lastarg; p++) *p = 0;
744         strcpy(real_argv[0], argv[0]);
745      }
746    ecore_app_args_set(argc, (const char **)argv);
747    ret = qr_main(argc, argv);
748    exit(ret);
749    return EINA_TRUE;
750 #else
751    return EINA_FALSE;
752    (void)argc;
753    (void)argv;
754    (void)cwd;
755    (void)postfork_func;
756    (void)postfork_data;
757 #endif
758 }
759
760 EAPI void
761 elm_quicklaunch_cleanup(void)
762 {
763 #ifdef HAVE_FORK
764    if (qr_handle)
765      {
766         dlclose(qr_handle);
767         qr_handle = NULL;
768         qr_main = NULL;
769      }
770 #endif
771 }
772
773 EAPI int
774 elm_quicklaunch_fallback(int    argc,
775                          char **argv)
776 {
777    int ret;
778    elm_quicklaunch_init(argc, argv);
779    elm_quicklaunch_sub_init(argc, argv);
780    elm_quicklaunch_prepare(argc, argv);
781    ret = qr_main(argc, argv);
782    exit(ret);
783    return ret;
784 }
785
786 EAPI char *
787 elm_quicklaunch_exe_path_get(const char *exe)
788 {
789    static char *path = NULL;
790    static Eina_List *pathlist = NULL;
791    const char *pathitr;
792    const Eina_List *l;
793    char buf[PATH_MAX];
794    if (exe[0] == '/') return strdup(exe);
795    if ((exe[0] == '.') && (exe[1] == '/')) return strdup(exe);
796    if ((exe[0] == '.') && (exe[1] == '.') && (exe[2] == '/')) return strdup(exe);
797    if (!path)
798      {
799         const char *p, *pp;
800         char *buf2;
801         path = getenv("PATH");
802         buf2 = alloca(strlen(path) + 1);
803         p = path;
804         pp = p;
805         for (;; )
806           {
807              if ((*p == ':') || (!*p))
808                {
809                   int len;
810
811                   len = p - pp;
812                   strncpy(buf2, pp, len);
813                   buf2[len] = 0;
814                   pathlist = eina_list_append(pathlist, eina_stringshare_add(buf2));
815                   if (!*p) break;
816                   p++;
817                   pp = p;
818                }
819              else
820                {
821                   if (!*p) break;
822                   p++;
823                }
824           }
825      }
826    EINA_LIST_FOREACH(pathlist, l, pathitr)
827      {
828         snprintf(buf, sizeof(buf), "%s/%s", pathitr, exe);
829         if (!access(buf, R_OK | X_OK)) return strdup(buf);
830      }
831    return NULL;
832 }
833
834 EAPI void
835 elm_run(void)
836 {
837    ecore_main_loop_begin();
838 }
839
840 EAPI void
841 elm_exit(void)
842 {
843    ecore_main_loop_quit();
844 }
845
846 EAPI Eina_Bool
847 elm_policy_set(unsigned int policy,
848                int          value)
849 {
850    Elm_Event_Policy_Changed *ev;
851
852    if (policy >= ELM_POLICY_LAST)
853      return EINA_FALSE;
854
855    if (value == _elm_policies[policy])
856      return EINA_TRUE;
857
858    /* TODO: validade policy? */
859
860    ev = malloc(sizeof(*ev));
861    ev->policy = policy;
862    ev->new_value = value;
863    ev->old_value = _elm_policies[policy];
864
865    _elm_policies[policy] = value;
866
867    ecore_event_add(ELM_EVENT_POLICY_CHANGED, ev, NULL, NULL);
868
869    return EINA_TRUE;
870 }
871
872 EAPI int
873 elm_policy_get(unsigned int policy)
874 {
875    if (policy >= ELM_POLICY_LAST)
876      return 0;
877    return _elm_policies[policy];
878 }
879
880 EAPI void
881 elm_language_set(const char *lang)
882 {
883    setlocale(LC_ALL, lang);
884    _elm_win_translate();
885 }
886
887 EAPI Eina_Bool
888 elm_object_mirrored_get(const Evas_Object *obj)
889 {
890    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
891    return elm_widget_mirrored_get(obj);
892 }
893
894 EAPI void
895 elm_object_mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
896 {
897    EINA_SAFETY_ON_NULL_RETURN(obj);
898    elm_widget_mirrored_set(obj, mirrored);
899 }
900
901 EAPI Eina_Bool
902 elm_object_mirrored_automatic_get(const Evas_Object *obj)
903 {
904    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
905    return elm_widget_mirrored_automatic_get(obj);
906 }
907
908 EAPI void
909 elm_object_mirrored_automatic_set(Evas_Object *obj, Eina_Bool automatic)
910 {
911    EINA_SAFETY_ON_NULL_RETURN(obj);
912    elm_widget_mirrored_automatic_set(obj, automatic);
913 }
914
915 /**
916  * @}
917  */
918
919 EAPI void
920 elm_object_scale_set(Evas_Object *obj,
921                      double       scale)
922 {
923    EINA_SAFETY_ON_NULL_RETURN(obj);
924    elm_widget_scale_set(obj, scale);
925 }
926
927 EAPI double
928 elm_object_scale_get(const Evas_Object *obj)
929 {
930    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0.0);
931    return elm_widget_scale_get(obj);
932 }
933
934 EAPI void
935 elm_object_text_part_set(Evas_Object *obj, const char *part, const char *label)
936 {
937    EINA_SAFETY_ON_NULL_RETURN(obj);
938    elm_widget_text_part_set(obj, part, label);
939 }
940
941 EAPI const char *
942 elm_object_text_part_get(const Evas_Object *obj, const char *part)
943 {
944    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
945    return elm_widget_text_part_get(obj, part);
946 }
947
948 EAPI void
949 elm_object_part_text_set(Evas_Object *obj, const char *part, const char *label)
950 {
951    EINA_SAFETY_ON_NULL_RETURN(obj);
952    elm_widget_text_part_set(obj, part, label);
953 }
954
955 EAPI const char *
956 elm_object_part_text_get(const Evas_Object *obj, const char *part)
957 {
958    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
959    return elm_widget_text_part_get(obj, part);
960 }
961
962 EAPI void
963 elm_object_domain_translatable_text_part_set(Evas_Object *obj, const char *part, const char *domain, const char *text)
964 {
965    EINA_SAFETY_ON_NULL_RETURN(obj);
966    elm_widget_domain_translatable_text_part_set(obj, part, domain, text);
967 }
968
969 EAPI const char *
970 elm_object_translatable_text_part_get(const Evas_Object *obj, const char *part)
971 {
972    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
973    return elm_widget_translatable_text_part_get(obj, part);
974 }
975
976 EAPI void
977 elm_object_part_content_set(Evas_Object *obj, const char *part, Evas_Object *content)
978 {
979    EINA_SAFETY_ON_NULL_RETURN(obj);
980    elm_widget_content_part_set(obj, part, content);
981 }
982
983 EAPI void
984 elm_object_content_part_set(Evas_Object *obj, const char *part, Evas_Object *content)
985 {
986    EINA_SAFETY_ON_NULL_RETURN(obj);
987    elm_widget_content_part_set(obj, part, content);
988 }
989
990
991 EAPI Evas_Object *
992 elm_object_part_content_get(const Evas_Object *obj, const char *part)
993 {
994    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
995    return elm_widget_content_part_get(obj, part);
996 }
997
998 EAPI Evas_Object *
999 elm_object_content_part_get(const Evas_Object *obj, const char *part)
1000 {
1001    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1002    return elm_widget_content_part_get(obj, part);
1003 }
1004
1005 EAPI Evas_Object *
1006 elm_object_part_content_unset(Evas_Object *obj, const char *part)
1007 {
1008    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1009    return elm_widget_content_part_unset(obj, part);
1010 }
1011
1012
1013 EAPI Evas_Object *
1014 elm_object_content_part_unset(Evas_Object *obj, const char *part)
1015 {
1016    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1017    return elm_widget_content_part_unset(obj, part);
1018 }
1019
1020 EAPI double
1021 elm_scale_get(void)
1022 {
1023    return _elm_config->scale;
1024 }
1025
1026 EAPI void
1027 elm_scale_set(double scale)
1028 {
1029    if (_elm_config->scale == scale) return;
1030    _elm_config->scale = scale;
1031    _elm_rescale();
1032 }
1033
1034 EAPI Eina_Bool
1035 elm_password_show_last_get(void)
1036 {
1037    return _elm_config->password_show_last;
1038 }
1039
1040 EAPI void
1041 elm_password_show_last_set(Eina_Bool password_show_last)
1042 {
1043    if (_elm_config->password_show_last == password_show_last) return;
1044    _elm_config->password_show_last = password_show_last;
1045    edje_password_show_last_set(_elm_config->password_show_last);
1046 }
1047
1048 EAPI double
1049 elm_password_show_last_timeout_get(void)
1050 {
1051    return _elm_config->password_show_last_timeout;
1052 }
1053
1054 EAPI void
1055 elm_password_show_last_timeout_set(double password_show_last_timeout)
1056 {
1057    if (_elm_config->password_show_last_timeout == password_show_last_timeout) return;
1058    _elm_config->password_show_last_timeout = password_show_last_timeout;
1059    edje_password_show_last_timeout_set(_elm_config->password_show_last_timeout);
1060 }
1061
1062 EAPI void
1063 elm_object_style_set(Evas_Object *obj,
1064                      const char  *style)
1065 {
1066    EINA_SAFETY_ON_NULL_RETURN(obj);
1067    elm_widget_style_set(obj, style);
1068 }
1069
1070 EAPI const char *
1071 elm_object_style_get(const Evas_Object *obj)
1072 {
1073    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1074    return elm_widget_style_get(obj);
1075 }
1076
1077 EAPI void
1078 elm_object_disabled_set(Evas_Object *obj,
1079                         Eina_Bool    disabled)
1080 {
1081    EINA_SAFETY_ON_NULL_RETURN(obj);
1082    elm_widget_disabled_set(obj, disabled);
1083 }
1084
1085 EAPI Eina_Bool
1086 elm_object_disabled_get(const Evas_Object *obj)
1087 {
1088    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1089    return elm_widget_disabled_get(obj);
1090 }
1091
1092 EAPI Eina_Bool
1093 elm_config_save(void)
1094 {
1095    return _elm_config_save();
1096 }
1097
1098 EAPI void
1099 elm_config_reload(void)
1100 {
1101    _elm_config_reload();
1102 }
1103
1104 EAPI const char *
1105 elm_profile_current_get(void)
1106 {
1107    return _elm_config_current_profile_get();
1108 }
1109
1110 EAPI const char *
1111 elm_profile_dir_get(const char *profile,
1112                     Eina_Bool   is_user)
1113 {
1114    return _elm_config_profile_dir_get(profile, is_user);
1115 }
1116
1117 EAPI void
1118 elm_profile_dir_free(const char *p_dir)
1119 {
1120    free((void *)p_dir);
1121 }
1122
1123 EAPI Eina_List *
1124 elm_profile_list_get(void)
1125 {
1126    return _elm_config_profiles_list();
1127 }
1128
1129 EAPI void
1130 elm_profile_list_free(Eina_List *l)
1131 {
1132    const char *dir;
1133
1134    EINA_LIST_FREE(l, dir)
1135      eina_stringshare_del(dir);
1136 }
1137
1138 EAPI void
1139 elm_profile_set(const char *profile)
1140 {
1141    EINA_SAFETY_ON_NULL_RETURN(profile);
1142    _elm_config_profile_set(profile);
1143 }
1144
1145 EAPI const char *
1146 elm_engine_get(void)
1147 {
1148    return _elm_config->engine;
1149 }
1150
1151 EAPI void
1152 elm_engine_set(const char *engine)
1153 {
1154    EINA_SAFETY_ON_NULL_RETURN(engine);
1155
1156    _elm_config_engine_set(engine);
1157 }
1158
1159 EAPI Eina_List *
1160 elm_text_classes_list_get(void)
1161 {
1162    return _elm_config_text_classes_get();
1163 }
1164
1165 EAPI void
1166 elm_text_classes_list_free(Eina_List *list)
1167 {
1168    _elm_config_text_classes_free(list);
1169 }
1170
1171 EAPI const Eina_List *
1172 elm_font_overlay_list_get(void)
1173 {
1174    return _elm_config_font_overlays_list();
1175 }
1176
1177 EAPI void
1178 elm_font_overlay_set(const char    *text_class,
1179                      const char    *font,
1180                      Evas_Font_Size size)
1181 {
1182    EINA_SAFETY_ON_NULL_RETURN(text_class);
1183    _elm_config_font_overlay_set(text_class, font, size);
1184 }
1185
1186 EAPI void
1187 elm_font_overlay_unset(const char *text_class)
1188 {
1189    EINA_SAFETY_ON_NULL_RETURN(text_class);
1190    _elm_config_font_overlay_remove(text_class);
1191 }
1192
1193 EAPI void
1194 elm_font_overlay_apply(void)
1195 {
1196    _elm_config_font_overlay_apply();
1197 }
1198
1199 EAPI Elm_Font_Properties *
1200 elm_font_properties_get(const char *font)
1201 {
1202    EINA_SAFETY_ON_NULL_RETURN_VAL(font, NULL);
1203    return _elm_font_properties_get(NULL, font);
1204 }
1205
1206 EAPI void
1207 elm_font_properties_free(Elm_Font_Properties *efp)
1208 {
1209    const char *str;
1210
1211    EINA_SAFETY_ON_NULL_RETURN(efp);
1212    EINA_LIST_FREE(efp->styles, str)
1213      if (str) eina_stringshare_del(str);
1214    if (efp->name) eina_stringshare_del(efp->name);
1215    free(efp);
1216 }
1217
1218 EAPI char *
1219 elm_font_fontconfig_name_get(const char *name,
1220                              const char *style)
1221 {
1222    char buf[256];
1223
1224    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
1225    if (!style || style[0] == 0) return (char *) eina_stringshare_add(name);
1226    snprintf(buf, 256, "%s" ELM_FONT_TOKEN_STYLE "%s", name, style);
1227    return (char *) eina_stringshare_add(buf);
1228 }
1229
1230 EAPI void
1231 elm_font_fontconfig_name_free(char *name)
1232 {
1233    eina_stringshare_del(name);
1234 }
1235
1236 EAPI Eina_Hash *
1237 elm_font_available_hash_add(Eina_List *list)
1238 {
1239    Eina_Hash *font_hash;
1240    Eina_List *l;
1241    void *key;
1242
1243    font_hash = NULL;
1244
1245    /* populate with default font families */
1246    //FIXME: Need to check whether fonts are being added multiple times.
1247    font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Regular");
1248    font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold");
1249    font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Oblique");
1250    font_hash = _elm_font_available_hash_add(font_hash,
1251                                             "Sans:style=Bold Oblique");
1252
1253    font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Regular");
1254    font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold");
1255    font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Oblique");
1256    font_hash = _elm_font_available_hash_add(font_hash,
1257                                             "Serif:style=Bold Oblique");
1258
1259    font_hash = _elm_font_available_hash_add(font_hash,
1260                                             "Monospace:style=Regular");
1261    font_hash = _elm_font_available_hash_add(font_hash,
1262                                             "Monospace:style=Bold");
1263    font_hash = _elm_font_available_hash_add(font_hash,
1264                                             "Monospace:style=Oblique");
1265    font_hash = _elm_font_available_hash_add(font_hash,
1266                                             "Monospace:style=Bold Oblique");
1267
1268    EINA_LIST_FOREACH(list, l, key)
1269      if (key) _elm_font_available_hash_add(font_hash, key);
1270
1271    return font_hash;
1272 }
1273
1274 EAPI void
1275 elm_font_available_hash_del(Eina_Hash *hash)
1276 {
1277    _elm_font_available_hash_del(hash);
1278 }
1279
1280 EAPI Evas_Coord
1281 elm_finger_size_get(void)
1282 {
1283    return _elm_config->finger_size;
1284 }
1285
1286 EAPI void
1287 elm_finger_size_set(Evas_Coord size)
1288 {
1289    if (_elm_config->finger_size == size) return;
1290    _elm_config->finger_size = size;
1291    _elm_rescale();
1292 }
1293
1294 EAPI void
1295 elm_coords_finger_size_adjust(int         times_w,
1296                               Evas_Coord *w,
1297                               int         times_h,
1298                               Evas_Coord *h)
1299 {
1300    if ((w) && (*w < (_elm_config->finger_size * times_w)))
1301      *w = _elm_config->finger_size * times_w;
1302    if ((h) && (*h < (_elm_config->finger_size * times_h)))
1303      *h = _elm_config->finger_size * times_h;
1304 }
1305
1306 EAPI void
1307 elm_cache_all_flush(void)
1308 {
1309    const Eina_List *l;
1310    Evas_Object *obj;
1311
1312    edje_file_cache_flush();
1313    edje_collection_cache_flush();
1314    eet_clearcache();
1315    EINA_LIST_FOREACH(_elm_win_list, l, obj)
1316      {
1317         Evas *e = evas_object_evas_get(obj);
1318         evas_image_cache_flush(e);
1319         evas_font_cache_flush(e);
1320         evas_render_dump(e);
1321      }
1322 }
1323
1324 EINA_DEPRECATED EAPI void
1325 elm_all_flush(void)
1326 {
1327    elm_cache_all_flush();
1328 }
1329
1330 EAPI int
1331 elm_cache_flush_interval_get(void)
1332 {
1333    return _elm_config->cache_flush_poll_interval;
1334 }
1335
1336 EAPI void
1337 elm_cache_flush_interval_set(int size)
1338 {
1339    if (_elm_config->cache_flush_poll_interval == size) return;
1340    _elm_config->cache_flush_poll_interval = size;
1341
1342    _elm_recache();
1343 }
1344
1345 EAPI Eina_Bool
1346 elm_cache_flush_enabled_get(void)
1347 {
1348    return _elm_config->cache_flush_enable;
1349 }
1350
1351 EAPI void
1352 elm_cache_flush_enabled_set(Eina_Bool enabled)
1353 {
1354    enabled = !!enabled;
1355    if (_elm_config->cache_flush_enable == enabled) return;
1356    _elm_config->cache_flush_enable = enabled;
1357
1358    _elm_recache();
1359 }
1360
1361 EAPI int
1362 elm_font_cache_get(void)
1363 {
1364    return _elm_config->font_cache;
1365 }
1366
1367 EAPI void
1368 elm_font_cache_set(int size)
1369 {
1370    if (_elm_config->font_cache == size) return;
1371    _elm_config->font_cache = size;
1372
1373    _elm_recache();
1374 }
1375
1376 EAPI int
1377 elm_image_cache_get(void)
1378 {
1379    return _elm_config->image_cache;
1380 }
1381
1382 EAPI void
1383 elm_image_cache_set(int size)
1384 {
1385    if (_elm_config->image_cache == size) return;
1386    _elm_config->image_cache = size;
1387
1388    _elm_recache();
1389 }
1390
1391 EAPI int
1392 elm_edje_file_cache_get(void)
1393 {
1394    return _elm_config->edje_cache;
1395 }
1396
1397 EAPI void
1398 elm_edje_file_cache_set(int size)
1399 {
1400    if (_elm_config->edje_cache == size) return;
1401    _elm_config->edje_cache = size;
1402
1403    _elm_recache();
1404 }
1405
1406 EAPI int
1407 elm_edje_collection_cache_get(void)
1408 {
1409    return _elm_config->edje_collection_cache;
1410 }
1411
1412 EAPI void
1413 elm_edje_collection_cache_set(int size)
1414 {
1415    if (_elm_config->edje_collection_cache == size) return;
1416    _elm_config->edje_collection_cache = size;
1417
1418    _elm_recache();
1419 }
1420
1421 EAPI Eina_Bool
1422 elm_object_focus_get(const Evas_Object *obj)
1423 {
1424    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1425    return elm_widget_focus_get(obj);
1426 }
1427
1428 EAPI void
1429 elm_object_focus_set(Evas_Object *obj,
1430                      Eina_Bool    focus)
1431 {
1432    EINA_SAFETY_ON_NULL_RETURN(obj);
1433
1434    if (focus == elm_widget_focus_get(obj)) return;
1435
1436    if (focus)
1437      elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
1438    else
1439      elm_widget_focused_object_clear(obj);
1440 }
1441
1442 EAPI void
1443 elm_object_focus(Evas_Object *obj)
1444 {
1445    EINA_SAFETY_ON_NULL_RETURN(obj);
1446    elm_object_focus_set(obj, EINA_TRUE);
1447 }
1448
1449 EAPI void
1450 elm_object_unfocus(Evas_Object *obj)
1451 {
1452    EINA_SAFETY_ON_NULL_RETURN(obj);
1453    elm_object_focus_set(obj, EINA_FALSE);
1454 }
1455
1456 EAPI void
1457 elm_object_focus_allow_set(Evas_Object *obj,
1458                            Eina_Bool    enable)
1459 {
1460    EINA_SAFETY_ON_NULL_RETURN(obj);
1461    elm_widget_can_focus_set(obj, enable);
1462 /*FIXME: According to the elm_object_focus_allow_get(), child_can_focus field
1463 of the parent should be updated. Otherwise, the checking of it's child focus allow states should not be in elm_object_focus_allow_get() */
1464 }
1465
1466 EAPI Eina_Bool
1467 elm_object_focus_allow_get(const Evas_Object *obj)
1468 {
1469    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1470    return (elm_widget_can_focus_get(obj)) || (elm_widget_child_can_focus_get(obj));
1471 }
1472
1473 EAPI void
1474 elm_object_focus_custom_chain_set(Evas_Object *obj,
1475                                   Eina_List   *objs)
1476 {
1477    EINA_SAFETY_ON_NULL_RETURN(obj);
1478    elm_widget_focus_custom_chain_set(obj, objs);
1479 }
1480
1481 EAPI void
1482 elm_object_focus_custom_chain_unset(Evas_Object *obj)
1483 {
1484    EINA_SAFETY_ON_NULL_RETURN(obj);
1485    elm_widget_focus_custom_chain_unset(obj);
1486 }
1487
1488 EAPI const Eina_List *
1489 elm_object_focus_custom_chain_get(const Evas_Object *obj)
1490 {
1491    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1492    return elm_widget_focus_custom_chain_get(obj);
1493 }
1494
1495 EAPI void
1496 elm_object_focus_custom_chain_append(Evas_Object *obj,
1497                                      Evas_Object *child,
1498                                      Evas_Object *relative_child)
1499 {
1500    EINA_SAFETY_ON_NULL_RETURN(obj);
1501    elm_widget_focus_custom_chain_append(obj, child, relative_child);
1502 }
1503
1504 EAPI void
1505 elm_object_focus_custom_chain_prepend(Evas_Object *obj,
1506                                       Evas_Object *child,
1507                                       Evas_Object *relative_child)
1508 {
1509    EINA_SAFETY_ON_NULL_RETURN(obj);
1510    elm_widget_focus_custom_chain_prepend(obj, child, relative_child);
1511 }
1512
1513 EAPI void
1514 elm_object_focus_cycle(Evas_Object        *obj,
1515                        Elm_Focus_Direction dir)
1516 {
1517    EINA_SAFETY_ON_NULL_RETURN(obj);
1518    elm_widget_focus_cycle(obj, dir);
1519 }
1520
1521 EAPI void
1522 elm_object_focus_direction_go(Evas_Object *obj,
1523                               int          x,
1524                               int          y)
1525 {
1526    EINA_SAFETY_ON_NULL_RETURN(obj);
1527    elm_widget_focus_direction_go(obj, x, y);
1528 }
1529
1530 EAPI void
1531 elm_object_tree_unfocusable_set(Evas_Object *obj,
1532                                 Eina_Bool    tree_unfocusable)
1533 {
1534    EINA_SAFETY_ON_NULL_RETURN(obj);
1535    elm_widget_tree_unfocusable_set(obj, tree_unfocusable);
1536 }
1537
1538 EAPI Eina_Bool
1539 elm_object_tree_unfocusable_get(const Evas_Object *obj)
1540 {
1541    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1542    return elm_widget_tree_unfocusable_get(obj);
1543 }
1544
1545 EAPI Eina_Bool
1546 elm_focus_highlight_enabled_get(void)
1547 {
1548    return _elm_config->focus_highlight_enable;
1549 }
1550
1551 EAPI void
1552 elm_focus_highlight_enabled_set(Eina_Bool enable)
1553 {
1554    _elm_config->focus_highlight_enable = !!enable;
1555 }
1556
1557 EAPI Eina_Bool
1558 elm_focus_highlight_animate_get(void)
1559 {
1560    return _elm_config->focus_highlight_animate;
1561 }
1562
1563 EAPI void
1564 elm_focus_highlight_animate_set(Eina_Bool animate)
1565 {
1566    _elm_config->focus_highlight_animate = !!animate;
1567 }
1568
1569 EAPI Eina_Bool
1570 elm_scroll_bounce_enabled_get(void)
1571 {
1572    return _elm_config->thumbscroll_bounce_enable;
1573 }
1574
1575 EAPI void
1576 elm_scroll_bounce_enabled_set(Eina_Bool enabled)
1577 {
1578    _elm_config->thumbscroll_bounce_enable = enabled;
1579 }
1580
1581 EAPI double
1582 elm_scroll_bounce_friction_get(void)
1583 {
1584    return _elm_config->thumbscroll_bounce_friction;
1585 }
1586
1587 EAPI void
1588 elm_scroll_bounce_friction_set(double friction)
1589 {
1590    _elm_config->thumbscroll_bounce_friction = friction;
1591 }
1592
1593 EAPI double
1594 elm_scroll_page_scroll_friction_get(void)
1595 {
1596    return _elm_config->page_scroll_friction;
1597 }
1598
1599 EAPI void
1600 elm_scroll_page_scroll_friction_set(double friction)
1601 {
1602    _elm_config->page_scroll_friction = friction;
1603 }
1604
1605 EAPI double
1606 elm_scroll_bring_in_scroll_friction_get(void)
1607 {
1608    return _elm_config->bring_in_scroll_friction;
1609 }
1610
1611 EAPI void
1612 elm_scroll_bring_in_scroll_friction_set(double friction)
1613 {
1614    _elm_config->bring_in_scroll_friction = friction;
1615 }
1616
1617 EAPI double
1618 elm_scroll_zoom_friction_get(void)
1619 {
1620    return _elm_config->zoom_friction;
1621 }
1622
1623 EAPI void
1624 elm_scroll_zoom_friction_set(double friction)
1625 {
1626    _elm_config->zoom_friction = friction;
1627 }
1628
1629 EAPI Eina_Bool
1630 elm_scroll_thumbscroll_enabled_get(void)
1631 {
1632    return _elm_config->thumbscroll_enable;
1633 }
1634
1635 EAPI void
1636 elm_scroll_thumbscroll_enabled_set(Eina_Bool enabled)
1637 {
1638    _elm_config->thumbscroll_enable = enabled;
1639 }
1640
1641 EAPI unsigned int
1642 elm_scroll_thumbscroll_threshold_get(void)
1643 {
1644    return _elm_config->thumbscroll_threshold;
1645 }
1646
1647 EAPI void
1648 elm_scroll_thumbscroll_threshold_set(unsigned int threshold)
1649 {
1650    _elm_config->thumbscroll_threshold = threshold;
1651 }
1652
1653 EAPI double
1654 elm_scroll_thumbscroll_momentum_threshold_get(void)
1655 {
1656    return _elm_config->thumbscroll_momentum_threshold;
1657 }
1658
1659 EAPI void
1660 elm_scroll_thumbscroll_momentum_threshold_set(double threshold)
1661 {
1662    _elm_config->thumbscroll_momentum_threshold = threshold;
1663 }
1664
1665 EAPI double
1666 elm_scroll_thumbscroll_friction_get(void)
1667 {
1668    return _elm_config->thumbscroll_friction;
1669 }
1670
1671 EAPI void
1672 elm_scroll_thumbscroll_friction_set(double friction)
1673 {
1674    _elm_config->thumbscroll_friction = friction;
1675 }
1676
1677 EAPI double
1678 elm_scroll_thumbscroll_border_friction_get(void)
1679 {
1680    return _elm_config->thumbscroll_border_friction;
1681 }
1682
1683 EAPI void
1684 elm_scroll_thumbscroll_border_friction_set(double friction)
1685 {
1686    if (friction < 0.0) friction = 0.0;
1687    if (friction > 1.0) friction = 1.0;
1688    _elm_config->thumbscroll_friction = friction;
1689 }
1690
1691 EAPI double
1692 elm_scroll_thumbscroll_sensitivity_friction_get(void)
1693 {
1694    return _elm_config->thumbscroll_sensitivity_friction;
1695 }
1696
1697 EAPI void
1698 elm_scroll_thumbscroll_sensitivity_friction_set(double friction)
1699 {
1700    if (friction < 0.1) friction = 0.1;
1701    if (friction > 1.0) friction = 1.0;
1702    _elm_config->thumbscroll_friction = friction;
1703 }
1704
1705 EAPI void
1706 elm_scroll_thumbscroll_sensitivity_friction_all_set(double friction)
1707 {
1708    elm_scroll_thumbscroll_sensitivity_friction_set(friction);
1709    elm_config_all_flush();
1710 }
1711
1712 EAPI void
1713 elm_object_scroll_hold_push(Evas_Object *obj)
1714 {
1715    EINA_SAFETY_ON_NULL_RETURN(obj);
1716    elm_widget_scroll_hold_push(obj);
1717 }
1718
1719 EAPI void
1720 elm_object_scroll_hold_pop(Evas_Object *obj)
1721 {
1722    EINA_SAFETY_ON_NULL_RETURN(obj);
1723    elm_widget_scroll_hold_pop(obj);
1724 }
1725
1726 EAPI void
1727 elm_object_scroll_freeze_push(Evas_Object *obj)
1728 {
1729    EINA_SAFETY_ON_NULL_RETURN(obj);
1730    elm_widget_scroll_freeze_push(obj);
1731 }
1732
1733 EAPI void
1734 elm_object_scroll_lock_x_set(Evas_Object *obj,
1735                              Eina_Bool    lock)
1736 {
1737    EINA_SAFETY_ON_NULL_RETURN(obj);
1738    elm_widget_drag_lock_x_set(obj, lock);
1739 }
1740
1741 EAPI void
1742 elm_object_scroll_lock_y_set(Evas_Object *obj,
1743                              Eina_Bool    lock)
1744 {
1745    EINA_SAFETY_ON_NULL_RETURN(obj);
1746    elm_widget_drag_lock_y_set(obj, lock);
1747 }
1748
1749 EAPI Eina_Bool
1750 elm_object_scroll_lock_x_get(const Evas_Object *obj)
1751 {
1752    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1753    return elm_widget_drag_lock_x_get(obj);
1754 }
1755
1756 EAPI Eina_Bool
1757 elm_object_scroll_lock_y_get(const Evas_Object *obj)
1758 {
1759    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1760    return elm_widget_drag_lock_y_get(obj);
1761 }
1762
1763 EAPI void
1764 elm_object_scroll_freeze_pop(Evas_Object *obj)
1765 {
1766    EINA_SAFETY_ON_NULL_RETURN(obj);
1767    elm_widget_scroll_freeze_pop(obj);
1768 }
1769
1770 EAPI Eina_Bool
1771 elm_object_widget_check(const Evas_Object *obj)
1772 {
1773    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1774    return elm_widget_is(obj);
1775 }
1776
1777 EAPI Evas_Object *
1778 elm_object_parent_widget_get(const Evas_Object *obj)
1779 {
1780    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1781    return elm_widget_parent_widget_get(obj);
1782 }
1783
1784 EAPI Evas_Object *
1785 elm_object_top_widget_get(const Evas_Object *obj)
1786 {
1787    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1788    return elm_widget_top_get(obj);
1789 }
1790
1791 EAPI const char *
1792 elm_object_widget_type_get(const Evas_Object *obj)
1793 {
1794    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1795    return elm_widget_type_get(obj);
1796 }
1797
1798 EAPI void
1799 elm_object_signal_emit(Evas_Object *obj,
1800                        const char  *emission,
1801                        const char  *source)
1802 {
1803    EINA_SAFETY_ON_NULL_RETURN(obj);
1804    elm_widget_signal_emit(obj, emission, source);
1805 }
1806
1807 EAPI void
1808 elm_object_signal_callback_add(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func, void *data)
1809 {
1810     EINA_SAFETY_ON_NULL_RETURN(obj);
1811     EINA_SAFETY_ON_NULL_RETURN(func);
1812     elm_widget_signal_callback_add(obj, emission, source, func, data);
1813 }
1814
1815 EAPI void *
1816 elm_object_signal_callback_del(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func)
1817 {
1818     EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1819     EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1820     return elm_widget_signal_callback_del(obj, emission, source, func);
1821 }
1822
1823 EAPI void
1824 elm_object_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1825 {
1826    EINA_SAFETY_ON_NULL_RETURN(obj);
1827    EINA_SAFETY_ON_NULL_RETURN(func);
1828    elm_widget_event_callback_add(obj, func, data);
1829 }
1830
1831 EAPI void *
1832 elm_object_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
1833 {
1834    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1835    EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
1836    return elm_widget_event_callback_del(obj, func, data);
1837 }
1838
1839 EAPI void
1840 elm_object_tree_dump(const Evas_Object *top)
1841 {
1842 #ifdef ELM_DEBUG
1843    elm_widget_tree_dump(top);
1844 #else
1845    return;
1846    (void)top;
1847 #endif
1848 }
1849
1850 EAPI void
1851 elm_object_tree_dot_dump(const Evas_Object *top,
1852                          const char        *file)
1853 {
1854 #ifdef ELM_DEBUG
1855    FILE *f = fopen(file, "wb");
1856    elm_widget_tree_dot_dump(top, f);
1857    fclose(f);
1858 #else
1859    return;
1860    (void)top;
1861    (void)file;
1862 #endif
1863 }
1864
1865 EAPI void
1866 elm_longpress_timeout_set(double longpress_timeout)
1867 {
1868    _elm_config->longpress_timeout = longpress_timeout;
1869 }
1870
1871 EAPI double
1872 elm_longpress_timeout_get(void)
1873 {
1874    return _elm_config->longpress_timeout;
1875 }
1876
1877 EAPI Evas_Object *
1878 elm_object_item_widget_get(const Elm_Object_Item *it)
1879 {
1880    return WIDGET(it);
1881 }
1882
1883 EAPI void
1884 elm_object_item_content_part_set(Elm_Object_Item *it,
1885                                  const char *part,
1886                                  Evas_Object *content)
1887 {
1888    _elm_widget_item_content_part_set((Elm_Widget_Item *) it, part, content);
1889 }
1890
1891 EAPI void
1892 elm_object_item_part_content_set(Elm_Object_Item *it,
1893                                  const char *part,
1894                                  Evas_Object *content)
1895 {
1896    _elm_widget_item_content_part_set((Elm_Widget_Item *) it, part, content);
1897 }
1898
1899 EAPI Evas_Object *
1900 elm_object_item_content_part_get(const Elm_Object_Item *it,
1901                                  const char *part)
1902 {
1903    return _elm_widget_item_content_part_get((Elm_Widget_Item *) it, part);
1904 }
1905
1906 EAPI Evas_Object *
1907 elm_object_item_part_content_get(const Elm_Object_Item *it,
1908                                  const char *part)
1909 {
1910    return _elm_widget_item_content_part_get((Elm_Widget_Item *) it, part);
1911 }
1912
1913 EAPI Evas_Object *
1914 elm_object_item_content_part_unset(Elm_Object_Item *it, const char *part)
1915 {
1916    return _elm_widget_item_content_part_unset((Elm_Widget_Item *) it, part);
1917 }
1918
1919 EAPI Evas_Object *
1920 elm_object_item_part_content_unset(Elm_Object_Item *it, const char *part)
1921 {
1922    return _elm_widget_item_content_part_unset((Elm_Widget_Item *) it, part);
1923 }
1924
1925 EAPI void
1926 elm_object_item_text_part_set(Elm_Object_Item *it,
1927                               const char *part,
1928                               const char *label)
1929 {
1930    _elm_widget_item_text_part_set((Elm_Widget_Item *) it, part, label);
1931 }
1932
1933 EAPI void
1934 elm_object_item_part_text_set(Elm_Object_Item *it,
1935                               const char *part,
1936                               const char *label)
1937 {
1938    _elm_widget_item_text_part_set((Elm_Widget_Item *) it, part, label);
1939 }
1940
1941 EAPI const char *
1942 elm_object_item_text_part_get(const Elm_Object_Item *it, const char *part)
1943 {
1944    return _elm_widget_item_text_part_get((Elm_Widget_Item *) it, part);
1945 }
1946
1947 EAPI const char *
1948 elm_object_item_part_text_get(const Elm_Object_Item *it, const char *part)
1949 {
1950    return _elm_widget_item_text_part_get((Elm_Widget_Item *) it, part);
1951 }
1952
1953 EAPI void
1954 elm_object_access_info_set(Evas_Object *obj, const char *txt)
1955 {
1956    elm_widget_access_info_set(obj, txt);
1957 }
1958
1959 EAPI Evas_Object *
1960 elm_object_name_find(const Evas_Object *obj, const char *name, int recurse)
1961 {
1962    return elm_widget_name_find(obj, name, recurse);
1963 }
1964
1965 EAPI void
1966 elm_object_item_access_info_set(Elm_Object_Item *it, const char *txt)
1967 {
1968    _elm_widget_item_access_info_set((Elm_Widget_Item *) it, txt);
1969 }
1970
1971 EAPI void *
1972 elm_object_item_data_get(const Elm_Object_Item *it)
1973 {
1974    return elm_widget_item_data_get(it);
1975 }
1976
1977 EAPI void
1978 elm_object_item_data_set(Elm_Object_Item *it, void *data)
1979 {
1980    elm_widget_item_data_set(it, data);
1981 }
1982
1983 EAPI void
1984 elm_object_item_signal_emit(Elm_Object_Item *it, const char *emission, const char *source)
1985 {
1986    _elm_widget_item_signal_emit((Elm_Widget_Item *) it, emission, source);
1987 }
1988
1989 EAPI void elm_object_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1990 {
1991    _elm_widget_item_disabled_set((Elm_Widget_Item *) it, disabled);
1992 }
1993
1994 EAPI Eina_Bool elm_object_item_disabled_get(const Elm_Object_Item *it)
1995 {
1996    return _elm_widget_item_disabled_get((Elm_Widget_Item *) it);
1997 }
1998
1999 EAPI void elm_object_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb del_cb)
2000 {
2001    _elm_widget_item_del_cb_set((Elm_Widget_Item *) it, del_cb);
2002 }
2003
2004 EAPI void elm_object_item_del(Elm_Object_Item *it)
2005 {
2006    _elm_widget_item_del((Elm_Widget_Item *) it);
2007 }
2008
2009 EAPI void
2010 elm_object_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
2011 {
2012    elm_widget_item_tooltip_text_set(it, text);
2013 }
2014
2015 EAPI void
2016 elm_object_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
2017 {
2018    elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
2019 }
2020
2021 EAPI void
2022 elm_object_item_tooltip_unset(Elm_Object_Item *it)
2023 {
2024    elm_widget_item_tooltip_unset(it);
2025 }
2026
2027 EAPI Eina_Bool
2028 elm_object_item_tooltip_window_mode_set(Elm_Object_Item *it, Eina_Bool disable)
2029 {
2030    return elm_widget_item_tooltip_window_mode_set(it, disable);
2031 }
2032
2033 EAPI Eina_Bool
2034 elm_object_item_tooltip_window_mode_get(const Elm_Object_Item *it)
2035 {
2036    return elm_widget_item_tooltip_window_mode_get(it);
2037 }
2038
2039 EAPI void
2040 elm_object_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
2041 {
2042    elm_widget_item_tooltip_style_set(it, style);
2043 }
2044
2045 EAPI const char *
2046 elm_object_item_tooltip_style_get(const Elm_Object_Item *it)
2047 {
2048    return elm_widget_item_tooltip_style_get(it);
2049 }
2050
2051 EINA_DEPRECATED EAPI Evas_Object *
2052 elm_object_item_object_get(const Elm_Object_Item *it)
2053 {
2054    return elm_object_item_widget_get(it);
2055 }
2056
2057 EAPI void
2058 elm_object_item_cursor_set(Elm_Object_Item *it, const char *cursor)
2059 {
2060    elm_widget_item_cursor_set(it, cursor);
2061 }
2062
2063 EAPI const char *
2064 elm_object_item_cursor_get(const Elm_Object_Item *it)
2065 {
2066    return elm_widget_item_cursor_get(it);
2067 }
2068
2069 EAPI void
2070 elm_object_item_cursor_unset(Elm_Object_Item *it)
2071 {
2072    elm_widget_item_cursor_unset(it);
2073 }
2074
2075 EAPI void
2076 elm_object_item_cursor_style_set(Elm_Object_Item *it, const char *style)
2077 {
2078    elm_widget_item_cursor_style_set(it, style);
2079 }
2080
2081 EAPI const char *
2082 elm_object_item_cursor_style_get(const Elm_Object_Item *it)
2083 {
2084    return elm_widget_item_cursor_style_get(it);
2085 }
2086
2087 EAPI void
2088 elm_object_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
2089 {
2090    elm_widget_item_cursor_engine_only_set(it, engine_only);
2091 }
2092
2093 EAPI Eina_Bool
2094 elm_object_item_cursor_engine_only_get(const Elm_Object_Item *it)
2095 {
2096    return elm_widget_item_cursor_engine_only_get(it);
2097 }