ad97d58861aeb6208b9f3e17e1f0d0f5a1b5ea01
[platform/core/uifw/libscl-ui-nui.git] / scl / modifier_decoration_bin_parser.cpp
1 /*
2  * Copyright (c) 2012 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 "modifier_decoration_bin_parser.h"
19 #include <memory.h>
20 #include "put_record.h"
21
22 BinModifierDecorationParser::BinModifierDecorationParser() {
23     memset(m_modifier_decoration_table, 0x00, sizeof(SclModifierDecoration) * MAX_SCL_MODIFIER_DECORATION_NUM);
24     parser_info_provider = NULL;
25 }
26
27 BinModifierDecorationParser::~BinModifierDecorationParser() {
28 }
29
30 BinModifierDecorationParser*
31 BinModifierDecorationParser::get_instance() {
32     static BinModifierDecorationParser instance;
33     return &instance;
34 }
35 void
36 BinModifierDecorationParser::init(const FileStorage& storage, int offset, int size, IParserInfo_Provider* provider) {
37     m_storage.set_str_provider(provider);
38     m_storage.get_storage(storage, offset, size);
39     this->parser_info_provider = provider;
40
41     parsing_modifier_decoration_table();
42 }
43
44 /* recompute_layout will change the table */
45 PSclModifierDecoration BinModifierDecorationParser::get_modifier_decoration_table() {
46     return m_modifier_decoration_table;
47 }
48
49 void
50 BinModifierDecorationParser::parsing_modifier_decoration_table() {
51     PSclModifierDecoration cur = m_modifier_decoration_table;
52
53     Modifier_decoration_width record_width;
54     set_modifier_decoration_width(*parser_info_provider, record_width);
55
56     // skip data_size
57     m_storage.advance(8);
58
59     int size = m_storage.get<sint_t>(4);
60     for (int i = 0; i < size; ++i) {
61         cur->valid = (sclboolean)true;
62         m_storage.get<sint_t>(record_width.extract_background);
63         m_storage.get_str(&(cur->name), record_width.name, m_string_collector);
64         for (int m = 0; m < DISPLAYMODE_MAX; ++m) {
65             for (int n = 0; n < KEY_MODIFIER_MAX; ++n) {
66                 m_storage.get_str(&(cur->bg_image_path[m][n]), record_width.bg_image_path, m_string_collector);
67             }
68         }
69
70         cur++;
71     }
72 #ifdef __SCL_TXT_DEBUG
73     put_modifier_decoration(DECODE, m_modifier_decoration_table);
74 #endif
75 }
76
77 int
78 BinModifierDecorationParser::get_modifier_decoration_id(const char *name )
79 {
80     if (name == NULL) return -1;
81
82     for (int i = 0; i < MAX_SCL_MODIFIER_DECORATION_NUM; ++i) {
83         if ( m_modifier_decoration_table[i].name ) {
84             if ( 0 == strcmp(m_modifier_decoration_table[i].name, name) ) {
85                 return i;
86             }
87         }
88     }
89
90     return -1;
91 }
92