summaryrefslogtreecommitdiff
path: root/src/bin/e_flowlayout.c
blob: f81fe9a22b349fe1b40bc4895af525a9e6d03bc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
#include "e.h"

typedef struct _E_Smart_Data E_Smart_Data;
typedef struct _E_Flowlayout_Item   E_Flowlayout_Item;

struct _E_Smart_Data
{ 
   Evas_Coord       x, y, w, h;
   Evas_Object     *obj;
   Evas_Object     *clip;
   int              frozen;
   unsigned char    changed : 1;
   unsigned char    horizontal : 1;
   unsigned char    homogenous : 1;
   unsigned char    fill : 1;
   unsigned char    flowright : 1;
   unsigned char    flowbottom : 1;
   Eina_List       *items;
   struct {
      Evas_Coord    w, h;
   } min, max;
   struct {
      double        x, y;
   } align;
   int rows;
   int cols;
}; 

struct _E_Flowlayout_Item
{
   E_Smart_Data    *sd;
   unsigned char    fill_w : 1;
   unsigned char    fill_h : 1;
   unsigned char    expand_w : 1;
   unsigned char    expand_h : 1;
   struct {
      Evas_Coord    w, h;
   } min, max;
   struct {
      double        x, y;
   } align;
   Evas_Object     *obj;
};

/* local subsystem functions */
static E_Flowlayout_Item *_e_flowlayout_smart_adopt(E_Smart_Data *sd, Evas_Object *obj);
static void        _e_flowlayout_smart_disown(Evas_Object *obj);
static void        _e_flowlayout_smart_item_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void        _e_flowlayout_smart_reconfigure(E_Smart_Data *sd);
static void        _e_flowlayout_smart_extents_calcuate(E_Smart_Data *sd);

static void _e_flowlayout_smart_init(void);
static void _e_flowlayout_smart_add(Evas_Object *obj);
static void _e_flowlayout_smart_del(Evas_Object *obj);
static void _e_flowlayout_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
static void _e_flowlayout_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
static void _e_flowlayout_smart_show(Evas_Object *obj);
static void _e_flowlayout_smart_hide(Evas_Object *obj);
static void _e_flowlayout_smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
static void _e_flowlayout_smart_clip_set(Evas_Object *obj, Evas_Object *clip);
static void _e_flowlayout_smart_clip_unset(Evas_Object *obj);

/* local subsystem globals */
static Evas_Smart *_e_smart = NULL;

/* externally accessible functions */
EAPI Evas_Object *
e_flowlayout_add(Evas *evas)
{
   _e_flowlayout_smart_init();
   return evas_object_smart_add(evas, _e_smart);
}

EAPI int
e_flowlayout_freeze(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   sd->frozen++;
   return sd->frozen;
}

EAPI int
e_flowlayout_thaw(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   sd->frozen--;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
   return sd->frozen;
}

EAPI void
e_flowlayout_orientation_set(Evas_Object *obj, int horizontal)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (((sd->horizontal) && (horizontal)) ||
       ((!sd->horizontal) && (!horizontal))) return;
   sd->horizontal = horizontal;
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
}

EAPI int
e_flowlayout_orientation_get(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   return sd->horizontal;
}

EAPI void
e_flowlayout_flowdirection_set(Evas_Object *obj, int right, int bottom)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if ((((sd->flowbottom) && (bottom)) ||
       ((!sd->flowbottom) && (!bottom))) &&
       (((sd->flowright)  && (right))  ||
       ((!sd->flowright)  && (!right))))	return;
   sd->flowright = right;
   sd->flowbottom = bottom;
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
}

EAPI void
e_flowlayout_flowdirection_get(Evas_Object *obj, int *right, int *bottom)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (right) *right = sd->flowright;
   if (bottom) *bottom = sd->flowright; 
}

EAPI void
e_flowlayout_homogenous_set(Evas_Object *obj, int homogenous)
{
   E_Smart_Data *sd;
  
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (sd->homogenous == homogenous) return;
   sd->homogenous = homogenous;
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
}

