Back to index

im-sdk  12.3.91
R6IMProtocol.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include "R6IMProtocol.hh"
00043 #include "IMTrans.hh"
00044 #include "CompoundString.hh"
00045 #include "XInputContext.hh"
00046 #ifdef DEBUG
00047 #include <stdio.h>
00048 #endif
00049 #include "XIC_Interface.h"
00050 
00051 #include "Xi18n.h"
00052 
00053 IMList <XIMPublic> ximp_list;
00054 IMList<XInputContext> xic_list;
00055 
00056 int
00057 R6IMProtocol::getICID(XInputContext *ic) {
00058   return xic_list.getIndex(ic);
00059 }
00060 
00061 R6IMProtocol::
00062 R6IMProtocol(IMArg *args, int args_count) : XIMPublic(args, args_count) {
00063   ims = 0;
00064   protocol_name = "R6IMP";
00065   thread = NULL;
00066 }
00067 
00068 R6IMProtocol::
00069 ~R6IMProtocol() {
00070 
00071   delete start_keys.keylist;
00072   delete stop_keys.keylist;
00073   delete thread;
00074 }
00075 
00076 /* Supported Input Method list */
00077 static XIMListOfAttr IMValues[] = {
00078     {XNQueryInputStyle, XimType_XIMStyles, 1},
00079     {(char *)NULL, (CARD16)0, (CARD16)0}
00080 };
00081 
00082 /* definitions of IC attribute identifiers. */
00083 #define              XIC_INPUT_STYLE             1
00084 #define              XIC_CLIENT_WINDOW    2
00085 #define              XIC_FOCUS_WINDOW     3
00086 #define              XIC_FILTER_EVENTS    4
00087 #define              XIC_PREEDIT_ATTR     5
00088 #define              XIC_STATUS_ATTR             6
00089 #define              XIC_FONTSET          7
00090 #define              XIC_AREA             8
00091 #define              XIC_AREA_NEEDED             9
00092 #define              XIC_COLORMAP         10
00093 #define              XIC_STD_COLORMAP     11
00094 #define              XIC_FOREGROUND              12
00095 #define              XIC_BACKGROUND              13
00096 #define              XIC_BACKGROUND_PIXMAP       14
00097 #define              XIC_SPOTLOCATION     15
00098 #define              XIC_LINESPACE        16
00099 #define              XIC_PREEDIT_STATE    17
00100 #define              XIC_FONTNAME         18
00101 #define              XIC_CURSOR           19
00102 
00103 /* Supported Input Context list */
00104 static XIMListOfAttr ICValues[] = {
00105     {XNInputStyle, XimType_CARD32, XIC_INPUT_STYLE},
00106     {XNClientWindow, XimType_Window,      XIC_CLIENT_WINDOW},
00107     {XNFocusWindow, XimType_Window,       XIC_FOCUS_WINDOW},
00108     {XNFilterEvents, XimType_CARD32,      XIC_FILTER_EVENTS},
00109     {XNPreeditAttributes, XimType_NEST, XIC_PREEDIT_ATTR},
00110     {XNStatusAttributes, XimType_NEST,    XIC_STATUS_ATTR},
00111     {XNFontSet, XimType_XFontSet,  XIC_FONTSET},
00112     {XNArea, XimType_XRectangle,   XIC_AREA},
00113     {XNAreaNeeded, XimType_XRectangle,    XIC_AREA_NEEDED},
00114     {XNColormap, XimType_CARD32,   XIC_COLORMAP},
00115     {XNStdColormap, XimType_CARD32,       XIC_STD_COLORMAP},
00116     {XNForeground, XimType_CARD32, XIC_FOREGROUND},
00117     {XNBackground, XimType_CARD32, XIC_BACKGROUND},
00118     {XNBackgroundPixmap, XimType_CARD32,XIC_BACKGROUND_PIXMAP},
00119     {XNSpotLocation, XimType_XPoint,      XIC_SPOTLOCATION},
00120     {XNLineSpace, XimType_CARD32,  XIC_LINESPACE},
00121     {XNPreeditState, XimType_CARD32,      XIC_PREEDIT_STATE},
00122     {(char *)NULL, (CARD16)0, (CARD16)0}
00123 };
00124 
00125 static XIMStyle  my_styles[] = {
00126        XIMPreeditCallbacks | XIMStatusCallbacks,
00127        XIMPreeditCallbacks | XIMStatusArea,
00128        XIMPreeditCallbacks | XIMStatusNothing,
00129        XIMPreeditCallbacks | XIMStatusNone,
00130        XIMPreeditPosition  | XIMStatusCallbacks,
00131        XIMPreeditPosition  | XIMStatusArea,
00132        XIMPreeditPosition  | XIMStatusNothing,
00133        XIMPreeditPosition  | XIMStatusNone,
00134        XIMPreeditArea           | XIMStatusCallbacks,
00135        XIMPreeditArea      | XIMStatusArea,
00136        XIMPreeditArea      | XIMStatusNothing,
00137        XIMPreeditArea      | XIMStatusNone,
00138        XIMPreeditNothing   | XIMStatusCallbacks,
00139        XIMPreeditNothing   | XIMStatusArea,
00140        XIMPreeditNothing   | XIMStatusNothing,
00141         XIMPreeditNothing   | XIMStatusNone,
00142        XIMPreeditNone           | XIMStatusCallbacks,
00143        XIMPreeditNone      | XIMStatusArea,
00144        XIMPreeditNone      | XIMStatusNothing,
00145        XIMPreeditNone           | XIMStatusNone
00146 };
00147 
00148 /* styles for disable_status_area */
00149 static XIMStyle my_styles2[] = {
00150   XIMPreeditCallbacks | XIMStatusNone,
00151   XIMPreeditPosition  | XIMStatusNone,
00152   XIMPreeditArea      | XIMStatusNone,
00153   XIMPreeditNothing   | XIMStatusNone,
00154   XIMPreeditNone      | XIMStatusNone
00155 };
00156 
00157 int
00158 R6IMProtocol::run() {
00159   XIMArg args[20];
00160   int ret;
00161   extern IMMethodsRec Xi18n_im_methods;
00162 
00163   if (display == 0) {
00164     // nothing to do
00165 #ifdef DEBUG
00166     fprintf(stderr, "   Error - No XDisplay connection\n");
00167     fprintf(stderr, "       X11R6IM cannot be used\n");
00168 #endif
00169     return -1;
00170   }
00171 
00172   IMTriggerKey keyp;
00173   XIMTriggerKey *trigger_keyp;
00174   int i;
00175 
00176   start_keys.count_keys = on_keys.count();
00177   start_keys.keylist = new XIMTriggerKey[start_keys.count_keys];
00178   trigger_keyp = start_keys.keylist;
00179   for (i = 0; i < start_keys.count_keys; i++, trigger_keyp++) {
00180     keyp = on_keys.getKey(i+1);
00181     trigger_keyp->modifier = keyp.get_modifier();
00182     trigger_keyp->modifier_mask = keyp.get_modifier_mask();
00183     trigger_keyp->keysym = keyp.get_keyCode();
00184   }
00185   stop_keys.count_keys = off_keys.count();
00186   stop_keys.keylist = new XIMTriggerKey[stop_keys.count_keys];
00187   trigger_keyp = stop_keys.keylist;
00188   for (i = 0; i < stop_keys.count_keys; i++, trigger_keyp++) {
00189     keyp = on_keys.getKey(i+1);
00190     trigger_keyp->modifier = keyp.get_modifier();
00191     trigger_keyp->modifier_mask = keyp.get_modifier_mask();
00192     trigger_keyp->keysym = keyp.get_keyCode();
00193   }
00194 
00195   if (display) {
00196     screen = DefaultScreen(display);
00197     im_window = XCreateSimpleWindow(display,
00198                                 DefaultRootWindow(display),
00199                                 0, 0, 1, 1, 1, 0, 0);
00200   }
00201 
00202   XIMStyles styles;
00203   styles.count_styles = sizeof(my_styles)/sizeof(XIMStyle);
00204   styles.supported_styles = &my_styles[0];
00205 
00206   if (disable_status_area == True){
00207     styles.count_styles = sizeof(my_styles2)/sizeof(XIMStyle);
00208     styles.supported_styles = &my_styles2[0];
00209   }
00210 
00211   unsigned long filter_events = KeyPressMask | KeyReleaseMask;
00212 
00213   int n = 0;
00214   args[n].name = (char*)IMServerName; args[n].value = im_name; n++;
00215   args[n].name = (char*)IMServerWindow; args[n].value = (char*)im_window; n++;
00216   args[n].name = (char*)IMLocale; args[n].value = input_locale; n++;
00217   args[n].name = (char*)IMServerTransport; args[n].value = im_address; n++;
00218   args[n].name = (char*)IMOnKeysList; args[n].value = (char*)&start_keys; n++;
00219   args[n].name = (char*)IMOffKeysList; args[n].value = (char*)&stop_keys; n++;
00220   args[n].name = (char*)IMInputStyles; args[n].value = (char*)&styles; n++;
00221 
00222   args[n].name = (char*)IMSupportedICValues; args[n].value = (char*)ICValues; n++;
00223   args[n].name = (char*)IMSupportedIMValues; args[n].value = (char*)IMValues; n++;
00224   args[n].name = (char*)IMFilterEventMask; args[n].value = (char*)filter_events; n++;
00225 #if 0
00226   args[n].name = (char*)IMProtocolHandler;       &r6_proto_callback,
00227 #endif
00228   args[n].name = 0; args[n].value = 0;
00229 
00230   ims = new XIMProtocolRec;
00231   memset(ims, 0, sizeof(XIMProtocolRec));
00232   ims->methods = &Xi18n_im_methods;
00233   ims->core.display = display;
00234   ims->protocol = (*ims->methods->setup)(display, args);
00235 
00236   OpenIM();
00237 
00238   ret = (ims->methods->openIM)(ims);
00239 
00240   ximp_list.addItem(this);
00241   ims->id = ximp_list.getIndex(this);
00242 
00243   if (thread == NULL)
00244     thread = new IMThread(xevent_loop, this);
00245 
00246   return 0;
00247 }
00248 
00249 void*
00250 R6IMProtocol::xevent_loop(void* client_data) {
00251   R6IMProtocol *ximp_protocol = (R6IMProtocol*)client_data;
00252   for (;;) {
00253     XEvent event;
00254     XNextEvent(ximp_protocol->display, &event);
00255     if (XFilterEvent(&event, 0) == True)
00256       continue;
00257     switch (event.type) {
00258     case ClientMessage:
00259     default:
00260       break;
00261     }
00262   }
00263   return 0;
00264 }
00265 
00266 extern "C" {
00267   int
00268   CreateXIC(XIMS ims,
00269            CARD16 connect_id,
00270            CARD16 preedit_attr_num,
00271            CARD16 status_attr_num,
00272            CARD16 ic_attr_num,
00273            XICAttribute *preedit_attr,
00274            XICAttribute *status_attr,
00275            XICAttribute *ic_attr) {
00276     int id = ims->id;
00277     XIMPublic *ximp = &(ximp_list.getItem(id));
00278     char *ret = NULL;
00279 
00280     CARD32 input_style = 0;
00281     // get input_style from ic_attr
00282     XICAttribute *icp;
00283     for (icp = ic_attr; icp < &ic_attr[ic_attr_num]; icp++) {
00284       if (!strcmp(icp->name, XNInputStyle)) {
00285        input_style = (*(CARD32*)icp->value);
00286        break;
00287       }
00288     }
00289     if (input_style == 0) {
00290       // something is wrong
00291       return -1;
00292     }
00293     XInputContext *ic = new XInputContext((XIMPublic*)ximp,
00294                                      connect_id,
00295                                      input_style);
00296     xic_list.addItem(ic);
00297     int ic_id = xic_list.getIndex(ic);
00298 
00299     ret = SetICValues(ic_id,
00300                     preedit_attr_num, status_attr_num, ic_attr_num,
00301                     preedit_attr, status_attr, ic_attr);
00302     return ic_id;
00303   }
00304   char* GetICValues(int icid,
00305                   CARD16 preedit_attr_num,
00306                   CARD16 status_attr_num,
00307                   CARD16 ic_attr_num,
00308                   XICAttribute *preedit_attr,
00309                   XICAttribute *status_attr,
00310                   XICAttribute *ic_attr) {
00311     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00312   
00313     // set ic_attr
00314     XICAttribute *icp;
00315     for (icp = ic_attr; icp < &ic_attr[ic_attr_num]; icp++) {
00316       // tcl/tk ja patch requires XNInputStyle in XGetICValues()
00317       if (!strcmp(icp->name, XNInputStyle)) {
00318        icp->value = new CARD32;
00319        ic->get_input_style((*(CARD32*)icp->value));
00320        icp->value_length = sizeof(CARD32);
00321       }
00322       if (!strcmp(icp->name, XNClientWindow)) {
00323        Window tmp;
00324        icp->value = new CARD32;
00325        ic->get_client_window(tmp);
00326        *(CARD32*)icp->value = (CARD32)tmp;
00327        icp->value_length = sizeof(CARD32);
00328       }
00329       else if (!strcmp(icp->name, XNFocusWindow)) {
00330        Window tmp;
00331        icp->value = new CARD32;
00332        ic->get_focus_window(tmp);
00333        *(CARD32*)icp->value = (CARD32)tmp;
00334        icp->value_length = sizeof(CARD32);
00335       }
00336       else if (!strcmp(icp->name, XNFilterEvents)) {
00337        icp->value = new CARD32;
00338        ic->get_fwin_select_mask((*(CARD32*)icp->value));
00339 
00340        /* This hack is to let gtk+ based client to filter key release event to
00341         * the XIM server (gnome bugzilla #81759)
00342         */
00343        if (!(*(CARD32*)icp->value & KeyReleaseMask))
00344          *(CARD32*)icp->value |= KeyReleaseMask;
00345 
00346        icp->value_length = sizeof(CARD32);
00347       }
00348       else if (!strcmp(icp->name, XNPreeditState)) {
00349        icp->value = new CARD32;
00350        (*(CARD32*)icp->value) = (ic->is_conv_state()) ?
00351          XIMPreeditEnable : XIMPreeditDisable;
00352        icp->value_length = sizeof(CARD32);
00353       }
00354     }
00355     // get preedit_attr
00356     for (icp = preedit_attr; icp < &preedit_attr[preedit_attr_num]; icp++) {
00357       if (!strcmp(icp->name, XNFontSet)) {
00358        char *ret = 0;
00359        ic->get_preedit_fontset(ret);
00360        icp->value = strdup(ret);
00361        icp->value_length = strlen(ret);
00362       }
00363       else if (!strcmp(icp->name, XNPreeditState)) {
00364        icp->value = new CARD32;
00365        (*(CARD32*)icp->value) = (ic->is_conv_state()) ?
00366          XIMPreeditEnable : XIMPreeditDisable;
00367        icp->value_length = sizeof(CARD32);
00368       }
00369       else if (!strcmp(icp->name, XNArea)) {
00370        icp->value = new XRectangle;
00371        long x = 0, y = 0;
00372        unsigned long width = 0, height = 0;
00373        ic->get_preedit_area(x, y, width, height);
00374        XRectangle rect;
00375        rect.x = x; rect.y = y; rect.width = width;
00376        rect.height = height;
00377        (*(XRectangle*)icp->value) = rect;
00378        icp->value_length = sizeof(XRectangle);
00379       }
00380       else if (!strcmp(icp->name, XNAreaNeeded)) {
00381        icp->value = new XRectangle;
00382        long x = 0, y = 0;
00383        unsigned long width = 0, height = 0;
00384        ic->get_preedit_area_needed(x, y, width, height);
00385        XRectangle rect;
00386        rect.x = x; rect.y = y; rect.width = width;
00387        rect.height = height;
00388        (*(XRectangle*)icp->value) = rect;
00389        icp->value_length = sizeof(XRectangle);
00390       }
00391       else if (!strcmp(icp->name, XNSpotLocation)) {
00392        icp->value = new XPoint;
00393        long x = 0, y = 0;
00394        ic->get_preedit_spot_location(x, y);
00395        XPoint point;
00396        point.x = x; point.y = y;
00397        (*(XPoint*)icp->value) = point;
00398        icp->value_length = sizeof(XPoint);
00399       }
00400       else if (!strcmp(icp->name, XNForeground)) {
00401        icp->value = new CARD32;
00402        ic->get_preedit_fg(*(CARD32*)icp->value);
00403        icp->value_length = sizeof(CARD32);
00404       }
00405       else if (!strcmp(icp->name, XNBackground)) {
00406        icp->value = new CARD32;
00407        ic->get_preedit_bg(*(CARD32*)icp->value);
00408        icp->value_length = sizeof(CARD32);
00409       }
00410       else if (!strcmp(icp->name, XNBackgroundPixmap)) {
00411        icp->value = new Pixmap;
00412        ic->get_preedit_bg_pixmap(*(Pixmap*)icp->value);
00413        icp->value_length = sizeof(Pixmap);
00414       }
00415       else if (!strcmp(icp->name, XNLineSpace)) {
00416        icp->value = new CARD32;
00417        ic->get_preedit_line_spacing(*(CARD32*)icp->value);
00418        icp->value_length = sizeof(CARD32);
00419       }
00420       else if (!strcmp(icp->name, XNCursor)) {
00421        icp->value = new Cursor;
00422        ic->get_preedit_cursor(*(Cursor*)icp->value);
00423        icp->value_length = sizeof(Cursor);
00424       }
00425       else if (!strcmp(icp->name, XNColormap)) {
00426        icp->value = new Colormap;
00427        ic->get_preedit_colormap(*(Colormap*)icp->value);
00428        icp->value_length = sizeof(Colormap);
00429       }
00430     }
00431     // get status_attr
00432     for (icp = status_attr; icp < &status_attr[status_attr_num]; icp++) {
00433       if (!strcmp(icp->name, XNFontSet)) {
00434        char *ret = 0;
00435        ic->get_status_fontset(ret);
00436        icp->value = strdup(ret);
00437        icp->value_length = strlen(ret);
00438       }
00439       else if (!strcmp(icp->name, XNArea)) {
00440        icp->value = new XRectangle;
00441        long x = 0, y = 0;
00442        unsigned long width = 0, height = 0;
00443        ic->get_status_area(x, y, width, height);
00444        XRectangle rect;
00445        rect.x = x; rect.y = y; rect.width = width;
00446        rect.height = height;
00447        (*(XRectangle*)icp->value) = rect;
00448        icp->value_length = sizeof(XRectangle);
00449       }
00450       else if (!strcmp(icp->name, XNAreaNeeded)) {
00451        icp->value = new XRectangle;
00452        long x = 0, y = 0;
00453        unsigned long width = 0, height = 0;
00454        ic->get_status_area_needed(x, y, width, height);
00455        XRectangle rect;
00456        rect.x = x; rect.y = y; rect.width = width;
00457        rect.height = height;
00458        (*(XRectangle*)icp->value) = rect;
00459        icp->value_length = sizeof(XRectangle);
00460       }
00461       else if (!strcmp(icp->name, XNForeground)) {
00462        icp->value = new CARD32;
00463        ic->get_status_fg(*(CARD32*)icp->value);
00464        icp->value_length = sizeof(CARD32);
00465       }
00466       else if (!strcmp(icp->name, XNBackground)) {
00467        icp->value = new CARD32;
00468        ic->get_status_bg(*(CARD32*)icp->value);
00469        icp->value_length = sizeof(CARD32);
00470       }
00471       else if (!strcmp(icp->name, XNBackgroundPixmap)) {
00472        icp->value = new Pixmap;
00473        ic->get_status_bg_pixmap(*(Pixmap*)icp->value);
00474        icp->value_length = sizeof(Pixmap);
00475       }
00476       else if (!strcmp(icp->name, XNLineSpace)) {
00477        icp->value = new CARD32;
00478        ic->get_status_line_spacing(*(CARD32*)icp->value);
00479        icp->value_length = sizeof(CARD32);
00480       }
00481       else if (!strcmp(icp->name, XNCursor)) {
00482        icp->value = new Cursor;
00483        ic->get_status_cursor(*(Cursor*)icp->value);
00484        icp->value_length = sizeof(Cursor);
00485       }
00486       else if (!strcmp(icp->name, XNColormap)) {
00487        icp->value = new Colormap;
00488        ic->get_status_colormap(*(Colormap*)icp->value);
00489        icp->value_length = sizeof(Colormap);
00490       }
00491     }
00492     return (char*)0;
00493   }
00494 
00495   void
00496   FreeICAttrNames(
00497         CARD16 preedit_attr_num,
00498         CARD16 status_attr_num,
00499         CARD16 ic_attr_num,
00500         XICAttribute *preedit_attr,
00501         XICAttribute *status_attr,
00502         XICAttribute *ic_attr)
00503   {
00504     XICAttribute *icp;
00505     for (icp = ic_attr; icp < &ic_attr[ic_attr_num]; icp++) {
00506           if(icp->name_length && icp->name) XFree(icp->name);
00507     }
00508     for (icp = preedit_attr; icp < &preedit_attr[preedit_attr_num]; icp++) {
00509           if(icp->name_length && icp->name) XFree(icp->name);
00510     }
00511     for (icp = status_attr; icp < &status_attr[status_attr_num]; icp++) {
00512           if(icp->name_length && icp->name) XFree(icp->name);
00513     }
00514   }
00515 
00516   void
00517   FreeICAttrValues(
00518         CARD16 preedit_attr_num,
00519         CARD16 status_attr_num,
00520         CARD16 ic_attr_num,
00521         XICAttribute *preedit_attr,
00522         XICAttribute *status_attr,
00523         XICAttribute *ic_attr)
00524   {
00525     XICAttribute *icp;
00526     for (icp = ic_attr; icp < &ic_attr[ic_attr_num]; icp++) {
00527           if(icp->value_length && icp->value) XFree(icp->value);
00528     }
00529     for (icp = preedit_attr; icp < &preedit_attr[preedit_attr_num]; icp++) {
00530           if(icp->value_length && icp->value) XFree(icp->value);
00531     }
00532     for (icp = status_attr; icp < &status_attr[status_attr_num]; icp++) {
00533           if(icp->value_length && icp->value) XFree(icp->value);
00534     }
00535   }
00536   char* SetICValues(int icid,
00537                   CARD16 preedit_attr_num,
00538                   CARD16 status_attr_num,
00539                   CARD16 ic_attr_num,
00540                   XICAttribute *preedit_attr,
00541                   XICAttribute *status_attr,
00542                   XICAttribute *ic_attr) {
00543     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00544   
00545     // set ic_attr
00546     XICAttribute *icp;
00547     for (icp = ic_attr; icp < &ic_attr[ic_attr_num]; icp++) {
00548       if (!strcmp(icp->name, XNClientWindow)) {
00549        ic->set_client_window((*(Window*)icp->value));
00550       }
00551       else if (!strcmp(icp->name, XNFocusWindow)) {
00552        ic->set_focus_window((*(Window*)icp->value));
00553       }
00554       else if (!strcmp(icp->name, XNFilterEvents)) {
00555        ic->set_fwin_select_mask(*(CARD32*)icp->value);
00556       }
00557       else if (!strcmp(icp->name, XNPreeditState)) {
00558         int *state=(int*)icp->value;
00559        if (*state == XIMPreeditEnable) {
00560          ic->conversion_start(True);
00561        }
00562        if (*state == XIMPreeditDisable) {
00563          ic->conversion_end(True);
00564        }
00565       }
00566     }
00567     // set preedit_attr
00568     for (icp = preedit_attr; icp < &preedit_attr[preedit_attr_num]; icp++) {
00569       if (!strcmp(icp->name, XNFontSet)) {
00570        ic->set_preedit_fontset((char*)icp->value);
00571       }
00572       else if (!strcmp(icp->name, XNPreeditState)) {
00573         int *state=(int*)icp->value;
00574        if (*state == XIMPreeditEnable) {
00575          ic->conversion_start(True);
00576        }
00577        if (*state == XIMPreeditDisable) {
00578          ic->conversion_end(True);
00579        }
00580       }
00581       else if (!strcmp(icp->name, XNArea)) {
00582        XRectangle *rect = (XRectangle*)icp->value;
00583        ic->set_preedit_area(rect->x, rect->y, rect->width, rect->height);
00584       }
00585       else if (!strcmp(icp->name, XNAreaNeeded)) {
00586        XRectangle *rect = (XRectangle*)icp->value;
00587        ic->set_preedit_area_needed(rect->width, rect->height);
00588       }
00589       else if (!strcmp(icp->name, XNSpotLocation)) {
00590        XPoint *point = (XPoint*)icp->value;
00591        ic->set_preedit_spot_location(point->x, point->y);
00592       }
00593       else if (!strcmp(icp->name, XNForeground)) {
00594        ic->set_preedit_fg((*(CARD32*)icp->value));
00595       }
00596       else if (!strcmp(icp->name, XNBackground)) {
00597        ic->set_preedit_bg((*(CARD32*)icp->value));
00598       }
00599       else if (!strcmp(icp->name, XNBackgroundPixmap)) {
00600        ic->set_preedit_bg_pixmap((*(Pixmap*)icp->value));
00601       }
00602       else if (!strcmp(icp->name, XNLineSpace)) {
00603        ic->set_preedit_line_spacing((*(CARD32*)icp->value));
00604       }
00605       else if (!strcmp(icp->name, XNCursor)) {
00606        ic->set_preedit_cursor((*(Cursor*)icp->value));
00607       }
00608       else if (!strcmp(icp->name, XNColormap)) {
00609        ic->set_preedit_colormap((*(Colormap*)icp->value));
00610       }
00611     }
00612     // set status_attr
00613     for (icp = status_attr; icp < &status_attr[status_attr_num]; icp++) {
00614       if (!strcmp(icp->name, XNFontSet)) {
00615        ic->set_status_fontset((char*)icp->value);
00616       }
00617       else if (!strcmp(icp->name, XNArea)) {
00618        XRectangle *rect = (XRectangle*)icp->value;
00619        ic->set_status_area(rect->x, rect->y, rect->width, rect->height);
00620       }
00621       else if (!strcmp(icp->name, XNAreaNeeded)) {
00622        XRectangle *rect = (XRectangle*)icp->value;
00623        ic->set_status_area_needed(rect->width, rect->height);
00624       }
00625       else if (!strcmp(icp->name, XNForeground)) {
00626        ic->set_status_fg((*(CARD32*)icp->value));
00627       }
00628       else if (!strcmp(icp->name, XNBackground)) {
00629        ic->set_status_bg((*(CARD32*)icp->value));
00630       }
00631       else if (!strcmp(icp->name, XNBackgroundPixmap)) {
00632        ic->set_status_bg_pixmap((*(Pixmap*)icp->value));
00633       }
00634       else if (!strcmp(icp->name, XNLineSpace)) {
00635        ic->set_status_line_spacing((*(CARD32*)icp->value));
00636       }
00637       else if (!strcmp(icp->name, XNCursor)) {
00638        ic->set_status_cursor((*(Cursor*)icp->value));
00639       }
00640       else if (!strcmp(icp->name, XNColormap)) {
00641        ic->set_status_colormap((*(Colormap*)icp->value));
00642       }
00643     }
00644     return (char*)0;
00645   }
00646   void SetICFocus(int icid) {
00647     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00648 
00649     if (ic) ic->set_focus();
00650   }
00651   void UnsetICFocus(int icid) {
00652     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00653 
00654     if (ic) ic->unset_focus();
00655   }
00656   Bool IsFocused(int icid) {
00657     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00658 
00659     if (ic) return ic->is_focused();
00660     return False;
00661   }
00662   void FilterEvent(int icid, XEvent *event) {
00663     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00664 
00665     if (ic) ic->filter_event(event);
00666   }
00667   void DestroyIC(int icid) {
00668     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00669 
00670     if (ic) ic->destroy();
00671   }
00672   char *ResetIC(int icid) {
00673     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00674     char *mb_data = 0;
00675     if (ic) {
00676       mb_data = ic->reset();
00677     }
00678     /* should reset to False */
00679     ic->being_reset = False;
00680     return mb_data;
00681   }
00682   void MoveSpot(int icid, int x, int y) {
00683     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00684 
00685     if (ic) ic->set_preedit_spot_location(x, y);
00686   }
00687   void ConversionStart(int icid) {
00688     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00689 
00690     if (ic) ic->conversion_start(True);
00691   }
00692   void ConversionEnd(int icid) {
00693     XInputContext *ic =(XInputContext*)&(xic_list.getItem(icid));
00694 
00695     if (ic) ic->conversion_end(True);
00696   }
00697           }
00698