2 * Copyright 2012-2013 Samsung Electronics Co., Ltd.
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
8 * http://floralicense.org/license/
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 const int get_layout_num(const PSclLayoutKeyCoordinatePointerTable keyCoordinatePointerFrame) {
180 assert(keyCoordinatePointerFrame != NULL);
181 int layout_num = MAX_SCL_LAYOUT;
182 for ( int i = 0; i < MAX_SCL_LAYOUT; ++i) {
183 // NULL is the end flag
184 if (keyCoordinatePointerFrame[i][0] == NULL) {
193 const int get_key_num(const PSclLayoutKeyCoordinatePointerTable keyCoordinatePointerFrame, const int layout_no) {
194 assert(keyCoordinatePointerFrame != NULL);
195 int key_num = MAX_KEY;
197 SclLayoutKeyCoordinatePointer* curLayoutRecordPointers = keyCoordinatePointerFrame[layout_no];
198 for (int i = 0; i < MAX_KEY; ++i) {
199 if (curLayoutRecordPointers[i] == NULL) {
210 encode_key_coordinate_frame_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
212 XMLResource *xmlresource = XMLResource::get_instance();
214 int layout_num = xmlresource->get_layout_size();
215 assert(layout_num >= 0);
216 SclLayoutKeyCoordinatePointer _key_coordinate_pointer_frame[MAX_SCL_LAYOUT][MAX_KEY];
217 memset(_key_coordinate_pointer_frame, 0x00, MAX_KEY * MAX_SCL_LAYOUT * sizeof(SclLayoutKeyCoordinatePointer));
219 if (xmlresource->get_default_configure()->use_lazy_loading == FALSE) {
220 for (int i = 0; i < layout_num; ++i) {
221 for (int j = 0; j < MAX_KEY; ++j) {
222 _key_coordinate_pointer_frame[i][j] = xmlresource->get_key_coordinate_pointer_frame()[i][j];
226 for (int i = 0; i < layout_num; ++i) {
227 xmlresource->load(i);
228 for (int j = 0; j < MAX_KEY; ++j) {
229 _key_coordinate_pointer_frame[i][j] = xmlresource->get_key_coordinate_pointer_frame()[i][j];
233 // 4 byte (range[0-4,294,967,295))
234 const int DATA_SIZE_BYTES = 4;
235 // 1 byte (range[0-128))
236 const int REC_NUM_BYTES = 1;
237 const int KEY_NUM_BYTES = 1;
238 // 2 byte (range[0-65536))
239 const int KEY_COORDIANTE_REC_DATA_SIZE_BYTES = 2;
241 int init_size = storage.size();
243 storage.reserve(DATA_SIZE_BYTES);
245 //TODO: assert layout_num < REC_NUM_BYTES's range
246 storage.put<uint_t>(layout_num, REC_NUM_BYTES);
248 int *pKey_num_array = new int[layout_num];
249 memset(pKey_num_array, 0x00, layout_num * sizeof(int));
250 for (int i = 0; i < layout_num; ++i) {
251 pKey_num_array[i] = get_key_num(_key_coordinate_pointer_frame, i);
252 //TODO: assert key_num < KEY_NUM_BYTES's range
253 storage.put<uint_t>(pKey_num_array[i], KEY_NUM_BYTES);
256 // key_coordinate_rec_data_size
257 storage.reserve(KEY_COORDIANTE_REC_DATA_SIZE_BYTES);
259 Key_coordinate_record_width record_width;
260 set_key_coordinate_record_width(md_helper, record_width);
263 int key_coordinate_rec_data_size = 0;
264 for ( int i = 0; i < layout_num; ++i) {
265 for ( int j = 0; j < pKey_num_array[i]; ++j) {
266 int pre_size = storage.size();
268 SclLayoutKeyCoordinatePointer cur = _key_coordinate_pointer_frame[i][j];
270 encode_key_coordinate_record(storage, cur, record_width);
272 int aft_size = storage.size();
273 if (key_coordinate_rec_data_size == 0) {
274 key_coordinate_rec_data_size = aft_size - pre_size;
276 assert(key_coordinate_rec_data_size == aft_size - pre_size);
280 delete[] pKey_num_array;
282 int advance_size = storage.size() - init_size;
283 storage.random_put<sint_t>(advance_size, DATA_SIZE_BYTES, init_size);
285 // random put key_coordinate_rec_data_size
286 int key_coordinate_rec_data_offset = init_size +
289 layout_num * KEY_NUM_BYTES;
290 storage.random_put<uint_t>(key_coordinate_rec_data_size,
291 KEY_COORDIANTE_REC_DATA_SIZE_BYTES,
292 key_coordinate_rec_data_offset);
294 return storage.size();
298 encode_key_coordinate_frame_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
301 ResourceStorage storage;
302 encode_key_coordinate_frame_file(storage, md_helper);
303 storage.toFile(file, offset);
305 return storage.size();
309 encode_key_coordinate_frame_file(const char* file, IMetaData_Helper& md_helper) {
312 ResourceStorage storage;
313 encode_key_coordinate_frame_file(storage, md_helper);
314 storage.toFile(file);
316 return storage.size();