home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / clintsrc.sit / DAundo.c < prev    next >
Text File  |  1990-06-20  |  4KB  |  178 lines

  1. /*========================================================================
  2. ===  DAundo.c
  3. ===
  4. ===  Greg Anderson
  5. ===  29 Kerr Hall
  6. ===  Social Sciences Computing
  7. ===  University of California at Santa Cruz
  8. ===  Santa Cruz CA  95062
  9. ===
  10. ===  (408) 459-2658
  11. ===  sirkm@ssyx.ucsc.edu
  12. ===
  13. ===  Text undo routines.
  14. === 
  15. ===  This code was never debugged, so all of the routines were removed.
  16. ========================================================================*/
  17. #include    <types.h>
  18. #include    <osutils.h>
  19. #include    <memory.h>
  20. #include    <devices.h>
  21. #include    <events.h>
  22. #include    <quickdraw.h>
  23. #include    <fonts.h>
  24. #include    <windows.h>
  25. #include    <files.h>
  26. #include    <errors.h>
  27. #include    <toolutils.h>
  28. #include    <packages.h>
  29.  
  30. #include    <Limits.h>
  31. #include    <Controls.h>
  32. #include    <TextEdit.h>
  33. #include    <Dialogs.h>
  34. #include    <Desk.h>
  35. #include    <Scrap.h>
  36. #include    <Traps.h>
  37. #include    <Lists.h>
  38. #include    <Menus.h>
  39.  
  40.  
  41. #include    "unixDA.h"
  42. #include    "DA.h"
  43.  
  44. /*----------------------------------------------------------------------
  45. |  Clear out the current Undo record
  46. ----------------------------------------------------------------------*/
  47. zapUndo( DCtlPtr dCtl )
  48. {
  49.     if( DA_global->undoText )
  50.     {
  51.         TEDispose( DA_global->undoText );
  52.         DA_global->undoText = (TEHandle) 0L;
  53.     }
  54.     DA_global->undoType = undoNothing;
  55. }
  56.  
  57. /*----------------------------------------------------------------------
  58. |  Set the Undo record up before executing a 'Cut' command
  59. ----------------------------------------------------------------------*/
  60. setUndoCut( DCtlPtr dCtl )
  61. {
  62.     TEHandle    saveScrap;
  63.     Handle        theScrap;
  64.     Rect        anyRect;
  65.     char        *p;
  66.     long        selLen = ((*DA_te)->selEnd - (*DA_te)->selStart);
  67.     
  68.     return;
  69.     /*
  70.      *  Save the TE scrap, as we are going to 'borrow' it for a moment.
  71.      */
  72.     SetRect(&anyRect,0,0,400,200);
  73.     saveScrap = TENew(&anyRect,&anyRect);
  74.     TEPaste( saveScrap );
  75.     /*
  76.      *  Clear out the old undo info and put in the new
  77.      */
  78.     zapUndo( dCtl );
  79.     /*
  80.      *  Create a new textEdit record & copy the selected
  81.      *  text into it.
  82.      */
  83.     DA_global->undoText = TENew(&anyRect,&anyRect);
  84.     /*
  85.      *  This is the old (and simple) way of doing things.  It
  86.      *  didn't work, so I tried something more straightforward
  87.      *
  88.      *    TECopy( DA_te );
  89.      *    TEPaste( DA_global->undoText );
  90.      *
  91.      *
  92.      *  The code inside of the 'if(selLen)' replaces the copy and
  93.      *  paste above.  It does not work either.
  94.      */
  95.     if( selLen )
  96.     {
  97.         theScrap = (Handle) TEGetText( DA_te );
  98.         HLock( theScrap );
  99.         p = *theScrap;
  100.         p += (*DA_te)->selStart;
  101.         TESetText( p,selLen,DA_global->undoText);
  102.         HUnlock( theScrap );
  103.     }
  104.     /*
  105.      *  Set the undo type & starting location
  106.      */
  107.     DA_global->undoType = undoCut;
  108.     DA_global->undoFrom = (*DA_te)->selStart;
  109.     DA_global->undoTo = DA_global->undoFrom;
  110.     /*
  111.      *  Time to restore the TE scrap
  112.      */
  113.     TESetSelect( 0, kMaxTELength, saveScrap );
  114.     TECopy( saveScrap );
  115.     TEDispose( saveScrap );
  116. }
  117.  
  118. /*----------------------------------------------------------------------
  119. |  Set the Undo record up before executing a 'paste' command
  120. ----------------------------------------------------------------------*/
  121. setUndoPaste( DCtlPtr dCtl )
  122. {
  123.     return;
  124.     
  125.     setUndoCut( dCtl );
  126.     DA_global->undoTo +=  TEGetScrapLen();
  127.     DA_global->undoType = undoPaste;
  128. }
  129.  
  130. /*----------------------------------------------------------------------
  131. |  Execute an 'undo'
  132. ----------------------------------------------------------------------*/
  133. doUndo( DCtlPtr dCtl )
  134. {
  135.     HiliteEditMenu();
  136.     
  137.     switch( DA_global->undoType )
  138.     {
  139.     case undoCut:
  140.     case undoPaste:
  141.         doUndoPaste( dCtl );
  142.         break;
  143.     }
  144.  
  145.     adjustScrollbars(DA_window, false);
  146.     adjustTE(DA_window);
  147.     shortPause();
  148.     HiliteMenu(0);
  149. }
  150.  
  151. /*----------------------------------------------------------------------
  152. |  Undo a 'paste' command
  153. ----------------------------------------------------------------------*/
  154. doUndoPaste( DCtlPtr dCtl )
  155. {
  156.     long    total,contig;
  157.     
  158.     return;
  159.     
  160.     PurgeSpace(&total, &contig);
  161.  
  162.     /*
  163.      *  First get rid of the text that was inserted (if any)
  164.      */
  165.     TESetSelect( DA_global->undoFrom, DA_global->undoTo, DA_te );
  166.     TEDelete( DA_te );
  167.     /*
  168.      *  Now paste into the whole
  169.      */
  170.     TESetScrapLen( 0L );
  171.     TESetSelect( 0,kMaxTELength, DA_global->undoText );
  172.     TECopy( DA_global->undoText );
  173.     /*
  174.     setUndoPaste( dCtl );
  175.     */
  176.     TEPaste( DA_te );
  177. }
  178.