home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 11.2 KB | 442 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawView.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Laurent Delamare
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWVIEW_H
- #include "DrawView.h"
- #endif
-
- #ifndef DRAWDEF_H
- #include "DrawDef.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef EDITCMDS_H
- #include "EditCmds.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.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 DRAWPRXY_H
- #include "DrawPrxy.h"
- #endif
-
- #ifndef SHPTRAKR_H
- #include "ShpTrakr.h"
- #endif
-
- #ifndef DRAWCMDS_H
- #include "DrawCmds.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef UTILS_H
- #include "Utils.h"
- #endif
-
- #ifndef DRWDDCMD_H
- #include "DrwDDCmd.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWLINSHP_H
- #include "FWLinShp.h"
- #endif
-
- #ifndef FWBMPSHP_H
- #include "FWBmpShp.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawframes
- #endif
-
- FW_DEFINE_CLASS_M1(CDrawView, FW_CView);
-
- //========================================================================================
- // CDrawView
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawView::CDrawView
- //----------------------------------------------------------------------------------------
-
- CDrawView::CDrawView(Environment* ev, CDrawFrame* frame, FW_CRect& bounds, CDrawPart* drawPart) :
- FW_CView(ev, (FW_CView*)frame, bounds),
- fDrawPart(drawPart),
- fDrawFrame(frame)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::~CDrawView
- //----------------------------------------------------------------------------------------
-
- CDrawView::~CDrawView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::Draw
- //----------------------------------------------------------------------------------------
-
- void CDrawView::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
- {
- // Render inside the content view
- FW_CViewContext vc(ev, this, odFacet, invalidShape);
- FW_CRect invalidRect;
- vc.GetClipRect(invalidRect);
-
- FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
-
- // ----- Determine what to Render -----
- ODCanvas* canvas = odFacet->GetCanvas(ev);
- FW_Boolean dynamicCanvas = canvas->IsDynamic(ev);
-
- // ----- Render the grid -----
- if (dynamicCanvas)
- DrawGrid(ev, vc, invalidRect);
-
- // ----- Render every shape -----
- FW_CRect updateBox;
- FW_COrderedCollectionIterator ite(fDrawPart->GetShapeList());
- for (CBaseShape* theShape = (CBaseShape*)ite.First(); ite.IsNotComplete(); theShape = (CBaseShape*)ite.Next())
- {
- theShape->GetUpdateBox(updateBox);
- if (invalidRect.IsIntersecting(updateBox))
- theShape->RenderShape(ev, odFacet, vc);
- }
-
- // ----- Render selections Handles -----
- if (IsActive(ev) && dynamicCanvas) { // Do not render handles for print / print preview
- fDrawFrame->GetSelection(ev)->RenderSelectionHandles(ev, vc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::AdjustCursor
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawView::AdjustCursor(Environment *ev, ODFacet* facet, const FW_CPoint& where)
- {
- FW_Boolean cursorAdjusted = FW_CView::AdjustCursor(ev, facet, where);
-
- if (!cursorAdjusted &&
- fDrawPart->GetActiveFrame(ev) == (FW_CFrame*)fDrawFrame &&
- fDrawPart->GetTool() != kSelectTool)
- {
- FW_gCrossHairCursor.Select();
- cursorAdjusted = TRUE;
- }
-
- return cursorAdjusted;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawView::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- ODFacet* theFacet = theMouseEvent.GetFacet(ev);
- CDrawSelection* selection = fDrawFrame->GetSelection(ev);
-
- if (fDrawPart->GetTool() == kSelectTool)
- {
- if (selection->IsMouseInDraggableItem(ev, fDrawFrame, theMouseEvent, FALSE))
- {
- fDrawFrame->Drag(ev, theMouseEvent);
- }
- else if (!selection->Resize(ev, theMouseEvent))
- {
- selection->SelectWithRectangle(ev, theMouseEvent);
- }
-
- return TRUE;
- }
-
- // ----- If read only don't want to create a new shape -----
- if (fDrawPart->IsReadOnly(ev))
- {
- FW_Beep();
- return TRUE;
- }
-
- // ----- Create a new shape -----
- CBaseShape *theShape = fDrawPart->NewShape(ev, fDrawPart->GetTool() - kLine + kLineShape);
-
- FW_TRY
- {
- FW_PStyle trackStyle(fDrawPart->GetRenderVerb() == kFillOnly ? FW_kFixedPos1 : fDrawPart->GetPenSize(), FW_kGrayPat);
- FW_PInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- theShape->ChangeRenderVerb(ev, fDrawPart, kFrameOnly);
- theShape->SetFrameInk(trackInk);
- theShape->SetFrameStyle(trackStyle);
-
- CShapeTracker tracker(ev, this, theFacet, theShape, fDrawPart->IsAutoGridOn());
- if (tracker.Track(ev, theMouseEvent))
- {
- theShape->SetFrameInk(FW_kNormalInk);
- theShape->SetFrameStyle(FW_kNormalStyle);
-
- FW_CColor color;
-
- theShape->ChangeRenderVerb(ev, fDrawPart, fDrawPart->GetRenderVerb());
- theShape->ChangePenSize(ev, fDrawPart, fDrawPart->GetPenSize());
-
- fDrawPart->GetFrameColor(color);
- theShape->ChangeFrameColor(ev, fDrawPart, color);
-
- fDrawPart->GetFillColor(color);
- theShape->ChangeFillColor(ev, fDrawPart, color);
-
- theShape->ChangeFramePattern(ev, fDrawPart, fDrawPart->GetFramePattern());
- theShape->ChangeFillPattern(ev, fDrawPart, fDrawPart->GetFillPattern());
-
- CDrawShapeCommand* cmd = FW_NEW(CDrawShapeCommand,
- (ev, fDrawPart, fDrawFrame, selection, theShape));
- fDrawPart->ExecuteCommand(ev, cmd);
-
- FW_CRect dragRect;
- theShape->GetDragRect(dragRect);
-
- FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, dragRect);
-
- CDrawFacetClipper facetClipper(ev, fDrawPart);
- facetClipper.Clip(ev, fDrawFrame->GetPresentation(ev), aqShape);
-
- FW_CViewContext vc(ev, this, theMouseEvent.GetFacet(ev));
- theShape->RenderShape(ev, theFacet, vc);
-
- theShape->GetUpdateBox(ev, aqShape);
- fDrawFrame->GetPresentation(ev)->Invalidate(ev, aqShape, theFacet); // will not invalide theFacet
- }
- else
- {
- delete theShape;
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete theShape;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::DoMouseDownInEmbeddedFrameBorder
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawView::DoMouseDownInEmbeddedFrameBorder(Environment *ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
- {
- fDrawPart->SetTool(ev, kSelectTool);
-
- GetFrame(ev)->Drag(ev, theBorderMouseEvent);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::DoMouseDownInEmbeddedFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawView::DoMouseDownInEmbeddedFrame(Environment* ev,
- const FW_CEmbeddedMouseEvent& theEmbeddedMouseEvent)
- {
- FW_Boolean handled = TRUE;
-
- if (theEmbeddedMouseEvent.GetNumberOfClicks(ev) > 1)
- GetFrame(ev)->OpenSelection(ev);
- else
- handled = DoMouseDown(ev, theEmbeddedMouseEvent);
-
- return handled;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::DrawGrid
- //----------------------------------------------------------------------------------------
-
- void CDrawView::DrawGrid(Environment *ev, FW_CGraphicContext& gc, const FW_CRect& invalidRect)
- {
- if (fDrawFrame->IsGraphicsGridOn())
- {
- FW_BitPattern vertical = {0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
- FW_BitPattern horizontal = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80};
-
- FW_PPattern verticalPat(vertical);
- FW_PPattern horizontalPat(horizontal);
-
- FW_CFixed minY = FW_IntToFixed(72 * (invalidRect.top.AsInt() / 72));
- FW_CFixed maxY = FW_IntToFixed(72 * ((invalidRect.bottom + FW_kFixed72).AsInt() / 72));
- FW_CFixed minX = FW_IntToFixed(72 * (invalidRect.left.AsInt() / 72));
- FW_CFixed maxX = FW_IntToFixed(72 * ((invalidRect.right + FW_kFixed72).AsInt() / 72));
-
- // skip top-most and left-most lines
- FW_CFixed startX = (minX == FW_kFixed0) ? FW_kFixed72 : minX;
- FW_CFixed startY = (minY == FW_kFixed0) ? FW_kFixed72 : minY;
-
- FW_PStyle lineStyle(FW_IntToFixed(0), verticalPat);
- FW_CLineShape line(startX, minY, startX, maxY, FW_kNormalInk, lineStyle);
-
- for (FW_CFixed x = startX; x <= maxX; x += FW_kFixed72)
- {
- line.Render(gc);
- line.MoveShape(FW_kFixed72, FW_IntToFixed(0));
- }
-
- line.GetStyle()->SetPattern(horizontalPat);
- line.SetLineStart(minX, startY);
- line.SetLineEnd(maxX, startY);
-
- for (FW_CFixed y = startY; y <= maxY; y += FW_kFixed72)
- {
- line.Render(gc);
- line.MoveShape(FW_IntToFixed(0), FW_kFixed72);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::Activate
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawView::Activate(Environment* ev)
- {
- FW_Boolean newState = FW_CView::Activate(ev);
-
- if (newState) {
- fDrawFrame->GetSelection(ev)->RenderAllHandles(ev, fDrawFrame);
- }
-
- return newState;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::Deactivate
- //----------------------------------------------------------------------------------------
-
- void CDrawView::Deactivate(Environment* ev)
- {
- FW_CView::Deactivate(ev);
- fDrawFrame->GetSelection(ev)->RenderAllHandles(ev, fDrawFrame);
- }
-