< prev index next >

src/java.desktop/aix/native/libawt_xawt/awt/awt_InputMethod.c

Print this page


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 166 #if NeedVarargsPrototypes
 167     XIM /* im */, ...
 168 #endif
 169 );
 170 
 171 static int st_wcslen(wchar_t *string);
 172 static Bool isPreeditStateActive(XIC ic);
 173 static void * buf_insert(void * src, void * insert, int size,
 174                          int src_len, int ins_len, int offset);
 175 static void * handle_buffer(void * source, void * insert,
 176                             int size, int src_len, int ins_len,
 177                             int del_len, int offset);
 178 static void preedit_draw_passive(X11InputMethodData *pX11IMData,
 179                                  XIMPreeditDrawCallbackStruct *pre_draw);
 180 static void resetPassivePreeditText(StatusWindow *statusWindow);
 181 static void draw_caret(StatusWindow *statusWindow, GC gc, int pos);
 182 static int  get_next_attr(int len, unsigned long *attr);
 183 static void draw_preedit(StatusWindow *statusWindow);
 184 static void align_status(StatusWindow *statusWindow);
 185 static void shrink_status(StatusWindow *statusWindow);
 186 static GC create_gc(Window win, Bool isReverse);
 187 static XFontSet create_fontset(void);
 188 static Bool is_text_available(XIMText * text);
 189 static Bool isNativeIm();
 190 static Window getGrandParent(Window parent);
 191 static void moveStatusWindow(StatusWindow *statusWindow);
 192 static void arrange_window_stack(StatusWindow* statusWindow);
 193 static Window get_current_focus(XIC ic);
 194 
 195 /*
 196  * This function is stolen from /src/solaris/hpi/src/system_md.c
 197  * It is used in setting the time in Java-level InputEvents
 198  */
 199 jlong
 200 awt_util_nowMillisUTC()
 201 {
 202     struct timeval t;
 203     gettimeofday(&t, NULL);
 204     return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
 205 }
 206 


 632     statusWindow->fontset = fontset;
 633     statusWindow->parent = parent;
 634     statusWindow->grandParent = grandParent;
 635     statusWindow->on  = False;
 636     statusWindow->x = x;
 637     statusWindow->y = y;
 638     statusWindow->width = xwa.width;
 639     statusWindow->height = xwa.height;
 640     statusWindow->off_x = off_x;
 641     statusWindow->off_y = off_y;
 642     statusWindow->bWidth  = bw;
 643     statusWindow->statusH = height;
 644     statusWindow->statusW = width;
 645     statusWindow->peTextW = 0;
 646     statusWindow->rootH = xxwa.height;
 647     statusWindow->rootW = xxwa.width;
 648     statusWindow->lightGC = XCreateGC(dpy, status, valuemask, &values);
 649     XSetForeground(dpy, statusWindow->lightGC, light);
 650     statusWindow->dimGC = XCreateGC(dpy, status, valuemask, &values);
 651     XSetForeground(dpy, statusWindow->dimGC, dim);
 652     statusWindow->fgGC = create_gc(status, FALSE);
 653     XSetForeground(dpy, statusWindow->fgGC, fg);
 654     statusWindow->bgGC = create_gc(status, TRUE);

 655     XSetForeground(dpy, statusWindow->bgGC, bg);

 656     statusWindow->status_ready = False;
 657     wcscpy(statusWindow->status, L"");
 658     return statusWindow;
 659 }
 660 
 661 /* This method is to turn off or turn on the status window. */
 662 static void onoffStatusWindow(X11InputMethodData* pX11IMData,
 663                                 Window parent,
 664                                 Bool ON){
 665     XWindowAttributes xwa;
 666     Window child;
 667     int x, y;
 668     StatusWindow *statusWindow = NULL;
 669 
 670     if (NULL == pX11IMData ||
 671         NULL == (statusWindow =  pX11IMData->statusWindow)){
 672         return;
 673     }
 674 
 675     if (ON == False) {


1640     XConfigureWindow(dpy, statusWindow->w, value_make, &xwc);
1641 }
1642 
1643 static void shrink_status(StatusWindow *statusWindow)
1644 {
1645     int value_make = CWX|CWWidth|CWHeight;
1646     XWindowChanges xwc;
1647 
1648     if (NULL == statusWindow) return;
1649     xwc.width  = statusWindow->statusW;
1650     xwc.height = statusWindow->statusH;
1651     statusWindow->peTextW = 0;
1652     xwc.x = statusWindow->x - statusWindow->off_x;
1653     if (xwc.x < 0 ) xwc.x = 0;
1654     if (xwc.x + xwc.width > statusWindow->rootW){
1655       xwc.x = statusWindow->rootW - xwc.width;
1656     }
1657     XConfigureWindow(dpy, statusWindow->w, value_make, &xwc);
1658 }
1659 
1660 static GC create_gc(Window win, Bool isReverse)
1661 {
1662     XGCValues xgcv;
1663     unsigned long mask;
1664     AwtScreenDataPtr defaultScreen;
1665 
1666     defaultScreen = getScreenData(DefaultScreen(dpy));
1667 
1668     mask = (GCForeground | GCBackground );
1669     if (isReverse) {
1670         xgcv.foreground = defaultScreen->whitepixel;
1671         xgcv.background = defaultScreen->blackpixel;
1672     } else {
1673         xgcv.foreground = defaultScreen->blackpixel;
1674         xgcv.background = defaultScreen->whitepixel;
1675     }
1676     return XCreateGC(dpy, win, mask, &xgcv);
1677 }
1678 
1679 static Bool isNativeIm()
1680 {
1681 #define XIMMODIFIER          "@im="
1682 #define XIM_SERVER_CATEGORY  "@server="
1683     char *immodifiers;
1684     char *imserver, *imserverPtr;
1685     Atom imserverAtom;
1686 
1687     if (!(immodifiers = getenv("XMODIFIERS"))) return True;
1688     if (!(imserver = calloc(1,strlen(immodifiers)+strlen(XIM_SERVER_CATEGORY)+1))) return True;
1689     if (!(immodifiers = strstr(immodifiers,XIMMODIFIER))) return True;
1690     immodifiers += strlen(XIMMODIFIER);
1691     strcpy(imserver,XIM_SERVER_CATEGORY);
1692     imserverPtr = imserver + strlen(imserver);
1693     while(*immodifiers != '@' && *immodifiers != '\0') {
1694         *imserverPtr = *immodifiers;
1695         imserverPtr++;
1696         immodifiers++;
1697     }
1698     imserverAtom = XInternAtom(awt_display, imserver, True);


   1 /*
   2  * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 166 #if NeedVarargsPrototypes
 167     XIM /* im */, ...
 168 #endif
 169 );
 170 
 171 static int st_wcslen(wchar_t *string);
 172 static Bool isPreeditStateActive(XIC ic);
 173 static void * buf_insert(void * src, void * insert, int size,
 174                          int src_len, int ins_len, int offset);
 175 static void * handle_buffer(void * source, void * insert,
 176                             int size, int src_len, int ins_len,
 177                             int del_len, int offset);
 178 static void preedit_draw_passive(X11InputMethodData *pX11IMData,
 179                                  XIMPreeditDrawCallbackStruct *pre_draw);
 180 static void resetPassivePreeditText(StatusWindow *statusWindow);
 181 static void draw_caret(StatusWindow *statusWindow, GC gc, int pos);
 182 static int  get_next_attr(int len, unsigned long *attr);
 183 static void draw_preedit(StatusWindow *statusWindow);
 184 static void align_status(StatusWindow *statusWindow);
 185 static void shrink_status(StatusWindow *statusWindow);

 186 static XFontSet create_fontset(void);
 187 static Bool is_text_available(XIMText * text);
 188 static Bool isNativeIm();
 189 static Window getGrandParent(Window parent);
 190 static void moveStatusWindow(StatusWindow *statusWindow);
 191 static void arrange_window_stack(StatusWindow* statusWindow);
 192 static Window get_current_focus(XIC ic);
 193 
 194 /*
 195  * This function is stolen from /src/solaris/hpi/src/system_md.c
 196  * It is used in setting the time in Java-level InputEvents
 197  */
 198 jlong
 199 awt_util_nowMillisUTC()
 200 {
 201     struct timeval t;
 202     gettimeofday(&t, NULL);
 203     return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
 204 }
 205 


 631     statusWindow->fontset = fontset;
 632     statusWindow->parent = parent;
 633     statusWindow->grandParent = grandParent;
 634     statusWindow->on  = False;
 635     statusWindow->x = x;
 636     statusWindow->y = y;
 637     statusWindow->width = xwa.width;
 638     statusWindow->height = xwa.height;
 639     statusWindow->off_x = off_x;
 640     statusWindow->off_y = off_y;
 641     statusWindow->bWidth  = bw;
 642     statusWindow->statusH = height;
 643     statusWindow->statusW = width;
 644     statusWindow->peTextW = 0;
 645     statusWindow->rootH = xxwa.height;
 646     statusWindow->rootW = xxwa.width;
 647     statusWindow->lightGC = XCreateGC(dpy, status, valuemask, &values);
 648     XSetForeground(dpy, statusWindow->lightGC, light);
 649     statusWindow->dimGC = XCreateGC(dpy, status, valuemask, &values);
 650     XSetForeground(dpy, statusWindow->dimGC, dim);
 651     statusWindow->fgGC = XCreateGC(dpy, status, valuemask, &values);
 652     XSetForeground(dpy, statusWindow->fgGC, fg);
 653     XSetBackground(dpy, statusWindow->fgGC, bg);
 654     statusWindow->bgGC = XCreateGC(dpy, status, valuemask, &values);
 655     XSetForeground(dpy, statusWindow->bgGC, bg);
 656     XSetBackground(dpy, statusWindow->bgGC, fg);
 657     statusWindow->status_ready = False;
 658     wcscpy(statusWindow->status, L"");
 659     return statusWindow;
 660 }
 661 
 662 /* This method is to turn off or turn on the status window. */
 663 static void onoffStatusWindow(X11InputMethodData* pX11IMData,
 664                                 Window parent,
 665                                 Bool ON){
 666     XWindowAttributes xwa;
 667     Window child;
 668     int x, y;
 669     StatusWindow *statusWindow = NULL;
 670 
 671     if (NULL == pX11IMData ||
 672         NULL == (statusWindow =  pX11IMData->statusWindow)){
 673         return;
 674     }
 675 
 676     if (ON == False) {


1641     XConfigureWindow(dpy, statusWindow->w, value_make, &xwc);
1642 }
1643 
1644 static void shrink_status(StatusWindow *statusWindow)
1645 {
1646     int value_make = CWX|CWWidth|CWHeight;
1647     XWindowChanges xwc;
1648 
1649     if (NULL == statusWindow) return;
1650     xwc.width  = statusWindow->statusW;
1651     xwc.height = statusWindow->statusH;
1652     statusWindow->peTextW = 0;
1653     xwc.x = statusWindow->x - statusWindow->off_x;
1654     if (xwc.x < 0 ) xwc.x = 0;
1655     if (xwc.x + xwc.width > statusWindow->rootW){
1656       xwc.x = statusWindow->rootW - xwc.width;
1657     }
1658     XConfigureWindow(dpy, statusWindow->w, value_make, &xwc);
1659 }
1660 



















1661 static Bool isNativeIm()
1662 {
1663 #define XIMMODIFIER          "@im="
1664 #define XIM_SERVER_CATEGORY  "@server="
1665     char *immodifiers;
1666     char *imserver, *imserverPtr;
1667     Atom imserverAtom;
1668 
1669     if (!(immodifiers = getenv("XMODIFIERS"))) return True;
1670     if (!(imserver = calloc(1,strlen(immodifiers)+strlen(XIM_SERVER_CATEGORY)+1))) return True;
1671     if (!(immodifiers = strstr(immodifiers,XIMMODIFIER))) return True;
1672     immodifiers += strlen(XIMMODIFIER);
1673     strcpy(imserver,XIM_SERVER_CATEGORY);
1674     imserverPtr = imserver + strlen(imserver);
1675     while(*immodifiers != '@' && *immodifiers != '\0') {
1676         *imserverPtr = *immodifiers;
1677         imserverPtr++;
1678         immodifiers++;
1679     }
1680     imserverAtom = XInternAtom(awt_display, imserver, True);


< prev index next >