tizen 2.4 release
[framework/uifw/elementary.git] / src / examples / box_cxx_example_02.cc
1 //Compile with:
2 //gcc -g box_example_02.c -o box_example_02 `pkg-config --cflags --libs elementary`
3
4
5 extern "C"
6 {
7
8 #ifdef HAVE_CONFIG_H
9 # include <elementary_config.h>
10 #endif
11
12 #define ELM_INTERNAL_API_ARGESFSDFEFC
13 #define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
14 #define ELM_INTERFACE_ATSPI_COMPONENT_PROTECTED
15 #define ELM_INTERFACE_ATSPI_ACTION_PROTECTED
16 #define ELM_INTERFACE_ATSPI_VALUE_PROTECTED
17 #define ELM_INTERFACE_ATSPI_EDITABLE_TEXT_PROTECTED
18 #define ELM_INTERFACE_ATSPI_TEXT_PROTECTED
19 #define ELM_INTERFACE_ATSPI_SELECTION_PROTECTED
20 #define ELM_INTERFACE_ATSPI_IMAGE_PROTECTED
21 #define ELM_INTERFACE_ATSPI_WIDGET_ACTION_PROTECTED
22
23 #include <Elementary.h>
24
25 #include <Eo.h>
26 #include <Evas.h>
27 #include <Elementary.h>
28 #include <elm_widget.h>
29
30 #include "elm_interface_atspi_accessible.h"
31 #include "elm_interface_atspi_accessible.eo.h"
32
33 #include "elm_interface_atspi_widget_action.h"
34 #include "elm_interface_atspi_widget_action.eo.h"
35 }
36
37 #include <iostream>
38
39 #include <elm_win.eo.hh>
40 #include <elm_box.eo.hh>
41 #include <elm_button.eo.hh>
42
43 #include <Eina.hh>
44
45 #include <deque>
46
47 struct Transitions_Data
48 {
49    efl::eo::wref<elm_box> box;
50    std::deque<Evas_Object_Box_Layout> transitions;
51    Evas_Object_Box_Layout last_layout;
52 };
53
54 static void
55 _test_box_transition_change(void *data)
56 {
57    Transitions_Data *tdata = static_cast<Transitions_Data*>(data);
58    Elm_Box_Transition *layout_data;
59    Evas_Object_Box_Layout next_layout;
60
61    assert (!!data);
62    assert (!tdata->transitions.empty());
63
64    if(efl::eina::optional<elm_box> box = tdata->box.lock())
65      {
66         next_layout = tdata->transitions.front();
67         layout_data = elm_box_transition_new(2.0, tdata->transitions.back(),
68                                              nullptr, nullptr, next_layout, nullptr, nullptr,
69                                              _test_box_transition_change, tdata);
70         box->layout_set(elm_box_layout_transition, layout_data,
71                         elm_box_transition_free);
72         tdata->last_layout = next_layout;
73        
74         tdata->transitions.push_back(tdata->transitions[0]);
75         tdata->transitions.pop_front();
76      }
77 }
78
79 struct clean_ref
80 {
81   clean_ref(efl::eo::base base)
82     : _ref(base._eo_ptr())
83   {}
84
85   template <typename T>
86   void operator()(T const&, Eo_Event_Description const&, void*) const
87   {
88     if(_ref)
89       eo_unref(_ref);
90   }
91
92   Eo* _ref;
93 };
94
95 EAPI_MAIN int
96 elm_main(int argc, char *argv[])
97 {
98    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
99
100    Transitions_Data tdata;
101    Eo* test;
102
103    {
104      ::elm_win win (elm_win_util_standard_add("box-transition", "Box Transition"));
105      win.autodel_set(true);
106
107      elm_box bigbox ( efl::eo::parent = win );
108      bigbox.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
109      win.resize_object_add(bigbox);
110      bigbox.visibility_set(true);
111      win.callback_del_add(clean_ref(bigbox));
112
113      elm_box buttons ( efl::eo::parent = win );
114      buttons.horizontal_set(EINA_TRUE);
115      bigbox.pack_end(buttons);
116      buttons.visibility_set(true);
117      win.callback_del_add(clean_ref(buttons));
118
119      elm_button add ( efl::eo::parent = win );
120      add.text_set("elm.text", "Add");
121      buttons.pack_end(add);
122      add.visibility_set(true);
123      add.callback_clicked_add
124        (std::bind([&tdata]
125         {
126           if(efl::eina::optional<elm_box> box = tdata.box.lock())
127           {
128             elm_button btn ( efl::eo::parent = *box );
129             btn.text_set("elm.text", "I do nothing");
130             efl::eina::list<evas::object> childrens(box->children_get());
131             if (!childrens.empty())
132               {
133                 box->pack_after(btn, childrens.front());
134               }
135             else
136               box->pack_end(btn);
137             btn.visibility_set(true);
138           }
139         }));
140      win.callback_del_add(clean_ref(add));
141
142      elm_button clear ( efl::eo::parent = win );
143      clear.text_set("elm.text", "Clear");
144      buttons.pack_end(clear);
145      clear.visibility_set(true);
146      clear.callback_clicked_add(std::bind([&tdata] { tdata.box.lock()->clear(); }));
147      win.callback_del_add(clean_ref(clear));
148
149      elm_box dynamic ( efl::eo::parent = win );
150      dynamic.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
151      dynamic.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL);
152      bigbox.pack_end(dynamic);
153      dynamic.visibility_set(true);
154      win.callback_del_add(clean_ref(dynamic));
155
156      auto unpack = std::bind([&tdata] (evas::clickable_interface obj)
157        {
158          elm_button btn = efl::eo::downcast<elm_button>(obj);
159          tdata.box.lock()->unpack(btn);
160          btn.position_set(0, 50);
161          btn.color_set(128, 64, 0, 128);
162        }, std::placeholders::_1)
163      ;
164
165      elm_button bt1 ( efl::eo::parent = win );
166      bt1.text_set("elm.text", "Button 1");
167      bt1.callback_clicked_add(unpack);
168      bt1.size_hint_weight_set(EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
169      bt1.size_hint_align_set(EVAS_HINT_FILL, EVAS_HINT_FILL);
170      dynamic.pack_end(bt1);
171      bt1.visibility_set(true);
172      win.callback_del_add(clean_ref(bt1));
173
174      elm_button bt2 ( efl::eo::parent = win );
175      bt2.text_set("elm.text", "Button 2");
176      bt2.size_hint_weight_set(EVAS_HINT_EXPAND, 0.0);
177      bt2.size_hint_align_set(1.0, 0.5);
178      bt2.callback_clicked_add(unpack);
179      dynamic.pack_end(bt2);
180      bt2.visibility_set(true);
181      win.callback_del_add(clean_ref(bt2));
182
183      elm_button bt3 ( efl::eo::parent = win );
184      bt3.text_set("elm.text", "Button 3");
185      bt3.callback_clicked_add(unpack);
186      dynamic.pack_end(bt3);
187      bt3.visibility_set(true);
188      win.callback_del_add(clean_ref(bt3));
189
190      tdata.box = dynamic;
191      tdata.last_layout = evas_object_box_layout_horizontal;
192      tdata.transitions.push_back(evas_object_box_layout_vertical);
193      tdata.transitions.push_back(evas_object_box_layout_horizontal);
194      tdata.transitions.push_back(evas_object_box_layout_stack);
195      tdata.transitions.push_back(evas_object_box_layout_homogeneous_vertical);
196      tdata.transitions.push_back(evas_object_box_layout_homogeneous_horizontal);
197      tdata.transitions.push_back(evas_object_box_layout_flow_vertical);
198      tdata.transitions.push_back(evas_object_box_layout_flow_horizontal);
199      tdata.transitions.push_back(evas_object_box_layout_stack);
200
201      dynamic.layout_set(evas_object_box_layout_horizontal, nullptr, nullptr);
202      _test_box_transition_change(&tdata);
203    
204      win.size_set(300, 320);
205      win.visibility_set(true);
206
207      std::cout << "references to win " << win.ref_get() << std::endl;
208      test = win._eo_ptr();
209      win._release();
210    }
211    std::cout << "references to win " << ::eo_ref_get(test) << std::endl;
212   
213    elm_run();
214    elm_shutdown();
215
216    return 0;
217 }
218 ELM_MAIN()