home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 13 / N_B_V203.ZIP / MENU-DD.DMO < prev    next >
Text File  |  1996-07-04  |  17KB  |  309 lines

  1. $if 0
  2.     ┌──────────────────────────╖                        PowerBASIC v3.20
  3.  ┌──┤          DASoft          ╟──────────────────────┬──────────────────╖
  4.  │  ├──────────────────────────╢    Copyright 1995    │ DATE: 1995-10-01 ╟─╖
  5.  │  │ FILE NAME   MENU-DD .DMO ║          by          ╘════════════════─ ║ ║
  6.  │  │                          ║  Don Schullian, Jr.                     ║ ║
  7.  │  ╘══════════════════════════╝                                         ║ ║
  8.  │ A license is hereby granted to the holder to use this source code in  ║ ║
  9.  │ any program, commercial or otherwise,  without receiving the express  ║ ║
  10.  │ permission of the copyright holder and without paying any royalties,  ║ ║
  11.  │ as long as this code is not distributed in any compilable format.     ║ ║
  12.  │  IE: source code files, PowerBASIC Unit files, and printed listings   ║ ║
  13.  ╘═╤═════════════════════════════════════════════════════════════════════╝ ║
  14.    │                ....................................                   ║
  15.    ╘═══════════════════════════════════════════════════════════════════════╝
  16.  
  17. ****************************************************************************
  18. ** ** ** ** ** ** ** ** **  GENERAL CHIT-CHAT  ** ** ** ** ** ** ** ** ** **
  19. ****************************************************************************
  20.  
  21. This menu system can easily handle a whole program or a simple little pop-up
  22. event/box.  Getting all the data DIMed and set just right can be a real pain
  23. but there is just no way to make it much easier and still keep all the power
  24. that is available. The best deal would be to use this file as a test program
  25. for your data and once it's correct transfer it into your program or drop it
  26. all into a file.
  27.  
  28. Five arrays are used to  import data into the  menu and they  are discussed
  29. below. In addition there are two strings that control the "look" and "feel"
  30. of the menu and provide your program with many possibilities, one of which,
  31. should meet any requirement(s) you need.
  32.  
  33. By changing the border type, centering, wrap, and auto-open values you can
  34. create your own best set-up. These, and other values, are carried into the
  35. menu by a single string.
  36.  
  37. TYPE TempTYPE           '┌─────────────────────────
  38.   BarRow   AS BYTE      '│ row # for bar items
  39.   BarCol   AS BYTE      '│ starting column of bar items
  40.   BarCols  AS BYTE      '│ # of columns for bar items
  41.   Center   AS BYTE      '│ >0 center bar items on row  =0 left justify
  42.   BrdrOn   AS BYTE      '│ border style 0 = none, 1 = underline line, 2 = box
  43.   AutoOpen AS BYTE      '│ automatically open DD boxes when BAR item is hot
  44.   WrapOn   AS BYTE      '│ wrap cursor selections if > last goto first, etc.
  45.   ShdoOn   AS BYTE      '│ shadow effect for DD boxes SEE: DrawTShadow
  46.   Sattr    AS BYTE      '│ if .ShdoOn what attribute to use
  47. END TYPE                '└────────────────────────────────────────────────
  48.  
  49. DIM tDDsetup AS TempTYPE
  50.  
  51. M$(0) = tDDsetup + "[ tMain Menup ]"
  52.  
  53. BYTE #1 Top row for BAR MENU
  54.         If BYTE #7 = 2 then this row would be the top of the box
  55.                             else the actual BAR MENU would reside here
  56.  
  57. BYTE #2 Left most column for BAR MENU
  58.  
  59. BYTE #3 Total number of columns for BAR MENU
  60.  
  61. BYTE #4 Center BarMenu Items?
  62.          defines how the BAR MENU items will be printed
  63.          IF Center? > 0 then it will appear like PB's menu
  64.          IF Center? = 0 then it would look like:
  65.          [  File  Edit  Search  Run  Compile  Options  Debug              ]
  66.            where the items fill in from the left like GUI menus
  67.  
  68. BYTE #5 Bar Menu border style
  69.         defines how many rows are used for the BAR MENU
  70.           0 = like PB's menu
  71.           1 = a single line "──────────" under the items
  72.               this one is good for pop-up boxes, etc.
  73.           2 = a full box around the menu ( like old TurboBasic's )
  74.               in this case you can also send a "TITLE" that will be printed
  75.               top row, center
  76.               Which ever you choose the dropdown boxes will have a simple
  77.               box around them and the action is automatic so you don't need
  78.               to send any further boxing commands except for color attrs.
  79.               BYTEs #10-> Title for BarMenu box IF BYTE #6 = 2
  80.  
  81. BYTE #6 Automatically open 1st DropDown menus?
  82.         determines how the first dropdowns will open.
  83.           IF = 0 then the user will have to press <ENTER> or <DOWN>
  84.                  to open the dropdowns
  85.           IF > 0 then the first dropdowns will automatically open
  86.                  when the BAR ITEM is "HOT" and there is a dropdown
  87.                  to be had. This is PB's style.
  88.           This value also affects how <ESC> is handled
  89.  
  90. BYTE #7 Wrap selection bar?
  91.         handles the "UP", "DOWN", "LEFT", "RIGHT" keys and what happens when
  92.         the first or last item is currently selected and a further command is
  93.         incoming to go "past" the boundary.
  94.         If > 0 then it will act like PB's menu
  95.         If = 0 then the key-press will be ignored
  96.  
  97. BYTE #8 Shadow style on DropDown menu boxes:
  98.  
  99. BYTE #9 Shadow color attribute
  100.         SEE: DrawTShadow
  101.         NOTE: The menu expects the shadow to be in position #1 (lower right)
  102.               so if you use position #2 your 1st DDs will have to start in
  103.               column 3 or greater. Positions 3 and 4 will not look good as
  104.               the shadow will encroach upon the Bar Menu.
  105.  
  106. BYTEs #10 and up   SEE: BYTE #5
  107.  
  108. Why call 2 routines for each menu?
  109. MenuDD only gets the environment ready to act, and prints the BAR MENU on
  110. the screen. If the area the BAR MENU will reside over needs to be saved
  111. it will be up to you to capture it. SEE: fTBoxREAD$ This allows your
  112. program to continue on until the user elects to go to the menu, like in
  113. GUI programs. [HELP] [ABOUT] (remember?) Then, when/if the menu is actually
  114. required you simply call fMenuDD$ and instantly you're in business! You can
  115. start at any "ON" item so, if your user presses <ALT>H (for example) you
  116. could automatically jump to item #2 which would be the 1st item under the
  117. first BAR ITEM. fMenuDD$ returns the actual key-press that was used to exit
  118. the menu: <ENTER> or one of your choosing, and the selection made is carried
  119. in a parameter variable SelNo? Upon exiting, all dropdowns are closed but
  120. the BAR MENU is still up and the set-up is unchanged so it can be called
  121. again and again with no other calls to MenuDD. So, for those small programs,
  122. that can be handled by a single menu structure, you would only call MenuDD
  123. only once.
  124.  
  125. NOTE: <ENTER> is the only key that will automatically exit the menu unless
  126.               you provide other keys for this function
  127.       <ENTER> is also the only key that will return a selection value >0
  128.       <ESC>   only closes opened dropdowns and will not exit the menu unless
  129.               it has been sent as a "HOT KEY" and then only
  130.               1) if Auto-Open is "OFF" and the user is at the BAR MENU
  131.               2) if Auto-Open is "ON" and the user is in the 1st DropDown
  132.  
  133. ****************************************************************************
  134. ** ** ** ** ** ** ** ** ** ** RULES OF ENGAGEMENT ** ** ** ** ** ** ** ** **
  135. ****************************************************************************
  136.  
  137. The menu is controlled by 4 arrays:
  138.   M$()  item names  VALUES: NULL or not
  139.                       LEVEL 1 items can not be NULL
  140.                       All NULL items are replaced with a "├─────┤"
  141.                                in the pulldown menus
  142.                       ALL NULL items must be "OFF" ie: O?(x) = 0
  143.   H$()  help line   VALUES: NULL or not
  144.                       IF UBOUND(H$(1)) < UBOUND(M$(1)) THEN Help is OFF
  145.                         LINE 25 is stored and then used to Tprint the
  146.                         help string(s) to that line
  147.                       MAX Visible length of H$(x) = 78
  148.                       IF H$(x) = "" AND Help is active LINE 25 is blank
  149.   L?()  item levels  VALUES: the level of the item 1,2,3,etc
  150.                              1 = bar items
  151.                              2 = first pull-down under bar item
  152.   O?()  ON/OFF flag  VALUES: 0 = OFF  :  1-255 = ON
  153.                        OFF items are deemed to be childless
  154.                          They may, in fact, have children but the
  155.                          kids are inaccessible as the item is OFF
  156.                        To change status of a level 1 item you must reopen
  157.                          the menu
  158.                        The 1st item of the BAR MENU MUST BE ACTIVE!
  159.   A?()  Color Attributes
  160.                      Each level of the menu has it's own set of attributes.
  161.                      A?() can be DIMed A?(0:5,0:LastL?) or
  162.                                        A?(0:5,1:LastL?) or
  163.                                        A?(1:5,0:LastL?) or
  164.                                        A?(1:5,1:LastL?)
  165. ** "HOT KEYS" are not mandatory
  166.  
  167. ** Embedded color commands SHOULD NOT precede a HOT KEY declaration, if any.
  168.      ie: "_File"                won't work
  169.           "_File:  MYFILE.BAS"  is just fine
  170.           "File"                is ok too
  171.  
  172. ** It is assumed that all arrays are equally DIMed ( except H$() )
  173.  
  174. ** An incoming Starting selection number CANNOT be in an OFF status.
  175.      a test is made and if this happens then the starting item will revert
  176.      to item #1
  177.    IF, however, you access a child of an OFF item unpredictable results
  178.      will occur. ie: it doesn't seem to crash but.........
  179.  
  180. $ENDIF
  181.  
  182. $STRING 32
  183. $STACK  16384
  184. $INCLUDE "DAS-NB01.INC"
  185. $INCLUDE "DAS-NB02.INC"
  186. $INCLUDE "DAS-NBT1.INC"
  187. $INCLUDE "DAS-NBT3.INC"
  188. COLOR 7, 0, 0
  189. CLS
  190.  
  191. Ioff$ = "xOFF"          ' 2 little ON/OFF menu messages
  192. Ion$  = "uON "          ' notice that we're changing attributes too
  193.  
  194. '┌───────┬────────────────────────────────────────>    ATTRIBUTES
  195. '│       │   ┌──────┬───────────────────────────────>    ON/OFF switches
  196. '│       │   │      │   ┌──────┬──────────────────────>    ITEM Levels
  197. '│       │   │      │   │      │   ┌───────┬────────────>    ITEM strings
  198. '│       │   │      │   │      │   │       │   ┌───────┬──>    HELP strings
  199. 'A?(1,1)=0 : O?(xx)=0 : L?(xx)=0 : M$(xx)="" : H$(xx)=""
  200.  
  201. DIM A?(5,4), O?(26), L?(26), M$(26), H$(26)
  202. O?(01) =   1 : L?(01) = 1 : M$(01) = "Bar Item _1"
  203. O?(02) = 101 : L?(02) = 2 : M$(02) =   "DropDown _1B1  " + Ioff$
  204. O?(03) = 102 : L?(03) = 2 : M$(03) =   "_Bar Item 2    " + Ion$
  205. O?(04) = 103 : L?(04) = 2 : M$(04) =   "DropDown _3B1"
  206. O?(05) =   0 : L?(05) = 2 : M$(05) =   ""
  207. O?(06) = 104 : L?(06) = 2 : M$(06) =   "DropDown _5B1"
  208. O?(07) =   1 : L?(07) = 2 : M$(07) =   "DropDown _6B1   u"
  209. O?(08) = 105 : L?(08) = 3 : M$(08) =     "DropDown _1B1"
  210. O?(09) = 106 : L?(09) = 3 : M$(09) =     "DropDown _2B1"
  211. O?(10) = 107 : L?(10) = 3 : M$(10) =     "_Finished      <ALT> X"
  212. O?(11) =   0 : L?(11) = 1 : M$(11) = "Bar Item _2"
  213. O?(12) = 108 : L?(12) = 2 : M$(12) =   "DropDown _1B2"
  214. O?(13) = 109 : L?(13) = 2 : M$(13) =   "DropDown _2B2"
  215. O?(14) =   1 : L?(14) = 2 : M$(14) =   "DropDown _3B2  u"
  216. O?(15) = 110 : L?(15) = 3 : M$(15) =     "DropDown _1B2"
  217. O?(16) = 111 : L?(16) = 3 : M$(16) =     "DropDown _2B2"
  218. O?(17) =   1 : L?(17) = 3 : M$(17) =     "DropDown _3B2  "
  219. O?(18) = 112 : L?(18) = 4 : M$(18) =       "DropDown _1B2"
  220. O?(19) = 113 : L?(19) = 4 : M$(19) =       "DropDown _2B2"
  221. O?(20) = 114 : L?(20) = 2 : M$(20) =   "DropDown _4B2"
  222. O?(21) = 115 : L?(21) = 1 : M$(21) = "_No Children"
  223. O?(22) =   1 : L?(22) = 1 : M$(22) = "Bar Item _4"
  224. O?(23) = 116 : L?(23) = 2 : M$(23) =   "DropDown _1B4"
  225. O?(24) =   1 : L?(24) = 2 : M$(24) =   "DropDown _2B4  u"
  226. O?(25) = 117 : L?(25) = 3 : M$(25) =     "DropDown _1B4"
  227. O?(26) = 118 : L?(26) = 3 : M$(26) =     "DropDown _2B4"
  228.                                                      '┌──────────────────────
  229. FOR X? = 1 TO UBOUND( H$(1) )                        '│ some dummy help
  230.   H$(X?) = USING$("THIS IS HELP FOR ITEM N° ##",X?) '│ messages or you can
  231. NEXT                                                 '│ REDIM H$(0) if you
  232. 'REDIM H$(0)                                         '│ with no help at all
  233.                                      '┌───────────────┴─────────────────────
  234. FOR L? = 1 TO 4                      '│ each level of the menu can have
  235.   FOR A? = 1 TO 5                    '│ a different color scheme
  236.     READ A?(A?,L?)                   '│ this is a little extra work but only
  237.   NEXT                               '│ once and the data is easily stored
  238. NEXT                                 '│ in a file
  239. '    Norm  1stL  SELb  OFF   Brdr    '│ A? can be DIMed A?(0,0) or A?(1,1)
  240. DATA 113,  116,  079,  120,  112     '├> BAR MENU      ( level 1 )
  241. DATA 113,  116,  031,  120,  112     '├> 1st DropDowns ( level 2 )
  242. DATA  31,   27,  113,   25,   30     '├> 2ed DropDowns ( level 3 )
  243. DATA  31,   27,  113,   25,   30     '├> 3rd DropDowns ( level 4 )
  244.                                      '└─────────────────────────────────────
  245. 'M$(0) carries┌────────────────────────> top row
  246. 'several byte │   ┌──────────────────────> left most column
  247. 'values into  │   │   ┌────────────────────> number of columns
  248. 'the function │   │   │   ┌───────────────────> center bar items
  249. 'and saves a  │   │   │   │   ┌────────────────> border type (0, 1 or 2)
  250. 'group of     │   │   │   │   │   ┌──────────────> wrap selection bar
  251. 'parameters!  │   │   │   │   │   │   ┌────────────> auto-open ON/OFF
  252. '             │   │   │   │   │   │   │   ┌──────────> shadow style
  253. '             │   │   │   │   │   │   │   │   ┌────────> shadow attribute
  254. '             │   │   │   │   │   │   │   │   │      ┌───> menu title
  255. '             │   │   │   │   │   │   │   │   │      │
  256. '             │   │   │   │   │   │   │   │   │      │
  257. M$(0) = CHR$(001,001,080,000,001,001,000,001,008) + "[ tMain Menup ]"
  258. Exet$ = CHR$(000,045,027,000)       ' <ALT>X and <ESC>
  259. TBoxFILL 1, 1, 25, 80, 177, 25
  260.  
  261. DO
  262.   IF TopRow$ = "" THEN
  263.     TopRow$ = fTmenuDDopen$( M$(), L?(), O?(), A?(), Exet$ )
  264.   END IF
  265.                                             '┌───────────────────────────────
  266.   SelNo? = fTmenuDD?( M$(), H$(), SelNo? )  '│ call the menu function but
  267.   O$ = INKEY$                               '│ read key-press
  268.   IF O$ = CHR$(000,045) THEN GOTO ENDofPROG '│ <ALT>X was pressed
  269.   M$ = USING$(" YOU SELECTED: ## ",SelNo?)  '│ our little message
  270.   SELECT CASE O?(SelNo?)                    '│
  271.     CASE 101                                '│ This is an ON/OFF item on a
  272.       IF MID$( M$(2), 18, 3 ) = "OFF" THEN  '│   DropDown so we don't have
  273.           MID$( M$(2), 16, 5 ) = Ion$       '│   to recall MenuDD after the
  274.         ELSE                                '│   change
  275.           MID$( M$(2), 16, 5 ) = Ioff$      '│
  276.       END IF                                '│
  277.     CASE 102                                '│ This selection turns Bar Item2
  278.       TopRow$ = ""                          '│   ON/OFF so we have to recall
  279.       IF O?(11) = 0 THEN                    '│   MenuDD to have the change
  280.           O?(11) = 1                        '│   take effect.
  281.           MID$( M$(3), 16, 5 ) = Ioff$      '│
  282.           SelNo? = 11                       '│ Here we make Bar Item2 the
  283.         ELSE                                '│   "hot" selection as it is
  284.           O?(11) = 0                        '│   now in an "ON" status
  285.           MID$( M$(3), 16, 5 ) = Ion$       '│ But here it is "OFF" so not
  286.       END IF                                '│
  287.     CASE 0, 107 : EXIT LOOP                 '│ <ESC> returns a 0 so we could
  288.     CASE ELSE                               '├┐  use another CASE for it ──┐
  289.       Tprint 20, 1, M$, 112                 '│└ all other menu selections  │
  290.       DELAY 2                               '│  do their own thing(s)      │
  291.       TBoxFILL 20, 1, 1, 18, 177, 25        '│                             │
  292.   END SELECT                                '│                          or │
  293. LOOP UNTIL SelNo? = 0                       '│ this would work also <──────┘
  294.                                             '├───────────────────────────────
  295. TBoxWRITE TopRow$                           '│ NOTE how I used values >100
  296. END                                         '│ for the ON/OFF on those items
  297.                                             '│ that could return from the
  298. ENDofPROG:                                  '│ function and 1 for those items
  299.   CLS                                       '│ that could not return. This
  300.   PRINT "YOU PRESSED <ALT>X"                '│ allows me to have a SELECT
  301.   END                                       '│ CASE in 101,102,103 order
  302. ' ───────────────────────────────────────────┴───────────────────────────────
  303.  
  304. FUNCTION fGetKey% LOCAL PUBLIC
  305.  
  306.   WHILE NOT INSTAT : WEND
  307.   FUNCTION = CVI( INKEY$ + CHR$(0) )
  308.  
  309. END FUNCTION