EAPI int
e_flowlayout_homogenous_get(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   return sd->homogenous;
}

EAPI void
e_flowlayout_fill_set(Evas_Object *obj, int fill)
{
   E_Smart_Data *sd;
  
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (sd->fill == fill) return;
   sd->fill = fill;
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
}

EAPI int
e_flowlayout_fill_get(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   return sd->fill;
}


EAPI int
e_flowlayout_pack_start(Evas_Object *obj, Evas_Object *child)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   _e_flowlayout_smart_adopt(sd, child);
   sd->items = eina_list_prepend(sd->items, child);
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
   return 0;
}

EAPI int
e_flowlayout_pack_end(Evas_Object *obj, Evas_Object *child)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   _e_flowlayout_smart_adopt(sd, child);
   sd->items = eina_list_append(sd->items, child);   
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
   return eina_list_count(sd->items) - 1;
}

EAPI int
e_flowlayout_pack_before(Evas_Object *obj, Evas_Object *child, Evas_Object *before)
{
   E_Smart_Data *sd;
   int i = 0;
   Eina_List *l;
   Evas_Object *item;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   _e_flowlayout_smart_adopt(sd, child);
   sd->items = eina_list_prepend_relative(sd->items, child, before);
   EINA_LIST_FOREACH(sd->items, l, item)
     {
	if (item == child) break;
	i++;
     }
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
   return i;
}

EAPI int
e_flowlayout_pack_after(Evas_Object *obj, Evas_Object *child, Evas_Object *after)
{
   E_Smart_Data *sd;
   int i = 0;
   Eina_List *l;
   Evas_Object *item;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   _e_flowlayout_smart_adopt(sd, child);
   sd->items = eina_list_append_relative(sd->items, child, after);
   EINA_LIST_FOREACH(sd->items, l, item)
     {
	if (item == child) break;
	i++;
     }
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
   return i;
}

EAPI int
e_flowlayout_pack_count_get(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return 0;
   return eina_list_count(sd->items);
}

EAPI Evas_Object *
e_flowlayout_pack_object_nth(Evas_Object *obj, int n)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return NULL;
   return eina_list_nth(sd->items, n);
}

EAPI Evas_Object *
e_flowlayout_pack_object_first(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return NULL;
   return eina_list_data_get(sd->items);
}

EAPI Evas_Object *
e_flowlayout_pack_object_last(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return NULL;
   return eina_list_data_get(eina_list_last(sd->items));
}

EAPI void
e_flowlayout_pack_options_set(Evas_Object *obj, int fill_w, int fill_h, int expand_w, int expand_h, double align_x, double align_y, Evas_Coord min_w, Evas_Coord min_h, Evas_Coord max_w, Evas_Coord max_h)
{
   E_Flowlayout_Item *bi;
   
   bi = evas_object_data_get(obj, "e_flowlayout_data");
   if (!bi) return;
   bi->fill_w = fill_w;
   bi->fill_h = fill_h;
   bi->expand_w = expand_w;
   bi->expand_h = expand_h;
   bi->align.x = align_x;
   bi->align.y = align_y;
   bi->min.w = min_w;
   bi->min.h = min_h;
   bi->max.w = max_w;
   bi->max.h = max_h;
   bi->sd->changed = 1;
   if (bi->sd->frozen <= 0) _e_flowlayout_smart_reconfigure(bi->sd);
}

EAPI void
e_flowlayout_unpack(Evas_Object *obj)
{
   E_Flowlayout_Item *bi;
   E_Smart_Data *sd;
   
   bi = evas_object_data_get(obj, "e_flowlayout_data");
   if (!bi) return;
   sd = bi->sd;
   if (!sd) return;
   sd->items = eina_list_remove(sd->items, obj);
   _e_flowlayout_smart_disown(obj);
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
}

