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,
|
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(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(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,
|