< prev index next >

modules/graphics/src/main/native-glass/gtk/glass_window_ime.cpp

Print this page


   1 /*
   2  * Copyright (c) 2011, 2014, 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
  23  * questions.
  24  */
  25 
  26 #include "com_sun_glass_ui_View.h"
  27 #include "glass_window.h"
  28 #include "glass_general.h"
  29 #include "glass_gtkcompat.h"
  30 
  31 #include <cstring>
  32 #include <cstdlib>
  33 
  34 bool WindowContextBase::hasIME() {
  35     return xim.enabled;
  36 }
  37 
  38 static XKeyPressedEvent convert_event(GdkEventKey *event) {
  39     XKeyPressedEvent result;
  40     memset(&result, 0, sizeof (result));
  41 
  42     result.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
  43     result.send_event = event->send_event;
  44     result.display = gdk_x11_display_get_xdisplay(glass_gdk_window_get_display(event->window));
  45     result.window = result.subwindow = GDK_WINDOW_XID(event->window);
  46     result.root = GDK_WINDOW_XID(gdk_screen_get_root_window(glass_gdk_window_get_screen(event->window)));
  47     result.time = event->time;
  48     result.state = event->state;
  49     result.keycode = event->hardware_keycode;
  50     result.same_screen = True;
  51 
  52     return result;
  53 }
  54 
  55 bool WindowContextBase::im_filter_keypress(GdkEventKey* event) {
  56     static size_t buf_len = 12;
  57     static char *buffer = NULL;
  58 
  59     if (buffer == NULL) {
  60         buffer = (char*)malloc(buf_len * sizeof (char));
  61     }
  62 
  63     KeySym keysym;
  64     Status status;


 205     XIMStyle result = 0;
 206 
 207     if (XGetIMValues(im_xim, XNQueryInputStyle, &styles, NULL) != NULL) { // NULL means it's OK
 208         return 0;
 209     }
 210 
 211     for (i = 0; i < styles->count_styles; ++i) {
 212         if (styles->supported_styles[i] == (XIMPreeditCallbacks | XIMStatusNothing)
 213                 || styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) {
 214             result = styles->supported_styles[i];
 215             break;
 216         }
 217     }
 218 
 219     XFree(styles);
 220 
 221     return result;
 222 }
 223 
 224 void WindowContextBase::enableOrResetIME() {
 225     Display *display = gdk_x11_display_get_xdisplay(glass_gdk_window_get_display(gdk_window));
 226     if (xim.im == NULL || xim.ic == NULL) {
 227         xim.im = XOpenIM(display, NULL, NULL, NULL);
 228         if (xim.im == NULL) {
 229             return;
 230         }
 231 
 232         XIMStyle styles = get_best_supported_style(xim.im);
 233         if (styles == 0) {
 234             return;
 235         }
 236 
 237         XIMCallback startCallback = {(XPointer) jview, (XIMProc) im_preedit_start};
 238         XIMCallback doneCallback = {(XPointer) jview, im_preedit_done};
 239         XIMCallback drawCallback = {(XPointer) jview, im_preedit_draw};
 240         XIMCallback caretCallback = {(XPointer) jview, im_preedit_caret};
 241 
 242         XVaNestedList list = XVaCreateNestedList(0,
 243                 XNPreeditStartCallback, &startCallback,
 244                 XNPreeditDoneCallback, &doneCallback,
 245                 XNPreeditDrawCallback, &drawCallback,


   1 /*
   2  * Copyright (c) 2011, 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
  23  * questions.
  24  */
  25 
  26 #include "com_sun_glass_ui_View.h"
  27 #include "glass_window.h"
  28 #include "glass_general.h"

  29 
  30 #include <cstring>
  31 #include <cstdlib>
  32 
  33 bool WindowContextBase::hasIME() {
  34     return xim.enabled;
  35 }
  36 
  37 static XKeyPressedEvent convert_event(GdkEventKey *event) {
  38     XKeyPressedEvent result;
  39     memset(&result, 0, sizeof (result));
  40 
  41     result.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
  42     result.send_event = event->send_event;
  43     result.display = gdk_x11_display_get_xdisplay(gdk_window_get_display(event->window));
  44     result.window = result.subwindow = GDK_WINDOW_XID(event->window);
  45     result.root = GDK_WINDOW_XID(gdk_screen_get_root_window(glass_gdk_window_get_screen(event->window)));
  46     result.time = event->time;
  47     result.state = event->state;
  48     result.keycode = event->hardware_keycode;
  49     result.same_screen = True;
  50 
  51     return result;
  52 }
  53 
  54 bool WindowContextBase::im_filter_keypress(GdkEventKey* event) {
  55     static size_t buf_len = 12;
  56     static char *buffer = NULL;
  57 
  58     if (buffer == NULL) {
  59         buffer = (char*)malloc(buf_len * sizeof (char));
  60     }
  61 
  62     KeySym keysym;
  63     Status status;


 204     XIMStyle result = 0;
 205 
 206     if (XGetIMValues(im_xim, XNQueryInputStyle, &styles, NULL) != NULL) { // NULL means it's OK
 207         return 0;
 208     }
 209 
 210     for (i = 0; i < styles->count_styles; ++i) {
 211         if (styles->supported_styles[i] == (XIMPreeditCallbacks | XIMStatusNothing)
 212                 || styles->supported_styles[i] == (XIMPreeditNothing | XIMStatusNothing)) {
 213             result = styles->supported_styles[i];
 214             break;
 215         }
 216     }
 217 
 218     XFree(styles);
 219 
 220     return result;
 221 }
 222 
 223 void WindowContextBase::enableOrResetIME() {
 224     Display *display = gdk_x11_display_get_xdisplay(gdk_window_get_display(gdk_window));
 225     if (xim.im == NULL || xim.ic == NULL) {
 226         xim.im = XOpenIM(display, NULL, NULL, NULL);
 227         if (xim.im == NULL) {
 228             return;
 229         }
 230 
 231         XIMStyle styles = get_best_supported_style(xim.im);
 232         if (styles == 0) {
 233             return;
 234         }
 235 
 236         XIMCallback startCallback = {(XPointer) jview, (XIMProc) im_preedit_start};
 237         XIMCallback doneCallback = {(XPointer) jview, im_preedit_done};
 238         XIMCallback drawCallback = {(XPointer) jview, im_preedit_draw};
 239         XIMCallback caretCallback = {(XPointer) jview, im_preedit_caret};
 240 
 241         XVaNestedList list = XVaCreateNestedList(0,
 242                 XNPreeditStartCallback, &startCallback,
 243                 XNPreeditDoneCallback, &doneCallback,
 244                 XNPreeditDrawCallback, &drawCallback,


< prev index next >