home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 26.1 KB | 943 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawSel.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef SHPTRAKR_H
- #include "ShpTrakr.h"
- #endif
-
- #ifndef DRAWCMDS_H
- #include "DrawCmds.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- #ifndef DRWPRMSE_H
- #include "DrwPrmse.h"
- #endif
-
- // ----- Part Layer -----
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #if defined(__MWERKS__) && GENERATING68K
- // A hack to work around a bug
- #pragma import list somGetGlobalEnvironment
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdraw2
- #endif
-
- //========================================================================================
- // class CDrawSelection
- //========================================================================================
-
- FW_DEFINE_AUTO(CDrawSelection)
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CDrawSelection
- //----------------------------------------------------------------------------------------
-
- CDrawSelection::CDrawSelection(Environment* ev, CDrawPart* drawPart):
- FW_CSelection(ev, TRUE, TRUE),
- fDrawPart(drawPart),
- fUpdateShape(NULL),
- fFrozenCount(0),
- fCount(0),
- fSelectionContent(NULL),
- fWorkingHandle(FW_kZeroRect, FW_kFill),
- fDraggedContent(NULL)
- {
- fSelectionContent = FW_NEW(CDrawSelectionContent, (ev, drawPart, this));
- fWorkingHandle.SetInk(FW_kInvertInk);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::~CDrawSelection
- //----------------------------------------------------------------------------------------
-
- CDrawSelection::~CDrawSelection()
- {
- FW_START_DESTRUCTOR
- if (fUpdateShape)
- fUpdateShape->Release(somGetGlobalEnvironment());
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetSelectedContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CDrawSelection::GetSelectedContent(Environment* ev)
- {
- return fSelectionContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::WhichHandle
- //----------------------------------------------------------------------------------------
-
- CBaseShape* CDrawSelection::WhichHandle(Environment* ev, FW_CGraphicContext& gc, const FW_CPoint& mouse, short& whichHandle) const
- {
- whichHandle = 0;
-
- if (fCount != 0)
- {
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- whichHandle = shape->WhichHandle(gc, mouse);
- if (whichHandle != 0)
- return shape;
- }
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderSelectionHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderSelectionHandles(Environment* ev, FW_CGraphicContext& gc)
- {
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->RenderHandles(gc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderAllHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderAllHandles(Environment* ev, FW_CFrame* frame)
- {
- if (fCount != 0)
- {
- FW_CFrameFacetIterator ite(ev, frame);
- for (ODFacet* facet = (ODFacet*)ite.First(ev); ite.IsNotComplete(ev); facet = (ODFacet*)ite.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- RenderSelectionHandles(ev, vc);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RenderHandles
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RenderHandles(Environment* ev, CBaseShape* shape)
- {
- FW_CPresentationFrameIterator ite(ev, GetPresentation(ev));
- for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev))
- {
- if (frame->HasSelectionFocus(ev) && frame->GetWindow(ev)->IsActive(ev))
- {
- FW_CFrameFacetIterator i(ev, frame);
- for (ODFacet* facet = i.First(ev); i.IsNotComplete(ev); facet = i.Next(ev))
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
- shape->RenderHandles(vc);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CloseSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::CloseSelection(Environment* ev)
- {
- CBaseShape* shape;
- while ((shape = fSelectionContent->GetFirstShape()) != NULL)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // turn off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::AddToSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::AddToSelection(Environment* ev, CBaseShape* theShape, FW_Boolean renderHandles)
- {
- if (theShape != NULL)
- {
- fDrawPart->SetTool(ev, kSelectTool);
- DoAdd(ev, theShape);
- if (renderHandles)
- RenderHandles(ev, theShape); // Turn on
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::RemoveFromSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::RemoveFromSelection(Environment* ev, CBaseShape* shape, FW_Boolean renderHandles)
- {
- if (shape != NULL)
- {
- DoRemove(ev, shape);
- if (renderHandles)
- RenderHandles(ev, shape); // Turn Off
- }
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoAdd
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::DoAdd(Environment* ev, CBaseShape *shape)
- {
- fSelectionContent->AddShape(ev, shape);
- this->ShapeAdded(ev, shape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ShapeAdded
- //----------------------------------------------------------------------------------------
- void CDrawSelection::ShapeAdded(Environment* ev, CBaseShape* shape)
- {
- shape->SelectShape(ev, true);
- fCount++;
- if (shape->IsFrozen())
- fFrozenCount++;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DoRemove
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::DoRemove(Environment* ev, CBaseShape *shape)
- {
- fSelectionContent->RemoveShape(ev, shape);
- shape->SelectShape(ev, false);
- fCount--;
- if (shape->IsFrozen())
- fFrozenCount--;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::ClearSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::ClearSelection(Environment* ev)
- {
- CBaseShape *shape;
- while ((shape = fSelectionContent->GetFirstShape()) != NULL)
- {
- shape->CheckPromise(ev, fDrawPart);
-
- DoRemove(ev, shape); // Remove from selection list
- fDrawPart->RemoveShapeFromPart(ev, shape); // Remove from part
- }
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- CalcCache(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectAll
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectAll(Environment* ev)
- {
- FW_CFrame* activeFrame = fDrawPart->GetLastActiveFrame(ev);
-
- RenderAllHandles(ev, activeFrame);
-
- CDrawContentShapeIterator ite(fDrawPart->GetDrawContent());
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (!shape->IsSelectedShape())
- DoAdd(ev, shape);
- }
-
- RenderAllHandles(ev, activeFrame);
-
- CalcCache(ev);
-
- fDrawPart->SetTool(ev, kSelectTool);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsEmpty(Environment* ev) const
- {
- return fCount == 0;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CenterSelection
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CDrawSelection::CenterSelection(Environment* ev, FW_CFrame* scopeFrame)
- {
- FW_ASSERT(scopeFrame);
-
- fDrawPart->SetTool(ev, kSelectTool);
-
- CalcCache(ev);
-
- FW_CRect bounds = scopeFrame->GetContentView(ev)->GetBoundsInContent(ev);
- FW_CRect box(fDragRect);
- box.PlaceInCenter(bounds);
-
- FW_CPoint result(box.left - fDragRect.left, box.top - fDragRect.top);
- OffsetSelection(ev, result.x, result.y);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), fUpdateShape);
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::Resize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::Resize(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- if (fClickedHandle == 0)
- return FALSE;
-
- if (!this->IsOKtoEdit(ev)) // can't resize read only part
- {
- FW_Beep();
- return TRUE;
- }
-
- if (!theMouseEvent.WaitUntilMouseMoved(ev))
- return TRUE;
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CBaseShape* anchorShape = GetAnchorShape();
-
- FW_CInk resizeInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- FW_CStyle resizeStyle(anchorShape->GetResizeStyle());
-
- CResizeTracker resizeTracker(ev, frame->GetContentView(ev), facet, anchorShape, fClickedHandle, resizeInk, resizeStyle, TRUE);
- if (resizeTracker.Track(ev, theMouseEvent))
- {
- GetPresentation(ev)->Invalidate(ev, fUpdateShape);
-
- FW_CPoint lastLocation;
- resizeTracker.GetLastLocation(lastLocation);
- FW_CRect srcRect, dstRect;
- anchorShape->GetMapRects(fClickedHandle, lastLocation, srcRect, dstRect);
-
- CResizeShapeCommand* cmd = FW_NEW(CResizeShapeCommand,
- (ev, fDrawPart, frame, this,
- srcRect, dstRect));
- cmd->Execute(ev);
- }
- else
- {
- FW_CViewContext vc(ev, frame->GetContentView(ev), facet);
-
- FW_CPoint penSize = vc.DeviceToLogical(2, 2);
- anchorShape->CalcHandle(fClickedHandle, &fWorkingHandle, penSize);
- fWorkingHandle.Render(vc); // redraw the handle
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CalcCache
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::CalcCache(Environment* ev)
- {
- fDragRect.Clear();
-
- if (fUpdateShape == NULL)
- fUpdateShape = ::FW_NewODShape(ev);
-
- if (fCount == 0)
- return;
-
- FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
- FW_CRect tempRect;
-
- FW_Boolean first = TRUE;
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->GetDragRect(tempRect);
- shape->GetUpdateBox(ev, aqTempShape);
- if (first)
- {
- fDragRect = tempRect;
- fUpdateShape->CopyFrom(ev, aqTempShape);
- }
- else
- {
- fDragRect |= tempRect;
- fUpdateShape->Union(ev, aqTempShape);
- }
-
- first = FALSE;
- }
-
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CDrawSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- FW_UNUSED(frame);
- FW_UNUSED(facet);
-
- ODShape* shape = ::FW_NewODShape(ev, fDragRect);
- return shape;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CDrawSelection::CreateSelectionOutline(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- ODShape* outline;
- if (GetAnchorShape() == NULL)
- outline = CreateSelectionShape(ev, facet, frame);
- else
- outline = GetAnchorShape()->CreateShapeOutline(ev);
-
- if (fCount > 1)
- {
- FW_CAcquiredODShape shapeOutline = FW_CSelection::CreateSelectionOutline(ev, facet, frame);
- outline->Union(ev, shapeOutline);
- }
-
- return outline;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::OffsetSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::OffsetSelection(Environment* ev, FW_Fixed xDelta, FW_Fixed yDelta)
- {
- FW_CAcquiredODShape aqUnionShape(fUpdateShape->Copy(ev));
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->OffsetShape(ev, xDelta, yDelta);
- }
-
- CalcCache(ev);
-
- aqUnionShape->Union(ev, fUpdateShape);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, GetPresentation(ev), aqUnionShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectWithRectangle
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectWithRectangle(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- CRectShape rectShape; // Create a rect shape on the stack
- FW_CStyle trackStyle(FW_kFixed0, FW_kAntPat);
- FW_CInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- rectShape.ChangeRenderVerb(ev, fDrawPart, kFrameOnly);
- rectShape.SetFrameInk(trackInk);
- rectShape.SetFrameStyle(trackStyle);
-
- ODFacet* facet = theMouseEvent.GetFacet(ev);
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
-
- CShapeTracker tracker(ev, frame->GetContentView(ev), facet, &rectShape, FALSE);
- if (tracker.Track(ev, theMouseEvent))
- {
- FW_Boolean isShift = theMouseEvent.IsExtendModifier(ev);
- FW_CRect selectRect = rectShape.GetRectGeometry();
-
- CDrawContentShapeIterator ite(fDrawPart->GetDrawContent());
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->InSelectionRect(selectRect))
- {
- if (shape->IsSelectedShape())
- {
- if (isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- else
- {
- DoAdd(ev, shape);
- RenderHandles(ev, shape); // Turn on
- }
- }
- else if (shape->IsSelectedShape() && !isShift)
- {
- DoRemove(ev, shape);
- RenderHandles(ev, shape); // Turn Off
- }
- }
- CalcCache(ev);
- }
- else
- {
- if (!theMouseEvent.IsExtendModifier(ev))
- CloseSelection(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SetFrozen
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SetFrozen(Environment* ev, FW_Boolean state)
- {
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->SetFrozen(state))
- {
- state ? fFrozenCount++ : fFrozenCount--;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectionChanged
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::SelectionChanged(Environment* ev)
- {
- CDrawPublishLinkCollection temp;
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->IsPublished())
- {
- if (!temp.Contains(shape->GetPublishLink()))
- temp.AddLast(shape->GetPublishLink());
- }
- }
-
- //--- Update affected links ---
- ODUpdateID updateID = fDrawPart->GetSession(ev)->UniqueUpdateID(ev);
- CDrawPublishLinkCollectionIterator tempIte(&temp);
- for (CDrawPublishLink* link = tempIte.First(); tempIte.IsNotComplete(); link = tempIte.Next())
- {
- link->ContentUpdated(ev, updateID);
- }
-
- //--- Notify frames ---
- GetPresentation(ev)->ContentUpdated(ev);
-
- temp.RemoveAll();
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsSelectionLinkable
- //----------------------------------------------------------------------------------------
- // Don't write a link spec if any of the selected shapes is in a link destination
-
- FW_Boolean CDrawSelection::IsSelectionLinkable(Environment* ev)
- {
- FW_Boolean result = TRUE;
-
- CDrawContentShapeIterator ite(fSelectionContent);
- for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- if (shape->IsInLinkDestination(ev))
- {
- result = FALSE;
- break;
- }
- else if (shape->IsPublished()) // don't allow a shape to be published more than once
- {
- result = FALSE;
- break;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::CanPasteAsLink
- //----------------------------------------------------------------------------------------
- FW_Boolean CDrawSelection::CanPasteAsLink(Environment* ev, ODPasteAsMergeSetting& setting,
- ODStorageUnit* su)
- {
- // Check whether the storage unit contains mergeable content
- if (su->Exists(ev, kODPropContents, fDrawPart->GetPartKind(ev), 0))
- setting = kODPasteAsMerge;
- else // foreign content - cannot be merged
- setting = kODPasteAsEmbedOnly;
-
- return fAllowLink;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsMouseInDraggableItem
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsMouseInDraggableItem(Environment* ev, FW_CFrame* frame,
- const FW_CMouseEvent& theMouseEvent,
- FW_Boolean inBackground)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- if (!inBackground && fDrawPart->GetTool() != kSelectTool)
- return FALSE;
-
- FW_CViewContext vc(ev, frame->GetContentView(ev), theMouseEvent.GetFacet(ev));
-
- // ----- Look first for a handle -----
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- CBaseShape* clickedShape = WhichHandle(ev, vc, where, fClickedHandle);
- if (clickedShape != NULL)
- {
- fAnchorShape = clickedShape;
- return FALSE; // if in a handle we won't drag
- }
-
- // ----- then look for a selected shape -----
- CBaseShape* shape = fDrawPart->WhichShape(ev, vc, theMouseEvent, TRUE);
-
- if (shape != NULL && shape->IsSelectedShape())
- {
- fAnchorShape = shape;
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::UpdateSelectionOnMouseDown
- //----------------------------------------------------------------------------------------
-
- void CDrawSelection::UpdateSelectionOnMouseDown(Environment* ev,
- const FW_CMouseEvent& mouseEvent,
- ODFacet* embeddedFacet,
- FW_Boolean inEmbeddedFrameBorder,
- FW_Boolean inBackground)
- {
- if (inEmbeddedFrameBorder)
- {
- fClickedHandle = 0;
- fAnchorShape = NULL;
-
- CProxyShape *theShape = (CProxyShape*)fDrawPart->GetProxy(ev, embeddedFacet->GetFrame(ev));
- FW_ASSERT(theShape);
-
- if (!theShape->IsSelectedShape())
- AddToSelection(ev, theShape, TRUE);
-
- fAnchorShape = theShape;
- }
- else if (fDrawPart->GetTool() == kSelectTool || inBackground)
- {
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
- FW_CViewContext vc(ev, frame->GetContentView(ev), mouseEvent.GetFacet(ev));
-
- // ----- First look if we are in a resize handle -----
- FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- frame->GetContentView(ev)->FrameToViewContent(ev, where);
-
- short clickedHandle;
- if (WhichHandle(ev, vc, where, clickedHandle) != NULL)
- return;
-
- // ----- So now we are not in a handle -----
- CBaseShape* clickedShape = fDrawPart->WhichShape(ev, vc, mouseEvent, FALSE);
- if (clickedShape)
- {
- if (mouseEvent.IsExtendModifier(ev))
- {
- if (clickedShape->IsSelectedShape())
- {
- RemoveFromSelection(ev, clickedShape, !inBackground);
- if (clickedShape == fAnchorShape)
- fAnchorShape = NULL;
- }
- else
- {
- AddToSelection(ev, clickedShape, !inBackground);
- fAnchorShape = clickedShape;
- }
- }
- else if (!clickedShape->IsSelectedShape())
- {
- fAnchorShape = clickedShape;
- CloseSelection(ev);
- AddToSelection(ev, clickedShape, !inBackground);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::DeleteSelection
- //----------------------------------------------------------------------------------------
- void CDrawSelection::DeleteSelection(Environment* ev)
- {
- CBaseShape *shape;
- while ((shape = fSelectionContent->GetFirstShape()) != NULL)
- {
- DoRemove(ev, shape); // Remove from selection
- fDrawPart->RemoveShapeFromPart(ev, shape); // Remove from part
- delete shape;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsOKtoEdit
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsOKtoEdit(Environment* ev)
- {
- // Check for a read-only part
- if (fDrawPart->IsReadOnly(ev))
- return FALSE;
-
- // check whether any of the selected shapes is in a link destination
- if (this->IsShapeInLinkDestination(ev))
- return FALSE;
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::IsShapeInLinkDestination
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::IsShapeInLinkDestination(Environment* ev)
- {
- // check whether the presentation's frame is in a link destination
- FW_CPresentationFrameIterator piter(ev, fPresentation);
- CDrawFrame* drawFrame = (CDrawFrame*)piter.First(ev);
- if (drawFrame->IsInLinkDestination(ev))
- return TRUE;
-
- // check whether any of the selected shapes is in a link destination
- CDrawContentShapeIterator iter(fSelectionContent);
- for (CBaseShape *shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
- {
- if (shape->IsInLinkDestination(ev))
- return TRUE; // can't edit a subscribed shape
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetSelectionPenSize
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawSelection::GetSelectionPenSize(Environment* ev, FW_Fixed& penSize)
- {
- CDrawContentShapeIterator iter(fSelectionContent);
- FW_Boolean first = TRUE;
- for (CBaseShape *shape = iter.First(); iter.IsNotComplete(); shape = iter.Next())
- {
- if (first)
- {
- penSize = shape->GetPenSize();
- first = FALSE;
- }
- else
- {
- if (shape->GetPenSize() != penSize)
- return FALSE;
- }
- }
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::SelectContent
- //----------------------------------------------------------------------------------------
- void CDrawSelection::SelectContent(Environment* ev, CDrawContent* content)
- {
- this->CloseSelection(ev);
-
- CDrawContentShapeIterator it(content);
- for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
- {
- this->AddToSelection(ev, shape, TRUE);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawSelection::GetDrawContent
- //----------------------------------------------------------------------------------------
-
- CDrawContent* CDrawSelection::GetDrawContent(Environment* ev)
- {
- return fSelectionContent;
- }
-