home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 10.7 KB | 378 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Selection.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Table.hpp"
-
- // ----- TablePart Includes -----
-
- #ifndef SELECTION_H
- #include "Selection.h"
- #endif
-
- #ifndef PROXY_H
- #include "Proxy.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef LINKING_H
- #include "Linking.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- ODF Includes -----
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfTable
- #endif
-
- FW_DEFINE_AUTO(CTableSelection)
-
- //========================================================================================
- // class CTableSelection
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CTableSelection
- //----------------------------------------------------------------------------------------
-
- CTableSelection::CTableSelection(Environment* ev, CTablePart* tablePart, CTableContent* content) :
- FW_CSelection(ev, true, true), // allow linking
- fTablePart(tablePart),
- fTableContent(content)
- {
- fSelectionContent = FW_NEW(CTableSelectionContent, (ev, tablePart, content));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::~CTableSelection
- //----------------------------------------------------------------------------------------
-
- CTableSelection::~CTableSelection()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::GetSelectedContent
- //----------------------------------------------------------------------------------------
-
- FW_CContent* CTableSelection::GetSelectedContent(Environment* ev)
- {
- return fSelectionContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::IsEmpty
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::IsEmpty(Environment* ev) const
- {
- return fSelectionContent->GetSelectedProxy(ev) == NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CloseSelection
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::CloseSelection(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::ClearSelection
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::ClearSelection(Environment* ev)
- {
- CTableProxy* proxy = fSelectionContent->GetSelectedProxy(ev);
- if (proxy)
- {
- fTablePart->AboutToClearCell(ev, fSelectionContent->GetCell()); // break existing links before removing the proxy
-
- fTablePart->PartChanged(ev);
-
- //--- Remove the proxy ---
- proxy->DetachEmbeddedFrames(ev);
- fTableContent->RemoveProxy(proxy);
- InvalidateSelection(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::SelectAll
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::SelectAll(Environment* ev)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::Select
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::Select(Environment* ev, const CCell& cell)
- {
- // Get the active frame
- CTableFrame* activeFrame = (CTableFrame*)fTablePart->GetLastActiveFrame(ev);
-
- // Get the previous selected cell and proxy
- CCell oldCell = fSelectionContent->GetCell();
- CTableProxy* proxy = fTableContent->CellToProxy(oldCell);
-
- // Get the link manager so we can check for links
- CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
- CTableLink* link = NULL;
- CTableLinkSource* linkSource = NULL;
-
- // if the previous selected cell was containing a proxy then change its selected state
- // and change its hilite
- if (proxy)
- {
- proxy->Selected(FALSE);
-
- link = linkMgr->CellToLink(ev, oldCell);
- if (link)
- link->Select(ev, false);
- linkSource = linkMgr->CellToSourceLink(ev, oldCell);
- if (linkSource)
- linkSource->Select(ev, false);
- }
-
- // Draw the cell hilite
- if (activeFrame)
- activeFrame->ChangeHiliteState(ev, FALSE);
-
- // select the new cell
- fSelectionContent->SetCell(cell);
-
- // get the proxy contained in the new selected cell
- proxy = fTableContent->CellToProxy(cell);
-
- // if the new selected cell contains a proxy then change its selected state
- // and hilite
- if (proxy)
- {
- proxy->Selected(TRUE);
-
- link = linkMgr->CellToLink(ev, cell);
- if (link)
- link->Select(ev, true);
- linkSource = linkMgr->CellToSourceLink(ev, cell);
- if (linkSource)
- linkSource->Select(ev, true);
- }
-
- // Draw the cell hilite
- if (activeFrame)
- activeFrame->ChangeHiliteState(ev, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CreateSelectionShape
- //----------------------------------------------------------------------------------------
-
- ODShape* CTableSelection::CreateSelectionShape(Environment* ev, ODFacet* facet, FW_CFrame* frame) const
- {
- FW_UNUSED(facet);
- FW_UNUSED(frame);
-
- return fSelectionContent->CreateDataFrameShape(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::InvalidateSelection
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::InvalidateSelection(Environment* ev)
- {
- FW_CAcquiredODShape aqShape(fSelectionContent->CreateDataFrameShape(ev));
- GetPresentation(ev)->Invalidate(ev, aqShape);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::SelectProxy
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::SelectProxy(Environment* ev, CTableProxy* proxy)
- {
- CCell cell = proxy->GetCell();
- this->Select(ev, cell);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::GetSelectedCell
- //----------------------------------------------------------------------------------------
-
- CCell CTableSelection::GetSelectedCell() const
- {
- return fSelectionContent->GetCell();
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::IsMouseInDraggableItem
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::IsMouseInDraggableItem(Environment* ev,
- FW_CFrame* frame,
- const FW_CMouseEvent& theMouseEvent,
- FW_Boolean inBackground)
- {
- FW_UNUSED(inBackground);
-
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
-
- CCell cell;
- ETableLoc tl = ((CTableFrame*)frame)->HitTest(ev, where, cell);
-
- return (tl == kTLCell && fTableContent->CellToProxy(cell) != NULL);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::UpdateSelectionOnMouseDown
- //----------------------------------------------------------------------------------------
-
- void CTableSelection::UpdateSelectionOnMouseDown(Environment* ev,
- const FW_CMouseEvent& mouseEvent,
- ODFacet* embeddedFacet,
- FW_Boolean inEmbeddedFrameBorder,
- FW_Boolean inBackground)
- {
- FW_UNUSED(inBackground);
-
- CTableFrame* tableFrame = (CTableFrame*)FW_CFrame::ODtoFWFrame(ev, mouseEvent.GetFacet(ev)->GetFrame(ev));
-
- if (tableFrame->IsGridShown(ev))
- {
- FW_Boolean select = FALSE;
- CCell cell;
-
- if (inEmbeddedFrameBorder)
- {
- FW_MProxy* proxy = tableFrame->GetProxy(ev, embeddedFacet->GetFrame(ev));
- FW_ASSERT(proxy);
-
- cell = ((CTableProxy*)proxy)->GetCell();
- select = TRUE;
- }
- else
- {
- FW_CPoint where = mouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
-
- ETableLoc tl = tableFrame->HitTest(ev, where, cell);
-
- select = (tl == kTLCell && cell != GetSelectedCell());
- }
-
- if (select)
- Select(ev, cell);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::CanPasteAsLink
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::CanPasteAsLink(Environment* ev, ODPasteAsMergeSetting& setting,
- ODStorageUnit* su)
- {
- FW_UNUSED(su);
- setting = kODPasteAsEmbedOnly; // table has no content to merge
-
- // Check whether the selected cell already contains an embedded part.
- // If it doesn't, allow Paste As.
- return this->IsEmpty(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::IsSelectionLinkable
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTableSelection::IsSelectionLinkable(Environment* ev)
- {
- FW_Boolean result = fAllowLinkSource;
-
- if (fAllowLinkSource)
- {
- // make sure the cell is not a link destination
- CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
- if (linkMgr->CellToLink(ev, this->GetSelectedCell()))
- result = FALSE;
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableSelection::DoFindLinkSource
- //----------------------------------------------------------------------------------------
-
- FW_CLinkSource* CTableSelection::DoFindLinkSource(Environment* ev) // Override
- {
- CTableLinkManager* linkMgr = (CTableLinkManager*)fTablePart->GetLinkManager(ev);
- return linkMgr->CellToSourceLink(ev, fSelectionContent->GetCell());
- }
-
-