home *** CD-ROM | disk | FTP | other *** search
- /* ==================
- * PedViewScroller.cc
- * ==================
- */
-
- #include "PedestalDebugging.h"
-
- #include "PedViewScroller.hh"
- #include "PedPaneSubView.hh"
- #include "PedViewScroll.hh"
- #include "PedScrollbar.hh"
-
-
- PedViewScroller::PedViewScroller(PedPaneSubView &inSuperPane)
- : PedViewSub(inSuperPane), mScrollV(NULL), mScrollH(NULL)
- {
- //mScrollV = new PedScrollbar(*this, kPedScrollVertical);
- //mScrollH = new PedScrollbar(*this, kPedScrollHorizontal);
- }
-
- PedViewScroller::~PedViewScroller()
- {
- if (mScrollV) mScrollV->release();
- if (mScrollH) mScrollH->release();
- }
-
- void
- PedViewScroller::Dispose()
- {
- if (mScrollV) {
- mScrollV->Dispose();
- mScrollV->release();
- mScrollV = NULL;
- }
- if (mScrollH) {
- mScrollH->Dispose();
- mScrollH->release();
- mScrollH = NULL;
- }
- }
-
-
- void
- PedViewScroller::NotifyScrolledTo(short inH, short inV)
- {
- if (mScrollH) {
- mScrollH->SetValue(inH);
- }
- if (mScrollV) {
- mScrollV->SetValue(inV);
- }
- }
-
- enum {kPedMsgNone, kPedMsgScroll, kPedMsgNotifyScrolledTo};
-
- long
- PedViewScroller::Message(long inMsgCode, void *inData)
- {
- switch (inMsgCode) {
- case kPedMsgScroll:
- // We need a block here
- if (1) {
- SPedScrollInfo info = *(SPedScrollInfo *)inData;
- Scroll(info.pt.h, info.pt.v, info.update);
- }
- break;
- case kPedMsgNotifyScrolledTo:
- // We need a block here
- if (1) {
- Point pt = *(Point *)inData;
- NotifyScrolledTo(pt.h, pt.v);
- }
- break;
- case kPedMsgNone:
- break;
- default:
- break;
- }
- return 0;
- }
-
-
- void
- PedViewScroller::SetScrollbarPresence(short inAxis, bool inPresent)
- {
- if (inAxis & kPedScrollVertical) {
- if (inPresent) {
- mScrollV = new PedScrollbar(*this, kPedScrollVertical);
- } else {
- delete mScrollV;
- mScrollV = NULL;
- }
- }
- if (inAxis & kPedScrollHorizontal) {
- if (inPresent) {
- mScrollH = new PedScrollbar(*this, kPedScrollHorizontal);
- } else {
- delete mScrollH;
- mScrollH = NULL;
- }
- }
- Resize(mFrame.right, mFrame.bottom);
- }
-
- void
- PedViewScroller::GetFrame(Rect &outFrame)
- {
- PedViewSub::GetFrame(outFrame);
- //outFrame.right -= 15;
- //outFrame.bottom -= 15;
- }
-
- void
- PedViewScroller::Open()
- {
- if (mScrollV) {
- mScrollV->Open();
- }
- if (mScrollH) {
- mScrollH->Open();
- }
- if (MyPane()) {
- MyPane()->Open();
- }
- }
-
- void
- PedViewScroller::Close()
- {
- if (mScrollV) {
- mScrollV->Close();
- }
- if (mScrollH) {
- mScrollH->Close();
- }
- if (MyPane()) {
- MyPane()->Close();
- }
- }
-
- void
- PedViewScroller::Activate()
- {
- if (mScrollV) {
- mScrollV->Activate();
- }
- if (mScrollH) {
- mScrollH->Activate();
- }
- if (MyPane()) {
- MyPane()->Activate();
- }
- }
-
- void
- PedViewScroller::Deactivate()
- {
- if (mScrollV) {
- mScrollV->Deactivate();
- }
- if (mScrollH) {
- mScrollH->Deactivate();
- }
- if (MyPane()) {
- MyPane()->Deactivate();
- }
- }
-
- void
- PedViewScroller::Resize(short inWidth, short inHeight)
- {
- PedView::Resize(inWidth, inHeight);
- mFrame.right = inWidth;
- mFrame.bottom = inHeight;
-
- Point offset;
- GetWindowToLocalOffset(offset);
-
- Rect bounds;
- bool box = true;
-
- if (mScrollV) {
- bounds.top = mFrame.top + offset.v - 1;
- bounds.bottom = mFrame.bottom + offset.v - (box || mScrollH ? 14 : -1);
- bounds.left = mFrame.right + offset.h - 15;
- bounds.right = mFrame.right + offset.h + 1;
- mScrollV->SetBounds(bounds);
- short contentHeight = mFrame.bottom - mFrame.top - (mScrollH ? 15 : 0);
- mScrollV->SetJumpUnit(contentHeight);
- }
- if (mScrollH) {
- bounds.left = mFrame.left + offset.h - 1;
- bounds.right = mFrame.right + offset.h - (box || mScrollV ? 14 : -1);
- bounds.top = mFrame.bottom + offset.v - 15;
- bounds.bottom = mFrame.bottom + offset.v + 1;
- mScrollH->SetBounds(bounds);
- short contentWidth = mFrame.right - mFrame.left - (mScrollV ? 15 : 0);
- mScrollH->SetJumpUnit(contentWidth);
- }
- if (MyPane()) {
- MyPane()->Resize(inWidth - (mScrollV ? 15 : 0),
- inHeight - (mScrollH ? 15 : 0));
- }
- Calibrate();
- }
-
-
- void
- PedViewScroller::Calibrate()
- {
- short hMax, vMax;
-
- PedPane *pane = Pane();
- if (pane) {
- Point scrollPos;
- GetScrollPos(scrollPos);
- Rect aperture, bounds;
- GetAperture(aperture);
- pane->GetBounds(bounds);
- short
- contentHeight, contentWidth,
- viewHeight, viewWidth,
- scrollHeight, scrollWidth;
- // Scroll height is either the content height, or the view height plus
- // the scroll position, whichever is greater. (Think of it as the height
- // of an actual 'scroll' that we're 'scrolling' through.
- contentWidth = bounds.right - bounds.left;
- contentHeight = bounds.bottom - bounds.top;
- viewWidth = aperture.right - aperture.left;
- viewHeight = aperture.bottom - aperture.top;
- scrollWidth = viewWidth + scrollPos.h;
- scrollHeight = viewHeight + scrollPos.v;
- if (scrollWidth < contentWidth ) scrollWidth = contentWidth;
- if (scrollHeight < contentHeight) scrollHeight = contentHeight;
- hMax = scrollWidth - viewWidth;
- vMax = scrollHeight - viewHeight;
- //if (hMax < 0) hMax = 0;
- //if (vMax < 0) vMax = 0;
- } else {
- hMax = vMax = 0;
- }
- if (mScrollV) {
- mScrollV->SetMaximum(vMax);
- }
- if (mScrollH) {
- mScrollH->SetMaximum(hMax);
- }
- }
-
-
- void
- PedViewScroller::DrawContent()
- {
- // set up drawing environment
- // for each pane, Draw()
- // restore drawing environment
- Rect bounds;
- if (mScrollV) {
- mScrollV->GetBounds(bounds);
- ::ClipRect(&bounds);
- mScrollV->DrawContent();
- }
- if (mScrollH) {
- mScrollH->GetBounds(bounds);
- ::ClipRect(&bounds);
- mScrollH->DrawContent();
- }
- if (MyPane()) {
- MyPane()->GetBounds(bounds);
- ::ClipRect(&bounds);
- MyPane()->DrawContent();
- }
- ::ClipRect(&qd.thePort->portRect);
- }
-
- void
- PedViewScroller::DispatchNullEvent(EventRecord &inEvent)
- {
- if (MyPane()) {
- MyPane()->DispatchNullEvent(inEvent);
- }
- }
-
- void
- PedViewScroller::DispatchClickEvent(EventRecord &inEvent)
- {
- Point pt, offset;
- pt = inEvent.where;
- ::GlobalToLocal(&pt);
- GetWindowToLocalOffset(offset);
- ::AddPt(offset, &pt);
- if (MyPane() && MyPane()->PointInAperture(pt)) {
- MyPane()->DispatchClickEvent(inEvent);
- } else if (mScrollV && mScrollV->PointInBounds(pt)) {
- mScrollV->DispatchClickEvent(inEvent);
- } else if (mScrollH && mScrollH->PointInBounds(pt)) {
- mScrollH->DispatchClickEvent(inEvent);
- } else {
- // !?
- }
- }
-
- void
- PedViewScroller::DispatchKey(EventRecord &inEvent)
- {
- if (MyPane()) {
- MyPane()->DispatchKey(inEvent);
- }
- }
-