Back to index

im-sdk  12.3.91
XIMPPreeditIC.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 <string.h>
00043 #include <sys/types.h>
00044 #include <unistd.h>
00045 #include <pwd.h>
00046 #include "XIMProtocol.hh"
00047 #include "XIMPInputContext.hh"
00048 #include "Xfactory.hh"
00049 
00050 void
00051 XIMPInputContext::set_preedit_spot_location(long x, long y) {
00052   attr_mask |= XIMP_PRE_SPOTL_MASK4;
00053   preedit_attr4.spot_location.x = x;
00054   preedit_attr4.spot_location.y = y;
00055 
00056   // as XIM client
00057   XVaNestedList preedit_attr;
00058   XPoint spot;
00059   spot.x = x; spot.y = y;
00060   preedit_attr = XVaCreateNestedList(0,
00061                                  XNSpotLocation, &spot,
00062                                  NULL);
00063   XSetICValues(xic,
00064               XNPreeditAttributes, preedit_attr,
00065               0);
00066   XFree(preedit_attr);
00067   return;
00068 }
00069 void
00070 XIMPInputContext::set_preedit_area(long x, long y, unsigned long width,
00071                                unsigned long height) {
00072   // as XIM client
00073   XVaNestedList preedit_attr;
00074   XRectangle area;
00075   area.x = x; area.y = y; area.width = width; area.height = height;
00076   preedit_attr = XVaCreateNestedList(0,
00077                                  XNArea, &area,
00078                                  NULL);
00079   XSetICValues(xic,
00080               XNPreeditAttributes, preedit_attr,
00081               0);
00082   XFree(preedit_attr);
00083   return;
00084 }
00085 void
00086 XIMPInputContext::set_preedit_area_needed(unsigned long width,
00087                                      unsigned long height) {
00088   // as XIM client
00089   XVaNestedList preedit_attr;
00090   XRectangle area;
00091   area.x = 0; area.y = 0; area.width = width; area.height = height;
00092   preedit_attr = XVaCreateNestedList(0,
00093                                  XNAreaNeeded, &area,
00094                                  NULL);
00095   XSetICValues(xic,
00096               XNPreeditAttributes, preedit_attr,
00097               0);
00098   XFree(preedit_attr);
00099   if (width == 0 || height == 0) {
00100     // do geometry negotiation
00101     XRectangle *area2 = (XRectangle*)0;
00102     preedit_attr = XVaCreateNestedList(0,
00103                                    XNAreaNeeded, &area2,
00104                                    NULL);
00105     XGetICValues(xic,
00106                XNPreeditAttributes, preedit_attr,
00107                0);
00108     XFree(preedit_attr);
00109     if (area2) {
00110       if (width == 0) {
00111        preedit_attr4.area_needed.width = area2->width;
00112       }
00113       if (height == 0) {
00114        preedit_attr4.area_needed.height = area2->height;
00115       }
00116       XFree(area2);
00117     }
00118     // fallback to avoid setting 0
00119     if (preedit_attr4.area_needed.width == 0) {
00120       XFontSet font_set = XFactory::create_fontset(dpy, preedit_fontname);
00121       XFontSetExtents *fsx = XExtentsOfFontSet(font_set);
00122       preedit_attr4.area_needed.width = fsx->max_logical_extent.width *10;
00123       XFactory::free_fontset(dpy, font_set);
00124     }
00125     if (preedit_attr4.area_needed.height == 0) {
00126       XFontSet font_set = XFactory::create_fontset(dpy, preedit_fontname);
00127       XFontSetExtents *fsx = XExtentsOfFontSet(font_set);
00128       preedit_attr4.area_needed.height = fsx->max_logical_extent.height;
00129       XFactory::free_fontset(dpy, font_set);
00130     }
00131   }
00132   return;
00133 }
00134 void
00135 XIMPInputContext::set_preedit_colormap(Colormap colormap) {
00136   // as XIM client
00137   XVaNestedList preedit_attr;
00138   preedit_attr = XVaCreateNestedList(0,
00139                                  XNColormap, colormap,
00140                                  NULL);
00141   XSetICValues(xic,
00142               XNPreeditAttributes, preedit_attr,
00143               0);
00144   XFree(preedit_attr);
00145   return;
00146 }
00147 void
00148 XIMPInputContext::set_preedit_bg_pixmap(Pixmap bg_pixmap) {
00149   // as XIM client
00150   XVaNestedList preedit_attr;
00151   preedit_attr = XVaCreateNestedList(0,
00152                                  XNBackgroundPixmap, bg_pixmap,
00153                                  NULL);
00154   XSetICValues(xic,
00155               XNPreeditAttributes, preedit_attr,
00156               0);
00157   XFree(preedit_attr);
00158 }
00159 void
00160 XIMPInputContext::set_preedit_line_spacing(long line_spacing) {
00161   // as XIM client
00162   XVaNestedList preedit_attr;
00163   preedit_attr = XVaCreateNestedList(0,
00164                                  XNLineSpace, line_spacing,
00165                                  NULL);
00166   XSetICValues(xic,
00167               XNPreeditAttributes, preedit_attr,
00168               0);
00169   XFree(preedit_attr);
00170 }
00171 void
00172 XIMPInputContext::set_preedit_cursor(Cursor cursor) {
00173   // as XIM client
00174   XVaNestedList preedit_attr;
00175   preedit_attr = XVaCreateNestedList(0,
00176                                  XNCursor, cursor,
00177                                  NULL);
00178   XSetICValues(xic,
00179               XNPreeditAttributes, preedit_attr,
00180               0);
00181   XFree(preedit_attr);
00182 }
00183 void
00184 XIMPInputContext::set_preedit_bg(unsigned long bg) {
00185   // as XIM client
00186   XVaNestedList preedit_attr;
00187   preedit_attr = XVaCreateNestedList(0,
00188                                  XNBackground, bg,
00189                                  NULL);
00190   XSetICValues(xic,
00191               XNPreeditAttributes, preedit_attr,
00192               0);
00193   XFree(preedit_attr);
00194 }
00195 void
00196 XIMPInputContext::set_preedit_fg(unsigned long fg) {
00197   XVaNestedList preedit_attr;
00198   preedit_attr = XVaCreateNestedList(0,
00199                                  XNForeground, fg,
00200                                  NULL);
00201   XSetICValues(xic,
00202               XNPreeditAttributes, preedit_attr,
00203               0);
00204   XFree(preedit_attr);
00205 }
00206 Bool
00207 XIMPInputContext::get_preedit_font() {
00208   if (!ximp_protocol->get_preedit_font(client_win,
00209                                    (char **)&preedit_fontname)) {
00210     return False;
00211   }
00212 
00213   // as XIM client
00214   XVaNestedList preedit_attr;
00215   XFontSet font_set = XFactory::create_fontset(dpy, preedit_fontname);
00216   preedit_attr = XVaCreateNestedList(0,
00217                                  XNFontSet, font_set,
00218                                  NULL);
00219   XSetICValues(xic,
00220               XNPreeditAttributes, preedit_attr,
00221               0);
00222   XFree(preedit_attr);
00223   return True;
00224 }