home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 14.2 KB | 536 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Frame.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Table.hpp"
-
- // ----- TablePart Includes -----
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef SELECTION_H
- #include "Selection.h"
- #endif
-
- #ifndef TRACKER_H
- #include "Tracker.h"
- #endif
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef LINKING_H
- #include "Linking.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWFCTCLP_H
- #include "FWFctClp.h"
- #endif
-
- #ifndef FWCLPCMD_H
- #include "FWClpCmd.h"
- #endif
-
- #ifndef FWPROXY_H
- #include "FWProxy.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWLNKITE_H
- #include "FWLnkIte.h"
- #endif
-
- #ifndef FWGROWBX_H
- #include "FWGrowBx.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWRECSHP_H
- #include "FWRecShp.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRGNSHP_H
- #include "FWRgnShp.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWCURSOR_H
- #include "FWCursor.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWEVEDEF_H
- #include "FWEveDef.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef FWODTYPS_H
- #include "FWODTyps.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- // ----- Macintosh Toolbox Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__RESOURCES__)
- #include <Resources.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfTable
- #endif
-
- FW_DEFINE_AUTO(CTableFrame)
-
- //========================================================================================
- // class CTableFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::CTableFrame
- //----------------------------------------------------------------------------------------
-
- CTableFrame::CTableFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- CTablePart* tablePart,
- CTablePartContent* tableContent) :
- FW_CEmbeddingFrame(ev, odFrame, presentation, tablePart),
- FW_MDraggableFrame(ev, this),
- FW_MDroppableFrame(ev, this),
- fTablePart(tablePart),
- fTableContent(tableContent),
- fTableView(NULL)
- {
- ChangeDroppableState(ev, FW_kFrameDroppable);
- fDraggedCell.fX = fDraggedCell.fY = -1;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::~CTableFrame
- //----------------------------------------------------------------------------------------
-
- CTableFrame::~CTableFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::GetSelection
- //----------------------------------------------------------------------------------------
-
- CTableSelection* CTableFrame::GetSelection(Environment* ev) const
- {
- return (CTableSelection*)GetPresentation(ev)->GetSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
- // As an embedding frame I can accept anything
-
- ODDragResult CTableFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
- {
- FW_UNUSED(ev);
- FW_UNUSED(dragInfo);
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::DoVirtualKey
- //----------------------------------------------------------------------------------------
-
- FW_Handled CTableFrame::DoVirtualKey(Environment* ev, const FW_CVirtualKeyEvent& theVirtualKeyEvent)
- {
- FW_Handled wasHandled = FW_kNotHandled;
- CCell cell = this->GetSelection(ev)->GetSelectedCell();
- CCell size = fTableContent->GetMaxRowCol();
-
- switch (theVirtualKeyEvent.GetKeyCode(ev))
- {
- case FW_kVKLeft:
- if(cell.fX > 0)
- {
- cell.fX -= 1;
- this->SelectCell(ev, cell);
- wasHandled = FW_kHandled;
- }
- break;
- case FW_kVKRight:
- if(cell.fX < size.fX - 1)
- {
- cell.fX += 1;
- this->SelectCell(ev, cell);
- wasHandled = FW_kHandled;
- }
- break;
- case FW_kVKUp:
- if(cell.fY > 0)
- {
- cell.fY -= 1;
- this->SelectCell(ev, cell);
- wasHandled = FW_kHandled;
- }
- break;
- case FW_kVKDown:
- if(cell.fY < size.fY - 1)
- {
- cell.fY += 1;
- this->SelectCell(ev, cell);
- wasHandled = FW_kHandled;
- }
- break;
-
- case FW_kVKBackspace:
- case FW_kVKClear:
- FW_CClipboardCommand* cmd = this->NewClipboardCommand(ev, kODCommandClear);
- if (cmd)
- {
- cmd->Execute(ev);
- wasHandled = FW_kHandled;
- }
- break;
- }
-
- return wasHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::DoMouseDownInEmbeddedFrameBorder
- //----------------------------------------------------------------------------------------
-
- FW_Handled CTableFrame::DoMouseDownInEmbeddedFrameBorder(Environment* ev, const FW_CBorderMouseEvent& theBorderMouseEvent)
- {
- FW_Handled result = FW_kNotHandled;
-
- if (fTableView->IsGridShown(ev) && this->Drag(ev, theBorderMouseEvent))
- result = FW_kHandled;
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::SelectCell
- //----------------------------------------------------------------------------------------
-
- void CTableFrame::SelectCell(Environment* ev, const CCell& cell)
- {
- GetSelection(ev)->Select(ev, cell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::GetContentRect
- //----------------------------------------------------------------------------------------
-
- FW_CRect CTableFrame::GetContentRect(Environment* ev) const
- {
- FW_CRect contentRect = GetBounds(ev);
-
- FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
-
- contentRect.bottom -= sbSize.y;
- contentRect.right -= sbSize.x;
-
- return contentRect;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::Drag
- //----------------------------------------------------------------------------------------
-
- FW_Handled CTableFrame::Drag(Environment* ev, const FW_CMouseEvent& event)
- {
- fDraggedCell = GetSelection(ev)->GetSelectedCell();
-
- FW_Boolean result = FW_MDraggableFrame::Drag(ev, event);
-
- fDraggedCell.fX = fDraggedCell.fY = -1;
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::FocusStateChanged
- //----------------------------------------------------------------------------------------
-
- void CTableFrame::FocusStateChanged(Environment* ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
- {
- FW_CEmbeddingFrame::FocusStateChanged(ev, focus, newState, newOwner);
-
- if (focus == FW_CPart::fgSelectionFocusToken)
- {
- fTableView->ChangeHighlightState(ev, newState ? kODFullHighlight : kODDimHighlight);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::NewDropCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDropCommand* CTableFrame::NewDropCommand(Environment* ev,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint)
- {
- FW_UNUSED(frame);
- FW_ASSERT(frame == this);
-
- CCell dropCell;
- ETableLoc loc = fTableContent->HitTest(ev, dropPoint, dropCell);
-
- if (loc != kTLCell || dropCell == fDraggedCell || fTableContent->CellToProxy(dropCell) != NULL) // If alreay a proxy gave up
- return NULL;
- else
- return FW_NEW(CCellDropCommand, (ev, fTablePart, fTableContent, this,
- dropInfo, odFacet, dropPoint,
- dropCell, fDraggedCell));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::NewDropTracker
- //----------------------------------------------------------------------------------------
-
- FW_CDropTracker* CTableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
- {
- return new CTableDropTracker(ev, fTablePart, fTableContent, (CTableView*)view, facet, fDraggedCell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::NewClipboardCommand
- //----------------------------------------------------------------------------------------
-
- FW_CClipboardCommand* CTableFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
- {
- return FW_NEW(CTableEditCommand, (ev,
- commandID,
- fTablePart,
- fTableContent,
- this,
- this->GetSelection(ev)));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::NewDragCommand
- //----------------------------------------------------------------------------------------
-
- FW_CDragCommand* CTableFrame::NewDragCommand(Environment* ev,
- FW_CFrame* theFrame,
- const FW_CMouseEvent& theMouseEvent)
- {
- FW_UNUSED(theMouseEvent);
- return FW_NEW(CCellDragCommand, (ev, fTableContent, theFrame, this->GetSelection(ev)));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::NewInsertCommand
- //----------------------------------------------------------------------------------------
- FW_CInsertCommand* CTableFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
- {
- return FW_NEW(CTableInsertCommand, (ev,
- this,
- fileSpec,
- fTablePart,
- GetSelection(ev)->GetSelectedCell()));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::MoveProxy
- //----------------------------------------------------------------------------------------
-
- void CTableFrame::MoveProxy(Environment* ev, CTableProxy* proxy, const CCell& destCell)
- {
- // Invalidate the source cell
- FW_CRect rect;
- CCell srcCell = proxy->GetCell();
- fTableContent->FindRect(srcCell, rect);
- this->GetPresentation(ev)->Invalidate(ev, rect);
-
- proxy->MoveEmbeddedFrames(ev, destCell);
- proxy->SetCell(destCell);
- this->SelectCell(ev, destCell);
-
- // Invalidate the destination cell
- fTableContent->FindRect(destCell, rect);
- this->GetPresentation(ev)->Invalidate(ev, rect);
-
- }
-
- //---------------------------------------------------------------------------------------
- // CTableFrame::FacetAdded
- //---------------------------------------------------------------------------------------
-
- void CTableFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
- {
- FW_CEmbeddingFrame::FacetAdded(ev, facet, facetCount); // call inherited
-
- if (facetCount == 1)
- fTablePart->DoPostCreate(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::PostCreateViewFromStream
- //----------------------------------------------------------------------------------------
- // PostCreateViewFromStream is called after subviews are created from resources.
- // Add code which cannot be handled by current resource types.
-
- void CTableFrame::PostCreateViewFromStream(Environment* ev)
- {
- fTableView = (CTableView*)FindViewByID(ev, kTableViewID);
-
- // WARNING: Make sure that classes created from resources won't be dead-stripped
- FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
- // My content view size has changed I need to clip my embedded facets.
-
- void CTableFrame::FrameShapeChanged(Environment* ev)
- {
- FW_CEmbeddingFrame::FrameShapeChanged(ev);
-
- FW_CFacetClipper facetClipper;
- facetClipper.Clip(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::AdjustZoomedWindowSize
- //----------------------------------------------------------------------------------------
- // proposedSize is the interior size of the window
-
- void CTableFrame::AdjustZoomedWindowSize(Environment *ev, FW_CPoint& proposedSize)
- {
- FW_UNUSED(ev);
- proposedSize = GetContentView(ev)->GetExtent(ev) + FW_CScrollBar::GetDefaultScrollBarSize();
- }
-
- //----------------------------------------------------------------------------------------
- // CTableFrame::AdjustContentViewSize
- //----------------------------------------------------------------------------------------
-
- void CTableFrame::AdjustContentViewSize(Environment* ev, FW_ERedrawVerb redraw)
- {
- FW_CRect contentRect = GetContentRect(ev);
-
- FW_CPoint drawingSize = fTableContent->GetExtent();
-
- FW_CPoint drawViewSize(FW_Minimum(drawingSize.x, contentRect.Width()),
- FW_Minimum(drawingSize.y, contentRect.Height()));
-
- FW_CPoint currentSize = GetContentView(ev)->GetSize(ev);
- if (currentSize != drawViewSize)
- GetContentView(ev)->SetSize(ev, drawViewSize, redraw);
- }
-