Back to index

im-sdk  12.3.91
XIMProtocol.hh
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 #ifndef _XIMProtocol_hh
00043 #define _XIMProtocol_hh
00044 
00045 #include <X11/Xatom.h>
00046 #include <X11/Xlibint.h>
00047 #include "XIMPublic.hh"
00048 #include "IMThread.hh"
00049 
00050 struct XIMPTypeRec {
00051   int num_of_types;
00052   unsigned long *types;
00053 };
00054 
00055 struct XIMPAtoms {
00056   Atom selection_owner;
00057   Atom selection_owner2;
00058   Atom ctext_type;
00059   Atom version;
00060   Atom supported_styles;
00061   Atom supported_types;
00062   Atom server_name;
00063   Atom server_version;
00064   Atom vendor_name;
00065   Atom keys;
00066   Atom sproc_started_keys;
00067   Atom sproc_stopped_keys;
00068   Atom focus;
00069   Atom preedit;
00070   Atom status;
00071   Atom preedit_font;
00072   Atom status_font;
00073   /* for XIMP_EXTENSION */
00074   Atom extensions;
00075   Atom ext_statuswin;
00076   Atom ext_backfront;
00077   Atom ext_conversion;
00078   /* for Callbacks */
00079   Atom preedit_draw_data;
00080   Atom feedbacks;
00081 };
00082 
00083 // forward declaration. Actual definitions are in ximp40/XIMProto.hh
00084 struct Ximp_PreeditPropRec4;
00085 struct Ximp_PreeditPropRec3;
00086 struct Ximp_StatusPropRec4;
00087 struct Ximp_StatusPropRec3;
00088 
00089 class XIMProtocol : public XIMPublic {
00090  public:
00091   XIMProtocol(IMArg*, int);
00092   ~XIMProtocol();
00093 
00094   int run();
00095   
00096   Bool get_protocol_version(Window, char*&);
00097   Bool get_focus_window(Window, Window&);
00098   Bool get_preedit_font(Window, char **);
00099   Bool get_status_font(Window, char **);
00100   Bool get_preedit4(Window, Ximp_PreeditPropRec4&);
00101   Bool get_status4(Window, Ximp_StatusPropRec4&);
00102   Bool get_preedit3(Window, Ximp_PreeditPropRec3&);
00103   Bool get_status3(Window, Ximp_StatusPropRec3&);
00104   Bool get_server_type4(Window, unsigned long&);
00105 
00106   Bool set_focus_window(Window, Window);
00107   Bool set_preedit_font(Window, char *);
00108   Bool set_status_font(Window, char *);
00109   Bool set_preedit4(Window, Ximp_PreeditPropRec4);
00110   Bool set_status4(Window, Ximp_StatusPropRec4);
00111   Bool set_preedit3(Window, Ximp_PreeditPropRec3);
00112   Bool set_status3(Window, Ximp_StatusPropRec3);
00113   Bool set_server_type4(Window, unsigned long);
00114 
00115   Bool read_property(Window, Atom, Atom, int,
00116                    unsigned char**, unsigned long*);
00117 
00118   Bool write_property(Window, Atom, Atom, int,
00119                     const unsigned char*, const unsigned long);
00120 
00121   enum XIMP_FE_BE_TYPE {
00122     XIMP_FRONTEND4 = (1L << 0), XIMP_BACKEND4 = (1L << 1), 
00123     XIMP_TYPE1 = (1L << 2), XIMP_TYPE2 = (1L << 3),
00124     XIMP_TYPE3 = (1L << 4), XIMP_SYNC = (1L << 5),
00125     XIMP_FE_TYPE1 = (XIMP_FRONTEND4 | XIMP_TYPE1),
00126     XIMP_FE_TYPE2 = (XIMP_FRONTEND4 | XIMP_TYPE2),
00127     XIMP_FE_TYPE3 = (XIMP_FRONTEND4 | XIMP_TYPE3),
00128     XIMP_BE_TYPE1 = (XIMP_BACKEND4  | XIMP_TYPE1),
00129     XIMP_BE_TYPE2 = (XIMP_BACKEND4  | XIMP_TYPE2),
00130     XIMP_SYNC_BE_TYPE1 = (XIMP_SYNC | XIMP_BE_TYPE1),
00131     XIMP_SYNC_BE_TYPE2 = (XIMP_SYNC | XIMP_BE_TYPE2)
00132   };
00133 
00134   enum XIMP_OLD_FE_BE_TYPE {
00135     XIMP_FRONTEND = 0, XIMP_BACKEND = 1
00136   };
00137 
00138   int getICID(InputContext *ic) {
00139     return input_context_list.getIndex(ic);
00140   }
00141 
00142   void send_client_message(Window, int,
00143                         unsigned long, unsigned long,
00144                         unsigned long, unsigned long);
00145 
00146   void commit_by_client_message(Window, int, const char*, int);
00147 
00148   Atom replace_prop_pool(const unsigned char *data, int len);
00149   
00150   Atom set_preedit_draw_data_property(const unsigned char *data , int len);
00151   Atom set_ctext_property(const unsigned char *data, int len,
00152                        int is_commit);
00153   Atom set_ctext_property(const unsigned char *data, int len);
00154 
00155   Atom set_feedback_property(const unsigned char *data, int len);
00156 
00157   enum XIM_PROTOCOL {
00158     /* client <=> frontend  */
00159     XIMP_KEYRELEASE4 = 100,
00160     XIMP_KEYPRESS4 = 101,
00161     /* client ==> frontend  * Base Protocol */
00162     XIMP_CREATE4 = 102,
00163     XIMP_DESTROY4 = 103,
00164     XIMP_REG_KEY_PRESSED4 = 104,
00165     XIMP_SETFOCUS4 = 105,
00166     XIMP_UNSETFOCUS4 = 106,
00167     XIMP_CLIENT_WINDOW4 = 107,
00168     XIMP_FOCUS_WINDOW4 = 108,
00169     XIMP_MOVE4 = 109,
00170     XIMP_RESET4 = 110,
00171     XIMP_SETVALUE4 = 111,
00172     XIMP_GETVALUE4 = 112,
00173     /* * Callback  Protocol */
00174     XIMP_PREEDITSTART_RETURN4 = 120,
00175     XIMP_PREEDITCARET_RETURN4 = 121,
00176     /* client <== frontend  * Base Protocol  */
00177     XIMP_SPROC_STARTED4 = 130,
00178     XIMP_SPROC_STOPPED4 = 131,
00179     XIMP_READPROP4 = 132,
00180     XIMP_CLIENT_WINDOW_RETURN4 = 133,
00181     XIMP_FOCUS_WINDOW_RETURN4 = 134,
00182     XIMP_GETVALUE_RETURN4 = 135,
00183     XIMP_RESET_RETURN4 = 136,
00184     XIMP_CREATE_RETURN4 = 137,
00185     XIMP_KEYPRESS_RETURN4 = 138,
00186     XIMP_KEYRELEASE_RETURN4 = 139,
00187     /* Callback  Protocol */
00188     XIMP_GEOMETRY4 = 140,
00189     XIMP_PREEDITSTART4 = 150,
00190     XIMP_PREEDITDONE4 = 151,
00191     XIMP_PREEDITDRAW4 = 152,
00192     XIMP_PREEDITDRAW_CM4 = 153,
00193     XIMP_PREEDITDRAW_CM_TINY4 = 154,
00194     XIMP_PREEDITDRAW_CM_FEEDBACK4 = 155,
00195     XIMP_PREEDITCARET4 = 156,
00196     XIMP_STATUSSTART4 = 160,
00197     XIMP_STATUSDONE4 = 161,
00198     XIMP_STATUSDRAW4 = 162,
00199     XIMP_STATUSDRAW_CM4 = 163,
00200     /* client => IM Server for frontend method */
00201     XIMP_EVENTMASK_NOTIFY4 = 200,
00202     /* client <= IM Server for frontend method */
00203     XIMP_EVENTMASK_NOTIFY_RETURN4 = 201,
00204     /* Extension Protocol */
00205     XIMP_EXTENSION4 = 500,
00206     /* client <== frontend  * Error Protocol */
00207     XIMP_ERROR4 = 999,
00208 
00209     /* ClientMessage No.  Ximp 3.5 */
00210     /* client <=> frontend  */
00211     XIMP_KEYPRESS3 = 1,
00212     /* client ==> frontend  * Base Protocol */
00213     XIMP_CREATE3 = 2,
00214     XIMP_DESTROY3 = 3,
00215     XIMP_BEGIN3 = 4,
00216     XIMP_END3 = 5,
00217     XIMP_SETFOCUS3 = 6,
00218     XIMP_UNSETFOCUS3 = 7,
00219     XIMP_CHANGE3 = 8,
00220     XIMP_MOVE3 = 9,
00221     XIMP_RESET3 = 10,
00222     XIMP_SETVALUE3 = 11,
00223     XIMP_GETVALUE3 = 12,
00224     /* Callback  Protocol */
00225     XIMP_PREEDITSTART_RETURN3 = 20,
00226     XIMP_PREEDITCARET_RETURN3 = 21,
00227     /* client <== frontend  * Base Protocol  */
00228     XIMP_CREATE_RETURN3 = 2,
00229     XIMP_CONVERSION_BEGIN3 = 30,
00230     XIMP_PROCESS_BEGIN3 = 30,
00231     XIMP_CONVERSION_END3 = 31,
00232     XIMP_PROCESS_END3 = 31, 
00233     XIMP_READPROP3 = 32,
00234     XIMP_GETVALUE_RETURN3 = 33,
00235     XIMP_RESET_RETURN3 = 34,
00236     /* Callback  Protocol */
00237     XIMP_GEOMETRY3 = 40,
00238     XIMP_PREEDITSTART3 = 41,
00239     XIMP_PREEDITDONE3 = 42,
00240     XIMP_PREEDITDRAW3 = 43,
00241     XIMP_PREEDITDRAW_CM3 = 44,
00242     XIMP_PREEDITCARET3 = 45,
00243     XIMP_STATUSSTART3 = 46,
00244     XIMP_STATUSDONE3 = 47,
00245     XIMP_STATUSDRAW3 = 48,
00246     XIMP_STATUSDRAW_CM3 = 49,
00247     XIMP_PREEDITDRAW_TINY3 = 50,
00248     /* Extension Protocol */
00249     XIMP_EXTENSION3 = 90,
00250     /* client <== frontend  * Error Protocol */
00251     XIMP_ERROR3 = 99
00252   };
00253 
00254  private:
00255   // XIMP specific connection address
00256   int screen;
00257   Atom ximp_request;        // Ximp message type
00258   Window im_window;         // IMServerWindow
00259   XIMStyles styles;         // IMInputStyles
00260   const char *ximp_version; // XIMPVersion
00261   XIMPTypeRec ximp_type;    // XIMPType
00262   const char *im_version;   // XIMPServerVersion
00263   IMThread *thread;
00264 
00265   /* Atoms */
00266   XIMPAtoms atoms;
00267   /* XIMPExtension */
00268   unsigned int ext_flag;    /* flag for supported_extensions */
00269   long ext_backfront; /* XGIMPExtBackFront value */
00270 
00271   enum XIMP_EXT {
00272     EXT_STATUS = (1L<<0), EXT_BACKFRONT = (1L<<1),
00273     EXT_CONV = (1L<<2)
00274   };
00275 
00276   enum XIMP_PROP_LEN {
00277     XIMP_PREEDIT_MAX_LONG3 = 14,
00278     XIMP_PREEDIT_MAX_LONG4 = 15,
00279     XIMP_STATUS_MAX_LONG3 = 13,
00280     XIMP_STATUS_MAX_LONG4 = 14
00281   };
00282 
00283   enum XIMP_CM_LEN {
00284     CM_DATA_ROOM = 15
00285   };
00286 
00287   int atom_sequence;
00288   char *MakeNewAtom(char*, int is_commit=0);
00289 
00290   static void *xevent_loop(void*);
00291 
00292   void setProps();
00293 
00294   InputContext * getInputContextByFocusWindow(Window ); 
00295   Bool key_press(XClientMessageEvent*);
00296   Bool key_release(XClientMessageEvent*);
00297   void create_ic(XClientMessageEvent *);
00298   void destroy_ic(XClientMessageEvent*);
00299   void destroy_window(XIMProtocol *, Window);
00300   void start(XClientMessageEvent*);
00301   void end(XClientMessageEvent*);
00302   void set_focus(XClientMessageEvent*);
00303   void unset_focus(XClientMessageEvent*);
00304   void set_clientwin(XClientMessageEvent *);
00305   void set_focuswin(XClientMessageEvent*);
00306   void move(XClientMessageEvent*);
00307   void set_icvalues(XClientMessageEvent*);
00308   void get_icvalues(XClientMessageEvent*);
00309   void reset(XClientMessageEvent*);
00310   void event_mask(XClientMessageEvent*);
00311   void extension(XClientMessageEvent*);
00312   void preedit_start_ret(XClientMessageEvent*);
00313   void preedit_caret_ret(XClientMessageEvent*);
00314 };
00315 
00316 #endif