Only in gcin-1.6.4.pre14_cwlin: gcin-setup-chewing.cpp
diff -ur gcin-1.6.4.pre14/gcin-setup.cpp gcin-1.6.4.pre14_cwlin/gcin-setup.cpp
--- gcin-1.6.4.pre14/gcin-setup.cpp	2011-05-23 09:14:03.000000000 -0400
+++ gcin-1.6.4.pre14_cwlin/gcin-setup.cpp	2011-06-03 03:36:42.000000000 -0400
@@ -71,6 +71,13 @@
   create_kbm_window();
 }
 
+#if USE_CHEWING
+void chewing_setup_window_create (void);
+static void cb_chewing_input_method ()
+{
+    chewing_setup_window_create ();
+}
+#endif
 
 static void cb_tslearn()
 {
@@ -959,6 +966,12 @@
   g_signal_connect (G_OBJECT (button_gtab_conf), "clicked",
                     G_CALLBACK (cb_gtab_conf), NULL);
 
+#if USE_CHEWING
+  GtkWidget *button_chewing_input_method = gtk_button_new_with_label(_(_L("新酷音設定")));
+  gtk_box_pack_start (GTK_BOX (vbox), button_chewing_input_method, TRUE, TRUE, 0);
+  g_signal_connect (G_OBJECT (button_chewing_input_method), "clicked",
+                    G_CALLBACK (cb_chewing_input_method), NULL);
+#endif
 
   GtkWidget *button_default_input_method = gtk_button_new_with_label(_(_L("內定輸入法 & 開啟/關閉")));
   gtk_box_pack_start (GTK_BOX (vbox), button_default_input_method, TRUE, TRUE, 0);
diff -ur gcin-1.6.4.pre14/Makefile gcin-1.6.4.pre14_cwlin/Makefile
--- gcin-1.6.4.pre14/Makefile	2011-05-28 22:44:16.000000000 -0400
+++ gcin-1.6.4.pre14_cwlin/Makefile	2011-06-03 03:42:28.000000000 -0400
@@ -70,6 +70,11 @@
 OBJS += gcb.o
 endif
 
+ifeq ($(USE_CHEWING),Y)
+CFLAGS += -DUSE_CHEWING=1
+OBJS_gcin_setup += gcin-setup-chewing.o
+endif
+
 OBJ_IMSRV=im-addr.o im-dispatch.o im-srv.o gcin-crypt.o
 
 PROGS=gcin tsd2a32 tsa2d32 phoa2d phod2a tslearn gcin-setup gcin2tab \
diff -ur gcin-1.6.4.pre14/modules/chewing.cpp gcin-1.6.4.pre14_cwlin/modules/chewing.cpp
--- gcin-1.6.4.pre14/modules/chewing.cpp	2011-05-16 08:10:10.000000000 -0400
+++ gcin-1.6.4.pre14_cwlin/modules/chewing.cpp	2011-06-03 03:49:05.000000000 -0400
@@ -1,3 +1,7 @@
+#include <chewing/chewing.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
 #include "gcin.h"
 #include "pho.h"
 #include "gst.h"
@@ -5,8 +9,6 @@
 #include "win1.h"
 #include "gcin-module.h"
 
-#include <chewing/chewing.h>
-
 #define MAX_SEG_NUM  128
 
 typedef struct _SEGMENT {
@@ -43,6 +45,11 @@
 static gboolean gcin_label_clear (int nCount);
 static gboolean gcin_label_cand_show (char *pszWord, int nCount);
 static gboolean gtk_pango_font_pixel_size_get (int *pnFontWidth, int *pnFontHeight);
+static gboolean chewing_config_open (void);
+static void chewing_config_load (void);
+static void chewing_config_set (void);
+static void chewing_config_dump (void);
+void chewing_config_close (void);
 
 /*---------------------------------------------------------------------------*/
 /*    global vars                                                            */
@@ -54,9 +61,10 @@
 static GtkWidget *g_pHBoxChewing     = NULL;
 static SEG *g_pSeg = NULL;
 static int g_nCurrentCursorPos = 0;
-static int g_selKeyDefine[11] = {'a', 's', 'd', 'f', 
-                                 'g', 'h', 'j', 'k', 
-                                 'l', ';', 0};
+static ChewingConfigData g_chewingConfig;
+static int g_nFd;
+static gboolean g_bUseDefault = FALSE;
+
 // FIXME: impl
 static gboolean
 select_idx (int c)
@@ -181,13 +189,12 @@
     if (!g_pChewingCtx)
         return FALSE;
 
-    chewing_set_KBType (g_pChewingCtx, chewing_KBStr2Num ("KB_DEFAULT"));
+    if (chewing_config_open ())
+        chewing_config_load ();
+
+    chewing_config_set ();
 
-    chewing_set_candPerPage (g_pChewingCtx, 10);
-    chewing_set_maxChiSymbolLen (g_pChewingCtx, 16);
-    chewing_set_addPhraseDirection (g_pChewingCtx, 1);
-    chewing_set_selKey (g_pChewingCtx, g_selKeyDefine, 10);
-    chewing_set_spaceAsSelection (g_pChewingCtx, 1);
+    chewing_config_close ();
 
     return TRUE;
 }
@@ -296,20 +303,61 @@
     return;
 }
 
