1. box has clear.
authorCarsten Haitzler <raster@rasterman.com>
Fri, 11 Sep 2009 13:43:02 +0000 (13:43 +0000)
committerCarsten Haitzler <raster@rasterman.com>
Fri, 11 Sep 2009 13:43:02 +0000 (13:43 +0000)
2. photocam widget++

SVN revision: 42405

src/bin/Makefile.am
src/bin/test.c
src/bin/test_photocam.c [new file with mode: 0644]
src/lib/Elementary.h.in
src/lib/Makefile.am
src/lib/elm_box.c
src/lib/elm_genlist.c
src/lib/elm_photocam.c [new file with mode: 0644]
src/lib/els_box.c
src/lib/els_box.h

index dfb3c54..7d3be9a 100644 (file)
@@ -56,7 +56,8 @@ test_fileselector.c \
 test_separator.c \
 test_scroller.c \
 test_spinner.c \
-test_index.c
+test_index.c \
+test_photocam.c
 elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la
 elementary_test_LDFLAGS =
 
index 3490cc1..f6c4dcf 100644 (file)
@@ -47,6 +47,7 @@ void test_separator(void *data, Evas_Object *obj, void *event_info);
 void test_scroller(void *data, Evas_Object *obj, void *event_info);
 void test_spinner(void *data, Evas_Object *obj, void *event_info);
 void test_index(void *data, Evas_Object *obj, void *event_info);
+void test_photocam(void *data, Evas_Object *obj, void *event_info);
 
 static void
 my_win_del(void *data, Evas_Object *obj, void *event_info)
@@ -175,6 +176,7 @@ my_win_main(void)
    elm_list_item_append(li, "Scroller", NULL, NULL, test_scroller, NULL);
    elm_list_item_append(li, "Spinner", NULL, NULL, test_spinner, NULL);
    elm_list_item_append(li, "Index", NULL, NULL, test_index, NULL);
+   elm_list_item_append(li, "Photocam", NULL, NULL, test_photocam, NULL);
 
    elm_list_go(li);
 
diff --git a/src/bin/test_photocam.c b/src/bin/test_photocam.c
new file mode 100644 (file)
index 0000000..ad2f23d
--- /dev/null
@@ -0,0 +1,34 @@
+#include <Elementary.h>
+
+void
+test_photocam(void *data, Evas_Object *obj, void *event_info)
+{
+   Evas_Object *win, *bg, *ph;
+   char buf[PATH_MAX];
+   const char *img[3] =
+     {
+        "/home/raster/t1.jpg", 
+        "/home/raster/t2.jpg", 
+        "/home/raster/t3.jpg"
+     };
+
+   win = elm_win_add(NULL, "photo", ELM_WIN_BASIC);
+   elm_win_title_set(win, "Photo");
+   elm_win_autodel_set(win, 1);
+
+   bg = elm_bg_add(win);
+   evas_object_size_hint_weight_set(bg, 1.0, 1.0);
+   elm_win_resize_object_add(win, bg);
+   evas_object_show(bg);
+
+   ph = elm_photocam_add(win);
+   evas_object_size_hint_weight_set(ph, 1.0, 1.0);
+   elm_win_resize_object_add(win, ph);
+   
+   elm_photocam_file_set(ph, img[1]);
+   
+   evas_object_show(ph);
+   
+   evas_object_resize(win, 800, 800);
+   evas_object_show(win);
+}
index b99125a..a1df040 100644 (file)
@@ -288,6 +288,7 @@ extern "C" {
    EAPI void         elm_box_pack_end(Evas_Object *obj, Evas_Object *subobj);
    EAPI void         elm_box_pack_before(Evas_Object *obj, Evas_Object *subobj, Evas_Object *before);
    EAPI void         elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after);
+   EAPI void         elm_box_clear(Evas_Object *obj);
    /* smart callbacks called:
     */
 
@@ -823,6 +824,9 @@ extern "C" {
    EAPI void         elm_index_item_clear(Evas_Object *obj);
    EAPI void         elm_index_item_go(Evas_Object *obj, int level);
    /* smart callbacks called:
+    * "changed" - when the selected index item changes
+    * "delay,changed" - when the selected index item changes, but after some small idle period
+    * "selected" - when the user releases heir finger and selects an item
     */
    
 #ifdef __cplusplus
index 3dcdeb3..a69660a 100644 (file)
@@ -58,6 +58,7 @@ elm_progressbar.c \
 elm_separator.c \
 elm_spinner.c \
 elm_index.c \
+elm_photocam.c \
 \
 elc_notepad.c \
 elc_anchorview.c \
index 5400297..eedc6b3 100644 (file)
@@ -222,3 +222,19 @@ elm_box_pack_after(Evas_Object *obj, Evas_Object *subobj, Evas_Object *after)
    elm_widget_sub_object_add(obj, subobj);
    _els_smart_box_pack_after(wd->box, subobj, after);
 }
