Back to index

im-sdk  12.3.91
composite_methods.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <X11/Xmd.h>
00003 #include <X11/Xlib.h>
00004 #include <gdk/gdkx.h>
00005 #include <gtk/gtk.h>
00006 
00007 #include "ime.h"
00008 #include "xaux_common.h"
00009 #include "xaux_ext_common.h"
00010 #include "le_aux_protocol.h"
00011 
00012 #include "common_aux_methods.h"
00013 #include "gtkiiimwin.h"
00014 
00015 extern Display *gDisplay;
00016 extern void* composite_aux;
00017 
00018 void composite_aux_Proc_LE_Show_Preedit_Notify(aux_ext_data_t * aux_ext_data);
00019 void composite_aux_Proc_LE_Hide_Preedit_Notify(aux_ext_data_t * aux_ext_data);
00020 void composite_aux_Proc_LE_Update_Preedit_Notify(aux_ext_data_t * aux_ext_data);
00021 void composite_aux_Proc_LE_Show_Candidates_Notify(aux_ext_data_t * aux_ext_data);
00022 void composite_aux_Proc_LE_Hide_Candidates_Notify(aux_ext_data_t * aux_ext_data);
00023 void composite_aux_Proc_LE_Update_Candidates_Notify(aux_ext_data_t * aux_ext_data);
00024 void composite_aux_Proc_LE_Change_Focus_Notify(aux_ext_data_t * aux_ext_data);
00025 void composite_aux_Proc_LE_Change_Option(aux_ext_data_t * aux_ext_data);
00026 void composite_aux_Proc_LE_Restore_Position(aux_ext_data_t * aux_ext_data);
00027 
00028 
00029 /* ================================================================= */
00030 /*       Process Notify information From Language Engine             */
00031 /* ================================================================= */
00032 void composite_aux_Proc_LE_Notify(aux_ext_data_t * aux_ext_data)
00033 {
00034     int nIntegerCount, notifyType;
00035 
00036     nIntegerCount = aux_ext_data->integer_count;
00037     if (nIntegerCount <= 0)
00038         return;
00039 
00040     notifyType = aux_ext_data->integer_list[0];
00041 
00042     switch (notifyType) {
00043     case COMMONAUX_SHOW_PREEDIT_NOTIFY:
00044         DEBUG_printf("COMMONAUX_SHOW_PREEDIT_NOTIFY Notify Received\n");
00045         composite_aux_Proc_LE_Show_Preedit_Notify(aux_ext_data);
00046         break;
00047     case COMMONAUX_HIDE_PREEDIT_NOTIFY:
00048         DEBUG_printf("COMMONAUX_HIDE_PREEDIT_NOTIFY Notify Received\n");
00049         composite_aux_Proc_LE_Hide_Preedit_Notify(aux_ext_data);
00050         break;
00051     case COMMONAUX_UPDATE_PREEDIT_NOTIFY:
00052         DEBUG_printf("COMMONAUX_UPDATE_PREEDIT_NOTIFY Notify Received\n");
00053         composite_aux_Proc_LE_Update_Preedit_Notify(aux_ext_data);
00054         break;
00055     case COMMONAUX_SHOW_CANDIDATES_NOTIFY:
00056         DEBUG_printf("COMMONAUX_SHOW_CANDIDATES_NOTIFY Notify Received\n");
00057         composite_aux_Proc_LE_Show_Candidates_Notify(aux_ext_data);
00058         break;
00059     case COMMONAUX_HIDE_CANDIDATES_NOTIFY:
00060         DEBUG_printf("COMMONAUX_HIDE_CANDIDATES_NOTIFY Notify Received\n");
00061         composite_aux_Proc_LE_Hide_Candidates_Notify(aux_ext_data);
00062         break;
00063     case COMMONAUX_UPDATE_CANDIDATES_NOTIFY:
00064         DEBUG_printf("COMMONAUX_UPDATE_CANDIDATES_NOTIFY Notify Received\n");
00065         composite_aux_Proc_LE_Update_Candidates_Notify(aux_ext_data);
00066         break;
00067     case COMPOSITE_PC_OPTION:
00068         DEBUG_printf("COMPOSITE_PC_OPTION Notify Received\n");
00069         composite_aux_Proc_LE_Change_Option(aux_ext_data);
00070         break;
00071     case COMPOSITE_PC_MOVE:
00072         DEBUG_printf("COMPOSITE_PC_MOVE Notify Received\n");
00073         composite_aux_Proc_LE_Restore_Position(aux_ext_data);
00074         break;
00075     }
00076 }
00077 
00078 void composite_aux_Proc_LE_Change_Option(aux_ext_data_t * aux_ext_data)
00079 {
00080     int cursor_x, cursor_y, cursor_w, cursor_h;
00081 
00082     DEBUG_printf("--------Composite aux style change--------\n");
00083     int nIntegerCount = aux_ext_data->integer_count;
00084     if (nIntegerCount != 1 + sizeof(TPCStyleOption)/sizeof(int) + 4) {
00085         DEBUG_printf("    XXXXXX: wrong composite update candidates protocol data\n");
00086         return;
00087     }
00088 
00089     recreateWindows(composite_aux, (TPCStyleOption*)(&aux_ext_data->integer_list[1]));
00090     if (isPCFollowCursor(composite_aux)) {
00091         composite_aux_get_cursor_rect(aux_ext_data, &cursor_x, &cursor_y, &cursor_w, &cursor_h);
00092         movePreedit(composite_aux, cursor_x, cursor_y, cursor_w, cursor_h);
00093     } else {
00094         movePreedit(composite_aux,
00095             aux_ext_data->integer_list[sizeof(TPCStyleOption)/sizeof(int) + 1],
00096             aux_ext_data->integer_list[sizeof(TPCStyleOption)/sizeof(int) + 2],
00097             aux_ext_data->integer_list[sizeof(TPCStyleOption)/sizeof(int) + 3],
00098             aux_ext_data->integer_list[sizeof(TPCStyleOption)/sizeof(int) + 4]);
00099     }
00100 }
00101 
00102 
00103 void composite_aux_Proc_LE_Show_Preedit_Notify(aux_ext_data_t * aux_ext_data)
00104 {
00105     int cursor_x, cursor_y, cursor_w, cursor_h;
00106 
00107     if (isPCFollowCursor(composite_aux)) {
00108         composite_aux_get_cursor_rect(aux_ext_data, &cursor_x, &cursor_y, &cursor_w, &cursor_h);
00109         movePreedit(composite_aux, cursor_x, cursor_y, cursor_w, cursor_h);
00110     }
00111     showPreedit(composite_aux);
00112 }
00113 
00114 void composite_aux_Proc_LE_Hide_Preedit_Notify(aux_ext_data_t * aux_ext_data)
00115 {
00116     hidePreedit(composite_aux);
00117 }
00118 
00119 void composite_aux_Proc_LE_Restore_Position(aux_ext_data_t * aux_ext_data)
00120 {
00121     if (aux_ext_data->integer_count != 5) {
00122         DEBUG_printf("    XXXXXX: wrong restore preedit position protocol data\n");
00123         return;
00124     }
00125 
00126     if (!isPCFollowCursor(composite_aux)) {
00127         movePreedit(composite_aux,
00128                     aux_ext_data->integer_list[1],
00129                     aux_ext_data->integer_list[2],
00130                     aux_ext_data->integer_list[3],
00131                     aux_ext_data->integer_list[4]);
00132     }
00133 }
00134 
00135 void composite_aux_Proc_LE_Update_Preedit_Notify(aux_ext_data_t * aux_ext_data)
00136 {
00137     int   nIntegerCount;
00138     int   nStringsCount;
00139     char *preedit_str;
00140     int   preedit_len;
00141     int   caret, cl_start;
00142 
00143     int cursor_x, cursor_y, cursor_w, cursor_h;
00144 
00145     nIntegerCount = aux_ext_data->integer_count;
00146     nStringsCount = aux_ext_data->string_count;
00147 
00148     if (((nIntegerCount -3)/4 * 4 != nIntegerCount-3) || (nStringsCount != 1)) {
00149         DEBUG_printf("XXXXXX-------XXXXXXX: wrong composite update preedit protocol data\n");
00150         return;
00151     }
00152 
00153     preedit_str = (char *)aux_ext_data->string_list[0].ptr;
00154     preedit_len = strlen(preedit_str);
00155     caret       = aux_ext_data->integer_list[1];
00156     cl_start    = aux_ext_data->integer_list[2];
00157 
00158     DEBUG_printf("composite_aux_Proc_LE_Update_Preedit_Notify: \n");
00159     DEBUG_printf("   preedit_str: %s\n", preedit_str);
00160     DEBUG_printf("   preedit_len: %d\n", preedit_len);
00161     DEBUG_printf("   caret: %d\n", caret);
00162 
00163     int i, nfbs = (nIntegerCount-3)/4;
00164     /*
00165     ImeFeedbackRec fbs[nfbs];
00166 
00167     for (i=0; i < nfbs; ++i) {
00168         fbs[i].type     = aux_ext_data->integer_list[4*i+3+0];
00169         fbs[i].value    = aux_ext_data->integer_list[4*i+3+1];
00170         fbs[i].start    = aux_ext_data->integer_list[4*i+3+2];
00171         fbs[i].length   = aux_ext_data->integer_list[4*i+3+3];
00172     }
00173     */
00174 
00175    if (isPCFollowCursor(composite_aux)) {
00176         composite_aux_get_cursor_rect(aux_ext_data, &cursor_x, &cursor_y, &cursor_w, &cursor_h);
00177         movePreedit(composite_aux, cursor_x, cursor_y, cursor_w, cursor_h);
00178     }
00179 
00180     updatePreedit(composite_aux, preedit_str, caret, cl_start, nfbs, /*fbs*/(ImeFeedbackRec*)(aux_ext_data->integer_list+3));
00181     return;
00182 }
00183 
00184 void composite_aux_Proc_LE_Show_Candidates_Notify(aux_ext_data_t * aux_ext_data)
00185 {
00186     showCandidates(composite_aux);
00187 }
00188 
00189 void composite_aux_Proc_LE_Hide_Candidates_Notify(aux_ext_data_t * aux_ext_data)
00190 {
00191     hideCandidates(composite_aux);
00192 }
00193 
00194 /******************************************************************************
00195 * IntegerList:
00196 *     protocal_id
00197 *     candidates_count    --->  n
00198 *     page_states
00199 *     focus_in_window
00200 *     n * feedback_count for each candidates
00201 *     feedbacks for candidates[1]
00202 *     ......
00203 *****************************************************************************/
00204 void composite_aux_Proc_LE_Update_Candidates_Notify(aux_ext_data_t * aux_ext_data)
00205 {
00206     int  nIntegerCount;
00207     int  nStringsCount;
00208     int  i, num_candidates, page_state, candi_current, candi_total, candi_first = 0;
00209     const char*candidates[126];
00210 
00211 
00212     nIntegerCount = aux_ext_data->integer_count;
00213     if (nIntegerCount < 4) {
00214         DEBUG_printf("    XXXXXX: wrong composite update candidates protocol data\n");
00215         return;
00216     }
00217 
00218     nStringsCount = aux_ext_data->string_count;
00219     if (nStringsCount < 0)
00220         return;
00221 
00222     num_candidates = aux_ext_data->integer_list[1];
00223     if (num_candidates > 126)
00224         num_candidates = 126;
00225 
00226     page_state = aux_ext_data->integer_list[2];
00227     candi_total = candi_current = aux_ext_data->integer_list[3];
00228     if ((page_state & 0x1) == 0)  {// not first page
00229         candi_first += 10;
00230         candi_total += 10;
00231     }
00232     if ((page_state & 0x2) == 0) // not last page
00233         candi_total += 10;
00234 
00235     int * p_fb_counts = (aux_ext_data->integer_list + 4);
00236     ImeFeedbackRec * pfbs[num_candidates], *p;
00237 
00238     p = (ImeFeedbackRec*)(aux_ext_data->integer_list + 4 + num_candidates);
00239     for (i= 0; i < num_candidates; i++) {
00240         candidates[i] = (char *)aux_ext_data->string_list[i].ptr;
00241         DEBUG_printf("candidates[%d]: %s\n", i, candidates[i]);
00242         pfbs[i] = p;
00243         p += p_fb_counts[i];
00244     }
00245 
00246     DEBUG_printf("composite_aux_Proc_LE_Update_Candidates_Notify: \n");
00247     DEBUG_printf("   num_candidates: %d\n", num_candidates);
00248 
00249     updateCandidates(composite_aux, num_candidates, candidates, NULL, candi_first, candi_current, candi_total, p_fb_counts, pfbs);
00250 
00251     return;
00252 }
00253 
00254 /******************************************************************************
00255 * Sending message to LE
00256 ******************************************************************************/
00257 void composite_aux_send_option_change(TPCStyleOption *poptions)
00258 {
00259     int nIntegerCount =  1+sizeof(TPCStyleOption)/sizeof(int);
00260     int pIntegerList[nIntegerCount];
00261 
00262     pIntegerList[0] = COMPOSITE_PC_OPTION;
00263     *(TPCStyleOption*)(pIntegerList+1) = *poptions;
00264 
00265     NotifyIntegerListDataToLanguageEngine(gDisplay, nIntegerCount, pIntegerList);
00266 }
00267 
00268 void composite_aux_send_candidate_selection(int idx)
00269 {
00270     int nIntegerCount = 2;
00271     int pIntegerList[nIntegerCount];
00272 
00273     pIntegerList[0] = COMPOSITE_PC_CANDIDATE_SELECTION;
00274     pIntegerList[1] = idx;
00275 
00276     NotifyIntegerListDataToLanguageEngine(gDisplay, nIntegerCount, pIntegerList);
00277 }
00278 
00279 void composite_aux_send_candidate_page(int pgop)
00280 {
00281     int nIntegerCount = 2;
00282     int pIntegerList[nIntegerCount];
00283 
00284     pIntegerList[0] = COMPOSITE_PC_CANDIDATE_PAGE;
00285     pIntegerList[1] = pgop;
00286 
00287     NotifyIntegerListDataToLanguageEngine(gDisplay, nIntegerCount, pIntegerList);
00288 }
00289 
00290 
00291 void composite_aux_send_move(int cursor_x, int cursor_y, int cursor_w, int cursor_h)
00292 {
00293     int nIntegerCount = 5;
00294     int pIntegerList[nIntegerCount];
00295 
00296     pIntegerList[0] = COMPOSITE_PC_MOVE;
00297     pIntegerList[1] = cursor_x;
00298     pIntegerList[2] = cursor_y;
00299     pIntegerList[3] = cursor_w;
00300     pIntegerList[4] = cursor_h;
00301 
00302     NotifyIntegerListDataToLanguageEngine(gDisplay, nIntegerCount, pIntegerList);
00303 }
00304