Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update chewing candidate word choosing and cmake

  • Loading branch information...
commit 8669ccd5fb80c841e3ef26f2e49952309be094cb 1 parent b7afa89
@wengxt wengxt authored
View
8 CMakeLists.txt
@@ -2,6 +2,9 @@ cmake_minimum_required (VERSION 2.6)
project(fcitx-chewing)
+set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
+
+FIND_PACKAGE(Chewing REQUIRED)
FIND_PACKAGE(Gettext REQUIRED)
FIND_PACKAGE(Fcitx REQUIRED)
@@ -23,7 +26,10 @@ if(NOT DEFINED LIB_INSTALL_DIR)
set(LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib)
endif()
-set(HAVE_CONFIG_H)
+configure_file(
+ "${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/config.h"
+ )
set(libdir ${LIB_INSTALL_DIR})
View
37 cmake/FindChewing.cmake
@@ -0,0 +1,37 @@
+# - Try to find the CHEWING libraries
+# Once done this will define
+#
+# CHEWING_FOUND - system has CHEWING
+# CHEWING_INCLUDE_DIR - the CHEWING include directory
+# CHEWING_LIBRARIES - CHEWING library
+#
+# Copyright (c) 2010 Dario Freddi <drf@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+if(CHEWING_INCLUDE_DIR AND CHEWING_LIBRARIES)
+ # Already in cache, be silent
+ set(CHEWING_FIND_QUIETLY TRUE)
+endif(CHEWING_INCLUDE_DIR AND CHEWING_LIBRARIES)
+
+find_package(PkgConfig)
+pkg_check_modules(PC_LIBCHEWING QUIET chewing)
+
+find_path(CHEWING_MAIN_INCLUDE_DIR
+ NAMES chewing.h
+ HINTS ${PC_LIBCHEWING_INCLUDEDIR}
+ PATH_SUFFIXES chewing)
+
+find_library(CHEWING_LIBRARIES
+ NAMES chewing
+ HINTS ${PC_LIBCHEWING_LIBDIR})
+
+_pkgconfig_invoke("chewing" CHEWING DATADIR "" "--variable=datadir")
+
+set(CHEWING_INCLUDE_DIR "${CHEWING_MAIN_INCLUDE_DIR}")
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(CHEWING DEFAULT_MSG CHEWING_LIBRARIES CHEWING_MAIN_INCLUDE_DIR)
+
+mark_as_advanced(CHEWING_INCLUDE_DIR CHEWING_LIBRARIES)
View
1  config.h.in
@@ -0,0 +1 @@
+#define CHEWING_DATADIR "@CHEWING_DATADIR@"
View
10 po/CMakeLists.txt
@@ -2,9 +2,9 @@ set(PO_FILES zh_CN.po)
file(RELATIVE_PATH REL_SOURCE_ROOT ${PROJECT_BINARY_DIR} ${PROJECT_SOURCE_DIR})
if ("${REL_SOURCE_ROOT}" STREQUAL "")
set(REL_SOURCE_ROOT ".")
-endif("${REL_SOURCE_ROOT}" STREQUAL "")
+endif("${REL_SOURCE_ROOT}" STREQUAL "")
-set(POT_FILE ${CMAKE_CURRENT_BINARY_DIR}/fcitx-chewing.pot)
+set(POT_FILE fcitx-chewing.pot)
configure_file(POTFILES.in.in ${CMAKE_CURRENT_BINARY_DIR}/POTFILES.in)
@@ -14,10 +14,10 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/desc.po
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/getdescpo ${PROJECT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS getdescpo)
-add_custom_command(
- OUTPUT ${POT_FILE}
+add_custom_target(
+ pot
COMMAND INTLTOOL_EXTRACT=${INTLTOOL_EXTRACT} srcdir=${CMAKE_CURRENT_BINARY_DIR} ${INTLTOOL_UPDATE} --gettext-package fcitx-chewing --pot
- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conf.po ${CMAKE_CURRENT_BINARY_DIR}/desc.po
)
View
32 po/fcitx-chewing.pot
@@ -0,0 +1,32 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2012-01-02 13:48+0800\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <LL@li.org>\n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: /home/saber/Develop/fcitx-chewing/data/fcitx-chewing.desc:4
+msgid "Priority of Chewing"
+msgstr ""
+
+# unknown
+#: /home/saber/Develop/fcitx-chewing/build/po/tmp/fcitx-chewing.conf.in.h:1
+#: /home/saber/Develop/fcitx-chewing/build/po/../..//src/eim.c:81
+msgid "Chewing"
+msgstr ""
+
+#: /home/saber/Develop/fcitx-chewing/build/po/tmp/fcitx-chewing.conf.in.h:2
+msgid "Chewing Wrapper For Fcitx"
+msgstr ""
View
12 po/zh_CN.po
@@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2012-01-01 06:59-0800\n"
+"POT-Creation-Date: 2012-01-02 13:48+0800\n"
"PO-Revision-Date: 2011-08-12 01:54+0800\n"
"Last-Translator: \n"
"Language-Team: Chinese Simplified <kde-i18n-doc@kde.org>\n"
@@ -17,11 +17,15 @@ msgstr ""
"X-Generator: Lokalize 1.2\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
-#: /home/march/fcitx-chewing/build/po/tmp/fcitx-chewing.conf.in.h:1
-#: /home/march/fcitx-chewing/build/po/../..//src/eim.c:81
+#: /home/saber/Develop/fcitx-chewing/build/po/tmp/fcitx-chewing.conf.in.h:1
+#: /home/saber/Develop/fcitx-chewing/build/po/../..//src/eim.c:81
msgid "Chewing"
msgstr "酷音"
-#: /home/march/fcitx-chewing/build/po/tmp/fcitx-chewing.conf.in.h:2
+#: /home/saber/Develop/fcitx-chewing/build/po/tmp/fcitx-chewing.conf.in.h:2
msgid "Chewing Wrapper For Fcitx"
msgstr "Fcitx 的 酷音 封装"
+
+#: /home/saber/Develop/fcitx-chewing/data/fcitx-chewing.desc:4
+msgid "Priority of Chewing"
+msgstr ""
View
7 src/CMakeLists.txt
@@ -1,11 +1,8 @@
-include(FindPkgConfig)
-
-PKG_CHECK_MODULES(CHEWING REQUIRED "chewing" )
-
-include_directories (${CHEWING_INCLUDE_DIRS})
+include_directories (${CHEWING_INCLUDE_DIR})
include_directories (${FCITX4_FCITX_INCLUDE_DIRS})
include_directories (${FCITX4_FCITX_CONFIG_INCLUDE_DIRS})
include_directories (${FCITX4_FCITX_UTILS_INCLUDE_DIRS})
+include_directories (${PROJECT_BINARY_DIR})
set( fcitx_chewing_sources
eim.c
View
324 src/eim.c
@@ -1,6 +1,6 @@
/***************************************************************************
- * Copyright (C) 2010~2010 by CSSlayer *
- * wengxt@gmail.com *
+ * Copyright (C) 2012~2012 by Tai-Lin Chu *
+ * tailinchugmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
@@ -23,17 +23,20 @@
#include <string.h>
#include <errno.h>
#include <fcitx/ime.h>
+#include <fcitx-config/xdg.h>
#include <fcitx-config/hotkey.h>
#include <fcitx-utils/log.h>
#include <fcitx-utils/utils.h>
#include <fcitx-utils/utf8.h>
#include <fcitx/instance.h>
+#include <fcitx/context.h>
#include <fcitx/keys.h>
#include <fcitx/ui.h>
#include <libintl.h>
#include <chewing.h>
+#include "config.h"
#include "eim.h"
FCITX_EXPORT_API
@@ -45,9 +48,17 @@ FCITX_EXPORT_API
int ABI_VERSION = FCITX_ABI_VERSION;
static int FcitxChewingGetRawCursorPos(char * str, int upos);
+static INPUT_RETURN_VALUE FcitxChewingGetCandWord(void* arg, FcitxCandidateWord* candWord);
-FcitxHotkey FCITX_CHEWING_UP[2] = {{NULL, FcitxKey_Up, FcitxKeyState_None}, {NULL, FcitxKey_None, FcitxKeyState_None}};
-FcitxHotkey FCITX_CHEWING_DOWN[2] = {{NULL, FcitxKey_Down, FcitxKeyState_None}, {NULL, FcitxKey_None, FcitxKeyState_None}};
+typedef struct _ChewingCandWord {
+ int index;
+} ChewingCandWord;
+
+const FcitxHotkey FCITX_CHEWING_UP[2] = {{NULL, FcitxKey_Up, FcitxKeyState_None}, {NULL, FcitxKey_None, FcitxKeyState_None}};
+const FcitxHotkey FCITX_CHEWING_DOWN[2] = {{NULL, FcitxKey_Down, FcitxKeyState_None}, {NULL, FcitxKey_None, FcitxKeyState_None}};
+FcitxHotkey FCITX_CHEWING_PGUP[2] = {{NULL, FcitxKey_Page_Up, FcitxKeyState_None}, {NULL, FcitxKey_None, FcitxKeyState_None}};
+FcitxHotkey FCITX_CHEWING_PGDN[2] = {{NULL, FcitxKey_Page_Down, FcitxKeyState_None}, {NULL, FcitxKey_None, FcitxKeyState_None}};
+int selKey[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
/**
* @brief initialize the extra input method
@@ -58,39 +69,53 @@ FcitxHotkey FCITX_CHEWING_DOWN[2] = {{NULL, FcitxKey_Down, FcitxKeyState_None},
__EXPORT_API
void* FcitxChewingCreate(FcitxInstance* instance)
{
+ char* user_path = NULL;
+ FILE* fp = FcitxXDGGetFileUserWithPrefix("chewing", ".place_holder", "w", NULL);
+ if (fp)
+ fclose(fp);
+ FcitxXDGGetFileUserWithPrefix("/", "chewing", NULL, &user_path);
+ FcitxLog(INFO, "Chewing storage path %s", user_path);
+ if (0 == chewing_Init(CHEWING_DATADIR, user_path)) {
+ FcitxLog(DEBUG, "chewing init ok");
+ } else {
+ FcitxLog(DEBUG, "chewing init failed");
+ return NULL;
+ }
+
FcitxChewing* chewing = (FcitxChewing*) fcitx_utils_malloc0(sizeof(FcitxChewing));
- bindtextdomain("fcitx-chewing", LOCALEDIR);
+ FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(instance);
+ FcitxInputState *input = FcitxInstanceGetInputState(instance);
+ FcitxCandidateWordSetChoose(FcitxInputStateGetCandidateList(input), DIGIT_STR_CHOOSE);
+ bindtextdomain("fcitx-chewing", LOCALEDIR);
+
chewing->context = chewing_new();
ChewingContext * c = chewing->context;
chewing->owner = instance;
- chewing_set_ChiEngMode(c, CHINESE_MODE);
+ chewing_set_ChiEngMode(c, CHINESE_MODE);
chewing_set_maxChiSymbolLen(c, 16);
// chewing will crash without set page
- chewing_set_candPerPage(c, 10);
- FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner);
- FcitxCandidateWordSetChoose(FcitxInputStateGetCandidateList(input), DIGIT_STR_CHOOSE);
- FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), 10);
- int selKey[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
+ chewing_set_candPerPage(c, config->iMaxCandWord);
+ FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), config->iMaxCandWord);
chewing_set_selKey(c, selKey, 10);
FcitxInstanceRegisterIM(
- instance,
- chewing,
- "chewing",
- _("Chewing"),
- "chewing",
- FcitxChewingInit,
- FcitxChewingReset,
- FcitxChewingDoInput,
- FcitxChewingGetCandWords,
- NULL,
- NULL,
- NULL,
- NULL,
- 1,
- "zh_CN"
- );
+ instance,
+ chewing,
+ "chewing",
+ _("Chewing"),
+ "chewing",
+ FcitxChewingInit,
+ FcitxChewingReset,
+ FcitxChewingDoInput,
+ FcitxChewingGetCandWords,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 1,
+ "zh_TW"
+ );
return chewing;
}
@@ -105,78 +130,69 @@ void* FcitxChewingCreate(FcitxInstance* instance)
__EXPORT_API
INPUT_RETURN_VALUE FcitxChewingDoInput(void* arg, FcitxKeySym sym, unsigned int state)
{
- FcitxChewing* chewing = (FcitxChewing*) arg;
- FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner);
+ FcitxChewing* chewing = (FcitxChewing*) arg;
+ FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner);
ChewingContext * c = chewing->context;
+ if (FcitxHotkeyIsHotKeyDigit(sym, state) && !chewing_cand_CheckDone(c))
+ return IRV_TO_PROCESS;
+
if (FcitxHotkeyIsHotKeySimple(sym, state)) {
- int scan_code= (int) sym & 0xff;
- chewing_handle_Default(c, scan_code);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
- chewing_handle_Backspace(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_DELETE)) {
- chewing_handle_Del(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
- chewing_handle_Space(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ESCAPE)) {
- chewing_handle_Esc(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_UP)) {
- chewing_handle_Up(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_DOWN)) {
- chewing_handle_Down(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT)) {
- chewing_handle_Right(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)) {
- chewing_handle_Left(c);
- }
- else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
+ int scan_code = (int) sym & 0xff;
+ chewing_handle_Default(c, scan_code);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_BACKSPACE)) {
+ chewing_handle_Backspace(c);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_DELETE)) {
+ chewing_handle_Del(c);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_SPACE)) {
+ chewing_handle_Space(c);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_UP)) {
+ chewing_handle_Up(c);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_DOWN)) {
+ chewing_handle_Down(c);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGUP)) {
+ chewing_handle_PageDown(c);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_CHEWING_PGDN)) {
+ chewing_handle_PageUp(c);
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_RIGHT)) {
+ return IRV_TO_PROCESS;
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_LEFT)) {
+ return IRV_TO_PROCESS;
+ } else if (FcitxHotkeyIsHotKey(sym, state, FCITX_ENTER)) {
chewing_handle_Enter(c);
- }
- else {
- // to do: more chewing_handle
- return IRV_TO_PROCESS;
- }
- if (chewing_keystroke_CheckAbsorb(c)) {
- return IRV_DISPLAY_CANDWORDS;
- } else if (chewing_keystroke_CheckIgnore(c)) {
- return IRV_TO_PROCESS;
- }
- else if (chewing_commit_Check(c)) {
- char* str = chewing_commit_String(c);
- strcpy(FcitxInputStateGetOutputString(input), str);
- chewing_free(str);
- return IRV_COMMIT_STRING;
- }
- else
- return IRV_DISPLAY_CANDWORDS;
+ } else if (state == FcitxKeyState_Ctrl && FcitxHotkeyIsHotKeyDigit(sym, FcitxKeyState_None)) {
+ chewing_handle_CtrlNum(c, sym);
+ } else {
+ // to do: more chewing_handle
+ return IRV_TO_PROCESS;
+ }
+ if (chewing_keystroke_CheckAbsorb(c)) {
+ return IRV_DISPLAY_CANDWORDS;
+ } else if (chewing_keystroke_CheckIgnore(c)) {
+ return IRV_TO_PROCESS;
+ } else if (chewing_commit_Check(c)) {
+ char* str = chewing_commit_String(c);
+ strcpy(FcitxInputStateGetOutputString(input), str);
+ chewing_free(str);
+ return IRV_COMMIT_STRING;
+ } else
+ return IRV_DISPLAY_CANDWORDS;
}
__EXPORT_API
boolean FcitxChewingInit(void* arg)
{
- if (0 == chewing_Init("/usr/share/chewing", NULL)) {
- FcitxLog(INFO, "chewing init ok");
- return true;
- }
- else {
- FcitxLog(INFO, "chewing init failed");
- return false;
- }
+ FcitxChewing* chewing = (FcitxChewing*) arg;
+ FcitxInstanceSetContext(chewing->owner, CONTEXT_ALTERNATIVE_PREVPAGE_KEY, FCITX_LEFT);
+ FcitxInstanceSetContext(chewing->owner, CONTEXT_ALTERNATIVE_NEXTPAGE_KEY, FCITX_RIGHT);
+ return true;
}
__EXPORT_API
void FcitxChewingReset(void* arg)
{
- FcitxChewing* chewing = (FcitxChewing*) arg;
- chewing_Reset(chewing->context);
+ FcitxChewing* chewing = (FcitxChewing*) arg;
+ chewing_Reset(chewing->context);
}
@@ -189,49 +205,98 @@ void FcitxChewingReset(void* arg)
__EXPORT_API
INPUT_RETURN_VALUE FcitxChewingGetCandWords(void* arg)
{
- FcitxChewing* chewing = (FcitxChewing*) arg;
+ FcitxChewing* chewing = (FcitxChewing*) arg;
FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner);
FcitxMessages *msgPreedit = FcitxInputStateGetPreedit(input);
ChewingContext * c = chewing->context;
+ FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(chewing->owner);
+ chewing_set_candPerPage(c, config->iMaxCandWord);
+ FcitxCandidateWordSetPageSize(FcitxInputStateGetCandidateList(input), config->iMaxCandWord);
+
//clean up window asap
FcitxInstanceCleanInputWindowUp(chewing->owner);
-
- char * buf_str = chewing_buffer_String(c);
- char * zuin_str = chewing_zuin_String(c, NULL);
- FcitxLog(INFO, "%s %s", buf_str, zuin_str);
-
- //get candidate word
- chewing_cand_Enumerate(c);
- while (chewing_cand_hasNext(c)) {
- char* str = chewing_cand_String(c);
- FcitxCandidateWord cw;
- cw.callback = NULL;
- cw.owner = chewing;
- cw.priv = NULL;
- cw.strExtra = NULL;
- cw.strWord = strdup(str);
- cw.wordType = MSG_OTHER;
- FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &cw);
- chewing_free(str);
- }
-
- // setup cursor
- FcitxInputStateSetShowCursor(input, true);
- int buf_len = chewing_buffer_Len(c);
- int cur = chewing_cursor_Current(c);
- FcitxLog(INFO, "buf len: %d, cur: %d", buf_len, cur);
- int rcur = FcitxChewingGetRawCursorPos(buf_str, cur);
- FcitxInputStateSetCursorPos(input, rcur);
+ char * buf_str = chewing_buffer_String(c);
+ char * zuin_str = chewing_zuin_String(c, NULL);
+
+ FcitxLog(INFO, "%s %s", buf_str, zuin_str);
+
+ if (!chewing_cand_CheckDone(c)) {
+ //get candidate word
+ chewing_cand_Enumerate(c);
+ int index = 0;
+ while (chewing_cand_hasNext(c)) {
+ char* str = chewing_cand_String(c);
+ FcitxCandidateWord cw;
+ ChewingCandWord* w = (ChewingCandWord*) fcitx_utils_malloc0(sizeof(ChewingCandWord));
+ w->index = index;
+ cw.callback = FcitxChewingGetCandWord;
+ cw.owner = chewing;
+ cw.priv = w;
+ cw.strExtra = NULL;
+ cw.strWord = strdup(str);
+ cw.wordType = MSG_OTHER;
+ FcitxCandidateWordAppend(FcitxInputStateGetCandidateList(input), &cw);
+ chewing_free(str);
+ index ++;
+ }
+ }
+
+ // setup cursor
+ FcitxInputStateSetShowCursor(input, true);
+ int buf_len = chewing_buffer_Len(c);
+ int cur = chewing_cursor_Current(c);
+ FcitxLog(INFO, "buf len: %d, cur: %d", buf_len, cur);
+ int rcur = FcitxChewingGetRawCursorPos(buf_str, cur);
+ FcitxInputStateSetCursorPos(input, rcur);
- // insert zuin in the middle
- char * half1 = strndup(buf_str, rcur);
- char * half2 = strdup(buf_str + rcur);
- FcitxMessagesAddMessageAtLast(msgPreedit, MSG_INPUT, "%s%s%s", half1, zuin_str, half2);
- chewing_free(buf_str); chewing_free(zuin_str);
+ // insert zuin in the middle
+ char * half1 = strndup(buf_str, rcur);
+ char * half2 = strdup(buf_str + rcur);
+ FcitxMessagesAddMessageAtLast(msgPreedit, MSG_INPUT, "%s%s%s", half1, zuin_str, half2);
+ chewing_free(buf_str); chewing_free(zuin_str);
- return IRV_DISPLAY_CANDWORDS;
+ return IRV_DISPLAY_CANDWORDS;
+}
+
+INPUT_RETURN_VALUE FcitxChewingGetCandWord(void* arg, FcitxCandidateWord* candWord)
+{
+ FcitxChewing* chewing = (FcitxChewing*) candWord->owner;
+ ChewingCandWord* w = (ChewingCandWord*) candWord->priv;
+ FcitxGlobalConfig* config = FcitxInstanceGetGlobalConfig(chewing->owner);
+ FcitxInputState *input = FcitxInstanceGetInputState(chewing->owner);
+ int page = w->index / config->iMaxCandWord;
+ int off = w->index % config->iMaxCandWord;
+ if (page < 0 || page >= chewing_cand_TotalPage(chewing->context))
+ return IRV_TO_PROCESS;
+ int lastPage = chewing_cand_CurrentPage(chewing->context);
+ while (page != chewing_cand_CurrentPage(chewing->context)) {
+ if (page < chewing_cand_CurrentPage(chewing->context)) {
+ chewing_handle_Left(chewing->context);
+ }
+ if (page > chewing_cand_CurrentPage(chewing->context)) {
+ chewing_handle_Right(chewing->context);
+ }
+ /* though useless, but take care if there is a bug cause freeze */
+ if (lastPage == chewing_cand_CurrentPage(chewing->context)) {
+ break;
+ }
+ lastPage = chewing_cand_CurrentPage(chewing->context);
+ }
+ chewing_handle_Default( chewing->context, selKey[off] );
+
+ if (chewing_keystroke_CheckAbsorb(chewing->context)) {
+ return IRV_DISPLAY_CANDWORDS;
+ } else if (chewing_keystroke_CheckIgnore(chewing->context)) {
+ return IRV_TO_PROCESS;
+ } else if (chewing_commit_Check(chewing->context)) {
+ char* str = chewing_commit_String(chewing->context);
+ strcpy(FcitxInputStateGetOutputString(input), str);
+ chewing_free(str);
+ return IRV_COMMIT_STRING;
+ } else
+ return IRV_DISPLAY_CANDWORDS;
}
/**
@@ -241,13 +306,12 @@ INPUT_RETURN_VALUE FcitxChewingGetCandWords(void* arg)
**/
static int FcitxChewingGetRawCursorPos(char * str, int upos)
{
- unsigned int i;
- int pos =0;
- for (i=0; i<upos; i++)
- {
- pos += fcitx_utf8_char_len(fcitx_utf8_get_nth_char(str, i));
- }
- return pos;
+ unsigned int i;
+ int pos = 0;
+ for (i = 0; i < upos; i++) {
+ pos += fcitx_utf8_char_len(fcitx_utf8_get_nth_char(str, i));
+ }
+ return pos;
}
/**
@@ -258,8 +322,8 @@ static int FcitxChewingGetRawCursorPos(char * str, int upos)
__EXPORT_API
void FcitxChewingDestroy(void* arg)
{
- FcitxChewing* chewing = (FcitxChewing*) arg;
- chewing_delete(chewing->context);
- chewing_Terminate();
- free(arg);
+ FcitxChewing* chewing = (FcitxChewing*) arg;
+ chewing_delete(chewing->context);
+ chewing_Terminate();
+ free(arg);
}

0 comments on commit 8669ccd

Please sign in to comment.
Something went wrong with that request. Please try again.