Back to index

im-sdk  12.3.91
XInputContext.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 _XInputContext_hh
00043 #define _XInputContext_hh
00044 
00045 #include <X11/Xlib.h>
00046 #include "XIMProto.hh"
00047 #include "R6IMProtocol.hh"
00048 
00049 // for preedit start callback
00050 typedef int (*XIMProc1)(XIC, XPointer, XPointer);
00051 typedef struct {
00052   XPointer client_data;
00053   XIMProc1 callback;
00054 } XIMCallback1;
00055 
00056 // for any other else
00057 typedef void (*XIMProc2)(XIC, XPointer, XPointer);
00058 typedef struct {
00059   XPointer client_data;
00060   XIMProc2 callback;
00061 } XIMCallback2;
00062 
00063 class XIMPublic;
00064 
00065 class XInputContext {
00066  public:
00067   XInputContext(XIMPublic*, CARD16, int);
00068   ~XInputContext();
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   // get ic value
00093   int get_input_style(CARD32 &ret) {
00094     ret = inputstyle;
00095     return inputstyle != 0;
00096   }
00097   int get_client_window(Window &ret) {
00098     ret = client_win;
00099     return client_win != 0;
00100   }
00101   int get_focus_window(Window &ret) {
00102     if (!(attr_mask & XIMP_FOCUS_WIN_MASK4)) return False;
00103     ret = focus_win;
00104     return True;
00105   }
00106   int get_fwin_select_mask(CARD32 &ret) {
00107     ret = ev_masks;
00108     return ev_masks != 0;
00109   }
00110   Bool is_conv_state() {return is_conv_on;}
00111 
00112   int get_preedit_fontset(char *ret) {
00113     if (!(attr_mask & XIMP_PRE_FONT_MASK4)) return False;
00114     ret = (char*)preedit_fontname;
00115     return True;
00116   }
00117   int get_preedit_area(long &x, long &y, unsigned long &width,
00118                      unsigned long &height) {
00119     if (!(attr_mask & XIMP_PRE_AREA_MASK4)) return False;
00120     x = preedit_attr4.area.x;
00121     y = preedit_attr4.area.y;    
00122     width = preedit_attr4.area.width;
00123     height = preedit_attr4.area.height;
00124     return True;
00125   }
00126   int get_preedit_area_needed(long &x, long &y, unsigned long &width,
00127                            unsigned long &height) {
00128     if (!(attr_mask & XIMP_PRE_AREANEED_MASK4)) return False;
00129     x = 0;
00130     y = 0;
00131     width = preedit_attr4.area_needed.width;
00132     height = preedit_attr4.area_needed.height;
00133     return True;
00134   }
00135   int get_preedit_spot_location(long &x, long &y) {
00136     if (!(attr_mask & XIMP_PRE_SPOTL_MASK4)) return False;
00137     x = preedit_attr4.spot_location.x;
00138     y = preedit_attr4.spot_location.y;
00139     return True;
00140   }
00141   int get_preedit_fg(CARD32 &fg) {
00142     if (!(attr_mask & XIMP_PRE_FG_MASK4)) return False;
00143     fg = preedit_attr4.foreground;
00144     return True;
00145   }
00146   int get_preedit_bg(CARD32 &bg) {
00147     if (!(attr_mask & XIMP_PRE_BG_MASK4)) return False;
00148     bg = preedit_attr4.background;
00149     return True;
00150   }
00151   int get_preedit_bg_pixmap(CARD32 &bg_pixmap) {
00152     if (!(attr_mask & XIMP_PRE_BGPIXMAP_MASK4)) return False;
00153     bg_pixmap = preedit_attr4.bg_pixmap;
00154     return True;
00155   }
00156   int get_preedit_line_spacing(CARD32 &linesp) {
00157     if (!(attr_mask & XIMP_PRE_LINESP_MASK4)) return False;
00158     linesp = preedit_attr4.line_spacing;
00159     return True;
00160   }
00161   int get_preedit_cursor(Cursor &cursor) {
00162     if (!(attr_mask & XIMP_PRE_CURSOR_MASK4)) return False;
00163     cursor = preedit_attr4.cursor;
00164     return True;
00165   }
00166   int get_preedit_colormap(Colormap &colormap) {
00167     if (!(attr_mask & XIMP_PRE_COLORMAP_MASK4)) return False;
00168     colormap = preedit_attr4.colormap;
00169     return True;
00170   }
00171 
00172   int get_status_fontset(char *ret) {
00173     if (!(attr_mask & XIMP_STS_FONT_MASK4)) return False;
00174     ret = (char*)status_fontname;
00175     return True;
00176   }
00177   int get_status_area(long &x, long &y, unsigned long &width,
00178                      unsigned long &height) {
00179     if (!(attr_mask & XIMP_STS_AREA_MASK4)) return False;
00180     x = status_attr4.area.x;
00181     y = status_attr4.area.y;    
00182     width = status_attr4.area.width;
00183     height = status_attr4.area.height;
00184     return True;
00185   }
00186   int get_status_area_needed(long &x, long &y, unsigned long &width,
00187                            unsigned long &height) {
00188     if (!(attr_mask & XIMP_STS_AREANEED_MASK4)) return False;
00189     x = 0;
00190     y = 0;
00191     width = status_attr4.area_needed.width;
00192     height = status_attr4.area_needed.height;
00193     return True;
00194   }
00195   int get_status_fg(CARD32 &fg) {
00196     if (!(attr_mask & XIMP_STS_FG_MASK4)) return False;
00197     fg = status_attr4.foreground;
00198     return True;
00199   }
00200   int get_status_bg(CARD32 &bg) {
00201     if (!(attr_mask & XIMP_STS_BG_MASK4)) return False;
00202     bg = status_attr4.background;
00203     return True;
00204   }
00205   int get_status_bg_pixmap(CARD32 &bg_pixmap) {
00206     if (!(attr_mask & XIMP_STS_BGPIXMAP_MASK4)) return False;
00207     bg_pixmap = status_attr4.bg_pixmap;
00208     return True;
00209   }
00210   int get_status_line_spacing(CARD32 &linesp) {
00211     if (!(attr_mask & XIMP_STS_LINESP_MASK4)) return False;
00212     linesp = status_attr4.line_spacing;
00213     return True;
00214   }
00215   int get_status_cursor(Cursor &cursor) {
00216     if (!(attr_mask & XIMP_STS_CURSOR_MASK4)) return False;
00217     cursor = status_attr4.cursor;
00218     return True;
00219   }
00220   int get_status_colormap(Colormap &colormap) {
00221     if (!(attr_mask & XIMP_STS_COLORMAP_MASK4)) return False;
00222     colormap = status_attr4.colormap;
00223     return True;
00224   }
00225 
00226   // set ic value
00227   void set_client_window(Window new_win);
00228   void set_focus_window(Window new_win);
00229 
00230   void set_fwin_select_mask(long mask);
00231 
00232   void set_preedit_spot_location(long x, long y);
00233   void set_preedit_fontset(char*);
00234   void set_preedit_area(long x, long y, unsigned long width,
00235                      unsigned long height);
00236   void set_preedit_area_needed(unsigned long width, unsigned long height);
00237   void set_preedit_colormap(Colormap colormap);
00238   void set_preedit_fg(unsigned long);
00239   void set_preedit_bg(unsigned long);
00240   void set_preedit_bg_pixmap(Pixmap pixmap);
00241   void set_preedit_line_spacing(long);
00242   void set_preedit_cursor(Cursor cursor);
00243 
00244   void set_status_fontset(char*);
00245   void set_status_area(long x, long y, unsigned long width,
00246                      unsigned long height);
00247   void set_status_area_needed(unsigned long width, unsigned long height);
00248   void set_status_colormap(Colormap colormap);
00249   void set_status_fg(unsigned long);
00250   void set_status_bg(unsigned long);
00251   void set_status_bg_pixmap(Pixmap pixmap);
00252   void set_status_line_spacing(long);
00253   void set_status_cursor(Cursor cursor);
00254 
00255   void set_focus();
00256   void unset_focus();
00257   Bool is_focused() {return focused;}
00258 
00259   char *reset();
00260   void destroy();
00261   void filter_event(XEvent*);
00262 
00263   void conversion_start(Bool reply_back);
00264   void conversion_end(Bool reply_back);
00265 
00266   Bool being_reset;  // whether XIC is being reset or not
00267 private:
00268   static Bool destroy_clientwin_filter(Display *, Window, XEvent*, XPointer);
00269   void register_clientwin_destroy_filter();
00270   void unregister_clientwin_destroy_filter();
00271   long filters;
00272   enum XimpFilterMode {
00273     FLT_NONE = (0L), FLT_KEYPRESS = (1L<<0),
00274     FLT_KEYRELEASE = (1L<<1), FLT_DESTROY = (1L<<2)
00275   };
00276 
00277   XIMCallback1 *preedit_start_cb;
00278 
00279   XIMCallback2 *preedit_draw_cb;
00280   XIMCallback2 *preedit_caret_cb;
00281   XIMCallback2 *preedit_done_cb;
00282   XIMCallback2 *status_start_cb;
00283   XIMCallback2 *status_draw_cb;
00284   XIMCallback2 *status_done_cb;
00285 
00286   XIMCallback2 *state_notify_cb;
00287   XIMCallback2 *commit_string_cb;
00288   XIMCallback2 *forward_event_cb;
00289 
00290   Ximp_PreeditPropRec4      preedit_attr4;
00291   CompoundString     preedit_fontname;
00292   Ximp_StatusPropRec4       status_attr4;
00293   CompoundString     status_fontname;
00294 
00295   void unselect_destroy_clientwin_emask();
00296   void select_destroy_clientwin_emask();
00297 
00298   void select_destroy_emask();
00299 
00300   XIMPublic *ximp_protocol;
00301   CARD16 connect_id;
00302 
00303   XIC xic;
00304   XIMStyle inputstyle;
00305   Display *dpy;
00306 
00307   Window client_win;
00308   Window focus_win;
00309 
00310   long attr_mask;
00311   long ev_masks;
00312   Bool is_conv_on;
00313   CompoundString reset_text;
00314 
00315   Bool focused;
00316 
00317   enum Ximp40ICMask {
00318     XIMP_FOCUS_WIN_MASK4    = (1L <<  0),
00319     XIMP_PRE_AREA_MASK4            = (1L <<  1),
00320     XIMP_PRE_AREANEED_MASK4 = (1L <<  2),
00321     XIMP_PRE_COLORMAP_MASK4 = (1L <<  3),
00322     XIMP_PRE_STD_COLORMAP_MASK4 = (1L <<  4),
00323     XIMP_PRE_FG_MASK4              = (1L <<  5),
00324     XIMP_PRE_BG_MASK4              = (1L <<  6),
00325     XIMP_PRE_BGPIXMAP_MASK4 = (1L <<  7),
00326     XIMP_PRE_LINESP_MASK4   = (1L <<  8),
00327     XIMP_PRE_CURSOR_MASK4   = (1L <<  9),
00328     XIMP_PRE_SPOTL_MASK4    = (1L << 10),
00329     XIMP_STS_AREA_MASK4            = (1L << 11),
00330     XIMP_STS_AREANEED_MASK4 = (1L << 12),
00331     XIMP_STS_COLORMAP_MASK4 = (1L << 13),
00332     XIMP_STS_STD_COLORMAP_MASK4    = (1L << 14),
00333     XIMP_STS_FG_MASK4              = (1L << 15),
00334     XIMP_STS_BG_MASK4              = (1L << 16),
00335     XIMP_STS_BGPIXMAP_MASK4 = (1L << 17),
00336     XIMP_STS_LINESP_MASK4   = (1L << 18),
00337     XIMP_STS_CURSOR_MASK4   = (1L << 19),
00338     XIMP_STS_WINDOW_MASK4   = (1L << 20),
00339     XIMP_PRE_FONT_MASK4            = (1L << 21),
00340     XIMP_STS_FONT_MASK4            = (1L << 22),
00341     XIMP_SERVERTYPE_MASK4   = (1L << 23)
00342   };
00343 
00344   void SetExtensionCallbacks();
00345   void SetPreeditCallbacks();
00346   void SetStatusCallbacks();
00347 };
00348 
00349 #endif