home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / CHRTDEM2.BA$ / CHRTDEM2.bin
Encoding:
Text File  |  1990-06-24  |  43.4 KB  |  1,410 lines

  1. '       CHRTDEM2.BAS - third module of the CHRTB demonstration program.
  2. '
  3. '               Copyright (C) 1989-1990, Microsoft Corporation
  4. '
  5. '   Main module - CHRTDEMO.BAS
  6. '   Include files - CHRTDEMO.BI
  7. '
  8. '$INCLUDE: 'chrtdemo.bi'
  9.  
  10. ' local functions
  11. DECLARE FUNCTION TrueColr% (colr%)
  12.  
  13. ' local subs
  14. DECLARE SUB OpenChart (newFlag%)
  15. DECLARE SUB Quit ()
  16. DECLARE SUB InitFonts ()
  17. DECLARE SUB InitStyles ()
  18. DECLARE SUB SetDisplayColor ()
  19. DECLARE SUB SetUpBackground ()
  20. DECLARE SUB SetUpMenu ()
  21. DECLARE SUB ViewChart ()
  22. DECLARE SUB ViewFont ()
  23. DECLARE SUB ViewScreenMode ()
  24.  
  25. DIM colorDisplay            AS INTEGER
  26. DIM egacolor(0 TO 15)       AS INTEGER
  27. DIM origPath$
  28.  
  29. DEFINT A-Z
  30. '
  31. ' Sub Name: ClearData
  32. '
  33. ' Description: Clears all chart data
  34. ' Arguments: None
  35. '
  36. SUB ClearData
  37. SHARED Cat$(), catLen AS INTEGER
  38. SHARED setVal!(), setLen() AS INTEGER, setName$()
  39.  
  40.     ' Can't view  chart when no data present
  41.     MenuSetState VIEWTITLE, 2, 0
  42.  
  43.     ' Clear categories
  44.     FOR i = 1 TO cMaxValues
  45.         Cat$(i) = ""
  46.     NEXT i
  47.     catLen = 0
  48.  
  49.     ' Clear set names and values
  50.     FOR i = 1 TO cMaxSets
  51.         setName$(i) = ""
  52.         setLen(i) = 0
  53.         FOR j = 1 TO cMaxValues
  54.             setVal!(j, i) = cMissingValue
  55.         NEXT j
  56.     NEXT i
  57.     setNum = 0
  58.  
  59.     ' chart not changed
  60.     chartChanged = FALSE
  61.  
  62. END SUB
  63.  
  64. '
  65. ' Sub Name: ClearFonts
  66. '
  67. ' Description: Sets all chart font pointers to 1.  This is called
  68. '              each time new fonts are loaded to ensure that
  69. '              all chart fonts specify a meaningful font
  70. '
  71. ' Arguments: None
  72. '
  73. SUB ClearFonts
  74.  
  75.     ' reset all font pointers if don't map to current fonts
  76.     IF CEnv.DataFont > numFonts THEN CEnv.DataFont = 1
  77.     IF CEnv.MainTitle.TitleFont > numFonts THEN CEnv.MainTitle.TitleFont = 1
  78.     IF CEnv.SubTitle.TitleFont > numFonts THEN CEnv.SubTitle.TitleFont = 1
  79.     IF CEnv.XAxis.AxisTitle.TitleFont > numFonts THEN CEnv.XAxis.AxisTitle.TitleFont = 1
  80.     IF CEnv.XAxis.TicFont > numFonts THEN CEnv.XAxis.TicFont = 1
  81.     IF CEnv.YAxis.AxisTitle.TitleFont > numFonts THEN CEnv.YAxis.AxisTitle.TitleFont = 1
  82.     IF CEnv.YAxis.TicFont > numFonts THEN CEnv.YAxis.TicFont = 1
  83.     IF CEnv.Legend.TextFont > numFonts THEN CEnv.Legend.TextFont = 1
  84.  
  85. END SUB
  86.  
  87. '
  88. ' Sub Name: CreateListBox
  89. '
  90. ' Description: Creates a list box within the current window
  91. ' Arguments: text$() - the list
  92. '            tbox    - the listBox
  93. '            func    - function flag for DrawList
  94. '
  95. SUB CreateListBox (text$(), tbox AS ListBox, func)
  96.  
  97.     ' get box length
  98.     tbox.boxLen = tbox.botRow - tbox.topRow - 1
  99.  
  100.     ' get displayable length
  101.     IF tbox.listLen < tbox.boxLen THEN
  102.         tbox.maxLen = tbox.listLen
  103.     ELSE
  104.         tbox.maxLen = tbox.boxLen
  105.     END IF
  106.  
  107.     ' get box width
  108.     tbox.boxWid = tbox.rightCol - tbox.leftCol - 1
  109.  
  110.     ' create box
  111.     WindowBox tbox.topRow, tbox.leftCol, tbox.botRow, tbox.rightCol
  112.  
  113.     ' add scroll bar if necessary or if forced (func = 5)
  114.     IF tbox.listLen <> tbox.maxLen OR func = 5 THEN
  115.         ButtonOpen tbox.scrollButton, 1, "", tbox.topRow + 1, tbox.rightCol, tbox.botRow - 1, tbox.rightCol, 6
  116.     ELSE
  117.         tbox.scrollButton = 0
  118.     END IF
  119.  
  120.     ' open area button
  121.     ButtonOpen tbox.areaButton, 1, "", tbox.topRow + 1, tbox.leftCol + 1, tbox.botRow - 1, tbox.rightCol - 1, 4
  122.  
  123.     ' set current list element relative to list box top
  124.     IF tbox.listPos <= tbox.maxLen THEN
  125.         tbox.currTop = 1
  126.         tbox.currPos = tbox.listPos
  127.     ELSEIF tbox.listPos + tbox.maxLen > tbox.listLen + 1 THEN
  128.         tbox.currTop = tbox.listLen - tbox.maxLen + 1
  129.         tbox.currPos = tbox.listPos - tbox.currTop + 1
  130.     ELSE
  131.         tbox.currTop = tbox.listPos
  132.         tbox.currPos = 1
  133.     END IF
  134.  
  135.     ' Display list within the box
  136.     DrawList text$(), tbox, func
  137.  
  138. END SUB
  139.  
  140. '
  141. ' Sub Name: DrawList
  142. '
  143. ' Description: Displays a list within the boundaries of a list box
  144. ' Arguments: text$() - the list
  145. '            tbox    - the listBox
  146. '            func    - function flag for special operations
  147. '
  148. SUB DrawList (text$(), tbox AS ListBox, func)
  149.  
  150.     ' Draw each element of list that should currently appear in box
  151.     FOR i% = 1 TO tbox.boxLen
  152.         ' highlight current list element
  153.         IF i% = tbox.currPos THEN
  154.             WindowColor 7, 0
  155.         ELSE
  156.             WindowColor 0, 7
  157.         END IF
  158.  
  159.         WindowLocate tbox.topRow + i%, tbox.leftCol + 1
  160.         IF i <= tbox.maxLen THEN
  161.             WindowPrint -1, LEFT$(text$(tbox.currTop + i% - 1) + STRING$(tbox.boxWid, " "), tbox.boxWid)
  162.         ELSE
  163.             WindowPrint -1, STRING$(tbox.boxWid, " ")
  164.         END IF
  165.     NEXT i%
  166.  
  167.     ' update scrollbar position indicator if scrollbar present
  168.     IF tbox.scrollButton <> 0 THEN
  169.         IF tbox.listLen <> 0 THEN
  170.             position = (tbox.currTop + tbox.currPos - 1) * (tbox.maxLen - 2) / tbox.listLen
  171.             IF position < 1 THEN
  172.                position = 1
  173.             ELSEIF position > tbox.maxLen - 2 THEN
  174.               position = tbox.maxLen - 2
  175.             END IF
  176.         ELSE
  177.             position = 1
  178.         END IF
  179.         ButtonSetState tbox.scrollButton, position
  180.     END IF
  181.  
  182.     ' Reset color in case current element was last to be drawn
  183.     WindowColor 0, 7
  184.  
  185.     ' update current position in case list has been scrolled
  186.     tbox.listPos = tbox.currTop + tbox.currPos - 1
  187.  
  188.     ' handle special operation of immediately updating colors$ in title editfield
  189.     SELECT CASE func
  190.         CASE 2: SetAtt 12, tbox.listPos          ' update title editfield foreground color
  191.     END SELECT
  192.  
  193. END SUB
  194.  
  195. '
  196. ' Func Name: HandleMenuEvent
  197. '
  198. ' Description: Determines the action to be performed when user makes
  199. '              a menu selection.
  200. '
  201. ' Arguments: none
  202. '
  203. SUB HandleMenuEvent
  204. SHARED saveFile$, colorDisplay AS INTEGER
  205.  
  206.     menu = MenuCheck(0)
  207.     item = MenuCheck(1)
  208.  
  209.     SELECT CASE menu
  210.         ' file menu title selection
  211.         CASE FILETITLE
  212.             SELECT CASE item
  213.                 ' new chart
  214.                 CASE 1: OpenChart TRUE
  215.                 ' open existing chart
  216.                 CASE 2: OpenChart FALSE
  217.                 ' save current chart
  218.                 CASE 3: junk = SaveChart(saveFile$, FALSE)
  219.                 ' save current chart under new name
  220.                 CASE 4: junk = SaveChart(saveFile$, TRUE)
  221.                 ' exit program
  222.                 CASE 6: Quit
  223.             END SELECT
  224.  
  225.         ' view menu title selection
  226.         CASE VIEWTITLE
  227.             SELECT CASE item
  228.                 ' Display and edit existing chart data
  229.                 CASE 1: ViewData
  230.                 ' Display chart
  231.                 CASE 2: ViewChart
  232.                 ' Display and load fonts
  233.                 CASE 3: ViewFont
  234.                 ' Display and edit screen mode
  235.                 CASE 4: ViewScreenMode
  236.             END SELECT
  237.  
  238.         ' Gallery menu title selection
  239.         CASE GALLERYTITLE
  240.             ' change chart type
  241.             ChangeChartType item
  242.  
  243.         ' Chart menu title selection
  244.         CASE CHARTTITLE
  245.             SELECT CASE item
  246.                 ' Change chart window
  247.                 CASE 1: ChangeWindow 1, "Chart Window", CEnv.ChartWindow
  248.                 ' Change data window
  249.                 CASE 2: ChangeWindow 1, "Data Window", CEnv.DataWindow
  250.                 ' Change legend
  251.                 CASE 3: ChangeLegend
  252.                 ' Change X axis
  253.                 CASE 4: ChangeAxis "X Axis", CEnv.XAxis
  254.                 ' Change Y axis
  255.                 CASE 5: ChangeAxis "Y Axis", CEnv.YAxis
  256.             END SELECT
  257.  
  258.         ' Title menu title selection
  259.         CASE TITLETITLE
  260.             SELECT CASE item
  261.                 ' Display and modify main title
  262.                 CASE 1: ChangeTitle 1, "Main Title", CEnv.MainTitle, 6, 16
  263.                 ' Display and modify sub title
  264.                 CASE 2: ChangeTitle 1, "Sub Title", CEnv.SubTitle, 6, 16
  265.                 ' Display and modify x axis title
  266.                 CASE 3:
  267.                     ChangeTitle 1, "X-axis Title", CEnv.XAxis.AxisTitle, 6, 16
  268.                     CEnv.XAxis.ScaleTitle.TitleColor = CEnv.XAxis.AxisTitle.TitleColor
  269.                     CEnv.XAxis.ScaleTitle.Justify = CEnv.XAxis.AxisTitle.Justify
  270.                 ' Display and modify y axis title
  271.                 CASE 4:
  272.                     ChangeTitle 1, "Y-axis Title", CEnv.YAxis.AxisTitle, 6, 16
  273.                     CEnv.YAxis.ScaleTitle.TitleColor = CEnv.YAxis.AxisTitle.TitleColor
  274.                     CEnv.YAxis.ScaleTitle.Justify = CEnv.YAxis.AxisTitle.Justify
  275.             END SELECT
  276.  
  277.         ' Options menu title selection
  278.         CASE OPTIONSTITLE
  279.             colorDisplay = item - 2
  280.             SetDisplayColor
  281.     END SELECT
  282.  
  283. END SUB
  284.  
  285. '
  286. ' Func Name: InitAll
  287. '
  288. ' Description: Performs all initialization for the program
  289. '
  290. ' Arguments: none
  291. '
  292. SUB InitAll
  293. SHARED finished AS INTEGER, screenMode AS INTEGER, saveFile$
  294. SHARED origPath$, colorDisplay  AS INTEGER
  295.  
  296.     saveFile$ = ""                          ' No save file to begin with
  297.     origPath$ = CURDIR$                     ' get working path
  298.     colorDisplay = FALSE                    ' start with mono display
  299.     GetBestMode screenMode                  ' get initial screen mode
  300.  
  301.     SCREEN 0                                ' init screen
  302.     WIDTH 80, 25
  303.     CLS
  304.  
  305.     MenuInit                                ' init menu routines
  306.     WindowInit                              ' init window routines
  307.     MouseInit                               ' init mouse routines
  308.  
  309.     ' exit if no graphic mode available
  310.     IF screenMode = 0 THEN
  311.         PrintError "No graphic screen modes available for charting. Exiting program."
  312.         finished = TRUE
  313.         EXIT SUB
  314.     ELSE
  315.         finished = FALSE
  316.     END IF
  317.  
  318.     SetUpMenu                               ' Set up menu bar
  319.     SetUpBackground                         ' Set up screen background
  320.     InitChart                               ' Initialize chart
  321.     InitColors                              ' Set up color list
  322.     InitStyles                              ' Set up border style list
  323.     InitFonts                               ' Set up font lists
  324.  
  325.     MenuShow                                ' display menu bar
  326.     MouseShow                               ' display mouse
  327.  
  328.     '               display program introduction
  329.     a$ = "Microsoft QuickChart|"
  330.     a$ = a$ + "A Presentation Graphics Toolbox Demo|"
  331.     a$ = a$ + "for|"
  332.     a$ = a$ + "Microsoft BASIC 7.1 Professional Development System|"
  333.     a$ = a$ + "Copyright (c) 1989-1990 Microsoft Corporation|"
  334.  
  335.     temp = Alert(4, a$, 9, 12, 15, 68, "Color", "Monochrome", "")
  336.  
  337.     ' set display to color or monochrome depending on colorDislay
  338.     IF temp = 1 THEN colorDisplay = TRUE
  339.  
  340.     SetDisplayColor
  341.  
  342. END SUB
  343.  
  344. '
  345. ' Sub Name: InitChart
  346. '
  347. ' Description: Initializes chart environment variables and other
  348. '              related information.
  349. '
  350. ' Arguments: None
  351. '
  352. SUB InitChart
  353.  
  354.     MenuItemToggle GALLERYTITLE, cBar       ' default chart type is BAR so
  355.                                             ' set up menu that way
  356.  
  357.     DefaultChart CEnv, cBar, cPlain         ' Get defaults for chart variable
  358.  
  359.     ClearData                               ' Clear all chart data
  360.     
  361. END SUB
  362.  
  363. '
  364. ' Sub Name: Initcolors
  365. '
  366. ' Description: Creates color list based on screen mode
  367. '
  368. ' Arguments: None
  369. '
  370. SUB InitColors
  371. SHARED screenMode AS INTEGER
  372. SHARED egacolor() AS INTEGER
  373.  
  374.     ' init EGA colors$ for SetAtt
  375.     egacolor(0) = 0
  376.     egacolor(1) = 1
  377.     egacolor(2) = 2
  378.     egacolor(3) = 3
  379.     egacolor(4) = 4
  380.     egacolor(5) = 5
  381.     egacolor(6) = 20
  382.     egacolor(7) = 7
  383.     egacolor(8) = 56
  384.     egacolor(9) = 57
  385.     egacolor(10) = 58
  386.     egacolor(11) = 59
  387.     egacolor(12) = 60
  388.     egacolor(13) = 61
  389.     egacolor(14) = 62
  390.     egacolor(15) = 63
  391.  
  392.     ' create list of displayable colors$ based on screen mode
  393.     SELECT CASE screenMode
  394.         CASE 1
  395.             numColors = 4
  396.             REDIM color$(numColors)
  397.             colors$(1) = "Black"
  398.             colors$(2) = "White"
  399.             colors$(3) = "Bright Cyan"
  400.             colors$(4) = "Bright Magenta"
  401.         CASE 2, 3, 4, 11
  402.             numColors = 2
  403.             REDIM color$(numColors)
  404.             colors$(1) = "Black"
  405.             colors$(2) = "White"
  406.         CASE 7, 8, 9, 12, 13
  407.             numColors = 16
  408.             REDIM color$(numColors)
  409.             colors$(1) = "Black"
  410.             colors$(2) = "High White"
  411.             colors$(3) = "Blue"
  412.             colors$(4) = "Green"
  413.             colors$(5) = "Cyan"
  414.             colors$(6) = "Red"
  415.             colors$(7) = "Magenta"
  416.             colors$(8) = "Brown"
  417.             colors$(9) = "White"
  418.             colors$(10) = "Gray"
  419.             colors$(11) = "Bright Blue"
  420.             colors$(12) = "Bright Green"
  421.             colors$(13) = "Bright Cyan"
  422.             colors$(14) = "Bright Red"
  423.             colors$(15) = "Bright Magenta"
  424.             colors$(16) = "Yellow"
  425.         CASE 10
  426.             numColors = 4
  427.             REDIM color$(numColors)
  428.             colors$(1) = "Off"
  429.             colors$(2) = "On High"
  430.             colors$(3) = "On Normal"
  431.             colors$(4) = "Blink"
  432.     END SELECT
  433.  
  434.     ' reset chart color pointers to default values
  435.     IF numColors < 16 THEN
  436.         CEnv.ChartWindow.Background = 0
  437.         CEnv.ChartWindow.BorderColor = 1
  438.         CEnv.DataWindow.Background = 0
  439.         CEnv.DataWindow.BorderColor = 1
  440.         CEnv.MainTitle.TitleColor = 1
  441.         CEnv.SubTitle.TitleColor = 1
  442.         CEnv.XAxis.AxisColor = 1
  443.         CEnv.XAxis.AxisTitle.TitleColor = 1
  444.         CEnv.YAxis.AxisColor = 1
  445.         CEnv.YAxis.AxisTitle.TitleColor = 1
  446.         CEnv.Legend.TextColor = 1
  447.         CEnv.Legend.LegendWindow.Background = 0
  448.         CEnv.Legend.LegendWindow.BorderColor = 1
  449.     END IF
  450. END SUB
  451.  
  452. '
  453. ' Sub Name: InitFonts
  454. '
  455. ' Description: sets up default font and initializes font list
  456. '
  457. ' Arguments: None
  458. '
  459. SUB InitFonts
  460. DIM FI AS FontInfo
  461.  
  462.     ' reset
  463.     UnRegisterFonts
  464.     SetMaxFonts 1, 1
  465.  
  466.     ' get default font
  467.     DefaultFont Segment%, Offset%
  468.     reg% = RegisterMemFont%(Segment%, Offset%)
  469.  
  470.     ' load default font
  471.     numFonts = LoadFont("n1")
  472.  
  473.     IF numFonts = 0 THEN numFonts = 1
  474.  
  475.     fonts$(numFonts) = "IBM 8 Point"
  476.  
  477.     UnRegisterFonts
  478. END SUB
  479.  
  480. '
  481. ' Sub Name: InitStyles
  482. '
  483. ' Description: Initializes border styles list
  484. '
  485. ' Arguments: None
  486. '
  487. SUB InitStyles
  488.  
  489.     ' create list of border styles
  490.     styles$(1) = "────────────────"
  491.     styles$(2) = "────    ────        "
  492.     styles$(3) = "────         ──      "
  493.     styles$(4) = "──  ──  ──      ──  "
  494.     styles$(5) = "──  ─   ──  ─       "
  495.     styles$(6) = "─── ─── ─── ──    ─ "
  496.     styles$(7) = "─── ─ ─ ─── ─     ─ "
  497.     styles$(8) = "──── ── ── ──── "
  498.     styles$(9) = "──── ── ──── ── "
  499.     styles$(10) = "──── ─ ─ ── ─     ─ "
  500.     styles$(11) = "──  ─── ─    ─  ─── "
  501.     styles$(12) = "─ ─ ─   ─ ─ ─       "
  502.     styles$(13) = "─ ─ ─ ─ ─ ─ ─     ─ "
  503.     styles$(14) = "───  ─  ───  ─      "
  504.     styles$(15) = "──  ─   ─   ─    ─  "
  505.  
  506. END SUB
  507.  
  508. '
  509. ' Func Name: Min
  510. '
  511. ' Description: Compares two numbers and returns the smallest
  512. '
  513. ' Arguments: num1, num2 - numbers to compare
  514. '
  515. FUNCTION Min% (num1, num2)
  516.  
  517.     IF num1 <= num2 THEN
  518.         Min% = num1
  519.     ELSE
  520.         Min% = num2
  521.     END IF
  522.  
  523. END FUNCTION
  524.  
  525. '
  526. ' Sub Name: Quit
  527. '
  528. ' Description: Exits the program after allowing the user a chance to
  529. '              save the current chart
  530. '
  531. ' Arguments: None
  532. '
  533. SUB Quit
  534. SHARED finished AS INTEGER, saveFile$, origPath$
  535.  
  536.     ' Allow user to save chart if necessary
  537.     IF chartChanged THEN
  538.         a$ = "| " + "Current chart has not been saved.  Save now?"
  539.  
  540.         status = Alert(4, a$, 8, 15, 12, 65, "Yes", "No", "Cancel")
  541.  
  542.         ' save chart
  543.         IF status = OK THEN
  544.             status = SaveChart(saveFile$, FALSE)
  545.         END IF
  546.     ELSE
  547.         status = OK
  548.     END IF
  549.  
  550.     ' quit if operation has not been canceled.
  551.     IF status <> CANCEL THEN
  552.         CHDRIVE MID$(origPath$, 1, 2)
  553.         CHDIR MID$(origPath$, 3, LEN(origPath$))
  554.         finished = TRUE
  555.         MouseHide
  556.         COLOR 15, 0
  557.         CLS
  558.     END IF
  559.  
  560. END SUB
  561.  
  562. '
  563. ' Sub Name: ScrollList
  564. '
  565. ' Description: Handles scrolling for a list box.
  566. '
  567. ' Arguments: text$() - list
  568. '            tbox - list box
  569. '            currButton - current button
  570. '            status - to determine if button was pressed, or up or down arrow
  571. '                     keys were used
  572. '            func - for special operations (passed to DrawList)
  573. '            winRow - top row of current window
  574. '            winCol - left column of current window
  575. '
  576. SUB ScrollList (text$(), tbox AS ListBox, currButton, status, func, winRow, winCol)
  577.  
  578.     ' scroll using scroll buttons
  579.     IF currButton = tbox.scrollButton AND status = 1 THEN
  580.         SELECT CASE Dialog(19)
  581.             ' scroll up
  582.             CASE -1:
  583.                 IF tbox.currTop > 1 THEN
  584.                     tbox.currTop = tbox.currTop - 1
  585.                     tbox.currPos = tbox.currPos + 1
  586.                     IF tbox.currPos > tbox.maxLen THEN tbox.currPos = tbox.maxLen
  587.                 END IF
  588.             ' scroll down
  589.             CASE -2:
  590.                 IF tbox.currTop + tbox.maxLen <= tbox.listLen THEN
  591.                     tbox.currTop = tbox.currTop + 1
  592.                     tbox.currPos = tbox.currPos - 1
  593.                     IF tbox.currPos < 1 THEN tbox.currPos = 1
  594.                 END IF
  595.             ' scroll to position
  596.             CASE ELSE:
  597.                 position = Dialog(19)
  598.                 IF position > 1 THEN
  599.                     position = position * (tbox.listLen) / (tbox.boxLen - 2)
  600.                     IF position < 1 THEN
  601.                         positon = 1
  602.                     ELSEIF position > tbox.listLen THEN
  603.                         position = tbox.listLen
  604.                     END IF
  605.                 END IF
  606.  
  607.                 IF tbox.currTop <= position AND tbox.currTop + tbox.maxLen > position THEN
  608.                     tbox.currPos = position - tbox.currTop + 1
  609.                 ELSEIF position <= tbox.maxLen THEN
  610.                     tbox.currTop = 1
  611.                     tbox.currPos = position
  612.                 ELSE
  613.                     tbox.currTop = position - tbox.maxLen + 1
  614.                     tbox.currPos = position - tbox.currTop + 1
  615.                 END IF
  616.         END SELECT
  617.  
  618.     ' area button chosen
  619.     ELSEIF status = 1 THEN
  620.         ' make selected position the current position
  621.         IF Dialog(17) <= tbox.maxLen THEN
  622.             tbox.currPos = Dialog(17)
  623.             DrawList text$(), tbox, func
  624.         END IF
  625.  
  626.         ' poll for repeated scrolling while mouse button is down
  627.         DO
  628.             X! = TIMER
  629.             MousePoll r, c, lb, rb              ' poll mouse
  630.             IF lb = TRUE THEN
  631.                 ' if below list box then scroll down
  632.                 IF r > tbox.botRow + winRow - 2 THEN
  633.                     GOSUB Down1
  634.                 ' if above list box then scroll up
  635.                 ELSEIF r < tbox.topRow + winRow THEN
  636.                     GOSUB Up1
  637.                 ' if to right of list box then scroll down
  638.                 ELSEIF c > tbox.rightCol + winCol - 2 THEN
  639.                     GOSUB Down1
  640.                 ' if to left of list box then scroll up
  641.                 ELSEIF c < tbox.leftCol + winCol THEN
  642.                     GOSUB Up1
  643.                 ' inside box
  644.                 ELSEIF r - winRow - tbox.topRow + 1 <= tbox.maxLen THEN
  645.                     tbox.currPos = r - winRow - tbox.topRow + 1
  646.                 END IF
  647.                 
  648.                 ' draw list
  649.                 DrawList text$(), tbox, func
  650.             ELSE
  651.                 EXIT DO
  652.             END IF
  653.             WHILE TIMER < X! + .05: WEND
  654.         LOOP
  655.  
  656.     ' up arrow key hit
  657.     ELSEIF status = 2 THEN
  658.         GOSUB Up1
  659.  
  660.     ' down arrow key hit
  661.     ELSEIF status = 3 THEN
  662.         GOSUB Down1
  663.     END IF
  664.  
  665.     DrawList text$(), tbox, func                    ' redraw list
  666.  
  667.     EXIT SUB
  668.  
  669. ' scroll list up one
  670. Up1:
  671.     IF tbox.currPos > 1 THEN
  672.         tbox.currPos = tbox.currPos - 1
  673.     ELSEIF tbox.currTop > 1 THEN
  674.         tbox.currTop = tbox.currTop - 1
  675.     END IF
  676. RETURN
  677.  
  678. ' scroll list down one
  679. Down1:
  680.     IF tbox.currPos < tbox.maxLen THEN
  681.         tbox.currPos = tbox.currPos + 1
  682.     ELSEIF tbox.currTop + tbox.maxLen <= tbox.listLen THEN
  683.         tbox.currTop = tbox.currTop + 1
  684.     END IF
  685. RETURN
  686.  
  687. END SUB
  688.  
  689. '
  690. ' Sub Name: Setatt
  691. '
  692. ' Description: Changes a color's attribute to that of another color's.
  693. '              This is used in the ChangeTitle routine to allow user
  694. '              color selections to immediately change the foreground
  695. '              color of the title edit field.  This allows the user
  696. '              to view the colors as they would look on a chart
  697. '
  698. ' Arguments: change - color to change
  699. '            source - color to change to
  700. '
  701. SUB SetAtt (change, source)
  702. SHARED screenMode AS INTEGER
  703. SHARED egacolor() AS INTEGER
  704.  
  705.     ' map colors$ based on screen mode
  706.     SELECT CASE screenMode
  707.         CASE 10:
  708.             IF source > 2 THEN
  709.                 temp = 9                            ' set "normal" and "blink" to white
  710.             ELSE
  711.                 temp = source                       ' off = black; high white = bright white
  712.             END IF
  713.         CASE 1:
  714.             IF source = 3 THEN                      ' map to cyan
  715.                 temp = 13
  716.             ELSEIF source = 4 THEN                  ' map to magenta
  717.                 temp = 15
  718.             ELSE                                    ' others okay
  719.                 temp = source
  720.             END IF
  721.         CASE ELSE
  722.             temp = source                           ' colors$ okay
  723.     END SELECT
  724.  
  725.     ' change attribute
  726.     DIM regs AS RegType
  727.     regs.ax = &H1000
  728.     regs.bx = 256 * egacolor(TrueColr(temp)) + change
  729.     CALL INTERRUPT(&H10, regs, regs)
  730.  
  731. END SUB
  732.  
  733. '
  734. ' Sub Name: SetDisplayColor
  735. '
  736. ' Description: Changes the program's display to monochrome (no colors) or
  737. '              to color (include colors in menu bar) based on the value of
  738. '              colorDisplay.
  739. '
  740. ' Arguments: none
  741. '
  742. SUB SetDisplayColor
  743. SHARED colorDisplay AS INTEGER
  744.  
  745.     MouseHide
  746.  
  747.     ' redraw background based on display color
  748.     SetUpBackground
  749.  
  750.     ' set menu bar to include colors
  751.     IF colorDisplay THEN
  752.         MenuSetState OPTIONSTITLE, 1, 2
  753.         MenuSetState OPTIONSTITLE, 2, 1
  754.         MenuColor 0, 7, 4, 8, 0, 4, 7
  755.     ' set monochrome menu bar
  756.     ELSE
  757.         MenuSetState OPTIONSTITLE, 1, 1
  758.         MenuSetState OPTIONSTITLE, 2, 2
  759.         MenuColor 0, 7, 15, 8, 7, 0, 15
  760.     END IF
  761.  
  762.     MenuShow
  763.     MouseShow
  764.  
  765. END SUB
  766.  
  767. '
  768. ' Sub Name: SetUpBackground
  769. '
  770. ' Description: Creates and displays background screen pattern
  771. '
  772. ' Arguments: none
  773. '
  774. SUB SetUpBackground
  775. SHARED colorDisplay AS INTEGER
  776.  
  777.     MouseHide
  778.  
  779.     WIDTH , 25
  780.     IF colorDisplay THEN
  781.         COLOR 15, 1                             ' set color for background
  782.     ELSE
  783.         COLOR 15, 0
  784.     END IF
  785.     CLS
  786.  
  787.     FOR a = 2 TO 80 STEP 4                      ' create and display pattern
  788.         FOR b = 2 TO 25 STEP 2
  789.             LOCATE b, a
  790.             PRINT CHR$(250);
  791.         NEXT b
  792.     NEXT a
  793.  
  794.     MouseShow
  795.  
  796. END SUB
  797.  
  798. '
  799. ' Sub Name: SetUpMenu
  800. '
  801. ' Description: Creates menu bar for the program
  802. '
  803. ' Arguments: none
  804. '
  805. SUB SetUpMenu
  806.  
  807.     ' file menu title
  808.     MenuSet FILETITLE, 0, 1, "File", 1
  809.     MenuSet FILETITLE, 1, 1, "New", 1
  810.     MenuSet FILETITLE, 2, 1, "Open ...", 1
  811.     MenuSet FILETITLE, 3, 1, "Save", 1
  812.     MenuSet FILETITLE, 4, 1, "Save As ...", 6
  813.     MenuSet FILETITLE, 5, 1, "-", 1
  814.     MenuSet FILETITLE, 6, 1, "Exit", 2
  815.  
  816.     ' view menu title
  817.     MenuSet VIEWTITLE, 0, 1, "View", 1
  818.     MenuSet VIEWTITLE, 1, 1, "Data ...", 1
  819.     MenuSet VIEWTITLE, 2, 1, "Chart        F5", 1
  820.     MenuSet VIEWTITLE, 3, 1, "Fonts ...", 1
  821.     MenuSet VIEWTITLE, 4, 1, "Screen Mode ...", 1
  822.  
  823.     ' gallery menu title
  824.     MenuSet GALLERYTITLE, 0, 1, "Gallery", 1
  825.     MenuSet GALLERYTITLE, 1, 1, "Bar ...", 1
  826.     MenuSet GALLERYTITLE, 2, 1, "Column ...", 1
  827.     MenuSet GALLERYTITLE, 3, 1, "Line ...", 1
  828.     MenuSet GALLERYTITLE, 4, 1, "Scatter ...", 1
  829.     MenuSet GALLERYTITLE, 5, 1, "Pie ...", 1
  830.  
  831.     ' chart menu title
  832.     MenuSet CHARTTITLE, 0, 1, "Chart", 1
  833.     MenuSet CHARTTITLE, 1, 1, "Chart Window ...", 1
  834.     MenuSet CHARTTITLE, 2, 1, "Data Window ...", 1
  835.     MenuSet CHARTTITLE, 3, 1, "Legend ...", 1
  836.     MenuSet CHARTTITLE, 4, 1, "X Axis ...", 1
  837.     MenuSet CHARTTITLE, 5, 1, "Y Axis ...", 1
  838.  
  839.     ' title menu title
  840.     MenuSet TITLETITLE, 0, 1, "Title", 1
  841.     MenuSet TITLETITLE, 1, 1, "Main ...", 1
  842.     MenuSet TITLETITLE, 2, 1, "Sub ...", 1
  843.     MenuSet TITLETITLE, 3, 1, "X Axis ...", 1
  844.     MenuSet TITLETITLE, 4, 1, "Y Axis ...", 1
  845.  
  846.     ' options menu title
  847.     MenuSet OPTIONSTITLE, 0, 1, "Options", 1
  848.     MenuSet OPTIONSTITLE, 1, 1, "Color", 1
  849.     MenuSet OPTIONSTITLE, 2, 1, "Monochrome", 1
  850.  
  851.     ' setup short cuts for some menu choices
  852.     ShortCutKeySet VIEWTITLE, 2, CHR$(0) + CHR$(63)     ' F5 = View Chart
  853.  
  854.     ' set original menu colors for monochrome screen
  855.     MenuColor 0, 7, 15, 8, 7, 0, 15
  856.     MenuPreProcess
  857.  
  858. END SUB
  859.  
  860. '
  861. ' Function Name: TrueColr
  862. '
  863. ' Description: Maps a given chart color to its actual color
  864. '              and returns this color.  This is needed because the chart
  865. '              colors start with BLACK = 1 and HIGH WHITE = 2
  866. '
  867. ' Arguments: colr - chart color number
  868. '
  869. FUNCTION TrueColr% (colr)
  870.  
  871.     IF colr = 1 THEN                                ' black
  872.         TrueColr% = 0                               ' bright white
  873.     ELSEIF colr = 2 THEN
  874.         TrueColr% = 15
  875.     ELSE
  876.         TrueColr% = colr - 2                        ' all others
  877.     END IF
  878.  
  879. END FUNCTION
  880.  
  881. '
  882. ' Sub Name: ViewChart
  883. '
  884. ' Description: Displays the chart
  885. '
  886. ' Arguments: none
  887. '
  888. SUB ViewChart
  889. SHARED setVal!(), Cat$(), setLen() AS INTEGER, setName$()
  890. SHARED screenMode AS INTEGER
  891.  
  892.     ' When a chart is drawn, data is moved from the 2-dimensional array
  893.     ' into arrays suitable for the charting library routines.  The
  894.     ' following arrays are used directly in calls to the charting routines:
  895.     DIM ValX1!(1 TO cMaxValues)                    ' pass to chart routine
  896.     DIM ValY1!(1 TO cMaxValues)
  897.     DIM ValX2!(1 TO cMaxValues, 1 TO cMaxSeries)   ' pass to chartMS routine
  898.     DIM ValY2!(1 TO cMaxValues, 1 TO cMaxSeries)
  899.  
  900.     DIM explode(1 TO cMaxValues)  AS INTEGER       ' explode pie chart pieces
  901.  
  902.  
  903.    ' Make sure some data exists
  904.    IF setNum <= 0 THEN
  905.        a$ = "|"
  906.        a$ = a$ + "No data available for chart."
  907.        junk = Alert(4, a$, 8, 15, 12, 65, "", "", "")
  908.        EXIT SUB
  909.    END IF
  910.  
  911.    ' find the longest series
  912.    maxLen% = 0
  913.    FOR i% = 1 TO setNum
  914.       IF setLen(i%) > maxLen% THEN maxLen% = setLen(i%)
  915.    NEXT i%
  916.  
  917.    ' Set up the proper screen mode (exit if not valid)
  918.    ChartScreen screenMode
  919.    IF ChartErr = cBadScreen THEN
  920.         PrintError "Invalid screen mode. Can't display chart."
  921.         EXIT SUB
  922.    END IF
  923.  
  924.    ' Process depending on chart type
  925.    SELECT CASE CEnv.ChartType
  926.       CASE cBar, cColumn, cLine, cPie:
  927.          ' If the chart is a single series one or a pie chart:
  928.          IF setNum = 1 OR CEnv.ChartType = cPie THEN
  929.  
  930.             ' Transfer data into a single dimension array:
  931.             FOR i% = 1 TO maxLen%
  932.                ValX1!(i%) = setVal!(i%, 1)
  933.             NEXT i%
  934.  
  935.             IF CEnv.ChartType = cPie THEN
  936.                 ' determine which pieces to explode
  937.                 FOR i% = 1 TO maxLen%
  938.                     IF setVal!(i%, 2) <> 0 THEN
  939.                         explode(i%) = 1
  940.                     ELSE
  941.                         explode(i%) = 0
  942.                     END IF
  943.                 NEXT i%
  944.  
  945.                 ' display pie chart
  946.                 ChartPie CEnv, Cat$(), ValX1!(), explode(), maxLen%
  947.             ELSE
  948.                 Chart CEnv, Cat$(), ValX1!(), maxLen%
  949.             END IF
  950.  
  951.          ' If multiple series, then data is OK so just call routine:
  952.          ELSE
  953.             ChartMS CEnv, Cat$(), setVal!(), maxLen%, 1, setNum, setName$()
  954.          END IF
  955.  
  956.       CASE cScatter:
  957.          ' Make sure there's enough data sets:
  958.          IF setNum = 1 THEN
  959.             SCREEN 0
  960.             WIDTH 80
  961.             SetUpBackground
  962.             MenuShow
  963.             MouseShow
  964.             a$ = "|"
  965.             a$ = a$ + "Too few data sets for Scatter chart"
  966.             junk = Alert(4, a$, 8, 15, 12, 65, "", "", "")
  967.             EXIT SUB
  968.  
  969.          ' If it's a single series scatter, transfer data to one-
  970.          ' dimensional arrays and make chart call:
  971.          ELSEIF setNum = 2 THEN
  972.             FOR i% = 1 TO maxLen%
  973.                ValX1!(i%) = setVal!(i%, 1)
  974.                ValY1!(i%) = setVal!(i%, 2)
  975.             NEXT i%
  976.             ChartScatter CEnv, ValX1!(), ValY1!(), maxLen%
  977.  
  978.          ' If it's a multiple series scatter, transfer odd columns to
  979.          ' X-axis data array and even columns to Y-axis array and make
  980.          ' chart call:
  981.          ELSE
  982.             FOR j% = 2 TO setNum STEP 2
  983.                FOR i% = 1 TO maxLen%
  984.                   ValX2!(i%, j% \ 2) = setVal!(i%, j% - 1)
  985.                   ValY2!(i%, j% \ 2) = setVal!(i%, j%)
  986.                NEXT i%
  987.             NEXT j%
  988.  
  989.             ChartScatterMS CEnv, ValX2!(), ValY2!(), maxLen%, 1, setNum \ 2, setName$()
  990.          END IF
  991.  
  992.    END SELECT
  993.  
  994.    ' If there's been a "fatal" error, indicate what it was:
  995.    IF ChartErr <> 0 THEN
  996.        GOSUB ViewError
  997.  
  998.    ' Otherwise, just wait for a keypress:
  999.    ELSE
  1000.       ' Wait for keypress
  1001.       DO
  1002.             c$ = INKEY$
  1003.             MousePoll r, c, lb, rb
  1004.       LOOP UNTIL c$ <> "" OR lb OR rb
  1005.       SCREEN 0
  1006.       WIDTH 80
  1007.       SetUpBackground
  1008.       MenuShow
  1009.       MouseShow
  1010.    END IF
  1011.  
  1012. EXIT SUB
  1013.  
  1014. ' handle charting errors
  1015. ViewError:
  1016.  
  1017.     ' re-init the display
  1018.     SCREEN 0
  1019.     WIDTH 80
  1020.     SetUpBackground
  1021.     MenuShow
  1022.     MouseShow
  1023.  
  1024.     ' display appropriate error message
  1025.     SELECT CASE ChartErr
  1026.         CASE cBadDataWindow:
  1027.             PrintError "Data window cannot be displayed in available space."
  1028.         CASE cBadLegendWindow:
  1029.             PrintError "Invalid legend coordinates."
  1030.         CASE cTooFewSeries:
  1031.             PrintError "Too few series to plot."
  1032.         CASE cTooSmallN:
  1033.             PrintError "No data in series."
  1034.         CASE IS > 200:                              ' basic error
  1035.             PrintError "BASIC error #" + LTRIM$(STR$(ChartErr - 200)) + " occurred."
  1036.         CASE ELSE:                                  ' extraneous error
  1037.             PrintError "Charting error #" + LTRIM$(STR$(ChartErr)) + " occurred."
  1038.     END SELECT
  1039.  
  1040. RETURN
  1041.  
  1042. END SUB
  1043.  
  1044. '
  1045. ' Sub Name: ViewFont
  1046. '
  1047. ' Description: Displays list of registered fonts and allows user to
  1048. '              select one or more of these fonts to load
  1049. '
  1050. ' Arguments: none
  1051. '
  1052. SUB ViewFont
  1053. SHARED screenMode AS INTEGER
  1054. SHARED origPath$
  1055. DIM FI AS FontInfo
  1056. DIM rfonts$(1 TO MAXFONTS)
  1057.  
  1058.     SetMaxFonts MAXFONTS, MAXFONTS
  1059.  
  1060.     ' get default font
  1061.     DefaultFont Segment%, Offset%
  1062.     numReg = RegisterMemFont%(Segment%, Offset%)
  1063.  
  1064.     ' use font files that are best suited for current screen mode
  1065.     IF MID$(origPath$, LEN(origPath$), 1) = "\" THEN
  1066.         t$ = ""
  1067.     ELSE
  1068.         t$ = "\"
  1069.     END IF
  1070.     SELECT CASE screenMode
  1071.         CASE 2, 8
  1072.             cour$ = origPath$ + t$ + "COURA.FON"
  1073.             helv$ = origPath$ + t$ + "HELVA.FON"
  1074.             tims$ = origPath$ + t$ + "TMSRA.FON"
  1075.         CASE 11, 12
  1076.             cour$ = origPath$ + t$ + "COURE.FON"
  1077.             helv$ = origPath$ + t$ + "HELVE.FON"
  1078.             tims$ = origPath$ + t$ + "TMSRE.FON"
  1079.         CASE ELSE
  1080.             cour$ = origPath$ + t$ + "COURB.FON"
  1081.             helv$ = origPath$ + t$ + "HELVB.FON"
  1082.             tims$ = origPath$ + t$ + "TMSRB.FON"
  1083.     END SELECT
  1084.     ' register courier fonts
  1085.     numReg = numReg + RegisterFonts%(cour$)
  1086.     fontname$ = cour$
  1087.     IF FontErr > 0 THEN GOSUB FontError
  1088.  
  1089.     ' register helvetica fonts
  1090.     numReg = numReg + RegisterFonts%(helv$)
  1091.     fontname$ = helv$
  1092.     IF FontErr > 0 THEN GOSUB FontError
  1093.  
  1094.     ' register times roman fonts
  1095.     numReg = numReg + RegisterFonts%(tims$)
  1096.     fontname$ = tims$
  1097.     IF FontErr > 0 THEN GOSUB FontError
  1098.  
  1099.     ' create a list of registered fonts
  1100.     FOR i = 1 TO numReg
  1101.         GetRFontInfo i, FI
  1102.         rfonts$(i) = RTRIM$(MID$(FI.FaceName, 1, 8)) + STR$(FI.Points) + " Point"
  1103.     NEXT i
  1104.  
  1105.     ' set up window display
  1106.     winRow = 5
  1107.     winCol = 25
  1108.     WindowOpen 1, winRow, winCol, winRow + numReg + 1, 51, 0, 7, 0, 7, 15, FALSE, FALSE, FALSE, TRUE, 2, "Chart Fonts"
  1109.  
  1110.     ' open buttons for each font in list
  1111.     FOR i% = 1 TO numReg
  1112.         ButtonOpen i, 1, rfonts$(i), i, 4, 0, 0, 2
  1113.         FOR j% = 1 TO numFonts
  1114.             IF fonts$(j%) = rfonts$(i%) THEN ButtonSetState i, 2
  1115.         NEXT j%
  1116.     NEXT i%
  1117.  
  1118.     WindowLine numReg + 1
  1119.     ButtonOpen numReg + 1, 2, "Load", numReg + 2, 4, 0, 0, 1
  1120.     ButtonOpen numReg + 2, 1, "Cancel ", numReg + 2, 15, 0, 0, 1
  1121.  
  1122.     ' start with cursor on first button
  1123.     currButton = 1
  1124.     pushButton = numReg + 1
  1125.  
  1126.     ' window control loop
  1127.     finished = FALSE
  1128.     WHILE NOT finished
  1129.         WindowDo currButton, 0
  1130.         SELECT CASE Dialog(0)
  1131.             CASE 1                                     ' button pressed
  1132.                 currButton = Dialog(1)
  1133.                 IF currButton > numReg THEN
  1134.                     pushButton = currButton
  1135.                     finished = TRUE
  1136.                 ELSE
  1137.                     ButtonToggle currButton
  1138.                 END IF
  1139.             CASE 6                                      ' enter
  1140.                 finished = TRUE
  1141.             CASE 7                                      ' tab
  1142.                 SELECT CASE currButton
  1143.                     CASE numReg, numReg + 1:
  1144.                         currButton = currButton + 1
  1145.                         ButtonSetState pushButton, 1
  1146.                         ButtonSetState currButton, 2
  1147.                         pushButton = currButton
  1148.                     CASE numReg + 2:
  1149.                         currButton = 1
  1150.                         ButtonSetState pushButton, 1
  1151.                         pushButton = numReg + 1
  1152.                         ButtonSetState pushButton, 2
  1153.                     CASE ELSE:
  1154.                         currButton = currButton + 1
  1155.                 END SELECT
  1156.             CASE 8                                      ' back tab
  1157.                 SELECT CASE currButton
  1158.                     CASE 1:
  1159.                         currButton = numReg + 2
  1160.                         ButtonSetState pushButton, 1
  1161.                         ButtonSetState currButton, 2
  1162.                         pushButton = currButton
  1163.                     CASE numReg + 2:
  1164.                         currButton = numReg + 1
  1165.                         ButtonSetState pushButton, 1
  1166.                         ButtonSetState currButton, 2
  1167.                         pushButton = currButton
  1168.                     CASE ELSE:
  1169.                         currButton = currButton - 1
  1170.                     END SELECT
  1171.             CASE 9                                      ' escape
  1172.                 pushButton = numReg + 2
  1173.                 finished = TRUE
  1174.             CASE 10, 12                                 ' up, left arrow
  1175.                 IF currButton <= numReg THEN ButtonSetState currButton, 2
  1176.             CASE 11, 13                                 ' down, right arrow
  1177.                 IF currButton <= numReg THEN ButtonSetState currButton, 1
  1178.             CASE 14                                     ' space bar
  1179.                 IF currButton <= numReg THEN
  1180.                     ButtonToggle currButton
  1181.                 ELSE
  1182.                     finished = TRUE
  1183.                 END IF
  1184.         END SELECT
  1185.  
  1186.     ' finished and not cancelled
  1187.     IF finished AND pushButton = numReg + 1 THEN
  1188.         ' create font spec for load operation
  1189.         FontSpec$ = ""
  1190.         FOR i% = 1 TO numReg
  1191.             IF ButtonInquire(i) = 2 THEN
  1192.                 FontSpec$ = FontSpec$ + "/n" + LTRIM$(STR$(i))
  1193.             END IF
  1194.         NEXT i%
  1195.  
  1196.         ' default if none chosen
  1197.         IF FontSpec$ = "" THEN
  1198.             PrintError "No fonts selected - using default."
  1199.             numFonts = LoadFont%("N1")
  1200.             REDIM fonts$(1)
  1201.             fonts$(1) = rfonts$(1)
  1202.         ELSE
  1203.             ' load selected fonts
  1204.             numLoaded = LoadFont%(RIGHT$(FontSpec$, LEN(FontSpec$) - 1))
  1205.  
  1206.             ' notify user of error and let them try again.
  1207.             IF FontErr <> 0 THEN
  1208.                 GOSUB FontError
  1209.                 finished = FALSE
  1210.                 currButton = 1
  1211.             ELSE
  1212.                 REDIM fonts$(numLoaded)
  1213.                 ' create a list of loaded fonts
  1214.                 FOR i = 1 TO numLoaded
  1215.                     SelectFont i
  1216.                     GetFontInfo FI
  1217.                     fonts$(i) = RTRIM$(MID$(FI.FaceName, 1, 8)) + STR$(FI.Points) + " Point"
  1218.                 NEXT i
  1219.                 numFonts = numLoaded
  1220.                 ClearFonts
  1221.             END IF
  1222.         END IF
  1223.     ' reload existing fonts if operation cancelled
  1224.     ELSEIF finished = TRUE AND pushButton = numReg + 2 THEN
  1225.         FontSpec$ = ""
  1226.         FOR i = 1 TO numReg
  1227.             FOR j% = 1 TO numFonts
  1228.                 IF fonts$(j%) = rfonts$(i%) THEN FontSpec$ = FontSpec$ + "/n" + LTRIM$(STR$(i))
  1229.             NEXT j%
  1230.         NEXT i
  1231.         numFonts = LoadFont%(RIGHT$(FontSpec$, LEN(FontSpec$) - 1))
  1232.     END IF
  1233.  
  1234.     WEND
  1235.  
  1236.     UnRegisterFonts
  1237.  
  1238.     WindowClose 1
  1239.  
  1240.     EXIT SUB
  1241.  
  1242. ' handle font loading errors
  1243. FontError:
  1244.     SELECT CASE FontErr
  1245.         CASE cNoFontMem:
  1246.             PrintError "Not enough memory to load selected fonts."
  1247.         CASE cFileNotFound:
  1248.             PrintError fontname$ + " font file not found."
  1249.         CASE cTooManyFonts:
  1250.             numReg = MAXFONTS
  1251.         CASE cBadFontFile:
  1252.             PrintError "Invalid font file format for " + fontname$ + "."
  1253.         CASE cNoFonts:
  1254.             PrintError "No fonts are loaded."
  1255.         CASE cBadFontType:
  1256.             PrintError "Font not a bitmap font."
  1257.         CASE IS > 200:                                  ' basic error
  1258.             PrintError "BASIC error #" + LTRIM$(STR$(FontErr - 200)) + " occurred."
  1259.         CASE ELSE                                       ' unplanned font error
  1260.             PrintError "Font error #" + LTRIM$(STR$(FontErr)) + " occurred."
  1261.     END SELECT
  1262.  
  1263. RETURN
  1264.  
  1265. END SUB
  1266.  
  1267. '
  1268. ' Sub Name: ViewScreenMode
  1269. '
  1270. ' Description: Displays list of valid screen modes and allows the
  1271. '              user to select one for viewing the chart
  1272. '
  1273. ' Arguments: none
  1274. '
  1275. SUB ViewScreenMode
  1276. SHARED screenMode AS INTEGER, numModes AS INTEGER, mode$()
  1277.  
  1278. DIM modeBox AS ListBox
  1279.  
  1280.     ' set up list box containing valid screen modes
  1281.     modeBox.scrollButton = 1
  1282.     modeBox.areaButton = 2
  1283.     modeBox.listLen = numModes
  1284.     modeBox.topRow = 1
  1285.     modeBox.botRow = numModes + 2
  1286.     modeBox.leftCol = 7
  1287.     modeBox.rightCol = 21
  1288.  
  1289.     ' determine current screen mode
  1290.     FOR i = 1 TO numModes
  1291.         IF screenMode = VAL(mode$(i)) THEN modeBox.listPos = i
  1292.     NEXT i
  1293.  
  1294.     ' set up display window
  1295.     winRow = 6
  1296.     winCol = 25
  1297.     WindowOpen 1, winRow, winCol, winRow + numModes + 3, 51, 0, 7, 0, 7, 15, FALSE, FALSE, FALSE, TRUE, 2, "Screen Mode"
  1298.     WindowLine numModes + 3
  1299.  
  1300.     ' create the list box
  1301.     CreateListBox mode$(), modeBox, 0
  1302.  
  1303.     ' open command buttons
  1304.     ButtonOpen 3, 2, "OK ", numModes + 4, 4, 0, 0, 1
  1305.     ButtonOpen 4, 1, "Cancel ", numModes + 4, 16, 0, 0, 1
  1306.  
  1307.     
  1308.         a$ = "Screen Mode Warning ||"
  1309.         a$ = a$ + "Selecting screen modes that support less than |"
  1310.         a$ = a$ + "than 16 colors will reset all chart colors to |"
  1311.         a$ = a$ + "their black and white defaults.               |"
  1312.         a$ = a$ + "|" + " Fonts should be reloaded after screen mode is   |"
  1313.         a$ = a$ + " changed to ensure best font match for screen   |"
  1314.         a$ = a$ + " resolution.                                     "
  1315.         junk = Alert(4, a$, 6, 15, 16, 65, "", "", "")
  1316.     
  1317.  
  1318.     ' start with cursor in area button
  1319.     currButton = 2
  1320.     pushButton = 3
  1321.  
  1322.     ' window control loop
  1323.     finished = FALSE
  1324.     WHILE NOT finished
  1325.         WindowDo currButton, 0                         ' wait for event
  1326.         SELECT CASE Dialog(0)
  1327.             CASE 1                                     ' button pressed
  1328.                 currButton = Dialog(1)
  1329.                 SELECT CASE currButton
  1330.                     CASE 1, 2:
  1331.                         ScrollList mode$(), modeBox, currButton, 1, 0, winRow, winCol
  1332.                         currButton = 2
  1333.                     CASE 3, 4:
  1334.                         pushButton = currButton
  1335.                         finished = TRUE
  1336.                 END SELECT
  1337.             CASE 6                                      ' enter
  1338.                 finished = TRUE
  1339.             CASE 7                                      ' tab
  1340.                 SELECT CASE currButton
  1341.                     CASE 1, 2:
  1342.                         currButton = 3
  1343.                         ButtonSetState pushButton, 1
  1344.                         ButtonSetState currButton, 2
  1345.                         pushButton = 3
  1346.                     CASE 3:
  1347.                         currButton = 4
  1348.                         ButtonSetState pushButton, 1
  1349.                         ButtonSetState currButton, 2
  1350.                         pushButton = 4
  1351.                     CASE 4:
  1352.                         ButtonSetState currButton, 1
  1353.                         currButton = 2
  1354.                         pushButton = 3
  1355.                         ButtonSetState pushButton, 2
  1356.                 END SELECT
  1357.             CASE 8                                      ' back tab
  1358.                 SELECT CASE currButton
  1359.                     CASE 1, 2:
  1360.                         currButton = 4
  1361.                         ButtonSetState pushButton, 1
  1362.                         ButtonSetState currButton, 2
  1363.                         pushButton = 4
  1364.                     CASE 3: currButton = 2
  1365.                     CASE 4:
  1366.                         currButton = 3
  1367.                         ButtonSetState pushButton, 1
  1368.                         ButtonSetState currButton, 2
  1369.                         pushButton = 3
  1370.                     END SELECT
  1371.             CASE 9                                      ' escape
  1372.                 pushButton = 4
  1373.                 finished = TRUE
  1374.             CASE 10, 12                                 ' up, left arrow
  1375.                 SELECT CASE currButton
  1376.                     CASE 1, 2: ScrollList mode$(), modeBox, currButton, 2, 0, winRow, winCol
  1377.                 END SELECT
  1378.             CASE 11, 13                                 ' down, right arrow
  1379.                 SELECT CASE currButton
  1380.                     CASE 1, 2: ScrollList mode$(), modeBox, currButton, 3, 0, winRow, winCol
  1381.                 END SELECT
  1382.             CASE 14                                     ' space bar
  1383.                 IF currButton > 2 THEN finished = TRUE
  1384.         END SELECT
  1385.     WEND
  1386.  
  1387.     ' if not canceled
  1388.     IF pushButton = 3 THEN
  1389.         ' change screen mode
  1390.         IF screenMode <> VAL(mode$(modeBox.listPos)) THEN
  1391.             IF setNum > 0 THEN chartChanged = TRUE
  1392.  
  1393.             screenMode = VAL(mode$(modeBox.listPos))
  1394.  
  1395.             ' reset window coords
  1396.             CEnv.ChartWindow.X1 = 0
  1397.             CEnv.ChartWindow.Y1 = 0
  1398.             CEnv.ChartWindow.X2 = 0
  1399.             CEnv.ChartWindow.Y2 = 0
  1400.  
  1401.             ' change color list based on new screen mode
  1402.             InitColors
  1403.         END IF
  1404.     END IF
  1405.  
  1406.     WindowClose 1
  1407.  
  1408. END SUB
  1409.  
  1410.