Enlightenment CVS committal
Author : moom
Project : e17
Module : libs/etk
Dir : e17/libs/etk/src/lib
Modified Files:
etk_filechooser_widget.c etk_image.c etk_theme.c etk_theme.h
etk_widget.c
Log Message:
* [Etk_Theme] Improve the API
* [Etk_Theme] Use default colors in etk_theme_color_get()
* [Etk_Theme] Get rid of the aliasing system since Edje can do that now
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_filechooser_widget.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- etk_filechooser_widget.c 16 Jan 2007 23:49:26 -0000 1.17
+++ etk_filechooser_widget.c 21 Mar 2007 18:15:26 -0000 1.18
@@ -176,7 +176,7 @@
strftime(mod_time_string, 128, "%x", mod_time2);
etk_tree_row_append(ETK_TREE(filechooser_widget->files_tree), NULL,
- filechooser_widget->files_name_col, etk_theme_icon_get(),
"places/folder_16", filename,
+ filechooser_widget->files_name_col, etk_theme_icon_path_get(),
"places/folder_16", filename,
filechooser_widget->files_date_col, mod_time_string, NULL);
}
@@ -214,7 +214,7 @@
strftime(mod_time_string, 128, "%x", mod_time2);
etk_tree_row_append(ETK_TREE(filechooser_widget->files_tree), NULL,
- filechooser_widget->files_name_col, etk_theme_icon_get(), icon ? icon
: "mimetypes/text-x-generic_16", filename,
+ filechooser_widget->files_name_col, etk_theme_icon_path_get(), icon ?
icon : "mimetypes/text-x-generic_16", filename,
filechooser_widget->files_date_col, mod_time_string, NULL);
}
@@ -541,18 +541,18 @@
etk_tree_freeze(ETK_TREE(fcw->places_tree));
row = etk_tree_row_append(ETK_TREE(fcw->places_tree), NULL,
- fcw->places_col, etk_theme_icon_get(), "actions/go-up_16", "..", NULL);
+ fcw->places_col, etk_theme_icon_path_get(), "actions/go-up_16", "..",
NULL);
etk_tree_row_data_set_full(row, strdup(".."), free);
if ((home = getenv("HOME")))
{
row = etk_tree_row_append(ETK_TREE(fcw->places_tree), NULL,
- fcw->places_col, etk_theme_icon_get(), "places/user-home_16",
_("Home"), NULL);
+ fcw->places_col, etk_theme_icon_path_get(), "places/user-home_16",
_("Home"), NULL);
etk_tree_row_data_set_full(row, strdup(home), free);
}
row = etk_tree_row_append(ETK_TREE(fcw->places_tree), NULL,
- fcw->places_col, etk_theme_icon_get(), "devices/computer_16", _("Root"),
NULL);
+ fcw->places_col, etk_theme_icon_path_get(), "devices/computer_16",
_("Root"), NULL);
etk_tree_row_data_set_full(row, strdup("/"), free);
/* Adds the mount points */
@@ -583,7 +583,7 @@
continue;
row = etk_tree_row_append(ETK_TREE(fcw->places_tree), NULL,
- fcw->places_col, etk_theme_icon_get(),
"devices/drive-harddisk_16", ecore_file_get_file(mount_point->mnt_dir), NULL);
+ fcw->places_col, etk_theme_icon_path_get(),
"devices/drive-harddisk_16", ecore_file_get_file(mount_point->mnt_dir), NULL);
etk_tree_row_data_set_full(row, strdup(mount_point->mnt_dir),
free);
}
endmntent(mtab);
@@ -617,7 +617,7 @@
continue;
row = etk_tree_row_append(ETK_TREE(fcw->places_tree), NULL,
- fcw->places_col, etk_theme_icon_get(),
"devices/drive-harddisk_16", ecore_file_get_file(mount_points[i].f_mntonname),
NULL);
+ fcw->places_col, etk_theme_icon_path_get(),
"devices/drive-harddisk_16", ecore_file_get_file(mount_points[i].f_mntonname),
NULL);
etk_tree_row_data_set_full(row, strdup(mount_points[i].f_mntonname),
free);
}
}
@@ -652,7 +652,7 @@
if (sscanf(line, "file://%s", fav) == 1)
{
row = etk_tree_row_append(ETK_TREE(fcw->fav_tree), NULL,
- fcw->fav_col, etk_theme_icon_get(), "places/folder_16",
ecore_file_get_file(fav), NULL);
+ fcw->fav_col, etk_theme_icon_path_get(), "places/folder_16",
ecore_file_get_file(fav), NULL);
etk_tree_row_data_set_full(row, strdup(fav), free);
}
}
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_image.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -3 -r1.30 -r1.31
--- etk_image.c 30 Dec 2006 14:42:00 -0000 1.30
+++ etk_image.c 21 Mar 2007 18:15:26 -0000 1.31
@@ -938,7 +938,7 @@
if (image->source == ETK_IMAGE_STOCK)
{
- file = etk_theme_icon_get();
+ file = etk_theme_icon_path_get();
key = etk_stock_key_get(image->info.stock.id,
image->info.stock.size);
}
else
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_theme.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -3 -r1.12 -r1.13
--- etk_theme.c 1 Feb 2007 19:14:52 -0000 1.12
+++ etk_theme.c 21 Mar 2007 18:15:26 -0000 1.13
@@ -3,60 +3,88 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <limits.h>
#include <Ecore_File.h>
#include <Edje.h>
#include "etk_widget.h"
#include "etk_config.h"
#include "config.h"
+/**
+ * @addtogroup Etk_Theme
+ * @{
+ */
+
static char *_etk_theme_find(const char *subdir, const char *file);
+static int _etk_theme_default_colors[ETK_COLOR_NUM_COLORS][4] =
+{
+ { 0, 0, 0, 255 },
+ { 255, 255, 255, 255 },
+ { 158, 158, 0, 255 },
+ { 255, 255, 255, 255 },
+ { 205, 0, 0, 255 },
+ { 255, 255, 255, 255 },
+ { 0, 0, 205, 255 },
+ { 255, 255, 255, 255 },
+ { 0, 140, 0, 255 },
+ { 255, 255, 255, 255 },
+ { 111, 79, 143, 255 },
+ { 255, 255, 255, 255 },
+ { 205, 0, 205, 255 },
+ { 255, 255, 255, 255 },
+ { 145, 87, 26, 255 },
+ { 255, 255, 255, 255 },
+ { 136, 136, 136, 255 },
+ { 255, 255, 255, 255 }
+};
+
+static char *_etk_theme_color_names[ETK_COLOR_NUM_COLORS] =
+{
+ "etk/color/foreground",
+ "etk/color/background",
+ "etk/color/important/fg",
+ "etk/color/important/bg",
+ "etk/color/warning/fg",
+ "etk/color/warning/bg",
+ "etk/color/info/fg",
+ "etk/color/info/bg",
+ "etk/color/default1/fg",
+ "etk/color/default1/bg",
+ "etk/color/default2/fg",
+ "etk/color/default2/bg",
+ "etk/color/default3/fg",
+ "etk/color/default3/bg",
+ "etk/color/default4/fg",
+ "etk/color/default4/bg",
+ "etk/color/default5/fg",
+ "etk/color/default5/bg"
+};
+
static char *_etk_theme_widget_default = NULL;
static char *_etk_theme_widget_current = NULL;
static char *_etk_theme_icon_default = NULL;
static char *_etk_theme_icon_current = NULL;
-static char *_etk_theme_colors[ETK_COLOR_NUM_COLORS];
/**
* @internal
- * @brief Initializes the themz system of Etk
+ * @brief Initializes the theme-system of Etk
*/
-void etk_theme_init()
+void etk_theme_init(void)
{
_etk_theme_widget_default = _etk_theme_find("themes", "default");
_etk_theme_icon_default = _etk_theme_find("icons", "default");
- etk_theme_widget_set(etk_config_widget_theme_get());
- etk_theme_icon_set("default");
-
- _etk_theme_colors[ETK_COLOR_FOREGROUND] = strdup("etk/color/foreground");
- _etk_theme_colors[ETK_COLOR_BACKGROUND] = strdup("etk/color/background");
- _etk_theme_colors[ETK_COLOR_IMPORTANT_FG] =
strdup("etk/color/important/fg");
- _etk_theme_colors[ETK_COLOR_IMPORTANT_BG] =
strdup("etk/color/important/bg");
- _etk_theme_colors[ETK_COLOR_WARNING_FG] = strdup("etk/color/warning/fg");
- _etk_theme_colors[ETK_COLOR_WARNING_BG] = strdup("etk/color/warning/bg");
- _etk_theme_colors[ETK_COLOR_INFO_FG] = strdup("etk/color/info/fg");
- _etk_theme_colors[ETK_COLOR_INFO_BG] = strdup("etk/color/info/bg");
- _etk_theme_colors[ETK_COLOR_DEFAULT1_FG] = strdup("etk/color/default1/fg");
- _etk_theme_colors[ETK_COLOR_DEFAULT1_BG] = strdup("etk/color/default1/bg");
- _etk_theme_colors[ETK_COLOR_DEFAULT2_FG] = strdup("etk/color/default2/fg");
- _etk_theme_colors[ETK_COLOR_DEFAULT2_BG] = strdup("etk/color/default2/bg");
- _etk_theme_colors[ETK_COLOR_DEFAULT3_FG] = strdup("etk/color/default3/fg");
- _etk_theme_colors[ETK_COLOR_DEFAULT3_BG] = strdup("etk/color/default3/bg");
- _etk_theme_colors[ETK_COLOR_DEFAULT4_FG] = strdup("etk/color/default4/fg");
- _etk_theme_colors[ETK_COLOR_DEFAULT4_BG] = strdup("etk/color/default4/bg");
- _etk_theme_colors[ETK_COLOR_DEFAULT5_FG] = strdup("etk/color/default5/fg");
- _etk_theme_colors[ETK_COLOR_DEFAULT5_BG] = strdup("etk/color/default5/bg");
+ etk_theme_widget_set_from_name(etk_config_widget_theme_get());
+ etk_theme_icon_set_from_name("default");
}
/**
* @internal
* @brief Shutdowns the theme system of Etk
*/
-void etk_theme_shutdown()
+void etk_theme_shutdown(void)
{
- int i;
-
free(_etk_theme_widget_default);
free(_etk_theme_widget_current);
free(_etk_theme_icon_default);
@@ -66,154 +94,252 @@
_etk_theme_widget_current = NULL;
_etk_theme_icon_default = NULL;
_etk_theme_icon_current = NULL;
+}
- for (i = 0; i < ETK_COLOR_NUM_COLORS; i++)
+/**
+ * @brief Sets the theme that will be used by new widgets, from its path
+ * @param theme_path the path of the widget-theme to use
+ * @return Returns ETK_TRUE if the theme has been found, or ETK_FALSE otherwise
+ */
+Etk_Bool etk_theme_widget_set_from_path(const char *theme_path)
+{
+ if (!theme_path)
+ return ETK_FALSE;
+
+ if (ecore_file_exists(theme_path))
{
- if (_etk_theme_colors[i])
- free(_etk_theme_colors[i]);
+ free(_etk_theme_widget_current);
+ _etk_theme_widget_current = strdup(theme_path);
+ return ETK_TRUE;
}
+ return ETK_FALSE;
+}
+
+/**
+ * @brief Sets the theme that will be used by new widgets, from its name
+ * @param theme_name the name of the widget-theme to use
+ * @return Returns ETK_TRUE if the theme has been found, or ETK_FALSE otherwise
+ */
+Etk_Bool etk_theme_widget_set_from_name(const char *theme_name)
+{
+ return etk_theme_widget_set_from_path(etk_theme_widget_find(theme_name));
}
/**
* @brief Gets the path of the current widget-theme file of Etk
* @return Returns the path of the current widget-theme file
*/
-const char *etk_theme_widget_get()
+const char *etk_theme_widget_path_get(void)
{
return _etk_theme_widget_current;
}
/**
- * @brief Sets the theme that will be used by new widgets
- * @param theme_name the name of the widget-theme to use
- * @return Returns ETK_TRUE if the theme has been found, or ETK_FALSE otherwise
+ * @brief Gets the name of the current widget-theme file of Etk
+ * @return Returns the name of the current widget-theme file, or NULL on
failure
+ * @note The returned path will have to be freed with free()
*/
-Etk_Bool etk_theme_widget_set(const char *theme_name)
+char *etk_theme_widget_name_get(void)
{
- char *path;
+ const char *start, *end;
+ char *name;
+ int len;
- if (!theme_name)
- return ETK_FALSE;
+ if (!_etk_theme_widget_current)
+ return NULL;
+
+ if (!(start = strrchr(_etk_theme_widget_current, '/')))
+ start = _etk_theme_widget_current;
+ else
+ start++;
- if ((path = _etk_theme_find("themes", theme_name)))
+ if ((end = strrchr(start, '.')))
{
- free(_etk_theme_widget_current);
- _etk_theme_widget_current = path;
- return ETK_TRUE;
+ len = end - start;
+ name = malloc(len + 1);
+ strncpy(name, start, len);
+ name[len] = '\0';
+ return name;
}
- return ETK_FALSE;
+
+ return NULL;
}
/**
- * @brief Gets the list of available widget-themes
- * @return Returns an Evas_List of available widget-themes.
- * The items of the list will have to be freed with free(), and the list will
have to be freed with evas_list_free()
+ * @brief Gets the list of the available widget-themes. The list contains the
names of the themes, not the paths
+ * @return Returns an Evas_List of the available widget-themes
+ * @note The returned list should be free with
etk_theme_available_themes_free()
*/
-Evas_List *etk_theme_widget_available_themes_get()
+Evas_List *etk_theme_widget_available_themes_get(void)
{
Ecore_List *files;
Evas_List *themes = NULL;
+ char path[2][PATH_MAX];
char *home;
- char *path;
char *file;
+ int i;
if ((home = getenv("HOME")))
+ snprintf(path[0], PATH_MAX, "%s/.e/etk/themes/", home);
+ else
+ path[0][0] = '\0';
+ snprintf(path[1], PATH_MAX, PACKAGE_DATA_DIR "/themes/");
+
+ for (i = 0; i < 2; i++)
{
- /* TODO: etk_config_dir_get? */
- path = malloc(strlen(home) + strlen("/.e/etk/themes/") + 1);
- sprintf(path, "%s/.e/etk/themes/", home);
- files = ecore_file_ls(path);
+ files = ecore_file_ls(path[i]);
if (files)
{
- ecore_list_goto_first(files);
- while ((file = ecore_list_next(files)))
- themes = evas_list_append(themes, ecore_file_strip_ext(file));
+ ecore_list_goto_first(files);
+ while ((file = ecore_list_next(files)))
+ themes = evas_list_append(themes, ecore_file_strip_ext(file));
ecore_list_destroy(files);
}
- free(path);
- }
-
- files = ecore_file_ls(PACKAGE_DATA_DIR "/themes/");
- if (files)
- {
- ecore_list_goto_first(files);
- while ((file = ecore_list_next(files)))
- themes = evas_list_append(themes, ecore_file_strip_ext(file));
- ecore_list_destroy(files);
}
return themes;
}
/**
- * @brief Gets the path of the current icon-theme file of Etk
- * @return Returns the path of the current icon-theme file
+ * @brief Finds the path of a widget-theme file, from its name
+ * @param theme_name the name of the theme to find
+ * @return Returns the path of the corresponding widget-theme file,
+ * or NULL if there is no corresponding theme
+ * @note The returned value will have to be freed with free()
*/
-const char *etk_theme_icon_get()
+char *etk_theme_widget_find(const char *theme_name)
{
- return _etk_theme_icon_current;
+ return _etk_theme_find("themes", theme_name);
}
/**
- * @brief Sets the theme that will be used by new icons
- * @param theme_name the name of the icon-theme to use
+ * @brief Sets the theme that will be used by new icons, from its path
+ * @param theme_path the path of the icon-theme to use
* @return Returns ETK_TRUE if the theme has been found, or ETK_FALSE otherwise
*/
-Etk_Bool etk_theme_icon_set(const char *theme_name)
+Etk_Bool etk_theme_icon_set_from_path(const char *theme_path)
{
- char *path;
-
- if (!theme_name)
+ if (!theme_path)
return ETK_FALSE;
- if ((path = _etk_theme_find("icons", theme_name)))
+ if (ecore_file_exists(theme_path))
{
free(_etk_theme_icon_current);
- _etk_theme_icon_current = path;
+ _etk_theme_icon_current = strdup(theme_path);
return ETK_TRUE;
}
return ETK_FALSE;
}
/**
- * @brief Gets the list of available icon-themes
- * @return Returns an Evas_List of available icon-themes.
- * The items of the list will have to be freed with free(), and the list will
have to be freed with evas_list_free()
+ * @brief Sets the theme that will be used by new icons, from its name
+ * @param theme_name the name of the icon-theme to use
+ * @return Returns ETK_TRUE if the theme has been found, or ETK_FALSE otherwise
+ */
+Etk_Bool etk_theme_icon_set_from_name(const char *theme_name)
+{
+ return etk_theme_icon_set_from_path(etk_theme_icon_find(theme_name));
+}
+
+/**
+ * @brief Gets the path of the current icon-theme file of Etk
+ * @return Returns the path of the current icon-theme file
+ */
+const char *etk_theme_icon_path_get(void)
+{
+ return _etk_theme_icon_current;
+}
+
+/**
+ * @brief Gets the name of the current icon-theme file of Etk
+ * @return Returns the name of the current icon-theme file, or NULL on failure
+ * @note The returned path will have to be freed with free()
+ */
+char *etk_theme_icon_name_get(void)
+{
+ const char *start, *end;
+ char *name;
+ int len;
+
+ if (!_etk_theme_icon_current)
+ return NULL;
+
+ if (!(start = strrchr(_etk_theme_icon_current, '/')))
+ start = _etk_theme_icon_current;
+ else
+ start++;
+
+ if ((end = strrchr(start, '.')))
+ {
+ len = end - start;
+ name = malloc(len + 1);
+ strncpy(name, start, len);
+ name[len] = '\0';
+ return name;
+ }
+
+ return NULL;
+}
+
+/**
+ * @brief Gets the list of the available icon-themes. The list contains the
names of the themes, not the paths
+ * @return Returns an Evas_List of the available icon-themes
+ * @note The returned list should be free with
etk_theme_available_themes_free()
*/
-Evas_List *etk_theme_icon_available_themes_get()
+Evas_List *etk_theme_icon_available_themes_get(void)
{
Ecore_List *files;
Evas_List *themes = NULL;
+ char path[2][PATH_MAX];
char *home;
- char *path;
char *file;
+ int i;
if ((home = getenv("HOME")))
+ snprintf(path[0], PATH_MAX, "%s/.e/etk/icons/", home);
+ else
+ path[0][0] = '\0';
+ snprintf(path[1], PATH_MAX, PACKAGE_DATA_DIR "/icons/");
+
+ for (i = 0; i < 2; i++)
{
- /* TODO: etk_config_dir_get? */
- path = malloc(strlen(home) + strlen("/.e/etk/icons/") + 1);
- sprintf(path, "%s/.e/etk/icons/", home);
- files = ecore_file_ls(path);
+ files = ecore_file_ls(path[i]);
if (files)
{
- ecore_list_goto_first(files);
- while ((file = ecore_list_next(files)))
- themes = evas_list_append(themes, ecore_file_strip_ext(file));
+ ecore_list_goto_first(files);
+ while ((file = ecore_list_next(files)))
+ themes = evas_list_append(themes, ecore_file_strip_ext(file));
ecore_list_destroy(files);
}
- free(path);
}
- files = ecore_file_ls(PACKAGE_DATA_DIR "/icons/");
- if (files)
+ return themes;
+}
+
+/**
+ * @brief Finds the path of a icon-theme file, from its name
+ * @param theme_name the name of the theme to find
+ * @return Returns the path of the corresponding icon-theme file,
+ * or NULL if there is no corresponding theme
+ * @note The returned value will have to be freed with free()
+ */
+char *etk_theme_icon_find(const char *theme_name)
+{
+ return _etk_theme_find("icons", theme_name);
+}
+
+/**
+ * @brief A function used to free the list returned by
etk_theme_widget_available_themes_get() or
+ * etk_theme_icon_available_themes_get()
+ * @param themes the list of themes to free
+ */
+void etk_theme_available_themes_free(Evas_List *themes)
+{
+ while (themes)
{
- ecore_list_goto_first(files);
- while ((file = ecore_list_next(files)))
- themes = evas_list_append(themes, ecore_file_strip_ext(file));
- ecore_list_destroy(files);
+ free(themes->data);
+ themes = evas_list_remove_list(themes, themes);
}
-
- return themes;
}
/**
@@ -226,47 +352,19 @@
*/
Etk_Bool etk_theme_group_exists(const char *file, const char *group, const
char *parent_group)
{
- char *full_group;
+ char full_group[PATH_MAX];
if (!file)
file = _etk_theme_widget_current ? _etk_theme_widget_current :
_etk_theme_widget_default;
- if (!group || *group == '\0' || !file)
+ if (!group || group[0] == '\0' || !file)
return ETK_FALSE;
- if (parent_group && *parent_group)
- {
- full_group = malloc(strlen("etk//") + strlen(parent_group) +
strlen(group) + 1);
- sprintf(full_group, "etk/%s/%s", parent_group, group);
- }
+ if (parent_group && parent_group[0] != '\0')
+ snprintf(full_group, PATH_MAX, "etk/%s/%s", parent_group, group);
else
- {
- full_group = malloc(strlen("etk/") + strlen(group) + 1);
- sprintf(full_group, "etk/%s", group);
- }
+ snprintf(full_group, PATH_MAX, "etk/%s", group);
- /* Checks if the theme-group exists */
- if (edje_file_group_exists(file, full_group))
- {
- free(full_group);
- return ETK_TRUE;
- }
- else
- {
- char *alias;
- char *alt_group;
- int ret;
-
- alias = malloc(strlen("alias: ") + strlen(full_group) + 1);
- sprintf(alias, "alias: %s", full_group);
- alt_group = edje_file_data_get(file, alias);
- free(full_group);
- free(alias);
-
- ret = edje_file_group_exists(file, alt_group);
- free(alt_group);
-
- return ret;
- }
+ return edje_file_group_exists(file, full_group);
}
/**
@@ -280,58 +378,30 @@
*/
Etk_Bool etk_theme_edje_object_set(Evas_Object *object, const char *file,
const char *group, const char *parent_group)
{
- char *full_group;
+ char full_group[PATH_MAX];
if (!object)
return ETK_FALSE;
if (!file)
file = _etk_theme_widget_current ? _etk_theme_widget_current :
_etk_theme_widget_default;
- if (!group || *group == '\0' || !file)
+ if (!group || group[0] == '\0' || !file)
{
edje_object_file_set(object, NULL, NULL);
return ETK_FALSE;
}
- if (parent_group && *parent_group)
- {
- full_group = malloc(strlen("etk//") + strlen(parent_group) +
strlen(group) + 1);
- sprintf(full_group, "etk/%s/%s", parent_group, group);
- }
+ if (parent_group && parent_group[0] != '\0')
+ snprintf(full_group, PATH_MAX, "etk/%s/%s", parent_group, group);
else
- {
- full_group = malloc(strlen("etk/") + strlen(group) + 1);
- sprintf(full_group, "etk/%s", group);
- }
+ snprintf(full_group, PATH_MAX, "etk/%s", group);
- /* Load the object */
if (edje_object_file_set(object, file, full_group))
- {
- free(full_group);
return ETK_TRUE;
- }
else
{
- char *alias;
- char *alt_group;
- int ret;
-
- alias = malloc(strlen("alias: ") + strlen(full_group) + 1);
- sprintf(alias, "alias: %s", full_group);
- alt_group = edje_file_data_get(file, alias);
- free(full_group);
- free(alias);
-
- ret = edje_object_file_set(object, file, alt_group);
- free(alt_group);
-
- if (ret)
- return ETK_TRUE;
- else
- {
- edje_object_file_set(object, NULL, NULL);
- return ETK_FALSE;
- }
+ edje_object_file_set(object, NULL, NULL);
+ return ETK_FALSE;
}
}
@@ -347,31 +417,51 @@
{
if (!object)
return ETK_FALSE;
- return etk_theme_edje_object_set(object, etk_widget_theme_file_get(parent),
group, etk_widget_theme_group_get(parent));
+
+ return etk_theme_edje_object_set(object, etk_widget_theme_file_get(parent),
+ group, etk_widget_theme_group_get(parent));
}
/**
- * @brief Gets the color type from the theme-file.
- * @param color_type an Etk_Color_Type
- * @return Returns an Etk_Color with the color filled from the theme-file, or
color with -1 if it wasn't found
+ * @brief Gets the components of the given color. The color depends on the
theme used
+ * @param file the path to the theme-file where to find the given color. If @a
file is NULL,
+ * the current widget-theme file will be used
+ * @param color_type the color whose components will be returned
+ * @param r the location where to store the 'red' component of the color
+ * @param g the location where to store the 'green' component of the color
+ * @param b the location where to store the 'blue' component of the color
+ * @param a the location where to store the 'alpha' component of the color
+ * @return Returns ETK_TRUE if the color has been found, ETK_FALSE otherwise
+ * @note Note that even if the color has not been found (because it is not
defined in the theme),
+ * the components will still be set to their default values, so the color will
still be usable
*/
-Etk_Color etk_theme_color_get(Etk_Color_Type color_type)
+Etk_Bool etk_theme_color_get(const char *file, Etk_Color_Type color_type, int
*r, int *g, int *b, int *a)
{
- Etk_Color color;
- const char *file;
char *color_string;
- file = _etk_theme_widget_current ? _etk_theme_widget_current :
_etk_theme_widget_default;
- color_string = edje_file_data_get(file, _etk_theme_colors[color_type]);
- if (!color_string || sscanf(color_string, "%d %d %d %d", &color.r,
&color.g, &color.b, &color.a) != 4)
+ if (!file)
+ file = _etk_theme_widget_current ? _etk_theme_widget_current :
_etk_theme_widget_default;
+ if (color_type < 0 || color_type >= ETK_COLOR_NUM_COLORS)
+ color_type = ETK_COLOR_FOREGROUND;
+
+ if (file)
{
- Etk_Color color = { .r = -1, .g = -1, .b = -1, .a = -1 };
- if (color_string) free(color_string);
- return color;
+ color_string = edje_file_data_get(file,
_etk_theme_color_names[color_type]);
+ if (color_string && sscanf(color_string, "%d %d %d %d", r, g, b, a) == 4)
+ {
+ free(color_string);
+ return ETK_TRUE;
+ }
+ free(color_string);
}
-
- if (color_string) free(color_string);
- return color;
+
+ /* The color has not been found, we set it to its default value */
+ if (r) *r = _etk_theme_default_colors[color_type][0];
+ if (g) *g = _etk_theme_default_colors[color_type][1];
+ if (b) *b = _etk_theme_default_colors[color_type][2];
+ if (a) *a = _etk_theme_default_colors[color_type][3];
+
+ return ETK_FALSE;
}
/**************************
@@ -383,28 +473,36 @@
/* Finds the theme called "theme_name" in the subdir "subdir" and returns its
path, or NULL on failure */
static char *_etk_theme_find(const char *subdir, const char *theme_name)
{
+ char path[PATH_MAX];
char *home;
- char *path;
if (!theme_name || !subdir)
return ETK_FALSE;
if ((home = getenv("HOME")))
{
- /* TODO: etk_config_dir_get? */
- path = malloc(strlen(home) + strlen(subdir) + strlen("/.e/etk//.edj") +
strlen(theme_name) + 1);
- sprintf(path, "%s/.e/etk/%s/%s.edj", home, subdir, theme_name);
+ snprintf(path, PATH_MAX, "%s/.e/etk/%s/%s.edj", home, subdir,
theme_name);
if (ecore_file_exists(path))
- return path;
- else
- free(path);
+ return strdup(path);
}
- path = malloc(strlen(subdir) + strlen(PACKAGE_DATA_DIR"//.edj") +
strlen(theme_name) + 1);
- sprintf(path, PACKAGE_DATA_DIR"/%s/%s.edj", subdir, theme_name);
+ snprintf(path, PATH_MAX, PACKAGE_DATA_DIR"/%s/%s.edj", subdir, theme_name);
if (ecore_file_exists(path))
- return path;
+ return strdup(path);
- free(path);
return NULL;
}
+
+/** @} */
+
+/**************************
+ *
+ * Documentation
+ *
+ **************************/
+
+/**
+ * @addtogroup Etk_Theme
+ *
+ * TODOC
+ */
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_theme.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- etk_theme.h 1 Feb 2007 19:14:52 -0000 1.6
+++ etk_theme.h 21 Mar 2007 18:15:26 -0000 1.7
@@ -2,15 +2,20 @@
#ifndef _ETK_THEME_H_
#define _ETK_THEME_H_
+#include <Evas.h>
+#include "etk_types.h"
+
+/* TODO/FIXME list:
+ * - Use etk_config_dir_get() to get the dirs where the themes should be
looked for
+ * - Better default colors?
+ */
+
/**
* @defgroup Etk_Theme The theme system of Etk
* @brief The theme system of Etk
* @{
*/
-#include <Evas.h>
-#include "etk_types.h"
-
/** @brief The different types of colors */
typedef enum Etk_Color_Type
{
@@ -20,8 +25,8 @@
ETK_COLOR_IMPORTANT_BG, /**< Background color to express importance
*/
ETK_COLOR_WARNING_FG, /**< Foreground color to express warning */
ETK_COLOR_WARNING_BG, /**< Background color to express warning */
- ETK_COLOR_INFO_FG, /**< Foreground color to show informative
areas */
- ETK_COLOR_INFO_BG, /**< Background color to show informative
areas */
+ ETK_COLOR_INFO_FG, /**< Foreground color to show informative
areas */
+ ETK_COLOR_INFO_BG, /**< Background color to show informative
areas */
ETK_COLOR_DEFAULT1_FG, /**< Default foreground color 1 */
ETK_COLOR_DEFAULT1_BG, /**< Default background color 1 */
ETK_COLOR_DEFAULT2_FG, /**< Default foreground color 2 */
@@ -35,22 +40,31 @@
ETK_COLOR_NUM_COLORS
} Etk_Color_Type;
-void etk_theme_init();
-void etk_theme_shutdown();
-const char *etk_theme_widget_get();
-Etk_Bool etk_theme_widget_set(const char *theme_name);
-Evas_List *etk_theme_widget_available_themes_get();
-
-const char *etk_theme_icon_get();
-Etk_Bool etk_theme_icon_set(const char *theme_name);
-Evas_List *etk_theme_icon_available_themes_get();
+void etk_theme_init(void);
+void etk_theme_shutdown(void);
+
+Etk_Bool etk_theme_widget_set_from_path(const char *theme_path);
+Etk_Bool etk_theme_widget_set_from_name(const char *theme_name);
+const char *etk_theme_widget_path_get(void);
+char *etk_theme_widget_name_get(void);
+Evas_List *etk_theme_widget_available_themes_get(void);
+char *etk_theme_widget_find(const char *theme_name);
+
+Etk_Bool etk_theme_icon_set_from_path(const char *theme_path);
+Etk_Bool etk_theme_icon_set_from_name(const char *theme_name);
+const char *etk_theme_icon_path_get(void);
+char *etk_theme_icon_name_get(void);
+Evas_List *etk_theme_icon_available_themes_get(void);
+char *etk_theme_icon_find(const char *theme_name);
+
+void etk_theme_available_themes_free(Evas_List *themes);
Etk_Bool etk_theme_group_exists(const char *file, const char *group, const
char *parent_group);
Etk_Bool etk_theme_edje_object_set(Evas_Object *object, const char *file,
const char *group, const char *parent_group);
Etk_Bool etk_theme_edje_object_set_from_parent(Evas_Object *object, const char
*group, Etk_Widget *parent);
-Etk_Color etk_theme_color_get(Etk_Color_Type color_type);
+Etk_Bool etk_theme_color_get(const char *file, Etk_Color_Type color_type, int
*r, int *g, int *b, int *a);
/** @} */
===================================================================
RCS file: /cvs/e/e17/libs/etk/src/lib/etk_widget.c,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -3 -r1.103 -r1.104
--- etk_widget.c 18 Mar 2007 20:44:47 -0000 1.103
+++ etk_widget.c 21 Mar 2007 18:15:26 -0000 1.104
@@ -500,8 +500,8 @@
* @brief Gets the full theme-group of the widget
* @param widget a widget
* @return Returns the full theme-group of the widget
- * @note The returned value may be different from the theme-group set with
etk_widget_theme_group_set(): if
- * @a widget has a theme-parent, this will be taken into account. For example,
if @a widget is a row, and
+ * @note The returned value may be different from the theme-group set with
etk_widget_theme_group_set() because
+ * if @a widget has a theme-parent, it will be taken into account. For
example, if @a widget is a row, and
* the theme-parent of the widget is a tree, the returned value will be
"tree/row", and not just "row". @n
* To get the value set with etk_widget_theme_group_set(), you can use
* etk_object_properties_get(ETK_OBJECT(widget), "theme_group", &theme_group);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
enlightenment-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs