2 * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <libxml/parser.h>
25 #include "layout_parser.h"
26 #include "default_configure_parser.h" /* use data in default_configure.xml */
27 #include "xml_parser_utils.h"
28 #include "layout_parser_helper.h"
29 #include "put_record.h"
30 #include "simple_debug.h"
35 #define LAYOUT_TAG "layout"
36 #define LAYOUT_NAME_ATTRIBUTE "name"
37 #define LAYOUT_DIRECTION_ATTRIBUTE "direction"
38 #define LAYOUT_DIRECTION_ATTRIBUTE_PORTRAIT_VALUE "portrait"
39 #define LAYOUT_DIRECTION_ATTRIBUTE_LANDSCAPE_VALUE "landscape"
40 #define LAYOUT_STYLE_ATTRIBUTE "style"
41 #define LAYOUT_STYLE_ATTRIBUTE_BASE_VALUE "base"
42 #define LAYOUT_STYLE_ATTRIBUTE_POPUP_VALUE "popup"
43 #define LAYOUT_STYLE_ATTRIBUTE_POPUP_GRAB_VALUE "popup_grab"
44 #define LAYOUT_WIDTH_ATTRIBUTE "width"
45 #define LAYOUT_HEIGHT_ATTRIBUTE "height"
46 #define LAYOUT_MAGNIFIER_ATTRIBUTE "magnifier"
47 #define LAYOUT_PART_BACKGROUND_ATTRIBUTE "part_background"
48 #define LAYOUT_SW_BUTTON_ATTRIBUTE "sw_button"
49 #define LAYOUT_SW_BACKGROUND_ATTRIBUTE "sw_background"
50 #define LAYOUT_KEY_WIDTH_ATTRIBUTE "key_width"
51 #define LAYOUT_KEY_HEIGHT_ATTRIBUTE "key_height"
52 #define LAYOUT_KEY_SPACING_ATTRIBUTE "key_spacing"
53 #define LAYOUT_ROW_SPACING_ATTRIBUTE "row_spacing"
54 #define LAYOUT_KEY_ADD_HIT_LEFT_ATTRIBUTE "hit_left"
55 #define LAYOUT_KEY_ADD_HIT_RIGHT_ATTRIBUTE "hit_right"
56 #define LAYOUT_KEY_ADD_HIT_TOP_ATTRIBUTE "hit_top"
57 #define LAYOUT_KEY_ADD_HIT_BOTTOM_ATTRIBUTE "hit_bottom"
58 #define LAYOUT_VIBE_STYLE_ATTRIBUTE "vibe_style"
59 #define LAYOUT_SOUND_STYLE_ATTRIBUTE "sound_style"
60 #define LAYOUT_LABEL_TYPE_ATTRIBUTE "label_type"
61 #define LAYOUT_MODIFIER_DECORATION_ATTRIBUTE "modifier_decoration"
63 #define LAYOUT_ADD_GRAB_TAG "grab_area"
64 #define LAYOUT_ADD_GRAB_LEFT_TAG "left"
65 #define LAYOUT_ADD_GRAB_RIGHT_TAG "right"
66 #define LAYOUT_ADD_GRAB_TOP_TAG "top"
67 #define LAYOUT_ADD_GRAB_BOTTOM_TAG "bottom"
69 #define LAYOUT_KEY_BACKGROUND_REC_TAG "rec"
70 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE "button"
71 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE_NORMAL_VALUE "normal"
72 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE_PRESSED_VALUE "pressed"
73 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE_DISABLED_VALUE "disabled"
75 #define LAYOUT_KEY_BACKGROUND_TAG "background_image"
76 #define LAYOUT_KEY_BACKGROUND_REC_TAG "rec"
77 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE "button"
78 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE_NORMAL_VALUE "normal"
79 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE_PRESSED_VALUE "pressed"
80 #define LAYOUT_KEY_BACKGROUND_REC_BUTTON_ATTRIBUTE_DISABLED_VALUE "disabled"
82 #define LAYOUT_BACKGROUND_TAG "image_path"
83 #define LAYOUT_BACKGROUND_NORMAL_TAG "button_normal"
84 #define LAYOUT_BACKGROUND_PRESSED_TAG "button_pressed"
85 #define LAYOUT_BACKGROUND_DISABLED_TAG "button_disabled"
86 #define LAYOUT_BACKGROUND_TOGGLED_TAG "button_toggled"
88 #define LAYOUT_SW_BACKGROUND_TAG "background_color"
90 #define LAYOUT_ROW_TAG "row"
91 #define LAYOUT_ROW_SUBLAYOUT_ID_ATTRIBUTE "sub_layout"
92 #define LAYOUT_ROW_X_ATTRIBUTE "x"
93 #define LAYOUT_ROW_Y_ATTRIBUTE "y"
94 #define LAYOUT_ROW_KEY_WIDTH_ATTRIBUTE LAYOUT_KEY_WIDTH_ATTRIBUTE
95 #define LAYOUT_ROW_KEY_HEIGHT_ATTRIBUTE LAYOUT_KEY_HEIGHT_ATTRIBUTE
96 #define LAYOUT_ROW_KEY_SPACING_ATTRIBUTE LAYOUT_KEY_SPACING_ATTRIBUTE
98 #define LAYOUT_ROW_KEY_TAG "key"
99 #define LAYOUT_ROW_KEY_CUSTOMID_ATTRIBUTE "custom_id"
100 #define LAYOUT_ROW_KEY_BUTTON_TYPE_ATTRIBUTE "button_type"
101 #define LAYOUT_ROW_KEY_KEY_TYPE_ATTRIBUTE "key_type"
102 #define LAYOUT_ROW_KEY_POPUP_TYPE_ATTRIBUTE "popup_type"
103 #define LAYOUT_ROW_KEY_MAGNIFIER_ATTRIBUTE "use_magnifier"
104 #define LAYOUT_ROW_KEY_LONGKEY_MAGNIFIER_ATTRIBUTE "longkey_magnifier"
105 #define LAYOUT_ROW_KEY_VIBE_STYLE_ATTRIBUTE LAYOUT_VIBE_STYLE_ATTRIBUTE
106 #define LAYOUT_ROW_KEY_SOUND_STYLE_ATTRIBUTE LAYOUT_SOUND_STYLE_ATTRIBUTE
107 #define LAYOUT_ROW_KEY_SIDE_BUTTON_ATTRIBUTE "is_side_button"
109 #define LAYOUT_ROW_KEY_X_ATTRIBUTE "x"
110 #define LAYOUT_ROW_KEY_Y_ATTRIBUTE "y"
111 #define LAYOUT_ROW_KEY_KEY_WIDTH_ATTRIBUTE "width"
112 #define LAYOUT_ROW_KEY_KEY_HEIGHT_ATTRIBUTE "height"
113 #define LAYOUT_ROW_KEY_ADD_HIT_LEFT_ATTRIBUTE "hit_left"
114 #define LAYOUT_ROW_KEY_ADD_HIT_RIGHT_ATTRIBUTE "hit_right"
115 #define LAYOUT_ROW_KEY_ADD_HIT_TOP_ATTRIBUTE "hit_top"
116 #define LAYOUT_ROW_KEY_ADD_HIT_BOTTOM_ATTRIBUTE "hit_bottom"
117 #define LAYOUT_ROW_KEY_POPUP_POS_X_ATTRIBUTE "popup_offset_x"
118 #define LAYOUT_ROW_KEY_POPUP_POS_Y_ATTRIBUTE "popup_offset_y"
119 #define LAYOUT_ROW_KEY_POPUP_IMAGE_X_ATTRIBUTE "popup_image_x"
120 #define LAYOUT_ROW_KEY_POPUP_IMAGE_Y_ATTRIBUTE "popup_image_y"
121 #define LAYOUT_ROW_KEY_SUBLAYOUT_ID_ATTRIBUTE "sub_layout"
123 #define LAYOUT_ROW_KEY_LABEL_TYPE_ATTRIBUTE "label_type"
124 #define LAYOUT_ROW_KEY_IMAGE_LABEL_TYPE_ATTRIBUTE "image_label_type"
125 #define LAYOUT_ROW_KEY_LONGKEY_TYPE_ATTRIBUTE "long_key_type"
126 #define LAYOUT_ROW_KEY_LONGKEY_VALUE_ATTRIBUTE "long_key_value"
127 #define LAYOUT_ROW_KEY_LONGKEY_EVENT_ATTRIBUTE "long_key_event"
128 #define LAYOUT_ROW_KEY_USE_REPEAT_KEY_ATTRIBUTE "use_repeat_key"
129 #define LAYOUT_ROW_KEY_DONOT_CLOSE_POPUP_ATTRIBUTE "donot_close_popup"
130 #define LAYOUT_ROW_KEY_EXTRA_OPTION_ATTRIBUTE "extra_option"
131 #define LAYOUT_ROW_KEY_MULTITOUCH_TYPE_ATTRIBUTE "multitouch_type"
132 #define LAYOUT_ROW_KEY_MODIFIER_DECORATION_ID_ATTRIBUTE "modifier_decoration_id"
134 #define LAYOUT_ROW_KEY_KEY_SPACING_ATTRIBUTE "key_spacing"
136 #define LAYOUT_ROW_KEY_LABEL_TAG "label"
137 #define LAYOUT_ROW_KEY_IMAGE_LABEL_TAG "image_label"
138 #define LAYOUT_ROW_KEY_BACKGROUND_IMAGE_TAG "background_image"
139 #define LAYOUT_ROW_KEY_KEY_VALUE_TAG "key_value"
140 #define LAYOUT_ROW_KEY_KEY_EVENT_TAG "key_event"
142 #define LAYOUT_ROW_KEY_POPUP_INPUTMODE_RECORD_TAG "popup_input_mode_record"
143 #define LAYOUT_ROW_KEY_POPUP_INPUTMODE_RECORD_INPUTMODE_TAG "popup_input_mode"
145 #define LAYOUT_ROW_KEY_AUTOPOPUP_KEYS_TAG "auto_popup_keys"
146 #define LAYOUT_ROW_KEY_AUTOPOPUP_KEYS_SHIFTMODE_ATTRIBUTE "shift_state"
147 #define LAYOUT_ROW_KEY_MAGNIFIER_LABEL_TAG "magnifier_label"
149 #define LAYOUT_ROW_KEY_HINT_STRING_TAG "hint_string"
151 #define LAYOUT_SUB_LAYOUT_DEFAULT_STRING "DEFAULT"
154 #define LOG_TAG "LIBSCL_UI"
157 class LayoutParserImpl {
165 sclshort key_spacing;
166 sclshort row_spacing;
168 sclshort add_hit_left;
169 sclshort add_hit_right;
170 sclshort add_hit_top;
171 sclshort add_hit_bottom;
175 sclchar *sound_style;
177 sclchar *bg_image_path[SCL_SHIFT_STATE_MAX][SCL_BUTTON_STATE_MAX];
182 void load(int layout_id);
184 bool loaded(int layout_id);
185 void set_directory(const string &dir);
186 int get_layout_index(const char *name);
187 int get_layout_size();
188 PSclLayout get_layout_table();
189 PSclLayoutKeyCoordinatePointerTable get_key_coordinate_pointer_frame();
190 int get_drag_state_prop(const xmlNodePtr cur_node);
191 int get_shift_state_prop(const xmlNodePtr cur_node);
192 int get_button_state_prop(const xmlNodePtr cur_node);
193 int get_multitouch_type_prop(const xmlNodePtr cur_node);
194 int get_extra_option_prop(const xmlNodePtr cur_node);
196 int parsing_layout_table(const vector<string> &layout_file_name);
197 void parsing_layout_node(const xmlNodePtr cur_node, const PSclLayout cur_rec_layout, int layout_no);
198 void loading_coordinate_resources(const xmlNodePtr cur_node, const PSclLayout cur_rec_layout, int layout_no);
199 void parsing_background(const xmlNodePtr cur_node, const PSclLayout);
200 void parsing_key_background(const xmlNodePtr cur_node, const PSclLayout);
201 void parsing_grab_area(const xmlNodePtr cur_node, const PSclLayout cur_rec_layout);
202 void parsing_sw_background_color(const xmlNodePtr cur_node, const PSclLayout);
204 void set_default_layout_value(const PSclLayout);
205 void set_default_row_value(Row*, const PSclLayout cur_rec_layout, const int row_y);
206 void set_default_key_coordinate_value(const PSclLayoutKeyCoordinate cur_rec_coordinate, const Row*);
208 void free_key_coordinate_table(const PSclLayoutKeyCoordinateTable curTable);
210 void parsing_layout_row_node(const xmlNodePtr cur_node, const PSclLayout cur_rec_layout,
211 int *row_y, int *sub_layout_height, SclLayoutKeyCoordinatePointer **cur_key);
212 void parsing_key_coordinate_record_node(const xmlNodePtr cur_node, Row* row, SclLayoutKeyCoordinatePointer *cur_key);
214 void parsing_label_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
215 void parsing_label_image_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
216 void parsing_background_image_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
217 void parsing_popup_input_mode_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
218 void parsing_key_value_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
219 void parsing_key_event_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
220 void parsing_auto_popup_keys_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
221 void parsing_magnifier_label_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
222 void parsing_hint_string_record_node(const xmlNodePtr cur_node, const PSclLayoutKeyCoordinate cur_rec);
224 void add_layout_string(xmlChar*);
225 void release_layout_strings();
227 void add_key_string(xmlChar*);
228 void release_key_strings();
230 void add_upper_string(gchar*);
231 void release_upper_strings();
235 SclLayout m_layout_table[MAX_SCL_LAYOUT];
236 vector<string> m_file_names;
237 SclLayoutKeyCoordinate* m_key_coordinate_pointer_frame[MAX_SCL_LAYOUT][MAX_KEY];
239 std::vector<xmlChar*> m_vec_layout_strings;
240 std::vector<xmlChar*> m_vec_key_strings;
241 std::vector<gchar*> m_vec_upper_strings;
246 LayoutParserImpl::LayoutParserImpl() {
248 memset(m_layout_table, 0x00, sizeof(SclLayout) * MAX_SCL_LAYOUT);
249 memset(m_key_coordinate_pointer_frame, 0x00, sizeof(SclLayoutKeyCoordinatePointer) * MAX_SCL_LAYOUT * MAX_KEY);
252 LayoutParserImpl::~LayoutParserImpl() {
253 for (int i = 0; i < MAX_SCL_LAYOUT; ++i) {
254 for (int j = 0; j < MAX_KEY; ++j) {
255 free(m_key_coordinate_pointer_frame[i][j]);
256 m_key_coordinate_pointer_frame[i][j] = NULL;
260 release_layout_strings();
261 release_key_strings();
262 release_upper_strings();
266 LayoutParserImpl::load(int layout_id) {
267 if (layout_id >= 0 && layout_id < MAX_SCL_LAYOUT) {
271 string input_file = m_dir + "/" + m_file_names[layout_id];
272 doc = xmlReadFile(input_file.c_str(), NULL, 0);
274 SCLLOG(SclLog::ERROR, "Could not load file: %s.", input_file.c_str());
275 LOGE("Could not load file: %s.", input_file.c_str());
279 cur_node = xmlDocGetRootElement(doc);
280 if (cur_node == NULL) {
281 SCLLOG(SclLog::ERROR, "LayoutParserImpl: empty document.\n");
282 LOGE("LayoutParserImpl: empty document.");
286 if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)LAYOUT_TAG))
288 SCLLOG(SclLog::ERROR, "LayoutParserImpl: root name error: %s\n!", (char *)cur_node->name);
289 LOGE("LayoutParserImpl: root name error: %s!", (char *)cur_node->name);
294 PSclLayout cur_rec_layout = m_layout_table + layout_id;
295 loading_coordinate_resources(cur_node, cur_rec_layout, layout_id);
301 void LayoutParserImpl::unload() {
302 for (int i = 0; i < MAX_SCL_LAYOUT; ++i) {
303 for (int j = 0; j < MAX_KEY; ++j) {
304 free(m_key_coordinate_pointer_frame[i][j]);
305 m_key_coordinate_pointer_frame[i][j] = NULL;
309 release_key_strings();
310 release_upper_strings();
314 LayoutParserImpl::loaded(int layout_id) {
317 if (layout_id >= 0 && layout_id < MAX_SCL_LAYOUT) {
318 if (m_key_coordinate_pointer_frame[layout_id][0] == NULL) {
327 LayoutParserImpl::set_directory(const string& dir) {
332 LayoutParserImpl::add_layout_string(xmlChar* newstr) {
334 m_vec_layout_strings.push_back(newstr);
339 LayoutParserImpl::release_layout_strings() {
340 for (size_t loop = 0; loop < m_vec_layout_strings.size(); loop++) {
341 if (m_vec_layout_strings[loop]) {
342 xmlFree(m_vec_layout_strings[loop]);
345 m_vec_layout_strings.clear();
349 LayoutParserImpl::add_key_string(xmlChar* newstr) {
351 m_vec_key_strings.push_back(newstr);
356 LayoutParserImpl::release_key_strings() {
357 for (size_t loop = 0; loop < m_vec_key_strings.size(); loop++) {
358 if (m_vec_key_strings[loop]) {
359 xmlFree(m_vec_key_strings[loop]);
362 m_vec_key_strings.clear();
366 LayoutParserImpl::add_upper_string(gchar* newstr) {
368 m_vec_upper_strings.push_back(newstr);
373 LayoutParserImpl::release_upper_strings() {
374 for (size_t loop = 0; loop < m_vec_upper_strings.size(); loop++) {
375 if (m_vec_upper_strings[loop]) {
376 g_free(m_vec_upper_strings[loop]);
379 m_vec_upper_strings.clear();
383 LayoutParserImpl::get_layout_index(const char *name) {
385 string strName = (string)name;
386 vector<string>::iterator it;
387 // make sure that the m_file_names are sorted.
388 it = lower_bound(m_file_names.begin(), m_file_names.end(), strName);
389 if (it != m_file_names.end() && *it == strName) {
390 return it - m_file_names.begin();
397 LayoutParserImpl::get_layout_table() {
398 return m_layout_table;
402 LayoutParserImpl::get_layout_size() {
403 return m_layout_size;
406 PSclLayoutKeyCoordinatePointerTable
407 LayoutParserImpl::get_key_coordinate_pointer_frame() {
408 return m_key_coordinate_pointer_frame;
412 LayoutParserImpl::parsing_layout_table(const vector<string> &vec_file) {
413 m_file_names = vec_file;
414 m_layout_size = vec_file.size();
415 vector<string>::const_iterator it;
416 for (it = vec_file.begin(); it != vec_file.end(); it++) {
420 string input_file = m_dir + "/" + *it;
421 doc = xmlReadFile(input_file.c_str(), NULL, 0);
423 SCLLOG(SclLog::DEBUG, "Could not load file: %s.", input_file.c_str());
427 cur_node = xmlDocGetRootElement(doc);
428 if (cur_node == NULL) {
429 SCLLOG(SclLog::DEBUG, "LayoutParserImpl: empty document.\n");
433 if (0 != xmlStrcmp(cur_node->name, (const xmlChar*)LAYOUT_TAG))
435 SCLLOG(SclLog::DEBUG, "LayoutParserImpl: root name error: %s\n!", (char *)cur_node->name);
440 int layout_id = it - vec_file.begin();
441 PSclLayout cur_rec_layout = &(m_layout_table[layout_id]);
442 parsing_layout_node(cur_node, cur_rec_layout, layout_id);
443 cur_rec_layout->name = (sclchar*)strdup(it->c_str());
451 LayoutParserImpl::parsing_background(
452 const xmlNodePtr cur_node,
453 PSclLayout cur_layout) {
454 assert(cur_node != NULL);
455 assert(cur_layout != NULL);
457 xmlNodePtr child_node = cur_node->xmlChildrenNode;
458 while (child_node != NULL) {
459 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_BACKGROUND_NORMAL_TAG)) {
460 xmlChar *key = xmlNodeGetContent(child_node);
461 cur_layout->image_path[BUTTON_STATE_NORMAL] = (char *)key;
462 add_layout_string(key);
463 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_BACKGROUND_PRESSED_TAG)) {
464 xmlChar *key = xmlNodeGetContent(child_node);
465 cur_layout->image_path[BUTTON_STATE_PRESSED] = (char *)key;
466 add_layout_string(key);
467 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_BACKGROUND_DISABLED_TAG )) {
468 xmlChar *key = xmlNodeGetContent(child_node);
469 cur_layout->image_path[BUTTON_STATE_DISABLED] = (char *)key;
470 add_layout_string(key);
471 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_BACKGROUND_TOGGLED_TAG )) {
472 xmlChar *key = xmlNodeGetContent(child_node);
473 cur_layout->image_path[BUTTON_STATE_TOGGLED] = (char *)key;
474 add_layout_string(key);
477 child_node = child_node->next;
482 LayoutParserImpl::parsing_sw_background_color(
483 const xmlNodePtr cur_node,
484 PSclLayout cur_layout) {
485 assert(cur_node != NULL);
486 assert(cur_layout != NULL);
488 xmlNodePtr child_node = cur_node->xmlChildrenNode;
489 while (child_node != NULL) {
490 if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"r")) {
491 cur_layout->bg_color.r = get_content_int(child_node);
492 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"g")) {
493 cur_layout->bg_color.g = get_content_int(child_node);
494 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"b")) {
495 cur_layout->bg_color.b = get_content_int(child_node);
496 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar *)"a")) {
497 cur_layout->bg_color.a = get_content_int(child_node);
500 child_node = child_node->next;
505 LayoutParserImpl::parsing_key_background(
506 const xmlNodePtr cur_node,
507 PSclLayout cur_layout) {
508 assert(cur_node != NULL);
509 assert(cur_layout != NULL);
511 xmlNodePtr child_node = cur_node->xmlChildrenNode;
512 while (child_node != NULL) {
513 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
514 int shift_state = get_shift_state_prop(child_node);
515 int button_state = get_button_state_prop(child_node);
516 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
517 for (int button_loop = 0;button_loop < SCL_BUTTON_STATE_MAX;button_loop++) {
518 if ((shift_state == shift_loop || shift_state == -1) &&
519 (button_state == button_loop || button_state == -1)) {
520 xmlChar* key = xmlNodeGetContent(child_node);
521 cur_layout->key_background_image[shift_loop][button_loop] = (sclchar*)key;
522 add_layout_string(key);
528 child_node = child_node->next;
534 LayoutParserImpl::set_default_layout_value(const PSclLayout cur_layout) {
535 DefaultConfigParser *default_configure_parser = DefaultConfigParser::get_instance();
536 assert(default_configure_parser);
537 const PSclDefaultConfigure sclres_default_configure = default_configure_parser->get_default_configure();
539 assert(cur_layout != NULL);
540 cur_layout->valid = 1;
541 cur_layout->style = LAYOUT_STYLE_BASE;
542 cur_layout->name = NULL;
544 if (sclres_default_configure) {
545 cur_layout->width = sclres_default_configure->target_screen_width;
546 cur_layout->height = sclres_default_configure->target_screen_height;
549 cur_layout->key_width = 0;
550 cur_layout->key_height = 0;
551 cur_layout->key_spacing = 0;
552 cur_layout->row_spacing = 0;
554 cur_layout->image_path[BUTTON_STATE_NORMAL] = NULL;
555 cur_layout->image_path[BUTTON_STATE_PRESSED] = NULL;
556 cur_layout->image_path[BUTTON_STATE_DISABLED] = NULL;
557 cur_layout->image_path[BUTTON_STATE_TOGGLED] = NULL;
559 cur_layout->use_sw_button = false;
560 cur_layout->use_magnifier_window = false;
562 cur_layout->display_mode = DISPLAYMODE_PORTRAIT;
563 cur_layout->use_sw_background = false;
564 memset (&(cur_layout->bg_color), 0, sizeof(SclColor));
565 cur_layout->bg_line_width = 0.0;
566 memset (&(cur_layout->bg_line_color), 0, sizeof(SclColor));
568 memset (cur_layout->key_background_image, 0, sizeof(cur_layout->key_background_image));
569 cur_layout->sound_style = NULL;
570 cur_layout->vibe_style = NULL;
571 cur_layout->label_type = NULL;
572 cur_layout->modifier_decorator = NULL;
574 cur_layout->add_grab_left = NOT_USED;
575 cur_layout->add_grab_right = NOT_USED;
576 cur_layout->add_grab_top = NOT_USED;
577 cur_layout->add_grab_bottom = NOT_USED;
581 LayoutParserImpl::set_default_row_value(
583 const PSclLayout cur_rec_layout,
588 row->key_width = cur_rec_layout->key_width;
589 row->key_height = cur_rec_layout->key_height;
590 row->key_spacing = cur_rec_layout->key_spacing;
591 row->row_spacing = cur_rec_layout->row_spacing;
592 row->add_hit_left = cur_rec_layout->add_hit_left;
593 row->add_hit_right = cur_rec_layout->add_hit_right;
594 row->add_hit_top = cur_rec_layout->add_hit_top;
595 row->add_hit_bottom = cur_rec_layout->add_hit_bottom;
596 row->sub_layout = NULL;
597 row->label_type = cur_rec_layout->label_type;
598 row->vibe_style = cur_rec_layout->vibe_style;
599 row->sound_style = cur_rec_layout->sound_style;
600 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
601 for (int button_state = 0; button_state < SCL_BUTTON_STATE_MAX; ++button_state) {
602 row->bg_image_path[shift_state][button_state] = cur_rec_layout->key_background_image[shift_state][button_state];
609 LayoutParserImpl::set_default_key_coordinate_value(
610 const PSclLayoutKeyCoordinate cur_rec_coordinate,
613 assert(cur_rec_coordinate != NULL);
617 if (row && cur_rec_coordinate) {
618 cur_rec_coordinate->valid = FALSE;
619 cur_rec_coordinate->custom_id = NULL;
620 cur_rec_coordinate->button_type = BUTTON_TYPE_NORMAL;
621 cur_rec_coordinate->key_type = KEY_TYPE_CHAR;
622 cur_rec_coordinate->popup_type = POPUP_TYPE_NONE;
623 cur_rec_coordinate->use_magnifier = (sclboolean)true;
624 cur_rec_coordinate->use_long_key_magnifier = (sclboolean)false;
625 //cur_rec_coordinate->enabled =(sclboolean) TRUE;
626 for (loop = 0;loop < SCL_DRAG_STATE_MAX;loop++) {
627 cur_rec_coordinate->popup_input_mode[loop] = NULL;
629 cur_rec_coordinate->sound_style = row->sound_style;
630 cur_rec_coordinate->vibe_style = row->vibe_style;
631 cur_rec_coordinate->is_side_button = false;
633 cur_rec_coordinate->x = row->row_x;
634 cur_rec_coordinate->y = row->row_y;
635 cur_rec_coordinate->width = row->key_width;
636 cur_rec_coordinate->height = row->key_height;
638 cur_rec_coordinate->add_hit_left = row->add_hit_left;
639 cur_rec_coordinate->add_hit_right = row->add_hit_right;
640 cur_rec_coordinate->add_hit_top = row->add_hit_top;
641 cur_rec_coordinate->add_hit_bottom = row->add_hit_bottom;
643 cur_rec_coordinate->label_type = row->label_type;
644 cur_rec_coordinate->image_label_type = NULL;
646 cur_rec_coordinate->label_count = 0;
647 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
648 for (int label_for_one = 0; label_for_one < MAX_SIZE_OF_LABEL_FOR_ONE; ++label_for_one) {
649 cur_rec_coordinate->label[shift_state][label_for_one] = NULL;
652 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
653 for (int button_state = 0; button_state < SCL_BUTTON_STATE_MAX; ++button_state) {
654 cur_rec_coordinate->image_label_path[shift_state][button_state] = NULL;
657 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
658 for (int button_state = 0; button_state < SCL_BUTTON_STATE_MAX; ++button_state) {
659 //cur_rec_coordinate->bg_image_path[shift_state]![button_state] = NULL;
660 cur_rec_coordinate->bg_image_path[shift_state][button_state] = row->bg_image_path[shift_state][button_state];
663 cur_rec_coordinate->key_value_count = 0;
664 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
665 for (int multitap_state = 0; multitap_state < MAX_SIZE_OF_MULTITAP_CHAR; ++multitap_state) {
666 cur_rec_coordinate->key_value[shift_state][multitap_state] = NULL;
669 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
670 for (int multitap_state = 0; multitap_state < MAX_SIZE_OF_MULTITAP_CHAR; ++multitap_state) {
671 cur_rec_coordinate->key_event[shift_state][multitap_state] = 0;
674 /* assume the long_key_type is the same with key_type, by default */
675 cur_rec_coordinate->long_key_type = cur_rec_coordinate->key_type;
676 cur_rec_coordinate->long_key_value = NULL;
677 cur_rec_coordinate->long_key_event = 0;
679 cur_rec_coordinate->use_repeat_key = false;
680 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
681 for (int autopopup_state = 0; autopopup_state < MAX_SIZE_OF_AUTOPOPUP_STRING; ++autopopup_state) {
682 cur_rec_coordinate->autopopup_key_labels[shift_state][autopopup_state] = NULL;
683 cur_rec_coordinate->autopopup_key_events[shift_state][autopopup_state] = 0;
684 cur_rec_coordinate->autopopup_key_values[shift_state][autopopup_state] = NULL;
687 cur_rec_coordinate->dont_close_popup = false;
688 cur_rec_coordinate->extra_option = NOT_USED;
689 cur_rec_coordinate->multitouch_type = SCL_MULTI_TOUCH_TYPE_EXCLUSIVE;
690 cur_rec_coordinate->modifier_decorator = NULL;
691 for (int shift_state = 0; shift_state < SCL_SHIFT_STATE_MAX; shift_state++) {
692 for (int multitap_state = 0; multitap_state < MAX_SIZE_OF_MULTITAP_CHAR; ++multitap_state) {
693 cur_rec_coordinate->hint_string[shift_state][multitap_state] = NULL;
696 cur_rec_coordinate->sub_layout = row->sub_layout;
701 LayoutParserImpl::parsing_grab_area(
702 const xmlNodePtr cur_node,
703 const PSclLayout cur_rec_layout) {
704 assert(cur_node != NULL);
706 xmlNodePtr child_node = cur_node->xmlChildrenNode;
707 while (child_node != NULL) {
708 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ADD_GRAB_LEFT_TAG)) {
709 cur_rec_layout->add_grab_left = get_content_int(child_node);
710 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ADD_GRAB_RIGHT_TAG)) {
711 cur_rec_layout->add_grab_right = get_content_int(child_node);
712 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ADD_GRAB_TOP_TAG)) {
713 cur_rec_layout->add_grab_top = get_content_int(child_node);
714 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ADD_GRAB_BOTTOM_TAG)) {
715 cur_rec_layout->add_grab_bottom = get_content_int(child_node);
717 child_node = child_node->next;
722 LayoutParserImpl::parsing_layout_node(
723 const xmlNodePtr cur_node,
724 const PSclLayout cur_rec_layout,
726 assert(cur_node != NULL);
727 assert(cur_rec_layout != NULL);
729 set_default_layout_value(cur_rec_layout);
733 if (equal_prop(cur_node, LAYOUT_DIRECTION_ATTRIBUTE,
734 LAYOUT_DIRECTION_ATTRIBUTE_LANDSCAPE_VALUE)) {
735 cur_rec_layout->display_mode = DISPLAYMODE_LANDSCAPE;
738 if (equal_prop(cur_node, LAYOUT_STYLE_ATTRIBUTE,
739 LAYOUT_STYLE_ATTRIBUTE_POPUP_VALUE)) {
740 cur_rec_layout->style = LAYOUT_STYLE_POPUP;
741 } else if (equal_prop(cur_node, LAYOUT_STYLE_ATTRIBUTE,
742 LAYOUT_STYLE_ATTRIBUTE_POPUP_GRAB_VALUE)) {
743 cur_rec_layout->style = LAYOUT_STYLE_POPUP_GRAB;
746 get_prop_number(cur_node, LAYOUT_WIDTH_ATTRIBUTE, &(cur_rec_layout->width));
747 get_prop_number(cur_node, LAYOUT_HEIGHT_ATTRIBUTE, &(cur_rec_layout->height));
748 get_prop_bool(cur_node, LAYOUT_MAGNIFIER_ATTRIBUTE, &(cur_rec_layout->use_magnifier_window));
750 get_prop_bool(cur_node, LAYOUT_PART_BACKGROUND_ATTRIBUTE, &(cur_rec_layout->extract_background));
751 get_prop_bool(cur_node, LAYOUT_SW_BUTTON_ATTRIBUTE, &(cur_rec_layout->use_sw_button));
752 get_prop_bool(cur_node, LAYOUT_SW_BACKGROUND_ATTRIBUTE, &(cur_rec_layout->use_sw_background));
754 get_prop_number(cur_node, LAYOUT_KEY_WIDTH_ATTRIBUTE, &(cur_rec_layout->key_width));
755 get_prop_number(cur_node, LAYOUT_KEY_HEIGHT_ATTRIBUTE, &(cur_rec_layout->key_height));
756 get_prop_number(cur_node, LAYOUT_KEY_SPACING_ATTRIBUTE, &(cur_rec_layout->key_spacing));
757 get_prop_number(cur_node, LAYOUT_ROW_SPACING_ATTRIBUTE, &(cur_rec_layout->row_spacing));
759 get_prop_number(cur_node, LAYOUT_KEY_ADD_HIT_LEFT_ATTRIBUTE, &(cur_rec_layout->add_hit_left));
760 get_prop_number(cur_node, LAYOUT_KEY_ADD_HIT_RIGHT_ATTRIBUTE, &(cur_rec_layout->add_hit_right));
761 get_prop_number(cur_node, LAYOUT_KEY_ADD_HIT_TOP_ATTRIBUTE, &(cur_rec_layout->add_hit_top));
762 get_prop_number(cur_node, LAYOUT_KEY_ADD_HIT_BOTTOM_ATTRIBUTE, &(cur_rec_layout->add_hit_bottom));
764 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_VIBE_STYLE_ATTRIBUTE);
766 cur_rec_layout->vibe_style = (sclchar*)key;
767 add_layout_string(key);
769 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_SOUND_STYLE_ATTRIBUTE);
771 cur_rec_layout->sound_style = (sclchar*)key;
772 add_layout_string(key);
774 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_LABEL_TYPE_ATTRIBUTE);
776 cur_rec_layout->label_type = (sclchar*)key;
777 add_layout_string(key);
779 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_MODIFIER_DECORATION_ATTRIBUTE);
781 cur_rec_layout->modifier_decorator = (sclchar*)key;
782 add_layout_string(key);
785 xmlNodePtr child_node = cur_node->xmlChildrenNode;
786 while (child_node != NULL) {
787 /* row node: layout coordinate resources is no need to parsing at this time */
788 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_BACKGROUND_TAG)) {
789 parsing_background(child_node, cur_rec_layout);
790 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_SW_BACKGROUND_TAG)) {
791 parsing_sw_background_color(child_node, cur_rec_layout);
792 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_KEY_BACKGROUND_TAG)) {
793 parsing_key_background(child_node, cur_rec_layout);
794 } else if (0 == xmlStrcmp(cur_node->name, (const xmlChar *)LAYOUT_ADD_GRAB_TAG)) {
795 parsing_grab_area(child_node, cur_rec_layout);
798 child_node = child_node->next;
803 LayoutParserImpl::loading_coordinate_resources(
804 const xmlNodePtr cur_node,
805 const PSclLayout cur_rec_layout,
807 assert(cur_node != NULL);
810 int sub_layout_height = 0;
812 SclLayoutKeyCoordinatePointer *cur_key = &m_key_coordinate_pointer_frame[layout_no][0];
814 if (*cur_key == NULL) {
815 xmlNodePtr child_node = cur_node->xmlChildrenNode;
816 while (child_node != NULL) {
817 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_TAG)) {
818 parsing_layout_row_node(child_node, cur_rec_layout, &row_y, &sub_layout_height, &cur_key);
821 child_node = child_node->next;
827 LayoutParserImpl::parsing_layout_row_node(
828 const xmlNodePtr cur_node,
829 const PSclLayout cur_rec_layout,
830 int *row_y, int *sub_layout_height,
831 SclLayoutKeyCoordinatePointer **cur_key) {
832 assert(cur_node != NULL);
836 set_default_row_value(&row, cur_rec_layout, *row_y);
839 get_prop_number(cur_node, LAYOUT_ROW_X_ATTRIBUTE, &(row.row_x));
840 get_prop_number(cur_node, LAYOUT_ROW_Y_ATTRIBUTE, &(row.row_y));
841 get_prop_number(cur_node, LAYOUT_ROW_KEY_WIDTH_ATTRIBUTE, &(row.key_width));
842 get_prop_number(cur_node, LAYOUT_ROW_KEY_HEIGHT_ATTRIBUTE, &(row.key_height));
843 get_prop_number(cur_node, LAYOUT_ROW_KEY_SPACING_ATTRIBUTE, &(row.key_spacing));
845 xmlChar *key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_SUBLAYOUT_ID_ATTRIBUTE);
847 row.sub_layout = (sclchar*)key;
851 if (row.sub_layout == NULL) {
853 /* If there's a stored sub_layout_height value, add it to current row's y position */
854 if (sub_layout_height) {
855 row.row_y += *sub_layout_height;
856 *sub_layout_height = 0;
858 *row_y = row.row_y + row.key_height + row.row_spacing;
861 /* Store the current row's height for later use when this sublayout is "DEFAULT" */
862 static const char default_sub_layout_string[] = LAYOUT_SUB_LAYOUT_DEFAULT_STRING;
863 if (row.sub_layout && strncmp(row.sub_layout, default_sub_layout_string, sizeof(default_sub_layout_string)) == 0) {
864 if (sub_layout_height) {
865 *sub_layout_height = row.key_height + row.row_spacing;
869 xmlNodePtr child_node = cur_node->xmlChildrenNode;
870 while (child_node != NULL) {
871 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_TAG)) {
872 parsing_key_coordinate_record_node(child_node, &row, *cur_key);
875 child_node = child_node->next;
880 LayoutParserImpl::get_drag_state_prop(const xmlNodePtr cur_node) {
881 assert(cur_node != NULL);
882 typedef struct _Match_Struct {
886 static Match_Struct table[] = {
887 {SCL_DRAG_STATE_NONE, "drag_state_none" },
888 {SCL_DRAG_STATE_LEFT, "drag_state_left" },
889 {SCL_DRAG_STATE_RIGHT, "drag_state_right" },
890 {SCL_DRAG_STATE_UP, "drag_state_up" },
891 {SCL_DRAG_STATE_DOWN, "drag_state_down" },
892 {SCL_DRAG_STATE_INVALID, "drag_state_invalid" },
893 {SCL_DRAG_STATE_RETURN, "drag_state_return" }
896 xmlChar* key = xmlGetProp(cur_node, (const xmlChar*)"drag_state");
897 if (key == NULL) return SCL_DRAG_STATE_NONE;
899 int drag_state = SCL_DRAG_STATE_NONE;
901 for (size_t i = 0; i < sizeof(table)/sizeof(Match_Struct); ++i) {
902 if (0 == strcmp((const char*)key, table[i].key))
904 drag_state = table[i].value;
914 LayoutParserImpl::get_shift_state_prop(const xmlNodePtr cur_node) {
915 assert(cur_node != NULL);
917 int shift_state = -1;
919 if (equal_prop(cur_node, "shift", "on")) {
920 shift_state = SCL_SHIFT_STATE_ON;
921 } else if (equal_prop(cur_node, "shift", "off")) {
922 shift_state = SCL_SHIFT_STATE_OFF;
923 } else if (equal_prop(cur_node, "shift", "loc")) {
924 shift_state = SCL_SHIFT_STATE_LOCK;
929 LayoutParserImpl::get_button_state_prop(const xmlNodePtr cur_node) {
930 assert(cur_node != NULL);
931 int button_state = -1;
933 if (equal_prop(cur_node, "button", "pressed")) {
934 button_state = BUTTON_STATE_PRESSED;
935 } else if (equal_prop(cur_node, "button", "normal")) {
936 button_state = BUTTON_STATE_NORMAL;
937 } else if (equal_prop(cur_node, "button", "disabled")) {
938 button_state = BUTTON_STATE_DISABLED;
939 } else if (equal_prop(cur_node, "button", "toggled")) {
940 button_state = BUTTON_STATE_TOGGLED;
946 LayoutParserImpl::get_multitouch_type_prop(const xmlNodePtr cur_node) {
947 assert(cur_node != NULL);
948 typedef struct _Match_Struct {
952 static Match_Struct table[] = {
953 {SCL_MULTI_TOUCH_TYPE_EXCLUSIVE, "exclusive" },
954 {SCL_MULTI_TOUCH_TYPE_SETTLE_PREVIOUS, "settle_previous" },
955 {SCL_MULTI_TOUCH_TYPE_COOPERATIVE, "cooperative" },
956 {SCL_MULTI_TOUCH_TYPE_GRAB_SUB_EVENTS, "grab_sub_events" },
959 xmlChar* key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_MULTITOUCH_TYPE_ATTRIBUTE);
960 if (key == NULL) return SCL_MULTI_TOUCH_TYPE_EXCLUSIVE;
962 int type = SCL_MULTI_TOUCH_TYPE_EXCLUSIVE;
964 for (size_t i = 0; i < sizeof(table)/sizeof(Match_Struct); ++i) {
965 if (0 == strcmp((const char*)key, table[i].key))
967 type = table[i].value;
977 LayoutParserImpl::get_extra_option_prop(
978 const xmlNodePtr cur_node) {
979 assert(cur_node != NULL);
980 typedef struct _Match_Struct {
984 static Match_Struct table[] = {
985 {DIRECTION_EXTRA_OPTION_4_DIRECTIONS, "4-directions" },
986 {DIRECTION_EXTRA_OPTION_8_DIRECTIONS, "8-directions" },
987 {DIRECTION_EXTRA_OPTION_4_DIRECTIONS_WITH_LONG, "4-directions-long" },
988 {DIRECTION_EXTRA_OPTION_8_DIRECTIONS_WITH_LONG, "8-directions-long" },
989 {DIRECTION_EXTRA_OPTION_4_DIRECTIONS_WITH_RETURN, "4-directions-return" },
990 {DIRECTION_EXTRA_OPTION_8_DIRECTIONS_WITH_RETURN, "8-directions-return" },
991 {DIRECTION_EXTRA_OPTION_4_DIRECTIONS_WITH_RETURN_AND_CURVE, "4-directions-return-curve" },
994 xmlChar* key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_EXTRA_OPTION_ATTRIBUTE);
995 if (key == NULL) return 0;
997 int type = DIRECTION_EXTRA_OPTION_4_DIRECTIONS;
999 for (size_t i = 0; i < sizeof(table)/sizeof(Match_Struct); ++i) {
1000 if (0 == strcmp((const char*)key, table[i].key))
1002 type = table[i].value;
1013 LayoutParserImpl::parsing_label_record_node(
1014 const xmlNodePtr cur_node,
1015 const PSclLayoutKeyCoordinate cur_rec) {
1016 assert(cur_node != NULL);
1017 assert(cur_rec != NULL);
1018 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"label"));
1019 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1021 while (child_node != NULL) {
1022 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
1023 int shift_state = get_shift_state_prop(child_node);
1025 int label_for_one_state = 0;
1026 get_prop_number(child_node, "multi", &label_for_one_state);
1027 if (cur_rec->label_count < (label_for_one_state + 1)) {
1028 cur_rec->label_count = (label_for_one_state + 1);
1031 sclboolean auto_upper = FALSE;
1032 get_prop_bool(child_node, "auto_upper", &auto_upper);
1034 if (label_for_one_state >= 0 && label_for_one_state < MAX_SIZE_OF_LABEL_FOR_ONE) {
1035 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1036 if ((shift_state == shift_loop || shift_state == -1)) {
1037 xmlChar* key = xmlNodeGetContent(child_node);
1039 sclboolean upper_created = FALSE;
1041 if (shift_loop != SCL_SHIFT_STATE_OFF) {
1042 gchar *upper = g_utf8_strup(reinterpret_cast<gchar*>(key), -1);
1044 add_upper_string(upper);
1045 upper_created = TRUE;
1046 key = reinterpret_cast<xmlChar*>(upper);
1049 if (!upper_created) {
1050 add_key_string(key);
1052 cur_rec->label[shift_loop][label_for_one_state] = (sclchar*)key;
1053 /* If current key_value is NULL, let's just consider this label is the default key_value */
1054 if (label_for_one_state == 0) {
1055 if (cur_rec->key_value[shift_loop][label_for_one_state] == NULL) {
1056 cur_rec->key_value[shift_loop][label_for_one_state] = (sclchar*)key;
1064 child_node = child_node->next;
1069 LayoutParserImpl::parsing_magnifier_label_record_node(
1070 const xmlNodePtr cur_node,
1071 const PSclLayoutKeyCoordinate cur_rec) {
1072 assert(cur_node != NULL);
1073 assert(cur_rec != NULL);
1074 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"magnifier_label"));
1075 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1077 while (child_node != NULL) {
1078 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
1079 int shift_state = get_shift_state_prop(child_node);
1081 int label_for_one_state = 0;
1082 get_prop_number(child_node, "multi", &label_for_one_state);
1084 if (label_for_one_state >= 0 && label_for_one_state < MAX_SIZE_OF_LABEL_FOR_ONE) {
1085 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1086 if ((shift_state == shift_loop || shift_state == -1)) {
1087 xmlChar* key = xmlNodeGetContent(child_node);
1089 cur_rec->magnifier_label[shift_loop][label_for_one_state] = (sclchar*)key;
1090 add_key_string(key);
1096 child_node = child_node->next;
1101 LayoutParserImpl::parsing_hint_string_record_node(
1102 const xmlNodePtr cur_node,
1103 const PSclLayoutKeyCoordinate cur_rec) {
1104 assert(cur_node != NULL);
1105 assert(cur_rec != NULL);
1106 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"hint_string"));
1107 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1109 while (child_node != NULL) {
1110 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
1111 int shift_state = get_shift_state_prop(child_node);
1112 int multichar_state = 0;
1113 get_prop_number(child_node, "multichar_state", &multichar_state);
1115 if (multichar_state >= 0 && multichar_state < MAX_SIZE_OF_MULTITAP_CHAR) {
1116 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1117 if ((shift_state == shift_loop || shift_state == -1)) {
1118 xmlChar* key = xmlNodeGetContent(child_node);
1120 cur_rec->hint_string[shift_loop][multichar_state] = (sclchar*)key;
1121 add_key_string(key);
1127 child_node = child_node->next;
1132 LayoutParserImpl::parsing_label_image_record_node(
1133 const xmlNodePtr cur_node,
1134 const PSclLayoutKeyCoordinate cur_rec) {
1135 assert(cur_node != NULL);
1136 assert(cur_rec != NULL);
1137 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"image_label"));
1138 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1140 while (child_node != NULL) {
1141 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
1142 int shift_state = get_shift_state_prop(child_node);
1143 int button_state = get_button_state_prop(child_node);
1144 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1145 for (int button_loop = 0;button_loop < SCL_BUTTON_STATE_MAX;button_loop++) {
1146 if ((shift_state == shift_loop || shift_state == -1) &&
1147 (button_state == button_loop || button_state == -1)) {
1148 xmlChar* key = xmlNodeGetContent(child_node);
1150 cur_rec->image_label_path[shift_loop][button_loop] = (sclchar*)key;
1151 add_key_string(key);
1157 child_node = child_node->next;
1162 LayoutParserImpl::parsing_background_image_record_node(
1163 const xmlNodePtr cur_node,
1164 const PSclLayoutKeyCoordinate cur_rec) {
1165 assert(cur_node != NULL);
1166 assert(cur_rec != NULL);
1167 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"background_image"));
1168 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1170 while (child_node != NULL) {
1171 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
1172 int shift_state = get_shift_state_prop(child_node);
1173 int button_state = get_button_state_prop(child_node);
1174 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1175 for (int button_loop = 0;button_loop < SCL_BUTTON_STATE_MAX;button_loop++) {
1176 if ((shift_state == shift_loop || shift_state == -1) &&
1177 (button_state == button_loop || button_state == -1)) {
1178 xmlChar* key = xmlNodeGetContent(child_node);
1180 cur_rec->bg_image_path[shift_loop][button_loop] = (sclchar*)key;
1181 add_key_string(key);
1187 child_node = child_node->next;
1192 LayoutParserImpl::parsing_key_value_record_node(
1193 const xmlNodePtr cur_node,
1194 const PSclLayoutKeyCoordinate cur_rec) {
1195 assert(cur_node != NULL);
1196 assert(cur_rec != NULL);
1197 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"key_value"));
1198 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1200 while (child_node != NULL) {
1201 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
1202 int shift_state = get_shift_state_prop(child_node);
1203 int multichar_state = 0;
1204 get_prop_number(child_node, "multichar_state", &multichar_state);
1206 sclboolean auto_upper = FALSE;
1207 get_prop_bool(child_node, "auto_upper", &auto_upper);
1209 if (multichar_state >= 0 && multichar_state < MAX_SIZE_OF_MULTITAP_CHAR) {
1210 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1211 if ((shift_state == shift_loop || shift_state == -1)) {
1212 xmlChar* key = xmlNodeGetContent(child_node);
1214 sclboolean upper_created = FALSE;
1216 if (shift_loop != SCL_SHIFT_STATE_OFF) {
1217 gchar *upper = g_utf8_strup(reinterpret_cast<gchar*>(key), -1);
1219 add_upper_string(upper);
1220 upper_created = TRUE;
1221 key = reinterpret_cast<xmlChar*>(upper);
1224 if (!upper_created) {
1225 add_key_string(key);
1227 cur_rec->key_value[shift_loop][multichar_state] = (sclchar*)key;
1233 child_node = child_node->next;
1238 LayoutParserImpl::parsing_key_event_record_node(
1239 const xmlNodePtr cur_node,
1240 const PSclLayoutKeyCoordinate cur_rec) {
1241 assert(cur_node != NULL);
1242 assert(cur_rec != NULL);
1243 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"key_event"));
1244 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1246 while (child_node != NULL) {
1247 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"rec")) {
1248 int shift_state = get_shift_state_prop(child_node);
1249 int multichar_state = 0;
1250 get_prop_number(child_node, "multichar_state", &multichar_state);
1252 if (multichar_state >= 0 && multichar_state < MAX_SIZE_OF_MULTITAP_CHAR) {
1253 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1254 if ((shift_state == shift_loop || shift_state == -1)) {
1255 cur_rec->key_event[shift_loop][multichar_state] = (sclulong)get_content_dex_string_int(child_node);
1260 child_node = child_node->next;
1265 LayoutParserImpl::parsing_auto_popup_keys_record_node(
1266 const xmlNodePtr cur_node,
1267 const PSclLayoutKeyCoordinate cur_rec) {
1268 assert(cur_node != NULL);
1269 assert(cur_rec != NULL);
1270 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)"auto_popup_keys"));
1271 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1273 while (child_node != NULL) {
1274 int shift_state = get_shift_state_prop(child_node);
1275 int autopopup_state = 0;
1276 get_prop_number(child_node, "autopopup", &autopopup_state);
1278 sclboolean auto_upper = FALSE;
1279 get_prop_bool(child_node, "auto_upper", &auto_upper);
1281 if (autopopup_state >= 0 && autopopup_state < MAX_SIZE_OF_AUTOPOPUP_STRING) {
1282 for (int shift_loop = 0;shift_loop < SCL_SHIFT_STATE_MAX;shift_loop++) {
1283 if ((shift_state == shift_loop || shift_state == -1)) {
1284 xmlChar* key = xmlNodeGetContent(child_node);
1286 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"label")) {
1287 sclboolean upper_created = FALSE;
1289 if (shift_loop != SCL_SHIFT_STATE_OFF) {
1290 gchar *upper = g_utf8_strup(reinterpret_cast<gchar*>(key), -1);
1292 add_upper_string(upper);
1293 upper_created = TRUE;
1294 key = reinterpret_cast<xmlChar*>(upper);
1297 if (!upper_created) {
1298 add_key_string(key);
1300 cur_rec->autopopup_key_labels[shift_loop][autopopup_state] = (sclchar*)key;
1301 /* If current key_value is NULL, let's just consider this label is the default key_value */
1302 if (cur_rec->autopopup_key_values[shift_loop][autopopup_state] == NULL) {
1303 cur_rec->autopopup_key_values[shift_loop][autopopup_state] = (sclchar*)key;
1305 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"value")) {
1306 cur_rec->autopopup_key_values[shift_loop][autopopup_state] = (sclchar*)key;
1307 add_key_string(key);
1308 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)"event")) {
1309 cur_rec->autopopup_key_events[shift_loop][autopopup_state] = (sclulong)atoi((sclchar*)key);
1310 add_key_string(key);
1316 child_node = child_node->next;
1321 LayoutParserImpl::parsing_key_coordinate_record_node(
1322 const xmlNodePtr cur_node, Row *row,
1323 SclLayoutKeyCoordinatePointer *cur_rec_coordinate) {
1324 assert(cur_node != NULL);
1325 assert(cur_rec_coordinate != NULL);
1327 *cur_rec_coordinate = (SclLayoutKeyCoordinatePointer)malloc(sizeof(SclLayoutKeyCoordinate));
1328 if (*cur_rec_coordinate == NULL) {
1329 SCLLOG(SclLog::ERROR, "LayoutParserImpl: memory malloc eror.\n");
1332 memset(*cur_rec_coordinate, 0x00, sizeof(SclLayoutKeyCoordinate));
1334 set_default_key_coordinate_value(*cur_rec_coordinate, row);
1338 int key_spacing = 0;
1341 key_spacing = row->key_spacing;
1344 (*cur_rec_coordinate)->valid = TRUE;
1346 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_CUSTOMID_ATTRIBUTE);
1348 (*cur_rec_coordinate)->custom_id = (sclchar*)key;
1349 add_key_string(key);
1352 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_BUTTON_TYPE_ATTRIBUTE);
1354 (*cur_rec_coordinate)->button_type = (SCLButtonType)ButtonTypeHelper::Int((const char*)key);
1358 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_KEY_TYPE_ATTRIBUTE);
1360 (*cur_rec_coordinate)->key_type = (SCLKeyType)KeyTypeHelper::Int((const char*)key);
1363 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_POPUP_TYPE_ATTRIBUTE);
1365 (*cur_rec_coordinate)->popup_type = (SCLPopupType)PopupTypeHelper::Int((const char*)key);
1369 get_prop_bool(cur_node, LAYOUT_ROW_KEY_MAGNIFIER_ATTRIBUTE, &((*cur_rec_coordinate)->use_magnifier));
1370 get_prop_bool(cur_node, LAYOUT_ROW_KEY_LONGKEY_MAGNIFIER_ATTRIBUTE,
1371 &((*cur_rec_coordinate)->use_long_key_magnifier));
1373 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_VIBE_STYLE_ATTRIBUTE);
1375 (*cur_rec_coordinate)->vibe_style = (sclchar*)key;
1376 add_key_string(key);
1378 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_SOUND_STYLE_ATTRIBUTE);
1380 (*cur_rec_coordinate)->sound_style = (sclchar*)key;
1381 add_key_string(key);
1384 get_prop_bool(cur_node, LAYOUT_ROW_KEY_SIDE_BUTTON_ATTRIBUTE, &((*cur_rec_coordinate)->is_side_button));
1386 get_prop_number(cur_node, LAYOUT_ROW_KEY_X_ATTRIBUTE, &((*cur_rec_coordinate)->x));
1387 get_prop_number(cur_node, LAYOUT_ROW_KEY_Y_ATTRIBUTE, &((*cur_rec_coordinate)->y));
1388 get_prop_number(cur_node, LAYOUT_ROW_KEY_KEY_WIDTH_ATTRIBUTE, &((*cur_rec_coordinate)->width));
1389 get_prop_number(cur_node, LAYOUT_ROW_KEY_KEY_HEIGHT_ATTRIBUTE, &((*cur_rec_coordinate)->height));
1391 get_prop_number(cur_node, LAYOUT_ROW_KEY_ADD_HIT_LEFT_ATTRIBUTE, &((*cur_rec_coordinate)->add_hit_left));
1392 get_prop_number(cur_node, LAYOUT_ROW_KEY_ADD_HIT_RIGHT_ATTRIBUTE, &((*cur_rec_coordinate)->add_hit_right));
1393 get_prop_number(cur_node, LAYOUT_ROW_KEY_ADD_HIT_TOP_ATTRIBUTE, &((*cur_rec_coordinate)->add_hit_top));
1394 get_prop_number(cur_node, LAYOUT_ROW_KEY_ADD_HIT_BOTTOM_ATTRIBUTE, &((*cur_rec_coordinate)->add_hit_bottom));
1396 get_prop_number(cur_node, LAYOUT_ROW_KEY_POPUP_POS_X_ATTRIBUTE, &((*cur_rec_coordinate)->popup_relative_x));
1397 get_prop_number(cur_node, LAYOUT_ROW_KEY_POPUP_POS_Y_ATTRIBUTE, &((*cur_rec_coordinate)->popup_relative_y));
1399 get_prop_number(cur_node, LAYOUT_ROW_KEY_POPUP_IMAGE_X_ATTRIBUTE, &((*cur_rec_coordinate)->extract_offset_x));
1400 get_prop_number(cur_node, LAYOUT_ROW_KEY_POPUP_IMAGE_Y_ATTRIBUTE, &((*cur_rec_coordinate)->extract_offset_y));
1402 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_LONGKEY_TYPE_ATTRIBUTE);
1404 (*cur_rec_coordinate)->long_key_type = (SCLKeyType)KeyTypeHelper::Int((const char*)key);
1407 /* assume the long_key_type is the same with key_type, by default */
1408 (*cur_rec_coordinate)->long_key_type = (*cur_rec_coordinate)->key_type;
1411 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_LONGKEY_VALUE_ATTRIBUTE);
1413 (*cur_rec_coordinate)->long_key_value = (sclchar*)key;
1414 add_key_string(key);
1417 get_prop_number(cur_node, LAYOUT_ROW_KEY_LONGKEY_EVENT_ATTRIBUTE, &((*cur_rec_coordinate)->long_key_event));
1419 get_prop_bool(cur_node, LAYOUT_ROW_KEY_USE_REPEAT_KEY_ATTRIBUTE, &((*cur_rec_coordinate)->use_repeat_key));
1420 get_prop_bool(cur_node, LAYOUT_ROW_KEY_DONOT_CLOSE_POPUP_ATTRIBUTE, &((*cur_rec_coordinate)->dont_close_popup));
1422 (*cur_rec_coordinate)->extra_option = get_extra_option_prop(cur_node);
1423 (*cur_rec_coordinate)->multitouch_type = get_multitouch_type_prop(cur_node);
1425 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_SUBLAYOUT_ID_ATTRIBUTE);
1427 (*cur_rec_coordinate)->sub_layout = (sclchar*)key;
1428 add_key_string(key);
1431 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_LABEL_TYPE_ATTRIBUTE);
1433 (*cur_rec_coordinate)->label_type = (sclchar*)key;
1434 add_key_string(key);
1437 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_IMAGE_LABEL_TYPE_ATTRIBUTE);
1439 (*cur_rec_coordinate)->image_label_type = (sclchar*)key;
1440 add_key_string(key);
1443 key = xmlGetProp(cur_node, (const xmlChar*)LAYOUT_ROW_KEY_MODIFIER_DECORATION_ID_ATTRIBUTE);
1445 (*cur_rec_coordinate)->modifier_decorator = (sclchar*)key;
1446 add_key_string(key);
1449 get_prop_number(cur_node, LAYOUT_ROW_KEY_KEY_SPACING_ATTRIBUTE, &key_spacing);
1451 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1452 while (child_node != NULL) {
1453 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_LABEL_TAG)) {
1454 parsing_label_record_node(child_node, (*cur_rec_coordinate));
1455 (*cur_rec_coordinate)->valid = TRUE;
1456 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_IMAGE_LABEL_TAG)) {
1457 parsing_label_image_record_node(child_node, (*cur_rec_coordinate));
1458 (*cur_rec_coordinate)->valid = TRUE;
1459 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_BACKGROUND_IMAGE_TAG)) {
1460 parsing_background_image_record_node(child_node, (*cur_rec_coordinate));
1461 (*cur_rec_coordinate)->valid = TRUE;
1462 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_KEY_VALUE_TAG)) {
1463 parsing_key_value_record_node(child_node, (*cur_rec_coordinate));
1464 (*cur_rec_coordinate)->valid = TRUE;
1465 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_KEY_EVENT_TAG)) {
1466 parsing_key_event_record_node(child_node, (*cur_rec_coordinate));
1467 (*cur_rec_coordinate)->valid = TRUE;
1468 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_AUTOPOPUP_KEYS_TAG)) {
1469 parsing_auto_popup_keys_record_node(child_node, (*cur_rec_coordinate));
1470 (*cur_rec_coordinate)->valid = TRUE;
1471 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_POPUP_INPUTMODE_RECORD_TAG)) {
1472 parsing_popup_input_mode_record_node(child_node, (*cur_rec_coordinate));
1473 (*cur_rec_coordinate)->valid = TRUE;
1474 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_MAGNIFIER_LABEL_TAG)) {
1475 parsing_magnifier_label_record_node(child_node, (*cur_rec_coordinate));
1476 (*cur_rec_coordinate)->valid = TRUE;
1477 } else if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_HINT_STRING_TAG)) {
1478 parsing_hint_string_record_node(child_node, (*cur_rec_coordinate));
1479 (*cur_rec_coordinate)->valid = TRUE;
1482 child_node = child_node->next;
1486 row->row_x = (*cur_rec_coordinate)->x + (*cur_rec_coordinate)->width + key_spacing;
1491 LayoutParserImpl::parsing_popup_input_mode_record_node(
1492 const xmlNodePtr cur_node,
1493 const PSclLayoutKeyCoordinate cur_rec) {
1494 assert(cur_node != NULL);
1495 assert(cur_rec != NULL);
1496 assert(0 == xmlStrcmp(cur_node->name, (const xmlChar*)LAYOUT_ROW_KEY_POPUP_INPUTMODE_RECORD_TAG));
1497 xmlNodePtr child_node = cur_node->xmlChildrenNode;
1499 while (child_node != NULL) {
1500 if (0 == xmlStrcmp(child_node->name, (const xmlChar*)LAYOUT_ROW_KEY_POPUP_INPUTMODE_RECORD_INPUTMODE_TAG)) {
1501 int drag_state = get_drag_state_prop(child_node);
1502 assert(drag_state >=0);
1503 assert(drag_state < SCL_DRAG_STATE_MAX);
1504 xmlChar* key = xmlNodeGetContent(child_node);
1507 cur_rec->popup_input_mode[drag_state] = (sclchar*)key;
1508 add_key_string(key);
1511 child_node = child_node->next;
1515 LayoutParser::LayoutParser() {
1516 m_impl = new LayoutParserImpl;
1518 LayoutParser::~LayoutParser() {
1519 SCLLOG(SclLog::MESSAGE, "~LayoutParser() has called");
1525 LayoutParser::get_instance() {
1526 static LayoutParser instance;
1531 LayoutParser::init(const char* dir, const vector<string> &vec_file) {
1534 m_impl->set_directory(dir);
1535 ret = m_impl->parsing_layout_table(vec_file);
1542 LayoutParser::load(int layout_id) {
1543 m_impl->load(layout_id);
1547 LayoutParser::loaded(int layout_id) {
1548 return m_impl->loaded(layout_id);
1552 LayoutParser::unload() {
1557 LayoutParser::get_layout_index(const char *name) {
1558 return m_impl->get_layout_index(name);
1562 LayoutParser::get_layout_size() {
1563 return m_impl->get_layout_size();
1567 LayoutParser::get_layout_table() {
1568 return m_impl->get_layout_table();
1571 PSclLayoutKeyCoordinatePointerTable
1572 LayoutParser::get_key_coordinate_pointer_frame() {
1573 return m_impl->get_key_coordinate_pointer_frame();