Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_genscroller.c
1 #include <Elementary.h>
2 #include <Elementary_Cursor.h>
3 #include "elm_priv.h"
4
5 /**
6  * @defgroup Genscroller Genscroller
7  *
8  */
9
10 typedef struct _Widget_Data Widget_Data;
11 typedef struct _Pan         Pan;
12
13 struct _Widget_Data
14 {
15    Evas_Object      *obj, *scr, *pan_smart;
16    Pan              *pan;
17    Evas_Coord        pan_x, pan_y, minw, minh;
18    
19    struct {
20       int w, h;
21       Evas_Coord total_w, total_h;
22    } cells;
23 };
24
25 struct _Pan
26 {
27    Evas_Object_Smart_Clipped_Data __clipped_data;
28    Widget_Data                   *wd;
29 };
30
31 static const char *widtype = NULL;
32 static void      _del_hook(Evas_Object *obj);
33 static void      _mirrored_set(Evas_Object *obj,
34                                Eina_Bool    rtl);
35 static void      _theme_hook(Evas_Object *obj);
36 static void      _show_region_hook(void        *data,
37                                    Evas_Object *obj);
38 static void      _sizing_eval(Evas_Object *obj);
39 static void      _on_focus_hook(void        *data,
40                                 Evas_Object *obj);
41 static Eina_Bool _event_hook(Evas_Object       *obj,
42                              Evas_Object       *src,
43                              Evas_Callback_Type type,
44                              void              *event_info);
45 static void      _signal_emit_hook(Evas_Object *obj,
46                                    const char *emission,
47                                    const char *source);
48 static void      _pan_calculate(Evas_Object *obj);
49
50 static Evas_Smart_Class _pan_sc = EVAS_SMART_CLASS_INIT_VERSION;
51
52 static const char SIG_SCROLL_EDGE_TOP[] = "scroll,edge,top";
53 static const char SIG_SCROLL_EDGE_BOTTOM[] = "scroll,edge,bottom";
54 static const char SIG_SCROLL_EDGE_LEFT[] = "scroll,edge,left";
55 static const char SIG_SCROLL_EDGE_RIGHT[] = "scroll,edge,right";
56
57 static const Evas_Smart_Cb_Description _signals[] = {
58       {SIG_SCROLL_EDGE_TOP, ""},
59       {SIG_SCROLL_EDGE_BOTTOM, ""},
60       {SIG_SCROLL_EDGE_LEFT, ""},
61       {SIG_SCROLL_EDGE_RIGHT, ""},
62       {NULL, NULL}
63 };
64
65 static Eina_Bool
66 _event_hook(Evas_Object       *obj,
67             Evas_Object       *src __UNUSED__,
68             Evas_Callback_Type type,
69             void              *event_info)
70 {
71    if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
72    Evas_Event_Key_Down *ev = event_info;
73    Widget_Data *wd = elm_widget_data_get(obj);
74    if (!wd) return EINA_FALSE;
75    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
76    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
77
78    Evas_Coord x = 0;
79    Evas_Coord y = 0;
80    Evas_Coord step_x = 0;
81    Evas_Coord step_y = 0;
82    Evas_Coord v_w = 0;
83    Evas_Coord v_h = 0;
84    Evas_Coord page_x = 0;
85    Evas_Coord page_y = 0;
86
87    elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
88    elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
89    elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
90    elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
91
92    if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
93      {
94         x -= step_x;
95      }
96    else if ((!strcmp(ev->keyname, "Right")) ||
97             (!strcmp(ev->keyname, "KP_Right")))
98      {
99         x += step_x;
100      }
101    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
102      {
103         y -= step_y;
104      }
105    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
106      {
107         y += step_y;
108      }
109    else return EINA_FALSE;
110
111    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
112    elm_smart_scroller_child_pos_set(wd->scr, x, y);
113    return EINA_TRUE;
114 }
115
116 static void
117 _on_focus_hook(void        *data __UNUSED__,
118                Evas_Object *obj)
119 {
120    Widget_Data *wd = elm_widget_data_get(obj);
121    if (!wd) return;
122    if (elm_widget_focus_get(obj))
123      {
124         elm_object_signal_emit(wd->obj, "elm,action,focus", "elm");
125         evas_object_focus_set(wd->obj, EINA_TRUE);
126      }
127    else
128      {
129         elm_object_signal_emit(wd->obj, "elm,action,unfocus", "elm");
130         evas_object_focus_set(wd->obj, EINA_FALSE);
131      }
132 }
133
134 static void
135 _del_hook(Evas_Object *obj)
136 {
137    Widget_Data *wd = elm_widget_data_get(obj);
138    if (!wd) return;
139    free(wd);
140 }
141
142 static void
143 _del_pre_hook(Evas_Object *obj)
144 {
145    Widget_Data *wd = elm_widget_data_get(obj);
146    if (!wd) return;
147    evas_object_del(wd->pan_smart);
148    wd->pan_smart = NULL;
149 }
150
151 static void
152 _mirrored_set(Evas_Object *obj,
153               Eina_Bool    rtl)
154 {
155    Widget_Data *wd = elm_widget_data_get(obj);
156    if (!wd) return;
157    elm_smart_scroller_mirrored_set(wd->scr, rtl);
158 }
159
160 static void
161 _theme_hook(Evas_Object *obj)
162 {
163    Widget_Data *wd = elm_widget_data_get(obj);
164    if (!wd) return;
165    evas_event_freeze(evas_object_evas_get(wd->obj));
166    _elm_widget_mirrored_reload(obj);
167    _mirrored_set(obj, elm_widget_mirrored_get(obj));
168    elm_smart_scroller_object_theme_set(obj, wd->scr, "genscroller", "base",
169                                        elm_widget_style_get(obj));
170    edje_object_scale_set(wd->scr, elm_widget_scale_get(obj) * _elm_config->scale);
171    _sizing_eval(obj);
172    evas_event_thaw(evas_object_evas_get(wd->obj));
173    evas_event_thaw_eval(evas_object_evas_get(wd->obj));
174 }
175
176 static void
177 _show_region_hook(void        *data,
178                   Evas_Object *obj)
179 {
180    Widget_Data *wd = elm_widget_data_get(data);
181    Evas_Coord x, y, w, h;
182    if (!wd) return;
183    elm_widget_show_region_get(obj, &x, &y, &w, &h);
184    //x & y are screen coordinates, Add with pan coordinates
185    x += wd->pan_x;
186    y += wd->pan_y;
187    elm_smart_scroller_child_region_show(wd->scr, x, y, w, h);
188 }
189
190 static void
191 _sizing_eval(Evas_Object *obj)
192 {
193    Widget_Data *wd = elm_widget_data_get(obj);
194    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
195    Evas_Coord vmw, vmh;
196    if (!wd) return;
197    evas_object_size_hint_min_get(wd->scr, &minw, &minh);
198    evas_object_size_hint_max_get(wd->scr, &maxw, &maxh);
199    edje_object_size_min_calc
200       (elm_smart_scroller_edje_object_get(wd->scr), &vmw, &vmh);
201    minw = vmw;
202    minh = vmh;
203    evas_object_size_hint_min_set(obj, minw, minh);
204    evas_object_size_hint_max_set(obj, maxw, maxh);
205 }
206
207 static void
208 _signal_emit_hook(Evas_Object *obj,
209                   const char  *emission,
210                   const char  *source)
211 {
212    Widget_Data *wd = elm_widget_data_get(obj);
213    edje_object_signal_emit(elm_smart_scroller_edje_object_get(wd->scr),
214                            emission, source);
215 }
216
217 static void
218 _pan_set(Evas_Object *obj,
219          Evas_Coord   x,
220          Evas_Coord   y)
221 {
222    Pan *sd = evas_object_smart_data_get(obj);
223
224    if ((x == sd->wd->pan_x) && (y == sd->wd->pan_y)) return;
225    sd->wd->pan_x = x;
226    sd->wd->pan_y = y;
227    // FIXME: pan virtual scroll pos set
228    printf("PAN SET: %i %i\n", x, y);
229 }
230
231 static void
232 _pan_get(Evas_Object *obj,
233          Evas_Coord  *x,
234          Evas_Coord  *y)
235 {
236    Pan *sd = evas_object_smart_data_get(obj);
237
238    if (x) *x = sd->wd->pan_x;
239    if (y) *y = sd->wd->pan_y;
240 }
241
242 static void
243 _pan_max_get(Evas_Object *obj,
244              Evas_Coord  *x,
245              Evas_Coord  *y)
246 {
247    Pan *sd = evas_object_smart_data_get(obj);
248    Evas_Coord ow, oh;
249
250    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
251    ow = sd->wd->minw - ow;
252    if (ow < 0) ow = 0;
253    oh = sd->wd->minh - oh;
254    if (oh < 0) oh = 0;
255    if (x) *x = ow;
256    if (y) *y = oh;
257 }
258
259 static void
260 _pan_min_get(Evas_Object *obj __UNUSED__,
261              Evas_Coord  *x,
262              Evas_Coord  *y)
263 {
264    if (x) *x = 0;
265    if (y) *y = 0;
266 }
267
268 static void
269 _pan_child_size_get(Evas_Object *obj,
270                     Evas_Coord  *w,
271                     Evas_Coord  *h)
272 {
273    Pan *sd = evas_object_smart_data_get(obj);
274
275    if (w) *w = sd->wd->minw;
276    if (h) *h = sd->wd->minh;
277 }
278
279 static void
280 _pan_add(Evas_Object *obj)
281 {
282    Pan *sd;
283    Evas_Object_Smart_Clipped_Data *cd;
284
285    _pan_sc.add(obj);
286    cd = evas_object_smart_data_get(obj);
287    sd = ELM_NEW(Pan);
288    if (!sd) return;
289    sd->__clipped_data = *cd;
290    free(cd);
291    evas_object_smart_data_set(obj, sd);
292 }
293
294 static void
295 _pan_del(Evas_Object *obj)
296 {
297    Pan *sd = evas_object_smart_data_get(obj);
298
299    if (!sd) return;
300    _pan_sc.del(obj);
301 }
302
303 static void
304 _pan_resize(Evas_Object *obj,
305             Evas_Coord   w,
306             Evas_Coord   h)
307 {
308 //   Pan *sd = evas_object_smart_data_get(obj);
309    Evas_Coord ow, oh;
310
311    evas_object_geometry_get(obj, NULL, NULL, &ow, &oh);
312    if ((ow == w) && (oh == h)) return;
313    // FIXME: pan resized
314    printf("PAN SIZE: %i %i\n", w, h);
315 }
316
317 static void
318 _pan_calculate(Evas_Object *obj)
319 {
320 //   Pan *sd = evas_object_smart_data_get(obj);
321    Evas_Coord ox, oy, ow, oh, cvx, cvy, cvw, cvh;
322
323    evas_event_freeze(evas_object_evas_get(obj));
324    evas_object_geometry_get(obj, &ox, &oy, &ow, &oh);
325    evas_output_viewport_get(evas_object_evas_get(obj), &cvx, &cvy, &cvw, &cvh);
326    // FIXME: move/resize/show/realize/unrealize stuff
327    printf("PAN CALC\n");
328    evas_event_thaw(evas_object_evas_get(obj));
329    evas_event_thaw_eval(evas_object_evas_get(obj));
330 }
331
332 static void
333 _pan_move(Evas_Object *obj __UNUSED__,
334           Evas_Coord   x,
335           Evas_Coord   y)
336 {
337 //   Pan *sd = evas_object_smart_data_get(obj);
338    // FIXME: pan moved
339    printf("PAN MOVE: %i %i\n", x, y);
340 }
341
342 static void
343 _hold_on(void        *data __UNUSED__,
344          Evas_Object *obj,
345          void        *event_info __UNUSED__)
346 {
347    Widget_Data *wd = elm_widget_data_get(obj);
348    if (!wd) return;
349    elm_smart_scroller_hold_set(wd->scr, 1);
350 }
351
352 static void
353 _hold_off(void        *data __UNUSED__,
354           Evas_Object *obj,
355           void        *event_info __UNUSED__)
356 {
357    Widget_Data *wd = elm_widget_data_get(obj);
358    if (!wd) return;
359    elm_smart_scroller_hold_set(wd->scr, 0);
360 }
361
362 static void
363 _freeze_on(void        *data __UNUSED__,
364            Evas_Object *obj,
365            void        *event_info __UNUSED__)
366 {
367    Widget_Data *wd = elm_widget_data_get(obj);
368    if (!wd) return;
369    elm_smart_scroller_freeze_set(wd->scr, 1);
370 }
371
372 static void
373 _freeze_off(void        *data __UNUSED__,
374             Evas_Object *obj,
375             void        *event_info __UNUSED__)
376 {
377    Widget_Data *wd = elm_widget_data_get(obj);
378    if (!wd) return;
379    elm_smart_scroller_freeze_set(wd->scr, 0);
380 }
381
382 static void
383 _scroll_edge_left(void        *data,
384                   Evas_Object *scr __UNUSED__,
385                   void        *event_info __UNUSED__)
386 {
387    Evas_Object *obj = data;
388    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_LEFT, NULL);
389 }
390
391 static void
392 _scroll_edge_right(void        *data,
393                    Evas_Object *scr __UNUSED__,
394                    void        *event_info __UNUSED__)
395 {
396    Evas_Object *obj = data;
397    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_RIGHT, NULL);
398 }
399
400 static void
401 _scroll_edge_top(void        *data,
402                  Evas_Object *scr __UNUSED__,
403                  void        *event_info __UNUSED__)
404 {
405    Evas_Object *obj = data;
406    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_TOP, NULL);
407 }
408
409 static void
410 _scroll_edge_bottom(void        *data,
411                     Evas_Object *scr __UNUSED__,
412                     void        *event_info __UNUSED__)
413 {
414    Evas_Object *obj = data;
415    evas_object_smart_callback_call(obj, SIG_SCROLL_EDGE_BOTTOM, NULL);
416 }
417
418 /****************************************************************************/
419
420 typedef struct _Cell Cell;
421 typedef struct _Span Span;
422
423 struct _Span
424 {
425    Span       *parent;
426    Evas_Coord  pos; // position RELATIVE to parent (geom)
427    Evas_Coord  size; // size of whole set of children (geom)
428    int         total_child_count; // total number of children in all sub trees
429    int         child_count; // number of children in children array
430    Span      **child; // child array (ordered)
431 };
432
433 /*
434  *       ^ PARENT SPAN
435  *       |
436  *     SPAN
437  *     / | \
438  *    /  |  \
439  *   /   |   \
440  *  /    |    \
441  * SPAN SPAN SPAN ... N SPAN CHILDREN
442
443  *
444  * +-SPAN-SPAN-SPAN-SPAN-SPAN-SPAN
445  * |
446  * S +--+ +--+ +--+ +--+ +--+ +--+
447  * P |  | |  | |  | |  | |  | |  |<- Cell
448  * A |  | |  | |  | |  | |  | |  |
449  * N +--+ +--+ +--+ +--+ +--+ +--+
450  * |
451  * S +--+ +--+ +--+ +--+ +--+ +--+
452  * P |  | |  | |  | |  | |  | |  |
453  * A |  | |  | |  | |  | |  | |  |
454  * N +--+ +--+ +--+ +--+ +--+ +--+
455  * |
456  * S +--+ +--+ +--+ +--+ +--+ +--+
457  * P |  | |  | |  | |  | |  | |  |
458  * A |  | |  | |  | |  | |  | |  |
459  * N +--+ +--+ +--+ +--+ +--+ +--+
460  * 
461  */
462
463 static Span *
464 __span_build(int total, Evas_Coord size, int levels, Evas_Coord pos, int bucketsize)
465 {
466    Span *sp;
467    int i, num, bucket;
468    Evas_Coord p;
469    
470    static int lv = 0;
471    
472    sp = calloc(1, sizeof(Span));
473    for (i = 0; i < lv; i++) printf(" ");
474    printf("SP: %i tot\n", total);
475    // FIXME: alloc fail handle
476    sp->size = size * total;
477    sp->total_child_count = total;
478    sp->pos = pos;
479    if (bucketsize == 1) return sp;
480    
481    // get max number of children per bucket
482    num = bucket = (bucketsize + (levels - 1)) / levels;
483    sp->child = calloc(levels, sizeof(Span *));
484    // FIXME: alloc fail handle
485    p = pos;
486    for (i = 0; i < levels; i++)
487      {
488         if (total < num) num = total;
489         total -= num;
490         if (num <= 0) break;
491         lv++;
492         sp->child[i] = __span_build(num, size, levels, p - pos, bucket);
493         lv--;
494         // FIXME: alloc fail handle
495         sp->child[i]->parent = sp;
496         p += sp->child[i]->size;
497         sp->child_count++;
498      }
499    return sp;
500 }
501
502 static Span *
503 _span_build(int total, Evas_Coord size, int levels)
504 {
505    // total == total # of leaf nodes (# of cells)
506    // size == size of each leaf node (geom)
507    // levels == number of children per node (preferred), eg 2, 3, 4, 5 etc.
508    int bucketsize = ((total + (levels - 1)) / levels) * levels;
509    return __span_build(total, size, levels, 0, bucketsize);
510 }
511
512 static Span *
513 _span_first(Span *sp)
514 {
515    Span *sp2;
516    
517    if (!sp->child) return sp;
518    sp2 = _span_first(sp->child[0]);
519    return sp2;
520 }
521
522 static Span *
523 _span_last(Span *sp)
524 {
525    Span *sp2;
526    
527    if (!sp->child) return sp;
528    sp2 = _span_last(sp->child[sp->child_count - 1]);
529    return sp2;
530 }
531
532 static Span *
533 _span_next(Span *sp)
534 {
535    Span *spp, *spn;
536    int i;
537
538    spp = sp->parent;
539    if (!spp) return NULL;
540    for (i = 0; i < spp->child_count; i++)
541      {
542         if (spp->child[i] == sp)
543           {
544              if (i < (spp->child_count - 1)) return spp->child[i + 1];
545              else
546                {
547                   spn = _span_next(spp);
548                   if (!spn) return NULL;
549                   return _span_first(spn);
550                }
551           }
552      }
553    return NULL;
554 }
555
556 static Span *
557 _span_prev(Span *sp)
558 {
559    Span *spp, *spn;
560    int i;
561
562    spp = sp->parent;
563    if (!spp) return NULL;
564    for (i = 0; i < spp->child_count; i++)
565      {
566         if (spp->child[i] == sp)
567           {
568              if (i > 0) return spp->child[i - 1];
569              else
570                {
571                   spn = _span_prev(spp);
572                   if (!spn) return NULL;
573                   return _span_last(spn);
574                }
575           }
576      }
577    return NULL;
578 }
579
580 static Evas_Coord
581 _span_real_pos_get(Span *sp)
582 {
583    Span *spp;
584    Evas_Coord pos = sp->pos;
585    
586    for (spp = sp->parent; spp; spp = spp->parent)
587       pos += spp->pos;
588    return pos;
589 }
590
591 static int
592 _span_real_num_get(Span *sp)
593 {
594    Span *spp, *spp_prev;
595    int i, num = 0;
596    
597    for (spp_prev = sp, spp = sp->parent; spp; 
598         spp_prev = spp, spp = spp->parent)
599      {
600         if (spp->child)
601           {
602              for (i = 0; i < spp->child_count; i++)
603                {
604                   if (spp->child[i] == spp_prev) break;
605                   num += spp->child[i]->total_child_count;
606                }
607           }
608      }
609    return num;
610 }
611
612 static Span *
613 _span_num_get(Span *sp, int num)
614 {
615    int i, n, cnt;
616
617    if (num < 0) return NULL;
618    if (!sp->child) return sp;
619    for (n = 0, i = 0; i < sp->child_count; i++)
620      {
621         cnt = sp->child[i]->total_child_count;
622         n += cnt;
623         if (n > num) return _span_num_get(sp->child[i], num - (n - cnt));
624      }
625    return NULL;
626 }
627
628 static Span *
629 _span_pos_get(Span *sp, Evas_Coord pos)
630 {
631    int i;
632    Evas_Coord p, sz;
633
634    if (pos < 0) return NULL;
635    if (!sp->child) return sp;
636    for (p = 0, i = 0; i < sp->child_count; i++)
637      {
638         sz = sp->child[i]->size;
639         p += sz;
640         if (p > pos) return _span_pos_get(sp->child[i], pos - (p - sz));
641      }
642    return NULL;
643 }
644
645 static int
646 __span_del(Span *sp, int num, int count, Evas_Coord *delsize)
647 {
648    int i, n, cnt, reduce = 0, deleted = 0, delstart = -1, num2, done;
649    Evas_Coord deleted_size = 0, size;
650    
651    if (!sp->child)
652      {
653         *delsize = sp->size;
654         free(sp);
655         return 1;
656      }
657    for (n = 0, i = 0; i < sp->child_count; i++)
658      {
659         cnt = sp->child[i]->total_child_count;
660         n += cnt;
661         if (n > num)
662           {
663              num2 = num - (n - cnt);
664              if (num2 < 0) num2 = 0;
665              size = 0;
666              done = 0;
667              if (count > 0)
668                 done = __span_del(sp->child[i], num2, count, &size);
669              deleted_size += size;
670              if (i < (sp->child_count - 1))
671                 sp->child[i + 1]->pos -= deleted_size;
672              count -= done;
673              if (done == cnt)
674                {
675                   deleted++;
676                   if (delstart == -1) delstart = i;
677                }
678              reduce += done;
679           }
680      }
681    if (delstart >= 0)
682      {
683         for (i = delstart; i < sp->child_count; i++)
684           {
685              if ((i + deleted) < sp->child_count)
686                 sp->child[i] = sp->child[i + deleted];
687           }
688      }
689    sp->size -= deleted_size;
690    sp->child_count -= deleted;
691    sp->total_child_count -= reduce;
692    if (sp->child_count == 0)
693      {
694         free(sp->child);
695         free(sp);
696      }
697    *delsize = deleted_size;
698    return reduce;
699 }
700
701 static int
702 _span_del(Span *sp, int num, int count)
703 {
704    Evas_Coord deleted;
705    return __span_del(sp, num, count, &deleted);
706 }
707
708 static void
709 __span_insert(Span *sp, int num, int count, Evas_Coord size, Evas_Coord pos)
710 {
711    Span *sp2;
712    int i, j, n, src;
713    
714    if (num < 0) return;
715 next:
716    // total child count and size go up by what we are inserting
717    sp->total_child_count += count;
718    sp->size += size * count;
719    // if we have more than 1 child we have to find out which branch to go down
720    // or if we have only 1 child AND that child has another child
721    if ((sp->child_count > 1) ||
722        ((sp->child_count == 1) && (sp->child[0]->child_count >= 1)))
723      {
724         for (n = 0, i = 0; i < sp->child_count; i++)
725           {
726              sp2 = sp->child[i];
727              n += sp2->total_child_count;
728              // if num is within the child we are looking at
729              if (n > num)
730                {
731                   // advance all children along by size * count
732                   for (j = (i + 1); j < sp->child_count; j++)
733                      sp->child[j]->pos += (size * count);
734                   // now adjust num for new span in child
735                   num -= (n - sp2->total_child_count);
736                   // and check in new child span and try next child down
737                   sp = sp2;
738                   goto next;
739                }
740           }
741      }
742    // now that we are just up from a leaf node... do this
743    if (!sp->child)
744      {
745         // no child at all... just fill it in
746         sp->child_count = count;
747         sp->child = calloc(count, sizeof(Span *));
748         sp->size = size * count;
749         sp->pos = pos;
750         for (i = 0; i < count; i++)
751           {
752              sp->child[i] = calloc(1, sizeof(Span));
753              sp->child[i]->size = size;
754              sp->child[i]->pos = sp->pos + (i * size);
755              sp->child[i]->total_child_count = 1;
756              sp->child[i]->child_count = 0;
757              sp->child[i]->child = NULL;
758           }
759         return;
760      }
761    else
762      {
763         // we have some children - find a spot and plug 'er in
764         Span **child;
765         
766         src = 0;
767         // alloc a new child array and copy in old child ptrs from old array
768         // up until the insertion point (num)
769         child = calloc(count + sp->child_count, sizeof(Span *));
770         for (i = 0; i < num; i++)
771           {
772              child[i] = sp->child[src];
773              pos = child[i]->pos + child[i]->size;
774              src++;
775           }
776         // now alloc new children of the right size and stick them in
777         for (i = 0; i < count; i++)
778           {
779              child[num + i] = calloc(1, sizeof(Span));
780              sp->child[num + i]->size = size;
781              sp->child[num + i]->pos = pos;
782              sp->child[num + i]->total_child_count = 1;
783              sp->child[num + i]->child_count = 0;
784              sp->child[num + i]->child = NULL;
785              pos += size;
786           }
787         // append rest of old children and adjust their pos values
788         for (i = num; i < (count + sp->child_count); i++)
789           {
790              child[count + i] = sp->child[src];
791              sp->child[count + i]->pos = pos;
792              pos += sp->child[num + count + i]->size;
793              src++;
794           }
795         sp->child_count += count;
796         free(sp->child);
797         sp->child = child;
798      }
799 }
800
801 static void
802 _span_insert(Span *sp, int num, int count, Evas_Coord size)
803 {
804    __span_insert(sp, num, count, size, 0);
805 }
806
807 static Span *
808 _span_rebalance(Span *sp, int levels)
809 {
810    // FIXME: do
811 }
812
813 static void
814 _span_resize(Span *sp, int num, Evas_Coord size)
815 {
816    // FIXME: do
817 }
818
819 /****************************************************************************/
820
821 /**
822  * Add a new Genscroller object
823  *
824  * @param parent The parent object
825  * @return The new object or NULL if it cannot be created
826  *
827  * @ingroup Genscroller
828  */
829 EAPI Evas_Object *
830 elm_genscroller_add(Evas_Object *parent)
831 {
832    Evas_Object *obj;
833    Evas *e;
834    Widget_Data *wd;
835    Evas_Coord minw, minh;
836    static Evas_Smart *smart = NULL;
837
838    if (!smart)
839      {
840         static Evas_Smart_Class sc;
841
842         evas_object_smart_clipped_smart_set(&_pan_sc);
843         sc = _pan_sc;
844         sc.name = "elm_genscroller_pan";
845         sc.version = EVAS_SMART_CLASS_VERSION;
846         sc.add = _pan_add;
847         sc.del = _pan_del;
848         sc.resize = _pan_resize;
849         sc.move = _pan_move;
850         sc.calculate = _pan_calculate;
851         if (!(smart = evas_smart_class_new(&sc))) return NULL;
852      }
853
854    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
855
856    ELM_SET_WIDTYPE(widtype, "genscroller");
857    elm_widget_type_set(obj, "genscroller");
858    elm_widget_sub_object_add(parent, obj);
859    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
860    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
861    elm_widget_data_set(obj, wd);
862    elm_widget_del_hook_set(obj, _del_hook);
863    elm_widget_del_pre_hook_set(obj, _del_pre_hook);
864    elm_widget_theme_hook_set(obj, _theme_hook);
865    elm_widget_can_focus_set(obj, EINA_TRUE);
866    elm_widget_event_hook_set(obj, _event_hook);
867    elm_widget_on_show_region_hook_set(obj, _show_region_hook, obj);
868
869    wd->scr = elm_smart_scroller_add(e);
870    elm_smart_scroller_widget_set(wd->scr, obj);
871    elm_smart_scroller_object_theme_set(obj, wd->scr, "genscroller", "base",
872                                        elm_widget_style_get(obj));
873    elm_smart_scroller_bounce_allow_set(wd->scr,
874                                        _elm_config->thumbscroll_bounce_enable,
875                                        _elm_config->thumbscroll_bounce_enable);
876    elm_widget_resize_object_set(obj, wd->scr);
877
878    evas_object_smart_callback_add(wd->scr, "edge,left", _scroll_edge_left, obj);
879    evas_object_smart_callback_add(wd->scr, "edge,right", _scroll_edge_right,
880                                   obj);
881    evas_object_smart_callback_add(wd->scr, "edge,top", _scroll_edge_top, obj);
882    evas_object_smart_callback_add(wd->scr, "edge,bottom", _scroll_edge_bottom,
883                                   obj);
884
885    wd->obj = obj;
886
887    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
888    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
889    evas_object_smart_callback_add(obj, "scroll-freeze-on", _freeze_on, obj);
890    evas_object_smart_callback_add(obj, "scroll-freeze-off", _freeze_off, obj);
891
892    wd->pan_smart = evas_object_smart_add(e, smart);
893    wd->pan = evas_object_smart_data_get(wd->pan_smart);
894    wd->pan->wd = wd;
895
896    elm_smart_scroller_extern_pan_set(wd->scr, wd->pan_smart,
897                                      _pan_set, _pan_get, _pan_max_get,
898                                      _pan_min_get, _pan_child_size_get);
899
900    edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
901                              &minw, &minh);
902    evas_object_size_hint_min_set(obj, minw, minh);
903
904    evas_object_smart_callbacks_descriptions_set(obj, _signals);
905
906    _mirrored_set(obj, elm_widget_mirrored_get(obj));
907    _sizing_eval(obj);
908
909      {
910         Span *sp0, *sp;
911         
912         sp0 = _span_build(46, 10, 4);
913         sp = _span_first(sp0);
914         if (sp) printf("first @ %i [%i], size %i\n", sp->pos, _span_real_pos_get(sp), sp->size);
915         sp = _span_last(sp0);
916         if (sp) printf("last @ %i [%i], size %i\n", sp->pos, _span_real_pos_get(sp), sp->size);
917         for (sp = _span_first(sp0); sp; sp = _span_next(sp))
918           {
919              if (sp) printf("  @ %i [%i], size %i t: %i %i\n",
920                             sp->pos, 
921                             _span_real_pos_get(sp), 
922                             sp->size,
923                             sp->child_count,
924                             sp->total_child_count);
925           }
926         for (sp = _span_last(sp0); sp; sp = _span_prev(sp))
927           {
928              if (sp) printf("  @ %i [%i], size %i\n", sp->pos, _span_real_pos_get(sp), sp->size);
929           }
930         sp = _span_num_get(sp0, 0);
931         if (sp) printf("sp 0 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
932         sp = _span_num_get(sp0, 1);
933         if (sp) printf("sp 1 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
934         sp = _span_num_get(sp0, 7);
935         if (sp) printf("sp 7 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
936         sp = _span_num_get(sp0, 39);
937         if (sp) printf("sp 39 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
938         sp = _span_num_get(sp0, 44);
939         if (sp) printf("sp 44 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
940
941         sp = _span_pos_get(sp0, -1);
942         if (sp) printf("sp pos -1 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
943         sp = _span_pos_get(sp0, 0);
944         if (sp) printf("sp pos 0 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
945         sp = _span_pos_get(sp0, 1);
946         if (sp) printf("sp pos 1 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
947         sp = _span_pos_get(sp0, 13);
948         if (sp) printf("sp pos 13 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
949         sp = _span_pos_get(sp0, 159);
950         if (sp) printf("sp pos 159 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
951         sp = _span_pos_get(sp0, 371);
952         if (sp) printf("sp pos 371 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
953         sp = _span_pos_get(sp0, 455);
954         if (sp) printf("sp pos 455 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
955         sp = _span_pos_get(sp0, 461);
956         if (sp) printf("sp pos 461 @ %i [%i]\n", _span_real_pos_get(sp), _span_real_num_get(sp));
957         
958         printf("del @13, 11 spans\n");
959         _span_del(sp0, 13, 11);
960         for (sp = _span_first(sp0); sp; sp = _span_next(sp))
961           {
962              if (sp) printf("  @ %i [%i], size %i\n", sp->pos, _span_real_pos_get(sp), sp->size);
963           }
964
965         printf("add @23, 29 spans, size 20\n");
966         _span_insert(sp0, 23, 19, 20);
967         for (sp = _span_first(sp0); sp; sp = _span_next(sp))
968           {
969              if (sp) printf("  @ %i [%i], size %i\n", sp->pos, _span_real_pos_get(sp), sp->size);
970           }
971      }
972    return obj;
973 }
974
975 /**
976  * XXX
977  *
978  * xxx
979  *
980  * @param obj The genlist object
981  *
982  * @ingroup Genscroller
983  */
984 EAPI void
985 elm_genscroller_world_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
986 {
987    ELM_CHECK_WIDTYPE(obj, widtype);
988    Widget_Data *wd = elm_widget_data_get(obj);
989    if (!wd) return;
990    wd->minw = w;
991    wd->minh = h;
992    evas_object_smart_callback_call(wd->pan_smart, "changed", NULL);
993    _sizing_eval(wd->obj);
994    evas_object_smart_changed(wd->pan_smart);
995 }
996
997 EAPI void
998 elm_genscroller_world_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
999 {
1000 }
1001
1002 EAPI void
1003 elm_genscroller_cell_size_set(Evas_Object *obj, int w, int h)
1004 {
1005    ELM_CHECK_WIDTYPE(obj, widtype);
1006    Widget_Data *wd = elm_widget_data_get(obj);
1007    if (!wd) return;
1008    wd->cells.w = w;
1009    wd->cells.h = h;
1010 }
1011
1012 EAPI void
1013 elm_genscroller_cell_size_get(Evas_Object *obj, int *w, int *h)
1014 {
1015 }
1016
1017 EAPI void
1018 elm_genscroller_cell_all_size_set(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
1019 {
1020 }
1021
1022 EAPI void
1023 elm_genscroller_cell_row_size_set(Evas_Object *obj, int y, Evas_Coord h)
1024 {
1025 }
1026
1027 EAPI void
1028 elm_genscroller_cell_col_size_set(Evas_Object *obj, int x, Evas_Coord w)
1029 {
1030 }
1031
1032 EAPI void
1033 elm_genscroller_cell_rows_insert(Evas_Object *obj, int y, int rows)
1034 {
1035 }
1036
1037 EAPI void
1038 elm_genscroller_cell_rows_del(Evas_Object *obj, int y, int rows)
1039 {
1040 }
1041
1042 EAPI void
1043 elm_genscroller_cell_cols_insert(Evas_Object *obj, int x, int cols)
1044 {
1045 }
1046
1047 EAPI void
1048 elm_genscroller_cell_cols_del(Evas_Object *obj, int x, int cols)
1049 {
1050 }