home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / OpenDoc / CreditNow! / CreditNow! Source / CPCreditNowDemo.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-30  |  9.9 KB  |  324 lines  |  [TEXT/MPCC]

  1. /*
  2.     File:        CPCreditNowDemo.cpp
  3.  
  4.  
  5. Modifications to support the CreditNOWDemo are surrounded by: //AET
  6. comment lines. Beginning of a block has a trailing <<, end has >>.
  7.  
  8.  
  9. There are 6 text input fields, two text output fields, and a button.
  10. The button is a real ToolBox control. The text fields are driven from
  11. Text Edit via TENew().
  12.  
  13. The Tab key moves you from field to field. The Return and Enter keys
  14. cause the "Authorize" function to be called. When "tab key" is pressed a 
  15. Validate function is called for the text field. Validate currently does
  16. nothing.
  17.  
  18. CreateTextFields() sets the rectangles and creates the TextEdit records for
  19. the input and output fields. It is called by FacetAdded(). The RegisterIdle()
  20. is also done there.
  21.  
  22. The text fields are created and accessed within CFocus blocks.
  23.  
  24. CreateButton() creates the Button which is called from FacetAdded(),
  25. and drawn in the Draw method. MyUsedShapeHandleMouseDown calls Authorize()
  26. to construct and send the AppleEvent to the CreditNOW! server.
  27.  
  28.  
  29.  
  30. Problems:
  31.  
  32. •Before the TextEdit calls were surrounded with CFocus clicking on the 
  33. button worked. Now the ODPoint comes back with a ridiculous value and "hit"
  34. in the MyHandleMouseDown method is zero. The real mouse location in the window
  35. is within the bounds of the button. So I ignore the OpenDoc hit testing and
  36. just do real QuickDraw control hit testing stuff.
  37.  
  38. •Somebody changes the window title back to "untitled <date>" after I
  39. painstakingly set it to what I want!!!
  40.  
  41. •I can't get rid of the "Dont Save, Cancel, Save" dialog even though I dont
  42. want to save any data!!
  43.  
  44.  
  45.  
  46.     Contains:    CPCreditNowDemo OpenDoc part editor class implementation.
  47.                 Built using PartMaker, then modified.
  48.     Written by:    PartMaker
  49.  
  50.     Change History (most recent first):
  51.  
  52.     <3>    4/14/95    JS        Updated for Developer Release 2
  53.     <4>    3/8/95    JS        Updated to b1c13/c14
  54.     <3>    3/8/95    RA        Add tokenized kODPresDefault param to RegisterWindow().
  55.     <2>    2/21/95    RA        Add kODFrameObject param to RegisterWindow().
  56.     <1>    2/2/95    RA        first checked in
  57.     <0>    PartMaker source by E. Soldan, T. Çelik, J. Alfke, R. Adkins, D. Nelson, J. Schalk
  58. */
  59.  
  60. #ifndef _CREDITNOWDEMO_
  61. #include "CPCreditNowDemo.h"
  62. #endif
  63.  
  64. #ifndef SOM_ODDispatcher_xh
  65. #include <Disptch.xh>
  66. #endif
  67.  
  68. //----------------------------------------------------------------------------------------
  69.  
  70. CPCreditNowDemo::CPCreditNowDemo()
  71. {
  72.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Constructor
  73.     EnteringMethod("\pCPCreditNowDemo::CPCreditNowDemo");
  74.  
  75.     fDirty                = kODFalse;
  76.     fWindowID            = 0;
  77.     fSession              = kODNULL;
  78.     fSelf                   = kODNULL;
  79.     fStorageUnit        = kODNULL;
  80.     fMenuBar              = kODNULL;
  81.     fDraftKey             = 0;
  82.     fThumbnailPicture    = kODNULL;
  83.  
  84.     // Note that fFrameList
  85.     //                         and fTextFields
  86.     // are static fields, and therefore
  87.     // constructors are automatically called before
  88.     // CPCreditNOWDemo constructor.
  89. //AET<<
  90.     fAuthButton = kODNULL;
  91.     fCurrentField = kODNULL;
  92.     fAddressVerify = kODNULL;
  93.     fAuthorization = kODNULL;
  94.     fFacet = kODNULL;
  95. //AET>>
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99.  
  100. CPCreditNowDemo::~CPCreditNowDemo()
  101. {
  102.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Destructor
  103.     EnteringMethod("\pCPCreditNowDemo::~CPCreditNowDemo");
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107.  
  108. void CPCreditNowDemo::Release(Environment* ev)
  109. {
  110.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Release
  111.     EnteringMethod("\pCPCreditNowDemo::Release");
  112.  
  113.     if (fSelf->GetRefCount(ev) == 1) {
  114.         // Here is where you would unregister idle time for the part if
  115.         // have registered time.  Note that if you unregister without
  116.         // registering, OpenDoc will crash.  It's not just a simple
  117.         // look-up-and-if-there-remove kind of operation.
  118.  
  119.         // Note that if you unregister idle here, OpenDoc will need to
  120.         // call Release (here) due to it.  This means that when we call
  121.         // to unregister the idle, we are nesting calls to Release.
  122.         // Due to this, I return out of each case, just to make the
  123.         // flow of control of the call(s) to Release more straightforward.
  124.  
  125.         // Note that if you are going to use idle registration, you will
  126.         // need to include "Disptch.h"
  127.  
  128. //AET<<
  129.         ( fSession->GetDispatcher(ev) )->UnregisterIdle(ev, fSelf, kODNULL);
  130. //AET>>
  131.         return;
  132.     }
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136.  
  137. ODID CPCreditNowDemo::Open(Environment* ev, ODFrame* frame)
  138. {
  139.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Open
  140.     EnteringMethod("\pCPCreditNowDemo::Open");
  141.  
  142.     ODID windowID;
  143.     ODWindow* window = kODNULL;
  144.  
  145.     if (frame) // Doing a View As Window or Open Root
  146.     {
  147.         if (frame->IsRoot(ev))
  148.         {
  149.             windowID = this->PrivOpenSavedWindow(ev, frame);
  150.         }
  151.         else
  152.         {
  153.             //ClockFrame* clockFrame = (ClockFrame*) frame->GetPartInfo(ev);
  154.             //if (clockFrame)
  155.             //    windowID = clockFrame->ViewInWindow(ev);
  156.         }
  157.     }
  158.     else
  159.     {
  160.         windowID = this->PrivOpenInitialWindow(ev);
  161.     }
  162.     return windowID;
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166.  
  167. ODWindow*  CPCreditNowDemo::PrivCreateWindow(Environment *ev,ODFrame* sourceFrame)
  168. {
  169.     // get rectangle
  170.     Rect windRect;
  171. //AET<<
  172.     ::SetRect(&windRect, 4, GetMBarHeight() + 24,
  173.             320,
  174.             295);        // rgacsun
  175. //AET>>
  176.  
  177.     // get title
  178.     Str255        windowTitleStr = "\pCreditNow!™ Demo";    // rgac
  179.  
  180.     ODPlatformWindow platformWindow = ::NewCWindow(kODNULL,
  181.                                                     &windRect,
  182.                                                     windowTitleStr,
  183.                                                     false,
  184.                                                     rDocProc,            //AET
  185.                                                     (WindowPtr)-1L,
  186.                                                     true,
  187.                                                     kODNULL);
  188.  
  189.     ODBoolean isRoot = ((sourceFrame == kODNULL) || sourceFrame->IsRoot(ev));
  190.  
  191.     ODWindow* window = fSession->GetWindowState(ev)->RegisterWindow(ev,
  192.                             platformWindow,                                // newWindow
  193.                             isRoot ?                                     // Persistent
  194.                             kODFrameObject:                             // Non-Persistent
  195.                             kODNonPersistentFrameObject,                // frameType
  196.                             isRoot,                                        // isRootWindow
  197.                             this->PrivWantResizableWindow(),                    // isResizable
  198.                             kODFalse,                                    // isFloating
  199.                             kODFalse,                                    // shouldSave    rgac
  200.                             fSelf,                                        // rootPart
  201.                             fSession->Tokenize(ev, kODViewAsFrame),        // viewType
  202.                             fSession->Tokenize(ev, kODPresDefault),        // presentation
  203.                             sourceFrame);                                // sourceFrame
  204.     return window;
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208.  
  209. ODID CPCreditNowDemo::PrivOpenInitialWindow(Environment* ev)
  210. {
  211.     ODWindow* window = this->PrivCreateWindow(ev, kODNULL);
  212.     ODID windowID = window->GetID(ev);
  213.     window->Open(ev);
  214.     window->Show(ev);
  215.     window->Select(ev);    
  216.     return windowID;            
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220.  
  221. ODID CPCreditNowDemo::PrivOpenSavedWindow(Environment* ev, ODFrame* frame)
  222. {
  223.     ODWindow* window = kODNULL;
  224.     WindowProperties props;
  225.     
  226.     if (BeginGetWindowProperties(ev, frame, &props))
  227.     {
  228.         ODPlatformWindow platformWindow = NewCWindow(kODNULL, &(props.boundsRect), props.title, 
  229.                     kODFalse, props.procID, (WindowPtr)-1L, props.hasCloseBox, props.refCon);
  230.         
  231.         window = fSession->GetWindowState(ev)->RegisterWindowForFrame(ev, 
  232.                                         platformWindow, 
  233.                                         frame,
  234.                                         props.isRootWindow,    // Keeps draft open
  235.                                         kODTrue,    // Is resizable
  236.                                         kODFalse,    // Is floating
  237.                                         kODFalse,    // shouldSave    rgac
  238.                                         props.sourceFrame);
  239.         EndGetWindowProperties(ev, &props); // Release source frame
  240.                 
  241.         window->Open(ev);
  242.         window->Show(ev);
  243.         return window->GetID(ev);
  244.     }
  245.     else 
  246.         return 0;
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250.  
  251. ODBoolean CPCreditNowDemo::PrivWantResizableWindow()
  252. {
  253.     return kODFalse;
  254. }
  255.  
  256. //----------------------------------------------------------------------------------------
  257.  
  258. void CPCreditNowDemo::ReleaseAll(Environment* ev)
  259. {
  260.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_ReleaseAll
  261.     EnteringMethod("\pCPCreditNowDemo::ReleaseAll");
  262.  
  263.     if (fMenuBar != kODNULL)
  264.         fMenuBar->Release(ev);
  265. }
  266.  
  267. //----------------------------------------------------------------------------------------
  268.  
  269. void CPCreditNowDemo::PrivInvalAllDisplayFrames(Environment* ev)
  270. {
  271.     // This is just a CPCreditNowDemo utility method.
  272.  
  273.     for (FrameLink *fl = fDisplayFrames.First(); fl->Frame(); fl = fl->Next())
  274.         fl->Frame()->Invalidate(ev, kODNULL, kODNULL);
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. // Storage protocol
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void CPCreditNowDemo::IncrementRefCount(Environment* ev)
  282. {
  283.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_IncrementRefCount
  284.     EnteringMethod("\pCPCreditNowDemo::IncrementRefCount");
  285. }
  286.  
  287. //----------------------------------------------------------------------------------------
  288.  
  289. void CPCreditNowDemo::CloneInto(Environment* ev, ODDraftKey key, 
  290.         ODStorageUnit* destinationSU, ODFrame* initiatingFrame)
  291. {
  292.     // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_CloneInto
  293.     EnteringMethod("\pCPCreditNowDemo::CloneInto");
  294.  
  295.     // We must first verify that we've never written to this storage unit.
  296.     // If we have, we should do nothing, otherwise we need to write out
  297.     // the current state of the part content.
  298.     
  299.     if ( destinationSU->Exists(ev, kODPropContents, kCreditNowDemoKind, 0) == kODFalse )
  300.     {
  301.         // Add the properties we need to successfully externalize
  302.         // ourselves into the destination storage unit.
  303.         this->PrivCheckAndAddProperties(ev, destinationSU);
  304.                 
  305.         // Write out the part's state information.
  306.         this->PrivExternalizeStateInfo(ev, destinationSU, key, initiatingFrame);
  307.             
  308.         // Write out the part's content.
  309.         this->PrivExternalizeContent(ev, destinationSU);
  310.     }
  311. }
  312.  
  313. //----------------------------------------------------------------------------------------
  314.  
  315. ODSize CPCreditNowDemo::Purge(Environment* ev, ODSize size)
  316. {
  317.     // 
  318.     ODUnused(size);
  319.     EnteringMethod("\pCPCreditNowDemo::Purge");
  320.  
  321.     // CPCreditNowDemo doesn't do anything here.
  322.     return 0;
  323. }
  324.