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.
18 #include "resource_storage_impl.h"
19 #include "encode_key_coordinate_frame.h"
21 #include "xmlresource.h"
22 #include "put_record.h"
23 #include "_auto_metadata.h"
24 using namespace xmlresource;
27 encode_key_coordinate_record(ResourceStorage& storage, const PSclLayoutKeyCoordinate cur, const Key_coordinate_record_width& record_width) {
28 if (cur == NULL) return;
31 storage.put<sint_t>(cur->x, record_width.x);
34 storage.put<sint_t>(cur->y, record_width.y);
37 storage.put<sint_t>(cur->width, record_width.width);
40 storage.put<sint_t>(cur->height, record_width.height);
43 storage.put<sint_t>(cur->add_hit_left, record_width.add_hit_left);
46 storage.put<sint_t>(cur->add_hit_right, record_width.add_hit_right);
49 storage.put<sint_t>(cur->add_hit_top, record_width.add_hit_top);
52 storage.put<sint_t>(cur->add_hit_bottom, record_width.add_hit_bottom);
55 storage.put<sint_t>(cur->popup_relative_x, record_width.popup_relative_x);
58 storage.put<sint_t>(cur->popup_relative_y, record_width.popup_relative_y);
61 storage.put<sint_t>(cur->extract_offset_x, record_width.extract_offset_x);
64 storage.put<sint_t>(cur->extract_offset_y, record_width.extract_offset_y);
66 storage.encode_string(cur->sub_layout, record_width.sub_layout);
69 storage.put<sint_t>(cur->magnifier_offset_x, record_width.magnifier_offset_x);
72 storage.put<sint_t>(cur->magnifier_offset_y, record_width.magnifier_offset_y);
74 storage.encode_string(cur->custom_id, record_width.custom_id);
77 storage.put<sint_t>(cur->button_type, record_width.button_type);
80 storage.put<sint_t>(cur->key_type, record_width.key_type);
83 storage.put<sint_t>(cur->popup_type, record_width.popup_type);
85 storage.put<sint_t>(cur->use_magnifier, record_width.use_magnifier);
86 storage.put<sint_t>(cur->use_long_key_magnifier, record_width.use_long_key_magnifier);
89 for (int i = 0; i < SCL_DRAG_STATE_MAX; ++i) {
90 storage.encode_string(cur->popup_input_mode[i], record_width.popup_input_mode);
93 storage.encode_string(cur->sound_style, record_width.sound_style);
94 storage.encode_string(cur->vibe_style, record_width.vibe_style);
95 storage.put<sint_t>(cur->is_side_button, record_width.is_side_button);
98 storage.put<sint_t>(cur->label_count, record_width.label_count);
101 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
102 for (int j = 0; j < MAX_SIZE_OF_LABEL_FOR_ONE; ++j) {
103 storage.encode_string(cur->label[i][j], record_width.label);
107 storage.encode_string(cur->label_type, record_width.label_type);
110 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
111 for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
112 storage.encode_string(cur->image_label_path[i][j], record_width.image_label_path);
116 storage.encode_string(cur->image_label_type, record_width.image_label_type);
119 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
120 for (int j = 0; j < SCL_BUTTON_STATE_MAX; ++j) {
121 storage.encode_string(cur->bg_image_path[i][j], record_width.bg_image_path);
126 storage.put<sint_t>(cur->key_value_count, record_width.key_value_count);
129 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
130 for (int j = 0; j < MAX_SIZE_OF_MULTITAP_CHAR; ++j) {
131 storage.encode_string(cur->key_value[i][j], record_width.key_value);
135 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
136 for (int j = 0; j < MAX_SIZE_OF_LABEL_FOR_ONE; ++j) {
137 storage.put<sint_t>(cur->key_event[i][j], record_width.key_event);
141 storage.put<sint_t>(cur->long_key_type, record_width.long_key_type);
144 storage.encode_string(cur->long_key_value, record_width.long_key_value);
147 storage.put<sint_t>(cur->long_key_event, record_width.long_key_event);
149 storage.put<sint_t>(cur->use_repeat_key, record_width.use_repeat_key);
152 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
153 for (int j = 0; j < MAX_SIZE_OF_AUTOPOPUP_STRING; ++j) {
154 storage.encode_string(cur->autopopup_key_labels[i][j], record_width.autopopup_key_labels);
155 storage.encode_string(cur->autopopup_key_values[i][j], record_width.autopopup_key_values);
156 storage.put<sint_t>(cur->autopopup_key_events[i][j], record_width.autopopup_key_events);
160 storage.put<sint_t>(cur->dont_close_popup, record_width.dont_close_popup);
163 storage.put<sint_t>(cur->extra_option, record_width.extra_option);
166 storage.put<sint_t>(cur->multitouch_type, record_width.multitouch_type);
169 storage.encode_string(cur->modifier_decorator, record_width.modifier_decorator);
172 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
173 for (int j = 0; j < MAX_SIZE_OF_LABEL_FOR_ONE; ++j) {
174 storage.encode_string(cur->magnifier_label[i][j], record_width.magnifier_label);
179 for (int i = 0; i < SCL_SHIFT_STATE_MAX; ++i) {
180 for (int j = 0; j < MAX_SIZE_OF_MULTITAP_CHAR; ++j) {
181 storage.encode_string(cur->hint_string[i][j], record_width.hint_string);
186 const int get_layout_num(const PSclLayoutKeyCoordinatePointerTable keyCoordinatePointerFrame) {
187 assert(keyCoordinatePointerFrame != NULL);
188 int layout_num = MAX_SCL_LAYOUT;
189 for ( int i = 0; i < MAX_SCL_LAYOUT; ++i ) {
190 // NULL is the end flag
191 if (keyCoordinatePointerFrame[i][0] == NULL) {
200 const int get_key_num(const PSclLayoutKeyCoordinatePointerTable keyCoordinatePointerFrame, const int layout_no) {
201 assert(keyCoordinatePointerFrame != NULL);
202 int key_num = MAX_KEY;
204 SclLayoutKeyCoordinatePointer* curLayoutRecordPointers = keyCoordinatePointerFrame[layout_no];
205 for (int i = 0; i < MAX_KEY; ++i) {
206 if (curLayoutRecordPointers[i] == NULL) {
217 encode_key_coordinate_frame_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
218 XMLResource *xmlresource = XMLResource::get_instance();
220 int layout_num = xmlresource->get_layout_size();
221 assert(layout_num >= 0);
222 SclLayoutKeyCoordinatePointer _key_coordinate_pointer_frame[MAX_SCL_LAYOUT][MAX_KEY];
223 memset(_key_coordinate_pointer_frame, 0x00, MAX_KEY * MAX_SCL_LAYOUT * sizeof(SclLayoutKeyCoordinatePointer));
225 for (int i = 0; i < layout_num; ++i) {
226 xmlresource->load(i);
227 for (int j = 0; j < MAX_KEY; ++j) {
228 _key_coordinate_pointer_frame[i][j] = xmlresource->get_key_coordinate_pointer_frame()[i][j];
231 // 4 byte (range[0-4,294,967,295))
232 const int DATA_SIZE_BYTES = 4;
233 // 1 byte (range[0-128))
234 const int REC_NUM_BYTES = 1;
235 const int KEY_NUM_BYTES = 1;
236 // 2 byte (range[0-65536))
237 const int KEY_COORDIANTE_REC_DATA_SIZE_BYTES = 2;
239 int init_size = storage.get_size();
241 storage.reserve(DATA_SIZE_BYTES);
243 //TODO: assert layout_num < REC_NUM_BYTES's range
244 storage.put<uint_t>(layout_num, REC_NUM_BYTES);
246 int *pKey_num_array = new int[layout_num];
247 memset(pKey_num_array, 0x00, layout_num * sizeof(int));
248 for (int i = 0; i < layout_num; ++i) {
249 pKey_num_array[i] = get_key_num(_key_coordinate_pointer_frame, i);
250 //TODO: assert key_num < KEY_NUM_BYTES's range
251 storage.put<uint_t>(pKey_num_array[i], KEY_NUM_BYTES);
254 // key_coordinate_rec_data_size
255 storage.reserve(KEY_COORDIANTE_REC_DATA_SIZE_BYTES);
257 Key_coordinate_record_width record_width;
258 set_key_coordinate_record_width(&md_helper, record_width);
261 int key_coordinate_rec_data_size = 0;
262 for ( int i = 0; i < layout_num; ++i ) {
263 for ( int j = 0; j < pKey_num_array[i]; ++j ) {
264 int pre_size = storage.get_size();
266 SclLayoutKeyCoordinatePointer cur = _key_coordinate_pointer_frame[i][j];
268 encode_key_coordinate_record(storage, cur, record_width);
270 int aft_size = storage.get_size();
271 if (key_coordinate_rec_data_size == 0) {
272 key_coordinate_rec_data_size = aft_size - pre_size;
274 assert(key_coordinate_rec_data_size == aft_size - pre_size);
278 delete[] pKey_num_array;
280 int advance_size = storage.get_size() - init_size;
281 storage.random_put<sint_t>(advance_size, DATA_SIZE_BYTES, init_size);
283 // random put key_coordinate_rec_data_size
284 int key_coordinate_rec_data_offset = init_size +
287 layout_num * KEY_NUM_BYTES;
288 storage.random_put<uint_t>(key_coordinate_rec_data_size,
289 KEY_COORDIANTE_REC_DATA_SIZE_BYTES,
290 key_coordinate_rec_data_offset);
292 return storage.get_size();
296 encode_key_coordinate_frame_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
299 ResourceStorage storage;
300 encode_key_coordinate_frame_file(storage, md_helper);
301 storage.toFile(file, offset);
303 return storage.get_size();
307 encode_key_coordinate_frame_file(const char* file, IMetaData_Helper& md_helper) {
310 ResourceStorage storage;
311 encode_key_coordinate_frame_file(storage, md_helper);
312 storage.toFile(file);
314 return storage.get_size();