Back to index

im-sdk  12.3.91
XIMPInputContext.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 _XIMPInputContext_hh
00043 #define _XIMPInputContext_hh
00044 
00045 #include "XIMProto.hh"
00046 #include "InputContext.hh"
00047 #include "CompoundString.hh"
00048 
00049 class XIMProtocol;
00050 
00051 // for preedit start callback
00052 typedef int (*XIMProc1)(XIC, XPointer, XPointer);
00053 typedef struct {
00054   XPointer client_data;
00055   XIMProc1 callback;
00056 } XIMCallback1;
00057 
00058 // for any other else
00059 typedef void (*XIMProc2)(XIC, XPointer, XPointer);
00060 typedef struct {
00061   XPointer client_data;
00062   XIMProc2 callback;
00063 } XIMCallback2;
00064 
00065 class XIMPInputContext : public InputContext {
00066  public:
00067   XIMPInputContext(XIMProtocol *ximp, XClientMessageEvent *ev);
00068   ~XIMPInputContext();
00069 
00070 // XIM callbacks
00071   static int preedit_start_cbproc(XIC xic, XPointer client_data,
00072                               XPointer call_data_p);
00073   static void preedit_draw_cbproc(XIC xic, XPointer client_data,
00074                               XPointer call_data_p);
00075   static void preedit_caret_cbproc(XIC xic, XPointer client_data,
00076                                XPointer call_data_p);
00077   static void preedit_done_cbproc(XIC xic, XPointer client_data,
00078                               XPointer call_data_p);
00079   static void status_start_cbproc(XIC xic, XPointer client_data,
00080                               XPointer call_data_p);
00081   static void status_draw_cbproc(XIC xic, XPointer client_data,
00082                              XPointer call_data_p);
00083   static void status_done_cbproc(XIC xic, XPointer client_data,
00084                              XPointer call_data_p);
00085   static void state_notify_cbproc(XIC xic, XPointer client_data,
00086                               XPointer call_data_p);
00087   static void commit_string_cbproc(XIC xic, XPointer client_data,
00088                                XPointer call_data_p);
00089   static void forward_event_cbproc(XIC xic, XPointer client_data,
00090                                XPointer call_data_p);
00091 
00092   const CompoundString& getUser() const;
00093   const CompoundString& getLocaleName() const;
00094   const CompoundString& getEngineName() const;
00095 
00096   // CLIENT DESCRIPTOR
00097   const CompoundString& getApplicationName() const;
00098   const CompoundString& getOSName() const;
00099   const CompoundString& getOSArch() const;
00100   const CompoundString& getOSVersion() const;
00101   // Client Display Info
00102   const CompoundString& getXDisplayString() const;
00103   const CompoundString& getXServerVendor() const;
00104 
00105   int commit_string(IMText *text);
00106   int forward_event(IMKeyEventStruct *event);
00107   int preedit_start(IMPreeditStruct *preedit);
00108   int preedit_draw(IMPreeditStruct *preedit);
00109   int preedit_caret(IMPreeditStruct *preedit);
00110   int preedit_done(IMPreeditStruct *preedit);
00111   int status_start(IMStatusStruct *status);
00112   int status_draw(IMStatusStruct *status);
00113   int status_done(IMStatusStruct *status);
00114   int lookup_start(IMLookupStruct *lookup);
00115   int lookup_draw(IMLookupStruct *lookup);
00116   int lookup_process(IMLookupStruct *lookup);
00117   int lookup_done(IMLookupStruct *lookup);
00118   int auxiliary_start(IMAuxStruct *auxiliary);
00119   int auxiliary_draw(IMAuxStruct *auxiliary);
00120   int auxiliary_done(IMAuxStruct *auxiliary);
00121   int conversion_start();
00122   int conversion_end();
00123 
00124   int conversion_start(Bool reply_back);
00125   int conversion_end(Bool reply_back);
00126 
00127   Window focus_window();
00128   Window client_window();
00129 
00130   int focus_window(Window&) const;
00131   int client_window(Window&) const;
00132 
00133   Bool is_version_40() {return (proto_version == XIMP_VERSION_40);}
00134   Bool is_conv_state() {return is_conv_on;}
00135   Bool set_conv_state(Bool flag) {return is_conv_on = flag;}
00136   Bool is_ximp_type(long type) {return (ev_flow_type == type);}
00137   Bool is_sync();
00138 
00139   void set_client_window(Window new_win);
00140   void set_focus_window(Window new_win);
00141   void set_fwin_select_mask(long mask);
00142   void set_preedit_spot_location(long x, long y);
00143   void set_preedit_maxlen(unsigned long len);
00144   void set_preedit_caret_position(unsigned long pos);
00145 
00146   void set_preedit_area(long x, long y, unsigned long width,
00147                      unsigned long height);
00148   void set_preedit_area_needed(unsigned long width, unsigned long height);
00149   void set_preedit_colormap(Colormap colormap);
00150   void set_preedit_fg(unsigned long);
00151   void set_preedit_bg(unsigned long);
00152   void set_preedit_bg_pixmap(Pixmap pixmap);
00153   void set_preedit_line_spacing(long);
00154   void set_preedit_cursor(Cursor cursor);
00155 
00156   void set_status_area(long x, long y, unsigned long width,
00157                      unsigned long height);
00158   void set_status_area_needed(unsigned long width, unsigned long height);
00159   void set_status_colormap(Colormap colormap);
00160   void set_status_fg(unsigned long);
00161   void set_status_bg(unsigned long);
00162   void set_status_bg_pixmap(Pixmap pixmap);
00163   void set_status_line_spacing(long);
00164   void set_status_cursor(Cursor cursor);
00165 
00166   void set_values(XClientMessageEvent *ev);
00167   void get_values(XClientMessageEvent *ev);
00168 
00169   void select_destroy_emask();
00170   void select_destroy_clientwin_emask();
00171   void select_keypress_emask();
00172   void select_keyrelease_emask();
00173   void unselect_destroy_emask();
00174   void unselect_destroy_clientwin_emask();
00175   void unselect_keypress_emask();
00176   void unselect_keyrelease_emask();
00177 
00178   void set_match(int kcode, int state);
00179   Bool process_match(int kcode, int state);
00180 
00181   XIMProtocol *ximp_protocol;
00182 
00183   char *get_commit_string();
00184 
00185   char *reset_xic();
00186   void destroy_xic();
00187   void set_xicfocus();
00188   void unset_xicfocus();
00189 
00190   Bool checkAltKey(XClientMessageEvent *ev);
00191   
00192   // backward compativility
00193   int forward_xevent(XEvent *event);
00194 
00195  private:
00196   static Bool destroy_clientwin_filter(Display *, Window, XEvent*, XPointer);
00197   void register_clientwin_destroy_filter();
00198   void unregister_clientwin_destroy_filter();
00199 
00200   XIC xic;
00201   Display *dpy;
00202   // XICCore part
00203   XIMStyle inputstyle;             /* IM's input style */
00204   Window client_win;        /* window IM can use for */
00205   Window focus_win;         /* where key events go */
00206   Ximp_PreeditPropRec4      preedit_attr4;
00207   char               *preedit_fontname;
00208   Ximp_StatusPropRec4       status_attr4;
00209   char               *status_fontname;
00210 
00211   // XICXimp part
00212   long attr_mask;
00213   long ev_flow_type; // event flow type
00214   long ev_masks;     // holds client's interest masks
00215   long filters;
00216   Bool is_conv_on;   /* holds current conversion state */
00217   int og_code;              /* holds keycode to keep matching */
00218   int og_state;             /* holds keystate to keep matching */
00219   Bool being_reset;  // whether XIC is being reset or not
00220   CompoundString reset_text;
00221 
00222   XIMCallback1 *preedit_start_cb;
00223 
00224   XIMCallback2 *preedit_draw_cb;
00225   XIMCallback2 *preedit_caret_cb;
00226   XIMCallback2 *preedit_done_cb;
00227   XIMCallback2 *status_start_cb;
00228   XIMCallback2 *status_draw_cb;
00229   XIMCallback2 *status_done_cb;
00230 
00231   XIMCallback2 *state_notify_cb;
00232   XIMCallback2 *commit_string_cb;
00233   XIMCallback2 *forward_event_cb;
00234 
00235   CompoundString user_name;
00236 
00237   CompoundString application_name;
00238   CompoundString os_name;
00239   CompoundString os_arch;
00240   CompoundString os_version;
00241 
00242   CompoundString xDisplayName;
00243   CompoundString xServerVendor;
00244 
00245   unsigned long preedit_maxlen;
00246   unsigned long preedit_caret_position;
00247 
00248   enum XimpProtocolVersion {
00249     XIMP_VERSION_35, XIMP_VERSION_40, XIMP_VERSION_UNKNOWN
00250   };
00251 
00252   enum XimpFilterMode {
00253     FLT_NONE = (0L), FLT_KEYPRESS = (1L<<0),
00254     FLT_KEYRELEASE = (1L<<1), FLT_DESTROY = (1L<<2)
00255   };
00256 
00257   enum Ximp40ICMask {
00258     XIMP_FOCUS_WIN_MASK4    = (1L <<  0),
00259     XIMP_PRE_AREA_MASK4            = (1L <<  1),
00260     XIMP_PRE_AREANEED_MASK4 = (1L <<  2),
00261     XIMP_PRE_COLORMAP_MASK4 = (1L <<  3),
00262     XIMP_PRE_STD_COLORMAP_MASK4 = (1L <<  4),
00263     XIMP_PRE_FG_MASK4              = (1L <<  5),
00264     XIMP_PRE_BG_MASK4              = (1L <<  6),
00265     XIMP_PRE_BGPIXMAP_MASK4 = (1L <<  7),
00266     XIMP_PRE_LINESP_MASK4   = (1L <<  8),
00267     XIMP_PRE_CURSOR_MASK4   = (1L <<  9),
00268     XIMP_PRE_SPOTL_MASK4    = (1L << 10),
00269     XIMP_STS_AREA_MASK4            = (1L << 11),
00270     XIMP_STS_AREANEED_MASK4 = (1L << 12),
00271     XIMP_STS_COLORMAP_MASK4 = (1L << 13),
00272     XIMP_STS_STD_COLORMAP_MASK4    = (1L << 14),
00273     XIMP_STS_FG_MASK4              = (1L << 15),
00274     XIMP_STS_BG_MASK4              = (1L << 16),
00275     XIMP_STS_BGPIXMAP_MASK4 = (1L << 17),
00276     XIMP_STS_LINESP_MASK4   = (1L << 18),
00277     XIMP_STS_CURSOR_MASK4   = (1L << 19),
00278     XIMP_STS_WINDOW_MASK4   = (1L << 20),
00279     XIMP_PRE_FONT_MASK4            = (1L << 21),
00280     XIMP_STS_FONT_MASK4            = (1L << 22),
00281     XIMP_SERVERTYPE_MASK4   = (1L << 23)
00282   };
00283 
00284   enum Ximp35ICMask {
00285     XIMP_FOCUS_WIN_MASK3    = (1L <<  0),
00286     XIMP_PRE_AREA_MASK3            = (1L <<  1),
00287     XIMP_PRE_FG_MASK3              = (1L <<  2),
00288     XIMP_PRE_BG_MASK3              = (1L <<  3),
00289     XIMP_PRE_COLORMAP_MASK3 = (1L <<  4),
00290     XIMP_PRE_BGPIXMAP_MASK3 = (1L <<  5),
00291     XIMP_PRE_LINESP_MASK3   = (1L <<  6),
00292     XIMP_PRE_CURSOR_MASK3   = (1L <<  7),
00293     XIMP_PRE_AREANEED_MASK3 = (1L <<  8),
00294     XIMP_PRE_SPOTL_MASK3    = (1L <<  9),
00295     XIMP_STS_AREA_MASK3            = (1L << 10),
00296     XIMP_STS_FG_MASK3              = (1L << 11),
00297     XIMP_STS_BG_MASK3              = (1L << 12),
00298     XIMP_STS_COLORMAP_MASK3 = (1L << 13),
00299     XIMP_STS_BGPIXMAP_MASK3 = (1L << 14),
00300     XIMP_STS_LINESP_MASK3   = (1L << 15),
00301     XIMP_STS_CURSOR_MASK3   = (1L << 16),
00302     XIMP_STS_AREANEED_MASK3 = (1L << 17),
00303     XIMP_STS_WINDOW_MASK3   = (1L << 18),
00304     XIMP_PRE_FONT_MASK3            = (1L << 19),
00305     XIMP_STS_FONT_MASK3            = (1L << 20)
00306   };
00307 
00308   XimpProtocolVersion proto_version;
00309 
00310   enum XIC_MASK {
00311     PREEDIT_MASK4 = (XIMP_PRE_AREA_MASK4|XIMP_PRE_AREANEED_MASK4|
00312                    XIMP_PRE_COLORMAP_MASK4|XIMP_PRE_STD_COLORMAP_MASK4|
00313                    XIMP_PRE_FG_MASK4|XIMP_PRE_BG_MASK4|
00314                    XIMP_PRE_BGPIXMAP_MASK4|XIMP_PRE_LINESP_MASK4|
00315                    XIMP_PRE_CURSOR_MASK4|XIMP_PRE_SPOTL_MASK4),
00316     STATUS_MASK4 = (XIMP_STS_AREA_MASK4|XIMP_STS_AREANEED_MASK4|
00317                   XIMP_STS_COLORMAP_MASK4|XIMP_STS_STD_COLORMAP_MASK4|
00318                   XIMP_STS_FG_MASK4|XIMP_STS_BG_MASK4|
00319                   XIMP_STS_BGPIXMAP_MASK4|XIMP_STS_LINESP_MASK4|
00320                   XIMP_STS_CURSOR_MASK4|XIMP_STS_WINDOW_MASK4),
00321     PREEDIT_MASK3 = (XIMP_PRE_AREA_MASK3|XIMP_PRE_AREANEED_MASK3|
00322                    XIMP_PRE_COLORMAP_MASK3|XIMP_PRE_FG_MASK3|
00323                    XIMP_PRE_BG_MASK3|XIMP_PRE_BGPIXMAP_MASK3|
00324                    XIMP_PRE_LINESP_MASK3|XIMP_PRE_CURSOR_MASK3|
00325                    XIMP_PRE_SPOTL_MASK3),
00326     STATUS_MASK3 = (XIMP_STS_AREA_MASK3|XIMP_STS_AREANEED_MASK3|
00327                   XIMP_STS_COLORMAP_MASK3|XIMP_STS_FG_MASK3|
00328                   XIMP_STS_BG_MASK3|XIMP_STS_BGPIXMAP_MASK3|
00329                   XIMP_STS_LINESP_MASK3|XIMP_STS_CURSOR_MASK3|
00330                   XIMP_STS_WINDOW_MASK3)
00331   };
00332 
00333   enum XimpClientMessageSize {
00334     COMMIT_CMSG_MAX = 30
00335   };
00336 
00337   enum XimpPDCBStates {
00338     XIMP_PDCBSTATUS_NOTEXT = 0x0001,
00339     XIMP_PDCBSTATUS_NOFEEDBACK = 0x0002,
00340     XIMP_PDCBSTATUS_FEEDBACKS_VIA_PROP = 0x0004
00341   };
00342 
00343   Bool get_xicvalues(unsigned long&);
00344   Bool get_focus_win();
00345   Bool get_preedit_font();
00346   Bool get_status_font();
00347   Bool get_preedit4(unsigned long);
00348   Bool get_status4(unsigned long);
00349   Bool get_server_type4();
00350   Bool get_preedit3(unsigned long);
00351   Bool get_status3(unsigned long);
00352 
00353   Bool set_xicvalues(unsigned long&);
00354   Bool set_focus_win();
00355   Bool set_preedit_font();
00356   Bool set_status_font();
00357   Bool set_preedit4();
00358   Bool set_status4();
00359   Bool set_server_type4();
00360   Bool set_preedit3();
00361   Bool set_status3();
00362 
00363   // backward compativility
00364   int commit_string(char *text);
00365   int preedit_draw(XIMPreeditDrawCallbackStruct *draw);
00366   int preedit_caret(XIMPreeditCaretCallbackStruct *caret);
00367   int status_draw(XIMStatusDrawCallbackStruct *draw);
00368   // int lookup_draw(XIMLookupDrawCallbackStruct *draw);
00369 
00370   int preedit_draw_by_cm(XIMPreeditDrawCallbackStruct *draw);
00371 
00372   int preedit_draw_feedback(XIMPreeditDrawCallbackStruct *draw);
00373   int preedit_draw_tiny(XIMPreeditDrawCallbackStruct *draw);
00374 
00375   // for delay binding to IIIMP server
00376   void DelayBind();
00377   void CreateXIC();
00378   void SetExtensionCallbacks();
00379   void SetPreeditCallbacks();
00380   void SetStatusCallbacks();
00381 };
00382 
00383 #endif