Add update_preedit_caret() API
[platform/core/uifw/libscl-core.git] / src / sclcoreimpl.cpp
1 /*
2  * Copyright (c) 2014 - 2015 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 "sclcoreimpl.h"
19 #include <app_common.h>
20 #include <dlog.h>
21
22 using namespace scl;
23
24 CSCLCoreImpl::CSCLCoreImpl()
25 {
26     m_event_callback = NULL;
27     m_display = NULL;
28     m_uuid = NULL;
29
30     m_window_created = FALSE;
31     m_window_creation_defer_flag = FALSE;
32 }
33
34 CSCLCoreImpl::~CSCLCoreImpl()
35 {
36     if (m_display) {
37         free(m_display);
38         m_display = NULL;
39     }
40     if (m_uuid) {
41         free(m_uuid);
42         m_uuid = NULL;
43     }
44 }
45
46 CSCLCoreImpl*
47 CSCLCoreImpl::get_instance()
48 {
49     static CSCLCoreImpl instance;
50     return &instance;
51 }
52
53 void CSCLCoreImpl::init()
54 {
55     LOGD("");
56     m_core_ui.init();
57     m_connection.init();
58 }
59
60 sclboolean CSCLCoreImpl::prepare()
61 {
62     sclboolean ret = TRUE;
63
64     if (!m_display) {
65         const char *display = getenv("DISPLAY");
66         LOGD("display env : '%s'\n", display);
67         m_display = display ? strdup(display) : strdup(":0");
68     }
69
70     if (!m_uuid) {
71         char *appid = NULL;
72         app_get_id(&appid);
73
74         LOGD("appid : '%s'\n", appid);
75
76         if (appid) {
77             m_uuid = strdup(appid);
78             free(appid);
79         }
80     }
81
82     if (!m_window_creation_defer_flag) {
83         LOGD("defer_flag FALSE, creating main window");
84         m_window_created = m_core_ui.create_main_window();
85         ret = m_window_created;
86     }
87     if (ret) {
88         m_connection.open_connection(m_display);
89     }
90
91     if (m_event_callback) {
92         m_event_callback->on_init();
93     }
94
95     return ret;
96 }
97
98 void CSCLCoreImpl::fini()
99 {
100     LOGD("");
101     if (m_event_callback) {
102         m_event_callback->on_exit();
103     }
104
105     m_connection.close_connection();
106
107     m_core_ui.fini();
108     m_connection.fini();
109 }
110
111 void CSCLCoreImpl::set_core_event_callback(ISCLCoreEventCallback *callback)
112 {
113     m_event_callback = callback;
114 }
115
116 ISCLCoreEventCallback* CSCLCoreImpl::get_core_event_callback()
117 {
118     ISCLCoreEventCallback* ret = m_event_callback;
119     return ret;
120 }
121
122 CSCLCoreUI* CSCLCoreImpl::get_core_ui()
123 {
124     return &m_core_ui;
125 }
126
127 CSCLConnection* CSCLCoreImpl::get_connection()
128 {
129     return &m_connection;
130 }
131
132 sclchar* CSCLCoreImpl::get_uuid()
133 {
134     return m_uuid;
135 }
136
137 void CSCLCoreImpl::config_reload()
138 {
139     m_connection.config_reload();
140 }
141
142 sclboolean CSCLCoreImpl::config_read_int(const sclchar *name, sclint &value)
143 {
144     return m_connection.config_read_int(name, value);
145 }
146
147 sclboolean CSCLCoreImpl::config_read_string(const sclchar *name, std::string &value)
148 {
149     return m_connection.config_read_string(name, value);
150 }
151
152 sclboolean CSCLCoreImpl::config_write_int(const sclchar *name, sclint value)
153 {
154     return m_connection.config_write_int(name, value);
155 }
156
157 sclboolean CSCLCoreImpl::config_write_string(const sclchar *name, const std::string value)
158 {
159     return m_connection.config_write_string(name, value);
160 }
161
162 sclboolean CSCLCoreImpl::config_erase(const sclchar *name)
163 {
164     return m_connection.config_erase(name);
165 }
166
167 sclboolean CSCLCoreImpl::config_flush(void)
168 {
169     return m_connection.config_flush();
170 }
171
172 void CSCLCoreImpl::send_imengine_event(sclint ic, const sclchar *ic_uuid, const sclint command, const sclu32 value)
173 {
174     m_connection.send_imengine_event(ic, ic_uuid, command, value);
175 }
176
177 void CSCLCoreImpl::reset_keyboard_ise()
178 {
179     m_connection.reset_keyboard_ise();
180 }
181
182 void CSCLCoreImpl::flush_keyboard_ise()
183 {
184     m_connection.flush_keyboard_ise();
185 }
186
187 void CSCLCoreImpl::send_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
188 {
189     m_connection.send_key_event(ic, ic_uuid, keycode, keymask);
190 }
191
192 void CSCLCoreImpl::forward_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
193 {
194     m_connection.forward_key_event(ic, ic_uuid, keycode, keymask);
195 }
196
197 void CSCLCoreImpl::commit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
198 {
199     m_connection.commit_string(ic, ic_uuid, str);
200 }
201
202 void CSCLCoreImpl::select_candidate(int index)
203 {
204     m_connection.select_candidate(index);
205 }
206
207 void CSCLCoreImpl::show_preedit_string(sclint ic, const sclchar *ic_uuid)
208 {
209     m_connection.show_preedit_string(ic, ic_uuid);
210 }
211
212 void CSCLCoreImpl::show_aux_string(void)
213 {
214     m_connection.show_aux_string();
215 }
216
217 void CSCLCoreImpl::show_candidate_string(void)
218 {
219     m_connection.show_candidate_string();
220 }
221
222 void CSCLCoreImpl::show_associate_string(void)
223 {
224     m_connection.show_associate_string();
225 }
226
227 void CSCLCoreImpl::hide_preedit_string(sclint ic, const sclchar *ic_uuid)
228 {
229     m_connection.hide_preedit_string(ic, ic_uuid);
230 }
231
232 void CSCLCoreImpl::hide_aux_string(void)
233 {
234     m_connection.hide_aux_string();
235 }
236
237 void CSCLCoreImpl::hide_candidate_string(void)
238 {
239     m_connection.hide_candidate_string();
240 }
241
242 void CSCLCoreImpl::hide_associate_string(void)
243 {
244     m_connection.hide_associate_string();
245 }
246
247 void CSCLCoreImpl::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
248 {
249     m_connection.update_preedit_string(ic, ic_uuid, str);
250 }
251
252 void CSCLCoreImpl::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str, const scim::AttributeList &attrs)
253 {
254     m_connection.update_preedit_string(ic, ic_uuid, str, attrs);
255 }
256
257 void CSCLCoreImpl::update_preedit_caret(sclint caret)
258 {
259     m_connection.update_preedit_caret(caret);
260 }
261
262 void CSCLCoreImpl::update_aux_string(const sclchar *str)
263 {
264     m_connection.update_aux_string(str);
265 }
266
267 void CSCLCoreImpl::update_input_context(sclu32 type, sclu32 value)
268 {
269     m_connection.update_input_context(type, value);
270 }
271
272 void CSCLCoreImpl::update_geometry(sclint x, sclint y, sclint width, sclint height)
273 {
274     m_connection.update_geometry(x, y, width, height);
275 }
276
277 void CSCLCoreImpl::get_surrounding_text(const sclchar* ic_uuid, sclint maxlen_before, sclint maxlen_after) const
278 {
279     m_connection.get_surrounding_text(ic_uuid, maxlen_before, maxlen_after);
280 }
281
282 sclint CSCLCoreImpl::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
283 {
284     return m_connection.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
285 }
286
287 void CSCLCoreImpl::delete_surrounding_text(sclint offset, sclint len) const
288 {
289     m_connection.delete_surrounding_text(offset, len);
290 }
291
292 void CSCLCoreImpl::set_candidate_position(sclint left, sclint top)
293 {
294     m_connection.set_candidate_position(left, top);
295 }
296
297 void CSCLCoreImpl::enable_soft_candidate(sclboolean enable)
298 {
299     m_connection.enable_soft_candidate(enable);
300 }
301
302 void CSCLCoreImpl::candidate_hide(void)
303 {
304     m_connection.candidate_hide();
305 }
306
307 void CSCLCoreImpl::set_keyboard_ise_by_uuid(const sclchar *uuid)
308 {
309     m_connection.set_keyboard_ise_by_uuid(uuid);
310 }
311
312 void CSCLCoreImpl::get_keyboard_ise(const sclchar *uuid)
313 {
314     m_connection.get_keyboard_ise(uuid);
315 }
316
317 void CSCLCoreImpl::on_run(const sclchar *uuid, const sclchar *display)
318 {
319     LOGD("uuid : '%s', display : '%s'\n", uuid, display);
320
321     if (uuid && strlen(uuid) > 0) {
322         if (m_uuid) {
323             free(m_uuid);
324         }
325
326         m_uuid = strdup(uuid);
327     }
328
329     if (display) {
330         if (m_display) {
331             free(m_display);
332         }
333
334         m_display = strdup(display);
335     }
336
337     if (m_event_callback) {
338         m_event_callback->on_run(0, NULL);
339     }
340 }
341
342 void CSCLCoreImpl::run()
343 {
344     init();
345
346     if (!m_display) {
347         const char *display = getenv("DISPLAY");
348         LOGD("display env : '%s'\n", display);
349         m_display = display ? strdup(display) : strdup(":0");
350     }
351
352     LOGD("");
353     m_core_ui.run(m_display);
354
355     fini();
356 }
357
358 sclwindow CSCLCoreImpl::get_main_window()
359 {
360     if (!m_window_created) {
361         LOGD("create main window\n");
362         m_window_created = m_core_ui.create_main_window();
363     }
364
365     return m_core_ui.get_main_window();
366 }
367
368 int CSCLCoreImpl::get_screen_rotation_degree()
369 {
370     return m_core_ui.get_screen_rotation_degree();
371 }
372
373 void CSCLCoreImpl::set_keyboard_size_hints(SclSize portrait, SclSize landscape)
374 {
375     m_core_ui.set_keyboard_size_hints(portrait, landscape);
376     m_core_ui.update_keyboard_geometry(portrait, landscape);
377 }
378
379 sclwindow CSCLCoreImpl::create_option_window()
380 {
381     return m_core_ui.create_option_window(OPTION_WINDOW_TYPE_NORMAL);
382 }
383
384 void CSCLCoreImpl::destroy_option_window(sclwindow window)
385 {
386     m_core_ui.destroy_option_window(window);
387 }
388
389 void CSCLCoreImpl::set_selection(sclint start, sclint end)
390 {
391     m_connection.set_selection(start, end);
392 }
393
394 void CSCLCoreImpl::send_private_command(const sclchar *command)
395 {
396     m_connection.send_private_command(command);
397 }
398
399 void CSCLCoreImpl::get_selection_text(sclchar **text)
400 {
401     m_connection.get_selection_text(text);
402 }
403
404 void CSCLCoreImpl::request_ise_hide()
405 {
406     m_connection.request_ise_hide();
407 }
408
409 void CSCLCoreImpl::commit_content(const sclchar *content, const sclchar *description, const sclchar *mime_types)
410 {
411     m_connection.commit_content(content, description, mime_types);
412 }
413
414 void CSCLCoreImpl::set_floating_mode(sclboolean floating_mode)
415 {
416     m_core_ui.set_floating_mode(floating_mode);
417 }
418
419 void CSCLCoreImpl::set_floating_drag_enabled(sclboolean enabled)
420 {
421     m_core_ui.set_floating_drag_enabled(enabled);
422 }
423
424 void CSCLCoreImpl::set_window_creation_defer_flag(sclboolean flag)
425 {
426     LOGD("defer_flag %d", flag);
427     m_window_creation_defer_flag = flag;
428 }