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 / Developer University / DU Projects / Graphics3D / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  5.4 KB  |  194 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef CONTENT_H
  10. #include "Content.h"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. #ifndef COMMANDS_H
  18. #include "Commands.h"
  19. #endif
  20.  
  21. #ifndef DEFINES_K
  22. #include "Defines.k"            // command numbers
  23. #endif
  24.  
  25. // ----- Framework Layer -----
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"            // FW_CViewContext
  28. #endif
  29.  
  30. #ifndef FWPRHDLR_H
  31. #include "FWPrHdlr.h"            // FW_CPrintHandler
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35. #ifndef FWMENU_H
  36. #include "FWMenu.h"                // FW_CMenuBar, etc.
  37. #endif
  38.  
  39. #ifndef FWEVENT_H
  40. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  41. #endif
  42.  
  43. #ifndef FWRECT_H
  44. #include <FWRect.h>                // FW_CRect
  45. #endif
  46.  
  47. #ifndef FWFILESP_H
  48. #include "FWFileSp.h"            // FW_PFileSpecification
  49. #endif
  50.  
  51. #ifndef FWFILEOP_H
  52. #include "FWFileOp.h"            // FW_CChooseFile
  53. #endif
  54.  
  55. //========================================================================================
  56. #ifdef FW_BUILD_MAC
  57. #pragma segment Graphics3D
  58. #endif
  59.  
  60. FW_DEFINE_AUTO(CGraphics3DFrame)
  61.  
  62. //========================================================================================
  63. CGraphics3DFrame::CGraphics3DFrame(Environment* ev, ODFrame* odFrame, 
  64.                                     FW_CPresentation* presentation, 
  65.                                     CGraphics3DContent* content)
  66.   : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  67.   fViewer(NULL)
  68. {
  69. }
  70.  
  71. //----------------------------------------------------------------------------------------
  72. CGraphics3DFrame::~CGraphics3DFrame()
  73. {
  74.     ::Q3ViewerDispose(fViewer);
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. void 
  79. CGraphics3DFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  80. {        
  81.     FW_CFrame::FacetAdded(ev, facet, facetCount);
  82.     ODPlatformWindow windowPtr = this->GetWindow(ev)->GetPlatformWindow(ev);
  83.     // Get rectangle enclosing the window’s content region.
  84.     Rect myRect = windowPtr->portRect;
  85.     // Create a new viewer object in entire content region
  86.     fViewer = ::Q3ViewerNew((CGrafPtr)windowPtr, &myRect, kQ3ViewerDefault);
  87.     FW_CRect frameRect = this->GetBounds(ev);
  88.     
  89. /*    FW_CAcquiredODTransform tForm = facet->AcquireExternalTransform(ev, facet->GetCanvas(ev));
  90.     ODPoint odPt;
  91.     tForm->GetOffset(ev, &odPt);
  92.     FW_CPoint fwPt(odPt);
  93.     frameRect.Offset(fwPt.x, fwPt.y);
  94. */    
  95.     Rect r = frameRect.AsPlatformRect();
  96.     short anErr = Q3ViewerSetBounds(fViewer, &r);
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. void 
  101. CGraphics3DFrame::FrameShapeChanged(Environment* ev)
  102. {
  103.     FW_CFrame::FrameShapeChanged(ev);
  104.     FW_CRect frameRect = this->GetBounds(ev);    // Get new frame rect
  105.     Rect r = frameRect.AsPlatformRect();
  106.     short anErr = ::Q3ViewerSetBounds(fViewer, &r);
  107.     this->Invalidate(ev, frameRect);            
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. void 
  112. CGraphics3DFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  113. {
  114.     FW_CPlatformGraphicContext pc(ev, odFacet, invalidShape);
  115.     FW_CRect frameRect = this->GetBounds(ev);    // Get new frame rect
  116.     Rect r = frameRect.AsPlatformRect();
  117.     short anErr = ::Q3ViewerSetBounds(fViewer, &r);
  118.     
  119.     ::Q3ViewerDraw(fViewer);
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. FW_Handled 
  124. CGraphics3DFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  125. {    
  126.     FW_UNUSED(ev);
  127.     ODEventData* eventRec = ((FW_CMouseEvent)theMouseEvent).GetPlatformEvent();
  128.     FW_Boolean aBool = ::Q3ViewerEvent(fViewer, eventRec);
  129.     return TRUE;
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. FW_Handled 
  134. CGraphics3DFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  135.                                                     FW_Boolean isRoot)    // Override
  136. {
  137.     FW_UNUSED(isRoot);
  138.     if (hasMenuFocus) {
  139.         menuBar->EnableCommand(ev, cOpenFileCmdID, TRUE);
  140.     }
  141.     return false;
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. FW_Handled 
  146. CGraphics3DFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  147. {
  148.     FW_Handled menuHandled = true;
  149.     switch (theMenuEvent.GetCommandID(ev)) { 
  150.         case cOpenFileCmdID:         
  151.             OSType fileType = '3DMF';
  152.             FW_COpenFileParameters openFileParam(fileType, NULL);
  153.             FW_OFileSpecification* fileSpec = FW_CChooseFile::ChooseFileToOpen(openFileParam);
  154.             FSSpec macSpec;
  155.             fileSpec->MacGetFSSpec(ev, &macSpec);
  156.             short refNum;
  157.             short anErr = FSpOpenDF(&macSpec, fsCurPerm, &refNum);
  158.             anErr = ::Q3ViewerUseFile(fViewer, refNum);
  159.             this->FrameShapeChanged(ev);
  160. //            FW_CRect frameRect = this->GetBounds(ev);
  161. //            this->Invalidate(ev, frameRect);            
  162.             break;
  163.         
  164.         default:
  165.             menuHandled = false;
  166.     }
  167.     return menuHandled;
  168. }
  169.  
  170. //------------------------------------------------------------------------------
  171. FW_CPrintHandler* 
  172. CGraphics3DFrame::NewPrintHandler(Environment* ev)
  173. {
  174.     FW_CPart* part = GetPart(ev);
  175.     return new FW_CPrintHandler(part, this);
  176. }
  177.  
  178. //------------------------------------------------------------------------------
  179. FW_Boolean 
  180. CGraphics3DFrame::IsCurrentlyPrintable(Environment* ev) const
  181. {
  182.     FW_UNUSED(ev);
  183.     return TRUE;
  184. }
  185.  
  186. //------------------------------------------------------------------------------
  187. void 
  188. CGraphics3DFrame::GetPrintContentExtent(Environment *ev, FW_CPoint& extent) const
  189. {
  190.     FW_CRect frameRect = this->GetBounds(ev);
  191.     extent = frameRect.Size();
  192. }
  193.  
  194.