summaryrefslogtreecommitdiff
path: root/src/lib/elementary/efl_ui_popup_alert.c
blob: 08097fc8d14c2ead9f640269b421e109b4c2b7a1 (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Elementary.h>

#include "elm_priv.h"
#include "efl_ui_popup_alert_private.h"
#include "efl_ui_popup_alert_part.eo.h"
#include "elm_part_helper.h"

#define MY_CLASS EFL_UI_POPUP_ALERT_CLASS
#define MY_CLASS_NAME "Efl.Ui.Popup_Alert"

static const char PART_NAME_BUTTON[] = "button";
static const char PART_NAME_BUTTON_LAYOUT[EFL_UI_POPUP_ALERT_BUTTON_COUNT][15] =
                                                {"button_layout1",
                                                 "button_layout2",
                                                 "button_layout3"};

static const char BUTTON_SWALLOW_NAME[EFL_UI_POPUP_ALERT_BUTTON_COUNT][20] =
                                                {"efl.button1",
                                                 "efl.button2",
                                                 "efl.button3"};

static Eina_Bool
_efl_ui_popup_alert_text_set(Eo *obj, Efl_Ui_Popup_Alert_Data *pd, const char *part, const char *label)
{
   if (eina_streq(part, "title") || eina_streq(part, "efl.text.title"))
     {
        Eina_Bool changed = eina_stringshare_replace(&pd->title_text, label);
        if (changed)
          {
             efl_text_set(efl_part(efl_super(obj, MY_CLASS), "title"), label);
             if (label)
               elm_layout_signal_emit(obj, "elm,title,show", "elm");
             else
               elm_layout_signal_emit(obj, "elm,title,hide", "elm");

             ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EINA_FALSE);
             edje_object_message_signal_process(wd->resize_obj);
             elm_layout_sizing_eval(obj);
          }
     }
   else
     efl_text_set(efl_part(efl_super(obj, MY_CLASS), part), label);

   return EINA_TRUE;
}

const char *
_efl_ui_popup_alert_text_get(Eo *obj EINA_UNUSED, Efl_Ui_Popup_Alert_Data *pd, const char *part)
{
   if (eina_streq(part, "title") || eina_streq(part, "efl.text.title"))
     {
        if (pd->title_text)
          return pd->title_text;

        return NULL;
     }

   return efl_text_get(efl_part(efl_super(obj, MY_CLASS), part));
}

static void
_positive_button_clicked_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *popup_obj = data;

   Efl_Ui_Popup_Alert_Button_Clicked_Event event;
   event.button_type = EFL_UI_POPUP_ALERT_BUTTON_POSITIVE;

   efl_event_callback_call(popup_obj, EFL_UI_POPUP_ALERT_EVENT_BUTTON_CLICKED, &event);
}

static void
_negative_button_clicked_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *popup_obj = data;

   Efl_Ui_Popup_Alert_Button_Clicked_Event event;
   event.button_type = EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE;

   efl_event_callback_call(popup_obj, EFL_UI_POPUP_ALERT_EVENT_BUTTON_CLICKED, &event);
}

static void
_user_button_clicked_cb(void *data, const Efl_Event *ev EINA_UNUSED)
{
   Eo *popup_obj = data;

   Efl_Ui_Popup_Alert_Button_Clicked_Event event;
   event.button_type = EFL_UI_POPUP_ALERT_BUTTON_USER;

   efl_event_callback_call(popup_obj, EFL_UI_POPUP_ALERT_EVENT_BUTTON_CLICKED, &event);
}

