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