+elm_icon_memfile_set
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 22 Jul 2011 23:03:46 +0000 (23:03 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 22 Jul 2011 23:03:46 +0000 (23:03 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@61603 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/Elementary.h.in
src/lib/elm_icon.c
src/lib/els_icon.c
src/lib/els_icon.h

index ef7c2e2..1bfc43a 100644 (file)
@@ -1956,6 +1956,23 @@ extern "C" {
     */
    EAPI Eina_Bool             elm_icon_file_set(Evas_Object *obj, const char *file, const char *group) EINA_ARG_NONNULL(1, 2);
    /**
+    * Set a location in memory to be used as an icon
+    *
+    * @param obj The icon object
+    * @param img The binary data that will be used as an image
+    * @param size The size of binary data @p img
+    * @param format Optional format of @p img to pass to the image loader
+    * @param key Optional key of @p img to pass to the image loader (eg. if @p img is an edje file)
+    *
+    * @return (@c EINA_TRUE = success, @c EINA_FALSE = error)
+    *
+    * @note The icon image set by this function can be changed by
+    * elm_icon_standard_set().
+    *
+    * @ingroup Icon
+    */
+   EAPI Eina_Bool             elm_icon_memfile_set(Evas_Object *obj, const void *img, size_t size, const char *format, const char *key);  EINA_ARG_NONNULL(1, 2);
+   /**
     * Get the file that will be used as icon.
     *
     * @param obj The icon object
index cd7edab..f70473c 100644 (file)
@@ -472,6 +472,23 @@ elm_icon_add(Evas_Object *parent)
 }
 
 EAPI Eina_Bool
+elm_icon_memfile_set(Evas_Object *obj, const void *img, size_t size, const char *format, const char *key)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Eina_Bool ret;
+
+   if (!wd) return EINA_FALSE;
+   EINA_SAFETY_ON_NULL_RETURN_VAL(img, EINA_FALSE);
+   EINA_SAFETY_ON_TRUE_RETURN_VAL(!size, EINA_FALSE);
+   eina_stringshare_del(wd->stdicon);
+   wd->stdicon = NULL;
+   ret = _els_smart_icon_memfile_set(wd->img, img, size, format, key);
+   _sizing_eval(obj);
+   return ret;
+}
+
+EAPI Eina_Bool
 elm_icon_file_set(Evas_Object *obj, const char *file, const char *group)
 {
    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
index 3b089db..6119a37 100644 (file)
@@ -65,14 +65,13 @@ _preloaded(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event __UNUSE
    sd->prev = NULL;
 }
 
-Eina_Bool
-_els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
+static void
+_els_smart_icon_file_helper(Evas_Object *obj)
 {
    Smart_Data *sd;
    Evas_Object *pclip;
 
    sd = evas_object_smart_data_get(obj);
-   if (!sd) return EINA_FALSE;
    /* smart code here */
    if (sd->prev) evas_object_del(sd->prev);
    pclip = evas_object_clip_get(sd->obj);
@@ -89,6 +88,40 @@ _els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key
 
    if (!sd->size)
      evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
+}
+
+Eina_Bool
+_els_smart_icon_memfile_set(Evas_Object *obj, const void *img, size_t size, const char *format, const char *key)
+{
+   Smart_Data *sd;
+
+   sd = evas_object_smart_data_get(obj);
+   if (!sd) return EINA_FALSE;
+   _els_smart_icon_file_helper(obj);
+
+   evas_object_image_memfile_set(sd->obj, (void*)img, size, (char*)format, (char*)key);
+   sd->preloading = EINA_TRUE;
+   sd->show = EINA_TRUE;
+   evas_object_hide(sd->obj);
+   evas_object_image_preload(sd->obj, EINA_FALSE);
+   if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
+     {
+        ERR("Things are going bad for some random %zu byte chunk of memory (%p)", size, sd->obj);
+        return EINA_FALSE;
+     }
+   _smart_reconfigure(sd);
+   return EINA_TRUE;
+}
+
+Eina_Bool
+_els_smart_icon_file_key_set(Evas_Object *obj, const char *file, const char *key)
+{
+   Smart_Data *sd;
+
+   sd = evas_object_smart_data_get(obj);
+   if (!sd) return EINA_FALSE;
+   _els_smart_icon_file_helper(obj);
+
    evas_object_image_file_set(sd->obj, file, key);
    sd->preloading = EINA_TRUE;
    sd->show = EINA_TRUE;
index bd49bb2..2d1cce2 100644 (file)
@@ -1,4 +1,5 @@
 Evas_Object *_els_smart_icon_add              (Evas *evas);
+Eina_Bool    _els_smart_icon_memfile_set      (Evas_Object *obj, const void *file, size_t size, const char *format, const char *key);
 Eina_Bool    _els_smart_icon_file_key_set     (Evas_Object *obj, const char *file, const char *key);
 Eina_Bool    _els_smart_icon_file_edje_set    (Evas_Object *obj, const char *file, const char *part);
 void         _els_smart_icon_file_get         (const Evas_Object *obj, const char **file, const char **key);