screen-layout.sl 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Screen-Layout.SL
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 19 August 1982
  8. % Revised: 18 February 1983
  9. %
  10. % This file contains functions that manage the screen layout for NMODE.
  11. %
  12. % 18-Feb-83 Alan Snyder
  13. % Add new function: find-buffer-in-exposed-windows.
  14. % 16-Feb-83 Alan Snyder
  15. % Declare -> Declare-Flavor.
  16. % 7-Feb-83 Alan Snyder
  17. % Revise handling of refresh breakout to allow refresh-one-window to work.
  18. % 31-Jan-83 Alan Snyder
  19. % Revise for new interpretation of argument to buffer-window$set-size.
  20. % Make input window an unlabeled buffer-window.
  21. % 27-Jan-83 Alan Snyder
  22. % Added (optional) softkey label screen.
  23. % 7-Jan-83 Alan Snyder
  24. % Change ENTER-RAW-MODE to not touch the other screen unless we are in
  25. % two-screen mode.
  26. % 6-Jan-83 Alan Snyder
  27. % Change NMODE-SELECT-MAJOR-WINDOW to also deexpose input window.
  28. % 30-Dec-82 Alan Snyder
  29. % Added two-screen mode. Minor change to NMODE-SELECT-WINDOW to make
  30. % things more graceful when using direct writing.
  31. % 20-Dec-82 Alan Snyder
  32. % Added declarations and made other small changes to improve efficiency by
  33. % reducing the amount of run-time method lookup. Fixed efficiency bug in
  34. % NMODE-NEW-TERMINAL: it failed to de-expose old screens and windows.
  35. %
  36. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  37. (BothTimes (load objects))
  38. (CompileTime (load display-char))
  39. % External variables used here:
  40. (fluid '(
  41. nmode-command-argument-given
  42. nmode-command-argument
  43. browser-split-screen
  44. ))
  45. % Options:
  46. (fluid '(
  47. nmode-allow-refresh-breakout % Abort refresh if user types something
  48. nmode-normal-enhancement % Display enhancement for normal text
  49. nmode-inverse-enhancement % Display enhancement for "inverse video" text
  50. ))
  51. % Global variables defined here:
  52. (fluid '(
  53. nmode-current-buffer % buffer that commands operate on
  54. nmode-current-window % window displaying current buffer
  55. nmode-major-window % the user's idea of nmode-current-window
  56. nmode-layout-mode % either 1 or 2
  57. nmode-two-screens? % T => each window has its own screen
  58. nmode-input-window % window used for string input
  59. nmode-message-screen % screen displaying NMODE "message"
  60. nmode-prompt-screen % screen displaying NMODE "prompt"
  61. nmode-main-buffer % buffer "MAIN"
  62. nmode-output-buffer % buffer "OUTPUT" (used for PSL output)
  63. nmode-input-buffer % internal buffer used for string input
  64. nmode-softkey-label-screen % screen displaying softkey labels (or NIL)
  65. nmode-terminal % the terminal object
  66. nmode-physical-screen % the physical screen object
  67. nmode-screen % the shared screen object
  68. nmode-other-terminal % the other terminal object (two-screen mode)
  69. nmode-other-physical-screen % the other physical screen object
  70. nmode-other-screen % the other shared screen object
  71. ))
  72. % Internal static variables:
  73. (fluid '(
  74. nmode-top-window % the top or full major window
  75. nmode-bottom-window % the bottom major window
  76. full-refresh-needed % next refresh should clear the screen first
  77. nmode-breakout-occurred? % last refresh was interrupted
  78. nmode-total-lines % total number of screen lines for window(s)
  79. nmode-top-lines % number of screen lines for top window
  80. nmode-inverse-video? % Display using "inverse video"
  81. nmode-blank-screen % blank screen used to clear the display
  82. ))
  83. (declare-flavor buffer-window
  84. nmode-current-window
  85. nmode-top-window nmode-bottom-window nmode-input-window)
  86. (declare-flavor virtual-screen
  87. nmode-blank-screen)
  88. (declare-flavor shared-physical-screen
  89. nmode-screen
  90. nmode-other-screen)
  91. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  92. % Initialization Function:
  93. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  94. (de nmode-initialize-screen-layout ()
  95. % This function is called as part of NMODE initialization, which occurs
  96. % before NMODE is saved.
  97. (setf nmode-allow-refresh-breakout T)
  98. (setf nmode-normal-enhancement (dc-make-enhancement-mask))
  99. (setf nmode-inverse-enhancement
  100. (dc-make-enhancement-mask INVERSE-VIDEO INTENSIFY))
  101. (setf nmode-inverse-video? NIL)
  102. (nmode-default-terminal)
  103. )
  104. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  105. % Functions for changing the screen layout:
  106. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  107. (de nmode-1-window ()
  108. (nmode-expand-top-window)
  109. )
  110. (de nmode-expand-top-window ()
  111. % This function does nothing if already in 1-window mode.
  112. % Otherwise: expands the top window to fill the screen; the top window
  113. % becomes current.
  114. (when (not (= nmode-layout-mode 1))
  115. (nmode-select-window nmode-top-window)
  116. (=> nmode-bottom-window deexpose)
  117. (setf nmode-layout-mode 1)
  118. (nmode-set-window-sizes)
  119. ))
  120. (de nmode-expand-bottom-window ()
  121. % This function does nothing if already in 1-window mode.
  122. % Otherwise: expands the bottom window to fill the screen; the bottom
  123. % window becomes current.
  124. (when (not (= nmode-layout-mode 1))
  125. (psetf nmode-top-window nmode-bottom-window
  126. nmode-bottom-window nmode-top-window)
  127. (nmode-expand-top-window)
  128. ))
  129. (de nmode-2-windows ()
  130. % This function does nothing if already in 2-window mode.
  131. % Otherwise: shrinks the top window and exposes the bottom window.
  132. (cond
  133. ((not (= nmode-layout-mode 2))
  134. (setf nmode-layout-mode 2)
  135. (nmode-set-window-sizes)
  136. )))
  137. (de nmode-set-window-position (p)
  138. (selectq p
  139. (FULL (nmode-1-window))
  140. (TOP (nmode-2-windows) (nmode-select-window nmode-top-window))
  141. (BOTTOM (nmode-2-windows) (nmode-select-window nmode-bottom-window))
  142. ))
  143. (de nmode-exchange-windows ()
  144. % Exchanges the current window with the other window, which becomes current.
  145. % In two window mode, the windows swap physical positions.
  146. (let ((w (nmode-other-window)))
  147. (psetf nmode-top-window nmode-bottom-window
  148. nmode-bottom-window nmode-top-window)
  149. (nmode-set-window-sizes)
  150. (nmode-select-window w)
  151. ))
  152. (de nmode-grow-window (n)
  153. % Increase (decrease if n<0) the size of the current window by N lines.
  154. % Does nothing and returns NIL if not in 2-window mode.
  155. (selectq (nmode-window-position)
  156. (FULL
  157. NIL
  158. )
  159. (TOP
  160. (setf nmode-top-lines (+ nmode-top-lines n))
  161. (nmode-set-window-sizes)
  162. T
  163. )
  164. (BOTTOM
  165. (setf nmode-top-lines (- nmode-top-lines n))
  166. (nmode-set-window-sizes)
  167. T
  168. )))
  169. (de nmode-expose-output-buffer (b)
  170. % Buffer B is being used as an output channel. It is not currently being
  171. % displayed. Cause it to be displayed (in the "other window", if we
  172. % are already in 2-window mode, in the bottom window otherwise).
  173. (nmode-2-windows)
  174. (window-select-buffer (nmode-other-window) b)
  175. )
  176. (de nmode-normal-video ()
  177. % Cause the display to use "normal" video polarity.
  178. (when nmode-inverse-video?
  179. (setf nmode-inverse-video? NIL)
  180. (nmode-establish-video-polarity)
  181. ))
  182. (de nmode-inverse-video ()
  183. % Cause the display to use "inverse" video polarity.
  184. (when (not nmode-inverse-video?)
  185. (setf nmode-inverse-video? T)
  186. (nmode-establish-video-polarity)
  187. ))
  188. (de nmode-invert-video ()
  189. % Toggle between normal and inverse video.
  190. (setf nmode-inverse-video? (not nmode-inverse-video?))
  191. (nmode-establish-video-polarity)
  192. )
  193. (de nmode-use-two-screens ()
  194. % If two screens are available, use them both.
  195. (when (and nmode-other-screen (not nmode-two-screens?))
  196. (when (not (=> nmode-other-terminal raw-mode))
  197. (=> nmode-other-terminal enter-raw-mode)
  198. (setf full-refresh-needed t)
  199. )
  200. (setf nmode-two-screens? T)
  201. (setf browser-split-screen T)
  202. (setf nmode-layout-mode 2)
  203. (nmode-set-window-sizes)
  204. ))
  205. (de nmode-use-one-screen ()
  206. % Use only the main screen.
  207. (when nmode-two-screens?
  208. (setf nmode-two-screens? NIL)
  209. (nmode-set-window-sizes)
  210. (if nmode-other-screen (=> nmode-other-screen refresh)) % clear it
  211. ))
  212. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  213. % Screen Layout Commands:
  214. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  215. (de one-window-command ()
  216. % The "C-X 1" command. Return to one window mode.
  217. (when (not (= nmode-layout-mode 1))
  218. (if nmode-command-argument-given
  219. (nmode-expand-bottom-window)
  220. (nmode-expand-top-window)
  221. )))
  222. (de two-windows-command ()
  223. % The "C-X 2" command. The bottom window is selected.
  224. (when (not (= nmode-layout-mode 2))
  225. (nmode-2-windows)
  226. (if nmode-command-argument-given
  227. (window-copy-buffer nmode-top-window nmode-bottom-window))
  228. (nmode-switch-windows)
  229. ))
  230. (de view-two-windows-command ()
  231. % The "C-X 3" command. The top window remains selected.
  232. (when (not (= nmode-layout-mode 2))
  233. (nmode-2-windows)
  234. (if nmode-command-argument-given
  235. (window-copy-buffer nmode-top-window nmode-bottom-window))
  236. ))
  237. (de grow-window-command ()
  238. (if (not (nmode-grow-window nmode-command-argument))
  239. (nmode-error "Not in 2-window mode!")
  240. ))
  241. (de other-window-command ()
  242. (let ((old-buffer nmode-current-buffer))
  243. (nmode-switch-windows)
  244. (if nmode-command-argument-given
  245. (buffer-select old-buffer))
  246. ))
  247. (de exchange-windows-command ()
  248. (selectq nmode-layout-mode
  249. (1 (Ding))
  250. (2 (nmode-exchange-windows))
  251. ))
  252. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  253. % Window Selection Functions:
  254. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  255. (de nmode-select-window (window)
  256. % Expose the specified window and make it the "current" window.
  257. % Its buffer becomes the "current" buffer. This is the only function that
  258. % should set the variable "NMODE-CURRENT-WINDOW".
  259. (when (not (eq window nmode-current-window))
  260. (if nmode-current-window (=> nmode-current-window deselect))
  261. (when (not (eq window nmode-input-window))
  262. (setf nmode-major-window window)
  263. (when (not (eq nmode-current-window nmode-input-window))
  264. (reset-message)
  265. ))
  266. (setf nmode-current-window window)
  267. (=> window expose)
  268. (=> window select)
  269. (setf nmode-current-buffer (=> window buffer))
  270. (nmode-establish-current-mode)
  271. ))
  272. (de nmode-switch-windows ()
  273. % Select the "other" window.
  274. (selectq nmode-layout-mode
  275. (2 (nmode-select-window (nmode-other-window)))
  276. (1 (nmode-exchange-windows))
  277. ))
  278. (de nmode-select-major-window ()
  279. % This function is used for possible error recovery. It ensures that the
  280. % current window is one of the exposed major windows (not, for example, the
  281. % INPUT window) and that the INPUT window is deexposed.
  282. (if (not (or (eq nmode-current-window nmode-top-window)
  283. (eq nmode-current-window nmode-bottom-window)
  284. ))
  285. (nmode-select-window nmode-top-window)
  286. )
  287. (=> nmode-input-window deexpose)
  288. )
  289. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  290. % Screen Information Functions:
  291. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  292. (de nmode-window-position ()
  293. (cond ((= nmode-layout-mode 1) 'FULL)
  294. ((eq nmode-current-window nmode-top-window) 'TOP)
  295. (t 'BOTTOM)
  296. ))
  297. (de nmode-other-window ()
  298. % Return the "other" window.
  299. (if (eq nmode-current-window nmode-top-window)
  300. nmode-bottom-window
  301. nmode-top-window
  302. ))
  303. (de find-buffer-in-windows (b)
  304. % Return a list containing the windows displaying the specified buffer.
  305. % The windows may or may not be displayed.
  306. (for (in w (list nmode-bottom-window nmode-top-window))
  307. % Put bottom window first in this list so that it will be
  308. % the one that is automatically adjusted on output if the
  309. % output buffer is being displayed by both windows.
  310. (when (eq b (=> w buffer)))
  311. (collect w))
  312. )
  313. (de find-buffer-in-exposed-windows (b)
  314. % Return a list containing the exposed windows displaying the specified
  315. % buffer.
  316. (for (in w (find-buffer-in-windows b))
  317. (when (=> w exposed?))
  318. (collect w))
  319. )
  320. (de buffer-is-displayed? (b)
  321. % Return T if the specified buffer is being displayed by an active window.
  322. (not
  323. (for (in w (nmode-active-windows))
  324. (never (eq b (=> w buffer)))
  325. )))
  326. (de nmode-active-windows ()
  327. (selectq nmode-layout-mode
  328. (1 (list nmode-top-window))
  329. (2 (list nmode-top-window nmode-bottom-window))
  330. ))
  331. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  332. % Typeout Functions:
  333. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  334. (de nmode-begin-typeout ()
  335. % Call this function before doing typeout using the standard output channel.
  336. % Someday this will do something clever, but for now it merely clears the
  337. % screen.
  338. (nmode-clear-screen)
  339. )
  340. (de nmode-end-typeout ()
  341. % Call this function after doing typeout using the standard output channel.
  342. % Someday this will do something clever, but for now it merely waits for
  343. % the user to type a character.
  344. (pause-until-terminal-input)
  345. )
  346. (de nmode-clear-screen ()
  347. % This is somewhat of a hack to clear the screen for normal typeout. The
  348. % next time a refresh is done, a full refresh will be done automatically.
  349. (=> nmode-blank-screen expose)
  350. (=> nmode-screen full-refresh NIL)
  351. (setf full-refresh-needed t)
  352. )
  353. (de Enter-Raw-Mode ()
  354. % Use this function to enter "raw mode", in which terminal input is not
  355. % echoed and special terminal keys are enabled. The next REFRESH will
  356. % automatically be a "full" refresh.
  357. (when (not (=> nmode-terminal raw-mode))
  358. (=> nmode-terminal enter-raw-mode)
  359. (setf full-refresh-needed t)
  360. )
  361. (when (and nmode-two-screens?
  362. nmode-other-terminal
  363. (not (=> nmode-other-terminal raw-mode)))
  364. (=> nmode-other-terminal enter-raw-mode)
  365. (setf full-refresh-needed t)
  366. )
  367. )
  368. (de leave-raw-mode ()
  369. % Use this function to leave "raw mode", i.e. turn on echoing of terminal
  370. % input and disable any special terminal keys. The cursor is positioned
  371. % on the last line of the screen, which is cleared.
  372. (when (=> nmode-terminal raw-mode)
  373. (=> nmode-terminal move-cursor (=> nmode-terminal maxrow) 0)
  374. (=> nmode-terminal clear-line)
  375. (=> nmode-terminal leave-raw-mode)
  376. ))
  377. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  378. % Refresh functions:
  379. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  380. (de nmode-refresh ()
  381. % This function refreshes the screen. It first ensures that all exposed
  382. % NMODE windows update their corresponding virtual screens. Then, it
  383. % asks the window package to update the display. A "full refresh" will
  384. % be done if some prior operation has indicated the need for one.
  385. (cond (full-refresh-needed
  386. (nmode-full-refresh))
  387. (t
  388. (nmode-refresh-windows)
  389. (when (not nmode-breakout-occurred?)
  390. (=> nmode-screen refresh nmode-allow-refresh-breakout)
  391. (if (and nmode-other-screen nmode-two-screens?)
  392. (=> nmode-other-screen refresh nmode-allow-refresh-breakout))
  393. ))))
  394. (de nmode-full-refresh ()
  395. % This function refreshes the screen after first clearing the terminal
  396. % display. It it used when the state of the terminal display is in doubt.
  397. (nmode-refresh-windows)
  398. (when (not (setf full-refresh-needed nmode-breakout-occurred?))
  399. (=> nmode-screen full-refresh nil)
  400. (if (and nmode-other-screen nmode-two-screens?)
  401. (=> nmode-other-screen full-refresh nil))
  402. ))
  403. (de nmode-refresh-one-window (w)
  404. % This function refreshes the display, but only updates the virtual screen
  405. % corresponding to the specified window.
  406. (cond (full-refresh-needed
  407. (nmode-full-refresh))
  408. (nmode-breakout-occurred?
  409. (nmode-refresh))
  410. (t
  411. (if (eq (=> nmode-screen owner 0 0) nmode-blank-screen) % hack!
  412. (=> nmode-blank-screen deexpose))
  413. (nmode-adjust-window w)
  414. (nmode-refresh-window w)
  415. (nmode-refresh-screen (=> (=> w screen) screen))
  416. )))
  417. (de nmode-refresh-virtual-screen (s)
  418. % This function refreshes the shared screen containing the specified
  419. % virtual screen.
  420. (cond (full-refresh-needed
  421. (nmode-full-refresh))
  422. (nmode-breakout-occurred?
  423. (nmode-refresh))
  424. (t
  425. (if (eq (=> nmode-screen owner 0 0) nmode-blank-screen) % hack!
  426. (=> nmode-blank-screen deexpose))
  427. (nmode-refresh-screen (=> s screen))
  428. )))
  429. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  430. % Internal functions:
  431. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  432. (de nmode-refresh-windows ()
  433. % Cause all windows to update their corresponding virtual screens. The
  434. % variable nmode-breakout-occurred? is set to T if the refresh is
  435. % interrupted by user input.
  436. (setf nmode-breakout-occurred? NIL)
  437. (=> nmode-blank-screen deexpose) % hack!
  438. (=> nmode-current-window adjust-window)
  439. (nmode-refresh-window nmode-top-window)
  440. (nmode-refresh-window nmode-bottom-window)
  441. (nmode-refresh-window nmode-input-window)
  442. )
  443. (de nmode-refresh-window (w)
  444. % Refresh only if window is exposed and no breakout has occurred.
  445. % Update the flag nmode-breakout-occurred?
  446. (if (not nmode-breakout-occurred?)
  447. (if (eq (object-type w) 'buffer-window) % hack for efficiency
  448. (if (buffer-window$exposed? w)
  449. (setf nmode-breakout-occurred?
  450. (not (buffer-window$refresh w nmode-allow-refresh-breakout))))
  451. (if (=> w exposed?)
  452. (setf nmode-breakout-occurred?
  453. (not (=> w refresh nmode-allow-refresh-breakout))))
  454. )))
  455. (de nmode-refresh-screen (s)
  456. % Refresh the specified shared-screen.
  457. (if (eq (object-type s) 'shared-physical-screen) % hack for efficiency
  458. (shared-physical-screen$refresh s nmode-allow-refresh-breakout)
  459. (=> s refresh nmode-allow-refresh-breakout)
  460. ))
  461. (de nmode-establish-video-polarity ()
  462. (let ((mask (if nmode-inverse-video?
  463. nmode-inverse-enhancement
  464. nmode-normal-enhancement
  465. )))
  466. (=> nmode-top-window set-text-enhancement mask)
  467. (=> nmode-bottom-window set-text-enhancement mask)
  468. (=> nmode-input-window set-text-enhancement mask)
  469. (=> nmode-prompt-screen set-default-enhancement mask)
  470. (=> nmode-message-screen set-default-enhancement mask)
  471. (=> nmode-blank-screen set-default-enhancement mask)
  472. (=> nmode-prompt-screen clear)
  473. (rewrite-message)
  474. (=> nmode-blank-screen clear)
  475. ))
  476. (de nmode-new-terminal ()
  477. % This function should be called when either NMODE-TERMINAL or
  478. % NMODE-OTHER-TERMINAL changes.
  479. (setf full-refresh-needed T)
  480. (setf nmode-physical-screen (create-physical-screen nmode-terminal))
  481. (setf nmode-other-physical-screen
  482. (if nmode-other-terminal
  483. (create-physical-screen nmode-other-terminal)))
  484. (if nmode-screen
  485. (=> nmode-screen set-screen nmode-physical-screen)
  486. (setf nmode-screen (create-shared-physical-screen nmode-physical-screen))
  487. )
  488. (nmode-setup-softkey-label-screen nmode-screen)
  489. (if nmode-other-terminal
  490. (if nmode-other-screen
  491. (=> nmode-other-screen set-screen nmode-other-physical-screen)
  492. (setf nmode-other-screen
  493. (create-shared-physical-screen nmode-other-physical-screen))
  494. )
  495. (setf nmode-other-screen nil)
  496. )
  497. (let ((height (=> nmode-screen height))
  498. (width (=> nmode-screen width))
  499. )
  500. (when nmode-softkey-label-screen
  501. (setf height (- height (=> nmode-softkey-label-screen height)))
  502. )
  503. (setf nmode-total-lines (- height 2)) % all but message and prompt lines
  504. (setf nmode-top-lines (/ nmode-total-lines 2)) % half for the top window
  505. % Throw away the old windows and screens!
  506. (if nmode-blank-screen (=> nmode-blank-screen deexpose))
  507. (if nmode-message-screen (=> nmode-message-screen deexpose))
  508. (if nmode-prompt-screen (=> nmode-prompt-screen deexpose))
  509. (if nmode-input-window (=> nmode-input-window deexpose))
  510. % Create new windows and screens:
  511. (setf nmode-blank-screen % hack to implement clear screen
  512. (nmode-create-screen height width 0 0))
  513. (setf nmode-message-screen (nmode-create-screen 1 width (- height 2) 0))
  514. (setf nmode-prompt-screen (nmode-create-screen 1 width (- height 1) 0))
  515. (setf nmode-input-window
  516. (create-unlabeled-buffer-window nmode-input-buffer
  517. (nmode-create-screen 1 width (- height 1) 0)))
  518. (nmode-fixup-windows)
  519. (setf nmode-layout-mode (if nmode-two-screens? 2 1))
  520. (=> nmode-message-screen expose)
  521. (=> nmode-prompt-screen expose)
  522. (nmode-select-window nmode-top-window)
  523. (nmode-establish-video-polarity)
  524. (nmode-set-window-sizes)
  525. ))
  526. (de nmode-create-screen (height width row-origin column-origin)
  527. (make-instance 'virtual-screen
  528. 'screen nmode-screen
  529. 'height height
  530. 'width width
  531. 'row-origin row-origin
  532. 'column-origin column-origin)
  533. )
  534. (de nmode-set-window-sizes ()
  535. % This function ensures that the top and bottom windows are properly
  536. % set up and exposed.
  537. (cond ((< nmode-top-lines 2)
  538. (setf nmode-top-lines 2))
  539. ((> nmode-top-lines (- nmode-total-lines 2))
  540. (setf nmode-top-lines (- nmode-total-lines 2)))
  541. )
  542. (nmode-fixup-windows)
  543. (cond
  544. (nmode-two-screens?
  545. (nmode-position-window nmode-top-window nmode-total-lines 0)
  546. (nmode-position-window nmode-bottom-window nmode-total-lines 0)
  547. (nmode-expose-both-windows)
  548. )
  549. ((= nmode-layout-mode 1)
  550. (nmode-position-window nmode-top-window nmode-total-lines 0)
  551. (nmode-position-window nmode-bottom-window nmode-total-lines 0)
  552. (=> nmode-top-window expose)
  553. )
  554. ((= nmode-layout-mode 2)
  555. (nmode-position-window nmode-top-window nmode-top-lines 0)
  556. (nmode-position-window nmode-bottom-window
  557. (- nmode-total-lines nmode-top-lines)
  558. nmode-top-lines
  559. )
  560. (nmode-expose-both-windows)
  561. )))
  562. (de nmode-position-window (w height origin)
  563. (if (eq (=> (=> w screen) screen) nmode-other-screen)
  564. (setf height (=> nmode-other-screen height)))
  565. (=> w set-size height (=> w width))
  566. (let ((s (=> w screen)))
  567. (=> s set-origin origin 0))
  568. )
  569. (de nmode-expose-both-windows ()
  570. (cond ((eq nmode-top-window nmode-current-window)
  571. (=> nmode-bottom-window expose)
  572. (=> nmode-top-window expose)
  573. )
  574. (t
  575. (=> nmode-top-window expose)
  576. (=> nmode-bottom-window expose)
  577. )))
  578. (de nmode-fixup-windows ()
  579. % Ensure that the two buffer-windows exist and are attached to the proper
  580. % shared-screens.
  581. (let ((top-screen (if (and nmode-two-screens? nmode-other-screen)
  582. nmode-other-screen
  583. nmode-screen
  584. ))
  585. (bottom-screen nmode-screen)
  586. )
  587. (if (or (not nmode-top-window)
  588. (neq (=> (=> nmode-top-window screen) screen) top-screen)
  589. )
  590. (nmode-create-top-window)
  591. )
  592. (if (or (not nmode-bottom-window)
  593. (neq (=> (=> nmode-bottom-window screen) screen) bottom-screen)
  594. )
  595. (nmode-create-bottom-window)
  596. )
  597. ))
  598. (de nmode-create-top-window ()
  599. (let ((vs (if (and nmode-two-screens? nmode-other-screen)
  600. (make-instance 'virtual-screen
  601. 'screen nmode-other-screen
  602. 'height (=> nmode-other-screen height)
  603. 'width (=> nmode-other-screen width)
  604. 'row-origin 0
  605. )
  606. (make-instance 'virtual-screen
  607. 'screen nmode-screen
  608. 'height nmode-total-lines
  609. 'width (=> nmode-screen width)
  610. 'row-origin 0
  611. )))
  612. )
  613. (if nmode-top-window
  614. (=> nmode-top-window set-screen vs)
  615. (setf nmode-top-window (create-buffer-window nmode-main-buffer vs))
  616. )))
  617. (de nmode-create-bottom-window ()
  618. (let ((vs (make-instance 'virtual-screen
  619. 'screen nmode-screen
  620. 'height nmode-total-lines
  621. 'width (=> nmode-screen width)
  622. 'row-origin 0
  623. ))
  624. )
  625. (if nmode-bottom-window
  626. (=> nmode-bottom-window set-screen vs)
  627. (setf nmode-bottom-window (create-buffer-window nmode-output-buffer vs))
  628. )))
  629. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  630. (undeclare-flavor nmode-top-window nmode-bottom-window nmode-input-window
  631. nmode-current-window nmode-blank-screen nmode-screen)