home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / clipper / memoge.zip / MEMOGET.PRG < prev    next >
Text File  |  1993-08-02  |  5KB  |  166 lines

  1. // MemoGET.prg
  2. //
  3. // Date   : 7/31/93
  4. // Author : Shaun Botha (CompuServe ID: 70043, 2641)
  5. // Purpose: Provide 'GET'ting of memo field
  6. // Compile: Clipper MEMOGET /n/m/w/l
  7. //
  8. // Notes  : The 'GET' displays only the first thirteen characters of the memo
  9. //          field - actually it's 15 but I put delimiters ("<>") around the
  10. //          field.
  11. //
  12. //          I'm using ALT_ENTER to indicate that we wish to edit the
  13. //          memo but you can easily change this by modifying the '#define'
  14. //
  15. //          By default the reader uses it's own editor function for editing
  16. //          the memo.  You can set your own by including the 'editor ...'
  17. //          statement as part of the GET.  Note that the editor function
  18. //          receives parameters as follows:
  19. //              cMemo     : The memo
  20. //              t, l, b, r: Coordinates of the window as specified in the
  21. //                          GET statement
  22. //          The editor function _must_ return the memo - it is not passed by
  23. //          reference !
  24. //
  25. // Should you make modifications to this please let me know so that I and
  26. // others can be kept updated
  27.  
  28. #include "inkey.ch"
  29. #include "getexit.ch"
  30. #include "memoget.ch"
  31.  
  32.  
  33. // Provide a reader for the 'ghost' field (representation of the memo)
  34. // Pretty much the same as Clipper's 'GetReader'
  35. procedure memoReader(get)
  36.     if ( getPreValidate(get) )
  37.         get:SetFocus()
  38.  
  39.         while ( get:exitState == GE_NOEXIT )
  40.             if ( get:typeOut )
  41.                 get:exitState := GE_ENTER
  42.             end
  43.  
  44.             while ( get:exitState == GE_NOEXIT )
  45.                 memoRdrApplyKey( get, Inkey(0) )
  46.             end
  47.  
  48.             if ( !GetPostValidate(get) )
  49.                 get:exitState := GE_NOEXIT
  50.             end
  51.         end
  52.         get:KillFocus()
  53.     end
  54. return
  55.  
  56.  
  57. // Apply keystrokes to the 'ghost' field
  58. procedure memoRdrApplyKey(get, key)
  59.     local bKeyBlock, cMemo
  60.  
  61.     if ( (bKeyBlock := setKey(key)) <> NIL )
  62.         getDoSetKey(bKeyBlock, get)
  63.         return
  64.     end
  65.  
  66.     do case
  67.         case ( key == K_UP )
  68.             get:exitState := GE_UP
  69.  
  70.         case ( key == K_SH_TAB )
  71.             get:exitState := GE_UP
  72.  
  73.         case ( key == K_DOWN )
  74.             get:exitState := GE_DOWN
  75.  
  76.         case ( key == K_TAB )
  77.             get:exitState := GE_DOWN
  78.  
  79.         case ( key == K_ENTER )
  80.             get:exitState := GE_ENTER
  81.  
  82.         case ( key == K_ESC )
  83.             if ( Set(_SET_ESCAPE) )
  84.                 get:undo()
  85.                 get:exitState := GE_ESCAPE
  86.             end
  87.  
  88.         case ( key == K_PGUP )
  89.             get:exitState := GE_WRITE
  90.  
  91.         case ( key == K_PGDN )
  92.             get:exitState := GE_WRITE
  93.  
  94.         case ( key == K_CTRL_HOME )
  95.             get:exitState := GE_TOP
  96.  
  97.  
  98.     #ifdef CTRL_END_SPECIAL
  99.  
  100.         // both ^W and ^End go to the last GET
  101.         case (key == K_CTRL_END)
  102.             get:exitState := GE_BOTTOM
  103.  
  104.     #else
  105.  
  106.         // both ^W and ^End terminate the READ (the default)
  107.         case (key == K_CTRL_W)
  108.             get:exitState := GE_WRITE
  109.  
  110.     #endif
  111.     
  112.         case (key == K_INS)
  113.             Set( _SET_INSERT, !Set(_SET_INSERT) )
  114.  
  115.         // This is where it all takes place
  116.         case (key == K_ACT_MEMO)
  117.             // Grab current value of memo field
  118.             cMemo := eval(get:cargo[1])
  119.  
  120.             // Edit the memo
  121.             if( empty(get:cargo[3]) )
  122.                 // Use default editor
  123.                 cMemo := defMemoEditor(cMemo, get:cargo[2,1], get:cargo[2,2],;
  124.                                               get:cargo[2,3], get:cargo[2,4])
  125.             else
  126.                 // Use custom editor
  127.                 cMemo := eval(get:cargo[3],;
  128.                                     cMemo, get:cargo[2,1], get:cargo[2,2],;
  129.                                     get:cargo[2,3], get:cargo[2,4])
  130.             endif
  131.  
  132.             // Assign edited memo back to variable
  133.             eval(get:cargo[1], cMemo)
  134.  
  135.             // Redisplay the 'ghost' field
  136.             // In order to display properly we'll need to remove focus, display
  137.             // and then redisplay again - try commenting out the '..focus'
  138.             // lines to see what happens <g>!!
  139.             get:killFocus()
  140.             get:display()
  141.             get:setFocus()
  142.     endcase
  143. return
  144.  
  145.  
  146. // Default editor for 'GET'ted (or is that 'GOT') memos
  147. static function defMemoEditor(cMemo,t,l,b,r)
  148.     local s
  149.     local row, col, clr, curs
  150.  
  151.     // Save screen environment
  152.     s := saveScreen(t,l,b,r)
  153.     row := row()
  154.     col := col()
  155.     clr := setColor()
  156.     curs := setCursor()
  157.  
  158.     cMemo := memoEdit(cMemo, t, l, b, r)
  159.  
  160.     // Restore screen environment
  161.     setPos(row, col)
  162.     setColor(clr)
  163.     setCursor(curs)
  164.     restScreen(t,l,b,r, s)
  165. return cMemo
  166.