bb923f4d64d85bae2a099b6ed28fb0ca6418ef02
[platform/core/uifw/libscl-ui-nui.git] / scl / layout_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 "layout_bin_parser.h"
19 #include "default_configure_bin_parser.h"
20 #include "key_coordinate_frame_bin_parser.h"
21 #include "sclutils.h"
22
23 #include "put_record.h"
24 #include <algorithm>
25 using namespace std;
26 using namespace scl;
27
28 BinLayoutParser::
29 BinLayoutParser() {
30     m_layout_size = 0;
31     memset(m_layout_table, 0x00, sizeof(SclLayout) * MAX_SCL_LAYOUT);
32     parser_info_provider = NULL;
33 }
34 BinLayoutParser::
35 ~BinLayoutParser() {
36 }
37 BinLayoutParser* BinLayoutParser::
38 get_instance() {
39     static BinLayoutParser instance;
40     return &instance;
41 }
42 void BinLayoutParser::
43 init(const FileStorage& storage, int offset, int size, IParserInfo_Provider* provider) {
44     m_storage.set_str_provider(provider);
45     m_storage.get_storage(storage, offset, size);
46     this->parser_info_provider = provider;
47     parsing_layout_table();
48 }
49
50 int BinLayoutParser::
51 get_layout_index(const char *name) {
52     int ret = NOT_USED;
53     if (name) {
54         for (int loop = 0;loop < MAX_SCL_LAYOUT && ret == NOT_USED;loop++) {
55             if (m_layout_table[loop].name) {
56                 if (strcmp(m_layout_table[loop].name, name) == 0) {
57                     ret = loop;
58                     break;
59                 }
60             }
61         }
62     }
63     return ret;
64 }
65
66 PSclLayout BinLayoutParser::
67 get_layout_table() {
68     return m_layout_table;
69 }
70 int BinLayoutParser::
71 get_layout_size() {
72     return m_layout_size;
73 }
74
75
76 PSclLayoutKeyCoordinatePointerTable BinLayoutParser::
77 get_key_coordinate_pointer_frame() {
78     BinKeyCoordFrameParser *key_coordinate_frame_bin_parser = BinKeyCoordFrameParser::get_instance();
79     return key_coordinate_frame_bin_parser->get_key_coordinate_pointer_frame();
80 }
81
82 void BinLayoutParser::
83 parsing_layout_table() {
84     // 4 byte (range[0-4,294,967,295))
85     const int DATA_SIZE_BYTES = 4;
86     // 1 byte (range[0-128))
87     const int REC_NUM_BYTES = 1;
88     // 2 byte (range[0-65536))
89     const int LAYOUT_REC_DATA_SIZE_BYTES = 2;
90
91     /*open binary file*/
92     Layout_width record_width;
93     set_layout_width(*parser_info_provider, record_width);
94
95     // skip data size
96     m_storage.advance(DATA_SIZE_BYTES);
97
98     // rec_num
99     m_layout_size = m_storage.get<sint_t>(REC_NUM_BYTES);
100
101     // layout_rec_data_size
102     m_storage.advance(LAYOUT_REC_DATA_SIZE_BYTES);
103
104     for (int i = 0; i < m_layout_size; ++i) {
105         SclLayout& cur = m_layout_table[i];
106         decode_layout_record(cur, record_width);
107     }
108 #ifdef __SCL_TXT_DEBUG
109     put_layout_table(DECODE, m_layout_table);
110 #endif
111 }
112
113 void
114 BinLayoutParser::
115 decode_color(SclColor& color, int width) {
116     if (width <= 0) return;
117
118     color.r = m_storage.get<sint_t>(width);
119     color.g = m_storage.get<sint_t>(width);
120     color.b = m_storage.get<sint_t>(width);
121     color.a = m_storage.get<sint_t>(width);
122 }
123 void BinLayoutParser::
124 decode_layout_record(SclLayout& cur, const Layout_width& record_width) {
125     //name
126     m_storage.get_str(&(cur.name), record_width.name, m_string_collector);
127     //display mode
128     cur.display_mode = (SCLDisplayMode)m_storage.get<sint_t>(record_width.display_mode);
129     //style
130     cur.style = (SCLLayoutStyle)m_storage.get<sint_t>(record_width.style);
131     //width
132     cur.width = m_storage.get<sint_t>(record_width.width);
133     //height
134     cur.height = m_storage.get<sint_t>(record_width.height);
135     //use_sw_button
136     cur.use_sw_button = m_storage.get<sint_t>(record_width.use_sw_button);
137
138     //use_magnifier_window
139     cur.use_magnifier_window = m_storage.get<sint_t>(record_width.use_magnifier_window);
140
141     //extract_background
142     cur.extract_background = m_storage.get<sint_t>(record_width.extract_background);
143
144     //key_width
145     cur.key_width = m_storage.get<sint_t>(record_width.key_width);
146     //key_height
147     cur.key_height = m_storage.get<sint_t>(record_width.key_height);
148     //key_spacing
149     cur.key_spacing = m_storage.get<sint_t>(record_width.key_spacing);
150     //row_spacing
151     cur.row_spacing = m_storage.get<sint_t>(record_width.row_spacing);
152     //use_sw_background
153     cur.use_sw_background = m_storage.get<sint_t>(record_width.use_sw_background);
154
155     decode_color(cur.bg_color, record_width.bg_color);
156     //bg_line_width
157     cur.bg_line_width = m_storage.get<float_t>(record_width.bg_line_width);
158
159     decode_color(cur.bg_line_color, record_width.bg_line_color);
160
161     //add_grab_left
162     cur.add_grab_left = m_storage.get<sint_t>(record_width.add_grab_left);
163
164     //add_grab_right
165     cur.add_grab_right = m_storage.get<sint_t>(record_width.add_grab_right);
166     //add_grab_top
167     cur.add_grab_top = m_storage.get<sint_t>(record_width.add_grab_top);
168     //add_grab_bottom
169     cur.add_grab_bottom = m_storage.get<sint_t>(record_width.add_grab_bottom);
170     //image_path
171     for (int i = 0; i < SCL_BUTTON_STATE_MAX; ++i) {
172         m_storage.get_str(&(cur.image_path[i]), record_width.image_path, m_string_collector);
173     }
174
175     //key_background_image
176     for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
177         for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
178             m_storage.get_str(&(cur.key_background_image[i][j]), record_width.key_background_image, m_string_collector);
179         }
180     }
181
182     //sound_style
183     m_storage.get_str(&(cur.sound_style), record_width.sound_style, m_string_collector);
184
185     //vibe_style
186     m_storage.get_str(&(cur.vibe_style), record_width.vibe_style, m_string_collector);
187
188     //label_type
189     m_storage.get_str(&(cur.label_type), record_width.label_type, m_string_collector);
190
191     //modifier_decorator
192     m_storage.get_str(&(cur.modifier_decorator), record_width.modifier_decorator, m_string_collector);
193 }
194
195