2f7aa1cc67ca6139932a4b2e521ce3939f2fdfc7
[platform/core/uifw/libscl-ui-nui.git] / scl / sclutils.h
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 <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include <map>
23
24 #include "scltypes.h"
25 #include "sclconfig.h"
26 #include "sclstructs.h"
27
28 #ifndef __SCL_UTILS_H__
29 #define __SCL_UTILS_H__
30
31 #ifdef __cplusplus
32 //SCL_BEGIN_DECLS
33 #endif
34
35 #ifndef _POSIX_PATH_MAX
36 #define _POSIX_PATH_MAX 255
37 #endif
38
39 namespace scl
40 {
41
42 /**
43  * @brief The base class to work as a soft-based keyboard
44  *
45  * This class implements all functions for working as a soft-based keyboard
46  * In side of ISE developer, they can modify it by their requirements.
47  */
48 class CSCLUtilsImpl
49 {
50 public :
51     CSCLUtilsImpl() { m_scr_size.width = 0;m_scr_size.height = 0; }
52
53     virtual void init() = 0;
54     virtual void fini() = 0;
55
56     virtual sclboolean get_screen_resolution(sclint *x, sclint *y) = 0;
57     virtual sclboolean update_screen_resolution() = 0;
58     virtual sclboolean play_tts(const sclchar *str) = 0;
59     virtual sclboolean play_sound(const sclchar* snd_style) = 0;
60     virtual sclboolean play_vibration(const sclchar* vibe_style, const scllong duration) = 0;
61
62     virtual sclboolean open_devices() = 0;
63     virtual sclboolean close_devices() = 0;
64
65     virtual sclint log(const sclchar *msg) = 0;
66
67 protected:
68     SclSize m_scr_size;
69 };
70
71 class CSCLUtilsImplLinux : public CSCLUtilsImpl
72 {
73 public :
74     void init();
75     void fini();
76
77     sclboolean get_screen_resolution(sclint *x, sclint *y);
78     sclboolean update_screen_resolution();
79     sclboolean play_tts(const sclchar *str);
80     sclboolean play_sound(const sclchar* snd_style);
81     sclboolean play_vibration(const sclchar* vibe_style, const scllong duration);
82
83     sclboolean open_devices();
84     sclboolean close_devices();
85
86     sclint log(const sclchar *msg);
87 };
88
89 class CSCLUtilsImplWin32 : public CSCLUtilsImpl
90 {
91 public :
92     void init();
93     void fini();
94
95     sclboolean get_screen_resolution(sclint *x, sclint *y);
96     sclboolean update_screen_resolution();
97     sclboolean play_tts(const sclchar *str);
98     sclboolean play_sound(const sclchar* snd_style);
99     sclboolean play_vibration(const sclchar* vibe_style, const scllong duration);
100
101     sclboolean open_devices();
102     sclboolean close_devices();
103
104     sclint log(const sclchar *msg);
105 };
106
107 class _CSCLUtils
108 {
109 public :
110     _CSCLUtils();
111
112     virtual void init();
113     virtual void fini();
114     virtual sclboolean get_screen_resolution(sclint *x, sclint *y);
115     virtual sclboolean update_screen_resolution();
116     virtual sclboolean play_tts(const sclchar *str);
117     virtual sclboolean play_sound(const sclchar* snd_style);
118     virtual sclboolean play_vibration(const sclchar* vibe_style, const scllong duration);
119 protected :
120     CSCLUtilsImpl* GetCSCLUtilsImpl();
121
122 private :
123     CSCLUtilsImpl* m_impl;
124 };
125
126 class EXAPI CSCLUtils : public _CSCLUtils
127 {
128 private:
129     CSCLUtils();
130 public :
131     virtual ~CSCLUtils();
132
133     static CSCLUtils* get_instance();
134
135     void init();
136     void fini();
137
138     void scale_x(scl16 *x);
139     void scale_y(scl16 *y);
140     scl16 get_scaled_x(scl16 x);
141     scl16 get_scaled_y(scl16 y);
142     sclfloat get_smallest_scale_rate();
143     sclfloat get_scale_rate_x();
144     sclfloat get_scale_rate_y();
145     sclfloat get_smallest_custom_scale_rate();
146     sclfloat get_custom_scale_rate_x();
147     sclfloat get_custom_scale_rate_y();
148
149     void set_custom_scale_rate_x(sclfloat x);
150     void set_custom_scale_rate_y(sclfloat y);
151
152     sclchar* get_str_dup(const sclchar* str);
153
154     sclboolean sleep(sclulong msc);
155
156     sclchar* get_composed_path(sclchar* buf, const sclchar* prefix, const sclchar* path);
157     sclchar* get_decomposed_path(sclchar* buf, const sclchar* prefix, const sclchar* path);
158     const SclNinePatchInfo* get_nine_patch_info(const sclchar *image_path);
159
160     sclboolean get_autopopup_window_variables(sclchar * const autopopup_keys[MAX_SIZE_OF_AUTOPOPUP_STRING], sclbyte *num_keys,
161         sclbyte *num_columns, sclbyte *num_rows, sclint *width, sclint *height);
162
163     scl16 get_unique_id();
164
165     sclboolean is_rect_overlap(SclRectangle rect1, SclRectangle rect2);
166     sclfloat get_distance(sclint x1, sclint y1, sclint x2, sclint y2);
167     sclfloat get_distance(SclPoint pt1, SclPoint pt2);
168
169     sclfloat get_approximate_distance(sclint x1, sclint y1, sclint x2, sclint y2);
170     sclfloat get_approximate_distance(SclPoint pt1, SclPoint pt2);
171
172     sclint log(const sclchar *fmt, ...);
173
174     void update_scale_rate_values();
175     sclboolean update_screen_resolution();
176 private :
177     sclfloat m_scn_rate_x;
178     sclfloat m_scn_rate_y;
179
180     sclfloat m_custom_scale_rate_x;
181     sclfloat m_custom_scale_rate_y;
182
183     sclint m_scn_resolution_x;
184     sclint m_scn_resolution_y;
185
186     std::map<sclchar*, SclNinePatchInfo> m_nine_patch_info_map;
187 };
188
189
190 } /* End of scl namespace */
191
192 #ifdef __cplusplus
193 //SCL_END_DECLS
194 #endif
195
196 #endif //__SCL_UTILS_H__