Merge "maximum value of year is made unset in the datefield_Add API. mousedownwq...
[framework/uifw/elementary.git] / src / lib / elm_main.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4
5 #include <dlfcn.h> /* dlopen,dlclose,etc */
6
7 #ifdef HAVE_CRT_EXTERNS_H
8 # include <crt_externs.h>
9 #endif
10
11 #ifdef HAVE_EVIL
12 # include <Evil.h>
13 #endif
14
15 #include <Elementary.h>
16 #include "elm_priv.h"
17
18 #define SEMI_BROKEN_QUICKLAUNCH 1
19
20 static Elm_Version _version = { VMAJ, VMIN, VMIC, VREV };
21 EAPI Elm_Version *elm_version = &_version;
22 /**
23  * @defgroup Main Main
24  * @ingroup Elementary
25  *
26  * This group includes functions of elm_main.c
27  */
28
29
30 Eina_Bool
31 _elm_dangerous_call_check(const char *call)
32 {
33    char buf[256];
34    const char *eval;
35
36    snprintf(buf, sizeof(buf), "%i.%i.%i.%i", VMAJ, VMIN, VMIC, VREV);
37    eval = getenv("ELM_NO_FINGER_WAGGLING");
38    if ((eval) && (!strcmp(eval, buf)))
39      return 0;
40    printf("ELEMENTARY FINGER WAGGLE!!!!!!!!!!\n"
41           "\n"
42           "  %s() used.\n"
43           "PLEASE see the API documentation for this function. This call\n"
44           "should almost never be used. Only in very special cases.\n"
45           "\n"
46           "To remove this warning please set the environment variable:\n"
47           "  ELM_NO_FINGER_WAGGLING\n"
48           "To the value of the Elementary version + revision number. e.g.:\n"
49           "  1.2.5.40295\n"
50           "\n"
51           ,
52           call);
53    return 1;
54 }
55
56 /**
57  * @defgroup Start Getting Started
58  * @ingroup Main
59  *
60  * To write an Elementary app, you can get started with the following:
61  *
62  * @code
63  * #include <Elementary.h>
64  * #ifndef ELM_LIB_QUICKLAUNCH
65  * EAPI int
66  * elm_main(int argc, char **argv)
67  * {
68  *    // create window(s) here and do any application init
69  *    elm_run(); // run main loop
70  *    elm_shutdown(); // after mainloop finishes running, shutdown
71  *    return 0; // exit 0 for exit code
72  * }
73  * #endif
74  * ELM_MAIN()
75  * @endcode
76  *
77  * To take full advantage of the quicklaunch architecture for launching
78  * processes as quickly as possible (saving time at startup time like
79  * connecting to X11, loading and linking shared libraries) you may want to
80  * use the following configure.in/configure.ac and Makefile.am and autogen.sh
81  * script to generate your files. It is assumed your application uses the
82  * main.c file for its code.
83  *
84  * configure.in/configure.ac:
85  *
86 @verbatim
87 AC_INIT(myapp, 0.0.0, myname@mydomain.com)
88 AC_PREREQ(2.52)
89 AC_CONFIG_SRCDIR(configure.in)
90
91 AM_INIT_AUTOMAKE(1.6 dist-bzip2)
92 AM_CONFIG_HEADER(config.h)
93
94 AC_C_BIGENDIAN
95 AC_ISC_POSIX
96 AC_PROG_CC
97 AM_PROG_CC_STDC
98 AC_HEADER_STDC
99 AC_C_CONST
100
101 AC_LIBTOOL_WIN32_DLL
102 define([AC_LIBTOOL_LANG_CXX_CONFIG], [:])dnl
103 define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl
104 AC_PROG_LIBTOOL
105
106 PKG_CHECK_MODULES([ELEMENTARY], elementary)
107
108 AC_OUTPUT(Makefile)
109 @endverbatim
110  *
111  * Makefile.am:
112  *
113 @verbatim
114 AUTOMAKE_OPTIONS     = 1.4 foreign
115 MAINTAINERCLEANFILES = Makefile.in
116
117 INCLUDES = -I$(top_srcdir) @ELEMENTARY_CFLAGS@
118
119 bin_PROGRAMS      = myapp
120 myapp_LTLIBRARIES = myapp.la
121
122 myappdir = $(libdir)
123
124 myapp_la_SOURCES = main.c
125 myapp_la_LIBADD = @ELEMENTARY_LIBS@
126 myapp_la_CFLAGS =
127 myapp_la_LDFLAGS = -module -avoid-version -no-undefined
128
129 myapp_SOURCES = main.c
130 myapp_LDADD = @ELEMENTARY_LIBS@
131 myapp_CFLAGS = -DELM_LIB_QUICKLAUNCH=1
132 @endverbatim
133  *
134  * autogen.sh:
135  *
136 @verbatim
137 #!/bin/sh
138 rm -rf autom4te.cache
139 rm -f aclocal.m4 ltmain.sh
140 rm -rf m4
141 mkdir m4
142
143 touch README
144 echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS -I m4 || exit 1
145 echo "Running autoheader..." ; autoheader || exit 1
146 echo "Running autoconf..." ; autoconf || exit 1
147 echo "Running libtoolize..." ; (libtoolize --copy --automake || glibtoolize --automake) || exit 1
148 echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
149
150 if [ -z "$NOCONFIGURE" ]; then
151   ./configure "$@"
152 fi
153 @endverbatim
154  *
155  * To gnerate all the things needed to bootstrap just run:
156  *
157 @verbatim
158 ./autogen.sh
159 @endverbatim
160  *
161  * This will generate Makefile.in's, the confgure script and everything else.
162  * After this it works like all normal autotools projects:
163 @verbatim
164 ./configure
165 make
166 sudo make install
167 @endverbatim
168  *
169  * Note sudo was assumed to get root permissions, as this would install in
170  * /usr/local which is system-owned. Ue any way you like to gain root, or
171  * specify a different prefix with configure:
172  *
173 @verbatim
174 ./confiugre --prefix=$HOME/mysoftware
175 @endverbatim
176  *
177  * Also remember that autotools buys you some useful commands like:
178 @verbatim
179 make uninstall
180 @endverbatim
181  *
182  * This uninstalls the software after it was installed with "make install".
183  * It is very useful to clear up what you built if you wish to clean the
184  * system.
185  *
186 @verbatim
187 make distcheck
188 @endverbatim
189  *
190  * This firstly checks if your build tree is "clean" and ready for
191  * distribution. It also builds a tarball (myapp-0.0.0.tar.gz) that is
192  * ready to upload and distribute to the world, that contains the generated
193  * Makefile.in's and configure script. The users do not need to run
194  * autogen.sh - just configure and on. They don't need autotools installed.
195  * This tarball also builds cleanly, has all the sources it needs to build
196  * included (that is sources for your application, not libraries it depends
197  * on like Elementary). It builds cleanly in a buildroot and does not
198  * contain any files that are temporarily generated like binaries and other
199  * build-gnerated files, so the tarball is clean, and no need to worry
200  * about cleaning up your tree before packaging.
201  *
202 @verbatim
203 make clean
204 @endverbatim
205  *
206  * This cleans up all build files (binaries, objects etc.) from the tree.
207  *
208 @verbatim
209 make distclean
210 @endverbatim
211  *
212  * This cleans out all files from the build and from configure's output too.
213  *
214 @verbatim
215 make maintainer-clean
216 @endverbatim
217  *
218  * This deletes all the files autogen.sh will produce so the tree is clean
219  * to be put into a revision-control system (like CVS, SVN or GIT for example).
220  *
221  * The above will build a library - libmyapp.so and install in the target
222  * library directory (default is /usr/local/lib). You will also get a
223  * myapp.a and myapp.la - these are useless and can be deleted. Libtool likes
224  * to generate these all the time. You will also get a binary in the target
225  * binary directory (default is /usr/local/bin). This is a "debug binary".
226  * This will run and dlopen() the myapp.so and then jump to it's elm_main
227  * function. This allows for easy debugging with GDB and Valgrind. When you
228  * are ready to go to production do the following:
229  *
230  * 1. delete the myapp binary. i.e. rm /usr/local/bin/myapp
231  *
232  * 2. symlink the myapp binary to elementary_run (supplied by elementary).
233  * i.e. ln -s elmentary_run /usr/local/bin/myapp
234  *
235  * 3. run elementary_quicklaunch as part of your graphical login session and
236  * keep it running.
237  *
238  * This will man elementary_quicklaunch does pre-initialization before the
239  * application needs to be run, saving the effort at the time the application
240  * is needed, thus speeding up the time it takes to appear.
241  *
242  * If you don't want to use the quicklaunch infrastructure (which is
243  * optional), you can execute the old fashioned way by just running the
244  * myapp binary loader than will load the myapp.so for you, or you can
245  * remove the split-file binary and put it into one binary as things always
246  * have been with the following configure.in/configure.ac and Makfile.am
247  * files:
248  *
249  * configure.in/configure.ac:
250  *
251 @verbatim
252 AC_INIT(myapp, 0.0.0, myname@mydomain.com)
253 AC_PREREQ(2.52)
254 AC_CONFIG_SRCDIR(configure.in)
255
256 AM_INIT_AUTOMAKE(1.6 dist-bzip2)
257 AM_CONFIG_HEADER(config.h)
258
259 AC_C_BIGENDIAN
260 AC_ISC_POSIX
261 AC_PROG_CC
262 AM_PROG_CC_STDC
263 AC_HEADER_STDC
264 AC_C_CONST
265
266 PKG_CHECK_MODULES([ELEMENTARY], elementary)
267
268 AC_OUTPUT(Makefile)
269 @endverbatim
270  *
271  * Makefile.am:
272  *
273 @verbatim
274 AUTOMAKE_OPTIONS     = 1.4 foreign
275 MAINTAINERCLEANFILES = Makefile.in
276
277 INCLUDES = -I$(top_srcdir) @ELEMENTARY_CFLAGS@
278
279 bin_PROGRAMS      = myapp
280
281 myapp_SOURCES = main.c
282 myapp_LDADD = @ELEMENTARY_LIBS@
283 myapp_CFLAGS =
284 @endverbatim
285  *
286  * Notice that they are the same as before, just with libtool and library
287  * building sections removed. Both ways work for building elementary
288  * applications. It is up to you to decide what is best for you. If you just
289  * follow the template above, you can do it both ways and can decide at build
290  * time. The more advanced of you may suggest making it a configure option.
291  * That is perfectly valid, but has been left out here for simplicity, as our
292  * aim to have an Elementary (and EFL) tutorial, not an autoconf & automake
293  * document.
294  *
295  */
296
297 static Eina_Bool _elm_signal_exit(void *data,
298                                   int   ev_type,
299                                   void *ev);
300
301 char *_elm_appname = NULL;
302 const char *_elm_data_dir = NULL;
303 const char *_elm_lib_dir = NULL;
304 int _elm_log_dom = -1;
305
306 EAPI int ELM_EVENT_POLICY_CHANGED = 0;
307
308 static int _elm_init_count = 0;
309 static int _elm_sub_init_count = 0;
310 static int _elm_ql_init_count = 0;
311 static int _elm_policies[ELM_POLICY_LAST];
312 static Ecore_Event_Handler *_elm_exit_handler = NULL;
313 static Eina_Bool quicklaunch_on = 0;
314
315 static Eina_Bool
316 _elm_signal_exit(void *data  __UNUSED__,
317                  int ev_type __UNUSED__,
318                  void *ev    __UNUSED__)
319 {
320    elm_exit();
321    return ECORE_CALLBACK_PASS_ON;
322 }
323
324 void
325 _elm_rescale(void)
326 {
327    edje_scale_set(_elm_config->scale);
328    _elm_win_rescale(NULL, EINA_FALSE);
329 }
330
331 /**
332  * @defgroup General General
333  * @ingroup Main
334  */
335
336 /**
337  * Inititalise Elementary
338  *
339  * @return The init counter value.
340  *
341  * This call is exported only for use by the ELM_MAIN() macro. There is no
342  * need to use this if you use this macro (which is highly advisable).
343  * @ingroup General
344  */
345 EAPI int
346 elm_init(int    argc,
347          char **argv)
348 {
349    _elm_init_count++;
350    if (_elm_init_count > 1) return _elm_init_count;
351    elm_quicklaunch_init(argc, argv);
352    elm_quicklaunch_sub_init(argc, argv);
353    return _elm_init_count;
354 }
355
356 /**
357  * Shut down Elementary
358  *
359  * @return The init counter value.
360  *
361  * This should be called at the end of your application just before it ceases
362  * to do any more processing. This will clean up any permanent resources your
363  * application may have allocated via Elementary that would otherwise persist
364  * on an exit without this call.
365  * @ingroup General
366  */
367 EAPI int
368 elm_shutdown(void)
369 {
370    _elm_init_count--;
371    if (_elm_init_count > 0) return _elm_init_count;
372    elm_quicklaunch_sub_shutdown();
373    elm_quicklaunch_shutdown();
374    return _elm_init_count;
375 }
376
377 #ifdef ELM_EDBUS
378 static int _elm_need_e_dbus = 0;
379 #endif
380 EAPI Eina_Bool
381 elm_need_e_dbus(void)
382 {
383 #ifdef ELM_EDBUS
384    if (_elm_need_e_dbus++) return EINA_TRUE;
385    e_dbus_init();
386    e_hal_init();
387    return EINA_TRUE;
388 #else
389    return EINA_FALSE;
390 #endif
391 }
392
393 static void
394 _elm_unneed_e_dbus(void)
395 {
396 #ifdef ELM_EDBUS
397    if (--_elm_need_e_dbus) return;
398
399    _elm_need_e_dbus = 0;
400    e_hal_shutdown();
401    e_dbus_shutdown();
402 #endif
403 }
404
405 #ifdef ELM_EFREET
406 static int _elm_need_efreet = 0;
407 #endif
408 EAPI Eina_Bool
409 elm_need_efreet(void)
410 {
411 #ifdef ELM_EFREET
412    if (_elm_need_efreet++) return EINA_TRUE;
413    efreet_init();
414    efreet_mime_init();
415    efreet_trash_init();
416     /*
417      {
418         Eina_List **list;
419
420         list = efreet_icon_extra_list_get();
421         if (list)
422           {
423              e_user_dir_concat_static(buf, "icons");
424              *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf));
425              e_prefix_data_concat_static(buf, "data/icons");
426              *list = eina_list_prepend(*list, (void *)eina_stringshare_add(buf));
427           }
428      }
429    */
430    return EINA_TRUE;
431 #else
432    return EINA_FALSE;
433 #endif
434 }
435
436 static void
437 _elm_unneed_efreet(void)
438 {
439 #ifdef ELM_EFREET
440    if (--_elm_need_efreet) return;
441
442    _elm_need_efreet = 0;
443    efreet_trash_shutdown();
444    efreet_mime_shutdown();
445    efreet_shutdown();
446 #endif
447 }
448
449 EAPI void
450 elm_quicklaunch_mode_set(Eina_Bool ql_on)
451 {
452    quicklaunch_on = ql_on;
453 }
454
455 EAPI Eina_Bool
456 elm_quicklaunch_mode_get(void)
457 {
458    return quicklaunch_on;
459 }
460
461 EAPI int
462 elm_quicklaunch_init(int    argc,
463                      char **argv)
464 {
465    char buf[PATH_MAX], *s;
466
467    _elm_ql_init_count++;
468    if (_elm_ql_init_count > 1) return _elm_ql_init_count;
469    eina_init();
470    _elm_log_dom = eina_log_domain_register("elementary", EINA_COLOR_LIGHTBLUE);
471    if (!_elm_log_dom)
472      {
473         EINA_LOG_ERR("could not register elementary log domain.");
474         _elm_log_dom = EINA_LOG_DOMAIN_GLOBAL;
475      }
476
477    eet_init();
478    ecore_init();
479    ecore_app_args_set(argc, (const char **)argv);
480
481    memset(_elm_policies, 0, sizeof(_elm_policies));
482    if (!ELM_EVENT_POLICY_CHANGED)
483      ELM_EVENT_POLICY_CHANGED = ecore_event_type_new();
484
485    ecore_file_init();
486
487    _elm_exit_handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _elm_signal_exit, NULL);
488
489    if (argv) _elm_appname = strdup(ecore_file_file_get(argv[0]));
490
491    if (!_elm_data_dir)
492      {
493         s = getenv("ELM_DATA_DIR");
494         _elm_data_dir = eina_stringshare_add(s);
495      }
496    if (!_elm_data_dir)
497      {
498         s = getenv("ELM_PREFIX");
499         if (s)
500           {
501              snprintf(buf, sizeof(buf), "%s/share/elementary", s);
502              _elm_data_dir = eina_stringshare_add(buf);
503           }
504      }
505    if (!_elm_lib_dir)
506      {
507         s = getenv("ELM_LIB_DIR");
508         _elm_lib_dir = eina_stringshare_add(s);
509      }
510    if (!_elm_lib_dir)
511      {
512         s = getenv("ELM_PREFIX");
513         if (s)
514           {
515              snprintf(buf, sizeof(buf), "%s/lib", s);
516              _elm_lib_dir = eina_stringshare_add(buf);
517           }
518      }
519 #ifdef HAVE_DLADDR
520    if ((!_elm_data_dir) || (!_elm_lib_dir))
521      {
522         Dl_info elementary_dl;
523         // libelementary.so/../../share/elementary/
524         if (dladdr(elm_init, &elementary_dl))
525           {
526              char *dir, *dir2;
527
528              dir = ecore_file_dir_get(elementary_dl.dli_fname);
529              if (dir)
530                {
531                   if (!_elm_lib_dir)
532                     {
533                        if (ecore_file_is_dir(dir))
534                          _elm_lib_dir = eina_stringshare_add(dir);
535                     }
536                   if (!_elm_data_dir)
537                     {
538                        dir2 = ecore_file_dir_get(dir);
539                        if (dir2)
540                          {
541                             snprintf(buf, sizeof(buf), "%s/share/elementary", dir2);
542                             if (ecore_file_is_dir(buf))
543                               _elm_data_dir = eina_stringshare_add(buf);
544                             free(dir2);
545                          }
546                     }
547                   free(dir);
548                }
549           }
550      }
551 #endif
552    if (!_elm_data_dir)
553      _elm_data_dir = eina_stringshare_add(PACKAGE_DATA_DIR);
554    if (!_elm_data_dir)
555      _elm_data_dir = eina_stringshare_add("/");
556    if (!_elm_lib_dir)
557      _elm_lib_dir = eina_stringshare_add(PACKAGE_LIB_DIR);
558    if (!_elm_lib_dir)
559      _elm_lib_dir = eina_stringshare_add("/");
560
561    _elm_config_init();
562    return _elm_ql_init_count;
563 }
564
565 EAPI int
566 elm_quicklaunch_sub_init(int    argc,
567                          char **argv)
568 {
569    _elm_sub_init_count++;
570    if (_elm_sub_init_count > 1) return _elm_sub_init_count;
571    if (quicklaunch_on)
572      {
573 #ifdef SEMI_BROKEN_QUICKLAUNCH
574         return _elm_sub_init_count;
575 #endif
576      }
577    if (!quicklaunch_on)
578      {
579         ecore_app_args_set(argc, (const char **)argv);
580         evas_init();
581         edje_init();
582         _elm_module_init();
583         _elm_config_sub_init();
584 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
585         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
586             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
587             ENGINE_COMPARE(ELM_XRENDER_X11) ||
588             ENGINE_COMPARE(ELM_OPENGL_X11))
589 #undef ENGINE_COMPARE
590           {
591 #ifdef HAVE_ELEMENTARY_X
592              ecore_x_init(NULL);
593 #endif
594           }
595         ecore_evas_init(); // FIXME: check errors
596         ecore_imf_init();
597      }
598    return _elm_sub_init_count;
599 }
600
601 EAPI int
602 elm_quicklaunch_sub_shutdown(void)
603 {
604    _elm_sub_init_count--;
605    if (_elm_sub_init_count > 0) return _elm_sub_init_count;
606    if (quicklaunch_on)
607      {
608 #ifdef SEMI_BROKEN_QUICKLAUNCH
609         return _elm_sub_init_count;
610 #endif
611      }
612    if (!quicklaunch_on)
613      {
614         _elm_win_shutdown();
615         _elm_module_shutdown();
616         ecore_imf_shutdown();
617         ecore_evas_shutdown();
618 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
619         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
620             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
621             ENGINE_COMPARE(ELM_XRENDER_X11) ||
622             ENGINE_COMPARE(ELM_OPENGL_X11))
623 #undef ENGINE_COMPARE
624           {
625 #ifdef HAVE_ELEMENTARY_X
626              ecore_x_disconnect();
627 #endif
628           }
629 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
630         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
631             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
632             ENGINE_COMPARE(ELM_XRENDER_X11) ||
633             ENGINE_COMPARE(ELM_OPENGL_X11) ||
634             ENGINE_COMPARE(ELM_SOFTWARE_SDL) ||
635             ENGINE_COMPARE(ELM_SOFTWARE_16_SDL) ||
636             ENGINE_COMPARE(ELM_OPENGL_SDL) ||
637             ENGINE_COMPARE(ELM_SOFTWARE_WIN32) ||
638             ENGINE_COMPARE(ELM_SOFTWARE_16_WINCE))
639 #undef ENGINE_COMPARE
640           evas_cserve_disconnect();
641         edje_shutdown();
642         evas_shutdown();
643      }
644    return _elm_sub_init_count;
645 }
646
647 EAPI int
648 elm_quicklaunch_shutdown(void)
649 {
650    _elm_ql_init_count--;
651    if (_elm_ql_init_count > 0) return _elm_ql_init_count;
652    eina_stringshare_del(_elm_data_dir);
653    _elm_data_dir = NULL;
654    eina_stringshare_del(_elm_lib_dir);
655    _elm_lib_dir = NULL;
656
657    free(_elm_appname);
658    _elm_appname = NULL;
659
660    _elm_config_shutdown();
661
662    ecore_event_handler_del(_elm_exit_handler);
663    _elm_exit_handler = NULL;
664
665    _elm_theme_shutdown();
666    _elm_unneed_efreet();
667    _elm_unneed_e_dbus();
668    _elm_unneed_ethumb();
669    ecore_file_shutdown();
670    ecore_shutdown();
671    eet_shutdown();
672
673    if ((_elm_log_dom > -1) && (_elm_log_dom != EINA_LOG_DOMAIN_GLOBAL))
674      {
675         eina_log_domain_unregister(_elm_log_dom);
676         _elm_log_dom = -1;
677      }
678
679    _elm_widget_type_clear();
680
681    eina_shutdown();
682    return _elm_ql_init_count;
683 }
684
685 EAPI void
686 elm_quicklaunch_seed(void)
687 {
688 #ifndef SEMI_BROKEN_QUICKLAUNCH
689    if (quicklaunch_on)
690      {
691         Evas_Object *win, *bg, *bt;
692
693         win = elm_win_add(NULL, "seed", ELM_WIN_BASIC);
694         bg = elm_bg_add(win);
695         elm_win_resize_object_add(win, bg);
696         evas_object_show(bg);
697         bt = elm_button_add(win);
698         elm_button_label_set(bt, " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~-_=+\\|]}[{;:'\",<.>/?");
699         elm_win_resize_object_add(win, bt);
700         ecore_main_loop_iterate();
701         evas_object_del(win);
702         ecore_main_loop_iterate();
703 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
704         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
705             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
706             ENGINE_COMPARE(ELM_XRENDER_X11) ||
707             ENGINE_COMPARE(ELM_OPENGL_X11))
708 #undef ENGINE_COMPARE
709           {
710 # ifdef HAVE_ELEMENTARY_X
711              ecore_x_sync();
712 # endif
713           }
714         ecore_main_loop_iterate();
715      }
716 #endif
717 }
718
719 static void *qr_handle = NULL;
720 static int (*qr_main)(int    argc,
721                       char **argv) = NULL;
722
723 EAPI Eina_Bool
724 elm_quicklaunch_prepare(int argc __UNUSED__,
725                         char   **argv)
726 {
727 #ifdef HAVE_FORK
728    char *exe = elm_quicklaunch_exe_path_get(argv[0]);
729    if (!exe)
730      {
731         ERR("requested quicklaunch binary '%s' does not exist\n", argv[0]);
732         return EINA_FALSE;
733      }
734    else
735      {
736         char *exe2, *p;
737         char *exename;
738
739         exe2 = malloc(strlen(exe) + 1 + 10);
740         strcpy(exe2, exe);
741         p = strrchr(exe2, '/');
742         if (p) p++;
743         else p = exe2;
744         exename = alloca(strlen(p) + 1);
745         strcpy(exename, p);
746         *p = 0;
747         strcat(p, "../lib/");
748         strcat(p, exename);
749         strcat(p, ".so");
750         if (!access(exe2, R_OK | X_OK))
751           {
752              free(exe);
753              exe = exe2;
754           }
755         else
756           free(exe2);
757      }
758    qr_handle = dlopen(exe, RTLD_NOW | RTLD_GLOBAL);
759    if (!qr_handle)
760      {
761         fprintf(stderr, "dlerr: %s\n", dlerror());
762         WRN("dlopen('%s') failed: %s", exe, dlerror());
763         free(exe);
764         return EINA_FALSE;
765      }
766    INF("dlopen('%s') = %p", exe, qr_handle);
767    qr_main = dlsym(qr_handle, "elm_main");
768    INF("dlsym(%p, 'elm_main') = %p", qr_handle, qr_main);
769    if (!qr_main)
770      {
771         WRN("not quicklauncher capable: no elm_main in '%s'", exe);
772         dlclose(qr_handle);
773         qr_handle = NULL;
774         free(exe);
775         return EINA_FALSE;
776      }
777    free(exe);
778    return EINA_TRUE;
779 #else
780    return EINA_FALSE;
781    (void)argv;
782 #endif
783 }
784
785 #ifdef HAVE_FORK
786 static void
787 save_env(void)
788 {
789    int i, size;
790    extern char **environ;
791    char **oldenv, **p;
792
793    oldenv = environ;
794
795    for (i = 0, size = 0; environ[i]; i++)
796      size += strlen(environ[i]) + 1;
797
798    p = malloc((i + 1) * sizeof(char *));
799    if (!p) return;
800
801    environ = p;
802
803    for (i = 0; oldenv[i]; i++)
804      environ[i] = strdup(oldenv[i]);
805    environ[i] = NULL;
806 }
807
808 #endif
809
810 EAPI Eina_Bool
811 elm_quicklaunch_fork(int    argc,
812                      char **argv,
813                      char  *cwd,
814                      void (postfork_func) (void *data),
815                      void  *postfork_data)
816 {
817 #ifdef HAVE_FORK
818    pid_t child;
819    int ret;
820    int real_argc;
821    char **real_argv;
822
823    // FIXME:
824    // need to accept current environment from elementary_run
825    if (!qr_main)
826      {
827         int i;
828         char **args;
829
830         child = fork();
831         if (child > 0) return EINA_TRUE;
832         else if (child < 0)
833           {
834              perror("could not fork");
835              return EINA_FALSE;
836           }
837         setsid();
838         if (chdir(cwd) != 0)
839           perror("could not chdir");
840         args = alloca((argc + 1) * sizeof(char *));
841         for (i = 0; i < argc; i++) args[i] = argv[i];
842         args[argc] = NULL;
843         WRN("%s not quicklaunch capable, fallback...", argv[0]);
844         execvp(argv[0], args);
845         ERR("failed to execute '%s': %s", argv[0], strerror(errno));
846         exit(-1);
847      }
848    child = fork();
849    if (child > 0) return EINA_TRUE;
850    else if (child < 0)
851      {
852         perror("could not fork");
853         return EINA_FALSE;
854      }
855    if (postfork_func) postfork_func(postfork_data);
856
857    if (quicklaunch_on)
858      {
859 #ifdef SEMI_BROKEN_QUICKLAUNCH
860         ecore_app_args_set(argc, (const char **)argv);
861         evas_init();
862         edje_init();
863         _elm_config_sub_init();
864 #define ENGINE_COMPARE(name) (!strcmp(_elm_config->engine, name))
865         if (ENGINE_COMPARE(ELM_SOFTWARE_X11) ||
866             ENGINE_COMPARE(ELM_SOFTWARE_16_X11) ||
867             ENGINE_COMPARE(ELM_XRENDER_X11) ||
868             ENGINE_COMPARE(ELM_OPENGL_X11))
869 #undef ENGINE_COMPARE
870           {
871 # ifdef HAVE_ELEMENTARY_X
872              ecore_x_init(NULL);
873 # endif
874           }
875         ecore_evas_init(); // FIXME: check errors
876         ecore_imf_init();
877         _elm_module_init();
878 #endif
879      }
880
881    setsid();
882    if (chdir(cwd) != 0)
883      perror("could not chdir");
884    // FIXME: this is very linux specific. it changes argv[0] of the process
885    // so ps etc. report what you'd expect. for other unixes and os's this
886    // may just not work
887    save_env();
888    if (argv)
889      {
890         char *lastarg, *p;
891
892         ecore_app_args_get(&real_argc, &real_argv);
893         lastarg = real_argv[real_argc - 1] + strlen(real_argv[real_argc - 1]);
894         for (p = real_argv[0]; p < lastarg; p++) *p = 0;
895         strcpy(real_argv[0], argv[0]);
896      }
897    ecore_app_args_set(argc, (const char **)argv);
898    ret = qr_main(argc, argv);
899    exit(ret);
900    return EINA_TRUE;
901 #else
902    return EINA_FALSE;
903    (void)argc;
904    (void)argv;
905    (void)cwd;
906    (void)postfork_func;
907    (void)postfork_data;
908 #endif
909 }
910
911 EAPI void
912 elm_quicklaunch_cleanup(void)
913 {
914 #ifdef HAVE_FORK
915    if (qr_handle)
916      {
917         dlclose(qr_handle);
918         qr_handle = NULL;
919         qr_main = NULL;
920      }
921 #endif
922 }
923
924 EAPI int
925 elm_quicklaunch_fallback(int    argc,
926                          char **argv)
927 {
928    int ret;
929    elm_quicklaunch_init(argc, argv);
930    elm_quicklaunch_sub_init(argc, argv);
931    elm_quicklaunch_prepare(argc, argv);
932    ret = qr_main(argc, argv);
933    exit(ret);
934    return ret;
935 }
936
937 EAPI char *
938 elm_quicklaunch_exe_path_get(const char *exe)
939 {
940    static char *path = NULL;
941    static Eina_List *pathlist = NULL;
942    const char *pathitr;
943    const Eina_List *l;
944    char buf[PATH_MAX];
945    if (exe[0] == '/') return strdup(exe);
946    if ((exe[0] == '.') && (exe[1] == '/')) return strdup(exe);
947    if ((exe[0] == '.') && (exe[1] == '.') && (exe[2] == '/')) return strdup(exe);
948    if (!path)
949      {
950         const char *p, *pp;
951         char *buf2;
952         path = getenv("PATH");
953         buf2 = alloca(strlen(path) + 1);
954         p = path;
955         pp = p;
956         for (;; )
957           {
958              if ((*p == ':') || (!*p))
959                {
960                   int len;
961
962                   len = p - pp;
963                   strncpy(buf2, pp, len);
964                   buf2[len] = 0;
965                   pathlist = eina_list_append(pathlist, eina_stringshare_add(buf2));
966                   if (!*p) break;
967                   p++;
968                   pp = p;
969                }
970              else
971                {
972                   if (!*p) break;
973                   p++;
974                }
975           }
976      }
977    EINA_LIST_FOREACH(pathlist, l, pathitr)
978      {
979         snprintf(buf, sizeof(buf), "%s/%s", pathitr, exe);
980         if (!access(buf, R_OK | X_OK)) return strdup(buf);
981      }
982    return NULL;
983 }
984
985 /**
986  * Run the main loop
987  *
988  * This call should be called just after all initialization is complete. This
989  * function will not return until elm_exit() is called. It will keep looping
990  * running the main event/processing loop for Elementary.
991  * @ingroup General
992  */
993 EAPI void
994 elm_run(void)
995 {
996    ecore_main_loop_begin();
997 }
998
999 /**
1000  * Exit the main loop
1001  *
1002  * If this call is called, it will flag the main loop to cease processing and
1003  * return back to its parent function.
1004  * @ingroup General
1005  */
1006 EAPI void
1007 elm_exit(void)
1008 {
1009    ecore_main_loop_quit();
1010 }
1011
1012 /**
1013  * Set new policy value.
1014  *
1015  * This will emit the ecore event ELM_EVENT_POLICY_CHANGED in the main
1016  * loop giving the event information Elm_Event_Policy_Changed with
1017  * policy identifier, new and old values.
1018  *
1019  * @param policy policy identifier as in Elm_Policy.
1020  * @param value policy value, depends on identifiers, usually there is
1021  *        an enumeration with the same prefix as the policy name, for
1022  *        example: ELM_POLICY_QUIT and Elm_Policy_Quit
1023  *        (ELM_POLICY_QUIT_NONE, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED).
1024  * @ingroup General
1025  *
1026  * @return @c EINA_TRUE on success or @c EINA_FALSE on error (right
1027  *         now just invalid policy identifier, but in future policy
1028  *         value might be enforced).
1029  */
1030 EAPI Eina_Bool
1031 elm_policy_set(unsigned int policy,
1032                int          value)
1033 {
1034    Elm_Event_Policy_Changed *ev;
1035
1036    if (policy >= ELM_POLICY_LAST)
1037      return EINA_FALSE;
1038
1039    if (value == _elm_policies[policy])
1040      return EINA_TRUE;
1041
1042    /* TODO: validade policy? */
1043
1044    ev = malloc(sizeof(*ev));
1045    ev->policy = policy;
1046    ev->new_value = value;
1047    ev->old_value = _elm_policies[policy];
1048
1049    _elm_policies[policy] = value;
1050
1051    ecore_event_add(ELM_EVENT_POLICY_CHANGED, ev, NULL, NULL);
1052
1053    return EINA_TRUE;
1054 }
1055
1056 /**
1057  * Gets the policy value set for given identifier.
1058  *
1059  * @param policy policy identifier as in Elm_Policy.
1060  * @ingroup Main
1061  *
1062  * @return policy value. Will be 0 if policy identifier is invalid.
1063  */
1064 EAPI int
1065 elm_policy_get(unsigned int policy)
1066 {
1067    if (policy >= ELM_POLICY_LAST)
1068      return 0;
1069    return _elm_policies[policy];
1070 }
1071
1072 /**
1073  * @defgroup Scaling Selective Widget Scaling
1074  * @ingroup Main
1075  *
1076  * Different widgets can be scaled independently. These functions allow you to
1077  * manipulate this scaling on a per-widget basis. The object and all its
1078  * children get their scaling factors multiplied by the scale factor set.
1079  * This is multiplicative, in that if a child also has a scale size set it is
1080  * in turn multiplied by its parent's scale size. 1.0 means “don't scale”,
1081  * 2.0 is double size, 0.5 is half etc.
1082  */
1083
1084 /**
1085  * Set the scaling factor
1086  *
1087  * @param obj The object
1088  * @param scale Scale factor (from 0.0 up, with 1.0 == no scaling)
1089  * @ingroup Scaling
1090  */
1091 EAPI void
1092 elm_object_scale_set(Evas_Object *obj,
1093                      double       scale)
1094 {
1095    EINA_SAFETY_ON_NULL_RETURN(obj);
1096    elm_widget_scale_set(obj, scale);
1097 }
1098
1099 /**
1100  * Get the scaling factor
1101  *
1102  * @param obj The object
1103  * @return The scaling factor set by elm_object_scale_set()
1104  * @ingroup Scaling
1105  */
1106 EAPI double
1107 elm_object_scale_get(const Evas_Object *obj)
1108 {
1109    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, 0.0);
1110    return elm_widget_scale_get(obj);
1111 }
1112
1113 /**
1114  * Get the global scaling factor
1115  *
1116  * This gets the globally configured scaling factor that is applied to all
1117  * objects.
1118  *
1119  * @return The scaling factor
1120  * @ingroup Scaling
1121  */
1122 EAPI double
1123 elm_scale_get(void)
1124 {
1125    return _elm_config->scale;
1126 }
1127
1128 /**
1129  * Set the global scaling factor
1130  *
1131  * This sets the globally configured scaling factor that is applied to all
1132  * objects.
1133  *
1134  * @param scale The scaling factor to set
1135  * @ingroup Scaling
1136  */
1137 EAPI void
1138 elm_scale_set(double scale)
1139 {
1140    if (_elm_config->scale == scale) return;
1141    _elm_config->scale = scale;
1142    _elm_rescale();
1143 }
1144
1145 /**
1146  * Set the global scaling factor for all applications on the display
1147  *
1148  * This sets the globally configured scaling factor that is applied to all
1149  * objects for all applications.
1150  * @param scale The scaling factor to set
1151  * @ingroup Scaling
1152  */
1153 EAPI void
1154 elm_scale_all_set(double scale)
1155 {
1156 #ifdef HAVE_ELEMENTARY_X
1157    static Ecore_X_Atom atom = 0;
1158    unsigned int scale_i = (unsigned int)(scale * 1000.0);
1159
1160    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_SCALE");
1161    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
1162                                   atom, &scale_i, 1);
1163 #endif
1164 }
1165
1166 /**
1167  * @defgroup Styles Styles
1168  * @ingroup Main
1169  *
1170  * Widgets can have different styles of look. These generic API's set
1171  * styles of widgets, if they support them (and if the theme(s) do).
1172  */
1173
1174 /**
1175  * Set the style
1176  *
1177  * This sets the name of the style
1178  * @param obj The object
1179  * @param style The style name to use
1180  * @ingroup Styles
1181  */
1182 EAPI void
1183 elm_object_style_set(Evas_Object *obj,
1184                      const char  *style)
1185 {
1186    EINA_SAFETY_ON_NULL_RETURN(obj);
1187    elm_widget_style_set(obj, style);
1188 }
1189
1190 /**
1191  * Get the style
1192  *
1193  * This gets the style being used for that widget. Note that the string
1194  * pointer is only valid as longas the object is valid and the style doesn't
1195  * change.
1196  *
1197  * @param obj The object
1198  * @return The style name
1199  * @ingroup Styles
1200  */
1201 EAPI const char *
1202 elm_object_style_get(const Evas_Object *obj)
1203 {
1204    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
1205    return elm_widget_style_get(obj);
1206 }
1207
1208 /**
1209  * Set the disable state
1210  *
1211  * This sets the disable state for the widget.
1212  *
1213  * @param obj The object
1214  * @param disabled The state
1215  * @ingroup Styles
1216  */
1217 EAPI void
1218 elm_object_disabled_set(Evas_Object *obj,
1219                         Eina_Bool    disabled)
1220 {
1221    EINA_SAFETY_ON_NULL_RETURN(obj);
1222    elm_widget_disabled_set(obj, disabled);
1223 }
1224
1225 /**
1226  * Get the disable state
1227  *
1228  * This gets the disable state for the widget.
1229  *
1230  * @param obj The object
1231  * @return True, if the widget is disabled
1232  * @ingroup Styles
1233  */
1234 EAPI Eina_Bool
1235 elm_object_disabled_get(const Evas_Object *obj)
1236 {
1237    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
1238    return elm_widget_disabled_get(obj);
1239 }
1240
1241 /**
1242  * @defgroup Config Elementary Config
1243  * @ingroup Main
1244  *
1245  * Elementary configuration is formed by a set options bounded to a
1246  * given @ref Profile profile, like @ref Theme theme, @ref Fingers
1247  * "finger size", etc. These are functions with which one syncronizes
1248  * changes made to those values to the configuration storing files, de
1249  * facto. You most probably don't want to use the functions in this
1250  * group unlees you're writing an elementary configuration manager.
1251  */
1252
1253 /**
1254  * Save back Elementary's configuration, so that it will persist on
1255  * future sessions.
1256  *
1257  * @return @c EINA_TRUE, when sucessful. @c EINA_FALSE, otherwise.
1258  * @ingroup Config
1259  *
1260  * This function will take effect -- thus, do I/O -- immediately. Use
1261  * it when you want to apply all configuration changes at once. The
1262  * current configuration set will get saved onto the current profile
1263  * configuration file.
1264  *
1265  */
1266 EAPI Eina_Bool
1267 elm_config_save(void)
1268 {
1269    return _elm_config_save();
1270 }
1271
1272 /**
1273  * Reload Elementary's configuration, bounded to current selected
1274  * profile.
1275  *
1276  * @return @c EINA_TRUE, when sucessful. @c EINA_FALSE, otherwise.
1277  * @ingroup Config
1278  *
1279  * Useful when you want to force reloading of configuration values for
1280  * a profile. If one removes user custom configuration directories,
1281  * for example, it will force a reload with system values insted.
1282  *
1283  */
1284 EAPI void
1285 elm_config_reload(void)
1286 {
1287    _elm_config_reload();
1288 }
1289
1290 /**
1291  * @defgroup Profile Elementary Profile
1292  * @ingroup Main
1293  *
1294  * Profiles are pre-set options that affect the whole look-and-feel of
1295  * Elementary-based applications. There are, for example, profiles
1296  * aimed at desktop computer applications and others aimed at mobile,
1297  * touchscreen-based ones. You most probably don't want to use the
1298  * functions in this group unlees you're writing an elementary
1299  * configuration manager.
1300  */
1301
1302 /**
1303  * Get Elementary's profile in use.
1304  *
1305  * This gets the global profile that is applied to all Elementary
1306  * applications.
1307  *
1308  * @return The profile's name
1309  * @ingroup Profile
1310  */
1311 EAPI const char *
1312 elm_profile_current_get(void)
1313 {
1314    return _elm_config_current_profile_get();
1315 }
1316
1317 /**
1318  * Get an Elementary's profile directory path in the filesystem. One
1319  * may want to fetch a system profile's dir or an user one (fetched
1320  * inside $HOME).
1321  *
1322  * @param profile The profile's name
1323  * @param is_user Whether to lookup for an user profile (@c EINA_TRUE)
1324  *                or a system one (@c EINA_FALSE)
1325  * @return The profile's directory path.
1326  * @ingroup Profile
1327  *
1328  * @note You must free it with elm_profile_dir_free().
1329  */
1330 EAPI const char *
1331 elm_profile_dir_get(const char *profile,
1332                     Eina_Bool   is_user)
1333 {
1334    return _elm_config_profile_dir_get(profile, is_user);
1335 }
1336
1337 /**
1338  * Free an Elementary's profile directory path, as returned by
1339  * elm_profile_dir_get().
1340  *
1341  * @param p_dir The profile's path
1342  * @ingroup Profile
1343  *
1344  */
1345 EAPI void
1346 elm_profile_dir_free(const char *p_dir)
1347 {
1348    free((void *)p_dir);
1349 }
1350
1351 /**
1352  * Get Elementary's list of available profiles.
1353  *
1354  * @return The profiles list. List node data are the profile name
1355  *         strings.
1356  * @ingroup Profile
1357  *
1358  * @note One must free this list, after usage, with the function
1359  *       elm_profile_list_free().
1360  */
1361 EAPI Eina_List *
1362 elm_profile_list_get(void)
1363 {
1364    return _elm_config_profiles_list();
1365 }
1366
1367 /**
1368  * Free Elementary's list of available profiles.
1369  *
1370  * @param The profiles list, as returned by elm_profile_list_get().
1371  * @ingroup Profile
1372  *
1373  */
1374 EAPI void
1375 elm_profile_list_free(Eina_List *l)
1376 {
1377    const char *dir;
1378
1379    EINA_LIST_FREE(l, dir)
1380      eina_stringshare_del(dir);
1381 }
1382
1383 /**
1384  * Set Elementary's profile.
1385  *
1386  * This sets the global profile that is applied to Elementary
1387  * applications. Just the process the call comes from will be
1388  * affected.
1389  *
1390  * @param profile The profile's name
1391  * @ingroup Profile
1392  *
1393  */
1394 EAPI void
1395 elm_profile_set(const char *profile)
1396 {
1397    EINA_SAFETY_ON_NULL_RETURN(profile);
1398    _elm_config_profile_set(profile);
1399 }
1400
1401 /**
1402  * Set Elementary's profile.
1403  *
1404  * This sets the global profile that is applied to all Elementary
1405  * applications. All running Elementary windows will be affected.
1406  *
1407  * @param profile The profile's name
1408  * @ingroup Profile
1409  *
1410  */
1411 EAPI void
1412 elm_profile_all_set(const char *profile)
1413 {
1414 #ifdef HAVE_ELEMENTARY_X
1415    static Ecore_X_Atom atom = 0;
1416
1417    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_PROFILE");
1418    ecore_x_window_prop_string_set(ecore_x_window_root_first_get(),
1419                                   atom, profile);
1420 #endif
1421 }
1422
1423 /**
1424  * @defgroup Engine Elementary Engine
1425  * @ingroup Main
1426  *
1427  * These are functions setting and querying which rendering engine
1428  * Elementary will use for drawing its windows' pixels.
1429  */
1430
1431 /**
1432  * Get Elementary's rendering engine in use.
1433  *
1434  * This gets the global rendering engine that is applied to all
1435  * Elementary applications.
1436  *
1437  * @return The rendering engine's name
1438  * @ingroup Engine
1439  *
1440  * @note there's no need to free the returned string, here.
1441  */
1442 EAPI const char *
1443 elm_engine_current_get(void)
1444 {
1445    return _elm_config->engine;
1446 }
1447
1448 /**
1449  * Set Elementary's rendering engine for use.
1450  *
1451  * This gets sets global rendering engine that is applied to all
1452  * Elementary applications. Note that it will take effect only to
1453  * subsequent Elementary window creations.
1454  *
1455  * @param The rendering engine's name
1456  * @ingroup Engine
1457  *
1458  * @note there's no need to free the returned string, here.
1459  */
1460 EAPI void
1461 elm_engine_set(const char *engine)
1462 {
1463    EINA_SAFETY_ON_NULL_RETURN(engine);
1464
1465    _elm_config_engine_set(engine);
1466 }
1467
1468 /**
1469  * @defgroup Fonts Elementary Fonts
1470  * @ingroup Main
1471  *
1472  * These are functions dealing with font rendering, selection and the
1473  * like for Elementary applications. One might fetch which system
1474  * fonts are there to use and set custom fonts for individual classes
1475  * of UI items containing text (text classes).
1476  */
1477
1478 /**
1479  * Get Elementary's list of supported text classes.
1480  *
1481  * @return The text classes list, with @c Elm_Text_Class blobs as data.
1482  * @ingroup Fonts
1483  *
1484  * Release the list with elm_text_classes_list_free().
1485  */
1486 EAPI const Eina_List *
1487 elm_text_classes_list_get(void)
1488 {
1489    return _elm_config_text_classes_get();
1490 }
1491
1492 /**
1493  * Free Elementary's list of supported text classes.
1494  *
1495  * @ingroup Fonts
1496  *
1497  * @see elm_text_classes_list_get().
1498  */
1499 EAPI void
1500 elm_text_classes_list_free(const Eina_List *list)
1501 {
1502    _elm_config_text_classes_free((Eina_List *)list);
1503 }
1504
1505 /**
1506  * Get Elementary's list of font overlays, set with
1507  * elm_font_overlay_set().
1508  *
1509  * @return The font overlays list, with @c Elm_Font_Overlay blobs as
1510  * data.
1511  *
1512  * @ingroup Fonts
1513  *
1514  * For each text class, one can set a <b>font overlay</b> for it,
1515  * overriding the default font properties for that class coming from
1516  * the theme in use. There is no need to free this list.
1517  *
1518  * @see elm_font_overlay_set() and elm_font_overlay_unset().
1519  */
1520 EAPI const Eina_List *
1521 elm_font_overlay_list_get(void)
1522 {
1523    return _elm_config_font_overlays_list();
1524 }
1525
1526 /**
1527  * Set a font overlay for a given Elementary text class.
1528  *
1529  * @param text_class Text class name
1530  * @param font Font name and style string
1531  * @param size Font size
1532  *
1533  * @ingroup Fonts
1534  *
1535  * @p font has to be in the format returned by
1536  * elm_font_fontconfig_name_get(). @see elm_font_overlay_list_get()
1537  * and @elm_font_overlay_unset().
1538  */
1539 EAPI void
1540 elm_font_overlay_set(const char    *text_class,
1541                      const char    *font,
1542                      Evas_Font_Size size)
1543 {
1544    _elm_config_font_overlay_set(text_class, font, size);
1545 }
1546
1547 /**
1548  * Unset a font overlay for a given Elementary text class.
1549  *
1550  * @param text_class Text class name
1551  *
1552  * @ingroup Fonts
1553  *
1554  * This will bring back text elements belonging to text class @p
1555  * text_class back to their default font settings.
1556  */
1557 EAPI void
1558 elm_font_overlay_unset(const char *text_class)
1559 {
1560    _elm_config_font_overlay_remove(text_class);
1561 }
1562
1563 /**
1564  * Apply the changes made with elm_font_overlay_set() and
1565  * elm_font_overlay_unset() on the current Elementary window.
1566  *
1567  * @ingroup Fonts
1568  *
1569  * This applies all font overlays set to all objects in the UI.
1570  */
1571 EAPI void
1572 elm_font_overlay_apply(void)
1573 {
1574    _elm_config_font_overlay_apply();
1575 }
1576
1577 /**
1578  * Apply the changes made with elm_font_overlay_set() and
1579  * elm_font_overlay_unset() on all Elementary application windows.
1580  *
1581  * @ingroup Fonts
1582  *
1583  * This applies all font overlays set to all objects in the UI.
1584  */
1585 EAPI void
1586 elm_font_overlay_all_apply(void)
1587 {
1588 #ifdef HAVE_ELEMENTARY_X
1589    static Ecore_X_Atom atom = 0;
1590    unsigned int dummy = (unsigned int)(1 * 1000.0);
1591
1592    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_FONT_OVERLAY");
1593    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(), atom, &dummy,
1594                                   1);
1595 #endif
1596 }
1597
1598 /**
1599  * Translate a font (family) name string in fontconfig's font names
1600  * syntax into an @c Elm_Font_Properties struct.
1601  *
1602  * @param font The font name and styles string
1603  * @return the font properties struct
1604  *
1605  * @ingroup Fonts
1606  *
1607  * @note The reverse translation can be achived with
1608  * elm_font_fontconfig_name_get(), for one style only (single font
1609  * instance, not family).
1610  */
1611 EAPI Elm_Font_Properties *
1612 elm_font_properties_get(const char *font)
1613 {
1614    EINA_SAFETY_ON_NULL_RETURN_VAL(font, NULL);
1615    return _elm_font_properties_get(NULL, font);
1616 }
1617
1618 /**
1619  * Free font properties return by elm_font_properties_get().
1620  *
1621  * @param efp the font properties struct
1622  *
1623  * @ingroup Fonts
1624  */
1625 EAPI void
1626 elm_font_properties_free(Elm_Font_Properties *efp)
1627 {
1628    const char *str;
1629
1630    EINA_SAFETY_ON_NULL_RETURN(efp);
1631    EINA_LIST_FREE(efp->styles, str)
1632      if (str) eina_stringshare_del(str);
1633    if (efp->name) eina_stringshare_del(efp->name);
1634    free(efp);
1635 }
1636
1637 /**
1638  * Translate a font name, bound to a style, into fontconfig's font names
1639  * syntax.
1640  *
1641  * @param name The font (family) name
1642  * @param style The given style (may be @c NULL)
1643  *
1644  * @return the font name and style string
1645  *
1646  * @ingroup Fonts
1647  *
1648  * @note The reverse translation can be achived with
1649  * elm_font_properties_get(), for one style only (single font
1650  * instance, not family).
1651  */
1652 EAPI const char *
1653 elm_font_fontconfig_name_get(const char *name,
1654                              const char *style)
1655 {
1656    char buf[256];
1657
1658    EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
1659    if (!style || style[0] == 0) return eina_stringshare_add(name);
1660    snprintf(buf, 256, "%s" ELM_FONT_TOKEN_STYLE "%s", name, style);
1661    return eina_stringshare_add(buf);
1662 }
1663
1664 /**
1665  * Free the font string return by elm_font_fontconfig_name_get().
1666  *
1667  * @param efp the font properties struct
1668  *
1669  * @ingroup Fonts
1670  */
1671 EAPI void
1672 elm_font_fontconfig_name_free(const char *name)
1673 {
1674    eina_stringshare_del(name);
1675 }
1676
1677 /**
1678  * Create a font hash table of available system fonts.
1679  *
1680  * One must call it with @p list being the return value of
1681  * evas_font_available_list(). The hash will be indexed by font
1682  * (family) names, being its values @c Elm_Font_Properties blobs.
1683  *
1684  * @param list The list of available system fonts, as returned by
1685  * evas_font_available_list().
1686  * @return the font hash.
1687  *
1688  * @ingroup Fonts
1689  *
1690  * @note The user is supposed to get it populated at least with 3
1691  * default font families (Sans, Serif, Monospace), which should be
1692  * present on most systems.
1693  */
1694 EAPI Eina_Hash *
1695 elm_font_available_hash_add(Eina_List *list)
1696 {
1697    Eina_Hash *font_hash;
1698    Eina_List *l;
1699    void *key;
1700
1701    font_hash = NULL;
1702
1703    /* populate with default font families */
1704    font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Regular");
1705    font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold");
1706    font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Oblique");
1707    font_hash = _elm_font_available_hash_add(font_hash,
1708                                             "Sans:style=Bold Oblique");
1709
1710    font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Regular");
1711    font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold");
1712    font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Oblique");
1713    font_hash = _elm_font_available_hash_add(font_hash,
1714                                             "Serif:style=Bold Oblique");
1715
1716    font_hash = _elm_font_available_hash_add(font_hash,
1717                                             "Monospace:style=Regular");
1718    font_hash = _elm_font_available_hash_add(font_hash,
1719                                             "Monospace:style=Bold");
1720    font_hash = _elm_font_available_hash_add(font_hash,
1721                                             "Monospace:style=Oblique");
1722    font_hash = _elm_font_available_hash_add(font_hash,
1723                                             "Monospace:style=Bold Oblique");
1724
1725    EINA_LIST_FOREACH(list, l, key)
1726      font_hash = _elm_font_available_hash_add(font_hash, key);
1727
1728    return font_hash;
1729 }
1730
1731 /**
1732  * Free the hash return by elm_font_available_hash_add().
1733  *
1734  * @param hash the hash to be freed.
1735  *
1736  * @ingroup Fonts
1737  */
1738 EAPI void
1739 elm_font_available_hash_del(Eina_Hash *hash)
1740 {
1741    _elm_font_available_hash_del(hash);
1742 }
1743
1744 /**
1745  * @defgroup Fingers Fingers
1746  * @ingroup Main
1747  *
1748  * Elementary is designed to be finger-friendly for touchscreens, and so in
1749  * addition to scaling for display resolution, it can also scale based on
1750  * finger "resolution" (or size).
1751  */
1752
1753 /**
1754  * Get the configured finger size
1755  *
1756  * This gets the globally configured finger size in pixels
1757  *
1758  * @return The finger size
1759  * @ingroup Fingers
1760  */
1761 EAPI Evas_Coord
1762 elm_finger_size_get(void)
1763 {
1764    return _elm_config->finger_size;
1765 }
1766
1767 /**
1768  * Set the configured finger size
1769  *
1770  * This sets the globally configured finger size in pixels
1771  *
1772  * @param size The finger size
1773  * @ingroup Fingers
1774  */
1775 EAPI void
1776 elm_finger_size_set(Evas_Coord size)
1777 {
1778    if (_elm_config->finger_size == size) return;
1779    _elm_config->finger_size = size;
1780    _elm_rescale();
1781 }
1782
1783 /**
1784  * Set the configured finger size for all applications on the display
1785  *
1786  * This sets the globally configured finger size in pixels for all applications
1787  * on the display
1788  *
1789  * @param size The finger size
1790  * @ingroup Fingers
1791  */
1792 EAPI void
1793 elm_finger_size_all_set(Evas_Coord size)
1794 {
1795 #ifdef HAVE_ELEMENTARY_X
1796    static Ecore_X_Atom atom = 0;
1797    unsigned int size_i = (unsigned int)size;
1798
1799    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_FINGER_SIZE");
1800    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
1801                                   atom, &size_i, 1);
1802 #endif   
1803 }
1804
1805 EAPI void
1806 elm_autocapitalization_allow_all_set(Eina_Bool on)
1807 {
1808 #ifdef HAVE_ELEMENTARY_X
1809    static Ecore_X_Atom atom = 0;
1810    unsigned int on_i = (unsigned int)on;
1811
1812    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_AUTOCAPITAL_ALLOW");
1813    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
1814                                   atom, &on_i, 1);
1815 #endif
1816 }
1817
1818 EAPI void
1819 elm_autoperiod_allow_all_set(Eina_Bool on)
1820 {
1821 #ifdef HAVE_ELEMENTARY_X
1822    static Ecore_X_Atom atom = 0;
1823    unsigned int on_i = (unsigned int)on;
1824
1825    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_AUTOPERIOD_ALLOW");
1826    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
1827                                   atom, &on_i, 1);
1828 #endif
1829 }
1830
1831
1832 /**
1833  * Adjust size of an element for finger usage
1834  *
1835  * This takes width and height sizes (in pixels) as input and a size multiple
1836  * (which is how many fingers you want to place within the area), and adjusts
1837  * the size tobe large enough to accommodate finger. On return the w and h
1838  * sizes poiner do by these parameters will be modified.
1839  *
1840  * @param times_w How many fingers should fit horizontally
1841  * @param w Pointer to the width size to adjust
1842  * @param times_h How many fingers should fit vertically
1843  * @param h Pointer to the height size to adjust
1844  * @ingroup Fingers
1845  */
1846 EAPI void
1847 elm_coords_finger_size_adjust(int         times_w,
1848                               Evas_Coord *w,
1849                               int         times_h,
1850                               Evas_Coord *h)
1851 {
1852    if ((w) && (*w < (_elm_config->finger_size * times_w)))
1853      *w = _elm_config->finger_size * times_w;
1854    if ((h) && (*h < (_elm_config->finger_size * times_h)))
1855      *h = _elm_config->finger_size * times_h;
1856 }
1857
1858 /**
1859  * @defgroup Caches Caches
1860  * @ingroup Main
1861  *
1862  * These are functions which let one fine-tune some cache values for
1863  * Elementary applications, thus allowing for performance adjustments.
1864  */
1865
1866 /**
1867  * Flush all caches & dump all data that can be to lean down to use
1868  * less memory
1869  *
1870  * @ingroup Caches
1871  */
1872 EAPI void
1873 elm_all_flush(void)
1874 {
1875    const Eina_List *l;
1876    Evas_Object *obj;
1877
1878    edje_file_cache_flush();
1879    edje_collection_cache_flush();
1880    eet_clearcache();
1881    EINA_LIST_FOREACH(_elm_win_list, l, obj)
1882      {
1883         Evas *e = evas_object_evas_get(obj);
1884             evas_image_cache_flush(e);
1885         evas_font_cache_flush(e);
1886         evas_render_dump(e);
1887      }
1888 }
1889
1890 /**
1891  * Get the configured cache flush interval time
1892  *
1893  * This gets the globally configured cache flush interval time, in
1894  * ticks
1895  *
1896  * @return The cache flush interval time
1897  * @ingroup Caches
1898  *
1899  * @see elm_all_flush()
1900  */
1901 EAPI int
1902 elm_cache_flush_interval_get(void)
1903 {
1904    return _elm_config->cache_flush_poll_interval;
1905 }
1906
1907 /**
1908  * Set the configured cache flush interval time
1909  *
1910  * This sets the globally configured cache flush interval time, in ticks
1911  *
1912  * @param size The cache flush interval time
1913  * @ingroup Caches
1914  *
1915  * @see elm_all_flush()
1916  */
1917 EAPI void
1918 elm_cache_flush_interval_set(int size)
1919 {
1920    if (_elm_config->cache_flush_poll_interval == size) return;
1921    _elm_config->cache_flush_poll_interval = size;
1922
1923    _elm_recache();
1924 }
1925
1926 /**
1927  * Set the configured cache flush interval time for all applications on the
1928  * display
1929  *
1930  * This sets the globally configured cache flush interval time -- in ticks
1931  * -- for all applications on the display.
1932  *
1933  * @param size The cache flush interval time
1934  * @ingroup Caches
1935  */
1936 EAPI void
1937 elm_cache_flush_interval_all_set(int size)
1938 {
1939 #ifdef HAVE_ELEMENTARY_X
1940    static Ecore_X_Atom atom = 0;
1941    unsigned int size_i = (unsigned int)size;
1942
1943    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_CACHE_FLUSH_INTERVAL");
1944    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
1945                                   atom, &size_i, 1);
1946 #endif
1947 }
1948
1949 /**
1950  * Get the configured cache flush enabled state
1951  *
1952  * This gets the globally configured cache flush state - if it is enabled
1953  * or not. When cache flushing is enabled, elementary will regularly
1954  * (see elm_cache_flush_interval_get() ) flush caches and dump data out of
1955  * memory and allow usage to re-seed caches and data in memory where it
1956  * can do so. An idle application will thus minimise its memory usage as
1957  * data will be freed from memory and not be re-loaded as it is idle and
1958  * not rendering or doing anything graphically right now.
1959  *
1960  * @return The cache flush state
1961  * @ingroup Caches
1962  *
1963  * @see elm_all_flush()
1964  */
1965 EAPI Eina_Bool
1966 elm_cache_flush_enmabled_get(void)
1967 {
1968    return _elm_config->cache_flush_enable;
1969 }
1970
1971 /**
1972  * Set the configured cache flush enabled state
1973  *
1974  * This sets the globally configured cache flush enabled state
1975  *
1976  * @param size The cache flush enabled state
1977  * @ingroup Caches
1978  *
1979  * @see elm_all_flush()
1980  */
1981 EAPI void
1982 elm_cache_flush_enabled_set(Eina_Bool enabled)
1983 {
1984    enabled = !!enabled;
1985    if (_elm_config->cache_flush_enable == enabled) return;
1986    _elm_config->cache_flush_enable = enabled;
1987
1988    _elm_recache();
1989 }
1990
1991 /**
1992  * Set the configured cache flush enabled state for all applications on the
1993  * display
1994  *
1995  * This sets the globally configured cache flush enabled state for all 
1996  * applications on the display.
1997  *
1998  * @param size The cache flush enabled state
1999  * @ingroup Caches
2000  */
2001 EAPI void
2002 elm_cache_flush_enabled_all_set(Eina_Bool enabled)
2003 {
2004 #ifdef HAVE_ELEMENTARY_X
2005    static Ecore_X_Atom atom = 0;
2006    unsigned int enabled_i = (unsigned int)enabled;
2007
2008    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_CACHE_FLUSH_ENABLE");
2009    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2010                                   atom, &enabled_i, 1);
2011 #endif
2012 }
2013
2014 /**
2015  * Get the configured font cache size
2016  *
2017  * This gets the globally configured font cache size, in bytes
2018  *
2019  * @return The font cache size
2020  * @ingroup Caches
2021  */
2022 EAPI int
2023 elm_font_cache_get(void)
2024 {
2025    return _elm_config->font_cache;
2026 }
2027
2028 /**
2029  * Set the configured font cache size
2030  *
2031  * This sets the globally configured font cache size, in bytes
2032  *
2033  * @param size The font cache size
2034  * @ingroup Caches
2035  */
2036 EAPI void
2037 elm_font_cache_set(int size)
2038 {
2039    if (_elm_config->font_cache == size) return;
2040    _elm_config->font_cache = size;
2041
2042    _elm_recache();
2043 }
2044
2045 /**
2046  * Set the configured font cache size for all applications on the
2047  * display
2048  *
2049  * This sets the globally configured font cache size -- in bytes
2050  * -- for all applications on the display.
2051  *
2052  * @param size The font cache size
2053  * @ingroup Caches
2054  */
2055 EAPI void
2056 elm_font_cache_all_set(int size)
2057 {
2058 #ifdef HAVE_ELEMENTARY_X
2059    static Ecore_X_Atom atom = 0;
2060    unsigned int size_i = (unsigned int)size;
2061
2062    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_FONT_CACHE");
2063    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2064                                   atom, &size_i, 1);
2065 #endif
2066 }
2067
2068 /**
2069  * Get the configured image cache size
2070  *
2071  * This gets the globally configured image cache size, in bytes
2072  *
2073  * @return The image cache size
2074  * @ingroup Caches
2075  */
2076 EAPI int
2077 elm_image_cache_get(void)
2078 {
2079    return _elm_config->image_cache;
2080 }
2081
2082 /**
2083  * Set the configured image cache size
2084  *
2085  * This sets the globally configured image cache size, in bytes
2086  *
2087  * @param size The image cache size
2088  * @ingroup Caches
2089  */
2090 EAPI void
2091 elm_image_cache_set(int size)
2092 {
2093    if (_elm_config->image_cache == size) return;
2094    _elm_config->image_cache = size;
2095
2096    _elm_recache();
2097 }
2098
2099 /**
2100  * Set the configured image cache size for all applications on the
2101  * display
2102  *
2103  * This sets the globally configured image cache size -- in bytes
2104  * -- for all applications on the display.
2105  *
2106  * @param size The image cache size
2107  * @ingroup Caches
2108  */
2109 EAPI void
2110 elm_image_cache_all_set(int size)
2111 {
2112 #ifdef HAVE_ELEMENTARY_X
2113    static Ecore_X_Atom atom = 0;
2114    unsigned int size_i = (unsigned int)size;
2115
2116    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_IMAGE_CACHE");
2117    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2118                                   atom, &size_i, 1);
2119 #endif
2120 }
2121
2122 /**
2123  * Get the configured edje file cache size.
2124  *
2125  * This gets the globally configured edje file cache size, in number
2126  * of files.
2127  *
2128  * @return The edje file cache size
2129  * @ingroup Caches
2130  */
2131 EAPI int
2132 elm_edje_file_cache_get(void)
2133 {
2134    return _elm_config->edje_cache;
2135 }
2136
2137 /**
2138  * Set the configured edje file cache size
2139  *
2140  * This sets the globally configured edje file cache size, in number
2141  * of files.
2142  *
2143  * @param size The edje file cache size
2144  * @ingroup Caches
2145  */
2146 EAPI void
2147 elm_edje_file_cache_set(int size)
2148 {
2149    if (_elm_config->edje_cache == size) return;
2150    _elm_config->edje_cache = size;
2151
2152    _elm_recache();
2153 }
2154
2155 /**
2156  * Set the configured edje file cache size for all applications on the
2157  * display
2158  *
2159  * This sets the globally configured edje file cache size -- in number
2160  * of files -- for all applications on the display.
2161  *
2162  * @param size The edje file cache size
2163  * @ingroup Caches
2164  */
2165 EAPI void
2166 elm_edje_file_cache_all_set(int size)
2167 {
2168 #ifdef HAVE_ELEMENTARY_X
2169    static Ecore_X_Atom atom = 0;
2170    unsigned int size_i = (unsigned int)size;
2171
2172    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_EDJE_FILE_CACHE");
2173    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2174                                   atom, &size_i, 1);
2175 #endif
2176 }
2177
2178 /**
2179  * Get the configured edje collections (groups) cache size.
2180  *
2181  * This gets the globally configured edje collections cache size, in
2182  * number of collections.
2183  *
2184  * @return The edje collections cache size
2185  * @ingroup Caches
2186  */
2187 EAPI int
2188 elm_edje_collection_cache_get(void)
2189 {
2190    return _elm_config->edje_collection_cache;
2191 }
2192
2193 /**
2194  * Set the configured edje collections (groups) cache size
2195  *
2196  * This sets the globally configured edje collections cache size, in
2197  * number of collections.
2198  *
2199  * @param size The edje collections cache size
2200  * @ingroup Caches
2201  */
2202 EAPI void
2203 elm_edje_collection_cache_set(int size)
2204 {
2205    if (_elm_config->edje_collection_cache == size) return;
2206    _elm_config->edje_collection_cache = size;
2207
2208    _elm_recache();
2209 }
2210
2211 /**
2212  * Set the configured edje collections (groups) cache size for all
2213  * applications on the display
2214  *
2215  * This sets the globally configured edje collections cache size -- in
2216  * number of collections -- for all applications on the display.
2217  *
2218  * @param size The edje collections cache size
2219  * @ingroup Caches
2220  */
2221 EAPI void
2222 elm_edje_collection_cache_all_set(int size)
2223 {
2224 #ifdef HAVE_ELEMENTARY_X
2225    static Ecore_X_Atom atom = 0;
2226    unsigned int size_i = (unsigned int)size;
2227
2228    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_EDJE_COLLECTION_CACHE");
2229    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2230                                   atom, &size_i, 1);
2231 #endif
2232 }
2233
2234 /**
2235  * @defgroup Focus Focus
2236  * @ingroup Main
2237  *
2238  * Objects have focus. This is what determines where the keyboard input goes to
2239  * within the application window.
2240  */
2241
2242 /**
2243  * Get the focus of the object
2244  *
2245  * This gets the focused property of the object.
2246  *
2247  * @param obj The object
2248  * @return 1 if the object is focused, 0 if not.
2249  * @ingroup Focus
2250  */
2251 EAPI Eina_Bool
2252 elm_object_focus_get(const Evas_Object *obj)
2253 {
2254    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
2255    return elm_widget_focus_get(obj);
2256 }
2257
2258 /**
2259  * Set the focus to the object
2260  *
2261  * This sets the focus target for keyboard input to be the object indicated.
2262  *
2263  * @param obj The object
2264  * @ingroup Focus
2265  */
2266 EAPI void
2267 elm_object_focus(Evas_Object *obj)
2268 {
2269    EINA_SAFETY_ON_NULL_RETURN(obj);
2270    if (elm_widget_focus_get(obj))
2271      return;
2272
2273    elm_widget_focus_cycle(obj, ELM_FOCUS_NEXT);
2274 }
2275
2276 /**
2277  * Remove the focus from the object
2278  *
2279  * This removes the focus target for keyboard input from be the object
2280  * indicated.
2281  *
2282  * @param obj The object
2283  * @ingroup Focus
2284  */
2285 EAPI void
2286 elm_object_unfocus(Evas_Object *obj)
2287 {
2288    EINA_SAFETY_ON_NULL_RETURN(obj);
2289    if (!elm_widget_can_focus_get(obj)) return;
2290    elm_widget_focused_object_clear(obj);
2291 }
2292
2293 /**
2294  * Set the ability for the object to focus
2295  *
2296  * This sets the ability for the object to be able to get keyboard focus or
2297  * not. By default all objects are able to be focused.
2298  *
2299  * @param obj The object
2300  * @param enable 1 if the object can be focused, 0 if not
2301  * @ingroup Focus
2302  */
2303 EAPI void
2304 elm_object_focus_allow_set(Evas_Object *obj,
2305                            Eina_Bool    enable)
2306 {
2307    EINA_SAFETY_ON_NULL_RETURN(obj);
2308    elm_widget_can_focus_set(obj, enable);
2309 }
2310
2311 /**
2312  * Get the ability for the object to focus
2313  *
2314  * This gets the ability for the object to be able to get keyboard focus or
2315  * not. By default all objects are able to be focused.
2316  *
2317  * @param obj The object
2318  * @return 1 if the object is allowed to be focused, 0 if not.
2319  * @ingroup Focus
2320  */
2321 EAPI Eina_Bool
2322 elm_object_focus_allow_get(const Evas_Object *obj)
2323 {
2324    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
2325    return (elm_widget_can_focus_get(obj)) || (elm_widget_child_can_focus_get(obj));
2326 }
2327
2328 /**
2329  * Set custom focus chain.
2330  *
2331  * This function i set one new and overwrite any previous custom focus chain
2332  * with the list of objects. The previous list will be deleted and this list
2333  * will be managed. After setted, don't modity it.
2334  *
2335  * @note On focus cycle, only will be evaluated children of this container.
2336  *
2337  * @param obj The container object
2338  * @param objs Chain of objects to pass focus
2339  * @ingroup Focus
2340  */
2341 EAPI void
2342 elm_object_focus_custom_chain_set(Evas_Object *obj,
2343                                   Eina_List   *objs)
2344 {
2345    EINA_SAFETY_ON_NULL_RETURN(obj);
2346    elm_widget_focus_custom_chain_set(obj, objs);
2347 }
2348
2349 /**
2350  * Unset custom focus chain
2351  *
2352  * @param obj The container object
2353  * @ingroup Focus
2354  */
2355 EAPI void
2356 elm_object_focus_custom_chain_unset(Evas_Object *obj)
2357 {
2358    EINA_SAFETY_ON_NULL_RETURN(obj);
2359    elm_widget_focus_custom_chain_unset(obj);
2360 }
2361
2362 /**
2363  * Get custom focus chain
2364  *
2365  * @param obj The container object
2366  * @ingroup Focus
2367  */
2368 EAPI const Eina_List *
2369 elm_object_focus_custom_chain_get(const Evas_Object *obj)
2370 {
2371    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
2372    return elm_widget_focus_custom_chain_get(obj);
2373 }
2374
2375 /**
2376  * Append object to custom focus chain.
2377  *
2378  * @note If relative_child equal to NULL or not in custom chain, the object
2379  * will be added in end.
2380  *
2381  * @note On focus cycle, only will be evaluated children of this container.
2382  *
2383  * @param obj The container object
2384  * @param child The child to be added in custom chain
2385  * @param relative_child The relative object to position the child
2386  * @ingroup Focus
2387  */
2388 EAPI void
2389 elm_object_focus_custom_chain_append(Evas_Object *obj,
2390                                      Evas_Object *child,
2391                                      Evas_Object *relative_child)
2392 {
2393    EINA_SAFETY_ON_NULL_RETURN(obj);
2394    EINA_SAFETY_ON_NULL_RETURN(child);
2395    elm_widget_focus_custom_chain_append(obj, child, relative_child);
2396 }
2397
2398 /**
2399  * Prepend object to custom focus chain.
2400  *
2401  * @note If relative_child equal to NULL or not in custom chain, the object
2402  * will be added in begin.
2403  *
2404  * @note On focus cycle, only will be evaluated children of this container.
2405  *
2406  * @param obj The container object
2407  * @param child The child to be added in custom chain
2408  * @param relative_child The relative object to position the child
2409  * @ingroup Focus
2410  */
2411 EAPI void
2412 elm_object_focus_custom_chain_prepend(Evas_Object *obj,
2413                                       Evas_Object *child,
2414                                       Evas_Object *relative_child)
2415 {
2416    EINA_SAFETY_ON_NULL_RETURN(obj);
2417    EINA_SAFETY_ON_NULL_RETURN(child);
2418    elm_widget_focus_custom_chain_prepend(obj, child, relative_child);
2419 }
2420
2421 /**
2422  * Give focus to next object in object tree.
2423  *
2424  * Give focus to next object in focus chain of one object sub-tree.
2425  * If the last object of chain already have focus, the focus will go to the
2426  * first object of chain.
2427  *
2428  * @param obj The object root of sub-tree
2429  * @param dir Direction to cycle the focus
2430  *
2431  * @ingroup Focus
2432  */
2433 EAPI void
2434 elm_object_focus_cycle(Evas_Object        *obj,
2435                        Elm_Focus_Direction dir)
2436 {
2437    EINA_SAFETY_ON_NULL_RETURN(obj);
2438    elm_widget_focus_cycle(obj, dir);
2439 }
2440
2441 /**
2442  * Give focus to near object in one direction.
2443  *
2444  * Give focus to near object in direction of one object.
2445  * If none focusable object in given direction, the focus will not change.
2446  *
2447  * @param obj The reference object
2448  * @param x Horizontal component of direction to focus
2449  * @param y Vertical component of direction to focus
2450  *
2451  * @ingroup Focus
2452  */
2453 EAPI void
2454 elm_object_focus_direction_go(Evas_Object *obj,
2455                               int          x,
2456                               int          y)
2457 {
2458    EINA_SAFETY_ON_NULL_RETURN(obj);
2459    elm_widget_focus_direction_go(obj, x, y);
2460 }
2461
2462 /**
2463  * Get the enable status of the focus highlight
2464  *
2465  * This gets whether the highlight on focused objects is enabled or not
2466  * @ingroup Focus
2467  */
2468 EAPI Eina_Bool
2469 elm_focus_highlight_enabled_get(void)
2470 {
2471    return _elm_config->focus_highlight_enable;
2472 }
2473
2474 /**
2475  * Set the enable status of the focus highlight
2476  *
2477  * Set whether to show or not the highlight on focused objects
2478  * @param enable Enable highlight if EINA_TRUE, disable otherwise
2479  * @ingroup Focus
2480  */
2481 EAPI void
2482 elm_focus_highlight_enabled_set(Eina_Bool enable)
2483 {
2484    _elm_config->focus_highlight_enable = !!enable;
2485 }
2486
2487 /**
2488  * Get the enable status of the highlight animation
2489  *
2490  * Get whether the focus highlight, if enabled, will animate its switch from
2491  * one object to the next
2492  * @ingroup Focus
2493  */
2494 EAPI Eina_Bool
2495 elm_focus_highlight_animate_get(void)
2496 {
2497    return _elm_config->focus_highlight_animate;
2498 }
2499
2500 /**
2501  * Set the enable status of the highlight animation
2502  *
2503  * Set whether the focus highlight, if enabled, will animate its switch from
2504  * one object to the next
2505  * @param animate Enable animation if EINA_TRUE, disable otherwise
2506  * @ingroup Focus
2507  */
2508 EAPI void
2509 elm_focus_highlight_animate_set(Eina_Bool animate)
2510 {
2511    _elm_config->focus_highlight_animate = !!animate;
2512 }
2513
2514 /**
2515  * @defgroup Scrolling Scrolling
2516  * @ingroup Main
2517  *
2518  * These are functions setting how scrollable views in Elementary
2519  * widgets should behave on user interaction.
2520  */
2521
2522 /**
2523  * Get whether scrollers should bounce when they reach their
2524  * viewport's edge during a scroll.
2525  *
2526  * @return the thumb scroll bouncing state
2527  *
2528  * This is the default behavior for touch screens, in general.
2529  * @ingroup Scrolling
2530  */
2531 EAPI Eina_Bool
2532 elm_scroll_bounce_enabled_get(void)
2533 {
2534    return _elm_config->thumbscroll_bounce_enable;
2535 }
2536
2537 /**
2538  * Set whether scrollers should bounce when they reach their
2539  * viewport's edge during a scroll.
2540  *
2541  * @param enabled the thumb scroll bouncing state
2542  *
2543  * @see elm_thumbscroll_bounce_enabled_get()
2544  * @ingroup Scrolling
2545  */
2546 EAPI void
2547 elm_scroll_bounce_enabled_set(Eina_Bool enabled)
2548 {
2549    _elm_config->thumbscroll_bounce_enable = enabled;
2550 }
2551
2552 /**
2553  * Set whether scrollers should bounce when they reach their
2554  * viewport's edge during a scroll, for all Elementary application
2555  * windows.
2556  *
2557  * @param enabled the thumb scroll bouncing state
2558  *
2559  * @see elm_thumbscroll_bounce_enabled_get()
2560  * @ingroup Scrolling
2561  */
2562 EAPI void
2563 elm_scroll_bounce_enabled_all_set(Eina_Bool enabled)
2564 {
2565 #ifdef HAVE_ELEMENTARY_X
2566    static Ecore_X_Atom atom = 0;
2567    unsigned int bounce_enable_i = (unsigned int)enabled;
2568
2569    if (!atom)
2570      atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_BOUNCE_ENABLE");
2571    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2572                                   atom, &bounce_enable_i, 1);
2573 #endif
2574 }
2575
2576 /**
2577  * Get the amount of inertia a scroller will impose at bounce
2578  * animations.
2579  *
2580  * @return the thumb scroll bounce friction
2581  *
2582  * @ingroup Scrolling
2583  */
2584 EAPI double
2585 elm_scroll_bounce_friction_get(void)
2586 {
2587    return _elm_config->thumbscroll_bounce_friction;
2588 }
2589
2590 /**
2591  * Set the amount of inertia a scroller will impose at bounce
2592  * animations.
2593  *
2594  * @param friction the thumb scroll bounce friction
2595  *
2596  * @see elm_thumbscroll_bounce_friction_get()
2597  * @ingroup Scrolling
2598  */
2599 EAPI void
2600 elm_scroll_bounce_friction_set(double friction)
2601 {
2602    _elm_config->thumbscroll_bounce_friction = friction;
2603 }
2604
2605 /**
2606  * Set the amount of inertia a scroller will impose at bounce
2607  * animations, for all Elementary application windows.
2608  *
2609  * @param friction the thumb scroll bounce friction
2610  *
2611  * @see elm_thumbscroll_bounce_friction_get()
2612  * @ingroup Scrolling
2613  */
2614 EAPI void
2615 elm_scroll_bounce_friction_all_set(double friction)
2616 {
2617 #ifdef HAVE_ELEMENTARY_X
2618    static Ecore_X_Atom atom = 0;
2619    unsigned int bounce_friction_i = (unsigned int)(friction * 1000.0);
2620
2621    if (!atom)
2622      atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_BOUNCE_FRICTION");
2623    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2624                                   atom, &bounce_friction_i, 1);
2625 #endif
2626 }
2627
2628 /**
2629  * Get the amount of inertia a <b>paged</b> scroller will impose at
2630  * page fitting animations.
2631  *
2632  * @return the page scroll friction
2633  *
2634  * @ingroup Scrolling
2635  */
2636 EAPI double
2637 elm_scroll_page_scroll_friction_get(void)
2638 {
2639    return _elm_config->page_scroll_friction;
2640 }
2641
2642 /**
2643  * Set the amount of inertia a <b>paged</b> scroller will impose at
2644  * page fitting animations.
2645  *
2646  * @param friction the page scroll friction
2647  *
2648  * @see elm_thumbscroll_page_scroll_friction_get()
2649  * @ingroup Scrolling
2650  */
2651 EAPI void
2652 elm_scroll_page_scroll_friction_set(double friction)
2653 {
2654    _elm_config->page_scroll_friction = friction;
2655 }
2656
2657 /**
2658  * Set the amount of inertia a <b>paged</b> scroller will impose at
2659  * page fitting animations, for all Elementary application windows.
2660  *
2661  * @param friction the page scroll friction
2662  *
2663  * @see elm_thumbscroll_page_scroll_friction_get()
2664  * @ingroup Scrolling
2665  */
2666 EAPI void
2667 elm_scroll_page_scroll_friction_all_set(double friction)
2668 {
2669 #ifdef HAVE_ELEMENTARY_X
2670    static Ecore_X_Atom atom = 0;
2671    unsigned int page_scroll_friction_i = (unsigned int)(friction * 1000.0);
2672
2673    if (!atom)
2674      atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_PAGE_SCROLL_FRICTION");
2675    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2676                                   atom, &page_scroll_friction_i, 1);
2677 #endif
2678 }
2679
2680 /**
2681  * Get the amount of inertia a scroller will impose at region bring
2682  * animations.
2683  *
2684  * @return the bring in scroll friction
2685  *
2686  * @ingroup Scrolling
2687  */
2688 EAPI double
2689 elm_scroll_bring_in_scroll_friction_get(void)
2690 {
2691    return _elm_config->bring_in_scroll_friction;
2692 }
2693
2694 /**
2695  * Set the amount of inertia a scroller will impose at region bring
2696  * animations.
2697  *
2698  * @param friction the bring in scroll friction
2699  *
2700  * @see elm_thumbscroll_bring_in_scroll_friction_get()
2701  * @ingroup Scrolling
2702  */
2703 EAPI void
2704 elm_scroll_bring_in_scroll_friction_set(double friction)
2705 {
2706    _elm_config->bring_in_scroll_friction = friction;
2707 }
2708
2709 /**
2710  * Set the amount of inertia a scroller will impose at region bring
2711  * animations, for all Elementary application windows.
2712  *
2713  * @param friction the bring in scroll friction
2714  *
2715  * @see elm_thumbscroll_bring_in_scroll_friction_get()
2716  * @ingroup Scrolling
2717  */
2718 EAPI void
2719 elm_scroll_bring_in_scroll_friction_all_set(double friction)
2720 {
2721 #ifdef HAVE_ELEMENTARY_X
2722    static Ecore_X_Atom atom = 0;
2723    unsigned int bring_in_scroll_friction_i = (unsigned int)(friction * 1000.0);
2724
2725    if (!atom)
2726      atom =
2727        ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_BRING_IN_SCROLL_FRICTION");
2728    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2729                                   atom, &bring_in_scroll_friction_i, 1);
2730 #endif
2731 }
2732
2733 /**
2734  * Get the amount of inertia scrollers will impose at animations
2735  * triggered by Elementary widgets' zooming API.
2736  *
2737  * @return the zoom friction
2738  *
2739  * @ingroup Scrolling
2740  */
2741 EAPI double
2742 elm_scroll_zoom_friction_get(void)
2743 {
2744    return _elm_config->zoom_friction;
2745 }
2746
2747 /**
2748  * Set the amount of inertia scrollers will impose at animations
2749  * triggered by Elementary widgets' zooming API.
2750  *
2751  * @param friction the zoom friction
2752  *
2753  * @see elm_thumbscroll_zoom_friction_get()
2754  * @ingroup Scrolling
2755  */
2756 EAPI void
2757 elm_scroll_zoom_friction_set(double friction)
2758 {
2759    _elm_config->zoom_friction = friction;
2760 }
2761
2762 /**
2763  * Set the amount of inertia scrollers will impose at animations
2764  * triggered by Elementary widgets' zooming API, for all Elementary
2765  * application windows.
2766  *
2767  * @param friction the zoom friction
2768  *
2769  * @see elm_thumbscroll_zoom_friction_get()
2770  * @ingroup Scrolling
2771  */
2772 EAPI void
2773 elm_scroll_zoom_friction_all_set(double friction)
2774 {
2775 #ifdef HAVE_ELEMENTARY_X
2776    static Ecore_X_Atom atom = 0;
2777    unsigned int zoom_friction_i = (unsigned int)(friction * 1000.0);
2778
2779    if (!atom)
2780      atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_ZOOM_FRICTION");
2781    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2782                                   atom, &zoom_friction_i, 1);
2783 #endif
2784 }
2785
2786 /**
2787  * Get whether scrollers should be draggable from any point in their
2788  * views.
2789  *
2790  * @return the thumb scroll state
2791  *
2792  * @note This is the default behavior for touch screens, in general.
2793  * @note All other functions namespaced with "thumbscroll" will only
2794  *       have effect if this mode is enabled.
2795  *
2796  * @ingroup Scrolling
2797  */
2798 EAPI Eina_Bool
2799 elm_scroll_thumbscroll_enabled_get(void)
2800 {
2801    return _elm_config->thumbscroll_enable;
2802 }
2803
2804 /**
2805  * Set whether scrollers should be draggable from any point in their
2806  * views.
2807  *
2808  * @param enabled the thumb scroll state
2809  *
2810  * @see elm_thumbscroll_enabled_get()
2811  * @ingroup Scrolling
2812  */
2813 EAPI void
2814 elm_scroll_thumbscroll_enabled_set(Eina_Bool enabled)
2815 {
2816    _elm_config->thumbscroll_enable = enabled;
2817 }
2818
2819 /**
2820  * Set whether scrollers should be draggable from any point in their
2821  * views, for all Elementary application windows.
2822  *
2823  * @param enabled the thumb scroll state
2824  *
2825  * @see elm_thumbscroll_enabled_get()
2826  * @ingroup Scrolling
2827  */
2828 EAPI void
2829 elm_scroll_thumbscroll_enabled_all_set(Eina_Bool enabled)
2830 {
2831 #ifdef HAVE_ELEMENTARY_X
2832    static Ecore_X_Atom atom = 0;
2833    unsigned int ts_enable_i = (unsigned int)enabled;
2834
2835    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_ENABLE");
2836    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2837                                   atom, &ts_enable_i, 1);
2838 #endif
2839 }
2840
2841 /**
2842  * Get the number of pixels one should travel while dragging a
2843  * scroller's view to actually trigger scrolling.
2844  *
2845  * @return the thumb scroll threshould
2846  *
2847  * One would use higher values for touch screens, in general, because
2848  * of their inherent imprecision.
2849  * @ingroup Scrolling
2850  */
2851 EAPI unsigned int
2852 elm_scroll_thumbscroll_threshold_get(void)
2853 {
2854    return _elm_config->thumbscroll_threshold;
2855 }
2856
2857 /**
2858  * Set the number of pixels one should travel while dragging a
2859  * scroller's view to actually trigger scrolling.
2860  *
2861  * @param threshold the thumb scroll threshould
2862  *
2863  * @see elm_thumbscroll_threshould_get()
2864  * @ingroup Scrolling
2865  */
2866 EAPI void
2867 elm_scroll_thumbscroll_threshold_set(unsigned int threshold)
2868 {
2869    _elm_config->thumbscroll_threshold = threshold;
2870 }
2871
2872 /**
2873  * Set the number of pixels one should travel while dragging a
2874  * scroller's view to actually trigger scrolling, for all Elementary
2875  * application windows.
2876  *
2877  * @param threshold the thumb scroll threshould
2878  *
2879  * @see elm_thumbscroll_threshould_get()
2880  * @ingroup Scrolling
2881  */
2882 EAPI void
2883 elm_scroll_thumbscroll_threshold_all_set(unsigned int threshold)
2884 {
2885 #ifdef HAVE_ELEMENTARY_X
2886    static Ecore_X_Atom atom = 0;
2887    unsigned int ts_threshold_i = (unsigned int)threshold;
2888
2889    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_THRESHOLD");
2890    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2891                                   atom, &ts_threshold_i, 1);
2892 #endif
2893 }
2894
2895 /**
2896  * Get the minimum speed of mouse cursor movement which will trigger
2897  * list self scrolling animation after a mouse up event
2898  * (pixels/second).
2899  *
2900  * @return the thumb scroll momentum threshould
2901  *
2902  * @ingroup Scrolling
2903  */
2904 EAPI double
2905 elm_scroll_thumbscroll_momentum_threshold_get(void)
2906 {
2907    return _elm_config->thumbscroll_momentum_threshold;
2908 }
2909
2910 /**
2911  * Set the minimum speed of mouse cursor movement which will trigger
2912  * list self scrolling animation after a mouse up event
2913  * (pixels/second).
2914  *
2915  * @param threshold the thumb scroll momentum threshould
2916  *
2917  * @see elm_thumbscroll_momentum_threshould_get()
2918  * @ingroup Scrolling
2919  */
2920 EAPI void
2921 elm_scroll_thumbscroll_momentum_threshold_set(double threshold)
2922 {
2923    _elm_config->thumbscroll_momentum_threshold = threshold;
2924 }
2925
2926 /**
2927  * Set the minimum speed of mouse cursor movement which will trigger
2928  * list self scrolling animation after a mouse up event
2929  * (pixels/second), for all Elementary application windows.
2930  *
2931  * @param threshold the thumb scroll momentum threshould
2932  *
2933  * @see elm_thumbscroll_momentum_threshould_get()
2934  * @ingroup Scrolling
2935  */
2936 EAPI void
2937 elm_scroll_thumbscroll_momentum_threshold_all_set(double threshold)
2938 {
2939 #ifdef HAVE_ELEMENTARY_X
2940    static Ecore_X_Atom atom = 0;
2941    unsigned int ts_momentum_threshold_i = (unsigned int)(threshold * 1000.0);
2942
2943    if (!atom)
2944      atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_MOMENTUM_THRESHOLD");
2945    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2946                                   atom, &ts_momentum_threshold_i, 1);
2947 #endif
2948 }
2949
2950 /**
2951  * Get the amount of inertia a scroller will impose at self scrolling
2952  * animations.
2953  *
2954  * @return the thumb scroll friction
2955  *
2956  * @ingroup Scrolling
2957  */
2958 EAPI double
2959 elm_scroll_thumbscroll_friction_get(void)
2960 {
2961    return _elm_config->thumbscroll_friction;
2962 }
2963
2964 /**
2965  * Set the amount of inertia a scroller will impose at self scrolling
2966  * animations.
2967  *
2968  * @param friction the thumb scroll friction
2969  *
2970  * @see elm_thumbscroll_friction_get()
2971  * @ingroup Scrolling
2972  */
2973 EAPI void
2974 elm_scroll_thumbscroll_friction_set(double friction)
2975 {
2976    _elm_config->thumbscroll_friction = friction;
2977 }
2978
2979 /**
2980  * Set the amount of inertia a scroller will impose at self scrolling
2981  * animations, for all Elementary application windows.
2982  *
2983  * @param friction the thumb scroll friction
2984  *
2985  * @see elm_thumbscroll_friction_get()
2986  * @ingroup Scrolling
2987  */
2988 EAPI void
2989 elm_scroll_thumbscroll_friction_all_set(double friction)
2990 {
2991 #ifdef HAVE_ELEMENTARY_X
2992    static Ecore_X_Atom atom = 0;
2993    unsigned int ts_friction_i = (unsigned int)(friction * 1000.0);
2994
2995    if (!atom) atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_FRICTION");
2996    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
2997                                   atom, &ts_friction_i, 1);
2998 #endif
2999 }
3000
3001 /**
3002  * Get the amount of lag between your actual mouse cursor dragging
3003  * movement and a scroller's view movement itself, while pushing it
3004  * into bounce state manually.
3005  *
3006  * @return the thumb scroll border friction
3007  *
3008  * @ingroup Scrolling
3009  */
3010 EAPI double
3011 elm_scroll_thumbscroll_border_friction_get(void)
3012 {
3013    return _elm_config->thumbscroll_border_friction;
3014 }
3015
3016 /**
3017  * Set the amount of lag between your actual mouse cursor dragging
3018  * movement and a scroller's view movement itself, while pushing it
3019  * into bounce state manually.
3020  *
3021  * @param friction the thumb scroll border friction. @c 0.0 for
3022  *        perfect synchrony between two movements, @c 1.0 for maximum
3023  *        lag.
3024  *
3025  * @see elm_thumbscroll_border_friction_get()
3026  * @note parameter value will get bound to 0.0 - 1.0 interval, always
3027  *
3028  * @ingroup Scrolling
3029  */
3030 EAPI void
3031 elm_scroll_thumbscroll_border_friction_set(double friction)
3032 {
3033    if (friction < 0.0)
3034      friction = 0.0;
3035
3036    if (friction > 1.0)
3037      friction = 1.0;
3038
3039    _elm_config->thumbscroll_friction = friction;
3040 }
3041
3042 /**
3043  * Set the amount of lag between your actual mouse cursor dragging
3044  * movement and a scroller's view movement itself, while pushing it
3045  * into bounce state manually, for all Elementary application windows.
3046  *
3047  * @param friction the thumb scroll border friction. @c 0.0 for
3048  *        perfect synchrony between two movements, @c 1.0 for maximum
3049  *        lag.
3050  *
3051  * @see elm_thumbscroll_border_friction_get()
3052  * @note parameter value will get bound to 0.0 - 1.0 interval, always
3053  *
3054  * @ingroup Scrolling
3055  */
3056 EAPI void
3057 elm_scroll_thumbscroll_border_friction_all_set(double friction)
3058 {
3059    if (friction < 0.0)
3060      friction = 0.0;
3061
3062    if (friction > 1.0)
3063      friction = 1.0;
3064
3065 #ifdef HAVE_ELEMENTARY_X
3066    static Ecore_X_Atom atom = 0;
3067    unsigned int border_friction_i = (unsigned int)(friction * 1000.0);
3068
3069    if (!atom)
3070      atom = ecore_x_atom_get("ENLIGHTENMENT_THUMBSCROLL_BORDER_FRICTION");
3071    ecore_x_window_prop_card32_set(ecore_x_window_root_first_get(),
3072                                   atom, &border_friction_i, 1);
3073 #endif
3074 }
3075
3076 /**
3077  * @defgroup Scrollhints Scrollhints
3078  * @ingroup Main
3079  *
3080  * Objects when inside a scroller can scroll, but this may not always be
3081  * desirable in certain situations. This allows an object to hint to itself
3082  * and parents to "not scroll" in one of 2 ways.
3083  *
3084  * 1. To hold on scrolling. This means just flicking and dragging may no
3085  * longer scroll, but pressing/dragging near an edge of the scroller will
3086  * still scroll. This is automastically used by the entry object when
3087  * selecting text.
3088  * 2. To totally freeze scrolling. This means it stops. until popped/released.
3089  */
3090
3091 /**
3092  * Push the scroll hold by 1
3093  *
3094  * This increments the scroll hold count by one. If it is more than 0 it will
3095  * take effect on the parents of the indicated object.
3096  *
3097  * @param obj The object
3098  * @ingroup Scrollhints
3099  */
3100 EAPI void
3101 elm_object_scroll_hold_push(Evas_Object *obj)
3102 {
3103    EINA_SAFETY_ON_NULL_RETURN(obj);
3104    elm_widget_scroll_hold_push(obj);
3105 }
3106
3107 /**
3108  * Pop the scroll hold by 1
3109  *
3110  * This decrements the scroll hold count by one. If it is more than 0 it will
3111  * take effect on the parents of the indicated object.
3112  *
3113  * @param obj The object
3114  * @ingroup Scrollhints
3115  */
3116 EAPI void
3117 elm_object_scroll_hold_pop(Evas_Object *obj)
3118 {
3119    EINA_SAFETY_ON_NULL_RETURN(obj);
3120    elm_widget_scroll_hold_pop(obj);
3121 }
3122
3123 /**
3124  * Push the scroll freeze by 1
3125  *
3126  * This increments the scroll freeze count by one. If it is more than 0 it will
3127  * take effect on the parents of the indicated object.
3128  *
3129  * @param obj The object
3130  * @ingroup Scrollhints
3131  */
3132 EAPI void
3133 elm_object_scroll_freeze_push(Evas_Object *obj)
3134 {
3135    EINA_SAFETY_ON_NULL_RETURN(obj);
3136    elm_widget_scroll_freeze_push(obj);
3137 }
3138
3139 /**
3140  * Lock the scrolling of the given widget (and thus all parents)
3141  *
3142  * This locks the given object from scrolling in the X axis (and implicitly
3143  * also locks all parent scrollers too from doing the same).
3144  *
3145  * @param obj The object
3146  * @param lock The lock state (1 == locked, 0 == unlocked)
3147  * @ingroup Scrollhints
3148  */
3149 EAPI void
3150 elm_object_scroll_lock_x_set(Evas_Object *obj,
3151                              Eina_Bool    lock)
3152 {
3153    EINA_SAFETY_ON_NULL_RETURN(obj);
3154    elm_widget_drag_lock_x_set(obj, lock);
3155 }
3156
3157 /**
3158  * Lock the scrolling of the given widget (and thus all parents)
3159  *
3160  * This locks the given object from scrolling in the Y axis (and implicitly
3161  * also locks all parent scrollers too from doing the same).
3162  *
3163  * @param obj The object
3164  * @param lock The lock state (1 == locked, 0 == unlocked)
3165  * @ingroup Scrollhints
3166  */
3167 EAPI void
3168 elm_object_scroll_lock_y_set(Evas_Object *obj,
3169                              Eina_Bool    lock)
3170 {
3171    EINA_SAFETY_ON_NULL_RETURN(obj);
3172    elm_widget_drag_lock_y_set(obj, lock);
3173 }
3174
3175 /**
3176  * Get the scrolling lock of the given widget
3177  *
3178  * This gets the lock for X axis scrolling.
3179  *
3180  * @param obj The object
3181  * @ingroup Scrollhints
3182  */
3183 EAPI Eina_Bool
3184 elm_object_scroll_lock_x_get(const Evas_Object *obj)
3185 {
3186    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
3187    return elm_widget_drag_lock_x_get(obj);
3188 }
3189
3190 /**
3191  * Get the scrolling lock of the given widget
3192  *
3193  * This gets the lock for X axis scrolling.
3194  *
3195  * @param obj The object
3196  * @ingroup Scrollhints
3197  */
3198 EAPI Eina_Bool
3199 elm_object_scroll_lock_y_get(const Evas_Object *obj)
3200 {
3201    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
3202    return elm_widget_drag_lock_y_get(obj);
3203 }
3204
3205 /**
3206  * Pop the scroll freeze by 1
3207  *
3208  * This decrements the scroll freeze count by one. If it is more than 0 it will
3209  * take effect on the parents of the indicated object.
3210  *
3211  * @param obj The object
3212  * @ingroup Scrollhints
3213  */
3214 EAPI void
3215 elm_object_scroll_freeze_pop(Evas_Object *obj)
3216 {
3217    EINA_SAFETY_ON_NULL_RETURN(obj);
3218    elm_widget_scroll_freeze_pop(obj);
3219 }
3220
3221 /**
3222  * @defgroup WidgetNavigation Widget Tree Navigation.
3223  * @ingroup Main
3224  *
3225  * How to check if an Evas Object is an Elementary widget? How to get
3226  * the first elementary widget that is parent of the given object?
3227  * These are all covered in widget tree navigation.
3228  */
3229
3230 /**
3231  * Check if the given Evas Object is an Elementary widget.
3232  *
3233  * @param obj the object to query.
3234  * @return @c EINA_TRUE if it is an elementary widget variant,
3235  *         @c EINA_FALSE otherwise
3236  * @ingroup WidgetNavigation
3237  */
3238 EAPI Eina_Bool
3239 elm_object_widget_check(const Evas_Object *obj)
3240 {
3241    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
3242    return elm_widget_is(obj);
3243 }
3244
3245 /**
3246  * Get the first parent of the given object that is an Elementary widget.
3247  *
3248  * @param obj the object to query.
3249  * @return the parent object that is an Elementary widget, or @c NULL
3250  *         if no parent is, or no parents at all.
3251  * @ingroup WidgetNavigation
3252  */
3253 EAPI Evas_Object *
3254 elm_object_parent_widget_get(const Evas_Object *obj)
3255 {
3256    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
3257    return elm_widget_parent_widget_get(obj);
3258 }
3259
3260 /**
3261  * Get the top level parent of an Elementary widget.
3262  *
3263  * @param obj The object to query.
3264  * @return The top level Elementary widget, or @c NULL if parent cannot be
3265  * found.
3266  * @ingroup WidgetNavigation
3267  */
3268 EAPI Evas_Object *
3269 elm_object_top_widget_get(const Evas_Object *obj)
3270 {
3271    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
3272    return elm_widget_top_get(obj);
3273 }
3274
3275 /**
3276  * Get the string that represents this Elementary widget.
3277  *
3278  * @note Elementary is weird and exposes itself as a single
3279  *       Evas_Object_Smart_Class of type "elm_widget", so
3280  *       evas_object_type_get() always return that, making debug and
3281  *       language bindings hard. This function tries to mitigate this
3282  *       problem, but the solution is to change Elementary to use
3283  *       proper inheritance.
3284  *
3285  * @param obj the object to query.
3286  * @return Elementary widget name, or @c NULL if not a valid widget.
3287  * @ingroup WidgetNavigation
3288  */
3289 EAPI const char *
3290 elm_object_widget_type_get(const Evas_Object *obj)
3291 {
3292    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
3293    return elm_widget_type_get(obj);
3294 }
3295
3296 /**
3297  * Send a signal to the widget edje object.
3298  *
3299  * This function sends a signal to the edje object of the obj. An edje program
3300  * can respond to a signal by specifying matching 'signal' and
3301  * 'source' fields.
3302  *
3303  * @param obj The object
3304  * @param emission The signal's name.
3305  * @param source The signal's source.
3306  * @ingroup General
3307  */
3308 EAPI void
3309 elm_object_signal_emit(Evas_Object *obj,
3310                        const char  *emission,
3311                        const char  *source)
3312 {
3313    EINA_SAFETY_ON_NULL_RETURN(obj);
3314    elm_widget_signal_emit(obj, emission, source);
3315 }
3316
3317 /**
3318  * Add a callback for a signal emitted by widget edje object.
3319  *
3320  * This function connects a callback function to a signal emitted by the
3321  * edje object of the obj.
3322  * Globs can occur in either the emission or source name.
3323  *
3324  * @param obj The object
3325  * @param emission The signal's name.
3326  * @param source The signal's source.
3327  * @param func The callback function to be executed when the signal is
3328  * emitted.
3329  * @param data A pointer to data to pass in to the callback function.
3330  * @ingroup General
3331  */
3332 EAPI void 
3333 elm_object_signal_callback_add(Evas_Object *obj, const char *emission, const char *source, void (*func) (void *data, Evas_Object *o, const char *emission, const char *source), void *data)
3334 {
3335     EINA_SAFETY_ON_NULL_RETURN(obj);
3336     EINA_SAFETY_ON_NULL_RETURN(func);
3337     elm_widget_signal_callback_add(obj, emission, source, func, data);
3338 }
3339
3340 /**
3341  * Remove a signal-triggered callback from an widget edje object.
3342  *
3343  * This function removes a callback, previoulsy attached to a signal emitted
3344  * by the edje object of the obj.
3345  * The parameters emission, source and func must match exactly those passed to
3346  * a previous call to elm_object_signal_callback_add(). The data pointer that
3347  * was passed to this call will be returned.
3348  *
3349  * @param obj The object
3350  * @param emission The signal's name.
3351  * @param source The signal's source.
3352  * @param func The callback function to be executed when the signal is
3353  * emitted.
3354  * @return The data pointer
3355  * @ingroup General
3356  */
3357 EAPI void *
3358 elm_object_signal_callback_del(Evas_Object *obj, const char *emission, const char *source, void (*func) (void *data, Evas_Object *o, const char *emission, const char *source))
3359 {
3360     EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
3361     EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
3362     return elm_widget_signal_callback_del(obj, emission, source, func);
3363 }
3364
3365 /**
3366  * Add a callback for a event emitted by widget or their children.
3367  *
3368  * This function connects a callback function to any key_down key_up event
3369  * emitted by the @p obj or their children.
3370  * This only will be called if no other callback has consumed the event.
3371  * If you want consume the event, and no other get it, func should return
3372  * EINA_TRUE and put EVAS_EVENT_FLAG_ON_HOLD in event_flags.
3373  *
3374  * @warning Accept duplicated callback addition.
3375  *
3376  * @param obj The object
3377  * @param func The callback function to be executed when the event is
3378  * emitted.
3379  * @param data Data to pass in to the callback function.
3380  * @ingroup General
3381  */
3382 EAPI void
3383 elm_object_event_callback_add(Evas_Object *obj, Elm_Event_Cb func, const void *data)
3384 {
3385    EINA_SAFETY_ON_NULL_RETURN(obj);
3386    EINA_SAFETY_ON_NULL_RETURN(func);
3387    elm_widget_event_callback_add(obj, func, data);
3388 }
3389
3390 /**
3391  * Remove a event callback from an widget.
3392  *
3393  * This function removes a callback, previoulsy attached to event emission
3394  * by the @p obj.
3395  * The parameters func and data must match exactly those passed to
3396  * a previous call to elm_object_event_callback_add(). The data pointer that
3397  * was passed to this call will be returned.
3398  *
3399  * @param obj The object
3400  * @param func The callback function to be executed when the event is
3401  * emitted.
3402  * @param data Data to pass in to the callback function.
3403  * @return The data pointer
3404  * @ingroup General
3405  */
3406 EAPI void *
3407 elm_object_event_callback_del(Evas_Object *obj, Elm_Event_Cb func, const void *data)
3408 {
3409    EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
3410    EINA_SAFETY_ON_NULL_RETURN_VAL(func, NULL);
3411    return elm_widget_event_callback_del(obj, func, data);
3412 }
3413
3414
3415 /**
3416  * @defgroup Debug Debug
3417  * @ingroup Main
3418  */
3419
3420 /**
3421  * Print Tree object hierarchy in stdout
3422  *
3423  * @param obj The root object
3424  * @ingroup Debug
3425  */
3426 EAPI void
3427 elm_object_tree_dump(const Evas_Object *top)
3428 {
3429 #ifdef ELM_DEBUG
3430    elm_widget_tree_dump(top);
3431 #else
3432    return;
3433    (void)top;
3434 #endif
3435 }
3436
3437 /**
3438  * Print Elm Objects tree hierarchy in file as dot(graphviz) syntax.
3439  *
3440  * @param obj The root object
3441  * @param file The path of output file
3442  * @ingroup Debug
3443  */
3444 EAPI void
3445 elm_object_tree_dot_dump(const Evas_Object *top,
3446                          const char        *file)
3447 {
3448 #ifdef ELM_DEBUG
3449    FILE *f = fopen(file, "w");
3450    elm_widget_tree_dot_dump(top, f);
3451    fclose(f);
3452 #else
3453    return;
3454    (void)top;
3455    (void)file;
3456 #endif
3457 }
3458
3459 /**
3460  * Set the duration for occuring long press event.
3461  *
3462  * @param lonpress_timeout Timeout for long press event
3463  * @ingroup Longpress
3464  */
3465 EAPI void
3466 elm_longpress_timeout_set(double longpress_timeout)
3467 {
3468    _elm_config->longpress_timeout = longpress_timeout;
3469 }
3470
3471 /**
3472  * Get the duration for occuring long press event.
3473  *
3474  * @return Timeout for long press event
3475  * @ingroup Longpress
3476  */
3477 EAPI double
3478 elm_longpress_timeout_get(void)
3479 {
3480    return _elm_config->longpress_timeout;
3481 }