home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 15.2 KB | 569 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrawView.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRAWVIEW_H
- #include "DrawView.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.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
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWEVEDEF_H
- #include "FWEveDef.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
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWCLPCMD_H
- #include "FWClpCmd.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
-
- #ifndef SLMixOS_H
- #include "SLMixOS.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_CSuperView)
-
- const FW_ClassTypeConstant LDrawView = FW_TYPE_CONSTANT('d','r','v','w');
- FW_REGISTER_ARCHIVABLE_CLASS(LDrawView, CDrawView, CDrawView::Create, FW_CView::Read, CDrawView::Destroy, FW_CView::Write)
-
- //========================================================================================
- // CDrawView
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawView::CDrawView
- //----------------------------------------------------------------------------------------
-
- CDrawView::CDrawView(Environment* ev) :
- FW_CSuperView(ev),
- fDrawPart(NULL),
- fDrawFrame(NULL),
- fDrawPartContent(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // 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);
-
- if (dynamicCanvas)
- {
- FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kRGBWhite);
- DrawGrid(ev, vc, invalidRect); // Render the grid
- }
-
- // ----- Render every shape -----
- FW_CRect updateBox;
- CDrawContentShapeIterator ite(fDrawPartContent);
- for (CBaseShape* theShape = ite.First(); ite.IsNotComplete(); theShape = ite.Next())
- {
- theShape->GetUpdateBox(updateBox);
- if (invalidRect.IsIntersecting(updateBox))
- theShape->RenderShape(ev, odFacet, vc);
- }
-
- // ----- Render selections Handles -----
- FW_CFrame* frame = GetFrame(ev);
- if (frame->HasSelectionFocus(ev) && dynamicCanvas && frame->GetWindow(ev)->IsActive(ev)) // Do not render handles for print / print preview
- fDrawFrame->GetSelection(ev)->RenderSelectionHandles(ev, vc, fDrawFrame->GetZoomFactor());
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::InternalTransformChanged
- //----------------------------------------------------------------------------------------
-
- void CDrawView::InternalTransformChanged(Environment *ev)
- {
- // InternalTransformChanged can be called before fDrawPart as been initialized
- if (fDrawPart != NULL)
- {
- // ----- Set purgeable flag according to visibility -----
- FW_CRect bounds = GetBoundsInContent(ev);
- CDrawContentShapeIterator ite(fDrawPart->GetDrawContent());
- for (CBaseShape* theShape = ite.First(); ite.IsNotComplete(); theShape = ite.Next())
- theShape->MakePurgeable(ev, fDrawFrame, bounds);
-
- CDrawFacetClipper facetClipper(fDrawPart);
- facetClipper.Clip(ev, fDrawFrame->GetPresentation(ev), NULL);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::AdjustToNewLayout
- //----------------------------------------------------------------------------------------
-
- void CDrawView::AdjustToNewLayout(Environment *ev,
- const FW_CPoint& oldExtent,
- const FW_CPoint& newExtent,
- FW_ERedrawVerb redraw)
- {
- FW_UNUSED(oldExtent);
- FW_UNUSED(newExtent);
-
- fDrawFrame->AdjustContentViewSize(ev, redraw);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::AdjustCursor
- //----------------------------------------------------------------------------------------
-
- FW_Handled CDrawView::AdjustCursor(Environment *ev, ODFacet* facet, const FW_CPoint& where, ODEventInfo* eventInfo)
- {
- FW_Handled cursorAdjusted = FW_CView::AdjustCursor(ev, facet, where, eventInfo);
-
- if (cursorAdjusted == FW_kNotHandled &&
- fDrawPart->GetLastActiveFrame(ev) == (FW_CFrame*)fDrawFrame &&
- fDrawPart->GetTool() != kSelectTool)
- {
- FW_gCrossHairCursor.Select();
- cursorAdjusted = FW_kHandled;
- }
-
- return cursorAdjusted;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::DoVirtualKey
- //----------------------------------------------------------------------------------------
-
- FW_Handled CDrawView::DoVirtualKey(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
- {
- FW_Handled wasHandled = FW_kNotHandled;
-
- switch (theVirtualKeyEvent.GetKeyCode(ev))
- {
- case FW_kVKBackspace:
- case FW_kVKClear:
- if (!fDrawFrame->GetSelection(ev)->IsEmpty(ev))
- {
- FW_CClipboardCommand* cmd = GetFrame(ev)->NewClipboardCommand(ev, kODCommandClear);
- if (cmd)
- {
- cmd->Execute(ev);
- wasHandled = FW_kHandled;
- }
- }
- break;
- }
-
- return wasHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::WantsToBeTarget:
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawView::WantsToBeTarget(Environment* ev)
- {
- FW_UNUSED(ev);
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Handled CDrawView::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- ODFacet* theFacet = theMouseEvent.GetFacet(ev);
- CDrawSelection* selection = fDrawFrame->GetSelection(ev);
-
- if (fDrawPart->GetTool() == kSelectTool)
- {
- FW_Handled handled = FW_kNotHandled;
-
- if (selection->IsMouseInDraggableItem(ev, fDrawFrame, theMouseEvent, FALSE))
- {
- if (fDrawFrame->Drag(ev, theMouseEvent))
- handled = FW_kHandled;
- }
- else if (!selection->Resize(ev, theMouseEvent))
- {
- selection->SelectWithRectangle(ev, theMouseEvent);
- handled = FW_kHandled;
- }
-
- return handled;
- }
-
- // ----- If read only don't want to create a new shape -----
- if (fDrawPart->IsReadOnly(ev))
- {
- FW_Beep();
- return FW_kHandled;
- }
-
- // ----- Create a new shape -----
- CBaseShape *theShape = fDrawPartContent->NewShape(ev, fDrawPart->GetTool() - kLine + kLineShape);
-
- FW_TRY
- {
- FW_CStyle trackStyle(fDrawPart->GetRenderVerb() == kFillOnly ? FW_kFixedPos1 : fDrawPart->GetPenSize(), FW_kGrayPat);
- FW_CInk trackInk(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
- theShape->ChangeRenderVerb(ev, kFrameOnly);
- theShape->SetFrameInk(trackInk);
- theShape->SetFrameStyle(trackStyle);
-
- CShapeTracker tracker(ev, this, theFacet, theShape, fDrawPart->IsAutoGridOn());
- if (tracker.Track(ev, theMouseEvent))
- {
-
- CDrawShapeCommand* cmd = FW_NEW(CDrawShapeCommand,
- (ev, fDrawPart, fDrawFrame, selection, theShape));
- if (cmd->Execute(ev))
- {
- theShape->SetFrameInk(FW_kNormalInk);
- theShape->SetFrameStyle(FW_kNormalStyle);
-
- FW_CColor color;
-
- theShape->ChangeRenderVerb(ev, fDrawPart->GetRenderVerb());
- theShape->ChangePenSize(ev, fDrawPart->GetPenSize());
-
- fDrawPart->GetFrameColor(color);
- theShape->ChangeFrameColor(ev, color);
-
- fDrawPart->GetFillColor(color);
- theShape->ChangeFillColor(ev, color);
-
- theShape->ChangeFramePattern(ev, fDrawPart->GetFramePattern());
- theShape->ChangeFillPattern(ev, fDrawPart->GetFillPattern());
-
- FW_CRect dragRect;
- theShape->GetDragRect(dragRect);
-
- FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, dragRect);
-
- CDrawFacetClipper facetClipper(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);
- Invalidate(ev, aqShape, TRUE); // want to invalidate all frames
-
- // ----- Because drawing has already been done in this facet -----
- ViewContentToFrame(ev, aqShape);
- theFacet->Validate(ev, aqShape, NULL);
- }
- else
- delete theShape;
- }
- else
- {
- delete theShape;
- }
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- delete theShape;
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- return FW_kHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::DrawGrid
- //----------------------------------------------------------------------------------------
-
- void CDrawView::DrawGrid(Environment *ev, FW_CGraphicContext& gc, const FW_CRect& invalidRect)
- {
- FW_UNUSED(ev);
- 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_CPattern verticalPat(vertical);
- FW_CPattern horizontalPat(horizontal);
-
- FW_Fixed minY = FW_IntToFixed(72 * (FW_FixedToInt(invalidRect.top) / 72));
- FW_Fixed maxY = FW_IntToFixed(72 * (FW_FixedToInt(invalidRect.bottom + FW_kFixed72) / 72));
- FW_Fixed minX = FW_IntToFixed(72 * (FW_FixedToInt(invalidRect.left) / 72));
- FW_Fixed maxX = FW_IntToFixed(72 * (FW_FixedToInt(invalidRect.right + FW_kFixed72) / 72));
-
- // skip top-most and left-most lines
- FW_Fixed startX = (minX == FW_kFixed0) ? FW_kFixed72 : minX;
- FW_Fixed startY = (minY == FW_kFixed0) ? FW_kFixed72 : minY;
-
- FW_CStyle lineStyle(FW_kFixed0, verticalPat);
- FW_CLineShape line(startX, minY, startX, maxY, FW_kNormalInk, lineStyle);
-
- for (FW_Fixed x = startX; x <= maxX; x += FW_kFixed72)
- {
- line.Render(gc);
- line.MoveShape(FW_kFixed72, FW_kFixed0);
- }
-
- line.GetStyle().SetPattern(horizontalPat);
- line.SetLineStart(minX, startY);
- line.SetLineEnd(maxX, startY);
-
- for (FW_Fixed y = startY; y <= maxY; y += FW_kFixed72)
- {
- line.Render(gc);
- line.MoveShape(FW_kFixed0, FW_kFixed72);
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::SizeChanged
- //----------------------------------------------------------------------------------------
- // My content view size has changed I need to clip my embedded facets. It's better to do it
- // here than in CDrawFrame::FrameShapeChanged because my frame shape can be changing but
- // my bounds may not.
-
- void CDrawView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
- {
- FW_CSuperView::SizeChanged(ev, oldSize);
-
- // ----- Reclip -----
- CDrawFacetClipper facetClipper(fDrawPart);
- facetClipper.Clip(ev, fDrawFrame->GetPresentation(ev));
-
- // ----- Set purgeable flag according to visibility -----
- FW_CRect bounds = GetBoundsInContent(ev);
- CDrawContentShapeIterator ite(fDrawPartContent);
- for (CBaseShape* theShape = ite.First(); ite.IsNotComplete(); theShape = ite.Next())
- theShape->MakePurgeable(ev, fDrawFrame, bounds);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::Create
- //----------------------------------------------------------------------------------------
-
- void* CDrawView::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(stream);
- FW_UNUSED(type);
- FW_SOMEnvironment ev;
- return new CDrawView(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::Destroy
- //----------------------------------------------------------------------------------------
-
- void CDrawView::Destroy(void* object, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- CDrawView* self = (CDrawView*) object;
- delete self;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::Flatten
- //----------------------------------------------------------------------------------------
-
- void CDrawView::Flatten(Environment* ev, FW_CWritableStream& archive) const
- {
- FW_CSuperView::Flatten(ev, archive);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawView::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void CDrawView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CSuperView::InitializeFromStream(ev, stream);
-
- FW_OObjectRegistry* registry = stream.GetRegistry();
- FW_CFrame* frame = (FW_CFrame*) registry->LookupByID(ev, FW_kPreregisteredFrameObject);
- FW_ASSERT(frame != NULL);
-
- fDrawFrame = FW_DYNAMIC_CAST(CDrawFrame, frame);
- FW_ASSERT(fDrawFrame != NULL);
-
- FW_CEmbeddingPart* part = fDrawFrame->GetPart(ev);
- fDrawPart = FW_DYNAMIC_CAST(CDrawPart, part);
- FW_ASSERT(fDrawPart != NULL);
-
- fDrawPartContent = fDrawPart->GetDrawContent();
- FW_ASSERT(fDrawPartContent != NULL);
- }
-
-