-// FIXME: impl
+// FIXME: chk
 int
 module_reset (void)
 {
     if (!g_pWinChewing)
         return 0;
+    return 1;
 }
 
-// FIXME: impl
+// FIXME: refine and chk
 int 
-module_get_preedit (char *pszStr, GCIN_PREEDIT_ATTR attr[], 
+module_get_preedit (char *pszStr, GCIN_PREEDIT_ATTR gcinPreeditAttr[], 
                     int *pnCursor, int *pCompFlag)
 {
-    return 0;
+    char *pszTmpStr = NULL;
+    int nIdx;
+    int nLength;
+    int nTotalLen = 0;
+    int nAttr = 0;
+
+    pszStr[0] = 0;
+    *pnCursor = 0;
+    gcinPreeditAttr[0].flag = GCIN_PREEDIT_ATTR_FLAG_UNDERLINE;
+    gcinPreeditAttr[0].ofs0 = 0;
+
+    if (chewing_buffer_Len (g_pChewingCtx))
+        nAttr = 1;
+
+    for (nIdx = 0; nIdx < chewing_buffer_Len (g_pChewingCtx); nIdx++)
+    {
+        pszTmpStr = (char *)gtk_label_get_text (GTK_LABEL (g_pSeg[nIdx].label));
+        nLength = g_gcinModMainFuncs.mf_utf8_str_N (pszTmpStr);
+        nTotalLen += nLength;
+    
+        if (nIdx < chewing_cursor_Current (g_pChewingCtx)) 
+            *pnCursor += nLength;
+
+#if 0
+        if (nIdx == chewing_cursor_Current (g_pChewingCtx))
+        {
+            gcinPreeditAttr[1].ofs0 = *pnCursor;
+            gcinPreeditAttr[1].ofs1 = *pnCursor + nLength;
+            gcinPreeditAttr[1].flag = GCIN_PREEDIT_ATTR_FLAG_REVERSE;
+            nAttr++;
+        }
+#endif
+
+        strcat (pszStr, pszTmpStr);
+    }
+
+    gcinPreeditAttr[0].ofs1 = nTotalLen;
+
+    pCompFlag = 0;
+
+    return nAttr;
 }
 
 gboolean 
@@ -457,6 +505,7 @@
         g_gcinModMainFuncs.mf_send_text (pszTmp);
 
         // FIXME: workaround for repeated commit
+        //        it impacts the bEscCleanAllBuf setting!
         chewing_handle_Esc (g_pChewingCtx); 
         free (pszTmp);
     }
@@ -541,7 +590,7 @@
     g_gcinModMainFuncs.mf_hide_win_sym ();
 }
 
-// FIXME: impl
+// FIXME: chk
 int 
 module_win_visible (void)
 {
@@ -562,3 +611,118 @@
                                        g_gcinModMainFuncs.mf_win_xl, 
                                        g_gcinModMainFuncs.mf_win_yl);
 }