EAPI void
e_flowlayout_size_min_get(Evas_Object *obj, Evas_Coord *minw, Evas_Coord *minh)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (sd->changed) _e_flowlayout_smart_extents_calcuate(sd);
   if (minw) *minw = sd->min.w;
   if (minh) *minh = sd->min.h;
}

EAPI void
e_flowlayout_size_max_get(Evas_Object *obj, Evas_Coord *maxw, Evas_Coord *maxh)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (sd->changed) _e_flowlayout_smart_extents_calcuate(sd);
   if (maxw) *maxw = sd->max.w;
   if (maxh) *maxh = sd->max.h;
}

EAPI int
e_flowlayout_max_children(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return -1;
   if (!sd->homogenous) return -1;
   return (sd->rows * sd->cols);
}
EAPI void
e_flowlayout_align_get(Evas_Object *obj, double *ax, double *ay)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (ax) *ax = sd->align.x;
   if (ay) *ay = sd->align.y;
}

EAPI void
e_flowlayout_align_set(Evas_Object *obj, double ax, double ay)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if ((sd->align.x == ax) && (sd->align.y == ay)) return;
   sd->align.x = ax;
   sd->align.y = ay;
   sd->changed = 1;
   if (sd->frozen <= 0) _e_flowlayout_smart_reconfigure(sd);
}

/* local subsystem functions */
static E_Flowlayout_Item *
_e_flowlayout_smart_adopt(E_Smart_Data *sd, Evas_Object *obj)
{
   E_Flowlayout_Item *bi;
   
   bi = calloc(1, sizeof(E_Flowlayout_Item));
   if (!bi) return NULL;
   bi->sd = sd;
   bi->obj = obj;
   /* defaults */
   bi->fill_w = 0;
   bi->fill_h = 0;
   bi->expand_w = 0;
   bi->expand_h = 0;
   bi->align.x = 0.5;
   bi->align.y = 0.5;
   bi->min.w = 0;
   bi->min.h = 0;
   bi->max.w = 0;
   bi->max.h = 0;
   evas_object_clip_set(obj, sd->clip);
   evas_object_smart_member_add(obj, bi->sd->obj);
   evas_object_data_set(obj, "e_flowlayout_data", bi);
   evas_object_event_callback_add(obj, EVAS_CALLBACK_FREE,
				  _e_flowlayout_smart_item_del_hook, NULL);
   if ((!evas_object_visible_get(sd->clip)) &&
       (evas_object_visible_get(sd->obj)))
     evas_object_show(sd->clip);
   return bi;
}

static void
_e_flowlayout_smart_disown(Evas_Object *obj)
{
   E_Flowlayout_Item *bi;
   
   bi = evas_object_data_get(obj, "e_flowlayout_data");
   if (!bi) return;
   if (!bi->sd->items)
     {
	if (evas_object_visible_get(bi->sd->clip))
	  evas_object_hide(bi->sd->clip);
     }
   evas_object_event_callback_del(obj,
				  EVAS_CALLBACK_FREE,
				  _e_flowlayout_smart_item_del_hook);
   evas_object_smart_member_del(obj);
   evas_object_clip_unset(obj);
   evas_object_data_del(obj, "e_flowlayout_data");
   free(bi);
}

static void
_e_flowlayout_smart_item_del_hook(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
   e_flowlayout_unpack(obj);
}

