Tizen 2.0 Release
[profile/ivi/libscl-ui.git] / xmlresource / layout_parser_helper.cpp
1 /*
2  * Copyright 2012-2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include "layout_parser_helper.h"
19 #include <stdio.h>
20 #include <string>
21 using namespace std;
22
23 const string RotationHelper::pcPortrait = "portrait";
24 const string RotationHelper::pcLandscape = "landscape";
25
26 const string RotationHelper::toString(const int val) {
27     switch (val) {
28         case PORTRAIT:
29             return pcPortrait;
30         case LANDSCAPE:
31             return pcLandscape;
32         default:
33             return pcLandscape;
34     }
35 }
36 const int RotationHelper::Int(const string str) {
37     if (str ==  pcPortrait) {
38         return PORTRAIT;
39     } else if (str ==  pcLandscape) {
40         return LANDSCAPE;
41     } else {
42         return PORTRAIT;
43     }
44 }
45
46 ////////////////////////////////////////////////////////////
47 const string PopStyleHelper::pcBase = "base";
48 const string PopStyleHelper::pcPopup = "popup";
49 const string PopStyleHelper::pcPopup_Grab = "popup_grab";
50 const string PopStyleHelper::toString(const int val) {
51     switch (val) {
52         case BASE:
53             return pcBase;
54         case POPUP:
55             return pcPopup;
56         case POPUP_GRAB:
57             return pcPopup_Grab;
58         default:
59             return pcBase;
60     }
61 }
62
63 const int PopStyleHelper::Int(const string str) {
64     if (str ==  pcBase) {
65         return BASE;
66     } else if (str ==  pcPopup) {
67         return POPUP;
68     } else if (str ==  pcPopup_Grab) {
69         return POPUP_GRAB;
70     } else {
71         return BASE;
72     }
73 }
74
75 ///////////////////////////////////////////////////////
76
77 const string ButtonTypeHelper::pcNormal = "normal";
78 const string ButtonTypeHelper::pcGrab = "grab";
79 const string ButtonTypeHelper::pcSelfish = "selfish";
80 const string ButtonTypeHelper::pcDrag = "drag";
81 const string ButtonTypeHelper::pcMultitap = "multitap";
82 const string ButtonTypeHelper::pcRotation = "rotation";
83 const string ButtonTypeHelper::pcDirection = "direction";
84 const string ButtonTypeHelper::pcRelative_Direction = "relative_direction";
85 const string ButtonTypeHelper::pcUiitem = "uiitem";
86
87 const string ButtonTypeHelper::toString(const int val) {
88     switch (val) {
89         case NORMAL:
90             return pcNormal;
91         case GRAB:
92             return pcGrab;
93         case SELFISH:
94             return pcSelfish;
95         case DRAG:
96             return pcDrag;
97         case MULTITAP:
98             return pcMultitap;
99         case ROTATION:
100             return pcRotation;
101         case DIRECTION:
102             return pcDirection;
103         case RELATIVE_DIRECTION:
104             return pcRelative_Direction;
105         case UIITEM:
106             return pcUiitem;
107         default:
108             return pcNormal;
109     }
110 }
111
112 const int ButtonTypeHelper::Int(const string str) {
113     if (str ==  pcNormal) {
114         return NORMAL;
115     } else if (str ==  pcGrab) {
116         return GRAB;
117     } else if (str ==  pcSelfish) {
118         return SELFISH;
119     } else if (str ==  pcDrag) {
120         return DRAG;
121     } else if (str ==  pcMultitap) {
122         return MULTITAP;
123     } else if (str ==  pcRotation) {
124         return ROTATION;
125     } else if (str ==  pcDirection) {
126         return DIRECTION;
127     } else if (str ==  pcRelative_Direction) {
128         return RELATIVE_DIRECTION;
129     } else if (str ==  pcUiitem) {
130         return UIITEM;
131     } else {
132         return NORMAL;
133     }
134 }
135 ////////////////////////////////////////////////////
136 const string ShiftStateHelper::pcOn = "on";
137 const string ShiftStateHelper::pcOff = "off";
138 const string ShiftStateHelper::pcLoc = "loc";
139
140 const string ShiftStateHelper::toString(const int val) {
141     switch (val) {
142         case ON:
143             return pcOn;
144         case OFF:
145             return pcOff;
146         case LOC:
147             return pcLoc;
148         default:
149             return pcOn;
150     }
151 }
152
153 const int ShiftStateHelper::Int(const string str) {
154     if (str ==  pcOn) {
155         return ON;
156     } else if (str ==  pcOff) {
157         return OFF;
158     } else if (str ==  pcLoc) {
159         return LOC;
160     } else {
161         return ON;
162     }
163 }
164 /////////////////////////////////////////////////////////
165 const string ButtonStateHelper::pcNormal = "normal";
166 const string ButtonStateHelper::pcPressed = "pressed";
167 const string ButtonStateHelper::pcDisabled = "disabled";
168 const string ButtonStateHelper::toString(const int val) {
169     switch (val) {
170         case NORMAL:
171             return pcNormal;
172         case PRESSED:
173             return pcPressed;
174         case DISABLED:
175             return pcDisabled;
176         default:
177             return pcNormal;
178     }
179 }
180 const int ButtonStateHelper::Int(const string str) {
181     if (str ==  pcNormal) {
182         return NORMAL;
183     } else if (str ==  pcPressed) {
184         return PRESSED;
185     } else if (str ==  pcDisabled) {
186         return DISABLED;
187     } else {
188         return NORMAL;
189     }
190 }
191 ///////////////////////////////////////////////////
192 const string KeyTypeHelper::pcNone = "none";
193 const string KeyTypeHelper::pcChar = "char";
194 const string KeyTypeHelper::pcControl = "control";
195 const string KeyTypeHelper::pcModechange = "modechange";
196 const string KeyTypeHelper::pcString = "string";
197 const string KeyTypeHelper::pcUser = "user";
198 const string KeyTypeHelper::toString(const int val) {
199     switch (val) {
200         case NONE:
201             return pcNone;
202         case CHAR:
203             return pcChar;
204         case CONTROL:
205             return pcControl;
206         case MODECHANGE:
207             return pcModechange;
208         case STRING:
209             return pcString;
210         case USER:
211             return pcUser;
212         default:
213             return pcNone;
214     }
215 }
216
217 const int KeyTypeHelper::Int(const string str) {
218     if (str ==  pcNone) {
219         return NONE;
220     } else if (str ==  pcChar) {
221         return CHAR;
222     } else if (str ==  pcControl) {
223         return CONTROL;
224     } else if (str ==  pcModechange) {
225         return MODECHANGE;
226     } else if (str ==  pcString) {
227         return STRING;
228     } else if (str ==  pcUser) {
229         return USER;
230     } else {
231         return NONE;
232     }
233 }
234 /////////////////////////////////////////////////////////
235 const string PopupTypeHelper::pcNone = "none";
236 const string PopupTypeHelper::pcBtn_Release_Popup = "release_popup";
237 const string PopupTypeHelper::pcBtn_Release_Popup_Once = "release_popup_once";
238 const string PopupTypeHelper::pcBtn_Press_Popup_Drag = "press_popup_drag";
239 const string PopupTypeHelper::pcLongpress_Popup = "longpress_popup";
240 const string PopupTypeHelper::pcLongpress_Popup_Once = "longpress_popup_once";
241 const string PopupTypeHelper::pcAuto_Popup = "auto_popup";
242
243 const string PopupTypeHelper::toString(const int val) {
244     switch (val) {
245         case NONE:
246             return pcNone;
247         case BTN_RELEASE_POPUP:
248             return pcBtn_Release_Popup;
249         case BTN_RELEASE_POPUP_ONCE:
250             return pcBtn_Release_Popup_Once;
251         case BTN_PRESS_POPUP_DRAG:
252             return pcBtn_Press_Popup_Drag;
253         case LONGPRESS_POPUP:
254             return pcLongpress_Popup;
255         case LONGPRESS_POPUP_ONCE:
256             return pcLongpress_Popup_Once;
257         case AUTO_POPUP:
258             return pcAuto_Popup;
259         default:
260             return pcNone;
261     }
262 }
263 const int PopupTypeHelper::Int(const string str) {
264     if (str ==  pcNone) {
265         return NONE;
266     } else if (str ==  pcBtn_Release_Popup) {
267         return BTN_RELEASE_POPUP;
268     } else if (str ==  pcBtn_Release_Popup_Once) {
269         return BTN_RELEASE_POPUP_ONCE;
270     } else if (str ==  pcBtn_Press_Popup_Drag) {
271         return BTN_PRESS_POPUP_DRAG;
272     } else if (str ==  pcLongpress_Popup) {
273         return LONGPRESS_POPUP;
274     } else if (str ==  pcLongpress_Popup_Once) {
275         return LONGPRESS_POPUP_ONCE;
276     } else if (str ==  pcAuto_Popup) {
277         return AUTO_POPUP;
278     } else {
279         return NONE;
280     }
281 }
282 ////////////////////////////////////////////////////////
283 const string DragStateHelper::pcNone = "none";
284 const string DragStateHelper::pcLeft = "left";
285 const string DragStateHelper::pcRight = "right";
286 const string DragStateHelper::pcUp = "up";
287 const string DragStateHelper::pcDown = "down";
288 const string DragStateHelper::pcInvalid = "invalid";
289 const string DragStateHelper::pcReturn = "return";
290
291 const string DragStateHelper::toString(const int val) {
292     switch (val) {
293         case NONE:
294             return pcNone;
295         case LEFT:
296             return pcLeft;
297         case RIGHT:
298             return pcRight;
299         case UP:
300             return pcUp;
301         case DOWN:
302             return pcDown;
303         case INVALID:
304             return pcInvalid;
305         case RETURN:
306             return pcReturn;
307         default:
308             return pcNone;
309     }
310 }
311
312 const int DragStateHelper::Int(const string str) {
313     if (str ==  pcNone) {
314         return NONE;
315     } else if (str ==  pcLeft) {
316         return LEFT;
317     } else if (str ==  pcRight) {
318         return RIGHT;
319     } else if (str ==  pcUp) {
320         return UP;
321     } else if (str ==  pcDown) {
322         return DOWN;
323     } else if (str ==  pcInvalid) {
324         return INVALID;
325     } else if (str ==  pcReturn) {
326         return RETURN;
327     } else {
328         return NONE;
329     }
330 }
331 /////////////////////////////////////////////////////////////
332 const string ExtraOptionHelper::pcOption_4_directions = "4-directions";
333 const string ExtraOptionHelper::pcOption_8_directions = "8-directions";
334 const string ExtraOptionHelper::pcOption_4_directions_long = "4-directions-long";
335 const string ExtraOptionHelper::pcOption_8_directions_long = "8-directions-long";
336 const string ExtraOptionHelper::pcOption_4_directions_return = "4-directions-return";
337 const string ExtraOptionHelper::pcOption_8_directions_return = "8-directions-return";
338 const string ExtraOptionHelper::pcOption_4_directions_return_curve = "4-directions-return-curve";
339
340 const string ExtraOptionHelper::toString(const int val) {
341     switch (val) {
342         case OPTION_4_DIRECTIONS:
343             return pcOption_4_directions;
344         case OPTION_8_DIRECTIONS:
345             return pcOption_8_directions;
346         case OPTION_4_DIRECTIONS_LONG:
347             return pcOption_4_directions_long;
348         case OPTION_8_DIRECTIONS_LONG:
349             return pcOption_8_directions_long;
350         case OPTION_4_DIRECTIONS_RETURN:
351             return pcOption_4_directions_return;
352         case OPTION_8_DIRECTIONS_RETURN:
353             return pcOption_8_directions_return;
354         case OPTION_4_DIRECTIONS_RETURN_CURVE:
355             return pcOption_4_directions_return_curve;
356         default:
357             return pcOption_4_directions;
358     }
359 }
360 const int ExtraOptionHelper::Int(const string str) {
361     if (str ==  pcOption_4_directions) {
362         return OPTION_4_DIRECTIONS;
363     } else if (str ==  pcOption_8_directions) {
364         return OPTION_8_DIRECTIONS;
365     } else if (str ==  pcOption_4_directions_long) {
366         return OPTION_4_DIRECTIONS_LONG;
367     } else if (str ==  pcOption_8_directions_long) {
368         return OPTION_8_DIRECTIONS_LONG;
369     } else if (str ==  pcOption_4_directions_return) {
370         return OPTION_4_DIRECTIONS_RETURN;
371     } else if (str ==  pcOption_8_directions_return) {
372         return OPTION_8_DIRECTIONS_RETURN;
373     } else if (str ==  pcOption_4_directions_return_curve) {
374         return OPTION_4_DIRECTIONS_RETURN_CURVE;
375     } else {
376         return OPTION_4_DIRECTIONS;
377     }
378 }
379 /////////////////////////////////////////////////////////////////////////////
380 const string MultitouchTypeHelper::pcExclusive = "exclusive";
381 const string MultitouchTypeHelper::pcCooperative = "cooperative";
382 const string MultitouchTypeHelper::pcGrab_Sub_Events = "grab_sub_events";
383
384 const string MultitouchTypeHelper::toString(const int val) {
385     switch (val) {
386         case EXCLUSIVE:
387             return pcExclusive;
388         case COOPERATIVE:
389             return pcCooperative;
390         case GRAB_SUB_EVENTS:
391             return pcGrab_Sub_Events;
392         default:
393             return pcExclusive;
394     }
395 }
396 const int MultitouchTypeHelper::Int(const string str) {
397     if (str ==  pcExclusive) {
398         return EXCLUSIVE;
399     } else if (str ==  pcCooperative) {
400         return COOPERATIVE;
401     } else if (str ==  pcGrab_Sub_Events) {
402         return GRAB_SUB_EVENTS;
403     } else {
404         return EXCLUSIVE;
405     }
406 }
407 ////////////////////////////////////////////////////
408 const string BOOLTypeHelper::pcTrue = "true";
409 const string BOOLTypeHelper::pcFalse = "false";
410
411 const string BOOLTypeHelper::toString(const bool val) {
412     if (val) return pcTrue;
413     return pcFalse;
414 }
415 const int BOOLTypeHelper::Bool(const string str) {
416     if (str ==  pcFalse) {
417         return false;
418     } else if (str ==  pcTrue) {
419         return true;
420     } else {
421         return false;
422     }
423 }
424 /////////////////////////////////////////////////
425 const string INTTypeHelper::dextoString(const int val) {
426     char temp[8] = {0};
427     sprintf(temp, "0x%x", val);
428     return string(temp);
429 }
430 const string INTTypeHelper::toString(const int val) {
431     char temp[8] = {0};
432     sprintf(temp, "%d", val);
433     return string(temp);
434 }
435 const int INTTypeHelper::Int(const string str) {
436     int val = 0;
437     sscanf(str.c_str(), "%d", &val);
438     return val;
439 }
440 const int INTTypeHelper::dexInt(const string str) {
441     int val = 0;
442     sscanf(str.c_str(), "%x", &val);
443     return val;
444 }