home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database / CLIPR502.DOS / SOURCE / RL / RLDIALG.PRG < prev    next >
Encoding:
Text File  |  1993-02-15  |  10.3 KB  |  701 lines

  1. /***
  2. *
  3. *  Rldialg.prg
  4. *
  5. *  Copyright (c) 1987-1993, Computer Associates International, Inc.
  6. *  All rights reserved.
  7. *
  8. */
  9.  
  10.  
  11. /***
  12. *
  13. *    multibox()
  14. *
  15. *    sysparam values:
  16. *        1    =    initialize and display
  17. *        2    =    hilite (become the current item)
  18. *        3    =    dehilite (become a non-current item)
  19. *        4    =    become a selected item and return a new state
  20. *
  21. *        note that the above values are interpreted
  22. *             differently by each function
  23. *
  24. *    states:
  25. *        0    =    abort the process
  26. *        1    =    initialization
  27. *        2    =    pointing (cursor)
  28. *        3    =    entry/selection
  29. *        4    =    complete the process
  30. *
  31. */
  32. FUNCTION multibox
  33.  
  34. PARAMETERS wt, wl, wh, beg_curs, boxarray
  35. PRIVATE funcn, sysparam, state, cursor, x
  36. PRIVATE asel, arel, frame, lframe
  37.  
  38. asel       = 1
  39. arel       = 0
  40. frame      = "╒═╕│╛═╘│"
  41. lframe     = "╤═╕│╛═╧│"
  42.  
  43. DECLARE box_row[LEN(boxarray)]
  44. DECLARE box_col[LEN(boxarray)]
  45.  
  46. SAVE SCREEN
  47.  
  48. @ wt, wl, wt + wh + 1, wl + 45 BOX frame + " "
  49.  
  50. * state 1 ... initialization
  51. sysparam = 1
  52.  
  53. FOR cursor = 1 TO LEN(boxarray)
  54.     funcn = boxarray[cursor]
  55.     x = &funcn
  56.  
  57.     * each function leaves the cursor at its top left corner
  58.     box_row[cursor] = ROW()
  59.     box_col[cursor] = COL()
  60.  
  61. NEXT
  62.  
  63. cursor = beg_curs
  64. state = 2
  65.  
  66. DO WHILE state <> 0 .AND. state <> 4
  67.     * till completed or aborted
  68.     funcn = boxarray[cursor]
  69.  
  70.     DO CASE
  71.  
  72.         CASE state = 2
  73.             * pointing state
  74.             sysparam = 2
  75.             x = &funcn
  76.  
  77.             k = INKEY(0)
  78.  
  79.             DO CASE
  80.  
  81.                 CASE k = 13 .OR. jisdata(k)
  82.                     * change to selection state
  83.                     state = 3
  84.  
  85.                 CASE k = 27
  86.                     * abort
  87.                     state = 0
  88.  
  89.                 OTHERWISE
  90.                     * current item becomes uncurrent
  91.                     sysparam = 3
  92.                     x = &funcn
  93.  
  94.                     * get a new cursor
  95.                     cursor = matrix(cursor, k)
  96.  
  97.             ENDCASE
  98.  
  99.         CASE state = 3
  100.             * be selected and return a new state
  101.             sysparam = 4
  102.             state = &funcn
  103.  
  104.     ENDCASE
  105. ENDDO
  106.  
  107. RESTORE SCREEN
  108.  
  109. RETURN state
  110.  
  111.  
  112.  
  113. /***
  114. *
  115. *  title()
  116. *
  117. */
  118. FUNCTION enter_title
  119. PARAMETERS sysparam
  120.  
  121. IF sysparam = 1
  122.     @ wt + 1, wl + 2 SAY "Enter a filename "
  123.  
  124.     * set cursor for initialization
  125.     @ wt + 1, wl + 2 SAY ""
  126.  
  127. ENDIF
  128.  
  129. RETURN 2
  130.  
  131.  
  132.  
  133. /***
  134. *
  135. *  save_title()
  136. *
  137. */
  138. FUNCTION save_title
  139. PARAMETERS sysparam
  140.  
  141. IF sysparam = 1
  142.     * watch out for the length of file, it may exceed the box width (path)
  143.     @ wt + 3, wl + 4 SAY "Save Changes To File " + TRIM(filename) + "?"
  144.  
  145.     * set cursor for initialization
  146.     @ wt + 3, wl + 4 SAY ""
  147.  
  148. ENDIF
  149.  
  150. RETURN 2
  151.  
  152.  
  153.  
  154. /***
  155. *
  156. *  rl_getfil()
  157. *
  158. *  get filename
  159. *
  160. */
  161. FUNCTION rl_getfil
  162. PARAMETERS sysparam
  163.  
  164. DO CASE
  165.  
  166.     CASE sysparam = 1 .OR. sysparam = 3
  167.         @ wt + 3, wl + 2 SAY "File " + SUBSTR(filename, 1, 20)
  168.  
  169.         IF sysparam = 1
  170.             * set cursor for initialization
  171.             @ wt + 3, wl + 9 SAY ""
  172.         ENDIF
  173.  
  174.     CASE sysparam = 2
  175.         * be current...hilite
  176.         SET COLOR TO I
  177.         @ wt + 3, wl + 7 SAY SUBSTR(filename, 1, 20)
  178.         SET COLOR TO BG+/B
  179.  
  180.     CASE sysparam = 4
  181.         * be selected...perform a GET on entry field
  182.         
  183.         Note: any other 'isdata' key will also execute selection
  184.         IF k <> 13
  185.             KEYBOARD CHR(k)
  186.         ENDIF
  187.         
  188.         filename = jenter_rc(filename, wt + 3, wl + 7, 64, "@K!S20")
  189.  
  190.         SET CURSOR ON
  191.         READ
  192.         SET CURSOR OFF
  193.  
  194.         IF LASTKEY() = 13 .AND. .NOT. EMPTY(filename)
  195.             * filename has been selected...go to the ok button
  196.             filename = JPAD(filename,20)
  197.             @ wt + 3, wl + 7 SAY filename
  198.             to_ok()
  199.         ENDIF
  200. ENDCASE
  201.  
  202. RETURN 2
  203.  
  204.  
  205.  
  206. /***
  207. *
  208. *  filelist()
  209. *
  210. */
  211. FUNCTION filelist
  212. PARAMETERS sysparam
  213. PRIVATE c
  214.  
  215. DO CASE
  216.  
  217.     CASE sysparam = 1
  218.         * clear the window
  219.         scroll(wt + 1, wl + 31, wt + wh, wl + 44, 0)
  220.         @ wt, wl + 30, wt + wh + 1, wl + 45 BOX lframe
  221.  
  222.         IF .NOT. EMPTY(files[1])
  223.             * display the files list
  224.             KEYBOARD CHR(27)
  225.             achoice(wt+1,wl+32,wt+wh,wl+43,files,"ch_func",0,asel,arel)
  226.  
  227.         ENDIF
  228.  
  229.         * set cursor for initialization
  230.         @ wt + 1, wl + 32 SAY ""
  231.  
  232.     CASE sysparam = 2
  233.  
  234.         IF EMPTY(files[1])
  235.             * cannot cursor onto an empty list
  236.             KEYBOARD CHR(219)
  237.  
  238.         ELSE
  239.             * set initial relative row and array element
  240.             asel = asel - arel + ROW() - wt - 1
  241.             arel = ROW() - wt - 1
  242.  
  243.             * do the list selection
  244.             c = achoice(wt+1,wl+32,wt+wh,wl+43,files,"ch_func",0,asel,arel)
  245.  
  246.             IF LASTKEY() = 13
  247.                 * filename selected from list...set memvar
  248.                 filename = SUBSTR(files[c] + SPACE(64), 1, 64)
  249.  
  250.                 * display filename in entry blank
  251.                 rl_getfil(3)
  252.  
  253.                 * go directly to ok button
  254.                 to_ok()
  255.  
  256.             ELSE
  257.  
  258.                 IF LASTKEY() = 19
  259.                     * the system responds to CHR(19) as ^S
  260.                     KEYBOARD CHR(219)
  261.  
  262.                 ELSE
  263.                     * send character to multibox
  264.                     KEYBOARD CHR(LASTKEY())
  265.  
  266.                 ENDIF
  267.             ENDIF
  268.         ENDIF
  269. ENDCASE
  270.  
  271. RETURN 2
  272.  
  273.  
  274.  
  275. /***
  276. *
  277. *  ok_button()
  278. *
  279. */
  280. FUNCTION ok_button
  281.  
  282. PARAMETERS sysparam
  283. PRIVATE ok, reply
  284.  
  285. ok = " Ok "
  286. reply = 2
  287.  
  288. DO CASE
  289.  
  290.     CASE sysparam = 1 .OR. sysparam = 3
  291.         @ wt + wh, wl + 9 SAY ok
  292.  
  293.         IF sysparam = 1
  294.             * set cursor for initialization
  295.             @ wt + wh, wl + 9 SAY ""
  296.  
  297.         ENDIF
  298.  
  299.     CASE sysparam = 2
  300.         * be current...hilite
  301.         SET COLOR TO I
  302.         @ wt + wh, wl + 9 SAY ok
  303.         SET COLOR TO BG+/B
  304.  
  305.     CASE sysparam = 4
  306.  
  307.         IF &okee_dokee
  308.             * a job well done...complete the process
  309.             reply = 4
  310.         ENDIF
  311.  
  312. ENDCASE
  313.  
  314. RETURN reply
  315.  
  316.  
  317.  
  318. /***
  319. *
  320. *  cancel_button()
  321. *
  322. */
  323. FUNCTION cancel_button
  324.  
  325. PARAMETERS sysparam
  326. PRIVATE can, reply
  327.  
  328. can = " Cancel "
  329. reply = 2
  330.  
  331. DO CASE
  332.  
  333.     CASE sysparam = 1 .OR. sysparam = 3
  334.         @ wt + wh, wl + 17 SAY can
  335.  
  336.         IF sysparam = 1
  337.             * set cursor for initialization
  338.             @ wt + wh, wl + 17 SAY ""
  339.  
  340.         ENDIF
  341.  
  342.     CASE sysparam = 2
  343.         * be current...hilite
  344.         SET COLOR TO I
  345.         @ wt + wh, wl + 17 SAY can
  346.         SET COLOR TO BG+/B
  347.  
  348.     CASE sysparam = 4
  349.         * cancel selected...abort the process
  350.         reply = 0
  351.  
  352. ENDCASE
  353.  
  354. RETURN reply
  355.  
  356.  
  357.  
  358. /***
  359. *
  360. *  can_button()
  361. *
  362. *    cancel button for save file box
  363. *
  364. */
  365. FUNCTION can_button
  366.  
  367. PARAMETERS sysparam
  368. PRIVATE can, reply
  369.  
  370. can = " Cancel "
  371. reply = 2
  372.  
  373. DO CASE
  374.  
  375.     CASE sysparam = 1 .OR. sysparam = 3
  376.         @ wt + wh, wl + 25 SAY can
  377.  
  378.         IF sysparam = 1
  379.             * set cursor for initialization
  380.             @ wt + wh, wl + 25 SAY ""
  381.  
  382.         ENDIF
  383.  
  384.     CASE sysparam = 2
  385.         * be current...hilite
  386.         SET COLOR TO I
  387.         @ wt + wh, wl + 25 SAY can
  388.         SET COLOR TO BG+/B
  389.  
  390.     CASE sysparam = 4
  391.         * cancel selected...abort the process
  392.         reply = 0
  393.  
  394. ENDCASE
  395.  
  396. RETURN reply
  397.  
  398.  
  399.  
  400. /***
  401. *
  402. *  no_button()
  403. *
  404. */
  405. FUNCTION no_button
  406.  
  407. PARAMETERS sysparam
  408. PRIVATE no, reply
  409.  
  410. no = " No "
  411. reply = 2
  412.  
  413. DO CASE
  414.  
  415.     CASE sysparam = 1 .OR. sysparam = 3
  416.         @ wt + wh, wl + 13 SAY no
  417.  
  418.         IF sysparam = 1
  419.             * set cursor for initialization
  420.             @ wt + wh, wl + 13 SAY ""
  421.  
  422.         ENDIF
  423.  
  424.     CASE sysparam = 2
  425.         * be current...hilite
  426.         SET COLOR TO I
  427.         @ wt + wh, wl + 13 SAY no
  428.         SET COLOR TO BG+/B
  429.  
  430.     CASE sysparam = 4
  431.         * 'No' selected...abort the process
  432.         reply = 0
  433.         no_save_flag = .T.
  434. ENDCASE
  435.  
  436. RETURN reply
  437.  
  438.  
  439.  
  440. /***
  441. *
  442. *  ch_func()
  443. *
  444. *    achoice user function
  445. *
  446. */
  447. FUNCTION ch_func
  448.  
  449. PARAMETERS amod, sel, rel
  450. PRIVATE k, r, srow, scol
  451.  
  452. srow = ROW()
  453. scol = COL()
  454.  
  455. asel = sel
  456. arel = rel
  457. r = 2
  458.  
  459. IF asel > arel + 1
  460.     * more files off screen up
  461.     @ wt + 1, wl + 44 SAY CHR(24)
  462.  
  463. ELSE
  464.     @ wt + 1, wl + 44 SAY " "
  465.  
  466. ENDIF
  467.  
  468. IF LEN(files) - asel > wh - 1 - arel
  469.     * more files off screen down
  470.     @ wt + wh, wl + 44 SAY CHR(25)
  471.  
  472. ELSE
  473.     @ wt + wh, wl + 44 SAY " "
  474.  
  475. ENDIF
  476.  
  477. IF amod = 3
  478.     k = LASTKEY()
  479.  
  480.     DO CASE
  481.  
  482.         CASE k = 27
  483.             * escape key
  484.             r = 0
  485.  
  486.         CASE k = 13 .OR. k = 19 .OR. k = 219
  487.             * return or left arrow
  488.             r = 1
  489.  
  490.         CASE k = 1
  491.             * home key..top of list
  492.             KEYBOARD CHR(31)
  493.  
  494.         CASE k = 6
  495.             * end key..end of list
  496.             KEYBOARD CHR(30)
  497.  
  498.     ENDCASE
  499. ENDIF
  500.  
  501. @ M->srow, M->scol SAY ""
  502. RETURN r
  503.  
  504.  
  505.  
  506. /***
  507. *
  508. *    do_it()
  509. *
  510. *    called from the "Ok" button as "&okee_dokee"
  511. *    this function normally completes the process
  512. *
  513. */
  514. FUNCTION do_it
  515.  
  516. PRIVATE done, error_str
  517.  
  518. DO CASE
  519.  
  520.     * error if empty filename
  521.     CASE EMPTY(filename)    && error, empty filename
  522.         KEYBOARD CHR(5)
  523.         done = .F.
  524.  
  525.     OTHERWISE
  526.         done = .T.
  527.  
  528. ENDCASE
  529.  
  530. RETURN done
  531.  
  532.  
  533.  
  534. /***
  535. *
  536. *  matrix()
  537. *
  538. *    relocate cursor
  539. *
  540. */
  541. FUNCTION matrix
  542.  
  543. PARAMETERS old_curs, k
  544. PRIVATE old_row, old_col, test_curs, new_curs
  545.  
  546. old_row = ROW()
  547. old_col = box_col[old_curs]
  548. new_curs = old_curs
  549. test_curs = old_curs
  550.  
  551. DO CASE
  552.  
  553.     CASE k = 19 .OR. k = 219
  554.         * left arrow
  555.  
  556.         DO WHILE test_curs > 2
  557.             test_curs = test_curs - 1
  558.  
  559.             IF box_col[test_curs] < old_col .AND. box_row[test_curs] >= old_row
  560.  
  561.                 IF box_row[test_curs] < box_row[new_curs] .OR. new_curs = old_curs
  562.                     * best so far
  563.                     new_curs = test_curs
  564.  
  565.                 ENDIF
  566.             ENDIF
  567.         ENDDO
  568.  
  569.     CASE k = 4
  570.         * right arrow
  571.  
  572.         DO WHILE test_curs < LEN(box_col)
  573.             test_curs = test_curs + 1
  574.  
  575.             IF box_col[test_curs] > old_col .AND. box_row[test_curs] <= old_row
  576.  
  577.                 IF box_row[test_curs] > box_row[new_curs] .OR. new_curs = old_curs
  578.                     * best so far
  579.                     new_curs = test_curs
  580.  
  581.                 ENDIF
  582.             ENDIF
  583.         ENDDO
  584.  
  585.     CASE k = 5
  586.         * up arrow
  587.  
  588.         DO WHILE test_curs > 2
  589.             test_curs = test_curs - 1
  590.  
  591.             IF box_row[test_curs] < old_row .AND. box_col[test_curs] <= old_col
  592.  
  593.                 IF box_col[test_curs] > box_col[new_curs] .OR. new_curs = old_curs
  594.                     * best so far
  595.                     new_curs = test_curs
  596.  
  597.                 ENDIF
  598.             ENDIF
  599.         ENDDO
  600.  
  601.     CASE k = 24
  602.         * down arrow
  603.  
  604.         DO WHILE test_curs < LEN(box_row)
  605.             test_curs = test_curs + 1
  606.  
  607.             IF box_row[test_curs] > old_row .AND. box_col[test_curs] >= old_col
  608.  
  609.                 IF box_col[test_curs] < box_col[new_curs] .OR. new_curs = old_curs
  610.                     * best so far
  611.                     new_curs = test_curs
  612.  
  613.                 ENDIF
  614.             ENDIF
  615.         ENDDO
  616. ENDCASE
  617.  
  618. RETURN new_curs
  619.  
  620.  
  621.  
  622. /***
  623. *
  624. *  to_ok()
  625. *
  626. *    go directly to ok button
  627. *
  628. */
  629. FUNCTION to_ok
  630.  
  631. cursor = ascan(boxarray, "ok_button(sysparam)")
  632. KEYBOARD CHR(219)
  633. RETURN 0
  634.  
  635.  
  636.  
  637. /***
  638. *
  639. *    jisdata()
  640. *
  641. *    determine if a key is data suitable for entry in place
  642. *
  643. */
  644. FUNCTION jisdata
  645.  
  646. PARAMETERS k
  647.  
  648. RETURN (M->k >= 32 .AND. M->k < 249 .AND. M->k <> 219 .AND. CHR(M->k) <> ";")
  649.  
  650.  
  651.  
  652. /***
  653. *
  654. *    jenter_rc(r,c,max_len,pfunc)
  655. *
  656. *    entry in place
  657. *
  658. */
  659. FUNCTION jenter_rc
  660.  
  661. PARAMETERS org_str,r,c,max_len,pfunc
  662. PRIVATE wk_str, keystroke
  663.  
  664. wk_str = JPAD(org_str, max_len)
  665. SET CURSOR ON
  666.  
  667. IF .NOT. EMPTY(pfunc)
  668.     @ r,c GET wk_str PICTURE pfunc
  669. ELSE
  670.     @ r,c GET wk_str
  671. ENDIF
  672.  
  673. READ
  674. SET CURSOR OFF
  675.  
  676. keystroke = LASTKEY()
  677.  
  678. IF keystroke = 27
  679.     wk_str = ""
  680. ENDIF
  681.  
  682. RETURN (TRIM(wk_str))
  683.  
  684.  
  685.  
  686. /***
  687. *
  688. *    jpad()
  689. *
  690. *    syntax: jpad( <expC>, <expN> )
  691. *
  692. *    return: <expC> padded with spaces so that len( <expC> ) = <expN>
  693. *
  694. */
  695. FUNCTION jpad
  696.  
  697. PARAMETERS s, n
  698.  
  699. RETURN(SUBSTR(s + SPACE(n), 1, n))
  700.  
  701.