home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / CyberStarter / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.0 KB  |  193 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Frame.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FRAME_H
  11. #include "Frame.h"
  12. #endif
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. // ----- Framework Includes -----
  19. #ifndef FWUTIL_H
  20. #include "FWUtil.h"
  21. #endif
  22.  
  23. #ifndef FWCONTXT_H
  24. #include "FWContxt.h"
  25. #endif
  26.  
  27. #ifndef FWRECSHP_H
  28. #include "FWRecShp.h"
  29. #endif
  30.  
  31. #ifndef FWEXTMGR_H
  32. #include "FWExtMgr.h"
  33. #endif
  34.  
  35. // ----- Cyberdog Support -----
  36.  
  37. #ifndef __CYBERDOG__
  38. #include <Cyberdog.h>
  39. #endif
  40.  
  41. #ifndef SOM_CyberServiceMenu_xh
  42. #include <CyberServiceMenu.xh>
  43. #endif
  44.  
  45. #ifndef SOM_CyberSession_xh
  46. #include <CyberSession.xh>
  47. #endif
  48.  
  49. //========================================================================================
  50. // 
  51. //========================================================================================
  52.  
  53. #ifdef FW_BUILD_MAC
  54. #pragma segment CFrame
  55. #endif
  56.  
  57. //========================================================================================
  58. // Class CFrame
  59. //========================================================================================
  60.  
  61. FW_DEFINE_AUTO(CFrame)
  62.  
  63. //----------------------------------------------------------------------------------------
  64. //     CFrame::CFrame
  65. //----------------------------------------------------------------------------------------
  66.  
  67. CFrame::CFrame (Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CPart* part) :
  68.     FW_CFrame(ev, odFrame, presentation, part),
  69.     fPart(part)
  70. {
  71.     FW_END_CONSTRUCTOR
  72. }
  73.  
  74. //----------------------------------------------------------------------------------------
  75. //     CFrame::~CFrame
  76. //----------------------------------------------------------------------------------------
  77.  
  78. CFrame::~CFrame()
  79. {
  80.     FW_START_DESTRUCTOR
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //     CFrame::Draw
  85. //----------------------------------------------------------------------------------------
  86.  
  87. void CFrame::Draw (Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  88. {
  89.     FW_CViewContext fc (ev, this, odFacet, invalidShape);
  90.     FW_CRect invalidRect;
  91.     fc.GetClipRect (invalidRect);
  92.     ::EraseRect (&fc.LogicalToDevice (invalidRect));
  93.     
  94.     if (!IsRoot(ev)) // draw a border to differentiate us from other parts
  95.          FW_CRectShape::RenderRect (fc, GetBounds(ev), FW_kFrame);
  96.     
  97.     DrawUpdate (ev, fc);
  98. }
  99.  
  100. //----------------------------------------------------------------------------------------
  101. //     CFrame::DrawUpdate
  102. //----------------------------------------------------------------------------------------
  103.  
  104. void CFrame::DrawUpdate (Environment *ev, FW_CGraphicContext & gc)
  105. {
  106.     // CONTENTDATA
  107.     
  108.     // I call this to draw the content w/o erasing first (avoids flashiness)
  109.     // This is useful during incremental downloads when we only need to display 
  110.     // additional content
  111.     
  112.     // When we're using platform graphics (as opposed to ODF's FWGraphx module) we have
  113.     // to reset things a lot - other parts tend to leave the GrafPort in a random state.
  114.     ::TextFont(1);
  115.     ::TextFace(0);
  116.     ::TextSize(0);
  117.     ::ForeColor (blackColor);
  118.     ::BackColor (whiteColor);
  119.     
  120.     FW_CRect bounds (FW_kZeroPoint, GetSize(ev));
  121.     FW_PlatformRect pBounds = gc.LogicalToDevice (bounds);
  122.     ::InsetRect (&pBounds, 4, 4);
  123.     ::HLock (fPart->fDownloadedText);
  124.     unsigned long size = GetHandleSize(fPart->fDownloadedText);
  125.     if (size > 32767) size = 32767; // TE can't draw it, but we shouldn't truncate it
  126.     ::TETextBox (*fPart->fDownloadedText, size, &pBounds, teFlushDefault);
  127.     ::HUnlock (fPart->fDownloadedText);
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //     CFrame::FrameShapeChanged
  132. //----------------------------------------------------------------------------------------
  133.  
  134. void CFrame::FrameShapeChanged (Environment* ev)
  135. {
  136.     FW_CFrame::FrameShapeChanged (ev);
  137.     Invalidate(ev);
  138. }
  139.  
  140. //----------------------------------------------------------------------------------------
  141. //     CFrame::FocusStateChanged
  142. //----------------------------------------------------------------------------------------
  143.  
  144. void CFrame::FocusStateChanged (Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  145. {
  146.     // CYBERDOG
  147.     if (focus == FW_CPart::fgMenuFocusToken) {
  148.         FW_CCyberdogHelper* helper = fPart->GetCyberdogHelper();
  149.         if (helper && helper->GetCyberServiceMenu()) {
  150.             if (newState)
  151.                 helper->GetCyberServiceMenu()->MenuFocusAcquired (ev, GetODFrame(ev));
  152.             else
  153.                 helper->GetCyberServiceMenu()->MenuFocusLost (ev, GetODFrame(ev));
  154.         }
  155.     }
  156.     
  157.     FW_CFrame::FocusStateChanged(ev, focus, newState, newOwner);    
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    CFrame::HandleWindowEvent
  162. //----------------------------------------------------------------------------------------
  163.  
  164. FW_Handled CFrame::HandleWindowEvent (Environment* ev, const FW_CMacWindowEvent& windowEvent)
  165. {
  166.     // *** Cyberdog Support ***
  167.     // Sorry about this mess. At some point this code may be moved into 
  168.     // FW_CFrame or someplace similar. Basically we're implementing the Cyberdog 
  169.     // recipe for handling window-closing (it's different than normal OpenDoc
  170.     // window-closing). You can just copy this code into your Frame subclass.
  171.     
  172.     FW_Handled handled = FW_kNotHandled;
  173.     
  174.     if (windowEvent.GetMessage() == inGoAway) {
  175.         FW_CExtensionManager* manager = GetPart(ev)->GetExtensionManager(ev);
  176.         FW_ASSERT (manager);
  177.         ODExtension* extension = manager->AcquireExtension (ev, kCyberPartExtension, FW_kDontCreateExtension);
  178.         if (extension) {
  179.             CyberPartExtension* cextension = (CyberPartExtension*) extension;
  180.             CyberSession* cyberSession = cextension->GetCyberSession (ev);
  181.             FW_ASSERT (cyberSession);
  182.             if (cyberSession && cyberSession->CloseCyberDraftWindow (ev, GetPart(ev)->GetODPart(ev)))
  183.                 handled = FW_kHandled;
  184.         }
  185.     }
  186.     
  187.     if (handled == FW_kNotHandled)
  188.         handled = FW_CFrame::HandleWindowEvent (ev, windowEvent);
  189.     
  190.     return handled;
  191. }
  192.  
  193.