]> git.decadent.org.uk Git - ion3.git/blob - ioncore/xic.c
Update cfg_kludge_flash for Flash 10
[ion3.git] / ioncore / xic.c
1 /*
2  * ion/ioncore/xic.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <ctype.h>
10 #include <string.h>
11 #include "common.h"
12 #include "global.h"
13 #include "ioncore.h"
14
15
16 static XIM input_method=NULL;
17 static XIMStyle input_style=(XIMPreeditNothing|XIMStatusNothing);
18
19
20 void ioncore_init_xim(void)
21 {
22     char *p;
23     int i;
24     XIM xim=NULL;
25     XIMStyles *xim_styles = NULL;
26       bool found=FALSE;
27
28     if((p=XSetLocaleModifiers(""))!=NULL && *p)
29         xim=XOpenIM(ioncore_g.dpy, NULL, NULL, NULL);
30     
31     if(xim==NULL && (p=XSetLocaleModifiers("@im=none"))!=NULL && *p)
32         xim=XOpenIM(ioncore_g.dpy, NULL, NULL, NULL);
33
34     if(xim==NULL){
35         ioncore_warn_nolog(TR("Failed to open input method."));
36         return;
37     }
38     
39     if(XGetIMValues(xim, XNQueryInputStyle, &xim_styles, NULL) || !xim_styles) {
40         ioncore_warn_nolog(TR("Input method doesn't support any style."));
41         XCloseIM(xim);
42         return;
43     }
44     
45     for(i=0; (ushort)i<xim_styles->count_styles; i++){
46         if(input_style==xim_styles->supported_styles[i]){
47             found=TRUE;
48             break;
49         }
50     }
51     
52     XFree(xim_styles);
53     
54     if(!found){
55         ioncore_warn_nolog(TR("input method doesn't support my preedit type."));
56         XCloseIM(xim);
57         return;
58     }
59
60     input_method=xim;    
61 }
62
63
64 XIC xwindow_create_xic(Window win)
65 {
66     /*static bool tried=FALSE;*/
67     XIC xic;
68     
69     /*
70     if(input_method==NULL && !tried){
71         init_xlocale();
72         tried=TRUE;
73     }*/
74     
75     if(input_method==NULL)
76         return NULL;
77     
78     xic=XCreateIC(input_method, XNInputStyle, input_style,
79                   XNClientWindow, win, XNFocusWindow, win,
80                   NULL);
81     
82     if(xic==NULL)
83         warn(TR("Failed to create input context."));
84
85     return xic;
86 }
87
88
89 bool window_create_xic(WWindow *wwin)
90 {
91     if(wwin->xic==NULL)
92         wwin->xic=xwindow_create_xic(wwin->win);
93     return (wwin->xic!=NULL);
94 }