Reload xml files when resolution gets changed
[platform/core/uifw/libscl-ui.git] / xml2binary / encode_default_configure.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 "encode_default_configure.h"
19 #include "xmlresource.h"
20 #include "resource_storage_impl.h"
21 using namespace xmlresource;
22
23 #include "put_record.h"
24 #include "_auto_metadata.h"
25 static void _encode_color(ResourceStorage& storage, const SclColor& color, int width) {
26     if (width <= 0) return;
27
28     storage.put<sint_t>(color.r, width);
29     storage.put<sint_t>(color.g, width);
30     storage.put<sint_t>(color.b, width);
31     storage.put<sint_t>(color.a, width);
32 }
33 static void
34 encode_default_configure_record(ResourceStorage& storage, const PSclDefaultConfigure cur, const Default_configure_width& record_width) {
35     //display_mode
36     storage.put<sint_t>((int)cur->display_mode, record_width.display_mode);
37
38     //input_mode
39     storage.encode_string(cur->input_mode, record_width.input_mode);
40
41     //image_file_base_path
42     storage.encode_string(cur->image_file_base_path, record_width.image_file_base_path);
43
44     //target_screen_width
45     storage.put<sint_t>(cur->target_screen_width, record_width.target_screen_width);
46
47     //target_screen_height
48     storage.put<sint_t>(cur->target_screen_height, record_width.target_screen_height);
49
50     //auto_detect_landscape
51     storage.put<sint_t>(cur->auto_detect_landscape, record_width.auto_detect_landscape);
52
53     //use_magnifier_window
54     storage.put<sint_t>(cur->use_magnifier_window, record_width.use_magnifier_window);
55
56     //use_auto_popup
57     storage.put<sint_t>(cur->use_auto_popup, record_width.use_auto_popup);
58
59     //use_zoom_window
60     storage.put<sint_t>(cur->use_zoom_window, record_width.use_zoom_window);
61
62     //on_error_noti_send
63     storage.put<sint_t>(cur->on_error_noti_send, record_width.on_error_noti_send);
64
65     //use_word_deletion
66     storage.put<sint_t>(cur->use_word_deletion, record_width.use_word_deletion);
67
68     //sw_button_style
69     storage.put<sint_t>(cur->sw_button_style, record_width.sw_button_style);
70
71     //touch_offset_level
72     for (int i = 0; i < DISPLAYMODE_MAX; ++i) {
73         storage.put<sint_t>((int)cur->touch_offset_level[i], record_width.touch_offset_level);
74     }
75
76     //touch_offset
77     for (int i = 0; i < DISPLAYMODE_MAX; ++i) {
78         storage.put<sint_t>((int)cur->touch_offset[i].x, record_width.touch_offset);
79         storage.put<sint_t>((int)cur->touch_offset[i].y, record_width.touch_offset);
80     }
81
82     //default_sub_layout
83     storage.encode_string(cur->default_sub_layout, record_width.default_sub_layout);
84
85     //use_actual_dim_window
86     storage.put<sint_t>(cur->use_actual_dim_window, record_width.use_actual_dim_window);
87
88     //dim_color
89     _encode_color(storage, cur->dim_color, record_width.dim_color);
90 }
91
92 int
93 encode_default_configure_file(ResourceStorage& storage, IMetaData_Helper& md_helper) {
94     int init_size = storage.get_size();
95
96     XMLResource *xmlresource = XMLResource::get_instance();
97     PSclDefaultConfigure defaultConfigure = xmlresource->get_default_configure();
98
99 #ifdef __SCL_TXT_DEBUG
100     put_default_configure(ENCODE, *defaultConfigure);
101
102 #endif
103     Default_configure_width record_width;
104     set_default_configure_width(md_helper, record_width);
105
106     storage.reserve(8);
107     encode_default_configure_record(storage, defaultConfigure, record_width);
108
109     int size = storage.get_size() - init_size;
110     storage.random_put<sint_t>(size, 8, init_size);
111     return storage.get_size();
112 }
113
114 int
115 encode_default_configure_file(const char* file, IMetaData_Helper& md_helper) {
116     if (!file) return 0;
117
118     ResourceStorage storage;
119     encode_default_configure_file(storage, md_helper);
120     storage.toFile(file);
121
122     return storage.get_size();
123 }
124
125 int
126 encode_default_configure_file(const char* file, int& offset, IMetaData_Helper& md_helper) {
127     if (!file) return 0;
128
129     ResourceStorage storage;
130     encode_default_configure_file(storage, md_helper);
131     storage.toFile(file, offset);
132
133     return storage.get_size();
134 }