Back to index

im-sdk  12.3.91
im-preedit-draw.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 
00005 #include <iiimp-data.h>
00006 #include <iiimp-opcode.h>
00007 
00008 #include "iiimp-dataP.h"
00009 
00010 
00011 IIIMP_message *
00012 iiimp_preedit_draw_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_card16     ic_id,
00016     IIIMP_int32             caret,
00017     IIIMP_int32             change_first,
00018     IIIMP_int32             change_length,
00019     IIIMP_contents * preedit)
00020 {
00021     IIIMP_message *  m;
00022     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00023     if (NULL == m) {
00024        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00025        return NULL;
00026     }
00027     m->opcode = IM_PREEDIT_DRAW;
00028     m->im_id = im_id;
00029     m->ic_id = ic_id;
00030     m->v.preedit_draw.caret = caret;
00031     m->v.preedit_draw.change_first = change_first;
00032     m->v.preedit_draw.change_length = change_length;
00033     m->v.preedit_draw.preedit = preedit;
00034     return m;
00035 }
00036 
00037 
00038 void
00039 iiimp_preedit_draw_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00040 {
00041     if (NULL == m) return;
00042     iiimp_contents_delete(data_s, m->v.preedit_draw.preedit);
00043     free(m);
00044     return;
00045 }
00046 
00047 
00048 uchar_t *
00049 iiimp_preedit_draw_pack(
00050     IIIMP_data_s *   data_s,
00051     IIIMP_card16     im_id,
00052     IIIMP_card16     ic_id,
00053     IIIMP_int32             caret,
00054     IIIMP_int32             change_first,
00055     IIIMP_int32             change_length,
00056     IIIMP_contents * preedit,
00057     size_t *         buf_size)
00058 {
00059     size_t           nbyte;
00060     int                     length;
00061     uchar_t *        buf;
00062     size_t           rest;
00063     uchar_t *        p;
00064 
00065     nbyte = 0;
00066     nbyte += 2;                    /* input method id */
00067     nbyte += 2;                    /* input context id */
00068     nbyte += 4;                    /* caret */
00069     nbyte += 4;                    /* change first */
00070     nbyte += 4;                    /* change length */
00071     nbyte += preedit->nbyte;       /* preedit string of text */
00072 
00073     length = (nbyte >> 2);
00074     *buf_size = (1 + 3 + nbyte);
00075 
00076     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00077     if (NULL == buf) {
00078        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00079        return NULL;
00080     }
00081 
00082     PUT_PACKET_HEADER(buf, IM_PREEDIT_DRAW, length);
00083 
00084     rest = nbyte;
00085     p = (buf + 4);
00086 
00087     PUTU16(im_id, rest, p, data_s->byte_swap);
00088     PUTU16(ic_id, rest, p, data_s->byte_swap);
00089     PUTU32(caret, rest, p, data_s->byte_swap);
00090     PUTU32(change_first, rest, p, data_s->byte_swap);
00091     PUTU32(change_length, rest, p, data_s->byte_swap);
00092     iiimp_contents_pack(data_s, preedit, &rest, &p);
00093 
00094     return buf;
00095 }
00096 
00097 
00098 IIIMP_message *
00099 iiimp_preedit_draw_unpack(
00100     IIIMP_data_s *   data_s,
00101     IIIMP_card7             opcode,
00102     size_t *         nbyte,
00103     const uchar_t ** ptr)
00104 {
00105     IIIMP_message *         m;
00106     IIIMP_preedit_draw_v *  v;
00107     size_t                  rest;
00108     const uchar_t *         p;
00109 
00110     rest = *nbyte;
00111     p = *ptr;
00112 
00113     if (rest < (2 + 2 + 4 + 4 + 4 + 4)) {
00114        data_s->status = IIIMP_DATA_INVALID;
00115        return NULL;
00116     }
00117 
00118     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00119     if (NULL == m) {
00120        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00121        return NULL;
00122     }
00123     v = &(m->v.preedit_draw);
00124 
00125     m->opcode = opcode;
00126 
00127     GETU16(m->im_id, rest, p, data_s->byte_swap);
00128     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00129     GET32(v->caret, rest, p, data_s->byte_swap);
00130     GET32(v->change_first, rest, p, data_s->byte_swap);
00131     GET32(v->change_length, rest, p, data_s->byte_swap);
00132 
00133     v->preedit = iiimp_contents_unpack(data_s, &rest, &p, rest);
00134     if (NULL == m) {
00135        free(m);
00136        return NULL;
00137     }
00138 
00139     *nbyte = rest;
00140     *ptr = p;
00141 
00142     return m;
00143 }
00144 
00145 
00146 void
00147 iiimp_preedit_draw_print(
00148     IIIMP_data_s *   data_s,
00149     IIIMP_message *  m)
00150 {
00151     IIIMP_preedit_draw_v *  v;
00152 
00153     v = &(m->v.preedit_draw);
00154     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00155     (void)fprintf(data_s->print_fp, "\tcaret=%d ", v->caret);
00156     (void)fprintf(data_s->print_fp, "change_first=%d ", v->change_first);
00157     (void)fprintf(data_s->print_fp, "change_length=%d\n", v->change_length);
00158     iiimp_contents_print(data_s, v->preedit);
00159 }
00160 
00161 
00162 /* Local Variables: */
00163 /* c-file-style: "iiim-project" */
00164 /* End: */