1 #
2 # tk/xim.rb : control imput_method
3 #
4 require 'tk'
5
6 module TkXIM
7 include Tk
8 extend Tk
9
10 TkCommandNames = ['imconfigure'.freeze].freeze
11
12 def TkXIM.useinputmethods(value = None, win = nil)
13 if value == None
14 if win
15 bool(tk_call_without_enc('tk', 'useinputmethods',
16 '-displayof', win))
17 else
18 bool(tk_call_without_enc('tk', 'useinputmethods'))
19 end
20 else
21 if win
22 bool(tk_call_without_enc('tk', 'useinputmethods',
23 '-displayof', win, value))
24 else
25 bool(tk_call_without_enc('tk', 'useinputmethods', value))
26 end
27 end
28 end
29
30 def TkXIM.useinputmethods_displayof(win, value = None)
31 TkXIM.useinputmethods(value, win)
32 end
33
34 def TkXIM.caret(win, keys=nil)
35 if keys
36 tk_call_without_enc('tk', 'caret', win, *hash_kv(keys))
37 self
38 else
39 lst = tk_split_list(tk_call_without_enc('tk', 'caret', win))
40 info = {}
41 while key = lst.shift
42 info[key[1..-1]] = lst.shift
43 end
44 info
45 end
46 end
47
48 def TkXIM.configure(win, slot, value=None)
49 begin
50 if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
51 if slot.kind_of? Hash
52 tk_call('imconfigure', win, *hash_kv(slot))
53 else
54 tk_call('imconfigure', win, "-#{slot}", value)
55 end
56 end
57 rescue
58 end
59 end
60
61 def TkXIM.configinfo(win, slot=nil)
62 if TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
63 begin
64 if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
65 if slot
66 conf = tk_split_list(tk_call('imconfigure', win, "-#{slot}"))
67 conf[0] = conf[0][1..-1]
68 conf
69 else
70 tk_split_list(tk_call('imconfigure', win)).collect{|conf|
71 conf[0] = conf[0][1..-1]
72 conf
73 }
74 end
75 else
76 []
77 end
78 rescue
79 []
80 end
81 else # ! TkComm::GET_CONFIGINFOwoRES_AS_ARRAY
82 TkXIM.current_configinfo(win, slot)
83 end
84 end
85
86 def TkXIM.current_configinfo(win, slot=nil)
87 begin
88 if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
89 if slot
90 conf = tk_split_list(tk_call('imconfigure', win, "-#{slot}"))
91 { conf[0][1..-1] => conf[1] }
92 else
93 ret = {}
94 tk_split_list(tk_call('imconfigure', win)).each{|conf|
95 ret[conf[0][1..-1]] = conf[1]
96 }
97 ret
98 end
99 else
100 {}
101 end
102 rescue
103 {}
104 end
105 end
106
107 def useinputmethods(value=None)
108 TkXIM.useinputmethods(value, self)
109 end
110
111 def caret(keys=nil)
112 TkXIM.caret(self, keys=nil)
113 end
114
115 def imconfigure(slot, value=None)
116 TkXIM.configure(self, slot, value)
117 end
118
119 def imconfiginfo(slot=nil)
120 TkXIM.configinfo(self, slot)
121 end
122 end