home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / DATABASE / YME060.ZIP / YSAMPLES.PRG < prev   
Encoding:
Text File  |  1993-08-28  |  15.8 KB  |  476 lines

  1. * YSamples.prg
  2. *
  3. * Sample application for YAME -- Yet Another Memo Editor
  4. *
  5. * by Kenneth Chan
  6. * Please refer to YAME.DOC for contacts
  7. *
  8. * 08/21/93
  9. *
  10.  
  11. use YSAMPLES
  12.  
  13. define popup uYAME from  7,26
  14. define bar 1 of uYAME prompt "  Single memo with .FMT "   message " WP option in CONFIG.DB "
  15. define bar 2 of uYAME prompt "  Multiple memo with .FMT " message " WP option in CONFIG.DB and YAMEPARM "
  16. define bar 3 of uYAME prompt "  .BIN invocation "         message " LOAD and CALL "
  17. define bar 4 of uYAME prompt "──────────────────────────" skip
  18. define bar 5 of uYAME prompt "  Last two rows problem "   message " Demonstrate problem with losing lines 23 and 24 "
  19. define bar 6 of uYAME prompt "  Last two rows solution  " message " Workaround for problem with losing lines 23 and 24 "
  20. define bar 7 of uYAME prompt "──────────────────────────" skip
  21. define bar 8 of uYAME prompt "  Go to dot prompt "        message " RETURN "
  22. define bar 9 of uYAME prompt "  Go to DOS        "        message " QUIT "
  23. on selection popup uYAME deactivate popup
  24. do while .t.
  25.   clear
  26.   @  4,34 say "YAME Samples"
  27.   @  3,26 to  5,53 double
  28.   activate popup uYAME
  29.   do case
  30.     case "Single" $ prompt()
  31.       do Fmt1
  32.     case "Multiple" $ prompt()
  33.       do Fmt2
  34.     case "BIN" $ prompt()
  35.       do BinInvoc
  36.     case "problem" $ prompt()
  37.       do RowsProb
  38.     case "solution" $ prompt()
  39.       do RowsSol
  40.     case "DOS" $ prompt()
  41.       quit
  42.     otherwise
  43.       exit
  44.   endcase
  45. enddo
  46. release popup uYAME
  47.  
  48. use in YSAMPLES
  49. RETURN
  50.  
  51.  
  52.  
  53. PROCEDURE Fmt1
  54.   set format to YSAMPLE1
  55.   *-- Goto record with memo formatted for this form.  In your applications,
  56.   *-- all your memos will be formatted the same, but in this demo file, there
  57.   *-- are different memos for the different implementations/margins.
  58.   goto 1                                && soft returns at 57 margin
  59.   edit next 1 nomenu
  60.   set format to
  61. RETURN
  62.  
  63.  
  64.  
  65. PROCEDURE Fmt2
  66.   set format to YSAMPLE2
  67.   load YAMEPARM
  68.   *-- Goto record with memo formatted for this form.
  69.   goto 2                                && soft returns at 37 margin
  70.   edit next 1 nomenu
  71.   *-- Uninstall YAMPARM by CALLing it with no parameters
  72.   call YAMEPARM
  73.   release module YAMEPARM
  74.   set format to
  75. RETURN
  76.  
  77.  
  78.  
  79. PROCEDURE BinInvoc
  80.   *-- Load YAME (note .COM extension)
  81.   load Y.COM
  82.   *-- Load edit buffer
  83.   load YAMEBUFF
  84.   *-- Init buffer with maximum allowed memo size.  65024 is maximum maximum.
  85.   call YAMEBUFF with 65024
  86.   *-- Goto record with memo formatted for this form.
  87.   goto 3                                && YAME native; no soft returns
  88.   clear
  89.   @  1, 1 say ".BIN invocation:  using the provided MemoKey() function, you can simulate the"
  90.   @  2, 1 say "standard key action for a memo field.  Here, there is one open window and one"
  91.   @  3, 1 say "memo marker.  The YAMEBUFF.BIN file must be loaded and initialized for the"
  92.   @  4, 1 say ".BIN invocation to work."
  93.   @  7, 0 to  7,79
  94.   @  8,27 say "Topic"
  95.   @  8,33 get TOPIC
  96.   @ 10,14 say "Argument FOR"
  97.   *-- Putting the memo marker one row down and one column to the right
  98.   *   ╔══════════════════════╗
  99.   *   ║memo                  ║
  100.   *   ║                      ║
  101.   *   ║                      ║
  102.   *   ╚══════════════════════╝
  103.   *-- of the window puts cursor at top left of the inside of the memo window
  104.   @ 12, 1 get ARG_PRO ;
  105.     when MemoKey( 11, 0, 19, 39, "/i19,1" )
  106.   *-- Display the contents of the open window
  107.   do DispMemo with "ARG_PRO", 11, 0, 19, 39
  108.   *-- For this field use a memo marker
  109.   @ 10,52 say "Argument AGAINST"
  110.   *-- by putting the memo field outside the window
  111.   @ 10,69 get ARG_CON ;
  112.     when MemoKey( 11, 40, 19, 79, "/i19,41" )
  113.   @ 22,28 say "by"
  114.   @ 22,31 get AUTHOR
  115.   read
  116.   *-- Uninstall YAMEBUFF with CALLing with no parameters
  117.   call YAMEBUFF
  118.   release module YAMEBUFF
  119.   *-- No separate uninstall for Y.COM; just RELEASE
  120.   release module Y
  121. RETURN
  122.  
  123.  
  124.  
  125. PROCEDURE RowsProb
  126.   clear
  127.   @  1, 0 to 23,79 176
  128.   *-- Goto record with memo formatted for this demo
  129.   goto 1
  130.   *-- Copy the memo field to a temp file to workaround abort READ anomaly
  131.   copy to ONEMEMO field ARG_CON next 1
  132.   use ONEMEMO in select()
  133.   @  4, 6 get TOPIC ;
  134.     message " Cursor down to the memo field "
  135.   @  6, 6 get ONEMEMO->ARG_CON ;
  136.     message " Press CTRL-HOME then press ESC.  Watch this line and the line above. "
  137.   @  8, 6 get AUTHOR ;
  138.     message " Cursor up to the memo field "
  139.   read
  140.   *-- If changes were made, copy memo back from temp file
  141.   if readkey() >= 256
  142.     replace ARG_CON with ONEMEMO->ARG_CON
  143.   endif
  144.   *-- Erase temp file(s)
  145.   use in ONEMEMO
  146.   erase ONEMEMO.DBF
  147.   erase ONEMEMO.DBT
  148. RETURN
  149.  
  150.  
  151.  
  152. PROCEDURE RowsSol
  153.   clear
  154.   @  1, 0 to 23,79 176
  155.   *-- Goto record with memo formatted for this demo
  156.   goto 1
  157.   *-- Copy the memo field to a temp file to workaround abort READ anomaly
  158.   copy to ONEMEMO field ARG_CON next 1
  159.   use ONEMEMO in select()
  160.   *-- State variable
  161.   public n_MemoScrn
  162.   *     0 == no checking
  163.   *     1 == initial entry into memo field
  164.   *     2 == grab next key
  165.   *     3 == screen saved
  166.   *-- Set state for initial entry into memo field
  167.   n_MemoScrn = 1
  168.   @  4, 6 get TOPIC ;
  169.     message " Cursor down to the memo field "
  170.   @  6, 6 get ONEMEMO->ARG_CON ;
  171.     when ForcValid() ;
  172.     valid required MemoScrn() ;
  173.     error "" ;
  174.     message " Press CTRL-HOME then press ESC.  Watch this line and the line above. "
  175.   @  8, 6 get AUTHOR ;
  176.     message " Cursor up to the memo field "
  177.   read
  178.   *-- If changes were made, copy memo back from temp file
  179.   if readkey() >= 256
  180.     replace ARG_CON with ONEMEMO->ARG_CON
  181.   endif
  182.   *-- Erase temp file(s)
  183.   use in ONEMEMO
  184.   erase ONEMEMO.DBF
  185.   erase ONEMEMO.DBT
  186.   *-- Release state variable
  187.   release n_MemoScrn
  188. RETURN
  189.  
  190.  
  191.  
  192. FUNCTION ForcValid
  193.   *----------------------------------------------------------------------------
  194.   *-- Programmer..: Kenneth Chan [Zak]  CIS:71542,2712
  195.   *-- Date........: 01/27/1993
  196.   *-- Notes.......: Workaround for losing last two lines on screen when
  197.   *                 using external memo editor.
  198.   *
  199.   *                 Forces a VALID check, activating MemoScrn()
  200.   *
  201.   *-- Written for.: dBASE IV, 1.5
  202.   *-- Rev. History: 01/27/1993 1.0
  203.   *-- Calls.......: Works in tandem with MemoScrn()
  204.   *                 The memvar n_MemoScrn must be defined, and should be
  205.   *                 set to 1 before the READ
  206.   *                     *-- State variable
  207.   *                     public n_MemoScrn
  208.   *                     *     0 == no checking
  209.   *                     *     1 == initial entry into memo field
  210.   *                     *     2 == grab next key
  211.   *                     *     3 == screen saved
  212.   *                     *-- Set state for initial entry into memo field
  213.   *                     n_MemoScrn = 1
  214.   *-- Called by...: WHEN clause of GET
  215.   *-- Usage.......: when ForcValid() valid required MemoScrn()
  216.   *-- Example.....: @ 6,11 get NOTES ;
  217.   *                   when ForcValid() ;
  218.   *                   valid required MemoScrn() ;
  219.   *                   error ""
  220.   *-- Returns.....: .T.
  221.   *-- Parameters..: <none>
  222.   *----------------------------------------------------------------------------
  223.   if n_MemoScrn = 1
  224.     *-- Move to next stage
  225.     n_MemoScrn = 2
  226.     *-- Trigger VALID check
  227.     keyboard "{CTRL-M}"
  228.     *-- Silence bell
  229.     set bell to 19,1
  230.   endif
  231.   if n_MemoScrn = 0
  232.     *-- Set state var for next memo field
  233.     n_MemoScrn = 1
  234.     *-- Restore bell to default tone
  235.     set bell to 512,2
  236.   endif
  237. RETURN .t.
  238.  
  239.  
  240.  
  241. FUNCTION MemoScrn
  242.   *----------------------------------------------------------------------------
  243.   *-- Programmer..: Kenneth Chan [Zak]  CIS:71542,2712
  244.   *-- Date........: 01/27/1993
  245.   *-- Notes.......: Workaround for losing last two lines on screen when
  246.   *                 using external memo editor.
  247.   *
  248.   *                 Works better when the ERROR message is set to
  249.   *                 nothing ("").
  250.   *
  251.   *-- Written for.: dBASE IV, 1.5
  252.   *-- Rev. History: 01/27/1993 1.0
  253.   *-- Calls.......: Works in tandem with ForcValid()
  254.   *                 The memvar n_MemoScrn must be defined
  255.   *                     *-- State variable
  256.   *                     public n_MemoScrn
  257.   *                     *     0 == no checking
  258.   *                     *     1 == initial entry into memo field
  259.   *                     *     2 == grab next key
  260.   *                     *     3 == screen saved
  261.   *-- Called by...: VALID REQUIRED clause of GET
  262.   *-- Usage.......: when ForcValid() valid required MemoScrn()
  263.   *-- Example.....: @ 6,11 get NOTES ;
  264.   *                   when ForcValid() ;
  265.   *                   valid required MemoScrn() ;
  266.   *                   error ""
  267.   *-- Returns.....: .T. eventually
  268.   *-- Parameters..: <none>
  269.   *----------------------------------------------------------------------------
  270.   private lRet, nKey
  271.   if n_MemoScrn > 1
  272.     if n_MemoScrn = 3
  273.       *-- Restore lines 23 and 24
  274.       restore screen from sMemoScrn
  275.       release screen sMemoScrn
  276.     endif
  277.     *-- Wait for keypress
  278.     nKey = inkey( 0 )
  279.     *-- Return VALID false to force next action to occur in
  280.     *-- current field
  281.     lRet = .f.
  282.     *-- Clear VALID error message
  283.     keyboard " "
  284.     *-- Ctrl-Home; edit memo
  285.     if nKey = 29
  286.       save screen to sMemoScrn
  287.       n_MemoScrn = 3
  288.       *-- Open memo and force recheck
  289.       keyboard "{CTRL-HOME}{CTRL-M}"
  290.     else
  291.       *-- Don't stop the next key
  292.       n_MemoScrn = 0
  293.       *-- Type the key that was trapped
  294.       keyboard "{" + ltrim( str( nKey )) + "}"
  295.     endif
  296.   else
  297.     *-- Pass key through
  298.     lRet = .t.
  299.     *-- Must init PRIVATE memvar
  300.     nKey = 0
  301.   endif
  302. RETURN lRet
  303.  
  304.  
  305.  
  306. PROCEDURE DispMemo
  307.   *----------------------------------------------------------------------------
  308.   *-- Programmer..: Kenneth Chan [Zak]  CIS:71542,2712
  309.   *-- Date........: 07/14/1993
  310.   *-- Notes.......: Displays a memo field in a window
  311.   *-- Written for.: dBASE IV, 1.5
  312.   *-- Rev. History: 07/14/1993 1.0
  313.   *-- Calls.......: <none>
  314.   *-- Called by...: <any>
  315.   *-- Usage.......: do DispMemo with <cMemoFld>, <nTop>, <nLft>, <nBtm>, <nRht>
  316.   *-- Example.....: do DispMemo with "NOTES", 5, 10, 18, 69
  317.   *-- Returns.....: <na>
  318.   *-- Parameters..: cMemoFld   = name of memo field
  319.   *                 nTop       = top row of window
  320.   *                 nLft       = left column of window
  321.   *                 nBtm       = bottom row of window
  322.   *                 nRht       = right column of window
  323.   *----------------------------------------------------------------------------
  324.   parameter cMemoFld, nTop, nLft, nBtm, nRht
  325.   private nOldWidth, n1
  326.   nOldWidth = set( "MEMOWIDTH" )
  327.   *-- Set MEMOWIDTH for window
  328.   set memowidth to nRht - nLft - 2
  329.   *-- Draw border
  330.   @ nTop, nLft to nBtm, nRht
  331.   @ nTop + 1, nLft + 1 clear to nBtm - 1, nRht - 1
  332.   n1 = 1
  333.   *-- Display each line
  334.   do while n1 < nBtm - nTop
  335.     @ nTop + n1, nLft + 1 say mline( &cMemoFld., n1 )
  336.     n1 = n1 + 1
  337.   enddo
  338.   set memowidth to nOldWidth
  339. RETURN
  340.  
  341.  
  342.  
  343. FUNCTION MemoKey
  344.   *----------------------------------------------------------------------------
  345.   *-- Programmer..: Kenneth Chan [Zak]  CIS:71542,2712
  346.   *-- Date........: 07/14/1993
  347.   *-- Notes.......: Emulates standard behavior when cursor is on memo marker.
  348.   *                 If Ctrl-Home or F9 is pressed, YAME is CALLed.  Defaults
  349.   *                 to double border, and margins to fit in window.
  350.   *
  351.   *                 If memo field is inside window coordinates, memo is
  352.   *                 treated like an OPEN WINDOW.
  353.   *
  354.   *-- Written for.: dBASE IV, 1.5
  355.   *-- Rev. History: 07/14/1993 1.0
  356.   *-- Calls.......: Y.COM, DispMemo
  357.   *-- Called by...: WHEN clause of GET
  358.   *-- Usage.......: when MemoKey( <nTop>, <nLft>, <nBtm>, <nRht>, ;
  359.   *                   [ <cExtraParm> ] )
  360.   *-- Example.....: @ 6,11 get NOTES when MemoKey( 5, 10, 18, 69 )
  361.   *-- Returns.....: .T.
  362.   *-- Parameters..: nTop       = top row of window
  363.   *                 nLft       = left column of window
  364.   *                 nBtm       = bottom row of window
  365.   *                 nRht       = right column of window
  366.   *                 cExtraParm = extra parameters to pass to YAME
  367.   *----------------------------------------------------------------------------
  368.   parameters nTop, nLft, nBtm, nRht, cExtraParm
  369.   *-- Make sure extra parameter is defined
  370.   if pcount() < 5
  371.     cExtraParm = ""
  372.   endif
  373.   private nRow, nCol, lLoop, cYAMEPARM, cMemoFld, cColorFld
  374.   *-- Construct YAME parameter string
  375.   cYAMEParm = "/m" + ltrim( str( nRht - nLft - 2 )) + " /@" + ;
  376.     ltrim( str( nTop )) + "," + ltrim( str( nLft )) + "," + ;
  377.     ltrim( str( nBtm )) + "," + ltrim( str( nRht )) + ;
  378.     " /bd " + cExtraParm + " MEMO_TMP.$DB"
  379.   cMemoFld = varread()
  380.   nRow = row()
  381.   nCol = col()
  382.   *-- Get the COLOR OF FIELDS
  383.   cColorFld = substr( set( "ATTRIBUTES" ), rat( ",", set( "ATTRIBUTES" )) + 1 )
  384.   if file( "MEMO_TMP.$DB" )
  385.     erase MEMO_TMP.$DB
  386.   endif
  387.   copy memo &cMemoFld. to MEMO_TMP.$DB
  388.   lLoop = .t.
  389.   do while lLoop
  390.     nKey = inkey( 0 )
  391.     do case
  392.       case nKey = 29 .or. nKey = -8 && Ctrl-Home or F9
  393.         save screen to sMemoKey
  394.         *-- Invoke YAME; exit code returned in parameter string
  395.         call Y with cYAMEParm
  396.         restore screen from sMemoKey
  397.         release screen sMemoKey
  398.         *-- Check exit code to see if file was saved
  399.         if cYAMEParm = "0"
  400.           *-- Update memo field
  401.           append memo &cMemoFld. from MEMO_TMP.$DB overwrite
  402.         endif
  403.         *-- If memo marker is outside the window
  404.         if nRow < nTop .or. nRow > nBtm .or. nCol + 3 < nLft .or. nCol > nRht
  405.           *-- Update the memo marker
  406.           @ nRow, nCol say iif( len( &cMemoFld. ) = 0, "memo", "MEMO" ) color &cColorFld.
  407.         else
  408.           *-- Redisplay memo
  409.           do DispMemo with cMemoFld, nTop, nLft, nBtm, nRht
  410.         endif
  411.         *-- Overwrite exit code with original slash
  412.         cYAMEParm = stuff( cYAMEParm, 1, 1, "/" )
  413.         *-- Do not KEYBOARD Ctrl-Home
  414.         nKey = 0
  415.       case "," + ltrim( str( nKey )) + "," $ ;
  416.         ",1,3,4,5,6,9,13,17,18,19,23,24,27,-400,"
  417.         *-- These keys will move the cursor, let them pass
  418.       case nKey > 0 .and. nKey < 256
  419.         *-- Ignore all other non-function keys
  420.         nKey = 0
  421.       otherwise
  422.         *-- KEYBOARD function key to allow for ON KEY traps
  423.         keyboard "{" + ltrim( str( nKey )) + "}"
  424.         *-- but don't leave
  425.         nKey = 0
  426.     endcase
  427.     if nKey # 0
  428.       *-- Type key
  429.       keyboard "{" + ltrim( str( nKey )) + "}" clear
  430.       *-- Quit loop
  431.       lLoop = .f.
  432.     endif
  433.     *-- Move cursor back after possible memo redraw
  434.     @ nRow, nCol say ""
  435.   enddo
  436.   if file( "MEMO_TMP.$DB" )
  437.     erase MEMO_TMP.$DB
  438.   endif
  439. *-- Return .T. to read stuffed keystroke
  440. RETURN .t.
  441.  
  442.  
  443.  
  444. *-- If you don't have dBASE IV v2.0, here's a RAT() UDF
  445. FUNCTION RAt
  446. *-------------------------------------------------------------------------------
  447. *-- Programmer..: Jay Parsons (CIS: 70160,340)
  448. *-- Date........: 03/01/1992
  449. *-- Notes.......: Reverse "at", returns position a character string is last
  450. *--               AT in a larger string.
  451. *-- Written for.: dBASE IV
  452. *-- Rev. History: 03/01/1992 -- Original Release
  453. *-- Calls.......: None
  454. *-- Called by...: Any
  455. *-- Usage.......: Rat("<cFindStr>","<cBigStr>")
  456. *-- Example.....: ? Rat("Test","This is a Test string, with Test data")
  457. *-- Returns.....: Numeric value
  458. *-- Parameters..: cFindStr = string to find in cBigStr
  459. *--               cBigStr  = string to look in
  460. *-------------------------------------------------------------------------------
  461.  
  462.     parameters cFindstr, cBigstr
  463.     private nPos,nLen
  464.     nLen = len( cFindstr )
  465.     nPos = len( cBigstr ) - nLen + 1
  466.     do while nPos > 0
  467.         if substr( cBigstr, nPos, nLen ) = cFindstr
  468.             exit
  469.         else
  470.             nPos = nPos - 1
  471.         endif
  472.     enddo
  473.     
  474. RETURN max( nPos, 0 )
  475. *-- EoF: RAt()
  476.