3 * Copyright 2012 Samsung Electronics Co., Ltd
5 * Licensed under the Flora License, Version 1.1 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://floralicense.org/license
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an AS IS BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 #include "calc-main.h"
21 #include "calc-view.h"
24 extern char calculator_input_str[];
25 extern int calculator_cursor_pos;
27 extern int cur_fontsize;
28 extern int default_fontsize;
31 extern int small_fontsize;
32 extern int scientific_result_len;
34 extern void calc_xxx(struct appdata *ap); /* will be removed */
35 extern void _calc_entry_text_set_rotate(struct appdata *ad);
36 extern void calc_por_pannel_load(struct appdata *ad);
37 extern void calc_lans_pannel_load(struct appdata *ad);
38 Evas_Object *load_edj(Evas_Object * parent, const char *file, const char *group)
43 eo = elm_layout_add(parent);
45 r = elm_layout_file_set(eo, file, group);
50 evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND,
59 * @When rotate to landscape view (Scientific calculation)
60 * @param[in] ad The appdata
61 * @param[in] angle The rotate angle 90 or 270
65 static void __to_landscape(struct appdata *ad, int angle)
71 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
72 calc_lans_pannel_load(ad);
73 edje_object_signal_emit(_EDJ(ad->edje), "landscape", "");
74 elm_win_rotation_with_resize_set(ad->win, angle);
75 //elm_win_rotation_with_resize_set(ad->eo, angle);/*when rotating, resize the window eo*/
76 default_fontsize = 98;
81 scientific_result_len = 13;
82 _calc_entry_text_set_rotate(ad);
83 if (!ad->panel_show) {
84 calc_view_show_histroy(ad->hist_area);
85 edje_object_signal_emit(_EDJ(ad->edje), "show,hist", "");
92 * @When rotate to protrait view (Basic calculation)
93 * @param[in] ad The appdata
94 * @param[in] angle The rotate angle 0 or 180
98 static void __to_portrait(struct appdata *ad, int angle)
104 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
105 calc_por_pannel_load(ad);
106 edje_object_signal_emit(_EDJ(ad->edje), "portrait", "");
107 elm_win_rotation_with_resize_set(ad->win, angle);
108 //elm_win_rotation_with_resize_set(ad->eo, angle);/*when rotating, resize the window eo*/
109 default_fontsize = 70;
114 scientific_result_len = 8;
115 _calc_entry_text_set_rotate(ad);
116 if (!ad->panel_show) {
117 calc_view_show_histroy(ad->hist_area);
118 edje_object_signal_emit(_EDJ(ad->edje), "show,hist", "");
132 static void _rotate(app_device_orientation_e mode, void *data)
138 struct appdata *ad = (struct appdata *)data;
141 case APP_DEVICE_ORIENTATION_0: //[1]0
142 __to_portrait(ad, 0);
145 case APP_DEVICE_ORIENTATION_180: //[2]180
146 __to_portrait(ad, 180);
149 case APP_DEVICE_ORIENTATION_270: //[3]-90
150 __to_landscape(ad, 270);
153 case APP_DEVICE_ORIENTATION_90: //[4]90
154 __to_landscape(ad, 90);
160 if (!ad->panel_show) {
161 calc_view_revise_history_scroller(ad);
163 calc_view_revise_input_scroller(ad);
166 /* When rotate, the size of input scroller will be changed. So it should adjust to cursor position. */
167 calc_view_revise_input_scroller(ad);
181 static void _win_del(void *data, Evas_Object * obj, void *event_info)
194 static int _set_input_entry_focus(void *data)
197 struct appdata *ad = (struct appdata *)data;
198 elm_object_focus_set(ad->input_entry, EINA_TRUE); //set focus
199 _calc_entry_clear(ad->input_entry);
201 return ECORE_CALLBACK_CANCEL; //0
212 static int _load_idle_view(void *data)
215 struct appdata *ad = (struct appdata *)data;
216 calc_view_load_in_idle(ad);
218 return ECORE_CALLBACK_CANCEL; //0
226 * @return Evas_Object*
229 static Evas_Object *_create_win(const char *name)
233 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
235 elm_win_title_set(eo, name);
236 evas_object_smart_callback_add(eo, "delete,request", _win_del,
251 static void _on_exit(struct appdata *ad)
254 if (ad->por_pannel) {
255 evas_object_del(ad->por_pannel);
256 ad->por_pannel = NULL;
259 if (ad->lan_pannel) {
260 evas_object_del(ad->lan_pannel);
261 ad->lan_pannel = NULL;
264 if (ad->input_entry) {
265 evas_object_del(ad->input_entry);
266 ad->input_entry = NULL;
268 if (ad->clear_item) {
269 elm_object_item_del(ad->clear_item);
270 ad->clear_item = NULL;
272 if (ad->more_btn_popup) {
273 evas_object_del(ad->more_btn_popup);
274 ad->more_btn_popup = NULL;
277 evas_object_del(ad->more_btn);
281 elm_object_item_del(ad->navi_it);
286 evas_object_del(ad->nf);
289 if (ad->window_icon) {
290 evas_object_del(ad->window_icon);
291 ad->window_icon = NULL;
295 evas_object_del(ad->hist_area);
296 ad->hist_area = NULL;
299 if (ad->hist_scroll) {
300 evas_object_del(ad->hist_scroll);
301 ad->hist_scroll = NULL;
306 evas_object_del(ad->edje);
311 evas_object_del(ad->layout);
316 evas_object_del(ad->bg);
321 evas_object_del(ad->win);
326 if (ad->calc_timer) {
327 ecore_timer_del(ad->calc_timer);
328 ad->calc_timer = NULL;
330 if (ad->wrong_timer) {
331 ecore_timer_del(ad->wrong_timer);
332 ad->wrong_timer = NULL;
335 feedback_deinitialize();
348 static bool app_create(void *data)
351 struct appdata *ad = (struct appdata *)data;
353 /* Use elm_theme_extension_add() API before creating any widgets */
354 elm_theme_extension_add(NULL, CALCULATOR_THEME);
357 ad->win = _create_win(PACKAGE);
358 if (ad->win == NULL) {
361 evas_object_smart_callback_add(ad->win, "profile,changed", win_profile_changed_cb, ad);
362 evas_object_show(ad->win);
364 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
366 /* will be removed */
371 ad->panel_show = EINA_TRUE;
374 int ret = vconf_get_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &value);
377 _rotate(APP_DEVICE_ORIENTATION_0, ad);
379 app_device_orientation_e curr = app_get_device_orientation();
383 app_device_orientation_e curr = app_get_device_orientation();
386 /* register callback */
387 ecore_idler_add((Ecore_Task_Cb) _set_input_entry_focus, ad);
388 ecore_idler_add((Ecore_Task_Cb) _load_idle_view, ad);
390 return TRUE; //EXIT_SUCCESS
402 static void app_terminate(void *data)
404 // Release all resources
405 struct appdata *ad = (struct appdata *)data;
417 static void app_pause(void *data)
419 // Take necessary actions when application becomes invisible
430 static void app_resume(void *data)
432 // Take necessary actions when application becomes visible.
433 struct appdata *ad = (struct appdata *)data;
434 elm_object_focus_set(ad->input_entry, EINA_TRUE);
439 * The entry of the program
446 int main(int argc, char *argv[])
451 app_event_callback_s event_callback;
453 event_callback.create = app_create;
454 event_callback.terminate = app_terminate;
455 event_callback.pause = app_pause;
456 event_callback.resume = app_resume;
457 event_callback.service = NULL;
458 event_callback.low_memory = NULL;
459 event_callback.low_battery = NULL;
460 event_callback.device_orientation = _rotate;
461 event_callback.language_changed = NULL;
462 event_callback.region_format_changed = NULL;
464 memset(&ad, 0x0, sizeof(struct appdata));
466 return app_efl_main(&argc, &argv, &event_callback, &ad);