code cleanup
[framework/uifw/cbhm.git] / src / clipdrawer.c
1 #include "common.h"
2 #include "cbhm_main.h"
3 #include "storage.h"
4 #include "xcnphandler.h"
5 #include "clipdrawer.h"
6
7 #define IM      "/mnt/ums/Images/Photo/"
8 static const char *images[] = {
9         IM"1_photo.jpg",
10         IM"2_photo.jpg",
11         IM"3_photo.jpg",
12         IM"4_photo.jpg",
13         IM"5_photo.jpg",
14         IM"6_photo.jpg",
15 };
16 #define N_IMAGES (6)
17
18 static void
19 _image_click(void *data, Evas_Object *obj, void *event_info)
20 {
21         struct appdata *ad = data;
22         char *p,*file;
23         int len;
24         file = evas_object_data_get(obj, "URI");
25         len = strlen(file);
26         p = malloc(len + 10);
27         snprintf(p,len+10,"file:///%s",file);
28
29         elm_selection_set(/*secondary*/1,obj,/*ELM_SEL_FORMAT_IMAGE*/4,p);
30
31         clipdrawer_lower_view(ad);
32 }
33
34 static void _list_click( void *data, Evas_Object *obj, void *event_info )
35 {
36         struct appdata *ad = data;
37     Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
38         if (it == NULL)
39                 return;
40
41     elm_list_item_selected_set(it, 0);
42
43         char *p = NULL;
44         int cplen;
45
46         char *cpdata = NULL;
47         cpdata = elm_list_item_label_get(it);
48         if (cpdata == NULL)
49                 return;
50         cplen = strlen(cpdata);
51         p = malloc(cplen + 1);
52         snprintf(p, cplen+1, "%s", cpdata);
53         elm_selection_set(1, obj, /*ELM_SEL_FORMAT_TEXT*/1, p);
54 //      elm_selection_set(1, obj, /*ELM_SEL_FORMAT_MARKUP*/2, p);
55
56         clipdrawer_lower_view(ad);
57 }
58
59 int clipdrawer_update_contents(void *data)
60 {
61         struct appdata *ad = data;
62         int i, pos;
63
64         elm_list_clear(ad->txtlist);
65         for (i = 0; i < HISTORY_QUEUE_NUMBER; i++)
66         {
67                 pos = get_current_history_position()+i;
68                 if (pos > HISTORY_QUEUE_NUMBER-1)
69                         pos = pos-HISTORY_QUEUE_NUMBER;
70                 if (get_item_contents_by_pos(pos) != NULL && strlen(get_item_contents_by_pos(pos)) > 0)
71                 {
72                         elm_list_item_append(ad->txtlist, get_item_contents_by_pos(pos), NULL, NULL, NULL, ad);
73                 }
74         }
75         elm_list_go(ad->txtlist);
76
77         /* FIXME : sometimes when list update, screen isn't updated */
78
79         return 0;
80 }
81
82 int clipdrawer_init(void *data)
83 {
84         struct appdata *ad = data;
85
86         evas_object_resize(ad->win_main, 480, 360);
87         evas_object_move(ad->win_main, 0, 440);
88         evas_object_resize(ad->ly_main, 480, 360);
89         evas_object_move(ad->ly_main, 0, 440);
90
91         ad->scrl = elm_scroller_add(ad->win_main);
92         edje_object_part_swallow(_EDJ(ad->ly_main), "cbhmdrawer/imglist", ad->scrl);
93         evas_object_size_hint_weight_set(ad->scrl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
94         elm_scroller_bounce_set(ad->scrl, EINA_TRUE, EINA_FALSE);
95         elm_scroller_policy_set(ad->scrl, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
96         elm_win_resize_object_add(ad->win_main, ad->scrl);
97         evas_object_show(ad->scrl);
98
99         evas_object_resize(ad->scrl,480,95);
100  
101         ad->imgbox = elm_box_add(ad->win_main);
102         elm_box_horizontal_set(ad->imgbox, TRUE);
103         evas_object_size_hint_weight_set(ad->imgbox, EVAS_HINT_EXPAND, 0);
104         evas_object_size_hint_align_set(ad->imgbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
105         elm_scroller_content_set(ad->scrl, ad->imgbox);
106         evas_object_show(ad->imgbox);
107
108         Evas_Object *pt;
109         int i;
110         for (i = 0 ; i < N_IMAGES ; i ++)
111         {
112                 pt = elm_photo_add(ad->win_main);
113                 elm_photo_file_set(pt, images[i]);
114                 evas_object_size_hint_weight_set(pt, EVAS_HINT_EXPAND,
115                                 EVAS_HINT_EXPAND);
116                 evas_object_size_hint_align_set(pt, EVAS_HINT_FILL,
117                                 EVAS_HINT_FILL);
118                 elm_photo_size_set(pt, 125);
119                 elm_box_pack_end(ad->imgbox, pt);
120                 evas_object_show(pt);
121                 evas_object_data_set(pt,"URI",images[i]);
122
123                 evas_object_smart_callback_add(pt, "clicked", _image_click, ad);
124         }
125
126         ad->txtlist = elm_list_add(ad->win_main);
127         elm_layout_content_set(ad->ly_main, "cbhmdrawer/txtlist", ad->txtlist);
128         elm_list_horizontal_mode_set(ad->txtlist, ELM_LIST_COMPRESS);
129         evas_object_smart_callback_add(ad->txtlist, "selected", _list_click, ad);
130         elm_list_item_append(ad->txtlist, "default", NULL, NULL, NULL, ad);
131
132         elm_list_go(ad->txtlist);
133
134         if (get_item_counts() != 0)
135                 clipdrawer_update_contents(ad);
136
137         return 0;
138 }
139
140 int clipdrawer_create_view(void *data)
141 {
142         struct appdata *ad = data;
143
144         clipdrawer_init(ad);
145
146         return 0;
147 }
148
149 void clipdrawer_activate_view(void *data)
150 {
151         struct appdata *ad = data;
152         
153         if (ad->win_main)
154         {
155                 evas_object_show(ad->win_main);
156                 elm_win_activate(ad->win_main);
157         }
158 }
159
160 void clipdrawer_lower_view(void *data)
161 {
162         struct appdata *ad = data;
163         
164         if (ad->win_main)
165         {
166                 evas_object_hide(ad->win_main);
167                 elm_win_lower(ad->win_main);
168         }
169 }