]> icculus.org git repositories - divverent/darkplaces.git/blob - uim.c
typo
[divverent/darkplaces.git] / uim.c
1 /* UIM input support for
2  * DarkPlaces
3  */
4 #include "quakedef.h"
5
6 #include "uim_dp.h"
7
8 /*
9 ================================================================================
10 CVars introduced with the UIM extension
11 ================================================================================
12 */
13
14 cvar_t im_method = {CVAR_SAVE, "im_method", "anthy", "which input method to use if uim is supported and active"};
15 cvar_t im_enabled = {CVAR_SAVE, "im_enabled", "0", "use UIM input"};
16
17 /*
18 ================================================================================
19 Library imports. Taken from the uim headers.
20 ================================================================================
21 */
22
23 struct uim_code_converter *quim_iconv;
24
25 int           (*quim_init)(void);
26 void          (*quim_quit)(void);
27 uim_candidate (*quim_get_candidate)(uim_context, int index, int accel_enum_hint);
28 void          (*quim_candidate_free)(uim_candidate);
29 int           (*quim_get_candidate_index)(uim_context);
30 const char*   (*quim_candidate_get_cand_str)(uim_candidate);
31 const char*   (*quim_get_default_im_name)(const char *localename);
32 uim_context   (*quim_create_context)(void *cookie,
33                                      const char *encoding,
34                                      const char *im, const char *lang,
35                                      const char *engine,
36                                      struct uim_code_converter *conv,
37                                      void (*commit_cb)(void *ptr, const char *str));
38 void          (*quim_release_context)(uim_context);
39 int           (*quim_helper_init_client_fd)(void (*disconnect_cb)(void));
40 void          (*quim_close_client_fd)(int);
41 void          (*quim_set_preedit_cb)(uim_context,
42                                      void (*clear_cb)(void*),
43                                      void (*pushback_cb)(void*, int attr, const char *str),
44                                      void (*update_cb)(void*));
45 //void          (*quim_set_prop_list_update_cb)(uim_context,
46 //                                            void (*update_cb)(void*, const char *longstr));
47 void          (*quim_set_candidate_selector_cb)(uim_context,
48                                                 void (*activate_cb)(void*, int nr, int display_limit),
49                                                 void (*select_cb)(void*, int index),
50                                                 void (*shift_page_cb)(void*, int direction),
51                                                 void (*deactivate_cb)(void*));
52 void          (*quim_prop_list_update)(uim_context);
53 void          (*quim_press_key)(uim_context, int key, int mods);
54 void          (*quim_release_key)(uim_context, int key, int mods);
55
56 /*
57 ================================================================================
58 Support for dynamically loading the UIM library
59 ================================================================================
60 */
61
62 static dllfunction_t uimfuncs[] =
63 {
64         {"uim_init",                    (void **) &quim_init},
65         {"uim_quit",                    (void **) &quim_quit},
66         {"uim_get_candidate",           (void **) &quim_get_candidate},
67         {"uim_candidate_free",          (void **) &quim_candidate_free},
68         {"uim_get_candidate_index",     (void **) &quim_get_candidate_index},
69         {"uim_candidate_get_cand_str",  (void **) &quim_candidate_get_cand_str},
70         {"uim_get_default_im_name",     (void **) &quim_get_default_im_name},
71         {"uim_create_context",          (void **) &quim_create_context},
72         {"uim_release_context",         (void **) &quim_release_context},
73         {"uim_helper_init_client_fd",   (void **) &quim_helper_init_client_fd},
74         {"uim_close_client_fd",         (void **) &quim_close_client_fd},
75         {"uim_set_preedit_cb",          (void **) &quim_set_preedit_cb},
76         {"uim_set_candidate_selector_cb",               (void **) &quim_set_candidate_selector_cb},
77         {"uim_prop_list_update",        (void **) &quim_prop_list_update},
78         {"uim_press_key",               (void **) &quim_press_key},
79         {"uim_release_key",             (void **) &quim_release_key},
80         {"uim_iconv",                   (void **) &quim_iconv},
81         
82         {NULL, NULL}
83 };
84
85 /// Handle for UIM dll
86 static dllhandle_t uim_dll = NULL;
87
88 /// Memory pool for uim
89 static mempool_t *uim_mempool= NULL;
90
91 /*
92 ====================
93 UIM_CloseLibrary
94
95 Unload the UIM DLL
96 ====================
97 */
98 void UIM_CloseLibrary (void)
99 {
100         if (uim_mempool)
101                 Mem_FreePool(&uim_mempool);
102         Sys_UnloadLibrary (&uim_dll);
103 }
104
105 /*
106 ====================
107 UIM_OpenLibrary
108
109 Try to load the UIM DLL
110 ====================
111 */
112 qboolean UIM_OpenLibrary (void)
113 {
114         const char* dllnames [] =
115         {
116 #if defined(WIN64)
117                 #error path for freetype 2 dll
118 #elif defined(WIN32)
119                 #error path for freetype 2 dll
120 #elif defined(MACOSX)
121                 "libuim.dylib",
122 #else
123                 "libuim.so.6",
124                 "libuim.so",
125 #endif
126                 NULL
127         };
128
129         // Already loaded?
130         if (uim_dll)
131                 return true;
132
133         // Load the DLL
134         if (!Sys_LoadLibrary (dllnames, &uim_dll, uimfuncs))
135                 return false;
136         return true;
137 }