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 / Tools & Goodies / IntlTest / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-09-12  |  8.5 KB  |  315 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. #include "IntlTest.hpp"
  11.  
  12. #ifndef FRAME_H
  13. #include "Frame.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef COMMANDS_H
  21. #include "Commands.h"
  22. #endif
  23.  
  24. #ifndef DEFINES_K
  25. #include "Defines.k"
  26. #endif
  27.  
  28. #ifndef VIEW_H
  29. #include "View.h"
  30. #endif
  31.  
  32. #ifndef SELECT_H
  33. #include "Select.h"
  34. #endif
  35.  
  36. #ifndef EDITVIEWS_H
  37. #include "EditViews.h"
  38. #endif
  39.  
  40. // ----- Framework Layer -----
  41.  
  42. #ifndef FWCONTXT_H
  43. #include "FWContxt.h"
  44. #endif
  45.  
  46. #ifndef FWPRESEN_H
  47. #include "FWPresen.h"
  48. #endif
  49.  
  50. #ifndef FWSELECT_H
  51. #include "FWSelect.h"
  52. #endif
  53.  
  54. #ifndef FWEDVIEW_H
  55. #include "FWEdView.h"
  56. #endif
  57.  
  58. #ifndef FWGROWBX_H
  59. #include "FWGrowBx.h"
  60. #endif
  61.  
  62. #ifndef FWIDLE_H
  63. #include "FWIdle.h"
  64. #endif
  65.  
  66. #ifndef FWSCLBAR_H
  67. #include "FWSclBar.h"
  68. #endif
  69.  
  70. #ifndef FWSTATIC_H
  71. #include "FWStatic.h"
  72. #endif
  73.  
  74. #ifndef FWTABBER_H
  75. #include "FWTabber.h"
  76. #endif
  77.  
  78. // ----- OS Layer -----
  79.  
  80. #ifndef FWMENU_H
  81. #include "FWMenu.h"
  82. #endif
  83.  
  84. #ifndef FWEVENT_H
  85. #include "FWEvent.h"
  86. #endif
  87.  
  88. // ----- Graphic Includes -----
  89.  
  90. #ifndef FWRECT_H
  91. #include "FWRect.h"
  92. #endif
  93.  
  94. #ifndef FWTXTBOX_H
  95. #include "FWTxtBox.h"
  96. #endif
  97.  
  98. #ifndef FWRECSHP_H
  99. #include "FWRecShp.h"
  100. #endif
  101.  
  102. // ----- OpenDoc Includes -----
  103.  
  104. #ifndef SOM_Module_OpenDoc_StdProps_defined
  105. #include <StdProps.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODDragItemIterator_xh
  109. #include <DgItmIt.xh>
  110. #endif
  111.  
  112. //========================================================================================
  113. // Runtime Information
  114. //========================================================================================
  115.  
  116. #ifdef FW_BUILD_MAC
  117. #pragma segment odfIntlTest
  118. #endif
  119.  
  120. //========================================================================================
  121. // CIntlTestFrame class
  122. //========================================================================================
  123.  
  124. FW_DEFINE_AUTO(CIntlTestFrame)
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // CIntlTestFrame constructor
  128. //----------------------------------------------------------------------------------------
  129. CIntlTestFrame::CIntlTestFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CIntlTestPart* part) :
  130.     FW_CFrame(ev, odFrame, presentation, part),
  131.     FW_MDroppableFrame(ev, this),
  132.     FW_MReceiver(),
  133.     fTestPart(part),
  134.     fTestView(NULL),
  135.     fTestSelection((CIntlTestSelection*)presentation->GetSelection(ev)),
  136.     fViewTabber(NULL)
  137. {
  138.     FW_CIdler* idler = FW_NEW(FW_CIdler, (this, 15));
  139.     idler->RegisterIdle(ev);                
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. // CIntlTestFrame destructor
  144. //----------------------------------------------------------------------------------------
  145.  
  146. CIntlTestFrame::~CIntlTestFrame()
  147. {
  148.     // fViewTabber is deleted automatically because it's an attached event handler
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. // CIntlTestFrame::Draw
  153. //----------------------------------------------------------------------------------------
  154.  
  155. void CIntlTestFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  156. {
  157.     FW_CRect frameRect = GetBounds(ev);
  158.     FW_CRect centerRect(GetFrame(ev)->GetContentView(ev)->GetBounds(ev));
  159.     
  160.     // Draw a gray background around the content view if it's smaller
  161.     if (centerRect.right < frameRect.right || centerRect.bottom < frameRect.bottom ) {
  162.  
  163.         FW_CViewContext vc(ev, this, odFacet, invalidShape);
  164.     
  165.         // Draw outside the center view to avoid flashing 
  166.         FW_CAcquiredODShape aqPaneShape = ::FW_NewODShape(ev, frameRect);
  167.         FW_CAcquiredODShape aqCenterShape = ::FW_NewODShape(ev, centerRect);
  168.         aqPaneShape->Subtract(ev, aqCenterShape);
  169.     
  170.         FW_CRegionShape::RenderRegion(vc, aqPaneShape, FW_kFill, FW_kRGBLightGray);
  171.     
  172.         // Draw a shadow frame around the content view
  173.         centerRect.Inset(-FW_IntToFixed(1),-FW_IntToFixed(1));
  174.          FW_CRectShape::RenderRect(vc, centerRect, FW_kFrame);
  175.          FW_CPoint p1(centerRect.left, centerRect.bottom);
  176.          FW_CPoint p2(centerRect.right, centerRect.bottom);
  177.          FW_CPoint p3(centerRect.right, centerRect.top);
  178.          FW_CLineShape::RenderLine(vc, p1, p2);
  179.          FW_CLineShape::RenderLine(vc, p2, p3);
  180.      }
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. //    CIntlTestFrame::NewClipboardCommand
  185. //----------------------------------------------------------------------------------------
  186.  
  187. FW_CClipboardCommand* CIntlTestFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  188. {
  189.     FW_CEditView* editView = NULL;
  190.     ODID id = this->GetActiveEditViewId(ev);
  191.     if (id)
  192.     {
  193.         editView = this->FindEditView(ev, id);
  194.     }
  195.  
  196.     CIntlTestEditCommand* cmd = FW_NEW(CIntlTestEditCommand, (ev, commandID, this, fTestSelection, editView, FW_kCanUndo));
  197.     return cmd;
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    CIntlTestFrame::NewDropCommand
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_CDropCommand* CIntlTestFrame::NewDropCommand(Environment* ev,
  205.                                                 FW_CFrame* frame,
  206.                                                 ODDragItemIterator* dropInfo, 
  207.                                                 ODFacet* odFacet, 
  208.                                                 const FW_CPoint& dropPoint)
  209. {
  210.     FW_UNUSED(frame);
  211.  
  212.     FW_CEditView* dropView = this->HitTest(ev, dropPoint);
  213.     if (dropView)
  214.         return FW_NEW(CIntlTestDropCommand, (ev, this, dropView, fTestSelection, dropInfo, odFacet, dropPoint));
  215.  
  216.     // dropPoint isn't in an edit view
  217.     return NULL;
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    CIntlTestFrame::CreateSubViews
  222. //----------------------------------------------------------------------------------------
  223. void CIntlTestFrame::CreateSubViews(Environment* ev)
  224. {
  225.     // ----- Create the content view
  226.     FW_CPoint extent;
  227.     FW_CRect contentRect;
  228.     GetContentRect(ev, contentRect, extent);
  229.     CIntlTestView* contentView = new CIntlTestView(ev, this, contentRect, extent);
  230.     contentView->BecomeContentView(ev);
  231.     fTestView = contentView;
  232.  
  233.     // ----- Read the subviews from resource
  234.     contentView->CreateSubViewsFromResource(ev, kIntlTestView);
  235.  
  236.     // ----- Add a ViewTabber to the frame 
  237.     fViewTabber = new FW_CViewTabber(ev, this); 
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. ODID CIntlTestFrame::GetActiveEditViewId(Environment* ev)
  242. {
  243.     FW_MEventHandler* target = this->GetTarget(ev);
  244.     if (target)
  245.     {
  246.         FW_CView* targetView = FW_DYNAMIC_CAST(FW_CView, target);
  247.         if (targetView)
  248.             return targetView->GetViewID(ev);
  249.     }
  250.  
  251.     return 0;
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. FW_CEditView* CIntlTestFrame::FindEditView(Environment* ev, ODID id)
  256. {
  257.     return (FW_CEditView*) fTestView->FindViewByID(ev, id);
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. void CIntlTestFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  262. {
  263.     FW_CFrame::FacetAdded(ev, facet, facetCount);    // Call inherited
  264.  
  265.     // Perform "DoPostCreate"-type initialization here.
  266.     fTestPart->UpdateViewsFromTextData(ev);
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. void CIntlTestFrame::HandleNotification(Environment* ev, const FW_CNotification& notification)
  271. {
  272.     // ---- Handle notification messages from the edit views
  273.     if (notification.GetMessage() == kEditViewMsg)
  274.     {
  275.         fTestPart->Changed(ev);    // so we can Save
  276.     }
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. void CIntlTestFrame::GetContentRect(Environment* ev, FW_CRect& rect, FW_CPoint& extent)
  281. {
  282.     rect = GetBounds(ev);
  283.     
  284.     // Leave space to draw 1 pixel border in non-root frames
  285.     if (IsRoot(ev) == FALSE)
  286.         rect.Inset(FW_kFixedPos1);
  287.  
  288.     extent = rect.BotRight();
  289.  
  290.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  291.     rect.right -= sbSize.x;
  292.     rect.bottom -= sbSize.y;
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. FW_CEditView* CIntlTestFrame::HitTest(Environment* ev, const FW_CPoint& where)
  297. {
  298.     // Find out which edit view the point is in; return NULL if point is not in an edit view.
  299.     FW_CEditView* editView;
  300.     FW_CRect bounds;
  301.  
  302.     editView = this->FindEditView(ev, kJapaneseEditView);
  303.     bounds = editView->GetBounds(ev);
  304.     if (bounds.Contains(where))
  305.         return editView;
  306.  
  307.     editView = this->FindEditView(ev, kEnglishEditView);
  308.     bounds = editView->GetBounds(ev);
  309.     if (bounds.Contains(where))
  310.         return editView;
  311.  
  312.     return NULL;
  313. }
  314.  
  315.