* filter api 변경
authorChoe Hwanjin <choe.hwanjin@gmail.com>
Sun, 4 Mar 2007 13:28:14 +0000 (22:28 +0900)
committerChoe Hwanjin <choe.hwanjin@gmail.com>
Sun, 4 Mar 2007 13:28:14 +0000 (22:28 +0900)
 - hangul_ic_connect_translate() 추가:
   ascii 코드에서 한글코드로 변환할때 불리는 callback 등록 함수
 - hangul_ic_connect_transition() 추가:
   입력된 글자에 따라서 상태 전이(transition)이 발생할때 불리는 callback 등록
   함수
 - hangul_ic_set_filter()를 앞으로 사용하지 않음, 삭제될 예정

git-svn-id: http://kldp.net/svn/hangul/libhangul/trunk@117 8f00fcd2-89fc-0310-932e-b01be5b65e01

hangul/hangul.h
hangul/hangulinputcontext.c

index f1ac558..97c0f34 100644 (file)
@@ -1,5 +1,5 @@
 /* libhangul
- * Copyright (C) 2004 - 2006 Choe Hwanjin
+ * Copyright (C) 2004 - 2007 Choe Hwanjin
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -66,8 +66,15 @@ typedef struct _HangulKeyboard        HangulKeyboard;
 typedef struct _HangulCombination     HangulCombination;
 typedef struct _HangulBuffer          HangulBuffer;
 typedef struct _HangulInputContext    HangulInputContext;
-typedef bool   (*HangulICFilter)     (HangulInputContext*,
-                                     ucschar, const ucschar*, void*);
+
+typedef bool   (*HangulOnTransition) (HangulInputContext*,
+                                     ucschar,
+                                     const ucschar*,
+                                     void*);
+typedef void   (*HangulOnTranslate)  (HangulInputContext*,
+                                     int,
+                                     ucschar*,
+                                     void*);
 
 enum {
     HANGUL_OUTPUT_SYLLABLE,
@@ -113,8 +120,13 @@ void hangul_ic_select_keyboard(HangulInputContext *hic,
                               const char* id);
 void hangul_ic_set_combination(HangulInputContext *hic,
                               const HangulCombination *combination);
-void hangul_ic_set_filter(HangulInputContext *hic,
-                         HangulICFilter func, void *user_data);
+
+void hangul_ic_connect_translate (HangulInputContext* hic,
+                                  HangulOnTranslate callback,
+                                  void* user_data);
+void hangul_ic_connect_transition(HangulInputContext* hic,
+                                  HangulOnTransition callback,
+                                  void* user_data);
 
 const ucschar* hangul_ic_get_preedit_string(HangulInputContext *hic);
 const ucschar* hangul_ic_get_commit_string(HangulInputContext *hic);
@@ -141,6 +153,12 @@ const char*  hanja_get_key(const Hanja* hanja);
 const char*  hanja_get_value(const Hanja* hanja);
 const char*  hanja_get_comment(const Hanja* hanja);
 
+
+/* deprecated */
+typedef bool (*HangulICFilter) (ucschar*, ucschar, ucschar, ucschar, void*);
+void hangul_ic_set_filter(HangulInputContext *hic,
+                         HangulICFilter func, void *user_data);
+
 #ifdef __cplusplus
 }
 #endif
index b69deb4..c1878c0 100644 (file)
@@ -63,13 +63,20 @@ struct _HangulInputContext {
     const HangulCombination* combination;
 
     HangulBuffer buffer;
-    HangulICFilter filter;
-    void *filter_data;
     int output_mode;
 
     ucschar preedit_string[64];
     ucschar commit_string[64];
     ucschar flushed_string[64];
+
+    HangulOnTranslate   on_translate;
+    void*               on_translate_data;
+
+    HangulOnTransition  on_transition;
+    void*               on_transition_data;
+
+    HangulICFilter filter;
+    void *filter_data;
 };
 
 #include "hangulkeyboard.h"
@@ -462,7 +469,7 @@ static inline bool
 hangul_ic_push(HangulInputContext *hic, ucschar c)
 {
     ucschar buf[64] = { 0, };
-    if (hic->filter != NULL) {
+    if (hic->on_transition != NULL) {
        ucschar cho, jung, jong;
        if (hangul_is_choseong(c)) {
            cho  = c;
@@ -482,7 +489,7 @@ hangul_ic_push(HangulInputContext *hic, ucschar c)
        }
 
        hangul_jaso_to_string(cho, jung, jong, buf, N_ELEMENTS(buf));
-       if (!hic->filter(hic, c, buf, hic->filter_data)) {
+       if (!hic->on_transition(hic, c, buf, hic->on_transition_data)) {
            hangul_ic_flush_internal(hic);
            return false;
        }
@@ -785,20 +792,22 @@ hangul_ic_process_jaso(HangulInputContext *hic, ucschar ch)
 bool
 hangul_ic_process(HangulInputContext *hic, int ascii)
 {
-    ucschar ch;
+    ucschar c;
 
     if (hic == NULL)
        return false;
 
-    ch = hangul_keyboard_get_value(hic->keyboard, ascii);
-
     hic->preedit_string[0] = 0;
     hic->commit_string[0] = 0;
 
+    c = hangul_keyboard_get_value(hic->keyboard, ascii);
+    if (hic->on_translate != NULL)
+       hic->on_translate(hic, ascii, &c, hic->on_translate_data);
+
     if (hangul_keyboard_get_type(hic->keyboard) == HANGUL_KEYBOARD_TYPE_JAMO)
-       return hangul_ic_process_jamo(hic, ch);
+       return hangul_ic_process_jamo(hic, c);
     else
-       return hangul_ic_process_jaso(hic, ch);
+       return hangul_ic_process_jaso(hic, c);
 }
 
 const ucschar*
@@ -1014,14 +1023,32 @@ hangul_ic_set_output_mode(HangulInputContext *hic, int mode)
     hic->output_mode = mode;
 }
 
+void
+hangul_ic_connect_translate (HangulInputContext* hic,
+                             HangulOnTranslate callback,
+                             void* user_data)
+{
+    if (hic != NULL) {
+       hic->on_translate      = callback;
+       hic->on_translate_data = user_data;
+    }
+}
+
+void
+hangul_ic_connect_transition(HangulInputContext* hic,
+                             HangulOnTransition callback,
+                             void* user_data)
+{
+    if (hic != NULL) {
+       hic->on_transition      = callback;
+       hic->on_transition_data = user_data;
+    }
+}
+
 void hangul_ic_set_filter(HangulInputContext *hic,
                          HangulICFilter func, void *user_data)
 {
-    if (hic == NULL)
-       return;
-
-    hic->filter = func;
-    hic->filter_data = user_data;
+    return;
 }
 
 void