home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 11.4 KB | 405 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: View.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Container.hpp"
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef DEFINES_K
- #include "Defines.k"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.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
-
- #ifndef FWFCTCLP_H
- #include "FWFctClp.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
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- //========================================================================================
- // Runtime Information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfcontainer
- #endif
-
- //========================================================================================
- // CContainerView
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(CContainerView, FW_CSuperView)
-
- // IMPORTANT: the constant below must match the resource label for RContainerView in views.fr
- const FW_ClassTypeConstant LContainerView = FW_TYPE_CONSTANT('c','t','v','w');
- FW_REGISTER_ARCHIVABLE_CLASS(LContainerView, CContainerView, CContainerView::Create, FW_CView::Read, CContainerView::Destroy, FW_CView::Write)
-
- //----------------------------------------------------------------------------------------
- // CContainerView::CContainerView
- //----------------------------------------------------------------------------------------
-
- CContainerView::CContainerView(Environment* ev, CContainerFrame* frame, FW_CRect& bounds,
- FW_CPoint& extent, CContainerPart* part) :
- FW_CSuperView(ev, frame, bounds, kContainerViewID, extent, FW_kXYScrolling),
- fContainerPart(part),
- fContainerFrame(frame),
- fPartContent(part->GetPartContent())
- {
- }
-
- CContainerView::CContainerView(Environment* ev) :
- FW_CSuperView(ev),
- fContainerPart(NULL),
- fContainerFrame(NULL),
- fPartContent(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::~CContainerView
- //----------------------------------------------------------------------------------------
-
- CContainerView::~CContainerView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::Draw
- //----------------------------------------------------------------------------------------
-
- void CContainerView::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_CColor(56000, 56000, 65535));
-
-
- // ----- Render every proxy -----
- // Note: like ODFDraw I don't let OpenDoc draws embedded facets because I want to
- // manage z-ordering myself
- CContentProxyIterator ite(fPartContent);
- for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
- {
- FW_CRect updateBox = proxy->GetBounds(ev);
- if (invalidRect.IsIntersecting(updateBox))
- proxy->Render(ev, odFacet, vc);
- }
-
- // ----- Render selection handles -----
- // Do not render handles for print / print preview
- if (GetFrame(ev)->HasSelectionFocus(ev) && odFacet->GetCanvas(ev)->IsDynamic(ev))
- {
- fContainerFrame->GetSelection(ev)->RenderSelectionHandles(ev, vc);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::AdjustToNewLayout
- //----------------------------------------------------------------------------------------
-
- void CContainerView::AdjustToNewLayout(Environment *ev, const FW_CPoint& oldExtent,
- const FW_CPoint& newExtent, FW_Boolean refresh)
- {
- FW_UNUSED(oldExtent);
- FW_UNUSED(newExtent);
-
- fContainerFrame->AdjustContentViewSize(ev, refresh);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::AdjustCursor
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::AdjustCursor(Environment* ev, ODFacet* facet, const FW_CPoint& where)
- {
- if (fContainerFrame->GetWindow(ev)->IsActive(ev) == false)
- {
- // Keep the arrow cursor in non-active windows
- FW_gArrowCursor.Select();
- }
- // Must call the base class first to adjust cursor in active border of embedded frames
- else if (FW_CView::AdjustCursor(ev, facet, where) == false)
- {
- // convert mouse position to content space for WhichProxy
- FW_CPoint mouse(where);
- FrameToViewContent(ev, mouse);
- FW_CViewContext vc(ev, this, facet);
-
- // Check if mouse is over the selection's handle first
- short proxyHandle;
- CContainerSelection* selection = fContainerFrame->GetSelection(ev);
-
- if (selection->WhichHandle(ev, vc, mouse, proxyHandle))
- {
- switch(proxyHandle)
- {
- case kInTopLeftCorner:
- case kInBottomRightCorner:
- FW_gSizeNWSECursor.Select();
- break;
- case kInTopRightCorner:
- case kInBottomLeftCorner:
- FW_gSizeNESWCursor.Select();
- break;
- case kInTopMiddle:
- case kInBottomMiddle:
- FW_gSizeNSCursor.Select();
- break;
- case kInLeftMiddle:
- case kInRightMiddle:
- FW_gSizeWECursor.Select();
- break;
- }
- }
-
- // Else use the hand cursor over a proxy to show dragging operation
- else if (fContainerPart->WhichProxy(ev, vc, mouse, TRUE))
- FW_gOpenHandCursor.Select();
-
- // Else use the cross hair cursor to show selection operation
- else
- FW_gCrossHairCursor.Select();
- }
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::DoVirtualKey
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::DoVirtualKey(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
- {
- FW_Boolean wasHandled = FALSE;
-
- switch (theVirtualKeyEvent.GetKeyCode(ev))
- {
- case FW_kVKBackspace:
- case FW_kVKClear:
- if (!fContainerFrame->GetSelection(ev)->IsEmpty(ev))
- {
- FW_CClipboardCommand* cmd = GetFrame(ev)->NewClipboardCommand(ev, kODCommandClear);
- if (cmd)
- {
- cmd->Execute(ev);
- wasHandled = TRUE;
- }
- }
- break;
- }
-
- return wasHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::WantsToBeTarget
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::WantsToBeTarget(Environment* ev)
- {
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CContainerView::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_Boolean result = TRUE;
-
- ODFacet* theFacet = theMouseEvent.GetFacet(ev);
- CContainerSelection* selection = fContainerFrame->GetSelection(ev);
-
- if (selection->IsMouseInDraggableItem(ev, fContainerFrame, theMouseEvent, FALSE))
- {
- FW_gClosedHandCursor.Select();
- result = fContainerFrame->Drag(ev, theMouseEvent);
- }
- else if (!selection->Resize(ev, theMouseEvent))
- {
- selection->SelectWithRectangle(ev, theMouseEvent);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::SizeChanged
- //----------------------------------------------------------------------------------------
- // My content view size has changed so I need to clip my embedded facets. It's better to do it
- // here than in CContainerFrame::FrameShapeChanged because my frame shape can be changing but
- // my bounds may not.
-
- void CContainerView::SizeChanged(Environment* ev, const FW_CPoint& oldSize)
- {
- FW_CSuperView::SizeChanged(ev, oldSize);
-
- FW_CFacetClipper facetClipper(ev, fContainerPart);
- facetClipper.Clip(ev, fContainerFrame, NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::Create
- //----------------------------------------------------------------------------------------
-
- void* CContainerView::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(stream);
- FW_UNUSED(type);
- FW_SOMEnvironment ev;
-
- // Call minimal constructor. Data fields will be initialized in InitializeFromStream
- return new CContainerView(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::Destroy
- //----------------------------------------------------------------------------------------
-
- void CContainerView::Destroy(void* object, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- CContainerView* self = (CContainerView*) object;
- delete self;
- }
-
- //----------------------------------------------------------------------------------------
- // CContainerView::Flatten
- //----------------------------------------------------------------------------------------
- // This method is required to handle custom resource fields added to the base type
-
- void CContainerView::Flatten(Environment* ev, FW_CWritableStream& archive) const
- {
- FW_CSuperView::Flatten(ev, archive);
-
- // Container doesn't have any custom fields to stream out
- }
-
-
- //----------------------------------------------------------------------------------------
- // CContainerView::InitializeFromStream
- //----------------------------------------------------------------------------------------
- // This method is required to handle custom resource fields added to the base type
- // and to initialize other class fields not initialized in the minimal ctor.
-
- void CContainerView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- // Read-in the base resource first
- FW_CSuperView::InitializeFromStream(ev, stream);
-
- // Get a pointer to the frame which was pre-registered
- FW_OObjectRegistry* registry = stream.GetRegistry();
- FW_CFrame* frame = (FW_CFrame*) registry->LookupByID(ev, FW_kPreregisteredFrameObject);
- FW_ASSERT(frame != NULL);
-
- // Set the fContainerFrame, fContainerPart & fPartContent fields
- fContainerFrame = FW_DYNAMIC_CAST(CContainerFrame, frame);
- FW_ASSERT(fContainerFrame != NULL);
-
- FW_CEmbeddingPart* part = fContainerFrame->GetPart(ev);
- fContainerPart = FW_DYNAMIC_CAST(CContainerPart, part);
- FW_ASSERT(fContainerPart != NULL);
-
- fPartContent = fContainerPart->GetPartContent();
- FW_ASSERT(fPartContent != NULL);
- }
-
-