home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / scr2frg.zip / SCR2FRG.COD next >
Text File  |  1990-05-08  |  17KB  |  491 lines

  1. //
  2. // Module Name: SCR2FRG.COD ver. 1.1
  3. // 1.1 fixes height problem of boxes appearing on screen 2 or higher
  4. //
  5.  
  6. FORMAT to REPORT (.scr -> .frg) File Template ver. 1.01
  7. -------------------------------------------------------
  8. Written by Bryan Flynn, Ashton-Tate Software Support
  9.  
  10. Description: This file will convert .SCR files to .FRG files,
  11.              Enabling the user to print Screen Forms with the
  12.              REPORT FORM command.  This special .GEN file will
  13.              replace the default FORM.GEN that is used to generate
  14.              screen forms.
  15.  
  16. Notes: o The SUMMARY option is not supported and has no effect if specified.
  17.        o ".PB" in the first column of a screen line will insert a page break
  18.          at that point.
  19.        o The screen form (.SCR) must be regenerated, using this .GEN
  20.          file, for the .FRG to be created.  Note that when modifying
  21.          the screen, pressing <Ctrl-End> will force regeneration.
  22.  
  23. For further details on the use of SCR2FRG.GEN, see the March 1990 issue
  24. of Ashton-Tate's TechNotes magazine.
  25.  
  26. {
  27. include "form.def";    // Form selectors
  28. include "builtin.def"; // Builtin functions
  29. //
  30. enum wrong_class = "This .GEN file can only be used on SCREEN FORM files.  ",
  31.      window_limit = 26;
  32. //
  33.  
  34. if Frame_class != form then // We are not processing a form object
  35.   pause(wrong_class + any_key);
  36.   goto NoGen;
  37. endif
  38.  
  39. var  frg_name,   // Format file name
  40.      crlf,       // line feed
  41.      temp,       // tempory work variables
  42.      line_cnt,   // Count for total lines processed
  43.      default_drv,// dBASE default drive
  44.      scrn_size,  // Screen size when generation starts
  45.      scrn_size2, // = 43 or 25
  46.      display,    // Type of display screen we are on
  47.      dB_status,  // dBASE status bar (on|off) before entering designer
  48.      maxrow,     // Used for blank lines
  49.      box_ht,     // HEIGHT of DEFINEd BOXes
  50.      is_memo,    // How many memos w/ windows are currently being printed
  51.      no_AT,      // Don't print AT location if memo marker
  52.      avail_stck, // Stack to hold which set of memo variables is available
  53.      used_stck,  // Stack to hold which set of memo variables is being used
  54. // memo#_1 = Holds expression for printout of memos
  55. // memo#_2 = What line of memo to print
  56. // memo#_3 = How many lines of memo to print
  57. // Screen can have up to 26 memo windows next to each other at any one time.
  58. // Arrays not supported in the Template Language
  59. memo1_1,  memo1_2,  memo1_3, memo2_1,  memo2_2,  memo2_3, memo3_1,  memo3_2,  memo3_3,
  60. memo4_1,  memo4_2,  memo4_3, memo5_1,  memo5_2,  memo5_3, memo6_1,  memo6_2,  memo6_3,
  61. memo7_1,  memo7_2,  memo7_3, memo8_1,  memo8_2,  memo8_3, memo9_1,  memo9_2,  memo9_3,
  62. memo10_1, memo10_2, memo10_3,memo11_1, memo11_2, memo11_3,memo12_1, memo12_2, memo12_3,
  63. memo13_1, memo13_2, memo13_3,memo14_1, memo14_2, memo14_3,memo15_1, memo15_2, memo15_3,
  64. memo16_1, memo16_2, memo16_3,memo17_1, memo17_2, memo17_3,memo18_1, memo18_2, memo18_3,
  65. memo19_1, memo19_2, memo19_3,memo20_1, memo20_2, memo20_3,memo21_1, memo21_2, memo21_3,
  66. memo22_1, memo22_2, memo22_3,memo23_1, memo23_2, memo23_3,memo24_1, memo24_2, memo24_3,
  67. memo25_1, memo25_2, memo25_3,memo26_1, memo26_2, memo26_3;
  68.  
  69.  
  70. //-----------------------------------------------
  71. // Assign default values to some of the variables
  72. //-----------------------------------------------
  73. is_memo = 0;
  74. avail_stck=" 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21," +
  75.            "22,23,24,25,26,";
  76. used_stck="";
  77.  
  78. crlf = chr(10);
  79. temp = "";
  80. line_cnt = 0;
  81.  
  82. //-------------------------------
  83. // Test screen size if display > 2 screen is 43 lines
  84. //-------------------------------
  85. display = numset(_flgcolor);
  86. if display > ega25 then scrn_size = 39 else scrn_size = 21 endif;
  87. scrn_size2 = scrn_size + 4;
  88. dB_status = numset(_flgstatus);  // _flgstatus defined in BUILTIN.DEF
  89. if scrn_size == 21 and !dB_status then
  90.     scrn_size = 24;
  91. endif
  92. //else
  93. if scrn_size == 39 and !dB_status then // STATUS is off
  94.    scrn_size = 42;
  95. endif
  96.  
  97. //-------------------------------
  98. // Create .FRG file
  99. //-------------------------------
  100. default_drv = strset(_defdrive);  // Grab default drive from dBASE
  101.  
  102. frg_name = FRAME_PATH + NAME;
  103. if not fileok(frg_name) then
  104.    if !default_drv then
  105.       frg_name = NAME;
  106.    else
  107.       frg_name = default_drv + ":" + NAME;
  108.    endif
  109. endif
  110. frg_name = upper(frg_name);
  111. if not create(frg_name+".FRG") then
  112.    pause(fileroot(frg_name) +".FRG" + read_only + any_key);
  113.    goto nogen;
  114. endif
  115. if not fileexist(frg_name+".FMT") then
  116.    cursor_pos(2, 1);
  117.    cput("You don't have a FORMAT file by this name.  Ignore 'File does not exist' error");
  118. endif
  119. }
  120. //
  121. *--- Name....: {filename(frg_name)}FRG
  122. *--- Date....: {ltrim(SUBSTR(date(),1,8))}
  123. *--- Version.: dBASE IV, Format {Frame_ver}.0x
  124. *
  125. *--- Parameters
  126. PARAMETERS m_NoEject, m_Plain, m_Summary, m_Heading, m_Extra
  127. *--- NOT USED: m_Summary
  128. *--- The first three parameters are of type logical.
  129. *--- The fourth parameter is a string.  The fifth is extra.
  130. PRIVATE _peject, _wrap, _box, m_Talk, m_Width, m_Prntflg, m_PSpace, m_Atline
  131.  
  132. *--- Report file initialization code --------------------------------------------
  133.  
  134. *--- Test for no records found
  135. IF EOF() .OR. .NOT. FOUND()
  136.    RETURN
  137. ENDIF
  138.  
  139. *--- Turn wrap mode off
  140. _wrap = .F.
  141.  
  142. *--- Set _box to true so DEFINEd BOXes will print
  143. _box = .T.
  144.  
  145. *--- Start printing at line zero of page.
  146. _plineno=0
  147.  
  148. *--- Set NOEJECT parameter of the REPORT FORM command.
  149. if m_NoEject
  150.    IF _peject = "BEFORE"
  151.       _peject = "NONE"
  152.    ENDIF
  153.    IF _peject = "BOTH"
  154.       _peject = "AFTER"
  155.    ENDIF
  156. ENDIF
  157.  
  158. *--- Set-up environment
  159. ON ESCAPE DO PrnAbort    &&Do procedure PRNABORT if ESC is pressed when printing.
  160. IF SET("TALK") = "ON"    &&Save status of TALK so it can be restored later.
  161.    SET TALK OFF
  162.    m_Talk = "ON"
  163. ELSE
  164.    m_Talk = "OFF"
  165. ENDIF
  166. m_Width = SET("MEMOWIDTH")    &&Save current memowidth setting.
  167. SET MEMOWIDTH TO 65           &&When printing memos, memowidth must be 65.
  168. m_Prntflg = .T.               &&Set to FALSE when user presses ESCAPE.
  169.  
  170. *--- Set up when to page break.
  171. IF _pspacing > 1
  172.    m_Atline= _plength - (_pspacing + 1)
  173. ELSE
  174.    m_Atline= _plength - 1
  175. ENDIF
  176. ON PAGE AT LINE m_Atline EJECT PAGE
  177.  
  178. *--- Print Report.
  179. PRINTJOB
  180.  
  181.    IF .NOT. m_Plain .AND. LEN(m_Heading) > 0
  182.       ?? m_Heading FUNCTION "I;V80"
  183.       ?
  184.    ENDIF
  185.  
  186.    ON PAGE AT LINE m_Atline DO Pgfoot
  187.  
  188.    *--- File Loop
  189.    DO WHILE m_Prntflg    && FOUND() .AND. .NOT. EOF() .AND. m_Prntflg
  190.       DO __Detail
  191.       CONTINUE
  192.       IF FOUND() .AND. .NOT. EOF() .AND. m_Prntflg .AND. _pageno <= _pepage
  193.          EJECT PAGE      && EJECT occurrs after each record
  194.       ELSE               && Don't want to print HEADING after last record
  195.          ON PAGE
  196.          EJECT PAGE
  197.          EXIT
  198.       ENDIF
  199.    ENDDO
  200.  
  201.    IF .NOT. m_Prntflg    && User pressed the escape key while printing
  202.       DO RESET
  203.       RETURN
  204.    ENDIF
  205.  
  206. ENDPRINTJOB
  207.  
  208. DO Reset
  209. RETURN
  210. *--- EOP: {filename(frg_name)}FRG
  211.  
  212. *--- Executed when user presses ESCAPE while report is running.
  213. PROCEDURE Prnabort
  214.    m_Prntflg = .F.
  215. RETURN
  216. *--- EOP: Prnabort
  217.  
  218. *--- Reset dBASE environment prior to calling report.
  219. *--- Note that any ON ESCAPE or ON PAGE  routine user had before
  220. *--- running the REPORT FORM command will be cleared.
  221. PROCEDURE Reset
  222.    SET TALK &m_Talk
  223.    SET MEMOWIDTH TO m_Width
  224.    ON ESCAPE
  225. RETURN
  226. *--- EOP: Reset
  227.  
  228. PROCEDURE __Detail
  229. {maxrow = line_cnt = 0;
  230.  FOREACH ELEMENT form_object
  231.    if ROW_POSITN - line_cnt > scrn_size then
  232.       line_cnt = line_cnt + scrn_size + 1;
  233.    endif
  234.    nextline:
  235.    if maxrow < ROW_POSITN then
  236.       outmemo();}
  237.    ?
  238. {     ++maxrow;
  239.       goto nextline;
  240.    endif
  241.    no_AT=0;   // "?? ... AT ## " should not be outputted if item is a memo with a window
  242.    case ELEMENT_TYPE of
  243.       @TEXT_ELEMENT:
  244.          if asc(TEXT_ITEM) < 32 then    // Control character - use CHR()
  245.             if len(TEXT_ITEM) == 1 then}
  246.    ?? CHR({asc(TEXT_ITEM)}) AT {nul2zero(COL_POSITN)}
  247. {           else}
  248.    ?? REPLICATE(CHR({asc(TEXT_ITEM)}), {len(TEXT_ITEM)}) AT {nul2zero(COL_POSITN)}
  249. {           endif
  250.          else
  251.             if nul2zero(COL_POSITN) == 0 and len(TEXT_ITEM) >=3 and
  252.               upper(substr(TEXT_ITEM, 1, 3)) == ".PB" then
  253.                 // User specified page break}
  254.    EJECT PAGE
  255. {              if len(TEXT_ITEM) > 3 then}
  256.    ?? "{substr(TEXT_ITEM, 4)}" AT 3
  257.    {           endif
  258.             else  // no page break specified}
  259.    ?? "{TEXT_ITEM}" AT {nul2zero(COL_POSITN)}
  260. {           endif
  261.          endif
  262.       @BOX_ELEMENT:
  263.          outbox(form_object)
  264.       @FLD_ELEMENT:
  265.          case FLD_FIELDTYPE of
  266.             calc:}
  267. * Calculated field - {FLD_DESCRIPT}
  268.    ?? \
  269. {              foreach FLD_EXPRESSION fcursor in form_object
  270.                   FLD_EXPRESSION}
  271. {              next} \
  272. {           dbf:
  273.                if not (chr(FLD_VALUE_TYPE) == "M") then //Not type memo}
  274.    ?? \
  275. {                 lower(FLD_FIELDNAME)} \
  276. {              else //Item is memo field
  277.                   if (FLD_MEM_TYP == 2) or
  278.                      (is_memo == window_limit) then //No window for memo}
  279.    ?? IIF(LEN({FLD_FIELDNAME}) = 0, "memo", "MEMO") \
  280. {                 else //Memo is in a window
  281.                      ++is_memo;
  282.  
  283.                      // Determine how wide memo line should be
  284.                      if BOX_WIDTH - 2 > 65 then
  285.                         temp = 65;
  286.                      else
  287.                         temp = BOX_WIDTH - 2;
  288.                      endif
  289.  
  290.                      // Expression used when outputting memo in a window
  291.                      // TEMP is assigned to memo#_1 in find_empty_memo()
  292.                      temp = FLD_FIELDNAME + space(10-len(alltrim(FLD_FIELDNAME))) +
  293.                             alltrim(str(temp)) + "), '') AT " + alltrim(str(BOX_LEFT + 1));
  294.                      outbox(form_object)    // Define memo window box
  295.                      find_empty_memo();     // Assign memo expression
  296.  
  297.                      no_AT=1;    // Don't print AT location
  298.                   endif
  299.                endif
  300.             memvar:}
  301. * Memory variable
  302.    ?? \
  303. {              lower("m->"+FLD_FIELDNAME)} \
  304. {        endcase //FLD_FLDTYPE of}\
  305. {        if not no_AT}AT {COL_POSITN} {endif}\
  306. {        if FLD_TEMPLATE and not (chr(FLD_VALUE_TYPE) == "M") then}
  307. PICTURE "{  if FLD_PICFUN and not AT("M",FLD_PICFUN) then
  308.                if not at("S",FLD_PICFUN) then}\
  309. @{FLD_PICFUN} {FLD_TEMPLATE}"
  310. {              else    //Scroll field
  311.                 substr(FLD_TEMPLATE,1,FLD_PIC_SCROLL)}"
  312. {              endif
  313.             else    //No picture clause, just template}
  314. {FLD_TEMPLATE}"
  315. {           endif
  316.          else}
  317. {           if not no_AT then print(crlf) endif  //If memo marker or no template
  318.          endif}
  319. {     otherwise:  //Non ELEMENT
  320.    endcase  //ELEMENT of
  321. next form_object;
  322.    outmemo();//fill out memo box
  323.  if ((maxrow + 1) % scrn_size2) != 0 then
  324.    //If not on last line of screen, finish "??" line from the above FOREACH loop.}
  325.    ?
  326. {  ++maxrow;
  327.    nextline2:
  328.    if ((maxrow + 1) % scrn_size2) != 0 then
  329.      // If not on last line of screen, fill out remainder of screen with ?'s
  330.       outmemo();}
  331.    ?
  332. {     ++maxrow;
  333.       goto nextline2;
  334.    endif
  335.  endif}
  336. RETURN
  337. *--- EOP: __Detail
  338.  
  339. PROCEDURE Pgfoot
  340.    EJECT PAGE
  341.    IF .NOT. m_Plain .AND. LEN(m_Heading) > 0
  342.       ?? m_Heading FUNCTION "I;V80"
  343.       ?
  344.    ENDIF
  345. RETURN
  346. *--- EOP: Pgfoot
  347.  
  348. {fileerase(frg_name+".FRO");
  349.  nogen:
  350.  return 0;
  351.  
  352. //---------------------------------------
  353. // Template user defined functions below
  354. //---------------------------------------
  355.  
  356. define nul2zero(numbr);
  357.    // If number is null and we are expecting a zero - convert the null to 0
  358.    if !numbr then numbr=0 endif;
  359.    return numbr;
  360. enddef
  361.  
  362. define outbox(cur)
  363.    var temp;}
  364.    DEFINE BOX FROM {nul2zero(cur.BOX_LEFT)} TO \
  365. {  nul2zero(cur.BOX_LEFT) + cur.BOX_WIDTH - 1} HEIGHT \
  366. {  temp = nul2zero(cur.BOX_TOP) + cur.BOX_HEIGHT - line_cnt - 1;
  367.    if temp > scrn_size then
  368.       box_ht = (scrn_size - cur.BOX_TOP + 1);
  369.    else
  370.       box_ht = cur.BOX_HEIGHT;
  371.    endif
  372.    // box_ht is defined in main program and is needed if the box is
  373.    // to be used with a memo window
  374.    box_ht} \
  375. {     case cur.BOX_TYPE of
  376.          0:  // Single}
  377. SINGLE
  378. {        1:  // Double}
  379. DOUBLE
  380. {        2:  // Defined}
  381. CHR({cur.BOX_SPECIAL_CHAR})
  382. {      endcase
  383. enddef
  384.  
  385. define outmemo()
  386.    // There can be up to 26 memo windows next to eachother in Screen Form
  387.    var temp_stck;
  388.    temp_stck = used_stck;
  389.    do while temp_stck
  390.       outmemo2(val(substr(temp_stck, 1, 2)))
  391.       temp_stck = substr(temp_stck, 4);
  392.    enddo
  393.    return;
  394. enddef
  395.  
  396. define outmemo2(whch_memo)
  397.    case whch_memo of
  398.        1: outmemo3(memo1_1, memo1_2, memo1_3, " 1")
  399.        2: outmemo3(memo2_1, memo2_2, memo2_3, " 2")
  400.        3: outmemo3(memo3_1, memo3_2, memo3_3, " 3")
  401.        4: outmemo3(memo4_1, memo4_2, memo4_3, " 4")
  402.        5: outmemo3(memo5_1, memo5_2, memo5_3, " 5")
  403.        6: outmemo3(memo6_1, memo6_2, memo6_3, " 6")
  404.        7: outmemo3(memo7_1, memo7_2, memo7_3, " 7")
  405.        8: outmemo3(memo8_1, memo8_2, memo8_3, " 8")
  406.        9: outmemo3(memo9_1, memo9_2, memo9_3, " 9")
  407.       10: outmemo3(memo10_1, memo10_2, memo10_3, "10")
  408.       11: outmemo3(memo11_1, memo11_2, memo11_3, "11")
  409.       12: outmemo3(memo12_1, memo12_2, memo12_3, "12")
  410.       13: outmemo3(memo13_1, memo13_2, memo13_3, "13")
  411.       14: outmemo3(memo14_1, memo14_2, memo14_3, "14")
  412.       15: outmemo3(memo15_1, memo15_2, memo15_3, "15")
  413.       16: outmemo3(memo16_1, memo16_2, memo16_3, "16")
  414.       17: outmemo3(memo17_1, memo17_2, memo17_3, "17")
  415.       18: outmemo3(memo18_1, memo18_2, memo18_3, "18")
  416.       19: outmemo3(memo19_1, memo19_2, memo19_3, "19")
  417.       20: outmemo3(memo20_1, memo20_2, memo20_3, "20")
  418.       21: outmemo3(memo21_1, memo21_2, memo21_3, "21")
  419.       22: outmemo3(memo22_1, memo22_2, memo22_3, "22")
  420.       23: outmemo3(memo23_1, memo23_2, memo23_3, "23")
  421.       24: outmemo3(memo24_1, memo24_2, memo24_3, "24")
  422.       25: outmemo3(memo25_1, memo25_2, memo25_3, "25")
  423.       26: outmemo3(memo26_1, memo26_2, memo26_3, "26")
  424.     endcase
  425.     return;
  426. enddef
  427.  
  428.  
  429. define outmemo3(expr, what_line, maximum_lines, whch_memo)
  430.    // Don't print out anything if printing top or bottom line of box
  431.    if (what_line != 1) and (what_line != maximum_lines) then}
  432.    ?? IIF('' <> MLINE({alltrim(substr(expr, 1, 10))}, {what_line - 1}), \
  433. SUBSTR(MLINE({alltrim(substr(expr, 1, 10))}, {what_line - 1}), 1, {substr(expr, 11)}
  434. {  endif
  435.    ++what_line;
  436.    if what_line > maximum_lines then    // Done printing memo
  437.       --is_memo;
  438.       // Take this reference off active stack
  439.       used_stck = substr(used_stck, 1, at(whch_memo, used_stck) - 1) +
  440.                   substr(used_stck, at(whch_memo, used_stck) + 3);
  441.       // Put this memo back on available stack so the corresponding memo
  442.       // variables can be used again.
  443.       avail_stck = whch_memo + "," + avail_stck;
  444.    endif
  445.    return;
  446. enddef
  447.  
  448. define assign_vals(expr, what_line, maximum_lines)
  449.    // Called when memo with window is encountered
  450.    expr = temp;     // temp is from main program
  451.    what_line = 1;   // First line to print of memo
  452.    maximum_lines = box_ht;
  453.    return;
  454. enddef
  455.  
  456. define find_empty_memo()
  457.    used_stck = substr(avail_stck, 1, 3) + used_stck;
  458.    avail_stck = substr(avail_stck, 4);
  459.    case val(substr(used_stck, 1, 2)) of
  460.        1: assign_vals(memo1_1, memo1_2, memo1_3)
  461.        2: assign_vals(memo2_1, memo2_2, memo2_3)
  462.        3: assign_vals(memo3_1, memo3_2, memo3_3)
  463.        4: assign_vals(memo4_1, memo4_2, memo4_3)
  464.        5: assign_vals(memo5_1, memo5_2, memo5_3)
  465.        6: assign_vals(memo6_1, memo6_2, memo6_3)
  466.        7: assign_vals(memo7_1, memo7_2, memo7_3)
  467.        8: assign_vals(memo8_1, memo8_2, memo8_3)
  468.        9: assign_vals(memo9_1, memo9_2, memo9_3)
  469.       10: assign_vals(memo10_1, memo10_2, memo10_3)
  470.       11: assign_vals(memo11_1, memo11_2, memo11_3)
  471.       12: assign_vals(memo12_1, memo12_2, memo12_3)
  472.       13: assign_vals(memo13_1, memo13_2, memo13_3)
  473.       14: assign_vals(memo14_1, memo14_2, memo14_3)
  474.       15: assign_vals(memo15_1, memo15_2, memo15_3)
  475.       16: assign_vals(memo16_1, memo16_2, memo16_3)
  476.       17: assign_vals(memo17_1, memo17_2, memo17_3)
  477.       18: assign_vals(memo18_1, memo18_2, memo18_3)
  478.       19: assign_vals(memo19_1, memo19_2, memo19_3)
  479.       20: assign_vals(memo20_1, memo20_2, memo20_3)
  480.       21: assign_vals(memo21_1, memo21_2, memo21_3)
  481.       22: assign_vals(memo22_1, memo22_2, memo22_3)
  482.       23: assign_vals(memo23_1, memo23_2, memo23_3)
  483.       24: assign_vals(memo24_1, memo24_2, memo24_3)
  484.       25: assign_vals(memo25_1, memo25_2, memo25_3)
  485.       26: assign_vals(memo26_1, memo26_2, memo26_3)
  486.    endcase
  487.    return;
  488. enddef
  489. }
  490. // EOP SCR2FRG.COD
  491.