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 / ODFx / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-08-26  |  8.1 KB  |  294 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ODFxFrm.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "ODFx.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 CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. // ----- Framework Layer -----
  29.  
  30. #ifndef FWCONTXT_H
  31. #include "FWContxt.h"
  32. #endif
  33.  
  34. #ifndef FWUTIL_H
  35. #include "FWUtil.h"
  36. #endif
  37.  
  38. #ifndef FWPRESEN_H
  39. #include "FWPresen.h"
  40. #endif
  41.  
  42. #ifndef FWSELECT_H
  43. #include "FWSelect.h"
  44. #endif
  45.  
  46. #ifndef FWGROWBX_H
  47. #include "FWGrowBx.h"
  48. #endif
  49.  
  50. #ifndef FWSCLBAR_H
  51. #include "FWSclBar.h"
  52. #endif
  53.  
  54. // ----- OS Layer -----
  55.  
  56. #ifndef FWMENU_H
  57. #include "FWMenu.h"
  58. #endif
  59.  
  60. #ifndef FWEVENT_H
  61. #include "FWEvent.h"
  62. #endif
  63.  
  64. #ifndef FWALERT_H
  65. #include "FWAlert.h"
  66. #endif
  67.  
  68. // ----- Graphic Includes -----
  69.  
  70. #ifndef FWRECT_H
  71. #include "FWRect.h"
  72. #endif
  73.  
  74. #ifndef FWTXTBOX_H
  75. #include "FWTxtBox.h"
  76. #endif
  77.  
  78. #ifndef FWRECSHP_H
  79. #include "FWRecShp.h"
  80. #endif
  81.  
  82. // ----- OpenDoc Includes -----
  83.  
  84. #ifndef SOM_Module_OpenDoc_StdProps_defined
  85. #include <StdProps.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODDragItemIterator_xh
  89. #include <DgItmIt.xh>
  90. #endif
  91.  
  92. #ifdef FW_BUILD_MAC
  93. #include "ColorPicker.h"
  94. #endif
  95.  
  96. //========================================================================================
  97. // Runtime Information
  98. //========================================================================================
  99.  
  100. #ifdef FW_BUILD_MAC
  101. #pragma segment odfx
  102. #endif
  103.  
  104. FW_DEFINE_AUTO(CODFxFrame)
  105.  
  106. //========================================================================================
  107. // CODFxFrame class
  108. //========================================================================================
  109.  
  110. //----------------------------------------------------------------------------------------
  111. // CODFxFrame constructor
  112. //----------------------------------------------------------------------------------------
  113. CODFxFrame::CODFxFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CODFxContent* content) :
  114.     FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  115.     FW_MDraggableFrame(ev, this),
  116.     FW_MDroppableFrame(ev, this),    
  117.     fContent(content)
  118. {
  119. }
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // CODFxFrame destructor
  123. //----------------------------------------------------------------------------------------
  124.  
  125. CODFxFrame::~CODFxFrame()
  126. {
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. //    CODFxFrame::DoMouseDown
  131. //----------------------------------------------------------------------------------------
  132.  
  133. FW_Handled CODFxFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  134. {
  135.     FW_Handled result = FW_kNotHandled;
  136.  
  137.     if (GetPresentation(ev)->GetSelection(ev)->IsMouseInDraggableItem(ev, this, theMouseEvent, FALSE) &&
  138.        this->Drag(ev, theMouseEvent))
  139.         result = FW_kHandled;
  140.      else if(theMouseEvent.GetNumberOfClicks(ev) == 2)
  141.     {
  142.         const short numRegions = fContent->GetNumColors() == 4 ? 2 : 3;
  143.         
  144.         // which region of the frame was the mouse clicked?
  145.         FW_CPoint mouse = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  146.         
  147.         FW_CRect bounds = GetBounds(ev);
  148.         FW_Fixed third = FW_DividedByInt(bounds.Width(), numRegions);
  149.  
  150.         short xZone = -1;
  151.         for(short x = 1; x <= numRegions; x++)
  152.             if(mouse.x < FW_MultipliedByInt(FW_DividedByInt(bounds.Width(), numRegions), x))
  153.             {
  154.                 xZone = x - 1;
  155.                 break;
  156.             }
  157.             
  158.         short yZone = -1;
  159.         for(short y = 1; y <= numRegions; y++)
  160.             if(mouse.y < FW_MultipliedByInt(FW_DividedByInt(bounds.Height(), numRegions), y))
  161.             {
  162.                 yZone = y - 1;
  163.                 break;
  164.             }
  165.         
  166.         if(xZone >= 0 && yZone >= 0)
  167.         {
  168.             short colorIndex = (yZone * 3) + xZone;
  169.             RGBColor color = fContent->GetColorData(colorIndex);
  170.             Point pt = {0,0};
  171.             if(::GetColor(pt, "\p", &color, &color))
  172.             {
  173.                 fContent->SetColorData(ev, colorIndex, FW_CColor(color));
  174.                 Invalidate(ev);
  175.             }
  176.         }
  177.         result = FW_kHandled;
  178.     }
  179.  
  180.     return result;
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // CODFxFrame::DoAdjustMenus
  185. //----------------------------------------------------------------------------------------
  186.  
  187. FW_Handled CODFxFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  188.                                       FW_Boolean hasMenuFocus,
  189.                                       FW_Boolean isRoot)    // Override
  190. {
  191. FW_UNUSED(isRoot);
  192.     if (hasMenuFocus)
  193.         menuBar->EnableCommand(ev, kODCommandCopy, true);
  194.     
  195.     return FW_kNotHandled;
  196. }
  197.  
  198. void CODFxFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  199. {
  200.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  201.  
  202.     FW_CRect bounds(GetBounds(ev));
  203.     
  204.     // render the picture to the screen
  205.     FW_CPictureShape::RenderPicture(vc, fContent->GetPictureData(ev), bounds);    
  206.  
  207.     if(fContent->GetShowGridLines() && odFacet->GetCanvas(ev)->IsDynamic(ev))
  208.     {
  209.         const short numRegions = fContent->GetNumColors() == 4 ? 2 : 3;
  210.         
  211.         FW_Fixed hLoc = bounds.left;
  212.         FW_Fixed vLoc = bounds.top;
  213.         
  214.         for(short x = 0; x < numRegions; x++)
  215.         {
  216.             hLoc += FW_DividedByInt(bounds.Width(), numRegions);
  217.             vLoc += FW_DividedByInt(bounds.Height(), numRegions);
  218.             FW_CLineShape::RenderLine(vc, FW_CPoint(bounds.left, vLoc), FW_CPoint(bounds.right, vLoc), FW_kInvertInk);
  219.             FW_CLineShape::RenderLine(vc, FW_CPoint(hLoc, bounds.top), FW_CPoint(hLoc, bounds.bottom), FW_kInvertInk);
  220.         }
  221.     }
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. // CODFxFrame::FrameShapeChanged
  226. //----------------------------------------------------------------------------------------
  227. // By default a FW_CFrame view is not refreshed entirely when resized.
  228. // You must decide if your content's appearance depends on the frame's size.
  229. // If it doesn't you don't need to override FrameShapeChanged().
  230. // Here we must redraw the whole frame everytime because the text is centered.
  231.  
  232. void CODFxFrame::FrameShapeChanged(Environment* ev)
  233. {
  234.     FW_CFrame::FrameShapeChanged(ev);
  235.     
  236.     this->Invalidate(ev);
  237. }
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    CODFxFrame::NewClipboardCommand
  241. //----------------------------------------------------------------------------------------
  242.  
  243. FW_CClipboardCommand* CODFxFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  244. {
  245.     return FW_NEW(CODFxEditCommand, (ev, commandID, fContent, this));
  246. }
  247.  
  248. //----------------------------------------------------------------------------------------
  249. //    CODFxFrame::NewDragCommand
  250. //----------------------------------------------------------------------------------------
  251.  
  252. FW_CDragCommand* CODFxFrame::NewDragCommand(Environment *ev, 
  253.                                             FW_CFrame* theFrame,
  254.                                             const FW_CMouseEvent& theMouseEvent)
  255. {
  256. FW_UNUSED(theMouseEvent);
  257.     return FW_NEW(CODFxDragCommand, (ev, fContent, theFrame));
  258. }
  259.  
  260. //----------------------------------------------------------------------------------------
  261. //    CODFxFrame::NewDropCommand
  262. //----------------------------------------------------------------------------------------
  263.  
  264. FW_CDropCommand* CODFxFrame::NewDropCommand(Environment* ev,
  265.                                              FW_CFrame* frame,
  266.                                              ODDragItemIterator* dropInfo, 
  267.                                              ODFacet* odFacet, 
  268.                                              const FW_CPoint& dropPoint)
  269. {
  270. FW_UNUSED(frame);
  271.     return FW_NEW(CODFxDropCommand, (ev, fContent, this, dropInfo, odFacet, dropPoint));
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //     CODFxFrame::CreateSubViews
  276. //----------------------------------------------------------------------------------------
  277.  
  278. void CODFxFrame::CreateSubViews(Environment* ev)
  279. {        
  280.     // Create a GrowBox only in root frame
  281.     // Note: you do not need CreateSubViews if the views are defined in resources.
  282.     //        See the Container or Form samples.
  283.     
  284.     if (this->IsRoot(ev)) 
  285.     {
  286.         FW_CRect frameRect = GetBounds(ev);  
  287.         FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  288.         frameRect.right -= sbSize.x;
  289.         frameRect.bottom -= sbSize.y;
  290.         
  291.         FW_CGrowBox* growBox = new FW_CGrowBox(ev, this, 0, frameRect.BotRight());
  292.     }
  293. }
  294.