home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Demos / Bowers Development / AppMaker 2.0b5 / Examples / PowerPlant / NeoAccess / CAMReminderApp.cp < prev    next >
Encoding:
Text File  |  1995-10-05  |  5.9 KB  |  264 lines  |  [TEXT/MMCC]

  1. // CAMReminderApp.cp -- application methods
  2. // Created 10/5/95 8:02 PM by AppMaker
  3.  
  4. #include "CAMReminderApp.h"
  5.  
  6. #include "CAMReminderDoc.h"
  7. #include "CAMReminderData.h"
  8. #include "CmdCodes.h"
  9.  
  10. #include <UDesktop.h>
  11. #include <URegistrar.h>
  12. #include <UScreenPort.h>
  13. #include <PPobClasses.h>
  14. #include <PP_Messages.h>
  15.  
  16. // ---------------------------------------------------------------------------
  17. //        • CAMReminderApp
  18. // ---------------------------------------------------------------------------
  19. //    Default constructor
  20.  
  21. CAMReminderApp::CAMReminderApp()
  22.     :CNeoAppNative (kSignature, kFileType)
  23. {
  24.     UScreenPort::Initialize();
  25.  
  26.     RegisterClasses();
  27.  
  28.     SetUpMenus();
  29.  
  30.     // initialize app's data:
  31.     CAMReminderData::InitAppData();
  32.  
  33. }
  34.  
  35.  
  36. // ---------------------------------------------------------------------------
  37. //        • ~CAMReminderApp
  38. // ---------------------------------------------------------------------------
  39. //    Destructor
  40. //
  41.  
  42. CAMReminderApp::~CAMReminderApp()
  43. {
  44. }
  45.  
  46. // ---------------------------------------------------------------------------
  47. //        • RegisterClasses
  48. // ---------------------------------------------------------------------------
  49. //
  50.  
  51. void
  52. CAMReminderApp::RegisterClasses()
  53. {
  54.     RegisterAllPPClasses();
  55.             // replace to register only classes that we use.
  56.             // windows know what classes they use
  57.             // so call static functions in each window/dialog,
  58. }
  59.  
  60. // ---------------------------------------------------------------------------
  61. //        • SetUpMenus
  62. // ---------------------------------------------------------------------------
  63. //
  64.  
  65. void
  66. CAMReminderApp::SetUpMenus()
  67. {
  68.  
  69. }
  70.  
  71. // ---------------------------------------------------------------------------
  72. //        • StartUp
  73. // ---------------------------------------------------------------------------
  74. //    The application calls this member function automatically when the application
  75. //    is opened
  76.  
  77. void
  78. CAMReminderApp::StartUp()
  79. {
  80.     ObeyCommand(cmd_Open, nil);
  81. }
  82.  
  83. //----------
  84. // called from CNeoAppPP in response to New command
  85.  
  86. CNeoDoc*
  87. CAMReminderApp::createDocument()
  88. {
  89.     CAMReminderDoc *        document = nil;
  90.  
  91.     VOLATILE(document);
  92.  
  93.     NEOTRY {
  94.         /*
  95.          * Create your document.
  96.          *
  97.          * The arguments indicate whether the document is...
  98.          *    printable (true),
  99.          *    a new file (true),
  100.          *    remote (false).
  101.          */
  102.         document = new CAMReminderDoc (true, true, false);
  103.         NeoFailNil (document);
  104.         document->SetSuperCommander (this);
  105.  
  106.         // Call the document’s newDatabase method.
  107.         document->newDatabase();
  108.     }
  109.     NEOCATCH {
  110.         /*
  111.          * This exception handler gets executed if a failure occurred
  112.          * anywhere within the scope of the above NEOTRY block. Since
  113.          * this indicates that a new doc could not be created, we
  114.          * check if an object had been allocated and if it has, delete
  115.          * it. The exception will propagate up to the next exception
  116.          * handler, which displays an error alert.
  117.          */
  118.         if (document != nil) {
  119.             delete document;
  120.             document = nil;
  121.         }
  122.     }
  123.     NEOENDTRY;
  124.  
  125.     return document;
  126. }
  127.  
  128. //----------
  129. // called from SendAEOpenDoc in response to Open command
  130.  
  131. void
  132. CAMReminderApp::OpenDocument(
  133.     FSSpec    *inMacFSSpec)
  134. {
  135.     CAMReminderDoc *        document    = nil;
  136.  
  137.     VOLATILE(document);
  138.  
  139.     NEOTRY {
  140.         // Our parent will check to see if this is a document we have
  141.         // already opened. If we find the file already open by the app,
  142.         // then fDocument will refer to it. If the file is opened but
  143.         // not by this app, then the parent will signal a failure.
  144.         inherited::OpenDocument (inMacFSSpec);
  145.         if (fDocument != nil)
  146.             return;
  147.  
  148.         // Create your document.
  149.         document = new CAMReminderDoc (true, false, false);
  150.         NeoFailNil (document);
  151.         document->SetSuperCommander (this);
  152.  
  153.         // Call the document's openDatabase method. The document will open
  154.         // a window, open the file specified in the file specification
  155.         // record, and display it in its window.
  156.         document->openFile (inMacFSSpec);
  157.     }
  158.     NEOCATCH {
  159.         /*
  160.          * This exception handler gets executed if a failure occurred
  161.          * anywhere within the scope of the NEOTRY block above. Since
  162.          * this indicates that the document could not be opened, we
  163.          * send it a unrefer message. The exception will propagate up to
  164.          * the event loop's exception handler, which handles displaying
  165.          * an error alert.
  166.          */
  167.         if (document != nil) {
  168.             delete document;
  169.             document = nil;
  170.         }
  171.     }
  172.     NEOENDTRY;
  173. }
  174.  
  175. //----------
  176. // called from LDocApplication in response to Open command
  177.  
  178. void
  179. CAMReminderApp::ChooseDocument()
  180. {
  181.     SFTypeList            typeList;
  182.     short                numTypes;
  183.     StandardFileReply    macFileReply;
  184.  
  185.     typeList[0] = kFileType;
  186.     numTypes = 1;
  187.  
  188.     UDesktop::Deactivate();
  189.     ::StandardGetFile(nil, numTypes, typeList, &macFileReply);
  190.     UDesktop::Activate();
  191.  
  192.     if (macFileReply.sfGood) {
  193.         SendAEOpenDoc(macFileReply.sfFile);
  194.     }
  195. }
  196.  
  197. //----------
  198. void
  199. CAMReminderApp::DoDeleteReminder ()
  200. {
  201. }
  202.  
  203. // ---------------------------------------------------------------------------
  204. //        • ObeyCommand
  205. // ---------------------------------------------------------------------------
  206. //    Respond to commands
  207.  
  208. Boolean
  209. CAMReminderApp::ObeyCommand(
  210.     CommandT    inCommand,
  211.     void        *ioParam)
  212. {
  213.     Boolean    cmdHandled = true;
  214.  
  215.     switch (inCommand) {
  216.  
  217.     // +++ Add cases here for the commands you handle
  218.     //        Remember to add same cases to FindCommandStatus below
  219.     //        to enable/disable the menu items for the commands
  220.  
  221.  
  222.     case cmdDeleteReminder:
  223.         DoDeleteReminder ();
  224.         break;
  225.  
  226.     default:
  227.             cmdHandled = CNeoAppNative::ObeyCommand(inCommand, ioParam);
  228.         break;
  229.     }
  230.  
  231.     return cmdHandled;
  232. }
  233.  
  234.  
  235. // ---------------------------------------------------------------------------
  236. //        • FindCommandStatus
  237. // ---------------------------------------------------------------------------
  238. //    Pass back status of a (menu) command
  239.  
  240. void
  241. CAMReminderApp::FindCommandStatus(
  242.     CommandT    inCommand,
  243.     Boolean        &outEnabled,
  244.     Boolean        &outUsesMark,
  245.     Char16        &outMark,
  246.     Str255        outName)
  247. {
  248.     outUsesMark = false;
  249.  
  250.     switch (inCommand) {
  251.  
  252.     // +++ Add cases here for the commands you handle
  253.  
  254.     case cmdDeleteReminder:
  255.         outEnabled = true;
  256.         break;
  257.  
  258.     default:
  259.             CNeoAppNative::FindCommandStatus(inCommand, outEnabled, outUsesMark,
  260.                                                 outMark, outName);
  261.         break;
  262.     }
  263. }
  264.