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.
21 #include "scluiimpl.h"
23 #include "scluibuilder.h"
24 #include "sclcontroller.h"
25 #include "sclresourcecache.h"
26 #include "sclerroradjustment.h"
27 #include "sclres_manager.h"
28 #include "scleventhandler.h"
32 CSCLUIImpl* CSCLUIImpl::m_instance = NULL; /* For singleton */
34 CSCLUIImpl::CSCLUIImpl()
38 /*CSCLUIBuilder *builder = CSCLUIBuilder::get_instance();
39 CSCLController *controller = CSCLController::get_instance();
40 if (builder && controller) {
41 builder->init(SCLWINDOW_INVALID);
46 CSCLUIImpl::~CSCLUIImpl()
52 CSCLUIImpl::get_instance()
55 m_instance = new CSCLUIImpl();
57 return (CSCLUIImpl*)m_instance;
60 sclboolean CSCLUIImpl::init(sclwindow parent, const SCLParserType parser_type, const char *entry_filepath)
64 SCL_DEBUG_ELAPASED_TIME_START();
66 SclResParserManager *sclres_manager = SclResParserManager::get_instance();
67 CSCLUIBuilder *builder = CSCLUIBuilder::get_instance();
68 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
69 CSCLUtils *utils = CSCLUtils::get_instance();
71 if (sclres_manager && builder && cache && utils) {
72 sclres_manager->init(parser_type, entry_filepath);
76 builder->init(parent);
78 PSclDefaultConfigure default_configure = sclres_manager->get_default_configure();
79 if (default_configure) {
80 set_cur_sublayout(default_configure->default_sub_layout);
86 SCL_DEBUG_ELAPASED_TIME_END();
92 * Shows the SCL main window
93 * For displaying the SCL UI, you should explicitly call this function after CSCLUIImpl class is created
96 //CSCLUIImpl::show(sclboolean auto_relocate /* = TRUE */ )
101 sclboolean ret = FALSE;
104 CSCLUtils *utils = CSCLUtils::get_instance();
105 CSCLWindows *windows = CSCLWindows::get_instance();
106 CSCLContext *context = CSCLContext::get_instance();
107 CSCLController *controller = CSCLController::get_instance();
109 if (windows && controller && context) {
110 //if (auto_relocate) {
112 /* Let's relocate our base window - bottomed center aligned */
113 sclint width, height;
114 //get_layout_size(&width, &height);
115 SclRectangle rect = get_main_window_rect();
118 utils->get_screen_resolution(&scrx, &scry);
120 sclint pos_x = (scrx - rect.width) / 2;
121 sclint pos_y = (scry - rect.height);
123 windows->move_window(windows->get_base_window(), pos_x, pos_y);
126 sclwindow window = windows->get_base_window();
127 controller->handle_engine_signal(SCL_SIG_SHOW);
128 windows->show_window(window);
134 * Hides the SCL main window
135 * The real hide action does not work about base window because that is child of the active window
142 sclboolean ret = FALSE;
145 CSCLController *controller = CSCLController::get_instance();
146 CSCLWindows *windows = CSCLWindows::get_instance();
147 if (controller && windows) {
148 controller->handle_engine_signal(SCL_SIG_HIDE);
149 windows->hide_window(windows->get_base_window());
156 * Regists an event callback function
157 * so that the user which uses SCL can recevies all events occuring in running
160 CSCLUIImpl::set_ui_event_callback(ISCLUIEventCallback *callback, const sclchar *input_mode)
164 sclboolean ret = FALSE;
167 CSCLEventHandler *handler = CSCLEventHandler::get_instance();
169 handler->set_event_callback(callback, input_mode);
175 * Sets the current input mode to the given mode
177 * gCore->set_input_mode("INPUT_MODE_SYMBOL");
180 CSCLUIImpl::set_input_mode(const sclchar *input_mode)
183 SCL_DEBUG_ELAPASED_TIME_START();
185 sclboolean ret = FALSE;
188 CSCLController *controller = CSCLController::get_instance();
189 CSCLWindows *windows = CSCLWindows::get_instance();
190 CSCLEventHandler *handler = CSCLEventHandler::get_instance();
192 scl8 mode = NOT_USED;
194 SclResParserManager *sclres_manager = SclResParserManager::get_instance();
195 if (sclres_manager) {
196 mode = sclres_manager->get_inputmode_id(input_mode);
199 if (controller && windows && handler && mode != NOT_USED) {
200 handler->set_input_mode(input_mode);
201 ret = controller->process_input_mode_change(mode);
202 windows->update_window(windows->get_base_window());
206 SCL_DEBUG_ELAPASED_TIME_END();
211 * Sets the current rotation
214 CSCLUIImpl::set_rotation(SCLRotation rotation)
218 sclboolean ret = FALSE;
221 CSCLUtils *utils = CSCLUtils::get_instance();
222 CSCLWindows *windows = CSCLWindows::get_instance();
223 CSCLController *controller = CSCLController::get_instance();
225 if (utils && windows && controller) {
226 ret = controller->process_rotation_change(rotation);
228 //if (auto_relocate) {
230 /* Let's relocate our base window - bottomed center aligned */
231 sclint width, height;
232 //get_layout_size(&width, &height);
233 SclRectangle rect = get_main_window_rect();
236 utils->get_screen_resolution(&scrx, &scry);
238 sclint pos_x = (scrx - rect.width) / 2;
239 sclint pos_y = (scry - rect.height);
241 windows->move_window(windows->get_base_window(), pos_x, pos_y);
250 * Returns the current rotation
253 CSCLUIImpl::get_rotation()
257 SCLRotation ret = ROTATION_0;
259 CSCLContext *context = CSCLContext::get_instance();
261 ret = context->get_rotation();
268 * Returns the current display mode
271 CSCLUIImpl::get_display_mode()
275 SCLDisplayMode ret = DISPLAYMODE_MAX;
277 CSCLContext *context = CSCLContext::get_instance();
279 ret = context->get_display_mode();
286 * Returns the current input mode
289 CSCLUIImpl::get_input_mode()
293 const sclchar *ret = NULL;
295 CSCLContext *context = CSCLContext::get_instance();
296 SclResParserManager *sclres_manager = SclResParserManager::get_instance();
297 if (context && sclres_manager) {
298 scl8 inputmode_id = context->get_input_mode();
299 ret = sclres_manager->get_inputmode_name(inputmode_id);
308 * Sets a private key to the current context
309 * The other properties except given parameters will keep to the orginal value.
311 * gCore->set_private_key(INPUT_MODE_NUMBER, LYT_PORTRAIT_NOW_3x4, 0, "private", 999, TRUE);
313 * @param fRedraw If true, it will redraw the current key
316 CSCLUIImpl::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 fRedraw)
319 sclint ret = NOT_USED;
321 CSCLWindows *windows = CSCLWindows::get_instance();
322 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
323 if (windows && cache) {
324 ret = cache->set_private_key((sclchar*)custom_id, label, imagelabel, imagebg,
325 key_event, key_value, fRedraw, windows->get_update_pending());
333 * Unsets a private key to the current context
336 CSCLUIImpl::unset_private_key(const sclchar* custom_id)
339 sclboolean ret = FALSE;
342 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
344 cache->unset_private_key(custom_id);
350 * Sets the current theme
352 /* FIXME : If setting themename is not allowed before initializing,
353 the default theme has to be loaded regardless of current theme name
354 and the appropriate current theme has to be loaded afterwards, which is very inefficient */
356 CSCLUIImpl::set_cur_themename(const sclchar *themename)
358 sclboolean ret = FALSE;
361 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
362 CSCLWindows *windows = CSCLWindows::get_instance();
363 if (cache && windows) {
364 cache->set_cur_themename(themename);
365 windows->update_window(windows->get_base_window());
369 window = windows->get_nth_popup_window(loop);
371 windows->update_window(window);
383 CSCLUIImpl::get_shift_state()
385 SCLShiftState ret = SCL_SHIFT_STATE_OFF;
387 CSCLContext *context = CSCLContext::get_instance();
389 ret = context->get_shift_state();
396 CSCLUIImpl::set_shift_state(SCLShiftState state)
399 CSCLUtils *utils = CSCLUtils::get_instance();
400 CSCLContext *context = CSCLContext::get_instance();
401 CSCLWindows *windows = CSCLWindows::get_instance();
402 if (context && windows && utils) {
403 SCLShiftState current_state = context->get_shift_state();
404 context->set_shift_state(state);
405 if (state != current_state) {
406 windows->update_window(windows->get_base_window());
408 if (context->get_tts_enabled()) {
409 if (state == SCL_SHIFT_STATE_ON) {
410 utils->play_tts(SCL_SHIFT_STATE_ON_HINT_STRING);
411 } else if (state == SCL_SHIFT_STATE_LOCK) {
412 utils->play_tts(SCL_SHIFT_STATE_LOCK_HINT_STRING);
414 utils->play_tts(SCL_SHIFT_STATE_OFF_HINT_STRING);
422 * This function will be called by the user which uses SCL when the context of the focus application is changed
423 * ISE user should explicitly call this function when the context of application is changed.
424 * For instance, focus-changed, application-changed,, and so on.
425 * This function will call CSCLController to init the related variables.
428 CSCLUIImpl::notify_app_focus_changed()
431 sclboolean ret = FALSE;
434 CSCLController *controller = CSCLController::get_instance();
436 controller->handle_engine_signal(SCL_SIG_FOCUS_CHANGE);
442 CSCLUIImpl::reset_popup_timeout()
445 sclboolean ret = FALSE;
448 CSCLEvents *events = CSCLEvents::get_instance();
449 CSCLWindows *windows = CSCLWindows::get_instance();
451 if (events && windows) {
452 events->destroy_timer(SCL_TIMER_POPUP_TIMEOUT);
455 sclboolean timerset = FALSE;
456 sclwindow window = SCLWINDOW_INVALID;
457 SclWindowContext *winctx = NULL;
459 window = windows->get_nth_window_in_Z_order_list(index);
460 //winctx = windows->get_window_context(window, FALSE);
461 winctx = windows->get_window_context(window);
463 if (winctx->timeout != 0) {
464 events->create_timer(SCL_TIMER_POPUP_TIMEOUT, winctx->timeout, 0, TRUE);
469 } while (index < MAX_ZORDER_NUM && window != SCLWINDOW_INVALID && !timerset);
475 CSCLUIImpl::close_all_popups()
478 sclboolean ret = FALSE;
481 CSCLWindows *windows = CSCLWindows::get_instance();
483 windows->close_all_popups();
489 * Returns a scale rate (see default screen resolution in sclconfig.h file)
492 CSCLUIImpl::get_scale_rate()
496 CSCLUtils *utils = CSCLUtils::get_instance();
498 ret = utils->get_smallest_scale_rate();
505 * Returns a calculated x value according to the current screen resolution
508 CSCLUIImpl::get_scale_x(scl16 x)
512 CSCLUtils *utils = CSCLUtils::get_instance();
514 ret = utils->get_scale_x(x);
521 * Returns a calculated y value according to the current screen resolution
524 CSCLUIImpl::get_scale_y(scl16 y)
528 CSCLUtils *utils = CSCLUtils::get_instance();
530 ret = utils->get_scale_y(y);
537 * Returns the scl base window size
540 CSCLUIImpl::get_main_window_rect()
542 SclRectangle ret = {0};
545 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
546 CSCLWindows *windows = CSCLWindows::get_instance();
547 if (cache && windows) {
548 //const SclLayout *layout = cache->get_cur_layout(windows->get_base_window());
549 SclWindowContext *winctx = windows->get_window_context(windows->get_base_window());
551 ret.x = winctx->geometry.x;
552 ret.y = winctx->geometry.y;
553 ret.width = winctx->geometry.width;
554 ret.height = winctx->geometry.height;
563 * Returns the scl base window size
566 CSCLUIImpl::get_input_mode_size(const sclchar *input_mode, SCLDisplayMode display_mode)
571 CSCLUtils *utils = CSCLUtils::get_instance();
572 SclResParserManager *sclres_manager = SclResParserManager::get_instance();
573 if (utils && sclres_manager) {
574 const PSclInputModeConfigure sclres_input_mode_configure = sclres_manager->get_input_mode_configure_table();
575 const PSclLayout sclres_layout = sclres_manager->get_layout_table();
576 sclint inputmode = sclres_manager->get_inputmode_id(input_mode);
577 sclint layout = sclres_manager->get_layout_id(
578 sclres_input_mode_configure[inputmode].layouts[display_mode]);
580 ret.width = sclres_layout[layout].width;
581 ret.height = sclres_layout[layout].height;
589 * Returns the screen resolution
592 CSCLUIImpl::get_screen_resolution(sclint *width, sclint *height)
594 sclboolean ret = FALSE;
597 CSCLUtils *utils = CSCLUtils::get_instance();
598 if (utils && width && height) {
599 utils->get_screen_resolution(width, height);
607 CSCLUIImpl::set_debug_mode(SCLDebugMode mode)
609 sclboolean ret = FALSE;
612 CSCLController *controller = CSCLController::get_instance();
614 controller->set_debug_mode(mode);
620 CSCLUIImpl::get_debug_mode()
622 SCLDebugMode ret = DEBUGMODE_DISABLED;
624 CSCLController *controller = CSCLController::get_instance();
626 ret = controller->get_debug_mode();
633 CSCLUIImpl::set_update_pending(sclboolean pend)
635 sclboolean ret = FALSE;
638 CSCLWindows *windows = CSCLWindows::get_instance();
640 windows->set_update_pending(pend);
646 CSCLUIImpl::enable_button(const sclchar* custom_id, sclboolean enabled)
648 sclboolean ret = FALSE;
651 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
653 cache->enable_button(custom_id, enabled);
659 CSCLUIImpl::get_multi_touch_context_num()
664 CSCLContext *context = CSCLContext::get_instance();
666 ret = context->get_multi_touch_context_num();
673 CSCLUIImpl::get_multi_touch_event(sclint seqorder, SclUIEventDesc *desc)
675 sclboolean ret = FALSE;
678 CSCLContext *context = CSCLContext::get_instance();
680 ret = context->get_multi_touch_event(seqorder, desc);
687 CSCLUIImpl::set_longkey_duration(scllong msc)
689 sclboolean ret = FALSE;
692 CSCLController *controller = CSCLController::get_instance();
694 ret = controller->set_longkey_duration(msc);
701 CSCLUIImpl::set_longkey_cancel_dist(sclshort dist)
703 sclboolean ret = FALSE;
706 CSCLController *controller = CSCLController::get_instance();
708 ret = controller->set_longkey_cancel_dist(dist);
715 CSCLUIImpl::set_repeatkey_duration(scllong msc)
717 sclboolean ret = FALSE;
720 CSCLController *controller = CSCLController::get_instance();
722 ret = controller->set_repeatkey_duration(msc);
729 CSCLUIImpl::set_autopoup_key_duration(scllong msc)
731 sclboolean ret = FALSE;
734 CSCLController *controller = CSCLController::get_instance();
736 ret = controller->set_autopopup_key_duration(msc);
743 CSCLUIImpl::set_button_delay_duration(scllong msc)
745 sclboolean ret = FALSE;
748 CSCLController *controller = CSCLController::get_instance();
750 ret = controller->set_button_delay_duration(msc);
757 CSCLUIImpl::enable_magnifier(sclboolean enabled)
759 sclboolean ret = FALSE;
762 CSCLContext *context = CSCLContext::get_instance();
764 context->set_magnifier_enabled(enabled);
770 CSCLUIImpl::enable_sound(sclboolean enabled)
772 sclboolean ret = FALSE;
775 CSCLContext *context = CSCLContext::get_instance();
777 context->set_sound_enabled(enabled);
783 CSCLUIImpl::enable_vibration(sclboolean enabled)
785 sclboolean ret = FALSE;
788 CSCLContext *context = CSCLContext::get_instance();
790 context->set_vibration_enabled(enabled);
796 CSCLUIImpl::enable_tts(sclboolean enabled)
798 sclboolean ret = FALSE;
801 CSCLContext *context = CSCLContext::get_instance();
803 context->set_tts_enabled(enabled);
809 CSCLUIImpl::enable_shift_multi_touch(sclboolean enabled)
811 sclboolean ret = FALSE;
814 CSCLContext *context = CSCLContext::get_instance();
816 context->set_shift_multi_touch_enabled(enabled);
822 CSCLUIImpl::enable_touch_offset(sclboolean enabled)
824 CSCLErrorAdjustment *adjustment = CSCLErrorAdjustment::get_instance();
826 adjustment->enable_touch_offset(enabled);
831 CSCLUIImpl::disable_input_events(sclboolean disabled)
833 sclboolean ret = FALSE;
836 CSCLController *controller = CSCLController::get_instance();
838 controller->disable_input_events(disabled);
844 CSCLUIImpl::set_cur_sublayout(const sclchar *sub_layout_name)
846 sclboolean ret = FALSE;
849 CSCLContext *context = CSCLContext::get_instance();
850 CSCLWindows *windows = CSCLWindows::get_instance();
851 if (context && windows) {
852 ret = context->set_cur_sublayout(sub_layout_name);
853 windows->update_window(windows->get_base_window());
860 CSCLUIImpl::get_cur_sublayout()
864 CSCLContext *context = CSCLContext::get_instance();
866 ret = context->get_cur_sublayout();
873 CSCLUIImpl::set_custom_magnifier_label(scltouchdevice touch_id, sclint index, const sclchar* label)
876 CSCLContext *context = CSCLContext::get_instance();
878 context->set_custom_magnifier_label(touch_id, index, label);
884 CSCLUIImpl::set_string_substitution(const sclchar *original, const sclchar *substitute)
887 CSCLWindows *windows = CSCLWindows::get_instance();
888 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
889 if (cache && windows) {
890 cache->set_string_substitution(original, substitute);
891 windows->update_window(windows->get_base_window());
897 CSCLUIImpl::unset_string_substitution(const sclchar *original)
900 CSCLWindows *windows = CSCLWindows::get_instance();
901 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
902 if (cache && windows) {
903 cache->unset_string_substitution(original);
904 windows->update_window(windows->get_base_window());
910 CSCLUIImpl::set_caps_mode(sclint mode) {
912 if (get_shift_state() != SCL_SHIFT_STATE_LOCK) {
913 set_shift_state(mode ? SCL_SHIFT_STATE_ON : SCL_SHIFT_STATE_OFF);
918 CSCLUIImpl::get_caps_mode() {