Back to index

im-sdk  12.3.91
input-context.c
Go to the documentation of this file.
00001 #include <stdlib.h>
00002 
00003 #include <iiimp.h>
00004 
00005 #include "input-method.h"
00006 #include "input-context.h"
00007 
00008 
00009 IIIMF_status
00010 iiimf_ic_new(IIIMF_im *            im,
00011             void *          client_data,
00012             IIIMF_ic **     ic_ret)
00013 {
00014     IIIMF_ic *       ic;
00015 
00016     if (NULL == im) return IIIMF_STATUS_IM_INVALID;
00017 
00018     ic = (IIIMF_ic *)malloc(sizeof (IIIMF_ic));
00019     if (NULL == ic) return IIIMF_STATUS_MALLOC;
00020 
00021     ic->ic_id = 0;
00022     ic->state = 0;
00023     ic->im = im;
00024     ic->language = NULL;
00025     ic->input_method = NULL;
00026     ic->language_list = NULL;
00027     ic->preedit_maximum_length = -1;
00028     ic->client_data = client_data;
00029     ic->next = im->ic_list;
00030     im->ic_list = ic;
00031 
00032     *ic_ret = ic;
00033     return IIIMF_STATUS_SUCCESS;
00034 }
00035 
00036 
00037 void
00038 iiimf_ic_delete(IIIMF_ic *  ic)
00039 {
00040     IIIMF_im *       im;
00041     IIIMF_ic *       p;
00042 
00043     im = ic->im;
00044 
00045     if (ic == im->ic_list) {
00046        im->ic_list = ic->next;
00047     } else {
00048        for (p = im->ic_list; NULL != p; p = p->next) {
00049            if (p->next == ic) {
00050               p->next = ic->next;
00051            }
00052        }
00053     }
00054 
00055     iiimp_string_list_delete(im->data_s, ic->language_list);
00056     free(ic);
00057 }
00058 
00059 
00060 IIIMF_status
00061 iiimf_ic_id_set(IIIMF_ic *  ic,
00062               int           ic_id)
00063 {
00064     ic->ic_id = ic_id;
00065     return IIIMF_STATUS_SUCCESS;
00066 }
00067 
00068 
00069 void *
00070 iiimf_ic_data_get(IIIMF_ic *       ic)
00071 {
00072     return ic->client_data;
00073 }
00074 
00075 
00076 void *
00077 iiimf_ic_data_set(
00078     IIIMF_ic *       ic,
00079     void *    client_data)
00080 {
00081     void *    p;
00082     p = ic->client_data;
00083     ic->client_data = client_data;
00084     return p;
00085 }
00086 
00087 
00088 IIIMF_status
00089 iiimf_ic_langauage_set(IIIMF_ic * ic, const char * language)
00090 {
00091     IIIMF_status     status;
00092     IIIMP_string *   p;
00093 
00094     if (NULL == language) {
00095        iiimp_string_delete(ic->im->data_s, ic->language);
00096        ic->language = NULL;
00097        return IIIMF_STATUS_SUCCESS;
00098     }
00099 
00100     status = iiimf_data_string_ascii_new(ic->im->data_s, language, &p);
00101     if (IIIMF_STATUS_SUCCESS != status) {
00102        return status;
00103     }
00104     iiimp_string_delete(ic->im->data_s, ic->language);
00105     ic->language = p;
00106 
00107     return IIIMF_STATUS_SUCCESS;
00108 }
00109 
00110 
00111 IIIMF_status
00112 iiimf_ic_input_method_set(IIIMF_ic * ic, const char * input_method)
00113 {
00114     IIIMF_status     status;
00115     IIIMP_string *   p;
00116 
00117     if (NULL == input_method) {
00118        iiimp_string_delete(ic->im->data_s, ic->input_method);
00119        ic->input_method = NULL;
00120        return IIIMF_STATUS_SUCCESS;
00121     }
00122 
00123     status = iiimf_data_string_ascii_new(ic->im->data_s, input_method, &p);
00124     if (IIIMF_STATUS_SUCCESS != status) {
00125        return status;
00126     }
00127     iiimp_string_delete(ic->im->data_s, ic->input_method);
00128     ic->input_method = p;
00129 
00130     return IIIMF_STATUS_SUCCESS;
00131 }
00132 
00133 
00134 IIIMF_status
00135 iiimf_ic_preedit_maximum_length_set(IIIMF_ic * ic, int preedit_maximum_length)
00136 {
00137     ic->preedit_maximum_length = preedit_maximum_length;
00138     return IIIMF_STATUS_SUCCESS;
00139 }
00140 
00141 
00142 int
00143 iiimf_ic_id(IIIMF_ic * ic)
00144 {
00145     return ic->ic_id;
00146 }
00147 
00148 
00149 /* Local Variables: */
00150 /* c-file-style: "iiim-project" */
00151 /* End: */