// output static jboolean get_commit(JNIEnv *env, jobject thiz, jint session_id) { RIME_STRUCT(RimeCommit, commit); Bool r = RimeGetCommit((RimeSessionId)session_id, &commit); jclass jc = env->GetObjectClass(thiz); jfieldID fid = env->GetFieldID(jc, "commit_text", "Ljava/lang/String;"); jstring s = NULL; if (r) { s = newJstring(env, commit.text); RimeFreeCommit(&commit); } env->SetObjectField(thiz, fid, s); return r; }
bool RimeWithWeaselHandler::_Respond(UINT session_id, LPWSTR buffer) { std::set<std::string> actions; std::list<std::string> messages; // extract information RimeCommit commit = {0}; if (RimeGetCommit(session_id, &commit)) { actions.insert("commit"); messages.push_back(boost::str(boost::format("commit=%s\n") % commit.text)); RimeFreeCommit(&commit); } bool is_composing; RimeStatus status = {0}; RIME_STRUCT_INIT(RimeStatus, status); if (RimeGetStatus(session_id, &status)) { is_composing = status.is_composing; actions.insert("status"); messages.push_back(boost::str(boost::format("status.ascii_mode=%d\n") % status.is_ascii_mode)); messages.push_back(boost::str(boost::format("status.composing=%d\n") % status.is_composing)); messages.push_back(boost::str(boost::format("status.disabled=%d\n") % status.is_disabled)); RimeFreeStatus(&status); } RimeContext ctx = {0}; RIME_STRUCT_INIT(RimeContext, ctx); if (RimeGetContext(session_id, &ctx)) { if (is_composing) { actions.insert("ctx"); messages.push_back(boost::str(boost::format("ctx.preedit=%s\n") % ctx.composition.preedit)); if (ctx.composition.sel_start <= ctx.composition.sel_end) { messages.push_back(boost::str(boost::format("ctx.preedit.cursor=%d,%d\n") % utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start) % utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end))); } } RimeFreeContext(&ctx); } // configuration information actions.insert("config"); messages.push_back(boost::str(boost::format("config.inline_preedit=%d\n") % (int) m_ui->style().inline_preedit)); // summarize if (actions.empty()) { messages.insert(messages.begin(), std::string("action=noop\n")); } else { std::string actionList(boost::join(actions, ",")); messages.insert(messages.begin(), boost::str(boost::format("action=%s\n") % actionList)); } messages.push_back(std::string(".\n")); // printing to stream memset(buffer, 0, WEASEL_IPC_BUFFER_SIZE); wbufferstream bs(buffer, WEASEL_IPC_BUFFER_LENGTH); BOOST_FOREACH(const std::string &msg, messages) { bs << utf8towcs(msg.c_str()); if (!bs.good()) { // response text toooo long! return false; } }
bool RimeWithWeaselHandler::_Respond(UINT session_id, EatLine eat) { std::set<std::string> actions; std::list<std::string> messages; // extract information RIME_STRUCT(RimeCommit, commit); if (RimeGetCommit(session_id, &commit)) { actions.insert("commit"); messages.push_back(std::string("commit=") + commit.text + '\n'); RimeFreeCommit(&commit); } bool is_composing = false; RIME_STRUCT(RimeStatus, status); if (RimeGetStatus(session_id, &status)) { is_composing = !!status.is_composing; actions.insert("status"); messages.push_back(std::string("status.ascii_mode=") + std::to_string(status.is_ascii_mode) + '\n'); messages.push_back(std::string("status.composing=") + std::to_string(status.is_composing) + '\n'); messages.push_back(std::string("status.disabled=") + std::to_string(status.is_disabled) + '\n'); RimeFreeStatus(&status); } RIME_STRUCT(RimeContext, ctx); if (RimeGetContext(session_id, &ctx)) { if (is_composing) { actions.insert("ctx"); switch (m_ui->style().preedit_type) { case weasel::UIStyle::PREVIEW: if (ctx.commit_text_preview != NULL) { std::string first = ctx.commit_text_preview; messages.push_back(std::string("ctx.preedit=") + first + '\n'); messages.push_back(std::string("ctx.preedit.cursor=") + std::to_string(utf8towcslen(first.c_str(), 0)) + ',' + std::to_string(utf8towcslen(first.c_str(), first.size())) + '\n'); break; } // no preview, fall back to composition case weasel::UIStyle::COMPOSITION: messages.push_back(std::string("ctx.preedit=") + ctx.composition.preedit + '\n'); if (ctx.composition.sel_start <= ctx.composition.sel_end) { messages.push_back(std::string("ctx.preedit.cursor=") + std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_start)) + ',' + std::to_string(utf8towcslen(ctx.composition.preedit, ctx.composition.sel_end)) + '\n'); } break; } } if (ctx.menu.num_candidates) { weasel::CandidateInfo cinfo; std::wstringstream ss; boost::archive::text_woarchive oa(ss); _GetCandidateInfo(cinfo, ctx); oa << cinfo; messages.push_back(std::string("ctx.cand=") + wcstoutf8(ss.str().c_str()) + '\n'); } RimeFreeContext(&ctx); } // configuration information actions.insert("config"); messages.push_back(std::string("config.inline_preedit=") + std::to_string((int)m_ui->style().inline_preedit) + '\n'); // style bool has_synced = RimeGetOption(session_id, "__synced"); if (!has_synced) { std::wstringstream ss; boost::archive::text_woarchive oa(ss); oa << m_ui->style(); actions.insert("style"); messages.push_back(std::string("style=") + wcstoutf8(ss.str().c_str()) + '\n'); RimeSetOption(session_id, "__synced", true); } // summarize if (actions.empty()) { messages.insert(messages.begin(), std::string("action=noop\n")); } else { std::string actionList(join(actions, ",")); messages.insert(messages.begin(), std::string("action=") + actionList + '\n'); } messages.push_back(std::string(".\n")); return std::all_of(messages.begin(), messages.end(), [&eat](std::string &msg) { return eat(std::wstring(utf8towcs(msg.c_str()))); }); }