e21ad6353f8abfb28a69056e184fdb7a64983d0d
[apps/core/preloaded/calculator.git] / include / calc-main.h
1 /*
2 *
3 * Copyright 2012  Samsung Electronics Co., Ltd
4 *
5 * Licensed under the Flora License, Version 1.0 (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
8 *
9 *    http://floralicense.org/license
10 *
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.
16 *
17 */
18
19 #ifndef __DEF_CALCULATOR_H_
20 #define __DEF_CALCULATOR_H_
21
22 #include <Elementary.h>
23 #include <stdlib.h>
24 #include <limits.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdbool.h>
28 #include <dlog.h>
29 #include <app.h>
30
31 /* Path & Name */
32 #define PACKAGE                                 "calculator"
33 #define LAYOUT_EDJ_NAME                 EDJDIR"/calculator.edj"
34 #define CALCULATOR_THEME                EDJDIR"/calculator_theme.edj"
35
36 #define GRP_MAIN                                "main"
37 #define GRP_POR_PANNEL                  "por_pannel"
38 #define GRP_LAN_PANNEL                  "lan_pannel"
39 #define GRP_APPINAPP_MAIN                       "appinapp.main"
40 #define GRP_MINI_PANNEL                 "mini_pannel"
41 #define GRP_MINI_TITLE  "mini/title"
42 //#define COM_SAMSUNG_S           "com.samsung.%s"
43
44 #define SAVE_HISTORY
45
46 /* Max */
47 #define MAX_FONT_SIZE           44
48 #define NUMBER_LENGTH 1024
49 #define MAX_EXPRESSION_LENGTH   1024
50 #define MAX_RESULT_LENGTH       1024
51 #define MAX_ERROR_MESSAGE_LENGTH  256
52
53 //#define MAX_TAG_EXPRESSION_LENGTH 4096
54 #define MAX_TAG_EXPRESSION_LENGTH 420*48
55
56 //#define MAX_RESULT_LENGTH       128
57
58 #define MAX_HISTORY_NUM         10
59 #define MAX_DECIMAL_NUM         5
60 #define MAX_NUM_LENGTH          15
61 #define MAX_OPERATOR_NUM        20
62 #define MAX_PARENTHESES_NUM     64
63
64 /* Math */
65 #define PI                                      3.1415926535897932384626433832795
66 #define EXPONENT                                2.718281828459045235360287471352662497757
67 #define RADIAN_FACTOR                   (PI/180)
68 #define DEGREEN_FACTOR                  (180/PI)
69 #define PI_STR                                  "3.1415926535897932384626433832795"
70 #define EXPONENT_STR                    "2.718281828459045235360287471352662497757"
71
72 /* Function */
73 #ifndef _EDJ
74 #define _EDJ(x) (Evas_Object *)elm_layout_edje_get(x)
75 #endif                          /* _EDJ */
76
77 #ifndef _
78 #define _(str) gettext(str)
79 #endif                          /* _ */
80
81 #ifndef gettext_noop
82 #define gettext_noop(str) (str)
83 #endif                          /* gettext_noop */
84
85 #ifndef N_
86 #define N_(str) gettext_noop(str)
87 #endif                          /* N_ */
88
89 #define SFREE(var)\
90         if(var != NULL){\
91                 free((void *)var);\
92                 var = NULL;\
93                 }\
94
95 #define CALCULATOR_CONTENT_LEN                                  32
96
97 #define CALCULATOR_MAX_RESULT_SUM2                              (10e+100)                               /**<maximum num of result sum*/
98 #define CALCULATOR_MIN_RESULT_SUM2                              (-10e+100)                              /**<minimum num of result sum*/
99
100 /* BEGIN DEBUG LOG MACRO */
101 #ifdef  LOG_TAG
102 #undef  LOG_TAG
103 #endif
104 #define LOG_TAG "CALCULATOR"
105
106 #define CALC_INFO(fmt, arg...) LOGD("[%s:%d] "fmt,__FILE__, __LINE__, ##arg);
107 #define FONT_COLOR_RESET    "\033[0m"
108 #define FONT_COLOR_RED      "\033[31m"
109 #define FONT_COLOR_GREEN    "\033[32m"
110 #define FONT_COLOR_YELLOW   "\033[33m"
111 #define FONT_COLOR_BLUE     "\033[34m"
112 #define FONT_COLOR_PURPLE   "\033[35m"
113 #define FONT_COLOR_CYAN     "\033[36m"
114 #define FONT_COLOR_GRAY     "\033[37m"
115
116 #define CALC_INFO_RED(fmt, arg...) CALC_INFO(FONT_COLOR_RED fmt FONT_COLOR_RESET, ##arg)
117 #define CALC_INFO_GREEN(fmt, arg...) CALC_INFO(FONT_COLOR_GREEN fmt FONT_COLOR_RESET, ##arg)
118 #define CALC_INFO_YELLOW(fmt, arg...) CALC_INFO(FONT_COLOR_YELLOW fmt FONT_COLOR_RESET, ##arg)
119 #define CALC_INFO_BLUE(fmt, arg...) CALC_INFO(FONT_COLOR_BLUE fmt FONT_COLOR_RESET, ##arg)
120 #define CALC_INFO_PURPLE(fmt, arg...) CALC_INFO(FONT_COLOR_PURPLE fmt FONT_COLOR_RESET, ##arg)
121 #define CALC_INFO_CYAN(fmt, arg...) CALC_INFO(FONT_COLOR_CYAN fmt FONT_COLOR_RESET, ##arg)
122 #define CALC_INFO_GRAY(fmt, arg...) CALC_INFO(FONT_COLOR_GRAY fmt FONT_COLOR_RESET, ##arg)
123
124
125 //#define PERFORMANCE_LOG
126 #ifdef PERFORMANCE_LOG
127 #define DBG(fmt, arg...) SLOGD("%s(%d) " fmt, __FUNCTION__, __LINE__, ##arg)
128 #define CALC_FUN_BEG() DBG("START")
129 #define CALC_FUN_END() DBG("END")
130 #else
131 #define CALC_FUN_BEG()  LOG(LOG_DEBUG,"LAUNCH","[calculator:Application:%s:IN]", __FUNCTION__);
132 #define CALC_FUN_END()  LOG(LOG_DEBUG,"LAUNCH","[calculator:Application:%s:OUT]", __FUNCTION__);
133 #endif
134
135 /* Help String of UI Guideline */
136 #define CALC_MSG_MAX_DIGIT                  _("IDS_CCL_POP_UP_TO_15_DIGITS_AVAILABLE")
137 #define CALC_MSG_MAX_DEC_DIGIT          _("IDS_CCL_POP_UP_TO_5_DECIMALS_AVAILABLE")
138 #define CALC_MSG_MAX_OP                     _("IDS_CCL_POP_UP_TO_20_OPERATORS_AVAILABLE")
139 #define CALC_MSG_DIVIDE_BY_ZERO         _("IDS_CCL_POP_UNABLE_TO_DIVIDE_BY_ZERO")
140 #define CALC_MSG_NUM_FIRST                  _("IDS_CCL_POP_NO_NUMBER_ERROR")
141 #define CALC_MSG_OUT_OF_RANGE           _("IDS_CCL_POP_ERROR")
142 #define CALC_MSG_NUM_AFTER_OP           _("IDS_CCL_POP_ENTER_NUMBER_AFTER_OPERATOR")
143 #define CALC_MSG_INVALID_SQUARE         _("IDS_CCL_BODY_INVALID_INPUT_FOR_SQUARE_ROOT_FUNCTION")
144 #define CALC_MSG_INVALID_LOG            _("IDS_CCL_BODY_INVALID_INPUT_FOR_LOG_FUNCTION")
145 #define CALC_MSG_INVALID_FAC            _("IDS_CCL_BODY_NATURAL_NUMBER_ONLY_FOR_X_E_FUNCTION")
146 #define CALC_MSG_NUM_FIRST_FAC          _("IDS_CCL_BODY_ENTER_NUMBER_BEFORE_INPUTTING_X_E_FUNCTION")
147 #define CALC_MSG_NUM_FIRST_RECIP        _("IDS_CCL_BODY_ENTER_NUMBER_BEFORE_INPUTTING_1_X_FUNCTION")
148 #define CALC_MSG_NUM_FIRST_X2           _("IDS_CCL_BODY_ENTER_NUMBER_BEFORE_INPUTTING_X2_FUNCTION")
149 #define CALC_MSG_NUM_FIRST_XY           _("IDS_CCL_BODY_ENTER_NUMBER_BEFORE_INPUTTING_XY_FUNCTION")
150
151 /* Custtom Error Message */
152 #define CALC_MSG_OP_FIRST                   _("IDS_CCL_POP_NO_OPERATOR_ERROR")
153 #define CALC_MSG_SYNTAX_ERROR       _("IDS_CCL_POP_SYNTAX_ERROR")
154 #define CALC_MSG_WRONG_FORMAT       _("IDS_CCL_POP_INPUT_ERROR")
155
156 #define CALC_MSG_CLEAR_HISTTORY      _("IDS_CCL_OPT_CLEAR_HISTORY")
157 #define CALC_MSG_MINIMISE      _("IDS_CCL_OPT_MINIMISE")
158 #define CALC_MSG_MINIMODE_TITLE      _("IDS_CCL_BODY_CALCULATOR")
159
160 #if 0
161 #define CALC_MSG_INVALID_LN         _("Invalid input for ln function")
162 #define CALC_MSG_INVALID_XY         _("Invalid param for x^y")
163 #define CALC_MSG_INVALID_TAN        _("Invalid param for tan")
164 #define CALC_MSG_ENTRY_LIMIT        _("Already had decimal in digit")
165 #endif
166 #define ARRAY_SIZE(array)  (sizeof(array)/sizeof(array[0]))
167
168
169 #define DESKTOP_MODE_ICON      "/opt/share/icons/default/small/com.samsung.calculator.png"
170
171 struct appdata {
172         Evas_Object *win;       //main window
173         Evas_Object *bg;
174         Evas_Object *conform;
175         Evas_Object *layout;
176         Evas_Object *edje;
177         Evas_Object *eo;
178
179         Evas_Object *input_scroller;
180         Evas_Object *input_entry;
181         Evas_Object *por_pannel;
182         Evas_Object *lan_pannel;
183         Evas_Object *back_btn;
184
185         Ecore_Timer *calc_timer;
186         Ecore_Timer *wrong_timer;
187
188         Evas_Object *nf;
189         Elm_Object_Item *navi_it;
190         Evas_Object *more_btn;
191         Evas_Object *more_btn_popup;
192         Elm_Object_Item *clear_item;
193 #ifdef SAVE_HISTORY
194         Evas_Object *hist_scroll;
195         Evas_Object *hist_area;
196         Eina_Bool panel_show;
197 #endif
198         Evas_Object *window_icon;  //only show it when in desktop mode;
199 };
200
201 /**
202 * @describe
203 *       Load edj file from group to elm_layout.
204 *
205 * @param    parent
206 * @param    file
207 * @param    group
208 * @return
209 * @exception
210 */
211 Evas_Object *load_edj(Evas_Object * parent, const char *file,
212                       const char *group);
213 void _calc_entry_clear(Evas_Object * entry);
214
215 #endif                          /* __DEF_CALCULATOR_H__ */