+
+int 
+module_flush_input (void)
+{
+    char *pszTmp;
+
+    if (chewing_commit_Check (g_pChewingCtx))
+    {
+        pszTmp = chewing_commit_String (g_pChewingCtx);
+        g_gcinModMainFuncs.mf_send_text (pszTmp);
+        free (pszTmp);
+    }
+
+    chewing_Reset (g_pChewingCtx);
+    return 0;
+}
+
+static gboolean
+chewing_config_open (void)
+{
+    char *pszChewingConfig;
+    char *pszHome;
+
+    pszHome = getenv ("HOME");
+    if (!pszHome)
+        pszHome = "";
+
+    pszChewingConfig = malloc (strlen (pszHome) + strlen ("/.chewing/gcin_conf.dat") + 1);
+    memset (pszChewingConfig, 0x00, strlen (pszHome) + strlen ("/.chewing/gcin_conf.dat") + 1);
+    sprintf (pszChewingConfig, "%s/.chewing/gcin_conf.dat", pszHome);
+
+    g_nFd = open (pszChewingConfig,
+                  O_RDONLY,
+                  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+    free (pszChewingConfig);
+
+    return (g_nFd == -1 ? !(g_bUseDefault = TRUE) : TRUE);
+}
+
+static void
+chewing_config_load (void)
+{
+    int nReadSize;
+
+    nReadSize = read (g_nFd, &g_chewingConfig, sizeof (g_chewingConfig));
+    if (nReadSize == 0 || nReadSize != sizeof (g_chewingConfig))
+        g_bUseDefault = TRUE;
+}
+
+// TODO: add kbtype into gcin_conf.dat 
+//       or use the gcin setting instead
+static void
+chewing_config_set (void)
+{
+    if (g_bUseDefault)
+    {
+        int nDefaultSelKey[MAX_SELKEY] = {'a', 's', 'd', 'f', 
+                                          'g', 'h', 'j', 'k', 
+                                          'l', ';'};
+
+        g_chewingConfig.candPerPage           = 10;
+        g_chewingConfig.maxChiSymbolLen       = 16;
+        g_chewingConfig.bAddPhraseForward     = 1;
+        g_chewingConfig.bSpaceAsSelection     = 1;
+        g_chewingConfig.bEscCleanAllBuf       = 0;
+        g_chewingConfig.bAutoShiftCur         = 1;
+        g_chewingConfig.bEasySymbolInput      = 0;
+        g_chewingConfig.bPhraseChoiceRearward = 1;
+        g_chewingConfig.hsuSelKeyType         = 0;
+        memcpy (&g_chewingConfig.selKey, 
+                &nDefaultSelKey, 
+                sizeof (g_chewingConfig.selKey));
+    }
+
+    chewing_set_KBType (g_pChewingCtx, chewing_KBStr2Num ("KB_DEFAULT"));
+    chewing_set_selKey (g_pChewingCtx, g_chewingConfig.selKey, 10);
+    chewing_set_candPerPage (g_pChewingCtx, g_chewingConfig.candPerPage);
+    chewing_set_maxChiSymbolLen (g_pChewingCtx, g_chewingConfig.maxChiSymbolLen);
+    chewing_set_addPhraseDirection (g_pChewingCtx, g_chewingConfig.bAddPhraseForward);
+    chewing_set_spaceAsSelection (g_pChewingCtx, g_chewingConfig.bSpaceAsSelection);
+    chewing_set_escCleanAllBuf (g_pChewingCtx, g_chewingConfig.bEscCleanAllBuf);
+    chewing_set_autoShiftCur (g_pChewingCtx, g_chewingConfig.bAutoShiftCur);
+    chewing_set_easySymbolInput (g_pChewingCtx, g_chewingConfig.bEasySymbolInput);
+    chewing_set_phraseChoiceRearward (g_pChewingCtx, g_chewingConfig.bPhraseChoiceRearward);
+    chewing_set_hsuSelKeyType (g_pChewingCtx, g_chewingConfig.hsuSelKeyType);
+}
+
+static void
+chewing_config_dump (void)
+{
+    int nIdx = 0;
+    printf ("chewing config:\n");
+    printf ("\tcandPerPage: %d\n", g_chewingConfig.candPerPage);
+    printf ("\tmaxChiSymbolLen: %d\n", g_chewingConfig.maxChiSymbolLen);
+    printf ("\tbAddPhraseForward: %d\n", g_chewingConfig.bAddPhraseForward);
+    printf ("\tbSpaceAsSelection: %d\n", g_chewingConfig.bSpaceAsSelection);
+    printf ("\tbEscCleanAllBuf: %d\n", g_chewingConfig.bEscCleanAllBuf);
+    printf ("\tbAutoShiftCur: %d\n", g_chewingConfig.bAutoShiftCur);
+    printf ("\tbEasySymbolInput: %d\n", g_chewingConfig.bEasySymbolInput);
+    printf ("\tbPhraseChoiceRearward: %d\n", g_chewingConfig.bPhraseChoiceRearward);
+    printf ("\thsuSelKeyType: %d\n", g_chewingConfig.hsuSelKeyType);
+    printf ("\tselKey: ");
+    for (nIdx = 0; nIdx < MAX_SELKEY; nIdx++)
+        printf ("%c ", g_chewingConfig.selKey[nIdx]);
+    printf ("\n");
+}
+
+void
+chewing_config_close (void)
+{
+    if (g_nFd != -1)
+        close (g_nFd);
+}
+
diff -ur gcin-1.6.4.pre14/modules/Makefile gcin-1.6.4.pre14_cwlin/modules/Makefile
--- gcin-1.6.4.pre14/modules/Makefile	2011-05-28 22:44:16.000000000 -0400
+++ gcin-1.6.4.pre14_cwlin/modules/Makefile	2011-06-03 03:52:10.000000000 -0400
@@ -21,7 +21,7 @@
 
 chewing_module_so = chewing.pico
 chewing-module.so: $(chewing_module_so)
-	$(CCLD) $(SO_FLAGS) -o $@ $(chewing_module_so) $(LDFLAGS) -lchewing -I/usr/include/chewing
+	$(CCLD) $(SO_FLAGS) -o $@ $(chewing_module_so) $(LDFLAGS) $(shell pkg-config --cflags --libs chewing)
 
 install:
 	install $(GCIN_MODULE) $(gcinlibdir)
