25b4c53fb1ef57f2367f351b3d3a3113424147e2
[framework/uifw/libscl-ui.git] / scl / sclui.cpp
1 /*
2  * Copyright 2012-2013 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://floralicense.org/license/
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 "sclui.h"
19 #include "scluiimpl.h"
20
21 using namespace scl;
22
23 CSCLUI::CSCLUI()
24 {
25     m_impl = CSCLUIImpl::get_instance();
26 }
27
28 CSCLUI::~CSCLUI()
29 {
30     delete m_impl;
31 }
32
33 sclboolean CSCLUI::init(sclwindow parent, const SCLParserType parser_type, const char *entry_filepath)
34 {
35     sclboolean ret = FALSE;
36     if (m_impl) {
37         ret = m_impl->init(parent, parser_type, entry_filepath);
38     }
39     return ret;
40 }
41
42 /**
43  * Shows the SCL main window
44  * For displaying the SCL UI, you should explicitly call this function after CSCLUI class is created
45  */
46 void
47 //CSCLUI::show(sclboolean auto_relocate /* = TRUE */ )
48 CSCLUI::show()
49 {
50     if (m_impl) {
51         m_impl->show();
52     }
53 }
54
55 /**
56  * Hides the SCL main window
57  * The real hide action does not work about base window because that is child of the active window
58  */
59 void
60 CSCLUI::hide()
61 {
62     if (m_impl) {
63         m_impl->hide();
64     }
65 }
66
67
68 /**
69  * Regists an event callback function
70  * so that the user which uses SCL can recevies all events occuring in running
71  */
72 void
73 CSCLUI::set_ui_event_callback(ISCLUIEventCallback *callback, const sclchar *input_mode)
74 {
75     if (m_impl) {
76         m_impl->set_ui_event_callback(callback, input_mode);
77     }
78 }
79
80 /**
81  * Sets the current input mode to the given mode
82  * @Usage
83  * gCore->set_input_mode("INPUT_MODE_SYMBOL");
84  */
85 sclboolean
86 CSCLUI::set_input_mode(const sclchar *input_mode)
87 {
88     sclboolean ret = FALSE;
89
90     if (m_impl) {
91         ret = m_impl->set_input_mode(input_mode);
92     }
93
94     return ret;
95 }
96
97 /**
98  * Sets the current rotation
99  */
100 sclboolean
101 CSCLUI::set_rotation(SCLRotation rotation)
102 {
103     sclboolean ret = FALSE;
104
105     if (m_impl) {
106         ret = m_impl->set_rotation(rotation);
107     }
108
109     return ret;
110 }
111
112 /**
113  * Gets the current rotation
114  */
115 SCLRotation
116 CSCLUI::get_rotation()
117 {
118     SCLRotation ret = ROTATION_0;
119
120     if (m_impl) {
121         ret = m_impl->get_rotation();
122     }
123
124     return ret;
125 }
126
127 /**
128  * Returns the current display mode
129  */
130 SCLDisplayMode
131 CSCLUI::get_display_mode()
132 {
133     SCLDisplayMode ret = DISPLAYMODE_PORTRAIT;
134
135     if (m_impl) {
136         ret = m_impl->get_display_mode();
137     }
138
139     return ret;
140 }
141
142 /**
143  * Returns the current input mode
144  */
145 const sclchar*
146 CSCLUI::get_input_mode()
147 {
148     const sclchar *ret = NULL;
149
150     if (m_impl) {
151         ret = m_impl->get_input_mode();
152     }
153
154     return ret;
155 }
156
157
158
159 /**
160  * Sets a private key to the current context
161  * The other properties except given parameters will keep to the orginal value.
162  * @Usage
163  * gCore->set_private_key(INPUT_MODE_NUMBER, LYT_PORTRAIT_NOW_3x4, 0, "private", 999, TRUE);
164  *
165  * @param fRedraw If true, it will redraw the current key
166  */
167 sclint
168 CSCLUI::set_private_key(const sclchar* custom_id, sclchar* label, sclchar* imagelabel[SCL_BUTTON_STATE_MAX], sclchar* imagebg[SCL_BUTTON_STATE_MAX], sclulong key_event, sclchar *key_value, sclboolean redraw)
169 {
170     sclint ret = NOT_USED;
171
172     if (m_impl) {
173         ret = m_impl->set_private_key(custom_id, label, imagelabel, imagebg, key_event, key_value, redraw);
174     }
175
176     return ret;
177 }
178
179
180 /**
181 * Unsets a private key to the current context
182 */
183 void
184 CSCLUI::unset_private_key(const sclchar* custom_id)
185 {
186     if (m_impl) {
187         m_impl->unset_private_key(custom_id);
188     }
189 }
190
191 /**
192 * Sets the current theme
193 */
194 /* FIXME : If setting themename is not allowed before initializing,
195            the default theme has to be loaded regardless of current theme name
196            and the appropriate current theme has to be loaded afterwards, which is very inefficient */
197 sclboolean
198 CSCLUI::set_cur_themename(const sclchar *themename)
199 {
200     sclboolean ret = FALSE;
201
202     if (m_impl) {
203         ret = m_impl->set_cur_themename(themename);
204     }
205
206     return ret;
207 }
208
209 SCLShiftState
210 CSCLUI::get_shift_state()
211 {
212     SCLShiftState ret = SCL_SHIFT_STATE_OFF;
213     if (m_impl) {
214         ret = m_impl->get_shift_state();
215     }
216     return ret;
217 }
218
219 void
220 CSCLUI::set_shift_state(SCLShiftState state)
221 {
222     if (m_impl) {
223         m_impl->set_shift_state(state);
224     }
225 }
226
227 /**
228  * This function will be called by the user which uses SCL when the context of the focus application is changed
229  * ISE user should explicitly call this function when the context of application is changed.
230  * For instance, focus-changed, application-changed,, and so on.
231  * This function will call CSCLController to init the related variables.
232  */
233 void
234 CSCLUI::notify_app_focus_changed()
235 {
236     if (m_impl) {
237         m_impl->notify_app_focus_changed();
238     }
239 }
240
241 void
242 CSCLUI::reset_popup_timeout()
243 {
244     if (m_impl) {
245         m_impl->notify_app_focus_changed();
246     }
247 }
248
249 void
250 CSCLUI::close_all_popups()
251 {
252     if (m_impl) {
253         m_impl->close_all_popups();
254     }
255 }
256
257 /**
258  * Returns a scale rate (see default screen resolution in sclconfig.h file)
259  */
260 sclfloat
261 CSCLUI::get_scale_rate()
262 {
263     sclfloat ret = 0.0f;
264     if (m_impl) {
265         ret = m_impl->get_scale_rate();
266     }
267     return ret;
268 }
269
270 /**
271  * Returns a calculated x value according to the current screen resolution
272  */
273 scl16
274 CSCLUI::get_scale_x(scl16 x)
275 {
276     scl16 ret = 0;
277     if (m_impl) {
278         ret = m_impl->get_scale_x(x);
279     }
280     return ret;
281 }
282
283 /**
284  * Returns a calculated y value according to the current screen resolution
285  */
286 scl16
287 CSCLUI::get_scale_y(scl16 y)
288 {
289     scl16 ret = 0;
290     if (m_impl) {
291         ret = m_impl->get_scale_y(y);
292     }
293     return ret;
294 }
295
296 /**
297  * Returns the scl main window size
298  */
299 SclRectangle
300 CSCLUI::get_main_window_rect()
301 {
302     SclRectangle ret = {0};
303
304     if (m_impl) {
305         ret = m_impl->get_main_window_rect();
306     }
307
308     return ret;
309 }
310
311 /**
312  * Returns the size of given input mode
313  */
314 SclSize
315 CSCLUI::get_input_mode_size(const sclchar *input_mode, SCLDisplayMode display_mode)
316 {
317     SclSize ret = {0};
318
319     if (m_impl) {
320         ret = m_impl->get_input_mode_size(input_mode, display_mode);
321     }
322
323     return ret;
324 }
325
326 /**
327 * Returns the screen resolution
328 */
329 void
330 CSCLUI::get_screen_resolution(sclint *width, sclint *height)
331 {
332     if (m_impl) {
333         m_impl->get_screen_resolution(width, height);
334     }
335 }
336
337
338
339 void
340 CSCLUI::set_debug_mode(SCLDebugMode mode)
341 {
342     if (m_impl) {
343         m_impl->set_debug_mode(mode);
344     }
345 }
346
347 SCLDebugMode
348 CSCLUI::get_debug_mode()
349 {
350     SCLDebugMode ret = DEBUGMODE_DISABLED;
351     if (m_impl) {
352         ret = m_impl->get_debug_mode();
353     }
354     return ret;
355 }
356
357 void
358 CSCLUI::set_update_pending(sclboolean pend)
359 {
360     if (m_impl) {
361         m_impl->set_update_pending(pend);
362     }
363 }
364
365 void
366 CSCLUI::enable_button(const sclchar* custom_id, sclboolean enabled)
367 {
368     if (m_impl) {
369         m_impl->enable_button(custom_id, enabled);
370     }
371 }
372
373 sclint
374 CSCLUI::get_multi_touch_context_num()
375 {
376     sclint ret = 0;
377     if (m_impl) {
378         ret = m_impl->get_multi_touch_context_num();
379     }
380     return ret;
381 }
382
383 sclboolean
384 CSCLUI::get_multi_touch_event(sclint seqorder, SclUIEventDesc *desc)
385 {
386     sclboolean ret = FALSE;
387     if (m_impl) {
388         ret = m_impl->get_multi_touch_event(seqorder, desc);
389     }
390     return ret;
391 }
392
393 sclboolean
394 CSCLUI::set_longkey_duration(scllong msc)
395 {
396     sclboolean ret = FALSE;
397     if (m_impl) {
398         ret = m_impl->set_longkey_duration(msc);
399     }
400     return ret;
401 }
402
403 sclboolean
404 CSCLUI::set_longkey_cancel_dist(sclshort dist)
405 {
406     sclboolean ret = FALSE;
407     if (m_impl) {
408         ret = m_impl->set_longkey_cancel_dist(dist);
409     }
410     return ret;
411 }
412
413 sclboolean
414 CSCLUI::set_repeatkey_duration(scllong msc)
415 {
416     sclboolean ret = FALSE;
417     if (m_impl) {
418         ret = m_impl->set_repeatkey_duration(msc);
419     }
420     return ret;
421 }
422
423 sclboolean
424 CSCLUI::set_autopoup_key_duration(scllong msc)
425 {
426     sclboolean ret = FALSE;
427     if (m_impl) {
428         ret = m_impl->set_autopoup_key_duration(msc);
429     }
430     return ret;
431 }
432
433 sclboolean
434 CSCLUI::set_button_delay_duration(scllong msc)
435 {
436     sclboolean ret = FALSE;
437     if (m_impl) {
438         ret = m_impl->set_button_delay_duration(msc);
439     }
440     return ret;
441 }
442
443 void
444 CSCLUI::enable_magnifier(sclboolean enabled)
445 {
446     if (m_impl) {
447         m_impl->enable_magnifier(enabled);
448     }
449 }
450
451 void
452 CSCLUI::enable_sound(sclboolean enabled)
453 {
454     if (m_impl) {
455         m_impl->enable_sound(enabled);
456     }
457 }
458
459 void
460 CSCLUI::enable_vibration(sclboolean enabled)
461 {
462     if (m_impl) {
463         m_impl->enable_vibration(enabled);
464     }
465 }
466
467 void
468 CSCLUI::enable_tts(sclboolean enabled)
469 {
470     if (m_impl) {
471         m_impl->enable_tts(enabled);
472     }
473 }
474
475 void
476 CSCLUI::enable_shift_multi_touch(sclboolean enabled)
477 {
478     if (m_impl) {
479         m_impl->enable_shift_multi_touch(enabled);
480     }
481 }
482
483 void
484 CSCLUI::enable_touch_offset(sclboolean enabled)
485 {
486     if (m_impl) {
487         m_impl->enable_touch_offset(enabled);
488     }
489 }
490
491 void
492 CSCLUI::disable_input_events(sclboolean disabled)
493 {
494     if (m_impl) {
495         m_impl->disable_input_events(disabled);
496     }
497 }
498
499 sclboolean
500 CSCLUI::set_cur_sublayout(const sclchar *sub_layout_name)
501 {
502     sclboolean ret = FALSE;
503     if (m_impl) {
504         ret = m_impl->set_cur_sublayout(sub_layout_name);
505     }
506     return ret;
507 }
508
509 const sclchar*
510 CSCLUI::get_cur_sublayout()
511 {
512     const sclchar* ret = NULL;
513     if (m_impl) {
514         ret = m_impl->get_cur_sublayout();
515     }
516     return ret;
517 }
518
519 void
520 CSCLUI::set_custom_magnifier_label(scltouchdevice touch_id, sclint index, const sclchar* label)
521 {
522     if (m_impl) {
523         m_impl->set_custom_magnifier_label(touch_id, index, label);
524     }
525 }
526
527 void
528 CSCLUI::set_string_substitution(const sclchar *original, const sclchar *substitute)
529 {
530     if (m_impl) {
531         m_impl->set_string_substitution(original, substitute);
532     }
533 }
534
535 void
536 CSCLUI::unset_string_substitution(const sclchar *original)
537 {
538     if (m_impl) {
539         m_impl->unset_string_substitution(original);
540     }
541 }