~ubuntu-branches/ubuntu/maverick/uim/maverick

« back to all changes in this revision

Viewing changes to uim/uim-key.c

  • Committer: Bazaar Package Importer
  • Author(s): Masahito Omote
  • Date: 2006-11-23 15:10:53 UTC
  • mfrom: (3.1.8 edgy)
  • Revision ID: james.westby@ubuntu.com-20061123151053-q42sk1lvks41xpfx
Tags: 1:1.2.1-9
uim-gtk2.0.postinst: Don't call update-gtk-immodules on purge.
(closes: Bug#398530)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 
3
 
  Copyright (c) 2003,2004 uim Project http://uim.freedesktop.org/
 
3
  Copyright (c) 2003-2006 uim Project http://uim.freedesktop.org/
4
4
 
5
5
  All rights reserved.
6
6
 
17
17
     may be used to endorse or promote products derived from this software
18
18
     without specific prior written permission.
19
19
 
20
 
  THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
20
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21
21
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
22
  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
 
  ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
23
  ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24
24
  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
25
  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
26
  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35
35
#include <stdlib.h>
36
36
#include <string.h>
37
37
 
38
 
#include "context.h"
 
38
#include "uim.h"
 
39
#include "uim-scm.h"
 
40
#include "uim-compat-scm.h"
 
41
#include "uim-internal.h"
39
42
 
40
 
/* valid-key-symbols in key.scm has also to be updated if you add new
41
 
 * key definition to key_tab
42
 
 */
43
 
static struct {
 
43
struct key_entry {
44
44
  int key;
45
 
  char *str;
46
 
} key_tab[] = {
 
45
  const char *str;
 
46
};
 
47
 
 
48
static struct key_entry key_tab[] = {
47
49
  {UKey_Backspace, "backspace"},
48
50
  {UKey_Delete, "delete"},
49
51
  {UKey_Escape, "escape"},
57
59
  {UKey_Next, "next"},
58
60
  {UKey_Home, "home"},
59
61
  {UKey_End, "end"},
60
 
  {UKey_Zenkaku_Hankaku, "zenkaku-hankaku"},
 
62
  {UKey_Insert, "insert"},
61
63
  {UKey_Multi_key, "Multi_key"},
62
64
  {UKey_Mode_switch, "Mode_switch"},
 
65
  {UKey_Kanji, "Kanji"},
 
66
  {UKey_Muhenkan, "Muhenkan"},
63
67
  {UKey_Henkan_Mode, "Henkan_Mode"},
64
 
  {UKey_Muhenkan, "Muhenkan"},
 
68
  {UKey_Romaji, "romaji"},
 
69
  {UKey_Hiragana, "hiragana"},
 
70
  {UKey_Katakana, "katakana"},
 
71
  {UKey_Hiragana_Katakana, "hiragana-katakana"},
 
72
  {UKey_Zenkaku, "zenkaku"},
 
73
  {UKey_Hankaku, "hankaku"},
 
74
  {UKey_Zenkaku_Hankaku, "zenkaku-hankaku"},
 
75
  {UKey_Touroku, "touroku"},
 
76
  {UKey_Massyo, "massyo"},
 
77
  {UKey_Kana_Lock, "kana-lock"},
 
78
  {UKey_Kana_Shift, "kana-shift"},
 
79
  {UKey_Eisu_Shift, "eisu-shift"},
 
80
  {UKey_Eisu_toggle, "eisu-toggle"},
65
81
  {UKey_F1, "F1"},
66
82
  {UKey_F2, "F2"},
67
83
  {UKey_F3, "F3"},
137
153
  {0,0}
138
154
};
139
155
 
 
156
#if 0
 
157
int uim_key_sym_to_int(uim_lisp sym);
 
158
 
140
159
int
141
 
uim_key_sym_to_int(LISP sym_)
 
160
uim_key_sym_to_int(uim_lisp sym_)
142
161
{
143
 
  char *sym = uim_get_c_string(sym_);
 
162
  char *sym = uim_scm_refer_c_str(sym_);
144
163
  int res = 0;
145
164
  int i;
146
165
  for (i = 0; key_tab[i].key; i++) {
148
167
      res = key_tab[i].key;
149
168
    }
150
169
  }
151
 
  free(sym);
152
170
  return res;
153
171
}
154
 
 
155
 
static char *
 
172
#endif
 
173
 
 
174
static void
 
175
define_valid_key_symbols(void)
 
176
{
 
177
  int i;
 
178
 
 
179
  UIM_EVAL_STRING(NULL, "(define valid-key-symbols ())");
 
180
  for (i = 0; key_tab[i].key; i++) {
 
181
    UIM_EVAL_FSTRING1(NULL,
 
182
                      "(set! valid-key-symbols (cons '%s valid-key-symbols))",
 
183
                      key_tab[i].str);
 
184
  }
 
185
}
 
186
 
 
187
static const char *
156
188
get_sym(int key)
157
189
{
158
190
  int i;
159
 
  char *res = NULL;
 
191
  const char *res = NULL;
160
192
  for (i = 0; key_tab[i].key; i++) {
161
193
    if (key_tab[i].key == key) {
162
194
      res = key_tab[i].str;
168
200
static int
169
201
keycode_to_sym(int key, char *buf)
170
202
{
171
 
  char *s = get_sym(key);
 
203
  char *s = (char *)get_sym(key);
172
204
  if (!s) {
173
205
    if (key > 128) {
174
206
      return -1;
181
213
}
182
214
 
183
215
static void
184
 
handle_key(uim_context uc, char *p, int key, int state)
 
216
handle_key(uim_context uc, const char *p, int key, int state)
185
217
{
186
218
  char keybuf[20];
187
219
  int rv;
236
268
  return uc->commit_raw_flag;
237
269
}
238
270
 
239
 
static LISP
240
 
define_key(LISP args, LISP env)
 
271
static uim_lisp
 
272
define_key(uim_lisp args, uim_lisp env)
241
273
{
242
 
  LISP define_key_internal, predicate_sym, sources;
243
 
 
244
 
  define_key_internal = leval(rintern("define-key-internal"), env);
245
 
  predicate_sym = car(args);
246
 
  sources = NULLP(args) ? NIL : car(CDR(args));
247
 
 
248
 
  sources = leval(sources, env);
249
 
  return funcall2(define_key_internal, predicate_sym, sources);
 
274
  uim_lisp form, predicate_sym, sources;
 
275
 
 
276
  predicate_sym = uim_scm_car(args);
 
277
  sources = uim_scm_nullp(args) ? uim_scm_null_list() : uim_scm_cadr(args);
 
278
  form = uim_scm_list3(uim_scm_make_symbol("define-key-internal"),
 
279
                       uim_scm_quote(predicate_sym),
 
280
                       sources);
 
281
 
 
282
  return uim_scm_eval(form);
250
283
}
251
284
 
252
285
void
253
286
uim_init_key_subrs(void)
254
287
{
255
 
  init_fsubr("define-key",  define_key);
 
288
  define_valid_key_symbols();
 
289
  uim_scm_init_fsubr("define-key", define_key);
256
290
}