+
+/**
+ * This clears the box items
+ *
+ * This delete all members of the box object, but not the box itself.
+ *
+ * @param obj The box object
+ *
+ * @ingroup Box
+ */
+EAPI void
+elm_box_clear(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   _els_smart_box_clear(wd->box);
+}
index 0eae85a..7702722 100644 (file)
@@ -258,8 +258,6 @@ struct _Widget_Data
    Elm_List_Mode mode;
    Eina_Bool on_hold : 1;
    Eina_Bool multi : 1;
-   Eina_Bool min_w : 1;
-   Eina_Bool min_h : 1;
    Eina_Bool always_select : 1;
    Eina_Bool longpressed : 1;
    Eina_Bool wasselected : 1;
@@ -343,6 +341,7 @@ _del_hook(Evas_Object *obj)
    elm_genlist_clear(obj);
    evas_object_del(wd->pan_smart);
    wd->pan_smart = NULL;
+   if (wd->calc_job) ecore_job_del(wd->calc_job);
    free(wd);
 }
 
diff --git a/src/lib/elm_photocam.c b/src/lib/elm_photocam.c
new file mode 100644 (file)
index 0000000..fce4057
--- /dev/null
@@ -0,0 +1,376 @@
+#include <Elementary.h>
+#include "elm_priv.h"
+
+/**
+ * @defgroup Photocam Photocam
+ *
+ * XXX
+ *
+ * Signals that you can add callbacks for are:
+ *
+ * clicked - This is called when a user has double-clicked an item. The
+ * event_info parameter is the genlist item that was double-clicked.
+ *
+ */
+typedef struct _Widget_Data Widget_Data;
+typedef struct _Pan Pan;
+
+struct _Widget_Data
+{
+   Evas_Object *obj;
+   Evas_Object *scr;
+   Evas_Object *img[2];
+   Evas_Object *pan_smart;
+   Pan *pan;
+   Ecore_Job *calc_job;
+   int ph_w, ph_h;
+   Evas_Coord pan_x, pan_y, minw, minh;
+   int scale;
+   int imuse;
+   const char *file;
+};
+
+struct _Pan
+{
+   Evas_Object_Smart_Clipped_Data __clipped_data;
+   Widget_Data *wd;
+};
+
+static void _del_hook(Evas_Object *obj);
+static void _theme_hook(Evas_Object *obj);
+static void _show_region_hook(void *data, Evas_Object *obj);
+static void _sizing_eval(Evas_Object *obj);
+
+static void _calc_job(void *data);
+
+static Evas_Smart_Class _pan_sc = {NULL};
+
+static void
+_del_hook(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   evas_object_del(wd->pan_smart);
+   wd->pan_smart = NULL;
+   if (wd->file) eina_stringshare_del(wd->file);
+   if (wd->calc_job) ecore_job_del(wd->calc_job);
+   free(wd);
+}
+
+static void
+_theme_hook(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   elm_smart_scroller_theme_set(wd->scr, "scroller", "base", elm_widget_style_get(obj));
+   edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
+   _sizing_eval(obj);
+}
+
+static void
+_show_region_hook(void *data, Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(data);
+   Evas_Coord x, y, w, h;
+   elm_widget_show_region_get(obj, &x, &y, &w, &h);
+   elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
+}
+
+static void
+_sizing_eval(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
+
+   evas_object_size_hint_min_get(wd->scr, &minw, &minh);
+   evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
+   minw = -1;
+   minh = -1;
+//   if (wd->mode != ELM_LIST_LIMIT) minw = -1;
+   evas_object_size_hint_min_set(obj, minw, minh);
+   evas_object_size_hint_max_set(obj, maxw, maxh);
+}
+
+static void
+_calc_job(void *data)
+{
+   Widget_Data *wd = data;
+   Evas_Coord minw, minh;
+
+   minw = wd->ph_w;
+   minh = wd->ph_h;
+   
+   if ((minw != wd->minw) || (minh != wd->minh))
+     {
+        wd->minw = minw;
+        wd->minh = minh;
+        evas_object_size_hint_min_set(wd->pan_smart, wd->minw, wd->minh);
+        evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
+        _sizing_eval(wd->obj);
+     }
+   wd->calc_job = NULL;
+   evas_object_smart_changed(wd->pan_smart);
+}
+
+static void
+_pan_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
+{
+   Pan *sd = evas_object_smart_data_get(obj);
+   if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
+   sd->wd->pan_x = x;
+   sd->wd->pan_y = y;
+   evas_object_smart_changed(obj);
+}
+
+static void
+_pan_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
+{
+   Pan *sd = evas_object_smart_data_get(obj);
+   if (x) *x = sd->wd->pan_x;
+   if (y) *y = sd->wd->pan_y;
+}
+
+static void
+_pan_max_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
+{
+   Pan *sd = evas_object_smart_data_get(obj);
+   Evas_Coord ow, oh;
+   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
+   ow = sd->wd->minw - ow;
+   if (ow < 0) ow = 0;
+   oh = sd->wd->minh - oh;
+   if (oh < 0) oh = 0;
+   if (x) *x = ow;
+   if (y) *y = oh;
+}
+
+static void
+_pan_child_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
+{
+   Pan *sd = evas_object_smart_data_get(obj);
+   if (w) *w = sd->wd->minw;
+   if (h) *h = sd->wd->minh;
+}
+
+static void
+_pan_add(Evas_Object *obj)
+{
+   Pan *sd;
+   Evas_Object_Smart_Clipped_Data *cd;
+
+   _pan_sc.add(obj);
+   cd = evas_object_smart_data_get(obj);
+   sd = calloc(1, sizeof(Pan));
+   if (!sd) return;
+   sd->__clipped_data = *cd;
+   free(cd);
+   evas_object_smart_data_set(obj, sd);
+}
+
+static void
+_pan_del(Evas_Object *obj)
+{
+   Pan *sd = evas_object_smart_data_get(obj);
+   if (!sd) return;
+   _pan_sc.del(obj);
+}
+
+static void
+_pan_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
+{
+   Pan *sd = evas_object_smart_data_get(obj);
+   Evas_Coord ow, oh;
+   evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
+   if ((ow == w) && (oh == h)) return;
+   if (sd->wd->calc_job) ecore_job_del(sd->wd->calc_job);
+   sd->wd->calc_job = ecore_job_add(_calc_job, sd->wd);
+}
+
+static void
+_pan_calculate(Evas_Object *obj)
+{
+   Pan *sd = evas_object_smart_data_get(obj);
+   Evas_Coord ox, oy, ow, oh;
+
+   evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
+   evas_object_move(sd->wd->img[0], 
+                    ox + 0 - sd->wd->pan_x,
+                    oy + 0 - sd->wd->pan_y);
+   evas_object_resize(sd->wd->img[0], sd->wd->minw, sd->wd->minh);
+   evas_object_move(sd->wd->img[1], 
+                    ox + 0 - sd->wd->pan_x,
+                    oy + 0 - sd->wd->pan_y);
+   evas_object_resize(sd->wd->img[1], sd->wd->minw, sd->wd->minh);
+}
+
+static void
+_hold_on(void *data, Evas_Object *obj, void *event_info)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   elm_smart_scroller_hold_set(wd->scr, 1);
+}
+
+static void
+_hold_off(void *data, Evas_Object *obj, void *event_info)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   elm_smart_scroller_hold_set(wd->scr, 0);
+}
+
+static void
+_freeze_on(void *data, Evas_Object *obj, void *event_info)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   elm_smart_scroller_freeze_set(wd->scr, 1);
+}
+
+static void
+_freeze_off(void *data, Evas_Object *obj, void *event_info)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   elm_smart_scroller_freeze_set(wd->scr, 0);
+}
+
+static void
+_preloaded(void *data, Evas *e, Evas_Object *o, void *event_info)
+{
+   Evas_Object *obj = data;
+   Widget_Data *wd = elm_widget_data_get(obj);
+   int w, h;
+   
+   printf("scale: %i use %i\n", wd->scale, wd->imuse);
+   evas_object_show(wd->img[wd->imuse]);
+   if (wd->scale == 1) return;
+   
+   wd->imuse = 1 - wd->imuse;
+   wd->scale /= 2;
+   evas_object_hide(wd->img[wd->imuse]);
+   evas_object_image_load_scale_down_set(wd->img[wd->imuse], wd->scale);
+   evas_object_image_pixels_dirty_set(wd->img[wd->imuse], 1);
+   evas_object_image_file_set(wd->img[wd->imuse], wd->file, NULL);
+   evas_object_image_preload(wd->img[wd->imuse], 0);
+   evas_object_image_size_get(wd->img[wd->imuse], &w, &h);
+   wd->ph_w = w * wd->scale;
+   wd->ph_h = h * wd->scale;
+   if (wd->calc_job) ecore_job_del(wd->calc_job);
+   wd->calc_job = ecore_job_add(_calc_job, wd);
+}
+   
+/**
+ * Add a new Photocam object
+ *
+ * @param parent The parent object
+ * @return The new object or NULL if it cannot be created
+ *
+ * @ingroup Photocam
+ */
+EAPI Evas_Object *
+elm_photocam_add(Evas_Object *parent)
+{
+   Evas_Object *obj;
+   Evas *e;
+   Widget_Data *wd;
+   Evas_Coord minw, minh;
+   static Evas_Smart *smart = NULL;
+   int i;
+
+   wd = ELM_NEW(Widget_Data);
+   e = evas_object_evas_get(parent);
+   obj = elm_widget_add(e);
+   elm_widget_type_set(obj, "genlist");
+   elm_widget_sub_object_add(parent, obj);
+   elm_widget_data_set(obj, wd);
+   elm_widget_del_hook_set(obj, _del_hook);
+   elm_widget_theme_hook_set(obj, _theme_hook);
+
+   wd->scr = elm_smart_scroller_add(e);
+   elm_widget_resize_object_set(obj, wd->scr);
+
+   elm_smart_scroller_bounce_allow_set(wd->scr, 1, 1);
+
+   wd->obj = obj;
+
+   evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
+   evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
+   evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
+   evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
+   
+   if (!smart)
+     {
+       static Evas_Smart_Class sc;
+
+       evas_object_smart_clipped_smart_set(&_pan_sc);
+       sc = _pan_sc;
+       sc.name = "elm_photocam_pan";
+       sc.version = EVAS_SMART_CLASS_VERSION;
+       sc.add = _pan_add;
+       sc.del = _pan_del;
+       sc.resize = _pan_resize;
+       sc.calculate = _pan_calculate;
+       smart = evas_smart_class_new(&sc);
+     }
+   if (smart)
+     {
+       wd->pan_smart = evas_object_smart_add(e, smart);
+       wd->pan = evas_object_smart_data_get(wd->pan_smart);
+       wd->pan->wd = wd;
+     }
+
+   elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
+                                    _pan_set, _pan_get,
+                                    _pan_max_get, _pan_child_size_get);
+   for (i = 0; i < 2; i++)
+     {
+        wd->img[i] = evas_object_image_add(e);
+        evas_object_smart_member_add(wd->img[i], wd->pan_smart);
+        elm_widget_sub_object_add(obj, wd->img[i]);
+        evas_object_image_filled_set(wd->img[i], 1);
+        evas_object_event_callback_add(wd->img[i], EVAS_CALLBACK_IMAGE_PRELOADED,
+                                       _preloaded, obj);
+        evas_object_show(wd->img[i]);
+     }
+   
+   edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr), 
+                             &minw, &minh);
+   evas_object_size_hint_min_set(obj, minw, minh);
+
+   _sizing_eval(obj);
+   return obj;
+}
+
+/**
+ * XXX
+ *
+ * xxx
+ *
+ * @param obj The photocam object
+ * @param file The photo file
+ *
+ * @ingroup Photocam
+ */
+EAPI Elm_Genlist_Item *
+elm_photocam_file_set(Evas_Object *obj, const char *file)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   int w, h;
+
+   if (wd->file) eina_stringshare_del(wd->file);
+//   evas_object_image_preload(wd->img[0], 1);
+//   evas_object_image_preload(wd->img[1], 1);
+   evas_object_hide(wd->img[0]);
+   evas_object_hide(wd->img[1]);
+   
+   wd->file = eina_stringshare_add(file);
+   wd->scale = 8;
+   wd->imuse = 0;
+   evas_object_image_load_scale_down_set(wd->img[wd->imuse], wd->scale);
+   evas_object_image_file_set(wd->img[wd->imuse], wd->file, NULL);
+   evas_object_image_preload(wd->img[wd->imuse], 0);
+   evas_object_image_size_get(wd->img[wd->imuse], &w, &h);
+   wd->ph_w = w * wd->scale;
+   wd->ph_h = h * wd->scale;
+   if (wd->calc_job) ecore_job_del(wd->calc_job);
+   wd->calc_job = ecore_job_add(_calc_job, wd);
+}
index f2c1791..b230082 100644 (file)
@@ -170,6 +170,20 @@ _els_smart_box_unpack(Evas_Object *obj)
      }
 }
 
+void
+_els_smart_box_clear(Evas_Object *obj)
+{
+   Smart_Data *sd;
+
+   sd = evas_object_smart_data_get(obj);
+   if (!sd) return;
+   while (sd->items)
+     {
+       Evas_Object *child = sd->items->data;
+        evas_object_del(child);
+     }
+}
+
 /* local subsystem functions */
 static void
 _smart_adopt(Smart_Data *sd, Evas_Object *obj)
index 1fde225..a488de7 100644 (file)
@@ -7,3 +7,4 @@ int          _els_smart_box_pack_end          (Evas_Object *obj, Evas_Object *ch
 int          _els_smart_box_pack_before       (Evas_Object *obj, Evas_Object *child, Evas_Object *before);
 int          _els_smart_box_pack_after        (Evas_Object *obj, Evas_Object *child, Evas_Object *after);
 void         _els_smart_box_unpack            (Evas_Object *obj);
+void         _els_smart_box_clear             (Evas_Object *obj);