home *** CD-ROM | disk | FTP | other *** search
- '***********************************************************************
- ' FormDev: Generate.RLZ
- '
- ' Copyright ⌐ 1991-1992 Computer Associates International, Inc.
- ' All rights reserved.
- '
- '***********************************************************************
-
- FUNC FDLogStr (logNum)
- '
- ' FAST append string s to Log #logNum.
- '
- 'WARNING: Use this routine only if you're sure the carriage returns and linefeeds
- 'are all OK. If you are sure, this routine is a LOT FASTER than:
- ' PRINT #logNum; s
- 'since the PRINT statement guarantees proper carriage return handling.
-
- LOCAL oldLen, hwt
- LOCAL WM_USER, EM_SETSEL, EM_REPLACESEL
-
- EXTERNAL "User" PROC SendMessage (word, word, word, pointer)
- WM_USER = 1024
- EM_SETSEL = (WM_USER + 1)
- EM_REPLACESEL = (WM_USER + 18)
-
- oldLen = LogQSize
- hwt = LogQ(_Hwnd)
- SendMessage(hwt, EM_SETSEL, 0, Pointer(32767*2^16 + 32767))
- SendMessage(hwt, EM_REPLACESEL, 0, fdOutStr)
- IF oldLen + Len(fdOutStr) <> LogQSize THEN
- INPUT "Error writing generated code to Log.", "FormDev";
- RETURN 0
- END IF
- fdOutStr = ""
- RETURN 1
- END FUNC
-
-
- PROC FDOut (s)
- fdOutStr = fdOutStr + s + CRLF
- END PROC
-
-
- FUNC GenstrModifiers(n)
- LOCAL m1, m2, s
-
- SELECT CASE item.type[n]
- CASE _OptionButton, _CheckBox
- s = IF bitand(item.modval1[n], 2) THEN "_Notify, " ELSE ""
- RETURN sprint("; &P(0), P(0)", s, item.modval1[n] mod 2, item.modval1[n] \ 4)
- CASE _EditText
- IF item.modval1[n] = 0 THEN
- RETURN ""
- END IF
- s = ""
- IF bitand(item.modval1[n], 1) THEN
- s = s + " + _NoBorder"
- END IF
- IF bitand(item.modval1[n], 2) THEN
- s = s + " + _MultiLine"
- END IF
- IF bitand(item.modval1[n], 4) THEN
- s = s + " + _Notify"
- END IF
- RETURN "; " + Mid$(s, 3)
- CASE _Chart
- IF item.modval1[n] THEN
- RETURN sprint("; P(0)", item.modval1[n])
- ELSE
- RETURN ""
- END IF
- CASE _ListBox, _ComboBox, _DropDownList, _DropDownCombo
- SELECT CASE item.modval1[n] mod 4
- CASE 0
- m1 = ""
- CASE 1
- m1 = "_Sorted"
- CASE 2
- m1 = "_Notify"
- CASE 3
- m1 = "_Sorted + _Notify"
- END SELECT
- SELECT CASE item.modval1[n] \ 4
- CASE _ListFiles
- m2 = ""
- IF bitand(item.modval2[n], 2) THEN
- m2 = m2 + " + _NoFiles"
- END IF
- IF bitand(item.modval2[n], 4) THEN
- m2 = m2 + " + _Drives"
- END IF
- IF bitand(item.modval2[n], 8) THEN
- m2 = m2 + " + _SubDirs"
- END IF
- IF m2 = "" THEN
- m2 = "_NormFiles"
- ELSE
- m2 = Mid$(m2, 3)
- END IF
- m2 = "_ListFiles, " + m2 + ", ""*.*"""
- CASE _ListVars
- m2 = ""
- IF bitand(item.modval2[n], _Real) THEN
- m2 = m2 + " + _Real"
- END IF
- IF bitand(item.modval2[n], _Alpha) THEN
- m2 = m2 + " + _Alpha"
- END IF
- IF bitand(item.modval2[n], _DateTime) THEN
- m2 = m2 + " + _DateTime"
- END IF
- IF bitand(item.modval2[n], _Array) THEN
- m2 = m2 + " + _Array"
- END IF
- IF bitand(item.modval2[n], _Scalar) THEN
- m2 = m2 + " + _Scalar"
- END IF
- IF m2 = "" THEN
- m2 = "0"
- ELSE
- m2 = Mid$(m2, 3)
- END IF
- m2 = "_ListVars, " + m2
- CASE _ListFams
- m2 = "_ListFams"
- CASE _ListFonts
- m2 = "_ListFonts"
- CASE _ListFontSizes
- m2 = "_ListFontSizes, """ + item.modstr[n] + """"
- CASE 15
- m2 = item.modstr[n]
- END SELECT
- IF m1 = "" AND m2 = "" THEN
- RETURN ""
- ELSEIF m1 = "" THEN
- RETURN "; " + m2
- ELSEIF m2 = "" THEN
- RETURN "; " + m1
- ELSE
- RETURN "; "+ m1 + ", " + m2
- END IF
- CASE ELSE
- RETURN ""
- END SELECT
- END FUNC
-
- FUNC GenstrStyle(style)
- LOCAL s
-
- IF style = 0 THEN
- RETURN ""
- END IF
- s = "X"
- s = s + IF bitand(style, _Close) THEN " + _Close" ELSE ""
- s = s + IF bitand(style, _Frame) THEN " + _Frame" ELSE ""
- s = s + IF bitand(style, _Size) THEN " + _Size" ELSE ""
- s = s + IF bitand(style, _Title) THEN " + _Title" ELSE ""
- s = s + IF bitand(style, _Minimize) THEN " + _Minimize" ELSE ""
- s = s + IF bitand(style, _ContextEnter) THEN " + _ContextEnter" ELSE ""
- s = s + IF bitand(style, _HotClick) THEN " + _HotClick" ELSE ""
- RETURN SubStr$(s, "X +", ",")
- END FUNC
-
- FUNC GenstrFontstyle(style)
- LOCAL s, n
-
- n = StrToNum(style)
- s = IF bitand(n, _Bold) THEN " + _Bold" ELSE ""
- s = s + IF bitand(n, _Italics) THEN " + _Italics" ELSE ""
- s = s + IF bitand(n, _Underline) THEN " + _Underline" ELSE ""
- s = s + IF bitand(n, _Strikeout) THEN " + _Strikeout" ELSE ""
- IF s = "" THEN
- RETURN ""
- ELSE
- RETURN ", " + Mid$(s, 4)
- END IF
- END FUNC
-
- FUNC GenstrSV(specval, rawval, fmtstr, unitstr)
- IF specval THEN
- SELECT CASE specval
- CASE _Left
- RETURN "_Left"
- CASE _Right
- RETURN "_Right"
- CASE _Top
- RETURN "_Top"
- CASE _Bottom
- RETURN "_Bottom"
- CASE _Center
- RETURN "_Center"
- CASE _Default
- RETURN "_Default"
- END SELECT
- ELSE
- RETURN sprint(fmtstr + " &", rawval, unitstr)
- END IF
- END FUNC
-
- PROC GenerateFontNew(tabs)
- LOCAL i, s
-
- IF Sum(fonts.refs) = 0 THEN
- EXIT PROC
- END IF
- FDOut(tabs + "'Define the fonts")
- s = "LOCAL "
- FOR i = 2 to EndValid(fonts.name)
- IF fonts.name[i] <> "" THEN
- s = s + Sprint("fontP(0), ", i)
- END IF
- NEXT i
- FDOut(tabs + Left$(s, Len(s) - 2))
- FOR i = 2 to EndValid(fonts.name)
- IF fonts.name[i] <> "" THEN
- FDOut(tabs + sprint("fontP(0) = FontQUnique", i))
- FDOut(tabs + sprint("FontNew(fontP(0); ""&"", &&)", i, fonts.name[i], fonts.size[i], GenstrFontstyle(fonts.style[i])))
- END IF
- NEXT i
- FDOut("")
- END PROC
-
- PROC GenerateFontClose(tabs)
- LOCAL i
-
- IF Sum(fonts.refs) = 0 THEN
- EXIT PROC
- END IF
- FDOut("" + CRLF + "'Close the fonts")
- FOR i = 2 to EndValid(fonts.name)
- IF fonts.name[i] <> "" THEN
- FDOut(tabs + sprint("FontSelect(fontP(0))", i))
- FDOut(tabs + "FontControl(_Close)")
- END IF
- NEXT i
- END PROC
-
-
- PROC GenerateCCLibRun
- ' DigitalClock?
- FOR i = 1 TO fdNumItems
- IF item.type[i] < 0 THEN
- FDOut("RUN ""CCLib1""" + CRLF)
- EXIT PROC
- END IF
- NEXT
- END PROC
-
-
- PROC GenerateHeader(saveflags)
- LOCAL list, i
-
- FDOut("'****************************************")
- FDOut("'** FormName: " + theform.name)
- FDOut("'****************************************")
- FDOut("")
-
- GenerateCCLibRun
-
- IF NOT(bitand(saveflags, 16)) THEN
- FDOut("IF QVar(%%flag" + theform.name + ", _Defined) THEN")
- FDOut(" EXIT MACRO")
- FDOut("END IF")
- FDOut("%%flag" + theform.name + " = 1")
- FDOut("")
- END IF
-
- IF theform.bitmapdir <> "" THEN
- FDOut("SetSys(_LoadDir, QSys(_LoadDir) + "";"" + """ + theform.bitmapdir + """)")
- FDOut("")
- END IF
-
- ListOfLinks(theform.init, list)
- FOR i = 1 to fdNumItems
- IF item.code[i] <> "" THEN
- ListOfLinks(item.code[i], list)
- END IF
- NEXT i
- IF EndValid(list) THEN
- IF theform.linkdir <> "" THEN
- FDOut("SetSys(_MacroDir, QSys(_MacroDir) + "";"" + """ + theform.linkdir + """)")
- END IF
- FOR i = 1 to EndValid(list)
- FDOut("RUN """ + list[i] + """")
- NEXT i
- FDOut("")
- END IF
- END PROC
-
- FUNC GenColor(cPacked, asWhich)
- LOCAL c
-
- c = ColorUnpack(cPacked)
- IF QVar(c, _Scalar) THEN
- RETURN Sprint("FormSetColor(__&; &)", ColorNames[c], asWhich)
- ELSE
- RETURN Sprint("FormSetColor(P(-3), P(-3), P(-3); &)", c[1], c[2], c[3], asWhich)
- END IF
- END FUNC
-
-
- PROC GenerateMakeform(fGen)
- LOCAL s, fs, fmt, i, tab
- LOCAL fontstr, leftstr, topstr, widthstr, heightstr, modstr, textstr, typestr
- LOCAL fieldcolorlast, textcolorlast
-
- tab = IF fGen THEN " " ELSE ""
- IF fGen THEN
- FDOut("PROC Make"+ theform.name)
- ELSE
- IF theform.bitmapdir <> "" THEN
- FDOut("SetSys(_LoadDir, QSys(_LoadDir) + "";"" + """ + theform.bitmapdir + """)")
- FDOut("")
- END IF
- END IF
- GenerateFontNew(tab)
- FDOut(tab + "form" + theform.name + " = FormQUnique")
- FDOut(SPRINT(tab + "FormNew(form" + theform.name + "; ""&""&)", theform.title, GenstrStyle(theform.style)))
- IF QVar(theform.bgcolor, _Array) THEN
- FDOut(tab + GenColor(ColorPack(theform.bgcolor), "_Background"))
- ELSE
- IF theform.bgcolor <> _White THEN
- FDOut(tab + GenColor(ColorPack(theform.bgcolor), "_Background"))
- END IF
- END IF
- fs = UnitFormatStr(theform.units)
- fmt = Sprint("FormControl(____Size; & _&, & _&, & _&, & _&)", fs, fs, fs, fs)
- s = UnitShortStr(theform.units)
- FDOut(SPRINT(tab + fmt, theform.rawleft, s, theform.rawtop, s, theform.rawwidth, s, theform.rawheight, s))
- FormSelect(fdMain)
- ItemsLocateAll
- ItemsIntoRaw
- IF theform.itemunits = 1 THEN
- s = UnitShortStr(theform.units)
- fs = UnitFormatStr(theform.units)
- ELSE
- s = UnitShortStr(2) 'percent
- fs = UnitFormatStr(2)
- END IF
- textcolorlast = ColorPack(_Black)
- fieldcolorlast = ColorPack(_White)
- FOR i = 1 TO fdNumItems
- IF item.textcolor[i] <> textcolorlast THEN
- FDOut(tab + GenColor(item.textcolor[i], "_Text"))
- textcolorlast = item.textcolor[i]
- END IF
- IF item.fieldcolor[i] <> fieldcolorlast THEN
- FDOut(tab + GenColor(item.fieldcolor[i], "_Field"))
- fieldcolorlast = item.fieldcolor[i]
- END IF
- textstr = item.text[i]
- textstr = IF Left$(textstr, 1) = "=" THEN Right$(textstr, Len(textstr) - 1) ELSE """" + textstr + """"
- fontstr = IF item.font[i] THEN sprint("fontP(0), ", item.font[i]) else ""
- leftstr = GenstrSV(item.leftsv[i], item.left[i], fs, s)
- topstr = GenstrSV(item.topsv[i], item.top[i], fs, s)
- widthstr = GenstrSV(item.widthsv[i], item.width[i], fs, s)
- heightstr = GenstrSV(item.heightsv[i], item.height[i], fs, s)
- modstr = GenstrModifiers(i)
- typestr = ItemNames[FirstMatch(ItemNums, item.type[i])]
- FDOut(SPRINT(tab + "FormSetObject(P(0), __&, &, &&, &, &, &&)", ItemID(i), typestr, textstr, fontstr, leftstr, topstr, widthstr, heightstr, modstr))
- NEXT i
- IF textcolorlast <> ColorPack(_Black) THEN
- FDOut(tab + "FormSetColor(_Black; _Text)")
- END IF
- IF fieldcolorlast <> ColorPack(_White) THEN
- FDOut(tab + "FormSetColor(_White; _Field)")
- END IF
- IF theform.type = 50 AND fGen THEN
- FDOut(" FormSetProc(formproc" + theform.name + ")")
- END IF
- GenerateFontClose(tab)
- ItemsIntoPixels
- IF theform.init <> "" THEN
- FDOut(CRLF + tab + "' Initialize the form" + CRLF + SubLinks(theform.init, tab))
- END IF
- IF fGen THEN
- FDOut("END PROC")
- END IF
- FDOut("")
- END PROC
-
- PROC GenerateSelect(tab, caseWhat)
- LOCAL i
-
- FDOut(tab + "SELECT CASE " + caseWhat)
- FOR i = 1 TO fdNumItems
- IF item.code[i] <> "" THEN
- FDOut(tab + "CASE " + NumToStr(ItemID(i)) + " '" + item.text[i])
- FDOut(SubLinks(item.code[i], tab + " "))
- END IF
- NEXT i
- FDOut(tab + "END SELECT")
- END PROC
-
- FUNC GenerateFormloop
- FDOut("FUNC Modal" + theform.name)
- FDOut(" FormSelect(form" + theform.name + ")")
- FDOut(" LOOP")
- GenerateSelect(" ", "FormWait")
- FDOut(" END LOOP")
- FDOut(" FormSelect(form" + theform.name + ")")
- FDOut(" FormControl(_Close)")
- FDOut(" RETURN 1")
- FDOut("END FUNC")
- RETURN 1
- END FUNC
-
- FUNC GenerateFormproc
- FDOut("PROC formproc" + theform.name + "(params)")
- FDOut(" FormSelect(form" + theform.name + ")")
- GenerateSelect(" ", "params[_ItemNum]")
- FDOut("END PROC")
- RETURN 1
- END FUNC
-
- PROC GenerateMain
- FDOut(CRLF + "'Main program" + CRLF)
- IF theform.type = 50 THEN
- FDOut("Make" + theform.name)
- FDOut("FormSelect(form" + theform.name + ")")
- FDOut("FormControl(_Show)")
- ELSE
- FDOut("Make" + theform.name)
- FDOut("dummy = Modal" + theform.name)
- END IF
- END PROC
-
- FUNC GenerateCode(fdOutLog, saveflags)
- LOCAL success, CRLF, fdOutStr
-
- CRLF = CHR$(13) + CHR$(10)
- fdOutStr = ""
- IF bitand(saveflags, 4) THEN
- GenerateCCLibRun
- GenerateMakeform(0)
- FDOut("FormControl(_Show)")
- success = 1
- ELSE
- GenerateHeader(saveflags)
- GenerateMakeform(1)
- IF theform.type = 50 THEN
- success = GenerateFormproc
- ELSE
- success = GenerateFormloop
- END IF
- IF success AND bitand(saveflags, 16) THEN
- GenerateMain
- END IF
- END IF
- IF success THEN
- success = FDLogStr(fdOutLog)
- END IF
- RETURN success
- END FUNC
-