home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 May / macformat-024.iso / Shareware City / Developers / CW CDEV Framework 1.1 / Sample CDEV / TControlPanel.cp < prev    next >
Encoding:
Text File  |  1995-01-09  |  5.4 KB  |  255 lines  |  [TEXT/MMCC]

  1. #ifndef _H_TControlPanel
  2. #include "TControlPanel.h"
  3. #endif
  4.  
  5. // CW CDEV Framework, ©1994-95, Matthew E. Axsom
  6. // Original Framework:  Matthew E. Axsom (chewey@nesw.mv.com)
  7. // Contributions From:    dEVoN Hubbard (TDevon@aol.com)
  8. // -----------------------------------------------------------
  9. // Version History
  10. // -----------------------------------------------------------
  11. // 1.1        Released 12/08/94 - mea
  12. //            Added more robust error handling so as to conform to Apple's
  13. //                standard cdev error return codes.
  14. //            Added and corrected comments and udated instructions.
  15. //            Also tested compilation under CW5  No problems.
  16.  
  17. // 1.1d2    Internal version - mea
  18. //            Added a Init() message to base class and call it from CDEVMain
  19. //                just after the object is created.  Should ease porting from Think.
  20. //            Added a Close() message to base class and call it from CDEVMain just
  21. //                before we delete the object.  Should ease porting from Think.
  22. //            Eliminated calls to CommandKey() if keyEvtDev is generated via an
  23. //                autoKey event.
  24. //            Changed name of class source files from CDEVClass.c/h to
  25. //                TControlPanel.cp/h.
  26. //            Changed name of starter cdev source from CDEV.c to CDEV.cp.
  27.  
  28. // 1.1d1    Internal version - dth
  29. //            (Modifications for easier porting from Think cdev class
  30. //                projects without losing strengths of Chewey's framework)
  31. //            Changed name of class from cdevObj to TControlPanel.
  32. //            Changed method names to begin w/capital letter.
  33. //            Changed hit() to ItemHit()
  34. //            Changed KeyDown() & CommandKey() to accept short byte value.
  35. //            Changed action() to give short byte value to key methods.
  36. //            Instance variables are now prefixed with an 'f' to indicate
  37. //                they are a member/field variable.
  38.  
  39. // 1.0.1    Released 12/13/94
  40. //            DlgCut() added to cut() method.
  41. //            DlgCopy() added to copy() method.
  42. //            DlgPaste() added to paste() method.
  43. //            DlgDelete() added to clear() method.
  44. //            Note:  The above additions were made to the sample's base class
  45. //           in the original 1.0 distribution, but didn't make it (I'll plead
  46. //            version control problems ;) into the framework's base class.
  47. //            Thanks to dEVoN Hubbard for pointing this out!
  48. //            
  49. // 1.0         Released 12/08/94
  50. //            Initial verison
  51.  
  52. TControlPanel::TControlPanel(short numItems,DialogPtr cp)
  53. {
  54.     fLastItem = numItems;
  55.     fDialog = cp;
  56.  
  57.     // Init() gets called from CDEVMain just after this call
  58. }
  59.  
  60. // sorry, don't have anything to destroy
  61. TControlPanel::~TControlPanel(void)
  62. {
  63.     // close gets called from CDEVMain just before this call
  64. }
  65.  
  66. // provided for compatibility with Think class.
  67. long TControlPanel::Init(void)
  68. {
  69.     return noErr;
  70. }
  71.  
  72. // provided for compatibility with Think class.
  73. long TControlPanel::Close(void)
  74. {
  75.     return noErr;
  76. }
  77.  
  78. // handle actions not related to initing, opening or closing
  79. long TControlPanel::actions(short message,short itemHit)
  80. {
  81.     long    result=0;
  82.     
  83.     switch (message)
  84.         {
  85.         // handle a click
  86.         case hitDev:
  87.             result=ItemHit(itemHit - fLastItem);    // normalize to our values
  88.             break;
  89.         
  90.         // handle a null event by performing any idle time processing
  91.         case nulDev:
  92.             result=Idle();
  93.             break;
  94.             
  95.         // handle user item updates
  96.         case updateDev:
  97.             result=Update();
  98.             break;
  99.         
  100.         // activate things
  101.         case activDev:
  102.             result=Activate();
  103.             break;
  104.         
  105.         // deactivate things
  106.         case deactivDev:
  107.             result=Deactivate();
  108.             break;
  109.         
  110.         // keydown or autokey
  111.         case keyEvtDev:
  112.             // filter out command keys and handle them via commandKey()
  113.  
  114.             if ((fEvent->modifiers & cmdKey) == 0)
  115.                 result = KeyDown((unsigned char) fEvent->message);
  116.             else
  117.                 // avoid processing command keys tied to autoKey events
  118.                 if (fEvent->message != autoKey)
  119.                     result = CommandKey((unsigned char) fEvent->message);
  120.             break;
  121.             
  122.         // undo command from edit menu
  123.         case undoDev:
  124.             result=Undo();
  125.             break;
  126.         
  127.         // cut command from edit menu
  128.         case cutDev:
  129.             result=Cut();
  130.             break;
  131.         
  132.         // copy command from edit menu
  133.         case copyDev:
  134.             result=Copy();
  135.             break;
  136.         
  137.         // paste command from edit menu
  138.         case pasteDev:
  139.             result=Paste();
  140.             break;
  141.         
  142.         // clear command from edit menu
  143.         case clearDev:
  144.             result=Clear();
  145.             break;
  146.         }
  147.     
  148.     return result;
  149. }
  150.  
  151. // handle command keys for normal editing items
  152. long TControlPanel::CommandKey(short theChar)
  153. {
  154.     long    result=0;
  155.     
  156.     switch (theChar) {
  157.         case 'z':    // cmd - z
  158.         case 'Z':
  159.             result=Undo();
  160.             break;
  161.         
  162.         case 'x':    // cmd - x
  163.         case 'X':
  164.             result=Cut();
  165.             break;
  166.         
  167.         case 'c':    // cmd - c
  168.         case 'C':
  169.             result=Copy();
  170.             break;
  171.         
  172.         case 'v':    // cmd - v
  173.         case 'V':
  174.             result=Paste();
  175.             break;
  176.     }
  177.     
  178.     return result;
  179. }
  180.  
  181. // handle a hit in the control panel.  Note lastItem has already been added to itemHit
  182. long TControlPanel::ItemHit(short /*itemHit*/)
  183. {
  184.     return noErr;
  185. }
  186.  
  187. // got a nulDev (nullEvent) message
  188. long TControlPanel::Idle(void)
  189. {
  190.     return noErr;
  191. }
  192.  
  193. // update any user items
  194. long TControlPanel::Update(void)
  195. {
  196.     return noErr;
  197. }
  198.  
  199. // activate items
  200. long TControlPanel::Activate(void)
  201. {
  202.     return noErr;
  203. }
  204.  
  205. // deactivate items
  206. long TControlPanel::Deactivate(void)
  207. {
  208.     return noErr;
  209. }
  210.  
  211. // handle a key down
  212. long TControlPanel::KeyDown(short /*theChar*/)
  213. {
  214.     return noErr;
  215. }
  216.  
  217. // handle an undo
  218. long TControlPanel::Undo(void)
  219. {
  220.     return noErr;
  221. }
  222.  
  223. // handle a cut
  224. long TControlPanel::Cut(void)
  225. {
  226.     DlgCut(fDialog);
  227.     
  228.     return noErr;
  229. }
  230.  
  231. // handle a copy
  232. long TControlPanel::Copy(void)
  233. {
  234.     DlgCopy(fDialog);
  235.     
  236.     return noErr;
  237. }
  238.  
  239. // handle a paste
  240. long TControlPanel::Paste(void)
  241. {
  242.     DlgPaste(fDialog);
  243.  
  244.     return noErr;
  245. }
  246.  
  247. // handle a clear
  248. long TControlPanel::Clear(void)
  249. {
  250.     DlgDelete(fDialog);
  251.     
  252.     return noErr;
  253. }
  254.     
  255.