2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.tizenopensource.org/license
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "item_manager.h"
20 static void item_free(CNP_ITEM *item)
25 DMSG("WRONG PARAMETER in %s\n", __func__);
31 if (item->ad->draw_item_del)
32 item->ad->draw_item_del(item->ad, item);
33 if (item->ad->storage_item_del)
34 item->ad->storage_item_del(item->ad, item);
39 if (item->ad->clip_selected_item == item)
40 item->ad->clip_selected_item = NULL;
44 CNP_ITEM *item_add_by_CNP_ITEM(AppData *ad, CNP_ITEM *item)
48 DMSG("WRONG PARAMETER in %s, ad: 0x%x, item: 0x%x\n", __func__, ad, item);
53 ad->item_list = eina_list_prepend(ad->item_list, item);
54 if (ad && ad->draw_item_add)
55 ad->draw_item_add(ad, item);
56 if (ad && ad->storage_item_add)
57 ad->storage_item_add(ad, item);
59 while (ITEM_CNT_MAX < eina_list_count(ad->item_list))
61 CNP_ITEM *ditem = eina_list_nth(ad->item_list, ITEM_CNT_MAX);
63 ad->item_list = eina_list_remove(ad->item_list, ditem);
67 slot_property_set(ad, -1);
68 slot_item_count_set(ad);
73 CNP_ITEM *item_add_by_data(AppData *ad, Ecore_X_Atom type, void *data, int len)
77 DMSG("WRONG PARAMETER in %s\n", __func__);
81 item = CALLOC(1, sizeof(CNP_ITEM));
84 item->type_index = atom_type_index_get(ad, type);
88 item = item_add_by_CNP_ITEM(ad, item);
92 CNP_ITEM *item_get_by_index(AppData *ad, int index)
94 if (!ad || eina_list_count(ad->item_list) <= index || 0 > index)
96 DMSG("WRONG PARAMETER in %s\n", __func__);
100 item = eina_list_nth(ad->item_list, index);
104 CNP_ITEM *item_get_by_data(AppData *ad, void *data)
108 DMSG("WRONG PARAMETER in %s\n", __func__);
113 EINA_LIST_FOREACH(ad->item_list, l, item)
115 if (item && item->data == data)
123 CNP_ITEM *item_get_last(AppData *ad)
127 DMSG("WRONG PARAMETER in %s\n", __func__);
130 return eina_list_data_get(ad->item_list);
133 void item_delete_by_CNP_ITEM(AppData *ad, CNP_ITEM *item)
138 DMSG("WRONG PARAMETER in %s\n", __func__);
141 DMSG("item: 0x%x, item->gitem: 0x%x\n", item, item->gitem);
142 ad->item_list = eina_list_remove(ad->item_list, item);
144 slot_property_set(ad, -1);
145 slot_item_count_set(ad);
148 void item_delete_by_data(AppData *ad, void *data)
153 DMSG("WRONG PARAMETER in %s\n", __func__);
157 item = item_get_by_data(ad, data);
158 item_delete_by_CNP_ITEM(ad, item);
161 void item_delete_by_index(AppData *ad, int index)
164 if (!ad || eina_list_count(ad->item_list) <= index || 0 > index)
166 DMSG("WRONG PARAMETER in %s\n", __func__);
170 item = item_get_by_index(ad, index);
171 item_delete_by_CNP_ITEM(ad, item);
174 void item_clear_all(AppData *ad)
179 CNP_ITEM *item = eina_list_data_get(ad->item_list);
180 ad->item_list = eina_list_remove(ad->item_list, item);
186 int item_count_get(AppData *ad)
188 return eina_list_count(ad->item_list);