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,
53 static const int h=2*300,w=2*200;
54 evas_object_size_hint_min_set(eo, w, h);
63 * @When rotate to landscape view (Scientific calculation)
64 * @param[in] ad The appdata
65 * @param[in] angle The rotate angle 90 or 270
69 static void __to_landscape(struct appdata *ad, int angle)
75 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
76 calc_lans_pannel_load(ad);
77 edje_object_signal_emit(_EDJ(ad->edje), "landscape", "");
78 elm_win_rotation_with_resize_set(ad->win, angle);
79 //elm_win_rotation_with_resize_set(ad->eo, angle);/*when rotating, resize the window eo*/
80 default_fontsize = 98;
85 scientific_result_len = 13;
86 _calc_entry_text_set_rotate(ad);
87 if (!ad->panel_show) {
88 calc_view_show_histroy(ad->hist_area);
89 edje_object_signal_emit(_EDJ(ad->edje), "show,hist", "");
96 * @When rotate to protrait view (Basic calculation)
97 * @param[in] ad The appdata
98 * @param[in] angle The rotate angle 0 or 180
102 static void __to_portrait(struct appdata *ad, int angle)
108 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
109 calc_por_pannel_load(ad);
110 edje_object_signal_emit(_EDJ(ad->edje), "portrait", "");
111 elm_win_rotation_with_resize_set(ad->win, angle);
112 //elm_win_rotation_with_resize_set(ad->eo, angle);/*when rotating, resize the window eo*/
113 default_fontsize = 70;
118 scientific_result_len = 8;
119 _calc_entry_text_set_rotate(ad);
120 if (!ad->panel_show) {
121 calc_view_show_histroy(ad->hist_area);
122 edje_object_signal_emit(_EDJ(ad->edje), "show,hist", "");
136 static void _rotate(app_device_orientation_e mode, void *data)
142 struct appdata *ad = (struct appdata *)data;
145 case APP_DEVICE_ORIENTATION_0: //[1]0
146 __to_portrait(ad, 0);
149 case APP_DEVICE_ORIENTATION_180: //[2]180
150 __to_portrait(ad, 180);
153 case APP_DEVICE_ORIENTATION_270: //[3]-90
154 __to_landscape(ad, 270);
157 case APP_DEVICE_ORIENTATION_90: //[4]90
158 __to_landscape(ad, 90);
164 if (!ad->panel_show) {
165 calc_view_revise_history_scroller(ad);
167 calc_view_revise_input_scroller(ad);
170 /* When rotate, the size of input scroller will be changed. So it should adjust to cursor position. */
171 calc_view_revise_input_scroller(ad);
185 static void _win_del(void *data, Evas_Object * obj, void *event_info)
198 static int _set_input_entry_focus(void *data)
201 struct appdata *ad = (struct appdata *)data;
202 elm_object_focus_set(ad->input_entry, EINA_TRUE); //set focus
203 _calc_entry_clear(ad->input_entry);
205 return ECORE_CALLBACK_CANCEL; //0
216 static int _load_idle_view(void *data)
219 struct appdata *ad = (struct appdata *)data;
220 calc_view_load_in_idle(ad);
222 return ECORE_CALLBACK_CANCEL; //0
230 * @return Evas_Object*
233 static Evas_Object *_create_win(const char *name)
238 eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
240 elm_win_title_set(eo, name);
241 evas_object_smart_callback_add(eo, "delete,request", _win_del,
243 elm_win_screen_size_get(eo, NULL, NULL, &w, &h);
247 w = ( t < w ) ? t : w;
249 evas_object_resize(eo, w, h);
263 static void _on_exit(struct appdata *ad)
266 if (ad->por_pannel) {
267 evas_object_del(ad->por_pannel);
268 ad->por_pannel = NULL;
271 if (ad->lan_pannel) {
272 evas_object_del(ad->lan_pannel);
273 ad->lan_pannel = NULL;
276 if (ad->input_entry) {
277 evas_object_del(ad->input_entry);
278 ad->input_entry = NULL;
280 if (ad->clear_item) {
281 elm_object_item_del(ad->clear_item);
282 ad->clear_item = NULL;
284 if (ad->more_btn_popup) {
285 evas_object_del(ad->more_btn_popup);
286 ad->more_btn_popup = NULL;
289 evas_object_del(ad->more_btn);
293 elm_object_item_del(ad->navi_it);
298 evas_object_del(ad->nf);
301 if (ad->window_icon) {
302 evas_object_del(ad->window_icon);
303 ad->window_icon = NULL;
307 evas_object_del(ad->hist_area);
308 ad->hist_area = NULL;
311 if (ad->hist_scroll) {
312 evas_object_del(ad->hist_scroll);
313 ad->hist_scroll = NULL;
318 evas_object_del(ad->edje);
323 evas_object_del(ad->bg);
328 evas_object_del(ad->win);
333 if (ad->calc_timer) {
334 ecore_timer_del(ad->calc_timer);
335 ad->calc_timer = NULL;
337 if (ad->wrong_timer) {
338 ecore_timer_del(ad->wrong_timer);
339 ad->wrong_timer = NULL;
342 feedback_deinitialize();
355 static bool app_create(void *data)
358 struct appdata *ad = (struct appdata *)data;
360 /* Use elm_theme_extension_add() API before creating any widgets */
361 elm_theme_extension_add(NULL, CALCULATOR_THEME);
364 ad->win = _create_win(PACKAGE);
365 if (ad->win == NULL) {
368 evas_object_smart_callback_add(ad->win, "profile,changed", win_profile_changed_cb, ad);
369 evas_object_show(ad->win);
371 elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
373 /* will be removed */
378 ad->panel_show = EINA_TRUE;
381 int ret = vconf_get_bool(VCONFKEY_SETAPPL_ROTATE_LOCK_BOOL, &value);
384 _rotate(APP_DEVICE_ORIENTATION_0, ad);
386 app_device_orientation_e curr = app_get_device_orientation();
390 app_device_orientation_e curr = app_get_device_orientation();
393 /* register callback */
394 ecore_idler_add((Ecore_Task_Cb) _set_input_entry_focus, ad);
395 ecore_idler_add((Ecore_Task_Cb) _load_idle_view, ad);
397 return EINA_TRUE; //EXIT_SUCCESS
409 static void app_terminate(void *data)
411 // Release all resources
412 struct appdata *ad = (struct appdata *)data;
424 static void app_pause(void *data)
426 // Take necessary actions when application becomes invisible
437 static void app_resume(void *data)
439 // Take necessary actions when application becomes visible.
440 struct appdata *ad = (struct appdata *)data;
441 elm_object_focus_set(ad->input_entry, EINA_TRUE);
446 * The entry of the program
453 int main(int argc, char *argv[])
458 app_event_callback_s event_callback;
460 event_callback.create = app_create;
461 event_callback.terminate = app_terminate;
462 event_callback.pause = app_pause;
463 event_callback.resume = app_resume;
464 event_callback.service = NULL;
465 event_callback.low_memory = NULL;
466 event_callback.low_battery = NULL;
467 event_callback.device_orientation = _rotate;
468 event_callback.language_changed = NULL;
469 event_callback.region_format_changed = NULL;
471 memset(&ad, 0x0, sizeof(struct appdata));
473 return app_efl_main(&argc, &argv, &event_callback, &ad);