changed SetContainerSize() to ComputeContainerSize().

This commit is contained in:
michaelp 1998-04-23 23:21:37 +00:00
Родитель 4843cc54d3
Коммит a67637dc6d
4 изменённых файлов: 78 добавлений и 50 удалений

Просмотреть файл

@ -30,10 +30,9 @@ class nsIScrollableView : public nsISupports
{
public:
/**
* Set the height of the container in nscoords.
* @param aSize height of container in twips.
* Compute the size of the scrolled contanier.
*/
virtual void SetContainerSize(PRInt32 aSize) = 0;
virtual void ComputeContainerSize(void) = 0;
/**
* Get the height of the container

Просмотреть файл

@ -142,12 +142,6 @@ nsresult nsScrollingView :: Init(nsIViewManager* aManager,
return rv;
}
void nsScrollingView :: SetPosition(nscoord x, nscoord y)
{
nsView :: SetPosition(x, y);
}
void nsScrollingView :: SetDimensions(nscoord width, nscoord height)
{
nsRect trect;
@ -173,7 +167,7 @@ void nsScrollingView :: SetDimensions(nscoord width, nscoord height)
//but unfortunately it will also cause scrollbar flashing. so long as
//all resize operations happen through the viewmanager, this is not
//an issue. we'll see. MMP
// SetContainerSize(mSize);
// ComputeContainerSize();
NS_RELEASE(dx);
NS_RELEASE(cx);
@ -250,55 +244,64 @@ nsEventStatus nsScrollingView :: HandleEvent(nsGUIEvent *aEvent, PRBool aCheckPa
return retval;
}
void nsScrollingView :: SetContainerSize(nscoord aSize)
void nsScrollingView :: ComputeContainerSize()
{
PRUint32 oldsize = aSize;
nsIView *scrollview = GetScrolledView();
mSize = aSize;
if (nsnull != mScrollBarView)
if (nsnull != scrollview)
{
nscoord width, height;
nsIScrollbar *scroll;
nsIWidget *win;
mScrollBarView->GetDimensions(&width, &height);
win = mScrollBarView->GetWidget();
static NS_DEFINE_IID(kscroller, NS_ISCROLLBAR_IID);
if (NS_OK == win->QueryInterface(kscroller, (void **)&scroll))
if (nsnull != mScrollBarView)
{
if (mSize > height)
nscoord width, height;
nsIScrollbar *scroll;
nsIWidget *win;
PRUint32 oldsize = mSize;
nsRect area(0, 0, 0, 0);
ComputeScrollArea(scrollview, area, 0, 0);
mSize = area.YMost();
mScrollBarView->GetDimensions(&width, &height);
win = mScrollBarView->GetWidget();
static NS_DEFINE_IID(kscroller, NS_ISCROLLBAR_IID);
if (NS_OK == win->QueryInterface(kscroller, (void **)&scroll))
{
nsIPresContext *px = mViewManager->GetPresContext();
if (mSize > mBounds.height)
{
nsIPresContext *px = mViewManager->GetPresContext();
//we need to be able to scroll
//we need to be able to scroll
mScrollBarView->SetVisibility(nsViewVisibility_kShow);
mScrollBarView->SetVisibility(nsViewVisibility_kShow);
//now update the scroller position for the new size
//now update the scroller position for the new size
PRUint32 newpos, oldpos = scroll->GetPosition();
PRInt32 offx, offy;
PRUint32 newpos, oldpos = scroll->GetPosition();
PRInt32 offx, offy;
newpos = NS_TO_INT_ROUND(NS_TO_INT_ROUND((((float)oldpos * mSize) / oldsize) * px->GetTwipsToPixels()) * px->GetPixelsToTwips());
newpos = NS_TO_INT_ROUND(NS_TO_INT_ROUND((((float)oldpos * mSize) / oldsize) * px->GetTwipsToPixels()) * px->GetPixelsToTwips());
mViewManager->GetWindowOffsets(&offx, &offy);
mViewManager->SetWindowOffsets(offx, newpos);
mViewManager->GetWindowOffsets(&offx, &offy);
mViewManager->SetWindowOffsets(offx, newpos);
scroll->SetParameters(mSize, mBounds.height, newpos, NS_POINTS_TO_TWIPS_INT(12));
scroll->SetParameters(mSize, mBounds.height, newpos, NS_POINTS_TO_TWIPS_INT(12));
NS_RELEASE(px);
NS_RELEASE(px);
}
else
mScrollBarView->SetVisibility(nsViewVisibility_kHide);
scroll->Release();
}
else
mScrollBarView->SetVisibility(nsViewVisibility_kHide);
scroll->Release();
NS_RELEASE(win);
}
NS_RELEASE(win);
NS_RELEASE(scrollview);
}
}
@ -365,3 +368,32 @@ nsIView * nsScrollingView :: GetScrolledView(void)
return retview;
}
void nsScrollingView :: ComputeScrollArea(nsIView *aView, nsRect &aRect,
nscoord aOffX, nscoord aOffY)
{
nsRect trect, vrect;
aView->GetBounds(vrect);
aOffX += vrect.x;
aOffY += vrect.y;
trect.x = aOffX;
trect.y = aOffY;
trect.width = vrect.width;
trect.height = vrect.height;
if (aRect.IsEmpty() == PR_TRUE)
aRect = trect;
else
aRect.UnionRect(aRect, trect);
PRInt32 numkids = aView->GetChildCount();
for (PRInt32 cnt = 0; cnt < numkids; cnt++)
{
nsIView *view = aView->GetChild(cnt);
ComputeScrollArea(view, aRect, aOffX, aOffY);
}
}

Просмотреть файл

@ -47,13 +47,12 @@ public:
nsViewVisibility aVisibilityFlag = nsViewVisibility_kShow);
//overrides
virtual void SetPosition(nscoord x, nscoord y);
virtual void SetDimensions(nscoord width, nscoord height);
virtual nsEventStatus HandleEvent(nsGUIEvent *aEvent, PRBool aCheckParent = PR_TRUE, PRBool aCheckChildren = PR_TRUE);
virtual void AdjustChildWidgets(nscoord aDx, nscoord aDy);
//nsIScrollableView interface
virtual void SetContainerSize(PRInt32 aSize);
virtual void ComputeContainerSize();
virtual PRInt32 GetContainerSize();
virtual void SetVisibleOffset(PRInt32 aOffset);
@ -61,6 +60,9 @@ public:
virtual nsIView * GetScrolledView(void);
//private
void ComputeScrollArea(nsIView *aView, nsRect &aRect, nscoord aOffX, nscoord aOffY);
protected:
PRInt32 mSize;
PRInt32 mOffset;

Просмотреть файл

@ -491,7 +491,7 @@ void nsView :: SetDimensions(nscoord width, nscoord height)
if (NS_OK == mParent->QueryInterface(kscroller, (void **)&scroller))
{
scroller->SetContainerSize(mBounds.height);
scroller->ComputeContainerSize();
NS_RELEASE(scroller);
}
}
@ -515,17 +515,12 @@ void nsView :: GetDimensions(nscoord *width, nscoord *height)
void nsView :: SetBounds(const nsRect &aBounds)
{
mBounds = aBounds;
SetPosition(aBounds.x, aBounds.y);
SetDimensions(aBounds.width, aBounds.height);
}
void nsView :: SetBounds(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight)
{
mBounds.x = aX;
mBounds.y = aY;
SetPosition(aX, aY);
SetDimensions(aWidth, aHeight);
}