added support to offset child window to correct location.

This commit is contained in:
dcone%netscape.com 1998-10-13 16:33:39 +00:00
Родитель 06ef02bf00
Коммит cb68173af5
5 изменённых файлов: 80 добавлений и 61 удалений

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

@ -149,7 +149,8 @@ nsButton::~nsButton()
PRBool nsButton::OnPaint(nsPaintEvent &aEvent)
{
DrawWidget(FALSE);
DrawWidget(FALSE,aEvent.renderingContext);
return PR_FALSE;
}
@ -185,26 +186,29 @@ nsButton::PtInWindow(PRInt32 aX,PRInt32 aY)
PRBool
nsButton::DispatchMouseEvent(nsMouseEvent &aEvent)
{
PRBool result;
PRBool result;
nsIRenderingContext *theRC;
theRC = this->GetRenderingContext();
switch (aEvent.message)
{
case NS_MOUSE_LEFT_BUTTON_DOWN:
mMouseDownInButton = PR_TRUE;
DrawWidget(PR_TRUE);
DrawWidget(PR_TRUE,theRC);
result = nsWindow::DispatchMouseEvent(aEvent);
result = nsEventStatus_eConsumeDoDefault;
break;
case NS_MOUSE_LEFT_BUTTON_UP:
mMouseDownInButton = PR_FALSE;
DrawWidget(PR_TRUE);
DrawWidget(PR_TRUE,theRC);
if(mWidgetArmed==PR_TRUE)
result = nsWindow::DispatchMouseEvent(aEvent);
break;
case NS_MOUSE_EXIT:
if(mMouseDownInButton)
{
DrawWidget(PR_FALSE);
DrawWidget(PR_FALSE,theRC);
mWidgetArmed = PR_FALSE;
}
result = nsWindow::DispatchMouseEvent(aEvent);
@ -212,7 +216,7 @@ PRBool result;
case NS_MOUSE_ENTER:
if(mMouseDownInButton)
{
DrawWidget(PR_TRUE);
DrawWidget(PR_TRUE,theRC);
mWidgetArmed = PR_TRUE;
}
result = nsWindow::DispatchMouseEvent(aEvent);
@ -230,7 +234,7 @@ PRBool result;
* @return nothing is returned
*/
void
nsButton::DrawWidget(PRBool aMouseInside)
nsButton::DrawWidget(PRBool aMouseInside,nsIRenderingContext *aTheContext)
{
PRInt16 width,x,y;
PRInt32 offx,offy;
@ -239,7 +243,7 @@ Rect macrect,crect;
GrafPtr theport;
RGBColor blackcolor = {0,0,0};
RgnHandle thergn;
//FontInfo fi;
CalcOffset(offx,offy);
GetPort(&theport);

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

@ -69,7 +69,7 @@ public:
private:
void DrawWidget(PRBool aMouseInside);
void DrawWidget(PRBool aMouseInside,nsIRenderingContext *aRContext);
nsString mLabel;
PRBool mMouseDownInButton;

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

@ -184,9 +184,10 @@ WindowPtr whichwindow;
nsWindow *thewindow;
nsRect rect;
RgnHandle updateregion;
nsPaintEvent pevent;
nsPaintEvent pEvent;
nsRefData *theRefData;
::GetPort(&curport);
whichwindow = (WindowPtr)aTheEvent->message;
@ -208,17 +209,18 @@ nsRefData *theRefData;
rect.height = bounds.top + (bounds.bottom-bounds.top);
// generate a paint event
pevent.message = NS_PAINT;
pevent.widget = thewindow;
pevent.eventStructType = NS_PAINT_EVENT;
pevent.point.x = 0;
pevent.point.y = 0;
pevent.rect = ▭
pevent.time = 0;
thewindow->OnPaint(pevent);
pEvent.message = NS_PAINT;
pEvent.renderingContext = thewindow->GetRenderingContext();
pEvent.widget = thewindow;
pEvent.eventStructType = NS_PAINT_EVENT;
pEvent.point.x = 0;
pEvent.point.y = 0;
pEvent.rect = ▭
pEvent.time = 0;
thewindow->OnPaint(pEvent);
// take care of the childern
thewindow->DoPaintWidgets(updateregion);
thewindow->DoPaintWidgets(updateregion,pEvent.renderingContext);
}
EndUpdate(whichwindow);
}

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

@ -1071,25 +1071,14 @@ nsRect rr;
GetBounds(rr);
event.rect = &rr;
event.renderingContext = nsnull;
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
if (NS_OK == nsRepository::CreateInstance(kRenderingContextCID,
nsnull,
kRenderingContextIID,
(void **)&event.renderingContext))
{
PRInt32 offx,offy;
GrafPtr theport;
Rect macrect;
nsRect therect;
RgnHandle thergn;
RGBColor redcolor = {0xff00,0,0};
RGBColor greencolor = {0,0xff00,0};
CalcOffset(offx,offy);
CalcTotalOffset(offx,offy);
GetPort(&theport);
::SetPort(mWindowPtr);
::SetOrigin(-offx,-offy);
@ -1102,8 +1091,8 @@ nsRect rr;
::GetClip(thergn);
::ClipRect(&macrect);
::PenNormal();
::RGBForeColor(&greencolor);
::FrameRect(&macrect);
//::RGBForeColor(&greencolor);
//::FrameRect(&macrect);
}
else
{
@ -1115,22 +1104,11 @@ nsRect rr;
thergn = ::NewRgn();
::GetClip(thergn);
::ClipRect(&macrect);
::PenNormal();
::RGBForeColor(&redcolor);
::EraseRect(&macrect);
::FrameRect(&macrect);
}
result = (DispatchWindowEvent(&event));
SetOrigin(0,0);
SetPort(theport);
event.renderingContext->Init(mContext, this);
result = (DispatchWindowEvent(&event));
NS_RELEASE(event.renderingContext);
}
else
{
result = PR_FALSE;
}
}
return result;
@ -1311,20 +1289,22 @@ nsWindow::PtInWindow(PRInt32 aX,PRInt32 aY)
{
PRBool result = PR_FALSE;
nsPoint hitPt(aX,aY);
nsRect bounds;
nsRect bounds,newbounds;
PRInt32 offx,offy;
GetBounds(bounds);
if(this->GetParent())
{
CalcOffset(offx,offy);
bounds.MoveBy(offx,offy);
bounds.x +=offx;
bounds.y +=offy;
}
else
{
offx = bounds.x;
offy = bounds.y;
bounds.MoveBy(-offx,-offy);
// no parent, the bounds in global, so make a local coorinate system at 0,0
bounds.x = 0;
bounds.y = 0;
}
if(bounds.Contains(hitPt))
@ -1377,11 +1357,12 @@ void nsWindow::MacRectToNSRect(const Rect& aMacRect, nsRect& aRect) const
}
//-------------------------------------------------------------------------
//
// Locate the widget that contains the point
//
//-------------------------------------------------------------------------
//========================================================================
/*
* Find the widget hit
@param aThePoint -- a point in local coordinats to test for the hit.
*/
nsWindow*
nsWindow::FindWidgetHit(Point aThePoint)
{
@ -1423,7 +1404,7 @@ nsRect rect;
* @return nothing is returned
*/
void
nsWindow::DoPaintWidgets(RgnHandle aTheRegion)
nsWindow::DoPaintWidgets(RgnHandle aTheRegion,nsIRenderingContext *aRC)
{
nsWindow *child = this;
nsRect rect;
@ -1455,6 +1436,7 @@ nsPaintEvent pevent;
// generate a paint event
pevent.message = NS_PAINT;
pevent.renderingContext = aRC;
pevent.widget = child;
pevent.eventStructType = NS_PAINT_EVENT;
pevent.point.x = 0;
@ -1464,7 +1446,7 @@ nsPaintEvent pevent;
child->OnPaint(pevent);
// now go check out the childern
child->DoPaintWidgets(aTheRegion);
child->DoPaintWidgets(aTheRegion,aRC);
}
child = (nsWindow*)mChildren->Next();
}
@ -1574,6 +1556,36 @@ nsRect therect;
return NS_OK;
}
//-------------------------------------------------------------------------
/* Calculate the x and y offsets for this particular widget
* @update ps 09/22/98
* @param aX -- x offset amount
* @param aY -- y offset amount
* @return NOTHING
*/
NS_IMETHODIMP nsWindow::CalcTotalOffset(PRInt32 &aX,PRInt32 &aY)
{
nsIWidget *theparent,*child;
nsRect therect;
aX = mBounds.x;
aY = mBounds.y;
theparent = this->GetParent();
while(theparent)
{
theparent->GetBounds(therect);
child = theparent->GetParent();
if(child)
{
aX += therect.x;
aY += therect.y;
}
theparent = child;
}
return NS_OK;
}
//-------------------------------------------------------------------------
//
//

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

@ -147,7 +147,7 @@ public:
NS_IMETHOD SetBounds(const Rect& aMacRect);
void MacRectToNSRect(const Rect& aMacRect, nsRect& aRect) const;
void nsRectToMacRect(const nsRect& aRect, Rect& aMacRect) const;
void DoPaintWidgets(RgnHandle aTheRegion);
void DoPaintWidgets(RgnHandle aTheRegion,nsIRenderingContext *aRC);
void DoResizeWidgets(nsSizeEvent &aEvent);
PRBool RgnIntersects(RgnHandle aTheRegion,RgnHandle aIntersectRgn);
@ -191,6 +191,7 @@ protected:
NS_IMETHOD UpdateVisibilityFlag();
NS_IMETHOD UpdateDisplay();
NS_IMETHOD CalcOffset(PRInt32 &aX,PRInt32 &aY);
NS_IMETHOD CalcTotalOffset(PRInt32 &aX,PRInt32 &aY);
protected: