1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
|
;;;
;;; Copyright (c) 2003-2008 uim Project http://code.google.com/p/uim/
;;;
;;; All rights reserved.
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;; 3. Neither the name of authors nor the names of its contributors
;;; may be used to endorse or promote products derived from this software
;;; without specific prior written permission.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
;;; SUCH DAMAGE.
;;;;
(require-custom "generic-key-custom.scm")
;;; user configs
(define scim-candidate-max 10)
;; key defs
(define-key scim-on-key? 'generic-on-key?)
(define-key scim-off-key? 'generic-off-key?)
;; widgets and actions
;; widgets
(define scim-widgets '(widget_scim_input_mode))
;; default activity for each widgets
(define default-widget_scim_input_mode 'action_scim_off)
;; actions of widget_scim_input_mode
(define scim-input-mode-actions
'(action_scim_off
action_scim_on))
;;; implementations
(register-action 'action_scim_off
(lambda (mc)
(list
'off
"-"
(N_ "off")
(N_ "Direct Input Mode")))
(lambda (mc)
(not (scim-context-on mc)))
(lambda (mc)
(scim-context-set-on! mc #f)))
(register-action 'action_scim_on
(lambda (mc)
(let* ((im (scim-context-im mc))
(name (symbol->string (im-name im))))
(list
'on
"O"
(N_ "on")
(string-append name (N_ " Mode")))))
(lambda (mc)
(scim-context-on mc))
(lambda (mc)
(scim-context-set-on! mc #t)))
;; Update widget definitions based on action configurations. The
;; procedure is needed for on-the-fly reconfiguration involving the
;; custom API
(define scim-configure-widgets
(lambda ()
(register-widget 'widget_scim_input_mode
(activity-indicator-new scim-input-mode-actions)
(actions-new scim-input-mode-actions))))
(define scim-context-rec-spec
(append
context-rec-spec
;; renamed from 'id' to avoid conflict with context-id
'((mc-id #f)
(on #f)
(showing-candidate #f))))
(define-record 'scim-context scim-context-rec-spec)
(define scim-context-new-internal scim-context-new)
(define scim-context-new
(lambda (id im name)
(let ((mc (scim-context-new-internal id im))
(mc-id (scim-lib-alloc-context name)))
(scim-context-set-widgets! mc scim-widgets)
(scim-context-set-mc-id! mc mc-id)
mc)))
(define scim-update-preedit
(lambda (mc)
(let* ((mid (scim-context-mc-id mc)))
(if (scim-lib-preedit-changed? mid)
(if (scim-lib-compose-mode? mid)
(begin
(im-clear-preedit mc)
(im-pushback-preedit mc
preedit-underline
(scim-lib-get-left-of-candidate mid))
(im-pushback-preedit mc
(+ preedit-reverse preedit-cursor)
(scim-lib-get-selected-candidate mid))
(im-pushback-preedit mc
preedit-underline
(scim-lib-get-right-of-candidate mid))
(im-update-preedit mc))
(begin
(im-clear-preedit mc)
(im-pushback-preedit mc
preedit-underline
(scim-lib-get-left-of-cursor mid))
(im-pushback-preedit mc
preedit-cursor "")
(im-pushback-preedit mc
preedit-underline
(scim-lib-get-right-of-cursor mid))
(im-update-preedit mc))
)))))
(define scim-update-candidate
(lambda (mc)
(scim-lib-fill-new-candidates! (scim-context-mc-id mc))
(let* ((mid (scim-context-mc-id mc))
(max (scim-lib-get-nr-candidates mid))
(showing-candidate? (scim-context-showing-candidate mc))
(candidates-changed? (scim-lib-candidates-changed? mid)))
;; FIXME: Rewrite this seriese of if with cond.
;; close candidate window
(if (or
(and showing-candidate? candidates-changed?)
(and showing-candidate? (not (scim-lib-candidate-show? mid))))
(begin
(im-deactivate-candidate-selector mc mid)
(scim-context-set-showing-candidate! mc #f)))
(if (and
(or
candidates-changed?
(and
(not showing-candidate?)
(scim-lib-candidate-show? mid)))
(not (= max 0)))
(begin
(im-activate-candidate-selector
mc max scim-candidate-max)
(im-select-candidate
mc (scim-lib-get-candidate-index mid))
(scim-context-set-showing-candidate! mc #t)))
(if (and showing-candidate?
(scim-lib-candidate-show? mid))
(im-select-candidate mc (scim-lib-get-candidate-index mid))))))
(define scim-append-modifiers
(lambda (key key-state key-str)
(if (shift-key-mask key-state)
(set! key-str (string-append "S-" key-str)))
(if (control-key-mask key-state)
(set! key-str (string-append "C-" key-str)))
(if (alt-key-mask key-state)
(set! key-str (string-append "A-" key-str)))
(if (meta-key-mask key-state)
(set! key-str (string-append "M-" key-str)))
key-str))
(define scim-proc-direct-state
(lambda (mc key key-state)
(if (scim-on-key? key key-state)
(scim-context-set-on! mc #t)
(scim-commit-raw mc))))
(define scim-commit-raw
(lambda (mc)
(im-commit-raw mc)))
; Unfortunatelly, we don't have simple way to translate...
(define scim-translate-ukey-to-mkey
(lambda (key key-state)
(scim-append-modifiers
key key-state
(cdr (assq key
'((backspace . "BackSpace")
(delete . "Delete")
(escape . "Escape")
(return . "Return")
(tab . "Tab")
(left . "Left")
(up . "Up")
(right . "Right")
(down . "Down")
(prior . "Page_Down")
(next . "Page_Up")
(home . "Home")
(end . "End")
(zenkaku-hankaku . "")
(Multi_key . "")
(Mode_switch . "")
(Henkan_Mode . "")
(Muhenkan . "")
(Kanji . "")
(hiragana-katakana . "")
(F1 . "F1")
(F2 . "F2")
(F3 . "F3")
(F4 . "F4")
(F5 . "F5")
(F6 . "F6")
(F7 . "F7")
(F8 . "F8")
(F9 . "F9")
(F10 . "F10")
(F11 . "F11")
(F12 . "F12")
(F13 . "F13")
(F14 . "F14")
(F15 . "F15")
(F16 . "F16")
(F17 . "F17")
(F18 . "F18")
(F19 . "F19")
(F20 . "F20")))))))
(define scim-init-handler
(lambda (id im arg)
(scim-context-new id im arg)))
(define scim-release-handler
(lambda (mc)
#f))
(define scim-push-key
(lambda (mc key key-state)
(let* ((mid (scim-context-mc-id mc)))
(cond
((scim-off-key? key key-state)
(scim-context-set-on! mc #f)
#t) ;; #t means key event was consumed.
((symbol? key)
(let ((mkey (scim-translate-ukey-to-mkey key key-state)))
(scim-lib-push-symbol-key mid mkey)))
(else
(scim-lib-push-key mid key key-state))))))
(define scim-press-key-handler
(lambda (mc key key-state)
(let* ((mid (scim-context-mc-id mc)))
(if (scim-context-on mc)
(if (scim-push-key mc key key-state)
#f ;; Discard key event
(let* ((result (scim-lib-get-result mid))
(consumed? (car result))
(commit-str (cdr result)))
(if (string=? commit-str "")
(im-commit-raw mc)
(begin
(im-commit mc commit-str)
(scim-lib-commit mid)
(if (not consumed?)
(im-commit-raw mc))))))
(scim-proc-direct-state mc key key-state))
(scim-update-preedit mc)
(scim-update-candidate mc))))
(define scim-release-key-handler
(lambda (mc key key-state)
#f))
(define scim-reset-handler
(lambda (mc)
#f))
(define scim-get-candidate-handler
(lambda (mc idx accel-enum-hint)
(let* ((mid (scim-context-mc-id mc))
(cand (scim-lib-get-nth-candidate
mid idx)))
(list cand (digit->string (+ idx 1)) ""))))
(define scim-set-candidate-index-handler
(lambda (mc idx)
#f))
;; Developer specified IM rejection should be completely withdrawn
;; after we got flexible install-time IM preference list. These
;; redundant IMs should be "disabled by default, but can be enabled"
;; under the feature. But we should invest our time for more valuable
;; issues. -- YamaKen 2005-01-25
(define duplicated-im-list
'("scim-ja-anthy"
"scim-ja-tcode"
"scim-zh-pinyin"
"scim-zh-py"))
;; At now, simply enable all IMs. Although they are redundant and
;; unconfortable, they can be disabled by uim-pref.
;; -- YamaKen 2005-01-25
(define duplicated-im?
(if #t
(lambda (name)
#f)
(lambda (name)
(member name duplicated-im-list))))
(define scim-register
(lambda (i nr-im)
(if (> nr-im i)
(begin
(if (not (duplicated-im? (scim-lib-nth-input-method-name i)))
(register-im
(string->symbol (scim-lib-nth-input-method-name i))
(scim-lib-nth-input-method-lang i)
"UTF-8"
(scim-lib-nth-input-method-name i)
(N_ "An input method provided by the scim library")
(scim-lib-nth-input-method-name i)
scim-init-handler
scim-release-handler
context-mode-handler
scim-press-key-handler
scim-release-key-handler
scim-reset-handler
scim-get-candidate-handler
scim-set-candidate-index-handler
context-prop-activate-handler
#f
#f
#f
#f
#f
))
(scim-register (+ i 1) nr-im))
())))
(scim-lib-init)
(scim-register 0 (scim-lib-nr-input-methods))
(scim-configure-widgets)
|