summaryrefslogtreecommitdiff
path: root/src/examples/ecore
diff options
context:
space:
mode:
authorJihoon Kim <imfine98@gmail.com>2013-01-26 02:58:50 +0000
committerJihoon Kim <imfine98@gmail.com>2013-01-26 02:58:50 +0000
commit0753ec709deca039ba8c07d891050a9972d795f3 (patch)
treecce9bbbbda33db3de8495f088afa5e4e738a42ba /src/examples/ecore
parent81370c8926cef9e88825bf79cab7c5d38bcc5c87 (diff)
ecore_imf_example: fix comment style
SVN revision: 83339
Diffstat (limited to 'src/examples/ecore')
-rw-r--r--src/examples/ecore/ecore_imf_example.c77
1 files changed, 44 insertions, 33 deletions
diff --git a/src/examples/ecore/ecore_imf_example.c b/src/examples/ecore/ecore_imf_example.c
index e9f91c121e..aaa364116d 100644
--- a/src/examples/ecore/ecore_imf_example.c
+++ b/src/examples/ecore/ecore_imf_example.c
@@ -73,6 +73,7 @@ _entry_focus_out_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
73 73
74 if (en->imf_context) 74 if (en->imf_context)
75 { 75 {
76 // ecore_imf_context_reset should be called for flushing the preedit string in focus-out event handler
76 ecore_imf_context_reset(en->imf_context); 77 ecore_imf_context_reset(en->imf_context);
77 ecore_imf_context_focus_out(en->imf_context); 78 ecore_imf_context_focus_out(en->imf_context);
78 } 79 }
@@ -129,7 +130,7 @@ _preedit_del(Entry *en)
129 if (!en->preedit_start || !en->preedit_end) return; 130 if (!en->preedit_start || !en->preedit_end) return;
130 if (!evas_textblock_cursor_compare(en->preedit_start, en->preedit_end)) return; 131 if (!evas_textblock_cursor_compare(en->preedit_start, en->preedit_end)) return;
131 132
132 /* delete the preedit characters */ 133 // delete the preedit characters
133 evas_textblock_cursor_range_delete(en->preedit_start, en->preedit_end); 134 evas_textblock_cursor_range_delete(en->preedit_start, en->preedit_end);
134} 135}
135 136
@@ -154,7 +155,7 @@ _preedit_clear(Entry *en)
154static Eina_Bool 155static Eina_Bool
155_ecore_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos) 156_ecore_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos)
156{ 157{
157 /* This callback will be called when the Input Method Context module requests the surrounding context. */ 158 // This callback will be called when the Input Method Context module requests the surrounding context.
158 Entry *en = data; 159 Entry *en = data;
159 const char *str; 160 const char *str;
160 161
@@ -165,7 +166,7 @@ _ecore_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx, char **te
165 if (text) 166 if (text)
166 *text = str ? strdup(str) : strdup(""); 167 *text = str ? strdup(str) : strdup("");
167 168
168 /* get the current position of cursor */ 169 // get the current position of cursor
169 if (cursor_pos) 170 if (cursor_pos)
170 *cursor_pos = evas_textblock_cursor_pos_get(en->cursor); 171 *cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
171 172
@@ -175,7 +176,7 @@ _ecore_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx, char **te
175static void 176static void
176_ecore_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx, void *event_info) 177_ecore_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx, void *event_info)
177{ 178{
178 /* called when the input method needs to delete all or part of the context surrounding the cursor */ 179 // called when the input method needs to delete all or part of the context surrounding the cursor
179 Entry *en = data; 180 Entry *en = data;
180 Ecore_IMF_Event_Delete_Surrounding *ev = event_info; 181 Ecore_IMF_Event_Delete_Surrounding *ev = event_info;
181 Evas_Textblock_Cursor *del_start, *del_end; 182 Evas_Textblock_Cursor *del_start, *del_end;
@@ -183,15 +184,18 @@ _ecore_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx, void
183 184
184 if (!en) return; 185 if (!en) return;
185 186
187 // get the current cursor position
186 cursor_pos = evas_textblock_cursor_pos_get(en->cursor); 188 cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
187 189
190 // start cursor position to be deleted
188 del_start = evas_object_textblock_cursor_new(en->txt_obj); 191 del_start = evas_object_textblock_cursor_new(en->txt_obj);
189 evas_textblock_cursor_pos_set(del_start, cursor_pos + ev->offset); 192 evas_textblock_cursor_pos_set(del_start, cursor_pos + ev->offset);
190 193
194 // end cursor position to be deleted
191 del_end = evas_object_textblock_cursor_new(en->txt_obj); 195 del_end = evas_object_textblock_cursor_new(en->txt_obj);
192 evas_textblock_cursor_pos_set(del_end, cursor_pos + ev->offset + ev->n_chars); 196 evas_textblock_cursor_pos_set(del_end, cursor_pos + ev->offset + ev->n_chars);
193 197
194 /* implement function to delete character(s) from 'cursor_pos+ev->offset' cursor position to 'cursor_pos + ev->offset + ev->n_chars' */ 198 // implement function to delete character(s) from 'cursor_pos+ev->offset' cursor position to 'cursor_pos + ev->offset + ev->n_chars'
195 evas_textblock_cursor_range_delete(del_start, del_end); 199 evas_textblock_cursor_range_delete(del_start, del_end);
196 200
197 evas_textblock_cursor_free(del_start); 201 evas_textblock_cursor_free(del_start);
@@ -205,15 +209,16 @@ _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx, void *event_info)
205 char *commit_str = (char *)event_info; 209 char *commit_str = (char *)event_info;
206 if (!en) return; 210 if (!en) return;
207 211
208 /* delete preedit string */ 212 // delete preedit string
209 _preedit_del(en); 213 _preedit_del(en);
210 _preedit_clear(en); 214 _preedit_clear(en);
211 215
212 printf("commit string : %s\n", commit_str); 216 printf("commit string : %s\n", commit_str);
213 217
218 // insert the commit string in the editor
214 evas_object_textblock_text_markup_prepend(en->cursor, commit_str); 219 evas_object_textblock_text_markup_prepend(en->cursor, commit_str);
215 220
216 /* notify cursor information */ 221 // notify the cursor information
217 _imf_cursor_info_set(en); 222 _imf_cursor_info_set(en);
218 223
219 return; 224 return;
@@ -222,7 +227,7 @@ _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx, void *event_info)
222static void 227static void
223_ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info) 228_ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info)
224{ 229{
225 /* example how to get preedit string */ 230 // example how to get preedit string
226 Entry *en = data; 231 Entry *en = data;
227 char *preedit_string; 232 char *preedit_string;
228 int cursor_pos; 233 int cursor_pos;
@@ -236,19 +241,19 @@ _ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *ev
236 241
237 if (!en) return; 242 if (!en) return;
238 243
239 /* get preedit string, attributes */ 244 // get preedit string and attributes
240 ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, &attrs, &cursor_pos); 245 ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, &attrs, &cursor_pos);
241 printf("preedit string : %s\n", preedit_string); 246 printf("preedit string : %s\n", preedit_string);
242 247
243 if (!strcmp(preedit_string, "")) 248 if (!strcmp(preedit_string, ""))
244 preedit_end_state = EINA_TRUE; 249 preedit_end_state = EINA_TRUE;
245 250
246 /* delete preedit */ 251 // delete preedit
247 _preedit_del(en); 252 _preedit_del(en);
248 253
249 preedit_start_pos = evas_textblock_cursor_pos_get(en->cursor); 254 preedit_start_pos = evas_textblock_cursor_pos_get(en->cursor);
250 255
251 /* insert preedit character(s) */ 256 // insert preedit character(s)
252 if (strlen(preedit_string) > 0) 257 if (strlen(preedit_string) > 0)
253 { 258 {
254 if (attrs) 259 if (attrs)
@@ -257,27 +262,27 @@ _ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *ev
257 { 262 {
258 if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB1) // style type 263 if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB1) // style type
259 { 264 {
260 /* apply appropriate style such as underline */ 265 // apply appropriate style such as underline
261 } 266 }
262 else if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB2 || attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3) 267 else if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB2 || attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3)
263 { 268 {
264 /* apply appropriate style such as underline */ 269 // apply appropriate style such as underline
265 } 270 }
266 } 271 }
267 272
268 /* insert code to display preedit string in your editor */ 273 // insert code to display preedit string in your editor
269 evas_object_textblock_text_markup_prepend(en->cursor, preedit_string); 274 evas_object_textblock_text_markup_prepend(en->cursor, preedit_string);
270 } 275 }
271 } 276 }
272 277
273 if (!preedit_end_state) 278 if (!preedit_end_state)
274 { 279 {
275 /* set preedit start cursor */ 280 // set preedit start cursor
276 if (!en->preedit_start) 281 if (!en->preedit_start)
277 en->preedit_start = evas_object_textblock_cursor_new(en->txt_obj); 282 en->preedit_start = evas_object_textblock_cursor_new(en->txt_obj);
278 evas_textblock_cursor_copy(en->cursor, en->preedit_start); 283 evas_textblock_cursor_copy(en->cursor, en->preedit_start);
279 284
280 /* set preedit end cursor */ 285 // set preedit end cursor
281 if (!en->preedit_end) 286 if (!en->preedit_end)
282 en->preedit_end = evas_object_textblock_cursor_new(en->txt_obj); 287 en->preedit_end = evas_object_textblock_cursor_new(en->txt_obj);
283 evas_textblock_cursor_copy(en->cursor, en->preedit_end); 288 evas_textblock_cursor_copy(en->cursor, en->preedit_end);
@@ -291,11 +296,11 @@ _ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *ev
291 296
292 en->have_preedit = EINA_TRUE; 297 en->have_preedit = EINA_TRUE;
293 298
294 /* set cursor position */ 299 // set cursor position
295 evas_textblock_cursor_pos_set(en->cursor, preedit_start_pos + cursor_pos); 300 evas_textblock_cursor_pos_set(en->cursor, preedit_start_pos + cursor_pos);
296 } 301 }
297 302
298 /* notify cursor information */ 303 // notify the cursor information
299 _imf_cursor_info_set(en); 304 _imf_cursor_info_set(en);
300 305
301 EINA_LIST_FREE(attrs, attr) 306 EINA_LIST_FREE(attrs, attr)
@@ -338,7 +343,7 @@ _key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
338 if (evas_textblock_cursor_char_prev(en->cursor)) 343 if (evas_textblock_cursor_char_prev(en->cursor))
339 { 344 {
340 evas_textblock_cursor_char_delete(en->cursor); 345 evas_textblock_cursor_char_delete(en->cursor);
341 /* notify cursor information */ 346 // notify the cursor information
342 _imf_cursor_info_set(en); 347 _imf_cursor_info_set(en);
343 } 348 }
344 return; 349 return;
@@ -396,7 +401,7 @@ _key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
396 } 401 }
397 } 402 }
398 403
399 /* notify cursor information */ 404 // notify the cursor information
400 _imf_cursor_info_set(en); 405 _imf_cursor_info_set(en);
401} 406}
402 407
@@ -425,15 +430,15 @@ create_input_field(Evas *evas, Entry *en, Evas_Coord x, Evas_Coord y, Evas_Coord
425{ 430{
426 if (!en) return; 431 if (!en) return;
427 432
428 /* create background for text input field */ 433 // create the background for text input field
429 en->rect = evas_object_rectangle_add(evas); 434 en->rect = evas_object_rectangle_add(evas);
430 evas_object_color_set(en->rect, 150, 150, 150, 255); /* gray */ 435 evas_object_color_set(en->rect, 150, 150, 150, 255); // gray color
431 evas_object_move(en->rect, x, y); 436 evas_object_move(en->rect, x, y);
432 evas_object_resize(en->rect, w, h); 437 evas_object_resize(en->rect, w, h);
433 evas_object_show(en->rect); 438 evas_object_show(en->rect);
434 evas_object_data_set(en->rect, "Entry", en); 439 evas_object_data_set(en->rect, "Entry", en);
435 440
436 /* create text object for displaying text */ 441 // create text object for displaying text
437 en->txt_obj = evas_object_textblock_add(evas); 442 en->txt_obj = evas_object_textblock_add(evas);
438 evas_object_color_set(en->txt_obj, 0, 0, 0, 255); 443 evas_object_color_set(en->txt_obj, 0, 0, 0, 255);
439 evas_object_pass_events_set(en->txt_obj, EINA_TRUE); 444 evas_object_pass_events_set(en->txt_obj, EINA_TRUE);
@@ -441,19 +446,19 @@ create_input_field(Evas *evas, Entry *en, Evas_Coord x, Evas_Coord y, Evas_Coord
441 evas_object_resize(en->txt_obj, w, h); 446 evas_object_resize(en->txt_obj, w, h);
442 evas_object_show(en->txt_obj); 447 evas_object_show(en->txt_obj);
443 448
444 /* set style on textblock */ 449 // set style on textblock
445 static const char *style_buf = 450 static const char *style_buf =
446 "DEFAULT='font=Sans font_size=30 color=#000 text_class=entry'" 451 "DEFAULT='font=Sans font_size=30 color=#000 text_class=entry'"
447 "newline='br'" 452 "newline='br'"
448 "b='+ font=Sans:style=bold'"; 453 "b='+ font=Sans:style=bold'";
449 en->txt_style = evas_textblock_style_new(); 454 en->txt_style = evas_textblock_style_new();
450 evas_textblock_style_set(en->txt_style, style_buf); 455 evas_textblock_style_set(en->txt_style, style_buf);
451 evas_object_textblock_style_set(en->txt_obj, en->txt_style); 456 evas_object_textblock_style_set(en->txt_obj, en->txt_style);
452 457
453 /* create cursor */ 458 // create cursor
454 en->cursor = evas_object_textblock_cursor_new(en->txt_obj); 459 en->cursor = evas_object_textblock_cursor_new(en->txt_obj);
455 460
456 /* create input context */ 461 // create input context
457 const char *default_id = ecore_imf_context_default_id_get(); 462 const char *default_id = ecore_imf_context_default_id_get();
458 if (!default_id) 463 if (!default_id)
459 return; 464 return;
@@ -462,10 +467,15 @@ create_input_field(Evas *evas, Entry *en, Evas_Coord x, Evas_Coord y, Evas_Coord
462 ecore_imf_context_client_window_set(en->imf_context, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(evas))); 467 ecore_imf_context_client_window_set(en->imf_context, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(evas)));
463 ecore_imf_context_client_canvas_set(en->imf_context, evas); 468 ecore_imf_context_client_canvas_set(en->imf_context, evas);
464 469
470 // register key event handler
465 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_KEY_DOWN, _key_down_cb, en); 471 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_KEY_DOWN, _key_down_cb, en);
466 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_KEY_UP, _key_up_cb, en); 472 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_KEY_UP, _key_up_cb, en);
473
474 // register mouse event handler
467 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, en); 475 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_MOUSE_DOWN, _mouse_down_cb, en);
468 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_MOUSE_UP, _mouse_up_cb, en); 476 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_MOUSE_UP, _mouse_up_cb, en);
477
478 // register focus event handler
469 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_FOCUS_IN, _entry_focus_in_cb, en); 479 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_FOCUS_IN, _entry_focus_in_cb, en);
470 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_FOCUS_OUT, _entry_focus_out_cb, en); 480 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_FOCUS_OUT, _entry_focus_out_cb, en);
471 481
@@ -473,16 +483,16 @@ create_input_field(Evas *evas, Entry *en, Evas_Coord x, Evas_Coord y, Evas_Coord
473 en->preedit_start = NULL; 483 en->preedit_start = NULL;
474 en->preedit_end = NULL; 484 en->preedit_end = NULL;
475 485
476 /* register retrieve surrounding callback */ 486 // register retrieve surrounding callback
477 ecore_imf_context_retrieve_surrounding_callback_set(en->imf_context, _ecore_imf_retrieve_surrounding_cb, en); 487 ecore_imf_context_retrieve_surrounding_callback_set(en->imf_context, _ecore_imf_retrieve_surrounding_cb, en);
478 488
479 /* register commit event callback */ 489 // register commit event callback
480 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_COMMIT, _ecore_imf_event_commit_cb, en); 490 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_COMMIT, _ecore_imf_event_commit_cb, en);
481 491
482 /* register preedit changed event handler */ 492 // register preedit changed event handler
483 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb, en); 493 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb, en);
484 494
485 /* register surrounding delete event callback */ 495 // register surrounding delete event callback
486 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _ecore_imf_event_delete_surrounding_cb, en); 496 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _ecore_imf_event_delete_surrounding_cb, en);
487} 497}
488 498
@@ -575,6 +585,7 @@ main(int argc, char *argv[])
575 evas_object_color_set(bg, 255, 255, 255, 255); 585 evas_object_color_set(bg, 255, 255, 255, 255);
576 evas_object_show(bg); 586 evas_object_show(bg);
577 587
588 // register canvas focus in/out event handler
578 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _canvas_focus_in_cb, NULL); 589 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _canvas_focus_in_cb, NULL);
579 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _canvas_focus_out_cb, NULL); 590 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _canvas_focus_out_cb, NULL);
580 591