home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / MENUSPCS.ZIP / MENEX.S < prev    next >
Encoding:
Text File  |  1987-12-14  |  13.0 KB  |  372 lines

  1. ;;; --------------------------------------------------------
  2. ;;; Menus for Scheme (tm)
  3. ;;; EXAMPLES
  4. ;;; $Revision:   1.2  $    $Date:   14 Dec 1987  0:43:50  $
  5. ;;; --------------------------------------------------------
  6. ;;; Copyright (c) 1987 by Morton Goldberg.  Permission is
  7. ;;; granted to make copies of this program text for
  8. ;;; personal, non-commercial use provided this notice of
  9. ;;; copyright appears in all copies and derived works.  You
  10. ;;; may also distribute unmodified copies of this text as
  11. ;;; shareware.  All other rights reserved.
  12. ;;; --------------------------------------------------------
  13. ;;; Implementation Language: Texas Instruments' PC SCHEME
  14. ;;; (Version 3.0)
  15. ;;; --------------------------------------------------------
  16.  
  17. (writeln "Menu Examples")
  18. (writeln "Copyright (c) 1987 by Morton Goldberg")
  19. (let ((rev-number "$Revision:   1.2  $"))
  20.   ;; Write the revision number string without the leading
  21.   ;; and trailing dollar-signs (which are needed by the
  22.   ;; version control system).
  23.   (writeln (substring rev-number
  24.                       1
  25.                       (sub1 (string-length rev-number)))))
  26.  
  27. ;;; If you have a color monitor and would like to see the
  28. ;;; examples displayed in color, replace FALSE with TRUE in
  29. ;;; the following statement.  If you have a monochrome
  30. ;;; monitor, let it be.
  31. (define *rgb-monitor* #f)
  32.  
  33. ;;; --------------------------------------------------------
  34. ;;; COLOR ATTRIBUTES FOR TEXT WINDOWS
  35. ;;; --------------------------------------------------------
  36.  
  37. ;;; The environment *text-colors* provides a name space from
  38. ;;; which commonly used text window color combinations can
  39. ;;; be extracted.
  40. ;;;
  41. (define *text-colors*
  42.   (make-environment
  43.     ;; The following are the components of the color
  44.     ;; combinations.  They are not intended to be extracted
  45.     ;; from the environment.
  46.     (define text-black   #x00)
  47.     (define text-blue    #x01)
  48.     (define text-green   #x02)
  49.     (define text-cyan    #x03)
  50.     (define text-red     #x04)
  51.     (define text-magenta #x05)
  52.     (define text-amber   #x06)
  53.     (define text-white   #x07)
  54.     (define bkgrnd-black   #x00)
  55.     (define bkgrnd-blue    #x10)
  56.     (define bkgrnd-green   #x20)
  57.     (define bkgrnd-cyan    #x30)
  58.     (define bkgrnd-red     #x40)
  59.     (define bkgrnd-magenta #x50)
  60.     (define bkgrnd-amber   #x60)
  61.     (define bkgrnd-white   #x70)
  62.     ;; The following are the color combinations available for
  63.     ;; use.  They provide a full set of CGA low-intensity
  64.     ;; colors against a white or black background plus the
  65.     ;; respective reverse video colors.
  66.     (define white-black   (+ text-white bkgrnd-black))
  67.     (define white-blue    (+ text-white bkgrnd-blue))
  68.     (define white-green   (+ text-white bkgrnd-green))
  69.     (define white-cyan    (+ text-white bkgrnd-cyan))
  70.     (define white-red     (+ text-white bkgrnd-red))
  71.     (define white-magenta (+ text-white bkgrnd-magenta))
  72.     (define white-amber   (+ text-white bkgrnd-amber))
  73.     (define black-white   (+ text-black bkgrnd-white))
  74.     (define blue-white    (+ text-blue bkgrnd-white))
  75.     (define green-white   (+ text-green bkgrnd-white))
  76.     (define cyan-white    (+ text-cyan bkgrnd-white))
  77.     (define red-white     (+ text-red bkgrnd-white))
  78.     (define magenta-white (+ text-magenta bkgrnd-white))
  79.     (define amber-white   (+ text-amber bkgrnd-white))
  80.     (define black-blue    (+ text-black bkgrnd-blue))
  81.     (define black-green   (+ text-black bkgrnd-green))
  82.     (define black-cyan    (+ text-black bkgrnd-cyan))
  83.     (define black-red     (+ text-black bkgrnd-red))
  84.     (define black-magenta (+ text-black bkgrnd-magenta))
  85.     (define black-amber   (+ text-black bkgrnd-amber))
  86.     (define blue-black    (+ text-blue bkgrnd-black))
  87.     (define green-black   (+ text-green bkgrnd-black))
  88.     (define cyan-black    (+ text-cyan bkgrnd-black))
  89.     (define red-black     (+ text-red bkgrnd-black))
  90.     (define magenta-black (+ text-magenta bkgrnd-black))
  91.     (define amber-black   (+ text-amber bkgrnd-black))))
  92.  
  93. ;;; --------------------------------------------------------
  94. ;;; EXAMPLE 1 -- THE "QUICK BROWN FOX" POPUP TEXT WINDOW
  95. ;;; --------------------------------------------------------
  96. ;;; This example creates a popup text window and moves it
  97. ;;; around on the screen.  The code provides procedures for
  98. ;;; performing vertical (top, center, and bottom) and
  99. ;;; horizontal (left, center, and right) justification of a
  100. ;;; popup text window.
  101.  
  102. ;;; Procedure for demonstrating the "quick brown fox"
  103. ;;; example.  After typing (do-fox) to start the demo, you
  104. ;;; must type [Esc] five times to complete it.  The window
  105. ;;; will move to a new position each time [Esc] is typed,
  106. ;;; excepting the 5-th [Esc], which ends the demo.
  107. ;;;
  108. (define (do-fox)
  109.   (v-justify 'TOP fox-popup)
  110.   (h-justify 'LEFT fox-popup)
  111.   (send fox-popup popup)
  112.   (v-justify 'TOP fox-popup)
  113.   (h-justify 'RIGHT fox-popup)
  114.   (send fox-popup popup)
  115.   (v-justify 'BOTTOM fox-popup)
  116.   (h-justify 'RIGHT fox-popup)
  117.   (send fox-popup popup)
  118.   (v-justify 'BOTTOM fox-popup)
  119.   (h-justify 'LEFT fox-popup)
  120.   (send fox-popup popup)
  121.   (v-justify 'CENTER fox-popup)
  122.   (h-justify 'CENTER fox-popup)
  123.   (send fox-popup popup))
  124.  
  125. ;;; This is the init-list for the "quick brown fox" popup
  126. ;;; text window; it determines the visual properties (screen
  127. ;;; position, colors, format) of the window.
  128. ;;;
  129. (define *fox-data*
  130.   (let ((attr1 (if *rgb-monitor*
  131.                    (access black-green *text-colors*)
  132.                    (access black-white *text-colors*))))
  133.     `('w-top 1
  134.       'w-left 1
  135.       'n-attr ,attr1
  136.       'border? #t)))
  137.  
  138. ;;; This is text of the "quick brown fox" popup text window.
  139. ;;; It is supplied to the window as a vector of text
  140. ;;; strings, one string for each line of displayed text.
  141. ;;;
  142. (define *fox-text*
  143.   '#("The quick brown fox jumped"
  144.      "over the lazy dog.  The quick"
  145.      "brown fox jumped over the"
  146.      "lazy dog."
  147.      ""
  148.      "Press [Esc] to Proceed"))
  149.  
  150. ;;; Create the "quick brown fox" popup text window.
  151. ;;;
  152. (define fox-popup
  153.   (make-popup-text-window *fox-data* *fox-text*))
  154.  
  155. ;;; --------------------------------------------------------
  156. ;;; EXAMPLE 2 -- A VERTICAL AND A HORIZONTAL MENU
  157. ;;; --------------------------------------------------------
  158. ;;; This example creates a horizontal menu and a vertical
  159. ;;; menu, both offering the same choices.  The menus invoke
  160. ;;; commonly used Scheme facilities such as the garbage
  161. ;;; collector.  To experiment with a menu, type (do-h) to
  162. ;;; get the horizontal menu or (do-v) to get the vertical
  163. ;;; one.
  164.  
  165. ;;; Procedure for demonstrating the vertical menu.  This
  166. ;;; menu will appear with its 2-nd item highlighted.
  167. ;;;
  168. (define (do-v)
  169.   (send vertical set-item-index 2)
  170.   (send vertical popup))
  171.  
  172. ;;; Procedure for demonstrating the horizontal menu.
  173. ;;;
  174. (define (do-h)
  175.   (send horizontal popup))
  176.  
  177. ;;; --------------------------------------------------------
  178. ;;; EXECUTE A DOS COMMAND
  179. ;;;
  180. ;;; The following code creates a two-line popup query window
  181. ;;; which prompts for a DOS command.  To activate the window,
  182. ;;; type (do-dos).  After the command is entered and [Enter]
  183. ;;; is pressed, the DOS command is executed and the window
  184. ;;; is erased.
  185.  
  186. ;;; This is the init-list for the DOS-command popup query
  187. ;;; window; it determines the visual properties (screen
  188. ;;; position, colors, format) of the window.
  189. ;;;
  190. (define *query-data*
  191.   (let ((attr1 (if *rgb-monitor*
  192.                    (access white-blue *text-colors*)
  193.                    (access black-white *text-colors*)))
  194.         (attr2 (if *rgb-monitor*
  195.                    (access black-white *text-colors*)
  196.                    (access white-black *text-colors*))))
  197.     `('w-top 4
  198.       'w-left 35
  199.       'cursor-row 1
  200.       'cursor-col 0
  201.       'input-width 40
  202.       'n-attr ,attr1
  203.       'hl-attr ,attr2
  204.       'border? #t)))
  205.  
  206. ;;; This is the vector of text strings for the DOS-command
  207. ;;; popup query window.  Note that the 2-nd element is an
  208. ;;; empty string; it serves as a place holder for the
  209. ;;; type-in area.
  210. ;;;
  211. (define *query-text*
  212.   '#("Enter a DOS Command or Press [Esc] to Cancel" ""))
  213.  
  214. ;;; Create the DOS-command popup query window.
  215. ;;;
  216. (define dos-cmd
  217.   (make-popup-query-window *query-data* *query-text*))
  218.  
  219. ;;; Activate the DOS-command popup query window.  Call DOS
  220. ;;; with the string typed-in by the user.
  221. ;;;
  222. (define (do-dos)
  223.   (send dos-cmd popup)
  224.   (let ((cmd (send dos-cmd get-response)))
  225.     (if (> (string-length cmd) 0)
  226.       (dos-call "" cmd 16384))))
  227.  
  228. ;;; --------------------------------------------------------
  229. ;;; REPORT ON FREE SPACE
  230. ;;;
  231. ;;; The following code creates a two-line popup text window
  232. ;;; which shows the amount to free space remaining to Scheme
  233. ;;; at the time the window is exposed.  To activate the
  234. ;;; window type (do-freesp).  Press [ESC] to erase the
  235. ;;; window.
  236.  
  237. ;;; This is the init-list for the report-free-space popup
  238. ;;; text window; it determines the visual properties (screen
  239. ;;; position, colors, format) of the window.
  240. ;;;
  241. (define *freesp-data*
  242.   (let ((attr1 (if *rgb-monitor*
  243.                    (access white-blue *text-colors*)
  244.                    (access black-white *text-colors*))))
  245.     `('w-top 4
  246.       'w-left 41
  247.       'n-attr ,attr1
  248.       'border? #t)))
  249.  
  250. ;;; Create the report-free-space popup text window.
  251. (define freesp-rpt
  252.   (let ((dummy-text '#(" ")))
  253.     (make-popup-text-window *freesp-data*
  254.                             dummy-text)))
  255.  
  256. ;;; Activate the report-free-space popup text window.
  257. ;;;
  258. (define (do-freesp)
  259.   (let ((line-1 (string-append "Free Space Remaining: "
  260.                                (integer->string (freesp)
  261.                                                 10)))
  262.         (line-2 "Press [Esc] to Proceed"))
  263.     (send freesp-rpt set-text (vector line-1 line-2))
  264.     (send freesp-rpt popup)))
  265.  
  266. ;;; --------------------------------------------------------
  267. ;;; DO A COMPACTING GARBAGE COLLECTION
  268. ;;;
  269. (define (do-gc)
  270.   (gc #t))
  271.  
  272. ;;; --------------------------------------------------------
  273. ;;; EXIT FROM THE MENU -- SAME A PRESSING ESC
  274. ;;;
  275. (define (do-abort)
  276.   'USER-ABORT)
  277.  
  278. ;;; --------------------------------------------------------
  279. ;;; EXIT TO DOS
  280. ;;;
  281. (define (do-exit)
  282.   (exit))
  283.  
  284. ;;; --------------------------------------------------------
  285. ;;; MENUS PROVIDING THE SERVICES DEFINED ABOVE
  286.  
  287. ;;; This is the item-list for both menus; it determines the
  288. ;;; selections provided to the user by the menus.
  289. ;;;
  290. (define *item-list*
  291.   `(("Do a DOS command" (#\d #\D) ,do-dos)
  292.     ("report Free space" (#\f #\F) ,do-freesp)
  293.     ("Garbage collect" (#\g #\G) ,do-gc)
  294.     ("Exit menu" (#\e #\E) ,do-abort)
  295.     ("eXit to DOS" (#\x #\X) ,do-exit)))
  296.  
  297. ;;; This is the init-list for the vertical form of the menu.
  298. ;;; It determines the visual properties (screen position,
  299. ;;; colors, format) of the menu.
  300. ;;;
  301. (define *vertical-menu-data*
  302.   (let ((attr1 (if *rgb-monitor*
  303.                    (access white-blue *text-colors*)
  304.                    (access black-white *text-colors*)))
  305.         (attr2 (if *rgb-monitor*
  306.                    (access white-red *text-colors*)
  307.                    (access white-black *text-colors*))))
  308.     `('w-top 1
  309.       'w-left 1
  310.       'n-attr ,attr1
  311.       'hl-attr ,attr2
  312.       'border? #t)))
  313.  
  314. ;;; Create the vertical version of the menu.
  315. ;;;
  316. (define vertical
  317.   (make-vertical-menu *vertical-menu-data*
  318.                       *item-list*))
  319.  
  320. ;;; This is the init-list for the horizontal form of the
  321. ;;; menu.
  322. ;;;
  323. (define *horizontal-menu-data*
  324.   (let ((attr1 (if *rgb-monitor*
  325.                    (access white-blue *text-colors*)
  326.                    (access black-white *text-colors*)))
  327.         (attr2 (if *rgb-monitor*
  328.                    (access white-red *text-colors*)
  329.                    (access white-black *text-colors*))))
  330.     `('w-top 1
  331.       'w-left 1
  332.       'n-attr ,attr1
  333.       'hl-attr ,attr2
  334.       'border? #t
  335.       'label-spacing 2)))
  336.  
  337. ;;; Create the horizontal version of the menu.
  338. ;;;
  339. (define horizontal
  340.   (make-horizontal-menu *horizontal-menu-data*
  341.                         *item-list*))
  342.  
  343. ;;; --------------------------------------------------------
  344. ;;; Just for fun, here is a menu that runs all the examples
  345. ;;; in this file.
  346. ;;; 
  347. (define *examples*
  348.   `(("Quick fox example" (#\q #\Q) ,do-fox)
  349.     ("Horizontal menu example" (#\h #\H) ,do-h)
  350.     ("Vertical menu example" (#\v #\V) ,do-v)
  351.     ("Exit menu" (#\e #\E) ,do-abort)))
  352.  
  353. (define *demo-menu* '())
  354.  
  355. ;;; This procedure constructs the demo menu the first time
  356. ;;; it is called, but only brings it back to the screen
  357. ;;; after the first time.  Because there is no reason for
  358. ;;; this menu to be different, *vertical-menu-data* is used
  359. ;;; for the init-list.
  360. ;;; 
  361. (define (menus)
  362.   (if (null? *demo-menu*)
  363.     (begin
  364.       (set! *demo-menu*
  365.             (make-vertical-menu *vertical-menu-data*
  366.                                 *examples*))
  367.       (v-justify 'CENTER *demo-menu*)
  368.       (h-justify 'CENTER *demo-menu*)))
  369.   (send *demo-menu* popup))
  370.  
  371. ;;; --------------------------------------------------------
  372.