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();
403 /*inform the client that the shift state changed */
404 CSCLEventHandler *handler = CSCLEventHandler::get_instance();
406 SCLEventReturnType ret = handler->on_event_notification(SCL_UINOTITYPE_SHIFT_STATE_CHANGE, state);
407 if (ret == SCL_EVENT_DONE) {
412 if (context && windows && utils) {
413 SCLShiftState current_state = context->get_shift_state();
414 context->set_shift_state(state);
415 if (state != current_state) {
416 windows->update_window(windows->get_base_window());
418 if (context->get_tts_enabled()) {
419 if (state == SCL_SHIFT_STATE_ON) {
420 utils->play_tts(SCL_SHIFT_STATE_ON_HINT_STRING);
421 } else if (state == SCL_SHIFT_STATE_LOCK) {
422 utils->play_tts(SCL_SHIFT_STATE_LOCK_HINT_STRING);
424 utils->play_tts(SCL_SHIFT_STATE_OFF_HINT_STRING);
432 * This function will be called by the user which uses SCL when the context of the focus application is changed
433 * ISE user should explicitly call this function when the context of application is changed.
434 * For instance, focus-changed, application-changed,, and so on.
435 * This function will call CSCLController to init the related variables.
438 CSCLUIImpl::notify_app_focus_changed()
441 sclboolean ret = FALSE;
444 CSCLController *controller = CSCLController::get_instance();
446 controller->handle_engine_signal(SCL_SIG_FOCUS_CHANGE);
452 CSCLUIImpl::reset_popup_timeout()
455 sclboolean ret = FALSE;
458 CSCLEvents *events = CSCLEvents::get_instance();
459 CSCLWindows *windows = CSCLWindows::get_instance();
461 if (events && windows) {
462 events->destroy_timer(SCL_TIMER_POPUP_TIMEOUT);
465 sclboolean timerset = FALSE;
466 sclwindow window = SCLWINDOW_INVALID;
467 SclWindowContext *winctx = NULL;
469 window = windows->get_nth_window_in_Z_order_list(index);
470 //winctx = windows->get_window_context(window, FALSE);
471 winctx = windows->get_window_context(window);
473 if (winctx->timeout != 0) {
474 events->create_timer(SCL_TIMER_POPUP_TIMEOUT, winctx->timeout, 0, TRUE);
479 } while (index < MAX_ZORDER_NUM && window != SCLWINDOW_INVALID && !timerset);
485 CSCLUIImpl::close_all_popups()
488 sclboolean ret = FALSE;
491 CSCLWindows *windows = CSCLWindows::get_instance();
493 windows->close_all_popups();
499 * Returns a scale rate (see default screen resolution in sclconfig.h file)
502 CSCLUIImpl::get_scale_rate()
506 CSCLUtils *utils = CSCLUtils::get_instance();
508 ret = utils->get_smallest_scale_rate();
515 * Returns a calculated x value according to the current screen resolution
518 CSCLUIImpl::get_scale_x(scl16 x)
522 CSCLUtils *utils = CSCLUtils::get_instance();
524 ret = utils->get_scale_x(x);
531 * Returns a calculated y value according to the current screen resolution
534 CSCLUIImpl::get_scale_y(scl16 y)
538 CSCLUtils *utils = CSCLUtils::get_instance();
540 ret = utils->get_scale_y(y);
547 * Returns the scl base window size
550 CSCLUIImpl::get_main_window_rect()
552 SclRectangle ret = {0};
555 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
556 CSCLWindows *windows = CSCLWindows::get_instance();
557 if (cache && windows) {
558 //const SclLayout *layout = cache->get_cur_layout(windows->get_base_window());
559 SclWindowContext *winctx = windows->get_window_context(windows->get_base_window());
561 ret.x = winctx->geometry.x;
562 ret.y = winctx->geometry.y;
563 ret.width = winctx->geometry.width;
564 ret.height = winctx->geometry.height;
573 * Returns the scl base window size
576 CSCLUIImpl::get_input_mode_size(const sclchar *input_mode, SCLDisplayMode display_mode)
581 CSCLUtils *utils = CSCLUtils::get_instance();
582 SclResParserManager *sclres_manager = SclResParserManager::get_instance();
583 if (utils && sclres_manager) {
584 const PSclInputModeConfigure sclres_input_mode_configure = sclres_manager->get_input_mode_configure_table();
585 const PSclLayout sclres_layout = sclres_manager->get_layout_table();
586 sclint inputmode = sclres_manager->get_inputmode_id(input_mode);
587 if (sclres_input_mode_configure && sclres_layout) {
588 sclint layout = sclres_manager->get_layout_id(
589 sclres_input_mode_configure[inputmode].layouts[display_mode]);
591 ret.width = sclres_layout[layout].width;
592 ret.height = sclres_layout[layout].height;
601 * Returns the screen resolution
604 CSCLUIImpl::get_screen_resolution(sclint *width, sclint *height)
606 sclboolean ret = FALSE;
609 CSCLUtils *utils = CSCLUtils::get_instance();
610 if (utils && width && height) {
611 utils->get_screen_resolution(width, height);
619 CSCLUIImpl::set_debug_mode(SCLDebugMode mode)
621 sclboolean ret = FALSE;
624 CSCLController *controller = CSCLController::get_instance();
626 controller->set_debug_mode(mode);
632 CSCLUIImpl::get_debug_mode()
634 SCLDebugMode ret = DEBUGMODE_DISABLED;
636 CSCLController *controller = CSCLController::get_instance();
638 ret = controller->get_debug_mode();
645 CSCLUIImpl::set_update_pending(sclboolean pend)
647 sclboolean ret = FALSE;
650 CSCLWindows *windows = CSCLWindows::get_instance();
652 windows->set_update_pending(pend);
658 CSCLUIImpl::enable_button(const sclchar* custom_id, sclboolean enabled)
660 sclboolean ret = FALSE;
663 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
665 cache->enable_button(custom_id, enabled);
671 CSCLUIImpl::get_multi_touch_context_num()
676 CSCLContext *context = CSCLContext::get_instance();
678 ret = context->get_multi_touch_context_num();
685 CSCLUIImpl::get_multi_touch_event(sclint seqorder, SclUIEventDesc *desc)
687 sclboolean ret = FALSE;
690 CSCLContext *context = CSCLContext::get_instance();
692 ret = context->get_multi_touch_event(seqorder, desc);
699 CSCLUIImpl::set_longkey_duration(scllong msc)
701 sclboolean ret = FALSE;
704 CSCLController *controller = CSCLController::get_instance();
706 ret = controller->set_longkey_duration(msc);
713 CSCLUIImpl::set_longkey_cancel_dist(sclshort dist)
715 sclboolean ret = FALSE;
718 CSCLController *controller = CSCLController::get_instance();
720 ret = controller->set_longkey_cancel_dist(dist);
727 CSCLUIImpl::set_repeatkey_duration(scllong msc)
729 sclboolean ret = FALSE;
732 CSCLController *controller = CSCLController::get_instance();
734 ret = controller->set_repeatkey_duration(msc);
741 CSCLUIImpl::set_autopoup_key_duration(scllong msc)
743 sclboolean ret = FALSE;
746 CSCLController *controller = CSCLController::get_instance();
748 ret = controller->set_autopopup_key_duration(msc);
755 CSCLUIImpl::set_button_delay_duration(scllong msc)
757 sclboolean ret = FALSE;
760 CSCLController *controller = CSCLController::get_instance();
762 ret = controller->set_button_delay_duration(msc);
769 CSCLUIImpl::enable_magnifier(sclboolean enabled)
771 sclboolean ret = FALSE;
774 CSCLContext *context = CSCLContext::get_instance();
776 context->set_magnifier_enabled(enabled);
782 CSCLUIImpl::enable_sound(sclboolean enabled)
784 sclboolean ret = FALSE;
787 CSCLContext *context = CSCLContext::get_instance();
789 context->set_sound_enabled(enabled);
795 CSCLUIImpl::enable_vibration(sclboolean enabled)
797 sclboolean ret = FALSE;
800 CSCLContext *context = CSCLContext::get_instance();
802 context->set_vibration_enabled(enabled);
808 CSCLUIImpl::enable_tts(sclboolean enabled)
810 sclboolean ret = FALSE;
813 CSCLContext *context = CSCLContext::get_instance();
815 context->set_tts_enabled(enabled);
821 CSCLUIImpl::enable_shift_multi_touch(sclboolean enabled)
823 sclboolean ret = FALSE;
826 CSCLContext *context = CSCLContext::get_instance();
828 context->set_shift_multi_touch_enabled(enabled);
834 CSCLUIImpl::enable_touch_offset(sclboolean enabled)
836 CSCLErrorAdjustment *adjustment = CSCLErrorAdjustment::get_instance();
838 adjustment->enable_touch_offset(enabled);
843 CSCLUIImpl::disable_input_events(sclboolean disabled)
845 sclboolean ret = FALSE;
848 CSCLController *controller = CSCLController::get_instance();
850 controller->disable_input_events(disabled);
856 CSCLUIImpl::set_cur_sublayout(const sclchar *sub_layout_name)
858 sclboolean ret = FALSE;
861 CSCLContext *context = CSCLContext::get_instance();
862 CSCLWindows *windows = CSCLWindows::get_instance();
863 if (context && windows) {
864 ret = context->set_cur_sublayout(sub_layout_name);
865 windows->update_window(windows->get_base_window());
872 CSCLUIImpl::get_cur_sublayout()
876 CSCLContext *context = CSCLContext::get_instance();
878 ret = context->get_cur_sublayout();
885 CSCLUIImpl::set_custom_magnifier_label(scltouchdevice touch_id, sclint index, const sclchar* label)
888 CSCLContext *context = CSCLContext::get_instance();
890 context->set_custom_magnifier_label(touch_id, index, label);
896 CSCLUIImpl::set_string_substitution(const sclchar *original, const sclchar *substitute)
899 CSCLWindows *windows = CSCLWindows::get_instance();
900 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
901 if (cache && windows) {
902 cache->set_string_substitution(original, substitute);
903 windows->update_window(windows->get_base_window());
909 CSCLUIImpl::unset_string_substitution(const sclchar *original)
912 CSCLWindows *windows = CSCLWindows::get_instance();
913 CSCLResourceCache *cache = CSCLResourceCache::get_instance();
914 if (cache && windows) {
915 cache->unset_string_substitution(original);
916 windows->update_window(windows->get_base_window());
922 CSCLUIImpl::set_caps_mode(sclint mode) {
924 if (get_shift_state() != SCL_SHIFT_STATE_LOCK) {
925 set_shift_state(mode ? SCL_SHIFT_STATE_ON : SCL_SHIFT_STATE_OFF);
930 CSCLUIImpl::get_caps_mode() {