home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / lb091.zip / FF12.BAS < prev    next >
BASIC Source File  |  1995-10-09  |  69KB  |  2,131 lines

  1.  
  2.     'Freeform v1.2 for Liberty BASIC
  3.  
  4.     'Copyright 1995, Shoptalk Systems
  5.     'All Rights Reserved
  6.  
  7.     'This program lets you graphically lay out
  8.     'windows and their controls, and then converts
  9.     'this visual layout to Liberty BASIC source code
  10.     'that you can paste into your Liberty BASIC
  11.     'programming session.
  12.  
  13.     'This program REQUIRES either:
  14.     '
  15.     '  Liberty BASIC for Windows v1.2 for Windows for better
  16.     '  Liberty BASIC for OS/2 v0.8 or better
  17.  
  18.     'set up an arrays to hold control specs
  19.  
  20.     dim type$(100)
  21.     dim label$(100)
  22.     dim names$(100)
  23.     dim xOrg(100)
  24.     dim yOrg(100)
  25.     dim width(100)
  26.     dim height(100)
  27.     dim corner$(100)
  28.     dim branchLabel$(100)
  29.     dim segment(100)
  30.     dim handle$(100)
  31.     dim bmpName$(100)
  32.     dim arrayName$(100)
  33.     dim menu$(20)
  34.     dim menuItem$(20, 30)
  35.     dim menuItemLocal$(30)
  36.     dim menuItemCount(20)
  37.     dim winType$(20)
  38.     index = 0
  39.     resizeable$ = " combobox textbox listbox groupbox windowframe textedit button "   'add more as you go
  40.     newControlNumber = 0  'increment by one each time a new control is added
  41.     qu$ = chr$(34)
  42.     controlsThatBranch$ = " button listbox combobox bmpbutton checkbox radiobutton "
  43.     snapOn = 1
  44.     xInterval = 8
  45.     yInterval = 5
  46.     createInspect = 1
  47.  
  48.     formName$ = "untitled.fre"
  49.     windowXOrigin = 70
  50.     windowYOrigin = 10
  51.     windowXExtent = 550
  52.     windowYExtent = 410
  53.     windowLabel$ = "untitled"
  54.     windowType$ = "dialog"
  55.     winHandle$ = "#main"
  56.     menuCount = 0
  57.  
  58.     loadbmp "systemBox", "systembx.bmp"
  59.     loadbmp "minBox", "minbx.bmp"
  60.     loadbmp "maxBox", "maxbx.bmp"
  61.     loadbmp "comboButton", "cmbobttn.bmp"
  62.     loadbmp "radioButton", "radibttn.bmp"
  63.     loadbmp "checkBox", "checkbox.bmp"
  64.     loadbmp "scrollUp", "scrlup.bmp"
  65.     loadbmp "scrollDown", "scrldown.bmp"
  66.     loadbmp "scrollRight", "scrlrght.bmp"
  67.     loadbmp "scrollLeft", "scrlleft.bmp"
  68.  
  69.     winType$(0) = "window"
  70.     winType$(1) = "window_nf"
  71.     winType$(2) = "dialog"
  72.     winType$(3) = "dialog_nf"
  73.     winType$(4) = "dialog_modal"
  74.     winType$(5) = "dialog_nf_modal"
  75.     winType$(6) = "graphics"
  76.     winType$(7) = "graphics_nf_nsb"
  77.  
  78.     gosub [loadIniFile]
  79.  
  80. [setUpWindowAndOpenIt]
  81.  
  82.     nomainwin
  83.  
  84.     menu #form, "&Files", "&New", [newFile], "&Open", [openFile], "&Save", [saveFile]
  85.     menu #form, "&Control", "&Inspect", [inspectControl], "&Delete", [deleteControl], |, "Move to &front", [moveToFront], "Move to &back", [moveToBack]
  86.     menu #form, "&Output", "&Produce Code", [produceCode], "Produce Code + Outline", [produceCodeAndOutline]
  87.     menu #form, "&Window", "&Title", [changeTitle], "T&ype", [changeWindowType], "&Handle", [changeHandle]
  88.     menu #form, "O&ptions", "&Auto Snap to Grid", [gridDialog], "&Settings", [settingsDialog]
  89.     menu #form, "&Menu", "&Add a Menu", [addAMenu], "&Remove a Menu", [removeMenu], "&Edit Menus", [editMenus]
  90.     bmpbutton #form, "textbttn.bmp", [addStaticText], UL, 5, 40
  91.     bmpbutton #form, "efldbttn.bmp", [addField], UL, 35, 40
  92.     bmpbutton #form, "bttnbttn.bmp", [addButton], UL, 5, 70
  93.     bmpbutton #form, "usrdbttn.bmp", [addBmpButton], UL, 35, 70
  94.     bmpbutton #form, "lboxbttn.bmp", [addListBox], UL, 5, 100
  95.     bmpbutton #form, "cboxbttn.bmp", [addComboBox], UL, 35, 100
  96.     bmpbutton #form, "rdiobttn.bmp", [addRadioButton], UL, 5, 130
  97.     bmpbutton #form, "chbxbttn.bmp", [addCheckBox], UL, 35, 130
  98.     bmpbutton #form, "gboxbttn.bmp", [addGroupBox], UL, 5, 160
  99.     bmpbutton #form, "tedtbttn.bmp", [addTextEdit], UL, 35, 160
  100.  
  101.     open "FreeForm v1.2 for Liberty BASIC" for graphics_fs_nsb as #form
  102.     if Platform$ = "OS/2" then print #form, "font systemmonospaced 8 12";
  103.     if Platform$ = "Windows" then print #form, "font fixedsys 8 15";
  104.     print #form, "trapclose [quit]";
  105.  
  106.  
  107. [drawTheWindow]
  108.  
  109.     gosub [renderWindow]
  110.     gosub [addWindowFrame]
  111.  
  112.     goto [setForSelection]
  113.  
  114.  
  115. [addWindowFrame]    'add the window frame as the first object
  116.  
  117.     objectCount = objectCount + 1
  118.     idx = objectCount
  119.     xOrg(idx) = 70
  120.     yOrg(idx) = 10
  121.     width(idx) = 550
  122.     height(idx) = 410
  123.     type$(idx) = "windowframe"
  124.     return
  125.  
  126.  
  127. [addButton]     'add a new button to the form
  128.  
  129.     text$ = ""
  130.     prompt "Please enter text for this button"; text$
  131.     if left$(text$, 1) = qu$ then text$ = mid$(text$, 2)
  132.     if right$(text$, 1) = qu$ then text$ = left$(text$, len(text$) - 1)
  133.     if text$ = "" then [inputLoop]
  134.  
  135.     newControlNumber = newControlNumber + 1
  136.     objectCount = objectCount + 1
  137.     idx = objectCount
  138.     xOrg(idx) = 80
  139.     yOrg(idx) = 40
  140.     label$(idx) = text$
  141.     width(idx) = 8 * (len(label$(idx))) + 10
  142.     height(idx) = 15 + 10
  143.     type$(idx) = "button"
  144.     names$(idx) = "button"+str$(newControlNumber)
  145.     corner$(idx) = "UL"
  146.     branchLabel$(idx) = "["+names$(idx)+"Click]"
  147.     gosub [renderButton]
  148.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  149.     goto [inputLoop]
  150.  
  151.  
  152. [addBmpButton]     'add a new bmpButton to the form
  153.  
  154.     bmp$ = ""
  155.     filedialog "Select a bitmap for this button", "*.bmp", bmp$
  156.     if bmp$ = "" then [inputLoop]
  157.  
  158.     newControlNumber = newControlNumber + 1
  159.     objectCount = objectCount + 1
  160.     idx = objectCount
  161.     xOrg(idx) = 100
  162.     yOrg(idx) = 50
  163.     type$(idx) = "bmpbutton"
  164.     names$(idx) = "bmpbutton"+str$(newControlNumber)
  165.     corner$(idx) = "UL"
  166.     bmpName$(idx) = bmp$
  167.     loadbmp bmp$, bmp$
  168.     branchLabel$(idx) = "["+names$(idx)+"Click]"
  169.     gosub [renderBmpButton]
  170.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  171.     goto [inputLoop]
  172.  
  173.  
  174. [addField]     'add a new field (textBox) to the form
  175.  
  176.     newControlNumber = newControlNumber + 1
  177.     objectCount = objectCount + 1
  178.     idx = objectCount
  179.     xOrg(idx) = 100
  180.     yOrg(idx) = 50
  181.     width(idx) = 100
  182.     height(idx) = 25
  183.     type$(idx) = "textbox"
  184.     names$(idx) = "textbox"+str$(newControlNumber)
  185.     gosub [renderTextBox]
  186.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  187.     goto [inputLoop]
  188.  
  189.  
  190. [addTextEdit]     'add a new field (textBox) to the form
  191.  
  192.     newControlNumber = newControlNumber + 1
  193.     objectCount = objectCount + 1
  194.     idx = objectCount
  195.     xOrg(idx) = 100
  196.     yOrg(idx) = 50
  197.     width(idx) = 100
  198.     height(idx) = 100
  199.     type$(idx) = "textedit"
  200.     names$(idx) = "textedit"+str$(newControlNumber)
  201.     gosub [renderTextEdit]
  202.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  203.     goto [inputLoop]
  204.  
  205.  
  206. [addComboBox]     'add a new combobox to the form
  207.  
  208.     newControlNumber = newControlNumber + 1
  209.     objectCount = objectCount + 1
  210.     idx = objectCount
  211.     xOrg(idx) = 100
  212.     yOrg(idx) = 50
  213.     width(idx) = 100
  214.     height(idx) = 100
  215.     type$(idx) = "combobox"
  216.     names$(idx) = "combobox"+str$(newControlNumber)
  217.     branchLabel$(idx) = "["+names$(idx)+"DoubleClick]"
  218.     arrayName$(idx) = "array$("
  219.     gosub [renderComboBox]
  220.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  221.     goto [inputLoop]
  222.  
  223.  
  224. [addListBox]     'add a new listbox to the form
  225.  
  226.     newControlNumber = newControlNumber + 1
  227.     objectCount = objectCount + 1
  228.     idx = objectCount
  229.     xOrg(idx) = 100
  230.     yOrg(idx) = 50
  231.     width(idx) = 100
  232.     height(idx) = 100
  233.     type$(idx) = "listbox"
  234.     names$(idx) = "listbox"+str$(newControlNumber)
  235.     branchLabel$(idx) = "["+names$(idx)+"DoubleClick]"
  236.     arrayName$(idx) = "array$("
  237.     gosub [renderListBox]
  238.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  239.     goto [inputLoop]
  240.  
  241.  
  242. [addStaticText]     'add statictext to the form
  243.  
  244.     text$ = ""
  245.     prompt "Please enter the text you would like to add:"; text$
  246.     if left$(text$, 1) = qu$ then text$ = mid$(text$, 2)
  247.     if right$(text$, 1) = qu$ then text$ = left$(text$, len(text$) - 1)
  248.     if text$ = "" then [inputLoop]
  249.  
  250.     newControlNumber = newControlNumber + 1
  251.     objectCount = objectCount + 1
  252.     idx = objectCount
  253.     xOrg(idx) = 100
  254.     yOrg(idx) = 50
  255.     label$(idx) = text$
  256.     width(idx) = 8 * len(label$(idx))
  257.     height(idx) = 20
  258.     type$(idx) = "statictext"
  259.     names$(idx) = "statictext"+str$(newControlNumber)
  260.     corner$(idx) = ""
  261.     gosub [renderStaticText]
  262.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  263.     goto [inputLoop]
  264.  
  265.  
  266. [addGroupBox]     'add groupbox to the form
  267.  
  268.     text$ = "No Text"
  269.     prompt "Please enter the text this GroupBox :"; text$
  270.     if left$(text$, 1) = qu$ then text$ = mid$(text$, 2)
  271.     if right$(text$, 1) = qu$ then text$ = left$(text$, len(text$) - 1)
  272.     if text$ = "" then [inputLoop]
  273.     if text$ = "No Text" then text$ = ""
  274.  
  275.     newControlNumber = newControlNumber + 1
  276.     objectCount = objectCount + 1
  277.     idx = objectCount
  278.     xOrg(idx) = 100
  279.     yOrg(idx) = 50
  280.     width(idx) = 100
  281.     height(idx) = 100
  282.     type$(idx) = "groupbox"
  283.     names$(idx) = "groupbox"+str$(newControlNumber)
  284.     corner$(idx) = ""
  285.     label$(idx) = text$
  286.     gosub [renderGroupBox]
  287.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  288.     goto [inputLoop]
  289.  
  290.  
  291. [addRadioButton]     'add radiobutton to the form
  292.  
  293.     text$ = ""
  294.     prompt "Please enter a label for the radiobutton:"; text$
  295.     if left$(text$, 1) = qu$ then text$ = mid$(text$, 2)
  296.     if right$(text$, 1) = qu$ then text$ = left$(text$, len(text$) - 1)
  297.     if text$ = "" then [inputLoop]
  298.  
  299.     newControlNumber = newControlNumber + 1
  300.     objectCount = objectCount + 1
  301.     idx = objectCount
  302.     xOrg(idx) = 100
  303.     yOrg(idx) = 50
  304.     type$(idx) = "radiobutton"
  305.     names$(idx) = "radiobutton"+str$(newControlNumber)
  306.     corner$(idx) = "UL"
  307.     label$(idx) = text$
  308.     branchLabel$(idx) = "["+names$(idx)+"Set] ["+names$(idx)+"Reset]"
  309.     gosub [renderRadioButton]
  310.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  311.     goto [inputLoop]
  312.  
  313.  
  314. [addCheckBox]     'add checkbox to the form
  315.  
  316.     text$ = ""
  317.     prompt "Please enter a label for the checkbox"; text$
  318.     if left$(text$, 1) = qu$ then text$ = mid$(text$, 2)
  319.     if right$(text$, 1) = qu$ then text$ = left$(text$, len(text$) - 1)
  320.     if text$ = "" then [inputLoop]
  321.  
  322.     newControlNumber = newControlNumber + 1
  323.     objectCount = objectCount + 1
  324.     idx = objectCount
  325.     xOrg(idx) = 100
  326.     yOrg(idx) = 50
  327.     type$(idx) = "checkbox"
  328.     names$(idx) = "checkbox"+str$(newControlNumber)
  329.     corner$(idx) = "UL"
  330.     label$(idx) = text$
  331.     branchLabel$(idx) = "["+names$(idx)+"Set] ["+names$(idx)+"Reset]"
  332.     gosub [renderCheckBox]
  333.     if createInspect then gosub [deselectOnly] : index = idx : gosub [selectDeselect] : goto [inspectControl]
  334.     goto [inputLoop]
  335.  
  336.  
  337. [inputLoop]
  338.  
  339.     input r$
  340.     goto [inputLoop]
  341.  
  342.  
  343. [renderWindow]
  344.  
  345.     'render the window depending on the value of windowType$
  346.  
  347.     xOrg = windowXOrigin
  348.     yOrg = windowYOrigin
  349.     xExt = windowXExtent
  350.     yExt = windowYExtent
  351.  
  352.     print #form, "cls";
  353.     print #form, "backcolor white ; color black ; down ; size 1";
  354.     print #form, "place "; xOrg + 4; " "; yOrg + 4;
  355.     if Platform$ = "OS/2" then print #form, "backcolor lightgray";
  356.     print #form, "boxfilled "; xOrg + xExt - 4; " "; yOrg + yExt - 4;
  357.     if instr(windowType$, "_nf") > 0 then [noResizingFrame]
  358.  
  359.     'draw resizing frame
  360.     print #form, "color lightgray ; size 3";
  361.     if Platform$ = "OS/2" then print #form, "color yellow";
  362.     if windowType$ = "dialog" then print #form, "color darkgray";
  363.     if windowType$ = "dialog" and Platform$ = "OS/2" then print #form, "color darkcyan";
  364.     print #form, "place "; xOrg + 2; " "; yOrg + 2;
  365.     print #form, "box "; xOrg + xExt - 2; " "; yOrg + yExt - 2;
  366.     print #form, "color black ; backcolor white ; size 1";
  367.     print #form, "place "; xOrg; " "; yOrg;
  368.     print #form, "box "; xOrg + xExt ; " "; yOrg + yExt;
  369.  
  370.   [noResizingFrame]
  371.     'draw titlebar
  372.     print #form, "color black ; backcolor darkblue";
  373.     if left$(windowType$, 6) = "dialog" then print #form, "backcolor darkgray";
  374.     if Platform$ = "OS/2" then print #form, "color darkgray ; backcolor darkcyan";
  375.     print #form, "place "; 4 + xOrg; " "; 4 + yOrg;
  376.     print #form, "boxfilled "; xOrg + xExt - 4; " "; 4 + yOrg + 20;
  377.     print #form, "place "; int(xExt/2) + xOrg - len(windowLabel$) * 4; " "; 18 + yOrg;
  378.     if Platform$ = "OS/2" then print #form, "place "; 48 + xOrg; " "; 18 + yOrg;
  379.     print #form, "color white";
  380.     print #form, "\"; windowLabel$;
  381.  
  382.     'draw buttons
  383.     print #form, "drawbmp systemBox "; xOrg + 5; " "; 4 + yOrg;
  384.     print #form, "backcolor white ; color black ; down ; size 1";
  385.     if windowType$ = "dialog" then print #form, "color white" ;
  386.     if windowType$ = "dialog" and Platform$ = "OS/2" then print #form, "color darkgray" ;
  387.     print #form, "place "; xOrg + 4; " "; yOrg + 4;
  388.     print #form, "box "; xOrg + xExt - 4; " "; yOrg + yExt - 4;
  389.     if left$(windowType$, 6) = "dialog" then [drawMenus]
  390.     if instr(windowType$, "_nf") then print #form, "drawbmp minBox "; xOrg + xExt - 24 - 1; " "; 4 + yOrg; : goto [drawMenus]
  391.     print #form, "drawbmp minBox "; xOrg + xExt - 43 - 2; " "; 4 + yOrg;
  392.     print #form, "drawbmp maxBox "; xOrg + xExt - 24 - 1; " "; 4 + yOrg;
  393.  
  394.   [drawMenus]
  395.     if menuCount = 0 then [dontDrawMenus]
  396.     print #form, "color black ; backcolor white" ;
  397.     if Platform$ = "Windows" then print #form, "place "; 4 + xOrg; " "; 23 + yOrg;
  398.     if Platform$ = "OS/2" then print #form, "color darkgray ; place "; 4 + xOrg; " "; 25 + yOrg;
  399.     print #form, "box "; xOrg + xExt - 4; " "; 24 + yOrg + 20 ;
  400.     string$ = ""
  401.     underline$ = ""
  402.     for x = 0 to menuCount - 1
  403.         item$ = menu$(x)
  404.         hkIndex = instr(menu$(x), "&")
  405.         if hkIndex = 0 then [noHotKey]
  406.         item$ = left$(item$, hkIndex - 1) + mid$(item$, hkIndex + 1)
  407.         underline$ = underline$ + chr$(len(string$)+hkIndex)
  408.       [noHotKey]
  409.         string$ = string$ + item$ + "  "
  410.     next x
  411.     print #form, "color black ; backcolor white" ;
  412.     if Platform$ = "OS/2" then print #form, "backcolor palegray" ;
  413.     print #form, "place "; xOrg + 10; " "; 38 + yOrg ;
  414.     print #form, "\"; string$;
  415.     if len(underline$) = 0 then [dontDrawMenus]
  416.     for x = 1 to len(underline$)
  417.         print #form, "place "; xOrg + 10 + (asc(mid$(underline$, x, 1)) - 1) * 8; " "; yOrg + 40 ;
  418.         print #form, "north ; turn 90 ; go 8";
  419.     next x
  420.  
  421.   [dontDrawMenus]
  422.     print #form, "flush" ;
  423.  
  424.     return
  425.  
  426.  
  427.  
  428. [changeTitle]
  429.  
  430.     'change the window's title
  431.     newWindowLabel$ = windowLabel$
  432.     prompt "Specify the window's title"; newWindowLabel$
  433.     if newWindowLabel$ <> "" then windowLabel$ = newWindowLabel$
  434.     gosub [redrawAll]
  435.     goto [inputLoop]
  436.  
  437.  
  438. [changeWindowType]
  439.  
  440.     WindowWidth = 380
  441.     WindowHeight = 200
  442.  
  443.     'change the window's type
  444.     statictext #type.statictext1, "Select the type of window desired:", 14, 11, 272, 20
  445.     combobox #type.types, winType$(, [selectWinType], 22, 36, 256, 115
  446.     button #type, "Accept", [acceptWinType], UL, 302, 36
  447.     button #type, "Cancel", [cancelWinType], UL, 302, 71
  448.     open "Select Window Type" for dialog_modal as #type
  449.     print #type.types, "select "; windowType$ 
  450.     print #type, "trapclose [cancelWinType]"
  451.     defaultType$ = windowType$
  452.  
  453.     goto [inputLoop]
  454.  
  455.  
  456. [selectWinType]   'Perform action for the combobox named 'types'
  457.  
  458.     'select the type of window desired
  459.     print #type.types, "selection?";
  460.     input #type.types, defaultType$
  461.  
  462.     goto [inputLoop]
  463.  
  464.  
  465. [acceptWinType]   'Perform action for the button named 'acceptWinType'
  466.  
  467.     'accept the selected window type
  468.     windowType$ = defaultType$
  469.     close #type
  470.     gosub [redrawAll]
  471.     goto [inputLoop]
  472.  
  473.  
  474. [cancelWinType]   'Perform action for the button named 'cancelWinType'
  475.  
  476.     'close the window, don't accept type change
  477.     close #type
  478.     goto [inputLoop]
  479.  
  480.  
  481. [changeHandle]
  482.  
  483.     'change the window's handle
  484.     prompt "Specify the window's handle (starts with a #)"; result$
  485.     if result$ = "" then [inputLoop]
  486.     winHandle$ = result$
  487.     if left$(winHandle$, 1) <> "#" then winHandle$ = "#" + winHandle$ : notice "Window handle defaults to: " + winHandle$
  488.     goto [inputLoop]
  489.  
  490.  
  491. [renderButton]
  492.  
  493.     'render the statictext at idx.
  494.     'assume an font 8 bits wide
  495.     type$(idx) = "button"
  496.     xOrgIdx = xOrg(idx)
  497.     yOrgIdx = yOrg(idx)
  498.     print #form, "place "; xOrgIdx; " "; yOrgIdx ;
  499.     print #form, "place "; xOrgIdx; " "; yOrgIdx ;
  500.     print #form, "color black ; backcolor lightgray ; size 1" ;
  501.     print #form, "down ; boxfilled "; xOrgIdx+width(idx); " "; yOrgIdx+height(idx) ;
  502.     print #form, "size 2 ; color darkgray ; place "; xOrgIdx+2; " "; yOrgIdx+2 ;
  503.     print #form, "box "; xOrgIdx+width(idx)-1; " "; yOrgIdx+height(idx)-1 ;
  504.     print #form, "color white" ;
  505.     print #form, "place  "; xOrgIdx+2; " "; yOrgIdx+height(idx)-3 ;
  506.     print #form, "goto "; xOrgIdx+2; " "; yOrgIdx+2 ;
  507.     print #form, "goto "; xOrgIdx+width(idx)-3; " "; yOrgIdx+2 ;
  508.     print #form, "color black ; backcolor lightgray ; size 1" ;
  509.     print #form, "place "; xOrgIdx+int((width(idx)-len(label$(idx))*8)/2); " "; yOrgIdx+int((height(idx)-15)/2)+12 ;
  510.     print #form, "\"; label$(idx);
  511.     gosub [createOrderMarker]
  512.     print #form, orderMarker1$ ;
  513.     print #form, orderMarker2$ ;
  514.     print #form, "up ; flush" ;
  515.     print #form, "segment" : input #form, id
  516.     segment(idx) = id
  517.  
  518.     return
  519.  
  520.  
  521. [renderStaticText]
  522.  
  523.     'render the statictext at idx.
  524.     'assume an font 8 bits wide, 15 high
  525.     type$(idx) = "statictext"
  526.     print #form, "place "; xOrg(idx); " "; yOrg(idx)+15-3 ; " ; place "; xOrg(idx); " "; yOrg(idx)+15-3 ;
  527.     print #form, "down ; color black ; backcolor white" ;
  528.     if Platform$ = "OS/2" then print #form, "backcolor palegray" ;
  529.     print #form, "\"; label$(idx);
  530.     gosub [createOrderMarker]
  531.     print #form, orderMarker1$ ;
  532.     print #form, orderMarker2$ ;
  533.     print #form, "up ; flush" ;
  534.     print #form, "segment" : input #form, id
  535.     segment(idx) = id
  536.  
  537.     return
  538.  
  539.  
  540. [renderRadioButton]
  541.  
  542.     'render the radiobutton at idx.
  543.     'assume an font 8 bits wide, 15 high
  544.     type$(idx) = "radiobutton"
  545.     width(idx) = 8 * len(label$(idx)) + 16
  546.     height(idx) = 20
  547.     print #form, "down" ;
  548.     print #form, "place "; xOrg(idx); " "; yOrg(idx);
  549.     print #form, "drawbmp radioButton "; xOrg(idx); " "; yOrg(idx);
  550.     print #form, "color black ; backcolor white" ;
  551.     if Platform$ = "OS/2" then print #form, "backcolor palegray" ;
  552.     print #form, "place "; xOrg(idx)+16; " "; yOrg(idx)+15-3 ;
  553.     print #form, "\"; label$(idx);
  554.     gosub [createOrderMarker]
  555.     print #form, orderMarker1$ ;
  556.     print #form, orderMarker2$ ;
  557.     print #form, "up ; flush" ;
  558.     print #form, "segment" : input #form, id
  559.     segment(idx) = id
  560.  
  561.     return
  562.  
  563.  
  564. [renderCheckBox]
  565.  
  566.     'render the checkbox at idx.
  567.     'assume an font 8 bits wide, 15 high
  568.     type$(idx) = "checkbox"
  569.     width(idx) = 8 * len(label$(idx)) + 16
  570.     height(idx) = 20
  571.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  572.     print #form, "down" ;
  573.     print #form, "drawbmp checkBox "; xOrg(idx); " "; yOrg(idx);
  574.     print #form, "color black ; backcolor white" ;
  575.     if Platform$ = "OS/2" then print #form, "backcolor palegray" ;
  576.     print #form, "place "; xOrg(idx)+16; " "; yOrg(idx)+15-3 ;
  577.     print #form, "\"; label$(idx);
  578.     gosub [createOrderMarker]
  579.     print #form, orderMarker1$ ;
  580.     print #form, orderMarker2$ ;
  581.     print #form, "up ; flush" ;
  582.     print #form, "segment" : input #form, id
  583.     segment(idx) = id
  584.  
  585.     return
  586.  
  587.  
  588. [renderBmpButton]
  589.  
  590.     'render the bmpbutton at idx.
  591.     'assume an font 8 bits wide
  592.     type$(idx) = "bmpbutton"
  593.     width(idx) = 20
  594.     height(idx) = 20
  595.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  596.     print #form, "drawbmp "; bmpName$(idx); " "; xOrg(idx); " "; yOrg(idx);
  597.     gosub [createOrderMarker]
  598.     print #form, "down ; "; orderMarker1$ ;
  599.     print #form, orderMarker2$ ;
  600.     print #form, "up ; flush" ;
  601.     print #form, "segment" : input #form, id
  602.     segment(idx) = id
  603.  
  604.     return
  605.  
  606.  
  607. [renderComboBox]
  608.  
  609.     'render the comboBox at idx.
  610.     type$(idx) = "combobox"
  611.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  612.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  613.     print #form, "color black ; backcolor white ; size 1" ;
  614.     print #form, "down ; boxfilled "; xOrg(idx)+width(idx)-24; " "; yOrg(idx)+22 ;
  615.     print #form, "drawbmp comboButton "; xOrg(idx)+width(idx)-16 ; " "; yOrg(idx) ;
  616.     gosub [createOrderMarker]
  617.     print #form, orderMarker1$ ;
  618.     print #form, orderMarker2$ ;
  619.     print #form, "up ; flush" ;
  620.     print #form, "segment" : input #form, id
  621.     segment(idx) = id
  622.  
  623.     return
  624.  
  625. [renderTextBox]
  626.  
  627.     'render the textbox at idx.
  628.     type$(idx) = "textbox"
  629.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ; " ; place "; xOrg(idx); " "; yOrg(idx) ;
  630.     print #form, "color black ; backcolor white ; size 1" ;
  631.     print #form, "down ; boxfilled "; xOrg(idx)+width(idx); " "; yOrg(idx)+height(idx) ;
  632.     gosub [createOrderMarker]
  633.     print #form, orderMarker1$ ;
  634.     print #form, orderMarker2$ ;
  635.     print #form, "up ; flush" ;
  636.     print #form, "segment" : input #form, id
  637.     segment(idx) = id
  638.  
  639.     return
  640.  
  641.  
  642. [renderTextEdit]
  643.  
  644.     'render the textedit at idx.
  645.     type$(idx) = "textedit"
  646.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  647.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  648.     print #form, "color black ; backcolor white ; size 1" ;
  649.     print #form, "down ; boxfilled "; xOrg(idx)+width(idx); " "; yOrg(idx)+height(idx) ;
  650.     print #form, "color black ; backcolor lightgray" ;
  651.     print #form, "place "; xOrg(idx)+width(idx)-17; " "; yOrg(idx);
  652.     print #form, "boxfilled "; xOrg(idx)+width(idx); " "; yOrg(idx)+height(idx)-17 ;
  653.     print #form, "drawbmp scrollUp "; xOrg(idx)+width(idx)-17; " "; yOrg(idx);
  654.     print #form, "drawbmp scrollDown "; xOrg(idx)+width(idx)-17; " "; yOrg(idx)+height(idx)-33;
  655.     print #form, "place "; xOrg(idx); " "; yOrg(idx)+height(idx)-17;
  656.     print #form, "boxfilled "; xOrg(idx)+width(idx); " "; yOrg(idx)+height(idx) ;
  657.     print #form, "drawbmp scrollLeft "; xOrg(idx); " "; yOrg(idx)+height(idx)-17;
  658.     print #form, "drawbmp scrollRight "; xOrg(idx)+width(idx)-33; " "; yOrg(idx)+height(idx)-17;
  659.     gosub [createOrderMarker]
  660.     print #form, orderMarker1$ ;
  661.     print #form, orderMarker2$ ;
  662.     print #form, "up ; flush" ;
  663.     print #form, "segment" : input #form, id
  664.     segment(idx) = id
  665.  
  666.     return
  667.  
  668.  
  669. [renderListBox]
  670.  
  671.     'render the listbox at idx.
  672.     type$(idx) = "listbox"
  673.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  674.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  675.     print #form, "color black ; backcolor white ; size 1" ;
  676.     print #form, "down ; boxfilled "; xOrg(idx)+width(idx); " "; yOrg(idx)+height(idx) ;
  677.     print #form, "color black ; backcolor lightgray" ;
  678.     print #form, "place "; xOrg(idx)+width(idx)-17; " "; yOrg(idx);
  679.     print #form, "boxfilled "; xOrg(idx)+width(idx); " "; yOrg(idx)+height(idx) ;
  680.     print #form, "drawbmp scrollUp "; xOrg(idx)+width(idx)-17; " "; yOrg(idx);
  681.     print #form, "drawbmp scrollDown "; xOrg(idx)+width(idx)-17; " "; yOrg(idx)+height(idx)-17;
  682.     gosub [createOrderMarker]
  683.     print #form, orderMarker1$ ;
  684.     print #form, orderMarker2$ ;
  685.     print #form, "up ; flush" ;
  686.     print #form, "segment" : input #form, id
  687.     segment(idx) = id
  688.  
  689.     return
  690.  
  691.  
  692. [renderGroupBox]
  693.  
  694.     'render the groupbox at idx.  assume a font 8x15.
  695.     type$(idx) = "groupbox"
  696.     print #form, "place "; xOrg(idx); " "; yOrg(idx) ;
  697.     print #form, "place "; xOrg(idx)+4 ; " "; yOrg(idx)+8 ;
  698.     print #form, "color black ; backcolor white ; size 1" ;
  699.     if Platform$ = "OS/2" then print #form, "backcolor palegray" ;
  700.     print #form, "down ; boxfilled "; xOrg(idx)+width(idx)-4; " "; yOrg(idx)+height(idx)-7 ;
  701.     print #form, "place "; xOrg(idx)+8; " "; yOrg(idx)+15 ;
  702.     print #form, "\"; label$(idx);
  703.     gosub [createOrderMarker]
  704.     print #form, orderMarker1$ ;
  705.     print #form, orderMarker2$ ;
  706.     print #form, "up ; flush" ;
  707.     print #form, "segment" : input #form, id
  708.     segment(idx) = id
  709.  
  710.     return
  711.  
  712.  
  713. [createOrderMarker]
  714.  
  715.     orderMarker1$ = ""
  716.     orderMarker2$ = ""
  717.     if displayOrdering = 0 then return
  718.     orderMarker1$ = "color white ; backcolor black ; place " + str$(xOrg(idx)-4) + " " + str$(yOrg(idx)+7)
  719.     orderMarker2$ = "\" + str$(idx - 1)
  720.     return
  721.  
  722.  
  723. [inspectControl]
  724.  
  725.     'pop up a dialog for displaying/modifying control
  726.     'properties
  727.  
  728.     if index < 2 then [inputLoop]
  729.  
  730.     if inspectIsOpen = 1 then close #inspect
  731.  
  732.     WindowHeight = 200
  733.     WindowWidth = 472
  734.  
  735.     textbox #inspect.labelField, 140, 15, 220, 25
  736.     textbox #inspect.nameField, 140, 46, 220, 25
  737.     textbox #inspect.branchLabelField, 140, 77, 220, 25
  738.     textbox #inspect.arrayNameField, 140, 108, 220, 25
  739.     statictext #inspect.type, "Label:", 17, 21, 200, 20
  740.     statictext #inspect.type, "Name:", 17, 52, 200, 20
  741.     statictext #inspect.statictext2, "Branch Label(s):", 17, 83, 200, 20
  742.     statictext #inspect.statictext4, "Array:", 17, 113, 114, 20
  743.     button #inspect, "Accept", [acceptInspect], UL, 372, 15
  744.     button #inspect, "Cancel", [cancelInspect], UL, 372, 46
  745.     statictext #inspect.statictext15, "n/a = not", 374, 79, 70, 20
  746.     statictext #inspect.statictext16, "applicable", 374, 95, 70, 20
  747.     open "Modify Control" for dialog_modal as #inspect
  748.     print #inspect, "trapclose [cancelInspect]";
  749.     inspectIsOpen = 1
  750.  
  751.     print #inspect.labelField, label$(index)
  752.     print #inspect.type, type$(index) + " name:"
  753.     print #inspect.nameField, names$(index)
  754.     print #inspect.branchLabelField, branchLabel$(index)
  755.     if instr(" button statictext checkbox radiobutton groupbox ", type$(index)) = 0 then print #inspect.labelField, "n/a"
  756.     if instr(controlsThatBranch$, type$(index)) = 0 then print #inspect.branchLabelField, "n/a"
  757.     if instr(" listbox combobox ", type$(index)) > 0 then print #inspect.arrayNameField, arrayName$(index) else print #inspect.arrayNameField, "n/a"
  758.  
  759.     goto [inputLoop]
  760.  
  761.  
  762. [acceptInspect]
  763.  
  764.     'set the properties as modified by the user
  765.     isModified = 1  'the form has been modified
  766.     hasLabel =  instr(" button statictext checkbox radiobutton groupbox ", type$(index))
  767.     if hasLabel > 0 then print #inspect.labelField, "!contents?" : input #inspect.labelField, label$ : label$(index) = label$
  768.     print #inspect.nameField, "!contents?" : input #inspect.nameField, names$ : names$(index) = names$
  769.     branches = instr(controlsThatBranch$, type$(index))
  770.     if branches > 0 then print #inspect.branchLabelField, "!contents?" : input #inspect.branchLabelField, bLabel$ : branchLabel$(index) = bLabel$
  771.     usesArray = instr(" listbox combobox ", type$(index))
  772.     if usesArray > 0 then print #inspect.arrayNameField, "!contents?" : input #inspect.arrayNameField, aName$ : arrayName$(index) = aName$
  773.     close #inspect
  774.     inspectIsOpen = 0
  775.  
  776.     if hasLabel > 0 then gosub [redrawAll]
  777.  
  778.     goto [inputLoop]
  779.  
  780.  
  781. [cancelInspect]
  782.  
  783.     'close the inspector window
  784.     close #inspect
  785.     inspectIsOpen = 0
  786.  
  787.     goto [inputLoop]
  788.  
  789.  
  790. [setForSelection]
  791.  
  792.     'set up event handling for the default behavior (selection)
  793.     print #form, "when leftButtonDown [selectControl]";
  794.     print #form, "when leftButtonDouble [inspectControl]";
  795.     print #form, "when leftButtonMove" ;
  796.     print #form, "when leftButtonUp" ;
  797.  
  798.     goto [inputLoop]
  799.  
  800.  
  801. [selectControl]
  802.  
  803.     'set up event handling
  804.     print #form, "when leftButtonUp [setForSelection]" ;
  805.     print #form, "when leftButtonDown" ;
  806.  
  807.     'highlight the control at the mouse click position
  808.     x = MouseX : y = MouseY
  809.  
  810.     if index = 0 then [dontDeselect]
  811.  
  812.     'check to see if the resize handle has been clicked on, if applicable
  813.     if instr(resizeable$, type$(index)) = 0 then [deselect]
  814.     if x < xOrg(index)+width(index)-3 or x > xOrg(index)+width(index)+3 then [deselect]
  815.     if y < yOrg(index)+height(index)-3 or y > yOrg(index)+height(index)+3 then [deselect]
  816.     goto [resizeControl]
  817.  
  818. [deselect]
  819.     print #form, "delsegment "; selectId -1 ;
  820.     gosub [selectDeselect]
  821.     index = 0
  822.     print #form, "delsegment "; selectId - 1 ;
  823.  
  824. [dontDeselect]
  825.     gosub [determineControl]
  826.     if newIndex = 0 then [setUpMovementEvent]
  827.  
  828.     index = newIndex
  829.     gosub [selectDeselect]
  830.     lastMouseX = MouseX
  831.     lastMouseY = MouseY
  832.  
  833. [setUpMovementEvent]
  834.  
  835.     if type$(newIndex) = "windowframe" then [inputLoop]
  836.     print #form, "when leftButtonMove [beginObjectMove]" ;
  837.     goto [inputLoop]
  838.  
  839.  
  840. [determineControl]
  841.  
  842.     'based on x/y, determine which control is selected
  843.     'set newIndex to point to this control, if found
  844.     'otherwise set newIndex to 0
  845.  
  846.     if objectCount = 0 then return
  847.  
  848.     newIndex = 0
  849.     for i = objectCount to 1 step -1
  850.         if newIndex > 0 then [skipControl]
  851.         if type$(i) = "" then [skipControl]
  852.         if x < xOrg(i) or x > xOrg(i)+width(i) then [skipControl]
  853.         if y < yOrg(i) or y > yOrg(i)+height(i) then [skipControl]
  854.         newIndex = i
  855.         i = 1
  856. [skipControl]
  857.     next i
  858.  
  859.     return
  860.  
  861.  
  862. [selectDeselect]
  863.  
  864.     'select or deselect the object at index by drawing handles
  865.     xOrgIdx = xOrg(index)
  866.     yOrgIdx = yOrg(index)
  867.     xow = xOrgIdx+width(index)
  868.     yoh = yOrgIdx+height(index)
  869.     print #form, "rule xor ; down";
  870.     if type$(index) = "windowframe" then [drawSizingHandle]
  871.     print #form, "color darkgray ; backcolor white" ;
  872.     print #form, "place "; xOrgIdx-3; " "; yOrgIdx-3 ;
  873.     print #form, "boxfilled "; xOrgIdx+3; " "; yOrgIdx+3 ;
  874.     print #form, "place "; xow-3; " "; yOrgIdx-3 ;
  875.     print #form, "boxfilled "; xow+3; " "; yOrgIdx+3 ;
  876.     print #form, "place "; xOrgIdx-3; " "; yoh-3 ;
  877.     print #form, "boxfilled "; xOrgIdx+3; " "; yoh+3 ;
  878.  
  879.   [drawSizingHandle]
  880.     if instr(resizeable$, type$(index)) > 0 then print #form, "backcolor black" ;
  881.     print #form, "place "; xow-3; " "; yoh-3 ;
  882.     print #form, "boxfilled "; xow+3; " "; yoh+3 ;
  883.     print #form, "rule over ; flush" ;
  884.     print #form, "segment" ;
  885.     input #form, selectId
  886.  
  887.  
  888.     return
  889.  
  890.  
  891. [deselectOnly]  'if there is a selected control, deselect it
  892.  
  893.     if index = 0 then return  'nothing is selected, do nothing
  894.     print #form, "delsegment "; selectId -1 ;
  895.     gosub [selectDeselect]
  896.     index = 0
  897.     print #form, "delsegment "; selectId - 1 ;
  898.  
  899.     return
  900.  
  901.  
  902.  
  903. [beginObjectMove]
  904.  
  905.     'if the mouse has only slightly moved, ignore the event
  906.     if abs(MouseX - x) < 3 and abs(MouseY - y) < 3 then [inputLoop]
  907.  
  908.     'set up to begin moving the selected object
  909.     print #form, "delsegment "; selectId - 1 ;
  910.     print #form, "when leftButtonMove [additionalObjectMoves]" ;
  911.     print #form, "when leftButtonUp [acceptMovement]" ;
  912.  
  913.  
  914. [additionalObjectMoves]
  915.  
  916.     'adjust the position of the selected object, then draw an object frame the size of the
  917.     'selected object at that new position using xor rule.  set event handling to manage
  918.     'additional movements or termination of this object's movement.
  919.  
  920.     gosub [snapMouse]
  921.     if MouseX = lastMouseX and MouseY = lastMouseY then [inputLoop]
  922.  
  923.     gosub [eraseObjectFrame]
  924.     xOrg(index) = xOrg(index) + (MouseX - lastMouseX)
  925.     yOrg(index) = yOrg(index) + (MouseY - lastMouseY)
  926.     gosub [snapXY]
  927.     lastMouseX = MouseX
  928.     lastMouseY = MouseY
  929.  
  930.     print #form, "color black ; backcolor white ; size 1" ;
  931.     print #form, "place "; xOrg(index); " "; yOrg(index) ;
  932.     print #form, "down ; rule xor ; box "; xOrg(index)+width(index); " "; yOrg(index)+height(index) ;
  933.     print #form, "rule over ; up ; flush" ;
  934.     print #form, "segment" : input #form, id
  935.     print #form, "delsegment "; id - 1 ;
  936.  
  937.     goto [inputLoop]
  938.  
  939.  
  940. [eraseObjectFrame]
  941.  
  942.     'erase the object frame (for movement)
  943.     print #form, "color black ; backcolor white ; size 1" ;
  944.     print #form, "place "; xOrg(index); " "; yOrg(index) ;
  945.     print #form, "down ; rule xor ; box "; xOrg(index)+width(index); " "; yOrg(index)+height(index) ;
  946.     print #form, "rule over ; up ; flush" ;
  947.     print #form, "segment" : input #form, id
  948.     print #form, "delsegment "; id - 1 ;
  949.  
  950.     return
  951.  
  952.  
  953. [acceptResizing]
  954.  
  955.     if width(index) < 25 then width(index) = 25
  956.     if height(index) < 25 then height(index) = 25
  957.  
  958.     if type$(index) <> "windowframe" then [acceptMovement]
  959.     if width(index) < 100 then width(index) = 100
  960.     if height(index) < 50 then height(index) = 50
  961.     windowXExtent = width(index)
  962.     windowYExtent = height(index)
  963.  
  964.  
  965. [acceptMovement]
  966.  
  967.     'end the movement phase, and redraw all objects
  968.     print #form, "delsegment "; segment(index) - 1 ;
  969.     gosub [redrawAll]
  970.     'index = 0
  971.     gosub [selectDeselect]
  972.     firstObjectMove = false
  973.     goto [setForSelection]
  974.  
  975.  
  976. [resizeControl]
  977.  
  978.     'set up to begin resizing the selected object
  979.     firstObjectMove = true
  980.     print #form, "delsegment "; selectId - 1 ;
  981.     print #form, "when leftButtonMove [additionalResizes]" ;
  982.     print #form, "when leftButtonUp [acceptResizing]" ;
  983.     gosub [snapMouse]
  984.     lastMouseX = MouseX
  985.     lastMouseY = MouseY
  986.  
  987. [additionalResizes]
  988.  
  989.     'adjust the position of the selected object, then draw an object frame the size of the
  990.     'selected object at that new position using xor rule.  set event handling to manage
  991.     'additional movements or termination of this object's movement.
  992.  
  993.     if firstObjectMove = false then gosub [eraseObjectFrame]
  994.  
  995.     gosub [snapMouse]
  996.     width(index) = width(index) + (MouseX - lastMouseX)
  997.     height(index) = height(index) + (MouseY - lastMouseY)
  998.     gosub [snapWH]
  999.     lastMouseX = MouseX
  1000.     lastMouseY = MouseY
  1001.  
  1002.     print #form, "color black ; backcolor white ; size 1" ;
  1003.     print #form, "place "; xOrg(index); " "; yOrg(index) ;
  1004.     print #form, "down ; rule xor ; box "; xOrg(index)+width(index); " "; yOrg(index)+height(index) ;
  1005.     print #form, "rule over ; up ; flush" ;
  1006.     print #form, "segment" : input #form, id
  1007.     print #form, "delsegment "; id - 1 ;
  1008.  
  1009.     goto [inputLoop]
  1010.  
  1011.  
  1012. [snapMouse]  'if snapOn is selected, then snap the mouse to grid
  1013.  
  1014.     if snapOn = 0 then return
  1015.  
  1016.     MouseX = int((MouseX + int(xInterval / 2)) / xInterval) * xInterval
  1017.     MouseY = int((MouseY + int(yInterval / 2)) / yInterval) * yInterval
  1018.     return
  1019.  
  1020.  
  1021. [snapWH]  'if snapOn is selected, then snap the width & height to grid
  1022.  
  1023.     if snapOn = 0 then return
  1024.  
  1025.     width(index) = int((width(index) + int(xInterval / 2)) / xInterval) * xInterval
  1026.     height(index) = int((height(index) + int(yInterval / 2)) / yInterval) * yInterval
  1027.     return
  1028.  
  1029.  
  1030. [snapXY]  'if snapOn is selected, then snap the x,y position to grid
  1031.  
  1032.     if snapOn = 0 then return
  1033.  
  1034.     xOrg(index) = int((xOrg(index) + int(xInterval / 2)) / xInterval) * xInterval
  1035.     yOrg(index) = int((yOrg(index) + int(yInterval / 2)) / yInterval) * yInterval
  1036.     return
  1037.  
  1038.  
  1039. [redrawAll]
  1040.  
  1041.     'redraw all controls
  1042.     isModified = 1  'the form has been modified
  1043.     print #form, "cls";
  1044.     index = 0
  1045.     gosub [renderWindow]
  1046.     if objectCount = 0 then return
  1047.     for idx = 1 to objectCount
  1048.         typeIdx$ = type$(idx)
  1049.         if typeIdx$ = "textbox" then gosub [renderTextBox] : goto [redrawNext]
  1050.         if typeIdx$ = "statictext" then gosub [renderStaticText] : goto [redrawNext]
  1051.         if typeIdx$ = "button" then gosub [renderButton] : goto [redrawNext]
  1052.         if typeIdx$ = "combobox" then gosub [renderComboBox] : goto [redrawNext]
  1053.         if typeIdx$ = "listbox" then gosub [renderListBox] : goto [redrawNext]
  1054.         if typeIdx$ = "bmpbutton" then gosub [renderBmpButton] : goto [redrawNext]
  1055.         if typeIdx$ = "radiobutton" then gosub [renderRadioButton] : goto [redrawNext]
  1056.         if typeIdx$ = "checkbox" then gosub [renderCheckBox] : goto [redrawNext]
  1057.         if typeIdx$ = "groupbox" then gosub [renderGroupBox] : goto [redrawNext]
  1058.         if typeIdx$ = "textedit" then gosub [renderTextEdit]
  1059.       [redrawNext]
  1060.     next idx
  1061.  
  1062.     return
  1063.  
  1064.  
  1065. [moveToBack]
  1066.  
  1067.     'move the selected control to the back (first item drawn)
  1068.     if index < 2 or objectCount < 2 then [inputLoop]
  1069.     if index = 2 then gosub [redrawAll] : goto [inputLoop]
  1070.  
  1071.     tmpType$ = type$(index)
  1072.     tmpLabel$ = label$(index)
  1073.     tmpNames$ = names$(index)
  1074.     tmpXOrigin = xOrg(index)
  1075.     tmpYOrigin = yOrg(index)
  1076.     tmpWidth = width(index)
  1077.     tmpHeight = height(index)
  1078.     tmpCorner$ = corner$(index)
  1079.     tmpBranchLabel$ = branchLabel$(index)
  1080.     tmpSegment = segment(index)
  1081.     tmpHandle$ = handle$(index)
  1082.     tmpBmpName$ = bmpName$(index)
  1083.  
  1084.     for idx = index - 1 to 2 step -1
  1085.         type$(idx+1) = type$(idx)
  1086.         label$(idx+1) = label$(idx)
  1087.         names$(idx+1) = names$(idx)
  1088.         xOrg(idx+1) = xOrg(idx)
  1089.         yOrg(idx+1) = yOrg(idx)
  1090.         width(idx+1) = width(idx)
  1091.         height(idx+1) = height(idx)
  1092.         corner$(idx+1) = corner$(idx)
  1093.         branchLabel$(idx+1) = branchLabel$(idx)
  1094.         segment(idx+1) = segment(idx)
  1095.         handle$(idx+1) = handle$(idx)
  1096.         bmpName$(idx+1) = bmpName$(idx)
  1097.     next idx
  1098.  
  1099.     type$(2) = tmpType$
  1100.     label$(2) = tmpLabel$
  1101.     names$(2) = tmpNames$
  1102.     xOrg(2) = tmpXOrigin
  1103.     yOrg(2) = tmpYOrigin
  1104.     width(2) = tmpWidth
  1105.     height(2) = tmpHeight
  1106.     corner$(2) = tmpCorner$
  1107.     branchLabel$(2) = tmpBranchLabel$
  1108.     segment(2) = tmpSegment
  1109.     handle$(2) = tmpHandle$
  1110.     bmpName$(2) = tmpBmpName$
  1111.  
  1112.     gosub [redrawAll]
  1113.     index = 0 'necessary here
  1114.  
  1115.     goto [inputLoop]
  1116.  
  1117.  
  1118. [moveToFront]
  1119.  
  1120.     'move the selected control to the front (last item drawn)
  1121.     if index < 2 or objectCount < 2 then [inputLoop]
  1122.     if index = objectCount then gosub [redrawAll] : goto [inputLoop]
  1123.  
  1124.     tmpType$ = type$(index)
  1125.     tmpLabel$ = label$(index)
  1126.     tmpNames$ = names$(index)
  1127.     tmpXOrigin = xOrg(index)
  1128.     tmpYOrigin = yOrg(index)
  1129.     tmpWidth = width(index)
  1130.     tmpHeight = height(index)
  1131.     tmpCorner$ = corner$(index)
  1132.     tmpBranchLabel$ = branchLabel$(index)
  1133.     tmpSegment = segment(index)
  1134.     tmpHandle$ = handle$(index)
  1135.     tmpBmpName$ = bmpName$(index)
  1136.  
  1137.     for idx = index to objectCount - 1
  1138.         type$(idx) = type$(idx+1)
  1139.         label$(idx) = label$(idx+1)
  1140.         names$(idx) = names$(idx+1)
  1141.         xOrg(idx) = xOrg(idx+1)
  1142.         yOrg(idx) = yOrg(idx+1)
  1143.         width(idx) = width(idx+1)
  1144.         height(idx) = height(idx+1)
  1145.         corner$(idx) = corner$(idx+1)
  1146.         branchLabel$(idx) = branchLabel$(idx+1)
  1147.         segment(idx) = segment(idx+1)
  1148.         handle$(idx) = handle$(idx+1)
  1149.         bmpName$(idx) = bmpName$(idx+1)
  1150.     next idx
  1151.  
  1152.     type$(objectCount) = tmpType$
  1153.     label$(idx) = tmpLabel$
  1154.     names$(objectCount) = tmpNames$
  1155.     xOrg(objectCount) = tmpXOrigin
  1156.     yOrg(objectCount) = tmpYOrigin
  1157.     width(objectCount) = tmpWidth
  1158.     height(objectCount) = tmpHeight
  1159.     corner$(objectCount) = tmpCorner$
  1160.     branchLabel$(objectCount) = tmpBranchLabel$
  1161.     segment(objectCount) = tmpSegment
  1162.     handle$(objectCount) = tmpHandle$
  1163.     bmpName$(objectCount) = tmpBmpName$
  1164.  
  1165.     gosub [redrawAll]
  1166.     gosub [selectDeselect]
  1167.  
  1168.     goto [inputLoop]
  1169.  
  1170.  
  1171. [deleteControl]
  1172.  
  1173.     'delete the selected control
  1174.     if index < 2 then [inputLoop]
  1175.  
  1176.     'delete graphical segments and clean up display
  1177.     print #form, "delsegment "; selectId -1 ;
  1178.     gosub [selectDeselect]
  1179.     print #form, "delsegment "; selectId - 1 ;
  1180.  
  1181.     for idx = index to objectCount
  1182.         type$(idx) = type$(idx+1)
  1183.         label$(idx) = label$(idx+1)
  1184.         names$(idx) = names$(idx+1)
  1185.         xOrg(idx) = xOrg(idx+1)
  1186.         yOrg(idx) = yOrg(idx+1)
  1187.         width(idx) = width(idx+1)
  1188.         height(idx) = height(idx+1)
  1189.         corner$(idx) = corner$(idx+1)
  1190.         branchLabel$(idx) = branchLabel$(idx+1)
  1191.         segment(idx) = segment(idx+1)
  1192.         handle$(idx) = handle$(idx+1)
  1193.         bmpName$(idx) = bmpName$(idx+1)
  1194.         arrayName$(idx) = arrayName$(idx+1)
  1195.     next idx
  1196.  
  1197.     objectCount = objectCount - 1
  1198.  
  1199.     gosub [redrawAll]
  1200.     index = 0
  1201.  
  1202.     goto [inputLoop]
  1203.  
  1204.  
  1205. [produceCodeAndOutline]
  1206.  
  1207.     'set a flag so that an outline will be added
  1208.     produceOutline = 1
  1209.  
  1210. [produceCode]
  1211.  
  1212.     'produce code for the controls in the form
  1213.     if objectCount < 2 then notice "No objects.  Code not produced" : goto [inputLoop]
  1214.  
  1215.     if codeIsOpen = 1 then close #code
  1216.  
  1217.     open "Free Form output window" for text as #code
  1218.     codeIsOpen = 1
  1219.  
  1220.  
  1221.  
  1222.     print #code, ""
  1223.     print #code, ""
  1224.     print #code, "    WindowWidth = "; windowXExtent
  1225.     print #code, "    WindowHeight = "; windowYExtent
  1226.     print #code, ""
  1227.  
  1228.     for x = 2 to objectCount
  1229.         if type$(x) = "button" then gosub [codeForButton]
  1230.         if type$(x) = "combobox" then gosub [codeForComboBox]
  1231.         if type$(x) = "textbox" then gosub [codeForTextBox]
  1232.         if type$(x) = "listbox" then gosub [codeForListBox]
  1233.         if type$(x) = "bmpbutton" then gosub [codeForBmpButton]
  1234.         if type$(x) = "statictext" then gosub [codeForStaticText]
  1235.         if type$(x) = "radiobutton" then gosub [codeForRadioButton]
  1236.         if type$(x) = "checkbox" then gosub [codeForCheckBox]
  1237.         if type$(x) = "groupbox" then gosub [codeForGroupBox]
  1238.         if type$(x) = "textedit" then gosub [codeForTextEdit]
  1239.         print #code, code$
  1240.     next x
  1241.  
  1242.     if menuCount = 0 then [noMenuCode]
  1243.  
  1244.     if left$(windowType$, 6) = "dialog" then print #code, "    '*** menus are not supported in windows of type "; windowType$; " ***"
  1245.  
  1246.     for x = 0 to menuCount - 1
  1247.         print #code, "    menu "; winHandle$; ", "; qu$; menu$(x); qu$;
  1248.         if menuItemCount(x) = 0 then print #code, ", "; chr$(34); "&FixMe"; chr$(34); ", [fixMe]  ' <-- this menu has no items!" : goto [produceNextMenu]
  1249.         for y = 0 to menuItemCount(x) - 1
  1250.             print #code, ", ";
  1251.             mi$ = menuItem$(x, y)
  1252.             print #code, qu$; left$(mi$, instr(mi$, chr$(0)) - 1) ; qu$;
  1253.             print #code, ", "; mid$(mi$, instr(mi$, chr$(0)) + 1) ;
  1254.         next y
  1255.         print #code, ""
  1256.       [produceNextMenu]
  1257.     next x
  1258.  
  1259.  
  1260. [noMenuCode] 'don't produce menu code
  1261.  
  1262.     print #code, "    open "; qu$; windowLabel$; qu$; " for "; windowType$; " as "; winHandle$
  1263.  
  1264.     if produceOutline = 0 then [doneProducingCode]
  1265.  
  1266.  
  1267. [produceOutline]
  1268.  
  1269.     inputLoopLabel$ = "[" + mid$(winHandle$, 2) + ".inputLoop]"
  1270.  
  1271.     print #code, ""
  1272.     print #code, ""
  1273.     print #code, inputLoopLabel$; "   'wait here for input event"
  1274.     print #code, "    input aVar$"
  1275.     print #code, "    goto "; inputLoopLabel$
  1276.     print #code, ""
  1277.  
  1278.     produceOutline = 0
  1279.     branchLabels$ = ""
  1280.  
  1281.     for x = 2 to objectCount
  1282.         if left$(trim$(branchLabel$(x)), 1) <> "[" then [nextOutlineObject]
  1283.         if instr(trim$(branchLabel$(x)), " ") > 0 then gosub [handleMultiBranchLabels] : goto [nextOutlineObject]
  1284.         if instr(branchLabels$, branchLabel$(x)) > 0 then [nextOutlineObject]
  1285.         branchLabels$ = branchLabels$ + " " + branchLabel$(x)
  1286.         print #code, ""
  1287.         print #code, ""
  1288.         print #code, branchLabel$(x); "   'Perform action for the "; type$(x); " named '"; names$(x); "'"
  1289.         print #code, ""
  1290.         print #code, "    'Insert your own code here"
  1291.         print #code, ""
  1292.         print #code, "    goto "; inputLoopLabel$
  1293.  
  1294.       [nextOutlineObject]
  1295.     next x
  1296.  
  1297.     if menuCount = 0 then [doneProducingCode]
  1298.  
  1299.     for x = 0 to menuCount - 1
  1300.         for y = 0 to menuItemCount(x) - 1
  1301.             mi$ = menuItem$(x, y)
  1302.             bl$ = mid$(mi$, instr(mi$, chr$(0)) + 1)
  1303.             if instr(branchLabels$, bl$) > 0 then [writeNextMenuItem]
  1304.             branchLabels$ = branchLabels$ + " " + bl$
  1305.             print #code, ""
  1306.             print #code, ""
  1307.             print #code, bl$; "   'Perform action for menu "; menu$(x); ", item "; left$(mi$, instr(mi$, chr$(0)) - 1)
  1308.             print #code, ""
  1309.             print #code, "    'Insert your own code here"
  1310.           [writeNextMenuItem]
  1311.         next y
  1312.     next x
  1313.  
  1314.  
  1315. [doneProducingCode]
  1316.  
  1317.     notice "Done.  Copy this code into your program."
  1318.  
  1319.     goto [inputLoop]
  1320.  
  1321.  
  1322. [handleMultiBranchLabels]   'handle the case where a control has more than 1 branching option
  1323.  
  1324.     if instr(branchLabels$, word$(branchLabel$(x), 1)) > 0 then [nextMultiBranchLabel]
  1325.     print #code, ""
  1326.     print #code, ""
  1327.     print #code, word$(branchLabel$(x), 1); "   'Perform action for the "; type$(x); " named '"; names$(x); "'"
  1328.     print #code, ""
  1329.     print #code, "    'Insert your own code here"
  1330.     print #code, ""
  1331.     print #code, "    goto "; inputLoopLabel$
  1332.  
  1333.     branchLabels$ = branchLabels$ + " " + word$(branchLabel$(x), 1)
  1334.  
  1335.   [nextMultiBranchLabel]
  1336.  
  1337.     if instr(branchLabels$, word$(branchLabel$(x), 2)) > 0 then [doneMultiBranchLabel]
  1338.     print #code, ""
  1339.     print #code, ""
  1340.     print #code, word$(branchLabel$(x), 2); "   'Perform action for the "; type$(x); " named '"; names$(x); "'"
  1341.     print #code, ""
  1342.     print #code, "    'Insert your own code here"
  1343.     print #code, ""
  1344.     print #code, "    goto "; inputLoopLabel$
  1345.     branchLabels$ = branchLabels$ + " " + word$(branchLabel$(x), 2)
  1346.  
  1347.   [doneMultiBranchLabel]
  1348.  
  1349.     return
  1350.  
  1351.  
  1352. [codeForButton]
  1353.  
  1354.     'produce code for a text button
  1355.     code$ = "    button "+winHandle$+", "+qu$+label$(x)+qu$+", "+branchLabel$(x)+", "+corner$(x)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1356.     return
  1357.  
  1358.  
  1359. [codeForBmpButton]
  1360.  
  1361.     'produce code for a bmp button
  1362.     code$ = "    bmpbutton "+winHandle$+", "+qu$+bmpName$(x)+qu$+", "+branchLabel$(x)+", "+corner$(x)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)
  1363.     return
  1364.  
  1365.  
  1366. [codeForTextBox]
  1367.  
  1368.     'produce code for a text box
  1369.     code$ = "    textbox "+winHandle$+"."+names$(x)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1370.     return
  1371.  
  1372.  
  1373. [codeForStaticText]
  1374.  
  1375.     'produce code for a static text
  1376.     code$ = "    statictext "+winHandle$+"."+names$(x)+", "+qu$+label$(x)+qu$+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1377.     return
  1378.  
  1379.  
  1380. [codeForGroupBox]
  1381.  
  1382.     'produce code for a group box
  1383.     code$ = "    groupbox "+winHandle$+", "+qu$+label$(x)+qu$+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1384.     return
  1385.  
  1386.  
  1387. [codeForListBox]
  1388.  
  1389.     'produce code for a listbox
  1390.     code$ = "    listbox "+winHandle$+"."+names$(x)+", "+arrayName$(x)+", "+branchLabel$(x)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1391.     return
  1392.  
  1393.  
  1394. [codeForComboBox]
  1395.  
  1396.     'produce code for a listbox
  1397.     code$ = "    combobox "+winHandle$+"."+names$(x)+", "+arrayName$(x)+", "+branchLabel$(x)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1398.     return
  1399.  
  1400.  
  1401. [codeForRadioButton]
  1402.  
  1403.     'produce code for a radiobutton
  1404.     code$ = "    radiobutton "+winHandle$+"."+names$(x)+", "+qu$+label$(x)+qu$+", "+word$(branchLabel$(x), 1)+", "+word$(branchLabel$(x), 2)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1405.     return
  1406.  
  1407.  
  1408. [codeForCheckBox]
  1409.  
  1410.     'produce code for a checkbox
  1411.     code$ = "    checkbox "+winHandle$+"."+names$(x)+", "+qu$+label$(x)+qu$+", "+word$(branchLabel$(x), 1)+", "+word$(branchLabel$(x), 2)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1412.     return
  1413.  
  1414. [codeForTextEdit]
  1415.  
  1416.     'produce code for a text edit box
  1417.     code$ = "    texteditor "+winHandle$+"."+names$(x)+", "+str$(xOrg(x)-xOrg-4)+", "+str$(yOrg(x)-yOrg-20-4)+", "+str$(width(x))+", "+str$(height(x))
  1418.     return
  1419.  
  1420.  
  1421. [newFile]
  1422.  
  1423.     'clear the contents of the form editor and start over
  1424.  
  1425.     if isModified = 1 then gosub [formIsModified]
  1426.  
  1427.     newControlNumber = 0
  1428.     windowLabel$ = "untitled"
  1429.     windowType$ = "window"
  1430.     objectCount = 0
  1431.     winHandle$ = "#main"
  1432.     windowXExtent = 550
  1433.     windowYExtent = 410
  1434.  
  1435.     gosub [clearMenuData]
  1436.     gosub [addWindowFrame]
  1437.     gosub [redrawAll]
  1438.  
  1439.     isModified = 0
  1440.  
  1441.     goto [inputLoop]
  1442.  
  1443.  
  1444. [saveFile]
  1445.  
  1446.     'abort if no controls
  1447.     if objectCount < 2 then notice "No controls.  Save aborted" : goto [inputLoop]
  1448.  
  1449.     'save the form into a *.fre file
  1450.     if formName$ = "" then formName$ = "untitled.fre"
  1451.     filedialog "Save form", "*.fre", formName$
  1452.     if formName$ = "" then [inputLoop]
  1453.  
  1454.     gosub [saveFormSubroutine]
  1455.  
  1456.     notice "Done.  File saved as " + formName$
  1457.     goto [inputLoop]
  1458.  
  1459.  
  1460. [saveFormSubroutine]   'the subroutine portion of the save routine
  1461.  
  1462.     open formName$ for output as #formOut
  1463.     print #formOut, newControlNumber
  1464.     print #formOut, windowLabel$
  1465.     print #formOut, windowType$
  1466.     print #formOut, objectCount
  1467.     print #formOut, winHandle$
  1468.     print #formOut, snapOn
  1469.     print #formOut, xInterval
  1470.     print #formOut, yInterval
  1471.     print #formOut, menuCount
  1472.     print #formOut, windowXExtent
  1473.     print #formOut, windowYExtent
  1474.  
  1475.     for i = 2 to objectCount
  1476.         print #formOut, type$(i)
  1477.         print #formOut, label$(i)
  1478.         print #formOut, names$(i)
  1479.         print #formOut, xOrg(i)
  1480.         print #formOut, yOrg(i)
  1481.         print #formOut, width(i)
  1482.         print #formOut, height(i)
  1483.         print #formOut, corner$(i)
  1484.         print #formOut, branchLabel$(i)
  1485.         print #formOut, segment(i)
  1486.         print #formOut, handle$(i)
  1487.         print #formOut, bmpName$(i)
  1488.         print #formOut, arrayName$(i)
  1489.     next i
  1490.  
  1491.     'Now write the menu information
  1492.     if menuCount = 0 then [noMenusToSave]
  1493.  
  1494.     for i = 0 to menuCount - 1
  1495.         print #formOut, menu$(i)
  1496.         print #formOut, menuItemCount(i)
  1497.         if menuItemCount(i) = 0 then [noMenuItemsToSave]
  1498.         for j = 0 to menuItemCount(i) - 1
  1499.             print #formOut, menuItem$(i, j)
  1500.         next j
  1501.       [noMenuItemsToSave]
  1502.     next i
  1503.  
  1504.  
  1505. [noMenusToSave]
  1506.  
  1507.     close #formOut
  1508.  
  1509.     return
  1510.  
  1511.  
  1512. [openFile]
  1513.  
  1514.     'load the form from a *.fre file
  1515.  
  1516.     if isModified = 1 then gosub [formIsModified]
  1517.  
  1518.     filedialog "Load form", "*.fre", formName$
  1519.     if formName$ = "" then [inputLoop]
  1520.  
  1521.     gosub [clearMenuData]
  1522.     objectCount = 0
  1523.     gosub [addWindowFrame]
  1524.  
  1525.     open formName$ for input as #formIn
  1526.     input #formIn, newControlNumber
  1527.     input #formIn, windowLabel$
  1528.     input #formIn, windowType$
  1529.     input #formIn, objectCount
  1530.     input #formIn, winHandle$
  1531.     input #formIn, snapOn
  1532.     input #formIn, xInterval
  1533.     input #formIn, yInterval
  1534.     input #formIn, menuCount
  1535.     input #formIn, windowXExtent
  1536.     input #formIn, windowYExtent
  1537.  
  1538.     width(1) = windowXExtent
  1539.     height(1) = windowYExtent
  1540.  
  1541.     for i = 2 to objectCount
  1542.         input #formIn, tmp$ : type$(i) = tmp$
  1543.         input #formIn, tmp$ : label$(i) = tmp$
  1544.         input #formIn, tmp$ : names$(i) = tmp$
  1545.         input #formIn, tmp : xOrg(i) = tmp
  1546.         input #formIn, tmp : yOrg(i) = tmp
  1547.         input #formIn, tmp : width(i) = tmp
  1548.         input #formIn, tmp : height(i) = tmp
  1549.         input #formIn, tmp$ : corner$(i) = tmp$
  1550.         input #formIn, tmp$ : branchLabel$(i) = tmp$
  1551.         input #formIn, tmp : segment(i) = tmp
  1552.         input #formIn, tmp$ : handle$(i) = tmp$
  1553.         input #formIn, tmp$ : bmpName$(i) = tmp$
  1554.         if trim$(tmp$) > "" then loadbmp tmp$, tmp$
  1555.         input #formIn, tmp$ : arrayName$(i) = tmp$
  1556.     next i
  1557.  
  1558.     if menuCount = 0 then [noMenusToRead]
  1559.  
  1560.     for i = 0 to menuCount - 1
  1561.         input #formIn, tmp$ : menu$(i)=tmp$
  1562.         input #formIn, tmp : menuItemCount(i) = tmp
  1563.         if menuItemCount(i) = 0 then [noMenuItemsToRead]
  1564.         for j = 0 to menuItemCount(i) - 1
  1565.             input #formIn, tmp$ : menuItem$(i, j) = tmp$
  1566.         next j
  1567.       [noMenuItemsToRead]
  1568.     next i
  1569.  
  1570. [noMenusToRead]
  1571.  
  1572.     close #formIn
  1573.     gosub [redrawAll]
  1574.  
  1575.     isModified = 0
  1576.  
  1577.     goto [inputLoop]
  1578.  
  1579.  
  1580.  
  1581.  
  1582. [gridDialog]  'open a dialog box for selecting & adjusting snap to grid
  1583.  
  1584.     WindowWidth = 350
  1585.     WindowHeight = 225
  1586.  
  1587.     if gridDialogIsOpen = 1 then close #gridDialog
  1588.  
  1589.     statictext #gridDialog.statictext2, "Select here whether control positions will", 26, 16, 336, 20
  1590.     statictext #gridDialog.statictext5, "automatically snap to gridded positions,", 26, 35, 320, 20
  1591.     statictext #gridDialog.statictext6, "and what the interval will be.", 26, 54, 240, 20
  1592.     checkbox #gridDialog.snapOnOff, "Snap to Grid", [snapOn], [snapOff], 26, 85, 120, 20
  1593.     statictext #gridDialog.statictext7, "X interval:", 34, 112, 70, 20
  1594.     textbox #gridDialog.xIntrvl, 111, 106, 38, 25
  1595.     statictext #gridDialog.statictext9, "Y interval:", 178, 112, 70, 20
  1596.     textbox #gridDialog.yIntrvl, 255, 106, 38, 25
  1597.     button #gridDialog, "OK", [acceptGridDialog], UL, 99, 149
  1598.     button #gridDialog, "Cancel", [cancelGridDialog], UL, 29, 149
  1599.     open "Snap to Grid" for dialog_modal as #gridDialog
  1600.     print #gridDialog, "trapclose [cancelGridDialog]"
  1601.     gridDialogIsOpen = 1
  1602.  
  1603.     if snapOn = 1 then snapOnSelected = 1 : print #gridDialog.snapOnOff, "set"
  1604.     print #gridDialog.xIntrvl, xInterval
  1605.     print #gridDialog.yIntrvl, yInterval
  1606.  
  1607.     goto [inputLoop]
  1608.  
  1609.  
  1610. [snapOn]   'Perform on action for the checkbox named 'snapOnOff'
  1611.  
  1612.     snapOnSelected = 1
  1613.     goto [inputLoop]
  1614.  
  1615.  
  1616. [snapOff]   'Perform off action for the checkbox named 'snapOnOff'
  1617.  
  1618.     snapOnSelected = 0
  1619.     goto [inputLoop]
  1620.  
  1621.  
  1622. [acceptGridDialog]
  1623.  
  1624.     snapOn = snapOnSelected
  1625.     print #gridDialog.xIntrvl, "!contents?"
  1626.     input #gridDialog.xIntrvl, xInterval
  1627.     print #gridDialog.yIntrvl, "!contents?"
  1628.     input #gridDialog.yIntrvl, yInterval
  1629.  
  1630.  
  1631. [cancelGridDialog]
  1632.  
  1633.     gridDialogIsOpen = 0
  1634.     close #gridDialog
  1635.     goto [inputLoop]
  1636.  
  1637.  
  1638. [addAMenu]    'add a new menu item
  1639.  
  1640.  
  1641.     WindowWidth = 400
  1642.     WindowHeight = 230
  1643.     listbox #newMenu.menuNames, menu$(, [inputLoop], 14, 36, 120, 120
  1644.     statictext #newMenu.statictext2, "Defined Menus", 14, 16, 104, 20
  1645.     statictext #newMenu.statictext3, "Enter new menu name here:", 150, 16, 200, 20
  1646.     textbox #newMenu.newMenuName, 150, 36, 208, 25
  1647.     button #newMenu, "Accept", [acceptNewMenu], UL, 302, 131
  1648.     button #newMenu, "Cancel", [cancelNewMenu], UL, 302, 101
  1649.     open "Add a Menu" for dialog_modal as #newMenu
  1650.     print #newMenu, "trapclose [cancelNewMenu]";
  1651.     goto [inputLoop]
  1652.  
  1653.  
  1654. [cancelNewMenu]   'Perform action for the button named 'cancelNewMenu'
  1655.  
  1656.     'close the dialog box
  1657.     close #newMenu
  1658.     goto [inputLoop]
  1659.  
  1660.  
  1661. [clearMenuData]     'reset menu data arrays and indices
  1662.  
  1663.     for x = 0 to 20
  1664.         menu$(x) = ""
  1665.         for y = 0 to 30
  1666.             menuItem$(x, y) = ""
  1667.         next y
  1668.     next x
  1669.     menuCount = 0
  1670.     return
  1671.  
  1672.  
  1673. [acceptNewMenu]   'Perform action for the button named 'acceptNewMenu'
  1674.  
  1675.     'add this menu onto the list of menus, and update the display as needed
  1676.     print #newMenu.newMenuName, "!contents?";
  1677.     input #newMenu.newMenuName, result$
  1678.     if result$ = "" then notice "Please type a name for a new menu." : goto [inputLoop]
  1679.     close #newMenu
  1680.     menu$(menuCount) = result$
  1681.     menuCount = menuCount + 1
  1682.     if menuCount > 1 then gosub [redrawAll] : goto [inputLoop]
  1683.  
  1684.     'since this is the first menu added, reposition all controls 20 pixels down
  1685.     if objectCount < 2 then gosub [redrawAll] : goto [inputLoop]
  1686.     for x = 2 to objectCount
  1687.         yOrg(x) = yOrg(x) + 20
  1688.     next x
  1689.     gosub [redrawAll]
  1690.     goto [inputLoop]
  1691.  
  1692.  
  1693.  
  1694. [removeMenu]   'remove a menu from the list of menus
  1695.  
  1696.     if menuCount = 0 then notice "No menus to remove." : goto [inputLoop]
  1697.  
  1698.     if removeMenuIsOpen = 1 then close #removeMenu
  1699.  
  1700.     WindowWidth = 330
  1701.     WindowHeight = 195
  1702.     statictext #removeMenu.statictext1, "Select a menu to remove:", 26, 16, 192, 20
  1703.     listbox #removeMenu.menusToRemove, menu$(, [acceptRemoveMenu], 22, 41, 208, 100
  1704.     button #removeMenu, "Accept", [acceptRemoveMenu], UL, 246, 81
  1705.     button #removeMenu, "Cancel", [cancelRemoveMenu], UL, 246, 111
  1706.     open "Remove a Menu" for dialog_modal as #removeMenu
  1707.     print #removeMenu, "trapclose [cancelRemoveMenu]";
  1708.     removeMenuIsOpen = 1
  1709.  
  1710.     goto [inputLoop]
  1711.  
  1712.  
  1713. [acceptRemoveMenu]   'get the name of the selected item, and remove it
  1714.  
  1715.     print #removeMenu.menusToRemove, "selectionIndex?"
  1716.     input #removeMenu.menusToRemove, result
  1717.     close #removeMenu
  1718.     removeMenuIsOpen = 0
  1719.     if result = 0 then notice "No item selected.  Menu not removed." : goto [inputLoop]
  1720.  
  1721.     menuCount = menuCount - 1
  1722.     result = result - 1
  1723.  
  1724.     if result = menuCount then menu$(result) = "" : goto [checkForEmptyMenuBar]
  1725.  
  1726.     for x = result to menuCount
  1727.         menu$(x) = menu$(x+1)
  1728.     next x
  1729.  
  1730.   [checkForEmptyMenuBar]  'if there are no more menus, shift controls up 20 pixels
  1731.  
  1732.     if menuCount > 0 then gosub [redrawAll] : goto [inputLoop]
  1733.  
  1734.     for x = 2 to objectCount
  1735.         yOrg(x) = yOrg(x) - 20
  1736.     next x
  1737.  
  1738.     gosub [redrawAll]
  1739.  
  1740.     goto [inputLoop]
  1741.  
  1742.  
  1743. [cancelRemoveMenu]   'close the remove menu dialog
  1744.  
  1745.     close #removeMenu
  1746.     removeMenuIsOpen = 0
  1747.     goto [inputLoop]
  1748.  
  1749.  
  1750. [editMenus]     'edit menu order and menu contents
  1751.  
  1752.     if menuCount = 0 then notice "No menus to edit." : goto [inputLoop]
  1753.  
  1754.     if editMenuIsOpen = 1 then close #editMenu
  1755.  
  1756.     WindowWidth = 450
  1757.     WindowHeight = 375
  1758.  
  1759.     listbox #editMenu.menuList, menu$(, [selectMenuToEdit], 14, 31, 112, 105
  1760.     listbox #editMenu.menuItems, menuItemLocal$(, [selectMenuItemToEdit], 14, 166, 288, 145
  1761.     statictext #editMenu.statictext6, "Menus:", 14, 11, 48, 20
  1762.     statictext #editMenu.statictext14, "Menu line items -> Branch labels:", 14, 146, 240, 20
  1763.     button #editMenu, "&Close", [closeMenuEdit], UL, 326, 21
  1764.     button #editMenu, "&New Item", [addNewMenuItem], UL, 310, 166
  1765.     button #editMenu, "&Edit", [editMenuItem], UL, 310, 196
  1766.     button #editMenu, "Move &Up", [moveMenuItemUp], UL, 310, 226
  1767.     button #editMenu, "&Move Dn", [moveMenuItemDown], UL, 310, 256
  1768.     button #editMenu, "&Delete", [deleteMenuItem], UL, 310, 286
  1769.     button #editMenu, "&To Top", [moveMenuToTop], UL, 134, 41
  1770.     open "Edit Menus" for dialog_modal as #editMenu
  1771.     print #editMenu, "trapclose [closeMenuEdit]";
  1772.     print #editMenu.menuList, "singleclickselect";
  1773.     print #editMenu.menuItems, "singleclickselect";
  1774.  
  1775.     editMenuIsOpen = 1
  1776.     menuItemIndex = 0
  1777.     result = 0
  1778.  
  1779.     goto [inputLoop]
  1780.  
  1781.  
  1782. [selectMenuToEdit]   'Perform action for the listbox named 'menuList'
  1783.  
  1784.     'populate the listbox named menuItems
  1785.     print #editMenu.menuList, "selectionIndex?"
  1786.     input #editMenu.menuList, result
  1787.  
  1788.     for x = 0 to 29
  1789.         mil$ = menuItem$(result - 1, x)
  1790.         if mil$ <> "" then mil$ = left$(mil$, instr(mil$, chr$(0)) - 1) + " -> " + mid$(mil$, instr(mil$, chr$(0)) + 1)
  1791.         menuItemLocal$(x) = mil$
  1792.     next x
  1793.     print #editMenu.menuItems, "reload"
  1794.  
  1795.     menuItemIndex = 0
  1796.  
  1797.     goto [inputLoop]
  1798.  
  1799.  
  1800. [moveMenuToTop]   'move the selected menu to the top of the list
  1801.  
  1802.     'if there is no selection, or if the selected item is already on top, do nothing
  1803.     if result = 0 or result = 1 then [inputLoop]
  1804.  
  1805.     menu$(20) = menu$(result - 1)
  1806.     for x = 0 to 29
  1807.         menuItem$(20, x) = menuItem$(result - 1, x)
  1808.     next x
  1809.  
  1810.     for x = result - 1 to 1 step -1
  1811.         menu$(x) = menu$(x - 1)
  1812.         for y = 0 to 29
  1813.             menuItem$(x, y) = menuItem$(x - 1, y)
  1814.         next y
  1815.     next x
  1816.  
  1817.     menu$(0) = menu$(20)
  1818.     menu$(20) = ""
  1819.     for x = 0 to 29
  1820.         menuItem$(0, x) = menuItem$(20, x)
  1821.         menuItem$(20, x) = ""
  1822.     next x
  1823.  
  1824.     print #editMenu.menuList, "reload"
  1825.     print #editMenu.menuList, "selectIndex 1"
  1826.     result = 1
  1827.  
  1828.     'now continue on to the next routine!
  1829.  
  1830.  
  1831. [selectMenuItemToEdit]   'Perform action for the listbox named 'menuItems'
  1832.  
  1833.     'set the selection index for the menu item to edit
  1834.     print #editMenu.menuItems, "selectionIndex?"
  1835.     input #editMenu.menuItems, menuItemIndex
  1836.     goto [inputLoop]
  1837.  
  1838.  
  1839. [addNewMenuItem]   'Perform action for the button named 'newItemButton'
  1840.  
  1841.     'Insert your own code here
  1842.     if result = 0 then [inputLoop]
  1843.  
  1844.     if editMenuItemIsOpen = 1 then gosub [closeEditMenuItem]
  1845.  
  1846.     menuItemCount(result - 1) = menuItemCount(result - 1) + 1
  1847.     menuItemIndex = menuItemCount(result - 1)
  1848.     editMenuItemAction$ = "ADD"
  1849.     goto [editMenuItemProperties]
  1850.  
  1851.  
  1852. [editMenuItem]   'Perform action for the button named 'editMenuItem'
  1853.  
  1854.     'Insert your own code here
  1855.     if menuItemIndex = 0 then [inputLoop]
  1856.  
  1857.     if editMenuItemIsOpen = 1 then gosub [closeEditMenuItem]
  1858.  
  1859.     editMenuItemAction$ = "EDIT"
  1860.     goto [editMenuItemProperties]
  1861.  
  1862.  
  1863. [moveMenuItemUp]   'Perform action for the button named 'moveMenuItemUp'
  1864.  
  1865.     'Insert your own code here
  1866.     if menuItemIndex = 1 or menuItemIndex = 0 then [inputLoop]
  1867.  
  1868.     tmpMi$ = menuItem$(result - 1, menuItemIndex - 1)
  1869.     menuItem$(result - 1, menuItemIndex - 1) = menuItem$(result - 1, menuItemIndex - 2)
  1870.     menuItem$(result - 1, menuItemIndex - 2) = tmpMi$
  1871.  
  1872.     gosub [reloadLocalMenuItems]
  1873.  
  1874.     menuItemIndex = menuItemIndex - 1
  1875.     print #editMenu.menuItems, "selectIndex "; menuItemIndex
  1876.  
  1877.     goto [inputLoop]
  1878.  
  1879.  
  1880. [moveMenuItemDown]   'Perform action for the button named 'moveMenuItemDown'
  1881.  
  1882.     'Insert your own code here
  1883.     if result = 0 then [inputLoop]
  1884.     if menuItemIndex = menuItemCount(result - 1) or menuItemIndex = 0 then [inputLoop]
  1885.  
  1886.     tmpMi$ = menuItem$(result - 1, menuItemIndex - 1)
  1887.     menuItem$(result - 1, menuItemIndex - 1) = menuItem$(result - 1, menuItemIndex)
  1888.     menuItem$(result - 1, menuItemIndex) = tmpMi$
  1889.  
  1890.     gosub [reloadLocalMenuItems]
  1891.  
  1892.     menuItemIndex = menuItemIndex + 1
  1893.     print #editMenu.menuItems, "selectIndex "; menuItemIndex
  1894.  
  1895.     goto [inputLoop]
  1896.  
  1897.  
  1898. [deleteMenuItem]   'Perform action for the button named 'deleteMenuItem'
  1899.  
  1900.     'Insert your own code here
  1901.     if result = 0 then [inputLoop]
  1902.     if menuItemCount(result - 1) = 0 or menuItemIndex = 0 then [inputLoop]
  1903.  
  1904.     for x = menuItemIndex to 30
  1905.         menuItem$(result - 1, x - 1) = menuItem$(result - 1, x)
  1906.     next x
  1907.  
  1908.     gosub [reloadLocalMenuItems]
  1909.  
  1910.     menuItemIndex = 0
  1911.  
  1912.     return
  1913.  
  1914.  
  1915. [reloadLocalMenuItems]  'reload the contents of the menu items listbox
  1916.  
  1917.     for x = 0 to 29
  1918.         mil$ = menuItem$(result - 1, x)
  1919.         if mil$ <> "" then mil$ = left$(mil$, instr(mil$, chr$(0)) - 1) + " -> " + mid$(mil$, instr(mil$, chr$(0)) + 1)
  1920.         menuItemLocal$(x) = mil$
  1921.     next x
  1922.     print #editMenu.menuItems, "reload"
  1923.  
  1924.     return
  1925.  
  1926.  
  1927. [closeMenuEdit]   'Perform action for the button named 'closeMenuEdit'
  1928.  
  1929.     'close the menu editing dialog and redraw the form
  1930.     for x = 0 to 29 : menuItemLocal$(x) = "" : next x
  1931.     close #editMenu
  1932.     editMenuIsOpen = 0
  1933.     'gosub [redrawAll]
  1934.  
  1935.     goto [inputLoop]
  1936.  
  1937.  
  1938. [editMenuItemProperties]    'open a dialog for editing menu item properties
  1939.  
  1940.  
  1941.     WindowWidth = 350
  1942.     WindowHeight = 150
  1943.  
  1944.     textbox #menuItems.name, 134, 16, 184, 25
  1945.     textbox #menuItems.branchLabel, 134, 51, 184, 25
  1946.     statictext #menuItems.statictext6, "Name:", 22, 21, 40, 20
  1947.     statictext #menuItems.statictext7, "Branch Label:", 22, 56, 104, 20
  1948.     button #menuItems, "Accept", [acceptMenuItemProps], UL, 198, 86
  1949.     button #menuItems, "Cancel", [cancelMenuItemProps], UL, 262, 86
  1950.     open "Menu Item Properties" for dialog_modal as #menuItems
  1951.     editMenuItemIsOpen = 1
  1952.  
  1953.     print #menuItems.name, "???"
  1954.     print #menuItems.branchLabel, "[???]"
  1955.  
  1956.     if menuItem$(result - 1, menuItemIndex - 1) = "" then [inputLoop]
  1957.  
  1958.     mi$ = menuItem$(result - 1, menuItemIndex - 1)
  1959.     print #menuItems.name, left$(mi$, instr(mi$, chr$(0)) - 1)
  1960.     print #menuItems.branchLabel, mid$(mi$, instr(mi$, chr$(0)) + 1)
  1961.  
  1962.     goto [inputLoop]
  1963.  
  1964.  
  1965. [acceptMenuItemProps]   'Perform action for the button named 'acceptMenuItemProps'
  1966.  
  1967.     'accept the edited menu item
  1968.     print #menuItems.name, "!contents?";
  1969.     input #menuItems.name, nResult$
  1970.     print #menuItems.branchLabel, "!contents?";
  1971.     input #menuItems.branchLabel, blResult$
  1972.  
  1973.     if nResult$ = "" or blResult$ = "" then notice "Bad menu item properties." : goto [inputLoop]
  1974.  
  1975.     blr$ = blResult$
  1976.     if left$(blResult$, 1) <> "[" then blResult$ = "[" + blResult$
  1977.     if right$(blResult$, 1) <> "]" then blResult$ = blResult$ + "]"
  1978.  
  1979.     if blr$ <> blResult$ then notice "Branch Label was " + blr$ + ", defaulting to " + blResult$
  1980.  
  1981.     menuItem$(result - 1, menuItemIndex - 1) = nResult$ + chr$(0) + blResult$
  1982.     menuItemLocal$(menuItemIndex - 1) = nResult$ + " -> " + blResult$
  1983.  
  1984.     close #menuItems
  1985.     editMenuItemIsOpen = 0
  1986.  
  1987.     print #editMenu.menuItems, "reload"
  1988.  
  1989.     goto [inputLoop]
  1990.  
  1991.  
  1992. [cancelMenuItemProps]   'Perform action for the button named 'cancelMenuItemProps'
  1993.  
  1994.     'close the window
  1995.     gosub [closeEditMenuItem]
  1996.     goto [inputLoop]
  1997.  
  1998.  
  1999. [closeEditMenuItem]   'close the window before opening it again
  2000.  
  2001.     'close the window
  2002.     close #menuItems
  2003.     if editMenuItemAction$ = "ADD" then menuItemCount(result - 1) = menuItemCount(result - 1) - 1
  2004.     editMenuItemIsOpen = 0
  2005.     return
  2006.  
  2007.  
  2008. [formIsModified]    'the form has been modified, offer to save
  2009.  
  2010.     isModified = 0 ' set the isModified flag to be 0
  2011.     if objectCount < 2 then return  ' if there are no objects, don't offer to save form
  2012.     confirm "Save changes to " + formName$ + "?"; answer$
  2013.     if answer$ = "yes" then gosub [saveFormSubroutine]
  2014.  
  2015.     return
  2016.  
  2017.  
  2018. [settingsDialog]    'edit the settings for FreeForm
  2019.  
  2020.     WindowWidth = 336
  2021.     WindowHeight = 165
  2022.  
  2023.     checkbox #settings.creationInspect, "Inspect each control when created", [creationInspectSet], [creationInspectClear], 22, 16, 280, 19
  2024.     checkbox #settings.displayOrdering, "Display control ordering", [displayOrderingSet], [displayOrderingReset], 22, 36, 208, 19
  2025.     button #settings, "Accept", [settingsAccept], UL, 254, 71
  2026.     button #settings, "Cancel", [settingsCancel], UL, 254, 101
  2027.     open "Settings" for dialog_modal as #settings
  2028.     print #settings, "trapclose [settingsCancel]"
  2029.  
  2030.     createInspectValue = createInspect
  2031.     if createInspect > 0 then print #settings.creationInspect, "set"
  2032.     displayOrderingValue = displayOrdering
  2033.     if displayOrdering > 0 then print #settings.displayOrdering, "set"
  2034.  
  2035.  
  2036. [settings.inputLoop]   'wait here for input event
  2037.     input aVar$
  2038.     goto [settings.inputLoop]
  2039.  
  2040.  
  2041.  
  2042. [creationInspectSet]   'set value for inspect on create
  2043.  
  2044.     createInspectValue = 1
  2045.  
  2046.     goto [settings.inputLoop]
  2047.  
  2048.  
  2049. [creationInspectClear]   'set value for no inspect on create
  2050.  
  2051.     createInspectValue = 0
  2052.  
  2053.     goto [settings.inputLoop]
  2054.  
  2055.  
  2056. [displayOrderingSet]   'set value for displaying of control ordering
  2057.  
  2058.     displayOrderingValue = 1
  2059.  
  2060.     goto [settings.inputLoop]
  2061.  
  2062.  
  2063. [displayOrderingReset]   'set value for non-displaying of control ordering
  2064.  
  2065.     displayOrderingValue = 0
  2066.  
  2067.     goto [settings.inputLoop]
  2068.  
  2069.  
  2070. [settingsAccept]   'accept the settings
  2071.  
  2072.     createInspect = createInspectValue
  2073.     displayOrdering = displayOrderingValue
  2074.     close #settings
  2075.     gosub [redrawAll]
  2076.  
  2077.     goto [inputLoop]
  2078.  
  2079.  
  2080. [settingsCancel]   'discard any settings changes
  2081.  
  2082.     close #settings
  2083.  
  2084.     goto [settings.inputLoop]
  2085.  
  2086.  
  2087.  
  2088. [loadIniFile]   'load the user preferences
  2089.  
  2090.     open "fflite.ini" for input as #ini
  2091.     if eof(#ini) then close #ini : gosub [saveIniFile] : return
  2092.  
  2093.     input #ini, xInterval   'snap to x
  2094.     input #ini, yInterval   'snap to y
  2095.     input #ini, snapOn      'snap to on/off
  2096.     input #ini, createInspect 'inspect each control when created
  2097.     input #ini, displayOrdering 'display control ordering
  2098.  
  2099.     close #ini
  2100.  
  2101.     return
  2102.  
  2103.  
  2104. [saveIniFile]   'save the user preferences
  2105.  
  2106.     open "fflite.ini" for output as #ini
  2107.  
  2108.     print #ini, xInterval
  2109.     print #ini, yInterval
  2110.     print #ini, snapOn
  2111.     print #ini, createInspect
  2112.     print #ini, displayOrdering
  2113.  
  2114.     close #ini
  2115.  
  2116.     return
  2117.  
  2118.  
  2119. [quit]   'exit Freeform
  2120.  
  2121.     if isModified = 1 then gosub [formIsModified]
  2122.  
  2123.     'quit freeform
  2124.     gosub [saveIniFile]
  2125.     close #form
  2126.     if codeIsOpen then close #code
  2127.  
  2128. end
  2129.  
  2130.  
  2131.