home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Frameworks / MacZoop 1.6.5 / Projects / Demo Project / Show Off Classes / ZUndoIPTask.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-18  |  2.0 KB  |  83 lines  |  [TEXT/CWIE]

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            ObjectMacZapp        -- a standard Mac OOP application template
  5. *
  6. *
  7. *
  8. *            ZUndoIPTask.cpp        -- an undo task for Image Processing ops in GWorld windows
  9. *
  10. *                                    (provided as an example of how to use it)
  11. *
  12. *
  13. *
  14. *            © 1996, Graham Cox
  15. *
  16. *
  17. *
  18. *
  19. *************************************************************************************************/
  20.  
  21.  
  22. #include    "ZUndoIPTask.h"
  23. #include    "ZGWorld.h"
  24. #include    "ZGWorldWindow.h"
  25.  
  26.  
  27. ZUndoIPTask::ZUndoIPTask( Str63 taskName, ZWindow* aWindow, short ipTaskID )
  28.     : ZUndoTask( taskName, aWindow )
  29. {
  30.     taskCode = ipTaskID;
  31. }
  32.  
  33.  
  34.  
  35. void    ZUndoIPTask::Do()
  36. {
  37.     ZGWorld*        aGW;
  38.     ZGWorldWindow*    zW;
  39.     
  40.     zW = (ZGWorldWindow*) itsTarget;
  41.     
  42.     if (zW)
  43.     {
  44.         aGW = zW->GetGWorld();
  45.         
  46.         switch (taskCode)
  47.         {
  48.             case undoInvert:
  49.                 aGW->Invert();
  50.                 zW->MakePaletteForWindow();
  51.                 break;
  52.                 
  53.                 // you could make this object perform more than one task by extending the
  54.                 // range of task codes and implementing more cases here to handle
  55.                 // each one. This may be better design than having a separate task object
  56.                 // for all possible tasks, since related functions are grouped and code can
  57.                 // be shared where this is appropriate.
  58.             default:
  59.                 break;
  60.         }
  61.         
  62.         zW->Focus();
  63.         zW->Draw();
  64.     }
  65.     
  66.     inherited::Do();    // important! Call inherited Do to maintain state    
  67. }
  68.  
  69.  
  70.  
  71. void    ZUndoIPTask::Undo()
  72. {
  73.     // because this task only currently deals with invert, Undo and Do amount to the same
  74.     // thing. This will not normally be the case, but for the sake of a simple illustration,
  75.     // this should be enough to show you how this works. If you extend this to perform other
  76.     // image processing tasks on a GWorld, the Undo will probably need to be more
  77.     // sophisticated- for example you may need to copy the image to another GWorld owned by
  78.     // this task in order to put it back completely when Undo is called.
  79.     
  80.     Do();
  81.     inherited::Undo();    // must call the inherited Undo at the end
  82. }
  83.