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 / Bitmap / Sources / Select.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  8.1 KB  |  302 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Select.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Bitmap.hpp"
  13.  
  14. #ifndef SELECT_H
  15. #include "Select.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef FRAME_H
  23. #include "Frame.h"
  24. #endif
  25.  
  26. #ifndef CONTENT_H
  27. #include "Content.h"
  28. #endif
  29.  
  30. // ----- Part Layer -----
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWITERS_H
  37. #include "FWIters.h"
  38. #endif
  39.  
  40. #ifndef FWPRESEN_H
  41. #include "FWPresen.h"
  42. #endif
  43.  
  44. #ifndef FWCONTXT_H
  45. #include "FWContxt.h"
  46. #endif
  47.  
  48. // ----- OS Layer -----
  49.  
  50. #ifndef FWPICTUR_H
  51. #include "FWPictur.h"
  52. #endif
  53.  
  54. #ifndef FWBARRAY_H
  55. #include "FWBArray.h"
  56. #endif
  57.  
  58. #ifndef FWODGEOM_H
  59. #include "FWODGeom.h"
  60. #endif
  61.  
  62. // ----- Foundation Layer -----
  63.  
  64. #ifndef FWSUSINK_H
  65. #include "FWSUSink.h"
  66. #endif
  67.  
  68. #ifndef FWMEMMGR_H
  69. #include "FWMemMgr.h"
  70. #endif
  71.  
  72. #ifndef FWMEMHLP_H
  73. #include "FWMemHlp.h"
  74. #endif
  75.  
  76. // ----- OpenDoc Includes -----
  77.  
  78. #ifndef SOM_Module_OpenDoc_StdProps_defined
  79. #include <StdProps.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODShape_xh
  83. #include <Shape.xh>
  84. #endif
  85.  
  86. //========================================================================================
  87. //    Runtime Information
  88. //========================================================================================
  89.  
  90. #ifdef FW_BUILD_MAC
  91. #pragma segment odfbitmap
  92. #endif
  93.  
  94. //========================================================================================
  95. //    class CBitmapSelection
  96. //========================================================================================
  97.  
  98. FW_DEFINE_AUTO(CBitmapSelection)
  99.  
  100. //---------------------------------------------------------------------------------------
  101. //    CBitmapSelection::CBitmapSelection
  102. //---------------------------------------------------------------------------------------
  103.  
  104. CBitmapSelection::CBitmapSelection(Environment* ev, CBitmapPart* thePart, CBitmapContent* content) :
  105.     FW_CSelection(ev, FALSE, FALSE),
  106.     fBitmapPart(thePart),
  107.     fSelectedContent(NULL),
  108.     fHasSelection(false)
  109. {
  110.     fSelectedContent = new CBitmapSelectionContent(ev, thePart, this, content);
  111.  
  112.     fRectShape.GetStyle().SetPattern(FW_kAntPat);
  113.     fRectShape.GetInk().SetTransferMode(FW_kXOr);
  114.     fRectShape.SetRenderVerb(FW_kFrame);
  115.     
  116.     FW_END_CONSTRUCTOR
  117. }
  118.  
  119. //---------------------------------------------------------------------------------------
  120. //    CBitmapSelection::~CBitmapSelection
  121. //---------------------------------------------------------------------------------------
  122.  
  123. CBitmapSelection::~CBitmapSelection()
  124. {    
  125.     FW_START_DESTRUCTOR
  126.     
  127.     delete fSelectedContent;
  128. }
  129.  
  130. //---------------------------------------------------------------------------------------
  131. //    CBitmapSelection::CloseSelection
  132. //---------------------------------------------------------------------------------------
  133.  
  134. void CBitmapSelection::CloseSelection(Environment* ev)
  135. {
  136.     if (fHasSelection)
  137.     {
  138.         DrawAnts(ev, (CBitmapFrame*)fBitmapPart->GetLastActiveFrame(ev));    // Erase ants
  139.         fHasSelection = false;
  140.     }
  141. }
  142.  
  143. //---------------------------------------------------------------------------------------
  144. //    CBitmapSelection::ClearSelection
  145. //---------------------------------------------------------------------------------------
  146.  
  147. void CBitmapSelection::ClearSelection(Environment* ev)
  148. {
  149. FW_UNUSED(ev);
  150.     // Nothing to do
  151. }
  152.  
  153. //---------------------------------------------------------------------------------------
  154. //    CBitmapSelection::SelectAll
  155. //---------------------------------------------------------------------------------------
  156.  
  157. void CBitmapSelection::SelectAll(Environment* ev)
  158. {
  159.     // ----- Close the selection if there is one -----
  160.     CloseSelection(ev);
  161.     
  162.     // ----- Select entire bitmap -----
  163.     fSelectedContent->SelectEntireBitmap(ev);
  164.     fHasSelection = true;
  165.     
  166.     // ----- Draw the first ants -----
  167.     DrawAnts(ev, (CBitmapFrame*)fBitmapPart->GetLastActiveFrame(ev));
  168. }
  169.  
  170. //---------------------------------------------------------------------------------------
  171. //    CBitmapSelection::GetSelectedContent
  172. //---------------------------------------------------------------------------------------
  173.  
  174. FW_CContent* CBitmapSelection::GetSelectedContent(Environment* ev)
  175. {
  176. FW_UNUSED(ev);
  177.     return fSelectedContent;
  178. }
  179.  
  180. //---------------------------------------------------------------------------------------
  181. //    CBitmapSelection::IsEmpty
  182. //---------------------------------------------------------------------------------------
  183.  
  184. FW_Boolean CBitmapSelection::IsEmpty(Environment* ev) const
  185. {
  186. FW_UNUSED(ev);
  187.     return !fHasSelection;
  188. }
  189.  
  190. //---------------------------------------------------------------------------------------
  191. //    CBitmapSelection::MoveAnts
  192. //---------------------------------------------------------------------------------------
  193.  
  194. void CBitmapSelection::MoveAnts(Environment* ev, CBitmapFrame* frame)
  195. {
  196.     DrawAnts(ev, frame);
  197.     
  198.     FW_CStyle style = fRectShape.GetStyle();    
  199.     FW_CPattern pattern = style.GetPattern();
  200.     pattern.ShiftRight();
  201.     style.SetPattern(pattern);
  202.         
  203.     DrawAnts(ev, frame);
  204. }
  205.  
  206. //---------------------------------------------------------------------------------------
  207. //    CBitmapSelection::DrawAnts
  208. //---------------------------------------------------------------------------------------
  209. // Draw ants in all facets of the given frame.
  210.  
  211. void CBitmapSelection::DrawAnts(Environment* ev, CBitmapFrame* frame)
  212. {
  213.     if (frame != NULL)
  214.     {
  215.         FW_CFrameFacetIterator iter(ev, frame);
  216.         for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  217.         {
  218.             FW_CViewContext vc(ev, frame, facet);
  219.             DoDrawAnts(ev, vc, frame);
  220.         }
  221.     }
  222. }
  223.  
  224. //---------------------------------------------------------------------------------------
  225. //    CBitmapSelection::DoDrawAnts
  226. //---------------------------------------------------------------------------------------
  227.  
  228. void CBitmapSelection::DoDrawAnts(Environment* ev, FW_CGraphicContext& gc, CBitmapFrame* frame)
  229. {
  230.     FW_CRect usedRect;
  231.     frame->CalcUsedRect(ev, usedRect);
  232.  
  233.     FW_CRect rect;
  234.     GetSelectRect(frame->GetZoomRatio(ev), usedRect, rect);
  235.  
  236.     fRectShape.SetRectangle(rect);
  237.     fRectShape.Render(gc);
  238. }
  239.  
  240. //----------------------------------------------------------------------------------------
  241. //    CBitmapSelection::AcquireSelectionShape
  242. //----------------------------------------------------------------------------------------
  243.  
  244. ODShape* CBitmapSelection::AcquireSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame)
  245. {
  246. FW_UNUSED(facet);
  247.     ODShape* selectionShape = ::FW_NewODShape(ev, FW_kZeroRect);
  248.     
  249.     if (!IsEmpty(ev))
  250.     {
  251.         FW_CRect usedRect;
  252.         ((CBitmapFrame*)frame)->CalcUsedRect(ev, usedRect);
  253.     
  254.         FW_CRect selectRect;
  255.         GetSelectRect(((CBitmapFrame*)frame)->GetZoomRatio(ev), usedRect, selectRect);
  256.     
  257.         ODRect odSelectRect = selectRect;
  258.         selectionShape->SetRectangle(ev, &odSelectRect);
  259.     }
  260.     
  261.     return selectionShape;
  262. }
  263.  
  264. //----------------------------------------------------------------------------------------
  265. //    CBitmapSelection::GetSelectRect
  266. //----------------------------------------------------------------------------------------
  267.  
  268. void CBitmapSelection::GetSelectRect(const FW_CPoint& ratio, const FW_CRect& usedRect, FW_CRect& rect) const
  269. {
  270.     if (fHasSelection)
  271.     {
  272.         FW_CPlatformRect selectRect;
  273.         fSelectedContent->GetSelectRect(selectRect);
  274.         rect.Set(
  275.             FW_MultipliedByInt(ratio.x, selectRect.left),
  276.             FW_MultipliedByInt(ratio.y, selectRect.top),
  277.             FW_MultipliedByInt(ratio.x, selectRect.right),
  278.             FW_MultipliedByInt(ratio.y, selectRect.bottom));
  279.     
  280.         rect.Offset(usedRect.left, usedRect.top);
  281.     }
  282.     else
  283.         rect.SetInt(0, 0, 0, 0);
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    CBitmapSelection::SetSelectRect
  288. //----------------------------------------------------------------------------------------
  289.  
  290. void CBitmapSelection::SetSelectRect(const FW_CPoint& ratio, const FW_CRect& usedRect, const FW_CRect& rect)
  291. {
  292.     FW_CPlatformRect selectRect(
  293.         FW_FixedToInt((rect.left  - usedRect.left) / ratio.x),
  294.         FW_FixedToInt((rect.top  - usedRect.top) / ratio.y),
  295.         FW_FixedToInt((rect.right  - usedRect.left) / ratio.x),
  296.         FW_FixedToInt((rect.bottom - usedRect.top) / ratio.y));
  297.     fHasSelection = TRUE;
  298.     fSelectedContent->SetSelectRect(selectRect);
  299. }
  300.  
  301.  
  302.