static void
_e_flowlayout_smart_reconfigure(E_Smart_Data *sd)
{
   Evas_Coord x, y, w, h, xx, yy, cr, cc;
   Eina_List *l;
   Evas_Object *obj;
   int minw, minh;
   int count, expand;


   if (!sd->changed) return;
   
   /* local variables */
   x = sd->x;
   y = sd->y;
   w = sd->w;
   h = sd->h;

   /* Calculate extents */
   _e_flowlayout_smart_extents_calcuate(sd);
   minw = sd->min.w;
   minh = sd->min.h;
   count = eina_list_count(sd->items);
   expand = 0;

   /* Too small? move a little */
   if (w < minw)
     {
	x = x + ((w - minw) * (1.0 - sd->align.x));
	w = minw;
     }
   if (h < minh)
     {
	y = y + ((h - minh) * (1.0 - sd->align.y));
	h = minh;
     }

   /* Some odd expanding counter */
   EINA_LIST_FOREACH(sd->items, l, obj)
     {
	E_Flowlayout_Item *bi;
	
	bi = evas_object_data_get(obj, "e_flowlayout_data");
	if (bi)
	  {
	     if (sd->horizontal)
	       {
		  if (bi->expand_w) expand++;
	       }
	     else
	       {
		  if (bi->expand_h) expand++;
	       }
	  }
     }

   /* If no expansion, w is minw, h is minh */
   if (expand == 0)
     {
	if (sd->horizontal)
	  {
	     x += (double)(w - minw) * sd->align.x;
	     w = minw;
	  }
	else
	  {
	     y += (double)(h - minh) * sd->align.y;
	     h = minh;
	  }
     }
   
   /* Some calculations */
   if (sd->flowright)
     xx = x;
   else
     xx = x + w;
   if (sd->flowbottom)
     yy = y;
   else
     yy = y + h;
   cr = 0;
   cc = 0;

   /* Now for the real deal */
   EINA_LIST_FOREACH(sd->items, l, obj)
     {
	E_Flowlayout_Item *bi;
	
	bi = evas_object_data_get(obj, "e_flowlayout_data");
	if (bi)
	  {
	     /* Horiziontal */
	     if (sd->horizontal)
	       {
		  /* Homogenous */
		  if (sd->homogenous)
		    {
		       Evas_Coord ww, hh, ow, oh;
		       ww = w / sd->cols;
		       hh = h / sd->rows;
		       if (sd->fill)
			 {
			    int num = count - (cr)*(sd->cols);
			    if (num < sd->cols)
			      {
     				 ww = w / num;
			      }
			 }
		       ow = bi->min.w;
		       if (bi->fill_w) ow = ww;
		       if ((bi->max.w >= 0) && (bi->max.w < ow)) ow = bi->max.w;
		       oh = bi->min.h;
		       if (bi->fill_h) oh = hh;
		       if ((bi->max.h >= 0) && (bi->max.h < oh)) oh = bi->max.h;
		       if (sd->flowright)
			 {
			    if (sd->flowbottom)
			      {
     				 evas_object_move(obj, 
					xx + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));
			      }
			    else
			      {
     				 evas_object_move(obj, 
					xx + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy - hh + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));
			      }
			    evas_object_resize(obj, ow, oh);
			    xx += ww;
			 }
		       else
			 {
			    if (sd->flowbottom)
			      {
     				 evas_object_move(obj, 
					xx - ww + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));
			      }
			    else
			      {
     				 evas_object_move(obj, 
					xx - ww + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy - hh + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));

			      }
     			    evas_object_resize(obj, ow, oh);
   			    xx -= ww;
			 }
		       cc++;
		       if (cc >= sd->cols)
			 {
			    cc = 0;
			    cr++;
			    if (sd->flowright)
			      xx = x;
			    else
			      xx = x + w;
			    if (sd->flowbottom)
  			      yy += hh;
			    else
			      yy -= hh;
			 }
		    }
		  /* TODO Nonhomogenous Horizontal */
		  else
		    {
		    }
	       }
	     /* Vertical */
	     else
	       {
		  if (sd->homogenous)
		    {
		       Evas_Coord ww, hh, ow, oh;
		       ww = w / sd->cols;
		       hh = h / sd->rows;
		       if (sd->fill)
			 {
			    int num = count - (cc)*(sd->rows);
			    if (num < sd->rows)
			      {
     				 hh = h / num;
			      }
			 }
		       oh = bi->min.h;
		       if (bi->fill_h) oh = hh;
		       if ((bi->max.h >= 0) && (bi->max.h < oh)) oh = bi->max.h;
		       ow = bi->min.w;
		       if (bi->fill_w) ow = ww;
		       if ((bi->max.w >= 0) && (bi->max.w < ow)) ow = bi->max.w;
		       if (sd->flowbottom)
			 {
			    if (sd->flowright)
			      {
     				 evas_object_move(obj, 
					xx + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));
			      }
			    else
			      {
     				 evas_object_move(obj, 
					xx - ww + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));
			      }
			    evas_object_resize(obj, ow, oh);
			    yy += hh;
			 }
		       else
			 {
			    if (sd->flowright)
			      {
     				 evas_object_move(obj, 
					xx + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy - hh + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));
			      }
			    else
			      {
     				 evas_object_move(obj, 
					xx - ww + (Evas_Coord)(((double)(ww - ow)) * bi->align.x),
					yy - hh + (Evas_Coord)(((double)(hh - oh)) * bi->align.y));

			      }
     			    evas_object_resize(obj, ow, oh);
   			    yy -= hh;
			 }
		       cr++;
		       if (cr >= sd->rows)
			 {
			    cr = 0;
			    cc++;
			    if (sd->flowbottom)
			      yy = y;
			    else
			      yy = y + h;
			    if (sd->flowright)
  			      xx += ww;
			    else
			      xx -= ww;
			 }

		    }
		  /* TODO Nonhomogeneous Vertical */
		  else
		    {
		    }
	       }
	  }
     }
   sd->changed = 0;
}

