Back to index

im-sdk  12.3.91
preedit.c
Go to the documentation of this file.
00001 /*
00002   preedit.c
00003 */
00004 
00005 #include <stdlib.h>
00006 #include "iiimcfint.h"
00007 
00008 IIIMF_status
00009 iiimcf_toggle_preedit(
00010     IIIMCF_context_rec *pc,
00011     int flag
00012 )
00013 {
00014     if (flag && !IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_PREEDIT_ENABLED)) {
00015        IIIMCF_SET_STATE(pc, IIIMCF_CONTEXT_PREEDIT_ENABLED);
00016        IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_PREEDIT_CHANGED);
00017        return iiimcf_store_simple_event(pc, IIIMCF_EVENT_TYPE_UI_PREEDIT_START);
00018     } else if (!flag && IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_PREEDIT_ENABLED)) {
00019        IIIMCF_RESET_STATE(pc, IIIMCF_CONTEXT_PREEDIT_ENABLED);
00020        IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_PREEDIT_CHANGED);
00021        return iiimcf_store_simple_event(pc, IIIMCF_EVENT_TYPE_UI_PREEDIT_DONE);
00022     }
00023 
00024     return IIIMF_STATUS_SUCCESS;
00025 }
00026 
00027 IIIMF_status
00028 iiimcf_update_preedit(
00029     IIIMCF_context_rec *pc,
00030     IIIMP_message *pmes
00031 )
00032 {
00033     IIIMF_status st;
00034     ASSERT(pmes->opcode == IM_PREEDIT_DRAW);
00035 
00036     st = iiimcf_update_text_by_preedit_draw(&pc->preedit_text, pmes);
00037     if (st != IIIMF_STATUS_SUCCESS) return st;
00038 
00039     /* 
00040        Strictly speaking, we should not enable status here.
00041        However, Solaris Chinese LEs never send IM_PREEDIT_START,
00042        we cannot help enabling preedit by IM_PREEDIT_DRAW as well...
00043        See iiimcf_update_status() also.
00044      */
00045     if (!IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_PREEDIT_ENABLED)) {
00046        st = iiimcf_toggle_preedit(pc, 1);
00047        if (st != IIIMF_STATUS_SUCCESS) return st;
00048     }
00049 
00050     pc->preedit_caret_position = pmes->v.preedit_draw.caret;
00051 
00052     IIIMCF_SET_STATE_CHANGE(pc, IIIMCF_STATE_PREEDIT_CHANGED);
00053 
00054     return iiimcf_store_simple_event(pc, IIIMCF_EVENT_TYPE_UI_PREEDIT_CHANGE);
00055 }
00056 
00057 IIIMF_status
00058 iiimcf_get_preedit_text(
00059     IIIMCF_context context,
00060     IIIMCF_text *ptext,
00061     int *pcaret_position
00062 )
00063 {
00064     IIIMCF_context_rec *pc = (IIIMCF_context_rec*) context;
00065 
00066     if (IIIMCF_IS_IC_INVALID(pc)) return IIIMF_STATUS_IC_INVALID;
00067     if ((!IIIMCF_IS_ENABLED(pc, IIIMCF_CONTEXT_PREEDIT_ENABLED))
00068        || (!IIIMCF_IS_VALID_TEXT(&pc->preedit_text)))
00069        return IIIMF_STATUS_NO_PREEDIT;
00070     
00071     *ptext = &pc->preedit_text;
00072     *pcaret_position = pc->preedit_caret_position;
00073 
00074     return IIIMF_STATUS_SUCCESS;
00075 }
00076 
00077 /* Local Variables: */
00078 /* c-file-style: "iiim-project" */
00079 /* End: */