home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 5.4 KB | 167 lines | [TEXT/CWIE] |
- //========================================================================================
- //
- // File: Scroller.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef SCROLLER_H
- #include "Scroller.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- //========================================================================================
- // CLASS FW_CScrollBarScroller
- //========================================================================================
-
- FW_DEFINE_AUTO(CTableScroller)
- FW_DEFINE_CLASS_M1(CTableScroller, FW_CScrollBarScroller)
-
- const FW_ClassTypeConstant FW_LTableScroller = FW_TYPE_CONSTANT('t','b','s','c');
- FW_REGISTER_ARCHIVABLE_CLASS(FW_LTableScroller, CTableScroller, CTableScroller::Create, FW_CScroller::Read, CTableScroller::Destroy, FW_CScroller::Write)
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::CTableScroller
- //----------------------------------------------------------------------------------------
-
- CTableScroller::CTableScroller(Environment* ev) :
- FW_CScrollBarScroller(ev),
- fTableFrame(NULL),
- fTableContent(NULL)
- {
- FW_UNUSED(ev);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::~CTableScroller
- //----------------------------------------------------------------------------------------
-
- CTableScroller::~CTableScroller()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::TranslationToPixels
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CTableScroller::TranslationToPixels(Environment* ev, const FW_CPoint& translation) const
- {
- FW_UNUSED(ev);
- FW_CPoint pixelOffset(fTableContent->FindLeft(FW_FixedToInt(translation.x)) - kPenWidth,
- fTableContent->FindTop(FW_FixedToInt(translation.y)) - kPenHeight);
- return pixelOffset;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::PixelsToTranslation
- //----------------------------------------------------------------------------------------
-
- FW_CPoint CTableScroller::PixelsToTranslation(const FW_CPoint& pixelOffset) const
- {
- CCell cell;
- fTableContent->FindCell(pixelOffset, cell);
-
- FW_CPoint offset(FW_IntToFixed(cell.fX), FW_IntToFixed(cell.fY));
- return offset;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::InitializeFromStream
- //----------------------------------------------------------------------------------------
-
- void CTableScroller::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
- {
- FW_CScrollBarScroller::InitializeFromStream(ev, stream);
-
- fTableFrame = (CTableFrame*)fFrame;
- fTableContent = fTableFrame->GetTableContent(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::GetScrollingArea
- //----------------------------------------------------------------------------------------
-
- FW_CRect CTableScroller::GetScrollingArea(Environment* ev) const
- {
- FW_CRect bounds = fFrame->GetContentView(ev)->GetBoundsInContent(ev);
-
- FW_CRect scrollingBounds;
- scrollingBounds[FW_kTopLeft] = PixelsToTranslation(bounds[FW_kTopLeft]);
- scrollingBounds[FW_kBotRight] = PixelsToTranslation(bounds[FW_kBotRight]);
-
- FW_CPoint extent = fTableContent->GetExtent();
-
- if (bounds.right > extent.x)
- scrollingBounds.right += FW_kFixedPos1;
- if (bounds.bottom > extent.y)
- scrollingBounds.bottom += FW_kFixedPos1;
-
- return scrollingBounds;
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::CalcMaxTranslation
- //----------------------------------------------------------------------------------------
-
- FW_Fixed CTableScroller::CalcMaxTranslation(Environment* ev, FW_Fixed scrollingArea, FW_XYSelector direction)
- {
- FW_UNUSED(scrollingArea);
- FW_CRect bounds = fFrame->GetContentView(ev)->GetBoundsInContent(ev);
- FW_CPoint extent = fTableContent->GetExtent();
-
- FW_Fixed pixelMax = extent[direction] - bounds.Length(direction);
- if (pixelMax < FW_kFixed0)
- return FW_kFixed0;
-
- CCell maxCell = fTableContent->GetMaxRowCol();
-
- short max = direction == FW_kHorizontal ? maxCell.fX : maxCell.fY;
-
- short c = 0;
- FW_Fixed pos = FW_kFixed0;
- while (pos < pixelMax && c <= max)
- {
- pos += fTableContent->GetCellSize(c, direction);
- c++;
- }
-
- return FW_IntToFixed(c);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::Create
- //----------------------------------------------------------------------------------------
-
- void* CTableScroller::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
- {
- FW_UNUSED(stream);
- FW_UNUSED(type);
- FW_SOMEnvironment ev;
- return FW_NEW(CTableScroller, (ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CTableScroller::Destroy
- //----------------------------------------------------------------------------------------
-
- void CTableScroller::Destroy(void* object, FW_ClassTypeConstant type)
- {
- FW_UNUSED(type);
- CTableScroller* self = (CTableScroller*) object;
- delete self;
- }
-
-
-