home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / uim / lazy-load.scm < prev    next >
Encoding:
Text File  |  2010-11-07  |  4.0 KB  |  107 lines

  1. ;;; lazy-load.scm: Lazy IM loading support
  2. ;;;
  3. ;;; Copyright (c) 2005-2009 uim Project http://code.google.com/p/uim/
  4. ;;;
  5. ;;; All rights reserved.
  6. ;;;
  7. ;;; Redistribution and use in source and binary forms, with or without
  8. ;;; modification, are permitted provided that the following conditions
  9. ;;; are met:
  10. ;;; 1. Redistributions of source code must retain the above copyright
  11. ;;;    notice, this list of conditions and the following disclaimer.
  12. ;;; 2. Redistributions in binary form must reproduce the above copyright
  13. ;;;    notice, this list of conditions and the following disclaimer in the
  14. ;;;    documentation and/or other materials provided with the distribution.
  15. ;;; 3. Neither the name of authors nor the names of its contributors
  16. ;;;    may be used to endorse or promote products derived from this software
  17. ;;;    without specific prior written permission.
  18. ;;;
  19. ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
  20. ;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. ;;; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. ;;; ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
  23. ;;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  24. ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  25. ;;; OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  26. ;;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  27. ;;; LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  28. ;;; OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. ;;; SUCH DAMAGE.
  30. ;;;;
  31.  
  32. (require "util.scm")
  33.  
  34. (define stub-im-generate-init-handler
  35.   (lambda (name module-name)
  36.     (lambda (id fake-im fake-arg)
  37.       (let* ((stub-im (retrieve-im name))
  38.          (stub-im-init-handler (and stub-im
  39.                     (im-init-handler stub-im))))
  40.     (and (require-module module-name)
  41.          (let* ((im (retrieve-im name))
  42.             (init-handler (im-init-handler im))
  43.             (arg (im-init-arg im))
  44.             (context (if (not (eq? init-handler
  45.                        stub-im-init-handler))
  46.                  (init-handler id im arg)
  47.                  (begin
  48.                    (error "stub IM actualization failed")
  49.                    #f))))
  50.            context))))))
  51.  
  52. (define register-stub-im
  53.   (lambda (name lang encoding name-label short-desc module-name)
  54.     (if (or (not (retrieve-im name))
  55.         (not (im-key-press-handler (retrieve-im name))))
  56.     (let ((init-handler (stub-im-generate-init-handler name module-name)))
  57.       (register-im
  58.        name
  59.        lang
  60.        encoding
  61.        name-label
  62.        short-desc
  63.        #f ;; arg
  64.        init-handler
  65.        #f ;; release-handler
  66.        #f ;; mode-handler
  67.        #f ;; press-key-handler
  68.        #f ;; release-key-handler
  69.        #f ;; reset-handler
  70.        #f ;; get-candidate-handler
  71.        #f ;; set-candidate-index-handler
  72.        #f ;; prop-activate-handler
  73.        #f ;; input-string-handler
  74.        #f ;; focus-in-handler
  75.        #f ;; focus-out-handler
  76.        #f ;; place-handler
  77.        #f ;; displace-handler
  78.        )
  79.       (im-set-module-name! (retrieve-im name) module-name)))))
  80.  
  81. ;; side effect: invoke require-module for all installed IM modules
  82. (define stub-im-generate-stub-im-list
  83.   (lambda (im-names)
  84.     (let ((orig-enabled-im-list enabled-im-list))
  85.       (set! enabled-im-list ())  ;; enable all IMs
  86.       (for-each require-module installed-im-module-list)
  87.       (set! enabled-im-list orig-enabled-im-list))
  88.     (map (lambda (name)
  89.        (let ((im (retrieve-im name)))
  90.          (string-append
  91.           "    (" (symbol->string name) "\n"
  92.           "     \"" (im-lang im) "\"\n"
  93.           "     \"" (im-encoding im) "\"\n"
  94.           "     " (string-escape (im-name-label im)) "\n"
  95.           "     " (string-escape (im-short-desc im)) "\n"
  96.           "     \"" (im-module-name im) "\")\n"
  97.           )))
  98.      im-names)))
  99.  
  100. ;; side effect: invoke require-module for all IM listed in
  101. ;; installed-im-module-list
  102. (define stub-im-generate-all-stub-im-list
  103.   (lambda ()
  104.     (for-each require-module installed-im-module-list)
  105.     (stub-im-generate-stub-im-list (map im-name
  106.                     (reverse im-list)))))
  107.