softkeys.sl 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % SoftKeys.SL - NMODE SoftKeys
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 28 January 1983
  8. %
  9. % This implementation of softkeys is intended primarily for the HP9836
  10. % implementation. It recognizes the escape-sequence Esc-/, followed by
  11. % a single character, as instructing NMODE to execute the softkey
  12. % corresponding to that character. In the HP9836 implementation,
  13. % we can cause the keys K0-K9 to send the appropriate escape sequence.
  14. %
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. (CompileTime (load fast-int fast-strings fast-vectors display-char))
  17. % Global variables defined here:
  18. (fluid '(nmode-softkey-label-screen
  19. nmode-softkey-label-screen-height % number of rows of keys
  20. nmode-softkey-label-screen-width % number of keys per row
  21. ))
  22. % Internal static variables (don't use elsewhere!):
  23. (fluid '(nmode-softkey-defs % vector of softkey definitions (see below)
  24. nmode-softkey-labels % vector of softkey label strings
  25. nmode-softkey-label-width % number of characters wide
  26. nmode-softkey-label-count % number of displayed labels
  27. ))
  28. (when (or (unboundp 'nmode-softkey-defs) (null nmode-softkey-defs))
  29. (setf nmode-softkey-label-screen NIL)
  30. (setf nmode-softkey-label-screen-height 0)
  31. (setf nmode-softkey-label-screen-width 0)
  32. (setf nmode-softkey-defs (make-vector 40 NIL))
  33. (setf nmode-softkey-labels (make-vector 40 NIL))
  34. (setf nmode-softkey-label-width 0)
  35. (setf nmode-softkey-label-count 0)
  36. )
  37. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  38. % Functions:
  39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  40. (de nmode-define-softkey (n fcn label-string)
  41. % N should be a softkey number. FCN should be a function ID, a string,
  42. % or NIL. Define softkey #n to run the specified function, execute the
  43. % specified string (as if typed), or be undefined, respectively.
  44. % LABEL-STRING should be a string or NIL. The string will be centered.
  45. (if (and (valid-softkey-number? n)
  46. (or (null fcn) (idp fcn) (stringp fcn))
  47. (or (null label-string) (stringp label-string))
  48. )
  49. (progn
  50. (vector-store nmode-softkey-defs n fcn)
  51. (vector-store nmode-softkey-labels n label-string)
  52. (nmode-write-softkey-label n)
  53. )
  54. (nmode-error "Invalid arguments to Define Softkey")
  55. ))
  56. (de valid-softkey-number? (n)
  57. (and (fixp n) (>= n 0) (<= n (vector-upper-bound nmode-softkey-defs)))
  58. )
  59. (de softkey-char-to-number (ch)
  60. (- (char-code ch) #/0))
  61. (de softkey-number-to-char (n)
  62. (+ n #/0))
  63. (de nmode-execute-softkey (n)
  64. % Execute softkey #n.
  65. (if (valid-softkey-number? n)
  66. (let ((fcn (vector-fetch nmode-softkey-defs n)))
  67. (cond ((null fcn)
  68. (nmode-error (bldmsg "Softkey %w is undefined." n)))
  69. ((stringp fcn)
  70. (nmode-execute-string fcn))
  71. ((idp fcn)
  72. (apply fcn ()))
  73. (t
  74. (nmode-error (bldmsg "Softkey %w has a bad definition." n)))
  75. ))
  76. (nmode-error (bldmsg "Invalid Softkey specified."))
  77. ))
  78. (de execute-softkey-command (n)
  79. (nmode-set-delayed-prompt "Execute Softkey: ")
  80. (let ((ch (input-direct-terminal-character)))
  81. (nmode-execute-softkey (softkey-char-to-number ch))
  82. ))
  83. (de nmode-setup-softkey-label-screen (sps)
  84. % If the requested size of the softkey label screen is nonzero, then
  85. % create a virtual screen of that size on the given shared screen.
  86. % The requested size is obtained from global variables.
  87. (setf nmode-softkey-label-width 0)
  88. (setf nmode-softkey-label-count 0)
  89. (let ((height nmode-softkey-label-screen-height)
  90. (width nmode-softkey-label-screen-width)
  91. (screen-height (=> sps height))
  92. (screen-width (=> sps width))
  93. )
  94. (setf nmode-softkey-label-screen
  95. (when (and (> height 0) (> width 0) (> screen-width (* 2 width))
  96. (>= screen-height height)
  97. )
  98. (let ((s (make-instance 'virtual-screen
  99. 'screen sps
  100. 'height height
  101. 'width screen-width
  102. 'row-origin (- screen-height height)
  103. 'column-origin 0
  104. )))
  105. (setf nmode-softkey-label-width (/ screen-width width))
  106. (setf nmode-softkey-label-count (* width height))
  107. (=> s set-default-enhancement (=> sps highlighted-enhancement))
  108. s
  109. )))
  110. (when nmode-softkey-label-screen
  111. (for (from i 0 (- nmode-softkey-label-count 1))
  112. (do (nmode-write-softkey-label i)))
  113. (=> nmode-softkey-label-screen expose)
  114. )
  115. ))
  116. (de nmode-write-softkey-label (n)
  117. (when (and nmode-softkey-label-screen
  118. (>= n 0)
  119. (< n nmode-softkey-label-count)
  120. )
  121. (let* ((row (/ n nmode-softkey-label-screen-width))
  122. (lcol (// n nmode-softkey-label-screen-width))
  123. (col (* lcol nmode-softkey-label-width))
  124. (enhancement (if (xor (= (// row 2) 0) (= (// lcol 2) 0))
  125. (dc-make-enhancement-mask INVERSE-VIDEO INTENSIFY)
  126. (dc-make-enhancement-mask INVERSE-VIDEO)
  127. ))
  128. (label (vector-fetch nmode-softkey-labels n))
  129. (bound (if label (string-upper-bound label) -1))
  130. (padding (/ (- nmode-softkey-label-width (+ bound 1)) 2))
  131. )
  132. (=> nmode-softkey-label-screen set-default-enhancement enhancement)
  133. (if (< padding 0) (setf padding 0))
  134. (for (from i 1 padding)
  135. (do (=> nmode-softkey-label-screen write #\space row col)
  136. (setf col (+ col 1))
  137. ))
  138. (for (from i 0 (- (- nmode-softkey-label-width padding) 1))
  139. (do (let ((ch (if (<= i bound)
  140. (string-fetch label i)
  141. #\space
  142. )))
  143. (=> nmode-softkey-label-screen write ch row (+ col i))
  144. )))
  145. )))