home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 8.1 KB | 298 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Select.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Bitmap.hpp"
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWPICTUR_H
- #include "FWPictur.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWMEMHLP_H
- #include "FWMemHlp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfbitmap
- #endif
-
- //========================================================================================
- // class CBitmapSelection
- //========================================================================================
-
- FW_DEFINE_AUTO(CBitmapSelection)
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::CBitmapSelection
- //---------------------------------------------------------------------------------------
-
- CBitmapSelection::CBitmapSelection(Environment* ev, CBitmapPart* thePart, CBitmapContent* content) :
- FW_CSelection(ev, FALSE, FALSE),
- fBitmapPart(thePart),
- fSelectedContent(NULL),
- fHasSelection(false)
- {
- fSelectedContent = new CBitmapSelectionContent(ev, thePart, this, content);
-
- fRectShape.GetStyle().SetPattern(FW_kAntPat);
- fRectShape.GetInk().SetTransferMode(FW_kXOr);
- fRectShape.SetRenderVerb(FW_kFrame);
-
- FW_END_CONSTRUCTOR
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::~CBitmapSelection
- //---------------------------------------------------------------------------------------
-
- CBitmapSelection::~CBitmapSelection()
- {
- FW_START_DESTRUCTOR
-
- delete fSelectedContent;
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::CloseSelection
- //---------------------------------------------------------------------------------------
-
- void CBitmapSelection::CloseSelection(Environment* ev)
- {
- if (fHasSelection)
- {
- DrawAnts(ev, (CBitmapFrame*)fBitmapPart->GetLastActiveFrame(ev)); // Erase ants
- fHasSelection = false;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::ClearSelection
- //---------------------------------------------------------------------------------------
-
- void CBitmapSelection::ClearSelection(Environment* ev)
- {
- // Nothing to do
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::SelectAll
- //---------------------------------------------------------------------------------------
-
- void CBitmapSelection::SelectAll(Environment* ev)
- {
- // ----- Close the selection if there is one -----
- CloseSelection(ev);
-
- // ----- Select entire bitmap -----
- fSelectedContent->SelectEntireBitmap(ev);
- fHasSelection = true;
-
- // ----- Draw the first ants -----
- DrawAnts(ev, (CBitmapFrame*)fBitmapPart->GetLastActiveFrame(ev));
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::GetSelectedContent
- //---------------------------------------------------------------------------------------
-
- FW_CContent* CBitmapSelection::GetSelectedContent(Environment* ev)
- {
- return fSelectedContent;
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::IsEmpty
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CBitmapSelection::IsEmpty(Environment* ev) const
- {
- return !fHasSelection;
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::MoveAnts
- //---------------------------------------------------------------------------------------
-
- void CBitmapSelection::MoveAnts(Environment* ev, CBitmapFrame* frame)
- {
- DrawAnts(ev, frame);
-
- FW_CStyle style = fRectShape.GetStyle();
- FW_CPattern pattern = style.GetPattern();
- pattern.ShiftRight();
- style.SetPattern(pattern);
-
- DrawAnts(ev, frame);
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::DrawAnts
- //---------------------------------------------------------------------------------------
- // Draw ants in all facets of the given frame.
-
- void CBitmapSelection::DrawAnts(Environment* ev, CBitmapFrame* frame)
- {
- if (frame != NULL)
- {
- FW_CFrameFacetIterator iter(ev, frame);
- for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
- {
- FW_CViewContext vc(ev, frame, facet);
- DoDrawAnts(ev, vc, frame);
- }
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CBitmapSelection::DoDrawAnts
- //---------------------------------------------------------------------------------------
-
- void CBitmapSelection::DoDrawAnts(Environment* ev, FW_CGraphicContext& gc, CBitmapFrame* frame)
- {
- FW_CRect usedRect;
- frame->CalcUsedRect(ev, usedRect);
-
- FW_CRect rect;
- GetSelectRect(frame->GetZoomRatio(ev), usedRect, rect);
-
- fRectShape.SetRectangle(rect);
- fRectShape.Render(gc);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CBitmapSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- ODShape* selectionShape = ::FW_NewODShape(ev, FW_kZeroRect);
-
- if (!IsEmpty(ev))
- {
- FW_CRect usedRect;
- ((CBitmapFrame*)frame)->CalcUsedRect(ev, usedRect);
-
- FW_CRect selectRect;
- GetSelectRect(((CBitmapFrame*)frame)->GetZoomRatio(ev), usedRect, selectRect);
-
- ODRect odSelectRect = selectRect;
- selectionShape->SetRectangle(ev, &odSelectRect);
- }
-
- return selectionShape;
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelection::GetSelectRect
- //----------------------------------------------------------------------------------------
-
- void CBitmapSelection::GetSelectRect(const FW_CPoint& ratio, const FW_CRect& usedRect, FW_CRect& rect) const
- {
- if (fHasSelection)
- {
- FW_CPlatformRect selectRect;
- fSelectedContent->GetSelectRect(selectRect);
- rect.Set(
- FW_MultipliedByInt(ratio.x, selectRect.left),
- FW_MultipliedByInt(ratio.y, selectRect.top),
- FW_MultipliedByInt(ratio.x, selectRect.right),
- FW_MultipliedByInt(ratio.y, selectRect.bottom));
-
- rect.Offset(usedRect.left, usedRect.top);
- }
- else
- rect.SetInt(0, 0, 0, 0);
- }
-
- //----------------------------------------------------------------------------------------
- // CBitmapSelection::SetSelectRect
- //----------------------------------------------------------------------------------------
-
- void CBitmapSelection::SetSelectRect(const FW_CPoint& ratio, const FW_CRect& usedRect, const FW_CRect& rect)
- {
- FW_CPlatformRect selectRect(
- FW_FixedToInt((rect.left - usedRect.left) / ratio.x),
- FW_FixedToInt((rect.top - usedRect.top) / ratio.y),
- FW_FixedToInt((rect.right - usedRect.left) / ratio.x),
- FW_FixedToInt((rect.bottom - usedRect.top) / ratio.y));
- fHasSelection = TRUE;
- fSelectedContent->SetSelectRect(selectRect);
- }
-
-
-