EOLIAN static void
_efl_ui_popup_alert_button_set(Eo *obj, Efl_Ui_Popup_Alert_Data *pd, Efl_Ui_Popup_Alert_Button type, const char *text)
{
   int i;
   Eo *cur_content;
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);

   if ((type < EFL_UI_POPUP_ALERT_BUTTON_POSITIVE) || (type > EFL_UI_POPUP_ALERT_BUTTON_USER))
     {
        ERR("Wrong type (%d) is passed!", type);
        return;
     }
   if (!pd->button[type])
     {
        pd->button[type] = efl_add(EFL_UI_BUTTON_CLASS, obj,
                                   elm_widget_element_update(obj, efl_added,
                                                             PART_NAME_BUTTON));
        switch (type)
          {
            case EFL_UI_POPUP_ALERT_BUTTON_POSITIVE:
              efl_event_callback_add(pd->button[type], EFL_UI_EVENT_CLICKED,
                                     _positive_button_clicked_cb, obj);
              break;
            case EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE:
              efl_event_callback_add(pd->button[type], EFL_UI_EVENT_CLICKED,
                                     _negative_button_clicked_cb, obj);
              break;
            case EFL_UI_POPUP_ALERT_BUTTON_USER:
              efl_event_callback_add(pd->button[type], EFL_UI_EVENT_CLICKED,
                                     _user_button_clicked_cb, obj);
              break;
            default:
              break;
          }
     }
   efl_text_set(pd->button[type], text);

   cur_content = efl_content_get(efl_part(obj, "efl.buttons"));
   if (cur_content)
     {
        for (i = 0; i < EFL_UI_POPUP_ALERT_BUTTON_COUNT; i++)
          efl_content_unset(efl_part(cur_content, BUTTON_SWALLOW_NAME[i]));
     }
   else
     {
        cur_content = efl_add(EFL_UI_LAYOUT_OBJECT_CLASS, obj,
                              efl_content_set(efl_part(obj, "efl.buttons"), efl_added));
     }

   int btn_count = !!pd->button[EFL_UI_POPUP_ALERT_BUTTON_POSITIVE] +
                   !!pd->button[EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE] +
                   !!pd->button[EFL_UI_POPUP_ALERT_BUTTON_USER];
   elm_widget_element_update(obj, cur_content, PART_NAME_BUTTON_LAYOUT[btn_count - 1]);

   i = 0;
   if (pd->button[EFL_UI_POPUP_ALERT_BUTTON_USER])
     {
        efl_content_set(efl_part(cur_content, BUTTON_SWALLOW_NAME[i]),
                                 pd->button[EFL_UI_POPUP_ALERT_BUTTON_USER]);
        i++;
     }
   if (pd->button[EFL_UI_POPUP_ALERT_BUTTON_POSITIVE])
     {
        efl_content_set(efl_part(cur_content, BUTTON_SWALLOW_NAME[i]),
                                 pd->button[EFL_UI_POPUP_ALERT_BUTTON_POSITIVE]);
        i++;
     }
   if (pd->button[EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE])
     {
        efl_content_set(efl_part(cur_content, BUTTON_SWALLOW_NAME[i]),
                                 pd->button[EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE]);
     }

   elm_layout_signal_emit(obj, "elm,efl.buttons,show", "elm");
   edje_object_message_signal_process(wd->resize_obj);
   elm_layout_sizing_eval(obj);
}

EOLIAN static Eo *
_efl_ui_popup_alert_efl_object_constructor(Eo *obj,
                                           Efl_Ui_Popup_Alert_Data *pd EINA_UNUSED)
{
   ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, NULL);

   if (!elm_widget_theme_klass_get(obj))
     elm_widget_theme_klass_set(obj, "popup_alert");
   obj = efl_constructor(efl_super(obj, MY_CLASS));
   efl_canvas_object_type_set(obj, MY_CLASS_NAME);

   elm_widget_sub_object_parent_add(obj);

   return obj;
}

EOLIAN static void
_efl_ui_popup_alert_efl_object_destructor(Eo *obj, Efl_Ui_Popup_Alert_Data *pd)
{
   ELM_SAFE_FREE(pd->title_text, eina_stringshare_del);
   efl_destructor(efl_super(obj, MY_CLASS));
}

static Eina_Bool
_part_is_efl_ui_popup_alert_part(const Eo *obj EINA_UNUSED, const char *part)
{
   return (eina_streq(part, "title") || eina_streq(part, "efl.text.title"));
}

/* Efl.Part begin */
ELM_PART_OVERRIDE_PARTIAL(efl_ui_popup_alert, EFL_UI_POPUP_ALERT,
                          Efl_Ui_Popup_Alert_Data, _part_is_efl_ui_popup_alert_part)
ELM_PART_OVERRIDE_TEXT_SET(efl_ui_popup_alert, EFL_UI_POPUP_ALERT, Efl_Ui_Popup_Alert_Data)
ELM_PART_OVERRIDE_TEXT_GET(efl_ui_popup_alert, EFL_UI_POPUP_ALERT, Efl_Ui_Popup_Alert_Data)
#include "efl_ui_popup_alert_part.eo.c"

/* Efl.Part end */

#include "efl_ui_popup_alert.eo.c"