home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / dnalib7a.zip / SUBMENU.BAS < prev    next >
BASIC Source File  |  1994-05-16  |  13KB  |  442 lines

  1. DECLARE SUB Browse(FileName$,Mouse%,TextColor%,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Attr%,Shadow%,Border%)
  2. DECLARE SUB PopWind(Title$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Attr%,Shadow%,Border%)
  3. DECLARE SUB SaveScreen(ScreenID$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Shadow%)
  4. DECLARE SUB RestoreScreen(ScreenID$,TopRow%,LeftColumn%)
  5. DECLARE SUB CalcByte(Attr%,LowByte%,HiByte%)
  6. DECLARE SUB Clicked(Rgt%,Lft%,Row%,Col%)
  7. DECLARE SUB HideCursor()
  8. DECLARE SUB ShowCursor()
  9. DECLARE SUB LocateCursor(Row%,Col%)
  10. DECLARE SUB SplitPath(FilePath$, Path$, FileName$)
  11. DECLARE FUNCTION GetProgramName$()
  12. DECLARE FUNCTION GetPSP%()
  13. DECLARE FUNCTION LeftButtonReleased%()
  14. DECLARE FUNCTION RightButtonReleased%()
  15. DECLARE FUNCTION TRIML$(Strng$,Amount%)
  16.  
  17. SUB ScrollMenu(Choices$(),Infoline$(),Rtrn$,Mouse%,Winsize%,Tag%,Centre%,HotKey%,HelpTextColor%,HelpAttr%,HiAttr%,Attr%,TopRow%,LeftColumn%,Shadow%,Border%) PUBLIC
  18.  
  19. $CODE SEG "DNASEG2"
  20.  
  21. CalcByte Attr%,FGround%,BGround%
  22. CalcByte HiAttr%,HiFG%,HiBG%
  23.  
  24. SplitPath GetProgramName$,Home$,EXEName$
  25.  
  26. i% = 0                                      'loop counter
  27. j% = 0                                      'loop compare
  28. Maxlength% = 0                              'string length counter
  29.  
  30. IF Mouse% THEN HideCursor
  31.  
  32. DO
  33.  
  34. INCR i%
  35. INCR j%                                 'first find out how many
  36.                     'strings there are and the
  37. IF LEN (Choices$(i%)) = 0 THEN          'length of the longest one
  38.   DECR i%
  39. ELSE
  40.   IF LEN(REMOVE$(Choices$(i%),"@")) > Maxlength% THEN
  41.     Maxlength% = LEN(REMOVE$(Choices$(i%),"@"))
  42.   END IF
  43. END IF
  44.  
  45. LOOP WHILE i% = j%
  46.  
  47. Count% = i%
  48. Rtrn$ = ""
  49. INCR Maxlength%                'add a space
  50. LessThanWinsize% = 0           'initialize to zero
  51.  
  52. FOR i% = 1 TO Count%
  53.   Choices$(i%) = " " + Choices$(i%)
  54. NEXT i%
  55.  
  56. IF Count% <= Winsize% - 1 THEN
  57.   LessThanWinsize% = 1
  58. END IF
  59.  
  60. IF LessThanWinsize% THEN      'we need to transfer Count% to Finish%
  61.   Finish% = Count%
  62.   ScrollBar% = 0
  63. ELSE                          'fixed size scrolling box
  64.   Finish% = Winsize%
  65.   ScrollBar% = Count% \ (Winsize% - 2)
  66. END IF
  67.  
  68.  
  69. IF Centre% THEN                            'do they want it centred
  70.   LeftColumn% = 40 - ((Maxlength% + 2) \ 2)
  71.   RightColumn% = LeftColumn% + (Maxlength% + 2)
  72.   TopRow% = (25 - Finish% ) \ 2
  73.   BottomRow% = TopRow% + (Finish% + 1)
  74. ELSE
  75.   RightColumn% = LeftColumn% + (Maxlength% + 2)
  76.   BottomRow% = TopRow% + (Finish% + 1)
  77. END IF
  78.  
  79. SaveScreen ScrollMenuScreen$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Shadow%
  80. PopWind Title$,TopRow%,LeftColumn%,BottomRow%,RightColumn%,Attr%,Shadow%,Border%
  81.  
  82. IF Mouse% THEN
  83.   Test% = LEN(Title$)
  84.   IF Test% THEN
  85.     IF Test% + 12 <= RightColumn% - LeftColumn% THEN
  86.       COLOR FGround%,BGround%
  87.       LOCATE TopRow%,LeftColumn% + 1,0
  88.       PRINT CHR$(91,254,93);
  89.     ELSE
  90.       COLOR FGround%,BGround%
  91.       LOCATE BottomRow%,LeftColumn% + 1,0
  92.       PRINT CHR$(91,254,93);
  93.     END IF
  94.   ELSE
  95.     COLOR FGround%,BGround%
  96.     LOCATE TopRow%,LeftColumn% + 1,0
  97.     PRINT CHR$(91,254,93);
  98.   END IF
  99. END IF
  100.  
  101. Pointer% = 1                      'initialize all these
  102. Start% = 1
  103. SelectionMade% = 0
  104.  
  105. DO
  106.  
  107. PrintRoutine:
  108.  
  109. IF Mouse% THEN HideCursor
  110. Bar% = 0
  111. Row% = TopRow% + 1
  112. Col% = LeftColumn% + 1
  113.  
  114. FOR a% = Start% TO Finish%
  115.   IF a% = Pointer% THEN
  116.     Fixedup$ = REMOVE$(Choices$(a%),"@")
  117.     COLOR HiFG%,HiBG%
  118.     LOCATE Row%,Col%,0
  119.     MouseRow% = Row%
  120.     PRINT Fixedup$ + SPACE$(Maxlength% - LEN(Fixedup$) + 1);
  121.     IF LEN(Infoline$(a%)) THEN
  122.       InfoLinePrinted% = 1
  123.       COLOR FGround%,BGround%
  124.       LOCATE 25,10,0
  125.       PRINT LEFT$(SPACE$((60 - LEN(Infoline$(a%))) \ 2) + Infoline$(a%) + SPACE$(60),60);
  126.     END IF
  127.   ELSE
  128.     IF INSTR(Choices$(a%),"@") > 0 THEN
  129.       HotKeyPos% = INSTR(Choices$(a%),"@")
  130.       Fixedup$ = REMOVE$(Choices$(a%),"@")
  131.       Front$ = LEFT$(Fixedup$,(HotKeyPos% - 1))
  132.       HotKey$ = MID$(Fixedup$,(HotKeyPos%),1)
  133.       Back$ = RIGHT$(Fixedup$,LEN(Fixedup$) - HotKeyPos%)
  134.       COLOR FGround%,BGround%
  135.       LOCATE Row%,Col%,0
  136.       PRINT Front$;
  137.       COLOR HotKey%,BGround%
  138.       PRINT HotKey$;
  139.       COLOR FGround%,BGround%
  140.       PRINT Back$ + SPACE$(Maxlength% - LEN(Fixedup$) + 1);
  141.     ELSE
  142.       COLOR FGround%,BGround%
  143.       LOCATE Row%,Col%,0
  144.       PRINT Choices$(a%) + SPACE$(Maxlength% - LEN(Choices$(a%)) + 1);
  145.     END IF
  146.   END IF
  147.  
  148.   IF ScrollBar% THEN
  149.     COLOR FGround%,BGround%
  150.     LOCATE Row%,RightColumn%,0
  151.     IF a% = Start% THEN
  152.       PRINT CHR$(24);
  153.     ELSEIF a% = Finish% THEN
  154.       PRINT CHR$(25);
  155.     ELSE
  156.       IF Bar% =  0 THEN
  157.         c% = Pointer%
  158.         FOR i% = 1 TO ScrollBar%
  159.           b% = c% \ ScrollBar%
  160.           IF a% = b% + Start% THEN
  161.             Bar% = 1
  162.             EXIT FOR
  163.           ELSE
  164.             INCR c%
  165.           END IF
  166.         NEXT i%
  167.     IF Bar%  THEN
  168.       PRINT CHR$(219);
  169.         ELSE
  170.           IF Bar% = 0 AND a% = Finish% - 1 THEN
  171.             PRINT CHR$(219);
  172.           ELSE
  173.             PRINT CHR$(176);
  174.           END IF
  175.     END IF
  176.       ELSE
  177.         PRINT CHR$(176);
  178.       END IF
  179.     END IF
  180.   END IF
  181.   INCR Row%
  182. NEXT a%
  183.  
  184. WHILE NOT INSTAT
  185.   IF Mouse% THEN
  186.     IF SaveMouse% THEN LocateCursor MouseRow%,MCol%
  187.     Rgt% = 0:Lft% = 0:MRow% = 0:MCol% = 0:SaveMouse% = 0
  188.     ShowCursor
  189.     Clicked Rgt%,Lft%,MRow%,MCol%
  190.     IF MRow% >= TopRow% AND MRow% =< BottomRow% AND MCol% >= LeftColumn% AND MCol% =< RightColumn% THEN
  191.       IF MRow% > TopRow% AND MRow% < BottomRow% AND MCol% > LeftColumn% AND MCol% < RightColumn% THEN
  192.         HideCursor
  193.         IF RightButtonReleased% THEN
  194.           IF Tag% THEN
  195.             Chose% = 32: GOTO KeyBoardRoutine
  196.           END IF
  197.         ELSEIF LeftButtonReleased% THEN
  198.           Chose% = 13: GOTO KeyBoardRoutine
  199.         END IF
  200.         IF LessThanWinsize% THEN
  201.           Pointer% = MRow% - TopRow%
  202.           GOTO PrintRoutine
  203.         ELSE
  204.           Offset% = MRow% - (TopRow% + 1)
  205.           Pointer% = Start% + Offset%
  206.           GOTO PrintRoutine
  207.         END IF
  208.       ELSE
  209.         SELECT CASE MRow%
  210.           CASE TopRow%
  211.             IF MCol% = LeftColumn% + 2 THEN
  212.               IF LeftButtonReleased% THEN  'Cancel Box bottom
  213.                 Chose% = 27: GOTO KeyBoardRoutine
  214.               END IF
  215.             END IF
  216.           CASE TopRow% + 1
  217.             IF MCol% = RightColumn% THEN
  218.               IF LeftButtonReleased% THEN
  219.                 Chose% = -73: GOTO KeyBoardRoutine
  220.               END IF
  221.             END IF
  222.           CASE BottomRow% - 1
  223.             IF MCol% = RightColumn% THEN
  224.               IF LeftButtonReleased% THEN
  225.                 Chose% = -81: GOTO KeyBoardRoutine
  226.               END IF
  227.             END IF
  228.           CASE BottomRow%
  229.             SELECT CASE MCol%
  230.               CASE LeftColumn% + 2
  231.                 IF LeftButtonReleased% THEN  'Cancel Box bottom
  232.                   Chose% = 27: GOTO KeyBoardRoutine
  233.                 END IF
  234.             END SELECT
  235.         END SELECT
  236.       END IF
  237.     ELSE
  238.       IF LeftButtonReleased% THEN
  239.         Chose% = 27: GOTO KeyBoardRoutine
  240.       END IF
  241.     END IF
  242.   END IF
  243. WEND
  244.  
  245. Ky$ = INKEY$
  246.  
  247. IF LEN(Ky$) = 1 THEN
  248.   Chose% = ASC(Ky$)
  249. ELSE
  250.   Chose% = -ASC(RIGHT$(Ky$,1))
  251. END IF
  252.  
  253. KeyBoardRoutine:
  254.  
  255. IF Mouse% THEN
  256.   IF MRow% > TopRow% AND MRow% < BottomRow% AND_
  257.     MCol% > LeftColumn% AND MCol% < RightColumn% THEN
  258.     SaveMouse% = 1
  259.     LocateCursor 1,1
  260.   END IF
  261. END IF
  262.  
  263. SELECT CASE Chose%
  264.     CASE 13                          'enter key, exit and pass the
  265.       SelectionMade% = 1                'selection to Rtrn$
  266.       IF Tag% THEN
  267.         IF LEN(Rtrn$) THEN
  268.           Rtrn$ = Rtrn$
  269.         ELSE
  270.               Rtrn$ = REMOVE$(LTRIM$(Choices$(Pointer%)),"@")
  271.         END IF
  272.       ELSE
  273.               Rtrn$ = REMOVE$(LTRIM$(Choices$(Pointer%)),"@")
  274.       END IF
  275.     CASE 27                          'Esc key, just exit routine
  276.       SelectionMade% = 1
  277.       Rtrn$ = ""
  278.     CASE 32
  279.       IF Tag% THEN
  280.         IF INSTR(Choices$(Pointer%),CHR$(Tag%)) THEN
  281.           Rtrn$ = REMOVE$(Rtrn$,REMOVE$(Choices$(Pointer%),"@"))
  282.           Choices$(Pointer%) = " " + LTRIM$(Choices$(Pointer%),CHR$(Tag%))
  283.         ELSE
  284.           Choices$(Pointer%) = CHR$(Tag%) + TRIML$(Choices$(Pointer%),1)
  285.           Rtrn$ = Rtrn$ + REMOVE$(Choices$(Pointer%),"@")
  286.         END IF
  287.         IF LessThanWinsize% THEN     'it's not a scrolling box
  288.           IF Pointer% < Finish% THEN
  289.         INCR Pointer%
  290.           ELSE
  291.         Pointer% = Start%
  292.           END IF
  293.         ELSE                              'it's a scrolling box
  294.           IF Pointer% < Finish% THEN
  295.         INCR Pointer%
  296.           ELSEIF Finish% < Count% THEN    'check to see if we have
  297.         INCR Pointer%                 'any more choices waiting
  298.         INCR Start%
  299.         INCR Finish%
  300.           END IF
  301.         END IF
  302.       END IF
  303.     CASE 65 TO 90,97 TO 122
  304.           FOR m% = 1 TO Count%
  305.             IF INSTR(Choices$(m%),"@") > 0 THEN
  306.               HotKeyPos% = INSTR(Choices$(m%),"@")
  307.               HotKey$ = UCASE$(MID$(Choices$(m%),(HotKeyPos% + 1),1))
  308.               TestKey$ = UCASE$(CHR$(Chose%))
  309.               IF HotKey$ = TestKey$ THEN
  310.                 IF Tag% THEN
  311.                   Pointer% = m%
  312.                   IF LessThanWinsize% = 0 THEN
  313.                     IF Pointer% + Winsize% <= Count% THEN
  314.                       Finish% = Pointer% + (Winsize% - 1)
  315.                       Start% = Finish% - (Winsize% - 1)
  316.                     ELSE
  317.                       Finish% = Count%
  318.                       Start% = Finish% - (Winsize% - 1)
  319.                     END IF
  320.                   END IF
  321.                   EXIT FOR
  322.                 ELSE
  323.                   Rtrn$ = REMOVE$(LTRIM$(Choices$(m%)),"@")
  324.                   SelectionMade% = 1
  325.                   EXIT FOR
  326.                 END IF
  327.               END IF
  328.             END IF
  329.           NEXT m%
  330.     CASE -71  'home key
  331.           Pointer% = Start%
  332.     CASE -72  'up arrow
  333.       IF LessThanWinsize% THEN    'it's not a scrolling box
  334.         IF Pointer% > Start% THEN
  335.           DECR Pointer%
  336.         ELSE
  337.           Pointer% = Finish%
  338.         END IF
  339.       ELSE                            'it's a scrolling box
  340.             IF Pointer% > Start% THEN
  341.               DECR Pointer%
  342.             ELSEIF Start% > 1 THEN
  343.               DECR Pointer%
  344.               DECR Start%
  345.               DECR Finish%
  346.             END IF
  347.       END IF
  348.         CASE -59  ' F1 Help key
  349.           IF LEN(REMOVE$(Choices$(Pointer%),ANY "@ ")) > 8 THEN
  350.             FileName$ = LEFT$(UCASE$(REMOVE$(Choices$(Pointer%),ANY "@ ")),8) + ".HLP"
  351.           ELSE
  352.             FileName$ = UCASE$(REMOVE$(Choices$(Pointer%),ANY "@ ")) + ".HLP"
  353.           END IF
  354.           BROWSE Home$ + FileName$,Mouse%,HelpTextColor%,7,16,18,64,HelpAttr%,Shadow%,Border%
  355.     CASE -73  'page up
  356.       IF Start% - (Winsize% - 1) >= 1 THEN    'this block handles the
  357.         DECR Start%,(Winsize% - 1)            'pageing
  358.         DECR Pointer%,(Winsize% - 1)
  359.         DECR Finish%,(Winsize% - 1)
  360.       ELSE
  361.         Pointer% = 1
  362.         Start% = 1
  363.         IF LessThanWinsize% THEN    'if we jump back to Start% make
  364.           Finish% = Count%              'sure we check to see what kind
  365.         ELSE                            'of scroll box and set Finish%
  366.           Finish% = Winsize%            'accordingly
  367.         END IF
  368.       END IF
  369.     CASE -79  'end key
  370.           Pointer% = Finish%
  371.     CASE -80  'down arrow
  372.       IF LessThanWinsize% THEN    'it's not a scrolling box
  373.         IF Pointer% < Finish% THEN
  374.           INCR Pointer%
  375.         ELSE
  376.           Pointer% = Start%
  377.         END IF
  378.       ELSE                            'it's a scrolling box
  379.             IF Pointer% < Finish% THEN
  380.               INCR Pointer%
  381.             ELSEIF Finish% < Count% THEN    'check to see if we have
  382.               INCR Pointer%                 'any more choices waiting
  383.               INCR Start%
  384.               INCR Finish%
  385.         END IF
  386.       END IF
  387.     CASE -81  'page down
  388.       IF Finish% + (Winsize% - 1) <= Count% THEN    'this block handles
  389.         INCR Start%,(Winsize% - 1)                  'the pageing
  390.         INCR Finish%,(Winsize% - 1)
  391.         INCR Pointer%,(Winsize% - 1)
  392.       ELSE
  393.         Pointer% = Count%
  394.         Finish% = Count%
  395.         IF LessThanWinsize% THEN       'if we jump to Finish% make
  396.           Start% = 1                       'sure we check to see what
  397.         ELSE                               'kind of scroll box and set
  398.           Start% = Count% - (Winsize% - 1) 'Start% accordingly
  399.         END IF
  400.       END IF
  401.     CASE -118  'Ctrl PgDown
  402.           IF Finish < Count% THEN                   'routine as a scroll
  403.             Start% = (Count% - (Winsize% - 1))      'box, and not a pick
  404.             Finish% = Count%                        'list we handle
  405.             Pointer% = Count%
  406.           END IF
  407.     CASE -132  'Ctrl PgUp
  408.           IF Start% > 1 THEN
  409.             Start% = 1
  410.             Finish% = (Start% + (Winsize% - 1))
  411.             Pointer% = Start%
  412.           END IF
  413.     CASE ELSE
  414.           BEEP
  415. END SELECT
  416.  
  417. LOOP UNTIL SelectionMade%
  418.  
  419. FOR i% = 1 TO Count%
  420.   IF INSTR(Choices$(i%),CHR$(Tag%)) THEN
  421.     Choices$(i%) = LTRIM$(Choices$(i%),CHR$(Tag%)) 'remove tag char
  422.   ELSE
  423.     Choices$(i%) = LTRIM$(Choices$(i%))            'remove the space
  424.   END IF
  425. NEXT i%
  426.  
  427. IF SaveMouse% THEN LocateCursor MouseRow%,MCol%
  428.  
  429. IF Mouse% THEN HideCursor
  430.  
  431. IF InfoLinePrinted% = 1 THEN
  432.   COLOR FGround%,BGround%
  433.   LOCATE 25,15,0
  434.   PRINT SPACE$(50);
  435. END IF
  436.  
  437. RestoreScreen ScrollMenuScreen$,TopRow%,LeftColumn%
  438.  
  439. END SUB
  440.  
  441.  
  442.