static void
_e_flowlayout_smart_extents_calcuate(E_Smart_Data *sd)
{
   Eina_List *l;
   Evas_Object *obj;
   int minw, minh, count;

   /* FIXME: need to calc max */
   sd->max.w = -1; /* max < 0 == unlimited */
   sd->max.h = -1;
   
   minw = 1;
   minh = 1;
   if (sd->homogenous)
     {
	EINA_LIST_FOREACH(sd->items, l, obj)
	  {
	     E_Flowlayout_Item *bi;
	     
	     bi = evas_object_data_get(obj, "e_flowlayout_data");	
	     if (bi)
	       {
		  if (sd->horizontal)
		    {
		       if (minh < bi->min.h) minh = bi->min.h;
		       if (minw < bi->min.w) minw = bi->min.w;
		    }
		  else
		    {
		       if (minw < bi->min.w) minw = bi->min.w;
		       if (minh < bi->min.h) minh = bi->min.h;
		    }
	       }
	  }
	if (sd->horizontal)
	  {
	     sd->rows = sd->h/minh;
	     if (sd->rows<1)
	       sd->rows = 1;
	     count = eina_list_count(sd->items);
	     sd->cols = sd->w/minw;
             if (count < sd->cols) sd->cols = count;
             sd->rows = 0;
             if (sd->cols > 0)
               {
                  while (count > 0)
                    {
                       count -= sd->cols;
                       sd->rows++;
                    }
               }
	  }
	else
	  {
	     sd->cols = sd->w/minw;
	     if (sd->cols<1)
	       sd->cols = 1;
	     count = eina_list_count(sd->items);
	     sd->rows = sd->h/minh;
             if (count < sd->cols) sd->rows = count;
             sd->cols = 0;
             if (sd->rows > 0)
               {
                  while (count > 0)
                    {
                       count -= sd->rows;
                       sd->cols++;
                    }
               }
	  }

	minw *= sd->cols;
	minh *= sd->rows;
     }
   /* TODO nonhomogenous */
   else
     {
	EINA_LIST_FOREACH(sd->items, l, obj)
	  {
	     E_Flowlayout_Item *bi;
	     
	     bi = evas_object_data_get(obj, "e_flowlayout_data");
	     if (bi)
	       {
		  if (sd->horizontal)
		    {
		       if (minh < bi->min.h) minh = bi->min.h*sd->rows;
		       minw += bi->min.w;
		    }
		  else
		    {
		       if (minw < bi->min.w) minw = bi->min.w*sd->cols;
		       minh += bi->min.h;
		    }
	       }
	  }
	 if (sd->horizontal)
	   {
	      sd->rows = sd->h/minh;
	      minh *= sd->rows;
	      sd->cols = -1;
	      minw = minw/sd->cols + 0.2*minw;
	   }
	 else
	   {
	      sd->cols = sd->w/minw;
	      minw *= sd->cols;
	      sd->rows = -1;
	      minh = minh/sd->cols + 0.2*minh;
	   }
     }
   sd->min.w = minw;
   sd->min.h = minh;
   if (sd->rows < 1)
     sd->rows = 1;
   if (sd->cols < 1)
     sd->cols = 1;
}

