Back to index

im-sdk  12.3.91
XIMPStatusIC.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_status_area(long x, long y, unsigned long width,
00052                               unsigned long height) {
00053   // as XIM client
00054   XVaNestedList status_attr;
00055   XRectangle area;
00056   area.x = x; area.y = y; area.width = width; area.height = height;
00057   status_attr = XVaCreateNestedList(0,
00058                                 XNArea, &area,
00059                                 NULL);
00060   XSetICValues(xic,
00061               XNStatusAttributes, status_attr,
00062               0);
00063   XFree(status_attr);
00064   return;
00065 }
00066 void
00067 XIMPInputContext::set_status_area_needed(unsigned long width,
00068                                      unsigned long height) {
00069   if (!xic) DelayBind();
00070 
00071   // as XIM client
00072   XVaNestedList status_attr;
00073   XRectangle area;
00074   area.x = 0; area.y = 0; area.width = width; area.height = height;
00075   status_attr = XVaCreateNestedList(0,
00076                                 XNAreaNeeded, &area,
00077                                 NULL);
00078   XSetICValues(xic,
00079               XNStatusAttributes, status_attr,
00080               0);
00081   XFree(status_attr);
00082   if (width == 0 || height == 0) {
00083     // do geometry negotiation
00084     XRectangle *area2 = (XRectangle*)0;
00085     status_attr = XVaCreateNestedList(0,
00086                                   XNAreaNeeded, &area2,
00087                                   NULL);
00088     XGetICValues(xic,
00089                XNStatusAttributes, status_attr,
00090                0);
00091     XFree(status_attr);
00092     if (area2) {
00093       if (width == 0 ||
00094          inputstyle & XIMPreeditArea) {
00095        status_attr4.area_needed.width = area2->width;
00096       }
00097       if (height == 0) {
00098        status_attr4.area_needed.height = area2->height;
00099       }
00100       XFree(area2);
00101     }
00102     // fallback to avoid setting 0
00103     if (status_attr4.area_needed.width == 0) {
00104       XFontSet font_set = XFactory::create_fontset(dpy, status_fontname);
00105       XFontSetExtents *fsx = XExtentsOfFontSet(font_set);
00106       status_attr4.area_needed.width = fsx->max_logical_extent.width *10;
00107       XFactory::free_fontset(dpy, font_set);
00108     }
00109     if (status_attr4.area_needed.height == 0) {
00110       XFontSet font_set = XFactory::create_fontset(dpy, status_fontname);
00111       XFontSetExtents *fsx = XExtentsOfFontSet(font_set);
00112       status_attr4.area_needed.height = fsx->max_logical_extent.height;
00113       XFactory::free_fontset(dpy, font_set);
00114     }
00115   }
00116   return;
00117 }
00118 void
00119 XIMPInputContext::set_status_colormap(Colormap colormap) {
00120   // as XIM client
00121   XVaNestedList status_attr;
00122   status_attr = XVaCreateNestedList(0,
00123                                 XNColormap, colormap,
00124                                 NULL);
00125   XSetICValues(xic,
00126               XNStatusAttributes, status_attr,
00127               0);
00128   XFree(status_attr);
00129   return;
00130 }
00131 void
00132 XIMPInputContext::set_status_bg(unsigned long bg) {
00133   // as XIM client
00134   XVaNestedList status_attr;
00135   status_attr = XVaCreateNestedList(0,
00136                                 XNBackground, bg,
00137                                 NULL);
00138   XSetICValues(xic,
00139               XNStatusAttributes, status_attr,
00140               0);
00141   XFree(status_attr);
00142 }
00143 void
00144 XIMPInputContext::set_status_fg(unsigned long fg) {
00145   // as XIM client
00146   XVaNestedList status_attr;
00147   status_attr = XVaCreateNestedList(0,
00148                                 XNForeground, fg,
00149                                 NULL);
00150   XSetICValues(xic,
00151               XNStatusAttributes, status_attr,
00152               0);
00153   XFree(status_attr);
00154 }
00155 void
00156 XIMPInputContext::set_status_bg_pixmap(Pixmap bg_pixmap) {
00157   // as XIM client
00158   XVaNestedList status_attr;
00159   status_attr = XVaCreateNestedList(0,
00160                                 XNBackgroundPixmap, bg_pixmap,
00161                                 NULL);
00162   XSetICValues(xic,
00163               XNStatusAttributes, status_attr,
00164               0);
00165   XFree(status_attr);
00166 }
00167 void
00168 XIMPInputContext::set_status_line_spacing(long line_spacing) {
00169   // as XIM client
00170   XVaNestedList status_attr;
00171   status_attr = XVaCreateNestedList(0,
00172                                 XNLineSpace, line_spacing,
00173                                 NULL);
00174   XSetICValues(xic,
00175               XNStatusAttributes, status_attr,
00176               0);
00177   XFree(status_attr);
00178 }
00179 void
00180 XIMPInputContext::set_status_cursor(Cursor cursor) {
00181   // as XIM client
00182   XVaNestedList status_attr;
00183   status_attr = XVaCreateNestedList(0,
00184                                 XNCursor, cursor,
00185                                 NULL);
00186   XSetICValues(xic,
00187               XNStatusAttributes, status_attr,
00188               0);
00189   XFree(status_attr);
00190 }
00191 Bool
00192 XIMPInputContext::get_status_font() {
00193   if (!ximp_protocol->get_status_font(client_win,
00194                                   (char **)&status_fontname)) {
00195     return False;
00196   }
00197   // as XIM client
00198   XVaNestedList status_attr;
00199   XFontSet font_set = XFactory::create_fontset(dpy, status_fontname);
00200   status_attr = XVaCreateNestedList(0,
00201                                 XNFontSet, font_set,
00202                                 NULL);
00203   XSetICValues(xic,
00204               XNStatusAttributes, status_attr,
00205               0);
00206   XFree(status_attr);
00207   return True;
00208 }
00209 
00210