summaryrefslogtreecommitdiff
path: root/src/examples
diff options
context:
space:
mode:
authorJihoon Kim <jihoon48.kim@samsung.com>2015-07-14 16:15:35 +0900
committerJihoon Kim <jihoon48.kim@samsung.com>2015-07-14 16:15:35 +0900
commita3d68321b81f710bb2861c175a55cd95db9934bd (patch)
tree22e9a897c8c7dc698af9d265f95e11661353ffb8 /src/examples
parentd639d25b885cce01cc5439d86107cdc7618f1aac (diff)
example: check NULL value in ecore imf example
Diffstat (limited to 'src/examples')
-rw-r--r--src/examples/ecore/ecore_imf_example.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/examples/ecore/ecore_imf_example.c b/src/examples/ecore/ecore_imf_example.c
index 20fca53fa2..3acb0d290f 100644
--- a/src/examples/ecore/ecore_imf_example.c
+++ b/src/examples/ecore/ecore_imf_example.c
@@ -78,13 +78,16 @@ _mouse_up_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *
78 return; 78 return;
79 } 79 }
80 80
81 if (evas_object_focus_get(en->rect)) 81 if (en->rect)
82 { 82 {
83 // notify cursor information 83 if (evas_object_focus_get(en->rect))
84 _imf_cursor_info_set(en); 84 {
85 // notify cursor information
86 _imf_cursor_info_set(en);
87 }
88 else
89 evas_object_focus_set(en->rect, EINA_TRUE);
85 } 90 }
86 else
87 evas_object_focus_set(en->rect, EINA_TRUE);
88} 91}
89 92
90static void 93static void
@@ -149,15 +152,20 @@ _imf_cursor_info_set(Entry *en)
149 if (!en) return; 152 if (!en) return;
150 153
151 // get cursor geometry 154 // get cursor geometry
152 evas_object_geometry_get(en->txt_obj, &x, &y, &w, &h); 155 if (en->txt_obj)
153 evas_textblock_cursor_geometry_get(en->cursor, &cx, &cy, &cw, &ch, &dir, EVAS_TEXTBLOCK_CURSOR_BEFORE); 156 evas_object_geometry_get(en->txt_obj, &x, &y, &w, &h);
154 157
155 // get cursor position 158 if (en->cursor && en->imf_context)
156 cursor_pos = evas_textblock_cursor_pos_get(en->cursor); 159 {
160 evas_textblock_cursor_geometry_get(en->cursor, &cx, &cy, &cw, &ch, &dir, EVAS_TEXTBLOCK_CURSOR_BEFORE);
161
162 // get cursor position
163 cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
157 164
158 ecore_imf_context_cursor_position_set(en->imf_context, cursor_pos); 165 ecore_imf_context_cursor_position_set(en->imf_context, cursor_pos);
159 ecore_imf_context_cursor_location_set(en->imf_context, x + cx, y + cy, cw, ch); 166 ecore_imf_context_cursor_location_set(en->imf_context, x + cx, y + cy, cw, ch);
160 ecore_imf_context_bidi_direction_set(en->imf_context, (Ecore_IMF_BiDi_Direction)dir); 167 ecore_imf_context_bidi_direction_set(en->imf_context, (Ecore_IMF_BiDi_Direction)dir);
168 }
161} 169}
162 170
163static void 171static void
@@ -204,7 +212,7 @@ _ecore_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSE
204 *text = str ? strdup(str) : strdup(""); 212 *text = str ? strdup(str) : strdup("");
205 213
206 // get the current position of cursor 214 // get the current position of cursor
207 if (cursor_pos) 215 if (cursor_pos && en->cursor)
208 *cursor_pos = evas_textblock_cursor_pos_get(en->cursor); 216 *cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
209 217
210 return EINA_TRUE; 218 return EINA_TRUE;
@@ -219,7 +227,7 @@ _ecore_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx EINA_U
219 Evas_Textblock_Cursor *del_start, *del_end; 227 Evas_Textblock_Cursor *del_start, *del_end;
220 int cursor_pos; 228 int cursor_pos;
221 229
222 if ((!en) || (!ev)) return; 230 if ((!en) || (!ev) || (!en->cursor)) return;
223 231
224 // get the current cursor position 232 // get the current cursor position
225 cursor_pos = evas_textblock_cursor_pos_get(en->cursor); 233 cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
@@ -253,7 +261,8 @@ _ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx EINA_UNUSED, void
253 printf("commit string : %s\n", commit_str); 261 printf("commit string : %s\n", commit_str);
254 262
255 // insert the commit string in the editor 263 // insert the commit string in the editor
256 evas_object_textblock_text_markup_prepend(en->cursor, commit_str); 264 if (en->cursor && commit_str)
265 evas_object_textblock_text_markup_prepend(en->cursor, commit_str);
257 266
258 // notify the cursor information 267 // notify the cursor information
259 _imf_cursor_info_set(en); 268 _imf_cursor_info_set(en);
@@ -276,7 +285,7 @@ _ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *ev
276 int i; 285 int i;
277 Eina_Bool preedit_end_state = EINA_FALSE; 286 Eina_Bool preedit_end_state = EINA_FALSE;
278 287
279 if (!en) return; 288 if (!en || !en->cursor) return;
280 289
281 // get preedit string and attributes 290 // get preedit string and attributes
282 ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, &attrs, &cursor_pos); 291 ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, &attrs, &cursor_pos);
@@ -352,7 +361,7 @@ _key_down_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *o EINA_UNUSED, void *
352 Entry *en = data; 361 Entry *en = data;
353 Evas_Event_Key_Down *ev = event_info; 362 Evas_Event_Key_Down *ev = event_info;
354 Eina_Bool control, alt, shift; 363 Eina_Bool control, alt, shift;
355 if ((!en) || (!ev->key)) return; 364 if ((!en) || (!ev->key) || (!en->cursor)) return;
356 365
357 if (en->imf_context) 366 if (en->imf_context)
358 { 367 {
@@ -497,7 +506,10 @@ create_input_field(Evas *evas, Entry *en, Evas_Coord x, Evas_Coord y, Evas_Coord
497 // create input context 506 // create input context
498 const char *default_id = ecore_imf_context_default_id_get(); 507 const char *default_id = ecore_imf_context_default_id_get();
499 if (!default_id) 508 if (!default_id)
500 return; 509 {
510 fprintf(stderr, "Can't create ecore_imf_context\n");
511 return;
512 }
501 513
502 en->imf_context = ecore_imf_context_add(default_id); 514 en->imf_context = ecore_imf_context_add(default_id);
503 ecore_imf_context_client_window_set(en->imf_context, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(evas))); 515 ecore_imf_context_client_window_set(en->imf_context, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(evas)));
@@ -621,6 +633,9 @@ main(void)
621 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _canvas_focus_in_cb, NULL); 633 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_IN, _canvas_focus_in_cb, NULL);
622 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _canvas_focus_out_cb, NULL); 634 evas_event_callback_add(evas, EVAS_CALLBACK_CANVAS_FOCUS_OUT, _canvas_focus_out_cb, NULL);
623 635
636 memset(&en1, 0, sizeof(en1));
637 memset(&en2, 0, sizeof(en2));
638
624 // create input field 1 639 // create input field 1
625 create_input_field(evas, &en1, 40, 60, 400, 80); 640 create_input_field(evas, &en1, 40, 60, 400, 80);
626 641