Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / eail / eail_thumb.c
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 /**
21  * @file eail_thumb.c
22  * @brief EailThumb Implementation
23  */
24
25 #include <Elementary.h>
26 #include <atk/atk.h>
27
28 #include "eail_thumb.h"
29 #include "eail_widget.h"
30
31 static void atk_image_iface_init(AtkImageIface *iface);
32
33 /**
34  * @brief EailThumb type definition
35  */
36 G_DEFINE_TYPE_WITH_CODE(EailThumb,
37                         eail_thumb,
38                         EAIL_TYPE_IMAGE,
39                         G_IMPLEMENT_INTERFACE(ATK_TYPE_IMAGE,
40                                               atk_image_iface_init));
41
42 /**
43  * @brief EailThumb initializer
44  *
45  * @param obj AtkObject instance
46  * @param data initialization data
47  */
48 static void
49 eail_thumb_initialize(AtkObject *obj, gpointer data)
50 {
51    ATK_OBJECT_CLASS(eail_thumb_parent_class)->initialize(obj, data);
52 }
53
54 /**
55  * @brief EailThumb instance initializer
56  *
57  * @param thumb EailThumb instance
58  */
59 static void
60 eail_thumb_init(EailThumb *thumb)
61 {
62 }
63
64 /**
65  * @brief Gets the state set of obj
66  *
67  * @param obj AtkObject instance
68  * @return AtkStateSet representing the state set of obj
69  */
70 static AtkStateSet*
71 eail_thumb_ref_state_set(AtkObject *obj)
72 {
73    AtkStateSet *state_set;
74
75    g_return_val_if_fail(EAIL_IS_THUMB(obj), NULL);
76
77    state_set = ATK_OBJECT_CLASS(eail_thumb_parent_class)->ref_state_set(obj);
78    if (!state_set)
79      atk_state_set_add_state(state_set, ATK_STATE_ANIMATED);
80
81    return state_set;
82 }
83
84 /**
85  * @brief EailThumb class initializer
86  *
87  * @param klass EailThumbClass instance
88  */
89 static void
90 eail_thumb_class_init(EailThumbClass *klass)
91 {
92    AtkObjectClass *atk_class = ATK_OBJECT_CLASS(klass);
93    atk_class->initialize = eail_thumb_initialize;
94    atk_class->ref_state_set = eail_thumb_ref_state_set;
95 }
96
97 /**
98  * @brief Gets the current size of a thumb
99  *
100  * @param image AtkImage instance
101  * @param [out] width thumb's current width
102  * @param [out] height thumb's current height
103  */
104 static void
105 eail_thumb_size_get(AtkImage *image, gint *width, gint *height)
106 {
107 #ifdef ELM_ETHUMB
108    Ethumb_Client *client;
109 #endif
110    Evas_Object *widget;
111
112    g_return_if_fail(EAIL_IS_THUMB(image));
113 #ifdef ELM_ETHUMB
114    client = elm_thumb_ethumb_client_get();
115    ethumb_client_size_get(client, width, height);
116    return;
117 #endif
118    widget = eail_widget_get_widget(EAIL_WIDGET(image));
119
120    if (!widget)
121      {
122         *width = -1;
123         *height = -1;
124         return;
125      }
126
127    evas_object_geometry_get(widget, NULL, NULL, width, height);
128 }
129
130 /**
131  * @brief AtkImage interface initializer
132  *
133  * @param iface AtkImageIface instance
134  */
135 static void
136 atk_image_iface_init(AtkImageIface *iface)
137 {
138    g_return_if_fail(iface != NULL);
139
140    iface->get_image_size = eail_thumb_size_get;
141 }