static void
_e_flowlayout_smart_init(void)
{
   if (_e_smart) return;
     {
	static const Evas_Smart_Class sc =
	  {
	     "e_flowlayout",
	       EVAS_SMART_CLASS_VERSION,
	       _e_flowlayout_smart_add,
	       _e_flowlayout_smart_del,
	       _e_flowlayout_smart_move,
	       _e_flowlayout_smart_resize,
	       _e_flowlayout_smart_show,
	       _e_flowlayout_smart_hide,
	       _e_flowlayout_smart_color_set,
	       _e_flowlayout_smart_clip_set,
	       _e_flowlayout_smart_clip_unset,
	       NULL,
	       NULL,
	       NULL,
  	       NULL,
  	       NULL,
  	       NULL,
  	       NULL
	  };
        _e_smart = evas_smart_class_new(&sc);
     }
}

static void
_e_flowlayout_smart_add(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = calloc(1, sizeof(E_Smart_Data));
   if (!sd) return;
   sd->obj = obj;
   sd->x = 0;
   sd->y = 0;
   sd->w = 0;
   sd->h = 0;
   sd->align.x = 0.5;
   sd->align.y = 0.5;
   sd->clip = evas_object_rectangle_add(evas_object_evas_get(obj));
   evas_object_smart_member_add(sd->clip, obj);
   evas_object_move(sd->clip, -100004, -100004);
   evas_object_resize(sd->clip, 200008, 200008);
   evas_object_color_set(sd->clip, 255, 255, 255, 255);
   evas_object_smart_data_set(obj, sd);
}
   
static void
_e_flowlayout_smart_del(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   /* FIXME: this gets into an infinite loop when changin basic->advanced on
    * ibar config dialog
    */
   while (sd->items)
     {
	Evas_Object *child;
	
	child = eina_list_data_get(sd->items);
	e_flowlayout_unpack(child);
     }
   evas_object_del(sd->clip);
   free(sd);
}

static void
_e_flowlayout_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if ((x == sd->x) && (y == sd->y)) return;
     {
	Eina_List *l;
	Evas_Object *item;
	Evas_Coord dx, dy;
	
	dx = x - sd->x;
	dy = y - sd->y;
	EINA_LIST_FOREACH(sd->items, l, item)
	  {
	     Evas_Coord ox, oy;
	     
	     evas_object_geometry_get(item, &ox, &oy, NULL, NULL);
	     evas_object_move(item, ox + dx, oy + dy);
	  }
     }
   sd->x = x;
   sd->y = y;
}

static void
_e_flowlayout_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if ((w == sd->w) && (h == sd->h)) return;
   sd->w = w;
   sd->h = h;
   sd->changed = 1;
   _e_flowlayout_smart_reconfigure(sd);
}

static void
_e_flowlayout_smart_show(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   if (sd->items) evas_object_show(sd->clip);
}

static void
_e_flowlayout_smart_hide(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   evas_object_hide(sd->clip);
}

static void
_e_flowlayout_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;   
   evas_object_color_set(sd->clip, r, g, b, a);
}

static void
_e_flowlayout_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   evas_object_clip_set(sd->clip, clip);
}

static void
_e_flowlayout_smart_clip_unset(Evas_Object *obj)
{
   E_Smart_Data *sd;
   
   sd = evas_object_smart_data_get(obj);
   if (!sd) return;
   evas_object_clip_unset(sd->clip);
}